3,881
社区成员
发帖
与我相关
我的任务
分享 lua_getglobal( g_pLua, "OnConfirmMessage");
if( lua_pcall( g_pLua, 0, 1, 0 ) != 0 )
{
AppendMessage( "调用OnConfirmMessage出错");
SetInfoText( "脚本OnConfirmMessage中可能存在错误,请确认。");
JustStop();
if( MessageBox( hMainDlg, "调用OnConfirmMessage时出现错误,要查看详细信息吗?", "错了", MB_YESNO ) == IDYES )
MessageBox( hMainDlg, lua_tostring( g_pLua, -1 ), "详细信息如下", MB_OK );
lua_pop( g_pLua, 1 );
return;
}
else
{
if( ! ( lua_isboolean( g_pLua, -1 ) && lua_toboolean( g_pLua, -1 )))
{
AppendMessage( "OnConfirmMessage失败");
SetInfoText( "OnConfirmMessage返回了错误值。");
JustStop();
lua_pop( g_pLua, 1 );
return;
}
lua_pop( g_pLua, 1 );
}
Lua调用C++
static int StringToInt( lua_State * pState )
{
if( lua_gettop( pState ) != 1 )
{
lua_pushinteger( pState, -1 );
return 1;
}
if( ! lua_isstring(pState, 1 ))
{
lua_pushinteger( pState, -1 );
return 1;
}
const char * pStr = lua_tostring( pState, 1 );
lua_pushinteger( pState, atoi( pStr ));
return 1;
}