Cloud Wu 6 years ago
parent
commit
4bc193f2e3
2 changed files with 18 additions and 6 deletions
  1. 2 5
      include/bgfx/c99/bgfx.h
  2. 16 1
      scripts/codegen.lua

+ 2 - 5
include/bgfx/c99/bgfx.h

@@ -864,11 +864,8 @@ typedef struct bgfx_vertex_decl_s
  * per thread should be used. Use `bgfx::begin()` to obtain an encoder for a thread.
  * per thread should be used. Use `bgfx::begin()` to obtain an encoder for a thread.
  *
  *
  */
  */
-typedef struct bgfx_encoder_s
-{
-	
-
-} bgfx_encoder_t;
+struct bgfx_encoder_s;
+typedef struct bgfx_encoder_s bgfx_encoder_t;
 
 
 
 
 
 

+ 16 - 1
scripts/codegen.lua

@@ -18,6 +18,14 @@ local function camelcase_to_underscorecase(name)
 	return table.concat(tmp, "_")
 	return table.concat(tmp, "_")
 end
 end
 
 
+local function underscorecase_to_camelcase(name)
+	local tmp = {}
+	for v in name:gmatch "[^_]+" do
+		tmp[#tmp+1] = v:sub(1,1):upper() .. v:sub(2)
+	end
+	return table.concat(tmp)
+end
+
 local function convert_funcname(name)
 local function convert_funcname(name)
 	name = name:gsub("^%l", string.upper)	-- Change to upper CamlCase
 	name = name:gsub("^%l", string.upper)	-- Change to upper CamlCase
 	return camelcase_to_underscorecase(name)
 	return camelcase_to_underscorecase(name)
@@ -426,6 +434,8 @@ local function codetemp(func)
 		RET = func.ret.fulltype,
 		RET = func.ret.fulltype,
 		CRET = func.ret.ctype,
 		CRET = func.ret.ctype,
 		CFUNCNAME = func.cname,
 		CFUNCNAME = func.cname,
+		CFUNCNAMEUPPER = func.cname:upper(),
+		CFUNCNAMECAML = underscorecase_to_camelcase(func.cname),
 		FUNCNAME = func.name,
 		FUNCNAME = func.name,
 		CARGS = table.concat(cargs, ", "),
 		CARGS = table.concat(cargs, ", "),
 		CPPARGS = table.concat(args, ", "),
 		CPPARGS = table.concat(args, ", "),
@@ -734,6 +744,10 @@ typedef struct $NAME_s
 
 
 } $NAME_t;
 } $NAME_t;
 ]]
 ]]
+local cstruct_empty_temp = [[
+struct $NAME_s;
+typedef struct $NAME_s $NAME_t;
+]]
 function codegen.gen_struct_cdefine(struct)
 function codegen.gen_struct_cdefine(struct)
 	assert(type(struct.struct) == "table", "Not a struct")
 	assert(type(struct.struct) == "table", "Not a struct")
 	local cname = struct.cname:match "(.-)_t$"
 	local cname = struct.cname:match "(.-)_t$"
@@ -745,7 +759,8 @@ function codegen.gen_struct_cdefine(struct)
 		NAME = cname,
 		NAME = cname,
 		ITEMS = table.concat(items, "\n\t"),
 		ITEMS = table.concat(items, "\n\t"),
 	}
 	}
-	return (cstruct_temp:gsub("$(%u+)", temp))
+	local codetemp = #struct.struct == 0 and cstruct_empty_temp or cstruct_temp
+	return (codetemp:gsub("$(%u+)", temp))
 end
 end
 
 
 local chandle_temp = [[
 local chandle_temp = [[