Script object provides a few options to tweak its behavior.
There are two kinds of options: local options and global options.
Local options can have a different value for each instance of the
There is a
Script.DefaultOptions static variable which holds the defaults; the defaults are copied over
script.Options everytime a new
Script is created, so that they can be customized further.
|ScriptLoader||This is the
|DebugPrint||This is a
|DebugInput||This is a
|UseLuaErrorLocations||If this is set to true, locations in error messages will only include the line numbers instead of lines and columns. Use this for compatibility with legacy Lua code which parses error messages.|
|Stdin, Stdout and Stderr||Default streams to be used in
|TailCallOptimizationThreshold||This is quite a complex option. Basically Lua uses a technique to drammatically reduce stack usage in certain scenarios at the expense of simplicity and ease of debugging. MoonSharp can behave the same way, but by default doesn't until it's needed. This defines the threshold. Refer to the reference help for more details.|
|CheckThreadAccess||Again a complex and unusual option. MoonSharp does some sanity checks to prevent scripts being used by multiple threads concurrently. For reasons detailed in the reference help, these checks can have false positives and false negatives. If you are experiencing false positives, you can disable the checks with this option. But please check that you are not calling MoonSharp execution concurrently from two threads as it is not supported.|
In this example we will override how text is printed, first globally, then specifically on our script:
As said, global options are accessed through
Script.GlobalOptions and are global to all scripts.
At the moment there are two options:
Platform: the platform accessor we learned about in the previous chapter
CustomConverters: the collection of all custom converters
As all global options have been touched in previous chapters, we will not spend any further time on them.