客户端代码规范

本文详细规范了客户端的代码规范。

缩进

采用统一的缩进规则。

CSharp

Lua

文件名

采用大驼峰命名规则,例如 “MyFile.lua”。

类命名

虽然CinderLua类名只是一个字符串,但也需要符合命名规范。采用大驼峰命名规则,名词属性。

local M = class("MyClass")

return M

函数命名

采用大驼峰命名规则,动词属性。

function M:DoSomething()

end

私有函数

私有函数需要额外以“_”开头。

function M:_DoPrivateThing()

end

成员变量

NOTE: 除了框架结构上的需求,其余情况下不允许直接访问成员变量。

成员变量以“_”开头,采用小驼峰命名规则。

function M:ctor()
self._name = ""
end

临时变量,参数

采用小驼峰命名规则。

function M:DoSomething(x, y)
local theResult = x + y;
end

使用Cinder提供的class关键字。

local M = class("MyClass")

return M

接口

使用Cinder提供的interface关键字。

local M = interface("MyInterface")

return M

类实现接口

NOTE: 使用Cinder提供的include关键字来加载其他文件。

local MyInterface = include("MyInterface")

local M = class("MyClass").implement(MyInterface)

return M