(index: number, inputType?: LuaType, userdata?: unknown)
| 269 | } |
| 270 | |
| 271 | public getValue(index: number, inputType?: LuaType, userdata?: unknown): any { |
| 272 | index = this.lua.lua_absindex(this.address, index) |
| 273 | |
| 274 | const type: LuaType = inputType ?? this.lua.lua_type(this.address, index) |
| 275 | |
| 276 | switch (type) { |
| 277 | case LuaType.None: |
| 278 | return undefined |
| 279 | case LuaType.Nil: |
| 280 | return null |
| 281 | case LuaType.Number: |
| 282 | return this.lua.lua_tonumberx(this.address, index, null) |
| 283 | case LuaType.String: |
| 284 | return this.lua.lua_tolstring(this.address, index, null) |
| 285 | case LuaType.Boolean: |
| 286 | return Boolean(this.lua.lua_toboolean(this.address, index)) |
| 287 | case LuaType.Thread: |
| 288 | return this.stateToThread(this.lua.lua_tothread(this.address, index)) |
| 289 | default: { |
| 290 | let metatableName: string | undefined |
| 291 | if (type === LuaType.Table || type === LuaType.Userdata) { |
| 292 | metatableName = this.getMetatableName(index) |
| 293 | } |
| 294 | |
| 295 | const typeExtensionWrapper = this.typeExtensions.find((wrapper) => |
| 296 | wrapper.extension.isType(this, index, type, metatableName), |
| 297 | ) |
| 298 | if (typeExtensionWrapper) { |
| 299 | return typeExtensionWrapper.extension.getValue(this, index, userdata) |
| 300 | } |
| 301 | |
| 302 | // Fallthrough if unrecognised user data |
| 303 | console.warn(`The type '${this.lua.lua_typename(this.address, type)}' returned is not supported on JS`) |
| 304 | return new Pointer(this.lua.lua_topointer(this.address, index)) |
| 305 | } |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | public close(): void { |
| 310 | if (this.isClosed()) { |
no test coverage detected