//全局常量优化 import win.ui; /*DSG{{*/ var winform = win.form(text="全局常量优化工具";right=626;bottom=389;parent=...) winform.add( btnConv={cls="button";text="将常量声明转换为智能提示";left=391;top=335;right=582;bottom=372;db=1;z=3}; static={cls="static";text="本程序转换标准常量(下划线开始的大写标识符)为智能提示模板格式, 可转换 C++ #define 格式常量、WM_USER 常量,本工具有优化 aardio 代码性能的作用。";left=23;top=13;right=571;bottom=54;dl=1;dr=1;dt=1;transparent=1;z=2}; static2={cls="static";text="智能提示配置可复制并保存到任何库文件重启 aardio 或在库目录右键菜单点击「刷新库目录、智能提示」即可生效。";left=24;top=342;right=368;bottom=380;db=1;dl=1;dr=1;transparent=1;z=4}; txtCode={cls="edit";text='_GLOBAL_CONST_AAA=123;\r\n_GLOBAL__CONST_BBB=123;\r\n_GLOBAL__CONST_CCC=123;\r\n#define TTM_GETCURRENTTOOLW\t(WM_USER+59)';left=25;top=55;right=600;bottom=327;db=1;dl=1;dr=1;dt=1;edge=1;hscroll=1;multiline=1;vscroll=1;z=1} ) /*}}*/ winform.txtCode.limit = 0xFFFFFF winform.btnConv.oncommand = function(id,event){ ..thread.invokeAndWait( function(winform,str){ global.onError = function( err,over ){ winform.msgboxErr(err) } //记录常量 var tconst ={} self@ = { //指定元表 _set = function(k,v){ if( (k[1]=='_'#) ){ //是下划线开头,并是大写 if( type(v)==type.number) { if( v > 9 ) table.push(tconst,string.format("%s=@0x%X/*%s*/",k,v,k ) ) else { table.push(tconst,string.format("%s=@%d/*%s*/",k,v,k ) ) } } elseif(type(v)==type.string) { table.push(tconst,string.format("%s=@""%s""",k,v,k ) ) } } global[[k]] = v; //这里要用[[ ]] 操作符,不然会再次递归调用_set元方法 } _float = true; //指定元表可修改 } var str = winform.txtCode.text; if( ..string.find(str,"/\**intellisense\(" ) ){ winform.msgboxErr("请先移除已转换成功的智能提示注释语句"); return; } str = string.replace(str,"#define\s+(\S+)","_\1="); str = string.replace(str,"!\wWM_USER!\W","0x400/*_WM_USER*/"); //加载并运行代码 assert( loadcode(str) ) (); //停止记录常量 self@ = null winform.txtCode.text = ' /**intellisense()\r\n' + string.join(tconst,'\r\n') + '\r\nend intellisense**/' ; },winform ) } winform.show(true) win.loopMessage(); return winform;