Skip to content

Development Specifications

i0gan edited this page Apr 12, 2024 · 2 revisions

C++

ref: https://google.github.io/styleguide/cppguide.html

Mainly follow Google naming conventions

File name

File names must be all lowercase and may contain underscores (_)

player_info.cc

player_info.h

Class name

Each word in the type name starts with a capital letter and does not contain underscores: MyExcitingClass, MyExcitingEnum. All type names—classes, structures, typedefs, enumerations use the same convention

Variable name

Variable names should always be lowercase, and words should be connected with underscores.

The member variables of the class end with an underscore, such as my_exciting_local_variable, my_exciting_member_variable_

Function name

Function names begin with a capital letter, with the first letter of each word capitalized, and no underscores: AddTableEntry()

Class' member set or get function:

class MyClass {
    public:
...
	int num_entries() const { return num_entries_; }
	void set_num_entries(int num_entries) { num_entries_ = num_entries; } private:
	int num_entries_;
};

Lua

File name

lowercase + underline

player_info.lua

Class name

Camel case method, capitalize the first letter [lua file name and class name are consistent]

Item = class("Item");

Function name

Camel case, capitalize the first letter

function Item:UpdateData(data)

end

Variable name

Local variable: Variable names should always be lowercase, and words should be connected with underscores.

Global variable: The first letter of global variables is capitalized, camel case

Const variable: uppercase and underlined

enumerate

All capital letters, multiple words separated by underscores

ENUM.CHAT_TYPE =
{
	WORLD           = 1,
	WHISPER         = 2,
}

Grammar

-- if..then..end、for..do..end、while..do.end、return、break, Each in its own line

for k,v in pairs(v) do

end

if i == 1 then
	return true;
end

while true do
	if i > max then
		break;
	end
end

ref: https://blog.csdn.net/diechenchen/article/details/108433899

Clone this wiki locally