跳转到内容

Aros/开发者/文档/LUA

来自 Wikibooks,开放世界中的开放书籍
用于 Aros 维基教科书的导航栏
Aros 用户
Aros 用户文档
Aros 用户常见问题解答
Aros 用户应用程序
Aros 用户 DOS Shell
Aros/用户/AmigaLegacy
Aros 开发者文档
Aros 开发者文档
从 AmigaOS/SDL 移植软件
Zune 初学者指南
Zune .MUI 类
SDL 初学者指南
Aros 开发者构建系统
特定平台
Aros x86 完整系统 HCL
Aros x86 音频/视频支持
Aros x86 网络支持
Aros Intel AMD x86 安装
Aros 存储支持 IDE SATA 等
Aros Poseidon USB 支持
x86-64 支持
摩托罗拉 68k Amiga 支持
Linux 和 FreeBSD 支持
Windows Mingw 和 MacOSX 支持
Android 支持
Arm Raspberry Pi 支持
PPC Power Architecture
杂项
Aros 公共许可证

Lua 已经安装在 Icaros Desktop 中,但其他发行版可能没有它,因此

Lua 目录可以放在任何地方,但需要添加一些分配

assign lua: drive:directory/Lua 

例如分配 lua: sys:dev/Lua

编写您的 lua 代码并保存为 filename.lua

lua filename.lua

请参阅下一节以了解 AROS 特定功能和 amilua

Lua 包含以下部分

  • 函数式
  • 面向对象

除了函数,Lua 编程还有其他方面,但函数很容易理解,举个例子...

  -- comments here
  function my_function(par1,par2)
      ...
  end

如您所见,声明函数很容易,您可以通过调用该函数在其他地方使用它

  my_function("hello","world")

在函数中,您可以声明局部变量。局部变量的范围仅限于它们声明的函数。任何函数都可以返回值,这里有一个例子

  function calculate(a,b)
      local temp
      temp=a+b
      return temp
  end

您可能已经猜到,此函数执行加法,您可以调用

  c=calculate(1,2)

并且“c”的值将为 3。

Lua 有一些常见的控制结构,例如“if...then”或“while...do”。这里有一个简短的例子

  if val==0 then
      result="zero"
  elseif val  <  0 then
      result="negative"
  else
      result="positive"
  end

还有一个

  while i>0 do
      result=result*2
      i=i-1
  end

要比较数值,您可以使用运算符

== (equals)
~= (different)
>(greater)
<(lower)
>= (greater or equal)
<= (lower or equal)

初学者教程

另一个教程

学习如何使用用户数据以及什么是自定义类(使用调用方法,不要使用引用索引)。

AmiLua 使用一些处理直觉窗口、工具、菜单和图形函数的函数扩展了 Lua。

有 3 个 Lua 表

  • Siamiga:窗口、工具和菜单的创建、消息处理、绘图函数
  • Sigadget:工具参数的设置和获取
  • Sipicture:位图的加载、抓取和混合。

.alua 是 Lua 的特定“方言”,它包含 zulu 和 siamiga。如果您要编写一些 zulu 或 siamiga 代码,则需要使用 .alua 扩展名并指向 amilua。

Siamiga.createwindow(title,  left,   top,  [width], [height], [sizeable], [smartrefresh])
Siamiga.openwindow(window)
Siamiga.querywindow(window)
Siamiga.closewindow(window)
Siamiga.pset(window, x,y)
Siamiga.line(window, x1, y1 , [x2] , [y2])
Siamiga.box(window, [left], [top], [width], [height], filled)
Siamiga.ellipse(window, x, y, rx, ry)
Siamiga.text(window, x, y, txt)
Siamiga.querytext(window, text)
Siamiga.createpen(red, green, blue)
Siamiga.releasepen(number)
Siamiga.setpen(window, number)
Siamiga.waitmessage(win1, [...])
Siamiga.getmessage(window)
Siamiga.filebox([title], [default dir])
Siamiga.messagebox(window, title, text, buttons)
Siamiga.queryscreen()
Siamiga.addmenu(window, code, type, label, [key])
Siamiga.addgadget(window, code, type, left, top, width, height, label, [default], [min], [max])
Siamiga.__gc
Sigadget.set(gadget, value)
Sigadget.get(gadget)

Sipicture

[编辑 | 编辑源代码]
Sipicture.load(filename)
Sipicture.put(picture, window, left, top, [width], [height])
Sipicture.get(window, left, top, width, height)
Sipicture.query(picture)
Sipicture.free(picture)
Sipicture.__gc

一个复杂的绘图工具,应该用 C 语言编写,因为您很快就会达到 LUA 的限制。

Zulu 允许您从 Lua 脚本创建 MUI 应用程序。

您可以在当前的 nightly build 中的“Extras/Development/Lua”目录中找到它。您需要一个名为“lua”的分配指向此目录。二进制文件 Amilua 是使用 MUI 绑定构建的。一些示例位于子目录“test-mui”中。文档位于“doc/zulu.txt”中。如果您以前从未编程过 MUI,您应该从 Aminet 下载 mui38dev 并学习文档。

组也是 MUI/Zune 类。当然,您必须查看文档以了解哪些属性是可能的。Group 类是 Area 类的子类,这使得它可以使用其属性,例如 MUIA_Disabled。

object = mui.new(class, tag1, value1, tag2, value2 , ...)
object = mui.make(class, param1, param2 , ... )

mui.set(object, tag1, value1, ...)
intval = mui.getint(object, tag)
strval = mui.getstr(object, tag)
ptrval = mui.getptr(object, tag)
boolval = mui.getbool(object, tag)

intval = mui.doint(object, method, ...)
strval = mui.dostr(object, method, ...)
ptrval = mui.doptr(object, method, ...)
boolval = mui.dobool(object, method, ...)
mui.dispose(object)

id, signals = mui.input(app)
mui.wait(signals)
retval = mui.request(app, win, flags, title, gadgets, text)
id = mui.makeid(4 digit string)
path = mui.filerequest(tag1, value1, ...)
bool = mui.check(object)

object = strarray.new( string1, string2 , ...)
strarray.dispose(object)
str = strarray.get(object, index)

require "muidefs" - * MUIC are class descriptors to use as first parameter for mui.new
                    * MUIO are class descriptors to use as first parameter for mui.make
                    * MUIM are methods for mui.doint, mui.dostr, mui.dobool and mui.doptr
                    * MUIA are attributes
                    * MUIV are values

require "muifuncs"

require "muiasl"

ASL 请求器

[编辑 | 编辑源代码]

要从 ASL 请求器通过 Zulu 函数 mui.filerequest() 获取多个文件,您必须在花括号中调用该函数以获取多个结果

files = { mui.filerequest(.....) }
mui.ASLFR_DoMultiSelect, true

下面是我 Lua 代码的一段代码(基于 Mazze 的示例)

file = { mui.filerequest( 
             mui.ASLFR_TitleText,           "Select one or more files to compress", 
             mui.ASLFR_InitialHeight,      400, 
             mui.ASLFR_InitialWidth,       320, 
             mui.ASLFR_InitialLeftEdge,  40, 
             mui.ASLFR_InitialTopEdge,  20, 
             mui.ASLFR_DoMultiSelect,   true,         
             mui.ASLFR_PositiveText,     "OK", 
             mui.ASLFR_RejectIcons,      true, 
             mui.ASLFR_NegativeText,   "CANCEL", 
             mui.ASLFR_InitialFile,          "asl.library", 
             mui.ASLFR_InitialDrawer,    "libs:" 
             ) 
        }
        print("Selected File(s)") 
        print(file)

Lua 目前仅支持静态库。zulu 和 siamiga 是静态库。因此,您必须创建一个静态库,然后用该库重新链接 AmiLua。据我所知,需要一个用于 Lua 和库之间连接的头文件。

LUA.Filesystem(尚未实现)

lfs.attributes (filepath [, aname])  e.g. dev, ino, nlink, uid, gid, rdev, access, modification, change, size,   blocks, blksize
lfs.chdir (path)
lfs.lock_dir(path, [seconds_stale])
lfs.currentdir ()
iter, dir_obj = lfs.dir (path)
lfs.lock (filehandle, mode[, start[, length]])
lfs.mkdir (dirname)
lfs.rmdir (dirname)
lfs.setmode (file, mode)
lfs.symlinkattributes (filepath [, aname])
lfs.touch (filepath [, atime [, mtime]])
lfs.unlock (filehandle[, start[, length]])

LUA.Socket


lua.sqlite3

db = sqlite3.open("filename")

db = sqlite3.open_memory()

db:close()

db:exec

db:irows
db:rows
db:cols
db:first_irows
db:first_rows
db:first_cols

db:prepare
db:set_function

LuaSQL 前端 文档.

Lua 使用一等函数允许使用函数式编程中的许多强大技术;

以及完整的词法作用域允许细粒度的信息隐藏以强制执行最小特权原则。

Lua 允许程序员使用其单个表实现来实现命名空间、类和其他相关功能;

Lua 不包含对继承的显式支持,但允许使用 元表 相对轻松地实现它。

示例代码

Shell 变量是存储在 ENV: 中的文件。

因此,您可以使用输出重定向

lua:lua checkspace.lua >env:myvariable

或者,您可以使用 Lua 的文件处理函数写入 ENV:myvariable。

lua:lua checkspace.lua dh0
IF $myvariable GT 18000000 VAL
...
ENDIF
require "muidefs"
require "muifuncs"

function creategui()
  local button = mui.SimpleButton("_Ok")
  local text = mui.TextObject(mui.MUIA_Text_Contents, "27cHello world! How are you?")
  local window = mui.WindowObject(
    mui.MUIA_Window_Title, "Hello world!",
    mui.MUIA_Window_RootObject, mui.ScrollgroupObject(
      mui.MUIA_Scrollgroup_Contents, mui.VirtgroupObject(
        mui.Child, text,
        mui.Child, button
      )
    )
  )
  app = mui.ApplicationObject(
    mui.MUIA_Application_Window, window
  )
  assert(app:check(), "Cant create application")
  window:doint(mui.MUIM_Notify, mui.MUIA_Window_CloseRequest, true,
    app, 2, mui.MUIM_Application_ReturnID, mui.MUIV_Application_ReturnID_Quit)
  button:doint(mui.MUIM_Notify, mui.MUIA_Pressed, false,
    app, 2, mui.MUIM_Application_ReturnID, mui.MUIV_Application_ReturnID_Quit)
  window:set(mui.MUIA_Window_Open, true)
end

function main()
  creategui()
  app:doint(mui.MUIM_Application_Execute)
end

_, err = pcall(main)
if err then print("Error: " .. err) end
if app then app:dispose() end

此示例允许您启用/禁用包含两个文本字段的组。

require "muidefs"
require "muifuncs"

ok_id = 1
cancel_id = 2

function creategui()
  local okbutton = mui.SimpleButton("_Enable")
  local cancelbutton = mui.SimpleButton("_Disable")
  local text1 = mui.TextObject(mui.MUIA_Text_Contents, "27cHello world!")
  local text2 = mui.TextObject(mui.MUIA_Text_Contents, "27cHow are you?")

  group = mui.VGroup(
      mui.Child, text1,
      mui.Child, text2
  )

  window = mui.WindowObject(
    mui.MUIA_Window_Title, "Hello world!",
    mui.MUIA_Window_RootObject, mui.VGroup(
      mui.Child, group,
      mui.Child, mui.HGroup(
        mui.Child, okbutton,
        mui.Child, cancelbutton
      )
    )
  )
  app = mui.ApplicationObject(
    mui.MUIA_Application_Window, window
  )
  assert(app:check(), "Cant create application")
  window:doint(mui.MUIM_Notify, mui.MUIA_Window_CloseRequest, true,
    app, 2, mui.MUIM_Application_ReturnID, mui.MUIV_Application_ReturnID_Quit)

  okbutton:doint(mui.MUIM_Notify, mui.MUIA_Pressed, false, app, 2, mui.MUIM_Application_ReturnID, ok_id)
  cancelbutton:doint(mui.MUIM_Notify, mui.MUIA_Pressed, false, app, 2, mui.MUIM_Application_ReturnID, cancel_id)

  window:set(mui.MUIA_Window_Open, true)
end

function main()
  creategui()
  running = true
  while running do
    id, signals = app:input()
    if id == mui.MUIV_Application_ReturnID_Quit then
      running = false
    elseif id == ok_id then
      group:set(mui.MUIA_Disabled, false)
    elseif id == cancel_id then
      group:set(mui.MUIA_Disabled, true)
    end
    if running then mui.wait(signals) end
  end
end

_, err = pcall(main)
if err then print("Error: " .. err) end
if app then app:dispose() end
-- AntiwordGUI.alua -- AmiLua/Zulu GUI for antiword
-- $VER: antiwordgui.alua 1.1 (28.01.2007)
-- This is Public Domain software; use at your own risk
-- Send bug reports to [email protected]

require "muidefs"
require "muifuncs"
require "muiasl"

verbose = false

outputformats = strarray.new("PDF", "Postscript", "XML", "Text", "Formatted Text")
papersizes = strarray.new("10x14", "a3", "a4", "a5", "b4", "b5", "executive", "folio", "legal",
  "letter", "note", "quarto", "statement", "tabloid")
imagelevels = strarray.new("Ghostscript extension", "no images", "PS level 2", "PS level3")

ok_id = 1
infile_id = 3
outfile_id = 4

function main()
  local outputformat_rdio = mui.RadioObject(mui.MUIA_Radio_Entries, outputformats, mui.MUIA_Radio_Active, 3)
  local papersize_cyc = mui.CycleObject(mui.MUIA_Cycle_Entries, papersizes, mui.MUIA_Cycle_Active, 2)
  local image_cyc = mui.CycleObject(mui.MUIA_Cycle_Entries, imagelevels, mui.MUIA_Cycle_Active, 2)

  local ok_btn = mui.SimpleButton("Call antiword")

  local infile_btn = mui.SimpleButton("Infile")
  local outfile_btn = mui.SimpleButton("Outfile")

  local infile_str = mui.StringObject(mui.MUIA_Frame, mui.MUIV_Frame_String)
  local outfile_str = mui.StringObject(mui.MUIA_Frame, mui.MUIV_Frame_String)
  local width_str = mui.StringObject(mui.MUIA_Frame, mui.MUIV_Frame_String,
    mui.MUIA_String_Accept , "0123456879")

  local hidden_cm = mui.make(mui.MUIO_Checkmark, 0)
  local removed_cm = mui.make(mui.MUIO_Checkmark, 0)
  local landscape_cm = mui.make(mui.MUIO_Checkmark, 0)

  window = mui.WindowObject(
    mui.MUIA_Window_Title, "Antiword GUI",
    mui.MUIA_Window_RootObject, mui.VGroup(
      mui.Child, mui.VGroup(
        mui.Child, mui.HGroup(
          mui.MUIA_Frame, mui.MUIV_Frame_Group,
          mui.MUIA_FrameTitle, "Output format",
          mui.Child, outputformat_rdio
        ),
        mui.Child, mui.ColGroup(2,
          mui.MUIA_Frame, mui.MUIV_Frame_Group,
          mui.MUIA_FrameTitle, "Options",
          mui.Child, mui.Label("Paper size"),
          mui.Child, papersize_cyc,
          mui.Child, mui.Label("Image level"),
          mui.Child, image_cyc,
          mui.Child, mui.Label("Include removed text"),
          mui.Child, removed_cm,
          mui.Child, mui.Label("Include hidden text"),
          mui.Child, hidden_cm,
          mui.Child, mui.Label("Landscape"),
          mui.Child, landscape_cm,
          mui.Child, mui.Label("Width"),
          mui.Child, width_str,
          mui.Child, infile_btn,
          mui.Child, infile_str,
          mui.Child, outfile_btn,
          mui.Child, outfile_str
        )
      ),
      mui.Child, mui.RectangleObject( 
        mui.MUIA_Rectangle_HBar, true,
        mui.MUIA_FixHeight,      2
      ),
      mui.Child, ok_btn
    )
  )
  app = mui.ApplicationObject(
    mui.MUIA_Application_Description, "GUI for antiword",
    mui.MUIA_Application_Window, window
  )
  assert(app:check(), "Cant create application")
  window:doint(mui.MUIM_Notify, mui.MUIA_Window_CloseRequest, true,
    app, 2, mui.MUIM_Application_ReturnID, mui.MUIV_Application_ReturnID_Quit)

  ok_btn:doint(mui.MUIM_Notify, mui.MUIA_Pressed, false, app, 2, mui.MUIM_Application_ReturnID, ok_id)
  infile_btn:doint(mui.MUIM_Notify, mui.MUIA_Pressed, false, app, 2, mui.MUIM_Application_ReturnID, infile_id)
  outfile_btn:doint(mui.MUIM_Notify, mui.MUIA_Pressed, false, app, 2, mui.MUIM_Application_ReturnID, outfile_id)

  window:set(mui.MUIA_Window_Open, true)

  local running = true
  local id,signals,file

  while running do
    id, signals = app:input()
    if id == mui.MUIV_Application_ReturnID_Quit then
      running = false
    elseif id == ok_id then
      local command = "antiword:antiword"
      local format_opt = outputformat_rdio:getint(mui.MUIA_Radio_Active)
      local papersize_opt = papersizes:get(papersize_cyc:getint(mui.MUIA_Cycle_Active) + 1)
      local infile_opt = infile_str:getstr(mui.MUIA_String_Contents)
      local outfile_opt = outfile_str:getstr(mui.MUIA_String_Contents)
      local width_opt = width_str:getint(mui.MUIA_String_Integer)
      local landscape_opt = landscape_cm:getint(mui.MUIA_Selected)
      local imagelevel_opt = image_cyc:getint(mui.MUIA_Cycle_Active)

      if (infile_opt == "") or (outfile_opt == "") then
        app:request(window, 0, "Error", "OK", "Input or output file name is missing")
      else
        if format_opt == 0 then -- pdf
          command = command .. " -a" .. papersize_opt .. " -i" .. imagelevel_opt
        elseif format_opt == 1 then -- ps
          command = command .. " -p" .. papersize_opt .. " -i" .. imagelevel_opt
          if landscape_opt == 1 then command = command .. " -L" end
        elseif format_opt == 2 then -- xml
          command = command .. " -x db"
        elseif format_opt == 3 then -- text
          command = command .. " -t" .. " -w" .. width_opt
        elseif format_opt == 4 then -- formatted text
          command = command .. " -f" .. " -w" .. width_opt
        end

        if removed_cm:getbool(mui.MUIA_Selected) then command = command .. " -r" end
        if hidden_cm:getbool(mui.MUIA_Selected) then command = command .. " -s" end
        command = command .. ' "' .. infile_opt .. '" >"' .. outfile_opt .. '"'
        if verbose then
          print (command)
        end
        local retval = os.execute(command)
        if retval > 0 then
          app:request(window, 0, "Error", "OK", "antiword returned error code " .. retval)
        end
      end
    elseif id == infile_id then
      file = mui.filerequest(
        mui.ASLFR_TitleText, "Choose input file",
        mui.ASLFR_RejectIcons, true,
        mui.ASLFR_DoPatterns, true
      )
      if file then infile_str:set(mui.MUIA_String_Contents, file) end
    elseif id == outfile_id then
      file = mui.filerequest(
        mui.ASLFR_TitleText, "Choose output file",
        mui.ASLFR_DoSaveMode, true,
        mui.ASLFR_RejectIcons, true
      )
      if file then outfile_str:set(mui.MUIA_String_Contents, file)
      end
    end
    if running then mui.wait(signals) end
  end
end

_, err = pcall(main)
if err then print("Error: " .. err) end

if app then app:dispose() end
if outputformats then outputformats:dispose() end
if papersizes then papersizes:dispose() end
if imagelevels then imagelevels:dispose() end
-- zuluwget.alua -- AmiLua/Zune GUI for wget
-- $VER: zuluwget.alua 0.3 (7.01.2011)
-- This is Public Domain software; use at your own risk
-- Send bug reports to [email protected]

require "muidefs"
require "muifuncs"
require "muiasl"

verbose = false

ok_id = 1
http_id = 2
inp_id = 3
dir_id = 4
help_id = 5
canc_id = 6

function main()
  
local language = os.getenv ("language")
       if language ~= "Italiano" and language ~= "Deutsch" and language ~= "Polski" then
       language = "english"
       end
  
strings = {}
strings["Italiano"] = {"per", "URL:", "File di input (lista di indirizzi):", "Sfogliare", "Locali cassetto download:", "continua", "console nascondere", "Ulteriori parametri:", "Aiuto (wget --help)", "_Correre", "_Smettere", "Errore", "Indirizzo o file con i mising URL","wget restituito il codice di errore"}
strings["Deutsch"] = {"für", "URL:", "Eingabe-Datei (Liste von Adressen):", "_Blättern", "Lokale laden Schublade:","weiter","Konsole verstecken", "Zusätzliche Parameter:", "_Hilfe (wget --help)", "_Laufen", "Be_enden", "Fehler", "keine Adresse oder keine Datei mit URLs", "wget Fehlercode zurückgegeben"}
strings["english"] = {"for", "URL:", "Input file (list of URL's):", "_Browse", "Local download drawer:", "continue", "quiet", "Additional parameters:", "_Help (wget --help)", "_Run", "_Quit", "Error", "Adress or file with URL's is mising", "wget returned error code"}
strings["Polski"] = {"dla", "URL:", "Plik wej¶ciowy (lista adresów):", "_Przegl±daj", "Katalog docelowy:", "kontynuuj", "ukryj konsolê", "Dodatkowe parametry:", "Po_moc (wget --help)", "_Uruchom", "_Wyjd¼", "B³±d", "Brak adresu lub pliku z adresami URL", "wget zwróci³ kod b³êdu"}

 local ok_btn = mui.SimpleButton(strings[language][10])
 local dir_btn = mui.SimpleButton(strings[language][4])
 local inp_btn = mui.SimpleButton(strings[language][4])
 local http_str = mui.StringObject(mui.MUIA_Frame, mui.MUIV_Frame_String)
 local addi_str = mui.StringObject(mui.MUIA_Frame, mui.MUIV_Frame_String)
 local cont_cm = mui.make(mui.MUIO_Checkmark, 0)
 local inp_cm = mui.make(mui.MUIO_Checkmark, 0)
 local quiet_cm = mui.make(mui.MUIO_Checkmark, 0)
 local info = mui.TextObject(mui.MUIA_Text_Contents, "\27cZune/Lua GUI " .. strings[language][1] .. " wget\nv.0.3 (7.1.2011)") 
 local dir_str = mui.StringObject(mui.MUIA_Frame, mui.MUIV_Frame_String)
 local inp_str = mui.StringObject(mui.MUIA_Frame, mui.MUIV_Frame_String)
 local help_btn = mui.SimpleButton(strings[language][9])
 local canc_btn = mui.SimpleButton(strings[language][11])

 group = mui.VGroup(          
          mui.Child, mui.VGroup(          
          mui.Child, mui.HGroup(
          mui.MUIA_FixWidth, 300,
          mui.MUIA_Frame, mui.MUIV_Frame_Group,
          mui.Child, info
          ),         
          mui.Child, mui.VGroup(
          mui.MUIA_Frame, mui.MUIV_Frame_Group, 
          mui.Child, mui.VGroup(      
          mui.Child, mui.Label("\27l" .. strings[language][2]),
          mui.Child, http_str,         
          mui.Child, mui.Label("\n\27c[-i] " .. strings[language][3])
           ),
          mui.Child, mui.ColGroup(2,
          mui.MUIA_FixWidth, 300,
          mui.Child, inp_str,
          mui.Child, inp_btn        
          ),
          mui.Child, mui.VGroup(      
          mui.Child, mui.Label("\n\27l[-P] " .. strings[language][5])
          ),
          mui.Child, mui.ColGroup(2,
          mui.MUIA_FixWidth, 300,
          mui.Child, dir_str,
          mui.Child, dir_btn     
          )
        ) 
        ),   
          mui.Child, mui.VGroup(   
          mui.MUIA_Frame, mui.MUIV_Frame_Group,                
          mui.Child, mui.ColGroup(4,
          mui.Child, cont_cm,
          mui.Child, mui.Label("\27l[-c] " .. strings[language][6]),
          mui.Child, quiet_cm,
          mui.Child, mui.Label("\27l[-q] " .. strings[language][7])

       ),
          mui.Child, mui.VGroup(        
          mui.MUIA_FixWidth, 300,
          mui.Child, mui.Label("\n\27l" .. strings[language][8]),
          mui.Child, addi_str,
          mui.Child, help_btn 
          )
          
               
        ),
       mui.Child, mui.ColGroup(2,
         mui.Child, ok_btn,
         mui.Child, canc_btn
         )
      )
     
    
    
     window = mui.WindowObject(
    mui.MUIA_Window_Title, "ZuluWget",
    mui.MUIA_Window_RootObject, group
    
  ) 
          
  
    app = mui.ApplicationObject(
    mui.MUIA_Application_Description, "GUI for wget",
    mui.MUIA_Application_Window, window
  )
  assert(app:check(), "Cant create application")
  window:doint(mui.MUIM_Notify, mui.MUIA_Window_CloseRequest, true,
    app, 2, mui.MUIM_Application_ReturnID, mui.MUIV_Application_ReturnID_Quit)

  ok_btn:doint(mui.MUIM_Notify, mui.MUIA_Pressed, false, app, 2, mui.MUIM_Application_ReturnID, ok_id)
  inp_btn:doint(mui.MUIM_Notify, mui.MUIA_Pressed, false, app, 2, mui.MUIM_Application_ReturnID, inp_id)
  dir_btn:doint(mui.MUIM_Notify, mui.MUIA_Pressed, false, app, 2, mui.MUIM_Application_ReturnID, dir_id)
  help_btn:doint(mui.MUIM_Notify, mui.MUIA_Pressed, false, app, 2, mui.MUIM_Application_ReturnID, help_id)
  canc_btn:doint(mui.MUIM_Notify, mui.MUIA_Pressed, false, app, 2, mui.MUIM_Application_ReturnID, canc_id)
  
  window:set(mui.MUIA_Window_Open, true)

  local running = true
  local id,signals,http
  
  while running do
    id, signals = app:input()
    if id == mui.MUIV_Application_ReturnID_Quit then
      running = false     
    elseif id == canc_id then
      running = false
    elseif id == help_id then
      command = "wget --help /p"
      os.execute(command)
    elseif id == ok_id then
      local command = "wget"
      local http_opt = http_str:getstr(mui.MUIA_String_Contents)
      local addi_opt = addi_str:getstr(mui.MUIA_String_Contents)   
      local dir_opt = dir_str:getstr(mui.MUIA_String_Contents)
      local inp_opt = inp_str:getstr(mui.MUIA_String_Contents)  
        
        
        if cont_cm:getbool(mui.MUIA_Selected) then command = command .. " -c" end
        if quiet_cm:getbool(mui.MUIA_Selected) then command = command .. " -q" end
         
         
       
          if inp_opt ~= "" or inp_opt ~= "\"\"" then command = command .. " -i " .. "\"" .. inp_opt .. "\"" end
 
         
          if http_opt == "" and (inp_opt == "\"\"" or inp_opt == "") then
           
          app:request(window, 0, strings[language][12], "OK", strings[language][13])
          else
               command = command .. " " .. addi_opt .. " -P " .."\"" ..  dir_opt .. "wget\" " ..  http_opt 
            
         
       
                  
       if verbose then
          print (command)
        end
        local retval = os.execute(command)
        if retval > 0 then
          app:request(window, 0, "strings[language][12]", "OK", strings[language][14].. " " .. retval)
        end
      end

     elseif id == dir_id then
      dir = mui.filerequest(
        mui.ASLFR_TitleText, strings[language][5],
        mui.ASLFR_DoSaveMode, true,
        mui.ASLFR_RejectIcons, true
      )
      if dir then dir_str:set(mui.MUIA_String_Contents, dir)
      end
     
     elseif id == inp_id then
      inp = mui.filerequest(
        mui.ASLFR_TitleText, strings[language][3],
        mui.ASLFR_DoSaveMode, true,
        mui.ASLFR_RejectIcons, true
      )
      if inp then inp_str:set(mui.MUIA_String_Contents, inp)
      end
     
       
    end
    if running then mui.wait(signals) end
  end
end

_, err = pcall(main)
if err then print(strings[language][12] .. err) end

if app then app:dispose() end
require "muidefs"
require "muifuncs"
require "muiasl"

UnitArray	= strarray.new("SI","US")
LanguageArray	= strarray.new("en","fr","de","es","sv","no","ru","pl")

Location	= "London"
Units		= 0
Lang		= 0
UpdateFreq  	= 60

Conf_menu_ID  = 10
Conf_close_ID = 20
Conf_save_ID  = 30

-- Conditions as reported by google weather API (Could be incomplete!)

-- "PARTLY SUNNY"
-- "SCATTERED THUNDERSTORMS"
-- "SHOWERS"
-- "SCATTERED SHOWERS"
-- "RAIN AND SNOW"
-- "OVERCAST"
-- "LIGHT SNOW"
-- "DRIZZLE"
-- "FREEZING DRIZZLE"
-- "CHANCE OF RAIN"
-- "SUNNY"
-- "CLEAR"
-- "MOSTLY SUNNY"
-- "PARTLY CLOUDY"
-- "MOSTLY CLOUDY"
-- "CHANCE OF STORM"
-- "RAIN"
-- "CHANCE OF SNOW"
-- "CLOUDY"
-- "MIST"
-- "STORM"
-- "THUNDERSTORM"
-- "CHANCE OF TSTORM"
-- "SLEET"
-- "SNOW"
-- "ICY"
-- "DUST"
-- "FOG"
-- "SMOKE"
-- "HAZE"
-- "FLURRIES"
-- "LIGHT RAIN"
-- "SNOW SHOWERS"

			
for_City = ""
for_CurT = 0
for_CurH = ""
for_CurC = "PARTLY SUNNY.PNG"
for_CurW = ""

for_F1Day = ""
for_F1Min = 0
for_F1Max = 0
for_F1Con = "PARTLY SUNNY.PNG"

for_F2Day = ""
for_F2Min = 0
for_F2Max = 0
for_F2Con = "PARTLY SUNNY.PNG"

for_F3Day = ""
for_F3Min = 0
for_F3Max = 0
for_F3Con = "PARTLY SUNNY.PNG"

for_F4Day = ""
for_F4Min = 0
for_F4Max = 0
for_F4Con = "PARTLY SUNNY.PNG"

-- only LUA simple XML parser (test)
XL = {}
 
function XL:new()
  local x = {}
  setmetatable(x, self)
  self.__index = self
  return x
end
 
function XL._get_attrs(s)
  local arg = {}
  string.gsub(s, "(%w+)=([\"'])(.-)%2", function (w, _, a)
    arg[w] = a
  end)
  return arg
end
 
function XL:root()
  for _, v in ipairs(self.xml) do
    if v.tag then return v end
  end
  return nil
end
 
function XL:find(x, t)
  r = {}
  if x~=nil then
    for _, v in ipairs(x) do
	if v.tag  and v.tag == t then r[#r+1] = v end
    end
  end
  return r
end
 
function XL:from_file(s)
  local f=io.open(s)
  local s = f:read('*all')

  s = string.gsub(s, '_', 'A')

  self:from_string(s)
  f:close()
end
 
function XL:from_string(s)
  self.xml = nil        -- reset
  local stack = {}
  local top = {}
  table.insert(stack, top)
  local ni,c,tag,attr, empty
  local i, j = 1, 1
  
  while true do
    ni,j,c,tag,attr, empty = string.find(s, "<(%/?)([%w:]+)(.-)(%/?)>", i)
    if not ni then break end
    local text = string.sub(s, i, ni-1)
	
    if not string.find(text, "^%s*$") then
      table.insert(top, text)
    end
    if empty == "/" then  -- empty element tag
      table.insert(top, {tag=tag, attr=self._get_attrs(attr)})
    elseif c == "" then   -- start tag
      top = {tag=tag, attr=self._get_attrs(attr)}
      table.insert(stack, top)   -- new level
    else  -- end tag
      local toclose = table.remove(stack)  -- remove top
      top = stack[#stack]
      if #stack < 1 then
        error("nothing to close with "..tag)
      end
      if toclose.tag ~= tag then
        error("trying to close "..toclose.tag.." with "..tag)
      end
      table.insert(top, toclose)
    end
    i = j+1
  end
  local text = string.sub(s, i)
  if not string.find(text, "^%s*$") then
    table.insert(stack[#stack], text)
  end
  if #stack > 1 then
    error("unclosed "..stack[stack.n].tag)
  end
  self.xml = stack[1]
end

-- Load and Save configuration file
function LoadConfig(configfile)
-- Loads the configuration file
	local cf
	
	cf = io.open(configfile,"r")
    
	if cf == nil then
		app:request(window, 0 , "Weather Forecast", "OK", "File does not exist")
	else
		-- Load Configuration file
		Location 	= cf:read("*l")
		Units		= tonumber(cf:read("*l"))
		Lang		= tonumber(cf:read("*l"))
		UpdateFreq  	= tonumber(cf:read("*l"))	
		cf:close()
	end
end

function SaveConfig(configfile)
-- Saves the configuration file
	local cf

	if (configfile ~= nil) then
		cf = io.open(configfile,"w+")
		if cf ~= nil then
			cf:write(Location .. "\n")
			cf:write(tostring(Units) .. "\n")
			cf:write(tostring(Lang) .. "\n")
			cf:write(tostring(UpdateFreq) .. "\n")
			cf:close()
		end
	end	
end

-- GUI
function menuentry(title, short)
-- Creates a single menu entry
	return mui.MenuitemObject(mui.MUIA_Menuitem_Title, title, mui.MUIA_Menuitem_Shortcut, short)
end

function set_menu_id(object, id)
-- Add a return ID to a menu selecvt event
	if id == 0 then
		error("Menu ID must not be 0")
	else
		object:doint(mui.MUIM_Notify, mui.MUIA_Menuitem_Trigger, mui.MUIV_EveryTime, app, 2, mui.MUIM_Application_ReturnID, id)
	end
end

function Slider(min, max, value)
  return mui.SliderObject(
    mui.MUIA_Numeric_Min, min,
    mui.MUIA_Numeric_Max, max,
    mui.MUIA_Numeric_Value, value)
end

function CreateGui()

	Conf_menu = menuentry("Configure","C")
	Quit_menu = menuentry("Quit","Q")
	Menu = mui.MenustripObject(
		mui.MUIA_Family_Child, mui.MenuObject(
			mui.MUIA_Menu_Title, "Project",
			mui.MUIA_Family_Child, Conf_menu,
			mui.MUIA_Family_Child, Quit_menu
		)
	)
		

	ImCurrent 	=	mui.new(mui.MUIC_Dtpic, mui.MUIA_Dtpic_Name,"Icons/PARTLY SUNNY.png")
	ImForecast1 = 	mui.new(mui.MUIC_Dtpic, mui.MUIA_Dtpic_Name,"Icons/PARTLY SUNNY.png")
	ImForecast2 = 	mui.new(mui.MUIC_Dtpic, mui.MUIA_Dtpic_Name,"Icons/PARTLY SUNNY.png")
	ImForecast3 = 	mui.new(mui.MUIC_Dtpic, mui.MUIA_Dtpic_Name,"Icons/PARTLY SUNNY.png")
	ImForecast4 = 	mui.new(mui.MUIC_Dtpic, mui.MUIA_Dtpic_Name,"Icons/PARTLY SUNNY.png")

	CurT = mui.TextObject(mui.MUIA_Text_Contents, "5 °C", mui.MUIA_Text_PreParse, "\27c")
	CurH = mui.TextObject(mui.MUIA_Text_Contents, "75%", mui.MUIA_Text_PreParse, "\27c")
	CurW = mui.TextObject(mui.MUIA_Text_Contents, "NE 20mph", mui.MUIA_Text_PreParse, "\27c")
	
	ForT1 = mui.TextObject(mui.MUIA_Text_Contents, "0 to 10", mui.MUIA_Text_PreParse, "\27c")
	ForT2 = mui.TextObject(mui.MUIA_Text_Contents, "0 to 10", mui.MUIA_Text_PreParse, "\27c")
	ForT3 = mui.TextObject(mui.MUIA_Text_Contents, "0 to 10", mui.MUIA_Text_PreParse, "\27c")
	ForT4 = mui.TextObject(mui.MUIA_Text_Contents, "0 to 10", mui.MUIA_Text_PreParse, "\27c")

	Current = mui.VGroup(	mui.MUIA_Frame, mui.MUIV_Frame_Group,
							mui.MUIA_FrameTitle, "Current",
							mui.Child, mui.HGroup(
								mui.Child, mui.RectangleObject(),
								mui.Child, ImCurrent,
								mui.Child, mui.RectangleObject()
							),
							mui.Child, CurT
						)
	
	DayT1 = mui.VGroup(	mui.MUIA_Frame, mui.MUIV_Frame_Group,
						mui.MUIA_FrameTitle, "Today",
						mui.Child, mui.HGroup(
							mui.Child, mui.RectangleObject(),
							mui.Child, ImForecast1,
							mui.Child, mui.RectangleObject()
						),
						mui.Child, ForT1
					)
				
	DayT2 = mui.VGroup(	mui.MUIA_Frame, mui.MUIV_Frame_Group,
						mui.MUIA_FrameTitle, "Day +1",
						mui.Child, mui.HGroup(
							mui.Child, mui.RectangleObject(),
							mui.Child, ImForecast2,
							mui.Child, mui.RectangleObject()
						),
						mui.Child, ForT2
					)
				
	DayT3 = mui.VGroup(	mui.MUIA_Frame, mui.MUIV_Frame_Group,
						mui.MUIA_FrameTitle, "Day +2",
						mui.Child, mui.HGroup(
							mui.Child, mui.RectangleObject(),
							mui.Child, ImForecast3,
							mui.Child, mui.RectangleObject()
						),
						mui.Child, ForT3
					)
				
	DayT4 = mui.VGroup(	mui.MUIA_Frame, mui.MUIV_Frame_Group,
						mui.MUIA_FrameTitle, "Day +3",
						mui.Child, mui.HGroup(
							mui.Child, mui.RectangleObject(),
							mui.Child, ImForecast4,
							mui.Child, mui.RectangleObject()
						),
						mui.Child, ForT4
					)

				
	window = mui.WindowObject(
		mui.MUIA_Window_Title, "Weather Forecast for " .. Location,
		mui.MUIA_Window_ID   , mui.makeid("WEFO"),
		
		mui.WindowContents, mui.VGroup(
			mui.MUIA_Group_SameWidth, true,

			mui.Child, mui.HGroup(
				mui.Child, Current,
				mui.Child, DayT1,
				mui.Child, DayT2,
				mui.Child, DayT3,
				mui.Child, DayT4
			),
		
			mui.Child, mui.HGroup(
				mui.Child, mui.HGroup(
					mui.MUIA_Frame, mui.MUIV_Frame_Group,
					mui.Child, CurH
				),
				mui.Child, mui.HGroup(
					mui.MUIA_Frame, mui.MUIV_Frame_Group,
					mui.Child, CurW
				)
			)
		)
	)

	Conf_Loc = mui.StringObject(mui.MUIA_String_Contents, Location)
	Conf_Lan = mui.CycleObject(mui.MUIA_Cycle_Entries, LanguageArray, mui.MUIA_Cycle_Active, 0)
	Conf_Uni = mui.CycleObject(mui.MUIA_Cycle_Entries, UnitArray, mui.MUIA_Cycle_Active, 0)
	Conf_Upd = Slider(1,15,2)
	SAVE 	 = mui.SimpleButton("_Save")
	CANCEL   = mui.SimpleButton("_Cancel")

	conf_window = mui.WindowObject(
		mui.MUIA_Window_Title, "Weather Forecast configuration",
		mui.MUIA_Window_ID   , mui.makeid("WFCO"),
		
		mui.WindowContents, mui.VGroup(
			mui.MUIA_Group_SameWidth, true,
			mui.Child, mui.ColGroup(
				2,
				mui.Child, mui.Label1("Location")	, mui.Child, Conf_Loc,
				mui.Child, mui.Label1("Language") 	, mui.Child, Conf_Lan,
				mui.Child, mui.Label1("Units")		, mui.Child, Conf_Uni,
				mui.Child, mui.Label1("Update Rate")	, mui.Child, Conf_Upd
			),			
			mui.Child, mui.HGroup(
				mui.Child, mui.RectangleObject(),
				mui.Child, SAVE,
				mui.Child, mui.RectangleObject(),
				mui.Child, CANCEL,
				mui.Child, mui.RectangleObject()
			)
		)
	)

	
	app = mui.ApplicationObject(
		mui.MUIA_Application_Title      , "Weather Forecast",
		mui.MUIA_Application_Version    , "$VER: Weather Forecast for AROS v1.0",
		mui.MUIA_Application_Author     , "Yannick Erb",
		mui.MUIA_Application_Description, "Weather Forecast for AROS",
		mui.MUIA_Application_Base       , "AROSWEFO",
		mui.MUIA_Application_Menustrip	, Menu,
		mui.SubWindow					, window,
		mui.SubWindow					, conf_window
	)

	assert(app:check(), "Failed to create Application.")

	collectgarbage("collect")
	
	-- set up actions
	window:doint(mui.MUIM_Notify, mui.MUIA_Window_CloseRequest, true,
		app, 2, mui.MUIM_Application_ReturnID, mui.MUIV_Application_ReturnID_Quit)

	conf_window:doint(mui.MUIM_Notify, mui.MUIA_Window_CloseRequest, true,
		app, 2, mui.MUIM_Application_ReturnID, Conf_close_ID)

	CANCEL:doint(mui.MUIM_Notify, mui.MUIA_Pressed, false,
		app, 2, mui.MUIM_Application_ReturnID, Conf_close_ID)

	SAVE:doint(mui.MUIM_Notify, mui.MUIA_Pressed, false,
		app, 2, mui.MUIM_Application_ReturnID, Conf_save_ID)
		
	-- set up Menu actions
	set_menu_id(Conf_menu, Conf_menu_ID)
	set_menu_id(Quit_menu, mui.MUIV_Application_ReturnID_Quit)
	
end

function ConvertTemp(T, inUnit, outUnit)

	outUnitStr = strarray.get(UnitArray,outUnit+1)
	
	if inUnit == outUnitStr then
		return T
	end
		
	if inUnit == "SI" then
		return (math.ceil(T*1.8+32))
	else
		return (math.ceil((T-32)/1.8))
	end
end

function ConvertIconName(s)
	s = string.gsub(s, 'A', ' ')
	s = string.gsub(s, '/ig/images/weather/', 'Icons/')
	s = string.gsub(s, '.gif', '.png')
	return s
end

function GetForecast()
	local cf
	
	-- Get forecast from google weather API
	Command = "wget -q http://www.google.com/ig/api?weather=" .. Location .. "&hl=" .. strarray.get(LanguageArray,Lang+1) .. " -O WeatherForecast.xml"
	os.execute(Command)

	parser = XL:new()
	parser:from_file("WeatherForecast.xml")

	weather = parser:find(parser:root(), "weather")
	
	if weather[1] ~= nil then
		-- Global informations
		Info = parser:find(weather[1],"forecastAinformation")
		if Info[1] ~= nil then	
			city = parser:find(Info[1],"city")
			for_City = city[1].attr.data
			UnitSys = parser:find(Info[1],"unitAsystem")
			CurUnits = UnitSys[1].attr.data

			-- Current Conditions
			CurrentCond = parser:find(weather[1],"currentAconditions")
			condition = parser:find(CurrentCond[1],"icon")
			for_CurC = ConvertIconName(condition[1].attr.data)
			tempc = parser:find(CurrentCond[1],"tempAc")
			for_CurT = ConvertTemp(tonumber(tempc[1].attr.data),"SI",Units)
			humidity = parser:find(CurrentCond[1],"humidity")
			for_CurH = humidity[1].attr.data
			windcondition = parser:find(CurrentCond[1],"windAcondition")
			for_CurW = windcondition[1].attr.data
	
			-- Forecasted Conditions
			forecastconditions = parser:find(weather[1],"forecastAconditions")
			Day = parser:find(forecastconditions[1],"dayAofAweek")
			for_F1Day = Day[1].attr.data
			Min = parser:find(forecastconditions[1],"low")
			for_F1Min = ConvertTemp(tonumber(Min[1].attr.data),CurUnits,Units)
			Max = parser:find(forecastconditions[1],"high")
			for_F1Max = ConvertTemp(tonumber(Max[1].attr.data),CurUnits,Units)
			condition = parser:find(forecastconditions[1],"icon")
			for_F1Con = ConvertIconName(condition[1].attr.data)
		
			Day = parser:find(forecastconditions[2],"dayAofAweek")
			for_F2Day = Day[1].attr.data
			Min = parser:find(forecastconditions[2],"low")
			for_F2Min = ConvertTemp(tonumber(Min[1].attr.data),CurUnits,Units)
			Max = parser:find(forecastconditions[2],"high")
			for_F2Max = ConvertTemp(tonumber(Max[1].attr.data),CurUnits,Units)
			condition = parser:find(forecastconditions[2],"icon")
			for_F2Con = ConvertIconName(condition[1].attr.data)
		
			Day = parser:find(forecastconditions[3],"dayAofAweek")
			for_F3Day = Day[1].attr.data
			Min = parser:find(forecastconditions[3],"low")
			for_F3Min = ConvertTemp(tonumber(Min[1].attr.data),CurUnits,Units)
			Max = parser:find(forecastconditions[3],"high")
			for_F3Max = ConvertTemp(tonumber(Max[1].attr.data),CurUnits,Units)
			condition = parser:find(forecastconditions[3],"icon")
			for_F3Con = ConvertIconName(condition[1].attr.data)
	
			Day = parser:find(forecastconditions[4],"dayAofAweek")
			for_F4Day = Day[1].attr.data
			Min = parser:find(forecastconditions[4],"low")
			for_F4Min = ConvertTemp(tonumber(Min[1].attr.data),CurUnits,Units)
			Max = parser:find(forecastconditions[4],"high")
			for_F4Max = ConvertTemp(tonumber(Max[1].attr.data),CurUnits,Units)
			condition = parser:find(forecastconditions[4],"icon")
			for_F4Con = ConvertIconName(condition[1].attr.data)
		end
	end
		
end

function UpdateDisplay()
	-- Set pictures
	mui.set(ImCurrent  , mui.MUIA_Dtpic_Name, for_CurC  )
	mui.set(ImForecast1, mui.MUIA_Dtpic_Name, for_F1Con )
	mui.set(ImForecast2, mui.MUIA_Dtpic_Name, for_F2Con )
	mui.set(ImForecast3, mui.MUIA_Dtpic_Name, for_F3Con )
	mui.set(ImForecast4, mui.MUIA_Dtpic_Name, for_F4Con )

	-- Set Current Values
	mui.set(window, mui.MUIA_Window_Title, "Weather Forecast for " .. for_City)
	mui.set(CurH, mui.MUIA_Text_Contents, for_CurH)
	mui.set(CurW, mui.MUIA_Text_Contents, for_CurW)
	if Units == 0 then
		mui.set(CurT, mui.MUIA_Text_Contents, tostring(for_CurT) .. " °C")
	else
		mui.set(CurT, mui.MUIA_Text_Contents, tostring(for_CurT) .. " °F")
	end
	
	--Set Forecasted Values
	mui.set(DayT1, mui.MUIA_FrameTitle, for_F1Day)
	mui.set(DayT2, mui.MUIA_FrameTitle, for_F2Day)
	mui.set(DayT3, mui.MUIA_FrameTitle, for_F3Day)
	mui.set(DayT4, mui.MUIA_FrameTitle, for_F4Day)
	mui.set(ForT1, mui.MUIA_Text_Contents, tostring(for_F1Min) .. " to " .. tostring(for_F1Max))
	mui.set(ForT2, mui.MUIA_Text_Contents, tostring(for_F2Min) .. " to " .. tostring(for_F2Max))
	mui.set(ForT3, mui.MUIA_Text_Contents, tostring(for_F3Min) .. " to " .. tostring(for_F3Max))
	mui.set(ForT4, mui.MUIA_Text_Contents, tostring(for_F4Min) .. " to " .. tostring(for_F4Max))
end

		
function main()

	-- if WeatherForecat.cfg exists load it
	cf = io.open("WeatherForecast.cfg","r")
	if cf ~= nil then
		LoadConfig("WeatherForecast.cfg")
		io.close(cf)
	else
		SaveConfig("WeatherForecast.cfg")
	end
	
	-- Get initial forecast
	GetForecast()
	
	
	-- Open Window
	CreateGui()
	window:set(mui.MUIA_Window_Open, true)
	
	-- Initial update
	UpdateDisplay()
	
	running = true

	UpdateTimer = os.time()
	
	-- Main loop
	while running do
		-- Get user inputs
		id, signals = app:input()
		if id == mui.MUIV_Application_ReturnID_Quit then
			-- Exit GUI
			running = false
		elseif id == Conf_menu_ID then
			mui.set(Conf_Loc, mui.MUIA_String_Contents, Location)
			mui.set(Conf_Lan, mui.MUIA_Cycle_Active, Lang)
			mui.set(Conf_Uni, mui.MUIA_Cycle_Active, Units)
			mui.set(Conf_Upd, mui.MUIA_Numeric_Value, UpdateFreq)
			conf_window:set(mui.MUIA_Window_Open, true)
		elseif id == Conf_close_ID then
			conf_window:set(mui.MUIA_Window_Open, false)
		elseif id == Conf_save_ID then
			Location	= mui.getstr(Conf_Loc, mui.MUIA_String_Contents)
			Units		= mui.getint(Conf_Uni, mui.MUIA_Cycle_Active)
			Lang		= mui.getint(Conf_Lan, mui.MUIA_Cycle_Active)
			UpdateFreq  	= mui.getint(Conf_Upd, mui.MUIA_Numeric_Value)
			SaveConfig("WeatherForecast.cfg")			
			conf_window:set(mui.MUIA_Window_Open, false)
			-- Update the display
			GetForecast()
			UpdateDisplay()
			UpdateTimer = os.time()	
		end
		
		-- update forecast
		if os.difftime(os.time(),UpdateTimer) > UpdateFreq*60 then
			GetForecast()
			UpdateDisplay()
			UpdateTimer = os.time()
		end
		
		if running then mui.wait(signals) end
	end  
end

--main()
_, err = pcall(main)
if err then print("Error: " .. err) end
if app then app:dispose() end

如何在外部文件中声明变量?我需要一个包含一些变量的配置文件。如何在主文件中声明它们?

example:

config.cfg:

v = 5

main.lua:

a = 5
v = ?????????

a = a + v

loadfile() 是您需要的。

Floattext.mui 类和 Lua 是否可以在 Zulu 中使用此类?如何使用它在窗口中读取和显示文本?无法为 WHD_Menu 很好地使用它。最终使用了列表对象。您可以从 Aros 存档下载 WHD_Menu 以了解它是如何实现的。此对象用于显示自述文件(变量为 CurrentReadMe)。

是否可以在此类中使用函数在自述文件中搜索请求的词以获取行号作为结果?每行都是列表中的一个条目。只需解析所有条目并搜索字段中的字符串。您将直接获得行号。

线程 多文件选择无法开箱即用,您必须创建自己的类,而 Lua/Zulu 无法做到这一点,您必须用 C 语言完成。

如果您下载到其他名称中包含空格的位置,仍然会出现问题。如何解决?确保路径用双引号括起来。来自 AROS Exec 下载工具

local retval = os.execute('c:run sys:utilities/multiview "' .. readme_target .. '"')

这里,readme_target 只有双引号,因为 MultiView 的路径没有空格。

将行更改为

local dir_opt = "\"" .. dir_str:getstr(mui.MUIA_String_Contents) .. "\""

示例 这里这里

如何对 Lua 脚本进行国际化?Lua 中没有与 locale.library 的接口。只需创建包含字符串的表。

strings = {}
strings["deutsch"] = {"Anwendung", "Fenster"}
strings["english"] = {"Application", "Window"}

language = "english"

print(strings[language][1])

因此,我需要添加“选择语言”工具,或者是否有任何函数可以检查系统中使用的语言环境?我可以使用外部文件 deutsch.lang、polski.lang 等,还是这些字符串必须在主文件中?对于这些小型 Lua 脚本,哪种方式更简单,哪种方式更好?

有一个名为“language”的环境变量,Lua有一个函数可以查询环境变量。

language = os.getenv ("language")
if language = NIL
language = "english"
end

在 MUI/ZUNE 中,要从 ListObject 读取字符串值,可以使用以下代码。

STRPTR *stringValue = NULL;
DoMethod(list, MUIM_List_GetEntry, active, &stringValue);

请记住,MUIM_List_GetEntry 返回一个指向通用条目的指针。字符串指针只是单列列表的特殊情况。

ZULU 如何在 Lua 中处理这个问题?根据 zulu.txt,没有一个访问器方法(getstr、dostr 等)似乎与这种将字符串指针作为参数传递的模式匹配?我正在使用 local current = listobject:getint(mui.MUIA_List_Active) 查询选定条目的索引。因此,您可以将 StrArray 分配给 mui.MUIA_List_SourceArray,然后使用 mui.MUIA_List_Active 结果作为该数组的索引。

参考资料

[编辑 | 编辑源代码]

基于 HTML 页面的参考

下载编程指南

简短参考 - PDF 下载

精简的单页参考

程序员维基

教程目录

官方常见问题解答

非官方常见问题解答

http://www.andreas-rozek.de/Lua/index_en_old.html

Lua 文件系统

http://luaforge.net/

http://www.tecgraf.puc-rio.br/~diego/professional/luasocket/

LOVE 和 nLOVE

[编辑 | 编辑源代码]

http://love2d.org/

维基百科IDE

function love.draw()
    love.graphics.print("Hello World", 400, 300)
end

入门

  • love.load
  • love.update
  • love.draw
  • love.mousepressed
  • love.mousereleased
  • love.keypressed
  • love.keyreleased
  • love.focus
  • love.quit

调试调试

require("debug")

"scripts.library.enemy" 而不是 "scripts/library/enemy"

犯一些你没有注意到的愚蠢错误,比如在 love.update 或 love.draw 中调用 newImage、newImageData、newFont 等?

华夏公益教科书