bullet3/build3/bin2cpp.lua
erwincoumans 794c8ec064 add BspDemo.bsp data file
add sphere2.urdf
move btSpatialAlgebra into LinearMath
remove some warnings, introduce BT_ZERO, BT_ONE, BT_HALF as defines for 0.f/0., 1.f/1., 0.5f/0.5 respectively
2015-04-16 10:17:35 -07:00

48 lines
1.3 KiB
Lua

function convertFile(filenameIn, filenameOut, stringname)
print("\nfilenameOut = " .. filenameOut)
local f = assert(io.open(filenameIn, "rb"))
local fw = io.open(filenameOut,"w")
fw:write(string.format("char %s[]={", stringname))
local block = 10
while true do
local bytes = f:read(block)
if not bytes then break end
for b in string.gfind(bytes, ".") do
fw:write(string.format("%u,", string.byte(b)))
end
--io.write(string.rep(" ", block - string.len(bytes) + 1))
--io.write(string.gsub(bytes, "%c", "."), "\n")
fw:write(string.format("\n"))
end
fw:write(string.format("\n};"))
end
newoption {
trigger = "binfile",
value = "binpath",
description = "full path to the binary input file"
}
newoption {
trigger = "cppfile",
value = "path",
description = "full path to the cpp output file"
}
newoption {
trigger = "stringname",
value = "var",
description = "name of the variable name in the cppfile that contains the binary data"
}
newaction {
trigger = "bin2cpp",
description = "convert binary file into cpp source",
execute = function ()
convertFile( _OPTIONS["binfile"] , _OPTIONS["cppfile"], _OPTIONS["stringname"])
end
}