Lua: memory mapped file?

Do any of you know how to create a memory mapping file in Lua? I have a program that writes code in Lua. Now I want to execute the code without saving it to a file, but writing it to a "memory" file, and then I execute it directly from memory. But I did not find a way to do this. Now I am writing a file like this:

file:write(instruction..'\n')

then download and run it as:

file = loadfile("filename")
file()

Does anyone know how to write a file to memory or execute it from memory without saving it to disk?

+3
source share
1 answer

Use loadstring:

chunk = loadstring("return ..., 1+2, 'hi'")
assert(chunk)
a, b, c = chunk(123) -- you can call many times
print (a,b,c) -- prints 123     3      hi
+3
source

All Articles