aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2004-07-09 15:24:41 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2004-07-09 15:24:41 -0300
commit4206d7ed6033764c81d97ccdc343f4defda516e6 (patch)
treed8a982a8001436bd0d534a1d5b7f9e319bcf52f4
parent7a796a0682e8d0a4e3798955f5db64255d9bd44d (diff)
downloadlua-4206d7ed6033764c81d97ccdc343f4defda516e6.tar.gz
lua-4206d7ed6033764c81d97ccdc343f4defda516e6.tar.bz2
lua-4206d7ed6033764c81d97ccdc343f4defda516e6.zip
`lua_Chunkwriter' returns 0 in case of success
-rw-r--r--ldump.c29
-rw-r--r--lstrlib.c6
2 files changed, 20 insertions, 15 deletions
diff --git a/ldump.c b/ldump.c
index d41082bd..2f5609c1 100644
--- a/ldump.c
+++ b/ldump.c
@@ -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
22typedef struct { 22typedef 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
29static void DumpBlock(const void* b, size_t size, DumpState* D) 30static 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
36static void DumpByte(int y, DumpState* D) 40static 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
57static void DumpString(TString* s, DumpState* D) 61static 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*/
159int luaU_dump (lua_State* L, const Proto* Main, lua_Chunkwriter w, void* data, int strip) 163int 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}
diff --git a/lstrlib.c b/lstrlib.c
index 502ea814..2e88f6e7 100644
--- a/lstrlib.c
+++ b/lstrlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstrlib.c,v 1.102 2004/04/30 20:13:38 roberto Exp roberto $ 2** $Id: lstrlib.c,v 1.103 2004/06/08 14:31:15 roberto Exp roberto $
3** Standard library for string operations and pattern-matching 3** Standard library for string operations and pattern-matching
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -133,7 +133,7 @@ static int str_char (lua_State *L) {
133static int writer (lua_State *L, const void* b, size_t size, void* B) { 133static int writer (lua_State *L, const void* b, size_t size, void* B) {
134 (void)L; 134 (void)L;
135 luaL_addlstring((luaL_Buffer*) B, (const char *)b, size); 135 luaL_addlstring((luaL_Buffer*) B, (const char *)b, size);
136 return 1; 136 return 0;
137} 137}
138 138
139 139
@@ -142,7 +142,7 @@ static int str_dump (lua_State *L) {
142 luaL_checktype(L, 1, LUA_TFUNCTION); 142 luaL_checktype(L, 1, LUA_TFUNCTION);
143 lua_settop(L, 1); 143 lua_settop(L, 1);
144 luaL_buffinit(L,&b); 144 luaL_buffinit(L,&b);
145 if (!lua_dump(L, writer, &b)) 145 if (lua_dump(L, writer, &b) != 0)
146 luaL_error(L, "unable to dump given function"); 146 luaL_error(L, "unable to dump given function");
147 luaL_pushresult(&b); 147 luaL_pushresult(&b);
148 return 1; 148 return 1;