summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lapi.js9
-rw-r--r--src/lbaselib.js19
2 files changed, 28 insertions, 0 deletions
diff --git a/src/lapi.js b/src/lapi.js
index 95eb6f7..bb6c224 100644
--- a/src/lapi.js
+++ b/src/lapi.js
@@ -299,6 +299,14 @@ const lua_setfield = function(L, idx, k) {
auxsetstr(L, index2addr(L, idx), k)
};
+const lua_rawset = function(L, idx) {
+ assert(2 < L.top - L.ci.funcOff, "not enough elements in the stack");
+ let o = index2addr(L, idx);
+ assert(o.ttistable(), "table expected");
+ o.__newindex(o, L.stack[L.top - 2], L.stack[L.top - 1]);
+ L.top -= 2;
+};
+
/*
** get functions (Lua -> stack)
*/
@@ -586,6 +594,7 @@ module.exports.lua_gettable = lua_gettable;
module.exports.lua_absindex = lua_absindex;
module.exports.index2addr = index2addr;
module.exports.lua_rawget = lua_rawget;
+module.exports.lua_rawset = lua_rawset;
module.exports.lua_isstring = lua_isstring;
module.exports.lua_rotate = lua_rotate;
module.exports.lua_remove = lua_remove;
diff --git a/src/lbaselib.js b/src/lbaselib.js
index 62d25df..a89cf9d 100644
--- a/src/lbaselib.js
+++ b/src/lbaselib.js
@@ -64,12 +64,31 @@ const luaB_rawequal = function(L) {
return 1;
};
+const luaB_rawget = function(L) {
+ lauxlib.luaL_checktype(L, 1, CT.LUA_TTABLE);
+ lauxlib.luaL_checkany(L, 2);
+ lapi.lua_settop(L, 2);
+ lapi.lua_rawget(L, 1);
+ return 1;
+};
+
+const luaB_rawset = function(L) {
+ lauxlib.luaL_checktype(L, 1, CT.LUA_TTABLE);
+ lauxlib.luaL_checkany(L, 2);
+ lauxlib.luaL_checkany(L, 3);
+ lapi.lua_settop(L, 3);
+ lapi.lua_rawset(L, 1);
+ return 1;
+};
+
const base_funcs = {
"print": luaB_print,
"tostring": luaB_tostring,
"getmetatable": luaB_getmetatable,
"setmetatable": luaB_setmetatable,
"rawequal": luaB_rawequal,
+ "rawset": luaB_rawset,
+ "rawget": luaB_rawget,
};
const luaopen_base = function(L) {