Yue Posted March 1, 2018 Share Posted March 1, 2018 It is possible from c++ to create new functions lua, and that later on to be called des script Lua? Quote Link to comment Share on other sites More sharing options...
Solution AggrorJorn Posted March 2, 2018 Solution Share Posted March 2, 2018 You can use ToLua++. Quote Link to comment Share on other sites More sharing options...
Crazycarpet Posted March 2, 2018 Share Posted March 2, 2018 https://www.lua.org/pil/24.html See lua_register, but keep in mind you have to wrap the functions you wish to expose in plain C.... ToLua++ is your best bet. https://bitbucket.org/Codeblockz/toluapkggenerator2 If you can figure out how to use my above tool, it will help you a ton! It'll auto-generate your Lua bindings for anything commented with //lua including enumerations, classes, polymorphic classes, namespaces, etc... Keep in mind to expose a class and it's members you have to tag the class declaration too like so: class MyClass //lua { void MyExposedFunc(); //lua int myExposedVar; //lua void MyUnexposedFunc(); } In Lua you would then do: local obj = MyClass() obj:MyExposedFunc() print(obj.myExposedVar) You do not have to tag namespaces with //lua however. I also wrote a C++ version of this I'm not planning on releasing publicly but if you need it I may be able to share it if you don't give it out. Also note that with namespaces the access is different like: namespace MyNamespace { void MyFunc(); //lua } Lua: MyNamespace.MyFunc() Note the '.' instead of ':' as namespaces are simply tables, where as classes are metatables. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.