Skip to content

try to run in Lua 5.2 #7

@supipd

Description

@supipd

Hi,
I tried run lua-inspect in Lua 5.2.0 (compiled with LUA_COMPAT_ALL) and had errors (getfenv,setfenv).

I made some changes, and it seems, that goes -> C:\JS_LUA\lua-5.2.0\Debug\lua52.exe test.lua successfully produces examples.html
I'm sure (Lua newbie), that my changes are not fully correct, if somebody know, how do things correctly, please report.

...\metalualib\metalua\base.lua (only 1 row chaged):

....
row 9:   metalua={} -- if not metalua then rawset(getfenv(), 'metalua', { }) end
....

...\luainspect (version dependant empty getfenv/setfenv function added):

#!/usr/bin/env lua

-- Set Lua library paths.
-- based on findbin -- https://gist.github.com/1342365
-- and lib -- https://gist.github.com/1342319
local function findbin()
  local script = arg and arg[0] or ''
  local bin = script:gsub('[/\\]?[^/\\]+$', '') -- remove file name
  if bin == '' then bin = '.' end
  return bin
end
local bin = findbin()
package.path = package.path..';'..bin..'/metalualib/?.lua'
package.path = package.path..';'..bin..'/luainspectlib/?.lua'

-- added for dummy (in Lua 5.2 not exists) functions
print (_VERSION)
if _VERSION=="Lua 5.2" then
    function getfenv()
    end
    function setfenv() 
    end
    function debug.getfenv() 
    end
    function debug.setfenv() 
    end
end

-- print (getfenv,setfenv,debug.getfenv,debug.setfenv)
require 'luainspect.command'

Test output:

C:\JS_LUA\davidm-lua-inspect>C:\JS_LUA\lua-5.2.0\Debug\lua52.exe test.lua
Lua 5.2
warning: [string " context.apply_value('shape$', {color='?', si..."]:1: attempt to index global 'context' (a nil value) :   context.apply_value('shape$', {color
='?', size={x=1,y=1}, f=function() return "?" end})
warning: [string " context.apply_value('^n.*', number)"]:1: attempt to index global 'context' (a nil value) :   context.apply_value('^n.*', number)
warning: [string " context.apply_value('^s.*', string)"]:1: attempt to index global 'context' (a nil value) :   context.apply_value('^s.*', string)
warning: [string " context.apply_value('^b.*', boolean)"]:1: attempt to index global 'context' (a nil value) :   context.apply_value('^b.*', boolean)
status: loading:math
warning: module not found: math
output written to examples.html

C:\JS_LUA\davidm-lua-inspect>lua test.lua
Lua 5.1
status: loading:math
warning: module not found: math
output written to examples.html

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions