使用PB未公开的INDIRECT关键字

作者: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 发贴 |  永久链接 |  删除 |  回复这个
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值