aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lapi.js49
-rw-r--r--src/lobject.js2
2 files changed, 30 insertions, 21 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
diff --git a/src/lobject.js b/src/lobject.js
index 5860f67..3a519c9 100644
--- a/src/lobject.js
+++ b/src/lobject.js
@@ -191,7 +191,7 @@ class LClosure extends TValue {
class CClosure extends TValue {
- constructor(n, f) {
+ constructor(f, n) {
super(CT.LUA_TCCL, null);
this.f = f;