--- a/lm_proxy.c Mon Feb 16 01:32:12 2009 +0200
+++ b/lm_proxy.c Fri Feb 20 23:07:43 2009 +0200
@@ -4,6 +4,7 @@
#include <glib.h>
#include <loudmouth/loudmouth.h>
+#include "config.h"
#include "util.h"
#include "lm_types.h"
@@ -30,15 +31,13 @@
{
int type = luaL_checkenum (L, 1, llm_proxy_type);
LmProxy *proxy;
- if (lua_gettop (L) > 0) {
+ if (lua_gettop (L) > 0)
proxy = lm_proxy_new_with_server (type, luaL_checkstring (L, 2), luaL_checkint (L, 3));
- lua_pop (L, 3);
- } else {
+ else
proxy = lm_proxy_new (type);
- lua_pop (L, 1);
- }
llm_proxy_bless (L, proxy);
lm_proxy_unref (proxy); // XXX
+ D ("Proxy %X created", (int) proxy);
return 1;
}
@@ -50,98 +49,82 @@
{
luaL_argcheck (L, lua_islightuserdata (L, 1), 1, "lm proxy lightuserdata expected");
llm_proxy_bless (L, lua_touserdata (L, 1));
- lua_remove (L, -2);
return 1;
}
/// proxy:type
/// Gets or sets proxy server type.
/// A: proxy type (optional)
-/// R: proxy type (when called with no args)
+/// R: proxy type (when called with no args) or lm proxy object
static int llm_proxy_kind (lua_State *L)
{
llm_proxy_t *proxy = luaL_checklm_proxy (L, 1);
if (lua_gettop (L) > 1) { // Set
lm_proxy_set_type (proxy->proxy, luaL_checkenum (L, 2, llm_proxy_type));
- lua_pop (L, 2);
- return 0;
- } else { // Get
+ lua_pop (L, 1);
+ } else // Get
luaL_pushenum (L, lm_proxy_get_type (proxy->proxy), llm_proxy_type);
- lua_remove (L, -2);
- return 1;
- }
+ return 1;
}
/// proxy:server
/// Gets or sets proxy server name.
/// A: string (optional)
-/// R: string (when called with no args)
+/// R: string (when called with no args) or lm proxy object
static int llm_proxy_server (lua_State *L)
{
llm_proxy_t *object = luaL_checklm_proxy (L, 1);
if (lua_gettop (L) > 1) { // Set
lm_proxy_set_server (object->proxy, luaL_checkstring (L, 2));
- lua_pop (L, 2);
- return 0;
- } else { // Get
+ lua_pop (L, 1);
+ } else // Get
lua_pushstring (L, lm_proxy_get_server (object->proxy));
- lua_remove (L, -2);
- return 1;
- }
+ return 1;
}
/// proxy:port
/// Gets or sets proxy server port.
/// A: integer (optional)
-/// R: integer (when called with no args)
+/// R: integer (when called with no args) or lm proxy object
static int llm_proxy_port (lua_State *L)
{
llm_proxy_t *object = luaL_checklm_proxy (L, 1);
if (lua_gettop (L) > 1) { // Set
lm_proxy_set_port (object->proxy, luaL_checkint (L, 2));
- lua_pop (L, 2);
- return 0;
- } else { // Get
+ lua_pop (L, 1);
+ } else // Get
lua_pushnumber (L, lm_proxy_get_port (object->proxy));
- lua_remove (L, -2);
- return 1;
- }
+ return 1;
}
/// proxy:username
/// Gets or sets username to authenticate to proxy server with.
/// A: string (optional)
-/// R: string (when called with no args)
+/// R: string (when called with no args) or lm proxy object
static int llm_proxy_username (lua_State *L)
{
llm_proxy_t *object = luaL_checklm_proxy (L, 1);
if (lua_gettop (L) > 1) { // Set
lm_proxy_set_username (object->proxy, luaL_checkstring (L, 2));
- lua_pop (L, 2);
- return 0;
- } else { // Get
+ lua_pop (L, 1);
+ } else // Get
lua_pushstring (L, lm_proxy_get_username (object->proxy));
- lua_remove (L, -2);
- return 1;
- }
+ return 1;
}
/// proxy:password
/// Gets or sets password to authenticate to proxy server with.
/// A: string (optional)
-/// R: string (when called with no args)
+/// R: string (when called with no args) or lm proxy object
static int llm_proxy_password (lua_State *L)
{
llm_proxy_t *object = luaL_checklm_proxy (L, 1);
if (lua_gettop (L) > 1) { // Set
lm_proxy_set_password (object->proxy, luaL_checkstring (L, 2));
- lua_pop (L, 2);
- return 0;
- } else { // Get
+ lua_pop (L, 1);
+ } else // Get
lua_pushstring (L, lm_proxy_get_password (object->proxy));
- lua_remove (L, -2);
- return 1;
- }
+ return 1;
}
/// proxy:pointer
@@ -151,15 +134,14 @@
{
llm_proxy_t *object = luaL_checklm_proxy (L, 1);
lua_pushlightuserdata (L, object->proxy);
- lua_remove (L, -2);
return 1;
}
static int llm_proxy_gc (lua_State *L)
{
llm_proxy_t *object = luaL_checklm_proxy (L, 1);
+ D ("Proxy %X gc called", (int) object);
lm_proxy_unref (object->proxy);
- lua_pop (L, 1);
return 0;
}