lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I am having problems using tolua to bind the following function, which uses varargs.

The C function:

bool lua_msg (const char *fmt,...)
{
	const char *msg;
	va_list vp;

	va_start(vp, fmt);

	msg = lua_pushvfstring(L, fmt, vp);
	if(!msg) return FALSE;

	MessageBox(hwnd, msg, "Lua Message Box", MB_OK | MB_ICONINFORMATION);

	va_end(vp);

	return TRUE;
}

The tolua 5.0a generated binding follows:

static int tolua_script_lua_msg00(lua_State* L)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_isstring(L,1,&tolua_err) ||
!tolua_isusertype(L,2,"...",0,&tolua_err) ||
!tolua_isnoobj(L,3,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
 const char *fmt = ((const char *)  tolua_tostring(L,1,0));
... tolua_var_2 = *((...*)  tolua_tousertype(L,2,0));
{
 bool tolua_ret = (bool)  lua_msg(fmt,tolua_var_2);
tolua_pushboolean(L,(bool)tolua_ret);
}
}
return 1;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(L,"#ferror in function 'lua_msg'.",&tolua_err);
return 0;
#endif
}

The above binding is unusable.

I tried to modify the binding as shown below:

static int tolua_script_lua_msg00(lua_State* L)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_isstring(L,1,0,&tolua_err) ||
!tolua_isstring(L,2,0,&tolua_err) ||
!tolua_isnoobj(L,3,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
 const char *fmt = ((const char *)  tolua_tostring(L,1,0));
 va_list vp = ((char *)  tolua_tostring(L,2,0));
{
 bool tolua_ret = (bool)  lua_msg(fmt,vp);
tolua_pushboolean(L,(bool)tolua_ret);
}
}
return 1;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(L,"#ferror in function 'lua_msg'.",&tolua_err);
return 0;
#endif
}

However, this will give me only a single (vp) argument.
It is obviously not using the va_list typedef.

Any help would be appreciated.

mrb

_________________________________________________________________
Don?t just search. Find. Check out the new MSN Search! http://search.msn.click-url.com/go/onm00200636ave/direct/01/