From f754d91e14fce3b2f95b90e6d6eac3e8fcb75ee2 Mon Sep 17 00:00:00 2001 From: John Alanbrook Date: Fri, 23 May 2025 18:11:07 -0500 Subject: [PATCH] fix compilation errors on windows and linux --- meson.options | 1 - source/jsffi.h | 2 +- source/qjs_os.c | 30 ++++++++++++++++++++---------- source/qjs_sdl.c | 38 +++++++++++++++++--------------------- 4 files changed, 38 insertions(+), 33 deletions(-) diff --git a/meson.options b/meson.options index aa427165..04f60782 100644 --- a/meson.options +++ b/meson.options @@ -1,4 +1,3 @@ option('editor', type:'boolean', value:true) option('chipmunk', type:'boolean', value:true) -option('enet', type:'boolean', value:true) option('storefront', type:'combo', choices:['none','steam', 'gog', 'egs'], value:'none') diff --git a/source/jsffi.h b/source/jsffi.h index 3606cea4..0078ee6c 100644 --- a/source/jsffi.h +++ b/source/jsffi.h @@ -9,7 +9,7 @@ #define JS_SetProperty(js, tar, str, val) JS_SetPropertyStr(js, tar, #str, val) #define JS_GetProperty(js, tar, atom) JS_GetPropertyStr(js, tar, #atom) -SDL_Window *global_window; +extern SDL_Window *global_window; // Core FFI functions void ffi_load(JSContext *js); diff --git a/source/qjs_os.c b/source/qjs_os.c index e26575c5..978c0775 100644 --- a/source/qjs_os.c +++ b/source/qjs_os.c @@ -23,6 +23,7 @@ #include #ifdef __linux__ #include +#include #endif #endif @@ -62,7 +63,8 @@ JSC_CCALL(os_power_state, JSC_CCALL(os_totalmem, return number2js(js, SDL_GetSystemRAM())) JSC_CCALL(os_platform, return JS_NewString(js,SDL_GetPlatform())) -JSC_CCALL(os_hostname, +static JSValue js_os_hostname(JSContext *js, JSValue self, int argc, JSValue *argv) { + JSValue ret = JS_UNDEFINED; #ifdef _WIN32 TCHAR buffer[256] = TEXT(""); DWORD size = sizeof(buffer) / sizeof(TCHAR); @@ -73,9 +75,11 @@ JSC_CCALL(os_hostname, if (uname(&buffer) != 0) return JS_ThrowReferenceError(js,"Could not get hostname."); return JS_NewString(js, buffer.nodename); #endif -) + return ret; +} -JSC_CCALL(os_arch, +static JSValue js_os_arch(JSContext *js, JSValue self, int argc, JSValue *argv) { + JSValue ret = JS_UNDEFINED; #if defined(__x86_64__) || defined(_M_X64) return JS_NewString(js,"x64"); #elif defined(__aarch64__) || defined(_M_ARM64) @@ -99,9 +103,11 @@ JSC_CCALL(os_arch, #else return JS_NewString(js,"unknown"); #endif -) + return ret; +} -JSC_CCALL(os_freemem, +static JSValue js_os_freemem(JSContext *js, JSValue self, int argc, JSValue *argv) { + JSValue ret = JS_UNDEFINED; #ifdef _WIN32 MEMORYSTATUSEX statex; statex.dwLength = sizeof(statex); @@ -124,9 +130,11 @@ JSC_CCALL(os_freemem, // Fallback: unknown return JS_NewInt64(js,0); #endif -) + return ret; +} -JSC_CCALL(os_version, +static JSValue js_os_version(JSContext *js, JSValue self, int argc, JSValue *argv) { + JSValue ret = JS_UNDEFINED; #ifdef _WIN32 typedef LONG (WINAPI *RtlGetVersionPtr)(PRTL_OSVERSIONINFOW); HMODULE h = GetModuleHandleA("ntdll.dll"); @@ -165,7 +173,8 @@ JSC_CCALL(os_version, if (!uname(&info)) return JS_NewString(js, info.release); return JS_NewString(js, ""); #endif -) + return ret; +} JSValue js_os_get_trace(JSContext *js, JSValue self) { @@ -205,7 +214,8 @@ JSC_CCALL(os_mallinfo, JSJMEMRET(keepcost);*/ ) -JSC_CCALL(os_rusage, +static JSValue js_os_rusage(JSContext *js, JSValue self, int argc, JSValue *argv) { + JSValue ret = JS_UNDEFINED; ret = JS_NewObject(js); #ifndef _WIN32 @@ -228,7 +238,7 @@ JSC_CCALL(os_rusage, #endif return ret; -) +} static const JSCFunctionListEntry js_os_funcs[] = { MIST_FUNC_DEF(os, platform, 0), diff --git a/source/qjs_sdl.c b/source/qjs_sdl.c index 6e84cf1b..6cb0b1e6 100644 --- a/source/qjs_sdl.c +++ b/source/qjs_sdl.c @@ -158,25 +158,7 @@ static const JSCFunctionListEntry js_camera_funcs[] = { MIST_FUNC_DEF(camera, position, 1), }; -static const JSCFunctionListEntry js_SDL_Camera_funcs[] = -{ -// MIST_FUNC_DEF(camera, frame, 0), -// MIST_FUNC_DEF(camera, release_frame, 1), -}; - -JSValue js_camera_use(JSContext *js) { - JSValue mod = JS_NewObject(js); - JS_SetPropertyFunctionList(js,mod,js_camera_funcs,countof(js_camera_funcs)); - - // Initialize SDL camera class with functions - JSValue c_types = JS_GetPropertyStr(js, JS_GetGlobalObject(js), "c_types"); - QJSCLASSPREP_FUNCS(SDL_Camera) - JS_FreeValue(js, c_types); - - return mod; -} - -JSC_CCALL(camera_frame, +JSC_CCALL(camera_capture, /* SDL_ClearError(); SDL_Camera *cam = js2SDL_Camera(js,self); @@ -200,15 +182,29 @@ JSC_CCALL(camera_frame, return SDL_Surface2js(js,newsurf); */ -) -JSC_CCALL(camera_release_frame, /* SDL_Camera *cam = js2SDL_Camera(js,self); SDL_Surface *surf = js2SDL_Surface(js,argv[0]); SDL_ReleaseCameraFrame(cam,surf); */ ) +static const JSCFunctionListEntry js_SDL_Camera_funcs[] = +{ + MIST_FUNC_DEF(camera, capture, 0), +}; + +JSValue js_camera_use(JSContext *js) { + JSValue mod = JS_NewObject(js); + JS_SetPropertyFunctionList(js,mod,js_camera_funcs,countof(js_camera_funcs)); + + // Initialize SDL camera class with functions + JSValue c_types = JS_GetPropertyStr(js, JS_GetGlobalObject(js), "c_types"); + QJSCLASSPREP_FUNCS(SDL_Camera) + JS_FreeValue(js, c_types); + + return mod; +} // SDL AUDIO FUNCTIONS