Using luac5.1.exe is there anyway to pass it a string to create a binary file or does anyone know of any module that could create a syntax checked binary file, what I'm looking to do is create a settings file that can be loaded again by require.
2 Answers
Note that require loads lua source files or dynamic libraries. Yu might be better off with a custom loader if you really need binary data.
Two libraries that do this are Roberto's struct and lhf's lpack.
If you really want require then you could convert your binary data to strings, but since presumably that are userdata, you'll need a C function to translate the userdata to a Lua accessible type such as string or number.
Comments
Perhaps try this:
function compile(source,file)
io.open(file,"wb")
:write(string.dump(assert(loadstring(source,""))))
:close()
end
5 Comments
Egor Skriptunoff
Why full source text is also included into output file?
lhf
@EgorSkriptunoff, I've edited the code to remove the full source.
Col_Blimp
thanks for that but I get an error running it, test string is "test test test" error is [string ""]:1:"=" expected near "<eof>" and Im unsure what that means
Egor Skriptunoff
@Col_Blimp -
source should be valid chunk (i.e., function's body)lhf
@Col_Blimp, if you need better error handling, remove the assert and handle the return code from
loadstring.