svlad

Check-in [4da807b56b]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:First working version.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:4da807b56bb7a0eb5bd9302e2055bae66d214381
User & Date: severak 2012-04-15 13:41:06
Context
2012-04-15
15:30
Now able to connect to database and do some queries and display results. check-in: 831243892a user: severak tags: trunk
13:41
First working version. check-in: 4da807b56b user: severak tags: trunk
13:01
initial empty check-in check-in: a54fa77d51 user: Spravce tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Added jo.lua.









































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
module('jo',package.seeall)

--author: Anonymous
--License: MIT/X11
--http://snippets.luacode.org/snippets/Deep_copy_of_a_Lua_Table_2
function deepcopy(t)
    if type(t) ~= 'table' then return t end
    local mt = getmetatable(t)
    local res = {}
    for k,v in pairs(t) do
      if type(v) == 'table' then
        v = deepcopy(v)
      end
      res[k] = v
    end
    setmetatable(res,mt)
    return res
end

--author: RCIX from stackoverflow
--based on code by Doug Currie
--http://stackoverflow.com/questions/1283388/lua-merge-tables
function tableMerge(t1, t2)
    for k,v in pairs(t2) do
        if type(v) == "table" then
                if type(t1[k] or false) == "table" then
                        tableMerge(t1[k] or {}, t2[k] or {})
                else
                        t1[k] = v
                end
        else
                t1[k] = v
        end
    end
    return t1
end

--author: Steven Donovan
--license: MIT/X11
--http://snippets.luacode.org/snippets/Simple_Table_Dump_7
function dump(o)
  if type(o) == 'table' then
    local s = '{ '
    for k,v in pairs(o) do
      if type(k) ~= 'number' then k = '"'..k..'"' end
        s = s .. '['..k..'] = ' .. dump(v) .. ','
    end
    return s .. '} '
  else
    return tostring(o)
  end
end

object={
--documentation-----------------------------------------------------------------  
  _H={
    _Name="jo.object",
    _basic="Basic jo object. It can be also some it's undocumented descendants.",
    _usage=
[[Clone this object by

    newInstance=jo.object:clone()

then you can change it by calling rewriteSlots function with an change table parameter

    newInstance:rewriteSlots({changed=1})
]],
    clone={
      _Name="clone()",
      _basic="Clones object. Returns its clone.",
      _example=" \n    clonedObject=someObject:clone()"
    },
    rewriteSlots={
      _Name="rewriteSlots(t)",
      _basic="Merges object with its parameter t. Used to adding new features.",
      _example=
[[
    --changes color and adds new function getColor
    --assume that oldObject.color="red"
    oldObject:rewriteSlots({
      color="blue",
      getColor=function(self)
        return self.color
      end
    })
]]
    }    
  },
--------------------------------------------------------------------------------  
  clone=function(self)
    local new=deepcopy(self)
    return new  
  end,
  
  rewriteSlots=function(self,add)
    return tableMerge(self,add)
  end 
}


helpful={
  help=function(self,theme)
    local chapters=self._H
    
    if not chapters then
       return false
    end
    
    if theme then
      if chapters[theme] then
        chapters=chapters[theme]
      else
         print("Undocumented feature or missing function. Object help shown instead.")
      end
    end
    
    if chapters._Name~=nil then
      print(chapters._Name)
      print(string.rep("=",string.len(chapters._Name)))
    end
    
    for k,v in pairs(chapters) do
      if string.sub(k,1,1)=="_" and k~="_Name" then
        print("##"..string.sub(k,2))
        print(v)
        print("")
      end
    end
  end
}

jo.object:rewriteSlots(jo.helpful)

Added jo/geometry.lua.

































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
module("jo.geometry",package.seeall)

require "math"
require "jo"
require "jo.utils"

point=jo.object:clone():rewriteSlots({
  x=0,
  y=0,
  
  with=function(self,x,y)
    self.x=x
    self.y=y
    return self
  end,
  
  distanceFrom=function(self,b)
    if jo.utils.validateSlots(b, { x="number",y="number" }) then
      return math.sqrt(math.pow(self.x-b.x,2)+math.pow(self.y-b.y,2))
    end
    return nil
  end
  
})

vector=jo.object:clone():rewriteSlots({
  sx=0,
  sy=0,
  
  

})

Added jo/utils.lua.





































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
module("jo.utils",package.seeall)
require "jo"

singleton={
  clone=function(self)
    error("One doesn't simply clone singleton.")
    return false
  end
}

function validateSlots(o,t)
  for k,v in pairs(t) do
    if type(o[k])~=v then
      return false
    end
  end
  return true
end

Added svlad-gui.lua.







































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
--Skeleton SVLADa
require "vcl"

function nasobilka()
  for x=1,9 do
    for y=1,9 do
      tabl:SetCell(x,y,x*y)
    end
  end
end

function sql_dotaz(sender)
  dotaz=table.concat(sql:GetText())
  VCL.ShowMessage(table.concat(sql:GetText(),"\n"))
  if dotaz=="nasobilka" then
    nasobilka()
  end
end

main=VCL.Form("mainWin")
main._={ caption="Svlad", width=500, height=500 }

tabl=VCL.StringGrid(main,"table")
tabl._={ align="alClient", rowCount=99, ColCount=99, AutoEdit=true }

p=VCL.Panel(main,"panel")
p._={ align="alBottom", height=90 }

sql=VCL.Memo(p,"sql")
sql._={ align="alClient",  font={name="Courier"} }

fire=VCL.Button(p,"fire")
fire._={ align="alBottom", caption="PAL!", onclick="sql_dotaz" }

main:ShowModal()

Added svlad.lua.







































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
--Skeleton SVLADa
require "vcl"

function nasobilka()
  for x=1,9 do
    for y=1,9 do
      tabl:SetCell(x,y,x*y)
    end
  end
end

function sql_dotaz(sender)
  dotaz=table.concat(sql:GetText())
  VCL.ShowMessage(table.concat(sql:GetText(),"\n"))
  if dotaz=="nasobilka" then
    nasobilka()
  end
end

main=VCL.Form("mainWin")
main._={ caption="Svlad", width=500, height=500 }

tabl=VCL.StringGrid(main,"table")
tabl._={ align="alClient", rowCount=99, ColCount=99, AutoEdit=true }

p=VCL.Panel(main,"panel")
p._={ align="alBottom", height=90 }

sql=VCL.Memo(p,"sql")
sql._={ align="alClient",  font={name="Courier"} }

fire=VCL.Button(p,"fire")
fire._={ align="alBottom", caption="PAL!", onclick="sql_dotaz" }

main:ShowModal()

Added zoo.lua.































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
require "jo"

helpful={
  help=function(self)
    for k,v in pairs(self._H) do
      print(string.upper(k))
      print(v)
      print("")
    end
  end
}

animal=jo.object:clone():rewriteSlots({
  living=true,
  name="animal",
  breath=function(self)
    print(self.name..": Aaaach!")
  end,
  _H={_Name="an animal",_basic="An animal."}
  
})

bird=animal:clone():rewriteSlots({
  name="bird",
  beep=function(self)
     print(self.name..":Tweeet!")
  end,
  _H={_Name="a bird"}
})

crow=bird:clone():rewriteSlots({
  color="black",
  beep=function(self)
     print(self.name..":Crou! Crou!")
  end,
  _H={_Name="a crow",_usage="Can beep and breath."}
})

Jarku=crow:clone()
Jarku.name="Jarku"

Jarku:breath()
Jarku:beep()
print("Jarku is "..Jarku.color..".")

Jarku:rewriteSlots(jo.helpful):help()