summaryrefslogtreecommitdiffstatshomepage
path: root/src
diff options
context:
space:
mode:
author cracyc <cracyc@users.noreply.github.com>2016-04-07 16:42:29 -0500
committer cracyc <cracyc@users.noreply.github.com>2016-04-07 16:42:29 -0500
commit65455f3369f53e095cabdb8f34524e7b3cffbe8a (patch)
treee9b37c1ba172a876d44196581b994e4fdc2e7ec7 /src
parent07b676038d732a0e2a13a7024afdbc43c4e9e078 (diff)
luaengine: fix read/write item (nw)
Diffstat (limited to 'src')
-rw-r--r--src/emu/luaengine.cpp42
1 files changed, 37 insertions, 5 deletions
diff --git a/src/emu/luaengine.cpp b/src/emu/luaengine.cpp
index f22d71d946a..640f1bc9874 100644
--- a/src/emu/luaengine.cpp
+++ b/src/emu/luaengine.cpp
@@ -755,12 +755,29 @@ int lua_engine::lua_item::l_item_read(lua_State *L)
{
luaL_argcheck(L, lua_isnumber(L, 2), 2, "offset (integer) expected");
int offset = lua_tounsigned(L, 2);
- if(!l_item_base || (offset > (l_item_size * l_item_count)))
+ int ret = 0;
+ if(!l_item_base || (offset > l_item_count))
{
lua_pushnil(L);
return 1;
}
- lua_pushunsigned(L, ((char *)l_item_base)[offset]);
+ switch(l_item_size)
+ {
+ case 1:
+ default:
+ ret = ((UINT8 *)l_item_base)[offset];
+ break;
+ case 2:
+ ret = ((UINT16 *)l_item_base)[offset];
+ break;
+ case 4:
+ ret = ((UINT32 *)l_item_base)[offset];
+ break;
+ case 8:
+ ret = ((UINT64 *)l_item_base)[offset];
+ break;
+ }
+ lua_pushunsigned(L, ret);
return 1;
}
@@ -769,10 +786,25 @@ int lua_engine::lua_item::l_item_write(lua_State *L)
luaL_argcheck(L, lua_isnumber(L, 2), 2, "offset (integer) expected");
luaL_argcheck(L, lua_isnumber(L, 3), 3, "value (integer) expected");
int offset = lua_tounsigned(L, 2);
- UINT8 value = lua_tounsigned(L, 3);
- if(!l_item_base || (offset > (l_item_size * l_item_count)))
+ UINT64 value = lua_tounsigned(L, 3);
+ if(!l_item_base || (offset > l_item_count))
return 1;
- ((char *)l_item_base)[offset] = value;
+ switch(l_item_size)
+ {
+ case 1:
+ default:
+ ((UINT8 *)l_item_base)[offset] = (UINT8)value;
+ break;
+ case 2:
+ ((UINT16 *)l_item_base)[offset] = (UINT16)value;
+ break;
+ case 4:
+ ((UINT32 *)l_item_base)[offset] = (UINT32)value;
+ break;
+ case 8:
+ ((UINT64 *)l_item_base)[offset] = (UINT64)value;
+ break;
+ }
return 1;
}