-
Notifications
You must be signed in to change notification settings - Fork 119
Overriding functions
MY-BASIC supports overriding functions for prototype
and referenced usertype
.
Class instance
It's accepted to override functions of: TYPE
, VAL
, LEN
, GET
, SET
; PUSH
, POP
, BACK
, INSERT
, SORT
, EXISTS
, INDEX_OF
, REMOVE
, CLEAR
, ITERATOR
, MOVE_NEXT
. Define a member function with an underline (_
) prefix to redirect execution to it. For example _LEN
for overridding LEN
, _PUSH
for overridding PUSH
, and so on. Overridden member functions accept any type and count of arguments, and could return any type of result.
Referenced usertype
Use mb_override_value
to override built-in functions for referenced usertype.
Use MB_MF_FUNC
to override generic functions including: TYPE
, VAL
, LEN
, GET
, SET
.
Use MB_MF_COLL
to override collection functions including: PUSH
, POP
, BACK
, INSERT
, SORT
, EXISTS
, INDEX_OF
, REMOVE
, CLEAR
, ITERATOR
, MOVE_NEXT
.
The function to override with must be a pointer of mb_meta_status_e (* mb_meta_func_t)(struct mb_interpreter_t*, void**, const char*)
. Which returns MB_MS_NONE
if the overridden function hadn't processed it, MB_MS_DONE
of processing done; the return value can be bitwise OR MB_MS_RETURNED
if the overridden function already pushed the return value to the interpreter.
Besides, it's possible to apply the CLONE
statement to a referenced usertype to clone it, it may return nil
if it's non-clonable. You don't need to write extra code to use this.
Others
Read the Overriding operators page to get information about overriding meta operators.
- Principles
- Coding
- Data types
- Standalone shell
- Integration
- Customization
- More scripting API
- FAQ