找不到模块-“找不到xxx模块”-Lua lang

时间:2020-06-09 16:25:13

标签: module lua require

如何使用此模块?

文件:Player.lua,我的模块

  local tabPlyer = require("Player")

请求模块的文件:Players.lua

[Running] lua "c:\Users\tct9\Documents\Lua\ScriptLua\Games\Players.lua"
lua: c:\Users\tct9\Documents\Lua\ScriptLua\Games\Players.lua:1: module 'Player' not found:
    no field package.preload['Player']
    no file 'c:\Users\tct9\Documents\Lua\lua\Player.lua'
    no file 'c:\Users\tct9\Documents\Lua\lua\Player\init.lua'
    no file 'c:\Users\tct9\Documents\Lua\Player.lua'
    no file 'c:\Users\tct9\Documents\Lua\Player\init.lua'
    no file '.\Player.lua'
    no file 'c:\Users\tct9\Documents\Lua\Player.dll'
    no file 'c:\Users\tct9\Documents\Lua\loadall.dll'
    no file '.\Player.dll'
    no file 'c:\Users\tct9\Documents\Lua\Player52.dll'
    no file '.\Player52.dll'
stack traceback:
    [C]: in function 'require'
    c:\Users\tct9\Documents\Lua\ScriptLua\Games\Players.lua:1: in main chunk
    [C]: in ?

错误消息:

class Kunde(models.Model):
   bruker = models.OneToOneField(
       User, null=True, blank=True, on_delete=models.CASCADE)
   # more fields here, so the model makes sense

   @property
   def fornavn(self): return self.user.first_name
   @property
   def etternavn(self): return self.user.last_name
   @property
   def email(self): return self.user.email

如何使用此模块?

重要说明

我正在使用VSCode。

PATH变量:...; C:\用户\ tct9 \文档\ Lua

变量LUA_PATH:C:\ Users \ tct9 \ Documents \ Lua

月亮路径:C:\ Users \ tct9 \ Documents \ Lua

脚本路径:C:\ Users \ tct9 \ Documents \ Lua \ ScriptLua \ Games

2 个答案:

答案 0 :(得分:2)

[运行中] lua “ c:\ Users \ tct9 \ Documents \ Lua \ ScriptLua \ Games \ Players.lua” lua: c:\ Users \ tct9 \ Documents \ Lua \ ScriptLua \ Games \ Players.lua:1:模块 找不到“玩家”: 没有字段package.preload ['Player'] 没有文件'c:\ Users \ tct9 \ Documents \ Lua \ lua \ Player.lua' 没有文件'c:\ Users \ tct9 \ Documents \ Lua \ lua \ Player \ init.lua' 没有文件'c:\ Users \ tct9 \ Documents \ Lua \ Player.lua' 没有文件'c:\ Users \ tct9 \ Documents \ Lua \ Player \ init.lua' 没有文件'。\ Player.lua' 没有文件'c:\ Users \ tct9 \ Documents \ Lua \ Player.dll' 没有文件'c:\ Users \ tct9 \ Documents \ Lua \ loadall.dll' 没有文件'。\ Player.dll' 没有文件'c:\ Users \ tct9 \ Documents \ Lua \ Player52.dll' 没有文件'。\ Player52.dll'

是Lua尝试查找的文件列表。如果您的Player.lua不是其中之一,则必须确保文件位于列出的路径之一中,或者在需要之前将包含文件的路径添加到package.path

通过脚本手动添加或将其添加到LUA_PATH

答案 1 :(得分:0)

我做了:

print (package.path)

我发现“ C:\ Users \ tct9 \ Documents \ Lua \ ?. lua”

然后我将其添加到package.path:

package.path = package.path .. "; C:\\Users\\tct9\\Documents\\Lua\\ScriptLua
\\Games\\?. lua"

之后,模块正常工作!