From 6d3d22b3938a811bdde9a311753837003df42d08 Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Mon, 20 Feb 2017 11:58:46 +0100 Subject: rawset, rawget --- tests/lbaselib.js | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) (limited to 'tests') diff --git a/tests/lbaselib.js b/tests/lbaselib.js index ab68a5f..b3af927 100644 --- a/tests/lbaselib.js +++ b/tests/lbaselib.js @@ -126,4 +126,64 @@ test('rawequal', function (t) { lapi.lua_toboolean(L, -1), "Correct element(s) on the stack" ); +}); + + +test('rawset, rawget', function (t) { + let luaCode = ` + local mt = { + __newindex = function (table, key, value) + rawset(table, key, "hello") + end + } + + local t = {} + + setmetatable(t, mt); + + t["yo"] = "bye" + rawset(t, "yoyo", "bye") + + return rawget(t, "yo"), t["yo"], rawget(t, "yoyo"), t["yoyo"] + `, L; + + t.plan(5); + + t.doesNotThrow(function () { + + let bc = toByteCode(luaCode).dataView; + + L = lauxlib.luaL_newstate(); + + linit.luaL_openlibs(L); + + lapi.lua_load(L, bc, "test-rawequal"); + + lapi.lua_call(L, 0, -1); + + }, "JS Lua program ran without error"); + + t.strictEqual( + lapi.lua_tostring(L, -4), + "hello", + "Correct element(s) on the stack" + ); + + t.strictEqual( + lapi.lua_tostring(L, -3), + "hello", + "Correct element(s) on the stack" + ); + + t.strictEqual( + lapi.lua_tostring(L, -2), + "bye", + "Correct element(s) on the stack" + ); + + t.strictEqual( + lapi.lua_tostring(L, -1), + "bye", + "Correct element(s) on the stack" + ); }); \ No newline at end of file -- cgit v1.2.3-70-g09d2