Skip to content

json.lua : attempt to call a nil value (global 'module') #2

@xingchch

Description

@xingchch

Compile json.lua with luac from lua-5.3.1 , run the binary code but got the error :attempt to call a nil value (global 'module')

if we want to run binary code compiled with luac in lua-5.3.1 ,below way to build module will cause runtime error:

local base = _G

-- Module declaration

module("json")

the right way might be like this:

local moduleName = json
local M = {} -- 局部的变量
_G[moduleName] = M -- 将这个局部变量最终赋值给模块名
package.loaded[moduleName] = M
..........

@nirenr ,Could you please verify this error and fixed it .

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