In lua, is it possible to serialize functions (without upvalues) and store them WITHOUT USING LOADSTRING ?
In lua, is it possible to serialize functions (without upvalues) and store them WITHOUT
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can serialize and store them without
loadstringat all – usestring.dump. You will only needloadstringif you want to deserealize them back.If you need it to reuse actual function later, (and not for some other simple purpose, like comparing), you will still need access to at least string version of
loadstring, because that’s the only facility that allows you to evaluate Lua source on the fly.If you have it, you may either try:
1) If you have access, modify Lua engine itself to save source code of function definition somewhere.
2) Write Lua bytecode to Lua source converter in Lua. With Lua’s simple VM it is not as hard task as it may sound.
If you have absolutely no access to
loadstringat all, you can try to write Lua VM in Lua. That’d be harder task than a simple converter, but still pretty doable.