diff options
Diffstat (limited to 'src/lib_string.c')
-rw-r--r-- | src/lib_string.c | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/lib_string.c b/src/lib_string.c index e54b2d50..5cbe6e4d 100644 --- a/src/lib_string.c +++ b/src/lib_string.c | |||
@@ -22,6 +22,7 @@ | |||
22 | #include "lj_tab.h" | 22 | #include "lj_tab.h" |
23 | #include "lj_state.h" | 23 | #include "lj_state.h" |
24 | #include "lj_ff.h" | 24 | #include "lj_ff.h" |
25 | #include "lj_bcdump.h" | ||
25 | #include "lj_char.h" | 26 | #include "lj_char.h" |
26 | #include "lj_lib.h" | 27 | #include "lj_lib.h" |
27 | 28 | ||
@@ -114,10 +115,24 @@ LJLIB_ASM_(string_upper) | |||
114 | 115 | ||
115 | /* ------------------------------------------------------------------------ */ | 116 | /* ------------------------------------------------------------------------ */ |
116 | 117 | ||
118 | static int writer_buf(lua_State *L, const void *p, size_t size, void *b) | ||
119 | { | ||
120 | luaL_addlstring((luaL_Buffer *)b, (const char *)p, size); | ||
121 | UNUSED(L); | ||
122 | return 0; | ||
123 | } | ||
124 | |||
117 | LJLIB_CF(string_dump) | 125 | LJLIB_CF(string_dump) |
118 | { | 126 | { |
119 | lj_err_caller(L, LJ_ERR_STRDUMP); | 127 | GCfunc *fn = lj_lib_checkfunc(L, 1); |
120 | return 0; /* unreachable */ | 128 | int strip = L->base+1 < L->top && tvistruecond(L->base+1); |
129 | luaL_Buffer b; | ||
130 | L->top = L->base+1; | ||
131 | luaL_buffinit(L, &b); | ||
132 | if (!isluafunc(fn) || lj_bcwrite(L, funcproto(fn), writer_buf, &b, strip)) | ||
133 | lj_err_caller(L, LJ_ERR_STRDUMP); | ||
134 | luaL_pushresult(&b); | ||
135 | return 1; | ||
121 | } | 136 | } |
122 | 137 | ||
123 | /* ------------------------------------------------------------------------ */ | 138 | /* ------------------------------------------------------------------------ */ |