Comparing version 1.15.1 to 1.16.0
@@ -6,3 +6,3 @@ import Global from './global'; | ||
global: Global; | ||
constructor(cmodule: LuaWasm, { openStandardLibs, injectObjects, enableProxy, traceAllocations }?: { | ||
constructor(cmodule: LuaWasm, { openStandardLibs, injectObjects, enableProxy, traceAllocations, functionTimeout, }?: { | ||
openStandardLibs?: boolean | undefined; | ||
@@ -12,2 +12,3 @@ injectObjects?: boolean | undefined; | ||
traceAllocations?: boolean | undefined; | ||
functionTimeout?: number | undefined; | ||
}); | ||
@@ -14,0 +15,0 @@ doString(script: string): Promise<any>; |
@@ -84,3 +84,3 @@ /// <reference types="emscripten" /> | ||
lua_tonumberx: (L: LuaState, idx: number, isnum: number | null) => number; | ||
lua_tointegerx: (L: LuaState, idx: number, isnum: number | null) => number; | ||
lua_tointegerx: (L: LuaState, idx: number, isnum: number | null) => bigint; | ||
lua_toboolean: (L: LuaState, idx: number) => number; | ||
@@ -98,3 +98,3 @@ lua_tolstring: (L: LuaState, idx: number, len: number | null) => string; | ||
lua_pushnumber: (L: LuaState, n: number) => void; | ||
lua_pushinteger: (L: LuaState, n: number) => void; | ||
lua_pushinteger: (L: LuaState, n: bigint) => void; | ||
lua_pushlstring: (L: LuaState, s: string | number | null, len: number) => string; | ||
@@ -109,5 +109,5 @@ lua_pushstring: (L: LuaState, s: string | number | null) => string; | ||
lua_getfield: (L: LuaState, idx: number, k: string | null) => LuaType; | ||
lua_geti: (L: LuaState, idx: number, n: number) => LuaType; | ||
lua_geti: (L: LuaState, idx: number, n: bigint) => LuaType; | ||
lua_rawget: (L: LuaState, idx: number) => number; | ||
lua_rawgeti: (L: LuaState, idx: number, n: number) => LuaType; | ||
lua_rawgeti: (L: LuaState, idx: number, n: bigint) => LuaType; | ||
lua_rawgetp: (L: LuaState, idx: number, p: number | null) => LuaType; | ||
@@ -121,5 +121,5 @@ lua_createtable: (L: LuaState, narr: number, nrec: number) => void; | ||
lua_setfield: (L: LuaState, idx: number, k: string | null) => void; | ||
lua_seti: (L: LuaState, idx: number, n: number) => void; | ||
lua_seti: (L: LuaState, idx: number, n: bigint) => void; | ||
lua_rawset: (L: LuaState, idx: number) => void; | ||
lua_rawseti: (L: LuaState, idx: number, n: number) => void; | ||
lua_rawseti: (L: LuaState, idx: number, n: bigint) => void; | ||
lua_rawsetp: (L: LuaState, idx: number, p: number | null) => void; | ||
@@ -126,0 +126,0 @@ lua_setmetatable: (L: LuaState, objindex: number) => number; |
@@ -11,2 +11,5 @@ import { BaseDecorationOptions, Decoration } from '../decoration'; | ||
export declare function decorateFunction(target: FunctionType, options: FunctionDecoration): Decoration<FunctionType, FunctionDecoration>; | ||
export default function createTypeExtension(thread: Global): TypeExtension<FunctionType, FunctionDecoration>; | ||
export interface FunctionTypeExtensionOptions { | ||
functionTimeout?: number; | ||
} | ||
export default function createTypeExtension(thread: Global, options?: FunctionTypeExtensionOptions): TypeExtension<FunctionType, FunctionDecoration>; |
{ | ||
"name": "wasmoon", | ||
"version": "1.15.1", | ||
"version": "1.16.0", | ||
"description": "A real lua VM with JS bindings made with webassembly", | ||
@@ -44,23 +44,23 @@ "main": "dist/index.js", | ||
"@rollup/plugin-typescript": "11.1.5", | ||
"@types/node": "20.8.9", | ||
"@typescript-eslint/eslint-plugin": "6.9.0", | ||
"@typescript-eslint/parser": "6.9.0", | ||
"mocha": "10.2.0", | ||
"jest-mock": "29.7.0", | ||
"@types/node": "20.10.4", | ||
"@typescript-eslint/eslint-plugin": "6.13.2", | ||
"@typescript-eslint/parser": "6.13.2", | ||
"chai": "4.3.10", | ||
"chai-as-promised": "7.1.1", | ||
"eslint": "8.52.0", | ||
"eslint-config-prettier": "9.0.0", | ||
"eslint": "8.55.0", | ||
"eslint-config-prettier": "9.1.0", | ||
"eslint-plugin-prettier": "5.0.1", | ||
"eslint-plugin-sort-imports-es6-autofix": "0.6.0", | ||
"fengari": "0.1.4", | ||
"prettier": "3.0.3", | ||
"rollup": "4.1.5", | ||
"jest-mock": "29.7.0", | ||
"mocha": "10.2.0", | ||
"prettier": "3.1.0", | ||
"rollup": "4.7.0", | ||
"rollup-plugin-copy": "3.5.0", | ||
"tslib": "2.6.2", | ||
"typescript": "5.2.2" | ||
"typescript": "5.3.3" | ||
}, | ||
"dependencies": { | ||
"@types/emscripten": "1.39.9" | ||
"@types/emscripten": "1.39.10" | ||
} | ||
} |
@@ -184,1 +184,84 @@ [![Build Status](https://github.com/ceifa/wasmoon/actions/workflows/publish.yml/badge.svg)](https://github.com/ceifa/wasmoon/actions/workflows/publish.yml) | ||
``` | ||
## Edge Cases | ||
### Null | ||
`null` is injected as userdata type if `injectObjects` is set to `true`. This works as expected except that it will evaluate to `true` in Lua. | ||
### Promises | ||
Promises can be await'd from Lua with some caveats detailed in the below section. To await a Promise call `:await()` on it which will yield the Lua execution until the promise completes. | ||
```js | ||
const { LuaFactory } = require('wasmoon') | ||
const factory = new LuaFactory() | ||
const lua = await factory.createEngine() | ||
try { | ||
lua.global.set('sleep', (length) => new Promise((resolve) => setTimeout(resolve, length))) | ||
await lua.doString(` | ||
sleep(1000):await() | ||
`) | ||
} finally { | ||
lua.global.close() | ||
} | ||
``` | ||
### Async/Await | ||
It's not possible to await in a callback from JS into Lua. This is a limitation of Lua but there are some workarounds. It can also be encountered when yielding at the top-level of a file. An example where you might encounter this is a snippet like this: | ||
```js | ||
local res = sleep(1):next(function () | ||
sleep(10):await() | ||
return 15 | ||
end) | ||
print("res", res:await()) | ||
``` | ||
Which will throw an error like this: | ||
``` | ||
Error: Lua Error(ErrorRun/2): cannot resume dead coroutine | ||
at Thread.assertOk (/home/tstableford/projects/wasmoon/dist/index.js:409:23) | ||
at Thread.<anonymous> (/home/tstableford/projects/wasmoon/dist/index.js:142:22) | ||
at Generator.throw (<anonymous>) | ||
at rejected (/home/tstableford/projects/wasmoon/dist/index.js:26:69) | ||
``` | ||
Or like this: | ||
``` | ||
attempt to yield across a C-call boundary | ||
``` | ||
You can workaround this by doing something like below: | ||
```lua | ||
function async(callback) | ||
return function(...) | ||
local co = coroutine.create(callback) | ||
local safe, result = coroutine.resume(co, ...) | ||
return Promise.create(function(resolve, reject) | ||
local function step() | ||
if coroutine.status(co) == "dead" then | ||
local send = safe and resolve or reject | ||
return send(result) | ||
end | ||
safe, result = coroutine.resume(co) | ||
if safe and result == Promise.resolve(result) then | ||
result:finally(step) | ||
else | ||
step() | ||
end | ||
end | ||
result:finally(step) | ||
end) | ||
end | ||
end | ||
``` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Obfuscated code
Supply chain riskObfuscated files are intentionally packed to hide their behavior. This could be a sign of malware.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
458718
25
2304
267
4
1
7
+ Added@types/emscripten@1.39.10(transitive)
- Removed@types/emscripten@1.39.9(transitive)
Updated@types/emscripten@1.39.10