Edje LUA scripting
Introduction
Lua scripts are declared in edc files with the lua_script keyword. Like this:
group { name: "mygroup"; lua_script { print("LUA: on-load script"); } parts { ... } programs { program { signal: "a_signal"; source: "a_part"; lua_script { print("LUA: 'mouse,down,1' on 'button'"); } } } }
Inside a lua_script code block, there's a reference to your edje Group named ed, which you may use for accessing your parts (e.g. a part named "label" is accessed through ed.label). This is the main object that is used to access every parts and is also used to create Timer, poller and animator; to emit signal, send messagges, run/stop programs and more. Look at the Group class to see all the methods and properties.
Some object attributes return a table of values, the Object attribute geometry for example return a table of 4 values (x,y,w,h). This tables don't have named index thus you can access the fields only using: geometry[1] for the x value. NOTE that you can NOT use gemetry.x or .geometry["x"]. But you can use the lua unpack function in this way:
x, y, w, h = unpack(ed.part_name.geometry) print("geometry: ", x, y, w, h) // the same for state names: state, val = unpack(ed.part_name.state) print("state: ", state, val) // and for setting tables attributes: custom.color = { 255, 255, 255, 255 } ed.part_name.state = { 'custom', 0.0 }
Classes hierarchy:
References:
- For general LUA documentations look at the official LUA manual (http://www.lua.org/manual/5.1/)
- The lua-users wiki is also full of lua info (http://lua-users.org/wiki/)
- Examples of edc files that use LUA can be found in the doc/examples folder in the edje sources.
Lua snippets:
// print one or more values in console in a tabbed way or using printf style print("something to say", val1, val2) s = string.format("%d %d", 3, 4) print(s) // string concat print("string1" .. "string2" .. val1) // var to string tostring(var) // Print the type of a variable print(type(var))
The timer class is a wrapper around ecore_timer. You can create a timer using the timer(secs,callback) method of the Group class. The callback function will be called every secs seconds until it will return CALLBACK_RENEW. If CALLBACK_CANCEL is returned the timer will stop.
Example:
lua_script { function timer_cb() print("timer_cb") return CALLBACK_RENEW end timer = ed:timer(0.5, timer_cb) }
A more detailed example can be found in doc/examples/lua_timer.edc
See also: Ecore Timer Docs
- Timer.pending
- Timer.precision
- Timer.interval
- Timer.interval
- Timer:del()
- Timer:freeze()
- Timer:thaw()
- Timer:delay(secs)
The animator class is a wrapper around ecore_animator. Animator are used the same way as Timer.
- Animator.frametime
- Animator:del()
The poller class is a wrapper around ecore_poller.
- Poller.interval
- Poller:del()
This is the base class, many other classes are children of this.
You can attach event callbacks to this class using a classic c approach:
function mouse_move_cb(self, ...)
print("mouse_move", ...)
end
rect = ed:rectangle()
rect.mouse_events = true
rect.mouse_move = mouse_move_cb
or you can also do the same in a more lua-fashion style
rect = ed:rectangle { mouse_events = true, mouse_move = function (self, ...) print ('mouse_move', ...) end }
See also: Evas Object Docs
- Object:del()
- Object:show()
- Object:hide()
- Object:move(x, y)
- Object:resize(w, h)
- Object:raise()
- Object:lower()
- Object:stack_above()
- Object:stack_below()
- Object:clip_unset()
- Object.name
- Object.geometry: (x, y, width, height)
- Object.type: object type (RECT=1, TEXT, IMAGE, SWALLOW, TEXTBLOCK, GRADIENT, GROUP, BOX, TABLE, EXTERNAL)
- Object.layer
- Object.above
- Object.below
- Object.size_hint_min: (w,h)
- Object.size_hint_max: (w,h)
- Object.size_hint_request: (w,h)
- Object.size_hint_aspect: (aspect, w, h)
- Object.size_hint_align: (w,h)
- Object.size_hint_weight: (w,h)
- Object.size_hint_padding: (l,r,t,b)
- Object.visible
- Object.render_op
- Object.anti_alias
- Object.scale
- Object.color: (r, g, b, alpha)
- Object.color_interpolation
- Object.clip
- Object.clipees
- Object.evas (not implemeted, always return nil)
- Object.pass_events
- Object.repeat_events
- Object.propagate_events
- Object.focus
- Object.pointer_mode
- Object.precise_is_inside
- Object.mouse_events
- Object.name
- Object.layer
- Object.size_hint_min: (w,h)
- Object.size_hint_max: (w,h)
- Object.size_hint_request: (w,h)
- Object.size_hint_aspect: (w,h)
- Object.size_hint_align: (w,h)
- Object.size_hint_weight: (w,h)
- Object.size_hint_padding: (l,r,t,b)
- Object.render_op
- Object.anti_alias
- Object.scale
- Object.color: (r, g, b, alpha)
- Object.color_interpolation
- Object.clip
- Object.pass_events
- Object.repeat_events
- Object.propagate_events
- Object.focus
- Object.pointer_mode
- Object.precise_is_inside
- Object.mouse_events
- Object.mouse_in: func(self,output_x,output_y,canvas_x,canvas_y)
- Object.mouse_out: func(self,output_x,output_y,canvas_x,canvas_y)
- Object.mouse_down: func(self,button,output_x,output_y,canvas_x,canvas_y)
- Object.mouse_up: func(self,button,output_x,output_y,canvas_x,canvas_y)
- Object.mouse_move: func(self,buttons,output_x,output_y,canvas_x,canvas_y)
- Object.mouse_wheel: func(self,z,output_x,output_y,canvas_x,canvas_y)
See also: Evas Object Image Docs
- Image.size: (w,h)
- Image.file
- Image.fill: (x,y,w,h)
- Image.fill_transform
- Image.alpha
See also: Evas Object Line Docs
- Line.xy: (x1,y1,x2,y2)
- Line.xy: (x1,y1,x2,y2)
See also: Evas Object Polygon Docs
- Polygon:point_add(x,y)
- Polygon:points_clear()
See also: Evas Object Table Docs
- Table.homogeneous
- Table.padding: (horiz,vert)
- Table.align: (horiz,vert)
- Table.col_row_size: (cols,rows)
- Table.children
- Table.homogeneous
- Table.padding: (horiz,vert)
- Table.align: (horiz,vert)
- Table.pack(child,col,row,colspan,rowspan)
- Table.unpack(child)
- Table.clear(clear)
- Description.alignment: (x,y)
- Description.min: (w,h)
- Description.max: (w,h)
- Description.step: (w,h)
- Description.aspect: (x,y)
- Description.aspect_pref
- Description.color: (r,g,b,a)
- Description.color2: (r,g,b,a)
- Description.color3: (r,g,b,a)
- Description.color_class
- Description.rel1: (x,y)
- Description.rel1_to: (to_x,to_y)
- Description.rel1_offset: (x,y)
- Description.rel2: (x,y)
- Description.rel2_to: (to_x,to_y)
- Description.rel2_offset: (x,y)
- Description.image (not yet implemented)
- Description.border: (l,r,t,b)
- Description.fill_smooth
- Description.fill_pos: (rel_x,rel_y,offset_x,offset_y)
- Description.fill_size: (rel_x,rel_y,offset_x,offset_y)
- Description.text
- Description.text_class
- Description.text_font
- Description.text_style
- Description.text_size
- Description.text_fit: (x,y)
- Description.text_min: (x,y)
- Description.text_max: (x,y)
- Description.text_align: (x,y)
- Description.visible
- Description.alignment: (x,y)
- Description.min: (w,h)
- Description.max: (w,h)
- Description.step: (w,h)
- Description.aspect: (x,y)
- Description.aspect_pref
- Description.color: (r,g,b,a)
- Description.color2: (r,g,b,a)
- Description.color3: (r,g,b,a)
- Description.color_class
- Description.rel1: (x,y)
- Description.rel1_to: (to_x,to_y)
- Description.rel1_offset: (x,y)
- Description.rel2: (x,y)
- Description.rel2_to: (to_x,to_y)
- Description.rel2_offset: (x,y)
- Description.image
- Description.border: (l,r,t,b)
- Description.fill_smooth
- Description.fill_pos: (rel_x,rel_y,offset_x,offset_y)
- Description.fill_size: (rel_x,rel_y,offset_x,offset_y)
- Description.text
- Description.text_class
- Description.text_font
- Description.text_style
- Description.text_size
- Description.text_fit: (x,y)
- Description.text_min: (x,y)
- Description.text_max: (x,y)
- Description.text_align: (x,y)
- Description.visible
Parts are objects, that is, they inherit the methods from the Object class. They also contain the following methods and attributes:
- Object Part.swallow
- Part.drag_dir
- Part.drag_value: (dx,dy)
- Part.drag_size: (dx,dy)
- Part.drag_step: (dx,dy)
- Part.drag_page: (dx,dy)
- Part.type
- Part.effect
- Part.mouse_events
- Part.states_list
- Part.state: (state,value)
- Part.text
- Part.text_selection
- Part.text_cursor_geometry: (x,y,w,h)
- Part.geometry: (x,y,w,h)
- Part.part_col_row_size: (cols,rows)
- Part.drag_value: (dx,dy)
- Part.drag_size: (dx,dy)
- Part.drag_step: (dx,dy)
- Part.drag_page: (dx,dy)
- Part.effect
- Part.mouse_events
- Part.repeat_events
- Part.state: (state,value)
- Part.tween_state
- Part.text
- Part:swallow(obj)
- Part:unswallow()
- PartDescription Part:custom_state(state_name, state_val)
- Part:text_select_none
- Part:text_select_all
- Part:text_insert(text)
- Part:table_pack(child, row, colspan, rowspan)
- Part:table_unpack(child)
- Part:table_clear(clear)
- Part:box_append(item)
- Part:box_prepend(item)
- Part:box_insert_before(item, before)
- Part:box_insert_at(item, index)
- Part:box_remove(item)
- Part:box_remove_at(item, index)
- Part:box_remove_all(clear)
Groups are objects, that is, they inherit the methods from the general Object Class. They also contain the following methods and attributes:
- Group.group
- Group.mouse: (x,y)
- Group.mouse_buttons
- Group.size_min: (w,h)
- Group.size_max: (w,h)
- Group.scale
- Group.load_error
- Group.load_error_str
- Group.play
- Group.animation
- Group.frametime
- Group.group
- Group.size_min: (w,h)
- Group.size_max: (w,h)
- Group.scale
- Group.play
- Group.animation
- Group.text_change_cb
- Group.frametime
- Timer Group:timer(secs, callback)
- Animator Group:animator(func)
- Poller Group:poller(interval, callback)
- Transform Group:transform()
- Group:signal_emit(emission, source)
- Group:message_send(message_type, id, msg)
- Group:program_run(name)
- Group:program_stop(name)
- Group:signal_callback_add(emission, source, callback)
- Group:signal_callback_del(emission, source)
- Group:freeze()
- Group:thaw()