diff options
author | Mnikolenko Productengine <mnikolenko@productengine.com> | 2024-01-26 16:49:19 +0200 |
---|---|---|
committer | Mnikolenko Productengine <mnikolenko@productengine.com> | 2024-01-26 17:28:46 +0200 |
commit | 81e1963f57d3a8a189cc78beb9c6acee1b0e129b (patch) | |
tree | 8adadc46838c6a2e959d947b3e5b5ace13cf7864 | |
parent | 6ffc1268b23d32c03e6bea5edeaeafb593bede0f (diff) |
DRTVWR-589: update to start using Luau libs
-rw-r--r-- | autobuild.xml | 46 | ||||
-rw-r--r-- | indra/cmake/Copy3rdPartyLibs.cmake | 1 | ||||
-rw-r--r-- | indra/cmake/Lualibs.cmake | 11 | ||||
-rw-r--r-- | indra/newview/CMakeLists.txt | 1 | ||||
-rw-r--r-- | indra/newview/llfloaterluadebug.h | 7 | ||||
-rw-r--r-- | indra/newview/llluamanager.cpp | 114 | ||||
-rwxr-xr-x | indra/newview/viewer_manifest.py | 3 |
7 files changed, 97 insertions, 86 deletions
diff --git a/autobuild.xml b/autobuild.xml index 8c4c6e0f9f..d3eec0dcb4 100644 --- a/autobuild.xml +++ b/autobuild.xml @@ -1658,42 +1658,10 @@ <key>name</key> <string>llphysicsextensions_tpv</string> </map> - <key>lua</key> + <key>luau</key> <map> <key>platforms</key> <map> - <key>darwin64</key> - <map> - <key>archive</key> - <map> - <key>creds</key> - <string>github</string> - <key>hash</key> - <string>50cf091adb3e145b1b9f783415e897dc0a6dc570</string> - <key>hash_algorithm</key> - <string>sha1</string> - <key>url</key> - <string>https://api.github.com/repos/secondlife/3p-lua/releases/assets/133676222</string> - </map> - <key>name</key> - <string>darwin64</string> - </map> - <key>linux64</key> - <map> - <key>archive</key> - <map> - <key>creds</key> - <string>github</string> - <key>hash</key> - <string>5f4607c388bd9ed91bc85719696dbc1f4777e7d4</string> - <key>hash_algorithm</key> - <string>sha1</string> - <key>url</key> - <string>https://api.github.com/repos/secondlife/3p-lua/releases/assets/133676226</string> - </map> - <key>name</key> - <string>linux64</string> - </map> <key>windows64</key> <map> <key>archive</key> @@ -1701,11 +1669,11 @@ <key>creds</key> <string>github</string> <key>hash</key> - <string>efde67ff252f9dbe0c4b806389da4318a619f9ac</string> + <string>eb21a1feaf86e14d6a5068ba90b78b7b6b0c4b3c</string> <key>hash_algorithm</key> <string>sha1</string> <key>url</key> - <string>https://api.github.com/repos/secondlife/3p-lua/releases/assets/133676232</string> + <string>https://api.github.com/repos/secondlife/3p-luau-proto/releases/assets/147845711</string> </map> <key>name</key> <string>windows64</string> @@ -1716,13 +1684,13 @@ <key>license_file</key> <string>LICENSES/lua.txt</string> <key>copyright</key> - <string>Copyright (c) 1994–2023 Lua.org, PUC-Rio.</string> + <string>Copyright (c) 2019-2023 Roblox Corporation, Copyright (c) 1994–2019 Lua.org, PUC-Rio.</string> <key>version</key> - <string>5.4.6</string> + <string>0.609</string> <key>name</key> - <string>lua</string> + <string>luau</string> <key>description</key> - <string>Lua is a powerful, efficient, lightweight, embeddable scripting language developed by a team at PUC-Rio, the Pontifical Catholic University of Rio de Janeiro in Brazil.</string> + <string>Luau is a fast, small, safe, gradually typed embeddable scripting language derived from Lua.</string> </map> <key>mesa</key> <map> diff --git a/indra/cmake/Copy3rdPartyLibs.cmake b/indra/cmake/Copy3rdPartyLibs.cmake index c2f4949bb7..7938d4f54b 100644 --- a/indra/cmake/Copy3rdPartyLibs.cmake +++ b/indra/cmake/Copy3rdPartyLibs.cmake @@ -60,7 +60,6 @@ if(WINDOWS) nghttp2.dll libhunspell.dll uriparser.dll - lua54.dll ) # OpenSSL diff --git a/indra/cmake/Lualibs.cmake b/indra/cmake/Lualibs.cmake index b6a7de41c6..2832cc1fc9 100644 --- a/indra/cmake/Lualibs.cmake +++ b/indra/cmake/Lualibs.cmake @@ -8,15 +8,16 @@ add_library( ll::lualibs INTERFACE IMPORTED ) use_system_binary( lualibs ) -use_prebuilt_binary(lua) +use_prebuilt_binary(luau) target_include_directories( ll::lualibs SYSTEM INTERFACE ${LIBS_PREBUILT_DIR}/include ) if (WINDOWS) - target_link_libraries(ll::lualibs INTERFACE ${ARCH_PREBUILT_DIRS_RELEASE}/lua54.lib) -elseif (DARWIN) - target_link_libraries(ll::lualibs INTERFACE ${ARCH_PREBUILT_DIRS_RELEASE}/liblua.a) -elseif (LINUX) + target_link_libraries(ll::lualibs INTERFACE ${ARCH_PREBUILT_DIRS_RELEASE}/Luau.Ast.lib) + target_link_libraries(ll::lualibs INTERFACE ${ARCH_PREBUILT_DIRS_RELEASE}/Luau.CodeGen.lib) + target_link_libraries(ll::lualibs INTERFACE ${ARCH_PREBUILT_DIRS_RELEASE}/Luau.Compiler.lib) + target_link_libraries(ll::lualibs INTERFACE ${ARCH_PREBUILT_DIRS_RELEASE}/Luau.Config.lib) + target_link_libraries(ll::lualibs INTERFACE ${ARCH_PREBUILT_DIRS_RELEASE}/Luau.VM.lib) endif (WINDOWS) diff --git a/indra/newview/CMakeLists.txt b/indra/newview/CMakeLists.txt index b45841eb6b..ba2f252593 100644 --- a/indra/newview/CMakeLists.txt +++ b/indra/newview/CMakeLists.txt @@ -1729,7 +1729,6 @@ if (WINDOWS) ${SHARED_LIB_STAGING_DIR}/openjp2.dll ${SHARED_LIB_STAGING_DIR}/libhunspell.dll ${SHARED_LIB_STAGING_DIR}/uriparser.dll - ${SHARED_LIB_STAGING_DIR}/lua54.dll #${SHARED_LIB_STAGING_DIR}/${LL_INTDIR}/SLVoice.exe #${SHARED_LIB_STAGING_DIR}/${LL_INTDIR}/libsndfile-1.dll #${SHARED_LIB_STAGING_DIR}/${LL_INTDIR}/vivoxoal.dll diff --git a/indra/newview/llfloaterluadebug.h b/indra/newview/llfloaterluadebug.h index fd61e29ebe..1e26828c83 100644 --- a/indra/newview/llfloaterluadebug.h +++ b/indra/newview/llfloaterluadebug.h @@ -31,9 +31,10 @@ extern "C" { -#include "lua/lua.h" -#include "lua/lauxlib.h" -#include "lua/lualib.h" +#include "luau/luacode.h" +#include "luau/lua.h" +#include "luau/luaconf.h" +#include "luau/lualib.h" } class LLLineEditor; diff --git a/indra/newview/llluamanager.cpp b/indra/newview/llluamanager.cpp index 2bdf4fd0b0..49bc83c66b 100644 --- a/indra/newview/llluamanager.cpp +++ b/indra/newview/llluamanager.cpp @@ -64,9 +64,21 @@ extern LLUIListener sUIListener; #include <boost/algorithm/string/replace.hpp> -#include "lua/lua.h" -#include "lua/lauxlib.h" -#include "lua/lualib.h" +#include "luau/luacode.h" +#include "luau/lua.h" +#include "luau/luaconf.h" +#include "luau/lualib.h" + +#if LL_WINDOWS +#pragma comment(lib, "Luau.Compiler.lib") +#pragma comment(lib, "Luau.Ast.lib") +#pragma comment(lib, "Luau.CodeGen.lib") +#pragma comment(lib, "Luau.Config.lib") +#pragma comment(lib, "Luau.VM.lib") +#endif + +#define lua_register(L, n, f) (lua_pushcfunction(L, (f), n), lua_setglobal(L, (n))) +#define lua_rawlen lua_objlen #include <algorithm> #include <cstdlib> // std::rand() @@ -289,9 +301,10 @@ int name##_::call(lua_State* L) // ... supply method body here, referencing 'L' ... // } +/* // This function consumes ALL Lua stack arguments and returns concatenated // message string -std::string lua_print_msg(lua_State* L, const std::string_view& level) +std::string lua_print_msg_args(lua_State* L, const std::string_view& level) { // On top of existing Lua arguments, push 'where' info luaL_checkstack(L, 1, nullptr); @@ -329,6 +342,20 @@ std::string lua_print_msg(lua_State* L, const std::string_view& level) LLEventPumps::instance().obtain("lua output").post(stringize(level, ": ", msg)); return msg; } +*/ + +std::string lua_print_msg(lua_State *L, const std::string_view &level) +{ + lua_getglobal(L, "tostring"); + + lua_pushvalue(L, -1); /* function to be called */ + lua_pushvalue(L, 1); /* value to print */ + lua_call(L, 1, 1); + std::string msg = lua_tostring(L, -1); + + LLEventPumps::instance().obtain("lua output").post(stringize(level, ": ", msg)); + return msg; +} lua_function(print_debug) { @@ -819,7 +846,8 @@ lua_function(listen_events) { if (! lua_isfunction(L, 1)) { - return luaL_typeerror(L, 1, "function"); + luaL_typeerror(L, 1, "function"); + return 0; } luaL_checkstack(L, 2, nullptr); @@ -829,7 +857,7 @@ lua_function(listen_events) // suspended) coroutine thread. // Registry table is at pseudo-index LUA_REGISTRYINDEX // Main thread is at registry key LUA_RIDX_MAINTHREAD - auto regtype{ lua_geti(L, LUA_REGISTRYINDEX, LUA_RIDX_MAINTHREAD) }; + auto regtype {lua_rawgeti(L, LUA_REGISTRYINDEX, 1 /*LUA_RIDX_MAINTHREAD*/)}; // Not finding the main thread at the documented place isn't a user error, // it's a Problem llassert_always(regtype == LUA_TTHREAD); @@ -996,15 +1024,25 @@ void LLLUAmanager::runScriptFile(const std::string& filename, script_finished_fn lua_register(L, "sleep", LUA_sleep_func); - if (L.checkLua(luaL_dofile(L, filename.c_str()))) + llifstream in_file; + in_file.open(filename.c_str()); + + if (in_file.is_open()) { - lua_getglobal(L, "call_once_func"); - if (lua_isfunction(L, -1)) - { - // call call_once_func(), setting internal error message if - // error - L.checkLua(lua_pcall(L, 0, 0, 0)); - } + std::string text((std::istreambuf_iterator<char>(in_file)), std::istreambuf_iterator<char>()); + + size_t bytecodeSize = 0; + char *bytecode = luau_compile(text.c_str(), text.length(), NULL, &bytecodeSize); + L.checkLua(luau_load(L, desc.c_str(), bytecode, bytecodeSize, 0)); + free(bytecode); + + L.checkLua(lua_pcall(L, 0, 0, 0)); + + in_file.close(); + } + else + { + LL_WARNS("Lua") << "unable to open script file '" << filename << "'" << LL_ENDL; } }); } @@ -1024,7 +1062,12 @@ void LLLUAmanager::runScriptLine(const std::string& cmd, script_finished_fn cb) LLCoros::instance().launch(desc, [desc, cmd, cb]() { LuaState L(desc, cb); - L.checkLua(luaL_dostring(L, cmd.c_str())); + + size_t bytecodeSize = 0; + char *bytecode = luau_compile(cmd.c_str(), cmd.length(), NULL, &bytecodeSize); + L.checkLua(luau_load(L, desc.c_str(), bytecode, bytecodeSize, 0)); + free(bytecode); + L.checkLua(lua_pcall(L, 0, 0, 0)); }); } @@ -1104,8 +1147,8 @@ public: case LUA_TUSERDATA: { - const size_t maxlen = 20; - size_t binlen{ lua_rawlen(self.L, self.index) }; + const S32 maxlen = 20; + S32 binlen{ lua_rawlen(self.L, self.index) }; LLSD::Binary binary(std::min(maxlen, binlen)); std::memcpy(binary.data(), lua_touserdata(self.L, self.index), binary.size()); out << LL::hexdump(binary); @@ -1333,7 +1376,7 @@ LLSD lua_tollsd(lua_State* L, int index) // operator is truthful, avoid allocations while we grow the keys // vector. Even if it's not, we can still grow the vector, albeit // a little less efficiently. - keys.reserve(luaL_len(L, index)); + keys.reserve(lua_objlen(L, index)); do { auto arraykeytype{ lua_type(L, -2) }; @@ -1347,12 +1390,13 @@ LLSD lua_tollsd(lua_State* L, int index) { // key isn't an integer - this doesn't fit our LLSD // array constraints - return luaL_error(L, "Expected integer array key, got %f instead", - lua_tonumber(L, -2)); + luaL_error(L, "Expected integer array key, got %f instead", lua_tonumber(L, -2)); + return 0; } if (intkey < 1) { - return luaL_error(L, "array key %d out of bounds", int(intkey)); + luaL_error(L, "array key %d out of bounds", int(intkey)); + return 0; } keys.push_back(LLSD::Integer(intkey)); @@ -1361,12 +1405,12 @@ LLSD lua_tollsd(lua_State* L, int index) case LUA_TSTRING: // break out strings specially to report the value - return luaL_error(L, "Cannot convert string array key '%s' to LLSD", - lua_tostring(L, -2)); + luaL_error(L, "Cannot convert string array key '%s' to LLSD", lua_tostring(L, -2)); + return 0; default: - return luaL_error(L, "Cannot convert %s array key to LLSD", - lua_typename(L, arraykeytype)); + luaL_error(L, "Cannot convert %s array key to LLSD", lua_typename(L, arraykeytype)); + return 0; } // remove value, keep key for next iteration @@ -1378,8 +1422,8 @@ LLSD lua_tollsd(lua_State* L, int index) size_t array_max{ 10000 }; if (keys.size() > array_max) { - return luaL_error(L, "Conversion from Lua to LLSD array limited to %d entries", - int(array_max)); + luaL_error(L, "Conversion from Lua to LLSD array limited to %d entries", int(array_max)); + return 0; } // We know the smallest key is >= 1. Check the largest. We also // know the vector is NOT empty, else we wouldn't have gotten here. @@ -1389,7 +1433,8 @@ LLSD lua_tollsd(lua_State* L, int index) { // Looks like we've gone beyond intentional array gaps into // crazy key territory. - return luaL_error(L, "Gaps in Lua table too large for conversion to LLSD array"); + luaL_error(L, "Gaps in Lua table too large for conversion to LLSD array"); + return 0; } LL_DEBUGS("Lua") << "collected " << keys.size() << " keys, max " << highkey << LL_ENDL; // right away expand the result array to the size we'll need @@ -1420,8 +1465,8 @@ LLSD lua_tollsd(lua_State* L, int index) auto mapkeytype{ lua_type(L, -2) }; if (mapkeytype != LUA_TSTRING) { - return luaL_error(L, "Cannot convert %s map key to LLSD", - lua_typename(L, mapkeytype)); + luaL_error(L, "Cannot convert %s map key to LLSD", lua_typename(L, mapkeytype)); + return 0; } auto key{ lua_tostdstring(L, -2) }; @@ -1436,8 +1481,8 @@ LLSD lua_tollsd(lua_State* L, int index) default: // First Lua key isn't number or string: sorry - return luaL_error(L, "Cannot convert %s table key to LLSD", - lua_typename(L, firstkeytype)); + luaL_error(L, "Cannot convert %s table key to LLSD", lua_typename(L, firstkeytype)); + return 0; } } @@ -1445,7 +1490,8 @@ LLSD lua_tollsd(lua_State* L, int index) // Other Lua entities (e.g. function, C function, light userdata, // thread, userdata) are not convertible to LLSD, indicating a coding // error in the caller. - return luaL_error(L, "Cannot convert type %s to LLSD", luaL_typename(L, index)); + luaL_error(L, "Cannot convert type %s to LLSD", luaL_typename(L, index)); + return 0; } } @@ -1505,7 +1551,7 @@ void lua_pushllsd(lua_State* L, const LLSD& data) // push new array value: table at -2, value at -1 lua_pushllsd(L, item); // pop value, assign table[key] = value - lua_seti(L, -2, ++key); + lua_rawseti(L, -2, ++key); } break; } diff --git a/indra/newview/viewer_manifest.py b/indra/newview/viewer_manifest.py index 98240d3a78..1fa4df1682 100755 --- a/indra/newview/viewer_manifest.py +++ b/indra/newview/viewer_manifest.py @@ -565,9 +565,6 @@ class Windows_x86_64_Manifest(ViewerManifest): # Uriparser self.path("uriparser.dll") - # lua libs - self.path("lua54.dll") - # These need to be installed as a SxS assembly, currently a 'private' assembly. # See http://msdn.microsoft.com/en-us/library/ms235291(VS.80).aspx self.path("msvcp140.dll") |