Engine 0.0.6
Game engine in lua
Loading...
Searching...
No Matches
meta.lua
Go to the documentation of this file.
1local application_default = require('src/lib/object/application')
2
3local function replace(src, meta, default)
4 if src and #src > 0 then
5 return (src
6 :gsub('{{id}}', meta.id or default.id)
7 :gsub('{{title}}', meta.title or default.title)
8 :gsub('{{author}}', meta.author or default.author)
9 :gsub('{{company}}', meta.company or default.company)
10 :gsub('{{version}}', meta.version or default.version)
11 :gsub('{{description}}', meta.description or default.description)
12 )
13 end
14 return ''
15end
17local function file(self, file)
18 local file_copy = string.format("%s", file)
19 self.pipeline[#self.pipeline + 1] = function()
20 if not self.loaded then return self end
21
22 local content = ''
23 local file_meta = io.open(file_copy, 'r')
24
25 repeat
26 local line = file_meta:read()
27 content = content..replace(line, self.meta, application_default.meta):gsub('\n', '')..'\n'
28 until not line
29
30 file_meta:close()
31
32 file_meta = io.open(file_copy, 'w')
33
34 file_meta:write(content)
35 file_meta:close()
36 end
37 return self
38end
39
40local function stdout(self, format)
41 local format_copy = string.format("%s", format)
42 if format_copy == 'json' then
43 format_copy = '{"id":"{{id}}","title":"{{title}}","company":"{{company}}",'
44 format_copy = format_copy..'"version":"{{version}}","description":"{{description}}"}'
45 end
46 self.pipeline[#self.pipeline + 1] = function()
47 if not self.loaded then return self end
48 print(replace(format_copy, self.meta, application_default.meta))
49 end
50 return self
51end
52
53local function pipe(self)
54 return function()
55 self:run()
56 end
57end
58
59local function run(self)
60 local index = 1
61 while index <= #self.pipeline do
62 self.pipeline[index]()
63 index = index + 1
64 end
65 return self
66end
67
68local function current(game, application)
69 local gamefile = game and io.open(game, 'r')
70 local bytecode = gamefile and gamefile:read('*a')
71 local metadata = bytecode and (loadstring and loadstring(bytecode) or load(bytecode))
72
73 if gamefile then
74 gamefile:close()
75 end
76
77 while type(metadata) == 'function' do
78 metadata = metadata()
79 end
80
81 if not application then
82 application = {
84 pipeline={},
85 file=file,
87 pipe=pipe,
88 run=run
89 }
90 end
91
92 if metadata then
93 application.loaded = true
94 application.meta = metadata.meta
95 end
96
97 return application
98end
99
100local function late(game)
101 local game_copy = string.format("%s", game)
102 local application = current()
103 local eval = application.run
104 application.run = function()
105 current(game_copy, application)
106 eval(application)
107 end
108 return application
109end
110
111local P = {
113 late = late
114}
115
116return P
local function meta()
local function stdout(self, format)
local application_default
Definition meta.lua:1
local function replace(src, meta, default)
local function pipe(self)
local function current(game, application)
local function run(self)
local function late(game)
local function file(self, file)
local function require(std, game, application)
local application
Definition main.lua:16
local game
Definition main.lua:17
function love load(args)
local function line(x1, y1, x2, y2)