LUA Web-Programming for openwrt board.




Lua is commonly described as a “multi-paradigm” language, providing a small set of general features that can be extended to fit different problem types, rather than providing a more complex and rigid specification to match a single paradigm. Lua, for instance, does not contain explicit support for inheritance, but allows it to be implemented with metatables. Similarly, Lua allows programmers to implement namespaces, classes, and other related features using its single table implementation; first-class functions allow the employment of many techniques from functional programming; and full lexical scoping allows fine-grained information hiding to enforce the principle of least privilege.
lua base language is light – the full reference interpreter is only about 180 kB compiled– and easily adaptable to a broad range of applications.
Lua is a dynamically typed language intended for use as an extension or scripting language, and is compact enough to fit on a variety of host platforms.
It supports only a small number of atomic data structures such as
 Boolean values,
 numbers (double-precision floating point by default), and
 strings.
Typical data structures such as
 arrays,
 sets,
 lists, and
 Records
can be represented using Lua’s single native data structure,
o the table, which is essentially a heterogeneous associative array.
Ex. a_table = {} — Creates a new, empty table

NOTES–Lua programs are not interpreted directly from the textual Lua file, but are compiled into byte-code which is then run on the Lua virtual machine. The compilation process is typically transparent to the user and is performed during run-time, but it can be done offline in order to increase loading performance or reduce the memory footprint of the host environment by leaving out the compiler.
How to Add Buttons in LUA and Handling their Events…
Button1 = exSection:option(Button, “_button_click_event “,translate(“Button Section”)) Note:- exSection is defined in a map, and button is defined in that exSection-section
Button1.title = translate(“CLICK HERE TO PERFORM BUTTON-ACTION”)
Button1.inputtitle=translate(” START “)
Function Button1.write(self, section, value) –Defining button-click event function‘/etc/init.d/test_daemon start’) –Firing a system-command to start a script
How to call Templates from LUA and calling lua-function from template
testTemplate = exSection:option(Value, “_custom”, translate(“Template Testing… “))
testTemplate.template = “Template-Testing”
<%- …… Lua code which you want to execute in your lua page….. %>
——Your HTML Code here h_testlval value comes from lua page.
Note:- In LUA page we called any input-type(EX.Button,TextBox..)From their name.
Function Definitions in lua page
function testTemplate.lastmodifiedtime(self, section)
local mdtime=st.mtime(“/usr/lib/test.txt”)
return‘%c’, mdtime)
How to create MAP and SECTION in lua page
local m, s
m=Map (“testing”, translate (“TEST-APPLICATION CONFIGURATION “))
s = m: section (TypedSection, “testagent”, translate (“TESTAGENT”))
s.anonymous = true
Predefined Function of lua when using map.
I. m.on_init=function(self)
———–Things which you want to execute before your lua page load———
II. m.on_before_commit = function(self)
——Before commit———-
III. m.on_after_commit=function(self)
—–After Commit———-
LUA Uses by different Organization in their Application.
A. Adobe Photoshop Lightroom uses Lua for its user interface.
B. Apache HTTP Server can use Lua anywhere in the request process (since version 2.3, via the core mod_lua module).
C. Cisco uses Lua to implement Dynamic Access Policies within the Adaptive Security Appliance.
D. iClone, a 3D real-time animation studio to create animation movies uses Lua in the controls of its new physic simulation.
E. MySQL Proxy uses Lua for its extensions
F. VLC media player uses Lua to provide scripting support.
G. Wikipedia since March 2013 Lua is used as a new templating language, and its template library is growing.

Pushpraj  Kumar

Helical IT Solution.