{"id":13896753,"url":"https://github.com/leafo/loadkit","last_synced_at":"2025-10-08T06:53:58.257Z","repository":{"id":11448592,"uuid":"13908173","full_name":"leafo/loadkit","owner":"leafo","description":"Loadkit allows you to load arbitrary files within the Lua package path","archived":false,"fork":false,"pushed_at":"2023-08-17T18:36:26.000Z","size":14,"stargazers_count":42,"open_issues_count":4,"forks_count":3,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-08-11T23:21:51.091Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"MoonScript","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/leafo.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":"2013-10-27T18:52:20.000Z","updated_at":"2025-08-11T03:20:34.000Z","dependencies_parsed_at":"2024-06-20T07:22:22.186Z","dependency_job_id":"6561c457-a161-4143-97ee-8a87ebf14fb6","html_url":"https://github.com/leafo/loadkit","commit_stats":{"total_commits":18,"total_committers":1,"mean_commits":18.0,"dds":0.0,"last_synced_commit":"c6c712dab45f6c568821f9ed7b49c790a44d12e7"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/leafo/loadkit","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leafo%2Floadkit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leafo%2Floadkit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leafo%2Floadkit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leafo%2Floadkit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/leafo","download_url":"https://codeload.github.com/leafo/loadkit/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leafo%2Floadkit/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278903034,"owners_count":26065786,"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","status":"online","status_checked_at":"2025-10-08T02:00:06.501Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-08-06T18:03:08.039Z","updated_at":"2025-10-08T06:53:58.242Z","avatar_url":"https://github.com/leafo.png","language":"MoonScript","funding_links":[],"categories":["MoonScript"],"sub_categories":[],"readme":"# loadkit\n\n![spec](https://github.com/leafo/loadkit/workflows/spec/badge.svg)\n\nLoadkit allows you to load arbitrary files within the Lua package path.\n\n## Install\n\n```bash\n$ luarocks install loadkit\n```\n\n## Example\n\n[`etlua`](http://github.com/leafo/etlua) is a library that lets you create\nembedded Lua templates. The result of the template is a function that when\ncalled returns the compiled template. Normally you need to load the template\nand compile the it manually. Let's make it so `require` is aware of `.elua`\nfiles and returns the compiled template.\n\n\nHere's an example directory structure:\n\n```\n|-- example.lua\n`-- templates\n    |-- hello.elua\n    `-- my_template.elua\n```\n\nAnd then we can run:\n\n```lua\n-- example.lua\nlocal etlua = require \"etlua\"\nlocal loadkit = require \"loadkit\"\n\n-- register a handler for .elua files\nloadkit.register(\"elua\", function(file)\n\treturn assert(etlua.compile(file:read(\"*a\")))\nend)\n\ntemplate = require \"templates.my_template\"\nprint(template())\n```\n\nThe functionality of `require` is unchanged, if the template's module name is\nrequired again it would return the cached value, avoiding any additional\nsearching.\n\n### What's the point?\n\nA project like [MoonScript](http://moonscript.org) uses a technique like this\nto let you load compiled MoonScript as you would load Lua making the\nintegration seamless.\n\nAlternatively, if you've ever wanted to bundle different kinds of file assets\ninside of a Lua module but were unsure about how to resolve the correct path to\nopen the file you can use this module:\n\n```lua\nlocal js_loader = loadkit.make_loader(\"js\")\n\n-- find the actual path of your resource\nlocal fname = js_loader(\"mymodule.some_script\")\n```\n\n## Reference\n\nThe module can be loaded by doing:\n\n```lua\nlocal loadkit = require \"loadkit\"\n```\n\n### Functions\n\n#### `loadkit.register(ext, handler)`\n\nRegisters a new loader for the extension `ext`. The handler is a function that\nis responsible for creating the module after a matching file has been found.\n\nThe handler takes three arguments: `file`, `module_name`, `file_path`.\n\nThe `file` is a freshly opened Lua file object ready for reading. Loadkit will\nautomatically close the file after executing the handler if you don't close it.\n\n`module_name` is the name of the module that was passed to require. `file_path`\nis the path of the file that was opened when searching through the search path.\n\nThe return value of the handler determines if the module is loaded. If `nil` is\nreturned no module is loaded. Any other value returned is used as the value of\nthe module.\n\n#### `success = loadkit.unregister(ext)`\n\nRemoves a handler that has already been registered. Returns `true` if found\nhandler to remove.\n\n#### `bool = loadkit.is_registered(ext)`\n\nReturns `true` if a loader has already been registered for the extension `ext`.\n\n#### `loader = loadkit.make_loader(ext, [handler, package_path])`\n\nMakes a loader without manipulating Lua's module loaders. The return value is a\nfunction that takes a module name and returns the path of the file that matches\nthat module name if it could be found.\n\nHandler is an optional function that works the same as in `register` from\nabove. If a handler is specified then its return value is returned by the\nloader.\n\n`package_path` defaults to the Lua install's `package.path` variable.\n\n# Changelog\n\n**1.1.0 -- Sun Dec  6 17:50:53 PST 2015**\n\n* `make_loader` can operate on a custom package path\n* Support lua 5.2 and above (fix unpack reference)\n\n## License\n\nMIT, Copyright (C) 2014 by Leaf Corcoran\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleafo%2Floadkit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleafo%2Floadkit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleafo%2Floadkit/lists"}