Git Product home page Git Product logo

static's Introduction

License

Static

Basic static typing support library for Lua.

Contents

Features

  • Basic typing
  • Tables with only one type
  • Functions with return type
  • Values that can be one or more types

Documentation

Static provides a simple and easy to use API, exposing only 3 methods:

  • new(Dec, Key, Val, ...): Creates a new typed value and store it into an internal registry. Arguments:

    • (string or table) Dec The TDM for the given value (see the specification below)
    • (string) Key An identifier to use for store the given value
    • Val The value to store
    • ... Variadic arguments, used only in functions returns (if needed)
  • set(Key, Val, ...): Set a new value for the given identifier

    • (string) Key The identifier that you used when created the typed value
    • Val The new value to store
    • ... Variadic arguments, used only in functions returns (if needed)
  • get(Key): Get the value for the given identifier

    • (string) Key The identifier that you used when created the typed value

Static uses metatables, so you can:

  • Call: Static(...). This is the same as Static:new(...)
  • Index: Static.something. This is the same as Static:get("something")
  • Set: Static.something = "ª". This is the same as Static:set("something", "ª")

Learn more in the Examples section

Specification

This specification tries to give you the knowledge needed to start using Static.

All types in Static start with a @ symbol and it's inmediatelly followed by a name in Capital Case. This is to attempt highlighting the TDM and helps you not confuse things up, like "Oh, this is a Static type, because starts with the @ symbol unlike a 'regular' type!". The following table contains all the supported types:

Static Lua
@Str string
@Num number
@Bool boolean
@User userdata
@Func function
@Table table
@Thread thread

Note that if you don't use the exact Static type name, it may result in unexpected behaviours because Static don't make an intense analysis of it.

That's all about types in general, but you may think "What the heck is a 'TDM'?"... Well, basically means "Type Declaration Mode" and it is very important, because it's the way of how Static works. Currently, Static supports only 4 TDMs (Basic, Struct, Return and Mixed), see them below.

Basic

A value that can be only of the specified type. This is done with the syntax: @Type. Example:

Static('@Num', "Num", 0)

This means that the value (stored as Num) can be only a number.

Struct

Tables that can have only one value type. This is done with the syntax: @Type{}. Example:

Static('@Bool{}', "Booleans", { true, false })

This means that the given table (stored as Booleans) can only contain boolean values.

Return

A function that returns a value of a specific type. This is done with the syntax: @Type(). Example:

Static('@Table()', "NewTable", function ()
  return {}
end)

This means that the given function (stored as NewTable) can return only tables.

Mixed

Values that can be two or more types. This is done with the syntax: { ... }. Example:

Static({ '@Str', '@Num' }, "Mix", 0)

This means that the given value (stored as Mix) can be both, an string or a number.

Examples

See Examples.lua

Limitations

See Limitations.md

Thanks

To @darltrash for polishing the readme and the idea itself.

static's People

Contributors

darltrash avatar miqueas avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.