1
/***************************************************************************
2
* Copyright (C) 2008-2011 by Heiko Koehn *
3
* KoehnHeiko@googlemail.com *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU General Public License as published by *
7
* the Free Software Foundation; either version 2 of the License, or *
8
* (at your option) any later version. *
10
* This program is distributed in the hope that it will be useful, *
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13
* GNU General Public License for more details. *
15
* You should have received a copy of the GNU General Public License *
16
* along with this program; if not, write to the *
17
* Free Software Foundation, Inc., *
18
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19
***************************************************************************/
26
#include <QNetworkAccessManager>
27
#include <QDesktopServices>
28
#include "TLuaInterpreter.h"
29
#include "TForkedProcess.h"
31
#include "HostManager.h"
37
#include "dlgMapper.h"
42
// #include "lua_yajl.c"
44
#include "lua_yajl1.c"
55
extern QStringList gSysErrors;
59
map<lua_State*, Host*> TLuaInterpreter::luaInterpreterMap;
61
TLuaInterpreter::TLuaInterpreter( Host * pH, int id )
68
connect(this,SIGNAL(signalEchoMessage(int, QString)), this,SLOT(slotEchoMessage(int,QString)));//,Qt::DirectConnection);
69
connect(this,SIGNAL(signalNewCommand(int,QString)), this,SLOT(slotNewCommand(int,QString)));//,Qt::QueuedConnection);
71
connect(this,SIGNAL(signalOpenUserWindow(int,QString)), this,SLOT(slotOpenUserWindow(int,QString)));
72
connect(this,SIGNAL(signalEchoUserWindow(int,QString,QString)), this,SLOT(slotEchoUserWindow(int,QString,QString)));
73
connect(this,SIGNAL(signalEnableTimer(int,QString)),this,SLOT(slotEnableTimer(int,QString)));
74
connect(this,SIGNAL(signalDisableTimer(int,QString)),this,SLOT(slotDisableTimer(int,QString)));
75
connect(this,SIGNAL(signalClearUserWindow(int,QString)),this,SLOT(slotClearUserWindow(int,QString)));
77
connect(this, SIGNAL(signalSelect(int, QString, int)), this, SLOT(slotSelect(int,QString,int)));
78
connect(this, SIGNAL(signalSelectSection(int, int,int)), this, SLOT(slotSelectSection(int,int,int)));
79
connect(this, SIGNAL(signalTempTimer(int, double,QString,QString)), this, SLOT(slotTempTimer(int,double,QString,QString)));
81
connect(this, SIGNAL(signalReplace(int, QString)), this, SLOT(slotReplace(int,QString)));
82
connect(this, SIGNAL(signalSetFgColor(int, int,int,int)), this, SLOT(slotSetFgColor(int,int,int,int)));
83
connect(this, SIGNAL(signalSetBgColor(int, int,int,int)), this, SLOT(slotSetBgColor(int,int,int,int)));
84
connect(&purgeTimer, SIGNAL(timeout()), this, SLOT(slotPurge()));
86
mpFileDownloader = new QNetworkAccessManager( this );
87
connect(mpFileDownloader, SIGNAL(finished(QNetworkReply*)),this, SLOT(replyFinished(QNetworkReply*)));
91
purgeTimer.start(2000);
94
lua_State * TLuaInterpreter::getLuaExecutionUnit( int unit )
112
void TLuaInterpreter::replyFinished(QNetworkReply * reply )
114
if( ! downloadMap.contains(reply) ) return;
115
QString name = downloadMap[reply];
117
file.open( QFile::WriteOnly );
118
file.write( reply->readAll() );
122
TEvent * e = new TEvent;
123
if( reply->error() == 0 )
125
e->mArgumentList << "sysDownloadDone";
126
e->mArgumentTypeList << ARGUMENT_TYPE_STRING;
127
e->mArgumentList << name;
128
e->mArgumentTypeList << ARGUMENT_TYPE_STRING;
132
e->mArgumentList << "sysDownloadError";
133
e->mArgumentTypeList << ARGUMENT_TYPE_STRING;
134
e->mArgumentList << reply->errorString();
135
e->mArgumentTypeList << ARGUMENT_TYPE_STRING;
138
mpHost->raiseEvent( e );
141
void TLuaInterpreter::slotDeleteSender() {
142
objectsToDelete.append(sender());
145
void TLuaInterpreter::slotPurge() {
146
while (!objectsToDelete.isEmpty()) {
147
delete objectsToDelete.takeFirst();
152
int TLuaInterpreter::Wait( lua_State *L )
154
int n = lua_gettop( L );
157
lua_pushstring( L, "Wait: wrong number of arguments" );
163
if( ! lua_isnumber( L, 1 ) )
165
lua_pushstring( L, "Wait: wrong argument type" );
171
luaSleepMsec = lua_tointeger( L, 1 );
173
msleep( luaSleepMsec );//FIXME thread::sleep()
177
int TLuaInterpreter::denyCurrentSend( lua_State * L )
179
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
180
pHost->mAllowToSendCommand = false;
184
int TLuaInterpreter::raiseEvent( lua_State * L )
186
TEvent * pE = new TEvent;
188
int n = lua_gettop( L );
189
for( int i=1; i<=n; i++)
191
if( lua_isnumber( L, i ) )
193
pE->mArgumentList.append( QString::number(lua_tonumber( L, i ) ) );
194
pE->mArgumentTypeList.append( ARGUMENT_TYPE_NUMBER );
196
else if( lua_isstring( L, i ) )
198
pE->mArgumentList.append( QString(lua_tostring( L, i )) );
199
pE->mArgumentTypeList.append( ARGUMENT_TYPE_STRING );
202
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
203
pHost->raiseEvent( pE );
207
int TLuaInterpreter::resetProfile( lua_State * L )
209
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
210
pHost->mResetProfile = true;
216
// cursorPositionInLine = select( text ) if not found -1
217
int TLuaInterpreter::select( lua_State * L )
220
int n = lua_gettop( L );
224
if( ! lua_isstring( L, s ) )
226
lua_pushstring( L, "select: wrong argument type" );
232
a1 = lua_tostring( L, s );
236
string luaSendText="";
237
if( ! lua_isstring( L, s ) )
239
lua_pushstring( L, "select: wrong argument type" );
245
luaSendText = lua_tostring( L, s );
249
if( ! lua_isnumber( L, s ) )
251
lua_pushstring( L, "select: wrong argument type" );
257
luaNumOfMatch = lua_tointeger( L, s );
259
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
262
int pos = pHost->mpConsole->select( QString( luaSendText.c_str() ), luaNumOfMatch );
263
lua_pushnumber( L, pos );
268
QString _name(a1.c_str());
269
int pos = mudlet::self()->selectString( pHost, _name, QString( luaSendText.c_str() ), luaNumOfMatch );
270
lua_pushnumber( L, pos );
275
int TLuaInterpreter::selectCurrentLine( lua_State * L )
277
string luaSendText="";
278
if( lua_gettop( L ) == 0 )
280
luaSendText = "main";
284
if( ! lua_isstring( L, 1 ) )
286
lua_pushstring( L, "selectCurrentLine: wrong argument type" );
292
luaSendText = lua_tostring( L, 1 );
295
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
296
pHost->mpConsole->selectCurrentLine( luaSendText );
300
int TLuaInterpreter::isAnsiFgColor( lua_State * L )
304
std::string console = "main";
306
if( ! lua_isnumber( L, 1 ) )
308
lua_pushstring( L, "isAnsiFgColor: wrong argument type" );
314
ansiFg = lua_tointeger( L, 1 );
317
std::list<int> result;
318
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
319
result = pHost->mpConsole->getFgColor( console );
320
typedef std::list<int>::iterator IT;
321
IT it=result.begin();
322
if( result.size() < 3 ) return 0;
323
if( ansiFg < 0 ) return 0;
324
if( ansiFg > 16 ) return 0;
330
case 0: c = pHost->mFgColor; break;
331
case 1: c = pHost->mLightBlack; break;
332
case 2: c = pHost->mBlack; break;
333
case 3: c = pHost->mLightRed; break;
334
case 4: c = pHost->mRed; break;
335
case 5: c = pHost->mLightGreen; break;
336
case 6: c = pHost->mGreen; break;
337
case 7: c = pHost->mLightYellow; break;
338
case 8: c = pHost->mYellow; break;
339
case 9: c = pHost->mLightBlue; break;
340
case 10: c = pHost->mBlue; break;
341
case 11: c = pHost->mLightMagenta; break;
342
case 12: c = pHost->mMagenta; break;
343
case 13: c = pHost->mLightCyan; break;
344
case 14: c = pHost->mCyan; break;
345
case 15: c = pHost->mLightWhite; break;
346
case 16: c = pHost->mWhite; break;
354
if( val == c.green() )
358
if( val == c.blue() )
360
lua_pushboolean( L, 1 );
366
lua_pushboolean( L, 0 );
370
int TLuaInterpreter::isAnsiBgColor( lua_State * L )
374
std::string console = "main";
376
if( ! lua_isnumber( L, 1 ) )
378
lua_pushstring( L, "isAnsiBgColor: wrong argument type" );
384
ansiFg = lua_tointeger( L, 1 );
387
std::list<int> result;
388
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
389
if( ! pHost ) return 0;
390
result = pHost->mpConsole->getBgColor( console );
391
typedef std::list<int>::iterator IT;
392
IT it=result.begin();
393
if( result.size() < 3 ) return 0;
394
if( ansiFg < 0 ) return 0;
395
if( ansiFg > 16 ) return 0;
401
case 0: c = pHost->mBgColor; break;
402
case 1: c = pHost->mLightBlack; break;
403
case 2: c = pHost->mBlack; break;
404
case 3: c = pHost->mLightRed; break;
405
case 4: c = pHost->mRed; break;
406
case 5: c = pHost->mLightGreen; break;
407
case 6: c = pHost->mGreen; break;
408
case 7: c = pHost->mLightYellow; break;
409
case 8: c = pHost->mYellow; break;
410
case 9: c = pHost->mLightBlue; break;
411
case 10: c = pHost->mBlue; break;
412
case 11: c = pHost->mLightMagenta; break;
413
case 12: c = pHost->mMagenta; break;
414
case 13: c = pHost->mLightCyan; break;
415
case 14: c = pHost->mCyan; break;
416
case 15: c = pHost->mLightWhite; break;
417
case 16: c = pHost->mWhite; break;
425
if( val == c.green() )
429
if( val == c.blue() )
431
lua_pushboolean( L, 1 );
437
lua_pushboolean( L, 0 );
441
int TLuaInterpreter::getFgColor( lua_State * L )
443
string luaSendText="";
444
if( lua_gettop( L ) == 0 )
446
luaSendText = "main";
450
if( ! lua_isstring( L, 1 ) )
452
lua_pushstring( L, "getFgColor: wrong argument type" );
458
luaSendText = lua_tostring( L, 1 );
461
QString _name(luaSendText.c_str());
462
std::list<int> result;
463
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
464
result = pHost->mpConsole->getFgColor( luaSendText );
465
typedef std::list<int>::iterator IT;
466
for( IT it=result.begin(); it!=result.end(); it++ )
469
lua_pushnumber( L, pos );
471
return result.size();
474
int TLuaInterpreter::getBgColor( lua_State * L )
476
string luaSendText="";
477
if( lua_gettop( L ) == 0 )
479
luaSendText = "main";
483
if( ! lua_isstring( L, 1 ) )
485
lua_pushstring( L, "getBgColor: wrong argument type" );
491
luaSendText = lua_tostring( L, 1 );
495
std::list<int> result;
496
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
497
result = pHost->mpConsole->getBgColor( luaSendText );
498
typedef std::list<int>::iterator IT;
499
for( IT it=result.begin(); it!=result.end(); it++ )
502
lua_pushnumber( L, pos );
504
return result.size();
507
int TLuaInterpreter::wrapLine( lua_State * L )
510
int n = lua_gettop( L );
514
if( ! lua_isstring( L, s ) )
516
lua_pushstring( L, "wrapLine: wrong argument type" );
522
a1 = lua_tostring( L, s );
528
if( ! lua_isnumber( L, s ) )
530
lua_pushstring( L, "wrapLine: wrong argument type" );
536
luaNumOfMatch = lua_tointeger( L, s );
539
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
540
pHost->mpConsole->luaWrapLine( a1, luaNumOfMatch );
546
int TLuaInterpreter::spawn( lua_State * L )
548
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
549
return TForkedProcess::startProcess(pHost->getLuaInterpreter(), L);
554
// cursorPositionInLine = selectCaptureGroup( groupNumber ) if not found -1
555
int TLuaInterpreter::selectCaptureGroup( lua_State * L )
558
if( ! lua_isnumber( L, 1 ) )
560
lua_pushstring( L, "selectCaptureGroup: wrong argument type" );
566
luaNumOfMatch = lua_tointeger( L, 1 );
568
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
569
if( luaNumOfMatch < 1 )
571
lua_pushnumber( L, -1 );
574
luaNumOfMatch--; //we want capture groups to start with 1 instead of 0
575
if( luaNumOfMatch < static_cast<int>(pHost->getLuaInterpreter()->mCaptureGroupList.size()) )
577
TLuaInterpreter * pL = pHost->getLuaInterpreter();
578
std::list<std::string>::iterator its = pL->mCaptureGroupList.begin();
579
std::list<int>::iterator iti = pL->mCaptureGroupPosList.begin();
581
for( int i=0; iti!=pL->mCaptureGroupPosList.end(); ++iti,++i )
583
if( i >= luaNumOfMatch ) break;
585
for( int i=0; its!=pL->mCaptureGroupList.end(); ++its,++i)
587
if( i >= luaNumOfMatch ) break;
591
std::string & s = *its;
592
int length = s.size();
593
//cout << "selectSection("<<begin<<", "<<length<<")"<<endl;
594
if( mudlet::debugMode ) {TDebug(QColor(Qt::white),QColor(Qt::red))<<"selectCaptureGroup("<<begin<<", "<<length<<")\n">>0;}
595
int pos = pHost->mpConsole->selectSection( begin, length );
596
lua_pushnumber( L, pos );
600
lua_pushnumber( L, -1 );
605
// luaTable result[line_number, content] = getLines( from_cursorPos, to_cursorPos )
606
int TLuaInterpreter::getLines( lua_State * L )
609
if( ! lua_isnumber( L, 1 ) )
611
lua_pushstring( L, "getLines: wrong argument type" );
617
luaFrom = lua_tointeger( L, 1 );
621
if( ! lua_isnumber( L, 2 ) )
623
lua_pushstring( L, "getLines: wrong argument type" );
629
luaTo=lua_tointeger( L, 2 );
631
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
632
QStringList strList = pHost->mpConsole->getLines( luaFrom, luaTo );
635
for( int i=0; i<strList.size(); i++ )
637
lua_pushnumber( L, i+1 );
638
lua_pushstring( L, strList[i].toLatin1().data() );
644
// luaTable result[line_number, content] = getLines( from_cursorPos, to_cursorPos )
645
int TLuaInterpreter::getBufferTable( lua_State * L )
648
if( ! lua_isnumber( L, 1 ) )
650
lua_pushstring( L, "getBufferTable: wrong argument type" );
656
luaFrom = lua_tointeger( L, 1 );
660
if( ! lua_isnumber( L, 2 ) )
662
lua_pushstring( L, "getBufferTable: wrong argument type" );
668
luaTo=lua_tointeger( L, 2 );
670
/*Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
671
QStringList strList = pHost->getBufferTable( luaFrom, luaTo );
672
if( mudlet::debugMode ) qDebug()<<"TLuaInterpreter::getBufferTable() strList="<<strList;
674
for( int i=0; i<strList.size(); i++ )
676
lua_pushnumber( L, i+1 );
677
lua_pushstring( L, strList[i].toLatin1().data() );
683
int TLuaInterpreter::loadRawFile( lua_State * L )
685
string luaSendText="";
686
if( ! lua_isstring( L, 1 ) )
688
lua_pushstring( L, "loadRawFile: wrong argument type" );
694
luaSendText = lua_tostring( L, 1 );
697
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
698
pHost->mpConsole->loadRawFile( luaSendText );
702
int TLuaInterpreter::getCurrentLine( lua_State * L )
704
string luaSendText="";
705
if( lua_gettop( L ) == 0 )
707
luaSendText = "main";
711
if( ! lua_isstring( L, 1 ) )
713
lua_pushstring( L, "getCurrentLine: wrong argument type" );
719
luaSendText = lua_tostring( L, 1 );
723
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
724
QString line = pHost->mpConsole->getCurrentLine( luaSendText );
725
lua_pushstring( L, line.toLatin1().data() );
729
int TLuaInterpreter::setMiniConsoleFontSize( lua_State * L )
731
string luaSendText="";
732
if( ! lua_isstring( L, 1 ) )
734
lua_pushstring( L, "setMiniConsoleFontSize: wrong argument type" );
740
luaSendText = lua_tostring( L, 1 );
743
if( ! lua_isnumber( L, 2 ) )
745
lua_pushstring( L, "setMiniConsoleFontSize: wrong argument type" );
751
luaNumOfMatch = lua_tointeger( L, 2 );
753
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
754
pHost->mpConsole->setMiniConsoleFontSize( luaSendText, luaNumOfMatch );
758
// returns current y position of the user cursor
759
int TLuaInterpreter::getLineNumber( lua_State * L )
762
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
763
int lineNumber = pHost->mpConsole->getLineNumber();
764
lua_pushnumber( L, lineNumber );
768
int TLuaInterpreter::centerview( lua_State * L )
771
if( lua_isnumber( L, 1 ) || lua_isstring( L, 1 ) )
773
roomid = lua_tointeger( L, 1 );
777
lua_pushstring( L, "centerview: need a valid room ID" );
782
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
783
if( pHost->mpMap && pHost->mpMap->rooms.contains( roomid ) )
785
pHost->mpMap->mRoomId = roomid;
786
pHost->mpMap->mNewMove = true;
787
if( pHost->mpMap->mpM )
789
pHost->mpMap->mpM->update();
791
if( pHost->mpMap->mpM )
793
pHost->mpMap->mpMapper->mp2dMap->update();
801
int TLuaInterpreter::copy( lua_State * L )
803
string luaWindowName="";
804
if( lua_isstring( L, 1 ) )
806
luaWindowName = lua_tostring( L, 1 );
809
luaWindowName = "main";
811
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
812
QString windowName(luaWindowName.c_str());
813
if( luaWindowName == "main" )
814
pHost->mpConsole->copy();
816
mudlet::self()->copy( pHost, windowName );
819
int TLuaInterpreter::cut( lua_State * L )
821
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
822
pHost->mpConsole->cut();
825
int TLuaInterpreter::paste( lua_State * L )
827
string luaWindowName="";
828
if( lua_isstring( L, 1 ) )
830
luaWindowName = lua_tostring( L, 1 );
833
luaWindowName = "main";
835
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
836
QString windowName(luaWindowName.c_str());
837
if( luaWindowName == "main" )
838
pHost->mpConsole->paste();
840
mudlet::self()->pasteWindow( pHost, windowName );
845
int TLuaInterpreter::feedTriggers( lua_State * L )
847
string luaWindowName="";
848
if( lua_isstring( L, 1 ) )
850
luaWindowName = lua_tostring( L, 1 );
854
lua_pushstring( L, "feedTriggers: wrong argument type" );
859
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
860
pHost->mpConsole->printOnDisplay( luaWindowName );
865
int TLuaInterpreter::isPrompt( lua_State *L )
867
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
868
int userCursorY = pHost->mpConsole->getLineNumber();
869
if( userCursorY < pHost->mpConsole->buffer.promptBuffer.size() && userCursorY >= 0 )
871
lua_pushboolean( L, pHost->mpConsole->buffer.promptBuffer.at( userCursorY ) );
876
if( pHost->mpConsole->mTriggerEngineMode && pHost->mpConsole->mIsPromptLine )
877
lua_pushboolean( L, true );
879
lua_pushboolean( L, false );
884
int TLuaInterpreter::setWindowWrap( lua_State * L )
886
string luaSendText="";
887
if( ! lua_isstring( L, 1 ) )
889
lua_pushstring( L, "setWindowWrap: wrong argument type" );
895
luaSendText = lua_tostring( L, 1 );
898
if( ! lua_isnumber( L, 2 ) )
900
lua_pushstring( L, "setWindowWrap: wrong argument type" );
906
luaFrom = lua_tointeger( L, 2 );
909
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
910
QString name = luaSendText.c_str();
912
pHost->mpConsole->setWrapAt( luaFrom );
914
mudlet::self()->setWindowWrap( pHost, name, luaFrom );
918
int TLuaInterpreter::setWindowWrapIndent( lua_State * L )
920
string luaSendText="";
921
if( ! lua_isstring( L, 1 ) )
923
lua_pushstring( L, "setWindowWrapIndent: wrong argument type" );
929
luaSendText = lua_tostring( L, 1 );
932
if( ! lua_isnumber( L, 2 ) )
934
lua_pushstring( L, "setWindowWrapIndent: wrong argument type" );
940
luaFrom = lua_tointeger( L, 2 );
943
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
944
QString name = luaSendText.c_str();
945
mudlet::self()->setWindowWrapIndent( pHost, name, luaFrom );
949
int TLuaInterpreter::getLineCount( lua_State * L )
951
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
952
if( lua_isstring( L, 1 ) )
954
string window = lua_tostring( L, 1 );
955
QString _window = window.c_str();
956
lua_pushnumber( L, mudlet::self()->getLastLineNumber( pHost, _window ) + 1 );
961
int lineNumber = pHost->mpConsole->getLineCount();
962
lua_pushnumber( L, lineNumber );
968
int TLuaInterpreter::getColumnNumber( lua_State * L )
970
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
971
int lineNumber = pHost->mpConsole->getColumnNumber();
972
lua_pushnumber( L, lineNumber );
976
int TLuaInterpreter::getStopWatchTime( lua_State * L )
979
if( ! lua_isnumber( L, 1 ) )
981
lua_pushstring( L, "getStopWatchTime: wrong argument type" );
987
watchID = lua_tointeger( L, 1 );
989
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
990
double time = pHost->getStopWatchTime( watchID );
991
lua_pushnumber( L, time );
995
int TLuaInterpreter::createStopWatch( lua_State * L )
997
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
998
double watchID = pHost->createStopWatch();
999
lua_pushnumber( L, watchID );
1003
int TLuaInterpreter::stopStopWatch( lua_State * L )
1006
if( ! lua_isnumber( L, 1 ) )
1008
lua_pushstring( L, "stopStopWatch: wrong argument type" );
1014
watchID = lua_tointeger( L, 1 );
1016
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
1017
double time = pHost->stopStopWatch( watchID );
1018
lua_pushnumber( L, time );
1022
int TLuaInterpreter::startStopWatch( lua_State * L )
1025
if( ! lua_isnumber( L, 1 ) )
1027
lua_pushstring( L, "startStopWatch: wrong argument type" );
1033
watchID = lua_tointeger( L, 1 );
1035
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
1036
bool b = pHost->startStopWatch( watchID );
1037
lua_pushboolean( L, b );
1041
int TLuaInterpreter::resetStopWatch( lua_State * L )
1044
if( ! lua_isnumber( L, 1 ) )
1046
lua_pushstring( L, "resetStopWatch: wrong argument type" );
1052
watchID = lua_tointeger( L, 1 );
1054
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
1055
bool b = pHost->resetStopWatch( watchID );
1056
lua_pushboolean( L, b );
1063
// cusorPositionInLine = selectSection( from_cursorPos, to_cursorPos ) -1 on not found
1064
int TLuaInterpreter::selectSection( lua_State * L )
1067
int n = lua_gettop( L );
1071
if( ! lua_isstring( L, s ) )
1073
lua_pushstring( L, "selectSection: wrong argument type" );
1079
a1 = lua_tostring( L, s );
1084
if( ! lua_isnumber( L, s ) )
1086
lua_pushstring( L, "selectSection: wrong argument type" );
1092
luaFrom = lua_tointeger( L, s );
1097
if( ! lua_isnumber( L, s ) )
1099
lua_pushstring( L, "selectSection: wrong argument type" );
1105
luaTo=lua_tointeger( L, s );
1108
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
1113
QString _name = a1.c_str();
1114
ret = mudlet::self()->selectSection( pHost, _name, luaFrom, luaTo );
1118
ret = pHost->mpConsole->selectSection( luaFrom, luaTo );
1120
lua_pushboolean( L, ret );
1125
int TLuaInterpreter::moveCursor( lua_State * L )
1128
int n = lua_gettop( L );
1132
if( ! lua_isstring( L, s ) )
1134
lua_pushstring( L, "moveCursor: wrong argument type" );
1140
a1 = lua_tostring( L, s );
1145
if( ! lua_isnumber( L, s ) )
1147
lua_pushstring( L, "moveCursor: wrong argument type" );
1153
luaFrom = lua_tointeger( L, s );
1158
if( ! lua_isnumber( L, s ) )
1160
lua_pushstring( L, "moveCursor: wrong argument type" );
1166
luaTo=lua_tointeger( L, s );
1169
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
1171
if( a1 == "main" || n < 3 )
1172
lua_pushboolean( L, pHost->mpConsole->moveCursor( luaFrom, luaTo ) );
1175
QString windowName = a1.c_str();
1176
lua_pushboolean( L, mudlet::self()->moveCursor( pHost, windowName, luaFrom, luaTo ) );
1181
int TLuaInterpreter::setConsoleBufferSize( lua_State * L )
1184
int n = lua_gettop( L );
1188
if( ! lua_isstring( L, s ) )
1190
lua_pushstring( L, "setConsoleBufferSize: wrong argument type" );
1196
a1 = lua_tostring( L, s );
1201
if( ! lua_isnumber( L, s ) )
1203
lua_pushstring( L, "setConsoleBufferSize: wrong argument type" );
1209
luaFrom = lua_tointeger( L, s );
1214
if( ! lua_isnumber( L, s ) )
1216
lua_pushstring( L, "setConsoleBufferSize: wrong argument type" );
1222
luaTo=lua_tointeger( L, s );
1225
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
1227
if( a1 == "main" || n < 3 )
1229
pHost->mpConsole->buffer.setBufferSize( luaFrom, luaTo );
1233
QString windowName = a1.c_str();
1234
mudlet::self()->setConsoleBufferSize( pHost, windowName, luaFrom, luaTo );
1239
int TLuaInterpreter::getBufferLine( lua_State * L )
1242
if( ! lua_isnumber( L, 1 ) )
1244
lua_pushstring( L, "getBufferLine: wrong argument type" );
1250
luaLine = lua_tointeger( L, 1 );
1253
/*Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
1254
QString line = pHost->getBufferLine( luaLine );
1255
if( mudlet::debugMode ) qDebug()<<"TLuaInterpreter::getBufferLine() line="<<line;
1256
lua_pushstring( L, line.toLatin1().data() );*/
1260
// replace( sessionID, replace_with )
1261
int TLuaInterpreter::replace( lua_State * L )
1265
int n = lua_gettop( L );
1267
if( ! lua_isstring( L, s ) )
1269
lua_pushstring( L, "replace: wrong argument type" );
1275
a1 = lua_tostring( L, s );
1279
QString _name( a1.c_str() );
1280
string luaSendText="";
1283
if( ! lua_isstring( L, s ) )
1285
lua_pushstring( L, "replace: wrong argument type" );
1291
a2 = lua_tostring( L, s );
1295
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
1297
pHost->mpConsole->replace( QString(a1.c_str()) );
1299
mudlet::self()->replace( pHost, _name, QString(a2.c_str()) );
1303
int TLuaInterpreter::deleteLine( lua_State * L )
1306
if( lua_gettop( L ) == 1 )
1308
if( ! lua_isstring( L, 1 ) )
1310
lua_pushstring( L, "deleteLine: wrong argument type" );
1316
name = lua_tostring( L, 1 );
1320
QString _name( name.c_str() );
1321
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
1324
pHost->mpConsole->skipLine();
1326
mudlet::self()->deleteLine( pHost, _name );
1330
int TLuaInterpreter::saveMap( lua_State * L )
1333
if( lua_gettop( L ) == 1 )
1335
if( ! lua_isstring( L, 1 ) )
1337
lua_pushstring( L, "saveMap: where do you want to save to?" );
1343
location = lua_tostring( L, 1 );
1347
QString _location( location.c_str() );
1348
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
1350
bool error = pHost->mpConsole->saveMap(_location);
1351
lua_pushboolean( L, error );
1355
// enableTimer( sess, timer_name )
1356
int TLuaInterpreter::enableTimer( lua_State *L )
1358
string luaSendText="";
1359
if( ! lua_isstring( L, 1 ) )
1361
lua_pushstring( L, "enableTimer: wrong argument type" );
1367
luaSendText = lua_tostring( L, 1 );
1369
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
1370
QString text(luaSendText.c_str());
1371
bool error = pHost->getTimerUnit()->enableTimer( text );
1372
lua_pushboolean( L, error );
1376
// disableTimer( session, timer_name )
1377
int TLuaInterpreter::disableTimer( lua_State *L )
1379
string luaSendText="";
1380
if( ! lua_isstring( L, 1 ) )
1382
lua_pushstring( L, "disableTimer: wrong argument type" );
1388
luaSendText = lua_tostring( L, 1 );
1390
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
1391
QString text(luaSendText.c_str());
1392
bool error = pHost->getTimerUnit()->disableTimer( text );
1393
lua_pushboolean( L, error );
1397
int TLuaInterpreter::enableKey( lua_State *L )
1399
string luaSendText="";
1400
if( ! lua_isstring( L, 1 ) )
1402
lua_pushstring( L, "enableKey: wrong argument type" );
1408
luaSendText = lua_tostring( L, 1 );
1410
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
1411
QString text(luaSendText.c_str());
1412
bool error = pHost->getKeyUnit()->enableKey( text );
1413
lua_pushboolean( L, error );
1417
// disableTimer( session, timer_name )
1418
int TLuaInterpreter::disableKey( lua_State *L )
1420
string luaSendText="";
1421
if( ! lua_isstring( L, 1 ) )
1423
lua_pushstring( L, "disableKey: wrong argument type" );
1429
luaSendText = lua_tostring( L, 1 );
1431
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
1432
QString text(luaSendText.c_str());
1433
bool error = pHost->getKeyUnit()->disableKey( text );
1434
lua_pushboolean( L, error );
1438
int TLuaInterpreter::enableAlias( lua_State *L )
1440
string luaSendText="";
1441
if( ! lua_isstring( L, 1 ) )
1443
lua_pushstring( L, "enableAlias: wrong argument type" );
1449
luaSendText = lua_tostring( L, 1 );
1451
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
1452
QString text(luaSendText.c_str());
1453
bool error = pHost->getAliasUnit()->enableAlias( text );
1454
lua_pushboolean( L, error );
1458
// disableTimer( session, timer_name )
1459
int TLuaInterpreter::disableAlias( lua_State *L )
1461
string luaSendText="";
1462
if( ! lua_isstring( L, 1 ) )
1464
lua_pushstring( L, "disableAlias: wrong argument type" );
1470
luaSendText = lua_tostring( L, 1 );
1472
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
1473
QString text(luaSendText.c_str());
1474
bool error = pHost->getAliasUnit()->disableAlias( text );
1475
lua_pushboolean( L, error );
1479
int TLuaInterpreter::killAlias( lua_State *L )
1481
string luaSendText="";
1482
if( ! lua_isstring( L, 1 ) )
1484
lua_pushstring( L, "killAlias: wrong argument type" );
1490
luaSendText = lua_tostring( L, 1 );
1492
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
1493
QString text(luaSendText.c_str());
1494
lua_pushboolean( L, pHost->getAliasUnit()->killAlias( text ) );
1498
// enableTimer( sess, timer_name )
1499
int TLuaInterpreter::enableTrigger( lua_State *L )
1501
string luaSendText="";
1502
if( ! lua_isstring( L, 1 ) )
1504
lua_pushstring( L, "enableTrigger: wrong argument type" );
1510
luaSendText = lua_tostring( L, 1 );
1512
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
1513
QString text(luaSendText.c_str());
1514
bool error = pHost->getTriggerUnit()->enableTrigger( text );
1515
lua_pushboolean( L, error );
1519
// disableTimer( session, timer_name )
1520
int TLuaInterpreter::disableTrigger( lua_State *L )
1522
string luaSendText="";
1523
if( ! lua_isstring( L, 1 ) )
1525
lua_pushstring( L, "disableTrigger: wrong argument type" );
1531
luaSendText = lua_tostring( L, 1 );
1533
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
1534
QString text(luaSendText.c_str());
1535
bool error = pHost->getTriggerUnit()->disableTrigger( text );
1536
lua_pushboolean( L, error );
1541
int TLuaInterpreter::killTimer( lua_State *L )
1543
string luaSendText="";
1544
if( ! lua_isstring( L, 1 ) )
1546
lua_pushstring( L, "killTimer: killTimer requires a string ID" );
1552
luaSendText = lua_tostring( L, 1 );
1554
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
1555
QString text(luaSendText.c_str());
1556
//pHost->disableTimer( text );
1557
lua_pushboolean( L, pHost->killTimer( text ) );
1561
int TLuaInterpreter::killTrigger( lua_State *L )
1563
string luaSendText="";
1564
if( ! lua_isstring( L, 1 ) )
1566
lua_pushstring( L, "killTrigger: wrong argument type" );
1572
luaSendText = lua_tostring( L, 1 );
1574
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
1575
QString text(luaSendText.c_str());
1576
lua_pushboolean( L, pHost->killTrigger( text ) );
1580
// openUserWindow( session, string window_name )
1581
int TLuaInterpreter::openUserWindow( lua_State *L )
1583
string luaSendText="";
1584
if( ! lua_isstring( L, 1 ) )
1586
lua_pushstring( L, "openUserWindow: wrong argument type" );
1592
luaSendText = lua_tostring( L, 1 );
1594
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
1595
QString text(luaSendText.c_str());
1596
mudlet::self()->openWindow( pHost, text );
1600
int TLuaInterpreter::createMiniConsole( lua_State *L )
1602
string luaSendText="";
1603
if( ! lua_isstring( L, 1 ) )
1605
lua_pushstring( L, "createMiniConsole: wrong argument type" );
1611
luaSendText = lua_tostring( L, 1 );
1613
int x,y,width,height;
1614
if( ! lua_isnumber( L, 2 ) )
1616
lua_pushstring( L, "createMiniConsole: wrong argument type" );
1622
x = lua_tonumber( L, 2 );
1624
if( ! lua_isnumber( L, 3 ) )
1626
lua_pushstring( L, "createMiniConsole: wrong argument type" );
1632
y = lua_tonumber( L, 3 );
1634
if( ! lua_isnumber( L, 4 ) )
1636
lua_pushstring( L, "createMiniConsole: wrong argument type" );
1642
width = lua_tonumber( L, 4 );
1644
if( ! lua_isnumber( L, 5 ) )
1646
lua_pushstring( L, "createMiniConsole: wrong argument type" );
1652
height = lua_tonumber( L, 5 );
1654
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
1655
QString name(luaSendText.c_str());
1656
lua_pushboolean( L, mudlet::self()->createMiniConsole( pHost, name, x, y, width, height ) );
1660
int TLuaInterpreter::createLabel( lua_State *L )
1662
string luaSendText="";
1663
if( ! lua_isstring( L, 1 ) )
1665
lua_pushstring( L, "createLabel: wrong argument type" );
1671
luaSendText = lua_tostring( L, 1 );
1673
int x,y,width,height;
1674
bool fillBackground=false;
1675
if( ! lua_isnumber( L, 2 ) )
1677
lua_pushstring( L, "createLabel: wrong argument type" );
1683
x = lua_tonumber( L, 2 );
1685
if( ! lua_isnumber( L, 3 ) )
1687
lua_pushstring( L, "createLabel: wrong argument type" );
1693
y = lua_tonumber( L, 3 );
1695
if( ! lua_isnumber( L, 4 ) )
1697
lua_pushstring( L, "createLabel: wrong argument type" );
1703
width = lua_tonumber( L, 4 );
1705
if( ! lua_isnumber( L, 5 ) )
1707
lua_pushstring( L, "createLabel: wrong argument type" );
1713
height = lua_tonumber( L, 5 );
1715
if( ! lua_isnumber( L, 6 ) )
1717
lua_pushstring( L, "createLabel: wrong argument type" );
1723
fillBackground = lua_toboolean( L, 6 );
1725
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
1726
QString name(luaSendText.c_str());
1727
lua_pushboolean( L, mudlet::self()->createLabel( pHost, name, x, y, width, height, fillBackground ) );
1731
int TLuaInterpreter::createMapper( lua_State *L )
1733
int x,y,width,height;
1734
if( ! lua_isnumber( L, 1 ) )
1736
lua_pushstring( L, "createMapper: wrong argument type" );
1742
x = lua_tonumber( L, 1 );
1744
if( ! lua_isnumber( L, 2 ) )
1746
lua_pushstring( L, "createMapper: wrong argument type" );
1752
y = lua_tonumber( L, 2 );
1754
if( ! lua_isnumber( L, 3 ) )
1756
lua_pushstring( L, "createMapper: wrong argument type" );
1762
width = lua_tonumber( L, 3 );
1764
if( ! lua_isnumber( L, 4 ) )
1766
lua_pushstring( L, "createMapper: wrong argument type" );
1772
height = lua_tonumber( L, 4 );
1774
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
1775
pHost->mpConsole->createMapper( x, y, width, height );
1780
int TLuaInterpreter::createButton( lua_State *L )
1782
string luaSendText="";
1783
if( ! lua_isstring( L, 1 ) )
1785
lua_pushstring( L, "createButton: wrong argument type" );
1791
luaSendText = lua_tostring( L, 1 );
1793
int x,y,width,height;
1794
bool fillBackground=false;
1795
if( ! lua_isnumber( L, 2 ) )
1797
lua_pushstring( L, "createButton: wrong argument type" );
1803
x = lua_tonumber( L, 2 );
1805
if( ! lua_isnumber( L, 3 ) )
1807
lua_pushstring( L, "createButton: wrong argument type" );
1813
y = lua_tonumber( L, 3 );
1815
if( ! lua_isnumber( L, 4 ) )
1817
lua_pushstring( L, "createButton: wrong argument type" );
1823
width = lua_tonumber( L, 4 );
1825
if( ! lua_isnumber( L, 5 ) )
1827
lua_pushstring( L, "createButton: wrong argument type" );
1833
height = lua_tonumber( L, 5 );
1835
if( ! lua_isnumber( L, 6 ) )
1837
lua_pushstring( L, "createButton: wrong argument type" );
1843
fillBackground = lua_toboolean( L, 6 );
1845
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
1846
QString name(luaSendText.c_str());
1848
mudlet::self()->createLabel( pHost, name, x, y, width, height, fillBackground );
1853
int TLuaInterpreter::createBuffer( lua_State *L )
1855
string luaSendText="";
1856
if( ! lua_isstring( L, 1 ) )
1858
lua_pushstring( L, "createBuffer: wrong argument type" );
1864
luaSendText = lua_tostring( L, 1 );
1866
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
1867
QString text(luaSendText.c_str());
1868
mudlet::self()->createBuffer( pHost, text );
1872
int TLuaInterpreter::clearUserWindow( lua_State *L )
1874
string luaSendText="";
1875
if( ! lua_isstring( L, 1 ) )
1877
lua_pushstring( L, "clearUserWindow: wrong argument type" );
1883
luaSendText = lua_tostring( L, 1 );
1885
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
1886
QString text(luaSendText.c_str());
1887
mudlet::self()->clearWindow( pHost, text );
1892
int TLuaInterpreter::closeUserWindow( lua_State *L )
1894
string luaSendText="";
1895
if( ! lua_isstring( L, 1 ) )
1897
lua_pushstring( L, "closeUserWindow: wrong argument type" );
1903
luaSendText = lua_tostring( L, 1 );
1905
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
1906
QString text(luaSendText.c_str());
1907
mudlet::self()->hideWindow( pHost, text );
1912
int TLuaInterpreter::hideUserWindow( lua_State *L )
1914
string luaSendText="";
1915
if( ! lua_isstring( L, 1 ) )
1917
lua_pushstring( L, "hideUserWindow: wrong argument type" );
1923
luaSendText = lua_tostring( L, 1 );
1925
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
1926
QString text(luaSendText.c_str());
1927
//mudlet::self()->hideWindow( pHost, text );
1928
pHost->mpConsole->hideWindow( text );
1933
int TLuaInterpreter::setBorderTop( lua_State *L )
1936
if( ! lua_isnumber( L, 1 ) )
1938
lua_pushstring( L, "setBorderTop: wrong argument type" );
1944
x1 = lua_tonumber( L, 1 );
1946
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
1947
pHost->mBorderTopHeight = x1;
1949
x = pHost->mpConsole->width();
1950
y = pHost->mpConsole->height();
1951
QSize s = QSize(x,y);
1952
QResizeEvent event(s, s);
1953
QApplication::sendEvent( pHost->mpConsole, &event);
1957
int TLuaInterpreter::setBorderBottom( lua_State *L )
1960
if( ! lua_isnumber( L, 1 ) )
1962
lua_pushstring( L, "setBorderBottom: wrong argument type" );
1968
x1 = lua_tonumber( L, 1 );
1970
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
1971
pHost->mBorderBottomHeight = x1;
1973
x = pHost->mpConsole->width();
1974
y = pHost->mpConsole->height();
1975
QSize s = QSize(x,y);
1976
QResizeEvent event(s, s);
1977
QApplication::sendEvent( pHost->mpConsole, &event);
1981
int TLuaInterpreter::setBorderLeft( lua_State *L )
1984
if( ! lua_isnumber( L, 1 ) )
1986
lua_pushstring( L, "setBorderLeft: wrong argument type" );
1992
x1 = lua_tonumber( L, 1 );
1994
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
1995
pHost->mBorderLeftWidth = x1;
1997
x = pHost->mpConsole->width();
1998
y = pHost->mpConsole->height();
1999
QSize s = QSize(x,y);
2000
QResizeEvent event(s, s);
2001
QApplication::sendEvent( pHost->mpConsole, &event);
2005
int TLuaInterpreter::setBorderRight( lua_State *L )
2008
if( ! lua_isnumber( L, 1 ) )
2010
lua_pushstring( L, "setBorderRight: wrong argument type" );
2016
x1 = lua_tonumber( L, 1 );
2018
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
2019
pHost->mBorderRightWidth = x1;
2021
x = pHost->mpConsole->width();
2022
y = pHost->mpConsole->height();
2023
QSize s = QSize(x,y);
2024
QResizeEvent event(s, s);
2025
QApplication::sendEvent( pHost->mpConsole, &event);
2029
int TLuaInterpreter::resizeUserWindow( lua_State *L )
2031
string luaSendText="";
2032
if( ! lua_isstring( L, 1 ) )
2034
lua_pushstring( L, "resizeUserWindow: wrong argument type" );
2040
luaSendText = lua_tostring( L, 1 );
2043
if( ! lua_isnumber( L, 2 ) )
2045
lua_pushstring( L, "resizeUserWindow: wrong argument type" );
2051
x1 = lua_tonumber( L, 2 );
2054
if( ! lua_isnumber( L, 3 ) )
2056
lua_pushstring( L, "resizeUserWindow: wrong argument type" );
2062
y1 = lua_tonumber( L, 3 );
2065
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
2066
QString text(luaSendText.c_str());
2067
mudlet::self()->resizeWindow( pHost, text, static_cast<int>(x1), static_cast<int>(y1) );
2072
int TLuaInterpreter::moveWindow( lua_State *L )
2074
string luaSendText="";
2075
if( ! lua_isstring( L, 1 ) )
2077
lua_pushstring( L, "moveWindow: wrong argument type" );
2083
luaSendText = lua_tostring( L, 1 );
2086
if( ! lua_isnumber( L, 2 ) )
2088
lua_pushstring( L, "moveWindow: wrong argument type" );
2094
x1 = lua_tonumber( L, 2 );
2097
if( ! lua_isnumber( L, 3 ) )
2099
lua_pushstring( L, "moveWindow: wrong argument type" );
2105
y1 = lua_tonumber( L, 3 );
2108
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
2110
QString text(luaSendText.c_str());
2111
mudlet::self()->moveWindow( pHost, text, static_cast<int>(x1), static_cast<int>(y1) );
2115
int TLuaInterpreter::setMainWindowSize( lua_State *L )
2118
if( ! lua_isnumber( L, 1 ) )
2120
lua_pushstring( L, "setBackgroundColor: wrong argument type" );
2126
x1 = lua_tonumber( L, 1 );
2129
if( ! lua_isnumber( L, 2 ) )
2131
lua_pushstring( L, "setBackgroundColor: wrong argument type" );
2137
y1 = lua_tonumber( L, 2 );
2139
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
2141
mudlet::self()->resize( x1, y1 );
2146
int TLuaInterpreter::setBackgroundColor( lua_State *L )
2148
string luaSendText="";
2149
if( ! lua_isstring( L, 1 ) )
2151
lua_pushstring( L, "setBackgroundColor: wrong argument type" );
2157
luaSendText = lua_tostring( L, 1 );
2160
if( ! lua_isnumber( L, 2 ) )
2162
lua_pushstring( L, "setBackgroundColor: wrong argument type" );
2168
x1 = lua_tonumber( L, 2 );
2171
if( ! lua_isnumber( L, 3 ) )
2173
lua_pushstring( L, "setBackgroundColor: wrong argument type" );
2179
y1 = lua_tonumber( L, 3 );
2182
if( ! lua_isnumber( L, 4 ) )
2184
lua_pushstring( L, "setBackgroundColor: wrong argument type" );
2190
x2 = lua_tonumber( L, 4 );
2193
if( ! lua_isnumber( L, 5 ) )
2195
lua_pushstring( L, "setBackgroundColor: wrong argument type" );
2201
y2 = lua_tonumber( L, 5 );
2203
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
2204
QString text(luaSendText.c_str());
2205
mudlet::self()->setBackgroundColor( pHost, text, static_cast<int>(x1), static_cast<int>(y1), static_cast<int>(x2), static_cast<int>(y2) );
2210
int TLuaInterpreter::calcFontWidth( int size )
2212
QFont font = QFont("Bitstream Vera Sans Mono", size, QFont::Courier);
2213
return QFontMetrics( font ).width( QChar('W') );
2216
int TLuaInterpreter::calcFontHeight( int size )
2218
QFont font = QFont("Bitstream Vera Sans Mono", size, QFont::Courier);
2219
int fontDescent = QFontMetrics( font ).descent();
2220
int fontAscent = QFontMetrics( font ).ascent();
2221
return fontAscent + fontDescent;
2224
int TLuaInterpreter::calcFontSize( lua_State *L )
2227
if( ! lua_isnumber( L, 1 ) )
2229
lua_pushstring( L, "calcFontSize: wrong argument type" );
2235
x = lua_tonumber( L, 1 );
2238
lua_pushnumber( L, calcFontWidth( x ) );
2239
lua_pushnumber( L, calcFontHeight( x ) );
2243
int TLuaInterpreter::startLogging( lua_State *L )
2246
if( ! lua_isboolean( L, 1 ) )
2248
lua_pushstring( L, "startLogging: wrong argument type" );
2254
logOn = lua_toboolean( L, 1 );
2257
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
2258
pHost->mpConsole->mLogToLogFile = ! logOn;
2259
pHost->mpConsole->slot_toggleLogging();
2263
int TLuaInterpreter::setBackgroundImage( lua_State *L )
2265
string luaSendText="";
2266
if( ! lua_isstring( L, 1 ) )
2268
lua_pushstring( L, "setBackgroundImage: wrong argument type" );
2274
luaSendText = lua_tostring( L, 1 );
2277
if( ! lua_isstring( L, 2 ) )
2279
lua_pushstring( L, "setBackgroundImage: wrong argument type" );
2285
luaName = lua_tostring( L, 2 );
2288
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
2289
QString text(luaSendText.c_str());
2290
QString name(luaName.c_str());
2291
mudlet::self()->setBackgroundImage( pHost, text, name );
2296
int TLuaInterpreter::setLabelClickCallback( lua_State *L )
2298
string luaSendText="";
2299
if( ! lua_isstring( L, 1 ) )
2301
lua_pushstring( L, "setLabelClickCallback: wrong argument type" );
2307
luaSendText = lua_tostring( L, 1 );
2310
if( ! lua_isstring( L, 2 ) )
2312
lua_pushstring( L, "setLabelClickCallback: wrong argument type" );
2318
luaName = lua_tostring( L, 2 );
2321
TEvent * pE = new TEvent;
2323
int n = lua_gettop( L );
2324
for( int i=3; i<=n; i++)
2326
if( lua_isnumber( L, i ) )
2328
pE->mArgumentList.append( QString::number(lua_tonumber( L, i ) ) );
2329
pE->mArgumentTypeList.append( ARGUMENT_TYPE_NUMBER );
2331
else if( lua_isstring( L, i ) )
2333
pE->mArgumentList.append( QString(lua_tostring( L, i )) );
2334
pE->mArgumentTypeList.append( ARGUMENT_TYPE_STRING );
2338
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
2339
QString text(luaSendText.c_str());
2340
QString name(luaName.c_str());
2341
mudlet::self()->setLabelClickCallback( pHost, text, name, pE );
2346
int TLuaInterpreter::setTextFormat( lua_State *L )
2348
string luaSendText="";
2349
if( ! lua_isstring( L, 1 ) )
2351
lua_pushstring( L, "setTextFormat: wrong argument type" );
2357
luaSendText = lua_tostring( L, 1 );
2360
if( ! lua_isnumber( L, 2 ) )
2362
lua_pushstring( L, "setTextFormat: wrong argument type" );
2368
r1 = lua_tonumber( L, 2 );
2371
if( ! lua_isnumber( L, 3 ) )
2373
lua_pushstring( L, "setTextFormat: wrong argument type" );
2379
g1 = lua_tonumber( L, 3 );
2382
if( ! lua_isnumber( L, 4 ) )
2384
lua_pushstring( L, "setTextFormat: wrong argument type" );
2390
b1 = lua_tonumber( L, 4 );
2393
if( ! lua_isnumber( L, 5 ) )
2395
lua_pushstring( L, "setTextFormat: wrong argument type" );
2401
r2 = lua_tonumber( L, 5 );
2404
if( ! lua_isnumber( L, 6 ) )
2406
lua_pushstring( L, "setTextFormat: wrong argument type" );
2412
g2 = lua_tonumber( L, 6 );
2415
if( ! lua_isnumber( L, 7 ) )
2417
lua_pushstring( L, "setTextFormat: wrong argument type" );
2423
b2 = lua_tonumber( L, 7 );
2426
if( ! lua_isnumber( L, 8 ) )
2428
lua_pushstring( L, "setTextFormat: wrong argument type" );
2434
bold = lua_tonumber( L, 8 );
2437
if( ! lua_isnumber( L, 9 ) )
2439
lua_pushstring( L, "setTextFormat: wrong argument type" );
2445
underline = lua_tonumber( L, 9 );
2448
if( ! lua_isnumber( L, 10 ) )
2450
lua_pushstring( L, "setTextFormat: wrong argument type" );
2456
italics = lua_tonumber( L, 10 );
2458
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
2459
QString text(luaSendText.c_str());
2460
if( text == "main" )
2462
TConsole * pC = pHost->mpConsole;
2463
pC->mFormatCurrent.bgR = r1;
2464
pC->mFormatCurrent.bgG = g1;
2465
pC->mFormatCurrent.bgB = b1;
2466
pC->mFormatCurrent.fgR = r2;
2467
pC->mFormatCurrent.fgG = g2;
2468
pC->mFormatCurrent.fgB = b2;
2469
pC->mFormatCurrent.bold = bold;
2470
pC->mFormatCurrent.underline = underline;
2471
pC->mFormatCurrent.italics = italics;
2476
mudlet::self()->setTextFormat( pHost, text, static_cast<int>(r1), static_cast<int>(g1), static_cast<int>(b1), static_cast<int>(r2),static_cast<int>(g2), static_cast<int>(b2), static_cast<bool>(bold), static_cast<bool>(underline), static_cast<bool>(italics) );
2482
int TLuaInterpreter::showUserWindow( lua_State *L )
2484
string luaSendText="";
2485
if( ! lua_isstring( L, 1 ) )
2487
lua_pushstring( L, "showUserWindow: wrong argument type" );
2493
luaSendText = lua_tostring( L, 1 );
2495
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
2496
QString text(luaSendText.c_str());
2497
lua_pushboolean( L, pHost->mpConsole->showWindow( text ));
2501
// xRot, yRot, zRot, zoom
2502
int TLuaInterpreter::setMapperView( lua_State *L )
2504
float x, y, z, zoom;
2506
if( ! lua_isnumber( L, 1 ) )
2508
lua_pushstring( L, "setMapperView: wrong argument type" );
2514
x = lua_tonumber( L, 1 );
2517
if( ! lua_isnumber( L, 2 ) )
2519
lua_pushstring( L, "setMapperView: wrong argument type" );
2525
y = lua_tonumber( L, 2 );
2527
if( ! lua_isnumber( L, 3 ) )
2529
lua_pushstring( L, "setMapperView: wrong argument type" );
2535
z = lua_tonumber( L, 3 );
2537
if( ! lua_isnumber( L, 4 ) )
2539
lua_pushstring( L, "setMapperView: wrong argument type" );
2545
zoom = lua_tonumber( L, 4 );
2547
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
2549
pHost->mpMap->setView( x, y, z, zoom );
2553
int TLuaInterpreter::setRoomEnv( lua_State *L )
2556
if( ! lua_isnumber( L, 1 ) )
2558
lua_pushstring( L, "setRoomEnv: wrong argument type" );
2564
id = lua_tonumber( L, 1 );
2566
if( ! lua_isnumber( L, 2 ) )
2568
lua_pushstring( L, "setRoomEnv: wrong argument type" );
2574
env = lua_tonumber( L, 2 );
2576
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
2577
if( pHost->mpMap->rooms.contains( id ) )
2579
pHost->mpMap->rooms[id]->environment = env;
2585
int TLuaInterpreter::setRoomName( lua_State *L )
2589
if( ! lua_isnumber( L, 1 ) )
2591
lua_pushstring( L, "setRoomName: wrong argument type" );
2597
id = lua_tonumber( L, 1 );
2599
if( ! lua_isstring( L, 2 ) )
2601
lua_pushstring( L, "setRoomName: wrong argument type" );
2607
name = lua_tostring( L, 2 );
2609
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
2610
QString _name = name.c_str();
2611
if( pHost->mpMap->rooms.contains( id ) )
2613
pHost->mpMap->rooms[id]->name = _name;
2619
int TLuaInterpreter::getRoomName( lua_State *L )
2622
if( ! lua_isnumber( L, 1 ) )
2624
lua_pushstring( L, "getRoomName: wrong argument type" );
2630
id = lua_tonumber( L, 1 );
2632
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
2633
if( pHost->mpMap->rooms.contains( id ) )
2635
lua_pushstring(L, pHost->mpMap->rooms[id]->name.toLatin1().data() );
2641
int TLuaInterpreter::setRoomWeight( lua_State *L )
2644
if( ! lua_isnumber( L, 1 ) )
2646
lua_pushstring( L, "setRoomWeight: wrong argument type" );
2652
id = lua_tonumber( L, 1 );
2655
if( ! lua_isnumber( L, 2 ) )
2657
lua_pushstring( L, "setRoomWeight: wrong argument type" );
2663
w = lua_tonumber( L, 2 );
2665
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
2666
if( pHost->mpMap->rooms.contains( id ) )
2668
pHost->mpMap->rooms[id]->weight = w;
2669
pHost->mpMap->mMapGraphNeedsUpdate = true;
2675
int TLuaInterpreter::connectToServer( lua_State *L )
2679
if( ! lua_isstring( L, 1 ) )
2681
lua_pushstring( L, "connectToServer: wrong argument type" );
2687
url = lua_tostring( L, 1 );
2690
if( ! lua_isnumber( L, 2 ) )
2692
lua_pushstring( L, "connectToServer: wrong argument type" );
2698
port = lua_tonumber( L, 2 );
2700
QString _url = url.c_str();
2701
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
2702
pHost->mTelnet.connectIt( _url, port );
2706
int TLuaInterpreter::setRoomIDbyHash( lua_State *L )
2709
if( ! lua_isnumber( L, 1 ) )
2711
lua_pushstring( L, "setRoomIDbyHash: wrong argument type" );
2717
id = lua_tonumber( L, 1 );
2720
if( ! lua_isstring( L, 2 ) )
2722
lua_pushstring( L, "setRoomIDbyHash: wrong argument type" );
2728
hash = lua_tostring( L, 2 );
2730
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
2731
pHost->mpMap->hashTable[QString(hash.c_str())] = id;
2735
int TLuaInterpreter::getRoomIDbyHash( lua_State *L )
2738
if( ! lua_isstring( L, 1 ) )
2740
lua_pushstring( L, "getRoomIDbyHash() wrong argument type" );
2746
hash = lua_tostring( L, 1 );
2748
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
2750
QString _hash = hash.c_str();
2751
if( pHost->mpMap->hashTable.contains( _hash ) )
2753
retID = pHost->mpMap->hashTable[_hash];
2754
lua_pushnumber( L, retID );
2757
lua_pushnumber( L, -1 );
2762
int TLuaInterpreter::solveRoomCollisions( lua_State *L )
2765
if( ! lua_isnumber( L, 1 ) )
2767
lua_pushstring( L, "solveRoomCollisions() wrong argument type" );
2773
id = lua_tonumber( L, 1 );
2775
int creationDirection=0;
2776
if( ! lua_isnumber( L, 2 ) )
2778
lua_pushstring( L, "solveRoomCollisons() wrong argument type" );
2784
creationDirection = lua_tonumber( L, 2 );
2786
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
2787
if( pHost->mpMap->rooms.contains( id ) )
2789
pHost->mpMap->solveRoomCollision( id, creationDirection );
2794
int TLuaInterpreter::roomLocked( lua_State *L )
2797
if( ! lua_isnumber( L, 1 ) )
2799
lua_pushstring( L, "roomLocked: wrong argument type" );
2805
id = lua_tonumber( L, 1 );
2808
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
2809
if( pHost->mpMap->rooms.contains( id ) )
2811
bool r = pHost->mpMap->rooms[id]->isLocked;
2812
lua_pushboolean( L, r );
2816
lua_pushboolean(L, false);
2821
int TLuaInterpreter::lockRoom( lua_State *L )
2825
if( ! lua_isnumber( L, 1 ) )
2827
lua_pushstring( L, "lockRoom: wrong argument type" );
2833
id = lua_tonumber( L, 1 );
2836
if( ! lua_isboolean( L, 2 ) )
2838
lua_pushstring( L, "lockRoom: wrong argument type" );
2844
b = lua_toboolean( L, 2 );
2846
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
2847
if( pHost->mpMap->rooms.contains( id ) )
2849
pHost->mpMap->rooms[id]->isLocked = b;
2850
pHost->mpMap->mMapGraphNeedsUpdate = true;
2851
lua_pushboolean(L, true);
2855
lua_pushboolean(L, false);
2860
int TLuaInterpreter::lockExit( lua_State *L )
2865
if( ! lua_isnumber( L, 1 ) )
2867
lua_pushstring( L, "lockExit: wrong argument type" );
2873
id = lua_tonumber( L, 1 );
2877
if( ! lua_isnumber( L, 2 ) )
2879
lua_pushstring( L, "lockExit: wrong argument type" );
2885
dir = lua_tonumber( L, 2 );
2888
if( ! lua_isboolean( L, 3 ) )
2890
lua_pushstring( L, "lockRoom: wrong argument type" );
2896
b = lua_toboolean( L, 3 );
2898
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
2899
if( pHost->mpMap->rooms.contains( id ) )
2901
pHost->mpMap->rooms[id]->setExitLock( dir, b );
2902
pHost->mpMap->mMapGraphNeedsUpdate = true;
2907
int TLuaInterpreter::lockSpecialExit( lua_State *L )
2912
if( ! lua_isnumber( L, 1 ) )
2914
lua_pushstring( L, "lockSpecialExit: wrong argument type" );
2920
id = lua_tonumber( L, 1 );
2923
if( ! lua_isnumber( L, 2 ) )
2925
lua_pushstring( L, "lockExit: wrong argument type" );
2931
to = lua_tonumber( L, 2 );
2934
if( ! lua_isstring( L, 3 ) )
2936
lua_pushstring( L, "lockSpecialExit: wrong argument type" );
2942
dir = lua_tostring( L, 3 );
2945
if( ! lua_isboolean( L, 4 ) )
2947
lua_pushstring( L, "lockSpecialExit: wrong argument type" );
2953
b = lua_toboolean( L, 4 );
2955
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
2956
if( pHost->mpMap->rooms.contains( id ) )
2958
QString _dir = dir.c_str();
2959
pHost->mpMap->rooms[id]->setSpecialExitLock( to, _dir, b );
2960
pHost->mpMap->mMapGraphNeedsUpdate = true;
2965
int TLuaInterpreter::hasSpecialExitLock( lua_State *L )
2970
if( ! lua_isnumber( L, 1 ) )
2972
lua_pushstring( L, "lockExit: wrong argument type" );
2978
id = lua_tonumber( L, 1 );
2982
if( ! lua_isnumber( L, 2 ) )
2984
lua_pushstring( L, "lockExit: wrong argument type" );
2990
to = lua_tonumber( L, 2 );
2992
if( ! lua_isstring( L, 3 ) )
2994
lua_pushstring( L, "hasSpecialExitLock: wrong argument type" );
3000
dir = lua_tostring( L, 3 );
3002
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
3003
if( pHost->mpMap->rooms.contains( id ) )
3005
QString _dir = dir.c_str();
3006
lua_pushboolean( L, pHost->mpMap->rooms[id]->hasSpecialExitLock( to, _dir ) );
3012
int TLuaInterpreter::hasExitLock( lua_State *L )
3016
if( ! lua_isnumber( L, 1 ) )
3018
lua_pushstring( L, "lockExit: wrong argument type" );
3024
id = lua_tonumber( L, 1 );
3028
if( ! lua_isnumber( L, 2 ) )
3030
lua_pushstring( L, "lockExit: wrong argument type" );
3036
dir = lua_tonumber( L, 2 );
3039
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
3040
if( pHost->mpMap->rooms.contains( id ) )
3042
lua_pushboolean( L, pHost->mpMap->rooms[id]->hasExitLock(dir) );
3048
int TLuaInterpreter::isLockedRoom( lua_State *L )
3051
if( ! lua_isnumber( L, 1 ) )
3053
lua_pushstring( L, "lockRoom: wrong argument type" );
3059
id = lua_tonumber( L, 1 );
3062
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
3063
if( pHost->mpMap->rooms.contains( id ) )
3065
lua_pushboolean( L, pHost->mpMap->rooms[id]->isLocked );
3069
lua_pushboolean(L, false);
3075
int TLuaInterpreter::getRoomExits( lua_State *L )
3078
if( ! lua_isnumber( L, 1 ) )
3080
lua_pushstring( L, "getRoomExits: wrong argument type" );
3086
id = lua_tonumber( L, 1 );
3089
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
3090
if( pHost->mpMap->rooms.contains( id ) )
3093
if( pHost->mpMap->rooms[id]->north != -1 )
3095
lua_pushstring( L, "north" );
3096
lua_pushnumber( L, pHost->mpMap->rooms[id]->north );
3097
lua_settable(L, -3);
3099
if( pHost->mpMap->rooms[id]->northwest != -1 )
3101
lua_pushstring( L, "northwest" );
3102
lua_pushnumber( L, pHost->mpMap->rooms[id]->northwest );
3103
lua_settable(L, -3);
3105
if( pHost->mpMap->rooms[id]->northeast != -1 )
3107
lua_pushstring( L, "northeast" );
3108
lua_pushnumber( L, pHost->mpMap->rooms[id]->northeast );
3109
lua_settable(L, -3);
3111
if( pHost->mpMap->rooms[id]->south != -1 )
3113
lua_pushstring( L, "south" );
3114
lua_pushnumber( L, pHost->mpMap->rooms[id]->south );
3115
lua_settable(L, -3);
3117
if( pHost->mpMap->rooms[id]->southwest != -1 )
3119
lua_pushstring( L, "southwest" );
3120
lua_pushnumber( L, pHost->mpMap->rooms[id]->southwest );
3121
lua_settable(L, -3);
3123
if( pHost->mpMap->rooms[id]->southeast != -1 )
3125
lua_pushstring( L, "southeast" );
3126
lua_pushnumber( L, pHost->mpMap->rooms[id]->southeast );
3127
lua_settable(L, -3);
3129
if( pHost->mpMap->rooms[id]->west != -1 )
3131
lua_pushstring( L, "west" );
3132
lua_pushnumber( L, pHost->mpMap->rooms[id]->west );
3133
lua_settable(L, -3);
3135
if( pHost->mpMap->rooms[id]->east != -1 )
3137
lua_pushstring( L, "east" );
3138
lua_pushnumber( L, pHost->mpMap->rooms[id]->east );
3139
lua_settable(L, -3);
3141
if( pHost->mpMap->rooms[id]->up != -1 )
3143
lua_pushstring( L, "up" );
3144
lua_pushnumber( L, pHost->mpMap->rooms[id]->up );
3145
lua_settable(L, -3);
3147
if( pHost->mpMap->rooms[id]->down != -1 )
3149
lua_pushstring( L, "down" );
3150
lua_pushnumber( L, pHost->mpMap->rooms[id]->down );
3151
lua_settable(L, -3);
3153
if( pHost->mpMap->rooms[id]->in != -1 )
3155
lua_pushstring( L, "in" );
3156
lua_pushnumber( L, pHost->mpMap->rooms[id]->in );
3157
lua_settable(L, -3);
3159
if( pHost->mpMap->rooms[id]->out != -1 )
3161
lua_pushstring( L, "out" );
3162
lua_pushnumber( L, pHost->mpMap->rooms[id]->out );
3163
lua_settable(L, -3);
3171
int TLuaInterpreter::searchRoom( lua_State *L )
3174
bool gotRoomID = false;
3176
if( lua_isnumber( L, 1 ) )
3178
room_id = lua_tointeger( L, 1 );
3181
else if( lua_isstring( L, 1 ) )
3183
room = lua_tostring( L, 1 );
3187
lua_pushstring( L, "searchRoom: wrong argument type" );
3192
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
3195
if( pHost->mpMap->rooms.contains( room_id ) )
3197
lua_pushstring( L, pHost->mpMap->rooms[room_id]->name.toLatin1().data() );
3202
lua_pushstring( L, "searchRoom ERROR: no such room" );
3208
QMapIterator<int, TRoom *> it( pHost->mpMap->rooms );
3210
while( it.hasNext() )
3214
if( pHost->mpMap->rooms[i]->name.contains( QString(room.c_str()), Qt::CaseInsensitive ) )
3216
QString name = pHost->mpMap->rooms[i]->name;
3217
int roomID = pHost->mpMap->rooms[i]->id;
3218
lua_pushstring( L, name.toLatin1().data() );
3219
lua_pushnumber( L, roomID );
3220
lua_settable(L, -3);
3227
int TLuaInterpreter::getAreaTable( lua_State *L )
3229
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
3230
QMapIterator<int, QString> it( pHost->mpMap->areaNamesMap );
3232
while( it.hasNext() )
3235
int roomID = it.key();
3236
QString name = it.value();
3237
lua_pushstring( L, name.toLatin1().data() );
3238
lua_pushnumber( L, roomID );
3239
lua_settable(L, -3);
3244
int TLuaInterpreter::getAreaRooms( lua_State *L )
3247
if( ! lua_isnumber( L, 1 ) )
3249
lua_pushstring( L, "getAreaRooms: wrong argument type" );
3255
area = lua_tonumber( L, 1 );
3257
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
3258
if( ! pHost->mpMap->areas.contains( area ) )
3264
for( int i=0; i<pHost->mpMap->areas[area]->rooms.size(); i++ )
3266
int roomID = pHost->mpMap->areas[area]->rooms.at( i );
3267
lua_pushnumber( L, i );
3268
lua_pushnumber( L, roomID );
3269
lua_settable(L, -3);
3274
int TLuaInterpreter::getRooms( lua_State *L )
3276
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
3278
QMapIterator<int,TRoom*> it(pHost->mpMap->rooms);
3279
while( it.hasNext() )
3282
lua_pushnumber( L, it.key() );
3283
lua_pushstring( L, it.value()->name.toLatin1().data() );
3284
lua_settable(L, -3);
3291
int TLuaInterpreter::getRoomWeight( lua_State *L )
3293
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
3294
if( pHost->mpMap->rooms.contains( pHost->mpMap->mRoomId ) )
3296
lua_pushnumber( L, pHost->mpMap->rooms[pHost->mpMap->mRoomId]->weight );
3302
int TLuaInterpreter::gotoRoom( lua_State *L )
3305
if( ! lua_isnumber( L, 1 ) )
3307
lua_pushstring( L, "gotoRoom: wrong argument type" );
3313
r = lua_tonumber( L, 1 );
3315
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
3316
bool ret = pHost->mpMap->gotoRoom( r );
3317
pHost->startSpeedWalk();
3318
lua_pushboolean( L, ret );
3322
int TLuaInterpreter::getPath( lua_State *L )
3326
if( ! lua_isnumber( L, 1 ) )
3328
lua_pushstring( L, "getPath: wrong argument type" );
3334
r1 = lua_tonumber( L, 1 );
3336
if( ! lua_isnumber( L, 2 ) )
3338
lua_pushstring( L, "getPath: wrong argument type" );
3344
r2 = lua_tonumber( L, 2 );
3346
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
3347
bool ret = pHost->mpMap->gotoRoom( r1, r2 );
3348
pHost->assemblePath();
3349
lua_pushboolean( L, ret );
3353
int TLuaInterpreter::deselect( lua_State *L )
3355
string luaWindowName="";
3356
if( lua_isstring( L, 1 ) )
3358
luaWindowName = lua_tostring( L, 1 );
3361
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
3362
QString name = luaWindowName.c_str();
3363
if( luaWindowName.size() < 1 || luaWindowName == "main" )
3365
pHost->mpConsole->deselect();
3369
mudlet::self()->deselect( pHost, name );
3374
int TLuaInterpreter::reset( lua_State *L )
3376
string luaWindowName="";
3377
if( lua_isstring( L, 1 ) )
3379
luaWindowName = lua_tostring( L, 1 );
3382
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
3383
QString name = luaWindowName.c_str();
3384
if( luaWindowName.size() < 1 || luaWindowName == "main" )
3386
pHost->mpConsole->reset();
3390
mudlet::self()->resetFormat( pHost, name );
3395
int TLuaInterpreter::hasFocus( lua_State *L )
3397
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
3398
lua_pushboolean( L, pHost->mpConsole->hasFocus() );//FIXME
3402
int TLuaInterpreter::echoUserWindow( lua_State *L )
3404
string luaWindowName="";
3405
if( ! lua_isstring( L, 1 ) )
3407
lua_pushstring( L, "echoUserWindow: wrong argument type" );
3413
luaWindowName = lua_tostring( L, 1 );
3416
string luaSendText="";
3417
if( ! lua_isstring( L, 2 ) )
3419
lua_pushstring( L, "echoUserWindow: wrong argument type" );
3425
luaSendText = lua_tostring( L, 2 );
3427
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
3428
QString text(luaSendText.c_str());
3429
QString windowName(luaWindowName.c_str());
3430
mudlet::self()->echoWindow( pHost, windowName, text );
3434
//qApp->setStyleSheet("QMainWindow::separator{border: 0px;width: 0px; height: 0px; padding: 0px;} QMainWindow::separator:hover {background: red;}");
3435
int TLuaInterpreter::setAppStyleSheet( lua_State *L )
3437
string luaWindowName="";
3438
if( lua_isstring( L, 1 ) )
3440
luaWindowName = lua_tostring( L, 1 );
3443
luaWindowName = "main";
3444
qApp->setStyleSheet( luaWindowName.c_str() );
3447
// this is an internal only function used by the package system
3448
int TLuaInterpreter::showUnzipProgress( lua_State * L )
3450
string luaSendText="";
3451
if( ! lua_isstring( L, 1 ) )
3453
lua_pushstring( L, "showUnzipProgress: wrong argument type" );
3459
luaSendText = lua_tostring( L, 1 );
3461
QString txt = luaSendText.c_str();
3462
mudlet::self()->showUnzipProgress( txt );
3472
int TLuaInterpreter::playSoundFile( lua_State * L )
3474
string luaSendText="";
3475
if( ! lua_isstring( L, 1 ) )
3477
lua_pushstring( L, "playSoundFile: wrong argument type" );
3483
luaSendText = lua_tostring( L, 1 );
3485
QString sound = luaSendText.c_str();
3486
//QSound::play( QString( luaSendText.c_str() ) );
3487
if( QDir::homePath().contains('\\') )
3489
sound.replace('/', "\\");
3493
sound.replace('\\', "/");
3495
mudlet::self()->playSound( sound );
3499
int TLuaInterpreter::moveCursorEnd( lua_State *L )
3501
string luaWindowName="";
3502
if( lua_isstring( L, 1 ) )
3504
luaWindowName = lua_tostring( L, 1 );
3507
luaWindowName = "main";
3509
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
3510
QString windowName(luaWindowName.c_str());
3511
if( luaWindowName == "main" )
3512
pHost->mpConsole->moveCursorEnd();
3514
mudlet::self()->moveCursorEnd( pHost, windowName );
3518
int TLuaInterpreter::getLastLineNumber( lua_State *L )
3520
string luaWindowName;
3521
if( ! lua_isstring( L, 1 ) )
3523
lua_pushstring( L, "getLastLineNumber: wrong argument type" );
3529
luaWindowName = lua_tostring( L, 1 );
3532
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
3533
QString windowName(luaWindowName.c_str());
3535
if( luaWindowName == "main" )
3536
number = pHost->mpConsole->getLastLineNumber();
3538
number = mudlet::self()->getLastLineNumber( pHost, windowName );
3539
lua_pushnumber( L, number );
3545
int TLuaInterpreter::getMudletHomeDir( lua_State * L )
3547
QString home = QDir::homePath();
3548
home.append( "/.config/mudlet/profiles/" );
3549
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
3550
QString name = pHost->getName();
3551
home.append( name );
3552
QString erg = QDir::toNativeSeparators( home );
3553
lua_pushstring( L, erg.toLatin1().data() );
3557
int TLuaInterpreter::disconnect( lua_State * L )
3559
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
3560
pHost->mTelnet.disconnect();
3564
int TLuaInterpreter::reconnect( lua_State * L )
3566
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
3567
pHost->mTelnet.connectIt( pHost->getUrl(), pHost->getPort() );
3571
int TLuaInterpreter::setTriggerStayOpen( lua_State *L )
3573
string luaWindowName;
3576
if( lua_gettop( L ) > 1 )
3578
if( ! lua_isstring( L, s ) )
3580
lua_pushstring( L, "setTriggerStayOpen: wrong argument type" );
3586
luaWindowName = lua_tostring( L, s );
3590
if( ! lua_isnumber( L, s ) )
3592
lua_pushstring( L, "setTriggerStayOpen: wrong argument type" );
3598
b = lua_tonumber( L, s );
3601
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
3602
QString windowName(luaWindowName.c_str());
3603
pHost->getTriggerUnit()->setTriggerStayOpen( QString( luaWindowName.c_str() ), static_cast<int>(b) );
3607
int TLuaInterpreter::setLink( lua_State * L )
3609
string luaWindowName;
3611
string linkFunction;
3614
if( lua_gettop( L ) > 2 )
3616
if( ! lua_isstring( L, s ) )
3618
lua_pushstring( L, "setLink: wrong argument type" );
3624
luaWindowName = lua_tostring( L, s );
3628
/*if( ! lua_isstring( L, s ) )
3630
lua_pushstring( L, "setLink: wrong argument type" );
3636
linkText = lua_tostring( L, s );
3640
if( ! lua_isstring( L, s ) )
3642
lua_pushstring( L, "setLink: wrong argument type" );
3648
linkFunction = lua_tostring( L, s );
3651
if( ! lua_isstring( L, s ) )
3653
lua_pushstring( L, "setLink: wrong argument type" );
3659
linkHint = lua_tostring( L, s );
3664
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
3665
QString windowName(luaWindowName.c_str());
3666
QString _linkText = "";//QString(linkText.c_str());
3667
QStringList _linkFunction;
3668
_linkFunction << QString(linkFunction.c_str());
3669
QStringList _linkHint;
3670
_linkHint << QString(linkHint.c_str());
3671
if( windowName.size() > 0 )
3672
mudlet::self()->setLink( pHost, windowName, _linkText, _linkFunction, _linkHint );
3674
pHost->mpConsole->setLink( _linkText, _linkFunction, _linkHint );
3678
int TLuaInterpreter::setPopup( lua_State *L )
3682
QStringList _hintList;
3683
QStringList _commandList;
3684
bool customFormat = false;
3686
int n = lua_gettop( L );
3687
// console name is an optional first argument
3690
if( ! lua_isstring( L, s ) )
3692
lua_pushstring( L, "setPopup: wrong argument type" );
3698
a1 = lua_tostring( L, s );
3702
if( ! lua_isstring( L, s ) )
3704
lua_pushstring( L, "setPopup: wrong argument type" );
3710
a2 = lua_tostring( L, s );
3714
if( ! lua_istable( L, s ) )
3716
lua_pushstring( L, "setPopup: wrong argument type" );
3723
while( lua_next( L, s ) != 0 )
3725
// key at index -2 and value at index -1
3726
if( lua_type(L, -1) == LUA_TSTRING )
3728
QString cmd = lua_tostring( L, -1 );
3729
_commandList << cmd;
3731
// removes value, but keeps key for next iteration
3736
if( ! lua_istable( L, s ) )
3738
lua_pushstring( L, "setPopup: wrong argument type" );
3745
while( lua_next( L, s ) != 0 )
3747
// key at index -2 and value at index -1
3748
if( lua_type(L, -1) == LUA_TSTRING )
3750
QString hint = lua_tostring( L, -1 );
3753
// removes value, but keeps key for next iteration
3760
customFormat = lua_toboolean( L, s );
3763
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
3764
QString txt = a2.c_str();
3765
QString name = a1.c_str();
3766
if( _commandList.size() != _hintList.size() )
3768
lua_pushstring( L, "Error: command list size and hint list size do not match cannot create popup" );
3775
pHost->mpConsole->setLink( txt, _commandList, _hintList );
3779
mudlet::self()->setLink( pHost, name, txt, _commandList, _hintList );
3786
int TLuaInterpreter::setBold( lua_State * L )
3788
string luaWindowName;
3791
if( lua_gettop( L ) > 1 )
3793
if( ! lua_isstring( L, s ) )
3795
lua_pushstring( L, "setBold: wrong argument type" );
3801
luaWindowName = lua_tostring( L, s );
3805
if( ! lua_isboolean( L, s ) )
3807
lua_pushstring( L, "setBold: wrong argument type" );
3813
b = lua_toboolean( L, s );
3816
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
3817
QString windowName(luaWindowName.c_str());
3818
if( windowName.size() > 0 )
3819
mudlet::self()->setBold( pHost, windowName, b );
3821
pHost->mpConsole->setBold( b );
3825
int TLuaInterpreter::setItalics( lua_State *L )
3827
string luaWindowName;
3830
if( lua_gettop( L ) > 1 )
3832
if( ! lua_isstring( L, s ) )
3834
lua_pushstring( L, "setItalics: wrong argument type" );
3840
luaWindowName = lua_tostring( L, s );
3844
if( ! lua_isboolean( L, s ) )
3846
lua_pushstring( L, "setItalics: wrong argument type" );
3852
b = lua_toboolean( L, s );
3855
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
3856
QString windowName(luaWindowName.c_str());
3857
if( windowName.size() > 0 )
3858
mudlet::self()->setItalics( pHost, windowName, b );
3860
pHost->mpConsole->setItalics( b );
3863
int TLuaInterpreter::setUnderline( lua_State *L )
3865
string luaWindowName;
3868
if( lua_gettop( L ) > 1 )
3870
if( ! lua_isstring( L, s ) )
3872
lua_pushstring( L, "setUnderline: wrong argument type" );
3878
luaWindowName = lua_tostring( L, s );
3882
if( ! lua_isboolean( L, s ) )
3884
lua_pushstring( L, "setUnderline: wrong argument type" );
3890
b = lua_toboolean( L, s );
3893
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
3894
QString windowName(luaWindowName.c_str());
3895
if( windowName.size() > 0 )
3896
mudlet::self()->setUnderline( pHost, windowName, b );
3898
pHost->mpConsole->setUnderline( b );
3902
int TLuaInterpreter::debug( lua_State *L )
3904
int nbargs = lua_gettop(L);
3905
QString luaDebugText="";
3906
for (int i=0; i<nbargs; i++)
3908
luaDebugText += (nbargs > 1 ? " [" + QString::number(i) + "] " : " ") + lua_tostring( L, i+1 );
3913
int TLuaInterpreter::hideToolBar( lua_State *L )
3915
string luaWindowName;
3916
if( ! lua_isstring( L, 1 ) )
3918
lua_pushstring( L, "hideToolBar: wrong argument type" );
3924
luaWindowName = lua_tostring( L, 1 );
3927
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
3928
QString windowName(luaWindowName.c_str());
3929
pHost->getActionUnit()->hideToolBar( windowName );
3933
int TLuaInterpreter::showToolBar( lua_State *L )
3935
string luaWindowName;
3936
if( ! lua_isstring( L, 1 ) )
3938
lua_pushstring( L, "showToolBar: wrong argument type" );
3944
luaWindowName = lua_tostring( L, 1 );
3947
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
3948
QString windowName(luaWindowName.c_str());
3949
pHost->getActionUnit()->showToolBar( windowName );
3953
int TLuaInterpreter::sendATCP( lua_State *L )
3956
if( ! lua_isstring( L, 1 ) )
3958
lua_pushstring( L, "sendATCP: what do you want to send?" );
3964
msg = lua_tostring( L, 1 );
3968
if( ! lua_isstring( L, 2 ) )
3970
lua_pushstring( L, "sendATCP: wrong argument type" );
3976
what = lua_tostring( L, 2 );
3990
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
3991
pHost->mTelnet.socketOutRaw( _h );
3995
int TLuaInterpreter::sendGMCP( lua_State *L )
3998
if( ! lua_isstring( L, 1 ) )
4000
lua_pushstring( L, "sendGMCP: what do you want to send?" );
4006
msg = lua_tostring( L, 1 );
4010
if( lua_isstring( L, 2 ) )
4012
what = lua_tostring( L, 2 );
4027
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
4028
pHost->mTelnet.socketOutRaw( _h );
4032
int TLuaInterpreter::sendTelnetChannel102( lua_State *L )
4035
if( ! lua_isstring( L, 1 ) )
4037
lua_pushstring( L, "sendTelnetChannel102: wrong argument type" );
4043
msg = lua_tostring( L, 1 );
4053
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
4054
pHost->mTelnet.socketOutRaw( _h );
4058
int TLuaInterpreter::getButtonState( lua_State *L )
4060
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
4062
state = pHost->mpConsole->getButtonState();
4063
lua_pushnumber( L, state );
4067
int TLuaInterpreter::getNetworkLatency( lua_State *L )
4069
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
4071
number = pHost->mTelnet.networkLatency;
4072
lua_pushnumber( L, number );
4076
int TLuaInterpreter::getMainConsoleWidth( lua_State * L )
4078
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
4079
int fw = QFontMetrics(pHost->mDisplayFont).width("W");
4080
fw *= pHost->mWrapAt + 1;
4081
lua_pushnumber( L, fw );
4085
int TLuaInterpreter::getMainWindowSize( lua_State *L )
4087
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
4088
QSize size = pHost->mpConsole->mpMainFrame->size();
4089
lua_pushnumber( L, size.width() );
4090
lua_pushnumber( L, size.height()-pHost->mpConsole->mpCommandLine->height() );
4094
// tempTimer(int session, float seconds, string function to call, string name) // one shot timer.
4095
int TLuaInterpreter::tempTimer( lua_State *L )
4098
if( ! lua_isnumber( L, 1 ) )
4100
lua_pushstring( L, "tempTimer: wrong argument type" );
4106
luaTimeout = lua_tonumber( L, 1 );
4110
if( lua_isfunction( L, 2 ) )
4112
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
4113
TLuaInterpreter * pLuaInterpreter = pHost->getLuaInterpreter();
4115
int timerID = pLuaInterpreter->startTempTimer( luaTimeout, _fun );
4116
TTimer * pT = pHost->getTimerUnit()->getTimer( timerID );
4117
pT->mRegisteredAnonymousLuaFunction = true;
4118
lua_pushlightuserdata( L, pT );
4119
lua_pushvalue( L, 2 );
4120
lua_settable( L, LUA_REGISTRYINDEX );
4121
lua_pushnumber( L, timerID );
4124
if( ! lua_isstring( L, 2 ) )
4126
lua_pushstring( L, "tempTimer: wrong argument type" );
4132
luaFunction = lua_tostring( L, 2 );
4135
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
4136
TLuaInterpreter * pLuaInterpreter = pHost->getLuaInterpreter();
4137
QString _fun = luaFunction.c_str();
4138
int timerID = pLuaInterpreter->startTempTimer( luaTimeout, _fun );
4139
lua_pushnumber( L, timerID );
4143
int TLuaInterpreter::tempExactMatchTrigger( lua_State *L )
4146
if( ! lua_isstring( L, 1 ) )
4148
lua_pushstring( L, "tempTrigger: wrong argument type" );
4154
luaRegex = lua_tostring( L, 1 );
4158
if( ! lua_isstring( L, 2 ) )
4160
lua_pushstring( L, "tempTrigger: wrong argument type" );
4166
luaFunction = lua_tostring( L, 2 );
4169
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
4170
TLuaInterpreter * pLuaInterpreter = pHost->getLuaInterpreter();
4171
QString _reg = luaRegex.c_str();
4172
QString _fun = luaFunction.c_str();
4173
int timerID = pLuaInterpreter->startTempExactMatchTrigger( _reg, _fun );
4174
lua_pushnumber( L, timerID );
4178
int TLuaInterpreter::tempBeginOfLineTrigger( lua_State *L )
4181
if( ! lua_isstring( L, 1 ) )
4183
lua_pushstring( L, "tempTrigger: wrong argument type" );
4189
luaRegex = lua_tostring( L, 1 );
4193
if( ! lua_isstring( L, 2 ) )
4195
lua_pushstring( L, "tempTrigger: wrong argument type" );
4201
luaFunction = lua_tostring( L, 2 );
4204
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
4205
TLuaInterpreter * pLuaInterpreter = pHost->getLuaInterpreter();
4206
QString _reg = luaRegex.c_str();
4207
QString _fun = luaFunction.c_str();
4208
int timerID = pLuaInterpreter->startTempBeginOfLineTrigger( _reg, _fun );
4209
lua_pushnumber( L, timerID );
4214
// tempTrigger( string regex, string function to call ) // one shot timer.
4215
int TLuaInterpreter::tempTrigger( lua_State *L )
4218
if( ! lua_isstring( L, 1 ) )
4220
lua_pushstring( L, "tempTrigger: wrong argument type" );
4226
luaRegex = lua_tostring( L, 1 );
4230
if( ! lua_isstring( L, 2 ) )
4232
lua_pushstring( L, "tempTrigger: wrong argument type" );
4238
luaFunction = lua_tostring( L, 2 );
4241
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
4242
TLuaInterpreter * pLuaInterpreter = pHost->getLuaInterpreter();
4243
QString _reg = luaRegex.c_str();
4244
QString _fun = luaFunction.c_str();
4245
int timerID = pLuaInterpreter->startTempTrigger( _reg, _fun );
4246
lua_pushnumber( L, timerID );
4251
// temporary color trigger. args: ansiFGColorCode, ansiBgColorCode, luaCode
4252
int TLuaInterpreter::tempColorTrigger( lua_State *L )
4255
if( ! lua_isnumber( L, 1 ) )
4257
lua_pushstring( L, "tempColorTrigger: wrong argument type" );
4263
luaFrom = lua_tointeger( L, 1 );
4266
if( ! lua_isnumber( L, 2 ) )
4268
lua_pushstring( L, "tempColorTrigger: wrong argument type" );
4274
luaTo = lua_tointeger( L, 2 );
4278
if( ! lua_isstring( L, 3 ) )
4280
lua_pushstring( L, "tempColorTrigger: wrong argument type" );
4286
luaFunction = lua_tostring( L, 3 );
4289
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
4290
TLuaInterpreter * pLuaInterpreter = pHost->getLuaInterpreter();
4291
QString _fun = luaFunction.c_str();
4292
int timerID = pLuaInterpreter->startTempColorTrigger( luaFrom, luaTo, _fun );
4293
lua_pushnumber( L, timerID );
4298
// triggerID = tempLineTrigger( from, howmany, func )
4299
int TLuaInterpreter::tempLineTrigger( lua_State *L )
4302
if( ! lua_isnumber( L, 1 ) )
4304
lua_pushstring( L, "tempLineTrigger: wrong argument type" );
4310
luaFrom = lua_tointeger( L, 1 );
4313
if( ! lua_isnumber( L, 2 ) )
4315
lua_pushstring( L, "tempLineTrigger: wrong argument type" );
4321
luaTo = lua_tointeger( L, 2 );
4325
if( ! lua_isstring( L, 3 ) )
4327
lua_pushstring( L, "tempLineTrigger: wrong argument type" );
4333
luaFunction = lua_tostring( L, 3 );
4336
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
4337
TLuaInterpreter * pLuaInterpreter = pHost->getLuaInterpreter();
4338
QString _fun = luaFunction.c_str();
4339
int timerID = pLuaInterpreter->startTempLineTrigger( luaFrom, luaTo, _fun );
4340
lua_pushnumber( L, timerID );
4345
// tempTrigger( string regex, string function to call ) // one shot timer.
4346
int TLuaInterpreter::tempRegexTrigger( lua_State *L )
4349
if( ! lua_isstring( L, 1 ) )
4351
lua_pushstring( L, "tempRegexTrigger: wrong argument type" );
4357
luaRegex = lua_tostring( L, 1 );
4361
if( ! lua_isstring( L, 2 ) )
4363
lua_pushstring( L, "tempRegexTrigger: wrong argument type" );
4369
luaFunction = lua_tostring( L, 2 );
4372
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
4373
TLuaInterpreter * pLuaInterpreter = pHost->getLuaInterpreter();
4374
QString _luaFunction = luaFunction.c_str();
4375
QString _luaRegex = luaRegex.c_str();
4376
int timerID = pLuaInterpreter->startTempRegexTrigger( _luaRegex, _luaFunction );
4377
lua_pushnumber( L, timerID );
4381
int TLuaInterpreter::tempAlias( lua_State *L )
4384
if( ! lua_isstring( L, 1 ) )
4386
lua_pushstring( L, "tempAlias: wrong argument type" );
4392
luaRegex = lua_tostring( L, 1 );
4396
if( ! lua_isstring( L, 2 ) )
4398
lua_pushstring( L, "tempAlias: wrong argument type" );
4404
luaFunction = lua_tostring( L, 2 );
4407
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
4408
TLuaInterpreter * pLuaInterpreter = pHost->getLuaInterpreter();
4409
QString _luaFunction = luaFunction.c_str();
4410
QString _luaRegex = luaRegex.c_str();
4411
int timerID = pLuaInterpreter->startTempAlias( _luaRegex, _luaFunction );
4412
lua_pushnumber( L, timerID );
4416
int TLuaInterpreter::exists( lua_State * L )
4419
if( ! lua_isstring( L, 1 ) )
4421
lua_pushstring( L, "exists: wrong argument type" );
4427
_name = lua_tostring( L, 1 );
4430
if( ! lua_isstring( L, 2 ) )
4432
lua_pushstring( L, "exists: wrong argument type" );
4438
_type = lua_tostring( L, 2 );
4440
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
4442
QString type = _type.c_str();
4443
type = type.toLower();
4444
QString name = _name.c_str();
4445
if( type == "timer")
4447
QMap<QString, TTimer *>::const_iterator it1 = pHost->getTimerUnit()->mLookupTable.find( name );
4448
while( it1 != pHost->getTimerUnit()->mLookupTable.end() && it1.key() == name )
4454
else if( type == "trigger")
4456
QMap<QString, TTrigger *>::const_iterator it1 = pHost->getTriggerUnit()->mLookupTable.find( name );
4457
while( it1 != pHost->getTriggerUnit()->mLookupTable.end() && it1.key() == name )
4463
else if( type == "alias")
4465
QMap<QString, TAlias *>::const_iterator it1 = pHost->getAliasUnit()->mLookupTable.find( name );
4466
while( it1 != pHost->getAliasUnit()->mLookupTable.end() && it1.key() == name )
4472
lua_pushnumber( L, cnt );
4476
int TLuaInterpreter::isActive( lua_State * L )
4479
if( ! lua_isstring( L, 1 ) )
4481
lua_pushstring( L, "isActive: wrong argument type" );
4487
_name = lua_tostring( L, 1 );
4490
if( ! lua_isstring( L, 2 ) )
4492
lua_pushstring( L, "isActive: wrong argument type" );
4498
_type = lua_tostring( L, 2 );
4500
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
4502
QString type = _type.c_str();
4503
type = type.toLower();
4504
QString name = _name.c_str();
4505
if( type == "timer")
4507
QMap<QString, TTimer *>::const_iterator it1 = pHost->getTimerUnit()->mLookupTable.find( name );
4508
while( it1 != pHost->getTimerUnit()->mLookupTable.end() && it1.key() == name )
4510
if( it1.value()->isActive() )
4517
else if( type == "trigger")
4519
QMap<QString, TTrigger *>::const_iterator it1 = pHost->getTriggerUnit()->mLookupTable.find( name );
4520
while( it1 != pHost->getTriggerUnit()->mLookupTable.end() && it1.key() == name )
4522
if( it1.value()->isActive() )
4529
else if( type == "alias")
4531
QMap<QString, TAlias *>::const_iterator it1 = pHost->getAliasUnit()->mLookupTable.find( name );
4532
while( it1 != pHost->getAliasUnit()->mLookupTable.end() && it1.key() == name )
4534
if( it1.value()->isActive() )
4541
lua_pushnumber( L, cnt );
4546
int TLuaInterpreter::permAlias( lua_State *L )
4549
if( ! lua_isstring( L, 1 ) )
4551
lua_pushstring( L, "permAlias: need a name for this alias" );
4557
luaName = lua_tostring( L, 1 );
4561
if( ! lua_isstring( L, 2 ) )
4563
lua_pushstring( L, "permAlias: need a parent alias/group to add this alias to" );
4569
luaParent = lua_tostring( L, 2 );
4573
if( ! lua_isstring( L, 3 ) )
4575
lua_pushstring( L, "permAlias: need the pattern for the alias" );
4581
luaRegex = lua_tostring( L, 3 );
4586
if( ! lua_isstring( L, 4 ) )
4588
lua_pushstring( L, "permAlias: need Lua code for this alias" );
4594
luaFunction = lua_tostring( L, 4 );
4597
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
4598
TLuaInterpreter * pLuaInterpreter = pHost->getLuaInterpreter();
4599
QString _luaName = luaName.c_str();
4600
QString _luaParent = luaParent.c_str();
4601
QString _luaFunction = luaFunction.c_str();
4602
QString _luaRegex = luaRegex.c_str();
4603
int aliasID = pLuaInterpreter->startPermAlias( _luaName, _luaParent, _luaRegex, _luaFunction );
4604
lua_pushnumber( L, aliasID );
4608
int TLuaInterpreter::permTimer( lua_State * L )
4611
if( ! lua_isstring( L, 1 ) )
4613
lua_pushstring( L, "permTimer: wrong argument type" );
4619
luaName = lua_tostring( L, 1 );
4622
if( ! lua_isstring( L, 2 ) )
4624
lua_pushstring( L, "permTimer: wrong argument type" );
4630
luaParent = lua_tostring( L, 2 );
4634
if( ! lua_isnumber( L, 3 ) )
4636
lua_pushstring( L, "permTimer: wrong argument type" );
4642
luaTimeout = lua_tonumber( L, 3 );
4646
if( ! lua_isstring( L, 4 ) )
4648
lua_pushstring( L, "permTimer: wrong argument type" );
4654
luaFunction = lua_tostring( L, 4 );
4657
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
4658
TLuaInterpreter * pLuaInterpreter = pHost->getLuaInterpreter();
4659
QString _name = luaName.c_str();
4660
QString _parent = luaParent.c_str();
4661
QString _fun = luaFunction.c_str();
4662
int timerID = pLuaInterpreter->startPermTimer( _name, _parent, luaTimeout, _fun );
4663
lua_pushnumber( L, timerID );
4667
int TLuaInterpreter::permSubstringTrigger( lua_State * L )
4670
if( ! lua_isstring( L, 1 ) )
4672
lua_pushstring( L, "permSubstringTrigger: wrong argument type" );
4678
name = lua_tostring( L, 1 );
4682
if( ! lua_isstring( L, 2 ) )
4684
lua_pushstring( L, "permSubstringTrigger: wrong argument type" );
4690
parent = lua_tostring( L, 2 );
4692
QStringList _regList;
4693
if( ! lua_istable( L, 3 ) )
4695
lua_pushstring( L, "permSubstringTrigger: wrong argument type" );
4702
while( lua_next( L, 3 ) != 0 )
4704
// key at index -2 and value at index -1
4705
if( lua_type(L, -1) == LUA_TSTRING )
4707
QString regex = lua_tostring( L, -1 );
4710
// removes value, but keeps key for next iteration
4716
if( ! lua_isstring( L, 4 ) )
4718
lua_pushstring( L, "permSubstringTrigger: wrong argument type" );
4724
luaFunction = lua_tostring( L, 4 );
4727
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
4728
TLuaInterpreter * pLuaInterpreter = pHost->getLuaInterpreter();
4729
QString _name = name.c_str();
4730
QString _parent = parent.c_str();
4731
QString _luaFunction = luaFunction.c_str();
4732
int ret = pLuaInterpreter->startPermSubstringTrigger( _name,
4736
lua_pushnumber( L, ret );
4740
int TLuaInterpreter::permBeginOfLineStringTrigger( lua_State * L )
4743
if( ! lua_isstring( L, 1 ) )
4745
lua_pushstring( L, "permBeginOfLineStringTrigger: wrong argument type" );
4751
name = lua_tostring( L, 1 );
4755
if( ! lua_isstring( L, 2 ) )
4757
lua_pushstring( L, "permBeginOfLineStringTrigger: wrong argument type" );
4763
parent = lua_tostring( L, 2 );
4765
QStringList _regList;
4766
if( ! lua_istable( L, 3 ) )
4768
lua_pushstring( L, "permBeginOfLineStringTrigger: wrong argument type" );
4775
while( lua_next( L, 3 ) != 0 )
4777
// key at index -2 and value at index -1
4778
if( lua_type(L, -1) == LUA_TSTRING )
4780
QString regex = lua_tostring( L, -1 );
4783
// removes value, but keeps key for next iteration
4789
if( ! lua_isstring( L, 4 ) )
4791
lua_pushstring( L, "permBeginOfLineStringTrigger: wrong argument type" );
4797
luaFunction = lua_tostring( L, 4 );
4800
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
4801
TLuaInterpreter * pLuaInterpreter = pHost->getLuaInterpreter();
4802
QString _name = name.c_str();
4803
QString _parent = parent.c_str();
4804
QString _luaFunction = luaFunction.c_str();
4805
int ret = pLuaInterpreter->startPermBeginOfLineStringTrigger( _name,
4809
lua_pushnumber( L, ret );
4813
int TLuaInterpreter::permRegexTrigger( lua_State *L )
4816
if( ! lua_isstring( L, 1 ) )
4818
lua_pushstring( L, "permRegexTrigger: wrong argument type" );
4824
name = lua_tostring( L, 1 );
4828
if( ! lua_isstring( L, 2 ) )
4830
lua_pushstring( L, "permRegexTrigger: wrong argument type" );
4836
parent = lua_tostring( L, 2 );
4838
QStringList _regList;
4839
if( ! lua_istable( L, 3 ) )
4841
lua_pushstring( L, "permRegexTrigger: wrong argument type" );
4848
while( lua_next( L, 3 ) != 0 )
4850
// key at index -2 and value at index -1
4851
if( lua_type(L, -1) == LUA_TSTRING )
4853
QString regex = lua_tostring( L, -1 );
4856
// removes value, but keeps key for next iteration
4862
if( ! lua_isstring( L, 4 ) )
4864
lua_pushstring( L, "permRegexTrigger: wrong argument type" );
4870
luaFunction = lua_tostring( L, 4 );
4873
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
4874
TLuaInterpreter * pLuaInterpreter = pHost->getLuaInterpreter();
4875
QString _name = name.c_str();
4876
QString _parent = parent.c_str();
4877
QString _luaFunction = luaFunction.c_str();
4878
int ret = pLuaInterpreter->startPermRegexTrigger( _name,
4882
lua_pushnumber( L, ret );
4886
#include <QFileDialog>
4888
int TLuaInterpreter::invokeFileDialog( lua_State * L )
4890
bool luaDir = false; //default is to chose a directory
4891
if( ! lua_isboolean( L, 1 ) )
4893
lua_pushstring( L, "invokeFileDialog: wrong argument type" );
4899
luaDir = lua_toboolean( L, 1 );
4902
if( ! lua_isstring( L, 2 ) )
4904
lua_pushstring( L, "invokeFileDialog: wrong argument type" );
4910
luaTitle = lua_tostring( L, 2 );
4914
QString fileName = QFileDialog::getExistingDirectory(0, QString( luaTitle.c_str()),
4915
QDir::currentPath() );
4916
lua_pushstring( L, fileName.toLatin1().data() );
4921
QString fileName = QFileDialog::getOpenFileName(0, QString( luaTitle.c_str()),
4922
QDir::currentPath() );
4923
lua_pushstring( L, fileName.toLatin1().data() );
4928
int TLuaInterpreter::getTimestamp( lua_State * L )
4931
int args = lua_gettop( L );
4941
if( lua_isstring( L, n ) )
4943
name = lua_tostring( L, n );
4948
if( ! lua_isnumber( L, n ) )
4950
lua_pushstring( L, "getTimestamp: wrong argument type" );
4956
luaLine = lua_tointeger( L, n );
4958
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
4961
if( luaLine > 0 && luaLine < pHost->mpConsole->buffer.timeBuffer.size() )
4963
lua_pushstring( L, pHost->mpConsole->buffer.timeBuffer.at(luaLine).toLatin1().data() );
4967
lua_pushstring( L, "getTimestamp: invalid line number");
4971
QString _name = name.c_str();
4972
QMap<QString, TConsole *> & dockWindowConsoleMap = mudlet::self()->mHostConsoleMap[pHost];
4973
if( dockWindowConsoleMap.contains( _name ) )
4975
TConsole * pC = dockWindowConsoleMap[_name];
4976
if( luaLine > 0 && luaLine < pC->buffer.timeBuffer.size() )
4978
lua_pushstring( L, pC->buffer.timeBuffer.at(luaLine).toLatin1().data() );
4982
lua_pushstring( L, "getTimestamp: invalid line number");
4989
int TLuaInterpreter::setBorderColor( lua_State *L )
4994
if( ! lua_isnumber( L, 1 ) )
4996
lua_pushstring( L, "setBorderColor: wrong argument type" );
5002
luaRed = lua_tointeger( L, 1 );
5005
if( ! lua_isnumber( L, 2 ) )
5007
lua_pushstring( L, "setBorderColor: wrong argument type" );
5013
luaGreen=lua_tointeger( L, 2 );
5016
if( ! lua_isnumber( L, 3 ) )
5018
lua_pushstring( L, "setBorderColor: wrong argument type" );
5024
luaBlue = lua_tointeger( L, 3 );
5027
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
5028
QPalette framePalette;
5029
framePalette.setColor( QPalette::Text, QColor(0,0,0) );
5030
framePalette.setColor( QPalette::Highlight, QColor(55,55,255) );
5031
framePalette.setColor( QPalette::Window, QColor( luaRed, luaGreen, luaBlue, 255 ) );
5032
pHost->mpConsole->mpMainFrame->setPalette( framePalette );
5037
int TLuaInterpreter::setRoomCoordinates( lua_State *L )
5043
if( ! lua_isnumber( L, 1 ) )
5045
lua_pushstring( L, "setRoomCoordinates: wrong argument type" );
5051
id = lua_tointeger( L, 1 );
5054
if( ! lua_isnumber( L, 2 ) )
5056
lua_pushstring( L, "setRoomCoordinates: wrong argument type" );
5062
x = lua_tointeger( L, 2 );
5065
if( ! lua_isnumber( L, 3 ) )
5067
lua_pushstring( L, "setRoomCoordinates: wrong argument type" );
5073
y = lua_tointeger( L, 3 );
5076
if( ! lua_isnumber( L, 4 ) )
5078
lua_pushstring( L, "setRoomCoordinates: wrong argument type" );
5084
z = lua_tointeger( L, 4 );
5087
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
5088
lua_pushboolean(L, pHost->mpMap->setRoomCoordinates( id, x, y, z ) );
5092
int TLuaInterpreter::setCustomEnvColor( lua_State *L )
5098
if( ! lua_isnumber( L, 1 ) )
5100
lua_pushstring( L, "setRoomCoordinates: wrong argument type" );
5106
id = lua_tointeger( L, 1 );
5109
if( ! lua_isnumber( L, 2 ) )
5111
lua_pushstring( L, "setRoomCoordinates: wrong argument type" );
5117
x = lua_tointeger( L, 2 );
5120
if( ! lua_isnumber( L, 3 ) )
5122
lua_pushstring( L, "setRoomCoordinates: wrong argument type" );
5128
y = lua_tointeger( L, 3 );
5131
if( ! lua_isnumber( L, 4 ) )
5133
lua_pushstring( L, "setRoomCoordinates: wrong argument type" );
5139
z = lua_tointeger( L, 4 );
5142
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
5143
pHost->mpMap->customEnvColors[id] = QColor( x, y, z );
5148
int TLuaInterpreter::setAreaName( lua_State *L )
5152
if( ! lua_isnumber( L, 1 ) )
5154
lua_pushstring( L, "setAreaName: wrong argument type" );
5160
id = lua_tointeger( L, 1 );
5163
if( ! lua_isstring( L, 2 ) )
5165
lua_pushstring( L, "setAreaName: wrong argument type" );
5171
name = lua_tostring( L, 2 );
5174
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
5175
QString _name = name.c_str();
5176
pHost->mpMap->areaNamesMap[id] = _name;
5180
int TLuaInterpreter::getRoomAreaName( lua_State *L )
5184
bool gotString = false;
5185
if( ! lua_isnumber( L, 1 ) )
5187
if( ! lua_isstring( L, 1 ) )
5189
lua_pushstring( L, "getRoomAreaName: wrong argument type" );
5195
name = lua_tostring( L, 1 );
5201
id = lua_tonumber( L, 1 );
5204
QString _name = name.c_str();
5205
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
5208
QList<int> idList = pHost->mpMap->areaNamesMap.keys( _name );
5209
if( idList.size() > 0 )
5211
lua_pushnumber( L, idList[0] );
5216
lua_pushnumber( L, -1 );
5222
if( pHost->mpMap->areaNamesMap.contains( id ) )
5224
lua_pushstring( L, pHost->mpMap->areaNamesMap[id].toLatin1().data() );
5227
lua_pushnumber( L, -1 );
5232
int TLuaInterpreter::addAreaName( lua_State *L )
5237
if( ! lua_isstring( L, 1 ) )
5239
lua_pushstring( L, "addAreaName: wrong argument type" );
5245
name = lua_tostring( L, 1 );
5248
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
5249
QString _name = name.c_str();
5250
id = pHost->mpMap->areaNamesMap.size()+1;
5253
if( ! pHost->mpMap->areaNamesMap.values().contains( _name ) )
5255
while( pHost->mpMap->areaNamesMap.contains( id ) )
5259
pHost->mpMap->areaNamesMap[id] = _name;
5260
lua_pushnumber( L, id );
5263
lua_pushnumber( L, -1 );
5267
int TLuaInterpreter::deleteArea( lua_State *L )
5272
if( lua_isnumber( L, 1 ) )
5274
id = lua_tonumber( L, 1 );
5275
if( id == -1 ) return 0;
5277
else if( lua_isstring( L, 1 ) )
5279
name = lua_tostring( L, 1 );
5283
lua_pushstring( L, "deleteArea: wrong argument type" );
5288
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
5291
QString _name = name.c_str();
5292
if( pHost->mpMap->areaNamesMap.values().contains( _name ) )
5294
pHost->mpMap->deleteArea( id );
5295
pHost->mpMap->mMapGraphNeedsUpdate = false;
5300
if( pHost->mpMap->areas.contains( id ) )
5302
pHost->mpMap->deleteArea( id );
5303
pHost->mpMap->mMapGraphNeedsUpdate = false;
5309
int TLuaInterpreter::deleteRoom( lua_State *L )
5313
if( lua_isnumber( L, 1 ) )
5315
id = lua_tonumber( L, 1 );
5316
if( id <= 0 ) return 0;
5320
lua_pushstring( L, "addAreaName: wrong argument type" );
5325
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
5326
if( pHost->mpMap->rooms.contains( id ) )
5328
pHost->mpMap->deleteRoom( id );
5329
pHost->mpMap->mMapGraphNeedsUpdate = false;
5335
int TLuaInterpreter::setExit( lua_State *L )
5339
if( ! lua_isnumber( L, 1 ) )
5341
lua_pushstring( L, "setExit: wrong argument type" );
5347
from = lua_tointeger( L, 1 );
5350
if( ! lua_isnumber( L, 2 ) )
5352
lua_pushstring( L, "setExit: wrong argument type" );
5358
to = lua_tointeger( L, 2 );
5361
if( ! lua_isnumber( L, 3 ) )
5363
lua_pushstring( L, "setExit: wrong argument type" );
5369
dir = lua_tointeger( L, 3 );
5372
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
5373
lua_pushboolean(L, pHost->mpMap->setExit( from, to, dir ) );
5374
pHost->mpMap->mMapGraphNeedsUpdate = true;
5378
int TLuaInterpreter::getRoomCoordinates( lua_State * L )
5381
if( ! lua_isnumber( L, 1 ) )
5383
lua_pushstring( L, "getRoomCoordinates: wrong argument type" );
5389
id = lua_tointeger( L, 1 );
5392
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
5393
if( ! pHost->mpMap->rooms.contains( id ) )
5395
lua_pushstring( L, "getRoomCoordinates: room ID does not exist");
5399
lua_pushnumber( L, pHost->mpMap->rooms[id]->x );
5400
lua_pushnumber( L, pHost->mpMap->rooms[id]->y );
5401
lua_pushnumber( L, pHost->mpMap->rooms[id]->z );
5405
int TLuaInterpreter::getRoomArea( lua_State * L )
5408
if( ! lua_isnumber( L, 1 ) )
5410
lua_pushstring( L, "getRoomArea: wrong argument type" );
5416
id = lua_tointeger( L, 1 );
5419
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
5420
if( ! pHost->mpMap->rooms.contains( id ) )
5425
lua_pushnumber( L, pHost->mpMap->rooms[id]->area );
5430
int TLuaInterpreter::roomExists( lua_State * L )
5433
if( ! lua_isnumber( L, 1 ) || ! lua_isstring( L, 1 ) )
5435
lua_pushstring( L, "roomExists: wrong argument type" );
5441
id = lua_tointeger( L, 1 );
5444
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
5445
if( pHost->mpMap->rooms.contains( id ) )
5447
lua_pushboolean( L, 1 );
5450
lua_pushboolean( L, 0 );
5454
int TLuaInterpreter::addRoom( lua_State * L )
5457
if( ! lua_isnumber( L, 1 ) )
5459
lua_pushstring( L, "getRoomArea: wrong argument type" );
5465
id = lua_tointeger( L, 1 );
5468
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
5469
lua_pushboolean( L, pHost->mpMap->addRoom( id ) );
5470
pHost->mpMap->mMapGraphNeedsUpdate = true;
5475
int TLuaInterpreter::createRoomID( lua_State * L )
5477
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
5478
lua_pushnumber( L, pHost->mpMap->createNewRoomID() );
5482
int TLuaInterpreter::unHighlightRoom( lua_State * L )
5485
if( ! lua_isnumber( L, 1 ) )
5487
lua_pushstring( L, "highlightRoom: wrong argument type" );
5493
id = lua_tointeger( L, 1 );
5495
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
5496
if( ! pHost->mpMap->rooms.contains( id ) ) return 0;
5497
pHost->mpMap->rooms[id]->highlight = false;
5499
if( pHost->mpMap->mpMapper )
5500
pHost->mpMap->mpMapper->mp2dMap->update();
5504
// highlightRoom( roomID, colorRed, colorGreen, colorBlue, col2Red, col2Green, col2Blue, (float)highlightRadius, alphaColor1, alphaColor2 )
5506
int TLuaInterpreter::highlightRoom( lua_State * L )
5508
int id, fgr, fgg, fgb, bgr, bgg, bgb;
5510
if( ! lua_isnumber( L, 1 ) )
5512
lua_pushstring( L, "highlightRoom: wrong argument type" );
5518
id = lua_tointeger( L, 1 );
5521
if( ! lua_isnumber( L, 2 ) )
5523
lua_pushstring( L, "highlightRoom: wrong argument type" );
5529
fgr = lua_tointeger( L, 2 );
5532
if( ! lua_isnumber( L, 3 ) )
5534
lua_pushstring( L, "highlightRoom: wrong argument type" );
5540
fgg = lua_tointeger( L, 3 );
5543
if( ! lua_isnumber( L, 4 ) )
5545
lua_pushstring( L, "highlightRoom: wrong argument type" );
5551
fgb = lua_tointeger( L, 4 );
5553
if( ! lua_isnumber( L, 5 ) )
5555
lua_pushstring( L, "highlightRoom: wrong argument type" );
5561
bgr = lua_tointeger( L, 5 );
5564
if( ! lua_isnumber( L, 6 ) )
5566
lua_pushstring( L, "highlightRoom: wrong argument type" );
5572
bgg = lua_tointeger( L, 6 );
5575
if( ! lua_isnumber( L, 7 ) )
5577
lua_pushstring( L, "highlightRoom: wrong argument type" );
5583
bgb = lua_tointeger( L, 7 );
5585
if( ! lua_isnumber( L, 8 ) )
5587
lua_pushstring( L, "highlightRoom: wrong argument type" );
5593
radius = lua_tonumber( L, 8 );
5596
if( ! lua_isnumber( L, 9 ) )
5598
lua_pushstring( L, "highlightRoom: wrong argument type" );
5604
alpha1 = lua_tointeger( L, 9 );
5606
if( ! lua_isnumber( L, 10 ) )
5608
lua_pushstring( L, "highlightRoom: wrong argument type" );
5614
alpha2 = lua_tointeger( L, 10 );
5617
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
5618
if( !pHost->mpMap ) return 0;
5619
if( ! pHost->mpMap->rooms.contains( id ) ) return 0;
5620
QColor fg = QColor(fgr,fgg,fgb,alpha1);
5621
QColor bg = QColor(bgr,bgg,bgb,alpha2);
5622
pHost->mpMap->rooms[id]->highlight = true;
5623
pHost->mpMap->rooms[id]->highlightColor = fg;
5624
pHost->mpMap->rooms[id]->highlightColor2 = bg;
5625
pHost->mpMap->rooms[id]->highlightRadius = radius;
5627
if( pHost->mpMap->mpMapper )
5628
if( pHost->mpMap->mpMapper->mp2dMap )
5629
pHost->mpMap->mpMapper->mp2dMap->update();
5634
// labelID = createMapLabel( area, text, posx, posy, fgRed, fgGreen, fgBlue, bgRed, bgGreen, bgBlue )
5635
int TLuaInterpreter::createMapLabel( lua_State * L )
5637
int area, fgr, fgg, fgb, bgr, bgg, bgb;
5640
if( ! lua_isnumber( L, 1 ) )
5642
lua_pushstring( L, "createMapLabel: wrong argument type" );
5648
area = lua_tointeger( L, 1 );
5651
if( ! lua_isstring( L, 2 ) )
5653
lua_pushstring( L, "createMapLabel: wrong argument type" );
5659
text = lua_tostring( L, 2 );
5662
if( ! lua_isnumber( L, 3 ) )
5664
lua_pushstring( L, "createMapLabel: wrong argument type" );
5670
posx = lua_tonumber( L, 3 );
5673
if( ! lua_isnumber( L, 4 ) )
5675
lua_pushstring( L, "createMapLabel: wrong argument type" );
5681
posy = lua_tonumber( L, 4 );
5684
if( ! lua_isnumber( L, 5 ) )
5686
lua_pushstring( L, "createMapLabel: wrong argument type" );
5692
fgr = lua_tointeger( L, 5 );
5695
if( ! lua_isnumber( L, 6 ) )
5697
lua_pushstring( L, "createMapLabel: wrong argument type" );
5703
fgg = lua_tointeger( L, 6 );
5706
if( ! lua_isnumber( L, 7 ) )
5708
lua_pushstring( L, "createMapLabel: wrong argument type" );
5714
fgb = lua_tointeger( L, 7 );
5717
if( ! lua_isnumber( L, 8 ) )
5719
lua_pushstring( L, "createMapLabel: wrong argument type" );
5725
bgr = lua_tointeger( L, 8 );
5728
if( ! lua_isnumber( L, 9 ) )
5730
lua_pushstring( L, "createMapLabel: wrong argument type" );
5736
bgg = lua_tointeger( L, 9 );
5739
if( ! lua_isnumber( L, 10 ) )
5741
lua_pushstring( L, "createMapLabel: wrong argument type" );
5747
bgb = lua_tointeger( L, 10 );
5750
QString _text = text.c_str();
5751
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
5752
QColor fg = QColor(fgr,fgg,fgb);
5753
QColor bg = QColor(bgr, bgg, bgb);
5754
lua_pushinteger( L, pHost->mpMap->createMapLabel( area, _text, posx, posy, fg, bg ) );
5758
int TLuaInterpreter::deleteMapLabel( lua_State * L )
5761
if( ! lua_isnumber( L, 1 ) )
5763
lua_pushstring( L, "deleteMapLabel: wrong argument type" );
5769
area = lua_tointeger( L, 1 );
5771
if( ! lua_isnumber( L, 2 ) )
5773
lua_pushstring( L, "deleteMapLabel: wrong argument type" );
5779
labelID = lua_tointeger( L, 2 );
5781
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
5782
pHost->mpMap->deleteMapLabel( area, labelID );
5786
int TLuaInterpreter::getMapLabels( lua_State * L )
5789
if( ! lua_isnumber( L, 1 ) )
5791
lua_pushstring( L, "deleteMapLabel: wrong argument type" );
5797
area = lua_tointeger( L, 1 );
5799
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
5800
if( pHost->mpMap->mapLabels.contains( area ) )
5803
QMapIterator<int,TMapLabel> it(pHost->mpMap->mapLabels[area]);
5804
while( it.hasNext() )
5807
lua_pushnumber( L, it.key() );
5808
lua_pushstring( L, it.value().text.toLatin1().data() );
5809
lua_settable(L, -3);
5815
int TLuaInterpreter::addSpecialExit( lua_State * L )
5819
if( ! lua_isnumber( L, 1 ) )
5821
lua_pushstring( L, "addSpecialExit: wrong argument type" );
5827
id_from = lua_tointeger( L, 1 );
5829
if( ! lua_isnumber( L, 2 ) )
5831
lua_pushstring( L, "addSpecialExit: wrong argument type" );
5837
id_to = lua_tointeger( L, 2 );
5839
if( ! lua_isstring( L, 3 ) )
5841
lua_pushstring( L, "addSpecialExit: wrong argument type" );
5847
dir = lua_tostring( L, 3 );
5849
QString _dir = dir.c_str();
5850
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
5851
if( pHost->mpMap->rooms.contains( id_from ) )
5853
if( pHost->mpMap->rooms.contains( id_to ) )
5855
pHost->mpMap->rooms[id_from]->addSpecialExit( id_to, _dir );
5856
pHost->mpMap->mMapGraphNeedsUpdate = true;
5862
int TLuaInterpreter::clearRoomUserData( lua_State * L )
5865
if( ! lua_isnumber( L, 1 ) )
5867
lua_pushstring( L, "clearRoomUserData: wrong argument type" );
5873
id_from = lua_tointeger( L, 1 );
5875
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
5876
if( pHost->mpMap->rooms.contains( id_from ) )
5878
pHost->mpMap->rooms[id_from]->userData.clear();
5883
int TLuaInterpreter::clearSpecialExits( lua_State * L )
5886
if( ! lua_isnumber( L, 1 ) )
5888
lua_pushstring( L, "clearSpecialExits: wrong argument type" );
5894
id_from = lua_tointeger( L, 1 );
5896
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
5897
if( pHost->mpMap->rooms.contains( id_from ) )
5899
pHost->mpMap->rooms[id_from]->other.clear();
5900
pHost->mpMap->mMapGraphNeedsUpdate = true;
5905
int TLuaInterpreter::getSpecialExits( lua_State * L )
5908
if( ! lua_isnumber( L, 1 ) )
5910
lua_pushstring( L, "getSpecialExits: wrong argument type" );
5916
id_from = lua_tointeger( L, 1 );
5918
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
5919
if( pHost->mpMap->rooms.contains( id_from ) )
5921
QMapIterator<int, QString> it(pHost->mpMap->rooms[id_from]->other);
5923
while( it.hasNext() )
5926
int id_to = it.key();
5927
QString dir = it.value();
5928
lua_pushnumber( L, id_to );
5929
lua_pushstring( L, dir.toLatin1().data() );
5930
lua_settable(L, -3);
5937
int TLuaInterpreter::getSpecialExitsSwap( lua_State * L )
5940
if( ! lua_isnumber( L, 1 ) )
5942
lua_pushstring( L, "getSpecialExitsSwap: wrong argument type" );
5948
id_from = lua_tointeger( L, 1 );
5950
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
5951
if( pHost->mpMap->rooms.contains( id_from ) )
5953
QMapIterator<int, QString> it(pHost->mpMap->rooms[id_from]->other);
5955
while( it.hasNext() )
5958
int id_to = it.key();
5959
QString dir = it.value();
5960
lua_pushstring( L, dir.toLatin1().data() );
5961
lua_pushnumber( L, id_to );
5962
lua_settable(L, -3);
5969
int TLuaInterpreter::getRoomEnv( lua_State * L )
5972
if( ! lua_isnumber( L, 1 ) )
5974
lua_pushstring( L, "getRoomEnv: wrong argument type" );
5980
roomID = lua_tointeger( L, 1 );
5983
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
5984
if( pHost->mpMap->rooms.contains( roomID ) )
5986
lua_pushnumber( L, pHost->mpMap->rooms[roomID]->environment );
5992
int TLuaInterpreter::getRoomUserData( lua_State * L )
5995
if( ! lua_isnumber( L, 1 ) )
5997
lua_pushstring( L, "getRoomUserData: wrong argument type" );
6003
roomID = lua_tointeger( L, 1 );
6006
if( ! lua_isstring( L, 2 ) )
6008
lua_pushstring( L, "getRoomUserData: wrong argument type" );
6014
key = lua_tostring( L, 2 );
6016
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
6017
if( pHost->mpMap->rooms.contains( roomID ) )
6019
QString _key = key.c_str();
6020
if( pHost->mpMap->rooms[roomID]->userData.contains( _key ) )
6022
lua_pushstring( L, pHost->mpMap->rooms[roomID]->userData[_key].toLatin1().data() );
6027
lua_pushstring( L, "" );
6033
lua_pushstring( L, "" );
6038
int TLuaInterpreter::setRoomUserData( lua_State * L )
6041
if( ! lua_isnumber( L, 1 ) )
6043
lua_pushstring( L, "getRoomUserData: wrong argument type" );
6049
roomID = lua_tointeger( L, 1 );
6052
if( ! lua_isstring( L, 2 ) )
6054
lua_pushstring( L, "getRoomUserData: wrong argument type" );
6060
key = lua_tostring( L, 2 );
6063
if( ! lua_isstring( L, 3 ) )
6065
lua_pushstring( L, "getRoomUserData: wrong argument type" );
6071
value = lua_tostring( L, 3 );
6073
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
6074
if( pHost->mpMap->rooms.contains( roomID ) )
6076
QString _key = key.c_str();
6077
QString _value = value.c_str();
6078
pHost->mpMap->rooms[roomID]->userData[_key] = _value;
6079
lua_pushboolean( L, true );
6084
lua_pushboolean( L, false );
6091
int TLuaInterpreter::downloadFile( lua_State * L )
6094
if( ! lua_isstring( L, 1 ) )
6096
lua_pushstring( L, "downloadFile: wrong argument type" );
6102
path = lua_tostring( L, 1 );
6104
if( ! lua_isstring( L, 2 ) )
6106
lua_pushstring( L, "downloadFile: wrong argument type" );
6112
url = lua_tostring( L, 2 );
6114
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
6115
QString _url = url.c_str();
6116
QString _path = path.c_str();
6118
QNetworkReply * reply = pHost->mLuaInterpreter.mpFileDownloader->get( QNetworkRequest( QUrl( _url ) ) );
6119
pHost->mLuaInterpreter.downloadMap[reply] = _path;
6125
int TLuaInterpreter::setRoomArea( lua_State * L )
6128
if( ! lua_isnumber( L, 1 ) )
6130
lua_pushstring( L, "setRoomArea: wrong argument type" );
6136
id = lua_tointeger( L, 1 );
6138
if( ! lua_isnumber( L, 2 ) )
6140
lua_pushstring( L, "setRoomArea: wrong argument type" );
6146
area = lua_tointeger( L, 2 );
6148
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
6150
pHost->mpMap->setRoomArea( id, area );
6154
int TLuaInterpreter::setRoomChar( lua_State * L )
6158
if( ! lua_isnumber( L, 1 ) )
6160
lua_pushstring( L, "setRoomArea: wrong argument type" );
6166
id = lua_tointeger( L, 1 );
6168
if( ! lua_isstring( L, 2 ) )
6170
lua_pushstring( L, "setRoomArea: wrong argument type" );
6176
c = lua_tostring( L, 2 );
6178
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
6179
if( ! pHost->mpMap->rooms.contains( id ) )
6181
lua_pushstring( L, "setRoomArea: room ID does not exist");
6189
pHost->mpMap->rooms[id]->c = c[0];
6196
int TLuaInterpreter::getRoomsByPosition( lua_State * L )
6199
if( ! lua_isnumber( L, 1 ) )
6201
lua_pushstring( L, "getRoomsByPosition: wrong argument type" );
6207
area = lua_tointeger( L, 1 );
6209
if( ! lua_isnumber( L, 2 ) )
6211
lua_pushstring( L, "getRoomsByPosition: wrong argument type" );
6217
x = lua_tointeger( L, 2 );
6219
if( ! lua_isnumber( L, 3 ) )
6221
lua_pushstring( L, "getRoomsByPosition: wrong argument type" );
6227
y = lua_tointeger( L, 3 );
6229
if( ! lua_isnumber( L, 4 ) )
6231
lua_pushstring( L, "getRoomsByPosition: wrong argument type" );
6237
z = lua_tointeger( L, 4 );
6241
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
6242
if( ! pHost->mpMap->areas.contains( area ) )
6247
QList<int> rL = pHost->mpMap->areas[area]->getRoomsByPosition( x, y, z);
6249
for( int i=0; i<rL.size(); i++ )
6251
lua_pushnumber( L, i );
6252
lua_pushnumber( L, rL[i] );
6253
lua_settable(L, -3);
6259
// returns true if area exits, otherwise false
6260
int TLuaInterpreter::setGridMode( lua_State * L )
6263
bool gridMode = false;
6264
if( ! lua_isnumber( L, 1 ) )
6266
lua_pushstring( L, "setRoomArea: wrong argument type" );
6272
area = lua_tointeger( L, 1 );
6274
if( ! lua_isboolean( L, 2 ) )
6276
lua_pushstring( L, "setRoomArea: wrong argument type" );
6282
gridMode = lua_toboolean( L, 2 );
6285
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
6286
if( ! pHost->mpMap->areas.contains( area ) )
6288
lua_pushboolean( L, false);
6293
pHost->mpMap->areas[area]->gridMode = gridMode;
6295
lua_pushboolean( L, true );
6301
int TLuaInterpreter::setFgColor( lua_State *L )
6304
int n = lua_gettop( L );
6311
if( lua_isstring( L, s ) )
6313
a1 = lua_tostring( L, s );
6317
if( ! lua_isnumber( L, s ) )
6319
lua_pushstring( L, "setFgColor: wrong argument type" );
6325
luaRed = lua_tointeger( L, s );
6329
if( ! lua_isnumber( L, s ) )
6331
lua_pushstring( L, "setFgColor: wrong argument type" );
6337
luaGreen=lua_tointeger( L, s );
6341
if( ! lua_isnumber( L, s ) )
6343
lua_pushstring( L, "setFgColor: wrong argument type" );
6349
luaBlue = lua_tointeger( L, s );
6352
QString _name( a1.c_str() );
6353
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
6355
pHost->mpConsole->setFgColor( luaRed, luaGreen, luaBlue );
6357
mudlet::self()->setFgColor( pHost, _name, luaRed, luaGreen, luaBlue );
6361
int TLuaInterpreter::setBgColor( lua_State *L )
6364
int n = lua_gettop( L );
6371
if( lua_isstring( L, s ) )
6373
a1 = lua_tostring( L, s );
6377
if( ! lua_isnumber( L, s ) )
6379
lua_pushstring( L, "setBgColor: wrong argument type" );
6385
luaRed = lua_tointeger( L, s );
6389
if( ! lua_isnumber( L, s ) )
6391
lua_pushstring( L, "setBgColor: wrong argument type" );
6397
luaGreen=lua_tointeger( L, s );
6401
if( ! lua_isnumber( L, s ) )
6403
lua_pushstring( L, "setBgColor: wrong argument type" );
6409
luaBlue = lua_tointeger( L, s );
6412
QString _name( a1.c_str() );
6413
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
6415
pHost->mpConsole->setBgColor( luaRed, luaGreen, luaBlue );
6417
mudlet::self()->setBgColor( pHost, _name, luaRed, luaGreen, luaBlue );
6421
int TLuaInterpreter::insertLink( lua_State *L )
6427
int n = lua_gettop( L );
6429
if( ! lua_isstring( L, s ) )
6431
lua_pushstring( L, "insertLink: wrong argument type" );
6437
a1 = lua_tostring( L, s );
6440
QString _name( a1.c_str() );
6444
if( ! lua_isstring( L, s ) )
6446
lua_pushstring( L, "insertLink: wrong argument type" );
6452
a2 = lua_tostring( L, s );
6458
if( ! lua_isstring( L, s ) )
6460
lua_pushstring( L, "insertLink: wrong argument type" );
6466
a3 = lua_tostring( L, s );
6471
if( ! lua_isstring( L, s ) )
6473
lua_pushstring( L, "insertLink: wrong argument type" );
6479
a4 = lua_tostring( L, s );
6482
QStringList command;
6485
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
6488
command << a2.c_str();
6490
pHost->mpConsole->insertLink( QString(a1.c_str()), command, hint );
6494
command << a3.c_str();
6496
mudlet::self()->insertLink( pHost, _name, QString( a2.c_str() ), command, hint );
6502
int TLuaInterpreter::insertPopup( lua_State *L )
6506
QStringList _hintList;
6507
QStringList _commandList;
6508
bool customFormat = false;
6510
int n = lua_gettop( L );
6511
// console name is an optional first argument
6514
if( ! lua_isstring( L, s ) )
6516
lua_pushstring( L, "insertPopup: wrong argument type" );
6522
a1 = lua_tostring( L, s );
6526
if( ! lua_isstring( L, s ) )
6528
lua_pushstring( L, "insertPopup: wrong argument type" );
6534
a2 = lua_tostring( L, s );
6538
if( ! lua_istable( L, s ) )
6540
lua_pushstring( L, "insertPopup: wrong argument type" );
6547
while( lua_next( L, s ) != 0 )
6549
// key at index -2 and value at index -1
6550
if( lua_type(L, -1) == LUA_TSTRING )
6552
QString cmd = lua_tostring( L, -1 );
6553
_commandList << cmd;
6555
// removes value, but keeps key for next iteration
6560
if( ! lua_istable( L, s ) )
6562
lua_pushstring( L, "insertPopup: wrong argument type" );
6569
while( lua_next( L, s ) != 0 )
6571
// key at index -2 and value at index -1
6572
if( lua_type(L, -1) == LUA_TSTRING )
6574
QString hint = lua_tostring( L, -1 );
6577
// removes value, but keeps key for next iteration
6584
customFormat = lua_toboolean( L, s );
6587
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
6588
QString txt = a2.c_str();
6589
QString name = a1.c_str();
6590
if( _commandList.size() != _hintList.size() )
6592
lua_pushstring( L, "Error: command list size and hint list size do not match cannot create popup" );
6599
pHost->mpConsole->insertLink( txt, _commandList, _hintList, customFormat );
6603
mudlet::self()->insertLink( pHost, name, txt, _commandList, _hintList, customFormat );
6609
int TLuaInterpreter::insertText( lua_State *L )
6613
int n = lua_gettop( L );
6615
if( ! lua_isstring( L, s ) )
6617
lua_pushstring( L, "insertText: wrong argument type" );
6623
a1 = lua_tostring( L, s );
6626
QString _name( a1.c_str() );
6630
if( ! lua_isstring( L, s ) )
6632
lua_pushstring( L, "insertText: wrong argument type" );
6638
a2 = lua_tostring( L, s );
6641
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
6643
pHost->mpConsole->insertText( QString(a1.c_str()) );
6645
mudlet::self()->insertText( pHost, _name, QString( a2.c_str() ) );
6649
int TLuaInterpreter::insertHTML( lua_State *L )
6652
if( ! lua_isstring( L, 1 ) )
6654
lua_pushstring( L, "insertHTML: wrong argument type" );
6660
luaSendText = lua_tostring( L, 1 );
6662
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
6663
pHost->mpConsole->insertHTML( QString(luaSendText.c_str()) );
6667
int TLuaInterpreter::Echo( lua_State *L )
6672
int n = lua_gettop( L );
6674
if( ! lua_isstring( L, s ) )
6676
lua_pushstring( L, "Echo: wrong argument type" );
6682
a1 = lua_tostring( L, s );
6687
if( ! lua_isstring( L, s ) )
6689
lua_pushstring( L, "Echo: wrong argument type" );
6695
a2 = lua_tostring( L, s );
6698
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
6704
pHost->mpConsole->echo( txt );
6710
mudlet::self()->echoWindow( pHost, name, txt );
6716
int TLuaInterpreter::echoPopup( lua_State *L )
6720
QStringList _hintList;
6721
QStringList _commandList;
6722
bool customFormat = false;
6724
int n = lua_gettop( L );
6725
// console name is an optional first argument
6728
if( ! lua_isstring( L, s ) )
6730
lua_pushstring( L, "echoPopup: wrong argument type" );
6736
a1 = lua_tostring( L, s );
6740
if( ! lua_isstring( L, s ) )
6742
lua_pushstring( L, "echoPopup: wrong argument type" );
6748
a2 = lua_tostring( L, s );
6752
if( ! lua_istable( L, s ) )
6754
lua_pushstring( L, "echoPopup: wrong argument type" );
6761
while( lua_next( L, s ) != 0 )
6763
// key at index -2 and value at index -1
6764
if( lua_type(L, -1) == LUA_TSTRING )
6766
QString cmd = lua_tostring( L, -1 );
6767
_commandList << cmd;
6769
// removes value, but keeps key for next iteration
6774
if( ! lua_istable( L, s ) )
6776
lua_pushstring( L, "echoPopup: wrong argument type" );
6783
while( lua_next( L, s ) != 0 )
6785
// key at index -2 and value at index -1
6786
if( lua_type(L, -1) == LUA_TSTRING )
6788
QString hint = lua_tostring( L, -1 );
6791
// removes value, but keeps key for next iteration
6798
customFormat = lua_toboolean( L, s );
6801
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
6802
QString txt = a2.c_str();
6803
QString name = a1.c_str();
6804
if( _commandList.size() != _hintList.size() )
6806
lua_pushstring( L, "Error: command list size and hint list size do not match cannot create popup" );
6813
pHost->mpConsole->echoLink( txt, _commandList, _hintList, customFormat );
6817
mudlet::self()->echoLink( pHost, name, txt, _commandList, _hintList, customFormat );
6824
int TLuaInterpreter::echoLink( lua_State *L )
6831
bool gotBool = false;
6834
int n = lua_gettop( L );
6836
if( ! lua_isstring( L, s ) )
6838
lua_pushstring( L, "echoLink: wrong argument type" );
6844
a1 = lua_tostring( L, s );
6849
if( ! lua_isstring( L, s ) )
6851
lua_pushstring( L, "echoLink: wrong argument type" );
6857
a2 = lua_tostring( L, s );
6863
if( ! lua_isstring( L, s ) )
6865
lua_pushstring( L, "echoLink: wrong argument type" );
6871
a3 = lua_tostring( L, s );
6877
if( lua_isstring( L, s ) )
6879
a4 = lua_tostring( L, s );
6882
else if( lua_isboolean( L, s ) )
6885
a5 = lua_toboolean( L, s );
6891
if( ! lua_isboolean( L, s ) )
6893
lua_pushstring( L, "echoLink: wrong argument type" );
6899
a5 = lua_toboolean( L, s );
6904
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
6909
if( n == 3 || ( n == 4 && gotBool ) )
6914
pHost->mpConsole->echoLink( txt, func, hint, a5 );
6922
mudlet::self()->echoLink( pHost, name, txt, func, hint, a5 );
6928
int TLuaInterpreter::pasteWindow( lua_State *L )
6931
if( ! lua_isstring( L, 1 ) )
6933
lua_pushstring( L, "pasteWindow: wrong argument type" );
6939
luaName = lua_tostring( L, 1 );
6941
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
6942
QString name( luaName.c_str());
6943
mudlet::self()->pasteWindow( pHost, name );
6947
int TLuaInterpreter::openUrl( lua_State *L )
6950
if( ! lua_isstring( L, 1 ) )
6952
lua_pushstring( L, "openUrl: wrong argument type" );
6958
luaName = lua_tostring( L, 1 );
6960
QString url( luaName.c_str());
6961
QDesktopServices::openUrl(url);
6965
int TLuaInterpreter::setLabelStyleSheet( lua_State * L )
6967
string luaSendText="";
6968
if( ! lua_isstring( L, 1 ) )
6970
lua_pushstring( L, "setLabelStyleSheet: wrong argument type" );
6976
luaSendText = lua_tostring( L, 1 );
6979
if( ! lua_isstring( L, 2 ) )
6981
lua_pushstring( L, "setLabelStyleSheet: wrong argument type" );
6987
a2 = lua_tostring( L, 2 );
6989
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
6990
pHost->mpConsole->setLabelStyleSheet( luaSendText, a2 );
6994
int TLuaInterpreter::getCustomEnvColorTable( lua_State * L )
6996
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
6997
if( pHost->mpMap->customEnvColors.size() > 0 )
7000
QList<int> colorList = pHost->mpMap->customEnvColors.keys();
7001
for( int idx=0; idx<colorList.size(); idx++ )
7003
lua_pushnumber( L, colorList[idx] );
7007
lua_pushnumber( L, 1 );
7008
lua_pushnumber( L, pHost->mpMap->customEnvColors[colorList[idx]].red() );
7009
lua_settable( L, -3 );//match in matches
7013
lua_pushnumber( L, 2 );
7014
lua_pushnumber( L, pHost->mpMap->customEnvColors[colorList[idx]].green() );
7015
lua_settable( L, -3 );//match in matches
7019
lua_pushnumber( L, 3 );
7020
lua_pushnumber( L, pHost->mpMap->customEnvColors[colorList[idx]].blue() );
7021
lua_settable( L, -3 );//match in matches
7023
lua_settable( L, -3 );//matches in regex
7033
//syntax: getTime( bool return_string, string time_format ) with return_string == false -> return table
7034
int TLuaInterpreter::getTime( lua_State * L )
7036
int n = lua_gettop( L );
7037
bool return_string = false;
7038
QString fmt = "yyyy.MM.dd hh:mm:ss.zzz";
7042
return_string = lua_toboolean( L, 1 );
7045
if( ! lua_isstring( L, 2 ) )
7047
lua_pushstring( L, "getTime: wrong argument type" );
7053
fmt = lua_tostring( L, 2 );
7057
QDateTime time = QDateTime::currentDateTime();
7060
tm = time.toString( fmt );
7061
lua_pushstring( L, tm.toLatin1().data() );
7065
QDate dt = time.date();
7066
QTime tm = time.time();
7067
lua_createtable( L, 0, 4 );
7068
lua_pushstring( L, "hour" );
7069
lua_pushinteger( L, tm.hour() );
7070
lua_rawset( L, n+1 );
7071
lua_pushstring( L, "min" );
7072
lua_pushinteger( L, tm.minute() );
7073
lua_rawset( L, n+1 );
7074
lua_pushstring( L, "sec" );
7075
lua_pushinteger( L, tm.second() );
7076
lua_rawset( L, n+1 );
7077
lua_pushstring( L, "msec" );
7078
lua_pushinteger( L, tm.msec() );
7079
lua_rawset( L, n+1 );
7080
lua_pushstring( L, "year" );
7081
lua_pushinteger( L, dt.year() );
7082
lua_rawset( L, n+1 );
7083
lua_pushstring( L, "month" );
7084
lua_pushinteger( L, dt.month() );
7085
lua_rawset( L, n+1 );
7086
lua_pushstring( L, "day" );
7087
lua_pushinteger( L, dt.day() );
7088
lua_rawset( L, n+1 );
7094
int TLuaInterpreter::appendBuffer( lua_State *L )
7099
int n = lua_gettop( L );
7102
if( ! lua_isstring( L, s ) )
7104
lua_pushstring( L, "appendBuffer: wrong argument type" );
7110
a1 = lua_tostring( L, s );
7114
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
7118
pHost->mpConsole->appendBuffer();
7122
QString name = a1.c_str();
7123
mudlet::self()->appendBuffer( pHost, name );
7129
int TLuaInterpreter::appendCmdLine( lua_State * L )
7132
if( ! lua_isstring( L, 1 ) )
7134
lua_pushstring( L, "appendCmdLine(): wrong argument type" );
7140
luaSendText = lua_tostring( L, 1 );
7142
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
7143
QString curText = pHost->mpConsole->mpCommandLine->toPlainText();
7144
pHost->mpConsole->mpCommandLine->setPlainText( curText + QString( luaSendText.c_str() ) );
7145
QTextCursor cur = pHost->mpConsole->mpCommandLine->textCursor();
7146
cur.clearSelection();
7147
cur.movePosition(QTextCursor::EndOfLine);
7148
pHost->mpConsole->mpCommandLine->setTextCursor(cur);
7152
int TLuaInterpreter::registerAnonymousEventHandler( lua_State * L )
7155
if( ! lua_isstring( L, 1 ) )
7157
lua_pushstring( L, "appendCmdLine(): wrong argument type" );
7163
event = lua_tostring( L, 1 );
7166
if( ! lua_isstring( L, 2 ) )
7168
lua_pushstring( L, "appendCmdLine(): wrong argument type" );
7174
func = lua_tostring( L, 2 );
7176
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
7177
QString e = event.c_str();
7178
QString f = func.c_str();
7179
pHost->registerAnonymousEventHandler( e, f );
7184
int TLuaInterpreter::Send( lua_State * L )
7187
if( ! lua_isstring( L, 1 ) )
7189
lua_pushstring( L, "Send: wrong argument type" );
7195
luaSendText = lua_tostring( L, 1 );
7197
bool wantPrint = true;
7198
if( lua_gettop( L ) > 1 )
7200
if( ! lua_isboolean( L, 2 ) )
7202
lua_pushstring( L, "Send: wrong argument type" );
7208
wantPrint = lua_toboolean( L, 2 );
7211
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
7212
pHost->send( QString( luaSendText.c_str() ), wantPrint, false );
7216
int TLuaInterpreter::printCmdLine( lua_State * L )
7219
if( ! lua_isstring( L, 1 ) )
7221
lua_pushstring( L, "printCmdLine: wrong argument type" );
7227
luaSendText = lua_tostring( L, 1 );
7229
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
7230
pHost->mpConsole->mpCommandLine->setPlainText( QString( luaSendText.c_str() ) );
7231
QTextCursor cur = pHost->mpConsole->mpCommandLine->textCursor();
7232
cur.clearSelection();
7233
cur.movePosition(QTextCursor::EndOfLine);
7234
pHost->mpConsole->mpCommandLine->setTextCursor(cur);
7238
int TLuaInterpreter::clearCmdLine( lua_State * L )
7240
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
7241
pHost->mpConsole->mpCommandLine->clear();
7245
int TLuaInterpreter::sendRaw( lua_State * L )
7248
if( ! lua_isstring( L, 1 ) )
7250
lua_pushstring( L, "sendRaw: wrong argument type" );
7256
luaSendText = lua_tostring( L, 1 );
7258
bool wantPrint = true;
7259
if( lua_gettop( L ) > 1 )
7261
if( ! lua_isboolean( L, 2 ) )
7263
lua_pushstring( L, "sendRaw: wrong argument type" );
7269
wantPrint = lua_toboolean( L, 2 );
7272
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
7273
pHost->send( QString(luaSendText.c_str()), wantPrint, true );
7277
int TLuaInterpreter::sendSocket( lua_State * L )
7280
if( ! lua_isstring( L, 1 ) )
7282
lua_pushstring( L, "sendSocket: wrong argument type" );
7288
luaSendText = lua_tostring( L, 1 );
7290
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
7291
pHost->mTelnet.socketOutRaw( luaSendText );
7296
int TLuaInterpreter::sendIrc( lua_State * L )
7299
if( ! lua_isstring( L, 1 ) )
7301
lua_pushstring( L, "sendSocket: wrong argument type" );
7307
who = lua_tostring( L, 1 );
7310
if( ! lua_isstring( L, 2 ) )
7312
lua_pushstring( L, "sendSocket: wrong argument type" );
7318
text = lua_tostring( L, 2 );
7320
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
7321
QString chan = who.c_str();
7322
QString txt = text.c_str();
7323
if( ! mudlet::self()->mpIRC ) return 0;
7324
mudlet::self()->mpIRC->session->cmdMessage( chan, txt );
7329
bool TLuaInterpreter::compileAndExecuteScript( QString & code )
7331
if( code.size() < 1 ) return false;
7332
lua_State * L = pGlobalLua;
7335
qDebug()<< "LUA CRITICAL ERROR: no suitable Lua execution unit found.";
7339
int error = luaL_dostring( L, code.toLatin1().data() );
7343
string e = "no error message available from Lua";
7344
if( lua_isstring( L, 1 ) )
7347
e+=lua_tostring( L, 1 );
7349
if( mudlet::debugMode ) qDebug()<<"LUA ERROR: code did not compile: ERROR:"<<e.c_str();
7350
emit signalEchoMessage( mHostID, QString( e.c_str() ) );
7353
lua_pop( L, lua_gettop( L ) );
7355
if( error == 0 ) return true;
7359
bool TLuaInterpreter::compileScript( QString & code )
7361
lua_State * L = pGlobalLua;
7364
qDebug()<< "LUA CRITICAL ERROR: no suitable Lua execution unit found.";
7368
/*lua_newtable( L );
7371
for( int i=0; i<matches.size(); i++ )
7373
lua_pushnumber( L, i+1 ); // Lua indexes start with 1
7374
lua_pushstring( L, matches[i].toLatin1().data() );
7375
lua_settable( L, -3 );
7377
lua_setglobal( L, "matches" );*/
7379
int error = luaL_dostring( L, code.toLatin1().data() );
7383
string e = "no error message available from Lua";
7384
if( lua_isstring( L, 1 ) )
7387
e+=lua_tostring( L, 1 );
7389
if( mudlet::debugMode ){ TDebug(QColor(Qt::white),QColor(Qt::red))<<"LUA: code did not compile: ERROR:"<<e.c_str()<<"\n">>0;}
7393
if( mudlet::debugMode ) {TDebug(QColor(Qt::white),QColor(Qt::darkGreen))<<"LUA: code compiled without errors. OK\n">>0;}
7395
lua_pop( L, lua_gettop( L ) );
7397
if( error == 0 ) return true;
7401
bool TLuaInterpreter::compile( QString & code )
7403
lua_State * L = pGlobalLua;
7406
qDebug()<< "LUA CRITICAL ERROR: no suitable Lua execution unit found.";
7410
int error = luaL_dostring( L, code.toLatin1().data() );
7414
string e = "no error message available from Lua";
7415
if( lua_isstring( L, 1 ) )
7418
e+=lua_tostring( L, 1 );
7420
if( mudlet::debugMode ){ TDebug(QColor(Qt::white),QColor(Qt::red))<<"LUA: code did not compile: ERROR:"<<e.c_str()<<"\n">>0;}
7424
if( mudlet::debugMode ){ TDebug(QColor(Qt::white),QColor(Qt::darkGreen))<<"LUA: code compiled without errors. OK\n" >> 0;}
7426
lua_pop( L, lua_gettop( L ) );
7428
if( error == 0 ) return true;
7432
bool TLuaInterpreter::compile( QString & code, QString & errorMsg )
7434
lua_State * L = pGlobalLua;
7437
qDebug()<< "LUA CRITICAL ERROR: no suitable Lua execution unit found.";
7441
int error = luaL_dostring( L, code.toLatin1().data() );
7445
string e = "Lua syntax error:";
7446
if( lua_isstring( L, 1 ) )
7448
e.append( lua_tostring( L, 1 ) );
7450
errorMsg = "<b><font color='blue'>";
7451
errorMsg.append( e.c_str() );
7452
errorMsg.append("</b></font>");
7453
if( mudlet::debugMode ){ TDebug(QColor(Qt::white),QColor(Qt::red))<<"\n "<<e.c_str()<<"\n">>0;}
7457
if( mudlet::debugMode ) {TDebug(QColor(Qt::white),QColor(Qt::red))<<"\nLUA: code compiled without errors. OK\n" >> 0;}
7459
lua_pop( L, lua_gettop( L ) );
7461
if( error == 0 ) return true;
7465
void TLuaInterpreter::setMultiCaptureGroups( const std::list< std::list<std::string> > & captureList,
7466
const std::list< std::list<int> > & posList )
7468
mMultiCaptureGroupList = captureList;
7469
mMultiCaptureGroupPosList = posList;
7471
/*std::list< std::list<string> >::const_iterator mit = mMultiCaptureGroupList.begin();
7474
for( ; mit!=mMultiCaptureGroupList.end(); mit++, k++ )
7476
cout << "regex#"<<k<<" got:"<<endl;
7477
std::list<string>::const_iterator it = (*mit).begin();
7478
for( int i=1; it!=(*mit).end(); it++, i++ )
7480
cout << i<<"#"<<"<"<<*it<<">"<<endl;
7482
cout << "-----------------------------"<<endl;
7486
void TLuaInterpreter::setCaptureGroups( const std::list<std::string> & captureList, const std::list<int> & posList )
7488
mCaptureGroupList = captureList;
7489
mCaptureGroupPosList = posList;
7491
/*std::list<string>::iterator it2 = mCaptureGroupList.begin();
7492
std::list<int>::iterator it1 = mCaptureGroupPosList.begin();
7494
for( ; it1!=mCaptureGroupPosList.end(); it1++, it2++, i++ )
7496
cout << "group#"<<i<<" begin="<<*it1<<" len="<<(*it2).size()<<"word="<<*it2<<endl;
7500
void TLuaInterpreter::clearCaptureGroups()
7502
mCaptureGroupList.clear();
7503
mCaptureGroupPosList.clear();
7504
mMultiCaptureGroupList.clear();
7505
mMultiCaptureGroupPosList.clear();
7507
lua_State * L = pGlobalLua;
7510
qDebug()<< "LUA CRITICAL ERROR: no suitable Lua execution unit found.";
7514
lua_setglobal( L, "matches" );
7516
lua_setglobal( L, "multimatches" );
7518
lua_pop( L, lua_gettop( L ) );
7522
void TLuaInterpreter::adjustCaptureGroups( int x, int a )
7524
// adjust all capture group positions in line if data has been inserted by the user
7525
typedef std::list<int>::iterator I;
7526
for( I it=mCaptureGroupPosList.begin(); it!=mCaptureGroupPosList.end(); it++ )
7535
void TLuaInterpreter::setAtcpTable( QString & var, QString & arg )
7537
lua_State * L = pGlobalLua;
7538
lua_getglobal( L, "atcp" ); //defined in LuaGlobal.lua
7539
lua_pushstring( L, var.toLatin1().data() );
7540
lua_pushstring( L, arg.toLatin1().data() );
7541
lua_rawset( L, -3 );
7545
event.mArgumentList.append( var );
7546
event.mArgumentTypeList.append( ARGUMENT_TYPE_STRING );
7547
event.mArgumentList.append( arg );
7548
event.mArgumentTypeList.append( ARGUMENT_TYPE_STRING );
7549
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
7550
pHost->raiseEvent( & event );
7554
void TLuaInterpreter::setGMCPTable(QString & key, QString & string_data)
7556
lua_State * L = pGlobalLua;
7557
lua_getglobal(L, "gmcp"); //defined in Lua init
7558
if( !lua_istable(L, -1) )
7560
qDebug()<<"ERROR: gmcp not defined -> error in LuaGlobal.lua";
7563
// key is in format of Blah.Blah or Blah.Blah.Bleh - we want to push & pre-create the tables as appriate
7565
QStringList tokenList = key.split(".");
7566
if( ! lua_checkstack( L, tokenList.size()+5 ) ) return;
7568
for( ; i<tokenList.size()-1; i++ )
7570
lua_getfield(L, -1, tokenList[i].toLatin1().data());
7571
if( !lua_istable(L, -1) )
7574
lua_pushstring(L, tokenList[i].toLatin1().data());
7577
lua_getfield(L, -1, tokenList[i].toLatin1().data());
7581
bool __needMerge = false;
7582
lua_getfield(L, -1, tokenList[i].toLatin1().data());
7583
if( lua_istable(L, -1) )
7585
// only merge tables (instead of replacing them) if the key has been registered as a need to merge key by the user default is Char.Status only
7586
if( mpHost->mGMCP_merge_table_keys.contains( key ) )
7593
lua_pushstring(L, tokenList[i].toLatin1().data());
7595
lua_pushstring(L, "__needMerge");
7597
lua_getglobal(L, "json_to_value");
7599
if( !lua_isfunction(L, -1) )
7602
qDebug()<<"CRITICAL ERROR: json_to_value not defined";
7605
lua_pushlstring(L, string_data.toLatin1().data(), string_data.size());
7606
int error = lua_pcall(L, 1, 1, 0);
7609
// Top of stack should now contain the lua representation of json.
7614
lua_getglobal(L, "__gmcp_merge_gmcp_sub_tables");
7615
if( !lua_isfunction(L, -1) )
7618
qDebug()<<"CRITICAL ERROR: __gmcp_merge_gmcp_sub_tables is not defined in lua_LuaGlobal.lua";
7621
lua_getglobal(L, "gmcp");
7623
for( ; i<tokenList.size()-1; i++ )
7625
lua_getfield(L, -1, tokenList[i].toLatin1().data());
7628
lua_pushstring( L, tokenList[i].toLatin1().data());
7629
lua_pcall(L, 2, 0, 0);
7634
// events: for key "foo.bar.top" we raise: gmcp.foo, gmcp.foo.bar and gmcp.foo.bar.top
7635
// with the actual key given as parameter e.g. event=gmcp.foo, param="gmcp.foo.bar"
7637
QString token = "gmcp";
7638
key.prepend("gmcp.");
7639
for( int k=0; k<tokenList.size(); k++ )
7642
token.append( "." );
7643
token.append( tokenList[k] );
7644
event.mArgumentList.append( token );
7645
event.mArgumentTypeList.append(ARGUMENT_TYPE_STRING);
7646
event.mArgumentList.append( key );
7647
event.mArgumentTypeList.append(ARGUMENT_TYPE_STRING);
7648
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
7649
if( mudlet::debugMode )
7651
QString msg = "\nGMCP event <";
7652
msg.append( token );
7653
msg.append("> display(gmcp) to see the full content\n");
7654
pHost->mpConsole->printSystemMessage(msg);
7656
pHost->raiseEvent( &event );
7658
// auto-detect IRE composer
7659
if( tokenList.size() == 3 && tokenList.at(0) == "IRE" && tokenList.at(1) == "Composer" && tokenList.at(2) == "Edit")
7661
QRegExp rx("\\{ \"title\": \"(.*)\", \"text\": \"(.*)\" \\}");
7662
if( rx.indexIn(string_data) != -1 )
7664
QString title = rx.cap(1);
7665
QString initialText = rx.cap(2);
7666
initialText.replace(QString("\\n"), QString("\n"));
7667
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
7668
if( pHost->mTelnet.mpComposer ) return;
7669
pHost->mTelnet.mpComposer = new dlgComposer( pHost );
7670
pHost->mTelnet.mpComposer->init( title, initialText );
7671
pHost->mTelnet.mpComposer->raise();
7672
pHost->mTelnet.mpComposer->show();
7675
lua_pop( L, lua_gettop( L ) );
7678
void TLuaInterpreter::setChannel102Table( int & var, int & arg )
7680
lua_State * L = pGlobalLua;
7681
lua_getglobal( L, "channel102" ); //defined in LuaGlobal.lua
7682
lua_pushnumber( L, var );
7683
lua_pushnumber( L, arg );
7684
lua_rawset( L, -3 );
7688
QString e = "channel102Message";
7689
event.mArgumentList.append( e );
7690
event.mArgumentTypeList.append( ARGUMENT_TYPE_STRING );
7691
event.mArgumentList.append( QString::number(var) );
7692
event.mArgumentTypeList.append( ARGUMENT_TYPE_NUMBER );
7693
event.mArgumentList.append( QString::number(arg) );
7694
event.mArgumentTypeList.append( ARGUMENT_TYPE_NUMBER );
7695
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
7696
pHost->raiseEvent( & event );
7699
bool TLuaInterpreter::call_luafunction( void * pT )
7701
lua_State * L = pGlobalLua;
7702
lua_pushlightuserdata( L, pT );
7703
lua_gettable( L, LUA_REGISTRYINDEX );
7704
if( lua_isfunction( L, -1 ) )
7706
int error = lua_pcall( L, 0, LUA_MULTRET, 0 );
7709
int nbpossible_errors = lua_gettop(L);
7710
for (int i=1; i<=nbpossible_errors; i++)
7713
if(lua_isstring( L, i) )
7716
e+=lua_tostring( L, i );
7717
QString _n = "error in anonymous Lua function";
7718
QString _n2 = "no debug data available";
7719
logError( e, _n, _n2 );
7720
if( mudlet::debugMode ){ TDebug(QColor(Qt::white),QColor(Qt::red))<<"LUA: ERROR running anonymous Lua function ERROR:"<<e.c_str()>>0;}
7726
if( mudlet::debugMode ){ TDebug(QColor(Qt::white),QColor(Qt::darkGreen))<<"LUA OK anonymous Lua function ran without errors\n">>0;}
7728
lua_pop( L, lua_gettop( L ) );
7737
QString _n = "error in anonymous Lua function";
7738
QString _n2 = "func reference not found by Lua, func can not be called";
7739
string e = "Lua error:";
7740
logError( e, _n, _n2 );
7747
bool TLuaInterpreter::call( QString & function, QString & mName )
7749
lua_State * L = pGlobalLua;
7752
qDebug()<< "LUA CRITICAL ERROR: no suitable Lua execution unit found.";
7756
if( mCaptureGroupList.size() > 0 )
7761
int i=1; // Lua indexes start with 1 as a general convention
7762
std::list<std::string>::iterator it = mCaptureGroupList.begin();
7763
for( ; it!=mCaptureGroupList.end(); it++, i++ )
7765
//if( (*it).length() < 1 ) continue; //have empty capture groups to be undefined keys i.e. machts[emptyCapGroupNumber] = nil otherwise it's = "" i.e. an empty string
7766
lua_pushnumber( L, i );
7767
lua_pushstring( L, (*it).c_str() );
7768
lua_settable( L, -3 );
7770
lua_setglobal( L, "matches" );
7773
lua_getglobal( L, function.toLatin1().data() );
7774
lua_getfield( L, LUA_GLOBALSINDEX, function.toLatin1().data() );
7775
int error = lua_pcall( L, 0, LUA_MULTRET, 0 );
7778
int nbpossible_errors = lua_gettop(L);
7779
for (int i=1; i<=nbpossible_errors; i++)
7782
if(lua_isstring( L, i) )
7784
e += lua_tostring( L, i );
7785
logError( e, mName, function );
7786
if( mudlet::debugMode ){ TDebug(QColor(Qt::white),QColor(Qt::red))<<"LUA: ERROR running script "<< mName << " (" << function <<") ERROR:"<<e.c_str()>>0;}
7792
if( mudlet::debugMode ){ TDebug(QColor(Qt::white),QColor(Qt::darkGreen))<<"LUA OK script "<<mName << " (" << function <<") ran without errors\n">>0;}
7794
lua_pop( L, lua_gettop( L ) );
7795
if( error == 0 ) return true;
7799
void TLuaInterpreter::logError( std::string & e, QString & name, QString & function )
7801
//QDateTime time = QDateTime::currentDateTime();
7802
// QString entry = QString("[%1]object:<%2> function:<%3> error:<%4>").arg(time.toString("MMM:dd:yyyy hh-mm-ss")).arg(name).arg(function).arg(e.c_str());
7803
//mpHost->mErrorLogStream << entry << endl;
7804
QColor blue = QColor(0,0,255);
7805
QColor green = QColor(0,255,0);
7806
QColor red = QColor(255,0,0);
7807
QColor black = QColor(0,0,0);
7808
QString s1 = QString("[ERROR:]");
7809
QString s2 = QString(" object:<%1> function:<%2>\n").arg(name).arg(function);
7810
QString s3 = QString(" <%1>\n").arg(e.c_str());
7811
if( mpHost->mpEditorDialog )
7813
mpHost->mpEditorDialog->mpErrorConsole->printDebug(blue, black, s1 );
7814
mpHost->mpEditorDialog->mpErrorConsole->printDebug(green, black, s2 );
7815
mpHost->mpEditorDialog->mpErrorConsole->printDebug(red, black, s3 );
7820
bool TLuaInterpreter::callConditionFunction( std::string & function, QString & mName )
7822
lua_State * L = pGlobalLua;
7825
qDebug()<< "LUA CRITICAL ERROR: no suitable Lua execution unit found.";
7829
lua_getfield( L, LUA_GLOBALSINDEX, function.c_str() );
7830
int error = lua_pcall( L, 0, 1, 0 );
7833
int nbpossible_errors = lua_gettop(L);
7834
for (int i=1; i<=nbpossible_errors; i++)
7837
if(lua_isstring( L, i) )
7839
e+=lua_tostring( L, i );
7840
QString _f = function.c_str();
7841
logError( e, mName, _f );
7842
if( mudlet::debugMode ){ TDebug(QColor(Qt::white),QColor(Qt::red))<<"LUA: ERROR running script "<< mName << " (" << function.c_str() <<") ERROR:"<<e.c_str()<<"\n">>0;}
7848
if( mudlet::debugMode ){ TDebug(QColor(Qt::white),QColor(Qt::darkGreen))<<"LUA OK script "<<mName << " (" << function.c_str() <<") ran without errors\n">>0;}
7852
int returnValues = lua_gettop( L );
7853
if( returnValues > 0 )
7855
if( lua_isboolean( L, 1 ) )
7857
ret = lua_toboolean( L, 1 );
7860
lua_pop( L, returnValues );
7861
if( (error == 0) && (ret>0) )
7871
bool TLuaInterpreter::callMulti( QString & function, QString & mName )
7873
lua_State * L = pGlobalLua;
7876
qDebug()<< "LUA CRITICAL ERROR: no suitable Lua execution unit found.";
7880
if( mMultiCaptureGroupList.size() > 0 )
7882
int k=1; // Lua indexes start with 1 as a general convention
7883
std::list< std::list<std::string> >::iterator mit = mMultiCaptureGroupList.begin();
7884
lua_newtable( L );//multimatches
7885
for( ; mit!=mMultiCaptureGroupList.end(); mit++, k++ )
7887
// multimatches{ trigger_idx{ table_matches{ ... } } }
7888
lua_pushnumber( L, k );
7889
lua_newtable( L );//regex-value => table matches
7890
int i=1; // Lua indexes start with 1 as a general convention
7891
std::list<std::string>::iterator it = (*mit).begin();
7892
for( ; it!=(*mit).end(); it++, i++ )
7894
lua_pushnumber( L, i );
7895
lua_pushstring( L, (*it).c_str() );
7896
lua_settable( L, -3 );//match in matches
7898
lua_settable( L, -3 );//matches in regex
7900
lua_setglobal( L, "multimatches" );
7903
lua_getglobal( L, function.toLatin1().data() );
7904
lua_getfield( L, LUA_GLOBALSINDEX, function.toLatin1().data() );
7905
int error = lua_pcall( L, 0, LUA_MULTRET, 0 );
7908
int nbpossible_errors = lua_gettop(L);
7909
for (int i=1; i<=nbpossible_errors; i++)
7912
if(lua_isstring( L, i) )
7914
e += lua_tostring( L, i );
7915
logError( e, mName, function );
7916
if( mudlet::debugMode ) {TDebug(QColor(Qt::white),QColor(Qt::red))<<"LUA: ERROR running script "<< mName << " (" << function <<") ERROR:"<<e.c_str()<<"\n">>0;}
7922
if( mudlet::debugMode ) {TDebug(QColor(Qt::white),QColor(Qt::darkGreen))<<"LUA OK script "<<mName << " (" << function <<") ran without errors\n">>0;}
7924
lua_pop( L, lua_gettop( L ) );
7925
if( error == 0 ) return true;
7930
bool TLuaInterpreter::callEventHandler( QString & function, TEvent * pE )
7932
lua_State * L = pGlobalLua;
7933
lua_getglobal( L, function.toLatin1().data() );
7934
lua_getfield( L, LUA_GLOBALSINDEX, function.toLatin1().data() );
7935
for( int i=0; i<pE->mArgumentList.size(); i++ )
7937
if( pE->mArgumentTypeList[i] == ARGUMENT_TYPE_NUMBER )
7939
lua_pushnumber( L, pE->mArgumentList[i].toInt() );
7943
lua_pushstring( L, pE->mArgumentList[i].toLatin1().data() );
7946
int error = lua_pcall( L, pE->mArgumentList.size(), LUA_MULTRET, 0 );
7950
if(lua_isstring( L, 1) )
7952
e+=lua_tostring( L, 1 );
7954
QString _n = "event handler function";
7955
logError( e, _n, function );
7956
if( mudlet::debugMode ) {TDebug(QColor(Qt::white),QColor(Qt::red))<<"LUA: ERROR running script "<< function << " (" << function <<") ERROR:"<<e.c_str()<<"\n">>0;}
7958
lua_pop( L, lua_gettop( L ) );
7959
if( error == 0 ) return true;
7964
void TLuaInterpreter::set_lua_table( QString & tableName, QStringList & variableList )
7966
lua_State * L = pGlobalLua;
7969
qDebug()<< "LUA CRITICAL ERROR: no suitable Lua execution unit found.";
7973
for( int i=0; i<variableList.size(); i++ )
7975
lua_pushnumber( L, i+1 ); // Lua indexes start with 1
7976
lua_pushstring( L, variableList[i].toLatin1().data() );
7977
lua_settable( L, -3 );
7979
lua_setglobal( L, tableName.toLatin1().data() );
7980
lua_pop( pGlobalLua, lua_gettop( pGlobalLua ) );
7983
void TLuaInterpreter::set_lua_string( const QString & varName, QString & varValue )
7985
lua_State * L = pGlobalLua;
7988
qDebug()<< "LUA CRITICAL ERROR: no suitable Lua execution unit found.";
7992
//lua_pushstring( L, varName.toLatin1().data() );
7993
lua_pushstring( L, varValue.toLatin1().data() );
7994
lua_setglobal( L, varName.toLatin1().data() );
7995
//lua_setfield( L, LUA_GLOBALSINDEX, s )
7996
lua_pop( pGlobalLua, lua_gettop( pGlobalLua ) );
7998
//lua_settable( L, LUA_GLOBALSINDEX );
8001
QString TLuaInterpreter::get_lua_string( QString & stringName )
8003
lua_State * L = pGlobalLua;
8006
qDebug()<< "LUA CRITICAL ERROR: no suitable Lua execution unit found.";
8007
return QString( "LUA CRITICAL ERROR" );
8010
lua_getglobal( L, stringName.toLatin1().data() );
8011
lua_getfield( L, LUA_GLOBALSINDEX, stringName.toLatin1().data() );
8012
return QString( lua_tostring( L, 1 ) );
8015
int TLuaInterpreter::check_for_mappingscript()
8017
lua_State * L = pGlobalLua;
8018
lua_getglobal(L, "mudlet");
8019
if( !lua_istable(L, -1) ) {
8024
lua_getfield(L, -1, "mapper_script");
8025
if( !lua_isboolean(L, -1) ) {
8030
int r = lua_toboolean(L, -1);
8035
void TLuaInterpreter::threadLuaInterpreterExec( string code )
8037
/* cout << "TLuaMainThread::threadLuaInterpreterExec(code) executing following code:" << endl;
8038
cout << "--------------------------------------------snip<" <<endl;
8039
cout << code << endl;
8040
cout << ">snip--------------------------------------------" <<endl;*/
8041
lua_State * L = pGlobalLua;
8042
int error = luaL_dostring(L,code.c_str());
8046
string e = "no error message available from Lua";
8047
if( lua_isstring( L, 1 ) )
8050
e += lua_tostring( L, 1 );
8052
emit signalEchoMessage( mHostID, QString( e.c_str() ) );
8053
qDebug()<< "LUA_ERROR:"<<e.c_str();
8056
cout << "cRunningScript::threadLuaInterpreterExec() done" << endl;
8061
void TLuaInterpreter::startLuaSessionInterpreter()
8063
//connect(this,SIGNAL(signalOpenWindow(int,QString)), this,SLOT(slotOpenWindow(int,QString)));
8064
//connect(this,SIGNAL(signalEchoWindow(int,QString,QString)), this,SLOT(slotEchoWindow(int,QString,QString)));
8065
//connect(this,SIGNAL(signalClearWindow(int,QString)), this,SLOT(slotClearWindow(int,QString)));
8066
//connect(this,SIGNAL(signalNewTrigger(QString,QString, int, QString)), this,SLOT(slotNewTrigger(QString,QString, int, QString)));
8067
//connect(this,SIGNAL(signalAddTimer(int,int,QString,QString)),this,SLOT(slotAddTimer(int,int,QString,QString)));
8068
//connect(this,SIGNAL(signalDeleteTrigger(int,QString)), this,SLOT(slotDeleteTrigger(int,QString)));
8071
//connect(this,SIGNAL(signalEchoMessage(int,QString)), this,SLOT(slotEchoMessage(int,QString)));//,Qt::DirectConnection);
8072
//connect(this,SIGNAL(signalNewEcho(int,QString)), this,SLOT(slotNewEcho(int,QString)));
8073
//connect(this,SIGNAL(signalNewCommand(int,QString)), this,SLOT(slotNewCommand(int,QString)));//,Qt::QueuedConnection);
8075
mpLuaSessionThread = new TLuaMainThread(this);
8076
mpLuaSessionThread->start(); //calls initLuaGlobals() to initialize the interpreter for this session
8083
// this function initializes the Lua Session interpreter.
8084
// on initialization of a new session *or* in case of an interpreter reset by the user.
8085
void TLuaInterpreter::initLuaGlobals()
8087
pGlobalLua = luaL_newstate();
8088
TLuaInterpreter::luaInterpreterMap[pGlobalLua]=mpHost;
8090
luaL_openlibs( pGlobalLua );
8092
lua_pushstring( pGlobalLua, "SESSION" );
8093
lua_pushnumber( pGlobalLua, mHostID );
8094
lua_settable( pGlobalLua, LUA_GLOBALSINDEX );
8096
lua_pushstring( pGlobalLua, "SCRIPT_NAME" );
8097
lua_pushstring( pGlobalLua, "Global Lua Session Interpreter" );
8098
lua_settable( pGlobalLua, LUA_GLOBALSINDEX );
8100
lua_pushstring( pGlobalLua, "SCRIPT_ID" );
8101
lua_pushnumber( pGlobalLua, -1 ); // ID 1 is used to indicate that this is the global Lua interpreter
8102
lua_settable( pGlobalLua, LUA_GLOBALSINDEX );
8103
lua_register( pGlobalLua, "showUnzipProgress", TLuaInterpreter::showUnzipProgress );//internal function used by the package system NOT FOR USERS
8104
lua_register( pGlobalLua, "wait", TLuaInterpreter::Wait );
8105
lua_register( pGlobalLua, "expandAlias", TLuaInterpreter::Send );
8106
lua_register( pGlobalLua, "echo", TLuaInterpreter::Echo );
8107
lua_register( pGlobalLua, "selectString", TLuaInterpreter::select );
8108
lua_register( pGlobalLua, "selectSection", TLuaInterpreter::selectSection );
8109
lua_register( pGlobalLua, "replace", TLuaInterpreter::replace );
8110
lua_register( pGlobalLua, "setBgColor", TLuaInterpreter::setBgColor );
8111
lua_register( pGlobalLua, "setFgColor", TLuaInterpreter::setFgColor );
8112
lua_register( pGlobalLua, "tempTimer", TLuaInterpreter::tempTimer );
8113
lua_register( pGlobalLua, "tempTrigger", TLuaInterpreter::tempTrigger );
8114
lua_register( pGlobalLua, "tempRegexTrigger", TLuaInterpreter::tempRegexTrigger );
8115
lua_register( pGlobalLua, "openUserWindow", TLuaInterpreter::openUserWindow );
8116
lua_register( pGlobalLua, "echoUserWindow", TLuaInterpreter::echoUserWindow );
8117
lua_register( pGlobalLua, "enableTimer", TLuaInterpreter::enableTimer );
8118
lua_register( pGlobalLua, "disableTimer", TLuaInterpreter::disableTimer );
8119
lua_register( pGlobalLua, "enableKey", TLuaInterpreter::enableKey );
8120
lua_register( pGlobalLua, "disableKey", TLuaInterpreter::disableKey );
8121
lua_register( pGlobalLua, "clearUserWindow", TLuaInterpreter::clearUserWindow );
8122
lua_register( pGlobalLua, "clearWindow", TLuaInterpreter::clearUserWindow );
8123
lua_register( pGlobalLua, "killTimer", TLuaInterpreter::killTimer );
8124
lua_register( pGlobalLua, "moveCursor", TLuaInterpreter::moveCursor );
8125
lua_register( pGlobalLua, "getLines", TLuaInterpreter::getLines );
8126
lua_register( pGlobalLua, "getLineNumber", TLuaInterpreter::getLineNumber );
8127
lua_register( pGlobalLua, "insertHTML", TLuaInterpreter::insertHTML );
8128
lua_register( pGlobalLua, "insertText", TLuaInterpreter::insertText );
8129
lua_register( pGlobalLua, "enableTrigger", TLuaInterpreter::enableTrigger );
8130
lua_register( pGlobalLua, "disableTrigger", TLuaInterpreter::disableTrigger );
8131
lua_register( pGlobalLua, "killTrigger", TLuaInterpreter::killTrigger );
8132
lua_register( pGlobalLua, "getLineCount", TLuaInterpreter::getLineCount );
8133
lua_register( pGlobalLua, "getColumnNumber", TLuaInterpreter::getColumnNumber );
8134
//lua_register( pGlobalLua, "getBufferTable", TLuaInterpreter::getBufferTable );
8135
//lua_register( pGlobalLua, "getBufferLine", TLuaInterpreter::getBufferLine );
8136
lua_register( pGlobalLua, "send", TLuaInterpreter::sendRaw );
8137
lua_register( pGlobalLua, "selectCaptureGroup", TLuaInterpreter::selectCaptureGroup );
8138
lua_register( pGlobalLua, "tempLineTrigger", TLuaInterpreter::tempLineTrigger );
8139
lua_register( pGlobalLua, "raiseEvent", TLuaInterpreter::raiseEvent );
8140
lua_register( pGlobalLua, "deleteLine", TLuaInterpreter::deleteLine );
8141
lua_register( pGlobalLua, "copy", TLuaInterpreter::copy );
8142
lua_register( pGlobalLua, "cut", TLuaInterpreter::cut );
8143
lua_register( pGlobalLua, "paste", TLuaInterpreter::paste );
8144
lua_register( pGlobalLua, "pasteWindow", TLuaInterpreter::pasteWindow );
8145
//lua_register( pGlobalLua, "userWindowLineWrap", TLuaInterpreter::userWindowLineWrap );
8146
lua_register( pGlobalLua, "debugc", TLuaInterpreter::debug );
8147
lua_register( pGlobalLua, "setWindowWrap", TLuaInterpreter::setWindowWrap );
8148
lua_register( pGlobalLua, "setWindowWrapIndent", TLuaInterpreter::setWindowWrapIndent );
8149
lua_register( pGlobalLua, "resetFormat", TLuaInterpreter::reset );
8150
lua_register( pGlobalLua, "moveCursorEnd", TLuaInterpreter::moveCursorEnd );
8151
lua_register( pGlobalLua, "getLastLineNumber", TLuaInterpreter::getLastLineNumber );
8152
lua_register( pGlobalLua, "getNetworkLatency", TLuaInterpreter::getNetworkLatency );
8153
lua_register( pGlobalLua, "createMiniConsole", TLuaInterpreter::createMiniConsole );
8154
lua_register( pGlobalLua, "createLabel", TLuaInterpreter::createLabel );
8155
lua_register( pGlobalLua, "hideWindow", TLuaInterpreter::hideUserWindow );
8156
lua_register( pGlobalLua, "showWindow", TLuaInterpreter::showUserWindow );
8157
lua_register( pGlobalLua, "createBuffer", TLuaInterpreter::createBuffer );
8158
lua_register( pGlobalLua, "createStopWatch", TLuaInterpreter::createStopWatch );
8159
lua_register( pGlobalLua, "getStopWatchTime", TLuaInterpreter::getStopWatchTime );
8160
lua_register( pGlobalLua, "stopStopWatch", TLuaInterpreter::stopStopWatch );
8161
lua_register( pGlobalLua, "startStopWatch", TLuaInterpreter::startStopWatch );
8162
lua_register( pGlobalLua, "resetStopWatch", TLuaInterpreter::resetStopWatch );
8163
lua_register( pGlobalLua, "closeUserWindow", TLuaInterpreter::closeUserWindow );
8164
lua_register( pGlobalLua, "resizeWindow", TLuaInterpreter::resizeUserWindow );
8165
lua_register( pGlobalLua, "appendBuffer", TLuaInterpreter::appendBuffer );
8166
lua_register( pGlobalLua, "setBackgroundImage", TLuaInterpreter::setBackgroundImage );
8167
lua_register( pGlobalLua, "setBackgroundColor", TLuaInterpreter::setBackgroundColor );
8168
lua_register( pGlobalLua, "createButton", TLuaInterpreter::createButton );
8169
lua_register( pGlobalLua, "setLabelClickCallback", TLuaInterpreter::setLabelClickCallback );
8170
lua_register( pGlobalLua, "moveWindow", TLuaInterpreter::moveWindow );
8171
lua_register( pGlobalLua, "setTextFormat", TLuaInterpreter::setTextFormat );
8172
lua_register( pGlobalLua, "getMainWindowSize", TLuaInterpreter::getMainWindowSize );
8173
lua_register( pGlobalLua, "getCurrentLine", TLuaInterpreter::getCurrentLine );
8174
lua_register( pGlobalLua, "setMiniConsoleFontSize", TLuaInterpreter::setMiniConsoleFontSize );
8175
lua_register( pGlobalLua, "selectCurrentLine", TLuaInterpreter::selectCurrentLine );
8176
lua_register( pGlobalLua, "spawn", TLuaInterpreter::spawn );
8177
lua_register( pGlobalLua, "getButtonState", TLuaInterpreter::getButtonState );
8178
lua_register( pGlobalLua, "showToolBar", TLuaInterpreter::showToolBar );
8179
lua_register( pGlobalLua, "hideToolBar", TLuaInterpreter::hideToolBar );
8180
lua_register( pGlobalLua, "loadRawFile", TLuaInterpreter::loadRawFile );
8181
lua_register( pGlobalLua, "setBold", TLuaInterpreter::setBold );
8182
lua_register( pGlobalLua, "setItalics", TLuaInterpreter::setItalics );
8183
lua_register( pGlobalLua, "setUnderline", TLuaInterpreter::setUnderline );
8184
lua_register( pGlobalLua, "disconnect", TLuaInterpreter::disconnect );
8185
lua_register( pGlobalLua, "reconnect", TLuaInterpreter::reconnect );
8186
lua_register( pGlobalLua, "getMudletHomeDir", TLuaInterpreter::getMudletHomeDir );
8187
lua_register( pGlobalLua, "setTriggerStayOpen", TLuaInterpreter::setTriggerStayOpen );
8188
lua_register( pGlobalLua, "wrapLine", TLuaInterpreter::wrapLine );
8189
lua_register( pGlobalLua, "getFgColor", TLuaInterpreter::getFgColor );
8190
lua_register( pGlobalLua, "getBgColor", TLuaInterpreter::getBgColor );
8191
lua_register( pGlobalLua, "tempColorTrigger", TLuaInterpreter::tempColorTrigger );
8192
lua_register( pGlobalLua, "isAnsiFgColor", TLuaInterpreter::isAnsiFgColor );
8193
lua_register( pGlobalLua, "isAnsiBgColor", TLuaInterpreter::isAnsiBgColor );
8194
lua_register( pGlobalLua, "playSoundFile", TLuaInterpreter::playSoundFile );
8195
lua_register( pGlobalLua, "setBorderTop", TLuaInterpreter::setBorderTop );
8196
lua_register( pGlobalLua, "setBorderBottom", TLuaInterpreter::setBorderBottom );
8197
lua_register( pGlobalLua, "setBorderLeft", TLuaInterpreter::setBorderLeft );
8198
lua_register( pGlobalLua, "setBorderRight", TLuaInterpreter::setBorderRight );
8199
lua_register( pGlobalLua, "setBorderColor", TLuaInterpreter::setBorderColor );
8200
lua_register( pGlobalLua, "setConsoleBufferSize", TLuaInterpreter::setConsoleBufferSize );
8201
lua_register( pGlobalLua, "startLogging", TLuaInterpreter::startLogging );
8202
lua_register( pGlobalLua, "calcFontSize", TLuaInterpreter::calcFontSize );
8203
lua_register( pGlobalLua, "permRegexTrigger", TLuaInterpreter::permRegexTrigger );
8204
lua_register( pGlobalLua, "permSubstringTrigger", TLuaInterpreter::permSubstringTrigger );
8205
lua_register( pGlobalLua, "permBeginOfLineStringTrigger", TLuaInterpreter::permBeginOfLineStringTrigger );
8206
lua_register( pGlobalLua, "permTimer", TLuaInterpreter::permTimer );
8207
lua_register( pGlobalLua, "permAlias", TLuaInterpreter::permAlias );
8208
lua_register( pGlobalLua, "exists", TLuaInterpreter::exists );
8209
lua_register( pGlobalLua, "isActive", TLuaInterpreter::isActive );
8210
lua_register( pGlobalLua, "enableAlias", TLuaInterpreter::enableAlias );
8211
lua_register( pGlobalLua, "tempAlias", TLuaInterpreter::tempAlias );
8212
lua_register( pGlobalLua, "disableAlias", TLuaInterpreter::disableAlias );
8213
lua_register( pGlobalLua, "killAlias", TLuaInterpreter::killAlias );
8214
lua_register( pGlobalLua, "setLabelStyleSheet", TLuaInterpreter::setLabelStyleSheet );
8215
lua_register( pGlobalLua, "getTime", TLuaInterpreter::getTime );
8216
lua_register( pGlobalLua, "invokeFileDialog", TLuaInterpreter::invokeFileDialog );
8217
lua_register( pGlobalLua, "getTimestamp", TLuaInterpreter::getTimestamp );
8218
lua_register( pGlobalLua, "setLink", TLuaInterpreter::setLink );
8219
lua_register( pGlobalLua, "deselect", TLuaInterpreter::deselect );
8220
lua_register( pGlobalLua, "insertLink", TLuaInterpreter::insertLink );
8221
lua_register( pGlobalLua, "echoLink", TLuaInterpreter::echoLink );
8222
lua_register( pGlobalLua, "echoPopup", TLuaInterpreter::echoPopup );
8223
lua_register( pGlobalLua, "insertPopup", TLuaInterpreter::insertPopup );
8224
lua_register( pGlobalLua, "setPopup", TLuaInterpreter::setPopup );
8225
lua_register( pGlobalLua, "sendATCP", TLuaInterpreter::sendATCP );
8226
lua_register( pGlobalLua, "hasFocus", TLuaInterpreter::hasFocus );
8227
lua_register( pGlobalLua, "isPrompt", TLuaInterpreter::isPrompt );
8228
lua_register( pGlobalLua, "feedTriggers", TLuaInterpreter::feedTriggers );
8229
lua_register( pGlobalLua, "sendTelnetChannel102", TLuaInterpreter::sendTelnetChannel102 );
8230
lua_register( pGlobalLua, "setRoomWeight", TLuaInterpreter::setRoomWeight );
8231
lua_register( pGlobalLua, "getRoomWeight", TLuaInterpreter::getRoomWeight );
8232
lua_register( pGlobalLua, "gotoRoom", TLuaInterpreter::gotoRoom );
8233
lua_register( pGlobalLua, "setMapperView", TLuaInterpreter::setMapperView );
8234
lua_register( pGlobalLua, "getRoomExits", TLuaInterpreter::getRoomExits );
8235
lua_register( pGlobalLua, "lockRoom", TLuaInterpreter::lockRoom );
8236
lua_register( pGlobalLua, "createMapper", TLuaInterpreter::createMapper );
8237
lua_register( pGlobalLua, "getMainConsoleWidth", TLuaInterpreter::getMainConsoleWidth );
8238
lua_register( pGlobalLua, "resetProfile", TLuaInterpreter::resetProfile );
8239
lua_register( pGlobalLua, "printCmdLine", TLuaInterpreter::printCmdLine );
8240
lua_register( pGlobalLua, "searchRoom", TLuaInterpreter::searchRoom );
8241
lua_register( pGlobalLua, "clearCmdLine", TLuaInterpreter::clearCmdLine );
8242
lua_register( pGlobalLua, "getAreaTable", TLuaInterpreter::getAreaTable );
8243
lua_register( pGlobalLua, "getAreaRooms", TLuaInterpreter::getAreaRooms );
8244
lua_register( pGlobalLua, "getPath", TLuaInterpreter::getPath );
8245
lua_register( pGlobalLua, "centerview", TLuaInterpreter::centerview );
8246
lua_register( pGlobalLua, "denyCurrentSend", TLuaInterpreter::denyCurrentSend );
8247
lua_register( pGlobalLua, "tempBeginOfLineTrigger", TLuaInterpreter::tempBeginOfLineTrigger );
8248
lua_register( pGlobalLua, "tempExactMatchTrigger", TLuaInterpreter::tempExactMatchTrigger );
8249
lua_register( pGlobalLua, "sendGMCP", TLuaInterpreter::sendGMCP );
8250
lua_register( pGlobalLua, "roomExists", TLuaInterpreter::roomExists );
8251
lua_register( pGlobalLua, "addRoom", TLuaInterpreter::addRoom );
8252
lua_register( pGlobalLua, "setExit", TLuaInterpreter::setExit );
8253
lua_register( pGlobalLua, "setRoomCoordinates", TLuaInterpreter::setRoomCoordinates );
8254
lua_register( pGlobalLua, "getRoomCoordinates", TLuaInterpreter::getRoomCoordinates );
8255
lua_register( pGlobalLua, "createRoomID", TLuaInterpreter::createRoomID );
8256
lua_register( pGlobalLua, "getRoomArea", TLuaInterpreter::getRoomArea );
8257
lua_register( pGlobalLua, "setRoomArea", TLuaInterpreter::setRoomArea );
8258
lua_register( pGlobalLua, "setAreaName", TLuaInterpreter::setAreaName );
8259
lua_register( pGlobalLua, "roomLocked", TLuaInterpreter::roomLocked );
8260
lua_register( pGlobalLua, "setCustomEnvColor", TLuaInterpreter::setCustomEnvColor );
8261
lua_register( pGlobalLua, "getCustomEnvColorTable", TLuaInterpreter::getCustomEnvColorTable );
8262
//lua_register( pGlobalLua, "setLevelColor", TLuaInterpreter::setLevelColor );
8263
//lua_register( pGlobalLua, "getLevelColorTable", TLuaInterpreter::getLevelColorTable );
8264
lua_register( pGlobalLua, "setRoomEnv", TLuaInterpreter::setRoomEnv );
8265
lua_register( pGlobalLua, "setRoomName", TLuaInterpreter::setRoomName );
8266
lua_register( pGlobalLua, "getRoomName", TLuaInterpreter::getRoomName );
8267
lua_register( pGlobalLua, "setGridMode", TLuaInterpreter::setGridMode );
8268
lua_register( pGlobalLua, "solveRoomCollisions", TLuaInterpreter::solveRoomCollisions );
8269
lua_register( pGlobalLua, "addSpecialExit", TLuaInterpreter::addSpecialExit );
8270
lua_register( pGlobalLua, "getSpecialExits", TLuaInterpreter::getSpecialExits );
8271
lua_register( pGlobalLua, "getSpecialExitsSwap", TLuaInterpreter::getSpecialExitsSwap );
8272
lua_register( pGlobalLua, "clearSpecialExits", TLuaInterpreter::clearSpecialExits );
8273
lua_register( pGlobalLua, "getRoomEnv", TLuaInterpreter::getRoomEnv );
8274
lua_register( pGlobalLua, "getRoomUserData", TLuaInterpreter::getRoomUserData );
8275
lua_register( pGlobalLua, "setRoomUserData", TLuaInterpreter::setRoomUserData );
8276
lua_register( pGlobalLua, "getRoomsByPosition", TLuaInterpreter::getRoomsByPosition );
8277
//lua_register( pGlobalLua, "dumpRoomUserData", TLuaInterpreter::dumpRoomUserData );
8278
lua_register( pGlobalLua, "clearRoomUserData", TLuaInterpreter::clearRoomUserData );
8279
lua_register( pGlobalLua, "downloadFile", TLuaInterpreter::downloadFile );
8280
lua_register( pGlobalLua, "appendCmdLine", TLuaInterpreter::appendCmdLine );
8281
lua_register( pGlobalLua, "openUrl", TLuaInterpreter::openUrl );
8282
lua_register( pGlobalLua, "sendSocket", TLuaInterpreter::sendSocket );
8283
lua_register( pGlobalLua, "setRoomIDbyHash", TLuaInterpreter::setRoomIDbyHash );
8284
lua_register( pGlobalLua, "getRoomIDbyHash", TLuaInterpreter::getRoomIDbyHash );
8285
lua_register( pGlobalLua, "addAreaName", TLuaInterpreter::addAreaName );
8286
lua_register( pGlobalLua, "getRoomAreaName", TLuaInterpreter::getRoomAreaName );
8287
lua_register( pGlobalLua, "deleteArea", TLuaInterpreter::deleteArea );
8288
lua_register( pGlobalLua, "deleteRoom", TLuaInterpreter::deleteRoom );
8289
lua_register( pGlobalLua, "setRoomChar", TLuaInterpreter::setRoomChar );
8290
lua_register( pGlobalLua, "registerAnonymousEventHandler", TLuaInterpreter::registerAnonymousEventHandler );
8291
lua_register( pGlobalLua, "saveMap", TLuaInterpreter::saveMap );
8292
lua_register( pGlobalLua, "setMainWindowSize", TLuaInterpreter::setMainWindowSize );
8293
// removed because of various Qt crashes
8294
//lua_register( pGlobalLua, "setAppStyleSheet", TLuaInterpreter::setAppStyleSheet );
8295
lua_register( pGlobalLua, "sendIrc", TLuaInterpreter::sendIrc );
8296
lua_register( pGlobalLua, "connectToServer", TLuaInterpreter::connectToServer );
8297
lua_register( pGlobalLua, "getRooms", TLuaInterpreter::getRooms );
8298
lua_register( pGlobalLua, "createMapLabel", TLuaInterpreter::createMapLabel );
8299
lua_register( pGlobalLua, "deleteMapLabel", TLuaInterpreter::deleteMapLabel );
8300
lua_register( pGlobalLua, "highlightRoom", TLuaInterpreter::highlightRoom );
8301
lua_register( pGlobalLua, "unHighlightRoom", TLuaInterpreter::unHighlightRoom );
8302
lua_register( pGlobalLua, "getMapLabels", TLuaInterpreter::getMapLabels );
8303
lua_register( pGlobalLua, "lockExit", TLuaInterpreter::lockExit );
8304
lua_register( pGlobalLua, "hasExitLock", TLuaInterpreter::hasExitLock );
8305
lua_register( pGlobalLua, "lockSpecialExit", TLuaInterpreter::lockSpecialExit );
8306
lua_register( pGlobalLua, "hasSpecialExitLock", TLuaInterpreter::hasSpecialExitLock );
8308
luaopen_yajl(pGlobalLua);
8309
lua_setglobal( pGlobalLua, "yajl" );
8312
luaopen_zip( pGlobalLua );
8313
lua_setglobal( pGlobalLua, "zip" );
8318
// if using LuaJIT, adjust the cpath to look in /usr/lib as well - it doesn't by default
8319
luaL_dostring (pGlobalLua, "if jit then package.cpath = package.cpath .. ';/usr/lib/lua/5.1/?.so;' end");
8321
error = luaL_dostring( pGlobalLua, "require \"rex_pcre\"" );
8325
string e = "no error message available from Lua";
8326
if( lua_isstring( pGlobalLua, 1 ) )
8329
e+=lua_tostring( pGlobalLua, 1 );
8331
QString msg = "[ ERROR ] cannot find Lua module rex_pcre. Some functions may not be available.";
8332
msg.append( e.c_str() );
8337
QString msg = "[ OK ] - Lua module rex_pcre loaded";
8341
error = luaL_dostring( pGlobalLua, "require \"zip\"" );
8345
string e = "no error message available from Lua";
8346
if( lua_isstring( pGlobalLua, 1 ) )
8349
e+=lua_tostring( pGlobalLua, 1 );
8351
QString msg = "[ ERROR ] cannot find Lua module zip";
8352
msg.append( e.c_str() );
8357
QString msg = "[ OK ] - Lua module zip loaded";
8360
error = luaL_dostring( pGlobalLua, "require \"lfs\"" );
8364
string e = "no error message available from Lua";
8365
if( lua_isstring( pGlobalLua, 1 ) )
8368
e+=lua_tostring( pGlobalLua, 1 );
8370
QString msg = "[ ERROR ] cannot find Lua module lfs (Lua File System).";
8371
msg.append( e.c_str() );
8376
QString msg = "[ OK ] - Lua module lfs loaded";
8380
error = luaL_dostring( pGlobalLua, "require \"luasql.sqlite3\"" );
8384
string e = "no error message available from Lua";
8385
if( lua_isstring( pGlobalLua, 1 ) )
8388
e+=lua_tostring( pGlobalLua, 1 );
8390
QString msg = "[ ERROR ] cannot find Lua module luasql.sqlite3. Database support will not be available.";
8391
msg.append( e.c_str() );
8396
QString msg = "[ OK ] - Lua module sqlite3 loaded";
8400
// QString path = QDir::homePath()+"/.config/mudlet/mudlet-lua/lua/LuaGlobal.lua";
8401
// error = luaL_dofile( pGlobalLua, path.toLatin1().data() );
8404
// string e = "no error message available from Lua";
8405
// if( lua_isstring( pGlobalLua, 1 ) )
8407
// e = "[CRITICAL ERROR] LuaGlobal.lua compile error - please report";
8408
// e += lua_tostring( pGlobalLua, 1 );
8410
// gSysErrors << e.c_str();
8414
// gSysErrors << "[INFO] LuaGlobal.lua loaded successfully.";
8417
/*path = QDir::homePath()+"/.config/mudlet/db.lua";
8418
error = luaL_dofile( pGlobalLua, path.toLatin1().data() );
8421
string e = "no error message available from Lua";
8422
if( lua_isstring( pGlobalLua, 1 ) )
8424
e = "[CRITICAL ERROR] db.lua compile error - please report";
8425
e += lua_tostring( pGlobalLua, 1 );
8427
gSysErrors << e.c_str();
8431
gSysErrors << "[INFO] db.lua loaded successfully.";
8435
QString tn = "atcp";
8437
set_lua_table( tn, args );
8440
set_lua_table( tn, args );
8442
lua_pop( pGlobalLua, lua_gettop( pGlobalLua ) );
8444
//FIXME make function call in destructor lua_close(L);
8447
void TLuaInterpreter::loadGlobal()
8449
//QString path = QDir::homePath()+"/.config/mudlet/mudlet-lua/lua/LuaGlobal.lua";
8451
QString path = "/usr/share/games/mudlet/lua/LuaGlobal.lua";
8452
int error = luaL_dofile( pGlobalLua, path.toLatin1().data() );
8455
string e = "no error message available from Lua";
8456
if( lua_isstring( pGlobalLua, 1 ) )
8458
e = "[ ERROR ] - LuaGlobal.lua compile error - please report!";
8459
e += lua_tostring( pGlobalLua, 1 );
8461
gSysErrors << e.c_str();
8465
gSysErrors << "[ OK ] - mudlet-lua API & Geyser Layout manager loaded.";
8469
void TLuaInterpreter::slotEchoMessage(int hostID, QString msg)
8471
Host * pHost = HostManager::self()->getHostFromHostID( hostID );
8472
mudlet::self()->print( pHost, msg );
8476
void TLuaInterpreter::slotNewCommand(int hostID, QString cmd)
8478
Host * pHost = HostManager::self()->getHostFromHostID( hostID );
8482
void TLuaInterpreter::slotOpenUserWindow(int hostID, QString windowName )
8486
void TLuaInterpreter::slotClearUserWindow(int hostID, QString windowName )
8490
void TLuaInterpreter::slotEnableTimer(int hostID, QString windowName )
8492
Host * pHost = HostManager::self()->getHostFromHostID( hostID );
8493
pHost->enableTimer( windowName );
8496
void TLuaInterpreter::slotDisableTimer(int hostID, QString windowName )
8498
Host * pHost = HostManager::self()->getHostFromHostID( hostID );
8499
pHost->disableTimer( windowName );
8502
void TLuaInterpreter::slotReplace(int hostID, QString text)
8506
void TLuaInterpreter::slotEchoUserWindow(int hostID, QString windowName, QString text )
8510
void TLuaInterpreter::slotTempTimer( int hostID, double timeout, QString function, QString timerName )
8512
Host * pHost = HostManager::self()->getHostFromHostID( hostID );
8513
QTime time(0,0,0,0);
8514
int msec = static_cast<int>(timeout * 1000);
8515
QTime time2 = time.addMSecs( msec );
8517
pT = new TTimer( timerName, time2, pHost );
8518
pT->setName( timerName );
8519
pT->setTime( time2 );
8520
//qDebug()<<"setting time of tempTimer to "<<time2.minute()<<":"<<time2.second()<<":"<<time2.msec()<<" timeout="<<timeout;
8521
pT->setScript( function );
8522
pT->setIsFolder( false );
8523
pT->setIsActive( true );
8524
pT->setIsTempTimer( true );
8525
pT->registerTimer();
8528
int TLuaInterpreter::startPermTimer( QString & name, QString & parent, double timeout, QString & function )
8530
QTime time( 0, 0, 0, 0 );
8531
int msec = static_cast<int>(timeout * 1000);
8532
QTime time2 = time.addMSecs( msec );
8534
if( parent.isEmpty() )
8536
pT = new TTimer( "a", time2, mpHost );
8540
TTimer * pP = mpHost->getTimerUnit()->findTimer( parent );
8543
return -1;//parent not found
8545
pT = new TTimer( pP, mpHost );
8548
pT->setTime( time2 );
8549
pT->setIsFolder( false );
8550
pT->setIsTempTimer( false );
8551
pT->registerTimer();
8552
pT->setScript( function );
8553
int id = pT->getID();
8554
pT->setName( name );//darf erst nach isTempTimer gesetzt werde, damit setName() schneller ist
8555
pT->setIsActive( false );
8556
mpHost->mpEditorDialog->mNeedUpdateData = true;
8560
int TLuaInterpreter::startTempTimer( double timeout, QString & function )
8562
QTime time( 0, 0, 0, 0 );
8563
int msec = static_cast<int>(timeout * 1000);
8564
QTime time2 = time.addMSecs( msec );
8566
pT = new TTimer( "a", time2, mpHost );
8567
pT->setTime( time2 );
8568
pT->setIsFolder( false );
8569
pT->setIsTempTimer( true );
8570
pT->registerTimer();
8571
pT->setScript( function );
8572
int id = pT->getID();
8573
pT->setName( QString::number( id ) );//darf erst nach isTempTimer gesetzt werde, damit setName() schneller ist
8574
pT->setIsActive( true );
8575
pT->enableTimer( id );
8579
int TLuaInterpreter::startPermAlias( QString & name, QString & parent, QString & regex, QString & function )
8583
if( parent.isEmpty() )
8585
pT = new TAlias("a", mpHost );
8589
TAlias * pP = mpHost->getAliasUnit()->findAlias( parent );
8592
return -1;//parent not found
8594
pT = new TAlias( pP, mpHost );
8596
pT->setRegexCode( regex );
8597
pT->setIsFolder( false );
8598
pT->setIsActive( true );
8599
pT->setIsTempAlias( false );
8600
pT->registerAlias();
8601
pT->setScript( function );
8602
int id = pT->getID();
8603
pT->setName( name );
8604
mpHost->mpEditorDialog->mNeedUpdateData = true;
8608
int TLuaInterpreter::startTempAlias( QString & regex, QString & function )
8611
pT = new TAlias("a", mpHost );
8612
pT->setRegexCode( regex );
8613
pT->setIsFolder( false );
8614
pT->setIsActive( true );
8615
pT->setIsTempAlias( true );
8616
pT->registerAlias();
8617
pT->setScript( function );
8618
int id = pT->getID();
8619
pT->setName( QString::number( id ) );
8623
int TLuaInterpreter::startTempExactMatchTrigger( QString & regex, QString & function )
8628
QList<int> propertyList;
8629
propertyList << REGEX_EXACT_MATCH;
8630
pT = new TTrigger("a", sList, propertyList, false, mpHost );
8631
pT->setIsFolder( false );
8632
pT->setIsActive( true );
8633
pT->setIsTempTrigger( true );
8634
pT->registerTrigger();
8635
pT->setScript( function );
8636
int id = pT->getID();
8637
pT->setName( QString::number( id ) );
8641
int TLuaInterpreter::startTempBeginOfLineTrigger( QString & regex, QString & function )
8646
QList<int> propertyList;
8647
propertyList << REGEX_BEGIN_OF_LINE_SUBSTRING;
8648
pT = new TTrigger("a", sList, propertyList, false, mpHost );
8649
pT->setIsFolder( false );
8650
pT->setIsActive( true );
8651
pT->setIsTempTrigger( true );
8652
pT->registerTrigger();
8653
pT->setScript( function );
8654
int id = pT->getID();
8655
pT->setName( QString::number( id ) );
8660
int TLuaInterpreter::startTempTrigger( QString & regex, QString & function )
8665
QList<int> propertyList;
8666
propertyList << REGEX_SUBSTRING;// substring trigger is default
8667
pT = new TTrigger("a", sList, propertyList, false, mpHost );
8668
pT->setIsFolder( false );
8669
pT->setIsActive( true );
8670
pT->setIsTempTrigger( true );
8671
pT->registerTrigger();
8672
pT->setScript( function );
8673
int id = pT->getID();
8674
pT->setName( QString::number( id ) );
8678
int TLuaInterpreter::startTempLineTrigger( int from, int howmany, QString & function )
8681
// QStringList sList;
8682
// QList<int> propertyList;
8683
// propertyList << REGEX_SUBSTRING;// substring trigger is default
8684
// pT = new TTrigger("a", sList, propertyList, false, mpHost );
8685
pT = new TTrigger( 0, mpHost );
8686
pT->setIsFolder( false );
8687
pT->setIsActive( true );
8688
pT->setIsTempTrigger( true );
8689
pT->setIsLineTrigger( true );
8690
pT->setStartOfLineDelta( from );
8691
pT->setLineDelta( howmany );
8692
pT->registerTrigger();
8693
pT->setScript( function );
8694
int id = pT->getID();
8695
pT->setName( QString::number( id ) );
8699
int TLuaInterpreter::startTempColorTrigger( int fg, int bg, QString & function )
8702
// QStringList sList;
8703
// QList<int> propertyList;
8704
// propertyList << REGEX_SUBSTRING;// substring trigger is default
8705
// pT = new TTrigger("a", sList, propertyList, false, mpHost );
8706
pT = new TTrigger( 0, mpHost );
8707
pT->setIsFolder( false );
8708
pT->setIsActive( true );
8709
pT->setIsTempTrigger( true );
8710
pT->setupTmpColorTrigger( fg, bg );
8712
pT->registerTrigger();
8713
pT->setScript( function );
8714
int id = pT->getID();
8715
pT->setName( QString::number( id ) );
8719
int TLuaInterpreter::startTempRegexTrigger( QString & regex, QString & function )
8725
QList<int> propertyList;
8726
propertyList << REGEX_PERL;// substring trigger is default
8727
pT = new TTrigger("a", sList, propertyList, false, mpHost );
8728
pT->setIsFolder( false );
8729
pT->setIsActive( true );
8730
pT->setIsTempTrigger( true );
8731
pT->registerTrigger();
8732
pT->setScript( function );
8733
int id = pT->getID();
8734
pT->setName( QString::number( id ) );
8738
int TLuaInterpreter::startPermRegexTrigger( QString & name, QString & parent, QStringList & regexList, QString & function )
8741
QList<int> propertyList;
8742
for( int i=0; i<regexList.size(); i++ )
8744
propertyList << REGEX_PERL;
8746
if( parent.isEmpty() )
8748
pT = new TTrigger( "a", regexList, propertyList, (regexList.size()>1), mpHost );
8752
TTrigger * pP = mpHost->getTriggerUnit()->findTrigger( parent );
8755
return -1;//parent not found
8757
pT = new TTrigger( pP, mpHost );
8758
pT->setRegexCodeList( regexList, propertyList );
8760
pT->setIsFolder( (regexList.size()==0) );
8761
pT->setIsActive( true );
8762
pT->setIsTempTrigger( false );
8763
pT->registerTrigger();
8764
pT->setScript( function );
8765
pT->setName( name );
8766
mpHost->mpEditorDialog->mNeedUpdateData = true;
8771
int TLuaInterpreter::startPermBeginOfLineStringTrigger( QString & name, QString & parent, QStringList & regexList, QString & function )
8774
QList<int> propertyList;
8775
for( int i=0; i<regexList.size(); i++ )
8777
propertyList << REGEX_BEGIN_OF_LINE_SUBSTRING;
8779
if( parent.isEmpty() )
8781
pT = new TTrigger( "a", regexList, propertyList, (regexList.size()>1), mpHost );
8785
TTrigger * pP = mpHost->getTriggerUnit()->findTrigger( parent );
8788
return -1;//parent not found
8790
pT = new TTrigger( pP, mpHost );
8791
pT->setRegexCodeList( regexList, propertyList );
8793
pT->setIsFolder( (regexList.size()==0) );
8794
pT->setIsActive( true );
8795
pT->setIsTempTrigger( false );
8796
pT->registerTrigger();
8797
pT->setScript( function );
8798
pT->setName( name );
8799
mpHost->mpEditorDialog->mNeedUpdateData = true;
8804
int TLuaInterpreter::startPermSubstringTrigger( QString & name, QString & parent, QStringList & regexList, QString & function )
8807
QList<int> propertyList;
8808
for( int i=0; i<regexList.size(); i++ )
8810
propertyList << REGEX_SUBSTRING;
8812
if( parent.isEmpty() )
8814
pT = new TTrigger( "a", regexList, propertyList, (regexList.size()>1), mpHost );
8818
TTrigger * pP = mpHost->getTriggerUnit()->findTrigger( parent );
8821
return -1;//parent not found
8823
pT = new TTrigger( pP, mpHost );
8824
pT->setRegexCodeList( regexList, propertyList );
8826
pT->setIsFolder( (regexList.size()==0) );
8827
pT->setIsActive( true );
8828
pT->setIsTempTrigger( false );
8829
pT->registerTrigger();
8830
pT->setScript( function );
8831
pT->setName( name );
8832
mpHost->mpEditorDialog->mNeedUpdateData = true;