mirror of
https://github.com/luau-lang/luau.git
synced 2025-04-11 22:30:53 +01:00
create simple interface
This commit is contained in:
parent
c4fbdf55c0
commit
92f9b7363e
3 changed files with 58 additions and 1003 deletions
14
CLI/Repl.cpp
14
CLI/Repl.cpp
|
@ -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();
|
||||||
|
|
1045
CLI/html/index.html
1045
CLI/html/index.html
File diff suppressed because one or more lines are too long
|
@ -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)
|
||||||
|
|
Loading…
Add table
Reference in a new issue