aboutsummaryrefslogtreecommitdiff
path: root/tests/test-suite
diff options
context:
space:
mode:
authorBenoit Giannangeli <giann008@gmail.com>2017-05-28 14:52:00 +0200
committerBenoit Giannangeli <giann008@gmail.com>2017-05-28 14:52:00 +0200
commit0d91aed9be2b4761e00d371410140c4b541eb14e (patch)
tree5d176a4b0e8c992fc8896ebae6b7740cfc38bf68 /tests/test-suite
parentfdce133484b0951816dc4998058c098ad882852b (diff)
downloadfengari-0d91aed9be2b4761e00d371410140c4b541eb14e.tar.gz
fengari-0d91aed9be2b4761e00d371410140c4b541eb14e.tar.bz2
fengari-0d91aed9be2b4761e00d371410140c4b541eb14e.zip
ltest.js: listk
Diffstat (limited to 'tests/test-suite')
-rw-r--r--tests/test-suite/ltests.js24
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/test-suite/ltests.js b/tests/test-suite/ltests.js
index 4f874d5..1fe114c 100644
--- a/tests/test-suite/ltests.js
+++ b/tests/test-suite/ltests.js
@@ -7,6 +7,7 @@ const assert = require("assert");
const lua = require('../../src/lua.js');
const lauxlib = require('../../src/lauxlib.js');
const ljstype = require('../../src/ljstype.js');
+const lobject = require('../../src/lobject.js');
const delimits = [" ", "\t", "\n", ",", ";"].map(e => e.charCodeAt(0));
@@ -779,11 +780,34 @@ const coresume = function(L) {
}
};
+const obj_at = function(L, k) {
+ return L.stack[L.ci.funcOff + k].value.p;
+};
+
+const pushobject = function(L, o){
+ L.stack[L.top++] = o;
+ assert(L.top <= L.ci.top, "stack overflow");
+};
+
+const listk = function(L) {
+ lauxlib.luaL_argcheck(L,
+ lua.lua_isfunction(L, 1) && !lua.lua_iscfunction(L, 1),
+ 1, lua.to_luastring("Lua function expected"), true);
+ let p = obj_at(L, 1);
+ lua.lua_createtable(L, p.k.length, 0);
+ for (let i = 0; i < p.k.length; i++) {
+ pushobject(L, p.k[i]);
+ lua.lua_rawseti(L, -2, i + 1);
+ }
+ return 1;
+};
+
const tests_funcs = {
"checkpanic": checkpanic,
"closestate": closestate,
"d2s": d2s,
"doremote": doremote,
+ "listk": listk,
"loadlib": loadlib,
"makeCfunc": makeCfunc,
"newstate": newstate,