I am embedding Lua in a C++ application and I want to provide a print() like function (or maybe simply override Lua's print function), so that I can pass variables of simple datatypes (string, boolean and number) into my C++ app as strings.
So what I am looking to do is to have a C++ function, which I export to Lua, called my_print()
I can then call my_print() in a Lua chunk like so:
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 will pass a C++ string to the C++ app. I have had a look at the Lua C API, I suspect that I will have to use lua_gettop(L), lua_type() etc.
A little snippet on how to get started in writing such a C/C++ function that can be exported to Lua and used in the manner described above, would be very much appreciated.