2021-01-12 14:14:38 -05:00
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// This module contains a library of lua functions
|
2021-07-20 14:48:53 -04:00
|
|
|
// for manipulating tables. It also provides a library
|
|
|
|
|
// of useful classes based on tables.
|
2021-01-12 14:14:38 -05:00
|
|
|
//
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
2020-11-27 13:21:07 -05:00
|
|
|
#ifndef TABLE_HPP
|
|
|
|
|
#define TABLE_HPP
|
2020-11-13 18:17:47 -05:00
|
|
|
|
2020-11-27 13:21:07 -05:00
|
|
|
#include "luastack.hpp"
|
2020-11-13 18:17:47 -05:00
|
|
|
|
2021-09-07 17:37:23 -04:00
|
|
|
// Starting at the specified root, find tables recursively.
|
|
|
|
|
//
|
|
|
|
|
// Returns a table containing every table found, in tabcount.
|
|
|
|
|
// The value associated with the table is the number of times the
|
|
|
|
|
// table was found.
|
|
|
|
|
//
|
|
|
|
|
void table_findtables(LuaStack &LS0, LuaSlot root, LuaSlot tabcount);
|
|
|
|
|
|
|
|
|
|
// table_clear
|
|
|
|
|
//
|
|
|
|
|
// Remove all key/value pairs from the table. Does not remove
|
|
|
|
|
// the metatable.
|
|
|
|
|
//
|
|
|
|
|
void table_clear(LuaStack &LS0, LuaSlot tab);
|
|
|
|
|
|
2021-01-12 14:14:38 -05:00
|
|
|
// table_equal
|
|
|
|
|
//
|
|
|
|
|
// True if two tables contain the same key/value pairs.
|
|
|
|
|
//
|
2021-09-07 17:37:23 -04:00
|
|
|
bool table_equal(LuaStack &LS0, LuaSlot tab1, LuaSlot tab2);
|
2021-01-12 14:14:38 -05:00
|
|
|
|
|
|
|
|
// table_findremove
|
|
|
|
|
//
|
|
|
|
|
// Given a vector and a value, remove the specified value from
|
|
|
|
|
// the vector, and shift elements downward to fill the gaps.
|
|
|
|
|
//
|
2021-09-07 17:37:23 -04:00
|
|
|
int lfn_table_findremove(lua_State *L);
|
2021-01-12 14:14:38 -05:00
|
|
|
|
|
|
|
|
// table_push
|
|
|
|
|
//
|
|
|
|
|
// Given a vector and a value, push the value onto the end.
|
|
|
|
|
//
|
2021-09-07 17:37:23 -04:00
|
|
|
int lfn_table_push(lua_State *L);
|
2021-01-12 14:14:38 -05:00
|
|
|
|
|
|
|
|
// table_find
|
|
|
|
|
//
|
|
|
|
|
// Given a vector and a value, search for the first occurrence
|
|
|
|
|
// of that value. Return the index.
|
|
|
|
|
//
|
2021-09-07 17:37:23 -04:00
|
|
|
int lfn_table_find(lua_State *L);
|
2021-01-12 14:14:38 -05:00
|
|
|
|
|
|
|
|
// table_empty
|
|
|
|
|
//
|
|
|
|
|
// Return true if the table has no key/value pairs.
|
|
|
|
|
//
|
2021-09-07 17:37:23 -04:00
|
|
|
int lfn_table_empty(lua_State *L);
|
2021-01-12 14:14:38 -05:00
|
|
|
|
|
|
|
|
// table_count
|
|
|
|
|
//
|
|
|
|
|
// Return the number of key/value pairs in the table.
|
|
|
|
|
//
|
2021-09-07 17:37:23 -04:00
|
|
|
int lfn_table_count(lua_State *L);
|
2021-01-12 14:14:38 -05:00
|
|
|
|
|
|
|
|
//
|
2021-07-20 14:48:53 -04:00
|
|
|
// Create and return an empty deque. Queues are implemented
|
2021-07-09 18:07:06 -04:00
|
|
|
// as tables which are used as dynamically-expandable circular
|
|
|
|
|
// buffers.
|
2021-01-12 14:14:38 -05:00
|
|
|
//
|
2021-09-07 17:37:23 -04:00
|
|
|
int lfn_deque_create(lua_State *L);
|
2021-01-12 14:14:38 -05:00
|
|
|
|
|
|
|
|
//
|
2021-07-12 00:37:07 -04:00
|
|
|
// Given a deque and a value, pushes the value onto the
|
|
|
|
|
// left or right end.
|
2021-01-12 14:14:38 -05:00
|
|
|
//
|
2021-09-07 17:37:23 -04:00
|
|
|
int lfn_deque_pushl(lua_State *L);
|
|
|
|
|
int lfn_deque_pushr(lua_State *L);
|
2021-01-12 14:14:38 -05:00
|
|
|
|
|
|
|
|
//
|
2021-07-12 00:37:07 -04:00
|
|
|
// Given a deque, pop from the left or right end. Returns the
|
|
|
|
|
// value and removes it from the deque. If the deque is
|
|
|
|
|
// empty, returns nil.
|
2021-01-12 14:14:38 -05:00
|
|
|
//
|
2021-09-07 17:37:23 -04:00
|
|
|
int lfn_deque_popl(lua_State *L);
|
|
|
|
|
int lfn_deque_popr(lua_State *L);
|
2021-01-12 14:14:38 -05:00
|
|
|
|
|
|
|
|
//
|
2021-07-12 00:37:07 -04:00
|
|
|
// Return the nth element from the left or right end of a deque.
|
2021-01-12 14:14:38 -05:00
|
|
|
//
|
2021-09-07 17:37:23 -04:00
|
|
|
int lfn_deque_nthl(lua_State *L);
|
|
|
|
|
int lfn_deque_nthr(lua_State *L);
|
2021-01-12 14:14:38 -05:00
|
|
|
|
2021-07-20 16:16:07 -04:00
|
|
|
// Set (overwrite) the nth element in a deque.
|
|
|
|
|
//
|
2021-09-07 17:37:23 -04:00
|
|
|
int lfn_deque_setl(lua_State *L);
|
|
|
|
|
int lfn_deque_setr(lua_State *L);
|
2021-07-20 16:16:07 -04:00
|
|
|
|
2021-07-20 14:48:53 -04:00
|
|
|
//
|
|
|
|
|
// Search a deque for a value.
|
|
|
|
|
//
|
|
|
|
|
// Search starts on the specified end and indices are relative
|
|
|
|
|
// to specified end.
|
|
|
|
|
//
|
2021-09-07 17:37:23 -04:00
|
|
|
int lfn_deque_findl(lua_State *L);
|
|
|
|
|
int lfn_deque_findr(lua_State *L);
|
2021-07-20 14:48:53 -04:00
|
|
|
|
2021-01-12 14:14:38 -05:00
|
|
|
//
|
2021-07-12 00:37:07 -04:00
|
|
|
// Return the number of values in the deque.
|
2021-01-12 14:14:38 -05:00
|
|
|
//
|
2021-09-07 17:37:23 -04:00
|
|
|
int lfn_deque_size(lua_State *L);
|
2020-11-13 18:17:47 -05:00
|
|
|
|
2020-11-27 13:21:07 -05:00
|
|
|
#endif // TABLE_HPP
|