Closed rohezal closed 1 year ago
If you use the following as a package path /home/my/path/?.lua
then your require should look like this requrie("myfile")
and it should not have the .lua
extension as it is already in the package path. The question mark ?
will be replaced with what you pass into the require
function. Take a look at this https://www.lua.org/pil/8.1.html
I believe there is no way to include a directory tree without some kind of additional system to walk through a directory tree. I myself have used dirent as set up here. Dirent is available on linux and mac by default and there is a MIT windows implementation in single file for lightweight cross platform use.
Based on the error message you show being so short, it looks as if the package path was not yet replaced when your code that contains require(testfunction.lua")
was run. The error should contain all of the paths searched, and it shows only two instead of several. I might be wrong, but I cant think of another reason from the top of my head.
I was to stupid to use lua.
Should have used
test = require "testfunction"
instead of
test = require "testfunction.lua"
My bad.
First I want to thank you for this amazing project :).
Is there prefered / better way to add a folder / all files in a folder to the lua package.path? Like
addPath("/home/user/luafiles/*);
oraddPathDirectory("/home/user/luafiles/)
;I am using sol2 for a game engine and call a lua script when an event happens (unit spawns etc.). When I use a require in the script, it fails, because it is not in the file is not in the lua package path.
When I use
"/home/my/path/?.lua"
the package path becomes "/home/my/path/lua.lua" which is strange.So I add lua file of my extracted map separately to the lua path. Which leads to a very long package path, which also fails.
package.path = /home/rohezal/.savage2/game/playerjoin_server.lua;/home/rohezal/.savage2/game/gamestartscript_client.lua;/home/rohezal/.savage2/game/worldscript_server.lua;/home/rohezal/.savage2/game/itemscript_client.lua;/home/rohezal/.savage2/game/json.lua;/home/rohezal/.savage2/game/item_activation_functions.lua;/home/rohezal/.savage2/game/playerjoinscript_client.lua;/home/rohezal/.savage2/game/playerspawn.lua;/home/rohezal/.savage2/game/worldscript_client.lua;/home/rohezal/.savage2/game/gamestartscript_server.lua;/home/rohezal/.savage2/game/deathscript_server.lua;/home/rohezal/.savage2/game/itemscript_server.lua;/home/rohezal/.savage2/game/testfunction.lua;/home/rohezal/.savage2/game/utility_functions.lua;/home/rohezal/.savage2/game/deathscript_client.lua;/home/rohezal/.savage2/game/buildingplaced.lua;/usr/local/share/lua/5.4/?.lua;/usr/local/share/lua/5.4/?/init.lua;/usr/local/lib/lua/5.4/?.lua;/usr/local/lib/lua/5.4/?/init.lua;./?.lua;./?/init.lua;/home/rohezal/.savage2/game/playerjoinscript_server.lua
` The error was something like:If I add this path after creating the monster package path, it works.
This is very confusing for me. May I ask why this works? testfunction is in the game folder when it is extracted. The path is correct. But it only works if I add the path an other time.