API: Lua: VM - ov-studio/Vital.sandbox GitHub Wiki

━ APIs

━ Vital::Sandbox::Lua::create()

@Objective: Creates a new VM.
vital_vm* vm = new Vital::Sandbox::Lua::create();

━ Vital::Sandbox::Lua::fetchVM()

@Objective: Retrieves vm by its state's reference.
vital_vm* vm = Vital::Sandbox::Lua::fetchVM(vital_ref* vm);

━ Methods

━ vm::destroy()

@Objective: Destroys targetted vm.
bool result = vm -> destroy();

━ vm::isVirtualThread()

@Objective: Verifies whether the instance is an virtual thread.
bool result = vm -> isVirtualThread();

━ vm::push()

@Objective: Pushes value of specified index onto the top of the stack.
void result = vm -> push(int index = 1);

━ vm::pop()

@Objective: Pops specified number of values from top of the stack.
void result = vm -> pop(int count = 1);

━ vm::move()

@Objective: Moves specified number of values from top of the current stack to the target stack.
ℹ️ To be used for exchanging values back & forth b/w threads of same instance.
void result = vm -> move(vital_vm* target, int index = 1);

━ vm::resume()

@Objective: Resumes specified virtual thread's handler.
⚠️ To be used only with virtual threads.
void result = vm -> resume();

━ vm::pause()

@Objective: Pauses specified virtual thread's handler.
⚠️ To be used only with virtual threads.
void result = vm -> pause();

━ vm::execute()

@Objective: Executes a C++ function safely on the vm while reporting encountered exceptions.
⚠️ To be used only within bound C++ functions.
int result = vm -> execute(std::function<int()> exec);

━ vm::loadString()

@Objective: Runs specified buffer on the vm.
bool result = vm -> loadString(std::string& buffer);

━ vm::throwError()

@Objective: Throws a error with call stack details.
bool result = vm -> throwError(std::string& error = "");
⚠️ **GitHub.com Fallback** ⚠️