Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lua: memory mapped file?

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

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

then loading and running it as:

file = loadfile("filename")
file()

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

like image 931
Euge Avatar asked Nov 28 '25 06:11

Euge


1 Answers

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
like image 63
Oliver Avatar answered Nov 29 '25 23:11

Oliver



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!