2020-02-27 17:01:34 +00:00
|
|
|
local keywords = {
|
|
|
|
"int", "long", "short", "char", "float", "double",
|
|
|
|
"uint8_t", "uint16_t", "uint32_t", "uint64_t",
|
|
|
|
"const", "unsigned", "register",
|
|
|
|
"void", "intptr_t", "bool"
|
|
|
|
}
|
|
|
|
|
|
|
|
local structs = {
|
|
|
|
"Vector2", "Vector3", "Vector4", "Quaternion",
|
|
|
|
"Matrix", "Color", "Rectangle", "Image", "Texture", "Texture2D",
|
2021-10-02 17:03:57 +00:00
|
|
|
"RenderTexture", "NPatchInfo", "GlyphInfo", "Font",
|
2020-02-27 17:01:34 +00:00
|
|
|
"Camera", "Camera2D", "Mesh", "Shader", "MaterialMap",
|
|
|
|
"Material", "Model", "Transform", "BoneInfo", "ModelAnimation",
|
2021-10-02 17:03:57 +00:00
|
|
|
"Ray", "RayCollision", "BoundingBox", "Wave", "Sound", "Music",
|
2020-02-27 17:01:34 +00:00
|
|
|
"AudioStream", "VrDeviceInfo", "Camera3D", "RenderTexture2D",
|
2020-03-31 19:32:36 +00:00
|
|
|
"TextureCubemap", "TraceLogCallback", "PhysicsBody",
|
2021-02-16 21:25:45 +00:00
|
|
|
"GestureEvent", "GuiStyle", "GuiTextBoxState",
|
2021-05-01 18:21:00 +00:00
|
|
|
"TraceLogCallback", "VertexBuffer", "DrawCall", "RenderBatch",
|
2022-04-12 21:39:43 +00:00
|
|
|
"ShaderAttributeDataType", "MaterialMapIndex", "VrStereoConfig",
|
|
|
|
"AudioCallback"
|
2020-02-27 17:01:34 +00:00
|
|
|
}
|
|
|
|
|
2021-10-02 17:03:57 +00:00
|
|
|
local rl_structs = {
|
|
|
|
"rlTraceLogLevel", "rlPixelFormat", "rlTextureFilter",
|
|
|
|
"rlBlendMode", "rlShaderLocationIndex", "rlShaderUniformDataType",
|
|
|
|
"rlShaderAttributeDataType", "rlFramebufferAttachType",
|
|
|
|
"rlFramebufferAttachTextureType", "rlVertexBuffer", "rlDrawCall",
|
|
|
|
"rlRenderBatch"
|
|
|
|
}
|
|
|
|
|
2020-02-27 17:01:34 +00:00
|
|
|
local functions = {}
|
|
|
|
local proto = {}
|
|
|
|
|
2020-03-01 19:09:56 +00:00
|
|
|
local counter = 0
|
2021-10-24 11:16:32 +00:00
|
|
|
local file = io.open(arg[1], "wb")
|
|
|
|
local modules = { "api" }
|
|
|
|
local funcname
|
2020-03-01 19:09:56 +00:00
|
|
|
|
|
|
|
local custom_support = {
|
|
|
|
["rlgl"] = function (line)
|
2021-10-02 17:03:57 +00:00
|
|
|
return line:gsub("([%s*]+)(rl%w+)", function (pre, part)
|
2020-03-01 19:09:56 +00:00
|
|
|
functions[#functions + 1] = part
|
2021-10-24 11:16:32 +00:00
|
|
|
funcname = part
|
2020-03-01 19:09:56 +00:00
|
|
|
counter = counter + 1
|
|
|
|
|
|
|
|
if counter == 2 then
|
|
|
|
print("WARN: Multiple matches for: " .. line)
|
2020-02-27 17:01:34 +00:00
|
|
|
end
|
2020-03-01 19:09:56 +00:00
|
|
|
|
|
|
|
return "(*)"
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
}
|
|
|
|
|
|
|
|
for i=2,#arg do
|
|
|
|
modules[i] = arg[i]
|
|
|
|
end
|
|
|
|
|
2021-10-24 11:16:32 +00:00
|
|
|
file:write [[
|
|
|
|
struct raylua_bind_entry {
|
|
|
|
const char *name;
|
|
|
|
const char *proto;
|
|
|
|
void *ptr;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct raylua_bind_entry raylua_entries[] = {
|
|
|
|
]]
|
|
|
|
|
2020-03-01 19:09:56 +00:00
|
|
|
for _,modname in ipairs(modules) do
|
|
|
|
for line in io.lines("tools/" .. modname .. ".h") do
|
2021-10-24 11:16:32 +00:00
|
|
|
if line:sub(1, 2) ~= "//" then
|
|
|
|
if line:sub(1, 1) == "#" then
|
|
|
|
file:write(" " .. line .. "\n")
|
|
|
|
else
|
|
|
|
counter = 0
|
|
|
|
funcname = nil
|
|
|
|
|
|
|
|
if custom_support[modname] then
|
|
|
|
line = custom_support[modname](line)
|
|
|
|
end
|
2020-02-27 17:01:34 +00:00
|
|
|
|
2021-10-24 11:16:32 +00:00
|
|
|
line = line:gsub("(%W)([%l%d][%w_]*)", function (before, part)
|
|
|
|
for i,keyword in ipairs(keywords) do
|
|
|
|
if part == keyword
|
|
|
|
or part == "t" then -- uintX_t workaround
|
|
|
|
return before .. part
|
|
|
|
end
|
2021-02-16 21:25:45 +00:00
|
|
|
end
|
2020-02-27 17:01:34 +00:00
|
|
|
|
2021-10-24 11:16:32 +00:00
|
|
|
for i,s in ipairs(rl_structs) do
|
|
|
|
if part == s then
|
|
|
|
return before .. part
|
|
|
|
end
|
2021-10-02 17:03:57 +00:00
|
|
|
end
|
|
|
|
|
2021-10-24 11:16:32 +00:00
|
|
|
return before
|
|
|
|
end)
|
2020-02-27 17:01:34 +00:00
|
|
|
|
2021-10-24 11:16:32 +00:00
|
|
|
line = line:gsub("%u%w+", function (part)
|
|
|
|
for i,struct in ipairs(structs) do
|
|
|
|
if part == struct then
|
|
|
|
return part
|
|
|
|
end
|
2021-02-16 21:25:45 +00:00
|
|
|
end
|
2020-02-27 17:01:34 +00:00
|
|
|
|
2021-10-24 11:16:32 +00:00
|
|
|
functions[#functions + 1] = part
|
|
|
|
funcname = part
|
|
|
|
counter = counter + 1
|
2020-02-27 17:01:34 +00:00
|
|
|
|
2021-10-24 11:16:32 +00:00
|
|
|
if counter == 2 then
|
|
|
|
print("WARN: Multiple matches for: " .. line)
|
|
|
|
end
|
|
|
|
|
|
|
|
return "(*)"
|
|
|
|
end)
|
2020-03-01 19:09:56 +00:00
|
|
|
|
2021-10-24 11:16:32 +00:00
|
|
|
-- Strip spaces
|
|
|
|
line = line:gsub("([(),*.])%s+(%w)", function (a, b) return a .. b end)
|
|
|
|
line = line:gsub("(%w)%s+([(),*.])", function (a, b) return a .. b end)
|
2020-02-27 17:01:34 +00:00
|
|
|
|
2021-10-24 11:16:32 +00:00
|
|
|
proto[#proto + 1] = line
|
2020-02-27 17:01:34 +00:00
|
|
|
|
2021-10-24 11:16:32 +00:00
|
|
|
if funcname and line then
|
|
|
|
file:write(string.format(' { "%s", "%s", &%s },\n', funcname, line, funcname))
|
|
|
|
elseif counter == 0 then
|
|
|
|
print("WARN: Invalid entry", funcname, line)
|
|
|
|
end
|
|
|
|
end
|
2021-02-16 21:25:45 +00:00
|
|
|
end
|
2020-03-01 19:09:56 +00:00
|
|
|
end
|
2020-02-27 17:01:34 +00:00
|
|
|
end
|
|
|
|
|
2020-03-01 19:09:56 +00:00
|
|
|
assert(#proto == #functions, "Mismatching proto and function count : " ..
|
|
|
|
#proto .. " ~= " .. #functions)
|
2020-02-27 17:01:34 +00:00
|
|
|
|
2021-10-24 11:16:32 +00:00
|
|
|
print(string.format("Bound %d functions.", #proto))
|
2020-02-27 17:01:34 +00:00
|
|
|
|
2021-10-24 11:16:32 +00:00
|
|
|
file:write ' { NULL, NULL, NULL },\n'
|
2020-02-27 17:01:34 +00:00
|
|
|
file:write "};\n"
|
|
|
|
|
|
|
|
file:close()
|