aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-02-16 07:35:26 +0100
committerBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-02-16 07:37:18 +0100
commit3a77114269b53fc57ff00342af18e71f97dcf590 (patch)
treee33feba1afb32d02c1684294362ac74b9e27007f /src
parent9d6afeba223c22163928557c69a102877223d3bd (diff)
downloadfengari-3a77114269b53fc57ff00342af18e71f97dcf590.tar.gz
fengari-3a77114269b53fc57ff00342af18e71f97dcf590.tar.bz2
fengari-3a77114269b53fc57ff00342af18e71f97dcf590.zip
luaL_newstate, lua_pushnil, lua_gettop, luaL_typename
Diffstat (limited to 'src')
-rw-r--r--src/lapi.js24
-rw-r--r--src/lauxlib.js8
-rw-r--r--src/ltm.js21
3 files changed, 50 insertions, 3 deletions
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
diff --git a/src/lauxlib.js b/src/lauxlib.js
index 3ff346e..6cc3d3c 100644
--- a/src/lauxlib.js
+++ b/src/lauxlib.js
@@ -18,4 +18,10 @@ const luaL_newstate = function() {
};
-module.exports.luaL_newstate = luaL_newstate; \ No newline at end of file
+const luaL_typename = function(L, i) {
+ return lapi.lua_typename(L, lapi.lua_type(L, i));
+}
+
+
+module.exports.luaL_newstate = luaL_newstate;
+module.exports.luaL_typename = luaL_typename; \ No newline at end of file
diff --git a/src/ltm.js b/src/ltm.js
index 8b4f4f5..77d65e4 100644
--- a/src/ltm.js
+++ b/src/ltm.js
@@ -40,6 +40,24 @@ const TMS = {
TM_N: 26
};
+const luaT_typenames_ = [
+ "no value",
+ "nil",
+ "boolean",
+ "userdata",
+ "number",
+ "string",
+ "table",
+ "function",
+ "userdata",
+ "thread",
+ "proto" /* this last case is used for tests only */
+];
+
+const ttypename = function(t) {
+ return luaT_typenames_[t + 1];
+};
+
const luaT_init = function(L) {
L.l_G.tmname = [];
for (let event in TMS) {
@@ -112,4 +130,5 @@ module.exports.luaT_callbinTM = luaT_callbinTM;
module.exports.luaT_trybinTM = luaT_trybinTM;
module.exports.luaT_callorderTM = luaT_callorderTM;
module.exports.luaT_gettmbyobj = luaT_gettmbyobj;
-module.exports.luaT_init = luaT_init; \ No newline at end of file
+module.exports.luaT_init = luaT_init;
+module.exports.ttypename = ttypename; \ No newline at end of file