Github User Fetcher 1.0.0
C Application with Server and GUI
Loading...
Searching...
No Matches
lundump.c File Reference
#include <string.h>
#include "lua.h"
#include "ldebug.h"
#include "ldo.h"
#include "lfunc.h"
#include "lmem.h"
#include "lobject.h"
#include "lstring.h"
#include "lundump.h"
#include "lzio.h"

Go to the source code of this file.

Data Structures

struct  LoadState
 

Macros

#define lundump_c
 
#define LUA_CORE
 
#define IF(c, s)   if (c) error(S,s)
 
#define LoadMem(S, b, n, size)   LoadBlock(S,b,(n)*(size))
 
#define LoadByte(S)   (lu_byte)LoadChar(S)
 
#define LoadVar(S, x)   LoadMem(S,&x,1,sizeof(x))
 
#define LoadVector(S, b, n, size)   LoadMem(S,b,n,size)
 

Functions

static void error (LoadState *S, const char *why)
 
static void LoadBlock (LoadState *S, void *b, size_t size)
 
static int LoadChar (LoadState *S)
 
static int LoadInt (LoadState *S)
 
static lua_Number LoadNumber (LoadState *S)
 
static TStringLoadString (LoadState *S)
 
static void LoadCode (LoadState *S, Proto *f)
 
static ProtoLoadFunction (LoadState *S, TString *p)
 
static void LoadConstants (LoadState *S, Proto *f)
 
static void LoadDebug (LoadState *S, Proto *f)
 
static void LoadHeader (LoadState *S)
 
ProtoluaU_undump (lua_State *L, ZIO *Z, Mbuffer *buff, const char *name)
 
void luaU_header (char *h)
 

Macro Definition Documentation

◆ IF

#define IF ( c,
s )   if (c) error(S,s)

Definition at line 34 of file lua-5.1.5/src/lundump.c.

Referenced by LoadBlock(), LoadFunction(), LoadHeader(), and LoadInt().

◆ LoadByte

◆ LoadMem

#define LoadMem ( S,
b,
n,
size )   LoadBlock(S,b,(n)*(size))

Definition at line 43 of file lua-5.1.5/src/lundump.c.

◆ LoadVar

#define LoadVar ( S,
x )   LoadMem(S,&x,1,sizeof(x))

Definition at line 45 of file lua-5.1.5/src/lundump.c.

Referenced by LoadChar(), LoadInt(), LoadNumber(), and LoadString().

◆ LoadVector

#define LoadVector ( S,
b,
n,
size )   LoadMem(S,b,n,size)

Definition at line 46 of file lua-5.1.5/src/lundump.c.

Referenced by LoadCode(), and LoadDebug().

◆ LUA_CORE

#define LUA_CORE

Definition at line 10 of file lua-5.1.5/src/lundump.c.

◆ lundump_c

#define lundump_c

Definition at line 9 of file lua-5.1.5/src/lundump.c.

Function Documentation

◆ error()

◆ LoadBlock()

static void LoadBlock ( LoadState * S,
void * b,
size_t size )
static

Definition at line 48 of file lua-5.1.5/src/lundump.c.

49{
50 size_t r=luaZ_read(S->Z,b,size);
51 IF (r!=0, "unexpected end");
52}
#define IF(c, s)
size_t luaZ_read(ZIO *z, void *b, size_t n)

References IF, luaZ_read(), and S.

Referenced by LoadHeader(), and LoadString().

◆ LoadChar()

static int LoadChar ( LoadState * S)
static

Definition at line 54 of file lua-5.1.5/src/lundump.c.

55{
56 char x;
57 LoadVar(S,x);
58 return x;
59}
#define LoadVar(S, x)

References LoadVar, and S.

Referenced by LoadConstants().

◆ LoadCode()

static void LoadCode ( LoadState * S,
Proto * f )
static

Definition at line 90 of file lua-5.1.5/src/lundump.c.

91{
92 int n=LoadInt(S);
94 f->sizecode=n;
95 LoadVector(S,f->code,n,sizeof(Instruction));
96}
lu_int32 Instruction
#define luaM_newvector(L, n, t)
#define LoadVector(S, b, n, size)
static int LoadInt(LoadState *S)
Instruction * code

References Proto::code, LoadInt(), LoadVector, luaM_newvector, S, and Proto::sizecode.

Referenced by LoadFunction().

◆ LoadConstants()

static void LoadConstants ( LoadState * S,
Proto * f )
static

Definition at line 100 of file lua-5.1.5/src/lundump.c.

101{
102 int i,n;
103 n=LoadInt(S);
104 f->k=luaM_newvector(S->L,n,TValue);
105 f->sizek=n;
106 for (i=0; i<n; i++) setnilvalue(&f->k[i]);
107 for (i=0; i<n; i++)
108 {
109 TValue* o=&f->k[i];
110 int t=LoadChar(S);
111 switch (t)
112 {
113 case LUA_TNIL:
114 setnilvalue(o);
115 break;
116 case LUA_TBOOLEAN:
117 setbvalue(o,LoadChar(S)!=0);
118 break;
119 case LUA_TNUMBER:
121 break;
122 case LUA_TSTRING:
123 setsvalue2n(S->L,o,LoadString(S));
124 break;
125 default:
126 error(S,"bad constant");
127 break;
128 }
129 }
130 n=LoadInt(S);
131 f->p=luaM_newvector(S->L,n,Proto*);
132 f->sizep=n;
133 for (i=0; i<n; i++) f->p[i]=NULL;
134 for (i=0; i<n; i++) f->p[i]=LoadFunction(S,f->source);
135}
#define NULL
Definition gmacros.h:924
#define setbvalue(obj, x)
#define setnvalue(obj, x)
#define setsvalue2n
#define setnilvalue(obj)
#define LUA_TSTRING
#define LUA_TBOOLEAN
#define LUA_TNUMBER
#define LUA_TNIL
static TString * LoadString(LoadState *S)
static lua_Number LoadNumber(LoadState *S)
static void error(LoadState *S, const char *why)
static Proto * LoadFunction(LoadState *S, TString *p)
static int LoadChar(LoadState *S)
struct Proto ** p
TString * source

References error(), Proto::k, LoadChar(), LoadFunction(), LoadInt(), LoadNumber(), LoadString(), LUA_TBOOLEAN, LUA_TNIL, LUA_TNUMBER, LUA_TSTRING, luaM_newvector, NULL, Proto::p, S, setbvalue, setnilvalue, setnvalue, setsvalue2n, Proto::sizek, Proto::sizep, and Proto::source.

Referenced by LoadFunction().

◆ LoadDebug()

static void LoadDebug ( LoadState * S,
Proto * f )
static

Definition at line 137 of file lua-5.1.5/src/lundump.c.

138{
139 int i,n;
140 n=LoadInt(S);
141 f->lineinfo=luaM_newvector(S->L,n,int);
142 f->sizelineinfo=n;
143 LoadVector(S,f->lineinfo,n,sizeof(int));
144 n=LoadInt(S);
146 f->sizelocvars=n;
147 for (i=0; i<n; i++) f->locvars[i].varname=NULL;
148 for (i=0; i<n; i++)
149 {
151 f->locvars[i].startpc=LoadInt(S);
152 f->locvars[i].endpc=LoadInt(S);
153 }
154 n=LoadInt(S);
156 f->sizeupvalues=n;
157 for (i=0; i<n; i++) f->upvalues[i]=NULL;
158 for (i=0; i<n; i++) f->upvalues[i]=LoadString(S);
159}
TString * varname
struct LocVar * locvars
TString ** upvalues

References LocVar::endpc, Proto::lineinfo, LoadInt(), LoadString(), LoadVector, Proto::locvars, luaM_newvector, NULL, S, Proto::sizelineinfo, Proto::sizelocvars, Proto::sizeupvalues, LocVar::startpc, Proto::upvalues, and LocVar::varname.

Referenced by LoadFunction().

◆ LoadFunction()

static Proto * LoadFunction ( LoadState * S,
TString * p )
static

Definition at line 161 of file lua-5.1.5/src/lundump.c.

162{
163 Proto* f;
164 if (++S->L->nCcalls > LUAI_MAXCCALLS) error(S,"code too deep");
165 f=luaF_newproto(S->L);
166 setptvalue2s(S->L,S->L->top,f); incr_top(S->L);
167 f->source=LoadString(S); if (f->source==NULL) f->source=p;
170 f->nups=LoadByte(S);
171 f->numparams=LoadByte(S);
172 f->is_vararg=LoadByte(S);
174 LoadCode(S,f);
175 LoadConstants(S,f);
176 LoadDebug(S,f);
177 IF (!luaG_checkcode(f), "bad code");
178 S->L->top--;
179 S->L->nCcalls--;
180 return f;
181}
int luaG_checkcode(const Proto *pt)
#define incr_top(L)
Proto * luaF_newproto(lua_State *L)
#define setptvalue2s
#define LUAI_MAXCCALLS
static void LoadConstants(LoadState *S, Proto *f)
#define LoadByte(S)
static void LoadDebug(LoadState *S, Proto *f)
static void LoadCode(LoadState *S, Proto *f)
lu_byte maxstacksize

References error(), IF, incr_top, Proto::is_vararg, Proto::lastlinedefined, Proto::linedefined, LoadByte, LoadCode(), LoadConstants(), LoadDebug(), LoadInt(), LoadString(), luaF_newproto(), luaG_checkcode(), LUAI_MAXCCALLS, Proto::maxstacksize, NULL, Proto::numparams, Proto::nups, S, setptvalue2s, and Proto::source.

Referenced by LoadConstants(), and luaU_undump().

◆ LoadHeader()

static void LoadHeader ( LoadState * S)
static

Definition at line 183 of file lua-5.1.5/src/lundump.c.

184{
185 char h[LUAC_HEADERSIZE];
186 char s[LUAC_HEADERSIZE];
187 luaU_header(h);
189 IF (memcmp(h,s,LUAC_HEADERSIZE)!=0, "bad header");
190}
static void LoadBlock(LoadState *S, void *b, size_t size)
void luaU_header(char *h)
#define LUAC_HEADERSIZE
CURL_EXTERN CURLMcode curl_socket_t s
Definition multi.h:318

References IF, LoadBlock(), LUAC_HEADERSIZE, luaU_header(), S, and s.

Referenced by luaU_undump().

◆ LoadInt()

static int LoadInt ( LoadState * S)
static

Definition at line 61 of file lua-5.1.5/src/lundump.c.

62{
63 int x;
64 LoadVar(S,x);
65 IF (x<0, "bad integer");
66 return x;
67}

References IF, LoadVar, and S.

Referenced by LoadCode(), LoadConstants(), LoadDebug(), and LoadFunction().

◆ LoadNumber()

static lua_Number LoadNumber ( LoadState * S)
static

Definition at line 69 of file lua-5.1.5/src/lundump.c.

70{
71 lua_Number x;
72 LoadVar(S,x);
73 return x;
74}
LUA_NUMBER lua_Number

References LoadVar, and S.

Referenced by LoadConstants().

◆ LoadString()

static TString * LoadString ( LoadState * S)
static

Definition at line 76 of file lua-5.1.5/src/lundump.c.

77{
78 size_t size;
79 LoadVar(S,size);
80 if (size==0)
81 return NULL;
82 else
83 {
84 char* s=luaZ_openspace(S->L,S->b,size);
85 LoadBlock(S,s,size);
86 return luaS_newlstr(S->L,s,size-1); /* remove trailing '\0' */
87 }
88}
TString * luaS_newlstr(lua_State *L, const char *str, size_t l)
char * luaZ_openspace(lua_State *L, Mbuffer *buff, size_t n)

References LoadBlock(), LoadVar, luaS_newlstr(), luaZ_openspace(), NULL, S, and s.

Referenced by LoadConstants(), LoadDebug(), and LoadFunction().

◆ luaU_header()

void luaU_header ( char * h)

Definition at line 214 of file lua-5.1.5/src/lundump.c.

215{
216 int x=1;
217 memcpy(h,LUA_SIGNATURE,sizeof(LUA_SIGNATURE)-1);
218 h+=sizeof(LUA_SIGNATURE)-1;
219 *h++=(char)LUAC_VERSION;
220 *h++=(char)LUAC_FORMAT;
221 *h++=(char)*(char*)&x; /* endianness */
222 *h++=(char)sizeof(int);
223 *h++=(char)sizeof(size_t);
224 *h++=(char)sizeof(Instruction);
225 *h++=(char)sizeof(lua_Number);
226 *h++=(char)(((lua_Number)0.5)==0); /* is lua_Number integral? */
227}
#define LUA_SIGNATURE
#define LUAC_FORMAT
#define LUAC_VERSION

References LUA_SIGNATURE, LUAC_FORMAT, and LUAC_VERSION.

Referenced by DumpHeader(), DumpHeader(), and LoadHeader().

◆ luaU_undump()

Proto * luaU_undump ( lua_State * L,
ZIO * Z,
Mbuffer * buff,
const char * name )

Definition at line 195 of file lua-5.1.5/src/lundump.c.

196{
197 LoadState S;
198 if (*name=='@' || *name=='=')
199 S.name=name+1;
200 else if (*name==LUA_SIGNATURE[0])
201 S.name="binary string";
202 else
203 S.name=name;
204 S.L=L;
205 S.Z=Z;
206 S.b=buff;
207 LoadHeader(&S);
208 return LoadFunction(&S,luaS_newliteral(L,"=?"));
209}
const char * name
Definition lsqlite3.c:2154
#define luaS_newliteral(L, s)
static void LoadHeader(LoadState *S)
const char * name

References LoadFunction(), LoadHeader(), LUA_SIGNATURE, luaS_newliteral, name, LoadState::name, and S.

Referenced by f_parser(), f_parser(), f_parser(), and f_parser().