I embed Lua in a C ++ application, and I want to provide a print () function (or maybe just override the Lua print function) so that I can pass variables of simple data types (strings, booleans and numbers) to my C ++ as strings.
So what I want to do is have C ++ - a function that I export to Lua called my_print ()
Then I can call my_print () in the Lua block as follows:
a = 22/7
b = false
c = 42
my_print('The value of variable a is: ' .. a)
my_print('b: ' .. b)
my_print('c is: ' .. c)
Each time my_print () is called, it passes the C ++ string to the C ++ application. I looked at the Lua C API, I suspect that I will have to use lua_gettop (L), lua_type (), etc.
A small snippet of how to start writing a C / C ++ function that can be exported to Lua and used as described above will be greatly appreciated.