Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ project "qjsc"
files {
"qjsc.c"
}
filter { "action:gmake*", "toolset:gcc" }
links { "dl", "pthread" }

-----------------------------------------------------------------------------------------------------------------------

Expand All @@ -144,6 +146,8 @@ project "qjs"
"qjscalc.js",
"qjscalc.c"
}
filter { "action:gmake*", "toolset:gcc" }
links { "dl", "pthread" }

-- Compile repl.js and save bytecode into repl.c
prebuildcommands { "\"%{cfg.buildtarget.directory}/qjsc.exe\" -c -o \"../../repl.c\" -m \"../../repl.js\"" }
Expand Down
8 changes: 7 additions & 1 deletion qjsc.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@
#include <sys/wait.h>
#include <unistd.h>
#else
#if !defined(__MINGW32__)
#include "win/getopt.h"
#else
#include <unistd.h>
#endif
#endif

#include "cutils.h"
Expand Down Expand Up @@ -244,7 +248,7 @@ JSModuleDef *jsc_module_loader(JSContext *ctx,
namelist_add(&init_module_list, e->name, e->short_name, 0);
/* create a dummy module */
m = JS_NewCModule(ctx, module_name, js_module_dummy_init);
} else if (has_suffix(module_name, ".so")) {
} else if (has_suffix(module_name, NATIVE_MODULE_SUFFIX)) {
fprintf(stderr, "Warning: binary module '%s' will be dynamically loaded\n", module_name);
/* create a dummy module */
m = JS_NewCModule(ctx, module_name, js_module_dummy_init);
Expand Down Expand Up @@ -763,3 +767,5 @@ int main(int argc, char **argv)
namelist_free(&init_module_list);
return 0;
}

#undef NATIVE_MODULE_SUFFIX
7 changes: 5 additions & 2 deletions quickjs-libc.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
#include <limits.h>
#include <sys/stat.h>
#if defined(_WIN32)
#if defined(__MINGW32__)
#include <dlfcn.h>
#endif
#include <windows.h>
#include <conio.h>
#include <io.h>
Expand Down Expand Up @@ -463,7 +466,7 @@ typedef JSModuleDef *(JSInitModuleFunc)(JSContext *ctx,
const char *module_name);


#if defined(_WIN32)
#if defined(_MSC_VER)
static JSModuleDef *js_module_loader_so(JSContext *ctx,
const char *module_name)
{
Expand Down Expand Up @@ -579,7 +582,7 @@ JSModuleDef *js_module_loader(JSContext *ctx,
{
JSModuleDef *m;

if (has_suffix(module_name, ".so")) {
if (has_suffix(module_name, NATIVE_MODULE_SUFFIX)) {
m = js_module_loader_so(ctx, module_name);
} else {
size_t buf_len;
Expand Down
4 changes: 3 additions & 1 deletion quickjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
#include <time.h>
#include <fenv.h>
#include <math.h>
#if defined(__APPLE__)
#if defined(_WIN32)
#include <timezoneapi.h>
#elif defined(__APPLE__)
#include <malloc/malloc.h>
#include <sys/time.h>
#elif defined(__linux__)
Expand Down
8 changes: 8 additions & 0 deletions quickjs.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@
#include <math.h>
#include "quickjs-version.h"

#if defined(_WIN32)
#define NATIVE_MODULE_SUFFIX ".dll"
#elif defined(__APPLE__)
#define NATIVE_NATIVE_MODULE_SUFFIX ".dylib"
#else
#define NATIVE_MODULE_SUFFIX ".so"
#endif

#ifdef __cplusplus
extern "C" {
#endif
Expand Down