summaryrefslogtreecommitdiff
path: root/src/lapi.js
diff options
context:
space:
mode:
authorBenoit Giannangeli <giann@users.noreply.github.com>2017-03-21 09:09:16 +0100
committerGitHub <noreply@github.com>2017-03-21 09:09:16 +0100
commit932875c87ab3f2ed2b676a98f273392661535f65 (patch)
tree505f463ecdd0b4be4f0ce3e6446183774d406783 /src/lapi.js
parent9ac1d380dd1da894c6317845ea3234124663714b (diff)
parent6bf508f234654b1b0c7afa04797601d14c150934 (diff)
downloadfengari-932875c87ab3f2ed2b676a98f273392661535f65.tar.gz
fengari-932875c87ab3f2ed2b676a98f273392661535f65.tar.bz2
fengari-932875c87ab3f2ed2b676a98f273392661535f65.zip
Merge pull request #8 from giann/feature/match
Feature/match
Diffstat (limited to 'src/lapi.js')
-rw-r--r--src/lapi.js22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/lapi.js b/src/lapi.js
index a884a97..5872545 100644
--- a/src/lapi.js
+++ b/src/lapi.js
@@ -428,6 +428,14 @@ const lua_createtable = function(L, narray, nrec) {
assert(L.top <= L.ci.top, "stack overflow");
};
+const lua_newuserdata = function(L, u) {
+ L.stack[L.top++] = new lobject.TValue(CT.LUA_TUSERDATA, u);
+
+ assert(L.top <= L.ci.top, "stack overflow");
+
+ return L.stack[L.top - 1].value;
+};
+
const aux_upvalue = function(fi, n) {
switch(fi.ttype()) {
case CT.LUAT_TCCL: { /* C closure */
@@ -534,7 +542,7 @@ const lua_toboolean = function(L, idx) {
const lua_tolstring = function(L, idx) {
let o = index2addr(L, idx);
- if (!o.ttisstring() && !o.ttisnumber())
+ if ((!o.ttisstring() && !o.ttisnumber()))
return null;
return o.ttisstring() ? o.jsstring() : `${o.value}`;
@@ -578,6 +586,16 @@ const lua_tonumber = function(L, idx) {
return lvm.tonumber(index2addr(L, idx));
};
+const lua_touserdata = function(L, idx) {
+ let o = index2addr(L, idx);
+ switch (o.ttnov()) {
+ case CT.LUA_TUSERDATA:
+ case CT.LUA_TLIGHTUSERDATA:
+ return o.value;
+ default: return null;
+ }
+};
+
const lua_tothread = function(L, idx) {
let o = index2addr(L, idx);
return o.ttisthread() ? o.value : null;
@@ -879,6 +897,7 @@ module.exports.lua_istable = lua_istable;
module.exports.lua_len = lua_len;
module.exports.lua_load = lua_load;
module.exports.lua_newtable = lua_newtable;
+module.exports.lua_newuserdata = lua_newuserdata;
module.exports.lua_next = lua_next;
module.exports.lua_pcall = lua_pcall;
module.exports.lua_pcallk = lua_pcallk;
@@ -924,6 +943,7 @@ module.exports.lua_tonumber = lua_tonumber;
module.exports.lua_topointer = lua_topointer;
module.exports.lua_tostring = lua_tostring;
module.exports.lua_tothread = lua_tothread;
+module.exports.lua_touserdata = lua_touserdata;
module.exports.lua_type = lua_type;
module.exports.lua_typename = lua_typename;
module.exports.lua_version = lua_version;