diff options
author | Benoit Giannangeli <benoit.giannangeli@boursorama.fr> | 2017-02-15 08:29:52 +0100 |
---|---|---|
committer | Benoit Giannangeli <benoit.giannangeli@boursorama.fr> | 2017-02-15 08:29:52 +0100 |
commit | 19b47119bad0ef5965841a51c21c6c2d99c77ce9 (patch) | |
tree | a47042790d0ef0ba59559746ce252982c7621c2e | |
parent | 5b8e5dfa30c4afe595d7ae87022dac85f0428f1d (diff) | |
download | fengari-19b47119bad0ef5965841a51c21c6c2d99c77ce9.tar.gz fengari-19b47119bad0ef5965841a51c21c6c2d99c77ce9.tar.bz2 fengari-19b47119bad0ef5965841a51c21c6c2d99c77ce9.zip |
__call
-rw-r--r-- | README.md | 25 | ||||
-rw-r--r-- | tests/ltm.js | 60 |
2 files changed, 61 insertions, 24 deletions
@@ -17,30 +17,7 @@ - [ ] userdata - [ ] thread - [ ] Tag Methods - - [x] `__index` - - [x] `__newindex` - - [x] `__add` - - [x] `__sub` - - [x] `__mul` - - [x] `__mod` - - [x] `__pow` - - [x] `__div` - - [x] `__idiv` - - [x] `__band` - - [x] `__bor` - - [x] `__bxor` - - [x] `__shl` - - [x] `__shr` - - [x] `__unm` - - [x] `__bnot` - - [x] `__eq` - - [x] `__lt` - - [x] `__le` - - [x] `__gc` (unavailable) - - [x] `__mode` (unavailable) - - [x] `__len` - - [x] `__concat` - - [ ] `__call` + - [x] ... - [ ] `__tostring` - [ ] `__pairs` - [ ] Debug (errors) diff --git a/tests/ltm.js b/tests/ltm.js index 17277ca..e365a2a 100644 --- a/tests/ltm.js +++ b/tests/ltm.js @@ -1257,4 +1257,64 @@ test('__concat', function (t) { "hello", "Program output is correct" ); +}); + + +test('__call', function (t) { + let luaCode = ` + local mt = { + __call = function (a, ...) + return "hello", ... + end + } + + local t = {} + + -- setmetatable(t, mt) + + return t("world","wow") + `, L; + + t.plan(4); + + t.comment("Running following code: \n" + luaCode); + + // main <hello.lua:0,0> (10 instructions at 0x7fc4c9403210) + // 0+ params, 5 slots, 1 upvalue, 2 locals, 3 constants, 1 function + // 1 [1] NEWTABLE 0 0 1 + // 2 [4] CLOSURE 1 0 ; 0x7fc4c9403440 + // 3 [4] SETTABLE 0 -1 1 ; "__call" - + // 4 [7] NEWTABLE 1 0 0 + // 5 [11] MOVE 2 1 + // 6 [11] LOADK 3 -2 ; "world" + // 7 [11] LOADK 4 -3 ; "wow" + // 8 [11] TAILCALL 2 3 0 <=== We stop here + // 9 [11] RETURN 2 0 + // 10 [11] RETURN 0 1 + + t.doesNotThrow(function () { + L = getState(luaCode); + }, "Bytecode parsed without errors"); + + L.stack[0].p.code[7].breakpoint = true; + + t.doesNotThrow(function () { + ldo.luaD_call(L, 0, -1); + }, "First part of the program executed without errors"); + + L.ci.pcOff--; + L.stack[0].p.code[7].breakpoint = false; + + t.comment("We manually set t's metatable to mt"); + L.stack[2].metatable = L.stack[1]; + + t.doesNotThrow(function () { + VM.luaV_execute(L); + }, "Second part of the program executed without errors"); + + t.deepEqual( + L.stack.slice(L.top - 3, L.top).map(function (e) { return e.value }), + ["hello", "world", "wow"], + "Program output is correct" + ); });
\ No newline at end of file |