mirror of
https://github.com/luau-lang/luau.git
synced 2025-04-07 20:30:53 +01:00
flesh out webrepl base
This commit is contained in:
parent
c0b95b8961
commit
c4fbdf55c0
5 changed files with 1098 additions and 13 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -5,3 +5,4 @@
|
||||||
^default.prof*
|
^default.prof*
|
||||||
^fuzz-*
|
^fuzz-*
|
||||||
^luau$
|
^luau$
|
||||||
|
/.vs
|
||||||
|
|
33
CLI/Repl.cpp
33
CLI/Repl.cpp
|
@ -249,6 +249,34 @@ 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"
|
||||||
|
{
|
||||||
|
const char* executeOnce(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());
|
||||||
|
}
|
||||||
|
|
||||||
|
return 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);
|
||||||
|
@ -420,6 +448,7 @@ 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;
|
||||||
|
@ -428,6 +457,7 @@ int main(int argc, char** argv)
|
||||||
if (strncmp(flag->name, "Luau", 4) == 0)
|
if (strncmp(flag->name, "Luau", 4) == 0)
|
||||||
flag->value = true;
|
flag->value = true;
|
||||||
|
|
||||||
|
executeCode("print'asd'");
|
||||||
if (argc == 1)
|
if (argc == 1)
|
||||||
{
|
{
|
||||||
runRepl();
|
runRepl();
|
||||||
|
@ -511,5 +541,4 @@ int main(int argc, char** argv)
|
||||||
return failed;
|
return failed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
1011
CLI/html/index.html
Normal file
1011
CLI/html/index.html
Normal file
File diff suppressed because one or more lines are too long
|
@ -6,8 +6,10 @@ 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)
|
||||||
|
@ -15,19 +17,50 @@ 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_CLI)
|
if(LUAU_BUILD_WEB_REPL AND EMSCRIPTEN)
|
||||||
add_executable(Luau.Repl.CLI)
|
# this is a hack, disable cli and tests since we're compiling using emscripten
|
||||||
add_executable(Luau.Analyze.CLI)
|
set(LUAU_BUILD_CLI OFF)
|
||||||
|
set(LUAU_BUILD_TESTS OFF)
|
||||||
|
|
||||||
# This also adds target `name` on Linux/macOS and `name.exe` on Windows
|
add_definitions(-DLUAU_WEB_REPL)
|
||||||
set_target_properties(Luau.Repl.CLI PROPERTIES OUTPUT_NAME luau)
|
|
||||||
set_target_properties(Luau.Analyze.CLI PROPERTIES OUTPUT_NAME luau-analyze)
|
# 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=['_executeOnce'] -sEXPORTED_RUNTIME_METHODS=['ccall','cwrap'])
|
||||||
|
|
||||||
|
# copy html directory
|
||||||
|
add_custom_command(TARGET Luau.Repl.Web PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/CLI/html ${CMAKE_BINARY_DIR}/webrepl)
|
||||||
|
|
||||||
|
# custom output directory for webm + js file
|
||||||
|
set_target_properties(Luau.Repl.Web PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/webrepl/luau)
|
||||||
|
else()
|
||||||
|
if(LUAU_BUILD_CLI)
|
||||||
|
add_executable(Luau.Repl.CLI)
|
||||||
|
add_executable(Luau.Analyze.CLI)
|
||||||
|
|
||||||
|
# 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.Analyze.CLI PROPERTIES OUTPUT_NAME luau-analyze)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(LUAU_BUILD_TESTS)
|
||||||
|
add_executable(Luau.UnitTest)
|
||||||
|
add_executable(Luau.Conformance)
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(LUAU_BUILD_TESTS)
|
|
||||||
add_executable(Luau.UnitTest)
|
|
||||||
add_executable(Luau.Conformance)
|
|
||||||
endif()
|
|
||||||
include(Sources.cmake)
|
include(Sources.cmake)
|
||||||
|
|
||||||
target_compile_features(Luau.Ast PUBLIC cxx_std_17)
|
target_compile_features(Luau.Ast PUBLIC cxx_std_17)
|
||||||
|
@ -54,7 +87,8 @@ 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
|
||||||
|
|
||||||
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
# 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
|
list(APPEND LUAU_OPTIONS -Wno-unused) # GCC considers variables declared/checked in if() as unused
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
|
@ -157,6 +157,16 @@ 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