{"id":17275485,"url":"https://github.com/quinchs/flua","last_synced_at":"2025-03-26T14:15:24.142Z","repository":{"id":112186172,"uuid":"379170918","full_name":"quinchs/FLua","owner":"quinchs","description":"FLua: A lua language extension","archived":false,"fork":false,"pushed_at":"2021-06-22T07:18:00.000Z","size":14,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-31T15:20:03.397Z","etag":null,"topics":["lua"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/quinchs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-06-22T06:51:17.000Z","updated_at":"2021-06-22T20:43:37.000Z","dependencies_parsed_at":"2023-05-11T04:45:38.725Z","dependency_job_id":null,"html_url":"https://github.com/quinchs/FLua","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quinchs%2FFLua","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quinchs%2FFLua/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quinchs%2FFLua/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quinchs%2FFLua/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/quinchs","download_url":"https://codeload.github.com/quinchs/FLua/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245668638,"owners_count":20653008,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["lua"],"created_at":"2024-10-15T08:56:21.769Z","updated_at":"2025-03-26T14:15:24.121Z","avatar_url":"https://github.com/quinchs.png","language":null,"readme":"\u003ch1 align=\"center\"\u003eFLua: A lua language extension\u003c/h1\u003e\n\nWelcome to Flua, the open source dynamic scripting language that compiles into Lua. It is heavily based on the 5.2 lua concepts. The initial idea of FLua came when I was trying to work with metatables and got so confused because I came from a C/C# background. The goal of FLua is to ease the writing of tables that are designed to represent entities. The compiled version of FLua is designed to be compatable with normal lua so you could use FLua created objects in lua.\n\n\u003cdiv align=\"center\"\u003e\n  \u003ch1\u003eNew keywords\u003c/h1\u003e\n\n| Keyword   | Description                                                 |\n| --------- | ----------------------------------------------------------- |\n| `class`   | Classes are declared using the keyword `class`              |\n| `public`  | Marks the current field or function public inside a class.  |\n| `private` | Marks the current field or function private inside a class. |\n| `import`  | Import a declaration from a file.                           |\n| `export`  | Exports a declaration globally.                             |\n| `get`     | Sets the `get` operator on a field in a class.              |\n| `set`     | Sets the `set` operator on a field in a class               |\n| `this`    | `this` is treated like the lua `self` keyword.              |\n| `new`     | Used to create and call a classes constructor.              |\n| `from`    | Used with `import` to define where to import from           |\n\n  \u003c/div\u003e\n  \n## Classes\n\nFlua adds classes that compile to lua metatables, however with FLua its much easier to make encapsulation compliant tables.\n\nWith classes you can control what can be accessed as well as use some metatable magic.\n\n### Defining a class\n\n```lua\nclass MyClass {\n    -- func's and fields go here\n}\n```\n\n### Creating an instance of a class\n\nIn FLua you can create a new instance of a class with the `new` keyword:\n\n```lua\nlocal inst = new MyClass()\n```\n\nThe new keyword acts like luas `:new` function and can be used as so:\n\n```lua\nlocal inst = MyClass:new()\n```\n\nBoth will create a new instance of the class and call the constructor if there is one.\n\n### Constructors\n\nMaking a constructor is easy in FLua. you make a **publically accessable** function with the same name of the class, you can have multiple constructors as long as they take a different amount of arguments.\n\n```lua\nclass MyClass {\n    function MyClass()\n        print(\"Constructor was called.\")\n    end\n\n    function MyClass(arg1)\n        print(\"Got arg \" .. tostring(arg1))\n    end\n}\n\nlocal inst = new MyClass()  -- prints \"Constructor was called.\"\ninst = new MyClass(\"Hello\") -- prints \"Got arg Hello\"\n```\n\n### `this` keyword\n\nWithin classes you can use the `this` keyword to access the instance of the current class. `self` does the same thing as `this`. currently in FLua classes are instance only, there is no static like implementation of classes _yet_.\n\n**Example usage of `this`**\n\n```lua\nclass MyClass {\n\n    function MyClass()\n        this.printHello()\n    end\n\n    function printHello()\n        print(\"Hello!\")\n    end\n}\n\nlocal inst = new MyClass() -- prints hello.\n\n```\n\n## Public and Private Properties\n\nWith FLua you can specify properties or functions in classes to have access keywords. Currently there is `public` and `private`. By default. all properties without an access keyword are made public.\n\n### Private\nOnly the class or an instance of the class can access these functions or properties. `private` behaives exactly like C#'s `private` keyword. The `private` keyword can be applied on funtions inside a class, fields inside a class, and on get and set functions.\n\n### Public\nAnyone can access the function or property with the `public` keyword. The `public` keyword can be applied on functions inside a class, fields inside a class, and get and set functions.\n\n**Example**\n\n```lua\nclass MyClass {\n    public propA = nil\n    private propB = nil\n\n    function MyClass()\n        self.propA = 1 -- valid.\n        self.propB = 2\n    end\n\n    function getPropB()\n        return self.propB -- valid.\n    end\n}\n\nlocal inst = new MyClass()\nprint(inst.propA) -- prints 2.\n\nprint(inst.propB) -- invalid.\nprint(inst.getPropB()) -- valid.\n\ninst.propA = 4 -- valid.\ninst.propB = 5 -- invalid.\n\n```\n\n## Get and Set\n\nThe `get` and `set` keywords allow you to control encapsulation inside your classes.\n\n### Get\nThe `get` keyword is used in properties to get the value of that property. they can be a function or a value. It is expected that the get function returns a value, but its not required.\n\n### Set\nThe `set` function is used to set the properties value. The set function should take in a `value` parameter which is what the executer of the function wants to set the field to.\n\n**Example**\n\n```lua\nclass MyClass {\n    public propA { get = propAPriv }\n    private propAPriv = 1\n\n    public propB { get = function() return math.random(10) end }\n\n    public propC\n    {\n        get = propCPriv,\n        set = function(value)\n            assert(type(value) == \"string\", \"value must be a string.\")\n            assert(value ~= nil, \"value cannot be nil\")\n            assert(#value \u003c= 25, \"value must be 25 characters or less\")\n            self.propCPriv = value\n        end\n    }\n\n    private propCPriv = \"\"\n\n    function MyClass()\n\n    end\n}\n\nlocal inst = new MyClass()\nprint(inst.propA)                         -- prints 1\ninst.propA = 2                            -- error: cannot set a read only properties value.\n\nprint(inst.propB)                         -- prints a number between 1 and 10.\n\ninst.propC = 1                            -- error: value must be a string.\ninst.propC = \"aaaaaaaaaaaaaaaaaaaaaaaaaa\" -- error: value must be 25 characters or less\ninst.propC = \"valid\"                      -- valid.\nprint(inst.propC)                         -- prints \"valid\"\n\n```\n\n## Import/Export\n\nThe `import` and `export` keywords are designed to help ease the usage of global variables.\n\n### Importing\n\nYou can import specific functios/tables from globals like so\n\n```lua\nimport pi from math\n\nprint(pi) -- prints 3.141...\n```\n\n### Exporting\n\n```lua\nclass MyClass {\n    function MyClass()\n        print(\"MyClass created!\")\n    end\n}\n\nexport MyClass\n```\n\n### Combining the two\n\n```lua\n-- File 1\nrandomGlobal = 10\n\nclass MyClass {\n    function MyClass()\n        print(\"MyClass created\")\n    end\n}\n\nexport MyClass, randomGlobal\n\n-- File 2\nimport MyClass from require \"file1\"\n\nprint(randomGlobal) -- nil, randomGlobal is undefined because we didnt import it yet.\nprint(MyClass)      -- prints the string version of the table, its defined.\n\nimport randomGlobal from require \"file1\"\nprint(randomGlobal) -- prints 10\n```\n\n# Whats in the works?\n\nOnce I write the core concepts listed above, im going to work on inheritance and static classes, methods, and fields. Currently not all of the things above work yet and theres no public version of a compiler for FLua yet, I am currently working on it though and will have somthing to publish in the next few weeks or so.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fquinchs%2Fflua","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fquinchs%2Fflua","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fquinchs%2Fflua/lists"}