From 3a77114269b53fc57ff00342af18e71f97dcf590 Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Thu, 16 Feb 2017 07:35:26 +0100 Subject: luaL_newstate, lua_pushnil, lua_gettop, luaL_typename --- src/lapi.js | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'src/lapi.js') diff --git a/src/lapi.js b/src/lapi.js index 9e20d7f..0cb0a4b 100644 --- a/src/lapi.js +++ b/src/lapi.js @@ -5,6 +5,7 @@ const assert = require('assert'); const ldo = require('./ldo.js'); const lobject = require('./lobject.js'); +const ltm = require('./ltm.js'); const lfunc = require('./lfunc.js'); const lua = require('./lua.js'); const lstate = require('./lstate.js'); @@ -49,6 +50,14 @@ const index2addr = function(L, idx) { }; +/* +** basic stack manipulation +*/ + +const lua_gettop = function(L) { + return L.top - 1; +}; + const lua_pushvalue = function(L, idx) { L.stack[L.top] = L.stack[index2addr(L, idx)]; @@ -164,6 +173,16 @@ const f_call = function(L, ud) { ldo.luaD_callnoyield(L, ud.func, ud.nresults); }; +const lua_type = function(L, idx) { + let o = index2addr(L, idx); + return o.ttnov(); // TODO: isvalid ? luaO_nilobject != nil tvalue ? +}; + +const lua_typename = function(L, t) { + assert(CT.LUA_TNONE <= t && t < CT.LUA_NUMTAGS, "invalid tag"); + return ltm.ttypename(t); +}; + /* ** 'load' and 'call' functions (run Lua code) @@ -225,4 +244,7 @@ module.exports.lua_pushinteger = lua_pushinteger; module.exports.lua_pushlstring = lua_pushlstring; module.exports.lua_pushstring = lua_pushstring; module.exports.lua_version = lua_version; -module.exports.lua_atpanic = lua_atpanic; \ No newline at end of file +module.exports.lua_atpanic = lua_atpanic; +module.exports.lua_gettop = lua_gettop; +module.exports.lua_typename = lua_typename; +module.exports.lua_type = lua_type; \ No newline at end of file -- cgit v1.2.3-54-g00ecf