extern "C" {
#include "LuaSrc/lua.h"
#include "LuaSrc/lualib.h"
#include "LuaSrc/lauxlib.h"
}
#include "LuaSrc/lua_tinker.h"
#include <map>
#include <string>
using namespace std;
static map<UINT, string> timers;
static CCriticalSection cs;
static void CALLBACK timerProc(HWND hwnd, UINT message, UINT iTimerID, UINT dwTime)
{
cs.Lock();
map<UINT, string>::iterator iter;
char test[50] = {0};
sprintf(test, "id:%d, 当前线程:0x%x 参数个数:%d",iTimerID, GetCurrentThreadId(), lua_gettop(l_State));
OutputDebugString(test);
if((iter = timers.find(iTimerID)) != timers.end())
{
lua_tinker::call<void>(l_State, iter->second.c_str());
}
sprintf(test, "结束后参数个数:%d", lua_gettop(l_State));
OutputDebugString(test);
cs.Unlock();
}
static UINT_PTR MyTimer(const char* lua_fun, UINT iTimerID, UINT dwTime)
{
UINT id = 0;
cs.Lock();
id = ::SetTimer(NULL, iTimerID, dwTime, (TIMERPROC)timerProc);
timers.insert(pair<UINT, string>(id, lua_fun));
cs.Unlock();
return id;
}
static void MyKillTimer(UINT iTimerID)
{
KillTimer(NULL, iTimerID);
#include "LuaSrc/lua.h"
#include "LuaSrc/lualib.h"
#include "LuaSrc/lauxlib.h"
}
#include "LuaSrc/lua_tinker.h"
#include <map>
#include <string>
using namespace std;
static map<UINT, string> timers;
static CCriticalSection cs;
static void CALLBACK timerProc(HWND hwnd, UINT message, UINT iTimerID, UINT dwTime)
{
cs.Lock();
map<UINT, string>::iterator iter;
char test[50] = {0};
sprintf(test, "id:%d, 当前线程:0x%x 参数个数:%d",iTimerID, GetCurrentThreadId(), lua_gettop(l_State));
OutputDebugString(test);
if((iter = timers.find(iTimerID)) != timers.end())
{
lua_tinker::call<void>(l_State, iter->second.c_str());
}
sprintf(test, "结束后参数个数:%d", lua_gettop(l_State));
OutputDebugString(test);
cs.Unlock();
}
static UINT_PTR MyTimer(const char* lua_fun, UINT iTimerID, UINT dwTime)
{
UINT id = 0;
cs.Lock();
id = ::SetTimer(NULL, iTimerID, dwTime, (TIMERPROC)timerProc);
timers.insert(pair<UINT, string>(id, lua_fun));
cs.Unlock();
return id;
}
static void MyKillTimer(UINT iTimerID)
{
KillTimer(NULL, iTimerID);
}
lua中 MyTimer('test()', 1000, 1000)