lua: Change timer() argument to float v0.0.6
authorMyhailo Danylenko <isbear@ukrpost.net>
Sat, 30 Jul 2016 05:04:35 +0300
changeset 153 8fba61f363a8
parent 152 0cf6c938ac03
child 154 e63030a181f0
lua: Change timer() argument to float
CMakeLists.txt
docs/api.mdwn
lua.c
--- a/CMakeLists.txt	Mon Mar 21 02:04:02 2016 +0200
+++ b/CMakeLists.txt	Sat Jul 30 05:04:35 2016 +0300
@@ -16,7 +16,7 @@
 
 cmake_minimum_required(VERSION 2.6)
 project(lua C)
-set(PROJECT_VERSION "0.0.5")
+set(PROJECT_VERSION "0.0.6")
 
 ## User options
 option(DEBUG                 "Enable debugging output"                                                           ON)
@@ -24,10 +24,10 @@
 option(LLM_CONNECTION_ENABLE "Enable exposing of mcabber loudmouth connection to lua"                            ON)
 option(LLM_LOG_HANDLER       "Enable registration of log messages handler for lua-loudmouth library's messages"  ON)
 option(COMPAT_0_0_4          "Provide global 'main' as alias to 'mcabber' for compatibility with v0.0.4"         ON)
-set(ML_SOURCE_PRIORITY G_PRIORITY_HIGH_IDLE CACHE STRING "Glib event source priority for timeout and bgread")
-set(ML_BGREAD_BUFFER   4096                 CACHE STRING "Background pipe reading buffer size")
-set(OPT_MLUA_RC        "lua_init_filename"  CACHE STRING "Mcabber option name to specify lua initialization file")
-set(OPT_MLUA_LM_DEBUG  "lua_lm_debug"       CACHE STRING "Mcabber option name to enable/disable lua logging of LM messages")
+set(ML_SOURCE_PRIORITY G_PRIORITY_DEFAULT_IDLE CACHE STRING "Glib event source priority for timeout and bgread")
+set(ML_BGREAD_BUFFER   4096                    CACHE STRING "Background pipe reading buffer size")
+set(OPT_MLUA_RC        "lua_init_filename"     CACHE STRING "Mcabber option name to specify lua initialization file")
+set(OPT_MLUA_LM_DEBUG  "lua_lm_debug"          CACHE STRING "Mcabber option name to enable/disable lua logging of LM messages")
 set(WANT_LUA           "AUTO" CACHE STRING "Lua version to use (You'll have to define this with -DWANT_LUA=LUAX.X)")
 set_property(CACHE WANT_LUA PROPERTY STRINGS "AUTO" "LUA5.1" "LUA5.2" "LUA5.3")
 
--- a/docs/api.mdwn	Mon Mar 21 02:04:02 2016 +0200
+++ b/docs/api.mdwn	Sat Jul 30 05:04:35 2016 +0300
@@ -259,7 +259,7 @@
 <a name="mcabber.timer"></a>
 ### mcabber.timer
 Creates new [timer function](#timer.function), that will be called periodically.  
-**Arguments:** integer (interval, seconds), [timer function](#timer.function)  
+**Arguments:** float (interval, seconds), [timer function](#timer.function)  
 
 <a name="background.reading.function"></a>
 ### background reading function
--- a/lua.c	Mon Mar 21 02:04:02 2016 +0200
+++ b/lua.c	Sat Jul 30 05:04:35 2016 +0300
@@ -1210,10 +1210,10 @@
 
 /// mcabber.timer
 /// Creates new timer function, that will be called periodically.
-/// A: integer (interval, seconds), timer function
+/// A: float (interval, seconds), timer function
 static int lua_main_timer (lua_State *L)
 {
-	int                   interval = luaL_checkinteger (L, 1);
+	lua_Number            interval = luaL_checknumber (L, 1);
 	guint                 source;
 	lua_timer_callback_t *cb;
 	luaL_argcheck (L, lua_isfunction (L, 2), 2, "function expected");
@@ -1222,7 +1222,11 @@
 	cb->reference = luaL_ref (L, LUA_REGISTRYINDEX);
 	cb->L         = L;
 
-	source = g_timeout_add_seconds_full (MLUA_SOURCE_PRIORITY, interval, (GSourceFunc) lua_timer_callback, cb, (GDestroyNotify) lua_timer_callback_destroy);
+	source = g_timeout_add_full (MLUA_SOURCE_PRIORITY,
+	                             (guint) ( interval*1000 ),
+	                             (GSourceFunc) lua_timer_callback,
+				     cb,
+				     (GDestroyNotify) lua_timer_callback_destroy);
 	cb->source = source;
 	lua_timers = g_slist_prepend (lua_timers, (gpointer) ((gsize) source));