elves / elvish

Powerful scripting language & versatile interactive shell

Home Page:https://elv.sh/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Better integration with programs in other languages

iacore opened this issue · comments

commented

Is it possible to have C API for elvish? It would be cool to use Elvish to exchange userdata (like in Lua) between programs.

So far, exchanging data between programs written in diffirint languages is janky. Applications usually include their own REPL, and each one has a different usage.

Wouldn't it be nice to have user programs to interop more tightly? No expect is needed.

It is possible to preserve state across command invocation with daemon. However, I think it's important to make this as simple as possible.

On some platforms you can build Go code with -buildmode=c-shared to get a shared library which can then be dynamically linked into a program written in another language like C. I haven't tried building Elvish that way and even if you could build a elvish.so file (rather than the usual executable binary) that is just a tiny part of solving the problem. Elvish would still need to provide an actual API for calling its code evaler and returning output to the caller. Which is further complicated because Elvish has both byte and value streams. Which also raises the question of how to handle non-string objects on the value stream; i.e., how to convert things like Elvish lists, maps, exceptions, bools, and other non-string values to something usable by a program written in C/C++. There is a lot of prior art to draw on so this wouldn't be a greenfield project, but still entails a lot of work.

I'm curious how long you've been using Elvish and why you feel it would be an embeddable scripting language superior to the existing solutions such as LUA and Python which would justify the non-trivial amount of work required.

commented

Not dynamic linked into a program. I mean the dynamic library to be used with dlopen.

  • elvish
  • program foo
  • nested elvish runtime (lookup elvish variables and what not)

One common usage: have elvish being the builtin REPL of that application. Application state is scoped to the process.

Another common usage: have short-running programs that return values, which may be mmap region, OpenGL context or whatever.

You don't need a complex API for most of those things.

what's needed (basic):

basic API for applications...

  • to manipulate variables of its parent shell. At least environment variables
  • to register native elvish functions in parent shell, then exit (the argument parsing and function body is left to the external program)

If you don't mind the ser/deser cost, it's possible for the external program to receive and return elvish values as string (put $a).

commented

Both byte & value stream makes this complicated. Maybe it's better to have implicit conversion first.

It has been three months since I first read this issue. Upon reading it again I still do not understand what is being requested. For example, this seemed to be the central question of the original problem statement:

It would be cool to use Elvish to exchange userdata (like in Lua) between programs.

That is usually done using an encoding such as JSON (natively handled by Elvish) or protobufs. You then wrote

Another common usage: have short-running programs that return values, which may be mmap region, OpenGL context or whatever.

There is literally no way for a separate short-running independent program to return a value of that sort that is useful to Elvish. There may be value in figuring out how to make Elvish usable as a scripting language for an application. Similar to how Lua and Tcl are used. But your comments, @iacore, suggest you have something else in mind.

commented

I didn't really think this through. Feel free to close this issue.

The proposed use case is like that of CPython. Elvish can both be a shell and have access to C libraries like Python.

There is literally no way for a separate short-running independent program to return a value of that sort that is useful to Elvish.

If the code is run in the same process, via dynamic library, then it's possible.