Permalink
Browse files

Lots of problems. I'm going to write this program in Ruby...

  • Loading branch information...
BlackBulletIV committed Mar 22, 2011
1 parent 14a6ad3 commit c4b38cb0a1c2ae79e9eb1d8a3650efdb9ced2ae6
Showing with 84 additions and 23 deletions.
  1. +1 −2 bin/config.lua
  2. +42 −18 bin/functions.lua
  3. +32 −0 bin/generate.lua
  4. +9 −3 bin/grace
View
@@ -4,9 +4,8 @@
grace.config.platform = 'unix'
--[[
- The directory this file is located in. NO TRAILING SLASH!
+ See the main grace program to edit grace.config.programLocation
--]]
-grace.config.programLocation = '/Users/michael/Sites/libraries/Lua/grace/bin'
--[[
What project template to use by default.
View
@@ -1,3 +1,4 @@
+-- command execution
function execute(cmd, windowsCmd)
local tmp = os.tmpname()
@@ -14,6 +15,7 @@ function execute(cmd, windowsCmd)
return result
end
+-- directory listing
function ls(dir)
local list = execute('ls -a1 ' .. dir, 'dir /b ' .. dir)
local ret = {}
@@ -25,24 +27,7 @@ function ls(dir)
return ret
end
-function isDir(file)
- local result = execute('file ' .. file, 'dir ' .. file)
-
- if grace.config.platform == 'windows' then
- if result:find('.+%s+%<DIR%>%s+%.') then
- return true
- else
- return false
- end
- else
- if result:find(file .. ': directory') then
- return true
- else
- return false
- end
- end
-end
-
+-- get current working directory
function pwd()
local dir = execute('pwd', 'cd')
@@ -53,6 +38,7 @@ function pwd()
return dir:gsub('[\r\n]', '')
end
+-- change working directory
function cd(dir)
if grace.config.platform == 'windows' then
dir = dir:gsub('/', '\\')
@@ -61,6 +47,7 @@ function cd(dir)
os.execute('cd ' .. dir)
end
+-- make directory
function mkdir(dir)
if grace.config.platform == 'windows' then
dir = dir:gsub('/', '\\')
@@ -69,6 +56,7 @@ function mkdir(dir)
os.execute('mkdir ' .. dir)
end
+-- copy recursively: cp -R
function cpr(source, destination)
if grace.config.platform == 'windows' then
source = source:gsub('/', '\\')
@@ -81,10 +69,46 @@ function cpr(source, destination)
execute('cp -R ' .. source .. ' ' .. destination, 'xcopy /E ' .. source .. ' ' .. destination)
end
+-- make sure path ends with slash
function endSlash(path)
if path:sub(path:len()) == '/' then
return path
else
return path .. '/'
end
end
+
+-- is this a directory?
+function isDir(file)
+ local result = execute('file ' .. file, 'dir ' .. file)
+
+ if grace.config.platform == 'windows' then
+ if result:find('.+%s+%<DIR%>%s+%.') then
+ return true
+ else
+ return false
+ end
+ else
+ if result:find(file .. ': directory') then
+ return true
+ else
+ return false
+ end
+ end
+end
+
+function graceDir(dir)
+ local f = io.open(endSlash(dir) .. '.grace')
+
+ if f then
+ f:close()
+ return dir
+ else
+ local path = dir:gsub('[\r\n\t]', '')
+ if path == '/' or path == 'C:/' then -- note sure if C:/ works
+ return false
+ else
+ return graceDir(endSlash(dir) .. '..')
+ end
+ end
+end
View
@@ -0,0 +1,32 @@
+function run()
+ if not graceDir('.') then error('This is not a Grace project.') end
+ if not args[2] then error("Please specify what to generate: 'entity' or 'world'.") end
+ if not args[3] then error("Please specify the name for the " .. args[2] .. ".") end
+
+ local dir = endSlash(graceDir('.'))
+
+ if args[2] == 'entity' then
+ local name = love.path.leaf(args[3])
+ local f = io.open(dir .. 'entities/' .. args[3] .. '.lua', 'w')
+
+ f:write(
+ name .. " = class('" .. name .. "', Entity)\n" ..
+ "\n" ..
+ "function " .. name .. ":initialize()\n" ..
+ love.config.indentation .. "Entity.initialize(self)\n" ..
+ "end\n" ..
+ "\n" ..
+ "function " .. name .. ":added()\n" ..
+ love.config.indentation .. "\n" ..
+ "end\n" ..
+ "\n" ..
+ "function " .. name .. ":removed()\n" ..
+ love.config.indentation .. "\n" ..
+ "end\n" ..
+ "\n" ..
+ "function " .. ":update(dt, rdt)\n" ..
+ love.config.indentation .. "Entity.update(self, dt, rdt)\n" ..
+ "end\n"
+ )
+ end
+end
View
@@ -8,16 +8,22 @@ command = {}
-- grace and commands
grace = {}
grace.config = {}
+
+--[[
+ The directory this file is located in. NO TRAILING SLASH!
+--]]
+grace.config.programLocation = '/Users/michael/Sites/libraries/Lua/grace/bin'
+
commands = {
new = 'new',
generate = 'generate',
g = 'generate'
}
-- get required files
-require('optparse')
-require('config')
-require('functions')
+require(grace.config.programLocation .. '/optparse.lua')
+require(grace.config.programLocation .. '/config')
+require(grace.config.programLocation .. '/functions')
-- create optparse
optparse = OptionParser({ help = 'Foo', version =

0 comments on commit c4b38cb

Please sign in to comment.