Luanti 5.17.0-dev
Loading...
Searching...
No Matches
LuaHelper Class Reference

#include <helper.h>

Inheritance diagram for LuaHelper:

Public Member Functions

template<>
bool readParam (lua_State *L, int index)
template<>
s16 readParam (lua_State *L, int index)
template<>
int readParam (lua_State *L, int index)
template<>
float readParam (lua_State *L, int index)
template<>
v2s16 readParam (lua_State *L, int index)
template<>
v2f readParam (lua_State *L, int index)
template<>
v3f readParam (lua_State *L, int index)
template<>
std::string_view readParam (lua_State *L, int index)
template<>
std::string readParam (lua_State *L, int index)
template<>
std::string_view readParam (lua_State *L, int index)
 Read a string from Lua state L at index without copying it.

Static Public Member Functions

static bool geti (lua_State *L, int table, int i)
 Utility for list iteration.
template<typename F>
static void for_ipairs (lua_State *L, int table, const F &f)
 Iterate values t[1], t[2], ... of the given table in order.

Static Protected Member Functions

template<typename T>
static T readParam (lua_State *L, int index)
 Read a value using a template type T from Lua state L at index.
template<typename T>
static T readParam (lua_State *L, int index, const T &default_value)
 Read a value using a template type T from Lua state L at index.

Member Function Documentation

◆ for_ipairs()

template<typename F>
void LuaHelper::for_ipairs ( lua_State * L,
int table,
const F & f )
inlinestatic

Iterate values t[1], t[2], ... of the given table in order.

Iterates up to the first nil value, similar to ipairs in Lua. Values will be left on the stack for f(). f() must leave the stack level unchanged.

Parameters
tableLua stack (pseudo-)index of table
fFunction (typically lambda) to be called for each value.

References geti(), and table.

Referenced by ModApiEnvBase::collectNodeIds(), get_biome_list(), ModApiMapgen::l_create_schematic(), NodeMetaRef::l_mark_as_private(), ModApiMapgen::l_set_gen_notify(), ObjectRef::l_set_minimap_modes(), ObjectRef::l_set_sky(), read_content_features(), ModApiHttp::read_http_fetch_request(), ScriptApiEnv::read_nodenames(), read_object_properties(), read_schematic_def(), and read_stringlist().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ geti()

bool LuaHelper::geti ( lua_State * L,
int table,
int i )
inlinestatic

Utility for list iteration.

Usage:

for (int i = 0; LuaHelper::geti(L, -1, i); ++i, lua_pop(L, 1)) ...
static bool geti(lua_State *L, int table, int i)
Utility for list iteration.
Definition helper.h:29
Parameters
tableindex of the table t on the stack
iinteger to index table with
Returns
false if t[i + 1] is nil, true otherwise; t[i + 1] is left on the stack in the latter case.

References table.

Referenced by for_ipairs(), read_content_features(), ModApiCraft::readCraftRecipeShaped(), and ModApiCraft::readCraftRecipeShapeless().

Here is the caller graph for this function:

◆ readParam() [1/12]

template<>
std::string LuaHelper::readParam ( lua_State * L,
int index )

References readParam().

Here is the call graph for this function:

◆ readParam() [2/12]

template<>
std::string_view LuaHelper::readParam ( lua_State * L,
int index )

◆ readParam() [3/12]

template<>
v3f LuaHelper::readParam ( lua_State * L,
int index )

References check_v3f().

Here is the call graph for this function:

◆ readParam() [4/12]

template<>
v2f LuaHelper::readParam ( lua_State * L,
int index )

References check_v2f().

Here is the call graph for this function:

◆ readParam() [5/12]

template<>
v2s16 LuaHelper::readParam ( lua_State * L,
int index )

References read_v2s16().

Here is the call graph for this function:

◆ readParam() [6/12]

template<>
float LuaHelper::readParam ( lua_State * L,
int index )

◆ readParam() [7/12]

template<>
int LuaHelper::readParam ( lua_State * L,
int index )

◆ readParam() [8/12]

template<>
s16 LuaHelper::readParam ( lua_State * L,
int index )

◆ readParam() [9/12]

template<>
bool LuaHelper::readParam ( lua_State * L,
int index )

◆ readParam() [10/12]

template<>
std::string_view LuaHelper::readParam ( lua_State * L,
int index )

Read a string from Lua state L at index without copying it.

Note that the returned string view is only valid as long as the value is on the stack and has not been modified. Be careful.

Parameters
LLua state
indexLua index to read
Returns
string view

◆ readParam() [11/12]

template<typename T>
T LuaHelper::readParam ( lua_State * L,
int index )
staticprotected

Read a value using a template type T from Lua state L at index.

Template Parameters
Ttype to read from Lua
Parameters
LLua state
indexLua index to read
Returns
read value from Lua

Referenced by ModApiEnvBase::collectNodeIds(), LuaAreaStore::create_object(), LuaRaycast::create_object(), LuaValueNoise::create_object(), ModApiMainMenu::getBoolData(), ScriptApiBase::getCurrentModNameInsecure(), MetaDataRef::handleFromTable(), ModApiEnv::l_add_entity(), ModApiParticles::l_add_particle(), ModApiParticles::l_add_particlespawner(), ModApiParticlesLocal::l_add_particlespawner(), LuaItemStack::l_add_wear_by_uses(), LuaValueNoiseMap::l_calc_2d_map(), LuaVoxelManip::l_calc_lighting(), ModApiUtil::l_compress(), InvRef::l_contains_item(), ModApiMainMenu::l_copy_dir(), ModApiInventory::l_create_detached_inventory_raw(), ModApiUtil::l_decode_base64(), ModApiUtil::l_decompress(), ModApiServer::l_disconnect_player(), ModApiAsync::l_do_async_callback(), ModApiServer::l_dynamic_add_media(), ModApiUtil::l_encode_base64(), ModApiUtil::l_encode_png(), ClientSoundHandle::l_fade(), ModApiEnv::l_find_node_near(), ModApiEnvVM::l_find_node_near(), ModApiEnv::l_find_nodes_in_area(), ModApiEnvVM::l_find_nodes_in_area(), ModApiMapgen::l_generate_decorations(), LuaValueNoise::l_get_2d(), LuaValueNoiseMap::l_get_2d_map(), LuaValueNoiseMap::l_get_2d_map_flat(), LuaAreaStore::l_get_areas_in_area(), ObjectRef::l_get_bone_override(), ObjectRef::l_get_bone_position(), LuaSettings::l_get_bool(), ModApiUtil::l_get_dig_params(), ModApiUtil::l_get_dir_list(), ModApiUtil::l_get_hit_params(), ModApiClient::l_get_item_def(), ModApiMainMenu::l_get_mapgen_names(), ModApiStorage::l_get_mod_storage(), ModApiServer::l_get_modnames(), ModApiClient::l_get_modpath(), ModApiClient::l_get_node_def(), ModApiEnv::l_get_objects_inside_radius(), ObjectRef::l_get_sky(), ModApiUtil::l_get_tool_wear_after_use(), ModApiEnv::l_get_value_noise(), ObjectRef::l_hud_set_hotbar_image(), ObjectRef::l_hud_set_hotbar_selected_image(), ModApiIPC::l_ipc_cas(), ModApiIPC::l_ipc_get(), ModApiIPC::l_ipc_poll(), ModApiIPC::l_ipc_set(), ModApiUtil::l_is_valid_player_name(), ModApiUtil::l_is_yes(), ModApiUtil::l_log(), NodeMetaRef::l_mark_as_private(), ObjectRef::l_move_to(), ModApiServer::l_notify_authentication_modified(), ObjectRef::l_override_day_night_ratio(), ModApiUtil::l_parse_json(), ModApiMapgen::l_place_schematic(), ModApiMapgen::l_place_schematic_on_vmanip(), ObjectRef::l_punch(), ModApiServer::l_register_async_dofile(), ModApiServer::l_register_mapgen_script(), InvRef::l_remove_item(), ModApiServer::l_request_shutdown(), ModApiUtil::l_rmdir(), ModApiUtil::l_safe_file_write(), ModApiMapgen::l_save_gen_notify(), ModApiMapgen::l_serialize_schematic(), NodeTimerRef::l_set(), ObjectRef::l_set_animation(), ObjectRef::l_set_animation_frame_speed(), ObjectRef::l_set_attach(), ModApiMainMenu::l_set_background(), ObjectRef::l_set_bone_override(), ObjectRef::l_set_bone_position(), LuaSettings::l_set_bool(), ModApiMainMenu::l_set_clouds(), ModApiMainMenu::l_set_clouds_color(), ObjectRef::l_set_eye_offset(), ObjectRef::l_set_formspec_prepend(), ObjectRef::l_set_fov(), ModApiMapgen::l_set_gen_notify(), ObjectRef::l_set_hp(), ObjectRef::l_set_inventory_formspec(), ObjectRef::l_set_local_animation(), ObjectRef::l_set_look_horizontal(), ObjectRef::l_set_look_pitch(), ObjectRef::l_set_look_vertical(), ObjectRef::l_set_look_yaw(), ModApiMapgen::l_set_mapgen_params(), ModApiMapgen::l_set_mapgen_setting(), ModApiMapgen::l_set_mapgen_setting_noiseparams(), ObjectRef::l_set_minimap_modes(), ModApiMapgen::l_set_noiseparams(), ObjectRef::l_set_observers(), ObjectRef::l_set_sky(), ModApiMainMenu::l_set_sky_color(), ObjectRef::l_set_sprite(), LuaPcgRandom::l_set_state(), MetaDataRef::l_set_string(), ObjectRef::l_set_texture_mod(), ModApiEnv::l_set_timeofday(), ObjectRef::l_set_wielded_item(), ObjectRef::l_set_yaw(), ModApiUtil::l_sha1(), ModApiUtil::l_sha256(), ModApiMainMenu::l_show_path_select_dialog(), ModApiServer::l_sound_fade(), ModApiMainMenuSound::l_sound_play(), ModApiServer::l_sound_play(), NodeTimerRef::l_start(), ModApiUtil::l_strip_escapes(), ModApiUtil::l_urlencode(), ModApiUtil::l_write_json(), LuaVoxelManip::l_write_to_map(), ScriptApiEntity::luaentity_Punch(), ScriptApiEntity::luaentity_run_simple_callback(), ScriptApiBase::luaPanic(), ScriptApiNode::node_on_flood(), ScriptApiNode::node_on_timer(), ScriptApiServer::on_chat_message(), ScriptApiClientCommon::on_formspec_input(), ScriptApiClient::on_inventory_open(), ScriptApiClient::on_item_use(), ScriptApiClient::on_placenode(), ScriptApiPlayer::on_prejoinplayer(), ScriptApiClient::on_punchnode(), ScriptApiPlayer::on_punchplayer(), ScriptApiClient::on_receiving_message(), ScriptApiPlayer::on_respawnplayer(), ScriptApiClient::on_sending_message(), ModApiHttp::read_http_fetch_request(), ScriptApiEnv::read_nodenames(), ModApiCraft::readCraftRecipeShaped(), ModApiCraft::readCraftRecipeShapeless(), ModApiCraft::readCraftReplacements(), readParam(), readParam(), ScriptApiServer::readPrivileges(), ScriptApiSecurity::sl_g_loadfile(), ScriptApiBase::stackDump(), and TestScriptApi::testReadParamFloat().

◆ readParam() [12/12]

template<typename T>
T LuaHelper::readParam ( lua_State * L,
int index,
const T & default_value )
inlinestaticprotected

Read a value using a template type T from Lua state L at index.

Template Parameters
Ttype to read from Lua
Parameters
LLua state
indexLua index to read
default_valuedefault value to apply if nil
Returns
read value from Lua or default value if nil

References readParam().

Here is the call graph for this function:

The documentation for this class was generated from the following files: