1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
|
-- Utilities
-- Dummy require
function require()
end
function printvars()
local n,v = nextvar(nil)
print("--printvars Start--")
while n ~= nil do
print(tostring(n).."="..tostring(v))
n,v = nextvar(n)
end
print("--printvars End--")
end
function printtable(t)
local n,v = next(t, nil)
print("--printtable Start--")
while n ~= nil do
print(tostring(n).."="..tostring(v))
n,v = next(t, n)
end
print("--printtable End--")
end
function print_version_info()
print(_VERSION .. " " .. iup._LUA_COPYRIGHT)
if (im) then print(im._VERSION .. " " .. im._COPYRIGHT) end
if (cd and cd._VERSION) then print(cd._VERSION .. " " .. cd._COPYRIGHT) end
print(iup._VERSION .. " " .. iup._COPYRIGHT)
print("")
print("IUP Info")
print(" System: " .. iup.GetGlobal("SYSTEM"))
print(" System Version: " .. iup.GetGlobal("SYSTEMVERSION"))
local mot = iup.GetGlobal("MOTIFVERSION")
if (mot) then print(" Motif Version: ", mot) end
print(" Screen Size: " .. iup.GetGlobal("SCREENSIZE"))
print(" Screen Depth: " .. iup.GetGlobal("SCREENDEPTH"))
if (iup.GL_VENDOR) then print(" OpenGL Vendor: " .. iup.GL_VENDOR) end
if (iup.GL_RENDERER) then print(" OpenGL Renderer: " .. iup.GL_RENDERER) end
if (iup.GL_VERSION) then print(" OpenGL Version: " .. iup.GL_VERSION) end
end
-- IUPLUA Full Application
lastfile = nil -- Last file open
mulCommands = iupmultiline{expand=IUP_YES, size="200x120", font="COURIER_NORMAL_10"}
poslabel = iuplabel{title="0:0", size="50x"}
filelabel = iuplabel{title="", size="50x", expand="HORIZONTAL"}
mulCommands.caretcb = function(self, lin, col)
poslabel.title = lin..":"..col
end
butExecute = iupbutton{size="50x15", title = "Execute", action="dostring(mulCommands.value)"}
butClearCommands = iupbutton{size="50x15", title = "Clear", action = "mulCommands.value = '' filelabel.title = '' lastfile = nil"}
butLoadFile = iupbutton{size="50x15", title = "Load..."}
butSaveasFile = iupbutton{size="50x15", title = "Save As..."}
butSaveFile = iupbutton{size="50x15", title = "Save"}
function butSaveFile:action()
if (lastfile == nil) then
butSaveasFile:action()
else
novoarq = openfile (lastfile, "w+")
if (novoarq ~= nil) then
write (novoarq,mulCommands.value)
closefile (novoarq)
else
error ("Cannot Save file "..filename)
end
end
end
function butSaveasFile:action()
local filedlg = iupfiledlg{dialogtype = "SAVE", title = "Save File", filter = "*.wlua", filterinfo = "Lua files",allownew=yes}
IupPopup(filedlg,IUP_LEFT, IUP_LEFT)
local status = filedlg.status
lastfile = filedlg.value
filelabel.title = lastfile
IupDestroy(filedlg)
if status ~= "-1" then
if (lastfile == nil) then
error ("Cannot Save file "..lastfile)
end
local novoarq = openfile (lastfile, "w+")
if (novoarq ~= nil) then
write (novoarq,mulCommands.value)
closefile (novoarq)
else
error ("Cannot Save file")
end
end
end
function butLoadFile:action()
local filedlg = iupfiledlg{dialogtype="OPEN", title="Load File", filter="*.wlua", filterinfo="Lua Files", allownew="NO"}
filedlg:popup(IUP_CENTER, IUP_CENTER)
local status = filedlg.status
local newfile = filedlg.value
IupDestroy(filedlg)
if (status == "-1") or (status == "1") then
if (status == "1") then
error ("Cannot load file "..newfile)
end
else
local fp = openfile (newfile, "r")
if (fp == nil) then
error ("Cannot load file "..newfile)
else
mulCommands.value = read (fp,"*a")
closefile (fp)
lastfile = newfile
filelabel.title = lastfile
end
end
end
vbxConsole = iupvbox
{
iupframe{iuphbox{iupvbox{butLoadFile, butSaveFile, butSaveasFile, butClearCommands, butExecute; margin="0x0", gap="10"}, iupvbox{filelabel, mulCommands, poslabel; alignment="ARIGHT"}; alignment="ATOP"}; title="Commands"}
;alignment="ACENTER", margin="5x5", gap="5"
}
-- Main Menu Definition.
mnuMain = iupmenu
{
iupsubmenu
{
iupmenu
{
iupitem{title="Exit", action="return IUP_CLOSE"}
}; title="File"
},
iupsubmenu{iupmenu
{
iup.item{title="Print Version Info...", action=print_version_info},
iupitem{title="About...", action="dlgAbout:popup(IUP_CENTER, IUP_CENTER)"}
};title="Help"}
}
-- Main Dialog Definition.
dlgMain = iupdialog{vbxConsole; title="Complete IupLua3 Interpreter", menu=mnuMain, close_cb = "return IUP_CLOSE"}
-- About Dialog Definition.
dlgAbout = iupdialog
{
iupvbox
{
iuplabel{title="Complete IupLua3 Interpreter"},
iupfill{size="5"},
iupfill{size="5"},
iupframe
{
iupvbox
{
iuplabel{title="Tecgraf/PUC-Rio"},
iuplabel{title="Mark/Ovídio/Scuri"},
iuplabel{title="iup@tecgraf.puc-rio.br"}
}
},
iupfill{size="5"},
iupbutton{title="OK", action="return IUP_CLOSE", size="50X20"}
;margin="10x10", alignment="ACENTER"
}
;maxbox=IUP_NO, minbox=IUP_NO, resize=IUP_NO, title="About"
}
-- Displays the Main Dialog
dlgMain:show()
IupMainLoop()
IupDestroy(dlgMain)
IupDestroy(dlgAbout)
|