/*
 * File: extern.txt
 * ----------------
 */

/* An executing function has its own variable space (scope). Therefor, a
   function can't normally access variables from the main program. */
foo = function() {
    wln("shitPickle = " + tostring(shitPickle));
};
shitPickle = 15;
foo();

/* JAIL doesn't quite follow the standard approach in this area. In many other
   languages, you can declare variables as global or local in one way or
   another. In Lua, for example, half the sourcecode of a program usually
   consists of the keyword "local", because every variable that's not declared
   as local is global. That makes sense and feels safe.
     But in JAIL, if you want to access a variable from the main program in a
   function, you "import" it with an extern statement. */
foo = function() {
    extern shitPickle;
    wln("shitPickle = " + tostring(shitPickle));
};
foo();

/* You can import several variables separated by commas. */
foo = function() {
    extern shitPickle, shit, pickle, nope;
    wln("shitPickle = " + tostring(shitPickle));
    wln("shit       = " + tostring(shit));
    wln("pickle     = " + tostring(pickle));
    wln("nope       = " + tostring(nope));
};
shit = 3;
pickle = 8;
foo();

