v4k-git-backup/tools/luajit_make_bindings.lua

79 lines
1.4 KiB
Lua
Raw Normal View History

local lcpp = require("tools/luajit_lcpp")
local glue = [[
#define __TINYC__
#define static
#define __thread
typedef struct FILE FILE;
typedef long int ptrdiff_t;
typedef long unsigned int size_t;
]]
function trim_multilines(str)
local lines = str:gmatch("([^\r\n]+)\r?\n?")
local output = lines()
for line in lines do
output = output .. "\n" .. line
end
return output
end
2023-08-10 14:30:56 +00:00
io.input("./engine/v4k.h")
local v4k_h = io.read("*all")
v4k_h = v4k_h:gsub("#line", "//#line")
v4k_h = v4k_h:gsub("#include", "//#include")
print('--autogenerated luajit bindings. do not edit.') -- .. os.date("%Y/%m/%d"))
print('local ffi = require("ffi")')
print('ffi.cdef([[')
2023-08-10 14:30:56 +00:00
local result = lcpp.compile(glue .. v4k_h)
print( trim_multilines(result) )
print(']])')
print([[
local _M = {}
function _M.vec2(x,y)
local v = ffi.new("union vec2")
v.x = x
v.y = y
return v
end
function _M.vec3(x,y,z)
local v = ffi.new("union vec3")
v.x = x
v.y = y
v.z = z
return v
end
function _M.vec4(x,y,z,w)
local v = ffi.new("union vec4")
v.x = x
v.y = y
v.z = z
v.w = w
return v
end
function _M.quat(x,y,z,w)
local q = ffi.new("union quat")
v.x = x
v.y = y
v.z = z
v.w = w
return q
end
function _M.mat44()
local m = ffi.new("float [16]")
return m
end
2023-08-10 14:30:56 +00:00
local v4k = ffi.load("v4k")
return setmetatable( _M, {
__index = function( table, key )
2023-08-10 14:30:56 +00:00
return v4k[ key ]
end
} )
]])