Skip to content

Commit

Permalink
Lower the priority of default null handler
Browse files Browse the repository at this point in the history
  • Loading branch information
gudzpoz committed Apr 3, 2024
1 parent d7e2ff0 commit 3704bc6
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 35 deletions.
8 changes: 5 additions & 3 deletions src/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
25 changes: 0 additions & 25 deletions src/type-extensions/default-null.ts

This file was deleted.

8 changes: 2 additions & 6 deletions src/type-extensions/null.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<unknown> {
private gcPointer: number
Expand Down Expand Up @@ -74,9 +73,6 @@ class NullTypeExtension extends TypeExtension<unknown> {
}
}

export default function createTypeExtension(thread: Global, userDataType: boolean): TypeExtension<null> {
if (userDataType) {
return new NullTypeExtension(thread)
}
return createDefaultNullType(thread)
export default function createTypeExtension(thread: Global): TypeExtension<null> {
return new NullTypeExtension(thread)
}
6 changes: 5 additions & 1 deletion src/type-extensions/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,13 @@ class TableTypeExtension extends TypeExtension<TableType> {
}

public pushValue(thread: Thread, { target }: Decoration<TableType>, userdata?: Map<any, number>): 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<any, number>()
Expand Down

0 comments on commit 3704bc6

Please sign in to comment.