MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
Runtime.hpp
Go to the documentation of this file.
1#pragma once
2
3namespace MayaFlux::Host::Live {
4
5/**
6 * @brief Start a Lila interpreter and TCP server inside this process.
7 *
8 * Constructs a Lila instance and initializes it in OperationMode::Both.
9 * The interpreter skips loading MayaFluxLib because the host process
10 * already has it resident in the symbol table.
11 *
12 * Only one Lila instance is permitted per process. Subsequent calls
13 * while one is already running return false and log a warning.
14 *
15 * JIT'd code evaluated through this session can call any MayaFlux
16 * symbol visible in the process symbol table. Objects constructed
17 * with shorter lifetimes than the host should use MayaFlux::store()
18 * or MayaFlux::make_persistent() to survive declaration-group scoping.
19 *
20 * @param port TCP port for the Lila server to listen on.
21 * @return true on successful start, false otherwise.
22 */
23[[nodiscard]] MAYAFLUX_HOST_API bool start_lila(uint16_t port = 9090);
24
25/**
26 * @brief Stop the running Lila interpreter and TCP server.
27 *
28 * Any JIT'd function pointers obtained through this session become
29 * invalid after this returns.
30 *
31 * @param clear_persistent_store If true, also empties the persistent
32 * store so objects created during the session are released.
33 * Defaults to false so a subsequent start_lila() can resume
34 * against store()-held state.
35 */
36MAYAFLUX_HOST_API void stop_lila(bool clear_persistent_store = false);
37
38/**
39 * @brief True if a Lila instance is currently running in this process.
40 */
41[[nodiscard]] MAYAFLUX_HOST_API bool lila_active();
42
43/**
44 * @brief TCP port of the running Lila instance, or 0 if none is running.
45 */
46[[nodiscard]] MAYAFLUX_HOST_API uint16_t lila_port();
47
48/**
49 * @brief Find the directory containing a header staged for inclusion.
50 *
51 * Used by the JIT to resolve #include directives for staged headers.
52 *
53 * @param filename Header filename to find, e.g. "Dust.hpp"
54 * @return optional path to the directory containing the header, or nullopt
55 * if the header was not staged or could not be found.
56 */
57MAYAFLUX_HOST_API std::optional<std::filesystem::path> find_include_dir(const std::string& filename);
58
59/**
60 * @brief Add an include path to the Lila interpreter.
61 *
62 * Must be called before start_lila(). Paths registered after initialization
63 * have no effect on the compiler state already built by initialize().
64 *
65 * @param path Directory to add to the JIT include search path.
66 */
67MAYAFLUX_HOST_API void lila_add_include_path(const std::string& path);
68
69/**
70 * @brief Add a compile flag to the Lila interpreter.
71 *
72 * Must be called before start_lila(). Flags registered after initialization
73 * have no effect on the compiler state already built by initialize().
74 *
75 * @param flag Compiler flag string, e.g. "-DMY_DEFINE" or "-I/some/path".
76 */
77MAYAFLUX_HOST_API void lila_add_compile_flag(const std::string& flag);
78
79/**
80 * @brief Stage a header for inclusion in the Lila interpreter.
81 *
82 * Resolves the header's directory and pre-evaluates the include
83 * so the type is available to JIT clients without manual inclusion.
84 *
85 * @param filename Header filename to find and include, e.g. "Dust.hpp"
86 * @return true if the file was found.
87 */
88MAYAFLUX_HOST_API bool lila_add_header(const std::string& filename);
89
90/**
91 * @brief Load a shared library into the JIT symbol table at runtime.
92 *
93 * Can be called before or after start_lila(). Libraries loaded before
94 * start_lila() are staged and loaded immediately after interpreter
95 * initialization. Use this for external .so/.dylib/.dll files that
96 * were not linked into the host process.
97 *
98 * @param path Full path to the shared library.
99 */
100MAYAFLUX_HOST_API void lila_load_library(const std::string& path);
101
102/**
103 * @brief Evaluate a code snippet in the Lila interpreter.
104 *
105 * Can be called after start_lila() to pre-warm the JIT state,
106 * e.g. to include community module headers before clients connect.
107 *
108 * @param code C++ code to evaluate, e.g. "#include \"Dust.hpp\""
109 * @return true if evaluation succeeded.
110 */
111MAYAFLUX_HOST_API bool lila_eval(const std::string& code);
112
113} // namespace MayaFlux::Host::Live
bool lila_active()
True if a Lila instance is currently running in this process.
Definition Runtime.cpp:87
void stop_lila(bool clear_persistent_store)
Stop the running Lila interpreter and TCP server.
Definition Runtime.cpp:66
std::optional< std::filesystem::path > find_include_dir(const std::string &filename)
Find the directory containing a header staged for inclusion.
Definition Runtime.cpp:99
bool start_lila(uint16_t port)
Start a Lila interpreter and TCP server inside this process.
Definition Runtime.cpp:24
uint16_t lila_port()
TCP port of the running Lila instance, or 0 if none is running.
Definition Runtime.cpp:93
bool lila_eval(const std::string &code)
Evaluate a code snippet in the Lila interpreter.
Definition Runtime.cpp:153
bool lila_add_header(const std::string &filename)
Stage a header for inclusion in the Lila interpreter.
Definition Runtime.cpp:130
void lila_load_library(const std::string &path)
Load a shared library into the JIT symbol table at runtime.
Definition Runtime.cpp:143
void lila_add_compile_flag(const std::string &flag)
Add a compile flag to the Lila interpreter.
Definition Runtime.cpp:120
void lila_add_include_path(const std::string &path)
Add an include path to the Lila interpreter.
Definition Runtime.cpp:110