Tiny C Compiler 0.9.26 binding for LuaJIT
-- Additional OO style for TCCState
tcc.delete(state)
-- or
state:delete()
-- Constants can be used in two ways
state:set_output_type(tcc.const.output_dll)
-- or
state:set_output_type('output_dll')
Binding is so close to the original API as possible, but some things still differ.
Before calling tcc functions you need to initialize binding with library name or path. Luajit uses dynamic library loading API directly, so behaviour may be different on each OS. Filename and location of tcc library may also vary. Several examples:
-- Windows
local tcc = require 'tcc' ('libtcc')
local tcc = require 'tcc' ('../some/path/libtcc.dll')
local tcc = require 'tcc' ('libtcc')
local state = tcc.new()
state:set_output_type('output_memory')
state:compile_string [[
int summ(int a, int b)
{
return a + b;
}
]]
state:relocate('relocate_auto')
local summ = state:get_symbol('summ', 'int(*)(int,int)')
print('5 + 7 = ' .. summ(5,7))
state:delete()