Difference between revisions of "Namespace"
(→Deletevar command) |
|||
(3 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
− | =Background= | + | |
− | Application development requires “semi” global variables that are associated with a task and do not create conflicts if the same name is defined many times with a different namespace. | + | = Background = |
− | Each task shall be able define a common shared variable with the same name, for example “var1”. Access from task is native like, “var1=1”, while access from command line or other tasks will require specification of a “namespace”, for example print task1::var1. | + | |
− | =Introduction= | + | Application development requires “semi” global variables that are associated with a task and do not create conflicts if the same name is defined many times with a different namespace. Each task shall be able define a common shared variable with the same name, for example “var1”. Access from task is native like, “var1=1”, while access from command line or other tasks will require specification of a “namespace”, for example print task1::var1. |
+ | |||
+ | = Introduction = | ||
+ | |||
This document describes the Namespace language feature. It presents the specifications and limitations of the feature and describes strategies in its implementation. | This document describes the Namespace language feature. It presents the specifications and limitations of the feature and describes strategies in its implementation. | ||
− | =Specifications= | + | = Specifications = |
− | ==Declaration== | + | |
− | ===Syntax=== | + | == Declaration == |
− | <pre> | + | |
− | Common shared <variable_name> as <data_type> Namespace is <namespace_name> | + | |
+ | === Syntax === | ||
+ | <pre>Common shared <variable_name> as <data_type> Namespace is <namespace_name>|* | ||
</pre> | </pre> | ||
− | ===Scope=== | + | === Scope === |
+ | |||
Global variables only. | Global variables only. | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | === | + | === Available for the following Data types === |
− | + | ||
− | + | *Long | |
− | + | *Double | |
− | + | *String | |
− | + | *String of UTF8 | |
+ | *Joint of <robot_type> | ||
+ | *Location of <robot_type> | ||
+ | *Generic Joint | ||
+ | *Generic Location | ||
+ | *Structure | ||
+ | *Const Long | ||
+ | *Const Double | ||
+ | *Const String | ||
+ | *Const String of UTF8 | ||
+ | *Const Joint of <robot_type> | ||
+ | *Const Location of <robot_type> | ||
+ | |||
+ | === Namespace name === | ||
− | + | The name of a PRG task without the extension. Since it's a task name, it cannot include more than 8 characters. Characters can only be alphabetical, numerical and underline. The namespace can be a reserved word. The namespace task doesn't have to be loaded in memory. | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | ==== | + | === Limitations === |
− | |||
− | |||
− | <pre> | + | ==== Unavailable for the following elements ==== |
− | MySub (byval param as long) namespace is MyTask → syntax error in prototype | + | |
+ | *Real axes | ||
+ | *Real groups | ||
+ | *Generic axes | ||
+ | *Generic groups | ||
+ | *User errors | ||
+ | *User notes | ||
+ | *User Semaphores | ||
+ | *Cam tables | ||
+ | *Compensation tables | ||
+ | *Conveyers | ||
+ | *PLS | ||
+ | |||
+ | ==== In functions ==== | ||
+ | |||
+ | *Cannot be used for function names. | ||
+ | *Cannot be used for parameter names. | ||
+ | <pre>MySub (byval param as long) namespace is MyTask → syntax error in prototype | ||
call MyTask::MySub(10) → syntax error in function call | call MyTask::MySub(10) → syntax error in function call | ||
MyFunc (param as long namespace is MyTask) as string → syntax error in prototype | MyFunc (param as long namespace is MyTask) as string → syntax error in prototype | ||
</pre> | </pre> | ||
− | ===Multiple global variables with identical names and different namespaces are allowed=== | + | |
+ | === Multiple global variables with identical names and different namespaces are allowed === | ||
+ | |||
Variables with identical names and different namespaces can also vary in number of dimensions (including scalars vs. arrays), data types (including different structure types) and robot types (for point variables). | Variables with identical names and different namespaces can also vary in number of dimensions (including scalars vs. arrays), data types (including different structure types) and robot types (for point variables). | ||
− | <pre> | + | ' name space is name of the task/library where it is defined |
− | + | ||
+ | Common shared Var1 as Long Namespace is * | ||
+ | <pre>' identical with different namespaces | ||
Common shared Var1 as Long Namespace is Task1 | Common shared Var1 as Long Namespace is Task1 | ||
Common shared Var1 as Long Namespace is Task2 | Common shared Var1 as Long Namespace is Task2 | ||
− | + | ' various number of dimensions with different namespaces | |
Common shared Var2 as Double Namespace is Task1 | Common shared Var2 as Double Namespace is Task1 | ||
Common shared Var2[10] as Double Namespace is Task2 | Common shared Var2[10] as Double Namespace is Task2 | ||
Common shared Var2[3][5][7] as Double Namespace is Task3 | Common shared Var2[3][5][7] as Double Namespace is Task3 | ||
− | + | ' various data types with different namespaces | |
Common shared Var3 as String of UTF8 Namespace is Task1 | Common shared Var3 as String of UTF8 Namespace is Task1 | ||
Common shared Var3 as Generic Location Namespace is Task2 | Common shared Var3 as Generic Location Namespace is Task2 | ||
− | + | ' various robot types with different namespaces | |
Common shared Var4 as Joint of XY Namespace is Task1 | Common shared Var4 as Joint of XY Namespace is Task1 | ||
Common shared Var4 as Joint of XYZR Namespace is Task2 | Common shared Var4 as Joint of XYZR Namespace is Task2 | ||
− | + | ' various structure types with different namespaces | |
Common shared Var5 as StructType1 Namespace is Task1 | Common shared Var5 as StructType1 Namespace is Task1 | ||
Common shared Var5 as StructType2 Namespace is Task2 | Common shared Var5 as StructType2 Namespace is Task2 | ||
− | + | ' and also one without a namespace | |
Common shared Var1 as Long | Common shared Var1 as Long | ||
</pre> | </pre> | ||
− | ==Applying to variables with namespaces== | + | == Applying to variables with namespaces == |
− | ===Access=== | + | |
− | ====Outside the "namespace" task==== | + | === Access === |
+ | |||
+ | ==== Outside the "namespace" task ==== | ||
+ | |||
The variable can only be accessed by using a prefix added to its name. The prefix will be composed of the namespace, followed by a double colon. | The variable can only be accessed by using a prefix added to its name. The prefix will be composed of the namespace, followed by a double colon. | ||
− | <pre> | + | <pre><namespace>::<variable_name> |
− | <namespace>::<variable_name> | ||
</pre> | </pre> | ||
− | ====Within the "namespace" task==== | + | ==== Within the "namespace" task ==== |
The variable can be accessed directly, without using its namespace prefix. It can also be accessed through its namespace prefix. | The variable can be accessed directly, without using its namespace prefix. It can also be accessed through its namespace prefix. | ||
− | + | | |
− | <pre> | + | <pre>Common shared Str1 as string namespace is StrTask |
− | Common shared Str1 as string namespace is StrTask | ||
In StrTask.PRG: | In StrTask.PRG: | ||
Line 120: | Line 131: | ||
Str = "IJKL" → Variable Str1 does not exist | Str = "IJKL" → Variable Str1 does not exist | ||
? Str1 →Variable Str1 does not exist | ? Str1 →Variable Str1 does not exist | ||
− | + | ' Unless there is a global Str1 without a namespace | |
StrTask::Str1 = "IJKL" | StrTask::Str1 = "IJKL" | ||
Line 126: | Line 137: | ||
− | + | ' Namespace can be used with a function\ subroutine argument | |
Common shared Str1 as string namespace is StrTask | Common shared Str1 as string namespace is StrTask | ||
Line 139: | Line 150: | ||
? MyFunc (Str1) Variable Str1 does not exist | ? MyFunc (Str1) Variable Str1 does not exist | ||
− | + | ' Unless there is a global Str1 without a namespace | |
</pre> | </pre> | ||
− | ===Priority=== | + | === Priority === |
− | ====Priority within program block==== | + | |
+ | ==== Priority within program block ==== | ||
Below static variables and above global variables. | Below static variables and above global variables. | ||
− | + | <pre>Common shared X1 as long = 1 | |
− | <pre> | ||
− | Common shared X1 as long = 1 | ||
Common shared X1 as long namespace is MyTask = 2 | Common shared X1 as long namespace is MyTask = 2 | ||
Line 163: | Line 173: | ||
Dim X3 as long = 600 | Dim X3 as long = 600 | ||
− | ?X1 → 2 | + | ?X1 → 2 ' X1 refers to the "namespaced" variable |
− | ?X2 → 40 | + | ?X2 → 40 ' X2 refers to the static variable |
− | ?X3 → 600 | + | ?X3 → 600 ' X3 refers to the local variable |
END PROGRAM | END PROGRAM | ||
Line 175: | Line 185: | ||
PROGRAM | PROGRAM | ||
− | X1 = 2 | + | X1 = 2 ' X1 refers to the "namespeced" variable |
END PROGRAM | END PROGRAM | ||
? MyTask.PRG.MyTask::X1 →2 | ? MyTask.PRG.MyTask::X1 →2 | ||
− | ? MyTask.PRG. X1 →2 | + | ? MyTask.PRG. X1 →2 ' X1 refers to the "namespeced" variable and not to the global variable |
</pre> | </pre> | ||
− | ====Priority in watch command==== | + | ==== Priority in watch command ==== |
− | |||
− | |||
− | |||
− | |||
− | |||
+ | === Within commands === | ||
+ | ==== Commands using variables ==== | ||
− | + | *FOR loop | |
− | + | *ASCII system function | |
− | + | *PRINTUSING$ command | |
− | + | *WATCH command | |
− | + | <pre>Common shared Index1 as long namespace is MyTask | |
− | |||
− | * FOR loop | ||
− | * ASCII system function | ||
− | * PRINTUSING$ command | ||
− | * WATCH command | ||
− | |||
− | <pre> | ||
− | Common shared Index1 as long namespace is MyTask | ||
Common shared Str1 as string namespace is MyTask | Common shared Str1 as string namespace is MyTask | ||
Line 216: | Line 215: | ||
PRINTU$ MyTask::Str1, "##"; 1 | PRINTU$ MyTask::Str1, "##"; 1 | ||
− | WATCH MyTask::Index1 | + | WATCH MyTask::Index1 ' Available only from terminal |
Inside MyTask.PRG: | Inside MyTask.PRG: | ||
Line 229: | Line 228: | ||
</pre> | </pre> | ||
− | ====Commands using array names==== | + | ==== Commands using array names ==== |
− | * ARRAYSIZE system function | + | |
− | * PASS Motion command | + | *ARRAYSIZE system function |
− | <pre> | + | *PASS Motion command |
− | Common shared JntArray[4] as joint of XYZR namespace is MyTask | + | <pre>Common shared JntArray[4] as joint of XYZR namespace is MyTask |
Common shared DblArray[4] as double namespace is MyTask | Common shared DblArray[4] as double namespace is MyTask | ||
Line 240: | Line 239: | ||
PASS Scara Nodes = MyTask:: JntArray Stretchvector = MyTask:: DblArray | PASS Scara Nodes = MyTask:: JntArray Stretchvector = MyTask:: DblArray | ||
− | ? ARRAYSIZE(MyTask :: JntArray, 1) | + | ? ARRAYSIZE(MyTask :: JntArray, 1) |
Inside MyTask.PRG: | Inside MyTask.PRG: | ||
Line 250: | Line 249: | ||
</pre> | </pre> | ||
− | ====Save command==== | + | ==== Save command ==== |
+ | |||
In order to save a "namespaced" variable, the variable name string- parameter must include the namespace prefix, even inside the namespace task. | In order to save a "namespaced" variable, the variable name string- parameter must include the namespace prefix, even inside the namespace task. | ||
− | <pre> | + | <pre>Common shared Var1 as long namespace is MyTask = 10 |
− | Common shared Var1 as long namespace is MyTask = 10 | ||
Common shared Var1 as long = 1000 | Common shared Var1 as long = 1000 | ||
Namespace prefix should be used both inside and outside MyTask.PRG: | Namespace prefix should be used both inside and outside MyTask.PRG: | ||
− | + | ' saving a “namespaced” variable | |
Save File = "MySave.PRG" Type = Long Variablename = "MyTask::Var1" | Save File = "MySave.PRG" Type = Long Variablename = "MyTask::Var1" | ||
Line 264: | Line 263: | ||
MYTASK::VAR1 = 10 | MYTASK::VAR1 = 10 | ||
− | + | ' saving a regular (that doesn’t have a namespace) global variable | |
Save File = "MySave.PRG" Type = Long Variablename = " Var1" | Save File = "MySave.PRG" Type = Long Variablename = " Var1" | ||
Line 272: | Line 271: | ||
</pre> | </pre> | ||
− | ==== Varlist command==== | + | ==== Varlist command ==== |
− | In order to exhibit "namespaced" variables through Varlist command, the variables must include a namespace prefix, which can be partial with wild cards (*, ?). | + | |
− | <pre> | + | In order to exhibit "namespaced" variables through Varlist command, the variables must include a namespace prefix, which can be partial with wild cards (*, ?). |
− | Common shared Var1 as long namespace is MyTask1 = 10 | + | <pre>Common shared Var1 as long namespace is MyTask1 = 10 |
Common shared Var2 as double namespace is MyTask1 = 0.5 | Common shared Var2 as double namespace is MyTask1 = 0.5 | ||
Common shared Var1 as string namespace is MyTask2 = "ABC" | Common shared Var1 as string namespace is MyTask2 = "ABC" | ||
Line 287: | Line 286: | ||
? Varlist *::* →MyTask1::Var1, MyTask1::Var2, MyTask2::Var1 | ? Varlist *::* →MyTask1::Var1, MyTask1::Var2, MyTask2::Var1 | ||
− | + | ' Without any part of the namespace prefix | |
? Varlist Var* →No variables found | ? Varlist Var* →No variables found | ||
</pre> | </pre> | ||
− | ====Deletevar command==== | + | ==== Deletevar command ==== |
− | |||
− | |||
− | <pre> | + | In order to delete "namespaced" variables through Deletevar command, the variables must include a namespace prefix, which can be partial with wild cards (*, ?). As with regular global variables, "namespaced" variables cannot be deleted until all tasks applying to these variables will be unloaded. |
− | Common shared Var1 as long namespace is MyTask1 = 10 | + | <pre>Common shared Var1 as long namespace is MyTask1 = 10 |
Common shared Var2 as double namespace is MyTask1 = 0.5 | Common shared Var2 as double namespace is MyTask1 = 0.5 | ||
Common shared Var1 as string namespace is MyTask2 = "ABC" | Common shared Var1 as string namespace is MyTask2 = "ABC" | ||
Line 308: | Line 305: | ||
Deletevar *::* → MyTask1::Var1, MyTask1::Var2, MyTask2::Var1 | Deletevar *::* → MyTask1::Var1, MyTask1::Var2, MyTask2::Var1 | ||
− | + | ' Without any part of the namespace prefix | |
Deletevar Var* → No variables found | Deletevar Var* → No variables found | ||
</pre> | </pre> |
Latest revision as of 15:29, 10 July 2019
Contents
Background
Application development requires “semi” global variables that are associated with a task and do not create conflicts if the same name is defined many times with a different namespace. Each task shall be able define a common shared variable with the same name, for example “var1”. Access from task is native like, “var1=1”, while access from command line or other tasks will require specification of a “namespace”, for example print task1::var1.
Introduction
This document describes the Namespace language feature. It presents the specifications and limitations of the feature and describes strategies in its implementation.
Specifications
Declaration
Syntax
Common shared <variable_name> as <data_type> Namespace is <namespace_name>|*
Scope
Global variables only.
Available for the following Data types
- Long
- Double
- String
- String of UTF8
- Joint of <robot_type>
- Location of <robot_type>
- Generic Joint
- Generic Location
- Structure
- Const Long
- Const Double
- Const String
- Const String of UTF8
- Const Joint of <robot_type>
- Const Location of <robot_type>
Namespace name
The name of a PRG task without the extension. Since it's a task name, it cannot include more than 8 characters. Characters can only be alphabetical, numerical and underline. The namespace can be a reserved word. The namespace task doesn't have to be loaded in memory.
Limitations
- Real axes
- Real groups
- Generic axes
- Generic groups
- User errors
- User notes
- User Semaphores
- Cam tables
- Compensation tables
- Conveyers
- PLS
In functions
- Cannot be used for function names.
- Cannot be used for parameter names.
MySub (byval param as long) namespace is MyTask → syntax error in prototype call MyTask::MySub(10) → syntax error in function call MyFunc (param as long namespace is MyTask) as string → syntax error in prototype
Multiple global variables with identical names and different namespaces are allowed
Variables with identical names and different namespaces can also vary in number of dimensions (including scalars vs. arrays), data types (including different structure types) and robot types (for point variables).
' name space is name of the task/library where it is defined
Common shared Var1 as Long Namespace is *
' identical with different namespaces Common shared Var1 as Long Namespace is Task1 Common shared Var1 as Long Namespace is Task2 ' various number of dimensions with different namespaces Common shared Var2 as Double Namespace is Task1 Common shared Var2[10] as Double Namespace is Task2 Common shared Var2[3][5][7] as Double Namespace is Task3 ' various data types with different namespaces Common shared Var3 as String of UTF8 Namespace is Task1 Common shared Var3 as Generic Location Namespace is Task2 ' various robot types with different namespaces Common shared Var4 as Joint of XY Namespace is Task1 Common shared Var4 as Joint of XYZR Namespace is Task2 ' various structure types with different namespaces Common shared Var5 as StructType1 Namespace is Task1 Common shared Var5 as StructType2 Namespace is Task2 ' and also one without a namespace Common shared Var1 as Long
Applying to variables with namespaces
Access
Outside the "namespace" task
The variable can only be accessed by using a prefix added to its name. The prefix will be composed of the namespace, followed by a double colon.
<namespace>::<variable_name>
Within the "namespace" task
The variable can be accessed directly, without using its namespace prefix. It can also be accessed through its namespace prefix.
Common shared Str1 as string namespace is StrTask In StrTask.PRG: Program StrTask::Str1 = "ABCD" ? Str1 → ABCD Str1 = "EFGH" ? StrTask::Str1 → EFGH End Program From terminal, another task or library: Str = "IJKL" → Variable Str1 does not exist ? Str1 →Variable Str1 does not exist ' Unless there is a global Str1 without a namespace StrTask::Str1 = "IJKL" ? StrTask::Str1 →IJKL ' Namespace can be used with a function\ subroutine argument Common shared Str1 as string namespace is StrTask In StrTask.PRG: ? MyFunc (StrTask::Str1) ? MyFunc (Str1) From terminal, another task or library: ? MyFunc (StrTask::Str1) ? MyFunc (Str1) Variable Str1 does not exist ' Unless there is a global Str1 without a namespace
Priority
Priority within program block
Below static variables and above global variables.
Common shared X1 as long = 1 Common shared X1 as long namespace is MyTask = 2 Common shared X2 as long namespace is MyTask = 30 Dim shared X2 as long = 40 Common shared X3 as long namespace is MyTask = 500 Dim shared X3 as long = 40 In MyTask.PRG: PROGRAM Dim X3 as long = 600 ?X1 → 2 ' X1 refers to the "namespaced" variable ?X2 → 40 ' X2 refers to the static variable ?X3 → 600 ' X3 refers to the local variable END PROGRAM Common shared X1 as long = 10 Common shared X1 as long namespace is MyTask In MyTask.PRG (task paused): PROGRAM X1 = 2 ' X1 refers to the "namespeced" variable END PROGRAM ? MyTask.PRG.MyTask::X1 →2 ? MyTask.PRG. X1 →2 ' X1 refers to the "namespeced" variable and not to the global variable
Priority in watch command
Within commands
Commands using variables
- FOR loop
- ASCII system function
- PRINTUSING$ command
- WATCH command
Common shared Index1 as long namespace is MyTask Common shared Str1 as string namespace is MyTask Outside and inside MyTask.PRG: For MyTask::Index1 = 1 to 10 … Next MyTask::Index1 ? ASCII (MyTask::Str1, 1) PRINTU$ MyTask::Str1, "##"; 1 WATCH MyTask::Index1 ' Available only from terminal Inside MyTask.PRG: For Index1 = 1 to 10 … Next Index1 ? ASCII(Str1, 1) PRINTU$ Str1, "##"; 1
Commands using array names
- ARRAYSIZE system function
- PASS Motion command
Common shared JntArray[4] as joint of XYZR namespace is MyTask Common shared DblArray[4] as double namespace is MyTask Outside and inside MyTask.PRG: PASS Scara Nodes = MyTask:: JntArray Stretchvector = MyTask:: DblArray ? ARRAYSIZE(MyTask :: JntArray, 1) Inside MyTask.PRG: PASS Scara Nodes = JntArray Stretchvector = DblArray ? ARRAYSIZE(JntArray, 1)
Save command
In order to save a "namespaced" variable, the variable name string- parameter must include the namespace prefix, even inside the namespace task.
Common shared Var1 as long namespace is MyTask = 10 Common shared Var1 as long = 1000 Namespace prefix should be used both inside and outside MyTask.PRG: ' saving a “namespaced” variable Save File = "MySave.PRG" Type = Long Variablename = "MyTask::Var1" Result in MySave.PRG: MYTASK::VAR1 = 10 ' saving a regular (that doesn’t have a namespace) global variable Save File = "MySave.PRG" Type = Long Variablename = " Var1" Result in MySave.PRG: VAR1 = 1000
Varlist command
In order to exhibit "namespaced" variables through Varlist command, the variables must include a namespace prefix, which can be partial with wild cards (*, ?).
Common shared Var1 as long namespace is MyTask1 = 10 Common shared Var2 as double namespace is MyTask1 = 0.5 Common shared Var1 as string namespace is MyTask2 = "ABC" At least part of the namespace prefix must be used in Varlist command: ? Varlist MyTask1::Var1 →MyTask1::Var1 ? Varlist MyTask1::* →MyTask1::Var1, MyTask1::Var2 ? Varlist MyTask?::Var? →MyTask1::Var1, MyTask1::Var2, MyTask2::Var1 ? Varlist *::Var1 →MyTask1::Var1, MyTask2::Var1 ? Varlist *::* →MyTask1::Var1, MyTask1::Var2, MyTask2::Var1 ' Without any part of the namespace prefix ? Varlist Var* →No variables found
Deletevar command
In order to delete "namespaced" variables through Deletevar command, the variables must include a namespace prefix, which can be partial with wild cards (*, ?). As with regular global variables, "namespaced" variables cannot be deleted until all tasks applying to these variables will be unloaded.
Common shared Var1 as long namespace is MyTask1 = 10 Common shared Var2 as double namespace is MyTask1 = 0.5 Common shared Var1 as string namespace is MyTask2 = "ABC" At least part of the namespace prefix must be used in Deletevar command: Deletevar MyTask1::Var1 →MyTask1::Var1 Deletevar MyTask1::* → MyTask1::Var1, MyTask1::Var2 Deletevar MyTask?::Var? → MyTask1::Var1, MyTask1::Var2, MyTask2::Var1 Deletevar *::Var1 MyTask1::Var1, MyTask2::Var1 Deletevar *::* → MyTask1::Var1, MyTask1::Var2, MyTask2::Var1 ' Without any part of the namespace prefix Deletevar Var* → No variables found