2

Can someone tell me is it possible to somehow call c function or simply wrap it into a lua function WITHOUT building a new module.

unresolved_external
  • 1,930
  • 5
  • 30
  • 65

3 Answers3

6

If it works for you, try the FFI library. See also luaffi.

lhf
  • 70,581
  • 9
  • 108
  • 149
5

Lua can't call arbitrary C functions - they have to be bound to something in the Lua namespace first. (This is intentional to prevent breaking out of sandboxes in embedded applications.)

Amber
  • 507,862
  • 82
  • 626
  • 550
  • so as far as I understand I have two ways to solve this problem: first - run lua script from C, and than wrap C functions and push them into a stack, and second - build a new module for lua. Am I right? – unresolved_external Oct 03 '11 at 13:06
  • Correct. You can dynamically bind C functions via the C API, or you can create a module that does that binding. – Amber Oct 03 '11 at 13:11
3

Or the Alien library.

jpjacobs
  • 9,359
  • 36
  • 45