'lua_load' has an extra argument 'mode'
This commit is contained in:
37
lauxlib.c
37
lauxlib.c
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lauxlib.c,v 1.235 2011/11/09 19:08:55 roberto Exp roberto $
|
||||
** $Id: lauxlib.c,v 1.236 2011/11/14 17:10:24 roberto Exp roberto $
|
||||
** Auxiliary functions for building Lua libraries
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@@ -592,16 +592,6 @@ static int errfile (lua_State *L, const char *what, int fnameindex) {
|
||||
}
|
||||
|
||||
|
||||
static int checkmode (lua_State *L, const char *mode, const char *x) {
|
||||
if (mode && strchr(mode, x[0]) == NULL) {
|
||||
lua_pushfstring(L,
|
||||
"attempt to load a %s chunk (mode is " LUA_QS ")", x, mode);
|
||||
return LUA_ERRFILE;
|
||||
}
|
||||
else return LUA_OK;
|
||||
}
|
||||
|
||||
|
||||
static int skipBOM (LoadF *lf) {
|
||||
const char *p = "\xEF\xBB\xBF"; /* Utf8 BOM mark */
|
||||
int c;
|
||||
@@ -651,23 +641,14 @@ LUALIB_API int luaL_loadfilex (lua_State *L, const char *filename,
|
||||
}
|
||||
if (skipcomment(&lf, &c)) /* read initial portion */
|
||||
lf.buff[lf.n++] = '\n'; /* add line to correct line numbers */
|
||||
if (c == LUA_SIGNATURE[0]) { /* binary file? */
|
||||
if ((status = checkmode(L, mode, "binary")) != LUA_OK)
|
||||
goto closefile;
|
||||
if (filename) {
|
||||
lf.f = freopen(filename, "rb", lf.f); /* reopen in binary mode */
|
||||
if (lf.f == NULL) return errfile(L, "reopen", fnameindex);
|
||||
skipcomment(&lf, &c); /* re-read initial portion */
|
||||
}
|
||||
}
|
||||
else { /* text file */
|
||||
if ((status = checkmode(L, mode, "text")) != LUA_OK)
|
||||
goto closefile;
|
||||
if (c == LUA_SIGNATURE[0] && filename) { /* binary file? */
|
||||
lf.f = freopen(filename, "rb", lf.f); /* reopen in binary mode */
|
||||
if (lf.f == NULL) return errfile(L, "reopen", fnameindex);
|
||||
skipcomment(&lf, &c); /* re-read initial portion */
|
||||
}
|
||||
if (c != EOF)
|
||||
lf.buff[lf.n++] = c; /* 'c' is the first character of the stream */
|
||||
status = lua_load(L, getF, &lf, lua_tostring(L, -1));
|
||||
closefile:
|
||||
status = lua_load(L, getF, &lf, lua_tostring(L, -1), mode);
|
||||
readstatus = ferror(lf.f);
|
||||
if (filename) fclose(lf.f); /* close file (even in case of errors) */
|
||||
if (readstatus) {
|
||||
@@ -695,12 +676,12 @@ static const char *getS (lua_State *L, void *ud, size_t *size) {
|
||||
}
|
||||
|
||||
|
||||
LUALIB_API int luaL_loadbuffer (lua_State *L, const char *buff, size_t size,
|
||||
const char *name) {
|
||||
LUALIB_API int luaL_loadbufferx (lua_State *L, const char *buff, size_t size,
|
||||
const char *name, const char *mode) {
|
||||
LoadS ls;
|
||||
ls.s = buff;
|
||||
ls.size = size;
|
||||
return lua_load(L, getS, &ls, name);
|
||||
return lua_load(L, getS, &ls, name, mode);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user