{"id":19297246,"url":"https://github.com/deemess/uLua","last_synced_at":"2025-04-22T08:31:24.568Z","repository":{"id":19145910,"uuid":"22376187","full_name":"deemess/uLua","owner":"deemess","description":"Lua compiler and iterpreter used to run onto different microcontrollers (like AVR 8 bit)","archived":false,"fork":false,"pushed_at":"2023-01-27T00:50:15.000Z","size":4387,"stargazers_count":83,"open_issues_count":2,"forks_count":17,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-04-05T10:41:32.647Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/deemess.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-07-29T10:26:06.000Z","updated_at":"2025-03-21T15:07:00.000Z","dependencies_parsed_at":"2023-02-14T12:02:11.038Z","dependency_job_id":null,"html_url":"https://github.com/deemess/uLua","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deemess%2FuLua","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deemess%2FuLua/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deemess%2FuLua/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deemess%2FuLua/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/deemess","download_url":"https://codeload.github.com/deemess/uLua/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250206177,"owners_count":21392204,"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-11-09T23:01:49.238Z","updated_at":"2025-04-22T08:31:20.331Z","avatar_url":"https://github.com/deemess.png","language":"C","funding_links":[],"categories":["C"],"sub_categories":[],"readme":"uLua\n====\n\nLua compiler and iterpreter to run on microcontroller (AVR 8 bit)\n\nAbout\n\nuLua aimed to run Lua scripts on microcontrollers with very limited resources, like RAM. uLua should work on microcontrollers with RAM \u003e= 1k. Second thing which uLua should achieve is fast code interpreter. Goal is 1 Million Lua instructions on 10 MIPS (10 MHz for AVR).\nUsage\n\n```\nluac.exe -s -o alltest.luc alltest.lua\nChunkSpy.lua alltest.luc alltest.lua -o alltest.lst\nuLuaPC.exe alltest.luc\n```\n\nChunkSpy.lua - optional. This script used to generate listing file from compiled luc file.\nFeatures\n\nCurrenly support:\n\nfunction calls\nglobal consts\nglobal and local variables\nmath operations\nfor loops\nnative functions (like print())\nclosures with upvalues\ngarbage collector \n\nFollowing code could be executed by uLua.\n\n```Lua\n--load nil test\nfunction loadtest()\n        local a,b,c,d,e = nil,nil,0\n        local aa,bb = true,false\n        print(a,b,c)\n        print(aa,bb)\nend\nloadtest()\n\n-- for loop test\nfor i = 1, 3, 1 do\n        print(i)\nend \n\nfor i = 3, 1, -1 do\n        print(i)\nend \n\n-- upvalue test\nfunction newCounter ()\n        local i = 0\n        return function ()   -- anonymous function\n                        i = i + 1\n                        return i\n                end\nend\nc1 = newCounter()\nprint(c1())  --\u003e 1\nprint(c1())  --\u003e 2\nprint(c1())  --\u003e 3\n\n\n-- function call test\nfunction func1(par1,par2)\n        local local1 = par1 + par2\n        return local1\nend\n\nfunction func2(par1,par2,par3)\n        local local1 = par1 + par2\n        local local2 = par3 * par3\n        local1 = local1 + local2\n        return local1\nend\n\na=1\nb=3\nc=3.5\n\nresult1 = func1(a,b)\nresult2 = func2(a,b,c)\nprint(\"Result1 = \", result1)\nprint(\"Result2 = \", result2)\n\n--math test\nlocal a,b = 2,4; a = a + 4 * b - a / 2 ^ b % 3\nprint(\"a + 4 * b - a / 2 ^ b % 3 = \", a)\n\n--conditional jumps test\nif a ~= b \n        then print(\"a != b\")\nend\nif a \u003e b \n        then print(\"a \u003e b\")\nend\nif a \u003e= b \n        then print(\"a \u003e= b\")\nend\nif a \u003c b \n        then print(\"a \u003c b\")\nend\nif a \u003c= b \n        then print(\"a \u003c= b\")\nend\nif a == b \n        then print(\"a == b\")\nend\n```\n\nUpcoming features:\n\nGC - garbage collector. Currenly implemented GC heap standard functions, like:\n\n```c\n    //initialize garbage collector and memory management\n    void gcInit();\n    //create new variable and return its number\n    gcvarpt* gcNew(vartype type);\n    //create new variable with given size and return its number\n    gcvarpt* gcNew(vartype type, u08 size);\n    //delete variable\n    void gcDelete(gcvarpt* variable);\n```\n\nTables - widly used in lua variable type. Will be implemented as hash table. GC should be implemented first. \n\nSupported Operands\n\n|OP_CODE|NAME|Description|\n|-------|----|-----------|\n|0\t|MOVE\t|Copy a value between registers|\n|1\t|LOADK\t|Load a constant into a register|\n|2\t|LOADBOOL\t|Load a boolean into a register|\n|3\t|LOADNIL\t|Load nil values into a range of registers|\n|4\t|GETUPVAL\t|Read an upvalue into a register|\n|5\t|GETGLOBAL\t|Read a global variable into a register|\n|7\t|SETGLOBAL\t|Write a register value into a global variable|\n|8\t|SETUPVAL\t|Write a register value into an upvalue|\n|12\t|ADD\t|Addition operator|\n|13\t|SUB\t|Subtraction operator|\n|14\t|MUL\t|Multiplication operator|\n|15\t|DIV\t|Division operator|\n|16\t|MOD\t|Modulus (remainder) operator|\n|17\t|POW\t|Exponentiation operator|\n|22\t|JMP\t|Unconditional jump|\n|23\t|EQ\t|Equality test|\n|24\t|LT\t|Less than test|\n|25\t|LE\t|Less than or equal to test|\n|28\t|CALL\t|Call a closure|\n|36\t|CLOSURE\t|Create a closure of a function prototype|\n|30\t|RETURN\t|Return from function call|\n|31\t|FORLOOP\t|Iterate a numeric for loop|\n|32\t|FORPREP\t|Initialization for a numeric for loop|\n\nNot yet supported\n\n|OP_CODE|NAME|Description|\n|-------|----|-----------|\n|6\t|GETTABLE\t|Read a table element into a register|\n|9\t|SETTABLE\t|Write a register value into a table element|\n|10\t|NEWTABLE\t|Create a new table|\n|11\t|SELF\t|Prepare an object method for calling|\n|18\t|UNM\t|Unary minus operator|\n|19\t|NOT\t|Logical NOT operator|\n|20\t|LEN\t|Length operator|\n|21\t|CONCAT\t|Concatenate a range of registers|\n|26\t|TEST\t|Boolean test, with conditional jump|\n|27\t|TESTSET\t|Boolean test, with conditional jump and assignment|\n|29\t|TAILCALL\t|Perform a tail call|\n|33\t|TFORLOOP\t|Iterate a generic for loop|\n|34\t|SETLIST\t|Set a range of array elements for a table|\n|35\t|CLOSE\t|Close a range of locals being used as upvalues|\n|37\t|VARARG\t|Assign vararg function arguments to registers|\n\nKnown Issues\n\nGC could leak, implemented simple reference counting logic. Reference cycling is not supported. \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeemess%2FuLua","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdeemess%2FuLua","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeemess%2FuLua/lists"}