diff options
Diffstat (limited to 'src/lua.js')
-rw-r--r-- | src/lua.js | 91 |
1 files changed, 88 insertions, 3 deletions
@@ -1,6 +1,32 @@ /*jshint esversion: 6 */ "use strict"; +const assert = require('assert'); +const lualib = require('./lualib.js'); + +const LUA_VERSION_MAJOR = "5"; +const LUA_VERSION_MINOR = "3"; +const LUA_VERSION_NUM = 503; +const LUA_VERSION_RELEASE = "4"; + +const LUA_VERSION = "Lua " + LUA_VERSION_MAJOR + "." + LUA_VERSION_MINOR; +const LUA_RELEASE = LUA_VERSION + "." + LUA_VERSION_RELEASE; +const LUA_COPYRIGHT = LUA_RELEASE + " Copyright (C) 1994-2017 Lua.org, PUC-Rio"; +const LUA_AUTHORS = "R. Ierusalimschy, L. H. de Figueiredo, W. Celes"; + +const FENGARI_VERSION_MAJOR = "0"; +const FENGARI_VERSION_MINOR = "0"; +const FENGARI_VERSION_NUM = 1; +const FENGARI_VERSION_RELEASE = "1"; + +const FENGARI_VERSION = "Fengari " + FENGARI_VERSION_MAJOR + "." + FENGARI_VERSION_MINOR; +const FENGARI_RELEASE = FENGARI_VERSION + "." + FENGARI_VERSION_RELEASE; +const FENGARI_COPYRIGHT = FENGARI_RELEASE + " Copyright (C) 2017 BenoƮt Giannangeli\nBased on: " + LUA_COPYRIGHT; +const FENGARI_AUTHORS = "B. Giannangeli"; + +const LUA_INIT_VAR = "LUA_INIT"; +const LUA_INITVARVERSION = LUA_INIT_VAR + lualib.LUA_VERSUFFIX; + const thread_status = { LUA_OK: 0, LUA_YIELD: 1, @@ -35,6 +61,65 @@ constant_types.LUA_TLCL = constant_types.LUA_TFUNCTION | (0 << 4); /* Lua closu constant_types.LUA_TLCF = constant_types.LUA_TFUNCTION | (1 << 4); /* light C function */ constant_types.LUA_TCCL = constant_types.LUA_TFUNCTION | (2 << 4); /* C closure */ -module.exports.constant_types = constant_types; -module.exports.thread_status = thread_status; -module.exports.LUA_MULTRET = -1;
\ No newline at end of file +const print_version = function() { + console.log(FENGARI_COPYRIGHT); +}; + + +const handle_script = function(L, args) { + // TODO: stdin + +}; + +const handle_luainit = function(L) { + // TODO: Should execute script in LUA_INIT_5_3 + return thread_status.LUA_OK; +}; + +/* +** Main body of stand-alone interpreter (to be called in protected mode). +** Reads the options and handles them all. +*/ +const pmain = function(L) { + // arguments are a userdata wrapping a plain JS object + let args = L.stack[1].value; // For now it should only hold a DataView containing bytecode + + // TODO: luaL_checkversion(L); + // TODO: LUA_NOENV + // TODO: luaL_openlibs(L); + // TODO: createargtable(L, argv, argc, script); + + if (!args.E) { + if (handle_luainit(L) != thread_status.LUA_OK) + return 0; /* error running LUA_INIT */ + } + + // TODO: runargs(L, argv, script) + if (args.script && handle_script(L, args) != thread_status.LUA_OK) + return 0; + + // TODO: doREPL(L); +}; + +module.exports.constant_types = constant_types; +module.exports.thread_status = thread_status; +module.exports.LUA_MULTRET = -1; +module.exports.print_version = print_version; +module.exports.LUA_VERSION_MAJOR = LUA_VERSION_MAJOR; +module.exports.LUA_VERSION_MINOR = LUA_VERSION_MINOR; +module.exports.LUA_VERSION_NUM = LUA_VERSION_NUM; +module.exports.LUA_VERSION_RELEASE = LUA_VERSION_RELEASE; +module.exports.LUA_VERSION = LUA_VERSION; +module.exports.LUA_RELEASE = LUA_RELEASE; +module.exports.LUA_COPYRIGHT = LUA_COPYRIGHT; +module.exports.LUA_AUTHORS = LUA_AUTHORS; +module.exports.FENGARI_VERSION_MAJOR = FENGARI_VERSION_MAJOR; +module.exports.FENGARI_VERSION_MINOR = FENGARI_VERSION_MINOR; +module.exports.FENGARI_VERSION_NUM = FENGARI_VERSION_NUM; +module.exports.FENGARI_VERSION_RELEASE = FENGARI_VERSION_RELEASE; +module.exports.FENGARI_VERSION = FENGARI_VERSION; +module.exports.FENGARI_RELEASE = FENGARI_RELEASE; +module.exports.FENGARI_COPYRIGHT = FENGARI_COPYRIGHT; +module.exports.FENGARI_AUTHORS = FENGARI_AUTHORS; +module.exports.LUA_INIT_VAR = LUA_INIT_VAR; +module.exports.LUA_INITVARVERSION = LUA_INITVARVERSION;
\ No newline at end of file |