// MY-BASIC - Script BASIC extension module
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <ctype.h>
#include <math.h>
#include <time.h>
#include "../../basext.h"
#include "cbasic.h"
#include "my_basic.h"
/****************************
Extension Module Functions
****************************/
besVERSION_NEGOTIATE
RETURN_FUNCTION((int)INTERFACE_VERSION);
besEND
besSUB_START
DIM AS long PTR p;
besMODULEPOINTER = besALLOC(sizeof(long));
IF (besMODULEPOINTER EQ NULL) THEN_DO RETURN_FUNCTION(0);
p = (long PTR)besMODULEPOINTER;
RETURN_FUNCTION(0);
besEND
besSUB_FINISH
DIM AS long PTR p;
p = (long PTR)besMODULEPOINTER;
IF (p EQ NULL) THEN_DO RETURN_FUNCTION(0);
RETURN_FUNCTION(0);
besEND
/********************
MY-BASIC Functions
********************/
static struct mb_interpreter_t* bas = 0;
static int watch(struct mb_interpreter_t* s, void** l) {
int result = MB_FUNC_OK;
int_t arg = 0;
mb_assert(s && l);
mb_check(mb_attempt_open_bracket(s, l));
mb_check(mb_pop_int(s, l, &arg)); // That's it!
mb_check(mb_attempt_close_bracket(s, l));
// arg is what you want.
return result;
}
besFUNCTION(mbas_init)
besRETURN_LONG(mb_init());
besEND
besFUNCTION(mbas_dispose)
besRETURN_LONG(mb_dispose());
besEND
besFUNCTION(mbas_open)
besRETURN_LONG(mb_open(AT bas));
besEND
besFUNCTION(mbas_close)
besRETURN_LONG(mb_close(AT bas));
besEND
besFUNCTION(mbas_load_str)
DIM AS const char PTR pgm;
besARGUMENTS("z")
AT pgm
besARGEND
besRETURN_LONG(mb_load_string(bas, pgm));
besEND
besFUNCTION(mbas_load_file)
DIM AS const char PTR pgm;
besARGUMENTS("z")
AT pgm
besARGEND
besRETURN_LONG(mb_load_file(bas, pgm));
besEND
besFUNCTION(mbas_run)
besRETURN_LONG(mb_run(bas));
besEND
besFUNCTION(mbas_reset)
besRETURN_LONG(mb_reset(bas, false));
besEND
besFUNCTION(mbas_getint)
DIM AS mb_value_t mbval;
DIM AS const char PTR varname;
besARGUMENTS("z")
AT varname
besARGEND
mbval.type = MB_DT_INT;
mb_debug_get(bas, varname, &mbval);
besRETURN_LONG(mbval.value.integer);
besEND
besFUNCTION(mbas_getdbl)
DIM AS mb_value_t mbval;
DIM AS const char PTR varname;
besARGUMENTS("z")
AT varname
besARGEND
mbval.type = MB_DT_REAL;
mb_debug_get(bas, varname, &mbval);
besRETURN_DOUBLE(mbval.value.float_point);
besEND
besFUNCTION(mbas_getstr)
DIM AS mb_value_t mbval;
DIM AS const char PTR varname;
besARGUMENTS("z")
AT varname
besARGEND
mbval.type = MB_DT_STRING;
mb_debug_get(bas, varname, &mbval);
besRETURN_STRING(mbval.value.string);
besEND
besFUNCTION(mbas_setint)
DIM AS mb_value_t mbval;
DIM AS int usrval;
DIM AS const char PTR varname;
besARGUMENTS("zi")
AT varname, AT usrval
besARGEND
mbval.type = MB_DT_INT;
mbval.value.integer = usrval;
besRETURN_LONG(mb_debug_set(bas, varname, mbval));
besEND
besFUNCTION(mbas_setdbl)
DIM AS mb_value_t mbval;
DIM AS double usrval;
DIM AS const char PTR varname;
besARGUMENTS("zr")
AT varname, AT usrval
besARGEND
mbval.type = MB_DT_REAL;
mbval.value.float_point = usrval;
besRETURN_LONG(mb_debug_set(bas, varname, mbval));
besEND
besFUNCTION(mbas_setstr)
DIM AS mb_value_t mbval;
DIM AS const char PTR usrval;
DIM AS const char PTR varname;
besARGUMENTS("zz")
AT varname, AT usrval
besARGEND
mbval.type = MB_DT_STRING;
mbval.value.string = usrval;
besRETURN_LONG(mb_debug_set(bas, varname, mbval));
besEND