Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Eval: Difference between revisions

From Jules RNG Wiki
Created page with "local p = {} function p.run(frame) -- Get the code passed as the first parameter local code = frame.args[1] or "" -- Load the string as a Lua chunk -- 'load' is preferred in newer Lua versions, 'loadstring' in 5.1 local func, err = loadstring(code) if not func then return "Lua Error: " .. err end -- Execute it return func() end return p"
 
No edit summary
 
Line 5: Line 5:
     local code = frame.args[1] or ""
     local code = frame.args[1] or ""
      
      
     -- Load the string as a Lua chunk
     -- Use 'load' instead of 'loadstring'
    -- 'load' is preferred in newer Lua versions, 'loadstring' in 5.1
    -- (Scribunto often disables loadstring or aliases it to load)
     local func, err = loadstring(code)
     local func, err = load(code)
      
      
     if not func then
     if not func then
         return "Lua Error: " .. err
         return "Lua Error: " .. (err or "Unknown error")
     end
     end
      
      
     -- Execute it
     -- Execute the code
     return func()
     return func()
end
end


return p
return p

Latest revision as of 03:51, 27 January 2026

Documentation for this module may be created at Module:Eval/doc

local p = {}

function p.run(frame)
    -- Get the code passed as the first parameter
    local code = frame.args[1] or ""
    
    -- Use 'load' instead of 'loadstring'
    -- (Scribunto often disables loadstring or aliases it to load)
    local func, err = load(code)
    
    if not func then
        return "Lua Error: " .. (err or "Unknown error")
    end
    
    -- Execute the code
    return func()
end

return p