Added suport for Fixed Buffers

A fixed buffer keeps a binary chunk "forever", so that the program
does not need to copy some of its parts when loading it.
This commit is contained in:
Roberto Ierusalimschy
2023-09-05 15:30:45 -03:00
parent f33cda8d6e
commit 14e416355f
12 changed files with 160 additions and 34 deletions

View File

@@ -337,9 +337,20 @@ static int load_aux (lua_State *L, int status, int envidx) {
}
static const char *getmode (lua_State *L, int idx) {
const char *mode = luaL_optstring(L, idx, "bt");
int i = 0;
if (mode[i] == 'b') i++;
if (mode[i] == 't') i++;
if (mode[i] != '\0')
luaL_argerror(L, idx, "invalid mode");
return mode;
}
static int luaB_loadfile (lua_State *L) {
const char *fname = luaL_optstring(L, 1, NULL);
const char *mode = luaL_optstring(L, 2, NULL);
const char *mode = getmode(L, 2);
int env = (!lua_isnone(L, 3) ? 3 : 0); /* 'env' index or 0 if no 'env' */
int status = luaL_loadfilex(L, fname, mode);
return load_aux(L, status, env);
@@ -388,7 +399,7 @@ static int luaB_load (lua_State *L) {
int status;
size_t l;
const char *s = lua_tolstring(L, 1, &l);
const char *mode = luaL_optstring(L, 3, "bt");
const char *mode = getmode(L, 3);
int env = (!lua_isnone(L, 4) ? 4 : 0); /* 'env' index or 0 if no 'env' */
if (s != NULL) { /* loading a string? */
const char *chunkname = luaL_optstring(L, 2, s);