1 /* 2 * Copyright (c) 2009 Mat Sutcliffe (oktal@gmx.co.uk) 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 18 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 23 * USE OF THIS SOFTWARE EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26 #include "EXTERN.h" 27 #include "perl.h" 28 #include "XSUB.h" 29 30 #include <agar/core.h> 31 #include <agar/gui.h> 32 #include "perl_agar.h" 33 34 MODULE = Agar::Config PACKAGE = Agar::Config PREFIX = AG_ 35 PROTOTYPES: ENABLE 36 VERSIONCHECK: DISABLE 37 38 void 39 lock(self) 40 Agar::Config self 41 CODE: 42 AG_ObjectLock(self); 43 44 void 45 unlock(self) 46 Agar::Config self 47 CODE: 48 AG_ObjectUnlock(self); 49 50 int 51 load(self, path) 52 Agar::Config self 53 const char * path 54 PREINIT: 55 AG_DataSource * ds; 56 CODE: 57 ds = AG_OpenFile(path, "r"); 58 if (ds) { 59 RETVAL = AG_ObjectLoadVariables(self, ds); 60 AG_CloseFile(ds); 61 } else { 62 XSRETURN_UNDEF; 63 } 64 OUTPUT: 65 RETVAL 66 67 int 68 save(self, path) 69 Agar::Config self 70 const char * path 71 PREINIT: 72 AG_DataSource * ds; 73 CODE: 74 ds = AG_OpenFile(path, "w"); 75 if (ds) { 76 RETVAL = 0; 77 AG_PropSave(self, ds); 78 AG_CloseFile(ds); 79 } else { 80 XSRETURN_UNDEF; 81 } 82 OUTPUT: 83 RETVAL 84 85 int 86 getBool(self, name) 87 Agar::Config self 88 const char * name 89 CODE: 90 RETVAL = AG_GetBool(self, name); 91 OUTPUT: 92 RETVAL 93 94 int 95 getInt(self, name) 96 Agar::Config self 97 const char * name 98 CODE: 99 RETVAL = AG_GetInt(self, name); 100 OUTPUT: 101 RETVAL 102 103 Uint 104 getUint(self, name) 105 Agar::Config self 106 const char * name 107 CODE: 108 RETVAL = AG_GetUint(self, name); 109 OUTPUT: 110 RETVAL 111 112 Uint8 113 getUint8(self, name) 114 Agar::Config self 115 const char * name 116 CODE: 117 RETVAL = AG_GetUint8(self, name); 118 OUTPUT: 119 RETVAL 120 121 Sint8 122 getSint8(self, name) 123 Agar::Config self 124 const char * name 125 CODE: 126 RETVAL = AG_GetSint8(self, name); 127 OUTPUT: 128 RETVAL 129 130 Uint16 131 getUint16(self, name) 132 Agar::Config self 133 const char * name 134 CODE: 135 RETVAL = AG_GetUint16(self, name); 136 OUTPUT: 137 RETVAL 138 139 Sint16 140 getSint16(self, name) 141 Agar::Config self 142 const char * name 143 CODE: 144 RETVAL = AG_GetSint16(self, name); 145 OUTPUT: 146 RETVAL 147 148 Uint32 149 getUint32(self, name) 150 Agar::Config self 151 const char * name 152 CODE: 153 RETVAL = AG_GetUint32(self, name); 154 OUTPUT: 155 RETVAL 156 157 Sint32 158 getSint32(self, name) 159 Agar::Config self 160 const char * name 161 CODE: 162 RETVAL = AG_GetSint32(self, name); 163 OUTPUT: 164 RETVAL 165 166 float 167 getFloat(self, name) 168 Agar::Config self 169 const char * name 170 CODE: 171 RETVAL = AG_GetFloat(self, name); 172 OUTPUT: 173 RETVAL 174 175 double 176 getDouble(self, name) 177 Agar::Config self 178 const char * name 179 CODE: 180 RETVAL = AG_GetDouble(self, name); 181 OUTPUT: 182 RETVAL 183 184 SV * 185 getString(self, name) 186 Agar::Config self 187 const char * name 188 PREINIT: 189 char * s; 190 CODE: 191 RETVAL = newSVpv(AG_GetStringDup(self, name), 0); 192 OUTPUT: 193 RETVAL 194 195 void 196 setBool(self, name, val) 197 Agar::Config self 198 const char * name 199 int val 200 CODE: 201 AG_SetBool(self, name, val); 202 203 void 204 setInt(self, name, val) 205 Agar::Config self 206 const char * name 207 int val 208 CODE: 209 AG_SetInt(self, name, val); 210 211 void 212 setUint(self, name, val) 213 Agar::Config self 214 const char * name 215 Uint val 216 CODE: 217 AG_SetUint(self, name, val); 218 219 void 220 setUint8(self, name, val) 221 Agar::Config self 222 const char * name 223 Uint8 val 224 CODE: 225 AG_SetUint8(self, name, val); 226 227 void 228 setSint8(self, name, val) 229 Agar::Config self 230 const char * name 231 Sint8 val 232 CODE: 233 AG_SetSint8(self, name, val); 234 235 void 236 setUint16(self, name, val) 237 Agar::Config self 238 const char * name 239 Uint16 val 240 CODE: 241 AG_SetUint16(self, name, val); 242 243 void 244 setSint16(self, name, val) 245 Agar::Config self 246 const char * name 247 Sint16 val 248 CODE: 249 AG_SetSint16(self, name, val); 250 251 void 252 setUint32(self, name, val) 253 Agar::Config self 254 const char * name 255 Uint32 val 256 CODE: 257 AG_SetUint32(self, name, val); 258 259 void 260 setSint32(self, name, val) 261 Agar::Config self 262 const char * name 263 Sint32 val 264 CODE: 265 AG_SetSint32(self, name, val); 266 267 void 268 setFloat(self, name, val) 269 Agar::Config self 270 const char * name 271 float val 272 CODE: 273 AG_SetFloat(self, name, val); 274 275 void 276 setDouble(self, name, val) 277 Agar::Config self 278 const char * name 279 double val 280 CODE: 281 AG_SetDouble(self, name, val); 282 283 void 284 setString(self, name, val) 285 Agar::Config self 286 const char * name 287 const char * val 288 CODE: 289 AG_SetString(self, name, val); 290 291