🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

LUABind: Export all classes in a single file?

Started by
2 comments, last by luridcortex 19 years, 11 months ago
Is it possible to export all your classes to lua in a single file? I have created a file called lua_exports.cpp and i include the headers for the classes i wish to export and the headers for luabind, and i procede to try and export a class using the module syntax but it will not compile. The compiler appears to not like the syntax for exporting the classes. i have gotten this to work before in a file in which the class was defined.. but that method seems a little messy. thanks, -gf
Advertisement
Well if you're exposing methods that aren't public, then a global free function will not be able to bind them to Luabind.

Good design says you shouldn't be giving scripts access to functions that aren't public anyway; but if you absolutely need to you could always use the friend keyword...

void registerLuaBindings(lua_State* L) {   module(L) [       class_<MyClass>("MyClass")           .def("privateFunction",&MyClass::privateFunction)   ];}...class MyClass {private:    int privateFunction() {        return 42;    }    friend void registerLuaBindings(lua_State* L);};

Yeah, i realize that.

Im just trying to create a single file in which everything i need exported is exported.

So i include all the headers for the classes whos methods i am exporting, and then export them all in a single function call.

However this is not working, i get alot of wierd template errors and syntax errors.

The only way i can get the exporting to work is if i have the class declaration and definition in the same file in which i am attempting to export.

thanks,
-gf
Fixed the problem, it was a syntax error >:

This topic is closed to new replies.

Advertisement