m-schmoock/lcpp

export #defines to lua code

aergo20 opened this issue · 2 comments

Hi

The code below causes an error

local lcpp = require("lcpp")
ffi.cdef[[
#define numberOne 1
]]
print(ffi.C.numberOne)

how to get the #define from cdef ?

Thanks

Hey, sorry for late answer. Currently it works like this (copy and paste in your LuaJIT console):

ffi = require("ffi")
lcpp = require("lcpp")
ffi.cdef[[#define numberOne 1]]
=ffi.lcpp_defs.numberOne

The define is not bount to ffi.C because it would make sense to have preprocessor macros and defines there, but only C symbols. The macros and defines are parsed whenever ffi.cdef is used from now automatically so that the next call will work from now: ffi.cdef[[static int foobar = numberOne]] and then ffi.C.foobar := 1. However as you can see the LCPP Preprocessor defines are stored here: ffi.lcpp_defs .

Thanks