Sunday, April 2, 2017

Calling C++ function from Lua

I tried to follow this example, but compiling failed.

The example was for Lua 5.1, while I was using Lua 5.2, so some changes had to be made.

First I changed the compile command to as follows:

% g++ luaavg.cpp -llua5.2 -I/usr/include/lua5.2 -o luaavg

Then, in the luaavg.cpp file, I changed "L = lua_open()" to "L = luaL_newstate()".

(To install Lua 5.2 in ubuntu, try this.)