nakama
nakama copied to clipboard
Resolve lua module path with slash.
@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?
lua 5.1 open package treats .
as /
. So require("base.utils")
should equivalent to require("base/utils")
.
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 .
.