-
Notifications
You must be signed in to change notification settings - Fork 2
/
moonshine.min.js
28 lines (28 loc) · 77.2 KB
/
moonshine.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/*
* Moonshine - a Lua virtual machine.
*
* Email: [email protected]
* 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.
*/
(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;c<b;c++){this.decrRef(d.keys[c])}for(c=0,b=d.values.length;c<b;c++){this.decrRef(d.values[c])}for(c=0,b=d.numValues.length;c<b;c++){this.decrRef(d.numValues[c])}this.cacheArray(d.keys);this.cacheArray(d.values);delete d.keys;delete d.values;this.cacheObject(d);delete e.__shine;for(c in e){if(e.hasOwnProperty(c)){this.decrRef(e[c])}}}}})(shine||{});"use strict";var shine=shine||{};shine.EventEmitter=function(){this._listeners={}};shine.EventEmitter.prototype._trigger=function(b,e){var d=this._listeners[b],a,c;if(!d){return}if(!((e||shine.EMPTY_OBJ) instanceof Array)){e=[e]}for(c in d){if(d.hasOwnProperty(c)){a=d[c].apply(this,e);if(a!==undefined&&!a){break}}}};shine.EventEmitter.prototype.on=function(a,b){if(!this._listeners[a]){this._listeners[a]=[]}this._listeners[a].push(b)};shine.EventEmitter.prototype.unbind=function(a,c){for(var b in this._listeners[a]){if(this._listeners[a].hasOwnProperty(b)&&this._listeners[a][b]===c){this._listeners[a].splice(b,1)}}};if(typeof module=="object"&&module.exports){module.exports.EventEmitter=shine.EventEmitter}"use strict";var shine=shine||{};shine.FileManager=function(){shine.EventEmitter.call(this);this._cache={}};shine.FileManager.prototype=new shine.EventEmitter();shine.FileManager.prototype.constructor=shine.FileManager;shine.FileManager.prototype.load=function(b,g){var c=this,d;function f(j,i){var h;if(c.constructor._isJson(j)){h=JSON.parse(j)}else{if(c.constructor._isLuac(j)){h=c.constructor._parseLuac(j)}}if(h){window.setTimeout(function(){if(i){c._cache[i]=h}c._onSuccess(i||"",h,g)},1)}return !!h}function e(h){if(!f(h,b)){throw new Error("File contains non-parsable content: "+b)}}function a(h){c._onError(h,g)}switch(typeof b){case"string":if(!f(b)){if(d=this._cache[b]){window.setTimeout(function(){c._onSuccess(b,d,g)},1)}else{shine.utils.get(b,e,a)}}break;case"object":this._onSuccess("",b,g);break;default:throw new TypeError("Can't load object of unknown type")}};shine.FileManager.prototype._onSuccess=function(a,d,e){var c,b;if(d.format=="moonshine.package"){for(b in d.files){this._cache[b]=d.files[b]}this._trigger("loaded-package",d);if(!(a=d.main)){return}if(!(d=d.files[a])){throw new ReferenceError("The package's main reference does not point to a filename within the package")}}c=new shine.File(a,d);this._onFileLoaded(c,function(){e(null,c)})};shine.FileManager.prototype._onFileLoaded=function(a,b){b()};shine.FileManager.prototype._onError=function(a,b){b(a)};shine.FileManager._isJson=function(a){return/^({.*}|\[.*\])$/.test(a)};shine.FileManager._isLuac=function(a){return a.substr(0,5)==String.fromCharCode(27,76,117,97,81)};shine.FileManager._parseLuac=function(a){if(!shine.distillery){throw new Error('Moonshine needs the distillery to parse Lua byte code. Please include "distillery.moonshine.js" in the page.')}if(!("ArrayBuffer" in window)){console.warn("Browser does not support ArrayBuffers, this could cause unexpected results when loading binary files.")}return new shine.distillery.Parser().parse(a)};shine.FileManager.prototype.dispose=function(){delete this._cache};"use strict";(function(a){a.VM=function(b){a.EventEmitter.call(this);this.fileManager=new a.FileManager();this._env=b||{};this._coroutineStack=[];this._status=a.RUNNING;this._resumeStack=[];this._callbackQueue=[];this._coroutineStack=[];this._resetGlobals()};a.VM.prototype=new a.EventEmitter();a.VM.prototype.constructor=a.VM;a.RUNNING=0;a.SUSPENDING=1;a.SUSPENDED=2;a.RESUMING=3;a.DEAD=4;a.VM.prototype._resetGlobals=function(){var b=new a.Table();b.setMember(-1,"moonshine");this._globals=this._bindLib(a.lib);this._globals.arg=b;for(var c in this._globals){if(this._globals.hasOwnProperty(c)&&this._globals[c] instanceof a.Table){this._globals["package"].loaded[c]=this._globals[c]}}this._globals["package"].loaded._G=this._globals;for(var c in this._env){if(this._env.hasOwnProperty(c)){this._globals[c]=this._env[c]}}};a.VM.prototype._bindLib=function(d){var b=a.gc.createObject();for(var c in d){if(d.hasOwnProperty(c)){b[c]=d[c]}}return new a.Table(b)};a.VM.prototype.load=function(c,e,b){var d=this;this.fileManager.load(c,function(g,f){if(g){throw new URIError("Failed to load file: "+c+" ("+g+")")}d._trigger("file-loaded",f);if(e||e===undefined){d.execute(b,f)}})};a.VM.prototype.execute=function(k,c){var i=this,b=c?[c]:this._files,f,c,h;if(!b.length){throw new Error("No files loaded.")}for(f in b){if(b.hasOwnProperty(f)){c=b[f];if(!c.data){throw new Error("Tried to execute file before data loaded.")}h=this._thread=new a.Function(this,c,c.data,this._globals);this._trigger("executing",[h,k]);try{if(!k){h.call()}else{var j=a.lib.coroutine.wrap.call(this,h),d=function(){j();if(k.uiOnly&&j._coroutine.status!=a.DEAD){window.setTimeout(d,1)}};d()}}catch(g){a.Error.catchExecutionError(g)}}}};a.VM.prototype.setGlobal=function(b,c){this._globals[b]=c};a.VM.prototype.getGlobal=function(b){return this._globals[b]};a.VM.prototype.suspend=function(){if(this._status!==a.RUNNING){throw new Error("attempt to suspend a non-running VM")}var b=this;this._status=a.SUSPENDING;this._resumeVars=undefined;window.setTimeout(function(){if(b._status==a.SUSPENDING){b._status=a.SUSPENDED}},1)};a.VM.prototype.resume=function(d){if(this._status!==a.SUSPENDED&&this._status!==a.SUSPENDING){throw new Error("attempt to resume a non-suspended VM")}if(!arguments.length||d!==undefined){d=d||this._resumeVars}if(d&&!(d instanceof Array)){var c=a.gc.createArray();c.push(d);d=c}this._status=a.RESUMING;this._resumeVars=d;var g=this._resumeStack.pop();if(g){try{if(g instanceof a.Coroutine){g.resume()}else{if(g instanceof a.Closure){g._run()}else{g()}}}catch(h){if(!((h||a.EMPTY_OBJ) instanceof a.Error)){var b=(h.stack||"");h=new a.Error("Error in host call: "+h.message);h.stack=b;h.luaStack=b.split("\n")}if(!h.luaStack){h.luaStack=a.gc.createArray()}h.luaStack.push([g,g._pc-1]);a.Error.catchExecutionError(h)}}if(this._status==a.RUNNING){while(this._callbackQueue[0]){this._callbackQueue.shift()()}}};a.VM.prototype.dispose=function(){var b;for(var c in this._files){if(this._files.hasOwnProperty(c)){this._files[c].dispose()}}if(b=this._thread){b.dispose()}delete this._files;delete this._thread;delete this._globals;delete this._env;delete this._coroutineStack;this.fileManager.dispose();delete this.fileManager;a.Closure._graveyard.length=0;a.Closure._current=undefined;a.Coroutine._graveyard.length=0};a.getCurrentVM=function(){var b;return(b=this.Closure._current)&&b._vm}})(shine||{});"use strict";(function(a){a.Register=function(){this._items=a.gc.createArray()};a.Register._graveyard=[];a.Register.create=function(){var b=a.Register._graveyard.pop();return b||new a.Register(arguments)};a.Register.prototype.getLength=function(){return this._items.length};a.Register.prototype.getItem=function(b){return this._items[b]};a.Register.prototype.setItem=function(b,d){var c=this._items[b];a.gc.incrRef(d);a.gc.decrRef(c);this._items[b]=d};a.Register.prototype.set=function(b){var d,c=Math.max(b.length,this._items.length);for(d=0;d<c;d++){this.setItem(d,b[d])}};a.Register.prototype.push=function(){this._items.push.apply(this._items,arguments)};a.Register.prototype.clearItem=function(b){delete this._items[b]};a.Register.prototype.splice=function(b,c){this._items.splice.apply(this._items,arguments)};a.Register.prototype.reset=function(){for(var c=0,b=this._items.length;c<b;c++){a.gc.decrRef(this._items[c])}this._items.length=0};a.Register.prototype.dispose=function(){this._items.reset();this.constructor._graveyard.push(this)}})(shine||{});"use strict";var shine=shine||{};shine.Closure=function(c,b,f,e,g){var d=this;this._vm=c;this._globals=e;this._file=b;this._data=f;this._upvalues=g||shine.gc.createArray();this._constants=f.constants;this._functions=f.functions;this._instructions=f.instructions;this._register=this._register||shine.Register.create();this._pc=0;this._localsUsedAsUpvalues=this._localsUsedAsUpvalues||shine.gc.createArray();this._funcInstances=this._funcInstances||shine.gc.createArray();this._localFunctions=shine.gc.createObject();var d=this,a=function(){var j=shine.gc.createArray();for(var k=0,h=arguments.length;k<h;k++){j.push(arguments[k])}return d.execute(j)};a._instance=this;a.dispose=function(){d.dispose.apply(d,arguments);delete this.dispose};return a};shine.Closure.prototype={};shine.Closure.prototype.constructor=shine.Closure;shine.Closure._graveyard=[];shine.Closure._current=undefined;shine.Closure.create=function(c,b,e,d,f){var a=shine.Closure._graveyard.pop();if(a){return shine.Closure.apply(a,arguments)}else{return new shine.Closure(c,b,e,d,f)}};shine.Closure.prototype.execute=function(c){var f=this;if(this._vm._status!=shine.RUNNING){this._vm._callbackQueue.push(function(){f.execute.call(f,c)});return}this._pc=0;this._params=shine.gc.createArray().concat(c);this._register.set(c.splice(0,this._data.paramCount));if(this._data.is_vararg==7){var b=shine.gc.createArray().concat(c),d=b.length;b=new shine.Table(b);b.setMember("n",d);this._register.push(b)}try{return this._run()}catch(g){if(!((g||shine.EMPTY_OBJ) instanceof shine.Error)){var a=(g.stack||"");g=new shine.Error("Error in host call: "+g.message);g.stack=a;g.luaStack=a.split("\n")}if(!g.luaStack){g.luaStack=shine.gc.createArray()}g.luaStack.push([this,this._pc-1]);throw g}};shine.Closure.prototype._run=function(){var d,q,e,n,k;this.terminated=false;if(this._vm._status==shine.RESUMING){if(this._vm._resumeStack.length){this._pc--}else{this._vm._status=shine.RUNNING;n=this._vm._resumeVars;delete this._vm._resumeVars}}else{if(shine.debug&&shine.debug._status==shine.RESUMING){if(shine.debug._resumeStack.length){this._pc--}else{shine.debug._setStatus(shine.RUNNING)}}else{if((k=this._vm._coroutineRunning)&&k.status==shine.RESUMING){if(k._resumeStack.length){this._pc--}else{k.status=shine.RUNNING;n=k._yieldVars}}}}if(n){var g=(this._pc-1)*4,p=this._instructions[g+1],o=this._instructions[g+2],m=this._instructions[g+3],j=shine.gc.createArray();for(var h=0,f=n.length;h<f;h++){j.push(n[h])}if(m===0){f=j.length;for(h=0;h<f;h++){this._register.setItem(p+h,j[h])}this._register.splice(p+f)}else{for(h=0;h<m-1;h++){this._register.setItem(p+h,j[h])}}shine.gc.collect(j)}while(this._instructions[this._pc*4]!==undefined){q=this._data.linePositions&&this._data.linePositions[this._pc];e=this._executeInstruction(this._pc++,q);if((k=this._vm._coroutineRunning)&&k.status==shine.SUSPENDING){k._resumeStack.push(this);if(k._func._instance==this){e=k._yieldVars;k.status=shine.SUSPENDED;shine.Coroutine._remove();return e}return}if(this._vm._status==shine.SUSPENDING&&!e){this._vm._resumeStack.push(this);return}if(shine.debug&&shine.debug._status==shine.SUSPENDING&&!e){shine.debug._resumeStack.push(this);return}if(e!==undefined){this.terminated=true;this.dispose();return e}}this.terminated=true;this.dispose()};shine.Closure.prototype._executeInstruction=function(c,b){this.constructor._current=this;var f=c*4,d=this._instructions[f],h=shine.operations.HANDLERS[d],a=this._instructions[f+1],g=this._instructions[f+2],e=this._instructions[f+3];return h.call(this,a,g,e)};shine.Closure.prototype.getConstant=function(a){if(this._constants[a]===null){return}return this._constants[a]};shine.Closure.prototype.hasRetainedScope=function(){if(this._localsUsedAsUpvalues.length){return true}if(this._upvalues.length){return true}for(var a in this._funcInstances){if(this._funcInstances.hasOwnProperty(a)&&this._funcInstances[a].isRetained()){return true}}return false};shine.Closure.prototype.dispose=function(a){if(a||!this.hasRetainedScope()){delete this._vm;delete this._globals;delete this._file;delete this._data;delete this._functions;delete this._instructions;delete this._pc;shine.gc.collect(this._params);shine.gc.collect(this._localFunctions);delete this._params;delete this._constants;delete this._upvalues;this._register.reset();this._funcInstances.length=0;this._localsUsedAsUpvalues.length=0;shine.Closure._graveyard.push(this)}};"use strict";var shine=shine||{};shine.Function=function(a,b,c,d,e){var h,g,f,i;this._vm=a;this._file=b;this._data=c||shine.gc.createObject();this._globals=d;this._upvalues=e||shine.gc.createArray();this._index=shine.Function._index++;this.instances=shine.gc.createArray();this._retainCount=0;this._convertInstructions()};shine.Function.prototype={};shine.Function.prototype.constructor=shine.Function;shine.Function._index=0;shine.Function.prototype.getInstance=function(){return shine.Closure.create(this._vm,this._file,this._data,this._globals,this._upvalues)};shine.Function.prototype._compile=function(){};shine.Function.prototype._convertInstructions=function(){var c=this._data.instructions||shine.gc.createArray(),e,b,f,d,a,g;if("ArrayBuffer" in window){if(c instanceof Int32Array){return}if(c.length==0||c[0].op===undefined){e=new ArrayBuffer(c.length*4);b=new Int32Array(e);b.set(c);this._data.instructions=b;return}e=new ArrayBuffer(c.length*4*4);b=new Int32Array(e)}else{if(c.length==0||typeof c[0]=="number"){return}b=[]}for(f=0,d=c.length;f<d;f++){a=c[f];g=f*4;b[g]=a.op;b[g+1]=a.A;b[g+2]=a.B;b[g+3]=a.C}this._data.instructions=b};shine.Function.prototype.call=function(d){var b=shine.gc.createArray(),a=arguments.length,c;for(c=1;c<a;c++){b.push(arguments[c])}return this.apply(d,b)};shine.Function.prototype.apply=function(d,b,a){if(d&&d instanceof Array&&!b){b=d;d=undefined}try{return this.getInstance().apply(d,b)}catch(c){shine.Error.catchExecutionError(c)}};shine.Function.prototype.toString=function(){return"function: 0x"+this._index.toString(16)};shine.Function.prototype.retain=function(){this._retainCount++};shine.Function.prototype.release=function(){if(!--this._retainCount&&this._readyToDispose){this.dispose()}};shine.Function.prototype.isRetained=function(){if(this._retainCount){return true}for(var a in this.instances){if(this.instances.hasOwnProperty(a)&&this.instances[a].hasRetainedScope()){return true}}return false};shine.Function.prototype.dispose=function(c){this._readyToDispose=true;if(c){for(var b=0,a=this.instances.length;b<a;b++){this.instances[b].dispose(true)}}else{if(this.isRetained()){return false}}delete this._vm;delete this._file;delete this._data;delete this._globals;delete this._upvalues;delete this.instances;delete this._readyToDispose;return true};"use strict";var shine=shine||{};shine.Coroutine=function(a){shine.EventEmitter.call(this);this._func=a.getInstance();this._index=shine.Coroutine._index++;this._started=false;this._yieldVars=undefined;this._resumeStack=this._resumeStack||shine.gc.createArray();this.status=shine.SUSPENDED;shine.stddebug.write("[coroutine created]\n")};shine.Coroutine.prototype=new shine.EventEmitter();shine.Coroutine.prototype.constructor=shine.Function;shine.Coroutine._index=0;shine.Coroutine._graveyard=[];shine.Coroutine.create=function(b){var a=shine.Coroutine._graveyard.pop();if(a){shine.Coroutine.apply(a,arguments);return a}else{return new shine.Coroutine(b)}};shine.Coroutine._add=function(b){var a=shine.getCurrentVM();a._coroutineStack.push(a._coroutineRunning);a._coroutineRunning=b};shine.Coroutine._remove=function(){var a=shine.getCurrentVM();a._coroutineRunning=a._coroutineStack.pop()};shine.Coroutine.prototype.resume=function(){var b,h,f=this._func._instance._vm;try{if(this.status==shine.DEAD){throw new shine.Error("cannot resume dead coroutine")}shine.Coroutine._add(this);if(f&&f._status==shine.RESUMING){h=f._resumeStack.pop()}else{if(shine.debug&&shine.debug._status==shine.RESUMING){h=shine.debug._resumeStack.pop()}}if(h){if(h instanceof shine.Coroutine){b=h.resume()}else{if(h instanceof Function){b=h()}else{b=this._func._instance._run()}}}else{if(!this._started){this.status=shine.RUNNING;shine.stddebug.write("[coroutine started]\n");this._started=true;b=this._func.apply(null,arguments)}else{this.status=shine.RESUMING;shine.stddebug.write("[coroutine resuming]\n");if(!arguments.length){this._yieldVars=undefined}else{var c=shine.gc.createArray();for(var d=0,a=arguments.length;d<a;d++){c.push(arguments[d])}this._yieldVars=c}b=this._resumeStack.pop()._run()}}if(shine.debug&&shine.debug._status==shine.SUSPENDING){shine.debug._resumeStack.push(this);return}this.status=this._func._instance.terminated?shine.DEAD:shine.SUSPENDED;if(b){b.unshift(true)}}catch(g){if(!g.luaStack){g.luaStack=shine.gc.createArray()}g.luaStack.push([this._func._instance,this._func._instance._pc-1]);b=[false,g];this.status=shine.DEAD}if(this.status==shine.DEAD){shine.Coroutine._remove();shine.stddebug.write("[coroutine terminated]\n");this._dispose()}return b};shine.Coroutine.prototype.toString=function(){return"thread:"+(this._index?"0x"+this._index.toString(16):"[dead]")};shine.Coroutine.prototype._dispose=function(){delete this._func;delete this._index;delete this._listeners;delete this._started;delete this._yieldVars;delete this.status;this._resumeStack.length=0;shine.Coroutine._graveyard.push(this)};"use strict";(function(a){a.Table=function(h){var e=((h||a.EMPTY_OBJ) instanceof Array),g,d,f,c;h=h||a.gc.createObject();this.__shine=g=a.gc.createObject();g.type="table";g.index=++a.Table.count;g.keys=a.gc.createArray();g.values=a.gc.createArray();g.numValues=[undefined];for(c in h){if(h.hasOwnProperty(c)){var b;d=e?parseInt(c,10)+1:c;f=h[c];if(f===null){f=undefined}if(typeof getQualifiedClassName!=="undefined"){b=(getQualifiedClassName(f)=="Object"&&!(f instanceof a.Table)&&!(f instanceof a.Coroutine)&&!(f instanceof a.Function)&&!(f instanceof a.Closure))||getQualifiedClassName(f)=="Array"}else{b=(typeof f=="object"&&f.constructor===Object)||f instanceof Array}this.setMember(d,b?new a.Table(f):f)}}};a.Table.count=0;a.Table.prototype.getMember=function(d){var e=typeof d,c,f,b,g;if(e=="string"&&(d=="getMember"||d=="setMember")){e="object"}switch(e){case"string":if(this.hasOwnProperty(d)&&this[d]!==undefined){return this[d]}break;case"number":if(d>0&&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<b;d++){if(this.luaStack[d-1]&&this.luaStack[d][0]===this.luaStack[d-1][0]&&this.luaStack[d][1]===this.luaStack[d-1][1]){continue}if(typeof this.luaStack[d]=="string"){n.push(this.luaStack[d])}else{f=this.luaStack[d][0];h=this.luaStack[d][1];if(!(g=f._data.sourceName)){if(k=this.luaStack[d+1]&&this.luaStack[d+1][0]){for(c in k._localFunctions){if(k._localFunctions[c]._data===f._data){g=c;break}}if(!g){for(c in k._upvalues){e=k._upvalues[c].getValue();if((e||shine.EMPTY_OBJ) instanceof shine.Function&&e._data===f._data){g=k._upvalues[c].name;break}}}}if(!g){for(c in f._globals){if((f._globals[c]||shine.EMPTY_OBJ) instanceof shine.Function&&f._globals[c]._data===f._data){g=c;break}}}}if(f._file&&f._file.url){if(a=f._file.data.sourcePath){a=f._file.url.match("^(.*)/.*?$");a=(a===null?".":a[1]||"")+"/"+a;a=a.replace(/\/\.\//g,"/").replace(/\/.*?\/\.\.\//g,"/")}else{a=f._file.url}}else{a="(compiled code)"}n.push((g||"function")+" ["+(a||"file")+":"+(f._data.linePositions?f._data.linePositions[h]:"?")+"]")}}return n.join("\n ")};shine.Error.prototype.toString=function(){return"Lua run-time error: "+this.message};"use strict";var shine=shine||{};shine.File=function(a,b){this.url=a;this.data=b};shine.File.prototype.dispose=function(){delete this.url;delete this.data};(function(shine){shine.operations={};function move(a,b){var val=this._register.getItem(b),local,i;this._register.setItem(a,val);if(this._data.locals&&val&&val instanceof shine.Function){for(i=this._data.locals.length-1;i>=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!=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<l;i++){item=additions[i];if((item!==undefined&&item instanceof shine.Table&&(mt=item.__shine.metatable)&&(f=mt.getMember("__concat")))||(f=textMetaTable)){args=shine.gc.createArray();args.push(item,text);text=f.apply(null,args,true)[0]}else{text=coerceToString(text,"attempt to concatenate a %type value");item=coerceToString(item,"attempt to concatenate a %type value");text=item+text}}return text}function jmp(a,sbx){this._pc+=sbx}function eq(a,b,c){b=(b>=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<c}function le(a,b,c){compare.call(this,a,b,c,"__le",le_func)}function le_func(b,c){return b<=c}function test(a,b,c){a=this._register.getItem(a);if(shine.utils.coerceToBoolean(a)!==!!c){this._pc++}}function testset(a,b,c){b=this._register.getItem(b);if(shine.utils.coerceToBoolean(b)===!!c){this._register.setItem(a,b)}else{this._pc++}}function call(a,b,c){var args=shine.gc.createArray(),i,l,retvals,funcToResume,running,f,o;if(this._vm._status==shine.RESUMING){funcToResume=this._vm._resumeStack.pop()}else{if(shine.debug&&shine.debug._status==shine.RESUMING){funcToResume=shine.debug._resumeStack.pop()}}if(funcToResume){if(funcToResume instanceof shine.Coroutine){retvals=funcToResume.resume();if(retvals){retvals.shift()}}else{if(funcToResume instanceof shine.Closure){retvals=funcToResume._run()}else{retvals=funcToResume()}}}else{if((running=this._vm._coroutineRunning)&&running.status==shine.RESUMING){funcToResume=running._resumeStack.pop();retvals=funcToResume._run()}else{args=call_prep.call(this,a,b)}}if(!funcToResume){f=this._register.getItem(a);retvals=call_internal.call(this,f,args)}shine.gc.collect(args);if(this._vm._status==shine.SUSPENDING){if(retvals!==undefined&&this._vm._resumeVars===undefined){this._vm._resumeVars=(retvals instanceof Array)?retvals:[retvals]}return}if(!(retvals&&retvals instanceof Array)){retvals=[retvals]}if((running=this._vm._coroutineRunning)&&running.status==shine.SUSPENDING){return}if(c===0){l=retvals.length;for(i=0;i<l;i++){this._register.setItem(a+i,(o=retvals[i])==null?undefined:o)}this._register.splice(a+l)}else{for(i=0;i<c-1;i++){this._register.setItem(a+i,(o=retvals[i])==null?undefined:o)}}}function call_prep(a,b){var i,l,args=[];if(b===0){l=this._register.getLength();for(i=a+1;i<l;i++){args.push(this._register.getItem(i))}}else{for(i=0;i<b-1;i++){args.push(this._register.getItem(a+i+1))}}return args}function call_internal(f,args){var retvals,mt,c;if(f!==undefined){if(f.apply){retvals=f.apply(null,args)}else{if(f instanceof shine.Table&&(mt=f.__shine.metatable)&&(c=mt.getMember("__call"))&&c.apply){args.unshift(f);retvals=c.apply(null,args,true)}else{throw new shine.Error("Attempt to call non-function")}}}else{throw new shine.Error("Attempt to call a nil value")}return retvals}function tailcall(a,b){return call.call(this,a,b,0)}function return_(a,b){var retvals=shine.gc.createArray(),val,i,l;if(b===0){l=this._register.getLength();for(i=a;i<l;i++){retvals.push(this._register.getItem(i))}}else{for(i=0;i<b-1;i++){retvals.push(val=this._register.getItem(a+i));shine.gc.incrRef(val)}}close.call(this,0);this.dead=true;return retvals}function forloop(a,sbx){var step=this._register.getItem(a+2),limit=this._register.getItem(a+1),index=this._register.getItem(a)+step,parity=step/Math.abs(step);this._register.setItem(a,index);if((parity===1&&index<=limit)||(parity!==1&&index>=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<c;i++){this._register.setItem(a+i+3,retvals[i])}if((val=retvals[0])!==undefined){this._register.setItem(a+2,val)}else{this._pc++}}function tforloop_internal(f,args){var retvals=f.apply(undefined,args),val;if(!(retvals&&retvals instanceof Array)){val=shine.gc.createArray();val.push(retvals);retvals=val}return retvals}function setlist(a,b,c){var length=b||this._register.getLength()-a-1,i;for(i=0;i<length;i++){this._register.getItem(a).setMember(50*(c-1)+i+1,this._register.getItem(a+i+1))}}function close(a,b,c){close_internal.call(this,a,close_getValue,close_clearItem)}function close_getValue(index){return this._register.getItem(index)}function close_clearItem(index){this._register.clearItem(index)}function close_internal(a,getValue,clearItem){for(var i=0,l=this._localsUsedAsUpvalues.length;i<l;i++){var local=this._localsUsedAsUpvalues[i];if(local&&local.registerIndex>=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<l;i+=4){opcode=upvalueData[i];A=upvalueData[i+1];B=upvalueData[i+2];C=upvalueData[i+3];upvalues.push((opcode?closure_getupval:closure_move).call(this,bx,i/4,A,B,C,getUpval,setUpval))}return upvalues}function closure_getUpval(b){return this._register.getItem(b)}function closure_setUpval(b,val){this._register.setItem(b,val)}function closure_move(funcIndex,index,a,b,c,getUpval,setUpval){var me=this,updata,upvalue;for(var j=0,l=this._localsUsedAsUpvalues.length;j<l;j++){updata=this._localsUsedAsUpvalues[j];if(updata.registerIndex===b){upvalue=updata.upvalue;break}}if(!upvalue){upvalue={open:true,getValue:function(){return this.open?getUpval.call(me,b):this.value},setValue:function(val){if(this.open){setUpval.call(me,b,val)}else{shine.gc.incrRef(val);shine.gc.decrRef(this.value);this.value=val}},name:this._functions[funcIndex].upvalues?this._functions[funcIndex].upvalues[index]:"(upvalue)"};this._localsUsedAsUpvalues.push({registerIndex:b,upvalue:upvalue})}return upvalue}function closure_getupval(funcIndex,index,a,b,c){var me=this;return{getValue:function(){return me._upvalues[b].getValue()},setValue:function(val){me._upvalues[b].setValue(val)},name:this._upvalues[b].name}}function vararg(a,b){var i,l,limit=b===0?Math.max(0,this._params.length-this._data.paramCount):b-1;for(i=0;i<limit;i++){this._register.setItem(a+i,this._params[this._data.paramCount+i])}for(i=a+limit,l=this._register.getLength();i<l;i++){this._register.clearItem(i)}}var incr=shine.gc.incrRef,decr=shine.gc.decrRef.bind(shine.gc),collect=shine.gc.collect.bind(shine.gc),createArray=shine.gc.createArray.bind(shine.gc),cacheArray=shine.gc.cacheArray.bind(shine.gc),EMPTY_ARR=shine.EMPTY_ARR;function get_upv(x){return this[x]}function set_upv(x,y){setR(this,x,y)}function setR(register,index,value){incr(value);decr(register[index]);register[index]=value}function clearR(register,index){for(var i=index,l=register.length;i<l;i++){decr(register[i])}register.length=index-1}function setRArr(register,index,limit,arr){var toDecr=register.splice(index,Infinity),i,l;if(!(arr instanceof Array)){i=createArray();i.push(arr);arr=i}for(i=0,l=limit||arr.length;i<l;i++){incr(register[index+i]=arr[i])}for(i=0,l=toDecr.length;i<l;i++){decr(register.shift())}cacheArray(arr)}function callR(register,index,c,argStart,argEnd){var args=createArray(),result,i,limit,toDecr;if(argStart){limit=argEnd?argEnd:register.length;for(i=argStart;i<limit;i++){args.push(register[i])}}result=call_internal(register[index],args);toDecr=register.splice(index,Infinity);if(c==1){}else{if(!(result instanceof Array)){setR(register,index,result)}else{for(i=0,limit=result.length;i<limit;i++){incr(result[i])}result.unshift(index,0);Array.prototype.splice.apply(register,result);cacheArray(result)}}for(i=0,limit=toDecr.length;i<limit;i++){decr(toDecr.shift())}cacheArray(args)}function setlistT(R,t,index,keyStart,length){t.setMember(keyStart,R[index]);if(--length){setlistT(R,t,index+1,keyStart+1,length)}}function create_func(def,upvals,cl){return new shine.Function(cl._vm,cl._file,def,cl._globals,upvals)}shine.operations.HANDLERS=[move,loadk,loadbool,loadnil,getupval,getglobal,gettable,setglobal,setupval,settable,newtable,self,add,sub,mul,div,mod,pow,unm,not,len,concat,jmp,eq,lt,le,test,testset,call,tailcall,return_,forloop,forprep,tforloop,setlist,close,closure,vararg];shine.operations.NAMES=["move","loadk","loadbool","loadnil","getupval","getglobal","gettable","setglobal","setupval","settable","newtable","self","add","sub","mul","div","mod","pow","unm","not","len","concat","jmp","eq","lt","le","test","testset","call","tailcall","return","forloop","forprep","tforloop","setlist","close","closure","vararg"];shine.operations.evaluateInScope=function(funcDef,vm){var func,shine_g=(vm||shine.getCurrentVM())._globals;eval("func="+funcDef);return func};shine.operations.internal={getglobal:getglobal_internal,gettable:gettable_internal,setglobal:setglobal_internal,settable:settable_internal,newtable:newtable_internal,self:self_internal,binary_arithmetic:binary_arithmetic_internal,add:add_internal,sub:sub_internal,mul:mul_internal,div:div_internal,mod:mod_internal,unm:unm_internal,len:len_internal,concat:concat_internal,eq:eq_internal,compare:compare_internal,call:call_internal,tforloop:tforloop_internal,close:close_internal,closure_upvalues:closure_upvalues,lt_func:lt_func,le_func:le_func}})(shine||{});"use strict";(function(d){d.jit=d.jit||{};d.jit.enabled=d.jit.enabled||false;d.jit.INVOCATION_TOLERANCE=2;d.jit.MIN_FPS_TO_COMPILE=59;d.jit.COMPILE_INTERVAL=500;var J=/^setR\(R,(\d+),([^;]*?)\);$/,v=d.gc,t=d.Function.prototype.apply,Q=v.createArray(),m=0,f=false,I=Date.now?Date.now:function(){return new Date().getTime()},e;d.Function.prototype.apply=function(){var ah,ai;if(d.jit.enabled){ah=this._data;if(ai=ah._compiled){this.apply=p(this,ah,ai);return this.apply.apply(this,arguments)}this._runCount=this._runCount||0;if(!this._compiling&&++this._runCount==d.jit.INVOCATION_TOLERANCE){this._compile()}}return t.apply(this,arguments)};d.Function.prototype._compile=function(){var ah=this,ai=this._data;if(!ai._compiling){ai._compiling=true;d.jit.compile(this,function(aj){if(ai._compiled=aj){ai._compiling=false;ah.apply=p(ah,ai,aj)}})}};function p(ah,ai,aj){return function(am,al){var an=v.createObject(),ak;an._vm=ah._vm;an._globals=ah._globals;an._upvalues=ah._upvalues;an._constants=ai.constants;an._functions=ai.functions;an._localsUsedAsUpvalues=v.createArray();return aj.apply(an,al)}}d.jit.onCompile=function(){};function F(){if(!f){f=true;e=I();m=0;window.setTimeout(y,d.jit.COMPILE_INTERVAL);window.requestAnimationFrame(l)}}function l(){if(f){m++;window.requestAnimationFrame(l)}}function y(){if(!d||!d.jit){return}var ah=I(),ai=1000*m/(ah-e);if(ai>=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;ak<ao;ak++){if(!((al=this.code[this.pc-ak])&&al.match(J))||al[1]!=""+(ap+ao-ak)){aq=false;break}else{aj.unshift(al[2])}}if(aq){al=this.code[this.pc-ao].match(J);if(al&&al[1]==""+ap){ah=al[2];for(ak=1;ak<=ao;ak++){this.code[this.pc-ak]=""}if(an==1){ar=ah+".call(void 0,"+aj.join(",")+");"}else{ar="setRArr(R,"+ap+","+(an?an-1:"void 0")+","+ah+".call(void 0,"+aj.join(",")+"));"}}}}}v.collect(aj);return ar||"callR(R,"+ap+","+an+","+am+");"}function c(ai,ah){return T.call(this,ai,ah,0)}function V(ai,ah){var ak=B.call(this,0),aj;if(ah===0){aj=s.call(this,"i");return"_=R.slice("+ai+");"+ak+"return _;"}else{if(ah==1){return ak+"return createArray();"}else{return"_=R.slice("+ai+","+(ai+ah-1)+");"+ak+"return _;"}}}function L(aq,an){var ah="R["+(aq+2)+"]",ai="R["+(aq+1)+"]",al="R["+aq+"]+"+ah,ak=ah+">0",am=s.call(this,"limit"),ao=this.pc+an+1;var ap=true,ar,aj;for(aj=ao;aj<this.pc;aj++){if(this.jumpDestinations[aj]||(this.code[aj]&&this.code[aj].indexOf("pc=")>=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<this.pc;ai++){if(this.jumpDestinations[ai]||(this.code[ai]&&this.code[ai].indexOf("pc=")>=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;ai<aj;ai++){aq+="setR(R,"+(an+ai+3)+","+ah+"["+ai+"]);"}aq+="if("+ah+"[0]!==void 0){setR(R,"+(an+2)+","+ah+"[0])}else{break}";this.code[ap]=aq;return"}"}this.jumpDestinations[ak]=1;aq=ah+"=tforloop_internal(R["+an+"],R.slice("+(an+1)+","+(an+3)+"));";for(ai=0;ai<aj;ai++){aq+="setR(R,"+(an+ai+3)+","+ah+"["+ai+"]);"}aq+="if("+ah+"[0]!==void 0){setR(R,"+(an+2)+","+ah+"[0])}else{pc="+ak+";break}";return aq}function w(ai,ah,aj){return"setlistT(R,R["+ai+"],"+(ai+1)+","+(50*(aj-1)+1)+","+(ah==0?"R.length-1":ah)+");"}function B(ai,ah,aj){if(this.vars.indexOf("getupval")<0){this.vars.push("getupval")}return"close_internal.call(cl,"+ai+",getupval);"}function n(aj,ao){var an=v.createArray(),ai=this._instructions,al=al,am=ai.slice||ai.subarray,ak,ah;this.pc++;if(this.vars.indexOf("getupval")<0){this.vars.push("getupval")}if(this.vars.indexOf("setupval")<0){this.vars.push("setupval")}while((ak=ai[this.pc*4])!==undefined&&(ak===0||ak===4)&&this._instructions[this.pc*4+1]===0){an.push.apply(an,am.call(ai,this.pc*4,this.pc*4+4));this.pc++}this.pc--;if(an.length||typeof al=="undefined"){ah="setR(R,"+aj+",create_func(cl._functions["+ao+"],closure_upvalues.call(cl,"+ao+","+JSON.stringify(an)+",getupval,setupval),cl));"}else{ah="setR(R,"+aj+",cl._functions["+ao+"]);"}v.collect(an);return ah}function C(ak,ai){var ah="R.length="+ak+";",al,aj;if(ai===0){ah="for(_="+this.paramCount+";_<arguments.length;_++)setR(R,_+"+(ak-this.paramCount)+",arguments[_]);"}else{for(al=0,aj=ai-1;al<aj;al++){ah+="setR(R,"+(ak+al)+",arguments["+(this.paramCount+al)+"]);"}}return ah}d.jit.TRANSLATORS=[b,R,E,h,W,G,P,O,S,K,X,ad,af,r,ae,U,ag,x,o,M,k,z,aa,g,ab,a,ac,q,T,c,V,L,j,H,w,B,n,C];d.jit.compile=function(ai,aj){if(d.jit.MIN_FPS_TO_COMPILE){var ah=v.createArray();ah.push(ai,aj);Q.push(ah);F()}else{i(ai,aj)}};d.jit.toJS=function(ao){var al=ao._data.instructions,ak=ao._data.paramCount,am=ao._data.is_vararg>0,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<av){ap=ah*4;aw=al[ap];aA=al[ap+1];az=al[ap+2];ay=al[ap+3];if(!an.code[ah]){an.code[ah]=d.jit.TRANSLATORS[aw].call(an,aA,az,ay)}ah=++an.pc}for(ah in an.jumpDestinations){ax=parseInt(ah,10);an.code[ax]="case "+ah+":"+an.code[ax]}if(ao._data.is_vararg==7){ai="setR(R,"+ak+",new shine.Table(Array.prototype.slice.call(arguments,"+ak+")));R["+ak+'].setMember("n", arguments.length-'+ak+");"}if(an.vars.indexOf("getupval")>=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<ak;ax++){aj.push("setR(R,"+ax+",A"+ax+");");aq.push("A"+ax)}if(ai){aj.push(ai)}aj.push(ar);aj.push("shine.Closure._current=cl;while(1){switch(pc){");aj=aj.concat(an.code);aj.push("}}");at="function("+aq.join()+"){"+aj.join("\n")+"}";v.collect(aj);v.collect(aq);v.collect(an.code);v.collect(an.vars);v.collect(an.jumpDestinations);v.collect(an);return at}})(shine||{});if(typeof module!="undefined"){module.exports=shine.jit}"use strict";(function(b){var o=16807,d=2147483647,g={"([^a-zA-Z0-9%(])-":"$1*?","(.)-([^a-zA-Z0-9?])":"$1*?$2","(.)-$":"$1*?","%a":"[a-zA-Z]","%A":"[^a-zA-Z]","%c":"[\x00-\x1f]","%C":"[^\x00-\x1f]","%d":"\\d","%D":"[^\d]","%l":"[a-z]","%L":"[^a-z]","%p":"[.,\"'?!;:#$%&()*+-/<>=@[]\\^_{}|~]","%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;s<q;s++){r+=e[s]}if(q>1&&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;s<q;s++){t=u.substr(s,1);r=false;if(t=="["){if(v){r=true}v++}else{if(t=="]"){v--;if(v){r=true}}}if(r){u=u.substr(0,s)+u.substr(s+++1);q++}}return u}function a(q,u){var s=k(this),r,t;s.fileManager.load(q,function(x,v){if(x){s._trigger("module-load-error",[v,x]);if(x==404&&/\.lua$/.test(q)){a.call(s,q+".json",u)}else{u()}return}var w=new b.Function(s,v,v.data,s._globals);s._trigger("module-loaded",[v,w]);u(w)});s._trigger("loading-module",q)}b.lib={assert:function(r,q){if(r===false||r===undefined){throw new b.Error(q||"Assertion failed!")}return[r,q]},collectgarbage:function(r,q){},dofile:function(q){},error:function(q){throw new b.Error(q)},getfenv:function(q){},getmetatable:function(r){var q;if(r instanceof b.Table){if((q=r.__shine.metatable)&&(q=q.__metatable)){return q}return r.__shine.metatable}else{if(typeof r=="string"){return j}}},ipairs:function(q){if(!((q||b.EMPTY_OBJ) instanceof b.Table)){throw new b.Error("Bad argument #1 in ipairs(). Table expected")}return[i,q,0]},load:function(v,r){var u=k(this),s="",t,q;while((t=v.apply(v))&&(t=t[0])){s+=(q=t)}return b.lib.loadstring.call(u,s)},loadfile:function(q){var r=k(this),s=function(t){r.resume(t||[])};r.suspend();a.call(r,q,s)},loadstring:function(r,q){var s=k(this);if(typeof r!="string"){throw new b.Error("bad argument #1 to 'loadstring' (string expected, got "+b.utils.coerce(r,"string")+")")}if(!r){return new b.Function(s)}s.suspend();s.fileManager.load(r,function(v,t){if(v){s.resume([]);return}var u=new b.Function(s,t,t.data,s._globals,b.gc.createArray());s.resume([u])})},next:function(w,s){var y=(s===undefined),t=w.__shine.numValues,x,v,u,r,q;if(y||(typeof s=="number"&&s>0&&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;t<r;t++){s.push(arguments[t])}try{if(typeof u=="function"){q=u.apply(null,s)}else{if((u||b.EMPTY_OBJ) instanceof b.Function){q=u.apply(null,s,true)}else{throw new b.Error("Attempt to call non-function")}}}catch(v){return[false,v&&v.message||v]}if(!((q||b.EMPTY_OBJ) instanceof Array)){q=[q]}q.unshift(true);return q},print:function(){var r=b.gc.createArray(),t;for(var s=0,q=arguments.length;s<q;s++){r.push(b.lib.tostring(arguments[s]))}return b.stdout.write(r.join("\t"))},rawequal:function(r,q){return(r===q)},rawget:function(r,q){if(!((r||b.EMPTY_OBJ) instanceof b.Table)){throw new b.Error("Bad argument #1 in rawget(). Table expected")}return r[q]},rawset:function(r,q,s){if(!((r||b.EMPTY_OBJ) instanceof b.Table)){throw new b.Error("Bad argument #1 in rawset(). Table expected")}if(q==undefined){throw new b.Error("Bad argument #2 in rawset(). Nil not allowed")}r[q]=s;return r},require:function(x){var s=k(this),y=s._globals["package"],A=b.Closure._current,r,B,D,E,q,v,w=b.gc.createArray();function u(F){return function(){return C(F)}}function C(G){var F;if(s._resumeStack.length){F=s._resumeStack.pop()._run()}else{if(b.debug&&b.debug._resumeStack&&b.debug._resumeStack.length){F=b.debug._resumeStack.pop()._run()}else{y.loaded[x]=true;F=G.call(null,x)}}if(s._status==b.SUSPENDING&&!F){A._pc--;s._resumeStack.push(u(G));return}else{if(b.debug&&b.debug._status==b.SUSPENDING&&!F){A._pc--;b.debug._resumeStack.push(u(G));return}}if(!F){return}r=F[0];if(r!==undefined){y.loaded.setMember(x,r)}return y.loaded[x]}x=b.utils.coerceToString(x);if(r=y.loaded[x]){return r}if(B=y.preload[x]){return C(B)}q=x.replace(/\./g,"/")+".lua.json";v=s.fileManager._cache[q];if(v){var t=new b.File(q,v);B=new b.Function(s,t,t.data,s._globals);y.preload[x]=B;return C(B)}D=y.path.replace(/;;/g,";").split(";");s.suspend();function z(){E=D.shift();if(!E){throw new b.Error("module '"+x+"' not found:\n no field package.preload['"+x+"']\n"+w.join("\n"))}else{E=E.replace(/\?/g,x.replace(/\./g,"/"));a.call(s,E,function(F){if(F){y.preload[x]=F;b.Closure._current._pc--;s.resume()}else{w.push(" no file '"+E+"'");z()}})}}z()},select:function(r){var q=b.gc.createArray();if(r=="#"){return arguments.length-1}else{if(r=parseInt(r,10)){return arguments.constructor===Array?arguments.slice(r):Array.prototype.slice.call(arguments,r)}else{throw new b.Error('bad argument #1 in select(). Number or "#" expected')}}},setmetatable:function(s,r){var q;if(!((s||b.EMPTY_OBJ) instanceof b.Table)){throw new b.Error("Bad argument #1 in setmetatable(). Table expected")}if(!(r===undefined||(r||b.EMPTY_OBJ) instanceof b.Table)){throw new b.Error("Bad argument #2 in setmetatable(). Nil or table expected")}if((q=s.__shine.metatable)&&(q=q.__metatable)){throw new b.Error("cannot change a protected metatable")}b.gc.incrRef(r);b.gc.decrRef(s.__shine.metatable);s.__shine.metatable=r;return s},tonumber:function(u,t){var q,r,s;if(u===""){return}t=t||10;if(t<2||t>36){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;t<r;t++){s.push(arguments[t])}return q.resume.apply(q,s)},running:function(){var q=k(this);return q._coroutineRunning},status:function(q){switch(q.status){case b.RUNNING:return(q===k()._coroutineRunning)?"running":"normal";case b.SUSPENDED:return"suspended";case b.DEAD:return"dead"}},wrap:function(t){var s=b.lib.coroutine.create(t),r=k(this);var q=function(){var w=[s];for(var x=0,u=arguments.length;x<u;x++){w.push(arguments[x])}var v=b.lib.coroutine.resume.apply(null,w),y;if(!v&&(r._status==b.SUSPENDING||(b.debug&&b.debug._status==b.SUSPENDING))){return}y=v.shift();if(y){return v}throw v[0]};q._coroutine=s;return q},yield:function(){var r=k()._coroutineRunning,s;if(!r){throw new b.Error("attempt to yield across metamethod/C-call boundary (not in coroutine)")}if(r.status!=b.RUNNING){throw new b.Error("attempt to yield non-running coroutine in host")}s=b.gc.createArray();for(var t=0,q=arguments.length;t<q;t++){s.push(arguments[t])}r._yieldVars=s;r.status=b.SUSPENDING;return{resume:function(){var v=[r],w,u=arguments.length,x=function(){b.lib.coroutine.resume.apply(undefined,v)};if(arguments.length==1&&arguments[0]===undefined){u=0}for(w=0;w<u;w++){v.push(arguments[w])}if(r.status==b.SUSPENDING){window.setTimeout(x,1)}else{x()}}}}});b.lib.debug=new b.Table({debug:function(){},getfenv:function(q){},gethook:function(q){},getinfo:function(q,r,s){},getlocal:function(q,s,r){},getmetatable:function(q){},getregistry:function(){},getupvalue:function(r,q){},setfenv:function(q,r){},sethook:function(q,t,r,s){},setlocal:function(q,t,r,s){},setmetatable:function(q,r){},setupvalue:function(r,q,s){},traceback:function(q,r,s){}});b.lib.io=new b.Table({close:function(q){if(q){throw new b.Error("File operations currently not supported.")}},flush:function(){},input:function(q){throw new b.Error("File operations currently not supported.")},lines:function(q){throw new b.Error("File operations currently not supported.")},open:function(q){throw new b.Error("File operations currently not supported.")},output:function(q){throw new b.Error("File operations currently not supported.")},popen:function(q,r){throw new b.Error("File operations currently not supported.")},read:function(){throw new b.Error("File operations currently not supported.")},stderr:{},stdin:{},stdout:{},tmpfile:function(){throw new b.Error("File operations currently not supported.")},type:function(){},write:function(){var s,q,r="";for(var s in arguments){if(arguments.hasOwnProperty(s)){r+=b.utils.coerceToString(arguments[s],"bad argument #"+s+" to 'write' (string expected, got %type)")}}b.stdout.write(r)}});b.lib.math=new b.Table({abs:function(q){return Math.abs(q)},acos:function(q){return Math.acos(q)},asin:function(q){return Math.asin(q)},atan:function(q){return Math.atan(q)},atan2:function(r,q){return Math.atan2(r,q)},ceil:function(q){return Math.ceil(q)},cos:function(q){return Math.cos(q)},cosh:function(q){var r=b.lib.math.exp;return(r(q)+r(-q))/2},deg:function(q){return q*180/Math.PI},exp:function(q){return Math.exp(q)},floor:function(q){return Math.floor(q)},fmod:function(q,r){return q%r},frexp:function(q){var t,s,r;if(q==0){return[0,0]}t=q>0?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;s<r;s++){q+=String.fromCharCode(arguments[s])}return q},dump:function(t){var u=t._data,r=b.gc.createObject(),q=b.gc.createArray(),s;for(s in u){if(u.hasOwnProperty(s)){r[s]=u[s]}}q.push.apply(q,r.instructions);r.instructions=q;return JSON.stringify(r)},find:function(w,x,y,u){if(typeof w!="string"&&typeof w!="number"){throw new b.Error("bad argument #1 to 'find' (string expected, got "+typeof w+")")}if(typeof x!="string"&&typeof x!="number"){throw new b.Error("bad argument #2 to 'find' (string expected, got "+typeof x+")")}w=""+w;y=y||1;var t,v,r,q;if(u===undefined||!u){x=p(x);v=new RegExp(x);t=w.substr(y-1).search(v);if(t<0){return}r=w.substr(y-1).match(v);q=[t+y,t+y+r[0].length-1];r.shift();return q.concat(r)}t=w.indexOf(x,y-1);return(t===-1)?undefined:[t+1,t+x.length]},format:function(H){var z=/^((.|\s)*?)(%)((.|\s)*)$/,r=/^(%?)([+\-#\ 0]*)(\d*)(\.(\d*))?([cdeEfgGiouqsxX])((.|\s)*)$/,B,y="",t,u=arguments.constructor===Array?arguments:Array.prototype.slice.call(arguments,0),F=2,v=2;u.shift();function D(x){var s=x[2],q=parseInt(x[5]);if((""+s).length>5){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<q)&&z&&(t=z.match(x))){if(typeof v=="function"||(v||b.EMPTY_OBJ) instanceof b.Function){y=v.apply(null,[t[0]],true);if(y instanceof Array){y=y[0]}if(y===undefined){y=t[0]}}else{if((v||b.EMPTY_OBJ) instanceof b.Table){y=v.getMember(t[0])}else{if(typeof v=="object"){y=v[t]}else{y=(""+v).replace(/%([0-9])/g,function(s,B){return t[B]})}}}if(t[0].length==0&&r===undefined){u=""}else{u=z.split(t[0],1)[0]}r=t[0];A+=u+y;z=z.substr((u+r).length);w++}return[A+z,w]},len:function(q){q=b.utils.coerceToString(q,"bad argument #1 to 'len' (string expected, got %type)");return q.length},lower:function(q){if(typeof q!="string"&&typeof q!="number"){throw new b.Error("bad argument #1 to 'lower' (string expected, got "+typeof q+")")}return(""+q).toLowerCase()},match:function(q,t,u){if(typeof q!="string"&&typeof q!="number"){throw new b.Error("bad argument #1 to 'match' (string expected, got "+typeof q+")")}if(typeof t!="string"&&typeof t!="number"){throw new b.Error("bad argument #2 to 'match' (string expected, got "+typeof t+")")}u=u?u-1:0;q=(""+q).substr(u);var r=q.match(new RegExp(p(t)));if(!r){return}if(!r[1]){return r[0]}r.shift();return r},rep:function(t,u){var q="",r;for(r=0;r<u;r++){q+=t}return q},reverse:function(t){var q="",r;for(r=t.length;r>=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(s<r&&u[s]===undefined){delete u[s++]}return q},sort:function(s,r){if(!((s||b.EMPTY_OBJ) instanceof b.Table)){throw new b.Error("Bad argument #1 to 'sort' (table expected)")}var t,q=s.__shine.numValues;if(r){if(!(r instanceof b.Function||r.constructor===Function)){throw new b.Error("Bad argument #2 to 'sort' (function expected)")}t=function(v,u){return r.apply(null,[v,u],true)[0]?-1:1}}else{t=function(v,u){return v<u?-1:1}}q.shift();q.sort(t).unshift(undefined)},unpack:function(t,s,r){if(!((t||b.EMPTY_OBJ) instanceof b.Table)){throw new b.Error("Bad argument #1 to 'unpack' (table expected)")}s=s||1;if(r===undefined){r=b.lib.table.getn(t)}var u=b.gc.createArray(),q;for(q=s;q<=r;q++){u.push(t.getMember(q))}return u}})})(shine||{});"use strict";(function(e){var b=/^[-+]?[0-9]*\.?([0-9]+([eE][-+]?[0-9]+)?)?$/,a=/^(\-)?0x([0-9a-fA-F]*)\.?([0-9a-fA-F]*)$/;function d(g,f){if(!f){return}f=(""+f).replace(/\%type/gi,e.lib.type(g));throw new e.Error(f)}function c(g){for(var f in g){if(g.hasOwnProperty(f)){if(typeof g[f]==="object"){g[f]=c(g[f])}else{if(g[f]===null){g[f]=undefined}}}}return new e.Table(g)}e.utils={coerceToBoolean:function(g,f){return !(g===false||g===undefined)},coerceToString:function(g,f){switch(true){case typeof g=="string":return g;case g===undefined:case g===null:return"nil";case g===Infinity:return"inf";case g===-Infinity:return"-inf";case typeof g=="number":case typeof g=="boolean":return window.isNaN(g)?"nan":""+g;default:return d(g,f)||""}},coerceToNumber:function(i,h){var j,g,f;switch(true){case typeof i=="number":return i;case i===undefined:return;case i==="inf":return Infinity;case i==="-inf":return -Infinity;case i==="nan":return NaN;default:if((""+i).match(b)){j=parseFloat(i)}else{if(g=(""+i).match(a)){f=g[3];if((j=g[2])||f){j=parseInt(j,16)||0;if(f){j+=parseInt(f,16)/Math.pow(16,f.length)}if(g[1]){j*=-1}}}}if(j===undefined){d(i,h)}return j}},toObject:function(m){var k=e.lib.table.getn(m)>0,f=e.gc["create"+(k?"Array":"Object")](),h=m.__shine.numValues,j,g=h.length;for(j=1;j<g;j++){f[j-1]=((h[j]||e.EMPTY_OBJ) instanceof e.Table)?e.utils.toObject(h[j]):h[j]}for(j in m){if(m.hasOwnProperty(j)&&!(j in e.Table.prototype)&&j!=="__shine"){f[j]=((m[j]||e.EMPTY_OBJ) instanceof e.Table)?e.utils.toObject(m[j]):m[j]}}return f},parseJSON:function(f){return c(JSON.parse(f))},get:function(g,j,f){var i=new XMLHttpRequest(),h;i.open("GET",g,true);if("ArrayBuffer" in window){i.responseType="arraybuffer";h=function(p){if(p.byteLength<=10000){return String.fromCharCode.apply(String,Array.prototype.slice.call(new Uint8Array(p)))}var o,n,m=new Uint8Array(p),k="";for(o=0,n=p.byteLength;o<n;o+=10000){k+=String.fromCharCode.apply(String,Array.prototype.slice.call(m.subarray(o,Math.min(o+10000,n))))}return k}}else{i.responseType="text";h=function(k){return k}}i.onload=function(k){if(this.status==200){if(j){j(h(this.response))}}else{if(f){f(this.status)}}};i.send(e.EMPTY_OBJ)}}})(shine||{});"use strict";(function(a){a.stdout={};a.stdout.write=function(b){if(console&&console.log){console.log(b)}else{if(trace){trace(b)}}};a.stddebug={};a.stddebug.write=function(b){};a.stderr={};a.stderr.write=function(b,c){c=c||"error";if(console&&console[c]){console[c](b)}}})(shine||{});var module=module;if(typeof module!="undefined"){module.exports=shine};