Merge branch 'main' into main
This commit is contained in:
@@ -11,7 +11,19 @@
|
||||
lua::luaerror::luaerror(const std::string& message) : std::runtime_error(message) {
|
||||
}
|
||||
|
||||
void lua::LuaState::removeLibFuncs(const char* libname, const char* funcs[]) {
|
||||
if (getglobal(libname)) {
|
||||
for (uint i = 0; funcs[i]; i++) {
|
||||
pushnil();
|
||||
setfield(funcs[i], -2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lua::LuaState::LuaState() {
|
||||
std::cout << LUA_VERSION << std::endl;
|
||||
std::cout << LUAJIT_VERSION << std::endl;
|
||||
|
||||
L = luaL_newstate();
|
||||
if (L == nullptr) {
|
||||
throw lua::luaerror("could not to initialize Lua");
|
||||
@@ -25,10 +37,19 @@ lua::LuaState::LuaState() {
|
||||
luaopen_jit(L);
|
||||
luaopen_bit(L);
|
||||
|
||||
std::cout << LUA_VERSION << std::endl;
|
||||
std::cout << LUAJIT_VERSION << std::endl;
|
||||
luaopen_os(L);
|
||||
const char* removed_os[] {
|
||||
"execute",
|
||||
"exit",
|
||||
"remove",
|
||||
"rename",
|
||||
"setlocale",
|
||||
"tmpname",
|
||||
nullptr
|
||||
};
|
||||
removeLibFuncs("os", removed_os);
|
||||
|
||||
createFuncs();
|
||||
createLibs();
|
||||
|
||||
lua_pushvalue(L, LUA_GLOBALSINDEX);
|
||||
setglobal(envName(0));
|
||||
@@ -94,7 +115,7 @@ void lua::LuaState::remove(const std::string& name) {
|
||||
lua_setglobal(L, name.c_str());
|
||||
}
|
||||
|
||||
void lua::LuaState::createFuncs() {
|
||||
void lua::LuaState::createLibs() {
|
||||
openlib("pack", packlib, 0);
|
||||
openlib("world", worldlib, 0);
|
||||
openlib("player", playerlib, 0);
|
||||
|
||||
@@ -21,6 +21,9 @@ namespace lua {
|
||||
|
||||
void logError(const std::string& text);
|
||||
void initEnvironment();
|
||||
|
||||
void removeLibFuncs(const char* libname, const char* funcs[]);
|
||||
void createLibs();
|
||||
public:
|
||||
LuaState();
|
||||
~LuaState();
|
||||
@@ -55,7 +58,6 @@ namespace lua {
|
||||
bool hasglobal(const std::string& name);
|
||||
bool rename(const std::string& from, const std::string& to);
|
||||
void remove(const std::string& name);;
|
||||
void createFuncs();
|
||||
int createEnvironment(int parent);
|
||||
void removeEnvironment(int id);
|
||||
const std::string storeAnonymous();
|
||||
|
||||
@@ -40,6 +40,7 @@ int l_hud_open_block(lua_State* L) {
|
||||
lua::luaint x = lua_tointeger(L, 1);
|
||||
lua::luaint y = lua_tointeger(L, 2);
|
||||
lua::luaint z = lua_tointeger(L, 3);
|
||||
bool playerInventory = !lua_toboolean(L, 4);
|
||||
|
||||
voxel* vox = scripting::level->chunks->get(x, y, z);
|
||||
if (vox == nullptr) {
|
||||
@@ -55,7 +56,7 @@ int l_hud_open_block(lua_State* L) {
|
||||
auto id = scripting::blocks->createBlockInventory(x, y, z);
|
||||
|
||||
scripting::hud->openInventory(
|
||||
glm::ivec3(x, y, z), layout, scripting::level->inventories->get(id)
|
||||
glm::ivec3(x, y, z), layout, scripting::level->inventories->get(id), playerInventory
|
||||
);
|
||||
|
||||
lua_pushinteger(L, id);
|
||||
|
||||
@@ -66,6 +66,21 @@ wstringsupplier scripting::create_wstring_supplier(
|
||||
};
|
||||
}
|
||||
|
||||
wstringchecker scripting::create_wstring_validator(
|
||||
int env,
|
||||
const std::string& src,
|
||||
const std::string& file
|
||||
) {
|
||||
return [=](const std::wstring& x){
|
||||
if (processCallback(env, src, file)) {
|
||||
state->pushstring(util::wstr2str_utf8(x));
|
||||
if (state->callNoThrow(1))
|
||||
return state->toboolean(-1);
|
||||
}
|
||||
return false;
|
||||
};
|
||||
}
|
||||
|
||||
boolconsumer scripting::create_bool_consumer(
|
||||
int env,
|
||||
const std::string& src,
|
||||
|
||||
@@ -24,6 +24,12 @@ namespace scripting {
|
||||
const std::string& file="<string>"
|
||||
);
|
||||
|
||||
wstringchecker create_wstring_validator(
|
||||
int env,
|
||||
const std::string& src,
|
||||
const std::string& file="<string>"
|
||||
);
|
||||
|
||||
boolconsumer create_bool_consumer(
|
||||
int env,
|
||||
const std::string& src,
|
||||
|
||||
Reference in New Issue
Block a user