Open ped7g opened 11 months ago
This is a simple example to illustrates the issue above:
DEVICE ZXSPECTRUM48
ORG 32768
; three ways to detect length of a file using LUA
; 1. direct LUA (this works)
LUA PASS3
local f = io.open("macro_lua.asm", "rb")
local file_len = f:seek("end")
f.close(f)
print("'macro_lua.asm' is " .. file_len .. " bytes long")
ENDLUA
; 2. LUA inside of macro (this does not work)
MACRO LUA.FileLength1
LUA PASS3
local f = io.open("macro_lua.asm", "rb")
local file_len = f:seek("end")
f.close(f)
print("'macro_lua.asm' is " .. file_len .. " bytes long")
ENDLUA
ENDM
; LUA.FileLength1
; if line above is uncommented, the following error message is generated:
; macro_lua.asm(20): error: [LUA] attempt to call a nil value (global 'seek')
; macro_lua.asm(24): ^ emitted from here
; 3. a temporary work around for the above problem (it works)
MACRO LUA.FileLength2
LUA PASS3
local f = io.open("macro_lua.asm", "rb")
local file_len = f.seek(f, "end") --; explicit call to the class method avoids using colon
f.close(f)
print("'macro_lua.asm' is " .. file_len .. " bytes long")
ENDLUA
ENDM
LUA.FileLength2
(Please note that I assume that the whole of the above snippet of code is residing in a file named macro_lua.asm
).
v1.20.3 all platforms
when colon is used inside lua code which is defined inside macro, it doesn't work (probably the line gets split as macro parser is not sensitive to lua blocks).
Needs example, there is 7.4 in docs with colons, something similar, using same block of lua inside/outside of macro to verify the bug exists and to debug it (I'm too busy/lazy to write it now).