有没有一个执行程序和调用函数是统一的系统呢?
我希望能够从 shell 执行以下一项或多项操作: - 调用程序中的任何函数,而不仅仅是主函数 - 传递的参数不仅仅是字符串(不仅仅是argv) - 让程序不仅返回 int (来自 main 的返回代码) - 将返回值分配给 shell 级变量,以便能够将它们传递给其他程序
您明白了。 例如,python toplevel 允许对 python 程序执行此操作。 那么 C++ 呢? 或者 Linux 上的 ELF 替代品可以实现这一点?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果您正在寻找执行此操作的操作系统 - vxWorks shell/C 解释器可以执行此操作。
但是,它是 vxWorks——一个实时操作系统(无 GUI)。
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).
设计一个应用程序并不太难,它允许您从动态库(例如 Windows 下的 DLL)中按名称调用某些函数,前提是这些函数仅采用有限的参数类型选择(例如整数、浮点数和固定字符串)。
然而,对于大多数 C++ 程序来说,这还不够。 例如,假设您的 C++ 函数将动态字符串到套接字的 std::map 作为参数 - 您将如何创建映射,更不用说您的 shell 中的内容了?
但是,如果您可以放弃 C++,那么有一种语言兼操作系统可以完全按照您的建议进行操作 - Smalltalk。 如果您对这种范例感兴趣,请查看 Squeak,它是免费软件。
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.
在Windows下,有RUNDLL32来调用DLL函数,例如
Under Windows, there is RUNDLL32 to call DLL function, eg
你看过c-repl吗?
Have you looked at c-repl?
该系统必须被完全解释,对吗? 您如何知道您所调用的事物的函数签名?
The system would have to be completely interpreted, right? And how would you know the function signatures of the things you were calling?