lua-users home
lua-l archive

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


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