页面导航:
项目下载地址:
zengl language v1.7.3 源代码的相关地址:
https://github.com/zenglong/zengl_language/ 对应的tag标签为:v1.7.3,存在两个分支:master和develop,其中master是主分支,develop是开发分支。
zengl v1.7.3:
该版本增加了zenglApi_GetMemBlockNNCount接口函数,通过此接口,可以获取到数组之类的内存块中非NONE成员的数量。在zenglApi.c文件中可以看到此接口函数的定义:
/*获取内存块中非NONE成员的数量*/
ZL_EXPORT ZL_EXP_INT zenglApi_GetMemBlockNNCount(ZL_EXP_VOID * VM_ARG,ZENGL_EXPORT_MEMBLOCK * memblock)
{
ZENGL_VM_TYPE * VM = (ZENGL_VM_TYPE *)VM_ARG;
ZENGL_RUN_TYPE * run;
ZENGL_RUN_VIRTUAL_MEM_LIST * tmpMemBlock;
ZL_CHAR * ApiName = "zenglApi_GetMemBlockNNCount";
if(VM->signer != ZL_VM_SIGNER) //通过虚拟机签名判断是否是有效的虚拟机
return -1;
switch(VM->ApiState)
{
case ZL_API_ST_MOD_FUN_HANDLE:
case ZL_API_ST_DEBUG_HANDLE:
break;
default:
VM->run.SetApiErrorEx(VM_ARG,ZL_ERR_VM_API_INVALID_CALL_POSITION, ApiName , ApiName);
return -1;
break;
}
run = &VM->run;
if(memblock == ZL_NULL)
run->exit(VM_ARG,ZL_ERR_VM_API_INVALID_MEMBLOCK_ARG_IN_GET_MEM_BLOCK_NNCOUNT);
tmpMemBlock = (ZENGL_RUN_VIRTUAL_MEM_LIST *)memblock->ptr;
return tmpMemBlock->nncount;
}
|
在main.c文件内,新增的bltGetArrayNNCount模块函数,就使用了该接口:
/*bltGetArrayNNCount模块函数,获取数组之类的内存块中有多少个非NONE类型的成员*/
ZL_EXP_VOID main_builtin_get_array_nncount(ZL_EXP_VOID * VM_ARG,ZL_EXP_INT argcount)
{
ZENGL_EXPORT_MOD_FUN_ARG arg = {ZL_EXP_FAT_NONE,{0}};
ZENGL_EXPORT_MEMBLOCK memblock = {0};
ZL_EXP_INT nncount;
if(argcount != 1)
zenglApi_Exit(VM_ARG,"usage:bltGetArrayNNCount(array)");
zenglApi_GetFunArg(VM_ARG,1,&arg);
if(arg.type != ZL_EXP_FAT_MEMBLOCK)
zenglApi_Exit(VM_ARG,"bltGetArrayNNCount函数的第一个参数必须是数组");
memblock = arg.val.memblock;
nncount = zenglApi_GetMemBlockNNCount(VM_ARG, &memblock);
zenglApi_SetRetVal(VM_ARG, ZL_EXP_FAT_INT, ZL_EXP_NULL, nncount, 0);
}
|
新增测试脚本 test_scripts/v1.7.3/test.zl 用于测试上面的模块函数:
use builtin;
a[3] = 'hello world!';
a[5] = 'good morning!!';
a[7] = 'welcome to here!!!';
a[9] = 'good luck to you!!!!';
a[12] = 'god bless you!!!!!';
print 'a\'s Non-NONE value count: ' + bltGetArrayNNCount(a);
print '';
bltPrintArray(a);
|
执行结果如下:
zengl@zengl-ubuntu:~/zengl_language/linux$ ./zengl test_scripts/v1.7.3/test.zl
run(编译执行中)...
a's Non-NONE value count: 5
[3] hello world!
[5] good morning!!
[7] welcome to here!!!
[9] good luck to you!!!!
[12] god bless you!!!!!
run finished(编译执行结束)
zengl@zengl-ubuntu:~/zengl_language/linux$
|
zengl v1.7.3的代码只在windows,linux和mac OSX中进行过基本的测试。
以上是当前版本相关的内容,相关C源码请读者结合注释来进行分析。
结束语:
To live as a monster or to die as a good man.
—— 《禁闭岛》