diff --git a/doc/lua_api.md b/doc/lua_api.md index 30b7e46bc..329f17b01 100644 --- a/doc/lua_api.md +++ b/doc/lua_api.md @@ -9095,20 +9095,20 @@ Used by `minetest.register_node`, `minetest.register_craftitem`, and -- Otherwise should be name of node which the client immediately places -- upon digging. Server will always update with actual result shortly. - touch_interaction = { - -- Only affects touchscreen clients. - -- Defines the meaning of short and long taps with the item in hand. - -- The fields in this table can be set to the following values: - -- * "user" (meaning depends on client-side settings) - -- * "long_dig_short_place" (long tap = dig, short tap = place) - -- * "short_dig_long_place" (short tap = dig, long tap = place) - -- The field to be used is selected according to the current - -- `pointed_thing`. - - pointed_nothing = "user", - pointed_node = "user", - pointed_object = "user", + touch_interaction = OR { + pointed_nothing = , + pointed_node = , + pointed_object = , }, + -- Only affects touchscreen clients. + -- Defines the meaning of short and long taps with the item in hand. + -- If specified as a table, the field to be used is selected according to + -- the current `pointed_thing`. + -- There are three possible TouchInteractionMode values: + -- * "user" (meaning depends on client-side settings) + -- * "long_dig_short_place" (long tap = dig, short tap = place) + -- * "short_dig_long_place" (short tap = dig, long tap = place) + -- The default value is "user". sound = { -- Definition of item sounds to be played at various events. diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp index 02f69b3e1..de4f2fe02 100644 --- a/src/script/common/c_content.cpp +++ b/src/script/common/c_content.cpp @@ -156,17 +156,24 @@ void read_item_definition(lua_State* L, int index, getboolfield(L, index, "wallmounted_rotate_vertical", def.wallmounted_rotate_vertical); + TouchInteraction &inter = def.touch_interaction; lua_getfield(L, index, "touch_interaction"); - if (!lua_isnil(L, -1)) { - luaL_checktype(L, -1, LUA_TTABLE); - - TouchInteraction &inter = def.touch_interaction; + if (lua_istable(L, -1)) { inter.pointed_nothing = (TouchInteractionMode)getenumfield(L, -1, "pointed_nothing", es_TouchInteractionMode, inter.pointed_nothing); inter.pointed_node = (TouchInteractionMode)getenumfield(L, -1, "pointed_node", es_TouchInteractionMode, inter.pointed_node); inter.pointed_object = (TouchInteractionMode)getenumfield(L, -1, "pointed_object", es_TouchInteractionMode, inter.pointed_object); + } else if (lua_isstring(L, -1)) { + int value; + if (string_to_enum(es_TouchInteractionMode, value, lua_tostring(L, -1))) { + inter.pointed_nothing = (TouchInteractionMode)value; + inter.pointed_node = (TouchInteractionMode)value; + inter.pointed_object = (TouchInteractionMode)value; + } + } else if (!lua_isnil(L, -1)) { + throw LuaError("invalid type for 'touch_interaction'"); } lua_pop(L, 1); }