lua 模板封装
This commit is contained in:
parent
9e0316c15a
commit
ad524aab97
@ -27,70 +27,87 @@ public:
|
||||
int UpdateScript(std::string);
|
||||
|
||||
|
||||
void pushstack(lua_Number arg) {
|
||||
int pushstack(lua_Number arg) {
|
||||
lua_pushnumber(mVM, arg);
|
||||
return 1;
|
||||
}
|
||||
void pushstack(lua_Integer arg) {
|
||||
int pushstack(lua_Integer arg) {
|
||||
lua_pushinteger(mVM, arg);
|
||||
return 1;
|
||||
}
|
||||
void pushstack(void* arg) {
|
||||
int pushstack(void* arg) {
|
||||
lua_pushlightuserdata(mVM, arg);
|
||||
return 1;
|
||||
}
|
||||
void pushstack(const char* arg) {
|
||||
int pushstack(const char* arg) {
|
||||
lua_pushstring(mVM,arg);
|
||||
return 1;
|
||||
}
|
||||
void pushstack(bool arg) {
|
||||
int pushstack(bool arg) {
|
||||
lua_pushboolean (mVM, arg);
|
||||
return 1;
|
||||
}
|
||||
void pushstack(std::string arg) {
|
||||
int pushstack(std::string arg) {
|
||||
lua_pushstring(mVM, arg.c_str());
|
||||
return 1;
|
||||
}
|
||||
void pushstack(lua_CFunction fn, int n) {
|
||||
int pushstack(lua_CFunction fn, int n) {
|
||||
lua_pushcclosure(mVM, fn, n);
|
||||
return 1;
|
||||
}
|
||||
|
||||
template <typename ... Types>
|
||||
void pushstack(lua_Number arg1, Types... rest) {
|
||||
int pushstack(lua_Number arg1, Types... rest) {
|
||||
lua_pushnumber(mVM, arg1);
|
||||
pushstack(rest...);
|
||||
int ret = pushstack(rest...) + 1;
|
||||
return ret;
|
||||
}
|
||||
template <typename ... Types>
|
||||
void pushstack(lua_Integer arg1, Types... rest) {
|
||||
int pushstack(lua_Integer arg1, Types... rest) {
|
||||
lua_pushinteger (mVM, arg1);
|
||||
pushstack(rest...);
|
||||
int ret = pushstack(rest...) + 1;
|
||||
return ret;
|
||||
}
|
||||
template <typename ... Types>
|
||||
void pushstack(bool arg1, Types... rest) {
|
||||
int pushstack(bool arg1, Types... rest) {
|
||||
lua_pushboolean(mVM, arg1);
|
||||
pushstack(rest...);
|
||||
int ret = pushstack(rest...) + 1;
|
||||
return ret;
|
||||
}
|
||||
template <typename ... Types>
|
||||
void pushstack(std::string arg1, Types... rest) {
|
||||
int pushstack(std::string arg1, Types... rest) {
|
||||
lua_pushstring(mVM, arg1.c_str());
|
||||
pushstack(rest...);
|
||||
int ret = pushstack(rest...) + 1;
|
||||
return ret;
|
||||
}
|
||||
template <typename ... Types>
|
||||
void pushstack(void* arg1, Types... rest) {
|
||||
int pushstack(void* arg1, Types... rest) {
|
||||
lua_pushlightuserdata(mVM, arg1);
|
||||
pushstack(rest...);
|
||||
int ret = pushstack(rest...) + 1;
|
||||
return ret;
|
||||
}
|
||||
template <typename ... Types>
|
||||
void pushstack(lua_CFunction fn, int n, Types... rest) {
|
||||
int pushstack(lua_CFunction fn, int n, Types... rest) {
|
||||
lua_pushcclosure(mVM, fn,n);
|
||||
pushstack(rest...);
|
||||
int ret = pushstack(rest...) + 1;
|
||||
return ret;
|
||||
}
|
||||
template <typename ... Types>
|
||||
void pushstack(const char* arg1, Types... rest) {
|
||||
int pushstack(const char* arg1, Types... rest) {
|
||||
lua_pushstring(mVM, arg1);
|
||||
pushstack(rest...);
|
||||
int ret = pushstack(rest...) + 1;
|
||||
return ret;
|
||||
}
|
||||
template<typename... T>
|
||||
void CallFuntion(std::string name,T... para){
|
||||
int CallFuntion(std::string name,T... para){
|
||||
int i = lua_getglobal(mVM,name.c_str());
|
||||
if(i < 0){
|
||||
return ;
|
||||
if(LUA_TNIL == i){
|
||||
return -1;
|
||||
}
|
||||
pushstack(para...);
|
||||
int ret = pushstack(para...);
|
||||
std::cout << "parameter count is " << ret;
|
||||
lua_call(mVM, ret, 0);
|
||||
return 0;
|
||||
}
|
||||
lua_State* VM();
|
||||
void PrintError(lua_State *L);
|
||||
|
@ -57,8 +57,8 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
|
||||
LuaDelegate lua;
|
||||
std::cout << std::endl;
|
||||
|
||||
lua.CallFuntion< lua_Number>(std::string("sds"),
|
||||
123.0);
|
||||
// lua.CallFuntion< lua_Number>(std::string("sds"),
|
||||
// 123.0);
|
||||
UNREFERENCED_PARAMETER(hPrevInstance);
|
||||
UNREFERENCED_PARAMETER(lpCmdLine);
|
||||
|
||||
|
@ -48,7 +48,7 @@ UartForm::UartForm(ui::Window* hwnd,std::wstring name,
|
||||
if (0 < SerialPort::ReadPort(PortNum, recv, 1024)) {
|
||||
printf("recv data: %s", recv);
|
||||
this->m_show_recv += string2wstring(recv);
|
||||
this->mLua->OnSerialData(recv);
|
||||
this->mLua->CallFuntion<std::string>("OnUartData", std::string(recv));
|
||||
if (this->mEditRecv != nullptr) {
|
||||
this->mEditRecv->AppendText(string2wstring(recv), false);
|
||||
::PostMessage(this->GetWindow()->GetHWND(), WM_ADD_UART_RECVDATA,0, 0);
|
||||
|
Loading…
Reference in New Issue
Block a user