diff --git a/HISTORY b/HISTORY index d99d6c6..72a036e 100755 --- a/HISTORY +++ b/HISTORY @@ -1,3 +1,6 @@ +Jul. 24 2017 +Added an mb_get_var_name function + Jul. 7 2017 Added support to apply the FOR statement to an iterable class instance diff --git a/MY-BASIC Quick Reference.pdf b/MY-BASIC Quick Reference.pdf index 495e874..2d53c55 100644 Binary files a/MY-BASIC Quick Reference.pdf and b/MY-BASIC Quick Reference.pdf differ diff --git a/core/my_basic.c b/core/my_basic.c index 1c72670..f4a2880 100755 --- a/core/my_basic.c +++ b/core/my_basic.c @@ -12513,6 +12513,32 @@ _exit: return result; } +/* Get the name of a variable */ +int mb_get_var_name(struct mb_interpreter_t* s, void* v, char** n) { + int result = MB_FUNC_OK; + _object_t* obj = 0; + + if(n) *n = 0; + + if(!s) { + result = MB_FUNC_ERR; + + goto _exit; + } + + if(!n || !v) + goto _exit; + + obj = (_object_t*)v; + if(obj->type != _DT_VAR) + goto _exit; + + if(n) *n = obj->data.variable->name; + +_exit: + return result; +} + /* Get the value of a variable */ int mb_get_var_value(struct mb_interpreter_t* s, void* v, mb_value_t* val) { int result = MB_FUNC_OK; diff --git a/core/my_basic.h b/core/my_basic.h index b237421..4c0eb6d 100755 --- a/core/my_basic.h +++ b/core/my_basic.h @@ -631,6 +631,7 @@ MBAPI int mb_set_class_userdata(struct mb_interpreter_t* s, void** l, void* d); MBAPI int mb_get_value_by_name(struct mb_interpreter_t* s, void** l, const char* n, mb_value_t* val); MBAPI int mb_add_var(struct mb_interpreter_t* s, void** l, const char* n, mb_value_t val, bool_t force); MBAPI int mb_get_var(struct mb_interpreter_t* s, void** l, void** v); +MBAPI int mb_get_var_name(struct mb_interpreter_t* s, void* v, char** n); MBAPI int mb_get_var_value(struct mb_interpreter_t* s, void* v, mb_value_t* val); MBAPI int mb_set_var_value(struct mb_interpreter_t* s, void* v, mb_value_t val); MBAPI int mb_init_array(struct mb_interpreter_t* s, void** l, mb_data_e t, int* d, int c, void** a);