尝试运行Love2D应用程序时出错

时间:2017-02-24 19:31:39

标签: lua love2d

所以我刚刚用Lua / Love包安装了Lua,Love2D,LuaJIT和Sublime Text。当我尝试运行这个小程序时:

function love.draw()
    love.graphics.print("Hello World", 400, 300)
end

使用CTRL+SHIFT+B然后LuaLove - Run我收到此错误:

luajit: [path to program]\main.lua:1: attempt to index global 'love' (a nil value)
stack traceback:
    [path to program]\main.lua:1: in main chunk
    [C]: at 0x00402020
[Finished in 0.0s with exit code 1]
[cmd: ['luajit', '[path to program]\\main.lua']]
[dir: [path to program]]
[path: [every thing in path variable]]

我认为这与我在路径变量中没有正确使用Love的方法有关。但它就像这样:C:\Program Files\LOVE 我希望有人有解决方案。

1 个答案:

答案 0 :(得分:1)

您正在使用luajit解释器而不是LOVE可执行文件运行脚本,这会触发您看到的错误(因为LuaJIT解释器对love个对象一无所知)。您需要配置LuaLove以使用LOVE可执行文件;有关详细信息,请参阅documentation中的此说明:Both Sublime 2 and 3 require the directory of your LÖVE binary to be part of your PATH variable. You can avoid this by changing the "love" path in the build script. This is more complicated in Sublime 3.