0

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 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

1

Perhaps try this:

function compile(source,file)
   io.open(file,"wb")
     :write(string.dump(assert(loadstring(source,""))))
     :close()
end

5 Comments

Why full source text is also included into output file?
@EgorSkriptunoff, I've edited the code to remove the full source.
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
@Col_Blimp - source should be valid chunk (i.e., function's body)
@Col_Blimp, if you need better error handling, remove the assert and handle the return code from loadstring.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.