使用PB未公开的INDIRECT关键字

来源:互联网 发布:重生之网络巨头txt下载 编辑:程序博客网 时间:2024/06/10 00:32

作者:Réal Gagnon

 

INDIRECT declaration statement enables a function to be called indirectly by simply setting an instance or shared variable. With a simple INDIRECTed variable, we need to provide 2 functions. One to set the value and one to retrieve the value.

 

Here some notes from Jeremy Lakeman (thanks!).

  • INDIRECT variables only compile with 2 or 6 functions in the array otherwise the compiler will crash.
  • Arguments that start with a * will be replaced by the appropriate value at compile time and all arguments are optional, the compiler wont complain if you don't pass one of the valid values
  • Arguments can be supplied in any order
  • The compiler will crash if you define a function with an unsuported argument
  • Extra identifiers can be passed to each method, but only if they are valid in the context of the calling code
  • The argument names are :
    string *name the name of the variable (used with INDIRECT array)
    any *value the value being assigned
    long[] *args the array of array dimensions (used with INDIRECT array)
  • Where a value is supplied as an argument, the compiler will call any matching method. This means that you could override the set methods to allow multiple types of values to be assigned.

INDIRECT keyword when used with an array is a little bit more tricky, we need to define 6 functions.

In the following example, the INDIRECT array converts its member to uppercase. A userobject is used to hold our INDIRECT array and the 6 required functions.

[EXPORT .sru file, save into a file _n_cst_indirect.sru_ and then IMPORT it in PB]

 

The same technique but this time, our array type is long.

 

Array with multi-dimensions needs functions with different signatures :

 
 由 Ericwoo 在 六月 07, 2008 15:44 发贴 | 永久链接 | 删除 | 回复这个