{"id":15064984,"url":"https://github.com/zenliucn/glu","last_synced_at":"2025-04-10T13:09:05.167Z","repository":{"id":57661426,"uuid":"428045782","full_name":"ZenLiuCN/glu","owner":"ZenLiuCN","description":"extension for gopher-lua","archived":false,"fork":false,"pushed_at":"2023-10-05T05:09:31.000Z","size":162,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-24T11:45:57.814Z","etag":null,"topics":["gopher-lua","lua","module"],"latest_commit_sha":null,"homepage":"","language":"Go","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/ZenLiuCN.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-11-14T21:29:48.000Z","updated_at":"2024-08-30T08:21:20.000Z","dependencies_parsed_at":"2023-02-18T23:45:56.624Z","dependency_job_id":"fbbf5136-6494-4328-b1cd-0a3e8debc71b","html_url":"https://github.com/ZenLiuCN/glu","commit_stats":{"total_commits":31,"total_committers":3,"mean_commits":"10.333333333333334","dds":0.09677419354838712,"last_synced_commit":"ea88ee8608e2cfac46492ae70de51d2742c3afc3"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZenLiuCN%2Fglu","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZenLiuCN%2Fglu/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZenLiuCN%2Fglu/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZenLiuCN%2Fglu/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ZenLiuCN","download_url":"https://codeload.github.com/ZenLiuCN/glu/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248224645,"owners_count":21068073,"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":["gopher-lua","lua","module"],"created_at":"2024-09-25T00:28:58.798Z","updated_at":"2025-04-10T13:09:05.147Z","avatar_url":"https://github.com/ZenLiuCN.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GLU (glucose) - [gopher-lua](https://github.com/yuin/gopher-lua) module extensions\n\n## Summary\n\n### requires\n\n+ go 1.17 (as gopher-lua required): `under branch v1 with uri \"github.com/ZenLiuCN/glu\"`\n+ go 1.18 (with Generic): `under branch v2 with \"github.com/ZenLiuCN/glu/v2\"`\n+ go 1.18 (simplify API): `under branch v3 with \"github.com/ZenLiuCN/glu/v3\"`\n\n## Packages\n\n1. √ `glu` the core module:\n    1. Define helper `Module` and `Type` for easier register user library and user type;\n    2. Define global LState pool for reuse;\n    3. Define Registry for `Modulars`, with optional auto-injection;\n    4. Support `Help(string?)` for help information;\n2. √ `json` dynamic json library base on [Jeffail/gabs](https://github.com/Jeffail/gabs/v2)\n3. √ `http` http server and client library base on [gorilla/mux](https://github.com/gorilla/mux), depends on `json`\n4. √ `sqlx` sqlx base on [jmoiron/sqlx](https://github.com/jmoiron/sqlx), depends on `json`, new in version `v2.0.2`\n\n## Samples\n\n1. usage\n\n```go\npackage sample\n\nimport (\n\t\"fmt\"\n\t\"github.com/ZenLiuCN/glu/v3\"\n\tlua \"github.com/yuin/gopher-lua\"\n)\n\nfunc main() {\n\tfmt.Println(DoSomeScript(\"1+2\") == 3.0)\n}\nfunc DoSomeScript(script string) float64 {\n\tvm := glu.Get()\n\tdefer glu.Put(vm)\n\tif err := vm.DoString(script); err != nil {\n\t\tpanic(err)\n\t}\n\treturn float64(vm.CheckNumber(1))\n}\n```\n\n2. print help\n```lua\n   local http=require('http')\n   local json=require('json')\n   print(json.help()) --will print comma split keyword list\n   print(http.help('?')) --will print module help\n   print(http.Server.help('?')) --will print type constructor help\n   for word in string.gmatch(http.Server.help(), '([^,]+)') do\n      print(http.Server.help(word)) --will print method constructor help\n   end\n   print(http.CTX.help('?'))\n   for word in string.gmatch(http.CTX.help(), '([^,]+)') do\n      print(http.CTX.Help(word))\n   end\n```\n\n3. http server\n```lua\nlocal http=require('http')\nlocal server=http.Server.new(':8081') --new Server with listen address\nfunction handle(c)\n c:sendString(c:query('p'))\nend\nserver:get('/',handle)\nserver:start(false)\nwhile (true) do\tend\n```\n\n4. http client\n   ```lua\n    local res,err=require('http').Client.new(5):get('http://github.com')\n    print(err)\n    if res:size()\u003e0 then\n    local txt=res:body()  \n    print(txt)\n    end \n   ```\n\n## Support this project\n\n1. offer your ideas\n\n2. fork and pull\n\n## License\n\nMIT as gopher-lua did\n\n## Changes `v2.x`\n\nThose are record start at version `2.0.2`\n\n1. `v2.0.2` :\n    + add module `sqlx` with `sqlx.DB`,`sqlx.Result`\n    + add function `of(jsonString):Json` in module `json`\n2. `v2.0.3` :\n    + adding `sqlx.Tx`,`sqlx.Stmt`,`sqlx.NamedStmt` to module `sqlx`\n3. `v2.0.4` :\n    + add `Json:get(string|number)` to module `json`, which will replace `Json:at`\n    + add `x:execMany` and `x:queryMany` to module `sqlx`\n    + add `sqlx.encB64` and `sqlx.decB64` to module `sqlx`\n      for [numeric issue](https://github.com/jmoiron/sqlx/issues/289)\n        + when use [pgx](https://github.com/jackc/pgx/) for postgresql there will no such needs.\n4. `v2.0.5` :\n    + add `sqlx:to_num` and `sqlx:from_num` to module `sqlx`, which convert json array of objects numeric fields from|to\n      binary\n   \n## Changes `v3.x`\n\nThose are record start at version `3.0.1`\n1. `v3.0.1`:\n    + simplify core api\n      + `Get`: get a pooled VM\n      + `Put`: return a pooled VM\n      + `Register`: register a modular\n      + `NewModule`: create a Module\n      + `NewSimpleType`: create a Simple Type\n      + `NewType`: create a Type\n      + `NewTypeCast`: create a Type with auto cast\n      + `modular.AddFunc`: add a function to Module or Type\n      + `modular.AddField`: add a field to Module or Type\n      + `modular.AddFieldSupplier`: add a field by supplier to Module or Type\n      + `modular.AddModule`: add a sub-module\n      + `Type.New`: create new instance and push to stack\n      + `Type.NewValue`: create new instance only\n      + `Type.Cast`: check if is auto cast Type\n      + `Type.Check`: check stack value is Type, must a Cast Type\n      + `Type.CheckSelf`: check top stack value is Type, must a Cast Type\n      + `Type.CheckUserData`: check user-data value is Type, must a Cast Type\n      + `Type.Caster`: the caster or nil\n      + `Type.AddMethod`: add a Method\n      + `Type.AddMethodUserData`: add a Method use UserData as receiver\n      + `Type.AddMethodCast`: add a Method use specific Type as receiver,  must a Cast Type\n      + `Type.Override`: override a meta function\n      + `Type.OverrideUserData`: override a meta function  use UserData as receiver\n      + `Type.OverrideCast`: override a meta function use specific Type as receiver,  must a Cast Type\n    + `json` gabs module to process JSON\n      + `json.stringify`: convert JSON to json string\n      + `json.parse`: create JSON from json string\n      + `json.of`: create JSON from lua value\n      + `JSON.new`: create new JSON from a json string\n      + `JSON:json`: convert JSON to json string\n      + `JSON:path`: fetch JSON element at path\n      + `JSON:exists`: check JSON path exists\n      + `JSON:get`: fetch JSON element at path or index of array\n      + `JSON:set`: set JSON element at path or index of array, nil value will delete.\n      + `JSON:type`: get JSON element type at path.\n      + `JSON:append`: append JSON element at path, returns error message.\n      + `JSON:isArray`: check if JSON element at path is JSON array.\n      + `JSON:isObject`: check if JSON element at path is JSON Object.\n      + `JSON:bool`: fetch JSON element at path, which should be a boolean.\n      + `JSON:string`: fetch JSON element at path, which should be a string.\n      + `JSON:number`: fetch JSON element at path, which should be a number.\n      + `JSON:size`: fetch JSON size at path,if not array or object, returns nil.\n      + `JSON:raw`: fetch JSON element at path, and convert to lua value.\n      + `tostring(JSON)`: convert JSON to json string.\n   + `http`: mux module to access and serve http \n     + `http.Server`: the http server\n     + `http.Client`: the http client\n     + `http.CTX`: the http request context\n     + `http.Response`: the http response\n     + `CTX:vars`: path variables by name\n     + `CTX:header`: request header by name\n     + `CTX:query`: request query by name\n     + `CTX:method`: request method\n     + `CTX:body`: request body as JSON\n     + `CTX:setHeader`: set response header\n     + `CTX:status`: set response status\n     + `CTX:sendJson`: send JSON as response body and end process\n     + `CTX:sendString`: send string as response body and end process\n     + `CTX:sendFile`: send File as response body and end process\n     + `Server.new`: create new http.Server listen at address\n     + `Server:stop`: shutdown http server\n     + `Server:running`: check if server is running\n     + `Server:start`: start server to listen\n     + `Server:route`: declare route without limit request method\n     + `Server:get`: declare route for GET method\n     + `Server:post`: declare route for POST method\n     + `Server:put`: declare route for PUT method\n     + `Server:head`: declare route for HEAD method\n     + `Server:patch`: declare route for PATCH method\n     + `Server:delete`: declare route for DELETE method\n     + `Server:connect`: declare route for CONNECT method\n     + `Server:options`: declare route for OPTIONS method\n     + `Server:trace`: declare route for TRACE method\n     + `Server:files`: declare route for serve with files\n     + `Server:release`: free server resources\n     + `Server.pool`: server pool size\n     + `Server.poolKeys`: server pool keys\n     + `Server.pooled`: fetch server from pool by key\n     + `Response:statusCode`: response status code\n     + `Response:status`: response status text\n     + `Response:size`: response content size\n     + `Response:header`: response headers\n     + `Response:body`: response body as string\n     + `Response:bodyJson`: response body as JSON\n     + `Client.new`: create new http client\n     + `Client:get`: send GET request\n     + `Client:post`: send POST request\n     + `Client:head`: send HEAD request\n     + `Client:form`: send POST request with form\n     + `Client:request`: send request with string data\n     + `Client:requestJson`: send request with JSON data\n     + `Client:release`:  free client resources\n     + `Client.pool`:  client pool size\n     + `Client.poolKeys`:  client pool keys\n     + `Client.pooled`:  get client from pool by key\n   + `sqlx`: sqlx module to access database\n     + `sqlx.DB`: sqlx database\n     + `sqlx.Tx`: sqlx transaction \n     + `sqlx.Stmt`: sqlx prepared statement \n     + `sqlx.NamedStmt`: sqlx prepared named statement \n     + `sqlx.Result`: sql execute result\n     + `sqlx.connect`: connect to database\n     + `sqlx.encB64`: encode string to base64\n     + `sqlx.decB64`: decode base64 to string\n     + `sqlx.from_num`: encode string of decimal to base64\n     + `sqlx.to_num`: decode base64 to string of decimal\n     + `DB.new`: connect to database\n     + `DB:query`: query SQL data as JSON\n     + `DB:exec`: execute SQL fetch Result\n     + `DB:queryMany`: query SQL with batch of parameters\n     + `DB:execMany`: execute SQL with batch of parameters\n     + `DB:begin`: begin transaction\n     + `DB:prepare`: prepare statement\n     + `DB:prepareNamed`: prepare named statement\n     + `DB:close`: close database\n     + `Tx:query`: query SQL data as JSON\n     + `Tx:exec`: execute SQL fetch Result\n     + `Tx:queryMany`: query SQL with batch of parameters\n     + `Tx:execMany`: execute SQL with batch of parameters\n     + `Tx:prepare`: prepare statement\n     + `Tx:prepareNamed`: prepare named statement\n     + `Tx:commit`:commit transaction\n     + `Tx:rollback`:rollback transaction\n     + `Stmt:query`: query data as JSON\n     + `Stmt:exec`: execute fetch Result\n     + `Stmt:queryMany`: query with batch of parameters\n     + `Stmt:execMany`: execute with batch of parameters\n     + `Stmt:close`: close statement\n     + `NamedStmt:query`: query data as JSON\n     + `NamedStmt:exec`: execute fetch Result\n     + `NamedStmt:queryMany`: query with batch of parameters\n     + `NamedStmt:execMany`: execute with batch of parameters\n     + `NamedStmt:close`: close statement\n     + `Result:lastID`: last inserted ID\n     + `Result:rows`: affected rows","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzenliucn%2Fglu","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzenliucn%2Fglu","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzenliucn%2Fglu/lists"}