dofile vs. require

Discuss using and improving Lua and the Lua Player specific to the PSP.

Moderators: Shine, Insert_witty_name

Post Reply
Sprak
Posts: 7
Joined: Tue Sep 27, 2005 7:26 pm
Location: Stockholm, Sweden
Contact:

dofile vs. require

Post by Sprak »

A small thing I noticed when using require (for example: require "monkey"; to include monkey.lua into the script). Luaplayer loads the file 'required' and then probably caches it, since any further changes in monkey.lua won't be reflected on subsequent loads of the main lua file (unless you restart luaplayer). However, if you use dofile("monkey.lua") instead, it loads the file anew upon execution.
Durante
Posts: 65
Joined: Sun Oct 02, 2005 6:07 am
Location: Austria

Post by Durante »

That's because "require" is intended for libraries and should therefore only load each required file one time. More about dofile vs. require is in one of the early chapters of the book.
Sprak
Posts: 7
Joined: Tue Sep 27, 2005 7:26 pm
Location: Stockholm, Sweden
Contact:

Post by Sprak »

Yeah, but how does that fit into loading only once even if you restart the application using the library? I totally understand the logic in only loading it once per session, but it feels like more of a cache error than "feature".
Sheesh, that book (Programming in Lua)... With fear of derailing this thread, it's not really written for people not used to Lua, even though that probably was the ambition from the outset. This page however has proven to be my best friend in grasping the intricacies of the whole thing.
Post Reply