{"id":16645626,"url":"https://github.com/cppcxy/luasyntax","last_synced_at":"2025-07-16T11:06:13.748Z","repository":{"id":132588986,"uuid":"192885091","full_name":"CppCXY/luaSyntax","owner":"CppCXY","description":"standard lua implement","archived":false,"fork":false,"pushed_at":"2019-06-26T14:07:41.000Z","size":7,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-18T20:07:53.650Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CppCXY.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2019-06-20T08:53:51.000Z","updated_at":"2019-06-26T14:07:43.000Z","dependencies_parsed_at":null,"dependency_job_id":"d3ff6ed5-b145-489a-b593-a8dc7374bff5","html_url":"https://github.com/CppCXY/luaSyntax","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/CppCXY%2FluaSyntax","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CppCXY%2FluaSyntax/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CppCXY%2FluaSyntax/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CppCXY%2FluaSyntax/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CppCXY","download_url":"https://codeload.github.com/CppCXY/luaSyntax/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243181054,"owners_count":20249415,"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":[],"created_at":"2024-10-12T08:24:35.024Z","updated_at":"2025-03-12T08:23:16.516Z","avatar_url":"https://github.com/CppCXY.png","language":"Lua","funding_links":[],"categories":[],"sub_categories":[],"readme":"# lua标准语法实现的新语法\n\n* 如何使用这个库?\n\n    ```lua\n    require \"luaSyntax.init\"\n    ```\n\n* 声明一个命名空间\n\n    ```lua\n    require \"luaSyntax.init\"\n    _ENV=namespace \"test\"\n    ```\n\n    1. 声明命名空间之后,所有的定义都会存在于当前命名空间之中\n    2. 声明命名空间之后,使用的变量会优先访问当前命名空间中已经定义的对象,然后访问using 过的命名空间中的对象,最后访问_G中的对象\n    3. 在一个命名中间中定义的对象,可以通过使用 命名空间.对象名称 的方式引用比如\n    \n    ```lua\n    --文件 test\n    require \"luaSyntax.init\"\n    _ENV=namespace \"test\"\n    a=123456\n    --文件 test2\n    require \"test\"\n    --会自动生成在test空间中的test2空间\n    _ENV=namespace \"test.test2\"\n    print(test.a) --123456\n    ```\n\n* using 命名空间\n\n    ```lua\n    --文件test\n    require \"luaSyntax.init\"\n    _ENV=namespace \"test\"\n    var=996\n    --文件test2\n    require \"test2\"\n    _ENV=namespace \"test2\"\n    using_namespace \"test\"\n\n    print(var) --996\n\n    ```\n\n    1. using 命名空间之后,你可以不加前缀的使用这个空间中的对象\n    2. 相同命名空间中的对象不必 using\n    3. using_namespace 不是全局变量,只能跟在namespace 声明之后用\n\n* 装饰器\n\n    声明一个装饰器\n\n    ```lua\n    require \"luaSyntax.namespace\"\n\n    _ENV=namespace \"decorator\"\n    --装饰器也用装饰器来声明\n    __decorator__()\n    --装饰器的实现和python差不多\n    function __TestTime__(params)\n        return function (luafunction,functionName)\n            return function(...)\n                local startTime=os.clock()\n                local result={luafunction(...)}\n                local endTime=os.clock()\n                print(\"function \"..functionName..\" cost time \"..(endTime-startTime)..\" s\")\n                return table.unpack(result)\n            end\n        end\n    end\n\n    ```\n\n    * 说明\n\n    ```lua\n    __decorator__ 属于元装饰器，定义于namespace中，使用他来声明其他装饰器。\n\n    ```\n\n    * 使用装饰器\n\n    ```lua\n    require \"luaSyntax.namespace\"\n    require \"luaSyntax.decorator.TestTime\"\n    _ENV=namespace \"test\"\n    using_namespace \"decorator\"\n\n    __TestTime__()\n    ---@param count number\n    function FOR_TEST(count)\n        local t={}\n        for i=1,count do\n            t[i]=i\n        end\n    end\n\n    FOR_TEST(999999)\n    ```\n\n    * 放在声明于命名空间中的函数的定义之前，函数就被包装了。\n    * 其他装饰器介绍\n\n    ```lua\n    __deprecated__(info) \n    --这个装饰器用于当函数被弃用，并且被使用的时候，打印出弃用信息\n    ```\n\n    ```lua\n    __NamedArgs__(...)\n    --这个装饰器修饰函数后函数可以使用具名参数的方式\n    --另外在装饰器参数中可以声明默认参数 bool 变量也可以\n    --例如\n    __NamedArgs__(\n        PARAM(1,\"people\",\"mayun\"),\n        PARAM(2,\"text\",\"996 is your reward\")\n    )\n    function speak(people,text)\n        print(people,text)\n    end\n    --会得到参数 \"mayun\" ,\"996 is your reward\"\n    speak()\n    --普通调用方式\n    speak(\"laozi\",\"xixixixxixixixi\")\n    --text会被传入参数 \"不行啊\"，people使用默认参数\"mayun\"\n    speak(ARG.text(\"不行啊\"))\n    --people使用第一个参数，text被传入具名参数\n    speak(\"laozi\",ARG.text(\"hahahaha\"))\n    ```\n\n    PARAM 这是一个函数，第一个参数是对应的参数位置，第二个参数是具名时候的名字，第三个参数是默认值。只能1对1，不能1对多想要1对多自己实现去。\n\n* 目前就写到这里","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcppcxy%2Fluasyntax","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcppcxy%2Fluasyntax","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcppcxy%2Fluasyntax/lists"}