Skip to content

Instantly share code, notes, and snippets.

@x5gtrn
Created October 25, 2009 07:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save x5gtrn/217945 to your computer and use it in GitHub Desktop.
Save x5gtrn/217945 to your computer and use it in GitHub Desktop.
making module template
package.path = package.path .. ";../?.lua"
require "module1"
require "module2"
module1.showDate()
showGrobalVal()
-- 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!"
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