Skip to content

Commit

Permalink
docs; fix example formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
ruby0x1 committed Jul 30, 2020
1 parent 81bfbfc commit 039150e
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 22 deletions.
34 changes: 23 additions & 11 deletions doc/site/embedding/index.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -203,33 +203,42 @@ been freed.
## A complete example

Below is a complete example of the above.
You can find this file in the [example](https://github.com/wren-lang/wren/tree/main/example/embedding) folder.
You can find this file in the [example](https://github.com/wren-lang/wren/blob/main/example/embedding/main.c) folder.

<pre class="snippet" data-lang="c">
//For more details, visit https://wren.io/embedding/

#include <stdio.h>
#include "wren.h"

static void writeFn(WrenVM* vm, const char* text) {
static void writeFn(WrenVM* vm, const char* text)
{
printf("%s", text);
}

void errorFn(WrenVM* vm, WrenErrorType errorType, const char* module, const int line, const char* msg) {
switch (errorType) {
case WREN_ERROR_COMPILE: {
void errorFn(WrenVM* vm, WrenErrorType errorType,
const char* module, const int line,
const char* msg)
{
switch (errorType)
{
case WREN_ERROR_COMPILE:
{
printf("[%s line %d] [Error] %s\n", module, line, msg);
} break;
case WREN_ERROR_STACK_TRACE: {
case WREN_ERROR_STACK_TRACE:
{
printf("[%s line %d] in %s\n", module, line, msg);
} break;
case WREN_ERROR_RUNTIME: {
case WREN_ERROR_RUNTIME:
{
printf("[Runtime Error] %s\n", msg);
} break;
}
}

int main() {
int main()
{

WrenConfiguration config;
wrenInitConfiguration(&config);
Expand All @@ -243,9 +252,12 @@ int main() {
WrenInterpretResult result = wrenInterpret(vm, module, script);

switch (result) {
case WREN_RESULT_COMPILE_ERROR: { printf("Compile Error!\n"); } break;
case WREN_RESULT_RUNTIME_ERROR: { printf("Runtime Error!\n"); } break;
case WREN_RESULT_SUCCESS: { printf("Success!\n"); } break;
case WREN_RESULT_COMPILE_ERROR:
{ printf("Compile Error!\n"); } break;
case WREN_RESULT_RUNTIME_ERROR:
{ printf("Runtime Error!\n"); } break;
case WREN_RESULT_SUCCESS:
{ printf("Success!\n"); } break;
}

wrenFreeVM(vm);
Expand Down
35 changes: 24 additions & 11 deletions example/embedding/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,34 @@
#include <stdio.h>
#include "wren.h"

static void writeFn(WrenVM* vm, const char* text) {
static void writeFn(WrenVM* vm, const char* text)
{
printf("%s", text);
}

void errorFn(WrenVM* vm, WrenErrorType errorType, const char* module, const int line, const char* msg) {
switch (errorType) {
case WREN_ERROR_COMPILE: {
void errorFn(WrenVM* vm, WrenErrorType errorType,
const char* module, const int line,
const char* msg)
{
switch (errorType)
{
case WREN_ERROR_COMPILE:
{
printf("[%s line %d] [Error] %s\n", module, line, msg);
} break;
case WREN_ERROR_STACK_TRACE: {
case WREN_ERROR_STACK_TRACE:
{
printf("[%s line %d] in %s\n", module, line, msg);
} break;
case WREN_ERROR_RUNTIME: {
case WREN_ERROR_RUNTIME:
{
printf("[Runtime Error] %s\n", msg);
} break;
}
}

int main() {
int main()
{

WrenConfiguration config;
wrenInitConfiguration(&config);
Expand All @@ -34,10 +43,14 @@ int main() {

WrenInterpretResult result = wrenInterpret(vm, module, script);

switch (result) {
case WREN_RESULT_COMPILE_ERROR: { printf("Compile Error!\n"); } break;
case WREN_RESULT_RUNTIME_ERROR: { printf("Runtime Error!\n"); } break;
case WREN_RESULT_SUCCESS: { printf("Success!\n"); } break;
switch (result)
{
case WREN_RESULT_COMPILE_ERROR:
{ printf("Compile Error!\n"); } break;
case WREN_RESULT_RUNTIME_ERROR:
{ printf("Runtime Error!\n"); } break;
case WREN_RESULT_SUCCESS:
{ printf("Success!\n"); } break;
}

wrenFreeVM(vm);
Expand Down

0 comments on commit 039150e

Please sign in to comment.