Bug w/ global variables not existing in subroutines?

13 views
Skip to first unread message

al

unread,
Jun 7, 2010, 1:37:28 PM6/7/10
to Sleep Developers
I'm new to sleep so maybe I'm missing something but it seems like
there is a problem with global variables not 'existing' in a
subroutine of an included script.

For example, in MAIN_SCRIPT I have a global variable declared. This
value is set through the scriptVariables.setScalar(...) method
before .runScript() is called.

The global variable and its values are accessible in MAIN_SCRIPT and
its subroutines.

The global variable and its values are accessible in INCLUDED_SCRIPT
as well.

However, the global variable and its values appear to not exist in a
subroutine of INCLUDED_SCRIPT.

It may be worth mentioning I'm running these scripts from an
application server (glassfish) though the same issues seem to exist
when just running it directly from a main class.

Raphael Mudge

unread,
Jun 7, 2010, 2:10:10 PM6/7/10
to sleep-de...@googlegroups.com
Hi Al,
Seeing some code will help. In jIRCii scripts can see global variables belonging to other scripts. The main trick is to make sure the scriptVariables object is installed into MAIN_SCRIPT and INCLUDED_SCRIPT by calling setScriptVariables on the ScriptInstance.

Subroutines look at the local scope (on the stack), the closure scope (similar to static scope in C), and then the global scope from the script variables object associated with the current script instance. 

If you're working with AtD, be aware that things get a little weird when you're working with fork(). fork() creates an isolated script environment and you have to explicitly copy values into it when you create the fork(). That's the scripter's responsibility in this case.

If you have script A:

global('$x');
$x = 42;

And script B:

sub foo {
   println($x);
}
foo();

And they're sharing the same script variables, you'll get an output of 42. If you're pretty sure the vars are shared, post some code and I'll take a look at it.

-- Raphael

P.S. I assume you saw this, but section 9.2 of the Sleep Manual talks about this: http://sleep.dashnine.org/manual/


--
-----
To post to this group, send email to sleep-de...@googlegroups.com
To unsubscribe from this group, send email to sleep-develope...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sleep-developers?hl=en

The Sleep Scripting Project: http://sleep.dashnine.org/

Reply all
Reply to author
Forward
0 new messages