Closed qwenger closed 3 years ago
Hi,
quickjs provides ways of evaluating code and getting the result (ctx.eval), adding functions (ctx.add_callable) and getting values (ctx.get).
ctx.eval
ctx.add_callable
ctx.get
AFAICS, there is currently no proper way of adding/setting variables.
I've been able to work around this via json dumping:
ctx.eval(f"my_variable_name = {json.dumps(variable)};")
It however feels a bit hacky. I think that it would be nice to be able to set variables directly, e.g. as
ctx.set("my_variable_name", variable)
or by adding an optional argument to eval, which would bind the return value (js-side) of the evaluation to a variable:
eval
ctx.eval(variable, "my_variable_name")
A set method on a context sounds reasonable.
set
Done in #55.
Hi,
quickjs provides ways of evaluating code and getting the result (
ctx.eval
), adding functions (ctx.add_callable
) and getting values (ctx.get
).AFAICS, there is currently no proper way of adding/setting variables.
I've been able to work around this via json dumping:
It however feels a bit hacky. I think that it would be nice to be able to set variables directly, e.g. as
or by adding an optional argument to
eval
, which would bind the return value (js-side) of the evaluation to a variable: