|
19 | 19 | getModifierKey |
20 | 20 | isInside |
21 | 21 | limitArray, areArraysEqual |
22 | | - log |
| 22 | + log, logNoTimestamp |
23 | 23 | newMonochromeImage, newImageUsingPalette |
24 | 24 | pcall_newImage, pcall_newShader |
25 | 25 | prepareSandbox |
@@ -313,14 +313,20 @@ export trim :: (s:string) -> string { |
313 | 313 | export prepareSandbox :: (globals:table) -> (env:table) { |
314 | 314 | local setMetatable :: (t:table, metatable:table) -> table !foreign lua "setmetatable" |
315 | 315 |
|
316 | | - local indexTable: table = { |
| 316 | + local sandboxPrint :: (...:any) { |
| 317 | + local values :: []string.{} |
| 318 | + for ... values[itIndex] = toString(it) |
| 319 | + logNoTimestamp(concatenate(values, "\t", 1, #...)) |
| 320 | + } |
| 321 | + |
| 322 | + local indexTable = table.{ |
317 | 323 | _VERSION = cast(any) !foreign lua "_VERSION", |
318 | 324 | assert = cast(any) !foreign lua "assert", |
319 | 325 | error = cast(any) !foreign lua "error", |
320 | 326 | ipairs = cast(any) !foreign lua "ipairs", |
321 | 327 | next = cast(any) !foreign lua "next", |
322 | 328 | pairs = cast(any) !foreign lua "pairs", |
323 | | - print = cast(any) !foreign lua "print", |
| 329 | + print = sandboxPrint, |
324 | 330 | select = cast(any) !foreign lua "select", |
325 | 331 | tonumber = cast(any) !foreign lua "tonumber", |
326 | 332 | tostring = cast(any) !foreign lua "tostring", |
@@ -401,7 +407,7 @@ export prepareSandbox :: (globals:table) -> (env:table) { |
401 | 407 | for globals indexTable[itIndex] = it |
402 | 408 |
|
403 | 409 | setMetatable(env, { |
404 | | - __newindex = (templateEnv:table, k:any, v:any) { |
| 410 | + __newindex = (templateEnv:table, k,v:any) { |
405 | 411 | errorf(2, "cannot add global '%s' (globals are disabled)", toString(k)) |
406 | 412 | }, |
407 | 413 | __index = indexTable, |
@@ -455,10 +461,18 @@ export log :: (s:string) { |
455 | 461 | insert(logStrings, os.getDate"[%H:%M:%S] "..s) |
456 | 462 | print(s) |
457 | 463 | } |
| 464 | +export logNoTimestamp :: (s:string) { |
| 465 | + if logStrings[LOG_MAX_ENTRIES] ~= NULL remove(logStrings, 1) |
| 466 | + insert(logStrings, s) |
| 467 | + print(s) |
| 468 | +} |
458 | 469 |
|
459 | 470 | export log :: (s:string, v,...:int|float|string|Type) { |
460 | 471 | log(format(s, v, ...)) |
461 | 472 | } |
| 473 | +export logNoTimestamp :: (s:string, v,...:int|float|string|Type) { |
| 474 | + logNoTimestamp(format(s, v, ...)) |
| 475 | +} |
462 | 476 |
|
463 | 477 |
|
464 | 478 |
|
|
0 commit comments