Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

options-script.cpp

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004 Ivo Danihelka (ivo@danihelka.net)
00003  *
00004  * This program is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation; either version 2 of the License, or
00007  * (at your option) any later version.
00008  */
00009 #include "options-script.h"
00010 
00011 #include "OptionAgent.h"
00012 #include "MessagerAgent.h"
00013 #include "StringMsg.h"
00014 #include "IntMsg.h"
00015 #include "SimpleMsg.h"
00016 #include "def-script.h"
00017 
00018 
00019 //-----------------------------------------------------------------
00020 /**
00021  * void sendMsg(listener, msg, [value])
00022  */
00023     int
00024 script_options_sendMsg(lua_State *L) throw()
00025 {
00026     BEGIN_NOEXCEPTION;
00027     BaseMsg *message = NULL;
00028     const char *listener = luaL_checkstring(L, 1);
00029     const char *msg = luaL_checkstring(L, 2);
00030     if (lua_isstring(L, 3)) {
00031         const char *string_value = luaL_checkstring(L, 3);
00032         message = new StringMsg(listener, msg, string_value);
00033     }
00034     else if (lua_isnumber(L, 3)) {
00035         int int_value = luaL_checkint(L, 3);
00036         message = new IntMsg(listener, msg, int_value);
00037     }
00038     else {
00039         message = new SimpleMsg(listener, msg);
00040     }
00041 
00042     MessagerAgent::agent()->forwardNewMsg(message);
00043 
00044     END_NOEXCEPTION;
00045     return 0;
00046 }
00047 //-----------------------------------------------------------------
00048 /**
00049  * void setParam(name, value)
00050  */
00051     int
00052 script_options_setParam(lua_State *L) throw()
00053 {
00054     BEGIN_NOEXCEPTION;
00055     const char *name = luaL_checkstring(L, 1);
00056     const char *value = lua_tostring(L, 2);
00057     if (!value) {
00058         value = luaL_checkstring(L, 2);
00059     }
00060     OptionAgent::agent()->setParam(name, value);
00061     END_NOEXCEPTION;
00062     return 0;
00063 }
00064 //-----------------------------------------------------------------
00065 /**
00066  * string getParam(name)
00067  * Returns string or nil.
00068  */
00069     int
00070 script_options_getParam(lua_State *L) throw()
00071 {
00072     BEGIN_NOEXCEPTION;
00073     const char *name = luaL_checkstring(L, 1);
00074     std::string value = OptionAgent::agent()->getParam(name);
00075     if (value.empty()) {
00076         lua_pushnil(L);
00077     }
00078     else {
00079         lua_pushlstring(L, value.c_str(), value.size());
00080     }
00081     END_NOEXCEPTION;
00082     //NOTE: return value
00083     return 1;
00084 }
00085 

Generated on Wed Jun 1 09:54:31 2005 for Fish Fillets - Next Generation by  doxygen 1.4.2