Monday, November 14, 2011

Package required to make calls from "Lua" to "C" and vice-versa

Lua provides the facility to make calls to C programs and also has the ability to be called from the C program.

I got a problem of being unable to get the required liblua5.1.so files which are essential for this type of communication to happen. So I finally found out what package I need to install to get this working.

One needs to install the "liblua5.1-dev" package and with this all the required files will be updated. You just need to fire this command:-

rahul@ubuntu32$ sudo apt-get install liblua5.1-dev

Once its installed, you can see the path of all the shared libraries "liblua5.1.so" by running the following commands:-

rahul@ubuntu32$ sudo updatedb
rahul@ubuntu32$ locate liblua | less

If you want to get the path of lua.h file, fire the command:-

rahul@ubuntu32$ sudo updatedb
rahul@ubuntu32$ locate /lua.h

Now you have the path of Include files and the shared libraries. Just create the shared library from the "C" program and then run the lua program. You would be able to call C program from the lua program.

A nice tutorial about this is given on the website "http://www.troubleshooters.com/codecorn/lua/lua_lua_calls_c.htm". Do have a look there for more details.


No comments:

Post a Comment