/* * Moonshine - a Lua virtual machine. * * Email: moonshine@gamesys.co.uk * http://moonshinejs.org * * Copyright (c) 2013-2015 Gamesys Limited. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ define(function(require,exports,module){ (function(){if(typeof window!="undefined"){var a=window.shine;window.shine={noConflict:function(){window.shine=a;return this}}}})();"use strict";var shine=shine||{};(function(a){a.EMPTY_OBJ={};a.EMPTY_ARR=[];a.gc={objects:[],arrays:[],collected:0,reused:0,cacheArray:function(b){b.length=0;this.arrays.push(b)},cacheObject:function(c){for(var b in c){if(c.hasOwnProperty(b)){delete c[b]}}this.objects.push(c)},createArray:function(){if(this.arrays.length){this.reused++}return this.arrays.pop()||[]},createObject:function(){if(this.objects.length){this.reused++}return this.objects.pop()||{}},decrRef:function(b){if(!b||!(b instanceof a.Table)||b.__shine.refCount===undefined){return}if(--b.__shine.refCount==0){this.collect(b)}},incrRef:function(b){if(!b||!(b instanceof a.Table)||b.__shine.refCount===undefined){return}b.__shine.refCount++},collect:function(e){if(e===undefined||e===null){return}if(e instanceof Array){return this.cacheArray(e)}if(typeof e=="object"&&e.constructor==Object){return this.cacheObject(e)}if(!(e instanceof a.Table)||e.__shine.refCount===undefined){return}var c,b,d=e.__shine;for(c=0,b=d.keys.length;c0&&d==d>>0){f=this.__shine.numValues[d];if(f!==undefined){return f}break}default:c=this.__shine.keys.indexOf(d);if(c>=0){return this.__shine.values[c]}}if((b=this.__shine.metatable)&&(g=b.__index)){switch(g.constructor){case a.Table:return g.getMember(d);case Function:case a.Function:f=g.apply(this,[this,d]);return(f instanceof Array)?f[0]:f}}};a.Table.prototype.setMember=function(f,i){var c=this.__shine.metatable,h=typeof f,b=f>0&&f==f>>0,e,g,d;if(h=="string"&&(f=="getMember"||f=="setMember")){h="object"}switch(h){case"string":e=this[f];break;case"number":if(b){e=this.__shine.numValues[f];break}default:g=this.__shine.keys;d=g.indexOf(f);e=d==-1?undefined:this.__shine.values[d];if(e===undefined){a.gc.incrRef(f)}}if(e===undefined&&c&&c.__newindex){switch(c.__newindex.constructor){case a.Table:return c.__newindex.setMember(f,i);case Function:return c.__newindex(this,f,i);case a.Function:return c.__newindex.apply(this,[this,f,i])[0]}}switch(h){case"string":this[f]=i;break;case"number":if(b){this.__shine.numValues[f]=i;break}default:if(d<0){d=g.length;g[d]=f}this.__shine.values[d]=i}a.gc.incrRef(i);a.gc.decrRef(e)};a.Table.prototype.toString=function(){var b;if(this.constructor!=a.Table){return"userdata"}if(this.__shine&&(b=this.__shine.metatable)&&b.__tostring){return b.__tostring.call(undefined,this)[0]}return"table: 0x"+this.__shine.index.toString(16)}})(shine||{});"use strict";var shine=shine||{};shine.Error=function(a){this.message=a};shine.Error.prototype=Object.create?Object.create(Error.prototype):new Error();shine.Error.prototype.constructor=shine.Error;shine.Error.catchExecutionError=function(a){if(!a){return}if((a||shine.EMPTY_OBJ) instanceof shine.Error){if(!a.luaMessage){a.luaMessage=a.message}a.message=a.luaMessage+"\n "+a._stackToString()}throw a};shine.Error.prototype._stackToString=function(){var n=[],f,h,g,k,e,a,m,d,c,b;this.luaStack=this.luaStack||[];for(d=0,b=this.luaStack.length;d=0;i--){local=this._data.locals[i];if(local.startpc==this._pc-1){this._localFunctions[local.varname]=val}}}}function loadk(a,bx){this._register.setItem(a,this.getConstant(bx))}function loadbool(a,b,c){this._register.setItem(a,!!b);if(c){this._pc++}}function loadnil(a,b){for(var i=a;i<=b;i++){this._register.setItem(i,undefined)}}function getupval(a,b){var value=(this._upvalues[b]===undefined)?undefined:this._upvalues[b].getValue();this._register.setItem(a,value)}function getglobal(a,b){b=this.getConstant(b);this._register.setItem(a,getglobal_internal.call(this,b))}function getglobal_internal(key){return(key=="_G")?this._globals:this._globals[key]}function gettable(a,b,c){b=this._register.getItem(b);c=(c>=256)?this.getConstant(c-256):this._register.getItem(c);this._register.setItem(a,gettable_internal.call(this,b,c))}function gettable_internal(b,c){var result,local,i;if(b===undefined){throw new shine.Error("Attempt to index a nil value ("+c+" not present in nil)")}if(b instanceof shine.Table){result=b.getMember(c)}else{if(typeof b=="string"&&shine.lib.string[c]){result=shine.lib.string[c]}else{result=b[c]}}if(this&&this._localFunctions&&result&&result instanceof shine.Function){this._localFunctions[c]=result}return result}function setglobal(a,b){var key=this.getConstant(b),value=this._register.getItem(a);setglobal_internal.call(this,key,value)}function setglobal_internal(key,value){var oldValue=this._globals[key];shine.gc.incrRef(value);shine.gc.decrRef(oldValue);this._globals[key]=value}function setupval(a,b){this._upvalues[b].setValue(this._register.getItem(a))}function settable(a,b,c){a=this._register.getItem(a);b=(b>=256)?this.getConstant(b-256):this._register.getItem(b);c=(c>=256)?this.getConstant(c-256):this._register.getItem(c);settable_internal.call(this,a,b,c)}function settable_internal(a,b,c){if(a===undefined){throw new shine.Error("Attempt to index a missing field (can't set \""+b+'" on a nil value)')}if(a instanceof shine.Table){a.setMember(b,c)}else{a[b]=c}}function newtable(a,b,c){this._register.setItem(a,newtable_internal())}function newtable_internal(){var t=new shine.Table();t.__shine.refCount=0;return t}function self(a,b,c){b=this._register.getItem(b);c=(c>=256)?this.getConstant(c-256):this._register.getItem(c);this._register.setItem(a+1,b);this._register.setItem(a,self_internal(b,c))}function self_internal(b,c){if(b===undefined){throw new shine.Error("Attempt to index a nil value ("+c+" not present in nil)")}if(b instanceof shine.Table){return b.getMember(c)}if(typeof b=="string"&&shine.lib.string[c]){return shine.lib.string[c]}return b[c]}function binary_arithmetic(a,b,c,mm,f){b=(b>=256)?this.getConstant(b-256):this._register.getItem(b);c=(c>=256)?this.getConstant(c-256):this._register.getItem(c);var result=binary_arithmetic_internal.call(this,b,c,mm,f);this._register.setItem(a,result)}function binary_arithmetic_internal(b,c,mm,f){var coerceToNumber=shine.utils.coerceToNumber,mt,f;if((b&&b instanceof shine.Table&&(mt=b.__shine.metatable)&&(f=mt.getMember(mm)))||(c&&c instanceof shine.Table&&(mt=c.__shine.metatable)&&(f=mt.getMember(mm)))){return f.apply(null,[b,c],true)[0]}if(typeof b!="number"){b=coerceToNumber(b,"attempt to perform arithmetic on a %type value")}if(typeof c!="number"){c=coerceToNumber(c,"attempt to perform arithmetic on a %type value")}return f(b,c)}function add(a,b,c){binary_arithmetic.call(this,a,b,c,"__add",add_internal)}function add_internal(x,y){return x+y}function sub(a,b,c){binary_arithmetic.call(this,a,b,c,"__sub",sub_internal)}function sub_internal(x,y){return x-y}function mul(a,b,c){binary_arithmetic.call(this,a,b,c,"__mul",mul_internal)}function mul_internal(x,y){return x*y}function div(a,b,c){binary_arithmetic.call(this,a,b,c,"__div",div_internal)}function div_internal(x,y){if(y===undefined){throw new shine.Error("attempt to perform arithmetic on a nil value")}return x/y}function mod(a,b,c){binary_arithmetic.call(this,a,b,c,"__mod",mod_internal)}function mod_internal(b,c){var result,absC;if(c===0||c===-Infinity||c===Infinity||window.isNaN(b)||window.isNaN(c)){return NaN}result=Math.abs(b)%(absC=Math.abs(c));if(b*c<0){result=absC-result}if(c<0){result*=-1}return result}function pow(a,b,c){binary_arithmetic.call(this,a,b,c,"__pow",Math.pow)}function unm(a,b){b=this._register.getItem(b);this._register.setItem(a,unm_internal(b))}function unm_internal(b){var mt,f,result;if(b&&b instanceof shine.Table&&(mt=b.__shine.metatable)&&(f=mt.getMember("__unm"))){result=shine.gc.createArray();result.push(b);return f.apply(null,result,true)[0]}if(typeof b!="number"){b=shine.utils.coerceToNumber(b,"attempt to perform arithmetic on a %type value")}return -b}function not(a,b){this._register.setItem(a,!this._register.getItem(b))}function len(a,b){b=this._register.getItem(b);this._register.setItem(a,len_internal(b))}function len_internal(b){var length,i;if(b==undefined){throw new shine.Error("attempt to get length of a nil value")}if(b instanceof shine.Table){return shine.lib.table.getn(b)}if(typeof b=="object"){length=0;for(i in b){if(b.hasOwnProperty(i)){length++}}return length}return b.length}function concat(a,b,c){var text=this._register.getItem(c),items=[],i;for(i=c-1;i>=b;i--){items.push(this._register.getItem(i))}this._register.setItem(a,concat_internal(text,items))}function concat_internal(text,additions){var textMetaTable=text&&text instanceof shine.Table&&(mt=text.__shine.metatable)&&(f=mt.getMember("__concat")),coerceToString=shine.utils.coerceToString,item,i,l,mt,f,args;for(i=0,l=additions.length;i=256)?this.getConstant(b-256):this._register.getItem(b);c=(c>=256)?this.getConstant(c-256):this._register.getItem(c);if(eq_internal(b,c)!=a){this._pc++}}function eq_internal(b,c){var mtb,mtc,f,result;if(b!==c&&b&&b instanceof shine.Table&&(c||shine.EMPTY_OBJ) instanceof shine.Table&&(mtb=b.__shine.metatable)&&(mtc=c.__shine.metatable)&&mtb===mtc&&(f=mtb.getMember("__eq"))){result=shine.gc.createArray();result.push(b,c);return !!f.apply(null,result,true)[0]}return(b===c)}function compare(a,b,c,mm,f){b=(b>=256)?this.getConstant(b-256):this._register.getItem(b);c=(c>=256)?this.getConstant(c-256):this._register.getItem(c);if(compare_internal(b,c,mm,f)!=a){this._pc++}}function compare_internal(b,c,mm,compare){var typeB=(typeof b!="object"&&typeof b)||(b instanceof shine.Table&&"table")||"userdata",typeC=(typeof c!="object"&&typeof c)||(c instanceof shine.Table&&"table")||"userdata",f,result,mtb,mtc;if(typeB!==typeC){throw new shine.Error("attempt to compare "+typeB+" with "+typeC)}else{if(typeB=="table"){if((mtb=b.__shine.metatable)&&(mtc=c.__shine.metatable)&&mtb===mtc&&(f=mtb.getMember(mm))){result=shine.gc.createArray();result.push(b,c);return f.apply(null,result,true)[0]}else{throw new shine.Error("attempt to compare two table values")}}else{return compare(b,c)}}}function lt(a,b,c){compare.call(this,a,b,c,"__lt",lt_func)}function lt_func(b,c){return b=limit)){this._register.setItem(a+3,index);this._pc+=sbx}}function forprep(a,sbx){this._register.setItem(a,this._register.getItem(a)-this._register.getItem(a+2));this._pc+=sbx}function tforloop(a,b,c){var args=shine.gc.createArray(),retvals,val,i;args.push(this._register.getItem(a+1),this._register.getItem(a+2));retvals=tforloop_internal(this._register.getItem(a),args);for(i=0;i=a){local.upvalue.value=getValue.call(this,local.registerIndex);local.upvalue.open=false;this._localsUsedAsUpvalues.splice(i--,1);l--;if(clearItem){clearItem.call(this,local.registerIndex)}}}}function closure(a,bx){var upvalueData=shine.gc.createArray(),instructions=this._instructions,slice=instructions.slice||instructions.subarray,opcode,f;while((opcode=instructions[this._pc*4])!==undefined&&(opcode===0||opcode===4)&&this._instructions[this._pc*4+1]===0){upvalueData.push.apply(upvalueData,slice.call(instructions,this._pc*4,this._pc*4+4));this._pc++}f=new shine.Function(this._vm,this._file,this._functions[bx],this._globals,closure_upvalues.call(this,bx,upvalueData,closure_getUpval,closure_setUpval));this._register.setItem(a,f)}function closure_upvalues(bx,upvalueData,getUpval,setUpval){var upvalues=shine.gc.createArray(),opcode,A,B,C,i,l;for(i=0,l=upvalueData.length;i=d.jit.MIN_FPS_TO_COMPILE){Y()}else{m=0;e=ah;window.setTimeout(y,d.jit.COMPILE_INTERVAL)}}function Y(){f=false;d.jit.onCompile();while(Q.length){var ah=Q.shift();i(ah[0],ah[1]);v.collect(ah)}}function i(ah,aj){var ai=d.jit.toJS(ah);aj(d.operations.evaluateInScope(ai,ah._vm))}var D=/\n/g,Z=/'/g;function u(ah){if(typeof ah=="string"){ah=ah.replace(D,"\\n");ah=ah.replace(Z,"\\'");return"'"+ah+"'"}return ah}function s(ai){var ah=ai+this.pc;this.vars.push(ah);return ah}function b(ai,ah){return"setR(R,"+ai+",R["+ah+"]);"}function R(ah,ai){return"setR(R,"+ah+","+u(this.getConstant(ai))+");"}function E(aj,ai,al){var ah="setR(R,"+aj+","+!!ai+");",ak;if(al){this.jumpDestinations[ak=this.pc+2]=1;ah+="pc="+ak+";break;"}return ah}function h(aj,ai){var al=v.createArray(),ah;for(var ak=aj;ak<=ai;ak++){al.push("setR(R,"+ak+");")}ah=al.join("");v.collect(al);return ah}function W(ai,ah){return"setR(R,"+ai+",cl._upvalues["+ah+"]===void 0?void 0:cl._upvalues["+ah+"].getValue());"}function G(ai,ah){var aj=this.getConstant(ah);return"setR(R,"+ai+",shine_g"+((aj=="_G")?"":"["+u(aj)+"]")+");"}function P(ai,ah,aj){aj=(aj>=256)?u(this.getConstant(aj-256)):"R["+aj+"]";return"setR(R,"+ai+",gettable_internal(R["+ah+"],"+aj+"));"}function O(ai,ah){var aj=u(this.getConstant(ah));return"setglobal_internal.call(cl,"+aj+",R["+ai+"]);"}function S(ai,ah){return"cl._upvalues["+ah+"].setValue(R["+ai+"]);"}function K(ai,ah,aj){ah=(ah>=256)?u(this.getConstant(ah-256)):"R["+ah+"]";aj=(aj>=256)?u(this.getConstant(aj-256)):"R["+aj+"]";return"settable_internal(R["+ai+"],"+ah+","+aj+");"}function X(ai,ah,aj){return"setR(R,"+ai+",newtable_internal());"}function ad(ai,ah,aj){aj=(aj>=256)?u(this.getConstant(aj-256)):"R["+aj+"]";return"setR(R,"+(ai+1)+",R["+ah+"]);setR(R,"+ai+",self_internal(R["+ah+"],"+aj+"));"}function N(ai,ah,ak,aj){ah=(ah>=256)?u(this.getConstant(ah-256)):"R["+ah+"]";ak=(ak>=256)?u(this.getConstant(ak-256)):"R["+ak+"]";return"setR(R,"+ai+",binary_arithmetic_internal("+ah+","+ak+",'__"+aj+"',"+aj+"_internal));"}function af(ai,ah,aj){return N.call(this,ai,ah,aj,"add")}function r(ai,ah,aj){return N.call(this,ai,ah,aj,"sub")}function ae(ai,ah,aj){return N.call(this,ai,ah,aj,"mul")}function U(ai,ah,aj){return N.call(this,ai,ah,aj,"div")}function ag(ai,ah,aj){return N.call(this,ai,ah,aj,"mod")}function x(ai,ah,aj){ah=(ah>=256)?u(this.getConstant(ah-256)):"R["+ah+"]";aj=(aj>=256)?u(this.getConstant(aj-256)):"R["+aj+"]";return"setR(R,"+ai+",binary_arithmetic_internal("+ah+","+aj+",'__pow',Math.pow));"}function o(ai,ah){return"setR(R,"+ai+",unm_internal(R["+ah+"]));"}function M(ai,ah){return"setR(R,"+ai+",!R["+ah+"]);"}function k(ai,ah){return"setR(R,"+ai+",len_internal(R["+ah+"]));"}function z(ai,ah,aj){return"setR(R,"+ai+",concat_internal(R["+aj+"],R.slice("+ah+","+aj+").reverse()));"}function aa(ai,ah){var aj=this.pc+ah+1;this.jumpDestinations[aj]=1;return"pc="+aj+";break;"}function g(ai,ah,ak){var aj=this.pc+2;this.jumpDestinations[aj]=1;ai=ai?"!":"";ah=(ah>=256)?u(this.getConstant(ah-256)):"R["+ah+"]";ak=(ak>=256)?u(this.getConstant(ak-256)):"R["+ak+"]";return"if("+ai+"eq_internal("+ah+","+ak+")){pc="+aj+";break}"}function A(ai,ah,am,al,ak){var aj=this.pc+2;this.jumpDestinations[aj]=1;ah=(ah>=256)?u(this.getConstant(ah-256)):"R["+ah+"]";am=(am>=256)?u(this.getConstant(am-256)):"R["+am+"]";return"if(compare_internal("+ah+","+am+",'"+al+"',"+ak+")!="+ai+"){pc="+aj+";break;}"}function ab(ai,ah,aj){return A.call(this,ai,ah,aj,"__lt","lt_func")}function a(ai,ah,aj){return A.call(this,ai,ah,aj,"__le","le_func")}function ac(ai,ah,ak){var aj=this.pc+2;this.jumpDestinations[aj]=1;return"if(shine.utils.coerceToBoolean(R["+ai+"])!="+ak+"){pc="+aj+";break}"}function q(ai,ah,ak){var aj=this.pc+2;this.jumpDestinations[aj]=1;return"if(shine.utils.coerceToBoolean(R["+ah+"])=="+ak+"){R["+ai+"]=R["+ah+"]}else{pc="+aj+";break}"}function T(ap,ao,an){var am,ar;if(ao===0){am=(ap+1)+",void 0"}else{if(ao===1){am="void 0,void 0"}else{am=(ap+1)+","+(ap+ao);var aq=true,ak,ai,aj=v.createArray(),al,ah;for(ak=1;ak0",am=s.call(this,"limit"),ao=this.pc+an+1;var ap=true,ar,aj;for(aj=ao;aj=0)){ap=false;break}}if(ap){ar="R["+(aq+3)+"]";this.code[ao-1]="for("+ar+"=R["+aq+"],"+am+"="+ai+";"+ak+"?"+ar+"<="+am+":"+ar+">="+am+";"+ar+"+="+ah+"){";delete this.jumpDestinations[this.pc];return"}"}this.jumpDestinations[ao]=1;return"setR(R,"+aq+","+al+");_="+ak+";if((_&&R["+aq+"]<="+ai+")||(!_&&R["+aq+"]>="+ai+")){setR(R,"+(aq+3)+",R["+aq+"]);pc="+ao+";break}"}function j(ai,ah){var aj=this.pc+ah+1;this.jumpDestinations[aj]=1;return"setR(R,"+ai+",R["+ai+"]-R["+(ai+2)+"]);pc="+aj+";break;"}function H(an,al,aj){var ah=s.call(this,"tfor"),ak=this.pc+2,aq,ai;var ap=this.pc+this._instructions[this.pc*4+6]+1,am=true,ao,ai;for(ai=ap+1;ai=0)){am=false;break}}if(am){delete this.jumpDestinations[this.pc];this.code[this.pc+1]="/* noop */";aq="while(1){";aq+=ah+"=tforloop_internal(R["+an+"],R.slice("+(an+1)+","+(an+3)+"));";for(ai=0;ai0,aj=v.createArray(),ah=0,an,aw,aA,az,ay,ap,ai,ar="",aq=v.createArray(),ao,at,ax,av,au;an={paramCount:ak,isVararg:am,stackSize:ao._data.maxStackSize,pc:ah,code:v.createArray(),vars:v.createArray(),jumpDestinations:v.createArray(),_constants:ao._data.constants,_instructions:ao._data.instructions,getConstant:function(aB){var aC=this._constants[aB];return this._constants[aB]===null?void 0:aC}};an.jumpDestinations.push(1);av=al.length/4;while(ah=0){ar+="getupval=get_upv.bind(R);"}if(an.vars.indexOf("setupval")>=0){ar+="setupval=set_upv.bind(R);"}aj=["/* "+(ao._file&&ao._file.url)+":"+ao._data.lineDefined+" */","var cl=this,R=createArray(),pc=0,_"+(an.vars.length?","+an.vars.join(","):"")+";"];for(ax=0;ax=@[]\\^_{}|~]","%P":"[^.,\"'?!;:#$%&()*+-/<>=@[]\\^_{}|~]","%s":"[ \\t\\n\\f\\v\\r]","%S":"[^ \t\n\f\v\r]","%u":"[A-Z]","%U":"[^A-Z]","%w":"[a-zA-Z0-9]","%W":"[^a-zA-Z0-9]","%x":"[a-fA-F0-9]","%X":"[^a-fA-F0-9]","%([^a-zA-Z])":"\\$1"},n=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],c=["January","February","March","April","May","June","July","August","September","October","November","December"],e=[31,28,31,30,31,30,31,31,30,31,30,31],h={"%a":function(r,q){return n[r["get"+(q?"UTC":"")+"Day"]()].substr(0,3)},"%A":function(r,q){return n[r["get"+(q?"UTC":"")+"Day"]()]},"%b":function(r,q){return c[r["get"+(q?"UTC":"")+"Month"]()].substr(0,3)},"%B":function(r,q){return c[r["get"+(q?"UTC":"")+"Month"]()]},"%c":function(r,q){return r["to"+(q?"UTC":"")+"LocaleString"]()},"%d":function(r,q){return("0"+r["get"+(q?"UTC":"")+"Date"]()).substr(-2)},"%H":function(r,q){return("0"+r["get"+(q?"UTC":"")+"Hours"]()).substr(-2)},"%I":function(r,q){return("0"+((r["get"+(q?"UTC":"")+"Hours"]()+11)%12+1)).substr(-2)},"%j":function(u,t){var r=u["get"+(t?"UTC":"")+"Date"](),q=u["get"+(t?"UTC":"")+"Month"]();for(var s=0;s1&&u["get"+(t?"UTC":"")+"FullYear"]()%4===0){r+=1}return("00"+r).substr(-3)},"%m":function(r,q){return("0"+(r["get"+(q?"UTC":"")+"Month"]()+1)).substr(-2)},"%M":function(r,q){return("0"+r["get"+(q?"UTC":"")+"Minutes"]()).substr(-2)},"%p":function(r,q){return(r["get"+(q?"UTC":"")+"Hours"]()<12)?"AM":"PM"},"%S":function(r,q){return("0"+r["get"+(q?"UTC":"")+"Seconds"]()).substr(-2)},"%U":function(r,q){return f(r,0,q)},"%w":function(r,q){return""+(r["get"+(q?"UTC":"")+"Day"]())},"%W":function(r,q){return f(r,1,q)},"%x":function(r,q){return h["%m"](r,q)+"/"+h["%d"](r,q)+"/"+h["%y"](r,q)},"%X":function(r,q){return h["%H"](r,q)+":"+h["%M"](r,q)+":"+h["%S"](r,q)},"%y":function(r,q){return h["%Y"](r,q).substr(-2)},"%Y":function(r,q){return""+r["get"+(q?"UTC":"")+"FullYear"]()},"%Z":function(s,r){var q;return(r&&"UTC")||((q=s.toString().match(/[A-Z][A-Z][A-Z]/))&&q[0])},"%%":function(){return"%"}},m=1,j;function l(){m=(o*m)%d;return m/d}function k(q){if(q&&q instanceof b.VM){return q}var r=b.getCurrentVM();if(!r){throw new b.Error("Can't call library function without passing a VM object as the context")}return r}function i(t,s){if(s===undefined){throw new b.Error("Bad argument #2 to ipairs() iterator")}var q=s+1,r=t.__shine.numValues;if(!r.hasOwnProperty(q)||r[q]===void 0){return void 0}return[q,r[q]]}function f(v,q,t){var s=parseInt(h["%j"](v),10),r=new Date(v.getFullYear(),0,1,12),u=(8-r["get"+(t?"UTC":"")+"Day"]()+q)%7;return("0"+(Math.floor((s-u)/7)+1)).substr(-2)}function p(u){u=""+u;var v=0,s,q,t,r;for(s in g){if(g.hasOwnProperty(s)){u=u.replace(new RegExp(s,"g"),g[s])}}q=u.length;for(s=0;s0&&s==s>>0)){if("keys" in Object){x=Object.keys(t);if(y){r=1}else{if(r=x.indexOf(""+s)+1){y=true}}if(y){while((v=x[r])!==void 0&&(u=t[v])===void 0){r++}if(u!==void 0){return[v>>=0,u]}}}else{for(q in t){r=q>>0;if(!y){if(r===s){y=true}}else{if(t[r]!==undefined){return[r,t[r]]}}}}}for(r in w){if(w.hasOwnProperty(r)&&!(r in b.Table.prototype)&&r!=="__shine"){if(!y){if(r==s){y=true}}else{if(w.hasOwnProperty(r)&&w[r]!==undefined&&(""+r).substr(0,2)!="__"){return[r,w[r]]}}}}for(r in w.__shine.keys){if(w.__shine.keys.hasOwnProperty(r)){var v=w.__shine.keys[r];if(!y){if(v===s){y=true}}else{if(w.__shine.values[r]!==undefined){return[v,w.__shine.values[r]]}}}}return b.gc.createArray()},pairs:function(q){if(!((q||b.EMPTY_OBJ) instanceof b.Table)){throw new b.Error("Bad argument #1 in pairs(). Table expected")}return[b.lib.next,q]},pcall:function(u){var s=b.gc.createArray(),q;for(var t=1,r=arguments.length;t36){throw new b.Error("bad argument #2 to tonumber() (base out of range)")}if(t==10&&(u===Infinity||u===-Infinity||(typeof u=="number"&&window.isNaN(u)))){return u}if(t!=10&&u==undefined){throw new b.Error("bad argument #1 to 'tonumber' (string expected, got nil)")}u=(""+u).replace(/^\s+|\s+$/g,"");if(t==10){return b.utils.coerceToNumber(u)}u=b.utils.coerceToString(u);if(t==16&&(q=u.match(/^(\-)?0[xX](.+)$/))){u=(q[1]||"")+q[2]}r="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";s=new RegExp("^["+r.substr(0,t)+"]*$","gi");if(!s.test(u)){return}return parseInt(u,t)},tostring:function(r){var q,s;if(r!==undefined&&r instanceof b.Table&&(q=r.__shine.metatable)&&(s=q.getMember("__tostring"))){return s.call(s,r)}if(r&&(r instanceof b.Table||r instanceof b.Function)){return r.toString()}if(typeof r=="function"){return"function: [host code]"}return b.utils.coerceToString(r)||"userdata"},type:function(q){var r=typeof q;switch(r){case"undefined":return"nil";case"number":case"string":case"boolean":case"function":return r;case"object":if(q.constructor===b.Table){return"table"}if((q||b.EMPTY_OBJ) instanceof b.Function){return"function"}return"userdata"}},unpack:function(s,r,q){return b.lib.table.unpack(s,r,q)},_VERSION:"Lua 5.1",xpcall:function(s,r){var q,v,t;try{if(typeof s=="function"){q=s.apply()}else{if((s||b.EMPTY_OBJ) instanceof b.Function){q=s.apply(null,undefined,true)}else{t=true}}v=true}catch(u){q=r.apply(null,undefined,true);if(((q||b.EMPTY_OBJ) instanceof Array)){q=q[0]}v=false}if(t){throw new b.Error("Attempt to call non-function")}if(!((q||b.EMPTY_OBJ) instanceof Array)){q=[q]}q.unshift(v);return q}};b.lib.coroutine=new b.Table({create:function(q){return b.Coroutine.create(q)},resume:function(q){if(arguments.length<2){return q.resume.call(q)}var s=b.gc.createArray();for(var t=1,r=arguments.length;t0?1:-1;q=q*t;s=Math.floor(Math.log(q)/Math.log(2))+1;r=q/Math.pow(2,s);return[r*t,s]},huge:Infinity,ldexp:function(q,r){return q*Math.pow(2,r)},log:function(r,s){var q=Math.log(r);if(s!==undefined){return q/Math.log(s)}return q},log10:function(q){return Math.log(q)/Math.log(10)},max:function(){return Math.max.apply(Math,arguments)},min:function(){return Math.min.apply(Math,arguments)},modf:function(q){var s=Math.floor(q),r=q-s;return[s,r]},pi:Math.PI,pow:function(q,s){var r=b.utils.coerceToNumber;q=r(q,"bad argument #1 to 'pow' (number expected)");s=r(s,"bad argument #2 to 'pow' (number expected)");return Math.pow(q,s)},rad:function(q){q=b.utils.coerceToNumber(q,"bad argument #1 to 'rad' (number expected)");return(Math.PI/180)*q},random:function(r,q){if(r===undefined&&q===undefined){return l()}if(typeof r!=="number"){throw new b.Error("bad argument #1 to 'random' (number expected)")}if(q===undefined){q=r;r=1}else{if(typeof q!=="number"){throw new b.Error("bad argument #2 to 'random' (number expected)")}}if(r>q){throw new b.Error("bad argument #2 to 'random' (interval is empty)")}return Math.floor(l()*(q-r+1)+r)},randomseed:function(q){if(typeof q!=="number"){throw new b.Error("bad argument #1 to 'randomseed' (number expected)")}m=q},sin:function(q){return Math.sin(q)},sinh:function(q){var r=b.lib.math.exp;return(r(q)-r(-q))/2},sqrt:function(q){return Math.sqrt(q)},tan:function(q){return Math.tan(q)},tanh:function(q){var r=b.lib.math.exp;return(r(q)-r(-q))/(r(q)+r(-q))}});b.lib.os=new b.Table({clock:function(){},date:function(v,u){if(v===undefined){v="%c"}var s,q=new Date();if(u){q.setTime(u*1000)}if(v.substr(0,1)==="!"){v=v.substr(1);s=true}if(v==="*t"){var t=function(y){var x=y.getFullYear(),w=new Date(x,0);return(y.getTimezoneOffset()!==w.getTimezoneOffset())};return new b.Table({year:parseInt(h["%Y"](q,s),10),month:parseInt(h["%m"](q,s),10),day:parseInt(h["%d"](q,s),10),hour:parseInt(h["%H"](q,s),10),min:parseInt(h["%M"](q,s),10),sec:parseInt(h["%S"](q,s),10),wday:parseInt(h["%w"](q,s),10)+1,yday:parseInt(h["%j"](q,s),10),isdst:t(q,s)})}for(var r in h){if(h.hasOwnProperty(r)&&v.indexOf(r)>=0){v=v.replace(r,h[r](q,s))}}return v},difftime:function(q,r){return q-r},execute:function(){if(arguments.length){throw new b.Error("shell is not available. You should always check first by calling os.execute with no parameters")}return 0},exit:function(q){throw new b.Error("Execution terminated ["+(q||0)+"]")},getenv:function(){},remove:function(){},rename:function(){},setlocale:function(){},time:function(v){var x;if(!v){x=Date.now?Date.now():new Date().getTime()}else{var r,w,u,q,s,t;if(!(r=v.getMember("day"))){throw new b.Error("Field 'day' missing in date table")}if(!(w=v.getMember("month"))){throw new b.Error("Field 'month' missing in date table")}if(!(u=v.getMember("year"))){throw new b.Error("Field 'year' missing in date table")}q=v.getMember("hour")||12;s=v.getMember("min")||0;t=v.getMember("sec")||0;if(v.getMember("isdst")){q--}x=new Date(u,w-1,r,q,s,t).getTime()}return Math.floor(x/1000)},tmpname:function(){}});b.lib["package"]=new b.Table({cpath:undefined,loaded:new b.Table(),loadlib:function(r,q){},path:"?.lua.json;?.json;modules/?.lua.json;modules/?.json;modules/?/?.lua.json;modules/?/index.lua.json",preload:{},seeall:function(r){var s=k(this),q=new b.Table();q.setMember("__index",s._globals);b.lib.setmetatable(r,q)}});b.lib.string=new b.Table({"byte":function(v,u,t){u=u||1;t=t||u;var q=b.gc.createArray(),w=v.length,r;for(r=u;r<=w&&r<=t;r++){q.push(v.charCodeAt(r-1)||undefined)}return q},"char":function(){var q="";for(var s=0,r=arguments.length;s5){throw new b.Error("invalid format (repeated flags)")}if(!q&&q!==0){q=Infinity}return{showSign:s.indexOf("+")>=0,prefix:s.indexOf(" ")>=0,leftAlign:s.indexOf("-")>=0,alternateForm:s.indexOf("#")>=0,zeroPad:s.indexOf("0")>=0,minWidth:parseInt(x[3])||0,hasPrecision:!!x[4],precision:q}}function I(s,q){return Array(q+1).join(s)}function K(q,M,x){var s;if(x.zeroPad&&!x.leftAlign&&(s=x.minWidth-q.length)>0){if(M||x.showSign||x.prefix){s--}q=I("0",s)+q}if(M){q="-"+q}else{if(x.showSign){q="+"+q}else{if(x.prefix){q=" "+q}}}if((s=x.minWidth-q.length)>0){if(x.leftAlign){return q+I(" ",s)}return I(" ",s)+q}return q}function L(q){q=b.utils.coerceToNumber(q,"bad argument #"+F+" to 'format' (number expected)");return String.fromCharCode(q)}function J(q){q=b.utils.coerceToNumber(q,"bad argument #"+F+" to 'format' (number expected)");var x=D(t),M=q<0,s;q=""+Math.floor(Math.abs(q));if(x.hasPrecision){if(x.precision!==Infinity&&(s=x.precision-q.length)>0){q=I("0",s)+q}x.zeroPad=false}return K(q,M,x)}function G(q){q=b.utils.coerceToNumber(q,"bad argument #"+F+" to 'format' (number expected)");var M=D(t),N=q<0,x=q-Math.floor(q),s=M.precision===Infinity?6:M.precision;q=""+Math.floor(Math.abs(q));if(s>0){x=x.toFixed(s).substr(2);s-=x.length;q+="."+x+(s?I("0",s):"")}return K(q,N,M)}function E(q,x){q=b.utils.coerceToNumber(q,"bad argument #"+F+" to 'format' (number expected)");var N=q<0,x=Math.pow(2,32),M=D(t),s;q=Math.floor(q);if(N){q=x+q}q=q.toString(16);if(M.hasPrecision&&M.precision!==Infinity&&(s=M.precision-q.length)>0){q=I("0",s)+q}if((s=M.minWidth-q.length)>0){if(M.leftAlign){return q+I(" ",s)}return I(" ",s)+q}return q}function C(q){q=b.utils.coerceToString(q);return'"'+q.replace(/([\n"])/g,"\\$1")+'"'}function A(q){var x=D(t),s;q=b.utils.coerceToString(q);q=q.substr(0,x.precision);if((s=x.minWidth-q.length)>0){if(x.leftAlign){return q+I(" ",s)}else{return I(x.zeroPad?"0":" ",s)+q}}return q}function w(q){q=b.utils.coerceToNumber(q,"bad argument #"+F+" to 'format' (number expected)");var O=q<0,M=4,x=Math.pow(2,32),N=D(t),s;q=Math.floor(q);if(O){q=x+q}q=q.toString(16);if(O&&M>2){q=I("f",(M-2)*4)+q}if(N.hasPrecision&&N.precision!==Infinity&&(s=N.precision-q.length)>0){q=I("0",s)+q}if(N.alternateForm){q="0x"+q}N.showSign=N.prefix=false;N.zeroPad=N.zeroPad&&N.hasPrecision;q=K(q,false,N);return q}while(B=(""+H).match(z)){y+=B[1];while(B[v]!="%"){v++}t=(""+B[v+1]).match(r);if(t[1]){y+="%"+t[2]+t[3]+(t[4]||"")+t[6]}else{switch(t[6]){case"c":y+=L(u.shift());break;case"d":y+=J(u.shift());break;case"f":y+=G(u.shift());break;case"q":y+=C(u.shift());break;case"o":y+=E(u.shift());break;case"s":y+=A(u.shift());break;case"x":y+=w(u.shift());break;case"X":y+=w(u.shift()).toUpperCase();break}}H=t[7];F++}return y+H},gmatch:function(r,u){u=p(u);var q=new RegExp(u,"g"),t=(""+r).match(q);return function(){var v=t.shift(),s=new RegExp(u).exec(v);if(v===undefined){return}s.shift();return s.length?s:v}},gsub:function(z,x,v,q){if(typeof z!="string"&&typeof z!="number"){throw new b.Error("bad argument #1 to 'gsub' (string expected, got "+typeof z+")")}if(typeof x!="string"&&typeof x!="number"){throw new b.Error("bad argument #2 to 'gsub' (string expected, got "+typeof x+")")}if(q!==undefined&&(q=b.utils.coerceToNumber(q))===undefined){throw new b.Error("bad argument #4 to 'gsub' (number expected, got "+typeof q+")")}z=""+z;x=p(""+x);var w=0,A="",y,u,t,r;while((q===undefined||w=0;r--){q+=t.charAt(r)}return q},sub:function(t,r,q){if(typeof t!="string"&&typeof t!="number"){throw new b.Error("Bad argument #1 to 'sub' (string expected, got "+typeof t+")")}t=""+t;r=r||1;q=q||t.length;if(r>0){r=r-1}else{if(r<0){r=t.length+r}}if(q<0){q=t.length+q+1}return t.substring(r,q)},upper:function(q){return q.toUpperCase()}});j=new b.Table({__index:b.lib.string});b.lib.table=new b.Table({concat:function(u,s,t,r){if(!((u||b.EMPTY_OBJ) instanceof b.Table)){throw new b.Error("Bad argument #1 to 'concat' (table expected)")}s=s||"";t=t||1;r=r||b.lib.table.maxn(u);var q=b.gc.createArray().concat(u.__shine.numValues).splice(t,r-t+1);return q.join(s)},getn:function(u){if(!((u||b.EMPTY_OBJ) instanceof b.Table)){throw new b.Error("Bad argument #1 in 'getn' (table expected)")}var v=u.__shine.numValues,t=b.gc.createArray(),s,r=0;for(s in v){if(v.hasOwnProperty(s)){t[s]=true}}while(t[r+1]){r++}if(r>0&&v[r]===undefined){var s=0;while(r-s>1){var q=Math.floor((s+r)/2);if(v[q]===undefined){r=q}else{s=q}}return s}return r},insert:function(r,q,s){if(!((r||b.EMPTY_OBJ) instanceof b.Table)){throw new b.Error("Bad argument #1 in table.insert(). Table expected")}if(s==undefined){s=q;q=r.__shine.numValues.length}else{q=b.utils.coerceToNumber(q,"Bad argument #2 to 'insert' (number expected)")}r.__shine.numValues.splice(q,0,undefined);r.setMember(q,s)},maxn:function(q){if(!((q||b.EMPTY_OBJ) instanceof b.Table)){throw new b.Error("Bad argument #1 to 'maxn' (table expected)")}return q.__shine.numValues.length-1},remove:function(t,s){if(!((t||b.EMPTY_OBJ) instanceof b.Table)){throw new b.Error("Bad argument #1 in table.remove(). Table expected")}var r=b.lib.table.getn(t),u=t.__shine.numValues,q;if(s>r){return}if(s==undefined){s=r}q=u.splice(s,1);while(s0,f=e.gc["create"+(k?"Array":"Object")](),h=m.__shine.numValues,j,g=h.length;for(j=1;j