Jump to content

New Lua Custom Functions?


Yue
 Share

Go to solution Solved by AggrorJorn,

Recommended Posts

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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...