-
-
Notifications
You must be signed in to change notification settings - Fork 64
Embed
Zenroom is designed to facilitate embedding into other native applications and high-level scripting languages. The stable releases distribute compiled library components for Apple/iOS and Google/Android platforms, as well MS/Windows DLL. Golang bindings and a Jupyter kernel are also in experimental phase.
To call Zenroom and execute Zencode from an host program is very simple, since there isn't an API of calls, but a single call to execute scripts and return their results. The call is called zencode_exec
and prints results to the "stderr/stdout" terminal output. Its prototype is common to all libraries:
int zencode_exec(char *script, char *conf, char *keys, char *data);
in case buffers should be used instead of stdout/err file descriptors, this call defines where to print out the output and the maximum sizes allowed for it. Output is NULL terminated. The input buffers are all read-only, here their functions:
-
script
: a long string containing the script to be executed -
conf
: a short configuration string (for now onlyumm
supported as value) -
keys
: a string often JSON formatted that contains keys (sensitive information) -
data
: a string (also JSON formatted) that contains data
In addition to this function there is another one that copies results (error messages and printed output) inside memory buffers:
int zenroom_exec_tobuf(char *script, char *conf, char *keys, char *data,
char *stdout_buf, size_t stdout_len,
char *stderr_buf, size_t stderr_len);
In addition to the previously explained arguments, the new ones are:
-
stdout_buf
: pre-allocated buffer by the caller where to copy stdout -
stdout_len
: maximum length of the pre-allocated stdout buffer -
stderr_buf
: pre-allocated buffer by the called where to copy stderr -
stderr_len
: maximum length of the pre-allocated stderr buffer
-This API can be called in similar ways from a variety of languages and wrappers that already facilitate its usage.
💾 Installation
npm install zenroom
or
yarn add zenroom
🎮 Quick Usage
const zenroom = require('zenroom').default
const script = `print("Hello World!")`
zenroom.script(script).zenroom_exec()
// prints in the console.log "Hello World!"
💾 Installation
pip install zenroom
🎮 Quick Usage
from zenroom import zenroom
script = "print('Hello world!')"
result = zenroom.zenroom_exec(script)
print(result.stdout) # guess what
💾 Installation
import "github.com/DECODEproject/Zenroom/bindings/golang/zenroom"
🎮 Quick Usage
script := []byte(`print("Hello World!")`)
res, _ := zenroom.Exec(script)
fmt.Println(string(res))
Zenroom is Copyright (C) 2017-2019 by the Dyne.org foundation.
The wiki documentation includes content taken from different Lua extensions, see AUTHORS for details.