mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-11-11 07:11:39 +00:00
LunaCON: fix Lua->CON line translation by recreating the line info, too.
git-svn-id: https://svn.eduke32.com/eduke32@3790 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
e1715a7683
commit
38d12b9441
3 changed files with 60 additions and 28 deletions
|
@ -1661,17 +1661,17 @@ G_.projectile = projectile
|
|||
G_.g_tile = g_tile
|
||||
|
||||
|
||||
---=== Lunatic interpreter setup ===---
|
||||
---=== Lunatic translator setup ===---
|
||||
|
||||
local concode
|
||||
read_into_string = readintostr_mod -- for lunacon
|
||||
local lunacon = require("lunacon")
|
||||
|
||||
local concode, lineinfo
|
||||
local g_firstRun = (ffiC.g_elCONSize == 0)
|
||||
|
||||
--- Get Lua code for CON (+ mutator) code.
|
||||
if (g_firstRun) then
|
||||
-- Compiling CON for the first time.
|
||||
read_into_string = readintostr_mod -- for lunacon
|
||||
local lunacon = require("lunacon")
|
||||
|
||||
local confn = { ffi.string(ffiC.G_ConFile()) }
|
||||
|
||||
local nummods = ffiC.g_scriptModulesNum
|
||||
|
@ -1683,7 +1683,6 @@ if (g_firstRun) then
|
|||
end
|
||||
end
|
||||
|
||||
local lineinfo
|
||||
concode, lineinfo = lunacon.compile(confn)
|
||||
|
||||
if (concode == nil) then
|
||||
|
@ -1697,6 +1696,12 @@ if (g_firstRun) then
|
|||
else
|
||||
-- CON was already compiled.
|
||||
concode = ffi.string(ffiC.g_elCON, ffiC.g_elCONSize)
|
||||
lineinfo = lunacon.get_lineinfo(concode)
|
||||
end
|
||||
|
||||
if (ffiC._DEBUG_LUNATIC ~= 0) then
|
||||
-- XXX: lineinfo of 2nd up time has one line less.
|
||||
printf("CON line info has %d Lua lines", #lineinfo.llines)
|
||||
end
|
||||
|
||||
do
|
||||
|
|
|
@ -3076,37 +3076,62 @@ local lineinfo_mt = {
|
|||
__metatable = true,
|
||||
}
|
||||
|
||||
-- Handle a line of translated CON->Lua code. Return its CON line number.
|
||||
local function lineinfo_handle_line(i, code, curline, curfile, lfiles)
|
||||
local lnumstr = code:match("%-%-([0-9]+)$")
|
||||
local begfn = lnumstr and nil or code:match("^%-%- BEGIN (.+)$")
|
||||
local endfn = lnumstr and nil or code:match("^%-%- END (.+)$")
|
||||
|
||||
if (lnumstr) then
|
||||
curline[#curline] = assert(tonumber(lnumstr))
|
||||
elseif (begfn) then
|
||||
curfile[#curfile+1] = begfn
|
||||
curline[#curline+1] = 1
|
||||
-- Begin an included file.
|
||||
lfiles[#lfiles+1] = { line=i, name=begfn }
|
||||
elseif (endfn) then
|
||||
assert(endfn==curfile[#curfile]) -- assert proper nesting
|
||||
curfile[#curfile] = nil
|
||||
curline[#curline] = nil
|
||||
-- End an included file, so reset the name to the includer's one.
|
||||
lfiles[#lfiles+1] = { line=i, name=curfile[#curfile] }
|
||||
end
|
||||
|
||||
return assert(curline[#curline])
|
||||
end
|
||||
|
||||
-- Construct Lua->CON line mapping info. This walks the generated code and
|
||||
-- looks for our inserted comment strings, so it's kind of hackish.
|
||||
local function get_lineinfo(flatcode)
|
||||
function get_lineinfo(flatcode)
|
||||
local curline, curfile = { 0 }, { "<none>" } -- stacks
|
||||
-- llines: [<Lua code line number>] = <CON code line number>
|
||||
-- lfiles: [<sequence number>] = { line=<Lua line number>, name=<filename> }
|
||||
local llines, lfiles = {}, {}
|
||||
|
||||
for i=1,#flatcode do
|
||||
local code = flatcode[i]
|
||||
|
||||
local lnumstr = code:match("%-%-([0-9]+)$")
|
||||
local begfn = lnumstr and nil or code:match("^%-%- BEGIN (.+)$")
|
||||
local endfn = lnumstr and nil or code:match("^%-%- END (.+)$")
|
||||
|
||||
if (lnumstr) then
|
||||
curline[#curline] = assert(tonumber(lnumstr))
|
||||
elseif (begfn) then
|
||||
curfile[#curfile+1] = begfn
|
||||
curline[#curline+1] = 1
|
||||
-- Begin an included file.
|
||||
lfiles[#lfiles+1] = { line=i, name=begfn }
|
||||
elseif (endfn) then
|
||||
assert(endfn==curfile[#curfile]) -- assert proper nesting
|
||||
curfile[#curfile] = nil
|
||||
curline[#curline] = nil
|
||||
-- End an included file, so reset the name to the includer's one.
|
||||
lfiles[#lfiles+1] = { line=i, name=curfile[#curfile] }
|
||||
if (type(flatcode)=="table") then
|
||||
for i=1,#flatcode do
|
||||
llines[i] = lineinfo_handle_line(i, flatcode[i], curline, curfile, lfiles)
|
||||
end
|
||||
else
|
||||
-- Already concat'ed code given.
|
||||
assert(type(flatcode)=="string")
|
||||
local olinestart = 1
|
||||
|
||||
llines[i] = assert(curline[#curline])
|
||||
for i=1,math.huge do
|
||||
local curnli = flatcode:find("\n", olinestart, true)
|
||||
local line
|
||||
|
||||
if (curnli ~= nil) then
|
||||
line = flatcode:sub(olinestart, curnli-1)
|
||||
olinestart = curnli+1
|
||||
else
|
||||
-- Last line
|
||||
line = flatcode:sub(olinestart, -1)
|
||||
break
|
||||
end
|
||||
|
||||
llines[i] = lineinfo_handle_line(i, line, curline, curfile, lfiles)
|
||||
end
|
||||
end
|
||||
|
||||
return setmetatable({ llines=llines, lfiles=lfiles }, lineinfo_mt)
|
||||
|
|
|
@ -397,6 +397,8 @@ void El_DestroyState(L_State *estate)
|
|||
{
|
||||
L_DestroyState(estate);
|
||||
|
||||
g_tweakTracebackMsg = 0;
|
||||
|
||||
// XXX: It would be cleaner to also clear stuff like g_elEvents[], but
|
||||
// currently, when the game Lua state is recreated, the array should have
|
||||
// the same values as before, so we're skipping that for now.
|
||||
|
|
Loading…
Reference in a new issue