unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Re: Can scm_shell be interrupted?
@ 2008-05-16 16:29 Remco Bras
  2008-06-01 21:58 ` Neil Jerram
  0 siblings, 1 reply; 5+ messages in thread
From: Remco Bras @ 2008-05-16 16:29 UTC (permalink / raw)
  To: guile-user

Hello,

after the last exchange in this thread, I wrote and tested a prototype of a 
repl for my app. The code for this is as follows:

int
exec_guile_shell (void *unused_arg)
{
  scm_init_guile();
  /*Horribly inefficient*/
  while(1)
    {
      SCM_TICK;
      SDL_mutexP(repl_signal);
      
scm_simple_format(scm_current_output_port(),scm_from_locale_string(PROMPT),SCM_EOL);
      
scm_simple_format(scm_current_output_port(),scm_from_locale_string("~S"),scm_list_1
(scm_primitive_eval(scm_read(scm_current_input_port()))));
      scm_newline(scm_current_output_port());
      SDL_mutexV(repl_signal);
    }
  return 0;                     //never reached, just here to please gcc.
}

This is run when the app starts, after using scm_c_define_gsubr to define the 
primitive interface my app exports and after scm_c_primitive_load is used to 
read in user-defined scheme files. When this function runs, the repl_signal 
mutex is already locked, after which a user's file may use (run-repl) to tell 
the main loop to unlock the mutex. 

For the most part, this works fine, but if I use this REPL to evaluate a call 
to one of the functions I have defined using scm_c_define_gsubr, for example 
(stop-repl), the function is unbound in the environment the REPL uses. I've 
tried using scm_interaction_environment() as a second argument to scm_eval 
rather than using scm_primitive_eval, but that did not solve this problem. 

I'm using guile 1.8.4 on GNU/Linux, in case that's relevant. Also, when 
evaluating files using scm_c_primitive_load, the previously defined functions 
are bound, regardless of whether they were defined by scm_c_define_gsubr or 
another file.

Regards,

Remco.




^ permalink raw reply	[flat|nested] 5+ messages in thread
* Can scm_shell be interrupted?
@ 2008-05-10 20:54 Remco Bras
  2008-05-12 20:43 ` Neil Jerram
  0 siblings, 1 reply; 5+ messages in thread
From: Remco Bras @ 2008-05-10 20:54 UTC (permalink / raw)
  To: guile-user

Hello,

I have a question about guile. I'd like to know if it is feasible to run a 
guile REPL and control when it runs. For example, consider the following 
scenario. A package may or may not have a thread running scm_shell, when the 
user requests that the package runs an REPL. The package responds by running 
scm_shell in a thread and keeping that thread's ID. If the user wants the 
package to stop the REPL at any moment, is there a way to do this safely? 

Thanks in advance,

Remco Bras




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2008-06-01 21:58 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-05-16 16:29 Can scm_shell be interrupted? Remco Bras
2008-06-01 21:58 ` Neil Jerram
  -- strict thread matches above, loose matches on Subject: below --
2008-05-10 20:54 Remco Bras
2008-05-12 20:43 ` Neil Jerram
2008-05-16 15:29   ` Remco Bras

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).