Bootstap Script
Posted: Tue Jul 28, 2009 7:52 pm
So I've been using Love for 24 hours, and it's great! Coming over from Processing (http://www.processing.org), it's refreshing to find a similar community with a cleaner scripting language and more rich physics and geometry.
My only gripe is how verbose the platform API is (love.blah.blah), so I've been writing a bootstrap script to flatten the namespaces (lua, to the rescue!). Right now, it looks like this:
I chose to Pascal-Case things both to avoid naming conflicts, and because it's my preference, coming from a C++ background.
Once run, code is much more economical:
Pointers, anyone?
Again, <3 <3 <3!!!
My only gripe is how verbose the platform API is (love.blah.blah), so I've been writing a bootstrap script to flatten the namespaces (lua, to the rescue!). Right now, it looks like this:
Code: Select all
default_mod = default_mod or _G
function GetFunctionsFrom(mod, into)
into = into or default_mod
for k,v in pairs(mod) do
if type(v) == "function" then
into[k:sub(1,1):upper()..k:sub(2,-1)] = v
end
end
end
function GetConstantsFrom(mod, into)
into = into or default_mod
for k,v in pairs(mod) do
t = type(v)
if t == "number" or t == "string" then
into[k:upper()] = v
end
end
end
GetConstantsFrom(love)
GetFunctionsFrom(love.graphics)
GetFunctionsFrom(love.audio)
GetFunctionsFrom(love.physics)
input = {}
GetFunctionsFrom(love.mouse, input)
GetFunctionsFrom(love.keyboard, input)
GetFunctionsFrom(love.joystick, input)
Once run, code is much more economical:
Code: Select all
love.filesystem.require("bootstrap.lua")
function load()
image = NewImage("icon.png")
font = NewFont(DEFAULT_FONT, 12)
SetFont(font)
SetCaption("Hello, World")
SetBackgroundColor(155,155,255)
input.SetVisible(false)
end
function draw()
SetColor(200,200,255)
Circle(DRAW_FILL, 0.65*GetWidth(), GetHeight()+400, 750, 75)
SetColor(255,255,255)
Drawf("Hello, World!",input.GetX()-50, input.GetY()-35, 100, ALIGN_CENTER)
Draw(image, input.GetX(), input.GetY())
end
Again, <3 <3 <3!!!