]> git.lizzy.rs Git - minetest.git/blobdiff - src/script/lua_api/l_localplayer.cpp
Remove setlocal and setupvalue from `debug` table whitelist
[minetest.git] / src / script / lua_api / l_localplayer.cpp
index 851ede53570dda8e68dde7559872017e8b3083b3..bdbe98cb0422fa7705cb6279d95781a5ba1a5617 100644 (file)
@@ -128,11 +128,11 @@ int LuaLocalPlayer::l_is_in_liquid_stable(lua_State *L)
        return 1;
 }
 
-int LuaLocalPlayer::l_get_liquid_viscosity(lua_State *L)
+int LuaLocalPlayer::l_get_move_resistance(lua_State *L)
 {
        LocalPlayer *player = getobject(L, 1);
 
-       lua_pushinteger(L, player->liquid_viscosity);
+       lua_pushinteger(L, player->move_resistance);
        return 1;
 }
 
@@ -223,16 +223,20 @@ int LuaLocalPlayer::l_get_control(lua_State *L)
        };
 
        lua_createtable(L, 0, 12);
-       set("up", c.up);
-       set("down", c.down);
-       set("left", c.left);
-       set("right", c.right);
-       set("jump", c.jump);
-       set("aux1", c.aux1);
+       set("jump",  c.jump);
+       set("aux1",  c.aux1);
        set("sneak", c.sneak);
-       set("zoom", c.zoom);
-       set("LMB", c.LMB);
-       set("RMB", c.RMB);
+       set("zoom",  c.zoom);
+       set("dig",   c.dig);
+       set("place", c.place);
+       // Player movement in polar coordinates and non-binary speed
+       set("movement_speed",     c.movement_speed);
+       set("movement_direction", c.movement_direction);
+       // Provide direction keys to ensure compatibility
+       set("up",    player->keyPressed & (1 << 0)); // Up, down, left, and right were removed in favor of
+       set("down",  player->keyPressed & (1 << 1)); // analog  direction indicators and are therefore not
+       set("left",  player->keyPressed & (1 << 2)); // available as booleans anymore. The corresponding values
+       set("right", player->keyPressed & (1 << 3)); // can still be read from the keyPressed bits though.
 
        return 1;
 }
@@ -369,10 +373,11 @@ int LuaLocalPlayer::l_hud_change(lua_State *L)
        if (!element)
                return 0;
 
+       HudElementStat stat;
        void *unused;
-       read_hud_change(L, element, &unused);
+       bool ok = read_hud_change(L, stat, element, &unused);
 
-       lua_pushboolean(L, true);
+       lua_pushboolean(L, ok);
        return 1;
 }
 
@@ -446,7 +451,7 @@ void LuaLocalPlayer::Register(lua_State *L)
 
        lua_pop(L, 1); // Drop metatable
 
-       luaL_openlib(L, 0, methods, 0); // fill methodtable
+       luaL_register(L, nullptr, methods); // fill methodtable
        lua_pop(L, 1);                  // Drop methodtable
 }
 
@@ -461,7 +466,6 @@ const luaL_Reg LuaLocalPlayer::methods[] = {
                luamethod(LuaLocalPlayer, is_touching_ground),
                luamethod(LuaLocalPlayer, is_in_liquid),
                luamethod(LuaLocalPlayer, is_in_liquid_stable),
-               luamethod(LuaLocalPlayer, get_liquid_viscosity),
                luamethod(LuaLocalPlayer, is_climbing),
                luamethod(LuaLocalPlayer, swimming_vertical),
                luamethod(LuaLocalPlayer, get_physics_override),
@@ -483,5 +487,7 @@ const luaL_Reg LuaLocalPlayer::methods[] = {
                luamethod(LuaLocalPlayer, hud_change),
                luamethod(LuaLocalPlayer, hud_get),
 
+               luamethod(LuaLocalPlayer, get_move_resistance),
+
                {0, 0}
 };