The Battle for Wesnoth  1.17.0+dev
Macros | Typedefs | Functions | Variables
ltablib.cpp File Reference
#include "lprefix.h"
#include <limits.h>
#include <stddef.h>
#include <string.h>
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
#include <time.h>
Include dependency graph for ltablib.cpp:

Go to the source code of this file.


#define ltablib_c
#define LUA_LIB
#define TAB_R   1 /* read */
#define TAB_W   2 /* write */
#define TAB_L   4 /* length */
#define TAB_RW   (TAB_R | TAB_W) /* read/write */
#define aux_getn(L, n, w)   (checktab(L, n, (w) | TAB_L), luaL_len(L, n))
#define sof(e)   (sizeof(e) / sizeof(unsigned int))
#define RANLIMIT   100u


typedef unsigned int IdxT


static int checkfield (lua_State *L, const char *key, int n)
static void checktab (lua_State *L, int arg, int what)
static int tinsert (lua_State *L)
static int tremove (lua_State *L)
static int tmove (lua_State *L)
static void addfield (lua_State *L, luaL_Buffer *b, lua_Integer i)
static int tconcat (lua_State *L)
static int tpack (lua_State *L)
static int tunpack (lua_State *L)
static unsigned int l_randomizePivot (void)
static void set2 (lua_State *L, IdxT i, IdxT j)
static int sort_comp (lua_State *L, int a, int b)
static IdxT partition (lua_State *L, IdxT lo, IdxT up)
static IdxT choosePivot (IdxT lo, IdxT up, unsigned int rnd)
static void auxsort (lua_State *L, IdxT lo, IdxT up, unsigned int rnd)
static int sort (lua_State *L)
LUAMOD_API int luaopen_table (lua_State *L)


static const luaL_Reg tab_funcs []

Macro Definition Documentation

◆ aux_getn

#define aux_getn (   L,
)    (checktab(L, n, (w) | TAB_L), luaL_len(L, n))

Definition at line 33 of file ltablib.cpp.

Referenced by sort(), tconcat(), tinsert(), and tremove().

◆ ltablib_c

#define ltablib_c

Definition at line 7 of file ltablib.cpp.


#define LUA_LIB

Definition at line 8 of file ltablib.cpp.


#define RANLIMIT   100u

Definition at line 260 of file ltablib.cpp.

Referenced by auxsort().

◆ sof

#define sof (   e)    (sizeof(e) / sizeof(unsigned int))

Definition at line 236 of file ltablib.cpp.

Referenced by l_randomizePivot().


#define TAB_L   4 /* length */

Definition at line 29 of file ltablib.cpp.

Referenced by checktab().


#define TAB_R   1 /* read */

Definition at line 27 of file ltablib.cpp.

Referenced by checktab(), tconcat(), and tmove().


#define TAB_RW   (TAB_R | TAB_W) /* read/write */

Definition at line 30 of file ltablib.cpp.

Referenced by sort(), tinsert(), and tremove().


#define TAB_W   2 /* write */

Definition at line 28 of file ltablib.cpp.

Referenced by checktab(), and tmove().

Typedef Documentation

◆ IdxT

typedef unsigned int IdxT

Definition at line 222 of file ltablib.cpp.

Function Documentation

◆ addfield()

static void addfield ( lua_State L,
luaL_Buffer b,
lua_Integer  i 

Definition at line 146 of file ltablib.cpp.

References lua_geti(), lua_isstring(), luaL_addvalue(), luaL_error(), and luaL_typename.

Referenced by tconcat().

◆ auxsort()

static void auxsort ( lua_State L,
IdxT  lo,
IdxT  up,
unsigned int  rnd 

Definition at line 343 of file ltablib.cpp.

References choosePivot(), l_randomizePivot(), lua_geti(), lua_pop, lua_pushvalue(), n, p, partition(), RANLIMIT, set2(), and sort_comp().

Referenced by sort().

◆ checkfield()

static int checkfield ( lua_State L,
const char *  key,
int  n 

Definition at line 36 of file ltablib.cpp.

References lua_pushstring(), lua_rawget(), and LUA_TNIL.

Referenced by checktab().

◆ checktab()

static void checktab ( lua_State L,
int  arg,
int  what 

Definition at line 46 of file ltablib.cpp.

References checkfield(), lua_getmetatable(), lua_pop, LUA_TTABLE, lua_type(), luaL_checktype(), n, TAB_L, TAB_R, and TAB_W.

Referenced by tmove().

◆ choosePivot()

static IdxT choosePivot ( IdxT  lo,
IdxT  up,
unsigned int  rnd 

Definition at line 332 of file ltablib.cpp.

References lua_assert, and p.

Referenced by auxsort().

◆ l_randomizePivot()

static unsigned int l_randomizePivot ( void  )

Definition at line 244 of file ltablib.cpp.

References c, i, sof, and t.

Referenced by auxsort().

◆ luaopen_table()

LUAMOD_API int luaopen_table ( lua_State L)

Definition at line 424 of file ltablib.cpp.

References luaL_newlib.

Referenced by lua_kernel_base::lua_kernel_base().

◆ partition()

static IdxT partition ( lua_State L,
IdxT  lo,
IdxT  up 

Definition at line 296 of file ltablib.cpp.

References i, lua_geti(), lua_pop, luaL_error(), set2(), and sort_comp().

Referenced by auxsort(), and pathfind::find_routes().

◆ set2()

static void set2 ( lua_State L,
IdxT  i,
IdxT  j 

Definition at line 263 of file ltablib.cpp.

References lua_seti().

Referenced by auxsort(), and partition().

◆ sort()

static int sort ( lua_State L)

Definition at line 397 of file ltablib.cpp.

References aux_getn, auxsort(), lua_isnoneornil, lua_settop(), LUA_TFUNCTION, luaL_argcheck, luaL_checktype(), n, and TAB_RW.

Referenced by preferences::advanced_manager::advanced_manager(), ng::connect_engine::connect_engine(), about::credits_group::credits_group(), wfl::builtins::DEFINE_WFL_FUNCTION(), events::console_handler::do_choose_level(), ai::ai_default_rca::candidate_action_evaluation_loop::do_play_stage(), unit_filter_impl::unit_filter_compound::fill(), mp::game_info::game_info(), help::generate_ability_topics(), help::generate_contents_links(), help::generate_era_topics(), help::generate_faction_topics(), help::generate_trait_topics(), help::generate_unit_topics(), help::generate_weapon_special_topics(), CVideo::get_available_resolutions(), wfl::function_symbol_table::get_builtins(), filesystem::get_files_in_dir(), gui2::dialogs::attack_predictions::get_hitpoint_probabilities(), get_languages(), filesystem::get_logs_dir(), unit::get_modification_advances(), savegame::save_index_class::get_saves_list(), gui2::dialogs::title_screen::hotkey_callback_select_tests(), help::make_unit_links_list(), gui::menu::max_items_onscreen(), gui2::dialogs::faction_select::on_faction_select(), help::parse_config_internal(), metrics::requests(), gui2::dialogs::campaign_selection::sort_campaigns(), terrain_type::terrain_type(), gui2::dialogs::unit_recruit::unit_recruit(), unit_weapons(), ng::flg_manager::update_choosable_leaders(), and schema_validation::schema_self_validator::validate().

◆ sort_comp()

static int sort_comp ( lua_State L,
int  a,
int  b 

Definition at line 273 of file ltablib.cpp.

References lua_call, lua_compare(), lua_isnil, LUA_OPLT, lua_pop, lua_pushvalue(), and lua_toboolean().

Referenced by auxsort(), and partition().

◆ tconcat()

static int tconcat ( lua_State L)

◆ tinsert()

static int tinsert ( lua_State L)

◆ tmove()

static int tmove ( lua_State L)

◆ tpack()

static int tpack ( lua_State L)

◆ tremove()

static int tremove ( lua_State L)

◆ tunpack()

static int tunpack ( lua_State L)

Variable Documentation

◆ tab_funcs

const luaL_Reg tab_funcs[]
Initial value:
= {
{"concat", tconcat},
{"insert", tinsert},
{"pack", tpack},
{"unpack", tunpack},
{"remove", tremove},
{"move", tmove},
{"sort", sort},
static int tunpack(lua_State *L)
Definition: ltablib.cpp:193
static int tmove(lua_State *L)
Definition: ltablib.cpp:114
static int tinsert(lua_State *L)
Definition: ltablib.cpp:61
static int tconcat(lua_State *L)
Definition: ltablib.cpp:155
static int tremove(lua_State *L)
Definition: ltablib.cpp:90
static int sort(lua_State *L)
Definition: ltablib.cpp:397
static int tpack(lua_State *L)
Definition: ltablib.cpp:180

Definition at line 412 of file ltablib.cpp.