# LuaKit **Repository Path**: halo_117/LuaKit ## Basic Information - **Project Name**: LuaKit - **Description**: No description available - **Primary Language**: Lua - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-03-11 - **Last Updated**: 2024-04-15 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # LuaKit 旨在封装通用的接口与设计模式 ## 支持面向对象 ``` lua --[[--描述信息 @Author: myc @Date: 2019-06-17 10:39:37 @Last Modified by YuchengMo @Last Modified time 2019-06-17 11:03:23 ]] require("LuaKit"); local Test = class("Test") --类名 function Test:ctor( ... ) --构造函数 dump("ctor") end function Test:dtor( ... ) --析构函数 dump("Test:dtor") end function Test:print( ... ) --测试接口 dump(...) end local TestA = class("Test",Test);--类名,父类 function TestA:ctor( ... ) self.super.ctor(self); --先调用父类构造函数 dump({...},"TestA:ctor") end function TestA:dtor( ... ) dump("TestA:dtor") --析构自身 self.super.dtor(self);--析构父类 end function TestA:print( ... ) dump({...}) end local t = new(TestA,"myc") t:print("myc","is","man") delete(t) ``` ### 构建属性geter和seter 使用属性构建器,可以方便的实现一个属性的修改获取监听,例如修改了x属性,则调用底层接口驱动更新UI ```lua require("LuaKit"); local myPoint = {} getset.init(myPoint) myPoint.x = mk_property(function(self,key) --获取属性值,这里使用_x代替x return self._x end,function( self,key,value) --修改了属性值,这里使用_x代替x,可以广播派发事件,例如修改UI -- dispatch(...) self._x = value end) myPoint.x = 41 dump(myPoint) ``` ## 常用辅助类 ### dump ```lua local player = {}; player.money = 100; player.uid = "12dcc1dcxfsdfdvdvg"; player.name = "myc" dump(player)--打印玩家数据 dumpToFile("player",player)--存储数据到本地,保存格式为lua table ``` ### 性能检测工具profiler ```lua local player = {}; player.money = 100; player.uid = "12dcc1dcxfsdfdvdvg"; player.name = "myc" local profiler = newProfiler("call") -- profiler:start() --开启性能分析 dump(player) --要测试的代码 profiler:stop() --结束分析 profiler:dumpReportToFile( "profiler.txt" ) --输出报告保存到文件 --以下是输出结果 --[[-- Total time spent in profiled functions: 0.001s Total call count spent in profiled functions: 148 Lua Profile output created by profiler.lua. author: myc ------------------------------------------------------------------------------------------------ | FILE : FUNCTION : TIME : % : Call count| ------------------------------------------------------------------------------------------------ | L:E:\lua\5.1\lua\LuaKit\utils\dump.lua:42 : dump : 0.0010 : 100.0 : 1 | | L:E:\lua\5.1\lua\LuaKit\lib\StringLib.lua:255 : split : 0.0010 : 100.0 : 1 | | C:insert@=[C]:-1 : insert : ~ : ~ : 4 | | C:format@=[C]:-1 : format : ~ : ~ : 17 | | C:(for generator)@=[C]:-1 : (for generator) : ~ : ~ : 5 | | C:@=[C]:-1 : unknow : ~ : ~ : 17 | | C:ipairs@=[C]:-1 : ipairs : ~ : ~ : 2 | | C:(for generator)@=[C]:-1 : (for generator) : ~ : ~ : 4 | | C:print@=[C]:-1 : print : ~ : ~ : 2 | | C:sub@=[C]:-1 : sub : ~ : ~ : 4 | | C:debug_traceback@=[C]:-1 : debug_traceback : ~ : ~ : 1 | | L:E:\lua\5.1\lua\LuaKit\utils\dump.lua:52 : _dump : ~ : ~ : 4 | | C:clockNow@=[C]:-1 : clockNow : ~ : ~ : 1 | | C:string_rep@=[C]:-1 : string_rep : ~ : ~ : 3 | | L:E:\lua\5.1\lua\LuaKit\utils\profiler.lua:159: stop : ~ : ~ : 1 | | C:find@=[C]:-1 : find : ~ : ~ : 4 | | C:concat@=[C]:-1 : concat : ~ : ~ : 1 | | C:type@=[C]:-1 : type : ~ : ~ : 48 | | C:pairs@=[C]:-1 : pairs : ~ : ~ : 1 | | L:E:\lua\5.1\lua\LuaKit\lib\StringLib.lua:259 : (for generator) : ~ : ~ : 4 | | C:string_len@=[C]:-1 : string_len : ~ : ~ : 6 | | C:gsub@=[C]:-1 : gsub : ~ : ~ : 2 | | L:E:\lua\5.1\lua\LuaKit\utils\dump.lua:22 : _dump_value : ~ : ~ : 13 | | C:sethook@=[C]:-1 : sethook : ~ : ~ : 1 | | L:E:\lua\5.1\lua\LuaKit\lib\StringLib.lua:1625: trim : ~ : ~ : 1 | ------------------------------------------------------------------------------------------------ ]] ```