Github User Fetcher 1.0.0
C Application with Server and GUI
Loading...
Searching...
No Matches
lstring.h File Reference
#include "lgc.h"
#include "lobject.h"
#include "lstate.h"

Go to the source code of this file.

Macros

#define sizestring(s)   (sizeof(union TString)+((s)->len+1)*sizeof(char))
 
#define sizeudata(u)   (sizeof(union Udata)+(u)->len)
 
#define luaS_newliteral(L, s)
 
#define luaS_fix(s)   l_setbit((s)->tsv.marked, FIXEDBIT)
 
#define isreserved(s)   ((s)->tsv.tt == LUA_TSHRSTR && (s)->tsv.extra > 0)
 
#define eqshrstr(a, b)   check_exp((a)->tsv.tt == LUA_TSHRSTR, (a) == (b))
 

Functions

LUAI_FUNC unsigned int luaS_hash (const char *str, size_t l, unsigned int seed)
 
LUAI_FUNC int luaS_eqlngstr (TString *a, TString *b)
 
LUAI_FUNC int luaS_eqstr (TString *a, TString *b)
 
LUAI_FUNC void luaS_resize (lua_State *L, int newsize)
 
LUAI_FUNC UdataluaS_newudata (lua_State *L, size_t s, Table *e)
 
LUAI_FUNC TStringluaS_newlstr (lua_State *L, const char *str, size_t l)
 
LUAI_FUNC TStringluaS_new (lua_State *L, const char *str)
 

Macro Definition Documentation

◆ eqshrstr

#define eqshrstr ( a,
b )   check_exp((a)->tsv.tt == LUA_TSHRSTR, (a) == (b))

◆ isreserved

#define isreserved ( s)    ((s)->tsv.tt == LUA_TSHRSTR && (s)->tsv.extra > 0)

Definition at line 28 of file lua-5.2.4/src/lstring.h.

Referenced by llex(), llex(), llex(), undefgoto(), and undefgoto().

◆ luaS_fix

#define luaS_fix ( s)    l_setbit((s)->tsv.marked, FIXEDBIT)

Definition at line 22 of file lua-5.2.4/src/lstring.h.

◆ luaS_newliteral

#define luaS_newliteral ( L,
s )
Value:
(luaS_newlstr(L, "" s, \
(sizeof(s)/sizeof(char))-1))
LUAI_FUNC TString * luaS_newlstr(lua_State *L, const char *str, size_t l)
CURL_EXTERN CURLMcode curl_socket_t s
Definition multi.h:318

Definition at line 19 of file lua-5.2.4/src/lstring.h.

19#define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \
20 (sizeof(s)/sizeof(char))-1))

◆ sizestring

#define sizestring ( s)    (sizeof(union TString)+((s)->len+1)*sizeof(char))

Definition at line 15 of file lua-5.2.4/src/lstring.h.

◆ sizeudata

#define sizeudata ( u)    (sizeof(union Udata)+(u)->len)

Definition at line 17 of file lua-5.2.4/src/lstring.h.

Function Documentation

◆ luaS_eqlngstr()

LUAI_FUNC int luaS_eqlngstr ( TString * a,
TString * b )

Definition at line 33 of file lua-5.2.4/src/lstring.c.

33 {
34 size_t len = a->tsv.len;
35 lua_assert(a->tsv.tt == LUA_TLNGSTR && b->tsv.tt == LUA_TLNGSTR);
36 return (a == b) || /* same instance or... */
37 ((len == b->tsv.len) && /* equal length and ... */
38 (memcmp(getstr(a), getstr(b), len) == 0)); /* equal contents */
39}
#define lua_assert(c)
#define getstr(ts)
#define LUA_TLNGSTR
struct TString::@46 tsv

◆ luaS_eqstr()

LUAI_FUNC int luaS_eqstr ( TString * a,
TString * b )

Definition at line 45 of file lua-5.2.4/src/lstring.c.

45 {
46 return (a->tsv.tt == b->tsv.tt) &&
47 (a->tsv.tt == LUA_TSHRSTR ? eqshrstr(a, b) : luaS_eqlngstr(a, b));
48}
#define LUA_TSHRSTR
int luaS_eqlngstr(TString *a, TString *b)
#define eqshrstr(a, b)

References eqshrstr, LUA_TSHRSTR, luaS_eqlngstr(), and TString::tsv.

Referenced by checkrepeated(), closegoto(), findgotos(), findlabel(), searchupvalue(), and searchvar().

◆ luaS_hash()

LUAI_FUNC unsigned int luaS_hash ( const char * str,
size_t l,
unsigned int seed )

Definition at line 51 of file lua-5.2.4/src/lstring.c.

51 {
52 unsigned int h = seed ^ cast(unsigned int, l);
53 size_t l1;
54 size_t step = (l >> LUAI_HASHLIMIT) + 1;
55 for (l1 = l; l1 >= step; l1 -= step)
56 h = h ^ ((h<<5) + (h>>2) + cast_byte(str[l1 - 1]));
57 return h;
58}
#define cast_byte(i)
#define cast(t, exp)
#define LUAI_HASHLIMIT

◆ luaS_new()

LUAI_FUNC TString * luaS_new ( lua_State * L,
const char * str )

Definition at line 170 of file lua-5.2.4/src/lstring.c.

170 {
171 return luaS_newlstr(L, str, strlen(str));
172}
TString * luaS_newlstr(lua_State *L, const char *str, size_t l)

◆ luaS_newlstr()

LUAI_FUNC TString * luaS_newlstr ( lua_State * L,
const char * str,
size_t l )

Definition at line 75 of file lua-5.1.5/src/lstring.c.

75 {
76 GCObject *o;
77 unsigned int h = cast(unsigned int, l); /* seed */
78 size_t step = (l>>5)+1; /* if string is too long, don't hash all its chars */
79 size_t l1;
80 for (l1=l; l1>=step; l1-=step) /* compute hash */
81 h = h ^ ((h<<5)+(h>>2)+cast(unsigned char, str[l1-1]));
82 for (o = G(L)->strt.hash[lmod(h, G(L)->strt.size)];
83 o != NULL;
84 o = o->gch.next) {
85 TString *ts = rawgco2ts(o);
86 if (ts->tsv.len == l && (memcmp(str, getstr(ts), l) == 0)) {
87 /* string may be dead */
88 if (isdead(G(L), o)) changewhite(o);
89 return ts;
90 }
91 }
92 return newlstr(L, str, l, h); /* not found */
93}
#define NULL
Definition gmacros.h:924
#define changewhite(x)
#define isdead(g, v)
#define lmod(s, size)
#define G(L)
#define rawgco2ts(o)
static TString * newlstr(lua_State *L, const char *str, size_t l, unsigned int h)

◆ luaS_newudata()

LUAI_FUNC Udata * luaS_newudata ( lua_State * L,
size_t s,
Table * e )

Definition at line 96 of file lua-5.1.5/src/lstring.c.

96 {
97 Udata *u;
98 if (s > MAX_SIZET - sizeof(Udata))
99 luaM_toobig(L);
100 u = cast(Udata *, luaM_malloc(L, s + sizeof(Udata)));
101 u->uv.marked = luaC_white(G(L)); /* is not finalized */
102 u->uv.tt = LUA_TUSERDATA;
103 u->uv.len = s;
104 u->uv.metatable = NULL;
105 u->uv.env = e;
106 /* chain it on udata list (after main thread) */
107 u->uv.next = G(L)->mainthread->next;
108 G(L)->mainthread->next = obj2gco(u);
109 return u;
110}
#define luaC_white(g)
#define MAX_SIZET
void * luaM_toobig(lua_State *L)
#define luaM_malloc(L, t)
#define obj2gco(v)
#define LUA_TUSERDATA
struct Udata::@47 uv
struct Table * env
struct Table * metatable

References cast, Udata::env, G, Udata::len, LUA_TUSERDATA, luaC_newobj(), luaC_white, luaM_malloc, luaM_toobig(), MAX_SIZET, Udata::metatable, NULL, obj2gco, s, GCObject::u, and Udata::uv.

Referenced by lua_newuserdata(), and lua_newuserdatauv().

◆ luaS_resize()

LUAI_FUNC void luaS_resize ( lua_State * L,
int newsize )

Definition at line 22 of file lua-5.1.5/src/lstring.c.

22 {
23 GCObject **newhash;
24 stringtable *tb;
25 int i;
26 if (G(L)->gcstate == GCSsweepstring)
27 return; /* cannot resize during GC traverse */
28 newhash = luaM_newvector(L, newsize, GCObject *);
29 tb = &G(L)->strt;
30 for (i=0; i<newsize; i++) newhash[i] = NULL;
31 /* rehash */
32 for (i=0; i<tb->size; i++) {
33 GCObject *p = tb->hash[i];
34 while (p) { /* for each node in the list */
35 GCObject *next = p->gch.next; /* save next */
36 unsigned int h = gco2ts(p)->hash;
37 int h1 = lmod(h, newsize); /* new position */
38 lua_assert(cast_int(h%newsize) == lmod(h, newsize));
39 p->gch.next = newhash[h1]; /* chain it */
40 newhash[h1] = p;
41 p = next;
42 }
43 }
44 luaM_freearray(L, tb->hash, tb->size, TString *);
45 tb->size = newsize;
46 tb->hash = newhash;
47}
#define GCSsweepstring
#define next(ls)
#define cast_int(i)
#define luaM_freearray(L, b, n, t)
#define luaM_newvector(L, n, t)
#define gco2ts(o)