[英]autobuild of Lua api from C++ application
I have a C++ application and I would like to design and offer Lua APIs for this application, there is some tool that can help me with that? 我有一个C ++应用程序,我想为此应用程序设计并提供Lua API,有一些工具可以帮助我吗? Maybe there is a way to mark some method and expose them to the Lua API layer?
也许有一种方法可以标记一些方法并将其公开给Lua API层? For other languages I have seen tool that can generate APIs after parsing the code, there is something similar to this for Lua?
对于其他语言,我看到了可以在解析代码后生成API的工具,对于Lua,有类似的东西吗?
I truely appreciated the very lightweight approach of LuaBridge which consists in just 1 (ONE!) header file to include in your application 我非常赞赏LuaBridge的非常轻量级的方法,该方法仅包含1个(一个!)头文件即可包含在您的应用程序中
https://github.com/vinniefalco/LuaBridge https://github.com/vinniefalco/LuaBridge
https://github.com/vinniefalco/LuaBridgeDemo 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();
}
Check out SWIG . 签出SWIG 。 Depending on your needs and how "clear" your C/C++ headers you can just feed entire .h files to SWIG or select functions/classes you want to export to Lua(like in this basic example):
根据您的需要以及如何“清除” C / C ++头,您可以将整个.h文件提供给SWIG或选择要导出到Lua的函数/类(如以下基本示例所示):
%module example
%{
#include "example.h"
%}
int gcd(int x, int y);
extern double Foo;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.