lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 16-08-20 05:41 PM, nobody wrote:
> On 2016-08-20 23:09, Satoru Kawahara wrote:
>> Hello,
>>
>> I tried to copy luac.out into a script file as string and run the native
>> code string with `load()`.
>
> Did you use a literal/long string ([[...]])?  It seems to normalize all
> line endings (0d0a / \r\n --> 0a / \n), thereby breaking it.
>
> ...
In short, lua long strings syntax is not suitable for storing binary data.

Read .out file to string directly as binary file or encode binary data
before saving it.


Fmm, Thank you.
But I WANT to embed the bytecode to the script, then I did like:
```
{
local str;str=""
while read -s line; do
str+=${line}
done < <(hexdump -e '"%02X"' test.out)
echo "local str_byte = '"'${str//\*/}'"' >> script.lua
}
```

```
local bin = ""
for c in str_byte:gmatch("..") do
  bin = bin .. ("0x"..c):char()
end

local fn = load(bin)
......
```

BTW, why does the binary modification occur?

--
Kawahara Satoru
College of Information Science
University of Tsukuba