~stuart/sandpad/stuart

« back to all changes in this revision

Viewing changes to sandpad.wlua

  • Committer: Stuart P. Bentley
  • Date: 2009-08-26 18:44:47 UTC
  • Revision ID: stuart@testtrack4.com-20090826184447-jvmbd5erslz62eji
the top box autorun toggle works just about correctly now. it resets if you change, which is pretty much just the way I was planning, although I can see it being considered the "wrong" behavior.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
--by Stuart P. Bentley (stuart@testtrack4.com)
4
4
--http://sandpad.luaforge.net
5
5
  local version="1.0"
6
 
  local pushed="8/24.2009"
 
6
  local pushed="8/26.2009"
7
7
------------------------------------------------
8
8
 
9
9
-------------------------------------------------------------------------------
106
106
    { 1,1,1,1,1,1,1,2,1,1,1,1,1,1,1,1 }
107
107
    -- Sets star image colors
108
108
    ; colors = { "BGCOLOR", "255 255 255", "0 0 0" }
109
 
    ; bgcolor="BGCOLOR"
110
109
  }
111
110
end
112
111
 
117
116
require "strings"
118
117
require "urls"
119
118
 
120
 
function print(...)
121
 
  local msg = {}
122
 
  local args={...}
123
 
  for i, v in ipairs(args) do
124
 
    msg[#msg+1]=tostring(v)
125
 
    if i~= #args then
126
 
      msg[#msg+1]="\t"
127
 
    end
128
 
  end
129
 
  msg[#msg+1]="\n"
130
 
  if iup2 then
131
 
    returndata.value=returndata.value..table.concat(msg)
132
 
  else
133
 
    returndata.append=table.concat(msg)
134
 
  end
135
 
end
136
 
 
137
119
colors={
138
120
  red="255 0 0",
139
121
  black="0 0 0",
218
200
  --BUG: outermost 1 pixel not updating
219
201
end
220
202
 
 
203
function boxtextbox(i, bgcolor)
 
204
  return iup.multiline{expand="YES",
 
205
    font=values.editfont, tabsize=tabwidth,
 
206
    tip=strings.tips.boxes[i],tipfont="SYSTEM",
 
207
    bgcolor=bgcolor}
 
208
end
 
209
 
 
210
local topboxchanged=false
 
211
local function topboxunauto()
 
212
  topboxchanged=true
 
213
end
 
214
--gets set after the function is creates
 
215
local topboxauto
 
216
 
221
217
boxes={ --individual box definitions
222
 
  --[[on env chains:
223
 
    each env runs from a shadow of the env above it,
224
 
    and when reset (when executing that box's text)
225
 
    remakes all shadows that come after it
226
 
    (since they all need to shadow the new env).
227
 
    env is stored in an index so it can be accessed
228
 
    by the lower boxes' environments.]]
229
 
 
230
218
  [0]={env=defaultenv,prints={}},
231
219
  {--1
232
 
    text=iup.multiline{expand="YES",font=values.editfont,tabsize=tabwidth,
233
 
      tip=strings.tips.boxes[1],tipfont="SYSTEM"},
 
220
    text=boxtextbox(1),
234
221
    color={
235
222
      fParse={ --soon this color will not come into play (String/Lua toggling)
236
223
        bg="255 192 192",
246
233
    }
247
234
  },
248
235
  {--2
249
 
    text=iup.multiline{expand="YES",font=values.editfont,tabsize=tabwidth,
250
 
      fgcolor=colors.black, bgcolor="255 250 223",
251
 
      tip=strings.tips.boxes[2],tipfont="SYSTEM",
252
 
      },
 
236
    text=boxtextbox(2,"255 250 223"),
253
237
    color={
254
238
      fParse={
255
239
        bg="255 255 128",
266
250
          if state==1 then
267
251
            boxes[2].cls.run.title=strings.buttons.autorun
268
252
            setactive(2,"run","NO")
 
253
            boxes[2].text.action=topboxauto
269
254
          else
270
255
            boxes[2].cls.run.title=strings.buttons.run
271
256
            setactive(2,"run","YES")
 
257
            boxes[2].text.action=topboxunauto
272
258
          end
273
259
        end
274
260
      },
275
261
      run=iup.button{title=strings.buttons.autorun,
276
262
        expand="HORIZONTAL",active="NO",--size="x14";
277
263
        action=function()
278
 
          boxes[2]:eval()
 
264
          if topboxchanged then
 
265
            boxes[2]:eval()
 
266
            topboxchanged=false
 
267
          else
 
268
            boxes[2]:run()
 
269
          end
279
270
        end
280
271
      },
281
272
      clear=iup.button{title=strings.buttons.clear,
451
442
  curBox:rechain()
452
443
  curBox:continue()
453
444
end
 
445
topboxauto=boxes[2].text.action
454
446
 
455
447
--print box run setup
456
448
boxes[#boxes].eval=function(self,newcode)
474
466
end
475
467
 
476
468
--this is *partly* because i don't know a better way to preserve
477
 
--the return arguments from print.
 
469
--the return arguments from pcall (what with the possible nils).
478
470
local function outputwith(self,success,...)
479
471
  if not success then
480
472
    self:fExec(...)
503
495
 
504
496
returndata=iup.multiline{font=values.printfont, bgcolor=values.printblank,
505
497
  alignment="ACENTER", border="YES", wordwrap="YES", expand="YES",
506
 
  readonly="YES", value=blankoutput, scrollbar="AUTOHIDE", size=nil,
 
498
  readonly="YES", value=blankoutput, scrollbar="AUTOHIDE",
507
499
  appendnewline="NO", tip=strings.tips.output, tipfont="SYSTEM"}
508
500
 
509
501
local function cheapsettingform(var)