Browse Source

Fixed possibility to initialize empty strings (and booleans)

master
Pavel R. 1 year ago
parent
commit
072d2c37f0
2 changed files with 8 additions and 4 deletions
  1. +3
    -2
      src/ldblib.c
  2. +5
    -2
      src/lparser.c

+ 3
- 2
src/ldblib.c View File

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


+ 5
- 2
src/lparser.c View File

@ -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) {
(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 */
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) {
char type_map_str[RAVI_TYPEMAP_MAX_LEN];
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));
}
}


Loading…
Cancel
Save