class - Passing existing C++ objects to Lua -
i working on own videogame engine , i'm trying implement support lua scripts in order code in game's behaviour. however, i'm struggling c++ classes in lua. understand how create new instance of class on heap lua - that's (probably) not want do.
i rather need pass object exists in c++ lua , work inside of script. (example: engine has instance of monster , i'd run script monster see whether sees player - , if so, monster attack player).
the solution have found one: passing existing c++ objects lua , calling passed objects' member functions - however, original poster using luabind requires boost (which don't want use).
thus, questions these:
how can pass object allocated on heap in c++ lua script? (without using luabind)
is approach correct? of i've found tends answer question "how create instance of c++ class in lua" rather passing it, leads me think whether idea right or not.
note: not mind using tool such luabind, don't want use them in case depend on external libraries such boost. if there's easy solution gladly use it.
sol perfect example of library can support c++11+-like semantics, including passing of class types using templates. if you, i'd sol's source code , try replicate methods of object , data passing--much of lua's "meta" functionality build on userdata
structure, i'd suggest start looking there.
by way, sol dependent on lua, , header-inclusion only. it's quite possible use out of box, provided you're using lua 5.2 (and not 5.3, big gripe of community shouldn't matter, luajit on 5.2, believe).
Comments
Post a Comment