Thus I try to play around with simple examples.
I was succesful with writing C functions that get and return numbers.
I also could export number and string constants.
Currently I try to exchange lightuserdata between HW and C.
As test case I want to expose exec.library AllocVec and FreeVec functions.
AllocVec:
Code: Select all
static SAVEDS int hw_allocvec(lua_State *L)
{
void *memptr=NULL;
lua_Number memsize = luaL_checknumber(L,1);
memptr=AllocVec(memsize,0L);
hwcl->LuaBase->lua_pushlightuserdata(L,memptr);
return 1;
}
Code: Select all
mem=t.Allocvec(100000000) ; allocate 100 MB of Ram
DebugPrint(men)
Now I want to do a
Code: Select all
t.Freevec(mem)
According to the HW manual, ToNumber can not only convert string to number, but also values of type #LIGHTUSERDATA.
My call now is:
Code: Select all
t.FreeVec(ToNumber(mem))
Code: Select all
static SAVEDS int hw_freevec(lua_State *L)
{
void *memptr=NULL;
memptr = hwcl->LuaBase->lua_touserdata(L,hwcl->LuaBase->lua_tonumber(L,1));
FreeVec(memptr);
return 0;
}
How can I do it right ?
Probably my function is not ok. But I cannot find any luaL_checklightuserdata function or likewise...