Fixed having register_functions from latest loaded script still in the ruby environment when loading a script which doesn't has a register_functions so the old one got called

This commit is contained in:
Jesse van den Kieboom 2005-10-11 09:44:17 +00:00
parent 6469efbbdc
commit 803f214b1a
1 changed files with 7 additions and 4 deletions

View File

@ -417,7 +417,7 @@ gm_scripts_run(GmScripts *scripts, GmWorld *world, gchar *name, gchar *argstr) {
}
VALUE
gm_scripts_register_func_old(int argc, VALUE *argv) {
gm_scripts_rb_register_func_old(int argc, VALUE *argv) {
debug_msg(1, "GmScripts.RegisterFunc: This is the deprecated way to "
"register functions is does no longer work. Use $scripts.register "
"instead.");
@ -438,6 +438,10 @@ gm_scripts_register_functions(GmScripts *scripts) {
g_signal_emit(scripts, gm_scripts_signals[MESSAGE], 0, msg);
g_free(msg);
// Okay, I'm desperate... define an empty register_functions method so
// that the previous when gets cleared ... :(
rb_eval_string("def register_functions() end");
if (!gm_scripts_rb_do(scripts, RB_CALLBACK(rb_load_file),
(VALUE) scripts->priv->loading->filename)) {
return;
@ -447,7 +451,7 @@ gm_scripts_register_functions(GmScripts *scripts) {
rbScripts = gm_scripts_rb_scripts_new(scripts);
rb_define_variable("$scripts", &rbScripts);
rb_define_global_function("register_func", &gm_scripts_register_func_old,
rb_define_global_function("register_func", &gm_scripts_rb_register_func_old,
-1);
gm_scripts_rb_do(scripts,
@ -514,11 +518,10 @@ gm_scripts_add_file(GmScripts *scripts, const gchar *uri) {
}
scripts->priv->files = g_list_append(scripts->priv->files, script);
g_signal_emit(scripts, gm_scripts_signals[SCRIPT_ADDED], 0, script);
scripts->priv->loading = script;
gm_scripts_register_functions(scripts);
g_signal_emit(scripts, gm_scripts_signals[SCRIPT_ADDED], 0, script);
return TRUE;
}