From my exp i can say that lua_gettop and lua_tostring act like original lua function.
If you are trying to execute a lua function without DoString() you can try with lua_pcall or lua_call ...
Code:
void Lua_CallVarg(const char *func, const char *sig, ...)
{ //http://www.lua.org/pil/25.3.html
void *L;
L = GetLuaState();
//DBGLOG( (PDWORD)L );
char* str;
va_list vl;
int narg, nres; /* number of arguments and results */
va_start(vl, sig);
Lua_Getglobal(L, func); /* get function */
/* push arguments */
narg = 0;
while (*sig) { /* push arguments */
switch (*sig++) {
case 'd': /* double argument */
Lua_pushnumber(L, va_arg(vl, double));
break;
case 'i': /* int argument */
Lua_pushnumber(L, va_arg(vl, int));
break;
case 's': /* string argument */
str = va_arg(vl, char *);
Lua_pushstring(L, str,strlen(str));
break;
case '>':
goto endwhile; // ugly conditional branch
default:
DBGLOG( "Lua_CallVarg : Invalid option " << *(sig - 1) );
}
narg++;
//luaL_checkstack(L, 1, "too many arguments");
} endwhile:
/* do the call */
nres = strlen(sig); /* number of expected results */
unsigned int size;
if (Lua_pcall(L, narg, nres, 0) != 0) /* do the call */
DBGLOG("error running function " << func << " " << Lua_tostring(L, -1,&size) );
/* retrieve results */
nres = -nres; /* stack index of first result */
while (*sig) { /* get results */
switch (*sig++) {
case 'd': /* double result */
if (!Lua_isnumber(L, nres))
DBGLOG ( "wrong result type");
*va_arg(vl, double *) = Lua_tonumber(L, nres);
break;
case 'i': /* int result */
if (!Lua_isnumber(L, nres))
DBGLOG ( "wrong result type");
*va_arg(vl, int *) = (int)Lua_tonumber(L, nres);
break;
case 's': /* string result */
if (!Lua_isstring(L, nres))
DBGLOG ( "wrong result type");
unsigned int size;
*va_arg(vl, const char **) = Lua_tostring(L, nres, &size);
break;
default:
DBGLOG ( "invalid option " << *(sig - 1));
}
nres++;
}
va_end(vl);
}
and call the GetCurrentMapContinent() with
Code:
int *i;
Lua_CallVarg("GetCurrentMapContinent",">i",i);