From 159326798e4bc0c2bebd23ed5ef0874f4192f86d Mon Sep 17 00:00:00 2001 From: Rob Blanckaert Date: Mon, 22 Nov 2021 18:01:08 -0800 Subject: [PATCH] Export Luau public symbols to WebAssembly Instead of only exporting the symbols for the web repl, export all public Luau symbols to the wasm build. --- CLI/Web.cpp | 2 +- CMakeLists.txt | 2 +- VM/include/luaconf.h | 8 ++++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CLI/Web.cpp b/CLI/Web.cpp index cf5c831e..dee5044a 100644 --- a/CLI/Web.cpp +++ b/CLI/Web.cpp @@ -79,7 +79,7 @@ static std::string runCode(lua_State* L, const std::string& source) return std::string(); } -extern "C" const char* executeScript(const char* source) +LUA_API const char* executeScript(const char* source) { // setup flags for (Luau::FValue* flag = Luau::FValue::list; flag; flag = flag->next) diff --git a/CMakeLists.txt b/CMakeLists.txt index bafc59e5..3cffe906 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -110,7 +110,7 @@ if(LUAU_BUILD_WEB) target_link_libraries(Luau.Web PRIVATE Luau.Compiler Luau.VM) # declare exported functions to emscripten - target_link_options(Luau.Web PRIVATE -sEXPORTED_FUNCTIONS=['_executeScript'] -sEXPORTED_RUNTIME_METHODS=['ccall','cwrap']) + target_link_options(Luau.Web PRIVATE -sEXPORTED_RUNTIME_METHODS=['ccall','cwrap']) # add -fexceptions for emscripten to allow exceptions to be caught in C++ target_link_options(Luau.Web PRIVATE -fexceptions) diff --git a/VM/include/luaconf.h b/VM/include/luaconf.h index cce70a20..24fbb157 100644 --- a/VM/include/luaconf.h +++ b/VM/include/luaconf.h @@ -2,6 +2,10 @@ // This code is based on Lua 5.x implementation licensed under MIT License; see lua_LICENSE.txt for details #pragma once +#ifdef __EMSCRIPTEN__ +#include +#endif + // When debugging complex issues, consider enabling one of these: // This will reallocate the stack very aggressively at every opportunity; use this with asan to catch stale stack pointers // #define HARDSTACKTESTS 1 @@ -34,7 +38,11 @@ #endif /* Can be used to reconfigure visibility/exports for public APIs */ +#ifdef __EMSCRIPTEN__ +#define LUA_API extern "C" EMSCRIPTEN_KEEPALIVE +#else #define LUA_API extern +#endif #define LUALIB_API LUA_API /* Can be used to reconfigure visibility for internal APIs */