Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lua require relative path

Tags:

lua

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.

like image 841
Lukas Avatar asked Oct 04 '13 13:10

Lukas


1 Answers

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.

like image 82
lhf Avatar answered Nov 09 '22 16:11

lhf