{"id":15722641,"url":"https://github.com/aglitchman/defold-savetable","last_synced_at":"2025-05-13T10:40:30.239Z","repository":{"id":145977690,"uuid":"402734834","full_name":"aglitchman/defold-savetable","owner":"aglitchman","description":"Encode/decode Lua tables into a string. It's a native extension for the Defold game engine.","archived":false,"fork":false,"pushed_at":"2022-06-07T22:55:42.000Z","size":13,"stargazers_count":12,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-20T23:32:33.598Z","etag":null,"topics":["defold","defold-game-engine","defold-library","defold-module","lua"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"cc0-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aglitchman.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2021-09-03T10:42:01.000Z","updated_at":"2024-04-22T09:57:45.000Z","dependencies_parsed_at":"2023-10-20T16:24:51.353Z","dependency_job_id":null,"html_url":"https://github.com/aglitchman/defold-savetable","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aglitchman%2Fdefold-savetable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aglitchman%2Fdefold-savetable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aglitchman%2Fdefold-savetable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aglitchman%2Fdefold-savetable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aglitchman","download_url":"https://codeload.github.com/aglitchman/defold-savetable/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253924689,"owners_count":21985160,"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":["defold","defold-game-engine","defold-library","defold-module","lua"],"created_at":"2024-10-03T22:08:44.482Z","updated_at":"2025-05-13T10:40:30.218Z","avatar_url":"https://github.com/aglitchman.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SaveTable\n\n⚠️ Defold has implemented [`sys.serialize()`/`sys.deserialize()`](https://defold.com/ref/beta/sys/#sys.serialize:table) since version 1.2.188. Use the new functions instead of this extension. ⚠️\n\n## Description\n\nThis asset allows you to serialize/deserialize Lua tables in Defold the same way as it does via `sys.save`/`sys.load`. The limits are the same:\n\n\u003e Internally, this function uses a workspace buffer sized output file sized 512kb. This size reflects the output file size which must not exceed this limit. Additionally, the total number of rows that any one table may contain is limited to 65536 (i.e. a 16 bit range). When tables are used to represent arrays, the values of keys are permitted to fall within a 32 bit range, supporting sparse arrays, however the limit on the total number of rows remains in effect.\n\n## Installation\n\nUse it in your own project by adding this project as a [Defold library dependency](http://www.defold.com/manuals/libraries/). Open your `game.project` file and in the dependencies field under project add:\n\nhttps://github.com/aglitchman/defold-savetable/archive/main.zip\n\n## Usage\n\n```lua\nlocal tbl = { example = true }\n\n-- Encode Lua table into a base64-encoded string\nlocal str = savetable.encode_base64(savetable.serialize(tbl))\nprint(str)\n\n-- Decode Lua table from a string\nlocal tbl2 = savetable.deserialize(savetable.decode_base64(str))\npprint(tbl2)\n```\n\n### How to use it in [DefSave](https://github.com/subsoap/defsave) for HTML5 builds\n\n`defsave/defsave.lua`, replace lines 124-131 with:\n\n```lua\n\tlocal loaded_file\n\tif html5 then\n\t\t-- sys.load can't be used for HTML5 apps running on iframe from a different origin (cross-origin iframe)\n\t\t-- use `localStorage` instead because of this limitation on default IndexedDB storage used by Defold\n\t\tlocal EMPTY_TABLE = savetable.encode_base64(savetable.serialize({}))\n\t\tloaded_file = savetable.deserialize(savetable.decode_base64(html5.run([[(function(){try{return window.localStorage.getItem(']] .. path .. [[')||']] .. EMPTY_TABLE .. [['}catch(e){return']] .. EMPTY_TABLE .. [['}})()]])))\n\telse\n\t\tloaded_file = sys.load(path)\n\tend\n```\n\n`defsave/defsave.lua`, replace lines 183-194 with:\n\n```lua\n\tlocal is_save_successful\n\tif html5 then\n\t\t-- sys.save can't be used for HTML5 apps running on iframe from a different origin (cross-origin iframe)\n\t\t-- use `localStorage` instead because of this limitation on default IndexedDB storage used by Defold\n\t\tlocal encoded_data = savetable.encode_base64(savetable.serialize(M.loaded[file].data))\n\t\thtml5.run([[try{window.localStorage.setItem(']] .. path .. [[', ']] .. encoded_data .. [[')}catch(e){}]])\n\n\t\tis_save_successful = true\n\telse\n\t\tis_save_successful = sys.save(path, M.loaded[file].data)\n\tend\n```\n\n## Credits\n\nThis project is licensed under the terms of the CC0 1.0 Universal license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faglitchman%2Fdefold-savetable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faglitchman%2Fdefold-savetable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faglitchman%2Fdefold-savetable/lists"}