{"id":13538595,"url":"https://github.com/gvvaughan/lyaml","last_synced_at":"2025-10-20T16:19:17.380Z","repository":{"id":7485514,"uuid":"8834157","full_name":"gvvaughan/lyaml","owner":"gvvaughan","description":"LibYAML binding for Lua.","archived":false,"fork":false,"pushed_at":"2023-03-13T13:58:33.000Z","size":1114,"stargazers_count":209,"open_issues_count":17,"forks_count":34,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-11-22T02:54:11.967Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"gvvaughan.github.io/lyaml","language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gvvaughan.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}},"created_at":"2013-03-17T12:37:44.000Z","updated_at":"2024-11-06T22:10:31.000Z","dependencies_parsed_at":"2023-02-16T22:31:23.334Z","dependency_job_id":"dda11f79-f022-40d4-a8cf-ceffe5e5d676","html_url":"https://github.com/gvvaughan/lyaml","commit_stats":{"total_commits":229,"total_committers":7,"mean_commits":"32.714285714285715","dds":"0.048034934497816595","last_synced_commit":"37a9e51e82848f718eafbe95d261377130dcdd3f"},"previous_names":[],"tags_count":37,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gvvaughan%2Flyaml","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gvvaughan%2Flyaml/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gvvaughan%2Flyaml/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gvvaughan%2Flyaml/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gvvaughan","download_url":"https://codeload.github.com/gvvaughan/lyaml/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246763805,"owners_count":20829795,"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-08-01T09:01:13.905Z","updated_at":"2025-10-20T16:19:12.348Z","avatar_url":"https://github.com/gvvaughan.png","language":"Lua","funding_links":[],"categories":["Lua","others","资源","Resources"],"sub_categories":["Parsing and Serialization"],"readme":"LYAML\n=====\n\nCopyright (C) 2013-2023 Gary V. Vaughan\n\n[![License](https://img.shields.io/:license-mit-blue.svg)](https://mit-license.org)\n[![workflow status](https://github.com/gvvaughan/lyaml/actions/workflows/spec.yml/badge.svg?branch=master)](https://github.com/gvvaughan/lyaml/actions)\n[![codecov.io](https://codecov.io/github/gvvaughan/lyaml/coverage.svg?branch=master)](https://codecov.io/github/gvvaughan/lyaml?branch=master)\n\n[LibYAML] binding for [Lua], with a fast C implementation\nfor converting between [%YAML 1.1][yaml11] and [Lua] tables,\nand a low-level [YAML] event parser for implementing more\nintricate [YAML] document loading.\n\nUsage\n-----\n\n### High Level API\n\nThese functions quickly convert back and forth between Lua tables\nand [%YAML 1.1][yaml11] format strings.\n\n```lua\nlocal lyaml   = require \"lyaml\"\nlocal t       = lyaml.load (YAML-STRING, [OPTS-TABLE])\nlocal yamlstr = lyaml.dump (LUA-TABLE, [OPTS-TABLE])\nlocal null    = lyaml.null ()\n```\n\n#### `lyaml.load`\n\n`lyaml.load` accepts a YAML string for parsing. If the YAML string contains\nmultiple documents, only the first document will be returned by default. To\nreturn multiple documents as a table, set `all = true` in the second\nargument OPTS-TABLE.\n\n```lua\nlyaml.load(\"foo: bar\")\n--\u003e { foo = \"bar\" }\n\nlyaml.load(\"foo: bar\", { all = true })\n--\u003e { { foo = \"bar\" } }\n\nmulti_doc_yaml = [[\n---\none\n...\n---\ntwo\n...\n]]\n\nlyaml.load(multi_doc_yaml)\n--\u003e \"one\"\n\nlyaml.load(multi_doc_yaml, { all = true })\n--\u003e { \"one\", \"two\" }\n```\n\nYou can supply an alternative function for converting implicit plain\nscalar values in the `implicit_scalar` field of the OPTS-TABLE argument;\notherwise a default is composed from the functions in the `lyaml.implicit`\nmodule.\n\nYou can also supply an alternative table for coverting explicitly tagged\nscalar values in the `explicit_scalar` field of the OPTS-TABLE argument;\notherwise all supported tags are parsed by default using the functions\nfrom the `lyaml.explicit` module.\n\n#### `lyaml.dump`\n\n`lyaml.dump` accepts a table of values to dump. Each value in the table\nrepresents a single YAML document. To dump a table of lua values this means\nthe table must be wrapped in another table (the outer table represents the\nYAML documents, the inner table is the single document table to dump).\n\n```lua\nlyaml.dump({ { foo = \"bar\" } })\n--\u003e ---\n--\u003e foo: bar\n--\u003e ...\n\nlyaml.dump({ \"one\", \"two\" })\n--\u003e --- one\n--\u003e ...\n--\u003e --- two\n--\u003e ...\n```\n\nIf you need to round-trip load a dumped document, and you used a custom\nfunction for converting implicit scalars, then you should pass that same\nfunction in the `implicit_scalar` field of the OPTS-TABLE argument to\n`lyaml.dump` so that it can quote strings that might otherwise be\nimplicitly converted on reload.\n\n#### Nil Values\n\n[Lua] tables treat `nil` valued keys as if they were not there,\nwhere [YAML] explicitly supports `null` values (and keys!).  Lyaml\nwill retain [YAML] `null` values as `lyaml.null ()` by default,\nthough it is straight forward to wrap the low level APIs to use `nil`,\nsubject to the usual caveats of how nil values work in [Lua] tables.\n\n\n### Low Level APIs\n\n```lua\nlocal emitter = require (\"yaml\").emitter ()\n\nemitter.emit {type = \"STREAM_START\"}\nfor _, event in ipairs (event_list) do\n  emitter.emit (event)\nend\nstr = emitter.emit {type = \"STREAM_END\"}\n```\n\nThe `yaml.emitter` function returns an emitter object that has a\nsingle emit function, which you call with event tables, the last\n`STREAM_END` event returns a string formatted as a [YAML 1.1][yaml11]\ndocument.\n\n```lua\nlocal iter = require (\"yaml\").scanner (YAML-STRING)\n\nfor token_table in iter () do\n  -- process token table\nend\n```\n\nEach time the iterator returned by `scanner` is called, it returns\na table describing the next token of YAML-STRING.  See LibYAML's\n[yaml.h] for details of the contents and semantics of the various\ntokens produced by `yaml_parser_scan`, the underlying call made by\nthe iterator.\n\n[LibYAML] implements a fast parser in C using `yaml_parser_scan`, which\nis also bound to lyaml, and easier to use than the token API above:\n\n```lua\nlocal iter = require (\"yaml\").parser (YAML-STRING)\n\nfor event_table in iter () do\n  -- process event table\nend\n```\n\nEach time the iterator returned by `parser` is called, it returns\na table describing the next event from the \"Parse\" process of the\n\"Parse, Compose, Construct\" processing model described in the\n[YAML 1.1][yaml11] specification using [LibYAML].\n\nImplementing the remaining \"Compose\" and \"Construct\" processes in\n[Lua] is left as an exercise for the reader -- though, unlike the\nhigh-level API, `lyaml.parser` exposes all details of the input\nstream events, such as line and column numbers.\n\n\nInstallation\n------------\n\nThere's no need to download an [lyaml] release, or clone the git repo,\nunless you want to modify the code.  If you use [LuaRocks], you can\nuse it to install the latest release from its repository:\n\n    luarocks --server=http://rocks.moonscript.org install lyaml\n\nOr from the rockspec in a release tarball:\n\n    luarocks make lyaml-?-1.rockspec\n\nTo install current git master from [GitHub][lyaml] (for testing):\n\n    luarocks install http://raw.github.com/gvvaughan/lyaml/master/lyaml-git-1.rockspec\n\nTo install without [LuaRocks], clone the sources from the\n[repository][lyaml], and then run the following commands:\n\n```sh\ncd lyaml\nbuild-aux/luke LYAML_DIR=LIBYAML-INSTALL-PREFIX\nsudo build-aux/luke PREFIX=LYAML-INSTALL-PREFIX install\nspecl -v1freport spec/*_spec.yaml\n```\n\nThe dependencies are listed in the dependencies entry of the file\n[rockspec][L15].\n\n\nBug reports and code contributions\n----------------------------------\n\nThis library is maintained by its users.\n\nPlease make bug reports and suggestions as [GitHub Issues][issues].\nPull requests are especially appreciated.\n\nBut first, please check that your issue has not already been reported by\nsomeone else, and that it is not already fixed by [master][lyaml] in\npreparation for the next release (see  Installation section above for how\nto temporarily install master with [LuaRocks][]).\n\nThere is no strict coding style, but please bear in mind the following\npoints when proposing changes:\n\n0. Follow existing code. There are a lot of useful patterns and avoided\n   traps there.\n\n1. 3-character indentation using SPACES in Lua sources: It makes rogue\n   TABs easier to see, and lines up nicely with 'if' and 'end' keywords.\n\n2. Simple strings are easiest to type using single-quote delimiters,\n   saving double-quotes for where a string contains apostrophes.\n\n3. Save horizontal space by only using SPACEs where the parser requires\n   them.\n\n4. Use vertical space to separate out compound statements to help the\n   coverage reports discover untested lines.\n\n5. Prefer explicit string function calls over object methods, to mitigate\n   issues with monkey-patching in caller environment.\n\n\n[issues]:   http://github.com/gvvaughas/lyaml/issues\n[libyaml]:  http://pyyaml.org/wiki/LibYAML\n[lua]:      http://www.lua.org\n[luarocks]: http://www.luarocks.org\n[lyaml]:    http://github.com/gvvaughan/lyaml\n[L15]:      http://github.com/gvvaughan/lyaml/blob/master/lyaml-git-1.rockspec#L15\n[yaml.h]:   http://pyyaml.org/browser/libyaml/branches/stable/include/yaml.h\n[yaml]:     http://yaml.org\n[yaml11]:   http://yaml.org/spec/1.1/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgvvaughan%2Flyaml","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgvvaughan%2Flyaml","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgvvaughan%2Flyaml/lists"}