2017-03-20 41 views
0

我是Lua的新手。我整理了JS文件中使用castl到Lua 5.2:Lua:找不到模塊'castl.runtime'

castl -o script.js 

這創建了一個名爲script.js.lua文件。這是我的新LUA文件的第一行:

local _ENV = require("castl.runtime"); 

我試圖運行該文件與lua52 script.js.lua,但我得到這個錯誤:

C:\Program Files\lua-5.2.4_Win64_bin\lua52.exe: script.js.lua:1: module 'castl.runtime' not found: 
     no field package.preload['castl.runtime'] 
     no file 'C:\Program Files\lua-5.2.4_Win64_bin\lua\castl\runtime.lua' 
     no file 'C:\Program Files\lua-5.2.4_Win64_bin\lua\castl\runtime\init.lua' 
     no file 'C:\Program Files\lua-5.2.4_Win64_bin\castl\runtime.lua' 
     no file 'C:\Program Files\lua-5.2.4_Win64_bin\castl\runtime\init.lua' 
     no file '.\castl\runtime.lua' 
     no file 'C:\Program Files\lua-5.2.4_Win64_bin\castl\runtime.dll' 
     no file 'C:\Program Files\lua-5.2.4_Win64_bin\loadall.dll' 
     no file '.\castl\runtime.dll' 
     no file 'C:\Program Files\lua-5.2.4_Win64_bin\castl\runtime52.dll' 
     no file '.\castl\runtime52.dll' 
     no file 'C:\Program Files\lua-5.2.4_Win64_bin\castl.dll' 
     no file 'C:\Program Files\lua-5.2.4_Win64_bin\loadall.dll' 
     no file '.\castl.dll' 
     no file 'C:\Program Files\lua-5.2.4_Win64_bin\castl52.dll' 
     no file '.\castl52.dll' 
stack traceback: 
     [C]: in function 'require' 
     script.js.lua:1: in main chunk 
     [C]: in ? 

我缺少什麼?我在Windows 10

+0

從文檔:一個Lua運行時庫(位於'lua/castl /'),它允許執行'castl.js'編譯的代碼。將其添加到您的環境的LUA_PATH,它應該工作。 – hjpotter92

回答

0

要回答你的問題

What am I missing?

你的問題是,您使用的功能require,但你不知道這個功能做什麼。因此,你無法理解它在執行你所期望的錯誤時所拋出的錯誤。

所以首先指的是Lua的手冊: https://www.lua.org/manual/5.3/manual.html#pdf-require

在那裏,你會發現:

require searches for a Lua loader using the path stored in package.path. If that also fails, it searches for a C loader using the path stored in package.cpath. If that also fails, it tries an all-in-one loader (see package.searchers).

https://www.lua.org/manual/5.3/manual.html#pdf-package.path

The path used by require to search for a Lua loader.

At start-up, Lua initializes this variable with the value of the environment variable LUA_PATH_5_3 or the environment variable LUA_PATH or with a default path defined in luaconf.h, if those environment variables are not defined. Any ;; in the value of the environment variable is replaced by the default path.

有關更多閱讀: https://www.lua.org/pil/8.1.html

在任何網絡搜索中輸入「Lua require」也會爲您的問題提供很多解決方案。

由於hjpotter92已經在他的評論中聲明,你必須告訴你的計算機在哪裏尋找你想要的文件,除非它們已經位於默認文件夾中。 將文件的位置添加到LUA_PATH環境變量中,或者在調用相應的需求之前將其添加到package.path字符串中。

+0

我可能只是沒有正確理解你的指令,但我試圖在名爲'LUA_PATH'的環境變量對話框中添加一個新的用戶變量,設置爲'%USERPROFILE%\ Desktop \ repos \ clones \ castl \ lua \ castl'。之後,我得到了同樣的錯誤,除了錯誤只列出了「.dll」文件的「無文件」條目(不再有'.lua'文件)。 –

+0

因此,注意到沒有環境變量Lua在C:\ Program Files \ ua-5.2.4_Win64_bin \ lua \ castl \'中搜索'runtime.lua'文件,我將lua'文件夾複製到我的castl回購到那個位置(''C:\ Program Files \ lua-5.2.4_Win64_bin \'')。這似乎讓我把這個錯誤轉移到了另一個...... –