Hi,

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

Recommended Answers

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

Jump to Post

All 2 Replies

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..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.