mirror of
https://github.com/luau-lang/luau.git
synced 2025-05-04 10:33:46 +01:00
Remove Luau.REPL.Web target.
This commit is contained in:
parent
8dde140eff
commit
1bff6154e6
3 changed files with 67 additions and 89 deletions
76
CLI/Repl.cpp
76
CLI/Repl.cpp
|
@ -194,6 +194,46 @@ static std::string runCode(lua_State* L, const std::string& source)
|
||||||
return std::string();
|
return std::string();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __EMSCRIPTEN__
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
// Luau errors are exceptions (see luaD_throw) which cannot be directly
|
||||||
|
// handled by emscripten. However we can recieve the pointer in JS and
|
||||||
|
// pass it through to this method to get the string content of the
|
||||||
|
// exception.
|
||||||
|
const char* getExceptionFromPtr(int ptr)
|
||||||
|
{
|
||||||
|
return reinterpret_cast<std::exception*>(ptr)->what();
|
||||||
|
}
|
||||||
|
|
||||||
|
void executeScript(const char* source)
|
||||||
|
{
|
||||||
|
// setup flags
|
||||||
|
for (Luau::FValue<bool>* flag = Luau::FValue<bool>::list; flag; flag = flag->next)
|
||||||
|
if (strncmp(flag->name, "Luau", 4) == 0)
|
||||||
|
flag->value = true;
|
||||||
|
|
||||||
|
// create new state
|
||||||
|
std::unique_ptr<lua_State, void (*)(lua_State*)> globalState(luaL_newstate(), lua_close);
|
||||||
|
lua_State* L = globalState.get();
|
||||||
|
|
||||||
|
// setup state
|
||||||
|
setupState(L);
|
||||||
|
|
||||||
|
// run code + collect error
|
||||||
|
std::string error = runCode(L, source);
|
||||||
|
|
||||||
|
// output error(s)
|
||||||
|
if (error.length())
|
||||||
|
{
|
||||||
|
fprintf(stdout, "%s\n", error.c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Excluded from emscripten compilation to avoid -Wunused-function errors.
|
||||||
|
#ifndef __EMSCRIPTEN__
|
||||||
static void completeIndexer(lua_State* L, const char* editBuffer, size_t start, std::vector<std::string>& completions)
|
static void completeIndexer(lua_State* L, const char* editBuffer, size_t start, std::vector<std::string>& completions)
|
||||||
{
|
{
|
||||||
std::string_view lookup = editBuffer + start;
|
std::string_view lookup = editBuffer + start;
|
||||||
|
@ -253,41 +293,6 @@ static void completeRepl(lua_State* L, const char* editBuffer, std::vector<std::
|
||||||
completeIndexer(L, editBuffer, start, completions);
|
completeIndexer(L, editBuffer, start, completions);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef LUAU_WEB_REPL
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
// Luau errors are exceptions (see luaD_throw) which cannot be directly
|
|
||||||
// handled by emscripten. However we can recieve the pointer in JS and
|
|
||||||
// pass it through to this method to get the string content of the
|
|
||||||
// exception.
|
|
||||||
const char* getExceptionFromPtr(int ptr)
|
|
||||||
{
|
|
||||||
return reinterpret_cast<std::exception*>(ptr)->what();
|
|
||||||
}
|
|
||||||
|
|
||||||
void executeScript(const char* source)
|
|
||||||
{
|
|
||||||
std::unique_ptr<lua_State, void (*)(lua_State*)> globalState(luaL_newstate(), lua_close);
|
|
||||||
lua_State* L = globalState.get();
|
|
||||||
|
|
||||||
setupState(L);
|
|
||||||
|
|
||||||
luaL_sandboxthread(L);
|
|
||||||
|
|
||||||
linenoise::SetCompletionCallback([L](const char* editBuffer, std::vector<std::string>& completions) {
|
|
||||||
completeRepl(L, editBuffer, completions);
|
|
||||||
});
|
|
||||||
|
|
||||||
std::string error = runCode(L, source);
|
|
||||||
|
|
||||||
if (error.length())
|
|
||||||
{
|
|
||||||
fprintf(stdout, "%s\n", error.c_str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static void runRepl()
|
static void runRepl()
|
||||||
{
|
{
|
||||||
std::unique_ptr<lua_State, void (*)(lua_State*)> globalState(luaL_newstate(), lua_close);
|
std::unique_ptr<lua_State, void (*)(lua_State*)> globalState(luaL_newstate(), lua_close);
|
||||||
|
@ -459,7 +464,6 @@ static int assertionHandler(const char* expr, const char* file, int line)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef LUAU_WEB_REPL
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
Luau::assertHandler() = assertionHandler;
|
Luau::assertHandler() = assertionHandler;
|
||||||
|
|
|
@ -6,10 +6,8 @@ endif()
|
||||||
|
|
||||||
cmake_minimum_required(VERSION 3.0)
|
cmake_minimum_required(VERSION 3.0)
|
||||||
project(Luau LANGUAGES CXX)
|
project(Luau LANGUAGES CXX)
|
||||||
set(CMAKE_CXX_STANDARD 17)
|
|
||||||
|
|
||||||
option(LUAU_BUILD_CLI "Build CLI" ON)
|
option(LUAU_BUILD_CLI "Build CLI" ON)
|
||||||
option(LUAU_BUILD_WEB_REPL "Build Web CLI" ON)
|
|
||||||
option(LUAU_BUILD_TESTS "Build tests" ON)
|
option(LUAU_BUILD_TESTS "Build tests" ON)
|
||||||
|
|
||||||
add_library(Luau.Ast STATIC)
|
add_library(Luau.Ast STATIC)
|
||||||
|
@ -17,45 +15,23 @@ add_library(Luau.Compiler STATIC)
|
||||||
add_library(Luau.Analysis STATIC)
|
add_library(Luau.Analysis STATIC)
|
||||||
add_library(Luau.VM STATIC)
|
add_library(Luau.VM STATIC)
|
||||||
|
|
||||||
if(LUAU_BUILD_WEB_REPL AND EMSCRIPTEN)
|
if(LUAU_BUILD_CLI)
|
||||||
# this is a hack, disable cli and tests since we're compiling using emscripten
|
|
||||||
set(LUAU_BUILD_CLI OFF)
|
|
||||||
set(LUAU_BUILD_TESTS OFF)
|
|
||||||
|
|
||||||
add_definitions(-DLUAU_WEB_REPL)
|
|
||||||
|
|
||||||
# luau web repl
|
|
||||||
add_executable(Luau.Repl.Web)
|
|
||||||
|
|
||||||
# configuration below
|
|
||||||
target_compile_options(Luau.Repl.Web PRIVATE ${LUAU_OPTIONS})
|
|
||||||
|
|
||||||
target_include_directories(Luau.Repl.Web PRIVATE extern)
|
|
||||||
target_link_libraries(Luau.Repl.Web PRIVATE Luau.Compiler Luau.VM)
|
|
||||||
|
|
||||||
if(UNIX)
|
|
||||||
target_link_libraries(Luau.Repl.Web PRIVATE pthread)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# declare exported functions to emscripten
|
|
||||||
target_link_options(Luau.Repl.Web PRIVATE -sEXPORTED_FUNCTIONS=['_getExceptionFromPtr','_executeScript'] -sEXPORTED_RUNTIME_METHODS=['ccall','cwrap'] -sNO_DISABLE_EXCEPTION_CATCHING)
|
|
||||||
|
|
||||||
# custom output directory for webm + js file
|
|
||||||
set_target_properties(Luau.Repl.Web PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/docs/assets/luau)
|
|
||||||
else()
|
|
||||||
if(LUAU_BUILD_CLI)
|
|
||||||
add_executable(Luau.Repl.CLI)
|
add_executable(Luau.Repl.CLI)
|
||||||
|
if(NOT EMSCRIPTEN)
|
||||||
add_executable(Luau.Analyze.CLI)
|
add_executable(Luau.Analyze.CLI)
|
||||||
|
endif()
|
||||||
|
|
||||||
# This also adds target `name` on Linux/macOS and `name.exe` on Windows
|
# This also adds target `name` on Linux/macOS and `name.exe` on Windows
|
||||||
set_target_properties(Luau.Repl.CLI PROPERTIES OUTPUT_NAME luau)
|
set_target_properties(Luau.Repl.CLI PROPERTIES OUTPUT_NAME luau)
|
||||||
|
|
||||||
|
if(NOT EMSCRIPTEN)
|
||||||
set_target_properties(Luau.Analyze.CLI PROPERTIES OUTPUT_NAME luau-analyze)
|
set_target_properties(Luau.Analyze.CLI PROPERTIES OUTPUT_NAME luau-analyze)
|
||||||
endif()
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
if(LUAU_BUILD_TESTS)
|
if(LUAU_BUILD_TESTS AND NOT EMSCRIPTEN)
|
||||||
add_executable(Luau.UnitTest)
|
add_executable(Luau.UnitTest)
|
||||||
add_executable(Luau.Conformance)
|
add_executable(Luau.Conformance)
|
||||||
endif()
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
include(Sources.cmake)
|
include(Sources.cmake)
|
||||||
|
@ -83,11 +59,6 @@ if(MSVC)
|
||||||
else()
|
else()
|
||||||
list(APPEND LUAU_OPTIONS -Wall) # All warnings
|
list(APPEND LUAU_OPTIONS -Wall) # All warnings
|
||||||
list(APPEND LUAU_OPTIONS -Werror) # Warnings are errors
|
list(APPEND LUAU_OPTIONS -Werror) # Warnings are errors
|
||||||
|
|
||||||
# temporary hot fix (removes need for commenting out line above when compiling with Clang)
|
|
||||||
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
|
||||||
list(APPEND LUAU_OPTIONS -Wno-unused) # GCC considers variables declared/checked in if() as unused
|
|
||||||
endif()
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
target_compile_options(Luau.Ast PRIVATE ${LUAU_OPTIONS})
|
target_compile_options(Luau.Ast PRIVATE ${LUAU_OPTIONS})
|
||||||
|
@ -96,7 +67,10 @@ target_compile_options(Luau.VM PRIVATE ${LUAU_OPTIONS})
|
||||||
|
|
||||||
if(LUAU_BUILD_CLI)
|
if(LUAU_BUILD_CLI)
|
||||||
target_compile_options(Luau.Repl.CLI PRIVATE ${LUAU_OPTIONS})
|
target_compile_options(Luau.Repl.CLI PRIVATE ${LUAU_OPTIONS})
|
||||||
|
|
||||||
|
if(NOT EMSCRIPTEN)
|
||||||
target_compile_options(Luau.Analyze.CLI PRIVATE ${LUAU_OPTIONS})
|
target_compile_options(Luau.Analyze.CLI PRIVATE ${LUAU_OPTIONS})
|
||||||
|
endif()
|
||||||
|
|
||||||
target_include_directories(Luau.Repl.CLI PRIVATE extern)
|
target_include_directories(Luau.Repl.CLI PRIVATE extern)
|
||||||
target_link_libraries(Luau.Repl.CLI PRIVATE Luau.Compiler Luau.VM)
|
target_link_libraries(Luau.Repl.CLI PRIVATE Luau.Compiler Luau.VM)
|
||||||
|
@ -105,10 +79,20 @@ if(LUAU_BUILD_CLI)
|
||||||
target_link_libraries(Luau.Repl.CLI PRIVATE pthread)
|
target_link_libraries(Luau.Repl.CLI PRIVATE pthread)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(NOT EMSCRIPTEN)
|
||||||
target_link_libraries(Luau.Analyze.CLI PRIVATE Luau.Analysis)
|
target_link_libraries(Luau.Analyze.CLI PRIVATE Luau.Analysis)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(EMSCRIPTEN)
|
||||||
|
# declare exported functions to emscripten
|
||||||
|
target_link_options(Luau.Repl.CLI PRIVATE -sEXPORTED_FUNCTIONS=['_getExceptionFromPtr','_executeScript'] -sEXPORTED_RUNTIME_METHODS=['ccall','cwrap'] -sNO_DISABLE_EXCEPTION_CATCHING)
|
||||||
|
|
||||||
|
# custom output directory for wasm + js file
|
||||||
|
set_target_properties(Luau.Repl.CLI PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/docs/assets/luau)
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(LUAU_BUILD_TESTS)
|
if(LUAU_BUILD_TESTS AND NOT EMSCRIPTEN)
|
||||||
target_compile_options(Luau.UnitTest PRIVATE ${LUAU_OPTIONS})
|
target_compile_options(Luau.UnitTest PRIVATE ${LUAU_OPTIONS})
|
||||||
target_include_directories(Luau.UnitTest PRIVATE extern)
|
target_include_directories(Luau.UnitTest PRIVATE extern)
|
||||||
target_link_libraries(Luau.UnitTest PRIVATE Luau.Analysis Luau.Compiler)
|
target_link_libraries(Luau.UnitTest PRIVATE Luau.Analysis Luau.Compiler)
|
||||||
|
|
|
@ -160,16 +160,6 @@ if(TARGET Luau.Repl.CLI)
|
||||||
CLI/Repl.cpp)
|
CLI/Repl.cpp)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (TARGET Luau.Repl.Web)
|
|
||||||
# Luau.Repl.Web Sources
|
|
||||||
target_sources(Luau.Repl.Web PRIVATE
|
|
||||||
CLI/FileUtils.h
|
|
||||||
CLI/FileUtils.cpp
|
|
||||||
CLI/Profiler.h
|
|
||||||
CLI/Profiler.cpp
|
|
||||||
CLI/Repl.cpp)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(TARGET Luau.Analyze.CLI)
|
if(TARGET Luau.Analyze.CLI)
|
||||||
# Luau.Analyze.CLI Sources
|
# Luau.Analyze.CLI Sources
|
||||||
target_sources(Luau.Analyze.CLI PRIVATE
|
target_sources(Luau.Analyze.CLI PRIVATE
|
||||||
|
|
Loading…
Add table
Reference in a new issue