summaryrefslogtreecommitdiff
path: root/src/ldblib.js
diff options
context:
space:
mode:
authorBenoit Giannangeli <giann008@gmail.com>2017-04-11 13:58:15 +0200
committerBenoit Giannangeli <giann008@gmail.com>2017-04-11 13:58:15 +0200
commit58fcb1d7f55424de904fd6ae53954b46d82aae8c (patch)
treeb6969917ab16a139b918b33d29aa1c93ae66336c /src/ldblib.js
parentea8b3d63af92085d1563c670968152c7dbbb7642 (diff)
downloadfengari-58fcb1d7f55424de904fd6ae53954b46d82aae8c.tar.gz
fengari-58fcb1d7f55424de904fd6ae53954b46d82aae8c.tar.bz2
fengari-58fcb1d7f55424de904fd6ae53954b46d82aae8c.zip
debug.upvalueid
Diffstat (limited to 'src/ldblib.js')
-rw-r--r--src/ldblib.js21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/ldblib.js b/src/ldblib.js
index efab872..426cef2 100644
--- a/src/ldblib.js
+++ b/src/ldblib.js
@@ -66,8 +66,27 @@ const db_getlocal = function(L) {
}
};
+/*
+** Check whether a given upvalue from a given closure exists and
+** returns its index
+*/
+const checkupval = function(L, argf, argnup) {
+ let nup = lauxlib.luaL_checkinteger(L, argnup); /* upvalue index */
+ lauxlib.luaL_checktype(L, argf, lua.CT.LUA_TFUNCTION); /* closure */
+ lauxlib.luaL_argcheck(L, (lapi.lua_getupvalue(L, argf, nup) !== null), argnup, lua.to_luastring("invalid upvalue index"));
+ return nup;
+};
+
+
+const db_upvalueid = function(L) {
+ let n = checkupval(L, 1, 2);
+ lapi.lua_pushlightuserdata(L, lapi.lua_upvalueid(L, 1, n));
+ return 1;
+};
+
const dblib = {
- "getlocal": db_getlocal
+ "getlocal": db_getlocal,
+ "upvalueid": db_upvalueid
};
// Only with Node