| View previous topic :: View next topic |
| Author |
Message |
Sprak
Joined: 27 Sep 2005 Posts: 7 Location: Stockholm, Sweden
|
Posted: Mon Oct 03, 2005 5:57 am Post subject: dofile vs. require |
|
|
| 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. |
|
| Back to top |
|
 |
Durante
Joined: 02 Oct 2005 Posts: 65 Location: Austria
|
Posted: Tue Oct 04, 2005 11:27 pm Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
Sprak
Joined: 27 Sep 2005 Posts: 7 Location: Stockholm, Sweden
|
Posted: Thu Oct 06, 2005 5:13 am Post subject: |
|
|
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. |
|
| Back to top |
|
 |
|