Replies: 3 comments 1 reply
-
|
Beta Was this translation helpful? Give feedback.
-
Thanks for the reply. Some followups:
|
Beta Was this translation helpful? Give feedback.
-
Came across 'Embedding Janet' in 'Janet for Mortals'; that explains a lot of the details, albeit in a somewhat more complicated context (Emscripten). |
Beta Was this translation helpful? Give feedback.
-
Hello Community,
OS: Windows 10
Version: Latest -- 1.23.1-dev
Language: C++20
Compiler: MSVC 2022
I'm in the process of embedding Janet into a 3D graphics engine, for the purpose of providing scripting capabilities.
I've read through the 'C API' section of the documentation. I have looked at the available C code in 'test' and 'examples' directories, and I've been looking for other locations with Janet C code. I've also done the usual Google searches.
I've been able to print "hello, world!" to std out from the 3D App, via an attached cmd console -- essentially, the code in this file:
https://github.com/janet-lang/janet/blob/master/test/amalg/main.c
I've also gained a decent idea how to go about creating libraries of C functions.
I'm ready to move onto the next phase, which is to define the Api and Environment exposed to Janet scripts, which run in the context
of the 3D App. Unfortunately for me, I've been unabled to figure out some extended use of the Janet embedding API.
If possible, can you please point me in the right direction where I can get further info/examples on how to use the embedding API?
Specifically, I'm trying to accomplish the following:
Compile a script into bytecode, verify correctness (for some level of 'correctness', such as syntax), and keep the bytecode around for later execution. The idea being that the App may compile some scripts during startup, and later run them on demand, possibly multiple times. It might also load other scripts, at arbitrary times, as the App executes.
Safely unload previously compiled bytecode.
Get a pointer to functions defined in the script files, to (possibly) execute them every frame.
Bind C functions to the Env from the C side, as opposed to by calling the
(use lib)
function from Janet script.Bind C variables to the Env, such as ints.
Dealing with errors on the C side, raised by called Janet functions.
A way to opt-into, rather than opt-out, of functions created by the default
janet_core_env()
function. Ideally, I'd like to specify what exactly goes into the initial environment, so that upgrading to later versions of Janet doesn't automatically pull in new features. Since the VM will run in the context of the Rendering App, there are functions that are not appropriate for the scripts.Managing the Garbage collector: Pausing, Unpausing, Collecting
Passing
void* userData
into callback functions: C -> Janet -> C (utilize userData here)Way to limit the execution time of scripts, so they don't monopolize the system.
From what've been experience so far, Janet is a really pleasant and well designed language. I can't wait to do cool things with it.
Regards
Beta Was this translation helpful? Give feedback.
All reactions