------------------------------------------ --アプリ選択メニュ v1.07 ------------------------------------------ --関数宣言-------------------------------- main={} --mainメソッド split={} --指定キャラクタの前後で2つの文字列に分ける directlua={} --実行するluaファイル名の入力 luacexecute={} --luacを実行します --グローバル変数宣言---------------------- Ver = "v1.07" Menu={ "はじめに, hajimeni.lua" , "exitサンプル, exitsample.lua" , "文字表示サンプル, textsample.lua" , "グラフィックサンプル, graphicsample.lua" , "文字入力サンプル, textinput.lua" , "画面タッチサンプル,touchsample.lua" , "Luaファイル直接実行, lua" , "Luaコンパイル, luac" , "ルアリダアプリ選択メニュ "..Ver..", luarida.lua" } LuaridaPath = system.getCardMnt().."/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 ------------------------------------------ --luacを実行します ------------------------------------------ function luacexecute() local BinPath = "/data/data/com.momoonga.luarida/files" local luafilename, a = editText("コンパイルするluaファイル名の入力") local luacfilename = "" local pos, str local i = 0 os.execute( "chmod 755 "..BinPath.."/luac") --luacに実行権限を与えています if( a~=nil and a==1 and luafilename~=nil and luafilename~="" )then --拡張子のチェック pos = string.find(luafilename, "." , i, true ) while(pos~=nil)do i = pos + 1 pos = string.find(luafilename, "." , i, true ) end str = string.sub(luafilename, i, string.len(luafilename) ) if( i==0 or (str~="lua" and str~="luac") )then luafilename = luafilename..".lua" --.luaの追加 end luacfilename = luafilename.."c" --cの追加 os.execute( BinPath.."/luac -s -o "..LuaridaPath.."/"..luacfilename.." "..LuaridaPath.."/"..luafilename) dialog("コンパイル結果",LuaridaPath.."/"..luafilename.." をコンパイルしました",1) else dialog( "コンパイル結果","コンパイルしませんでした",1) end end ------------------------------------------ -- 実行するluaファイル名の入力 ------------------------------------------ function directlua() local luacPath = "" local luafilename, a = editText("実行するluaファイル名の入力") local pos,str local i = 0 if( a~=nil and a==1 and luafilename~=nil and luafilename~="" )then --拡張子のチェック pos = string.find(luafilename, "." , i, true ) while(pos~=nil)do i = pos + 1 pos = string.find(luafilename, "." , i, true ) end str = string.sub(luafilename, i, string.len(luafilename) ) if( i==0 or (str~="lua" and str~="luac") )then luafilename = luafilename..".lua" --.luaの追加 end else luafilename = "luarida.lua" end return luafilename 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タッチでJota Text Editorが立ち上がります" ) if( a~=0 )then for i=1, 1000 do x, y, b = touch() if( b~=1 )then if( tmenu[a]=="lua" or tmenu[a]=="luac" )then tmenu[a] = "luarida.lua" end --エディタ起動 --system.impCallActionView("file://"..LuaridaPath.."/"..tmenu[a], "text/plain") system.expCall( "jp.sblo.pandora.jota.Main", "file://"..LuaridaPath.."/"..tmenu[a], "text/plain" ) dialog("エディタが呼び出せません", "Jota Text Editorをインストールしてください", 1) break end end if( tmenu[a]=="lua" )then tmenu[a] = directlua() elseif( tmenu[a]=="luac" )then luacexecute() tmenu[a] = "luarida.lua" end system.setrun( LuaridaPath.."/"..tmenu[a] ) else dialog( "Luaridaを終了します", "また使ってね", 1 ) --Luaridaを強制終了します El_Psy_Congroo(); --エル・プサイ・コングルゥ end end main()