DelSkayn / rquickjs

High level bindings to the quickjs javascript engine
MIT License
434 stars 59 forks source link

how to defined a function with variable argument size by macro 'rquickjs::function' #256

Closed LXS2000 closed 5 months ago

LXS2000 commented 5 months ago

there is a function i created,jsreq is necessary, the remaining arguments is optional


#[rquickjs::function]
pub async fn fetch<'js>(
jsreg: JsRequest.
proxy: Option<String>
ja3: Option<i64>,
h2: Option<i64>
ctx: Ctx<'js>,
)-> Result<JsResponse>

when i use it in js runtime ,i got a error

Error calling function with 2 argument(s) while 4 where expected

LXS2000 commented 5 months ago
await fetch(request, proxy)
DelSkayn commented 5 months ago

Using Option<T> as an argument signifies to rquickjs that the value can be null-like i.e. either the value T undefined or null but that the argument is still required. If you want the argument to be optional use Opt

LXS2000 commented 5 months ago

Thank you for your answer ,it's work