create simple interface

This commit is contained in:
Pelanyo Kamara 2021-11-06 22:14:45 +00:00
parent c4fbdf55c0
commit 92f9b7363e
No known key found for this signature in database
GPG key ID: 848AD95363B749B5
3 changed files with 58 additions and 1003 deletions

View file

@ -252,7 +252,16 @@ static void completeRepl(lua_State* L, const char* editBuffer, std::vector<std::
#ifdef LUAU_WEB_REPL #ifdef LUAU_WEB_REPL
extern "C" extern "C"
{ {
const char* executeOnce(const char* source) // 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); std::unique_ptr<lua_State, void (*)(lua_State*)> globalState(luaL_newstate(), lua_close);
lua_State* L = globalState.get(); lua_State* L = globalState.get();
@ -271,8 +280,6 @@ extern "C"
{ {
fprintf(stdout, "%s\n", error.c_str()); fprintf(stdout, "%s\n", error.c_str());
} }
return error.c_str();
} }
} }
#endif #endif
@ -457,7 +464,6 @@ 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();

File diff suppressed because one or more lines are too long

View file

@ -38,7 +38,7 @@ if(LUAU_BUILD_WEB_REPL AND EMSCRIPTEN)
endif() endif()
# declare exported functions to emscripten # declare exported functions to emscripten
target_link_options(Luau.Repl.Web PRIVATE -sEXPORTED_FUNCTIONS=['_executeOnce'] -sEXPORTED_RUNTIME_METHODS=['ccall','cwrap']) target_link_options(Luau.Repl.Web PRIVATE -sEXPORTED_FUNCTIONS=['_getExceptionFromPtr','_executeScript'] -sEXPORTED_RUNTIME_METHODS=['ccall','cwrap'] -sNO_DISABLE_EXCEPTION_CATCHING)
# copy html directory # 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) add_custom_command(TARGET Luau.Repl.Web PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/CLI/html ${CMAKE_BINARY_DIR}/webrepl)