Skip to content

Lua cpp expose

Exposition to Lua runtime mechanism proposition.

The user has to create an object that is LuaScriptAbleObject, make it inherit the CRTPLuaScriptObject class and voila.

For example, a simple FooBar examples might be:

// Default sample exposer for lua scripts
script_class (SampleObject) {
    LUA_SCRIPTABLE_CLASS(SampleObject)

    SampleObject()  noexcept { fprintf(stderr, "CREATE SampleObject\n"); }
    ~SampleObject() noexcept { fprintf(stderr, "DESTROY SampleObject\n"); }

    static int foo(lua_State *L) noexcept
    {
        SampleObject *obj = CHECK(L, 1);
        double bar        = luaL_checknumber(L, 2);
        return 0;
    }

    static constexpr inline auto metaMethods = { luaRegDefaultGC, LUA_DECL_CREATE(SampleObject) };
    static constexpr inline auto methods     = { LUA_DECL_METHOD(SampleObject, foo) };
};

A sample file for a script can be found at utils/lua/sample-spec.lua, this is just a proposition.

Modification effectuée par Kubat

Rapports de requête de fusion

Chargement en cours