2
* Copyright (C) 2012 Jacek Sieka, arnetheduck on gmail point com
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
#ifndef SCRIPT_INSTANCE_H
20
#define SCRIPT_INSTANCE_H
22
#include "CriticalSection.h"
25
#include "LuaManager.h"
27
using dcpp::CriticalSection;
32
class ScriptInstance {
33
bool MakeCallRaw(const string& table, const string& method, int args, int ret) throw();
35
void LuaPush(int i) { lua_pushnumber(L, i); }
36
void LuaPush(const string& s) { lua_pushlstring(L, s.data(), s.size()); }
37
void LuaPush(void* p) { lua_pushlightuserdata(L, p); }
40
virtual ~ScriptInstance() { }
43
bool MakeCall(const string& table, const string& method, int ret, const T& t) throw() {
46
return MakeCallRaw(table, method, 1, ret);
49
template <typename T, typename T2>
50
bool MakeCall(const string& table, const string& method, int ret, const T& t, const T2& t2) throw() {
54
return MakeCallRaw(table, method, 2, ret);
57
bool CheckFunction(const string& table, const string& method);
58
string GetHubType(HubDataPtr aHub) { return (aHub->protocol == PROTOCOL_ADC ? "adch" : "nmdch"); }
62
static CriticalSection cs;
64
static void EvaluateChunk(const string& chunk);
65
static void EvaluateFile(const string& fn);
68
#endif // SCRIPT_INSTANCE_H