Sample code that prints a message from wren

This commit is contained in:
King_DuckZ 2020-04-25 01:49:46 +02:00
commit 257513e72a
6 changed files with 177 additions and 0 deletions

3
.gitmodules vendored Normal file
View file

@ -0,0 +1,3 @@
[submodule "subprojects/wren/wren"]
path = subprojects/wren/wren
url = https://github.com/wren-lang/wren.git

13
meson.build Normal file
View file

@ -0,0 +1,13 @@
project('wrentest', 'cpp',
version: '1.0.0',
meson_version: '>=0.49.2',
default_options: ['debug=true', 'cpp_std=c++17', 'b_ndebug=if-release'],
)
wren_dep = dependency('wren', version: '>=0.2.0', fallback: ['wren', 'wren_dep'])
executable(meson.project_name(),
'src/main.cpp',
dependencies: [wren_dep],
install: true,
)

32
src/main.cpp Normal file
View 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;
}

View file

@ -0,0 +1,125 @@
project('wren', 'c',
version: '0.2.0',
meson_version: '>=0.49.2',
default_options: ['debug=false', 'c_std=c99', 'build_testing=true'],
)
c_compiler = meson.get_compiler('c')
wren_incl = include_directories('wren/src/include', is_system: true)
wren_pvt_incl = include_directories('wren/src/vm', 'wren/src/optional')
module_incl = include_directories('wren/src/module')
cli_incl = include_directories('wren/src/cli')
threads_dep = dependency('threads')
libuv_dep = c_compiler.find_library('libuv', required: true)
m_dep = c_compiler.find_library('m', required: true)
opt_src = [
'wren/src/optional/wren_opt_random.c',
'wren/src/optional/wren_opt_meta.c',
]
vm_src = [
'wren/src/vm/wren_debug.c',
'wren/src/vm/wren_core.c',
'wren/src/vm/wren_utils.c',
'wren/src/vm/wren_vm.c',
'wren/src/vm/wren_value.c',
'wren/src/vm/wren_primitive.c',
'wren/src/vm/wren_compiler.c',
]
module_src = [
'wren/src/module/io.c',
'wren/src/module/timer.c',
'wren/src/module/repl.c',
'wren/src/module/os.c',
'wren/src/module/scheduler.c',
]
wren = library(meson.project_name(),
opt_src,
vm_src,
include_directories: [wren_incl, wren_pvt_incl],
dependencies: [threads_dep, m_dep],
install: get_option('wren_installable'),
)
wren_dep = declare_dependency(
include_directories: [wren_incl],
link_with: wren,
)
if get_option('wren_with_cli')
cli = executable(meson.project_name(),
'wren/src/cli/main.c',
'wren/src/cli/path.c',
'wren/src/cli/modules.c',
'wren/src/cli/vm.c',
module_src,
install: get_option('wren_installable'),
include_directories: [cli_incl, module_incl],
dependencies: [wren_dep, libuv_dep],
c_args: ['-D_XOPEN_SOURCE=600'],
)
endif
if get_option('build_testing')
test_api_src = [
'wren/test/api/main.c',
'wren/test/api/reset_stack_after_foreign_construct.c',
'wren/test/api/new_vm.c',
'wren/test/api/get_variable.c',
'wren/test/api/slots.c',
'wren/test/api/lists.c',
'wren/test/api/user_data.c',
'wren/test/api/call.c',
'wren/test/api/foreign_class.c',
'wren/test/api/call_wren_call_root.c',
'wren/test/api/handle.c',
'wren/test/api/resolution.c',
'wren/test/api/error.c',
'wren/test/api/call_calls_foreign.c',
'wren/test/api/reset_stack_after_call_abort.c',
'wren/test/api/benchmark.c',
]
test_unit_src = [
'wren/test/unit/main.c',
'wren/test/unit/test.c',
'wren/test/unit/path_test.c',
]
test_api = executable('api_' + meson.project_name(),
test_api_src,
module_src,
'wren/src/cli/path.c',
'wren/src/cli/modules.c',
'wren/src/cli/vm.c',
install: false,
dependencies: [wren_dep, libuv_dep],
include_directories: [cli_incl, module_incl],
c_args: ['-D_XOPEN_SOURCE=600'],
)
test(meson.project_name() + ' api test', test_api)
test_unit = executable('unit_' + meson.project_name(),
test_unit_src,
module_src,
'wren/src/cli/path.c',
'wren/src/cli/modules.c',
'wren/src/cli/vm.c',
install: false,
include_directories: [cli_incl, module_incl],
dependencies: [wren_dep, libuv_dep],
c_args: ['-D_XOPEN_SOURCE=600'],
)
test(meson.project_name() + ' unit test', test_unit)
endif
if get_option('wren_installable')
install_headers(
'wren/src/include/wren.h',
'wren/src/include/wren.hpp',
)
endif

View file

@ -0,0 +1,3 @@
option('build_testing', type: 'boolean', value: false)
option('wren_with_cli', type: 'boolean', value: true)
option('wren_installable', type: 'boolean', value: true)

1
subprojects/wren/wren Submodule

@ -0,0 +1 @@
Subproject commit 6ab4abe9e3a2767ced01589e9a3d583c840f54c3