API documentation¶
Main berry entry API.
This file is part of the Berry default interpreter.
- Author
- Copyright
(c) 2018-2022 Guan Wenliang MIT License (https://github.com/Skiars/berry/blob/master/LICENSE)
native-module member type specifier.
-
BE_CNIL¶
native-module member type specifier.
BE_CNIL
-
BE_CINT¶
BE_CINT
-
BE_CREAL¶
BE_CREAL
-
BE_CBOOL¶
BE_CBOOL
-
BE_CFUNCTION¶
BE_CFUNCTION
-
BE_CSTRING¶
BE_CSTRING
-
BE_CMODULE¶
BE_CMODULE
debug hook typedefs.
-
BE_HOOK_LINE¶
debug hook typedefs.
BE_HOOK_LINE
-
BE_HOOK_CALL¶
BE_HOOK_CALL
-
BE_HOOK_RET¶
BE_HOOK_RET
-
BE_HOOK_EXCEPT¶
BE_HOOK_EXCEPT
Defines
-
BERRY_VERSION¶
do not modify the version number!
-
BE_INTEGER¶
BE_INTEGER
-
BE_INT_FMTLEN¶
BE_INT_FMTLEN
-
BE_INT_FORMAT¶
BE_INT_FORMAT
-
bbool¶
bbool
-
bfalse¶
bfalse
-
btrue¶
btrue
-
BERRY_API¶
API function mark.
-
be_native_module_nil(_name)¶
native module node definition macro
-
be_native_module_int(_name, _v)¶
be_native_module_int
-
be_native_module_real(_name, _v)¶
be_native_module_real
-
be_native_module_bool(_name, _b)¶
be_native_module_bool
-
be_native_module_function(_name, _f)¶
be_native_module_function
-
be_native_module_str(_name, _s)¶
be_native_module_str
-
be_native_module_module(_name, _m)¶
be_native_module_module
-
be_native_module_attr_table(name)¶
be_native_module_attr_table
-
be_native_module(name)¶
be_native_module
-
be_native_class(name)¶
be_native_class
-
be_extern_native_module(name)¶
native module declaration macro
-
be_extern_native_class(name)¶
native class declaration macro
-
be_define_native_module(_name, _init)¶
native module definition macro
-
be_define_local_const_str(_name, _s, _hash, _len)¶
support for solidified berry functions native const strings outside of global string hash
-
be_nested_const_str(_s, _hash, _len)¶
new version for more compact literals
-
be_local_const_str(_name)¶
be_local_const_str
-
BE_IIF(cond)¶
conditional macro see https://stackoverflow.com/questions/11632219/c-preprocessor-macro-specialisation-based-on-an-argument
-
BE_IIF_0(t, f)¶
conditional macro see https://stackoverflow.com/questions/11632219/c-preprocessor-macro-specialisation-based-on-an-argument
-
BE_IIF_1(t, f)¶
conditional macro see https://stackoverflow.com/questions/11632219/c-preprocessor-macro-specialisation-based-on-an-argument
-
be_local_const_upval(ins, idx)¶
be_local_const_upval
-
PROTO_SOURCE_FILE(n)¶
-
PROTO_SOURCE_FILE_STR(n)¶
-
PROTO_RUNTIME_BLOCK¶
conditional block in bproto depending on compilation options
-
PROTO_VAR_INFO_BLOCK¶
PROTO_VAR_INFO_BLOCK.
-
be_define_local_proto(_name, _nstack, _argc, _is_const, _is_subproto, _is_upval)¶
define bproto
-
be_nested_proto(_nstack, _argc, _varg, _has_upval, _upvals, _has_subproto, _protos, _has_const, _ktab, _fname, _source, _code)¶
new version for more compact literals
-
be_define_local_closure(_name)¶
be_define_local_closure
-
be_local_closure(_name, _proto)¶
new version for more compact literals
-
be_assert(expr)¶
the default assert definition
-
be_writestring(s)¶
be_writestring
Note
FFI function
-
be_writenewline()¶
be_writenewline
Note
FFI function
-
be_return(vm)¶
be_return
Note
FFI function
- Parameters:
vm – virtual machine instance virtual machine instance
-
be_return_nil(vm)¶
be_return_nil
Note
FFI function
- Parameters:
vm – virtual machine instance virtual machine instance
-
be_loadfile(vm, name)¶
be_loadfile
Note
FFI function
- Parameters:
vm – virtual machine instance virtual machine instance
name – (???)
-
be_loadmodule(vm, name)¶
be_loadmodule
Note
FFI function
- Parameters:
vm – virtual machine instance virtual machine instance
name –
-
be_loadstring(vm, str)¶
be_loadstring
Note
FFI function
- Parameters:
vm – virtual machine instance virtual machine instance
str – (???)
-
be_dostring(vm, s)¶
be_dostring
Note
FFI function
- Parameters:
vm – virtual machine instance virtual machine instance
s – (???)
Typedefs
-
typedef uint8_t bbyte¶
bbyte
-
typedef BE_INTEGER bint¶
bint
-
typedef double breal¶
breal
-
typedef struct bntvmodobj bntvmodobj_t¶
bntvmodobj_t
-
typedef struct bntvmodule bntvmodule_t¶
bntvmodule_t
-
typedef const struct bclass *bclass_ptr¶
we need only the pointer to
bclass
here
-
typedef bclass_ptr bclass_array[]¶
array of bclass* pointers, NULL terminated
-
typedef void (*bntvhook)(bvm *vm, bhookinfo_t *info)¶
void (*bntvhook)(bvm *vm, bhookinfo *info)
- Param vm:
virtual machine instance
- Param info:
Enums
-
enum berrorcode¶
error code definition
Values:
-
enumerator BE_OK¶
BE_OK
-
enumerator BE_EXIT¶
BE_EXIT
-
enumerator BE_MALLOC_FAIL¶
BE_MALLOC_FAIL
-
enumerator BE_EXCEPTION¶
BE_EXCEPTION
-
enumerator BE_SYNTAX_ERROR¶
BE_SYNTAX_ERROR
-
enumerator BE_EXEC_ERROR¶
BE_EXEC_ERROR
-
enumerator BE_IO_ERROR¶
BE_IO_ERROR
-
enumerator BE_OK¶
-
enum beobshookevents¶
beobshookevents
Values:
-
enumerator BE_OBS_PCALL_ERROR¶
called when be_callp() returned an error, most likely an exception
-
enumerator BE_OBS_GC_START¶
start of GC, arg = allocated size
-
enumerator BE_OBS_GC_END¶
end of GC, arg = allocated size
-
enumerator BE_OBS_VM_HEARTBEAT¶
VM heartbeat called every million instructions
-
enumerator BE_OBS_STACK_RESIZE_START¶
Berry stack resized
-
enumerator BE_OBS_MALLOC_FAIL¶
Memory allocation failed
-
enumerator BE_OBS_PCALL_ERROR¶
Functions
-
BERRY_API bint be_str2int(const char *str, const char **endstr)¶
(???)
Note
FFI function
- Parameters:
str – (???)
endstr – (???)
- Returns:
(???)
-
BERRY_API breal be_str2real(const char *str, const char **endstr)¶
(???)
Note
FFI function
- Parameters:
str –
endstr – (???)
- Returns:
(???)
-
BERRY_API const char *be_str2num(bvm *vm, const char *str)¶
(???)
Note
FFI function
- Parameters:
vm – virtual machine instance virtual machine instance
str – (???)
- Returns:
(???)
-
BERRY_API int be_top(bvm *vm)¶
returns the absolute index value of the top element in the virtual stack
This function returns the absolute index value of the top element in the virtual stack. This value is also the number of elements in the virtual stack (the capacity of the virtual stack). Call this function before adding or subtracting elements in the virtual stack to get the number of parameters of the native function.
Note
FFI function
- Parameters:
vm – virtual machine instance virtual machine instance
- Returns:
(???)
-
BERRY_API const char *be_typename(bvm *vm, int index)¶
converts the type of the Berry object into a string and returns it
This function converts the type of the Berry object into a string and returns it. For example, it returns “int” for an integer object, and “function” for a function object.
Note
FFI function
- Parameters:
vm – virtual machine instance virtual machine instance
index – index of the object to be operated
- Returns:
string corresponding to the parameter type (see: baselib_type)
-
BERRY_API const char *be_classname(bvm *vm, int index)¶
converts the type of the Berry object into a string and returns it.
This function converts the type of the Berry object into a string and returns it. For example, it returns “int” for an integer object, and “function” for a function object
Note
FFI function
- Parameters:
vm – virtual machine instance virtual machine instance
index – index of the object to be operated
- Returns:
string corresponding to the parameter type (see: baselib_type)
-
BERRY_API bbool be_classof(bvm *vm, int index)¶
(???)
Note
FFI function
- Parameters:
vm – virtual machine instance virtual machine instance
index – (???)
- Returns:
(???)
-
BERRY_API int be_strlen(bvm *vm, int index)¶
length of the specified Berry string
This function returns the number of bytes in the string at index (the ‘\0’ characters at the end of the Berry string are not counted). If the value of the index position is not a string, the be_strlen function will return 0. Although the Berry string is compatible with the C string format, it is not recommended to use the strlen function of the C standard library to measure the length of the Berry string. For Berry strings, be_strlen is faster than strlen and has better compatibility.
Note
FFI function
- Parameters:
vm – virtual machine instance virtual machine instance
index – index of the object to be operated
- Returns:
length
-
BERRY_API void be_strconcat(bvm *vm, int index)¶
splice two Berry strings
This function will concatenate the string at the parameter position of index with the string at the top position of the stack, and then put the resulting string into the position indexed by index.
Note
FFI function
- Parameters:
vm – virtual machine instance virtual machine instance
index – (???)
-
BERRY_API void be_pop(bvm *vm, int n)¶
pops the value at the top of the stack
Note that the value of n cannot exceed the capacity of the stack.
Note
FFI function
- Parameters:
vm – virtual machine instance virtual machine instance
n – number of values to be popped
-
BERRY_API void be_remove(bvm *vm, int index)¶
remove a value from the stack
After the value at index is moved out, the following values will be filled forward, and the stack capacity will be reduced by one. The value of index cannot exceed the capacity of the stack.
Note
FFI function
- Parameters:
vm – virtual machine instance virtual machine instance
index – the object to be removed
-
BERRY_API int be_absindex(bvm *vm, int index)¶
absolute index value of a given index value
If index is positive, the return value is the value of index. If index is negative, the return value of textttbe_absindex is the absolute index value corresponding to index. When index is a negative value (relative index), its index position cannot be lower than the bottom of the stack.
Note
FFI function
- Parameters:
vm – virtual machine instance virtual machine instance
index – index value
- Returns:
absolute index
-
BERRY_API bbool be_isnil(bvm *vm, int index)¶
value in virtual stack is nil
This function returns whether the value indexed by the parameter index in the virtual stack is nil, if it is, it returns 1, otherwise it returns 0
Note
FFI function
- Parameters:
vm – virtual machine instance virtual machine instance
index – value index
- Returns:
true/false
-
BERRY_API bbool be_isbool(bvm *vm, int index)¶
value in virtual stack is bool
This function returns whether the value indexed by the parameter index in the virtual stack is bool, if it is, it returns 1, otherwise it returns 0
Note
FFI function
- Parameters:
vm – virtual machine instance virtual machine instance
index – value index
- Returns:
true/false
-
BERRY_API bbool be_isint(bvm *vm, int index)¶
value in virtual stack is int
This function returns whether the value indexed by the parameter index in the virtual stack is int, if it is, it returns 1, otherwise it returns 0
Note
FFI function
- Parameters:
vm – virtual machine instance virtual machine instance
index – value index
- Returns:
true/false
-
BERRY_API bbool be_isreal(bvm *vm, int index)¶
value in virtual stack is real
This function returns whether the value indexed by the parameter index in the virtual stack is real, if it is, it returns 1, otherwise it returns 0
Note
FFI function
- Parameters:
vm – virtual machine instance virtual machine instance
index – value index
- Returns:
true/false
-
BERRY_API bbool be_isnumber(bvm *vm, int index)¶
value in virtual stack is number
This function returns whether the value indexed by the parameter index in the virtual stack is number, if it is, it returns 1, otherwise it returns 0
Note
FFI function
- Parameters:
vm – virtual machine instance virtual machine instance
index – value index
- Returns:
true/false
-
BERRY_API bbool be_isstring(bvm *vm, int index)¶
value in virtual stack is string
This function returns whether the value indexed by the parameter index in the virtual stack is string, if it is, it returns 1, otherwise it returns 0
Note
FFI function
- Parameters:
vm – virtual machine instance
index – value index
- Returns:
true/false
-
BERRY_API bbool be_isclosure(bvm *vm, int index)¶
value in virtual stack is closure
This function returns whether the value indexed by the parameter index in the virtual stack is closure, if it is, it returns 1, otherwise it returns 0
Note
FFI function
- Parameters:
vm – virtual machine instance
index – value index
- Returns:
true/false
-
BERRY_API bbool be_isntvclos(bvm *vm, int index)¶
value in virtual stack is primitive closure type
This function returns whether the value indexed by the parameter index in the virtual stack is primitive closure type, if it is, it returns 1, otherwise it returns 0
Note
FFI function
- Parameters:
vm – virtual machine instance
index – value index
- Returns:
true/false
-
BERRY_API bbool be_isfunction(bvm *vm, int index)¶
value in virtual stack is function
This function returns whether the value indexed by the parameter index in the virtual stack is function, if it is, it returns 1, otherwise it returns 0
Note
FFI function
- Parameters:
vm – virtual machine instance virtual machine instance
index – value index
- Returns:
true/false
-
BERRY_API bbool be_isproto(bvm *vm, int index)¶
value in virtual stack is proto
This function returns whether the value indexed by the parameter index in the virtual stack is proto, if it is, it returns 1, otherwise it returns 0
Note
FFI function
- Parameters:
vm – virtual machine instance virtual machine instance
index – value index
- Returns:
true/false
-
BERRY_API bbool be_isclass(bvm *vm, int index)¶
value in virtual stack is class
This function returns whether the value indexed by the parameter index in the virtual stack is class, if it is, it returns 1, otherwise it returns 0
Note
FFI function
- Parameters:
vm – virtual machine instance virtual machine instance
index – value index
- Returns:
true/false
-
BERRY_API bbool be_isinstance(bvm *vm, int index)¶
value in virtual stack is instance
This function returns whether the value indexed by the parameter index in the virtual stack is instance, if it is, it returns 1, otherwise it returns 0
Note
FFI function
- Parameters:
vm – virtual machine instance virtual machine instance
index – value index
- Returns:
true/false
-
BERRY_API bbool be_ismapinstance(bvm *vm, int index)¶
value in virtual stack is instance
This function returns whether the value indexed by the parameter index in the virtual stack is an instance of class map (or derived). If it is, it returns 1, otherwise it returns 0
This function returns whether the value indexed by the parameter index in the virtual stack is an instance of class list (or derived). If it is, it returns 1, otherwise it returns 0
Note
FFI function
Note
FFI function
- Parameters:
vm – virtual machine instance virtual machine instance
index – value index
vm – virtual machine instance virtual machine instance
index – value index
- Returns:
true/false
- Returns:
true/false
-
BERRY_API bbool be_ismodule(bvm *vm, int index)¶
value in virtual stack is module
This function returns whether the value indexed by the parameter index in the virtual stack is module, if it is, it returns 1, otherwise it returns 0
Note
FFI function
- Parameters:
vm – virtual machine instance virtual machine instance
index – value index
- Returns:
true/false
-
BERRY_API bbool be_islist(bvm *vm, int index)¶
value in virtual stack is list
This function returns whether the value indexed by the parameter index in the virtual stack is list, if it is, it returns 1, otherwise it returns 0
Note
FFI function
- Parameters:
vm – virtual machine instance
index – value index
- Returns:
true/false
-
BERRY_API bbool be_ismap(bvm *vm, int index)¶
value in virtual stack is map
This function returns whether the value indexed by the parameter index in the virtual stack is map, if it is, it returns 1, otherwise it returns 0
Note
FFI function
- Parameters:
vm – virtual machine instance
index – value index
- Returns:
true/false
-
BERRY_API bbool be_iscomptr(bvm *vm, int index)¶
value in virtual stack is universal pointer type
This function returns whether the value indexed by the parameter index in the virtual stack is universal pointer type, if it is, it returns 1, otherwise it returns 0
Note
FFI function
- Parameters:
vm – virtual machine instance
index – value index
- Returns:
true/false
-
BERRY_API bbool be_iscomobj(bvm *vm, int index)¶
(???)
Note
FFI function
- Parameters:
vm – virtual machine instance virtual machine instance
index – value index
- Returns:
true/false
-
BERRY_API bbool be_isderived(bvm *vm, int index)¶
(???)
Note
FFI function
- Parameters:
vm – virtual machine instance virtual machine instance
index – value index
- Returns:
true/false
-
BERRY_API bbool be_isbytes(bvm *vm, int index)¶
value in virtual stack is instance or sub-instance of class bytes
This function returns whether the value indexed by the parameter index in the virtual stack is instance or sub-instance of class bytes, if it is, it returns 1, otherwise it returns 0
Note
FFI function
- Parameters:
vm – virtual machine instance virtual machine instance
index – value index
- Returns:
true/false
-
BERRY_API bint be_toint(bvm *vm, int index)¶
virtual stack to integer type
Get the value of the index position of index from the virtual stack and return it as an integer type. This function does not check the correctness of the type. If the value is an instance, the method toint() is called if it exists.
Note
FFI function
- Parameters:
vm – virtual machine instance virtual machine instance
index – value index
- Returns:
(???)
-
BERRY_API breal be_toreal(bvm *vm, int index)¶
virtual stack to floating-point number type
Get the value of the index position of index from the virtual stack and return it as an floating-point number type. This function does not check the correctness of the type.
Note
FFI function
- Parameters:
vm – virtual machine instance virtual machine instance
index –
- Returns:
(???)
-
BERRY_API int be_toindex(bvm *vm, int index)¶
virtual stack to integer type
Get the value of the index position of index from the virtual stack and return it as an integer type. This function does not check the correctness of the type. Unlike be_toint, the return value type of be_toindex is int, while the return value of the former is bint.
Note
FFI function
- Parameters:
vm – virtual machine instance virtual machine instance
index –
- Returns:
(???)
-
BERRY_API bbool be_tobool(bvm *vm, int index)¶
virtual stack to Boolean type
Get the value of the index position of index from the virtual stack and return it as a Boolean type. If the indexed value is not of Boolean type, it will be converted according to the rules in section type_bool, and the conversion process will not cause the indexed value to change. If the value is an instance, the method tobool() is called if it exists.
Note
FFI function
- Parameters:
vm – virtual machine instance virtual machine instance
index –
- Returns:
(???)
-
BERRY_API const char *be_tostring(bvm *vm, int index)¶
virtual stack to string
Get the value of the index position of index from the virtual stack and return it as a string type. If the indexed value is not a string type, the indexed value will be converted to a string, and the conversion process will replace the value at the indexed position in the virtual stack with the converted string. The string returned by this function always ends with ‘\0’ characters. If the value is an instance, the method tostring() is called if it exists.
Note
FFI function
- Parameters:
vm – virtual machine instance virtual machine instance
index –
- Returns:
(???)
-
BERRY_API const char *be_toescape(bvm *vm, int index, int mode)¶
(???)
Note
FFI function
- Parameters:
vm – virtual machine instance virtual machine instance
index –
mode –
- Returns:
(???)
-
BERRY_API void *be_tocomptr(bvm *vm, int index)¶
virtual stack to general pointer
Get the value of the index position of index from the virtual stack and return it as a general pointer type. This function does not check the correctness of the type.
Note
FFI function
- Parameters:
vm – virtual machine instance virtual machine instance
index –
-
BERRY_API void be_moveto(bvm *vm, int from, int to)¶
(???)
Note
FFI function
- Parameters:
vm – virtual machine instance virtual machine instance
from –
to –
-
BERRY_API void be_pushnil(bvm *vm)¶
Push a nil value onto the virtual stack.
Note
FFI function
- Parameters:
vm – virtual machine instance
-
BERRY_API void be_pushbool(bvm *vm, int b)¶
Push a Boolean value onto the virtual stack.
Push a Boolean value onto the virtual stack. The parameter b is the boolean value to be pushed onto the stack. When the value is 0, it means false, otherwise it is true.
Note
FFI function
- Parameters:
vm – virtual machine instance
b –
-
BERRY_API void be_pushint(bvm *vm, bint i)¶
Push an integer value i onto the virtual stack.
Note
FFI function
- Parameters:
vm – virtual machine instance
i –
-
BERRY_API void be_pushreal(bvm *vm, breal r)¶
Push a floating point value r onto the virtual stack.
Note
FFI function
- Parameters:
vm – virtual machine instance
r –
-
BERRY_API void be_pushstring(bvm *vm, const char *str)¶
Push the string str onto the virtual stack.
Push the string str onto the virtual stack. The parameter str must point to a C string that ends with a null character ‘\0’, and a null pointer cannot be passed in.
Note
FFI function
- Parameters:
vm – virtual machine instance
str –
-
BERRY_API void be_pushnstring(bvm *vm, const char *str, size_t n)¶
Push the string str of length n onto the virtual stack.
Push the string str of length n onto the virtual stack. The length of the string is subject to the parameter n, and the null character is not used as the end mark of the string.
Note
FFI function
- Parameters:
vm – virtual machine instance
str –
n –
-
BERRY_API const char *be_pushfstring(bvm *vm, const char *format, ...)¶
Push the formatted string into the virtual stack.
Push the formatted string into the virtual stack. The parameter format is a formatted string, which contains the text to be pushed onto the stack, and the format parameter contains a label, which can be replaced by the value specified by the subsequent additional parameter and formatted as required. According to the label of the format string, a series of additional parameters may be required, and each additional parameter will replace the corresponding % label in the format parameter.
Note
FFI function
- Parameters:
vm – virtual machine instance
format –
- Returns:
(???)
-
BERRY_API void *be_pushbuffer(bvm *vm, size_t size)¶
(???)
Note
FFI function
- Parameters:
vm – virtual machine instance
size –
-
BERRY_API void be_pushvalue(bvm *vm, int index)¶
Push the value with index index onto the top of the virtual stack.
Note
FFI function
- Parameters:
vm – virtual machine instance
index –
-
BERRY_API void be_pushclosure(bvm *vm, void *cl)¶
(???)
Note
FFI function
- Parameters:
vm – virtual machine instance
cl –
-
BERRY_API void be_pushntvclosure(bvm *vm, bntvfunc f, int nupvals)¶
Push a native closure onto the top of the virtual stack.
Push a native closure onto the top of the virtual stack. The parameter f is the C function pointer of the native closure, and nupvals is the upvalue number of the closure.
Note
FFI function
- Parameters:
vm – virtual machine instance
f –
nupvals –
-
BERRY_API void be_pushntvfunction(bvm *vm, bntvfunc f)¶
Push a native function onto the top of the virtual stack, and the parameter f is the native function pointer.
Note
FFI function
- Parameters:
vm – virtual machine instance
f –
-
BERRY_API void be_pushclass(bvm *vm, const char *name, const bnfuncinfo *lib)¶
Push a native class onto the top of the virtual stack.
Push a native class onto the top of the virtual stack. The parameter name is the name of the native class, and the parameter lib is the attribute description of the native class.
Note
FFI function
- Parameters:
vm – virtual machine instance
name –
lib –
-
BERRY_API void be_pushntvclass(bvm *vm, const struct bclass *c)¶
(???)
Note
FFI function
- Parameters:
vm – virtual machine instance
c –
-
BERRY_API void be_pushcomptr(bvm *vm, void *ptr)¶
Push a general pointer onto the top of the virtual stack.
Push a general pointer onto the top of the virtual stack. The general pointer ptr points to a certain C data area. Since the content pointed to by this pointer is not maintained by Berry’s garbage collector, users have to maintain the life cycle of the data themselves.
Note
FFI function
- Parameters:
vm – virtual machine instance
ptr –
-
BERRY_API bbool be_pushiter(bvm *vm, int index)¶
Push an iterator onto the top of the virtual stack.
Note
FFI function
- Parameters:
vm – virtual machine instance
index –
- Returns:
(???)
-
BERRY_API void be_newlist(bvm *vm)¶
creates a new list value
After this function is successfully called, the new list value will be pushed onto the top of the stack. list value is an internal representation of a list, not to be confused with an instance of the list class.
Note
FFI function
- Parameters:
vm – virtual machine instance
-
BERRY_API void be_newmap(bvm *vm)¶
creates a new map value
After this function is successfully called, the new map value will be pushed onto the top of the stack. map value is an internal representation of a list, not to be confused with an instance of the map class.
Note
FFI function
- Parameters:
vm – virtual machine instance
-
BERRY_API void be_newmodule(bvm *vm)¶
(???)
Note
FFI function
- Parameters:
vm – virtual machine instance
-
BERRY_API void be_newcomobj(bvm *vm, void *data, bntvfunc destroy)¶
(???)
Note
FFI function
- Parameters:
vm – virtual machine instance
data –
destroy –
-
BERRY_API void be_newobject(bvm *vm, const char *name)¶
(???)
Note
FFI function
- Parameters:
vm – virtual machine instance
name –
-
BERRY_API bbool be_copy(bvm *vm, int index)¶
(???)
Note
FFI function
- Parameters:
vm – virtual machine instance
index –
- Returns:
-
BERRY_API bbool be_setname(bvm *vm, int index, const char *name)¶
(???)
Note
FFI function
- Parameters:
vm – virtual machine instance
index –
name –
- Returns:
(???)
-
BERRY_API bbool be_getglobal(bvm *vm, const char *name)¶
pushes the global variable with the specified name onto the stack
After this function is called, the global variable named name will be pushed onto the top of the virtual stack
Note
FFI function
- Parameters:
vm – virtual machine instance
name –
- Returns:
(???)
-
BERRY_API void be_setglobal(bvm *vm, const char *name)¶
(???)
Note
FFI function
- Parameters:
vm – virtual machine instance
name –
-
BERRY_API bbool be_getbuiltin(bvm *vm, const char *name)¶
(???)
Note
FFI function
- Parameters:
vm – virtual machine instance
name –
- Returns:
(???)
-
BERRY_API bbool be_setmember(bvm *vm, int index, const char *k)¶
set the value of the member variable of the instance object class
This function will copy the value at the top of the stack to the member k of the index position instance. Note that the top element of the stack will not pop up automatically.
Note
FFI function
- Parameters:
vm – virtual machine instance
index – index of the instance object
k – name of the member
- Returns:
(???)
-
BERRY_API bbool be_getmember(bvm *vm, int index, const char *k)¶
get the value of the member variable of the instance object class
This function pushes the value of the member of the index position instance k onto the top of the virtual stack.
Note
FFI function
- Parameters:
vm – virtual machine instance
index – index of the instance object
k – name of the member
- Returns:
(???)
-
BERRY_API bbool be_getmethod(bvm *vm, int index, const char *k)¶
(???)
Note
FFI function
- Parameters:
vm – virtual machine instance
index –
k –
- Returns:
(???)
-
BERRY_API bbool be_getindex(bvm *vm, int index)¶
get the value of list or map
This function is used to get an element from the map or list container (internal values, not instances of map or list classes), and the index of the element is stored at the top of the stack (relative index is -1). After calling this function, the value obtained from the container will be pushed onto the top of the stack. If there is no subscript pointed to by the container, the value of nil will be pushed onto the top of the stack.
Note
FFI function
- Parameters:
vm – virtual machine instance
index – index of the object to be operated
- Returns:
(???)
-
BERRY_API bbool be_setindex(bvm *vm, int index)¶
set a value in list or map
This function is used to write an element of the map or list container. The index of the value to be written in the virtual stack is -1, and the index of the subscript of the write position in the virtual stack is -2. If the element with the specified subscript does not exist in the container, the write operation will fail.
Note
FFI function
- Parameters:
vm – virtual machine instance
index – index of the object to be operated
- Returns:
(???)
-
BERRY_API void be_getupval(bvm *vm, int index, int pos)¶
read an Up Value of the native closure
The read Up Value will be pushed onto the top of the virtual stack.
Note
FFI function
- Parameters:
vm – virtual machine instance
index – the native closure index value of the Up Value to be read
pos – position of the Up Value in the native closure Up Value table (numbering starts from 0)
-
BERRY_API bbool be_setupval(bvm *vm, int index, int pos)¶
set an Up Value of the native closure.
This function obtains a value from the top of the virtual stack and writes it to the target Up Value. After the operation is completed, the top value of the stack will not be popped from the stack.
Note
FFI function
- Parameters:
vm – virtual machine instance
index – the native closure index value of the Up Value to be read
pos – position of the Up Value in the native closure Up Value table (numbering starts from 0)
- Returns:
(???)
-
BERRY_API bbool be_setsuper(bvm *vm, int index)¶
(???)
Note
FFI function
- Parameters:
vm – virtual machine instance
index –
- Returns:
(???)
-
BERRY_API void be_getsuper(bvm *vm, int index)¶
get the parent object of the base class or instance of the class.
If the value at index is a class with a base class, the function will push its base class onto the top of the stack; if the value at index is an object with a parent object, the function will take its parent The object is pushed onto the top of the stack; otherwise, a value of nil is pushed onto the top of the stack.
Note
FFI function
- Parameters:
vm – virtual machine instance
index – the class or object to be operated
-
BERRY_API int be_data_size(bvm *vm, int index)¶
get the number of elements contained in the container
If the value at index is a Map value or List value, the function returns the number of elements contained in the container, otherwise it returns -1.
Note
FFI function
- Parameters:
vm – virtual machine instance
index – index of the container object to be operated
- Returns:
(???)
-
BERRY_API void be_data_push(bvm *vm, int index)¶
append a new element to the end of the container.
The object at index must be a List value. This function gets a value from the top of the stack and appends it to the end of the container. After the operation is completed, the value at the top of the stack will not be popped from the stack.
Note
FFI function
- Parameters:
vm – virtual machine instance
index – index of the container object to be operate
-
BERRY_API bbool be_data_insert(bvm *vm, int index)¶
insert a pair of elements into the container
The object at index must be a List value or a Map value. The inserted element forms a pair of key-value pairs. The value is stored at the top of the stack, and the key is stored at the previous index on the top of the stack. It should be noted that the key inserted into the Map container cannot be a nil value, and the key inserted into the List container must be an integer value. If the operation is successful, the function will return bture, otherwise it will return bfalse.
Note
FFI function
- Parameters:
vm – virtual machine instance
index – container object to be operated
- Returns:
(???)
-
BERRY_API bbool be_data_remove(bvm *vm, int index)¶
remove an element in the container
The object at index must be a List value or Map value. For the Map container, the key to delete the element is stored on the top of the virtual stack (need to be pressed before the function call); for the List container, the index of the element to be deleted is stored on the top of the virtual stack (need to be before the function call) push into). If the operation is successful, the function will return bture, otherwise it will return bfalse.
Note
FFI function
- Parameters:
vm – virtual machine instance
index – container object to be operated.
- Returns:
(???)
-
BERRY_API bbool be_data_merge(bvm *vm, int index)¶
(???)
Note
FFI function
- Parameters:
vm – virtual machine instance
index –
- Returns:
(???)
-
BERRY_API void be_data_resize(bvm *vm, int index)¶
reset the capacity of the container
This function is only available for List containers, and the new capacity is stored on the top of the virtual stack (must be an integer).
Note
FFI function
- Parameters:
vm – virtual machine instance
index – container object to be operated
-
BERRY_API void be_data_reverse(bvm *vm, int index)¶
(???)
Note
FFI function
- Parameters:
vm – virtual machine instance
index –
-
BERRY_API int be_iter_next(bvm *vm, int index)¶
get the next element of the iterator
The iterator object may be an iterator of a List container or a Map container. For the List iterator, this function pushes the iteration result value onto the top of the stack, while for the Map iterator, it pushes the key value into the previous position and the top of the stack respectively. Calling this function will update the iterator. If the function returns 0, the call fails, returning 1 to indicate that the current iterator is a List iterator, and returning 2 to indicate that the current iterator is a Map iterator.
Note
FFI function
- Parameters:
vm – virtual machine instance
index – iterator to be operated
- Returns:
(???)
-
BERRY_API bbool be_iter_hasnext(bvm *vm, int index)¶
test whether there is another element in the iterator
The iterator object may be an iterator of a List container or a Map container. If there are more iterable elements in the iterator, return 1, otherwise return 0.
Note
FFI function
- Parameters:
vm – virtual machine instance
index – iterator to be operated
- Returns:
(???)
-
BERRY_API bbool be_refcontains(bvm *vm, int index)¶
test whether there is a reference to the specified object in the reference stack
This function is used to test whether there is a reference to the specified object in the reference stack. It must be used in conjunction with be_refpush and be_refpop. This API can avoid recursion when traversing objects that have their own references. This function is used for the value of an instance type. If there is a reference to the object in the reference stack, it returns 1, otherwise it returns 0.
Note
FFI function
- Parameters:
vm – virtual machine instance
index – object to be operated
- Returns:
(???)
-
BERRY_API void be_refpush(bvm *vm, int index)¶
Push the reference of the specified object onto the reference stack.
This function is used for the value of an instance type.
Note
FFI function
- Parameters:
vm – virtual machine instance
index – object to be operated
-
BERRY_API void be_refpop(bvm *vm)¶
Pop the object at the top of the reference stack.
This function is used in pairs with be_refpush
Note
FFI function
- Parameters:
vm – virtual machine instance
-
BERRY_API void be_stack_require(bvm *vm, int count)¶
tests the amount of free space on the stack and expands the stack space if it is insufficient
If the free capacity of the virtual stack allocated by the VM to the native function is lower than this value, an expansion operation will be performed.
Note
FFI function
- Parameters:
vm – virtual machine instance
count – required free stack capacity.
-
BERRY_API bbool be_getmodule(bvm *vm, const char *k)¶
(???)
Note
FFI function
- Parameters:
vm – virtual machine instance
k –
- Returns:
(???)
-
BERRY_API bbool be_iseq(bvm *vm)¶
(???)
Note
relop operation API
- Parameters:
vm – virtual machine instance
- Returns:
(???)
-
BERRY_API bbool be_isneq(bvm *vm)¶
(???)
Note
relop operation API
- Parameters:
vm – virtual machine instance
- Returns:
(???)
-
BERRY_API bbool be_islt(bvm *vm)¶
(???)
Note
relop operation API
- Parameters:
vm – virtual machine instance
- Returns:
(???)
-
BERRY_API bbool be_isle(bvm *vm)¶
(???)
Note
relop operation API
- Parameters:
vm – virtual machine instance
- Returns:
(???)
-
BERRY_API bbool be_isgt(bvm *vm)¶
(???)
Note
relop operation API
- Parameters:
vm – virtual machine instance
- Returns:
(???)
-
BERRY_API bbool be_isge(bvm *vm)¶
(???)
Note
relop operation API
- Parameters:
vm – virtual machine instance
- Returns:
(???)
-
BERRY_API int be_returnvalue(bvm *vm)¶
(???)
Note
Function call/return API
- Parameters:
vm – virtual machine instance
- Returns:
(???)
-
BERRY_API int be_returnnilvalue(bvm *vm)¶
(???)
Note
Function call/return API
- Parameters:
vm – virtual machine instance
- Returns:
(???)
-
BERRY_API void be_call(bvm *vm, int argc)¶
(???)
Note
Function call/return API
- Parameters:
vm – virtual machine instance
argc –
-
BERRY_API int be_pcall(bvm *vm, int argc)¶
(???)
Note
Function call/return API
- Parameters:
vm – virtual machine instance
argc –
- Returns:
(???)
-
BERRY_API void be_exit(bvm *vm, int status)¶
(???)
Note
Function call/return API
- Parameters:
vm – virtual machine instance
status –
-
BERRY_API void be_raise(bvm *vm, const char *except, const char *msg)¶
(???)
Note
exception API
- Parameters:
vm – virtual machine instance
except –
msg –
-
BERRY_API int be_getexcept(bvm *vm, int code)¶
(???)
Note
exception API
- Parameters:
vm – virtual machine instance
code –
- Returns:
(???)
-
BERRY_API void be_dumpvalue(bvm *vm, int index)¶
(???)
Note
exception API
- Parameters:
vm – virtual machine instance
index –
-
BERRY_API void be_dumpexcept(bvm *vm)¶
(???)
Note
exception API
- Parameters:
vm – virtual machine instance
-
BERRY_API void be_stop_iteration(bvm *vm)¶
(???)
Note
exception API
- Parameters:
vm – virtual machine instance
-
BERRY_API void be_regfunc(bvm *vm, const char *name, bntvfunc f)¶
register a native function
The specific behavior of this function is related to the value of the BE_USE_PRECOMPILED_OBJECT macro (although the FFI is still available when using the compile-time construction technique, it cannot dynamically register the built-in variables. In this case, please refer to the method of registering the built-in objects.
Note
exception API
- Parameters:
vm – virtual machine instance
name – name of the native function
f – pointer of the native function
-
BERRY_API void be_regclass(bvm *vm, const char *name, const bnfuncinfo *lib)¶
(???)
Note
exception API
- Parameters:
vm – virtual machine instance
name –
lib –
-
BERRY_API void be_vm_delete(bvm *vm)¶
Destroy a VM.
Note
VM management API
- Parameters:
vm – virtual machine instance
-
BERRY_API void be_set_obs_hook(bvm *vm, bobshook hook)¶
(???)
Note
Observability hook
- Parameters:
vm – virtual machine instance
hook –
-
BERRY_API void be_set_ctype_func_hanlder(bvm *vm, bctypefunc handler)¶
(???)
Note
Observability hook
- Parameters:
vm – virtual machine instance
handler –
-
BERRY_API bctypefunc be_get_ctype_func_hanlder(bvm *vm)¶
(???)
Note
Observability hook
- Parameters:
vm – virtual machine instance
- Returns:
(???)
-
BERRY_API int be_loadbuffer(bvm *vm, const char *name, const char *buffer, size_t length)¶
load a piece of source code from the buffer and compile it into bytecode
f the compilation is successful, be_loadbuffer will compile the source code into a Berry function and place it on the top of the virtual stack. If the compilation encounters an error, be_loadbuffer will return an error value of type berrorcode (Section errorcode), and if possible, will store the specific error message string at the top of the virtual stack.
Note
code load API
- Parameters:
vm – virtual machine instance
name – string, which is usually used to mark the source of the source code
buffer – buffer for storing the source code
length – length of the buffer
- Returns:
(???)
-
BERRY_API int be_loadmode(bvm *vm, const char *name, bbool islocal)¶
(???)
Note
code load API
- Parameters:
vm – virtual machine instance
name –
islocal –
- Returns:
(???)
-
BERRY_API int be_loadlib(bvm *vm, const char *path)¶
(???)
Note
code load API
- Parameters:
vm – virtual machine instance
path –
- Returns:
(???)
-
BERRY_API int be_savecode(bvm *vm, const char *name)¶
(???)
Note
code load API
- Parameters:
vm – virtual machine instance
name –
- Returns:
(???)
-
BERRY_API void be_module_path(bvm *vm)¶
(???)
Note
module path list API
- Parameters:
vm – virtual machine instance
-
BERRY_API void be_module_path_set(bvm *vm, const char *path)¶
(???)
Note
module path list API
- Parameters:
vm – virtual machine instance
path –
-
BERRY_API void *be_pushbytes(bvm *vm, const void *buf, size_t len)¶
Push a bytes() buffer.
Note
bytes operation
- Parameters:
vm – virtual machine instance
buf – starting at position
len – size
-
BERRY_API const void *be_tobytes(bvm *vm, int index, size_t *len)¶
return virtual stack as a bytes buffer
Get the value of the index position of index from the virtual stack and return it as a bytes buffer. The pointer of the buffer is returned, and the size is stored in *len (unless len is NULL). This function works only for instances of the bytes class, or returns NULL.
Note
bytes operation
- Parameters:
vm – virtual machine instance
index – index from the virtual stac
len – size
-
BERRY_API void be_sethook(bvm *vm, const char *mask)¶
(???)
Note
debug API
- Parameters:
vm – virtual machine instance
mask –
-
BERRY_API void be_setntvhook(bvm *vm, bntvhook hook, void *data, int mask)¶
(???)
Note
debug API
- Parameters:
vm – virtual machine instance
hook –
data –
mask –
-
BERRY_API void be_writebuffer(const char *buffer, size_t length)¶
implement on berry_port.c
Output a piece of data to the standard output device, the parameter
buffer
is the first address of the output data block, andlength
is the length of the output data block. This function outputs to thestdout
file by default. Inside the interpreter, this function is usually used as a character stream output, not a binary stream.Note
basic character IO API
- Parameters:
buffer –
length –
-
BERRY_API char *be_readstring(char *buffer, size_t size)¶
implement on berry_port.c
Input a piece of data from the standard input device, and read at most one row of data each time this function is called. The parameter
buffer
is the data buffer passed in by the caller, and the capacity of the buffer issize
. This function will stop reading and return when the buffer capacity is used up, otherwise it will return when a newline character or end of file character is read. If the function executes successfully, it will directly use thebuffer
parameter as the return value, otherwise it will returnNULL
.This function will add the read line breaks to the read data, and each time the
be_readstring
function is called, it will continue to read from the current position. This function is only called in the implementation of the native functioninput
, and thebe_readstring
function may not be implemented when it is not necessary.Note
basic character IO API
- Parameters:
buffer –
size –
- Returns:
(???)
-
struct bnfuncinfo¶
- #include <berry.h>
native function information
-
struct bntvmodule¶
- #include <berry.h>
bntvmodule
Public Members
-
const char *name¶
native module name
-
const bntvmodobj_t *attrs¶
native module attributes
-
size_t size¶
native module attribute count
-
const struct bmodule *module¶
const module object
-
const char *name¶
-
struct bhookinfo¶
- #include <berry.h>
bhookinfo