Mirror docs/tsl/codegen into the bundled tsl-api-reference skill and rebuild the function index. Remove invalid duplicate API entries for cb_delistedbydate, createhttpsession, exportJsonString, and Anova_Bartlett so exact lookup returns the canonical entries.
864 lines
26 KiB
Markdown
864 lines
26 KiB
Markdown
# Builtin - 系统 / 运行时
|
||
|
||
## 运行时
|
||
|
||
### `setPrecision(number, precision)`
|
||
|
||
从指定精度四舍五入截断小数点位数,返回number的保留小数点Precision位后的值
|
||
|
||
| 参数 | 类型 | 说明 |
|
||
| ----------- | ------- | ------------------------------------------ |
|
||
| `number` | real | 实数/实数数组。 |
|
||
| `precision` | integer | 整数,目的是为了截取实数后面小数点的位数。 |
|
||
|
||
返回:real
|
||
|
||
#### 示例
|
||
|
||
```tsl
|
||
return setPrecision(123.4567, 3); // 返回值为保留3位小数点后的实数:123.457。
|
||
```
|
||
|
||
### `toStm(v, gtype, stm_type, p_n)`
|
||
|
||
转换成为STM流数据。可以通过stmType参数控制是否转换为新流模式或超大流新流模式,新的stm流占用空间更少,访问效率更高。
|
||
|
||
| 参数 | 类型 | 说明 |
|
||
| ---------- | ------- | -------------------------------------------------------------------------------------------------------------- |
|
||
| `v` | | 任意类型数据 |
|
||
| `gtype` | integer | 可选参数,图型等特殊类型 ,默认为0 |
|
||
| `stm_type` | integer | 可选参数,流模式,0:普通模式;1:新流模式;2:超极大流的紧缩模式;默认为0。其中,超大流模式能处理超大结果集。 |
|
||
| `p_n` | integer | 可选参数,精度,默认为-1,全精度 |
|
||
|
||
返回:binary
|
||
|
||
#### 示例
|
||
|
||
```tsl
|
||
return toStm(array(1, 23, 4, 5, 6, 7,)); // 返回以.stm为后缀名的二进制文件。
|
||
// 可选参数的应用
|
||
t := rand(4, 5);
|
||
s := toStm(t, 0, 1, 2); // 用新流模式,且保留两位小数
|
||
return stm(s);
|
||
// 返回如下:
|
||
```
|
||
|
||
### `toStn(v, n)`
|
||
|
||
转换成为STN字符串。小数位四舍五入,尾数是五就进一。
|
||
|
||
| 参数 | 类型 | 说明 |
|
||
| ---- | ------- | ------------------------------------------------------------------------- |
|
||
| `v` | any | 任意类型数据 |
|
||
| `n` | integer | 整型,保留小数点后的位数,可选参数。只对v是小数时且v的小数数位比N大有效。 |
|
||
|
||
返回:string
|
||
|
||
#### 示例
|
||
|
||
范例一:
|
||
|
||
```tsl
|
||
return toStn(12345); // 返回值为字符串:’12345’。
|
||
```
|
||
|
||
范例二:
|
||
|
||
```tsl
|
||
return toStn(1.2345, 2); // 返回值为字符串:’1.23’。
|
||
```
|
||
|
||
### `exportCsv(data, csv_str, include_index, include_header)`
|
||
|
||
将指定数组Data转换为csv格式字符串并存储在csvStr参数中。仅支持一维及二维数组的转换。和ExportCsvne的区别:在处理浮点数据时,ExportCsv的结果会输出为1E15等格式。
|
||
|
||
| 参数 | 类型 | 说明 |
|
||
| ---------------- | ------ | --------------------------------------------------------------- |
|
||
| `data` | array | 数组类型,要转换成csv格式字符串的数组。 |
|
||
| `csv_str` | string | 字符串类型,转换成功的csv格式字符串(输出值)。 |
|
||
| `include_index` | bool | 可选参数,布尔类型。转换结果是否包含数组下标信息。默认为False。 |
|
||
| `include_header` | bool | 可选参数,布尔类型。转换结果是否包含字段头部信息。默认为True。 |
|
||
|
||
返回:bool
|
||
|
||
#### 示例
|
||
|
||
范例01:一维数组转换成csv格式字符串(含大数量级数据)
|
||
|
||
```tsl
|
||
data := array(1, 2, "3", "A", 9, 1E15);
|
||
ret := exportCsv(data, s);
|
||
if ret then return s;
|
||
else return ret;
|
||
// 输出:
|
||
// 示例未提供可直接输出的返回表达式。
|
||
```
|
||
|
||
范例02:二维数组转换成csv格式字符串
|
||
|
||
```tsl
|
||
data := array((2, 5, 0), (3, 2, 1), (4, 7, 2));
|
||
ret := exportCsv(data, s);
|
||
if ret then return s;
|
||
else return ret;
|
||
// 输出:
|
||
// 示例未提供可直接输出的返回表达式。
|
||
```
|
||
|
||
范例03:转换成csv格式字符串,结果包含数组下标信息
|
||
|
||
```tsl
|
||
data := array("A": (2, 5, 0), "B": (3, 2, 1), "C": (4, 7, 2));
|
||
ret := exportCsv(data, s, 1);
|
||
if ret then return s;
|
||
else return ret;
|
||
// 输出:
|
||
// 示例未提供可直接输出的返回表达式。
|
||
```
|
||
|
||
范例04:转换成csv格式字符串,结果不包含字段头部信息
|
||
|
||
```tsl
|
||
data := array((2, 5, 0), (3, 2, 1), (4, 7, 2));
|
||
ret := exportCsv(data, s, 0, 0);
|
||
if ret then return s;
|
||
else return ret;
|
||
// 输出:
|
||
// 示例未提供可直接输出的返回表达式。
|
||
```
|
||
|
||
### `setProfiler(flag)`
|
||
|
||
设置需要记录的优化信息(当设置了记录优化信息的时候,运行速度可能会比正常运行慢很多)并返回设置前的状态值,如果设置了记录优化信息,在平台运行的模型结束的时候会在终端打开优化信息的窗口,用户也可以调用GetProfilerInfo来手动获得优化信息。
|
||
|
||
| 参数 | 类型 | 说明 |
|
||
| ------ | ---- | ----------------------------------------------------------------------------------------------------------------------------- |
|
||
| `flag` | | 整数,可省略,若省略则仅返回状态值而不设置。设置需要记录的优化信息,由一个四位二进制数组成,即以下几种常见组合说明: 取值 说明 |
|
||
|
||
返回:integer
|
||
|
||
#### 示例
|
||
|
||
范例01:1+2+4的优化信息返回
|
||
|
||
```tsl
|
||
setProfiler(7);
|
||
a := array();
|
||
setSysParam(PN_Stock(), 'SH000001');
|
||
for i := 20000101t to 20200721T do
|
||
begin
|
||
if not spec(isTradeDay(i), 'SH000001') then continue;
|
||
echo specDate(close(), i);
|
||
end
|
||
return 1;
|
||
// 结果:times为函数运行的次数,seconds为运行时间,op为指令的优化信息,type为函数类型。
|
||
```
|
||
|
||
范例02:内置对象的优化信息返回
|
||
|
||
```tsl
|
||
setProfiler(8);
|
||
o := new TStringList();
|
||
o.text := "Tinysoft"; // 给对象的属性赋值
|
||
o.delimited_text := 'A=abc,B=123,C=abc,F=996,E=abd';
|
||
o.add("G=666");
|
||
return 1;
|
||
// 优化信息如:
|
||
```
|
||
|
||
### `randomfrom(avalues)`
|
||
|
||
返回一个随机的数组元素,这个数组是由参数Avalue传递进来的。
|
||
|
||
| 参数 | 类型 | 说明 |
|
||
| --------- | ------------ | ---------------------------------- |
|
||
| `avalues` | array of any | 数组名称,可以是整数数组或实数数组 |
|
||
|
||
返回:any
|
||
|
||
#### 示例
|
||
|
||
```tsl
|
||
a := array('a', 'b', 'c', 'd', 'e', 'f');
|
||
return randomFrom(a);
|
||
// 返回值为随机返回A字符串中一个字符:’b’。
|
||
```
|
||
|
||
### `getSysParams()`
|
||
|
||
取出所有系统参数的值。
|
||
|
||
返回:array
|
||
|
||
### `Logger_debug(msg)`
|
||
|
||
打印带执行节点的调试信息
|
||
|
||
| 参数 | 类型 | 说明 |
|
||
| ----- | ------ | ----------------------------------------------------------- |
|
||
| `msg` | string | 任意数据类型,如果是字符串原样打印,如果非字符串按tostn打印 |
|
||
|
||
返回:any
|
||
|
||
### `logger_info(msg)`
|
||
|
||
打印带执行节点的提示信息
|
||
|
||
| 参数 | 类型 | 说明 |
|
||
| ----- | ------ | ----------------------------------------------------------- |
|
||
| `msg` | string | 任意数据类型,如果是字符串原样打印,如果非字符串按tostn打印 |
|
||
|
||
返回:any
|
||
|
||
### `logger_warning(msg)`
|
||
|
||
打印带执行节点的调试信息
|
||
|
||
| 参数 | 类型 | 说明 |
|
||
| ----- | ---- | ----------------------------------------------------------- |
|
||
| `msg` | any | 任意数据类型,如果是字符串原样打印,如果非字符串按tostn打印 |
|
||
|
||
返回:any
|
||
|
||
### `logger_info2(p1, p2, p3, pn)`
|
||
|
||
打印带执行节点的提示信息
|
||
|
||
| 参数 | 类型 | 说明 |
|
||
| ---- | ---- | ------------------------ |
|
||
| `p1` | any | 第一个参数的内容 |
|
||
| `p2` | any | 第二个参数的内容,可省略 |
|
||
| `p3` | any | 第三个参数的内容,可省略 |
|
||
| `pn` | any | 第N个参数的内容,可省略 |
|
||
|
||
返回:any
|
||
|
||
### `sp_UserSysParam2()`
|
||
|
||
用户自定义函数教学范例,获得当前系统参数
|
||
|
||
返回:string
|
||
|
||
### `sp_SetSysParam1()`
|
||
|
||
设置系统参数教学范例,使用缺省系统参数,返回股票.基本信息
|
||
|
||
返回:any
|
||
|
||
### `sp_SetSysParam2()`
|
||
|
||
设置系统参数教学范例,指定系统参数(当前为SH600718),返回股票.基本信息
|
||
|
||
返回:any
|
||
|
||
### `ifThen3(left, right, r1, r2, r3)`
|
||
|
||
比较left与Right大小,若Left大,则返回r1;若相等,返回r2;若Right大,返回r3。
|
||
|
||
| 参数 | 类型 | 说明 |
|
||
| ------- | ---- | ------ |
|
||
| `left` | real | 实数 |
|
||
| `right` | real | 实数 |
|
||
| `r1` | expr | 表达式 |
|
||
| `r2` | expr | 表达式 |
|
||
| `r3` | expr | 表达式 |
|
||
|
||
返回:expr
|
||
|
||
#### 示例
|
||
|
||
```tsl
|
||
return ifThen3(1, 2, '左大', '相等', '右大');
|
||
// 返回:’右大’
|
||
```
|
||
|
||
### `safeEval(exp)`
|
||
|
||
表达式求值
|
||
|
||
| 参数 | 类型 | 说明 |
|
||
| ----- | ----------- | ---------- |
|
||
| `exp` | texpression | 表达式类型 |
|
||
|
||
返回:any
|
||
|
||
### `tsAppServerName()`
|
||
|
||
返回平台设置的名字,如果没有设置,默认是ip:进程路径。
|
||
|
||
返回:string
|
||
|
||
#### 示例
|
||
|
||
```tsl
|
||
return tsAppServerName();
|
||
// 结果:192.168.101.26:z:\server\bin\exec64.exe
|
||
```
|
||
|
||
### `call(func_name, p1, pn)`
|
||
|
||
根据名称或者函数指针调用指定的函数,后面带的参数将自动送入该函数。
|
||
|
||
| 参数 | 类型 | 说明 |
|
||
| ----------- | ----------------- | ------------------------------------------------ |
|
||
| `func_name` | string\|tfunction | 如果是字符串,表示函数的名称,也可以是函数类型。 |
|
||
| `p1` | any | 整数,参数1 |
|
||
| `pn` | any | 整数,参数N。 |
|
||
|
||
返回:any
|
||
|
||
#### 示例
|
||
|
||
```tsl
|
||
// 采用字符串方式来调用函数
|
||
return call("IntTodate", 20140101);
|
||
// 返回41640
|
||
// 采用函数指针来调用函数
|
||
f := ThisFunction(int_to_date);
|
||
return call(f, 20140101);
|
||
// 返回41640
|
||
```
|
||
|
||
### `toXml(v)`
|
||
|
||
转换成为XML字符串。
|
||
|
||
| 参数 | 类型 | 说明 |
|
||
| ---- | ---- | -------- |
|
||
| `v` | any | 任意类型 |
|
||
|
||
返回:string
|
||
|
||
#### 示例
|
||
|
||
```tsl
|
||
return toXml('this is XML document');
|
||
{返回值为字符串:
|
||
<?xml version="1.0" encoding="GB2312"?>
|
||
<TSXML Copyright="Generated by ShenZhen Tinysoft Corp,Ltd. All rights reserved." TYPE="STRING" VALUE="this is XML document"/>}
|
||
// 差异说明
|
||
// 仅windows中支持,Linux中暂不支持。
|
||
```
|
||
|
||
### `xml(v)`
|
||
|
||
把XML串转换为任意类型。
|
||
|
||
| 参数 | 类型 | 说明 |
|
||
| ---- | ------ | ------------- |
|
||
| `v` | string | 字符串,XML串 |
|
||
|
||
返回:any
|
||
|
||
#### 示例
|
||
|
||
```tsl
|
||
return xml('<?xml version="1.0" encoding="GB2312"?>
|
||
<TSXML Copyright="Generated by ShenZhen Tinysoft Corp,Ltd. All rights reserved." type="STRING" VALUE="this is XML document"/>');
|
||
// 返回值为字符串:’this is a document’。
|
||
// 差异说明
|
||
// 仅windows中支持,Linux中暂不支持。
|
||
```
|
||
|
||
### `exportCsvne(data, csv_str, include_index, include_header)`
|
||
|
||
将指定数组Data转换为csv格式字符串并存储在csvStr参数中。仅支持一维及二维数组的转换。和ExportCsv的区别:在处理浮点数据时,ExportCsvne的结果不会输出为1E15等格式。
|
||
|
||
| 参数 | 类型 | 说明 |
|
||
| ---------------- | ------ | ---- |
|
||
| `data` | array | |
|
||
| `csv_str` | string | |
|
||
| `include_index` | | |
|
||
| `include_header` | bool | |
|
||
|
||
返回:bool
|
||
|
||
#### 示例
|
||
|
||
范例01:一维数组转换成csv格式字符串(含大数量级数据)
|
||
|
||
```tsl
|
||
data := array(1, 2, "3", "A", 9, 1E15);
|
||
ret := exportCsvne(data, s);
|
||
if ret then return s;
|
||
else return ret;
|
||
// 输出:
|
||
// 示例未提供可直接输出的返回表达式。
|
||
```
|
||
|
||
范例02:二维数组转换成csv格式字符串
|
||
|
||
```tsl
|
||
data := array((2, 5, 0), (3, 2, 1), (4, 7, 2));
|
||
ret := exportCsvne(data, s);
|
||
if ret then return s;
|
||
else return ret;
|
||
// 输出:
|
||
// 示例未提供可直接输出的返回表达式。
|
||
```
|
||
|
||
范例03:转换成csv格式字符串,结果包含数组下标信息
|
||
|
||
```tsl
|
||
data := array("A": (2, 5, 0), "B": (3, 2, 1), "C": (4, 7, 2));
|
||
ret := exportCsvne(data, s, 1);
|
||
if ret then return s;
|
||
else return ret;
|
||
// 输出:
|
||
// 示例未提供可直接输出的返回表达式。
|
||
```
|
||
|
||
范例04:转换成csv格式字符串,结果不包含字段头部信息
|
||
|
||
```tsl
|
||
data := array((2, 5, 0), (3, 2, 1), (4, 7, 2));
|
||
ret := exportCsvne(data, s, 0, 0);
|
||
if ret then return s;
|
||
else return ret;
|
||
// 输出:
|
||
// 示例未提供可直接输出的返回表达式。
|
||
```
|
||
|
||
### `callInArray(func_name, param_content)`
|
||
|
||
根据名称或者函数指针调用指定的函数,将参数放入一个数组中送入该函数,不支持变参。另外,天软的函数指针可以用thisfunction()获得。该函数与call函数功能类似,注意两个函数设置参数的区别。Call函数直接列举,CallInArray函数将调用的函数的参数放在Array中。
|
||
|
||
| 参数 | 类型 | 说明 |
|
||
| --------------- | ----------------- | ---------------------------------------------------------------------------- |
|
||
| `func_name` | string\|tfunction | 如果是字符串,表示函数名称,也可以是函数类型。 |
|
||
| `param_content` | array | 数组类型,第一个参数放在ParamContent[0],第二个放在ParamContent[1]以此类推。 |
|
||
|
||
返回:any
|
||
|
||
#### 示例
|
||
|
||
范例1:根据函数名称调用,第一个参数为函数名称
|
||
|
||
```tsl
|
||
return callInArray("StrToIntDef", array('1234', 999));
|
||
// 返回1234
|
||
```
|
||
|
||
范例2:调用匿名函数,第一个参数是指向匿名函数的变量
|
||
|
||
```tsl
|
||
{func1是一个变量,我们将一个函数体赋值给这个变量,变量型函数我们称为匿名函数,匿名函数的语句段放在某个函数体内,调用的时候,需使用call或callinarray函数进行调用。
|
||
这个例子中,a是一个变量,当a在func1匿名函数中,并在匿名函数体重修改a,使a := a+10; ,但执行完匿名函数后,a参数的值是不变的,即不支持变参,所以最后返回a为10,b为20。
|
||
callinarray在这里执行匿名函数func1时,其参数不需要跟在func1之后。}
|
||
a := 10;
|
||
func1 := function(a) begin
|
||
a := a+10;
|
||
return a;
|
||
end;
|
||
b := callInArray(func1, array(a));
|
||
return array(a, b);
|
||
// array(10,20)
|
||
```
|
||
|
||
范例3:根据函数指针调用,第一个参数为函数指针
|
||
|
||
```tsl
|
||
{thisfunction()函数可获得函数指针;由于调用的是stockzf3,该函数没有参数,因此,callinarray的第二个参数给空数组}
|
||
setSysParam(pn_stock(), 'SH000001');
|
||
return callInArray(thisfunction(stockzf3), array());
|
||
```
|
||
|
||
范例04:调用时指定参数传参
|
||
|
||
```tsl
|
||
function CCC(a, b, c, d); // 展示各参数的值
|
||
begin
|
||
echo "A:", a, " B:", b, " C:", c, " D:", d;
|
||
return b;
|
||
end;
|
||
// 调用
|
||
return callInArray("CCC", array("b": 1, "d": 4));
|
||
// 返回:1
|
||
// 打印结果:A: <NIL> B: 1 C: <NIL> D: 40
|
||
// 解析:callINArray在通过数组传参数时,可以通过指定下标的方式给指定参数进行传参,下标对应函数定义中的变量名。
|
||
// 上面示例中,只对参数b与d进行了传参,其它两参数没有进行传值,所以是nil。
|
||
```
|
||
|
||
### `doubleVariableExecute(arr, sys_name, time_arr, exp)`
|
||
|
||
计算指定系统参数,指定时间序列下的指标表达式的值
|
||
|
||
| 参数 | 类型 | 说明 |
|
||
| ---------- | ----------- | ---------------------------- |
|
||
| `arr` | integer | 二维数组,设置的系统参数的值 |
|
||
| `sys_name` | integer | 字符串,指定的系统参数名 |
|
||
| `time_arr` | integer | 二维数组,需要计算的指定时间 |
|
||
| `exp` | texpression | 表达式,指标表达式 |
|
||
|
||
返回:array
|
||
|
||
#### 示例
|
||
|
||
```tsl
|
||
stocks := array(getBk('上证50'));
|
||
timer := marketTradeDayQk(20220101T, 20221211T);
|
||
return doubleVariableExecute(stocks, pn_Stock(), timer, @close());
|
||
// 返回: (部分结果截图)
|
||
```
|
||
|
||
### `multipleExecute(exp)`
|
||
|
||
表达式求值
|
||
|
||
| 参数 | 类型 | 说明 |
|
||
| ----- | ----------- | ------ |
|
||
| `exp` | texpression | 表达式 |
|
||
|
||
返回:array
|
||
|
||
### `singleVariableExecute(arr, sys_name, exp)`
|
||
|
||
设置系统变量SysName的值为Arr中的元素,执行表达式exp,将表达式的值放到数组Arr中。
|
||
|
||
| 参数 | 类型 | 说明 |
|
||
| ---------- | ----------- | ------------------------ |
|
||
| `arr` | array | 数组, |
|
||
| `sys_name` | string | 字符串,指定系统参数名称 |
|
||
| `exp` | texpression | 表达式 |
|
||
|
||
返回:array
|
||
|
||
#### 示例
|
||
|
||
```tsl
|
||
// Arr中存储的是代码,获取2019年3月1日,Arr中所有代码的收盘价
|
||
arr := array('SZ000001', 'SZ000002');
|
||
return singleVariableExecute(arr, pn_stock(), @close());
|
||
```
|
||
|
||
### `safeSetSysParam(systype, value)`
|
||
|
||
设置系统参数。主要是将value的值转化为正确的对应于systype数据类型,再通过setsysparam进行设置setysparam(systype,value),保证系统参数设置成功。
|
||
|
||
| 参数 | 类型 | 说明 |
|
||
| --------- | ------ | ------------------------ |
|
||
| `systype` | string | 字符串,系统参数名称 |
|
||
| `value` | real | 实数或字符串,系统参数值 |
|
||
|
||
返回:integer
|
||
|
||
### `tsAppServer()`
|
||
|
||
获得当前运行的模型所在的运算服务器的标识。
|
||
|
||
返回:string
|
||
|
||
#### 示例
|
||
|
||
```tsl
|
||
a := rand(10, 10);
|
||
return tsAppServer();
|
||
// 结果:192.168.101.45:3328(Z:\server\bin5)
|
||
```
|
||
|
||
### `dupValue(value)`
|
||
|
||
返回一份value的复制值,一般无需要使用,特别用于不需要变参的函数调用。
|
||
|
||
| 参数 | 类型 | 说明 |
|
||
| ------- | ---- | ---------------------- |
|
||
| `value` | any | 任意类型,被复制的数据 |
|
||
|
||
返回:any
|
||
|
||
#### 示例
|
||
|
||
```tsl
|
||
// 主函数
|
||
function test1();
|
||
begin
|
||
a := 1;
|
||
b := 2;
|
||
c := 3;
|
||
d := test2(dupValue (a), b, c);
|
||
return array(a, b, c, d);
|
||
end;
|
||
// 返回array(1,20,3,33)
|
||
// 被调用函数
|
||
function test2(a, b, c);
|
||
begin
|
||
a := 10;
|
||
b := 20;
|
||
return a+b+c;
|
||
end;
|
||
// 由test1执行出来的结果可以知道,a变量,由于使用了dupValue复制值,虽然在子函数test2中改变了其值,但在主函数中的a变量仍然没变。而b变量则发生了改变。
|
||
```
|
||
|
||
### `ifThen(avalue, atrue, a_false)`
|
||
|
||
如果Avalue值为真,返回参数Atrue,否则返回参数Afalse
|
||
|
||
| 参数 | 类型 | 说明 |
|
||
| --------- | ---- | -------------------------- |
|
||
| `avalue` | bool | 布尔类型,判定条件 |
|
||
| `atrue` | any | 任意类型,Avalue为真返回值 |
|
||
| `a_false` | any | 任意类型,Avalue为假返回值 |
|
||
|
||
返回:any
|
||
|
||
#### 示例
|
||
|
||
```tsl
|
||
a := 1;
|
||
b := 2;
|
||
return ifThen(a>b, a, b);
|
||
// 返回:2。
|
||
```
|
||
|
||
### `integer(value)`
|
||
|
||
强制成整数,类型转换,对有些必需要指定类型的函数有用,如format
|
||
|
||
| 参数 | 类型 | 说明 |
|
||
| ------- | ---- | ---------- |
|
||
| `value` | real | 实数或整数 |
|
||
|
||
返回:integer
|
||
|
||
#### 示例
|
||
|
||
```tsl
|
||
return integer(123.456); // 返回值为整型数据:123。
|
||
```
|
||
|
||
### `int64(value)`
|
||
|
||
强制成整数,类型转换,对有些必需要指定类型的函数有用,如format
|
||
|
||
| 参数 | 类型 | 说明 |
|
||
| ------- | ---- | ---------- |
|
||
| `value` | real | 实数或整数 |
|
||
|
||
返回:int64
|
||
|
||
#### 示例
|
||
|
||
```tsl
|
||
return int64(123); // 返回值为64位整型数据:123。
|
||
```
|
||
|
||
### `real(value)`
|
||
|
||
强制为实数,类型转换,对有些必需要指定类型的函数有用,如format
|
||
|
||
| 参数 | 类型 | 说明 |
|
||
| ------- | ---- | ---------- |
|
||
| `value` | real | 实数或整数 |
|
||
|
||
返回:real
|
||
|
||
#### 示例
|
||
|
||
```tsl
|
||
return real(123); // 返回值为实数数据:123.00
|
||
```
|
||
|
||
### `wideString(value)`
|
||
|
||
将字符串转为Unicode字符串,或者强制让二进制为Unicode字符串。
|
||
|
||
| 参数 | 类型 | 说明 |
|
||
| ------- | -------------------------- | -------------------- |
|
||
| `value` | string\|binary\|widestring | 字符串或者二进制数据 |
|
||
|
||
返回:widestring
|
||
|
||
#### 示例
|
||
|
||
```tsl
|
||
return wideString('abcd');
|
||
// 返回值为Unicode字符串:L’abcd’。
|
||
```
|
||
|
||
### `binary(value)`
|
||
|
||
强制把字符串或者Unicode字符串转化为二进制流,对有些必需要指定类型的函数有用
|
||
|
||
| 参数 | 类型 | 说明 |
|
||
| ------- | -------------------------- | -------------------- |
|
||
| `value` | string\|binary\|widestring | 字符串或者二进制数据 |
|
||
|
||
返回:binary
|
||
|
||
#### 示例
|
||
|
||
```tsl
|
||
return binary('111111'); // 返回值为二进制流。
|
||
```
|
||
|
||
### `stn(v)`
|
||
|
||
把STN串转换为任意类型。
|
||
|
||
| 参数 | 类型 | 说明 |
|
||
| ---- | ------ | ------------- |
|
||
| `v` | string | 字符串,STN串 |
|
||
|
||
返回:any
|
||
|
||
### `randomize()`
|
||
|
||
已废弃函数。
|
||
|
||
返回:any
|
||
|
||
### `random()`
|
||
|
||
(参考文档未提供简述。)
|
||
|
||
返回:real
|
||
|
||
### `tslfilename()`
|
||
|
||
获取正在执行的 `.tsl` 主脚本完整路径。
|
||
|
||
返回:string
|
||
|
||
### `sysgettsllibpath()`
|
||
|
||
获取当前函数库查找路径。
|
||
|
||
返回:string
|
||
|
||
## 错误与断言函数
|
||
|
||
### `assert(error)`
|
||
|
||
断言。若Check为假,返回出错信息
|
||
|
||
| 参数 | 类型 | 说明 |
|
||
| ------- | ------ | ---------- |
|
||
| `error` | string | 字符串类型 |
|
||
|
||
返回:string
|
||
|
||
#### 示例
|
||
|
||
```tsl
|
||
return assert(0, '无效的语段');
|
||
// 输出:
|
||
// 示例包含说明文字,未作为可执行片段运行。
|
||
```
|
||
|
||
### `getProfilerInfo(clear)`
|
||
|
||
获得记录的优化信息。
|
||
|
||
| 参数 | 类型 | 说明 |
|
||
| ------- | ---- | --------- |
|
||
| `clear` | bool | Boolean。 |
|
||
|
||
返回:array
|
||
|
||
#### 示例
|
||
|
||
范例01:不弹出profiler窗口
|
||
|
||
```tsl
|
||
setProfiler(7); // 记录TSL源代码函数调用+二进制函数的调用+指令调用的优化信息
|
||
a := 99;
|
||
b := intToStr(a); // inttostr是函数
|
||
a := rand(1000, 1); // rand是指令
|
||
a := select * from a where [0]>0.5 end; // select是指令
|
||
setSysParam(pn_stock(), "SZ000002");
|
||
b := nDay3(100, close()); // nday3也算是指令,不是函数 ,close是函数
|
||
return getProfilerInfo(1);
|
||
// 输出:
|
||
// array(
|
||
// ("name":"__main__","times":0,"seconds":0.0,"op":
|
||
// (
|
||
// ("name":"usercall","times":4,"seconds":4.1E-5),
|
||
// ("name":"select","times":1,"seconds":0.0007792),
|
||
// ("name":"nday3","times":1,"seconds":6.8E-6),
|
||
// ("name":":=","times":6,"seconds":0.0011755),
|
||
// ("name":">","times":1000,"seconds":0.000292900000000004),
|
||
// ("name":"[","times":1000,"seconds":0.000127500000000002),
|
||
// ("name":"rand","times":1,"seconds":0.0002869)),"type":"tsl"),
|
||
// ("name":"getProfilerInfo","times":1,"seconds":0.0,"type":"bin"),
|
||
// ("name":"intToStr","times":1,"seconds":1.72E-5,"type":"bin"),
|
||
// ... 共 14 行输出,已截断。
|
||
```
|
||
|
||
范例02:弹出profiler窗口
|
||
|
||
```tsl
|
||
setProfiler(7); // 记录TSL源代码函数调用+二进制函数的调用+指令调用的优化信息
|
||
a := 99;
|
||
b := intToStr(a); // inttostr是函数
|
||
a := rand(1000, 1); // rand是指令
|
||
a := select * from a where [0]>0.5 end; // select是指令
|
||
setSysParam(pn_stock(), "SZ000002");
|
||
b := nDay3(100, close()); // nday3也算是指令,不是函数 ,close是函数
|
||
t := getProfilerInfo();
|
||
return b;
|
||
// 输出:返回程序结果的同时,另外弹出profiler窗口
|
||
```
|
||
|
||
### `importCsv(csv_str, data, include_index, include_header, single_arr)`
|
||
|
||
将指定csv格式字符串csvStr转换为数组,并存储在Data参数中。
|
||
|
||
| 参数 | 类型 | 说明 |
|
||
| ---------------- | ------ | ------------------------------------------------------------------- |
|
||
| `csv_str` | string | 字符串类型,csv格式字符串。 |
|
||
| `data` | array | 数组类型,转换成功的数组(输出值)。 |
|
||
| `include_index` | bool | 可选参数,布尔类型。指定字符串中是否包含数组下标信息。默认为False。 |
|
||
| `include_header` | bool | 可选参数,布尔类型。指定字符串中是否包含字段头部信息。默认为True。 |
|
||
| `single_arr` | bool | 可选参数,布尔类型。是否转换为一个一维数组。默认为False。 |
|
||
|
||
返回:bool
|
||
|
||
#### 示例
|
||
|
||
范例01:将指定csv格式字符串转换成二维数组
|
||
|
||
```tsl
|
||
s := "0,1,2\r\n2,5,0\r\n3,2,1\r\n4,7,2\r\n";
|
||
ret := importCsv(s, data);
|
||
if ret then return data;
|
||
else return ret;
|
||
// 输出:
|
||
// 示例未提供可直接输出的返回表达式。
|
||
```
|
||
|
||
范例02:读取本地csv文件,并将其转换成数组
|
||
|
||
```tsl
|
||
// 本地csv文件内容如下:
|
||
filepath := "D:\\test\\csv\\data.csv";
|
||
rdo2 readFile(rwRaw(), "", filepath, 0, 1000, s);
|
||
ret := importCsv(s, data, 1);
|
||
if ret then return data;
|
||
else return ret;
|
||
// 输出:
|
||
// Execute script error at Line:4
|
||
// function:__main__:line 4:instruction:usercall: 执行函数 importCsv 出错。
|
||
// function:__main__:line 4:instruction:usercall: function execute error
|
||
```
|
||
|
||
### `stm(v)`
|
||
|
||
把STM流转换为任意类型。
|
||
|
||
| 参数 | 类型 | 说明 |
|
||
| ---- | ------ | ----------------- |
|
||
| `v` | binary | 二进制类型,STM流 |
|
||
|
||
返回:any
|
||
|
||
### `getGlobalCache(name, out_value)`
|
||
|
||
按键读取全局缓存。
|
||
|
||
| 参数 | 类型 | 说明 |
|
||
| ----------- | ------ | -------------------- |
|
||
| `name` | string | 缓存键 |
|
||
| `out_value` | any | 输出变量,接收缓存值 |
|
||
|
||
返回:any
|