Returning Values in LUA

Started by
2 comments, last by Prozak 19 years, 11 months ago
I''m using LUA 5, and havent yet nailed this one down: LUA code calls C++ function C++ function executes & returns value (int) LUA code grabs the return Something like: lua_function() { handle = cplusplus_function_get_handle_to_animal("cow"); }; Ok, so what code do I have to add to my c++ function so that it returns the value back to the lua script? Thanks for any tips on this... Salsa cooked it, your eyes eat it![Hugo Ferreira][Positronic Dreams][Colibri 3D Engine][Entropy HL2 MOD][My DevDiary]
[Yann L.][Enginuity] [Penny Arcade] [MSDN][VS RoadMap][Humus][BSPs][UGP][NeHe]
"our stupidity allways comes back to bite us in the ass... in a white-shark sort of way..." - Prozak
Advertisement
This should be in the scripting forum, but well:

C-Functions known to Lua always look like int Function( lua_State* L);

When you''re done with reading the parameters from the lua stack you just push the values on the stack and return the number of the parameters at the end of your function.

Something like:

lua_pushnumber( L, 17 );
lua_pushstring( L, "Hello World" );
return 2;

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

Moved.
Ah thanks... i was missing the "return x;" part... that was the key

Salsa cooked it, your eyes eat it![Hugo Ferreira][Positronic Dreams][Colibri 3D Engine][Entropy HL2 MOD][My DevDiary]
[Yann L.][Enginuity] [Penny Arcade] [MSDN][VS RoadMap][Humus][BSPs][UGP][NeHe]
"our stupidity allways comes back to bite us in the ass... in a white-shark sort of way..." - Prozak

This topic is closed to new replies.

Advertisement