Skip to content

Tiny C Compiler 0.9.26 binding for LuaJIT

License

Notifications You must be signed in to change notification settings

Hel00/luajit-tcc

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Features

  • Full support of 0.9.26 API
 -- 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')

Differences from the C API

Binding is so close to the original API as possible, but some things still differ.

  1. Names lost 'tcc_' prefix as not needed.
  2. 'tcc.add_symbol' and 'tcc.get_symbol' have optional argument for in-place cast.
  3. 'tcc.run' accept table instead of argc-argv pair.

Start using

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')

Example code

  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()

About

Tiny C Compiler 0.9.26 binding for LuaJIT

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Lua 100.0%