我有一个C ++应用程序,我想为这个应用程序设计并提供Lua API,有一些工具可以帮助我吗?也许有办法标记一些方法并将它们暴露给Lua API层?对于其他语言,我看过解析代码后可以生成API的工具,Lua有类似的东西吗?
答案 0 :(得分:4)
我非常感谢LuaBridge非常轻量级的方法,它只包含1个(ONE!)头文件以包含在您的应用程序中
https://github.com/vinniefalco/LuaBridge
https://github.com/vinniefalco/LuaBridgeDemo
/** Declare LUA binding for this class
*
* @param global_lua
*/
void c_entity::lua_bind(lua_State* L) {
getGlobalNamespace(L)
.beginClass<c_entity>("c_entity")
.addFunction("getSpeed",&c_entity::get_linear_speed)
.addFunction("getName",&c_entity::get_name)
.addFunction("getMaxSpeed",&c_entity::get_max_linear_speed)
.addFunction("getAcceleration",&c_entity::get_max_linear_acceleration)
.addFunction("getHull",&c_entity::get_hull)
.addFunction("getArmor",&c_entity::get_armor)
.addFunction("getShield",&c_entity::get_shield)
.addCFunction("getStatus",&c_entity::getStatus)
.addFunction("logTrace",&c_entity::log_trace)
.addFunction("logInfo",&c_entity::log_info)
.addFunction("logDebug",&c_entity::log_debug)
.addFunction("logError",&c_entity::log_error)
.endClass();
}
答案 1 :(得分:1)