mirror of https://github.com/rusefi/lua.git
"integer" keys in tables are now lua_Integer, not 'int'.
This commit is contained in:
parent
a2f5c28a80
commit
d4e6b75098
6
lapi.c
6
lapi.c
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
** $Id: lapi.c,v 2.173 2013/04/15 15:43:34 roberto Exp roberto $
|
||||
** $Id: lapi.c,v 2.174 2013/04/25 13:52:49 roberto Exp roberto $
|
||||
** Lua API
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
@ -656,7 +656,7 @@ LUA_API void lua_rawget (lua_State *L, int idx) {
|
|||
}
|
||||
|
||||
|
||||
LUA_API void lua_rawgeti (lua_State *L, int idx, int n) {
|
||||
LUA_API void lua_rawgeti (lua_State *L, int idx, lua_Integer n) {
|
||||
StkId t;
|
||||
lua_lock(L);
|
||||
t = index2addr(L, idx);
|
||||
|
@ -791,7 +791,7 @@ LUA_API void lua_rawset (lua_State *L, int idx) {
|
|||
}
|
||||
|
||||
|
||||
LUA_API void lua_rawseti (lua_State *L, int idx, int n) {
|
||||
LUA_API void lua_rawseti (lua_State *L, int idx, lua_Integer n) {
|
||||
StkId t;
|
||||
lua_lock(L);
|
||||
api_checknelems(L, 1);
|
||||
|
|
34
ltable.c
34
ltable.c
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
** $Id: ltable.c,v 2.71 2012/05/23 15:37:09 roberto Exp $
|
||||
** $Id: ltable.c,v 2.73 2013/04/15 15:44:46 roberto Exp roberto $
|
||||
** Lua tables (hash)
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
@ -123,9 +123,9 @@ static Node *mainposition (const Table *t, const TValue *key) {
|
|||
}
|
||||
|
||||
|
||||
static int numisint (lua_Number n, int *p) {
|
||||
int k;
|
||||
lua_number2int(k, n);
|
||||
static int numisint (lua_Number n, lua_Integer *p) {
|
||||
lua_Integer k;
|
||||
lua_number2integer(k, n);
|
||||
if (luai_numeq(cast_num(k), n)) { /* 'k' is int? */
|
||||
*p = k;
|
||||
return 1;
|
||||
|
@ -139,8 +139,12 @@ static int numisint (lua_Number n, int *p) {
|
|||
** the array part of the table, -1 otherwise.
|
||||
*/
|
||||
static int arrayindex (const TValue *key) {
|
||||
if (ttisinteger(key)) return ivalue(key);
|
||||
else return -1; /* `key' did not match some condition */
|
||||
if (ttisinteger(key)) {
|
||||
lua_Integer k = ivalue(key);
|
||||
if (0 < k && k <= MAXASIZE) /* is `key' an appropriate array index? */
|
||||
return cast_int(k);
|
||||
}
|
||||
return -1; /* `key' did not match some condition */
|
||||
}
|
||||
|
||||
|
||||
|
@ -225,7 +229,7 @@ static int computesizes (int nums[], int *narray) {
|
|||
|
||||
static int countint (const TValue *key, int *nums) {
|
||||
int k = arrayindex(key);
|
||||
if (0 < k && k <= MAXASIZE) { /* is `key' an appropriate array index? */
|
||||
if (k > 0) { /* is `key' an appropriate array index? */
|
||||
nums[luaO_ceillog2(k)]++; /* count as such */
|
||||
return 1;
|
||||
}
|
||||
|
@ -416,7 +420,7 @@ TValue *luaH_newkey (lua_State *L, Table *t, const TValue *key) {
|
|||
if (ttisnil(key)) luaG_runerror(L, "table index is nil");
|
||||
else if (ttisfloat(key)) {
|
||||
lua_Number n = fltvalue(key);
|
||||
int k;
|
||||
lua_Integer k;
|
||||
if (luai_numisnan(L, n))
|
||||
luaG_runerror(L, "table index is NaN");
|
||||
if (numisint(n, &k)) { /* index is int? */
|
||||
|
@ -460,10 +464,10 @@ TValue *luaH_newkey (lua_State *L, Table *t, const TValue *key) {
|
|||
/*
|
||||
** search function for integers
|
||||
*/
|
||||
const TValue *luaH_getint (Table *t, int key) {
|
||||
const TValue *luaH_getint (Table *t, lua_Integer key) {
|
||||
/* (1 <= key && key <= t->sizearray) */
|
||||
if (cast(unsigned int, key-1) < cast(unsigned int, t->sizearray))
|
||||
return &t->array[key-1];
|
||||
if (cast_unsigned(key - 1) < cast_unsigned(t->sizearray))
|
||||
return &t->array[key - 1];
|
||||
else {
|
||||
Node *n = hashint(t, key);
|
||||
do { /* check whether `key' is somewhere in the chain */
|
||||
|
@ -500,7 +504,7 @@ const TValue *luaH_get (Table *t, const TValue *key) {
|
|||
case LUA_TNUMINT: return luaH_getint(t, ivalue(key));
|
||||
case LUA_TNIL: return luaO_nilobject;
|
||||
case LUA_TNUMFLT: {
|
||||
int k;
|
||||
lua_Integer k;
|
||||
if (numisint(fltvalue(key), &k)) /* index is int? */
|
||||
return luaH_getint(t, k); /* use specialized version */
|
||||
/* else go through */
|
||||
|
@ -530,7 +534,7 @@ TValue *luaH_set (lua_State *L, Table *t, const TValue *key) {
|
|||
}
|
||||
|
||||
|
||||
void luaH_setint (lua_State *L, Table *t, int key, TValue *value) {
|
||||
void luaH_setint (lua_State *L, Table *t, lua_Integer key, TValue *value) {
|
||||
const TValue *p = luaH_getint(t, key);
|
||||
TValue *cell;
|
||||
if (p != luaO_nilobject)
|
||||
|
@ -550,13 +554,13 @@ static int unbound_search (Table *t, unsigned int j) {
|
|||
/* find `i' and `j' such that i is present and j is not */
|
||||
while (!ttisnil(luaH_getint(t, j))) {
|
||||
i = j;
|
||||
j *= 2;
|
||||
if (j > cast(unsigned int, MAX_INT)) { /* overflow? */
|
||||
if (j > cast(unsigned int, MAX_INT)/2) { /* overflow? */
|
||||
/* table was built with bad purposes: resort to linear search */
|
||||
i = 1;
|
||||
while (!ttisnil(luaH_getint(t, i))) i++;
|
||||
return i - 1;
|
||||
}
|
||||
j *= 2;
|
||||
}
|
||||
/* now do a binary search between them */
|
||||
while (j - i > 1) {
|
||||
|
|
7
ltable.h
7
ltable.h
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
** $Id: ltable.h,v 2.15 2011/08/09 20:58:29 roberto Exp roberto $
|
||||
** $Id: ltable.h,v 2.16 2011/08/17 20:26:47 roberto Exp roberto $
|
||||
** Lua tables (hash)
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
@ -18,8 +18,9 @@
|
|||
#define invalidateTMcache(t) ((t)->flags = 0)
|
||||
|
||||
|
||||
LUAI_FUNC const TValue *luaH_getint (Table *t, int key);
|
||||
LUAI_FUNC void luaH_setint (lua_State *L, Table *t, int key, TValue *value);
|
||||
LUAI_FUNC const TValue *luaH_getint (Table *t, lua_Integer key);
|
||||
LUAI_FUNC void luaH_setint (lua_State *L, Table *t, lua_Integer key,
|
||||
TValue *value);
|
||||
LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key);
|
||||
LUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key);
|
||||
LUAI_FUNC TValue *luaH_newkey (lua_State *L, Table *t, const TValue *key);
|
||||
|
|
6
lua.h
6
lua.h
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
** $Id: lua.h,v 1.286 2013/04/25 13:52:49 roberto Exp roberto $
|
||||
** $Id: lua.h,v 1.287 2013/04/26 13:07:53 roberto Exp roberto $
|
||||
** Lua - A Scripting Language
|
||||
** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
|
||||
** See Copyright Notice at the end of this file
|
||||
|
@ -226,7 +226,7 @@ LUA_API void (lua_getglobal) (lua_State *L, const char *var);
|
|||
LUA_API void (lua_gettable) (lua_State *L, int idx);
|
||||
LUA_API void (lua_getfield) (lua_State *L, int idx, const char *k);
|
||||
LUA_API void (lua_rawget) (lua_State *L, int idx);
|
||||
LUA_API void (lua_rawgeti) (lua_State *L, int idx, int n);
|
||||
LUA_API void (lua_rawgeti) (lua_State *L, int idx, lua_Integer n);
|
||||
LUA_API void (lua_rawgetp) (lua_State *L, int idx, const void *p);
|
||||
LUA_API void (lua_createtable) (lua_State *L, int narr, int nrec);
|
||||
LUA_API void *(lua_newuserdata) (lua_State *L, size_t sz);
|
||||
|
@ -241,7 +241,7 @@ LUA_API void (lua_setglobal) (lua_State *L, const char *var);
|
|||
LUA_API void (lua_settable) (lua_State *L, int idx);
|
||||
LUA_API void (lua_setfield) (lua_State *L, int idx, const char *k);
|
||||
LUA_API void (lua_rawset) (lua_State *L, int idx);
|
||||
LUA_API void (lua_rawseti) (lua_State *L, int idx, int n);
|
||||
LUA_API void (lua_rawseti) (lua_State *L, int idx, lua_Integer n);
|
||||
LUA_API void (lua_rawsetp) (lua_State *L, int idx, const void *p);
|
||||
LUA_API int (lua_setmetatable) (lua_State *L, int objindex);
|
||||
LUA_API void (lua_setuservalue) (lua_State *L, int idx);
|
||||
|
|
Loading…
Reference in New Issue