Difference between revisions of "Namespace"

From SoftMC-Wiki
Jump to: navigation, search
(Multiple global variables with identical names and different namespaces are allowed)
(Outside the "namespace" task)
Line 95: Line 95:
 
====Outside the "namespace" task====
 
====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>
 
+
<namespace>::<variable_name>
 +
</pre>
  
 
====Within the "namespace" task====
 
====Within the "namespace" task====

Revision as of 07:18, 24 April 2016

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

Unavailable for the following elements

- 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).

/* 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.













Priority

Priority within program block

Below static variables and above global variables.







Priority in watch command

Within commands

Commands using variables

- FOR loop - ASCII system function - PRINTUSING$ command - WATCH command














Commands using array names

- ARRAYSIZE system function - PASS Motion 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.





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 (*, ?).






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.