コンピュータを楽しもう!!

今、自分が面白くていろいろやってみたことを書き綴りたいと思います。連絡先はtarosa.yでgmail.comです。

Luaridaメニュ編 (2)

Luarida v1.21Betaではメニュから呼び出すエディタをsheditor liteに固定しました。下記の例system.expCall()しているところが変更点です。

------------------------------------------
--アプリ選択メニュ
------------------------------------------
--関数宣言--------------------------------
main={}  --mainメソッド
split={} --指定キャラクタの前後で2つの文字列に分ける
--グローバル変数宣言----------------------
Menu={
  "はじめに, hajimeni.lua"
, "exitサンプル, exitsample.lua"
, "加速度センササンプル, gsensorsample.lua"
, "ラジオボタンサンプル, radiobuttonsample.lua"
, "リストサンプル, listsample.lua"
, "エディットサンプル, editlua.lua"
, "画像ファイルサンプル, bitmapsample.lua"
, "チェックリストサンプル, checklist.lua"
, "文字表示サンプル, textsample.lua"
, "グラフィックサンプル, graphicsample.lua"
, "Dialogのサンプル, dialogsample.lua"
, "文字入力サンプル, textinput.lua"
, "画面タッチサンプル,touchsample.lua"
, "簡単Lua電卓, dentaku.lua"
, "明示的アプリ呼び出しサンプル, explicitsample.lua"
, "暗黙のアプリ呼び出しサンプル, implicitsample.lua"
, "ルアリダアプリ選択メニュ, luarida.lua"
}
Path="/sdcard/luarida/"	--luaファイルを保存しているPath
------------------------------------------
mt={}
mt.__newindex=function(mtt,mtn,mtv)
 dialog( "Error Message", "宣言していない変数 "..mtn.." に値を入れようとしています", 0 )
 toast("画面タッチで実行を続けます", 1)
 touch(3)
end
mt.__index=function(mtt,mtn)
 dialog( "Error Message", "変数 "..mtn.." は宣言されていません", 0 )
 toast("画面タッチで実行を続けます", 1)
 touch(3)
end
setmetatable(_G,mt)
--------以下が実プログラム----------------
------------------------------------------
--文字の分解
------------------------------------------
function split(str, d)
local s = str
local t = {}
local p = "%s*(.-)%s*"..d.."%s*"
local f = function(v) table.insert(t, v) end
 if s ~= nil then
   string.gsub(s, p, f)
   f(string.gsub(s, p, ""))
 end
 return t
end
------------------------------------------
--メインプログラム
------------------------------------------
function main()
local t={}
local tmenu={}
local a, i
local key
local value
local x, y, b
 canvas.drawCls( color(0,0,255) ) --背景を青に
 item.clear()                     --item Listのclear
 --menuテーブルを分解してitem Listに追加していく
 for key,value in pairs( Menu ) do
   t = split( value, "," )
   item.add( t[1], 0 )
   tmenu[key] = t[2]              --実行ファイル名をtmenuに取得
 end
 --リスト選択
 a = item.list("Luarida Ver."..system.version().."\n2タッチでエディタが立ち上がります" )
 if( a~=0 )then		
   for i=1, 300 do
     x, y, b = touch()
     if( b~=1 )then
       	--エディタ起動
        --system.impCallActionView("file://"..Path..tmenu[a], "text/plain")
        system.expCall( "info.tdoc.sheditor.EditMain", "file://"..Path..tmenu[a], "text/plain" )
        break
     end
   end
   system.setrun( Path..tmenu[a] )
 else
   dialog( "Luaridaを終了します", "また使ってね", 1 )
   --Luaridaを強制終了します
   system.exit()
 end
end
main()