Hi Doug,

> I'd like to embed minipicolisp in C applications. I'd like to be able
> to create a minipicolisp environment, and then pass strings to it
> (commands) for execution. It would also be great to be able get back the
> results in a string.

The mechanism in PicoLisp to execute a string is 'load'. If an argument
to 'load' starts with a hyphen, the rest is interpreted as an expression
(without the surrounding parentheses). This mechanism is normally used
to run expressions from the command line.

The lower level functions for that are 'str', both for converting a
transient symbol to a list (without the surrounding parentheses) and to
do the reverse, and EVAL() (which is actually not a function but a

Unfortunately, there is no way currently to convert a C string directly
to an executable Lisp expression (without the intermediate transient

> In lua, you'd do something like,
>  L = lua_open();

Here you'd need a function that initialized the PicoLisp VM, as is done
by main(), i.e. calls heapAlloc(), initSymbol() etc.

>  luaL_dostring(L, str_in );
>  str_out = l_results_to_string(L);

You need a C function similar to 'loadAll()'. It would call 'mkStr()' on
the C string to create the transient symbol, then load() to run the

Better would be to cook something more specialized, similar to parse(),
to avoid the intermediate transient symbol step.

To pack the result into a C string, you need a mechanism similar to

You define a function which writes a single byte into a C character

   void putCharC(int c) {
      *CBytePtr++ = c;

and store a pointer to that function into 'Env.put':

   void (*putSave)(int);

   putSave = Env.put;
   Env.put = putCharC;
   Env.put = putSave;

Hope this helps.

- Alex
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe

Reply via email to