0
\$\begingroup\$

This is my first attempt to make a SDL2 based 2d game engine in C, i am planning using Lua as scripting language for gameplay purposes.

First i learned how to call a C function from Lua:

lua_State* state;

static int function(lua_State* state)
{
    ...
}

int main(int argc, char* argv[])
{
    state = lua_open();
    luaL_openlibs(state);

    lua_register(state, "function", function);

    luaL_dofile(state, "script.lua");

    lua_close(state);

    getchar();

    return 0;
}

In C i just have to use pollEvent function and place update method right there and hardcode all the gameplay, anyways i don't know how to register an update method like unity update method (just an example) to be called from Lua.

Any resource provided would be really appreciated.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.