Skip to content

Commit

Permalink
Merge pull request #1628 from vsariola/feat/core-closure
Browse files Browse the repository at this point in the history
Optimize tic api call performance in LUA.
  • Loading branch information
nesbox authored Nov 1, 2021
2 parents 8c6aecf + 3b4331b commit 9a716af
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/api/lua.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,18 @@ static s32 getLuaNumber(lua_State* lua, s32 index)

static void registerLuaFunction(tic_core* core, lua_CFunction func, const char *name)
{
lua_pushcfunction(core->currentVM, func);
lua_pushlightuserdata(core->currentVM, core);
lua_pushcclosure(core->currentVM, func, 1);
lua_setglobal(core->currentVM, name);
}

static tic_core* getLuaCore(lua_State* lua)
{
tic_core* core = lua_touserdata(lua, lua_upvalueindex(1));
return core;
}

static tic_core* getLuaCoreGlobal(lua_State* lua)
{
lua_getglobal(lua, TicCore);
tic_core* core = lua_touserdata(lua, -1);
Expand Down Expand Up @@ -1356,7 +1363,7 @@ static void lua_open_builtins(lua_State *lua)

static void checkForceExit(lua_State *lua, lua_Debug *luadebug)
{
tic_core* core = getLuaCore(lua);
tic_core* core = getLuaCoreGlobal(lua);

tic_tick_data* tick = core->data;

Expand Down

0 comments on commit 9a716af

Please sign in to comment.