Configuration files - loading and unloading

Get Help on scripting in POL with configurations, config setups, script trouble shooting, etc.
Post Reply
phao
Grandmaster Poster
Posts: 129
Joined: Fri Aug 31, 2007 2:25 pm

Configuration files - loading and unloading

Post 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?
Gnafu
Grandmaster Poster
Posts: 136
Joined: Thu Feb 02, 2006 7:29 am

Re: Configuration files - loading and unloading

Post 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.
phao
Grandmaster Poster
Posts: 129
Joined: Fri Aug 31, 2007 2:25 pm

Re: Configuration files - loading and unloading

Post 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
Post Reply