aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenoit Giannangeli <giann008@gmail.com>2017-04-12 16:26:13 +0200
committerBenoit Giannangeli <giann008@gmail.com>2017-04-13 13:29:35 +0200
commitad3491890872721b7cfb81517c1465c7bdbd53a8 (patch)
tree97ae97c40fa035f36680a67859bd5db65e3a22b2
parent5b6c4d32675e29b615e3bc92b090d2e1df4f9f39 (diff)
downloadfengari-ad3491890872721b7cfb81517c1465c7bdbd53a8.tar.gz
fengari-ad3491890872721b7cfb81517c1465c7bdbd53a8.tar.bz2
fengari-ad3491890872721b7cfb81517c1465c7bdbd53a8.zip
debug.setmetatable debug.getmetatable
-rw-r--r--README.md4
-rw-r--r--src/ldblib.js28
2 files changed, 25 insertions, 7 deletions
diff --git a/README.md b/README.md
index b23562c..2e53fc2 100644
--- a/README.md
+++ b/README.md
@@ -88,15 +88,15 @@
- [x] debug.debug
- [x] debug.getinfo
- [x] debug.getlocal
+ - [x] debug.getmetatable
- [x] debug.getregistry
+ - [x] debug.setmetatable
- [x] debug.traceback
- [ ] debug.gethook
- - [ ] debug.getmetatable
- [ ] debug.getupvalue
- [ ] debug.getuservalue
- [ ] debug.sethook
- [ ] debug.setlocal
- - [ ] debug.setmetatable
- [ ] debug.setupvalue
- [ ] debug.setuservalue
- [ ] debug.upvalueid
diff --git a/src/ldblib.js b/src/ldblib.js
index 7dde1c4..2edc507 100644
--- a/src/ldblib.js
+++ b/src/ldblib.js
@@ -23,6 +23,22 @@ const db_getregistry = function(L) {
return 1;
};
+const db_getmetatable = function(L) {
+ lauxlib.luaL_checkany(L, 1);
+ if (!lapi.lua_getmetatable(L, 1)) {
+ lapi.lua_pushnil(L); /* no metatable */
+ }
+ return 1;
+};
+
+const db_setmetatable = function(L) {
+ const t = lapi.lua_type(L, 2);
+ lauxlib.luaL_argcheck(L, t == lua.CT.LUA_TNIL || t == lua.CT.LUA_TTABLE, 2, lua.to_luastring("nil or table expected"));
+ lapi.lua_settop(L, 2);
+ lapi.lua_setmetatable(L, 1);
+ return 1; /* return 1st argument */
+};
+
/*
** Auxiliary function used by several library functions: check for
** an optional thread as function's first argument and set 'arg' with
@@ -194,11 +210,13 @@ const db_traceback = function(L) {
};
const dblib = {
- "getinfo": db_getinfo,
- "getlocal": db_getlocal,
- "getregistry": db_getregistry,
- "traceback": db_traceback,
- "upvalueid": db_upvalueid
+ "getinfo": db_getinfo,
+ "getlocal": db_getlocal,
+ "getmetatable": db_getmetatable,
+ "getregistry": db_getregistry,
+ "setmetatable": db_setmetatable,
+ "traceback": db_traceback,
+ "upvalueid": db_upvalueid
};
// Only with Node