diff options
Diffstat (limited to 'src/lib_base.c')
-rw-r--r-- | src/lib_base.c | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/lib_base.c b/src/lib_base.c index cb2e244e..1c8816f0 100644 --- a/src/lib_base.c +++ b/src/lib_base.c | |||
@@ -19,6 +19,7 @@ | |||
19 | #include "lj_gc.h" | 19 | #include "lj_gc.h" |
20 | #include "lj_err.h" | 20 | #include "lj_err.h" |
21 | #include "lj_debug.h" | 21 | #include "lj_debug.h" |
22 | #include "lj_buf.h" | ||
22 | #include "lj_str.h" | 23 | #include "lj_str.h" |
23 | #include "lj_tab.h" | 24 | #include "lj_tab.h" |
24 | #include "lj_meta.h" | 25 | #include "lj_meta.h" |
@@ -406,10 +407,22 @@ LJLIB_CF(load) | |||
406 | GCstr *name = lj_lib_optstr(L, 2); | 407 | GCstr *name = lj_lib_optstr(L, 2); |
407 | GCstr *mode = lj_lib_optstr(L, 3); | 408 | GCstr *mode = lj_lib_optstr(L, 3); |
408 | int status; | 409 | int status; |
409 | if (L->base < L->top && (tvisstr(L->base) || tvisnumber(L->base))) { | 410 | if (L->base < L->top && |
410 | GCstr *s = lj_lib_checkstr(L, 1); | 411 | (tvisstr(L->base) || tvisnumber(L->base) || tvisbuf(L->base))) { |
412 | const char *s; | ||
413 | MSize len; | ||
414 | if (tvisbuf(L->base)) { | ||
415 | SBufExt *sbx = bufV(L->base); | ||
416 | s = sbx->r; | ||
417 | len = sbufxlen(sbx); | ||
418 | if (!name) name = &G(L)->strempty; /* Buffers are not NUL-terminated. */ | ||
419 | } else { | ||
420 | GCstr *str = lj_lib_checkstr(L, 1); | ||
421 | s = strdata(str); | ||
422 | len = str->len; | ||
423 | } | ||
411 | lua_settop(L, 4); /* Ensure env arg exists. */ | 424 | lua_settop(L, 4); /* Ensure env arg exists. */ |
412 | status = luaL_loadbufferx(L, strdata(s), s->len, strdata(name ? name : s), | 425 | status = luaL_loadbufferx(L, s, len, name ? strdata(name) : s, |
413 | mode ? strdata(mode) : NULL); | 426 | mode ? strdata(mode) : NULL); |
414 | } else { | 427 | } else { |
415 | lj_lib_checkfunc(L, 1); | 428 | lj_lib_checkfunc(L, 1); |