Add support for calling wren methods from c++ using call()
This commit is contained in:
parent
2755371792
commit
df52fe0fba
5 changed files with 117 additions and 11 deletions
|
@ -68,6 +68,21 @@ namespace wren {
|
|||
retval.finalize = funcs.finalize;
|
||||
return retval;
|
||||
}
|
||||
|
||||
void throw_if_err (WrenInterpretResult res, const char* module_name) {
|
||||
using std::runtime_error;
|
||||
using std::string;
|
||||
|
||||
switch (res) {
|
||||
case WREN_RESULT_COMPILE_ERROR:
|
||||
throw runtime_error(string("Compilation of ") + module_name + " has failed");
|
||||
case WREN_RESULT_RUNTIME_ERROR:
|
||||
throw runtime_error(string("A runtime error occurred in ") + module_name);
|
||||
|
||||
case WREN_RESULT_SUCCESS:
|
||||
break;
|
||||
}
|
||||
}
|
||||
} //unnamed namespace
|
||||
|
||||
struct VM::LocalData {
|
||||
|
@ -138,15 +153,12 @@ namespace wren {
|
|||
using std::runtime_error;
|
||||
|
||||
const WrenInterpretResult res = wrenInterpret(m_local->wvm, module_name, script);
|
||||
switch (res) {
|
||||
case WREN_RESULT_COMPILE_ERROR:
|
||||
throw runtime_error(string("Compilation of ") + module_name + " has failed");
|
||||
case WREN_RESULT_RUNTIME_ERROR:
|
||||
throw runtime_error(string("A runtime error occurred in ") + module_name);
|
||||
throw_if_err(res, module_name);
|
||||
}
|
||||
|
||||
case WREN_RESULT_SUCCESS:
|
||||
break;
|
||||
}
|
||||
void VM::call (const Handle& method) {
|
||||
const WrenInterpretResult res = wrenCall(m_local->wvm, method);
|
||||
throw_if_err(res, "[wrenCall()]");
|
||||
}
|
||||
|
||||
void VM::release_handle (Handle& handle) noexcept {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue