free counters
Diberdayakan oleh Blogger.
Tampilkan postingan dengan label lua. Tampilkan semua postingan
Tampilkan postingan dengan label lua. Tampilkan semua postingan

Senin, 10 Maret 2014

Completing Interactive Conky Button For Clementine

by Unknown  |  in pemrograman at  Senin, Maret 10, 2014
Finally, after trying for a couples of day to create control button for clementine and learning some basic programming in lua, yesterday I've finished it.

Here the show:



Download the full package of conky and necessary file in zip here.

There are 4 important files in the zip:
1. conkyrc; conky file configuration
2. button_script.lua; script for interactive button. We don't need to change this.
3. clementine_controller.lua; Controller for clementine.
4. my_button.lua; This is file where we define our clementine button.


When trying to use these conky, please remember to change these file:
1. conkyrc
    Change path in line:
    lua_load /home/rio/joie_conky/button_script.lua
    to your script path.
2. button_script.lua
    change path in line:
    dofile("/home/rio/joie_conky/my_button.lua")
    to your script path.
3. my_button.lua
    change path in line:
    dofile("/home/rio/joie_conky/clementine_controller.lua")
    to your script path.

Don't forget to add conky autostart in your system.

Kudos to mrpeachy for his interactive button.


Happy Programming...:D ;)

How to include function in lua file from another lua file

by Unknown  |  in pemrograman at  Senin, Maret 10, 2014
Detail of lua can be read here

There  are 2 ways to include function from lua file to another lua file.
To explain the ways, we will use this schema:
 there must be at least 2 file, here we use
 1. caller.lua  ; lua file from where we call other file function.
 2. called.lua ; file where called function reside.

here the code for caller.lua:

function main()
   print("main called")
end

main()


Here the code for called.lua:
function called()
   print("i am called")
end


The Ways
A. First way, Using require
By using require, our called file must be resided in the same path with the caller file. If the called file not in the same path, lua will throwing some error. If we want the called file work, we must place the called file in lua library path. There is nothing needed to change in called.lua. We only need to change called.lua.

Here the code for caller.lua
require "called"
function main()
   print("main")
   called()
end


B. Second way, Using dofile
dofile working like require with exception that we need to use the full path of the called file. The benefit of using loadfile is we can call called file from another directory of the caller file. There is nothing needed to change in called.lua. We only need to change called.lua.

Here the code for caller.lua
require "PATH_OF_CALLED_FILE/called.lua"
function main()
   print("main")
   called()
end

PATH_OF_CALLED_FILE is the path of the called.lua


For detail of using require and dofile, please with http://www.lua.org/