-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathluathread.cpp
46 lines (38 loc) · 1.78 KB
/
luathread.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/////////////////////////////////////////////////////////////////////////////////
// Author: Steven Lamerton
// Copyright: Copyright (C) 2009 - 2010 Steven Lamerton
// License: GNU GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
/////////////////////////////////////////////////////////////////////////////////
#include <wx/listctrl.h>
#include <wx/stdpaths.h>
#include "toucan.h"
#include "luathread.h"
#include "basicfunctions.h"
#include <lua.hpp>
extern "C" {
extern int luaopen_toucan(lua_State*L);
}
LuaThread::LuaThread(const wxString &line) : wxThread(), m_Command(line){
m_StartTime = wxDateTime::Now();
m_State = luaL_newstate();
luaL_openlibs(m_State);
luaopen_toucan(m_State);
wxString path = wxPathOnly(wxStandardPaths::Get().GetExecutablePath()) + wxFILE_SEP_PATH + wxT("bindings.lua");
if (luaL_loadfile(m_State, path.mb_str()) || lua_pcall(m_State, 0, 0, 0)) {
OutputProgress(wxT("Cannot run lua file: ") + wxString(lua_tostring(m_State, -1), wxConvUTF8), Error);
}
}
void *LuaThread::Entry(){
OutputProgress(wxT("Toucan ") + wxString(TOUCAN_VERSION, wxConvUTF8), StartingLine);
OutputProgress(_("Date:") + " " + m_StartTime.FormatISODate(), StartingInfo);
OutputProgress(_("Computer Name:") + " " + wxGetHostName(), StartingInfo);
OutputProgress(_("Operating System:") + " " + wxGetOsDescription(), StartingInfo);
OutputProgress(wxEmptyString, Message);
if (luaL_loadstring(m_State, m_Command.mb_str()) || lua_pcall(m_State, 0, 0, 0)) {
OutputProgress(wxT("Cannot run lua file: ") + wxString(lua_tostring(m_State, -1), wxConvUTF8), Error);
}
OutputProgress(wxEmptyString, Message);
OutputProgress(_("Elapsed:") + wxT(" ") + wxDateTime::Now().Subtract(m_StartTime).Format(), FinishingInfo);
OutputProgress(_("Finished"), FinishingLine);
return NULL;
}