wrenbind17::VM #
Module: Wrenbind17
Holds the entire Wren VM from which all of the magic happens.
#include <vm.hpp>
Public Classes #
Name | |
---|---|
class | Data |
Public Functions #
Name | |
---|---|
VM(std::vector< std::string > paths ={”./"}, const size_t initHeap =1024 *1024, const size_t minHeap =1024 *1024 *10, const int heapGrowth =50)The only constructor available. | |
VM(const VM & other) | |
VM(VM && other) | |
~VM() =default | |
VM & | operator=(const VM & other) |
VM & | operator=(VM && other) |
void | swap(VM & other) |
void | runFromSource(const std::string & name, const std::string & code)Runs a Wren source code by passing it as a string. |
void | runFromFile(const std::string & name, const std::string & path)Runs a Wren source code directly from a file. |
void | runFromModule(const std::string & name)Runs a Wren source code by passing it as a string. |
Variable | find(const std::string & module, const std::string & name)Looks up a variable from a module. |
ForeignModule & | module(const std::string & name)Creates a new custom module. |
void | addClassType(const std::string & module, const std::string & name, const size_t hash) |
void | getClassType(std::string & module, std::string & name, const size_t hash) |
bool | isClassRegistered(const size_t hash) const |
void | addClassCast(std::shared_ptr< detail::ForeignPtrConvertor > convertor, const size_t hash, const size_t other) |
detail::ForeignPtrConvertor * | getClassCast(const size_t hash, const size_t other) |
std::string | getLastError() |
void | setNextError(std::string str) |
void | setPrintFunc(const PrintFn & fn)Set a custom print function that is used by the System.print() |
void | setLoadFileFunc(const LoadFileFn & fn)Set a custom loader function for imports. |
void | gc()Runs the garbage collector. |
Public Functions Documentation #
function VM #
inline explicit VM(
std::vector< std::string > paths ={"./"},
const size_t initHeap =1024 *1024,
const size_t minHeap =1024 *1024 *10,
const int heapGrowth =50
)
The only constructor available.
Parameters:
- paths The lookup paths used by the import loader function
- initHeap The size of the heap at the beginning
- minHeap The minimum size of the heap
- heapGrowth How the heap should grow
function VM #
inline VM(
const VM & other
)
function VM #
inline VM(
VM && other
)
function ~VM #
inline ~VM() =default
function operator= #
inline VM & operator=(
const VM & other
)
function operator= #
inline VM & operator=(
VM && other
)
function swap #
inline void swap(
VM & other
)
function runFromSource #
inline void runFromSource(
const std::string & name,
const std::string & code
)
Runs a Wren source code by passing it as a string.
Parameters:
- name The module name to assign this code into, this module name can be then used to import this code in some other place
- code Your raw multiline Wren code
Exceptions:
- CompileError if the compilation has failed
function runFromFile #
inline void runFromFile(
const std::string & name,
const std::string & path
)
Runs a Wren source code directly from a file.
Parameters:
- name The module name to assign this code into, this module name can be then used to import this code in some other place
- path The path to the file
Exceptions:
- Exception if the file has not been found or the file cannot be read
- CompileError if the compilation has failed
function runFromModule #
inline void runFromModule(
const std::string & name
)
Runs a Wren source code by passing it as a string.
Parameters:
- name The module name to load, this will use the loader function to load the file from
Exceptions:
- CompileError if the compilation has failed
See: setLoadFileFunc
function find #
inline Variable find(
const std::string & module,
const std::string & name
)
Looks up a variable from a module.
Parameters:
- module The name of the module to look for the variable in
- name The name of the variable or a class itself that must start with a capital letter
Exceptions:
- NotFound if the variable has not been found
function module #
inline ForeignModule & module(
const std::string & name
)
Creates a new custom module.
Note: Calling this function multiple times with the same name does not create a new module, but instead it returns the same module.
function addClassType #
inline void addClassType(
const std::string & module,
const std::string & name,
const size_t hash
)
function getClassType #
inline void getClassType(
std::string & module,
std::string & name,
const size_t hash
)
function isClassRegistered #
inline bool isClassRegistered(
const size_t hash
) const
function addClassCast #
inline void addClassCast(
std::shared_ptr< detail::ForeignPtrConvertor > convertor,
const size_t hash,
const size_t other
)
function getClassCast #
inline detail::ForeignPtrConvertor * getClassCast(
const size_t hash,
const size_t other
)
function getLastError #
inline std::string getLastError()
function setNextError #
inline void setNextError(
std::string str
)
function setPrintFunc #
inline void setPrintFunc(
const PrintFn & fn
)
Set a custom print function that is used by the System.print()
See: PrintFn
function setLoadFileFunc #
inline void setLoadFileFunc(
const LoadFileFn & fn
)
Set a custom loader function for imports.
See: LoadFileFn
This must be a function that accepts a std::vector of strings (which are the lookup paths from the constructor) and the name of the import as the second parameter. You must return the source code from this custom function. If you want to cancel the import, simply throw an exception.
function gc #
inline void gc()
Runs the garbage collector.
Updated on 17 October 2023 at 12:26:25 UTC