This tutorial will be brief and assumes that you’ve followed the tutorial on script loaders to the end.
If you didn’t, please go back and learn everything about script loaders first.
Platform accessors are very similar to script loaders although they serve a different purpose.
Platform accessors are meant to provide access to OS APIs to suit the standard library or other accessory parts of MoonSharp.
In particular, the
os modules heavily depend on platform accessors, but other methods go through the platform accessor, like
debug.debug and others.
Depending on the platforms you run to you have these choices of platform accessors :
StandardPlatformAccessor: implements all the needed methods, going to files, environment variables, etc.
LimitedPlatformAccessor: very limited support. Disables the
fileand parts of the
The default script loader used by MoonSharp if no redefinition happens is
LimitedPlatformAccessor for the portable class library build and
the other builds.
Changing the platform accessor impacts all scripts, both created or not. Because of this, changing the platform accessor should NEVER be done once a script has been created. For the sake of this tutorial we’ll do it anyway, but please don’t do it.
You can implement your own platform accessor to define how some functions behave.
As for script loaders you have two main options: extend
PlatformAccessorBase (recommended) or implement
To take decisions about the real platform you are running on, see the
PlatformAutoDetector which performs a lot of runtime checks to try to understand
which platform it’s running on.
There are a few aspects of a platform accessor which are often going to be customized. To avoid having to implement a custom platform accessor everytime you want
to redefine how