1
0
forked from Mirror/wren

docs; fix example formatting

This commit is contained in:
underscorediscovery
2020-07-30 09:24:23 -07:00
parent 81bfbfce23
commit 039150efeb
2 changed files with 47 additions and 22 deletions

View File

@ -203,7 +203,7 @@ been freed.
## A complete example ## A complete example
Below is a complete example of the above. 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"> <pre class="snippet" data-lang="c">
//For more details, visit https://wren.io/embedding/ //For more details, visit https://wren.io/embedding/
@ -211,25 +211,34 @@ You can find this file in the [example](https://github.com/wren-lang/wren/tree/m
#include <stdio.h> #include <stdio.h>
#include "wren.h" #include "wren.h"
static void writeFn(WrenVM* vm, const char* text) { static void writeFn(WrenVM* vm, const char* text)
{
printf("%s", text); printf("%s", text);
} }
void errorFn(WrenVM* vm, WrenErrorType errorType, const char* module, const int line, const char* msg) { void errorFn(WrenVM* vm, WrenErrorType errorType,
switch (errorType) { const char* module, const int line,
case WREN_ERROR_COMPILE: { const char* msg)
{
switch (errorType)
{
case WREN_ERROR_COMPILE:
{
printf("[%s line %d] [Error] %s\n", module, line, msg); printf("[%s line %d] [Error] %s\n", module, line, msg);
} break; } break;
case WREN_ERROR_STACK_TRACE: { case WREN_ERROR_STACK_TRACE:
{
printf("[%s line %d] in %s\n", module, line, msg); printf("[%s line %d] in %s\n", module, line, msg);
} break; } break;
case WREN_ERROR_RUNTIME: { case WREN_ERROR_RUNTIME:
{
printf("[Runtime Error] %s\n", msg); printf("[Runtime Error] %s\n", msg);
} break; } break;
} }
} }
int main() { int main()
{
WrenConfiguration config; WrenConfiguration config;
wrenInitConfiguration(&config); wrenInitConfiguration(&config);
@ -243,9 +252,12 @@ int main() {
WrenInterpretResult result = wrenInterpret(vm, module, script); WrenInterpretResult result = wrenInterpret(vm, module, script);
switch (result) { switch (result) {
case WREN_RESULT_COMPILE_ERROR: { printf("Compile Error!\n"); } break; case WREN_RESULT_COMPILE_ERROR:
case WREN_RESULT_RUNTIME_ERROR: { printf("Runtime Error!\n"); } break; { printf("Compile Error!\n"); } break;
case WREN_RESULT_SUCCESS: { printf("Success!\n"); } break; case WREN_RESULT_RUNTIME_ERROR:
{ printf("Runtime Error!\n"); } break;
case WREN_RESULT_SUCCESS:
{ printf("Success!\n"); } break;
} }
wrenFreeVM(vm); wrenFreeVM(vm);

View File

@ -3,25 +3,34 @@
#include <stdio.h> #include <stdio.h>
#include "wren.h" #include "wren.h"
static void writeFn(WrenVM* vm, const char* text) { static void writeFn(WrenVM* vm, const char* text)
{
printf("%s", text); printf("%s", text);
} }
void errorFn(WrenVM* vm, WrenErrorType errorType, const char* module, const int line, const char* msg) { void errorFn(WrenVM* vm, WrenErrorType errorType,
switch (errorType) { const char* module, const int line,
case WREN_ERROR_COMPILE: { const char* msg)
{
switch (errorType)
{
case WREN_ERROR_COMPILE:
{
printf("[%s line %d] [Error] %s\n", module, line, msg); printf("[%s line %d] [Error] %s\n", module, line, msg);
} break; } break;
case WREN_ERROR_STACK_TRACE: { case WREN_ERROR_STACK_TRACE:
{
printf("[%s line %d] in %s\n", module, line, msg); printf("[%s line %d] in %s\n", module, line, msg);
} break; } break;
case WREN_ERROR_RUNTIME: { case WREN_ERROR_RUNTIME:
{
printf("[Runtime Error] %s\n", msg); printf("[Runtime Error] %s\n", msg);
} break; } break;
} }
} }
int main() { int main()
{
WrenConfiguration config; WrenConfiguration config;
wrenInitConfiguration(&config); wrenInitConfiguration(&config);
@ -34,10 +43,14 @@ int main() {
WrenInterpretResult result = wrenInterpret(vm, module, script); WrenInterpretResult result = wrenInterpret(vm, module, script);
switch (result) { 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_COMPILE_ERROR:
case WREN_RESULT_SUCCESS: { printf("Success!\n"); } break; { 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); wrenFreeVM(vm);