summaryrefslogtreecommitdiffstats
path: root/mbbsd
diff options
context:
space:
mode:
authorkcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2008-01-11 23:51:06 +0800
committerkcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2008-01-11 23:51:06 +0800
commit89443698a9cf7c2b708b154f57449baa96e42a94 (patch)
tree4b9c63bafe7d8826858c0d0f0e998514a1b4b32f /mbbsd
parente7fef1f83a6c2f397dacc520a07d8578d2551b44 (diff)
downloadpttbbs-89443698a9cf7c2b708b154f57449baa96e42a94.tar
pttbbs-89443698a9cf7c2b708b154f57449baa96e42a94.tar.gz
pttbbs-89443698a9cf7c2b708b154f57449baa96e42a94.tar.bz2
pttbbs-89443698a9cf7c2b708b154f57449baa96e42a94.tar.lz
pttbbs-89443698a9cf7c2b708b154f57449baa96e42a94.tar.xz
pttbbs-89443698a9cf7c2b708b154f57449baa96e42a94.tar.zst
pttbbs-89443698a9cf7c2b708b154f57449baa96e42a94.zip
- bbslua: correct line number in file.
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@3821 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'mbbsd')
-rw-r--r--mbbsd/bbslua.c41
1 files changed, 38 insertions, 3 deletions
diff --git a/mbbsd/bbslua.c b/mbbsd/bbslua.c
index 76b01451..9938cca8 100644
--- a/mbbsd/bbslua.c
+++ b/mbbsd/bbslua.c
@@ -756,10 +756,11 @@ bbslua_isHeader(const char *ps, const char *pe)
}
static int
-bbslua_detect_range(char **pbs, char **pbe)
+bbslua_detect_range(char **pbs, char **pbe, int *lineshift)
{
int szsig = strlen(BBSLUA_SIGNATURE);
char *bs, *be, *ps, *pe;
+ int line = 0;
bs = ps = *pbs;
be = pe = *pbe;
@@ -771,7 +772,9 @@ bbslua_detect_range(char **pbs, char **pbe)
break;
// else, skip to next line
while (ps + szsig < pe && *ps++ != '\n');
+ line++;
}
+ *lineshift = line;
if (!(ps + szsig < pe))
return 0;
@@ -991,6 +994,37 @@ bbslua_logo(lua_State *L)
lua_pop(L, 1);
}
+typedef struct LoadS {
+ const char *s;
+ size_t size;
+ int lineshift;
+} LoadS;
+
+static const char* bbslua_reader(lua_State *L, void *ud, size_t *size)
+{
+ LoadS *ls = (LoadS *)ud;
+ (void)L;
+ if (ls->size == 0) return NULL;
+ if (ls->lineshift > 0) {
+ const char *linefeed = "\n";
+ *size = 1;
+ ls->lineshift--;
+ return linefeed;
+ }
+ *size = ls->size;
+ ls->size = 0;
+ return ls->s;
+}
+
+static int bbslua_loadbuffer (lua_State *L, const char *buff, size_t size,
+ const char *name, int lineshift) {
+ LoadS ls;
+ ls.s = buff;
+ ls.size = size;
+ ls.lineshift = lineshift;
+ return lua_load(L, bbslua_reader, &ls, name);
+}
+
int
bbslua(const char *fpath)
{
@@ -998,6 +1032,7 @@ bbslua(const char *fpath)
lua_State *L = lua_open();
char *bs, *ps, *pe;
int sz = 0;
+ int lineshift;
unsigned int prevmode = getutmpmode();
// re-entrant not supported!
@@ -1013,7 +1048,7 @@ bbslua(const char *fpath)
ps = bs;
pe = ps + sz;
- if(!bbslua_detect_range(&ps, &pe))
+ if(!bbslua_detect_range(&ps, &pe, &lineshift))
{
// not detected
bbslua_detach(bs, sz);
@@ -1029,7 +1064,7 @@ bbslua(const char *fpath)
bbslua_load_TOC(L, ps, pe);
// load script
- r = luaL_loadbuffer(L, ps, pe-ps, "BBS-Lua");
+ r = bbslua_loadbuffer(L, ps, pe-ps, "BBS-Lua", lineshift);
// unmap
bbslua_detach(bs, sz);