Created
October 25, 2009 07:19
-
-
Save x5gtrn/217945 to your computer and use it in GitHub Desktop.
making module template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package.path = package.path .. ";../?.lua" | |
require "module1" | |
require "module2" | |
module1.showDate() | |
showGrobalVal() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- setup module | |
local modname = ... | |
local M = {} | |
_G[modname] = M | |
package.loaded[modname] = M | |
-- import section | |
-- declare identifier needed in this module. | |
local _G = _G | |
local os = os | |
local print = print | |
local pairs = pairs | |
grobalVal1 = "hello world!" | |
-- end of access to outer | |
setfenv(1, M) | |
-- module start | |
function showDate () | |
print("os.date", os.date()) | |
print("os == _G.os", os == _G.os) | |
end | |
function showGrobalVal () | |
for v in pairs(_G) do | |
print(v) | |
end | |
end | |
grobalVal2 = "hello world!" | |
_G.grobalVal3 = "hello world!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function showGrobalVal () | |
print("grobalVal1", grobalVal1) | |
print("grobalVal2", grobalVal2) | |
print("grobalVal3", grobalVal3) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment