跳轉到內容

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 mrustler@gmx.de

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 tpaul@wp.pl

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 等?

華夏公益教科書