mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
...
This commit is contained in:
parent
85a9588459
commit
cdd6776058
@ -1,17 +1,5 @@
|
||||
#ifndef PK_EXPORT
|
||||
|
||||
#ifdef _WIN32
|
||||
#define PK_EXPORT __declspec(dllexport)
|
||||
#elif __EMSCRIPTEN__
|
||||
#include <emscripten.h>
|
||||
#define PK_EXPORT EMSCRIPTEN_KEEPALIVE
|
||||
#else
|
||||
#define PK_EXPORT __attribute__((visibility("default")))
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
@ -24,12 +12,17 @@
|
||||
|
||||
#include <Windows.h>
|
||||
|
||||
#define PK_EXPORT __declspec(dllexport)
|
||||
#elif __EMSCRIPTEN__
|
||||
|
||||
#include <emscripten.h>
|
||||
|
||||
#elif __unix__
|
||||
|
||||
#include <dlfcn.h>
|
||||
#define PK_EXPORT EMSCRIPTEN_KEEPALIVE
|
||||
#else
|
||||
#define PK_EXPORT __attribute__((visibility("default")))
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __unix__
|
||||
#include <dlfcn.h>
|
||||
#endif
|
@ -108,20 +108,11 @@ PK_EXPORT bool pkpy_check_stack(pkpy_vm*, int free);
|
||||
//returns the number of elements on the stack
|
||||
PK_EXPORT int pkpy_stack_size(pkpy_vm*);
|
||||
|
||||
typedef void (*OutputHandler)(pkpy_vm*, const char*);
|
||||
PK_EXPORT void pkpy_set_output_handlers(pkpy_vm*, OutputHandler stdout_handler, OutputHandler stderr_handler);
|
||||
|
||||
PK_EXPORT bool pkpy_getattr(pkpy_vm*, const char* name);
|
||||
PK_EXPORT bool pkpy_setattr(pkpy_vm*, const char* name);
|
||||
PK_EXPORT bool pkpy_eval(pkpy_vm*, const char* source);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*************************GLOBAL NAMESPACE*************************/
|
||||
extern "C" {
|
||||
/*********************************************************/
|
||||
PK_EXPORT
|
||||
void pkpy_free(void* p);
|
||||
|
||||
@ -151,9 +142,10 @@ extern "C" {
|
||||
|
||||
PK_EXPORT
|
||||
void pkpy_delete_repl(void* repl);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -131,27 +131,15 @@ void gc_marker_ex(CVM* vm) {
|
||||
if(vm->error != nullptr) PK_OBJ_MARK(vm->error);
|
||||
}
|
||||
|
||||
static OutputHandler stdout_handler = nullptr;
|
||||
static OutputHandler stderr_handler = nullptr;
|
||||
|
||||
void pkpy_set_output_handlers(pkpy_vm*, OutputHandler stdout_handler, OutputHandler stderr_handler){
|
||||
::stdout_handler = stdout_handler;
|
||||
::stderr_handler = stderr_handler;
|
||||
}
|
||||
|
||||
pkpy_vm* pkpy_vm_create(bool use_stdio, bool enable_os) {
|
||||
CVM* vm = new CVM(enable_os);
|
||||
vm->c_data = new LuaStack();
|
||||
vm->heap._gc_marker_ex = (void (*)(VM*)) gc_marker_ex;
|
||||
|
||||
if (!use_stdio) {
|
||||
vm->_stdout = [](VM* vm, const Str& s){
|
||||
std::string str = s.str();
|
||||
if (stdout_handler != nullptr) stdout_handler((pkpy_vm*)vm, str.c_str());
|
||||
};
|
||||
vm->_stderr = [](VM* vm, const Str& s){
|
||||
std::string str = s.str();
|
||||
if (stderr_handler != nullptr) stderr_handler((pkpy_vm*)vm, str.c_str());
|
||||
vm->_stdout = vm->_stderr = [](VM* vm, const Str& s){
|
||||
PK_UNUSED(vm);
|
||||
PK_UNUSED(s);
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user