ms-vite-plugin 1.4.61 → 1.4.63
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/luaObfuscator/addVararg.js +1 -1
- package/dist/luaObfuscator/compiler.js +1 -1
- package/dist/luaObfuscator/flatten.js +1 -1
- package/dist/luaObfuscator/index.js +1 -1
- package/dist/luaObfuscator/lexer.js +10 -10
- package/dist/luaObfuscator/numbers.js +1 -1
- package/dist/luaObfuscator/parser.js +1 -1
- package/dist/luaObfuscator/rename.js +1 -1
- package/dist/luaObfuscator/scope.js +1 -1
- package/dist/luaObfuscator/splitStrings.js +1 -1
- package/docs/api/opencv.md +8 -8
- package/docs/apilua/cloud.md +1 -2
- package/docs/apilua/file.md +30 -34
- package/docs/apilua/global.md +5 -13
- package/docs/apilua/http.md +7 -5
- package/docs/apilua/image.md +31 -16
- package/docs/apilua/node.md +1 -1
- package/docs/apilua/opencv.md +12 -11
- package/docs/apilua/system.md +1 -1
- package/docs/apilua/ui.md +13 -1
- package/docs/apilua/yolocls.md +17 -12
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.addVararg=c;function s(
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.addVararg=c;function s(o){o.vararg=!0,t(o.body.body)}function a(o){switch(o.type){case"FuncExpr":s(o);break;case"UnaryExpr":a(o.arg);break;case"BinaryExpr":a(o.left),a(o.right);break;case"TableExpr":for(const e of o.fields)e.kind==="index"&&a(e.key),a(e.value);break;case"IndexExpr":a(o.object),a(o.index);break;case"MemberExpr":a(o.object);break;case"CallExpr":a(o.callee);for(const e of o.args)a(e);break;case"MethodCallExpr":a(o.object);for(const e of o.args)a(e);break;case"ParenExpr":a(o.exp);break;default:break}}function t(o){for(const e of o)switch(e.type){case"DoStat":case"WhileStat":case"RepeatStat":case"ForNumStat":case"ForInStat":if(e.type==="WhileStat"&&a(e.cond),e.type==="RepeatStat"&&a(e.cond),e.type==="ForNumStat"&&(a(e.start),a(e.end),e.step&&a(e.step)),e.type==="ForInStat")for(const r of e.exps)a(r);t(e.body.body);break;case"IfStat":for(const r of e.clauses)a(r.cond),t(r.body.body);e.elseBody&&t(e.elseBody.body);break;case"FuncStat":case"LocalFuncStat":s(e.func);break;case"LocalStat":if(e.exps)for(const r of e.exps)a(r);break;case"AssignStat":for(const r of e.vars)a(r);for(const r of e.exps)a(r);break;case"CallStat":a(e.exp);break;case"ReturnStat":for(const r of e.exps)a(r);break;default:break}}function c(o){t(o.body)}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.compileChunk=P;class O{constructor(){Object.defineProperty(this,"code",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"ops",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"consts",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"protos",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"upvals",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"numparams",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"isVararg",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"maxStack",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"top",{enumerable:!0,configurable:!0,writable:!0,value:1}),Object.defineProperty(this,"frames",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"parent",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"labels",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"gotos",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"breaks",{enumerable:!0,configurable:!0,writable:!0,value:[]})}emit(r,e=0,n=0,s=0){return this.ops.push(r),this.code.push([0,e,n,s]),this.code.length-1}patch(r,e,n,s){const o=this.code[r];e!==void 0&&(o[1]=e),n!==void 0&&(o[2]=n),s!==void 0&&(o[3]=s)}kNil(){return this.intern({t:"nil"})}kBool(r){return this.intern({t:"bool",v:r})}kNum(r,e){return this.intern({t:"num",v:r,raw:e})}kStr(r){return this.intern({t:"str",v:r})}intern(r){for(let e=0;e<this.consts.length;e+=1){const n=this.consts[e];if(n.t===r.t&&(n.t==="nil"||n.t==="bool"&&r.t==="bool"&&n.v===r.v||n.t==="num"&&r.t==="num"&&n.v===r.v||n.t==="str"&&r.t==="str"&&n.v===r.v))return e+1}return this.consts.push(r),this.consts.length}alloc(r=1){const e=this.top;return this.top+=r,this.top-1>this.maxStack&&(this.maxStack=this.top-1),e}freeTo(r){this.top=r}pushFrame(){this.frames.push({locals:[],savedTop:this.top})}currentLocals(){return this.frames[this.frames.length-1]?.locals??[]}bind(r,e=!1){const n=this.alloc(1);return this.currentLocals().push({name:r,reg:n,close:e}),n}findLocal(r){for(let e=this.frames.length-1;e>=0;e-=1){const n=this.frames[e].locals;for(let s=n.length-1;s>=0;s-=1)if(n[s].name===r)return n[s].reg}}findUpval(r){for(let s=0;s<this.upvals.length;s+=1)if(this.upvals[s].name===r)return s+1;if(!this.parent)return;const e=this.parent.findLocal(r);if(e!==void 0)return this.upvals.push({name:r,inStack:!0,index:e}),this.upvals.length;const n=this.parent.findUpval(r);if(n!==void 0)return this.upvals.push({name:r,inStack:!1,index:n}),this.upvals.length}finish(){for(const r of this.gotos){const e=this.labels.get(r.name);if(e===void 0)throw new Error(`goto \u672A\u5B9A\u4E49\u6807\u7B7E ::${r.name}::`);this.patch(r.pc,0,e-(r.pc+1))}return{code:this.code,ops:this.ops,consts:this.consts,protos:this.protos,upvals:this.upvals,numparams:this.numparams,isVararg:this.isVararg,maxStack:Math.max(this.maxStack,this.numparams,1)}}}const k={"+":"ADD","-":"SUB","*":"MUL","/":"DIV","//":"IDIV","%":"MOD","^":"POW","&":"BAND","|":"BOR","~":"BXOR","<<":"SHL",">>":"SHR","..":"CONCAT"},A={"-":"UNM","~":"BNOT",not:"NOT","#":"LEN"};function P(t){const r=new O;return r.isVararg=!0,r.pushFrame(),u(r,t.body),r.emit("RETURN",1,0),r.finish()}function d(t,r){const e=new O;e.parent=t,e.numparams=r.params.length,e.isVararg=r.vararg,e.pushFrame();for(const n of r.params)e.bind(n);return u(e,r.body.body),e.emit("RETURN",1,0),t.protos.push(e.finish()),t.protos.length}function u(t,r){for(const e of r)B(t,e)}function p(t,r){for(const e of r.locals)t.emit("CLOSE",e.reg);t.freeTo(r.savedTop)}function B(t,r){switch(r.type){case"EmptyStat":return;case"BreakStat":{if(t.breaks.length===0)throw new Error("break \u51FA\u73B0\u5728\u5FAA\u73AF\u5916");const e=t.emit("JMP",0,0);t.breaks[t.breaks.length-1].push(e);return}case"GotoStat":{const e=t.emit("JMP",0,0);t.gotos.push({name:r.name,pc:e});return}case"LabelStat":t.labels.set(r.name,t.code.length);return;case"DoStat":{t.pushFrame(),u(t,r.body.body),p(t,t.frames.pop());return}case"WhileStat":{const e=t.code.length,n=i(t,r.cond);t.emit("TEST",n,0,0);const s=t.emit("JMP",0,0);t.freeTo(n),t.breaks.push([]),t.pushFrame(),u(t,r.body.body),p(t,t.frames.pop()),t.emit("JMP",0,e-(t.code.length+1)),t.patch(s,0,t.code.length-(s+1)),f(t,t.breaks.pop(),t.code.length);return}case"RepeatStat":{const e=t.code.length;t.breaks.push([]),t.pushFrame(),u(t,r.body.body);const n=i(t,r.cond);t.emit("TEST",n,0,0),t.emit("JMP",0,e-(t.code.length+1)),p(t,t.frames.pop()),f(t,t.breaks.pop(),t.code.length);return}case"IfStat":{const e=[];for(let n=0;n<r.clauses.length;n+=1){const s=i(t,r.clauses[n].cond);t.emit("TEST",s,0,0);const o=t.emit("JMP",0,0);t.freeTo(s),t.pushFrame(),u(t,r.clauses[n].body.body),p(t,t.frames.pop()),(n<r.clauses.length-1||r.elseBody)&&e.push(t.emit("JMP",0,0)),t.patch(o,0,t.code.length-(o+1))}r.elseBody&&(t.pushFrame(),u(t,r.elseBody.body),p(t,t.frames.pop()));for(const n of e)t.patch(n,0,t.code.length-(n+1));return}case"ForNumStat":{const e=t.alloc(4);i(t,r.start,e),i(t,r.end,e+1),r.step?i(t,r.step,e+2):t.emit("LOADK",e+2,t.kNum(1,"1"));const n=t.emit("FORPREP",e,0);t.breaks.push([]),t.pushFrame();const s=t.bind(r.name);t.emit("MOVE",s,e+3),u(t,r.body.body),p(t,t.frames.pop());const o=t.emit("FORLOOP",e,0);t.patch(n,e,o-(n+1)),t.patch(o,e,n+1-(o+1)),f(t,t.breaks.pop(),t.code.length),t.freeTo(e);return}case"ForInStat":{const e=t.alloc(3);h(t,r.exps,e,3);const n=t.emit("TFORCALL",e,r.names.length),s=t.emit("TFORLOOP",e,0);t.breaks.push([]),t.pushFrame();for(let o=0;o<r.names.length;o+=1){const a=t.bind(r.names[o]);t.emit("MOVE",a,e+3+o)}u(t,r.body.body),p(t,t.frames.pop()),t.emit("JMP",0,n-(t.code.length+1)),t.patch(s,e,t.code.length-(s+1)),f(t,t.breaks.pop(),t.code.length),t.freeTo(e);return}case"FuncStat":{const e=d(t,r.func),n=t.alloc(1);t.emit("CLOSURE",n,e),w(t,r.name.base,r.name.fields,r.name.method,n),t.freeTo(n);return}case"LocalFuncStat":{const e=t.bind(r.name),n=d(t,r.func);t.emit("CLOSURE",e,n);return}case"LocalStat":{const e=r.names.length,n=[];if(r.exps&&r.exps.length>0){const s=t.top;h(t,r.exps,s,e);for(let o=0;o<e;o+=1){const a=t.bind(r.names[o].name,r.names[o].attr==="close");t.emit("MOVE",a,s+o),n.push(a)}t.freeTo(n[0]),t.top=n[e-1]+1}else for(const s of r.names){const o=t.bind(s.name,s.attr==="close");t.emit("LOADNIL",o),n.push(o)}return}case"AssignStat":{const e=t.top;h(t,r.exps,e,r.vars.length);for(let n=0;n<r.vars.length;n+=1)F(t,r.vars[n],e+n);t.freeTo(e);return}case"CallStat":{const e=t.top;i(t,r.exp,void 0,0),t.freeTo(e);return}case"ReturnStat":{if(r.exps.length===0){t.emit("RETURN",1,0);return}const e=t.top;h(t,r.exps,e,-1);const n=r.exps[r.exps.length-1],s=n.type==="CallExpr"||n.type==="MethodCallExpr"||n.type==="VarargExpr";t.emit("RETURN",e,s?-1:r.exps.length);return}}}function f(t,r,e){for(const n of r)t.patch(n,0,e-(n+1))}function w(t,r,e,n,s){if(e.length===0&&!n){S(t,r,s);return}let o=T(t,r);const a=n?[...e,n]:e;for(let c=0;c<a.length-1;c+=1){const l=t.alloc(1);t.emit("GETTABLE",l,o,-t.kStr(a[c])),o=l}t.emit("SETTABLE",o,-t.kStr(a[a.length-1]),s)}function S(t,r,e){const n=t.findLocal(r);if(n!==void 0){t.emit("MOVE",n,e);return}const s=t.findUpval(r);if(s!==void 0){t.emit("SETUPVAL",e,s);return}t.emit("SETGLOBAL",e,t.kStr(r))}function T(t,r,e){const n=e??t.alloc(1),s=t.findLocal(r);if(s!==void 0)return n!==s&&t.emit("MOVE",n,s),n;const o=t.findUpval(r);return o!==void 0?(t.emit("GETUPVAL",n,o),n):(t.emit("GETGLOBAL",n,t.kStr(r)),n)}function F(t,r,e){if(r.type==="NameExpr"){S(t,r.name,e);return}if(r.type==="MemberExpr"){const n=i(t,r.object);t.emit("SETTABLE",n,-t.kStr(r.field),e);return}if(r.type==="IndexExpr"){const n=i(t,r.object),s=i(t,r.index);t.emit("SETTABLE",n,s,e);return}throw new Error("\u975E\u6CD5\u8D4B\u503C\u5DE6\u503C")}function i(t,r,e,n=1){const s=e??t.alloc(1);switch(r.type){case"NilLiteral":return t.emit("LOADNIL",s),s;case"BoolLiteral":return t.emit("LOADBOOL",s,r.value?1:0),s;case"NumberLiteral":return t.emit("LOADK",s,t.kNum(r.value,r.raw)),s;case"StringLiteral":return t.emit("LOADK",s,t.kStr(r.value)),s;case"VarargExpr":return t.emit("VARARG",s,n),s;case"NameExpr":return T(t,r.name,s);case"ParenExpr":return i(t,r.exp,s,1);case"UnaryExpr":{const o=i(t,r.arg);return t.emit(A[r.op],s,o),s}case"BinaryExpr":return M(t,r.op,r.left,r.right,s);case"FuncExpr":{const o=d(t,r);return t.emit("CLOSURE",s,o),s}case"TableExpr":return R(t,r.fields,s);case"IndexExpr":{const o=i(t,r.object),a=i(t,r.index);return t.emit("GETTABLE",s,o,a),s}case"MemberExpr":{const o=i(t,r.object);return t.emit("GETTABLE",s,o,-t.kStr(r.field)),s}case"CallExpr":return y(t,r.callee,r.args,s,n,!1);case"MethodCallExpr":return y(t,r.object,r.args,s,n,r.method);default:throw new Error(`\u4E0D\u652F\u6301\u7684\u8868\u8FBE\u5F0F ${r.type}`)}}function M(t,r,e,n,s){if(r==="and"||r==="or"){i(t,e,s),t.emit("TEST",s,0,r==="and"?0:1);const l=t.emit("JMP",0,0);return i(t,n,s),t.patch(l,0,t.code.length-(l+1)),s}if(r==="=="||r==="~="||r==="<"||r===">"||r==="<="||r===">="){const l=i(t,e),b=i(t,n);let m="EQ",g=l,E=b;r==="<"||r===">="?m="LT":r==="<="||r===">"?m="LE":m="EQ",(r===">"||r===">=")&&(g=b,E=l);const x=r==="~=";t.emit(m,g,E,x?1:0);const L=t.emit("JMP",0,0);t.emit("LOADBOOL",s,1);const v=t.emit("JMP",0,0);return t.patch(L,0,t.code.length-(L+1)),t.emit("LOADBOOL",s,0),t.patch(v,0,t.code.length-(v+1)),s}const o=k[r];if(!o)throw new Error(`\u4E0D\u652F\u6301\u7684\u8FD0\u7B97\u7B26 ${r}`);const a=i(t,e),c=i(t,n);return t.emit(o,s,a,c),s}function N(t){return t.type==="CallExpr"||t.type==="MethodCallExpr"||t.type==="VarargExpr"}function y(t,r,e,n,s,o){const a=n,c=e.length>0&&N(e[e.length-1]);if(o){const l=i(t,r,a);return t.emit("SELF",a,l,-t.kStr(o)),h(t,e,a+2,-1),t.emit("CALL",a,c?-1:e.length+1,s),a}return i(t,r,a),h(t,e,a+1,-1),t.emit("CALL",a,c?-1:e.length,s),a}function h(t,r,e,n){const s=n>0?n:Math.max(r.length,1);if(t.top<e+s&&(t.top=e+s,t.top-1>t.maxStack&&(t.maxStack=t.top-1)),r.length===0){if(n>0)for(let o=0;o<n;o+=1)t.emit("LOADNIL",e+o);return}for(let o=0;o<r.length;o+=1){const a=o===r.length-1,c=a&&(n<0||n>r.length)?n===-1?-1:n-o:1;i(t,r[o],e+o,a?c:1)}if(n>r.length)for(let o=r.length;o<n;o+=1)t.emit("LOADNIL",e+o)}function R(t,r,e){t.emit("NEWTABLE",e);const n=[];for(const s of r)if(s.kind==="list")n.push(s.value);else if(s.kind==="name"){const o=i(t,s.value);t.emit("SETTABLE",e,-t.kStr(s.key),o)}else{const o=i(t,s.key),a=i(t,s.value);t.emit("SETTABLE",e,o,a)}if(n.length>0){const s=t.top;h(t,n,s,-1),t.emit("SETLIST",e,s,n.length),t.freeTo(s)}return e}
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.compileChunk=P;class O{constructor(){Object.defineProperty(this,"code",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"ops",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"consts",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"protos",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"upvals",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"numparams",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"isVararg",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"maxStack",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"top",{enumerable:!0,configurable:!0,writable:!0,value:1}),Object.defineProperty(this,"frames",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"parent",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"labels",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"gotos",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"breaks",{enumerable:!0,configurable:!0,writable:!0,value:[]})}emit(r,e=0,o=0,s=0){return this.ops.push(r),this.code.push([0,e,o,s]),this.code.length-1}patch(r,e,o,s){const a=this.code[r];e!==void 0&&(a[1]=e),o!==void 0&&(a[2]=o),s!==void 0&&(a[3]=s)}kNil(){return this.intern({t:"nil"})}kBool(r){return this.intern({t:"bool",v:r})}kNum(r,e){return this.intern({t:"num",v:r,raw:e})}kStr(r){return this.intern({t:"str",v:r})}intern(r){for(let e=0;e<this.consts.length;e+=1){const o=this.consts[e];if(o.t===r.t&&(o.t==="nil"||o.t==="bool"&&r.t==="bool"&&o.v===r.v||o.t==="num"&&r.t==="num"&&o.v===r.v||o.t==="str"&&r.t==="str"&&o.v===r.v))return e+1}return this.consts.push(r),this.consts.length}alloc(r=1){const e=this.top;return this.top+=r,this.top-1>this.maxStack&&(this.maxStack=this.top-1),e}freeTo(r){this.top=r}pushFrame(){this.frames.push({locals:[],savedTop:this.top})}currentLocals(){return this.frames[this.frames.length-1]?.locals??[]}bind(r,e=!1){const o=this.alloc(1);return this.currentLocals().push({name:r,reg:o,close:e}),o}findLocal(r){for(let e=this.frames.length-1;e>=0;e-=1){const o=this.frames[e].locals;for(let s=o.length-1;s>=0;s-=1)if(o[s].name===r)return o[s].reg}}findUpval(r){for(let s=0;s<this.upvals.length;s+=1)if(this.upvals[s].name===r)return s+1;if(!this.parent)return;const e=this.parent.findLocal(r);if(e!==void 0)return this.upvals.push({name:r,inStack:!0,index:e}),this.upvals.length;const o=this.parent.findUpval(r);if(o!==void 0)return this.upvals.push({name:r,inStack:!1,index:o}),this.upvals.length}finish(){for(const r of this.gotos){const e=this.labels.get(r.name);if(e===void 0)throw new Error(`goto \u672A\u5B9A\u4E49\u6807\u7B7E ::${r.name}::`);this.patch(r.pc,0,e-(r.pc+1))}return{code:this.code,ops:this.ops,consts:this.consts,protos:this.protos,upvals:this.upvals,numparams:this.numparams,isVararg:this.isVararg,maxStack:Math.max(this.maxStack,this.numparams,1)}}}const k={"+":"ADD","-":"SUB","*":"MUL","/":"DIV","//":"IDIV","%":"MOD","^":"POW","&":"BAND","|":"BOR","~":"BXOR","<<":"SHL",">>":"SHR","..":"CONCAT"},A={"-":"UNM","~":"BNOT",not:"NOT","#":"LEN"};function P(t){const r=new O;return r.isVararg=!0,r.pushFrame(),u(r,t.body),r.emit("RETURN",1,0),r.finish()}function d(t,r){const e=new O;e.parent=t,e.numparams=r.params.length,e.isVararg=r.vararg,e.pushFrame();for(const o of r.params)e.bind(o);return u(e,r.body.body),e.emit("RETURN",1,0),t.protos.push(e.finish()),t.protos.length}function u(t,r){for(const e of r)B(t,e)}function p(t,r){for(const e of r.locals)t.emit("CLOSE",e.reg);t.freeTo(r.savedTop)}function B(t,r){switch(r.type){case"EmptyStat":return;case"BreakStat":{if(t.breaks.length===0)throw new Error("break \u51FA\u73B0\u5728\u5FAA\u73AF\u5916");const e=t.emit("JMP",0,0);t.breaks[t.breaks.length-1].push(e);return}case"GotoStat":{const e=t.emit("JMP",0,0);t.gotos.push({name:r.name,pc:e});return}case"LabelStat":t.labels.set(r.name,t.code.length);return;case"DoStat":{t.pushFrame(),u(t,r.body.body),p(t,t.frames.pop());return}case"WhileStat":{const e=t.code.length,o=n(t,r.cond);t.emit("TEST",o,0,0);const s=t.emit("JMP",0,0);t.freeTo(o),t.breaks.push([]),t.pushFrame(),u(t,r.body.body),p(t,t.frames.pop()),t.emit("JMP",0,e-(t.code.length+1)),t.patch(s,0,t.code.length-(s+1)),f(t,t.breaks.pop(),t.code.length);return}case"RepeatStat":{const e=t.code.length;t.breaks.push([]),t.pushFrame(),u(t,r.body.body);const o=n(t,r.cond);t.emit("TEST",o,0,0),t.emit("JMP",0,e-(t.code.length+1)),p(t,t.frames.pop()),f(t,t.breaks.pop(),t.code.length);return}case"IfStat":{const e=[];for(let o=0;o<r.clauses.length;o+=1){const s=n(t,r.clauses[o].cond);t.emit("TEST",s,0,0);const a=t.emit("JMP",0,0);t.freeTo(s),t.pushFrame(),u(t,r.clauses[o].body.body),p(t,t.frames.pop()),(o<r.clauses.length-1||r.elseBody)&&e.push(t.emit("JMP",0,0)),t.patch(a,0,t.code.length-(a+1))}r.elseBody&&(t.pushFrame(),u(t,r.elseBody.body),p(t,t.frames.pop()));for(const o of e)t.patch(o,0,t.code.length-(o+1));return}case"ForNumStat":{const e=t.alloc(4);n(t,r.start,e),n(t,r.end,e+1),r.step?n(t,r.step,e+2):t.emit("LOADK",e+2,t.kNum(1,"1"));const o=t.emit("FORPREP",e,0);t.breaks.push([]),t.pushFrame();const s=t.bind(r.name);t.emit("MOVE",s,e+3),u(t,r.body.body),p(t,t.frames.pop());const a=t.emit("FORLOOP",e,0);t.patch(o,e,a-(o+1)),t.patch(a,e,o+1-(a+1)),f(t,t.breaks.pop(),t.code.length),t.freeTo(e);return}case"ForInStat":{const e=t.alloc(3);h(t,r.exps,e,3);const o=t.emit("TFORCALL",e,r.names.length),s=t.emit("TFORLOOP",e,0);t.breaks.push([]),t.pushFrame();for(let a=0;a<r.names.length;a+=1){const i=t.bind(r.names[a]);t.emit("MOVE",i,e+3+a)}u(t,r.body.body),p(t,t.frames.pop()),t.emit("JMP",0,o-(t.code.length+1)),t.patch(s,e,t.code.length-(s+1)),f(t,t.breaks.pop(),t.code.length),t.freeTo(e);return}case"FuncStat":{const e=d(t,r.func),o=t.alloc(1);t.emit("CLOSURE",o,e),w(t,r.name.base,r.name.fields,r.name.method,o),t.freeTo(o);return}case"LocalFuncStat":{const e=t.bind(r.name),o=d(t,r.func);t.emit("CLOSURE",e,o);return}case"LocalStat":{const e=r.names.length,o=[];if(r.exps&&r.exps.length>0){const s=t.top;h(t,r.exps,s,e);for(let a=0;a<e;a+=1){const i=t.bind(r.names[a].name,r.names[a].attr==="close");t.emit("MOVE",i,s+a),o.push(i)}t.freeTo(o[0]),t.top=o[e-1]+1}else for(const s of r.names){const a=t.bind(s.name,s.attr==="close");t.emit("LOADNIL",a),o.push(a)}return}case"AssignStat":{const e=t.top;h(t,r.exps,e,r.vars.length);for(let o=0;o<r.vars.length;o+=1)F(t,r.vars[o],e+o);t.freeTo(e);return}case"CallStat":{const e=t.top;n(t,r.exp,void 0,0),t.freeTo(e);return}case"ReturnStat":{if(r.exps.length===0){t.emit("RETURN",1,0);return}const e=t.top;h(t,r.exps,e,-1);const o=r.exps[r.exps.length-1],s=o.type==="CallExpr"||o.type==="MethodCallExpr"||o.type==="VarargExpr";t.emit("RETURN",e,s?-1:r.exps.length);return}}}function f(t,r,e){for(const o of r)t.patch(o,0,e-(o+1))}function w(t,r,e,o,s){if(e.length===0&&!o){S(t,r,s);return}let a=T(t,r);const i=o?[...e,o]:e;for(let c=0;c<i.length-1;c+=1){const l=t.alloc(1);t.emit("GETTABLE",l,a,-t.kStr(i[c])),a=l}t.emit("SETTABLE",a,-t.kStr(i[i.length-1]),s)}function S(t,r,e){const o=t.findLocal(r);if(o!==void 0){t.emit("MOVE",o,e);return}const s=t.findUpval(r);if(s!==void 0){t.emit("SETUPVAL",e,s);return}t.emit("SETGLOBAL",e,t.kStr(r))}function T(t,r,e){const o=e??t.alloc(1),s=t.findLocal(r);if(s!==void 0)return o!==s&&t.emit("MOVE",o,s),o;const a=t.findUpval(r);return a!==void 0?(t.emit("GETUPVAL",o,a),o):(t.emit("GETGLOBAL",o,t.kStr(r)),o)}function F(t,r,e){if(r.type==="NameExpr"){S(t,r.name,e);return}if(r.type==="MemberExpr"){const o=n(t,r.object);t.emit("SETTABLE",o,-t.kStr(r.field),e);return}if(r.type==="IndexExpr"){const o=n(t,r.object),s=n(t,r.index);t.emit("SETTABLE",o,s,e);return}throw new Error("\u975E\u6CD5\u8D4B\u503C\u5DE6\u503C")}function n(t,r,e,o=1){const s=e??t.alloc(1);switch(r.type){case"NilLiteral":return t.emit("LOADNIL",s),s;case"BoolLiteral":return t.emit("LOADBOOL",s,r.value?1:0),s;case"NumberLiteral":return t.emit("LOADK",s,t.kNum(r.value,r.raw)),s;case"StringLiteral":return t.emit("LOADK",s,t.kStr(r.value)),s;case"VarargExpr":return t.emit("VARARG",s,o),s;case"NameExpr":return T(t,r.name,s);case"ParenExpr":return n(t,r.exp,s,1);case"UnaryExpr":{const a=n(t,r.arg);return t.emit(A[r.op],s,a),s}case"BinaryExpr":return M(t,r.op,r.left,r.right,s);case"FuncExpr":{const a=d(t,r);return t.emit("CLOSURE",s,a),s}case"TableExpr":return R(t,r.fields,s);case"IndexExpr":{const a=n(t,r.object),i=n(t,r.index);return t.emit("GETTABLE",s,a,i),s}case"MemberExpr":{const a=n(t,r.object);return t.emit("GETTABLE",s,a,-t.kStr(r.field)),s}case"CallExpr":return y(t,r.callee,r.args,s,o,!1);case"MethodCallExpr":return y(t,r.object,r.args,s,o,r.method);default:throw new Error(`\u4E0D\u652F\u6301\u7684\u8868\u8FBE\u5F0F ${r.type}`)}}function M(t,r,e,o,s){if(r==="and"||r==="or"){n(t,e,s),t.emit("TEST",s,0,r==="and"?0:1);const l=t.emit("JMP",0,0);return n(t,o,s),t.patch(l,0,t.code.length-(l+1)),s}if(r==="=="||r==="~="||r==="<"||r===">"||r==="<="||r===">="){const l=n(t,e),b=n(t,o);let m="EQ",g=l,E=b;r==="<"||r===">="?m="LT":r==="<="||r===">"?m="LE":m="EQ",(r===">"||r===">=")&&(g=b,E=l);const x=r==="~=";t.emit(m,g,E,x?1:0);const L=t.emit("JMP",0,0);t.emit("LOADBOOL",s,1);const v=t.emit("JMP",0,0);return t.patch(L,0,t.code.length-(L+1)),t.emit("LOADBOOL",s,0),t.patch(v,0,t.code.length-(v+1)),s}const a=k[r];if(!a)throw new Error(`\u4E0D\u652F\u6301\u7684\u8FD0\u7B97\u7B26 ${r}`);const i=n(t,e),c=n(t,o);return t.emit(a,s,i,c),s}function N(t){return t.type==="CallExpr"||t.type==="MethodCallExpr"||t.type==="VarargExpr"}function y(t,r,e,o,s,a){const i=o,c=e.length>0&&N(e[e.length-1]);if(a){const l=n(t,r,i);return t.emit("SELF",i,l,-t.kStr(a)),h(t,e,i+2,-1),t.emit("CALL",i,c?-1:e.length+1,s),i}return n(t,r,i),h(t,e,i+1,-1),t.emit("CALL",i,c?-1:e.length,s),i}function h(t,r,e,o){const s=o>0?o:Math.max(r.length,1);if(t.top<e+s&&(t.top=e+s,t.top-1>t.maxStack&&(t.maxStack=t.top-1)),r.length===0){if(o>0)for(let a=0;a<o;a+=1)t.emit("LOADNIL",e+a);return}for(let a=0;a<r.length;a+=1){const i=a===r.length-1,c=i&&(o<0||o>r.length)?o===-1?-1:o-a:1;n(t,r[a],e+a,i?c:1)}if(o>r.length)for(let a=r.length;a<o;a+=1)t.emit("LOADNIL",e+a)}function R(t,r,e){t.emit("NEWTABLE",e);const o=[];for(const s of r)if(s.kind==="list")o.push(s.value);else if(s.kind==="name"){const a=n(t,s.value);t.emit("SETTABLE",e,-t.kStr(s.key),a)}else{const a=n(t,s.key),i=n(t,s.value);t.emit("SETTABLE",e,a,i)}if(o.length>0){const s=t.top;h(t,o,s,-1),t.emit("SETLIST",e,s,o.length),t.freeTo(s)}return e}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.flattenControlFlow=C;function m(t){return{type:"NumberLiteral",raw:String(t),value:t}}function p(t){return{type:"NameExpr",name:t}}function f(t,
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.flattenControlFlow=C;function m(t){return{type:"NumberLiteral",raw:String(t),value:t}}function p(t){return{type:"NameExpr",name:t}}function f(t,n){return{type:"AssignStat",vars:t.map(e=>p(e)),exps:n}}function u(t,n){return f([t.stateName],[typeof n=="number"?m(n):n])}function k(t,n,e){return{type:"BinaryExpr",op:"or",left:{type:"BinaryExpr",op:"and",left:p(t),right:m(n)},right:m(e)}}function E(t,n,e){return{type:"BinaryExpr",op:t,left:n,right:e}}function S(t){const n=`__t${t.nextTemp}`;return t.nextTemp+=1,t.temps.push(n),n}function x(t){const n=t.nextState;return t.nextState+=1,t.states.set(n,[]),n}function o(t,n,e){t.states.get(n).push(e)}function F(t,n){for(const e of t)if(e.type==="LocalStat")for(const a of e.names)n.push(a.name);else if(e.type==="LocalFuncStat")n.push(e.name);else if(e.type==="ForNumStat")n.push(e.name),F(e.body.body,n);else if(e.type==="ForInStat")n.push(...e.names),F(e.body.body,n);else if(e.type==="DoStat"||e.type==="WhileStat"||e.type==="RepeatStat")F(e.body.body,n);else if(e.type==="IfStat"){for(const a of e.clauses)F(a.body.body,n);e.elseBody&&F(e.elseBody.body,n)}}function h(t,n,e,a){if(t.length===0)return n;const y=t.map(()=>x(e));for(let s=0;s<t.length;s+=1){const r=t[s];r.type==="LabelStat"&&e.userLabels.set(r.name,y[s])}for(let s=0;s<t.length;s+=1){const r=s+1<t.length?y[s+1]:n;I(e,y[s],t[s],r,a)}return y[0]}function I(t,n,e,a,y){switch(e.type){case"EmptyStat":case"LabelStat":o(t,n,u(t,a));return;case"AssignStat":case"CallStat":case"FuncStat":o(t,n,e),o(t,n,u(t,a));return;case"LocalStat":e.exps&&e.exps.length>0&&o(t,n,f(e.names.map(s=>s.name),e.exps)),o(t,n,u(t,a));return;case"LocalFuncStat":o(t,n,f([e.name],[e.func])),o(t,n,u(t,a));return;case"ReturnStat":o(t,n,e);return;case"BreakStat":o(t,n,u(t,y));return;case"GotoStat":{const s=t.userLabels.get(e.name);if(s===void 0)throw new Error(`goto \u672A\u5B9A\u4E49\u6807\u7B7E ::${e.name}::`);o(t,n,u(t,s));return}case"DoStat":o(t,n,u(t,h(e.body.body,a,t,y)));return;case"IfStat":{const s=S(t);let r=n;for(let l=0;l<e.clauses.length;l+=1){const b=l===e.clauses.length-1,d=h(e.clauses[l].body.body,a,t,y);let i=a;b?e.elseBody&&(i=h(e.elseBody.body,a,t,y)):i=x(t),o(t,r,f([s],[e.clauses[l].cond])),o(t,r,u(t,k(s,d,i))),b||(r=i)}e.clauses.length===0&&o(t,n,u(t,a));return}case"WhileStat":{const s=S(t),r=h(e.body.body,n,t,a);o(t,n,f([s],[e.cond])),o(t,n,u(t,k(s,r,a)));return}case"RepeatStat":{const s=S(t),r=x(t),l=h(e.body.body,r,t,a);o(t,n,u(t,l)),o(t,r,f([s],[e.cond])),o(t,r,u(t,k(s,a,l)));return}case"ForNumStat":{const s=e.name,r=S(t),l=S(t),b=S(t),d=x(t),i=x(t),L=x(t),g=x(t),N=h(e.body.body,g,t,a);o(t,n,f([s],[e.start])),o(t,n,f([r],[e.end])),o(t,n,f([l],[e.step??m(1)])),o(t,n,u(t,d)),o(t,d,f([b],[E(">=",p(l),m(0))])),o(t,d,u(t,k(b,i,L))),o(t,i,f([b],[E("<=",p(s),p(r))])),o(t,i,u(t,k(b,N,a))),o(t,L,f([b],[E(">=",p(s),p(r))])),o(t,L,u(t,k(b,N,a))),o(t,g,f([s],[E("+",p(s),p(l))])),o(t,g,u(t,d));return}case"ForInStat":{const s=S(t),r=S(t),l=S(t),b=S(t),d=x(t),i=[f([l],[p(e.names[0])]),...e.body.body],L=h(i,d,t,a),g=e.exps.slice();for(;g.length<3;)g.push({type:"NilLiteral"});o(t,n,f([s,r,l],g.slice(0,3))),o(t,n,u(t,d)),o(t,d,{type:"AssignStat",vars:e.names.map(N=>p(N)),exps:[{type:"CallExpr",callee:p(s),args:[p(r),p(l)]}]}),o(t,d,f([b],[E("~=",p(e.names[0]),{type:"NilLiteral"})])),o(t,d,u(t,k(b,L,a)));return}default:o(t,n,u(t,a))}}function v(t,n){const e=t.slice();let a=n>>>0||1;for(let y=e.length-1;y>0;y-=1){a=Math.imul(a,1664525)+1013904223>>>0;const s=a%(y+1),r=e[y];e[y]=e[s],e[s]=r}return e}function w(t,n){if(t.length===0)return t;const e={states:new Map,temps:[],nextState:1,nextTemp:1,stateName:"__s",userLabels:new Map},a=[];F(t,a);const y=h(t,0,e,0),s=[...new Set([...a,...e.temps,e.stateName])],r=v([...e.states.keys()],n).map(l=>({cond:E("==",p(e.stateName),m(l)),body:{type:"Block",body:e.states.get(l)}}));return[{type:"LocalStat",names:s.map(l=>({name:l}))},f([e.stateName],[m(y)]),{type:"WhileStat",cond:E("~=",p(e.stateName),m(0)),body:{type:"Block",body:[{type:"IfStat",clauses:r}]}}]}function c(t,n){switch(t.type){case"FuncExpr":B(t.body.body,n),t.body.body=w(t.body.body,n);break;case"UnaryExpr":c(t.arg,n);break;case"BinaryExpr":c(t.left,n),c(t.right,n);break;case"TableExpr":for(const e of t.fields)e.kind==="index"&&c(e.key,n),c(e.value,n);break;case"IndexExpr":c(t.object,n),c(t.index,n);break;case"MemberExpr":c(t.object,n);break;case"CallExpr":c(t.callee,n);for(const e of t.args)c(e,n);break;case"MethodCallExpr":c(t.object,n);for(const e of t.args)c(e,n);break;case"ParenExpr":c(t.exp,n);break;default:break}}function B(t,n){for(const e of t)switch(e.type){case"DoStat":case"WhileStat":case"RepeatStat":case"ForNumStat":case"ForInStat":if((e.type==="WhileStat"||e.type==="RepeatStat")&&c(e.cond,n),e.type==="ForNumStat"&&(c(e.start,n),c(e.end,n),e.step&&c(e.step,n)),e.type==="ForInStat")for(const a of e.exps)c(a,n);B(e.body.body,n);break;case"IfStat":for(const a of e.clauses)c(a.cond,n),B(a.body.body,n);e.elseBody&&B(e.elseBody.body,n);break;case"FuncStat":case"LocalFuncStat":B(e.func.body.body,n),e.func.body.body=w(e.func.body.body,n);break;case"LocalStat":if(e.exps)for(const a of e.exps)c(a,n);break;case"AssignStat":for(const a of e.vars)c(a,n);for(const a of e.exps)c(a,n);break;case"CallStat":c(e.exp,n);break;case"ReturnStat":for(const a of e.exps)c(a,n);break;default:break}}function C(t,n){B(t.body,n),t.body=w(t.body,n)}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.createFoldMixParams=exports.foldEncrypt=exports.foldDecrypt=exports.LuaParseError=exports.LuaLexError=exports.luaObfuscatorPresets=void 0,exports.obfuscateLua=
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.createFoldMixParams=exports.foldEncrypt=exports.foldDecrypt=exports.LuaParseError=exports.LuaLexError=exports.luaObfuscatorPresets=void 0,exports.obfuscateLua=E;const l=require("./addVararg"),f=require("./antiTamper"),b=require("./compiler"),y=require("./constantArray"),u=require("./flatten"),c=require("./minify"),a=require("./numbers"),p=require("./parser"),m=require("./rename"),d=require("./splitStrings"),L=require("./vmEmit"),q=require("./wrapInFunction");exports.luaObfuscatorPresets=["Minify","Weak","Medium","Strong"];function P(n){let t=2166136261;for(let r=0;r<n.length;r+=1)t=Math.imul(t^n.charCodeAt(r),16777619);return t>>>0||1}function o(n){return(0,p.parseLua)((0,L.emitVm)((0,b.compileChunk)(n)))}function i(n,t,r){(0,y.applyConstantArray)(n,t,{shuffle:r.shuffle,rotate:r.shuffle}),r.numbersOnVm&&(0,a.numbersToExpressions)(n,(t^2654435769)>>>0);for(let e=0;e<r.wraps;e+=1)(0,q.wrapInFunction)(n);return(0,m.renameLocals)(n),(0,c.minifyLua)(n)}function E(n,t){const r=P(n);let e=(0,p.parseLua)(n);return(0,m.renameLocals)(e),t==="Minify"?(0,c.minifyLua)(e):t==="Weak"?((0,u.flattenControlFlow)(e,r),e=o(e),i(e,r,{shuffle:!1,wraps:1,numbersOnVm:!1})):t==="Medium"?((0,l.addVararg)(e),(0,d.splitStrings)(e,r),(0,a.numbersToExpressions)(e,r),(0,f.applyAntiTamper)(e,r),(0,u.flattenControlFlow)(e,r),e=o(e),i(e,r,{shuffle:!0,wraps:1,numbersOnVm:!0})):((0,l.addVararg)(e),(0,d.splitStrings)(e,(r^2135587861)>>>0),(0,a.numbersToExpressions)(e,r),(0,f.applyAntiTamper)(e,(r^2246822507)>>>0),(0,u.flattenControlFlow)(e,(r^2246822507)>>>0),e=o(e),i(e,r,{shuffle:!0,wraps:2,numbersOnVm:!0}))}var O=require("./lexer");Object.defineProperty(exports,"LuaLexError",{enumerable:!0,get:function(){return O.LuaLexError}});var g=require("./parser");Object.defineProperty(exports,"LuaParseError",{enumerable:!0,get:function(){return g.LuaParseError}});var s=require("./strings");Object.defineProperty(exports,"foldDecrypt",{enumerable:!0,get:function(){return s.foldDecrypt}}),Object.defineProperty(exports,"foldEncrypt",{enumerable:!0,get:function(){return s.foldEncrypt}}),Object.defineProperty(exports,"createFoldMixParams",{enumerable:!0,get:function(){return s.createFoldMixParams}});
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.LuaLexError=void 0,exports.lexLua=
|
|
2
|
-
`?(m+=1,d=1):d+=1,u},a=u=>{throw new F(u,m,d)},b=u=>u>="A"&&u<="Z"||u>="a"&&u<="z"||u==="_",E=u=>u>="0"&&u<="9",p=u=>E(u)||u>="a"&&u<="f"||u>="A"&&u<="F",C=u=>{const
|
|
3
|
-
`||u==="\f"||u==="\v",B=u=>{if(
|
|
4
|
-
`&&e();let
|
|
5
|
-
`;)e()},
|
|
6
|
-
`)return a("\u77ED\u5B57\u7B26\u4E32\u5185\u51FA\u73B0\u672A\u8F6C\u4E49\u6362\u884C");if(n!=="\\"){
|
|
7
|
-
`;else if(
|
|
8
|
-
`)
|
|
9
|
-
`&&e(),
|
|
10
|
-
`;else if(
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.LuaLexError=void 0,exports.lexLua=y;const L=require("./reserved");class F extends Error{constructor(s,l,c){super(`${s} (${l}:${c})`),Object.defineProperty(this,"line",{enumerable:!0,configurable:!0,writable:!0,value:l}),Object.defineProperty(this,"column",{enumerable:!0,configurable:!0,writable:!0,value:c}),this.name="LuaLexError"}}exports.LuaLexError=F;function y(v){const s=v.replace(/^\uFEFF/,""),l=[];let c=0,m=1,d=1;const r=(u=0)=>s[c+u]??"",h=()=>c>=s.length,e=()=>{const u=s[c++];return u===`
|
|
2
|
+
`?(m+=1,d=1):d+=1,u},a=u=>{throw new F(u,m,d)},b=u=>u>="A"&&u<="Z"||u>="a"&&u<="z"||u==="_",E=u=>u>="0"&&u<="9",p=u=>E(u)||u>="a"&&u<="f"||u>="A"&&u<="F",C=u=>{const t=Buffer.from(u,"utf8");let n="";for(const i of t)n+=String.fromCharCode(i);return n},g=u=>u===" "||u===" "||u==="\r"||u===`
|
|
3
|
+
`||u==="\f"||u==="\v",B=u=>{if(s[u]!=="[")return-1;let t=0,n=u+1;for(;s[n]==="=";)t+=1,n+=1;return s[n]==="["?t:-1},k=u=>{e();for(let n=0;n<u;n+=1)e();e(),r()==="\r"&&e(),r()===`
|
|
4
|
+
`&&e();let t="";for(;!h();){if(r()==="]"){let n=c+1,i=0;for(;s[n]==="=";)i+=1,n+=1;if(i===u&&s[n]==="]"){e();for(let o=0;o<u;o+=1)e();return e(),t}}t+=C(e())}return a("\u672A\u95ED\u5408\u7684\u957F\u62EC\u53F7\u5B57\u7B26\u4E32\u6216\u6CE8\u91CA")},w=()=>{for(;!h()&&r()!==`
|
|
5
|
+
`;)e()},A=u=>{e();let t="";for(;!h();){const n=r();if(n===u)return e(),t;if(n===`
|
|
6
|
+
`)return a("\u77ED\u5B57\u7B26\u4E32\u5185\u51FA\u73B0\u672A\u8F6C\u4E49\u6362\u884C");if(n!=="\\"){t+=C(e());continue}e();const i=r();if(i==="a")e(),t+="\x07";else if(i==="b")e(),t+="\b";else if(i==="f")e(),t+="\f";else if(i==="n")e(),t+=`
|
|
7
|
+
`;else if(i==="r")e(),t+="\r";else if(i==="t")e(),t+=" ";else if(i==="v")e(),t+="\v";else if(i==="\\"||i==='"'||i==="'"||i===`
|
|
8
|
+
`)t+=e();else if(i==="\r")e(),r()===`
|
|
9
|
+
`&&e(),t+=`
|
|
10
|
+
`;else if(i==="x"){e();const o=r(),f=r(1);if(!p(o)||!p(f))return a("\u65E0\u6548\u7684 \\x \u8F6C\u4E49");e(),e(),t+=String.fromCharCode(parseInt(o+f,16))}else if(i==="u"){if(e(),r()!=="{")return a("\u65E0\u6548\u7684 \\u \u8F6C\u4E49");e();let o="";for(;p(r());)o+=e();if(r()!=="}"||o.length===0)return a("\u65E0\u6548\u7684 \\u{...} \u8F6C\u4E49");e(),t+=C(String.fromCodePoint(parseInt(o,16)))}else if(i==="z")for(e();g(r());)e();else if(E(i)){let o="";for(;E(r())&&o.length<3;)o+=e();const f=parseInt(o,10);if(f>255)return a("\u5341\u8FDB\u5236\u8F6C\u4E49\u8D85\u8FC7 255");t+=String.fromCharCode(f)}else return a(`\u65E0\u6548\u7684\u8F6C\u4E49\u5E8F\u5217 \\${i}`)}return a("\u672A\u95ED\u5408\u7684\u77ED\u5B57\u7B26\u4E32")},D=()=>{const u=m,t=d;let n="";if(r()==="0"&&(r(1)==="x"||r(1)==="X")){for(n+=e(),n+=e();p(r())||r()===".";)n+=e();if(r()==="p"||r()==="P")for(n+=e(),(r()==="+"||r()==="-")&&(n+=e());E(r());)n+=e()}else{for(;E(r())||r()===".";)n+=e();if(r()==="e"||r()==="E")for(n+=e(),(r()==="+"||r()==="-")&&(n+=e());E(r());)n+=e()}const i=Number(n);if(!Number.isFinite(i))throw new F(`\u65E0\u6548\u6570\u5B57 ${n}`,u,t);return{kind:"number",value:n,line:u,column:t,parsed:i}};for(;!h();){const u=r();if(g(u)){e();continue}if(u==="-"&&r(1)==="-"){const f=m,$=d;e(),e();const x=B(c);x>=0?k(x):w();continue}const t=m,n=d;if(u==="'"||u==='"'){const f=A(u);l.push({kind:"string",value:f,line:t,column:n,parsed:f});continue}const i=B(c);if(i>=0){const f=k(i);l.push({kind:"string",value:f,line:t,column:n,parsed:f});continue}if(E(u)||u==="."&&E(r(1))){l.push(D());continue}if(b(u)){let f="";for(;b(r())||E(r());)f+=e();l.push({kind:L.luaKeywords.has(f)?"keyword":"name",value:f,line:t,column:n});continue}const o=u+r(1);if(o+r(2)==="..."){e(),e(),e(),l.push({kind:"vararg",value:"...",line:t,column:n});continue}if(["//","<<",">>","==","~=","<=",">=","..","::"].includes(o)){e(),e(),l.push({kind:o,value:o,line:t,column:n});continue}if(["+","-","*","/","%","^","#","&","|","~","<",">","=","(",")","{","}","[","]",";",":",",","."].includes(u)){e(),l.push({kind:u,value:u,line:t,column:n});continue}a(`\u975E\u6CD5\u5B57\u7B26 ${JSON.stringify(u)}`)}return l.push({kind:"eof",value:"",line:m,column:d}),l}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.numbersToExpressions=o;const y=require("./visit");function l(e,a){const t=Math.abs(a)%9+2,r=e-t;if(e<0)return{type:"UnaryExpr",op:"-",arg:l(-e,a+3)};if(e<=2)return{type:"NumberLiteral",raw:String(e),value:e};if(a%3===0){const p=e%7+2,
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.numbersToExpressions=o;const y=require("./visit");function l(e,a){const t=Math.abs(a)%9+2,r=e-t;if(e<0)return{type:"UnaryExpr",op:"-",arg:l(-e,a+3)};if(e<=2)return{type:"NumberLiteral",raw:String(e),value:e};if(a%3===0){const p=e%7+2,i=Math.floor(e/p),n=e-p*i,u={type:"BinaryExpr",op:"*",left:{type:"NumberLiteral",raw:String(p),value:p},right:{type:"NumberLiteral",raw:String(i),value:i}};return n===0?{type:"ParenExpr",exp:u}:{type:"ParenExpr",exp:{type:"BinaryExpr",op:"+",left:u,right:{type:"NumberLiteral",raw:String(n),value:n}}}}return{type:"ParenExpr",exp:{type:"BinaryExpr",op:"+",left:{type:"NumberLiteral",raw:String(t),value:t},right:{type:"NumberLiteral",raw:String(r),value:r}}}}function o(e,a){let t=0;(0,y.mapChunk)(e,r=>r.type!=="NumberLiteral"||!Number.isInteger(r.value)||!Number.isSafeInteger(r.value)?r:(t+=1,l(r.value,a+t*17)))}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.LuaParseError=void 0,exports.parseLua=te;const Z=require("./ast"),ee=require("./lexer");class j extends Error{constructor(b,p
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.LuaParseError=void 0,exports.parseLua=te;const Z=require("./ast"),ee=require("./lexer");class j extends Error{constructor(b,l,p){super(`${b} (${l}:${p})`),Object.defineProperty(this,"line",{enumerable:!0,configurable:!0,writable:!0,value:l}),Object.defineProperty(this,"column",{enumerable:!0,configurable:!0,writable:!0,value:p}),this.name="LuaParseError"}}exports.LuaParseError=j;function te(E){const b=(0,ee.lexLua)(E);let l=0;const p=()=>b[l],u=(e,t)=>{const n=p();return!(n.kind!==e||t!==void 0&&n.value!==t)},w=e=>u("keyword",e),m=e=>{const t=p();throw new j(e,t.line,t.column)},r=(e,t)=>{const n=p();return n.kind!==e||t!==void 0&&n.value!==t?m(`\u671F\u671B ${t??e}\uFF0C\u5B9E\u9645 ${n.value||n.kind}`):(l+=1,n)},o=(e,t)=>{if(u(e,t)){const n=p();return l+=1,n}},a=e=>w(e)?(l+=1,!0):!1,s=()=>r("name").value,c=e=>{const t=[];for(;!u("eof")&&!(p().kind==="keyword"&&e.includes(p().value));){if(w("return")){t.push($()),o(";");break}const n=D();n&&t.push(n)}return{type:"Block",body:t}},$=()=>(r("keyword","return"),u("eof")||u(";")||p().kind==="keyword"&&["end","else","elseif","until"].includes(p().value)?{type:"ReturnStat",exps:[]}:{type:"ReturnStat",exps:k()}),D=()=>{if(o(";"))return{type:"EmptyStat"};if(a("break"))return{type:"BreakStat"};if(a("goto"))return{type:"GotoStat",name:s()};if(a("do")){const e=c(["end"]);return r("keyword","end"),{type:"DoStat",body:e}}if(a("while")){const e=i();r("keyword","do");const t=c(["end"]);return r("keyword","end"),{type:"WhileStat",cond:e,body:t}}if(a("repeat")){const e=c(["until"]);r("keyword","until");const t=i();return{type:"RepeatStat",body:e,cond:t}}if(a("if"))return N();if(a("for"))return U();if(a("function")){const e=I(),t=v(!!e.method);return{type:"FuncStat",name:e,func:t}}if(a("local")){if(a("function")){const e=s(),t=v(!1);return{type:"LocalFuncStat",name:e,func:t}}return M()}if(u("::")){r("::");const e=s();return r("::"),{type:"LabelStat",name:e}}return O()},N=()=>{const e=[],t=i();for(r("keyword","then"),e.push({cond:t,body:c(["elseif","else","end"])});a("elseif");){const d=i();r("keyword","then"),e.push({cond:d,body:c(["elseif","else","end"])})}let n;return a("else")&&(n=c(["end"])),r("keyword","end"),{type:"IfStat",clauses:e,elseBody:n}},U=()=>{const e=s();if(o("=")){const h=i();r(",");const g=i();let P;o(",")&&(P=i()),r("keyword","do");const Y=c(["end"]);return r("keyword","end"),{type:"ForNumStat",name:e,start:h,end:g,step:P,body:Y}}const t=[e];for(;o(",");)t.push(s());r("keyword","in");const n=k();r("keyword","do");const d=c(["end"]);return r("keyword","end"),{type:"ForInStat",names:t,exps:n,body:d}},I=()=>{const e=s(),t=[];for(;o(".");)t.push(s());let n;return o(":")&&(n=s()),{base:e,fields:t,method:n}},v=e=>{r("(");const t=[];e&&t.push("self");let n=!1;if(!u(")"))if(u("vararg"))r("vararg"),n=!0;else for(t.push(s());o(",");){if(u("vararg")){r("vararg"),n=!0;break}t.push(s())}r(")");const d=c(["end"]);return r("keyword","end"),{type:"FuncExpr",params:t,vararg:n,body:d}},M=()=>{const e=[S()];for(;o(",");)e.push(S());let t;return o("=")&&(t=k()),{type:"LocalStat",names:e,exps:t}},S=()=>{const e=s();if(o("<")){const t=s();return r(">"),t!=="const"&&t!=="close"&&m(`\u672A\u77E5\u5C5E\u6027 <${t}>`),{name:e,attr:t}}return{name:e}},O=()=>{const e=x();if(u("=")||u(",")){const t=[e];for(;o(",");)t.push(x());r("=");const n=k();return{type:"AssignStat",vars:t,exps:n}}return(0,Z.isCallExpression)(e)?{type:"CallStat",exp:e}:m("\u8BED\u53E5\u5FC5\u987B\u662F\u8D4B\u503C\u6216\u51FD\u6570\u8C03\u7528")},k=()=>{const e=[i()];for(;o(",");)e.push(i());return e},i=()=>R(),y=(e,t)=>{let n=e();for(;;){const d=p(),h=d.kind==="keyword"?d.value:d.kind;if(!t.includes(h))break;l+=1;const g=e();n={type:"BinaryExpr",op:h,left:n,right:g}}return n},R=()=>y(q,["or"]),q=()=>y(A,["and"]),A=()=>y(_,["<",">","<=",">=","~=","=="]),_=()=>y(G,["|"]),G=()=>y(T,["~"]),T=()=>y(V,["&"]),V=()=>y(B,["<<",">>"]),B=()=>{const e=W();return u("..")?(l+=1,{type:"BinaryExpr",op:"..",left:e,right:B()}):e},W=()=>y(z,["+","-"]),z=()=>y(f,["*","/","//","%"]),f=()=>a("not")?{type:"UnaryExpr",op:"not",arg:f()}:o("#")?{type:"UnaryExpr",op:"#",arg:f()}:o("-")?{type:"UnaryExpr",op:"-",arg:f()}:o("~")?{type:"UnaryExpr",op:"~",arg:f()}:H(),H=()=>{const e=J();return u("^")?(l+=1,{type:"BinaryExpr",op:"^",left:e,right:f()}):e},J=()=>{if(a("nil"))return{type:"NilLiteral"};if(a("true"))return{type:"BoolLiteral",value:!0};if(a("false"))return{type:"BoolLiteral",value:!1};if(u("number")){const e=r("number");return{type:"NumberLiteral",raw:e.value,value:e.parsed}}if(u("string"))return{type:"StringLiteral",value:r("string").parsed};if(o("vararg"))return{type:"VarargExpr"};if(a("function"))return v(!1);if(u("{")){let e=C();return e=F(e),e}return x()},F=e=>{let t=e;for(;;){if(o(".")){t={type:"MemberExpr",object:t,field:s()};continue}if(o("[")){const n=i();r("]"),t={type:"IndexExpr",object:t,index:n};continue}if(o(":")){const n=s(),d=L();t={type:"MethodCallExpr",object:t,method:n,args:d};continue}if(u("(")||u("{")||u("string")){t={type:"CallExpr",callee:t,args:L()};continue}break}return t},x=()=>F(K()),K=()=>{if(o("(")){const e=i();return r(")"),{type:"ParenExpr",exp:e}}return u("name")?{type:"NameExpr",name:s()}:m("\u671F\u671B\u8868\u8FBE\u5F0F")},L=()=>{if(u("string"))return[{type:"StringLiteral",value:r("string").parsed}];if(u("{"))return[C()];if(r("("),o(")"))return[];const e=k();return r(")"),e},C=()=>{r("{");const e=[];for(;!u("}")&&(e.push(Q()),!(!o(",")&&!o(";"))););return r("}"),{type:"TableExpr",fields:e}},Q=()=>{if(o("[")){const e=i();return r("]"),r("="),{kind:"index",key:e,value:i()}}if(u("name")&&b[l+1]?.kind==="="){const e=s();return r("="),{kind:"name",key:e,value:i()}}return{kind:"list",value:i()}},X=c([]);return r("eof"),{type:"Chunk",body:X.body}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.shortName=
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.shortName=r,exports.renameLocals=c;const u=require("./reserved"),d=require("./scope"),l="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";function r(a){let e=a,t="";do t=l[e%l.length]+t,e=Math.floor(e/l.length)-1;while(e>=0);return u.luaKeywords.has(t)?`_${t}`:t}function c(a){let e=0;const t=new Set;(0,d.collectAndRename)(a,(o,s)=>{if(o.newName!==o.original)return;let n=r(e);for(e+=1;s.has(n)||t.has(n)||u.luaKeywords.has(n);)n=r(e),e+=1;o.newName=n,t.add(n),s.add(n)})}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.resolveLocal=i,exports.collectAndRename=
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.resolveLocal=i,exports.collectAndRename=x;function i(e,t){let r=e;for(;r;){const o=r.locals.get(t);if(o)return o;r=r.parent}}function n(e){return{parent:e,locals:new Map}}function f(e,t){const r=e.locals.get(t);if(r)return r;const o={original:t,newName:t};return e.locals.set(t,o),o}function x(e,t){const r=new Set,o={locals:new Map};d(e.body,o,r,t)}function l(e,t,r,o){d(e.body,t,r,o)}function d(e,t,r,o){for(const s of e)b(s,t,r,o)}function m(e,t,r,o){const s=n(t),a=e.params.slice();for(let u=0;u<a.length;u+=1){const p=f(s,a[u]);o(p,r),e.params[u]=p.newName}l(e.body,s,r,o)}function b(e,t,r,o){switch(e.type){case"EmptyStat":case"BreakStat":case"GotoStat":case"LabelStat":return;case"DoStat":l(e.body,n(t),r,o);return;case"WhileStat":c(e.cond,t,r,o),l(e.body,n(t),r,o);return;case"RepeatStat":{const s=n(t);l(e.body,s,r,o),c(e.cond,s,r,o);return}case"IfStat":for(const s of e.clauses)c(s.cond,t,r,o),l(s.body,n(t),r,o);e.elseBody&&l(e.elseBody,n(t),r,o);return;case"ForNumStat":{c(e.start,t,r,o),c(e.end,t,r,o),e.step&&c(e.step,t,r,o);const s=n(t),a=f(s,e.name);o(a,r),e.name=a.newName,l(e.body,s,r,o);return}case"ForInStat":{for(const a of e.exps)c(a,t,r,o);const s=n(t);for(let a=0;a<e.names.length;a+=1){const u=f(s,e.names[a]);o(u,r),e.names[a]=u.newName}l(e.body,s,r,o);return}case"FuncStat":{const s=i(t,e.name.base);s&&(e.name.base=s.newName),m(e.func,t,r,o);return}case"LocalFuncStat":{const s=f(t,e.name);o(s,r),e.name=s.newName,m(e.func,t,r,o);return}case"LocalStat":if(e.exps)for(const s of e.exps)c(s,t,r,o);for(let s=0;s<e.names.length;s+=1){const a=f(t,e.names[s].name);o(a,r),e.names[s].name=a.newName}return;case"AssignStat":for(const s of e.vars)c(s,t,r,o);for(const s of e.exps)c(s,t,r,o);return;case"CallStat":c(e.exp,t,r,o);return;case"ReturnStat":for(const s of e.exps)c(s,t,r,o);return}}function c(e,t,r,o){switch(e.type){case"NilLiteral":case"BoolLiteral":case"NumberLiteral":case"StringLiteral":case"VarargExpr":return;case"NameExpr":{const s=i(t,e.name);s&&(e.name=s.newName);return}case"UnaryExpr":c(e.arg,t,r,o);return;case"BinaryExpr":c(e.left,t,r,o),c(e.right,t,r,o);return;case"FuncExpr":m(e,t,r,o);return;case"TableExpr":for(const s of e.fields)s.kind==="index"&&c(s.key,t,r,o),c(s.value,t,r,o);return;case"IndexExpr":c(e.object,t,r,o),c(e.index,t,r,o);return;case"MemberExpr":c(e.object,t,r,o);return;case"CallExpr":c(e.callee,t,r,o);for(const s of e.args)c(s,t,r,o);return;case"MethodCallExpr":c(e.object,t,r,o);for(const s of e.args)c(s,t,r,o);return;case"ParenExpr":c(e.exp,t,r,o);return}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.splitStrings=
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.splitStrings=o;const u=require("./visit");function a(e){let r={type:"StringLiteral",value:e[0]};for(let n=1;n<e.length;n+=1)r={type:"BinaryExpr",op:"..",left:r,right:{type:"StringLiteral",value:e[n]}};return{type:"ParenExpr",exp:r}}function p(e,r){if(e.length<4)return[e];const n=r%2+2,t=Math.max(1,Math.ceil(e.length/n)),l=[];for(let i=0;i<e.length;i+=t)l.push(e.slice(i,i+t));return l}function o(e,r){let n=0;(0,u.mapChunk)(e,t=>{if(t.type!=="StringLiteral"||t.encoded||t.value.length<4)return t;n+=1;const l=p(t.value,r+n);return l.length<2?t:a(l)})}
|
package/docs/api/opencv.md
CHANGED
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
|
|
35
35
|
```javascript
|
|
36
36
|
const src = cv.capture();
|
|
37
|
-
const gray = cv.cvtColor(src,
|
|
37
|
+
const gray = cv.cvtColor(src, cv.COLOR_BGR2GRAY);
|
|
38
38
|
const edges = cv.Canny(gray, { threshold1: 100, threshold2: 200 });
|
|
39
39
|
const feat = cv.SIFT(gray, { nfeatures: 500 });
|
|
40
40
|
logi(`keypoints=${feat.keypoints.length}`);
|
|
@@ -51,7 +51,7 @@ cv.release(feat.descriptors);
|
|
|
51
51
|
const imageId = image.captureScreen();
|
|
52
52
|
const mat = cv.imread(imageId); // 或 cv.fromImageId(imageId)
|
|
53
53
|
image.release(imageId);
|
|
54
|
-
const gray = cv.cvtColor(mat,
|
|
54
|
+
const gray = cv.cvtColor(mat, cv.COLOR_BGR2GRAY);
|
|
55
55
|
const outId = cv.toImageId(gray);
|
|
56
56
|
cv.release(mat);
|
|
57
57
|
cv.release(gray);
|
|
@@ -316,7 +316,7 @@ cv.release(copy);
|
|
|
316
316
|
|
|
317
317
|
```typescript
|
|
318
318
|
function cvtColor(mat: Mat, code: number): Mat | null;
|
|
319
|
-
const hsv = cv.cvtColor(src,
|
|
319
|
+
const hsv = cv.cvtColor(src, cv.COLOR_BGR2HSV);
|
|
320
320
|
```
|
|
321
321
|
|
|
322
322
|
### threshold - 固定阈值
|
|
@@ -385,8 +385,8 @@ function inRange(mat: Mat, options: { lowerb: number[]; upperb: number[] }): Mat
|
|
|
385
385
|
**示例:**
|
|
386
386
|
|
|
387
387
|
```javascript
|
|
388
|
-
const hsv = cv.cvtColor(src,
|
|
389
|
-
const mask = cv.inRange(hsv, {
|
|
388
|
+
const hsv = cv.cvtColor(src, cv.COLOR_BGR2HSV);
|
|
389
|
+
const mask = cv.inRange(hsv, { lowerb: [0, 80, 80], upperb: [20, 255, 255] });
|
|
390
390
|
```
|
|
391
391
|
|
|
392
392
|
### bitwise_and / bitwise_or / bitwise_xor / bitwise_not
|
|
@@ -994,7 +994,7 @@ function SIFT(mat: Mat, options?: {
|
|
|
994
994
|
**示例:**
|
|
995
995
|
|
|
996
996
|
```javascript
|
|
997
|
-
const gray = cv.cvtColor(src,
|
|
997
|
+
const gray = cv.cvtColor(src, cv.COLOR_BGR2GRAY);
|
|
998
998
|
const feat = cv.SIFT(gray, { nfeatures: 500 });
|
|
999
999
|
if (feat) {
|
|
1000
1000
|
logi(`SIFT keypoints=${feat.keypoints.length}`);
|
|
@@ -1113,8 +1113,8 @@ function findHomography(options: {
|
|
|
1113
1113
|
|
|
1114
1114
|
function perspectiveTransform(points: Point[], options: { M: Mat }): Point[] | null;
|
|
1115
1115
|
const templ = cv.imread("logo.png");
|
|
1116
|
-
const g1 = cv.cvtColor(src,
|
|
1117
|
-
const g2 = cv.cvtColor(templ,
|
|
1116
|
+
const g1 = cv.cvtColor(src, cv.COLOR_BGR2GRAY);
|
|
1117
|
+
const g2 = cv.cvtColor(templ, cv.COLOR_BGR2GRAY);
|
|
1118
1118
|
|
|
1119
1119
|
const f1 = cv.SIFT(g1, { nfeatures: 800 });
|
|
1120
1120
|
const f2 = cv.SIFT(g2, { nfeatures: 800 });
|
package/docs/apilua/cloud.md
CHANGED
package/docs/apilua/file.md
CHANGED
|
@@ -238,7 +238,7 @@ end
|
|
|
238
238
|
|
|
239
239
|
```lua
|
|
240
240
|
---@param path string
|
|
241
|
-
---@return string
|
|
241
|
+
---@return string
|
|
242
242
|
function readFile(path) end
|
|
243
243
|
```
|
|
244
244
|
|
|
@@ -250,18 +250,18 @@ function readFile(path) end
|
|
|
250
250
|
|
|
251
251
|
**返回值:**
|
|
252
252
|
|
|
253
|
-
| 类型
|
|
254
|
-
|
|
|
255
|
-
| `string
|
|
253
|
+
| 类型 | 描述 |
|
|
254
|
+
| -------- | ------------------------ |
|
|
255
|
+
| `string` | 文件内容;失败时为空字符串 |
|
|
256
256
|
|
|
257
257
|
**示例:**
|
|
258
258
|
|
|
259
259
|
```lua
|
|
260
260
|
local content = file.readFile("/path/to/file.txt")
|
|
261
|
-
if content ~=
|
|
262
|
-
print("文件内容: " ..
|
|
261
|
+
if content ~= "" then
|
|
262
|
+
print("文件内容: " .. content)
|
|
263
263
|
else
|
|
264
|
-
print("
|
|
264
|
+
print("读取失败")
|
|
265
265
|
end
|
|
266
266
|
```
|
|
267
267
|
|
|
@@ -274,7 +274,7 @@ end
|
|
|
274
274
|
|
|
275
275
|
```lua
|
|
276
276
|
---@param fileName string
|
|
277
|
-
---@return string
|
|
277
|
+
---@return string
|
|
278
278
|
function readResFile(fileName) end
|
|
279
279
|
```
|
|
280
280
|
|
|
@@ -286,9 +286,9 @@ function readResFile(fileName) end
|
|
|
286
286
|
|
|
287
287
|
**返回值:**
|
|
288
288
|
|
|
289
|
-
| 类型
|
|
290
|
-
|
|
|
291
|
-
| `string
|
|
289
|
+
| 类型 | 描述 |
|
|
290
|
+
| -------- | ------------------------ |
|
|
291
|
+
| `string` | 文件内容;失败时为空字符串 |
|
|
292
292
|
|
|
293
293
|
**示例:**
|
|
294
294
|
|
|
@@ -409,7 +409,7 @@ end
|
|
|
409
409
|
```lua
|
|
410
410
|
---@param path string
|
|
411
411
|
---@param lineNo number
|
|
412
|
-
---@return string
|
|
412
|
+
---@return string
|
|
413
413
|
function readLine(path, lineNo) end
|
|
414
414
|
```
|
|
415
415
|
|
|
@@ -422,18 +422,18 @@ function readLine(path, lineNo) end
|
|
|
422
422
|
|
|
423
423
|
**返回值:**
|
|
424
424
|
|
|
425
|
-
| 类型
|
|
426
|
-
|
|
|
427
|
-
| `string
|
|
425
|
+
| 类型 | 描述 |
|
|
426
|
+
| -------- | ---------------------- |
|
|
427
|
+
| `string` | 行内容;失败时为空字符串 |
|
|
428
428
|
|
|
429
429
|
**示例:**
|
|
430
430
|
|
|
431
431
|
```lua
|
|
432
432
|
local firstLine = file.readLine("/path/to/file.txt", 1)
|
|
433
|
-
if firstLine ~=
|
|
434
|
-
print("第一行内容: " ..
|
|
433
|
+
if firstLine ~= "" then
|
|
434
|
+
print("第一行内容: " .. firstLine)
|
|
435
435
|
else
|
|
436
|
-
print("
|
|
436
|
+
print("读取失败")
|
|
437
437
|
end
|
|
438
438
|
```
|
|
439
439
|
|
|
@@ -441,7 +441,7 @@ end
|
|
|
441
441
|
|
|
442
442
|
```lua
|
|
443
443
|
---@param path string
|
|
444
|
-
---@return string[]
|
|
444
|
+
---@return string[]
|
|
445
445
|
function readAllLines(path) end
|
|
446
446
|
```
|
|
447
447
|
|
|
@@ -453,20 +453,16 @@ function readAllLines(path) end
|
|
|
453
453
|
|
|
454
454
|
**返回值:**
|
|
455
455
|
|
|
456
|
-
| 类型
|
|
457
|
-
|
|
|
458
|
-
| `string[]
|
|
456
|
+
| 类型 | 描述 |
|
|
457
|
+
| ---------- | -------------------- |
|
|
458
|
+
| `string[]` | 所有行;失败时为空表 |
|
|
459
459
|
|
|
460
460
|
**示例:**
|
|
461
461
|
|
|
462
462
|
```lua
|
|
463
463
|
local lines = file.readAllLines("/path/to/file.txt")
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
print("第" .. tostring(index + 1) .. "行: " .. tostring(line))
|
|
467
|
-
end)
|
|
468
|
-
else
|
|
469
|
-
print("读取所有行失败或文件不存在")
|
|
464
|
+
for i, line in ipairs(lines) do
|
|
465
|
+
print(i, line)
|
|
470
466
|
end
|
|
471
467
|
```
|
|
472
468
|
|
|
@@ -511,7 +507,7 @@ file.deleteLine("/path/to/file.txt", 5, "debug")
|
|
|
511
507
|
|
|
512
508
|
```lua
|
|
513
509
|
---@param path string
|
|
514
|
-
---@return string
|
|
510
|
+
---@return string
|
|
515
511
|
function fileMD5(path) end
|
|
516
512
|
```
|
|
517
513
|
|
|
@@ -523,16 +519,16 @@ function fileMD5(path) end
|
|
|
523
519
|
|
|
524
520
|
**返回值:**
|
|
525
521
|
|
|
526
|
-
| 类型
|
|
527
|
-
|
|
|
528
|
-
| `string
|
|
522
|
+
| 类型 | 描述 |
|
|
523
|
+
| -------- | ----------------------- |
|
|
524
|
+
| `string` | 文件 MD5;失败时为空字符串 |
|
|
529
525
|
|
|
530
526
|
**示例:**
|
|
531
527
|
|
|
532
528
|
```lua
|
|
533
529
|
local md5 = file.fileMD5("/path/to/file.txt")
|
|
534
|
-
if md5 then
|
|
535
|
-
print("文件MD5 = " ..
|
|
530
|
+
if md5 ~= "" then
|
|
531
|
+
print("文件MD5 = " .. md5)
|
|
536
532
|
else
|
|
537
533
|
print("获取MD5失败")
|
|
538
534
|
end
|
package/docs/apilua/global.md
CHANGED
|
@@ -4,10 +4,6 @@
|
|
|
4
4
|
|
|
5
5
|
**全局模块无调用前缀,直接使用即可。不要 `require`。**
|
|
6
6
|
|
|
7
|
-
`StartThread` 是同一 Lua VM 里的协作协程,不是操作系统线程;协程只在 `Sleep` 时被调度。
|
|
8
|
-
|
|
9
|
-
主脚本收到停止信号后,引擎会通过 instruction hook 和可中断的 `Sleep` 直接中断,不必在主循环里轮询 `ShouldInterruptThread`。
|
|
10
|
-
|
|
11
7
|
|
|
12
8
|
## 功能概览
|
|
13
9
|
|
|
@@ -170,7 +166,7 @@ end
|
|
|
170
166
|
|
|
171
167
|
### Sleep
|
|
172
168
|
|
|
173
|
-
|
|
169
|
+
等待指定的毫秒数。
|
|
174
170
|
|
|
175
171
|
```lua
|
|
176
172
|
---@param ms number
|
|
@@ -193,7 +189,7 @@ print("等待结束")
|
|
|
193
189
|
|
|
194
190
|
### Exit
|
|
195
191
|
|
|
196
|
-
退出当前脚本。
|
|
192
|
+
退出当前脚本。
|
|
197
193
|
|
|
198
194
|
```lua
|
|
199
195
|
function Exit() end
|
|
@@ -540,7 +536,7 @@ end)
|
|
|
540
536
|
|
|
541
537
|
### StartThread
|
|
542
538
|
|
|
543
|
-
|
|
539
|
+
启动协作协程,返回协程名。
|
|
544
540
|
|
|
545
541
|
```lua
|
|
546
542
|
---@param func function
|
|
@@ -571,7 +567,7 @@ local name = StartThread(function()
|
|
|
571
567
|
end)
|
|
572
568
|
```
|
|
573
569
|
|
|
574
|
-
`StopThread
|
|
570
|
+
需要停掉某个协程时调用 `StopThread`。
|
|
575
571
|
|
|
576
572
|
### StopThread
|
|
577
573
|
|
|
@@ -596,11 +592,7 @@ StopThread(name)
|
|
|
596
592
|
|
|
597
593
|
### ShouldInterruptThread
|
|
598
594
|
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
主脚本**不必**调用本函数:停止按钮、`Exit()`、引擎 stop 都会让 hook 和 `Sleep` 直接中断主程序。
|
|
602
|
-
|
|
603
|
-
仅当 `StartThread` 协程被 `StopThread` 之后还要自己做收尾(而不是靠抛错退出)时,才需要轮询。
|
|
595
|
+
当前协程是否应退出。`StopThread` 之后可在循环里判断。
|
|
604
596
|
|
|
605
597
|
```lua
|
|
606
598
|
---@return boolean
|
package/docs/apilua/http.md
CHANGED
|
@@ -19,7 +19,7 @@ function request(params) end
|
|
|
19
19
|
| 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
|
|
20
20
|
| ------------------- | ------- | -------- | -------- | --------------------------- |
|
|
21
21
|
| `url` | string | 是 | - | 请求地址 |
|
|
22
|
-
| `timeout` | number | 否 |
|
|
22
|
+
| `timeout` | number | 否 | 30000 | 请求超时时间(毫秒) |
|
|
23
23
|
| `method` | string | 否 | GET | 请求方法(GET、POST 等) |
|
|
24
24
|
| `proxy` | table | 否 | - | 代理服务器配置 |
|
|
25
25
|
| `followRedirects` | boolean | 否 | true | 是否跟随重定向 |
|
|
@@ -106,7 +106,7 @@ function httpGet(url, params, timeout, headers) end
|
|
|
106
106
|
| --------- | ---------------------- | -------- | ------ | ---------------- |
|
|
107
107
|
| `url` | string | 是 | - | 请求地址 |
|
|
108
108
|
| `params` | table | 否 | - | URL 查询参数 |
|
|
109
|
-
| `timeout` | number | 否 |
|
|
109
|
+
| `timeout` | number | 否 | 30000 | 超时时间(毫秒) |
|
|
110
110
|
| `headers` | table | 否 | - | 请求头 |
|
|
111
111
|
|
|
112
112
|
**返回值:**
|
|
@@ -150,7 +150,7 @@ function httpPost(url, params, files, timeout, headers) end
|
|
|
150
150
|
| `url` | string | 是 | - | 请求地址 |
|
|
151
151
|
| `params` | table | 否 | - | 表单参数 |
|
|
152
152
|
| `files` | table | 否 | - | 文件参数 |
|
|
153
|
-
| `timeout` | number | 否 |
|
|
153
|
+
| `timeout` | number | 否 | 30000 | 超时时间(毫秒) |
|
|
154
154
|
| `headers` | table | 否 | - | 请求头 |
|
|
155
155
|
|
|
156
156
|
**返回值:**
|
|
@@ -196,7 +196,7 @@ function postJSON(url, json, timeout, headers) end
|
|
|
196
196
|
| --------- | ---------------------- | -------- | ------ | ---------------- |
|
|
197
197
|
| `url` | string | 是 | - | 请求地址 |
|
|
198
198
|
| `json` | table | 否 | - | JSON 数据 |
|
|
199
|
-
| `timeout` | number | 否 |
|
|
199
|
+
| `timeout` | number | 否 | 30000 | 超时时间(毫秒) |
|
|
200
200
|
| `headers` | table | 否 | - | 请求头 |
|
|
201
201
|
|
|
202
202
|
**返回值:**
|
|
@@ -241,7 +241,7 @@ function downloadFile(url, file, timeout, headers) end
|
|
|
241
241
|
| --------- | ---------------------- | -------- | ------ | -------------------- |
|
|
242
242
|
| `url` | string | 是 | - | 文件下载地址 |
|
|
243
243
|
| `file` | string | 是 | - | 本地保存路径 |
|
|
244
|
-
| `timeout` | number | 否 |
|
|
244
|
+
| `timeout` | number | 否 | 30000 | 下载超时时间(毫秒) |
|
|
245
245
|
| `headers` | table | 否 | - | 请求头 |
|
|
246
246
|
|
|
247
247
|
**返回值:**
|
|
@@ -344,6 +344,8 @@ function sendBinary(data) end
|
|
|
344
344
|
|
|
345
345
|
#### 事件回调
|
|
346
346
|
|
|
347
|
+
这些回调在 `Sleep` 时执行。
|
|
348
|
+
|
|
347
349
|
```lua
|
|
348
350
|
---@param callback function
|
|
349
351
|
function onOpen(callback) end
|
package/docs/apilua/image.md
CHANGED
|
@@ -513,7 +513,7 @@ end
|
|
|
513
513
|
---@param ey number
|
|
514
514
|
---@param threshold number
|
|
515
515
|
---@param limit number
|
|
516
|
-
---@param method number
|
|
516
|
+
---@param method number?
|
|
517
517
|
---@param rgb boolean?
|
|
518
518
|
---@param options table?
|
|
519
519
|
---@return any
|
|
@@ -530,7 +530,7 @@ function findImage(imageId, templateImageId, x, y, ex, ey, threshold, limit, met
|
|
|
530
530
|
| `ex, ey` | number | 是 | - | 搜索区域右下角坐标;传 `0` 表示延伸到图片右侧或底部边界 |
|
|
531
531
|
| `threshold` | number | 是 | - | 匹配阈值 (0.0-1.0)。method `0`/`99` 建议 `0.5`–`0.6`;普通模板匹配(`1`/`3`/`5`)建议 `0.9`–`0.995` |
|
|
532
532
|
| `limit` | number | 是 | - | 最大查找数量,每个模板图片最多找 limit 个匹配结果 |
|
|
533
|
-
| `method` | number |
|
|
533
|
+
| `method` | number | 否 | `5` | 匹配方法,见下方说明 |
|
|
534
534
|
| `rgb` | boolean | 否 | `false` | 是否使用 RGB 找图,默认 `false` 会自动转灰度找图 |
|
|
535
535
|
| `options` | table | 否 | - | 额外选项。`scaleFactors` 仅 method=`99` 生效;`orz` 用于按方向取结果 |
|
|
536
536
|
| `options.scaleFactors` | number\[] | 否 | `[1.0, 0.9, 1.1, 0.8, 1.2]` | 仅 method=`99` 生效。模板相对当前图的缩放比列表(**不是** `device.getScreenScale()`)。应按 baseScale 动态计算,见下方详解;默认值只适合尺寸接近时的盲扫 |
|
|
@@ -650,19 +650,26 @@ local templateDeviceWidth = 750
|
|
|
650
650
|
local currentWidth = device.getScreenRealSize().width
|
|
651
651
|
local baseScale = currentWidth / templateDeviceWidth
|
|
652
652
|
-- 围绕 baseScale,步进 0.05,左右各扩 2 档 → 共 5 个
|
|
653
|
-
local function buildScaleFactors(base, step
|
|
654
|
-
|
|
653
|
+
local function buildScaleFactors(base, step, halfRange)
|
|
654
|
+
step = step or 0.05
|
|
655
|
+
halfRange = halfRange or 2
|
|
656
|
+
local list = { tonumber(string.format("%.4f", base)) }
|
|
655
657
|
for i = 1, halfRange do
|
|
656
|
-
list.
|
|
657
|
-
list.
|
|
658
|
+
list[#list + 1] = tonumber(string.format("%.4f", base - step * i))
|
|
659
|
+
list[#list + 1] = tonumber(string.format("%.4f", base + step * i))
|
|
658
660
|
end
|
|
659
|
-
|
|
660
|
-
|
|
661
|
+
local out = {}
|
|
662
|
+
for _, s in ipairs(list) do
|
|
663
|
+
if s > 0.05 and s < 8 then
|
|
664
|
+
out[#out + 1] = s
|
|
665
|
+
end
|
|
666
|
+
end
|
|
667
|
+
return out
|
|
661
668
|
end
|
|
662
669
|
|
|
663
670
|
local scaleFactors = buildScaleFactors(baseScale)
|
|
664
671
|
-- 例如 baseScale=1.56, step=0.05, halfRange=2
|
|
665
|
-
-- →
|
|
672
|
+
-- → { 1.56, 1.51, 1.61, 1.46, 1.66 }
|
|
666
673
|
```
|
|
667
674
|
|
|
668
675
|
##### 3. 按场景怎么选
|
|
@@ -766,18 +773,26 @@ local templateDeviceWidth = 750
|
|
|
766
773
|
local currentWidth = device.getScreenRealSize().width
|
|
767
774
|
local baseScale = currentWidth / templateDeviceWidth
|
|
768
775
|
|
|
769
|
-
local function buildScaleFactors(base, step
|
|
770
|
-
|
|
776
|
+
local function buildScaleFactors(base, step, halfRange)
|
|
777
|
+
step = step or 0.05
|
|
778
|
+
halfRange = halfRange or 2
|
|
779
|
+
local list = { tonumber(string.format("%.4f", base)) }
|
|
771
780
|
for i = 1, halfRange do
|
|
772
|
-
list.
|
|
773
|
-
list.
|
|
781
|
+
list[#list + 1] = tonumber(string.format("%.4f", base - step * i))
|
|
782
|
+
list[#list + 1] = tonumber(string.format("%.4f", base + step * i))
|
|
783
|
+
end
|
|
784
|
+
local out = {}
|
|
785
|
+
for _, s in ipairs(list) do
|
|
786
|
+
if s > 0.05 and s < 8 then
|
|
787
|
+
out[#out + 1] = s
|
|
788
|
+
end
|
|
774
789
|
end
|
|
775
|
-
return
|
|
790
|
+
return out
|
|
776
791
|
end
|
|
777
792
|
|
|
778
793
|
local scaleFactors = buildScaleFactors(baseScale)
|
|
779
|
-
-- 750 → 1170 时约等于
|
|
780
|
-
print(
|
|
794
|
+
-- 750 → 1170 时约等于 { 1.56, 1.51, 1.61, 1.46, 1.66 }
|
|
795
|
+
print(string.format("baseScale=%.3f scaleFactors=%s", baseScale, ToJsonString(scaleFactors)))
|
|
781
796
|
|
|
782
797
|
local scaled = image.findImage(
|
|
783
798
|
"screen",
|
package/docs/apilua/node.md
CHANGED
|
@@ -90,7 +90,7 @@ local listPage = node.createNodeSelector({ mode = 2 })
|
|
|
90
90
|
| `input(text)` | 追加输入,不清空原内容;不可见时会先自动滚到可见 |
|
|
91
91
|
| `setValue(text)` | 设置值(见下方;不可见时会先自动滚到可见) |
|
|
92
92
|
| `parent()` | 父节点 |
|
|
93
|
-
| `child(index)` | 第 `index`
|
|
93
|
+
| `child(index)` | 第 `index` 个子节点,`index` 从 0 开始 |
|
|
94
94
|
| `allChildren()` | 全部子节点 |
|
|
95
95
|
| `siblings()` | 全部兄弟节点 |
|
|
96
96
|
| `previousSiblings()` | 前面的兄弟 |
|
package/docs/apilua/opencv.md
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
- 路径 / msbundle / imageId / `screen` 等读图只用 `imread`;其它 API 只接受 Mat 句柄;`imdecode` 只解 base64。
|
|
12
12
|
- 用完请 `release` / `releaseAll`。
|
|
13
13
|
- 颜色参数为 **BGR**;也可用 `#RRGGBB`。
|
|
14
|
-
- options 用 Lua 表:`{
|
|
14
|
+
- options 用 Lua 表:`{ threshold1 = 100, threshold2 = 200 }`;`cvtColor` 第二参是数字:`cv.cvtColor(src, cv.COLOR_BGR2GRAY)`;点集用 `{ { x = 1, y = 2 }, ... }`。
|
|
15
15
|
|
|
16
16
|
## 功能一览
|
|
17
17
|
|
|
@@ -53,7 +53,7 @@ Mat:`Mat` · `zeros` · `ones` · `clone` · `empty` · `isRelease` · `releas
|
|
|
53
53
|
```lua
|
|
54
54
|
|
|
55
55
|
local src = cv.capture()
|
|
56
|
-
local gray = cv.cvtColor(src,
|
|
56
|
+
local gray = cv.cvtColor(src, cv.COLOR_BGR2GRAY)
|
|
57
57
|
local edges = cv.Canny(gray, { threshold1 = 100, threshold2 = 200 })
|
|
58
58
|
local feat = cv.SIFT(gray, { nfeatures = 500 })
|
|
59
59
|
if feat then
|
|
@@ -227,7 +227,7 @@ function imencode(ext, mat, quality) end
|
|
|
227
227
|
**示例:**
|
|
228
228
|
|
|
229
229
|
```lua
|
|
230
|
-
local b64 = cv.imencode(".jpg", mat,
|
|
230
|
+
local b64 = cv.imencode(".jpg", mat, 85)
|
|
231
231
|
```
|
|
232
232
|
|
|
233
233
|
### fromImageId / toImageId - 与 image 互通
|
|
@@ -278,7 +278,7 @@ function Mat(options) end
|
|
|
278
278
|
|
|
279
279
|
```lua
|
|
280
280
|
local z = cv.zeros({ rows = 100, cols = 100, type = cv.CV_8UC3 })
|
|
281
|
-
local filled = cv.Mat({ rows = 10, cols = 10, type = cv.CV_8UC1, scalar =
|
|
281
|
+
local filled = cv.Mat({ rows = 10, cols = 10, type = cv.CV_8UC1, scalar = { 255 } })
|
|
282
282
|
cv.release(z)
|
|
283
283
|
cv.release(filled)
|
|
284
284
|
```
|
|
@@ -396,8 +396,8 @@ function inRange(mat, options) end
|
|
|
396
396
|
**示例:**
|
|
397
397
|
|
|
398
398
|
```lua
|
|
399
|
-
local hsv = cv.cvtColor(src,
|
|
400
|
-
local mask = cv.inRange(hsv, {
|
|
399
|
+
local hsv = cv.cvtColor(src, cv.COLOR_BGR2HSV)
|
|
400
|
+
local mask = cv.inRange(hsv, { lowerb = { 0, 80, 80 }, upperb = { 20, 255, 255 } })
|
|
401
401
|
```
|
|
402
402
|
|
|
403
403
|
### countNonZero / minMaxLoc / mean / split / merge
|
|
@@ -648,11 +648,12 @@ function boundingRect(matOrPoints) end
|
|
|
648
648
|
```lua
|
|
649
649
|
for _, c in ipairs(contours) do
|
|
650
650
|
local area = cv.contourArea(c)
|
|
651
|
-
if
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
651
|
+
if area >= 100 then
|
|
652
|
+
local rect = cv.boundingRect(c)
|
|
653
|
+
local hull = cv.convexHull(c)
|
|
654
|
+
local approx = cv.approxPolyDP(c, { epsilon = 0.02 * cv.arcLength(c, true), closed = true })
|
|
655
|
+
cv.rectangle(src, { pt1 = { x = rect.x, y = rect.y }, pt2 = { x = rect.x + rect.width, y = rect.y + rect.height }, color = { 0, 255, 0 }, thickness = 1 })
|
|
656
|
+
end
|
|
656
657
|
end
|
|
657
658
|
```
|
|
658
659
|
|
package/docs/apilua/system.md
CHANGED
|
@@ -524,7 +524,7 @@ print("系统总内存: " .. tostring(totalMemory) .. "MB")
|
|
|
524
524
|
-- 计算内存使用率
|
|
525
525
|
local usedMemory = system.getUsedMemory()
|
|
526
526
|
local usagePercentage = (usedMemory / totalMemory) * 100
|
|
527
|
-
print("内存使用率: "
|
|
527
|
+
print(string.format("内存使用率: %.1f%%", usagePercentage))
|
|
528
528
|
-- 获取完整的内存信息
|
|
529
529
|
local memoryInfo = system.getMemoryInfo()
|
|
530
530
|
print("内存信息: 已使用 " .. tostring(memoryInfo.used) .. "MB / 总计 " .. tostring(memoryInfo.total) .. "MB")
|
package/docs/apilua/ui.md
CHANGED
|
@@ -86,6 +86,18 @@ function show() end
|
|
|
86
86
|
ui.show()
|
|
87
87
|
```
|
|
88
88
|
|
|
89
|
+
### hide - 隐藏 WebView。
|
|
90
|
+
|
|
91
|
+
```lua
|
|
92
|
+
function hide() end
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
**示例:**
|
|
96
|
+
|
|
97
|
+
```lua
|
|
98
|
+
ui.hide()
|
|
99
|
+
```
|
|
100
|
+
|
|
89
101
|
### eval - 在 WebView 中执行 JavaScript 代码。
|
|
90
102
|
|
|
91
103
|
```lua
|
|
@@ -113,7 +125,7 @@ ui.eval("document.title = 'KuaiJS'")
|
|
|
113
125
|
function onEvent(onEvent) end
|
|
114
126
|
```
|
|
115
127
|
|
|
116
|
-
|
|
128
|
+
传入 `nil` 取消监听。回调在 `Sleep` 时执行。
|
|
117
129
|
|
|
118
130
|
**参数:**
|
|
119
131
|
|
package/docs/apilua/yolocls.md
CHANGED
|
@@ -26,7 +26,7 @@ YOLO 分类概率结果,字段命名与 Ultralytics `Probs` 保持一致。
|
|
|
26
26
|
|
|
27
27
|
```lua
|
|
28
28
|
---@class YoloClsProbs
|
|
29
|
-
---@field data number[]
|
|
29
|
+
---@field data number[] -- Lua 下标从 1 起,类别 0 对应 data[1]
|
|
30
30
|
---@field top1 number | nil
|
|
31
31
|
---@field top5 number[]
|
|
32
32
|
---@field top1conf number | nil
|
|
@@ -37,7 +37,7 @@ YOLO 分类概率结果,字段命名与 Ultralytics `Probs` 保持一致。
|
|
|
37
37
|
|
|
38
38
|
| 字段名 | 类型 | 描述 |
|
|
39
39
|
| ---------- | ---------------- | ---------------------------------------------------------- |
|
|
40
|
-
| `data` | `number[]` |
|
|
40
|
+
| `data` | `number[]` | 所有类别概率;Lua 下标从 1 起,类别 0 对应 `data[1]` |
|
|
41
41
|
| `top1` | `number \| nil` | 概率最高的类别 ID;分类失败时为 `nil` |
|
|
42
42
|
| `top5` | `number[]` | 概率最高的 5 个类别 ID,按概率从高到低排序 |
|
|
43
43
|
| `top1conf` | `number \| nil` | `top1` 对应的概率;分类失败时为 `nil` |
|
|
@@ -45,7 +45,7 @@ YOLO 分类概率结果,字段命名与 Ultralytics `Probs` 保持一致。
|
|
|
45
45
|
|
|
46
46
|
**结果说明:**
|
|
47
47
|
|
|
48
|
-
- `top1` 等于 `top5[
|
|
48
|
+
- `top1` 等于 `top5[1]`,`top1conf` 等于 `data[top1 + 1]`。
|
|
49
49
|
- 当模型类别数少于 5 时,`top5` 和 `top5conf` 的长度会小于 5。
|
|
50
50
|
- 分类失败时返回空结果:`data`、`top5`、`top5conf` 为空数组,`top1` 和 `top1conf` 为 `nil`。
|
|
51
51
|
|
|
@@ -150,20 +150,23 @@ local probs = yolocls.classify(
|
|
|
150
150
|
|
|
151
151
|
if probs.top1 ~= nil then
|
|
152
152
|
print("top1 类别ID = " .. tostring(probs.top1))
|
|
153
|
-
print("top1 置信度: "
|
|
153
|
+
print(string.format("top1 置信度: %.2f%%", probs.top1conf * 100))
|
|
154
154
|
else
|
|
155
155
|
print("分类失败或无有效结果")
|
|
156
156
|
end
|
|
157
157
|
|
|
158
158
|
for i = 1, #probs.top5 do
|
|
159
|
-
print(
|
|
160
|
-
"top[
|
|
161
|
-
|
|
159
|
+
print(string.format(
|
|
160
|
+
"top[%d] = 类别ID=%s, 置信度=%.4f",
|
|
161
|
+
i,
|
|
162
|
+
tostring(probs.top5[i]),
|
|
163
|
+
probs.top5conf[i]
|
|
164
|
+
))
|
|
162
165
|
end
|
|
163
|
-
--
|
|
166
|
+
-- Lua 数组从 1 起,类别 ID 0 对应 data[1]
|
|
164
167
|
local classId = 0
|
|
165
168
|
if #probs.data > classId then
|
|
166
|
-
print("类别
|
|
169
|
+
print(string.format("类别 %d 概率: %.4f", classId, probs.data[classId + 1]))
|
|
167
170
|
end
|
|
168
171
|
|
|
169
172
|
yolocls.free(modelId)
|
|
@@ -217,9 +220,11 @@ local regionProbs = yolocls.classifyRegion(
|
|
|
217
220
|
)
|
|
218
221
|
|
|
219
222
|
if regionProbs.top1 ~= nil then
|
|
220
|
-
print(
|
|
221
|
-
"区域分类 top1
|
|
222
|
-
|
|
223
|
+
print(string.format(
|
|
224
|
+
"区域分类 top1=%s, 置信度=%.4f",
|
|
225
|
+
tostring(regionProbs.top1),
|
|
226
|
+
regionProbs.top1conf
|
|
227
|
+
))
|
|
223
228
|
end
|
|
224
229
|
```
|
|
225
230
|
|