File-global scope variables from within chaiscript?


#1

Is it at all possible to create a variable with a file-global scope in chaiscript? Something like:

var myGlobalVariable = Foo();
def SomeFunction()
{
    DoSomething(myGlobalVariable);
}

Currently myGlobalVariable falls out of scope inside functions. Is there any global-keyword or something, like in PHP?


#2

For anyone wondering, I found a solution for me by using the keyword GLOBAL (note allcaps) instead of var. This will make the variable global for the whole script (ChaiScript instance), however it was pretty much what I wanted. I’d guess having an actual file-global variable is impossible because of how the whole scripting system works.

Either way, I really think the documentation for the chaiscript API (as well as chaiscript) can be improved. Currently everything is very spread out and its difficult to find basic stuff like the GLOBAL keyword. I will look into writing a documentation myself.

EDIT: For example, the GLOBAL keyword should really be listed here: http://chaiscript.com/docs/5/LangKeywordRef.html


#3

FYI, the ChaiScript cheatsheet has info on this: https://github.com/ChaiScript/ChaiScript/blob/develop/cheatsheet.md

Thanks,
Jason