Begin integrating Neko support

This commit is contained in:
Joshua Granick
2014-06-25 14:34:27 -07:00
parent cd879b6287
commit d2f34a71dc
6 changed files with 122 additions and 2 deletions

View File

@@ -19,6 +19,7 @@
#include <ui/TouchEvent.h>
#include <ui/Window.h>
#include <ui/WindowEvent.h>
#include <vm/Neko.h>
namespace lime {
@@ -99,6 +100,16 @@ namespace lime {
}
value lime_neko_execute (value module) {
#ifdef LIME_NEKO
Neko::Execute (val_string (module));
#endif
return alloc_null ();
}
value lime_png_decode (value bytes, value imageData) {
ByteArray byteArray (bytes);
@@ -184,6 +195,7 @@ namespace lime {
DEFINE_PRIM (lime_lzma_encode, 1);
DEFINE_PRIM (lime_lzma_decode, 1);
DEFINE_PRIM (lime_mouse_event_manager_register, 2);
DEFINE_PRIM (lime_neko_execute, 1);
DEFINE_PRIM (lime_png_decode, 2);
DEFINE_PRIM (lime_renderer_create, 1);
DEFINE_PRIM (lime_renderer_flip, 1);

70
project/src/vm/Neko.cpp Normal file
View File

@@ -0,0 +1,70 @@
#include <vm/Neko.h>
#include <stdio.h>
#include <neko_vm.h>
extern "C" { void std_main (); }
namespace lime {
static void report( neko_vm *vm, value exc, int isexc ) {
int i;
buffer b = alloc_buffer(NULL);
value st = neko_exc_stack(vm);
for(i=0;i<val_array_size(st);i++) {
value s = val_array_ptr(st)[i];
buffer_append(b,"Called from ");
if( val_is_null(s) )
buffer_append(b,"a C function");
else if( val_is_string(s) ) {
buffer_append(b,val_string(s));
buffer_append(b," (no debug available)");
} else if( val_is_array(s) && val_array_size(s) == 2 && val_is_string(val_array_ptr(s)[0]) && val_is_int(val_array_ptr(s)[1]) ) {
val_buffer(b,val_array_ptr(s)[0]);
buffer_append(b," line ");
val_buffer(b,val_array_ptr(s)[1]);
} else
val_buffer(b,s);
buffer_append_char(b,'\n');
}
if( isexc )
buffer_append(b,"Uncaught exception - ");
val_buffer(b,exc);
# ifdef NEKO_STANDALONE
neko_standalone_error(val_string(buffer_to_string(b)));
# else
fprintf(stderr,"%s\n",val_string(buffer_to_string(b)));
# endif
}
void Neko::Execute (const char *modulePath) {
neko_vm *vm;
neko_global_init ();
vm = neko_vm_alloc (NULL);
neko_vm_select (vm);
std_main ();
value mload = neko_default_loader(NULL, 0);
value args2[] = { alloc_string(modulePath), mload };
value exc = NULL;
val_callEx(mload,val_field(mload,val_id("loadmodule")),args2,2,&exc);
if( exc != NULL ) {
report(vm,exc,1);
//return 1;
}
//return 0;
}
}