From e02fa80026ed5789e04ab865f238c8d184487dd2 Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Fri, 17 Feb 2017 07:39:04 +0100 Subject: JS closure --- src/lapi.js | 50 ++++++++++++++++++++++++++++---------------------- src/lua.js | 2 +- 2 files changed, 29 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/lapi.js b/src/lapi.js index dd74552..2bef5a5 100644 --- a/src/lapi.js +++ b/src/lapi.js @@ -151,7 +151,7 @@ const lua_pushcclosure = function(L, fn, n) { 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, fn, n); + let cl = new CClosure(fn, n); L.top -= n; while (n--) { @@ -165,10 +165,14 @@ const lua_pushcclosure = function(L, fn, n) { assert(L.top <= L.ci.top, "stack overflow"); }; +const lua_pushjsclosure = lua_pushcclosure; + const lua_pushcfunction = function(L, fn) { lua_pushcclosure(L, fn, 0); }; +const lua_pushjsfunction = lua_pushcfunction; + const lua_pushboolean = function(L, b) { L.stack[L.top] = new TValue(CT.LUA_TBOOLEAN, b ? true : false); @@ -307,24 +311,26 @@ 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_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; -module.exports.lua_callk = lua_callk; -module.exports.lua_call = lua_call; \ 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_pushjsclosure = lua_pushjsclosure; +module.exports.lua_pushjsfunction = lua_pushjsfunction; +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; +module.exports.lua_callk = lua_callk; +module.exports.lua_call = lua_call; \ No newline at end of file diff --git a/src/lua.js b/src/lua.js index 58cc0cd..6ebf250 100644 --- a/src/lua.js +++ b/src/lua.js @@ -68,7 +68,7 @@ const LUA_MINSTACK = 20; const LUA_REGISTRYINDEX = -luaconf.LUAI_MAXSTACK - 1000; const lua_upvalueindex = function(i) { - LUA_REGISTRYINDEX - i; + return LUA_REGISTRYINDEX - i; }; /* predefined values in the registry */ -- cgit v1.2.3-70-g09d2