Page 1 of 1

Configuration files - loading and unloading

Posted: Sun Jan 10, 2010 7:12 pm
by phao
According to what I've read in the UnloadConfigFile() description, when I open a file, it's reference becomes available globally (if a script has access to the reference, it may get data from the config file).

Based on that. I've made a set of wrapper functions to handle config file openning and realoding.

Code: Select all

use uo;
use cfgfile;

function GetConfigFileRef(cf_prop, file_string)
	var r := GetGlobalProperty(cf_prop);

	if(r == error)
		r:= ReadConfigFile(file_string);
		SetGlobalProperty(cf_prop, r);
	endif

	return r;
endfunction

function ForceConfigFileReload(cf_prop, file_string)
	UnloadConfigFile(file_string);
	SetGlobalProperty(cf_prop, error);
endfunction
Basically, GetConfigFileRef is going to get a config file ref for the file passed as argument and store it in a global prop. It'll also return that reference.

ForceConfigFileReload is going to unload that config file and make an error to be placed at the global prop so that GetConfigFileRef gets a new reference next time it's called.

I did this to avoid unnecessary reloading of config files. This seems too good. But... Are there problems? I mean, is there anything that could go wrong by doing this?

Another question. What happens if I call ReadConfigFile() more than once for the same file?

Re: Configuration files - loading and unloading

Posted: Mon Jan 11, 2010 4:00 am
by Gnafu
Very good question.
Maybe the POL does the check you wrote when a cfg file is requested; in case it doesn't, it's a very good idea.

Re: Configuration files - loading and unloading

Posted: Mon Jan 11, 2010 8:56 am
by phao
[14:46] <phao> Turley,
[14:46] <phao> can you take a look at this http://forums.polserver.com/viewtopic.p ... 13&p=15488 ?
[14:47] <CrazyMan> Phao, config file loads into memory just one time
[14:47] <CrazyMan> All other ReadConfigFile does not load it again
[14:48] <CrazyMan> And config will be in memory until you will unload it.
[14:48] * Tomi has quit (Exit: Quit)
[14:53] <Turley> jep no need to script such a wrapper
[14:53] <Turley> its basically exactly what the core does