Skip to content

Commit

Permalink
[VM] Improve token API
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas BOUQUET committed Jul 4, 2023
1 parent 985f21b commit 9a87cc9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions VM/include/lua.h
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ LUA_API lua_Callbacks* lua_callbacks(lua_State* L);
*/
LUA_API size_t lua_newtoken(lua_State* L, const char *str);
LUA_API void lua_pushtoken(lua_State* L, int token);
LUA_API int lua_gettoken(lua_State* L, int idx, int token);
LUA_API int lua_rawgettoken(lua_State* L, int idx, int token);
LUA_API void lua_rawsettoken(lua_State* L, int idx, int token);

Expand Down
13 changes: 13 additions & 0 deletions VM/src/lapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1536,6 +1536,19 @@ void lua_pushtoken(lua_State* L, int token)
return;
}

int lua_gettoken(lua_State* L, int idx, int token)
{
api_check(L, token<L->global->ttoken.size());
luaC_threadbarrier(L);
StkId t = index2addr(L, idx);
api_check(L, ttistable(t));
TValue key;
setsvalue(L, &key, L->global->ttoken[token]);
luaV_gettable(L, t, &key, L->top);
api_incr_top(L);
return ttype(L->top - 1);
}

int lua_rawgettoken(lua_State* L, int idx, int token)
{
api_check(L, token<L->global->ttoken.size());
Expand Down

0 comments on commit 9a87cc9

Please sign in to comment.