5
votes

I can't load .Lua-files from relative paths.

This works:

2.lua

function Math( v1, v2 )
 return v1 + v2
end

1.lua

package.path = package.path .. ';C:/Users/Lukas/Desktop/lua/function/?.lua'
require("2")
print(Math(1,6))

This doesn't work:

package.path = package.path .. './function/?.lua;'
require("2")
print(Math(1,6))

Couldn't find any solution for my problem.

2
Please leave the original question as it was. Add solutions as answers. - lhf

2 Answers

6
votes

You're missing a ; to separate the new path from the old one:

package.path = package.path .. ';./function/?.lua;'

require probably showed you this message:

no file './2.lua./function/2.lua'

which should have alerted you to the problem.

2
votes
package.path = package.path .. ';function/?.lua'

or

package.path = 'function/?.lua;' .. package.path

Up to you.