lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


>         I am a new user of Lua.
>I need to integrate code of Lua with C++.
>With C it is easy , just 'extern C'.
>Is there similar mechanism for Lua too,
>so that you can call C++ procedures from Lua
>and vice-versa.

You can use lua_register() to export C++ functions just like you do with C
functions.

If you want to export C++ classes and/or objects to Lua, however, you must
use a different approach.
Take a look at Lenny Palozzi's paper on binding C++ classes to lua:
<http://www.lua.org/notes/ltn005.html>
And his template class implementation:
<http://lua-users.org/files/wiki_insecure/users/lpalozzi/luna.tar.gz>

It's written for Lua 4.0 and needs some tweaks to work properly with Lua 5.0
alpha.

To call Lua functions from C/C++ you must use lua_call/lua_pcall, if I
remember. This is a real 'RTFM' question.

Good luck.

Thiago Bastos
Student, PUC-Rio