G.module

From GMod Wiki

Revision as of 20:38, 11 November 2009 by Crazy Quebecer (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Function
Syntax module( String Module Name, Table ... )
Where is this used?
Description:
Creates a table called moduleName and changes the environment to that table
Returns: nil
Part of Library: Global Functions
Realm: NewerShared.png
BBCode Link: [b][url=http://wiki.garrysmod.com/?title=G.module]G.module [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]


Examples

DescriptionMaking a simple module
Used onNewerShared.png
Code
-- iterators.lua
-- upvalues we need to use in the module
local next, _G = next, _G
 
module("iterators")
-- Keys Iterator, skips non-key enums
local function keyIterate( state, last )
	local value
	while true do
		local k, v = next( state, last )
		if not k then return end
		if k:match( "KEY_" ) then
			return k, v
		else
			last = k
		end
	end
end
function AllKeys()
	return keyIterate, _G, nil
end
--Example use
require( "iterators" )
for name, value in iterators.AllKeys() do
	print(name, value)
end
OutputPrints the KEY_* enums


DescriptionMaking a module with package.seeall
Used onNewerShared.png
Code
-- iterators.lua
 
module("iterators",package.seeall)
-- Keys Iterator, skips non-key enums
local function keyIterate( state, last )
	local value
	while true do
		local k, v = next( state, last )
		if not k then return end
		if k:match( "KEY_" ) then
			return k, v
		else
			last = k
		end
	end
end
function AllKeys()
	return keyIterate, _G, nil
end
OutputN/A


Additional Notes

See Also

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox