VSL Tips

From Virtools Wiki

Jump to: navigation, search


This is a list of Do's and Dont's when coding VSL.


Contents

VSL Coding DOs

  • DO be careful of the Undo function (Ctrl+Z). It does not always work correctly.
  • ALWAYS initialize your static variables before using them. One method is to use a unique bIn, such as an "Init" bIn, which is activated before the script actually needs to use the static variables.
  • DO constantly save versions of your CMOs when working in VSL. The entire VSL Manager can become corrupt and lose ALL of your VSL scripts. This behavior is suspected to happen when a VSL script attempts to access a NULL ptr, but this hasn't been 100% reproducible.


VSL Coding DON'Ts

  • DO NOT test bIns with == true. The if will not evaluate correctly. See Example 1.
  • DO NOT use static variables in dynamic VSL Scripts; that is scripts that are copied or loaded at runtime. They cause hidden bugs and also remember their values even when the scripts do not exist!
  • NEVER trust that a static variable will reset it's value when reseting the context.
  • DO NOT EVER attempt to set a value on a pIn (ParameterIn). It will rarely work, cause odd inexplicable behavior, and be difficult to debug. Treat all pIns as const!


C++ Binding

  • DO NOT bind variables of type "bool", the value will not transfer to VSL correctly. Bind boolean values with CKBOOL, XBOOL, or int.
  • Be careful when binding XString. Best to bind a char * when passing a string from VSL to C++ and us a pass-by-reference XString& when getting string from C++ to VSL.
  • DO NOT bind virtual member functions to VSL of a class bound to VSL when that class inherits that function from another class which also declares that function as virtual, but is not bound to VSL. See Example 2.


Examples

Example 1

Code:

Correct:  if( bIn1 ) ... 
Incorrect: if( bIn1 == true ) ...  


Example 2

Class A declares a virtual function, or pure virtual function, foo();
Class B inherits from A.
B and B's members are bound to VSL.
A and its members are NOT bound to vsl, so calls to foo and pureFoo on an instance of class B in VSL will fail.

Code:

class A { 
virtual void foo(); 
virtual void pureFoo() = 0; } 

class B : public A { 
virtual void foo() {} 
virtual void pureFoo() {} 
 } 

CKERROR MyManager::OnCKInit() 
{ 
  STARTVSLBIND(ctx) 
    DECLAREPOINTERTYPE( B )  // Bind B class 
    DECLAREMETHOD_0( B, void, foo )  // Bind B functions 
    DECLAREMETHOD_0( B, void, pureFoo ) 
  STOPVSLBIND 
} 


Example 3

Make sure that you declare your manager as pointertype (DECLAREPOINTERTYPE) otherwise you wind up with copies instead of instances.

Code:

// MANAGER 
DECLAREFUN_C_0(CKGUID, GetDomsNewtonManGuid) // GUID 
DECLAREPOINTERTYPE(DomsNewtonMan) 
DECLAREOBJECTTYPEALIAS(DomsNewtonMan, "DomsNewtonMan") // class 
DECLARESTATIC_1(DomsNewtonMan,DomsNewtonMan*,Cast, CKBaseManager* iM ) //static cast mem method  
Personal tools
The Swap-Meet