Skip to content

write c code inside your lua code. use gcc and luajit ffi to build and link while you run.

Notifications You must be signed in to change notification settings

thenumbernine/lua-ffi-c

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Write C/C++ code inline in your Lua code!

Donate via Stripe

For the lazy individuals who want to include optimized C++ code in their Lua code, but don't want to bother with compiling code, this is the library for you!

You can either manually invoke the compiler and the ffi prototype like so:

local cpp = require 'cpp'
local build = cpp:build[[ int sum(int a, int b) { return a + b; } ]]
local ffi = require 'ffi'
ffi.cdef[[ int sum(int a, int b); ]]
print(build.lib.sum(a,b))

or, for the truly lazy programmer, you can combine both these actions in one fell swoop:

local cpp = require 'cpp'
local build = cpp:func('int sum (int a, int b)', 'return a + 1;')
print(build.lib.sum(a,b))

Depends on my lua-ext, lua-template, and lua-make libraries

About

write c code inside your lua code. use gcc and luajit ffi to build and link while you run.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages