import_type attempt to call global

439 views Asked by At

I'm using the latest lua interface and trying to run this code

luanet.load_assembly("Phoenix")
luanet.load_assembly("Phoenix.Structures")
NpcDialog = luanet.import_type("Phoenix.Structures.NpcDialog")

function npc(request, client)
    local dialog = new NpcDialog(client)
    dialog.Text("hi this is a test")
    dialog.Send()
end

but getting this error LuaInterface.LuaException: [string "chunk"]:6: attempt to call global 'NpcDialog ' (a nil value)

the exe name is Map Server.exe

Assembly name Map Server Default namespace Phoenix

it happens because the the assembly of the file different than the Assembly name and i don't know why!!

is there a way to make it work without changing the Assembly name

2

There are 2 answers

1
lhf On

Line 6 is valid Lua code but it does not do what you think. Lua parses it as if there was a ; after new, and so tries to call NpcDialog.

1
Oliver On

There is no new operator in Lua. Write:

function npc(request, client)
    local dialog = NpcDialog(client)

If you still get same problem after this fix, then NpcDialog is nil: maybe return value of import is nil, or maybe it gets nilled between the import line and the line that calls npc(r,c). Maybe try

assert( NpcDialog )

If this fails meaning that load_assembly("Phoenix") failed, it's probably because the assembly is not called "Phoenix" but "Map Server", so try

luanet.load_assembly("Map Server")
NpcDialog = luanet.import_type("Phoenix.Structures.NpcDialog")
assert(NpcDialog)