x5gtrn
10/25/2009 - 7:19 AM

making module template

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