I need to embed a scripting languange in a C++ application.
Currently I am evaluating some scripting languages for this purpose.
* perl (that works, although it needs a big amount of C++ glue code to deal with the perl stack(s)
* python - have not tried yet
* lua - that's really great, very easy to embed. Not surpring since lua is "designed to be embedded". Unfortuneately the lua interpreter is very limited
* ruby - there is no/very limited docs about howto do that
to clarify: I am not talking about *extending* ruby, e.g. via SWIG. That is quite easy to do.
What I mean is *embedding* it into an existing large C++ program and than call some ruby functions (and to give some values to this ruby functions and to get some values back from this ruby functions)
As it is in the following lua example:
int main (void) {
lua_State *L = lua_open();
/* load and parse script - but do not execute */
luaL_loadfile(L, "example.lua");
/* push functions and arguments */
lua_getglobal(L, "f"); /* function to be called */
lua_pushnumber(L, x); /* push 1st argument */
lua_pushnumber(L, y); /* push 2nd argument */
/* do the call (2 arguments, 1 result) */
lua_pcall(L, 2, 1, 0);
/* retrieve result */
int result = lua_tonumber(L, -1);
lua_pop(L, 1);
lua_close(L);
return 0;
}
I have found some docs a la:
int main(int argc, char **argv)
{
RUBY_INIT_STACK
ruby_init();
ruby_options(argc, argv);
ruby_run();
return(0);
}
But I did not find a simple example describing howto bring values onto the ruby stack, call a function and get results back. Moreover I found out that ruby_run() does not return. I need to have the C++ application keeping control.