{"id":17706784,"url":"https://github.com/rifleh700/check","last_synced_at":"2025-03-13T11:31:04.541Z","repository":{"id":176265551,"uuid":"295224595","full_name":"rifleh700/check","owner":"rifleh700","description":"Argument lua-type\\userdata-type\\element-type checking lib for MTA:SA","archived":false,"fork":false,"pushed_at":"2021-01-19T17:44:48.000Z","size":31,"stargazers_count":9,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-26T06:53:31.126Z","etag":null,"topics":["arg","check","lua","mta","mtasa","multitheftauto","type"],"latest_commit_sha":null,"homepage":"","language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rifleh700.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":"2020-09-13T19:41:20.000Z","updated_at":"2024-05-23T18:33:57.000Z","dependencies_parsed_at":"2023-07-10T15:47:46.540Z","dependency_job_id":null,"html_url":"https://github.com/rifleh700/check","commit_stats":null,"previous_names":["rifleh700/check"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rifleh700%2Fcheck","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rifleh700%2Fcheck/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rifleh700%2Fcheck/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rifleh700%2Fcheck/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rifleh700","download_url":"https://codeload.github.com/rifleh700/check/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243396137,"owners_count":20284293,"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":["arg","check","lua","mta","mtasa","multitheftauto","type"],"created_at":"2024-10-25T00:03:11.417Z","updated_at":"2025-03-13T11:31:04.535Z","avatar_url":"https://github.com/rifleh700.png","language":"Lua","funding_links":[],"categories":["Libs and utils"],"sub_categories":[],"readme":"## Description\n\n  Simple Lua/MTA argument type checking lib for MTA:SA.\n\n## API\n\n### Functions\n\n- `boolean check(string patern)`\n  Check function arguments by pattern. It causes an error \"bad argument\" if the check failed, otherwise returns 'true'.\n  \n- `boolean scheck(string pattern)`\n  Soft check function arguments by pattern. It causes a warning \"bad argument\" and returns 'false' if the check failed, otherwise returns 'true'.\n  \n- `boolean warn(string msg [, int lvl = 1])`\n  Cause a warning. Unlike 'error', doesn't terminate the function. Unlike outputDebugString, u can define Lua warning lvl. \n  \n### Variables\n\n- `table checkers`\n  Table of user custom checkers.\n\n## How to use\n\n### Patterns\n\n#### Lua types shortcuts\n\n  Use types shortcuts instead full type names:\n\n```lua\ncheck(\"boolean\") -- сheck whether the arg #1 is a boolean\ncheck(\"b\") -- same\n  \ncheck(\"nil\") -- nil type doesn't have shortcut\n  \ncheck(\"number\")\ncheck(\"n\")\n  \ncheck(\"string\")\ncheck(\"s\")\n  \ncheck(\"table\")\ncheck(\"t\")\n  \ncheck(\"userdata\")\ncheck(\"u\")\n  \ncheck(\"function\")\ncheck(\"f\")\n  \ncheck(\"thread\")\ncheck(\"th\")\n```\n\n#### Multiple args\n\n  Use as many arguments types as you need:\n  \n```lua\ncheck(\"s,n,t\") -- #1 - string, #2 - number, #3 - table\n```\n\n#### Special symbols\n\n  Use 'any' type by '?' symbol or 'notnil' type by '!' symbol:\n\n```lua\ncheck(\"s,?,t\") -- #1 - string, #2 - any type, #3 - table\ncheck(\"s,n,!\") -- #1 - string, #2 - number, #3 - any type but NOT nil\n```\n\n#### Optional args\n\n  Use optional arguments by '?' symbol:\n  \n```lua\ncheck(\"s,?n,t\") -- #1 - string, #2 - nil or number(optional argument), #3 - table\n```\n\n#### Type variants\n\n  Use two or more variants of type separated by '|' symbol:\n\n```lua\ncheck(\"nil|s,n,t\") -- #1 - nil or string(optional argument), #2 - number, #3 - table\ncheck(\"?s,n,t\") -- same\ncheck(\"s|n|t,t\") -- #1 - string or number or table, #2 - table\ncheck(\"?s|n|t,t\") -- #1 - nil or string or number or table(optional argument), #2 - table\n```\n\n#### Type repeat\n\n  Use two or more same types by '[n]' block:\n  \n```lua\ncheck(\"s,n[2],t\") -- #1 - string, #2 - number, #3 - number, #4 - table\ncheck(\"s,b|n[2],t\") -- #1 - string, #2 - boolean or number, #3 - boolean or number, #4 - table\ncheck(\"s,?b|n[2],t\") -- #1 - string, #2 - nil or boolean or number(optional argument), #3 - nil or boolean or number(optional argument), #4 - table\n```\n\n#### Metatable types\n\n  Use metatable types\n  \n```lua\nfunction f(c)\n    check(\"color\")\n    return true\nend\n\nfunction test()\n    local red = setmetatable({255, 0, 0}, {__type = \"color\"})\n    iprint(f(red)) -- true\nend\n```\n\n#### MTA types\n\n  Use userdata MTA types as subtypes of 'userdata':\n  \n```lua\ncheck(\"u:acl-group\") -- #1 - acl-group\ncheck(\"u:lua-timer\") -- #1 - timer\n```\n\n  Use MTA element types as subtypes of 'userdata:element':\n  \n```lua\ncheck(\"u:element:vehicle\") -- #1 - vehicle element\ncheck(\"u:element:player|u:element:ped\") -- #1 - player element or ped element\n```\n\n  GUI elements default checker is available:\n  \n```lua\ncheck(\"userdata:element:gui\") -- #1 - any MTA gui element (button, label, gridlist, etc...)\ncheck(\"u:element:gui\") -- same\n```\n\n### Check\n\n#### Hard check\n\n  It causes Lua error \"bad argument\" if the check failed:\n  \n```lua\nfunction f(str, num, data)\n    check(\"s,?n,t\") -- #1 - string, #2 - nil or number(optional argument), #3 - table\n    return true\nend\n\nfunction test()\n    iprint(f(\"lol\", 1, {})) -- true\n    iprint(f(\"lol\", nil, {})) -- true\n    iprint(f(\"lol\", nil, nil)) -- error: bad argument #3 'data' to 'f' (table expected, got nil)\nend\n```\n\n#### Soft check\n\n  It causes a warning \"bad argument\" and returns 'false' if the check failed, otherwise returns 'true':\n  \n```lua\nfunction f(str, num, data)\n    if not scheck(\"s,?n,t\") then return false end\n    return true\nend\n\nfunction test()\n    iprint(f(\"lol\", 1, {})) -- true\n    iprint(f(\"lol\", nil, {})) -- true\n    iprint(f(\"lol\", nil, nil)) -- false, warning: bad argument #3 'data' to 'f' (table expected, got nil)\nend\n```\n  \n#### Custom checkers\n\n  Define your own checkers:\n  \n```lua\nfunction f(num)\n    check(\"percent\")\n    return true\nend\n\nfunction test()\n    checkers.percent = function(v) return type(v) == \"number\" and v \u003e= 0 and v \u003c= 1 end\n    iprint(f(0.1)) -- true\n    iprint(f(1)) -- true\n    iprint(f(1.1)) -- error: bad argument #1 'num' to 'f' (percent expected, got number)\nend\n```\n\n#### Warnings\n\n  Use warnings instead errors wherever you need:\n  \n```lua\nfunction f()\n    warn(\"something is wrong, but that's all right\", 2)\n    return true\nend\n\nfunction test()\n    iprint(f()) -- true, warning: something is wrong, but that's all right\nend\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frifleh700%2Fcheck","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frifleh700%2Fcheck","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frifleh700%2Fcheck/lists"}