~manky/bmdc++/trunk

« back to all changes in this revision

Viewing changes to Plugins/LuaPlugin/LuaPlugin/ScriptInstance.h

  • Committer: M@niu
  • Date: 2017-12-08 16:42:20 UTC
  • Revision ID: m@niu-20171208164220-co5o2eqljpxnv09q
remove plugins folder . some small fixes

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (C) 2012 Jacek Sieka, arnetheduck on gmail point com
3
 
 *
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.
8
 
 *
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.
13
 
 *
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.
17
 
 */
18
 
 
19
 
#ifndef SCRIPT_INSTANCE_H
20
 
#define SCRIPT_INSTANCE_H
21
 
 
22
 
#include "CriticalSection.h"
23
 
#include <debug.h>
24
 
 
25
 
#include "LuaManager.h"
26
 
 
27
 
using dcpp::CriticalSection;
28
 
using dcpp::Lock;
29
 
 
30
 
using std::string;
31
 
 
32
 
class ScriptInstance {
33
 
        bool MakeCallRaw(const string& table, const string& method, int args, int ret) throw();
34
 
 
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); }
38
 
protected:
39
 
        ScriptInstance() { }
40
 
        virtual ~ScriptInstance() { }
41
 
 
42
 
        template <typename T>
43
 
        bool MakeCall(const string& table, const string& method, int ret, const T& t) throw() {
44
 
                Lock l(cs);
45
 
                LuaPush(t);
46
 
                return MakeCallRaw(table, method, 1, ret);
47
 
        }
48
 
 
49
 
        template <typename T, typename T2>
50
 
        bool MakeCall(const string& table, const string& method, int ret, const T& t, const T2& t2) throw() {
51
 
                Lock l(cs);
52
 
                LuaPush(t);
53
 
                LuaPush(t2);
54
 
                return MakeCallRaw(table, method, 2, ret);
55
 
        }
56
 
 
57
 
        bool CheckFunction(const string& table, const string& method);
58
 
        string GetHubType(HubDataPtr aHub) { return (aHub->protocol == PROTOCOL_ADC ? "adch" : "nmdch"); }
59
 
        Bool GetLuaBool();
60
 
 
61
 
        static lua_State* L;
62
 
        static CriticalSection cs;
63
 
public:
64
 
        static void EvaluateChunk(const string& chunk);
65
 
        static void EvaluateFile(const string& fn);
66
 
};
67
 
 
68
 
#endif // SCRIPT_INSTANCE_H