diff --git a/src/engine.ts b/src/engine.ts index 4800940..f8875e2 100755 --- a/src/engine.ts +++ b/src/engine.ts @@ -31,9 +31,11 @@ export default class LuaEngine { // Contains the :await functionality. this.global.registerTypeExtension(1, createPromiseType(this.global, injectObjects)) - // Should be higher priority than table since that catches generic objects along - // with userdata so it doesn't end up a userdata type. - this.global.registerTypeExtension(5, createNullType(this.global, injectObjects)) + if (injectObjects) { + // Should be higher priority than table since that catches generic objects along + // with userdata so it doesn't end up a userdata type. + this.global.registerTypeExtension(5, createNullType(this.global)) + } if (enableProxy) { // This extension only really overrides tables and arrays. diff --git a/src/type-extensions/default-null.ts b/src/type-extensions/default-null.ts deleted file mode 100644 index 405fe61..0000000 --- a/src/type-extensions/default-null.ts +++ /dev/null @@ -1,25 +0,0 @@ -import Global from '../global' -import Thread from '../thread' -import TypeExtension from '../type-extension' - -// A default extension that treats js null as lua nil -class DefaultNullTypeExtension extends TypeExtension { - constructor(thread: Global) { - super(thread, 'js_null') - } - public getValue(): null { - throw new Error('nil values should be converted by pushValue') - } - public pushValue(thread: Thread, decoration: any): boolean { - if (decoration?.target !== null) { - return false - } - thread.lua.lua_pushnil(thread.address) - return true - } - public close(): void {} -} - -export default function createTypeExtension(thread: Global): TypeExtension { - return new DefaultNullTypeExtension(thread) -} diff --git a/src/type-extensions/null.ts b/src/type-extensions/null.ts index 9ce3273..7f95a73 100644 --- a/src/type-extensions/null.ts +++ b/src/type-extensions/null.ts @@ -3,7 +3,6 @@ import { LuaReturn, LuaState } from '../types' import Global from '../global' import Thread from '../thread' import TypeExtension from '../type-extension' -import createDefaultNullType from './default-null' class NullTypeExtension extends TypeExtension { private gcPointer: number @@ -74,9 +73,6 @@ class NullTypeExtension extends TypeExtension { } } -export default function createTypeExtension(thread: Global, userDataType: boolean): TypeExtension { - if (userDataType) { - return new NullTypeExtension(thread) - } - return createDefaultNullType(thread) +export default function createTypeExtension(thread: Global): TypeExtension { + return new NullTypeExtension(thread) } diff --git a/src/type-extensions/table.ts b/src/type-extensions/table.ts index a9f302e..6fe0389 100644 --- a/src/type-extensions/table.ts +++ b/src/type-extensions/table.ts @@ -39,9 +39,13 @@ class TableTypeExtension extends TypeExtension { } public pushValue(thread: Thread, { target }: Decoration, userdata?: Map): boolean { - if (typeof target !== 'object' || target === null) { + if (typeof target !== 'object') { return false } + if (target === null) { + thread.lua.lua_pushnil(thread.address) + return true + } // This is a map of JS objects to luaL references. const seenMap = userdata || new Map()