00001
00002
00003
00004
00005
00006
00007
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
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
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
00067
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
00083 return 1;
00084 }
00085