-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3a72c40
commit 8643380
Showing
4 changed files
with
61 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,25 @@ | ||
Rectangle = {'area': 0, 'length': 0, 'breadth': 0} | ||
Rect = {'width': 0, 'height': 0} | ||
|
||
fn Rectangle:new(o,length,breadth) { | ||
o = o or {} | ||
setmetatable(o, self) | ||
self.__index = self | ||
self.length = length or 0 | ||
self.breadth = breadth or 0 | ||
self.area = length*breadth; | ||
rt o | ||
fn Rect:new() { | ||
o = {} | ||
for k, v in Rect { | ||
o[k] = v | ||
} | ||
rt o | ||
} | ||
|
||
fn Rectangle:printArea() { | ||
print("矩形面积为 ", self.area) | ||
fn Rect:square(len) { | ||
o = self:new() | ||
o.width = len | ||
o.height = len | ||
rt o | ||
} | ||
|
||
shy rect = Rectangle:new(nil, 10, 20) | ||
rect:printArea() | ||
fn Rect:printArea() { | ||
print("Rect area: ", self.width * self.height) | ||
} | ||
|
||
fn Rect:set(width, height) { | ||
self.width = width | ||
self.height = height | ||
} |