Search code examples
c++apiluaauto-build

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? Maybe there is a way to mark some method and expose them to the Lua API layer? For other languages I have seen tool that can generate APIs after parsing the code, there is something similar to this for Lua?


Solution

  • I truely appreciated the very lightweight approach of LuaBridge which consists in just 1 (ONE!) header file to include in your application

    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();
    }