About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

ltablib.c 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.c:

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 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)
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.c.

◆ ltablib_c

#define ltablib_c

Definition at line 7 of file ltablib.c.


#define LUA_LIB

Definition at line 8 of file ltablib.c.


#define RANLIMIT   100u

Definition at line 274 of file ltablib.c.

◆ sof

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

Definition at line 250 of file ltablib.c.


#define TAB_L   4 /* length */

Definition at line 29 of file ltablib.c.


#define TAB_R   1 /* read */

Definition at line 27 of file ltablib.c.


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

Definition at line 30 of file ltablib.c.


#define TAB_W   2 /* write */

Definition at line 28 of file ltablib.c.

Typedef Documentation

◆ IdxT

typedef unsigned int IdxT

Definition at line 236 of file ltablib.c.

Function Documentation

◆ addfield()

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

Definition at line 160 of file ltablib.c.

References b, i, L, 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 357 of file ltablib.c.

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

Referenced by sort().

◆ checkfield()

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

Definition at line 36 of file ltablib.c.

References key, L, lua_pushstring(), lua_rawget(), LUA_TNIL, and n.

Referenced by checktab().

◆ checktab()

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

Definition at line 46 of file ltablib.c.

References checkfield(), L, lua_getmetatable(), lua_pop, LUA_TTABLE, lua_type(), luaL_checktype(), n, TAB_L, TAB_R, TAB_W, and gen-indic-table::what.

Referenced by tmove().

◆ choosePivot()

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

Definition at line 346 of file ltablib.c.

References lua_assert, p, r4, rnd, and up.

Referenced by auxsort().

◆ l_randomizePivot()

static unsigned int l_randomizePivot ( void  )

Definition at line 258 of file ltablib.c.

References buff, c, i, memcpy, NULL, rnd, sof, and time().

Referenced by auxsort().

◆ luaopen_table()

int luaopen_table ( lua_State L)

Definition at line 441 of file ltablib.c.

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

◆ pack()

static int pack ( lua_State L)

Definition at line 194 of file ltablib.c.

References i, L, lua_createtable(), lua_gettop(), lua_insert, lua_pushinteger(), lua_setfield(), lua_seti(), and n.

◆ partition()

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

Definition at line 310 of file ltablib.c.

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

Referenced by auxsort().

◆ set2()

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

Definition at line 277 of file ltablib.c.

References i, j, L, and lua_seti().

Referenced by auxsort(), and partition().

◆ sort()

◆ sort_comp()

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

Definition at line 287 of file ltablib.c.

References a, b, L, lua_call, lua_compare(), lua_isnil, LUA_OPLT, lua_pop, lua_pushvalue(), lua_toboolean(), and res.

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)

◆ tremove()

static int tremove ( lua_State L)

Definition at line 106 of file ltablib.c.

References aux_getn, L, lua_geti(), lua_pushnil(), lua_seti(), luaL_argcheck, luaL_optinteger(), pos, size, and TAB_RW.

◆ unpack()

static int unpack ( lua_State L)

Variable Documentation

◆ tab_funcs

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

Definition at line 426 of file ltablib.c.

Referenced by luaopen_table().