Hello There, Guest! Login Register


Using relative path in lua?
#1
Not so great at lua (or anything for the matter Tongue)

How can you get the relative path in lua?

Directory eg:
Scripts/list.lua
Scripts/Kanto/Leveling/route11.lua
Scripts/Johto/EV/route666.lua


I want to require list.lua in route11.lua (and route666)


I've tried;
package.path = package.path .. ";../?.lua"
require('list')
--require('Scripts.list')


Right now I have to either put everything in one folder (sucks shifting through several dozen files) or do sequential alternate pathing of folders (Kanto/Johto/Hoenn/basic lua files that will be used ina ll) which is what I'm currently doing, with the only other option is to copy list.lua in kanto/leveling, kanto/EV, johto/leveling etc etc. (not gonna happen).
penguins
 
Reply
#2
Wouldn't something like...

require("../../list")

... be enough?
 
Reply
#3
Nope.

[14:44:11] Could not load script MtMoon - Cerulean.lua:
MoonSharp.Interpreter.ScriptRuntimeException: module '../../list' not found
at PROBot.BotClient.LoadScript(String filename)
at PROShine.MainWindow.LoadScript()



I put list.lua in all previous folders (Scripts, Scripts/Kanto, Scripts/Johto) to be sure lol.
penguins
 
Reply
#4
Oh, I'm out of ideas then.
If you do not need to use require, would doFile work?

doFile("../../list.lua")

doFile is a very simple function, it just opens the specified file and executes it (adds it) inside the current file. There is no module path involved.
 
Reply
#5
Nope didn't work either;

[15:48:41] Could not load script MtMoon - Cerulean.lua:
MoonSharp.Interpreter.ScriptRuntimeException: attempt to call a nil value
at PROBot.BotClient.LoadScript(String filename)
at PROShine.MainWindow.LoadScript()

I guess I'll just stick to forward pathing. If anyone does manage to get this to work, let me know Big Grin
penguins
 
Reply
#6
My bad, it's not doFile but dofile.

http://luatut.com/dofile.html
 
Reply
#7
Ahh yes, that seems to work fine. I dont see any limitations to dofile over require (that I've read so far, I only plan on calling once before any functions) so yeah, should be good ^^


Thanks for the help.
penguins
 
Reply
  


Forum Jump:


Browsing: 1 Guest(s)