aboutsummaryrefslogtreecommitdiff
path: root/tests/ltm.js
blob: 8a5ccb744a7f240569da1ce3884a1683f291cb5e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*jshint esversion: 6 */
"use strict";

const test           = require('tape');
const beautify       = require('js-beautify').js_beautify;

const lua_State      = require("../src/lstate.js").lua_State;
const VM             = require("../src/lvm.js");
const Table          = require("../src/lobject.js").Table;;

const getState       = require("./tests.js");


test('__add', function (t) {
    let luaCode = `
        local t = {}
        setmetatable(t, {__add = function ()
            return "hello"
        end})
        return t + 1
    `, L;
    
    t.plan(2);

    t.comment("Running following code: \n" + luaCode);

    t.doesNotThrow(function () {
        L = getState(luaCode);
        VM.luaV_execute(L);
    }, "Program executed without errors");

    t.strictEqual(
        L.stack[L.top - 1].value,
        "hello",
        "Program output is correct"
    );
});