This is a hobby project of mine - a game in C, using SDL. I'd like to only 
use C for the rendering part - rather use a scripting language for all of 
the gameplay code. I want to try to use Racket for this - I've been doing 
enough Clojure that I'm familiar with a lisp. My first approach was to 
following along "Embedding into a Program" section of the Racket guide. But 
I'm running into road blocks - and I can't find any good examples of 
projects which embed Racket in a C program that calls functions in a Racket 
environment. My initial plan was to define a Racket module that provided an 
"init", an "update", and a "draw" function, then call those from the C 
program. The embedding guide points me to using "raco" to generate a C 
version of "racket/base", and that works - I can eval basic stuff, but I'm 
getting an error when I (require "test.rkt"). So I'm guessing there's more 
to be done with setting up the environment.

My "test.rkt" file is this:

#lang racket/base

(printf "Hello World!\n")

And this is the pertinent part of the main.c file, which links libracket.

#include "scheme.h"
#include "base.c"

static int run(Scheme_Env* e, int argc, char* argv[]) {
scheme_env = e;

declare_modules(e);

scheme_namespace_require(scheme_intern_symbol("racket/base"));

Scheme_Config* config = scheme_current_config();
Scheme_Object *curout = scheme_get_param(config, MZCONFIG_OUTPUT_PORT);
Scheme_Object* v = scheme_eval_string("(+ 1 2)", scheme_env);
scheme_display(v, curout);
scheme_display(scheme_make_char('\n'), curout);

scheme_eval_string("(require \"test.rkt\")", scheme_env);
  
  return 0;
}

int main(int argc, char* argv[]) {
scheme_main_setup(1, run, argc, argv);
return 0;
}

The output is:

3
standard-module-name-resolver: collection not found
  for module path: racket/base/lang/reader
  collection: "racket/base/lang"
  in collection directories:
  context...:
   show-collection-err_0
   standard-module-name-resolver
   1/module-path-index-resolve
   do-dynamic-require5_0
   read-syntax3_0
   default-load-handler
   standard-module-name-resolver
   1/module-path-index-resolve
   perform-require!78.1
   for-loop_0
   expand-capturing-lifts
   temp118_0
   temp91_0
   compile15_0
   temp85_0

I'm thinking that the environment isn't correctly setup here, the "in 
collection directories" lists is empty.

Am I going about this the wrong way though? Would I be better served in 
setting up all of the game loops, etc. in Racket, then use FFI just for 
rendering with SDL?

The game I'm making is a roguelike, so performance isn't as critical.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/7b0bcf81-f826-49fd-9f81-9e0d0b0da398%40googlegroups.com.

Reply via email to