From 23d15010edc905a3b7c123e85ef6d1960d3da039 Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Tue, 21 Feb 2017 08:46:48 +0100 Subject: luaG_ functions --- src/lfunc.js | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) (limited to 'src/lfunc.js') diff --git a/src/lfunc.js b/src/lfunc.js index c309147..7057f2d 100644 --- a/src/lfunc.js +++ b/src/lfunc.js @@ -99,9 +99,26 @@ const luaF_initupvals = function(L, cl) { } }; -module.exports.Proto = Proto; -module.exports.UpVal = UpVal; -module.exports.findupval = findupval; -module.exports.luaF_close = luaF_close; -module.exports.MAXUPVAL = 255; -module.exports.luaF_initupvals = luaF_initupvals; \ No newline at end of file +/* +** Look for n-th local variable at line 'line' in function 'func'. +** Returns null if not found. +*/ +const luaF_getlocalname = function(f, local_number, pc) { + for (let i = 0; i < f.locvars.length && f.locvars[i].startpc <= pc; i++) { + if (pc < f.locvars[i].endpc) { /* is variable active? */ + local_number--; + if (local_number == 0) + return f.locvars[i].varname; + } + } + return null; /* not found */ +} + + +module.exports.Proto = Proto; +module.exports.UpVal = UpVal; +module.exports.findupval = findupval; +module.exports.luaF_close = luaF_close; +module.exports.MAXUPVAL = 255; +module.exports.luaF_initupvals = luaF_initupvals; +module.exports.luaF_getlocalname = luaF_getlocalname \ No newline at end of file -- cgit v1.2.3-70-g09d2