This commit is contained in:
BADIM-PC\Vadim
2017-11-21 17:31:01 +03:00
parent c99b402c41
commit f4808d40d4
8 changed files with 33 additions and 124 deletions

View File

@@ -956,18 +956,21 @@ static s32 lua_pmem(lua_State *lua)
if(top >= 1)
{
u32 index = getLuaNumber(lua, 1);
index %= TIC_PERSISTENT_SIZE;
s32 val = memory->ram.persistent.data[index];
if(top >= 2)
if(index >= 0 && index < TIC_PERSISTENT_SIZE)
{
memory->ram.persistent.data[index] = getLuaNumber(lua, 2);
s32 val = memory->ram.persistent.data[index];
if(top >= 2)
{
memory->ram.persistent.data[index] = getLuaNumber(lua, 2);
}
lua_pushinteger(lua, val);
return 1;
}
lua_pushinteger(lua, val);
return 1;
luaL_error(lua, "invalid persistent memory index\n");
}
else luaL_error(lua, "invalid params, pmem(index [val]) -> val\n");
@@ -1013,7 +1016,7 @@ static s32 lua_mouse(lua_State *lua)
static s32 lua_dofile(lua_State *lua)
{
luaL_error(lua, "you can use 'dofile' only on first line\n");
luaL_error(lua, "unknown method: \"dofile\"\n");
return 0;
}