From 9a87cc968ecbcf56bcbf591b26c47f8ba5a3986b Mon Sep 17 00:00:00 2001 From: Nicolas BOUQUET Date: Tue, 4 Jul 2023 16:53:01 +0200 Subject: [PATCH] [VM] Improve token API --- VM/include/lua.h | 1 + VM/src/lapi.cpp | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/VM/include/lua.h b/VM/include/lua.h index d3e9154e2..6a8c1da1b 100644 --- a/VM/include/lua.h +++ b/VM/include/lua.h @@ -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); diff --git a/VM/src/lapi.cpp b/VM/src/lapi.cpp index dc9f402a6..80197a962 100644 --- a/VM/src/lapi.cpp +++ b/VM/src/lapi.cpp @@ -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, tokenglobal->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, tokenglobal->ttoken.size());