Yes I'm sure it return an integer. LoadSoundF used 2 look like this (see below) and it worked, but I wanted place the iFileID in the lua script.
int LoadSoundF(lua_State *L){ if(lua_gettop(L) == 2) { int iFileID = -1; iFileID = dOpenAL->LoadSound(lua_tostring(L, -2), (ALboolean)lua_toboolean(L, -1)); return iFileID; } return -1;}
I was just thinking "LoadSoundF" is a C function, can LUA use the return value of this function just like that or do I need 2 do something like lua_push<something>!?
Edit:
I just took a better look into the manual and now its all clear 2 me. The return value from the c function is the number of values pushed on the stack. So i need to do a lua_push 1st and then return a 1 because I only pushed 1 value on the stack.
From the lua manual:
In order to communicate properly with Lua, a C function must follow the following protocol,
which defines the way parameters and results are passed: A C function receives its arguments from
Lua in its stack in direct order (the first argument is pushed first). So, when the function starts, its
first argument (if any) is at index 1. To return values to Lua, a C function just pushes them onto
the stack, in direct order (the first result is pushed first), and returns the number of results. Any
other value in the stack below the results will be properly discharged by Lua. Like a Lua function,
a C function called by Lua can also return many results.
As an example, the following function receives a variable number of numerical arguments
Edit 2:
Yes it works. The C functions now looks like this and the lua function remains the same.
int LoadSoundF(lua_State *L){ if(lua_gettop(L) == 2) { lua_pushnumber(L, dOpenAL->LoadSound(lua_tostring(L, -2), (ALboolean)lua_toboolean(L, -1))); return 1; } return 0;}
[Edited by - D3DXVECTOR3 on January 6, 2005 12:38:11 PM]