Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Adding a Safe Interactive Intrepreter to an Application.

0 views
Skip to first unread message

davidh...@simplifiedlogic.com

unread,
May 16, 2007, 10:27:18 AM5/16/07
to
Good People,

I have been considering adding an interactive shell to one of our
stand alone applicaions.

Any ideas on how to do this?

Dave

davidh...@simplifiedlogic.com

unread,
May 18, 2007, 10:44:11 AM5/18/07
to
No takers on this?

Dave

Uwe Klein

unread,
May 18, 2007, 11:52:28 AM5/18/07
to
davidh...@simplifiedlogic.com wrote:
> No takers on this?
>
> Dave
>
Never done anything with save interps but:

#!/usr/bin/tclsh

set saveinterp [ interp create -safe ]
puts stderr "saveinterp created : $saveinterp"

set prompt "\n>> "
set ::run 1
set ::ifd stdin
set ::ofd stdout

# I guess here you would insert some aliases and stuff
# for commands not present in the save interp to work
# ( in a save way, puts, exit, ... comes to mind )

# end of prelude

while {$::run} {
puts -nonewline $::ofd \n$prompt ; flush $::ofd
append script " "
append script [ gets $::ifd ]
if {[info complete $script]} {
catch { interp eval $saveinterp $script } cerr
puts -nonewline $::ofd $cerr ; flush $::ofd
unset script
set ::prompt "\n>> "
} else {
set ::prompt "\n > "
}
}

uwe

davidh...@simplifiedlogic.com

unread,
May 18, 2007, 10:59:56 PM5/18/07
to
On May 18, 11:52 am, Uwe Klein <uwe_klein_habertw...@t-online.de>
wrote:


Not sure how this works -- the idea I was hoping for was more along
the lines of a text editor that I would be able to embed in my Tcl/Tk
application for the user to perofrm tcl functions, string
manipulations, evaluations, etc. from within the text widget.

Got any ideas on that?

Dave


Erik Leunissen

unread,
May 19, 2007, 6:46:32 AM5/19/07
to
davidh...@simplifiedlogic.com wrote:

> ...


> Not sure how this works -- the idea I was hoping for was more along
> the lines of a text editor that I would be able to embed in my Tcl/Tk
> application for the user to perofrm tcl functions, string
> manipulations, evaluations, etc. from within the text widget.
>
> Got any ideas on that?
>

If your Tcl/Tk application simply embedded tkcon (= sourceing tkcon.tcl)
, would that provide the sort of functionality that that you're after?
You probably need to make some modifications to make the interactive
interpreter safe.

References:
http://tkcon.sourceforge.net/
http://mini.net/tcl/tkcon

Erik
--
leunissen@ nl | Merge the left part of these two lines into one,
e. hccnet. | respecting a character's position in a line.

Michael Schlenker

unread,
May 19, 2007, 7:07:46 AM5/19/07
to
davidh...@simplifiedlogic.com schrieb:

What are you actually trying to achieve?

One fast way is embedding the tkcon megawidget as a command shell.
(http://wiki.tcl.tk/17616)

Depending on your requirements (aka should users be able to block/kill
the app from the shell or not) you might want put the console into a
separate thread and in a safe interpreter there or just in a safe
interpreter.

If you put tkcon into a child interpreter (safe or not) you can then
export your application API with some interp aliases. I usually put my
external interface in one namespace and then use something like this to
init the aliases in the console interpreter:

foreach cmd [info commands ::external::*] {
interp alias $consoleInterp $cmd {} $cmd
}

If you think about user written plugins, the pluginmgr module in tcllib
might be useful for you, it provides a safe interpreter sandbox with
definable APIs for plugins.
http://tcllib.sourceforge.net/doc/pluginmgr.html

Especially [exit] should be remapped in the child interpreter, to do
something sane for your app.

Michael

davidh...@simplifiedlogic.com

unread,
May 19, 2007, 8:40:06 AM5/19/07
to
On May 19, 6:46 am, Erik Leunissen <l...@the.footer.invalid> wrote:


YES - that is about PEREFCT - but Too MUCH! Anyway to get rid of the
menus and all of that..?

Dave

0 new messages