添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
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.

thats the thing though I want it to put it in the global namespace thats why I was doing it that way. I don't want to have to require it and assign all of the functions and constants to a variable for every file, there could be hundreds of functions and constants – Shadowblitz16 May 2, 2018 at 1:46

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.