I have singleton class and I would like to bind it for lua to use. I'm using SLB (Simple Lua Binder). I really have no idea how to do this. All my ideas just dont work. Anyone?
void Logger::export_class_to_lua(SLB::Manager *m) {
SLB::Class< Logger, SLB::Instance::NoCopyNoDestroy >("Logger",m)
.set("getInstance",&Logger::getInstance)
.set("log",&Logger::log)
.set("info",&Logger::info)
.set("warning",&Logger::warning)
.set("error",&Logger::error)
.set("fatal",&Logger::fatal);
}
Using your code do:
void Logger::export_class_to_lua(SLB::Manager *m) {
SLB::Class< Logger, SLB::Instance::NoCopyNoDestroy >("Logger",m)
//.set("getInstance",&Logger::getInstance) // OMIT THIS
.set("log",&Logger::log)
.set("info",&Logger::info)
.set("warning",&Logger::warning)
.set("error",&Logger::error)
.set("fatal",&Logger::fatal);
// Next we set global variable within LUA to access the Singleton
SLB::setGlobal<Logger*>(&(*lua_State), getInstance(), "logger");
}
lua_State will be a pointer to whatever lua_State you created. "logger" is the name of the object/class/variable you use within LUA to access the Singleton.
So for example; inside of LUA you would do:
logger:log("Logging some information.")
logger:error("An error has occured.")
Assuming your log and error functions take const char* or something.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With