Eebado
Contributors
Posts: 165
|
Post by Eebado on Oct 29, 2019 20:06:09 GMT
I'd prefer that my code be split between multiple .lua files to keep them decluttered. How does everyone handle this separation? - How do you include other .lua files into the main file?
- When compiling, is it possible to include the libraries into a single file?
Thanks for the help.
|
|
|
Post by AnkuLua on Oct 30, 2019 14:24:33 GMT
You can use dofile() to include other lua files.
You can compile many files into one luac file. For example, luac5.1 -s -o main.luac lib1.lua lib2.lua main.lua
|
|
Eebado
Contributors
Posts: 165
|
Post by Eebado on Oct 30, 2019 23:44:34 GMT
Is that the design that you generally use when creating scripts?
|
|
|
Post by AnkuLua on Oct 31, 2019 13:18:57 GMT
Is that the design that you generally use when creating scripts? Yes. Compile into one file and encrypt the file.
|
|
Eebado
Contributors
Posts: 165
|
Post by Eebado on Nov 5, 2019 15:58:36 GMT
You can use dofile() to include other lua files. You can compile many files into one luac file. For example, luac5.1 -s -o main.luac lib1.lua lib2.lua main.lua When I attempt to do dofile("util.lua") and then compile them into a single file, it throws the following: If I include them into the same compiled binary, do I need to link them differently than using "dofile"? I've also attempted 'require "util" ' but that does not work either as it can't find the module.
|
|
|
Post by AnkuLua on Nov 6, 2019 6:55:18 GMT
You can use dofile() to include other lua files. You can compile many files into one luac file. For example, luac5.1 -s -o main.luac lib1.lua lib2.lua main.lua When I attempt to do dofile("util.lua") and then compile them into a single file, it throws the following: If I include them into the same compiled binary, do I need to link them differently than using "dofile"? I've also attempted 'require "util" ' but that does not work either as it can't find the module. Change the dofile to pcall. pcall(dofile, "util.lua")
|
|
Eebado
Contributors
Posts: 165
|
Post by Eebado on Nov 6, 2019 15:33:03 GMT
When I attempt to do dofile("util.lua") and then compile them into a single file, it throws the following: If I include them into the same compiled binary, do I need to link them differently than using "dofile"? I've also attempted 'require "util" ' but that does not work either as it can't find the module. Change the dofile to pcall. pcall(dofile, "util.lua") I'm not looking to suppress the exception, I'm looking to find the right way to include the actual library. What is the right way to include a file, using dofile, and then compile them together? Currently I only get errors that it can't fine the file, even though it's compiled into the same binary.
|
|
|
Post by AnkuLua on Nov 6, 2019 22:57:49 GMT
Change the dofile to pcall. pcall(dofile, "util.lua") I'm not looking to suppress the exception, I'm looking to find the right way to include the actual library. What is the right way to include a file, using dofile, and then compile them together? Currently I only get errors that it can't fine the file, even though it's compiled into the same binary. Just remove or overwrite dofile() in one compiled file condition.
|
|
Eebado
Contributors
Posts: 165
|
Post by Eebado on Nov 7, 2019 18:07:03 GMT
I'm not looking to suppress the exception, I'm looking to find the right way to include the actual library. What is the right way to include a file, using dofile, and then compile them together? Currently I only get errors that it can't fine the file, even though it's compiled into the same binary. Just remove or overwrite dofile() in one compiled file condition. So are you saying that in the event that I've compiled multiple files together, any Global variables or methods will be available automatically to other files which are compiled together?
|
|
|
Post by AnkuLua on Nov 7, 2019 23:01:10 GMT
Just remove or overwrite dofile() in one compiled file condition. So are you saying that in the event that I've compiled multiple files together, any Global variables or methods will be available automatically to other files which are compiled together? Compiling multiple files together will not change the locality of variables and methods. For example, with local.lua local hello = "hello" global = "global"
main.lua print(local) print(global) luac -s -o main.luac local.lua main.lua The result of main.luac is nil global
|
|