(rawValue: unknown, userdata?: unknown)
| 185 | } |
| 186 | |
| 187 | public pushValue(rawValue: unknown, userdata?: unknown): void { |
| 188 | const decoratedValue = this.getValueDecorations(rawValue) |
| 189 | const target = decoratedValue.target |
| 190 | |
| 191 | if (target instanceof Thread) { |
| 192 | const isMain = this.lua.lua_pushthread(target.address) === 1 |
| 193 | if (!isMain) { |
| 194 | this.lua.lua_xmove(target.address, this.address, 1) |
| 195 | } |
| 196 | return |
| 197 | } |
| 198 | |
| 199 | const startTop = this.getTop() |
| 200 | |
| 201 | // Handle primitive types |
| 202 | switch (typeof target) { |
| 203 | case 'undefined': |
| 204 | this.lua.lua_pushnil(this.address) |
| 205 | break |
| 206 | case 'number': |
| 207 | if (Number.isInteger(target)) { |
| 208 | this.lua.lua_pushinteger(this.address, BigInt(target)) |
| 209 | } else { |
| 210 | this.lua.lua_pushnumber(this.address, target) |
| 211 | } |
| 212 | break |
| 213 | case 'string': |
| 214 | this.lua.lua_pushstring(this.address, target) |
| 215 | break |
| 216 | case 'boolean': |
| 217 | this.lua.lua_pushboolean(this.address, target ? 1 : 0) |
| 218 | break |
| 219 | default: |
| 220 | if (this.typeExtensions.find((wrapper) => wrapper.extension.pushValue(this, decoratedValue, userdata))) { |
| 221 | break |
| 222 | } |
| 223 | if (target === null) { |
| 224 | this.lua.lua_pushnil(this.address) |
| 225 | break |
| 226 | } |
| 227 | throw new Error(`The type '${typeof target}' is not supported by Lua`) |
| 228 | } |
| 229 | |
| 230 | if (decoratedValue.options.metatable) { |
| 231 | this.setMetatable(-1, decoratedValue.options.metatable) |
| 232 | } |
| 233 | |
| 234 | if (this.getTop() !== startTop + 1) { |
| 235 | throw new Error(`pushValue expected stack size ${startTop + 1}, got ${this.getTop()}`) |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | public setMetatable(index: number, metatable: Record<any, any>): void { |
| 240 | index = this.lua.lua_absindex(this.address, index) |
no test coverage detected