lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Thanks for the help!  I'm using Delphi so I really appriciate the Delphi code!

I understand how to create userdata (lua_newuserdata(luaState,
pObject)), but I don't understand metatables or how (or why) you set
methods to manipulate the object.

Can you possible give me a full example of an object and then how you
expose it's methods and properties to lua?

Thanks!!


On 12/8/05, Dušan Majkić <dmajkic@sezampro.yu> wrote:
> > 1) Create an object in C++ (or Delphi) and share it with lua.
>
>   Create new userdata, attach metatable with methods you want to be
>   accesible from lua. Push that userdata to lua state.
>
>   Note that I'm using Delphi.
>   (And still searching a way to staticaly link lua)
>
>   I use this userdata for all delphi objects:
>
>   TObjectData = record
>     Obj: TObject;
>   end;
>   PObjectData = ^TObjectData;
>
>   Then you could set __gc method in metatable to call Obj.Free
>   Or you dont't. If you want your object to live after lua_close().
>
>   I do lua binding manualy. Delphi does not include RTTI with every
>   class and there is no preprocesor - so tools like tolua or swig.
>
>
> > 2) Create a variable in C++ (or Delphi) and share it with lua.
>
>   You can do it in two ways.
>
>   First is to push your variable value to lua state, execute some
>   lua code and then return value to your C++/Delphi variable.
>
>   Second is to push your variable as userdata with metatable, and
>   handle changes to it as they happen, in whatever way you like.
>
>
>