mirror of
https://github.com/lua/lua
synced 2025-03-21 13:12:55 +03:00
dumping and undumping integers
This commit is contained in:
parent
c37b7b3cca
commit
eee51492e2
20
ldump.c
20
ldump.c
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: ldump.c,v 2.17 2012/01/23 23:02:10 roberto Exp roberto $
|
** $Id: ldump.c,v 2.18 2013/04/12 19:07:09 roberto Exp roberto $
|
||||||
** save precompiled Lua chunks
|
** save precompiled Lua chunks
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@ -52,6 +52,11 @@ static void DumpNumber(lua_Number x, DumpState* D)
|
|||||||
DumpVar(x,D);
|
DumpVar(x,D);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void DumpInteger(lua_Integer x, DumpState* D)
|
||||||
|
{
|
||||||
|
DumpVar(x,D);
|
||||||
|
}
|
||||||
|
|
||||||
static void DumpVector(const void* b, int n, size_t size, DumpState* D)
|
static void DumpVector(const void* b, int n, size_t size, DumpState* D)
|
||||||
{
|
{
|
||||||
DumpInt(n,D);
|
DumpInt(n,D);
|
||||||
@ -84,18 +89,21 @@ static void DumpConstants(const Proto* f, DumpState* D)
|
|||||||
for (i=0; i<n; i++)
|
for (i=0; i<n; i++)
|
||||||
{
|
{
|
||||||
const TValue* o=&f->k[i];
|
const TValue* o=&f->k[i];
|
||||||
DumpChar(ttnov(o),D);
|
DumpChar(ttype(o),D);
|
||||||
switch (ttnov(o))
|
switch (ttype(o))
|
||||||
{
|
{
|
||||||
case LUA_TNIL:
|
case LUA_TNIL:
|
||||||
break;
|
break;
|
||||||
case LUA_TBOOLEAN:
|
case LUA_TBOOLEAN:
|
||||||
DumpChar(bvalue(o),D);
|
DumpChar(bvalue(o),D);
|
||||||
break;
|
break;
|
||||||
case LUA_TNUMBER:
|
case LUA_TNUMFLT:
|
||||||
DumpNumber(nvalue(o),D);
|
DumpNumber(fltvalue(o),D);
|
||||||
break;
|
break;
|
||||||
case LUA_TSTRING:
|
case LUA_TNUMINT:
|
||||||
|
DumpInteger(ivalue(o),D);
|
||||||
|
break;
|
||||||
|
case LUA_TSHRSTR: case LUA_TLNGSTR:
|
||||||
DumpString(rawtsvalue(o),D);
|
DumpString(rawtsvalue(o),D);
|
||||||
break;
|
break;
|
||||||
default: lua_assert(0);
|
default: lua_assert(0);
|
||||||
|
16
lundump.c
16
lundump.c
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: lundump.c,v 2.21 2012/03/19 22:58:09 roberto Exp roberto $
|
** $Id: lundump.c,v 2.22 2012/05/08 13:53:33 roberto Exp roberto $
|
||||||
** load precompiled Lua chunks
|
** load precompiled Lua chunks
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@ -69,6 +69,13 @@ static lua_Number LoadNumber(LoadState* S)
|
|||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static lua_Integer LoadInteger(LoadState* S)
|
||||||
|
{
|
||||||
|
lua_Integer x;
|
||||||
|
LoadVar(S,x);
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
static TString* LoadString(LoadState* S)
|
static TString* LoadString(LoadState* S)
|
||||||
{
|
{
|
||||||
size_t size;
|
size_t size;
|
||||||
@ -112,10 +119,13 @@ static void LoadConstants(LoadState* S, Proto* f)
|
|||||||
case LUA_TBOOLEAN:
|
case LUA_TBOOLEAN:
|
||||||
setbvalue(o,LoadChar(S));
|
setbvalue(o,LoadChar(S));
|
||||||
break;
|
break;
|
||||||
case LUA_TNUMBER:
|
case LUA_TNUMFLT:
|
||||||
setnvalue(o,LoadNumber(S));
|
setnvalue(o,LoadNumber(S));
|
||||||
break;
|
break;
|
||||||
case LUA_TSTRING:
|
case LUA_TNUMINT:
|
||||||
|
setivalue(o,LoadInteger(S));
|
||||||
|
break;
|
||||||
|
case LUA_TSHRSTR: case LUA_TLNGSTR:
|
||||||
setsvalue2n(S->L,o,LoadString(S));
|
setsvalue2n(S->L,o,LoadString(S));
|
||||||
break;
|
break;
|
||||||
default: lua_assert(0);
|
default: lua_assert(0);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user