Sample code that prints a message from wren
This commit is contained in:
commit
257513e72a
6 changed files with 177 additions and 0 deletions
32
src/main.cpp
Normal file
32
src/main.cpp
Normal file
|
@ -0,0 +1,32 @@
|
|||
#include <iostream>
|
||||
#include <wren.hpp>
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
namespace {
|
||||
void wren_print (WrenVM*, const char* text) {
|
||||
std::cout << text;
|
||||
}
|
||||
|
||||
void wren_error (WrenVM*, WrenErrorType type, const char* module, int line, const char* message) {
|
||||
std::cerr << "Wren error: " << message << " in " << module << ':' << line << '\n';
|
||||
}
|
||||
} //unnamed namespace
|
||||
|
||||
int main() {
|
||||
std::cout << "hello world\n";
|
||||
WrenConfiguration config;
|
||||
wrenInitConfiguration(&config);
|
||||
config.writeFn = &wren_print;
|
||||
config.errorFn = &wren_error;
|
||||
WrenVM* vm = wrenNewVM(&config);
|
||||
WrenInterpretResult result = wrenInterpret(
|
||||
vm,
|
||||
"my_module",
|
||||
"System.print(\"I am running in a VM!\")"
|
||||
);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
|
||||
wrenFreeVM(vm);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue