Hi,
I would like to know the significance of lua methods beginning with an underscore.. for example __init().. Thanks !!
Hi,
I would like to know the significance of lua methods beginning with an underscore.. for example __init().. Thanks !!
The only place I'm aware of that double underscores mean anything to Lua is in metatables.
Basically they allow you to create custom behavior for certain object; it's an operator overloading feature.
For example, you create a struct or class in your C/C++ code, add it to a Lua state as a userdata object, add a Lua function to the object's metatable with the key "__add", and then that function will be called when your objects are added in Lua with the +
operator. The section of the Lua Reference Manual I linked explains in more detail.
Thanks..
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.