From 7d376acf62b6a72e6afae276d713ced5499730e2 Mon Sep 17 00:00:00 2001 From: annelin Date: Thu, 20 May 2021 09:05:44 +0300 Subject: [PATCH] Added `debug.settype(typ, metatable)` function --- src/ldblib.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/ldblib.c b/src/ldblib.c index 640ebf2..dfdc502 100644 --- a/src/ldblib.c +++ b/src/ldblib.c @@ -433,6 +433,15 @@ static int db_traceback (lua_State *L) { return 1; } +static int db_settype (lua_State *L) { + const char *type = luaL_checkstring(L, 1); + lua_setfield(L, LUA_REGISTRYINDEX, type); + lua_pop(L, 1); + lua_pushvalue(L, LUA_REGISTRYINDEX); + lua_getfield(L, 1, type); + return 1; +} + static const luaL_Reg dblib[] = { {"debug", db_debug}, @@ -451,6 +460,7 @@ static const luaL_Reg dblib[] = { {"setmetatable", db_setmetatable}, {"setupvalue", db_setupvalue}, {"traceback", db_traceback}, + {"settype", db_settype}, {NULL, NULL} };