Fixed possibility to initialize empty strings (and booleans)

master
Pavel R. 3 years ago
parent 21fd437e89
commit 072d2c37f0

@ -433,8 +433,9 @@ static int db_traceback (lua_State *L) {
return 1; return 1;
} }
static int db_settype (lua_State *L) { static int db_registertype (lua_State *L) {
const char *type = luaL_checkstring(L, 1); const char *type = luaL_checkstring(L, 1);
luaL_checktype(L, 2, LUA_TTABLE);
lua_setfield(L, LUA_REGISTRYINDEX, type); lua_setfield(L, LUA_REGISTRYINDEX, type);
lua_pop(L, 1); lua_pop(L, 1);
lua_pushvalue(L, LUA_REGISTRYINDEX); lua_pushvalue(L, LUA_REGISTRYINDEX);
@ -460,7 +461,7 @@ static const luaL_Reg dblib[] = {
{"setmetatable", db_setmetatable}, {"setmetatable", db_setmetatable},
{"setupvalue", db_setupvalue}, {"setupvalue", db_setupvalue},
{"traceback", db_traceback}, {"traceback", db_traceback},
{"settype", db_settype}, {"registertype", db_registertype},
{NULL, NULL} {NULL, NULL}
}; };

@ -668,13 +668,16 @@ static void ravi_code_typecoersion(LexState *ls, int reg, ravi_type_map tm,
*/ */
static void ravi_code_setzero(FuncState *fs, int reg, ravi_type_map ravi_type, TString *usertype) { static void ravi_code_setzero(FuncState *fs, int reg, ravi_type_map ravi_type, TString *usertype) {
(void) usertype; (void) usertype;
if (ravi_type == RAVI_TM_FLOAT || ravi_type == RAVI_TM_INTEGER) if (ravi_type == RAVI_TM_FLOAT || ravi_type == RAVI_TM_INTEGER)
/* code an instruction to convert in place */ /* code an instruction to convert in place */
luaK_codeABC(fs, ravi_type == RAVI_TM_FLOAT ? OP_RAVI_LOADFZ : OP_RAVI_LOADIZ, reg, 0, 0); luaK_codeABC(fs, ravi_type == RAVI_TM_FLOAT ? OP_RAVI_LOADFZ : OP_RAVI_LOADIZ, reg, 0, 0);
else if (ravi_type == RAVI_TM_BOOLEAN)
luaK_codeABC(fs, OP_LOADBOOL, reg, 0, 0);
else if (ravi_type == RAVI_TM_STRING)
luaK_codeABC(fs, OP_LOADNIL, reg, 0, 0);
else if ((ravi_type & RAVI_TM_NIL) == 0) { else if ((ravi_type & RAVI_TM_NIL) == 0) {
char type_map_str[RAVI_TYPEMAP_MAX_LEN]; char type_map_str[RAVI_TYPEMAP_MAX_LEN];
raviY_typemap_string(ravi_type, type_map_str); raviY_typemap_string(ravi_type, type_map_str);
luaX_syntaxerror(fs->ls, luaO_pushfstring(fs->ls->L, "uninitialized %s in local variable", type_map_str)); luaX_syntaxerror(fs->ls, luaO_pushfstring(fs->ls->L, "uninitialized %s in local variable", type_map_str));
} }
} }

Loading…
Cancel
Save