lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


lua_dofile (which is deprecated IIRC) is not what you want to use if you wish to cache scripts.
Lookup lua_loadfile.
 
Compare the docs on lua_loadfile to those for lua_dofile.
The basic gist is that lua_dofile calls lua_loadfile to "cache" the script and then runs the script and "throws it away".  That's a slight oversimplification and a poor way of expressing it, but <I think> that is the "translation" to your current outlook.
 
Then go back and read the code suggested by lhf.  He wrote this code in Lua, but turning it into C code calling the API is fairly straightforward.
 
Lua does not "cache" scripts by default because that could be functionally incorrect (i.e. it assumes that the files don't change and that is not an assumption that Lua itself should be making).
-----Original Message-----
From: lua-bounces@bazar2.conectiva.com.br [mailto:lua-bounces@bazar2.conectiva.com.br]On Behalf Of sohyl siddiqui
Sent: Monday, March 22, 2004 3:22 PM
To: lua@bazar2.conectiva.com.br
Subject: Re: question regarding caching of scripts

hi ppl,
first of all sorry for the late reply but i was caught up in work ...... thanks for the help ..... but i am still learning Lua and hence i didn't completely understand your replies.
i will try to explain what i am doing in my program.
first i open a single lua state, which is used throughout the program,  using:

m_pLUAState = lua_open();

then i initialize other things needed and register with Lua the C++ functions that i want to export to my scripts:

lua_register(LUAPtr, FuncNAme, FuncPtr);

then i simply call a script file, which is a simple local text file, using:

lua_dofile(m_pLUAState, Filename );

now what i think happens is that each time lua_dofile is called internally lua opens the file, loads it, parses it etc etc. and then closes it upon returning.

the question that i had (if the assumption above is correct, plz verify this) is since lua already opened and loaded a file once it should not do this again if the same script was called.

is there a way to manage this in a simple and efficient manner? or prefably if lua could do this on its own end.

thanks in advance,

sohyl.

P.S. comments wuold be really helpful if you suggest some code.

 

Do you Yahoo!?
Yahoo! Finance Tax Center - File online. File on time.