4 #include "pcheader.hpp"
8 #include "funcproto.hpp"
10 #include "userdata.hpp"
11 #include "compiler.hpp"
12 #include "funcstate.hpp"
16 VXInteger
vox_aux_invalidtype(VXState
* v
,VXOType type
)
18 return v
->ThrowError("unexpected type '%s'", IdType2Name(type
));
24 void vox_aux_printcallstack(VXState
* v
)
28 VXPrintFunction pf
= v
->GetErrorFunc();
32 //1 is to skip this function that is level 0
34 while(VX_SUCCEEDED(v
->StackInfos(level
, &si
)))
36 fn
= get_funcname(si
);
37 src
= get_sourcename(si
);
38 pf(v
, " At '%s' in [%s:%d]\n", fn
, src
, si
.line
, si
.column
);
44 VXInteger
vox_aux_printerror(VXState
* v
)
46 VXPrintFunction pf
= v
->GetErrorFunc();
52 if(VX_FAILED(v
->GetString(2, &sErr
, NULL
)))
54 sErr
= "[unknown error]";
56 pf(v
, "\nRuntime Error: %s\n", sErr
);
57 vox_aux_printcallstack(v
);
63 void vox_aux_compiler_error(VXState
* v
,
69 VXPrintFunction pf
= v
->GetErrorFunc();
73 "Syntax Error: in %s, line %d, column %d: %s\n",
74 sSource
, line
, column
, sErr
);
78 void vox_aux_asserthandler(const char* expr
,
83 fprintf(stderr
, "vox_assert(%s) failed:\n At %s:%d, function '%s'\n",
84 expr
, file
, line
, funct
);
90 VXInteger
vox_getfunctioninfo(VXState
* v
,VXInteger level
,VXFunctionInfo
*fi
)
92 VXInteger cssize
= v
->_callsstacksize
;
95 VXState::CallInfo
&ci
= v
->_callsstack
[cssize
-level
-1];
96 if(ci
._closure
.IsClosure())
98 VXForeignClosureObj
*c
= _closure(ci
._closure
);
99 VXFuncProtoObj
*proto
= c
->_function
;
101 fi
->name
= type(proto
->_name
) == VX_OT_STRING
?_stringval(proto
->_name
):"unknown";
102 fi
->source
= type(proto
->_name
) == VX_OT_STRING
?_stringval(proto
->_sourcename
):"unknown";
106 return v
->ThrowError("the object is not a closure");