How to make ffi bindings to termux api
I want to use it directly in a programming language rather than the shell interface in a shell script.
Is it possible to do? I used the file command on the termux-api file and it said it was a shared object.
I'm hoping someone can give me some pointers on doing it. Can I interface with it through a C FFI? If it's java, do I need to install a jre to use it?
7 Replies
You can probably use the commands provided by the
termux-api
package as a shim by "shelling out".
E.g. running it through an external system command.I'm aware of that option.
I'll do that if there's no other way
The programming language I'm using has a C FFI that I really like and I'd prefer to use that if possible. There's nothing like that yet for shell programs in the language.
There is no official FFI bindings for Termux-API as far as I am aware.
You might be able to use an existing C FFI for
am
(the Android activity manager), though that loses out on the convenience factor of using Termux-API since it provides wrappes around common am
calls to the Termux API.Are these C programs?
I glanced at the source of one of them in the termux-api repo and it looked like java.
The source of the termux-api program
There's two parts to this.
Termux:API is the java implementation of the activity manager endpoints for Termux.
termux-api
is the package containing the shell wrappers around those am
calls for the most common usecases.
There's a bit of C in there, but I'm not sure if it's gonna be of any use to you.
https://github.com/termux/termux-api-packageGitHub
GitHub - termux/termux-api-package: Termux package containing scrip...
Termux package containing scripts to call functionality in Termux:API. - termux/termux-api-package
Actually,
termux-api.c
and termux-api.h
might be exactly what you are looking for.
Gets compiled down to libtermux-api.so
, that sounds like a C FFI to me.Hm. Im read it and it doesn't look useful to me. Run api command is the only function there that sounds useful and what it does is send command line arguments to a running process. Some program it talks to by socket.
It's still command line arguments so there's no change in interface.
Thanks though.