<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          fakescript腳本語言

          聯(lián)合創(chuàng)作 · 2023-09-27 23:37

          fake

          Author PlatformScript License

          輕量級嵌入式腳本語言

           

          簡介

          fake是一款輕量級的嵌入式腳本語言, 使用c++語言編寫, 語法吸取自lua、golang、erlang, 基于flex、bison生成語法樹, 編譯成字節(jié)碼解釋執(zhí)行。

           

          腳本特性

          • 運行環(huán)境linux amd64、MacOS amd64
          • 支持VM, JIT(實驗性質(zhì))
          • 支持fake testfunc(param1)產(chǎn)生routine, 在單線程上實現(xiàn)多線程效果(此特性不支持JIT)
          • 支持調(diào)試, 自帶gdb風格的命令行調(diào)試器, 以及VS風格的可視化編輯調(diào)試ide, 也可在C里直接通過接口調(diào)用, 開始命令行調(diào)試
          • 支持熱更新
          • 支持C風格函數(shù)和C++類成員函數(shù)的綁定
          • 支持profile, 可獲取腳本各個函數(shù)運行時間
          • 支持array, map, 可以無限嵌套
          • 支持多返回值
          • 支持Int64
          • 支持const定義
          • 支持包
          • 支持struct
          • 支持打包bin文件或可執(zhí)行文件

           

          產(chǎn)品應用

          瘋狂炸翻天 我是大主宰 天天炫斗

           

          示例

          
          
          -- 當前包名
          package mypackage.test
          
          -- 引入的文件
          include "common.fk"
          
          -- 結(jié)構體定義
          struct teststruct
          	sample_a
          	sample_b
          	sample_c
          end
          
          -- 常量值
          const hellostring = "hello"
          const helloint = 1234
          const hellomap = {1 : "a" 2 : "b" 3 : [1 2 3]}
          
          -- func1 comment
          func myfunc1(arg1, arg2)
          	
          	-- C函數(shù)和類成員函數(shù)的調(diào)用
          	arg3 := cfunc1(helloint) + arg2:memfunc1(arg1)
          	
          	-- 分支
          	if arg1 < arg2 then	
          		-- 創(chuàng)建一個協(xié)程
          		fake myfunc2(arg1, arg2)
          	elseif arg1 == arg2 then	
          		print("elseif")
          	else
          		print("else")
          	end
          	
          	-- for循環(huán)
          	for var i = 0, i < arg2, i++ then
          		print("i = ", i)
          	end
          	
          	-- 數(shù)組
          	var a = array()
          	a[1] = 3
          	
          	-- 集合
          	var b = map()
          	b[a] = 1
          	b[1] = a
          	
          	-- Int64
          	var uid = 1241515236123614u
          	log("uid = ", uid)
          
          	-- 子函數(shù)調(diào)用
          	var ret1, var ret2 = myfunc2()
          
          	-- 其他包的函數(shù)調(diào)用
          	ret1 = otherpackage.test.myfunc1(arg1, arg2)
          	
          	-- 結(jié)構體
          	var tt = teststruct()
          	tt->sample_a = 1
          	tt->sample_b = teststruct()
          	tt->sample_b->sample_a = 10
          
          	-- 分支
          	switch arg1
          		case 1 then
          			print("1")
          		case "a" then
          			print("a")
          		default
          			print("default")
          	end
          
          	-- 多返回值
          	return arg1, arg3
          	
          end
          

           

          C++示例

          // 創(chuàng)建一個實例
          fake * fk = newfake();
          // 注冊全局函數(shù)
          fkreg(fk, "cfunc1", cfunc1);
          // 注冊類成員函數(shù), 不同的類注冊一樣的函數(shù)名字不沖突
          fkreg(fk, "memfunc1", &class1::memfunc1);
          // 解析fake腳本文件
          fkparse(fk, argv[1]);
          // 執(zhí)行myfunc1函數(shù), 傳入兩個參數(shù)分別為1和2
          ret = fkrun<int>(fk, "myfunc1", 1, 2);
          // 刪除實例
          delfake(fk);
          

           

          性能比較

          運行cd benchmark/ && ./benchmark.sh ,在MacBook Pro 2.3 GHz Intel Core i5上的數(shù)據(jù)

            Lua Python Fake Fake JIT
          Loop 0.8s 2.3s 1.3s 0.2s
          Prime 13.5s 20.9s 12.8s 5.9s
          String 0.8s 0.4s 1.2s 3.2s

          注:因為JIT目前無法GC,所以String反而最慢

           

          如何使用

          復制 include/fake-inc.h 和 bin/libfake.so 到你的工程, 直接使用

           

          如何編譯

          1. 安裝cmake
          2. (可選)安裝flex, bison, 運行./gen.sh
          3. 安裝gcc, gcc-c++
          4. ./build.sh 或者 ./build.sh release

           

          測試示例

          1. test/sample 目錄下有腳本示例代碼
          2. 運行方法 cd test && ./test.sh
          3. bin/fakebin 為可執(zhí)行文件,可以自己編寫運行,如:./fakebin your.fk

           

          調(diào)試環(huán)境

          • IDE (bin/fakeide.app)

          • 命令行 (bin/fakebin)

          瀏覽 17
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          編輯 分享
          舉報
          評論
          圖片
          表情
          推薦
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          編輯 分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  4438成人网222 51精品一区二区三区 | 色哟哟无码精品一区二区三区 | 黄色成人观看网站 | 日本片A天堂 | 丁香婷婷五月天亚洲天堂 |