Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
can someone tell me if its possible in lua to do something like this?
where it uses a module file to include other module files using a single lua header?
--main.lua
require "std"
local test = WIDGETS[0]
--std.lua
require "std.constants" -- this is the problem its local to this file only
require "std.functions" -- this is the problem its local to this file only
-std.constants.lua
WIDGETS =
NONE,
PANEL,
BUTTON
I need to do something like this so I don't have to type std.constants.WIDGET[whatever]
You could add the line local WIDGETS = std.constants.WIDGETS
after your require "std"
. Then, all functions in that file can reference WIDGETS
without polluting the global namespace:
-- main.lua
require "std"
local WIDGETS = std.constants.WIDGETS
local test = WIDGETS[0]
You would only have to do this once per file.
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.