views:

140

answers:

5

I would like to be able to do one or more of the following from the shell: - call any function from the program not only the main - pass parameters that are not only strings (not only argv) - have a program return not only int (the return code from main) - assign returned values to shell-level variables to be able to pass them to other programs

You get the idea. For instance python toplevel allow this for python programs. What about C++? Or a ELF replacement on linux that would allow that?

+2  A: 

If you looking for an operating system that does this - the vxWorks shell/C interpreter does this.

But, it's vxWorks - a realtime operating system (no GUI).

paquetp
+2  A: 

It's not too difficult to come up with an app that allows you to call certain functions by name from dynamic libraries such as DLLs under Windows, provided those functions take only a limited selection of parameter types such as ints, floats and fixed strings.

However, for most C++ programs this is not sufficient. For example, suppose your C++ function takes s std::map of dynamic string to socket as a parameter - how are you going to create the map, to say nothing of its contents in your shell?

But if you can forgo C++, there is one language cum operating system that does exactly what you suggest - Smalltalk. If you are interested in this paradigm, take a look at Squeak, which is free software.

anon
There is already a program like that on Windows: rundll32.exe
0xA3
Actually, this would work with any image-based environment that provides some sort of REPL, e.g. some Common Lisp implementation. You just need to write some functions that wrap the common system calls.
Svante
A: 

The system would have to be completely interpreted, right? And how would you know the function signatures of the things you were calling?

Jeff
The app will know it by reflection. The app can display error message if the signature doesn't match.
CDR
+2  A: 

Under Windows, there is RUNDLL32 to call DLL function, eg

RUNDLL32.EXE USER32.DLL,SwapMouseButton
Adrian
+1  A: 

Have you looked at c-repl?

sigjuice