summaryrefslogtreecommitdiff
path: root/lib/LuaConfigFile.cc
blob: b8081c4cb6143736f47c11f340dafde93544be78 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*
 *  Baltisot
 *  Copyright (C) 1999-2003 Nicolas "Pixel" Noble
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

/* $Id: LuaConfigFile.cc,v 1.4 2007-05-29 14:27:52 pixel Exp $ */

#include "LuaConfigFile.h"

class LuaConfigSectionContents : public LuaObject {
  public:
    static void pushstatics(Lua *) throw (GeneralException);
      LuaConfigSectionContents(ConfigSectionContents *);
  protected:
    virtual void pushmembers(Lua *);
    ConfigSectionContents * c;
};

LuaConfigFile::LuaConfigFile(ConfigFile * _c) : c(_c) { }

enum ConfigFile_methods_t {
    CONFIGFILE_INDEX = 0,
    CONFIGFILE_NEWINDEX,
};

enum ConfigFile_functions_t {
    CONFIGFILE_NEWCONFIGFILE = 0,
};

struct lua_functypes_t ConfigFile_methods[] = {
    { CONFIGFILE_INDEX,     "index",     1, 1, {LUA_STRING} },
    { CONFIGFILE_NEWINDEX,  "newindex",  1, 1, {LUA_ANY} },
    { -1, 0, 0, 0, 0 }
};

struct lua_functypes_t ConfigFile_functions[] = {
    { CONFIGFILE_NEWCONFIGFILE,   "ConfigFile" ,     1, 1, {LUA_OBJECT } },
    { -1, 0, 0, 0, 0 }
};

class sLua_ConfigFile : public Base {
  public:
    DECLARE_METHOD(ConfigFile, CONFIGFILE_INDEX);
    DECLARE_METHOD(ConfigFile, CONFIGFILE_NEWINDEX);

    DECLARE_FUNCTION(ConfigFile, CONFIGFILE_NEWCONFIGFILE);
  private:
    static int ConfigFile_proceed(Lua * L, int n, ConfigFile * obj, int caller);
    static int ConfigFile_proceed_statics(Lua * L, int n, int caller);
};

void LuaConfigFile::pushmembers(Lua * L) {
    pushme(L, c);

    PUSH_METAMETHOD(ConfigFile, CONFIGFILE_INDEX);
    PUSH_METAMETHOD(ConfigFile, CONFIGFILE_NEWINDEX);
}

void LuaConfigFile::pushstatics(Lua * L) throw (GeneralException) {
    CHECK_METHODS(ConfigFile);
    CHECK_FUNCTIONS(ConfigFile);

    PUSH_FUNCTION(ConfigFile, CONFIGFILE_NEWCONFIGFILE);

    LuaConfigSectionContents::pushstatics(L);
}

int sLua_ConfigFile::ConfigFile_proceed(Lua * L, int n, ConfigFile * c, int caller) {
    String i;

    switch (caller) {
    case CONFIGFILE_INDEX:
        i = L->tostring(2);
        {
            LuaConfigSectionContents csc(&((*c)[i]));
            csc.push(L);
        }
        break;
    case CONFIGFILE_NEWINDEX:
        L->error("ConfigFile is read only.");
        break;
    }

    return 1;
}

int sLua_ConfigFile::ConfigFile_proceed_statics(Lua * L, int n, int caller) {
    Handle * h;

    switch (caller) {
    case CONFIGFILE_NEWCONFIGFILE:
        h = (Handle *) LuaObject::getme(L, 1);
        {
            LuaConfigFile c(new ConfigFile(h));
            c.pushdestruct(L);
        }
        break;
    }

    return 1;
}

LuaConfigSectionContents::LuaConfigSectionContents(ConfigSectionContents * _c) : c(_c) { }

enum ConfigSectionContents_methods_t {
    CONFIGSECTIONCONTENTS_INDEX = 0,
    CONFIGSECTIONCONTENTS_NEWINDEX,
};

struct lua_functypes_t ConfigSectionContents_methods[] = {
    { CONFIGSECTIONCONTENTS_INDEX,     "index",     1, 1, {LUA_STRING} },
    { CONFIGSECTIONCONTENTS_NEWINDEX,  "newindex",  1, 1, {LUA_ANY} },
    { -1, 0, 0, 0, 0 }
};

class sLua_ConfigSectionContents : public Base {
  public:
    DECLARE_METHOD(ConfigSectionContents, CONFIGSECTIONCONTENTS_INDEX);
    DECLARE_METHOD(ConfigSectionContents, CONFIGSECTIONCONTENTS_NEWINDEX);
  private:
    static int ConfigSectionContents_proceed(Lua * L, int n, ConfigSectionContents * obj, int caller);
    static int ConfigSectionContents_proceed_statics(Lua * L, int n, int caller);
};

void LuaConfigSectionContents::pushmembers(Lua * L) {
    pushme(L, c);

    PUSH_METAMETHOD(ConfigSectionContents, CONFIGSECTIONCONTENTS_INDEX);
    PUSH_METAMETHOD(ConfigSectionContents, CONFIGSECTIONCONTENTS_NEWINDEX);
}

void LuaConfigSectionContents::pushstatics(Lua * L) throw (GeneralException) {
    CHECK_METHODS(ConfigSectionContents);
}

int sLua_ConfigSectionContents::ConfigSectionContents_proceed(Lua * L, int n, ConfigSectionContents * c, int caller) {
    String i;

    switch (caller) {
    case CONFIGSECTIONCONTENTS_INDEX:
        i = L->tostring(2);
        L->push((*c)[i]);
        break;
    case CONFIGSECTIONCONTENTS_NEWINDEX:
        L->error("ConfigSectionContents is read only.");
        break;
    }

    return 1;
}