nakama icon indicating copy to clipboard operation
nakama copied to clipboard

Resolve lua module path with slash.

Open deflinhec opened this issue 3 years ago • 4 comments

deflinhec avatar Sep 02 '21 18:09 deflinhec

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Sep 02 '21 18:09 CLAassistant

@deflinhec Thanks for the PR! Could you add a bit of detail on what the issue you're trying to solve is, example(s) of prior behaviour, and example(s) of behaviour after your PR would be applied?

zyro avatar Sep 02 '21 18:09 zyro

lua 5.1 open package treats . as /. So require("base.utils") should equivalent to require("base/utils").

deflinhec avatar Sep 02 '21 18:09 deflinhec

I was porting some lua files from different project into Nakama module directory and errors shown right after server restart.

{"level":"info","ts":"2021-09-02T16:33:24.755Z","caller":"server/runtime_lua.go:111","msg":"Initialising Lua runtime provider","path":"data/modules"}
{"level":"error","ts":"2021-09-02T16:33:24.766Z","caller":"server/runtime_lua.go:1955","msg":"Could not complete runtime invocation","error":"data/modules/lobby/rpc.lua:15: module base/util not found:\n\tno field package.preload['base/util']\n\tno cached module 'base/util', \nstack traceback:\n\t[G]: in function 'require'\n\tdata/modules/lobby/rpc.lua:15: in main chunk\n\t[G]: ?"}
{"level":"error","ts":"2021-09-02T16:33:24.766Z","caller":"server/runtime.go:590","msg":"Error initialising Lua runtime provider","error":"data/modules/lobby/rpc.lua:15: module base/util not found:\n\tno field package.preload['base/util']\n\tno cached module 'base/util', \nstack traceback:\n\t[G]: in function 'require'\n\tdata/modules/lobby/rpc.lua:15: in main chunk\n\t[G]: ?"}
{"level":"fatal","ts":"2021-09-02T16:33:24.767Z","caller":"v3/main.go:148","msg":"Failed initializing runtime modules","error":"data/modules/lobby/rpc.lua:15: module base/util not found:\n\tno field package.preload['base/util']\n\tno cached module 'base/util', \nstack traceback:\n\t[G]: in function 'require'\n\tdata/modules/lobby/rpc.lua:15: in main chunk\n\t[G]: ?"}

After removing dependency between files, I'm also confuse with this log message. All modules has been load correctly, but not found when requiring them.

{"level":"info","ts":"2021-09-02T15:34:23.824Z","caller":"server/runtime.go:611","msg":"Found runtime modules","count":3,"modules":["base/util.lua","lobby/control.lua","lobby/rpc.lua"]}

Then I found that all lua module stores in moduleCache converts / to ..

deflinhec avatar Sep 02 '21 20:09 deflinhec