Lua needs a relative path

I cannot load a .Lua file from a relative path.

This works:

2.lua

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

1.lua

< pre>package.path = package.path ..’;C:/Users/Lukas/Desktop/lua/function/?.lua’
require(“2”)
print(Math(1, 6))

This does not work:

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

Can’t find a solution to my problem.

you missed it; separate the new path from the old path:

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

Require may show you this message:

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

Should remind you of this problem.

I cannot load .Lua files from relative paths. < p>

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 does not work:

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

Can’t find a solution to my problem.

You Missed it; separate the new path from the old path:

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

pre>

require may show you this message:

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

You should be reminded of this problem.

Leave a Comment

Your email address will not be published.