简体   繁体   中英

Lua - serialize functions without loadstring?

在lua中,是否可以序列化函数(没有upvalues)并存储它们而不使用LOADSTRING

You can serialize and store them without loadstring at all - use string.dump . You will only need loadstring if 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 loadstring at all, you can try to write Lua VM in Lua. That'd be harder task than a simple converter, but still pretty doable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM