--[[-------------------------------------------------------------
Script Name: TrailMyx's Namespace Interface Routines
Author: TrailMyx
Version: v7
Shard OSI / FS: sure, why not?
Revision Date: 9/10/2010
Purpose: Collection of routines to simulate the namespace functions found in
the original EasyUO
Functions:
New(o) - creates a new namespace object. You will only need one.
OEUO example: myns = TM_NS:New() -- create TM_NS object
EUO example: none
Push() - pushes or "remembers" current nsname and nstype from the stack
OEUO example: myns:Push() -- saves nsname and nstype
EUO example: namespace push
Pop() - pops or "recalls" the saved nsname and nstype from the stack
OEUO example: myns:Pop() -- recall last saved nsname and nstype
EUO example: namespace pop
Switch(ns_type, ns_name) - sets the current values of nsname and nstype
OEUO example: myns:Switch("local","ns1")
EUO example: namespace local ns1
Exists(ns_type, ns_name) - determines if a namespace exists (true)
OEUO example: myns:Exists("local","ns1") -- true if exists, otherwise false
EUO example: no equivalent
Read(item) - reads a variable from the current namespace
OEUO example: myns:Read("var1")
EUO example: !var1
ReadAbs(ns_type, ns_name, item) - reads a variable from a specified namespace
OEUO example: myns:Read("global", "ns1", "var1") -- reads "var1" from global:ns1
EUO example: namespace copy var1 from global ns1 ; careful, overwrites current var1
Write(item, value) - writes a value to a variable in the current namespace
OEUO example: myns:Write("var1", 5)
EUO example: !var = 5
WriteAbs(ns_type, ns_name, item, value) - writes a writes a value to a variable in a specified namespace
OEUO example: myns:Write("local", "ns1", "var1", 5)
EUO example: namespace copy var1 to local ns1
Clear() - clears the contents of the current namespace
OEUO example: myns:Clear()
EUO example: namespace clear
CopyTo(ns_type, ns_name, item) - copies current namespace values to specified NS
OEUO example: myns:CopyTo("local", "ns1", "var") -- copies vars starting with "var" to local:ns1
OEUO example: myns:CopyTo("local", "ns1", "*") -- copies everything to local:ns1
EUO example: namespace copy var* to local ns1
EUO example: namespace copy * to local ns1 ; copy everything
CopyFrom(ns_type, ns_name, item) - copies specific values from namespace to local namespace
OEUO example: myns:CopyFrom("local", "ns1", "var") -- copies vars starting with "var" from local:ns1
OEUO example: myns:CopyFrom("local", "ns1", "*") -- copies everything from local:ns1
EUO example: namespace copy var* from local ns1
EUO example: namespace copy * from local ns1 ; copy everything
Match(ns_type, ns_name, item) - creates a table of items that match "item" from specified namespace
OEUO example: tbl = myns:Match("local", "ns1", "var") -- creates table(tbl) that holds matchs {varname, value}
EUO example: none
Special Thanks:
Beta testers:
Bug testers:
---------------------------------------------------------------]]
See attached sample code commented out a the bottom.
This collection of routines gives the scripter much of the same functionality lost when EUO moved to Lua. Global and Local namespaces are again available. See the syntax as described in the header.
The lookup process uses indexed tables for exceptional speed.
Note that with the CopyTo and CopyFrom, these are automatically considered wildcard arguments. Also the argument of "*" can be used to copy EVERYTHING. If you need to copy just one variable, then use ReadAbs() and WriteAbs()
Also notice that you can copy from local<-->global namespaces with these functions. Very useful.