Use lua_pushliteral and lua_setfield
authorMyhailo Danylenko <isbear@ukrpost.net>
Mon, 27 Apr 2009 13:15:23 +0300
changeset 19 d775d7289fe4
parent 18 6effa1929af7
child 20 0ce7093df25f
Use lua_pushliteral and lua_setfield
lm.c
lm_connection.c
lm_message.c
lm_message_handler.c
lm_message_node.c
lm_proxy.c
lm_ssl.c
lm_types.c
--- a/lm.c	Sun Apr 05 16:55:48 2009 +0300
+++ b/lm.c	Mon Apr 27 13:15:23 2009 +0300
@@ -22,34 +22,26 @@
 int luaopen_loudmouth (lua_State *L)
 {
 	lua_pushliteral (L, LLM_OBJREGISTRY); // 1 registry key
-	lua_newtable (L);                    // 2 registry value (table)
-	lua_createtable (L, 0, 1);           // 3 metatable
-	lua_pushliteral (L, "__mode");        // 4 metatable key
-	lua_pushliteral (L, "v");             // 5 metatable value
-	lua_settable (L, -3);                // 3 metatable
-	lua_setmetatable (L, -2);            // 2 registry value
-	lua_rawset (L, LUA_REGISTRYINDEX);   // 0
+	lua_newtable (L);                     // 2 registry value (table)
+	lua_createtable (L, 0, 1);            // 3 metatable
+	lua_pushliteral (L, "v");             // 4 metatable value
+	lua_setfield (L, -2, "__mode");       // 3 metatable
+	lua_setmetatable (L, -2);             // 2 registry value
+	lua_rawset (L, LUA_REGISTRYINDEX);    // 0
 	
 	lua_createtable (L, 6, 0);
-
-	lua_pushliteral (L, "message_node");
 	luaopen_lm_message_node (L);
-	lua_settable (L, -3);
-	lua_pushliteral (L, "message");
+	lua_setfield (L, -2, "message_node");
 	luaopen_lm_message (L);
-	lua_settable (L, -3);
-	lua_pushliteral (L, "message_handler");
+	lua_setfield (L, -2, "message");
 	luaopen_lm_message_handler (L);
-	lua_settable (L, -3);
-	lua_pushliteral (L, "proxy");
+	lua_setfield (L, -2, "message_handler");
 	luaopen_lm_proxy (L);
-	lua_settable (L, -3);
-	lua_pushliteral (L, "ssl");
+	lua_setfield (L, -2, "proxy");
 	luaopen_lm_ssl (L);
-	lua_settable (L, -3);
-	lua_pushliteral (L, "connection");
+	lua_setfield (L, -2, "ssl");
 	luaopen_lm_connection (L);
-	lua_settable (L, -3);
+	lua_setfield (L, -2, "connection");
 
 	return 1;
 }
--- a/lm_connection.c	Sun Apr 05 16:55:48 2009 +0300
+++ b/lm_connection.c	Mon Apr 27 13:15:23 2009 +0300
@@ -229,7 +229,7 @@
 #else
 		W ("Sorry, your loudmouth have no get_keep_alive_rate ()");
 		lua_pushnil (L);
-		lua_pushstring (L, "Sorry, your loudmouth have no get_keep_alive_rate ()");
+		lua_pushliteral (L, "Sorry, your loudmouth have no get_keep_alive_rate ()");
 		return 2;
 #endif
 	}
@@ -556,9 +556,8 @@
 int luaopen_lm_connection (lua_State *L)
 {
 	luaL_newmetatable (L, "loudmouth.connection");
-	lua_pushstring (L, "__index");
-	lua_pushvalue (L, -2);
-	lua_settable (L, -3);
+	lua_pushvalue (L, -1);
+	lua_setfield (L, -2, "__index");
 	luaL_register (L, NULL, reg_m_lm_connection);
 	lua_pop (L, 1);
 	lua_newtable (L); // XXX we can specify here exact amount of fields
--- a/lm_message.c	Sun Apr 05 16:55:48 2009 +0300
+++ b/lm_message.c	Mon Apr 27 13:15:23 2009 +0300
@@ -280,9 +280,8 @@
 int luaopen_lm_message (lua_State *L)
 {
 	luaL_newmetatable (L, "loudmouth.message");
-	lua_pushstring (L, "__index");
-	lua_pushvalue (L, -2);
-	lua_settable (L, -3);
+	lua_pushvalue (L, -1);
+	lua_setfield (L, -2, "__index");
 	luaL_register (L, NULL, reg_m_lm_message);
 	lua_pop (L, 1);
 	lua_newtable (L); // XXX we can specify here exact amount of fields
--- a/lm_message_handler.c	Sun Apr 05 16:55:48 2009 +0300
+++ b/lm_message_handler.c	Mon Apr 27 13:15:23 2009 +0300
@@ -127,9 +127,8 @@
 int luaopen_lm_message_handler (lua_State *L)
 {
 	luaL_newmetatable (L, "loudmouth.message_handler");
-	lua_pushstring (L, "__index");
-	lua_pushvalue (L, -2);
-	lua_settable (L, -3);
+	lua_pushvalue (L, -1);
+	lua_setfield (L, -2, "__index");
 	luaL_register (L, NULL, reg_m_lm_handler);
 	lua_pop (L, 1);
 	lua_newtable (L); // XXX we can specify here exact amount of fields
--- a/lm_message_node.c	Sun Apr 05 16:55:48 2009 +0300
+++ b/lm_message_node.c	Mon Apr 27 13:15:23 2009 +0300
@@ -245,9 +245,8 @@
 int luaopen_lm_message_node (lua_State *L)
 {
 	luaL_newmetatable (L, "loudmouth.message_node");
-	lua_pushstring (L, "__index");
-	lua_pushvalue (L, -2);
-	lua_settable (L, -3);
+	lua_pushvalue (L, -1);
+	lua_setfield (L, -2, "__index");
 	luaL_register (L, NULL, reg_m_lm_node);
 	lua_pop (L, 1);
 	lua_newtable (L); // XXX we can specify here exact amount of fields
--- a/lm_proxy.c	Sun Apr 05 16:55:48 2009 +0300
+++ b/lm_proxy.c	Mon Apr 27 13:15:23 2009 +0300
@@ -165,9 +165,8 @@
 int luaopen_lm_proxy (lua_State *L)
 {
 	luaL_newmetatable (L, "loudmouth.proxy");
-	lua_pushstring (L, "__index");
-	lua_pushvalue (L, -2);
-	lua_settable (L, -3);
+	lua_pushvalue (L, -1);
+	lua_setfield (L, -2, "__index");
 	luaL_register (L, NULL, reg_m_lm_proxy);
 	lua_pop (L, 1);
 	lua_newtable (L); // XXX we can specify here exact amount of fields
--- a/lm_ssl.c	Sun Apr 05 16:55:48 2009 +0300
+++ b/lm_ssl.c	Mon Apr 27 13:15:23 2009 +0300
@@ -186,9 +186,8 @@
 int luaopen_lm_ssl (lua_State *L)
 {
 	luaL_newmetatable (L, "loudmouth.ssl");
-	lua_pushstring (L, "__index");
-	lua_pushvalue (L, -2);
-	lua_settable (L, -3);
+	lua_pushvalue (L, -1);
+	lua_setfield (L, -2, "__index");
 	luaL_register (L, NULL, reg_m_lm_ssl);
 	lua_pop (L, 1);
 	lua_newtable (L); // XXX we can specify here exact amount of fields
--- a/lm_types.c	Sun Apr 05 16:55:48 2009 +0300
+++ b/lm_types.c	Mon Apr 27 13:15:23 2009 +0300
@@ -26,7 +26,7 @@
 llm_##WHAT##_t *bless_lm_##WHAT (lua_State *L, TYPE *WHAT)                      \
 {                                                                               \
 	llm_##WHAT##_t *object;                              /* top of stack */ \
-	lua_pushstring (L, LLM_OBJREGISTRY);       /* 1 registry table name  */ \
+	lua_pushliteral (L, LLM_OBJREGISTRY);      /* 1 registry table name  */ \
 	lua_rawget (L, LUA_REGISTRYINDEX);               /* 1 registry table */ \
 	lua_pushlightuserdata (L, WHAT);                 /* 2 light userdata */ \
 	lua_rawget (L, -2);                                  /* 2 object/nil */ \