fe icon indicating copy to clipboard operation
fe copied to clipboard

how do you extract values from the code?

Open derpyzza opened this issue 3 years ago • 3 comments

like if i had a fe file with the code: (= input "hello there") and i wanted to access the value of the input variable in c, how would i do that?

derpyzza avatar May 01 '22 18:05 derpyzza

I would try fe_tostring(ctx, fe_symbol(ctx, "myvariable"))

You might have to use fe_eval in between: fe_tostring(ctx, fe_eval(ctx, fe_symbol(ctx, "myvariable")))

There's an example of using fe_eval under "Calling a Function" here: https://github.com/rxi/fe/blob/master/doc/capi.md#calling-a-function

jminor avatar May 02 '22 01:05 jminor

thanks for the reply! i'll try that out

derpyzza avatar May 03 '22 19:05 derpyzza

fe_Object *obj = fe_eval(ctx, fe_symbol(ctx, "input"));

Don't forget to take care of restoring the GC stack if you're not doing it inside a fe function. To avoid creating the 'input' symbol every time (via fe_symbol), you can create it beforehand. This will be much faster.

ooichu avatar Feb 02 '23 21:02 ooichu