How to Use LUA as Web Script

Posted on by By Nikhilesh, in Business Intelligence | 0

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,

  •  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…..  %>

<input type=”text ” name=”” id=” ” value=”<%-=h_testlval-%>”></input>                           ——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.

  1. Adobe Photoshop Lightroom uses LUA for its user interface.
  2. Apache HTTP Server can use LUA anywhere in the request process (since version 2.3, via the core mod_lua module).
  3. Cisco uses LUA to implement Dynamic Access Policies within the Adaptive Security Appliance.
  4. iClone, a 3D real-time animation studio to create animation movies uses Lua in the controls of its new physic simulation.
  5. MySQL Proxy uses LUA for its extensions
  6. VLC media player uses LUA to provide scripting support.

Wikipedia since March 2013 LUA is used as a new templating language, and its template library is growing.


Pushpraj Kumar,

Helical IT Solutions


Best Open Source Business Intelligence Software Helical Insight is Here


A Business Intelligence Framework

0 0 votes
Article Rating
Notify of
Inline Feedbacks
View all comments