Sharing application data with chibi without global variables

51 views
Skip to first unread message

Hleb

unread,
Apr 27, 2023, 6:02:17 PM4/27/23
to chibi-scheme
Hello!
I have an application written in C++, I want extend with scheme scripts.

Let's imaging that my application is implemented as "class App".
Now I have a context created and want my make my application available in functions added via sexp_define_foreign. I don't want to use global C++ variables for this.

Currently I'm using sexp_env_define to define a new symbol pointing to the application instance and later retrieve it in my functions.

Is there any better way?

Amirouche Boubekki

unread,
Apr 28, 2023, 10:01:42 AM4/28/23
to chibi-...@googlegroups.com
You want to expose c++ methods inside the chino interpreter ?



Is there any better way?

--
You received this message because you are subscribed to the Google Groups "chibi-scheme" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chibi-scheme...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/chibi-scheme/bfbed09c-28e7-4824-ae0e-19024c3c893bn%40googlegroups.com.

Hleb

unread,
Apr 30, 2023, 3:16:00 AM4/30/23
to chibi-scheme
Yes, I want to allow user to control the application using scripts.
Message has been deleted

Alex Shinn

unread,
May 2, 2023, 1:44:05 AM5/2/23
to chibi-...@googlegroups.com
That's the low-level approach.  You can also use the FFI and `(define-c-class App)'.

--
Alex
 

Is there any better way?

--

Hleb

unread,
May 22, 2023, 4:37:54 AM5/22/23
to chibi-scheme
Why not to add a special field to context or environment to share data between a host application and functions defined for chibi?
Something like this:
==========
sexp sexp_set_env_userdata(sexp env, void *userdata) {
    if (sexp_envp(env)) {
        env->value.env.userdata = userdata;
    }
    return env;
}

void* sexp_get_env_userdata(sexp env) {
    if (sexp_envp(env)) {
        return env->value.env.userdata;
    }
    return NULL;
}
==============
Reply all
Reply to author
Forward
0 new messages