diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2004-07-09 15:24:41 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2004-07-09 15:24:41 -0300 |
commit | 4206d7ed6033764c81d97ccdc343f4defda516e6 (patch) | |
tree | d8a982a8001436bd0d534a1d5b7f9e319bcf52f4 /ldump.c | |
parent | 7a796a0682e8d0a4e3798955f5db64255d9bd44d (diff) | |
download | lua-4206d7ed6033764c81d97ccdc343f4defda516e6.tar.gz lua-4206d7ed6033764c81d97ccdc343f4defda516e6.tar.bz2 lua-4206d7ed6033764c81d97ccdc343f4defda516e6.zip |
`lua_Chunkwriter' returns 0 in case of success
Diffstat (limited to 'ldump.c')
-rw-r--r-- | ldump.c | 29 |
1 files changed, 17 insertions, 12 deletions
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldump.c,v 2.1 2003/12/10 12:13:36 roberto Exp roberto $ | 2 | ** $Id: ldump.c,v 1.7 2004/06/09 21:03:53 lhf Exp lhf $ |
3 | ** save bytecodes | 3 | ** save pre-compiled Lua chunks |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
6 | 6 | ||
@@ -21,16 +21,20 @@ | |||
21 | 21 | ||
22 | typedef struct { | 22 | typedef struct { |
23 | lua_State* L; | 23 | lua_State* L; |
24 | lua_Chunkwriter write; | 24 | lua_Chunkwriter writer; |
25 | void* data; | 25 | void* data; |
26 | int strip; | 26 | int strip; |
27 | int status; | ||
27 | } DumpState; | 28 | } DumpState; |
28 | 29 | ||
29 | static void DumpBlock(const void* b, size_t size, DumpState* D) | 30 | static void DumpBlock(const void* b, size_t size, DumpState* D) |
30 | { | 31 | { |
31 | lua_unlock(D->L); | 32 | if (D->status==0) |
32 | (*D->write)(D->L,b,size,D->data); | 33 | { |
33 | lua_lock(D->L); | 34 | lua_unlock(D->L); |
35 | D->status=(*D->writer)(D->L,b,size,D->data); | ||
36 | lua_lock(D->L); | ||
37 | } | ||
34 | } | 38 | } |
35 | 39 | ||
36 | static void DumpByte(int y, DumpState* D) | 40 | static void DumpByte(int y, DumpState* D) |
@@ -54,7 +58,7 @@ static void DumpNumber(lua_Number x, DumpState* D) | |||
54 | DumpBlock(&x,sizeof(x),D); | 58 | DumpBlock(&x,sizeof(x),D); |
55 | } | 59 | } |
56 | 60 | ||
57 | static void DumpString(TString* s, DumpState* D) | 61 | static void DumpString(const TString* s, DumpState* D) |
58 | { | 62 | { |
59 | if (s==NULL || getstr(s)==NULL) | 63 | if (s==NULL || getstr(s)==NULL) |
60 | DumpSize(0,D); | 64 | DumpSize(0,D); |
@@ -154,16 +158,17 @@ static void DumpHeader(DumpState* D) | |||
154 | } | 158 | } |
155 | 159 | ||
156 | /* | 160 | /* |
157 | ** dump function as precompiled chunk | 161 | ** dump Lua function as precompiled chunk |
158 | */ | 162 | */ |
159 | int luaU_dump (lua_State* L, const Proto* Main, lua_Chunkwriter w, void* data, int strip) | 163 | int luaU_dump (lua_State* L, const Proto* f, lua_Chunkwriter w, void* data, int strip) |
160 | { | 164 | { |
161 | DumpState D; | 165 | DumpState D; |
162 | D.L=L; | 166 | D.L=L; |
163 | D.write=w; | 167 | D.writer=w; |
164 | D.data=data; | 168 | D.data=data; |
165 | D.strip=strip; | 169 | D.strip=strip; |
170 | D.status=0; | ||
166 | DumpHeader(&D); | 171 | DumpHeader(&D); |
167 | DumpFunction(Main,NULL,&D); | 172 | DumpFunction(f,NULL,&D); |
168 | return 1; | 173 | return D.status; |
169 | } | 174 | } |