diff --git a/scripts/bgfx-codegen.lua b/scripts/bgfx-codegen.lua index 6b253e31f..4069b933f 100644 --- a/scripts/bgfx-codegen.lua +++ b/scripts/bgfx-codegen.lua @@ -1,9 +1,8 @@ -- 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" -local doxygen = require "doxygen" +local idl = codegen.idl "bgfx.idl" local func_actions = { @@ -31,14 +30,6 @@ local type_actions = { cfuncptrs = "\n", } -do - local source = doxygen.load "bgfx.idl" - local f = assert(load(source, "bgfx.idl" , "t", idl)) - f() -end - -codegen.nameconversion(idl.types, idl.funcs) - local function cfunc(f) return function(func) if not func.cpponly then diff --git a/scripts/codegen.lua b/scripts/codegen.lua index 63949262e..2d90cc223 100644 --- a/scripts/codegen.lua +++ b/scripts/codegen.lua @@ -248,7 +248,7 @@ local function calc_flag_values(flag) value = index + base - 1 end if value >= cap then - error (string.format("Out of range for %s (%d/%d)", name, value, cap)) + error (string.format("Out of range for %s.%s (%d/%d)", flag.name, item.name, value, cap)) end value = value << shift elseif #item == 0 then @@ -964,4 +964,31 @@ function codegen.gen_handle(handle) return (handle_temp:gsub("$(%u+)", { NAME = handle.name })) end +local idl = require "idl" +local doxygen = require "doxygen" +local conversion +local idlfile = {} + +function codegen.load(filename) + assert(conversion == nil, "Don't call codegen.load() after codegen.idl()") + assert(idlfile[filename] == nil, "Duplicate load " .. filename) + local source = doxygen.load(filename) + + local f = assert(load(source, filename , "t", idl)) + f() + idlfile[filename] = true +end + +function codegen.idl(filename) + if conversion == nil then + if filename and not idlfile[filename] then + codegen.load(filename) + end + assert(next(idlfile), "call codegen.load() first") + conversion = true + codegen.nameconversion(idl.types, idl.funcs) + end + return idl +end + return codegen diff --git a/scripts/csharp.lua b/scripts/csharp.lua index 7a5388932..f0a1cdc2f 100644 --- a/scripts/csharp.lua +++ b/scripts/csharp.lua @@ -1,14 +1,5 @@ -local idl = require "idl" - -do - local doxygen = require "doxygen" - local source = doxygen.load "bgfx.idl" - local f = assert(load(source, "bgfx.idl" , "t", idl)) - f() - - local codegen = require "codegen" - codegen.nameconversion(idl.types, idl.funcs) -end +local codegen = require "codegen" +local idl = codegen.idl "bgfx.idl" local csharp_template = [[ using System; diff --git a/scripts/doxygen.lua b/scripts/doxygen.lua index e2607d2fd..531210e7b 100644 --- a/scripts/doxygen.lua +++ b/scripts/doxygen.lua @@ -1,5 +1,3 @@ -local idl = require "idl" - local doxygen = {} function doxygen.load(filename)