What is the difference with dofile, loadfile and loadstring(file:read()())?

Viewed 459

Would there be any performance boost from using one of the function. Is there a internal difference from using these two function, if so what are they.

1 Answers

dofile, loadfile and loadstring all call the same primitive to parse scripts.

I assume you mean loadstring(file:read("*a")). In this case, there may be a small performance hit (which I haven't measured) because Lua has to store the whole contents of the file as a string. The primitive that parses scripts does not do that: it reads the input in pieces.

Related