Minetest  5.4.0
c_converter.cpp File Reference
#include "lua.h"
#include "lauxlib.h"
#include "util/numeric.h"
#include "util/serialize.h"
#include "util/string.h"
#include "common/c_converter.h"
#include "common/c_internal.h"
#include "constants.h"
#include <set>
+ Include dependency graph for c_converter.cpp:

Macros

#define CHECK_TYPE(index, name, type)
 
#define CHECK_POS_COORD(name)   CHECK_TYPE(-1, "position coordinate '" name "'", LUA_TNUMBER)
 
#define CHECK_FLOAT_RANGE(value, name)
 
#define CHECK_POS_TAB(index)   CHECK_TYPE(index, "position", LUA_TTABLE)
 

Functions

void push_float_string (lua_State *L, float value)
 
void push_v3f (lua_State *L, v3f p)
 
void push_v2f (lua_State *L, v2f p)
 
void push_v3_float_string (lua_State *L, v3f p)
 
void push_v2_float_string (lua_State *L, v2f p)
 
v2s16 read_v2s16 (lua_State *L, int index)
 
void push_v2s16 (lua_State *L, v2s16 p)
 
void push_v2s32 (lua_State *L, v2s32 p)
 
v2s32 read_v2s32 (lua_State *L, int index)
 
v2f read_v2f (lua_State *L, int index)
 
v2f check_v2f (lua_State *L, int index)
 
v3f read_v3f (lua_State *L, int index)
 
v3f check_v3f (lua_State *L, int index)
 
v3d read_v3d (lua_State *L, int index)
 
v3d check_v3d (lua_State *L, int index)
 
void push_ARGB8 (lua_State *L, video::SColor color)
 
void pushFloatPos (lua_State *L, v3f p)
 
v3f checkFloatPos (lua_State *L, int index)
 
void push_v3s16 (lua_State *L, v3s16 p)
 
v3s16 read_v3s16 (lua_State *L, int index)
 
v3s16 check_v3s16 (lua_State *L, int index)
 
bool read_color (lua_State *L, int index, video::SColor *color)
 
video::SColor read_ARGB8 (lua_State *L, int index)
 
bool is_color_table (lua_State *L, int index)
 
aabb3f read_aabb3f (lua_State *L, int index, f32 scale)
 
void push_aabb3f (lua_State *L, aabb3f box)
 
std::vector< aabb3fread_aabb3f_vector (lua_State *L, int index, f32 scale)
 
size_t read_stringlist (lua_State *L, int index, std::vector< std::string > *result)
 
bool check_field_or_nil (lua_State *L, int index, int type, const char *fieldname)
 
bool getstringfield (lua_State *L, int table, const char *fieldname, std::string &result)
 
bool getfloatfield (lua_State *L, int table, const char *fieldname, float &result)
 
bool getboolfield (lua_State *L, int table, const char *fieldname, bool &result)
 
size_t getstringlistfield (lua_State *L, int table, const char *fieldname, std::vector< std::string > *result)
 
std::string getstringfield_default (lua_State *L, int table, const char *fieldname, const std::string &default_)
 
int getintfield_default (lua_State *L, int table, const char *fieldname, int default_)
 
float getfloatfield_default (lua_State *L, int table, const char *fieldname, float default_)
 
bool getboolfield_default (lua_State *L, int table, const char *fieldname, bool default_)
 
v3s16 getv3s16field_default (lua_State *L, int table, const char *fieldname, v3s16 default_)
 
void setstringfield (lua_State *L, int table, const char *fieldname, const std::string &value)
 
void setintfield (lua_State *L, int table, const char *fieldname, int value)
 
void setfloatfield (lua_State *L, int table, const char *fieldname, float value)
 
void setboolfield (lua_State *L, int table, const char *fieldname, bool value)
 
size_t write_array_slice_float (lua_State *L, int table_index, float *data, v3u16 data_size, v3u16 slice_offset, v3u16 slice_size)
 

Macro Definition Documentation

◆ CHECK_FLOAT_RANGE

#define CHECK_FLOAT_RANGE (   value,
  name 
)
Value:
if (value < F1000_MIN || value > F1000_MAX) { \
std::ostringstream error_text; \
error_text << "Invalid float vector dimension range '" name "' " << \
"(expected " << F1000_MIN << " < " name " < " << F1000_MAX << \
" got " << value << ")." << std::endl; \
throw LuaError(error_text.str()); \
}
Definition: c_types.h:55
#define F1000_MIN
Definition: serialize.h:55
#define F1000_MAX
Definition: serialize.h:56

◆ CHECK_POS_COORD

#define CHECK_POS_COORD (   name)    CHECK_TYPE(-1, "position coordinate '" name "'", LUA_TNUMBER)

◆ CHECK_POS_TAB

#define CHECK_POS_TAB (   index)    CHECK_TYPE(index, "position", LUA_TTABLE)

◆ CHECK_TYPE

#define CHECK_TYPE (   index,
  name,
  type 
)
Value:
{ \
int t = lua_type(L, (index)); \
if (t != (type)) { \
throw LuaError(std::string("Invalid ") + (name) + \
" (expected " + lua_typename(L, (type)) + \
" got " + lua_typename(L, t) + ")."); \
} \
}

Function Documentation

◆ check_field_or_nil()

bool check_field_or_nil ( lua_State *  L,
int  index,
int  type,
const char *  fieldname 
)

References errorstream, hash(), murmur_hash_64_ua(), and script_get_backtrace().

Referenced by getboolfield(), getfloatfield(), getintfield(), getstringfield(), and read_content_features().

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

◆ check_v2f()

v2f check_v2f ( lua_State *  L,
int  index 
)

References CHECK_POS_COORD, CHECK_POS_TAB, and p().

+ Here is the call graph for this function:

◆ check_v3d()

v3d check_v3d ( lua_State *  L,
int  index 
)

References CHECK_FLOAT_RANGE, CHECK_POS_COORD, and CHECK_POS_TAB.

Referenced by check_v3s16().

+ Here is the caller graph for this function:

◆ check_v3f()

◆ check_v3s16()

◆ checkFloatPos()

v3f checkFloatPos ( lua_State *  L,
int  index 
)

References BS, and check_v3f().

Referenced by LuaRaycast::create_object(), ModApiEnvMod::l_add_entity(), ObjectRef::l_add_velocity(), ModApiEnvMod::l_get_objects_inside_radius(), ModApiEnvMod::l_line_of_sight(), ObjectRef::l_move_to(), ObjectRef::l_set_acceleration(), ObjectRef::l_set_pos(), and ObjectRef::l_set_velocity().

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

◆ getboolfield()

bool getboolfield ( lua_State *  L,
int  table,
const char *  fieldname,
bool &  result 
)

References check_field_or_nil(), and table.

Referenced by getboolfield_default(), ScriptApiEnv::initializeEnvironment(), ObjectRef::l_hud_set_flags(), ObjectRef::l_set_physics_override(), ModApiClient::l_sound_play(), ModApiEnvMod::l_spawn_tree(), read_content_features(), read_flags_table(), read_item_definition(), read_object_properties(), and read_server_sound_params().

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

◆ getboolfield_default()

bool getboolfield_default ( lua_State *  L,
int  table,
const char *  fieldname,
bool  default_ 
)

References getboolfield(), and table.

Referenced by ScriptApiEnv::initializeEnvironment(), ModApiParticles::l_add_particle(), ModApiParticlesLocal::l_add_particle(), ModApiParticles::l_add_particlespawner(), ModApiParticlesLocal::l_add_particlespawner(), ModApiMapgen::l_serialize_schematic(), LuaAreaStore::l_set_cache_params(), ObjectRef::l_set_moon(), ObjectRef::l_set_sky(), ObjectRef::l_set_stars(), ObjectRef::l_set_sun(), ModApiHttp::read_http_fetch_request(), read_schematic_def(), and read_tiledef().

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

◆ getfloatfield()

bool getfloatfield ( lua_State *  L,
int  table,
const char *  fieldname,
float &  result 
)

References check_field_or_nil(), and table.

Referenced by getfloatfield_default(), ScriptApiEnv::initializeEnvironment(), ModApiMapgen::l_register_ore(), ObjectRef::l_set_physics_override(), ModApiClient::l_sound_play(), read_content_features(), read_noiseparams(), read_object_properties(), read_server_sound_params(), read_soundspec(), and read_tool_capabilities().

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

◆ getfloatfield_default()

float getfloatfield_default ( lua_State *  L,
int  table,
const char *  fieldname,
float  default_ 
)

References getfloatfield(), and table.

Referenced by ModApiParticles::l_add_particle(), ModApiParticlesLocal::l_add_particle(), ModApiParticles::l_add_particlespawner(), ModApiParticlesLocal::l_add_particlespawner(), ModApiCraft::l_register_craft(), ModApiMapgen::l_register_decoration(), ModApiMapgen::l_register_ore(), ObjectRef::l_set_clouds(), ObjectRef::l_set_moon(), ObjectRef::l_set_stars(), ObjectRef::l_set_sun(), read_biome_def(), read_item_definition(), and read_server_sound_params().

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

◆ getintfield_default()

int getintfield_default ( lua_State *  L,
int  table,
const char *  fieldname,
int  default_ 
)

◆ getstringfield()

bool getstringfield ( lua_State *  L,
int  table,
const char *  fieldname,
std::string &  result 
)

References check_field_or_nil(), and table.

Referenced by ScriptApiServer::getAuth(), getstringfield_default(), ScriptApiEnv::initializeEnvironment(), ModApiAuth::l_auth_create(), ModApiAuth::l_auth_save(), ModApiEnvMod::l_spawn_tree(), read_content_features(), ModApiHttp::read_http_fetch_request(), read_item_definition(), read_object_properties(), read_schematic_def(), read_server_sound_params(), read_soundspec(), and read_tiledef().

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

◆ getstringfield_default()

std::string getstringfield_default ( lua_State *  L,
int  table,
const char *  fieldname,
const std::string &  default_ 
)

◆ getstringlistfield()

size_t getstringlistfield ( lua_State *  L,
int  table,
const char *  fieldname,
std::vector< std::string > *  result 
)

References read_stringlist(), and table.

Referenced by ModApiMapgen::l_register_decoration(), ModApiMapgen::l_register_ore(), read_biome_def(), and read_deco_simple().

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

◆ getv3s16field_default()

v3s16 getv3s16field_default ( lua_State *  L,
int  table,
const char *  fieldname,
v3s16  default_ 
)

References getv3intfield(), and table.

Referenced by read_biome_def().

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

◆ is_color_table()

bool is_color_table ( lua_State *  L,
int  index 
)

Referenced by ObjectRef::l_set_sky().

+ Here is the caller graph for this function:

◆ push_aabb3f()

void push_aabb3f ( lua_State *  L,
aabb3f  box 
)

Referenced by push_box(), push_nodebox(), and push_object_properties().

+ Here is the caller graph for this function:

◆ push_ARGB8()

void push_ARGB8 ( lua_State *  L,
video::SColor  color 
)

Referenced by ObjectRef::l_get_clouds(), ObjectRef::l_get_nametag_attributes(), ObjectRef::l_get_sky(), ObjectRef::l_get_sky_color(), ObjectRef::l_get_stars(), push_content_features(), push_item_definition_full(), push_object_properties(), and push_palette().

+ Here is the caller graph for this function:

◆ push_float_string()

void push_float_string ( lua_State *  L,
float  value 
)

Referenced by push_noiseparams(), push_v2_float_string(), and push_v3_float_string().

+ Here is the caller graph for this function:

◆ push_v2_float_string()

void push_v2_float_string ( lua_State *  L,
v2f  p 
)

References p(), and push_float_string().

+ Here is the call graph for this function:

◆ push_v2f()

void push_v2f ( lua_State *  L,
v2f  p 
)

References p().

Referenced by ObjectRef::l_get_animation(), and push_hud_element().

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

◆ push_v2s16()

void push_v2s16 ( lua_State *  L,
v2s16  p 
)

References p().

Referenced by push_object_properties().

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

◆ push_v2s32()

void push_v2s32 ( lua_State *  L,
v2s32  p 
)

References p().

Referenced by ObjectRef::l_get_local_animation(), and push_hud_element().

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

◆ push_v3_float_string()

void push_v3_float_string ( lua_State *  L,
v3f  p 
)

References p(), and push_float_string().

Referenced by push_noiseparams().

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

◆ push_v3f()

void push_v3f ( lua_State *  L,
v3f  p 
)

◆ push_v3s16()

void push_v3s16 ( lua_State *  L,
v3s16  p 
)

References p().

Referenced by ScriptApiEnv::environment_OnGenerated(), ModApiEnvMod::l_find_node_near(), ModApiEnvMod::l_find_nodes_in_area(), ModApiEnvMod::l_find_nodes_in_area_under_air(), ModApiEnvMod::l_find_nodes_with_meta(), ModApiEnvMod::l_find_path(), LuaVoxelManip::l_get_emerged_area(), InvRef::l_get_location(), ModApiMapgen::l_get_mapgen_object(), LuaMinimap::l_get_pos(), ModApiEnvMod::l_line_of_sight(), LuaVoxelManip::l_read_from_map(), ModApiMapgen::l_read_schematic(), ModApiRollback::l_rollback_get_node_actions(), ScriptApiNode::node_after_destruct(), ScriptApiNode::node_on_construct(), ScriptApiNode::node_on_destruct(), ScriptApiNode::node_on_dig(), ScriptApiNode::node_on_flood(), ScriptApiNode::node_on_punch(), ScriptApiNode::node_on_receive_fields(), ScriptApiNode::node_on_timer(), ScriptApiNodemeta::nodemeta_inventory_AllowMove(), ScriptApiNodemeta::nodemeta_inventory_AllowPut(), ScriptApiNodemeta::nodemeta_inventory_AllowTake(), ScriptApiNodemeta::nodemeta_inventory_OnMove(), ScriptApiNodemeta::nodemeta_inventory_OnPut(), ScriptApiNodemeta::nodemeta_inventory_OnTake(), ScriptApiClient::on_dignode(), ScriptApiEnv::on_emerge_area_completion(), ScriptApiClient::on_punchnode(), push_area(), push_collision_move_result(), push_pointed_thing(), LuaLBM::trigger(), and LuaABM::trigger().

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

◆ pushFloatPos()

void pushFloatPos ( lua_State *  L,
v3f  p 
)

References BS, p(), and push_v3f().

Referenced by ScriptApiItem::item_OnDrop(), ObjectRef::l_get_acceleration(), and ObjectRef::l_get_velocity().

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

◆ read_aabb3f()

aabb3f read_aabb3f ( lua_State *  L,
int  index,
f32  scale 
)

Referenced by read_aabb3f_vector(), and read_object_properties().

+ Here is the caller graph for this function:

◆ read_aabb3f_vector()

std::vector<aabb3f> read_aabb3f_vector ( lua_State *  L,
int  index,
f32  scale 
)

References read_aabb3f().

+ Here is the call graph for this function:

◆ read_ARGB8()

video::SColor read_ARGB8 ( lua_State *  L,
int  index 
)

References CHECK_TYPE.

Referenced by read_color().

+ Here is the caller graph for this function:

◆ read_color()

bool read_color ( lua_State *  L,
int  index,
video::SColor *  color 
)

References parseColorString(), and read_ARGB8().

Referenced by ObjectRef::l_set_clouds(), ObjectRef::l_set_nametag_attributes(), ObjectRef::l_set_sky(), ObjectRef::l_set_stars(), read_content_features(), read_item_definition(), read_object_properties(), and read_tiledef().

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

◆ read_stringlist()

size_t read_stringlist ( lua_State *  L,
int  index,
std::vector< std::string > *  result 
)

Referenced by getstringlistfield().

+ Here is the caller graph for this function:

◆ read_v2f()

v2f read_v2f ( lua_State *  L,
int  index 
)

References CHECK_POS_TAB, and p().

Referenced by read_hud_change(), read_hud_element(), and read_object_properties().

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

◆ read_v2s16()

v2s16 read_v2s16 ( lua_State *  L,
int  index 
)

References CHECK_POS_TAB, and p().

Referenced by read_object_properties().

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

◆ read_v2s32()

v2s32 read_v2s32 ( lua_State *  L,
int  index 
)

References CHECK_POS_TAB, and p().

Referenced by ObjectRef::l_set_local_animation(), read_hud_change(), and read_hud_element().

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

◆ read_v3d()

v3d read_v3d ( lua_State *  L,
int  index 
)

References CHECK_POS_TAB.

Referenced by read_v3s16().

+ Here is the caller graph for this function:

◆ read_v3f()

v3f read_v3f ( lua_State *  L,
int  index 
)

References CHECK_POS_TAB.

Referenced by ModApiEnvMod::l_get_objects_in_area(), ModApiClient::l_sound_play(), read_hud_change(), read_hud_element(), read_noiseparams(), and read_server_sound_params().

+ Here is the caller graph for this function:

◆ read_v3s16()

v3s16 read_v3s16 ( lua_State *  L,
int  index 
)

References doubleToInt(), and read_v3d().

Referenced by LuaPerlinNoiseMap::create_object(), ModApiEnvMod::l_add_node_level(), ModApiEnvMod::l_bulk_set_node(), ModApiEnvMod::l_delete_area(), ModApiEnvMod::l_dig_node(), ModApiEnvMod::l_emerge_area(), ModApiEnvMod::l_find_node_near(), ModApiEnvMod::l_find_nodes_in_area(), ModApiEnvMod::l_find_nodes_in_area_under_air(), ModApiEnvMod::l_find_path(), ModApiEnvMod::l_fix_light(), ModApiEnvMod::l_forceload_block(), ModApiEnvMod::l_forceload_free_block(), ModApiMapgen::l_get_biome_data(), ModApiMapgen::l_get_heat(), ModApiMapgen::l_get_humidity(), LuaPerlinNoiseMap::l_get_map_slice(), ModApiClient::l_get_meta(), ModApiEnvMod::l_get_meta(), ModApiEnvMod::l_get_natural_light(), ModApiEnvMod::l_get_node(), ModApiEnvMod::l_get_node_level(), ModApiEnvMod::l_get_node_light(), ModApiEnvMod::l_get_node_max_level(), ModApiClient::l_get_node_or_nil(), ModApiEnvMod::l_get_node_or_nil(), ModApiEnvMod::l_get_node_timer(), ModApiEnvMod::l_get_perlin_map(), ModApiEnvMod::l_get_voxel_manip(), ModApiEnvMod::l_place_node(), ModApiEnvMod::l_punch_node(), ModApiEnvMod::l_remove_node(), ModApiRollback::l_rollback_get_node_actions(), ObjectRef::l_send_mapblock(), ModApiEnvMod::l_set_node(), ModApiEnvMod::l_set_node_level(), LuaMinimap::l_set_pos(), ModApiEnvMod::l_spawn_tree(), ModApiEnvMod::l_swap_node(), and ModApiEnvMod::l_transforming_liquid_add().

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

◆ setboolfield()

void setboolfield ( lua_State *  L,
int  table,
const char *  fieldname,
bool  value 
)

References table.

Referenced by ModApiClient::l_get_csm_restrictions(), push_collision_move_result(), push_dig_params(), ModApiHttp::push_http_fetch_result(), and ScriptApiMainMenu::setMainMenuData().

+ Here is the caller graph for this function:

◆ setfloatfield()

void setfloatfield ( lua_State *  L,
int  table,
const char *  fieldname,
float  value 
)

References table.

Referenced by push_dig_params(), and push_tool_capabilities().

+ Here is the caller graph for this function:

◆ setintfield()

void setintfield ( lua_State *  L,
int  table,
const char *  fieldname,
int  value 
)

References table.

Referenced by ModApiCraft::l_get_craft_recipe(), ModApiCraft::l_get_craft_result(), push_craft_recipe(), push_dig_params(), push_hit_params(), ModApiHttp::push_http_fetch_result(), and push_tool_capabilities().

+ Here is the caller graph for this function:

◆ setstringfield()

void setstringfield ( lua_State *  L,
int  table,
const char *  fieldname,
const std::string &  value 
)

References table.

Referenced by ModApiHttp::push_http_fetch_result().

+ Here is the caller graph for this function:

◆ write_array_slice_float()

size_t write_array_slice_float ( lua_State *  L,
int  table_index,
float *  data,
v3u16  data_size,
v3u16  slice_offset,
v3u16  slice_size 
)

References MYMIN.

Referenced by LuaPerlinNoiseMap::l_get_map_slice().

+ Here is the caller graph for this function: