From 40cb52853ce7a0715761504940b07d77bacf5ec4 Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Tue, 11 Apr 2017 10:54:49 +0200 Subject: Basic interactive lua cli --- tests/debug-cli.js | 19 ------------------- tests/ldblib.js | 7 +++++++ tests/manual-tests/debug-cli.js | 19 +++++++++++++++++++ tests/manual-tests/lua-cli.js | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 59 insertions(+), 19 deletions(-) delete mode 100644 tests/debug-cli.js create mode 100644 tests/ldblib.js create mode 100644 tests/manual-tests/debug-cli.js create mode 100755 tests/manual-tests/lua-cli.js (limited to 'tests') diff --git a/tests/debug-cli.js b/tests/debug-cli.js deleted file mode 100644 index aa6847f..0000000 --- a/tests/debug-cli.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict"; - -const lapi = require("../src/lapi.js"); -const lauxlib = require("../src/lauxlib.js"); -const lua = require('../src/lua.js'); -const linit = require('../src/linit.js'); - -let luaCode = ` - a = "debug me" - debug.debug() -`, L; - -L = lauxlib.luaL_newstate(); - -linit.luaL_openlibs(L); - -lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); - -lapi.lua_call(L, 0, -1); diff --git a/tests/ldblib.js b/tests/ldblib.js new file mode 100644 index 0000000..5e5c298 --- /dev/null +++ b/tests/ldblib.js @@ -0,0 +1,7 @@ +"use strict"; + +const lapi = require("../src/lapi.js"); +const lauxlib = require("../src/lauxlib.js"); +const lua = require('../src/lua.js'); +const linit = require('../src/linit.js'); + diff --git a/tests/manual-tests/debug-cli.js b/tests/manual-tests/debug-cli.js new file mode 100644 index 0000000..18dee7f --- /dev/null +++ b/tests/manual-tests/debug-cli.js @@ -0,0 +1,19 @@ +"use strict"; + +const lapi = require("../../src/lapi.js"); +const lauxlib = require("../../src/lauxlib.js"); +const lua = require('../../src/lua.js'); +const linit = require('../../src/linit.js'); + +let luaCode = ` + a = "debug me" + debug.debug() +`, L; + +L = lauxlib.luaL_newstate(); + +linit.luaL_openlibs(L); + +lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); + +lapi.lua_call(L, 0, -1); diff --git a/tests/manual-tests/lua-cli.js b/tests/manual-tests/lua-cli.js new file mode 100755 index 0000000..6c7801c --- /dev/null +++ b/tests/manual-tests/lua-cli.js @@ -0,0 +1,33 @@ +#!/usr/bin/env node +"use strict"; + +const lua = require('../../src/lua.js'); +const lapi = require('../../src/lapi.js'); +const lauxlib = require('../../src/lauxlib.js'); +const linit = require('../../src/linit.js'); +const fs = require('fs'); +const readlineSync = require('readline-sync'); + +readlineSync.setDefaultOptions({ + prompt: '> ' +}); + +const L = lauxlib.luaL_newstate(); + +linit.luaL_openlibs(L); + +console.log(lua.FENGARI_COPYRIGHT); + +for (;;) { + let input = readlineSync.prompt(); + + if (input.length === 0) + continue; + + let buffer = lua.to_luastring(input); + if (lauxlib.luaL_loadbuffer(L, buffer, buffer.length, lua.to_luastring("=stdin")) + || lapi.lua_pcall(L, 0, 0, 0)) { + lauxlib.lua_writestringerror(`${lapi.lua_tojsstring(L, -1)}\n`); + } + lapi.lua_settop(L, 0); /* remove eventual returns */ +} -- cgit v1.2.3-70-g09d2