ADG Lua 

ADG Lua Commit Details

Date:2013-03-21 10:47:14 (6 years 5 months ago)
Author:Nicola Fontana
Branch:master
Commit:4e851bbaec07fcc540bc3b3425844667852d23c0
Parents: ebb308fd73f817cc13c61a66b0c0641025c15577
Message:adg-demo: improved cache data generation

Changes:
Mpiston.lua (9 diffs)

File differences

piston.lua
2626
2727
2828
29
2930
3031
3132
......
4748
4849
4950
50
51
5152
5253
5354
......
5758
5859
5960
60
61
6162
62
63
6364
6465
6566
......
191192
192193
193194
194
195
195196
196
197
197198
198199
199200
200201
201202
202
203
203204
204
205
205206
206207
207208
......
237238
238239
239240
240
241
241242
242243
243244
......
432433
433434
434435
435
436
436437
437438
438439
......
455456
456457
457458
459
460
461
462
463
464
465
458466
459467
460468
......
462470
463471
464472
465
466
467
468
469
470
471
472
473
473474
474475
475476
......
477478
478479
479480
480
481
482
483
484
485
486
487
481
488482
489483
490484
local Adg = lgi.require 'Adg'
local SQRT3 = math.sqrt(3)
local generator = {}
-- Backward compatibility
-- MODEL
-----------------------------------------------------------------
local model = {}
generator.model = {}
local constructor = {}
-- Inject the regenerate method into Adg.Model
constructor[model](part, model)
end)
function model.body(part, path)
function generator.model.body(part, path)
path = path or Adg.Path {}
constructor[path] = model.body
constructor[path] = generator.model.body
local data = part.data
return path
end
function model.edges(part, edges)
function generator.model.edges(part, edges)
edges = edges or Adg.Edges {}
constructor[edges] = model.edges
constructor[edges] = generator.model.edges
edges:set_source(part.model.body)
return edges
end
function model.hole(part, path)
function generator.model.hole(part, path)
path = path or Adg.Path {}
constructor[path] = model.hole
constructor[path] = generator.model.hole
local data = part.data
-- VIEW
-----------------------------------------------------------------
local view = {}
generator.view = {}
-- Inject the export method into Adg.Canvas
rawset(Adg.Canvas, 'export', function (canvas, file)
canvas:add(dim)
end
function view.detailed(part)
function generator.view.detailed(part)
local canvas = Adg.Canvas {}
local model = part.model
function controller.new(data)
local part = {}
local function generate(class, method)
local constructor = generator[class][method]
local result = constructor and constructor(part) or false
part[class][method] = result
return result
end
-- data: numbers and strings needed to define the whole part
part.data = data or {}
part.model = {}
setmetatable(part.model, {
__index = function (self, key)
-- Check if the model name is valid
if not model[key] then return end
-- Create the model and store it into the cache
self[key] = model[key](part)
-- Return the cached result
return self[key]
return generate('model', key)
end
})
part.view = {}
setmetatable(part.view, {
__index = function (self, key)
-- Check if the view name is valid
if not view[key] then return end
-- Create the view and store it into the cache
self[key] = view[key](part)
-- Return the cached result
return self[key]
return generate('view', key)
end
})

Archive Download the corresponding diff file

Branches

Tags