Skip to content

MS2 Type safety

GoogleFeud edited this page Feb 1, 2021 · 6 revisions

MS2 is a type-safe programming language, but it's type safety features are hidden. That means you cannot add variables of different types and get weird results like in javascript, or even worse - errors.

Import types

You should always provide typings to the objects you import. For example:

const Evaler = new MS2({
   typings: {
     imports: {
      player: { type: OBJECT, properties: { name: STRING, id: NUMBER } },
      someArr: { type: ARRAY, of: [STRING, NUMBER], readonly: true }
} 
}
});

Export types

Same for the export types. In order to make sure you are getting all the exports you need, specify them:

const Evaler = new MS2({
   typings: {
     exports: {
        name: STRING,
        someHook: {type: FUNCTION, returns: BOOLEAN, params: [STRING, NUMBER], allowNull: false}
} 
}
});

All typings settings

  • type - The type
  • returns - Only applicable to functions, the return type of the function
  • params - Only applicable to functions, the parameters of the function
  • allowNull - If the import/export can be null
  • properties - Only applicable to objects, the properties of the object
  • of - Only applicable to arrays, the types of the values inside the array
  • readonly - Only applicable to imported variables, if the variable can be overridden
  • locked - Only applicable to imported objects, if any of the properties of the object can be modified

Clone this wiki locally