aboutsummaryrefslogtreecommitdiff
path: root/src/lapi.js
diff options
context:
space:
mode:
authorBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-02-16 14:49:25 +0100
committerBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-02-16 14:49:25 +0100
commitf556eada483134f5dc433e6bd4510047e4953649 (patch)
treed3e0679859bb19e0694972f8970078f6c58d0fbc /src/lapi.js
parent8f913dd74957ef18e144f15b78c3e55893744218 (diff)
downloadfengari-f556eada483134f5dc433e6bd4510047e4953649.tar.gz
fengari-f556eada483134f5dc433e6bd4510047e4953649.tar.bz2
fengari-f556eada483134f5dc433e6bd4510047e4953649.zip
lua_pushcclosure, lua_pushcfunction
Diffstat (limited to 'src/lapi.js')
-rw-r--r--src/lapi.js49
1 files changed, 29 insertions, 20 deletions
diff --git a/src/lapi.js b/src/lapi.js
index 6aba915..ee976e1 100644
--- a/src/lapi.js
+++ b/src/lapi.js
@@ -1,4 +1,4 @@
-/*jshint esversion: 6 */
+/* jshint esversion: 6 */
"use strict";
const assert = require('assert');
@@ -36,7 +36,7 @@ const index2addr = function(L, idx) {
assert(idx <= ci.top - (ci.funcOff + 1), "unacceptable index");
if (o >= L.top) return nil;
else return L.stack[o];
- } else if (idx < 0) { // TODO: pseudo-indices
+ } else if (idx < 0) { // TODO: pseudo-indices relative to LUA_REGISTRYINDEX
assert(idx !== 0 && -idx <= L.top, "invalid index");
return L.stack[L.top + idx];
// TODO: if (idx == LUA_REGISTRYINDEX) return &G(L)->l_registry;
@@ -134,11 +134,14 @@ const lua_pushcclosure = function(L, fn, n) {
else {
assert(n < L.top - L.ci.funcOff, "not enough elements in the stack");
assert(n <= MAXUPVAL, "upvalue index too large");
- let cl = new CClosure(L, n, fn);
+
+ let cl = new CClosure(L, fn, n);
+
L.top -= n;
while (n--) {
cl.upvalue[n] = L.stack[L.top + n];
}
+
L.stack[L.top] = cl;
}
@@ -146,6 +149,10 @@ const lua_pushcclosure = function(L, fn, n) {
assert(L.top <= L.ci.top, "stack overflow");
};
+const lua_pushcfunction = function(L, fn) {
+ lua_pushcclosure(L, fn, 0);
+};
+
const lua_pushboolean = function(L, b) {
L.stack[L.top] = new TValue(CT.LUA_TBOOLEAN, b ? true : false);
@@ -261,20 +268,22 @@ const lua_pcallk = function(L, nargs, nresults, errfunc, ctx, k) {
return status;
};
-module.exports.lua_pushvalue = lua_pushvalue;
-module.exports.lua_pushnil = lua_pushnil;
-module.exports.lua_pushnumber = lua_pushnumber;
-module.exports.lua_pushinteger = lua_pushinteger;
-module.exports.lua_pushlstring = lua_pushlstring;
-module.exports.lua_pushstring = lua_pushstring;
-module.exports.lua_pushboolean = lua_pushboolean;
-module.exports.lua_version = lua_version;
-module.exports.lua_atpanic = lua_atpanic;
-module.exports.lua_gettop = lua_gettop;
-module.exports.lua_typename = lua_typename;
-module.exports.lua_type = lua_type;
-module.exports.lua_tonumber = lua_tonumber;
-module.exports.lua_tointeger = lua_tointeger;
-module.exports.lua_toboolean = lua_toboolean;
-module.exports.lua_tolstring = lua_tolstring;
-module.exports.lua_tostring = lua_tostring; \ No newline at end of file
+module.exports.lua_pushvalue = lua_pushvalue;
+module.exports.lua_pushnil = lua_pushnil;
+module.exports.lua_pushnumber = lua_pushnumber;
+module.exports.lua_pushinteger = lua_pushinteger;
+module.exports.lua_pushlstring = lua_pushlstring;
+module.exports.lua_pushstring = lua_pushstring;
+module.exports.lua_pushboolean = lua_pushboolean;
+module.exports.lua_pushcclosure = lua_pushcclosure;
+module.exports.lua_pushcfunction = lua_pushcfunction;
+module.exports.lua_version = lua_version;
+module.exports.lua_atpanic = lua_atpanic;
+module.exports.lua_gettop = lua_gettop;
+module.exports.lua_typename = lua_typename;
+module.exports.lua_type = lua_type;
+module.exports.lua_tonumber = lua_tonumber;
+module.exports.lua_tointeger = lua_tointeger;
+module.exports.lua_toboolean = lua_toboolean;
+module.exports.lua_tolstring = lua_tolstring;
+module.exports.lua_tostring = lua_tostring; \ No newline at end of file