[LUA] Modify package.path globally
Enviado: 10 Ago 2020, 12:33
Note: This is for MoonLoader lua.
Hey guys, I tried setting package.path inside a script before launching another script from the previous script. The problem is that in the new script, package.path has its default value instead of the changed value. I though package.path was global? I have searched the internet for any workarounds and all say that I should modify package.path, but if it is local instead of global, then how do I set it for a script before launching it? Is there any way to pass a variable to script before launching it?
Here are two scripts:
1.lua:
[font][font]2nd moon[/font][/font][font][font] :[/font][/font]
Here is moonloader.log:
Notice how 1.lua changes the path, but the change only applies to 1.lua, and not 2.lua. Is there any way to globally change the path for lua module loading during runtime? Or any method to pass the modified package.path to the new script before launching it (using script.load) ?
Hey guys, I tried setting package.path inside a script before launching another script from the previous script. The problem is that in the new script, package.path has its default value instead of the changed value. I though package.path was global? I have searched the internet for any workarounds and all say that I should modify package.path, but if it is local instead of global, then how do I set it for a script before launching it? Is there any way to pass a variable to script before launching it?
Here are two scripts:
1.lua:
Código: Selecionar tudo
function main()
print("path:", package.path)
wait(500)
package.path = "C:\\Test;" .. package.path
print("changed path:", package.path)
endCódigo: Selecionar tudo
function main()
print("path:", package.path)
wait(1000)
print("changed path:", package.path)
endCódigo: Selecionar tudo
[20:25:28.789445] (script) 1.lua: path: D:\Grand Theft Auto San Andreas\GAME\moonloader\libstd\?.lua;D:\Grand Theft Auto San Andreas\GAME\moonloader\libstd\?\init.lua;D:\Grand Theft Auto San Andreas\GAME\moonloader\lib\?.lua;D:\Grand Theft Auto San Andreas\GAME\moonloader\lib\?.luac;D:\Grand Theft Auto San Andreas\GAME\moonloader\lib\?\init.lua;D:\Grand Theft Auto San Andreas\GAME\moonloader\lib\?\init.luac
[20:25:28.790444] (script) 2.lua: path: D:\Grand Theft Auto San Andreas\GAME\moonloader\libstd\?.lua;D:\Grand Theft Auto San Andreas\GAME\moonloader\libstd\?\init.lua;D:\Grand Theft Auto San Andreas\GAME\moonloader\lib\?.lua;D:\Grand Theft Auto San Andreas\GAME\moonloader\lib\?.luac;D:\Grand Theft Auto San Andreas\GAME\moonloader\lib\?\init.lua;D:\Grand Theft Auto San Andreas\GAME\moonloader\lib\?\init.luac
[20:25:32.814680] (script) 1.lua: changed path: C:\Test;D:\Grand Theft Auto San Andreas\GAME\moonloader\libstd\?.lua;D:\Grand Theft Auto San Andreas\GAME\moonloader\libstd\?\init.lua;D:\Grand Theft Auto San Andreas\GAME\moonloader\lib\?.lua;D:\Grand Theft Auto San Andreas\GAME\moonloader\lib\?.luac;D:\Grand Theft Auto San Andreas\GAME\moonloader\lib\?\init.lua;D:\Grand Theft Auto San Andreas\GAME\moonloader\lib\?\init.luac
[20:25:32.814680] (system) 1.lua: Script terminated. (id:1)
[20:25:32.814680] (script) 2.lua: changed path: D:\Grand Theft Auto San Andreas\GAME\moonloader\libstd\?.lua;D:\Grand Theft Auto San Andreas\GAME\moonloader\libstd\?\init.lua;D:\Grand Theft Auto San Andreas\GAME\moonloader\lib\?.lua;D:\Grand Theft Auto San Andreas\GAME\moonloader\lib\?.luac;D:\Grand Theft Auto San Andreas\GAME\moonloader\lib\?\init.lua;D:\Grand Theft Auto San Andreas\GAME\moonloader\lib\?\init.luac
[20:25:32.814680] (system) 2.lua: Script terminated. (id:2)