Бранимир Караџић 6 years ago
parent
commit
3c1a6b061c
2 changed files with 37 additions and 33 deletions
  1. 36 32
      scripts/bgfx-idl.lua
  2. 1 1
      scripts/genie.lua

+ 36 - 32
scripts/bgfx-idl.lua

@@ -1,14 +1,16 @@
 -- Copyright 2019 云风 https://github.com/cloudwu . All rights reserved.
 -- License (the same with bgfx) : https://github.com/bkaradzic/bgfx/blob/master/LICENSE
 
-local idl     = require "idl"
-local codegen = require "codegen"
+function doIdl()
 
-assert(loadfile("bgfx.idl" , "t", idl))()
+	local idl     = require "idl"
+	local codegen = require "codegen"
 
-codegen.nameconversion(idl.types, idl.funcs)
+	assert(loadfile("bgfx.idl" , "t", idl))()
 
-local code_temp_include = [[
+	codegen.nameconversion(idl.types, idl.funcs)
+
+	local code_temp_include = [[
 /*
  * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
  */
@@ -27,7 +29,7 @@ typedef struct bgfx_interface_vtbl
 } bgfx_interface_vtbl_t;
 ]]
 
-local code_temp_impl = [[
+	local code_temp_impl = [[
 /*
  * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
  */
@@ -56,38 +58,40 @@ BGFX_C_API bgfx_interface_vtbl_t* bgfx_get_interface(uint32_t _version)
 }
 ]]
 
-local function codes()
-	local temp = {}
-	local action = {
-		c99 = "\n",
-		c99decl = "\n",
-		interface_struct = "\n\t",
-		interface_import = ",\n\t\t\t",
-	}
-	for k in pairs(action) do
-		temp[k] = {}
-	end
-	for _, f in ipairs(idl.funcs) do
+	local function codes()
+		local temp = {}
+		local action = {
+			c99 = "\n",
+			c99decl = "\n",
+			interface_struct = "\n\t",
+			interface_import = ",\n\t\t\t",
+		}
 		for k in pairs(action) do
-			table.insert(temp[k], (codegen["gen_"..k](f)))
+			temp[k] = {}
+		end
+		for _, f in ipairs(idl.funcs) do
+			for k in pairs(action) do
+				table.insert(temp[k], (codegen["gen_"..k](f)))
+			end
 		end
-	end
 
-	for k, ident in pairs(action) do
-		temp[k] = table.concat(temp[k], ident)
+		for k, ident in pairs(action) do
+			temp[k] = table.concat(temp[k], ident)
+		end
+
+		return temp
 	end
 
-	return temp
-end
+	local codes_tbl = codes()
 
-local codes_tbl = codes()
+	for filename, temp in pairs {
+		["../include/bgfx/c99/bgfx.idl.h"] = code_temp_include ,
+		["../src/bgfx.idl.inl"] = code_temp_impl } do
 
-for filename, temp in pairs {
-	["../include/bgfx/c99/bgfx.idl.h"] = code_temp_include ,
-	["../src/bgfx.idl.inl"] = code_temp_impl } do
+		print ("Generate " .. filename)
+		local out = io.open(filename, "wb")
+		out:write((temp:gsub("$([%l%d_]+)", codes_tbl)))
+		out:close()
+	end
 
-	print ("Generate " .. filename)
-	local out = io.open(filename, "wb")
-	out:write((temp:gsub("$([%l%d_]+)", codes_tbl)))
-	out:close()
 end

+ 1 - 1
scripts/genie.lua

@@ -53,7 +53,7 @@ dofile "bgfx-idl.lua"
 newaction {
 	trigger = "idl",
 	description = "Generate bgfx interface source code",
-	execute = doidl
+	execute = doIdl
 }
 
 solution "bgfx"