~ubuntu-branches/debian/squeeze/geany-plugins/squeeze

« back to all changes in this revision

Viewing changes to geanylua/examples/work/01.edit-test-script.lua

  • Committer: Bazaar Package Importer
  • Author(s): Chow Loong Jin
  • Date: 2009-07-10 22:56:41 UTC
  • Revision ID: james.westby@ubuntu.com-20090710225641-xc1126t7pq0jmpos
Tags: upstream-0.17.1
ImportĀ upstreamĀ versionĀ 0.17.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
--[[
 
2
  Opens the existing script named "run-test-script.lua" that you can use
 
3
  for development. If the script does not exist it will be created and
 
4
  added to the "Tools->Lua Scripts" menu, under the same menu item as
 
5
  this one.
 
6
--]]
 
7
 
 
8
local test_script=geany.dirname(geany.script)..geany.dirsep.."02.run-test-script.lua"
 
9
 
 
10
local comment='  This is your "scratch pad" for developing new scripts.'
 
11
 
 
12
 
 
13
repeat
 
14
  local stat,err=geany.stat(test_script)
 
15
  if stat then
 
16
    if stat.type=="r" then
 
17
      if geany.open(test_script) == 0 then
 
18
        geany.message("Can't open script!", test_script.."\nAccess denied.")
 
19
      end
 
20
    else
 
21
      geany.message("Can't open script!", test_script.."\nNot a regular file.")
 
22
    end
 
23
    break
 
24
  else
 
25
    if geany.confirm("Can't open script!", test_script..
 
26
               "\n"..err.."\n\nWould you like to create this file?", true)
 
27
    then
 
28
      fh,err=io.open(test_script,"w")
 
29
      if fh then
 
30
        fh:write("--[[\n"..comment.."\n--]]\n\n")
 
31
        if fh:close() then
 
32
          geany.rescan()
 
33
        else
 
34
          geany.message("Can't create script!", "Error saving file.")
 
35
          break
 
36
        end
 
37
      else
 
38
        geany.message("Can't create script!", err)
 
39
        break
 
40
      end
 
41
    else
 
42
      break
 
43
    end
 
44
  end
 
45
until false