1

Can we dynamically create a function from string and call a ffi.C binding? example :

ffi.cdef [[

void foo_bar_A_get_info(void);
void foo_bar_B_get_info(void);

]]

some = ffi.load("some.so")
function call_fun(var)
    -- var can be A or B
    some.foo_bar_var_get_info()
end

call_fun("A")
call_fun("B")

I am getting error : missing declaration for symbol 'foo_bar_var_get_info'

I searched online a lot but could not find any way to do it, so wanted to post it here so someone can help.

1
  • would some["foo_bar_"..var.."_get_info"]() work? Commented May 22, 2014 at 21:30

1 Answer 1

4

C libraries loaded from the FFI are indexed just like Lua table; you can index them with a raw value in the same way:

some["foo_bar"..some_string.."_baz"]()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.