2013-01-03 2 views
1

저는 C++ 응용 프로그램을 가지고 있으며이 응용 프로그램에 루아 API를 디자인하고 제공하고 싶습니다. 저에게 도움이되는 도구가 있습니까? 어떤 메소드를 표시하고이를 Lua API 레이어에 노출시키는 방법이있을 수 있습니까? 다른 언어의 경우 코드를 파싱 한 후 API를 생성 할 수있는 도구를 보았습니다. Lua의 경우 이와 비슷한 것이 있습니까?C++ 응용 프로그램에서 루아 API의 자동 빌드

+1

http://stackoverflow.com/questions/13615975를보고 질문을 수정하십시오. – prapin

+1

http://stackoverflow.com/questions/103347/how-do-you-glue-lua-to-c-code를 참조하십시오. – mkluwe

답변

4

나는 진정으로 응용 프로그램

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 (ONE!) 헤더 파일에 구성 LuaBridge의 매우 가벼운 접근 방식을 평가
+0

니스! c/C++ 선언에서 바인딩 코드를 생성하는 도구가 있습니까? – kerim

+0

아니요,하지만 일단 당신이 그것에 이해를 얻을 그들은 매우 쉽게 생성 예를 들어 내 대답을 편집 – Alar

+0

예, 아주 간단합니다. 지금은 이해합니다. 자동 코드 생성이 필요하지 않으므로 쉽습니다. – kerim

1

체크 아웃 SWIG. 귀하의 필요와 방법 "명확한"당신의 C/C++ 헤더에 따라 당신은 (this 기본 예제처럼)/당신은 루아에 내보낼 클래스를 SWIG하는 전체 .H 파일을 선택하거나 기능을 공급할 수 :

%module example 
%{ 
#include "example.h" 
%} 
int gcd(int x, int y); 
extern double Foo;