From ed8925b28dbb66383a5931165b82f0eaa97385f9 Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Thu, 3 Apr 2014 07:34:06 +1000 Subject: Read in any matching .skang files in moduleBegin(). --- ClientHamr/GuiLua/skang.lua | 10 +++++++++- ClientHamr/GuiLua/test.lua | 26 +++++++++----------------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/ClientHamr/GuiLua/skang.lua b/ClientHamr/GuiLua/skang.lua index d5622fd..bd05031 100644 --- a/ClientHamr/GuiLua/skang.lua +++ b/ClientHamr/GuiLua/skang.lua @@ -116,7 +116,15 @@ moduleBegin = function (name, author, copyright, version, timestamp, skin, isLua end _M.VERSION = version .. versionName .. timestamp _M.VERSION_DESC = versionDesc - -- TODO - If there's no skin passed in, try to find the file skin .. '.skang' and load that instead. + -- If there is a .skang file, read that in and override the passed in skin. + local f = io.open(name .. '.skang') + if f then + skin = f:read('*l') + if '#' == string.sub(skin, 1, 1) then skin = '' end + skin = skin .. f:read('*a') + f:close() + end + if skin then skin = "local skang = require 'skang'\nlocal this = require 'test'\n" .. skin end _M.DEFAULT_SKANG = skin --_G[_M._NAME] = _M -- Stuff it into a global of the same name. diff --git a/ClientHamr/GuiLua/test.lua b/ClientHamr/GuiLua/test.lua index 4ddbc1d..f45aff9 100644 --- a/ClientHamr/GuiLua/test.lua +++ b/ClientHamr/GuiLua/test.lua @@ -4,26 +4,14 @@ do -- Only I'm not gonna indent this. local skang = require 'skang' local _M = skang.moduleBegin('test', nil, 'Copyright 2014 David Seikel', '0.1', '2014-03-27 03:57:00', [[ -#!/usr/bin/env skang -- Lua allows this shell hack. + local widget = require 'widget' --- There's an implied local this = require 'test' --- There's an implied local skang = require 'skang' - -local widget = require 'widget' --- local other = require 'otherPackageName' - -skang.clear -skang.window(200, 200, "G'day planet.") - -quitter = widget.button('Quit', 0.5, 0.5, 0.5, 0.5) -quitter:action('quit') -- 'quit' is looked up in ThingSpace.commands, and translated into the Lua 'skang.quit()'. - ---other.foo = 'stuff' -this.bar = 'things' -this.func(1, 'two') + skang.clear + skang.window(200, 200, "G'day planet.") + quitter = widget.button('Quit', 0.5, 0.5, 0.5, 0.5) + quitter:action('quit') ]]) - print('code') -- A variable that is private to this module. @@ -53,6 +41,10 @@ local test_c = require 'test_c' local copy = skang.copy(test, 'copy') print('End ' .. test.bar .. ' ' .. test.VERSION .. ' ' .. skang.get(test, 'ffunc', 'help') .. ' ->> ' .. skang.get(test, 'f', 'action')) + +print(test.DEFAULT_SKANG) +print('') + print('foo = ' .. test.foo .. ' ->> ' .. skang.get(test, 'foo', 'help')) print('cfooble = ' .. test_c.cfooble .. ' ->> ' .. skang.get(test_c, 'cfooble', 'help') .. '[' .. skang.get(test_c, 'cfooble', 'widget') .. ']') print('cfunc ->> ' .. skang.get(test_c, 'cfunc', 'help')) -- cgit v1.1