|
@@ -29,34 +29,55 @@ internal struct NativeFunctions
|
|
|
}
|
|
}
|
|
|
]]
|
|
]]
|
|
|
|
|
|
|
|
|
|
+local function hasPrefix(str, prefix)
|
|
|
|
|
+ return prefix == "" or str:sub(1, #prefix) == prefix
|
|
|
|
|
+end
|
|
|
|
|
+
|
|
|
local function hasSuffix(str, suffix)
|
|
local function hasSuffix(str, suffix)
|
|
|
return suffix == "" or str:sub(-#suffix) == suffix
|
|
return suffix == "" or str:sub(-#suffix) == suffix
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
local function convert_type_0(arg)
|
|
local function convert_type_0(arg)
|
|
|
|
|
|
|
|
- if arg.ctype == "uint64_t" then
|
|
|
|
|
- return "ulong"
|
|
|
|
|
- elseif arg.ctype == "uint32_t" then
|
|
|
|
|
- return "uint"
|
|
|
|
|
- elseif arg.ctype == "uint16_t" then
|
|
|
|
|
|
|
+ if hasPrefix(arg.ctype, "uint64_t") then
|
|
|
|
|
+ return arg.ctype:gsub("uint64_t", "ulong")
|
|
|
|
|
+ elseif hasPrefix(arg.ctype, "uint32_t") then
|
|
|
|
|
+ return arg.ctype:gsub("uint32_t", "uint")
|
|
|
|
|
+ elseif hasPrefix(arg.ctype, "int32_t") then
|
|
|
|
|
+ return arg.ctype:gsub("int32_t", "int")
|
|
|
|
|
+ elseif hasPrefix(arg.ctype, "uint16_t") then
|
|
|
|
|
+ return arg.ctype:gsub("uint16_t", "ushort")
|
|
|
|
|
+ elseif arg.ctype == "bgfx_view_id_t" then
|
|
|
return "ushort"
|
|
return "ushort"
|
|
|
- elseif arg.ctype == "uint8_t" then
|
|
|
|
|
- return "byte"
|
|
|
|
|
|
|
+ elseif hasPrefix(arg.ctype, "uint8_t") then
|
|
|
|
|
+ return arg.ctype:gsub("uint8_t", "byte")
|
|
|
|
|
+ elseif hasPrefix(arg.ctype, "uintptr_t") then
|
|
|
|
|
+ return arg.ctype:gsub("uintptr_t", "UIntPtr")
|
|
|
elseif arg.ctype == "const char*" then
|
|
elseif arg.ctype == "const char*" then
|
|
|
return "[MarshalAs(UnmanagedType.LPStr)] string"
|
|
return "[MarshalAs(UnmanagedType.LPStr)] string"
|
|
|
elseif hasSuffix(arg.fulltype, "Handle") then
|
|
elseif hasSuffix(arg.fulltype, "Handle") then
|
|
|
return arg.fulltype
|
|
return arg.fulltype
|
|
|
- elseif hasSuffix(arg.fulltype, "::Enum") then
|
|
|
|
|
- return arg.fulltype:gsub("::Enum", "")
|
|
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
- return arg.ctype
|
|
|
|
|
|
|
+ return arg.fulltype
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
local function convert_type(arg)
|
|
local function convert_type(arg)
|
|
|
local ctype = convert_type_0(arg)
|
|
local ctype = convert_type_0(arg)
|
|
|
- return ctype:gsub("const ", "")
|
|
|
|
|
|
|
+ ctype = ctype:gsub("::Enum", "")
|
|
|
|
|
+ ctype = ctype:gsub("const ", "")
|
|
|
|
|
+ ctype = ctype:gsub(" &", "*")
|
|
|
|
|
+ ctype = ctype:gsub("&", "*")
|
|
|
|
|
+ return ctype
|
|
|
|
|
+end
|
|
|
|
|
+
|
|
|
|
|
+local function convert_ret_type(arg)
|
|
|
|
|
+ local ctype = convert_type(arg)
|
|
|
|
|
+ if hasPrefix(ctype, "[MarshalAs(UnmanagedType.LPStr)]") then
|
|
|
|
|
+ return "string"
|
|
|
|
|
+ end
|
|
|
|
|
+
|
|
|
|
|
+ return ctype
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
local converter = {}
|
|
local converter = {}
|
|
@@ -100,7 +121,7 @@ local function FlagBlock(typ)
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
local format = "0x%08x"
|
|
local format = "0x%08x"
|
|
|
- local enumType = ""
|
|
|
|
|
|
|
+ local enumType = " : uint"
|
|
|
if typ.bits == 64 then
|
|
if typ.bits == 64 then
|
|
|
format = "0x%016x"
|
|
format = "0x%016x"
|
|
|
enumType = " : ulong"
|
|
enumType = " : ulong"
|
|
@@ -220,7 +241,9 @@ function converter.funcs(func)
|
|
|
yield("[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]")
|
|
yield("[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]")
|
|
|
|
|
|
|
|
if func.ret.cpptype == "bool" then
|
|
if func.ret.cpptype == "bool" then
|
|
|
- yield("[return: MarshalAs(UnmanagedType:I1)]")
|
|
|
|
|
|
|
+ yield("[return: MarshalAs(UnmanagedType.I1)]")
|
|
|
|
|
+ elseif func.ret.cpptype == "const char*" then
|
|
|
|
|
+ yield("[return: MarshalAs(UnmanagedType.LPStr)]")
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
local first = ""
|
|
local first = ""
|
|
@@ -234,7 +257,7 @@ function converter.funcs(func)
|
|
|
first = ", "
|
|
first = ", "
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
- yield("internal static extern unsafe " .. convert_type(func.ret) .. " bgfx_" .. func.cname .. args .. ");")
|
|
|
|
|
|
|
+ yield("internal static extern unsafe " .. convert_ret_type(func.ret) .. " bgfx_" .. func.cname .. args .. ");")
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
print(gen())
|
|
print(gen())
|