isaacscript-common 84.2.3 → 84.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,6 +3,990 @@
3
3
 
4
4
  // cspell: disable
5
5
 
6
+ /*
7
+ Copyright 2011 Maximilian Herkender
8
+
9
+ Licensed under the Apache License, Version 2.0 (the "License");
10
+ you may not use this file except in compliance with the License.
11
+ You may obtain a copy of the License at
12
+
13
+ http://www.apache.org/licenses/LICENSE-2.0
14
+
15
+ Unless required by applicable law or agreed to in writing, software
16
+ distributed under the License is distributed on an "AS IS" BASIS,
17
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ See the License for the specific language governing permissions and
19
+ limitations under the License.
20
+ */
21
+ var lua_print = function () {
22
+ try {
23
+ console.log.apply(console, arguments);
24
+ } catch (a) {}
25
+ return [];
26
+ };
27
+ function lua_load(a, b) {
28
+ if (!lua_parser)
29
+ throw Error(
30
+ "Lua parser not available, perhaps you're not using the lua+parser.js version of the library?",
31
+ );
32
+ eval(
33
+ "fn = function " +
34
+ (b || "load") +
35
+ "() {\nreturn (function () {\n" +
36
+ lua_parser.parse(a) +
37
+ "\n})()[0];\n};",
38
+ );
39
+ }
40
+ function slice(a, b) {
41
+ return a.slice ? a.slice(b) : Array.prototype.slice.call(a, b);
42
+ }
43
+ function not_supported() {
44
+ throw Error("Not supported");
45
+ }
46
+ function ensure_arraymode(a) {
47
+ if (!a.arraymode) {
48
+ var b = [],
49
+ c;
50
+ for (c in a.uints) null != a.uints[c] && (b[c - 1] = a.uints[c]);
51
+ a.uints = b;
52
+ a.arraymode = !0;
53
+ }
54
+ }
55
+ function ensure_notarraymode(a) {
56
+ if (a.arraymode) {
57
+ var b = {},
58
+ c;
59
+ for (c in a.uints) null != a.uints[c] && (b[c - -1] = a.uints[c]);
60
+ a.uints = b;
61
+ delete a.arraymode;
62
+ }
63
+ }
64
+ function ReturnValues(a) {
65
+ this.vars = a || [];
66
+ }
67
+ function lua_true(a) {
68
+ return null != a && !1 !== a;
69
+ }
70
+ function lua_not(a) {
71
+ return null == a || !1 === a;
72
+ }
73
+ function lua_and(a, b) {
74
+ return null == a || !1 === a ? a : b();
75
+ }
76
+ function lua_or(a, b) {
77
+ return null != a && !1 !== a ? a : b();
78
+ }
79
+ function lua_assertfloat(a) {
80
+ var b = parseFloat(a);
81
+ if (isNaN(b)) throw Error("Invalid number: " + a);
82
+ return b;
83
+ }
84
+ function lua_newtable(a) {
85
+ for (
86
+ var b = { str: {}, uints: {}, floats: {}, bool: {}, objs: [] }, c = 1;
87
+ c < arguments.length - 1;
88
+ c += 2
89
+ ) {
90
+ var d = arguments[c + 1];
91
+ if (null != d) {
92
+ var e = arguments[c];
93
+ switch (typeof e) {
94
+ case "string":
95
+ b.str[e] = d;
96
+ break;
97
+ case "number":
98
+ if (e != e) throw Error("Table index is NaN");
99
+ 0 < e && (e | 0) == e ? (b.uints[e] = d) : (b.floats[e] = d);
100
+ break;
101
+ case "boolean":
102
+ b.bool[e] = d;
103
+ break;
104
+ case "object":
105
+ if (null == e) throw Error("Table index is nil");
106
+ var f = !1;
107
+ for (c in b.objs)
108
+ if (b.objs[c][0] === e) {
109
+ null == d ? b.objs.splice(c, 1) : ((f = !0), (b.objs[c][1] = d));
110
+ break;
111
+ }
112
+ f || b.objs.push([e, d]);
113
+ break;
114
+ default:
115
+ throw Error("Unsupported type for table: " + typeof e);
116
+ }
117
+ }
118
+ }
119
+ if (a)
120
+ if ((ensure_arraymode(b), 0 == b.uints.length)) b.uints = a;
121
+ else for (c = a.length; 0 < c--; ) b.uints[c] = a[c];
122
+ return b;
123
+ }
124
+ function lua_newtable2(a) {
125
+ var b = {},
126
+ c;
127
+ for (c in a) b[c] = a[c];
128
+ return { str: b, uints: {}, floats: {}, bool: {}, objs: {} };
129
+ }
130
+ function lua_len(a) {
131
+ if ("string" == typeof a) return a.length;
132
+ if ("object" == typeof a && null != a) {
133
+ if (null == a.length) {
134
+ var b = 0;
135
+ if (a.arraymode) for (; null != a.uints[b++]; );
136
+ else for (; null != a.uints[++b]; );
137
+ return (a.length = b - 1);
138
+ }
139
+ return a.length;
140
+ }
141
+ if ((b = a.metatable && a.metatable.str.__len)) return lua_rawcall(b, [a])[0];
142
+ throw Error("Length of <" + a + "> not supported");
143
+ }
144
+ function lua_rawcall(a, b) {
145
+ try {
146
+ return a.apply(null, b);
147
+ } catch (c) {
148
+ if (c.constructor == ReturnValues) return c.vars;
149
+ throw c;
150
+ }
151
+ }
152
+ function lua_tablegetcall(a, b, c) {
153
+ a = lua_tableget(a, b);
154
+ if ("function" == typeof a) return lua_rawcall(a, c);
155
+ if (null == a) throw Error("attempt to call field '" + b + "' (a nil value)");
156
+ b = a.metatable && a.metatable.str.__call;
157
+ if (null != b) return lua_rawcall(b, [a].concat(c));
158
+ throw Error("Could not call " + a + " as function");
159
+ }
160
+ function lua_call(a, b) {
161
+ if ("function" == typeof a) return lua_rawcall(a, b);
162
+ if (null == a) throw Error("attempt to call function (a nil value)");
163
+ var c = a.metatable && a.metatable.str.__call;
164
+ if (null != c) return lua_rawcall(c, [a].concat(b));
165
+ throw Error("Could not call " + a + " as function");
166
+ }
167
+ function lua_mcall(a, b, c) {
168
+ var d = lua_tableget(a, b);
169
+ if (null == d)
170
+ throw Error("attempt to call method '" + b + "' (a nil value)");
171
+ return lua_call(d, [a].concat(c));
172
+ }
173
+ function lua_eq(a, b) {
174
+ if (typeof a != typeof b) return null == a && null == b ? !0 : !1;
175
+ if (a == b) return !0;
176
+ if (null == a || null == b) return !1;
177
+ var c = a.metatable && a.metatable.str.__eq;
178
+ return c && c == (b.metatable && b.metatable.str.__eq)
179
+ ? lua_true(lua_rawcall(c, [a, b])[0])
180
+ : !1;
181
+ }
182
+ function lua_lt(a, b) {
183
+ if (
184
+ ("number" == typeof a && "number" == typeof b) ||
185
+ ("string" == typeof a && "string" == typeof b)
186
+ )
187
+ return a < b;
188
+ var c = a.metatable && a.metatable.str.__lt;
189
+ if (c && c == (b.metatable && b.metatable.str.__lt))
190
+ return lua_true(lua_rawcall(c, [a, b])[0]);
191
+ throw Error("Unable to compare " + a + " and " + b);
192
+ }
193
+ function lua_lte(a, b) {
194
+ if (
195
+ ("number" == typeof a && "number" == typeof b) ||
196
+ ("string" == typeof a && "string" == typeof b)
197
+ )
198
+ return a <= b;
199
+ var c = a.metatable && a.metatable.str.__le;
200
+ if (c && c == (b.metatable && b.metatable.str.__le))
201
+ return lua_true(lua_rawcall(c, [a, b])[0]);
202
+ if (
203
+ (c = a.metatable && a.metatable.str.__lt) &&
204
+ c == (b.metatable && b.metatable.str.__lt)
205
+ )
206
+ return lua_not(lua_rawcall(c, [b, a])[0]);
207
+ throw Error("Unable to compare " + a + " and " + b);
208
+ }
209
+ function lua_unm(a) {
210
+ var b = parseFloat(a);
211
+ if (isNaN(b)) {
212
+ if ((b = a.metatable && a.metatable.str.__unm))
213
+ return lua_rawcall(b, [a])[0];
214
+ throw Error("Inverting <" + a + "> not supported");
215
+ }
216
+ return -b;
217
+ }
218
+ function lua_add(a, b) {
219
+ var c = parseFloat(a),
220
+ d = parseFloat(b);
221
+ if (isNaN(c) || isNaN(d)) {
222
+ if (
223
+ (c =
224
+ (a.metatable && a.metatable.str.__add) ||
225
+ (b.metatable && b.metatable.str.__add))
226
+ )
227
+ return lua_rawcall(c, [a, b])[0];
228
+ throw Error("Adding <" + a + "> and <" + b + "> not supported");
229
+ }
230
+ return c + d;
231
+ }
232
+ function lua_subtract(a, b) {
233
+ var c = parseFloat(a),
234
+ d = parseFloat(b);
235
+ if (isNaN(c) || isNaN(d)) {
236
+ if (
237
+ (c =
238
+ (a.metatable && a.metatable.str.__sub) ||
239
+ (b.metatable && b.metatable.str.__sub))
240
+ )
241
+ return lua_rawcall(c, [a, b])[0];
242
+ throw Error("Subtracting <" + a + "> and <" + b + "> not supported");
243
+ }
244
+ return c - d;
245
+ }
246
+ function lua_divide(a, b) {
247
+ var c = parseFloat(a),
248
+ d = parseFloat(b);
249
+ if (isNaN(c) || isNaN(d)) {
250
+ if (
251
+ (c =
252
+ (a.metatable && a.metatable.str.__div) ||
253
+ (b.metatable && b.metatable.str.__div))
254
+ )
255
+ return lua_rawcall(c, [a, b])[0];
256
+ throw Error("Dividing <" + a + "> and <" + b + "> not supported");
257
+ }
258
+ return c / d;
259
+ }
260
+ function lua_multiply(a, b) {
261
+ var c = parseFloat(a),
262
+ d = parseFloat(b);
263
+ if (isNaN(c) || isNaN(d)) {
264
+ if (
265
+ (c =
266
+ (a.metatable && a.metatable.str.__mul) ||
267
+ (b.metatable && b.metatable.str.__mul))
268
+ )
269
+ return lua_rawcall(c, [a, b])[0];
270
+ throw Error("Multiplying <" + a + "> and <" + b + "> not supported");
271
+ }
272
+ return c * d;
273
+ }
274
+ function lua_power(a, b) {
275
+ var c = parseFloat(a),
276
+ d = parseFloat(b);
277
+ if (isNaN(c) || isNaN(d)) {
278
+ if (
279
+ (c =
280
+ (a.metatable && a.metatable.str.__pow) ||
281
+ (b.metatable && b.metatable.str.__pow))
282
+ )
283
+ return lua_rawcall(c, [a, b])[0];
284
+ throw Error("<" + a + "> to the power of <" + b + "> not supported");
285
+ }
286
+ return Math.pow(c, d);
287
+ }
288
+ function lua_mod(a, b) {
289
+ var c = parseFloat(a),
290
+ d = parseFloat(b);
291
+ if (isNaN(c) || isNaN(d)) {
292
+ if (
293
+ (c =
294
+ (a.metatable && a.metatable.str.__mod) ||
295
+ (b.metatable && b.metatable.str.__mod))
296
+ )
297
+ return lua_rawcall(c, [a, b])[0];
298
+ throw Error("Modulo <" + a + "> and <" + b + "> not supported");
299
+ }
300
+ return 0 <= c
301
+ ? 0 <= d
302
+ ? c % d
303
+ : (d + (c % d)) % d
304
+ : 0 <= d
305
+ ? (d + (c % d)) % d
306
+ : c % d;
307
+ }
308
+ function lua_rawget(a, b) {
309
+ switch (typeof b) {
310
+ case "string":
311
+ return a.str[b];
312
+ case "number":
313
+ if (b != b) throw Error("Table index is NaN");
314
+ return 0 < b && (b | 0) == b
315
+ ? a.arraymode
316
+ ? a.uints[b - 1]
317
+ : a.uints[b]
318
+ : a.floats[b];
319
+ case "boolean":
320
+ return a.bool[b];
321
+ case "object":
322
+ if (null == b) return null;
323
+ for (var c in a.objs) if (a.objs[c][0] == b) return a.objs[c][1];
324
+ break;
325
+ default:
326
+ throw Error("Unsupported key for table: " + typeof b);
327
+ }
328
+ }
329
+ function lua_rawset(a, b, c) {
330
+ delete a.length;
331
+ switch (typeof b) {
332
+ case "string":
333
+ null == c ? delete a.str[b] : (a.str[b] = c);
334
+ break;
335
+ case "number":
336
+ if (b != b) throw Error("Table index is NaN");
337
+ 0 < b && (b | 0) == b
338
+ ? (ensure_notarraymode(a),
339
+ null == c ? delete a.uints[b] : (a.uints[b] = c))
340
+ : null == c
341
+ ? delete a.floats[b]
342
+ : (a.floats[b] = c);
343
+ break;
344
+ case "boolean":
345
+ null == c ? delete a.bool[b] : (a.bool[b] = c);
346
+ break;
347
+ case "object":
348
+ if (null == b) throw Error("Table index is nil");
349
+ var d = !1,
350
+ e;
351
+ for (e in a.objs)
352
+ if (a.objs[e][0] == b) {
353
+ null == c ? a.objs.splice(e, 1) : ((d = !0), (a.objs[e][1] = c));
354
+ break;
355
+ }
356
+ d || a.objs.push([b, c]);
357
+ break;
358
+ default:
359
+ throw Error("Unsupported key for table: " + typeof b);
360
+ }
361
+ }
362
+ function lua_tableget(a, b) {
363
+ if (null == a)
364
+ throw Error("attempt to index field '" + b + "' in a nil value");
365
+ if ("object" == typeof a) {
366
+ var c = lua_rawget(a, b);
367
+ if (null != c) return c;
368
+ c = a.metatable && a.metatable.str.__index;
369
+ if (null == c) return null;
370
+ } else if (((c = a.metatable && a.metatable.str.__index), null == c))
371
+ throw Error("Unable to index key " + b + " from " + a);
372
+ return "function" == typeof c
373
+ ? lua_rawcall(c, [a, b])[0]
374
+ : lua_tableget(c, b);
375
+ }
376
+ function lua_tableset(a, b, c) {
377
+ if (null == a) throw Error("attempt to set field '" + b + "' in a nil value");
378
+ if ("object" == typeof a) {
379
+ if (null != lua_rawget(a, b)) {
380
+ lua_rawset(a, b, c);
381
+ return;
382
+ }
383
+ var d = a.metatable && a.metatable.str.__newindex;
384
+ if (null == d) {
385
+ lua_rawset(a, b, c);
386
+ return;
387
+ }
388
+ } else if (((d = a.metatable && a.metatable.str.__newindex), null == d))
389
+ throw Error("Unable to set key " + b + " in table " + a);
390
+ "function" == typeof d ? lua_rawcall(d, [a, b, c]) : lua_tableset(d, b, c);
391
+ }
392
+ function lua_concat(a, b) {
393
+ if ("number" == typeof a && "number" == typeof b)
394
+ throw Error("number concat not supported yet");
395
+ if (
396
+ ("string" == typeof a || "number" == typeof a) &&
397
+ ("string" == typeof b || "number" == typeof b)
398
+ )
399
+ return a + b;
400
+ var c =
401
+ (a.metatable && a.metatable.str.__concat) ||
402
+ (b.metatable && b.metatable.str.__concat);
403
+ if (c) return lua_rawcall(c, [a, b])[0];
404
+ throw Error("Unable to concat " + a + " and " + b);
405
+ }
406
+ function _ipairs_next(a, b) {
407
+ var c;
408
+ c = a.arraymode ? a.uints[b] : a.uints[b + 1];
409
+ return null == c ? [null, null] : [b + 1, c];
410
+ }
411
+ var lua_libs = {},
412
+ lua_core = {
413
+ assert: function (a, b) {
414
+ 1 > arguments.length && (b = "assertion failed!");
415
+ if (null != a && !1 !== a) return [a];
416
+ throw Error(b);
417
+ },
418
+ collectgarbage: function () {},
419
+ dofile: function () {
420
+ not_supported();
421
+ },
422
+ error: function (a) {
423
+ throw Error(a);
424
+ },
425
+ getfenv: function () {
426
+ not_supported();
427
+ },
428
+ getmetatable: function (a) {
429
+ return [a.metatable && (a.metatable.str.__metatable || a.metatable)];
430
+ },
431
+ ipairs: function (a) {
432
+ return [_ipairs_next, a, 0];
433
+ },
434
+ load: function (a, b) {
435
+ for (var c = "", d; null != (d = a()) && "" != d; ) c += d;
436
+ try {
437
+ return [lua_load(c, b)];
438
+ } catch (e) {
439
+ return [null, e.message];
440
+ }
441
+ },
442
+ loadfile: function () {
443
+ not_supported();
444
+ },
445
+ loadstring: function (a, b) {
446
+ try {
447
+ return [lua_load(a, b)];
448
+ } catch (c) {
449
+ return [null, c.message];
450
+ }
451
+ },
452
+ next: function () {
453
+ not_supported();
454
+ },
455
+ pairs: function (a) {
456
+ var b = [],
457
+ c;
458
+ for (c in a.str) b.push(c);
459
+ if (a.arraymode)
460
+ for (var d = a.uints.length; 0 < d--; )
461
+ null != a.uints[d] && b.push(d + 1);
462
+ else for (c in a.uints) b.push(parseFloat(c));
463
+ for (c in a.floats) b.push(parseFloat(c));
464
+ for (c in a.bool) b.push("true" === c ? !0 : !1);
465
+ for (c in a.objs) b.push(a.objs[c][0]);
466
+ c = 0;
467
+ return [
468
+ function (a, d) {
469
+ var g;
470
+ do {
471
+ if (c >= b.length) return [null, null];
472
+ d = b[c++];
473
+ g = lua_rawget(a, d);
474
+ } while (null == g);
475
+ return [d, g];
476
+ },
477
+ a,
478
+ null,
479
+ ];
480
+ },
481
+ pcall: function (a) {
482
+ try {
483
+ return [!0].concat(a.apply(null, slice(arguments, 1)));
484
+ } catch (b) {
485
+ return [!1, b.message];
486
+ }
487
+ },
488
+ print: lua_print,
489
+ rawequal: function (a, b) {
490
+ return [a == b || (null == a && null == b)];
491
+ },
492
+ rawget: function (a, b) {
493
+ if ("object" == typeof a && null != a) return [lua_rawget(a, b)];
494
+ throw Error("Unable to index key " + b + " from " + a);
495
+ },
496
+ rawset: function (a, b, c) {
497
+ if ("object" == typeof a && null != a && null != b)
498
+ return lua_rawset(a, b, c), [a];
499
+ throw Error("Unable set key " + b + " in " + a);
500
+ },
501
+ select: function (a) {
502
+ if ("#" === a) return [arguments.length - 1];
503
+ a = lua_assertfloat(a);
504
+ if (1 <= a) return slice(arguments, lua_assertfloat(a));
505
+ throw Error("Index out of range");
506
+ },
507
+ setfenv: function () {
508
+ not_supported();
509
+ },
510
+ setmetatable: function (a, b) {
511
+ if ("object" != typeof a || null == a)
512
+ throw Error("table expected, got " + a);
513
+ if (null == b) delete a.metatable;
514
+ else if ("object" === typeof b) a.metatable = b;
515
+ else throw Error("table or nil expected, got " + b);
516
+ return [a];
517
+ },
518
+ tonumber: function (a, b) {
519
+ return "number" == typeof a
520
+ ? [a]
521
+ : 10 === b || null == b
522
+ ? [parseFloat(a)]
523
+ : [parseInt(a, b)];
524
+ },
525
+ tostring: function (a) {
526
+ if (null == a) return ["nil"];
527
+ var b = a.metatable && a.metatable.str.__tostring;
528
+ if (b) return lua_rawcall(b, [a]);
529
+ switch (typeof a) {
530
+ case "number":
531
+ case "boolean":
532
+ return [a.toString()];
533
+ case "string":
534
+ return [a];
535
+ case "object":
536
+ return ["table"];
537
+ case "function":
538
+ return ["function"];
539
+ default:
540
+ return ["nil"];
541
+ }
542
+ },
543
+ type: function (a) {
544
+ switch (typeof a) {
545
+ case "number":
546
+ return ["number"];
547
+ case "string":
548
+ return ["string"];
549
+ case "boolean":
550
+ return ["boolean"];
551
+ case "function":
552
+ return ["function"];
553
+ case "object":
554
+ return [null === a ? "nil" : "table"];
555
+ case "undefined":
556
+ return ["nil"];
557
+ default:
558
+ throw Error("Unepected value of type " + typeof a);
559
+ }
560
+ },
561
+ unpack: function (a, b, c) {
562
+ ensure_arraymode(a);
563
+ if (null != a.length) c = a.length;
564
+ else {
565
+ for (c = 0; null != a.uints[c++]; );
566
+ a.length = --c;
567
+ }
568
+ if (null == b || 1 > b) b = 1;
569
+ null == c && (c = a.length);
570
+ throw new ReturnValues(a.uints.slice(b - 1, c));
571
+ },
572
+ _VERSION: "Lua 5.1",
573
+ xpcall: function () {
574
+ not_supported();
575
+ },
576
+ },
577
+ _lua_coroutine = (lua_libs.coroutine = {});
578
+ _lua_coroutine.resume =
579
+ _lua_coroutine.running =
580
+ _lua_coroutine.status =
581
+ _lua_coroutine.wrap =
582
+ _lua_coroutine.yield =
583
+ _lua_coroutine.create =
584
+ function () {
585
+ not_supported();
586
+ };
587
+ var _lua_debug = (lua_libs.debug = {
588
+ getmetatable: function (a) {
589
+ return [a.metatable];
590
+ },
591
+ });
592
+ _lua_debug.traceback =
593
+ _lua_debug.getfenv =
594
+ _lua_debug.gethook =
595
+ _lua_debug.getinfo =
596
+ _lua_debug.getlocal =
597
+ _lua_debug.getregistry =
598
+ _lua_debug.getupvalue =
599
+ _lua_debug.setfenv =
600
+ _lua_debug.sethook =
601
+ _lua_debug.setlocal =
602
+ _lua_debug.setupvalue =
603
+ _lua_debug.debug =
604
+ function () {
605
+ not_supported();
606
+ };
607
+ var _lua_write_buffer = "",
608
+ _lua_io = (lua_libs.io = {
609
+ write: function () {
610
+ _lua_write_buffer += Array.prototype.join.call(arguments, "");
611
+ for (var a = _lua_write_buffer.split("\n"); 1 < a.length; )
612
+ _lua_print(a.shift());
613
+ _lua_write_buffer = a[0];
614
+ return [];
615
+ },
616
+ flush: function () {},
617
+ stderr: null,
618
+ stdin: null,
619
+ stdout: null,
620
+ });
621
+ _lua_io.close =
622
+ _lua_io.input =
623
+ _lua_io.lines =
624
+ _lua_io.output =
625
+ _lua_io.popen =
626
+ _lua_io.read =
627
+ _lua_io.tmpfile =
628
+ _lua_io.type =
629
+ _lua_io.open =
630
+ function () {
631
+ not_supported();
632
+ };
633
+ var _lua_randmax = 4294967296,
634
+ _lua_randseed = (Math.random() * _lua_randmax) & (_lua_randmax - 1);
635
+ lua_libs.math = {
636
+ abs: function (a) {
637
+ return [Math.abs(a)];
638
+ },
639
+ acos: function (a) {
640
+ return [Math.acos(a)];
641
+ },
642
+ asin: function (a) {
643
+ return [Math.asin(a)];
644
+ },
645
+ atan: function (a) {
646
+ return [Math.atan(a)];
647
+ },
648
+ atan2: function (a, b) {
649
+ return [Math.atan2(a, b)];
650
+ },
651
+ ceil: function (a) {
652
+ return [Math.ceil(a)];
653
+ },
654
+ cos: function (a) {
655
+ return [Math.cos(a)];
656
+ },
657
+ cosh: function (a) {
658
+ return [(Math.exp(a) + Math.exp(-a)) / 2];
659
+ },
660
+ deg: function (a) {
661
+ return [a * (180 / Math.PI)];
662
+ },
663
+ exp: function (a) {
664
+ return [Math.exp(a)];
665
+ },
666
+ floor: function (a) {
667
+ return [Math.floor(a)];
668
+ },
669
+ fmod: function (a, b) {
670
+ return [a % b];
671
+ },
672
+ frexp: function () {
673
+ not_supported();
674
+ },
675
+ huge: Infinity,
676
+ ldexp: function (a, b) {
677
+ return [a * Math.pow(2, b)];
678
+ },
679
+ log: function (a) {
680
+ return [Math.log(a)];
681
+ },
682
+ log10: function (a) {
683
+ return [Math.log(a) / Math.LN10];
684
+ },
685
+ max: function () {
686
+ return [Math.max.apply(null, arguments)];
687
+ },
688
+ min: function () {
689
+ return [Math.min.apply(null, arguments)];
690
+ },
691
+ modf: function (a) {
692
+ var b = a % 1;
693
+ return [a - b, b];
694
+ },
695
+ pi: Math.PI,
696
+ pow: function (a, b) {
697
+ return [Math.pow(a, b)];
698
+ },
699
+ rad: function (a) {
700
+ return [a * (Math.PI / 180)];
701
+ },
702
+ sin: function (a) {
703
+ return [Math.sin(a)];
704
+ },
705
+ sinh: function (a) {
706
+ return [(Math.exp(a) - Math.exp(-a)) / 2];
707
+ },
708
+ sqrt: function (a) {
709
+ return [Math.sqrt(a)];
710
+ },
711
+ tan: function (a) {
712
+ return [Math.tan(a)];
713
+ },
714
+ tanh: function (a) {
715
+ var b = Math.exp(a),
716
+ a = Math.exp(-a);
717
+ return [(b - a) / (b + a)];
718
+ },
719
+ random: function (a, b) {
720
+ _lua_randseed = ~_lua_randseed + (_lua_randseed << 15);
721
+ _lua_randseed ^= _lua_randseed >>> 12;
722
+ _lua_randseed += _lua_randseed << 2;
723
+ _lua_randseed ^= _lua_randseed >>> 4;
724
+ _lua_randseed *= 2057;
725
+ _lua_randseed ^= _lua_randseed >>> 16;
726
+ var c;
727
+ c =
728
+ 0 > _lua_randseed
729
+ ? ((_lua_randseed + _lua_randmax) / _lua_randmax) % 1
730
+ : (_lua_randseed / _lua_randmax) % 1;
731
+ if (2 <= arguments.length) {
732
+ a |= 0;
733
+ b |= 0;
734
+ if (a >= b) throw Error("Invalid range");
735
+ return [Math.floor(c * (b - a + 1) + a)];
736
+ }
737
+ return 1 == arguments.length ? [Math.floor(c * (a | 0) + 1)] : [c];
738
+ },
739
+ randomseed: function (a) {
740
+ _lua_randseed = a & (_lua_randmax - 1);
741
+ },
742
+ };
743
+ var _lua_clock_start = new Date().getTime() / 1e3;
744
+ lua_libs.os = {
745
+ clock: function () {
746
+ return [new Date().getTime() / 1e3 - _lua_clock_script];
747
+ },
748
+ date: function (a, b) {
749
+ return ["[" + b + "]" + a];
750
+ },
751
+ difftime: function (a, b) {
752
+ return [a - b];
753
+ },
754
+ execute: function () {
755
+ return 0;
756
+ },
757
+ exit: function () {
758
+ not_supported();
759
+ },
760
+ getenv: function () {
761
+ return [null];
762
+ },
763
+ remove: function () {
764
+ not_supported();
765
+ },
766
+ rename: function () {
767
+ not_supported();
768
+ },
769
+ setlocale: function () {
770
+ not_supported();
771
+ },
772
+ time: function (a) {
773
+ if (a) not_supported();
774
+ else return [Math.floor(new Date().getTime() / 1e3)];
775
+ },
776
+ };
777
+ var lua_packages = lua_newtable();
778
+ function lua_createmodule(a, b, c) {
779
+ var d = lua_tableget(lua_packages, b) || lua_tableget(a, b) || lua_newtable();
780
+ lua_tableset(a, b, d);
781
+ lua_tableset(lua_packages, b, d);
782
+ lua_tableset(d, "_NAME", b);
783
+ lua_tableset(d, "_M", d);
784
+ lua_tableset(d, "_PACKAGE", b.split(".").slice(0, -1).join("."));
785
+ for (a = 0; a < c.length; a++) lua_call(c[a], [d]);
786
+ return d;
787
+ }
788
+ function lua_module(a) {
789
+ var b = lua_tableget(lua_packages, a);
790
+ if (null == b)
791
+ throw Error(
792
+ "Module " + a + " not found. Module must be loaded before use.",
793
+ );
794
+ return b;
795
+ }
796
+ function lua_require(a, b) {
797
+ for (
798
+ var c = lua_module(b), d = a, e = b.split("."), f = 0;
799
+ f < e.length - 1;
800
+ f++
801
+ )
802
+ if (!lua_tableget(d, e[f])) {
803
+ var g = lua_newtable();
804
+ lua_tableset(d, e[f], g);
805
+ d = g;
806
+ }
807
+ lua_tableset(d, e[e.length - 1], c);
808
+ return c;
809
+ }
810
+ lua_libs["package"] = {
811
+ path: "",
812
+ cpath: "",
813
+ loaded: lua_packages,
814
+ loaders: lua_newtable(),
815
+ preload: lua_newtable(),
816
+ loadlib: function () {
817
+ not_supported();
818
+ },
819
+ };
820
+ lua_libs.string = {
821
+ byte: function (a, b, c) {
822
+ null == b && (b = 0);
823
+ null == c && (c = b);
824
+ for (var d = []; b < c && b < a.length; ) d.push(a.charCodeAt(b));
825
+ return d;
826
+ },
827
+ char: function () {
828
+ return [String.fromCharCode.apply(null, arguments)];
829
+ },
830
+ dump: function () {
831
+ not_supported();
832
+ },
833
+ find: function () {
834
+ not_supported();
835
+ },
836
+ format: function (a) {
837
+ return ["[" + slice(arguments, 1).join(", ") + "]" + arguments[0]];
838
+ },
839
+ gmatch: function () {
840
+ not_supported();
841
+ },
842
+ gsub: function () {
843
+ not_supported();
844
+ },
845
+ len: function (a) {
846
+ if ("string" == typeof a) return [a.length];
847
+ throw Error("Input not string");
848
+ },
849
+ lower: function (a) {
850
+ if ("string" == typeof a) return [a.toLowerCase()];
851
+ throw Error("Input not string");
852
+ },
853
+ match: function () {
854
+ not_supported();
855
+ },
856
+ rep: function (a, b) {
857
+ if ("string" == typeof a && "number" == typeof b) {
858
+ for (var c = []; 0 < b--; ) c.push(a);
859
+ return [c.join("")];
860
+ }
861
+ throw Error("Input not string and number");
862
+ },
863
+ reverse: function (a) {
864
+ if ("string" == typeof a) return [a.split("").reverse().join("")];
865
+ throw Error("Input not string");
866
+ },
867
+ sub: function (a, b, c) {
868
+ b = 0 > b ? b + a.length + 1 : 0 <= b ? b : 0;
869
+ null == c && (c = -1);
870
+ c = 0 > c ? c + a.length + 1 : 0 <= c ? c : 0;
871
+ 1 > b && (b = 1);
872
+ c > a.length && (c = a.length);
873
+ return b <= c ? [a.substr(b - 1, c - b + 1)] : [""];
874
+ },
875
+ upper: function (a) {
876
+ if ("string" == typeof a) return [a.toUpperCase()];
877
+ throw Error("Input not string");
878
+ },
879
+ };
880
+ String.prototype.metatable = lua_newtable(
881
+ null,
882
+ "__index",
883
+ lua_newtable2(lua_libs.string),
884
+ );
885
+ lua_libs.table = {
886
+ concat: function (a, b, c, d) {
887
+ ensure_arraymode(a);
888
+ null == b && (b = "");
889
+ return null != c
890
+ ? (null == d && (d = a.uints.length), [a.uints.slice(c - 1, d).join(b)])
891
+ : [a.uints.join(b)];
892
+ },
893
+ insert: function (a, b, c) {
894
+ ensure_arraymode(a);
895
+ 2 == arguments.length && ((c = b), (b = a.uints.length + 1));
896
+ a.uints.splice(b - 1, 0, c);
897
+ null != a.length && a.length++;
898
+ return [];
899
+ },
900
+ maxn: function (a) {
901
+ if (a.arraymode) return [a.uints.length];
902
+ var b = 0,
903
+ c;
904
+ for (c in a.uints) (a = parseFloat(c)), a > b && (b = a);
905
+ return [b];
906
+ },
907
+ remove: function (a, b) {
908
+ ensure_arraymode(a);
909
+ b = null == b ? a.uints.length : lua_assertfloat(b);
910
+ if (a.uints.length) {
911
+ var c = a.uints[b - 1];
912
+ a.uints.splice(b - 1, 1);
913
+ null != a.length && a.length--;
914
+ return [c];
915
+ }
916
+ return [];
917
+ },
918
+ sort: function (a, b) {
919
+ ensure_arraymode(a);
920
+ b
921
+ ? a.uints.sort(function (a, d) {
922
+ return b(a, d)[0] ? -1 : 1;
923
+ })
924
+ : a.uints.sort(function (a, b) {
925
+ return lua_lt(a, b) ? -1 : 1;
926
+ });
927
+ return [];
928
+ },
929
+ };
930
+ lua_libs.bit = {
931
+ tobit: function (a) {
932
+ return [a << 0];
933
+ },
934
+ tohex: function (a, b) {
935
+ if (0 < b) {
936
+ for (var c = a.toString(16).substr(-b); c.length < b; ) c = "0" + c;
937
+ return [c];
938
+ }
939
+ if (0 > b) {
940
+ for (c = a.toString(16).substr(b).toUpperCase(); c.length < -b; )
941
+ c = "0" + c;
942
+ return [c];
943
+ }
944
+ return [a.toString(16)];
945
+ },
946
+ bnot: function (a) {
947
+ return [~a];
948
+ },
949
+ bor: function (a) {
950
+ for (var a = lua_assertfloat(a), b = 1; b < arguments.length; b++)
951
+ a |= arguments[b];
952
+ return [a];
953
+ },
954
+ band: function (a) {
955
+ for (var a = lua_assertfloat(a), b = 1; b < arguments.length; b++)
956
+ a &= arguments[b];
957
+ return [a];
958
+ },
959
+ bxor: function (a) {
960
+ for (var a = lua_assertfloat(a), b = 1; b < arguments.length; b++)
961
+ a ^= arguments[b];
962
+ return [a];
963
+ },
964
+ lshift: function (a, b) {
965
+ return [a << b];
966
+ },
967
+ rshift: function (a, b) {
968
+ return [a >>> b];
969
+ },
970
+ arshift: function (a, b) {
971
+ return [a >> b];
972
+ },
973
+ rol: function (a, b) {
974
+ b &= 15;
975
+ return [(a << b) | (a >>> -b)];
976
+ },
977
+ ror: function (a, b) {
978
+ b &= 15;
979
+ return [(a >>> b) | (a << -b)];
980
+ },
981
+ bswap: function (a) {
982
+ a = ((a >> 1) & 1431655765) | ((a & 1431655765) << 1);
983
+ a = ((a >> 2) & 858993459) | ((a & 858993459) << 2);
984
+ a = ((a >> 4) & 252645135) | ((a & 252645135) << 4);
985
+ a = ((a >> 8) & 16711935) | ((a & 16711935) << 8);
986
+ return [(a >> 16) | (a << 16)];
987
+ },
988
+ };
989
+
6
990
  var lua_script = (function () {
7
991
  var tmp;
8
992
  var G = lua_newtable2(lua_core);