(
private cmodule: LuaWasm,
{
openStandardLibs = true,
injectObjects = false,
enableProxy = true,
traceAllocations = false,
functionTimeout = undefined as number | undefined,
}: CreateEngineOptions = {},
)
| 14 | public global: Global |
| 15 | |
| 16 | public constructor( |
| 17 | private cmodule: LuaWasm, |
| 18 | { |
| 19 | openStandardLibs = true, |
| 20 | injectObjects = false, |
| 21 | enableProxy = true, |
| 22 | traceAllocations = false, |
| 23 | functionTimeout = undefined as number | undefined, |
| 24 | }: CreateEngineOptions = {}, |
| 25 | ) { |
| 26 | this.global = new Global(this.cmodule, traceAllocations) |
| 27 | |
| 28 | // Generic handlers - These may be required to be registered for additional types. |
| 29 | this.global.registerTypeExtension(0, createTableType(this.global)) |
| 30 | this.global.registerTypeExtension(0, createFunctionType(this.global, { functionTimeout })) |
| 31 | |
| 32 | // Contains the :await functionality. |
| 33 | this.global.registerTypeExtension(1, createPromiseType(this.global, injectObjects)) |
| 34 | |
| 35 | if (injectObjects) { |
| 36 | // Should be higher priority than table since that catches generic objects along |
| 37 | // with userdata so it doesn't end up a userdata type. |
| 38 | this.global.registerTypeExtension(5, createNullType(this.global)) |
| 39 | } |
| 40 | |
| 41 | if (enableProxy) { |
| 42 | // This extension only really overrides tables and arrays. |
| 43 | // When a function is looked up in one of it's tables it's bound and then |
| 44 | // handled by the function type extension. |
| 45 | this.global.registerTypeExtension(3, createProxyType(this.global)) |
| 46 | } else { |
| 47 | // No need to register this when the proxy is enabled. |
| 48 | this.global.registerTypeExtension(1, createErrorType(this.global, injectObjects)) |
| 49 | } |
| 50 | |
| 51 | // Higher priority than proxied objects to allow custom user data without exposing methods. |
| 52 | this.global.registerTypeExtension(4, createUserdataType(this.global)) |
| 53 | |
| 54 | if (openStandardLibs) { |
| 55 | this.cmodule.luaL_openlibs(this.global.address) |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Executes Lua code from a string asynchronously. |
nothing calls this directly
no test coverage detected