{"id":21071598,"url":"https://github.com/esrrhs/fake","last_synced_at":"2025-10-26T19:36:10.857Z","repository":{"id":23708810,"uuid":"27081214","full_name":"esrrhs/fake","owner":"esrrhs","description":"嵌入式脚本语言 Lightweight embedded scripting language","archived":false,"fork":false,"pushed_at":"2023-03-19T14:33:14.000Z","size":33489,"stargazers_count":210,"open_issues_count":0,"forks_count":55,"subscribers_count":30,"default_branch":"master","last_synced_at":"2025-04-09T16:17:02.073Z","etag":null,"topics":["asm","bison","c","c-plus-plus","flex","gcc","ide","interpreter","jit","jit-compiler","language"],"latest_commit_sha":null,"homepage":"","language":"C++","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/esrrhs.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":"2014-11-24T15:19:11.000Z","updated_at":"2025-01-17T00:47:30.000Z","dependencies_parsed_at":"2024-11-19T18:53:52.791Z","dependency_job_id":"9fca5e66-ae06-4a38-8aab-1f5a782a8a9a","html_url":"https://github.com/esrrhs/fake","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/esrrhs%2Ffake","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/esrrhs%2Ffake/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/esrrhs%2Ffake/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/esrrhs%2Ffake/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/esrrhs","download_url":"https://codeload.github.com/esrrhs/fake/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248065285,"owners_count":21041872,"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":["asm","bison","c","c-plus-plus","flex","gcc","ide","interpreter","jit","jit-compiler","language"],"created_at":"2024-11-19T18:53:42.157Z","updated_at":"2025-10-26T19:36:10.749Z","avatar_url":"https://github.com/esrrhs.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fake\n\n[\u003cimg src=\"https://img.shields.io/github/license/esrrhs/fake\"\u003e](https://github.com/esrrhs/fake)\n[\u003cimg src=\"https://img.shields.io/github/languages/top/esrrhs/fake\"\u003e](https://github.com/esrrhs/fake)\n[\u003cimg src=\"https://img.shields.io/github/v/release/esrrhs/fake\"\u003e](https://github.com/esrrhs/fake)\n[![Codacy Badge](https://api.codacy.com/project/badge/Grade/450723e1bc374ccd8aac7154227c69d7)](https://www.codacy.com/manual/esrrhs/fake?utm_source=github.com\u0026amp;utm_medium=referral\u0026amp;utm_content=esrrhs/fake\u0026amp;utm_campaign=Badge_Grade)\n[\u003cimg src=\"https://img.shields.io/github/actions/workflow/status/esrrhs/fake/ccpp.yml?branch=master\"\u003e](https://github.com/esrrhs/fake/actions)\n\n轻量级嵌入式脚本语言\n\n[README_EN](./README_EN.md)\n\n## 简介\n**fake**是一款轻量级的嵌入式脚本语言, 使用c++语言编写, 语法吸取自lua、golang、erlang, 基于flex、bison生成语法树, 编译成字节码解释执行。\n\n[Java版本fake](https://github.com/esrrhs/fakejava)\n\n[Go版本fake](https://github.com/esrrhs/fakego)\n\n\n## 脚本特性\n* 运行环境linux amd64、MacOS amd64\n* 支持VM, JIT(实验性质)\n* 支持fake testfunc(param1)产生routine, 在单线程上实现多线程效果(此特性不支持JIT)\n* 支持调试, 自带gdb风格的命令行调试器, 以及VS风格的可视化编辑调试ide, 也可在C里直接通过接口调用, 开始命令行调试\n* 支持热更新\n* 支持C风格函数和C++类成员函数的绑定\n* 支持profile, 可获取脚本各个函数运行时间\n* 支持array, map, 可以无限嵌套\n* 支持多返回值\n* 支持Int64\n* 支持const定义\n* 支持包\n* 支持struct\n* 支持打包bin文件或可执行文件\n\n## 产品应用\n![image](img/use3.jpg)[疯狂炸翻天](https://www.muzhiwan.com/com.fkzft.gamewin.mzw.html)\n![image](img/use1.jpg)[我是大主宰](http://dzz.youxi.com)\n![image](img/use2.jpg)[天天炫斗](http://ttxd.qq.com/act/a20160419brandP/)\n\n## 示例\n\n```\n\n\n-- 当前包名\npackage mypackage.test\n\n-- 引入的文件\ninclude \"common.fk\"\n\n-- 结构体定义\nstruct teststruct\n\tsample_a\n\tsample_b\n\tsample_c\nend\n\n-- 常量值\nconst hellostring = \"hello\"\nconst helloint = 1234\nconst hellomap = {1 : \"a\" 2 : \"b\" 3 : [1 2 3]}\n\n-- func1 comment\nfunc myfunc1(arg1, arg2)\n\t\n\t-- C函数和类成员函数的调用\n\targ3 := cfunc1(helloint) + arg2:memfunc1(arg1)\n\t\n\t-- 分支\n\tif arg1 \u003c arg2 then\t\n\t\t-- 创建一个协程\n\t\tfake myfunc2(arg1, arg2)\n\telseif arg1 == arg2 then\t\n\t\tprint(\"elseif\")\n\telse\n\t\tprint(\"else\")\n\tend\n\t\n\t-- for循环\n\tfor var i = 0, i \u003c arg2, i++ then\n\t\tprint(\"i = \", i)\n\tend\n\t\n\t-- 数组\n\tvar a = array()\n\ta[1] = 3\n\t\n\t-- 集合\n\tvar b = map()\n\tb[a] = 1\n\tb[1] = a\n\t\n\t-- Int64\n\tvar uid = 1241515236123614u\n\tlog(\"uid = \", uid)\n\n\t-- 子函数调用\n\tvar ret1, var ret2 = myfunc2()\n\n\t-- 其他包的函数调用\n\tret1 = otherpackage.test.myfunc1(arg1, arg2)\n\t\n\t-- 结构体\n\tvar tt = teststruct()\n\ttt-\u003esample_a = 1\n\ttt-\u003esample_b = teststruct()\n\ttt-\u003esample_b-\u003esample_a = 10\n\n\t-- 分支\n\tswitch arg1\n\t\tcase 1 then\n\t\t\tprint(\"1\")\n\t\tcase \"a\" then\n\t\t\tprint(\"a\")\n\t\tdefault\n\t\t\tprint(\"default\")\n\tend\n\n\t-- 多返回值\n\treturn arg1, arg3\n\t\nend\n```\n\n## C++示例\n\n```\n// 创建一个实例\nfake * fk = newfake();\n// 注册全局函数\nfkreg(fk, \"cfunc1\", cfunc1);\n// 注册类成员函数, 不同的类注册一样的函数名字不冲突\nfkreg(fk, \"memfunc1\", \u0026class1::memfunc1);\n// 解析fake脚本文件\nfkparse(fk, argv[1]);\n// 执行myfunc1函数, 传入两个参数分别为1和2\nret = fkrun\u003cint\u003e(fk, \"myfunc1\", 1, 2);\n// 删除实例\ndelfake(fk);\n```\n\n\n## 性能比较\n运行```cd benchmark/ \u0026\u0026 ./benchmark.sh```\n,在MacBook Pro 2.3 GHz Intel Core i5上的数据\n\n|       | Lua   | Python |  Fake | Fake JIT |\n|-------|-------|:------:|------:|----------|\n| Loop  | 0.8s  |  2.3s  |  1.3s | 0.2s     |\n| Prime | 13.5s |  20.9s | 12.8s | 5.9s     |\n| String | 0.8s |  0.4s | 1.2s | 3.2s     |\n\n注：因为JIT目前无法GC，所以String反而最慢\n\n## 如何使用\n复制 include/**fake-inc.h** 和 bin/**libfake.so** 到你的工程, 直接使用\n\n\n## 如何编译\n1. 安装cmake\n2. (可选)安装flex, bison, 运行```./gen.sh```\n3. 安装gcc, gcc-c++\n4. ```./build.sh``` 或者 ```./build.sh release```\n\n## 测试示例\n1. test/sample 目录下有脚本示例代码\n2. 运行方法 ```cd test \u0026\u0026 ./test.sh```\n3. bin/fakebin 为可执行文件，可以自己编写运行，如：```./fakebin your.fk```\n\n\n## 调试环境\n* IDE **（bin/fakeide.app）**\n\n![image](img/ide.png)\n\n* 命令行 **（bin/fakebin）**\n\n![image](img/debug.png)\n\n## Stargazers over time\n\n[![Stargazers over time](https://starchart.cc/esrrhs/fake.svg)](https://starchart.cc/esrrhs/fake)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fesrrhs%2Ffake","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fesrrhs%2Ffake","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fesrrhs%2Ffake/lists"}