Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how do you extract values from the code? #15

Open
derpyzza opened this issue May 1, 2022 · 3 comments
Open

how do you extract values from the code? #15

derpyzza opened this issue May 1, 2022 · 3 comments

Comments

@derpyzza
Copy link

derpyzza commented May 1, 2022

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?

@jminor
Copy link

jminor commented May 2, 2022

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

@derpyzza
Copy link
Author

derpyzza commented May 3, 2022

thanks for the reply! i'll try that out

@ooichu
Copy link

ooichu commented Feb 2, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants