Github User Fetcher 1.0.0
C Application with Server and GUI
Loading...
Searching...
No Matches
ldump.c File Reference
#include "lprefix.h"
#include <stddef.h>
#include "lua.h"
#include "lobject.h"
#include "lstate.h"
#include "lundump.h"

Go to the source code of this file.

Data Structures

struct  DumpState
 

Macros

#define ldump_c
 
#define LUA_CORE
 
#define DumpVector(v, n, D)   DumpBlock(v,(n)*sizeof((v)[0]),D)
 
#define DumpLiteral(s, D)   DumpBlock(s, sizeof(s) - sizeof(char), D)
 
#define DumpVar(x, D)   DumpVector(&x,1,D)
 

Functions

static void DumpBlock (const void *b, size_t size, DumpState *D)
 
static void DumpByte (int y, DumpState *D)
 
static void DumpInt (int x, DumpState *D)
 
static void DumpNumber (lua_Number x, DumpState *D)
 
static void DumpInteger (lua_Integer x, DumpState *D)
 
static void DumpString (const TString *s, DumpState *D)
 
static void DumpCode (const Proto *f, DumpState *D)
 
static void DumpFunction (const Proto *f, TString *psource, DumpState *D)
 
static void DumpConstants (const Proto *f, DumpState *D)
 
static void DumpProtos (const Proto *f, DumpState *D)
 
static void DumpUpvalues (const Proto *f, DumpState *D)
 
static void DumpDebug (const Proto *f, DumpState *D)
 
static void DumpHeader (DumpState *D)
 
int luaU_dump (lua_State *L, const Proto *f, lua_Writer w, void *data, int strip)
 

Macro Definition Documentation

◆ DumpLiteral

#define DumpLiteral ( s,
D )   DumpBlock(s, sizeof(s) - sizeof(char), D)

Definition at line 37 of file lua-5.3.6/src/ldump.c.

Referenced by DumpHeader().

◆ DumpVar

#define DumpVar ( x,
D )   DumpVector(&x,1,D)

Definition at line 49 of file lua-5.3.6/src/ldump.c.

Referenced by DumpByte(), DumpInt(), DumpInteger(), DumpNumber(), and DumpString().

◆ DumpVector

#define DumpVector ( v,
n,
D )   DumpBlock(v,(n)*sizeof((v)[0]),D)

Definition at line 35 of file lua-5.3.6/src/ldump.c.

Referenced by DumpCode(), DumpDebug(), DumpDebug(), DumpDebug(), and DumpString().

◆ ldump_c

#define ldump_c

Definition at line 7 of file lua-5.3.6/src/ldump.c.

◆ LUA_CORE

#define LUA_CORE

Definition at line 8 of file lua-5.3.6/src/ldump.c.

Function Documentation

◆ DumpBlock()

static void DumpBlock ( const void * b,
size_t size,
DumpState * D )
static

Definition at line 40 of file lua-5.3.6/src/ldump.c.

40 {
41 if (D->status == 0 && size > 0) {
42 lua_unlock(D->L);
43 D->status = (*D->writer)(D->L, b, size, D->data);
44 lua_lock(D->L);
45 }
46}
#define lua_unlock(L)
#define lua_lock(L)
lua_State * L
lua_Writer writer

References DumpState::data, DumpState::L, lua_lock, lua_unlock, DumpState::status, and DumpState::writer.

◆ DumpByte()

static void DumpByte ( int y,
DumpState * D )
static

Definition at line 52 of file lua-5.3.6/src/ldump.c.

52 {
53 lu_byte x = (lu_byte)y;
54 DumpVar(x, D);
55}
unsigned char lu_byte
#define DumpVar(x, D)

References DumpVar.

Referenced by DumpConstants(), DumpFunction(), DumpHeader(), DumpString(), DumpUpvalues(), and luaU_dump().

◆ DumpCode()

static void DumpCode ( const Proto * f,
DumpState * D )
static

Definition at line 90 of file lua-5.3.6/src/ldump.c.

90 {
91 DumpInt(f->sizecode, D);
92 DumpVector(f->code, f->sizecode, D);
93}
static void DumpInt(int x, DumpState *D)
#define DumpVector(v, n, D)
Instruction * code

References Proto::code, DumpInt(), DumpVector, and Proto::sizecode.

◆ DumpConstants()

static void DumpConstants ( const Proto * f,
DumpState * D )
static

Definition at line 98 of file lua-5.3.6/src/ldump.c.

98 {
99 int i;
100 int n = f->sizek;
101 DumpInt(n, D);
102 for (i = 0; i < n; i++) {
103 const TValue *o = &f->k[i];
104 DumpByte(ttype(o), D);
105 switch (ttype(o)) {
106 case LUA_TNIL:
107 break;
108 case LUA_TBOOLEAN:
109 DumpByte(bvalue(o), D);
110 break;
111 case LUA_TNUMFLT:
112 DumpNumber(fltvalue(o), D);
113 break;
114 case LUA_TNUMINT:
115 DumpInteger(ivalue(o), D);
116 break;
117 case LUA_TSHRSTR:
118 case LUA_TLNGSTR:
119 DumpString(tsvalue(o), D);
120 break;
121 default:
122 lua_assert(0);
123 }
124 }
125}
#define lua_assert(c)
#define tsvalue(o)
#define bvalue(o)
#define ttype(o)
#define LUA_TBOOLEAN
#define LUA_TNIL
#define LUA_TSHRSTR
#define LUA_TLNGSTR
static void DumpNumber(lua_Number x, DumpState *D)
static void DumpInteger(lua_Integer x, DumpState *D)
static void DumpByte(int y, DumpState *D)
static void DumpString(const TString *s, DumpState *D)
#define LUA_TNUMINT
#define fltvalue(o)
#define ivalue(o)
#define LUA_TNUMFLT

References bvalue, DumpByte(), DumpInt(), DumpInteger(), DumpNumber(), DumpString(), fltvalue, ivalue, Proto::k, lua_assert, LUA_TBOOLEAN, LUA_TLNGSTR, LUA_TNIL, LUA_TNUMFLT, LUA_TNUMINT, LUA_TSHRSTR, Proto::sizek, tsvalue, and ttype.

Referenced by DumpFunction().

◆ DumpDebug()

static void DumpDebug ( const Proto * f,
DumpState * D )
static

Definition at line 147 of file lua-5.3.6/src/ldump.c.

147 {
148 int i, n;
149 n = (D->strip) ? 0 : f->sizelineinfo;
150 DumpInt(n, D);
151 DumpVector(f->lineinfo, n, D);
152 n = (D->strip) ? 0 : f->sizelocvars;
153 DumpInt(n, D);
154 for (i = 0; i < n; i++) {
155 DumpString(f->locvars[i].varname, D);
156 DumpInt(f->locvars[i].startpc, D);
157 DumpInt(f->locvars[i].endpc, D);
158 }
159 n = (D->strip) ? 0 : f->sizeupvalues;
160 DumpInt(n, D);
161 for (i = 0; i < n; i++)
162 DumpString(f->upvalues[i].name, D);
163}
TString * varname
struct LocVar * locvars
TString ** upvalues

References DumpInt(), DumpString(), DumpVector, LocVar::endpc, Proto::lineinfo, Proto::locvars, Proto::sizelineinfo, Proto::sizelocvars, Proto::sizeupvalues, LocVar::startpc, DumpState::strip, Proto::upvalues, and LocVar::varname.

Referenced by DumpFunction().

◆ DumpFunction()

static void DumpFunction ( const Proto * f,
TString * psource,
DumpState * D )
static

Definition at line 166 of file lua-5.3.6/src/ldump.c.

166 {
167 if (D->strip || f->source == psource)
168 DumpString(NULL, D); /* no debug info or same source as its parent */
169 else
170 DumpString(f->source, D);
171 DumpInt(f->linedefined, D);
173 DumpByte(f->numparams, D);
174 DumpByte(f->is_vararg, D);
175 DumpByte(f->maxstacksize, D);
176 DumpCode(f, D);
177 DumpConstants(f, D);
178 DumpUpvalues(f, D);
179 DumpProtos(f, D);
180 DumpDebug(f, D);
181}
#define NULL
Definition gmacros.h:924
#define DumpCode(f, D)
static void DumpProtos(const Proto *f, DumpState *D)
static void DumpConstants(const Proto *f, DumpState *D)
static void DumpDebug(const Proto *f, DumpState *D)
static void DumpUpvalues(const Proto *f, DumpState *D)
lu_byte maxstacksize
TString * source

References DumpByte(), DumpCode, DumpConstants(), DumpDebug(), DumpInt(), DumpProtos(), DumpString(), DumpUpvalues(), Proto::is_vararg, Proto::lastlinedefined, Proto::linedefined, Proto::maxstacksize, NULL, Proto::numparams, Proto::source, and DumpState::strip.

Referenced by DumpProtos(), and luaU_dump().

◆ DumpHeader()

static void DumpHeader ( DumpState * D)
static

Definition at line 184 of file lua-5.3.6/src/ldump.c.

184 {
189 DumpByte(sizeof(int), D);
190 DumpByte(sizeof(size_t), D);
191 DumpByte(sizeof(Instruction), D);
192 DumpByte(sizeof(lua_Integer), D);
193 DumpByte(sizeof(lua_Number), D);
196}
lu_int32 Instruction
LUA_INTEGER lua_Integer
LUA_NUMBER lua_Number
#define LUA_SIGNATURE
#define LUAC_FORMAT
#define LUAC_VERSION
#define DumpLiteral(s, D)
#define LUAC_NUM
#define LUAC_DATA
#define LUAC_INT

References DumpByte(), DumpInteger(), DumpLiteral, DumpNumber(), LUA_SIGNATURE, LUAC_DATA, LUAC_FORMAT, LUAC_INT, LUAC_NUM, and LUAC_VERSION.

Referenced by luaU_dump().

◆ DumpInt()

static void DumpInt ( int x,
DumpState * D )
static

Definition at line 58 of file lua-5.3.6/src/ldump.c.

58 {
59 DumpVar(x, D);
60}

References DumpVar.

Referenced by DumpCode(), DumpConstants(), DumpDebug(), DumpFunction(), DumpProtos(), and DumpUpvalues().

◆ DumpInteger()

static void DumpInteger ( lua_Integer x,
DumpState * D )
static

Definition at line 68 of file lua-5.3.6/src/ldump.c.

68 {
69 DumpVar(x, D);
70}

References DumpVar.

Referenced by DumpConstants(), and DumpHeader().

◆ DumpNumber()

static void DumpNumber ( lua_Number x,
DumpState * D )
static

Definition at line 63 of file lua-5.3.6/src/ldump.c.

63 {
64 DumpVar(x, D);
65}

References DumpVar.

Referenced by DumpConstants(), and DumpHeader().

◆ DumpProtos()

static void DumpProtos ( const Proto * f,
DumpState * D )
static

Definition at line 128 of file lua-5.3.6/src/ldump.c.

128 {
129 int i;
130 int n = f->sizep;
131 DumpInt(n, D);
132 for (i = 0; i < n; i++)
133 DumpFunction(f->p[i], f->source, D);
134}
static void DumpFunction(const Proto *f, TString *psource, DumpState *D)
struct Proto ** p

References DumpFunction(), DumpInt(), Proto::p, Proto::sizep, and Proto::source.

Referenced by DumpFunction().

◆ DumpString()

static void DumpString ( const TString * s,
DumpState * D )
static

Definition at line 73 of file lua-5.3.6/src/ldump.c.

73 {
74 if (s == NULL)
75 DumpByte(0, D);
76 else {
77 size_t size = tsslen(s) + 1; /* include trailing '\0' */
78 const char *str = getstr(s);
79 if (size < 0xFF)
80 DumpByte(cast_int(size), D);
81 else {
82 DumpByte(0xFF, D);
83 DumpVar(size, D);
84 }
85 DumpVector(str, size - 1, D); /* no need to save '\0' */
86 }
87}
#define cast_int(i)
#define getstr(ts)
#define tsslen(s)
CURL_EXTERN CURLMcode curl_socket_t s
Definition multi.h:318

References cast_int, DumpByte(), DumpVar, DumpVector, getstr, NULL, s, and tsslen.

Referenced by DumpConstants(), DumpDebug(), and DumpFunction().

◆ DumpUpvalues()

static void DumpUpvalues ( const Proto * f,
DumpState * D )
static

Definition at line 137 of file lua-5.3.6/src/ldump.c.

137 {
138 int i, n = f->sizeupvalues;
139 DumpInt(n, D);
140 for (i = 0; i < n; i++) {
141 DumpByte(f->upvalues[i].instack, D);
142 DumpByte(f->upvalues[i].idx, D);
143 }
144}

References DumpByte(), DumpInt(), Proto::sizeupvalues, and Proto::upvalues.

Referenced by DumpFunction().

◆ luaU_dump()

int luaU_dump ( lua_State * L,
const Proto * f,
lua_Writer w,
void * data,
int strip )

Definition at line 202 of file lua-5.3.6/src/ldump.c.

203 {
204 DumpState D;
205 D.L = L;
206 D.writer = w;
207 D.data = data;
208 D.strip = strip;
209 D.status = 0;
210 DumpHeader(&D);
211 DumpByte(f->sizeupvalues, &D);
212 DumpFunction(f, NULL, &D);
213 return D.status;
214}
static void DumpHeader(DumpState *D)

References DumpState::data, DumpByte(), DumpFunction(), DumpHeader(), DumpState::L, NULL, Proto::sizeupvalues, DumpState::status, DumpState::strip, and DumpState::writer.