[plt-scheme] Problem embedding scheme in real time application.
Hello,
I'm trying use mzScheme for a realtime application in C++ using Visual
Studio 8.0. I wrapped the scheme setup in a class (and this is
probably where I'm having problems). Here's a small main loop:
#include <iostream>
#include "SchemeInterface.h"
#include <string>
void main(int argc, char *argv[]) {
SchemeInterface sh;
sh.evaluate("(define test 'test)");
bool exit = false;
while(!exit) {
sh.evaluate("test");
}
}
This will run for a short while and then crash out with an access
violation error. So it seems I'm writing or reading somewhere I
shouldn't.
Here's my class file. I hope someone can point, my mistake
Thank you,
Dan
//
// Header
//
#pragma once
#define MZ_PRECISE_GC
#include <string>
#include "scheme.h"
class SchemeInterface
{
private:
Scheme_Env *e;
Scheme_Object *curout, *v;
Scheme_Config *config;
mz_jmp_buf * volatile save, fresh;
public:
SchemeInterface(void);
~SchemeInterface(void);
Scheme_Object * evaluate(const std::string& expression);
};
//
// CPP file
//
#include "SchemeInterface.h"
#include <iostream>
// Creates gc_var_stack
MZ_GC_DECL_REG(5);
SchemeInterface::SchemeInterface(void) {
e = NULL;
curout = NULL;
v = NULL;
config = NULL;
save = NULL;
MZ_GC_DECL_REG(5);
MZ_GC_VAR_IN_REG(0, e);
MZ_GC_VAR_IN_REG(1, curout);
MZ_GC_VAR_IN_REG(2, save);
MZ_GC_VAR_IN_REG(3, config);
MZ_GC_VAR_IN_REG(4, v);
# ifdef MZ_PRECISE_GC
# define STACK_BASE &__gc_var_stack__
# else
# define STACK_BASE NULL
# endif
scheme_set_stack_base(STACK_BASE, 1);
MZ_GC_REG();
e = scheme_basic_env();
config = scheme_current_config();
curout = scheme_get_param(config, MZCONFIG_OUTPUT_PORT);
}
SchemeInterface::~SchemeInterface(void) {
MZ_GC_UNREG();
}
Scheme_Object * SchemeInterface::evaluate(const std::string& expression){
Scheme_Object * v = 0;
v = scheme_eval_string(expression.c_str(), e);
// std::cout << "Output type:" << v->type << std::endl;
scheme_display(v, curout);
scheme_flush_output(curout);
return v;
}
--
Check out my pictures here: flickr.com/photos/balaam/
<a href="flickr.com/photos/balaam/">Linky Linky</a>