The Battle for Wesnoth  1.15.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.

Macros

#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
 

Typedefs

typedef unsigned int IdxT
 

Functions

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 pack (lua_State *L)
 
static int unpack (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)
 

Variables

static const luaL_Reg tab_funcs []
 

Macro Definition Documentation

◆ aux_getn

#define aux_getn (   L,
  n,
  w 
)    (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.

◆ LUA_LIB

#define LUA_LIB

Definition at line 8 of file ltablib.cpp.

◆ RANLIMIT

#define RANLIMIT   100u

Definition at line 274 of file ltablib.cpp.

Referenced by auxsort().

◆ sof

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

Definition at line 250 of file ltablib.cpp.

Referenced by l_randomizePivot().

◆ TAB_L

#define TAB_L   4 /* length */

Definition at line 29 of file ltablib.cpp.

Referenced by checktab().

◆ TAB_R

#define TAB_R   1 /* read */

Definition at line 27 of file ltablib.cpp.

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

◆ TAB_RW

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

Definition at line 30 of file ltablib.cpp.

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

◆ TAB_W

#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 236 of file ltablib.cpp.

Function Documentation

◆ addfield()

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

Definition at line 160 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 
)
static

Definition at line 357 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 
)
static

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 
)
static

◆ choosePivot()

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

Definition at line 346 of file ltablib.cpp.

References lua_assert, and p.

Referenced by auxsort().

◆ l_randomizePivot()

static unsigned int l_randomizePivot ( void  )
static

Definition at line 258 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 441 of file ltablib.cpp.

References lua_getfield(), lua_setglobal(), and luaL_newlib.

Referenced by lua_kernel_base::lua_kernel_base().

◆ pack()

static int pack ( lua_State L)
static

◆ partition()

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

Definition at line 310 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 
)
static

Definition at line 277 of file ltablib.cpp.

References lua_seti().

Referenced by auxsort(), and partition().

◆ sort()

static int sort ( lua_State L)
static

Definition at line 411 of file ltablib.cpp.

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

Referenced by 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(), unit::get_modification_advances(), savegame::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(), gui2::dialogs::preferences_dialog::preferences_dialog(), 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 
)
static

Definition at line 287 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)
static

◆ tinsert()

static int tinsert ( lua_State L)
static

◆ tmove()

static int tmove ( lua_State L)
static

◆ tremove()

static int tremove ( lua_State L)
static

◆ unpack()

static int unpack ( lua_State L)
static

Variable Documentation

◆ tab_funcs

const luaL_Reg tab_funcs[]
static
Initial value:
= {
{"concat", tconcat},
{"insert", tinsert},
{"pack", pack},
{"unpack", unpack},
{"remove", tremove},
{"move", tmove},
{"sort", sort},
{NULL, NULL}
}
static int pack(lua_State *L)
Definition: ltablib.cpp:194
static int unpack(lua_State *L)
Definition: ltablib.cpp:207
static int tmove(lua_State *L)
Definition: ltablib.cpp:128
static int tinsert(lua_State *L)
Definition: ltablib.cpp:79
static int tconcat(lua_State *L)
Definition: ltablib.cpp:169
static int tremove(lua_State *L)
Definition: ltablib.cpp:106
static int sort(lua_State *L)
Definition: ltablib.cpp:411

Definition at line 426 of file ltablib.cpp.