Tutorial :Is there a system where executing a program and calling a function is unified?



Question:

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?


Solution:1

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).


Solution:2

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.


Solution:3

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

RUNDLL32.EXE USER32.DLL,SwapMouseButton  


Solution:4

Have you looked at c-repl?


Solution:5

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


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »