mirror of
https://github.com/airstruck/luigi.git
synced 2025-11-18 12:25:06 +00:00
Launcher for the LuaJIT backend.
Looks for main.lua. Launch it like this:
luajit myapp/lib/luigi/launch.lua
If luigi isn't inside the project directory, pass
the path containing main.lua as the second argument.
The path must end with a directory separator.
luajit /opt/luigi/launch.lua ./myapp/
If the app prefixes luigi modules with something
other then 'luigi', pass that prefix as the third
argument.
luajit /opt/luigi/launch.lua ./myapp/ lib.luigi
This commit is contained in:
@@ -103,5 +103,5 @@ end)
|
|||||||
-- show the main layout
|
-- show the main layout
|
||||||
layout:show()
|
layout:show()
|
||||||
|
|
||||||
-- only needed when using LuaJIT/SDL
|
-- only needed when using LuaJIT/SDL and not using launch.lua
|
||||||
Backend.run()
|
-- Backend.run()
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
local REL = (...):gsub('[^.]*$', '')
|
local REL = (...):gsub('[^.]*$', '')
|
||||||
|
local APP_ROOT = rawget(_G, 'LUIGI_APP_ROOT') or ''
|
||||||
|
|
||||||
local ffi = require 'ffi'
|
local ffi = require 'ffi'
|
||||||
local sdl = require(REL .. 'sdl')
|
local sdl = require(REL .. 'sdl')
|
||||||
@@ -207,7 +208,7 @@ function Font:constructor (path, size)
|
|||||||
local key = path .. '_' .. size
|
local key = path .. '_' .. size
|
||||||
|
|
||||||
if not fontCache[key] then
|
if not fontCache[key] then
|
||||||
local font = SDL2_ttf.TTF_OpenFont(path, size)
|
local font = SDL2_ttf.TTF_OpenFont(APP_ROOT .. path, size)
|
||||||
|
|
||||||
if font == nil then
|
if font == nil then
|
||||||
error(ffi.string(sdl.getError()))
|
error(ffi.string(sdl.getError()))
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
local REL = (...):gsub('[^.]*$', '')
|
local REL = (...):gsub('[^.]*$', '')
|
||||||
|
local APP_ROOT = rawget(_G, 'LUIGI_APP_ROOT') or ''
|
||||||
|
|
||||||
local ffi = require 'ffi'
|
local ffi = require 'ffi'
|
||||||
local sdl = require(REL .. 'sdl')
|
local sdl = require(REL .. 'sdl')
|
||||||
@@ -15,7 +16,7 @@ end })
|
|||||||
function Image:constructor (renderer, path)
|
function Image:constructor (renderer, path)
|
||||||
self.sdlRenderer = renderer
|
self.sdlRenderer = renderer
|
||||||
self.sdlSurface = ffi.gc(
|
self.sdlSurface = ffi.gc(
|
||||||
SDL2_image.IMG_Load(path),
|
SDL2_image.IMG_Load(APP_ROOT .. path),
|
||||||
sdl.freeSurface)
|
sdl.freeSurface)
|
||||||
|
|
||||||
if self.sdlSurface == nil then
|
if self.sdlSurface == nil then
|
||||||
|
|||||||
54
luigi/launch.lua
Normal file
54
luigi/launch.lua
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
--[[--
|
||||||
|
Launcher for the LuaJIT backend.
|
||||||
|
|
||||||
|
Looks for main.lua. Launch it like this:
|
||||||
|
|
||||||
|
luajit myapp/lib/luigi/launch.lua
|
||||||
|
|
||||||
|
If luigi isn't inside the project directory, pass
|
||||||
|
the path containing main.lua as the second argument.
|
||||||
|
The path must end with a directory separator.
|
||||||
|
|
||||||
|
luajit /opt/luigi/launch.lua ./myapp/
|
||||||
|
|
||||||
|
If the app prefixes luigi modules with something
|
||||||
|
other then 'luigi', pass that prefix as the third
|
||||||
|
argument.
|
||||||
|
|
||||||
|
luajit /opt/luigi/launch.lua ./myapp/ lib.luigi
|
||||||
|
|
||||||
|
--]]--
|
||||||
|
local packagePath = package.path
|
||||||
|
local libRoot = arg[0]:gsub('[^/\\]*%.lua$', '')
|
||||||
|
local appRoot, modPath = ...
|
||||||
|
|
||||||
|
local function run (appRoot, modPath)
|
||||||
|
package.path = packagePath .. ';' .. appRoot .. '?.lua'
|
||||||
|
rawset(_G, 'LUIGI_APP_ROOT', appRoot)
|
||||||
|
require 'main'
|
||||||
|
require (modPath .. '.backend').run()
|
||||||
|
end
|
||||||
|
|
||||||
|
-- expect to find main.lua in appRoot if specified
|
||||||
|
if appRoot then
|
||||||
|
return run(appRoot, modPath or 'luigi')
|
||||||
|
end
|
||||||
|
|
||||||
|
-- try to find main.lua in a parent of this library, recursively.
|
||||||
|
local lastLibRoot = libRoot
|
||||||
|
repeat
|
||||||
|
if io.open(libRoot .. 'main.lua') then
|
||||||
|
return run(libRoot, modPath)
|
||||||
|
end
|
||||||
|
lastLibRoot = libRoot
|
||||||
|
libRoot = libRoot:gsub('([^/\\]*).$', function (m)
|
||||||
|
modPath = modPath and (m .. '.' .. modPath) or m
|
||||||
|
return ''
|
||||||
|
end)
|
||||||
|
until libRoot == lastLibRoot
|
||||||
|
|
||||||
|
error 'main.lua not found'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user