I want to use duk_pcall
to do it, here is what I tried:
char* string
.duk_pcompile_string(ctx, 0, programBody)
to compile it.duk_pcall(ctx, 0)
to call it once, and call duk_pop(ctx)
.But when I try to use duk_pcall
a second time, I failed.
Can you give me some advice about how to do it the right way?
duk_pcompile_string
places the result on the TOS and duk_pcall
executes the TOS (+ eventual parameters) and replaces all of that by the return value of the call.
In order to make the function callable multiple times you have to duplicate the TOS insert the required parameter and then call that using the pcall. After the call remove the result from the stack. The original function should now be at the TOS again. Start over with what is written in this paragraph, to call it again.