aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenoit Giannangeli <giann008@gmail.com>2017-02-18 07:59:06 +0100
committerBenoit Giannangeli <giann008@gmail.com>2017-02-18 08:04:37 +0100
commit6316cab500cdaa944c6d2ef886138e7e9da0cc7c (patch)
tree63a82e1a374b5d05fac84a3dca27aa46218207cf
parentde7046f938975dbdcd6cfaba6f535dec53dfc263 (diff)
downloadfengari-6316cab500cdaa944c6d2ef886138e7e9da0cc7c.tar.gz
fengari-6316cab500cdaa944c6d2ef886138e7e9da0cc7c.tar.bz2
fengari-6316cab500cdaa944c6d2ef886138e7e9da0cc7c.zip
Corrected lua_gettop, print works !
-rw-r--r--src/lapi.js2
-rw-r--r--tests/lapi.js118
2 files changed, 24 insertions, 96 deletions
diff --git a/src/lapi.js b/src/lapi.js
index dc8ca68..ece02e0 100644
--- a/src/lapi.js
+++ b/src/lapi.js
@@ -71,7 +71,7 @@ const lua_absindex = function(L, idx) {
};
const lua_gettop = function(L) {
- return L.top - 1;
+ return L.top - (L.ci.funcOff + 1);
};
const lua_pushvalue = function(L, idx) {
diff --git a/tests/lapi.js b/tests/lapi.js
index b7ba8ed..561b774 100644
--- a/tests/lapi.js
+++ b/tests/lapi.js
@@ -16,10 +16,10 @@ const lua = require('../src/lua.js');
const linit = require('../src/linit.js');
const CT = lua.constant_types;
-test('luaL_newstate, lua_pushnil, lua_gettop, luaL_typename', function (t) {
+test('luaL_newstate, lua_pushnil, luaL_typename', function (t) {
let L;
- t.plan(3);
+ t.plan(2);
t.doesNotThrow(function () {
@@ -30,13 +30,7 @@ test('luaL_newstate, lua_pushnil, lua_gettop, luaL_typename', function (t) {
}, "JS Lua program ran without error");
t.strictEqual(
- lapi.lua_gettop(L),
- 1,
- "top is correct"
- );
-
- t.strictEqual(
- lauxlib.luaL_typename(L, lapi.lua_gettop(L)),
+ lauxlib.luaL_typename(L, -1),
"nil",
"Correct element(s) on the stack"
);
@@ -46,7 +40,7 @@ test('luaL_newstate, lua_pushnil, lua_gettop, luaL_typename', function (t) {
test('lua_pushnumber', function (t) {
let L;
- t.plan(4);
+ t.plan(3);
t.doesNotThrow(function () {
@@ -57,13 +51,7 @@ test('lua_pushnumber', function (t) {
}, "JS Lua program ran without error");
t.strictEqual(
- lapi.lua_gettop(L),
- 1,
- "top is correct"
- );
-
- t.strictEqual(
- lauxlib.luaL_typename(L, lapi.lua_gettop(L)),
+ lauxlib.luaL_typename(L, -1),
"number",
"Correct element(s) on the stack"
);
@@ -79,7 +67,7 @@ test('lua_pushnumber', function (t) {
test('lua_pushinteger', function (t) {
let L;
- t.plan(4);
+ t.plan(3);
t.doesNotThrow(function () {
@@ -90,13 +78,7 @@ test('lua_pushinteger', function (t) {
}, "JS Lua program ran without error");
t.strictEqual(
- lapi.lua_gettop(L),
- 1,
- "top is correct"
- );
-
- t.strictEqual(
- lauxlib.luaL_typename(L, lapi.lua_gettop(L)),
+ lauxlib.luaL_typename(L, -1),
"number",
"Correct element(s) on the stack"
);
@@ -112,7 +94,7 @@ test('lua_pushinteger', function (t) {
test('lua_pushstring', function (t) {
let L;
- t.plan(4);
+ t.plan(3);
t.doesNotThrow(function () {
@@ -123,13 +105,7 @@ test('lua_pushstring', function (t) {
}, "JS Lua program ran without error");
t.strictEqual(
- lapi.lua_gettop(L),
- 1,
- "top is correct"
- );
-
- t.strictEqual(
- lauxlib.luaL_typename(L, lapi.lua_gettop(L)),
+ lauxlib.luaL_typename(L, -1),
"string",
"Correct element(s) on the stack"
);
@@ -145,7 +121,7 @@ test('lua_pushstring', function (t) {
test('lua_pushboolean', function (t) {
let L;
- t.plan(4);
+ t.plan(3);
t.doesNotThrow(function () {
@@ -156,13 +132,7 @@ test('lua_pushboolean', function (t) {
}, "JS Lua program ran without error");
t.strictEqual(
- lapi.lua_gettop(L),
- 1,
- "top is correct"
- );
-
- t.strictEqual(
- lauxlib.luaL_typename(L, lapi.lua_gettop(L)),
+ lauxlib.luaL_typename(L, -1),
"boolean",
"Correct element(s) on the stack"
);
@@ -178,7 +148,7 @@ test('lua_pushboolean', function (t) {
test('lua_pushvalue', function (t) {
let L;
- t.plan(6);
+ t.plan(5);
t.doesNotThrow(function () {
@@ -191,12 +161,6 @@ test('lua_pushvalue', function (t) {
}, "JS Lua program ran without error");
t.strictEqual(
- lapi.lua_gettop(L),
- 2,
- "top is correct"
- );
-
- t.strictEqual(
lauxlib.luaL_typename(L, -1),
"string",
"Correct element(s) on the stack"
@@ -211,13 +175,13 @@ test('lua_pushvalue', function (t) {
t.strictEqual(
lapi.lua_tostring(L, -1),
"hello",
- "top is correct"
+ "Correct element(s) on the stack"
);
t.strictEqual(
lapi.lua_tostring(L, -2),
"hello",
- "top is correct"
+ "Correct element(s) on the stack"
);
});
@@ -225,7 +189,7 @@ test('lua_pushvalue', function (t) {
test('lua_pushjsclosure', function (t) {
let L;
- t.plan(3);
+ t.plan(2);
t.doesNotThrow(function () {
@@ -241,13 +205,7 @@ test('lua_pushjsclosure', function (t) {
}, "JS Lua program ran without error");
t.strictEqual(
- lapi.lua_gettop(L),
- 1,
- "top is correct"
- );
-
- t.strictEqual(
- lauxlib.luaL_typename(L, lapi.lua_gettop(L)),
+ lauxlib.luaL_typename(L, -1),
"function",
"Correct element(s) on the stack"
);
@@ -257,7 +215,7 @@ test('lua_pushjsclosure', function (t) {
test('lua_pushjsfunction', function (t) {
let L;
- t.plan(3);
+ t.plan(2);
t.doesNotThrow(function () {
@@ -272,13 +230,7 @@ test('lua_pushjsfunction', function (t) {
}, "JS Lua program ran without error");
t.strictEqual(
- lapi.lua_gettop(L),
- 1,
- "top is correct"
- );
-
- t.strictEqual(
- lauxlib.luaL_typename(L, lapi.lua_gettop(L)),
+ lauxlib.luaL_typename(L, -1),
"function",
"Correct element(s) on the stack"
);
@@ -288,7 +240,7 @@ test('lua_pushjsfunction', function (t) {
test('lua_call (calling a light JS function)', function (t) {
let L;
- t.plan(3);
+ t.plan(2);
t.doesNotThrow(function () {
@@ -306,12 +258,6 @@ test('lua_call (calling a light JS function)', function (t) {
}, "JS Lua program ran without error");
t.strictEqual(
- lapi.lua_gettop(L),
- 1,
- "top is correct"
- );
-
- t.strictEqual(
lapi.lua_tostring(L, -1),
"hello",
"top is correct"
@@ -322,7 +268,7 @@ test('lua_call (calling a light JS function)', function (t) {
test('lua_call (calling a JS closure)', function (t) {
let L;
- t.plan(3);
+ t.plan(2);
t.doesNotThrow(function () {
@@ -341,12 +287,6 @@ test('lua_call (calling a JS closure)', function (t) {
}, "JS Lua program ran without error");
t.strictEqual(
- lapi.lua_gettop(L),
- 1,
- "top is correct"
- );
-
- t.strictEqual(
lapi.lua_tostring(L, -1),
"upvalue hello !",
"top is correct"
@@ -357,7 +297,7 @@ test('lua_call (calling a JS closure)', function (t) {
test('lua_pcall (calling a light JS function)', function (t) {
let L;
- t.plan(3);
+ t.plan(2);
t.doesNotThrow(function () {
@@ -375,12 +315,6 @@ test('lua_pcall (calling a light JS function)', function (t) {
}, "JS Lua program ran without error");
t.strictEqual(
- lapi.lua_gettop(L),
- 1,
- "top is correct"
- );
-
- t.strictEqual(
lapi.lua_tostring(L, -1),
"hello",
"top is correct"
@@ -414,7 +348,7 @@ test('lua_pcall that breaks', function (t) {
test('lua_pop', function (t) {
let L;
- t.plan(3);
+ t.plan(2);
t.doesNotThrow(function () {
@@ -428,12 +362,6 @@ test('lua_pop', function (t) {
}, "JS Lua program ran without error");
t.strictEqual(
- lapi.lua_gettop(L),
- 1,
- "top is correct"
- );
-
- t.strictEqual(
lapi.lua_tostring(L, -1),
"hello",
"Correct element(s) on the stack"
@@ -567,7 +495,7 @@ test('lua_settable, lua_gettable', function (t) {
test('print', function (t) {
let luaCode = `
- print("hello world")
+ print("hello", "world", 123)
`, L;
t.plan(1);