Advertisement

[LUA] How to modify a class properties in LUA?

Started by January 23, 2005 11:48 AM
1 comment, last by rogerdv 19 years, 7 months ago
HI, I have a question about lua again. Can I modify a C++ class's properties in lua script? for example: /////////////C code//////////////// class A { A(){}; ~A(){}; public: int a; int b; } void main() { A a = A(); lua_state L = lua_open(); luadofile(L, "modifyA.lua"); lua_close(L); } ////////////Lua Code//////////// function modify() --do modify to A end //////////////////////////////// Thank you
You can modify A through an accessor that you register with Lua.
Don't be afraid to be yourself. Nobody else ever will be.
Advertisement
There are several examples illustrating this, but it works for small classes. For large projects it is recommended that you use some glue code generator, like tolua++ or luabind. They take a header file and generate required code to pass your class and modify it in lua scripts.

This topic is closed to new replies.

Advertisement