Tangent128 / luasdl2

A pure C binding of SDL 2.0 for Lua 5.1, Lua 5.2, and LuaJIT.
ISC License
385 stars 74 forks source link

trouble after install with luarocks #85

Closed SwissalpS closed 4 years ago

SwissalpS commented 4 years ago

installed using luarocks, downloaded example and tried to run it but get errors that SDL can't be found:

$ lua tutorial.lua
lua: tutorial.lua:6: module 'SDL' not found:
    no field package.preload['SDL']
    no file '/usr/share/lua/5.3/SDL.lua'
    no file '/usr/share/lua/5.3/SDL/init.lua'
    no file '/usr/lib64/lua/5.3/SDL.lua'
    no file '/usr/lib64/lua/5.3/SDL/init.lua'
    no file './SDL.lua'
    no file './SDL/init.lua'
    no file '/usr/lib64/lua/5.3/SDL.so'
    no file '/usr/lib64/lua/5.3/loadall.so'
    no file './SDL.so'
stack traceback:
    [C]: in function 'require'
    tutorial.lua:6: in main chunk
    [C]: in ?
$ lua -v
Lua 5.3.5  Copyright (C) 1994-2018 Lua.org, PUC-Rio

Which install step did I miss?

ShortRoundDev commented 4 years ago

Hi, @SwissalpS I'm not affiliated with this project but I had the same problem. You need to add your luarocks path to your LUA_PATH environment variable. When Lua looks for a required library file, it looks in all the directories listed by the LUA_PATH environment variable. I assume you are on either MacOS or Linux, based on your /usr/ paths. If you type

luarocks path

you will see an output for what your LUA_PATH should be. in a bash terminal, if you type

eval $(luarocks path)

it should set your LUA_PATH to the correct variable. If you want this to carry over to your next session, add that line to your ~/.bashrc file and it will set the path every time you open a terminal. I'm not sure if this solution will work on newer macbooks because they have moved from bash to zsh, and I have no experience with zsh. If you're using zsh and the problem continues, find someone who knows zsh and tell them the problem and they can probably help you

SwissalpS commented 4 years ago

Thank you very much @collinoswalt. That is a very good explanation.

I'm using Fedora 32 and no zsh Have made a wrapper shell script that first does

export LUA_CPATH="/usr/lib/lua/5.3/?.so;/usr/lib/lua/5.3/SDL/?.so;";

before running

lua mySDLapp.lua
eval $(luarocks path)

is better for most compatibility with other platforms. Thanks again :D