diff --git a/doc/tutorial.md b/doc/tutorial.md index 1797a75..2cfef5a 100644 --- a/doc/tutorial.md +++ b/doc/tutorial.md @@ -593,7 +593,7 @@ module_func_info func_tbl[] = { // the reason why using this way to get function pointer // is because `var` has constructors, which is not compatiable in C // so "extern "C" var fib" may get compilation warnings -extern "C" module_func_info* get() { +NASAL_EXTERN module_func_info* get() { return func_tbl; } ``` diff --git a/doc/tutorial_zh.md b/doc/tutorial_zh.md index f97c139..b6f7070 100644 --- a/doc/tutorial_zh.md +++ b/doc/tutorial_zh.md @@ -574,7 +574,7 @@ module_func_info func_tbl[] = { // 之所以用这种方式来获取函数指针, 是因为`var`是有构造函数的 // 有构造函数的类型作为返回值, 和C是不兼容的, 这导致 // 类似 "extern "C" var fib" 的写法会得到编译错误 -extern "C" module_func_info* get() { +NASAL_EXTERN module_func_info* get() { return func_tbl; } ``` diff --git a/module/fib.cpp b/module/fib.cpp index 6e22011..dcc77ee 100644 --- a/module/fib.cpp +++ b/module/fib.cpp @@ -115,7 +115,7 @@ module_func_info func_tbl[] = { } -extern "C" module_func_info* get() { +NASAL_EXTERN module_func_info* get() { return fib_module::func_tbl; } diff --git a/module/json.cpp b/module/json.cpp index 8dab16f..ef4bf4f 100644 --- a/module/json.cpp +++ b/module/json.cpp @@ -371,7 +371,7 @@ module_func_info func_tbl[] = { {nullptr, nullptr} }; -extern "C" module_func_info* get() { +NASAL_EXTERN module_func_info* get() { return func_tbl; } diff --git a/module/keyboard.cpp b/module/keyboard.cpp index 8586c58..27df676 100644 --- a/module/keyboard.cpp +++ b/module/keyboard.cpp @@ -106,7 +106,7 @@ module_func_info func_tbl[] = { {nullptr, nullptr} }; -extern "C" module_func_info* get() { +NASAL_EXTERN module_func_info* get() { return func_tbl; } diff --git a/module/matrix.cpp b/module/matrix.cpp index 6dc8bb7..3108427 100644 --- a/module/matrix.cpp +++ b/module/matrix.cpp @@ -295,7 +295,7 @@ module_func_info func_tbl[] = { {nullptr, nullptr} }; -extern "C" module_func_info* get() { +NASAL_EXTERN module_func_info* get() { return func_tbl; } diff --git a/module/nasocket.cpp b/module/nasocket.cpp index 0ddbea2..282dc2c 100644 --- a/module/nasocket.cpp +++ b/module/nasocket.cpp @@ -256,7 +256,7 @@ module_func_info func_tbl[] = { {nullptr, nullptr} }; -extern "C" module_func_info* get() { +NASAL_EXTERN module_func_info* get() { return func_tbl; } diff --git a/src/nasal_gc.h b/src/nasal_gc.h index a1e0071..e1c9a39 100644 --- a/src/nasal_gc.h +++ b/src/nasal_gc.h @@ -124,4 +124,13 @@ struct module_func_info { // module function "get" type typedef module_func_info* (*get_func_ptr)(); + +// avoid error loading function bug in MSVC version nasal.exe +#ifdef _MSC_VER + // and fuck MSVC again + #define NASAL_EXTERN extern "C" __declspec(dllexport) +#else + #define NASAL_EXTERN extern "C" +#endif + }