You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm working with a Lua script that requires binary data be written/read in string form (the io functions are operating on binary files). I cannot change this as I'm required to be backwards compatible with existing scripts. How do I register a function on the NLua context such that a byte[] is returned as a Lua string and not a System.Byte[]?
I cannot modify the extant Lua scripts, so using string.char is not an option for me.
Here's the script I'm working with:
if ReadInt(continue+0xC)~= prevContinue and ReadByte(0x711438-offset2)==0 and blacklisted == false then
local f= io.open("KH2autosave.dat","wb")
f:write(ReadString(continue,0x10FC0))
f:close()
ConsolePrint("Wrote autosave")
end
I am expected to implement ReadString. It must be able to:
Read binary data from address 0x10FC0 from a byte buffer (not valid UTF-8 data, which is why using string will not work)
Report that binary data to the Lua side as a Lua string for use with f:write
I can't write a test case for this unless the behavior of returning a byte[] from Lua#RegisterFunction should be changed to be Translated as a Lua string.
Here's the other side of the code, which can actually accept a byte[] due to the Translator supporting Lua string → C# byte[]:
localf= io.open("KH2autosave.dat","rb")
if f ~= nil then
WriteString(save1, f:read("*a"))
f:close()
ConsolePrint("Loaded autosave")
end
I'm working with a Lua script that requires binary data be written/read in string form (the
io
functions are operating on binary files). I cannot change this as I'm required to be backwards compatible with existing scripts. How do I register a function on the NLua context such that abyte[]
is returned as a Lua string and not aSystem.Byte[]
?This data is not valid UTF-8 and as such will not survive a
raw → UTF16 → UTF8
roundtrip.The text was updated successfully, but these errors were encountered: