因为公司转整体转战js,遂决定开源,历时一年多的优化,经历了一个完整项目的测试,有兴趣的同学可以看下。
不排除还有bug,有兴趣的可以邮件联系我,也可以自行修改尝试。项目相关代码基于保密协议已经去掉。
总之一句话,给1年多的心血留下一条生路。源码我打包放在群文件里了(luapp.zip),luapp.lua文件末尾有简单示例,部分示例代码可能已经陈旧,参照文件头版本日志吧。群号:386217855。
注:文件编码大部分为GBK,mac需要转码才能看到注释。
主要功能: 所有关键字功能 参考C++实现
提供了面向对象的基于class的全局变量static
提供了强制类型转换以及绑定userdata的机制
提供C++权限管理 以及 virtual final overwrite staticconst 等等 修饰符
提供了Release运行模式移除大部分检查校验以提高运行效率。
提供了无序引用以及运行过程中添加替换指定类,主要用于热更新,隐藏了动态编译过程,有性能需求也可以提前编译。
具体功能关注源码吧。太多东西都是细节不想一一叙述了。
简单的例子:
local public, private, protected = ppclass(“GameScene”, “CGScene”);
if public == nil then return; end
require “src.game.Engine.REngine”
private._gameEngine = nil;
function public:GameScene()
self._gameEngine = ppnew(“REngine”);
self._gameEngine:showEngine(self);
local keylistener = cc.EventListenerKeyboard:create();
keylistener:registerScriptHandler(
function(key, event)
end, cc.Handler.EVENT_KEYBOARD_PRESSED);
keylistener:registerScriptHandler(
function(key, event)
if cc.KeyCodeKey[key] == "KEY_BREAK" then
--[[
if ppstatic("CGGameManager"):instance():isInTargetView() then return; end
if ppstatic("CGGuideManager"):instance():isGuiding() then return; end
if ppstatic("CGBattleManager"):instance()._victory then return; end
ppstatic("CGEventManager"):instance():activeEvent("battle");
--]]
elseif cc.KeyCodeKey[key] == "KEY_HOME" then
--ppstatic("CGSdkManager"):pauseGame();
elseif cc.KeyCodeKey[key] == "KEY_MENU" then
local text = ppstatic("CGLOG"):getWindowShow();
if text then
text:setPosition(ppstatic("VisibleRect"):center());
self:addChild(text, 1000);
end
end
end, cc.Handler.EVENT_KEYBOARD_RELEASED);
self:getEventDispatcher():addEventListenerWithSceneGraphPriority(keylistener, ppblandget(self));
end
function public:_GameScene()
if self._gameEngine ~= nil then
self._gameEngine:pprelease();
self._gameEngine = nil;
end
end
