0

Hi,

I would like to know the significance of lua methods beginning with an underscore.. for example __init().. Thanks !!

2
Contributors
2
Replies
4
Views
6 Years
Discussion Span
Last Post by kartik14
0

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.