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 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)
 
#define luai_verifycode(L, b, f)   /* empty */
 
#define N0   LUAC_HEADERSIZE
 
#define N1   (sizeof(LUA_SIGNATURE)-sizeof(char))
 
#define N2   N1+2
 
#define N3   N2+6
 
#define MYINT(s)   (s[0]-'0')
 
#define VERSION   MYINT(LUA_VERSION_MAJOR)*16+MYINT(LUA_VERSION_MINOR)
 
#define FORMAT   0 /* this is the official format */
 

Functions

static l_noret 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 void LoadFunction (LoadState *S, Proto *f)
 
static void LoadConstants (LoadState *S, Proto *f)
 
static void LoadUpvalues (LoadState *S, Proto *f)
 
static void LoadDebug (LoadState *S, Proto *f)
 
static void LoadHeader (LoadState *S)
 
ClosureluaU_undump (lua_State *L, ZIO *Z, Mbuffer *buff, const char *name)
 
void luaU_header (lu_byte *h)
 

Macro Definition Documentation

◆ FORMAT

#define FORMAT   0 /* this is the official format */

Definition at line 237 of file lua-5.2.4/src/lundump.c.

Referenced by luaU_header().

◆ LoadByte

#define LoadByte ( S)    (lu_byte)LoadChar(S)

Definition at line 37 of file lua-5.2.4/src/lundump.c.

Referenced by LoadFunction(), and LoadUpvalues().

◆ LoadMem

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

Definition at line 36 of file lua-5.2.4/src/lundump.c.

◆ LoadVar

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

Definition at line 38 of file lua-5.2.4/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 39 of file lua-5.2.4/src/lundump.c.

Referenced by LoadCode(), and LoadDebug().

◆ LUA_CORE

#define LUA_CORE

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

◆ luai_verifycode

#define luai_verifycode ( L,
b,
f )   /* empty */

Definition at line 42 of file lua-5.2.4/src/lundump.c.

Referenced by luaU_undump().

◆ lundump_c

#define lundump_c

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

◆ MYINT

#define MYINT ( s)    (s[0]-'0')

Definition at line 235 of file lua-5.2.4/src/lundump.c.

◆ N0

#define N0   LUAC_HEADERSIZE

Definition at line 185 of file lua-5.2.4/src/lundump.c.

Referenced by LoadHeader().

◆ N1

#define N1   (sizeof(LUA_SIGNATURE)-sizeof(char))

Definition at line 186 of file lua-5.2.4/src/lundump.c.

Referenced by LoadHeader().

◆ N2

#define N2   N1+2

Definition at line 187 of file lua-5.2.4/src/lundump.c.

Referenced by LoadHeader().

◆ N3

#define N3   N2+6

Definition at line 188 of file lua-5.2.4/src/lundump.c.

Referenced by LoadHeader().

◆ VERSION

#define VERSION   MYINT(LUA_VERSION_MAJOR)*16+MYINT(LUA_VERSION_MINOR)

Definition at line 236 of file lua-5.2.4/src/lundump.c.

Referenced by luaU_header().

Function Documentation

◆ error()

static l_noret error ( LoadState * S,
const char * why )
static

Definition at line 30 of file lua-5.2.4/src/lundump.c.

31{
32 luaO_pushfstring(S->L,"%s: %s precompiled chunk",S->name,why);
34}
void luaD_throw(lua_State *L, int errcode)
const char * luaO_pushfstring(lua_State *L, const char *fmt,...)
#define LUA_ERRSYNTAX
#define S(x)
Definition print.c:159

References LUA_ERRSYNTAX, luaD_throw(), luaO_pushfstring(), and S.

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

◆ LoadBlock()

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

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

46{
47 if (luaZ_read(S->Z,b,size)!=0) error(S,"truncated");
48}
size_t luaZ_read(ZIO *z, void *b, size_t n)
static l_noret error(LoadState *S, const char *why)

References error(), luaZ_read(), and S.

Referenced by LoadHeader(), and LoadString().

◆ LoadChar()

static int LoadChar ( LoadState * S)
static

Definition at line 50 of file lua-5.2.4/src/lundump.c.

51{
52 char x;
53 LoadVar(S,x);
54 return x;
55}
#define LoadVar(S, x)

References LoadVar, and S.

Referenced by LoadConstants().

◆ LoadCode()

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

Definition at line 86 of file lua-5.2.4/src/lundump.c.

87{
88 int n=LoadInt(S);
90 f->sizecode=n;
91 LoadVector(S,f->code,n,sizeof(Instruction));
92}
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 96 of file lua-5.2.4/src/lundump.c.

97{
98 int i,n;
99 n=LoadInt(S);
100 f->k=luaM_newvector(S->L,n,TValue);
101 f->sizek=n;
102 for (i=0; i<n; i++) setnilvalue(&f->k[i]);
103 for (i=0; i<n; i++)
104 {
105 TValue* o=&f->k[i];
106 int t=LoadChar(S);
107 switch (t)
108 {
109 case LUA_TNIL:
110 setnilvalue(o);
111 break;
112 case LUA_TBOOLEAN:
113 setbvalue(o,LoadChar(S));
114 break;
115 case LUA_TNUMBER:
117 break;
118 case LUA_TSTRING:
119 setsvalue2n(S->L,o,LoadString(S));
120 break;
121 default: lua_assert(0);
122 }
123 }
124 n=LoadInt(S);
125 f->p=luaM_newvector(S->L,n,Proto*);
126 f->sizep=n;
127 for (i=0; i<n; i++) f->p[i]=NULL;
128 for (i=0; i<n; i++)
129 {
130 f->p[i]=luaF_newproto(S->L);
131 LoadFunction(S,f->p[i]);
132 }
133}
#define NULL
Definition gmacros.h:924
Proto * luaF_newproto(lua_State *L)
#define lua_assert(c)
#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 void LoadFunction(LoadState *S, Proto *f)
static TString * LoadString(LoadState *S)
static lua_Number LoadNumber(LoadState *S)
static int LoadChar(LoadState *S)
struct Proto ** p

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

Referenced by LoadFunction().

◆ LoadDebug()

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

Definition at line 149 of file lua-5.2.4/src/lundump.c.

150{
151 int i,n;
152 f->source=LoadString(S);
153 n=LoadInt(S);
154 f->lineinfo=luaM_newvector(S->L,n,int);
155 f->sizelineinfo=n;
156 LoadVector(S,f->lineinfo,n,sizeof(int));
157 n=LoadInt(S);
159 f->sizelocvars=n;
160 for (i=0; i<n; i++) f->locvars[i].varname=NULL;
161 for (i=0; i<n; i++)
162 {
164 f->locvars[i].startpc=LoadInt(S);
165 f->locvars[i].endpc=LoadInt(S);
166 }
167 n=LoadInt(S);
168 for (i=0; i<n; i++) f->upvalues[i].name=LoadString(S);
169}
TString * varname
struct LocVar * locvars
TString ** upvalues
TString * source

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

Referenced by LoadFunction().

◆ LoadFunction()

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

Definition at line 171 of file lua-5.2.4/src/lundump.c.

172{
175 f->numparams=LoadByte(S);
176 f->is_vararg=LoadByte(S);
178 LoadCode(S,f);
179 LoadConstants(S,f);
180 LoadUpvalues(S,f);
181 LoadDebug(S,f);
182}
static void LoadConstants(LoadState *S, Proto *f)
#define LoadByte(S)
static void LoadUpvalues(LoadState *S, Proto *f)
static void LoadDebug(LoadState *S, Proto *f)
static void LoadCode(LoadState *S, Proto *f)
lu_byte maxstacksize

References Proto::is_vararg, Proto::lastlinedefined, Proto::linedefined, LoadByte, LoadCode(), LoadConstants(), LoadDebug(), LoadInt(), LoadUpvalues(), Proto::maxstacksize, Proto::numparams, and S.

Referenced by LoadConstants(), and luaU_undump().

◆ LoadHeader()

static void LoadHeader ( LoadState * S)
static

Definition at line 190 of file lua-5.2.4/src/lundump.c.

191{
194 luaU_header(h);
195 memcpy(s,h,sizeof(char)); /* first char already read */
196 LoadBlock(S,s+sizeof(char),LUAC_HEADERSIZE-sizeof(char));
197 if (memcmp(h,s,N0)==0) return;
198 if (memcmp(h,s,N1)!=0) error(S,"not a");
199 if (memcmp(h,s,N2)!=0) error(S,"version mismatch in");
200 if (memcmp(h,s,N3)!=0) error(S,"incompatible"); else error(S,"corrupted");
201}
unsigned char lu_byte
#define LUAC_HEADERSIZE
void luaU_header(lu_byte *h)
#define N0
static void LoadBlock(LoadState *S, void *b, size_t size)
#define N1
#define N2
#define N3
CURL_EXTERN CURLMcode curl_socket_t s
Definition multi.h:318

References error(), LoadBlock(), LUAC_HEADERSIZE, luaU_header(), N0, N1, N2, N3, S, and s.

Referenced by luaU_undump().

◆ LoadInt()

static int LoadInt ( LoadState * S)
static

Definition at line 57 of file lua-5.2.4/src/lundump.c.

58{
59 int x;
60 LoadVar(S,x);
61 if (x<0) error(S,"corrupted");
62 return x;
63}

References error(), LoadVar, and S.

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

◆ LoadNumber()

static lua_Number LoadNumber ( LoadState * S)
static

Definition at line 65 of file lua-5.2.4/src/lundump.c.

66{
67 lua_Number x;
68 LoadVar(S,x);
69 return x;
70}
LUA_NUMBER lua_Number

References LoadVar, and S.

Referenced by LoadConstants().

◆ LoadString()

static TString * LoadString ( LoadState * S)
static

Definition at line 72 of file lua-5.2.4/src/lundump.c.

73{
74 size_t size;
75 LoadVar(S,size);
76 if (size==0)
77 return NULL;
78 else
79 {
80 char* s=luaZ_openspace(S->L,S->b,size);
81 LoadBlock(S,s,size*sizeof(char));
82 return luaS_newlstr(S->L,s,size-1); /* remove trailing '\0' */
83 }
84}
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(), and LoadDebug().

◆ LoadUpvalues()

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

Definition at line 135 of file lua-5.2.4/src/lundump.c.

136{
137 int i,n;
138 n=LoadInt(S);
140 f->sizeupvalues=n;
141 for (i=0; i<n; i++) f->upvalues[i].name=NULL;
142 for (i=0; i<n; i++)
143 {
144 f->upvalues[i].instack=LoadByte(S);
145 f->upvalues[i].idx=LoadByte(S);
146 }
147}

References LoadByte, LoadInt(), luaM_newvector, NULL, S, Proto::sizeupvalues, and Proto::upvalues.

Referenced by LoadFunction().

◆ luaU_header()

void luaU_header ( lu_byte * h)

Definition at line 244 of file lua-5.2.4/src/lundump.c.

245{
246 int x=1;
247 memcpy(h,LUA_SIGNATURE,sizeof(LUA_SIGNATURE)-sizeof(char));
248 h+=sizeof(LUA_SIGNATURE)-sizeof(char);
249 *h++=cast_byte(VERSION);
250 *h++=cast_byte(FORMAT);
251 *h++=cast_byte(*(char*)&x); /* endianness */
252 *h++=cast_byte(sizeof(int));
253 *h++=cast_byte(sizeof(size_t));
254 *h++=cast_byte(sizeof(Instruction));
255 *h++=cast_byte(sizeof(lua_Number));
256 *h++=cast_byte(((lua_Number)0.5)==0); /* is lua_Number integral? */
257 memcpy(h,LUAC_TAIL,sizeof(LUAC_TAIL)-sizeof(char));
258}
#define cast_byte(i)
#define LUA_SIGNATURE
#define VERSION
#define FORMAT
#define LUAC_TAIL

References cast_byte, FORMAT, LUA_SIGNATURE, LUAC_TAIL, and VERSION.

Referenced by LoadHeader().

◆ luaU_undump()

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

Definition at line 206 of file lua-5.2.4/src/lundump.c.

207{
208 LoadState S;
209 Closure* cl;
210 if (*name=='@' || *name=='=')
211 S.name=name+1;
212 else if (*name==LUA_SIGNATURE[0])
213 S.name="binary string";
214 else
215 S.name=name;
216 S.L=L;
217 S.Z=Z;
218 S.b=buff;
219 LoadHeader(&S);
220 cl=luaF_newLclosure(L,1);
221 setclLvalue(L,L->top,cl); incr_top(L);
222 cl->l.p=luaF_newproto(L);
223 LoadFunction(&S,cl->l.p);
224 if (cl->l.p->sizeupvalues != 1)
225 {
226 Proto* p=cl->l.p;
227 cl=luaF_newLclosure(L,cl->l.p->sizeupvalues);
228 cl->l.p=p;
229 setclLvalue(L,L->top-1,cl);
230 }
231 luai_verifycode(L,buff,cl->l.p);
232 return cl;
233}
const char * name
Definition lsqlite3.c:2154
#define incr_top(L)
Closure * luaF_newLclosure(lua_State *L, int nelems, Table *e)
#define setclLvalue(L, obj, x)
static void LoadHeader(LoadState *S)
#define luai_verifycode(L, b, f)
struct Proto * p

References incr_top, Closure::l, LoadFunction(), LoadHeader(), LUA_SIGNATURE, luaF_newLclosure(), luaF_newproto(), luai_verifycode, name, LClosure::p, S, setclLvalue, Proto::sizeupvalues, and lua_State::top.