Giter Club home page Giter Club logo

riwwppp's Introduction

riwwppp

Classes description language for Lua

Alarm!

lpeg-dev branch what internally uses lpeg in active develpment with few more features realized and features in plans. See PR to stay tuned.

Content

Exports

name arguments description
riwwppp.load string str Builds and executes class from description language code
riwwppp.loadFile string filename Builds and executes class from file

Instructions

Instructions in riwwppp are always followed by @ symbol Example:

@class Person
name example description
pragma @pragma safe Specifies pragma for builder
class @class Person Defines class name
constructor @constructor Create Defines constructor name
field @field age Defines new class field (with no accessors)
data @data name Defines new class field with setters and getters

constructor instruction

Example:

@class Person
@constuctor Create

->

Animal = {}

function Animal:Create()
        local o = {}
        setmetatable(o, self)
        self.__index = self
        return o
end

-- Uses in internal purposes for inheritance and generates for every class
Animal._constructor = Animal.Create

If not specified, default constructor is new

field instruction

Example:

@class Person

@field wealth
@field age = 18

->

Person = {}

function Person:new()
        local o = {}
        setmetatable(o, self)
        self.__index = self
        self.wealth = nil
        self.age = 18
        return o
end

Person._constructor = Person.new
local Peter = Person:new()
print(Peter.age) -- 18

data instruction

@class Person

@data name

@data [number] age = 18
@data [number safe] money = 1000

@data [const] truth = 42

->

Person = {}

function Person:new()
        local o = {}
        setmetatable(o, self)
        self.__index = self
        self.age = 18
        self.money = 1000
        return o
end

function Person:getName()
        return self.name
end

function Person:setName(value)
        self.name = value
end

function Person:getAge()
        return tonumber(self.age)
end

function Person:setAge(value)
        self.age = value
end

function Person:getMoney()
        return tonumber(self.money)
end

function Person:setMoney(value)
        if type(value) ~= "number" then error("Trying to set forbidden type for field money") end
        self.money = value
end

function Person:getTruth()
        return 42
end

Person._constructor = Person.new

data modifiers

name description
string Sets internal data type and adds conversion in getter
number Sets internal data type and adds conversion in getter
table Sets internal data type
safe Adds typecheck in setter if type is setted
const Adds getter with inlined value

Pragmas

name description
capitalizeMethods Capitalizes set and get in setters and getters
safe All @data instructions have safe modifier by default

Usage

local riwwppp = require("riwwppp")
riwwppp.debug = false -- Temporary default is true

riwwppp.load(str)
riwwppp.loadFile(filename)

Examples

See here

riwwppp's People

Contributors

rorkh avatar

Stargazers

 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.