mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-08 04:21:50 +00:00
add direct-scripting-data-access setting
This commit is contained in:
parent
dc9ae6e99e
commit
24a2c35f41
5 changed files with 31 additions and 25 deletions
|
|
@ -5,6 +5,7 @@
|
|||
#include <iostream>
|
||||
|
||||
#include "util/stringutil.hpp"
|
||||
#include "engine/Engine.hpp"
|
||||
|
||||
using namespace lua;
|
||||
|
||||
|
|
@ -369,3 +370,29 @@ void lua::remove_environment(State* L, int id) {
|
|||
pushnil(L);
|
||||
store_env(L, id);
|
||||
}
|
||||
|
||||
std::string_view lua::bytearray_as_string(lua::State* L, int idx) {
|
||||
const auto& settings = scripting::engine->getSettings();
|
||||
if (type(L, idx) == LUA_TSTRING) {
|
||||
return tolstring(L, idx);
|
||||
}
|
||||
pushvalue(L, idx);
|
||||
|
||||
if (settings.system.directScriptingDataAccess.get()) {
|
||||
requireglobal(L, "Bytearray_as_ptr");
|
||||
pushvalue(L, -2);
|
||||
call(L, 1, 2);
|
||||
auto view = tolstring(L, -2);
|
||||
uint64_t size = touinteger(L, -1);
|
||||
auto ptr = (const char*)std::stoull(std::string(view), nullptr, 16);
|
||||
pop(L, 3);
|
||||
return std::string_view(ptr, size);
|
||||
} else {
|
||||
requireglobal(L, "Bytearray_as_string");
|
||||
pushvalue(L, -2);
|
||||
call(L, 1, 1);
|
||||
auto view = tolstring(L, -1);
|
||||
pop(L, 2);
|
||||
return view;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -828,27 +828,5 @@ namespace lua {
|
|||
return create_bytearray(L, bytes.data(), bytes.size());
|
||||
}
|
||||
|
||||
inline std::string_view bytearray_as_string(lua::State* L, int idx) {
|
||||
if (type(L, idx) == LUA_TSTRING) {
|
||||
return tolstring(L, idx);
|
||||
}
|
||||
pushvalue(L, idx);
|
||||
#ifdef VC_LUA_DIRECT_BYTEARRAY_ACCESS
|
||||
requireglobal(L, "Bytearray_as_ptr");
|
||||
pushvalue(L, -2);
|
||||
call(L, 1, 2);
|
||||
auto view = tolstring(L, -2);
|
||||
uint64_t size = touinteger(L, -1);
|
||||
auto ptr = (const char*)std::stoull(std::string(view), nullptr, 16);
|
||||
pop(L, 3);
|
||||
return std::string_view(ptr, size);
|
||||
#else
|
||||
requireglobal(L, "Bytearray_as_string");
|
||||
pushvalue(L, -2);
|
||||
call(L, 1, 1);
|
||||
auto view = tolstring(L, -1);
|
||||
pop(L, 2);
|
||||
return view;
|
||||
#endif // VC_LUA_DIRECT_BYTEARRAY_ACCESS
|
||||
}
|
||||
std::string_view bytearray_as_string(lua::State* L, int idx);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue