diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..65f66343 --- /dev/null +++ b/.gitignore @@ -0,0 +1,14 @@ +# Idea +.Idea + +# Xcode +*.xcuserstate +project.xcworkspace/ +xcuserdata/ + +# others +.git_old_branch + +# Pods +TaobaoEnv +IOS/Demo/Pods/* diff --git a/Android/.gitignore b/Android/.gitignore new file mode 100644 index 00000000..c286a992 --- /dev/null +++ b/Android/.gitignore @@ -0,0 +1,9 @@ +# Created by .ignore support plugin (hsz.mobi) +# IntelliJ project files +.idea +.gradle +build +gradle +local.properties +*.iml +build/intermediates/dex-cache/cache.xml \ No newline at end of file diff --git a/Android/.gradle/2.2/taskArtifacts/cache.properties.lock b/Android/.gradle/2.2/taskArtifacts/cache.properties.lock new file mode 100644 index 00000000..b821389f Binary files /dev/null and b/Android/.gradle/2.2/taskArtifacts/cache.properties.lock differ diff --git a/Android/.gradle/2.2/taskArtifacts/fileHashes.bin b/Android/.gradle/2.2/taskArtifacts/fileHashes.bin new file mode 100644 index 00000000..ef6abf8c Binary files /dev/null and b/Android/.gradle/2.2/taskArtifacts/fileHashes.bin differ diff --git a/Android/.gradle/2.2/taskArtifacts/fileSnapshots.bin b/Android/.gradle/2.2/taskArtifacts/fileSnapshots.bin new file mode 100644 index 00000000..ea706a56 Binary files /dev/null and b/Android/.gradle/2.2/taskArtifacts/fileSnapshots.bin differ diff --git a/Android/.gradle/2.2/taskArtifacts/outputFileStates.bin b/Android/.gradle/2.2/taskArtifacts/outputFileStates.bin new file mode 100644 index 00000000..56023c2d Binary files /dev/null and b/Android/.gradle/2.2/taskArtifacts/outputFileStates.bin differ diff --git a/Android/.gradle/2.2/taskArtifacts/taskArtifacts.bin b/Android/.gradle/2.2/taskArtifacts/taskArtifacts.bin new file mode 100644 index 00000000..5bd253b3 Binary files /dev/null and b/Android/.gradle/2.2/taskArtifacts/taskArtifacts.bin differ diff --git a/Android/LICENSE b/Android/LICENSE new file mode 100644 index 00000000..f2d12cc5 --- /dev/null +++ b/Android/LICENSE @@ -0,0 +1,20 @@ +The MIT License (MIT) + +Copyright (c) 2017 Alibaba Group + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. \ No newline at end of file diff --git a/Android/LuaViewDemo/.gitignore b/Android/LuaViewDemo/.gitignore new file mode 100644 index 00000000..b3fdf275 --- /dev/null +++ b/Android/LuaViewDemo/.gitignore @@ -0,0 +1,2 @@ +build +target \ No newline at end of file diff --git a/Android/LuaViewDemo/AndroidManifest.xml b/Android/LuaViewDemo/AndroidManifest.xml new file mode 100644 index 00000000..27ba6fb2 --- /dev/null +++ b/Android/LuaViewDemo/AndroidManifest.xml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Android/LuaViewDemo/LuaViewDemo.iml b/Android/LuaViewDemo/LuaViewDemo.iml new file mode 100644 index 00000000..5a9396ff --- /dev/null +++ b/Android/LuaViewDemo/LuaViewDemo.iml @@ -0,0 +1,106 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Android/LuaViewDemo/assets/luaview/test.szip b/Android/LuaViewDemo/assets/luaview/test.szip new file mode 100644 index 00000000..f9727acc Binary files /dev/null and b/Android/LuaViewDemo/assets/luaview/test.szip differ diff --git a/Android/LuaViewDemo/assets/test-standard/NUI_AudioPlayer.lua b/Android/LuaViewDemo/assets/test-standard/NUI_AudioPlayer.lua new file mode 100644 index 00000000..2d870595 --- /dev/null +++ b/Android/LuaViewDemo/assets/test-standard/NUI_AudioPlayer.lua @@ -0,0 +1,65 @@ +-- Created by LuaView. +-- Copyright (c) 2017, Alibaba Group. All rights reserved. +-- +-- This source code is licensed under the MIT. +-- For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + +w, h = System:screenSize(); + +local player1 = AudioPlayer(); + +button1 = Button(); +button1:title("播放音效-url"); +button1:callback(function() + if (player1) then + player1:play("http://dx.sc.chinaz.com/files/download/sound1/201308/3381.wav", 2); + end +end) + +button2 = Button(); +button2:title("播放音效-本地"); +button2:xy(200, 0) +button2:callback(function() + if (player1) then + player1:play("music/test.mp3", 0); + end +end) + +button1_pause = Button(); +button1_pause:title("pause") +button1_pause:xy(0, 50) +button1_pause:callback(function() + if (player1) then + player1:pause(); + end +end) + +button1_resume = Button(); +button1_resume:title("resume") +button1_resume:xy(200, 50) +button1_resume:callback(function() + if (player1) then + player1:resume(); + end +end) + +t = { + a = function() + print('a called', t.c) + end, + b = function() + print('b called', t.c) + end, + c = 1 +} + +t.a() +t.b() + + + + + + + + diff --git a/Android/LuaViewDemo/assets/test-standard/NUI_DynamicCode.lua b/Android/LuaViewDemo/assets/test-standard/NUI_DynamicCode.lua new file mode 100644 index 00000000..8ede8555 --- /dev/null +++ b/Android/LuaViewDemo/assets/test-standard/NUI_DynamicCode.lua @@ -0,0 +1,35 @@ +-- Created by LuaView. +-- Copyright (c) 2017, Alibaba Group. All rights reserved. +-- +-- This source code is licensed under the MIT. +-- For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + +-- Created by LuaView. +-- Copyright (c) 2017, Alibaba Group. All rights reserved. +-- +-- This source code is licensed under the MIT. +-- For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + +code = [[ + a = {} + a.x = function() + local btn = Button() + btn:frame(0, 0, 100, 100) + btn:text("button") +-- btn:callback(function +-- Toast("btn clicked") +-- end) + end + + a.x() +]] + + +--hi = load(code) +--hi() + + + +load("local btn = Button(); btn:text('yyy'); btn:callback(function Toast('x') end)")() + + diff --git a/Android/LuaViewDemo/assets/test-standard/NUI_File.lua b/Android/LuaViewDemo/assets/test-standard/NUI_File.lua new file mode 100644 index 00000000..c3b2bfc0 --- /dev/null +++ b/Android/LuaViewDemo/assets/test-standard/NUI_File.lua @@ -0,0 +1,97 @@ +-- Created by LuaView. +-- Copyright (c) 2017, Alibaba Group. All rights reserved. +-- +-- This source code is licensed under the MIT. +-- For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + +-- Created by LuaView. +-- Copyright (c) 2017, Alibaba Group. All rights reserved. +-- +-- This source code is licensed under the MIT. +-- For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + + +local label = Label() +label:text("请看日志输出") +label:frame(0, 0, System.screenSize()) + +http = Http() +http:get("http://www.baidu.com", { + query = 1 +}, function(response) + local data = response:data() + + print(data) + test1(data) + test2(data) + test3(data) +end) + + +function test1(data) + print("-------------------------test1---------------------") + print("save", File.save(data, "test.html")) + print("read", File.read("test.html")) + print("path", File.path("test.html")) + print("exists", File.exists("test.html")) + print("--------------------------test1---------------------") +end + +function test2(data) + print("-------------------------test2---------------------") + print("save", File.save(data, "demo/test.html")) + print("read", File.read("demo/test.html")) + print("path", File.path("demo/test.html")) + print("exists", File.exists("demo/test.html")) + print("--------------------------test2---------------------") +end + +function test3(data) + print("-------------------------test3---------------------") + print("save", File.save(data, "../../../common/test.html")) + print("read", File.read("../../../common/test.html")) + print("path", File.path("../../../common/test.html")) + print("exists", File.exists("../../../common/test.html")) + print("--------------------------test3---------------------") +end + +function test4(data) + print("-------------------------test4---------------------") + + File.save(data, "test1.html", function(status) + print("file saved", status, File.exists("test1.html")) + print("read1", File.read("test1.html"), "xxx") + + + print("path2", File.path("test1.html")) + print("exists1", File.exists("test1.html")) + print("exists3", File.exists("test2.html")) + + File.read("test1.html", function(data) + print("read2", data) + print("-------------------------test4---------------------") + end) + end) + + +end + + + + +http = Http() +http:get("https://gju1.alicdn.com/bao/uploaded/i4/100000120700895002/TB2Qu0_fXXXXXb9XpXXXXXXXXXX_!!0-0-juitemmedia.jpg_560x560Q90.jpg", function(response) + local data = response:data() + + File.save(data, "../common/test.png") + + File.read("../common/test.png", function(data) + local img = Image() + img:frame(0, 0, 100, 100) + img:image("../common/test.png") + + local img2 = Image() + img2:frame(101, 0, 100, 100) + img2:image(data) + end) +end) \ No newline at end of file diff --git a/Android/LuaViewDemo/assets/test-standard/UI_HScrollView.lua b/Android/LuaViewDemo/assets/test-standard/UI_HScrollView.lua new file mode 100644 index 00000000..f1462922 --- /dev/null +++ b/Android/LuaViewDemo/assets/test-standard/UI_HScrollView.lua @@ -0,0 +1,26 @@ +-- 活动指示器 +local SCREEN_WIDTH = System:screenSize() + +local scrollView = HScrollView() + + +for i = 0, 10, 1 do + local btn = Label() + btn:text("BTN" .. i) + btn:frame(i * 60, 10, 59, 80) + btn:backgroundColor(0xff00ff00) + scrollView:addView(btn) +end + +scrollView:xy(0, 300) +scrollView:size(SCREEN_WIDTH, 100) +scrollView:backgroundColor(0xffcccccc) +scrollView:showScrollIndicator(false) + + +scrollView:callback({ + Scrolling = function(x, y) + print("Scrolling", x, y) + print(scrollView:offset()) + end +}) diff --git a/Android/LuaViewDemo/assets/test-standard/music/test.mp3 b/Android/LuaViewDemo/assets/test-standard/music/test.mp3 new file mode 100644 index 00000000..6ce1f6ee Binary files /dev/null and b/Android/LuaViewDemo/assets/test-standard/music/test.mp3 differ diff --git a/Android/LuaViewDemo/assets/test/11UI_Matrix.lua b/Android/LuaViewDemo/assets/test/11UI_Matrix.lua new file mode 100644 index 00000000..9e57074f --- /dev/null +++ b/Android/LuaViewDemo/assets/test/11UI_Matrix.lua @@ -0,0 +1,24 @@ +-- Created by LuaView. +-- Copyright (c) 2017, Alibaba Group. All rights reserved. +-- +-- This source code is licensed under the MIT. +-- For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + +view = Image(); +view.backgroundColor(0xff0000, 0.3) +view.image("animate1") +view.frame(0, 64, 200, 200) + +view.callback(function() + --view.matrix( {2,3,4,5,6,7} ); + view.matrix(1, 2, 1, 1, 0, 1); + + arr = view.matrix(); + print(arr[1],arr[2],arr[3],arr[4],arr[5],arr[6] ); + + view.invalidate() + + Toast("done") + +end) + diff --git a/Android/LuaViewDemo/assets/test/DEMO_Time.lua b/Android/LuaViewDemo/assets/test/DEMO_Time.lua new file mode 100644 index 00000000..beb3eeb8 --- /dev/null +++ b/Android/LuaViewDemo/assets/test/DEMO_Time.lua @@ -0,0 +1,44 @@ +-- Created by LuaView. +-- Copyright (c) 2017, Alibaba Group. All rights reserved. +-- +-- This source code is licensed under the MIT. +-- For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + +view1 = View() +view1.cornerRadius(25) +view1.frame(50, 50, 100, 20) +view1.backgroundColor(0x0000ff, 0.5) + + +container = View() +container.frame(51, 51, 10, 20) + + +view2 = View() +container.addView(view2) +view2.cornerRadius(25) +view2.frame(0, 0, 98, 18) +view2.backgroundColor(0xff0000, 0.8) + +local time = os:time(); +local t = os:date("*t", time); +print("time", time, "t.year", t.year, "t.month", t.month,"t.day", t.day,"t.hour", t.hour,"t.min", t.min,"t.sec", t.sec); +local tb1 = {year=t.year, month=t.month, day=t.day, hour=10, min=0, sec=0, isdst=false}; +local time1 = os:time(tb1) * 1000; +print("time1", time1); + +local tb2 = {year=t.year, month=t.month, day=t.day, hour=20, min=0, sec=0, isdst=false}; +local time2 = os:time(tb2) * 1000; +print("time2", time2); + +local tb3 = {year=t.year, month=t.month, day=t.day, hour=25, min=0, sec=0, isdst=false}; +local time3 = os:time(tb3) * 1000; +print("time3", time3); + +local tb4 = {year=t.year, month=t.month, day=t.day, min=0, sec=0, isdst=false}; +local time4 = os:time(tb4) * 1000; +print("time4", time4); + + + + diff --git a/Android/LuaViewDemo/assets/test/NUI_AudioPlayer.lua b/Android/LuaViewDemo/assets/test/NUI_AudioPlayer.lua new file mode 100644 index 00000000..69f8f501 --- /dev/null +++ b/Android/LuaViewDemo/assets/test/NUI_AudioPlayer.lua @@ -0,0 +1,53 @@ +-- Created by LuaView. +-- Copyright (c) 2017, Alibaba Group. All rights reserved. +-- +-- This source code is licensed under the MIT. +-- For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + +w, h = System.screenSize(); + + +local player1 = AudioPlayer(); + +button1 = Button(); +button1.title("播放音效-url"); +button1.callback(function() + if (player1) then + player1.play("http://dx.sc.chinaz.com/files/download/sound1/201308/3381.wav", 2); + end +end) + +button2 = Button(); +button2.title("播放音效-本地"); +button2.xy(200, 0) +button2.callback(function() + if (player1) then + player1.play("music/test.mp3", 0); + end +end) + +button1_pause = Button(); +button1_pause.title("pause") +button1_pause.xy(0, 50) +button1_pause.callback(function() + if (player1) then + player1.pause(); + end +end) + +button1_resume = Button(); +button1_resume.title("resume") +button1_resume.xy(200, 50) +button1_resume.callback(function() + if (player1) then + player1.resume(); + end +end) + + + + + + + + diff --git a/Android/LuaViewDemo/assets/test/NUI_Bridge.lua b/Android/LuaViewDemo/assets/test/NUI_Bridge.lua new file mode 100644 index 00000000..7efd2b73 --- /dev/null +++ b/Android/LuaViewDemo/assets/test/NUI_Bridge.lua @@ -0,0 +1,28 @@ +-- Created by LuaView. +-- Copyright (c) 2017, Alibaba Group. All rights reserved. +-- +-- This source code is licensed under the MIT. +-- For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + +local label = Label() +label.text("请看日志输出") +label.frame(0, 0, System.screenSize()) + + +bridge.testParams({"a", "b"}) + +bridge.testParams({aa="a", bb="b"}) + +-- 从Native注册一个bridge对象给lua,并在lua中调用native函数 +print("Map", type(bridge.testMap()), bridge.testMap(), bridge.testMap().get("key1")) +print("List", type(bridge.testList()), bridge.testList(), bridge.testList().get(1)) +print("String", type(bridge.testString()), bridge.testString()) +print("int", type(bridge.testInt()), bridge.testInt()) +print("Int2", type(bridge.testInt2()), bridge.testInt2()) +print("long", type(bridge.testLong()), bridge.testLong()) +print("Long2", type(bridge.testLong2()), bridge.testLong2()) +print("double", type(bridge.testDouble()), bridge.testDouble()) +print("Double2", type(bridge.testDouble2()), bridge.testDouble2()) +print("boolean", type(bridge.testBoolean()), bridge.testBoolean()) +print("Boolean", type(bridge.testBoolean2()), bridge.testBoolean2()) + diff --git a/Android/LuaViewDemo/assets/test/NUI_CallLua.lua b/Android/LuaViewDemo/assets/test/NUI_CallLua.lua new file mode 100644 index 00000000..03dae0f8 --- /dev/null +++ b/Android/LuaViewDemo/assets/test/NUI_CallLua.lua @@ -0,0 +1,51 @@ +-- Created by LuaView. +-- Copyright (c) 2017, Alibaba Group. All rights reserved. +-- +-- This source code is licensed under the MIT. +-- For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + +-- 全局函数 +function global_fun_test1(a, b, c) + print("global_fun_test1 called params:", a, b, c) + return "global_fun_test1" +end + + +function global_fun_test2(a, b, c) + print("global_fun_test2 called params:", a, b, c) + return { + "global_fun_test2_a", + "global_fun_test2_b" + } +end + +-- 注册window的回调函数 +window.callback({ + onHide=function() + print("onHide") + end, + window_fun1 = function(a, b, c) + print("window_fun1 called params:", a, b, c) + return "window_fun1" + end, + window_fun2 = function(a, b, c) + print("window_fun2 called params:", a, b, c) + return 2 + end +}) + + +local title = Label() + +title.text("请看后台log输出") +title.frame(0, 0, 200, 200) + + + + + + + + + + diff --git a/Android/LuaViewDemo/assets/test/NUI_DataAndJson.lua b/Android/LuaViewDemo/assets/test/NUI_DataAndJson.lua new file mode 100644 index 00000000..7a99251d --- /dev/null +++ b/Android/LuaViewDemo/assets/test/NUI_DataAndJson.lua @@ -0,0 +1,86 @@ +-- Created by LuaView. +-- Copyright (c) 2017, Alibaba Group. All rights reserved. +-- +-- This source code is licensed under the MIT. +-- For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + +require("kit/lv_kit") + + +local label = Label() +label.text("请看日志输出") +label.frame(0, 0, System.screenSize()) + + +data = Data(97, "abc", "def") +print("1", data) + + +data1 = Data("a") +data2 = Data("b") + +print("2", data1 + data2) + + +print("3", Data('a').toString("latin-1")) + +printTable("4", Data('{"a":"1"}').toTable()) + +print("5", Data('{"a":"1"}').toJson()) + +-- not json +print("6", Data('a').toJson()) + +print("7", Data('{"a":"1"}')) + + +print("-----Json------") + +printTable("8", Json.toTable('{"a":"1"}')) + +printTable("9", Json.toTable(Data('{"a":"1"}'))) + +printTable("10", Json.toTable("a")) + +printTable("11", Json.toTable()) + + +print("-----isValid------") + +print("12", Json.isValid('{"a":"1"}')) + +print("13", Json.isValid(Data('{"a":"1"}'))) + +print("14", Json.isValid("a")) + +print("15", Json.isValid()) + +print("-----nil------") +print("16") +local table = Json.toTable('{}') +printTable(table) + +print("17") +table = Json.toTable('') +printTable(table) + +print("18") +printTable(Json.toTable({ + a = '1' +})) + +print("-----async------") +Json.toTable('{"a":"1"}', function(result) + print("19") + printTable(result) +end) + +data = '{"a"=1,"b"="3","c"={"c1"=1}}' +printTable(Json.toTable(data)) + +Json.toTable(data, function(result) + printTable(result) +end) + + + diff --git a/Android/LuaViewDemo/assets/test/NUI_DynamicCode.lua b/Android/LuaViewDemo/assets/test/NUI_DynamicCode.lua new file mode 100644 index 00000000..939534d7 --- /dev/null +++ b/Android/LuaViewDemo/assets/test/NUI_DynamicCode.lua @@ -0,0 +1,56 @@ +-- Created by LuaView. +-- Copyright (c) 2017, Alibaba Group. All rights reserved. +-- +-- This source code is licensed under the MIT. +-- For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + + +--------------------------------------------------------------------------- +print("case1:") + +code = [[ + param = "Hello world!!!" + print(param) +]] + + +hi = load(code) +hi() + +--------------------------------------------------------------------------- + +print("case2:") + +hi2 = load("param = param .. 'ha ha ha '; x = 1; x = x+1; print(param, x)") +hi2() + +hi3 = load("x=x+1; print(param, x)") +hi3() + +hi4 = load("fun = function() print('this is a function') end") +hi4() +fun() + +fun2 = nil +hi5 = load("fun2 = function(p) print('this is a function', p) end") +hi5() +fun2("hahaha") + + + +--------------------------------------------------------------------------- +print("case3:") + +x = "hello abc" + +dump = string:dump(function() print(x) end) + +hello = load(dump) +hello() + +--------------------------------------------------------------------------- +print("case4:") + +audioplayer = loadfile("NUI_AudioPlayer.lua") +audioplayer() + diff --git a/Android/LuaViewDemo/assets/test/NUI_File.lua b/Android/LuaViewDemo/assets/test/NUI_File.lua new file mode 100644 index 00000000..f906aa0e --- /dev/null +++ b/Android/LuaViewDemo/assets/test/NUI_File.lua @@ -0,0 +1,92 @@ +-- Created by LuaView. +-- Copyright (c) 2017, Alibaba Group. All rights reserved. +-- +-- This source code is licensed under the MIT. +-- For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + +require "kit/lv_kit" + +local label = Label() +label.text("请看日志输出") +label.frame(0, 0, System.screenSize()) + +http = Http() +http.get("http://www.baidu.com", { + query = 1 +}, function(response) + local data = response:data() + + print(data) + test1(data) + test2(data) + test3(data) +end) + + +function test1(data) + print("-------------------------test1---------------------") + print("save", File.save(data, "test.html")) + print("read", File.read("test.html")) + print("path", File.path("test.html")) + print("exists", File.exists("test.html")) + print("--------------------------test1---------------------") +end + +function test2(data) + print("-------------------------test2---------------------") + print("save", File.save(data, "demo/test.html")) + print("read", File.read("demo/test.html")) + print("path", File.path("demo/test.html")) + print("exists", File.exists("demo/test.html")) + print("--------------------------test2---------------------") +end + +function test3(data) + print("-------------------------test3---------------------") + print("save", File.save(data, "../../../common/test.html")) + print("read", File.read("../../../common/test.html")) + print("path", File.path("../../../common/test.html")) + print("exists", File.exists("../../../common/test.html")) + print("--------------------------test3---------------------") +end + +function test4(data) + print("-------------------------test4---------------------") + + File.save(data, "test1.html", function(status) + print("file saved", status, File.exists("test1.html")) + print("read1", File.read("test1.html"), "xxx") + + + print("path2", File.path("test1.html")) + print("exists1", File.exists("test1.html")) + print("exists3", File.exists("test2.html")) + + File.read("test1.html", function(data) + print("read2", data) + print("-------------------------test4---------------------") + end) + end) + + +end + + + + +http = Http() +http.get("https://gju1.alicdn.com/bao/uploaded/i4/100000120700895002/TB2Qu0_fXXXXXb9XpXXXXXXXXXX_!!0-0-juitemmedia.jpg_560x560Q90.jpg", function(response) + local data = response:data() + + File.save(data, "../common/test.png") + + File.read("../common/test.png", function(data) + local img = Image() + img.frame(0, 0, 100, 100) + img.image("../common/test.png") + + local img2 = Image() + img2.frame(101, 0, 100, 100) + img2.image(data) + end) +end) \ No newline at end of file diff --git a/Android/LuaViewDemo/assets/test/NUI_Http.lua b/Android/LuaViewDemo/assets/test/NUI_Http.lua new file mode 100644 index 00000000..6a9dcfe2 --- /dev/null +++ b/Android/LuaViewDemo/assets/test/NUI_Http.lua @@ -0,0 +1,22 @@ +-- Created by LuaView. +-- Copyright (c) 2017, Alibaba Group. All rights reserved. +-- +-- This source code is licensed under the MIT. +-- For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + +require "kit/lv_kit" + +local label = Label() +label.text("请看日志输出") +label.frame(0, 0, System.screenSize()) + +http = Http() +http.get("http://www.baidu.com", { + query = 1 +}, function(response) + print(response) + printTable(response) + print(response.data()) +end) + + diff --git a/Android/LuaViewDemo/assets/test/NUI_System.lua b/Android/LuaViewDemo/assets/test/NUI_System.lua new file mode 100644 index 00000000..e48f28d0 --- /dev/null +++ b/Android/LuaViewDemo/assets/test/NUI_System.lua @@ -0,0 +1,51 @@ +-- Created by LuaView. +-- Copyright (c) 2017, Alibaba Group. All rights reserved. +-- +-- This source code is licensed under the MIT. +-- For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + +require "kit/lv_kit" + +print(type(System)) +print(System.ios()) +print(System.android()) +print(System.vmVersion()) +print(System.osVersion()) +print(System.platform()) +print(System.scale()) +printTable(System.device()) +print(System.screenSize()) + +-- network +Timer(function() + print("Timer--" .. System.network()) +end).start(1, true) + +System.gc() + +print(window.size()) + +btn1 = Button(); +btn1.text("Screen-On") +btn1.xy(0, 0) +btn1.callback(function() + System.keepScreenOn() +end) + +btn2 = Button() +btn2.xy(120, 0) +btn2.text("Screen-Off") +btn2.callback(function() + System.keepScreenOn(false) +end) + + + +print("System.ios = " , System.ios() ) +print("System.android = ", System.android() ) +print("System.vmVersion = ", System.vmVersion() ) +print("System.osVersion = ", System.osVersion() ) --获取手机操作系统版本号 +print("System.platform = ", System.platform() ) --获取平台信息 +print("System.scale = ", System.scale() ) --获取屏幕分辨率 +print("System.device = ", System.device() ) --获取设备信息 +print("System.screenSize() = ", System.screenSize() ); \ No newline at end of file diff --git a/Android/LuaViewDemo/assets/test/NUI_Timer.lua b/Android/LuaViewDemo/assets/test/NUI_Timer.lua new file mode 100644 index 00000000..c7a720e8 --- /dev/null +++ b/Android/LuaViewDemo/assets/test/NUI_Timer.lua @@ -0,0 +1,42 @@ +-- Created by LuaView. +-- Copyright (c) 2017, Alibaba Group. All rights reserved. +-- +-- This source code is licensed under the MIT. +-- For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + +scrW,scrH = System.screenSize(); +label = Label(); +label.frame(0,0,scrW,scrH-64); +label.lineCount(100); + +function myprint( s , s2 ) + s = s .. " " .. tostring(s2) + print(s); + local text = label.text(); + if( text ) then + label.text( text .. "\n" .. s); + else + label.text( s); + end +end + +---- 1 +--timer1 = Timer(function() +-- myprint("Timer1 Run") +--end); +--timer1 = timer1.start(0.1, false); + +--2 +index2 = 1; +timer2 = Timer() +timer2.callback( + function() + myprint("Timer2 Run",index2) + index2 = index2 + 1; + + if(index2 > 10) then + timer2.cancel() + end + end + ) +timer2.start(0.2, true) diff --git a/Android/LuaViewDemo/assets/test/NUI_Vibrator.lua b/Android/LuaViewDemo/assets/test/NUI_Vibrator.lua new file mode 100644 index 00000000..dabbf977 --- /dev/null +++ b/Android/LuaViewDemo/assets/test/NUI_Vibrator.lua @@ -0,0 +1,63 @@ +-- Created by LuaView. +-- Copyright (c) 2017, Alibaba Group. All rights reserved. +-- +-- This source code is licensed under the MIT. +-- For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + +w, h = System.screenSize(); + + +local vibrator = Vibrator(); + +button1 = Button(); +button1.title("震动-1"); +button1.callback(function() + if (vibrator) then + vibrator.vibrate(); + end +end) + +button2 = Button(); +button2.title("震动-2"); +button2.xy(100, 0) +button2.callback(function() + if (vibrator) then + vibrator.vibrate(2) + end +end) + +button3 = Button(); +button3.title("震动-3") +button3.xy(0, 50) +button3.callback(function() + if (vibrator) then + vibrator.vibrate({3}) + end +end) + +button4 = Button(); +button4.title("震动-4") +button4.xy(100, 50) +button4.callback(function() + if (vibrator) then + vibrator.vibrate({1, 2, 1, 0.3, 0.2, 0.1, 0.01, 1.1}, 4) + end +end) + + +button5 = Button(); +button5.title("震动-cancel") +button5.xy(100, 100) +button5.callback(function() + if (vibrator) then + vibrator.cancel() + end +end) + + + + + + + + diff --git a/Android/LuaViewDemo/assets/test/UI_Alert.lua b/Android/LuaViewDemo/assets/test/UI_Alert.lua new file mode 100644 index 00000000..d50f2169 --- /dev/null +++ b/Android/LuaViewDemo/assets/test/UI_Alert.lua @@ -0,0 +1,37 @@ +-- Created by LuaView. +-- Copyright (c) 2017, Alibaba Group. All rights reserved. +-- +-- This source code is licensed under the MIT. +-- For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + +-- +-- Created by IntelliJ IDEA. +-- User: song + +--1 一个按钮 +as1 = StyledString("一个按钮", { fontColor = 0xffff0000, backgroundColor = 0xff00ff00, fontSize = 30 }) +as2 = StyledString("两个按钮", { fontColor = 0xffff0000, backgroundColor = 0xff00ff00, fontSize = 30 }) +as3 = StyledString("只有内容", { fontColor = 0xffff0000, backgroundColor = 0xff00ff00, fontSize = 30 }) + +text = StyledString("文字", { fontColor = 0xffff0000, backgroundColor = 0xff00ff00, fontSize = 30 }) + + +ok = StyledString("确定", { fontColor = 0xffff0000, backgroundColor = 0xff00ff00, fontSize = 30 }) + + +Alert(as1, text, ok, function() + print("点击了") +end) + +--2 两个按钮 +Alert(as2, text, ok, "取消", function() + print("点击了") +end, function() + print("取消了") +end) + +--3 只有内容 +Alert(nil, as3) + +--4 只有标题 +Alert("只有标题") diff --git a/Android/LuaViewDemo/assets/test/UI_Animator.lua b/Android/LuaViewDemo/assets/test/UI_Animator.lua new file mode 100644 index 00000000..443dc3f0 --- /dev/null +++ b/Android/LuaViewDemo/assets/test/UI_Animator.lua @@ -0,0 +1,125 @@ +-- Created by LuaView. +-- Copyright (c) 2017, Alibaba Group. All rights reserved. +-- +-- This source code is licensed under the MIT. +-- For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + +-- 简单动画 +startBtn = Button(); +startBtn.frame(10, 10, 80, 50) + +resumeBtn = Button() +resumeBtn.frame(100, 10, 80, 50) + +stateLabel = Label() +stateLabel.frame(200, 10, 100, 50) + +local function isRunning() + return translation.isRunning() +end + +local function isPaused() + return translation.isPaused() +end + +local function updateControlBtns() + local running, paused = isRunning(), isPaused() + print("Running=", running, " Paused=", paused) + + startBtn.text(running and "Cancel" or "Start") + resumeBtn.enabled(running) + resumeBtn.text(paused and "Resume" or "Pause") +end + +translation = Animation().translation(100, -100).duration(3).repeatCount(-1).interpolator(Interpolator.ACCELERATE_DECELERATE).callback({ + onStart = function() + stateLabel.text("Running") + end, + onCancel = function() + stateLabel.text("Canceled") + updateControlBtns() + end, + onEnd = function() + stateLabel.text("End") + updateControlBtns() + end, + onPause = function() + stateLabel.text("Paused") + end, + onResume = function() + stateLabel.text("Running") + end, +}) +scale = Animation().scale(2, 0.5).duration(2).delay(1) + +local startAnimations, cancelAnimations, pauseAnimations, resumeAnimations + +function startAnimations() + if animationView then + animationView.removeFromSuper() + end + if isRunning() then + cancelAnimations() + end + + animationView = View() + animationView.frame(50, 300, 100, 100) + animationView.backgroundColor(0xff0000, 1) + child = Label() + child.frame(10, 10, 80, 80) + child.backgroundColor(0x00ff00) + child.text("child view") + animationView.addView(child) + animationView.callback({ + onClick = function() + print("scale:", animationView.scale()) + print("translation:", animationView.translation()) + end + }) + + translation.with(animationView).start() + scale.with(animationView).start() +end + +function cancelAnimations() + translation.cancel() + scale.cancel() +end + +function pauseAnimations() + if isRunning() and not isPaused() then + translation.pause() + scale.pause() + end +end + +function resumeAnimations() + if isRunning() and isPaused() then + translation.resume() + scale.resume() + end +end + +startBtn.callback({ + onClick = function() + if isRunning() then + cancelAnimations() + else + startAnimations() + end + updateControlBtns() + end +}) + +resumeBtn.callback({ + onClick = function() + if isPaused() then + resumeAnimations() + else + pauseAnimations() + end + updateControlBtns() + end +}) + +updateControlBtns() diff --git a/Android/LuaViewDemo/assets/test/UI_Animator2.lua b/Android/LuaViewDemo/assets/test/UI_Animator2.lua new file mode 100644 index 00000000..77ac30ee --- /dev/null +++ b/Android/LuaViewDemo/assets/test/UI_Animator2.lua @@ -0,0 +1,89 @@ +-- Created by LuaView. +-- Copyright (c) 2017, Alibaba Group. All rights reserved. +-- +-- This source code is licensed under the MIT. +-- For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + +sw, sh = System.screenSize() +x = sw / 2 - 50 +y = sh / 2 - 50 + +w = 100 +h = 100 + +sw = 100 +sh = 100 + +dx = 20 +dy = 20 + +xr = x + w +yb = y + h + + +container = View() +container.frame(x, y, w, h) +container.borderColor(0xff0000) +container.borderWidth(1) + + +x = 0 +y = 0 +xr = x + w +yb = y + h + +--左 +v1 = View() +v1.frame(x - sw + dx, y, sw, sh) +v1.backgroundColor(0xf00000, 0.5) +container.addView(v1) + +--上 +v2 = View() +v2.frame(x, y - sh + dy, sw, sh) +v2.backgroundColor(0x0f0000, 0.5) +container.addView(v2) + +-- 右 +v3 = View() +v3.frame(xr - dx, y, sw, sh) +v3.backgroundColor(0x00f000, 0.5) +container.addView(v3) + +-- 下 +v4 = View() +v4.frame(x, yb - dy, sw, sh) +v4.backgroundColor(0x0000f0, 0.5) +container.addView(v4) + +container.nativeView().setClipChildren(true) +container.callback(function() + t = 2 + + print("v1", v1.frame()) + print("v2", v2.frame()) + print("v3", v3.frame()) + print("v4", v4.frame()) + + + --V1 + tx, ty = v1.xy() + Animation().with(v1).translation(-tx, -ty).duration(t).start() + + --V2 + tx, ty = v2.xy() + Animation().with(v2).translation(-tx, -ty).delay(t).duration(t).start() + + --V3 + tx, ty = v3.xy() + Animation().with(v3).translation(-tx, -ty).delay(2 * t).duration(t).start() + + --v4 + tx, ty = v4.xy() + Animation().with(v4).translation(-tx, -ty).delay(3 * t).duration(t).start() + + print("container clicked") + +end) + +print("end") \ No newline at end of file diff --git a/Android/LuaViewDemo/assets/test/UI_AnimatorSet.lua b/Android/LuaViewDemo/assets/test/UI_AnimatorSet.lua new file mode 100644 index 00000000..2390d61a --- /dev/null +++ b/Android/LuaViewDemo/assets/test/UI_AnimatorSet.lua @@ -0,0 +1,125 @@ +-- Created by LuaView. +-- Copyright (c) 2017, Alibaba Group. All rights reserved. +-- +-- This source code is licensed under the MIT. +-- For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + +-- 简单动画 +startBtn = Button(); +startBtn.frame(10, 10, 80, 50) + +resumeBtn = Button() +resumeBtn.frame(100, 10, 80, 50) + +stateLabel = Label() +stateLabel.frame(200, 10, 100, 50) + +local function isRunning() + return translation.isRunning() +end + +local function isPaused() + return translation.isPaused() +end + +local function updateControlBtns() + local running, paused = isRunning(), isPaused() + print("Running=", running, " Paused=", paused) + + startBtn.text(running and "Cancel" or "Start") + resumeBtn.enabled(running) + resumeBtn.text(paused and "Resume" or "Pause") +end + +translation = AnimationSet("Attention.Bounce").duration(1).interpolator(Interpolator.ACCELERATE_DECELERATE).callback({ + onStart = function() + stateLabel.text("Running") + end, + onCancel = function() + stateLabel.text("Canceled") + updateControlBtns() + end, + onEnd = function() + stateLabel.text("End") + updateControlBtns() + end, + onPause = function() + stateLabel.text("Paused") + end, + onResume = function() + stateLabel.text("Running") + end, +}) +scale = AnimationSet("Fade.In").duration(1).delay(1) + +local startAnimations, cancelAnimations, pauseAnimations, resumeAnimations + +function startAnimations() + if animationView then + animationView.removeFromSuper() + end + if isRunning() then + cancelAnimations() + end + + animationView = View() + animationView.frame(50, 300, 100, 100) + animationView.backgroundColor(0xff0000, 1) + child = Label() + child.frame(10, 10, 80, 80) + child.backgroundColor(0x00ff00) + child.text("child view") + animationView.addView(child) + animationView.callback({ + onClick = function() + print("scale:", animationView.scale()) + print("translation:", animationView.translation()) + end + }) + + translation.with(animationView).start() + scale.with(animationView).start() +end + +function cancelAnimations() + translation.cancel() + scale.cancel() +end + +function pauseAnimations() + if isRunning() and not isPaused() then + translation.pause() + scale.pause() + end +end + +function resumeAnimations() + if isRunning() and isPaused() then + translation.resume() + scale.resume() + end +end + +startBtn.callback({ + onClick = function() + if isRunning() then + cancelAnimations() + else + startAnimations() + end + updateControlBtns() + end +}) + +resumeBtn.callback({ + onClick = function() + if isPaused() then + resumeAnimations() + else + pauseAnimations() + end + updateControlBtns() + end +}) + +updateControlBtns() diff --git a/Android/LuaViewDemo/assets/test/UI_Bitmap.lua b/Android/LuaViewDemo/assets/test/UI_Bitmap.lua new file mode 100644 index 00000000..2c455361 --- /dev/null +++ b/Android/LuaViewDemo/assets/test/UI_Bitmap.lua @@ -0,0 +1,65 @@ +-- Created by LuaView. +-- Copyright (c) 2017, Alibaba Group. All rights reserved. +-- +-- This source code is licensed under the MIT. +-- For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + +--1. 普通设置url,size,center +view = Image() +view.frame(0, 0, 200, 200) +view.backgroundColor(0xffaa0000) + + +--view.image("animate1") + +--2. 普通构造传url +bmp = Bitmap("https://gju1.alicdn.com/bao/uploaded/i4/100000120700895002/TB2Qu0_fXXXXXb9XpXXXXXXXXXX_!!0-0-juitemmedia.jpg_560x560Q90.jpg", function(ok) + if(ok) then + view.image(bmp) + else + view.image("animate1") + end +end) + + +spriteBmp = function(t) + local w, h = t.size() + t.sprite(0, 0, w / 2, h / 2, function(newBmp) + view.image(newBmp) + bmp = newBmp + end) + Toast("width = " .. w .. " height = " .. h) +end + + +view.callback(function() + spriteBmp(bmp) +end) + + +view2 = Image() +view2.frame(0, 200, 200, 200) +bmp2 = Bitmap("animate1", function(ok) + view2.image(ok and bmp2) +end) + +view2.callback(function() + local n = 5; + local w, h = bmp2.size() + local sw = w / 5; + local vw = view2.width() / 5 + local x = 0 + local vx = 0; + for i = 1, n do + x = (i - 1) * sw + vx = (i - 1) * vw + (i - 1) * 2 + local v = Image() + v.frame(vx, 403, vw, h) + v.image(bmp2.sprite(x, 0, sw, h)) + end +end) + + + + + diff --git a/Android/LuaViewDemo/assets/test/UI_BorderAndCorner.lua b/Android/LuaViewDemo/assets/test/UI_BorderAndCorner.lua new file mode 100644 index 00000000..d6eca63b --- /dev/null +++ b/Android/LuaViewDemo/assets/test/UI_BorderAndCorner.lua @@ -0,0 +1,29 @@ +-- Created by LuaView. +-- Copyright (c) 2017, Alibaba Group. All rights reserved. +-- +-- This source code is licensed under the MIT. +-- For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + +view = Image() +view.frame(10, 10, 100, 100) +view.image("animate3") +view.cornerRadius(50) +view.borderColor(0x33ff0000) +view.borderWidth(2) + + +view2 = Image() +view2.frame(120, 10, 100, 100) +view2.image("animate1") +view2.cornerRadius(20) +view2.borderColor(0xff0000) +view2.borderWidth(2) + + +view3 = Image() +view3.frame(230, 10, 100, 100) +view3.image("animate1") +view3.cornerRadius(20) +view3.borderColor(0xff0000) +view3.borderWidth(2) +view3.borderDash(5, 2) \ No newline at end of file diff --git a/Android/LuaViewDemo/assets/test/UI_Button.lua b/Android/LuaViewDemo/assets/test/UI_Button.lua new file mode 100644 index 00000000..3c5caff2 --- /dev/null +++ b/Android/LuaViewDemo/assets/test/UI_Button.lua @@ -0,0 +1,45 @@ +-- Created by LuaView. +-- Copyright (c) 2017, Alibaba Group. All rights reserved. +-- +-- This source code is licensed under the MIT. +-- For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + +function createButton(text, x, y, w, h, callback) + local button = Button(); + button.frame(x, y, w, h); + button.text(text); + button.backgroundColor(0xfa0000); + button.callback(function() + if (callback) then + callback(); + end + end); + button.adjustSize() + return button; +end + +button1 = createButton("123456中文", 10, 10, 1000, 60); + +button2 = Image(); +button2.frame(10, 100 + 80, 100, 100); +button2.image("http://g.alicdn.com/ju/lua/2.0.25/doc/icon.png"); + +button2.callback(function() + print("我是图片按钮"); + button2.adjustSize(); +end); + +obj = {}; + +function obj.test(a) + print(self, a); +end + +obj.test "good"; + +button3 = Button() +button3.frame(150, 180, 100, 100) +button3.image("animate2", "http://online.sccnn.com/icon/517/actionIcons_006.png") +button3.callback(function() + print("button3 clicked") +end) \ No newline at end of file diff --git a/Android/LuaViewDemo/assets/test/UI_CollectionView.lua b/Android/LuaViewDemo/assets/test/UI_CollectionView.lua new file mode 100644 index 00000000..34aa636f --- /dev/null +++ b/Android/LuaViewDemo/assets/test/UI_CollectionView.lua @@ -0,0 +1,97 @@ +-- Created by LuaView. +-- Copyright (c) 2017, Alibaba Group. All rights reserved. +-- +-- This source code is licensed under the MIT. +-- For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + +--工具包引入 +require "kit/lv_kit" +-- 变量定义 +local s_width, s_height = System.screenSize() +local tableView + +local tableViewData = { + Section = { + SectionCount = 2, -- section数量 + RowCount = function(section) + if(section == 1) then + return 50 + else + return 50 + end + end + }, + Cell = { + Id = function(section, row) -- 指定section和row对应的Cell类型唯一识别号 + local id = "Cell1" .. section .. row + print("Id", id) + return id; + end, + + Cell1 = { + Size = function(section, row) + print("Size", section, row, 10 + row * 2) + return 10 + row * 2 + end, + Init = function(cell, section, row) -- 初始化cell + print("Init", section, row, 10 + row * 2) + cell.title = Label(); + cell.title.backgroundColor(section == 1 and 0xff0000 or 0x00ff00) + end, + Layout = function(cell, section, row) -- cell复用时调用 + print("Layout", section, row, 10 + row * 2) +-- cell.title.frame(0, 0, s_width, 10 + row * 2) + cell.title.text(section .. '--' .. row) + end, + Callback = function(cell, section, row) -- 用户点击了section和row + Toast("Section " .. section .. ", Row " .. row); + end + } + } +} + +local cellData = function(_, key) + print(key) + return { + Size = function(section, row) + print("Size", section, row, 10 + row * 2) +-- return 10 + row * 2 + return s_width, 200 + end, + Init = function(cell, section, row) -- 初始化cell + print("Init", section, row, 10 + row * 2) + cell.title = Label(); + cell.title.backgroundColor(section == 1 and 0xff0000 or 0x00ff00) + cell.title.lines(10) + cell.title.maxLine(10) + end, + Layout = function(cell, section, row) -- cell复用时调用 + print("Layout", section, row, 10 + row * 2) +-- cell.title.frame(0, 0, s_width, 10 + row * 2) + + cell.title.text("sfadfssfadfssfadfssfadfssfadfssfadfssfadfssfadfssfadfssfadfssfadfssfadfssfadfssfadfssfadfssfadfssfadfssfadfssfadfssfadfssfadfssfadfssfadfssfadfssfadfssfadfssfadfssfadfssfadfssfadfssfadfssfadfssfadfssfadfssfadfssfadfs") + + print("cell-size 11", cell.title.height()) + + cell.title.adjustSize() + + print("cell-size 22", cell.title.height()) + + end, + Callback = function(cell, section, row) -- 用户点击了section和row + Toast("Section " .. section .. ", Row " .. row); + end + } +end + +setmetatable(tableViewData.Cell, { __index = cellData }) +tableView = CollectionView(tableViewData) +tableView.miniSpacing(1) +tableView.frame(0, 0, s_width, s_height) +tableView.showScrollIndicator(false) +tableView.enabled(false) + + + + + diff --git a/Android/LuaViewDemo/assets/test/UI_CollectionView_reload.lua b/Android/LuaViewDemo/assets/test/UI_CollectionView_reload.lua new file mode 100644 index 00000000..fa5d8ad8 --- /dev/null +++ b/Android/LuaViewDemo/assets/test/UI_CollectionView_reload.lua @@ -0,0 +1,189 @@ +-- Created by LuaView. +-- Copyright (c) 2017, Alibaba Group. All rights reserved. +-- +-- This source code is licensed under the MIT. +-- For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + +w, h = System.screenSize() +cellHeight = 100 +imageUrl1 = "http://gju2.alicdn.com/bao/uploaded/i1/10000073270926575/TB2fpg0cXXXXXb6XpXXXXXXXXXX_!!0-0-juitemmedia.jpg" +imageUrl2 = "http://img4.duitang.com/uploads/item/201306/25/20130625045508_sairr.thumb.600_0.jpeg" + +sectionCount = 2 +rowCount1 = 1 +rowCount2 = 1 +rowTitle = "x" +tableView = CollectionView { + Section = { + SectionCount = function() + return sectionCount + end, + RowCount = function(section) + if(section == 1) then + return rowCount1 + else + return rowCount2 + end + end + }, + Cell = { + Id = function(section, row) + if (section == 1) then + return "ImageAndLabel" + elseif(section == 2) then + return "ImageAndImage" + else + return "Label" + end + end, + Label = { + Size = function(section, row) + return w, cellHeight + end, + Init = function(cell, section, row) + cell.title = Label() + end, + Layout = function(cell, section, row) + cell.title.frame(0, 0, w - cellHeight, cellHeight) + cell.title.text("测试" .. section .. "--" .. row .. "--" .. rowTitle) + cell.title.backgroundColor(0xdcdcdc) + end + }, + ImageAndLabel = { + Size = function(section, row) + return w, cellHeight + end, + Init = function(cell, section, row) + cell.icon = Image() + cell.title = Label() + cell.bg = Button() + end, + Layout = function(cell, section, row) + cell.icon.frame(20, 0, cellHeight, cellHeight) + cell.icon.image(imageUrl1) + + cell.title.frame(20 + cellHeight, 0, w - cellHeight, cellHeight) + cell.title.text("测试" .. section .. "--" .. row .. "--" .. rowTitle) + + cell.bg.frame(0, 0, w, cellHeight) + cell.bg.image(nil, imageUrl1) + end, + Callback = function(section, row) + print(section, row) + tableView.stopRefreshing() + System.gc() + end + }, + ImageAndImage = { + Size = function(section, row) + return cellHeight + end, + Init = function(cell, section, row) + cell.icon = Image() + cell.icon2 = Image() + end, + Layout = function(cell, section, row) + local cellWdith, cellHeight = cell.window.size() + cell.icon.frame(0, 0, cellHeight, cellHeight) + cell.icon.image(imageUrl1) + + + cell.icon2.frame(cellHeight + 10, 0, cellHeight, cellHeight) + cell.icon2.image(imageUrl1) + end, + Callback = function(section, row) + print(section, row) + tableView.stopRefreshing() + System.gc() + end + } + } +} + +tableView.frame(0, 152, w, h - 64 - 152) + + +local btn = Button() +btn.text("reload") +btn.frame(0, 0, 80, 50) +btn.callback(function() + print("reload") + tableView.reload() +end) + +local btn2 = Button() +btn2.text("+rows") +btn2.frame(81, 0, 80, 50) +btn2.callback(function() + rowCount1 = rowCount1 + 2 + print("+rows", 1, rowCount1) + tableView.reload(1) +end) + +local btn3 = Button() +btn3.text("-rows") +btn3.frame(162, 0, 80, 50) +btn3.callback(function() + rowCount1 = rowCount1 - 2 + rowCount1 = math:max(rowCount1, 1) + print("-rows", 1, rowCount1) + tableView.reload(1) +end) + +local btn4 = Button() +btn4.text("update-rows") +btn4.frame(243, 0, 80, 50) +btn4.callback(function() + rowTitle = rowTitle .. "y" + print("update-rows", 1) + tableView.reload(1) +end) + +local btn5 = Button() +btn5.text("+row") +btn5.frame(0, 51, 80, 50) +btn5.callback(function() + rowCount1 = rowCount1 + 1 + print("+row", 1, rowCount1) + tableView.reload(1, 1) +end) + +local btn6 = Button() +btn6.text("-row") +btn6.frame(81, 51, 80, 50) +btn6.callback(function() + rowCount1 = rowCount1 - 1 + rowCount1 = math:max(rowCount1, 1) + print("-row", 1, rowCount1) + tableView.reload(1, 1) +end) + +local btn7 = Button() +btn7.text("update-row") +btn7.frame(162, 51, 80, 50) +btn7.callback(function() + rowTitle = rowTitle .. "x" + print("update-row", 1, 1) + tableView.reload(1, 1) +end) + + +local btn8 = Button() +btn8.text("+section") +btn8.frame(0, 102, 80, 50) +btn8.callback(function() + sectionCount = sectionCount + 1 + print("+section", sectionCount) + tableView.reload(sectionCount) +end) + +local btn9 = Button() +btn9.text("-section") +btn9.frame(91, 102, 80, 50) +btn9.callback(function() + sectionCount = sectionCount - 1 + sectionCount = math:max(sectionCount, 1) + print("-section", sectionCount) + tableView.reload(sectionCount) +end) + diff --git a/Android/LuaViewDemo/assets/test/UI_CustomPanel.lua b/Android/LuaViewDemo/assets/test/UI_CustomPanel.lua new file mode 100644 index 00000000..2ed04485 --- /dev/null +++ b/Android/LuaViewDemo/assets/test/UI_CustomPanel.lua @@ -0,0 +1,21 @@ +-- Created by LuaView. +-- Copyright (c) 2017, Alibaba Group. All rights reserved. +-- +-- This source code is licensed under the MIT. +-- For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + +panel = CustomError() +panel.backgroundColor(0xff0000) +panel.frame(0, 0, 200, 200) +panel.callback(function(message, arg1, arg2, arg3, arg4) + print(message, arg1, arg2, arg3, arg4) + if(value == "success") then + -- do + else + -- do + end +end) + +print("rootView", panel.nativeView().getAlpha()) + + diff --git a/Android/LuaViewDemo/assets/test/UI_CustomView.lua b/Android/LuaViewDemo/assets/test/UI_CustomView.lua new file mode 100644 index 00000000..f1b5bd67 --- /dev/null +++ b/Android/LuaViewDemo/assets/test/UI_CustomView.lua @@ -0,0 +1,233 @@ +-- Created by LuaView. +-- Copyright (c) 2017, Alibaba Group. All rights reserved. +-- +-- This source code is licensed under the MIT. +-- For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + +img = Image() + +view = CustomView() +view.frame(100, 100, 200, 200) +view.backgroundColor(0x000000, 0.3) + +img.hidden(true) + +view.onDraw(function(canvas) + testCanvasAndroidAndIos(canvas) +end) + +view.onClick(function() + view.invalidate() + Toast("invalidate") +end) + +bmp = Bitmap("https://gju1.alicdn.com/bao/uploaded/i4/100000120700895002/TB2Qu0_fXXXXXb9XpXXXXXXXXXX_!!0-0-juitemmedia.jpg_560x560Q90.jpg") + +function testCanvasAndroidAndIos(canvas) + print(canvas) + -- drawLine + canvas.color(0xff0000) + canvas.strokeWidth(2) + canvas.drawLine(0, 50, 100, 50) + canvas.drawLine(50, 0, 50, 100) + + canvas.resetPaint() + canvas.color(0x00ff00) + canvas.alpha(0.5) + canvas.drawLine(0, 0, 100, 0) + canvas.drawLine(100, 0, 100, 100) + canvas.drawLine(100, 100, 0, 100) + canvas.drawLine(0, 100, 0, 0) + canvas.drawLine(0, 0, 100, 100) + canvas.drawLine(100, 0, 0, 100) + + -- drawPoint + canvas.color(0xff0000) + canvas.strokeWidth(2) + canvas.drawPoint(1, 5) + canvas.drawPoint(99, 93) + + -- drawRect + canvas.resetPaint() + canvas.style(PaintStyle.STROKE) + canvas.drawRect(5, 5, 5, 5) + canvas.style(PaintStyle.FILL) + canvas.drawRect(10, 10, 5, 5) + + -- drawRoundRects + canvas.drawRoundRect(45, 1, 5, 5, 2, 2) + canvas.drawRoundRect(45, 5, 10, 5, 2, 2) + + -- drawCircle + canvas.drawCircle(80, 0, 5) + canvas.drawCircle(80, 15, 5) + + -- drawText + canvas.textSize(20) + canvas.drawText("x", 20, 55) + canvas.textSize(14) + canvas.drawText("y", 20, 65) + canvas.resetPaint() + + -- drawOval + canvas.drawOval(45, 50, 25, 10) + canvas.drawOval(45, 60, 25, 10) + + -- draw Arc + canvas.drawArc(30, 30, 20, 20, 0, 90, true) + + -- drawBitmap + canvas.save() + canvas.rotate(-10, 100, 100) + canvas.skew(100) + canvas.scale(1.2) + canvas.translate(-10, -10) + canvas.strokeWidth(10) + canvas.textSize(15) + canvas.bold(true) + canvas.drawText("测试一下", 20, 150) + canvas.alpha(0.5) + canvas.drawImage("animate1", 0, 100, 100, 100) + canvas.restore() + canvas.resetPaint() + + print(img) + if(img) then + canvas.drawImage(img, 100, 0, 100, 100) + end + + canvas.drawImage(bmp, 0, 0, 100, 100) + + -- clipRect + canvas.clipRect(100, 100, 35, 35) + canvas.drawCircle(100, 100, 40) + + canvas.clipRect(150, 150, 30, 30) + canvas.drawText("TestABCDEFGHEFGHIJKLMOPQRST", 150, 150) + + print(canvas.nativeObj()) +end + + +img.image("https://gju1.alicdn.com/bao/uploaded/i4/100000120700895002/TB2Qu0_fXXXXXb9XpXXXXXXXXXX_!!0-0-juitemmedia.jpg_560x560Q90.jpg", function() + view.invalidate() + print("image load finish") +end) + + + +function testCanvasAndroid(canvas) + print(canvas) + + + -- drawLine + + canvas.drawLine(0, 50, 100, 50, { color = 0xff0000 }) + canvas.drawLine(50, 0, 50, 100, { strokeWidth = 2 }) + + canvas.drawLine({ + { 0, 0, 100, 0 }, + { 100, 0, 100, 100 }, + { 100, 100, 0, 100 }, + { 0, 100, 0, 0 }, + { 0, 0, 100, 100 }, + { 100, 0, 0, 100 } + }, { color = 0x00ff00, alpha = 0.5 }) + + canvas.resetPaint() + + + -- drawPoint + canvas.drawPoint(1, 3) + canvas.drawPoint(99, 97) + + canvas.drawPoint({ + { 3, 1 }, + { 97, 99 }, + { 1, 97 }, + { 97, 1 } + }) + + + -- drawRect + canvas.drawRect(5, 5, 5, 5, { style = "stroke" }) + canvas.drawRect(10, 10, 5, 5, { style = "fillStroke" }) + + canvas.drawRect({ + { 15, 15, 5, 5 }, + { 20, 20, 5, 5 }, + { 26, 26, 5, 5 }, + }, { style = 2 }) + + -- drawRoundRects + canvas.drawRoundRect(45, 1, 10, 5, 2, 2) + canvas.drawRoundRect(45, 5, 10, 5, 2, 2) + + canvas.drawRoundRect({ + { 45, 10, 10, 5, 2, 2 }, + { 45, 16, 20, 4, 1, 1 }, + }) + + -- drawCircle + canvas.drawCircle(80, 0, 5) + canvas.drawCircle(80, 15, 5) + + canvas.drawCircle({ + { 80, 30, 5 }, + { 80, 45, 2 }, + }) + + -- drawText + + canvas.drawText("x", 20, 55, { textSize = 20, textAlign = TextAlign.RIGHT }) + canvas.drawText("y", 20, 65, { textSize = 14 }) + + canvas.drawText({ + { "xx", 20, 75, { color = 0x0000ff, strikeThrough = true, textSize = 20, textSkewX = 1.5, bold = true } }, + { "yy", 20, 85 }, + }, { color = 0x0fff00, underline = true, textSize = 10, textScaleX = 3, letterSpacing = 0.2, linearText = true }) + canvas.resetPaint() + + -- drawOval + canvas.drawOval(45, 50, 25, 20) + canvas.drawOval(45, 60, 25, 20) + + canvas.drawOval({ + { 45, 70, 25, 5 }, + { 45, 80, 25, 5 } + }) + + -- draw Arc + canvas.drawArc(30, 30, 20, 20, 0, 90, true) + + canvas.drawArc({ + { 10, 30, 20, 10, 91, 180, true }, + { 30, 30, 20, 20, 182, 100, false } + }) + + -- drawBitmap + canvas.save() + canvas.rotate(-10, 100, 100) + canvas.skew(100) + canvas.scale(1.2) + canvas.translate(-10, -10) + canvas.drawText("测试一下", 20, 150, { strokeWidth = 10, textSize = 15, filterBitmap = true, bold = true }) + canvas.drawBitmap("animate1", 0, 100, 100, 100, { alpha = 0.5 }) + canvas.restore() + canvas.resetPaint() + + print(img) + if (img) then + canvas.drawBitmap(img, 100, 0, 200, 100) + end + + -- clipRect + canvas.clipRect(100, 100, 35, 35) + canvas.drawCircle(100, 100, 40) + + canvas.clipRect(150, 150, 30, 30) + canvas.drawText("TestABCDEFGHEFGHIJKLMOPQRST", 150, 150) + + print(canvas.nativeObj()) +end + diff --git a/Android/LuaViewDemo/assets/test/UI_FlexboxLayout.lua b/Android/LuaViewDemo/assets/test/UI_FlexboxLayout.lua new file mode 100644 index 00000000..e2b49c63 --- /dev/null +++ b/Android/LuaViewDemo/assets/test/UI_FlexboxLayout.lua @@ -0,0 +1,92 @@ +-- Created by LuaView. +-- Copyright (c) 2017, Alibaba Group. All rights reserved. +-- +-- This source code is licensed under the MIT. +-- For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + +LIGHT_GRAY = 0xf5edb3 +RED_COLOR = 0xf61d4b +BLUE_COLOR = 0x26a96d +GREEN_COLOR = 0x05A5D1 +MAGENTA_COLOR = 0xff00ff +MOCCASIN_COLOR = 0xffe4b5 +OLIVEDRAB_COLOR = 0x6b8e23 + +w,h = System.screenSize() + +-- 依次从上往下对应 +contentView = View() +contentView.frame(0, 0, w, 400) +contentView.backgroundColor(LIGHT_GRAY) + +-- 对应第一个纯色的红色的view +view1 = View() +view1.backgroundColor(RED_COLOR) +view1.flexCss("flex: 1, margin: 5") + +-- 对应第二个绿色的View,这个View有5个子View,从左往右排列 +view2 = View() +view2.backgroundColor(BLUE_COLOR) + +-- 左边红色与相邻的蓝色,宽度关系表示为1:3 +view3 = View() +view3.backgroundColor(RED_COLOR) +view3.flexCss("flex: 1") + +-- View4 蓝色这块也有一些子view, 这里解释了如何换行 +view4 = View() +view4.backgroundColor(GREEN_COLOR) +view4.flexCss("flex: 3, flex-direction: row-reverse, align-items: stretch, flex-wrap: 1, align-content: flex-start, justify-content: center") + +view41 = View() +view41.backgroundColor(MAGENTA_COLOR) +view41.flexCss("width: 50, align-self: stretch, margin: 5, height: 25") + +view42 = Label() +view42.backgroundColor(MOCCASIN_COLOR) +view42.text("flex box") +view42.lineCount(0) +view42.flexCss("margin: 5, sizetofit: 1, align-self: center, margin-top: 20") + +view43 = Label() +view43.backgroundColor(OLIVEDRAB_COLOR) +view43.flexCss("margin-left: 10, sizetofit: 1, align-self: center") +view43.text("you will like it!") +view43.lineCount(1) + +view4.flexChildren(view41, view42, view43) + +view5 = View() +view5.backgroundColor(RED_COLOR) +view5.flexCss("width: 40, height: 40, margin-left: 10, align-self: center") + +image = Image() +image.image("http://img4.tbcdn.cn/L1/461/1/img_20151116194256.JPEG_240x240") +image.flexCss("width: 30, height: 30, align-self: flex-end") + +-- 一个绝对定位的view,黑色的那块,与其他子不发生关系,只与父发生关系 +view6 = View() +view6.backgroundColor(0x00) +view6.flexCss("width: 50, height: 50, position: absolute, left: 5, top: 5") + +view2.flexChildren(view3, view4, image, view5, view6) +view2.flexCss("flex: 2, padding: 10.0, flex-direction: row, align-items: stretch") + +label = Label() +label.backgroundColor(GREEN_COLOR) +label.text("The Réunion parrot or Dubois's parrot (Necropsittacus borbonicus) is a hypothetical extinct species of parrot based on descriptions of birds from the Mascarene island of Réunion. ") +label.flexCss("margin: 20, sizetofit: 1") +label.lineCount(0) + +contentView.flexChildren(view1, view2, label) +contentView.flexCss("flex-direction: column") +contentView.flxLayout(true, function() + print("cccc") +end) + +view2.callback(function() + view3.flexCss("flex: 2") + view4.flexCss("flex: 1") + + contentView.flxLayout() +end) diff --git a/Android/LuaViewDemo/assets/test/UI_HScrollView.lua b/Android/LuaViewDemo/assets/test/UI_HScrollView.lua new file mode 100644 index 00000000..ed0b18b9 --- /dev/null +++ b/Android/LuaViewDemo/assets/test/UI_HScrollView.lua @@ -0,0 +1,54 @@ +-- Created by LuaView. +-- Copyright (c) 2017, Alibaba Group. All rights reserved. +-- +-- This source code is licensed under the MIT. +-- For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + +--工具包引入 +require "kit/lv_kit" + + +-- 活动指示器 +local SCREEN_WIDTH = System.screenSize() + +local scrollView = HScrollView() +b0 = Button() +b0.text("scrollTo") +b0.callback(function() + scrollView.offset(2, 0) +end) + +b1 = Button() +b1.text("scrollBy") +b1.xy(100, 0) +b1.callback(function() + scrollView.scrollBy(20, 0) +end) + +b3 = Button() +b3.text("smoothScrollTo") +b3.xy(0, 75) +b3.callback(function() + scrollView.offset(20, 0, true) +end) + +b4 = Button() +b4.text("smoothScrollBy") +b4.xy(150, 75) +b4.callback(function() + scrollView.smoothScrollBy(20, 0) +end) + + +for i = 0, 10, 1 do + local btn = Label() + btn.text("BTN" .. i) + btn.frame(i * 60, 10, 59, 80) + btn.backgroundColor(0xff00ff00) + scrollView.addView(btn) +end + +scrollView.xy(0, 300) +scrollView.size(SCREEN_WIDTH, 100) +scrollView.backgroundColor(0xffcccccc) +scrollView.showScrollIndicator(false) diff --git a/Android/LuaViewDemo/assets/test/UI_HelloLuaView.lua b/Android/LuaViewDemo/assets/test/UI_HelloLuaView.lua new file mode 100644 index 00000000..c6ef71c8 --- /dev/null +++ b/Android/LuaViewDemo/assets/test/UI_HelloLuaView.lua @@ -0,0 +1,23 @@ +-- Created by LuaView. +-- Copyright (c) 2017, Alibaba Group. All rights reserved. +-- +-- This source code is licensed under the MIT. +-- For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + +local screenWidth, screenHeight = System.screenSize() + +-- Test Label +local label = Label() +label.text(System.ios() and "iOS" or "Android") +label.textColor(0x000000) +label.frame(0, 0, screenWidth, screenHeight) +label.textAlign(TextAlign.CENTER) + +-- Test Button +local btn = Button() +btn.size(200, 200) +btn.text("Click Me") +btn.backgroundColor(0xff0000) +btn.callback(function() + Alert("Hello LuaView") +end) diff --git a/Android/LuaViewDemo/assets/test/UI_Image.lua b/Android/LuaViewDemo/assets/test/UI_Image.lua new file mode 100644 index 00000000..0201b69f --- /dev/null +++ b/Android/LuaViewDemo/assets/test/UI_Image.lua @@ -0,0 +1,88 @@ +-- Created by LuaView. +-- Copyright (c) 2017, Alibaba Group. All rights reserved. +-- +-- This source code is licensed under the MIT. +-- For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + +--1. 普通设置url,size,center +view = Image() +view.size(100, 100) +view.center(50, 50) +print(view.size()) +view.backgroundColor(0xffaa0000) +view.callback(function() + print("Button Clicked") +end) +view.image("animate1") + +print("view-url", view.image()) + + +--2. 普通构造传url +view2 = Image("https://gju1.alicdn.com/bao/uploaded/i4/100000120700895002/TB2Qu0_fXXXXXb9XpXXXXXXXXXX_!!0-0-juitemmedia.jpg_560x560Q90.jpg") +view2.frame(150, 0, 150, 100) +print("view2-url", view2.image()) + + + +scrW, scrH = System.screenSize(); +window.backgroundColor("#FFFF00", 0.5); + +w = scrW / 3; +X0 = scrW / 10; +Y0 = scrH / 4; + + +imageView = Image(); +imageView.frame(X0, Y0, w, w); +imageView.backgroundColor(0xff0000, 0.5); +imageView.startAnimationImages({"animate1", "animate2"}, 3.0, 1); + +imageView.callback({ + onShow = function() + print("show") + end, + onHide = function() + print("hide") + end +}) + +window.callback({ + onShow = function() + print("window show") + end, + onHide = function() + print("window hide") + end +}) + +label = Label(); + +imageView2 = Image(); +imageView2.frame(X0 + w + X0, Y0, w, w); +imageView2.image("http://g.alicdn.com/ju/lua/2.0.24/doc/icon.png", + function() + --这里的text会报一个bug + print("图片加载成功!"); + label.text("图片加载成功!") + label.adjustSize(); + label.center(scrW / 2, scrH / 2); + end); + + + +-- gif +imageView3 = Image() +imageView3.image("http://static1.squarespace.com/static/552a5cc4e4b059a56a050501/565f6b57e4b0d9b44ab87107/565f6ddee4b0d9b44ab89215/1449098068446/NYCGifathon2.gif", function() end) +imageView3.frame(scrW / 2 - 50, scrH / 2 + 100, 100, 100) +imageView3.callback(function() + imageView3.adjustSize() +end) + + + + + + + + diff --git a/Android/LuaViewDemo/assets/test/UI_Label.lua b/Android/LuaViewDemo/assets/test/UI_Label.lua new file mode 100644 index 00000000..5e20ce67 --- /dev/null +++ b/Android/LuaViewDemo/assets/test/UI_Label.lua @@ -0,0 +1,80 @@ +-- Created by LuaView. +-- Copyright (c) 2017, Alibaba Group. All rights reserved. +-- +-- This source code is licensed under the MIT. +-- For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + +screenWidth, screenHeight = System.screenSize() +bg = View() +bg.backgroundColor(0xdddddd, 0.5) +bg.size(screenWidth, 60) + +a = Label() +a.text("测试") +a.backgroundColor(0xaaaa00) +a.xy(10, 10) +a.size(100, 50) + +b = Label() +b.text(StyledString("测试说", {fontColor=0xff0000, fontWeight=FontWeight.BOLD--[[fontStyle="bold", fontWeight="bold"]]})) +b.fontSize(12) +b.backgroundColor(0xaa00aa) +b.cornerRadius(5) +b.xy(50, 10) + +c = Label() +c.font("fonts/iconfont.ttf", 40) +c.text(Unicode(0xe617) .. "123") +c.backgroundColor(0x999999) +c.xy(180, 10) + +view = Label() +view.text("测试1") +view.font(20) +view.lines(2) +view.backgroundColor(0xaaaa00) +view.frame(50, 120, 50, 50) + + +view2 = Label() +view2.text("测试2") +view2.font(20) +view2.lines(2) +view2.backgroundColor(0xaaaa00) +view2.frame(50, 190, 50, 50) + +view3 = Label() +view3.text("测试3测试3测试3测试3测试3测试3测试3测试3测试3测试3测试3测试3测试3测试3测试3测试3测试3测试3测试3测试3测试3测试3测试3测试3测试3测试3测试3测试3测试3测试3测试3测试3测试3测试3测试3测试3测试3测试3测试3测试3测试3测试3测试3测试3测试3") +view3.font(20) +view3.lines(2) +view3.backgroundColor(0xaaaa00) +view3.frame(50, 270, 100, 100) + +view4 = Label() +view4.text("测试4测试4测试4测试4测试4") +view4.font(20) +view4.lines(1) +view4.backgroundColor(0xaaaa00) +view4.frame(50, 400, 100, 100) + +btn = Button() +btn.text("adjustFontSize") +btn.xy(0, 70) +btn.callback(function() + view.text(view.text() .. "测试1") + view.adjustFontSize() +end) + + +btn2 = Button() +btn2.xy(200, 70) +btn2.text("adjustSize") +btn2.callback(function() + view2.adjustSize() + view3.adjustSize() + view4.adjustSize() +end) + + + + diff --git a/Android/LuaViewDemo/assets/test/UI_LoadingDialog.lua b/Android/LuaViewDemo/assets/test/UI_LoadingDialog.lua new file mode 100644 index 00000000..1832b7e9 --- /dev/null +++ b/Android/LuaViewDemo/assets/test/UI_LoadingDialog.lua @@ -0,0 +1,31 @@ +-- Created by LuaView. +-- Copyright (c) 2017, Alibaba Group. All rights reserved. +-- +-- This source code is licensed under the MIT. +-- For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + +--工具包引入 +require "kit/lv_kit" + +local loading +local width = System.screenSize() +local timer = Timer() + +btn1 = Button() +btn1.callback(function() + loading = LoadingDialog(); + loading.show() + + if (timer) then + timer.start(5).callback(function() + Toast("canceld by Timer") + if (loading) then + loading.hide() + end + end) + end +end) + +btn1.text("Start") +btn1.frame(0, 0, width, 100) + diff --git a/Android/LuaViewDemo/assets/test/UI_LoadingIndicator.lua b/Android/LuaViewDemo/assets/test/UI_LoadingIndicator.lua new file mode 100644 index 00000000..c5d031a1 --- /dev/null +++ b/Android/LuaViewDemo/assets/test/UI_LoadingIndicator.lua @@ -0,0 +1,39 @@ +-- Created by LuaView. +-- Copyright (c) 2017, Alibaba Group. All rights reserved. +-- +-- This source code is licensed under the MIT. +-- For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + +--工具包引入 +require "kit/lv_kit" + + + +local loading = LoadingIndicator() +loading.backgroundColor(0xaaaa0000) +loading.size(50, 50) +loading.alignCenter() + +local width = System.screenSize() + +btn1 = Button() +btn1.callback(function() + if (loading) then + loading.show() + end +end) + +btn2 = Button() +btn2.callback(function() + if (loading) then + loading.hide() + end +end) + + +btn1.text("Start") +btn1.frame(0, 100, width, 100) +btn2.text("Stop") +btn2.frame(0, 300, width, 100) + + diff --git a/Android/LuaViewDemo/assets/test/UI_Navigation.lua b/Android/LuaViewDemo/assets/test/UI_Navigation.lua new file mode 100644 index 00000000..c10ba815 --- /dev/null +++ b/Android/LuaViewDemo/assets/test/UI_Navigation.lua @@ -0,0 +1,40 @@ +-- Created by LuaView. +-- Copyright (c) 2017, Alibaba Group. All rights reserved. +-- +-- This source code is licensed under the MIT. +-- For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + + +scrW, scrH = System.screenSize(); + +function createButton( text , x,y,w,h, callback) + local button = Button(); + button.frame(x,y,w,h); + button.text(text); + button.backgroundColor(0xeeeeee); + button.callback( function() + print("ok",button); + if( callback ) then + callback(); + end + end ); + return button; +end + +buttonH = scrH /10; + +----------------- + +button1 = createButton("设置导航栏 标题",0,buttonH*1,scrW,buttonH, function() + Navigation.title("测试view") + end); + + +img = Image(); +img.image("http://gtms02.alicdn.com/tps/i2/TB1qmXnHpXXXXcuaXXXQG.m0FXX-640-128.jpg",function() + Navigation.background(img, 0xff0000) +end); + + + + diff --git a/Android/LuaViewDemo/assets/test/UI_NoticeView.lua b/Android/LuaViewDemo/assets/test/UI_NoticeView.lua new file mode 100644 index 00000000..8a6c4d98 --- /dev/null +++ b/Android/LuaViewDemo/assets/test/UI_NoticeView.lua @@ -0,0 +1,29 @@ +-- Created by LuaView. +-- Copyright (c) 2017, Alibaba Group. All rights reserved. +-- +-- This source code is licensed under the MIT. +-- For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + +--工具包引入 +require "kit/lv_kit" + +local width = System.screenSize() + +btn1 = Button() +btn1.callback(function() + Toast(StyledString("测试一下Toast", {fontColor=0xffff0000, backgroundColor=0xff00ff00, fontSize=50})) +end) + +btn2 = Button() +btn2.callback(function() + local notice = Toast(); + notice.show("xx") +end) + + +btn1.text("第一") +btn1.frame(0, 0, width, 100) +btn2.text("第二") +btn2.frame(0, 150, width, 100) + + diff --git a/Android/LuaViewDemo/assets/test/UI_OnTouch.lua b/Android/LuaViewDemo/assets/test/UI_OnTouch.lua new file mode 100644 index 00000000..19842bef --- /dev/null +++ b/Android/LuaViewDemo/assets/test/UI_OnTouch.lua @@ -0,0 +1,105 @@ +-- Created by LuaView. +-- Copyright (c) 2017, Alibaba Group. All rights reserved. +-- +-- This source code is licensed under the MIT. +-- For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + +sw, sh = System.screenSize() + +bg = Label() +bg.text("我是背景,重复进入页面,尝试不同状态。") +bg.frame(0, 0, sw, sh) +bg.callback(function() + Toast("bg clicked") +end) + + +view = CustomView() +view.frame(0, 0, sw,sh) +view.backgroundColor(0xff0000, 0.5) + +lastX = nil +lastY = nil + +x = 0 +y = 0 +w = 4 +dx = 0 +dy = 0 + +isTouchable = math:random() > 0.5 + +bg.text(bg.text() .. (isTouchable and " 不可点击" or " 可以点击")) + +view.onTouch(function(event) + print(event.id, event.pointer, event.action, event.x, event.y) + dx = lastX and event.x - lastX or 0 + dy = lastY and event.y - lastY or 0 + + + x = x + dx + y = y + dy + + if(x < 0) then + x = 0 + end + + if(y < 0) then + y = 0 + end + + if(x > sw) then + x = sw + end + + if (y > sh) then + y = sh + end + + lastX = event.action == TouchEvent.MOVE and event.x or nil + lastY = event.action == TouchEvent.MOVE and event.y or nil + + view.invalidate() + + return isTouchable; +end) + +rect = {} + +count = 20 + +for i = 0, count, 1 do + rect[i + 1] = {} + rect[i + 1][1] = x + rect[i + 1][2] = y + rect[i + 1][3] = w + rect[i + 1][4] = w + + x = x + 20 + + w = 3 + math:random(10) +end + +view.onDraw(function(canvas) + print(x, y, w, h) + + for i = 0, count, 1 do + canvas.drawRect(rect[i+1][1], rect[i+1][2], rect[i+1][3], rect[i+1][4]) + end + + for i = 0, count, 1 do + rect[i+1][2] = (rect[i+1][2] + math:random()) * 1.005 - dy + + if(rect[i+1][2] + rect[i+1][4] > 500) then + rect[i+1][2] = 500 - rect[i + 1][4] + end + end + + canvas.drawLine(0, 500 - dy, sw, 500-dy) + +end) + + +Timer().callback(function() + view.invalidate() +end).start(0.01, true) \ No newline at end of file diff --git a/Android/LuaViewDemo/assets/test/UI_PagerIndicator.lua b/Android/LuaViewDemo/assets/test/UI_PagerIndicator.lua new file mode 100644 index 00000000..ed0db0af --- /dev/null +++ b/Android/LuaViewDemo/assets/test/UI_PagerIndicator.lua @@ -0,0 +1,53 @@ +-- Created by LuaView. +-- Copyright (c) 2017, Alibaba Group. All rights reserved. +-- +-- This source code is licensed under the MIT. +-- For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + +--工具包引入 +require "kit/lv_kit" + +-- 活动指示器 +local SCREEN_WIDTH = System.screenSize() + +function createCircleIndicator() + local indicator = PagerIndicator() +-- indicator.size(SCREEN_WIDTH / 2, 100) +-- indicator.alignCenter() + indicator.frame(10, 100, SCREEN_WIDTH / 2, 100) + indicator.selectedColor(0xff0000) + indicator.unselectedColor(0x00ff00) +-- indicator.fillColor(0xff0000) +-- indicator.pageColor(0x00ff00) + return indicator +end + +pagerView = PagerView({ + PageCount = 12, + Pages = { + Title = function(pos) + return "Title" + end, + Init = function(page, pos) + page.icon = Button() + end, + Layout = function(page, pos) + page.icon.text("测试按钮"..pos) + page.icon.frame(0, 0, SCREEN_WIDTH, 50) + end + }, + Callback = { + Scrolling=function(pos, percent, distance) + Toast("滑动"..pos) + end, + Selected=function(pos) + Toast("选中"..pos) + end + } +}) + +--活动指示器 +pagerView.indicator(createCircleIndicator()) + + + diff --git a/Android/LuaViewDemo/assets/test/UI_PagerView.lua b/Android/LuaViewDemo/assets/test/UI_PagerView.lua new file mode 100644 index 00000000..8a567c3c --- /dev/null +++ b/Android/LuaViewDemo/assets/test/UI_PagerView.lua @@ -0,0 +1,53 @@ +-- Created by LuaView. +-- Copyright (c) 2017, Alibaba Group. All rights reserved. +-- +-- This source code is licensed under the MIT. +-- For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + +--工具包引入 +require "kit/lv_kit" + +local width, height = System.screenSize() + +vp = PagerView({ + PageCount = 4, + Pages = { + Title = function(pos) + return "Title" + end, + Init = function(page, pos) + page.icon = Button() + end, + Layout = function(page, pos) + page.icon.text("测试按钮"..(pos-1)) + page.icon.frame(0, 0, width, 200) + page.icon.callback(function() + if(pos == 1) then + vp.looping(true) + vp.autoScroll(1) + elseif(pos == 2) then + vp.looping(false) + vp.autoScroll(0) + elseif(pos == 3) then + vp.autoScroll(1, true) + elseif(pos == 4) then + vp.looping(true) + end + end) + end + }, + Callback = { + Scrolling=function(pos, percent, distance) + Toast("滑动"..pos) + print("滚动"..pos) + end, + Selected=function(pos) + Toast("选中"..pos) + print("选中"..pos) + end + } +}) + +vp.backgroundColor(0xaaaa0000) +vp.frame(0, 20, width, height - 20) + diff --git a/Android/LuaViewDemo/assets/test/UI_PagerViewAndCollectionView.lua b/Android/LuaViewDemo/assets/test/UI_PagerViewAndCollectionView.lua new file mode 100644 index 00000000..6005eda0 --- /dev/null +++ b/Android/LuaViewDemo/assets/test/UI_PagerViewAndCollectionView.lua @@ -0,0 +1,153 @@ +-- Created by LuaView. +-- Copyright (c) 2017, Alibaba Group. All rights reserved. +-- +-- This source code is licensed under the MIT. +-- For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + +--工具包引入 +require "kit/lv_kit" + +w, h = System.screenSize() + +cellHeight = 100 +imageUrl1 = "http://gju2.alicdn.com/bao/uploaded/i1/10000073270926575/TB2fpg0cXXXXXb6XpXXXXXXXXXX_!!0-0-juitemmedia.jpg" +imageUrl2 = "http://img4.duitang.com/uploads/item/201306/25/20130625045508_sairr.thumb.600_0.jpeg" + + +local vp = PagerView({ + PageCount = 4, + Pages = { + Title = function(pos) + return "Title" + end, + Init = function(page, pos) + local tableView = RefreshCollectionView { + Section = { + SectionCount = 2, + RowCount = function(section) + if(section == 1) then + return 1 + elseif(section == 2) then + return 10 + end + end + }, + Cell = { + Id = function(section, row) + if(pos % 2 ~= 0) then + if (section == 1) then + return "HScroll" + else + return "ImageAndImage" + end + else + if (section == 2) then + return "Pager" + else + return "ImageAndImage" + end + end + end, + HScroll = { + Size = function(section, row) + return w, 100 + end, + Init = function(cell, section, row) + local scrollView = HScrollView() + for i = 0, 10, 1 do + local btn = Label() + btn.text("BTN" .. i) + btn.frame(i * 80, 0, 79, 100) + btn.backgroundColor(0xff00ff00) + btn.callback(function() + Toast(btn.text()) + end) + scrollView.addView(btn) + end + scrollView.size(w, 100) + scrollView.backgroundColor(0xffcccccc) + cell.container= scrollView + end, + Layout = function(cell, section, row) + end + }, + Pager = { + Size = function(section, row) + return w, 100 + end, + Init = function(cell, section, row) + local vp = PagerView({ + PageCount = 10, + Pages = { + Title = function(pos) + return "Title" + end, + Init = function(page, pos) + page.icon = Button() + end, + Layout = function(page, pos) + page.icon.text("测试按钮"..pos) + page.icon.frame(0, 0, w, 100) + page.icon.callback(function() + Toast(page.icon.text()) + end) + end + } + }) + + vp.backgroundColor(0xaaaa0000) + vp.frame(0, 0, w, 100) + + cell.container = vp + end, + Layout = function(cell, section, row) + end + }, + ImageAndImage = { + Size = function(section, row) + return cellHeight + end, + Init = function(cell, section, row) + cell.icon = Image() + cell.icon2 = Image() + end, + Layout = function(cell, section, row) + local cellWdith, cellHeight = cell.window.size() + cell.icon.frame(0, 0, cellHeight, cellHeight) + cell.icon.image(imageUrl1, function() + print("imageLoaded-ImageAndImage-1", section, row) + end) + cell.icon.callback(function() + print("cell_icon1") + end) + + + cell.icon2.frame(cellHeight + 10, 0, cellHeight, cellHeight) + cell.icon2.image(imageUrl1, function() + print("imageLoaded-ImageAndImage-2", section, row) + end) + cell.icon2.callback(function() + print("cell_icon2") + end) + end + } + } + } + tableView.frame(0, 0, w, h - 64) + + page.view = tableView + + end, + Layout = function(page, pos) + end + } +}) + +vp.backgroundColor(0xaaaa0000) +vp.frame(0, 0, w, h) + + + + + + diff --git a/Android/LuaViewDemo/assets/test/UI_RecyclerView.lua b/Android/LuaViewDemo/assets/test/UI_RecyclerView.lua new file mode 100644 index 00000000..957c24d1 --- /dev/null +++ b/Android/LuaViewDemo/assets/test/UI_RecyclerView.lua @@ -0,0 +1,87 @@ +-- Created by LuaView. +-- Copyright (c) 2017, Alibaba Group. All rights reserved. +-- +-- This source code is licensed under the MIT. +-- For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + +--工具包引入 +require "kit/lv_kit" +-- 变量定义 +local s_width, s_height = System.screenSize() +local tableView + +local tableViewData = { + Section = { + SectionCount = 2, -- section数量 + RowCount = function(section) + if(section == 1) then + return 50 + else + return 50 + end + end + }, + Cell = { + Id = function(section, row) -- 指定section和row对应的Cell类型唯一识别号 + local id = "Cell1" .. section .. row + print("Id", id) + return id; + end, + + Cell1 = { + Size = function(section, row) + print("Size", section, row, 10 + row * 2) + return 10 + row * 2 + end, + Init = function(cell, section, row) -- 初始化cell + print("Init", section, row, 10 + row * 2) + cell.title = Label(); + cell.title.backgroundColor(section == 1 and 0xff0000 or 0x00ff00) + end, + Layout = function(cell, section, row) -- cell复用时调用 + print("Layout", section, row, 10 + row * 2) +-- cell.title.frame(0, 0, s_width, 10 + row * 2) + cell.title.text(section .. '--' .. row) + end, + Callback = function(cell, section, row) -- 用户点击了section和row + Toast("Section " .. section .. ", Row " .. row); + end + } + } +} + +local cellData = function(_, key) + print(key) + return { + Size = function(section, row) + print("Size", section, row, 10 + row * 2) + return 10 + row * 2 + end, + Init = function(cell, section, row) -- 初始化cell + print("Init", section, row, 10 + row * 2) + cell.title = Label(); + cell.title.backgroundColor(section == 1 and 0xff0000 or 0x00ff00) + end, + Layout = function(cell, section, row) -- cell复用时调用 + print("Layout", section, row, 10 + row * 2) + cell.title.frame(0, 0, s_width, 10 + row * 2) + cell.title.text(section .. '--' .. row) + end, + Callback = function(cell, section, row) -- 用户点击了section和row + Toast("Section " .. section .. ", Row " .. row); + end + } +end + +setmetatable(tableViewData.Cell, { __index = cellData }) +tableView = CollectionView(tableViewData) +tableView.reload() +tableView.miniSpacing(1) +tableView.frame(0, 0, s_width, s_height) +tableView.showScrollIndicator(true) + + + + + + diff --git a/Android/LuaViewDemo/assets/test/UI_RecyclerViewPinned.lua b/Android/LuaViewDemo/assets/test/UI_RecyclerViewPinned.lua new file mode 100644 index 00000000..3a89c70e --- /dev/null +++ b/Android/LuaViewDemo/assets/test/UI_RecyclerViewPinned.lua @@ -0,0 +1,252 @@ +-- Created by LuaView. +-- Copyright (c) 2017, Alibaba Group. All rights reserved. +-- +-- This source code is licensed under the MIT. +-- For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + +-- +-- Created by IntelliJ IDEA. +-- User: tuoli +-- Date: 11/4/16 +-- Time: 7:00 PM +-- To change this template use File | Settings | File Templates. +-- + +w,h = System.screenSize(); +imageUrl1 = "http://gju2.alicdn.com/bao/uploaded/i1/10000073270926575/TB2fpg0cXXXXXb6XpXXXXXXXXXX_!!0-0-juitemmedia.jpg" +imageUrl2 = "http://img4.duitang.com/uploads/item/201306/25/20130625045508_sairr.thumb.600_0.jpeg" +collectionView = RefreshCollectionView { + Section = { + SectionCount = 26, + RowCount = function(section, row) + return 8; + end, + }, + Cell = { + Id = function ( section, row ) + if (section == 1 and row ==1) then + return "Pager" + end + + if (row == 2) then + return "PinnedCell1", Pinned.YES; + -- if (section == 2 and row == 1) then + -- return "PinnedScrollCell", Pinned.YES; + else + return "ImageAndLabel" + end + end, + PinnedScrollCell = { + Size = function(section, row) + return w, 60; + end, + Init = function(cell, section, row) + cell.window.backgroundColor(0xf0ff97) + cell.scrollView = HScrollView(); + cell.scrollView.frame(0, 0, w, 60); + cell.views = {}; + for i = 0, 30, 1 do + local btn = Label() + btn.text(section .. " BTN " .. i) + btn.frame(0, 0, 60, 40) + btn.backgroundColor(0xff00ff00) + local view = View() + view.frame(i * 60, 10, 60, 50) + view.callback( + function() + Toast(btn.text()) + cell.window.backgroundColor(0x032f00) + end + ) + view.addView(btn) + cell.scrollView.addView(view) + cell.views[i] = view; + end + cell.scrollView.contentSize(30*60,0); + end, + Layout = function(cell, section, row) + end + }, + PinnedCell1 = { + Size = function(section, row) + return w, 50; + end, + Init = function(cell, section, row) + cell.title = Label(); + cell.title.frame(50, 0, 100, 50); + cell.title.backgroundColor(0xffffff) + if (section % 2 == 1) then + cell.window.backgroundColor(0x80ffff) + else + cell.window.backgroundColor(0x80f56f) + end + end, + Layout = function(cell, section, row) + cell.title.text("Type " .. section); + if (section % 2 == 1) then + cell.title.textColor(0x00f309) + else + cell.title.textColor(0x000000) + end + + end, + + Callback = { + Click = function() + end, + LongClick = function() + end + } + }, + Pager = { + Size = function(section, row) + return w, 200; + end, + Init = function(cell, section, row) + local cellWidth ,cellHeight = cell.window.size(); + cell.pagerView = PagerView({ + PageCount = function() + return 2 + end, + Pages = { + Title = function(pos) + return "Title" + end, + Init = function(page, pos) + page.icon = Button() + if (pos == 1) then + page.icon.backgroundColor(0x00ff00) + else + page.icon.backgroundColor(0x00ffff) + end + end, + Layout = function(page, pos) + page.icon.text("测试按钮"..pos) + page.icon.frame(0, 0, cell.pagerView.width()-60, 150) + end + }, + Callback = { + Scrolling=function(pos, percent, distance) + Toast("滑动"..pos) + end, + Selected=function(pos) + Toast("选中"..pos) + end + } + }) + cell.pagerView.frame(0, 0, cellWidth, cellHeight); + cell.pagerView.looping(true) + cell.pagerView.autoScroll() + -- cell.pagerView.nativeView().setClipToPadding(false) + -- cell.pagerView.nativeView().setPadding(150, 0, 150, 0) + cell.pagerView.previewSide(30, 30) + -- cell.pagerView.backgroundColor(0xff0000) + local createCircleIndicator = function () + local indicator = PagerIndicator() + -- indicator.size(SCREEN_WIDTH / 2, 100) + -- indicator.alignCenter() + -- print("tuoli", cell.pagerView.width()) + indicator.frame(0, 180, cell.pagerView.width(), 30) + indicator.selectedColor(0xff0000) + indicator.unselectedColor(0x00ff00) + -- indicator.fillColor(0xff0000) + -- indicator.pageColor(0x00ff00) + return indicator + end + + --活动指示器 + cell.pagerView.indicator(createCircleIndicator()) + end, + Layout = function(cell , section, row) + -- cell.icon.image(imageUrl1, function() + -- local x,y,w,h = cell.icon.frame(); + -- end); + end, + Callback = function(cell, section, row) + end + }, + ImageAndLabel = { + Size = function(section, row) + return w ,200; + end, + Init = function(cell, section, row) + local cellWidth ,cellHeight = cell.window.size(); + cellHeight = cellHeight / 2; + cell.icon = Image(); + cell.icon.frame(0, 0, cellHeight, cellHeight); + cell.title = Label(); + cell.title.frame(0, cellHeight, cellHeight, cellHeight/2); + cell.title.textColor(0xffFFFF); + cell.title.backgroundColor(0xff00ff); + end, + Layout = function(cell , section, row) + cell.icon.image(imageUrl1, function() + local x,y,w,h = cell.icon.frame(); + end); + cell.title.text("测试"..section .."--" .. row); + cell.window.backgroundColor( section*0x770000 + (row%3)*0x33 ); + end, + Callback = function(cell, section, row) + print(section, row); + System.gc(); + collectionView.scrollToCell(section, row); + end + }, + ImageAndLabel2 = { + Size = function(section, row) + return w ,200; + end, + Init = function(cell) + local cellHeight = 100 + cell.icon = Image(); + cell.icon.frame(w*0.05, 10, cellHeight, cellHeight); + cell.icon2 = Image(); + cell.icon2.frame(160, 0, cellHeight, cellHeight); + cell.button = Button(); + cell.button.frame(0,0,100,60); + cell.button.backgroundColor(0x777777); + cell.button.callback( + function() + Toast("hhhhhhh"); + end); + end, + Layout = function(cell , section, row) + cell.icon.image( + imageUrl1, + function() + local x,y,w,h = cell.icon.frame(); + end); + cell.icon2.image(imageUrl1) + cell.window.backgroundColor( section*0x770000 + (row%3)*0x33 ); + end, + Callback = { + Click = function() + print("tuoli ImageAndLabel2 Click") + end, + LongClick = function() + end + } + } + }, + Callback = { + Scrolling = function( firstVisibleSection, firstVisibleRow, visibleCellCount ) + -- print("scrolling", firstVisibleSection,"---" ,firstVisibleRow, "---", visibleCellCount); + end, + ScrollBegin = function(firstVisibleSection, firstVisibleRow, visibleCellCount ) + -- print("scrolling begin", firstVisibleSection,"---" ,firstVisibleRow, "---", visibleCellCount); + end, + ScrollEnd = function(firstVisibleSection, firstVisibleRow, visibleCellCount ) + -- print("scrolling end", firstVisibleSection,"---" ,firstVisibleRow, "---", visibleCellCount); + end, + PullDown = function() + collectionView.stopRefreshing() + collectionView.reload() + end + } +}; +collectionView.frame(0,0,w,h-64); +collectionView.backgroundColor(0xffFFFF); +collectionView.miniSpacing(5) + +print("tuoli System.vmVersion = ", System.vmVersion() ) + diff --git a/Android/LuaViewDemo/assets/test/UI_RefreshCollectionView.lua b/Android/LuaViewDemo/assets/test/UI_RefreshCollectionView.lua new file mode 100644 index 00000000..7c299a08 --- /dev/null +++ b/Android/LuaViewDemo/assets/test/UI_RefreshCollectionView.lua @@ -0,0 +1,125 @@ +-- Created by LuaView. +-- Copyright (c) 2017, Alibaba Group. All rights reserved. +-- +-- This source code is licensed under the MIT. +-- For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + +w, h = System.screenSize(); + +cellHeight = 100 +imageUrl1 = "http://gju2.alicdn.com/bao/uploaded/i1/10000073270926575/TB2fpg0cXXXXXb6XpXXXXXXXXXX_!!0-0-juitemmedia.jpg" +imageUrl2 = "http://img4.duitang.com/uploads/item/201306/25/20130625045508_sairr.thumb.600_0.jpeg" + +collectionView = RefreshCollectionView { + Section = { + SectionCount = 10, + RowCount = function(section) + if(section == 4 or section == 6) then + return 10; + end + return 1 + end + }, + Cell = { + Id = function(section, row) + if (section == 4) then + return "ImageAndLabel"; + elseif(section == 6) then + return "ImageAndImage"; + end + return "NONE" + end, + NONE = { + Init = function(cell) + end, + Layout = function(cell, section, row) + cell.line = View(); + cell.line.size(w, 1) + cell.line.backgroundColor(0xff0000); + end, + Size = function(section, row) + return w, 1; + end, + Callback = function(cell, section, row) + end + + }, + ImageAndLabel = { + Size = function(section, row) + return 50, cellHeight; + end, + Init = function(cell, section, row) + cell.bg = View() + cell.icon = Image(); + cell.title = Label(); + print("构造Cell"); + end, + Layout = function(cell, section, row) + cell.icon.frame(0, 0, 20, 50); + cell.icon.image(imageUrl1, function() + print("imageLoaded-ImageAndLabel", section, row) + end); + + cell.title.frame(20, 0, w - 20, cellHeight); + cell.title.text("测试" .. section .. "--" .. row); + + cell.bg.addView(cell.bg) + end, + Callback = function(section, row) + print(section, row); + collectionView.stopRefreshing(); + System.gc(); + end + }, + ImageAndImage = { + Size = function(section, row) + return cellHeight; + end, + Init = function(cell, section, row) + cell.icon = Image(); + cell.icon2 = Image(); + end, + Layout = function(cell, section, row) + print(window); + local cellWdith, cellHeight = cell.window.size(); + cell.icon.frame(0, 0, cellHeight, cellHeight); + cell.icon.image(imageUrl1, function() + print("imageLoaded-ImageAndImage-1", section, row) + end); + + + cell.icon2.frame(cellHeight + 10, 0, cellHeight, cellHeight); + cell.icon2.image(imageUrl1, function() + print("imageLoaded-ImageAndImage-2", section, row) + end); + end, + Callback = function(section, row) + print(section, row); + collectionView.stopRefreshing(); + System.gc(); + end + } + }, + Callback = { + Scrolling = function() + print("scrolling"); + end, + ScrollBegin = function() + print("scrolling begin"); + end, + ScrollEnd = function() + print("scrolling end"); + end, + PullDown = function() + print("PullDown"); + end + } +}; + +loading = false; + +collectionView.frame(0, 0, w, h - 64); +collectionView.showScrollIndicator(false) + + + diff --git a/Android/LuaViewDemo/assets/test/UI_RefreshTableView.lua b/Android/LuaViewDemo/assets/test/UI_RefreshTableView.lua new file mode 100644 index 00000000..15f88dba --- /dev/null +++ b/Android/LuaViewDemo/assets/test/UI_RefreshTableView.lua @@ -0,0 +1,108 @@ +-- Created by LuaView. +-- Copyright (c) 2017, Alibaba Group. All rights reserved. +-- +-- This source code is licensed under the MIT. +-- For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + +w, h = System.screenSize(); +cellHeight = 100 +imageUrl1 = "http://gju2.alicdn.com/bao/uploaded/i1/10000073270926575/TB2fpg0cXXXXXb6XpXXXXXXXXXX_!!0-0-juitemmedia.jpg" +imageUrl2 = "http://img4.duitang.com/uploads/item/201306/25/20130625045508_sairr.thumb.600_0.jpeg" + +tableView = RefreshTableView { + Section = { + SectionCount = 2, + RowCount = function(section) + return 10; + end + }, + Cell = { + Id = function(section, row) + if (section == 1) then + return "ImageAndLabel"; + else + return "ImageAndImage"; + end + end, + ImageAndLabel = { + Size = function(section, row) + return cellHeight; + end, + Init = function(cell, section, row) + cell.icon = Image(); + cell.title = Label(); + print("构造Cell"); + + cell.bg = Button() + end, + Layout = function(cell, section, row) + cell.icon.frame(20, 0, cellHeight, cellHeight); + cell.icon.image(imageUrl1, function() + print("imageLoaded-ImageAndLabel", section, row) + end); + + cell.title.frame(20 + cellHeight, 0, w - cellHeight, cellHeight); + cell.title.text("测试" .. section .. "--" .. row); + + + cell.bg.frame(0, 0, w, cellHeight) + cell.bg.image(nil, imageUrl1) + end, + Callback = function(section, row) + print(section, row); + tableView.stopRefreshing(); + System.gc(); + end + }, + ImageAndImage = { + Size = function(section, row) + return cellHeight; + end, + Init = function(cell, section, row) + cell.icon = Image(); + cell.icon2 = Image(); + end, + Layout = function(cell, section, row) + print(cell.window, "xxxxx"); + local cellWdith, cellHeight = cell.window.size(); + cell.icon.frame(0, 0, cellHeight, cellHeight); + cell.icon.image(imageUrl1, function() + print("imageLoaded-ImageAndImage-1", section, row) + end); + + + cell.icon2.frame(cellHeight + 10, 0, cellHeight, cellHeight); + cell.icon2.image(imageUrl1, function() + print("imageLoaded-ImageAndImage-2", section, row) + end); + end, + Callback = function(section, row) + print(section, row); + tableView.stopRefreshing(); + System.gc(); + end + } + }, + Callback = { + Scrolling = function() + print("scrolling"); + end, + ScrollBegin = function() + print("scrolling begin"); + end, + ScrollEnd = function() + print("scrolling end"); + end, + PullDown = function() + print("PullDown"); + end + } +}; + +loading = false; + +tableView.frame(0, 0, w, h - 64); +tableView.showScrollIndicator(false) + + + diff --git a/Android/LuaViewDemo/assets/test/UI_ScaleType.lua b/Android/LuaViewDemo/assets/test/UI_ScaleType.lua new file mode 100644 index 00000000..f39c0fb0 --- /dev/null +++ b/Android/LuaViewDemo/assets/test/UI_ScaleType.lua @@ -0,0 +1,70 @@ +-- Created by LuaView. +-- Copyright (c) 2017, Alibaba Group. All rights reserved. +-- +-- This source code is licensed under the MIT. +-- For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + +-- +-- Created by IntelliJ IDEA. +-- User: song +-- Date: 16/10/13 +-- Time: 下午2:32 +-- To change this template use File | Settings | File Templates. +-- + +--2. 普通构造传url +v1 = Image() +v1.frame(0, 0, 100, 100) +v1.scaleType(ScaleType.FIT_XY) +v1.image("https://gju1.alicdn.com/bao/uploaded/i4/100000120700895002/TB2Qu0_fXXXXXb9XpXXXXXXXXXX_!!0-0-juitemmedia.jpg_560x560Q90.jpg") + +v2 = Image() +v2.frame(101, 0, 100, 100) +v2.scaleType(ScaleType.FIT_START) +v2.image("https://gju1.alicdn.com/bao/uploaded/i4/100000120700895002/TB2Qu0_fXXXXXb9XpXXXXXXXXXX_!!0-0-juitemmedia.jpg_560x560Q90.jpg") + +v3 = Image() +v3.frame(202, 0, 100, 100) +v3.scaleType(ScaleType.FIT_END) +v3.image("https://gju1.alicdn.com/bao/uploaded/i4/100000120700895002/TB2Qu0_fXXXXXb9XpXXXXXXXXXX_!!0-0-juitemmedia.jpg_560x560Q90.jpg") + + +v4 = Image() +v4.scaleType(ScaleType.FIT_CENTER) +v4.image("https://gju1.alicdn.com/bao/uploaded/i4/100000120700895002/TB2Qu0_fXXXXXb9XpXXXXXXXXXX_!!0-0-juitemmedia.jpg_560x560Q90.jpg") +v4.frame(0, 101, 100, 100) + +v5 = Image() +v5.scaleType(ScaleType.CENTER) +v5.frame(101, 101, 100, 100) +v5.image("https://gju1.alicdn.com/bao/uploaded/i4/100000120700895002/TB2Qu0_fXXXXXb9XpXXXXXXXXXX_!!0-0-juitemmedia.jpg_560x560Q90.jpg") + +--TODO +v6 = Image() +v6.scaleType(ScaleType.CENTER_CROP) +v6.image("https://gju1.alicdn.com/bao/uploaded/i4/100000120700895002/TB2Qu0_fXXXXXb9XpXXXXXXXXXX_!!0-0-juitemmedia.jpg_560x560Q90.jpg") +v6.frame(202, 101, 100, 100) + + +v7 = Image() +v7.scaleType(ScaleType.CENTER_INSIDE) +v7.image("https://gju1.alicdn.com/bao/uploaded/i4/100000120700895002/TB2Qu0_fXXXXXb9XpXXXXXXXXXX_!!0-0-juitemmedia.jpg_560x560Q90.jpg") +v7.frame(0, 202, 100, 100) + +--TODO +v8 = Image() +v8.scaleType(ScaleType.MATRIX) +v8.image("https://gju1.alicdn.com/bao/uploaded/i4/100000120700895002/TB2Qu0_fXXXXXb9XpXXXXXXXXXX_!!0-0-juitemmedia.jpg_560x560Q90.jpg") +v8.frame(101, 202, 100, 100) + + +v9 = Image() +v9.scaleType(ScaleType.CENTER_CROP) +v9.image("https://gju1.alicdn.com/bao/uploaded/i4/100000120700895002/TB2Qu0_fXXXXXb9XpXXXXXXXXXX_!!0-0-juitemmedia.jpg_560x560Q90.jpg") +v9.scale(1.2, 1.2) +v9.frame(0, 303, 100, 100) + + + + + diff --git a/Android/LuaViewDemo/assets/test/UI_StyledString.lua b/Android/LuaViewDemo/assets/test/UI_StyledString.lua new file mode 100644 index 00000000..dc2e3866 --- /dev/null +++ b/Android/LuaViewDemo/assets/test/UI_StyledString.lua @@ -0,0 +1,52 @@ +-- Created by LuaView. +-- Copyright (c) 2017, Alibaba Group. All rights reserved. +-- +-- This source code is licensed under the MIT. +-- For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + +--1. 普通设置url,size,center,contentmode等 + +as0 = StyledString("测试一啊12345", { fontColor = 0xffffff }) +as1 = StyledString("测试一啊12345", { fontColor = 0xffff0000, fontWeight = 600}) +as11 = StyledString("测试一啊12345", { fontColor = 0xffff0000, fontStyle = "bold" }) +as2 = StyledString("测试2", { backgroundColor = 0xaa00ff00, fontSize = 10 }) +as3 = StyledString("3333", { fontColor = 0xff0000ff, fontSize = 14 }) +as4 = StyledString(Unicode(0xe607), { fontColor = 0xff00aaff, fontSize = 40 }) + + +label0 = Label() +label0.text(as0) +print(label0.textColor()) + +label = Label() +label.xy(0, 20) +label.text(as1) + +label2 = Label() +label2.xy(0, 40) +label2.text(as11) + +button = Button() +button.text(as2) +button.xy(0, 60) + + +button2 = Button() +button2.text(as1 + as2 + as3) +button2.xy(0, 150) + + +button3 = Button() +button3.fontName("fonts/iconfont"); +button3.text(as4 + as2) +button3.xy(0, 200) + +print(button3.fontName()) + + + + + + + + diff --git a/Android/LuaViewDemo/assets/test/UI_TableView.lua b/Android/LuaViewDemo/assets/test/UI_TableView.lua new file mode 100644 index 00000000..ac5d3ff1 --- /dev/null +++ b/Android/LuaViewDemo/assets/test/UI_TableView.lua @@ -0,0 +1,63 @@ +-- Created by LuaView. +-- Copyright (c) 2017, Alibaba Group. All rights reserved. +-- +-- This source code is licensed under the MIT. +-- For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + +--工具包引入 +require "kit/lv_kit" +-- 变量定义 +local s_width, s_height = System.screenSize() +local tableView + +local tableViewData = { + Section = { + SectionCount = 1, -- section数量 + RowCount = function(section) + return 50 + end + }, + Cell = { + Id = function(section, row) -- 指定section和row对应的Cell类型唯一识别号 + local id = "Cell1" .. row + print("Id", id) + return id; + end + } +} + +local cellData = function(_, key) + print(key) + return { + Size = function(section, row) + print("Size", section, row, 10 + row * 2) + return 10 + row * 2 + end, + Init = function(cell, section, row) -- 初始化cell + print("Init", section, row, 10 + row * 2) + cell.title = Label(); + cell.title.backgroundColor(0xff0000) + end, + Layout = function(cell, section, row) -- cell复用时调用 + print("Layout", section, row, 10 + row * 2) +-- cell.title.frame(0, 0, s_width, 10 + row * 2) + cell.title.text(section .. '--' .. row) + end, + Callback = function(cell, section, row) -- 用户点击了section和row + Toast("Section " .. section .. ", Row " .. row .. cell.title.frame()); + end + } +end + +setmetatable(tableViewData.Cell, { __index = cellData }) +tableView = TableView(tableViewData) +tableView.miniSpacing(1) +tableView.frame(0, 0, s_width, s_height) +tableView.showScrollIndicator(false) +tableView.reload() + + + + + + diff --git a/Android/LuaViewDemo/assets/test/UI_TextField.lua b/Android/LuaViewDemo/assets/test/UI_TextField.lua new file mode 100644 index 00000000..807697f0 --- /dev/null +++ b/Android/LuaViewDemo/assets/test/UI_TextField.lua @@ -0,0 +1,36 @@ +-- Created by LuaView. +-- Copyright (c) 2017, Alibaba Group. All rights reserved. +-- +-- This source code is licensed under the MIT. +-- For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + +--工具包引入 +require "kit/lv_kit" + +local width = System.screenSize() + +local tf = TextField() +tf.hint(StyledString("测试额", {fontColor=0xff0000ff, fontSize=80, fontStyle=3, backgroundColor=0x99ff0000})) +tf.frame(0, 0, width, 100) + +tf.callback({ + BeginEditing=function() + Toast("开始编辑") + end, + + EndEditing=function() + Toast("结束编辑") + end +}) + +local btn1 = Button() +btn1.callback(function() + tf.text("点击了") +end) + + +btn1.text("点我试试") +btn1.frame(0, 100, width, 100) + + + diff --git a/Android/LuaViewDemo/assets/test/UI_View.lua b/Android/LuaViewDemo/assets/test/UI_View.lua new file mode 100644 index 00000000..a3804daa --- /dev/null +++ b/Android/LuaViewDemo/assets/test/UI_View.lua @@ -0,0 +1,74 @@ +-- Created by LuaView. +-- Copyright (c) 2017, Alibaba Group. All rights reserved. +-- +-- This source code is licensed under the MIT. +-- For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + +view = View() +view.frame(0, 10, 100, 100) +view.backgroundColor(0x11001100) +view.borderColor(0x020304) +view.borderWidth(0.3) +local x, y = view.center(); +Toast("中心点位置: " .. x .. "," .. y) + +print("background-color", view.backgroundColor(), 0x11001100) +--print("border-color", view.borderColor(), 0x020304) +--print("border-width", view.borderWidth(), 0.3) + + +view.backgroundColor(1) +--print(view.backgroundColor()) + +view.backgroundColor(0x12000001) +print(view.backgroundColor()) + +view.backgroundColor(0x000001, 0.5) +print(view.backgroundColor()) + +view.backgroundColor(0xff000001, 0.5) +print(view.backgroundColor()) + + +print(view) +view.children(function(parent) + print(parent) + local child1 = View() + child1.frame(2, 2, 90, 90) + child1.backgroundColor(0x00ff00) + print(child1) + child1.children(function(parent) + print(parent) + local child2 = View() + child2.frame(2, 2, 80, 80) + child2.backgroundColor(0xff0000) + print(child2) + child2.children(function(parent) + print(parent) + local child3 = View() + child3.frame(2, 2, 60, 60) + child3.backgroundColor(0x770000ff) + end) + end) +end) + + + +view3 = View() +view3.frame(120, 50, 100, 100) +view3.borderColor(0xff0000) +view3.borderWidth(2) + +view4 = View() +view4.backgroundColor(0x0fffff) + +view3.addView(view4) +view3.nativeView().setClipChildren(true) +view4.frame(5, -20, 90, 50) + +view3.callback(function() + print("view4.frame=", view4.frame()) + Animation().with(view4).translation(0, 40).duration(3).start() +end) + +print("end") \ No newline at end of file diff --git a/Android/LuaViewDemo/assets/test/UI_ViewEffect.lua b/Android/LuaViewDemo/assets/test/UI_ViewEffect.lua new file mode 100644 index 00000000..b584f4fd --- /dev/null +++ b/Android/LuaViewDemo/assets/test/UI_ViewEffect.lua @@ -0,0 +1,55 @@ +-- Created by LuaView. +-- Copyright (c) 2017, Alibaba Group. All rights reserved. +-- +-- This source code is licensed under the MIT. +-- For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + +view = View() +view.frame(0, 0, 100, 100) +view.backgroundColor(0xaaaaaa) +view.callback(function() + print("xxxx") +end) + +local view2 = View() +view2.frame(102, 0, 100, 100) +view2.backgroundColor(0x00ff00) + + +local image = Image() +image.frame(100, 100, 100, 100) +image.backgroundColor(0xdcdcdc) +-- 网络图有问题,属于GlideImageProvider造成的问题 + image.image("https://gju1.alicdn.com/bao/uploaded/i4/100000120700895002/TB2Qu0_fXXXXXb9XpXXXXXXXXXX_!!0-0-juitemmedia.jpg_560x560Q90.jpg") +--image.image("animate1") +image.effects(ViewEffect.CLICK, 0xff0000, 0.6) +image.callback(function() + print("yyy") +end) + + +local button = Button() +button.frame(100, 200, 100, 100) +button.text("Button") +button.backgroundColor(0xdcdcdc) +button.callback(function() + local effect = view.effects() + if(effect == ViewEffect.CLICK) then + view.effects(ViewEffect.NONE) + else + view.effects(ViewEffect.CLICK) + end + print("Change ViewEffect", view.effects()) +end) +button.effects(ViewEffect.CLICK) + + +imageView2 = Image(); +imageView2.frame( 50, 300, 300, 200); +imageView2.image("http://g.alicdn.com/ju/lua/2.0.24/doc/icon.png"); + +imageView2.effects(ViewEffect.PARALLAX, 150, 140) +imageView2.effects(ViewEffect.CLICK, 0xff0000, 0.6) +imageView2.callback(function() + print("yyy") +end) \ No newline at end of file diff --git a/Android/LuaViewDemo/assets/test/UI_WebView.lua b/Android/LuaViewDemo/assets/test/UI_WebView.lua new file mode 100644 index 00000000..9f4c6ac5 --- /dev/null +++ b/Android/LuaViewDemo/assets/test/UI_WebView.lua @@ -0,0 +1,161 @@ +-- Created by LuaView. +-- Copyright (c) 2017, Alibaba Group. All rights reserved. +-- +-- This source code is licensed under the MIT. +-- For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + + +local function createRootView(params) + local rootView = View() + rootView.frame(params.x, params.y, params.w, params.h) + return rootView +end + +local function createWebView(rootView, params) + local webview = WebView() + webview.frame(params.x, params.y, params.w, params.h) + webview.loadUrl(params.url) + webview.callback(params.callbacks) + webview.removeFromSuper() + rootView.addView(webview) + return webview +end + +local function test(rootView, params) + local button = Button() + button.frame(params.x, params.y, params.w, params.h) + button.text(params.text) + button.callback(params.callback) + button.removeFromSuper() + rootView.addView(button) +end + +local function main() + local scrW, scrH = System.screenSize() + + local rootViewParams = { + x = 0, + y = 0, + w = scrW, + h = scrH + } + local rootView = createRootView(rootViewParams) + + local webViewParams = { + x = 0, + y = 0, + w = scrW, + h = scrH - 350, + url = "http://m.taobao.com", + callbacks = { + onPageStarted = function() + print("started") + end, + onPageFinished = function() + print("finished") + end, + onReceiveError = function(errorCode, description, failedUrl) + print("error", errorCode, description, failedUrl) + end + } + } + local webview = createWebView(rootView, webViewParams) + + local backParams = { + x = 0, + y = 400, + w = 80, + h = 80, + text = "back", + callback = function() + if webview.canGoBack() then + webview.goBack() + end + end + } + test(rootView, backParams) + + local forwardParams = { + x = 100, + y = 400, + w = 80, + h = 80, + text = "forward", + callback = function() + if webview.canGoForward() then + webview.goForward() + end + end + } + test(rootView, forwardParams) + + local reloadParams = { + x = 200, + y = 400, + w = 80, + h = 80, + text = "reload", + callback = function() + webview.reload() + end + } + test(rootView, reloadParams) + + local stopLoadingParams = { + x = 300, + y = 400, + w = 80, + h = 80, + text = "stopLoading", + callback = function() + webview.stopLoading() + end + } + test(rootView, stopLoadingParams) + + local getUrlParams = { + x = 0, + y = 500, + w = 80, + h = 80, + text = "getUrl", + callback = function() + Alert(webview.url()) + end + } + test(rootView, getUrlParams) + + local getTitleParams = { + x = 100, + y = 500, + w = 80, + h = 80, + text = "getTitle", + callback = function() + Alert(webview.title()) + end + } + test(rootView, getTitleParams) + + local canPullParams = { + x = 200, + y = 500, + w = 80, + h = 80, + text = "canPull", + callback = function() + if webview.pullRefreshEnable() == true then + webview.pullRefreshEnable(false) + else + webview.pullRefreshEnable(true) + end + end + } + test(rootView, canPullParams) +end + +main() + + + + diff --git a/Android/LuaViewDemo/assets/test/UI_Window.lua b/Android/LuaViewDemo/assets/test/UI_Window.lua new file mode 100644 index 00000000..32c4f9b7 --- /dev/null +++ b/Android/LuaViewDemo/assets/test/UI_Window.lua @@ -0,0 +1,59 @@ +-- Created by LuaView. +-- Copyright (c) 2017, Alibaba Group. All rights reserved. +-- +-- This source code is licensed under the MIT. +-- For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + +scrW, scrH = System.screenSize() +error = Button() +error.text("xxxx") +error.frame(0, 0, scrW, scrH - 50); +error.backgroundColor(0xffff00) +error.callback(function() + hideError(); +end); + +function showError() + window.addView(error); +end + +function hideError() + error.removeFromSuper(); +end + +hideError(); +showError(); + + + +window.callback({ + onShow = function() + print("onShow") + end, + onHide = function() + print("onHide") + end, + onBack = function() + print("onBack") + + + Toast("onBack") + return true + end, + onWifiConnected = function() + print("onWifiConnected") + print(System.network()) + end, + onMobileConnected = function() + print("onMobileConnected") + print(System.network()) + end, + onConnectionClosed = function() + print("onConnectionClosed") + print(System.network()) + end, + onLayout = function() + print("onLayout") + end +}) + diff --git a/Android/LuaViewDemo/assets/test/bundle/lv_kit.lua b/Android/LuaViewDemo/assets/test/bundle/lv_kit.lua new file mode 100644 index 00000000..93f274c7 --- /dev/null +++ b/Android/LuaViewDemo/assets/test/bundle/lv_kit.lua @@ -0,0 +1,85 @@ +-- Created by LuaView. +-- Copyright (c) 2017, Alibaba Group. All rights reserved. +-- +-- This source code is licensed under the MIT. +-- For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + +-- LuaView 相关的kit +-- Created by IntelliJ IDEA. +-- User: song +-- Date: 15/9/8 +-- Time: 上午10:33 +-- + + +--1. Lua Table View by Elertan +function printTable(t, exclusions) + if (type(t) == "table") then + local nests = 0 + if not exclusions then exclusions = {} end + local recurse = function(t, recurse, exclusions) + indent = function() + local dent = "" + for i = 1, nests do + dent = dent .. " " + end + return dent + end + local excluded = function(key) + for k, v in pairs(exclusions) do + if v == key then + return true + end + end + return false + end + local isFirst = true + for k, v in pairs(t) do + local dent = indent() + if isFirst then + print(dent .. "|") + isFirst = false + end + dent = indent() + if type(v) == "table" and not excluded(k) then + print(dent .. "|- " .. tostring(k) .. ": " .. type(v)) + nests = nests + 1 + recurse(v, recurse, exclusions) + elseif excluded(k) then + print(dent .. "|- " .. tostring(k) .. ": " .. type(v)) + elseif type(v) == "userdata" or type(v) == "function" then + print(dent .. "|- " .. tostring(k) .. ": " .. type(v)) + elseif type(v) == "string" then + print(dent .. "|- " .. tostring(k) .. ": " .. "\"" .. tostring(v) .. "\"") + else + print(dent .. "|- " .. tostring(k) .. ": " .. tostring(v)) + end + end + nests = nests - 1 + end + + nests = 0 + + if t then + print("### START TABLE ###") + for k, v in pairs(t) do + if type(v) == "table" then + print("|- " .. k .. ": " .. type(v)) + nests = nests + 1 + recurse(v, recurse, exclusions) + elseif type(v) == "userdata" or type(v) == "function" then + print("|- " .. tostring(k) .. ": " .. type(v)) + elseif type(v) == "string" then + print("|- " .. tostring(k) .. ": " .. "\"" .. tostring(v) .. "\"") + else + print("|- " .. tostring(k) .. ": " .. tostring(v)) + end + end + print("### END TABLE ###") + else + print("NIL TABLE") + end + else + print(t) + end +end diff --git a/Android/LuaViewDemo/assets/test/bundle/main.lua b/Android/LuaViewDemo/assets/test/bundle/main.lua new file mode 100644 index 00000000..c0b5a931 --- /dev/null +++ b/Android/LuaViewDemo/assets/test/bundle/main.lua @@ -0,0 +1,153 @@ +-- Created by LuaView. +-- Copyright (c) 2017, Alibaba Group. All rights reserved. +-- +-- This source code is licensed under the MIT. +-- For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + +--工具包引入 +require "lv_kit" + +w, h = System.screenSize() + +cellHeight = 100 +imageUrl1 = "http://gju2.alicdn.com/bao/uploaded/i1/10000073270926575/TB2fpg0cXXXXXb6XpXXXXXXXXXX_!!0-0-juitemmedia.jpg" +imageUrl2 = "http://img4.duitang.com/uploads/item/201306/25/20130625045508_sairr.thumb.600_0.jpeg" + + +local vp = PagerView({ + PageCount = 4, + Pages = { + Title = function(pos) + return "Title" + end, + Init = function(page, pos) + local tableView = RefreshCollectionView { + Section = { + SectionCount = 2, + RowCount = function(section) + if(section == 1) then + return 1 + else + return 10 + end + end + }, + Cell = { + Id = function(section, row) + if(pos % 2 == 0) then + if (section == 1) then + return "HScroll" + else + return "ImageAndImage" + end + else + if (section == 1) then + return "Pager" + else + return "ImageAndImage" + end + end + end, + HScroll = { + Size = function(section, row) + return w, 100 + end, + Init = function(cell, section, row) + local scrollView = HScrollView() + for i = 0, 10, 1 do + local btn = Label() + btn.text("BTN" .. i) + btn.frame(i * 80, 0, 79, 100) + btn.backgroundColor(0xff00ff00) + btn.callback(function() + Toast(btn.text()) + end) + scrollView.addView(btn) + end + scrollView.size(w, 100) + scrollView.backgroundColor(0xffcccccc) + cell.container= scrollView + end, + Layout = function(cell, section, row) + end + }, + Pager = { + Size = function(section, row) + return w, 100 + end, + Init = function(cell, section, row) + local vp = PagerView({ + PageCount = 10, + Pages = { + Title = function(pos) + return "Title" + end, + Init = function(page, pos) + page.icon = Button() + end, + Layout = function(page, pos) + page.icon.text("测试按钮"..pos) + page.icon.frame(0, 0, w, 100) + page.icon.callback(function() + Toast(page.icon.text()) + end) + end + } + }) + + vp.backgroundColor(0xaaaa0000) + vp.frame(0, 0, w, 100) + + cell.container = vp + end, + Layout = function(cell, section, row) + end + }, + ImageAndImage = { + Size = function(section, row) + return cellHeight + end, + Init = function(cell, section, row) + cell.icon = Image() + cell.icon2 = Image() + end, + Layout = function(cell, section, row) + local cellWdith, cellHeight = cell.window.size() + cell.icon.frame(0, 0, cellHeight, cellHeight) + cell.icon.image(imageUrl1, function() + print("imageLoaded-ImageAndImage-1", section, row) + end) + cell.icon.callback(function() + print("cell_icon1") + end) + + + cell.icon2.frame(cellHeight + 10, 0, cellHeight, cellHeight) + cell.icon2.image(imageUrl1, function() + print("imageLoaded-ImageAndImage-2", section, row) + end) + cell.icon2.callback(function() + print("cell_icon2") + end) + end + } + } + } + tableView.frame(0, 0, w, h - 64) + + page.view = tableView + + end, + Layout = function(page, pos) + end + } +}) + +vp.backgroundColor(0xaaaa0000) +vp.frame(0, 0, w, h) + + + + + + diff --git a/Android/LuaViewDemo/assets/test/fonts/iconfont.ttf b/Android/LuaViewDemo/assets/test/fonts/iconfont.ttf new file mode 100644 index 00000000..014f80db Binary files /dev/null and b/Android/LuaViewDemo/assets/test/fonts/iconfont.ttf differ diff --git a/Android/LuaViewDemo/assets/test/kit/lv_kit.lua b/Android/LuaViewDemo/assets/test/kit/lv_kit.lua new file mode 100644 index 00000000..93f274c7 --- /dev/null +++ b/Android/LuaViewDemo/assets/test/kit/lv_kit.lua @@ -0,0 +1,85 @@ +-- Created by LuaView. +-- Copyright (c) 2017, Alibaba Group. All rights reserved. +-- +-- This source code is licensed under the MIT. +-- For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + +-- LuaView 相关的kit +-- Created by IntelliJ IDEA. +-- User: song +-- Date: 15/9/8 +-- Time: 上午10:33 +-- + + +--1. Lua Table View by Elertan +function printTable(t, exclusions) + if (type(t) == "table") then + local nests = 0 + if not exclusions then exclusions = {} end + local recurse = function(t, recurse, exclusions) + indent = function() + local dent = "" + for i = 1, nests do + dent = dent .. " " + end + return dent + end + local excluded = function(key) + for k, v in pairs(exclusions) do + if v == key then + return true + end + end + return false + end + local isFirst = true + for k, v in pairs(t) do + local dent = indent() + if isFirst then + print(dent .. "|") + isFirst = false + end + dent = indent() + if type(v) == "table" and not excluded(k) then + print(dent .. "|- " .. tostring(k) .. ": " .. type(v)) + nests = nests + 1 + recurse(v, recurse, exclusions) + elseif excluded(k) then + print(dent .. "|- " .. tostring(k) .. ": " .. type(v)) + elseif type(v) == "userdata" or type(v) == "function" then + print(dent .. "|- " .. tostring(k) .. ": " .. type(v)) + elseif type(v) == "string" then + print(dent .. "|- " .. tostring(k) .. ": " .. "\"" .. tostring(v) .. "\"") + else + print(dent .. "|- " .. tostring(k) .. ": " .. tostring(v)) + end + end + nests = nests - 1 + end + + nests = 0 + + if t then + print("### START TABLE ###") + for k, v in pairs(t) do + if type(v) == "table" then + print("|- " .. k .. ": " .. type(v)) + nests = nests + 1 + recurse(v, recurse, exclusions) + elseif type(v) == "userdata" or type(v) == "function" then + print("|- " .. tostring(k) .. ": " .. type(v)) + elseif type(v) == "string" then + print("|- " .. tostring(k) .. ": " .. "\"" .. tostring(v) .. "\"") + else + print("|- " .. tostring(k) .. ": " .. tostring(v)) + end + end + print("### END TABLE ###") + else + print("NIL TABLE") + end + else + print(t) + end +end diff --git a/Android/LuaViewDemo/assets/test/lvp/UI_Window.luap b/Android/LuaViewDemo/assets/test/lvp/UI_Window.luap new file mode 100644 index 00000000..760a7ce1 Binary files /dev/null and b/Android/LuaViewDemo/assets/test/lvp/UI_Window.luap differ diff --git a/Android/LuaViewDemo/assets/test/music/test.mp3 b/Android/LuaViewDemo/assets/test/music/test.mp3 new file mode 100644 index 00000000..6ce1f6ee Binary files /dev/null and b/Android/LuaViewDemo/assets/test/music/test.mp3 differ diff --git a/Android/LuaViewDemo/assets/test/test.lua b/Android/LuaViewDemo/assets/test/test.lua new file mode 100644 index 00000000..0bd0b4ea --- /dev/null +++ b/Android/LuaViewDemo/assets/test/test.lua @@ -0,0 +1,51 @@ +-- Created by LuaView. +-- Copyright (c) 2017, Alibaba Group. All rights reserved. +-- +-- This source code is licensed under the MIT. +-- For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + +require "" +str = {"中","华","人","民","共","和","国","万","岁"} + + +txt = Label() +txt.frame(0, 0, 200, 300) +txt.backgroundColor(0xdcdcdc) + +index = 1 + +t = "" + +timer = Timer() +timer.callback(function() +-- t = t .. string:char(str, index) + + print(string:char(str, index)) +-- txt.text(string:char(str, 1, index)) +-- index = index + SubStringGetByteCount(str, index) + +-- t = t .. str[index] + txt.text(t) + index = index + 1 + +end) + +--返回当前字符实际占用的字符数 +function SubStringGetByteCount(str, index) + local curByte = string:byte(str, index) + local byteCount = 1; + if curByte == nil then + byteCount = 0 + elseif curByte > 0 and curByte <= 127 then + byteCount = 1 + elseif curByte>=192 and curByte<223 then + byteCount = 2 + elseif curByte>=224 and curByte<239 then + byteCount = 3 + elseif curByte>=240 and curByte<=247 then + byteCount = 4 + end + return byteCount; +end + +timer.start(0.5, true) \ No newline at end of file diff --git a/Android/LuaViewDemo/build.gradle b/Android/LuaViewDemo/build.gradle new file mode 100644 index 00000000..2e484d02 --- /dev/null +++ b/Android/LuaViewDemo/build.gradle @@ -0,0 +1,73 @@ +//运行配置 +apply plugin: 'android' + +description = """LuaView-Android-Demo: 用lua写Android、iOS""" + +repositories { + mavenLocal() + mavenCentral() + jcenter() +} + +configurations { + providedCompile +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) + + //LuaViewSDK + compile project(':LuaViewSDK') + + //glide for imageview + compile 'com.github.bumptech.glide:glide:3.7.0' +} + +/* + 定义android插件 +*/ +android { + compileSdkVersion 23 + buildToolsVersion '25.0.0' + sourceSets { + main { + jniLibs.srcDirs = ['libs'] + manifest.srcFile 'AndroidManifest.xml' + java.srcDirs = ['src'] + resources.srcDirs = ['src'] + aidl.srcDirs = ['src'] + renderscript.srcDirs = ['src'] + res.srcDirs = ['res'] + assets.srcDirs = ['assets'] + } + + // Move the tests to tests/java, tests/res, etc... + instrumentTest.setRoot('tests') + + // Move the build types to build-types/ + // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ... + // This moves them out of them default location under src//... which would + // conflict with src/ being used by the main source set. + // Adding new build types or product flavors should be accompanied + // by a similar customization. + debug.setRoot('build-types/debug') + release.setRoot('build-types/release') + } + packagingOptions { + exclude 'META-INF/LICENSE.txt' + exclude 'META-INF/NOTICE.txt' + } + + buildTypes{ + debug{ + proguardFile("proguard.cfg") + } + } + lintOptions { + checkReleaseBuilds false + // Or, if you prefer, you can continue to check for errors in release builds, + // but continue the build even when errors are found: + abortOnError false + } +} + diff --git a/Android/LuaViewDemo/proguard-rules.pro b/Android/LuaViewDemo/proguard-rules.pro new file mode 100644 index 00000000..8b3bf7ef --- /dev/null +++ b/Android/LuaViewDemo/proguard-rules.pro @@ -0,0 +1,17 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in /Users/song/AndroidSDK/sdk/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/Android/LuaViewDemo/proguard.cfg b/Android/LuaViewDemo/proguard.cfg new file mode 100644 index 00000000..4fd55b83 --- /dev/null +++ b/Android/LuaViewDemo/proguard.cfg @@ -0,0 +1,6 @@ +# proguard for Glide +-keep public class * implements com.bumptech.glide.module.GlideModule +-keep public enum com.bumptech.glide.load.resource.bitmap.ImageHeaderParser$** { + **[] $VALUES; + public *; +} diff --git a/Android/LuaViewDemo/res/drawable-hdpi/ic_launcher.png b/Android/LuaViewDemo/res/drawable-hdpi/ic_launcher.png new file mode 100644 index 00000000..288b6655 Binary files /dev/null and b/Android/LuaViewDemo/res/drawable-hdpi/ic_launcher.png differ diff --git a/Android/LuaViewDemo/res/drawable-mdpi/ic_launcher.png b/Android/LuaViewDemo/res/drawable-mdpi/ic_launcher.png new file mode 100644 index 00000000..6ae570b4 Binary files /dev/null and b/Android/LuaViewDemo/res/drawable-mdpi/ic_launcher.png differ diff --git a/Android/LuaViewDemo/res/drawable-xhdpi/ic_launcher.png b/Android/LuaViewDemo/res/drawable-xhdpi/ic_launcher.png new file mode 100644 index 00000000..d4fb7cd9 Binary files /dev/null and b/Android/LuaViewDemo/res/drawable-xhdpi/ic_launcher.png differ diff --git a/Android/LuaViewDemo/res/drawable-xxhdpi/ic_launcher.png b/Android/LuaViewDemo/res/drawable-xxhdpi/ic_launcher.png new file mode 100644 index 00000000..85a60815 Binary files /dev/null and b/Android/LuaViewDemo/res/drawable-xxhdpi/ic_launcher.png differ diff --git a/Android/LuaViewDemo/res/drawable/animate1.jpeg b/Android/LuaViewDemo/res/drawable/animate1.jpeg new file mode 100644 index 00000000..62ee8183 Binary files /dev/null and b/Android/LuaViewDemo/res/drawable/animate1.jpeg differ diff --git a/Android/LuaViewDemo/res/drawable/animate2.jpeg b/Android/LuaViewDemo/res/drawable/animate2.jpeg new file mode 100644 index 00000000..4a2cf581 Binary files /dev/null and b/Android/LuaViewDemo/res/drawable/animate2.jpeg differ diff --git a/Android/LuaViewDemo/res/layout/activity_main.xml b/Android/LuaViewDemo/res/layout/activity_main.xml new file mode 100644 index 00000000..47bc8969 --- /dev/null +++ b/Android/LuaViewDemo/res/layout/activity_main.xml @@ -0,0 +1,13 @@ + + + + + diff --git a/Android/LuaViewDemo/res/layout/activity_main2.xml b/Android/LuaViewDemo/res/layout/activity_main2.xml new file mode 100644 index 00000000..28d40a55 --- /dev/null +++ b/Android/LuaViewDemo/res/layout/activity_main2.xml @@ -0,0 +1,30 @@ + + + + + + + + + diff --git a/Android/LuaViewDemo/res/layout/demo_ac_fragment_container.xml b/Android/LuaViewDemo/res/layout/demo_ac_fragment_container.xml new file mode 100644 index 00000000..0bbf4ce8 --- /dev/null +++ b/Android/LuaViewDemo/res/layout/demo_ac_fragment_container.xml @@ -0,0 +1,7 @@ + + + diff --git a/Android/LuaViewDemo/res/values-w820dp/dimens.xml b/Android/LuaViewDemo/res/values-w820dp/dimens.xml new file mode 100644 index 00000000..63fc8164 --- /dev/null +++ b/Android/LuaViewDemo/res/values-w820dp/dimens.xml @@ -0,0 +1,6 @@ + + + 64dp + diff --git a/Android/LuaViewDemo/res/values/dimens.xml b/Android/LuaViewDemo/res/values/dimens.xml new file mode 100644 index 00000000..47c82246 --- /dev/null +++ b/Android/LuaViewDemo/res/values/dimens.xml @@ -0,0 +1,5 @@ + + + 16dp + 16dp + diff --git a/Android/LuaViewDemo/res/values/strings.xml b/Android/LuaViewDemo/res/values/strings.xml new file mode 100644 index 00000000..e6998682 --- /dev/null +++ b/Android/LuaViewDemo/res/values/strings.xml @@ -0,0 +1,7 @@ + + + + LuaView + LuaView SDK Demo + + diff --git a/Android/LuaViewDemo/res/values/styles.xml b/Android/LuaViewDemo/res/values/styles.xml new file mode 100644 index 00000000..0309de5a --- /dev/null +++ b/Android/LuaViewDemo/res/values/styles.xml @@ -0,0 +1,20 @@ + + + + + + + + + diff --git a/Android/LuaViewDemo/src/com/taobao/luaview/demo/activity/Demo2Activity.java b/Android/LuaViewDemo/src/com/taobao/luaview/demo/activity/Demo2Activity.java new file mode 100644 index 00000000..48ddcec9 --- /dev/null +++ b/Android/LuaViewDemo/src/com/taobao/luaview/demo/activity/Demo2Activity.java @@ -0,0 +1,80 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.demo.activity; + +import android.app.Activity; +import android.graphics.Color; +import android.os.Bundle; +import android.view.View; +import android.view.ViewGroup; +import android.widget.RelativeLayout; + +import com.taobao.android.luaview.demo.R; + +public class Demo2Activity extends Activity { + + private ViewGroup mContainer = null; + private View child = null; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + test0(); + +// test(); + } + + private void test0() { + setContentView(R.layout.activity_main2); + + mContainer = (ViewGroup) this.findViewById(R.id.container); + child = this.findViewById(R.id.child); + + child.setOnClickListener(new View.OnClickListener(){ + + @Override + public void onClick(View v) { + child.animate().translationY(-200).setDuration(2000).start(); + } + }); + } + + private void test() { + mContainer = new RelativeLayout(this); + + mContainer.setBackgroundColor(Color.RED); + mContainer.setAlpha(0.5f); + + child = new RelativeLayout(this); + + child.setBackgroundColor(Color.BLUE); + child.setAlpha(0.5f); + + + mContainer.addView(child, new ViewGroup.MarginLayoutParams(300, 300)); + + ((ViewGroup.MarginLayoutParams)child.getLayoutParams()).leftMargin = 0; + ((ViewGroup.MarginLayoutParams)child.getLayoutParams()).topMargin = 200; + + + child.setOnClickListener(new View.OnClickListener() { + + @Override + public void onClick(View v) { + child.animate().translationY(-200).setDuration(2000).start(); + } + }); + + setContentView(mContainer, new ViewGroup.MarginLayoutParams(300, 300)); + + ((ViewGroup.MarginLayoutParams)mContainer.getLayoutParams()).leftMargin = 200; + ((ViewGroup.MarginLayoutParams)mContainer.getLayoutParams()).topMargin = 200; + } +} diff --git a/Android/LuaViewDemo/src/com/taobao/luaview/demo/activity/DemoActivity.java b/Android/LuaViewDemo/src/com/taobao/luaview/demo/activity/DemoActivity.java new file mode 100644 index 00000000..d2401831 --- /dev/null +++ b/Android/LuaViewDemo/src/com/taobao/luaview/demo/activity/DemoActivity.java @@ -0,0 +1,90 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.demo.activity; + +import android.app.ListActivity; +import android.content.Intent; +import android.os.Bundle; +import android.view.View; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; + +import com.taobao.luaview.global.Constants; +import com.taobao.luaview.global.LuaViewConfig; +import com.taobao.luaview.scriptbundle.LuaScriptManager; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +public class DemoActivity extends ListActivity { + //测试标准语法 + public static boolean useStandardSyntax = true; + + //非标准语法代码路径 + private static final String FOLDER_NAME = "test"; + + //标准语法代码路径 + private static final String FOLDER_STANDARD_NAME = "test-standard"; + + private String getFolderName() { + return (useStandardSyntax ? FOLDER_STANDARD_NAME : FOLDER_NAME); + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + initContent(); + initLuaView(); + } + + private void initContent() { + final ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_expandable_list_item_1, getContentData()); + + getListView().setAdapter(adapter); + getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + final String fileName = adapter.getItem(position - getListView().getHeaderViewsCount()); + final Intent intent = new Intent(DemoActivity.this, DemoLuaViewActivity.class); + intent.putExtra(Constants.PARAM_URI, getFolderName() + "/" + fileName); + startActivity(intent); + } + }); + } + + private List getContentData() { + String[] array = null; + List result = new ArrayList(); + try { + array = getResources().getAssets().list(getFolderName()); + + if (array != null) { + for (String name : array) { + if (LuaScriptManager.isLuaScript(name)) { + result.add(name); + } + } + } + } catch (IOException e) { + e.printStackTrace(); + } + return result; + } + + /** + * 初始化LuaView + */ + private void initLuaView() { + LuaViewConfig.init(this);//初始化,只需要调用一次 + LuaViewConfig.setDebug(true);//设置是否debug,默认release模式下不会开启 + LuaViewConfig.setOpenDebugger(false);//是否开启调试器,默认模拟器环境会开启,真机不会开启。TODO Android 真机调试 + LuaViewConfig.setAutoSetupClickEffects(true);//是否自动设置点击效果(如果有点击事件会自动设置) + } +} diff --git a/Android/LuaViewDemo/src/com/taobao/luaview/demo/activity/DemoLuaViewActivity.java b/Android/LuaViewDemo/src/com/taobao/luaview/demo/activity/DemoLuaViewActivity.java new file mode 100644 index 00000000..73d60788 --- /dev/null +++ b/Android/LuaViewDemo/src/com/taobao/luaview/demo/activity/DemoLuaViewActivity.java @@ -0,0 +1,177 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.demo.activity; + +import android.app.Activity; +import android.os.Bundle; + +import com.taobao.luaview.demo.provider.GlideImageProvider; +import com.taobao.luaview.demo.ui.CustomError; +import com.taobao.luaview.demo.ui.CustomLoading; +import com.taobao.luaview.global.Constants; +import com.taobao.luaview.global.LuaScriptLoader; +import com.taobao.luaview.global.LuaView; +import com.taobao.luaview.scriptbundle.ScriptBundle; +import com.taobao.luaview.util.AssetUtil; +import com.taobao.luaview.util.JsonUtil; +import com.taobao.luaview.util.LogUtil; +import com.taobao.luaview.view.LVLoadingDialog; + +import org.luaj.vm2.LuaValue; + +/** + * 通过LuaView、注入bridge对象,实现Lua-Java通信 + * + * @author song + * @date 15/11/11 + * 主要功能描述 + * 修改描述 + * 下午4:50 song XXX + */ +public class DemoLuaViewActivity extends Activity { + private LuaView mLuaView; + private LVLoadingDialog mDialog; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + initActionBar(); + showLoading(); + createLuaViewAsync(); + } + + private void initActionBar() { + getActionBar().setDisplayShowHomeEnabled(false); + getActionBar().setDisplayHomeAsUpEnabled(true); + } + + private void showLoading() { + mDialog = new LVLoadingDialog(this); + mDialog.show(); + } + + private void hideLoading() { + if (mDialog != null) { + mDialog.cancel(); + } + } + + /** + * 异步创建LuaView(推荐方式) + */ + private void createLuaViewAsync() { + LuaView.createAsync(this, new LuaView.CreatedCallback() { + @Override + public void onCreated(LuaView luaView) { + hideLoading(); + mLuaView = luaView; + if (mLuaView != null) { + extendsLuaView(mLuaView); + loadScript(mLuaView); + setContentView(mLuaView); + } + } + }); + } + + /** + * 同步创建LuaView + */ + private void createLuaView(){ + mLuaView = LuaView.create(this); + extendsLuaView(mLuaView); + loadScript(mLuaView); + setContentView(mLuaView); + hideLoading(); + } + + + /** + * 扩展LuaView + * 注册Panel(如果已经有UI组件,需要在Lua使用) + * 注册Bridge(有部分API或功能,需要在Lua使用) + */ + private void extendsLuaView(final LuaView luaView) { + luaView.registerImageProvider(GlideImageProvider.class); + luaView.registerPanel(CustomError.class); + luaView.registerPanel(CustomLoading.class); + luaView.register("bridge", new LuaViewBridge(this)); + luaView.setUseStandardSyntax(DemoActivity.useStandardSyntax);//是否使用标准语法 + } + + /** + * 加载数据 + */ + public void loadScript(final LuaView luaView) { + luaView.load(getLuaUri(), new LuaScriptLoader.ScriptExecuteCallback() { + @Override + public boolean onScriptPrepared(ScriptBundle bundle) { + return false; + } + + @Override + public boolean onScriptCompiled(LuaValue value, LuaValue context, LuaValue view) { + return false; + } + + @Override + public void onScriptExecuted(String uri, boolean executedSuccess) { + //测试调用 lua function + LogUtil.d("call-lua-function return:", luaView.callLuaFunction("global_fun_test1", 1, "a", 0.1)); + LogUtil.d("call-lua-function return:", JsonUtil.toString(luaView.callLuaFunction("global_fun_test2", 2, "b", 0.2))); + LogUtil.d("call-window-function return:", luaView.callWindowFunction("window_fun1", 3, "c", 0.3)); + LogUtil.d("call-window-function return:", luaView.callWindowFunction("window_fun2", 4, "d", 0.4)); + } + }); + } + + /** + * load bytecode directly + * + * @param luaView + */ + public void loadBytecodeScript(final LuaView luaView) { + luaView.loadPrototype(AssetUtil.open(this, "test/lvp/UI_Window.luap"), "UI_window", new LuaScriptLoader.ScriptExecuteCallback() { + @Override + public boolean onScriptPrepared(ScriptBundle bundle) { + return false; + } + + @Override + public boolean onScriptCompiled(LuaValue value, LuaValue context, LuaValue view) { + return false; + } + + @Override + public void onScriptExecuted(String uri, boolean executedSuccess) { + } + }); + } + + /** + * 获取文件名称 + * + * @return + */ + private String getLuaUri() { + if (getIntent() != null && getIntent().hasExtra(Constants.PARAM_URI)) { + return getIntent().getStringExtra(Constants.PARAM_URI); + } + return null; + } + + @Override + protected void onDestroy() { + LogUtil.d("LuaView-onDestroy"); + super.onDestroy(); + if (mLuaView != null) { + mLuaView.onDestroy(); + } + } +} diff --git a/Android/LuaViewDemo/src/com/taobao/luaview/demo/activity/LuaViewBridge.java b/Android/LuaViewDemo/src/com/taobao/luaview/demo/activity/LuaViewBridge.java new file mode 100644 index 00000000..de30a498 --- /dev/null +++ b/Android/LuaViewDemo/src/com/taobao/luaview/demo/activity/LuaViewBridge.java @@ -0,0 +1,100 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.demo.activity; + +import android.app.Activity; +import android.content.Intent; +import android.net.Uri; + +import com.taobao.luaview.util.LogUtil; + +import org.luaj.vm2.LuaTable; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * LuaView & Native 接口 + * + * @author song + * @date 15/12/30 + * 主要功能描述 + * 修改描述 + * 下午2:31 song XXX + */ +public class LuaViewBridge { + private Activity mActivity; + + public LuaViewBridge(Activity activity) { + this.mActivity = activity; + } + + public void openPage(String pageUri){ + Intent intent = new Intent(); + intent.setData(Uri.parse(pageUri)); + mActivity.startActivity(intent); + } + + public boolean isLogin(){ + return true; + } + + public Map testMap() { + Map map = new HashMap(); + map.put("key1", "map1"); + map.put("key2", "map2"); + map.put("key3", "map3"); + return map; + } + + public List testList() { + return Arrays.asList(new String[]{"list1", "list2", "list3"}); + } + + public String testString() { + return "string"; + } + + public int testInt() { + return 0; + } + + public Integer testInt2() { + return 1; + } + + public long testLong() { + return 0L; + } + + public Long testLong2() { + return 0L; + } + + public double testDouble() { + return 0.0; + } + + public Double testDouble2() { + return 0.0; + } + + public boolean testBoolean() { + return true; + } + + public Boolean testBoolean2() { + return false; + } + + public void testParams(LuaTable value){ + } +} diff --git a/Android/LuaViewDemo/src/com/taobao/luaview/demo/fragment/DemoLuaViewFragment.java b/Android/LuaViewDemo/src/com/taobao/luaview/demo/fragment/DemoLuaViewFragment.java new file mode 100644 index 00000000..855c47d0 --- /dev/null +++ b/Android/LuaViewDemo/src/com/taobao/luaview/demo/fragment/DemoLuaViewFragment.java @@ -0,0 +1,49 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.demo.fragment; + +import android.os.Bundle; + +import com.taobao.luaview.demo.activity.LuaViewBridge; +import com.taobao.luaview.demo.ui.CustomError; +import com.taobao.luaview.demo.ui.CustomLoading; +import com.taobao.luaview.fragment.LuaViewFragment; +import com.taobao.luaview.global.LuaView; + +/** + * @author song + * @date 15/11/11 + */ +public class DemoLuaViewFragment extends LuaViewFragment { + + /** + * create a new lua view fragment + * + * @param bundle + * @return + */ + public static DemoLuaViewFragment newInstance(Bundle bundle) { + DemoLuaViewFragment fragment = new DemoLuaViewFragment(); + fragment.setArguments(bundle); + return fragment; + } + + @Override + public void registerNameBeforeLoad(LuaView luaView) { + super.registerNameBeforeLoad(luaView); + luaView.registerPanel(CustomError.class); + luaView.registerPanel(CustomLoading.class); + luaView.register("viewController", new LuaViewBridge(getActivity())); + } + + @Override + public void load(final LuaView luaView) { + luaView.load("testButton"); + } +} diff --git a/Android/LuaViewDemo/src/com/taobao/luaview/demo/provider/GlideConfiguration.java b/Android/LuaViewDemo/src/com/taobao/luaview/demo/provider/GlideConfiguration.java new file mode 100644 index 00000000..32f2c8c2 --- /dev/null +++ b/Android/LuaViewDemo/src/com/taobao/luaview/demo/provider/GlideConfiguration.java @@ -0,0 +1,34 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.demo.provider; + +import android.content.Context; + +import com.bumptech.glide.Glide; +import com.bumptech.glide.GlideBuilder; +import com.bumptech.glide.load.DecodeFormat; +import com.bumptech.glide.module.GlideModule; + +/** + * configuration for glide + * @author song + */ +public class GlideConfiguration implements GlideModule { + + @Override + public void applyOptions(Context context, GlideBuilder builder) { + // Apply options to the builder here. + builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888); + } + + @Override + public void registerComponents(Context context, Glide glide) { + // register ModelLoaders here. + } +} \ No newline at end of file diff --git a/Android/LuaViewDemo/src/com/taobao/luaview/demo/provider/GlideImageProvider.java b/Android/LuaViewDemo/src/com/taobao/luaview/demo/provider/GlideImageProvider.java new file mode 100644 index 00000000..050f2ca5 --- /dev/null +++ b/Android/LuaViewDemo/src/com/taobao/luaview/demo/provider/GlideImageProvider.java @@ -0,0 +1,123 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.demo.provider; + +import android.app.Activity; +import android.content.Context; +import android.graphics.drawable.BitmapDrawable; +import android.graphics.drawable.Drawable; +import android.os.Build; +import android.view.ViewGroup; +import android.widget.ImageView; + +import com.bumptech.glide.Glide; +import com.bumptech.glide.load.resource.bitmap.GlideBitmapDrawable; +import com.bumptech.glide.load.resource.drawable.GlideDrawable; +import com.bumptech.glide.request.RequestListener; +import com.bumptech.glide.request.target.Target; +import com.taobao.luaview.provider.ImageProvider; +import com.taobao.luaview.view.imageview.BaseImageView; +import com.taobao.luaview.view.imageview.DrawableLoadCallback; + +import java.lang.ref.WeakReference; + +/** + * XXX + * + * @author song + * @date 16/4/11 + * 主要功能描述 + * 修改描述 + * 下午5:42 song XXX + */ +public class GlideImageProvider implements ImageProvider { + + @Override + public void pauseRequests(final ViewGroup view, Context context) { + Glide.with(context).pauseRequests(); + } + + @Override + public void resumeRequests(final ViewGroup view, Context context) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { + if (context instanceof Activity && (((Activity) context).isFinishing() || ((Activity) context).isDestroyed())) { + return; + } + } else { + if (context instanceof Activity && (((Activity) context).isFinishing())) { + return; + } + } + if (Glide.with(context).isPaused()) { + Glide.with(context).resumeRequests(); + } + } + + /** + * load url + * + * @param referImageView + * @param url + * @param callback + */ + public void load(final Context context, final WeakReference referImageView, final String url, final WeakReference callback) { + if (referImageView != null) { + ImageView imageView = referImageView.get(); + if (imageView != null) { + if (callback != null) { + Glide.with(context).load(url).listener(new RequestListener() { + @Override + public boolean onException(Exception e, String model, Target target, boolean isFirstResource) { + if (callback != null && callback.get() != null) { + callback.get().onLoadResult(null); + } + return false; + } + + @Override + public boolean onResourceReady(GlideDrawable resource, String model, Target target, boolean isFromMemoryCache, boolean isFirstResource) { + if (callback != null && callback.get() != null) { + callback.get().onLoadResult(resource.getCurrent()); + } + return false; + } + }).into(imageView); + } else { + Glide.with(context).load(url).into(imageView); + } + } + } + } + + @Override + public void preload(final Context context, String url, final DrawableLoadCallback callback) { + if (callback != null) { + Glide.with(context).load(url).listener(new RequestListener() { + @Override + public boolean onException(Exception e, String model, Target target, boolean isFirstResource) { + if (callback != null) { + callback.onLoadResult(null); + } + return false; + } + + @Override + public boolean onResourceReady(GlideDrawable resource, String model, Target target, boolean isFromMemoryCache, boolean isFirstResource) { + if (callback != null) { + Drawable r = resource instanceof GlideBitmapDrawable ? new BitmapDrawable(context.getResources(), ((GlideBitmapDrawable) resource).getBitmap()) : resource; + callback.onLoadResult(r); + } + return false; + } + }).preload(); + } else { + Glide.with(context).load(url).preload(); + } + } +} diff --git a/Android/LuaViewDemo/src/com/taobao/luaview/demo/ui/CustomError.java b/Android/LuaViewDemo/src/com/taobao/luaview/demo/ui/CustomError.java new file mode 100644 index 00000000..f79d15a9 --- /dev/null +++ b/Android/LuaViewDemo/src/com/taobao/luaview/demo/ui/CustomError.java @@ -0,0 +1,51 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.demo.ui; + +import android.view.View; +import android.widget.Button; +import android.widget.RelativeLayout; + +import com.taobao.luaview.util.LuaViewUtil; +import com.taobao.luaview.view.LVCustomPanel; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaTable; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; + +/** + * @author song + * @date 15/11/3 + */ +public class CustomError extends LVCustomPanel { + + public CustomError(Globals globals, LuaValue metaTable, Varargs varargs) { + super(globals, metaTable, varargs); + } + + @Override + public void initPanel() { + Button button = new Button(getContext()); + button.setText("Error"); + + LayoutParams relativeLayout = LuaViewUtil.createRelativeLayoutParamsWW(); + relativeLayout.addRule(RelativeLayout.CENTER_IN_PARENT); + addView(button, relativeLayout); + + button.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + LuaTable table = new LuaTable(); + table.insert(1, LuaValue.valueOf(1.4)); + callLuaCallback("Message", "Error", 100, new Object(), table); + } + }); + } +} diff --git a/Android/LuaViewDemo/src/com/taobao/luaview/demo/ui/CustomLoading.java b/Android/LuaViewDemo/src/com/taobao/luaview/demo/ui/CustomLoading.java new file mode 100644 index 00000000..dba2c242 --- /dev/null +++ b/Android/LuaViewDemo/src/com/taobao/luaview/demo/ui/CustomLoading.java @@ -0,0 +1,42 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.demo.ui; + +import android.view.View; +import android.widget.Button; +import android.widget.ProgressBar; +import android.widget.RelativeLayout; + +import com.taobao.luaview.util.LuaViewUtil; +import com.taobao.luaview.view.LVCustomPanel; +import com.taobao.luaview.view.LVLoadingView; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; + +/** + * @author song + * @date 15/11/3 + */ +public class CustomLoading extends LVCustomPanel { + + public CustomLoading(Globals globals, LuaValue metaTable, Varargs varargs) { + super(globals, metaTable, varargs); + } + + @Override + public void initPanel() { + final View lvLoadingView = new ProgressBar(getContext(), null, android.R.attr.progressBarStyleSmallInverse); + LayoutParams relativeLayout = LuaViewUtil.createRelativeLayoutParamsWW(); + relativeLayout.addRule(RelativeLayout.CENTER_IN_PARENT); + lvLoadingView.setVisibility(View.VISIBLE); + addView(lvLoadingView, relativeLayout); + } +} diff --git a/Android/LuaViewSDK/.gitignore b/Android/LuaViewSDK/.gitignore new file mode 100644 index 00000000..b3fdf275 --- /dev/null +++ b/Android/LuaViewSDK/.gitignore @@ -0,0 +1,2 @@ +build +target \ No newline at end of file diff --git a/Android/LuaViewSDK/AndroidManifest.xml b/Android/LuaViewSDK/AndroidManifest.xml new file mode 100644 index 00000000..03e30d44 --- /dev/null +++ b/Android/LuaViewSDK/AndroidManifest.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Android/LuaViewSDK/LuaViewSDK.iml b/Android/LuaViewSDK/LuaViewSDK.iml new file mode 100644 index 00000000..2b234176 --- /dev/null +++ b/Android/LuaViewSDK/LuaViewSDK.iml @@ -0,0 +1,99 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Android/LuaViewSDK/assets/debug.lua b/Android/LuaViewSDK/assets/debug.lua new file mode 100644 index 00000000..d64fc771 --- /dev/null +++ b/Android/LuaViewSDK/assets/debug.lua @@ -0,0 +1,406 @@ +_DEBUG_FILE = "@debug.lua" + +debug.bps = { + max = 0, + trace = false, + last_cmd = "", + next = false, + cur_func = nil, + trace_count = 0, + var_tbl = nil, +} + +function debug_log( log_str ) + print( "[调试器] " .. log_str ); +end + +function debug_print_var_0( name, value, level ) + local ret = ""; + local prefix = string:rep( " ", level ) + local str = string:format( "%s%s = %s", prefix, name, tostring(value) ) + + if type( value ) == "table" then + if debug.var_tbl[value] then + --已在临时表中的,只打印表地址 + -- print( str ) + ret = ret .. tostring(str) .. '\n'; + return ret; + end + + --加到临时表中,以免表出现循环引用时,打印也产生死循环 + debug.var_tbl[value] = true + --打印表中所有数据 + --print( string:format( "%s%s = {", prefix, name ) ) + ret = ret .. string:format( "%s%s = {", prefix, name ) .. '\n'; + for k, v in pairs( value ) do + if type( k ) == "string" then + else + k = tostring(k); + end + --不打印 "_"开头的内部变量 + --if string:sub( k, 1, 1 ) ~= "_" then + ret = ret .. debug_print_var_0( k, v, level + 1 ) + --end + end + -- print( prefix .. "}" ) + ret = ret .. prefix .. "}" .. '\n'; + elseif type( value ) == "string" then + -- print( str ) + ret = ret .. tostring(str) .. '\n'; + else + -- print( str ) + ret = ret .. tostring(str) .. '\n'; + end + return ret; +end + +function debug_print_var( name, value, level ) + local s = debug_print_var_0( name, value, level ); + if( s ) then + s = string:sub(s, 1, #s - 1); + debug_log( s ); + else + debug_log( s ); + end +end + +function debug_print_expr( var ) + if ( var==nil ) then + debug_log("debug_print_expr var==nil"); + return; + end + --清空临时变量表 + debug.var_tbl = {} + + local index = 1 + --找局部变量 + while true do + local name, value = debug:getlocal( 4, index ) + if not name then + break + end + index = index + 1 + + if name == var then + debug_print_var( var, value, 0 ) + return + end + end + + -- try upvalues + local func = debug:getinfo(4,"f").func + local index = 1 + while true do + local name, value = debug:getupvalue(func, index) + if not name then + break + end + if name == var then + debug_print_var( var, value, 0 ) + return + end + index = index + 1 + end + + + --找全局变量 + if _G[var] ~= nil then + debug_print_var( var, _G[var], 0 ) + return + end + + debug_log( var .. " is invalid" ) +end + + +function debug_run_expr( s ) + loadJson(s) +end + +function add_breakpoint( expr ) + local si = string:find( expr, ":" ) + if nil == si then + debug_log( "add breakpoint error, expr (" .. expr .. ") invalid" ) + return + end + + local line = string:sub( expr, si + 1 ) + local line = tonumber( line ) + local source = string:sub( expr, 1, si - 1 ) + + --先查找有不有相同断点 + if ( ( debug.bps[line] ~= nil ) and ( debug.bps[line][source] ~= nil ) ) then + debug_log( string:format( "breakpoint %s:%d existed", source, line ) ) + return + end + + local tbl = {} + tbl.source = source + tbl.line = line + tbl.active = true + tbl.number = debug.bps.max + 1 + + if debug.bps[line] == nil then + debug.bps[line] = {} + end + + debug.bps[line][source] = tbl + debug.bps.max = debug.bps.max + 1 + debug_log( string:format( "加断点(%s:%d)", source, line ) ) +end + +function remove_breakpoint( expr ) + local si = string:find( expr, ":" ) + if nil == si then + debug_log( "remove breakpoint error, expr (" .. expr .. ") invalid" ) + return + end + + local line = string:sub( expr, si + 1 ) + local line = tonumber( line ) + local source = string:sub( expr, 1, si - 1 ) + + --先查找有不有相同断点 + if( ( debug.bps[line] ~= nil ) and ( debug.bps[line][source] ~= nil ) )then + debug.bps[line][source] = nil; + debug_log( string:format( "删点断(%s:%d)", source, line ) ) + return + else + debug_log( string:format( "not found breakpoint %s:%d existed", source, line ) ) + return + end +end + +function debug_show_bp() + for k, v in pairs( debug.bps ) do + if type( v ) == "table" then + for k1, v1 in pairs( v ) do + local str = string:format( "bp num:%d %s:%d active:", + v1.number, + v1.source, + v1.line ) + if v1.active then + str = str .. "enable" + else + str = str .. "disable" + end + debug_log( str ) + end + end + end +end + +function debug_del_bp( expr ) + local number = tonumber( expr ) + for k, v in pairs( debug.bps ) do + if type( v ) == "table" then + for k1, v1 in pairs( v ) do + if v1.number == number then + debug.bps[k][k1] = nil + debug_log( "remove bp:" .. number .. " ok" ) + end + end + end + end +end + +function debug_enable_bp( expr ) + local number = tonumber( expr ) + for k, v in pairs( debug.bps ) do + if type( v ) == "table" then + for k1, v1 in pairs( v ) do + if v1.number == number then + v1.active = true + debug_log( "enable bp:" .. number ) + end + end + end + end +end + +function debug_disable_bp( expr ) + local number = tonumber( expr ) + for k, v in pairs( debug.bps ) do + if type( v ) == "table" then + for k1, v1 in pairs( v ) do + if v1.number == number then + v1.active = false + debug_log( "disable bp:" .. number ) + end + end + end + end +end + +function debug_help() + print( "h help info" ) + print( "c continue" ) + print( "s trace" ) + print( "n next" ) + print( "p var print variable" ) + print( "run expression run expression code" ) + print( "b src:line add breakpoint" ) + print( "rb src:line remove breakpoint" ) + print( "bl list breakpoint" ) + print( "bt print traceback" ) +end + +function debug_runing_execute( cmd ) + if( cmd==nil ) then + return; + end + local c = cmd + local expr = "" + local si = string:find( cmd, " " ) + if si ~= nil then + c = string:sub( cmd, 1, si - 1 ) + expr = string:sub( cmd, string:find( cmd, " %w" ) + 1 ) + end + + if c == "b" then + add_breakpoint( expr ) + elseif c == "rb" then + remove_breakpoint( expr ) + elseif c == "p" then + debug_print_expr( expr ) + end +end + +function debug_execute_cmd( env ) + --print( "(ldb) " ) + local cmd = debug:readCmd() + if ( cmd ==nil ) then + debug:sleep(0.01); + return false; + end + --取上一次的命令,方便调试 + -- if cmd ~= "" then + -- debug.bps.last_cmd = cmd + -- else + -- cmd = debug.bps.last_cmd + -- end + + local c = cmd + local expr = "" + local si = string:find( cmd, " " ) + if si ~= nil then + c = string:sub( cmd, 1, si - 1 ) + -- local index = string:find( cmd, " %w" ); + -- if ( index ) then + -- expr = string:sub( cmd, index + 1 ); + -- end + expr = string:sub(cmd, si + 1 ); + end + if c=="close" then + debug_close(); + return true; + elseif c=="none" then + return false; + elseif c == "c" then + debug.bps.trace = false + return true + elseif c == "s" then + debug.bps.trace = true + return true + elseif c == "n" then + debug.bps.trace = false + debug.bps.next = true + debug.bps.cur_func = env.func + debug.bps.trace_count = debug:traceback_count() + return true + elseif c == "p" then + debug_print_expr( expr ) + elseif c == "run" then + debug_run_expr( expr ) + elseif c == "b" then + add_breakpoint( expr ) + elseif c == "rb" then + remove_breakpoint( expr ) + elseif c == "bl" then + debug_show_bp() + elseif c == "d" then + debug_del_bp( expr ) + elseif c == "be" then + debug_enable_bp( expr ) + elseif c == "bd" then + debug_disable_bp( expr ) + elseif c == "bt" then + print( debug:traceback("", 3) ) + elseif c == "h" then + debug_help() + else + debug_log( "invalid cmd:" .. cmd ) + end + return false +end + +function debug_trace( event, line ) + + local env = debug:getinfo( 2 ) + if not env then + print("getinfo failed ", event, line) + return + end + + if env.source == _DEBUG_FILE then + return + end + + --判断是否在next调试 + if debug.bps.next then + local trace_count = debug:traceback_count() + --函数返回了,调用栈数量就会比现在小 + if trace_count < debug.bps.trace_count then + debug.bps.next = false + debug.bps.trace = true + elseif trace_count == debug.bps.trace_count then + if debug.bps.cur_func == env.func then + debug.bps.next = false + debug.bps.trace = true + end + end + end + + --判断是否有断点 + if( ( not debug.bps.trace ) and ( debug.bps[line] ~= nil ) ) then + local tbl = debug.bps[line][env.source] + if( ( tbl ~= nil ) and tbl.active )then + --如果在next时,碰到断点了,就清除单步运行状态 + debug.bps.next = false + debug.bps.trace = true + -- debug_log( "碰到断点 " .. env.source .. " - " .. line ) + end + end + + if debug.bps.trace then + local src = debug:get_file_line( env.source, line ) + local funname = env.name or "unknow" + --debug_log( string:format( "%s:%d(%s) %s", env.source, line, funname, src ) ) + debug:runningLine( env.source, line ); + debug.bps.cur_file = env.source; + debug.bps.cur_line = line + while not debug_execute_cmd( env ) do + end + return; + end + + -- local cmd = debug:readCmd() + -- debug_runing_execute( cmd ); +end + +function begin_debug() + debug.bps.trace = true + debug:sethook( debug_trace, "l" ) +end + +--关闭debugger +function debug_close() + debug.bps.trace = false + debug.bps.next = false + debug:sethook() +end + +debug:printToServer(true); + + +begin_debug(); -- last line diff --git a/Android/LuaViewSDK/build.gradle b/Android/LuaViewSDK/build.gradle new file mode 100644 index 00000000..cd5e2b6b --- /dev/null +++ b/Android/LuaViewSDK/build.gradle @@ -0,0 +1,66 @@ +//打包配置 +apply plugin: 'com.android.library' + +description = """LuaView-Android: 用lua写Android、iOS""" + +repositories { + mavenLocal() + mavenCentral() + jcenter() +} + +configurations { + providedCompile +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) + compile 'com.android.support:support-v4:23.0.1' + //recycler view + compile 'com.android.support:recyclerview-v7:23.0.1' +// compile 'com.android.support:appcompat-v7:23.4.0' +} + +/* + 定义android插件 +*/ +android { + compileSdkVersion 23 + buildToolsVersion '25.0.0' + sourceSets { + main { + jniLibs.srcDirs = ['libs'] + manifest.srcFile 'AndroidManifest.xml' + java.srcDirs = ['src', 'src-csslayout'] + resources.srcDirs = ['src'] + aidl.srcDirs = ['src'] + renderscript.srcDirs = ['src'] + res.srcDirs = ['res'] + assets.srcDirs = ['assets'] + } + + // Move the tests to tests/java, tests/res, etc... + instrumentTest.setRoot('tests') + + // Move the build types to build-types/ + // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ... + // This moves them out of them default location under src//... which would + // conflict with src/ being used by the main source set. + // Adding new build types or product flavors should be accompanied + // by a similar customization. + debug.setRoot('build-types/debug') + release.setRoot('build-types/release') + } + packagingOptions { + exclude 'META-INF/LICENSE.txt' + } + buildTypes { + debug { + debuggable true + } + } + lintOptions { + abortOnError false + } +} + diff --git a/Android/LuaViewSDK/github_sync.sh b/Android/LuaViewSDK/github_sync.sh new file mode 100644 index 00000000..017c0fc9 --- /dev/null +++ b/Android/LuaViewSDK/github_sync.sh @@ -0,0 +1,39 @@ +if [ ! -n "$1" ]; then + echo "必须指定需要的同步的分支, sh github_sync.sh branch_name" + exit 0; +fi + +GIT_MERGE="git merge $1" + +echo "save current branch changes:" + +git stash + +GIT_CURRENT_BRANCH=$(git symbolic-ref -q HEAD) +GIT_CURRENT_BRANCH=${GIT_CURRENT_BRANCH##refs/heads/} +GIT_CURRENT_BRANCH=${GIT_CURRENT_BRANCH:-HEAD} + + +git pull +git checkout develop +git pull +$GIT_MERGE + +echo "\npush to develop" +git push +echo "\npush to github on branch develop" +git push https://github.com/alibaba/LuaViewSDK develop:develop + +echo "\n" +git checkout master +git pull +git merge develop + +echo "\npush to master" +git push +echo "\npush to github on branch master" +git push https://github.com/alibaba/LuaViewSDK master:master + +echo "\n" +git checkout $GIT_CURRENT_BRANCH +git stash apply diff --git a/Android/LuaViewSDK/package/keystore/test/debug.keystore b/Android/LuaViewSDK/package/keystore/test/debug.keystore new file mode 100644 index 00000000..1399bfd5 Binary files /dev/null and b/Android/LuaViewSDK/package/keystore/test/debug.keystore differ diff --git a/Android/LuaViewSDK/package/keystore/test/debugkeystore readme.txt b/Android/LuaViewSDK/package/keystore/test/debugkeystore readme.txt new file mode 100644 index 00000000..b138878c --- /dev/null +++ b/Android/LuaViewSDK/package/keystore/test/debugkeystore readme.txt @@ -0,0 +1,2 @@ +alias:androiddebugkey +pwd:android \ No newline at end of file diff --git a/Android/LuaViewSDK/pom.xml b/Android/LuaViewSDK/pom.xml new file mode 100644 index 00000000..7efd6784 --- /dev/null +++ b/Android/LuaViewSDK/pom.xml @@ -0,0 +1,131 @@ + + 4.0.0 + + + + com.taobao.ju.android + luaviewsdk + 1.0.0-SNAPSHOT + ${packaging.type} + + LuaView-Android SDK + + + LuaView Android SDK, 2015.11.23 add by song + + + + true + 57 + aar + UTF-8 + + + + src + + + + + com.taobao.maven.plugins.android + android-maven-plugin + + + 1.3.6.7 + true + true + + ${pakageidsegment} + true + ${project.basedir}/src + ${project.basedir}/AndroidManifest.xml + ${project.basedir}/res + ${project.basedir}/assets + + + + + + + + + releases + http://mvnrepo.alibaba-inc.com/mvn/releases + + + snapshots + http://mvnrepo.alibaba-inc.com/mvn/snapshots + + + + + + + + com.google.android + android + r23 + provided + + + + + com.android.support + support-v4 + 23.0.1 + aar + provided + + + + + + + + com.android.support + recyclerview-v7 + 23.4.0 + aar + provided + + + + + + + + + awb + + awb + provided + false + + + + + aar + + true + + + aar + provided + false + + + + + diff --git a/Android/LuaViewSDK/proguard-rules.pro b/Android/LuaViewSDK/proguard-rules.pro new file mode 100644 index 00000000..8b3bf7ef --- /dev/null +++ b/Android/LuaViewSDK/proguard-rules.pro @@ -0,0 +1,17 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in /Users/song/AndroidSDK/sdk/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/Android/LuaViewSDK/proguard.cfg b/Android/LuaViewSDK/proguard.cfg new file mode 100644 index 00000000..e69de29b diff --git a/Android/LuaViewSDK/res/color/lv_vpi__dark_theme.xml b/Android/LuaViewSDK/res/color/lv_vpi__dark_theme.xml new file mode 100644 index 00000000..2a1cb137 --- /dev/null +++ b/Android/LuaViewSDK/res/color/lv_vpi__dark_theme.xml @@ -0,0 +1,23 @@ + + + + + + + + + + diff --git a/Android/LuaViewSDK/res/color/lv_vpi__light_theme.xml b/Android/LuaViewSDK/res/color/lv_vpi__light_theme.xml new file mode 100644 index 00000000..ffe0390d --- /dev/null +++ b/Android/LuaViewSDK/res/color/lv_vpi__light_theme.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + diff --git a/Android/LuaViewSDK/res/drawable-v21/lv_click_foreground.xml b/Android/LuaViewSDK/res/drawable-v21/lv_click_foreground.xml new file mode 100644 index 00000000..6865917a --- /dev/null +++ b/Android/LuaViewSDK/res/drawable-v21/lv_click_foreground.xml @@ -0,0 +1,10 @@ + + + + + + + + \ No newline at end of file diff --git a/Android/LuaViewSDK/res/drawable/lv_bg_dialog_progress_default.xml b/Android/LuaViewSDK/res/drawable/lv_bg_dialog_progress_default.xml new file mode 100644 index 00000000..5cd5e755 --- /dev/null +++ b/Android/LuaViewSDK/res/drawable/lv_bg_dialog_progress_default.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Android/LuaViewSDK/res/drawable/lv_click_foreground.xml b/Android/LuaViewSDK/res/drawable/lv_click_foreground.xml new file mode 100644 index 00000000..21323871 --- /dev/null +++ b/Android/LuaViewSDK/res/drawable/lv_click_foreground.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/Android/LuaViewSDK/res/drawable/lv_vpi__tab_indicator.xml b/Android/LuaViewSDK/res/drawable/lv_vpi__tab_indicator.xml new file mode 100644 index 00000000..9def9ba8 --- /dev/null +++ b/Android/LuaViewSDK/res/drawable/lv_vpi__tab_indicator.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/Android/LuaViewSDK/res/drawable/lv_vpi__tab_selected_focused_holo.9.png b/Android/LuaViewSDK/res/drawable/lv_vpi__tab_selected_focused_holo.9.png new file mode 100644 index 00000000..673e3bf1 Binary files /dev/null and b/Android/LuaViewSDK/res/drawable/lv_vpi__tab_selected_focused_holo.9.png differ diff --git a/Android/LuaViewSDK/res/drawable/lv_vpi__tab_selected_holo.9.png b/Android/LuaViewSDK/res/drawable/lv_vpi__tab_selected_holo.9.png new file mode 100644 index 00000000..d57df98b Binary files /dev/null and b/Android/LuaViewSDK/res/drawable/lv_vpi__tab_selected_holo.9.png differ diff --git a/Android/LuaViewSDK/res/drawable/lv_vpi__tab_selected_pressed_holo.9.png b/Android/LuaViewSDK/res/drawable/lv_vpi__tab_selected_pressed_holo.9.png new file mode 100644 index 00000000..6278eef4 Binary files /dev/null and b/Android/LuaViewSDK/res/drawable/lv_vpi__tab_selected_pressed_holo.9.png differ diff --git a/Android/LuaViewSDK/res/drawable/lv_vpi__tab_unselected_focused_holo.9.png b/Android/LuaViewSDK/res/drawable/lv_vpi__tab_unselected_focused_holo.9.png new file mode 100644 index 00000000..294991d7 Binary files /dev/null and b/Android/LuaViewSDK/res/drawable/lv_vpi__tab_unselected_focused_holo.9.png differ diff --git a/Android/LuaViewSDK/res/drawable/lv_vpi__tab_unselected_holo.9.png b/Android/LuaViewSDK/res/drawable/lv_vpi__tab_unselected_holo.9.png new file mode 100644 index 00000000..19532ab1 Binary files /dev/null and b/Android/LuaViewSDK/res/drawable/lv_vpi__tab_unselected_holo.9.png differ diff --git a/Android/LuaViewSDK/res/drawable/lv_vpi__tab_unselected_pressed_holo.9.png b/Android/LuaViewSDK/res/drawable/lv_vpi__tab_unselected_pressed_holo.9.png new file mode 100644 index 00000000..aadc6f87 Binary files /dev/null and b/Android/LuaViewSDK/res/drawable/lv_vpi__tab_unselected_pressed_holo.9.png differ diff --git a/Android/LuaViewSDK/res/layout/lv_dialog_progress_default.xml b/Android/LuaViewSDK/res/layout/lv_dialog_progress_default.xml new file mode 100644 index 00000000..2736c0ff --- /dev/null +++ b/Android/LuaViewSDK/res/layout/lv_dialog_progress_default.xml @@ -0,0 +1,13 @@ + + + + + + \ No newline at end of file diff --git a/Android/LuaViewSDK/res/layout/lv_recyclerview_vertical.xml b/Android/LuaViewSDK/res/layout/lv_recyclerview_vertical.xml new file mode 100644 index 00000000..18562e74 --- /dev/null +++ b/Android/LuaViewSDK/res/layout/lv_recyclerview_vertical.xml @@ -0,0 +1,7 @@ + + \ No newline at end of file diff --git a/Android/LuaViewSDK/res/values/attrs_auto_fit_text.xml b/Android/LuaViewSDK/res/values/attrs_auto_fit_text.xml new file mode 100644 index 00000000..f36dd180 --- /dev/null +++ b/Android/LuaViewSDK/res/values/attrs_auto_fit_text.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Android/LuaViewSDK/res/values/colors.xml b/Android/LuaViewSDK/res/values/colors.xml new file mode 100644 index 00000000..54c6a849 --- /dev/null +++ b/Android/LuaViewSDK/res/values/colors.xml @@ -0,0 +1,6 @@ + + + + #99000000 + + \ No newline at end of file diff --git a/Android/LuaViewSDK/res/values/dimens.xml b/Android/LuaViewSDK/res/values/dimens.xml new file mode 100644 index 00000000..be1dc8ba --- /dev/null +++ b/Android/LuaViewSDK/res/values/dimens.xml @@ -0,0 +1,5 @@ + + + 5dp + + \ No newline at end of file diff --git a/Android/LuaViewSDK/res/values/ids.xml b/Android/LuaViewSDK/res/values/ids.xml new file mode 100644 index 00000000..5260221c --- /dev/null +++ b/Android/LuaViewSDK/res/values/ids.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Android/LuaViewSDK/res/values/lv_vpi__attrs.xml b/Android/LuaViewSDK/res/values/lv_vpi__attrs.xml new file mode 100644 index 00000000..464221ef --- /dev/null +++ b/Android/LuaViewSDK/res/values/lv_vpi__attrs.xml @@ -0,0 +1,129 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Android/LuaViewSDK/res/values/lv_vpi__colors.xml b/Android/LuaViewSDK/res/values/lv_vpi__colors.xml new file mode 100644 index 00000000..0b006c25 --- /dev/null +++ b/Android/LuaViewSDK/res/values/lv_vpi__colors.xml @@ -0,0 +1,26 @@ + + + + + #ff000000 + #fff3f3f3 + @color/lv_vpi__background_holo_light + @color/lv_vpi__background_holo_dark + #ff4c4c4c + #ffb2b2b2 + @color/lv_vpi__bright_foreground_holo_light + @color/lv_vpi__bright_foreground_holo_dark + diff --git a/Android/LuaViewSDK/res/values/lv_vpi__defaults.xml b/Android/LuaViewSDK/res/values/lv_vpi__defaults.xml new file mode 100644 index 00000000..d07c44a9 --- /dev/null +++ b/Android/LuaViewSDK/res/values/lv_vpi__defaults.xml @@ -0,0 +1,53 @@ + + + + + true + #FFFFFFFF + #00000000 + 0 + 3dp + false + #FFDDDDDD + 1dp + + 12dp + 4dp + 1dp + #FF33B5E5 + #FFBBBBBB + true + + 4dp + #FF33B5E5 + 2dp + 2 + 4dp + 20dp + 7dp + 0 + #FFFFFFFF + true + #BBFFFFFF + 15dp + 5dp + 7dp + + true + 300 + 400 + #FF33B5E5 + \ No newline at end of file diff --git a/Android/LuaViewSDK/res/values/lv_vpi__styles.xml b/Android/LuaViewSDK/res/values/lv_vpi__styles.xml new file mode 100644 index 00000000..f2fcbf56 --- /dev/null +++ b/Android/LuaViewSDK/res/values/lv_vpi__styles.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + diff --git a/Android/LuaViewSDK/res/values/strings.xml b/Android/LuaViewSDK/res/values/strings.xml new file mode 100644 index 00000000..07157276 --- /dev/null +++ b/Android/LuaViewSDK/res/values/strings.xml @@ -0,0 +1,7 @@ + + + + LuaView + + + diff --git a/Android/LuaViewSDK/res/values/styles.xml b/Android/LuaViewSDK/res/values/styles.xml new file mode 100644 index 00000000..0309de5a --- /dev/null +++ b/Android/LuaViewSDK/res/values/styles.xml @@ -0,0 +1,20 @@ + + + + + + + + + diff --git a/Android/LuaViewSDK/src/com/facebook/csslayout/CSSAlign.java b/Android/LuaViewSDK/src/com/facebook/csslayout/CSSAlign.java new file mode 100644 index 00000000..f177270f --- /dev/null +++ b/Android/LuaViewSDK/src/com/facebook/csslayout/CSSAlign.java @@ -0,0 +1,17 @@ +/** + * Copyright (c) 2014, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ +package com.facebook.csslayout; + +public enum CSSAlign { + AUTO, + FLEX_START, + CENTER, + FLEX_END, + STRETCH, +} diff --git a/Android/LuaViewSDK/src/com/facebook/csslayout/CSSConstants.java b/Android/LuaViewSDK/src/com/facebook/csslayout/CSSConstants.java new file mode 100644 index 00000000..ec0b3f7c --- /dev/null +++ b/Android/LuaViewSDK/src/com/facebook/csslayout/CSSConstants.java @@ -0,0 +1,18 @@ +/** + * Copyright (c) 2014, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ +package com.facebook.csslayout; + +public class CSSConstants { + + public static final float UNDEFINED = Float.NaN; + + public static boolean isUndefined(float value) { + return Float.compare(value, UNDEFINED) == 0; + } +} diff --git a/Android/LuaViewSDK/src/com/facebook/csslayout/CSSDirection.java b/Android/LuaViewSDK/src/com/facebook/csslayout/CSSDirection.java new file mode 100644 index 00000000..26e93bd6 --- /dev/null +++ b/Android/LuaViewSDK/src/com/facebook/csslayout/CSSDirection.java @@ -0,0 +1,15 @@ +/** + * Copyright (c) 2014, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ +package com.facebook.csslayout; + +public enum CSSDirection { + INHERIT, + LTR, + RTL, +} diff --git a/Android/LuaViewSDK/src/com/facebook/csslayout/CSSFlexDirection.java b/Android/LuaViewSDK/src/com/facebook/csslayout/CSSFlexDirection.java new file mode 100644 index 00000000..b5040e25 --- /dev/null +++ b/Android/LuaViewSDK/src/com/facebook/csslayout/CSSFlexDirection.java @@ -0,0 +1,16 @@ +/** + * Copyright (c) 2014, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ +package com.facebook.csslayout; + +public enum CSSFlexDirection { + COLUMN, + COLUMN_REVERSE, + ROW, + ROW_REVERSE +} diff --git a/Android/LuaViewSDK/src/com/facebook/csslayout/CSSJustify.java b/Android/LuaViewSDK/src/com/facebook/csslayout/CSSJustify.java new file mode 100644 index 00000000..371b38cb --- /dev/null +++ b/Android/LuaViewSDK/src/com/facebook/csslayout/CSSJustify.java @@ -0,0 +1,17 @@ +/** + * Copyright (c) 2014, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ +package com.facebook.csslayout; + +public enum CSSJustify { + FLEX_START, + CENTER, + FLEX_END, + SPACE_BETWEEN, + SPACE_AROUND, +} diff --git a/Android/LuaViewSDK/src/com/facebook/csslayout/CSSLayout.java b/Android/LuaViewSDK/src/com/facebook/csslayout/CSSLayout.java new file mode 100644 index 00000000..26ec4d56 --- /dev/null +++ b/Android/LuaViewSDK/src/com/facebook/csslayout/CSSLayout.java @@ -0,0 +1,58 @@ +/** + * Copyright (c) 2014, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ +package com.facebook.csslayout; + +import java.util.Arrays; + +/** + * Where the output of {@link LayoutEngine#layoutNode(CSSNode, float)} will go in the CSSNode. + */ +public class CSSLayout { + public static final int POSITION_LEFT = 0; + public static final int POSITION_TOP = 1; + public static final int POSITION_RIGHT = 2; + public static final int POSITION_BOTTOM = 3; + + public static final int DIMENSION_WIDTH = 0; + public static final int DIMENSION_HEIGHT = 1; + + public float[] position = new float[4]; + public float[] dimensions = new float[2]; + public CSSDirection direction = CSSDirection.LTR; + + /** + * This should always get called before calling {@link LayoutEngine#layoutNode(CSSNode, float)} + */ + public void resetResult() { + Arrays.fill(position, 0); + Arrays.fill(dimensions, CSSConstants.UNDEFINED); + direction = CSSDirection.LTR; + } + + public void copy(CSSLayout layout) { + position[POSITION_LEFT] = layout.position[POSITION_LEFT]; + position[POSITION_TOP] = layout.position[POSITION_TOP]; + position[POSITION_RIGHT] = layout.position[POSITION_RIGHT]; + position[POSITION_BOTTOM] = layout.position[POSITION_BOTTOM]; + dimensions[DIMENSION_WIDTH] = layout.dimensions[DIMENSION_WIDTH]; + dimensions[DIMENSION_HEIGHT] = layout.dimensions[DIMENSION_HEIGHT]; + direction = layout.direction; + } + + @Override + public String toString() { + return "layout: {" + + "left: " + position[POSITION_LEFT] + ", " + + "top: " + position[POSITION_TOP] + ", " + + "width: " + dimensions[DIMENSION_WIDTH] + ", " + + "height: " + dimensions[DIMENSION_HEIGHT] + ", " + + "direction: " + direction + + "}"; + } +} diff --git a/Android/LuaViewSDK/src/com/facebook/csslayout/CSSLayoutContext.java b/Android/LuaViewSDK/src/com/facebook/csslayout/CSSLayoutContext.java new file mode 100644 index 00000000..8c93e0eb --- /dev/null +++ b/Android/LuaViewSDK/src/com/facebook/csslayout/CSSLayoutContext.java @@ -0,0 +1,20 @@ +/** + * Copyright (c) 2014, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ +package com.facebook.csslayout; + +/** + * A context for holding values local to a given instance of layout computation. + * + * This is necessary for making layout thread-safe. A separate instance should + * be used when {@link CSSNode#calculateLayout} is called concurrently on + * different node hierarchies. + */ +public class CSSLayoutContext { + /*package*/ final MeasureOutput measureOutput = new MeasureOutput(); +} diff --git a/Android/LuaViewSDK/src/com/facebook/csslayout/CSSNode.java b/Android/LuaViewSDK/src/com/facebook/csslayout/CSSNode.java new file mode 100644 index 00000000..95d4f67d --- /dev/null +++ b/Android/LuaViewSDK/src/com/facebook/csslayout/CSSNode.java @@ -0,0 +1,601 @@ +/** + * Copyright (c) 2014, Facebook, Inc. + * All rights reserved. + *

+ * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ +package com.facebook.csslayout; + +import com.taobao.luaview.annotations.Nullable; +import com.taobao.luaview.util.Assertions; + +import java.util.ArrayList; + +import static com.facebook.csslayout.CSSLayout.DIMENSION_HEIGHT; +import static com.facebook.csslayout.CSSLayout.DIMENSION_WIDTH; +import static com.facebook.csslayout.CSSLayout.POSITION_BOTTOM; +import static com.facebook.csslayout.CSSLayout.POSITION_LEFT; +import static com.facebook.csslayout.CSSLayout.POSITION_RIGHT; +import static com.facebook.csslayout.CSSLayout.POSITION_TOP; + +/** + * A CSS Node. It has a style object you can manipulate at {@link #style}. After calling + * {@link #calculateLayout()}, {@link #layout} will be filled with the results of the layout. + */ +public class CSSNode { + + private static enum LayoutState { + /** + * Some property of this node or its children has changes and the current values in + * {@link #layout} are not valid. + */ + DIRTY, + + /** + * This node has a new layout relative to the last time {@link #markLayoutSeen()} was called. + */ + HAS_NEW_LAYOUT, + + /** + * {@link #layout} is valid for the node's properties and this layout has been marked as + * having been seen. + */ + UP_TO_DATE, + } + + public static interface MeasureFunction { + + /** + * Should measure the given node and put the result in the given MeasureOutput. + * + * NB: measure is NOT guaranteed to be threadsafe/re-entrant safe! + */ + public void measure(CSSNode node, float width, float height, MeasureOutput measureOutput); + } + + // VisibleForTesting + /*package*/ final CSSStyle style = new CSSStyle(); + /*package*/ final CSSLayout layout = new CSSLayout(); + /*package*/ final CachedCSSLayout lastLayout = new CachedCSSLayout(); + + public int lineIndex = 0; + + /*package*/ CSSNode nextAbsoluteChild; + /*package*/ CSSNode nextFlexChild; + + protected + @Nullable + ArrayList mChildren; + private + @Nullable + CSSNode mParent; + private + @Nullable + MeasureFunction mMeasureFunction = null; + private boolean mSizeToFit; + private LayoutState mLayoutState = LayoutState.DIRTY; + + public int getChildCount() { + return mChildren == null ? 0 : mChildren.size(); + } + + public CSSLayout getLayout() { + return layout; + } + + public void resetChildren() { + mChildren.clear(); + } + + public boolean getSizeToFit() { + return mSizeToFit; + } + + public void setSizeToFit(boolean sizeToFit) { + mSizeToFit = sizeToFit; + } + + public CSSNode getChildAt(int i) { + Assertions.assertNotNull(mChildren); + return mChildren.get(i); + } + + public void addChildAt(CSSNode child, int i) { + if (child.mParent != null) { + throw new IllegalStateException("Child already has a parent, it must be removed first."); + } + if (mChildren == null) { + // 4 is kinda arbitrary, but the default of 10 seems really high for an average View. + mChildren = new ArrayList(4); + } + + mChildren.add(i, child); + child.mParent = this; + dirty(); + } + + public void setAlignContent(CSSAlign alignContent) { + if (style.alignContent != alignContent) { + style.alignContent = alignContent; + dirty(); + } + } + + public CSSAlign getAlignContent() { + return style.alignContent; + } + + public float getStyleMinWidth() { + return style.minWidth; + } + + public void setStyleMinWidth(float width) { + if (!valuesEqual(style.minWidth, width)) { + style.minWidth = width; + dirty(); + } + } + + public float getStyleMinHeight() { + return style.minHeight; + } + + public void setStyleMinHeight(float height) { + if (!valuesEqual(style.minHeight, height)) { + style.minHeight = height; + dirty(); + } + } + + public float getStyleMaxWidth() { + return style.maxWidth; + } + + public void setStyleMaxWidth(float width) { + if (!valuesEqual(style.maxWidth, width)) { + style.maxWidth = width; + dirty(); + } + } + + public float getStyleMaxHeight() { + return style.maxHeight; + } + + public void setStyleMaxHeight(float height) { + if (!valuesEqual(style.maxHeight, height)) { + style.maxHeight = height; + dirty(); + } + } + + + public void addChild(CSSNode child) { + if (child.mParent != null) { + throw new IllegalStateException("Child already has a parent, it must be removed first."); + } + if (mChildren == null) { + // 4 is kinda arbitrary, but the default of 10 seems really high for an average View. + mChildren = new ArrayList(4); + } + + mChildren.add(child); + child.mParent = this; + dirty(); + } + + public CSSNode removeChildAt(int i) { + Assertions.assertNotNull(mChildren); + CSSNode removed = mChildren.remove(i); + removed.mParent = null; + dirty(); + return removed; + } + + public + @Nullable + CSSNode getParent() { + return mParent; + } + + /** + * @return the index of the given child, or -1 if the child doesn't exist in this node. + */ + public int indexOf(CSSNode child) { + Assertions.assertNotNull(mChildren); + return mChildren.indexOf(child); + } + + public void setMeasureFunction(MeasureFunction measureFunction) { + if (mMeasureFunction != measureFunction) { + mMeasureFunction = measureFunction; + dirty(); + } + } + + public boolean isMeasureDefined() { + return mMeasureFunction != null; + } + + /*package*/ MeasureOutput measure(MeasureOutput measureOutput, float width, float height) { + if (!isMeasureDefined()) { + throw new RuntimeException("Measure function isn't defined!"); + } + measureOutput.height = CSSConstants.UNDEFINED; + measureOutput.width = CSSConstants.UNDEFINED; + Assertions.assertNotNull(mMeasureFunction).measure(this, width, height, measureOutput); + return measureOutput; + } + + /** + * Performs the actual layout and saves the results in {@link #layout} + */ + public void calculateLayout(CSSLayoutContext layoutContext) { + layout.resetResult(); + LayoutEngine.layoutNode(layoutContext, this, CSSConstants.UNDEFINED, CSSConstants.UNDEFINED, null); + } + + /** + * See {@link LayoutState#DIRTY}. + */ + protected boolean isDirty() { + return mLayoutState == LayoutState.DIRTY; + } + + /** + * See {@link LayoutState#HAS_NEW_LAYOUT}. + */ + public boolean hasNewLayout() { + return mLayoutState == LayoutState.HAS_NEW_LAYOUT; + } + + protected void dirty() { + if (mLayoutState == LayoutState.DIRTY) { + return; + } else if (mLayoutState == LayoutState.HAS_NEW_LAYOUT) { + throw new IllegalStateException("Previous layout was ignored! markLayoutSeen() never called"); + } + + mLayoutState = LayoutState.DIRTY; + + if (mParent != null) { + mParent.dirty(); + } + } + + /*package*/ void markHasNewLayout() { + mLayoutState = LayoutState.HAS_NEW_LAYOUT; + } + + /** + * Tells the node that the current values in {@link #layout} have been seen. Subsequent calls + * to {@link #hasNewLayout()} will return false until this node is laid out with new parameters. + * You must call this each time the layout is generated if the node has a new layout. + */ + public void markLayoutSeen() { + if (!hasNewLayout()) { + throw new IllegalStateException("Expected node to have a new layout to be seen!"); + } + + mLayoutState = LayoutState.UP_TO_DATE; + } + + private void toStringWithIndentation(StringBuilder result, int level) { + // Spaces and tabs are dropped by IntelliJ logcat integration, so rely on __ instead. + StringBuilder indentation = new StringBuilder(); + for (int i = 0; i < level; ++i) { + indentation.append("__"); + } + + result.append(indentation.toString()); + result.append(layout.toString()); + + if (getChildCount() == 0) { + return; + } + + result.append(", children: [\n"); + for (int i = 0; i < getChildCount(); i++) { + getChildAt(i).toStringWithIndentation(result, level + 1); + result.append("\n"); + } + result.append(indentation + "]"); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + this.toStringWithIndentation(sb, 0); + return sb.toString(); + } + + protected boolean valuesEqual(float f1, float f2) { + return FloatUtil.floatsEqual(f1, f2); + } + + /** + * Get this node's direction, as defined in the style. + */ + public CSSDirection getStyleDirection() { + return style.direction; + } + + public void setDirection(CSSDirection direction) { + if (style.direction != direction) { + style.direction = direction; + dirty(); + } + } + + /** + * Get this node's flex direction, as defined by style. + */ + public CSSFlexDirection getFlexDirection() { + return style.flexDirection; + } + + public void setFlexDirection(CSSFlexDirection flexDirection) { + if (style.flexDirection != flexDirection) { + style.flexDirection = flexDirection; + dirty(); + } + } + + /** + * Get this node's justify content, as defined by style. + */ + public CSSJustify getJustifyContent() { + return style.justifyContent; + } + + public void setJustifyContent(CSSJustify justifyContent) { + if (style.justifyContent != justifyContent) { + style.justifyContent = justifyContent; + dirty(); + } + } + + /** + * Get this node's align items, as defined by style. + */ + public CSSAlign getAlignItems() { + return style.alignItems; + } + + public void setAlignItems(CSSAlign alignItems) { + if (style.alignItems != alignItems) { + style.alignItems = alignItems; + dirty(); + } + } + + /** + * Get this node's align items, as defined by style. + */ + public CSSAlign getAlignSelf() { + return style.alignSelf; + } + + public void setAlignSelf(CSSAlign alignSelf) { + if (style.alignSelf != alignSelf) { + style.alignSelf = alignSelf; + dirty(); + } + } + + /** + * Get this node's position type, as defined by style. + */ + public CSSPositionType getPositionType() { + return style.positionType; + } + + public void setPositionType(CSSPositionType positionType) { + if (style.positionType != positionType) { + style.positionType = positionType; + dirty(); + } + } + + public void setWrap(CSSWrap flexWrap) { + if (style.flexWrap != flexWrap) { + style.flexWrap = flexWrap; + dirty(); + } + } + + /** + * Get this node's flex, as defined by style. + */ + public float getFlex() { + return style.flex; + } + + public void setFlex(float flex) { + if (!valuesEqual(style.flex, flex)) { + style.flex = flex; + dirty(); + } + } + + /** + * Get this node's margin, as defined by style + default margin. + */ + public Spacing getMargin() { + return style.margin; + } + + public void setMargin(int spacingType, float margin) { + if (style.margin.set(spacingType, margin)) { + dirty(); + } + } + + /** + * Get this node's padding, as defined by style + default padding. + */ + public Spacing getPadding() { + return style.padding; + } + + public void setPadding(int spacingType, float padding) { + if (style.padding.set(spacingType, padding)) { + dirty(); + } + } + + /** + * Get this node's border, as defined by style. + */ + public Spacing getBorder() { + return style.border; + } + + public void setBorder(int spacingType, float border) { + if (style.border.set(spacingType, border)) { + dirty(); + } + } + + /** + * Get this node's position top, as defined by style. + */ + public float getPositionTop() { + return style.position[POSITION_TOP]; + } + + public void setPositionTop(float positionTop) { + if (!valuesEqual(style.position[POSITION_TOP], positionTop)) { + style.position[POSITION_TOP] = positionTop; + dirty(); + } + } + + /** + * Get this node's position bottom, as defined by style. + */ + public float getPositionBottom() { + return style.position[POSITION_BOTTOM]; + } + + public void setPositionBottom(float positionBottom) { + if (!valuesEqual(style.position[POSITION_BOTTOM], positionBottom)) { + style.position[POSITION_BOTTOM] = positionBottom; + dirty(); + } + } + + /** + * Get this node's position left, as defined by style. + */ + public float getPositionLeft() { + return style.position[POSITION_LEFT]; + } + + public void setPositionLeft(float positionLeft) { + if (!valuesEqual(style.position[POSITION_LEFT], positionLeft)) { + style.position[POSITION_LEFT] = positionLeft; + dirty(); + } + } + + /** + * Get this node's position right, as defined by style. + */ + public float getPositionRight() { + return style.position[POSITION_RIGHT]; + } + + public void setPositionRight(float positionRight) { + if (!valuesEqual(style.position[POSITION_RIGHT], positionRight)) { + style.position[POSITION_RIGHT] = positionRight; + dirty(); + } + } + + /** + * Get this node's width, as defined in the style. + */ + public float getStyleWidth() { + return style.dimensions[DIMENSION_WIDTH]; + } + + public void setStyleWidth(float width) { + if (!valuesEqual(style.dimensions[DIMENSION_WIDTH], width)) { + style.dimensions[DIMENSION_WIDTH] = width; + dirty(); + } + } + + public void setNoDirtyStyleWidth(float width) { + if (!valuesEqual(style.dimensions[DIMENSION_WIDTH], width)) { + style.dimensions[DIMENSION_WIDTH] = width; + } + } + + public void setNoDirtyStyleHeight(float height) { + if (!valuesEqual(style.dimensions[DIMENSION_HEIGHT], height)) { + style.dimensions[DIMENSION_HEIGHT] = height; + } + } + + /** + * Get this node's height, as defined in the style. + */ + public float getStyleHeight() { + return style.dimensions[DIMENSION_HEIGHT]; + } + + public void setStyleHeight(float height) { + if (!valuesEqual(style.dimensions[DIMENSION_HEIGHT], height)) { + style.dimensions[DIMENSION_HEIGHT] = height; + dirty(); + } + } + + public float getLayoutX() { + return layout.position[POSITION_LEFT]; + } + + public float getLayoutY() { + return layout.position[POSITION_TOP]; + } + + public float getLayoutWidth() { + return layout.dimensions[DIMENSION_WIDTH]; + } + + public float getLayoutHeight() { + return layout.dimensions[DIMENSION_HEIGHT]; + } + + public CSSDirection getLayoutDirection() { + return layout.direction; + } + + /** + * Set a default padding (left/top/right/bottom) for this node. + */ + public void setDefaultPadding(int spacingType, float padding) { + if (style.padding.setDefault(spacingType, padding)) { + dirty(); + } + } + + /** + * Resets this instance to its default state. This method is meant to be used when + * recycling {@link CSSNode} instances. + */ + public void reset() { + if (mParent != null || (mChildren != null && mChildren.size() > 0)) { + throw new IllegalStateException("You should not reset an attached CSSNode"); + } + + style.reset(); + layout.resetResult(); + lineIndex = 0; + mLayoutState = LayoutState.DIRTY; + } +} diff --git a/Android/LuaViewSDK/src/com/facebook/csslayout/CSSPositionType.java b/Android/LuaViewSDK/src/com/facebook/csslayout/CSSPositionType.java new file mode 100644 index 00000000..6dca2dc3 --- /dev/null +++ b/Android/LuaViewSDK/src/com/facebook/csslayout/CSSPositionType.java @@ -0,0 +1,14 @@ +/** + * Copyright (c) 2014, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ +package com.facebook.csslayout; + +public enum CSSPositionType { + RELATIVE, + ABSOLUTE, +} diff --git a/Android/LuaViewSDK/src/com/facebook/csslayout/CSSStyle.java b/Android/LuaViewSDK/src/com/facebook/csslayout/CSSStyle.java new file mode 100644 index 00000000..f4d325dc --- /dev/null +++ b/Android/LuaViewSDK/src/com/facebook/csslayout/CSSStyle.java @@ -0,0 +1,69 @@ +/** + * Copyright (c) 2014, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ +package com.facebook.csslayout; + +import java.util.Arrays; + +/** + * The CSS style definition for a {@link CSSNode}. + */ +public class CSSStyle { + + public CSSDirection direction; + public CSSFlexDirection flexDirection; + public CSSJustify justifyContent; + public CSSAlign alignContent; + public CSSAlign alignItems; + public CSSAlign alignSelf; + public CSSPositionType positionType; + public CSSWrap flexWrap; + public float flex; + + public Spacing margin = new Spacing(); + public Spacing padding = new Spacing(); + public Spacing border = new Spacing(); + + public float[] position = new float[4]; + public float[] dimensions = new float[2]; + + public float minWidth = CSSConstants.UNDEFINED; + public float minHeight = CSSConstants.UNDEFINED; + + public float maxWidth = CSSConstants.UNDEFINED; + public float maxHeight = CSSConstants.UNDEFINED; + + CSSStyle() { + reset(); + } + + void reset() { + direction = CSSDirection.INHERIT; + flexDirection = CSSFlexDirection.COLUMN; + justifyContent = CSSJustify.FLEX_START; + alignContent = CSSAlign.FLEX_START; + alignItems = CSSAlign.STRETCH; + alignSelf = CSSAlign.AUTO; + positionType = CSSPositionType.RELATIVE; + flexWrap = CSSWrap.NOWRAP; + flex = 0f; + + margin.reset();; + padding.reset(); + border.reset(); + + Arrays.fill(position, CSSConstants.UNDEFINED); + Arrays.fill(dimensions, CSSConstants.UNDEFINED); + + minWidth = CSSConstants.UNDEFINED; + minHeight = CSSConstants.UNDEFINED; + + maxWidth = CSSConstants.UNDEFINED; + maxHeight = CSSConstants.UNDEFINED; + } +} diff --git a/Android/LuaViewSDK/src/com/facebook/csslayout/CSSWrap.java b/Android/LuaViewSDK/src/com/facebook/csslayout/CSSWrap.java new file mode 100644 index 00000000..581481a4 --- /dev/null +++ b/Android/LuaViewSDK/src/com/facebook/csslayout/CSSWrap.java @@ -0,0 +1,14 @@ +/** + * Copyright (c) 2014, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ +package com.facebook.csslayout; + +public enum CSSWrap { + NOWRAP, + WRAP, +} diff --git a/Android/LuaViewSDK/src/com/facebook/csslayout/CachedCSSLayout.java b/Android/LuaViewSDK/src/com/facebook/csslayout/CachedCSSLayout.java new file mode 100644 index 00000000..e5393ef6 --- /dev/null +++ b/Android/LuaViewSDK/src/com/facebook/csslayout/CachedCSSLayout.java @@ -0,0 +1,22 @@ +/** + * Copyright (c) 2014, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ +package com.facebook.csslayout; + +/** + * CSSLayout with additional information about the conditions under which it was generated. + * {@link #requestedWidth} and {@link #requestedHeight} are the width and height the parent set on + * this node before calling layout visited us. + */ +public class CachedCSSLayout extends CSSLayout { + + public float requestedWidth = CSSConstants.UNDEFINED; + public float requestedHeight = CSSConstants.UNDEFINED; + public float parentMaxWidth = CSSConstants.UNDEFINED; + public float parentMaxHeight = CSSConstants.UNDEFINED; +} diff --git a/Android/LuaViewSDK/src/com/facebook/csslayout/FloatUtil.java b/Android/LuaViewSDK/src/com/facebook/csslayout/FloatUtil.java new file mode 100644 index 00000000..37dd007b --- /dev/null +++ b/Android/LuaViewSDK/src/com/facebook/csslayout/FloatUtil.java @@ -0,0 +1,21 @@ +/** + * Copyright (c) 2014, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ +package com.facebook.csslayout; + +public class FloatUtil { + + private static final float EPSILON = .00001f; + + public static boolean floatsEqual(float f1, float f2) { + if (Float.isNaN(f1) || Float.isNaN(f2)) { + return Float.isNaN(f1) && Float.isNaN(f2); + } + return Math.abs(f2 - f1) < EPSILON; + } +} diff --git a/Android/LuaViewSDK/src/com/facebook/csslayout/LayoutEngine.java b/Android/LuaViewSDK/src/com/facebook/csslayout/LayoutEngine.java new file mode 100644 index 00000000..f4743291 --- /dev/null +++ b/Android/LuaViewSDK/src/com/facebook/csslayout/LayoutEngine.java @@ -0,0 +1,948 @@ +/** + * Copyright (c) 2014, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ +package com.facebook.csslayout; + +import static com.facebook.csslayout.CSSLayout.DIMENSION_HEIGHT; +import static com.facebook.csslayout.CSSLayout.DIMENSION_WIDTH; +import static com.facebook.csslayout.CSSLayout.POSITION_BOTTOM; +import static com.facebook.csslayout.CSSLayout.POSITION_LEFT; +import static com.facebook.csslayout.CSSLayout.POSITION_RIGHT; +import static com.facebook.csslayout.CSSLayout.POSITION_TOP; + +/** + * Calculates layouts based on CSS style. See {@link #layoutNode(CSSNode, float, float)}. + */ +public class LayoutEngine { + + private static final int CSS_FLEX_DIRECTION_COLUMN = + CSSFlexDirection.COLUMN.ordinal(); + private static final int CSS_FLEX_DIRECTION_COLUMN_REVERSE = + CSSFlexDirection.COLUMN_REVERSE.ordinal(); + private static final int CSS_FLEX_DIRECTION_ROW = + CSSFlexDirection.ROW.ordinal(); + private static final int CSS_FLEX_DIRECTION_ROW_REVERSE = + CSSFlexDirection.ROW_REVERSE.ordinal(); + + private static final int CSS_POSITION_RELATIVE = CSSPositionType.RELATIVE.ordinal(); + private static final int CSS_POSITION_ABSOLUTE = CSSPositionType.ABSOLUTE.ordinal(); + + private static final int[] leading = { + POSITION_TOP, + POSITION_BOTTOM, + POSITION_LEFT, + POSITION_RIGHT, + }; + + private static final int[] trailing = { + POSITION_BOTTOM, + POSITION_TOP, + POSITION_RIGHT, + POSITION_LEFT, + }; + + private static final int[] pos = { + POSITION_TOP, + POSITION_BOTTOM, + POSITION_LEFT, + POSITION_RIGHT, + }; + + private static final int[] dim = { + DIMENSION_HEIGHT, + DIMENSION_HEIGHT, + DIMENSION_WIDTH, + DIMENSION_WIDTH, + }; + + private static final int[] leadingSpacing = { + Spacing.TOP, + Spacing.BOTTOM, + Spacing.START, + Spacing.START + }; + + private static final int[] trailingSpacing = { + Spacing.BOTTOM, + Spacing.TOP, + Spacing.END, + Spacing.END + }; + + private static float boundAxis(CSSNode node, int axis, float value) { + float min = CSSConstants.UNDEFINED; + float max = CSSConstants.UNDEFINED; + + if (axis == CSS_FLEX_DIRECTION_COLUMN || + axis == CSS_FLEX_DIRECTION_COLUMN_REVERSE) { + min = node.style.minHeight; + max = node.style.maxHeight; + } else if (axis == CSS_FLEX_DIRECTION_ROW || + axis == CSS_FLEX_DIRECTION_ROW_REVERSE) { + min = node.style.minWidth; + max = node.style.maxWidth; + } + + float boundValue = value; + + if (!Float.isNaN(max) && max >= 0.0 && boundValue > max) { + boundValue = max; + } + if (!Float.isNaN(min) && min >= 0.0 && boundValue < min) { + boundValue = min; + } + + return boundValue; + } + + private static void setDimensionFromStyle(CSSNode node, int axis) { + // The parent already computed us a width or height. We just skip it + if (!Float.isNaN(node.layout.dimensions[dim[axis]])) { + return; + } + // We only run if there's a width or height defined + if (Float.isNaN(node.style.dimensions[dim[axis]]) || + node.style.dimensions[dim[axis]] <= 0.0) { + return; + } + + // The dimensions can never be smaller than the padding and border + float maxLayoutDimension = Math.max( + boundAxis(node, axis, node.style.dimensions[dim[axis]]), + node.style.padding.getWithFallback(leadingSpacing[axis], leading[axis]) + + node.style.padding.getWithFallback(trailingSpacing[axis], trailing[axis]) + + node.style.border.getWithFallback(leadingSpacing[axis], leading[axis]) + + node.style.border.getWithFallback(trailingSpacing[axis], trailing[axis])); + node.layout.dimensions[dim[axis]] = maxLayoutDimension; + } + + private static float getRelativePosition(CSSNode node, int axis) { + float lead = node.style.position[leading[axis]]; + if (!Float.isNaN(lead)) { + return lead; + } + + float trailingPos = node.style.position[trailing[axis]]; + return Float.isNaN(trailingPos) ? 0 : -trailingPos; + } + + private static int resolveAxis( + int axis, + CSSDirection direction) { + if (direction == CSSDirection.RTL) { + if (axis == CSS_FLEX_DIRECTION_ROW) { + return CSS_FLEX_DIRECTION_ROW_REVERSE; + } else if (axis == CSS_FLEX_DIRECTION_ROW_REVERSE) { + return CSS_FLEX_DIRECTION_ROW; + } + } + + return axis; + } + + private static CSSDirection resolveDirection(CSSNode node, CSSDirection parentDirection) { + CSSDirection direction = node.style.direction; + if (direction == CSSDirection.INHERIT) { + direction = (parentDirection == null ? CSSDirection.LTR : parentDirection); + } + + return direction; + } + + private static int getFlexDirection(CSSNode node) { + return node.style.flexDirection.ordinal(); + } + + private static int getCrossFlexDirection( + int axis, + CSSDirection direction) { + if (axis == CSS_FLEX_DIRECTION_COLUMN || + axis == CSS_FLEX_DIRECTION_COLUMN_REVERSE) { + return resolveAxis(CSS_FLEX_DIRECTION_ROW, direction); + } else { + return CSS_FLEX_DIRECTION_COLUMN; + } + } + + private static CSSAlign getAlignItem(CSSNode node, CSSNode child) { + if (child.style.alignSelf != CSSAlign.AUTO) { + return child.style.alignSelf; + } + return node.style.alignItems; + } + + private static boolean isMeasureDefined(CSSNode node) { + return node.isMeasureDefined(); + } + + static boolean needsRelayout(CSSNode node, float parentMaxWidth, float parentMaxHeight) { + return node.isDirty() || + !FloatUtil.floatsEqual( + node.lastLayout.requestedHeight, + node.layout.dimensions[DIMENSION_HEIGHT]) || + !FloatUtil.floatsEqual( + node.lastLayout.requestedWidth, + node.layout.dimensions[DIMENSION_WIDTH]) || + !FloatUtil.floatsEqual(node.lastLayout.parentMaxWidth, parentMaxWidth) || + !FloatUtil.floatsEqual(node.lastLayout.parentMaxHeight, parentMaxHeight); + } + + /*package*/ static void layoutNode( + CSSLayoutContext layoutContext, + CSSNode node, + float parentMaxWidth, + float parentMaxHeight, + CSSDirection parentDirection) { + if (needsRelayout(node, parentMaxWidth, parentMaxHeight)) { + node.lastLayout.requestedWidth = node.layout.dimensions[DIMENSION_WIDTH]; + node.lastLayout.requestedHeight = node.layout.dimensions[DIMENSION_HEIGHT]; + node.lastLayout.parentMaxWidth = parentMaxWidth; + node.lastLayout.parentMaxHeight = parentMaxHeight; + + layoutNodeImpl(layoutContext, node, parentMaxWidth, parentMaxHeight, parentDirection); + node.lastLayout.copy(node.layout); + } else { + node.layout.copy(node.lastLayout); + } + + node.markHasNewLayout(); + } + + private static void layoutNodeImpl( + CSSLayoutContext layoutContext, + CSSNode node, + float parentMaxWidth, + float parentMaxHeight, + CSSDirection parentDirection) { + for (int i = 0, childCount = node.getChildCount(); i < childCount; i++) { + node.getChildAt(i).layout.resetResult(); + } + + /** START_GENERATED **/ + + CSSDirection direction = resolveDirection(node, parentDirection); + int mainAxis = resolveAxis(getFlexDirection(node), direction); + int crossAxis = getCrossFlexDirection(mainAxis, direction); + int resolvedRowAxis = resolveAxis(CSS_FLEX_DIRECTION_ROW, direction); + + // Handle width and height style attributes + setDimensionFromStyle(node, mainAxis); + setDimensionFromStyle(node, crossAxis); + + // Set the resolved resolution in the node's layout + node.layout.direction = direction; + + // The position is set by the parent, but we need to complete it with a + // delta composed of the margin and left/top/right/bottom + node.layout.position[leading[mainAxis]] += node.style.margin.getWithFallback(leadingSpacing[mainAxis], leading[mainAxis]) + + getRelativePosition(node, mainAxis); + node.layout.position[trailing[mainAxis]] += node.style.margin.getWithFallback(trailingSpacing[mainAxis], trailing[mainAxis]) + + getRelativePosition(node, mainAxis); + node.layout.position[leading[crossAxis]] += node.style.margin.getWithFallback(leadingSpacing[crossAxis], leading[crossAxis]) + + getRelativePosition(node, crossAxis); + node.layout.position[trailing[crossAxis]] += node.style.margin.getWithFallback(trailingSpacing[crossAxis], trailing[crossAxis]) + + getRelativePosition(node, crossAxis); + + // Inline immutable values from the target node to avoid excessive method + // invocations during the layout calculation. + int childCount = node.getChildCount(); + float paddingAndBorderAxisResolvedRow = ((node.style.padding.getWithFallback(leadingSpacing[resolvedRowAxis], leading[resolvedRowAxis]) + node.style.border.getWithFallback(leadingSpacing[resolvedRowAxis], leading[resolvedRowAxis])) + (node.style.padding.getWithFallback(trailingSpacing[resolvedRowAxis], trailing[resolvedRowAxis]) + node.style.border.getWithFallback(trailingSpacing[resolvedRowAxis], trailing[resolvedRowAxis]))); + float paddingAndBorderAxisColumn = ((node.style.padding.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_COLUMN], leading[CSS_FLEX_DIRECTION_COLUMN]) + node.style.border.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_COLUMN], leading[CSS_FLEX_DIRECTION_COLUMN])) + (node.style.padding.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_COLUMN], trailing[CSS_FLEX_DIRECTION_COLUMN]) + node.style.border.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_COLUMN], trailing[CSS_FLEX_DIRECTION_COLUMN]))); + + if (isMeasureDefined(node)) { + boolean isResolvedRowDimDefined = (!Float.isNaN(node.layout.dimensions[dim[resolvedRowAxis]]) && node.layout.dimensions[dim[resolvedRowAxis]] >= 0.0); + + float width = CSSConstants.UNDEFINED; + if ((!Float.isNaN(node.style.dimensions[dim[resolvedRowAxis]]) && node.style.dimensions[dim[resolvedRowAxis]] >= 0.0)) { + width = node.style.dimensions[DIMENSION_WIDTH]; + } else if (isResolvedRowDimDefined) { + width = node.layout.dimensions[dim[resolvedRowAxis]]; + } else { + width = parentMaxWidth - + (node.style.margin.getWithFallback(leadingSpacing[resolvedRowAxis], leading[resolvedRowAxis]) + node.style.margin.getWithFallback(trailingSpacing[resolvedRowAxis], trailing[resolvedRowAxis])); + } + width -= paddingAndBorderAxisResolvedRow; + + float height = CSSConstants.UNDEFINED; + if ((!Float.isNaN(node.style.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]]) && node.style.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]] >= 0.0)) { + height = node.style.dimensions[DIMENSION_HEIGHT]; + } else if ((!Float.isNaN(node.layout.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]]) && node.layout.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]] >= 0.0)) { + height = node.layout.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]]; + } else { + height = parentMaxHeight - + (node.style.margin.getWithFallback(leadingSpacing[resolvedRowAxis], leading[resolvedRowAxis]) + node.style.margin.getWithFallback(trailingSpacing[resolvedRowAxis], trailing[resolvedRowAxis])); + } + height -= ((node.style.padding.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_COLUMN], leading[CSS_FLEX_DIRECTION_COLUMN]) + node.style.border.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_COLUMN], leading[CSS_FLEX_DIRECTION_COLUMN])) + (node.style.padding.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_COLUMN], trailing[CSS_FLEX_DIRECTION_COLUMN]) + node.style.border.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_COLUMN], trailing[CSS_FLEX_DIRECTION_COLUMN]))); + + // We only need to give a dimension for the text if we haven't got any + // for it computed yet. It can either be from the style attribute or because + // the element is flexible. + boolean isRowUndefined = !(!Float.isNaN(node.style.dimensions[dim[resolvedRowAxis]]) && node.style.dimensions[dim[resolvedRowAxis]] >= 0.0) && !isResolvedRowDimDefined; + boolean isColumnUndefined = !(!Float.isNaN(node.style.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]]) && node.style.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]] >= 0.0) && + Float.isNaN(node.layout.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]]); + + // Let's not measure the text if we already know both dimensions + if (isRowUndefined || isColumnUndefined) { + MeasureOutput measureDim = node.measure( + + layoutContext.measureOutput, + width, + height + ); + if (isRowUndefined) { + node.layout.dimensions[DIMENSION_WIDTH] = measureDim.width + + paddingAndBorderAxisResolvedRow; + } + if (isColumnUndefined) { + node.layout.dimensions[DIMENSION_HEIGHT] = measureDim.height + + paddingAndBorderAxisColumn; + } + } + if (childCount == 0) { + return; + } + } + + boolean isNodeFlexWrap = (node.style.flexWrap == CSSWrap.WRAP); + + CSSJustify justifyContent = node.style.justifyContent; + + float leadingPaddingAndBorderMain = (node.style.padding.getWithFallback(leadingSpacing[mainAxis], leading[mainAxis]) + node.style.border.getWithFallback(leadingSpacing[mainAxis], leading[mainAxis])); + float leadingPaddingAndBorderCross = (node.style.padding.getWithFallback(leadingSpacing[crossAxis], leading[crossAxis]) + node.style.border.getWithFallback(leadingSpacing[crossAxis], leading[crossAxis])); + float paddingAndBorderAxisMain = ((node.style.padding.getWithFallback(leadingSpacing[mainAxis], leading[mainAxis]) + node.style.border.getWithFallback(leadingSpacing[mainAxis], leading[mainAxis])) + (node.style.padding.getWithFallback(trailingSpacing[mainAxis], trailing[mainAxis]) + node.style.border.getWithFallback(trailingSpacing[mainAxis], trailing[mainAxis]))); + float paddingAndBorderAxisCross = ((node.style.padding.getWithFallback(leadingSpacing[crossAxis], leading[crossAxis]) + node.style.border.getWithFallback(leadingSpacing[crossAxis], leading[crossAxis])) + (node.style.padding.getWithFallback(trailingSpacing[crossAxis], trailing[crossAxis]) + node.style.border.getWithFallback(trailingSpacing[crossAxis], trailing[crossAxis]))); + + boolean isMainDimDefined = (!Float.isNaN(node.layout.dimensions[dim[mainAxis]]) && node.layout.dimensions[dim[mainAxis]] >= 0.0); + boolean isCrossDimDefined = (!Float.isNaN(node.layout.dimensions[dim[crossAxis]]) && node.layout.dimensions[dim[crossAxis]] >= 0.0); + boolean isMainRowDirection = (mainAxis == CSS_FLEX_DIRECTION_ROW || mainAxis == CSS_FLEX_DIRECTION_ROW_REVERSE); + + int i; + int ii; + CSSNode child; + int axis; + + CSSNode firstAbsoluteChild = null; + CSSNode currentAbsoluteChild = null; + + float definedMainDim = CSSConstants.UNDEFINED; + if (isMainDimDefined) { + definedMainDim = node.layout.dimensions[dim[mainAxis]] - paddingAndBorderAxisMain; + } + + // We want to execute the next two loops one per line with flex-wrap + int startLine = 0; + int endLine = 0; + // int nextOffset = 0; + int alreadyComputedNextLayout = 0; + // We aggregate the total dimensions of the container in those two variables + float linesCrossDim = 0; + float linesMainDim = 0; + int linesCount = 0; + while (endLine < childCount) { + // Layout non flexible children and count children by type + + // mainContentDim is accumulation of the dimensions and margin of all the + // non flexible children. This will be used in order to either set the + // dimensions of the node if none already exist, or to compute the + // remaining space left for the flexible children. + float mainContentDim = 0; + + // There are three kind of children, non flexible, flexible and absolute. + // We need to know how many there are in order to distribute the space. + int flexibleChildrenCount = 0; + float totalFlexible = 0; + int nonFlexibleChildrenCount = 0; + + // Use the line loop to position children in the main axis for as long + // as they are using a simple stacking behaviour. Children that are + // immediately stacked in the initial loop will not be touched again + // in . + boolean isSimpleStackMain = + (isMainDimDefined && justifyContent == CSSJustify.FLEX_START) || + (!isMainDimDefined && justifyContent != CSSJustify.CENTER); + int firstComplexMain = (isSimpleStackMain ? childCount : startLine); + + // Use the initial line loop to position children in the cross axis for + // as long as they are relatively positioned with alignment STRETCH or + // FLEX_START. Children that are immediately stacked in the initial loop + // will not be touched again in . + boolean isSimpleStackCross = true; + int firstComplexCross = childCount; + + CSSNode firstFlexChild = null; + CSSNode currentFlexChild = null; + + float mainDim = leadingPaddingAndBorderMain; + float crossDim = 0; + + float maxWidth; + float maxHeight; + for (i = startLine; i < childCount; ++i) { + child = node.getChildAt(i); + child.lineIndex = linesCount; + + child.nextAbsoluteChild = null; + child.nextFlexChild = null; + + CSSAlign alignItem = getAlignItem(node, child); + + // Pre-fill cross axis dimensions when the child is using stretch before + // we call the recursive layout pass + if (alignItem == CSSAlign.STRETCH && + child.style.positionType == CSSPositionType.RELATIVE && + isCrossDimDefined && + !(!Float.isNaN(child.style.dimensions[dim[crossAxis]]) && child.style.dimensions[dim[crossAxis]] >= 0.0)) { + child.layout.dimensions[dim[crossAxis]] = Math.max( + boundAxis(child, crossAxis, node.layout.dimensions[dim[crossAxis]] - + paddingAndBorderAxisCross - (child.style.margin.getWithFallback(leadingSpacing[crossAxis], leading[crossAxis]) + child.style.margin.getWithFallback(trailingSpacing[crossAxis], trailing[crossAxis]))), + // You never want to go smaller than padding + ((child.style.padding.getWithFallback(leadingSpacing[crossAxis], leading[crossAxis]) + child.style.border.getWithFallback(leadingSpacing[crossAxis], leading[crossAxis])) + (child.style.padding.getWithFallback(trailingSpacing[crossAxis], trailing[crossAxis]) + child.style.border.getWithFallback(trailingSpacing[crossAxis], trailing[crossAxis]))) + ); + } else if (child.style.positionType == CSSPositionType.ABSOLUTE) { + // Store a private linked list of absolutely positioned children + // so that we can efficiently traverse them later. + if (firstAbsoluteChild == null) { + firstAbsoluteChild = child; + } + if (currentAbsoluteChild != null) { + currentAbsoluteChild.nextAbsoluteChild = child; + } + currentAbsoluteChild = child; + + // Pre-fill dimensions when using absolute position and both offsets for the axis are defined (either both + // left and right or top and bottom). + for (ii = 0; ii < 2; ii++) { + axis = (ii != 0) ? CSS_FLEX_DIRECTION_ROW : CSS_FLEX_DIRECTION_COLUMN; + if ((!Float.isNaN(node.layout.dimensions[dim[axis]]) && node.layout.dimensions[dim[axis]] >= 0.0) && + !(!Float.isNaN(child.style.dimensions[dim[axis]]) && child.style.dimensions[dim[axis]] >= 0.0) && + !Float.isNaN(child.style.position[leading[axis]]) && + !Float.isNaN(child.style.position[trailing[axis]])) { + child.layout.dimensions[dim[axis]] = Math.max( + boundAxis(child, axis, node.layout.dimensions[dim[axis]] - + ((node.style.padding.getWithFallback(leadingSpacing[axis], leading[axis]) + node.style.border.getWithFallback(leadingSpacing[axis], leading[axis])) + (node.style.padding.getWithFallback(trailingSpacing[axis], trailing[axis]) + node.style.border.getWithFallback(trailingSpacing[axis], trailing[axis]))) - + (child.style.margin.getWithFallback(leadingSpacing[axis], leading[axis]) + child.style.margin.getWithFallback(trailingSpacing[axis], trailing[axis])) - + (Float.isNaN(child.style.position[leading[axis]]) ? 0 : child.style.position[leading[axis]]) - + (Float.isNaN(child.style.position[trailing[axis]]) ? 0 : child.style.position[trailing[axis]])), + // You never want to go smaller than padding + ((child.style.padding.getWithFallback(leadingSpacing[axis], leading[axis]) + child.style.border.getWithFallback(leadingSpacing[axis], leading[axis])) + (child.style.padding.getWithFallback(trailingSpacing[axis], trailing[axis]) + child.style.border.getWithFallback(trailingSpacing[axis], trailing[axis]))) + ); + } + } + } + + float nextContentDim = 0; + + // It only makes sense to consider a child flexible if we have a computed + // dimension for the node. + if (isMainDimDefined && (child.style.positionType == CSSPositionType.RELATIVE && child.style.flex > 0)) { + flexibleChildrenCount++; + totalFlexible += child.style.flex; + + // Store a private linked list of flexible children so that we can + // efficiently traverse them later. + if (firstFlexChild == null) { + firstFlexChild = child; + } + if (currentFlexChild != null) { + currentFlexChild.nextFlexChild = child; + } + currentFlexChild = child; + + // Even if we don't know its exact size yet, we already know the padding, + // border and margin. We'll use this partial information, which represents + // the smallest possible size for the child, to compute the remaining + // available space. + nextContentDim = ((child.style.padding.getWithFallback(leadingSpacing[mainAxis], leading[mainAxis]) + child.style.border.getWithFallback(leadingSpacing[mainAxis], leading[mainAxis])) + (child.style.padding.getWithFallback(trailingSpacing[mainAxis], trailing[mainAxis]) + child.style.border.getWithFallback(trailingSpacing[mainAxis], trailing[mainAxis]))) + + (child.style.margin.getWithFallback(leadingSpacing[mainAxis], leading[mainAxis]) + child.style.margin.getWithFallback(trailingSpacing[mainAxis], trailing[mainAxis])); + + } else { + maxWidth = CSSConstants.UNDEFINED; + maxHeight = CSSConstants.UNDEFINED; + + if (!isMainRowDirection) { + if ((!Float.isNaN(node.layout.dimensions[dim[resolvedRowAxis]]) && node.layout.dimensions[dim[resolvedRowAxis]] >= 0.0)) { + maxWidth = node.layout.dimensions[dim[resolvedRowAxis]] - + paddingAndBorderAxisResolvedRow; + } else { + maxWidth = parentMaxWidth - + (node.style.margin.getWithFallback(leadingSpacing[resolvedRowAxis], leading[resolvedRowAxis]) + node.style.margin.getWithFallback(trailingSpacing[resolvedRowAxis], trailing[resolvedRowAxis])) - + paddingAndBorderAxisResolvedRow; + } + } else { + if ((!Float.isNaN(node.layout.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]]) && node.layout.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]] >= 0.0)) { + maxHeight = node.layout.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]] - + paddingAndBorderAxisColumn; + } else { + maxHeight = parentMaxHeight - + (node.style.margin.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_COLUMN], leading[CSS_FLEX_DIRECTION_COLUMN]) + node.style.margin.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_COLUMN], trailing[CSS_FLEX_DIRECTION_COLUMN])) - + paddingAndBorderAxisColumn; + } + } + + // This is the main recursive call. We layout non flexible children. + if (alreadyComputedNextLayout == 0) { + layoutNode(layoutContext, child, maxWidth, maxHeight, direction); + } + + // Absolute positioned elements do not take part of the layout, so we + // don't use them to compute mainContentDim + if (child.style.positionType == CSSPositionType.RELATIVE) { + nonFlexibleChildrenCount++; + // At this point we know the final size and margin of the element. + nextContentDim = (child.layout.dimensions[dim[mainAxis]] + child.style.margin.getWithFallback(leadingSpacing[mainAxis], leading[mainAxis]) + child.style.margin.getWithFallback(trailingSpacing[mainAxis], trailing[mainAxis])); + } + } + + // The element we are about to add would make us go to the next line + if (isNodeFlexWrap && + isMainDimDefined && + mainContentDim + nextContentDim > definedMainDim && + // If there's only one element, then it's bigger than the content + // and needs its own line + i != startLine) { + nonFlexibleChildrenCount--; + alreadyComputedNextLayout = 1; + break; + } + + // Disable simple stacking in the main axis for the current line as + // we found a non-trivial child. The remaining children will be laid out + // in . + if (isSimpleStackMain && + (child.style.positionType != CSSPositionType.RELATIVE || (child.style.positionType == CSSPositionType.RELATIVE && child.style.flex > 0))) { + isSimpleStackMain = false; + firstComplexMain = i; + } + + // Disable simple stacking in the cross axis for the current line as + // we found a non-trivial child. The remaining children will be laid out + // in . + if (isSimpleStackCross && + (child.style.positionType != CSSPositionType.RELATIVE || + (alignItem != CSSAlign.STRETCH && alignItem != CSSAlign.FLEX_START) || + !(!Float.isNaN(child.layout.dimensions[dim[crossAxis]]) && child.layout.dimensions[dim[crossAxis]] >= 0.0))) { + isSimpleStackCross = false; + firstComplexCross = i; + } + + if (isSimpleStackMain) { + child.layout.position[pos[mainAxis]] += mainDim; + if (isMainDimDefined) { + child.layout.position[trailing[mainAxis]] = node.layout.dimensions[dim[mainAxis]] - child.layout.dimensions[dim[mainAxis]] - child.layout.position[pos[mainAxis]]; + } + + mainDim += (child.layout.dimensions[dim[mainAxis]] + child.style.margin.getWithFallback(leadingSpacing[mainAxis], leading[mainAxis]) + child.style.margin.getWithFallback(trailingSpacing[mainAxis], trailing[mainAxis])); + crossDim = Math.max(crossDim, boundAxis(child, crossAxis, (child.layout.dimensions[dim[crossAxis]] + child.style.margin.getWithFallback(leadingSpacing[crossAxis], leading[crossAxis]) + child.style.margin.getWithFallback(trailingSpacing[crossAxis], trailing[crossAxis])))); + } + + if (isSimpleStackCross) { + child.layout.position[pos[crossAxis]] += linesCrossDim + leadingPaddingAndBorderCross; + if (isCrossDimDefined) { + child.layout.position[trailing[crossAxis]] = node.layout.dimensions[dim[crossAxis]] - child.layout.dimensions[dim[crossAxis]] - child.layout.position[pos[crossAxis]]; + } + } + + alreadyComputedNextLayout = 0; + mainContentDim += nextContentDim; + endLine = i + 1; + } + + // Layout flexible children and allocate empty space + + // In order to position the elements in the main axis, we have two + // controls. The space between the beginning and the first element + // and the space between each two elements. + float leadingMainDim = 0; + float betweenMainDim = 0; + + // The remaining available space that needs to be allocated + float remainingMainDim = 0; + if (isMainDimDefined) { + remainingMainDim = definedMainDim - mainContentDim; + } else { + remainingMainDim = Math.max(mainContentDim, 0) - mainContentDim; + } + + // If there are flexible children in the mix, they are going to fill the + // remaining space + if (flexibleChildrenCount != 0) { + float flexibleMainDim = remainingMainDim / totalFlexible; + float baseMainDim; + float boundMainDim; + + // If the flex share of remaining space doesn't meet min/max bounds, + // remove this child from flex calculations. + currentFlexChild = firstFlexChild; + while (currentFlexChild != null) { + baseMainDim = flexibleMainDim * currentFlexChild.style.flex + + ((currentFlexChild.style.padding.getWithFallback(leadingSpacing[mainAxis], leading[mainAxis]) + currentFlexChild.style.border.getWithFallback(leadingSpacing[mainAxis], leading[mainAxis])) + (currentFlexChild.style.padding.getWithFallback(trailingSpacing[mainAxis], trailing[mainAxis]) + currentFlexChild.style.border.getWithFallback(trailingSpacing[mainAxis], trailing[mainAxis]))); + boundMainDim = boundAxis(currentFlexChild, mainAxis, baseMainDim); + + if (baseMainDim != boundMainDim) { + remainingMainDim -= boundMainDim; + totalFlexible -= currentFlexChild.style.flex; + } + + currentFlexChild = currentFlexChild.nextFlexChild; + } + flexibleMainDim = remainingMainDim / totalFlexible; + + // The non flexible children can overflow the container, in this case + // we should just assume that there is no space available. + if (flexibleMainDim < 0) { + flexibleMainDim = 0; + } + + currentFlexChild = firstFlexChild; + while (currentFlexChild != null) { + // At this point we know the final size of the element in the main + // dimension + currentFlexChild.layout.dimensions[dim[mainAxis]] = boundAxis(currentFlexChild, mainAxis, + flexibleMainDim * currentFlexChild.style.flex + + ((currentFlexChild.style.padding.getWithFallback(leadingSpacing[mainAxis], leading[mainAxis]) + currentFlexChild.style.border.getWithFallback(leadingSpacing[mainAxis], leading[mainAxis])) + (currentFlexChild.style.padding.getWithFallback(trailingSpacing[mainAxis], trailing[mainAxis]) + currentFlexChild.style.border.getWithFallback(trailingSpacing[mainAxis], trailing[mainAxis]))) + ); + + maxWidth = CSSConstants.UNDEFINED; + if ((!Float.isNaN(node.layout.dimensions[dim[resolvedRowAxis]]) && node.layout.dimensions[dim[resolvedRowAxis]] >= 0.0)) { + maxWidth = node.layout.dimensions[dim[resolvedRowAxis]] - + paddingAndBorderAxisResolvedRow; + } else if (!isMainRowDirection) { + maxWidth = parentMaxWidth - + (node.style.margin.getWithFallback(leadingSpacing[resolvedRowAxis], leading[resolvedRowAxis]) + node.style.margin.getWithFallback(trailingSpacing[resolvedRowAxis], trailing[resolvedRowAxis])) - + paddingAndBorderAxisResolvedRow; + } + maxHeight = CSSConstants.UNDEFINED; + if ((!Float.isNaN(node.layout.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]]) && node.layout.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]] >= 0.0)) { + maxHeight = node.layout.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]] - + paddingAndBorderAxisColumn; + } else if (isMainRowDirection) { + maxHeight = parentMaxHeight - + (node.style.margin.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_COLUMN], leading[CSS_FLEX_DIRECTION_COLUMN]) + node.style.margin.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_COLUMN], trailing[CSS_FLEX_DIRECTION_COLUMN])) - + paddingAndBorderAxisColumn; + } + + // And we recursively call the layout algorithm for this child + layoutNode(layoutContext, currentFlexChild, maxWidth, maxHeight, direction); + + child = currentFlexChild; + currentFlexChild = currentFlexChild.nextFlexChild; + child.nextFlexChild = null; + } + + // We use justifyContent to figure out how to allocate the remaining + // space available + } else if (justifyContent != CSSJustify.FLEX_START) { + if (justifyContent == CSSJustify.CENTER) { + leadingMainDim = remainingMainDim / 2; + } else if (justifyContent == CSSJustify.FLEX_END) { + leadingMainDim = remainingMainDim; + } else if (justifyContent == CSSJustify.SPACE_BETWEEN) { + remainingMainDim = Math.max(remainingMainDim, 0); + if (flexibleChildrenCount + nonFlexibleChildrenCount - 1 != 0) { + betweenMainDim = remainingMainDim / + (flexibleChildrenCount + nonFlexibleChildrenCount - 1); + } else { + betweenMainDim = 0; + } + } else if (justifyContent == CSSJustify.SPACE_AROUND) { + // Space on the edges is half of the space between elements + betweenMainDim = remainingMainDim / + (flexibleChildrenCount + nonFlexibleChildrenCount); + leadingMainDim = betweenMainDim / 2; + } + } + + // Position elements in the main axis and compute dimensions + + // At this point, all the children have their dimensions set. We need to + // find their position. In order to do that, we accumulate data in + // variables that are also useful to compute the total dimensions of the + // container! + mainDim += leadingMainDim; + + for (i = firstComplexMain; i < endLine; ++i) { + child = node.getChildAt(i); + + if (child.style.positionType == CSSPositionType.ABSOLUTE && + !Float.isNaN(child.style.position[leading[mainAxis]])) { + // In case the child is position absolute and has left/top being + // defined, we override the position to whatever the user said + // (and margin/border). + child.layout.position[pos[mainAxis]] = (Float.isNaN(child.style.position[leading[mainAxis]]) ? 0 : child.style.position[leading[mainAxis]]) + + node.style.border.getWithFallback(leadingSpacing[mainAxis], leading[mainAxis]) + + child.style.margin.getWithFallback(leadingSpacing[mainAxis], leading[mainAxis]); + } else { + // If the child is position absolute (without top/left) or relative, + // we put it at the current accumulated offset. + child.layout.position[pos[mainAxis]] += mainDim; + + // Define the trailing position accordingly. + if (isMainDimDefined) { + child.layout.position[trailing[mainAxis]] = node.layout.dimensions[dim[mainAxis]] - child.layout.dimensions[dim[mainAxis]] - child.layout.position[pos[mainAxis]]; + } + + // Now that we placed the element, we need to update the variables + // We only need to do that for relative elements. Absolute elements + // do not take part in that phase. + if (child.style.positionType == CSSPositionType.RELATIVE) { + // The main dimension is the sum of all the elements dimension plus + // the spacing. + mainDim += betweenMainDim + (child.layout.dimensions[dim[mainAxis]] + child.style.margin.getWithFallback(leadingSpacing[mainAxis], leading[mainAxis]) + child.style.margin.getWithFallback(trailingSpacing[mainAxis], trailing[mainAxis])); + // The cross dimension is the max of the elements dimension since there + // can only be one element in that cross dimension. + crossDim = Math.max(crossDim, boundAxis(child, crossAxis, (child.layout.dimensions[dim[crossAxis]] + child.style.margin.getWithFallback(leadingSpacing[crossAxis], leading[crossAxis]) + child.style.margin.getWithFallback(trailingSpacing[crossAxis], trailing[crossAxis])))); + } + } + } + + float containerCrossAxis = node.layout.dimensions[dim[crossAxis]]; + if (!isCrossDimDefined) { + containerCrossAxis = Math.max( + // For the cross dim, we add both sides at the end because the value + // is aggregate via a max function. Intermediate negative values + // can mess this computation otherwise + boundAxis(node, crossAxis, crossDim + paddingAndBorderAxisCross), + paddingAndBorderAxisCross + ); + } + + // Position elements in the cross axis + for (i = firstComplexCross; i < endLine; ++i) { + child = node.getChildAt(i); + + if (child.style.positionType == CSSPositionType.ABSOLUTE && + !Float.isNaN(child.style.position[leading[crossAxis]])) { + // In case the child is absolutely positionned and has a + // top/left/bottom/right being set, we override all the previously + // computed positions to set it correctly. + child.layout.position[pos[crossAxis]] = (Float.isNaN(child.style.position[leading[crossAxis]]) ? 0 : child.style.position[leading[crossAxis]]) + + node.style.border.getWithFallback(leadingSpacing[crossAxis], leading[crossAxis]) + + child.style.margin.getWithFallback(leadingSpacing[crossAxis], leading[crossAxis]); + + } else { + float leadingCrossDim = leadingPaddingAndBorderCross; + + // For a relative children, we're either using alignItems (parent) or + // alignSelf (child) in order to determine the position in the cross axis + if (child.style.positionType == CSSPositionType.RELATIVE) { + /*eslint-disable */ + // This variable is intentionally re-defined as the code is transpiled to a block scope language + CSSAlign alignItem = getAlignItem(node, child); + /*eslint-enable */ + if (alignItem == CSSAlign.STRETCH) { + // You can only stretch if the dimension has not already been set + // previously. + if (!(!Float.isNaN(child.layout.dimensions[dim[crossAxis]]) && child.layout.dimensions[dim[crossAxis]] >= 0.0)) { + child.layout.dimensions[dim[crossAxis]] = Math.max( + boundAxis(child, crossAxis, containerCrossAxis - + paddingAndBorderAxisCross - (child.style.margin.getWithFallback(leadingSpacing[crossAxis], leading[crossAxis]) + child.style.margin.getWithFallback(trailingSpacing[crossAxis], trailing[crossAxis]))), + // You never want to go smaller than padding + ((child.style.padding.getWithFallback(leadingSpacing[crossAxis], leading[crossAxis]) + child.style.border.getWithFallback(leadingSpacing[crossAxis], leading[crossAxis])) + (child.style.padding.getWithFallback(trailingSpacing[crossAxis], trailing[crossAxis]) + child.style.border.getWithFallback(trailingSpacing[crossAxis], trailing[crossAxis]))) + ); + } + } else if (alignItem != CSSAlign.FLEX_START) { + // The remaining space between the parent dimensions+padding and child + // dimensions+margin. + float remainingCrossDim = containerCrossAxis - + paddingAndBorderAxisCross - (child.layout.dimensions[dim[crossAxis]] + child.style.margin.getWithFallback(leadingSpacing[crossAxis], leading[crossAxis]) + child.style.margin.getWithFallback(trailingSpacing[crossAxis], trailing[crossAxis])); + + if (alignItem == CSSAlign.CENTER) { + leadingCrossDim += remainingCrossDim / 2; + } else { // CSSAlign.FLEX_END + leadingCrossDim += remainingCrossDim; + } + } + } + + // And we apply the position + child.layout.position[pos[crossAxis]] += linesCrossDim + leadingCrossDim; + + // Define the trailing position accordingly. + if (isCrossDimDefined) { + child.layout.position[trailing[crossAxis]] = node.layout.dimensions[dim[crossAxis]] - child.layout.dimensions[dim[crossAxis]] - child.layout.position[pos[crossAxis]]; + } + } + } + + linesCrossDim += crossDim; + linesMainDim = Math.max(linesMainDim, mainDim); + linesCount += 1; + startLine = endLine; + } + + // + // + // Note(prenaux): More than one line, we need to layout the crossAxis + // according to alignContent. + // + // Note that we could probably remove and handle the one line case + // here too, but for the moment this is safer since it won't interfere with + // previously working code. + // + // See specs: + // http://www.w3.org/TR/2012/CR-css3-flexbox-20120918/#layout-algorithm + // section 9.4 + // + if (linesCount > 1 && isCrossDimDefined) { + float nodeCrossAxisInnerSize = node.layout.dimensions[dim[crossAxis]] - + paddingAndBorderAxisCross; + float remainingAlignContentDim = nodeCrossAxisInnerSize - linesCrossDim; + + float crossDimLead = 0; + float currentLead = leadingPaddingAndBorderCross; + + CSSAlign alignContent = node.style.alignContent; + if (alignContent == CSSAlign.FLEX_END) { + currentLead += remainingAlignContentDim; + } else if (alignContent == CSSAlign.CENTER) { + currentLead += remainingAlignContentDim / 2; + } else if (alignContent == CSSAlign.STRETCH) { + if (nodeCrossAxisInnerSize > linesCrossDim) { + crossDimLead = (remainingAlignContentDim / linesCount); + } + } + + int endIndex = 0; + for (i = 0; i < linesCount; ++i) { + int startIndex = endIndex; + + // compute the line's height and find the endIndex + float lineHeight = 0; + for (ii = startIndex; ii < childCount; ++ii) { + child = node.getChildAt(ii); + if (child.style.positionType != CSSPositionType.RELATIVE) { + continue; + } + if (child.lineIndex != i) { + break; + } + if ((!Float.isNaN(child.layout.dimensions[dim[crossAxis]]) && child.layout.dimensions[dim[crossAxis]] >= 0.0)) { + lineHeight = Math.max( + lineHeight, + child.layout.dimensions[dim[crossAxis]] + (child.style.margin.getWithFallback(leadingSpacing[crossAxis], leading[crossAxis]) + child.style.margin.getWithFallback(trailingSpacing[crossAxis], trailing[crossAxis])) + ); + } + } + endIndex = ii; + lineHeight += crossDimLead; + + for (ii = startIndex; ii < endIndex; ++ii) { + child = node.getChildAt(ii); + if (child.style.positionType != CSSPositionType.RELATIVE) { + continue; + } + + CSSAlign alignContentAlignItem = getAlignItem(node, child); + if (alignContentAlignItem == CSSAlign.FLEX_START) { + child.layout.position[pos[crossAxis]] = currentLead + child.style.margin.getWithFallback(leadingSpacing[crossAxis], leading[crossAxis]); + } else if (alignContentAlignItem == CSSAlign.FLEX_END) { + child.layout.position[pos[crossAxis]] = currentLead + lineHeight - child.style.margin.getWithFallback(trailingSpacing[crossAxis], trailing[crossAxis]) - child.layout.dimensions[dim[crossAxis]]; + } else if (alignContentAlignItem == CSSAlign.CENTER) { + float childHeight = child.layout.dimensions[dim[crossAxis]]; + child.layout.position[pos[crossAxis]] = currentLead + (lineHeight - childHeight) / 2; + } else if (alignContentAlignItem == CSSAlign.STRETCH) { + child.layout.position[pos[crossAxis]] = currentLead + child.style.margin.getWithFallback(leadingSpacing[crossAxis], leading[crossAxis]); + // TODO(prenaux): Correctly set the height of items with undefined + // (auto) crossAxis dimension. + } + } + + currentLead += lineHeight; + } + } + + boolean needsMainTrailingPos = false; + boolean needsCrossTrailingPos = false; + + // If the user didn't specify a width or height, and it has not been set + // by the container, then we set it via the children. + if (!isMainDimDefined) { + node.layout.dimensions[dim[mainAxis]] = Math.max( + // We're missing the last padding at this point to get the final + // dimension + boundAxis(node, mainAxis, linesMainDim + (node.style.padding.getWithFallback(trailingSpacing[mainAxis], trailing[mainAxis]) + node.style.border.getWithFallback(trailingSpacing[mainAxis], trailing[mainAxis]))), + // We can never assign a width smaller than the padding and borders + paddingAndBorderAxisMain + ); + + if (mainAxis == CSS_FLEX_DIRECTION_ROW_REVERSE || + mainAxis == CSS_FLEX_DIRECTION_COLUMN_REVERSE) { + needsMainTrailingPos = true; + } + } + + if (!isCrossDimDefined) { + node.layout.dimensions[dim[crossAxis]] = Math.max( + // For the cross dim, we add both sides at the end because the value + // is aggregate via a max function. Intermediate negative values + // can mess this computation otherwise + boundAxis(node, crossAxis, linesCrossDim + paddingAndBorderAxisCross), + paddingAndBorderAxisCross + ); + + if (crossAxis == CSS_FLEX_DIRECTION_ROW_REVERSE || + crossAxis == CSS_FLEX_DIRECTION_COLUMN_REVERSE) { + needsCrossTrailingPos = true; + } + } + + // Set trailing position if necessary + if (needsMainTrailingPos || needsCrossTrailingPos) { + for (i = 0; i < childCount; ++i) { + child = node.getChildAt(i); + + if (needsMainTrailingPos) { + child.layout.position[trailing[mainAxis]] = node.layout.dimensions[dim[mainAxis]] - child.layout.dimensions[dim[mainAxis]] - child.layout.position[pos[mainAxis]]; + } + + if (needsCrossTrailingPos) { + child.layout.position[trailing[crossAxis]] = node.layout.dimensions[dim[crossAxis]] - child.layout.dimensions[dim[crossAxis]] - child.layout.position[pos[crossAxis]]; + } + } + } + + // Calculate dimensions for absolutely positioned elements + currentAbsoluteChild = firstAbsoluteChild; + while (currentAbsoluteChild != null) { + // Pre-fill dimensions when using absolute position and both offsets for + // the axis are defined (either both left and right or top and bottom). + for (ii = 0; ii < 2; ii++) { + axis = (ii != 0) ? CSS_FLEX_DIRECTION_ROW : CSS_FLEX_DIRECTION_COLUMN; + + if ((!Float.isNaN(node.layout.dimensions[dim[axis]]) && node.layout.dimensions[dim[axis]] >= 0.0) && + !(!Float.isNaN(currentAbsoluteChild.style.dimensions[dim[axis]]) && currentAbsoluteChild.style.dimensions[dim[axis]] >= 0.0) && + !Float.isNaN(currentAbsoluteChild.style.position[leading[axis]]) && + !Float.isNaN(currentAbsoluteChild.style.position[trailing[axis]])) { + currentAbsoluteChild.layout.dimensions[dim[axis]] = Math.max( + boundAxis(currentAbsoluteChild, axis, node.layout.dimensions[dim[axis]] - + (node.style.border.getWithFallback(leadingSpacing[axis], leading[axis]) + node.style.border.getWithFallback(trailingSpacing[axis], trailing[axis])) - + (currentAbsoluteChild.style.margin.getWithFallback(leadingSpacing[axis], leading[axis]) + currentAbsoluteChild.style.margin.getWithFallback(trailingSpacing[axis], trailing[axis])) - + (Float.isNaN(currentAbsoluteChild.style.position[leading[axis]]) ? 0 : currentAbsoluteChild.style.position[leading[axis]]) - + (Float.isNaN(currentAbsoluteChild.style.position[trailing[axis]]) ? 0 : currentAbsoluteChild.style.position[trailing[axis]]) + ), + // You never want to go smaller than padding + ((currentAbsoluteChild.style.padding.getWithFallback(leadingSpacing[axis], leading[axis]) + currentAbsoluteChild.style.border.getWithFallback(leadingSpacing[axis], leading[axis])) + (currentAbsoluteChild.style.padding.getWithFallback(trailingSpacing[axis], trailing[axis]) + currentAbsoluteChild.style.border.getWithFallback(trailingSpacing[axis], trailing[axis]))) + ); + } + + if (!Float.isNaN(currentAbsoluteChild.style.position[trailing[axis]]) && + !!Float.isNaN(currentAbsoluteChild.style.position[leading[axis]])) { + currentAbsoluteChild.layout.position[leading[axis]] = + node.layout.dimensions[dim[axis]] - + currentAbsoluteChild.layout.dimensions[dim[axis]] - + (Float.isNaN(currentAbsoluteChild.style.position[trailing[axis]]) ? 0 : currentAbsoluteChild.style.position[trailing[axis]]); + } + } + + child = currentAbsoluteChild; + currentAbsoluteChild = currentAbsoluteChild.nextAbsoluteChild; + child.nextAbsoluteChild = null; + } + } + /** END_GENERATED **/ +} diff --git a/Android/LuaViewSDK/src/com/facebook/csslayout/MeasureOutput.java b/Android/LuaViewSDK/src/com/facebook/csslayout/MeasureOutput.java new file mode 100644 index 00000000..3efa1f2e --- /dev/null +++ b/Android/LuaViewSDK/src/com/facebook/csslayout/MeasureOutput.java @@ -0,0 +1,18 @@ +/** + * Copyright (c) 2014, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ +package com.facebook.csslayout; + +/** + * POJO to hold the output of the measure function. + */ +public class MeasureOutput { + + public float width; + public float height; +} diff --git a/Android/LuaViewSDK/src/com/facebook/csslayout/Spacing.java b/Android/LuaViewSDK/src/com/facebook/csslayout/Spacing.java new file mode 100644 index 00000000..3a68b0fb --- /dev/null +++ b/Android/LuaViewSDK/src/com/facebook/csslayout/Spacing.java @@ -0,0 +1,220 @@ +/** + * Copyright (c) 2014, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ +package com.facebook.csslayout; + +import com.taobao.luaview.annotations.Nullable; + +import java.util.Arrays; + +/** + * Class representing CSS spacing (padding, margin, and borders). This is mostly necessary to + * properly implement interactions and updates for properties like margin, marginLeft, and + * marginHorizontal. + */ +public class Spacing { + + /** + * Spacing type that represents the left direction. E.g. {@code marginLeft}. + */ + public static final int LEFT = 0; + /** + * Spacing type that represents the top direction. E.g. {@code marginTop}. + */ + public static final int TOP = 1; + /** + * Spacing type that represents the right direction. E.g. {@code marginRight}. + */ + public static final int RIGHT = 2; + /** + * Spacing type that represents the bottom direction. E.g. {@code marginBottom}. + */ + public static final int BOTTOM = 3; + /** + * Spacing type that represents vertical direction (top and bottom). E.g. {@code marginVertical}. + */ + public static final int VERTICAL = 4; + /** + * Spacing type that represents horizontal direction (left and right). E.g. + * {@code marginHorizontal}. + */ + public static final int HORIZONTAL = 5; + /** + * Spacing type that represents start direction e.g. left in left-to-right, right in right-to-left. + */ + public static final int START = 6; + /** + * Spacing type that represents end direction e.g. right in left-to-right, left in right-to-left. + */ + public static final int END = 7; + /** + * Spacing type that represents all directions (left, top, right, bottom). E.g. {@code margin}. + */ + public static final int ALL = 8; + + private static final int[] sFlagsMap = { + 1, /*LEFT*/ + 2, /*TOP*/ + 4, /*RIGHT*/ + 8, /*BOTTOM*/ + 16, /*VERTICAL*/ + 32, /*HORIZONTAL*/ + 64, /*START*/ + 128, /*END*/ + 256, /*ALL*/ + }; + + private final float[] mSpacing = newFullSpacingArray(); + @Nullable private float[] mDefaultSpacing = null; + private int mValueFlags = 0; + private boolean mHasAliasesSet; + + /** + * Set a spacing value. + * + * @param spacingType one of {@link #LEFT}, {@link #TOP}, {@link #RIGHT}, {@link #BOTTOM}, + * {@link #VERTICAL}, {@link #HORIZONTAL}, {@link #ALL} + * @param value the value for this direction + * @return {@code true} if the spacing has changed, or {@code false} if the same value was already + * set + */ + public boolean set(int spacingType, float value) { + if (!FloatUtil.floatsEqual(mSpacing[spacingType], value)) { + mSpacing[spacingType] = value; + + if (CSSConstants.isUndefined(value)) { + mValueFlags &= ~sFlagsMap[spacingType]; + } else { + mValueFlags |= sFlagsMap[spacingType]; + } + + mHasAliasesSet = + (mValueFlags & sFlagsMap[ALL]) != 0 || + (mValueFlags & sFlagsMap[VERTICAL]) != 0 || + (mValueFlags & sFlagsMap[HORIZONTAL]) != 0; + + return true; + } + return false; + } + + /** + * Set a default spacing value. This is used as a fallback when no spacing has been set for a + * particular direction. + * + * @param spacingType one of {@link #LEFT}, {@link #TOP}, {@link #RIGHT}, {@link #BOTTOM} + * @param value the default value for this direction + * @return + */ + public boolean setDefault(int spacingType, float value) { + if (mDefaultSpacing == null) { + mDefaultSpacing = newSpacingResultArray(); + } + if (!FloatUtil.floatsEqual(mDefaultSpacing[spacingType], value)) { + mDefaultSpacing[spacingType] = value; + return true; + } + return false; + } + + /** + * Get the spacing for a direction. This takes into account any default values that have been set. + * + * @param spacingType one of {@link #LEFT}, {@link #TOP}, {@link #RIGHT}, {@link #BOTTOM} + */ + public float get(int spacingType) { + float defaultValue = (mDefaultSpacing != null) + ? mDefaultSpacing[spacingType] + : (spacingType == START || spacingType == END ? CSSConstants.UNDEFINED : 0); + + if (mValueFlags == 0) { + return defaultValue; + } + + if ((mValueFlags & sFlagsMap[spacingType]) != 0) { + return mSpacing[spacingType]; + } + + if (mHasAliasesSet) { + int secondType = spacingType == TOP || spacingType == BOTTOM ? VERTICAL : HORIZONTAL; + if ((mValueFlags & sFlagsMap[secondType]) != 0) { + return mSpacing[secondType]; + } else if ((mValueFlags & sFlagsMap[ALL]) != 0) { + return mSpacing[ALL]; + } + } + + return defaultValue; + } + + /** + * Get the raw value (that was set using {@link #set(int, float)}), without taking into account + * any default values. + * + * @param spacingType one of {@link #LEFT}, {@link #TOP}, {@link #RIGHT}, {@link #BOTTOM}, + * {@link #VERTICAL}, {@link #HORIZONTAL}, {@link #ALL} + */ + public float getRaw(int spacingType) { + return mSpacing[spacingType]; + } + + /** + * Resets the spacing instance to its default state. This method is meant to be used when + * recycling {@link Spacing} instances. + */ + void reset() { + Arrays.fill(mSpacing, CSSConstants.UNDEFINED); + mDefaultSpacing = null; + mHasAliasesSet = false; + mValueFlags = 0; + } + + /** + * Try to get start value and fallback to given type if not defined. This is used privately + * by the layout engine as a more efficient way to fetch direction-aware values by + * avoid extra method invocations. + */ + float getWithFallback(int spacingType, int fallbackType) { + return + (mValueFlags & sFlagsMap[spacingType]) != 0 + ? mSpacing[spacingType] + : get(fallbackType); + } + + private static float[] newFullSpacingArray() { + return new float[] { + CSSConstants.UNDEFINED, + CSSConstants.UNDEFINED, + CSSConstants.UNDEFINED, + CSSConstants.UNDEFINED, + CSSConstants.UNDEFINED, + CSSConstants.UNDEFINED, + CSSConstants.UNDEFINED, + CSSConstants.UNDEFINED, + CSSConstants.UNDEFINED, + }; + } + + private static float[] newSpacingResultArray() { + return newSpacingResultArray(0); + } + + private static float[] newSpacingResultArray(float defaultValue) { + return new float[] { + defaultValue, + defaultValue, + defaultValue, + defaultValue, + defaultValue, + defaultValue, + CSSConstants.UNDEFINED, + CSSConstants.UNDEFINED, + defaultValue, + }; + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/activity/LuaViewActivity.java b/Android/LuaViewSDK/src/com/taobao/luaview/activity/LuaViewActivity.java new file mode 100644 index 00000000..4902dd58 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/activity/LuaViewActivity.java @@ -0,0 +1,70 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.activity; + +import android.app.Activity; +import android.os.Bundle; + +import com.taobao.luaview.global.Constants; +import com.taobao.luaview.global.LuaView; + +/** + * LuaView Activity + * + * @author song + * @date 15/9/22 + */ +public class LuaViewActivity extends Activity { + private LuaView mLuaView; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + mLuaView = LuaView.create(this); + setContentView(mLuaView); + } + + @Override + protected void onPostCreate(Bundle savedInstanceState) { + super.onPostCreate(savedInstanceState); + if (mLuaView != null) { + registerNameBeforeLoad(mLuaView); + load(mLuaView); + } + } + + /** + * 注册接口,注册各种脚本,panel + */ + public void registerNameBeforeLoad(final LuaView luaView) { + } + + /** + * 加载数据 + */ + public void load(final LuaView luaView) { + luaView.load(getLuaUri()); + } + + /** + * 获取文件名称 + * + * @return + */ + private String getLuaUri() { + if (getIntent() != null && getIntent().hasExtra(Constants.PARAM_URI)) { + return getIntent().getStringExtra(Constants.PARAM_URI); + } + return null; + } + + public LuaView getLuaView() { + return mLuaView; + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/activity/LuaViewFragmentActivity.java b/Android/LuaViewSDK/src/com/taobao/luaview/activity/LuaViewFragmentActivity.java new file mode 100644 index 00000000..9748c3e6 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/activity/LuaViewFragmentActivity.java @@ -0,0 +1,72 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.activity; + +import android.os.Bundle; +import android.support.v4.app.FragmentActivity; + +import com.taobao.luaview.global.Constants; +import com.taobao.luaview.global.LuaView; + +/** + * LuaView Activity + * + * @author song + * @date 15/9/22 + */ +public class LuaViewFragmentActivity extends FragmentActivity { + private LuaView mLuaView; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + mLuaView = LuaView.create(this); + setContentView(mLuaView); + getSupportFragmentManager().beginTransaction().commit(); + } + + + @Override + protected void onPostCreate(Bundle savedInstanceState) { + super.onPostCreate(savedInstanceState); + if (mLuaView != null) { + registerNameBeforeLoad(mLuaView); + load(mLuaView); + } + } + + /** + * 注册接口,注册各种脚本,panel + */ + public void registerNameBeforeLoad(final LuaView luaView) { + } + + /** + * 加载数据 + */ + public void load(final LuaView luaView) { + luaView.load(getLuaUri()); + } + + /** + * 获取文件名称 + * + * @return + */ + private String getLuaUri() { + if (getIntent() != null && getIntent().hasExtra(Constants.PARAM_URI)) { + return getIntent().getStringExtra(Constants.PARAM_URI); + } + return null; + } + + public LuaView getLuaView() { + return mLuaView; + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/annotations/Nonnull.java b/Android/LuaViewSDK/src/com/taobao/luaview/annotations/Nonnull.java new file mode 100644 index 00000000..6b79ae5c --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/annotations/Nonnull.java @@ -0,0 +1,29 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.annotations; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Documented +@TypeQualifier +@Retention(RetentionPolicy.RUNTIME) +public @interface Nonnull { + When when() default When.ALWAYS; + + public static class Checker implements TypeQualifierValidator { + public Checker() { + } + + public When forConstantValue(Nonnull qualifierqualifierArgument, Object value) { + return value == null?When.NEVER:When.ALWAYS; + } + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/annotations/Nullable.java b/Android/LuaViewSDK/src/com/taobao/luaview/annotations/Nullable.java new file mode 100644 index 00000000..72b786a8 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/annotations/Nullable.java @@ -0,0 +1,22 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.annotations; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Documented +@Nonnull( + when = When.UNKNOWN +) +@Retention(RetentionPolicy.RUNTIME) +@TypeQualifierNickname +public @interface Nullable { +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/annotations/TypeQualifier.java b/Android/LuaViewSDK/src/com/taobao/luaview/annotations/TypeQualifier.java new file mode 100644 index 00000000..c3c71d74 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/annotations/TypeQualifier.java @@ -0,0 +1,22 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.annotations; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Documented +@Target({ElementType.ANNOTATION_TYPE}) +@Retention(RetentionPolicy.RUNTIME) +public @interface TypeQualifier { + Class applicableTo() default Object.class; +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/annotations/TypeQualifierNickname.java b/Android/LuaViewSDK/src/com/taobao/luaview/annotations/TypeQualifierNickname.java new file mode 100644 index 00000000..9a3bfcb8 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/annotations/TypeQualifierNickname.java @@ -0,0 +1,18 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.annotations; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; + +@Documented +@Target({ElementType.ANNOTATION_TYPE}) +public @interface TypeQualifierNickname { +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/annotations/TypeQualifierValidator.java b/Android/LuaViewSDK/src/com/taobao/luaview/annotations/TypeQualifierValidator.java new file mode 100644 index 00000000..46640f28 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/annotations/TypeQualifierValidator.java @@ -0,0 +1,16 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.annotations; + +import java.lang.annotation.Annotation; + +public interface TypeQualifierValidator { + @Nonnull + When forConstantValue(@Nonnull A var1, Object var2); +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/annotations/When.java b/Android/LuaViewSDK/src/com/taobao/luaview/annotations/When.java new file mode 100644 index 00000000..db8b0673 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/annotations/When.java @@ -0,0 +1,19 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.annotations; + +public enum When { + ALWAYS, + UNKNOWN, + MAYBE, + NEVER; + + private When() { + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/cache/AppCache.java b/Android/LuaViewSDK/src/com/taobao/luaview/cache/AppCache.java new file mode 100644 index 00000000..999c2933 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/cache/AppCache.java @@ -0,0 +1,252 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.cache; + +import android.app.Application; +import android.support.v4.util.LruCache; + +import java.util.HashMap; +import java.util.Map; + +/** + * App级别的引用cache,不会在退出的时候清空 + * + * @author song + * @date 16/1/27 + */ +public class AppCache { + public static final int DEFAULT_LRU_CACHE_PROTOTYPE_SIZE = (int) (1.5 * 1024 * 1024);//1.5M + public static final int DEFAULT_LRU_CACHE_SIZE = 5;//5个 + public static final String CACHE_METHODS = "cache_methods";//方法名称缓存 + public static final String CACHE_PUBLIC_KEY = "cache_public_key";//公钥 + public static final String CACHE_METATABLES = "cache_metatables";//metatable缓存 + public static final String CACHE_SCRIPTS = "cache_scripts";//脚本文件缓存,占用空间2% + public static final String CACHE_PROTOTYPE = "cache_prototype";//lua中间码缓存,占用空间3% + + //全局静态cache + private static Map mCachePool; + + //simple cache + private Map mCache; + + //lru cache + private LuaLruCache mLruCache; + + + /** + * on received memory warning + * + * @param level + */ + public static void onTrimMemory(int level) { + switch (level) { + case Application.TRIM_MEMORY_COMPLETE:// = 80; clear all + clear(); + break; + case Application.TRIM_MEMORY_MODERATE:// = 60; + clear(CACHE_PROTOTYPE, CACHE_SCRIPTS); + break; + case Application.TRIM_MEMORY_BACKGROUND:// = 40; + clear(CACHE_SCRIPTS); + break; + case Application.TRIM_MEMORY_UI_HIDDEN:// = 20; + clear(CACHE_SCRIPTS); + break; + case Application.TRIM_MEMORY_RUNNING_CRITICAL:// = 15; + break; + case Application.TRIM_MEMORY_RUNNING_LOW:// = 10; + break; + case Application.TRIM_MEMORY_RUNNING_MODERATE:// = 5; + break; + } + } + + private AppCache() { + this(DEFAULT_LRU_CACHE_SIZE); + } + + private AppCache(int size) { + mCache = new HashMap(); + if (size > 0) { + mLruCache = new LuaLruCache(size); + } + } + + /** + * get a named cache + * + * @return + */ + public static AppCache getPrototpyeCache() { + return getCache(CACHE_PROTOTYPE, DEFAULT_LRU_CACHE_PROTOTYPE_SIZE); + } + + public static AppCache getCache(String cacheName) { + return getCache(cacheName, DEFAULT_LRU_CACHE_SIZE); + } + + public static AppCache getCache(String cacheName, int size) { + if (mCachePool == null) { + mCachePool = new HashMap(); + } + if (!mCachePool.containsKey(cacheName)) { + final AppCache appCache = new AppCache(size); + mCachePool.put(cacheName, appCache); + return appCache; + } + return mCachePool.get(cacheName); + } + + + /** + * should call when LuaView is destroy + */ + public static void clear() { + if (mCachePool != null) { + mCachePool.clear(); + } + } + + /** + * clear certain cache + * + * @param keys + */ + public static void clear(String... keys) { + if (mCachePool != null && keys != null) { + AppCache appCache = null; + for (String key : keys) { + if (mCachePool.containsKey(key)) { + appCache = mCachePool.remove(key); + if (appCache != null) { + if (appCache.mCache != null) { + appCache.mCache.clear(); + } + if (appCache.mLruCache != null) { + appCache.mLruCache.evictAll(); + } + } + } + } + } + } + + /** + * get from cache + * + * @param key + * @param + * @return + */ + public T get(final Object key) { + if (mCache != null && mCache.get(key) != null) { + return (T) mCache.get(key); + } + return null; + } + + /** + * get from cache + * + * @param key + * @param + * @return + */ + public T getLru(final Object key) { + if (mLruCache != null && mLruCache.get(key) != null) { + return (T) mLruCache.getWrap(key); + } + return null; + } + + /** + * update cache + * + * @param key + * @param value + * @param + * @return + */ + public T put(final Object key, T value) { + if (mCache != null) { + mCache.put(key, value); + } + return value; + } + + /** + * update cache + * + * @param key + * @param value + * @param + * @return + */ + public T putLru(final Object key, T value, Integer size) { + if (mLruCache != null) { + mLruCache.putWrap(key, value, size); + } + return value; + } + + public T putLru(final Object key, T value) { + if (mLruCache != null) { + mLruCache.putWrap(key, value, null); + } + return value; + } + + //----------------------------------------extend lru object------------------------------------- + static class LuaLruCache extends LruCache { + public LuaLruCache(int maxSize) { + super(maxSize); + } + + public void putWrap(Object key, Object value, Integer size) { + if (key != null && value != null) { + if (size != null) { + super.put(key, new WrapLruObject(value, size)); + } else { + super.put(key, value); + } + } + } + + public Object getWrap(Object key) { + if (key != null) { + Object result = super.get(key); + if (result instanceof WrapLruObject) { + return ((WrapLruObject) result).obj; + } else { + return result; + } + } else { + return null; + } + } + + @Override + protected int sizeOf(Object key, Object value) { + if (value instanceof WrapLruObject) { + return ((WrapLruObject) value).size; + } + return super.sizeOf(key, value); + } + } + + static class WrapLruObject extends Object { + Object obj; + int size; + + WrapLruObject(Object obj, int size) { + this.obj = obj; + this.size = size; + } + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/cache/LuaCache.java b/Android/LuaViewSDK/src/com/taobao/luaview/cache/LuaCache.java new file mode 100644 index 00000000..69276220 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/cache/LuaCache.java @@ -0,0 +1,87 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.cache; + +import java.lang.ref.WeakReference; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * 所有LuaView级别的cache管理 + * + * @author song + * @date 16/4/11 + * 主要功能描述 + * 修改描述 + * 上午11:32 song XXX + */ +public class LuaCache { + //缓存的数据,需要在退出的时候清空 + private Map>> mCachedObjects; + + //缓存数据管理器 + public interface CacheableObject { + void onCacheClear(); + } + + /** + * clear cache + */ + public static void clear() { + SimpleCache.clear(); + WeakCache.clear(); + } + + /** + * 缓存对象 + * + * @param type + * @param obj + */ + public void cacheObject(Class type, CacheableObject obj) { + if (mCachedObjects == null) { + mCachedObjects = new HashMap>>(); + } + List> cache = mCachedObjects.get(type); + if (cache == null) { + cache = new ArrayList>(); + mCachedObjects.put(type, cache); + } + + if (!cache.contains(obj)) { + cache.add(new WeakReference(obj)); + } + } + + /** + * 清理所有缓存的对象 + * TODO 需要在onShow的时候恢复所有cache后的对象 + */ + public void clearCachedObjects() { + if (mCachedObjects != null && mCachedObjects.size() > 0) { + for (final Class type : mCachedObjects.keySet()) { + List> cache = mCachedObjects.get(type); + if (cache != null) { + for (int i = 0; i < cache.size(); i++) { + final WeakReference obj = cache.get(i); + if (obj != null && obj.get() != null) { + obj.get().onCacheClear(); + } + cache.set(i, null); + } + } + mCachedObjects.put(type, null); + } + mCachedObjects.clear(); + } + mCachedObjects = null; + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/cache/SimpleCache.java b/Android/LuaViewSDK/src/com/taobao/luaview/cache/SimpleCache.java new file mode 100644 index 00000000..7cb65d74 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/cache/SimpleCache.java @@ -0,0 +1,99 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.cache; + +import java.util.HashMap; +import java.util.Map; + +/** + * Simple Reference Cache,在LuaView退出的时候会清空 + * + * @author song + * @date 16/1/27 + */ +public class SimpleCache { + //全局静态cache + private static Map mCachePool; + + private Map mCache; + + private SimpleCache() { + mCache = new HashMap(); + } + + /** + * get a named cache + * + * @param cacheName + * @return + */ + public static SimpleCache getCache(String cacheName) { + if (mCachePool == null) { + mCachePool = new HashMap(); + } + if (!mCachePool.containsKey(cacheName)) { + final SimpleCache weakReferenceCache = new SimpleCache(); + mCachePool.put(cacheName, weakReferenceCache); + return weakReferenceCache; + } + return mCachePool.get(cacheName); + } + + /** + * should call when LuaView is destroy + */ + public static void clear() { + if (mCachePool != null) { + SimpleCache sc = null; + Object cacheObj = null; + for (String key : mCachePool.keySet()) { + sc = mCachePool.get(key); + if (sc != null && sc.mCache != null) { + for (Object key2 : sc.mCache.keySet()) { + cacheObj = sc.mCache.get(key2); + if (cacheObj instanceof LuaCache.CacheableObject) { + ((LuaCache.CacheableObject) cacheObj).onCacheClear(); + } + } + sc.mCache.clear(); + } + } + mCachePool.clear(); + } + } + + /** + * get from cache + * + * @param key + * @param + * @return + */ + public T get(final Object key) { + if (mCache != null && mCache.get(key) != null) { + return (T) mCache.get(key); + } + return null; + } + + /** + * update cache + * + * @param key + * @param value + * @param + * @return + */ + public T put(final Object key, T value) { + if (mCache != null) { + mCache.put(key, value); + } + return value; + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/cache/SparseCache.java b/Android/LuaViewSDK/src/com/taobao/luaview/cache/SparseCache.java new file mode 100644 index 00000000..9901f141 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/cache/SparseCache.java @@ -0,0 +1,51 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.cache; + +import android.util.SparseArray; + +/** + * Cache using sparse array + * + * @author song + * @date 16/2/23 + */ +public class SparseCache { + + private SparseArray mCache; + + public SparseCache() { + mCache = new SparseArray(); + } + + public boolean contains(int key) { + return mCache != null && mCache.get(key) != null; + } + + public T get(final int key) { + if (mCache != null) { + return mCache.get(key); + } + return null; + } + + public T get(final int key, T defaultValueIfNotFound) { + if (mCache != null) { + return mCache.get(key, defaultValueIfNotFound); + } + return null; + } + + public void put(final int key, T value) { + if (mCache != null) { + mCache.put(key, value); + } + } + +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/cache/WeakCache.java b/Android/LuaViewSDK/src/com/taobao/luaview/cache/WeakCache.java new file mode 100644 index 00000000..0ee3f205 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/cache/WeakCache.java @@ -0,0 +1,104 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.cache; + +import java.lang.ref.WeakReference; +import java.util.HashMap; +import java.util.Map; + +/** + * Weak Reference Cache,在退出的时候会清空 + * + * @author song + * @date 16/1/27 + */ +public class WeakCache { + //全局静态cache + private static Map mCachePool; + + private Map> mCache; + + private WeakCache() { + mCache = new HashMap>(); + } + + /** + * get a named cache + * + * @param cacheName + * @return + */ + public static WeakCache getCache(String cacheName) { + if (mCachePool == null) { + mCachePool = new HashMap(); + } + if (!mCachePool.containsKey(cacheName)) { + final WeakCache weakReferenceCache = new WeakCache(); + mCachePool.put(cacheName, weakReferenceCache); + return weakReferenceCache; + } + return mCachePool.get(cacheName); + } + + /** + * should call when LuaView is destroy + */ + public static void clear() { + if (mCachePool != null) { + WeakCache c = null; + WeakReference weakObj = null; + Object cacheObj = null; + for (String key : mCachePool.keySet()) {//remove mCachePool + c = mCachePool.get(key); + if (c != null && c.mCache != null) {//remove mCache + for (Object key2 : c.mCache.keySet()) { + weakObj = c.mCache.get(key2); + if (weakObj != null) { + cacheObj = weakObj.get(); + if (cacheObj instanceof LuaCache.CacheableObject) { + ((LuaCache.CacheableObject) cacheObj).onCacheClear(); + } + } + } + c.mCache.clear(); + } + } + mCachePool.clear(); + } + } + + /** + * get from cache + * + * @param key + * @param + * @return + */ + public T get(final Object key) { + if (mCache != null && mCache.get(key) != null && mCache.get(key).get() != null) { + return (T) mCache.get(key).get(); + } + return null; + } + + /** + * update cache + * + * @param key + * @param value + * @param + * @return + */ + public T put(final Object key, T value) { + if (mCache != null) { + mCache.put(key, new WeakReference(value)); + } + return value; + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/debug/DebugConnection.java b/Android/LuaViewSDK/src/com/taobao/luaview/debug/DebugConnection.java new file mode 100644 index 00000000..10f5316e --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/debug/DebugConnection.java @@ -0,0 +1,133 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.debug; + +import android.os.Build; + +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.net.Socket; + +/** + * Created by lamo on 16/2/16. + */ +public class DebugConnection extends Socket { + + private static final String EMULATOR_LOCALHOST = "10.0.2.2"; + private static final String GENYMOTION_LOCALHOST = "10.0.3.2"; + private static final String DEVICE_LOCALHOST = "localhost"; + private static final int PORT = 9876; + + private DataInputStream input = null; + private DataOutputStream output = null; + + public boolean sendingEnabled = true; + + private static String getDebugServerHost() { + // Since genymotion runs in vbox it use different hostname to refer to adb host. + // We detect whether app runs on genymotion and replace js bundle server hostname accordingly + if (isRunningOnGenymotion()) { + return GENYMOTION_LOCALHOST; + } + if (isRunningOnStockEmulator()) { + return EMULATOR_LOCALHOST; + } + + return DEVICE_LOCALHOST; + } + + private static boolean isRunningOnGenymotion() { + return Build.FINGERPRINT.contains("vbox"); + } + + private static boolean isRunningOnStockEmulator() { + return Build.FINGERPRINT.contains("generic"); + } + + public static DebugConnection create() { + String host = getDebugServerHost(); + try { + return new DebugConnection(host, PORT); + } catch (IOException e) { + return null; + } + } + + public DebugConnection(String host, int port) throws IOException { + super(host, port); + input = new DataInputStream(getInputStream()); + output = new DataOutputStream(getOutputStream()); + } + + public boolean sendScript(byte[] content, String fileName) { + return sendCmd("loadfile", fileName, content); + } + + public boolean sendCmd(String cmd, String fileName, String info) { + return sendCmd(cmd, fileName, info != null ? info.getBytes() : null); + } + + public boolean sendCmd(String cmd, String fileName, byte[] info) { + String header = "Cmd-Name:" + cmd + "\n"; + if (fileName != null) { + header += "File-Name:" + fileName + "\n"; + } + header += "\n"; + + if (info == null) { + return sendBytes(header.getBytes()); + } else { + return sendBytes(header.getBytes(), info); + } + } + + public boolean sendBytes(byte[]... pieces) { + if (!sendingEnabled) { + return false; + } + try { + int length = 0; + for (byte[] bytes: pieces) { + length += bytes.length; + } + + output.writeByte(length >> 24); + output.writeByte(length >> 16); + output.writeByte(length >> 8); + output.writeByte(length); + + for (byte[] bytes: pieces) { + output.write(bytes); + } + + return true; + } catch (IOException e) { + return false; + } + } + + public String reciveCMD() { + try { + int length = 0; + length |= input.readByte() << 24; + length |= input.readByte() << 16; + length |= input.readByte() << 8; + length |= input.readByte(); + + byte[] buffer = new byte[length]; + input.read(buffer); + + return new String(buffer); + } catch (IOException e) { + return null; + } + } + +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/dialog/LuaViewDialog.java b/Android/LuaViewSDK/src/com/taobao/luaview/dialog/LuaViewDialog.java new file mode 100644 index 00000000..4a07352f --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/dialog/LuaViewDialog.java @@ -0,0 +1,89 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.dialog; + +import android.app.AlertDialog; +import android.content.Context; +import android.os.Bundle; + +import com.taobao.luaview.global.LuaView; + +/** + * LuaView Dialog + * + * @author song + * @date 15/12/30 + */ +public class LuaViewDialog extends AlertDialog { + private LuaView mLuaView; + + /** + * create a transparent without title Dialog + * + * @param context + * @return + */ + public static LuaViewDialog create(Context context) { + return new LuaViewDialog(context, android.R.style.Theme_Translucent_NoTitleBar); + } + + /** + * create a fullscreen transparent without title Dialog + * + * @param context + * @return + */ + public static LuaViewDialog createFullScreen(Context context) { + return new LuaViewDialog(context, android.R.style.Theme_Translucent_NoTitleBar_Fullscreen); + } + + + public LuaViewDialog(Context context) { + super(context); + mLuaView = LuaView.create(context); + } + + /** + * create dialog with theme + * + * @param context + * @param theme + */ + public LuaViewDialog(Context context, int theme) { + super(context, theme); + mLuaView = LuaView.create(context); + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(mLuaView); + } + + public LuaView getLuaView() { + return mLuaView; + } + + //-----------------------------------------load------------------------------------------------- + + public LuaViewDialog load(final String url) { + if (mLuaView != null) { + mLuaView.load(url); + } + return this; + } + + public LuaViewDialog loadScript(final String script) { + if (mLuaView != null) { + mLuaView.loadScript(script); + } + return this; + } + +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/exception/LuaViewException.java b/Android/LuaViewSDK/src/com/taobao/luaview/exception/LuaViewException.java new file mode 100644 index 00000000..764ec4bf --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/exception/LuaViewException.java @@ -0,0 +1,42 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.exception; + +/** + * LuaView错误 + * + * @author song + * @date 15/11/15 + */ +public class LuaViewException extends Exception { + private int mCode = 0; + private String mMessage = null; + + public LuaViewException() { + super(); + } + + public LuaViewException(Throwable throwable) { + super(throwable); + } + + public LuaViewException(int code) { + super(); + this.mCode = code; + } + + public LuaViewException(String message) { + super(message); + } + + public LuaViewException(int code, String message) { + super(message); + this.mCode = code; + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/extend/CustomTypefaceSpan.java b/Android/LuaViewSDK/src/com/taobao/luaview/extend/CustomTypefaceSpan.java new file mode 100644 index 00000000..d1c30dae --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/extend/CustomTypefaceSpan.java @@ -0,0 +1,58 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.extend; + +import android.graphics.Paint; +import android.graphics.Typeface; +import android.text.TextPaint; +import android.text.style.TypefaceSpan; + +/** + * 自定义 TypefaceSpan + */ +public class CustomTypefaceSpan extends TypefaceSpan { + + private final Typeface newType; + + public CustomTypefaceSpan(String family, Typeface type) { + super(family); + newType = type; + } + + @Override + public void updateDrawState(TextPaint ds) { + applyCustomTypeFace(ds, newType); + } + + @Override + public void updateMeasureState(TextPaint paint) { + applyCustomTypeFace(paint, newType); + } + + private static void applyCustomTypeFace(Paint paint, Typeface tf) { + int oldStyle; + Typeface old = paint.getTypeface(); + if (old == null) { + oldStyle = 0; + } else { + oldStyle = old.getStyle(); + } + + int fake = oldStyle & ~tf.getStyle(); + if ((fake & Typeface.BOLD) != 0) { + paint.setFakeBoldText(true); + } + + if ((fake & Typeface.ITALIC) != 0) { + paint.setTextSkewX(-0.25f); + } + + paint.setTypeface(tf); + } +} \ No newline at end of file diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/extend/SensorInterpreter.java b/Android/LuaViewSDK/src/com/taobao/luaview/extend/SensorInterpreter.java new file mode 100644 index 00000000..5003ee8a --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/extend/SensorInterpreter.java @@ -0,0 +1,134 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ +package com.taobao.luaview.extend; + +import android.content.Context; +import android.hardware.SensorEvent; +import android.hardware.SensorManager; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.view.Surface; +import android.view.WindowManager; + +import static android.hardware.SensorManager.AXIS_MINUS_X; +import static android.hardware.SensorManager.AXIS_MINUS_Y; +import static android.hardware.SensorManager.AXIS_X; +import static android.hardware.SensorManager.AXIS_Y; + +public class SensorInterpreter { + + private static final String TAG = SensorInterpreter.class.getName(); + + private float[] mTiltVector = new float[3]; + + private boolean mTargeted = false; + + private float[] mTargetMatrix = new float[16]; + + private float[] mRotationMatrix = new float[16]; + private float[] mOrientedRotationMatrix = new float[16]; + + private float[] mTruncatedRotationVector; + + private float mTiltSensitivity = 2.0f; + + @SuppressWarnings("SuspiciousNameCombination") + public float[] interpretSensorEvent(@NonNull Context context, @Nullable SensorEvent event) { + if (event == null) { + return null; + } + + float[] rotationVector = getRotationVectorFromSensorEvent(event); + + if (!mTargeted) { + setTargetVector(rotationVector); + return null; + } + + SensorManager.getRotationMatrixFromVector(mRotationMatrix, rotationVector); + + final int rotation = ((WindowManager) context + .getSystemService(Context.WINDOW_SERVICE)) + .getDefaultDisplay() + .getRotation(); + + if (rotation == Surface.ROTATION_0) { + SensorManager.getAngleChange(mTiltVector, mRotationMatrix, mTargetMatrix); + } else { + switch (rotation) { + case Surface.ROTATION_90: + SensorManager.remapCoordinateSystem(mRotationMatrix, AXIS_Y, AXIS_MINUS_X, mOrientedRotationMatrix); + break; + + case Surface.ROTATION_180: + SensorManager.remapCoordinateSystem(mRotationMatrix, AXIS_MINUS_X, AXIS_MINUS_Y, mOrientedRotationMatrix); + break; + + case Surface.ROTATION_270: + SensorManager.remapCoordinateSystem(mRotationMatrix, AXIS_MINUS_Y, AXIS_X, mOrientedRotationMatrix); + break; + } + + SensorManager.getAngleChange(mTiltVector, mOrientedRotationMatrix, mTargetMatrix); + } + + for (int i = 0; i < mTiltVector.length; i++) { + mTiltVector[i] /= Math.PI; + + mTiltVector[i] *= mTiltSensitivity; + + if (mTiltVector[i] > 1) { + mTiltVector[i] = 1f; + } else if (mTiltVector[i] < -1) { + mTiltVector[i] = -1f; + } + } + + return mTiltVector; + } + + @NonNull + float[] getRotationVectorFromSensorEvent(@NonNull SensorEvent event) { + if (event.values.length > 4) { + // On some Samsung devices SensorManager.getRotationMatrixFromVector + // appears to throw an exception if rotation vector has length > 4. + // For the purposes of this class the first 4 values of the + // rotation vector are sufficient (see crbug.com/335298 for details). + if (mTruncatedRotationVector == null) { + mTruncatedRotationVector = new float[4]; + } + System.arraycopy(event.values, 0, mTruncatedRotationVector, 0, 4); + return mTruncatedRotationVector; + } else { + return event.values; + } + } + + protected void setTargetVector(float[] values) { + SensorManager.getRotationMatrixFromVector(mTargetMatrix, values); + mTargeted = true; + } + + public void reset() { + mTargeted = false; + } + + public float getTiltSensitivity() { + return mTiltSensitivity; + } + + public void setTiltSensitivity(float tiltSensitivity) { + if (tiltSensitivity <= 0) { + throw new IllegalArgumentException("Tilt sensitivity must be positive"); + } + + mTiltSensitivity = tiltSensitivity; + } + +} + diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/extend/WeightStyleSpan.java b/Android/LuaViewSDK/src/com/taobao/luaview/extend/WeightStyleSpan.java new file mode 100644 index 00000000..7311c668 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/extend/WeightStyleSpan.java @@ -0,0 +1,36 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.extend; + +import android.graphics.Paint; +import android.text.TextPaint; +import android.text.style.CharacterStyle; + +import com.taobao.luaview.userdata.constants.UDFontWeight; + +/** + * custom style for weight + */ +public class WeightStyleSpan extends CharacterStyle { + private final int mWeight; + + public WeightStyleSpan(int weight) { + mWeight = weight; + } + + @Override + public void updateDrawState(TextPaint paint) { + final float newStrokeWidth = (mWeight / (UDFontWeight.WEIGHT_NORMAL_INT + 0.0f)); + if (paint.getStyle() == Paint.Style.FILL) { + paint.setStyle(Paint.Style.FILL_AND_STROKE); + } + paint.setStrokeWidth(newStrokeWidth); + } + +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/AnimatorDecorationHelper.java b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/AnimatorDecorationHelper.java new file mode 100644 index 00000000..fa9b6ac3 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/AnimatorDecorationHelper.java @@ -0,0 +1,193 @@ +package com.taobao.luaview.extend.animation; + +import com.taobao.luaview.extend.animation.attention.BounceAnimatorDecoration; +import com.taobao.luaview.extend.animation.attention.FlashAnimatorDecoration; +import com.taobao.luaview.extend.animation.attention.PulseAnimatorDecoration; +import com.taobao.luaview.extend.animation.attention.RubberBandAnimatorDecoration; +import com.taobao.luaview.extend.animation.attention.ShakeAnimatorDecoration; +import com.taobao.luaview.extend.animation.attention.SwingAnimatorDecoration; +import com.taobao.luaview.extend.animation.attention.TadaAnimatorDecoration; +import com.taobao.luaview.extend.animation.attention.WaveAnimatorDecoration; +import com.taobao.luaview.extend.animation.attention.WobbleAnimatorDecoration; +import com.taobao.luaview.extend.animation.bouncing_entrances.BounceInAnimatorDecoration; +import com.taobao.luaview.extend.animation.bouncing_entrances.BounceInDownAnimatorDecoration; +import com.taobao.luaview.extend.animation.bouncing_entrances.BounceInLeftAnimatorDecoration; +import com.taobao.luaview.extend.animation.bouncing_entrances.BounceInRightAnimatorDecoration; +import com.taobao.luaview.extend.animation.bouncing_entrances.BounceInUpAnimatorDecoration; +import com.taobao.luaview.extend.animation.fading_entrances.FadeInAnimatorDecoration; +import com.taobao.luaview.extend.animation.fading_entrances.FadeInDownAnimatorDecoration; +import com.taobao.luaview.extend.animation.fading_entrances.FadeInLeftAnimatorDecoration; +import com.taobao.luaview.extend.animation.fading_entrances.FadeInRightAnimatorDecoration; +import com.taobao.luaview.extend.animation.fading_entrances.FadeInUpAnimatorDecoration; +import com.taobao.luaview.extend.animation.fading_exits.FadeOutAnimatorDecoration; +import com.taobao.luaview.extend.animation.fading_exits.FadeOutDownAnimatorDecoration; +import com.taobao.luaview.extend.animation.fading_exits.FadeOutLeftAnimatorDecoration; +import com.taobao.luaview.extend.animation.fading_exits.FadeOutRightAnimatorDecoration; +import com.taobao.luaview.extend.animation.fading_exits.FadeOutUpAnimatorDecoration; +import com.taobao.luaview.extend.animation.flippers.FlipInXAnimatorDecoration; +import com.taobao.luaview.extend.animation.flippers.FlipInYAnimatorDecoration; +import com.taobao.luaview.extend.animation.flippers.FlipOutXAnimatorDecoration; +import com.taobao.luaview.extend.animation.flippers.FlipOutYAnimatorDecoration; +import com.taobao.luaview.extend.animation.rotating_entrances.RotateInAnimatorDecoration; +import com.taobao.luaview.extend.animation.rotating_entrances.RotateInDownLeftAnimatorDecoration; +import com.taobao.luaview.extend.animation.rotating_entrances.RotateInDownRightAnimatorDecoration; +import com.taobao.luaview.extend.animation.rotating_entrances.RotateInUpLeftAnimatorDecoration; +import com.taobao.luaview.extend.animation.rotating_entrances.RotateInUpRightAnimatorDecoration; +import com.taobao.luaview.extend.animation.rotating_exits.RotateOutAnimatorDecoration; +import com.taobao.luaview.extend.animation.rotating_exits.RotateOutDownLeftAnimatorDecoration; +import com.taobao.luaview.extend.animation.rotating_exits.RotateOutDownRightAnimatorDecoration; +import com.taobao.luaview.extend.animation.rotating_exits.RotateOutUpLeftAnimatorDecoration; +import com.taobao.luaview.extend.animation.rotating_exits.RotateOutUpRightAnimatorDecoration; +import com.taobao.luaview.extend.animation.sliders.SlideInDownAnimatorDecoration; +import com.taobao.luaview.extend.animation.sliders.SlideInLeftAnimatorDecoration; +import com.taobao.luaview.extend.animation.sliders.SlideInRightAnimatorDecoration; +import com.taobao.luaview.extend.animation.sliders.SlideInUpAnimatorDecoration; +import com.taobao.luaview.extend.animation.sliders.SlideOutDownAnimatorDecoration; +import com.taobao.luaview.extend.animation.sliders.SlideOutLeftAnimatorDecoration; +import com.taobao.luaview.extend.animation.sliders.SlideOutRightAnimatorDecoration; +import com.taobao.luaview.extend.animation.sliders.SlideOutUpAnimatorDecoration; +import com.taobao.luaview.extend.animation.specials.RollInAnimatorDecoration; +import com.taobao.luaview.extend.animation.specials.RollOutAnimatorDecoration; +import com.taobao.luaview.extend.animation.zooming_entrances.ZoomInAnimatorDecoration; +import com.taobao.luaview.extend.animation.zooming_entrances.ZoomInDownAnimatorDecoration; +import com.taobao.luaview.extend.animation.zooming_entrances.ZoomInLeftAnimatorDecoration; +import com.taobao.luaview.extend.animation.zooming_entrances.ZoomInRightAnimatorDecoration; +import com.taobao.luaview.extend.animation.zooming_entrances.ZoomInUpAnimatorDecoration; +import com.taobao.luaview.extend.animation.zooming_exits.ZoomOutAnimatorDecoration; +import com.taobao.luaview.extend.animation.zooming_exits.ZoomOutDownAnimatorDecoration; +import com.taobao.luaview.extend.animation.zooming_exits.ZoomOutLeftAnimatorDecoration; +import com.taobao.luaview.extend.animation.zooming_exits.ZoomOutRightAnimatorDecoration; +import com.taobao.luaview.extend.animation.zooming_exits.ZoomOutUpAnimatorDecoration; + +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.util.HashMap; +import java.util.Map; + +/** + * Decoration of Animator + * + * @author song + * @date 16/11/1 + * 主要功能描述 + * 修改描述 + * 下午3:48 song XXX + */ +public class AnimatorDecorationHelper { + + private static final Map> mViewDecorations = new HashMap>(); + + static { + //Attention + mViewDecorations.put("Attention.Bounce", BounceAnimatorDecoration.class); + mViewDecorations.put("Attention.Flash", FlashAnimatorDecoration.class); + mViewDecorations.put("Attention.Pulse", PulseAnimatorDecoration.class); + mViewDecorations.put("Attention.RubberBand", RubberBandAnimatorDecoration.class); + mViewDecorations.put("Attention.Shake", ShakeAnimatorDecoration.class); + mViewDecorations.put("Attention.Swing", SwingAnimatorDecoration.class); + mViewDecorations.put("Attention.Tada", TadaAnimatorDecoration.class); + mViewDecorations.put("Attention.Wave", WaveAnimatorDecoration.class); + mViewDecorations.put("Attention.Wobble", WobbleAnimatorDecoration.class); + + //Bounce + mViewDecorations.put("Bounce.In", BounceInAnimatorDecoration.class); + mViewDecorations.put("Bounce.In.Down", BounceInDownAnimatorDecoration.class); + mViewDecorations.put("Bounce.In.Left", BounceInLeftAnimatorDecoration.class); + mViewDecorations.put("Bounce.In.Right", BounceInRightAnimatorDecoration.class); + mViewDecorations.put("Bounce.In.Up", BounceInUpAnimatorDecoration.class); + + + //Fade in + mViewDecorations.put("Fade.In", FadeInAnimatorDecoration.class); + mViewDecorations.put("Fade.In.Down", FadeInDownAnimatorDecoration.class); + mViewDecorations.put("Fade.In.Left", FadeInLeftAnimatorDecoration.class); + mViewDecorations.put("Fade.In.Right", FadeInRightAnimatorDecoration.class); + mViewDecorations.put("Fade.In.Up", FadeInUpAnimatorDecoration.class); + + //Fade out + mViewDecorations.put("Fade.Out", FadeOutAnimatorDecoration.class); + mViewDecorations.put("Fade.Out.Down", FadeOutDownAnimatorDecoration.class); + mViewDecorations.put("Fade.Out.Left", FadeOutLeftAnimatorDecoration.class); + mViewDecorations.put("Fade.Out.Right", FadeOutRightAnimatorDecoration.class); + mViewDecorations.put("Fade.Out.Up", FadeOutUpAnimatorDecoration.class); + + //Flip + mViewDecorations.put("Flip.In.X", FlipInXAnimatorDecoration.class); + mViewDecorations.put("Flip.In.Y", FlipInYAnimatorDecoration.class); + mViewDecorations.put("Flip.Out.X", FlipOutXAnimatorDecoration.class); + mViewDecorations.put("Flip.Out.Y", FlipOutYAnimatorDecoration.class); + + //rotate in + mViewDecorations.put("Rotate.In", RotateInAnimatorDecoration.class); + mViewDecorations.put("Rotate.In.DownLeft", RotateInDownLeftAnimatorDecoration.class); + mViewDecorations.put("Rotate.In.DownRight", RotateInDownRightAnimatorDecoration.class); + mViewDecorations.put("Rotate.In.UpLeft", RotateInUpLeftAnimatorDecoration.class); + mViewDecorations.put("Rotate.In.UpRight", RotateInUpRightAnimatorDecoration.class); + + //rotate out + mViewDecorations.put("Rotate.Out", RotateOutAnimatorDecoration.class); + mViewDecorations.put("Rotate.Out.DownLeft", RotateOutDownLeftAnimatorDecoration.class); + mViewDecorations.put("Rotate.Out.DownRight", RotateOutDownRightAnimatorDecoration.class); + mViewDecorations.put("Rotate.Out.UpLeft", RotateOutUpLeftAnimatorDecoration.class); + mViewDecorations.put("Rotate.Out.UpRight", RotateOutUpRightAnimatorDecoration.class); + + //slide in + mViewDecorations.put("Slide.In.Down", SlideInDownAnimatorDecoration.class); + mViewDecorations.put("Slide.In.Left", SlideInLeftAnimatorDecoration.class); + mViewDecorations.put("Slide.In.Right", SlideInRightAnimatorDecoration.class); + mViewDecorations.put("Slide.In.Up", SlideInUpAnimatorDecoration.class); + + //slide out + mViewDecorations.put("Slide.Out.Down", SlideOutDownAnimatorDecoration.class); + mViewDecorations.put("Slide.Out.Left", SlideOutLeftAnimatorDecoration.class); + mViewDecorations.put("Slide.Out.Right", SlideOutRightAnimatorDecoration.class); + mViewDecorations.put("Slide.Out.Up", SlideOutUpAnimatorDecoration.class); + + //roll + mViewDecorations.put("Roll.In", RollInAnimatorDecoration.class); + mViewDecorations.put("Roll.Out", RollOutAnimatorDecoration.class); + + //Zoom in + mViewDecorations.put("Zoom.In", ZoomInAnimatorDecoration.class); + mViewDecorations.put("Zoom.In.Down", ZoomInDownAnimatorDecoration.class); + mViewDecorations.put("Zoom.In.Left", ZoomInLeftAnimatorDecoration.class); + mViewDecorations.put("Zoom.In.Right", ZoomInRightAnimatorDecoration.class); + mViewDecorations.put("Zoom.In.Up", ZoomInUpAnimatorDecoration.class); + + //Zoom out + mViewDecorations.put("Zoom.Out", ZoomOutAnimatorDecoration.class); + mViewDecorations.put("Zoom.Out.Down", ZoomOutDownAnimatorDecoration.class); + mViewDecorations.put("Zoom.Out.Left", ZoomOutLeftAnimatorDecoration.class); + mViewDecorations.put("Zoom.Out.Right", ZoomOutRightAnimatorDecoration.class); + mViewDecorations.put("Zoom.Out.Up", ZoomOutUpAnimatorDecoration.class); + } + + /** + * create a decoration + * + * @param name + * @return + */ + public static BaseViewAnimatorDecoration createDecoration(String name) { + if (mViewDecorations != null && mViewDecorations.containsKey(name)) { + Class clazz = mViewDecorations.get(name); + if (clazz != null) { + try { + Constructor constructor = clazz.getConstructor(); + if (constructor != null) { + return constructor.newInstance(); + } + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } catch (InstantiationException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + } + } + return null; + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/AnimatorProxy.java b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/AnimatorProxy.java new file mode 100644 index 00000000..f85d55b7 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/AnimatorProxy.java @@ -0,0 +1,322 @@ +package com.taobao.luaview.extend.animation; + +import android.graphics.Camera; +import android.graphics.Matrix; +import android.graphics.RectF; +import android.os.Build; +import android.view.View; +import android.view.animation.Animation; +import android.view.animation.Transformation; + +import java.lang.ref.WeakReference; +import java.util.WeakHashMap; + +/** + * A proxy class to allow for modifying post-3.0 view properties on all pre-3.0 + * platforms. DO NOT wrap your views with this class if you + * are using {@code ObjectAnimator} as it will handle that itself. + */ +public final class AnimatorProxy extends Animation { + /** Whether or not the current running platform needs to be proxied. */ + public static final boolean NEEDS_PROXY = Integer.valueOf(Build.VERSION.SDK).intValue() < Build.VERSION_CODES.HONEYCOMB; + + private static final WeakHashMap PROXIES = + new WeakHashMap(); + + /** + * Create a proxy to allow for modifying post-3.0 view properties on all + * pre-3.0 platforms. DO NOT wrap your views if you are + * using {@code ObjectAnimator} as it will handle that itself. + * + * @param view View to wrap. + * @return Proxy to post-3.0 properties. + */ + public static AnimatorProxy wrap(View view) { + AnimatorProxy proxy = PROXIES.get(view); + // This checks if the proxy already exists and whether it still is the animation of the given view + if (proxy == null || proxy != view.getAnimation()) { + proxy = new AnimatorProxy(view); + PROXIES.put(view, proxy); + } + return proxy; + } + + private final WeakReference mView; + private final Camera mCamera = new Camera(); + private boolean mHasPivot; + + private float mAlpha = 1; + private float mPivotX; + private float mPivotY; + private float mRotationX; + private float mRotationY; + private float mRotationZ; + private float mScaleX = 1; + private float mScaleY = 1; + private float mTranslationX; + private float mTranslationY; + + private final RectF mBefore = new RectF(); + private final RectF mAfter = new RectF(); + private final Matrix mTempMatrix = new Matrix(); + + private AnimatorProxy(View view) { + setDuration(0); //perform transformation immediately + setFillAfter(true); //persist transformation beyond duration + view.setAnimation(this); + mView = new WeakReference(view); + } + + public float getAlpha() { + return mAlpha; + } + public void setAlpha(float alpha) { + if (mAlpha != alpha) { + mAlpha = alpha; + View view = mView.get(); + if (view != null) { + view.invalidate(); + } + } + } + public float getPivotX() { + return mPivotX; + } + public void setPivotX(float pivotX) { + if (!mHasPivot || mPivotX != pivotX) { + prepareForUpdate(); + mHasPivot = true; + mPivotX = pivotX; + invalidateAfterUpdate(); + } + } + public float getPivotY() { + return mPivotY; + } + public void setPivotY(float pivotY) { + if (!mHasPivot || mPivotY != pivotY) { + prepareForUpdate(); + mHasPivot = true; + mPivotY = pivotY; + invalidateAfterUpdate(); + } + } + public float getRotation() { + return mRotationZ; + } + public void setRotation(float rotation) { + if (mRotationZ != rotation) { + prepareForUpdate(); + mRotationZ = rotation; + invalidateAfterUpdate(); + } + } + public float getRotationX() { + return mRotationX; + } + public void setRotationX(float rotationX) { + if (mRotationX != rotationX) { + prepareForUpdate(); + mRotationX = rotationX; + invalidateAfterUpdate(); + } + } + public float getRotationY() { + return mRotationY; + } + + public void setRotationY(float rotationY) { + if (mRotationY != rotationY) { + prepareForUpdate(); + mRotationY = rotationY; + invalidateAfterUpdate(); + } + } + public float getScaleX() { + return mScaleX; + } + public void setScaleX(float scaleX) { + if (mScaleX != scaleX) { + prepareForUpdate(); + mScaleX = scaleX; + invalidateAfterUpdate(); + } + } + public float getScaleY() { + return mScaleY; + } + public void setScaleY(float scaleY) { + if (mScaleY != scaleY) { + prepareForUpdate(); + mScaleY = scaleY; + invalidateAfterUpdate(); + } + } + public int getScrollX() { + View view = mView.get(); + if (view == null) { + return 0; + } + return view.getScrollX(); + } + public void setScrollX(int value) { + View view = mView.get(); + if (view != null) { + view.scrollTo(value, view.getScrollY()); + } + } + public int getScrollY() { + View view = mView.get(); + if (view == null) { + return 0; + } + return view.getScrollY(); + } + public void setScrollY(int value) { + View view = mView.get(); + if (view != null) { + view.scrollTo(view.getScrollX(), value); + } + } + + public float getTranslationX() { + return mTranslationX; + } + public void setTranslationX(float translationX) { + if (mTranslationX != translationX) { + prepareForUpdate(); + mTranslationX = translationX; + invalidateAfterUpdate(); + } + } + public float getTranslationY() { + return mTranslationY; + } + public void setTranslationY(float translationY) { + if (mTranslationY != translationY) { + prepareForUpdate(); + mTranslationY = translationY; + invalidateAfterUpdate(); + } + } + public float getX() { + View view = mView.get(); + if (view == null) { + return 0; + } + return view.getLeft() + mTranslationX; + } + public void setX(float x) { + View view = mView.get(); + if (view != null) { + setTranslationX(x - view.getLeft()); + } + } + public float getY() { + View view = mView.get(); + if (view == null) { + return 0; + } + return view.getTop() + mTranslationY; + } + public void setY(float y) { + View view = mView.get(); + if (view != null) { + setTranslationY(y - view.getTop()); + } + } + + private void prepareForUpdate() { + View view = mView.get(); + if (view != null) { + computeRect(mBefore, view); + } + } + private void invalidateAfterUpdate() { + View view = mView.get(); + if (view == null || view.getParent() == null) { + return; + } + + final RectF after = mAfter; + computeRect(after, view); + after.union(mBefore); + + ((View)view.getParent()).invalidate( + (int) Math.floor(after.left), + (int) Math.floor(after.top), + (int) Math.ceil(after.right), + (int) Math.ceil(after.bottom)); + } + + private void computeRect(final RectF r, View view) { + // compute current rectangle according to matrix transformation + final float w = view.getWidth(); + final float h = view.getHeight(); + + // use a rectangle at 0,0 to make sure we don't run into issues with scaling + r.set(0, 0, w, h); + + final Matrix m = mTempMatrix; + m.reset(); + transformMatrix(m, view); + mTempMatrix.mapRect(r); + + r.offset(view.getLeft(), view.getTop()); + + // Straighten coords if rotations flipped them + if (r.right < r.left) { + final float f = r.right; + r.right = r.left; + r.left = f; + } + if (r.bottom < r.top) { + final float f = r.top; + r.top = r.bottom; + r.bottom = f; + } + } + + private void transformMatrix(Matrix m, View view) { + final float w = view.getWidth(); + final float h = view.getHeight(); + final boolean hasPivot = mHasPivot; + final float pX = hasPivot ? mPivotX : w / 2f; + final float pY = hasPivot ? mPivotY : h / 2f; + + final float rX = mRotationX; + final float rY = mRotationY; + final float rZ = mRotationZ; + if ((rX != 0) || (rY != 0) || (rZ != 0)) { + final Camera camera = mCamera; + camera.save(); + camera.rotateX(rX); + camera.rotateY(rY); + camera.rotateZ(-rZ); + camera.getMatrix(m); + camera.restore(); + m.preTranslate(-pX, -pY); + m.postTranslate(pX, pY); + } + + final float sX = mScaleX; + final float sY = mScaleY; + if ((sX != 1.0f) || (sY != 1.0f)) { + m.postScale(sX, sY); + final float sPX = -(pX / w) * ((sX * w) - w); + final float sPY = -(pY / h) * ((sY * h) - h); + m.postTranslate(sPX, sPY); + } + + m.postTranslate(mTranslationX, mTranslationY); + } + + @Override + protected void applyTransformation(float interpolatedTime, Transformation t) { + View view = mView.get(); + if (view != null) { + t.setAlpha(mAlpha); + transformMatrix(t.getMatrix(), view); + } + } +} \ No newline at end of file diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/BaseViewAnimatorDecoration.java b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/BaseViewAnimatorDecoration.java new file mode 100644 index 00000000..49b936fe --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/BaseViewAnimatorDecoration.java @@ -0,0 +1,59 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014 daimajia + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.taobao.luaview.extend.animation; + +import android.animation.AnimatorSet; +import android.view.View; + + +public abstract class BaseViewAnimatorDecoration { + public static final long DURATION = 1000; + + protected abstract void prepare(AnimatorSet animatorSet, View target); + + public BaseViewAnimatorDecoration setTarget(AnimatorSet animatorSet, View target) { + reset(target); + prepare(animatorSet, target); + return this; + } + + /** + * reset the view to default status + * + * @param target + */ + public void reset(View target) { + ViewHelper.setAlpha(target, 1); + ViewHelper.setScaleX(target, 1); + ViewHelper.setScaleY(target, 1); + ViewHelper.setTranslationX(target, 0); + ViewHelper.setTranslationY(target, 0); + ViewHelper.setRotation(target, 0); + ViewHelper.setRotationY(target, 0); + ViewHelper.setRotationX(target, 0); + ViewHelper.setPivotX(target, target.getMeasuredWidth() / 2.0f); + ViewHelper.setPivotY(target, target.getMeasuredHeight() / 2.0f); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/ViewHelper.java b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/ViewHelper.java new file mode 100644 index 00000000..a6693754 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/ViewHelper.java @@ -0,0 +1,290 @@ +package com.taobao.luaview.extend.animation; + +import android.view.View; + +public final class ViewHelper { + private ViewHelper() { + } + + public static float getAlpha(View view) { + return com.taobao.luaview.extend.animation.AnimatorProxy.NEEDS_PROXY ? AnimatorProxy.wrap(view).getAlpha() : Honeycomb.getAlpha(view); + } + + public static void setAlpha(View view, float alpha) { + if (AnimatorProxy.NEEDS_PROXY) { + AnimatorProxy.wrap(view).setAlpha(alpha); + } else { + Honeycomb.setAlpha(view, alpha); + } + } + + public static float getPivotX(View view) { + return AnimatorProxy.NEEDS_PROXY ? AnimatorProxy.wrap(view).getPivotX() : Honeycomb.getPivotX(view); + } + + public static void setPivotX(View view, float pivotX) { + if (AnimatorProxy.NEEDS_PROXY) { + AnimatorProxy.wrap(view).setPivotX(pivotX); + } else { + Honeycomb.setPivotX(view, pivotX); + } + } + + public static float getPivotY(View view) { + return AnimatorProxy.NEEDS_PROXY ? AnimatorProxy.wrap(view).getPivotY() : Honeycomb.getPivotY(view); + } + + public static void setPivotY(View view, float pivotY) { + if (AnimatorProxy.NEEDS_PROXY) { + AnimatorProxy.wrap(view).setPivotY(pivotY); + } else { + Honeycomb.setPivotY(view, pivotY); + } + } + + public static float getRotation(View view) { + return AnimatorProxy.NEEDS_PROXY ? AnimatorProxy.wrap(view).getRotation() : Honeycomb.getRotation(view); + } + + public static void setRotation(View view, float rotation) { + if (AnimatorProxy.NEEDS_PROXY) { + AnimatorProxy.wrap(view).setRotation(rotation); + } else { + Honeycomb.setRotation(view, rotation); + } + } + + public static float getRotationX(View view) { + return AnimatorProxy.NEEDS_PROXY ? AnimatorProxy.wrap(view).getRotationX() : Honeycomb.getRotationX(view); + } + + public static void setRotationX(View view, float rotationX) { + if (AnimatorProxy.NEEDS_PROXY) { + AnimatorProxy.wrap(view).setRotationX(rotationX); + } else { + Honeycomb.setRotationX(view, rotationX); + } + } + + public static float getRotationY(View view) { + return AnimatorProxy.NEEDS_PROXY ? AnimatorProxy.wrap(view).getRotationY() : Honeycomb.getRotationY(view); + } + + public static void setRotationY(View view, float rotationY) { + if (AnimatorProxy.NEEDS_PROXY) { + AnimatorProxy.wrap(view).setRotationY(rotationY); + } else { + Honeycomb.setRotationY(view, rotationY); + } + } + + public static float getScaleX(View view) { + return AnimatorProxy.NEEDS_PROXY ? AnimatorProxy.wrap(view).getScaleX() : Honeycomb.getScaleX(view); + } + + public static void setScaleX(View view, float scaleX) { + if (AnimatorProxy.NEEDS_PROXY) { + AnimatorProxy.wrap(view).setScaleX(scaleX); + } else { + Honeycomb.setScaleX(view, scaleX); + } + } + + public static float getScaleY(View view) { + return AnimatorProxy.NEEDS_PROXY ? AnimatorProxy.wrap(view).getScaleY() : Honeycomb.getScaleY(view); + } + + public static void setScaleY(View view, float scaleY) { + if (AnimatorProxy.NEEDS_PROXY) { + AnimatorProxy.wrap(view).setScaleY(scaleY); + } else { + Honeycomb.setScaleY(view, scaleY); + } + } + + public static float getScrollX(View view) { + return AnimatorProxy.NEEDS_PROXY ? AnimatorProxy.wrap(view).getScrollX() : Honeycomb.getScrollX(view); + } + + public static void setScrollX(View view, int scrollX) { + if (AnimatorProxy.NEEDS_PROXY) { + AnimatorProxy.wrap(view).setScrollX(scrollX); + } else { + Honeycomb.setScrollX(view, scrollX); + } + } + + public static float getScrollY(View view) { + return AnimatorProxy.NEEDS_PROXY ? AnimatorProxy.wrap(view).getScrollY() : Honeycomb.getScrollY(view); + } + + public static void setScrollY(View view, int scrollY) { + if (AnimatorProxy.NEEDS_PROXY) { + AnimatorProxy.wrap(view).setScrollY(scrollY); + } else { + Honeycomb.setScrollY(view, scrollY); + } + } + + public static float getTranslationX(View view) { + return AnimatorProxy.NEEDS_PROXY ? AnimatorProxy.wrap(view).getTranslationX() : Honeycomb.getTranslationX(view); + } + + public static void setTranslationX(View view, float translationX) { + if (AnimatorProxy.NEEDS_PROXY) { + AnimatorProxy.wrap(view).setTranslationX(translationX); + } else { + Honeycomb.setTranslationX(view, translationX); + } + } + + public static float getTranslationY(View view) { + return AnimatorProxy.NEEDS_PROXY ? AnimatorProxy.wrap(view).getTranslationY() : Honeycomb.getTranslationY(view); + } + + public static void setTranslationY(View view, float translationY) { + if (AnimatorProxy.NEEDS_PROXY) { + AnimatorProxy.wrap(view).setTranslationY(translationY); + } else { + Honeycomb.setTranslationY(view, translationY); + } + } + + public static float getX(View view) { + return AnimatorProxy.NEEDS_PROXY ? AnimatorProxy.wrap(view).getX() : Honeycomb.getX(view); + } + + public static void setX(View view, float x) { + if (AnimatorProxy.NEEDS_PROXY) { + AnimatorProxy.wrap(view).setX(x); + } else { + Honeycomb.setX(view, x); + } + } + + public static float getY(View view) { + return AnimatorProxy.NEEDS_PROXY ? AnimatorProxy.wrap(view).getY() : Honeycomb.getY(view); + } + + public static void setY(View view, float y) { + if (AnimatorProxy.NEEDS_PROXY) { + AnimatorProxy.wrap(view).setY(y); + } else { + Honeycomb.setY(view, y); + } + } + + private static final class Honeycomb { + static float getAlpha(View view) { + return view.getAlpha(); + } + + static void setAlpha(View view, float alpha) { + view.setAlpha(alpha); + } + + static float getPivotX(View view) { + return view.getPivotX(); + } + + static void setPivotX(View view, float pivotX) { + view.setPivotX(pivotX); + } + + static float getPivotY(View view) { + return view.getPivotY(); + } + + static void setPivotY(View view, float pivotY) { + view.setPivotY(pivotY); + } + + static float getRotation(View view) { + return view.getRotation(); + } + + static void setRotation(View view, float rotation) { + view.setRotation(rotation); + } + + static float getRotationX(View view) { + return view.getRotationX(); + } + + static void setRotationX(View view, float rotationX) { + view.setRotationX(rotationX); + } + + static float getRotationY(View view) { + return view.getRotationY(); + } + + static void setRotationY(View view, float rotationY) { + view.setRotationY(rotationY); + } + + static float getScaleX(View view) { + return view.getScaleX(); + } + + static void setScaleX(View view, float scaleX) { + view.setScaleX(scaleX); + } + + static float getScaleY(View view) { + return view.getScaleY(); + } + + static void setScaleY(View view, float scaleY) { + view.setScaleY(scaleY); + } + + static float getScrollX(View view) { + return view.getScrollX(); + } + + static void setScrollX(View view, int scrollX) { + view.setScrollX(scrollX); + } + + static float getScrollY(View view) { + return view.getScrollY(); + } + + static void setScrollY(View view, int scrollY) { + view.setScrollY(scrollY); + } + + static float getTranslationX(View view) { + return view.getTranslationX(); + } + + static void setTranslationX(View view, float translationX) { + view.setTranslationX(translationX); + } + + static float getTranslationY(View view) { + return view.getTranslationY(); + } + + static void setTranslationY(View view, float translationY) { + view.setTranslationY(translationY); + } + + static float getX(View view) { + return view.getX(); + } + + static void setX(View view, float x) { + view.setX(x); + } + + static float getY(View view) { + return view.getY(); + } + + static void setY(View view, float y) { + view.setY(y); + } + } +} \ No newline at end of file diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/attention/BounceAnimatorDecoration.java b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/attention/BounceAnimatorDecoration.java new file mode 100644 index 00000000..579c9210 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/attention/BounceAnimatorDecoration.java @@ -0,0 +1,41 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014 daimajia + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.taobao.luaview.extend.animation.attention; + +import android.animation.AnimatorSet; +import android.animation.ObjectAnimator; +import android.view.View; + +import com.taobao.luaview.extend.animation.BaseViewAnimatorDecoration; + + +public class BounceAnimatorDecoration extends BaseViewAnimatorDecoration { + @Override + protected void prepare(AnimatorSet animatorSet, View target) { + animatorSet.playTogether( + ObjectAnimator.ofFloat(target, "translationY", 0, 0, -30, 0, -15, 0, 0) + ); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/attention/FlashAnimatorDecoration.java b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/attention/FlashAnimatorDecoration.java new file mode 100644 index 00000000..308f4519 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/attention/FlashAnimatorDecoration.java @@ -0,0 +1,42 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014 daimajia + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.taobao.luaview.extend.animation.attention; + +import android.animation.AnimatorSet; +import android.animation.ObjectAnimator; +import android.view.View; + +import com.taobao.luaview.extend.animation.BaseViewAnimatorDecoration; + + +public class FlashAnimatorDecoration extends BaseViewAnimatorDecoration { + + @Override + protected void prepare(AnimatorSet animatorSet, View target) { + animatorSet.playTogether( + ObjectAnimator.ofFloat(target, "alpha", 1, 0, 1, 0, 1) + ); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/attention/PulseAnimatorDecoration.java b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/attention/PulseAnimatorDecoration.java new file mode 100644 index 00000000..9800c9da --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/attention/PulseAnimatorDecoration.java @@ -0,0 +1,42 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014 daimajia + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.taobao.luaview.extend.animation.attention; + +import android.animation.AnimatorSet; +import android.animation.ObjectAnimator; +import android.view.View; + +import com.taobao.luaview.extend.animation.BaseViewAnimatorDecoration; + +public class PulseAnimatorDecoration extends BaseViewAnimatorDecoration { + + @Override + protected void prepare(AnimatorSet animatorSet, View target) { + animatorSet.playTogether( + ObjectAnimator.ofFloat(target, "scaleY", 1, 1.1f, 1), + ObjectAnimator.ofFloat(target, "scaleX", 1, 1.1f, 1) + ); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/attention/RubberBandAnimatorDecoration.java b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/attention/RubberBandAnimatorDecoration.java new file mode 100644 index 00000000..cbd5eb6f --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/attention/RubberBandAnimatorDecoration.java @@ -0,0 +1,41 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014 daimajia + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.taobao.luaview.extend.animation.attention; + +import android.animation.AnimatorSet; +import android.animation.ObjectAnimator; +import android.view.View; + +import com.taobao.luaview.extend.animation.BaseViewAnimatorDecoration; + +public class RubberBandAnimatorDecoration extends BaseViewAnimatorDecoration { + @Override + protected void prepare(AnimatorSet animatorSet, View target) { + animatorSet.playTogether( + ObjectAnimator.ofFloat(target, "scaleX", 1, 1.25f, 0.75f, 1.15f, 1), + ObjectAnimator.ofFloat(target, "scaleY", 1, 0.75f, 1.25f, 0.85f, 1) + ); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/attention/ShakeAnimatorDecoration.java b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/attention/ShakeAnimatorDecoration.java new file mode 100644 index 00000000..87b1f047 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/attention/ShakeAnimatorDecoration.java @@ -0,0 +1,42 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014 daimajia + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.taobao.luaview.extend.animation.attention; + + +import android.animation.AnimatorSet; +import android.animation.ObjectAnimator; +import android.view.View; + +import com.taobao.luaview.extend.animation.BaseViewAnimatorDecoration; + + +public class ShakeAnimatorDecoration extends BaseViewAnimatorDecoration { + @Override + protected void prepare(AnimatorSet animatorSet, View target) { + animatorSet.playTogether( + ObjectAnimator.ofFloat(target, "translationX", 0, 25, -25, 25, -25, 15, -15, 6, -6, 0) + ); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/attention/StandUpAnimatorDecoration.java b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/attention/StandUpAnimatorDecoration.java new file mode 100644 index 00000000..60ee2f04 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/attention/StandUpAnimatorDecoration.java @@ -0,0 +1,46 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014 daimajia + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.taobao.luaview.extend.animation.attention; + +import android.animation.AnimatorSet; +import android.animation.ObjectAnimator; +import android.view.View; + +import com.taobao.luaview.extend.animation.BaseViewAnimatorDecoration; + + +public class StandUpAnimatorDecoration extends BaseViewAnimatorDecoration { + @Override + protected void prepare(AnimatorSet animatorSet, View target) { + float x = (target.getWidth() - target.getPaddingLeft() - target.getPaddingRight()) / 2 + + target.getPaddingLeft(); + float y = target.getHeight() - target.getPaddingBottom(); + animatorSet.playTogether( + ObjectAnimator.ofFloat(target, "pivotX", x, x, x, x, x), + ObjectAnimator.ofFloat(target, "pivotY", y, y, y, y, y), + ObjectAnimator.ofFloat(target, "rotationX", 55, -30, 15, -15, 0) + ); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/attention/SwingAnimatorDecoration.java b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/attention/SwingAnimatorDecoration.java new file mode 100644 index 00000000..245b7df6 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/attention/SwingAnimatorDecoration.java @@ -0,0 +1,41 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014 daimajia + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.taobao.luaview.extend.animation.attention; + +import android.animation.AnimatorSet; +import android.animation.ObjectAnimator; +import android.view.View; + +import com.taobao.luaview.extend.animation.BaseViewAnimatorDecoration; + +public class SwingAnimatorDecoration extends BaseViewAnimatorDecoration { + + @Override + protected void prepare(AnimatorSet animatorSet, View target) { + animatorSet.playTogether( + ObjectAnimator.ofFloat(target, "rotation", 0, 10, -10, 6, -6, 3, -3, 0) + ); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/attention/TadaAnimatorDecoration.java b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/attention/TadaAnimatorDecoration.java new file mode 100644 index 00000000..e7111bf4 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/attention/TadaAnimatorDecoration.java @@ -0,0 +1,44 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014 daimajia + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.taobao.luaview.extend.animation.attention; + +import android.animation.AnimatorSet; +import android.animation.ObjectAnimator; +import android.view.View; + +import com.taobao.luaview.extend.animation.BaseViewAnimatorDecoration; + + +public class TadaAnimatorDecoration extends BaseViewAnimatorDecoration { + + @Override + protected void prepare(AnimatorSet animatorSet, View target) { + animatorSet.playTogether( + ObjectAnimator.ofFloat(target, "scaleX", 1, 0.9f, 0.9f, 1.1f, 1.1f, 1.1f, 1.1f, 1.1f, 1.1f, 1), + ObjectAnimator.ofFloat(target, "scaleY", 1, 0.9f, 0.9f, 1.1f, 1.1f, 1.1f, 1.1f, 1.1f, 1.1f, 1), + ObjectAnimator.ofFloat(target, "rotation", 0, -3, -3, 3, -3, 3, -3, 3, -3, 0) + ); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/attention/WaveAnimatorDecoration.java b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/attention/WaveAnimatorDecoration.java new file mode 100644 index 00000000..a304c9e3 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/attention/WaveAnimatorDecoration.java @@ -0,0 +1,45 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014 daimajia + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.taobao.luaview.extend.animation.attention; + +import android.animation.AnimatorSet; +import android.animation.ObjectAnimator; +import android.view.View; + +import com.taobao.luaview.extend.animation.BaseViewAnimatorDecoration; + +public class WaveAnimatorDecoration extends BaseViewAnimatorDecoration { + @Override + protected void prepare(AnimatorSet animatorSet, View target) { + float x = (target.getWidth() - target.getPaddingLeft() - target.getPaddingRight()) / 2 + + target.getPaddingLeft(); + float y = target.getHeight() - target.getPaddingBottom(); + animatorSet.playTogether( + ObjectAnimator.ofFloat(target, "rotation", 12, -12, 3, -3, 0), + ObjectAnimator.ofFloat(target, "pivotX", x, x, x, x, x), + ObjectAnimator.ofFloat(target, "pivotY", y, y, y, y, y) + ); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/attention/WobbleAnimatorDecoration.java b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/attention/WobbleAnimatorDecoration.java new file mode 100644 index 00000000..b6858f16 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/attention/WobbleAnimatorDecoration.java @@ -0,0 +1,44 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014 daimajia + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.taobao.luaview.extend.animation.attention; + +import android.animation.AnimatorSet; +import android.animation.ObjectAnimator; +import android.view.View; + +import com.taobao.luaview.extend.animation.BaseViewAnimatorDecoration; + + +public class WobbleAnimatorDecoration extends BaseViewAnimatorDecoration { + @Override + protected void prepare(AnimatorSet animatorSet, View target) { + float width = target.getWidth(); + float one = (float) (width / 100.0); + animatorSet.playTogether( + ObjectAnimator.ofFloat(target, "translationX", 0 * one, -25 * one, 20 * one, -15 * one, 10 * one, -5 * one, 0 * one, 0), + ObjectAnimator.ofFloat(target, "rotation", 0, -5, 3, -3, 2, -1, 0) + ); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/bouncing_entrances/BounceInAnimatorDecoration.java b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/bouncing_entrances/BounceInAnimatorDecoration.java new file mode 100644 index 00000000..49eb6183 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/bouncing_entrances/BounceInAnimatorDecoration.java @@ -0,0 +1,43 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014 daimajia + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.taobao.luaview.extend.animation.bouncing_entrances; + +import android.animation.AnimatorSet; +import android.animation.ObjectAnimator; +import android.view.View; + +import com.taobao.luaview.extend.animation.BaseViewAnimatorDecoration; + + +public class BounceInAnimatorDecoration extends BaseViewAnimatorDecoration { + @Override + protected void prepare(AnimatorSet animatorSet, View target) { + animatorSet.playTogether( + ObjectAnimator.ofFloat(target, "alpha", 0, 1, 1, 1), + ObjectAnimator.ofFloat(target, "scaleX", 0.3f, 1.05f, 0.9f, 1), + ObjectAnimator.ofFloat(target, "scaleY", 0.3f, 1.05f, 0.9f, 1) + ); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/bouncing_entrances/BounceInDownAnimatorDecoration.java b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/bouncing_entrances/BounceInDownAnimatorDecoration.java new file mode 100644 index 00000000..62c78522 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/bouncing_entrances/BounceInDownAnimatorDecoration.java @@ -0,0 +1,41 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014 daimajia + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.taobao.luaview.extend.animation.bouncing_entrances; + +import android.animation.AnimatorSet; +import android.animation.ObjectAnimator; +import android.view.View; + +import com.taobao.luaview.extend.animation.BaseViewAnimatorDecoration; + +public class BounceInDownAnimatorDecoration extends BaseViewAnimatorDecoration { + @Override + protected void prepare(AnimatorSet animatorSet, View target) { + animatorSet.playTogether( + ObjectAnimator.ofFloat(target, "alpha", 0, 1, 1, 1), + ObjectAnimator.ofFloat(target,"translationY",-target.getHeight(),30,-10,0) + ); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/bouncing_entrances/BounceInLeftAnimatorDecoration.java b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/bouncing_entrances/BounceInLeftAnimatorDecoration.java new file mode 100644 index 00000000..76f23a6a --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/bouncing_entrances/BounceInLeftAnimatorDecoration.java @@ -0,0 +1,43 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014 daimajia + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.taobao.luaview.extend.animation.bouncing_entrances; + +import android.animation.AnimatorSet; +import android.animation.ObjectAnimator; +import android.view.View; + +import com.taobao.luaview.extend.animation.BaseViewAnimatorDecoration; + + +public class BounceInLeftAnimatorDecoration extends BaseViewAnimatorDecoration { + @Override + protected void prepare(AnimatorSet animatorSet, View target) { + animatorSet.playTogether( + ObjectAnimator.ofFloat(target, "translationX", -target.getWidth(), 30, -10, 0), + ObjectAnimator.ofFloat(target, "alpha", 0, 1, 1, 1) + ); + } +} + diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/bouncing_entrances/BounceInRightAnimatorDecoration.java b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/bouncing_entrances/BounceInRightAnimatorDecoration.java new file mode 100644 index 00000000..91a78067 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/bouncing_entrances/BounceInRightAnimatorDecoration.java @@ -0,0 +1,42 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014 daimajia + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.taobao.luaview.extend.animation.bouncing_entrances; + +import android.animation.AnimatorSet; +import android.animation.ObjectAnimator; +import android.view.View; + +import com.taobao.luaview.extend.animation.BaseViewAnimatorDecoration; + + +public class BounceInRightAnimatorDecoration extends BaseViewAnimatorDecoration { + @Override + protected void prepare(AnimatorSet animatorSet, View target) { + animatorSet.playTogether( + ObjectAnimator.ofFloat(target, "translationX", target.getMeasuredWidth() + target.getWidth(), -30, 10, 0), + ObjectAnimator.ofFloat(target, "alpha", 0, 1, 1, 1) + ); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/bouncing_entrances/BounceInUpAnimatorDecoration.java b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/bouncing_entrances/BounceInUpAnimatorDecoration.java new file mode 100644 index 00000000..663442c0 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/bouncing_entrances/BounceInUpAnimatorDecoration.java @@ -0,0 +1,43 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014 daimajia + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.taobao.luaview.extend.animation.bouncing_entrances; + +import android.animation.AnimatorSet; +import android.animation.ObjectAnimator; +import android.view.View; + +import com.taobao.luaview.extend.animation.BaseViewAnimatorDecoration; + + +public class BounceInUpAnimatorDecoration extends BaseViewAnimatorDecoration { + + @Override + protected void prepare(AnimatorSet animatorSet, View target) { + animatorSet.playTogether( + ObjectAnimator.ofFloat(target, "translationY", target.getMeasuredHeight(), -30, 10, 0), + ObjectAnimator.ofFloat(target, "alpha", 0, 1, 1, 1) + ); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/fading_entrances/FadeInAnimatorDecoration.java b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/fading_entrances/FadeInAnimatorDecoration.java new file mode 100644 index 00000000..e800f255 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/fading_entrances/FadeInAnimatorDecoration.java @@ -0,0 +1,41 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014 daimajia + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.taobao.luaview.extend.animation.fading_entrances; + + +import android.animation.AnimatorSet; +import android.animation.ObjectAnimator; +import android.view.View; + +import com.taobao.luaview.extend.animation.BaseViewAnimatorDecoration; + +public class FadeInAnimatorDecoration extends BaseViewAnimatorDecoration { + @Override + protected void prepare(AnimatorSet animatorSet, View target) { + animatorSet.playTogether( + ObjectAnimator.ofFloat(target, "alpha", 0, 1) + ); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/fading_entrances/FadeInDownAnimatorDecoration.java b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/fading_entrances/FadeInDownAnimatorDecoration.java new file mode 100644 index 00000000..5f7e1bb9 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/fading_entrances/FadeInDownAnimatorDecoration.java @@ -0,0 +1,42 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014 daimajia + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.taobao.luaview.extend.animation.fading_entrances; + + +import android.animation.AnimatorSet; +import android.animation.ObjectAnimator; +import android.view.View; + +import com.taobao.luaview.extend.animation.BaseViewAnimatorDecoration; + +public class FadeInDownAnimatorDecoration extends BaseViewAnimatorDecoration { + @Override + protected void prepare(AnimatorSet animatorSet, View target) { + animatorSet.playTogether( + ObjectAnimator.ofFloat(target, "alpha", 0, 1), + ObjectAnimator.ofFloat(target, "translationY", -target.getHeight() / 4, 0) + ); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/fading_entrances/FadeInLeftAnimatorDecoration.java b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/fading_entrances/FadeInLeftAnimatorDecoration.java new file mode 100644 index 00000000..841fad70 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/fading_entrances/FadeInLeftAnimatorDecoration.java @@ -0,0 +1,42 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014 daimajia + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.taobao.luaview.extend.animation.fading_entrances; + +import android.animation.AnimatorSet; +import android.animation.ObjectAnimator; +import android.view.View; + +import com.taobao.luaview.extend.animation.BaseViewAnimatorDecoration; + + +public class FadeInLeftAnimatorDecoration extends BaseViewAnimatorDecoration { + @Override + protected void prepare(AnimatorSet animatorSet, View target) { + animatorSet.playTogether( + ObjectAnimator.ofFloat(target, "alpha", 0, 1), + ObjectAnimator.ofFloat(target, "translationX", -target.getWidth() / 4, 0) + ); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/fading_entrances/FadeInRightAnimatorDecoration.java b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/fading_entrances/FadeInRightAnimatorDecoration.java new file mode 100644 index 00000000..6cdfb5f7 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/fading_entrances/FadeInRightAnimatorDecoration.java @@ -0,0 +1,42 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014 daimajia + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.taobao.luaview.extend.animation.fading_entrances; + + +import android.animation.AnimatorSet; +import android.animation.ObjectAnimator; +import android.view.View; + +import com.taobao.luaview.extend.animation.BaseViewAnimatorDecoration; + +public class FadeInRightAnimatorDecoration extends BaseViewAnimatorDecoration { + @Override + protected void prepare(AnimatorSet animatorSet, View target) { + animatorSet.playTogether( + ObjectAnimator.ofFloat(target, "alpha", 0, 1), + ObjectAnimator.ofFloat(target, "translationX", target.getWidth() / 4, 0) + ); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/fading_entrances/FadeInUpAnimatorDecoration.java b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/fading_entrances/FadeInUpAnimatorDecoration.java new file mode 100644 index 00000000..96d95b10 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/fading_entrances/FadeInUpAnimatorDecoration.java @@ -0,0 +1,42 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014 daimajia + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.taobao.luaview.extend.animation.fading_entrances; + + +import android.animation.AnimatorSet; +import android.animation.ObjectAnimator; +import android.view.View; + +import com.taobao.luaview.extend.animation.BaseViewAnimatorDecoration; + +public class FadeInUpAnimatorDecoration extends BaseViewAnimatorDecoration { + @Override + protected void prepare(AnimatorSet animatorSet, View target) { + animatorSet.playTogether( + ObjectAnimator.ofFloat(target, "alpha", 0, 1), + ObjectAnimator.ofFloat(target, "translationY", target.getHeight() / 4, 0) + ); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/fading_exits/FadeOutAnimatorDecoration.java b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/fading_exits/FadeOutAnimatorDecoration.java new file mode 100644 index 00000000..4120eaef --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/fading_exits/FadeOutAnimatorDecoration.java @@ -0,0 +1,41 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014 daimajia + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.taobao.luaview.extend.animation.fading_exits; + +import android.animation.AnimatorSet; +import android.animation.ObjectAnimator; +import android.view.View; + +import com.taobao.luaview.extend.animation.BaseViewAnimatorDecoration; + + +public class FadeOutAnimatorDecoration extends BaseViewAnimatorDecoration { + @Override + protected void prepare(AnimatorSet animatorSet, View target) { + animatorSet.playTogether( + ObjectAnimator.ofFloat(target, "alpha", 1, 0) + ); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/fading_exits/FadeOutDownAnimatorDecoration.java b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/fading_exits/FadeOutDownAnimatorDecoration.java new file mode 100644 index 00000000..4d141530 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/fading_exits/FadeOutDownAnimatorDecoration.java @@ -0,0 +1,42 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014 daimajia + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.taobao.luaview.extend.animation.fading_exits; + + +import android.animation.AnimatorSet; +import android.animation.ObjectAnimator; +import android.view.View; + +import com.taobao.luaview.extend.animation.BaseViewAnimatorDecoration; + +public class FadeOutDownAnimatorDecoration extends BaseViewAnimatorDecoration { + @Override + protected void prepare(AnimatorSet animatorSet, View target) { + animatorSet.playTogether( + ObjectAnimator.ofFloat(target, "alpha", 1, 0), + ObjectAnimator.ofFloat(target, "translationY", 0, target.getHeight() / 4) + ); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/fading_exits/FadeOutLeftAnimatorDecoration.java b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/fading_exits/FadeOutLeftAnimatorDecoration.java new file mode 100644 index 00000000..64a766ad --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/fading_exits/FadeOutLeftAnimatorDecoration.java @@ -0,0 +1,42 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014 daimajia + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.taobao.luaview.extend.animation.fading_exits; + + +import android.animation.AnimatorSet; +import android.animation.ObjectAnimator; +import android.view.View; + +import com.taobao.luaview.extend.animation.BaseViewAnimatorDecoration; + +public class FadeOutLeftAnimatorDecoration extends BaseViewAnimatorDecoration { + @Override + protected void prepare(AnimatorSet animatorSet, View target) { + animatorSet.playTogether( + ObjectAnimator.ofFloat(target, "alpha", 1, 0), + ObjectAnimator.ofFloat(target, "translationX", 0, -target.getWidth() / 4) + ); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/fading_exits/FadeOutRightAnimatorDecoration.java b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/fading_exits/FadeOutRightAnimatorDecoration.java new file mode 100644 index 00000000..8a1dda1e --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/fading_exits/FadeOutRightAnimatorDecoration.java @@ -0,0 +1,42 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014 daimajia + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.taobao.luaview.extend.animation.fading_exits; + + +import android.animation.AnimatorSet; +import android.animation.ObjectAnimator; +import android.view.View; + +import com.taobao.luaview.extend.animation.BaseViewAnimatorDecoration; + +public class FadeOutRightAnimatorDecoration extends BaseViewAnimatorDecoration { + @Override + protected void prepare(AnimatorSet animatorSet, View target) { + animatorSet.playTogether( + ObjectAnimator.ofFloat(target, "alpha", 1, 0), + ObjectAnimator.ofFloat(target, "translationX", 0, target.getWidth() / 4) + ); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/fading_exits/FadeOutUpAnimatorDecoration.java b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/fading_exits/FadeOutUpAnimatorDecoration.java new file mode 100644 index 00000000..9ab3fc1d --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/fading_exits/FadeOutUpAnimatorDecoration.java @@ -0,0 +1,42 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014 daimajia + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.taobao.luaview.extend.animation.fading_exits; + + +import android.animation.AnimatorSet; +import android.animation.ObjectAnimator; +import android.view.View; + +import com.taobao.luaview.extend.animation.BaseViewAnimatorDecoration; + +public class FadeOutUpAnimatorDecoration extends BaseViewAnimatorDecoration { + @Override + protected void prepare(AnimatorSet animatorSet, View target) { + animatorSet.playTogether( + ObjectAnimator.ofFloat(target, "alpha", 1, 0), + ObjectAnimator.ofFloat(target, "translationY", 0, -target.getHeight() / 4) + ); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/flippers/FlipInXAnimatorDecoration.java b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/flippers/FlipInXAnimatorDecoration.java new file mode 100644 index 00000000..cda580f0 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/flippers/FlipInXAnimatorDecoration.java @@ -0,0 +1,42 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014 daimajia + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.taobao.luaview.extend.animation.flippers; + + +import android.animation.AnimatorSet; +import android.animation.ObjectAnimator; +import android.view.View; + +import com.taobao.luaview.extend.animation.BaseViewAnimatorDecoration; + +public class FlipInXAnimatorDecoration extends BaseViewAnimatorDecoration { + @Override + protected void prepare(AnimatorSet animatorSet, View target) { + animatorSet.playTogether( + ObjectAnimator.ofFloat(target, "rotationX", 90, -15, 15, 0), + ObjectAnimator.ofFloat(target, "alpha", 0.25f, 0.5f, 0.75f, 1) + ); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/flippers/FlipInYAnimatorDecoration.java b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/flippers/FlipInYAnimatorDecoration.java new file mode 100644 index 00000000..c506d76d --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/flippers/FlipInYAnimatorDecoration.java @@ -0,0 +1,42 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014 daimajia + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.taobao.luaview.extend.animation.flippers; + + +import android.animation.AnimatorSet; +import android.animation.ObjectAnimator; +import android.view.View; + +import com.taobao.luaview.extend.animation.BaseViewAnimatorDecoration; + +public class FlipInYAnimatorDecoration extends BaseViewAnimatorDecoration { + @Override + protected void prepare(AnimatorSet animatorSet, View target) { + animatorSet.playTogether( + ObjectAnimator.ofFloat(target, "rotationY", 90, -15, 15, 0), + ObjectAnimator.ofFloat(target, "alpha", 0.25f, 0.5f, 0.75f, 1) + ); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/flippers/FlipOutXAnimatorDecoration.java b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/flippers/FlipOutXAnimatorDecoration.java new file mode 100644 index 00000000..8e09a3fd --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/flippers/FlipOutXAnimatorDecoration.java @@ -0,0 +1,42 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014 daimajia + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.taobao.luaview.extend.animation.flippers; + + +import android.animation.AnimatorSet; +import android.animation.ObjectAnimator; +import android.view.View; + +import com.taobao.luaview.extend.animation.BaseViewAnimatorDecoration; + +public class FlipOutXAnimatorDecoration extends BaseViewAnimatorDecoration { + @Override + protected void prepare(AnimatorSet animatorSet, View target) { + animatorSet.playTogether( + ObjectAnimator.ofFloat(target, "rotationX", 0, 90), + ObjectAnimator.ofFloat(target, "alpha", 1, 0) + ); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/flippers/FlipOutYAnimatorDecoration.java b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/flippers/FlipOutYAnimatorDecoration.java new file mode 100644 index 00000000..964b46f3 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/flippers/FlipOutYAnimatorDecoration.java @@ -0,0 +1,42 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014 daimajia + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.taobao.luaview.extend.animation.flippers; + + +import android.animation.AnimatorSet; +import android.animation.ObjectAnimator; +import android.view.View; + +import com.taobao.luaview.extend.animation.BaseViewAnimatorDecoration; + +public class FlipOutYAnimatorDecoration extends BaseViewAnimatorDecoration { + @Override + protected void prepare(AnimatorSet animatorSet, View target) { + animatorSet.playTogether( + ObjectAnimator.ofFloat(target, "rotationY", 0, 90), + ObjectAnimator.ofFloat(target, "alpha", 1, 0) + ); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/rotating_entrances/RotateInAnimatorDecoration.java b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/rotating_entrances/RotateInAnimatorDecoration.java new file mode 100644 index 00000000..91e07409 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/rotating_entrances/RotateInAnimatorDecoration.java @@ -0,0 +1,42 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014 daimajia + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.taobao.luaview.extend.animation.rotating_entrances; + + +import android.animation.AnimatorSet; +import android.animation.ObjectAnimator; +import android.view.View; + +import com.taobao.luaview.extend.animation.BaseViewAnimatorDecoration; + +public class RotateInAnimatorDecoration extends BaseViewAnimatorDecoration { + @Override + protected void prepare(AnimatorSet animatorSet, View target) { + animatorSet.playTogether( + ObjectAnimator.ofFloat(target, "rotation", -200, 0), + ObjectAnimator.ofFloat(target, "alpha", 0, 1) + ); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/rotating_entrances/RotateInDownLeftAnimatorDecoration.java b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/rotating_entrances/RotateInDownLeftAnimatorDecoration.java new file mode 100644 index 00000000..f58b6f09 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/rotating_entrances/RotateInDownLeftAnimatorDecoration.java @@ -0,0 +1,46 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014 daimajia + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.taobao.luaview.extend.animation.rotating_entrances; + + +import android.animation.AnimatorSet; +import android.animation.ObjectAnimator; +import android.view.View; + +import com.taobao.luaview.extend.animation.BaseViewAnimatorDecoration; + +public class RotateInDownLeftAnimatorDecoration extends BaseViewAnimatorDecoration { + @Override + protected void prepare(AnimatorSet animatorSet, View target) { + float x = target.getPaddingLeft(); + float y = target.getHeight() - target.getPaddingBottom(); + animatorSet.playTogether( + ObjectAnimator.ofFloat(target, "rotation", -90, 0), + ObjectAnimator.ofFloat(target, "alpha", 0, 1), + ObjectAnimator.ofFloat(target, "pivotX", x, x), + ObjectAnimator.ofFloat(target, "pivotY", y, y) + ); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/rotating_entrances/RotateInDownRightAnimatorDecoration.java b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/rotating_entrances/RotateInDownRightAnimatorDecoration.java new file mode 100644 index 00000000..5b8cbc1d --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/rotating_entrances/RotateInDownRightAnimatorDecoration.java @@ -0,0 +1,46 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014 daimajia + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.taobao.luaview.extend.animation.rotating_entrances; + + +import android.animation.AnimatorSet; +import android.animation.ObjectAnimator; +import android.view.View; + +import com.taobao.luaview.extend.animation.BaseViewAnimatorDecoration; + +public class RotateInDownRightAnimatorDecoration extends BaseViewAnimatorDecoration { + @Override + protected void prepare(AnimatorSet animatorSet, View target) { + float x = target.getWidth() - target.getPaddingRight(); + float y = target.getHeight() - target.getPaddingBottom(); + animatorSet.playTogether( + ObjectAnimator.ofFloat(target, "rotation", 90, 0), + ObjectAnimator.ofFloat(target, "alpha", 0, 1), + ObjectAnimator.ofFloat(target, "pivotX", x, x), + ObjectAnimator.ofFloat(target, "pivotY", y, y) + ); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/rotating_entrances/RotateInUpLeftAnimatorDecoration.java b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/rotating_entrances/RotateInUpLeftAnimatorDecoration.java new file mode 100644 index 00000000..d47bce84 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/rotating_entrances/RotateInUpLeftAnimatorDecoration.java @@ -0,0 +1,46 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014 daimajia + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.taobao.luaview.extend.animation.rotating_entrances; + + +import android.animation.AnimatorSet; +import android.animation.ObjectAnimator; +import android.view.View; + +import com.taobao.luaview.extend.animation.BaseViewAnimatorDecoration; + +public class RotateInUpLeftAnimatorDecoration extends BaseViewAnimatorDecoration { + @Override + protected void prepare(AnimatorSet animatorSet, View target) { + float x = target.getPaddingLeft(); + float y = target.getHeight() - target.getPaddingBottom(); + animatorSet.playTogether( + ObjectAnimator.ofFloat(target, "rotation", 90, 0), + ObjectAnimator.ofFloat(target, "alpha", 0, 1), + ObjectAnimator.ofFloat(target, "pivotX", x, x), + ObjectAnimator.ofFloat(target, "pivotY", y, y) + ); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/rotating_entrances/RotateInUpRightAnimatorDecoration.java b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/rotating_entrances/RotateInUpRightAnimatorDecoration.java new file mode 100644 index 00000000..dec75e36 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/rotating_entrances/RotateInUpRightAnimatorDecoration.java @@ -0,0 +1,46 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014 daimajia + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.taobao.luaview.extend.animation.rotating_entrances; + + +import android.animation.AnimatorSet; +import android.animation.ObjectAnimator; +import android.view.View; + +import com.taobao.luaview.extend.animation.BaseViewAnimatorDecoration; + +public class RotateInUpRightAnimatorDecoration extends BaseViewAnimatorDecoration { + @Override + protected void prepare(AnimatorSet animatorSet, View target) { + float x = target.getWidth() - target.getPaddingRight(); + float y = target.getHeight() - target.getPaddingBottom(); + animatorSet.playTogether( + ObjectAnimator.ofFloat(target, "rotation", -90, 0), + ObjectAnimator.ofFloat(target, "alpha", 0, 1), + ObjectAnimator.ofFloat(target, "pivotX", x, x), + ObjectAnimator.ofFloat(target, "pivotY", y, y) + ); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/rotating_exits/RotateOutAnimatorDecoration.java b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/rotating_exits/RotateOutAnimatorDecoration.java new file mode 100644 index 00000000..9c231f9d --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/rotating_exits/RotateOutAnimatorDecoration.java @@ -0,0 +1,42 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014 daimajia + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.taobao.luaview.extend.animation.rotating_exits; + + +import android.animation.AnimatorSet; +import android.animation.ObjectAnimator; +import android.view.View; + +import com.taobao.luaview.extend.animation.BaseViewAnimatorDecoration; + +public class RotateOutAnimatorDecoration extends BaseViewAnimatorDecoration { + @Override + protected void prepare(AnimatorSet animatorSet, View target) { + animatorSet.playTogether( + ObjectAnimator.ofFloat(target, "alpha", 1, 0), + ObjectAnimator.ofFloat(target, "rotation", 0, 200) + ); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/rotating_exits/RotateOutDownLeftAnimatorDecoration.java b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/rotating_exits/RotateOutDownLeftAnimatorDecoration.java new file mode 100644 index 00000000..1f4b64b3 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/rotating_exits/RotateOutDownLeftAnimatorDecoration.java @@ -0,0 +1,46 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014 daimajia + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.taobao.luaview.extend.animation.rotating_exits; + + +import android.animation.AnimatorSet; +import android.animation.ObjectAnimator; +import android.view.View; + +import com.taobao.luaview.extend.animation.BaseViewAnimatorDecoration; + +public class RotateOutDownLeftAnimatorDecoration extends BaseViewAnimatorDecoration { + @Override + protected void prepare(AnimatorSet animatorSet, View target) { + float x = target.getPaddingLeft(); + float y = target.getHeight() - target.getPaddingBottom(); + animatorSet.playTogether( + ObjectAnimator.ofFloat(target, "alpha", 1, 0), + ObjectAnimator.ofFloat(target, "rotation", 0, 90), + ObjectAnimator.ofFloat(target, "pivotX", x, x), + ObjectAnimator.ofFloat(target, "pivotY", y, y) + ); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/rotating_exits/RotateOutDownRightAnimatorDecoration.java b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/rotating_exits/RotateOutDownRightAnimatorDecoration.java new file mode 100644 index 00000000..409b8cca --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/rotating_exits/RotateOutDownRightAnimatorDecoration.java @@ -0,0 +1,46 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014 daimajia + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.taobao.luaview.extend.animation.rotating_exits; + + +import android.animation.AnimatorSet; +import android.animation.ObjectAnimator; +import android.view.View; + +import com.taobao.luaview.extend.animation.BaseViewAnimatorDecoration; + +public class RotateOutDownRightAnimatorDecoration extends BaseViewAnimatorDecoration { + @Override + protected void prepare(AnimatorSet animatorSet, View target) { + float x = target.getWidth() - target.getPaddingRight(); + float y = target.getHeight() - target.getPaddingBottom(); + animatorSet.playTogether( + ObjectAnimator.ofFloat(target, "alpha", 1, 0), + ObjectAnimator.ofFloat(target, "rotation", 0, -90), + ObjectAnimator.ofFloat(target, "pivotX", x, x), + ObjectAnimator.ofFloat(target, "pivotY", y, y) + ); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/rotating_exits/RotateOutUpLeftAnimatorDecoration.java b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/rotating_exits/RotateOutUpLeftAnimatorDecoration.java new file mode 100644 index 00000000..23786a0b --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/rotating_exits/RotateOutUpLeftAnimatorDecoration.java @@ -0,0 +1,46 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014 daimajia + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.taobao.luaview.extend.animation.rotating_exits; + + +import android.animation.AnimatorSet; +import android.animation.ObjectAnimator; +import android.view.View; + +import com.taobao.luaview.extend.animation.BaseViewAnimatorDecoration; + +public class RotateOutUpLeftAnimatorDecoration extends BaseViewAnimatorDecoration { + @Override + protected void prepare(AnimatorSet animatorSet, View target) { + float x = target.getPaddingLeft(); + float y = target.getHeight() - target.getPaddingBottom(); + animatorSet.playTogether( + ObjectAnimator.ofFloat(target, "alpha", 1, 0), + ObjectAnimator.ofFloat(target, "rotation", 0, -90), + ObjectAnimator.ofFloat(target, "pivotX", x, x), + ObjectAnimator.ofFloat(target, "pivotY", y, y) + ); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/rotating_exits/RotateOutUpRightAnimatorDecoration.java b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/rotating_exits/RotateOutUpRightAnimatorDecoration.java new file mode 100644 index 00000000..884f250c --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/rotating_exits/RotateOutUpRightAnimatorDecoration.java @@ -0,0 +1,46 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014 daimajia + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.taobao.luaview.extend.animation.rotating_exits; + + +import android.animation.AnimatorSet; +import android.animation.ObjectAnimator; +import android.view.View; + +import com.taobao.luaview.extend.animation.BaseViewAnimatorDecoration; + +public class RotateOutUpRightAnimatorDecoration extends BaseViewAnimatorDecoration { + @Override + protected void prepare(AnimatorSet animatorSet, View target) { + float x = target.getWidth() - target.getPaddingRight(); + float y = target.getHeight() - target.getPaddingBottom(); + animatorSet.playTogether( + ObjectAnimator.ofFloat(target, "alpha", 1, 0), + ObjectAnimator.ofFloat(target, "rotation", 0, 90), + ObjectAnimator.ofFloat(target, "pivotX", x, x), + ObjectAnimator.ofFloat(target, "pivotY", y, y) + ); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/sliders/SlideInDownAnimatorDecoration.java b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/sliders/SlideInDownAnimatorDecoration.java new file mode 100644 index 00000000..692ea104 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/sliders/SlideInDownAnimatorDecoration.java @@ -0,0 +1,42 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014 daimajia + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.taobao.luaview.extend.animation.sliders; + +import android.animation.AnimatorSet; +import android.animation.ObjectAnimator; +import android.view.View; + +import com.taobao.luaview.extend.animation.BaseViewAnimatorDecoration; + +public class SlideInDownAnimatorDecoration extends BaseViewAnimatorDecoration { + @Override + protected void prepare(AnimatorSet animatorSet, View target) { + int distance = target.getTop() + target.getHeight(); + animatorSet.playTogether( + ObjectAnimator.ofFloat(target, "alpha", 0, 1), + ObjectAnimator.ofFloat(target, "translationY", -distance, 0) + ); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/sliders/SlideInLeftAnimatorDecoration.java b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/sliders/SlideInLeftAnimatorDecoration.java new file mode 100644 index 00000000..bccefc62 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/sliders/SlideInLeftAnimatorDecoration.java @@ -0,0 +1,45 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014 daimajia + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.taobao.luaview.extend.animation.sliders; + + +import android.animation.AnimatorSet; +import android.animation.ObjectAnimator; +import android.view.View; +import android.view.ViewGroup; + +import com.taobao.luaview.extend.animation.BaseViewAnimatorDecoration; + +public class SlideInLeftAnimatorDecoration extends BaseViewAnimatorDecoration { + @Override + protected void prepare(AnimatorSet animatorSet, View target) { + ViewGroup parent = (ViewGroup) target.getParent(); + int distance = parent.getWidth() - target.getLeft(); + animatorSet.playTogether( + ObjectAnimator.ofFloat(target, "alpha", 0, 1), + ObjectAnimator.ofFloat(target, "translationX", -distance, 0) + ); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/sliders/SlideInRightAnimatorDecoration.java b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/sliders/SlideInRightAnimatorDecoration.java new file mode 100644 index 00000000..8559623a --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/sliders/SlideInRightAnimatorDecoration.java @@ -0,0 +1,44 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014 daimajia + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.taobao.luaview.extend.animation.sliders; + +import android.animation.AnimatorSet; +import android.animation.ObjectAnimator; +import android.view.View; +import android.view.ViewGroup; + +import com.taobao.luaview.extend.animation.BaseViewAnimatorDecoration; + +public class SlideInRightAnimatorDecoration extends BaseViewAnimatorDecoration { + @Override + protected void prepare(AnimatorSet animatorSet, View target) { + ViewGroup parent = (ViewGroup) target.getParent(); + int distance = parent.getWidth() - target.getLeft(); + animatorSet.playTogether( + ObjectAnimator.ofFloat(target, "alpha", 0, 1), + ObjectAnimator.ofFloat(target, "translationX", distance, 0) + ); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/sliders/SlideInUpAnimatorDecoration.java b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/sliders/SlideInUpAnimatorDecoration.java new file mode 100644 index 00000000..e6288801 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/sliders/SlideInUpAnimatorDecoration.java @@ -0,0 +1,45 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014 daimajia + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.taobao.luaview.extend.animation.sliders; + + +import android.animation.AnimatorSet; +import android.animation.ObjectAnimator; +import android.view.View; +import android.view.ViewGroup; + +import com.taobao.luaview.extend.animation.BaseViewAnimatorDecoration; + +public class SlideInUpAnimatorDecoration extends BaseViewAnimatorDecoration { + @Override + protected void prepare(AnimatorSet animatorSet, View target) { + ViewGroup parent = (ViewGroup) target.getParent(); + int distance = parent.getHeight() - target.getTop(); + animatorSet.playTogether( + ObjectAnimator.ofFloat(target, "alpha", 0, 1), + ObjectAnimator.ofFloat(target, "translationY", distance, 0) + ); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/sliders/SlideOutDownAnimatorDecoration.java b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/sliders/SlideOutDownAnimatorDecoration.java new file mode 100644 index 00000000..508f871e --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/sliders/SlideOutDownAnimatorDecoration.java @@ -0,0 +1,45 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014 daimajia + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.taobao.luaview.extend.animation.sliders; + + +import android.animation.AnimatorSet; +import android.animation.ObjectAnimator; +import android.view.View; +import android.view.ViewGroup; + +import com.taobao.luaview.extend.animation.BaseViewAnimatorDecoration; + +public class SlideOutDownAnimatorDecoration extends BaseViewAnimatorDecoration { + @Override + protected void prepare(AnimatorSet animatorSet, View target) { + ViewGroup parent = (ViewGroup) target.getParent(); + int distance = parent.getHeight() - target.getTop(); + animatorSet.playTogether( + ObjectAnimator.ofFloat(target, "alpha", 1, 0), + ObjectAnimator.ofFloat(target, "translationY", 0, distance) + ); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/sliders/SlideOutLeftAnimatorDecoration.java b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/sliders/SlideOutLeftAnimatorDecoration.java new file mode 100644 index 00000000..4c0da2d2 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/sliders/SlideOutLeftAnimatorDecoration.java @@ -0,0 +1,42 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014 daimajia + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.taobao.luaview.extend.animation.sliders; + + +import android.animation.AnimatorSet; +import android.animation.ObjectAnimator; +import android.view.View; + +import com.taobao.luaview.extend.animation.BaseViewAnimatorDecoration; + +public class SlideOutLeftAnimatorDecoration extends BaseViewAnimatorDecoration { + @Override + protected void prepare(AnimatorSet animatorSet, View target) { + animatorSet.playTogether( + ObjectAnimator.ofFloat(target, "alpha", 1, 0), + ObjectAnimator.ofFloat(target, "translationX", 0, -target.getRight()) + ); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/sliders/SlideOutRightAnimatorDecoration.java b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/sliders/SlideOutRightAnimatorDecoration.java new file mode 100644 index 00000000..bea9713d --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/sliders/SlideOutRightAnimatorDecoration.java @@ -0,0 +1,45 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014 daimajia + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.taobao.luaview.extend.animation.sliders; + + +import android.animation.AnimatorSet; +import android.animation.ObjectAnimator; +import android.view.View; +import android.view.ViewGroup; + +import com.taobao.luaview.extend.animation.BaseViewAnimatorDecoration; + +public class SlideOutRightAnimatorDecoration extends BaseViewAnimatorDecoration { + @Override + protected void prepare(AnimatorSet animatorSet, View target) { + ViewGroup parent = (ViewGroup) target.getParent(); + int distance = parent.getWidth() - target.getLeft(); + animatorSet.playTogether( + ObjectAnimator.ofFloat(target, "alpha", 1, 0), + ObjectAnimator.ofFloat(target, "translationX", 0, distance) + ); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/sliders/SlideOutUpAnimatorDecoration.java b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/sliders/SlideOutUpAnimatorDecoration.java new file mode 100644 index 00000000..33d95b63 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/sliders/SlideOutUpAnimatorDecoration.java @@ -0,0 +1,44 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014 daimajia + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.taobao.luaview.extend.animation.sliders; + + +import android.animation.AnimatorSet; +import android.animation.ObjectAnimator; +import android.view.View; +import android.view.ViewGroup; + +import com.taobao.luaview.extend.animation.BaseViewAnimatorDecoration; + +public class SlideOutUpAnimatorDecoration extends BaseViewAnimatorDecoration { + @Override + protected void prepare(AnimatorSet animatorSet, View target) { + ViewGroup parent = (ViewGroup) target.getParent(); + animatorSet.playTogether( + ObjectAnimator.ofFloat(target, "alpha", 1, 0), + ObjectAnimator.ofFloat(target, "translationY", 0, -target.getBottom()) + ); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/specials/RollInAnimatorDecoration.java b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/specials/RollInAnimatorDecoration.java new file mode 100644 index 00000000..4a5ea252 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/specials/RollInAnimatorDecoration.java @@ -0,0 +1,43 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014 daimajia + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.taobao.luaview.extend.animation.specials; + + +import android.animation.AnimatorSet; +import android.animation.ObjectAnimator; +import android.view.View; + +import com.taobao.luaview.extend.animation.BaseViewAnimatorDecoration; + +public class RollInAnimatorDecoration extends BaseViewAnimatorDecoration { + @Override + protected void prepare(AnimatorSet animatorSet, View target) { + animatorSet.playTogether( + ObjectAnimator.ofFloat(target, "alpha", 0, 1), + ObjectAnimator.ofFloat(target, "translationX", -(target.getWidth() - target.getPaddingLeft() - target.getPaddingRight()), 0), + ObjectAnimator.ofFloat(target, "rotation", -120, 0) + ); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/specials/RollOutAnimatorDecoration.java b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/specials/RollOutAnimatorDecoration.java new file mode 100644 index 00000000..c9d1aa24 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/specials/RollOutAnimatorDecoration.java @@ -0,0 +1,43 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014 daimajia + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.taobao.luaview.extend.animation.specials; + + +import android.animation.AnimatorSet; +import android.animation.ObjectAnimator; +import android.view.View; + +import com.taobao.luaview.extend.animation.BaseViewAnimatorDecoration; + +public class RollOutAnimatorDecoration extends BaseViewAnimatorDecoration { + @Override + protected void prepare(AnimatorSet animatorSet, View target) { + animatorSet.playTogether( + ObjectAnimator.ofFloat(target, "alpha", 1, 0), + ObjectAnimator.ofFloat(target, "translationX", 0, target.getWidth()), + ObjectAnimator.ofFloat(target, "rotation", 0, 120) + ); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/zooming_entrances/ZoomInAnimatorDecoration.java b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/zooming_entrances/ZoomInAnimatorDecoration.java new file mode 100644 index 00000000..ee7d9440 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/zooming_entrances/ZoomInAnimatorDecoration.java @@ -0,0 +1,43 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014 daimajia + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.taobao.luaview.extend.animation.zooming_entrances; + + +import android.animation.AnimatorSet; +import android.animation.ObjectAnimator; +import android.view.View; + +import com.taobao.luaview.extend.animation.BaseViewAnimatorDecoration; + +public class ZoomInAnimatorDecoration extends BaseViewAnimatorDecoration { + @Override + protected void prepare(AnimatorSet animatorSet, View target) { + animatorSet.playTogether( + ObjectAnimator.ofFloat(target, "scaleX", 0.45f, 1), + ObjectAnimator.ofFloat(target, "scaleY", 0.45f, 1), + ObjectAnimator.ofFloat(target, "alpha", 0, 1) + ); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/zooming_entrances/ZoomInDownAnimatorDecoration.java b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/zooming_entrances/ZoomInDownAnimatorDecoration.java new file mode 100644 index 00000000..861eaeca --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/zooming_entrances/ZoomInDownAnimatorDecoration.java @@ -0,0 +1,44 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014 daimajia + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.taobao.luaview.extend.animation.zooming_entrances; + + +import android.animation.AnimatorSet; +import android.animation.ObjectAnimator; +import android.view.View; + +import com.taobao.luaview.extend.animation.BaseViewAnimatorDecoration; + +public class ZoomInDownAnimatorDecoration extends BaseViewAnimatorDecoration { + @Override + protected void prepare(AnimatorSet animatorSet, View target) { + animatorSet.playTogether( + ObjectAnimator.ofFloat(target, "scaleX", 0.1f, 0.475f, 1), + ObjectAnimator.ofFloat(target, "scaleY", 0.1f, 0.475f, 1), + ObjectAnimator.ofFloat(target, "translationY", -target.getBottom(), 60, 0), + ObjectAnimator.ofFloat(target, "alpha", 0, 1, 1) + ); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/zooming_entrances/ZoomInLeftAnimatorDecoration.java b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/zooming_entrances/ZoomInLeftAnimatorDecoration.java new file mode 100644 index 00000000..fc102604 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/zooming_entrances/ZoomInLeftAnimatorDecoration.java @@ -0,0 +1,44 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014 daimajia + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.taobao.luaview.extend.animation.zooming_entrances; + + +import android.animation.AnimatorSet; +import android.animation.ObjectAnimator; +import android.view.View; + +import com.taobao.luaview.extend.animation.BaseViewAnimatorDecoration; + +public class ZoomInLeftAnimatorDecoration extends BaseViewAnimatorDecoration { + @Override + protected void prepare(AnimatorSet animatorSet, View target) { + animatorSet.playTogether( + ObjectAnimator.ofFloat(target, "scaleX", 0.1f, 0.475f, 1), + ObjectAnimator.ofFloat(target, "scaleY", 0.1f, 0.475f, 1), + ObjectAnimator.ofFloat(target, "translationX", -target.getRight(), 48, 0), + ObjectAnimator.ofFloat(target, "alpha", 0, 1, 1) + ); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/zooming_entrances/ZoomInRightAnimatorDecoration.java b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/zooming_entrances/ZoomInRightAnimatorDecoration.java new file mode 100644 index 00000000..d59168b8 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/zooming_entrances/ZoomInRightAnimatorDecoration.java @@ -0,0 +1,44 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014 daimajia + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.taobao.luaview.extend.animation.zooming_entrances; + + +import android.animation.AnimatorSet; +import android.animation.ObjectAnimator; +import android.view.View; + +import com.taobao.luaview.extend.animation.BaseViewAnimatorDecoration; + +public class ZoomInRightAnimatorDecoration extends BaseViewAnimatorDecoration { + @Override + protected void prepare(AnimatorSet animatorSet, View target) { + animatorSet.playTogether( + ObjectAnimator.ofFloat(target, "scaleX", 0.1f, 0.475f, 1), + ObjectAnimator.ofFloat(target, "scaleY", 0.1f, 0.475f, 1), + ObjectAnimator.ofFloat(target, "translationX", target.getWidth() + target.getPaddingRight(), -48, 0), + ObjectAnimator.ofFloat(target, "alpha", 0, 1, 1) + ); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/zooming_entrances/ZoomInUpAnimatorDecoration.java b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/zooming_entrances/ZoomInUpAnimatorDecoration.java new file mode 100644 index 00000000..72b297a5 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/zooming_entrances/ZoomInUpAnimatorDecoration.java @@ -0,0 +1,47 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014 daimajia + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.taobao.luaview.extend.animation.zooming_entrances; + + +import android.animation.AnimatorSet; +import android.animation.ObjectAnimator; +import android.view.View; +import android.view.ViewGroup; + +import com.taobao.luaview.extend.animation.BaseViewAnimatorDecoration; + +public class ZoomInUpAnimatorDecoration extends BaseViewAnimatorDecoration { + @Override + protected void prepare(AnimatorSet animatorSet, View target) { + ViewGroup parent = (ViewGroup) target.getParent(); + int distance = parent.getHeight() - target.getTop(); + animatorSet.playTogether( + ObjectAnimator.ofFloat(target, "alpha", 0, 1, 1), + ObjectAnimator.ofFloat(target, "scaleX", 0.1f, 0.475f, 1), + ObjectAnimator.ofFloat(target, "scaleY", 0.1f, 0.475f, 1), + ObjectAnimator.ofFloat(target, "translationY", distance, -60, 0) + ); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/zooming_exits/ZoomOutAnimatorDecoration.java b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/zooming_exits/ZoomOutAnimatorDecoration.java new file mode 100644 index 00000000..cd87f763 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/zooming_exits/ZoomOutAnimatorDecoration.java @@ -0,0 +1,43 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014 daimajia + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.taobao.luaview.extend.animation.zooming_exits; + + +import android.animation.AnimatorSet; +import android.animation.ObjectAnimator; +import android.view.View; + +import com.taobao.luaview.extend.animation.BaseViewAnimatorDecoration; + +public class ZoomOutAnimatorDecoration extends BaseViewAnimatorDecoration { + @Override + protected void prepare(AnimatorSet animatorSet, View target) { + animatorSet.playTogether( + ObjectAnimator.ofFloat(target, "alpha", 1, 0, 0), + ObjectAnimator.ofFloat(target, "scaleX", 1, 0.3f, 0), + ObjectAnimator.ofFloat(target, "scaleY", 1, 0.3f, 0) + ); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/zooming_exits/ZoomOutDownAnimatorDecoration.java b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/zooming_exits/ZoomOutDownAnimatorDecoration.java new file mode 100644 index 00000000..f89a8ba2 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/zooming_exits/ZoomOutDownAnimatorDecoration.java @@ -0,0 +1,47 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014 daimajia + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.taobao.luaview.extend.animation.zooming_exits; + + +import android.animation.AnimatorSet; +import android.animation.ObjectAnimator; +import android.view.View; +import android.view.ViewGroup; + +import com.taobao.luaview.extend.animation.BaseViewAnimatorDecoration; + +public class ZoomOutDownAnimatorDecoration extends BaseViewAnimatorDecoration { + @Override + protected void prepare(AnimatorSet animatorSet, View target) { + ViewGroup parent = (ViewGroup) target.getParent(); + int distance = parent.getHeight() - target.getTop(); + animatorSet.playTogether( + ObjectAnimator.ofFloat(target, "alpha", 1, 1, 0), + ObjectAnimator.ofFloat(target, "scaleX", 1, 0.475f, 0.1f), + ObjectAnimator.ofFloat(target, "scaleY", 1, 0.475f, 0.1f), + ObjectAnimator.ofFloat(target, "translationY", 0, -60, distance) + ); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/zooming_exits/ZoomOutLeftAnimatorDecoration.java b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/zooming_exits/ZoomOutLeftAnimatorDecoration.java new file mode 100644 index 00000000..b5ecaf26 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/zooming_exits/ZoomOutLeftAnimatorDecoration.java @@ -0,0 +1,44 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014 daimajia + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.taobao.luaview.extend.animation.zooming_exits; + + +import android.animation.AnimatorSet; +import android.animation.ObjectAnimator; +import android.view.View; + +import com.taobao.luaview.extend.animation.BaseViewAnimatorDecoration; + +public class ZoomOutLeftAnimatorDecoration extends BaseViewAnimatorDecoration { + @Override + protected void prepare(AnimatorSet animatorSet, View target) { + animatorSet.playTogether( + ObjectAnimator.ofFloat(target, "alpha", 1, 1, 0), + ObjectAnimator.ofFloat(target, "scaleX", 1, 0.475f, 0.1f), + ObjectAnimator.ofFloat(target, "scaleY", 1, 0.475f, 0.1f), + ObjectAnimator.ofFloat(target, "translationX", 0, 42, -target.getRight()) + ); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/zooming_exits/ZoomOutRightAnimatorDecoration.java b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/zooming_exits/ZoomOutRightAnimatorDecoration.java new file mode 100644 index 00000000..73d1c5a1 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/zooming_exits/ZoomOutRightAnimatorDecoration.java @@ -0,0 +1,47 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014 daimajia + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.taobao.luaview.extend.animation.zooming_exits; + + +import android.animation.AnimatorSet; +import android.animation.ObjectAnimator; +import android.view.View; +import android.view.ViewGroup; + +import com.taobao.luaview.extend.animation.BaseViewAnimatorDecoration; + +public class ZoomOutRightAnimatorDecoration extends BaseViewAnimatorDecoration { + @Override + protected void prepare(AnimatorSet animatorSet, View target) { + ViewGroup parent = (ViewGroup) target.getParent(); + int distance = parent.getWidth() - parent.getLeft(); + animatorSet.playTogether( + ObjectAnimator.ofFloat(target, "alpha", 1, 1, 0), + ObjectAnimator.ofFloat(target, "scaleX", 1, 0.475f, 0.1f), + ObjectAnimator.ofFloat(target, "scaleY", 1, 0.475f, 0.1f), + ObjectAnimator.ofFloat(target, "translationX", 0, -42, distance) + ); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/zooming_exits/ZoomOutUpAnimatorDecoration.java b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/zooming_exits/ZoomOutUpAnimatorDecoration.java new file mode 100644 index 00000000..88bb1a25 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/extend/animation/zooming_exits/ZoomOutUpAnimatorDecoration.java @@ -0,0 +1,44 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014 daimajia + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.taobao.luaview.extend.animation.zooming_exits; + + +import android.animation.AnimatorSet; +import android.animation.ObjectAnimator; +import android.view.View; + +import com.taobao.luaview.extend.animation.BaseViewAnimatorDecoration; + +public class ZoomOutUpAnimatorDecoration extends BaseViewAnimatorDecoration { + @Override + protected void prepare(AnimatorSet animatorSet, View target) { + animatorSet.playTogether( + ObjectAnimator.ofFloat(target, "alpha", 1, 1, 0), + ObjectAnimator.ofFloat(target, "scaleX", 1, 0.475f, 0.1f), + ObjectAnimator.ofFloat(target, "scaleY", 1, 0.475f, 0.1f), + ObjectAnimator.ofFloat(target, "translationY", 0, 60, -target.getBottom()) + ); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fragment/LVPageFragment.java b/Android/LuaViewSDK/src/com/taobao/luaview/fragment/LVPageFragment.java new file mode 100644 index 00000000..97932da9 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fragment/LVPageFragment.java @@ -0,0 +1,92 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fragment; + +import android.annotation.SuppressLint; +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import com.taobao.luaview.fun.mapper.ui.UIViewGroupMethodMapper; +import com.taobao.luaview.global.LuaViewManager; +import com.taobao.luaview.userdata.base.UDLuaTable; +import com.taobao.luaview.userdata.ui.UDView; +import com.taobao.luaview.userdata.ui.UDViewGroup; +import com.taobao.luaview.userdata.ui.UDViewPager; +import com.taobao.luaview.view.LVViewGroup; + +import org.luaj.vm2.Globals; + +/** + * ViewPager 的 Fragment + * + * @author song + * @date 15/9/18 + */ +@SuppressLint("ValidFragment") +public class LVPageFragment extends Fragment { + private Globals mGlobals; + private UDViewPager mInitProps; + private int mPosInViewPager; + + public LVPageFragment(Globals globals, UDViewPager mInitProps, int posInViewPager) { + this.mGlobals = globals; + this.mInitProps = mInitProps; + this.mPosInViewPager = posInViewPager; + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + //View封装 + final UDView page = new UDViewGroup(createPageLayout(), mGlobals, null);//TODO 为什么用mLuaUserData.getmetatable()不行 + //对外数据封装,必须使用LuaTable + final UDLuaTable pageData = new UDLuaTable(page); + final View pageView = pageData.getView(); + //初始化View + initView(pageData, mPosInViewPager); + //绘制数据 + renderView(pageData, mPosInViewPager); + return pageView; + } + + /** + * 调用LuaView的Init方法进行Cell的初始化 + * + * @param position + * @return + */ + private void initView(UDLuaTable page, int position) { + this.mGlobals.saveContainer(page.getLVViewGroup()); + this.mInitProps.callPageInit(page, position); + this.mGlobals.restoreContainer(); + } + + /** + * 调用LuaView的Layout方法进行数据填充 + * + * @param page + * @param position + */ + private void renderView(UDLuaTable page, int position) { + this.mGlobals.saveContainer(page.getLVViewGroup()); + this.mInitProps.callPageLayout(page, position); + this.mGlobals.restoreContainer(); + } + + /** + * 创建 cell 的布局 + * + * @return + */ + private LVViewGroup createPageLayout() { + return new LVViewGroup(mGlobals, mInitProps.getmetatable(), null); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fragment/LuaViewFragment.java b/Android/LuaViewSDK/src/com/taobao/luaview/fragment/LuaViewFragment.java new file mode 100644 index 00000000..2d73d314 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fragment/LuaViewFragment.java @@ -0,0 +1,70 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fragment; + +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import com.taobao.luaview.global.Constants; +import com.taobao.luaview.global.LuaView; + +/** + * LuaView Fragment + * + * @author song + * @date 15/9/22 + */ +public class LuaViewFragment extends Fragment { + private LuaView mLuaView; + + @Override + public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + mLuaView = LuaView.create(getActivity()); + if (mLuaView != null) { + registerNameBeforeLoad(mLuaView); + load(mLuaView); + } + return mLuaView; + } + + /** + * 注册接口,注册各种脚本,panel + */ + public void registerNameBeforeLoad(final LuaView luaView) { + } + + /** + * 加载数据 + */ + public void load(final LuaView luaView) { +// luaView.loadFile(getLuaUri()); + luaView.load(getLuaUri()); + } + + /** + * 获取文件名称 + * + * @return + */ + private String getLuaUri() { + if (getActivity() != null && getActivity().getIntent() != null && getActivity().getIntent().hasExtra(Constants.PARAM_URI)) { + String uri = getActivity().getIntent().getStringExtra(Constants.PARAM_URI); + return uri; + } + return null; + } + + public LuaView getLuaView() { + return mLuaView; + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/base/BaseFunctionBinder.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/base/BaseFunctionBinder.java new file mode 100644 index 00000000..e7b8d7bf --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/base/BaseFunctionBinder.java @@ -0,0 +1,63 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.base; + +import com.taobao.luaview.global.LuaViewConfig; +import com.taobao.luaview.global.LuaViewManager; + +import org.luaj.vm2.LuaTable; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.lib.LibFunction; +import org.luaj.vm2.lib.TwoArgFunction; + +/** + * 基础两参数函数对象 + * + * @author song + * @date 15/8/14 + */ +public abstract class BaseFunctionBinder extends TwoArgFunction { + public String[] luaNames; + + public BaseFunctionBinder(String... name) { + this.luaNames = name; + } + + public String[] getLuaNames() { + return luaNames; + } + + @Override + public LuaValue call(LuaValue modname, LuaValue env) { + return call(env, getMapperClass()); + } + + private LuaValue call(LuaValue env, Class libClass) { + final LuaTable metatable = (libClass == null || LuaViewConfig.isLibsLazyLoad() == false) ? LuaViewManager.createMetatable(libClass) : null;//当不是lazyLoad或者lib为空(常量)的时候直接加载 + if (luaNames != null) { + for (String name : luaNames) { + env.set(name, createCreator(env, metatable)); + } + } + return metatable; + } + + public abstract Class getMapperClass(); + + /** + * 默认返回metatable,如果要使用对象方式调用,则返回一个LuaFunction + * + * @param env + * @param metaTable + * @return + */ + public LuaValue createCreator(LuaValue env, LuaValue metaTable) { + return metaTable; + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/base/BaseMethodMapper.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/base/BaseMethodMapper.java new file mode 100644 index 00000000..dfd344bb --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/base/BaseMethodMapper.java @@ -0,0 +1,172 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.base; + +import com.taobao.luaview.cache.AppCache; +import com.taobao.luaview.global.LuaViewConfig; +import com.taobao.luaview.userdata.base.BaseUserdata; +import com.taobao.luaview.util.LogUtil; + +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; +import org.luaj.vm2.lib.VarArgFunction; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * 基础多参数函数 + * + * @author song + * @date 15/8/14 + */ +public abstract class BaseMethodMapper extends VarArgFunction { + private static final String CACHE_METHODS = AppCache.CACHE_METHODS; + + /** + * 该函数使用反射,调用方法,并且被调用方法签名必须为:fun(UIView, Varargs)格式,否则不被支持 + * 所有的method都是被注册的public方法,使用class.getMethods返回 + * TODO 如果这里性能受限的话,考虑使用其他方式实现(反射性能大概低了20倍),但是只会在创建的时候消耗,其他情况下不消耗性能 + * + * @param args the arguments to the function call. + * @return + */ + public Varargs invoke(Varargs args) { + try { + if (opcode != -1) { + return invoke(opcode, getUD(args), args); + } else { + return (Varargs) method.invoke(this, getUD(args), args); + } + } catch (Exception e) { + if (LuaViewConfig.isDebug()) { + LogUtil.e("[----Method Invoke Error Start----]"); + LogUtil.e("[Class]", getClass()); + LogUtil.e("[Opcode]", opcode); + LogUtil.e("[Method]", method != null ? method : getMethodByOpcode(opcode)); + LogUtil.e("[Arguments]", args); + LogUtil.e("[Target]", getTarget(args)); + LogUtil.e("[Error]", e); + LogUtil.e("[----Method Invoke Error End----]"); + } + e.printStackTrace(); + return NONE; + } + } + + /** + * 获取userdata + * + * @param varargs + * @return + */ + public U getUD(Varargs varargs) { + return (U) varargs.arg1(); + } + + public Object getTarget(Varargs varargs) { + U target = getUD(varargs); + if (target instanceof BaseUserdata) { + return ((BaseUserdata) target).userdata(); + } + return target; + } + + //---------------------------------------------------------------------------------------------- + + /** + * merge function names with cache tag + * + * @param tag + * @param supernames + * @param names + * @return + */ + public List mergeFunctionNames(final String tag, final List supernames, final String[] names) { + List result = AppCache.getCache(CACHE_METHODS).get(tag); + if (result == null) { + result = mergeFunctionNames(supernames, names); + AppCache.getCache(CACHE_METHODS).put(tag, result); + } + return result; + } + + public List mergeFunctionNames(final String tag, final List supernames, final List names) { + List result = AppCache.getCache(CACHE_METHODS).get(tag); + if (result == null) { + result = mergeFunctionNames(supernames, names); + AppCache.getCache(CACHE_METHODS).put(tag, result); + } + return result; + } + + /** + * merge function names + * 将names拼接在supernames之后 + * + * @param supernames + * @param names + * @return + */ + private List mergeFunctionNames(final List supernames, final String[] names) { + return mergeFunctionNames(supernames, Arrays.asList(names)); + } + + /** + * merge FunctionNames + * 将自己的names拼接在supernames之后 + */ + private List mergeFunctionNames(final List supernames, final List names) { + final List result = new ArrayList(); + if (supernames != null && supernames.size() > 0) { + result.addAll(supernames); + } + if (supernames != null && names != null) { + result.addAll(supernames.size(), names); + } + return result; + } + + /** + * 获取所有函数名称,供子类调用 + * + * @return + */ + public List getAllFunctionNames() { + return new ArrayList(); + } + + /** + * 根据code获取函数名称 + * + * @param optcode + * @return + */ + public String getMethodByOpcode(int optcode) { + List allMethods = getAllFunctionNames(); + if (allMethods != null && allMethods.size() > optcode && optcode >= 0) { + return allMethods.get(optcode); + } + return null; + } + + /** + * 调用子类 + * + * @param code + * @param target + * @param varargs + * @return + */ + public Varargs invoke(int code, U target, Varargs varargs) { + return LuaValue.NIL; + } + +} \ No newline at end of file diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/base/BaseVarArgCreator.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/base/BaseVarArgCreator.java new file mode 100644 index 00000000..b07dc481 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/base/BaseVarArgCreator.java @@ -0,0 +1,87 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.base; + +import com.taobao.luaview.fun.mapper.LuaViewLib; +import com.taobao.luaview.fun.mapper.ui.NewIndexFunction; +import com.taobao.luaview.global.LuaViewConfig; +import com.taobao.luaview.global.LuaViewManager; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaTable; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; +import org.luaj.vm2.lib.LibFunction; +import org.luaj.vm2.lib.VarArgFunction; + +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.List; + +/** + * 零参数函数 + * + * @author song + * @date 15/8/14 + */ +public abstract class BaseVarArgCreator extends VarArgFunction { + public Globals globals; + public LuaValue metatable; + public Class libClass; + + public BaseVarArgCreator(Globals globals, LuaValue metatable) { + this(globals, metatable, null); + } + + public BaseVarArgCreator(Globals globals, LuaValue metatable, Class libClass) { + this.globals = globals; + this.metatable = metatable; + this.libClass = libClass; + } + + public Varargs invoke(Varargs args) { + if (LuaViewConfig.isLibsLazyLoad()) { + metatable = LuaViewManager.createMetatable(libClass); + } + return createUserdata(globals, metatable, args); + } + + /** + * 获取所有方法 + * + * @param clazz + * @return + */ + private List getMapperMethods(final Class clazz) { + final List methods = new ArrayList(); + getMapperMethodsByClazz(methods, clazz); + return methods.size() > 0 ? methods : null; + } + + private void getMapperMethodsByClazz(final List result, final Class clazz) { + if (clazz != null && clazz.isAnnotationPresent(LuaViewLib.class)) {//XXXMapper + getMapperMethodsByClazz(result, clazz.getSuperclass());//处理super + final Method[] methods = clazz.getDeclaredMethods(); + if (methods != null && methods.length > 0) { + for (final Method method : methods) {//add self + if (method.getModifiers() == Modifier.PUBLIC) {//public 方法才行 + result.add(method); + } + } + } + } + } + + private LuaValue addNewIndex(LuaTable t) { + return tableOf(new LuaValue[]{INDEX, t, NEWINDEX, new NewIndexFunction(t)}); + } + + public abstract LuaValue createUserdata(Globals globals, LuaValue metaTable, Varargs varargs); +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/base/BaseVarArgUICreator.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/base/BaseVarArgUICreator.java new file mode 100644 index 00000000..b877d904 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/base/BaseVarArgUICreator.java @@ -0,0 +1,58 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.base; + +import android.view.View; + +import com.taobao.luaview.global.LuaViewConfig; +import com.taobao.luaview.global.LuaViewManager; +import com.taobao.luaview.util.LuaViewUtil; +import com.taobao.luaview.view.interfaces.ILVView; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; +import org.luaj.vm2.lib.LibFunction; +import org.luaj.vm2.lib.VarArgFunction; + +/** + * 零参数函数 + * + * @author song + * @date 15/8/14 + */ +public abstract class BaseVarArgUICreator extends VarArgFunction { + public Globals globals; + public LuaValue metatable; + public Class libClass; + + public BaseVarArgUICreator(Globals globals, LuaValue metatable) { + this(globals, metatable, null); + } + + public BaseVarArgUICreator(Globals globals, LuaValue metatable, Class libClass) { + this.globals = globals; + this.metatable = metatable; + this.libClass = libClass; + } + + public Varargs invoke(Varargs args) { + if (LuaViewConfig.isLibsLazyLoad()) { + metatable = LuaViewManager.createMetatable(libClass); + } + + ILVView view = createView(globals, metatable, args); + if (globals.container != null && view instanceof View && ((View) view).getParent() == null) { + LuaViewUtil.addView(globals.container, (View) view, args); + } + return view.getUserdata(); + } + + public abstract ILVView createView(Globals globals, LuaValue metaTable, Varargs varargs); +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/constants/AlignBinder.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/constants/AlignBinder.java new file mode 100644 index 00000000..e46d96c9 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/constants/AlignBinder.java @@ -0,0 +1,38 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.binder.constants; + +import com.taobao.luaview.fun.base.BaseFunctionBinder; +import com.taobao.luaview.userdata.constants.UDAlign; + +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.lib.LibFunction; + +/** + * Align 常量 + * + * @author song + * @date 15/8/21 + */ +public class AlignBinder extends BaseFunctionBinder { + + public AlignBinder() { + super("Align"); + } + + @Override + public Class getMapperClass() { + return null; + } + + @Override + public LuaValue createCreator(LuaValue env, final LuaValue metaTable) { + return new UDAlign(env.checkglobals(), metaTable); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/constants/EllipsizeBinder.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/constants/EllipsizeBinder.java new file mode 100644 index 00000000..684f2387 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/constants/EllipsizeBinder.java @@ -0,0 +1,37 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.binder.constants; + +import com.taobao.luaview.fun.base.BaseFunctionBinder; +import com.taobao.luaview.userdata.constants.UDEllipsize; + +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.lib.LibFunction; + +/** + * Ellipsize 常量 + * @author song + * @date 15/11/5 + */ +public class EllipsizeBinder extends BaseFunctionBinder { + + public EllipsizeBinder() { + super("Ellipsize"); + } + + @Override + public Class getMapperClass() { + return null; + } + + @Override + public LuaValue createCreator(LuaValue env, final LuaValue metaTable) { + return new UDEllipsize(env.checkglobals(), metaTable); + } +} \ No newline at end of file diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/constants/FontStyleBinder.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/constants/FontStyleBinder.java new file mode 100644 index 00000000..7e739103 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/constants/FontStyleBinder.java @@ -0,0 +1,38 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.binder.constants; + +import com.taobao.luaview.fun.base.BaseFunctionBinder; +import com.taobao.luaview.userdata.constants.UDFontStyle; + +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.lib.LibFunction; + +/** + * FontStyle 常量 + * + * @author song + * @date 15/8/21 + */ +public class FontStyleBinder extends BaseFunctionBinder { + + public FontStyleBinder() { + super("FontStyle"); + } + + @Override + public Class getMapperClass() { + return null; + } + + @Override + public LuaValue createCreator(LuaValue env, final LuaValue metaTable) { + return new UDFontStyle(env.checkglobals(), metaTable); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/constants/FontWeightBinder.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/constants/FontWeightBinder.java new file mode 100644 index 00000000..17fc3811 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/constants/FontWeightBinder.java @@ -0,0 +1,38 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.binder.constants; + +import com.taobao.luaview.fun.base.BaseFunctionBinder; +import com.taobao.luaview.userdata.constants.UDFontWeight; + +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.lib.LibFunction; + +/** + * FontWeight 常量 + * + * @author song + * @date 15/8/21 + */ +public class FontWeightBinder extends BaseFunctionBinder { + + public FontWeightBinder() { + super("FontWeight"); + } + + @Override + public Class getMapperClass() { + return null; + } + + @Override + public LuaValue createCreator(LuaValue env, final LuaValue metaTable) { + return new UDFontWeight(env.checkglobals(), metaTable); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/constants/GravityBinder.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/constants/GravityBinder.java new file mode 100644 index 00000000..974dc62c --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/constants/GravityBinder.java @@ -0,0 +1,38 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.binder.constants; + +import com.taobao.luaview.fun.base.BaseFunctionBinder; +import com.taobao.luaview.userdata.constants.UDGravity; + +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.lib.LibFunction; + +/** + * Gravity 常量 + * + * @author song + * @date 15/8/21 + */ +public class GravityBinder extends BaseFunctionBinder { + + public GravityBinder() { + super("Gravity"); + } + + @Override + public Class getMapperClass() { + return null; + } + + @Override + public LuaValue createCreator(LuaValue env, final LuaValue metaTable) { + return new UDGravity(env.checkglobals(), metaTable); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/constants/InterpolatorBinder.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/constants/InterpolatorBinder.java new file mode 100644 index 00000000..484dff17 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/constants/InterpolatorBinder.java @@ -0,0 +1,38 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.binder.constants; + +import com.taobao.luaview.fun.base.BaseFunctionBinder; +import com.taobao.luaview.userdata.constants.UDInterpolator; + +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.lib.LibFunction; + +/** + * Interpolator 常量 + * + * @author song + * @date 15/8/21 + */ +public class InterpolatorBinder extends BaseFunctionBinder { + + public InterpolatorBinder() { + super("Interpolator"); + } + + @Override + public Class getMapperClass() { + return null; + } + + @Override + public LuaValue createCreator(LuaValue env, final LuaValue metaTable) { + return new UDInterpolator(env.checkglobals(), metaTable); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/constants/PaintStyleBinder.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/constants/PaintStyleBinder.java new file mode 100644 index 00000000..689cf6a1 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/constants/PaintStyleBinder.java @@ -0,0 +1,41 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.binder.constants; + +import com.taobao.luaview.fun.base.BaseFunctionBinder; +import com.taobao.luaview.userdata.constants.UDPaintStyle; + +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.lib.LibFunction; + +/** + * Paint Style + * + * @author song + * @date 16/8/15 + * 主要功能描述 + * 修改描述 + * 下午4:03 song XXX + */ +public class PaintStyleBinder extends BaseFunctionBinder { + + public PaintStyleBinder() { + super("PaintStyle"); + } + + @Override + public Class getMapperClass() { + return null; + } + + @Override + public LuaValue createCreator(LuaValue env, final LuaValue metaTable) { + return new UDPaintStyle(env.checkglobals(), metaTable); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/constants/PinnedBinder.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/constants/PinnedBinder.java new file mode 100644 index 00000000..bddb24de --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/constants/PinnedBinder.java @@ -0,0 +1,32 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.binder.constants; + +import com.taobao.luaview.fun.base.BaseFunctionBinder; +import com.taobao.luaview.userdata.constants.UDPinned; + +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.lib.LibFunction; + +public class PinnedBinder extends BaseFunctionBinder { + + public PinnedBinder() { + super("Pinned"); + } + + @Override + public Class getMapperClass() { + return null; + } + + @Override + public LuaValue createCreator(LuaValue env, final LuaValue metaTable) { + return new UDPinned(env.checkglobals(), metaTable); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/constants/ScaleTypeBinder.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/constants/ScaleTypeBinder.java new file mode 100644 index 00000000..a8c85915 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/constants/ScaleTypeBinder.java @@ -0,0 +1,32 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.binder.constants; + +import com.taobao.luaview.fun.base.BaseFunctionBinder; +import com.taobao.luaview.userdata.constants.UDImageScaleType; + +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.lib.LibFunction; + +public class ScaleTypeBinder extends BaseFunctionBinder { + + public ScaleTypeBinder() { + super("ScaleType"); + } + + @Override + public Class getMapperClass() { + return null; + } + + @Override + public LuaValue createCreator(LuaValue env, final LuaValue metaTable) { + return new UDImageScaleType(env.checkglobals(), metaTable); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/constants/TextAlignBinder.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/constants/TextAlignBinder.java new file mode 100644 index 00000000..720f3252 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/constants/TextAlignBinder.java @@ -0,0 +1,32 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.binder.constants; + +import com.taobao.luaview.fun.base.BaseFunctionBinder; +import com.taobao.luaview.userdata.constants.UDTextAlign; + +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.lib.LibFunction; + +public class TextAlignBinder extends BaseFunctionBinder { + + public TextAlignBinder() { + super("TextAlign"); + } + + @Override + public Class getMapperClass() { + return null; + } + + @Override + public LuaValue createCreator(LuaValue env, final LuaValue metaTable) { + return new UDTextAlign(env.checkglobals(), metaTable); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/constants/TouchEventBinder.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/constants/TouchEventBinder.java new file mode 100644 index 00000000..ccfc98e7 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/constants/TouchEventBinder.java @@ -0,0 +1,33 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.binder.constants; + +import com.taobao.luaview.fun.base.BaseFunctionBinder; +import com.taobao.luaview.userdata.constants.UDTouchEvent; +import com.taobao.luaview.userdata.constants.UDViewEffect; + +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.lib.LibFunction; + +public class TouchEventBinder extends BaseFunctionBinder { + + public TouchEventBinder() { + super("TouchEvent"); + } + + @Override + public Class getMapperClass() { + return null; + } + + @Override + public LuaValue createCreator(LuaValue env, final LuaValue metaTable) { + return new UDTouchEvent(env.checkglobals(), metaTable); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/constants/ViewEffectBinder.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/constants/ViewEffectBinder.java new file mode 100644 index 00000000..22bd35f0 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/constants/ViewEffectBinder.java @@ -0,0 +1,41 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.binder.constants; + +import com.taobao.luaview.fun.base.BaseFunctionBinder; +import com.taobao.luaview.userdata.constants.UDViewEffect; + +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.lib.LibFunction; + +/** + * View Effect + * + * @author song + * @date 16/8/15 + * 主要功能描述 + * 修改描述 + * 下午4:03 song XXX + */ +public class ViewEffectBinder extends BaseFunctionBinder { + + public ViewEffectBinder() { + super("ViewEffect"); + } + + @Override + public Class getMapperClass() { + return null; + } + + @Override + public LuaValue createCreator(LuaValue env, final LuaValue metaTable) { + return new UDViewEffect(env.checkglobals(), metaTable); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/indicator/UICircleViewPagerIndicatorBinder.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/indicator/UICircleViewPagerIndicatorBinder.java new file mode 100644 index 00000000..22f6364f --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/indicator/UICircleViewPagerIndicatorBinder.java @@ -0,0 +1,43 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.binder.indicator; + +import com.taobao.luaview.fun.base.BaseFunctionBinder; +import com.taobao.luaview.fun.base.BaseVarArgUICreator; +import com.taobao.luaview.fun.mapper.indicator.UICircleViewPagerIndicatorMethodMapper; +import com.taobao.luaview.view.indicator.LVCircleViewPagerIndicator; +import com.taobao.luaview.view.interfaces.ILVView; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; +import org.luaj.vm2.lib.LibFunction; + + +public class UICircleViewPagerIndicatorBinder extends BaseFunctionBinder { + + public UICircleViewPagerIndicatorBinder() { + super("PagerIndicator"); + } + + @Override + public Class getMapperClass() { + return UICircleViewPagerIndicatorMethodMapper.class; + } + + @Override + public LuaValue createCreator(LuaValue env, LuaValue metaTable) { + return new BaseVarArgUICreator(env.checkglobals(), metaTable, getMapperClass()) { + @Override + public ILVView createView(Globals globals, LuaValue metaTable, Varargs varargs) { + return new LVCircleViewPagerIndicator(globals, metaTable, varargs); + } + }; + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/indicator/UICustomViewPagerIndicatorBinder.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/indicator/UICustomViewPagerIndicatorBinder.java new file mode 100644 index 00000000..fec3e592 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/indicator/UICustomViewPagerIndicatorBinder.java @@ -0,0 +1,42 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.binder.indicator; + +import com.taobao.luaview.fun.base.BaseFunctionBinder; +import com.taobao.luaview.fun.base.BaseVarArgUICreator; +import com.taobao.luaview.fun.mapper.indicator.UICustomViewPagerIndicatorMethodMapper; +import com.taobao.luaview.view.indicator.LVCustomViewPagerIndicator; +import com.taobao.luaview.view.interfaces.ILVView; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; +import org.luaj.vm2.lib.LibFunction; + +public class UICustomViewPagerIndicatorBinder extends BaseFunctionBinder { + + public UICustomViewPagerIndicatorBinder() { + super("CustomPagerIndicator"); + } + + @Override + public Class getMapperClass() { + return UICustomViewPagerIndicatorMethodMapper.class; + } + + @Override + public LuaValue createCreator(LuaValue env, LuaValue metaTable) { + return new BaseVarArgUICreator(env.checkglobals(), metaTable, getMapperClass()) { + @Override + public ILVView createView(Globals globals, LuaValue metaTable, Varargs varargs) { + return new LVCustomViewPagerIndicator(globals, metaTable, varargs); + } + }; + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/kit/ActionBarBinder.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/kit/ActionBarBinder.java new file mode 100644 index 00000000..94dc3d50 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/kit/ActionBarBinder.java @@ -0,0 +1,32 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.binder.kit; + +import com.taobao.luaview.fun.base.BaseFunctionBinder; +import com.taobao.luaview.userdata.kit.UDActionBar; + +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.lib.LibFunction; + +public class ActionBarBinder extends BaseFunctionBinder { + + public ActionBarBinder() { + super("Navigation"); + } + + @Override + public Class getMapperClass() { + return null; + } + + @Override + public LuaValue createCreator(LuaValue env, final LuaValue metaTable) { + return new UDActionBar(env.checkglobals(), metaTable); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/kit/AudioBinder.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/kit/AudioBinder.java new file mode 100644 index 00000000..10562021 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/kit/AudioBinder.java @@ -0,0 +1,42 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.binder.kit; + +import com.taobao.luaview.fun.base.BaseFunctionBinder; +import com.taobao.luaview.fun.base.BaseVarArgCreator; +import com.taobao.luaview.fun.mapper.kit.AudioMethodMapper; +import com.taobao.luaview.userdata.kit.UDAudio; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; +import org.luaj.vm2.lib.LibFunction; + + +public class AudioBinder extends BaseFunctionBinder { + + public AudioBinder() { + super("AudioPlayer"); + } + + @Override + public Class getMapperClass() { + return AudioMethodMapper.class; + } + + @Override + public LuaValue createCreator(LuaValue env, final LuaValue metaTable) { + return new BaseVarArgCreator(env.checkglobals(), metaTable, getMapperClass()) { + @Override + public LuaValue createUserdata(Globals globals, LuaValue metaTable, Varargs varargs) { + return new UDAudio(globals, metaTable, varargs); + } + }; + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/kit/BitmapBinder.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/kit/BitmapBinder.java new file mode 100644 index 00000000..06972860 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/kit/BitmapBinder.java @@ -0,0 +1,46 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.binder.kit; + +import com.taobao.luaview.fun.base.BaseFunctionBinder; +import com.taobao.luaview.fun.base.BaseVarArgCreator; +import com.taobao.luaview.fun.mapper.kit.BitmapMethodMapper; +import com.taobao.luaview.userdata.kit.UDBitmap; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; +import org.luaj.vm2.lib.LibFunction; + +/** + * Bitmap 接口封装 + * + * @author song + */ +public class BitmapBinder extends BaseFunctionBinder { + + public BitmapBinder() { + super("Bitmap"); + } + + @Override + public Class getMapperClass() { + return BitmapMethodMapper.class; + } + + @Override + public LuaValue createCreator(LuaValue env, final LuaValue metaTable) { + return new BaseVarArgCreator(env.checkglobals(), metaTable, getMapperClass()) { + @Override + public LuaValue createUserdata(Globals globals, LuaValue metaTable, Varargs varargs) { + return new UDBitmap(globals, metaTable, varargs); + } + }; + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/kit/DataBinder.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/kit/DataBinder.java new file mode 100644 index 00000000..a6b4eb96 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/kit/DataBinder.java @@ -0,0 +1,45 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.binder.kit; + +import com.taobao.luaview.fun.base.BaseFunctionBinder; +import com.taobao.luaview.fun.base.BaseVarArgCreator; +import com.taobao.luaview.fun.mapper.kit.DataMethodMapper; +import com.taobao.luaview.userdata.kit.UDData; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; +import org.luaj.vm2.lib.LibFunction; + +/** + * Data 接口封装 (二进制数据) + * @author song + */ +public class DataBinder extends BaseFunctionBinder { + + public DataBinder() { + super("Data"); + } + + @Override + public Class getMapperClass() { + return DataMethodMapper.class; + } + + @Override + public LuaValue createCreator(LuaValue env, final LuaValue metaTable) { + return new BaseVarArgCreator(env.checkglobals(), metaTable, getMapperClass()) { + @Override + public LuaValue createUserdata(Globals globals, LuaValue metaTable, Varargs varargs) { + return new UDData(globals, metaTable, varargs); + } + }; + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/kit/DownloaderBinder.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/kit/DownloaderBinder.java new file mode 100644 index 00000000..92dec17a --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/kit/DownloaderBinder.java @@ -0,0 +1,33 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.binder.kit; + +import com.taobao.luaview.fun.base.BaseFunctionBinder; +import com.taobao.luaview.userdata.kit.UDDownloader; + +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.lib.LibFunction; + +@Deprecated +public class DownloaderBinder extends BaseFunctionBinder { + + public DownloaderBinder() { + super("Downloader"); + } + + @Override + public Class getMapperClass() { + return null; + } + + @Override + public LuaValue createCreator(LuaValue env, final LuaValue metaTable) { + return new UDDownloader(env.checkglobals(), metaTable); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/kit/FileBinder.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/kit/FileBinder.java new file mode 100644 index 00000000..6d0043fb --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/kit/FileBinder.java @@ -0,0 +1,41 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.binder.kit; + +import com.taobao.luaview.fun.base.BaseFunctionBinder; +import com.taobao.luaview.userdata.kit.UDFile; + +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.lib.LibFunction; + +/** + * File operation + * + * @author song + * @date 16/12/5 + * 主要功能描述 + * 修改描述 + * 下午2:41 song XXX + */ +public class FileBinder extends BaseFunctionBinder { + + public FileBinder() { + super("File"); + } + + @Override + public Class getMapperClass() { + return null; + } + + @Override + public LuaValue createCreator(LuaValue env, final LuaValue metaTable) { + return new UDFile(env.checkglobals(), metaTable); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/kit/JsonBinder.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/kit/JsonBinder.java new file mode 100644 index 00000000..2d30a4b2 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/kit/JsonBinder.java @@ -0,0 +1,36 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.binder.kit; + +import com.taobao.luaview.fun.base.BaseFunctionBinder; +import com.taobao.luaview.userdata.kit.UDJson; + +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.lib.LibFunction; + +/** + * Json 接口封装 + * @author song + */ +public class JsonBinder extends BaseFunctionBinder { + + public JsonBinder() { + super("Json"); + } + + @Override + public Class getMapperClass() { + return null; + } + + @Override + public LuaValue createCreator(LuaValue env, final LuaValue metaTable) { + return new UDJson(env.checkglobals(), metaTable); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/kit/SystemBinder.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/kit/SystemBinder.java new file mode 100644 index 00000000..24017c8b --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/kit/SystemBinder.java @@ -0,0 +1,38 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.binder.kit; + +import com.taobao.luaview.fun.base.BaseFunctionBinder; +import com.taobao.luaview.userdata.kit.UDSystem; + +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.lib.LibFunction; + +/** + * System 接口封装 + * + * @author song + * @date 15/8/21 + */ +public class SystemBinder extends BaseFunctionBinder { + + public SystemBinder() { + super("System"); + } + + @Override + public Class getMapperClass() { + return null; + } + + @Override + public LuaValue createCreator(LuaValue env, final LuaValue metaTable) { + return new UDSystem(env.checkglobals(), metaTable); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/kit/TimerBinder.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/kit/TimerBinder.java new file mode 100644 index 00000000..468b7db3 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/kit/TimerBinder.java @@ -0,0 +1,47 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.binder.kit; + +import com.taobao.luaview.fun.base.BaseFunctionBinder; +import com.taobao.luaview.fun.base.BaseVarArgCreator; +import com.taobao.luaview.fun.mapper.kit.TimerMethodMapper; +import com.taobao.luaview.userdata.kit.UDTimer; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; +import org.luaj.vm2.lib.LibFunction; + +/** + * Timer 接口封装 + * + * @author song + * @date 15/8/21 + */ +public class TimerBinder extends BaseFunctionBinder { + + public TimerBinder() { + super("Timer"); + } + + @Override + public Class getMapperClass() { + return TimerMethodMapper.class; + } + + @Override + public LuaValue createCreator(LuaValue env, final LuaValue metaTable) { + return new BaseVarArgCreator(env.checkglobals(), metaTable, getMapperClass()) { + @Override + public LuaValue createUserdata(Globals globals, LuaValue metaTable, Varargs varargs) { + return new UDTimer(globals, metaTable, varargs); + } + }; + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/kit/UnicodeBinder.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/kit/UnicodeBinder.java new file mode 100644 index 00000000..5d5acf48 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/kit/UnicodeBinder.java @@ -0,0 +1,46 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.binder.kit; + +import com.taobao.luaview.fun.base.BaseFunctionBinder; +import com.taobao.luaview.fun.base.BaseVarArgCreator; +import com.taobao.luaview.userdata.kit.UDUnicode; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; +import org.luaj.vm2.lib.LibFunction; + +/** + * Unicode 接口封装 + * + * @author song + * @date 15/8/21 + */ +public class UnicodeBinder extends BaseFunctionBinder { + + public UnicodeBinder() { + super("Unicode"); + } + + @Override + public Class getMapperClass() { + return null; + } + + @Override + public LuaValue createCreator(LuaValue env, final LuaValue metaTable) { + return new BaseVarArgCreator(env.checkglobals(), metaTable, getMapperClass()) { + @Override + public LuaValue createUserdata(Globals globals, LuaValue metaTable, Varargs varargs) { + return new UDUnicode(globals, metaTable, varargs).getUnicode();//直接返回一个string,而不是对象,这样就可以在代码中直接加了 + } + }; + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/kit/VibratorBinder.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/kit/VibratorBinder.java new file mode 100644 index 00000000..ef57d177 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/kit/VibratorBinder.java @@ -0,0 +1,47 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.binder.kit; + +import com.taobao.luaview.fun.base.BaseFunctionBinder; +import com.taobao.luaview.fun.base.BaseVarArgCreator; +import com.taobao.luaview.fun.mapper.kit.VibratorMethodMapper; +import com.taobao.luaview.userdata.kit.UDVibrator; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; +import org.luaj.vm2.lib.LibFunction; + +/** + * Vibrator 接口封装 + * + * @author song + * @date 15/8/21 + */ +public class VibratorBinder extends BaseFunctionBinder { + + public VibratorBinder() { + super("Vibrator"); + } + + @Override + public Class getMapperClass() { + return VibratorMethodMapper.class; + } + + @Override + public LuaValue createCreator(LuaValue env, final LuaValue metaTable) { + return new BaseVarArgCreator(env.checkglobals(), metaTable, getMapperClass()) { + @Override + public LuaValue createUserdata(Globals globals, LuaValue metaTable, Varargs varargs) { + return new UDVibrator(globals, metaTable, varargs); + } + }; + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/net/HttpBinder.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/net/HttpBinder.java new file mode 100644 index 00000000..3abe72b8 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/net/HttpBinder.java @@ -0,0 +1,47 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.binder.net; + +import com.taobao.luaview.fun.base.BaseFunctionBinder; +import com.taobao.luaview.fun.base.BaseVarArgCreator; +import com.taobao.luaview.fun.mapper.net.HttpMethodMapper; +import com.taobao.luaview.userdata.net.UDHttp; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; +import org.luaj.vm2.lib.LibFunction; + +/** + * Http 接口封装 + * + * @author song + * @date 15/8/21 + */ +public class HttpBinder extends BaseFunctionBinder { + + public HttpBinder() { + super("Http"); + } + + @Override + public Class getMapperClass() { + return HttpMethodMapper.class; + } + + @Override + public LuaValue createCreator(LuaValue env, final LuaValue metaTable) { + return new BaseVarArgCreator(env.checkglobals(), metaTable, getMapperClass()) { + @Override + public LuaValue createUserdata(Globals globals, LuaValue metaTable, Varargs varargs) { + return new UDHttp(globals, metaTable, varargs); + } + }; + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/ui/SpannableStringBinder.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/ui/SpannableStringBinder.java new file mode 100644 index 00000000..5e971e60 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/ui/SpannableStringBinder.java @@ -0,0 +1,46 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.binder.ui; + +import com.taobao.luaview.fun.base.BaseFunctionBinder; +import com.taobao.luaview.fun.base.BaseVarArgCreator; +import com.taobao.luaview.fun.mapper.ui.SpannableStringMethodMapper; +import com.taobao.luaview.userdata.ui.UDSpannableString; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; +import org.luaj.vm2.lib.LibFunction; + +/** + * StyledString 复合文本 + * @author song + */ +public class SpannableStringBinder extends BaseFunctionBinder { + + public SpannableStringBinder() { + super("StyledString"); + } + + @Override + public Class getMapperClass() { + return SpannableStringMethodMapper.class; + } + + @Override + public LuaValue createCreator(LuaValue env, LuaValue metaTable) { + return new BaseVarArgCreator(env.checkglobals(), metaTable, getMapperClass()) { + @Override + public LuaValue createUserdata(Globals globals, LuaValue metaTable, Varargs varargs) { + return new UDSpannableString(globals, metaTable, varargs); + } + }; + } + +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/ui/UIAlertBinder.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/ui/UIAlertBinder.java new file mode 100644 index 00000000..7d30ebed --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/ui/UIAlertBinder.java @@ -0,0 +1,47 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.binder.ui; + +import com.taobao.luaview.fun.base.BaseFunctionBinder; +import com.taobao.luaview.fun.base.BaseVarArgCreator; +import com.taobao.luaview.fun.mapper.ui.UIAlertMethodMapper; +import com.taobao.luaview.userdata.ui.UDAlert; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; +import org.luaj.vm2.lib.LibFunction; + +/** + * AlertDialog + * + * @author song + * @date 15/9/2 + */ +public class UIAlertBinder extends BaseFunctionBinder { + + public UIAlertBinder() { + super("Alert"); + } + + @Override + public Class getMapperClass() { + return UIAlertMethodMapper.class; + } + + @Override + public LuaValue createCreator(LuaValue env, final LuaValue metaTable) { + return new BaseVarArgCreator(env.checkglobals(), metaTable, getMapperClass()) { + @Override + public LuaValue createUserdata(Globals globals, LuaValue metaTable, Varargs varargs) { + return new UDAlert(globals, metaTable, varargs); + } + }; + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/ui/UIAnimationBinder.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/ui/UIAnimationBinder.java new file mode 100644 index 00000000..36321226 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/ui/UIAnimationBinder.java @@ -0,0 +1,48 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.binder.ui; + +import com.taobao.luaview.fun.base.BaseFunctionBinder; +import com.taobao.luaview.fun.base.BaseVarArgCreator; +import com.taobao.luaview.fun.mapper.ui.UIAnimationMethodMapper; +import com.taobao.luaview.userdata.ui.UDAnimation; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; +import org.luaj.vm2.lib.LibFunction; + +/** + * 动画 (使用Animator,废弃) + * + * @author song + * @date 15/9/2 + */ +@Deprecated +public class UIAnimationBinder extends BaseFunctionBinder { + + public UIAnimationBinder() { + super("Animate"); + } + + @Override + public Class getMapperClass() { + return UIAnimationMethodMapper.class; + } + + @Override + public LuaValue createCreator(LuaValue env, final LuaValue metaTable) { + return new BaseVarArgCreator(env.checkglobals(), metaTable, getMapperClass()) { + @Override + public LuaValue createUserdata(Globals globals, LuaValue metaTable, Varargs varargs) { + return new UDAnimation(globals, metaTable, varargs); + } + }; + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/ui/UIAnimatorBinder.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/ui/UIAnimatorBinder.java new file mode 100644 index 00000000..8fcc182c --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/ui/UIAnimatorBinder.java @@ -0,0 +1,47 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.binder.ui; + +import com.taobao.luaview.fun.base.BaseFunctionBinder; +import com.taobao.luaview.fun.base.BaseVarArgCreator; +import com.taobao.luaview.fun.mapper.ui.UIAnimatorMethodMapper; +import com.taobao.luaview.userdata.ui.UDAnimator; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; +import org.luaj.vm2.lib.LibFunction; + +/** + * Animator 动画 + * + * @author song + * @date 15/9/2 + */ +public class UIAnimatorBinder extends BaseFunctionBinder { + + public UIAnimatorBinder() { + super("Animation"); + } + + @Override + public Class getMapperClass() { + return UIAnimatorMethodMapper.class; + } + + @Override + public LuaValue createCreator(LuaValue env, final LuaValue metaTable) { + return new BaseVarArgCreator(env.checkglobals(), metaTable, getMapperClass()) { + @Override + public LuaValue createUserdata(Globals globals, LuaValue metaTable, Varargs varargs) { + return new UDAnimator(globals, metaTable, varargs); + } + }; + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/ui/UIAnimatorSetBinder.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/ui/UIAnimatorSetBinder.java new file mode 100644 index 00000000..ffa528ee --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/ui/UIAnimatorSetBinder.java @@ -0,0 +1,48 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.binder.ui; + +import com.taobao.luaview.fun.base.BaseFunctionBinder; +import com.taobao.luaview.fun.base.BaseVarArgCreator; +import com.taobao.luaview.fun.mapper.ui.UIAnimatorSetMethodMapper; +import com.taobao.luaview.userdata.ui.UDAnimatorSet; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; +import org.luaj.vm2.lib.LibFunction; + +/** + * Animator 动画 + * + * @author song + * @date 15/9/2 + */ +@Deprecated +public class UIAnimatorSetBinder extends BaseFunctionBinder { + + public UIAnimatorSetBinder() { + super("AnimationSet"); + } + + @Override + public Class getMapperClass() { + return UIAnimatorSetMethodMapper.class; + } + + @Override + public LuaValue createCreator(LuaValue env, final LuaValue metaTable) { + return new BaseVarArgCreator(env.checkglobals(), metaTable, getMapperClass()) { + @Override + public LuaValue createUserdata(Globals globals, LuaValue metaTable, Varargs varargs) { + return new UDAnimatorSet(globals, metaTable, varargs); + } + }; + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/ui/UIButtonBinder.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/ui/UIButtonBinder.java new file mode 100644 index 00000000..4257663e --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/ui/UIButtonBinder.java @@ -0,0 +1,47 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.binder.ui; + +import com.taobao.luaview.fun.base.BaseFunctionBinder; +import com.taobao.luaview.fun.base.BaseVarArgUICreator; +import com.taobao.luaview.fun.mapper.ui.UIButtonMethodMapper; +import com.taobao.luaview.view.LVButton; +import com.taobao.luaview.view.interfaces.ILVView; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; +import org.luaj.vm2.lib.LibFunction; + +/** + * Button 普通按钮 + * @author song + */ +public class UIButtonBinder extends BaseFunctionBinder { + + public UIButtonBinder() { + super("Button"); + } + + @Override + public Class getMapperClass() { + return UIButtonMethodMapper.class; + } + + @Override + public LuaValue createCreator(LuaValue env, LuaValue metaTable) { + return new BaseVarArgUICreator(env.checkglobals(), metaTable, getMapperClass()) { + @Override + public ILVView createView(Globals globals, LuaValue metaTable, Varargs varargs) { + return new LVButton(globals, metaTable, varargs); + } + }; + } + +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/ui/UICustomPanelBinder.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/ui/UICustomPanelBinder.java new file mode 100644 index 00000000..81faa7b2 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/ui/UICustomPanelBinder.java @@ -0,0 +1,66 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.binder.ui; + +import com.taobao.luaview.fun.base.BaseFunctionBinder; +import com.taobao.luaview.fun.base.BaseVarArgUICreator; +import com.taobao.luaview.fun.mapper.ui.UICustomPanelMethodMapper; +import com.taobao.luaview.view.interfaces.ILVView; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; +import org.luaj.vm2.lib.LibFunction; + +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; + +/** + * 自定义面板,支持将其他自定义View加入该面板并跟Lua交互 + * @author song + */ +public class UICustomPanelBinder extends BaseFunctionBinder { + private Class mPanelClazz; + + public UICustomPanelBinder(final Class clazz, final String bindName) { + super(bindName != null ? bindName : (clazz != null ? clazz.getSimpleName() : null)); + this.mPanelClazz = clazz; + } + + @Override + public Class getMapperClass() { + return UICustomPanelMethodMapper.class; + } + + @Override + public LuaValue createCreator(LuaValue env, LuaValue metaTable) { + return new BaseVarArgUICreator(env.checkglobals(), metaTable, getMapperClass()) { + @Override + public ILVView createView(Globals globals, LuaValue metaTable, Varargs varargs) { + if (mPanelClazz != null) { + try { + final Constructor constructor = mPanelClazz.getConstructor(Globals.class, LuaValue.class, Varargs.class); + return (ILVView) constructor.newInstance(globals, metaTable, varargs); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } catch (InstantiationException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + } + return null; + } + }; + } +} \ No newline at end of file diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/ui/UICustomViewBinder.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/ui/UICustomViewBinder.java new file mode 100644 index 00000000..99dc93d9 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/ui/UICustomViewBinder.java @@ -0,0 +1,48 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.binder.ui; + +import com.taobao.luaview.fun.base.BaseFunctionBinder; +import com.taobao.luaview.fun.base.BaseVarArgUICreator; +import com.taobao.luaview.fun.mapper.ui.UICustomViewMethodMapper; +import com.taobao.luaview.view.LVCustomView; +import com.taobao.luaview.view.interfaces.ILVView; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; +import org.luaj.vm2.lib.LibFunction; + +/** + * 自定义View,可以自己绘制等 + * + * @author song + */ +public class UICustomViewBinder extends BaseFunctionBinder { + + public UICustomViewBinder() { + super("CustomView"); + } + + @Override + public Class getMapperClass() { + return UICustomViewMethodMapper.class; + } + + @Override + public LuaValue createCreator(LuaValue env, LuaValue metaTable) { + return new BaseVarArgUICreator(env.checkglobals(), metaTable, getMapperClass()) { + @Override + public ILVView createView(Globals globals, LuaValue metaTable, Varargs varargs) { + return new LVCustomView(globals, metaTable, varargs); + } + }; + } + +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/ui/UIEditTextBinder.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/ui/UIEditTextBinder.java new file mode 100644 index 00000000..34c63b5c --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/ui/UIEditTextBinder.java @@ -0,0 +1,47 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.binder.ui; + +import com.taobao.luaview.fun.base.BaseFunctionBinder; +import com.taobao.luaview.fun.base.BaseVarArgUICreator; +import com.taobao.luaview.fun.mapper.ui.UIEditTextMethodMapper; +import com.taobao.luaview.view.LVEditText; +import com.taobao.luaview.view.interfaces.ILVView; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; +import org.luaj.vm2.lib.LibFunction; + +/** + * EditText 普通按钮 + * @author song + */ +public class UIEditTextBinder extends BaseFunctionBinder { + + public UIEditTextBinder() { + super("TextField"); + } + + @Override + public Class getMapperClass() { + return UIEditTextMethodMapper.class; + } + + @Override + public LuaValue createCreator(LuaValue env, LuaValue metaTable) { + return new BaseVarArgUICreator(env.checkglobals(), metaTable, getMapperClass()) { + @Override + public ILVView createView(Globals globals, LuaValue metaTable, Varargs varargs) { + return new LVEditText(globals, metaTable, varargs); + } + }; + } + +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/ui/UIHorizontalScrollViewBinder.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/ui/UIHorizontalScrollViewBinder.java new file mode 100644 index 00000000..3a025bc8 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/ui/UIHorizontalScrollViewBinder.java @@ -0,0 +1,48 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.binder.ui; + +import com.taobao.luaview.fun.base.BaseFunctionBinder; +import com.taobao.luaview.fun.base.BaseVarArgUICreator; +import com.taobao.luaview.fun.mapper.ui.UIHorizontalScrollViewMethodMapper; +import com.taobao.luaview.view.LVHorizontalScrollView; +import com.taobao.luaview.view.interfaces.ILVView; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; +import org.luaj.vm2.lib.LibFunction; + +/** + * HScrollView 横向可滚动容器类,放各个view + * + * @author song + * @date 15/8/20 + */ +public class UIHorizontalScrollViewBinder extends BaseFunctionBinder { + + public UIHorizontalScrollViewBinder() { + super("HScrollView"); + } + + @Override + public Class getMapperClass() { + return UIHorizontalScrollViewMethodMapper.class; + } + + @Override + public LuaValue createCreator(LuaValue env, LuaValue metaTable) { + return new BaseVarArgUICreator(env.checkglobals(), metaTable, getMapperClass()) { + @Override + public ILVView createView(Globals globals, LuaValue metaTable, Varargs varargs) { + return new LVHorizontalScrollView(globals, metaTable, varargs); + } + }; + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/ui/UIImageViewBinder.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/ui/UIImageViewBinder.java new file mode 100644 index 00000000..461aca81 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/ui/UIImageViewBinder.java @@ -0,0 +1,47 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.binder.ui; + +import com.taobao.luaview.fun.base.BaseFunctionBinder; +import com.taobao.luaview.fun.base.BaseVarArgUICreator; +import com.taobao.luaview.fun.mapper.ui.UIImageViewMethodMapper; +import com.taobao.luaview.view.LVImageView; +import com.taobao.luaview.view.interfaces.ILVView; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; +import org.luaj.vm2.lib.LibFunction; + +/** + * Image 图片 + * @author song + */ +public class UIImageViewBinder extends BaseFunctionBinder { + + public UIImageViewBinder() { + super("Image"); + } + + @Override + public Class getMapperClass() { + return UIImageViewMethodMapper.class; + } + + @Override + public LuaValue createCreator(LuaValue env, LuaValue metaTable) { + return new BaseVarArgUICreator(env.checkglobals(), metaTable, getMapperClass()) { + @Override + public ILVView createView(Globals globals, LuaValue metaTable, Varargs varargs) { + return new LVImageView(globals, metaTable, varargs); + } + }; + } + +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/ui/UIListViewBinder.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/ui/UIListViewBinder.java new file mode 100644 index 00000000..e770dcbe --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/ui/UIListViewBinder.java @@ -0,0 +1,48 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.binder.ui; + +import com.taobao.luaview.fun.base.BaseFunctionBinder; +import com.taobao.luaview.fun.base.BaseVarArgUICreator; +import com.taobao.luaview.fun.mapper.list.UIListViewMethodMapper; +import com.taobao.luaview.view.LVListView; +import com.taobao.luaview.view.interfaces.ILVView; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; +import org.luaj.vm2.lib.LibFunction; + +/** + * TableView 容器类,放各个view + * + * @author song + * @date 15/8/20 + */ +public class UIListViewBinder extends BaseFunctionBinder { + + public UIListViewBinder() { + super("TableView"); + } + + @Override + public Class getMapperClass() { + return UIListViewMethodMapper.class; + } + + @Override + public LuaValue createCreator(LuaValue env, LuaValue metaTable) { + return new BaseVarArgUICreator(env.checkglobals(), metaTable, getMapperClass()) { + @Override + public ILVView createView(Globals globals, LuaValue metaTable, Varargs varargs) { + return new LVListView(globals, metaTable, varargs, null); + } + }; + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/ui/UILoadingDialogBinder.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/ui/UILoadingDialogBinder.java new file mode 100644 index 00000000..aeaeda66 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/ui/UILoadingDialogBinder.java @@ -0,0 +1,49 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.binder.ui; + +import com.taobao.luaview.fun.base.BaseFunctionBinder; +import com.taobao.luaview.fun.base.BaseVarArgCreator; +import com.taobao.luaview.fun.mapper.LuaViewApi; +import com.taobao.luaview.fun.mapper.ui.UILoadingDialogMethodMapper; +import com.taobao.luaview.userdata.ui.UDLoadingDialog; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; +import org.luaj.vm2.lib.LibFunction; + +/** + * 菊花(对话框) + * @author song + */ +@Deprecated +@LuaViewApi(revisions = {"iOS 无"}) +public class UILoadingDialogBinder extends BaseFunctionBinder { + + public UILoadingDialogBinder() { + super("LoadingDialog"); + } + + @Override + public Class getMapperClass() { + return UILoadingDialogMethodMapper.class; + } + + @Override + public LuaValue createCreator(LuaValue env, LuaValue metaTable) { + return new BaseVarArgCreator(env.checkglobals(), metaTable, getMapperClass()) { + @Override + public LuaValue createUserdata(Globals globals, LuaValue metaTable, Varargs varargs) { + return new UDLoadingDialog(globals, metaTable, varargs); + } + }; + } + +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/ui/UILoadingViewBinder.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/ui/UILoadingViewBinder.java new file mode 100644 index 00000000..a4396163 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/ui/UILoadingViewBinder.java @@ -0,0 +1,47 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.binder.ui; + +import com.taobao.luaview.fun.base.BaseFunctionBinder; +import com.taobao.luaview.fun.base.BaseVarArgUICreator; +import com.taobao.luaview.fun.mapper.ui.UILoadingViewMethodMapper; +import com.taobao.luaview.view.LVLoadingView; +import com.taobao.luaview.view.interfaces.ILVView; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; +import org.luaj.vm2.lib.LibFunction; + +/** + * 菊花(非对话框) + * @author song + */ +public class UILoadingViewBinder extends BaseFunctionBinder { + + public UILoadingViewBinder() { + super("LoadingIndicator"); + } + + @Override + public Class getMapperClass() { + return UILoadingViewMethodMapper.class; + } + + @Override + public LuaValue createCreator(LuaValue env, LuaValue metaTable) { + return new BaseVarArgUICreator(env.checkglobals(), metaTable, getMapperClass()) { + @Override + public ILVView createView(Globals globals, LuaValue metaTable, Varargs varargs) { + return new LVLoadingView(globals, metaTable, varargs); + } + }; + } + +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/ui/UIRecyclerViewBinder.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/ui/UIRecyclerViewBinder.java new file mode 100644 index 00000000..8eaa9fd3 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/ui/UIRecyclerViewBinder.java @@ -0,0 +1,49 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.binder.ui; + +import com.taobao.luaview.fun.base.BaseFunctionBinder; +import com.taobao.luaview.fun.base.BaseVarArgUICreator; +import com.taobao.luaview.fun.mapper.list.UIRecyclerViewMethodMapper; +import com.taobao.luaview.view.LVRecyclerView; +import com.taobao.luaview.view.interfaces.ILVView; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; +import org.luaj.vm2.lib.LibFunction; + +/** + * RecyclerView for LuaView + * + * @author song + * @date 15/8/20 + */ +public class UIRecyclerViewBinder extends BaseFunctionBinder { + + public UIRecyclerViewBinder() { + super("CollectionView"); + } + + @Override + public Class getMapperClass() { + return UIRecyclerViewMethodMapper.class; + } + + @Override + public LuaValue createCreator(LuaValue env, LuaValue metaTable) { + return new BaseVarArgUICreator(env.checkglobals(), metaTable, getMapperClass()) { + @Override + public ILVView createView(Globals globals, LuaValue metaTable, Varargs varargs) { +// return new LVRecyclerView(globals, metaTable, varargs, null); + return LVRecyclerView.createVerticalView(globals, metaTable, varargs, null); + } + }; + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/ui/UIRefreshLayoutBinder.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/ui/UIRefreshLayoutBinder.java new file mode 100644 index 00000000..c32437ca --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/ui/UIRefreshLayoutBinder.java @@ -0,0 +1,46 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.binder.ui; + +import com.taobao.luaview.fun.base.BaseFunctionBinder; +import com.taobao.luaview.fun.base.BaseVarArgUICreator; +import com.taobao.luaview.fun.mapper.ui.UIRefreshLayoutViewMethodMapper; +import com.taobao.luaview.view.LVRefreshLayout; +import com.taobao.luaview.view.interfaces.ILVView; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; +import org.luaj.vm2.lib.LibFunction; + +/** + * Created by tuoli on 12/20/16. + */ + +public class UIRefreshLayoutBinder extends BaseFunctionBinder { + + public UIRefreshLayoutBinder() { + super("RefreshLayout"); + } + + @Override + public Class getMapperClass() { + return UIRefreshLayoutViewMethodMapper.class; + } + + @Override + public LuaValue createCreator(LuaValue env, LuaValue metaTable) { + return new BaseVarArgUICreator(env.checkglobals(), metaTable, getMapperClass()) { + @Override + public ILVView createView(Globals globals, LuaValue metaTable, Varargs varargs) { + return new LVRefreshLayout(globals, metaTable, varargs); + } + }; + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/ui/UIRefreshListViewBinder.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/ui/UIRefreshListViewBinder.java new file mode 100644 index 00000000..0e4e5976 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/ui/UIRefreshListViewBinder.java @@ -0,0 +1,49 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.binder.ui; + +import com.taobao.luaview.fun.base.BaseFunctionBinder; +import com.taobao.luaview.fun.base.BaseVarArgUICreator; +import com.taobao.luaview.fun.mapper.list.UIRefreshListViewMethodMapper; +import com.taobao.luaview.view.LVRefreshListView; +import com.taobao.luaview.view.interfaces.ILVView; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; +import org.luaj.vm2.lib.LibFunction; + +/** + * 容器类,放各个view, Refreshable TableView/ListView + * + * @author song + * @date 15/8/20 + */ +public class UIRefreshListViewBinder extends BaseFunctionBinder { + + public UIRefreshListViewBinder() { + super("RefreshTableView"); + } + + @Override + public Class getMapperClass() { + return UIRefreshListViewMethodMapper.class; + } + + @Override + public LuaValue createCreator(LuaValue env, LuaValue metaTable) { + return new BaseVarArgUICreator(env.checkglobals(), metaTable, getMapperClass()) {//TODO 这里加载耗时3ms + @Override + public ILVView createView(Globals globals, LuaValue metaTable, Varargs varargs) { + return new LVRefreshListView(globals, metaTable, varargs); + } + }; + } + +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/ui/UIRefreshRecyclerViewBinder.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/ui/UIRefreshRecyclerViewBinder.java new file mode 100644 index 00000000..355ce165 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/ui/UIRefreshRecyclerViewBinder.java @@ -0,0 +1,48 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.binder.ui; + +import com.taobao.luaview.fun.base.BaseFunctionBinder; +import com.taobao.luaview.fun.base.BaseVarArgUICreator; +import com.taobao.luaview.fun.mapper.list.UIRefreshRecyclerViewMethodMapper; +import com.taobao.luaview.view.LVRefreshRecyclerView; +import com.taobao.luaview.view.interfaces.ILVView; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; +import org.luaj.vm2.lib.LibFunction; + +/** + * 容器类,放各个view, Refreshable CollectionView/RecyclerView + * + * @author song + * @date 15/8/20 + */ +public class UIRefreshRecyclerViewBinder extends BaseFunctionBinder { + + public UIRefreshRecyclerViewBinder() { + super("RefreshCollectionView"); + } + + @Override + public Class getMapperClass() { + return UIRefreshRecyclerViewMethodMapper.class; + } + + @Override + public LuaValue createCreator(LuaValue env, LuaValue metaTable) { + return new BaseVarArgUICreator(env.checkglobals(), metaTable, getMapperClass()) { + @Override + public ILVView createView(Globals globals, LuaValue metaTable, Varargs varargs) { + return new LVRefreshRecyclerView(globals, metaTable, varargs); + } + }; + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/ui/UITextViewBinder.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/ui/UITextViewBinder.java new file mode 100644 index 00000000..cee554c0 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/ui/UITextViewBinder.java @@ -0,0 +1,47 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.binder.ui; + +import com.taobao.luaview.fun.base.BaseFunctionBinder; +import com.taobao.luaview.fun.base.BaseVarArgUICreator; +import com.taobao.luaview.fun.mapper.ui.UITextViewMethodMapper; +import com.taobao.luaview.view.LVTextView; +import com.taobao.luaview.view.interfaces.ILVView; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; +import org.luaj.vm2.lib.LibFunction; + +/** + * 文本 + * @author song + */ +public class UITextViewBinder extends BaseFunctionBinder { + + public UITextViewBinder() { + super("Label"); + } + + @Override + public Class getMapperClass() { + return UITextViewMethodMapper.class; + } + + @Override + public LuaValue createCreator(LuaValue env, LuaValue metaTable) { + return new BaseVarArgUICreator(env.checkglobals(), metaTable, getMapperClass()) { + @Override + public ILVView createView(Globals globals, LuaValue metaTable, Varargs varargs) { + return new LVTextView(globals, metaTable, varargs); + } + }; + } + +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/ui/UIToastBinder.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/ui/UIToastBinder.java new file mode 100644 index 00000000..f0d84df1 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/ui/UIToastBinder.java @@ -0,0 +1,47 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.binder.ui; + +import com.taobao.luaview.fun.base.BaseFunctionBinder; +import com.taobao.luaview.fun.base.BaseVarArgCreator; +import com.taobao.luaview.fun.mapper.ui.UIToastMethodMapper; +import com.taobao.luaview.userdata.ui.UDToast; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; +import org.luaj.vm2.lib.LibFunction; + +/** + * Toast for LuaView + * + * @author song + * @date 15/9/2 + */ +public class UIToastBinder extends BaseFunctionBinder { + + public UIToastBinder() { + super("Toast"); + } + + @Override + public Class getMapperClass() { + return UIToastMethodMapper.class; + } + + @Override + public LuaValue createCreator(LuaValue env, final LuaValue metaTable) { + return new BaseVarArgCreator(env.checkglobals(), metaTable, getMapperClass()) { + @Override + public LuaValue createUserdata(Globals globals, LuaValue metaTable, Varargs varargs) { + return new UDToast(globals, metaTable, varargs); + } + }; + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/ui/UIViewGroupBinder.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/ui/UIViewGroupBinder.java new file mode 100644 index 00000000..df2e6e26 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/ui/UIViewGroupBinder.java @@ -0,0 +1,48 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.binder.ui; + +import com.taobao.luaview.fun.base.BaseFunctionBinder; +import com.taobao.luaview.fun.base.BaseVarArgUICreator; +import com.taobao.luaview.fun.mapper.ui.UIViewGroupMethodMapper; +import com.taobao.luaview.view.LVViewGroup; +import com.taobao.luaview.view.interfaces.ILVView; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; +import org.luaj.vm2.lib.LibFunction; + +/** + * 容器类,放各个view + * + * @author song + * @date 15/8/20 + */ +public class UIViewGroupBinder extends BaseFunctionBinder { + + public UIViewGroupBinder() { + super("View"); + } + + @Override + public Class getMapperClass() { + return UIViewGroupMethodMapper.class; + } + + @Override + public LuaValue createCreator(LuaValue env, LuaValue metaTable) { + return new BaseVarArgUICreator(env.checkglobals(), metaTable, getMapperClass()) { + @Override + public ILVView createView(Globals globals, LuaValue metaTable, Varargs varargs) { + return new LVViewGroup(globals, metaTable, varargs); + } + }; + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/ui/UIViewPagerBinder.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/ui/UIViewPagerBinder.java new file mode 100644 index 00000000..9e398793 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/ui/UIViewPagerBinder.java @@ -0,0 +1,48 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.binder.ui; + +import com.taobao.luaview.fun.base.BaseFunctionBinder; +import com.taobao.luaview.fun.base.BaseVarArgUICreator; +import com.taobao.luaview.fun.mapper.ui.UIViewPagerMethodMapper; +import com.taobao.luaview.view.LVViewPager; +import com.taobao.luaview.view.interfaces.ILVView; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; +import org.luaj.vm2.lib.LibFunction; + +/** + * 容器类,ViewPager + * + * @author song + * @date 15/8/20 + */ +public class UIViewPagerBinder extends BaseFunctionBinder { + + public UIViewPagerBinder() { + super("PagerView"); + } + + @Override + public Class getMapperClass() { + return UIViewPagerMethodMapper.class; + } + + @Override + public LuaValue createCreator(LuaValue env, LuaValue metaTable) { + return new BaseVarArgUICreator(env.checkglobals(), metaTable, getMapperClass()) { + @Override + public ILVView createView(Globals globals, LuaValue metaTable, Varargs varargs) { + return new LVViewPager(globals, metaTable, varargs); + } + }; + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/ui/UIWebViewBinder.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/ui/UIWebViewBinder.java new file mode 100644 index 00000000..1bbfd00a --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/binder/ui/UIWebViewBinder.java @@ -0,0 +1,46 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.binder.ui; + +import com.taobao.luaview.fun.base.BaseFunctionBinder; +import com.taobao.luaview.fun.base.BaseVarArgUICreator; +import com.taobao.luaview.fun.mapper.ui.UIWebViewMethodMapper; +import com.taobao.luaview.view.LVWebView; +import com.taobao.luaview.view.interfaces.ILVView; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; +import org.luaj.vm2.lib.LibFunction; + +/** + * Created by tuoli on 10/9/16. + */ + +public class UIWebViewBinder extends BaseFunctionBinder { + + public UIWebViewBinder() { + super("WebView"); + } + + @Override + public Class getMapperClass() { + return UIWebViewMethodMapper.class; + } + + @Override + public LuaValue createCreator(LuaValue env, LuaValue metaTable) { + return new BaseVarArgUICreator(env.checkglobals(), metaTable, getMapperClass()) { + @Override + public ILVView createView(Globals globals, LuaValue metaTable, Varargs varargs) { + return new LVWebView(globals, metaTable, varargs); + } + }; + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/LuaViewApi.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/LuaViewApi.java new file mode 100644 index 00000000..ce0b22f8 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/LuaViewApi.java @@ -0,0 +1,43 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.mapper; + +import com.taobao.luaview.global.VmVersion; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * LuaView UI Lib 标识 + * + * @author song + * @date 15/12/25 + */ +@Documented +@Retention(RetentionPolicy.SOURCE) +@Target({ElementType.METHOD, ElementType.TYPE}) +public @interface LuaViewApi { + + /** + * api 起始版本,不写标示从默认版本起始 + */ + String since() default VmVersion.V_440; + + /** + * api 修订版本,标示该API修订过,之前可能有bug,或者只是空实现。 + * 字符串,默认为空。 + * 每次新增两个字符串:第一个标示版本,第二句标示修订内容。 + * + * @return + */ + String[] revisions() default {}; +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/LuaViewLib.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/LuaViewLib.java new file mode 100644 index 00000000..65329078 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/LuaViewLib.java @@ -0,0 +1,35 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.mapper; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * LuaView UI Lib 标识 + * + * @author song + * @date 15/12/25 + */ +@Documented +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface LuaViewLib { + /** + * api 修订版本,标示该API修订过,之前可能有bug,或者只是空实现。 + * 字符串,默认为空。 + * 每次新增两个字符串:第一个标示版本,第二句标示修订内容。 + * + * @return + */ + String[] revisions() default {}; +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/indicator/UICircleViewPagerIndicatorMethodMapper.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/indicator/UICircleViewPagerIndicatorMethodMapper.java new file mode 100644 index 00000000..0b7d777f --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/indicator/UICircleViewPagerIndicatorMethodMapper.java @@ -0,0 +1,318 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.mapper.indicator; + +import com.taobao.luaview.fun.mapper.LuaViewApi; +import com.taobao.luaview.fun.mapper.LuaViewLib; +import com.taobao.luaview.fun.mapper.ui.UIViewMethodMapper; +import com.taobao.luaview.global.VmVersion; +import com.taobao.luaview.userdata.indicator.UDCircleViewPagerIndicator; +import com.taobao.luaview.util.ColorUtil; +import com.taobao.luaview.util.DimenUtil; +import com.taobao.luaview.util.LuaUtil; + +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; + +import java.util.List; + + +/** + * method mapper for PagerIndicator + * + * @param + */ +@LuaViewLib(revisions = {"20170306已对标"}) +public class UICircleViewPagerIndicatorMethodMapper extends UIViewMethodMapper { + private static final String TAG = "UICircleViewPagerIndicatorMethodMapper"; + private static final String[] sMethods = new String[]{ + "unselectedColor",//0 + "selectedColor",//1 + "fillColor",//2 + "pageColor",//3 + "strokeWidth",//4 + "strokeColor",//5 + "radius",//6 + "snap",//7 + "currentPage",//8 + "currentItem"//9 + }; + + @Override + public List getAllFunctionNames() { + return mergeFunctionNames(TAG, super.getAllFunctionNames(), sMethods); + } + + @Override + public Varargs invoke(int code, U target, Varargs varargs) { + final int opcode = code - super.getAllFunctionNames().size(); + switch (opcode) { + case 0: + return unselectedColor(target, varargs); + case 1: + return selectedColor(target, varargs); + case 2: + return fillColor(target, varargs); + case 3: + return pageColor(target, varargs); + case 4: + return strokeWidth(target, varargs); + case 5: + return strokeColor(target, varargs); + case 6: + return radius(target, varargs); + case 7: + return snap(target, varargs); + case 8: + return currentPage(target, varargs); + case 9: + return currentItem(target, varargs); + } + return super.invoke(code, target, varargs); + } + + //--------------------------------------- API -------------------------------------------------- + + /** + * 设置未选中颜色 + * + * @param view + * @param varargs + * @return + */ + public LuaValue unselectedColor(U view, Varargs varargs) { + return pageColor(view, varargs); + } + + public LuaValue setUnselectedColor(U view, Varargs varargs) { + return setPageColor(view, varargs); + } + + public LuaValue getUnselectedColor(U view, Varargs varargs) { + return getPageColor(view, varargs); + } + + /** + * 设置选中颜色 + * + * @param view + * @param varargs + * @return + */ + @LuaViewApi(since = VmVersion.V_500) + public LuaValue selectedColor(U view, Varargs varargs) { + return fillColor(view, varargs); + } + + @LuaViewApi(since = VmVersion.V_500) + public LuaValue setSelectedColor(U view, Varargs varargs) { + return setFillColor(view, varargs); + } + + @LuaViewApi(since = VmVersion.V_500) + public LuaValue getSelectedColor(U view, Varargs varargs) { + return getFileColor(view, varargs); + } + + /** + * 设置未选中颜色 + * + * @param view + * @param varargs + * @return + */ + @Deprecated + public LuaValue fillColor(U view, Varargs varargs) { + if (varargs.narg() > 1) {//set + return setFillColor(view, varargs); + } else { + return getFileColor(view, varargs); + } + } + + public LuaValue setFillColor(U view, Varargs varargs) { + final Integer color = ColorUtil.parse(LuaUtil.getInt(varargs, 2)); + return view.setFillColor(color); + } + + public LuaValue getFileColor(U view, Varargs varargs) { + return valueOf(ColorUtil.getHexColor(view.getFillColor())); + } + + + /** + * 设置颜色 + * + * @param view + * @param varargs + * @return + */ + @Deprecated + public LuaValue pageColor(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setPageColor(view, varargs); + } else { + return getPageColor(view, varargs); + } + } + + public LuaValue setPageColor(U view, Varargs varargs) { + final Integer color = ColorUtil.parse(LuaUtil.getInt(varargs, 2)); + return view.setPageColor(color); + } + + public LuaValue getPageColor(U view, Varargs varargs) { + return valueOf(ColorUtil.getHexColor(view.getPageColor())); + } + + /** + * 设置线条宽度 + * + * @param view + * @param varargs + * @return + */ + @Deprecated + public LuaValue strokeWidth(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setStrokeWidth(view, varargs); + } else { + return getStrokeWidth(view, varargs); + } + } + + public LuaValue setStrokeWidth(U view, Varargs varargs) { + final int width = DimenUtil.dpiToPx(varargs.arg(2)); + return view.setStrokeWidth(width); + } + + public LuaValue getStrokeWidth(U view, Varargs varargs) { + return valueOf(DimenUtil.pxToDpi(view.getStrokeWidth())); + } + + /** + * 设置线条颜色 + * + * @param view + * @param varargs + * @return + */ + @Deprecated + public LuaValue strokeColor(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setStrokeColor(view, varargs); + } else { + return getStrokeColor(view, varargs); + } + } + + public LuaValue setStrokeColor(U view, Varargs varargs) { + final Integer color = ColorUtil.parse(LuaUtil.getInt(varargs, 2)); + return view.setStrokeColor(color); + } + + public LuaValue getStrokeColor(U view, Varargs varargs) { + return valueOf(ColorUtil.getHexColor(view.getStrokeColor())); + } + + /** + * 设置半径 + * + * @param view + * @param varargs + * @return + */ + @Deprecated + public LuaValue radius(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setRadius(view, varargs); + } else { + return getRadius(view, varargs); + } + } + + public LuaValue setRadius(U view, Varargs varargs) { + final int radius = DimenUtil.dpiToPx(varargs.arg(2)); + return view.setRadius(radius); + } + + public LuaValue getRadius(U view, Varargs varargs) { + return valueOf(DimenUtil.pxToDpi(view.getRadius())); + } + + /** + * 设置是否移动瞬间过去 + * + * @param view + * @param varargs + * @return + */ + @Deprecated + public LuaValue snap(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setSnap(view, varargs); + } else { + return isSnap(view, varargs); + } + } + + public LuaValue setSnap(U view, Varargs varargs) { + final boolean snap = varargs.optboolean(2, false); + return view.setSnap(snap); + } + + public LuaValue isSnap(U view, Varargs varargs) { + return valueOf(view.isSnap()); + } + + /** + * 设置当前第几页 + * + * @param view + * @param varargs + * @return + */ + public LuaValue currentPage(U view, Varargs varargs) { + return currentItem(view, varargs); + } + + public LuaValue setCurrentPage(U view, Varargs varargs) { + return setCurrentItem(view, varargs); + } + + public LuaValue getCurrentPage(U view, Varargs varargs) { + return getCurrentItem(view, varargs); + } + + /** + * 设置当前第几页 + * + * @param view + * @param varargs + * @return + */ + @Deprecated + public LuaValue currentItem(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setCurrentItem(view, varargs); + } else { + return getCurrentItem(view, varargs); + } + } + + public LuaValue setCurrentItem(U view, Varargs varargs) { + final int currentItem = varargs.optint(2, -1); + return view.setCurrentItem(currentItem); + } + + public LuaValue getCurrentItem(U view, Varargs varargs) { + //TODO 这里需要获取currentItem,但是PageIndicator不支持 + return view; + } +} \ No newline at end of file diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/indicator/UICustomViewPagerIndicatorMethodMapper.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/indicator/UICustomViewPagerIndicatorMethodMapper.java new file mode 100644 index 00000000..ee4825c6 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/indicator/UICustomViewPagerIndicatorMethodMapper.java @@ -0,0 +1,99 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.mapper.indicator; + +import com.taobao.luaview.fun.mapper.LuaViewLib; +import com.taobao.luaview.fun.mapper.ui.UIViewMethodMapper; +import com.taobao.luaview.userdata.indicator.UDCustomViewPagerIndicator; +import com.taobao.luaview.util.LuaUtil; + +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; + +import java.util.List; + +/** + * Method Mapper for Custom View Pager + * + * @param + * @author song + */ +@LuaViewLib(revisions = {"20170306已对标", "iOS无"}) +@Deprecated +public class UICustomViewPagerIndicatorMethodMapper extends UIViewMethodMapper { + private static final String TAG = "UICustomViewPagerIndicatorMethodMapper"; + private static final String[] sMethods = new String[]{ + "currentPage",//0 + "currentItem"//1 + }; + + @Override + public List getAllFunctionNames() { + return mergeFunctionNames(TAG, super.getAllFunctionNames(), sMethods); + } + + @Override + public Varargs invoke(int code, U target, Varargs varargs) { + final int opcode = code - super.getAllFunctionNames().size(); + switch (opcode) { + case 0: + return currentPage(target, varargs); + case 1: + return currentItem(target, varargs); + } + return super.invoke(code, target, varargs); + } + + //--------------------------------------- API -------------------------------------------------- + + /** + * 滚动到第几页面 + * + * @param view + * @param varargs + * @return + */ + public LuaValue currentPage(U view, Varargs varargs) { + return currentItem(view, varargs); + } + + public LuaValue setCurrentPage(U view, Varargs varargs) { + return setCurrentItem(view, varargs); + } + + public LuaValue getCurrentPage(U view, Varargs varargs) { + return getCurrentItem(view, varargs); + } + + /** + * 设置滚动到第几页 + * + * @param view + * @param varargs + * @return + */ + public LuaValue currentItem(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setCurrentItem(view, varargs); + } else { + return getCurrentItem(view, varargs); + } + } + + public LuaValue setCurrentItem(U view, Varargs varargs) { + final int item = varargs.optint(2, -1); + return view.setCurrentItem(item); + } + + public LuaValue getCurrentItem(U view, Varargs varargs) { + return LuaUtil.toLuaInt(view.getCurrentItem()); + } + + +} \ No newline at end of file diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/kit/AudioMethodMapper.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/kit/AudioMethodMapper.java new file mode 100644 index 00000000..8683e66a --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/kit/AudioMethodMapper.java @@ -0,0 +1,193 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.mapper.kit; + +import com.taobao.luaview.fun.base.BaseMethodMapper; +import com.taobao.luaview.fun.mapper.LuaViewLib; +import com.taobao.luaview.userdata.kit.UDAudio; +import com.taobao.luaview.util.LuaUtil; + +import org.luaj.vm2.LuaFunction; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; + +import java.util.List; + +/** + * Audio 接口封装,声音处理 + * + * @author song + * @date 15/8/21 + */ +@LuaViewLib(revisions = {"20170306已对标"}) +public class AudioMethodMapper extends BaseMethodMapper { + private static final String TAG = "AudioMethodMapper"; + private static final String[] sMethods = new String[]{ + "play",//0 + "pause",//1 + "resume",//2 + "stop",//3 + "seekTo",//4 + "callback",//5 + "playing",//6 + "pausing",//7 + "looping"//8 + }; + + @Override + public List getAllFunctionNames() { + return mergeFunctionNames(TAG, super.getAllFunctionNames(), sMethods); + } + + @Override + public Varargs invoke(int code, U target, Varargs varargs) { + final int optcode = code - super.getAllFunctionNames().size(); + switch (optcode) { + case 0: + return play(target, varargs); + case 1: + return pause(target, varargs); + case 2: + return resume(target, varargs); + case 3: + return stop(target, varargs); + case 4: + return seekTo(target, varargs); + case 5: + return callback(target, varargs); + case 6: + return playing(target, varargs); + case 7: + return pausing(target, varargs); + case 8: + return looping(target, varargs); + } + return super.invoke(code, target, varargs); + } + + //--------------------------------------- API -------------------------------------------------- + + /** + * play music + * + * @param audio + * @param varargs + * @return + */ + public LuaValue play(U audio, Varargs varargs) { + final String uriOrName = LuaUtil.getString(varargs, 2); + final Integer loopTimes = LuaUtil.getInt(varargs, 2, 3); + return audio.play(uriOrName, loopTimes); + } + + /** + * pause playing + * + * @param audio + * @param varargs + * @return + */ + public LuaValue pause(U audio, Varargs varargs) { + return audio.pause(); + } + + + /** + * resume playing + * + * @param audio + * @param varargs + * @return + */ + public LuaValue resume(U audio, Varargs varargs) { + return audio.resume(); + } + + /** + * stop playing + * + * @param audio + * @param varargs + * @return + */ + public LuaValue stop(U audio, Varargs varargs) { + return audio.stop(); + } + + /** + * 到某个位置 + * + * @param audio + * @param varargs + * @return + */ + public LuaValue seekTo(U audio, Varargs varargs) { + final Integer msec = LuaUtil.getInt(varargs, 2); + return audio.seekTo(msec); + } + + /** + * 回调 + * + * @param audio + * @param varargs + * @return + */ + public LuaValue callback(U audio, Varargs varargs) { + if (varargs.narg() > 1) { + return setCallback(audio, varargs); + } else { + return getCallback(audio, varargs); + } + } + + public LuaValue setCallback(U audio, Varargs varargs) { + final LuaFunction callback = LuaUtil.getFunction(varargs, 2); + return audio.setCallback(callback); + } + + public LuaValue getCallback(U audio, Varargs varargs) { + return audio.getCallback(); + } + + + /** + * 是否播放 + * + * @param audio + * @param varargs + * @return + */ + public LuaValue playing(U audio, Varargs varargs) { + return valueOf(audio.isPlaying()); + } + + /** + * 是否暂停 + * + * @param audio + * @param varargs + * @return + */ + public LuaValue pausing(U audio, Varargs varargs) { + return valueOf(audio.isPause()); + } + + /** + * 是否循环 + * + * @param audio + * @param varargs + * @return + */ + public LuaValue looping(U audio, Varargs varargs) { + return valueOf(audio.isLooping()); + } + +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/kit/BitmapMethodMapper.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/kit/BitmapMethodMapper.java new file mode 100644 index 00000000..61ee89b5 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/kit/BitmapMethodMapper.java @@ -0,0 +1,83 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.mapper.kit; + +import com.taobao.luaview.fun.base.BaseMethodMapper; +import com.taobao.luaview.fun.mapper.LuaViewLib; +import com.taobao.luaview.userdata.kit.UDBitmap; +import com.taobao.luaview.util.DimenUtil; +import com.taobao.luaview.util.LuaUtil; + +import org.luaj.vm2.LuaFunction; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; + +import java.util.List; + +/** + * Bitmap 接口封装,二进制数据处理 + * + * @author song + * @date 15/8/21 + */ +@LuaViewLib(revisions = {"20170306已对标"}) +public class BitmapMethodMapper extends BaseMethodMapper { + private static final String TAG = "BitmapMethodMapper"; + + private static final String[] sMethods = new String[]{ + "sprite",//0 + "size",//1 + }; + + @Override + public List getAllFunctionNames() { + return mergeFunctionNames(TAG, super.getAllFunctionNames(), sMethods); + } + + @Override + public Varargs invoke(int code, U target, Varargs varargs) { + final int optcode = code - super.getAllFunctionNames().size(); + switch (optcode) { + case 0: + return sprite(target, varargs); + case 1: + return size(target, varargs); + } + return super.invoke(code, target, varargs); + } + + //--------------------------------------- API -------------------------------------------------- + + /** + * 切割bitmap + * + * @param bitmap + * @param varargs + * @return + */ + public LuaValue sprite(U bitmap, Varargs varargs) { + final int x = DimenUtil.dpiToPx(varargs.arg(2)); + final int y = DimenUtil.dpiToPx(varargs.arg(3)); + final int width = DimenUtil.dpiToPx(varargs.arg(4)); + final int height = DimenUtil.dpiToPx(varargs.arg(5)); + final LuaFunction callback = LuaUtil.getFunction(varargs, 6); + return bitmap.sprite(x, y, width, height, callback); + } + + /** + * 获取bitmap size + * + * @param bitmap + * @param varargs + * @return + */ + public Varargs size(U bitmap, Varargs varargs) { + return varargsOf(new LuaValue[]{valueOf(DimenUtil.pxToDpi(bitmap.getWidth())), valueOf(DimenUtil.pxToDpi(bitmap.getHeight()))}); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/kit/DataMethodMapper.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/kit/DataMethodMapper.java new file mode 100644 index 00000000..338fde08 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/kit/DataMethodMapper.java @@ -0,0 +1,108 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.mapper.kit; + +import com.taobao.luaview.fun.base.BaseMethodMapper; +import com.taobao.luaview.fun.mapper.LuaViewLib; +import com.taobao.luaview.userdata.kit.UDData; + +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; + +import java.util.List; + +/** + * Data 接口封装,二进制数据处理 + * + * @author song + * @date 15/8/21 + */ +@LuaViewLib(revisions = {"20170306已对标"}) +public class DataMethodMapper extends BaseMethodMapper { + private static final String TAG = "DataMethodMapper"; + + private static final String[] sMethods = new String[]{ + "append",//0 + "toString",//1 + "toJson",//2 + "toTable",//3 + }; + + @Override + public List getAllFunctionNames() { + return mergeFunctionNames(TAG, super.getAllFunctionNames(), sMethods); + } + + @Override + public Varargs invoke(int code, U target, Varargs varargs) { + final int optcode = code - super.getAllFunctionNames().size(); + switch (optcode){ + case 0: + return append(target, varargs); + case 1: + return toString(target, varargs); + case 2: + return toJson(target, varargs); + case 3: + return toTable(target, varargs); + } + return super.invoke(code, target, varargs); + } + + //--------------------------------------- API -------------------------------------------------- + + /** + * 新增一部分数据,防止新建一个对象 + * + * @param data + * @param varargs + * @return + */ + public LuaValue append(U data, Varargs varargs) { + return data.append(varargs.arg(2)); + } + + + /** + * 将二进制数据转成String,使用给定的编码,默认utf-8 + * + * @param data + * @param varargs + * @return + */ + public LuaValue toString(U data, Varargs varargs) { + final String encode = varargs.optjstring(2, UDData.DEFAULT_ENCODE); + return valueOf(data.toString(encode)); + } + + /** + * 将二进制数据转成Json,使用给定的编码,默认utf-8 + * + * @param data + * @param varargs + * @return + */ + public LuaValue toJson(U data, Varargs varargs) { + final String encode = varargs.optjstring(2, UDData.DEFAULT_ENCODE); + final String json = data.toJson(encode); + return json != null ? valueOf(json) : NIL; + } + + /** + * 将二进制数据转成table,使用给定的编码,默认utf-8 + * + * @param data + * @param varargs + * @return + */ + public LuaValue toTable(U data, Varargs varargs) { + final String encode = varargs.optjstring(2, UDData.DEFAULT_ENCODE); + return data.toTable(encode); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/kit/TimerMethodMapper.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/kit/TimerMethodMapper.java new file mode 100644 index 00000000..b06ea8af --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/kit/TimerMethodMapper.java @@ -0,0 +1,229 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.mapper.kit; + +import com.taobao.luaview.fun.base.BaseMethodMapper; +import com.taobao.luaview.fun.mapper.LuaViewApi; +import com.taobao.luaview.fun.mapper.LuaViewLib; +import com.taobao.luaview.global.VmVersion; +import com.taobao.luaview.userdata.kit.UDTimer; +import com.taobao.luaview.util.LuaUtil; + +import org.luaj.vm2.LuaFunction; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; + +import java.util.List; + +/** + * timer 接口封装 + * + * @author song + * @date 15/8/21 + */ +@LuaViewLib(revisions = {"20170306已对标"}) +public class TimerMethodMapper extends BaseMethodMapper { + private static final String TAG = "TimerMethodMapper"; + private static final String[] sMethods = new String[]{ + "delay",//0 + "repeat",//1 + "repeatCount",//2 + "interval",//3 + "start",//4 + "callback",//5 + "cancel"//6 + }; + + @Override + public List getAllFunctionNames() { + return mergeFunctionNames(TAG, super.getAllFunctionNames(), sMethods); + } + + @Override + public Varargs invoke(int code, U target, Varargs varargs) { + final int optcode = code - super.getAllFunctionNames().size(); + switch (optcode) { + case 0: + return delay(target, varargs); + case 1: + return repeat(target, varargs); + case 2: + return repeatCount(target, varargs); + case 3: + return interval(target, varargs); + case 4: + return start(target, varargs); + case 5: + return callback(target, varargs); + case 6: + return cancel(target, varargs); + } + return super.invoke(code, target, varargs); + } + + //--------------------------------------- API -------------------------------------------------- + + /** + * 启动延时 + * + * @param udTimer + * @param varargs + * @return + */ + @LuaViewApi(since = VmVersion.V_500) + public LuaValue delay(U udTimer, Varargs varargs) { + if (varargs.narg() > 1) { + return setDelay(udTimer, varargs); + } else { + return getDelay(udTimer, varargs); + } + } + + @LuaViewApi(since = VmVersion.V_500) + public LuaValue setDelay(U udTimer, Varargs varargs) { + final long delay = LuaUtil.getTimeLong(varargs, 0f, 2); + return udTimer.setDelay(delay); + } + + @LuaViewApi(since = VmVersion.V_500) + public LuaValue getDelay(U udTimer, Varargs varargs) { + return valueOf(udTimer.getDelay()); + } + + /** + * 是否重复 + * + * @param udTimer + * @param varargs + * @return + */ + @LuaViewApi(since = VmVersion.V_500) + public LuaValue repeat(U udTimer, Varargs varargs) { + if (varargs.narg() > 1) { + return setRepeat(udTimer, varargs); + } else { + return getRepeat(udTimer, varargs); + } + } + + @LuaViewApi(since = VmVersion.V_500) + public LuaValue setRepeat(U udTimer, Varargs varargs) { + final boolean repeat = LuaUtil.getBoolean(varargs, false, 2); + return udTimer.setRepeat(repeat); + } + + @LuaViewApi(since = VmVersion.V_500) + public LuaValue getRepeat(U udTimer, Varargs varargs) { + return valueOf(udTimer.isRepeat()); + } + + /** + * 重复次数 + * TODO 修改次数控制 + * @param udTimer + * @param varargs + * @return + */ + @LuaViewApi(since = VmVersion.V_511) + @Deprecated + public LuaValue repeatCount(U udTimer, Varargs varargs) { + if (varargs.narg() > 1) { + return setRepeatCount(udTimer, varargs); + } else { + return getRepeatCount(udTimer, varargs); + } + } + + @LuaViewApi(since = VmVersion.V_511) + public LuaValue setRepeatCount(U udTimer, Varargs varargs) { + final int repeat = LuaUtil.getInt(varargs, 0, 2); + return udTimer.setRepeat(repeat > 0); + } + + @LuaViewApi(since = VmVersion.V_511) + public LuaValue getRepeatCount(U udTimer, Varargs varargs) { + return valueOf(udTimer.isRepeat()); + } + + + /** + * 设置interval + * + * @param udTimer + * @param varargs + * @return + */ + @LuaViewApi(since = VmVersion.V_500) + public LuaValue interval(U udTimer, Varargs varargs) { + if (varargs.narg() > 1) { + return setInterval(udTimer, varargs); + } else { + return getInterval(udTimer, varargs); + } + } + + @LuaViewApi(since = VmVersion.V_500) + public LuaValue setInterval(U udTimer, Varargs varargs) { + final long interval = LuaUtil.getTimeLong(varargs, 1f, 2); + return udTimer.setInterval(interval); + } + + @LuaViewApi(since = VmVersion.V_500) + public LuaValue getInterval(U udTimer, Varargs varargs) { + return valueOf(udTimer.getInterval()); + } + + /** + * 取消定时器 + * + * @param udTimer + * @param varargs + * @return + */ + public LuaValue start(U udTimer, Varargs varargs) { + final Long interval = LuaUtil.getTimeLong(varargs, 2); + final Boolean repeat = LuaUtil.getBoolean(varargs, 3); + return udTimer.start(interval, repeat); + } + + /** + * 取消定时器 + * + * @param udTimer + * @param varargs + * @return + */ + public LuaValue callback(U udTimer, Varargs varargs) { + if (varargs.narg() > 1) { + return setCallback(udTimer, varargs); + } else { + return getCallback(udTimer, varargs); + } + } + + public LuaValue setCallback(U udTimer, Varargs varargs) { + final LuaFunction callback = varargs.optfunction(2, null); + return udTimer.setCallback(callback); + } + + public LuaValue getCallback(U udTimer, Varargs varargs) { + return udTimer.getCallback(); + } + + /** + * 取消定时器 + * + * @param udTimer + * @param varargs + * @return + */ + public LuaValue cancel(U udTimer, Varargs varargs) { + return udTimer.cancel(); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/kit/VibratorMethodMapper.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/kit/VibratorMethodMapper.java new file mode 100644 index 00000000..a550e7db --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/kit/VibratorMethodMapper.java @@ -0,0 +1,100 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.mapper.kit; + +import com.taobao.luaview.fun.base.BaseMethodMapper; +import com.taobao.luaview.fun.mapper.LuaViewApi; +import com.taobao.luaview.fun.mapper.LuaViewLib; +import com.taobao.luaview.userdata.kit.UDVibrator; +import com.taobao.luaview.util.DateUtil; +import com.taobao.luaview.util.LuaUtil; + +import org.luaj.vm2.LuaTable; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; + +import java.util.List; + +/** + * Vibrate 接口封装,声音处理 + * + * @author song + * @date 15/8/21 + */ +@LuaViewLib(revisions = {"20170306已对标", "iOS不支持复杂功能"}) +public class VibratorMethodMapper extends BaseMethodMapper { + private static final String TAG = "VibratorMethodMapper"; + private static final String[] sMethods = new String[]{ + "hasVibrator",//0 + "vibrate",//1 + "cancel"//2 + }; + + @Override + public List getAllFunctionNames() { + return mergeFunctionNames(TAG, super.getAllFunctionNames(), sMethods); + } + + @Override + public Varargs invoke(int code, U target, Varargs varargs) { + final int optcode = code - super.getAllFunctionNames().size(); + switch (optcode){ + case 0: + return hasVibrator(target, varargs); + case 1: + return vibrate(target, varargs); + case 2: + return cancel(target, varargs); + } + return super.invoke(code, target, varargs); + } + + //--------------------------------------- API -------------------------------------------------- + + /** + * 是否存在震动组件 + * @param vibrator + * @param varargs + * @return + */ + @LuaViewApi(revisions = {"iOS无此方法"}) + public LuaValue hasVibrator(U vibrator, Varargs varargs){ + return valueOf(vibrator.hasVibrator()); + } + + /** + * 开始震动 + * + * @param vibrator + * @param varargs + * @return + */ + public LuaValue vibrate(U vibrator, Varargs varargs) { + if (varargs.narg() > 2 || (varargs.narg() > 1 && varargs.istable(2))) { + final LuaTable luaTable = LuaUtil.getTable(varargs, 2); + final Integer repeat = LuaUtil.toJavaInt(varargs.arg(3)); + return vibrator.vibrate(luaTable, repeat); + } else { + final Double time = LuaUtil.getDouble(varargs, 2); + return vibrator.vibrate((long) (time != null ? time * DateUtil.ONE_SECOND : DateUtil.ONE_SECOND)); + } + } + + /** + * 取消震动 + * + * @param vibrator + * @param varargs + * @return + */ + public LuaValue cancel(U vibrator, Varargs varargs) { + return vibrator.cancel(); + } + +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/list/UIBaseListOrRecyclerViewMethodMapper.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/list/UIBaseListOrRecyclerViewMethodMapper.java new file mode 100644 index 00000000..859ddbf6 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/list/UIBaseListOrRecyclerViewMethodMapper.java @@ -0,0 +1,271 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.mapper.list; + +import com.taobao.luaview.fun.mapper.LuaViewLib; +import com.taobao.luaview.fun.mapper.ui.UIViewGroupMethodMapper; +import com.taobao.luaview.userdata.list.UDBaseListOrRecyclerView; +import com.taobao.luaview.userdata.ui.UDViewGroup; +import com.taobao.luaview.util.DimenUtil; +import com.taobao.luaview.util.LuaUtil; + +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; + +import java.util.List; + +/** + * Recycler View or List View + * + * @author song + * @date 15/11/30 + */ +@LuaViewLib(revisions = {"20170306已对标"}) +public abstract class UIBaseListOrRecyclerViewMethodMapper extends UIViewGroupMethodMapper { + private static final String TAG = "UIBaseListOrRecyclerViewMethodMapper"; + private static final String[] sMethods = new String[]{ + "reload",//0 + "contentSize",//1 + "contentOffset",//2 + "contentInset",//3 + "showScrollIndicator",//4 + "scrollToTop",//5 + "scrollToCell",//6 + "miniSpacing",//7 + "lazyLoad"//8 + }; + + @Override + public List getAllFunctionNames() { + return mergeFunctionNames(TAG, super.getAllFunctionNames(), sMethods); + } + + @Override + public Varargs invoke(int code, U target, Varargs varargs) { + final int optcode = code - super.getAllFunctionNames().size(); + switch (optcode){ + case 0: + return reload(target, varargs); + case 1: + return contentSize(target, varargs); + case 2: + return contentOffset(target, varargs); + case 3: + return contentInset(target, varargs); + case 4: + return showScrollIndicator(target, varargs); + case 5: + return scrollToTop(target, varargs); + case 6: + return scrollToCell(target, varargs); + case 7: + return miniSpacing(target, varargs); + case 8: + return lazyLoad(target, varargs); + } + return super.invoke(code, target, varargs); + } + + //--------------------------------------- API -------------------------------------------------- + + public abstract UDBaseListOrRecyclerView getUDBaseListOrRecyclerView(Varargs varargs); + + /** + * 重新刷新加载TableView + * + * @param view + * @param varargs + * @return + */ + public LuaValue reload(U view, Varargs varargs) { + final Integer section = LuaUtil.toJavaInt(LuaUtil.getInt(varargs, 2));//get section + final Integer row = LuaUtil.toJavaInt(LuaUtil.getInt(varargs, 3));//get row + return getUDBaseListOrRecyclerView(varargs).reload(section, row); + } + + + /** + * () 获取ContentSize大小 + * + * @param view + * @param varargs + * @return + */ + @Deprecated + public LuaValue contentSize(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setContentSize(view, varargs); + } else { + return getContentSize(view, varargs); + } + } + + public LuaValue setContentSize(U view, Varargs varargs) { + //TODO + //DimenUtil.dpiToPx(varargs.arg(2)); + return view; + } + + public LuaValue getContentSize(U view, Varargs varargs) { + //TODO + //DimenUtil.pxToDpi(px); + return view; + } + + /** + * 获取contentOffset大小 + * + * @param view + * @param varargs + * @return + */ + @Deprecated + public LuaValue contentOffset(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setContentOffset(view, varargs); + } else { + return getContentOffset(view, varargs); + } + } + + public LuaValue setContentOffset(U view, Varargs varargs) { + //TODO + //DimenUtil.dpiToPx(varargs.arg(2)); + return view; + } + + public LuaValue getContentOffset(U view, Varargs varargs) { + //TODO + //DimenUtil.pxToDpi(px); + return view; + } + + /** + * () 获取contentInset + * + * @param view + * @param varargs + * @return + */ + @Deprecated + public LuaValue contentInset(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setContentInset(view, varargs); + } else { + return getContentInset(view, varargs); + } + } + + public LuaValue setContentInset(U view, Varargs varargs) { + //TODO + //DimenUtil.dpiToPx(varargs.arg(2)); + return view; + } + + public LuaValue getContentInset(U view, Varargs varargs) { + //TODO + //DimenUtil.pxToDpi(px); + return view; + } + + + /** + * () 获取是否显示滚动条信息 + * + * @param view + * @param varargs + * @return + */ + public LuaValue showScrollIndicator(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setShowScrollIndicator(view, varargs); + } else { + return isShowScrollIndicator(view, varargs); + } + } + + public LuaValue setShowScrollIndicator(U view, Varargs varargs) { + final boolean isShow = varargs.optboolean(2, true); + return view.setVerticalScrollBarEnabled(isShow); + } + + public LuaValue isShowScrollIndicator(U view, Varargs varargs) { + return valueOf(view.isVerticalScrollBarEnabled()); + } + + + /** + * (x, y, w, h, animate) 滚动到指定位置 + * + * @param view + * @param varargs + * @return + */ + public LuaValue scrollToTop(U view, Varargs varargs) { + final int offset = varargs.isnumber(2) ? DimenUtil.dpiToPx(varargs.arg(2)) : 0; + final boolean animate = varargs.isnumber(2) ? varargs.optboolean(3, true) : varargs.optboolean(2, true); + return getUDBaseListOrRecyclerView(varargs).scrollToTop(offset, animate); + } + + /** + * (x, y, w, h, animate) 滚动到指定位置 + * + * @param view + * @param varargs + * @return + */ + public LuaValue scrollToCell(U view, Varargs varargs) { + final int section = LuaUtil.toJavaInt(varargs.arg(2));//lua从1开始 + final int rowInSection = LuaUtil.toJavaInt(varargs.arg(3));//lua从1开始 + final int offset = DimenUtil.dpiToPx(varargs.arg(4)); + final boolean animate = varargs.optboolean(5, true); + return getUDBaseListOrRecyclerView(varargs).scrollToItem(section, rowInSection, offset, animate); + } + + + /** + * 分隔线高度 + * + * @param view + * @param varargs + * @return + */ + public LuaValue miniSpacing(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setMiniSpacing(view, varargs); + } else { + return getMiniSpacing(view, varargs); + } + } + + public LuaValue setMiniSpacing(U view, Varargs varargs) { + final UDBaseListOrRecyclerView udBaseListOrRecyclerView = getUDBaseListOrRecyclerView(varargs); + final int spacing = DimenUtil.dpiToPx(varargs.arg(2)); + return udBaseListOrRecyclerView.setMiniSpacing(spacing); + } + + public LuaValue getMiniSpacing(U view, Varargs varargs) { + final UDBaseListOrRecyclerView udBaseListOrRecyclerView = getUDBaseListOrRecyclerView(varargs); + return valueOf(DimenUtil.pxToDpi(udBaseListOrRecyclerView.getMiniSpacing())); + } + + /** + * 是否使用列表ImageView延迟加载,默认为true,如果列表简单的话,可以关闭 + * + * @param view + * @param varargs + * @return + */ + @Deprecated + public LuaValue lazyLoad(U view, Varargs varargs) { + final UDBaseListOrRecyclerView udBaseListOrRecyclerView = getUDBaseListOrRecyclerView(varargs); + Boolean lazyLoad = LuaUtil.getBoolean(varargs, 2); + return udBaseListOrRecyclerView.setLazyLoad(lazyLoad != null ? lazyLoad : true); + } +} \ No newline at end of file diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/list/UIBaseListViewMethodMapper.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/list/UIBaseListViewMethodMapper.java new file mode 100644 index 00000000..dc6ca534 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/list/UIBaseListViewMethodMapper.java @@ -0,0 +1,127 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.mapper.list; + +import com.taobao.luaview.fun.mapper.LuaViewLib; +import com.taobao.luaview.userdata.list.UDBaseListOrRecyclerView; +import com.taobao.luaview.userdata.list.UDBaseListView; +import com.taobao.luaview.userdata.ui.UDViewGroup; + +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; + +import java.util.List; + +/** + * ListView的方法映射 + * @author song + */ +@LuaViewLib +@Deprecated +public abstract class UIBaseListViewMethodMapper extends UIBaseListOrRecyclerViewMethodMapper { + private static final String TAG = "UIBaseListViewMethodMapper"; + private static final String[] sMethods = new String[]{ + "header",//0 + "footer",//1 + "dividerHeight"//2 + }; + + @Override + public List getAllFunctionNames() { + return mergeFunctionNames(TAG, super.getAllFunctionNames(), sMethods); + } + + @Override + public Varargs invoke(int code, U target, Varargs varargs) { + final int optcode = code - super.getAllFunctionNames().size(); + switch (optcode){ + case 0: + return header(target, varargs); + case 1: + return footer(target, varargs); + case 2: + return dividerHeight(target, varargs); + } + return super.invoke(code, target, varargs); + } + + //--------------------------------------- API -------------------------------------------------- + + public abstract UDBaseListView getUDBaseListView(Varargs varargs); + + + @Override + public UDBaseListOrRecyclerView getUDBaseListOrRecyclerView(Varargs varargs) { + return getUDBaseListView(varargs); + } + + /** + * 设置TableView的头 + * + * @param view + * @param varargs + * @return + */ + public LuaValue header(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setHeader(view, varargs); + } else { + return getHeader(view, varargs); + } + } + + public LuaValue setHeader(U view, Varargs varargs) { + final LuaValue header = varargs.arg(2); + return getUDBaseListView(varargs).setHeader(header); + } + + public LuaValue getHeader(U view, Varargs varargs) { + return getUDBaseListView(varargs).getHeader(); + } + + /** + * 设置TableView的尾 + * + * @param view + * @param varargs + * @return + */ + public LuaValue footer(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setFooter(view, varargs); + } else { + return getFooter(view, varargs); + } + } + + public LuaValue setFooter(U view, Varargs varargs) { + final LuaValue footer = varargs.arg(2); + return getUDBaseListView(varargs).setFooter(footer); + } + + public LuaValue getFooter(U view, Varargs varargs) { + return getUDBaseListView(varargs).getFooter(); + } + + + /** + * 分隔线高度 + * + * @param view + * @param varargs + * @return + */ + public LuaValue dividerHeight(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setMiniSpacing(view, varargs); + } else { + return getMiniSpacing(view, varargs); + } + } +} \ No newline at end of file diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/list/UIBaseRecyclerViewMethodMapper.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/list/UIBaseRecyclerViewMethodMapper.java new file mode 100644 index 00000000..3b900b6d --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/list/UIBaseRecyclerViewMethodMapper.java @@ -0,0 +1,49 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.mapper.list; + +import com.taobao.luaview.fun.mapper.LuaViewLib; +import com.taobao.luaview.userdata.list.UDBaseListOrRecyclerView; +import com.taobao.luaview.userdata.list.UDBaseRecyclerView; + +import org.luaj.vm2.Varargs; + +import java.util.List; + +/** + * RecyclerView的方法映射 + * @author song + */ +@LuaViewLib +public abstract class UIBaseRecyclerViewMethodMapper extends UIBaseListOrRecyclerViewMethodMapper { + private static final String TAG = "UIBaseRecyclerViewMethodMapper"; + + @Override + public List getAllFunctionNames() { + return mergeFunctionNames(TAG, super.getAllFunctionNames(), new String[]{}); + } + + @Override + public Varargs invoke(int code, U target, Varargs varargs) { + final int optcode = code - super.getAllFunctionNames().size(); + switch (optcode){ + //TODO + } + return super.invoke(code, target, varargs); + } + + //--------------------------------------- API -------------------------------------------------- + + public abstract UDBaseRecyclerView getUDBaseRecyclerView(Varargs varargs); + + @Override + public UDBaseListOrRecyclerView getUDBaseListOrRecyclerView(Varargs varargs) { + return getUD(varargs); + } +} \ No newline at end of file diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/list/UIListViewMethodMapper.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/list/UIListViewMethodMapper.java new file mode 100644 index 00000000..89487ea8 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/list/UIListViewMethodMapper.java @@ -0,0 +1,51 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.mapper.list; + +import com.taobao.luaview.fun.mapper.LuaViewLib; +import com.taobao.luaview.userdata.list.UDBaseListView; +import com.taobao.luaview.userdata.list.UDListView; + +import org.luaj.vm2.Varargs; + +import java.util.List; + +/** + * ListView的方法映射 + * + * @author song + */ +@LuaViewLib +@Deprecated +public class UIListViewMethodMapper extends UIBaseListViewMethodMapper { + private static final String TAG = "UIListViewMethodMapper"; + + @Override + public List getAllFunctionNames() { + return mergeFunctionNames(TAG, super.getAllFunctionNames(), new String[]{ + }); + } + + @Override + public Varargs invoke(int code, U target, Varargs varargs) { + final int optcode = code - super.getAllFunctionNames().size(); + switch (optcode) { + //TODO + } + return super.invoke(code, target, varargs); + } + + //--------------------------------------- API -------------------------------------------------- + + + @Override + public UDBaseListView getUDBaseListView(Varargs varargs) { + return getUD(varargs); + } +} \ No newline at end of file diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/list/UIRecyclerViewMethodMapper.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/list/UIRecyclerViewMethodMapper.java new file mode 100644 index 00000000..99def44f --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/list/UIRecyclerViewMethodMapper.java @@ -0,0 +1,81 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.mapper.list; + +import android.support.v7.widget.LinearLayoutManager; +import android.view.View; + +import com.taobao.luaview.fun.mapper.LuaViewLib; +import com.taobao.luaview.userdata.list.UDBaseListOrRecyclerView; +import com.taobao.luaview.userdata.list.UDBaseRecyclerView; +import com.taobao.luaview.userdata.list.UDRecyclerView; +import com.taobao.luaview.util.DimenUtil; + +import org.luaj.vm2.Varargs; + +import java.util.List; + +/** + * RecyclerView的方法映射 + * + * @author song + */ +@LuaViewLib +public class UIRecyclerViewMethodMapper extends UIBaseRecyclerViewMethodMapper { + + private static final String TAG = "UIRecyclerViewMethodMapper"; + + @Override + public List getAllFunctionNames() { + return mergeFunctionNames(TAG, super.getAllFunctionNames(), new String[]{}); + } + + @Override + public Varargs invoke(int code, U target, Varargs varargs) { + final int optcode = code - super.getAllFunctionNames().size(); + switch (optcode) { + //TODO + } + return super.invoke(code, target, varargs); + } + + //--------------------------------------- API -------------------------------------------------- + + + @Override + public UDBaseRecyclerView getUDBaseRecyclerView(Varargs varargs) { + return getUD(varargs); + } + + @Override + public UDBaseListOrRecyclerView getUDBaseListOrRecyclerView(Varargs varargs) { + return getUD(varargs); + } + + @Override + public Varargs initParams(U view, Varargs varargs) { + Varargs ret = super.initParams(view, varargs); + this.reload(view, varargs); + return ret; + } + + @Override + public Varargs offset(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setScrollXY(view, varargs); + } else { + LinearLayoutManager layoutManager = (LinearLayoutManager) view.getLVRecyclerView().getLayoutManager(); + int position = layoutManager.findFirstVisibleItemPosition(); + View firstVisiableChildView = layoutManager.findViewByPosition(position); + int itemHeight = firstVisiableChildView.getHeight(); + int dy = (position) * itemHeight - firstVisiableChildView.getTop(); + return varargsOf(valueOf(0), valueOf(DimenUtil.pxToDpi(dy))); + } + } +} \ No newline at end of file diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/list/UIRefreshListViewMethodMapper.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/list/UIRefreshListViewMethodMapper.java new file mode 100644 index 00000000..177e043b --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/list/UIRefreshListViewMethodMapper.java @@ -0,0 +1,142 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.mapper.list; + +import com.taobao.luaview.fun.mapper.LuaViewLib; +import com.taobao.luaview.userdata.list.UDBaseListView; +import com.taobao.luaview.userdata.list.UDRefreshListView; +import com.taobao.luaview.util.LuaUtil; + +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; + +import java.util.List; + +/** + * Refreshable ListView的方法映射 + * + * @author song + */ +@LuaViewLib +@Deprecated +public class UIRefreshListViewMethodMapper extends UIBaseListViewMethodMapper { + + private static final String TAG = "UIRefreshListViewMethodMapper"; + private static final String[] sMethods = new String[]{ + "refreshEnable",//0 + "initRefreshing",//1 + "isRefreshing",//2 + "startRefreshing",//3 + "stopRefreshing"//4 + }; + + @Override + public List getAllFunctionNames() { + return mergeFunctionNames(TAG, super.getAllFunctionNames(), sMethods); + } + + @Override + public Varargs invoke(int code, U target, Varargs varargs) { + final int optcode = code - super.getAllFunctionNames().size(); + switch (optcode) { + case 0: + return refreshEnable(target, varargs); + case 1: + return initRefreshing(target, varargs); + case 2: + return isRefreshing(target, varargs); + case 3: + return startRefreshing(target, varargs); + case 4: + return stopRefreshing(target, varargs); + } + return super.invoke(code, target, varargs); + } + + //--------------------------------------- API -------------------------------------------------- + + + @Override + public UDBaseListView getUDBaseListView(Varargs varargs) { + return getUD(varargs); + } + + /** + * 设置是否可以刷新 + * + * @param view + * @param varargs + * @return + */ + public LuaValue refreshEnable(U view, Varargs varargs) { + final boolean enable = LuaUtil.getBoolean(varargs, 2); + return view.setRefreshEnable(enable); + } + + /** + * 初始化下拉刷新 for iOS,Android不需要 + * + * @param view + * @param varargs + * @return + */ + public LuaValue initRefreshing(U view, Varargs varargs) { + return view; + } + + public LuaValue initPullDownRefreshing(U view, Varargs varargs) { + return view; + } + + /** + * 是否刷新 + * + * @param view + * @param varargs + * @return + */ + public LuaValue isRefreshing(U view, Varargs varargs) { + return valueOf(view.isRefreshing()); + } + + public LuaValue isPullDownRefreshing(U view, Varargs varargs) { + return valueOf(view.isRefreshing()); + } + + /** + * 停止刷新 + * + * @param view + * @param varargs + * @return + */ + public LuaValue startRefreshing(U view, Varargs varargs) { + return view.startPullDownRefreshing(); + } + + public LuaValue startPullDownRefreshing(U view, Varargs varargs) { + return view.startPullDownRefreshing(); + } + + /** + * 停止刷新 + * + * @param view + * @param varargs + * @return + */ + public LuaValue stopRefreshing(U view, Varargs varargs) { + return view.stopPullDownRefreshing(); + } + + public LuaValue stopPullDownRefreshing(U view, Varargs varargs) { + return view.stopPullDownRefreshing(); + } + +} \ No newline at end of file diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/list/UIRefreshRecyclerViewMethodMapper.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/list/UIRefreshRecyclerViewMethodMapper.java new file mode 100644 index 00000000..44869904 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/list/UIRefreshRecyclerViewMethodMapper.java @@ -0,0 +1,149 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.mapper.list; + +import com.taobao.luaview.fun.mapper.LuaViewLib; +import com.taobao.luaview.userdata.list.UDBaseRecyclerView; +import com.taobao.luaview.userdata.list.UDRefreshRecyclerView; +import com.taobao.luaview.util.LuaUtil; + +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; + +import java.util.List; + +/** + * Refreshable RecyclerView的方法映射 + * @author song + */ +@LuaViewLib(revisions = {"20170306已对标"}) +public class UIRefreshRecyclerViewMethodMapper extends UIBaseRecyclerViewMethodMapper { + + private static final String TAG = "UIRefreshRecyclerViewMethodMapper"; + private static final String[] sMethods = new String[]{ + "refreshEnable",//0 + "initRefreshing",//1 + "isRefreshing",//2 + "startRefreshing",//3 + "stopRefreshing"//4 + }; + + @Override + public List getAllFunctionNames() { + return mergeFunctionNames(TAG, super.getAllFunctionNames(), sMethods); + } + + @Override + public Varargs invoke(int code, U target, Varargs varargs) { + final int optcode = code - super.getAllFunctionNames().size(); + switch (optcode) { + case 0: + return refreshEnable(target, varargs); + case 1: + return initRefreshing(target, varargs); + case 2: + return isRefreshing(target, varargs); + case 3: + return startRefreshing(target, varargs); + case 4: + return stopRefreshing(target, varargs); + } + return super.invoke(code, target, varargs); + } + + //--------------------------------------- API -------------------------------------------------- + + + @Override + public UDBaseRecyclerView getUDBaseRecyclerView(Varargs varargs) { + return getUD(varargs); + } + + + + /** + * 设置是否可以刷新 + * @param view + * @param varargs + * @return + */ + public LuaValue refreshEnable(U view, Varargs varargs){ + final boolean enable = LuaUtil.getBoolean(varargs, 2); + return view.setRefreshEnable(enable); + } + + /** + * 初始化下拉刷新 for iOS,Android不需要 + * + * @param view + * @param varargs + * @return + */ + @Deprecated + public LuaValue initRefreshing(U view, Varargs varargs) { + return view; + } + + public LuaValue initPullDownRefreshing(U view, Varargs varargs) { + return view; + } + + /** + * 是否刷新 + * + * @param view + * @param varargs + * @return + */ + public LuaValue isRefreshing(U view, Varargs varargs) { + return valueOf(view.isRefreshing()); + } + + public LuaValue isPullDownRefreshing(U view, Varargs varargs) { + return valueOf(view.isRefreshing()); + } + + /** + * 停止刷新 + * + * @param view + * @param varargs + * @return + */ + public LuaValue startRefreshing(U view, Varargs varargs) { + return view.startPullDownRefreshing(); + } + + public LuaValue startPullDownRefreshing(U view, Varargs varargs) { + return view.startPullDownRefreshing(); + } + + /** + * 停止刷新 + * + * @param view + * @param varargs + * @return + */ + public LuaValue stopRefreshing(U view, Varargs varargs) { + return view.stopPullDownRefreshing(); + } + + public LuaValue stopPullDownRefreshing(U view, Varargs varargs) { + return view.stopPullDownRefreshing(); + } + + @Override + public Varargs initParams(U view, Varargs varargs) { + Varargs ret = super.initParams(view, varargs); + this.reload(view, varargs); + return ret; + } + +} \ No newline at end of file diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/net/HttpMethodMapper.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/net/HttpMethodMapper.java new file mode 100644 index 00000000..c11969ae --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/net/HttpMethodMapper.java @@ -0,0 +1,275 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.mapper.net; + +import com.taobao.luaview.fun.base.BaseMethodMapper; +import com.taobao.luaview.fun.mapper.LuaViewLib; +import com.taobao.luaview.userdata.net.UDHttp; +import com.taobao.luaview.util.LuaUtil; + +import org.luaj.vm2.LuaFunction; +import org.luaj.vm2.LuaTable; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; + +import java.util.List; + +/** + * http 接口封装 + * + * @author song + * @date 15/8/21 + */ +@LuaViewLib(revisions = {"20170306已对标", "iOS不支持对象调用,只支持创建方式调用,待统一"}) +public class HttpMethodMapper extends BaseMethodMapper { + + private static final String TAG = "HttpMethodMapper"; + private static final String[] sMethods = new String[]{ + "url",//0 + "method",//1 + "retryTimes",//2 + "timeout",//3 + "params",//4 + "callback",//5 + "request",//6 + "cancel",//7 + "get",//8 + "post"//9 + }; + + @Override + public List getAllFunctionNames() { + return mergeFunctionNames(TAG, super.getAllFunctionNames(), sMethods); + } + + @Override + public Varargs invoke(int code, U target, Varargs varargs) { + final int optcode = code - super.getAllFunctionNames().size(); + switch (optcode) { + case 0: + return url(target, varargs); + case 1: + return method(target, varargs); + case 2: + return retryTimes(target, varargs); + case 3: + return timeout(target, varargs); + case 4: + return params(target, varargs); + case 5: + return callback(target, varargs); + case 6: + return request(target, varargs); + case 7: + return cancel(target, varargs); + case 8: + return get(target, varargs); + case 9: + return post(target, varargs); + } + return super.invoke(code, target, varargs); + } + + //--------------------------------------- API -------------------------------------------------- + + + /** + * 设置请求url + * + * @param http + * @param varargs + * @return + */ + public LuaValue url(U http, Varargs varargs) { + if (varargs.narg() > 1) { + return setUrl(http, varargs); + } else { + return getUrl(http, varargs); + } + } + + public LuaValue setUrl(U http, Varargs varargs) { + final String url = varargs.optjstring(2, null); + return http.setUrl(url); + } + + public LuaValue getUrl(U http, Varargs varargs) { + return valueOf(http.getUrl()); + } + + /** + * 请求方法 + * + * @param http + * @param varargs + * @return + */ + public LuaValue method(U http, Varargs varargs) { + if (varargs.narg() > 1) { + return setMethod(http, varargs); + } else { + return getMethod(http, varargs); + } + } + + public LuaValue setMethod(U http, Varargs varargs) { + final String method = varargs.optjstring(2, UDHttp.METHOD_POST); + return http.setMethod(method); + } + + public LuaValue getMethod(U http, Varargs varargs) { + return valueOf(http.getMethod()); + } + + /** + * 重试次数 + * + * @param http + * @param varargs + * @return + */ + public LuaValue retryTimes(U http, Varargs varargs) { + if (varargs.narg() > 1) { + return setRetryTimes(http, varargs); + } else { + return getRetryTimes(http, varargs); + } + } + + public LuaValue setRetryTimes(U http, Varargs varargs) { + final int retryTimes = varargs.optint(2, UDHttp.DEFAULT_RETRY_TIMES); + return http.setRetryTimes(retryTimes); + } + + public LuaValue getRetryTimes(U http, Varargs varargs) { + return valueOf(http.getRetryTimes()); + } + + /** + * 延时 + * + * @param http + * @param varargs + * @return + */ + public LuaValue timeout(U http, Varargs varargs) { + if (varargs.narg() > 1) { + return setTimeout(http, varargs); + } else { + return getTimeout(http, varargs); + } + } + + public LuaValue setTimeout(U http, Varargs varargs) { + final int timeout = varargs.optint(2, UDHttp.DEFAULT_TIMEOUT); + return http.setTimeout(timeout); + } + + public LuaValue getTimeout(U http, Varargs varargs) { + return valueOf(http.getTimeout()); + } + + /** + * 参数 + * + * @param http + * @param varargs + * @return + */ + public LuaValue params(U http, Varargs varargs) { + if (varargs.narg() > 1) { + return setParams(http, varargs); + } else { + return getParams(http, varargs); + } + } + + public LuaValue setParams(U http, Varargs varargs) { + final LuaTable params = http.opttable(2, null); + return http.setParams(params); + } + + public LuaValue getParams(U http, Varargs varargs) { + return http.getParams(); + } + + /** + * 回调 + * + * @param http + * @param varargs + * @return + */ + public LuaValue callback(U http, Varargs varargs) { + if (varargs.narg() > 1) { + return setCallback(http, varargs); + } else { + return getCallback(http, varargs); + } + } + + public LuaValue setCallback(U http, Varargs varargs) { + final LuaFunction callback = varargs.optfunction(2, null); + return http.setCallback(callback); + } + + public LuaValue getCallback(U http, Varargs varargs) { + return http.getCallback(); + } + + /** + * 请求 + * + * @param http + * @param varargs + * @return + */ + public LuaValue request(U http, Varargs varargs) { + return http.request(); + } + + /** + * 取消 + * + * @param http + * @param varargs + * @return + */ + public LuaValue cancel(U http, Varargs varargs) { + return http.cancel(); + } + + /** + * get请求 + * + * @param http + * @param varargs + * @return + */ + public LuaValue get(U http, Varargs varargs) { + final String url = LuaUtil.getString(varargs, 2); + final LuaTable params = LuaUtil.getTable(varargs, 3, 2); + final LuaFunction callback = LuaUtil.getFunction(varargs, 4, 3, 2); + return http.get(url, params, callback); + } + + /** + * pos 请求 + * + * @param http + * @param varargs + * @return + */ + public LuaValue post(U http, Varargs varargs) { + final String url = LuaUtil.getString(varargs, 2); + final LuaTable params = LuaUtil.getTable(varargs, 3, 2); + final LuaFunction callback = LuaUtil.getFunction(varargs, 4, 3, 2); + return http.post(url, params, callback); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/ui/NewIndexFunction.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/ui/NewIndexFunction.java new file mode 100644 index 00000000..b948609d --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/ui/NewIndexFunction.java @@ -0,0 +1,42 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.mapper.ui; + +import com.taobao.luaview.fun.base.BaseMethodMapper; +import com.taobao.luaview.util.LogUtil; + +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; + +/** + * 属性赋值操作 + * @author song + */ +public class NewIndexFunction extends BaseMethodMapper { + + private LuaValue metatable; + + public NewIndexFunction(LuaValue metatable) { + this.metatable = metatable; + } + + @Override + public Varargs invoke(Varargs args) { + LuaValue key = args.arg(2); + Varargs newargs = varargsOf(args.arg(1), args.arg(3)); + LuaValue func = metatable.get(key); + if (func.isfunction()) {//函数调用 + func.invoke(newargs); + } else { + LogUtil.d("[LuaView error]", "property not fount :", key.toString()); + } + return NONE; + } + +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/ui/SpannableStringMethodMapper.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/ui/SpannableStringMethodMapper.java new file mode 100644 index 00000000..6c0ff932 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/ui/SpannableStringMethodMapper.java @@ -0,0 +1,63 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.mapper.ui; + +import com.taobao.luaview.fun.base.BaseMethodMapper; +import com.taobao.luaview.fun.mapper.LuaViewLib; +import com.taobao.luaview.userdata.ui.UDSpannableString; + +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; + +import java.util.List; + +/** + * SpannableString 接口封装 + * + * @author song + * @date 15/8/21 + */ +@LuaViewLib(revisions = {"20170306已对标", "待沟通,支持lineSpace、charSpace"}) +public class SpannableStringMethodMapper extends BaseMethodMapper { + + private static final String TAG = "SpannableStringMethodMapper"; + private static final String[] sMethods = new String[]{ + "append"//0 + }; + + @Override + public List getAllFunctionNames() { + return mergeFunctionNames(TAG, super.getAllFunctionNames(), sMethods); + } + + @Override + public Varargs invoke(int code, U target, Varargs varargs) { + final int optcode = code - super.getAllFunctionNames().size(); + switch (optcode) { + case 0: + return append(target, varargs); + } + return super.invoke(code, target, varargs); + } + + //--------------------------------------- API -------------------------------------------------- + + /** + * 新增一段内容 + * + * @param ssb + * @param varargs + * @return + */ + public LuaValue append(U ssb, Varargs varargs) { + LuaValue ssb2 = varargs.optvalue(2, null); + return ssb.append(ssb2); + } + +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/ui/UIAlertMethodMapper.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/ui/UIAlertMethodMapper.java new file mode 100644 index 00000000..b2658114 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/ui/UIAlertMethodMapper.java @@ -0,0 +1,44 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.mapper.ui; + +import com.taobao.luaview.fun.base.BaseMethodMapper; +import com.taobao.luaview.fun.mapper.LuaViewLib; +import com.taobao.luaview.userdata.ui.UDAlert; + +import org.luaj.vm2.Varargs; + +import java.util.List; + +/** + * alert 接口封装 + * + * @author song + * @date 15/8/21 + */ +@LuaViewLib(revisions = {"20170306已对标", "跟iOS不统一待统一"}) +public class UIAlertMethodMapper extends BaseMethodMapper { + private static final String TAG = "UIAlertMethodMapper"; + + @Override + public List getAllFunctionNames() { + return mergeFunctionNames(TAG, super.getAllFunctionNames(), new String[]{}); + } + + @Override + public Varargs invoke(int code, U target, Varargs varargs) { + final int optcode = code - super.getAllFunctionNames().size(); + switch (optcode) { + //TODO + } + return super.invoke(code, target, varargs); + } + + //--------------------------------------- API -------------------------------------------------- +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/ui/UIAnimationMethodMapper.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/ui/UIAnimationMethodMapper.java new file mode 100644 index 00000000..a5167005 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/ui/UIAnimationMethodMapper.java @@ -0,0 +1,145 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.mapper.ui; + +import com.taobao.luaview.fun.base.BaseMethodMapper; +import com.taobao.luaview.fun.mapper.LuaViewLib; +import com.taobao.luaview.userdata.ui.UDAnimation; +import com.taobao.luaview.util.ParamUtil; + +import org.luaj.vm2.LuaFunction; +import org.luaj.vm2.LuaTable; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; + +import java.util.List; + +/** + * Animation 接口封装 + * + * @author song + * @date 15/8/21 + */ +@Deprecated +@LuaViewLib +public class UIAnimationMethodMapper extends BaseMethodMapper { + + private static final String TAG = "UIAnimationMethodMapper"; + private static final String[] sMethods = new String[]{ + "alpha",//0 + "rotate",//1 + "scale",//2 + "translate",//3 + "duration",//4 + "startDelay",//5 + "repeatCount",//6 + "to",//7 + "callback",//8 + "onStartCallback",//9 + "onEndCallback",//10 + "onRepeatCallback"//11 + }; + + @Override + public List getAllFunctionNames() { + return mergeFunctionNames(TAG, super.getAllFunctionNames(), sMethods); + } + + + @Override + public Varargs invoke(int code, U target, Varargs varargs) { + final int optcode = code - super.getAllFunctionNames().size(); + switch (optcode) { + case 0: + return alpha(target, varargs); + case 1: + return rotate(target, varargs); + case 2: + return scale(target, varargs); + case 3: + return translate(target, varargs); + case 4: + return duration(target, varargs); + case 5: + return startDelay(target, varargs); + case 6: + return repeatCount(target, varargs); + case 7: + return to(target, varargs); + case 8: + return callback(target, varargs); + case 9: + return onStartCallback(target, varargs); + case 10: + return onEndCallback(target, varargs); + case 11: + return onRepeatCallback(target, varargs); + } + return super.invoke(code, target, varargs); + } + + //--------------------------------------- API -------------------------------------------------- + + + public LuaValue alpha(U udAnimation, Varargs varargs) { + return udAnimation.alpha(ParamUtil.getFloatValues(varargs, 2)); + } + + public LuaValue rotate(U udAnimation, Varargs varargs) { + return udAnimation.rotate(ParamUtil.getFloatValues(varargs, 2)); + } + + public LuaValue scale(U udAnimation, Varargs varargs) { + return udAnimation.scale(ParamUtil.getFloatValues(varargs, 2)); + } + + public LuaValue translate(U udAnimation, Varargs varargs) { + return udAnimation.translate(ParamUtil.getFloatValues(varargs, 2)); + } + + public LuaValue duration(U udAnimation, Varargs varargs) { + final long duration = (long) (varargs.optdouble(2, 0.3f) * 1000); + return udAnimation.setDuration(duration); + } + + public LuaValue startDelay(U udAnimation, Varargs varargs) { + final long delay = (long) (varargs.optdouble(2, 0) * 1000); + return udAnimation.setStartDelay(delay); + } + + public LuaValue repeatCount(U udAnimation, Varargs varargs) { + final int repeatCount = varargs.optint(2, 0); + return udAnimation.setRepeatCount(repeatCount); + } + + public LuaValue to(U udAnimation, Varargs varargs) { + return udAnimation.setValue(ParamUtil.getFloatValues(varargs, 2)); + } + + public LuaValue callback(U udAnimation, Varargs varargs) { + final LuaTable callback = varargs.opttable(2, null); + return udAnimation.setCallback(callback); + } + + + public LuaValue onStartCallback(U udAnimation, Varargs varargs) { + final LuaFunction callback = varargs.optfunction(2, null); + return udAnimation.setOnStartCallback(callback); + } + + public LuaValue onEndCallback(U udAnimation, Varargs varargs) { + final LuaFunction callback = varargs.optfunction(2, null); + return udAnimation.setOnEndCallback(callback); + } + + public LuaValue onRepeatCallback(U udAnimation, Varargs varargs) { + final LuaFunction callback = varargs.optfunction(2, null); + return udAnimation.setOnRepeatCallback(callback); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/ui/UIAnimatorMethodMapper.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/ui/UIAnimatorMethodMapper.java new file mode 100644 index 00000000..e006245e --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/ui/UIAnimatorMethodMapper.java @@ -0,0 +1,313 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.mapper.ui; + +import android.animation.ValueAnimator; + +import com.taobao.luaview.fun.base.BaseMethodMapper; +import com.taobao.luaview.fun.mapper.LuaViewApi; +import com.taobao.luaview.fun.mapper.LuaViewLib; +import com.taobao.luaview.global.VmVersion; +import com.taobao.luaview.userdata.constants.UDInterpolator; +import com.taobao.luaview.userdata.ui.UDAnimator; +import com.taobao.luaview.userdata.ui.UDView; +import com.taobao.luaview.util.DimenUtil; +import com.taobao.luaview.util.LuaUtil; +import com.taobao.luaview.util.ParamUtil; + +import org.luaj.vm2.LuaTable; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; + +import java.util.List; + +/** + * animator 接口封装 + * + * @author song + * @date 15/8/21 + */ +@LuaViewLib(revisions = {"20170306已对标"}) + public class UIAnimatorMethodMapper extends BaseMethodMapper { + + private static final String TAG = "UIAnimatorMethodMapper"; + private static final String[] sMethods = new String[]{ + "with",//0 + "start",//1 + "alpha",//2 + "rotation",//3 + "scale",//4 + "scaleX",//5 + "scaleY",//6 + "translation",//7 + "translationX",//8 + "translationY",//9 + "duration",//10 + "delay",//11 + "repeatCount",//12 + "interpolator",//13 + "cancel",//14 + "pause",//15 + "isPaused",//16 + "isRunning",//17 + "resume",//18 + "reverses",//19 + "values",//20 + "callback",//21 + "onStart",//22 + "onEnd",//23 + "onRepeat",//24 + "onCancel",//25 + "onPause",//26 + "onUpdate",//27 + "onResume"//28 + }; + + @Override + public List getAllFunctionNames() { + return mergeFunctionNames(TAG, super.getAllFunctionNames(), sMethods); + } + + @Override + public Varargs invoke(int code, U target, Varargs varargs) { + final int optcode = code - super.getAllFunctionNames().size(); + switch (optcode) { + case 0: + return with(target, varargs); + case 1: + return start(target, varargs); + case 2: + return alpha(target, varargs); + case 3: + return rotation(target, varargs); + case 4: + return scale(target, varargs); + case 5: + return scaleX(target, varargs); + case 6: + return scaleY(target, varargs); + case 7: + return translation(target, varargs); + case 8: + return translationX(target, varargs); + case 9: + return translationY(target, varargs); + case 10: + return duration(target, varargs); + case 11: + return delay(target, varargs); + case 12: + return repeatCount(target, varargs); + case 13: + return interpolator(target, varargs); + case 14: + return cancel(target, varargs); + case 15: + return pause(target, varargs); + case 16: + return isPaused(target, varargs); + case 17: + return isRunning(target, varargs); + case 18: + return resume(target, varargs); + case 19: + return reverses(target, varargs); + case 20: + return values(target, varargs); + case 21: + return callback(target, varargs); + case 22: + return onStart(target, varargs); + case 23: + return onEnd(target, varargs); + case 24: + return onRepeat(target, varargs); + case 25: + return onCancel(target, varargs); + case 26: + return onPause(target, varargs); + case 27: + return onUpdate(target, varargs); + case 28: + return onResume(target, varargs); + } + return super.invoke(code, target, varargs); + } + + //--------------------------------------- API -------------------------------------------------- + + + public LuaValue with(U udAnimator, Varargs varargs) { + final UDView udView = (varargs.narg() > 1 && varargs.arg(2) instanceof UDView) ? (UDView) varargs.arg(2) : null; + return udAnimator.with(udView); + } + + public LuaValue start(U udAnimator, Varargs varargs) { + return udAnimator.start(); + } + + //------------------------------------------各种属性---------------------------------------------- + + public LuaValue alpha(U udAnimator, Varargs varargs) { + return udAnimator.ofProperty("alpha", ParamUtil.getFloatValues(varargs, 2)); + } + + public LuaValue rotation(U udAnimator, Varargs varargs) { + return udAnimator.ofProperty("rotation", ParamUtil.getFloatValues(varargs, 2)); + } + + public LuaValue scale(U udAnimator, Varargs varargs) { + udAnimator.ofProperty("scaleX", LuaUtil.getFloat(varargs, 2)); + return udAnimator.ofProperty("scaleY", LuaUtil.getFloat(varargs, 3, 2)); + } + + public LuaValue scaleX(U udAnimator, Varargs varargs) { + return udAnimator.ofProperty("scaleX", ParamUtil.getFloatValues(varargs, 2)); + } + + public LuaValue scaleY(U udAnimator, Varargs varargs) { + return udAnimator.ofProperty("scaleY", ParamUtil.getFloatValues(varargs, 2)); + } + + public LuaValue translation(U udAnimator, Varargs varargs) { + final Float translationX = LuaUtil.getFloat(varargs, 2); + final Float translationY = LuaUtil.getFloat(varargs, 3); + if (translationY != null) { + udAnimator.ofProperty("translationX", DimenUtil.dpiToPxF(translationX)); + return udAnimator.ofProperty("translationY", DimenUtil.dpiToPxF(translationY)); + } else { + return udAnimator.ofProperty("translationX", DimenUtil.dpiToPxF(translationX)); + } + } + + public LuaValue translationX(U udAnimator, Varargs varargs) { + return udAnimator.ofProperty("translationX", DimenUtil.dpiToPxF(ParamUtil.getFloatValues(varargs, 2))); + } + + public LuaValue translationY(U udAnimator, Varargs varargs) { + return udAnimator.ofProperty("translationY", DimenUtil.dpiToPxF(ParamUtil.getFloatValues(varargs, 2))); + } + + public LuaValue duration(U udAnimator, Varargs varargs) { + final long duration = (long) (varargs.optdouble(2, 0.3f) * 1000); + return udAnimator.setDuration(duration); + } + + public LuaValue delay(U udAnimator, Varargs varargs) { + final long delay = (long) (varargs.optdouble(2, 0) * 1000); + return udAnimator.setStartDelay(delay); + } + + public LuaValue repeatCount(U udAnimator, Varargs varargs) { + final int repeatCount = varargs.optint(2, 0); + return udAnimator.setRepeatCount(repeatCount); + } + + /** + * 插值器,可以控制不同值 + * + * @param udAnimator + * @param varargs + * @return + */ + @LuaViewApi(since = VmVersion.V_500) + public LuaValue interpolator(U udAnimator, Varargs varargs) { + final Integer type = LuaUtil.getInt(varargs, 2); + final Float cycles = LuaUtil.getFloat(varargs, 3, 2); + return udAnimator.setInterpolator(UDInterpolator.parse(type, cycles)); + } + + @LuaViewApi(since = VmVersion.V_500) + public LuaValue cancel(U udAnimator, Varargs varargs) { + return udAnimator.cancel(); + } + + @LuaViewApi(since = VmVersion.V_500) + public LuaValue pause(U udAnimator, Varargs varargs) { + return udAnimator.pause(); + } + + @LuaViewApi(since = VmVersion.V_500) + public LuaValue isPaused(U udAnimator, Varargs varargs) { + return valueOf(udAnimator.isPaused()); + } + + @LuaViewApi(since = VmVersion.V_500) + public LuaValue isRunning(U udAnimator, Varargs varargs) { + return valueOf(udAnimator.isRunning()); + } + + @LuaViewApi(since = VmVersion.V_500) + public LuaValue resume(U udAnimator, Varargs varargs) { + return udAnimator.resume(); + } + + /** + * 设置动画repeat mode 类型是否reverse + * + * @param udAnimation + * @param varargs + * @return + */ + public LuaValue reverses(U udAnimation, Varargs varargs) { + final boolean reverse = varargs.optboolean(2, true); + return udAnimation.setRepeatMode(reverse ? ValueAnimator.REVERSE : ValueAnimator.RESTART); + } + + @LuaViewApi(revisions = {"跟IOS名称不一样,iOS只支持一个值"}) + public LuaValue values(U udAnimator, Varargs varargs) { + return udAnimator.setFloatValues(ParamUtil.getFloatValues(varargs, 2)); + } + + //--------------------------------------------回调---------------------------------------------- + + public LuaValue callback(U udAnimator, Varargs varargs) { + final LuaTable callback = varargs.opttable(2, null); + return udAnimator.setCallback(callback); + } + + + public LuaValue onStart(U udAnimator, Varargs varargs) { + final LuaValue callback = varargs.optvalue(2, NIL); + return udAnimator.setOnStartCallback(callback); + } + + public LuaValue onEnd(U udAnimator, Varargs varargs) { + final LuaValue callback = varargs.optvalue(2, NIL); + return udAnimator.setOnEndCallback(callback); + } + + public LuaValue onRepeat(U udAnimator, Varargs varargs) { + final LuaValue callback = varargs.optvalue(2, NIL); + return udAnimator.setOnRepeatCallback(callback); + } + + public LuaValue onCancel(U udAnimator, Varargs varargs) { + final LuaValue callback = varargs.optvalue(2, NIL); + return udAnimator.setOnCancelCallback(callback); + } + + public LuaValue onPause(U udAnimator, Varargs varargs) { + final LuaValue callback = varargs.optvalue(2, NIL); + return udAnimator.setOnPauseCallback(callback); + } + + @LuaViewApi(revisions = {"iOS无"}) + @Deprecated + public LuaValue onUpdate(U udAnimator, Varargs varargs) { + final LuaValue callback = varargs.optvalue(2, NIL); + return udAnimator.setOnUpdateCallback(callback); + } + + public LuaValue onResume(U udAnimator, Varargs varargs) { + final LuaValue callback = varargs.optvalue(2, NIL); + return udAnimator.setOnResumeCallback(callback); + } + +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/ui/UIAnimatorSetMethodMapper.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/ui/UIAnimatorSetMethodMapper.java new file mode 100644 index 00000000..506590da --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/ui/UIAnimatorSetMethodMapper.java @@ -0,0 +1,334 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.mapper.ui; + +import android.animation.ValueAnimator; + +import com.taobao.luaview.fun.base.BaseMethodMapper; +import com.taobao.luaview.fun.mapper.LuaViewApi; +import com.taobao.luaview.fun.mapper.LuaViewLib; +import com.taobao.luaview.global.VmVersion; +import com.taobao.luaview.userdata.constants.UDInterpolator; +import com.taobao.luaview.userdata.ui.UDAnimatorSet; +import com.taobao.luaview.userdata.ui.UDView; +import com.taobao.luaview.util.DimenUtil; +import com.taobao.luaview.util.LuaUtil; +import com.taobao.luaview.util.ParamUtil; + +import org.luaj.vm2.LuaTable; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; + +import java.util.List; + +/** + * animator 接口封装 + * + * @author song + * @date 15/8/21 + */ +@Deprecated +@LuaViewLib +public class UIAnimatorSetMethodMapper extends BaseMethodMapper { + + private static final String TAG = "UIAnimatorSetMethodMapper"; + private static final String[] sMethods = new String[]{ + "with",//0 + "start",//1 + "alpha",//2 + "rotation",//3 + "scale",//4 + "scaleX",//5 + "scaleY",//6 + "translation",//7 + "translationX",//8 + "translationY",//9 + "duration",//10 + "delay",//11 + "repeatCount",//12 + "interpolator",//13 + "cancel",//14 + "pause",//15 + "resume",//16 + "reverses",//17 + "values",//18 + "callback",//19 + "onStart",//20 + "onEnd",//21 + "onRepeat",//22 + "onCancel",//23 + "onPause",//24 + "onUpdate",//25 + "onResume",//26 + "isRunning", //27 + "isPaused",//28 + "isStarted"//29 + }; + + @Override + public List getAllFunctionNames() { + return mergeFunctionNames(TAG, super.getAllFunctionNames(), sMethods); + } + + @Override + public Varargs invoke(int code, U target, Varargs varargs) { + final int optcode = code - super.getAllFunctionNames().size(); + switch (optcode) { + case 0: + return with(target, varargs); + case 1: + return start(target, varargs); + case 2: + return alpha(target, varargs); + case 3: + return rotation(target, varargs); + case 4: + return scale(target, varargs); + case 5: + return scaleX(target, varargs); + case 6: + return scaleY(target, varargs); + case 7: + return translation(target, varargs); + case 8: + return translationX(target, varargs); + case 9: + return translationY(target, varargs); + case 10: + return duration(target, varargs); + case 11: + return delay(target, varargs); + case 12: + return repeatCount(target, varargs); + case 13: + return interpolator(target, varargs); + case 14: + return cancel(target, varargs); + case 15: + return pause(target, varargs); + case 16: + return resume(target, varargs); + case 17: + return reverses(target, varargs); + case 18: + return values(target, varargs); + case 19: + return callback(target, varargs); + case 20: + return onStart(target, varargs); + case 21: + return onEnd(target, varargs); + case 22: + return onRepeat(target, varargs); + case 23: + return onCancel(target, varargs); + case 24: + return onPause(target, varargs); + case 25: + return onUpdate(target, varargs); + case 26: + return onResume(target, varargs); + case 27: + return isRunning(target, varargs); + case 28: + return isPaused(target, varargs); + case 29: + return isStarted(target, varargs); + } + return super.invoke(code, target, varargs); + } + + //--------------------------------------- API -------------------------------------------------- + + + public LuaValue with(U udAnimator, Varargs varargs) { + final UDView udView = (varargs.narg() > 1 && varargs.arg(2) instanceof UDView) ? (UDView) varargs.arg(2) : null; + return udAnimator.with(udView); + } + + public LuaValue start(U udAnimator, Varargs varargs) { + return udAnimator.start(); + } + + //------------------------------------------各种属性---------------------------------------------- + + public LuaValue alpha(U udAnimator, Varargs varargs) { + return udAnimator.ofProperty("alpha", ParamUtil.getFloatValues(varargs, 2)); + } + + public LuaValue rotation(U udAnimator, Varargs varargs) { + return udAnimator.ofProperty("rotation", ParamUtil.getFloatValues(varargs, 2)); + } + + @LuaViewApi(revisions = VmVersion.V_500) + public LuaValue scale(U udAnimator, Varargs varargs) { + udAnimator.ofProperty("scaleX", LuaUtil.getFloat(varargs, 2)); + return udAnimator.ofProperty("scaleY", LuaUtil.getFloat(varargs, 3, 2)); + } + + public LuaValue scaleX(U udAnimator, Varargs varargs) { + return udAnimator.ofProperty("scaleX", ParamUtil.getFloatValues(varargs, 2)); + } + + public LuaValue scaleY(U udAnimator, Varargs varargs) { + return udAnimator.ofProperty("scaleY", ParamUtil.getFloatValues(varargs, 2)); + } + + @LuaViewApi(revisions = VmVersion.V_500) + public LuaValue translation(U udAnimator, Varargs varargs) { + udAnimator.ofProperty("translationX", DimenUtil.dpiToPxF(LuaUtil.getFloat(varargs, 2))); + return udAnimator.ofProperty("translationY", DimenUtil.dpiToPxF(LuaUtil.getFloat(varargs, 3))); + } + + public LuaValue translationX(U udAnimator, Varargs varargs) { + return udAnimator.ofProperty("translationX", DimenUtil.dpiToPxF(ParamUtil.getFloatValues(varargs, 2))); + } + + public LuaValue translationY(U udAnimator, Varargs varargs) { + return udAnimator.ofProperty("translationY", DimenUtil.dpiToPxF(ParamUtil.getFloatValues(varargs, 2))); + } + + public LuaValue duration(U udAnimator, Varargs varargs) { + final long duration = (long) (varargs.optdouble(2, 0.3f) * 1000); + return udAnimator.setDuration(duration); + } + + public LuaValue delay(U udAnimator, Varargs varargs) { + final long delay = (long) (varargs.optdouble(2, 0) * 1000); + return udAnimator.setStartDelay(delay); + } + + public LuaValue repeatCount(U udAnimator, Varargs varargs) { + final int repeatCount = varargs.optint(2, 0); + return udAnimator.setRepeatCount(repeatCount); + } + + /** + * 插值器,可以控制不同值 + * + * @param udAnimator + * @param varargs + * @return + */ + @LuaViewApi(since = VmVersion.V_500) + public LuaValue interpolator(U udAnimator, Varargs varargs) { + final Integer type = LuaUtil.getInt(varargs, 2); + final Float cycles = LuaUtil.getFloat(varargs, 3, 2); + return udAnimator.setInterpolator(UDInterpolator.parse(type, cycles)); + } + + @LuaViewApi(since = VmVersion.V_500) + public LuaValue cancel(U udAnimator, Varargs varargs) { + return udAnimator.cancel(); + } + + @LuaViewApi(since = VmVersion.V_500) + public LuaValue pause(U udAnimator, Varargs varargs) { + return udAnimator.pause(); + } + + @LuaViewApi(since = VmVersion.V_500) + public LuaValue resume(U udAnimator, Varargs varargs) { + return udAnimator.resume(); + } + + /** + * 设置动画repeat mode 类型是否reverse + * + * @param udAnimation + * @param varargs + * @return + */ + public LuaValue reverses(U udAnimation, Varargs varargs) { + final boolean reverse = varargs.optboolean(2, true); + return udAnimation.setRepeatMode(reverse ? ValueAnimator.REVERSE : ValueAnimator.RESTART); + } + + public LuaValue values(U udAnimator, Varargs varargs) { + return udAnimator.setFloatValues(ParamUtil.getFloatValues(varargs, 2)); + } + + /** + * is Running + * + * @param udAnimation + * @param varargs + * @return + */ + @LuaViewApi(since = VmVersion.V_540) + public LuaValue isRunning(U udAnimation, Varargs varargs) { + return valueOf(udAnimation.isRunning()); + } + + /** + * is paused + * + * @param udAnimation + * @param varargs + * @return + */ + @LuaViewApi(since = VmVersion.V_540) + public LuaValue isPaused(U udAnimation, Varargs varargs) { + return valueOf(udAnimation.isPaused()); + } + + /** + * is started + * + * @param udAnimation + * @param varargs + * @return + */ + @LuaViewApi(since = VmVersion.V_540) + public LuaValue isStarted(U udAnimation, Varargs varargs) { + return valueOf(udAnimation.isStarted()); + } + //--------------------------------------------回调---------------------------------------------- + + public LuaValue callback(U udAnimator, Varargs varargs) { + final LuaTable callback = varargs.opttable(2, null); + return udAnimator.setCallback(callback); + } + + public LuaValue onStart(U udAnimator, Varargs varargs) { + final LuaValue callback = varargs.optvalue(2, NIL); + return udAnimator.setOnStartCallback(callback); + } + + public LuaValue onEnd(U udAnimator, Varargs varargs) { + final LuaValue callback = varargs.optvalue(2, NIL); + return udAnimator.setOnEndCallback(callback); + } + + public LuaValue onRepeat(U udAnimator, Varargs varargs) { + final LuaValue callback = varargs.optvalue(2, NIL); + return udAnimator.setOnRepeatCallback(callback); + } + + public LuaValue onCancel(U udAnimator, Varargs varargs) { + final LuaValue callback = varargs.optvalue(2, NIL); + return udAnimator.setOnCancelCallback(callback); + } + + public LuaValue onPause(U udAnimator, Varargs varargs) { + final LuaValue callback = varargs.optvalue(2, NIL); + return udAnimator.setOnPauseCallback(callback); + } + + public LuaValue onUpdate(U udAnimator, Varargs varargs) { + final LuaValue callback = varargs.optvalue(2, NIL); + return udAnimator.setOnUpdateCallback(callback); + } + + public LuaValue onResume(U udAnimator, Varargs varargs) { + final LuaValue callback = varargs.optvalue(2, NIL); + return udAnimator.setOnResumeCallback(callback); + } + +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/ui/UIButtonMethodMapper.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/ui/UIButtonMethodMapper.java new file mode 100644 index 00000000..6a448092 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/ui/UIButtonMethodMapper.java @@ -0,0 +1,149 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.mapper.ui; + +import com.taobao.luaview.fun.mapper.LuaViewLib; +import com.taobao.luaview.userdata.ui.UDButton; + +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; + +import java.util.List; + + +/** + * Button 接口封装 + * @author song + * @param + */ +@LuaViewLib(revisions = {"20170306已对标", "跟iOS不一致,iOS继承自View"}) +public class UIButtonMethodMapper extends UITextViewMethodMapper { + private static final String TAG = "UIButtonMethodMapper"; + private static final String[] sMethods = new String[]{ + "title",//0 + "titleColor",//1 + "image",//2 + "showsTouchWhenHighlighted"//3 + }; + + @Override + public List getAllFunctionNames() { + return mergeFunctionNames(TAG, super.getAllFunctionNames(), sMethods); + } + + @Override + public Varargs invoke(int code, U target, Varargs varargs) { + final int optcode = code - super.getAllFunctionNames().size(); + switch (optcode) { + case 0: + return title(target, varargs); + case 1: + return titleColor(target, varargs); + case 2: + return image(target, varargs); + case 3: + return showsTouchWhenHighlighted(target, varargs); + } + return super.invoke(code, target, varargs); + } + + //--------------------------------------- API -------------------------------------------------- + + + /** + * setText + * + * @param view UIButton + * @param varargs Varargs + * @return LuaValue + */ + @Deprecated + public LuaValue title(U view, Varargs varargs) { + return text(view, varargs); + } + + public LuaValue setTitle(U view, Varargs varargs) { + return setText(view, varargs); + } + + public LuaValue getTitle(U view, Varargs varargs) { + return getText(view, varargs); + } + + /** + * 文字颜色 + * + * @param view + * @param varargs + * @return + */ + @Deprecated + public LuaValue titleColor(U view, Varargs varargs) { + return textColor(view, varargs); + } + + public LuaValue setTitleColor(U view, Varargs varargs) { + return setTextColor(view, varargs); + } + + public LuaValue getTitleColor(U view, Varargs varargs) { + return getTextColor(view, varargs); + } + + /** + * 设置图片 + * + * @param view + * @param varargs + * @return + */ + public Varargs image(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setImage(view, varargs); + } else { + return getImage(view, varargs); + } + } + + public LuaValue setImage(U view, Varargs varargs) {//TODO 支持参数为Data类型 + final String normalImage = varargs.optjstring(2, null); + final String pressedImage = varargs.optjstring(3, null); + return view.setImage(normalImage, pressedImage); + } + + public Varargs getImage(U view, Varargs varargs) { + return view.getImage(); + } + + /** + * 获取按钮点击是否高亮 + * + * @param view + * @param varargs + * @return + */ + @Deprecated + public LuaValue showsTouchWhenHighlighted(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setShowsTouchWhenHighlighted(view, varargs); + } else { + return isShowsTouchWhenHighlighted(view, varargs); + } + } + + public LuaValue setShowsTouchWhenHighlighted(U view, Varargs varargs) { + //TODO + return view.setHighlightColor(0); + } + + public LuaValue isShowsTouchWhenHighlighted(U view, Varargs varargs) { + //TODO + return valueOf(view.getHighlightColor() == 0); + } +} \ No newline at end of file diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/ui/UICustomPanelMethodMapper.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/ui/UICustomPanelMethodMapper.java new file mode 100644 index 00000000..e509b8fb --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/ui/UICustomPanelMethodMapper.java @@ -0,0 +1,74 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.mapper.ui; + + +import com.taobao.luaview.fun.mapper.LuaViewApi; +import com.taobao.luaview.fun.mapper.LuaViewLib; +import com.taobao.luaview.global.VmVersion; +import com.taobao.luaview.userdata.ui.UDCustomPanel; + +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; + +import java.util.List; + +/** + * 自定义面板 + * + * @param + * @author song + */ +@LuaViewLib(revisions = {"20170306已对标", "增加调用Lua方法"}) +public class UICustomPanelMethodMapper extends UIViewGroupMethodMapper { + + private static final String TAG = "UICustomPanelMethodMapper"; + private static final String[] sMethods = new String[]{ + "nativeView",//0 + "getNativeView"//1 + }; + + @Override + public List getAllFunctionNames() { + return mergeFunctionNames(TAG, super.getAllFunctionNames(), sMethods); + } + + @Override + public Varargs invoke(int code, U target, Varargs varargs) { + final int optcode = code - super.getAllFunctionNames().size(); + switch (optcode) { + case 0: + return nativeView(target, varargs); + case 1: + return getNativeView(target, varargs); + } + return super.invoke(code, target, varargs); + } + + //--------------------------------------- API -------------------------------------------------- + + /** + * 获取native view + * + * @param customPanel + * @param varargs + * @return + */ + @Deprecated + @LuaViewApi(since = VmVersion.V_500, revisions = {"移动到 UIViewMethodMapper(V510)"}) + public LuaValue nativeView(U customPanel, Varargs varargs) { + return getNativeView(customPanel, varargs); + } + + @Deprecated + @LuaViewApi(since = VmVersion.V_500, revisions = {"移动到 UIViewMethodMapper(V510)"}) + public LuaValue getNativeView(U customPanel, Varargs varargs) { + return customPanel.getNativeView(); + } +} \ No newline at end of file diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/ui/UICustomViewMethodMapper.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/ui/UICustomViewMethodMapper.java new file mode 100644 index 00000000..7f35bfad --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/ui/UICustomViewMethodMapper.java @@ -0,0 +1,78 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.mapper.ui; + +import com.taobao.luaview.fun.mapper.LuaViewApi; +import com.taobao.luaview.fun.mapper.LuaViewLib; +import com.taobao.luaview.global.VmVersion; +import com.taobao.luaview.userdata.ui.UDCustomView; + +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; + +import java.util.List; + +/** + * CustomView 接口封装 + * 有onDraw方法处理 + * + * @param + * @author song + */ +@LuaViewLib(revisions = {"20170306已对标"}) +public class UICustomViewMethodMapper extends UIViewMethodMapper { + + private static final String TAG = "UICustomViewMethodMapper"; + private static final String[] sMethods = new String[]{ + "onDraw"//0 + }; + + @Override + public List getAllFunctionNames() { + return mergeFunctionNames(TAG, super.getAllFunctionNames(), sMethods); + } + + @Override + public Varargs invoke(int code, U target, Varargs varargs) { + final int optcode = code - super.getAllFunctionNames().size(); + switch (optcode) { + case 0: + return onDraw(target, varargs); + } + return super.invoke(code, target, varargs); + } + + //--------------------------------------- API -------------------------------------------------- + + /** + * onDraw + * + * @param view + * @param varargs + * @return + */ + @LuaViewApi(since = VmVersion.V_550) + public LuaValue onDraw(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setOnDraw(view, varargs); + } else { + return getOnDraw(view, varargs); + } + } + + public LuaValue setOnDraw(U view, Varargs varargs) { + final LuaValue callbacks = varargs.optvalue(2, NIL); + return view.setOnDrawCallback(callbacks); + } + + public LuaValue getOnDraw(U view, Varargs varargs) { + return view.getOnDrawCallback(); + } + +} \ No newline at end of file diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/ui/UIEditTextMethodMapper.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/ui/UIEditTextMethodMapper.java new file mode 100644 index 00000000..e7b2b119 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/ui/UIEditTextMethodMapper.java @@ -0,0 +1,121 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.mapper.ui; + +import com.taobao.luaview.fun.mapper.LuaViewLib; +import com.taobao.luaview.userdata.ui.UDEditText; +import com.taobao.luaview.util.LuaViewUtil; + +import org.luaj.vm2.LuaString; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; + +import java.util.List; + + +/** + * EditText 接口封装 + * @author song + * @param + */ +@LuaViewLib(revisions = {"20170306已对标"}) +public class UIEditTextMethodMapper extends UITextViewMethodMapper { + + private static final String TAG = "UIEditTextMethodMapper"; + private static final String[] sMethods = new String[]{ + "hint",//0 + "placeholder",//1 + "inputType"//2 + }; + + @Override + public List getAllFunctionNames() { + return mergeFunctionNames(TAG, super.getAllFunctionNames(), sMethods); + } + + @Override + public Varargs invoke(int code, U target, Varargs varargs) { + final int optcode = code - super.getAllFunctionNames().size(); + switch (optcode) { + case 0: + return hint(target, varargs); + case 1: + return placeholder(target, varargs); + case 2: + return inputType(target, varargs); + } + return super.invoke(code, target, varargs); + } + + //--------------------------------------- API -------------------------------------------------- + + /** + * 键盘类型 + */ + public LuaValue inputType(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setInputType(view, varargs); + } else { + return getInputType(view, varargs); + } + } + + public LuaValue setInputType(U view, Varargs varargs) { + final CharSequence type = LuaViewUtil.getText(varargs.optvalue(2, NIL)); + return view.setInputType(type); + } + + public LuaValue getInputType(U view, Varargs varargs) { + return valueOf(view.getInputType()); + } + + /** + * 获取placeHolder内容 + * + * @param view + * @param varargs + * @return + */ + public LuaValue hint(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setHint(view, varargs); + } else { + return getHint(view, varargs); + } + } + + public LuaValue setHint(U view, Varargs varargs) { + final CharSequence text = LuaViewUtil.getText(varargs.optvalue(2, NIL)); + return view.setHint(text); + } + + public LuaValue getHint(U view, Varargs varargs) { + return valueOf(view.getHint()); + } + + /** + * 获取placeHolder内容 + * + * @param view + * @param varargs + * @return + */ + @Deprecated + public LuaValue placeholder(U view, Varargs varargs) { + return hint(view, varargs); + } + + public LuaValue setPlaceholder(U view, Varargs varargs) { + return setHint(view, varargs); + } + + public LuaValue getPlaceholder(U view, Varargs varargs) { + return getHint(view, varargs); + } +} \ No newline at end of file diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/ui/UIHorizontalScrollViewMethodMapper.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/ui/UIHorizontalScrollViewMethodMapper.java new file mode 100644 index 00000000..5e5698ed --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/ui/UIHorizontalScrollViewMethodMapper.java @@ -0,0 +1,240 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.mapper.ui; + +import com.taobao.luaview.fun.mapper.LuaViewApi; +import com.taobao.luaview.fun.mapper.LuaViewLib; +import com.taobao.luaview.userdata.ui.UDHorizontalScrollView; +import com.taobao.luaview.util.DimenUtil; + +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; + +import java.util.List; + +/** + * HorizontalScrollView的方法映射 + */ +@LuaViewLib(revisions = {"20170306已对标"}) +public class UIHorizontalScrollViewMethodMapper extends UIViewGroupMethodMapper { + + private static final String TAG = "UIHorizontalScrollViewMethodMapper"; + private static final String[] sMethods = new String[]{ + "offset",//0 + "scrollTo",//1 + "offsetBy",//2 + "scrollBy",//3 + "smoothScrollTo",//4 + "smoothScrollBy",//5 + "pageScroll",//6 + "fullScroll",//7 + "contentSize"//8 + }; + + @Override + public List getAllFunctionNames() { + return mergeFunctionNames(TAG, super.getAllFunctionNames(), sMethods); + } + + @Override + public Varargs invoke(int code, U target, Varargs varargs) { + final int optcode = code - super.getAllFunctionNames().size(); + switch (optcode) { + case 0: + return offset(target, varargs); + case 1: + return scrollTo(target, varargs); + case 2: + return offsetBy(target, varargs); + case 3: + return scrollBy(target, varargs); + case 4: + return smoothScrollTo(target, varargs); + case 5: + return smoothScrollBy(target, varargs); + case 6: + return pageScroll(target, varargs); + case 7: + return fullScroll(target, varargs); + case 8: + return contentSize(target, varargs); + } + return super.invoke(code, target, varargs); + } + + //--------------------------------------- API -------------------------------------------------- + + + /** + * 滚动到某个位置 + * + * @param view + * @param varargs + * @return + */ + public Varargs offset(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setOffset(view, varargs); + } else { + return getOffset(view, varargs); + } + } + + public LuaValue setOffset(U view, Varargs varargs) { + final int x = DimenUtil.dpiToPx(varargs.arg(2)); + final int y = DimenUtil.dpiToPx(varargs.arg(3)); + final boolean smooth = varargs.optboolean(4, false); + if (smooth) { + return view.smoothScrollTo(x, y); + } else { + return view.scrollTo(x, y); + } + } + + public Varargs getOffset(U view, Varargs varargs) { + return getOffsetXY(view, varargs); + } + + + /** + * 滚动到某个位置 + * + * @param view + * @param varargs + * @return + */ + @Deprecated + public LuaValue scrollTo(U view, Varargs varargs) { + final int x = DimenUtil.dpiToPx(varargs.arg(2)); + final int y = DimenUtil.dpiToPx(varargs.arg(3)); + final boolean smooth = varargs.optboolean(4, false); + if (smooth) { + return view.smoothScrollTo(x, y); + } else { + return view.scrollTo(x, y); + } + } + + /** + * 滚动到某个位置 + * + * @param view + * @param varargs + * @return + */ + public Varargs offsetBy(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setOffsetBy(view, varargs); + } else { + return getOffsetBy(view, varargs); + } + } + + public LuaValue setOffsetBy(U view, Varargs varargs) { + final int x = DimenUtil.dpiToPx(varargs.arg(2)); + final int y = DimenUtil.dpiToPx(varargs.arg(3)); + final boolean smooth = varargs.optboolean(4, false); + if (smooth) { + return view.smoothScrollBy(x, y); + } else { + return view.scrollBy(x, y); + } + } + + public Varargs getOffsetBy(U view, Varargs varargs) { + return getOffsetXY(view, varargs); + } + + /** + * 滚动一段距离 + * + * @param view + * @param varargs + * @return + */ + @Deprecated + public LuaValue scrollBy(U view, Varargs varargs) { + final int dx = DimenUtil.dpiToPx(varargs.arg(2)); + ; + final int dy = DimenUtil.dpiToPx(varargs.arg(3)); + final boolean smooth = varargs.optboolean(4, false); + if (smooth) { + return view.smoothScrollBy(dx, dy); + } else { + return view.scrollBy(dx, dy); + } + } + + /** + * 滚动到某个位置 + * + * @param view + * @param varargs + * @return + */ + @Deprecated + public LuaValue smoothScrollTo(U view, Varargs varargs) { + final int x = DimenUtil.dpiToPx(varargs.arg(2)); + final int y = DimenUtil.dpiToPx(varargs.arg(3)); + return view.smoothScrollTo(x, y); + } + + /** + * 滚动一段距离 + * + * @param view + * @param varargs + * @return + */ + @Deprecated + public LuaValue smoothScrollBy(U view, Varargs varargs) { + final int dx = DimenUtil.dpiToPx(varargs.arg(2)); + final int dy = DimenUtil.dpiToPx(varargs.arg(3)); + return view.smoothScrollBy(dx, dy); + } + + /** + * scroll one page + * + * @param view + * @param varargs + * @return + */ + @Deprecated + public LuaValue pageScroll(U view, Varargs varargs) { + final int direction = varargs.optint(2, 0); + return view.pageScroll(direction); + } + + /** + * scroll whole page + * + * @param view + * @param varargs + * @return + */ + @Deprecated + public LuaValue fullScroll(U view, Varargs varargs) { + final int direction = varargs.optint(2, 0); + return view.fullScroll(direction); + } + + /** + * 空实现 + * + * @param view + * @param varargs + * @return + */ + @LuaViewApi(revisions = {"iOS特有,待沟通"}) + public LuaValue contentSize(U view, Varargs varargs) { + return view; + } + +} \ No newline at end of file diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/ui/UIImageViewMethodMapper.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/ui/UIImageViewMethodMapper.java new file mode 100644 index 00000000..c7dc66fc --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/ui/UIImageViewMethodMapper.java @@ -0,0 +1,207 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.mapper.ui; + +import android.widget.ImageView; + +import com.taobao.luaview.fun.mapper.LuaViewLib; +import com.taobao.luaview.userdata.constants.UDImageScaleType; +import com.taobao.luaview.userdata.kit.UDBitmap; +import com.taobao.luaview.userdata.kit.UDData; +import com.taobao.luaview.userdata.ui.UDImageView; + +import org.luaj.vm2.LuaFunction; +import org.luaj.vm2.LuaTable; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; + +import java.util.List; + +/** + * Image 接口封装 + * + * @param + * @author song + */ +@LuaViewLib(revisions = {"20170306已对标"}) +public class UIImageViewMethodMapper extends UIViewMethodMapper { + + private static final String TAG = "UIImageViewMethodMapper"; + private static final String[] sMethods = new String[]{ + "image",//0 + "contentMode",//1 + "scaleType",//2 + "startAnimationImages",//3 + "stopAnimationImages",//4 + "isAnimationImages"//5 + }; + + @Override + public List getAllFunctionNames() { + return mergeFunctionNames(TAG, super.getAllFunctionNames(), sMethods); + } + + @Override + public Varargs invoke(int code, U target, Varargs varargs) { + final int optcode = code - super.getAllFunctionNames().size(); + switch (optcode) { + case 0: + return image(target, varargs); + case 1: + return contentMode(target, varargs); + case 2: + return scaleType(target, varargs); + case 3: + return startAnimationImages(target, varargs); + case 4: + return stopAnimationImages(target, varargs); + case 5: + return isAnimationImages(target, varargs); + } + return super.invoke(code, target, varargs); + } + + //--------------------------------------- API -------------------------------------------------- + + + /** + * 设置图片url + * + * @param view UDImageView + * @param varargs Varargs + * @return LuaValue + */ + public LuaValue image(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setImage(view, varargs); + } else { + return getImage(view, varargs); + } + } + + public LuaValue setImage(U view, Varargs varargs) { + if (varargs.isstring(2)) { + final String url = varargs.optjstring(2, null); + final LuaFunction callback = varargs.optfunction(3, null); + return view.setImageUrl(url, callback); + } else if (varargs.arg(2) instanceof UDData) {//data + final UDData data = (UDData) varargs.arg(2); + return view.setImageBytes(data != null ? data.bytes() : null); + } else if (varargs.arg(2) instanceof UDBitmap){//bitmap + final UDBitmap bitmap = (UDBitmap) varargs.arg(2); + return view.setImageBitmap(bitmap); + } + return view; + } + + public LuaValue getImage(U view, Varargs varargs) { + String imageUrl = view.getImageUrl(); + return imageUrl != null ? valueOf(imageUrl) : LuaValue.NIL; + } + + + /** + * 设置图片的缩放模式 + * + * @param view + * @param varargs + * @return + */ + @Deprecated + public LuaValue contentMode(U view, Varargs varargs) { + return scaleType(view, varargs); + } + + public LuaValue setContentMode(U view, Varargs varargs) { + return setScaleType(view, varargs); + } + + public LuaValue getContentMode(U view, Varargs varargs) { + return getScaleType(view, varargs); + } + + + /** + * 设置图片的缩放模式 + * TODO 跟iOS统一常 + * + * @param view + * @param varargs + * @return + */ + public LuaValue scaleType(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setScaleType(view, varargs); + } else { + return getScaleType(view, varargs); + } + } + + public LuaValue setScaleType(U view, Varargs varargs) { + final String scaleTypeName = varargs.optjstring(2, ImageView.ScaleType.FIT_XY.name());//默认FIT_XY + final ImageView.ScaleType scaleType = UDImageScaleType.parse(scaleTypeName); + return view.setScaleType(scaleType); + } + + public LuaValue getScaleType(U view, Varargs varargs) { + return valueOf(view.getScaleType()); + } + + /** + * 开始帧动画 + * + * @param view + * @param varargs 时间是秒而不是毫秒 + * @return + */ + @Deprecated + public LuaValue startAnimationImages(U view, Varargs varargs) {//TODO 支持UDImageView和UDBitmap + final LuaTable imagesTable = varargs.opttable(2, null); + final double duration = varargs.optdouble(3, 1f); + boolean repeat = false; + if (varargs.isnumber(4)) { + repeat = varargs.optint(4, -1) > 0; + } else { + repeat = varargs.optboolean(4, false); + } + if (imagesTable != null && imagesTable.length() > 0) { + final String[] images = new String[imagesTable.length()]; + int i = 0; + for (LuaValue key : imagesTable.keys()) { + images[i++] = imagesTable.get(key).optjstring(null); + } + return view.startAnimationImages(images, (int) duration * 1000, repeat); + } + return view; + } + + /** + * 停止帧动画 + * + * @param view + * @param varargs + * @return + */ + @Deprecated + public LuaValue stopAnimationImages(U view, Varargs varargs) { + return view.stopAnimationImages(); + } + + /** + * 是否在动画中 + * + * @param view + * @param varargs + * @return + */ + @Deprecated + public LuaValue isAnimationImages(U view, Varargs varargs) { + return valueOf(view.isAnimationImages()); + } +} \ No newline at end of file diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/ui/UILoadingDialogMethodMapper.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/ui/UILoadingDialogMethodMapper.java new file mode 100644 index 00000000..950391e4 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/ui/UILoadingDialogMethodMapper.java @@ -0,0 +1,174 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.mapper.ui; + +import com.taobao.luaview.fun.base.BaseMethodMapper; +import com.taobao.luaview.fun.mapper.LuaViewLib; +import com.taobao.luaview.userdata.ui.UDLoadingDialog; +import com.taobao.luaview.util.ColorUtil; +import com.taobao.luaview.util.LuaUtil; + +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; + +import java.util.List; + +@LuaViewLib(revisions = {"20170306已对标"}) +public class UILoadingDialogMethodMapper extends BaseMethodMapper { + + private static final String TAG = "UILoadingDialogMethodMapper"; + private static final String[] sMethods = new String[]{ + "show",//0 + "isShow",//1 + "start",//2 + "isStart",//3 + "startAnimating",//4 + "isAnimating",//5 + "hide",//6 + "stop",//7 + "stopAnimating",//8 + "color"//9 + }; + + @Override + public List getAllFunctionNames() { + return mergeFunctionNames(TAG, super.getAllFunctionNames(), sMethods); + } + + @Override + public Varargs invoke(int code, U target, Varargs varargs) { + final int optcode = code - super.getAllFunctionNames().size(); + switch (optcode) { + case 0: + return show(target, varargs); + case 1: + return isShow(target, varargs); + case 2: + return start(target, varargs); + case 3: + return isStart(target, varargs); + case 4: + return startAnimating(target, varargs); + case 5: + return isAnimating(target, varargs); + case 6: + return hide(target, varargs); + case 7: + return stop(target, varargs); + case 8: + return stopAnimating(target, varargs); + case 9: + return color(target, varargs); + } + return super.invoke(code, target, varargs); + } + + //--------------------------------------- API -------------------------------------------------- + + + /** + * 菊花开始转动 + * + * @param view + * @param varargs + * @return + */ + @Deprecated + public LuaValue show(U view, Varargs varargs) { + return view.startAnimating(); + } + + @Deprecated + public LuaValue isShow(U view, Varargs varargs) { + return valueOf(view.isAnimating()); + } + + + /** + * 菊花开始转动 + * + * @param view + * @param varargs + * @return + */ + public LuaValue start(U view, Varargs varargs) { + return view.startAnimating(); + } + + @Deprecated + public LuaValue isStart(U view, Varargs varargs) { + return valueOf(view.isAnimating()); + } + + /** + * 菊花开始转动 + * + * @param view + * @param varargs + * @return + */ + @Deprecated + public LuaValue startAnimating(U view, Varargs varargs) { + return view.startAnimating(); + } + + public LuaValue isAnimating(U view, Varargs varargs) { + return valueOf(view.isAnimating()); + } + + + /** + * 菊花停止转动 + * + * @param view + * @param varargs + * @return + */ + @Deprecated + public LuaValue hide(U view, Varargs varargs) { + return view.stopAnimating(); + } + + public LuaValue stop(U view, Varargs varargs) { + return view.stopAnimating(); + } + + @Deprecated + public LuaValue stopAnimating(U view, Varargs varargs) { + return view.stopAnimating(); + } + + + /** + * 获取菊花颜色 + * + * @param view + * @param varargs + * @return + */ + public Varargs color(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setColor(view, varargs); + } else { + return getColor(view, varargs); + } + } + + public LuaValue setColor(U view, Varargs varargs) { + final Integer color = ColorUtil.parse(LuaUtil.getInt(varargs, 2)); + final Double alpha = LuaUtil.getDouble(varargs, 3); + return view.setColorAndAlpha(color, alpha); + } + + public Varargs getColor(U view, Varargs varargs) { + return varargsOf(valueOf(ColorUtil.getHexColor(view.getColor())), valueOf(view.getAlpha())); + } + + +} \ No newline at end of file diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/ui/UILoadingViewMethodMapper.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/ui/UILoadingViewMethodMapper.java new file mode 100644 index 00000000..f3395833 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/ui/UILoadingViewMethodMapper.java @@ -0,0 +1,146 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.mapper.ui; + +import com.taobao.luaview.fun.mapper.LuaViewApi; +import com.taobao.luaview.fun.mapper.LuaViewLib; +import com.taobao.luaview.userdata.ui.UDLoadingView; +import com.taobao.luaview.util.ColorUtil; +import com.taobao.luaview.util.LuaUtil; + +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; + +import java.util.List; + +/** + * Loading View 接口封装 + * + * @param + * @author song + */ +@LuaViewLib(revisions = {"20170306已对标"}) +public class UILoadingViewMethodMapper extends UIViewGroupMethodMapper { + + private static final String TAG = "UILoadingViewMethodMapper"; + private static final String[] sMethods = new String[]{ + "start",//0 + "isStart",//1 + "startAnimating",//2 + "isAnimating",//3 + "stop",//4 + "stopAnimating",//5 + "color"//6 + }; + + @Override + public List getAllFunctionNames() { + return mergeFunctionNames(TAG, super.getAllFunctionNames(), sMethods); + } + + @Override + public Varargs invoke(int code, U target, Varargs varargs) { + final int optcode = code - super.getAllFunctionNames().size(); + switch (optcode) { + case 0: + return start(target, varargs); + case 1: + return isStart(target, varargs); + case 2: + return startAnimating(target, varargs); + case 3: + return isAnimating(target, varargs); + case 4: + return stop(target, varargs); + case 5: + return stopAnimating(target, varargs); + case 6: + return color(target, varargs); + } + return super.invoke(code, target, varargs); + } + + //--------------------------------------- API -------------------------------------------------- + + + /** + * 菊花开始转动 + * + * @param view + * @param varargs + * @return + */ + public LuaValue start(U view, Varargs varargs) { + return view.show(); + } + + @Deprecated + public LuaValue isStart(U view, Varargs varargs) { + return valueOf(view.isShow()); + } + + /** + * 菊花开始转动 + * + * @param view + * @param varargs + * @return + */ + @Deprecated + public LuaValue startAnimating(U view, Varargs varargs) { + return view.show(); + } + + public LuaValue isAnimating(U view, Varargs varargs) { + return valueOf(view.isShow()); + } + + + /** + * 菊花停止转动 + * + * @param view + * @param varargs + * @return + */ + public LuaValue stop(U view, Varargs varargs) { + return view.hide(); + } + + @Deprecated + public LuaValue stopAnimating(U view, Varargs varargs) { + return view.hide(); + } + + /** + * 颜色 + * + * @param view + * @param varargs + * @return + */ + @LuaViewApi(revisions = {"支持alpha"}) + public LuaValue color(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setColor(view, varargs); + } else { + return getColor(view, varargs); + } + } + + public LuaValue setColor(U view, Varargs varargs) { + final Integer color = ColorUtil.parse(LuaUtil.getInt(varargs, 2)); + return view.setColor(color); + } + + public LuaValue getColor(U view, Varargs varargs) { + return valueOf(ColorUtil.getHexColor(view.getColor())); + } + +} \ No newline at end of file diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/ui/UIRefreshLayoutViewMethodMapper.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/ui/UIRefreshLayoutViewMethodMapper.java new file mode 100644 index 00000000..f197134e --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/ui/UIRefreshLayoutViewMethodMapper.java @@ -0,0 +1,64 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.mapper.ui; + +import com.taobao.luaview.fun.mapper.LuaViewApi; +import com.taobao.luaview.fun.mapper.LuaViewLib; +import com.taobao.luaview.userdata.ui.UDRefreshLayout; + +import org.luaj.vm2.Lua; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; + +import java.util.List; + +/** + * Created by tuoli on 12/20/16. + */ +@LuaViewLib(revisions = {"20170306已对标", "iOS无"}) +public class UIRefreshLayoutViewMethodMapper extends UIViewGroupMethodMapper { + + private static final String TAG = "UIRefreshLayoutViewMethodMapper"; + private static final String[] sMethods = new String[] { + "stopRefreshing", + "setRefreshingOffset" + }; + + @Override + public List getAllFunctionNames() { + return mergeFunctionNames(TAG, super.getAllFunctionNames(), sMethods); + } + + @Override + public Varargs invoke(int code, U target, Varargs varargs) { + final int optcode = code - super.getAllFunctionNames().size(); + switch (optcode) { + case 0: + return stopRefreshing(target, varargs); + case 1: + return setRefreshingOffset(target, varargs); + } + return super.invoke(code, target, varargs); + } + + //--------------------------------------- API -------------------------------------------------- + + public LuaValue stopRefreshing(U view, Varargs varargs) { + view.stopRefreshing(); + return this; + } + + @LuaViewApi(revisions = {"名称去掉set"}) + public LuaValue setRefreshingOffset(U view, Varargs varargs) { + final LuaValue offset = varargs.optvalue(2, NIL); + view.setRefreshingOffset(offset.tofloat()); + return this; + } + +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/ui/UITextViewMethodMapper.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/ui/UITextViewMethodMapper.java new file mode 100644 index 00000000..b56c7b1c --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/ui/UITextViewMethodMapper.java @@ -0,0 +1,432 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.mapper.ui; + +import android.text.TextUtils; + +import com.taobao.luaview.fun.mapper.LuaViewApi; +import com.taobao.luaview.fun.mapper.LuaViewLib; +import com.taobao.luaview.userdata.constants.UDEllipsize; +import com.taobao.luaview.userdata.ui.UDTextView; +import com.taobao.luaview.util.ColorUtil; +import com.taobao.luaview.util.DimenUtil; +import com.taobao.luaview.util.LuaUtil; +import com.taobao.luaview.util.LuaViewUtil; + +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; + +import java.util.List; + +@LuaViewLib(revisions = {"20170306已对标"}) +public class UITextViewMethodMapper extends UIViewMethodMapper { + + private static final String TAG = "UITextViewMethodMapper"; + private static final String[] sMethods = new String[]{ + "text",//0 + "textColor",//1 + "textSize",//2 + "fontSize",//3 + "fontName",//4 + "font",//5 + "gravity",//6 + "textAlign",//7 + "lines",//8 TODO iOS没有这个方法 + "maxLines",//9 + "lineCount",//10 + "minLines",//11 + "ellipsize",//12 + "adjustTextSize",//13 + "adjustFontSize"//14 + }; + + @Override + public List getAllFunctionNames() { + return mergeFunctionNames(TAG, super.getAllFunctionNames(), sMethods); + } + + @Override + public Varargs invoke(int code, U target, Varargs varargs) { + final int optcode = code - super.getAllFunctionNames().size(); + switch (optcode) { + case 0: + return text(target, varargs); + case 1: + return textColor(target, varargs); + case 2: + return textSize(target, varargs); + case 3: + return fontSize(target, varargs); + case 4: + return fontName(target, varargs); + case 5: + return font(target, varargs); + case 6: + return gravity(target, varargs); + case 7: + return textAlign(target, varargs); + case 8: + return lines(target, varargs); + case 9: + return maxLines(target, varargs); + case 10: + return lineCount(target, varargs); + case 11: + return minLines(target, varargs); + case 12: + return ellipsize(target, varargs); + case 13: + return adjustTextSize(target, varargs); + case 14: + return adjustFontSize(target, varargs); + } + return super.invoke(code, target, varargs); + } + + //--------------------------------------- API -------------------------------------------------- + + + /** + * 获得文本 + * + * @param view UDTextView + * @param varargs Varargs + * @return LuaValue + */ + public LuaValue text(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setText(view, varargs); + } else { + return getText(view, varargs); + } + } + + public LuaValue setText(U view, Varargs varargs) { + final CharSequence text = LuaViewUtil.getText(varargs.optvalue(2, NIL)); + return view.setText(text); + } + + public LuaValue getText(U view, Varargs varargs) { + return valueOf(String.valueOf(view.getText())); + } + + + /** + * 获取字体颜色 + * + * @param view UDTextView + * @param varargs Varargs + * @return LuaValue + */ + @LuaViewApi(revisions = {"iOS支持多个参数,可以支持alpha"}) + public LuaValue textColor(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setTextColor(view, varargs); + } else { + return getTextColor(view, varargs); + } + } + + public LuaValue setTextColor(U view, Varargs varargs) { + final Integer color = ColorUtil.parse(LuaUtil.getInt(varargs, 2)); + return view.setTextColor(color); + } + + public LuaValue getTextColor(U view, Varargs varargs) { + return valueOf(ColorUtil.getHexColor(view.getTextColor())); + } + + + /** + * 字体大小 + * + * @param view UDTextView + * @param varargs Varargs + * @return LuaValue + */ + @Deprecated + public LuaValue textSize(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setTextSize(view, varargs); + } else { + return getTextSize(view, varargs); + } + } + + public LuaValue setTextSize(U view, Varargs varargs) { + final float fontSize = (float) varargs.optdouble(2, 12.0);//TODO 这里需要转sp么? + return view.setTextSize(fontSize); + } + + public LuaValue getTextSize(U view, Varargs varargs) { + return valueOf(view.getTextSize()); + } + + /** + * 设置文字大小 + * + * @param view + * @param varargs + * @return + */ + public LuaValue fontSize(U view, Varargs varargs) { + return textSize(view, varargs); + } + + public LuaValue setFontSize(U view, Varargs varargs) { + return setTextSize(view, varargs); + } + + public LuaValue getFontSize(U view, Varargs varargs) { + return getTextSize(view, varargs); + } + + /** + * 设置字体 + * + * @param view + * @param varargs + * @return + */ + @Deprecated + public LuaValue fontName(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setFontName(view, varargs); + } else { + return getFontName(view, varargs); + } + } + + public LuaValue setFontName(U view, Varargs varargs) { + final String fontName = varargs.optjstring(2, null); + return view.setFont(fontName); + } + + public LuaValue getFontName(U view, Varargs varargs) { + return valueOf(view.getFont()); + } + + /** + * 获得文字和大小 + * + * @param view + * @param varargs + * @return + */ + @LuaViewApi(revisions = {"需要支持只传一个String"}) + public Varargs font(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setFont(view, varargs); + } else { + return getFont(view, varargs); + } + } + + public LuaValue setFont(U view, Varargs varargs) { + if (varargs.narg() > 2) {//两个参数 + final String fontName = varargs.optjstring(2, null); + final float fontSize = (float) varargs.optdouble(3, -1); + return view.setFont(fontName, fontSize); + } else {//一个参数 + final float fontSize = (float) varargs.optdouble(2, -1); + return view.setTextSize(fontSize); + } + } + + public Varargs getFont(U view, Varargs varargs) { + return varargsOf(valueOf(view.getFont()), valueOf(view.getTextSize())); + } + + /** + * 设置文字对齐方式 + * + * @param view + * @param varargs + * @return + */ + @LuaViewApi(revisions = "待废弃,集成到textAlign中") + public LuaValue gravity(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setGravity(view, varargs); + } else { + return getGravity(view, varargs); + } + } + + public LuaValue setGravity(U view, Varargs varargs) { + final int gravity = varargs.optint(2, 0); + return view.setGravity(gravity); + } + + public LuaValue getGravity(U view, Varargs varargs) { + return valueOf(view.getGravity()); + } + + /** + * 获得文字的对齐方式 + * TODO 需要跟iOS统一alignment的数值 + * + * @param view + * @param varargs + * @return + */ + public LuaValue textAlign(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setTextAlign(view, varargs); + } else { + return getTextAlign(view, varargs); + } + } + + public LuaValue setTextAlign(U view, Varargs varargs) { + final int alignment = varargs.optint(2, 0); + return view.setTextAlign(alignment); + } + + public LuaValue getTextAlign(U view, Varargs varargs) { + return valueOf(view.getTextAlign()); + } + + + /** + * 获得文字行数 + * + * @param view + * @param varargs + * @return + */ + public LuaValue lines(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setLines(view, varargs); + } else { + return getLines(view, varargs); + } + } + + public LuaValue setLines(U view, Varargs varargs) { + final int lines = varargs.optint(2, -1); + return view.setLines(lines); + } + + public LuaValue getLines(U view, Varargs varargs) { + return valueOf(view.getLines()); + } + + + /** + * 获得文字最大行数 + * + * @param view + * @param varargs + * @return + */ + @Deprecated + public LuaValue maxLines(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setMaxLines(view, varargs); + } else { + return getMaxLines(view, varargs); + } + } + + public LuaValue setMaxLines(U view, Varargs varargs) { + final int lines = varargs.optint(2, -1); + return view.setMaxLines(lines); + } + + public LuaValue getMaxLines(U view, Varargs varargs) { + return valueOf(view.getMaxLines()); + } + + /** + * 文字行数(最大) + * + * @param view + * @param varargs + * @return + */ + @Deprecated + public LuaValue lineCount(U view, Varargs varargs) { + return maxLines(view, varargs); + } + + public LuaValue setLineCount(U view, Varargs varargs) { + return setMaxLines(view, varargs); + } + + public LuaValue getLineCount(U view, Varargs varargs) { + return getMaxLines(view, varargs); + } + + + /** + * 获得文字最小行数 + * + * @param view + * @param varargs + * @return + */ + @Deprecated + public LuaValue minLines(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setMinLines(view, varargs); + } else { + return getMinLines(view, varargs); + } + } + + public LuaValue setMinLines(U view, Varargs varargs) { + final int lines = varargs.optint(2, -1); + return view.setMinLines(lines); + } + + public LuaValue getMinLines(U view, Varargs varargs) { + return valueOf(view.getMinLines()); + } + + + /** + * 文字显示不下的时候如何显示... + */ + public LuaValue ellipsize(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setEllipsize(view, varargs); + } else { + return getEllipsize(view, varargs); + } + } + + public LuaValue setEllipsize(U view, Varargs varargs) { + //TODO 这里需要统一 + final String ellipsizeName = varargs.optjstring(2, TextUtils.TruncateAt.END.name()); + final TextUtils.TruncateAt ellipsize = UDEllipsize.parse(ellipsizeName); + return view.setEllipsize(ellipsize); + } + + public LuaValue getEllipsize(U view, Varargs varargs) { + return valueOf(view.getEllipsize()); + } + + + /** + * 让Label字体大小适应宽度, 设置的字体为最大字体, 如果文字超出会缩小字体. + * + * @param view + * @param varargs + * @return + */ + @Deprecated + public LuaValue adjustTextSize(U view, Varargs varargs) { + return view.adjustTextSize(); + } + + public LuaValue adjustFontSize(U view, Varargs varargs) { + return view.adjustTextSize(); + } +} \ No newline at end of file diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/ui/UIToastMethodMapper.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/ui/UIToastMethodMapper.java new file mode 100644 index 00000000..be4866e8 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/ui/UIToastMethodMapper.java @@ -0,0 +1,63 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.mapper.ui; + +import com.taobao.luaview.fun.base.BaseMethodMapper; +import com.taobao.luaview.fun.mapper.LuaViewLib; +import com.taobao.luaview.userdata.ui.UDToast; +import com.taobao.luaview.util.LuaViewUtil; + +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; + +import java.util.List; + +/** + * notice/toast 接口封装 + * + * @author song + * @date 15/8/21 + */ +@LuaViewLib(revisions = {"20170306已对标"}) +public class UIToastMethodMapper extends BaseMethodMapper { + private static final String TAG = "UIToastMethodMapper"; + private static final String[] sMethods = new String[]{ + "show"//0 + }; + + @Override + public List getAllFunctionNames() { + return mergeFunctionNames(TAG, super.getAllFunctionNames(), sMethods); + } + + @Override + public Varargs invoke(int code, U target, Varargs varargs) { + final int optcode = code - super.getAllFunctionNames().size(); + switch (optcode) { + case 0: + return show(target, varargs); + } + return super.invoke(code, target, varargs); + } + + //--------------------------------------- API -------------------------------------------------- + + /** + * show a toast + * + * @param view + * @param varargs + * @return + */ + @Deprecated + public LuaValue show(U view, Varargs varargs) { + final CharSequence text = LuaViewUtil.getText(varargs.optvalue(2, NIL)); + return view.show(text); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/ui/UIViewGroupMethodMapper.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/ui/UIViewGroupMethodMapper.java new file mode 100644 index 00000000..1cb96d3b --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/ui/UIViewGroupMethodMapper.java @@ -0,0 +1,261 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.mapper.ui; + +import com.taobao.luaview.fun.mapper.LuaViewApi; +import com.taobao.luaview.fun.mapper.LuaViewLib; +import com.taobao.luaview.userdata.ui.UDView; +import com.taobao.luaview.userdata.ui.UDViewGroup; +import com.taobao.luaview.util.LuaUtil; + +import org.luaj.vm2.LuaFunction; +import org.luaj.vm2.LuaTable; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; + +import java.util.ArrayList; +import java.util.List; + +/** + * View 接口封装 + * TODO onShow, onHide, onBack只实现在了ViewGroup,后续可以考虑迁移到基础View中 + * + * @param + * @author song + */ +@LuaViewLib(revisions = {"20170306已对标"}) +public class UIViewGroupMethodMapper extends UIViewMethodMapper { + + private static final String TAG = "UIViewGroupMethodMapper"; + private static final String[] sMethods = new String[]{ + "onShow",//0 + "onHide",//1 + "onBack",//2 + "onLayout",//3 + "addView",//4 + "removeView",//5 + "removeAllViews",//6 + "children",//7 + "flexChildren",//8 + }; + + @Override + public List getAllFunctionNames() { + return mergeFunctionNames(TAG, super.getAllFunctionNames(), sMethods); + } + + @Override + public Varargs invoke(int code, U target, Varargs varargs) { + final int optcode = code - super.getAllFunctionNames().size(); + switch (optcode) { + case 0: + return onShow(target, varargs); + case 1: + return onHide(target, varargs); + case 2: + return onBack(target, varargs); + case 3: + return onLayout(target, varargs); + case 4: + return addView(target, varargs); + case 5: + return removeView(target, varargs); + case 6: + return removeAllViews(target, varargs); + case 7: + return children(target, varargs); + case 8: + return flexChildren(target, varargs); + } + return super.invoke(code, target, varargs); + } + + //--------------------------------------- API -------------------------------------------------- + + + /** + * onShow + * + * @param view + * @param varargs + * @return + */ + public LuaValue onShow(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setOnShow(view, varargs); + } else { + return getOnShow(view, varargs); + } + } + + public LuaValue setOnShow(U view, Varargs varargs) { + final LuaValue callbacks = varargs.optvalue(2, NIL); + return view.setOnShowCallback(callbacks); + } + + public LuaValue getOnShow(U view, Varargs varargs) { + return view.getOnShowCallback(); + } + + /** + * onHide + * + * @param view + * @param varargs + * @return + */ + public LuaValue onHide(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setOnHide(view, varargs); + } else { + return getOnHide(view, varargs); + } + } + + public LuaValue setOnHide(U view, Varargs varargs) { + final LuaValue callbacks = varargs.optvalue(2, NIL); + return view.setOnHideCallback(callbacks); + } + + public LuaValue getOnHide(U view, Varargs varargs) { + return view.getOnHideCallback(); + } + + /** + * onBack + * + * @param view + * @param varargs + * @return + */ + @LuaViewApi(revisions = {"Android特有"}) + public LuaValue onBack(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setOnBack(view, varargs); + } else { + return getOnBack(view, varargs); + } + } + + public LuaValue setOnBack(U view, Varargs varargs) { + final LuaValue callbacks = varargs.optvalue(2, NIL); + return view.setOnBackCallback(callbacks); + } + + public LuaValue getOnBack(U view, Varargs varargs) { + return view.getOnBackCallback(); + } + + /** + * onLayout + * + * @param view + * @param varargs + * @return + */ + public LuaValue onLayout(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setOnLayout(view, varargs); + } else { + return getOnLayout(view, varargs); + } + } + + public LuaValue setOnLayout(U view, Varargs varargs) { + final LuaValue callbacks = varargs.optvalue(2, NIL); + return view.setOnLayoutCallback(callbacks); + } + + public LuaValue getOnLayout(U view, Varargs varargs) { + return view.getOnLayoutCallback(); + } + + /** + * 添加子类 + * + * @param view + * @param varargs + * @return + */ + public LuaValue addView(U view, Varargs varargs) { + final LuaValue luaValue = varargs.optvalue(2, null); + final Integer pos = LuaUtil.getInt(varargs, 3); + if (luaValue instanceof UDView) { + return view.addView((UDView) luaValue, pos); + } + return view; + } + + /** + * 移除子类 + * + * @param view + * @return + */ + public LuaValue removeView(U view, Varargs varargs) { + final LuaValue luaValue = varargs.optvalue(2, null); + if (luaValue instanceof UDView) { + return view.removeView((UDView) luaValue); + } + return view; + } + + /** + * 移除所有子类 + * + * @param view + * @param varargs + * @return + */ + public LuaValue removeAllViews(U view, Varargs varargs) { + return view.removeAllViews(); + } + + + /** + * 设置子View的构造环境,可以方便地构造子view,不用显式remove & add了 + * + * @param view + * @param varargs + * @return + */ + public LuaValue children(U view, Varargs varargs) { + final LuaFunction callback = LuaUtil.getFunction(varargs, 2); + return view.children(callback); + } + + /** + * Flexbox 设置childViews + * + * @param view + * @param varargs + * @return + */ + public LuaValue flexChildren(U view, Varargs varargs) { + ArrayList flexChildren = new ArrayList(); + LuaValue children = varargs.arg(2); + if (children != null && children instanceof LuaTable) { // 子节点以一个表的形式作为参数传入 + for (int i = 0; i <= children.length(); i++) { + LuaValue luaValue = children.get(i + 1); + if (luaValue != null && luaValue instanceof UDView) { + flexChildren.add((UDView) luaValue); + } + } + } else { + for (int i = 2; i <= varargs.narg(); i++) { + LuaValue luaValue = varargs.optvalue(i, null); + if (luaValue != null && luaValue instanceof UDView) { + flexChildren.add((UDView) luaValue); + } + } + } + view.setChildNodeViews(flexChildren); + return view; + } +} \ No newline at end of file diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/ui/UIViewMethodMapper.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/ui/UIViewMethodMapper.java new file mode 100644 index 00000000..b458b515 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/ui/UIViewMethodMapper.java @@ -0,0 +1,2385 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.mapper.ui; + +import android.widget.RelativeLayout; + +import com.taobao.luaview.fun.base.BaseMethodMapper; +import com.taobao.luaview.fun.mapper.LuaViewApi; +import com.taobao.luaview.fun.mapper.LuaViewLib; +import com.taobao.luaview.global.SdkVersion; +import com.taobao.luaview.global.VmVersion; +import com.taobao.luaview.userdata.ui.UDView; +import com.taobao.luaview.util.ColorUtil; +import com.taobao.luaview.util.DimenUtil; +import com.taobao.luaview.util.LuaUtil; + +import org.luaj.vm2.LuaFunction; +import org.luaj.vm2.LuaTable; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; + +import java.util.ArrayList; +import java.util.List; + +/** + * 所有view 接口封装 + * + * @param + * @author song + */ +@LuaViewLib(revisions = {"20170306已对标"}) +public class UIViewMethodMapper extends BaseMethodMapper { + private static final String TAG = "UIViewMethodMapper"; + private static final String[] sMethods = new String[]{ + "initParams",//0 + "invalidate",//1 + "padding",//2 + "frame",//3 + "backgroundColor",//4 + "size",//5 + "xy",//6 + "align",//7 + "alignLeft",//8 + "alignTop",//9 + "alignRight",//10 + "alignBottom",//11 + "alignLeftTop",//12 + "alignTopLeft",//13 + "alignCenterTop",//14 + "alignTopCenter",//15 + "alignRightTop",//16 + "alignTopRight",//17 + "alignLeftBottom",//18 + "alignBottomLeft",//19 + "alignCenterBottom",//20 + "alignBottomCenter",//21 + "alignRightBottom",//22 + "alignBottomRight",//23 + "alignCenter",//24 + "alignLeftCenter",//25 + "alignCenterLeft",//26 + "alignRightCenter",//27 + "alignCenterRight",//28 + "alignCenterHorizontal",//29 + "alignHorizontalCenter",//30 + "alignCenterVertical",//31 + "alignVerticalCenter",//32 + "center",//33 + "x",//34 + "y",//35 + "left",//36 + "top",//37 + "right",//38 + "bottom",//39 + "width",//40 + "minWidth",//41 + "height",//42 + "centerX",//43 + "centerY",//44 + "visible",//45 + "hidden",//46 + "show",//47 + "isShow",//48 + "hide",//49 + "isHide",//50 + "enabled",//51 + "alpha",//52 + "borderWidth",//53 + "borderColor",//54 + "clipsToBounds",//55 + "shadowPath",//56 + "masksToBounds",//57 + "shadowOffset",//58 + "shadowRadius",//59 + "shadowOpacity",//60 + "shadowColor",//61 + "sizeToFit",//62 + "addGestureRecognizer",//63 + "removeGestureRecognizer",//64 + "transform3D",//65 + "anchorPoint",//66 + "removeFromSuper",//67 + "removeFromParent",//68 + "hasFocus",//69 + "requestFocus",//70 + "clearFocus",//71 + "rotation",//72 + "rotationXY",//73 + "scale",//74 + "scaleX",//75 + "scaleY",//76 + "translation",//77 + "translationX",//78 + "translationY",//79 + "bringToFront",//80 + "scrollTo",//81 + "scrollBy",//82 + "scrollX",//83 + "offsetX",//84 + "scrollY",//85 + "offsetY",//86 + "scrollXY",//87 + "offsetXY",//88 + "offset",//89 + "showScrollIndicator",//90 + "callback",//91 + "onClick",//92 + "onLongClick",//93 + "adjustSize",//94 + "cornerRadius",//95 + "startAnimation",//96 + "stopAnimation",//97 + "isAnimating",//98 + "flexCss",//99 + "flxLayout",//100 + "effects",//101 + "nativeView",//102 + "borderDash",//103 + "margin",//104 + "onTouch"//105 +// "matrix"//106 + }; + + @Override + public List getAllFunctionNames() { + return mergeFunctionNames(TAG, super.getAllFunctionNames(), sMethods); + } + + @Override + public Varargs invoke(int code, U target, Varargs varargs) { + final int optcode = code - super.getAllFunctionNames().size(); + switch (optcode) { + case 0: + return initParams(target, varargs); + case 1: + return invalidate(target, varargs); + case 2: + return padding(target, varargs); + case 3: + return frame(target, varargs); + case 4: + return backgroundColor(target, varargs); + case 5: + return size(target, varargs); + case 6: + return xy(target, varargs); + case 7: + return align(target, varargs); + case 8: + return alignLeft(target, varargs); + case 9: + return alignTop(target, varargs); + case 10: + return alignRight(target, varargs); + case 11: + return alignBottom(target, varargs); + case 12: + return alignLeftTop(target, varargs); + case 13: + return alignTopLeft(target, varargs); + case 14: + return alignCenterTop(target, varargs); + case 15: + return alignTopCenter(target, varargs); + case 16: + return alignRightTop(target, varargs); + case 17: + return alignTopRight(target, varargs); + case 18: + return alignLeftBottom(target, varargs); + case 19: + return alignBottomLeft(target, varargs); + case 20: + return alignCenterBottom(target, varargs); + case 21: + return alignBottomCenter(target, varargs); + case 22: + return alignRightBottom(target, varargs); + case 23: + return alignBottomRight(target, varargs); + case 24: + return alignCenter(target, varargs); + case 25: + return alignLeftCenter(target, varargs); + case 26: + return alignCenterLeft(target, varargs); + case 27: + return alignRightCenter(target, varargs); + case 28: + return alignCenterRight(target, varargs); + case 29: + return alignCenterHorizontal(target, varargs); + case 30: + return alignHorizontalCenter(target, varargs); + case 31: + return alignCenterVertical(target, varargs); + case 32: + return alignVerticalCenter(target, varargs); + case 33: + return center(target, varargs); + case 34: + return x(target, varargs); + case 35: + return y(target, varargs); + case 36: + return left(target, varargs); + case 37: + return top(target, varargs); + case 38: + return right(target, varargs); + case 39: + return bottom(target, varargs); + case 40: + return width(target, varargs); + case 41: + return minWidth(target, varargs); + case 42: + return height(target, varargs); + case 43: + return centerX(target, varargs); + case 44: + return centerY(target, varargs); + case 45: + return visible(target, varargs); + case 46: + return hidden(target, varargs); + case 47: + return show(target, varargs); + case 48: + return isShow(target, varargs); + case 49: + return hide(target, varargs); + case 50: + return isHide(target, varargs); + case 51: + return enabled(target, varargs); + case 52: + return alpha(target, varargs); + case 53: + return borderWidth(target, varargs); + case 54: + return borderColor(target, varargs); + case 55: + return clipsToBounds(target, varargs); + case 56: + return shadowPath(target, varargs); + case 57: + return masksToBounds(target, varargs); + case 58: + return shadowOffset(target, varargs); + case 59: + return shadowRadius(target, varargs); + case 60: + return shadowOpacity(target, varargs); + case 61: + return shadowColor(target, varargs); + case 62: + return sizeToFit(target, varargs); + case 63: + return addGestureRecognizer(target, varargs); + case 64: + return removeGestureRecognizer(target, varargs); + case 65: + return transform3D(target, varargs); + case 66: + return anchorPoint(target, varargs); + case 67: + return removeFromSuper(target, varargs); + case 68: + return removeFromParent(target, varargs); + case 69: + return hasFocus(target, varargs); + case 70: + return requestFocus(target, varargs); + case 71: + return clearFocus(target, varargs); + case 72: + return rotation(target, varargs); + case 73: + return rotationXY(target, varargs); + case 74: + return scale(target, varargs); + case 75: + return scaleX(target, varargs); + case 76: + return scaleY(target, varargs); + case 77: + return translation(target, varargs); + case 78: + return translationX(target, varargs); + case 79: + return translationY(target, varargs); + case 80: + return bringToFront(target, varargs); + case 81: + return scrollTo(target, varargs); + case 82: + return scrollBy(target, varargs); + case 83: + return scrollX(target, varargs); + case 84: + return offsetX(target, varargs); + case 85: + return scrollY(target, varargs); + case 86: + return offsetY(target, varargs); + case 87: + return scrollXY(target, varargs); + case 88: + return offsetXY(target, varargs); + case 89: + return offset(target, varargs); + case 90: + return showScrollIndicator(target, varargs); + case 91: + return callback(target, varargs); + case 92: + return onClick(target, varargs); + case 93: + return onLongClick(target, varargs); + case 94: + return adjustSize(target, varargs); + case 95: + return cornerRadius(target, varargs); + case 96: + return startAnimation(target, varargs); + case 97: + return stopAnimation(target, varargs); + case 98: + return isAnimating(target, varargs); + case 99: + return flexCss(target, varargs); + case 100: + return flxLayout(target, varargs); + case 101: + return effects(target, varargs); + case 102: + return nativeView(target, varargs); + case 103: + return borderDash(target, varargs); + case 104: + return margin(target, varargs); + case 105: + return onTouch(target, varargs); +// case 106: +// return matrix(target, varargs); + } + return super.invoke(code, target, varargs); + } + + //--------------------------------------- API -------------------------------------------------- + + + /** + * 初始化数据 + * + * @param view + * @param varargs + * @return + */ + @Deprecated + public Varargs initParams(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setInitParams(view, varargs); + } else { + return getInitParams(view, varargs); + } + } + + public LuaValue setInitParams(U view, Varargs varargs) { + final LuaValue initParams = varargs.optvalue(2, NIL); + return view.setInitParams(initParams); + } + + public Varargs getInitParams(U view, Varargs varargs) { + return view.getInitParams(); + } + + /** + * 刷新view + * + * @param view + * @param varargs + * @return + */ + public LuaValue invalidate(U view, Varargs varargs) { + return view.invalidate(); + } + + + /** + * 设置位置 + * + * @param view + * @param varargs + * @return + */ + public Varargs padding(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setPadding(view, varargs); + } else { + return getPadding(view, varargs); + } + } + + public LuaValue setPadding(U view, Varargs varargs) { + final int left = DimenUtil.dpiToPx(varargs.arg(2)); + final int top = DimenUtil.dpiToPx(varargs.arg(3)); + final int right = DimenUtil.dpiToPx(varargs.arg(4)); + final int bottom = DimenUtil.dpiToPx(varargs.arg(5)); + return view.setPadding(left, top, right, bottom); + } + + public Varargs getPadding(U view, Varargs varargs) { + return varargsOf(new LuaValue[]{valueOf(DimenUtil.pxToDpi(view.getPaddingLeft())), valueOf(DimenUtil.pxToDpi(view.getPaddingTop())), valueOf(DimenUtil.pxToDpi(view.getPaddingRight())), valueOf(DimenUtil.pxToDpi(view.getPaddingBottom()))}); + } + + + /** + * 设置Margin + * + * @param view + * @param varargs + * @return + */ + public Varargs margin(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setMargin(view, varargs); + } else { + return getMargin(view, varargs); + } + } + + public LuaValue setMargin(U view, Varargs varargs) { + final Integer left = DimenUtil.dpiToPx(varargs.arg(2), null); + final Integer top = DimenUtil.dpiToPx(varargs.arg(3), null); + final Integer right = DimenUtil.dpiToPx(varargs.arg(4), null); + final Integer bottom = DimenUtil.dpiToPx(varargs.arg(5), null); + return view.setMargin(left, top, right, bottom); + } + + public Varargs getMargin(U view, Varargs varargs) { + return varargsOf(new LuaValue[]{valueOf(DimenUtil.pxToDpi(view.getMarginLeft())), valueOf(DimenUtil.pxToDpi(view.getMarginTop())), valueOf(DimenUtil.pxToDpi(view.getMarginRight())), valueOf(DimenUtil.pxToDpi(view.getMarginBottom()))}); + } + + /** + * 获取view的位置和大小 + * + * @param view + * @param varargs + * @return + */ + public Varargs frame(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setFrame(view, varargs); + } else { + return getFrame(view, varargs); + } + } + + public LuaValue setFrame(U view, Varargs varargs) { + final int x = DimenUtil.dpiToPx(varargs.arg(2)); + final int y = DimenUtil.dpiToPx(varargs.arg(3)); + final int width = DimenUtil.dpiToPx(varargs.arg(4)); + final int height = DimenUtil.dpiToPx(varargs.arg(5)); + return view.setFrame(x, y, width, height); + } + + public Varargs getFrame(U view, Varargs varargs) { + return varargsOf(new LuaValue[]{valueOf(DimenUtil.pxToDpi(view.getX())), valueOf(DimenUtil.pxToDpi(view.getY())), valueOf(DimenUtil.pxToDpi(view.getWidth())), valueOf(DimenUtil.pxToDpi(view.getHeight()))}); + } + + + /** + * 获取背景颜色 + * + * @param view + * @param varargs + * @return + */ + @LuaViewApi(revisions = {"IOS不支持图片", "待替换成background"}) + public Varargs backgroundColor(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setBackgroundColor(view, varargs); + } else { + return getBackgroundColor(view, varargs); + } + } + + public LuaValue setBackgroundColor(final U view, final Varargs args) { + if (args.isnumber(2)) {//TODO 支持8位颜色设置,以及alpha设置。同时支持获取 + final Integer color = ColorUtil.parse(LuaUtil.getInt(args, 2)); + Double alpha = LuaUtil.getDouble(args, 3); + return view.setBackgroundColorAndAlpha(color, alpha); + } else { + final String pic = args.optjstring(2, ""); + final Double alpha = LuaUtil.getDouble(args, 3); + return view.setBackgroundResourceAndAlpha(pic, alpha); + } + } + + public Varargs getBackgroundColor(U view, Varargs varargs) { + return varargsOf(valueOf(ColorUtil.getHexColor(view.getBackgroundColor())), valueOf(view.getBackgroundAlpha())); + } + + + /** + * 获取尺寸 + * + * @param view UIView + * @param varargs + * @return + */ + public Varargs size(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setSize(view, varargs); + } else { + return getSize(view, varargs); + } + } + + public LuaValue setSize(U view, Varargs varargs) { + final int width = DimenUtil.dpiToPx(varargs.arg(2), -1); + final int height = DimenUtil.dpiToPx(varargs.arg(3), -1); + if (width != -1 && height != -1) {//两个值则设置宽高 + return view.setSize(width, height); + } + return view.setWidth(width);//一个值设置宽 + } + + public Varargs getSize(U view, Varargs varargs) { + final float width = DimenUtil.pxToDpi(view.getWidth()); + final float height = DimenUtil.pxToDpi(view.getHeight()); + return varargsOf(valueOf(width), valueOf(height)); + } + + + /** + * 位置 + * + * @param view + * @param varargs + * @return + */ + public Varargs xy(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setXY(view, varargs); + } else { + return getXY(view, varargs); + } + } + + public LuaValue setXY(U view, Varargs varargs) { + final int x = DimenUtil.dpiToPx(varargs.arg(2)); + final int y = DimenUtil.dpiToPx(varargs.arg(3)); + return view.setXY(x, y); + } + + public Varargs getXY(U view, Varargs varargs) { + return varargsOf(valueOf(DimenUtil.pxToDpi(view.getX())), valueOf(DimenUtil.pxToDpi(view.getY()))); + } + + + /** + * 设置位于 + * + * @param view + * @param varargs + * @return + */ + public LuaValue align(U view, Varargs varargs) { + if (varargs.narg() > 1) { + ArrayList list = new ArrayList(); + for (int i = 0; i < varargs.narg(); i++) { + int align = varargs.optint((2 + i), -1); + if (align != -1) { + list.add(align); + } + } + if (list.size() > 0) { + Integer[] aligns = new Integer[list.size()]; + list.toArray(aligns); + return view.align(aligns); + } + } + return view; + } + + /** + * 位于左上 + * + * @param view UIView + * @param args + * @return + */ + public LuaValue alignLeft(U view, Varargs args) { + return alignTopLeft(view, args); + } + + /** + * 位于左上 + * + * @param view UIView + * @param args + * @return + */ + public LuaValue alignTop(U view, Varargs args) { + return alignTopLeft(view, args); + } + + /** + * 位于右上 + * + * @param view UIView + * @param args + * @return + */ + public LuaValue alignRight(U view, Varargs args) { + return alignTopRight(view, args); + } + + /** + * 位于左下 + * + * @param view UIView + * @param args + * @return + */ + public LuaValue alignBottom(U view, Varargs args) { + return alignBottomLeft(view, args); + } + + + /** + * 位于左上 + * + * @param view UIView + * @param args + * @return + */ + @Deprecated + public LuaValue alignLeftTop(U view, Varargs args) { + return alignTopLeft(view, args); + } + + @Deprecated + public LuaValue alignTopLeft(U view, Varargs args) { + return view.align(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.ALIGN_PARENT_LEFT); + } + + /** + * 位于上中 + * + * @param view UIView + * @param args + * @return + */ + @Deprecated + public LuaValue alignCenterTop(U view, Varargs args) { + return alignTopCenter(view, args); + } + + @Deprecated + public LuaValue alignTopCenter(U view, Varargs args) { + return view.align(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.CENTER_HORIZONTAL); + } + + /** + * 位于左下 + * + * @param view UIView + * @param args + * @return + */ + @Deprecated + public LuaValue alignRightTop(U view, Varargs args) { + return alignTopRight(view, args); + } + + @Deprecated + public LuaValue alignTopRight(U view, Varargs args) { + return view.align(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.ALIGN_PARENT_RIGHT); + } + + /** + * 位于下左 + * + * @param view UIView + * @param args + * @return + */ + @Deprecated + public LuaValue alignLeftBottom(U view, Varargs args) { + return alignBottomLeft(view, args); + } + + @Deprecated + public LuaValue alignBottomLeft(U view, Varargs args) { + return view.align(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.ALIGN_PARENT_LEFT); + } + + /** + * 位于下左 + * + * @param view UIView + * @param args + * @return + */ + @Deprecated + public LuaValue alignCenterBottom(U view, Varargs args) { + return alignBottomCenter(view, args); + } + + @Deprecated + public LuaValue alignBottomCenter(U view, Varargs args) { + return view.align(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.CENTER_HORIZONTAL); + } + + /** + * 位于下右 + * + * @param view UIView + * @param args + * @return + */ + @Deprecated + public LuaValue alignRightBottom(U view, Varargs args) { + return alignBottomRight(view, args); + } + + @Deprecated + public LuaValue alignBottomRight(U view, Varargs args) { + return view.align(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.ALIGN_PARENT_RIGHT); + } + + + /** + * 设置水平、竖直居中 + * + * @param view UIView + * @param args + * @return + */ + public LuaValue alignCenter(U view, Varargs args) { + return view.align(RelativeLayout.CENTER_IN_PARENT); + } + + /** + * 设置水平、居左 + * + * @param view UIView + * @param args + * @return + */ + @Deprecated + public LuaValue alignLeftCenter(U view, Varargs args) { + return alignCenterLeft(view, args); + } + + @Deprecated + public LuaValue alignCenterLeft(U view, Varargs args) { + return view.align(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.ALIGN_PARENT_LEFT); + } + + /** + * 设置水平,居右 + * + * @param view UIView + * @param args + * @return + */ + @Deprecated + public LuaValue alignRightCenter(U view, Varargs args) { + return alignCenterRight(view, args); + } + + @Deprecated + public LuaValue alignCenterRight(U view, Varargs args) { + return view.align(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.ALIGN_PARENT_RIGHT); + } + + /** + * 设置水平居中 + * + * @param view UIView + * @param args + * @return + */ + @Deprecated + public LuaValue alignCenterHorizontal(U view, Varargs args) { + return alignHorizontalCenter(view, args); + } + + @Deprecated + public LuaValue alignHorizontalCenter(U view, Varargs args) { + return view.align(RelativeLayout.CENTER_HORIZONTAL); + } + + /** + * 设置竖直居中 + * + * @param view UIView + * @param args + * @return + */ + @Deprecated + public LuaValue alignCenterVertical(U view, Varargs args) { + return alignVerticalCenter(view, args); + } + + @Deprecated + public LuaValue alignVerticalCenter(U view, Varargs args) { + return view.align(RelativeLayout.CENTER_VERTICAL); + } + + + /** + * 设置中心点位置 + * + * @param view UIView + * @param varargs + * @return + */ + public Varargs center(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setCenter(view, varargs); + } else { + return getCenter(view, varargs); + } + } + + public LuaValue setCenter(U view, Varargs varargs) { + final int x = DimenUtil.dpiToPx(varargs.arg(2)); + final int y = DimenUtil.dpiToPx(varargs.arg(3)); + return view.setCenter(x, y); + } + + public Varargs getCenter(U view, Varargs varargs) { + float x = 0.0f, y = 0.0f; + if (view != null && view.getView() != null) { + x = view.getX() + view.getWidth() / 2.0f; + y = view.getY() + view.getHeight() / 2.0f; + } + return varargsOf(valueOf(DimenUtil.pxToDpi(x)), valueOf(DimenUtil.pxToDpi(y))); + } + + /** + * 获取X坐标 + * + * @param view UIView + * @param varargs + * @return + */ + public LuaValue x(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setX(view, varargs); + } else { + return getX(view, varargs); + } + } + + public LuaValue setX(U view, Varargs varargs) { + final int x = DimenUtil.dpiToPx(varargs.arg(2)); + return view.setX(x); + } + + public LuaValue getX(U view, Varargs varargs) { + return valueOf(DimenUtil.pxToDpi(view.getX())); + } + + + /** + * 设置Y坐标 + * + * @param view UIView + * @param varargs + * @return + */ + public LuaValue y(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setY(view, varargs); + } else { + return getY(view, varargs); + } + } + + public LuaValue setY(U view, Varargs varargs) { + final int y = DimenUtil.dpiToPx(varargs.arg(2)); + return view.setY(y); + } + + public LuaValue getY(U view, Varargs varargs) { + return valueOf(DimenUtil.pxToDpi(view.getY())); + } + + /** + * 设置left坐标 + * + * @param view UIView + * @param varargs + * @return + */ + public LuaValue left(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setLeft(view, varargs); + } else { + return getLeft(view, varargs); + } + } + + public LuaValue setLeft(U view, Varargs varargs) { + final int left = DimenUtil.dpiToPx(varargs.arg(2)); + return view.setX(left); + } + + public LuaValue getLeft(U view, Varargs varargs) { + return valueOf(DimenUtil.pxToDpi(view.getX())); + } + + /** + * 设置top坐标 + * + * @param view UIView + * @param varargs + * @return + */ + public LuaValue top(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setTop(view, varargs); + } else { + return getTop(view, varargs); + } + } + + public LuaValue setTop(U view, Varargs varargs) { + final int top = DimenUtil.dpiToPx(varargs.arg(2)); + return view.setY(top); + } + + public LuaValue getTop(U view, Varargs varargs) { + return valueOf(DimenUtil.pxToDpi(view.getY())); + } + + + /** + * 设置right坐标 + * + * @param view UIView + * @param varargs + * @return + */ + public LuaValue right(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setRight(view, varargs); + } else { + return getRight(view, varargs); + } + } + + public LuaValue setRight(U view, Varargs varargs) { + final int right = DimenUtil.dpiToPx(varargs.arg(2)); + return view.setX(right - view.getWidth()); + } + + public LuaValue getRight(U view, Varargs varargs) { + return valueOf(DimenUtil.pxToDpi(view.getX() + view.getWidth())); + } + + + /** + * 设置bottom坐标 + * + * @param view UIView + * @param varargs + * @return + */ + public LuaValue bottom(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setBottom(view, varargs); + } else { + return getBottom(view, varargs); + } + } + + public LuaValue setBottom(U view, Varargs varargs) { + final int bottom = DimenUtil.dpiToPx(varargs.arg(2)); + return view.setY(bottom - view.getHeight()); + } + + public LuaValue getBottom(U view, Varargs varargs) { + return valueOf(DimenUtil.pxToDpi(view.getY() + view.getHeight())); + } + + /** + * 设置宽度 + * + * @param view + * @param varargs + * @return + */ + public LuaValue width(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setWidth(view, varargs); + } else { + return getWidth(view, varargs); + } + } + + public LuaValue setWidth(U view, Varargs varargs) { + final int width = DimenUtil.dpiToPx(varargs.arg(2), -1); + return view.setWidth(width); + } + + public LuaValue getWidth(U view, Varargs varargs) { + return valueOf(DimenUtil.pxToDpi(view.getWidth())); + } + + /** + * 设置最小宽度 + * + * @param view + * @param varargs + * @return + */ + @Deprecated + public LuaValue minWidth(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setMinWidth(view, varargs); + } else { + return getMinWidth(view, varargs); + } + } + + public LuaValue setMinWidth(U view, Varargs varargs) { + final int width = DimenUtil.dpiToPx(varargs.arg(2), -1); + return view.setMinWidth(width); + } + + public LuaValue getMinWidth(U view, Varargs varargs) { + return valueOf(DimenUtil.pxToDpi(view.getMinWidth())); + } + + /** + * 设置高度 + * + * @param view + * @param varargs + * @return + */ + public LuaValue height(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setHeight(view, varargs); + } else { + return getHeight(view, varargs); + } + } + + public LuaValue setHeight(U view, Varargs varargs) { + final int height = DimenUtil.dpiToPx(varargs.arg(2), -1); + return view.setHeight(height); + } + + public LuaValue getHeight(U view, Varargs varargs) { + return valueOf(DimenUtil.pxToDpi(view.getHeight())); + } + + + /** + * 设置中心X位置 + * + * @param view + * @param varargs + * @return + */ + public LuaValue centerX(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setCenterX(view, varargs); + } else { + return getCenterX(view, varargs); + } + } + + public LuaValue setCenterX(U view, Varargs varargs) { + final int x = DimenUtil.dpiToPx(varargs.arg(2)); + return view.setCenterX(x); + } + + public LuaValue getCenterX(U view, Varargs varargs) { + return valueOf(DimenUtil.pxToDpi(view.getX() + view.getWidth() / 2.0f)); + } + + /** + * 设置中心Y位置 + * + * @param view + * @param varargs + * @return + */ + public LuaValue centerY(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setCenterY(view, varargs); + } else { + return getCenterY(view, varargs); + } + } + + public LuaValue setCenterY(U view, Varargs varargs) { + final int y = DimenUtil.dpiToPx(varargs.arg(2)); + return view.setCenterY(y); + } + + + public LuaValue getCenterY(U view, Varargs varargs) { + return valueOf(DimenUtil.pxToDpi(view.getY() + view.getHeight() / 2.0f)); + } + + /** + * 显示 + * + * @param view + * @param varargs + * @return + */ + public LuaValue visible(U view, Varargs varargs) { + if (varargs.narg() > 1) { + boolean isShow = varargs.optboolean(2, true); + return isShow ? show(view, varargs) : hide(view, varargs); + } else { + return isShow(view, varargs); + } + } + + /** + * 显示 + * + * @param view + * @param varargs + * @return + */ + public LuaValue hidden(U view, Varargs varargs) { + if (varargs.narg() > 1) { + boolean isHide = varargs.optboolean(2, true); + return isHide ? hide(view, varargs) : show(view, varargs); + } else { + return isHide(view, varargs); + } + } + + /** + * 显示 + * + * @param view + * @param varargs + * @return + */ + @Deprecated + public LuaValue show(U view, Varargs varargs) { + return view.show(); + } + + @Deprecated + public LuaValue isShow(U view, Varargs varargs) { + return valueOf(view.isShow()); + } + + /** + * 隐藏 + * + * @param view + * @param varargs + * @return + */ + @Deprecated + public LuaValue hide(U view, Varargs varargs) { + return view.hide(); + } + + @Deprecated + public LuaValue isHide(U view, Varargs varargs) { + return valueOf(view.isHide()); + } + + + /** + * 设置是否有效 + * + * @param view UIView + * @param varargs + * @return + */ + public LuaValue enabled(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setEnabled(view, varargs); + } else { + return isEnabled(view, varargs); + } + } + + public LuaValue setEnabled(U view, Varargs args) { + final boolean enable = args.optboolean(2, true); + return view.setEnabled(enable); + } + + public LuaValue isEnabled(U view, Varargs varargs) { + return valueOf(view.isEnabled()); + } + + /** + * 设置alpha + * + * @param view UIView + * @param varargs + * @return + */ + public LuaValue alpha(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setAlpha(view, varargs); + } else { + return getAlpha(view, varargs); + } + } + + public LuaValue setAlpha(U view, Varargs varargs) { + final float alpha = (float) varargs.optdouble(2, 1.0f); + return view.setAlpha(alpha); + } + + public LuaValue getAlpha(U view, Varargs varargs) { + return valueOf(view.getAlpha()); + } + + /** + * 设置边框粗细 + * + * @param view + * @param varargs + * @return + */ + public LuaValue borderWidth(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setBorderWidth(view, varargs); + } else { + return getBorderWidth(view, varargs); + } + } + + public LuaValue setBorderWidth(U view, Varargs varargs) { + final int width = DimenUtil.dpiToPx(varargs.arg(2)); + return view.setBorderWidth(width); + } + + public LuaValue getBorderWidth(U view, Varargs varargs) { + return valueOf(DimenUtil.pxToDpi(view.getBorderWidth())); + } + + /** + * 设置边框颜色,alpha + * + * @param view + * @param varargs + * @return + */ + public LuaValue borderColor(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setBorderColor(view, varargs); + } else { + return getBorderColor(view, varargs); + } + } + + public LuaValue setBorderColor(U view, Varargs varargs) { + final Integer color = ColorUtil.parse(LuaUtil.getInt(varargs, 2)); + return view.setBorderColor(color); + } + + public LuaValue getBorderColor(U view, Varargs varargs) { + return valueOf(ColorUtil.getHexColor(view.getBorderColor())); + } + + /** + * 设置边框虚线,dash + * + * @param view + * @param varargs + * @return + */ + @LuaViewApi(since = VmVersion.V_540) + public Varargs borderDash(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setBorderDash(view, varargs); + } else { + return getBorderDash(view, varargs); + } + } + + @LuaViewApi(since = VmVersion.V_540) + public LuaValue setBorderDash(U view, Varargs varargs) { + final float width = DimenUtil.dpiToPxF(LuaUtil.getFloat(varargs, 2)); + final float gap = DimenUtil.dpiToPxF(LuaUtil.getFloat(varargs, 3)); + return view.setBorderDashSize(width, gap); + } + + @LuaViewApi(since = VmVersion.V_540) + public Varargs getBorderDash(U view, Varargs varargs) { + return varargsOf(valueOf(DimenUtil.pxToDpi(view.getBorderDashWidth())), valueOf(DimenUtil.pxToDpi(view.getBorderDashGap()))); + } + + /** + * 设置View边框是否剪接 + * + * @param view + * @param varargs + * @return + */ + @LuaViewApi(revisions = "Only for iOS") + public LuaValue clipsToBounds(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setClipsToBounds(view, varargs); + } else { + return isClipsToBounds(view, varargs); + } + } + + public LuaValue setClipsToBounds(U view, Varargs varargs) { + final boolean clipsToBounds = varargs.optboolean(2, false); + //TODO + return view; + } + + public LuaValue isClipsToBounds(U view, Varargs varargs) { + //TODO + return view; + } + + /** + * 设置 只对边框外部加阴影 + * + * @param view + * @param varargs + * @return + */ + @Deprecated + public LuaValue shadowPath(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setShadowPath(view, varargs); + } else { + return getShadowPath(view, varargs); + } + } + + public LuaValue setShadowPath(U view, Varargs varargs) { + //TODO + return view; + } + + public LuaValue getShadowPath(U view, Varargs varargs) { + //TODO + return view; + } + + /** + * 设置边框是否裁剪 + * + * @param view + * @param varargs + * @return + */ + @Deprecated + public LuaValue masksToBounds(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setMasksToBounds(view, varargs); + } else { + return getMasksToBounds(view, varargs); + } + } + + public LuaValue setMasksToBounds(U view, Varargs varargs) { + //TODO + return view; + } + + public LuaValue getMasksToBounds(U view, Varargs varargs) { + //TODO + return view; + } + + /** + * 设置View阴影偏移位置 + * + * @param view + * @param varargs + * @return + */ + @Deprecated + public LuaValue shadowOffset(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setShadowOffset(view, varargs); + } else { + return getShadowOffset(view, varargs); + } + } + + public LuaValue setShadowOffset(U view, Varargs varargs) { + //TODO + //DimenUtil.dpiToPx + return view; + } + + public LuaValue getShadowOffset(U view, Varargs varargs) { + //TODO + //DimenUtil.pxToDpi + return view; + } + + /** + * 设置View阴影高斯模糊半径 + * + * @param view + * @param varargs + * @return + */ + @Deprecated + public LuaValue shadowRadius(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setShadowRadius(view, varargs); + } else { + return getShadowRadius(view, varargs); + } + } + + public LuaValue setShadowRadius(U view, Varargs varargs) { + //TODO + //DimenUtil.dpiToPx + return view; + } + + public LuaValue getShadowRadius(U view, Varargs varargs) { + //TODO + //DimenUtil.pxToDpi + return view; + } + + /** + * 设置View阴影透明度 + * + * @param view + * @param varargs + * @return + */ + @Deprecated + public LuaValue shadowOpacity(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setShadowOpacity(view, varargs); + } else { + return getShadowOpacity(view, varargs); + } + } + + public LuaValue setShadowOpacity(U view, Varargs varargs) { + //TODO + return view; + } + + public LuaValue getShadowOpacity(U view, Varargs varargs) { + //TODO + return view; + } + + /** + * 设置View阴影颜色 + * + * @param view + * @param varargs + * @return + */ + @Deprecated + public LuaValue shadowColor(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setShadowColor(view, varargs); + } else { + return getShadowColor(view, varargs); + } + } + + public LuaValue setShadowColor(U view, Varargs varargs) { + //TODO + return view; + } + + public LuaValue getShadowColor(U view, Varargs varargs) { + //TODO + return view; + } + + /** + * 适应View内容的大小 + * + * @param view + * @param varargs + * @return + */ + @LuaViewApi(revisions = {"iOS平台特性,待废弃"}) + public LuaValue sizeToFit(U view, Varargs varargs) { + //TODO + return view; + } + + /** + * 添加手势 + * + * @param view + * @param varargs + * @return + */ + @Deprecated + public LuaValue addGestureRecognizer(U view, Varargs varargs) { + //TODO + return view; + } + + /** + * 移除手势 + * + * @param view + * @param varargs + * @return + */ + @Deprecated + public LuaValue removeGestureRecognizer(U view, Varargs varargs) { + //TODO + return view; + } + + /** + * 设置3D变换矩阵 + * + * @param view + * @param varargs + * @return + */ + @Deprecated + public LuaValue transform3D(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setTransform3D(view, varargs); + } else { + return getTransform3D(view, varargs); + } + } + + public LuaValue setTransform3D(U view, Varargs varargs) { + //TODO + return view; + } + + public LuaValue getTransform3D(U view, Varargs varargs) { + //TODO + return view; + } + + /** + * 设置锚点 + * + * @param view + * @param varargs + * @return + */ + @LuaViewApi(revisions = {"名称有待讨论"}) + public Varargs anchorPoint(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setAnchorPoint(view, varargs); + } else { + return getAnchorPoint(view, varargs); + } + } + + public LuaValue setAnchorPoint(U view, Varargs varargs) { + //TODO oc实现跟这个不一样,oc会移动一下 + final float pivotX = (float) varargs.optdouble(2, 0.5f); + final float pivotY = (float) varargs.optdouble(3, 0.5f); + return view.setPivot(pivotX, pivotY); + } + + public Varargs getAnchorPoint(U view, Varargs varargs) { + return varargsOf(valueOf(view.getPivotX()), valueOf(view.getPivotY())); + } + + /** + * 从父容器中移除 + * + * @param view + * @param varargs + * @return + */ + @LuaViewApi(revisions = {"名称待讨论"}) + public LuaValue removeFromSuper(U view, Varargs varargs) { + return view.removeFromParent(); + } + + @Deprecated + public LuaValue removeFromParent(U view, Varargs varargs) { + return view.removeFromParent(); + } + + /** + * 是否有焦点 + * + * @param view + * @param varargs + * @return + */ + public LuaValue hasFocus(U view, Varargs varargs) { + return valueOf(view.hasFocus()); + } + + /** + * 请求焦点 + * + * @param view + * @param varargs + * @return + */ + public LuaValue requestFocus(U view, Varargs varargs) { + return view.requestFocus(); + } + + /** + * 取消焦点 + * + * @param view + * @param varargs + * @return + */ + public LuaValue clearFocus(U view, Varargs varargs) { + return view.clearFocus(); + } + + /** + * 旋转 + * + * @param view + * @param varargs + * @return + */ + @LuaViewApi(revisions = {"待优化,增加rotationX, rotationY"}) + public LuaValue rotation(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setRotation(view, varargs); + } else { + return getRotation(view, varargs); + } + } + + public LuaValue setRotation(U view, Varargs varargs) { + final float rotation = (float) varargs.optdouble(2, 0.0); + return view.setRotation(rotation); + } + + public LuaValue getRotation(U view, Varargs varargs) { + return valueOf(view.getRotation()); + } + + + /** + * 旋转 + * + * @param view + * @param varargs + * @return + */ + @Deprecated + public Varargs rotationXY(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setRotationXY(view, varargs); + } else { + return getRotationXY(view, varargs); + } + } + + public LuaValue setRotationXY(U view, Varargs varargs) { + final int rotationX = DimenUtil.dpiToPx(varargs.arg(2)); + final int rotationY = DimenUtil.dpiToPx(varargs.arg(3)); + return view.setRotationXY(rotationX, rotationY); + } + + public Varargs getRotationXY(U view, Varargs varargs) { + return varargsOf(valueOf(DimenUtil.pxToDpi(view.getRotationX())), valueOf(DimenUtil.pxToDpi(view.getRotationY()))); + } + + /** + * 旋转 + * + * @param view + * @param varargs + * @return + */ + public Varargs scale(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setScale(view, varargs); + } else { + return getScale(view, varargs); + } + } + + public LuaValue setScale(U view, Varargs varargs) { + final float scaleX = LuaUtil.getFloat(varargs, 0f, 2); + final float scaleY = LuaUtil.getFloat(varargs, 0f, 3, 2); + return view.setScale(scaleX, scaleY); + } + + public Varargs getScale(U view, Varargs varargs) { + return varargsOf(valueOf(view.getScaleX()), valueOf(view.getScaleY())); + } + + public Varargs scaleX(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setScaleX(view, varargs); + } else { + return getScaleX(view, varargs); + } + } + + public LuaValue setScaleX(U view, Varargs varargs) { + final float scaleX = LuaUtil.getFloat(varargs, 0f, 2); + return view.setScaleX(scaleX); + } + + public Varargs getScaleX(U view, Varargs varargs) { + return valueOf(view.getScaleX()); + } + + public Varargs scaleY(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setScaleY(view, varargs); + } else { + return getScaleY(view, varargs); + } + } + + public LuaValue setScaleY(U view, Varargs varargs) { + final float scaleY = LuaUtil.getFloat(varargs, 0f, 2); + return view.setScaleY(scaleY); + } + + public Varargs getScaleY(U view, Varargs varargs) { + return valueOf(view.getScaleY()); + } + + + /** + * 获取translation + * + * @param view + * @param varargs + * @return + */ + public Varargs translation(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setTranslation(view, varargs); + } else { + return getTranslation(view, varargs); + } + } + + public Varargs setTranslation(U view, Varargs varargs) { + final float translationX = DimenUtil.dpiToPx(LuaUtil.getFloat(varargs, 2)); + final float translationY = DimenUtil.dpiToPx(LuaUtil.getFloat(varargs, 3)); + return view.setTranslation(translationX, translationY); + } + + public Varargs getTranslation(U view, Varargs varargs) { + return varargsOf(valueOf(DimenUtil.pxToDpi(view.getTranslationX())), valueOf(DimenUtil.pxToDpi(view.getTranslationY()))); + } + + /** + * 获取translationX + * + * @param view + * @param varargs + * @return + */ + public LuaValue translationX(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setTranslationX(view, varargs); + } else { + return getTranslationX(view, varargs); + } + } + + public LuaValue setTranslationX(U view, Varargs varargs) { + final float translationX = DimenUtil.dpiToPx(LuaUtil.getFloat(varargs, 2)); + return view.setTranslation(translationX, null); + } + + public LuaValue getTranslationX(U view, Varargs varargs) { + return valueOf(DimenUtil.pxToDpi(view.getTranslationX())); + } + + /** + * 获取translationX + * + * @param view + * @param varargs + * @return + */ + public LuaValue translationY(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setTranslationY(view, varargs); + } else { + return getTranslationY(view, varargs); + } + } + + public LuaValue setTranslationY(U view, Varargs varargs) { + final float translationY = DimenUtil.dpiToPx(LuaUtil.getFloat(varargs, 2)); + return view.setTranslation(null, translationY); + } + + public LuaValue getTranslationY(U view, Varargs varargs) { + return valueOf(DimenUtil.pxToDpi(view.getTranslationX())); + } + + + /** + * 将view设置到前台 + * + * @param view + * @param varargs + * @return + */ + @LuaViewApi(revisions = "iOS待新增") + public LuaValue bringToFront(U view, Varargs varargs) { + return view.bringToFront(); + } + + + /** + * 滚动到某个位置 + * + * @param view + * @param varargs + * @return + */ + @LuaViewApi(revisions = {"iOS无,待迁移到ScrollView"}) + public LuaValue scrollTo(U view, Varargs varargs) { + final int x = DimenUtil.dpiToPx(varargs.arg(2)); + final int y = DimenUtil.dpiToPx(varargs.arg(3)); + return view.scrollTo(x, y); + } + + /** + * 滚动一段距离 + * + * @param view + * @param varargs + * @return + */ + @LuaViewApi(revisions = {"iOS无,待迁移到ScrollView"}) + public LuaValue scrollBy(U view, Varargs varargs) { + final int dx = DimenUtil.dpiToPx(varargs.arg(2)); + final int dy = DimenUtil.dpiToPx(varargs.arg(3)); + return view.scrollBy(dx, dy); + } + + /** + * 滚动x + * + * @param view + * @param varargs + * @return + */ + @LuaViewApi(revisions = {"iOS无,待迁移到ScrollView"}) + public LuaValue scrollX(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setScrollX(view, varargs); + } else { + return getScrollX(view, varargs); + } + } + + public LuaValue setScrollX(U view, Varargs varargs) { + final int x = DimenUtil.dpiToPx(varargs.arg(2)); + final int y = (int) view.getY(); + return view.scrollTo(x, y); + } + + + public LuaValue getScrollX(U view, Varargs varargs) { + return valueOf(DimenUtil.pxToDpi(view.getScrollX())); + } + + /** + * 滚动x + * + * @param view + * @param varargs + * @return + */ + @LuaViewApi(revisions = {"iOS无,待迁移到ScrollView"}) + public LuaValue offsetX(U view, Varargs varargs) { + return scrollX(view, varargs); + } + + public LuaValue setOffsetX(U view, Varargs varargs) { + return setScrollX(view, varargs); + } + + public LuaValue getOffsetX(U view, Varargs varargs) { + return getScrollX(view, varargs); + } + + /** + * 滚动y + * + * @param view + * @param varargs + * @return + */ + @LuaViewApi(revisions = {"iOS无,待迁移到ScrollView"}) + public LuaValue scrollY(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setScrollY(view, varargs); + } else { + return getScrollY(view, varargs); + } + } + + public LuaValue setScrollY(U view, Varargs varargs) { + final int x = (int) view.getX(); + final int y = DimenUtil.dpiToPx(varargs.arg(2)); + return view.scrollTo(x, y); + } + + public LuaValue getScrollY(U view, Varargs varargs) { + return valueOf(DimenUtil.pxToDpi(view.getScrollY())); + } + + /** + * 滚动y + * + * @param view + * @param varargs + * @return + */ + @LuaViewApi(revisions = {"iOS无,待迁移到ScrollView"}) + public LuaValue offsetY(U view, Varargs varargs) { + return scrollY(view, varargs); + } + + public LuaValue setOffsetY(U view, Varargs varargs) { + return setScrollY(view, varargs); + } + + public LuaValue getOffsetY(U view, Varargs varargs) { + return getScrollY(view, varargs); + } + + /** + * 获取滚动的x,y + * + * @param view + * @param varargs + * @return + */ + @LuaViewApi(revisions = {"iOS无,待迁移到ScrollView"}) + public Varargs scrollXY(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setScrollXY(view, varargs); + } else { + return getScrollXY(view, varargs); + } + } + + public LuaValue setScrollXY(U view, Varargs varargs) { + final int x = DimenUtil.dpiToPx(varargs.arg(2)); + final int y = DimenUtil.dpiToPx(varargs.arg(3)); + return view.scrollTo(x, y); + } + + public Varargs getScrollXY(U view, Varargs varargs) { + return varargsOf(valueOf(DimenUtil.pxToDpi(view.getScrollX())), valueOf(DimenUtil.pxToDpi(view.getScrollY()))); + } + + /** + * 获取滚动的x,y + * + * @param view + * @param varargs + * @return + */ + @LuaViewApi(revisions = {"iOS无,待迁移到ScrollView"}) + public Varargs offsetXY(U view, Varargs varargs) { + return scrollXY(view, varargs); + } + + public Varargs setOffsetXY(U view, Varargs varargs) { + return setScrollXY(view, varargs); + } + + public Varargs getOffsetXY(U view, Varargs varargs) { + return getScrollXY(view, varargs); + } + + /** + * 滚动到某个位置 + * + * @param view + * @param varargs + * @return + */ + @LuaViewApi(revisions = {"iOS无,待迁移到ScrollView"}) + public Varargs offset(U view, Varargs varargs) { + return scrollXY(view, varargs); + } + + public LuaValue setOffset(U view, Varargs varargs) { + return setScrollXY(view, varargs); + } + + public Varargs getOffset(U view, Varargs varargs) { + return getScrollXY(view, varargs); + } + + + /** + * 设置滚动条是否显示(横向、纵向) + * + * @param view + * @param varargs + * @return + */ + @LuaViewApi(revisions = {"iOS无,待迁移到ScrollView"}) + public Varargs showScrollIndicator(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setShowScrollIndicator(view, varargs); + } else { + return isShowScrollIndicator(view, varargs); + } + } + + public LuaValue setShowScrollIndicator(U view, Varargs varargs) { + final boolean horizontalIndicator = varargs.optboolean(2, false); + final boolean verticalIndicator = varargs.optboolean(3, false); + view.setHorizontalScrollBarEnabled(horizontalIndicator); + view.setVerticalScrollBarEnabled(verticalIndicator); + return view; + } + + public Varargs isShowScrollIndicator(U view, Varargs varargs) { + return varargsOf(valueOf(view.isHorizontalScrollBarEnabled()), valueOf(view.isVerticalScrollBarEnabled())); + } + + + /** + * 设置回调 + * BeginEditing --开始编辑 + * EndEditing -- 结束编辑 + * Clear -- 删除 + * Return --返回 + * + * @param view + * @param varargs + * @return + */ + public LuaValue callback(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setCallback(view, varargs); + } else { + return getCallback(view, varargs); + } + } + + public LuaValue setCallback(U view, Varargs varargs) { + final LuaValue callbacks = varargs.optvalue(2, NIL); + return view.setCallback(callbacks); + } + + public LuaValue getCallback(U view, Varargs varargs) { + return view.getCallback(); + } + + /** + * 点击 + * + * @param view + * @param varargs + * @return + */ + public LuaValue onClick(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setOnClick(view, varargs); + } else { + return getOnClick(view, varargs); + } + } + + public LuaValue setOnClick(U view, Varargs varargs) { + final LuaFunction callback = LuaUtil.getFunction(varargs, 2); + return view.setOnClickCallback(callback); + } + + public LuaValue getOnClick(U view, Varargs varargs) { + return view.getOnClickCallback(); + } + + /** + * 长按 + * + * @param view + * @param varargs + * @return + */ + public LuaValue onLongClick(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setOnLongClick(view, varargs); + } else { + return getOnLongClick(view, varargs); + } + } + + public LuaValue setOnLongClick(U view, Varargs varargs) { + final LuaFunction callback = LuaUtil.getFunction(varargs, 2); + return view.setOnLongClickCallback(callback); + } + + public LuaValue getOnLongClick(U view, Varargs varargs) { + return view.getOnLongClickCallback(); + } + + /** + * On Touch 事件 + * + * @param view + * @param varargs + * @return + */ + @LuaViewApi(since = VmVersion.V_550) + public LuaValue onTouch(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setOnTouch(view, varargs); + } else { + return getOnTouch(view, varargs); + } + } + + public LuaValue setOnTouch(U view, Varargs varargs) { + final LuaFunction callback = LuaUtil.getFunction(varargs, 2); + return view.setOnTouchCallback(callback); + } + + public LuaValue getOnTouch(U view, Varargs varargs) { + return view.getOnTouchCallback(); + } + + + @LuaViewApi(since = SdkVersion.V_051) + public LuaValue matrix(U view, Varargs varargs) { + if (varargs.narg() > 1) { + if (varargs.istable(2)) { + LuaTable table = LuaUtil.getTable(varargs, 2); + int n = table.length(); + if (n > 9) { + float[] values = new float[9]; + for (int i = 0; i < 9; i++) { + values[i] = LuaUtil.getFloat(table, 0F, i + 2); + } + return view.setMatrix(values); + } else if (n > 6){ + float[] values = new float[9]; + for (int i = 0; i < 6; i++) { + values[i] = LuaUtil.getFloat(table, 0F, i + 2); + } + values[6] = 0; + values[7] = 0; + values[8] = 1; + return view.setMatrix(values); + + } + } else { + int n = varargs.narg(); + if (n > 9) { + float[] values = new float[9]; + for (int i = 0; i < 9; i++) { + values[i] = LuaUtil.getFloat(varargs, 0F, i + 2); + } + return view.setMatrix(values); + } else if (n > 6){ + float[] values = new float[9]; + for (int i = 0; i < 6; i++) { + values[i] = LuaUtil.getFloat(varargs, 0F, i + 2); + } + values[6] = 0; + values[7] = 0; + values[8] = 1; + return view.setMatrix(values); + } + } + } else { + float[] values = view.getMatrix(); + if (values != null) { + LuaTable table = new LuaTable(); + for (int i = 0; i < 6; i++) { + table.set(i + 1, valueOf(values[i])); + } + return table; + } + } + return view; + } + + /** + * 调整大小以适应内容 + * + * @return + */ + @LuaViewApi(revisions = {"待沟通,是否需要"}) + public LuaValue adjustSize(U view, Varargs varargs) { + return view.adjustSize(); + } + + + /** + * 设置边框圆角半径 + * + * @param view + * @param varargs + * @return + */ + public LuaValue cornerRadius(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setCornerRadius(view, varargs); + } else { + return getCornerRadius(view, varargs); + } + } + + public LuaValue setCornerRadius(U view, Varargs varargs) { + final int radius = DimenUtil.dpiToPx(varargs.arg(2)); + return view.setCornerRadius(radius); + } + + public LuaValue getCornerRadius(U view, Varargs varargs) { + return valueOf(DimenUtil.pxToDpi(view.getCornerRadius())); + } + + /** + * 开始动画 + * + * @param view + * @param varargs + * @return + */ + @LuaViewApi(revisions = {"待废弃"}) + public LuaValue startAnimation(U view, Varargs varargs) { + LuaValue[] animators = null; + if (varargs.narg() > 1) { + animators = new LuaValue[varargs.narg() - 1]; + for (int i = 2; i <= varargs.narg(); i++) { + animators[i - 2] = varargs.arg(i); + } + } + return view.startAnimation(animators); + } + + @LuaViewApi(revisions = {VmVersion.V_500, "修改了底层的停止API", "待废弃"}) + public LuaValue stopAnimation(U view, Varargs varargs) { + view.cancelAnimation(); + return view; + } + + @LuaViewApi(revisions = {"待废弃"}) + public LuaValue isAnimating(U view, Varargs varargs) { + return valueOf(view.isAnimating()); + } + + /** + * 设置flex css属性 + * + * @param view + * @param varargs + * @return + */ + @LuaViewApi(since = VmVersion.V_500) + public LuaValue flexCss(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setFlexCss(view, varargs); + } else { + return getFlexCss(view, varargs); + } + } + + @LuaViewApi(since = VmVersion.V_500) + public LuaValue setFlexCss(U view, Varargs varargs) { + final String css = LuaUtil.getString(varargs, 2); + return view.setFlexCss(css); + } + + @LuaViewApi(since = VmVersion.V_500) + public LuaValue getFlexCss(U view, Varargs varargs) { + return valueOf(view.getFlexCss()); + } + + /** + * 设置flex layout + * + * @param view + * @param varargs + * @return + */ + @LuaViewApi(since = VmVersion.V_500, revisions = {"iOS有,待沟通"}) + public LuaValue flxLayout(U view, Varargs varargs) { + // Android doing nothing here + return view; + } + + + /** + * 设置View的特殊效果,如果为-1,则取消所有view的特效 + * + * @param view + * @param varargs + * @return + */ + @LuaViewApi(since = VmVersion.V_511) + public LuaValue effects(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setEffects(view, varargs); + } else { + return getEffects(view, varargs); + } + } + + @LuaViewApi(since = VmVersion.V_511) + public LuaValue setEffects(U view, Varargs varargs) { + return view.setEffects(varargs); + } + + @LuaViewApi(since = VmVersion.V_511) + public LuaValue getEffects(U view, Varargs varargs) { + return valueOf(view.getEffects()); + } + + + /** + * 获取native view + * + * @param customPanel + * @param varargs + * @return + */ + @LuaViewApi(since = VmVersion.V_511, revisions = {"从UICustomPanelMethodMapper移过来(V500)"}) + public LuaValue nativeView(U customPanel, Varargs varargs) { + return getNativeView(customPanel, varargs); + } + + @LuaViewApi(since = VmVersion.V_511, revisions = {"从UICustomPanelMethodMapper移过来(V500)"}) + public LuaValue getNativeView(U customPanel, Varargs varargs) { + return customPanel.getNativeView(); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/ui/UIViewPagerMethodMapper.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/ui/UIViewPagerMethodMapper.java new file mode 100644 index 00000000..351eb380 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/ui/UIViewPagerMethodMapper.java @@ -0,0 +1,209 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.mapper.ui; + +import com.taobao.luaview.fun.mapper.LuaViewApi; +import com.taobao.luaview.fun.mapper.LuaViewLib; +import com.taobao.luaview.global.VmVersion; +import com.taobao.luaview.userdata.ui.UDViewPager; +import com.taobao.luaview.util.LuaUtil; +import com.taobao.luaview.view.viewpager.AutoScrollViewPager; + +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; + +import java.util.List; + +@LuaViewLib(revisions = {"20170306已对标"}) +public class UIViewPagerMethodMapper extends UIViewGroupMethodMapper { + + private static final String TAG = "UIViewPagerMethodMapper"; + private static final String[] sMethods = new String[]{ + "reload",//0 + "indicator",//1 + "currentPage",//2 + "currentItem",//3 + "autoScroll",//4 + "looping",//5 + "previewSide"//6 + }; + + @Override + public List getAllFunctionNames() { + return mergeFunctionNames(TAG, super.getAllFunctionNames(), sMethods); + } + + @Override + public Varargs invoke(int code, U target, Varargs varargs) { + final int optcode = code - super.getAllFunctionNames().size(); + switch (optcode) { + case 0: + return reload(target, varargs); + case 1: + return indicator(target, varargs); + case 2: + return currentPage(target, varargs); + case 3: + return currentItem(target, varargs); + case 4: + return autoScroll(target, varargs); + case 5: + return looping(target, varargs); + case 6: + return previewSide(target, varargs); + } + return super.invoke(code, target, varargs); + } + + //--------------------------------------- API -------------------------------------------------- + + /** + * 支持左右透出预览 + * @param view + * @param varargs + * @return + */ + @LuaViewApi(since = VmVersion.V_570) + public LuaValue previewSide(U view, Varargs varargs) { + Integer left = LuaUtil.getInt(varargs, 2); + Integer right = LuaUtil.getInt(varargs, 3); + return view.previewSide(left, right); + } + + /** + * 重新更新数据 + * + * @param view + * @param varargs + * @return + */ + public LuaValue reload(U view, Varargs varargs) { + return view.reload(); + } + + + /** + * 指示器 + * + * @param view + * @param varargs + * @return + */ + public LuaValue indicator(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setIndicator(view, varargs); + } else { + return getIndicator(view, varargs); + } + } + + public LuaValue setIndicator(U view, Varargs varargs) { + final LuaValue indicator = varargs.arg(2); + return view.setViewPagerIndicator(indicator); + } + + public LuaValue getIndicator(U view, Varargs varargs) { + return view.getViewPagerIndicator(); + } + + + /** + * 设置第几页面 + * + * @param view + * @param varargs + * @return + */ + public LuaValue currentPage(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setCurrentPage(view, varargs); + } else { + return getCurrentPage(view, varargs); + } + } + + public LuaValue setCurrentPage(U view, Varargs varargs) { + return setCurrentItem(view, varargs); + } + + public LuaValue getCurrentPage(U view, Varargs varargs) { + return getCurrentItem(view, varargs); + } + + /** + * 当前是第几页 + * + * @param view + * @param varargs + * @return + */ + @Deprecated + public LuaValue currentItem(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setCurrentItem(view, varargs); + } else { + return getCurrentItem(view, varargs); + } + } + + public LuaValue setCurrentItem(U view, Varargs varargs) { + final int currentItem = LuaUtil.toJavaInt(varargs.arg(2)); + final boolean smoothScroll = varargs.optboolean(3, true); + return view.setCurrentItem(currentItem, smoothScroll); + } + + public LuaValue getCurrentItem(U view, Varargs varargs) { + return LuaUtil.toLuaInt(view.getCurrentItem()); + } + + /** + * 自动滚动 + */ + @LuaViewApi(since = VmVersion.V_501) + public LuaValue autoScroll(U view, Varargs varargs) { + Integer duration = LuaUtil.getInt(varargs, 2); + duration = duration != null ? duration * 1000 : AutoScrollViewPager.DEFAULT_INTERVAL; + final boolean reverseDirection = LuaUtil.getBoolean(varargs, false, 3); + return view.setAutoScroll(duration, reverseDirection); + } + + /** + * 是否循环滚动 + * + * @param view + * @param varargs + * @return + */ + @LuaViewApi(since = VmVersion.V_501) + public LuaValue looping(U view, Varargs varargs) { + if (varargs.narg() > 1) { + return setLooping(view, varargs); + } else { + return isLooping(view, varargs); + } + } + + @LuaViewApi(since = VmVersion.V_501) + public LuaValue setLooping(U view, Varargs varargs) { + final boolean looping = LuaUtil.getBoolean(varargs, false, 2); + return view.setLooping(looping); + } + + @LuaViewApi(since = VmVersion.V_501) + public LuaValue isLooping(U view, Varargs varargs) { + return valueOf(view.isLooping()); + } + + @Override + public Varargs initParams(U view, Varargs varargs) { + Varargs ret = super.initParams(view, varargs); + this.reload(view, varargs); + return ret; + } +} \ No newline at end of file diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/ui/UIWebViewMethodMapper.java b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/ui/UIWebViewMethodMapper.java new file mode 100644 index 00000000..74dc8f7f --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/fun/mapper/ui/UIWebViewMethodMapper.java @@ -0,0 +1,140 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.fun.mapper.ui; + +import com.taobao.luaview.fun.mapper.LuaViewApi; +import com.taobao.luaview.fun.mapper.LuaViewLib; +import com.taobao.luaview.global.VmVersion; +import com.taobao.luaview.userdata.ui.UDWebView; +import com.taobao.luaview.util.LuaUtil; + +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; + +import java.util.List; + +/** + * Created by tuoli on 10/9/16. + */ +@LuaViewLib(revisions = {"20170306已对标"}) +public class UIWebViewMethodMapper extends UIViewMethodMapper { + + private static final String TAG = "UIWebViewMethodMapper"; + private static final String[] sMethods = new String[]{ + "loadUrl", //0 + "canGoBack", // 1 + "canGoForward", //2 + "goBack", //3 + "goForward",//4 + "reload",//5 + "title",//6 + "isLoading",//7 + "stopLoading",//8 + "url",//9 + "pullRefreshEnable"//10 + }; + + @Override + public List getAllFunctionNames() { + return mergeFunctionNames(TAG, super.getAllFunctionNames(), sMethods); + } + + @Override + public Varargs invoke(int code, U target, Varargs varargs) { + final int optcode = code - super.getAllFunctionNames().size(); + switch (optcode) { + case 0: + return loadUrl(target, varargs); + case 1: + return canGoBack(target, varargs); + case 2: + return canGoForward(target, varargs); + case 3: + return goBack(target, varargs); + case 4: + return goForward(target, varargs); + case 5: + return reload(target, varargs); + case 6: + return title(target, varargs); + case 7: + return isLoading(target, varargs); + case 8: + return stopLoading(target, varargs); + case 9: + return url(target, varargs); + case 10: + return pullRefreshEnable(target, varargs); + } + return super.invoke(code, target, varargs); + } + + //--------------------------------------- API -------------------------------------------------- + // 使用反射的方式调用的时候,需要public关键字声明 + + @LuaViewApi(since = VmVersion.V_530) + public LuaValue loadUrl(U view, Varargs varargs) { + return view.loadUrl(LuaUtil.getString(varargs, 2)); + } + + @LuaViewApi(since = VmVersion.V_530) + public LuaValue canGoBack(U view, Varargs varargs) { + return valueOf(view.canGoBack()); + } + + @LuaViewApi(since = VmVersion.V_530) + public LuaValue canGoForward(U view, Varargs varargs) { + return valueOf(view.canGoForward()); + } + + @LuaViewApi(since = VmVersion.V_530) + public LuaValue goBack(U view, Varargs varargs) { + return view.goBack(); + } + + @LuaViewApi(since = VmVersion.V_530) + public LuaValue goForward(U view, Varargs varargs) { + return view.goForward(); + } + + @LuaViewApi(since = VmVersion.V_530) + public LuaValue reload(U view, Varargs varargs) { + return view.reload(); + } + + @LuaViewApi(since = VmVersion.V_530) + public LuaValue title(U view, Varargs varargs) { + return valueOf(view.title()); + } + + @LuaViewApi(since = VmVersion.V_530) + public LuaValue isLoading(U view, Varargs varargs) { + return valueOf(view.isLoading()); + } + + @LuaViewApi(since = VmVersion.V_530) + public LuaValue stopLoading(U view, Varargs varargs) { + return view.stopLoading(); + } + + @LuaViewApi(since = VmVersion.V_530) + public LuaValue url(U view, Varargs varargs) { + return valueOf(view.url()); + } + + @LuaViewApi(since = VmVersion.V_530) + public LuaValue pullRefreshEnable(U view, Varargs varargs) { + if (varargs.narg() > 1) { + final boolean enable = LuaUtil.getBoolean(varargs, 2); + return view.pullRefreshEnable(enable); + } else { + return valueOf(view.isPullRefreshEnable()); + } + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/global/Constants.java b/Android/LuaViewSDK/src/com/taobao/luaview/global/Constants.java new file mode 100644 index 00000000..5e6809cb --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/global/Constants.java @@ -0,0 +1,46 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ +package com.taobao.luaview.global; + +import android.content.Context; + +import com.taobao.android.luaview.R; +import com.taobao.luaview.util.AndroidUtil; + + +/** + * 常量类 + * + * @author song + * @date 15/10/26 + */ +public class Constants { + public static float sScale = -1; + public static final String PARAM_URI = "uri"; + public static final String PAGE_PARAMS = "page_params"; + + // asset file prefix for loading luaview.load(ASSET_FILE_PREFIX + "foler/name") + public static final String ASSET_FILE_PREFIX = "file:///android_asset/"; + + //Bundle encrypt and decrypt + public static final String PUBLIC_KEY_PATH = "luaview/luaview_rsa_public_key.der"; + public static final String PUBLIC_KEY_PATH_MD5 = "luaview/luaview_rsa_public_key.der-md5"; + public static final String PUBLIC_KEY_PATH_PK = "luaview/luaview_rsa_public_key.der-pk"; + public static final String PUBLIC_KEY_PATH_CIPHER = "luaview/luaview_rsa_public_key.der-cipher"; + + //resources tag + public static final int RES_LV_TAG_URL = R.id.lv_tag_url; + public static final int RES_LV_TAG = R.id.lv_tag; + public static final int RES_LV_TAG_POSITION = R.id.lv_tag_position; + public static final int RES_LV_TAG_PINNED = R.id.lv_tag_pinned; + public static final int RES_LV_TAG_INIT = R.id.lv_tag_init; + + public static void init(Context context) { + sScale = AndroidUtil.getDensity(context); + } +} \ No newline at end of file diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/global/LuaResourceFinder.java b/Android/LuaViewSDK/src/com/taobao/luaview/global/LuaResourceFinder.java new file mode 100644 index 00000000..a4cb049b --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/global/LuaResourceFinder.java @@ -0,0 +1,479 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.global; + +import android.content.Context; +import android.content.res.AssetManager; +import android.graphics.Typeface; +import android.graphics.drawable.Drawable; +import android.text.TextUtils; + +import com.taobao.luaview.scriptbundle.LuaScriptManager; +import com.taobao.luaview.scriptbundle.ScriptBundle; +import com.taobao.luaview.scriptbundle.ScriptFile; +import com.taobao.luaview.scriptbundle.asynctask.ScriptBundleLoadTask; +import com.taobao.luaview.scriptbundle.asynctask.SimpleTask1; +import com.taobao.luaview.scriptbundle.asynctask.delegate.ScriptBundleLoadDelegate; +import com.taobao.luaview.util.AssetUtil; +import com.taobao.luaview.util.DrawableUtil; +import com.taobao.luaview.util.FileUtil; +import com.taobao.luaview.util.IOUtil; +import com.taobao.luaview.util.LogUtil; +import com.taobao.luaview.util.ParamUtil; +import com.taobao.luaview.util.TypefaceUtil; +import com.taobao.luaview.view.imageview.BaseImageView; + +import org.luaj.vm2.lib.ResourceFinder; + +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; + +/** + * 给定相对路径,找对应的资源(脚本、图片、字体等) + * + * @author song + * @date 16/1/5 + */ +public class LuaResourceFinder implements ResourceFinder { + public static final String DEFAULT_MAIN_ENTRY = "main.lua";//默认的脚本入口,在加载folder或者bundle的时候会默认加载该名称的脚本 + private static final String FILE_PATH_ANDROID_ASSET = "file:///android_asset/"; + + private Context mContext; + + //内存脚本 + private ScriptBundle mScriptBundle; + + //加载的uri(可以是url,也可以是包名称) + private String mUri; + + //基础scriptPath + private String mBaseScriptFolderPath;//默认cache目录 + private String mBaseBundlePath;//Bundle文件系统路径 + private String mBaseAssetPath;//asset下路径 + + //callback for drawable finder + public interface DrawableFindCallback { + public void onStart(String urlOrPath); + + public void onFinish(Drawable result); + } + + public LuaResourceFinder(Context context) { + if (context != null) { + this.mContext = context.getApplicationContext(); + } + } + + public void setScriptBundle(ScriptBundle scriptBundle) { + mScriptBundle = scriptBundle; + } + + public void setUri(String uri) { + mUri = uri; + mBaseScriptFolderPath = LuaScriptManager.getBaseScriptFolderPath(); + mBaseBundlePath = LuaScriptManager.buildScriptBundleFolderPath(uri); + mBaseAssetPath = FileUtil.getAssetFolderPath(uri);//脚本默认放在asset目录下 + } + + public String getUri() { + return mUri; + } + + public String getBaseBundlePath() { + return mBaseBundlePath; + } + + /** + * find Script in given name or path + * + * @param nameOrPath + * @return + */ + @Override + public InputStream findResource(final String nameOrPath) { + if (mScriptBundle != null && mScriptBundle.containsKey(nameOrPath)) {//from cache, 这里直接使用文件名称来处理 + LogUtil.d("[findResource-ScriptBundle]", nameOrPath); + final ScriptFile scriptFile = mScriptBundle.getScriptFile(nameOrPath); + return scriptFile.getInputStream(); + } + + if (LuaScriptManager.isLuaEncryptScript(nameOrPath)) {//.lv TODO 这里需要去掉,不再有本地lv文件 + return ScriptBundleLoadDelegate.loadEncryptScript(mContext, findFile(nameOrPath)); + } else {//.lua 或者 输入folder名字(其实是lvbundle的名字,如ppt440), 则加载 main.lua + final String newName = LuaScriptManager.isLuaScript(nameOrPath) ? nameOrPath : DEFAULT_MAIN_ENTRY;//如果是脚本则加载,否则加载main.lua + InputStream inputStream = ScriptBundleLoadDelegate.loadEncryptScript(mContext, findFile(LuaScriptManager.changeSuffix(newName, LuaScriptManager.POSTFIX_LV))); + if (inputStream == null) {//如果.lv不存在,则尝试读取.lua + inputStream = findFile(newName); + } + return inputStream; + } + } + + /** + * find drawable async + * + * @param nameOrPath + * @param callback + */ + public void findDrawable(final String nameOrPath, final DrawableFindCallback callback) { + new SimpleTask1() { + @Override + protected void onPreExecute() { + super.onPreExecute(); + if (callback != null) { + callback.onStart(nameOrPath); + } + } + + @Override + protected Drawable doInBackground(Object... params) { + return findDrawable(nameOrPath); + } + + @Override + protected void onPostExecute(Drawable drawable) { + super.onPostExecute(drawable); + if (callback != null) { + callback.onFinish(drawable); + } + } + }.executeInPool(); + } + + /** + * find drawable async + * + * @param imageView + * @param nameOrPath + */ + public void findDrawable(final BaseImageView imageView, final String nameOrPath) { + new SimpleTask1() { + @Override + protected void onPreExecute() { + super.onPreExecute(); + if (imageView != null && nameOrPath != null) { + imageView.setTag(Constants.RES_LV_TAG_URL, nameOrPath); + } + } + + @Override + protected Drawable doInBackground(Object... params) { + return findDrawable(nameOrPath); + } + + @Override + protected void onPostExecute(Drawable drawable) { + super.onPostExecute(drawable); + if (imageView != null && nameOrPath != null && nameOrPath.equals(imageView.getTag(Constants.RES_LV_TAG_URL))) { + imageView.setImageDrawable(drawable); + } + } + }.executeInPool(); + } + + /** + * 在 res 或者 asset 或者 文件系统 找drawable + * TODO 异步 + * + * @param nameOrPath + * @return + */ + public Drawable findDrawable(final String nameOrPath) { + Drawable drawable = null; + if (!TextUtils.isEmpty(nameOrPath)) { + final String drawableName = FileUtil.hasPostfix(nameOrPath) ? nameOrPath : ParamUtil.getFileNameWithPostfix(nameOrPath, "png");//如果没有后缀,则处理成.png + + String filepath = buildPathInSdcardIfExists(drawableName); + if (filepath != null) {//从filepath加载 + drawable = DrawableUtil.getByPath(filepath); + } + + if (drawable == null) {//从asset加载 + filepath = buildPathInAssetsIfExists(drawableName); + if (filepath != null) { + drawable = DrawableUtil.getAssetByPath(mContext, drawableName); + } + } + + if (drawable == null) {//直接使用name加载 + drawable = DrawableUtil.getByName(mContext, nameOrPath); + } + } + return drawable; + } + + /** + * 在 asset 或者 文件系统 找字体文件 + * TODO 优化 + * + * @param nameOrPath + * @return + */ + public Typeface findTypeface(final String nameOrPath) { + Typeface typeface = null; + if (!TextUtils.isEmpty(nameOrPath)) { + final String typefaceNameOrPath = FileUtil.hasPostfix(nameOrPath) ? nameOrPath : ParamUtil.getFileNameWithPostfix(nameOrPath, "ttf");//如果没有后缀,则处理成.ttf + String filepath = buildPathInSdcardIfExists(typefaceNameOrPath); + + if (filepath != null) {//从文件系统加载 + typeface = TypefaceUtil.create(filepath); + } + + if (typeface == null) {//从asset下加载 + filepath = buildPathInAssetsIfExists(typefaceNameOrPath); + if (filepath != null) { + typeface = TypefaceUtil.create(mContext, filepath); + } + } + + if (typeface == null) {//default name + typeface = TypefaceUtil.create(mContext, nameOrPath); + } + } + return typeface != null ? typeface : Typeface.DEFAULT; + } + + + /** + * 在 文件系统 或者 asset下 找资源 + * TODO 异步 + * + * @param nameOrPath + * @return + */ + public InputStream findFile(final String nameOrPath) { + InputStream inputStream = null; + + if (!TextUtils.isEmpty(nameOrPath)) { + String filepath = buildPathInSdcardIfExists(nameOrPath); + if (filepath != null) {//从文件系统加载 + inputStream = FileUtil.open(filepath); + } + + if (inputStream == null) {//从asset下加载 + filepath = buildPathInAssetsIfExists(nameOrPath); + if (filepath != null) { + inputStream = AssetUtil.open(mContext, filepath); + } + } + + if(inputStream == null){//直接使用name加载 + inputStream = AssetUtil.open(mContext, nameOrPath); + } + } + return inputStream; + } + + /** + * exists + * + * @param nameOrPath + * @return + */ + public boolean exists(final String nameOrPath) { + if (!TextUtils.isEmpty(nameOrPath)) { + String fullPath = buildSecurePathInSdcard(nameOrPath); + if (fullPath != null) {//文件 + return FileUtil.exists(fullPath); + } else { + fullPath = buildSecurePathInAssets(nameOrPath); + return AssetUtil.exists(mContext, fullPath); + } + } + return false; + } + + /** + * 获取文件的完整路径 + * + * @param nameOrPath + * @return + */ + public String buildFullPathInBundleOrAssets(final String nameOrPath) { + if (!TextUtils.isEmpty(nameOrPath)) { + String fullPath = buildPathInBundleFolder(nameOrPath); + if (!FileUtil.exists(fullPath)) { + fullPath = buildPathInAssets(nameOrPath); + } + return fullPath; + } + return null; + } + + /** + * 找文件在SD卡的路径,如果存在在获取 + * + * @param nameOrPath + * @return + */ + private String buildPathInSdcardIfExists(final String nameOrPath) { + String filepath = buildPathInBundleFolder(nameOrPath); + if (FileUtil.exists(filepath)) {//check bundle folder + return filepath; + } + + if (filepath == null) {//check script folder + filepath = buildPathInRootFolder(nameOrPath); + if (FileUtil.exists(filepath)) { + return filepath; + } + } + return null; + } + + /** + * 获取安全路径(不一定在bundle下面,但必须在script目录下) + * + * @param nameOrPath + * @return + */ + public String buildSecurePathInSdcard(final String nameOrPath) {//主要用在文件操作 + String path = buildPathInBundleFolder(nameOrPath); + if (path != null) {//处理../../../ TODO 这里如何应对全局路径 + final String canonicalPath = FileUtil.getCanonicalPath(path); + if (canonicalPath != null && canonicalPath.startsWith(mBaseScriptFolderPath)) { + return path; + } else { + LogUtil.e("[LuaView-Error buildSecurePathInSdcard error]", nameOrPath, "must in folder", mBaseScriptFolderPath); + return null; + } + } + return null; + } + + /** + * build file path + * + * @param nameOrPath + * @return + */ + public String buildPathInBundleFolder(final String nameOrPath) { + String result = null; + + if(nameOrPath != null && nameOrPath.startsWith("/")){//如果反斜杠开头,则直接返回,TODO 待优化 + return nameOrPath; + } + + if (!TextUtils.isEmpty(mBaseBundlePath)) { + if (!FileUtil.isContainsFolderPath(nameOrPath, mBaseBundlePath)) {//不带基础路径的情况 + final String filePath = FileUtil.buildPath(mBaseBundlePath, nameOrPath); + LogUtil.d("[buildPathInBundleFolder-FileSystem]", filePath); + result = filePath; + } else { + LogUtil.d("[buildPathInBundleFolder-FileSystem]", nameOrPath); + result = nameOrPath; + } + } + return result; + } + + /** + * build file path + * + * @param nameOrPath + * @return + */ + public String buildPathInRootFolder(final String nameOrPath) { + String result = null; + + if(nameOrPath != null && nameOrPath.startsWith("/")){//如果反斜杠开头,则直接返回,TODO 待优化 + return nameOrPath; + } + + if (!TextUtils.isEmpty(mBaseScriptFolderPath)) { + if (!FileUtil.isContainsFolderPath(nameOrPath, mBaseScriptFolderPath)) {//不带基础路径的情况 + final String filePath = FileUtil.buildPath(mBaseScriptFolderPath, nameOrPath); + LogUtil.d("[buildPathInBundleFolder-FileSystem]", filePath); + result = filePath; + } else { + LogUtil.d("[buildPathInBundleFolder-FileSystem]", nameOrPath); + result = nameOrPath; + } + } + return result; + } + + + /** + * 获取安全路径 + * + * @param nameOrPath + * @return + */ + public String buildSecurePathInAssets(final String nameOrPath) {//主要用在文件操作 + String path = buildPathInAssets(nameOrPath); + if (path != null) {//处理../../../ + final String canonicalPath = FileUtil.getCanonicalPath(path); + return canonicalPath != null && canonicalPath.startsWith(mBaseAssetPath) ? path : null; + } + return null; + } + + /** + * build path in assets + * + * @param nameOrPath + * @return + */ + private String buildPathInAssetsIfExists(final String nameOrPath) { + String filepath = buildPathInAssets(nameOrPath); + if (AssetUtil.exists(mContext, filepath)) { + return filepath; + } else if (AssetUtil.exists(mContext, nameOrPath)) { + return nameOrPath; + } + return null; + } + + /** + * 找文件在asset下的路径 + * + * @param nameOrPath + * @return + */ + private String buildPathInAssets(final String nameOrPath) { + String result = null; + + if(nameOrPath != null && nameOrPath.startsWith("/")){//如果反斜杠开头,则直接返回,TODO 待优化 + return nameOrPath; + } + + if (!TextUtils.isEmpty(mBaseAssetPath) && !FileUtil.isContainsFolderPath(nameOrPath, mBaseAssetPath)) {//不带基础路径,或者不在asset下 + final String assetFilePath = FileUtil.buildPath(mBaseAssetPath, nameOrPath); + LogUtil.d("[buildPathInAssets-Assets]", assetFilePath); + result = assetFilePath; + } else { + LogUtil.d("[buildPathInAssets-Assets]", nameOrPath); + result = nameOrPath; + } + return result; + } + + public byte[] readFromAssets(String name) { + AssetManager assetManager = this.mContext.getAssets(); + InputStream inputStream = null; + try { + inputStream = assetManager.open(name); + return IOUtil.toBytes(inputStream); + } catch (IOException e) { + e.printStackTrace(); + } finally { + try { + if (inputStream != null) { + inputStream.close(); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + return null; + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/global/LuaScriptLoader.java b/Android/LuaViewSDK/src/com/taobao/luaview/global/LuaScriptLoader.java new file mode 100644 index 00000000..6ebd24ea --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/global/LuaScriptLoader.java @@ -0,0 +1,186 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.global; + +import android.content.Context; +import android.text.TextUtils; + +import com.taobao.luaview.scriptbundle.LuaScriptManager; +import com.taobao.luaview.scriptbundle.ScriptBundle; +import com.taobao.luaview.scriptbundle.asynctask.ScriptBundleDownloadTask; +import com.taobao.luaview.scriptbundle.asynctask.ScriptBundleUltimateLoadTask; +import com.taobao.luaview.scriptbundle.asynctask.SimpleTask1; +import com.taobao.luaview.scriptbundle.asynctask.delegate.ScriptBundleUnpackDelegate; +import com.taobao.luaview.util.FileUtil; + +import org.luaj.vm2.LuaValue; + +/** + * script loader + * + * @author song + * @date 15/11/10 + */ +public class LuaScriptLoader { + + /** + * Lua脚本加载事件 + */ + public enum LuaScriptLoadEvent { + EVENT_DOWNLOAD_START, + EVENT_DOWNLOAD_END, + EVENT_LOAD_CACHE, + EVENT_LOAD_LOCAL, + EVENT_LOAD_PREDOWNLOAD, + EVENT_LOAD_ASSET + } + + + private Context mContext; + + public LuaScriptLoader(final Context context) { + if (context != null) { + try { + this.mContext = context.getApplicationContext(); + } catch (Exception e) { + e.printStackTrace(); + } + } + LuaScriptManager.init(context); + } + + public interface ScriptLoaderCallback { + void onScriptLoaded(final ScriptBundle bundle);//脚本加载 + } + + public interface ScriptLoaderCallback2 extends ScriptLoaderCallback { + void onEvent(LuaScriptLoadEvent event, Object params); + } + + /** + * 脚本运行回调 + */ + public interface ScriptExecuteCallback { + /** + * 脚本准备完毕, 返回true,表示需要自己处理执行,onScriptCompiled,onScriptExecuted不会被执行,返回false表示系统继续执行 + * + * @param bundle + * @return + */ + boolean onScriptPrepared(ScriptBundle bundle); + + /** + * 脚本编译完成,参数表示编译之后的结果,不保证一定被调用到 + * 返回true,表示需要自己处理执行,返回false,表示系统继续执行 + * + * @param value + */ + boolean onScriptCompiled(LuaValue value, LuaValue context, LuaValue view); + + /** + * 脚本执行完成,参数表示是否执行成功,保证一定被调用到 + * + * @param uri 原始的加载url + * @param executedSuccess + */ + void onScriptExecuted(String uri, boolean executedSuccess); + } + + /** + * 脚本运行回调 + */ + public interface ScriptExecuteCallback2 extends ScriptExecuteCallback { + + /** + * @param event + * @param params + */ + void onEvent(LuaScriptLoadEvent event, Object params); + } + + //-----------------------------------------static methods--------------------------------------- + + /** + * 将asset目录下所有bundle包解压缩出来,一般在初始化的时候调用 + * + * @param basePath + */ + public void unpackAllAssetBundle(final String basePath) { + if (basePath != null) { + ScriptBundleUnpackDelegate.unpackAllAssetScripts(mContext, basePath); + } + } + + /** + * clear invalid bundle of given url + * TODO 在脚本加载失败的时候调用清理函数 + * + * @param url + */ + public static void clearInvalidBundle(final String url) { + if (!TextUtils.isEmpty(url)) { + new SimpleTask1() { + @Override + protected Void doInBackground(Object... params) { + String folderPath = LuaScriptManager.buildScriptBundleFolderPath(url); + FileUtil.delete(folderPath); + return null; + } + }.executeInPool(); + } + } + + //--------------------------------lua script get and decode------------------------------------- + + /** + * fetch a script from network (if needed) or from local file system + * + * @param url + * @param callback + */ + public void load(final String url, final ScriptLoaderCallback callback) { + load(url, null, callback); + } + + /** + * fetch a script from network (if needed) or from local file system + * + * @param url + * @param sha256 + * @param callback + */ + public void load(final String url, final String sha256, final ScriptLoaderCallback callback) { + new ScriptBundleUltimateLoadTask(mContext, callback).load(url, sha256); + } + + + //--------------------------------preload script------------------------------------------------ + + /** + * preload script + * + * @param url + * @param sha256 + */ + public void preload(final String url, final String sha256) { + new ScriptBundleUltimateLoadTask(mContext, null).load(url, sha256); + } + + /** + * download script + * + * @param url + * @param sha256 + */ + public void download(final String url, final String sha256) { + if (!LuaScriptManager.existsScriptBundle(url)) {//load local + new ScriptBundleDownloadTask(mContext, null).executeInPool(url, sha256); + } + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/global/LuaView.java b/Android/LuaViewSDK/src/com/taobao/luaview/global/LuaView.java new file mode 100644 index 00000000..4fa52744 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/global/LuaView.java @@ -0,0 +1,533 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.global; + +import android.content.Context; +import android.view.ViewGroup; + +import com.taobao.luaview.fun.mapper.ui.UIViewGroupMethodMapper; +import com.taobao.luaview.provider.ImageProvider; +import com.taobao.luaview.scriptbundle.ScriptBundle; +import com.taobao.luaview.scriptbundle.ScriptFile; +import com.taobao.luaview.userdata.ui.UDView; +import com.taobao.luaview.util.LuaUtil; +import com.taobao.luaview.view.LVCustomPanel; +import com.taobao.luaview.view.LVViewGroup; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaTable; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; + +import java.io.InputStream; + +/** + * LuaView 实现类 + * + * @author song + * @date 15/8/20 + */ +public class LuaView extends LVViewGroup { + + //LuaViewCore + private LuaViewCore mLuaViewCore; + + /** + * created callback + */ + public interface CreatedCallback { + void onCreated(LuaView luaView); + } + //---------------------------------------静态方法------------------------------------------------ + + /** + * create a luaview + * + * @param context + * @return + */ + public static LuaView create(final Context context) { + LuaViewCore luaViewCore = LuaViewCore.create(context); + return createLuaView(context, luaViewCore); + } + + /** + * create LuaView async + * + * @param context + * @return + */ + public static LuaView createAsync(final Context context) { + LuaViewCore luaViewCore = LuaViewCore.createAsync(context); + return createLuaView(context, luaViewCore); + } + + /** + * create LuaView async (兼容老的,可以使用无回调方法) + * + * @param context + * @param createdCallback + */ + public static void createAsync(final Context context, final CreatedCallback createdCallback) { + LuaViewCore.createAsync(context, new LuaViewCore.CreatedCallback() { + @Override + public void onCreated(LuaViewCore luaViewCore) { + final LuaView luaView = createLuaView(context, luaViewCore); + if (createdCallback != null) { + createdCallback.onCreated(luaView); + } + } + }); + } + + private static LuaView createLuaView(final Context context, LuaViewCore luaViewCore) { + final LuaView luaView = new LuaView(context, luaViewCore, createMetaTableForLuaView()); + luaViewCore.setRenderTarget(luaView); + luaViewCore.setWindowUserdata(luaView.getUserdata()); + return luaView; + } + //-----------------------------------------加载函数---------------------------------------------- + + /** + * 加载,可能是url,可能是Asset,可能是文件,也可能是脚本 + * url : http or https, http://[xxx] or https://[xxx] + * asset : folder or file, file://android_asset/[xxx] + * file : folder or file, file://[xxx] + * script: content://[xxx] + * + * @param urlOrFileOrScript + * @return + */ + public LuaView load(final String urlOrFileOrScript) { + return load(urlOrFileOrScript, null, null); + } + + public LuaView load(final String urlOrFileOrScript, final LuaScriptLoader.ScriptExecuteCallback callback) { + return load(urlOrFileOrScript, null, callback); + } + + public LuaView load(final String urlOrFileOrScript, final String sha256) { + return load(urlOrFileOrScript, sha256, null); + } + + public LuaView load(final String urlOrFileOrScript, final String sha256, final LuaScriptLoader.ScriptExecuteCallback callback) { + if (mLuaViewCore != null) { + mLuaViewCore.load(urlOrFileOrScript, sha256, callback); + } + return this; + } + + /** + * 直接加载网络脚本 + * + * @param url http://[xxx] or https://[xxx] + * @return + */ + public LuaView loadUrl(final String url, final String sha256) { + return loadUrl(url, sha256, null); + } + + public LuaView loadUrl(final String url, final String sha256, final LuaScriptLoader.ScriptExecuteCallback callback) { + if (mLuaViewCore != null) { + mLuaViewCore.loadUrl(url, sha256, callback); + } + return this; + } + + /** + * 加载 Asset路径下的脚本 + * + * @param assetPath folder path or file path + * @return + */ + private LuaView loadAsset(final String assetPath) { + return loadAsset(assetPath, null); + } + + private LuaView loadAsset(final String assetPath, final LuaScriptLoader.ScriptExecuteCallback callback) { + if (mLuaViewCore != null) { + mLuaViewCore.loadAsset(assetPath, callback); + } + return this; + } + + /** + * 加载脚本库,必须在主进程中执行,先判断asset下是否存在,再去文件系统中查找 + * + * @param luaFileName plain file name or file://[xxx] + * @return + */ + private LuaView loadFile(final String luaFileName) { + return loadFile(luaFileName, null); + } + + private LuaView loadFile(final String luaFileName, final LuaScriptLoader.ScriptExecuteCallback callback) { + if (mLuaViewCore != null) { + mLuaViewCore.loadFile(luaFileName, callback); + } + return this; + } + + /** + * Load plain Script Code + * + * @param script + * @return + */ + public LuaView loadScript(final String script) { + return loadScript(script, null); + } + + public LuaView loadScript(final String script, final LuaScriptLoader.ScriptExecuteCallback callback) { + if (mLuaViewCore != null) { + mLuaViewCore.loadScript(script, callback); + } + return this; + } + + /** + * 加载Script Bundle (zip file) + * + * @param scriptFile + * @return + */ + private LuaView loadScript(final ScriptFile scriptFile) { + return loadScript(scriptFile, null); + } + + private LuaView loadScript(final ScriptFile scriptFile, final LuaScriptLoader.ScriptExecuteCallback callback) { + if (mLuaViewCore != null) { + mLuaViewCore.loadScript(scriptFile, callback); + } + return this; + } + + /** + * 加载 Script Bundle + * + * @param scriptBundle + * @return + */ + public LuaView loadScriptBundle(final ScriptBundle scriptBundle) { + return loadScriptBundle(scriptBundle, null); + } + + public LuaView loadScriptBundle(final ScriptBundle scriptBundle, final LuaScriptLoader.ScriptExecuteCallback callback) { + return loadScriptBundle(scriptBundle, LuaResourceFinder.DEFAULT_MAIN_ENTRY, callback); + } + + public LuaView loadScriptBundle(final ScriptBundle scriptBundle, final String mainScriptFileName, final LuaScriptLoader.ScriptExecuteCallback callback) { + if (mLuaViewCore != null) { + mLuaViewCore.loadScriptBundle(scriptBundle, mainScriptFileName, callback); + } + return this; + } + + /** + * load prototype (lua bytecode or sourcecode) + * + * @param inputStream + * @return + */ + public LuaView loadPrototype(final InputStream inputStream, final String name, final LuaScriptLoader.ScriptExecuteCallback callback) { + if (mLuaViewCore != null) { + mLuaViewCore.loadPrototype(inputStream, name, callback); + } + return this; + } + + + /** + * execute script + * + * @param value + * @param activity + * @param viewObj + * @param callback + * @return + */ + public boolean executeScript(LuaValue value, LuaValue activity, LuaValue viewObj, final LuaScriptLoader.ScriptExecuteCallback callback) { + return mLuaViewCore != null ? mLuaViewCore.executeScript(value, activity, viewObj, callback) : false; + } + //---------------------------------------注册函数------------------------------------------------ + + /** + * 加载一个binder,可以用作覆盖老功能 + * Lib 必须注解上 LuaViewLib + * + * @param binders + * @return + */ + public LuaView registerLibs(LuaValue... binders) { + if (mLuaViewCore != null) { + mLuaViewCore.registerLibs(binders); + } + return this; + } + + /** + * 注册一个名称到该lua对象的命名空间中 + * + * @param luaName + * @param obj + * @return + */ + public LuaView register(final String luaName, final Object obj) { + if (mLuaViewCore != null) { + mLuaViewCore.register(luaName, obj); + } + return this; + } + + /** + * 注册一个名称到该lua对象的命名空间中 + * + * @param clazz + * @return + */ + public LuaView registerPanel(final Class clazz) { + return registerPanel(clazz != null ? clazz.getSimpleName() : null, clazz); + } + + /** + * 注册一个名称到该lua对象的命名空间中 + * + * @param luaName + * @param clazz + * @return + */ + public LuaView registerPanel(final String luaName, final Class clazz) { + if (mLuaViewCore != null) { + mLuaViewCore.registerPanel(luaName, clazz); + } + return this; + } + + /** + * 解注册一个命名空间中的名字 + * + * @param luaName + * @return + */ + public LuaView unregister(final String luaName) { + if (mLuaViewCore != null) { + mLuaViewCore.unregister(luaName); + } + return this; + } + + //----------------------------------------call lua function------------------------------------- + + /** + * 调用lua的某个全局函数 + * + * @param funName + * @param objs + * @return + */ + public Object callLuaFunction(String funName, Object... objs) { + if (mLuaViewCore != null) { + mLuaViewCore.callLuaFunction(funName, objs); + } + return LuaValue.NIL; + } + + /** + * 调用window.callback下的某个函数 + * + * @param funName + * @param objs + * @return + */ + public Varargs callWindowFunction(String funName, Object... objs) { + if (funName != null) { + final UDView userdata = getUserdata(); + if (userdata != null) { + final LuaValue callbacks = userdata.getCallback(); + if (LuaUtil.isValid(callbacks)) { + return LuaUtil.callFunction(callbacks.get(funName), objs); + } + } + } + return LuaValue.NIL; + } + + //----------------------------------------Image Provider---------------------------------------- + + /** + * 注册ImageProvider + */ + public static void registerImageProvider(final Class clazz) { + LuaViewCore.registerImageProvider(clazz); + } + + /** + * 获取ImageProvider + * + * @return + */ + public static ImageProvider getImageProvider() { + return LuaViewCore.getImageProvider(); + } + + //----------------------------------------setup functions--------------------------------------- + + /** + * 设置使用标准语法 + * + * @param standardSyntax + */ + public void setUseStandardSyntax(boolean standardSyntax) { + if (mLuaViewCore != null) { + mLuaViewCore.setUseStandardSyntax(standardSyntax); + } + } + + /** + * 刷新容器是否可以刷新(用在RefreshCollectionView初始化的地方) + * + * @param enable + */ + public void setRefreshContainerEnable(boolean enable) { + if (mLuaViewCore != null) { + mLuaViewCore.setRefreshContainerEnable(enable); + } + } + + /** + * 刷新容器是否可以刷新(用在RefreshCollectionView初始化的地方) + */ + public boolean isRefreshContainerEnable() { + return mLuaViewCore != null ? mLuaViewCore.isRefreshContainerEnable() : true; + } + + + public String getUri() { + return mLuaViewCore != null ? mLuaViewCore.getUri() : null; + } + + public void setUri(String uri) { + if (mLuaViewCore != null) { + mLuaViewCore.setUri(uri); + } + } + + public Globals getGlobals() { + return mLuaViewCore != null ? mLuaViewCore.getGlobals() : null; + } + + public LuaViewCore getLuaViewCore() { + return mLuaViewCore; + } + //-------------------------------------------私有------------------------------------------------ + + /** + * TODO 优化 + * 创建LuaView的methods,这里可以优化,实现更加优雅,其实就是将window注册成一个userdata,并且userdata是UDViewGroup + * + * @return + */ + private static LuaTable createMetaTableForLuaView() { + return LuaViewManager.createMetatable(UIViewGroupMethodMapper.class); + } + + /** + * @param context View级别的Context + * @param luaViewCore + * @param metaTable + */ + private LuaView(Context context, LuaViewCore luaViewCore, LuaValue metaTable) { + super(context, luaViewCore.getGlobals(), metaTable, LuaValue.NIL); + this.mLuaViewCore = luaViewCore; + } + + //-----------------------------------------网络回调---------------------------------------------- + + /** + * 当显示的时候调用 + */ + @Override + protected void onWindowVisibilityChanged(int visibility) { + if (mLuaViewCore != null) { + mLuaViewCore.onShow(visibility); + } + super.onWindowVisibilityChanged(visibility); + if (mLuaViewCore != null) { + mLuaViewCore.onHide(visibility); + } + } + + /** + * 创建的时候调用 + */ + @Override + protected void onAttachedToWindow() { + if (mLuaViewCore != null) { + mLuaViewCore.onAttached(); + } + super.onAttachedToWindow(); + } + + /** + * 离开的时候调用 + */ + @Override + protected void onDetachedFromWindow() { + super.onDetachedFromWindow(); + if (mLuaViewCore != null) { + mLuaViewCore.onDetached(); + } + } + + //----------------------------------------getter and setter------------------------------------- + + /** + * create a default render target (viewgroup) + * + * @return + */ + public ViewGroup createDefaultRenderTarget() { + return new LVViewGroup(getGlobals(), createMetaTableForLuaView(), null); + } + + /** + * set render target + * + * @param viewGroup + * @return + */ + public LuaView setRenderTarget(ViewGroup viewGroup) { + if (mLuaViewCore != null) { + mLuaViewCore.setRenderTarget(viewGroup); + //TODO 需要在这里设置setWindowUserdata(XXX) + } + return this; + } + + /** + * get render target + * + * @return + */ + private ViewGroup getRenderTarget() { + return mLuaViewCore != null ? mLuaViewCore.getRenderTarget() : this; + } + + //----------------------------------------生命周期 管理---------------------------------------- + + /** + * 销毁的时候从外部调用,清空所有外部引用 + */ + public void onDestroy() { + if (mLuaViewCore != null) { + mLuaViewCore.onDestroy(); + mLuaViewCore = null; + } + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/global/LuaViewConfig.java b/Android/LuaViewSDK/src/com/taobao/luaview/global/LuaViewConfig.java new file mode 100644 index 00000000..5aa03aae --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/global/LuaViewConfig.java @@ -0,0 +1,167 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.global; + +import android.content.Context; +import android.os.Build; + +import com.taobao.android.luaview.BuildConfig; + +/** + * LuaView 全局设置 + * + * @author song + * @date 15/9/9 + */ +public class LuaViewConfig { + private static boolean isDebug = BuildConfig.DEBUG; + private static boolean isOpenDebugger = isEmulator();//目前只支持模拟器下断点调试Lua,不支持真机,真机环境关闭该功能 + private static boolean isLibsLazyLoad = false;//是否延迟加载Libs,如果延迟加载则只会加载用到的libs,并且只会在用到的时候才加载,不用到不加载 + private static boolean isUseLuaDC = false;//是否使用LuaDC Compiler,直接将lua代码编译成dex文件,能够加速虚拟机执行 + private static boolean isUseNoReflection = false;//是否不使用反射调用接口 + private static boolean isCachePrototype = false;//是否缓存prototype,默认不缓存 + private static boolean isAutoSetupClickEffects = false;//是否自动设置点击效果 + + //设备标识 + private static String sTtid = null; + + /** + * init luaview + * + * @param context + */ + public static void init(Context context) { + //延迟加载Libs + LuaViewConfig.setLibsLazyLoad(true); + //是否使用非反射方式API调用(默认为true) + LuaViewConfig.setUseNoReflection(true); + } + + public static boolean isDebug() { + return isDebug; + } + + public static boolean isOpenDebugger() { + return isOpenDebugger; + } + + public static boolean isLibsLazyLoad() { + return isLibsLazyLoad; + } + + public static boolean isUseLuaDC() { + return isUseLuaDC; + } + + /** + * 判断当前设备是否是模拟器。如果返回TRUE,则当前是模拟器,不是返回FALSE + * + * @return + */ + private static boolean isEmulator() { + return isRunningOnGenymotion() || isRunningOnStockEmulator(); + } + + private static boolean isRunningOnGenymotion() { + return Build.FINGERPRINT.contains("vbox"); + } + + private static boolean isRunningOnStockEmulator() { + return Build.FINGERPRINT.contains("generic"); + } + + /** + * 获取ttid + * + * @return + */ + public static String getTtid() { + return sTtid != null ? sTtid : "999999@taobao_android_1.0"; + } + + /** + * 设置 ttid + * + * @param ttid + */ + public static void setTtid(String ttid) { + sTtid = ttid; + } + + /** + * 全局是否debug + * + * @param debug + */ + public static void setDebug(boolean debug) { + isDebug = debug; + } + + /** + * 设置是否开启调试器用于断点调试 + * + * @param openDebugger + */ + public static void setOpenDebugger(boolean openDebugger) { + isOpenDebugger = openDebugger; + } + + /** + * 是否延迟加载libs,如果设置为true的话则会在运行的时候才会加载用户lib,而不是初始化虚拟机的时候加载 + * + * @param lazyLoad + */ + public static void setLibsLazyLoad(boolean lazyLoad) { + isLibsLazyLoad = lazyLoad; + } + + /** + * 是否使用LuaDC Loader,可以直接lua to dex bytecode + */ + public static void setUseLuaDC(boolean useLuaDC) { + isUseLuaDC = useLuaDC; + } + + /** + * 设置不使用反射 + * + * @param useNoReflection + */ + public static void setUseNoReflection(boolean useNoReflection) { + isUseNoReflection = useNoReflection; + } + + public static boolean isUseNoReflection() { + return isUseNoReflection; + } + + /** + * 是否缓存prototype + */ + public static void setCachePrototype(boolean cachePrototype) { + isCachePrototype = cachePrototype; + } + + public static boolean isCachePrototype() { + return isCachePrototype; + } + + /** + * 是否自动设置ripple effects + * + * @param isAutoSetupClickEffects + */ + public static void setAutoSetupClickEffects(boolean isAutoSetupClickEffects) { + LuaViewConfig.isAutoSetupClickEffects = isAutoSetupClickEffects; + } + + public static boolean isAutoSetupClickEffects() { + return isAutoSetupClickEffects; + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/global/LuaViewCore.java b/Android/LuaViewSDK/src/com/taobao/luaview/global/LuaViewCore.java new file mode 100644 index 00000000..c4505fb0 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/global/LuaViewCore.java @@ -0,0 +1,855 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.global; + +import android.content.Context; +import android.os.StrictMode; +import android.text.TextUtils; +import android.view.View; +import android.view.ViewGroup; +import android.webkit.URLUtil; + +import com.taobao.luaview.debug.DebugConnection; +import com.taobao.luaview.fun.binder.ui.UICustomPanelBinder; +import com.taobao.luaview.fun.mapper.ui.UIViewGroupMethodMapper; +import com.taobao.luaview.provider.ImageProvider; +import com.taobao.luaview.receiver.ConnectionStateChangeBroadcastReceiver; +import com.taobao.luaview.scriptbundle.LuaScriptManager; +import com.taobao.luaview.scriptbundle.ScriptBundle; +import com.taobao.luaview.scriptbundle.ScriptFile; +import com.taobao.luaview.scriptbundle.asynctask.SimpleTask1; +import com.taobao.luaview.userdata.ui.UDView; +import com.taobao.luaview.util.EncryptUtil; +import com.taobao.luaview.util.LogUtil; +import com.taobao.luaview.util.LuaUtil; +import com.taobao.luaview.util.NetworkUtil; +import com.taobao.luaview.view.LVCustomPanel; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaTable; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Prototype; +import org.luaj.vm2.lib.jse.CoerceJavaToLua; + +import java.io.IOException; +import java.io.InputStream; + +/** + * Core of LuaView functions + * + * @author song + * @date 17/2/22 + * 主要功能描述 + * 修改描述 + * 下午5:04 song XXX + */ +public class LuaViewCore implements ConnectionStateChangeBroadcastReceiver.OnConnectionChangeListener { + + //window luavalue + private static final String LV_WINDOW = "window"; + + //image provider class + private static Class mImageProviderClazz; + + //provider for loading image + private static ImageProvider mImageProvider; + + //Context + private Context mContext; + + //globals + public Globals mGlobals; + + //userdata for render target + private UDView mWindowUserdata; + + public interface CreatedCallback { + void onCreated(LuaViewCore luaViewCore); + } + //---------------------------------------静态方法------------------------------------------------ + + /** + * create a LuaViewCore + * + * @param context + * @return + */ + public static LuaViewCore create(final Context context) { + final Globals globals = LuaViewManager.createGlobals(); + return createLuaViewCore(context, globals); + } + + /** + * create LuaViewCore async (带返回值) + * + * @param context + */ + public static LuaViewCore createAsync(final Context context) { + final Globals globals = LuaViewManager.createGlobalsAsync(); + return createLuaViewCore(context, globals); + } + + /** + * create LuaViewCore async(兼容老的,没必要包装一层SimpleTask) + * + * @param context + * @param createdCallback + */ + public static void createAsync(final Context context, final LuaViewCore.CreatedCallback createdCallback) { + new SimpleTask1() { + @Override + protected LuaViewCore doInBackground(Object... params) { + return create(context); + } + + @Override + protected void onPostExecute(LuaViewCore luaViewCore) { + if (createdCallback != null) { + createdCallback.onCreated(luaViewCore); + } + } + }.executeInPool(); + } + + /** + * create LuaViewCore and setup everything + * + * @param context + * @param globals + * @return + */ + private static LuaViewCore createLuaViewCore(final Context context, final Globals globals) { + final LuaViewCore core = new LuaViewCore(context, globals); + if (LuaViewConfig.isOpenDebugger()) {//如果是debug,支持ide调试 + core.openDebugger(); + } + return core; + } + + + //-----------------------------------------load script------------------------------------------ + + /** + * 加载,可能是url,可能是Asset,可能是文件,也可能是脚本 + * url : http or https, http://[xxx] or https://[xxx] + * TODO asset : folder or file, file://android_asset/[xxx] + * TODO file : folder or file, file://[xxx] + * TODO script: content://[xxx] + * + * @param urlOrFileOrScript + * @return + */ + public LuaViewCore load(final String urlOrFileOrScript) { + return load(urlOrFileOrScript, null, null); + } + + public LuaViewCore load(final String urlOrFileOrScript, final LuaScriptLoader.ScriptExecuteCallback callback) { + return load(urlOrFileOrScript, null, callback); + } + + public LuaViewCore load(final String urlOrFileOrScript, final String sha256) { + return load(urlOrFileOrScript, sha256, null); + } + + public LuaViewCore load(final String urlOrFileOrScript, final String sha256, final LuaScriptLoader.ScriptExecuteCallback callback) { + if (!TextUtils.isEmpty(urlOrFileOrScript)) { + if (URLUtil.isNetworkUrl(urlOrFileOrScript) || URLUtil.isAssetUrl(urlOrFileOrScript)) {//url, http:// or https:// or asset:// + loadUrl(urlOrFileOrScript, sha256, callback); + } else { + loadFile(urlOrFileOrScript, callback); + } + //TODO other schema + } else if (callback != null) { + callback.onScriptExecuted(null, false); + } + return this; + } + + /** + * 直接加载网络脚本 + * + * @param url http://[xxx] or https://[xxx] + * @return + */ + public LuaViewCore loadUrl(final String url, final String sha256) { + return loadUrl(url, sha256, null); + } + + + /** + * load url + * + * @param url + * @param sha256 + * @param callback + * @return + */ + public LuaViewCore loadUrl(final String url, final String sha256, final LuaScriptLoader.ScriptExecuteCallback callback) { + updateUri(url); + if (!TextUtils.isEmpty(url)) { + new LuaScriptLoader(mContext).load(url, sha256, new LuaScriptLoader.ScriptLoaderCallback2() { + @Override + public void onEvent(LuaScriptLoader.LuaScriptLoadEvent event, Object params) { + if (callback instanceof LuaScriptLoader.ScriptExecuteCallback2) { + ((LuaScriptLoader.ScriptExecuteCallback2) callback).onEvent(event, params); + } + } + + @Override + public void onScriptLoaded(ScriptBundle bundle) {//脚本本地 or Asset or 网络 准备成功 + if (callback == null || callback.onScriptPrepared(bundle) == false) {//脚本准备完成,且不第三方自己执行 + loadScriptBundle(bundle, callback); + } else if (callback != null) { + callback.onScriptExecuted(url, false); + } + } + }); + } else if (callback != null) { + callback.onScriptExecuted(null, false); + } + return this; + } + + /** + * 加载 Asset 路径下的脚本 + * + * @param assetPath folder path or file path + * @return + */ + public LuaViewCore loadAsset(final String assetPath) { + return loadAsset(assetPath, null); + } + + public LuaViewCore loadAsset(final String assetPath, final LuaScriptLoader.ScriptExecuteCallback callback) { + //TODO + return this; + } + + /** + * 加载脚本库,必须在主进程中执行,先判断asset下是否存在,再去文件系统中查找 + * + * @param luaFileName plain file name or file://[xxx] + * @return + */ + public LuaViewCore loadFile(final String luaFileName) { + return loadFile(luaFileName, null); + } + + public LuaViewCore loadFile(final String luaFileName, final LuaScriptLoader.ScriptExecuteCallback callback) { + updateUri(luaFileName); + if (!TextUtils.isEmpty(luaFileName)) { + this.loadFileInternal(luaFileName, callback);//加载文件 + } else { + if (callback != null) { + callback.onScriptExecuted(getUri(), false); + } + } + return this; + } + + /** + * 加载脚本 + * + * @param script + * @return + */ + public LuaViewCore loadScript(final String script) { + return loadScript(script, null); + } + + public LuaViewCore loadScript(final String script, final LuaScriptLoader.ScriptExecuteCallback callback) { + updateUri(""); + if (!TextUtils.isEmpty(script)) { + this.loadScriptInternal(new ScriptFile(script, EncryptUtil.md5Hex(script)), callback); + } else { + if (callback != null) { + callback.onScriptExecuted(getUri(), false); + } + } + return this; + } + + /** + * 加载 Script File + * + * @param scriptFile + * @return + */ + public LuaViewCore loadScript(final ScriptFile scriptFile) { + return loadScript(scriptFile, null); + } + + public LuaViewCore loadScript(final ScriptFile scriptFile, final LuaScriptLoader.ScriptExecuteCallback callback) { + if (scriptFile != null) { + this.loadScriptInternal(scriptFile, callback); + } else if (callback != null) { + callback.onScriptExecuted(getUri(), false); + } + return this; + } + + /** + * 加载 Script Bundle + * + * @param scriptBundle + * @return + */ + public LuaViewCore loadScriptBundle(final ScriptBundle scriptBundle) { + return loadScriptBundle(scriptBundle, null); + } + + public LuaViewCore loadScriptBundle(final ScriptBundle scriptBundle, final LuaScriptLoader.ScriptExecuteCallback callback) { + loadScriptBundle(scriptBundle, LuaResourceFinder.DEFAULT_MAIN_ENTRY, callback); + return this; + } + + public LuaViewCore loadScriptBundle(final ScriptBundle scriptBundle, final String mainScriptFileName, final LuaScriptLoader.ScriptExecuteCallback callback) { + if (scriptBundle != null) { + if (mGlobals != null && mGlobals.getLuaResourceFinder() != null) { + mGlobals.getLuaResourceFinder().setScriptBundle(scriptBundle); + } + if (scriptBundle.containsKey(mainScriptFileName)) { + final ScriptFile scriptFile = scriptBundle.getScriptFile(mainScriptFileName); + loadScript(scriptFile, callback); + return this; + } + } + if (callback != null) { + callback.onScriptExecuted(getUri(), false); + } + return this; + } + + /** + * load prototype (lua bytecode or sourcecode) + * + * @param inputStream + * @return + */ + public LuaViewCore loadPrototype(final InputStream inputStream, final String name, final LuaScriptLoader.ScriptExecuteCallback callback) { + new SimpleTask1() { + @Override + protected LuaValue doInBackground(Object... params) { + try { + if (mGlobals != null) { + Prototype prototype = mGlobals.loadPrototype(inputStream, name, "bt"); + if (prototype != null) { + LuaValue result = mGlobals.load(prototype, name); + return result; + } + } + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } + + @Override + protected void onPostExecute(LuaValue value) { + final LuaValue activity = CoerceJavaToLua.coerce(mContext); + final LuaValue viewObj = CoerceJavaToLua.coerce(LuaViewCore.this); + if (callback == null || callback.onScriptCompiled(value, activity, viewObj) == false) { + executeScript(value, activity, viewObj, callback); + } + } + }.executeInPool(); + return this; + } + //---------------------------------------注册函数---------------------------------------------- + + /** + * 加载一个binder,可以用作覆盖老功能 + * Lib 必须注解上 LuaViewLib + * + * @param binders + * @return + */ + public synchronized LuaViewCore registerLibs(LuaValue... binders) { + if (mGlobals != null && binders != null) { + for (LuaValue binder : binders) { + mGlobals.tryLazyLoad(binder); + } + } + return this; + } + + /** + * 注册一个名称到该lua对象的命名空间中 + * + * @param luaName + * @param obj + * @return + */ + public synchronized LuaViewCore register(final String luaName, final Object obj) { + if (mGlobals != null && !TextUtils.isEmpty(luaName)) { + final LuaValue value = mGlobals.get(luaName); + if (obj != value) { + mGlobals.set(luaName, CoerceJavaToLua.coerce(obj)); + } + } else { + LogUtil.e("name " + luaName + " is invalid!"); + } + return this; + } + + /** + * 注册一个名称到该lua对象的命名空间中 + * + * @param clazz + * @return + */ + public synchronized LuaViewCore registerPanel(final Class clazz) { + return registerPanel(clazz != null ? clazz.getSimpleName() : null, clazz); + } + + /** + * 注册一个名称到该lua对象的命名空间中 + * + * @param luaName + * @param clazz + * @return + */ + public synchronized LuaViewCore registerPanel(final String luaName, final Class clazz) { + if (mGlobals != null && !TextUtils.isEmpty(luaName) && (clazz != null && clazz.getSuperclass() == LVCustomPanel.class)) { + final LuaValue value = mGlobals.get(luaName); + if (value == null || value.isnil()) { + mGlobals.tryLazyLoad(new UICustomPanelBinder(clazz, luaName)); + } else { + LogUtil.e("panel name " + luaName + " is already registered!"); + } + } else { + LogUtil.e("name " + luaName + " is invalid or Class " + clazz + " is not subclass of " + LVCustomPanel.class.getSimpleName()); + } + return this; + } + + /** + * 解注册一个命名空间中的名字 + * + * @param luaName + * @return + */ + public synchronized LuaViewCore unregister(final String luaName) { + if (mGlobals != null && !TextUtils.isEmpty(luaName)) { + mGlobals.set(luaName, LuaValue.NIL); + } + return this; + } + + //----------------------------------------call lua function------------------------------------- + + /** + * 调用lua的某个全局函数 + * + * @param funName + * @param objs + * @return + */ + public Object callLuaFunction(String funName, Object... objs) { + if (mGlobals != null && funName != null) { + final LuaValue callback = mGlobals.get(funName); + return LuaUtil.callFunction(callback, objs); + } + return LuaValue.NIL; + } + + //----------------------------------------Image Provider---------------------------------------- + + /** + * 注册ImageProvider + */ + + public static void registerImageProvider(final Class clazz) { + mImageProviderClazz = clazz; + } + + /** + * 获取ImageProvider + * + * @return + */ + public static ImageProvider getImageProvider() { + if (mImageProvider == null && mImageProviderClazz != null) { + try { + mImageProvider = mImageProviderClazz.newInstance(); + } catch (InstantiationException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + } + return mImageProvider; + } + + //----------------------------------------setup functions--------------------------------------- + + /** + * 设置使用标准语法 + * + * @param standardSyntax + */ + public void setUseStandardSyntax(boolean standardSyntax) { + if (mGlobals != null) { + mGlobals.setUseStandardSyntax(standardSyntax); + } + } + + /** + * 刷新容器是否可以刷新(用在RefreshCollectionView初始化的地方) + * + * @param enable + */ + public void setRefreshContainerEnable(boolean enable) { + if (this.mGlobals != null) { + this.mGlobals.isRefreshContainerEnable = enable; + } + } + + /** + * 刷新容器是否可以刷新(用在RefreshCollectionView初始化的地方) + */ + public boolean isRefreshContainerEnable() { + return this.mGlobals != null ? this.mGlobals.isRefreshContainerEnable : true; + } + + + public String getUri() { + if (mGlobals != null && mGlobals.getLuaResourceFinder() != null) { + return mGlobals.getLuaResourceFinder().getUri(); + } + return null; + } + + public void setUri(String uri) { + if (mGlobals != null && mGlobals.getLuaResourceFinder() != null) { + mGlobals.getLuaResourceFinder().setUri(uri); + } + } + + public Globals getGlobals() { + return mGlobals; + } + //-------------------------------------------私有------------------------------------------------ + + /** + * TODO 优化 + * 创建LuaView的methods,这里可以优化,实现更加优雅,其实就是将window注册成一个userdata,并且userdata是UDViewGroup + * + * @return + */ + private static LuaTable createMetaTableForLuaView() { + return LuaViewManager.createMetatable(UIViewGroupMethodMapper.class); + } + + /** + * @param globals + */ + private LuaViewCore(Context context, Globals globals) { + init(context); + this.mContext = context; + this.mGlobals = globals; + } + + private void init(Context context) { + //常量初始化 + Constants.init(context); + //初始化脚本管理 + LuaScriptManager.init(context); + } + + /** + * 开启debugger + */ + public void openDebugger() { + loadFile("debug.lua", new LuaScriptLoader.ScriptExecuteCallback() { + @Override + public boolean onScriptPrepared(ScriptBundle bundle) { + return false; + } + + @Override + public boolean onScriptCompiled(LuaValue value, LuaValue activity, LuaValue obj) { + return false; + } + + @Override + public void onScriptExecuted(String uri, boolean executedSuccess) { + if (executedSuccess && mGlobals != null) { + StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() + .detectNetwork() // or .detectAll() for all detectable problems,主线程执行socket + .build()); + mGlobals.debugConnection = DebugConnection.create(); + } + } + }); + } + + //-----------------------------------------私有load函数------------------------------------------ + private void updateUri(String uri) { + if (mGlobals != null && mGlobals.getLuaResourceFinder() != null) { + mGlobals.getLuaResourceFinder().setUri(uri); + } + } + + /** + * 初始化 + * + * @param luaFileName + */ + private LuaViewCore loadFileInternal(final String luaFileName, final LuaScriptLoader.ScriptExecuteCallback callback) { + new SimpleTask1() { + @Override + protected LuaValue doInBackground(Object... params) { + if (mGlobals != null) { + if (mGlobals.isInited) { + try { + return mGlobals.loadfile(luaFileName); + } catch (Exception e) { + e.printStackTrace(); + LogUtil.e("[Load Script Failed]", luaFileName, e); + } + } else { + try { + Thread.sleep(16); + return doInBackground(params); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + return null; + } + + @Override + protected void onPostExecute(LuaValue value) { + final LuaValue activity = CoerceJavaToLua.coerce(mContext); + final LuaValue viewObj = CoerceJavaToLua.coerce(LuaViewCore.this); + if (callback == null || callback.onScriptCompiled(value, activity, viewObj) == false) { + //执行脚本,在主线程 + executeScript(value, activity, viewObj, callback); + } + } + }.executeInPool();//TODO 这里使用execute,而不是executeInPoll,与createGlobalAsync保持一致 + + return this; + } + + /** + * 加载纯脚本 + * + * @param scriptFile + */ + + private LuaViewCore loadScriptInternal(final ScriptFile scriptFile, final LuaScriptLoader.ScriptExecuteCallback callback) { + new SimpleTask1() {//load async + @Override + protected LuaValue doInBackground(Object... params) { + if (mGlobals != null) { + if (mGlobals.isInited) { + if (scriptFile != null) {//prototype + String filePath = scriptFile.getFilePath(); + if (scriptFile.prototype != null) {//prototype + return mGlobals.load(scriptFile.prototype, filePath); + } else {//source code + try { + return mGlobals.load(scriptFile.getScriptString(), filePath); + } catch (Exception e) { + e.printStackTrace(); + LogUtil.e("[Load Script Failed]", filePath, e); + } + } + } + } else { + try { + Thread.sleep(16); + return doInBackground(params); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + return null; + } + + @Override + protected void onPostExecute(LuaValue value) { + final LuaValue activity = CoerceJavaToLua.coerce(mContext); + final LuaValue viewObj = CoerceJavaToLua.coerce(LuaViewCore.this); + if (callback == null || callback.onScriptCompiled(value, activity, viewObj) == false) { + //执行脚本,在主线程 + executeScript(value, activity, viewObj, callback); + } + } + }.executeInPool();//TODO 这里使用execute,而不是executeInPoll,与createGlobalAsync保持一致 + return this; + } + + /** + * 执行脚本 + * + * @param value + * @param activity + * @param viewObj + * @param callback + */ + public boolean executeScript(LuaValue value, LuaValue activity, LuaValue viewObj, final LuaScriptLoader.ScriptExecuteCallback callback) { + try { + if (mGlobals != null && value != null) { + mGlobals.saveContainer(getRenderTarget()); + mGlobals.set(LV_WINDOW, mWindowUserdata);//TODO 优化到其他地方?,设置window对象 + value.call(activity, viewObj); + mGlobals.restoreContainer(); + if (callback != null) { + callback.onScriptExecuted(getUri(), true); + } + return true; + } + } catch (Exception e) { + e.printStackTrace(); + LogUtil.e("[Executed Script Failed]", e); + } + if (callback != null) { + callback.onScriptExecuted(getUri(), false); + } + return false; + } + + //-----------------------------------------网络回调---------------------------------------------- + + @Override + public void onConnectionClosed() { + if (mWindowUserdata != null) { + if (mWindowUserdata.getCallback() != null && mWindowUserdata.getCallback().istable()) { + LuaUtil.callFunction(LuaUtil.getFunction(mWindowUserdata.getCallback(), "onConnectionClosed", "OnConnectionClosed")); + } + } + } + + @Override + public void onMobileConnected() { + if (mWindowUserdata != null) { + if (mWindowUserdata.getCallback() != null && mWindowUserdata.getCallback().istable()) { + LuaUtil.callFunction(LuaUtil.getFunction(mWindowUserdata.getCallback(), "onMobileConnected", "OnMobileConnected")); + } + } + } + + @Override + public void onWifiConnected() { + if (mWindowUserdata != null) { + if (mWindowUserdata.getCallback() != null && mWindowUserdata.getCallback().istable()) { + LuaUtil.callFunction(LuaUtil.getFunction(mWindowUserdata.getCallback(), "onWifiConnected", "OnWifiConnected")); + } + } + } + + //----------------------------------------getter and setter------------------------------------- + + /** + * set window userdata + * + * @param userdata + * @return + */ + public LuaViewCore setWindowUserdata(UDView userdata) { + this.mWindowUserdata = userdata; + return this; + } + + /** + * get userdata for window + * + * @return + */ + public LuaValue getWindowUserdata() { + return this.mWindowUserdata; + } + + /** + * set render target + * + * @param viewGroup + * @return + */ + public LuaViewCore setRenderTarget(ViewGroup viewGroup) { + if (mGlobals != null) { + mGlobals.setRenderTarget(viewGroup); + } + return this; + } + + /** + * get render target + * + * @return + */ + public ViewGroup getRenderTarget() { + return mGlobals != null ? mGlobals.getRenderTarget() : null; + } + + //----------------------------------------显示的生命周期 管理------------------------------------- + + /** + * View初始化的时候注册监听 + */ + public void onAttached() { + } + + /** + * 显示 + * + * @param visibility + */ + public void onShow(int visibility) { + if (visibility == View.VISIBLE) {//onShow + NetworkUtil.registerConnectionChangeListener(mContext, this);//show之前注册 + } + } + + /** + * 隐藏 + * + * @param visibility + */ + public void onHide(int visibility) { + if (visibility != View.VISIBLE) {//onHide + NetworkUtil.unregisterConnectionChangeListener(mContext, this);//hide之后调用 + } + } + + /** + * 在onDetached的时候清空cache + */ + public void onDetached() { + clearCache(); + } + + /** + * 销毁的时候从外部调用,清空所有外部引用 + */ + public synchronized void onDestroy() { + clearCache(); + if (mGlobals != null) { + mGlobals.onDestroy(); + mGlobals = null; + } + mContext = null; + mWindowUserdata = null; + } + + /** + * 清空cache + */ + private void clearCache() { + if (mGlobals != null) { + mGlobals.clearCache(); + } + NetworkUtil.unregisterConnectionChangeListener(mContext, this); + } +} \ No newline at end of file diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/global/LuaViewManager.java b/Android/LuaViewSDK/src/com/taobao/luaview/global/LuaViewManager.java new file mode 100644 index 00000000..f0e241c6 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/global/LuaViewManager.java @@ -0,0 +1,408 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.global; + +import com.taobao.luaview.cache.AppCache; +import com.taobao.luaview.fun.base.BaseMethodMapper; +import com.taobao.luaview.fun.binder.constants.AlignBinder; +import com.taobao.luaview.fun.binder.constants.EllipsizeBinder; +import com.taobao.luaview.fun.binder.constants.FontStyleBinder; +import com.taobao.luaview.fun.binder.constants.FontWeightBinder; +import com.taobao.luaview.fun.binder.constants.GravityBinder; +import com.taobao.luaview.fun.binder.constants.InterpolatorBinder; +import com.taobao.luaview.fun.binder.constants.PaintStyleBinder; +import com.taobao.luaview.fun.binder.constants.PinnedBinder; +import com.taobao.luaview.fun.binder.constants.ScaleTypeBinder; +import com.taobao.luaview.fun.binder.constants.TextAlignBinder; +import com.taobao.luaview.fun.binder.constants.TouchEventBinder; +import com.taobao.luaview.fun.binder.constants.ViewEffectBinder; +import com.taobao.luaview.fun.binder.indicator.UICircleViewPagerIndicatorBinder; +import com.taobao.luaview.fun.binder.indicator.UICustomViewPagerIndicatorBinder; +import com.taobao.luaview.fun.binder.kit.ActionBarBinder; +import com.taobao.luaview.fun.binder.kit.AudioBinder; +import com.taobao.luaview.fun.binder.kit.BitmapBinder; +import com.taobao.luaview.fun.binder.kit.DataBinder; +import com.taobao.luaview.fun.binder.kit.FileBinder; +import com.taobao.luaview.fun.binder.kit.JsonBinder; +import com.taobao.luaview.fun.binder.kit.SystemBinder; +import com.taobao.luaview.fun.binder.kit.TimerBinder; +import com.taobao.luaview.fun.binder.kit.UnicodeBinder; +import com.taobao.luaview.fun.binder.kit.VibratorBinder; +import com.taobao.luaview.fun.binder.net.HttpBinder; +import com.taobao.luaview.fun.binder.ui.SpannableStringBinder; +import com.taobao.luaview.fun.binder.ui.UIAlertBinder; +import com.taobao.luaview.fun.binder.ui.UIAnimatorBinder; +import com.taobao.luaview.fun.binder.ui.UIAnimatorSetBinder; +import com.taobao.luaview.fun.binder.ui.UIButtonBinder; +import com.taobao.luaview.fun.binder.ui.UICustomViewBinder; +import com.taobao.luaview.fun.binder.ui.UIEditTextBinder; +import com.taobao.luaview.fun.binder.ui.UIHorizontalScrollViewBinder; +import com.taobao.luaview.fun.binder.ui.UIImageViewBinder; +import com.taobao.luaview.fun.binder.ui.UIListViewBinder; +import com.taobao.luaview.fun.binder.ui.UILoadingDialogBinder; +import com.taobao.luaview.fun.binder.ui.UILoadingViewBinder; +import com.taobao.luaview.fun.binder.ui.UIRecyclerViewBinder; +import com.taobao.luaview.fun.binder.ui.UIRefreshLayoutBinder; +import com.taobao.luaview.fun.binder.ui.UIRefreshListViewBinder; +import com.taobao.luaview.fun.binder.ui.UIRefreshRecyclerViewBinder; +import com.taobao.luaview.fun.binder.ui.UITextViewBinder; +import com.taobao.luaview.fun.binder.ui.UIToastBinder; +import com.taobao.luaview.fun.binder.ui.UIViewGroupBinder; +import com.taobao.luaview.fun.binder.ui.UIViewPagerBinder; +import com.taobao.luaview.fun.binder.ui.UIWebViewBinder; +import com.taobao.luaview.fun.mapper.LuaViewLib; +import com.taobao.luaview.fun.mapper.ui.NewIndexFunction; +import com.taobao.luaview.scriptbundle.asynctask.SimpleTask; +import com.taobao.luaview.scriptbundle.asynctask.SimpleTask0; +import com.taobao.luaview.vm.extend.luadc.LuaDC; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaError; +import org.luaj.vm2.LuaTable; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.lib.LibFunction; +import org.luaj.vm2.lib.jse.JsePlatform; + +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * LuaView Lib管理等 + * + * @author song + * @date 15/8/14 + */ +public class LuaViewManager { + private static final String CACHE_METATABLES = AppCache.CACHE_METATABLES; + + public static Globals sStaticGlobals;//使用该全局Globals来加速加载,需要提前创建Globals + + /** + * pre create globals + * + * @return + */ + public static synchronized void preCreateGlobals() { + synchronized (LuaViewManager.class) { + if (sStaticGlobals == null) { + new SimpleTask0() { + @Override + public void doTask() { + synchronized (LuaViewManager.class) { + if (sStaticGlobals == null) { + sStaticGlobals = setupGlobals(new Globals()); + } + } + } + }.executeInPool(); + } + } + } + + /** + * 创建Globals + * 根据是否用lua-to-java bytecode来处理(如果使用LuaJC的话则会使用库bcel 533k) + * + * @return + */ + public static Globals createGlobals() { + if (sStaticGlobals != null) { + synchronized (sStaticGlobals) { + Globals result = sStaticGlobals; + sStaticGlobals = null; + return result; + } + } else { + return setupGlobals(new Globals()); + } + } + + /** + * 创建Globals + * 根据是否用lua-to-java bytecode来处理(如果使用LuaJC的话则会使用库bcel 533k) + * + * @return + */ + public static Globals createGlobalsAsync() { + if (sStaticGlobals != null) { + synchronized (sStaticGlobals) { + Globals result = sStaticGlobals; + sStaticGlobals = null; + return result; + } + } else { + final Globals globals = new Globals(); + new SimpleTask() { + @Override + public void doTask(Globals... params) { + setupGlobals(params != null && params.length > 0 ? params[0] : null); + } + }.executeSerial(globals);//TODO 这里放到serial线程中执行,而不是executeInPool中执行,为了保证后续的执行时序列 + return globals; + } + } + + /** + * setup global values + * + * @param globals + */ + private static Globals setupGlobals(Globals globals) { + if (globals != null) { + if (LuaViewConfig.isOpenDebugger()) { + JsePlatform.debugGlobals(globals); + } else { + JsePlatform.standardGlobals(globals);//加载系统libs TODO 性能瓶颈 + } + + if (LuaViewConfig.isUseLuaDC()) { + LuaDC.install(globals); + } + loadLuaViewLibs(globals);//加载用户lib TODO 性能瓶颈 + globals.isInited = true; + } + return globals; + } + + /** + * tryLazyLoad Android API lib + * TODO 能否做到按需加载,而不是首次进来加载全部binder + * + * @param globals + */ + private static void loadLuaViewLibs(final Globals globals) { + //ui + globals.tryLazyLoad(new UITextViewBinder()); + globals.tryLazyLoad(new UIEditTextBinder()); + globals.tryLazyLoad(new UIButtonBinder()); + globals.tryLazyLoad(new UIImageViewBinder()); + globals.tryLazyLoad(new UIViewGroupBinder()); + globals.tryLazyLoad(new UIListViewBinder()); + globals.tryLazyLoad(new UIRecyclerViewBinder()); + globals.tryLazyLoad(new UIRefreshListViewBinder()); + globals.tryLazyLoad(new UIRefreshRecyclerViewBinder()); + globals.tryLazyLoad(new UIViewPagerBinder()); + globals.tryLazyLoad(new UICustomViewPagerIndicatorBinder()); + globals.tryLazyLoad(new UICircleViewPagerIndicatorBinder()); + globals.tryLazyLoad(new UIHorizontalScrollViewBinder()); + globals.tryLazyLoad(new UIAlertBinder()); + + globals.tryLazyLoad(new UILoadingViewBinder()); + globals.tryLazyLoad(new UILoadingDialogBinder()); + globals.tryLazyLoad(new UIToastBinder()); + globals.tryLazyLoad(new SpannableStringBinder()); + + globals.tryLazyLoad(new UIWebViewBinder()); + globals.tryLazyLoad(new UICustomViewBinder()); + globals.tryLazyLoad(new UIRefreshLayoutBinder()); + + //animation + globals.tryLazyLoad(new UIAnimatorBinder()); + globals.tryLazyLoad(new UIAnimatorSetBinder()); + + //net + globals.tryLazyLoad(new HttpBinder()); + + //kit + globals.tryLazyLoad(new TimerBinder()); + globals.tryLazyLoad(new SystemBinder()); + globals.tryLazyLoad(new ActionBarBinder()); + globals.tryLazyLoad(new FileBinder()); + globals.tryLazyLoad(new UnicodeBinder()); + globals.tryLazyLoad(new DataBinder()); + globals.tryLazyLoad(new JsonBinder()); + globals.tryLazyLoad(new AudioBinder()); + globals.tryLazyLoad(new VibratorBinder()); + + globals.tryLazyLoad(new BitmapBinder()); + + //常量 + globals.tryLazyLoad(new AlignBinder()); + globals.tryLazyLoad(new TextAlignBinder()); + globals.tryLazyLoad(new FontWeightBinder()); + globals.tryLazyLoad(new FontStyleBinder()); + globals.tryLazyLoad(new ScaleTypeBinder()); + globals.tryLazyLoad(new GravityBinder()); + globals.tryLazyLoad(new EllipsizeBinder()); + globals.tryLazyLoad(new InterpolatorBinder()); + globals.tryLazyLoad(new ViewEffectBinder());//view特效 + globals.tryLazyLoad(new PinnedBinder()); + globals.tryLazyLoad(new PaintStyleBinder()); + globals.tryLazyLoad(new TouchEventBinder()); + } + + //----------------------------------------bind methods------------------------------------------ + + /** + * bind lua function using methods + * + * @param factory + * @param methods + */ + public static LuaTable bindMethods(Class factory, Method[] methods) { + if (methods != null) { + return bindMethods(factory, Arrays.asList(methods)); + } + return new LuaTable(); + } + + /** + * bind lua functions using method + * + * @param factory + * @param methods + * @return + */ + public static LuaTable bindMethods(Class factory, List methods) { + LuaTable env = new LuaTable(); + try { + if (methods != null) { + for (int i = 0; i < methods.size(); i++) { + LibFunction f = factory.newInstance(); + f.opcode = -1; + f.method = methods.get(i); + f.name = methods.get(i).getName(); + env.set(f.name, f); + } + } + } catch (Exception e) { + throw new LuaError("[Bind Failed] " + e); + } finally { + return env; + } + } + + /** + * bind lua functions using opcode + * + * @param factory + * @param methods + * @return + */ + public static LuaTable bind(Class factory, List methods) { + LuaTable env = new LuaTable(); + try { + if (methods != null) { + for (int i = 0; i < methods.size(); i++) { + LibFunction f = factory.newInstance(); + f.opcode = i; + f.method = null; + f.name = methods.get(i); + env.set(f.name, f); + } + } + } catch (Exception e) { + throw new LuaError("[Bind Failed] " + e); + } finally { + return env; + } + } + + /** + * bind lua functions using opcode + * + * @param factory + * @param methods + * @return + */ + public static LuaTable bind(Class factory, String[] methods) { + LuaTable env = new LuaTable(); + try { + if (methods != null) { + for (int i = 0; i < methods.length; i++) { + LibFunction f = factory.newInstance(); + f.opcode = i; + f.method = null; + f.name = methods[i]; + env.set(f.name, f); + } + } + } catch (Exception e) { + throw new LuaError("[Bind Failed] " + e); + } finally { + return env; + } + } + //-----------------------------------------metatable-------------------------------------------- + + /** + * create metatable for libs + * + * @return + */ + public static LuaTable createMetatable(Class libClass) { + LuaTable result = AppCache.getCache(CACHE_METATABLES).get(libClass);//get from cache + + if (result == null) { + LuaTable libTable = null; + if (LuaViewConfig.isUseNoReflection()) { + final List methodNames = getMapperMethodNames(libClass); + libTable = LuaViewManager.bind(libClass, methodNames); + } else { + final List methods = getMapperMethods(libClass); + libTable = LuaViewManager.bindMethods(libClass, methods); + } + result = LuaValue.tableOf(new LuaValue[]{LuaValue.INDEX, libTable, LuaValue.NEWINDEX, new NewIndexFunction(libTable)}); + + //update cache + AppCache.getCache(CACHE_METATABLES).put(libClass, result); + } + return result; + } + + /** + * 获取所有方法的名字 + * + * @param clazz + * @return + */ + private static List getMapperMethodNames(final Class clazz) { + try { + if (clazz != null) { + Object obj = clazz.newInstance(); + if (obj instanceof BaseMethodMapper) { + return ((BaseMethodMapper) obj).getAllFunctionNames(); + } + } + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + /** + * 获取所有方法 + * + * @param clazz + * @return + */ + private static List getMapperMethods(final Class clazz) { + final List methods = new ArrayList(); + getMapperMethodsByClazz(methods, clazz); + return methods.size() > 0 ? methods : null; + } + + private static void getMapperMethodsByClazz(final List result, final Class clazz) { + if (clazz != null && clazz.isAnnotationPresent(LuaViewLib.class)) {//XXXMapper + getMapperMethodsByClazz(result, clazz.getSuperclass());//处理super + final Method[] methods = clazz.getDeclaredMethods(); + if (methods != null && methods.length > 0) { + for (final Method method : methods) {//add self + if (method.getModifiers() == Modifier.PUBLIC) {//public 方法才行 + result.add(method); + } + } + } + } + } + +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/global/SdkVersion.java b/Android/LuaViewSDK/src/com/taobao/luaview/global/SdkVersion.java new file mode 100644 index 00000000..62d5a9c4 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/global/SdkVersion.java @@ -0,0 +1,36 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.global; + +/** + * LuaView版本 + * + * @author song + */ +public class SdkVersion { + public static final String V_050 = "0.5.0"; + + public static final String V_051 = "0.5.1"; + + public static final String V_052 = "0.5.2"; + + public static String getCurrent() { + return V_052; + } + + /** + * 是否比某个版本更新 + * + * @param compareVersion + * @return + */ + public static boolean isHigherThan(String compareVersion) { + return getCurrent().compareTo(compareVersion) > 0; + } +} \ No newline at end of file diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/global/VmVersion.java b/Android/LuaViewSDK/src/com/taobao/luaview/global/VmVersion.java new file mode 100644 index 00000000..cb8b5269 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/global/VmVersion.java @@ -0,0 +1,47 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.global; + +/** + * LuaView虚拟机版本 + * + * @author song + */ +@Deprecated +public class VmVersion { + public static final String V_440 = "4.4.0"; + public static final String V_450 = "4.5.0"; + public static final String V_451 = "4.5.1"; + public static final String V_500 = "5.0.0"; + public static final String V_501 = "5.0.1"; + public static final String V_510 = "5.1.0"; + public static final String V_511 = "5.1.1"; + public static final String V_520 = "5.2.0"; + public static final String V_530 = "5.3.0"; + public static final String V_540 = "5.4.0"; + public static final String V_550 = "5.5.0"; + public static final String V_570 = "5.7.0"; + public static final String V_580 = "5.8.0"; + public static final String V_590 = "5.9.0"; + public static final String V_5170 = "5.17.0"; + + public static String getCurrent() { + return V_5170; + } + + /** + * 是否比某个版本更新 + * + * @param compareVersion + * @return + */ + public static boolean isHigherThan(String compareVersion) { + return getCurrent().compareTo(compareVersion) > 0; + } +} \ No newline at end of file diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/provider/ImageProvider.java b/Android/LuaViewSDK/src/com/taobao/luaview/provider/ImageProvider.java new file mode 100644 index 00000000..3d321c56 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/provider/ImageProvider.java @@ -0,0 +1,72 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.provider; + +import android.content.Context; +import android.view.ViewGroup; + +import com.taobao.luaview.view.imageview.BaseImageView; +import com.taobao.luaview.view.imageview.BitmapLoadCallback; +import com.taobao.luaview.view.imageview.DrawableLoadCallback; + +import java.lang.ref.WeakReference; + +/** + * 提供图片下载功能,用作ImageView相关 + * + * @author song + * @date 16/4/11 + * 主要功能描述 + * 修改描述 + * 下午4:48 song XXX + */ +public interface ImageProvider { + /** + * 下载图片 + * + * @param imageView + * @param url + * @param callback + */ + void load(final Context context, final WeakReference imageView, final String url, final WeakReference callback); + + /** + * load a bitmap + * + * @param context + * @param url + * @param callback + */ +// void loadBitmap(final Context context, final String url, final WeakReference callback); + + /** + * 预下载图片 + * + * @param context + * @param url + * @param callback + */ + void preload(final Context context, final String url, final DrawableLoadCallback callback); + + /** + * pause all requests + * + * @param context + */ + void pauseRequests(final ViewGroup view, final Context context); + + /** + * resume all requests + * + * @param context + */ + void resumeRequests(final ViewGroup view, final Context context); + + +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/receiver/ConnectionStateChangeBroadcastReceiver.java b/Android/LuaViewSDK/src/com/taobao/luaview/receiver/ConnectionStateChangeBroadcastReceiver.java new file mode 100644 index 00000000..ee9cdd9f --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/receiver/ConnectionStateChangeBroadcastReceiver.java @@ -0,0 +1,117 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.receiver; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; + +import com.taobao.luaview.util.NetworkUtil; + +import java.lang.ref.WeakReference; +import java.util.concurrent.ConcurrentSkipListMap; + +/** + * 监听网络状态变化 + * + * @author song + */ +public class ConnectionStateChangeBroadcastReceiver extends BroadcastReceiver { + private ConcurrentSkipListMap> mOnConnectionChangeListeners; + + public interface OnConnectionChangeListener { + void onConnectionClosed();//所有的连接都断开 + + void onMobileConnected();//连接到移动网络 + + void onWifiConnected();//连接到wifi + } + + public ConnectionStateChangeBroadcastReceiver() { + this.mOnConnectionChangeListeners = new ConcurrentSkipListMap>(); + } + + public void addOnConnectionChangeListener(OnConnectionChangeListener listener) { + final Integer hashCode = listener != null ? listener.hashCode() : null; + if (hashCode != null) {//有效 + WeakReference onConnectionChangeListenerWeakReference = mOnConnectionChangeListeners != null ? mOnConnectionChangeListeners.get(hashCode) : null; + if (onConnectionChangeListenerWeakReference == null || onConnectionChangeListenerWeakReference.get() == null) {//没有加过 + mOnConnectionChangeListeners.put(hashCode, new WeakReference(listener)); + } + } + } + + public void removeOnConnectionChangeListener(OnConnectionChangeListener listener) { + final Integer hashCode = listener != null ? listener.hashCode() : null; + if (hashCode != null && mOnConnectionChangeListeners != null) { + this.mOnConnectionChangeListeners.remove(hashCode); + } + } + + /** + * 获得listener size + * + * @return + */ + public int getListenerSize() { + return mOnConnectionChangeListeners != null ? mOnConnectionChangeListeners.size() : 0; + } + + @Override + public void onReceive(final Context context, Intent intent) { + if (this.mOnConnectionChangeListeners != null) { + WeakReference listenerWeakReference = null; + if (intent.getAction().equals(Intent.ACTION_SHUTDOWN)) { + for (Integer key : mOnConnectionChangeListeners.keySet()) { + listenerWeakReference = mOnConnectionChangeListeners.get(key); + if (listenerWeakReference != null && listenerWeakReference.get() != null) { + listenerWeakReference.get().onConnectionClosed(); + } + } + } else { + final NetworkUtil.NetworkType currentNetworkType = NetworkUtil.getCurrentType(context); + switch (currentNetworkType) { + case NETWORK_2G: + case NETWORK_3G: + case NETWORK_4G: { + for (Integer key : mOnConnectionChangeListeners.keySet()) { + listenerWeakReference = mOnConnectionChangeListeners.get(key); + if (listenerWeakReference != null && listenerWeakReference.get() != null) { + listenerWeakReference.get().onMobileConnected(); + } + } + break; + } + case NETWORK_WIFI: { + for (Integer key : mOnConnectionChangeListeners.keySet()) { + listenerWeakReference = mOnConnectionChangeListeners.get(key); + if (listenerWeakReference != null && listenerWeakReference.get() != null) { + listenerWeakReference.get().onWifiConnected(); + } + } + break; + } + case NETWORK_NONE: { + for (Integer key : mOnConnectionChangeListeners.keySet()) { + listenerWeakReference = mOnConnectionChangeListeners.get(key); + if (listenerWeakReference != null && listenerWeakReference.get() != null) { + listenerWeakReference.get().onConnectionClosed(); + } + } + break; + } + case NETWORK_UNKNOWN: + break; + default: + break; + } + } + } + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/scriptbundle/LuaScriptManager.java b/Android/LuaViewSDK/src/com/taobao/luaview/scriptbundle/LuaScriptManager.java new file mode 100644 index 00000000..f8cfb7dd --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/scriptbundle/LuaScriptManager.java @@ -0,0 +1,359 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.scriptbundle; + +import android.content.Context; +import android.os.Environment; +import android.text.TextUtils; + +import com.taobao.luaview.global.LuaViewConfig; +import com.taobao.luaview.util.EncryptUtil; +import com.taobao.luaview.util.FileUtil; + +import java.io.File; + +/** + * Lua脚本管理类 + * + * @author song + * @date 15/11/9 + */ +public class LuaScriptManager { + private static String BASE_FILECACHE_PATH; + private static String BASE_PREDOWNLOAD_FILECACHE_PATH;//预下载都使用data/data目录 + //folders + private static final String PACKAGE_NAME_DEFAULT = "luaview"; + public static final String FOLDER_SCRIPT = "script"; + public static final String FOLDER_PRE_DOWNLOAD = "predownload"; + + //默认缓存文件的后缀 + public static final String POSTFIX_SCRIPT_BUNDLE = ".lvraw"; + public static final String POSTFIX_JPG = ".jpg"; + public static final String POSTFIX_APK = ".apk"; + public static final String POSTFIX_PNG = ".png"; + public static final String POSTFIX_LOG = ".log"; + public static final String POSTFIX_LUA = ".lua"; + public static final String POSTFIX_B_LUA = ".blua"; + public static final String POSTFIX_LV = ".lv";//Lua加密脚本(source or bytecode) + public static final String POSTFIX_LV_ZIP = ".zip";//lua的zip包 + public static final String POSTFIX_LV_BYTECODE_ZIP = ".bzip";//lua的二进制zip包 + public static final String POSTFIX_LV_STANDARD_SYNTAX_ZIP = ".szip";//标准语法的zip包 + public static final String POSTFIX_SIGN = ".sign"; + + /** + * 初始化 + * + * @param context + */ + public static void init(final Context context) { + if (TextUtils.isEmpty(BASE_FILECACHE_PATH) && context != null) { + if (!LuaViewConfig.isDebug()) {//真实环境优先使用data/data目录 + initInternalFilePath(context); + } else {//测试环境优先使用sd卡路径 + if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) { + BASE_FILECACHE_PATH = context.getExternalCacheDir() + File.separator; + + //base predownload path +// final File file = context.getDir(PACKAGE_NAME_DEFAULT, Context.MODE_PRIVATE); +// if(file != null) { +// BASE_PREDOWNLOAD_FILECACHE_PATH = file.getPath() + File.separator; +// } else { +// BASE_PREDOWNLOAD_FILECACHE_PATH = context.getCacheDir() + File.separator; +// } + + BASE_PREDOWNLOAD_FILECACHE_PATH = "/data/data/" + context.getPackageName() + "/app_luaview/"; + } else { + initInternalFilePath(context); + } + } + } + } + + /** + * 初始化内部存储目录路径 + * + * @param context + */ + private static void initInternalFilePath(Context context) { + final File dir = context.getDir(PACKAGE_NAME_DEFAULT, Context.MODE_PRIVATE); + if (dir != null) {//优先存在 data/data/packagename/app_luaview + BASE_FILECACHE_PATH = dir.getPath() + File.separator; + } else { + BASE_FILECACHE_PATH = context.getCacheDir() + File.separator; + } + + BASE_PREDOWNLOAD_FILECACHE_PATH = BASE_FILECACHE_PATH; + } + //--------------------------------static methods for get file path------------------------------ + + /** + * 获取基础文件路径 + * + * @return + */ + public static String getBaseFilePath() { + return BASE_FILECACHE_PATH + PACKAGE_NAME_DEFAULT + File.separator; + } + + /** + * get scriptFolderPath + * + * @return + */ + public static String getBaseScriptFolderPath() { + return BASE_FILECACHE_PATH + PACKAGE_NAME_DEFAULT + File.separator + FOLDER_SCRIPT + File.separator; + } + + /** + * get predownload folder path + * + * @return + */ + public static String getBasePredownloadFolderPath() { + return BASE_PREDOWNLOAD_FILECACHE_PATH + FOLDER_PRE_DOWNLOAD + File.separator; + } + + /** + * get path of given folder + * + * @param subFolderName + * @return + */ + public static String getFolderPath(final String subFolderName) { + return new StringBuffer() + .append(getBaseScriptFolderPath()) + .append(subFolderName) + .append(File.separator) + .toString(); + } + + /** + * get file path + * + * @param subFolderName + * @param fileNameWithPostfix + * @return + */ + public static String getFilePath(final String subFolderName, final String fileNameWithPostfix) { + return new StringBuffer() + .append(getFolderPath(subFolderName)) + .append(fileNameWithPostfix) + .toString(); + } + + /** + * get pre downloaded file path + * + * @param fileNameWithPostfix + * @return + */ + public static String getPredownloadFilePath(String fileNameWithPostfix) { + return new StringBuffer() + .append(getBasePredownloadFolderPath()) + .append(fileNameWithPostfix).toString(); + } + + + /** + * 构建文件名称 + * + * @param nameWithoutPostfix 不带后缀的文件名称 + * @param postfixWithDot 带点的文件后缀 + * @return + */ + public static String buildFileName(final String nameWithoutPostfix, final String postfixWithDot) { + return new StringBuffer().append(nameWithoutPostfix).append(postfixWithDot).toString(); + } + + + //------------------------------------------script function------------------------------------- + + /** + * 根据Url构建ScriptBundle 的文件名称 + * + * @param uri + * @return + */ + public static String buildScriptBundleFileName(final String uri) { + return buildFileName(EncryptUtil.md5Hex(uri), LuaScriptManager.POSTFIX_SCRIPT_BUNDLE); + } + + /** + * 根据Url构建ScriptBundle的文件路径名称 + * + * @param uri + * @return + */ + public static String buildScriptBundleFolderPath(final String uri) { + final String fileNameWithoutPostfix = EncryptUtil.md5Hex(uri); + final String folderName = fileNameWithoutPostfix;//使用文件名作为子目录的名称//new StringBuffer().append(FOLDER_SCRIPT).append(File.separator).append(fileNameWithoutPostfix).toString(); + return getFolderPath(folderName); + } + + /** + * 构建脚本文件文件名 + * + * @param uri + * @return + */ + public static String buildScriptBundleFilePath(final String uri) { + final String fileNameWithoutPostfix = EncryptUtil.md5Hex(uri); + final String folderName = fileNameWithoutPostfix;//使用文件名作为子目录的名称//new StringBuffer().append(FOLDER_SCRIPT).append(File.separator).append(fileNameWithoutPostfix).toString(); + final String fileName = buildFileName(fileNameWithoutPostfix, POSTFIX_SCRIPT_BUNDLE); + return getFilePath(folderName, fileName); + } + + + /** + * 构建预下载脚本文件名(这里直接使用脚本地址,不做任何修改) + * + * @param uri + * @return + */ + public static String buildPredownloadScriptBundleFilePath(final String uri) { + if (uri != null) { + String fileName = uri.substring(uri.lastIndexOf('/') + 1);//只取最后的文件名 + return getPredownloadFilePath(fileName); + } else { + return null; + } + } + + //------------------------------------------exists---------------------------------------------- + + /** + * Script Bundle 是否存在 + * + * @param uri + * @return + */ + public static boolean existsScriptBundle(final String uri) { + if (!TextUtils.isEmpty(uri)) { + return FileUtil.exists(buildScriptBundleFilePath(uri)); + } + return false; + } + + /** + * 预下载目录下的某个文件是否存在 + * + * @param uri + * @return + */ + public static boolean existsPredownloadBundle(final String uri) { + if (!TextUtils.isEmpty(uri)) { + return FileUtil.exists(buildPredownloadScriptBundleFilePath(uri)); + } + return false; + } + + //--------------------------------------------判断函数------------------------------------------- + + /** + * 是否是lua脚本包 + * + * @param fileName + * @return + */ + public static boolean isLuaScriptBundle(final String fileName) { + return FileUtil.isSuffix(fileName, LuaScriptManager.POSTFIX_SCRIPT_BUNDLE); + } + + /** + * 是否是lua的zip包(zip,bzip,szip) + * + * @param fileName + * @return + */ + public static boolean isLuaScriptZip(final String fileName) { + return FileUtil.isSuffix(fileName, LuaScriptManager.POSTFIX_LV_ZIP) + || FileUtil.isSuffix(fileName, LuaScriptManager.POSTFIX_LV_BYTECODE_ZIP) + || FileUtil.isSuffix(fileName, LuaScriptManager.POSTFIX_LV_STANDARD_SYNTAX_ZIP); + } + + /** + * 是否是lua 二进制zip包 + * + * @param url + * @return + */ + public static boolean isLuaBytecodeUrl(final String url) { + return FileUtil.isSuffix(url, LuaScriptManager.POSTFIX_LV_BYTECODE_ZIP); + } + + public static boolean isLuaBytecodeFile(final String fileName) { + return FileUtil.isSuffix(fileName, LuaScriptManager.POSTFIX_B_LUA); + } + + /** + * 是否是标准语法的 zip包 + * + * @param url + * @return + */ + public static boolean isLuaStandardSyntaxUrl(final String url) { + return FileUtil.isSuffix(url, LuaScriptManager.POSTFIX_LV_STANDARD_SYNTAX_ZIP); + } + + /** + * 是否是非标准语法的 zip包 + * + * @param url + * @return + */ + public static boolean isLuaUnStandardSyntaxUrl(final String url) { + return FileUtil.isSuffix(url, LuaScriptManager.POSTFIX_LV_ZIP);//只有zip包是非标准包,bzip、szip都认为是标准,bzip有问题么? + } + + + /** + * 是否是lua加密脚本 + * + * @param fileName + * @return + */ + public static boolean isLuaEncryptScript(final String fileName) { + return FileUtil.isSuffix(fileName, LuaScriptManager.POSTFIX_LV); + } + + /** + * 是否是普通lua文件 + * + * @param fileName + * @return + */ + public static boolean isLuaScript(final String fileName) { + return FileUtil.isSuffix(fileName, LuaScriptManager.POSTFIX_LUA); + } + + /** + * 签名文件 + * + * @param fileName + * @return + */ + public static boolean isLuaSignFile(final String fileName) { + return FileUtil.isSuffix(fileName, LuaScriptManager.POSTFIX_SIGN); + } + + /** + * 改变filename的名称 + * + * @param fileName + * @param newSuffix + * @return + */ + public static String changeSuffix(final String fileName, final String newSuffix) { + if (fileName != null && fileName.lastIndexOf('.') != -1) { + return fileName.substring(0, fileName.lastIndexOf('.')) + newSuffix; + } + return fileName; + } + +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/scriptbundle/ScriptBundle.java b/Android/LuaViewSDK/src/com/taobao/luaview/scriptbundle/ScriptBundle.java new file mode 100644 index 00000000..fbe0b330 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/scriptbundle/ScriptBundle.java @@ -0,0 +1,110 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.scriptbundle; + +import com.taobao.luaview.scriptbundle.asynctask.SimpleTask1; +import com.taobao.luaview.util.FileUtil; + +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; + +/** + * 脚本文件包,每一个加载的脚本包,加载成功后返回该bundle + * + * @author song + * @date 15/11/10 + */ +public class ScriptBundle { + //脚本网络地址 + private String mUrl; + + //脚本本地地址 + private String mBaseFilePath; + + //脚本文件 + private HashMap mScriptFileMap; + + //是否是bytecode + private boolean isBytecode; + + //config,TODO 可以根据脚本包里的配置来控制虚拟机的运行 + private Properties mProps; + + public ScriptBundle() { + mScriptFileMap = new HashMap(); + } + + public ScriptBundle addScript(ScriptFile scriptFile) { + if (mScriptFileMap != null) { + mScriptFileMap.put(scriptFile.fileName, scriptFile); + } + return this; + } + + public int size() { + return mScriptFileMap != null ? mScriptFileMap.size() : 0; + } + + public void setUrl(String url) { + this.mUrl = url; + } + + public void setBytecode(boolean isBytecode) { + this.isBytecode = isBytecode; + } + + public void setBaseFilePath(String mBaseFilePath) { + this.mBaseFilePath = mBaseFilePath; + } + + public String getBaseFilePath() { + return mBaseFilePath; + } + + public String getUrl() { + return mUrl; + } + + public boolean isBytecode() { + return isBytecode; + } + + public Map getScriptFileMap() { + return mScriptFileMap; + } + + public boolean containsKey(final String key) { + return mScriptFileMap != null && mScriptFileMap.containsKey(key); + } + + public ScriptFile getScriptFile(final String key) { + return mScriptFileMap != null ? mScriptFileMap.get(key) : null; + } + + public void saveToFile(final String path) { + if (path != null) { + if (mScriptFileMap != null) { + new SimpleTask1() { + @Override + protected Object doInBackground(Object... params) { + ScriptFile file = null; + for (String key : mScriptFileMap.keySet()) { + file = mScriptFileMap.get(key); + if (file != null) { + FileUtil.save(path + "/" + file.fileName, file.scriptData); + } + } + return null; + } + }.executeInPool(); + } + } + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/scriptbundle/ScriptFile.java b/Android/LuaViewSDK/src/com/taobao/luaview/scriptbundle/ScriptFile.java new file mode 100644 index 00000000..568ebf4b --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/scriptbundle/ScriptFile.java @@ -0,0 +1,80 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.scriptbundle; + +import org.luaj.vm2.Prototype; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; + +/** + * 脚本文件类,封装了从服务端下发的脚本,包含脚本名称以及对应的代码 + * + * @author song + * @date 15/11/10 + */ +public class ScriptFile { + //脚本的下载地址 + public String url; + + //脚本文件本地地址 + public String baseFilePath; + + //文件名称 + public String fileName; + + //sign file name + public String signFileName; + + //语法树原型 + public Prototype prototype; + + //lua源码二进制数据 + public byte[] scriptData; + + //lua源码对应的加密数据 + public byte[] signData; + + + public ScriptFile(final String script, final String fileName) { + this(null, null, fileName, script != null ? script.getBytes() : null); + } + + public ScriptFile(final String url, final String baseFilePath, final String fileName, final byte[] scriptData) { + this(url, baseFilePath, fileName, scriptData, null); + } + + public ScriptFile(final String url, final String baseFilePath, final String fileName, final byte[] scriptData, final byte[] signData) { + this.url = url; + this.baseFilePath = baseFilePath; + this.fileName = LuaScriptManager.changeSuffix(fileName, LuaScriptManager.POSTFIX_LUA);//main.lv->main.lua 这里使用真实的lua脚本名称,因为这里的脚本都是被解密过的 + this.signFileName = fileName + LuaScriptManager.POSTFIX_SIGN;//sign文件名称, 使用的是fileName,main.lv.sign + this.scriptData = scriptData; + this.signData = signData; + } + + public String getScriptString() { + return this.scriptData != null ? new String(this.scriptData) : null; + } + + public String getFilePath() { + if(baseFilePath != null && baseFilePath.endsWith("/")) { + return new StringBuffer().append(baseFilePath).append(fileName).toString(); + } else { + return new StringBuffer().append(baseFilePath).append("/").append(fileName).toString(); + } + } + + public InputStream getInputStream() { + if (scriptData != null) { + return new ByteArrayInputStream(scriptData); + } + return null; + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/scriptbundle/asynctask/BaseAsyncTask.java b/Android/LuaViewSDK/src/com/taobao/luaview/scriptbundle/asynctask/BaseAsyncTask.java new file mode 100644 index 00000000..7622ac44 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/scriptbundle/asynctask/BaseAsyncTask.java @@ -0,0 +1,28 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.scriptbundle.asynctask; + +import android.os.AsyncTask; + +/** + * 简单任务封装 + * + * @author song + */ +public abstract class BaseAsyncTask extends AsyncTask { + + public void executeInPool(Params... values) { + super.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, values); + } + + public void executeSerial(Params...values){ + super.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR, values); + } + +} \ No newline at end of file diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/scriptbundle/asynctask/ScriptBundleDownloadTask.java b/Android/LuaViewSDK/src/com/taobao/luaview/scriptbundle/asynctask/ScriptBundleDownloadTask.java new file mode 100644 index 00000000..62012aab --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/scriptbundle/asynctask/ScriptBundleDownloadTask.java @@ -0,0 +1,76 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.scriptbundle.asynctask; + +import android.content.Context; + +import com.taobao.luaview.global.LuaScriptLoader; +import com.taobao.luaview.scriptbundle.asynctask.delegate.ScriptBundleDownloadDelegate; +import com.taobao.luaview.util.DebugUtil; + +/** + * download lua script bundle from server and return saved path in local file system + * + * @author song + */ +public class ScriptBundleDownloadTask extends BaseAsyncTask { + private Context mContext; + private LuaScriptLoader.ScriptLoaderCallback mScriptLoaderCallback; + + public ScriptBundleDownloadTask(final Context context, LuaScriptLoader.ScriptLoaderCallback callback) { + if (context != null) { + mContext = context.getApplicationContext(); + } + mScriptLoaderCallback = callback; + } + + /** + * 接受两个参数,第一个是下载的url,第二个是sha256 + * + * @param params + * @return + */ + @Override + protected String doInBackground(String... params) { + DebugUtil.tsi("luaviewp-scriptDownloadTask"); + + final String url = params[0]; + final String sha256 = params.length > 1 ? params[1] : null; + + if (new ScriptBundleDownloadDelegate(url, sha256).download()) { + return url; + } else { + return null; + } + } + + @Override + protected void onCancelled() { + callLoaderCallback(null); + } + + @Override + protected void onCancelled(String s) { + callLoaderCallback(s); + } + + @Override + protected void onPostExecute(String url) { + DebugUtil.tei("luaviewp-scriptDownloadTask"); + callLoaderCallback(url); + } + + private void callLoaderCallback(String url) { + if (url != null) {//如果下载保存成功,则进行解包操作(不论是否需要请求回调 ) + new ScriptBundleUnpackTask(mContext, mScriptLoaderCallback).executeInPool(url); + } else if (mScriptLoaderCallback != null) { + mScriptLoaderCallback.onScriptLoaded(null); + } + } +} \ No newline at end of file diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/scriptbundle/asynctask/ScriptBundleLoadTask.java b/Android/LuaViewSDK/src/com/taobao/luaview/scriptbundle/asynctask/ScriptBundleLoadTask.java new file mode 100644 index 00000000..69ef8d5f --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/scriptbundle/asynctask/ScriptBundleLoadTask.java @@ -0,0 +1,124 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.scriptbundle.asynctask; + +import android.content.Context; + +import com.taobao.luaview.cache.AppCache; +import com.taobao.luaview.global.LuaScriptLoader; +import com.taobao.luaview.scriptbundle.LuaScriptManager; +import com.taobao.luaview.scriptbundle.ScriptBundle; +import com.taobao.luaview.scriptbundle.ScriptFile; +import com.taobao.luaview.scriptbundle.asynctask.delegate.ScriptBundleLoadDelegate; +import com.taobao.luaview.scriptbundle.asynctask.delegate.ScriptBundleUnpackDelegate; +import com.taobao.luaview.util.DebugUtil; +import com.taobao.luaview.util.DecryptUtil; +import com.taobao.luaview.util.FileUtil; +import com.taobao.luaview.util.IOUtil; +import com.taobao.luaview.util.VerifyUtil; +import com.taobao.luaview.util.ZipUtil; + +import org.luaj.vm2.LoadState; +import org.luaj.vm2.LuaError; +import org.luaj.vm2.Prototype; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.util.Map; + +/** + * 从文件系统中读取lua byte code文件,做签名验证,验证成功后,返回prototype + * + * @author song + * @date 15/11/9 + *

+ * 1. 从文件读取给定目录下的prototype,读取的同时做签名校验(AES256) + * 2. 签名验证成功的文件,做unzip操作,获取需要返回的数据 + */ +public class ScriptBundleLoadTask extends BaseAsyncTask { + private static final String CACHE_SCRIPTS = AppCache.CACHE_SCRIPTS; + private Context mContext; + + //加载的脚本 + private LuaScriptLoader.ScriptLoaderCallback mScriptLoaderCallback; + + public ScriptBundleLoadTask(Context context, LuaScriptLoader.ScriptLoaderCallback scriptLoaderCallback) { + if (context != null) { + this.mContext = context.getApplicationContext(); + } + this.mScriptLoaderCallback = scriptLoaderCallback; + } + + + /** + * 接受两个参数,第一个是存储的地址,第二个是脚本解析的列表 + * + * @param params + * @return + */ + @Override + protected ScriptBundle doInBackground(Object... params) { + final Object param0 = (params != null && params.length > 0) ? params[0] : null; + ScriptBundle scriptBundle = (param0 instanceof ScriptBundle) ? (ScriptBundle) param0 : null;//首先判断脚本解析的列表是否存在(下载即加载的情形) + final String url = (param0 instanceof String) ? (String) param0 : null; + String destFolderPath = null; + if (scriptBundle == null) {//不是下载即加载的情况 + destFolderPath = LuaScriptManager.buildScriptBundleFolderPath(url); + + scriptBundle = AppCache.getCache(CACHE_SCRIPTS).getLru(url); + if (scriptBundle != null) { + return scriptBundle; + } else { + DebugUtil.tsi("luaviewp-loadBundle"); + + scriptBundle = ScriptBundleUnpackDelegate.loadBundle(LuaScriptManager.isLuaBytecodeUrl(url), url, destFolderPath);//TODO 性能瓶颈 + + DebugUtil.tei("luaviewp-loadBundle"); + } + } + + scriptBundle = new ScriptBundleLoadDelegate().load(mContext, scriptBundle);//解密脚本或者加载Prototype + + if(scriptBundle != null) { + if (url != null) { + scriptBundle.setUrl(url); + } + if (destFolderPath != null) { + scriptBundle.setBaseFilePath(destFolderPath); + } + + //cache + AppCache.getCache(CACHE_SCRIPTS).putLru(url != null ? url : scriptBundle.getUrl(), scriptBundle); + } + return scriptBundle; + } + + + @Override + protected void onCancelled() { + callLoaderCallback(null); + + } + + @Override + protected void onCancelled(ScriptBundle scriptBundle) { + callLoaderCallback(scriptBundle); + } + + @Override + protected void onPostExecute(ScriptBundle unzippedScripts) { + callLoaderCallback(unzippedScripts); + } + + private void callLoaderCallback(ScriptBundle unzippedScripts) { + if (mScriptLoaderCallback != null) { + mScriptLoaderCallback.onScriptLoaded(unzippedScripts); + } + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/scriptbundle/asynctask/ScriptBundleUltimateLoadTask.java b/Android/LuaViewSDK/src/com/taobao/luaview/scriptbundle/asynctask/ScriptBundleUltimateLoadTask.java new file mode 100644 index 00000000..a58caacd --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/scriptbundle/asynctask/ScriptBundleUltimateLoadTask.java @@ -0,0 +1,259 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.scriptbundle.asynctask; + +import android.content.Context; +import android.support.annotation.Nullable; +import android.webkit.URLUtil; + +import com.taobao.luaview.cache.AppCache; +import com.taobao.luaview.global.LuaScriptLoader; +import com.taobao.luaview.scriptbundle.LuaScriptManager; +import com.taobao.luaview.scriptbundle.ScriptBundle; +import com.taobao.luaview.scriptbundle.asynctask.delegate.ScriptBundleDownloadDelegate; +import com.taobao.luaview.scriptbundle.asynctask.delegate.ScriptBundleLoadDelegate; +import com.taobao.luaview.scriptbundle.asynctask.delegate.ScriptBundleUnpackDelegate; +import com.taobao.luaview.util.AssetUtil; +import com.taobao.luaview.util.DebugUtil; +import com.taobao.luaview.util.FileUtil; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.RandomAccessFile; +import java.net.HttpURLConnection; + +/** + * download lua script bundle from server and load as a ScriptBundle + * + * @author song + */ +public class ScriptBundleUltimateLoadTask extends BaseAsyncTask { + private Context mContext; + private LuaScriptLoader.ScriptLoaderCallback mScriptLoaderCallback; + private String mPackageName; + + public ScriptBundleUltimateLoadTask(Context context, LuaScriptLoader.ScriptLoaderCallback scriptLoaderCallback) { + if (context != null) { + this.mContext = context.getApplicationContext(); + } + this.mScriptLoaderCallback = scriptLoaderCallback; + } + + public void load(String... params) { + super.executeInPool(params); + } + + public void loadAsset(String... params) { + super.executeInPool(params); + } + + /** + * 接受两个参数,第一个是下载的url,第二个是存储的地址 + * + * @param params + * @return + */ + @Override + public ScriptBundle doInBackground(String... params) { + DebugUtil.tsi("luaviewp-ScriptBundleUltimateLoadTask"); + + final String urlOrAssetPath = params[0]; + final String destFolderPath = LuaScriptManager.buildScriptBundleFolderPath(urlOrAssetPath); + final String sha256 = params.length > 1 ? params[1] : null; + + ScriptBundle scriptBundle = null; + + if (LuaScriptManager.existsScriptBundle(urlOrAssetPath)) {//读取并加载,之前的脚本 + scriptBundle = AppCache.getCache(AppCache.CACHE_SCRIPTS).getLru(urlOrAssetPath); + if (scriptBundle != null) { + + callLoaderCallbackOnEvent(LuaScriptLoader.LuaScriptLoadEvent.EVENT_LOAD_CACHE, scriptBundle); + return scriptBundle; + } else { + DebugUtil.tsi("luaviewp-loadBundle"); + + scriptBundle = ScriptBundleUnpackDelegate.loadBundle(LuaScriptManager.isLuaBytecodeUrl(urlOrAssetPath), urlOrAssetPath, destFolderPath);//TODO 性能瓶颈 + + DebugUtil.tei("luaviewp-loadBundle"); + + callLoaderCallbackOnEvent(LuaScriptLoader.LuaScriptLoadEvent.EVENT_LOAD_LOCAL, scriptBundle); + } + + } else if (LuaScriptManager.existsPredownloadBundle(urlOrAssetPath)) {//预先加载的地址有脚本,则尝试解压并加载 xxx.zip + scriptBundle = AppCache.getCache(AppCache.CACHE_SCRIPTS).getLru(urlOrAssetPath); + if (scriptBundle != null) { + callLoaderCallbackOnEvent(LuaScriptLoader.LuaScriptLoadEvent.EVENT_LOAD_CACHE, scriptBundle); + return scriptBundle; + } else { + DebugUtil.tsi("luaviewp-loadPredownloadBundle"); + + String uri = LuaScriptManager.buildPredownloadScriptBundleFilePath(urlOrAssetPath); + InputStream inputStream = FileUtil.open(uri); + scriptBundle = ScriptBundleUnpackDelegate.unpack(urlOrAssetPath, inputStream); + + DebugUtil.tei("luaviewp-loadPredownloadBundle"); + + callLoaderCallbackOnEvent(LuaScriptLoader.LuaScriptLoadEvent.EVENT_LOAD_PREDOWNLOAD, scriptBundle); + } + } else if (URLUtil.isAssetUrl(urlOrAssetPath) && AssetUtil.exists(mContext, urlOrAssetPath)) {//asset file exists + if (LuaScriptManager.isLuaScriptZip(urlOrAssetPath)) {//asset下的包加载 + scriptBundle = ScriptBundleUnpackDelegate.unpack(mContext, FileUtil.removePostfix(urlOrAssetPath), urlOrAssetPath); + } + + callLoaderCallbackOnEvent(LuaScriptLoader.LuaScriptLoadEvent.EVENT_LOAD_ASSET, scriptBundle); + } else {//下载解压加载 + + // Assert 预置包 + // loadAssertScriptBundle(); + + // 下载包 + callLoaderCallbackOnEvent(LuaScriptLoader.LuaScriptLoadEvent.EVENT_DOWNLOAD_START, null); + + // download + ScriptBundleDownloadDelegate downloadDelegate = new ScriptBundleDownloadDelegate(urlOrAssetPath, sha256); + HttpURLConnection connection = downloadDelegate.createHttpUrlConnection(); + InputStream inputStream = downloadDelegate.downloadAsStream(connection); + + if (inputStream != null) { + scriptBundle = ScriptBundleUnpackDelegate.unpack(urlOrAssetPath, inputStream);//unpack + } + + if (connection != null) { + connection.disconnect(); + } + + //下载结束 + callLoaderCallbackOnEvent(LuaScriptLoader.LuaScriptLoadEvent.EVENT_DOWNLOAD_END, scriptBundle); + } + + scriptBundle = new ScriptBundleLoadDelegate().load(mContext, scriptBundle);//解密脚本或者加载Prototype + + if (scriptBundle != null) { + + if (urlOrAssetPath != null) { + scriptBundle.setUrl(urlOrAssetPath); + scriptBundle.setBaseFilePath(destFolderPath); + } + + //cache + AppCache.getCache(AppCache.CACHE_SCRIPTS).putLru(urlOrAssetPath != null ? urlOrAssetPath : scriptBundle.getUrl(), scriptBundle); + } + + return scriptBundle; + } + + + @Nullable + private void loadAssertScriptBundle() { + if (mPackageName != null && mScriptLoaderCallback instanceof LuaScriptLoader.ScriptLoaderCallback2) {//有预置包则先加载预置的 + String assetPackageName = LuaScriptManager.buildFileName(mPackageName, LuaScriptManager.POSTFIX_LV_STANDARD_SYNTAX_ZIP);//szip,只处理szip,TODO处理其他类型zip + if (LuaScriptManager.isLuaScriptZip(assetPackageName)) {//asset下的包加载 + ScriptBundle scriptBundle = ScriptBundleUnpackDelegate.unpack(mContext, FileUtil.removePostfix(assetPackageName), "luaview" + File.separator + assetPackageName); + + if (scriptBundle != null) { + + scriptBundle = new ScriptBundleLoadDelegate().load(mContext, scriptBundle); + + //call callback when asset's script loaded + callLoaderCallbackWhenAssetLoaded((LuaScriptLoader.ScriptLoaderCallback2) mScriptLoaderCallback, scriptBundle); + } + } + } + } + + + private void saveFileUsingFileOutputStream(File destFile, byte[] fileData) { + FileOutputStream output = null; + try { + output = new FileOutputStream(destFile); + output.write(fileData); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } finally { + if (output != null) { + try { + output.flush(); + output.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } + + /** + * save file + * + * @param destFile + * @param fileData + */ + private void saveFileUsingRandomAccessFile(File destFile, byte[] fileData) { + try { + RandomAccessFile randomAccessFile = new RandomAccessFile(destFile, "rw"); + randomAccessFile.write(fileData); + randomAccessFile.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Override + protected void onCancelled() { + callLoaderCallback(null); + } + + @Override + protected void onCancelled(ScriptBundle scriptBundle) { + callLoaderCallback(scriptBundle); + } + + @Override + protected void onPostExecute(ScriptBundle unzippedScripts) { + DebugUtil.tei("luaviewp-ScriptBundleUltimateLoadTask"); + callLoaderCallback(unzippedScripts); + } + + /** + * 事件回调 + * @param event + * @param args + */ + private void callLoaderCallbackOnEvent(LuaScriptLoader.LuaScriptLoadEvent event, Object args){ + if(mScriptLoaderCallback instanceof LuaScriptLoader.ScriptLoaderCallback2){ + ((LuaScriptLoader.ScriptLoaderCallback2) mScriptLoaderCallback).onEvent(event, args); + } + } + + /** + * 加载结束 + * + * @param unzippedScripts + */ + private void callLoaderCallback(ScriptBundle unzippedScripts) { + if (mScriptLoaderCallback != null) { + mScriptLoaderCallback.onScriptLoaded(unzippedScripts); + } + } + + private void callLoaderCallbackWhenAssetLoaded(final LuaScriptLoader.ScriptLoaderCallback2 callback, final ScriptBundle bundle) { +// LuaViewUtil.runOnUiThread(mContext, new Runnable() { +// @Override +// public void run() { +// if (callback != null) { +// callback.onAssetScriptLoaded(bundle); +// } +// } +// }); + } +} \ No newline at end of file diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/scriptbundle/asynctask/ScriptBundleUnpackTask.java b/Android/LuaViewSDK/src/com/taobao/luaview/scriptbundle/asynctask/ScriptBundleUnpackTask.java new file mode 100644 index 00000000..826f0c22 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/scriptbundle/asynctask/ScriptBundleUnpackTask.java @@ -0,0 +1,85 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.scriptbundle.asynctask; + +import android.content.Context; +import android.content.res.AssetManager; + +import com.taobao.luaview.global.LuaScriptLoader; +import com.taobao.luaview.scriptbundle.LuaScriptManager; +import com.taobao.luaview.scriptbundle.ScriptBundle; +import com.taobao.luaview.scriptbundle.asynctask.delegate.ScriptBundleUnpackDelegate; +import com.taobao.luaview.util.FileUtil; + +import java.io.File; + +/** + * 将下发的脚本bundle解压到本地文件系统,下发源码的时候才使用 + * + * @author song + *

+ * 1. 将输入流根据(文件名,data)的格式解出到文件 + * 2. 将输入流保存的签名信息(文件名,sign)解出到文件 + */ +public class ScriptBundleUnpackTask extends BaseAsyncTask { + private Context mContext; + private LuaScriptLoader.ScriptLoaderCallback mScriptLoaderCallback; + + public ScriptBundleUnpackTask(final Context context) { + this(context, null); + } + + public ScriptBundleUnpackTask(final Context context, final LuaScriptLoader.ScriptLoaderCallback scriptLoaderCallback) { + if (context != null) { + this.mContext = context.getApplicationContext(); + } + this.mScriptLoaderCallback = scriptLoaderCallback; + } + + /** + * 接受一个参数,加载的脚本根目录 + * + * @param params + * @return + */ + @Override + protected ScriptBundle doInBackground(Object... params) { + if (params != null && params.length > 0) {//一个参数,指定文件路径 + final String url = (String) params[0]; + final String asset = params.length > 1 ? String.valueOf(params[1]) : null; + return ScriptBundleUnpackDelegate.unpack(mContext, url, asset); + } + return null; + } + + @Override + protected void onPostExecute(ScriptBundle bundle) { + callLoaderCallback(bundle); + } + + @Override + protected void onCancelled() { + callLoaderCallback(null); + } + + @Override + protected void onCancelled(ScriptBundle bundle) { + callLoaderCallback(bundle); + } + + private void callLoaderCallback(ScriptBundle bundle) { + if (mScriptLoaderCallback != null) { + if (bundle != null && bundle.size() > 0) {//启动loader task + new ScriptBundleLoadTask(mContext, mScriptLoaderCallback).executeInPool(bundle); + } else { + mScriptLoaderCallback.onScriptLoaded(null); + } + } + } +} \ No newline at end of file diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/scriptbundle/asynctask/SimpleTask.java b/Android/LuaViewSDK/src/com/taobao/luaview/scriptbundle/asynctask/SimpleTask.java new file mode 100644 index 00000000..f9bfcf78 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/scriptbundle/asynctask/SimpleTask.java @@ -0,0 +1,25 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.scriptbundle.asynctask; + +/** + * 简单任务封装 + * + * @author song + */ +public abstract class SimpleTask extends BaseAsyncTask { + + @Override + protected Object doInBackground(Params... params) { + doTask(params); + return null; + } + + public abstract void doTask(Params... params); +} \ No newline at end of file diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/scriptbundle/asynctask/SimpleTask0.java b/Android/LuaViewSDK/src/com/taobao/luaview/scriptbundle/asynctask/SimpleTask0.java new file mode 100644 index 00000000..bfad89ae --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/scriptbundle/asynctask/SimpleTask0.java @@ -0,0 +1,25 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.scriptbundle.asynctask; + +/** + * 简单任务封装 + * + * @author song + */ +public abstract class SimpleTask0 extends BaseAsyncTask { + + @Override + protected Object doInBackground(Object... params) { + doTask(); + return null; + } + + public abstract void doTask(); +} \ No newline at end of file diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/scriptbundle/asynctask/SimpleTask1.java b/Android/LuaViewSDK/src/com/taobao/luaview/scriptbundle/asynctask/SimpleTask1.java new file mode 100644 index 00000000..c679ee70 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/scriptbundle/asynctask/SimpleTask1.java @@ -0,0 +1,18 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.scriptbundle.asynctask; + +/** + * 带输出结果的简单任务,带一个输出 + * + * @author song + */ +public abstract class SimpleTask1 extends BaseAsyncTask { + +} \ No newline at end of file diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/scriptbundle/asynctask/SimpleTask2.java b/Android/LuaViewSDK/src/com/taobao/luaview/scriptbundle/asynctask/SimpleTask2.java new file mode 100644 index 00000000..f174e54e --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/scriptbundle/asynctask/SimpleTask2.java @@ -0,0 +1,18 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.scriptbundle.asynctask; + +/** + * 带输入输出参数的简单任务,带输入&输出的简单封装 + * + * @author song + */ +public abstract class SimpleTask2 extends BaseAsyncTask { + +} \ No newline at end of file diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/scriptbundle/asynctask/delegate/ScriptBundleDownloadDelegate.java b/Android/LuaViewSDK/src/com/taobao/luaview/scriptbundle/asynctask/delegate/ScriptBundleDownloadDelegate.java new file mode 100644 index 00000000..c8197b4c --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/scriptbundle/asynctask/delegate/ScriptBundleDownloadDelegate.java @@ -0,0 +1,206 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.scriptbundle.asynctask.delegate; + +import com.taobao.luaview.scriptbundle.LuaScriptManager; +import com.taobao.luaview.util.DebugUtil; +import com.taobao.luaview.util.EncryptUtil; +import com.taobao.luaview.util.FileUtil; +import com.taobao.luaview.util.HexUtil; +import com.taobao.luaview.util.IOUtil; +import com.taobao.luaview.util.LogUtil; + +import java.io.BufferedInputStream; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.RandomAccessFile; +import java.net.HttpURLConnection; +import java.net.URL; + +/** + * ScriptBundle Download Delegate + * + * @author song + * @date 17/2/8 + * 主要功能描述 + * 修改描述 + * 下午2:42 song XXX + */ + +public class ScriptBundleDownloadDelegate { + private String url; + private String sha256; + + public ScriptBundleDownloadDelegate(String url, String sha256) { + this.url = url; + this.sha256 = sha256; + } + + /** + * download ScriptBundle + * + * @return + */ + public boolean download() { + byte[] fileData = downloadAsBytes(); + + if (fileData != null) {//save file + DebugUtil.tsi("luaviewp-saveFiles0"); + + saveFile(fileData); + + DebugUtil.tei("luaviewp-saveFiles0"); + + return true; + } + + return false; + } + + public void saveFile(byte[] fileData){ + String destFilePath = LuaScriptManager.buildScriptBundleFilePath(url); + File destFile = FileUtil.createFile(destFilePath); + saveFileUsingFileOutputStream(destFile, fileData); + } + + /** + * download as bytes + * + * @return + */ + public byte[] downloadAsBytes() { + HttpURLConnection connection = createHttpUrlConnection(); + if (connection != null) { + InputStream input = downloadAsStream(connection); + if (input != null) { + DebugUtil.tsi("luaviewp-readBytes"); + final byte[] fileData = IOUtil.toBytes(input);//TODO 有性能瓶颈,可以考虑安全验证 + DebugUtil.tei("luaviewp-readBytes"); + + DebugUtil.tsi("luaviewp-sha256"); + if (!checkSha256(fileData)) { + return null; + } + DebugUtil.tei("luaviewp-sha256"); + + try { + input.close(); + } catch (IOException e) { + e.printStackTrace(); + } + + connection.disconnect(); + + return fileData; + } + } + return null; + } + + /** + * create HttpURLConnection + * + * @return + */ + public HttpURLConnection createHttpUrlConnection() { + try { + + final URL uri = new URL(url); + HttpURLConnection connection = (HttpURLConnection) uri.openConnection(); + connection.connect(); + + return connection; + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + /** + * download as Stream + * + * @param connection + * @return + */ + public InputStream downloadAsStream(HttpURLConnection connection) { + try { + if (connection != null) { + if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) { + LogUtil.e("[Server Returned HTTP] ", connection.getResponseCode(), connection.getResponseMessage()); + return null; + } + return new BufferedInputStream(connection.getInputStream()); + } + return null; + } catch (Exception e) { + LogUtil.e("[Script Download Error] ", e); + e.printStackTrace(); + return null; + } + } + + /** + * check sha256 + * + * @param fileData + * @return + */ + public boolean checkSha256(byte[] fileData) { + if (sha256 != null && !sha256.equalsIgnoreCase(HexUtil.bytesToHex(EncryptUtil.sha256(fileData)))) {//验证脚本的完整性 + return false; + } + return true; + } + + /** + * save file using output stream + * + * @param destFile + * @param fileData + */ + private void saveFileUsingFileOutputStream(File destFile, byte[] fileData) { + FileOutputStream output = null; + try { + output = new FileOutputStream(destFile); + output.write(fileData); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } finally { + if (output != null) { + try { + output.flush(); + output.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } + + /** + * save file + * + * @param destFile + * @param fileData + */ + private void saveFileUsingRandomAccessFile(File destFile, byte[] fileData) { + try { + RandomAccessFile randomAccessFile = new RandomAccessFile(destFile, "rw"); + randomAccessFile.write(fileData); + randomAccessFile.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/scriptbundle/asynctask/delegate/ScriptBundleLoadDelegate.java b/Android/LuaViewSDK/src/com/taobao/luaview/scriptbundle/asynctask/delegate/ScriptBundleLoadDelegate.java new file mode 100644 index 00000000..22beb3f2 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/scriptbundle/asynctask/delegate/ScriptBundleLoadDelegate.java @@ -0,0 +1,178 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.scriptbundle.asynctask.delegate; + +import android.content.Context; + +import com.taobao.luaview.scriptbundle.ScriptBundle; +import com.taobao.luaview.scriptbundle.ScriptFile; +import com.taobao.luaview.util.DebugUtil; +import com.taobao.luaview.util.DecryptUtil; +import com.taobao.luaview.util.IOUtil; +import com.taobao.luaview.util.VerifyUtil; +import com.taobao.luaview.util.ZipUtil; + +import org.luaj.vm2.LoadState; +import org.luaj.vm2.LuaError; +import org.luaj.vm2.Prototype; + +import java.io.BufferedInputStream; +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.util.Map; + +/** + * ScriptBundle Load Delegate + * + * @author song + * @date 17/2/8 + * 主要功能描述 + * 修改描述 + * 下午2:44 song XXX + */ + +public class ScriptBundleLoadDelegate { + public ScriptBundleLoadDelegate() { + } + + public ScriptBundle load(Context context, ScriptBundle scriptBundle) { + if (scriptBundle != null && scriptBundle.size() > 0 && verifyAllScripts(context, scriptBundle)) {//强校验,如果脚本存在并且校验成功才返回 + Map files = scriptBundle.getScriptFileMap(); + ScriptFile scriptFile = null; + + for (String key : files.keySet()) { + scriptFile = files.get(key); + scriptFile.scriptData = loadEncryptScript(context, scriptBundle.isBytecode(), scriptFile); + if (scriptBundle.isBytecode()) {//如果是bytecode,则加载prototype + DebugUtil.tsi("luaviewp-loadPrototype"); + scriptFile.prototype = loadPrototype(scriptFile); // TODO 性能瓶颈 + DebugUtil.tei("luaviewp-loadPrototype"); + } + } + return scriptBundle; + } else { + return null; + } + } + + //------------------------------------------加载脚本函数------------------------------------------ + + /** + * load a prototype + * + * @param scriptFile + * @return + */ + private Prototype loadPrototype(final ScriptFile scriptFile) { + if (LoadState.instance != null && scriptFile != null) { + try { + return LoadState.instance.undump(new BufferedInputStream(new ByteArrayInputStream(scriptFile.scriptData)), scriptFile.getFilePath());//TODO 低端机性能上可以进一步优化 + } catch (LuaError error) { + error.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + } + return null; + } + + /** + * 加载一个脚本 + * + * @param context + * @return + */ + public static InputStream loadEncryptScript(final Context context, final InputStream inputStream) { + if (inputStream != null) { + InputStream result = new ByteArrayInputStream(ZipUtil.unzip(DecryptUtil.aes(context, IOUtil.toBytes(inputStream)))); + try { + inputStream.close(); + } catch (Exception e) {//close input, 这里需要注意,外面不能使用该inputStream + } + return result; + } + return inputStream; + } + + /** + * 加载加密过的脚本 + * + * @param context + * @param scriptFile + * @return + */ + private static byte[] loadEncryptScript(final Context context, final boolean isBytecode, final ScriptFile scriptFile) { + if (scriptFile != null) { + if (isBytecode) {//bytecode不进行unzip + if (scriptFile.signData != null && scriptFile.signData.length > 0) {//加密过则进行解密并unzip + return DecryptUtil.aes(context, scriptFile.scriptData); + } else { + return scriptFile.scriptData; + } + } else { + if (scriptFile.signData != null && scriptFile.signData.length > 0) {//加密过则进行解密并unzip + return ZipUtil.unzip(DecryptUtil.aes(context, scriptFile.scriptData)); + } else { + return ZipUtil.unzip(scriptFile.scriptData); + } + } + } + return null; + } + + /** + * 加载加密过的脚本 + * + * @param context + * @param script + * @return + */ + private static byte[] loadEncryptScript(final Context context, final byte[] script) { + return ZipUtil.unzip(DecryptUtil.aes(context, script)); + } + + /** + * 验证所有脚本,有任何一个失败则返回失败 + * + * @param bundle + * @return + */ + private static boolean verifyAllScripts(Context context, ScriptBundle bundle) { + Map files = bundle != null ? bundle.getScriptFileMap() : null; + if (files != null) { + for (final String key : files.keySet()) { + if (verifyScript(context, bundle.isBytecode(), files.get(key)) == false) { + return false; + } + } + } + return true; + } + + /** + * 验证一个脚本 + * + * @param isBytecode + * @param script + * @return + */ + private static boolean verifyScript(Context context, boolean isBytecode, ScriptFile script) { + if (script != null) { + if (isBytecode) {//bytecode 模式下,如果没有signdata也算验证通过 + if (script.signData != null && script.signData.length > 0) { + return VerifyUtil.rsa(context, script.scriptData, script.signData); + } + return true; + } else { + return VerifyUtil.rsa(context, script.scriptData, script.signData); + } + } + return false; + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/scriptbundle/asynctask/delegate/ScriptBundleUnpackDelegate.java b/Android/LuaViewSDK/src/com/taobao/luaview/scriptbundle/asynctask/delegate/ScriptBundleUnpackDelegate.java new file mode 100644 index 00000000..5f5c6e21 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/scriptbundle/asynctask/delegate/ScriptBundleUnpackDelegate.java @@ -0,0 +1,385 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.scriptbundle.asynctask.delegate; + +import android.content.Context; +import android.content.res.AssetManager; + +import com.taobao.luaview.scriptbundle.LuaScriptManager; +import com.taobao.luaview.scriptbundle.ScriptBundle; +import com.taobao.luaview.scriptbundle.ScriptFile; +import com.taobao.luaview.scriptbundle.asynctask.SimpleTask; +import com.taobao.luaview.scriptbundle.asynctask.SimpleTask1; +import com.taobao.luaview.util.AssetUtil; +import com.taobao.luaview.util.DebugUtil; +import com.taobao.luaview.util.FileUtil; +import com.taobao.luaview.util.IOUtil; + +import java.io.BufferedInputStream; +import java.io.ByteArrayInputStream; +import java.io.DataOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.MappedByteBuffer; +import java.nio.channels.FileChannel; +import java.util.HashMap; +import java.util.Map; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; + +/** + * ScriptBundle Unpack Delegate + * + * @author song + * @date 17/2/8 + * 主要功能描述 + * 修改描述 + * 下午2:43 song XXX + */ + +public class ScriptBundleUnpackDelegate { + + /** + * 将所有assert下面的脚本解压缩到文件系统 + * + * @param assetFolderPath + */ + public static void unpackAllAssetScripts(final Context context, final String assetFolderPath) { + if (context != null && assetFolderPath != null) { + new SimpleTask1() {//起simple task 来解压包 + @Override + protected Object doInBackground(Object[] params) { + final AssetManager assetManager = context.getAssets(); + if (assetManager != null) { + try { + final String[] assetBundles = assetManager.list(assetFolderPath);//list 耗时 + if (assetBundles != null) { + for (final String assetBundleFileName : assetBundles) { + if (LuaScriptManager.isLuaScriptZip(assetBundleFileName)) {//如果是luaview zip,则解包 + unpack(context, FileUtil.removePostfix(assetBundleFileName), assetFolderPath + File.separator + assetBundleFileName); + } + } + } + } catch (Exception e) { + e.printStackTrace(); + } + } + return null; + } + }.executeInPool(); + } + } + + /** + * unpack asset + * + * @param url + * @param assetFilePath + * @return + */ + public static ScriptBundle unpack(Context context, String url, String assetFilePath) { + final String scriptBundleFilePath = LuaScriptManager.buildScriptBundleFilePath(url); + final InputStream inputStream = assetFilePath != null ? AssetUtil.open(context, assetFilePath) : FileUtil.open(scriptBundleFilePath);//额外参数,告知了inputstream (asset的情况) + try { + return unpackBundle(LuaScriptManager.isLuaBytecodeUrl(url), url, inputStream);//TODO 性能瓶颈 + } catch (IOException e) { + return null; + } finally { + if (assetFilePath != null) {//asset,copy原始文件到文件夹下 + FileUtil.copy(AssetUtil.open(context, assetFilePath), scriptBundleFilePath); + } + } + } + + /** + * unpack asset + * + * @param url + * @return + */ + public static ScriptBundle unpack(String url) { + final String scriptBundleFilePath = LuaScriptManager.buildScriptBundleFilePath(url); + final InputStream inputStream = FileUtil.open(scriptBundleFilePath);//额外参数,告知了inputstream (asset的情况) + try { + return unpackBundle(LuaScriptManager.isLuaBytecodeUrl(url), url, inputStream);//TODO 性能瓶颈 + } catch (IOException e) { + return null; + } + } + + /** + * unpack asset + * + * @param url + * @return + */ + public static ScriptBundle unpack(String url, byte[] fileData) { + try { + return unpackBundle(LuaScriptManager.isLuaBytecodeUrl(url), url, new ByteArrayInputStream(fileData));//TODO 性能瓶颈 + } catch (IOException e) { + return null; + } + } + + /** + * unpack asset + * + * @param url + * @return + */ + public static ScriptBundle unpack(String url, InputStream inputStream) { + try { + return unpackBundle(LuaScriptManager.isLuaBytecodeUrl(url), url, inputStream);//TODO 性能瓶颈 + } catch (IOException e) { + return null; + } + } + + /** + * 加载指定目录下的所有lua文件 + * + * @param destFilePath path or file + * @return + */ + public static ScriptBundle loadBundle(boolean isBytecode, final String url, String destFilePath) { + String rawFilePath = LuaScriptManager.buildScriptBundleFilePath(url); + File file = new File(rawFilePath); + if (!file.exists()) { + return null; + } + + if (file.isFile()) { + try { + return unpackBundleRaw(isBytecode, url, file); + } catch (Exception e) { + e.printStackTrace(); + } + } + return null; + } + + /** + * unpack a bundle + * + * @param inputStream + * @param url + * @return + */ + public static ScriptBundle unpackBundle(final boolean isBytecode, final String url, final InputStream inputStream) throws IOException { + if (inputStream == null || url == null) { + return null; + } + + final ScriptBundle scriptBundle = new ScriptBundle(); + + final ZipInputStream zipStream = new ZipInputStream(new BufferedInputStream(inputStream)); + final String scriptBundleFolderPath = LuaScriptManager.buildScriptBundleFolderPath(url); + final Map luaSigns = new HashMap(); + final Map luaRes = new HashMap(); + final Map luaScripts = new HashMap(); + + scriptBundle.setUrl(url); + scriptBundle.setBytecode(isBytecode); + scriptBundle.setBaseFilePath(scriptBundleFolderPath); + + ZipEntry entry; + String rawName = null; + String fileName = null; + String filePath = null; + + DebugUtil.tsi("luaviewp-unpackBundle-zip"); + while ((entry = zipStream.getNextEntry()) != null) { + // 处理../ 这种方式只能使用单层路径,不能处理子目录,在这里可以添加公用path + rawName = entry.getName(); + if (rawName == null || rawName.indexOf("../") != -1) { + zipStream.close(); + return null; + } + + fileName = FileUtil.getSecurityFileName(rawName); + + if (entry.isDirectory()) { + filePath = FileUtil.buildPath(scriptBundleFolderPath, fileName); + File dir = new File(filePath); + if (!dir.exists()) { + dir.mkdir(); + } + } else { + + byte[] fileData = IOUtil.toBytes(zipStream);//TODO 性能瓶颈 + + if (LuaScriptManager.isLuaEncryptScript(fileName)) {//lua file (source or prototype) + scriptBundle.addScript(new ScriptFile(url, scriptBundleFolderPath, fileName, fileData, null)); + luaScripts.put(fileName, fileData); + } else if (LuaScriptManager.isLuaSignFile(fileName)) {//签名文件,不解压到文件系统 + luaSigns.put(fileName, fileData); + } else {//其他文件解压到文件系统(图片、资源) + filePath = FileUtil.buildPath(scriptBundleFolderPath, fileName); + luaRes.put(filePath, fileData); + } + } + + //close entry + zipStream.closeEntry(); + } + DebugUtil.tei("luaviewp-unpackBundle-zip"); + + zipStream.close(); + + ScriptFile scriptFile = null; + Map fileMap = scriptBundle.getScriptFileMap(); + for (String key : fileMap.keySet()) { + scriptFile = fileMap.get(key); + scriptFile.signData = luaSigns.get(scriptFile.signFileName); + } + + if (luaRes.size() > 0) { + new SimpleTask>() {//写资源文件 + @Override + public void doTask(Map... params) { + if (params != null && params.length > 0) { + Map fileToBeSave = params[0]; + for (Map.Entry file : fileToBeSave.entrySet()) {//save all res files + FileUtil.save(file.getKey(), file.getValue()); + } + } + } + }.executeInPool(luaRes); + } + + if (luaScripts.size() > 0) { + new SimpleTask() {//写xxx.lvbundle文件 + @Override + public void doTask(Object... params) { + boolean isBytecode = params != null && params.length >= 0 ? (Boolean) params[0] : false; + Map fileData = params != null && params.length >= 1 ? (Map) params[1] : null; + Map signData = params != null && params.length >= 2 ? (Map) params[2] : null; + saveFilesUsingOutputStream(isBytecode, url, fileData, signData); + } + }.executeInPool(isBytecode, luaScripts, luaSigns); + } + + return scriptBundle; + } + + /** + * save files as xxx.lvbundle + * + * @param url + * @param fileDatas + */ + private static void saveFilesUsingOutputStream(boolean isBytecode, String url, Map fileDatas, Map signDatas) { + String filePath = LuaScriptManager.buildScriptBundleFilePath(url); + File tmpFile = FileUtil.createFile(filePath); + DataOutputStream output = null; + try { + output = new DataOutputStream(new FileOutputStream(tmpFile)); + output.writeInt(fileDatas.size()); + String fileNameStr = null; + for (Map.Entry file : fileDatas.entrySet()) { + fileNameStr = file.getKey(); + byte[] fileName = fileNameStr.getBytes(); + + output.writeInt(fileName.length); + output.write(fileName); + + byte[] fileData = file.getValue(); + output.writeInt(fileData.length); + output.write(fileData); + + if (!isBytecode) {//非bytecode还写sign + byte[] signData = signDatas.get(LuaScriptManager.changeSuffix(fileNameStr, LuaScriptManager.POSTFIX_LV) + LuaScriptManager.POSTFIX_SIGN);//sign file name, TODO 这里可以优化一下,名称使用统一的名称 + output.writeInt(signData.length); + output.write(signData); + } + } + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (output != null) { + try { + output.flush(); + output.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } + + /** + * unpack a xxx.lvbundle + * + * @param file + * @param url + * @return + */ + public static ScriptBundle unpackBundleRaw(boolean isBytecode, final String url, final File file) throws IOException { + DebugUtil.tsi("luaviewp-unpackBundle-raw"); + + if (file == null || url == null) { + return null; + } + + final ScriptBundle scriptBundle = new ScriptBundle(); + final FileInputStream inputStream = new FileInputStream(file); + final MappedByteBuffer buffer = inputStream.getChannel().map(FileChannel.MapMode.READ_ONLY, 0, file.length()); + final String scriptBundleFolderPath = LuaScriptManager.buildScriptBundleFolderPath(url); + + scriptBundle.setUrl(url); + scriptBundle.setBytecode(isBytecode); + scriptBundle.setBaseFilePath(scriptBundleFolderPath); + + int fileNameLen = 0; + int fileLen = 0; + String fileNameStr = null; + + byte[] fileName, fileData, signData; + int count = buffer.getInt(); + for (int i = 0; i < count; i++) {//all files + fileNameLen = buffer.getInt();// get file name + fileName = new byte[fileNameLen]; + buffer.get(fileName); + + fileLen = buffer.getInt();// get file data + fileData = new byte[fileLen]; + buffer.get(fileData); + + if (!isBytecode) {//非二进制的还有sign的data + fileLen = buffer.getInt(); + signData = new byte[fileLen]; + buffer.get(signData); + } else { + signData = null; + } + + fileNameStr = new String(fileName); + if (fileNameStr == null || fileNameStr.indexOf("../") != -1) { + return null; + } + + scriptBundle.addScript(new ScriptFile(url, scriptBundleFolderPath, fileNameStr, fileData, signData)); + } + + if (inputStream != null) { + try { + inputStream.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + DebugUtil.tei("luaviewp-unpackBundle-raw"); + + return scriptBundle; + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/userdata/base/BaseCacheUserdata.java b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/base/BaseCacheUserdata.java new file mode 100644 index 00000000..b347d902 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/base/BaseCacheUserdata.java @@ -0,0 +1,55 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.userdata.base; + +import com.taobao.luaview.cache.LuaCache; +import com.taobao.luaview.global.LuaView; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; + +/** + * Cacheable UserData + * + * @author song + * @date 16/1/21 + * 下午5:14 song XXX + */ +public abstract class BaseCacheUserdata extends BaseUserdata implements LuaCache.CacheableObject { + + public BaseCacheUserdata(Globals globals, LuaValue metatable) { + super(globals, metatable); + cacheObject(); + } + + public BaseCacheUserdata(Globals globals, LuaValue metatable, Varargs varargs) { + super(globals, metatable, varargs); + cacheObject(); + } + + public BaseCacheUserdata(Object obj, Globals globals, LuaValue metatable) { + super(obj, globals, metatable); + cacheObject(); + } + + public BaseCacheUserdata(Object obj, Globals globals, LuaValue metatable, Varargs varargs) { + super(obj, globals, metatable, varargs); + cacheObject(); + } + + private void cacheObject() { + final Globals globals = getGlobals(); + final LuaCache luaCache = globals != null ? globals.getLuaCache() : null; + if(luaCache != null){ + luaCache.cacheObject(getClass(), this); + } + } + +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/userdata/base/BaseLuaTable.java b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/base/BaseLuaTable.java new file mode 100644 index 00000000..e36ff174 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/base/BaseLuaTable.java @@ -0,0 +1,54 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.userdata.base; + +import android.content.Context; + +import com.taobao.luaview.global.LuaResourceFinder; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaTable; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; + +import java.io.Serializable; + +/** + * 基础Table + * + * @author song + * @date 15/8/21 + */ +public class BaseLuaTable extends LuaTable implements Serializable { + private Globals mGlobals; + private LuaValue mMetatable; + public Varargs mVarargs; + + public BaseLuaTable(Globals globals, LuaValue metatable) { + this(globals, metatable, NIL); + } + + public BaseLuaTable(Globals globals, LuaValue metatable, Varargs varargs) { + this.mGlobals = globals; + this.mMetatable = metatable; + this.mVarargs = varargs; + } + + public Globals getGlobals() { + return mGlobals; + } + + public LuaResourceFinder getLuaResourceFinder() { + return mGlobals != null ? mGlobals.getLuaResourceFinder() : null; + } + + public Context getContext() { + return getGlobals() != null ? getGlobals().getContext() : null; + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/userdata/base/BaseUserdata.java b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/base/BaseUserdata.java new file mode 100644 index 00000000..5d727f34 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/base/BaseUserdata.java @@ -0,0 +1,126 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.userdata.base; + +import android.content.Context; + +import com.taobao.luaview.global.LuaResourceFinder; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaUserdata; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; + +import java.io.Serializable; +import java.lang.ref.WeakReference; + +/** + * 基础用户数据 + * + * @author song + * @date 15/8/21 + */ +public class BaseUserdata extends LuaUserdata implements Serializable { + private Globals mGlobals; + public Varargs initParams = LuaValue.NIL; + + public BaseUserdata(Globals globals, LuaValue metatable) { + this(globals, metatable, NIL); + } + + public BaseUserdata(Object obj, Globals globals, LuaValue metatable) { + this(obj, globals, metatable, NIL); + } + + public BaseUserdata(Globals globals, LuaValue metatable, Varargs varargs) { + super(globals, metatable); + this.initParams = varargs; + } + + public BaseUserdata(Object obj, Globals globals, LuaValue metatable, Varargs varargs) { + super(new WeakReference(obj), metatable); + this.mGlobals = globals; + this.initParams = varargs; + } + + public LuaValue setInitParams(Varargs initParams) { + this.initParams = initParams; + return this; + } + + public Varargs getInitParams() { + return initParams; + } + + public LuaValue getInitParam1() { + return getInitParam1(LuaValue.NIL); + } + + public LuaValue getInitParam2() { + return getInitParam2(LuaValue.NIL); + } + + public LuaValue getInitParam1(LuaValue defaultValue) { + return getInitParam(1, defaultValue); + } + + public LuaValue getInitParam2(LuaValue defaultValue) { + return getInitParam(2, defaultValue); + } + + public LuaValue getInitParam(int index, LuaValue defaultValue) { + return initParams != null && initParams.narg() >= index ? initParams.arg(index) : defaultValue; + } + + public LuaValue getInitParam1(Varargs varargs) { + return getInitParam1(1, varargs, LuaValue.NIL); + } + + public LuaValue getInitParam1(int index, Varargs varargs, LuaValue defaultValue) { + return varargs != null && varargs.narg() >= index ? varargs.arg(index) : defaultValue; + } + + public int getInitParamsCount() { + return initParams != null ? initParams.narg() : 0; + } + + @Override + public Object userdata() { + Object obj = super.userdata(); + if (obj instanceof WeakReference) { + return ((WeakReference) obj).get(); + } else { + return obj; + } + } + + public Globals getGlobals() { + return userdata() instanceof Globals ? (Globals) userdata() : mGlobals; + } + + public LuaResourceFinder getLuaResourceFinder() { + return getGlobals() != null ? getGlobals().getLuaResourceFinder() : null; + } + + public Context getContext() { + return getGlobals() != null ? getGlobals().getContext() : null; + } + + /** + * 销毁的时候置空 + */ + public void onDestroy() { + m_instance = null; + } + + @Override + public String tojstring() { + return String.valueOf(userdata()); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/userdata/base/UDLuaTable.java b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/base/UDLuaTable.java new file mode 100644 index 00000000..ce6be242 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/base/UDLuaTable.java @@ -0,0 +1,53 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.userdata.base; + +import android.view.View; + +import com.taobao.luaview.userdata.ui.UDView; +import com.taobao.luaview.view.LVViewGroup; + +import org.luaj.vm2.LuaTable; + +/** + * 封装LuaTable,可以保存View + * + * @author song + * @date 15/9/2 + */ +public class UDLuaTable extends LuaTable { + private UDView udView; + + public UDLuaTable(UDView udView) { + this.udView = udView; + this.set("window", udView);//TODO 优化,父容器音容 + } + + public void setUdView(UDView udView) { + this.udView = udView; + } + + public View getView() { + if (udView != null) { + return udView.getView(); + } + return null; + } + + public LVViewGroup getLVViewGroup() { + if (getView() instanceof LVViewGroup) { + return (LVViewGroup) getView(); + } + return null; + } + + public UDView getUdView() { + return udView; + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/userdata/constants/UDAlign.java b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/constants/UDAlign.java new file mode 100644 index 00000000..472c7775 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/constants/UDAlign.java @@ -0,0 +1,65 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.userdata.constants; + +import android.annotation.TargetApi; +import android.os.Build; +import android.widget.RelativeLayout; + +import com.taobao.luaview.fun.mapper.LuaViewLib; +import com.taobao.luaview.userdata.base.BaseLuaTable; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaValue; + +/** + * Align 用户数据封装 + * + * @author song + * @date 15/9/6 + */ +@LuaViewLib(revisions = {"20170306已对标", "iOS无Start、End"}) +public class UDAlign extends BaseLuaTable { + + public UDAlign(Globals globals, LuaValue metatable) { + super(globals, metatable); + init(); + } + + private void init() { + initViewAlign(); + } + + /** + * view的布局 + */ + private void initViewAlign() { + set("LEFT", RelativeLayout.ALIGN_PARENT_LEFT); + set("TOP", RelativeLayout.ALIGN_PARENT_TOP); + set("RIGHT", RelativeLayout.ALIGN_PARENT_RIGHT); + set("BOTTOM", RelativeLayout.ALIGN_PARENT_BOTTOM); + set("CENTER", RelativeLayout.CENTER_IN_PARENT); + set("H_CENTER", RelativeLayout.CENTER_HORIZONTAL); + set("V_CENTER", RelativeLayout.CENTER_VERTICAL); + + intViewAlignV17(); + } + + @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) + private void intViewAlignV17() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { + set("START", RelativeLayout.ALIGN_PARENT_START); + set("END", RelativeLayout.ALIGN_PARENT_END); + } else { + set("START", RelativeLayout.ALIGN_PARENT_LEFT); + set("END", RelativeLayout.ALIGN_PARENT_RIGHT); + } + } + +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/userdata/constants/UDEllipsize.java b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/constants/UDEllipsize.java new file mode 100644 index 00000000..fcb88c71 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/constants/UDEllipsize.java @@ -0,0 +1,58 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.userdata.constants; + +import android.text.TextUtils; + +import com.taobao.luaview.fun.mapper.LuaViewLib; +import com.taobao.luaview.userdata.base.BaseLuaTable; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaValue; + +/** + * Ellipse 文字处理 + * + * @author song + * @date 15/9/6 + */ +@LuaViewLib(revisions = {"20170306已对标"}) +public class UDEllipsize extends BaseLuaTable { + + public UDEllipsize(Globals globals, LuaValue metatable) { + super(globals, metatable); + init(); + } + + private void init() { + set("START", TextUtils.TruncateAt.START.name()); + set("MIDDLE", TextUtils.TruncateAt.MIDDLE.name()); + set("END", TextUtils.TruncateAt.END.name()); + set("MARQUEE", TextUtils.TruncateAt.MARQUEE.name()); + } + + /** + * parse ellipsize + * + * @param ellipsizeName + * @return + */ + public static TextUtils.TruncateAt parse(String ellipsizeName) { + return parse(ellipsizeName, TextUtils.TruncateAt.END); + } + + public static TextUtils.TruncateAt parse(String ellipsizeName, TextUtils.TruncateAt defaultValue) { + try { + return TextUtils.TruncateAt.valueOf(ellipsizeName); + } catch (Exception e) { + e.printStackTrace(); + return defaultValue; + } + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/userdata/constants/UDFontSize.java b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/constants/UDFontSize.java new file mode 100644 index 00000000..7f4718ab --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/constants/UDFontSize.java @@ -0,0 +1,43 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.userdata.constants; + +import com.taobao.luaview.fun.mapper.LuaViewLib; +import com.taobao.luaview.userdata.base.BaseLuaTable; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaValue; + +/** + * 字体大小 + * + * @author song + * @date 16/3/16 + */ +@LuaViewLib(revisions = {"20170306已对标"}) +@Deprecated +public class UDFontSize extends BaseLuaTable { + public static final int FONTSIZE_MICRO = 12; + public static final int FONTSIZE_SMALL = 14; + public static final int FONTSIZE_MEDIUM = 18; + public static final int FONTSIZE_LARGE = 22; + + public UDFontSize(Globals globals, LuaValue metatable) { + super(globals, metatable); + init(); + } + + private void init() { + this.set("MICRO", FONTSIZE_MICRO); + this.set("SMALL", FONTSIZE_SMALL); + this.set("MEDIUM", FONTSIZE_MEDIUM); + this.set("LARGE", FONTSIZE_LARGE); + } + +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/userdata/constants/UDFontStyle.java b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/constants/UDFontStyle.java new file mode 100644 index 00000000..b6e6e439 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/constants/UDFontStyle.java @@ -0,0 +1,67 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.userdata.constants; + +import android.graphics.Typeface; +import android.text.TextUtils; + +import com.taobao.luaview.fun.mapper.LuaViewLib; +import com.taobao.luaview.userdata.base.BaseLuaTable; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaValue; + +/** + * FontStyle 用户数据封装 + * + * @author song + * @date 15/9/6 + */ +@LuaViewLib(revisions = {"20170306已对标", "iOS无BOLD"}) +public class UDFontStyle extends BaseLuaTable { + + public static final String STYLE_NORMAL = "normal"; + public static final String STYLE_ITALIC = "italic"; + public static final String STYLE_BOLD = "bold";//TODO 需要跟fontWeight的Bold统一 + + public UDFontStyle(Globals globals, LuaValue metatable) { + super(globals, metatable); + init(); + } + + private void init() { + this.set("NORMAL", Typeface.NORMAL); + this.set("ITALIC", Typeface.ITALIC); + this.set("BOLD", Typeface.BOLD); + } + + public static int getValue(final String name) { + if (!TextUtils.isEmpty(name)) { + if (STYLE_NORMAL.equalsIgnoreCase(name)) { + return Typeface.NORMAL; + } else if (STYLE_BOLD.equalsIgnoreCase(name)) { + return Typeface.BOLD; + } else if (STYLE_ITALIC.equalsIgnoreCase(name)) { + return Typeface.ITALIC; + } + } + return Typeface.NORMAL; + } + + public static String getName(int type) { + switch (type) { + case Typeface.ITALIC: + return STYLE_ITALIC; + case Typeface.BOLD: + return STYLE_BOLD; + default: + return STYLE_NORMAL; + } + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/userdata/constants/UDFontWeight.java b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/constants/UDFontWeight.java new file mode 100644 index 00000000..b5821fd0 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/constants/UDFontWeight.java @@ -0,0 +1,55 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.userdata.constants; + +import android.text.TextUtils; + +import com.taobao.luaview.fun.mapper.LuaViewLib; +import com.taobao.luaview.userdata.base.BaseLuaTable; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaValue; + +/** + * FontWeight 用户数据封装 + * + * @author song + * @date 15/9/6 + */ +@LuaViewLib(revisions = {"20170306已对标", "ios不支持数值"}) +public class UDFontWeight extends BaseLuaTable { + + public static final String WEIGHT_NORMAL = "normal"; + public static final String WEIGHT_BOLD = "bold"; + + public static final int WEIGHT_NORMAL_INT = 400; + public static final int WEIGHT_BOLD_INT = 700; + + public UDFontWeight(Globals globals, LuaValue metatable) { + super(globals, metatable); + init(); + } + + private void init() { + this.set("NORMAL", WEIGHT_NORMAL_INT); + this.set("BOLD", WEIGHT_BOLD_INT); + } + + public static int getValue(final String name) { + if (!TextUtils.isEmpty(name)) { + if (WEIGHT_NORMAL.equalsIgnoreCase(name)) { + return WEIGHT_NORMAL_INT; + } else if (WEIGHT_BOLD.equalsIgnoreCase(name)) { + return WEIGHT_BOLD_INT; + } + } + return WEIGHT_NORMAL_INT; + } + +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/userdata/constants/UDGravity.java b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/constants/UDGravity.java new file mode 100644 index 00000000..a834383c --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/constants/UDGravity.java @@ -0,0 +1,56 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.userdata.constants; + +import android.view.Gravity; + +import com.taobao.luaview.fun.mapper.LuaViewLib; +import com.taobao.luaview.userdata.base.BaseLuaTable; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaValue; + +/** + * Gravity 文本布局 + * + * @author song + * @date 15/9/6 + */ +@LuaViewLib(revisions = {"20170306已对标", "IOS不支持"}) +public class UDGravity extends BaseLuaTable { + + public UDGravity(Globals globals, LuaValue metatable) { + super(globals, metatable); + init(); + } + + private void init() { + initGravity(); + } + + /** + * 设置gravity + */ + private void initGravity() { + set("LEFT", Gravity.LEFT); + set("TOP", Gravity.TOP); + set("RIGHT", Gravity.RIGHT); + set("BOTTOM", Gravity.BOTTOM); + set("H_CENTER", Gravity.CENTER_HORIZONTAL); + set("V_CENTER", Gravity.CENTER_VERTICAL); + + set("CENTER", Gravity.CENTER);//TODO IOS无 + set("START", Gravity.START);//TODO IOS无 + set("END", Gravity.END);//TODO IOS无 + set("FILL", Gravity.FILL);//TODO IOS无 + set("H_FILL", Gravity.FILL_HORIZONTAL);//TODO IOS无 + set("V_FILL", Gravity.FILL_VERTICAL);//TODO IOS无 + } + +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/userdata/constants/UDImageScaleType.java b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/constants/UDImageScaleType.java new file mode 100644 index 00000000..c3e20c64 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/constants/UDImageScaleType.java @@ -0,0 +1,65 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.userdata.constants; + +import android.widget.ImageView; + +import com.taobao.luaview.fun.mapper.LuaViewLib; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaTable; +import org.luaj.vm2.LuaValue; + +/** + * ScaleType 图片布局 + * + * @author song + * @date 15/9/6 + */ +@LuaViewLib(revisions = {"20170306已对标"}) +public class UDImageScaleType extends LuaTable { + private Globals mGlobals; + + public UDImageScaleType(Globals globals, LuaValue metatable) { + this.mGlobals = globals; + init(); + } + + private void init() { + initScaleType(); + } + + /** + * init scale type + */ + private void initScaleType() { + set("FIT_XY", ImageView.ScaleType.FIT_XY.name()); + set("FIT_START", ImageView.ScaleType.FIT_START.name()); + set("FIT_END", ImageView.ScaleType.FIT_END.name()); + set("FIT_CENTER", ImageView.ScaleType.FIT_CENTER.name()); + set("CENTER", ImageView.ScaleType.CENTER.name()); + set("CENTER_CROP", ImageView.ScaleType.CENTER_CROP.name()); + set("CENTER_INSIDE", ImageView.ScaleType.CENTER_INSIDE.name()); + set("MATRIX", ImageView.ScaleType.MATRIX.name()); + } + + public static ImageView.ScaleType parse(String scaleTypeName) { + return parse(scaleTypeName, ImageView.ScaleType.FIT_XY); + } + + public static ImageView.ScaleType parse(String scaleTypeName, ImageView.ScaleType defaultValue) { + try { + return ImageView.ScaleType.valueOf(scaleTypeName); + } catch (Exception e) { + e.printStackTrace(); + return defaultValue; + } + } + +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/userdata/constants/UDInterpolator.java b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/constants/UDInterpolator.java new file mode 100644 index 00000000..5c0f43bd --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/constants/UDInterpolator.java @@ -0,0 +1,101 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.userdata.constants; + + +import android.view.animation.AccelerateDecelerateInterpolator; +import android.view.animation.AccelerateInterpolator; +import android.view.animation.AnticipateInterpolator; +import android.view.animation.AnticipateOvershootInterpolator; +import android.view.animation.BounceInterpolator; +import android.view.animation.CycleInterpolator; +import android.view.animation.DecelerateInterpolator; +import android.view.animation.Interpolator; +import android.view.animation.LinearInterpolator; +import android.view.animation.OvershootInterpolator; + +import com.taobao.luaview.fun.mapper.LuaViewLib; +import com.taobao.luaview.userdata.base.BaseLuaTable; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaValue; + +/** + * Interpolator 封装 + * + * @author song + * @date 15/9/6 + */ +@LuaViewLib(revisions = {"20170306已对标", "ios部分无"}) +public class UDInterpolator extends BaseLuaTable { + + public UDInterpolator(Globals globals, LuaValue metatable) { + super(globals, metatable); + init(); + } + + private void init() { + initInterpolator(); + } + + /** + * init interpolator + */ + private void initInterpolator() { + set("ACCELERATE_DECELERATE", 0); + set("ACCELERATE", 1); + set("ANTICIPATE", 2); + set("ANTICIPATE_OVERSHOOT", 3); + set("BOUNCE", 4);//TODO IOS 无 + set("CYCLE", 5);//TODO IOS 无 + set("DECELERATE", 6); + set("LINEAR", 7); + set("OVERSHOOT", 8); + //暂时不支持的 +// set("FAST_OUT_LINEAR", 9); +// set("FAST_OUT_SLOW_IN", 10); +// set("LINEAR_OUT_SLOW_IN", 11); +// set("PATH", 12); + } + + public static Interpolator parse(Integer type, Float cycles) { + if (type != null) { + switch (type) { + case 0: + return new AccelerateDecelerateInterpolator(); + case 1: + return new AccelerateInterpolator(); + case 2: + return new AnticipateInterpolator(); + case 3: + return new AnticipateOvershootInterpolator(); + case 4: + return new BounceInterpolator(); + case 5: + return new CycleInterpolator((cycles != null && cycles > 0) ? cycles : 1f); + case 6: + return new DecelerateInterpolator(); + case 7: + return new LinearInterpolator(); + case 8: + return new OvershootInterpolator(); + //暂时不支持的 +// case 7: return new FastOutLinearInterplator(); +// case 8: return new FastOutSlowInInterplator(); +// case 10: return new LinearOutSlowInInterplator(); +// case 12: return new PathInterplator(); + default: + return new LinearInterpolator(); + } + } else { + return new LinearInterpolator(); + } + } + +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/userdata/constants/UDPaintStyle.java b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/constants/UDPaintStyle.java new file mode 100644 index 00000000..aa6d17fd --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/constants/UDPaintStyle.java @@ -0,0 +1,36 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.userdata.constants; + +import com.taobao.luaview.fun.mapper.LuaViewLib; +import com.taobao.luaview.userdata.base.BaseLuaTable; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaValue; + +/** + * Canvas.Paint 用户数据封装 + * + * @author song + * @date 15/9/6 + */ +@LuaViewLib(revisions = {"20170306已对标", "EOFILL、FILLSTROKE、EOFILLSTROKE IOS有,Android无"}) +public class UDPaintStyle extends BaseLuaTable { + + public UDPaintStyle(Globals globals, LuaValue metatable) { + super(globals, metatable); + init(); + } + + private void init() { + set("FILL", 0);//Paint.Style.FILL + set("STROKE", 1);//Paint.Style.STROKE + set("FILLSTROKE", 2);//Paint.Style.FILL_AND_STROKE + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/userdata/constants/UDPinned.java b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/constants/UDPinned.java new file mode 100644 index 00000000..7bafd560 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/constants/UDPinned.java @@ -0,0 +1,36 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.userdata.constants; + +import com.taobao.luaview.fun.mapper.LuaViewLib; +import com.taobao.luaview.userdata.base.BaseLuaTable; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaValue; + +/** + * Created by tuoli on 11/7/16. + * + * 标记可吸顶的列表行 + */ +@LuaViewLib(revisions = {"20170306已对标"}) +public class UDPinned extends BaseLuaTable { + public static final int PINNED_YES = 1; + public static final int PINNED_NO = 0; + + public UDPinned(Globals globals, LuaValue metatable) { + super(globals, metatable); + init(); + } + + private void init() { + this.set("YES", PINNED_YES); + this.set("NO", PINNED_NO); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/userdata/constants/UDTextAlign.java b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/constants/UDTextAlign.java new file mode 100644 index 00000000..0ceb7f16 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/constants/UDTextAlign.java @@ -0,0 +1,60 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.userdata.constants; + +import android.view.Gravity; + +import com.taobao.luaview.userdata.base.BaseLuaTable; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaValue; + +/** + * TextAlign 文本布局 + * + * @author song + * @date 15/9/6 + */ +public class UDTextAlign extends BaseLuaTable { + public static final int LEFT = Gravity.LEFT | Gravity.CENTER_VERTICAL; + public static final int CENTER = Gravity.CENTER; + public static final int RIGHT = Gravity.RIGHT | Gravity.CENTER_VERTICAL; + + public UDTextAlign(Globals globals, LuaValue metatable) { + super(globals, metatable); + init(); + } + + private void init() { + initTextViewAlignment(); + } + + + /** + * 文字的排版 + */ + private void initTextViewAlignment() { + set("LEFT", LEFT);//默认竖直居中,ios不支持居上 + set("CENTER", CENTER); + set("RIGHT", RIGHT);//默认竖直居中,ios不支持居上 + + + //以下在两端统一后开启 + /* + set("LEFT", Gravity.LEFT); + set("RIGHT", Gravity.RIGHT); + set("TOP", Gravity.TOP); + set("BOTTOM", Gravity.BOTTOM); + set("CENTER", Gravity.CENTER); + set("HCENTER", Gravity.CENTER_HORIZONTAL); + set("VCENTER", Gravity.CENTER_VERTICAL); + */ + } + +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/userdata/constants/UDTouchEvent.java b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/constants/UDTouchEvent.java new file mode 100644 index 00000000..e596a266 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/constants/UDTouchEvent.java @@ -0,0 +1,41 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.userdata.constants; + +import android.view.MotionEvent; + +import com.taobao.luaview.fun.mapper.LuaViewLib; +import com.taobao.luaview.userdata.base.BaseLuaTable; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaValue; + +/** + * Canvas.Paint 用户数据封装 + * + * @author song + * @date 15/9/6 + */ +@LuaViewLib(revisions = {"20170306已对标", "ios有更多的属性"}) +public class UDTouchEvent extends BaseLuaTable { + + public UDTouchEvent(Globals globals, LuaValue metatable) { + super(globals, metatable); + init(); + } + + private void init() { + set("DOWN", MotionEvent.ACTION_DOWN);//0 + set("UP", MotionEvent.ACTION_UP);//1 + set("MOVE", MotionEvent.ACTION_MOVE);//2 + set("CANCEL", MotionEvent.ACTION_CANCEL);//3 + set("OUTSIDE", MotionEvent.ACTION_OUTSIDE);//4 + } + +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/userdata/constants/UDViewEffect.java b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/constants/UDViewEffect.java new file mode 100644 index 00000000..eb1151af --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/constants/UDViewEffect.java @@ -0,0 +1,51 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.userdata.constants; + +import com.taobao.luaview.fun.mapper.LuaViewLib; +import com.taobao.luaview.userdata.base.BaseLuaTable; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaValue; + +/** + * View特效 + * + * @author song + * @date 16/8/15 + * 主要功能描述 + * 修改描述 + * 下午4:01 song XXX + */ +@LuaViewLib(revisions = {"20170306已对标"}) +public class UDViewEffect extends BaseLuaTable { + public static final int EFFECT_NONE = -1; + public static final int EFFECT_CLICK = 1; + public static final int EFFECT_PARALLAX = 2; + + public UDViewEffect(Globals globals, LuaValue metatable) { + super(globals, metatable); + init(); + } + + private void init() { + initEffects(); + } + + + /** + * View的特效 + */ + private void initEffects() { + set("NONE", EFFECT_NONE);//无效果 + set("CLICK", EFFECT_CLICK);//点击 + set("PARALLAX", EFFECT_PARALLAX);//视差效果 + } + +} \ No newline at end of file diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/userdata/indicator/UDCircleViewPagerIndicator.java b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/indicator/UDCircleViewPagerIndicator.java new file mode 100644 index 00000000..072e0e90 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/indicator/UDCircleViewPagerIndicator.java @@ -0,0 +1,175 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.userdata.indicator; + +import com.taobao.luaview.userdata.ui.UDView; +import com.taobao.luaview.view.indicator.LVCircleViewPagerIndicator; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; + + +/** + * 指示器-ViewPagerIndicator + * + * @author song + * @date 15/8/20 + */ +public class UDCircleViewPagerIndicator extends UDView { + + public UDCircleViewPagerIndicator(U view, Globals globals, LuaValue metaTable, Varargs initParams) { + super(view, globals, metaTable, initParams); + } + + /** + * 设置填充颜色 + * + * @param color + * @return + */ + public UDCircleViewPagerIndicator setFillColor(Integer color) { + if (color != null && getView() != null) { + getView().setFillColor(color); + } + return this; + } + + /** + * 获取填充的颜色 + * + * @return + */ + public int getFillColor() { + return getView() != null ? getView().getFillColor() : -1; + } + + /** + * 设置页面标示颜色 + * + * @param color + * @return + */ + public UDCircleViewPagerIndicator setPageColor(Integer color) { + if (color != null && getView() != null) { + getView().setPageColor(color); + } + return this; + } + + /** + * 获取页面标示颜色 + * + * @return + */ + public int getPageColor() { + return getView() != null ? getView().getPageColor() : -1; + } + + /** + * 设置线条宽度 + * + * @param strokeWidth + * @return + */ + public UDCircleViewPagerIndicator setStrokeWidth(float strokeWidth) { + if (strokeWidth != -1 && getView() != null) { + getView().setStrokeWidth(strokeWidth); + } + return this; + } + + /** + * 获取线条宽度 + * + * @return + */ + public float getStrokeWidth() { + return getView() != null ? getView().getStrokeWidth() : -1.0f; + } + + /** + * 设置线条颜色 + * + * @param color + * @return + */ + public UDCircleViewPagerIndicator setStrokeColor(Integer color) { + if (color != null && getView() != null) { + getView().setStrokeColor(color); + } + return this; + } + + /** + * 获取线条颜色 + * + * @return + */ + public int getStrokeColor() { + return getView() != null ? getView().getStrokeColor() : -1; + } + + /** + * 设置圆圈半径 + * + * @param radius + * @return + */ + public UDCircleViewPagerIndicator setRadius(float radius) { + if (radius != -1 && getView() != null) { + getView().setRadius(radius); + } + return this; + } + + /** + * 获取半径 + * + * @return + */ + public float getRadius() { + return getView() != null ? getView().getRadius() : -1.0f; + } + + /** + * 设置是否需要动画 + * + * @param snap + * @return + */ + public UDCircleViewPagerIndicator setSnap(boolean snap) { + if (getView() != null) { + getView().setSnap(snap); + } + return this; + } + + /** + * 是否需要动画 + * + * @return + */ + public boolean isSnap() { + return getView() != null ? getView().isSnap() : false; + } + + /** + * 设置当前页面 + * + * @param item + * @return + */ + public UDCircleViewPagerIndicator setCurrentItem(final int item) { + if (item != -1 && getView() != null) { + getView().setCurrentItem(item); + } + return this; + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/userdata/indicator/UDCustomViewPagerIndicator.java b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/indicator/UDCustomViewPagerIndicator.java new file mode 100644 index 00000000..e4a397c0 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/indicator/UDCustomViewPagerIndicator.java @@ -0,0 +1,85 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.userdata.indicator; + +import com.taobao.luaview.userdata.ui.UDView; +import com.taobao.luaview.util.LuaUtil; +import com.taobao.luaview.view.indicator.LVCustomViewPagerIndicator; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; + + +/** + * 指示器-Custom ViewPagerIndicator + * + * @author song + * @date 15/8/20 + */ +public class UDCustomViewPagerIndicator extends UDView { + + public UDCustomViewPagerIndicator(U view, Globals globals, LuaValue metaTable, Varargs initParams) { + super(view, globals, metaTable, initParams); + } + + + /** + * call init + * + * @param pos + * @return + */ + public LuaValue callCellInit(LuaValue cellData, int pos, int currentItem) { + return callCellFunction("Init", cellData, pos, currentItem); + } + + /** + * call Layout + * + * @param pos + * @return + */ + public LuaValue callCellLayout(LuaValue cellData, int pos, int currentItem) { + return callCellFunction("Layout", cellData, pos, currentItem); + } + + /** + * 调用 Page的某些方法 + * + * @param method + * @param position + * @return + */ + private LuaValue callCellFunction(String method, LuaValue cellData, int position, int currentItem) { + return LuaUtil.callFunction(LuaUtil.getValue(initParams, method), cellData, LuaUtil.toLuaInt(position), LuaUtil.toLuaInt(currentItem)); + } + + /** + * 设置当前页面 + * + * @param item + * @return + */ + public UDCustomViewPagerIndicator setCurrentItem(final int item) { + if (item != -1 && getView() != null) { + getView().setCurrentItem(item); + } + return this; + } + + /** + * 当前页面 + * + * @return + */ + public int getCurrentItem() { + return getView() != null ? getView().getCurrentItem() : 0; + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/userdata/kit/UDActionBar.java b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/kit/UDActionBar.java new file mode 100644 index 00000000..8b9d618f --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/kit/UDActionBar.java @@ -0,0 +1,281 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.userdata.kit; + +import android.app.ActionBar; +import android.graphics.drawable.Drawable; +import android.text.TextUtils; +import android.view.View; +import android.widget.ImageView; + +import com.taobao.luaview.fun.mapper.LuaViewLib; +import com.taobao.luaview.global.Constants; +import com.taobao.luaview.userdata.base.BaseLuaTable; +import com.taobao.luaview.userdata.ui.UDImageView; +import com.taobao.luaview.userdata.ui.UDSpannableString; +import com.taobao.luaview.userdata.ui.UDView; +import com.taobao.luaview.util.ImageUtil; +import com.taobao.luaview.util.LuaViewUtil; +import com.taobao.luaview.view.imageview.BaseImageView; +import com.taobao.luaview.view.imageview.DrawableLoadCallback; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; +import org.luaj.vm2.lib.VarArgFunction; + +/** + * ActionBar 用户数据封装 + * + * @author song + * @date 15/9/6 + */ +@LuaViewLib(revisions = {"20170306已对标"}) +public class UDActionBar extends BaseLuaTable { + + public UDActionBar(Globals globals, LuaValue metatable) { + super(globals, metatable); + init(); + } + + private void init() { + set("title", new title()); + set("setTitle", new setTitle()); + set("getTitle", new getTitle()); + set("background", new background()); + set("setBackground", new setBackground()); + set("getBackground", new getBackground()); + set("left", new left()); + set("leftBarButton", new left());//@Deprecated + set("right", new right()); + set("rightBarButton", new right());//@Deprecated + } + + private int fixIndex(Varargs varargs){ + return varargs != null && varargs.arg1() instanceof UDActionBar ? 1 : 0; + } + + /** + * 系统中间View + */ + class title extends VarArgFunction { + + @Override + public Varargs invoke(Varargs args) { + final int fixIndex = fixIndex(args); + if (args.narg() > fixIndex) { + return new setTitle().invoke(args); + } else { + return new getTitle().invoke(args); + } + } + } + + @Deprecated + class setTitle extends VarArgFunction { + + @Override + public Varargs invoke(Varargs args) { + final int fixIndex = fixIndex(args); + if (args.isstring(fixIndex + 1) || args.optvalue(fixIndex + 1, NIL) instanceof UDSpannableString) {//title + final CharSequence title = LuaViewUtil.getText(args.optvalue(fixIndex + 1, NIL)); + if (title != null) { + final ActionBar actionBar = LuaViewUtil.getActionBar(getGlobals()); + if (actionBar != null) { + actionBar.setTitle(title); + } else { +// final android.support.v7.app.ActionBar supportActionBar = LuaViewUtil.getSupportActionBar(getGlobals()); +// if (supportActionBar != null) { +// supportActionBar.setTitle(title); +// } + } + } + } else if (args.isuserdata(fixIndex + 1)) {//view + final LuaValue titleViewValue = args.optvalue(fixIndex + 1, null); + if (titleViewValue instanceof UDView) { + final ActionBar actionBar = LuaViewUtil.getActionBar(getGlobals()); + if (actionBar != null) { + final View view = ((UDView) titleViewValue).getView(); + if (view != null) { + view.setTag(Constants.RES_LV_TAG, titleViewValue); + } + actionBar.setDisplayShowCustomEnabled(true); + actionBar.setCustomView(LuaViewUtil.removeFromParent(view)); + + } else { +// final android.support.v7.app.ActionBar supportActionBar = LuaViewUtil.getSupportActionBar(getGlobals()); +// if (supportActionBar != null) { +// final View view = ((UDView) titleViewValue).getView(); +// if (view != null) { +// view.setTag(Constants.RES_LV_TAG, titleViewValue); +// } +// supportActionBar.setDisplayShowCustomEnabled(true); +// supportActionBar.setCustomView(LuaViewUtil.removeFromParent(view)); +// } + } + } + } + return UDActionBar.this; + } + } + + @Deprecated + class getTitle extends VarArgFunction { + @Override + public Varargs invoke(Varargs args) { + final ActionBar actionBar = LuaViewUtil.getActionBar(getGlobals()); + if (actionBar != null) { + final CharSequence title = actionBar.getTitle(); + if (!TextUtils.isEmpty(title)) { + return valueOf(title.toString()); + } else { + final View view = actionBar.getCustomView(); + if (view != null) { + final Object tag = view.getTag(Constants.RES_LV_TAG); + return tag instanceof LuaValue ? (LuaValue) tag : NIL; + } + } + } + return NIL; + } + } + + + /** + * 背景 + */ + class background extends VarArgFunction { + @Override + public Varargs invoke(Varargs args) { + final int fixIndex = fixIndex(args); + if (args.narg() > fixIndex) { + return new setBackground().invoke(args); + } else { + return new getBackground().invoke(args); + } + } + } + + @Deprecated + class setBackground extends VarArgFunction { + @Override + public Varargs invoke(Varargs args) { + final int fixIndex = fixIndex(args); + if (args.isstring(fixIndex + 1)) { + ImageUtil.fetch(getContext(), getLuaResourceFinder(), args.optjstring(fixIndex + 1, null), new DrawableLoadCallback() { + @Override + public void onLoadResult(Drawable drawable) { + setupActionBarDrawable(drawable); + } + }); + } else if (args.isuserdata(fixIndex + 1)) {//view + final LuaValue data = args.optvalue(fixIndex + 1, null); + if (data instanceof UDImageView) { + final ImageView imageView = (ImageView) LuaViewUtil.removeFromParent(((UDImageView) data).getView()); + if (imageView instanceof BaseImageView) {//TODO ActionBar支持gif + ImageUtil.fetch(getContext(), getLuaResourceFinder(), ((BaseImageView) imageView).getUrl(), new DrawableLoadCallback() { + @Override + public void onLoadResult(Drawable drawable) { + setupActionBarDrawable(drawable); + } + }); + } + } else if (data instanceof UDBitmap) { + setupActionBarDrawable(((UDBitmap) data).createDrawable()); + } + } + return UDActionBar.this; + } + + private void setupActionBarDrawable(Drawable drawable) { + if (drawable != null) { + final ActionBar actionBar = LuaViewUtil.getActionBar(getGlobals()); + if (actionBar != null) { + actionBar.setBackgroundDrawable(drawable); + } + } + } + } + + @Deprecated + class getBackground extends VarArgFunction { + @Override + public Varargs invoke(Varargs args) { + //TODO + return UDActionBar.this; + } + } + + /** + * 左按钮 + */ + class left extends VarArgFunction { + @Override + public Varargs invoke(Varargs args) { + final int fixIndex = fixIndex(args); + if (args.narg() > fixIndex) { + return new setLeft().invoke(args); + } else { + return new getLeft().invoke(args); + } + } + } + + class setLeft extends VarArgFunction { + @Override + public Varargs invoke(Varargs args) { + final ActionBar actionBar = LuaViewUtil.getActionBar(getGlobals()); + if (actionBar != null) { + final int fixIndex = fixIndex(args); + final boolean showBack = args.optboolean(fixIndex + 1, true); + actionBar.setDisplayHomeAsUpEnabled(showBack); + } + return UDActionBar.this; + } + } + + class getLeft extends VarArgFunction { + @Override + public Varargs invoke(Varargs args) { + return UDActionBar.this; + } + } + + /** + * 右按钮 + */ + class right extends VarArgFunction { + @Override + public Varargs invoke(Varargs args) { + final int fixIndex = fixIndex(args); + if (args.narg() > fixIndex) { + return new setRight().invoke(args); + } else { + return new getRight().invoke(args); + } + } + } + + class setRight extends VarArgFunction { + @Override + public Varargs invoke(Varargs args) { + final ActionBar actionBar = LuaViewUtil.getActionBar(getGlobals()); + if (actionBar != null) { + } + return UDActionBar.this; + } + } + + class getRight extends VarArgFunction { + @Override + public Varargs invoke(Varargs args) { + return UDActionBar.this; + } + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/userdata/kit/UDAudio.java b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/kit/UDAudio.java new file mode 100644 index 00000000..5b93ecc0 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/kit/UDAudio.java @@ -0,0 +1,344 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.userdata.kit; + +import android.content.Context; +import android.content.res.AssetFileDescriptor; +import android.media.MediaPlayer; +import android.os.Handler; +import android.webkit.URLUtil; + +import com.taobao.luaview.userdata.base.BaseCacheUserdata; +import com.taobao.luaview.util.AssetUtil; +import com.taobao.luaview.util.LuaUtil; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaFunction; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.Method; + +/** + * Audio 用户数据封装 + * + * @author song + * @date 15/9/6 + */ +public class UDAudio extends BaseCacheUserdata implements MediaPlayer.OnPreparedListener, MediaPlayer.OnCompletionListener, MediaPlayer.OnErrorListener { + private MediaPlayer mMediaPlayer; + private String mUriOrName; + private Integer mLoopTimes; + private LuaFunction mCallback; + + public UDAudio(Globals globals, LuaValue metatable, Varargs varargs) { + super(globals, metatable, varargs); + init(); + } + + private void init() { + if (initParams != null) { + mUriOrName = LuaUtil.getString(initParams, 1); + mLoopTimes = LuaUtil.getInt(initParams, 2, 1); + mCallback = LuaUtil.getFunction(initParams, 3, 2, 1); + } + } + + public UDAudio setCallback(LuaFunction callback) { + this.mCallback = callback; + return this; + } + + public LuaFunction getCallback() { + return mCallback; + } + + /** + * create a media player + * + * @return + */ + private synchronized MediaPlayer getMediaPlayer() { + if (mMediaPlayer == null) { + mMediaPlayer = new MediaPlayer(); + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) { + try { + final Class cMediaTimeProvider = Class.forName("android.media.MediaTimeProvider"); + final Class cSubtitleController = Class.forName("android.media.SubtitleController"); + final Class iSubtitleControllerAnchor = Class.forName("android.media.SubtitleController$Anchor"); + final Class iSubtitleControllerListener = Class.forName("android.media.SubtitleController$Listener"); + + final Constructor constructor = cSubtitleController.getConstructor(new Class[]{Context.class, cMediaTimeProvider, iSubtitleControllerListener}); + + final Object subtitleInstance = constructor.newInstance(getContext(), null, null); + + final Field f = cSubtitleController.getDeclaredField("mHandler"); + + f.setAccessible(true); + try { + f.set(subtitleInstance, new Handler()); + } catch (IllegalAccessException e) { + return mMediaPlayer; + } finally { + f.setAccessible(false); + } + + final Method setSubtitleAnchor = mMediaPlayer.getClass().getMethod("setSubtitleAnchor", cSubtitleController, iSubtitleControllerAnchor); + setSubtitleAnchor.invoke(mMediaPlayer, subtitleInstance, null); + } catch (Exception e) { + } + } + } + return mMediaPlayer; + } + + /** + * start playing audio + * + * @param uriOrName + * @param loopTimes + * @return + */ + public synchronized UDAudio play(String uriOrName, Integer loopTimes) { + stopAndReset(); + + if (uriOrName != null && uriOrName.equals(this.mUriOrName) == false) {//url 不同 + this.mUriOrName = uriOrName; + } + + if (loopTimes != null) { + this.mLoopTimes = loopTimes; + } + + if (this.mUriOrName != null) { + final MediaPlayer player = getMediaPlayer(); + if (player != null && player.isPlaying() == false) { + String uri = null; + boolean assetFileExist = false; + if (URLUtil.isNetworkUrl(this.mUriOrName) || URLUtil.isFileUrl(this.mUriOrName) || URLUtil.isAssetUrl(this.mUriOrName)) {//net & file & asset + uri = this.mUriOrName; + } else {//plain text, use as file path + uri = getLuaResourceFinder().buildFullPathInBundleOrAssets(this.mUriOrName); + assetFileExist = AssetUtil.exists(getContext(), uri); + } + try { + if (assetFileExist) { + final AssetFileDescriptor descriptor = getContext().getAssets().openFd(uri); + player.setDataSource(descriptor.getFileDescriptor(), descriptor.getStartOffset(), descriptor.getLength()); + } else { + player.setDataSource(uri); + } + player.setOnErrorListener(this); + player.setOnCompletionListener(this); + player.setOnPreparedListener(this); + player.setLooping((this.mLoopTimes != null && this.mLoopTimes > 1) ? true : false); + player.prepareAsync(); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + + return this; + } + + /** + * pause playing audio + * + * @return + */ + public synchronized UDAudio pause() { + final MediaPlayer player = getMediaPlayer(); + if (player != null) { + try { + player.pause(); + } catch (Exception e) { + e.printStackTrace(); + } + } + return this; + } + + /** + * resume playing + * + * @return + */ + public synchronized UDAudio resume() { + final MediaPlayer player = getMediaPlayer(); + if (player != null && player.isPlaying() == false) { + try { + if (player.getCurrentPosition() > 0) { + player.start(); + } else { + play(mUriOrName, mLoopTimes); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + return this; + } + + /** + * seek to position + * + * @param position + * @return + */ + public synchronized UDAudio seekTo(Integer position) { + if (position != null) { + final MediaPlayer player = getMediaPlayer(); + if (player != null) { + try { + player.seekTo(position); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + return this; + } + + + /** + * stop playing audio + * + * @return + */ + public synchronized UDAudio stop() { + final MediaPlayer player = getMediaPlayer(); + if (player != null && player.isPlaying()) { + try { + player.stop(); + } catch (Exception e) { + e.printStackTrace(); + } + } + return this; + } + + /** + * reset from error state + * + * @return + */ + public synchronized UDAudio reset() { + final MediaPlayer player = getMediaPlayer(); + if (player != null) { + try { + player.reset(); + } catch (Exception e) { + e.printStackTrace(); + } + } + return this; + } + + /** + * stop playing and reset error state + * + * @return + */ + public synchronized UDAudio stopAndReset() { + return stop().reset(); + } + + /** + * stop playing and release + * + * @return + */ + public synchronized UDAudio stopAndRelease() { + return stop().release(); + } + + /** + * release resource + * + * @return + */ + public synchronized UDAudio release() { + final MediaPlayer player = getMediaPlayer(); + if (player != null) { + try { + player.release(); + } catch (Exception e) { + e.printStackTrace(); + } + } + return this; + } + + public boolean isPlaying() { + return getMediaPlayer() != null && getMediaPlayer().isPlaying(); + } + + public boolean isLooping() { + return getMediaPlayer() != null && getMediaPlayer().isLooping(); + } + + public boolean isPause() { + return getMediaPlayer() != null && getMediaPlayer().isPlaying() == false && getMediaPlayer().getCurrentPosition() > 0; + } + + @Override + public void onCacheClear() { + release(); + } + + + //-----------------------------------------listeners-------------------------------------------- + + @Override + public void onPrepared(MediaPlayer mp) { + if (mp != null) { + synchronized (mp) { + try { + if (mp.isPlaying() == false) { + mp.start(); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + } + } + + /** + * @param mp + */ + @Override + public void onCompletion(MediaPlayer mp) { + if (mp != null) { + synchronized (mp) { + try { + mp.stop(); + mp.reset(); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + + if (mCallback != null) { + LuaUtil.callFunction(LuaUtil.getFunction(mCallback, "onComplete", "OnComplete")); + } + } + + @Override + public boolean onError(MediaPlayer mp, int what, int extra) { + if (mCallback != null) { + LuaUtil.callFunction(mCallback.get("onError"), valueOf(what)); + } + return false; + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/userdata/kit/UDBitmap.java b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/kit/UDBitmap.java new file mode 100644 index 00000000..6c6abfab --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/kit/UDBitmap.java @@ -0,0 +1,224 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.userdata.kit; + +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.graphics.drawable.BitmapDrawable; +import android.graphics.drawable.Drawable; +import android.text.TextUtils; +import android.webkit.URLUtil; + +import com.taobao.luaview.global.LuaResourceFinder; +import com.taobao.luaview.global.LuaView; +import com.taobao.luaview.provider.ImageProvider; +import com.taobao.luaview.scriptbundle.asynctask.SimpleTask1; +import com.taobao.luaview.scriptbundle.asynctask.SimpleTask2; +import com.taobao.luaview.userdata.base.BaseUserdata; +import com.taobao.luaview.util.LogUtil; +import com.taobao.luaview.util.LuaUtil; +import com.taobao.luaview.view.imageview.DrawableLoadCallback; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaFunction; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; + +/** + * Bitmap 用户数据封装,二进制数据 + * + * @author song + * @date 15/9/6 + */ +public class UDBitmap extends BaseUserdata { + private String mUrl; + private LuaValue mCallback = null; + private Bitmap mBitmap; + + public UDBitmap(Globals globals, LuaValue metatable, Varargs varargs) { + super(globals, metatable, varargs); + init(); + } + + /** + * 初始化 + */ + private void init() { + if (initParams != null) { + LuaValue data = null; + if (initParams.isuserdata(1)) { + data = LuaUtil.getUserdata(initParams, 1); + } else { + mUrl = LuaUtil.getString(initParams, 1); + } + mCallback = LuaUtil.getFunction(initParams, 2); + + if (data != null) { + fetchBitmapFromData(data); + } else { + fetchBitmapFromUrl(mUrl); + } + } + } + + /** + * fetch bitmap from data + * + * @param data + */ + private void fetchBitmapFromData(LuaValue data) { + if (data instanceof UDData) { + new SimpleTask2() { + @Override + protected Bitmap doInBackground(byte[]... params) { + byte[] bmpData = params != null && params.length > 0 ? params[0] : null; + if (bmpData != null) { + try { + return BitmapFactory.decodeByteArray(bmpData, 0, bmpData.length); + } catch (Throwable e){ + e.printStackTrace(); + LogUtil.e("[LuaView-Error] Bitmap.fetchBitmapFromData OutOfMemoryError!"); + } + } + return null; + } + + @Override + protected void onPostExecute(Bitmap bitmap) { + mBitmap = bitmap; + LuaUtil.callFunction(mCallback, bitmap != null ? LuaValue.TRUE : LuaValue.FALSE); + } + }.executeInPool(((UDData) data).bytes()); + } + } + + /** + * fetch bitmap from url or local file + * + * @param urlOrName + */ + private void fetchBitmapFromUrl(String urlOrName) { + if (!TextUtils.isEmpty(urlOrName)) { + if (URLUtil.isNetworkUrl(urlOrName)) {//network + final ImageProvider provider = LuaView.getImageProvider(); + if (provider != null) { + provider.preload(getContext(), urlOrName, new DrawableLoadCallback() { + @Override + public void onLoadResult(Drawable result) { + mBitmap = result instanceof BitmapDrawable ? ((BitmapDrawable) result).getBitmap() : null; + callCallback(mBitmap); + + if(mBitmap == null){ + LogUtil.i("[LuaView-Info] UDBitmap load image failed"); + } + } + }); + } else { + callCallback(null); + } + } else { + if (getLuaResourceFinder() != null) {//异步加载图片 + getLuaResourceFinder().findDrawable(urlOrName, new LuaResourceFinder.DrawableFindCallback() { + @Override + public void onStart(String urlOrPath) { + } + + @Override + public void onFinish(Drawable drawable) { + mBitmap = drawable instanceof BitmapDrawable ? ((BitmapDrawable) drawable).getBitmap() : null; + callCallback(drawable); + + if(mBitmap == null){ + LogUtil.i("[LuaView-Info] UDBitmap load image failed"); + } + } + }); + } else { + callCallback(null); + } + } + } else {//设置null + callCallback(true); + } + } + + /** + * call callback + * + * @param result + */ + private void callCallback(Object result) { + if (mCallback != null) {//异步回调,需要checktag + LuaUtil.callFunction(mCallback, result != null ? LuaValue.TRUE : LuaValue.FALSE); + } + } + + /** + * 创建一个切片 + * + * @param x + * @param y + * @param width + * @param height + * @param callback + * @return + */ + public LuaValue sprite(final int x, final int y, final int width, final int height, final LuaFunction callback) { + if (callback != null) { + new SimpleTask1() { + @Override + protected LuaValue doInBackground(Object... params) { + return createSprite(x, y, width, height); + } + + @Override + protected void onPostExecute(LuaValue luaValue) { + LuaUtil.callFunction(callback, luaValue); + } + }.executeInPool(); + return LuaValue.NIL; + } else { + return createSprite(x, y, width, height); + } + } + + private LuaValue createSprite(final int x, final int y, final int width, final int height) { + if (mBitmap != null) { + UDBitmap bitmap = new UDBitmap(getGlobals(), getmetatable(), null); + try { + bitmap.mBitmap = Bitmap.createBitmap(mBitmap, x, y, width, height); + return bitmap; + } catch (Throwable e){ + e.printStackTrace(); + LogUtil.e("[LuaView-Error] Bitmap.createSprite failed", x, y, width, height, "Error!"); + } + } + return LuaValue.NIL; + } + + public int getWidth() { + return mBitmap != null ? mBitmap.getWidth() : 0; + } + + public int getHeight() { + return mBitmap != null ? mBitmap.getHeight() : 0; + } + + public Bitmap getBitmap() { + return mBitmap; + } + + public Drawable createDrawable() { + if (getContext() != null) { + return new BitmapDrawable(getContext().getResources(), mBitmap); + } + return null; + } + +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/userdata/kit/UDData.java b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/kit/UDData.java new file mode 100644 index 00000000..ad766712 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/kit/UDData.java @@ -0,0 +1,134 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.userdata.kit; + +import com.taobao.luaview.userdata.base.BaseUserdata; +import com.taobao.luaview.util.JsonUtil; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; + +import java.io.ByteArrayOutputStream; +import java.io.UnsupportedEncodingException; + +/** + * Data 用户数据封装,二进制数据 + * + * @author song + * @date 15/9/6 + */ +public class UDData extends BaseUserdata { + private static final int DEFAULT_BUFFER_SIZE = 128; + public static final String DEFAULT_ENCODE = "utf-8"; + + public UDData(Globals globals, LuaValue metatable, Varargs varargs) { + super(new ByteArrayOutputStream(DEFAULT_BUFFER_SIZE), globals, metatable, varargs); + init(); + } + + private void init() { + ByteArrayOutputStream byteArrayBuffer = (ByteArrayOutputStream) userdata(); + if (initParams != null) { + try { + for (int i = 0; i < initParams.narg(); i++) { + Object obj = initParams.arg(i + 1); + String str = String.valueOf(obj); + byte[] data = str.getBytes(DEFAULT_ENCODE); + byteArrayBuffer.write(data, 0, data.length); + } + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + } + } + + /** + * get bytes of this data + * @return + */ + public byte[] bytes() { + if (userdata() instanceof ByteArrayOutputStream) { + return ((ByteArrayOutputStream) userdata()).toByteArray(); + } + return null; + } + + @Override + public LuaValue add(LuaValue data2) { + return new UDData(getGlobals(), getmetatable(), null).append(this).append(data2); + } + + /** + * 新增一部分数据 + * + * @param appendData + * @return + */ + public UDData append(Object appendData) { + ByteArrayOutputStream result = (ByteArrayOutputStream) this.userdata(); + if (appendData instanceof UDData) { + ByteArrayOutputStream buffer2 = (ByteArrayOutputStream) ((UDData) appendData).userdata(); + result.write(buffer2.toByteArray(), 0, buffer2.size()); + } else if (appendData instanceof byte[]) { + byte[] buffer2 = (byte[]) appendData; + result.write(buffer2, 0, buffer2.length); + } + return this; + } + + @Override + public String tojstring() { + return toString(DEFAULT_ENCODE); + } + + + @Override + public String toString() { + return tojstring(); + } + + /** + * 转成给定的编码字符 + * + * @param encode + * @return + */ + public String toString(String encode) { + ByteArrayOutputStream buffer = (ByteArrayOutputStream) userdata(); + try { + return (buffer != null && buffer.size() > 0) ? new String(buffer.toByteArray(), encode != null ? encode : DEFAULT_ENCODE) : ""; + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + return ""; + } + + /** + * 将string转成方便阅读的Json数据 + * + * @param encode + * @return + */ + public String toJson(String encode) { + final String jsonString = toString(encode); + return JsonUtil.isJson(jsonString) ? jsonString : null; + } + + /** + * 转成LuaTable + * + * @param encode + * @return + */ + public LuaValue toTable(String encode) { + final String jsonString = toString(encode); + return JsonUtil.toLuaTable(jsonString); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/userdata/kit/UDDownloader.java b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/kit/UDDownloader.java new file mode 100644 index 00000000..e44bc127 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/kit/UDDownloader.java @@ -0,0 +1,64 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.userdata.kit; + +import android.text.TextUtils; + +import com.taobao.luaview.fun.mapper.LuaViewLib; +import com.taobao.luaview.userdata.base.BaseLuaTable; +import com.taobao.luaview.util.DateUtil; +import com.taobao.luaview.util.EncryptUtil; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaFunction; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; +import org.luaj.vm2.lib.VarArgFunction; + +/** + * 下载器 TODO + * + * @author song + * @date 15/9/6 + */ +@LuaViewLib(revisions = {"20170306已对标"}) +@Deprecated +public class UDDownloader extends BaseLuaTable { + + public UDDownloader(Globals globals, LuaValue metatable) { + super(globals, metatable); + init(); + } + + private void init() { + set("fetch", new fetch()); + } + + private String newFileName(String url) { + return EncryptUtil.md5(url) + DateUtil.getCurrent(DateUtil.DATE_FORMAT_CN_24_SHORT_ENG); + } + + /** + * 下载内容 + */ + class fetch extends VarArgFunction { + @Override + public Varargs invoke(Varargs args) { + final String url = args.optjstring(1, null); + if (!TextUtils.isEmpty(url)) { + final String fileName = args.optjstring(2, newFileName(url)); + final LuaFunction callback = args.optfunction(3, null); + //TODO 下载器下载并保存 + } + return UDDownloader.this; + } + } + + +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/userdata/kit/UDFile.java b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/kit/UDFile.java new file mode 100644 index 00000000..c8638419 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/kit/UDFile.java @@ -0,0 +1,211 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.userdata.kit; + +import android.text.TextUtils; + +import com.taobao.luaview.fun.mapper.LuaViewApi; +import com.taobao.luaview.fun.mapper.LuaViewLib; +import com.taobao.luaview.global.LuaResourceFinder; +import com.taobao.luaview.global.VmVersion; +import com.taobao.luaview.scriptbundle.asynctask.SimpleTask1; +import com.taobao.luaview.userdata.base.BaseLuaTable; +import com.taobao.luaview.util.FileUtil; +import com.taobao.luaview.util.LuaUtil; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaString; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; +import org.luaj.vm2.lib.VarArgFunction; + +import java.io.File; + +/** + * File 用户数据封装 + * + * @author song + * @date 15/9/6 + */ +@LuaViewLib(revisions = {"20170306已对标"}) +@LuaViewApi(since = VmVersion.V_550) +public class UDFile extends BaseLuaTable { + + public UDFile(Globals globals, LuaValue metatable) { + super(globals, metatable); + init(); + } + + private void init() { + set("save", new save()); + set("read", new read()); + set("exists", new exists()); + set("path", new path()); + } + + private int fixIndex(Varargs args) { + return args != null && args.arg1() instanceof UDFile ? 1 : 0; + } + + /** + * 保存文件 + */ + class save extends VarArgFunction { + @Override + public Varargs invoke(Varargs args) { + final int fixIndex = fixIndex(args); + if (args.narg() > fixIndex) { + final LuaResourceFinder finder = getLuaResourceFinder(); + if (finder != null) { + final LuaValue param1 = args.arg(fixIndex + 1); + final LuaValue param2 = args.arg(fixIndex + 2); + + String name = null; + byte[] data = null; + if (LuaUtil.isString(param1)) { + name = param1.optjstring(null); + + if (param2 instanceof UDData) { + data = ((UDData) param2).bytes(); + } else if (param2 instanceof LuaString) { + data = ((LuaString) param2).m_bytes; + } else if (param2 instanceof CharSequence) { + data = param2.toString().getBytes(); + } + + } else if (param1 instanceof UDData) { + data = ((UDData) param1).bytes(); + name = param2.optjstring(null); + } + + if (data != null && data.length > 0 && !TextUtils.isEmpty(name)) { + if (args.isfunction(fixIndex + 3)) { + final LuaValue callback = LuaUtil.getFunction(args, fixIndex + 3); + new SimpleTask1() { + @Override + protected Boolean doInBackground(Object... params) { + final String path = finder.buildSecurePathInSdcard((String) params[0]); + return FileUtil.save(path, (byte[]) params[1]); + } + + @Override + protected void onPostExecute(Boolean o) { + LuaUtil.callFunction(callback, o); + } + }.executeInPool(name, data); + } else { + final String path = finder.buildSecurePathInSdcard(name); + return valueOf(FileUtil.save(path, data)); + } + } + } + } + return FALSE; + } + } + + + /** + * 读取文件 + */ + class read extends VarArgFunction { + @Override + public Varargs invoke(Varargs args) { + final int fixIndex = fixIndex(args); + if (args.narg() > fixIndex) { + final LuaResourceFinder finder = getLuaResourceFinder(); + if (finder != null) { + final String name = LuaUtil.getString(args, fixIndex + 1); + final String path = finder.buildSecurePathInSdcard(name); + + if (args.isfunction(fixIndex + 2)) { + final LuaValue callback = LuaUtil.getFunction(args, fixIndex + 2); + if (path != null) { + new SimpleTask1() { + @Override + protected UDData doInBackground(Object... params) { + byte[] data = FileUtil.readBytes(new File(path)); + if (data != null) { + return new UDData(getGlobals(), getmetatable(), null).append(data); + } else { // 外存储卡读取不到的情况下,尝试在assets资源包下读取 + data = finder.readFromAssets(name); + return new UDData(getGlobals(), getmetatable(), null).append(data); + } + } + + @Override + protected void onPostExecute(UDData udData) { + LuaUtil.callFunction(callback, udData); + } + }.executeInPool(); + } else { + LuaUtil.callFunction(callback, NIL); + } + } else { + if (path != null) { + byte[] data = FileUtil.readBytes(new File(path)); + if (data != null) { + return new UDData(getGlobals(), getmetatable(), null).append(data); + } else { // 外存储卡读取不到的情况下,尝试在assets资源包下读取 + data = finder.readFromAssets(name); + if (data != null) { + return new UDData(getGlobals(), getmetatable(), null).append(data); + } else { + return NIL; + } + } + } else { + return NIL; + } + } + } + } + return NIL; + } + } + + /** + * 文件是否存在 + */ + class exists extends VarArgFunction { + @Override + public Varargs invoke(Varargs args) { + final int fixIndex = fixIndex(args); + if (args.narg() > fixIndex) { + final LuaResourceFinder finder = getLuaResourceFinder(); + if (finder != null) { + final String fileName = LuaUtil.getString(args, fixIndex + 1); + if (!TextUtils.isEmpty(fileName)) { + return valueOf(finder.exists(fileName)); + } + } + } + return valueOf(false); + } + } + + /** + * 获取文件绝对路径 + */ + class path extends VarArgFunction { + @Override + public Varargs invoke(Varargs args) { + final int fixIndex = fixIndex(args); + if (args.narg() > fixIndex) { + final LuaResourceFinder finder = getLuaResourceFinder(); + if (finder != null) { + final String fileName = LuaUtil.getString(args, fixIndex + 1); + final String path = finder.buildSecurePathInSdcard(fileName); + return path != null ? valueOf(path) : NIL; + } + } + return NIL; + } + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/userdata/kit/UDJson.java b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/kit/UDJson.java new file mode 100644 index 00000000..5d3eb7c5 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/kit/UDJson.java @@ -0,0 +1,122 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.userdata.kit; + +import com.taobao.luaview.fun.mapper.LuaViewLib; +import com.taobao.luaview.scriptbundle.asynctask.SimpleTask1; +import com.taobao.luaview.userdata.base.BaseLuaTable; +import com.taobao.luaview.util.JsonUtil; +import com.taobao.luaview.util.LuaUtil; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; +import org.luaj.vm2.lib.VarArgFunction; + +/** + * Json 用户数据封装 + * + * @author song + * @date 15/9/6 + */ +@LuaViewLib(revisions = {"20170306已对标", "iOS有toJson方法"}) +public class UDJson extends BaseLuaTable { + + public UDJson(Globals globals, LuaValue metatable) { + super(globals, metatable); + init(); + } + + private void init() { + set("toTable", new toTable()); + set("isValid", new isValid()); +// set("parse", new parse()); + } + + private int fixIndex(Varargs varargs){ + return varargs != null && varargs.arg1() instanceof UDJson ? 1 : 0; + } + + //is vaild + class isValid extends VarArgFunction { + + @Override + public LuaValue invoke(Varargs args) { + final int fixIndex = fixIndex(args); + final LuaValue target = args.arg(fixIndex + 1); + final LuaValue callback = LuaUtil.getFunction(args, fixIndex + 2); + if(callback != null){//通过callback来处理 + new SimpleTask1() { + @Override + protected LuaValue doInBackground(Object... params) { + return isValid(target); + } + + @Override + protected void onPostExecute(LuaValue result) { + LuaUtil.callFunction(callback, result); + } + }.executeInPool(); + return LuaValue.NIL; + } else { + return isValid(target); + } + } + + private LuaValue isValid(LuaValue target){ + if (target instanceof UDData) { + return valueOf(JsonUtil.isJson(((UDData) target).toJson(UDData.DEFAULT_ENCODE))); + } else if (LuaUtil.isString(target)) { + return valueOf(JsonUtil.isJson(target.optjstring(null))); + } + return LuaValue.FALSE; + } + } + + + //to table + class toTable extends VarArgFunction { + + @Override + public Varargs invoke(Varargs args) { + final int fixIndex = fixIndex(args); + final LuaValue target = args.arg(fixIndex + 1); + final LuaValue callback = LuaUtil.getFunction(args, fixIndex + 2); + if (callback != null) {//通过callback来处理toTable + new SimpleTask1() { + @Override + protected LuaValue doInBackground(Object... params) { + return toTable(target); + } + + @Override + protected void onPostExecute(LuaValue result) { + LuaUtil.callFunction(callback, result); + } + }.executeInPool(); + return NIL; + } else { + return toTable(target); + } + } + + private LuaValue toTable(LuaValue target) { + if (target instanceof UDData) { + return ((UDData) target).toTable(UDData.DEFAULT_ENCODE); + } else if (LuaUtil.isString(target)) { + return JsonUtil.toLuaTable(target.optjstring(null)); + } else if (LuaUtil.isTable(target)) { + return target; + } + return NIL; + } + } + + +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/userdata/kit/UDSystem.java b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/kit/UDSystem.java new file mode 100644 index 00000000..7811addd --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/kit/UDSystem.java @@ -0,0 +1,182 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.userdata.kit; + +import com.taobao.luaview.fun.mapper.LuaViewLib; +import com.taobao.luaview.global.SdkVersion; +import com.taobao.luaview.global.VmVersion; +import com.taobao.luaview.userdata.base.BaseLuaTable; +import com.taobao.luaview.util.AndroidUtil; +import com.taobao.luaview.util.DimenUtil; +import com.taobao.luaview.util.LuaUtil; +import com.taobao.luaview.util.NetworkUtil; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaBoolean; +import org.luaj.vm2.LuaTable; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; +import org.luaj.vm2.lib.VarArgFunction; +import org.luaj.vm2.lib.ZeroArgFunction; + +/** + * System 用户数据封装 + * + * @author song + * @date 15/9/6 + */ +@LuaViewLib(revisions = {"20170306已对标"}) +public class UDSystem extends BaseLuaTable { + + public UDSystem(Globals globals, LuaValue metatable) { + super(globals, metatable); + init(); + } + + private void init() { + set("ios", new ios());//是否ios + set("android", new android());//是否android + set("vmVersion", new vmVersion());//LuaView早期的版本系统 @Deprecated + set("sdkVersion", new sdkVersion());//LuaView版本 + set("osVersion", new osVersion());//系统版本 + set("platform", new platform());//平台信息 + set("scale", new scale());//屏幕分辨率 + set("device", new device());//设备信息 + set("screenSize", new screenSize());//屏幕尺寸 + set("network", new network());//获取网络 + set("gc", new gc()); + set("keepScreenOn", new keepScreenOn()); + } + + private int fixIndex(Varargs varargs){ + return varargs != null && varargs.arg1() instanceof UDSystem ? 1 : 0; + } + + class ios extends VarArgFunction { + @Override + public Varargs invoke(Varargs args) { + return LuaBoolean.FALSE; + } + } + + class android extends VarArgFunction { + @Override + public Varargs invoke(Varargs args) { + return LuaBoolean.TRUE; + } + } + + @Deprecated + class vmVersion extends VarArgFunction { + @Override + public Varargs invoke(Varargs args) { + return valueOf(VmVersion.getCurrent()); + } + } + + class sdkVersion extends VarArgFunction { + @Override + public Varargs invoke(Varargs args) { + return valueOf(SdkVersion.getCurrent()); + } + } + + class osVersion extends VarArgFunction { + @Override + public Varargs invoke(Varargs args) { + return valueOf(AndroidUtil.getOsVersion()); + } + } + + class platform extends VarArgFunction { + @Override + public Varargs invoke(Varargs args) { + return valueOf(AndroidUtil.getOsModel()); + } + } + + class scale extends VarArgFunction { + @Override + public Varargs invoke(Varargs args) { + return valueOf(AndroidUtil.getDensity(getContext())); + } + } + + class device extends VarArgFunction { + @Override + public Varargs invoke(Varargs args) { + LuaTable table = new LuaTable(); + table.set("device", AndroidUtil.getDevice()); + table.set("brand", AndroidUtil.getBrand()); + table.set("product", AndroidUtil.getProduct()); + table.set("manufacturer", AndroidUtil.getManufacturer()); + + //screen size + int[] screenSize = AndroidUtil.getWindowSizeInDp(getContext()); + table.set("window_width", screenSize[0]); + table.set("window_height", screenSize[1]); + + //action bar height + int actionBarHeight = AndroidUtil.getActionBarHeightInDp(getContext()); + table.set("nav_height", actionBarHeight); + int bottomNavHeight = AndroidUtil.getNavigationBarHeightInDp(getContext()); + table.set("bottom_nav_height", bottomNavHeight); + int statusBarHeight = AndroidUtil.getStatusBarHeightInDp(getContext()); + table.set("status_bar_height", statusBarHeight); + return table; + } + } + + + /** + * 系统屏幕大小 + */ + class screenSize extends VarArgFunction { + @Override + public Varargs invoke(Varargs args) { + return varargsOf(new LuaValue[]{valueOf(DimenUtil.pxToDpi(AndroidUtil.getScreenWidth(getContext()))), valueOf(DimenUtil.pxToDpi(AndroidUtil.getScreenHeight(getContext())))}); + } + } + + /** + * 系统垃圾回收 + */ + class gc extends ZeroArgFunction { + @Override + public LuaValue call() { + java.lang.System.gc(); + return UDSystem.this; + } + } + + /** + * 获取网络状态 + */ + class network extends VarArgFunction { + @Override + public Varargs invoke(Varargs varargs) { + return valueOf(NetworkUtil.getCurrentTypeStr(getContext())); + } + } + + /** + * 屏幕常亮开启 + */ + class keepScreenOn extends VarArgFunction { + @Override + public Varargs invoke(Varargs varargs) { + if (getGlobals() != null && getGlobals().getRenderTarget() != null) { + final int fixIndex = fixIndex(varargs); + final Boolean keepScreenOn = LuaUtil.getBoolean(varargs, fixIndex + 1); + getGlobals().getRenderTarget().setKeepScreenOn(keepScreenOn != null ? keepScreenOn : true); + } + return LuaValue.NIL; + } + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/userdata/kit/UDTimer.java b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/kit/UDTimer.java new file mode 100644 index 00000000..d5c93f47 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/kit/UDTimer.java @@ -0,0 +1,186 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.userdata.kit; + +import android.os.Handler; + +import com.taobao.luaview.userdata.base.BaseCacheUserdata; +import com.taobao.luaview.util.LuaUtil; +import com.taobao.luaview.util.LuaViewUtil; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaFunction; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; + +/** + * Timer 用户数据封装 + * + * @author song + * @date 15/9/6 + */ +public class UDTimer extends BaseCacheUserdata { + private LuaFunction mCallback; + + private Handler mTimerHandler; + + private Runnable mTimerRunnable; + + //启动延时,默认为0 + private long mDelay = 0L; + + //是否重复,默认为false + private boolean mRepeat = false; + + //间隔,重复间隔,默认为1秒 + private long mInterval = 1000L; + + //是否正在调用callback +// private boolean isCalling = false; + + //isRunning + private boolean isRunning = false; + + public UDTimer(Globals globals, LuaValue metatable, Varargs varargs) { + super(new Handler(), globals, metatable, varargs); + init(); + } + + private void init() { + this.mTimerHandler = (Handler) userdata(); + this.mCallback = initParams.optfunction(1, null); + } + + @Override + public void onCacheClear() { + this.cancel(); + } + + /** + * set delegate + * + * @param callback + */ + public UDTimer setCallback(LuaFunction callback) { + this.mCallback = callback; + return this; + } + + public LuaFunction getCallback() { + return this.mCallback; + } + + /** + * 设置delay + * + * @param delay + * @return + */ + public UDTimer setDelay(long delay) { + this.mDelay = delay; + return this; + } + + public long getDelay() { + return mDelay; + } + + /** + * 设置repeat + * + * @param repeat + * @return + */ + public UDTimer setRepeat(boolean repeat) { + this.mRepeat = repeat; + return this; + } + + public boolean isRepeat() { + return mRepeat; + } + + /** + * 设置intervale + * + * @param interval + * @return + */ + public UDTimer setInterval(long interval) { + if (interval >= 0) { + this.mInterval = interval; + } + return this; + } + + public long getInterval() { + return mInterval; + } + + + /** + * start a timer + * + * @param interval + * @param repeat + */ + public UDTimer start(final Long interval, final Boolean repeat) { + if (interval != null) { + mInterval = interval; + mDelay = interval; + } + if (repeat != null) { + mRepeat = repeat; + } + + if (mTimerRunnable != null) {//start新的时候新停掉老的 + cancel(); + } + + mTimerRunnable = new Runnable() { + @Override + public void run() { + if (isRunning) { +// LogUtil.d("timercallback9", DateUtil.getCurrent("yyyy-MM-dd HH:mm:ss SSS")); + if (mRepeat && mTimerHandler != null) { + mTimerHandler.postDelayed(this, mInterval); + } + LuaViewUtil.runOnUiThread(getContext(), new Runnable() { + @Override + public void run() { + LuaUtil.callFunction(mCallback); + } + }); + /*if (!isCalling){ + isCalling = true; + LuaUtil.callFunction(mCallback); + isCalling = false; + }*/ + } + } + }; + this.isRunning = true; + this.mTimerHandler.postDelayed(mTimerRunnable, mDelay); + + return this; + } + + /** + * cancel a runnable + */ + public UDTimer cancel() { + if (this.mTimerHandler != null && this.mTimerRunnable != null) { + this.mTimerHandler.removeCallbacks(this.mTimerRunnable); + this.mTimerRunnable = null; + this.isRunning = false; +// this.isCalling = false; + } + return this; + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/userdata/kit/UDUnicode.java b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/kit/UDUnicode.java new file mode 100644 index 00000000..04819764 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/kit/UDUnicode.java @@ -0,0 +1,46 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.userdata.kit; + +import com.taobao.luaview.userdata.base.BaseUserdata; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; + +/** + * Unicode 用户数据封装 + * + * @author song + * @date 15/9/6 + */ +public class UDUnicode extends BaseUserdata { + + private String mCharSequence; + + public UDUnicode(Globals globals, LuaValue metatable, Varargs varargs) { + super(globals, metatable); + init(varargs); + } + + private void init(Varargs varargs) { + final StringBuffer sb = new StringBuffer(); + if (varargs != null) { + for (int i = 0; i < varargs.narg(); i++) { + sb.append(varargs.tochar(i + 1)); + } + } + mCharSequence = sb.toString(); + } + + public LuaValue getUnicode() { + return valueOf(mCharSequence); + } + +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/userdata/kit/UDVibrator.java b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/kit/UDVibrator.java new file mode 100644 index 00000000..de531a21 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/kit/UDVibrator.java @@ -0,0 +1,96 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.userdata.kit; + +import android.content.Context; +import android.os.Vibrator; + +import com.taobao.luaview.userdata.base.BaseUserdata; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaTable; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; + +/** + * Vibrate 用户数据封装 + * + * @author song + * @date 15/9/6 + */ +public class UDVibrator extends BaseUserdata { + private Vibrator mVibrator; + + public UDVibrator(Globals globals, LuaValue metatable, Varargs varargs) { + super(globals, metatable, varargs); + } + + + public synchronized Vibrator getVibrator() { + if (mVibrator == null && getContext() != null) { + mVibrator = (Vibrator) getContext().getSystemService(Context.VIBRATOR_SERVICE); + } + return mVibrator; + } + + /** + * 是否有震动组件 + * @return + */ + public boolean hasVibrator() { + return getVibrator() != null && getVibrator().hasVibrator(); + } + + /** + * 震动 + * + * @param time + * @return + */ + public UDVibrator vibrate(final long time) { + final Vibrator vibrator = getVibrator(); + if (vibrator != null) { + vibrator.vibrate(time); + } + return this; + } + + /** + * 震动 + * + * @param patternTable + * @param repeat + * @return + */ + public UDVibrator vibrate(final LuaTable patternTable, final Integer repeat) { + if (patternTable != null) { + final Vibrator vibrator = getVibrator(); + if (vibrator != null) { + if (patternTable.length() > 1) { + long[] pattern = new long[patternTable.length()]; + for (int i = 0; i < patternTable.length(); i++) { + pattern[i] = (long) (patternTable.get((i + 1)).optdouble(1) * 1000); + } + vibrator.vibrate(pattern, repeat); + } else { + vibrator.vibrate((long) (patternTable.get(1).optdouble(1) * 1000)); + } + } + } + return this; + } + + public UDVibrator cancel() { + final Vibrator vibrator = getVibrator(); + if (vibrator != null) { + vibrator.cancel(); + } + return this; + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/userdata/list/UDBaseListOrRecyclerView.java b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/list/UDBaseListOrRecyclerView.java new file mode 100644 index 00000000..11a8f7af --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/list/UDBaseListOrRecyclerView.java @@ -0,0 +1,673 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.userdata.list; + +import android.graphics.Point; +import android.view.ViewGroup; +import android.widget.AbsListView; + +import com.taobao.luaview.cache.SparseCache; +import com.taobao.luaview.global.LuaView; +import com.taobao.luaview.provider.ImageProvider; +import com.taobao.luaview.userdata.ui.UDViewGroup; +import com.taobao.luaview.util.AndroidUtil; +import com.taobao.luaview.util.DimenUtil; +import com.taobao.luaview.util.LuaUtil; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; + +import java.util.HashMap; +import java.util.concurrent.atomic.AtomicBoolean; + +/** + * UDBaseListView or RecyclerView + * + * @author song + * @date 15/10/23 + */ +public abstract class UDBaseListOrRecyclerView extends UDViewGroup { + //初始化数据 + private LuaValue mSectionDelegate; + protected LuaValue mCellDelegate; + + //view type map + private AtomicBoolean isSectionLengthInit = new AtomicBoolean(false); + private Point[] mSectionLength;//长度数组,每个point的x为开始位置(包含),y为结束位置(不包含),(y-x)为该组长度 + protected HashMap mViewTypeMap = new HashMap();//view类型集合,从0开始,不能放到init中初始化 + protected HashMap mViewTypeNameMap = new HashMap();//View类型名称集合,不能放到init中初始化 + + //id + protected SparseCache mIdCache; + + //延迟加载 + protected boolean mLazyLoad = true; + + public UDBaseListOrRecyclerView(T view, Globals globals, LuaValue metaTable, Varargs initParams) { + super(view, globals, metaTable, initParams); + init(); + } + + /** + * 初始化数据 + */ + public void init() { + if (this.initParams != null) { + this.mIdCache = new SparseCache(); + + this.mSectionDelegate = LuaUtil.getValue(initParams, "Section"); + this.mCellDelegate = LuaUtil.getValue(initParams, "Cell"); + this.mCallback = LuaUtil.getValue(initParams, "Callback"); + initSectionLength(); + } + } + + /** + * 初始化section的长度 + */ + private void initSectionLength() { + isSectionLengthInit.set(false); + final int numOfSections = getSectionCount(); + if (numOfSections > 0) { + mSectionLength = new Point[numOfSections]; + int left = 0, right = 0; + for (int i = 0; i < numOfSections; i++) { + left = right; + right = right + getRowCount(i); + mSectionLength[i] = new Point(left, right); + } + } + isSectionLengthInit.set(true); + } + + //-----------------------------------------section---------------------------------------------- + + /** + * 获取新的总数跟老的总数差别 + * + * @return + */ + public int getDiffTotalCount() { + int oldCount = (isSectionLengthInit.get() && mSectionLength != null) ? mSectionLength[mSectionLength.length - 1].y : 0; + int newCount = getRawTotalCount(); + return newCount - oldCount; + } + + /** + * 获取总的个数 + * + * @return + */ + public int getTotalCount() { + if (isSectionLengthInit.get()) { + return mSectionLength != null ? mSectionLength[mSectionLength.length - 1].y : 0; + } else { + final int totalSections = getSectionCount(); + int totalCount = 0; + for (int i = 0; i < totalSections; i++) { + totalCount += getRowCount(i); + } + return totalCount; + } + } + + /** + * 获取原始总个数 + * + * @return + */ + protected int getRawTotalCount() { + final int totalSections = getRawSectionCount(); + int totalCount = 0; + for (int i = 0; i < totalSections; i++) { + totalCount += getRawRowCount(i); + } + return totalCount; + } + + /** + * 返回新count 跟 老count的差距 + * + * @return + */ + protected int getDiffSectionCount() { + int oldCount = (isSectionLengthInit.get() && mSectionLength != null) ? mSectionLength.length : 0; + int newCount = getRawSectionCount(); + return newCount - oldCount; + } + + /** + * 分区个数,android的totalCount=分区个数*每个分区的数目 + * + * @return + */ + protected int getSectionCount() { + if (isSectionLengthInit.get()) { + return mSectionLength != null ? mSectionLength.length : 0; + } else { + return getRawSectionCount(); + } + } + + /** + * 获取原始的SectionCount + * + * @return + */ + protected int getRawSectionCount() { + if (this.mSectionDelegate == null) { + return 0; + } + + return LuaUtil.getOrCallFunction(this.mSectionDelegate.get("SectionCount")).optint(1); + } + + /** + * 获取diff of new RowCount and old RowCount of Section + * + * @param section + * @return + */ + protected int diffRowCount(int section) { + int oldCount = (isSectionLengthInit.get() && mSectionLength != null) ? (this.mSectionLength[section].y - this.mSectionLength[section].x) : 0; + int newCount = getRawRowCount(section); + return newCount - oldCount; + } + + /** + * 每个分区的行数,section从0开始 + * + * @param section + * @return + */ + protected int getRowCount(int section) { + if (isSectionLengthInit.get()) { + return mSectionLength != null ? (this.mSectionLength[section].y - this.mSectionLength[section].x) : 0; + } else { + return getRawRowCount(section); + } + } + + /** + * 读取RowCount,获取原始count + * + * @param section + * @return + */ + protected int getRawRowCount(int section) { + return LuaUtil.callFunction(this.mSectionDelegate.get("RowCount"), LuaUtil.toLuaInt(section)).optint(0); + } + //------------------------------------------cell------------------------------------------------ + + /** + * get position by section and rowInSection + * + * @param section + * @param rowInSection + * @return + */ + protected int getPositionBySectionAndRow(int section, int rowInSection) { + if (mSectionLength != null) { + if (section >= 0 && section < mSectionLength.length) { + return mSectionLength[section].x + rowInSection; + } else { + return 0; + } + } + return rowInSection; + } + + /** + * 根据position来判断该位置属于哪个position + * + * @param position + * @return + */ + protected int getSectionByPosition(int position) { + if (mSectionLength != null) { + for (int i = 0; i < mSectionLength.length; i++) { + if (position >= mSectionLength[i].x && position < mSectionLength[i].y) { + return i; + } + } + } + return 0; + } + + /** + * 根据position来判断该位置位于section的第几个位置 + * + * @param position + * @return + */ + protected int getRowInSectionByPosition(int position) { + if (mSectionLength != null) { + final int section = getSectionByPosition(position); + return position - mSectionLength[section].x; + } else { + return 0; + } + } + + /** + * 根据position获取某个cell的类型 + * + * @param position + * @return + */ + public String getId(int position) { + return getId(position, getSectionByPosition(position), getRowInSectionByPosition(position)); + } + + /** + * 根据section, row获取cell的Id + * + * @param position + * @param section + * @param row + * @return + */ + protected String getId(int position, int section, int row) { + final String cacheId = mIdCache != null ? mIdCache.get(position) : null; + if (cacheId != null) { + return cacheId; + } else { + final String id = LuaUtil.callFunction(mCellDelegate.get("Id"), LuaUtil.toLuaInt(section), LuaUtil.toLuaInt(row)).optjstring(""); + if (mIdCache != null) { + mIdCache.put(position, id); + } + return id; + } + } + + + /** + * 根据id获取某个cell + * + * @param id + * @return + */ + public LuaValue getCell(String id) { + return mCellDelegate.get(id); + } + + + /** + * 是否有size的定义 + * + * @param position + * @return + */ + public boolean hasCellSize(int position) { + return hasCellFunction(position, "Size"); + } + + /** + * return width, height + * + * @param cell + * @param position + * @return + */ + public int[] callCellSize(LuaValue cell, int position, int... defaultSize) { + final Varargs size = invokeCellSize(cell, position); + int defaultWidth = (defaultSize != null && defaultSize.length > 1) ? defaultSize[0] : AndroidUtil.getScreenWidth(getContext()); + int width = 0, height = 0; + if (size != null) { + if (size.narg() > 1) {//width & height + width = DimenUtil.dpiToPx(size.arg(1), defaultWidth); + height = DimenUtil.dpiToPx(size.arg(2)); + } else { + width = defaultWidth; + height = DimenUtil.dpiToPx(size.arg(1)); + } + } + return new int[]{width, height}; + } + + /** + * 调用 Size 方法 (返回多个值) + * + * @param cell + * @param position + * @return + */ + public Varargs invokeCellSize(LuaValue cell, int position) { +// return invokeCellFunction("Size", cell, position); + return invokeCellFunction("Size", position);//不带cell + } + + /** + * 调用 Init 方法 + * + * @param cell + * @param position + * @return + */ + public LuaValue callCellInit(LuaValue cell, int position) { + return callCellFunction("Init", cell, position);//Lua从1开始 + } + + /** + * 调用 Layout 方法 + * + * @param cell + * @param position + * @return + */ + public LuaValue callCellLayout(LuaValue cell, int position) { + return callCellFunction("Layout", cell, position); + } + + /** + * 调用 Callback 方法 + * + * @param cell + * @param position + * @return + */ + public LuaValue onCellClicked(LuaValue cell, int position) { + final int section = getSectionByPosition(position); + final int row = getRowInSectionByPosition(position); + final String id = getId(position, section, row); + final LuaValue cellData = getCell(id); + if (cellData != null) { + final LuaValue callback = cellData.get("Callback"); + if (callback.isfunction()) { + return LuaUtil.callFunction(callback, cell, LuaUtil.toLuaInt(section), LuaUtil.toLuaInt(row)); + } else if (callback.istable()) { + return LuaUtil.callFunction(LuaUtil.getFunction(callback, "Click", "click"), cell, LuaUtil.toLuaInt(section), LuaUtil.toLuaInt(row)); + } + } + return NIL; + } + + /** + * 调用 Callback 方法 + * + * @param cell + * @param position + * @return + */ + public boolean onCellLongClicked(LuaValue cell, int position) { + final int section = getSectionByPosition(position); + final int row = getRowInSectionByPosition(position); + final String id = getId(position, section, row); + final LuaValue cellData = getCell(id); + if (cellData != null) { + final LuaValue callback = cellData.get("Callback"); + if (callback != null && callback.istable()) { + return LuaUtil.callFunction(LuaUtil.getFunction(callback, "LongClick", "longClick"), cell, LuaUtil.toLuaInt(section), LuaUtil.toLuaInt(row)).optboolean(false); + } + } + return false; + } + + /** + * 调用cell的某个方法 + * + * @param method + * @param cell + * @param position + * @return + */ + private LuaValue callCellFunction(String method, LuaValue cell, int position) { + final int section = getSectionByPosition(position); + final int row = getRowInSectionByPosition(position); + return callCellFunction(getId(position, section, row), method, cell, section, row); + } + + /** + * 调用cell的某个方法,返回多个值 + * + * @param method + * @param cell + * @param position + * @return + */ + private Varargs invokeCellFunction(String method, LuaValue cell, int position) { + final int section = getSectionByPosition(position); + final int row = getRowInSectionByPosition(position); + return invokeCellFunction(getId(position, section, row), method, cell, section, row); + } + + /** + * 调用cell的某个方法,返回多个值 + * + * @param method + * @param position + * @return + */ + private Varargs invokeCellFunction(String method, int position) { + final int section = getSectionByPosition(position); + final int row = getRowInSectionByPosition(position); + return invokeCellFunction(getId(position, section, row), method, section, row); + } + + /** + * 调用cell的某个方法 + * + * @param id + * @param method + * @param cell + * @param section + * @param row + * @return + */ + private LuaValue callCellFunction(String id, String method, LuaValue cell, int section, int row) { + final LuaValue methodData = getCell(id); + if (!methodData.isnil()) { + return LuaUtil.callFunction(methodData.get(method), cell, LuaUtil.toLuaInt(section), LuaUtil.toLuaInt(row)); + } + return NIL; + } + + /** + * 调用cell的某个方法 (返回多个值) + * + * @param id + * @param method + * @param cell + * @param section + * @param row + * @return + */ + private Varargs invokeCellFunction(String id, String method, LuaValue cell, int section, int row) { + final LuaValue methodData = getCell(id); + if (!methodData.isnil()) { + return LuaUtil.invokeFunction(methodData.get(method), cell, LuaUtil.toLuaInt(section), LuaUtil.toLuaInt(row)); + } + return NIL; + } + + /** + * 调用cell的某个方法 (返回多个值) + * + * @param id + * @param method + * @param section + * @param row + * @return + */ + private Varargs invokeCellFunction(String id, String method, int section, int row) { + final LuaValue methodData = getCell(id); + if (!methodData.isnil()) { + return LuaUtil.invokeFunction(methodData.get(method), LuaUtil.toLuaInt(section), LuaUtil.toLuaInt(row)); + } + return NIL; + } + + /** + * 是否有某个函数 + * + * @param method + * @param position + * @return + */ + private boolean hasCellFunction(int position, String method) { + final int section = getSectionByPosition(position); + final int row = getRowInSectionByPosition(position); + final String id = getId(position, section, row); + return hasCellFunction(id, method); + } + + /** + * 是否有某个函数 + * + * @param cellId + * @param method + * @return + */ + public boolean hasCellFunction(String cellId, String method) { + final LuaValue methodData = getCell(cellId); + return !methodData.isnil() && methodData.get(method) != null && methodData.get(method).isfunction(); + } + + /** + * 获取key map + * + * @return + */ + public HashMap getCellKeyMap() { + HashMap result = new HashMap(); + if (mCellDelegate != null) { + LuaValue[] keys = this.mCellDelegate.checktable().keys(); + if (keys != null) { + for (int i = 0; i < keys.length; i++) { + result.put(keys[i].toString(), i); + } + } + } + return result; + } + + /** + * 根据位置获取 item 的type id + * + * @param position + * @return + */ + public int getItemViewType(int position) { + final String viewTypeName = getId(position);//得到坑位类型名称 + if (this.mViewTypeMap != null) { + if (!this.mViewTypeMap.containsKey(viewTypeName)) { + final int index = this.mViewTypeMap.size(); + this.mViewTypeMap.put(viewTypeName, index); + this.mViewTypeNameMap.put(index, viewTypeName); + return index; + } + return this.mViewTypeMap.get(viewTypeName); + } + return 0; + } + + /** + * 获取ViewType的name + * + * @param viewType + * @return + */ + public String getItemViewTypeName(int viewType) { + if (this.mViewTypeNameMap != null) { + return this.mViewTypeNameMap.get(viewType); + } + return null; + } + + /** + * 这里不是真实的viewType的数字,只是获取Cell中的属性数目(该属性数目一定比cell种数多) + * TODO 这里通过读取ID的方式获取所有的count + * + * @return + */ + public int getViewTypeCount() { + return getCellKeyMap().size(); + } + + + public UDBaseListOrRecyclerView setLazyLoad(boolean mLazyLoad) { + this.mLazyLoad = mLazyLoad; + return this; + } + + //-----------------------------------------lazy load-------------------------------------------- + + /** + * 更新所有子view的ScrollState,用于延迟加载 + * + * @param view + * @param scrollState + */ + protected void updateAllChildScrollState(ViewGroup view, int scrollState) { + if (this.mLazyLoad && view != null) { + if (scrollState >= AbsListView.OnScrollListener.SCROLL_STATE_FLING) {//手滑动的时候 + final ImageProvider provider = LuaView.getImageProvider(); + if (provider != null) { + provider.pauseRequests(view, getContext()); + } + } else { + final ImageProvider provider = LuaView.getImageProvider(); + if (provider != null) { + provider.resumeRequests(view, getContext()); + } + } + } + } + + //------------------------------------------Scroll---------------------------------------------- + + /** + * 初始化滚动回调 + */ + public abstract void initOnScrollCallback(final T view); + + //------------------------------------------功能------------------------------------------------ + + /** + * 重新加载 + * + * @return + */ + public abstract UDBaseListOrRecyclerView reload(Integer section, Integer row); + + /** + * listview滚动到顶部 + * + * @param animate 是否动画 + * @return + */ + public abstract UDBaseListOrRecyclerView scrollToTop(final int offset, final boolean animate); + + /** + * listview滚动到某个位置 + * + * @param section + * @param rowInSection + * @param offset + * @return + */ + public abstract UDBaseListOrRecyclerView scrollToItem(final int section, final int rowInSection, final int offset, final boolean animate); + + + /** + * 设置item最小间隔 + * + * @param spacing + * @return + */ + public abstract UDBaseListOrRecyclerView setMiniSpacing(final int spacing); + + /** + * 获取item最小间隔 + * + * @return + */ + public abstract int getMiniSpacing(); +} \ No newline at end of file diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/userdata/list/UDBaseListView.java b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/list/UDBaseListView.java new file mode 100644 index 00000000..29ad65b6 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/list/UDBaseListView.java @@ -0,0 +1,219 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.userdata.list; + +import android.view.ViewGroup; +import android.widget.AbsListView; +import android.widget.ListView; + +import com.taobao.luaview.userdata.ui.UDView; +import com.taobao.luaview.util.LuaUtil; +import com.taobao.luaview.view.interfaces.ILVListView; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; + +/** + * UDBaseListView 封装 + * + * @author song + * @date 15/10/23 + */ +public abstract class UDBaseListView extends UDBaseListOrRecyclerView { + + //header & footer + private LuaValue mHeader; + private LuaValue mFooter; + + public UDBaseListView(T view, Globals globals, LuaValue metaTable, Varargs initParams) { + super(view, globals, metaTable, initParams); + } + + public abstract ListView getListView(); + + + @Override + public UDBaseListOrRecyclerView reload(Integer section, Integer row) { + final T lv = getView(); + if (lv instanceof ILVListView) { + init();//重新初始化数据 + if (((ILVListView) lv).getLVAdapter() != null) { + ((ILVListView) lv).getLVAdapter().notifyDataSetChanged(); + } + } + return this; + } + + @Override + public void initOnScrollCallback(T view) { + if (view instanceof ListView) { + final ListView listview = (ListView) view; + if (LuaUtil.isValid(mCallback) || mLazyLoad) { + listview.setOnScrollListener(new AbsListView.OnScrollListener() { + @Override + public void onScrollStateChanged(AbsListView view, int scrollState) { + updateAllChildScrollState(view, scrollState); + + if (LuaUtil.isValid(mCallback)) {//callback + switch (scrollState) { + case AbsListView.OnScrollListener.SCROLL_STATE_TOUCH_SCROLL: { + final int itemPosition = listview.getFirstVisiblePosition() - listview.getHeaderViewsCount(); + final int section = getSectionByPosition(itemPosition); + final int row = getRowInSectionByPosition(itemPosition); + LuaUtil.callFunction(LuaUtil.getFunction(mCallback, "ScrollBegin", "scrollBegin"), LuaUtil.toLuaInt(section), LuaUtil.toLuaInt(row)); + break; + } + case AbsListView.OnScrollListener.SCROLL_STATE_FLING: + break; + case AbsListView.OnScrollListener.SCROLL_STATE_IDLE: { + final int itemPosition = listview.getFirstVisiblePosition() - listview.getHeaderViewsCount(); + final int section = getSectionByPosition(itemPosition); + final int row = getRowInSectionByPosition(itemPosition); + LuaUtil.callFunction(LuaUtil.getFunction(mCallback, "ScrollEnd", "scrollEnd"), LuaUtil.toLuaInt(section), LuaUtil.toLuaInt(row)); + break; + } + } + } + } + + @Override + public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { + if (LuaUtil.isValid(mCallback)) { + final int itemPosition = firstVisibleItem - listview.getHeaderViewsCount(); + final int section = getSectionByPosition(itemPosition); + final int row = getRowInSectionByPosition(itemPosition); + LuaUtil.callFunction(LuaUtil.getFunction(mCallback, "Scrolling", "scrolling"), LuaUtil.toLuaInt(section), LuaUtil.toLuaInt(row), valueOf(visibleItemCount)); + } + } + }); + } + } + } + + //------------------------------------------header---------------------------------------------- + + /** + * 调用Header函数 + * + * @return + */ + public UDView setHeader(LuaValue header) { + final T lv = getView(); + if (lv instanceof ILVListView) { + if (header instanceof UDView) { + mHeader = header; + ((ILVListView) lv).addHeader(((UDView) header).getView()); + } else if (header == null || header.isnil()) { + mHeader = NIL; + ((ILVListView) lv).removeHeader(); + } + } + return this; + } + + public LuaValue getHeader() { + return mHeader; + } + + //------------------------------------------footer---------------------------------------------- + + /** + * 调用Header函数 + * + * @return + */ + public UDView setFooter(LuaValue footer) { + final T lv = getView(); + if (lv instanceof ILVListView) { + if (footer instanceof UDView) { + mFooter = footer; + ((ILVListView) lv).addFooter(((UDView) footer).getView()); + } else if (footer == null || footer.isnil()) { + mFooter = NIL; + ((ILVListView) lv).removeFooter(); + } + } + return this; + } + + public LuaValue getFooter() { + return mFooter; + } + + + //-------------------------------------------scroll--------------------------------------------- + + /** + * listview滚动到顶部 + * + * @param animate 是否动画 + * @return + */ + public UDBaseListOrRecyclerView scrollToTop(final int offset, final boolean animate) { + final ListView lv = getListView(); + if (lv != null) { + if (animate) { + if (lv.getFirstVisiblePosition() > 7) {//hack fast scroll + lv.setSelection(7); + } + lv.smoothScrollToPositionFromTop(0, offset); + } else { + lv.setSelectionFromTop(0, offset); + } + } + return this; + } + + /** + * listview滚动到某个位置 + * + * @param section + * @param rowInSection + * @param offset + * @return + */ + public UDBaseListOrRecyclerView scrollToItem(final int section, final int rowInSection, final int offset, final boolean animate) { + final ListView lv = getListView(); + if (lv != null) { + if (animate) { + lv.smoothScrollToPositionFromTop(getPositionBySectionAndRow(section, rowInSection), offset); + } else { + lv.setSelectionFromTop(getPositionBySectionAndRow(section, rowInSection), offset); + } + } + return this; + } + + + /** + * 设置分隔条高度 + * + * @param height + * @return + */ + @Override + public UDBaseListOrRecyclerView setMiniSpacing(int height) { + final ListView lv = getListView(); + if (lv != null && height >= 0) { + lv.setDividerHeight(height); + } + return this; + } + + /** + * 获取分隔高度 + * + * @return + */ + @Override + public int getMiniSpacing() { + return getListView() != null ? getListView().getDividerHeight() : 0; + } +} \ No newline at end of file diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/userdata/list/UDBaseRecyclerView.java b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/list/UDBaseRecyclerView.java new file mode 100644 index 00000000..1e7646fa --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/list/UDBaseRecyclerView.java @@ -0,0 +1,582 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.userdata.list; + +import android.support.v7.widget.GridLayoutManager; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.support.v7.widget.StaggeredGridLayoutManager; +import android.util.SparseArray; +import android.util.SparseBooleanArray; +import android.util.SparseIntArray; +import android.view.View; +import android.view.ViewGroup; +import android.widget.AbsListView; +import android.widget.FrameLayout; +import android.widget.RelativeLayout; + +import com.taobao.luaview.global.Constants; +import com.taobao.luaview.userdata.constants.UDPinned; +import com.taobao.luaview.util.LuaUtil; +import com.taobao.luaview.view.LVRecyclerView; +import com.taobao.luaview.view.LVRefreshRecyclerView; +import com.taobao.luaview.view.recyclerview.LVRecyclerViewHolder; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; + +/** + * UDBaseRecyclerView 封装 + * + * @author song + * @date 15/10/23 + */ +public abstract class UDBaseRecyclerView extends UDBaseListOrRecyclerView { + + private static final int DEFAULT_MAX_SPAN = 1; + + private SparseIntArray mSpanSize; + + // 用于添加吸顶视图的容器 + private ViewGroup mPinnedContainer; + + private View mCurrentPinnedView; + + private int mCurrentPinnedPosition = -1; + + private boolean mHasPinnedCell = false; + + // 缓存真实的Pinned Cell Name + private SparseArray mPinnedPositionCellId = new SparseArray(); + + // 缓存被Pinned标记的position + public SparseBooleanArray mIsPinnedSparseArray = new SparseBooleanArray(); + // 缓存被pinned标记的viewType, position + public SparseIntArray mPinnedViewTypePosition = new SparseIntArray(); + // 缓存被pinned标记的position,Holder + public SparseArray mPinnedPositionHolder = new SparseArray(); + + public UDBaseRecyclerView(T view, Globals globals, LuaValue metaTable, Varargs initParams) { + super(view, globals, metaTable, initParams); + } + + public abstract LVRecyclerView getLVRecyclerView(); + + /** + * mPinnedViewTypePosition是onCreateViewHolder时缓存的,不能清除 + */ + private void restore() { + mHasPinnedCell = false; + mIsPinnedSparseArray.clear(); + mPinnedPositionCellId.clear(); + mPinnedViewTypePosition.clear(); + } + + /** + * notify data changed (section, row) in java + * + * @param section + * @param row + * @return + */ + @Override + public UDBaseRecyclerView reload(Integer section, Integer row) { + restore(); + + final LVRecyclerView recyclerView = getLVRecyclerView(); + if (recyclerView != null) { + final RecyclerView.Adapter adapter = recyclerView.getLVAdapter(); + if (adapter != null) { + int diffSectionCount = getDiffSectionCount(); + + if (section == null || diffSectionCount != 0) {//如果 section无值,或者section数量变动则更新所有 + refreshState(recyclerView); + adapter.notifyDataSetChanged(); + } else {//如果传了section,row,则表示要更新部分数据 + int diffTotalCount = getDiffTotalCount();//total count diff + boolean isChanged = diffTotalCount == 0;//数据变更,数量未变更 + boolean isInserted = diffTotalCount > 0;//数量增加 + boolean isRemoved = diffTotalCount < 0;//数量减少 + + if (row == null) {//row is null, notify whole section + int start = getPositionBySectionAndRow(section, 0); + int currentRowCount = getRowCount(section); + if (isChanged) {//更新整个section,count不变,数据变 + refreshState(recyclerView); + adapter.notifyItemRangeChanged(start, currentRowCount); + } else if (isInserted) {//更新整个section,count增加 + int newRowCount = getRawRowCount(section); + int count = Math.abs(newRowCount - currentRowCount);//新增count + refreshState(recyclerView); + adapter.notifyItemRangeInserted(start, count); + } else if (isRemoved) {//更新整个section,count减少 + int newRowCount = getRawRowCount(section); + int count = Math.abs(newRowCount - currentRowCount);//新增count + refreshState(recyclerView); + adapter.notifyItemRangeRemoved(start, count); + } + } else {//row not null, notify row + int pos = getPositionBySectionAndRow(section, row); + refreshState(recyclerView); + if (isChanged) {//更新某个元素 + adapter.notifyItemChanged(pos); + } else if (isInserted) {//插入一个元素 + adapter.notifyItemInserted(pos); + } else if (isRemoved) {//减少一个元素 + adapter.notifyItemRemoved(pos); + } + } + } + } + } + return this; + } + + /** + * 更新列表状态,重新更新数据,元素间隔等 + * + * @param recyclerView + */ + private void refreshState(LVRecyclerView recyclerView) { + init();//重新初始化数据 + recyclerView.updateMaxSpanCount(); + } + + @Override + public void initOnScrollCallback(final T view) { + if (view instanceof LVRecyclerView) { + final LVRecyclerView lvRecyclerView = (LVRecyclerView) view; + if (LuaUtil.isValid(mCallback) || mLazyLoad) { + lvRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { + @Override + public void onScrollStateChanged(RecyclerView recyclerView, int scrollState) { + updateAllChildScrollState(recyclerView, scrollState); + + if (LuaUtil.isValid(mCallback)) { + switch (scrollState) { + case AbsListView.OnScrollListener.SCROLL_STATE_TOUCH_SCROLL: { + final int itemPosition = lvRecyclerView.getFirstVisiblePosition(); + final int section = getSectionByPosition(itemPosition); + final int row = getRowInSectionByPosition(itemPosition); + LuaUtil.callFunction(LuaUtil.getFunction(mCallback, "ScrollBegin", "scrollBegin"), LuaUtil.toLuaInt(section), LuaUtil.toLuaInt(row)); + break; + } + case AbsListView.OnScrollListener.SCROLL_STATE_FLING: + break; + case AbsListView.OnScrollListener.SCROLL_STATE_IDLE: { + final int itemPosition = lvRecyclerView.getFirstVisiblePosition(); + final int section = getSectionByPosition(itemPosition); + final int row = getRowInSectionByPosition(itemPosition); + LuaUtil.callFunction(LuaUtil.getFunction(mCallback, "ScrollEnd", "scrollEnd"), LuaUtil.toLuaInt(section), LuaUtil.toLuaInt(row)); + break; + } + } + } + } + + @Override + public void onScrolled(RecyclerView recyclerView, int dx, int dy) { + if (LuaUtil.isValid(mCallback)) { + final int itemPosition = lvRecyclerView.getFirstVisiblePosition(); + final int section = getSectionByPosition(itemPosition); + final int row = getRowInSectionByPosition(itemPosition); + LuaUtil.callFunction(LuaUtil.getFunction(mCallback, "Scrolling", "scrolling"), LuaUtil.toLuaInt(section), LuaUtil.toLuaInt(row), valueOf(lvRecyclerView.getVisibleItemCount())); + } + + pinned(lvRecyclerView); + } + }); + } + } + } + + // TODO: 11/15/16 处理itemView之前有spacing的情况 + private void pinned(LVRecyclerView lvRecyclerView) { + if (!mHasPinnedCell) + return; + + if (mPinnedContainer == null) { + mPinnedContainer = new FrameLayout(lvRecyclerView.getContext()); + RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); + + ViewGroup parent = (ViewGroup) lvRecyclerView.getParent(); + if (parent instanceof LVRefreshRecyclerView) { + // RefreshCollectionView + params.leftMargin = (int) parent.getX(); + params.topMargin = (int) parent.getY(); + ((ViewGroup) parent.getParent()).addView(mPinnedContainer, params); + } else { + // CollectionView + params.leftMargin = (int) lvRecyclerView.getX(); + params.topMargin = (int) lvRecyclerView.getY(); + parent.addView(mPinnedContainer, params); + } + } + + int firstVisiblePosition = findFirstVisiblePosition(lvRecyclerView.getLayoutManager()); + // 从firstVisiblePosition位置开始递减查找上一个pinned position + int pinnedViewPosition = findPinnedViewPositionDecrease(firstVisiblePosition); + if (pinnedViewPosition >= 0 && mCurrentPinnedPosition != pinnedViewPosition) { + if (mPinnedPositionHolder.get(pinnedViewPosition) != null) { + ViewGroup itemView = (ViewGroup) mPinnedPositionHolder.get(pinnedViewPosition).itemView; + View child = itemView.getChildAt(0); + if (child != null) { + // 从itemView移除child之前,先设置其与child一样的宽高占位。 + itemView.getLayoutParams().width = child.getLayoutParams().width; + itemView.getLayoutParams().height = child.getLayoutParams().height; + itemView.removeView(child); + mPinnedContainer.addView(child); + if (mCurrentPinnedView != null) { + mCurrentPinnedView.setVisibility(View.GONE); + } + mCurrentPinnedView = child; + } else { + // 从(pinnedViewPosition + 1)位置开始递增查找下一个pinned position + int nextPinnedPosition = findPinnedViewPositionIncrease(pinnedViewPosition + 1); + ViewGroup parentItemView = (ViewGroup) mPinnedPositionHolder.get(nextPinnedPosition).itemView; + View pinnedView = mPinnedContainer.getChildAt(mPinnedContainer.getChildCount() - 1); + mPinnedContainer.removeView(pinnedView); + parentItemView.addView(pinnedView); + mCurrentPinnedView = mPinnedContainer.getChildAt(mPinnedContainer.getChildCount() - 1); + if (mCurrentPinnedView != null) { + mCurrentPinnedView.setVisibility(View.VISIBLE); + } + } + + mCurrentPinnedPosition = pinnedViewPosition; + } + } + + // 第一个吸顶视图被移除的情况,亦即列表恢复没有吸顶视图的状态。 + if (pinnedViewPosition == -1 && mCurrentPinnedPosition != -1) { + View subview = mPinnedContainer.getChildAt(mPinnedContainer.getChildCount() - 1); + mPinnedContainer.removeView(subview); + // 从position 0开始找第一个pinned标记的itemView,并把最后一个吸顶视图添加回到它的原本位置 + int firstPinnedPosition = findPinnedViewPositionIncrease(0); + ViewGroup parentItemView = (ViewGroup) mPinnedPositionHolder.get(firstPinnedPosition).itemView; + parentItemView.addView(subview); + // 列表恢复没有吸顶视图的状态 + mCurrentPinnedPosition = -1; + mCurrentPinnedView = null; + } + + // 处理吸顶视图切换时的位移效果 + if (mPinnedContainer != null && mCurrentPinnedPosition != -1) { + View targetView = lvRecyclerView.findChildViewUnder(mPinnedContainer.getMeasuredWidth() / 2, mPinnedContainer.getMeasuredHeight() + 1); + if (targetView != null) { + boolean isPinned = ((Boolean) targetView.getTag(Constants.RES_LV_TAG_PINNED)).booleanValue(); + if (isPinned && targetView.getTop() > 0) { + if (pinnedViewPosition != -1) { + int deltaY = targetView.getTop() - mPinnedContainer.getMeasuredHeight(); + if (deltaY < (lvRecyclerView.getMiniSpacing() - mPinnedContainer.getMeasuredHeight())) { + // 防止设置了spacing的时候,在这个范围内mPinnedContainer被位移到top之上,而itemView是空白的现象 + mPinnedContainer.setTranslationY(0); + } else { + mPinnedContainer.setTranslationY(deltaY); + } + } + } else { + mPinnedContainer.setTranslationY(0); + } + } else { + mPinnedContainer.setTranslationY(0); + } + } + + // Fix bug: 解决调用scrollToPositionWithOffset()方法时,吸顶容器没有被绘制的问题。 + if (mPinnedContainer != null) { + mPinnedContainer.postDelayed(new Runnable() { + @Override + public void run() { + mPinnedContainer.requestLayout(); + } + }, 1); + } + } + + /** + * 从传入位置递增找出Pinned的位置 + * + * @param fromPosition + * @return int + */ + private int findPinnedViewPositionIncrease(int fromPosition) { + for (int position = fromPosition; position < this.getTotalCount(); position++) { + // 位置递减,只要查到位置是Pinned标示,立即返回此位置 + if (this.mIsPinnedSparseArray.get(position)) { + return position; + } + } + + return -1; + } + + /** + * 从传入位置递减找出Pinned的位置 + * + * @param fromPosition + * @return int + */ + private int findPinnedViewPositionDecrease(int fromPosition) { + for (int position = fromPosition; position >= 0; position--) { + // 位置递减,只要查到位置是Pinned标示,立即返回此位置 + if (this.mIsPinnedSparseArray.get(position)) { + return position; + } + } + + return -1; + } + + /** + * 找出第一个可见的Item的位置 + * + * @param layoutManager + * @return + */ + private int findFirstVisiblePosition(RecyclerView.LayoutManager layoutManager) { + int firstVisiblePosition = 0; + if (layoutManager instanceof GridLayoutManager) { + firstVisiblePosition = ((GridLayoutManager) layoutManager).findFirstVisibleItemPosition(); + } else if (layoutManager instanceof LinearLayoutManager) { + firstVisiblePosition = ((LinearLayoutManager) layoutManager).findFirstVisibleItemPosition(); + } else if (layoutManager instanceof StaggeredGridLayoutManager) { + int[] into = new int[((StaggeredGridLayoutManager) layoutManager).getSpanCount()]; + ((StaggeredGridLayoutManager) layoutManager).findFirstVisibleItemPositions(into); + firstVisiblePosition = Integer.MAX_VALUE; + for (int pos : into) { + firstVisiblePosition = Math.min(pos, firstVisiblePosition); + } + } + return firstVisiblePosition; + } + + /** + * 由于该函数的特殊性,有则获取无则生成。 + * 对于生成,有Pinned.YES标记的Id,会先加后缀(".PINNED"+position),再存放到mIdCache中; + * 对于获取,用mPinnedPositionCellId缓存的Lua定义的真实的Id。 + * + * @param position + * @param section + * @param row + * @return + */ + @Override + protected String getId(int position, int section, int row) { + final String cacheId = mIdCache != null ? mIdCache.get(position) : null; + if (cacheId != null) { + if (this.mIsPinnedSparseArray.get(position)) { + // 获取CellId的时候,要用lua定义的真正的Id + return mPinnedPositionCellId.get(position); + } + return cacheId; + } else { + String id = null; + Varargs args = LuaUtil.invokeFunction(mCellDelegate.get("Id"), LuaUtil.toLuaInt(section), LuaUtil.toLuaInt(row)); + if (args != null) { + if (args.narg() > 1) { + if (args.arg(2).toint() == UDPinned.PINNED_YES) { + mHasPinnedCell = true; + mIsPinnedSparseArray.put(position, true); + id = args.arg(1).optjstring(""); + /** + * 构造唯一的id,使得在lua用同一种Cell作为多个position的PinnedCell时,也会有不同的viewType. + * 见 {@link UDBaseRecyclerView#getItemViewType(int)} + */ + mPinnedPositionCellId.put(position, id); + id = new StringBuffer(id).append(".PINNED").append(position).toString(); + } else { + id = args.arg(1).optjstring(""); + } + } else { // 兼容旧版本的写法,只有一个String参数的情况 + id = ((LuaValue) args).optjstring(""); + } + } + + if (mIdCache != null) { + mIdCache.put(position, id); + } + + return id; + } + } + + /** + * 根据位置获取item的viewType + * + * @param position + * @return + */ + @Override + public int getItemViewType(int position) { + int viewType = 0; + String viewTypeName = mIdCache.get(position);//得到坑位类型名称 + if (viewTypeName == null) { + // 已经有该position的viewTypeName则直接用,没有则调用getId函数生成并存入mIdCache,并返回。 + viewTypeName = getId(position); + } + if (this.mViewTypeMap != null) { + if (!this.mViewTypeMap.containsKey(viewTypeName)) { + final int index = this.mViewTypeMap.size(); + this.mViewTypeMap.put(viewTypeName, index); + this.mViewTypeNameMap.put(index, viewTypeName); + viewType = index; + } else { + viewType = this.mViewTypeMap.get(viewTypeName); + } + } + + if (this.mIsPinnedSparseArray.get(position)) { + this.mPinnedViewTypePosition.put(viewType, position); + } + + return viewType; + } + + /** + * TODO 支持offset + * + * @param offset + * @param animate 是否动画 + * @return + */ + @Override + public UDBaseListOrRecyclerView scrollToTop(int offset, boolean animate) { + final LVRecyclerView lv = getLVRecyclerView(); + if (lv != null) { + if (animate) { + if (lv.getFirstVisiblePosition() > 7) {//hack fast scroll + lv.scrollToPosition(7); + } + lv.smoothScrollToPosition(0); + } else { + if (lv.getLayoutManager() instanceof LinearLayoutManager) { + ((LinearLayoutManager) lv.getLayoutManager()).scrollToPositionWithOffset(0, offset); + } else if (lv.getLayoutManager() instanceof StaggeredGridLayoutManager) { + ((StaggeredGridLayoutManager) lv.getLayoutManager()).scrollToPositionWithOffset(0, offset); + } else { + lv.scrollToPosition(0); + } + } + } + return this; + } + + /** + * TODO 支持offset + * + * @param section + * @param rowInSection + * @param offset + * @param animate + * @return + */ + @Override + public UDBaseListOrRecyclerView scrollToItem(int section, int rowInSection, int offset, boolean animate) { + final LVRecyclerView recyclerView = getLVRecyclerView(); + if (recyclerView != null) { + if (animate) { + recyclerView.smoothScrollToPosition(getPositionBySectionAndRow(section, rowInSection)); + } else { + if (recyclerView.getLayoutManager() instanceof LinearLayoutManager) { + ((LinearLayoutManager) recyclerView.getLayoutManager()).scrollToPositionWithOffset(getPositionBySectionAndRow(section, rowInSection), offset); + } else if (recyclerView.getLayoutManager() instanceof StaggeredGridLayoutManager) { + ((StaggeredGridLayoutManager) recyclerView.getLayoutManager()).scrollToPositionWithOffset(getPositionBySectionAndRow(section, rowInSection), offset); + } else { + recyclerView.scrollToPosition(getPositionBySectionAndRow(section, rowInSection)); + } + } + } + return this; + } + + @Override + public UDBaseListOrRecyclerView setMiniSpacing(int spacing) { + final LVRecyclerView view = getLVRecyclerView(); + if (view != null) { + view.setMiniSpacing(spacing); + } + return this; + } + + @Override + public int getMiniSpacing() { + return getView() instanceof LVRecyclerView ? ((LVRecyclerView) getView()).getMiniSpacing() : 0; + } + + + /** + * 获取最大的spanCount,默认为1 + * 1. 先读取所有cell的size,找到最小cell,能放多少个该cell即为最大列数 + * 2. 初始化每个item的spanSize + * TODO 使用另外的算法:先找到最小的gap,然后算出spancount的方式。找最小gap的方式需要遍历一遍,找到每行的最小空隙,如果最小空隙为0则找最小的cell为最小的gap。(该方式的问题是填不满的行会有间隙) + * + * @return + */ + public int getMaxSpanCount() { + if (getWidth() > 0) { + final int maxWidth = getWidth(); + final int maxSpanCount = Math.max(1, maxWidth); + initSpanSize(maxSpanCount); + return maxSpanCount; + } + return DEFAULT_MAX_SPAN; + } + + /** + * 初始化spanCount,并保存 + * + * @param maxSpanCount + */ + private void initSpanSize(int maxSpanCount) { + mSpanSize = new SparseIntArray(); + final int totalCount = getTotalCount(); + for (int i = 0; i < totalCount; i++) { + final int[] size = callCellSize(LuaValue.NIL, i); + final int spanSize = Math.max(0, Math.min(maxSpanCount, size[0]));//0 <= spanSize <= maxSpanCount + mSpanSize.put(i, spanSize); + } + } + + /** + * get cached span size + * + * @param position + * @return + */ + public int getSpanSize(int position) { + if (mSpanSize != null) { + return mSpanSize.get(position); + } + return DEFAULT_MAX_SPAN; + } + + + //------------------------------------has cell size--------------------------------------------- + + /** + * 是否有size的定义 + * + * @param viewType + * @return + */ + public boolean hasCellSize(int viewType) { + final String id = getItemViewTypeName(viewType); + if (id != null) { + if (mHasPinnedCell && this.mPinnedViewTypePosition.get(viewType, -1) != -1) { + // 获取CellId的时候,要用Lua层定义的正确的Id + return hasCellFunction(mPinnedPositionCellId.get(mPinnedViewTypePosition.get(viewType)), "Size"); + } + + return hasCellFunction(id, "Size"); + } + return false; + } +} \ No newline at end of file diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/userdata/list/UDListView.java b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/list/UDListView.java new file mode 100644 index 00000000..52589f27 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/list/UDListView.java @@ -0,0 +1,35 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.userdata.list; + +import android.widget.ListView; + +import com.taobao.luaview.view.LVListView; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; + +/** + * 容器类-ListView,模拟OC的section分区实现,Section顺序排列 + * + * @author song + * @date 15/8/20 + */ +public class UDListView extends UDBaseListView { + + public UDListView(LVListView view, Globals globals, LuaValue metaTable, Varargs initParams) { + super(view, globals, metaTable, initParams); + } + + @Override + public ListView getListView() { + return getView(); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/userdata/list/UDRecyclerView.java b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/list/UDRecyclerView.java new file mode 100644 index 00000000..77594506 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/list/UDRecyclerView.java @@ -0,0 +1,33 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.userdata.list; + +import com.taobao.luaview.view.LVRecyclerView; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; + +/** + * 容器类-RecyclerView + * + * @author song + * @date 15/8/20 + */ +public class UDRecyclerView extends UDBaseRecyclerView { + + public UDRecyclerView(T view, Globals globals, LuaValue metaTable, Varargs initParams) { + super(view, globals, metaTable, initParams); + } + + @Override + public LVRecyclerView getLVRecyclerView() { + return getView(); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/userdata/list/UDRefreshListView.java b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/list/UDRefreshListView.java new file mode 100644 index 00000000..1c371150 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/list/UDRefreshListView.java @@ -0,0 +1,132 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.userdata.list; + +import android.support.v4.widget.SwipeRefreshLayout; +import android.widget.ListView; + +import com.taobao.luaview.userdata.refreshable.OnLVRefreshListener; +import com.taobao.luaview.util.LuaUtil; +import com.taobao.luaview.view.LVRefreshListView; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; + +/** + * 容器类-ListView,模拟OC的section分区实现,Section顺序排列 + * + * @author song + * @date 15/8/20 + */ +public class UDRefreshListView extends UDBaseListView implements OnLVRefreshListener { + + public UDRefreshListView(LVRefreshListView view, Globals globals, LuaValue metaTable, Varargs initParams) { + super(view, globals, metaTable, initParams); + } + + @Override + public ListView getListView() { + return getView() != null ? getView().getListView() : null; + } + + //------------------------------------------Refresh--------------------------------------------- + + /** + * 初始化下拉刷新 + */ + public void initPullRefresh() { + final LVRefreshListView view = getView(); + if (view != null && LuaUtil.isValid(mCallback)) { + view.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { + @Override + public void onRefresh() { + UDRefreshListView.this.onRefresh(null); + } + }); + } + } + + /** + * 设置是否可以刷新 + * + * @param enable + */ + public UDRefreshListView setRefreshEnable(boolean enable) { + final LVRefreshListView view = getView(); + if (view != null) { + view.setEnabled(enable); + + if (!enable) { + view.setOnRefreshListener(null); + } + } + return this; + } + + @Override + public void onRefresh(final Object param) { + final LVRefreshListView view = getView(); + if (view != null && LuaUtil.isValid(mCallback)) { + //这里必须放在handler中执行,否则会造成nullpointerexception(dispatchDraw的时候调用removeView出错) http://dashasalo.com/2013/09/16/android-removeview-crashes-animation-listener/ + view.post(new Runnable() {//下一帧回调,否则会造成view onDraw乱序。否则在同一帧调用的时候再调用addView, removeView会有bug + @Override + public void run() { + if (LuaUtil.isValid(mCallback)) { + LuaUtil.callFunction(LuaUtil.getFunction(mCallback, "PullDown", "pullDown")); + } + + if (param instanceof OnLVRefreshListener) { + ((OnLVRefreshListener) param).onRefresh(null); + } + } + }); + } else { + if (param instanceof OnLVRefreshListener) { + ((OnLVRefreshListener) param).onRefresh(null); + } + } + } + + + /** + * 是否在刷新 + * + * @return + */ + public boolean isRefreshing() { + return getView() != null && getView().isRefreshing(); + } + + /** + * 开始刷新 + * + * @return + */ + public UDRefreshListView startPullDownRefreshing() { + final LVRefreshListView lv = getView(); + if (lv != null) { + lv.startPullDownRefreshing(); + } + return this; + } + + /** + * 停止刷新 + * + * @return + */ + public UDRefreshListView stopPullDownRefreshing() { + final LVRefreshListView lv = getView(); + if (lv != null) { + lv.stopPullDownRefreshing(); + } + return this; + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/userdata/list/UDRefreshRecyclerView.java b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/list/UDRefreshRecyclerView.java new file mode 100644 index 00000000..8ced93be --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/list/UDRefreshRecyclerView.java @@ -0,0 +1,145 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.userdata.list; + +import android.support.v4.widget.SwipeRefreshLayout; + +import com.taobao.luaview.userdata.refreshable.OnLVRefreshListener; +import com.taobao.luaview.util.LuaUtil; +import com.taobao.luaview.view.LVRecyclerView; +import com.taobao.luaview.view.LVRefreshRecyclerView; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; + +/** + * 容器类-RecyclerView,模拟OC的section分区实现,Section顺序排列 + * + * @author song + * @date 15/8/20 + */ +public class UDRefreshRecyclerView extends UDBaseRecyclerView implements OnLVRefreshListener { + + private boolean mIsPullDownInit; + + public UDRefreshRecyclerView(LVRefreshRecyclerView view, Globals globals, LuaValue metaTable, Varargs initParams) { + super(view, globals, metaTable, initParams); + } + + @Override + public LVRecyclerView getLVRecyclerView() { + return getView() != null ? getView().getRecyclerView() : null; + } + + //------------------------------------------Refresh--------------------------------------------- + + /** + * 初始化下拉刷新 + */ + public void initPullRefresh() { + if (mIsPullDownInit) { + return; + } + + final LVRefreshRecyclerView view = getView(); + if (view != null && LuaUtil.isValid(mCallback)) { + view.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { + @Override + public void onRefresh() { + UDRefreshRecyclerView.this.onRefresh(null); + } + }); + mIsPullDownInit = true; + } + } + + @Override + public UDBaseRecyclerView reload(Integer section, Integer row) { + UDBaseRecyclerView view = super.reload(section, row); + initPullRefresh(); + return view; + } + + /** + * 设置是否可以刷新 + * + * @param enable + */ + public UDRefreshRecyclerView setRefreshEnable(boolean enable) { + final LVRefreshRecyclerView view = getView(); + if (view != null) { + view.setEnabled(enable); + + if (!enable) { + view.setOnRefreshListener(null); + } + } + return this; + } + + @Override + public void onRefresh(final Object param) { + final LVRefreshRecyclerView view = getView(); + if (view != null && LuaUtil.isValid(mCallback)) { + //这里必须放在handler中执行,否则会造成nullpointerexception(dispatchDraw的时候调用removeView出错) http://dashasalo.com/2013/09/16/android-removeview-crashes-animation-listener/ + view.post(new Runnable() {//下一帧回调,否则会造成view onDraw乱序。否则在同一帧调用的时候再调用addView, removeView会有bug + @Override + public void run() { + if (LuaUtil.isValid(mCallback)) { + LuaUtil.callFunction(LuaUtil.getFunction(mCallback, "PullDown", "pullDown")); + } + if (param instanceof OnLVRefreshListener) { + ((OnLVRefreshListener) param).onRefresh(null); + } + } + }); + } else { + if (param instanceof OnLVRefreshListener) { + ((OnLVRefreshListener) param).onRefresh(null); + } + } + } + + + /** + * 是否在刷新 + * + * @return + */ + public boolean isRefreshing() { + return getView() != null && getView().isRefreshing(); + } + + /** + * 开始刷新 + * + * @return + */ + public UDRefreshRecyclerView startPullDownRefreshing() { + final LVRefreshRecyclerView lv = getView(); + if (lv != null) { + lv.startPullDownRefreshing(); + } + return this; + } + + /** + * 停止刷新 + * + * @return + */ + public UDRefreshRecyclerView stopPullDownRefreshing() { + final LVRefreshRecyclerView lv = getView(); + if (lv != null) { + lv.stopPullDownRefreshing(); + } + return this; + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/userdata/net/CookieManager.java b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/net/CookieManager.java new file mode 100644 index 00000000..2b4e65f9 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/net/CookieManager.java @@ -0,0 +1,190 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.userdata.net; + +import android.os.Build; +import android.text.TextUtils; +import android.webkit.CookieSyncManager; + +import com.taobao.luaview.util.LogUtil; + +import java.net.CookieHandler; +import java.net.CookiePolicy; +import java.net.CookieStore; +import java.net.HttpCookie; +import java.net.HttpURLConnection; +import java.util.List; +import java.util.Map; + +/** + * 处理Http Cookies + * + * @author song + * @date 16/7/27 + * 主要功能描述 + * 修改描述 + * 下午5:20 song XXX + */ +public class CookieManager { + private static final String TAG = "CookieManager"; + public static final String COOKIE = "Cookie"; + public static final String COOKIES_HEADER = "Set-Cookie"; + + //cookies manager + private static java.net.CookieManager mCookieManager; + + private static java.net.CookieManager getCookieManager() { + if (mCookieManager == null) { + mCookieManager = new java.net.CookieManager(null, CookiePolicy.ACCEPT_ALL); + CookieHandler.setDefault(mCookieManager); + } + return mCookieManager; + } + + /** + * clear net cookies + */ + public static void clearNetCookies() { + java.net.CookieManager cookieManager = getCookieManager(); + CookieStore cookieStore = cookieManager.getCookieStore(); + if (cookieStore != null) { + cookieStore.removeAll(); + } + } + + /** + * 处理请求的cookie + * + * @param connection + */ + public static void handleRequestCookies(HttpURLConnection connection, String requestUrl) { + if (connection != null) { + final StringBuffer cookie = new StringBuffer(); + final String webkitCookie = getWebkitRequestCookies(requestUrl); + if (webkitCookie != null) { + cookie.append(webkitCookie); + } + if (cookie.length() > 0) { + final String cookieStr = cookie.toString(); + connection.setRequestProperty(COOKIE, cookieStr); + } + } + } + + /** + * web kit cookies + * + * @param requestUrl + */ + private static String getWebkitRequestCookies(String requestUrl) { + android.webkit.CookieManager cookieManager = android.webkit.CookieManager.getInstance(); + if (cookieManager != null) { + syncWebkitCookies(cookieManager); + final String webkitCookie = cookieManager.getCookie(requestUrl); + LogUtil.d(TAG, "get-webkit", webkitCookie); + return webkitCookie; + } + return null; + } + + /** + * synchronous cookies for webkit + * + * @param cookieManager + */ + private static void syncWebkitCookies(android.webkit.CookieManager cookieManager) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {//同步cookie synchronous + CookieSyncManager.getInstance().sync(); + } else { + cookieManager.flush(); + } + } + + /** + * net cookies + */ + private static String getNetRequestCookies() { + final CookieStore cookieStore = getCookieManager().getCookieStore(); + //net cookie + if (cookieStore != null) { + final List cookies = cookieStore.getCookies(); + if (cookies != null && cookies.size() > 0) { + //While joining the Cookies, use ',' or ';' as needed. Most of the server are using ';' + final String netCookie = TextUtils.join(";", cookies); + LogUtil.d(TAG, "get-net", netCookie); + return netCookie; + } + } + return null; + } + + + /** + * cookies from response + * TODO 将cookie信息同步到webview cookie里 + * + * @param connection + */ + public static void handleResponseCookies(HttpURLConnection connection, String url) { + if (connection != null) { + final Map> headerFields = connection.getHeaderFields(); + if (headerFields != null && headerFields.containsKey(COOKIES_HEADER)) { + final List cookiesHeader = headerFields.get(COOKIES_HEADER); + //write webkit cookie +// updateWebkitResponseCookies(cookiesHeader, url); + } + } + } + + /** + * @param cookiesHeader + */ + private static String updateWebkitResponseCookies(List cookiesHeader, String requestUrl) { + //write webkit cookie + final CookieStore cookieStore = getCookieManager().getCookieStore(); + if (cookieStore != null && cookiesHeader != null) { + + StringBuffer cookie = new StringBuffer(); + for (String cookieHeader : cookiesHeader) { + cookie.append(cookieHeader).append(";"); + } + android.webkit.CookieManager cookieManager = android.webkit.CookieManager.getInstance(); + if (cookieManager != null && cookie.length() > 0) { + String cookieStr = cookie.toString(); + LogUtil.d(TAG, "write-webkit", cookieStr); + cookieManager.setCookie(requestUrl, cookieStr); + } + } + return null; + } + + /** + * write net cookies + * + * @param cookiesHeader + */ + private static void updateNetResponseCookies(List cookiesHeader) { + //write net cookie + final CookieStore cookieStore = getCookieManager().getCookieStore(); + if (cookieStore != null && cookiesHeader != null) { + HttpCookie cookieStr = null; + for (String cookieHeader : cookiesHeader) { + if (cookieHeader != null) { + List cookies = HttpCookie.parse(cookieHeader); + if (cookies != null && cookies.size() > 0) { + cookieStr = cookies.get(0); + LogUtil.d(TAG, "write-net", cookieStr); + cookieStore.add(null, cookieStr); + } + } + } + } + } + +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/userdata/net/UDHttp.java b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/net/UDHttp.java new file mode 100644 index 00000000..fa4cd43b --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/net/UDHttp.java @@ -0,0 +1,416 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.userdata.net; + +import android.os.Build; +import android.support.annotation.NonNull; +import android.text.TextUtils; +import android.webkit.CookieSyncManager; + +import com.taobao.luaview.userdata.base.BaseUserdata; +import com.taobao.luaview.util.IOUtil; +import com.taobao.luaview.util.LogUtil; +import com.taobao.luaview.util.LuaUtil; +import com.taobao.luaview.util.LuaViewUtil; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaFunction; +import org.luaj.vm2.LuaTable; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; + +/** + * Http 用户数据封装 + * + * @author song + * @date 15/9/6 + */ +public class UDHttp extends BaseUserdata { + private LuaFunction mCallback; + + public static final String METHOD_GET = "GET"; + public static final String METHOD_POST = "POST"; + public static final int DEFAULT_RETRY_TIMES = 3; + public static final int DEFAULT_TIMEOUT = 30; + + private String mMethod = METHOD_POST; + private String mUrl; + private LuaTable mParams; + private int mRetryTimes = DEFAULT_RETRY_TIMES; + private int mTimeout = DEFAULT_TIMEOUT; + + //令牌 + private Future mFuture; + + private static ExecutorService mExecutor; + + private static synchronized ExecutorService getExecutor() { + if (mExecutor == null) { + mExecutor = Executors.newFixedThreadPool(5); + } + return mExecutor; + } + + + public UDHttp(Globals globals, LuaValue metatable, Varargs varargs) { + super(globals, metatable, varargs); + init(); + } + + /** + * 初始化mtop调用 + */ + private void init() { + initVarargs(); + } + + /** + * 初始化数据 + */ + private void initVarargs() { + final LuaValue param1 = getInitParam1(); + final LuaFunction callback = LuaUtil.getFunction(initParams, 2); + final String method = LuaUtil.getString(param1, "method"); + final LuaTable params = LuaUtil.getTable(param1, "params"); + setMethod(method); + setParams(params); + setCallback(callback); + disableConnectionReuseIfNecessary(); + } + + /** + * 请求 url + * + * @param url + * @return + */ + public UDHttp setUrl(String url) { + this.mUrl = url; + return this; + } + + public String getUrl() { + return this.mUrl; + } + + /** + * 请求方法 post/get/put/delete等 + * + * @param mMethod + * @return + */ + public UDHttp setMethod(String mMethod) { + this.mMethod = mMethod; + return this; + } + + public String getMethod() { + return this.mMethod; + } + + /** + * 请求参数,使用table构建 + * + * @param mParams + * @return + */ + public UDHttp setParams(LuaTable mParams) { + this.mParams = mParams; + return this; + } + + public LuaValue getParams() { + return this.mParams != null ? this.mParams : NIL; + } + + /** + * 重试次数 + * + * @param retryTimes + * @return + */ + public UDHttp setRetryTimes(int retryTimes) { + this.mRetryTimes = retryTimes; + return this; + } + + public int getRetryTimes() { + return this.mRetryTimes; + } + + /** + * 请求超时时长 + * + * @param timeOut + * @return + */ + public UDHttp setTimeout(int timeOut) { + this.mTimeout = timeOut; + return this; + } + + public int getTimeout() { + return this.mTimeout; + } + + /** + * 清空net cookies + */ + public UDHttp clearNetCookies() { + CookieManager.clearNetCookies(); + return this; + } + + /** + * 回调 + * + * @param luaFunction + */ + public UDHttp setCallback(final LuaFunction luaFunction) { + this.mCallback = luaFunction; + return this; + } + + public LuaFunction getCallback() { + return this.mCallback; + } + + /** + * 发送get请求 + * + * @return + */ + public UDHttp get(String url, LuaTable params, LuaFunction callback) { + setMethod(METHOD_GET); + if (url != null) { + setUrl(url); + } + if (params != null) { + setParams(params); + } + if (callback != null) { + setCallback(callback); + } + return request(); + } + + public UDHttp post(String url, LuaTable params, LuaFunction callback) { + setMethod(METHOD_POST); + if (url != null) { + setUrl(url); + } + if (params != null) { + setParams(params); + } + if (callback != null) { + setCallback(callback); + } + return request(); + } + + /** + * 请求mtop + */ + public synchronized UDHttp request() { + if (mFuture == null) { + mFuture = getExecutor().submit(buildRunnable()); + } + return this; + } + + public synchronized UDHttp cancel() { + if (mFuture != null && !mFuture.isCancelled()) { + mFuture.cancel(true); + mFuture = null; + } + return this; + } + + /** + * 调用回调,注意:需要在主线程执行该操作 + * + * @param result + */ + private void callCallback(final LuaValue result) { + LuaViewUtil.runOnUiThread(getContext(), new Runnable() { + @Override + public void run() { + LuaUtil.callFunction(mCallback, result); + } + }); + } + + /** + * build a runnable to execute http request + * TODO retry times重试次数设置。 + * + * @return + */ + private Runnable buildRunnable() { + return new Runnable() { + @Override + public void run() { + InputStream input = null; + OutputStream output = null; + HttpURLConnection connection = null; + + final UDHttpResponse udHttpResponse = new UDHttpResponse(getGlobals(), getmetatable(), null); + try { + final URL url = new URL(mUrl); + connection = (HttpURLConnection) url.openConnection(); + connection.setInstanceFollowRedirects(true);//支持301重定向 + HttpURLConnection.setFollowRedirects(true);//支持重定向 + + //method + connection.setRequestMethod(mMethod); + //timeout + connection.setConnectTimeout(mTimeout * 1000); + + CookieSyncManager.createInstance(getContext()); + //请求的cookie + CookieManager.handleRequestCookies(connection, mUrl); + + if (mParams != null) { + for (LuaValue key : mParams.keys()) { + final LuaValue value = mParams.get(key); + final String requestKey = key != null ? key.optjstring(null) : null; + final String requestValue = value != null ? value.optjstring(null) : null; + if (!TextUtils.isEmpty(requestKey) && !TextUtils.isEmpty(requestValue)) { + connection.setRequestProperty(requestKey, requestValue); + } + } + } + + //连接服务器 + connection.connect(); + + //301重定向&重定向cookie + connection = handle301Redirect(connection); + + //code + udHttpResponse.setStatusCode(connection.getResponseCode()); + + if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) { + LogUtil.e("[Server Returned HTTP] ", connection.getResponseCode(), connection.getResponseMessage()); + + //msg + udHttpResponse.setResponseMsg(connection.getResponseMessage()); + return; + } + + input = connection.getInputStream(); + + final byte[] fileData = IOUtil.toBytes(input, getContentCharset(connection)); + + //data + udHttpResponse.setData(fileData); + + //header + udHttpResponse.setHeaders(connection.getHeaderFields()); + + //response cookie +// CookieManager.handleResponseCookies(connection, mUrl); + } catch (Exception e) { + LogUtil.e("[Http error] ", e); + e.printStackTrace(); + udHttpResponse.setResponseMsg(e.toString()); + } finally { + try { + if (output != null) { + output.flush(); + output.close(); + } + if (input != null) { + input.close(); + } + } catch (IOException ignored) { + ignored.printStackTrace(); + } + if (connection != null) { + connection.disconnect(); + } + + //调用回调 + callCallback(udHttpResponse); + } + } + }; + } + + @NonNull + private HttpURLConnection handle301Redirect(HttpURLConnection connection) throws IOException { + if (connection != null) { + boolean redirect = false; + + // normally, 3xx is redirect + int status = connection.getResponseCode(); + if (status != HttpURLConnection.HTTP_OK) { + if (status == HttpURLConnection.HTTP_MOVED_TEMP + || status == HttpURLConnection.HTTP_MOVED_PERM + || status == HttpURLConnection.HTTP_SEE_OTHER) + redirect = true; + } + + if (redirect) { + // get redirect url from "location" header field + String newUrl = connection.getHeaderField("Location"); + + // get the cookie if need, for login + String cookies = connection.getHeaderField(com.taobao.luaview.userdata.net.CookieManager.COOKIES_HEADER); + + // open the new connnection again + connection = (HttpURLConnection) new URL(newUrl).openConnection(); + connection.setRequestProperty(com.taobao.luaview.userdata.net.CookieManager.COOKIE, cookies); + + //连接服务器 + connection.connect(); + + //重复301重定向 + connection = handle301Redirect(connection); + } + } + return connection; + } + + private String getContentCharset(HttpURLConnection connection) { + if (connection != null) { + final String contentType = connection.getContentType(); + if (contentType != null) { + final String[] values = contentType.split(";"); // values.length should be 2 + String charset = null; + if (values != null) { + for (String value : values) { + value = value.trim(); + if (value != null && value.toLowerCase().startsWith("charset=")) { + charset = value.substring("charset=".length()); + } + } + } + return charset; + } + } + return null; + } + + private void disableConnectionReuseIfNecessary() { + // Work around pre-Froyo bugs in HTTP connection reuse. + if (Integer.parseInt(Build.VERSION.SDK) < Build.VERSION_CODES.FROYO) { + System.setProperty("http.keepAlive", "false"); + } + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/userdata/net/UDHttpResponse.java b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/net/UDHttpResponse.java new file mode 100644 index 00000000..8ffd193c --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/net/UDHttpResponse.java @@ -0,0 +1,143 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.userdata.net; + +import com.taobao.luaview.userdata.base.BaseLuaTable; +import com.taobao.luaview.userdata.kit.UDData; +import com.taobao.luaview.util.LuaUtil; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaTable; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; +import org.luaj.vm2.lib.VarArgFunction; + +import java.util.List; +import java.util.Map; + +/** + * Http 返回数据 + * @author song + */ +public class UDHttpResponse extends BaseLuaTable { + private byte[] mData; + private int mStatusCode = -1; + private String mResponseMsg; + private Map> mHeaders; + + public UDHttpResponse(Globals globals, LuaValue metatable, Varargs varargs) { + super(globals, metatable, varargs); + init(); + } + + private void init() { + set("data", new data()); + set("code", new code()); + set("header", new header()); + set("message", new message());//TODO iOS无 + } + + public UDHttpResponse setData(byte[] mData) { + this.mData = mData; + return this; + } + + public LuaValue getData() { + return mData != null ? new UDData(getGlobals(), getmetatable(), null).append(mData) : LuaValue.NIL; + } + + public UDHttpResponse setResponseMsg(String message) { + this.mResponseMsg = message; + return this; + } + + public String getResponseMsg() { + return mResponseMsg; + } + + public UDHttpResponse setStatusCode(int statusCode) { + this.mStatusCode = statusCode; + return this; + } + + public int getStatusCode() { + return mStatusCode; + } + + public UDHttpResponse setHeaders(Map> headers) { + this.mHeaders = headers; + return this; + } + + public LuaValue getHeaders(String name) { + if (mHeaders != null) { + if (name != null) {//获取某一个header + return LuaUtil.toTable(mHeaders.get(name)); + } else {//获取所有的header + return LuaUtil.toTable(mHeaders); + } + } + return NIL; + } + + /** + * convert response to LuaTable + * + * @return + */ + public LuaTable toTable() { + LuaTable result = new LuaTable(); + result.set("data", new UDData(getGlobals(), getmetatable(), null).append(mData)); + result.set("code", LuaValue.valueOf(mStatusCode)); + result.set("header", LuaUtil.toTable(mHeaders)); + result.set("message", LuaValue.valueOf(mResponseMsg)); + return result; + } + + //-----------------------------------------functions-------------------------------------------- + + /** + * 获取数据 + */ + class data extends VarArgFunction { + @Override + public Varargs invoke(Varargs args) { + return getData(); + } + } + + /** + * 错误码 + */ + class code extends VarArgFunction { + @Override + public Varargs invoke(Varargs args) { + return valueOf(mStatusCode); + } + } + + /** + * 请求头 + */ + class header extends VarArgFunction { + @Override + public Varargs invoke(Varargs args) { + return getHeaders(args.narg() > 1 ? args.optjstring(2, null) : null); + } + } + + /** + * 错误信息 + */ + class message extends VarArgFunction { + public Varargs invoke(Varargs args) { + return valueOf(mResponseMsg); + } + } +} \ No newline at end of file diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/userdata/refreshable/OnLVRefreshListener.java b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/refreshable/OnLVRefreshListener.java new file mode 100644 index 00000000..d417082e --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/refreshable/OnLVRefreshListener.java @@ -0,0 +1,27 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.userdata.refreshable; + +/** + * 刷新回调 + * + * @author song + * @date 16/7/20 + * 主要功能描述 + * 修改描述 + * 下午6:05 song XXX + */ +public interface OnLVRefreshListener { + + /** + * 刷新接口,可以接收一个参数 + * @param param + */ + void onRefresh(Object param); +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/userdata/ui/UDAlert.java b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/ui/UDAlert.java new file mode 100644 index 00000000..e476b3d4 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/ui/UDAlert.java @@ -0,0 +1,113 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.userdata.ui; + +import android.content.DialogInterface; + +import com.taobao.luaview.userdata.base.BaseUserdata; +import com.taobao.luaview.util.AlertUtil; +import com.taobao.luaview.util.LuaUtil; +import com.taobao.luaview.util.LuaViewUtil; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaFunction; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; + +import java.util.ArrayList; +import java.util.List; + +/** + * Alert 数据封装 + * @author song + */ +public class UDAlert extends BaseUserdata { + //dialog属性 + private CharSequence mTitle; + private CharSequence mContent; + private List mButtonTexts; + private List mButtonCallbacks; + + public UDAlert(Globals globals, LuaValue metaTable, Varargs varargs) { + super(globals, metaTable, varargs); + init(); + } + + /** + * 初始化数据 + */ + private void init() { + mTitle = LuaViewUtil.getText(getInitParam1()); + mContent = LuaViewUtil.getText(getInitParam2()); + mButtonTexts = new ArrayList(); + mButtonCallbacks = new ArrayList(); + for (int i = 3; i <= getInitParamsCount(); i++) { + if (this.initParams.isfunction(i)) { + mButtonCallbacks.add(this.initParams.optfunction(i, null)); + } else { + mButtonTexts.add(LuaViewUtil.getText(this.initParams.optvalue(i, NIL))); + } + } + showDialog(); + } + + /** + * 创建dialog + */ + private void showDialog() { + int buttonCount = Math.max(mButtonTexts.size(), mButtonCallbacks.size()); + switch (buttonCount) { + case 0: + case 1: + showOneButtonDialog(); + break; + case 2: + showTwoButtonDialog(); + break; + } + } + + /** + * 创建一个按钮的对话框 + */ + private void showOneButtonDialog() { + final CharSequence ok = mButtonTexts.size() > 0 ? mButtonTexts.get(0) : null; + AlertUtil.showAlert(getContext(), mTitle, mContent, ok, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + if (mButtonCallbacks.size() > 0) { + LuaUtil.callFunction(mButtonCallbacks.get(0)); + } + } + }); + } + + /** + * 创建两个按钮的对话框 + */ + private void showTwoButtonDialog() { + final CharSequence ok = mButtonTexts.size() > 0 ? mButtonTexts.get(0) : null; + final CharSequence cancel = mButtonTexts.size() > 1 ? mButtonTexts.get(1) : null; + AlertUtil.showAlert(getContext(), mTitle, mContent, ok, cancel, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + if (mButtonCallbacks.size() > 0) { + LuaUtil.callFunction(mButtonCallbacks.get(0)); + } + } + }, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + if (mButtonCallbacks.size() > 1) { + LuaUtil.callFunction(mButtonCallbacks.get(1)); + } + } + }); + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/userdata/ui/UDAnimation.java b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/ui/UDAnimation.java new file mode 100644 index 00000000..b0c2d824 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/ui/UDAnimation.java @@ -0,0 +1,190 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.userdata.ui; + +import android.view.View; +import android.view.animation.AlphaAnimation; +import android.view.animation.Animation; +import android.view.animation.RotateAnimation; +import android.view.animation.ScaleAnimation; +import android.view.animation.TranslateAnimation; + +import com.taobao.luaview.userdata.base.BaseUserdata; +import com.taobao.luaview.util.DimenUtil; +import com.taobao.luaview.util.LuaUtil; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaFunction; +import org.luaj.vm2.LuaTable; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; + + +/** + * AlphaAnimation, RotateAnimation, ScaleAnimation, TranslateAnimation + * 废弃,使用Animator来处理 + * @author song + */ +@Deprecated +public class UDAnimation extends BaseUserdata { + private static final int TYPE_ALPHA = 1; + private static final int TYPE_ROTATE = 2; + private static final int TYPE_SCALE = 3; + private static final int TYPE_TRANSLATE = 4; + + private LuaValue mOnStartCallback; + private LuaValue mOnEndCallback; + private LuaValue mOnRepeatCallback; + + private int mAnimationType; + private float[] mValues; + private long mDuration = 300; + private long mStartOffset = 0; + private int mRepeatCount = 0; + + public UDAnimation(Globals globals, LuaValue metaTable, Varargs varargs) { + super(globals, metaTable, varargs); + } + + public UDAnimation setAnimationType(int type) { + mAnimationType = type; + return this; + } + + public UDAnimation alpha(float... values) { + this.mAnimationType = TYPE_ALPHA; + this.mValues = values; + return this; + } + + public UDAnimation rotate(float... values) { + this.mAnimationType = TYPE_ROTATE; + this.mValues = values; + return this; + } + + public UDAnimation scale(float... values) { + this.mAnimationType = TYPE_SCALE; + this.mValues = values; + return this; + } + + public UDAnimation translate(float... values) { + this.mAnimationType = TYPE_TRANSLATE; + this.mValues = values; + return this; + } + + public UDAnimation setValue(float... values) { + this.mValues = values; + return this; + } + + public UDAnimation setDuration(long duration) { + this.mDuration = duration; + return this; + } + + public UDAnimation setStartDelay(long mStartDelay) { + this.mStartOffset = mStartDelay; + return this; + } + + public UDAnimation setRepeatCount(int mRepeatCount) { + this.mRepeatCount = mRepeatCount; + return this; + } + + public UDAnimation setOnRepeatCallback(LuaFunction mOnRepeatCallback) { + this.mOnRepeatCallback = mOnRepeatCallback; + return this; + } + + public UDAnimation setOnStartCallback(LuaFunction mOnStartCallback) { + this.mOnStartCallback = mOnStartCallback; + return this; + } + + public UDAnimation setOnEndCallback(LuaFunction mOnEndCallback) { + this.mOnEndCallback = mOnEndCallback; + return this; + } + + public UDAnimation setCallback(LuaTable callback) { + if (callback != null) { + this.mOnStartCallback = LuaUtil.getFunction(callback, "OnStart", "onStart"); + this.mOnEndCallback = LuaUtil.getFunction(callback, "OnEnd", "onEnd"); + this.mOnRepeatCallback = LuaUtil.getFunction(callback, "OnRepeat", "onRepeat"); + } + return this; + } + + /** + * build an animation + * + * @return + */ + public Animation build(View view) { + Animation animation = null; + if (view != null) { + switch (mAnimationType) { + case TYPE_ALPHA: + if (this.mValues != null && this.mValues.length > 0) { + animation = new AlphaAnimation(view.getAlpha(), this.mValues[0]); + } + break; + case TYPE_ROTATE: + if (this.mValues != null && this.mValues.length > 0) { + animation = new RotateAnimation(view.getRotation(), this.mValues[0]); + } + break; + case TYPE_SCALE: + if (this.mValues != null && this.mValues.length > 1) { + animation = new ScaleAnimation(view.getScaleX(), this.mValues[0], view.getScaleY(), this.mValues[1]); + } + break; + case TYPE_TRANSLATE: + if (this.mValues != null && this.mValues.length > 1) { + animation = new TranslateAnimation(view.getX(), DimenUtil.dpiToPx(this.mValues[0]), view.getY(), DimenUtil.dpiToPx(this.mValues[1])); + } + break; + } + + if (animation != null) { + animation.setFillEnabled(true); + animation.setFillAfter(true);//默认结束后设置属性 + animation.setFillBefore(true); + animation.setDuration(mDuration); + animation.setStartOffset(mStartOffset); + animation.setRepeatCount(mRepeatCount); + + if (mOnStartCallback != null || mOnRepeatCallback != null || mOnEndCallback != null) { + animation.setAnimationListener(new Animation.AnimationListener() { + @Override + public void onAnimationStart(Animation animation) { + LuaUtil.callFunction(mOnStartCallback); + } + + @Override + public void onAnimationEnd(Animation animation) { + LuaUtil.callFunction(mOnEndCallback); + } + + @Override + public void onAnimationRepeat(Animation animation) { + LuaUtil.callFunction(mOnRepeatCallback); + } + }); + } + } + } + return animation; + } + +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/userdata/ui/UDAnimator.java b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/ui/UDAnimator.java new file mode 100644 index 00000000..c5b5d0e0 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/ui/UDAnimator.java @@ -0,0 +1,466 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.userdata.ui; + +import android.animation.Animator; +import android.animation.ObjectAnimator; +import android.animation.PropertyValuesHolder; +import android.animation.ValueAnimator; +import android.os.Build; +import android.text.TextUtils; +import android.view.animation.Interpolator; + +import com.taobao.luaview.userdata.base.BaseUserdata; +import com.taobao.luaview.util.AnimatorUtil; +import com.taobao.luaview.util.LuaUtil; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaTable; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; + +import java.util.Arrays; +import java.util.List; + +/** + * Animator 数据封装 + * + * @author song + */ +public class UDAnimator extends BaseUserdata { + private LuaValue mOnStartCallback; + private LuaValue mOnEndCallback; + private LuaValue mOnCancelCallback; + private LuaValue mOnRepeatCallback; + private LuaValue mOnPauseCallback; + private LuaValue mOnResumeCallback; + private LuaValue mOnUpdateCallback; + + private Boolean isRunning; + + private UDView mTarget; + + + public UDAnimator(Globals globals, LuaValue metaTable, Varargs varargs) { + super(new ObjectAnimator(), globals, metaTable, varargs); + init(); + } + + private ObjectAnimator getAnimator() { + return (ObjectAnimator) userdata(); + } + + private void init() { + final ObjectAnimator animator = getAnimator(); + if (animator != null) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { + animator.setAutoCancel(true); + } + } + } + + /** + * 设置target + * + * @param udView + * @return + */ + public UDAnimator with(UDView udView) { + final ObjectAnimator animator = getAnimator(); + if (animator != null && udView != null && udView.getView() != null) { + mTarget = udView; + animator.setTarget(udView.getView()); + } + return this; + } + + public UDAnimator setCallback(LuaTable callbacks) { + if (callbacks != null) { + mOnStartCallback = LuaUtil.getFunction(callbacks, "onStart", "OnStart"); + mOnEndCallback = LuaUtil.getFunction(callbacks, "onEnd", "OnEnd"); + mOnCancelCallback = LuaUtil.getFunction(callbacks, "onCancel", "OnCancel"); + mOnPauseCallback = LuaUtil.getFunction(callbacks, "onPause", "OnPause"); + mOnResumeCallback = LuaUtil.getFunction(callbacks, "onResume", "OnResume"); + mOnRepeatCallback = LuaUtil.getFunction(callbacks, "onRepeat", "OnRepeat"); + mOnUpdateCallback = LuaUtil.getFunction(callbacks, "onUpdate", "OnUpdate"); + } + return this; + } + + public UDAnimator setOnStartCallback(LuaValue mOnStartCallback) { + this.mOnStartCallback = mOnStartCallback; + return this; + } + + public UDAnimator setOnEndCallback(LuaValue mOnEndCallback) { + this.mOnEndCallback = mOnEndCallback; + return this; + } + + public UDAnimator setOnCancelCallback(LuaValue mOnCancelCallback) { + this.mOnCancelCallback = mOnCancelCallback; + return this; + } + + public UDAnimator setOnRepeatCallback(LuaValue mOnRepeatCallback) { + this.mOnRepeatCallback = mOnRepeatCallback; + return this; + } + + public UDAnimator setOnPauseCallback(LuaValue mOnPauseCallback) { + this.mOnPauseCallback = mOnPauseCallback; + return this; + } + + public UDAnimator setOnResumeCallback(LuaValue mOnResumeCallback) { + this.mOnResumeCallback = mOnResumeCallback; + return this; + } + + public UDAnimator setOnUpdateCallback(LuaValue mOnUpdateCallback) { + this.mOnUpdateCallback = mOnUpdateCallback; + return this; + } + + + /** + * 设置属性 + * + * @param name + * @return + */ + public UDAnimator ofProperty(final String name, float... values) { + final ObjectAnimator animator = getAnimator(); + if (animator != null && TextUtils.isEmpty(name) == false && values != null) { + PropertyValuesHolder[] valuesHolders = null; + if (animator.getValues() != null && animator.getValues().length > 0) { + valuesHolders = Arrays.copyOf(animator.getValues(), animator.getValues().length + 1); + } else { + valuesHolders = new PropertyValuesHolder[1]; + } + valuesHolders[valuesHolders.length - 1] = PropertyValuesHolder.ofFloat(name, values); + animator.setValues(valuesHolders); + } + return this; + } + + /** + * 时长 + * + * @param duration + * @return + */ + public UDAnimator setDuration(long duration) { + final ObjectAnimator animator = getAnimator(); + if (animator != null && duration >= 0) { + animator.setDuration(duration); + } + return this; + } + + /** + * 启动延时 + * + * @param delay + * @return + */ + public UDAnimator setStartDelay(long delay) { + final ObjectAnimator animator = getAnimator(); + if (animator != null && delay >= 0) { + animator.setStartDelay(delay); + } + return this; + } + + /** + * 重复次数,负数标示无限 + * + * @param repeatCount + * @return + */ + public UDAnimator setRepeatCount(int repeatCount) { + final ObjectAnimator animator = getAnimator(); + if (animator != null) { + if (repeatCount >= 0) { + animator.setRepeatCount(repeatCount); + } else { + animator.setRepeatCount(ValueAnimator.INFINITE); + } + } + return this; + } + + /** + * 重复方式(1 default, -1 infinite, 2 reverse) + * + * @param repeatMode + * @return + */ + public UDAnimator setRepeatMode(int repeatMode) { + final ObjectAnimator animator = getAnimator(); + if (animator != null) { + animator.setRepeatMode(repeatMode); + } + return this; + } + + /** + * 浮点数 + * + * @param values + * @return + */ + public UDAnimator setFloatValues(float... values) { + final ObjectAnimator animator = getAnimator(); + if (animator != null && values != null && values.length > 0) { + animator.setFloatValues(values); + } + return this; + } + + /** + * 整数 + * + * @param values + * @return + */ + public UDAnimator setIntValues(int... values) { + final ObjectAnimator animator = getAnimator(); + if (animator != null && values != null && values.length > 0) { + animator.setIntValues(values); + } + return this; + } + + /** + * 加速器 + * AccelerateDecelerateInterpolator, + * AccelerateInterpolator, + * AnticipateInterpolator, + * AnticipateOvershootInterpolator, + * BaseInterpolator, + * BounceInterpolator, + * CycleInterpolator, + * DecelerateInterpolator, + * FastOutLinearInInterpolator, + * FastOutSlowInInterpolator, + * LinearInterpolator, + * LinearOutSlowInInterpolator, + * OvershootInterpolator, + * PathInterpolator + * + * @param interpolator + * @return + */ + public UDAnimator setInterpolator(final Interpolator interpolator) { + final ObjectAnimator animator = getAnimator(); + if (animator != null && interpolator != null) { + animator.setInterpolator(interpolator); + } + return this; + } + + /** + * start all animator + * + * @return + */ + public UDAnimator start() { + final ObjectAnimator animator = getAnimator(); + setupListeners(animator); + AnimatorUtil.start(animator); + if (mTarget != null) { + mTarget.startAnimation(); + } + return this; + } + + /** + * cancel animator + * + * @return + */ + public UDAnimator cancel() { + AnimatorUtil.cancel(getAnimator()); + if (mTarget != null) { + mTarget.cancelAnimation(); + } + return this; + } + + /** + * pause animator + * + * @return + */ + public UDAnimator pause() { + AnimatorUtil.pause(getAnimator()); + if (mTarget != null) { + mTarget.pauseAnimation(); + } + return this; + } + + /** + * resume animator + * + * @return + */ + public UDAnimator resume() { + AnimatorUtil.resume(getAnimator()); + if (mTarget != null) { + mTarget.resumeAnimation(); + } + return this; + } + + /** + * end animator + * + * @return + */ + public UDAnimator end() { + AnimatorUtil.end(getAnimator()); + if (mTarget != null) { + mTarget.endAnimation(); + } + return this; + } + + /** + * is paused + * + * @return + */ + public boolean isPaused() { + return AnimatorUtil.isPaused(getAnimator()) || (mTarget != null && mTarget.isAnimationPaused()); + } + + /** + * is running + * TODO 这里的判断有问题 + * @return + */ + public boolean isRunning() { + if (isRunning != null) { + return isRunning; + } + return AnimatorUtil.isRunning(getAnimator()) || (mTarget != null && mTarget.isAnimating()); + } + + /** + * setup listeners + * + * @param animator + * @return + */ + public UDAnimator setupListeners(ObjectAnimator animator) { + if (animator != null) { + animator.removeAllListeners();//删除所有listener, pause listener + animator.removeAllUpdateListeners();//删除所有update listener + addAnimatorListener(animator); + addOnPauseListener(animator); + addOnUpdateListener(animator); + } + return this; + } + + /** + * build a copy of given animator + * + * @return + */ + public Animator build() { + //这种方式clone出来的animator不能重复播放 + /*final ObjectAnimator result = getAnimator().clone();//克隆一份 + setupListeners(result); + result.setupStartValues(); + return result;*/ + + final ObjectAnimator self = this.getAnimator(); + final ObjectAnimator anim = new ObjectAnimator(); + anim.setTarget(self.getTarget()); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { + anim.setAutoCancel(true); + } + if (self.getValues() != null) { + anim.setValues(self.getValues()); + } + anim.setInterpolator(self.getInterpolator()); + anim.setDuration(self.getDuration()); + anim.setStartDelay(self.getStartDelay()); + anim.setRepeatCount(self.getRepeatCount()); + anim.setRepeatMode(self.getRepeatMode()); + setupListeners(anim); + return anim; + } + + public List getPropertyValuesHolder() { + return Arrays.asList(getAnimator().getValues()); + } + //----------------------------------------listeners--------------------------------------------- + + private void addAnimatorListener(ObjectAnimator animator) { + if (animator != null && (mOnStartCallback != null || mOnEndCallback != null || mOnCancelCallback != null || mOnRepeatCallback != null)) { + animator.addListener(new Animator.AnimatorListener() {//add a listener + @Override + public void onAnimationStart(Animator animation) { + isRunning = true; + LuaUtil.callFunction(mOnStartCallback); + } + + @Override + public void onAnimationEnd(Animator animation) { + isRunning = false; + LuaUtil.callFunction(mOnEndCallback); + } + + @Override + public void onAnimationCancel(Animator animation) { + isRunning = false; + LuaUtil.callFunction(mOnCancelCallback); + } + + @Override + public void onAnimationRepeat(Animator animation) { + LuaUtil.callFunction(mOnRepeatCallback); + } + }); + } + } + + private void addOnPauseListener(ObjectAnimator animator) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { + if (animator != null && (mOnPauseCallback != null || mOnResumeCallback != null)) { + animator.addPauseListener(new Animator.AnimatorPauseListener() { + @Override + public void onAnimationPause(Animator animation) { + LuaUtil.callFunction(mOnPauseCallback); + } + + @Override + public void onAnimationResume(Animator animation) { + LuaUtil.callFunction(mOnResumeCallback); + } + }); + } + } + } + + private void addOnUpdateListener(ObjectAnimator animator) { + if (animator != null && mOnUpdateCallback != null) { + animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { + @Override + public void onAnimationUpdate(ValueAnimator animation) { + LuaUtil.callFunction(mOnUpdateCallback); + } + }); + } + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/userdata/ui/UDAnimatorSet.java b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/ui/UDAnimatorSet.java new file mode 100644 index 00000000..6a105bbc --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/ui/UDAnimatorSet.java @@ -0,0 +1,473 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.userdata.ui; + +import android.animation.Animator; +import android.animation.AnimatorSet; +import android.animation.ObjectAnimator; +import android.animation.ValueAnimator; +import android.os.Build; +import android.text.TextUtils; +import android.view.animation.Interpolator; + +import com.taobao.luaview.extend.animation.AnimatorDecorationHelper; +import com.taobao.luaview.extend.animation.BaseViewAnimatorDecoration; +import com.taobao.luaview.userdata.base.BaseUserdata; +import com.taobao.luaview.util.LuaUtil; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaTable; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; + +import java.util.ArrayList; +import java.util.List; + +/** + * Animator 数据封装 + * + * @author song + */ +public class UDAnimatorSet extends BaseUserdata { + private LuaValue mOnStartCallback; + private LuaValue mOnEndCallback; + private LuaValue mOnCancelCallback; + private LuaValue mOnRepeatCallback; + private LuaValue mOnPauseCallback; + private LuaValue mOnResumeCallback; + private LuaValue mOnUpdateCallback; + + private List mAnimators; + private UDView mTarget; + private int mRepeatCount; + private int mRepeatMode; + private float[] mFloatValues; + private int[] mIntValues; + + private BaseViewAnimatorDecoration mAnimatorDecoration; + + public UDAnimatorSet(Globals globals, LuaValue metaTable, Varargs varargs) { + super(new AnimatorSet(), globals, metaTable, varargs); + init(varargs); + } + + private AnimatorSet getAnimatorSet() { + return (AnimatorSet) userdata(); + } + + private void init(Varargs varargs) { + mAnimators = new ArrayList(); + String animTypeName = LuaUtil.getString(varargs, 1); + this.mAnimatorDecoration = AnimatorDecorationHelper.createDecoration(animTypeName); + } + + private ObjectAnimator createAnimator() { + final ObjectAnimator animator = new ObjectAnimator(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { + animator.setAutoCancel(true); + } + return animator; + } + + /** + * 设置target + * + * @param udView + * @return + */ + public UDAnimatorSet with(UDView udView) { + final AnimatorSet animator = getAnimatorSet(); + if (animator != null && udView != null && udView.getView() != null) { + mTarget = udView; + if (mAnimatorDecoration != null) {//decoration + mAnimatorDecoration.setTarget(animator, udView.getView()); + } + } + return this; + } + + public UDAnimatorSet setCallback(LuaTable callbacks) { + if (callbacks != null) { + mOnStartCallback = LuaUtil.getFunction(callbacks, "onStart", "OnStart"); + mOnEndCallback = LuaUtil.getFunction(callbacks, "onEnd", "OnEnd"); + mOnCancelCallback = LuaUtil.getFunction(callbacks, "onCancel", "OnCancel"); + mOnPauseCallback = LuaUtil.getFunction(callbacks, "onPause", "OnPause"); + mOnResumeCallback = LuaUtil.getFunction(callbacks, "onResume", "OnResume"); + mOnRepeatCallback = LuaUtil.getFunction(callbacks, "onRepeat", "OnRepeat"); + mOnUpdateCallback = LuaUtil.getFunction(callbacks, "onUpdate", "OnUpdate"); + } + return this; + } + + public UDAnimatorSet setOnStartCallback(LuaValue mOnStartCallback) { + this.mOnStartCallback = mOnStartCallback; + return this; + } + + public UDAnimatorSet setOnEndCallback(LuaValue mOnEndCallback) { + this.mOnEndCallback = mOnEndCallback; + return this; + } + + public UDAnimatorSet setOnCancelCallback(LuaValue mOnCancelCallback) { + this.mOnCancelCallback = mOnCancelCallback; + return this; + } + + public UDAnimatorSet setOnRepeatCallback(LuaValue mOnRepeatCallback) { + this.mOnRepeatCallback = mOnRepeatCallback; + return this; + } + + public UDAnimatorSet setOnPauseCallback(LuaValue mOnPauseCallback) { + this.mOnPauseCallback = mOnPauseCallback; + return this; + } + + public UDAnimatorSet setOnResumeCallback(LuaValue mOnResumeCallback) { + this.mOnResumeCallback = mOnResumeCallback; + return this; + } + + // 这个在AnimatorSet中没有 + public UDAnimatorSet setOnUpdateCallback(LuaValue mOnUpdateCallback) { + this.mOnUpdateCallback = mOnUpdateCallback; + return this; + } + + + /** + * 设置属性 + * + * @param name + * @return + */ + public UDAnimatorSet ofProperty(final String name, float... values) { + if (mAnimators != null && TextUtils.isEmpty(name) == false) { + final ObjectAnimator animator = createAnimator(); + animator.setPropertyName(name); + if (values != null && values.length > 0) { + animator.setFloatValues(values); + } + mAnimators.add(animator); + } + return this; + } + + /** + * 时长 + * + * @param duration + * @return + */ + public UDAnimatorSet setDuration(long duration) { + final AnimatorSet animatorSet = getAnimatorSet(); + if (animatorSet != null && duration >= 0) { + animatorSet.setDuration(duration); + } + return this; + } + + /** + * 启动延时 + * + * @param delay + * @return + */ + public UDAnimatorSet setStartDelay(long delay) { + final AnimatorSet animator = getAnimatorSet(); + if (animator != null && delay >= 0) { + animator.setStartDelay(delay); + } + return this; + } + + /** + * 重复次数,负数标示无限 + * + * @param repeatCount + * @return + */ + public UDAnimatorSet setRepeatCount(int repeatCount) { + this.mRepeatCount = repeatCount; + return this; + } + + /** + * 重复方式(1 default, -1 infinite, 2 reverse) + * + * @param repeatMode + * @return + */ + public UDAnimatorSet setRepeatMode(int repeatMode) { + this.mRepeatMode = repeatMode; + return this; + } + + /** + * 浮点数 + * + * @param values + * @return + */ + public UDAnimatorSet setFloatValues(float... values) { + mFloatValues = values; + return this; + } + + /** + * 整数 + * + * @param values + * @return + */ + public UDAnimatorSet setIntValues(int... values) { + mIntValues = values; + return this; + } + + /** + * 加速器 + * AccelerateDecelerateInterpolator, + * AccelerateInterpolator, + * AnticipateInterpolator, + * AnticipateOvershootInterpolator, + * BaseInterpolator, + * BounceInterpolator, + * CycleInterpolator, + * DecelerateInterpolator, + * FastOutLinearInInterpolator, + * FastOutSlowInInterpolator, + * LinearInterpolator, + * LinearOutSlowInInterpolator, + * OvershootInterpolator, + * PathInterpolator + * + * @param interpolator + * @return + */ + public UDAnimatorSet setInterpolator(final Interpolator interpolator) { + final AnimatorSet animator = getAnimatorSet(); + if (animator != null && interpolator != null) { + animator.setInterpolator(interpolator); + } + return this; + } + + /** + * start all animator + * + * @return + */ + public UDAnimatorSet start() { + final AnimatorSet animatorSet = getAnimatorSet(); + if (animatorSet != null && mTarget != null) { + if (!animatorSet.isStarted()) { + setup(animatorSet); + animatorSet.setupStartValues();//设置开始值 + animatorSet.start(); + } + } + return this; + } + + /** + * cancel animator + * + * @return + */ + public UDAnimatorSet cancel() { + final AnimatorSet animatorSet = getAnimatorSet(); + if (animatorSet != null) { + if (animatorSet.isStarted()) { + animatorSet.cancel(); + animatorSet.setupEndValues(); + } + } + + if (mTarget != null) { + mTarget.cancelAnimation(); + } + + return this; + } + + /** + * pause animator + * + * @return + */ + public UDAnimatorSet pause() { + final AnimatorSet animatorSet = getAnimatorSet(); + if (animatorSet != null) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { + if (!animatorSet.isPaused()) { + animatorSet.pause(); + } + } + } + + if (mTarget != null) { + mTarget.pauseAnimation(); + } + return this; + } + + /** + * resume animator + * + * @return + */ + public UDAnimatorSet resume() { + final AnimatorSet animatorSet = getAnimatorSet(); + if (animatorSet != null) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { + if (animatorSet.isPaused()) { + animatorSet.resume(); + } + } + } + + if (mTarget != null) { + mTarget.resumeAnimation(); + } + + return this; + } + + public UDAnimatorSet setup(Animator animator) { + setupValues(animator); + setupListeners(animator); + return this; + } + + public UDAnimatorSet setupValues(Animator animator) { + animator.setupStartValues(); + if (mTarget != null && mAnimators != null) { + for (Animator anim : mAnimators) { + anim.setTarget(mTarget.getView()); + anim.setupStartValues(); + if (anim instanceof ValueAnimator) { + ((ValueAnimator) anim).setRepeatCount(mRepeatCount); + ((ValueAnimator) anim).setRepeatMode(mRepeatMode); + //TODO + } + } + if (animator instanceof AnimatorSet) { + ((AnimatorSet) animator).playTogether(mAnimators); + } + } + return this; + } + + /** + * setup listeners + * + * @param animator + * @return + */ + public UDAnimatorSet setupListeners(Animator animator) { + if (animator != null) { + animator.removeAllListeners();//先移除所有listener、pause listener + if (animator instanceof ValueAnimator) {//移除所有update listener + ((ValueAnimator) animator).removeAllUpdateListeners(); + } + addAnimatorListener(animator); + addOnPauseListener(animator); + addOnUpdateListener(animator); + } + return this; + } + + /** + * build a copy of given animator + * + * @return + */ + public Animator build() { + final AnimatorSet animatorSet = getAnimatorSet(); + final AnimatorSet result = animatorSet.clone();//克隆一份 + setup(result); + return result; + } + + public boolean isRunning() { + return getAnimatorSet().isRunning(); + } + + public boolean isStarted() { + return getAnimatorSet().isStarted(); + } + + public boolean isPaused() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { + return getAnimatorSet().isPaused(); + } else {//TODO 这个判断是否有问题? + return !isRunning() && isStarted(); + } + } + //----------------------------------------listeners--------------------------------------------- + + private void addAnimatorListener(Animator animator) { + if (animator != null && (mOnStartCallback != null || mOnEndCallback != null || mOnCancelCallback != null || mOnRepeatCallback != null)) { + animator.addListener(new Animator.AnimatorListener() {//add a listener + @Override + public void onAnimationStart(Animator animation) { + LuaUtil.callFunction(mOnStartCallback); + } + + @Override + public void onAnimationEnd(Animator animation) { + LuaUtil.callFunction(mOnEndCallback); + } + + @Override + public void onAnimationCancel(Animator animation) { + LuaUtil.callFunction(mOnCancelCallback); + } + + @Override + public void onAnimationRepeat(Animator animation) { + LuaUtil.callFunction(mOnRepeatCallback); + } + }); + } + } + + private void addOnPauseListener(Animator animator) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { + if (animator != null && (mOnPauseCallback != null || mOnResumeCallback != null)) { + animator.addPauseListener(new Animator.AnimatorPauseListener() { + @Override + public void onAnimationPause(Animator animation) { + LuaUtil.callFunction(mOnPauseCallback); + } + + @Override + public void onAnimationResume(Animator animation) { + LuaUtil.callFunction(mOnResumeCallback); + } + }); + } + } + } + + private void addOnUpdateListener(Animator animator) { + if (mOnUpdateCallback != null) { + if (animator instanceof ValueAnimator) { + ((ValueAnimator) animator).addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { + @Override + public void onAnimationUpdate(ValueAnimator animation) { + LuaUtil.callFunction(mOnUpdateCallback); + } + }); + } + } + } +} diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/userdata/ui/UDButton.java b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/ui/UDButton.java new file mode 100644 index 00000000..fa94a9d3 --- /dev/null +++ b/Android/LuaViewSDK/src/com/taobao/luaview/userdata/ui/UDButton.java @@ -0,0 +1,108 @@ +/* + * Created by LuaView. + * Copyright (c) 2017, Alibaba Group. All rights reserved. + * + * This source code is licensed under the MIT. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +package com.taobao.luaview.userdata.ui; + +import android.annotation.TargetApi; +import android.graphics.drawable.Drawable; +import android.graphics.drawable.StateListDrawable; +import android.os.Build; +import android.util.StateSet; +import android.widget.Button; + +import com.taobao.luaview.util.ImageUtil; + +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; + +import java.util.Map; + +public class UDButton extends UDTextView + + + + + diff --git a/IOS/Playground/Playground/playground/sample/github/github_cell.xml b/IOS/Playground/Playground/playground/sample/github/github_cell.xml new file mode 100644 index 00000000..f1ea4915 --- /dev/null +++ b/IOS/Playground/Playground/playground/sample/github/github_cell.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/IOS/Playground/Playground/playground/sample/github/github_ios.xml b/IOS/Playground/Playground/playground/sample/github/github_ios.xml new file mode 100644 index 00000000..d827c463 --- /dev/null +++ b/IOS/Playground/Playground/playground/sample/github/github_ios.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/IOS/Playground/Playground/playground/widget/Animation.lua b/IOS/Playground/Playground/playground/widget/Animation.lua new file mode 100644 index 00000000..bd890f6c --- /dev/null +++ b/IOS/Playground/Playground/playground/widget/Animation.lua @@ -0,0 +1,53 @@ +-- +-- Copyright 2017 Alibaba Group +-- License: MIT +-- Website: https://alibaba.github.io/LuaViewSDK +-- User: tuoli +-- Date: 17/3/30 +-- + +Navigation:title("Animation.lua") + +local meta = object:new() + +function meta:onCreate(args) + self.views = pica:getInstance():render("widget/animation.xml") + self.spirit = self.views["img"] + self.translateBtn = self.views["translateBtn"] + self.scaleBtn = self.views["scaleBtn"] + self.alphaBtn = self.views["alphaBtn"] + self.resetBtn = self.views["resetBtn"] + self.allBtn = self.views["allBtn"] + + self:handle() +end + +function meta:handle() + self.translateBtn:onClick(function() + local translate = Animation():translation(sys.contW/2, sys.contW/2):duration(1) + translate:with(self.spirit):start() + end) + self.scaleBtn:onClick(function() + local scale = Animation():scale(0.5, 0.5):duration(1) + scale:with(self.spirit):start() + end) + self.alphaBtn:onClick(function() + local alpha = Animation():alpha(0.3):duration(1) + alpha:with(self.spirit):start() + end) + self.allBtn:onClick(function() + local translate = Animation():translation(sys.contW/2, sys.contW/2):duration(1) + local scale = Animation():scale(0.5, 0.5):duration(1) + local alpha = Animation():alpha(0.3):duration(1) + alpha:with(self.spirit):start() + scale:with(self.spirit):start() + translate:with(self.spirit):start() + end) + self.resetBtn:onClick(function() + self.spirit:translation(0, 0) + self.spirit:scale(1, 1) + self.spirit:alpha(1) + end) +end + +return meta diff --git a/IOS/Playground/Playground/playground/widget/Button.lua b/IOS/Playground/Playground/playground/widget/Button.lua new file mode 100644 index 00000000..25ee82cc --- /dev/null +++ b/IOS/Playground/Playground/playground/widget/Button.lua @@ -0,0 +1,46 @@ +-- +-- Copyright 2017 Alibaba Group +-- License: MIT +-- Website: https://alibaba.github.io/LuaViewSDK +-- User: tuoli +-- Date: 17/3/30 +-- + +Navigation:title("Button.lua") + +local meta = object:new() + +function meta:onCreate(args) + self.views = pica:getInstance():render("widget/button.xml") + self.button1 = self.views["button1"] + self.button2 = self.views["button2"] + self.button3 = self.views["button3"] + self.button4 = self.views["button4"] + self.button5 = self.views["button5"] + self.button6 = self.views["button6"] + + self:handle() +end + +function meta:handle() + self.button1:onClick(function() + Toast("Clicked") + end) + self.button2:onClick(function() + Toast("Clicked") + end) + self.button3:onClick(function() + Toast("Clicked") + end) + self.button4:onClick(function() + Toast("Clicked") + end) + self.button5:onClick(function() + Toast("Clicked") + end) + self.button6:onClick(function() + Toast("Clicked") + end) +end + +return meta diff --git a/IOS/Playground/Playground/playground/widget/HScrollView.lua b/IOS/Playground/Playground/playground/widget/HScrollView.lua new file mode 100644 index 00000000..1f89b4c1 --- /dev/null +++ b/IOS/Playground/Playground/playground/widget/HScrollView.lua @@ -0,0 +1,40 @@ +-- +-- Copyright 2017 Alibaba Group +-- License: MIT +-- Website: https://alibaba.github.io/LuaViewSDK +-- User: tuoli +-- Date: 17/3/30 +-- + +Navigation:title("HScrollView.lua") + +local meta = object:new() + +function meta:onCreate(args) + self.views = pica:getInstance():render("widget/hscrollview.xml") + self.scroller = self.views["scroller"] + + self:handle() +end + +function meta:handle() + for k, v in pairs(self.views) do + if k ~= "scroller" then + v:onClick(function() + v:backgroundColor(0xEB3131) + for _k, _v in pairs(self.views) do + if _k ~= "scroller" then + if (_v ~= v) then + _v:backgroundColor(0x004B97) + end + end + end + local x, y, w, h = v:frame() + local dx = (sys.contW - w)/2 + self.scroller:offset(x-dx, 0, true) + end) + end + end +end + +return meta \ No newline at end of file diff --git a/IOS/Playground/Playground/playground/widget/Image.lua b/IOS/Playground/Playground/playground/widget/Image.lua new file mode 100644 index 00000000..720ace9d --- /dev/null +++ b/IOS/Playground/Playground/playground/widget/Image.lua @@ -0,0 +1,17 @@ +-- +-- Copyright 2017 Alibaba Group +-- License: MIT +-- Website: https://alibaba.github.io/LuaViewSDK +-- User: tuoli +-- Date: 17/3/30 +-- + +Navigation:title("Image.lua") + +local meta = object:new() + +function meta:onCreate(args) + self.views = pica:getInstance():render("widget/image.xml") +end + +return meta diff --git a/IOS/Playground/Playground/playground/widget/Label.lua b/IOS/Playground/Playground/playground/widget/Label.lua new file mode 100644 index 00000000..4076a5fe --- /dev/null +++ b/IOS/Playground/Playground/playground/widget/Label.lua @@ -0,0 +1,52 @@ +-- +-- Copyright 2017 Alibaba Group +-- License: MIT +-- Website: https://alibaba.github.io/LuaViewSDK +-- User: tuoli +-- Date: 17/3/30 +-- + +Navigation:title("Label.lua") + +local meta = object:new() + +function meta:onCreate(args) + self.list = CollectionView() + self.list:frame(0, 0, sys.contW, sys.contH) + self.list:initParams({ + Section = { + SectionCount = function() + return 1 + end, + RowCount = function(section) + return 1 + end + }, + Cell = { + Id = function(section, row) + return "LabelCell" + end, + LabelCell = { + Size = function(section, row) + return sys.contW, sys.contH*2.5 + end, + Init = function(cell, section, row) + cell.objs = pica:getInstance():render("widget/label_item.xml") + + local fs1 = cell.objs["fs1"] + fs1:text(StyledString("normal", {fontStyle = "normal", fontSize=25*sys.scale })) + local fs2 = cell.objs["fs2"] + fs2:text(StyledString("bold", {fontStyle = "bold", fontSize=25*sys.scale})) + local fs3 = cell.objs["fs3"] + fs3:text(StyledString("italic", {fontStyle = "italic", fontSize=25*sys.scale})) + local td1 = cell.objs["td1"] + td1:text(StyledString("strikethrough", {strikethrough = true, fontSize=25*sys.scale})) + local td2 = cell.objs["td2"] + td2:text(StyledString("underline", {underline = true, fontSize=25*sys.scale})) + end + } + } + }) +end + +return meta diff --git a/IOS/Playground/Playground/playground/widget/List.lua b/IOS/Playground/Playground/playground/widget/List.lua new file mode 100644 index 00000000..bf8f8a6e --- /dev/null +++ b/IOS/Playground/Playground/playground/widget/List.lua @@ -0,0 +1,66 @@ +-- +-- Copyright 2017 Alibaba Group +-- License: MIT +-- Website: https://alibaba.github.io/LuaViewSDK +-- User: tuoli +-- Date: 17/3/30 +-- + +Navigation:title("List.lua") + +local meta = object:new() + +function meta:onCreate(args) + self.views = pica:getInstance():render("widget/list.xml") + self.list = self.views["tableView"] + self.header = self.views["headerText"] + + self:handle() +end + +function meta:handle() + self.list:initParams({ + Section = { + SectionCount = function() + return 1 + end, + RowCount = function(section) + return 20 + end + }, + Cell = { + Id = function(section, row) + return "RowCell" + end, + RowCell = { + Size = function(section, row) + return sys.contW, sys.contH/10 + end, + Init = function(cell, section, row) + cell.window:frame(0, 0, sys.contW, sys.contH/10) + cell.window:flexCss("flex-direction: row") + cell.window:backgroundColor(0xffffff) + + local label = Label() + label:flexCss("margin: 15, flex: 1") + + cell.label = label + cell.window:flexChildren(cell.label) + cell.window:flxLayout(true) -- iOS + end, + Layout = function(cell, section, row) + local style = StyledString("row " .. row, { fontSize = 16*sys.scale, fontColor = 0x000000}) + cell.label:text(style) + end + } + }, + Callback = { + Scrolling = function( firstVisibleSection, firstVisibleRow, visibleCellCount ) + self.header:text("Visible Items: " .. firstVisibleSection * firstVisibleRow .. ", " .. firstVisibleRow + visibleCellCount - 1) + end + } + }) +end + +return meta + diff --git a/IOS/Playground/Playground/playground/widget/ListPinned.lua b/IOS/Playground/Playground/playground/widget/ListPinned.lua new file mode 100644 index 00000000..ea939339 --- /dev/null +++ b/IOS/Playground/Playground/playground/widget/ListPinned.lua @@ -0,0 +1,161 @@ +-- +-- Copyright 2017 Alibaba Group +-- License: MIT +-- Website: https://alibaba.github.io/LuaViewSDK +-- User: tuoli +-- Date: 17/4/11 +-- + +Navigation:title("ListPinned.lua") + +local meta = object:new() + +function meta:onCreate(args) + self.list = CollectionView() + self.list:frame(0, 0, sys.contW, sys.contH) + self.list:initParams({ + Section = { + SectionCount = function() + return (1 + 1 + 12) + end, + RowCount = function(section) + if (section == 1 or section == 2) then + return 1 + else + return 10 + end + end + }, + Cell = { + Id = function(section, row) + if (section == 1) then + return "HeaderCell" + elseif (section == 2) then + return "PinnedCell", Pinned.YES + else + return "CommonCell" + end + end, + HeaderCell = { + Size = function(section, row) + return sys.contW, sys.contH*0.3 + end, + Init = function(cell, section, row) + cell.objs = pica:getInstance():render("widget/list_pinned_head.xml") + end + }, + PinnedCell = { + Size = function(section, row) + return sys.contW, sys.contH/10 + end, + Init = function(cell, section, row) + cell.objs = pica:getInstance():render("widget/hscrollview.xml") + self.pinnedViews = cell.objs + for k, v in pairs(cell.objs) do + if k ~= "scroller" then + v:onClick(function() + self.gotoTop:show() + v:backgroundColor(0xEB3131) + for _k, _v in pairs(cell.objs) do + if _k ~= "scroller" then + if (_v ~= v) then + _v:backgroundColor(0x004B97) + end + end + end + local x, y, w, h = v:frame() + local dx = (sys.contW - w)/2 + cell.objs["scroller"]:offset(x-dx, 0, true) + local index = math.floor(x/(sys.contW/4)) + -- todo: SDK需要统一这个API的第三个参数offset + if (sys.android) then + self.list:scrollToCell(index+3, 1, sys.contH/10, false) + else + self.list:scrollToCell(index+3, 1, -sys.contH/10, false) + end + end) + end + end + end + }, + CommonCell = { + Size = function(section, row) + return sys.contW, sys.contH/3 + end, + Init = function(cell, section, row) + cell.objs = pica:getInstance():render("widget/button.xml") + end, + Layout = function(cell, section, row) + cell.objs["button1"]:title(tostring((section-2)*10+row-1)) + end + } + }, + Callback = { + Scrolling = function( firstVisibleSection, firstVisibleRow, visibleCellCount ) + local dx, dy = self.list:offset() + if (dy <= 0) then + if (self.pinnedViews) then + self.pinnedViews["scroller"]:offset(0, 0, true) + for _k, _v in pairs(self.pinnedViews) do + if _k ~= "scroller" then + if (_k ~= "item1") then + _v:backgroundColor(0x004B97) + else + _v:backgroundColor(0xEB3131) + end + end + end + end + end + + local diff = dy-sys.contH*0.3 + if (diff >= 0) then + self.gotoTop:show() + local index = math.floor(diff/(10*sys.contH/3)+0.01) + 1 + if (self.pinnedViews["item"..index]) then + local x, y, w, h = self.pinnedViews["item"..index]:frame() + local dx = (sys.contW - w)/2 + self.pinnedViews["scroller"]:offset(x-dx, 0, true) + for _k, _v in pairs(self.pinnedViews) do + if _k ~= "scroller" then + if (_k ~= "item"..index) then + _v:backgroundColor(0x004B97) + else + _v:backgroundColor(0xEB3131) + end + end + end + end + else + self.gotoTop:hide() + end + end, + ScrollEnd = function(firstVisibleSection, firstVisibleRow, visibleCellCount ) + end, + } + }) + + self.gotoTop = Image() + self.gotoTop:frame(sys.contW*0.85, sys.contH*0.85, sys.contH*0.07, sys.contH*0.07) + self.gotoTop:image("backtop.png") + self.gotoTop:hide() + self.gotoTop:onClick(function() + self.gotoTop:hide() + self.list:scrollToCell(1, 1, 0, false) + if (self.pinnedViews) then + self.pinnedViews["scroller"]:offset(0, 0, true) + for _k, _v in pairs(self.pinnedViews) do + if _k ~= "scroller" then + if (_k ~= "item1") then + _v:backgroundColor(0x004B97) + else + _v:backgroundColor(0xEB3131) + end + end + end + end + end) +end + +return meta + diff --git a/IOS/Playground/Playground/playground/widget/Loading.lua b/IOS/Playground/Playground/playground/widget/Loading.lua new file mode 100644 index 00000000..697e8c12 --- /dev/null +++ b/IOS/Playground/Playground/playground/widget/Loading.lua @@ -0,0 +1,20 @@ +-- +-- Copyright 2017 Alibaba Group +-- License: MIT +-- Website: https://alibaba.github.io/LuaViewSDK +-- User: tuoli +-- Date: 17/3/30 +-- + +Navigation:title("Loading.lua") + +local meta = object:new() + +function meta:onCreate(args) + self.views = pica:getInstance():render("widget/loading.xml") + self.loading = self.views["loading"] + self.loading:start() +end + +return meta + diff --git a/IOS/Playground/Playground/playground/widget/PagerView.lua b/IOS/Playground/Playground/playground/widget/PagerView.lua new file mode 100644 index 00000000..5431fabc --- /dev/null +++ b/IOS/Playground/Playground/playground/widget/PagerView.lua @@ -0,0 +1,54 @@ +-- +-- Copyright 2017 Alibaba Group +-- License: MIT +-- Website: https://alibaba.github.io/LuaViewSDK +-- User: tuoli +-- Date: 17/3/30 +-- + +Navigation:title("PagerView.lua") + +local meta = object:new() + +function meta:onCreate(args) + self.views = pica:getInstance():render("widget/pagerview.xml") + self.manualSlider = self.views["pagerView1"] + self.indicator1 = self.views["indicator1"] + self.autoSlider = self.views["pagerView2"] + self.indicator2 = self.views["indicator2"] + + self.color = {0xA066D3, 0xFF7F50, 0x228B22} + + self:handle() +end + +function meta:handle() + self.manualSlider:initParams({ + PageCount = 3, + Pages = { + Init = function(page, pos) + page.objs = pica:getInstance():render("widget/pagerview_page1.xml") + end, + Layout = function(page, pos) + page.objs["root"]:backgroundColor(self.color[pos]) + end + } + }) + self.manualSlider:indicator(self.indicator1) + + self.autoSlider:initParams({ + PageCount = 3, + Pages = { + Init = function(page, pos) + page.objs = pica:getInstance():render("widget/pagerview_page.xml") + end, + Layout = function(page, pos) + page.objs["root"]:backgroundColor(self.color[pos]) + end + } + }) + self.autoSlider:indicator(self.indicator2) +end + +return meta + diff --git a/IOS/Playground/Playground/playground/widget/TextField.lua b/IOS/Playground/Playground/playground/widget/TextField.lua new file mode 100644 index 00000000..29b25a10 --- /dev/null +++ b/IOS/Playground/Playground/playground/widget/TextField.lua @@ -0,0 +1,21 @@ +-- +-- Copyright 2017 Alibaba Group +-- License: MIT +-- Website: https://alibaba.github.io/LuaViewSDK +-- User: tuoli +-- Date: 17/3/30 +-- + +Navigation:title("TextField.lua") + +local meta = object:new() + +function meta:onCreate(args) + if (sys.android) then + pica:getInstance():render("widget/textfield_android.xml") + else + pica:getInstance():render("widget/textfield_ios.xml") + end +end + +return meta \ No newline at end of file diff --git a/IOS/Playground/Playground/playground/widget/WebView.lua b/IOS/Playground/Playground/playground/widget/WebView.lua new file mode 100644 index 00000000..e4b3de19 --- /dev/null +++ b/IOS/Playground/Playground/playground/widget/WebView.lua @@ -0,0 +1,35 @@ +-- +-- Copyright 2017 Alibaba Group +-- License: MIT +-- Website: https://alibaba.github.io/LuaViewSDK +-- User: tuoli +-- Date: 17/3/30 +-- + +Navigation:title("WebView.lua") + +local meta = object:new() + +function meta:onCreate(args) + self.views = pica:getInstance():render("widget/webview.xml") + self.web = self.views["web"] + + self:handle() +end + +function meta:handle() + self.web:callback({ + onPageStarted = function() + print("started") + end, + onPageFinished = function() + print("finished") + end, + onReceiveError = function(errorCode, description, failedUrl) + print("error", errorCode, description, failedUrl) + end + }) +end + +return meta + diff --git a/IOS/Playground/Playground/playground/widget/animation.xml b/IOS/Playground/Playground/playground/widget/animation.xml new file mode 100644 index 00000000..ceef4fdc --- /dev/null +++ b/IOS/Playground/Playground/playground/widget/animation.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/IOS/Playground/Playground/playground/widget/button.xml b/IOS/Playground/Playground/playground/widget/button.xml new file mode 100644 index 00000000..baa48dce --- /dev/null +++ b/IOS/Playground/Playground/playground/widget/button.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/IOS/Playground/Playground/playground/widget/hscrollview.xml b/IOS/Playground/Playground/playground/widget/hscrollview.xml new file mode 100644 index 00000000..1a323a42 --- /dev/null +++ b/IOS/Playground/Playground/playground/widget/hscrollview.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/IOS/Playground/Playground/playground/widget/image.xml b/IOS/Playground/Playground/playground/widget/image.xml new file mode 100644 index 00000000..de3f3be5 --- /dev/null +++ b/IOS/Playground/Playground/playground/widget/image.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/IOS/Playground/Playground/playground/widget/label_item.xml b/IOS/Playground/Playground/playground/widget/label_item.xml new file mode 100644 index 00000000..c2b464e1 --- /dev/null +++ b/IOS/Playground/Playground/playground/widget/label_item.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/IOS/Playground/Playground/playground/widget/list.xml b/IOS/Playground/Playground/playground/widget/list.xml new file mode 100644 index 00000000..0071ef8a --- /dev/null +++ b/IOS/Playground/Playground/playground/widget/list.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/IOS/Playground/Playground/playground/widget/list_pinned_head.xml b/IOS/Playground/Playground/playground/widget/list_pinned_head.xml new file mode 100644 index 00000000..5cb3a42f --- /dev/null +++ b/IOS/Playground/Playground/playground/widget/list_pinned_head.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/IOS/Playground/Playground/playground/widget/loading.xml b/IOS/Playground/Playground/playground/widget/loading.xml new file mode 100644 index 00000000..441766af --- /dev/null +++ b/IOS/Playground/Playground/playground/widget/loading.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/IOS/Playground/Playground/playground/widget/pagerview.xml b/IOS/Playground/Playground/playground/widget/pagerview.xml new file mode 100644 index 00000000..825d954c --- /dev/null +++ b/IOS/Playground/Playground/playground/widget/pagerview.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/IOS/Playground/Playground/playground/widget/pagerview_page.xml b/IOS/Playground/Playground/playground/widget/pagerview_page.xml new file mode 100644 index 00000000..765ec822 --- /dev/null +++ b/IOS/Playground/Playground/playground/widget/pagerview_page.xml @@ -0,0 +1,3 @@ + + + diff --git a/IOS/Playground/Playground/playground/widget/pagerview_page1.xml b/IOS/Playground/Playground/playground/widget/pagerview_page1.xml new file mode 100644 index 00000000..7a6b9a01 --- /dev/null +++ b/IOS/Playground/Playground/playground/widget/pagerview_page1.xml @@ -0,0 +1,3 @@ + + + diff --git a/IOS/Playground/Playground/playground/widget/textfield_android.xml b/IOS/Playground/Playground/playground/widget/textfield_android.xml new file mode 100644 index 00000000..ae3e467a --- /dev/null +++ b/IOS/Playground/Playground/playground/widget/textfield_android.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/IOS/Playground/Playground/playground/widget/textfield_ios.xml b/IOS/Playground/Playground/playground/widget/textfield_ios.xml new file mode 100644 index 00000000..19f7dc47 --- /dev/null +++ b/IOS/Playground/Playground/playground/widget/textfield_ios.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/IOS/Playground/Playground/playground/widget/webview.xml b/IOS/Playground/Playground/playground/widget/webview.xml new file mode 100644 index 00000000..54d6e270 --- /dev/null +++ b/IOS/Playground/Playground/playground/widget/webview.xml @@ -0,0 +1,3 @@ + + + diff --git a/IOS/Playground/Playground/test/testLuaLang.lua b/IOS/Playground/Playground/test/testLuaLang.lua new file mode 100644 index 00000000..0b2b021f --- /dev/null +++ b/IOS/Playground/Playground/test/testLuaLang.lua @@ -0,0 +1,22 @@ +-- 1. 函数{}支持 +function abc(a, b, c) { + Toast("Fun" .. a .. "\n" .. b .. c) +} + +abc(1, 'a', ',') + + +-- 2. while {}支持 +--a = 3 +--while(a > 0) do +-- a = a - 1 +--end +-- +--a = 3 +--while(a > 0) { +-- a = a - 1 +--} +-- +-- +-- +-- diff --git a/IOS/Playground/Playground/test/testNavigation.lua b/IOS/Playground/Playground/test/testNavigation.lua new file mode 100644 index 00000000..789046d4 --- /dev/null +++ b/IOS/Playground/Playground/test/testNavigation.lua @@ -0,0 +1,12 @@ +--工具包引入 +require "kit/lv_kit" + + +--Navigation.setTitle("这是导航测试") + +local button = Button() +button.text("测试view") +Navigation.title(button) + + +print(Navigation.title()) \ No newline at end of file diff --git a/IOS/Playground/Playground/test/testSystem.lua b/IOS/Playground/Playground/test/testSystem.lua new file mode 100644 index 00000000..24e4260d --- /dev/null +++ b/IOS/Playground/Playground/test/testSystem.lua @@ -0,0 +1,12 @@ +require "kit/lv_kit" + +print(type(System)) +print(System.ios()) +print(System.android()) +print(System.vmVersion()) +print(System.osVersion()) +print(System.platform()) +print(System.scale()) +print(System.device()) +print(System.screenSize()) +System.gc() \ No newline at end of file diff --git a/IOS/Playground/Playground/test/testTimer.lua b/IOS/Playground/Playground/test/testTimer.lua new file mode 100644 index 00000000..220ae352 --- /dev/null +++ b/IOS/Playground/Playground/test/testTimer.lua @@ -0,0 +1,15 @@ +-- 1 +Timer(function() + print("Timer1 Run") +end).start(1, true).cancel() + +--2 +timer2 = Timer() +timer2.callback(function() print("Timer2 Run") end) +timer2.start(2, true) + +--3 +timer3 = Timer(function() + timer2.cancel() +end) +timer3.start(10.1) \ No newline at end of file diff --git a/IOS/Playground/Playground/test/testUIAlert.lua b/IOS/Playground/Playground/test/testUIAlert.lua new file mode 100644 index 00000000..e4aa68cc --- /dev/null +++ b/IOS/Playground/Playground/test/testUIAlert.lua @@ -0,0 +1,21 @@ +-- +-- Created by IntelliJ IDEA. +-- User: song + +--1 一个按钮 +Alert("一个按钮", "文字", "确定", function() + print("点击了") +end) + +--2 两个按钮 +Alert("两个按钮", "文字", "确定", "取消", function() + print("点击了") +end, function() + print("取消了") +end) + +--3 只有内容 +Alert(nil, "只有内容") + +--4 只有标题 +Alert("只有标题") diff --git a/IOS/Playground/Playground/test/testUIButton.lua b/IOS/Playground/Playground/test/testUIButton.lua new file mode 100644 index 00000000..c3672f4a --- /dev/null +++ b/IOS/Playground/Playground/test/testUIButton.lua @@ -0,0 +1,9 @@ +-- +-- Created by IntelliJ IDEA. +-- User: song + +--button +button = Button() +button.text("测试") +button.size(200, 200) +--button.setFrame(200, 0, 500, 200) diff --git a/IOS/Playground/Playground/test/testUIHorizontalScrollView.lua b/IOS/Playground/Playground/test/testUIHorizontalScrollView.lua new file mode 100644 index 00000000..a78e9a45 --- /dev/null +++ b/IOS/Playground/Playground/test/testUIHorizontalScrollView.lua @@ -0,0 +1,47 @@ +--工具包引入 +require "kit/lv_kit" + + +-- 活动指示器 +local SCREEN_WIDTH = System.screenSize() + +local scrollView = HorizontalScrollView() +b0 = Button() +b0.text("scrollTo") +b0.callback(function() + scrollView.offset(20, 0) +end) + +b1 = Button() +b1.text("scrollBy") +b1.xy(300, 0) +b1.callback(function() + scrollView.scrollBy(20, 0) +end) + +b3 = Button() +b3.text("smoothScrollTo") +b3.xy(0, 200) +b3.callback(function() + scrollView.offset(20, 0, true) +end) + +b4 = Button() +b4.text("smoothScrollBy") +b4.xy(500, 200) +b4.callback(function() + scrollView.smoothScrollBy(20, 0) +end) + + +for i = 0, 10, 1 do + local btn = Label() + btn.text("BTN" .. i) + btn.frame(i * 400, 0, 398, 198) + btn.backgroundColor(0xff00ff00) + scrollView.addView(btn) +end + +scrollView.xy(0, 500) +scrollView.size(SCREEN_WIDTH, 200) +scrollView.backgroundColor(0xffcccccc) diff --git a/IOS/Playground/Playground/test/testUIImageView.lua b/IOS/Playground/Playground/test/testUIImageView.lua new file mode 100644 index 00000000..97ebcbc8 --- /dev/null +++ b/IOS/Playground/Playground/test/testUIImageView.lua @@ -0,0 +1,31 @@ +--1. 普通设置url,size,center,contentmode等 +view = Image() +view.size(500, 400) +view.center(50, 50) +print(view.size()) +view.backgroundColor(0xffaa0000) +view.callback(function() + print("Button Clicked") +end) +view.contentMode(2) +view.image("https://gju1.alicdn.com/bao/uploaded/i1/100000119234047241/TB2JnnKeVXXXXcpXXXXXXXXXXXX_!!0-0-juitemmedia.jpg_560x560Q90.jpg") + + +--2. 普通构造传url +view2 = Image("https://gju1.alicdn.com/bao/uploaded/i4/100000120700895002/TB2Qu0_fXXXXXb9XpXXXXXXXXXX_!!0-0-juitemmedia.jpg_560x560Q90.jpg") +view2.frame(0, 300, 300, 300) + + +--3. 动画 +view3 = Image("https://gju1.alicdn.com/bao/uploaded/i4/100000120700895002/TB2Qu0_fXXXXXb9XpXXXXXXXXXX_!!0-0-juitemmedia.jpg_560x560Q90.jpg"); +images = {} +images[1] = "animate1" +images[2] = "animate2" +view3.backgroundColor(0xff00aa00) +view3.frame(300, 600, 300, 600) +view3.startAnimation(images, 1 , 0) + + + + + diff --git a/IOS/Playground/Playground/test/testUILoadingDialog.lua b/IOS/Playground/Playground/test/testUILoadingDialog.lua new file mode 100644 index 00000000..33f9f5a3 --- /dev/null +++ b/IOS/Playground/Playground/test/testUILoadingDialog.lua @@ -0,0 +1,26 @@ +--工具包引入 +require "kit/lv_kit" + +local loading +local width = System.screenSize() + +btn1 = Button() +btn1.callback(function() + loading = LoadingDialog(); + loading.show() +end) + +btn2 = Button() +btn2.callback(function() + if(loading) then + loading.hide() + end +end) + + +btn1.text("Start") +btn1.frame(0, 0, width, 200) +btn2.text("Stop") +btn2.frame(0, 700, width, 200) + + diff --git a/IOS/Playground/Playground/test/testUILoadingView.lua b/IOS/Playground/Playground/test/testUILoadingView.lua new file mode 100644 index 00000000..0a51d8a3 --- /dev/null +++ b/IOS/Playground/Playground/test/testUILoadingView.lua @@ -0,0 +1,33 @@ +--工具包引入 +require "kit/lv_kit" + + + +local loading = LoadingIndicator() +loading.backgroundColor(0xaaaa0000) +loading.size(200, 200) +loading.alignCenter() + +local width = System.screenSize() + +btn1 = Button() +btn1.callback(function() + if (loading) then + loading.show() + end +end) + +btn2 = Button() +btn2.callback(function() + if (loading) then + loading.hide() + end +end) + + +btn1.text("Start") +btn1.frame(0, 200, width, 200) +btn2.text("Stop") +btn2.frame(0, 400, width, 200) + + diff --git a/IOS/Playground/Playground/test/testUINoticeView.lua b/IOS/Playground/Playground/test/testUINoticeView.lua new file mode 100644 index 00000000..f0509672 --- /dev/null +++ b/IOS/Playground/Playground/test/testUINoticeView.lua @@ -0,0 +1,24 @@ +--工具包引入 +require "kit/lv_kit" + +local width = System.screenSize() + +btn1 = Button() + +btn1.callback(function() + Notice("测试一下Toast") +end) + +btn2 = Button() +btn2.callback(function() + local notice = Notice(); + notice.show("xx") +end) + + +btn1.text("第一") +btn1.frame(0, 0, width, 200) +btn2.text("第二") +btn2.frame(0, 700, width, 200) + + diff --git a/IOS/Playground/Playground/test/testUIRefreshTableView.lua b/IOS/Playground/Playground/test/testUIRefreshTableView.lua new file mode 100644 index 00000000..f538ae8b --- /dev/null +++ b/IOS/Playground/Playground/test/testUIRefreshTableView.lua @@ -0,0 +1,76 @@ +--工具包引入 +require "kit/lv_kit" +-- 变量定义 +local s_width, s_height = System.screenSize() +local blockData, tableView + +local loading = LoadingIndicator() +loading.size(200, 200) +loading.alignCenter() +loading.show() + +tableView = RefreshTableView { + Section = { + SectionCount = 1, -- section数量 + RowCount = function(section) + if (blockData) then + return table:getn(blockData.model) + else + return 0 + end + end + }, + Cell = { + Id = function(section, row) -- 指定section和row对应的Cell类型唯一识别号 + return "Cell1"; + end, + Cell1 = { + -- cell 具体样式 + Size = function(section, row) + return 600 + end, + Init = function(cell, section, row) -- 初始化cell + cell.icon = Image(); + cell.title = Label(); + cell.info = Label(); + end, + Layout = function(cell, section, row) -- cell复用时调用 + if (blockData) then + cell.icon.size(s_width, 400); + cell.icon.image('http:' .. blockData.model[row].materials["brandLogoUrl"]); + cell.title.frame(0, 400, 200, 50); + cell.title.text(blockData.model[row].materials["logoText"]); + cell.info.frame(500, 400, 600, 50) + cell.info.text(blockData.model[row].materials["brandDesc"]) + end + end, + Callback = { + Click = function(cell, section, row) -- 用户点击了section和row + Toast("Click-Section " .. section .. ", Row " .. row); + System.gc(); + end, + LongClick= function(cell, section, row) + Toast("LongClick-Section " .. section .. ", Row " .. row); + return true; + end + } + } + }, + Callback = { + PullDown = function() + -- 开始下拉刷新回调 + Timer(function() + tableView.stopPullDownRefreshing() + end).start(3000); + end, + PullUp = function() + -- 开始上拉刷新回调 + end + } +}; + + +tableView.frame(0, 200, s_width, s_height - 200) +tableView.showScrollIndicator(false) + + diff --git a/IOS/Playground/Playground/test/testUITableView.lua b/IOS/Playground/Playground/test/testUITableView.lua new file mode 100644 index 00000000..272cacf7 --- /dev/null +++ b/IOS/Playground/Playground/test/testUITableView.lua @@ -0,0 +1,58 @@ +--工具包引入 +require "kit/lv_kit" +-- 变量定义 +local s_width, s_height = System.screenSize() +local blockData, tableView + +local loading = LoadingIndicator() +loading.size(200, 200) +loading.alignCenter() +loading.show() + + +tableView = TableView { + Section = { + SectionCount = 1, -- section数量 + RowCount = function(section) + if (blockData) then + return table:getn(blockData.model) + else + return 0 + end + end + }, + Cell = { + Id = function(section, row) -- 指定section和row对应的Cell类型唯一识别号 + return "Cell1"; + end, + Cell1 = { + -- cell 具体样式 + Size = function(section, row) + return 450 + end, + Init = function(cell, section, row) -- 初始化cell + cell.icon = Image(); + cell.title = Label(); + cell.info = Label(); + end, + Layout = function(cell, section, row) -- cell复用时调用 + if (blockData) then + cell.icon.size(s_width, 400); + cell.icon.image('http:' .. blockData.model[row].materials["brandLogoUrl"]); + cell.title.frame(0, 400, 200, 50); + cell.title.text(blockData.model[row].materials["logoText"]); + cell.info.frame(500, 400, 600, 50) + cell.info.text(blockData.model[row].materials["brandDesc"]) + end + end, + Callback = function(cell, section, row) -- 用户点击了section和row + Toast("Section " .. section .. ", Row " .. row); + System.gc(); + end + } + } +}; + +tableView.showScrollIndicator(true) + + diff --git a/IOS/Playground/Playground/test/testUITextFieldView.lua b/IOS/Playground/Playground/test/testUITextFieldView.lua new file mode 100644 index 00000000..d443b973 --- /dev/null +++ b/IOS/Playground/Playground/test/testUITextFieldView.lua @@ -0,0 +1,39 @@ +--工具包引入 +require "kit/lv_kit" + +local width = System.screenSize() + +local tf = TextField() +tf.hint("测试额") +tf.frame(0, 0, width, 150) + +tf.callback({ + BeginEditing=function() + Toast("开始编辑") + end, + + EndEditing=function() + Toast("结束编辑") + end +}) + +local btn1 = Button() +btn1.callback(function() + --tf.text("点击了") + print( tf.text() ); +end) + + +btn1.text("点我试试") +btn1.frame(0, 300, width, 200) + + + +att1 = StyledString( "123test", { fontSize=12, fontWeight=FontWeight.BOLD, fontColor=0x220000ff, foregroundAlpha=0.5 } ); +att2 = StyledString( "测试测试", { fontSize=30, fontColor=0xff0000, backgroundColor=0xff} ); +att3 = StyledString( "2897348", { fontSize=13, fontColor=0x777777, strikethrough =1} ); +att4 = StyledString( "下划线测试", { fontSize=9, fontColor=0x777777, underline=true} ); + +tf.text(att1+att2+att3+att4); + + diff --git a/IOS/Playground/Playground/test/testUITextView.lua b/IOS/Playground/Playground/test/testUITextView.lua new file mode 100644 index 00000000..4f938918 --- /dev/null +++ b/IOS/Playground/Playground/test/testUITextView.lua @@ -0,0 +1,9 @@ +--1. +view = Label() +view.text("测试") +view.backgroundColor(0xaaaa0000) +view.frame(200, 200, 200, 200) + + + + diff --git a/IOS/Playground/Playground/test/testUITextView2.lua b/IOS/Playground/Playground/test/testUITextView2.lua new file mode 100644 index 00000000..daa6ef31 --- /dev/null +++ b/IOS/Playground/Playground/test/testUITextView2.lua @@ -0,0 +1,48 @@ +--1. +view = Label() +view.text("测试1") +view.fontSize(30) +view.lineCount(2) +view.backgroundColor(0xaaaa0000) +view.frame(200, 200, 200, 200) + + +view2 = Label() +view2.text("测试2") +view2.fontSize(30) +view2.lineCount(2) +view2.backgroundColor(0xaaaa0000) +view2.frame(200, 500, 200, 200) + +view3 = Label() +view3.text("测试3测试3测试3测试3测试3测试3测试3测试3测试3") +view3.fontSize(30) +view3.lineCount(2) +view3.backgroundColor(0xaaaa0000) +view3.frame(200, 800, 200, 200) + +view4 = Label() +view4.text("测试4测试4测试4测试4测试4") +view4.fontSize(30) +view4.lineCount(1) +view4.backgroundColor(0xaaaa0000) +view4.frame(200, 1100, 200, 200) + +btn = Button() +btn.text("adjustFontSize") +btn.callback(function() + view.text(view.text() .. "测试1") + view.adjustFontSize() +end) + + +btn2 = Button() +btn2.xy(500, 0) +btn2.text("adjustSize") +btn2.callback(function() + view2.adjustSize() + view3.adjustSize() + view4.adjustSize() +end) + + diff --git a/IOS/Playground/Playground/test/testUIView.lua b/IOS/Playground/Playground/test/testUIView.lua new file mode 100644 index 00000000..69ef0c16 --- /dev/null +++ b/IOS/Playground/Playground/test/testUIView.lua @@ -0,0 +1,5 @@ +view = View() +view.frame(100, 100, 200, 300) +view.backgroundColor(0x44aa0000) +local x, y = view.center(); +Toast("中心点位置: " .. x .. "," .. y) \ No newline at end of file diff --git a/IOS/Playground/Playground/test/testViewPager.lua b/IOS/Playground/Playground/test/testViewPager.lua new file mode 100644 index 00000000..069205c1 --- /dev/null +++ b/IOS/Playground/Playground/test/testViewPager.lua @@ -0,0 +1,44 @@ +--工具包引入 +require "kit/lv_kit" + +local width, height = System.screenSize() + +local vp = PagerView({ + PageCount = 12, + Indicator = function() +-- 活动指示器 + local indicator = CirclePagerIndicator() + indicator.size(width / 2, 200) + indicator.pageColor(0xffff0000) + indicator.fillColor(0xff0000ff) + indicator.radius(10) + indicator.strokeWidth(4) + indicator.strokeColor(0xff00aaaa) + indicator.backgroundColor(0x33333333) + indicator.alignCenter() + return indicator + end, + Pages = { + Title = function(pos) + return "Title" + end, + Init = function(page, pos) + page.icon = Button() + end, + Layout = function(page, pos) + page.icon.text("测试按钮"..pos) + page.icon.frame(0, 0, width, 200) + end + }, + Callback = { + Scrolling=function(pos, percent, distance) + Toast("滑动"..pos) + end, + Selected=function(pos) + Toast("选中"..pos) + end + } +}) + +vp.backgroundColor(0xaaaa0000) +vp.frame(0, 20, width, height - 20) \ No newline at end of file diff --git a/IOS/Playground/Playground/test/testViewPagerIndicator.lua b/IOS/Playground/Playground/test/testViewPagerIndicator.lua new file mode 100644 index 00000000..07324c13 --- /dev/null +++ b/IOS/Playground/Playground/test/testViewPagerIndicator.lua @@ -0,0 +1,51 @@ +--工具包引入 +require "kit/lv_kit" + + +-- 活动指示器 +local SCREEN_WIDTH, SCREEN_HEGITH = window.size() + +indicator = nil; + +function createSelfDefinedIndicator() + indicator = PagerIndicator() + indicator.size(SCREEN_WIDTH/2, 200) + indicator.backgroundColor(0x33333333) + indicator.alignCenter() + return indicator +end + +pagerView = PagerView({ + PageCount = 12, + Indicator = function() + return createSelfDefinedIndicator() + end, + Pages = { + Title = function(pos) + return "Title" + end, + Init = function(page, pos) + page.icon = Button() + end, + Layout = function(page, pos) + page.icon.text("测试按钮"..pos) + page.icon.frame(0, 0, SCREEN_WIDTH, 200) + end + }, + Callback = { + Scrolling=function(pos, percent, distance) + Toast("滑动"..pos) + end + } +}) + +pagerView.frame(0,0,SCREEN_WIDTH, SCREEN_HEGITH); + + +button = Button(); +button.backgroundColor(0xff); +button.title("测试"); +button.frame(0,300,100,100); +button.callback(function() + indicator.currentPage(3); +end); \ No newline at end of file diff --git a/IOS/Playground/Podfile b/IOS/Playground/Podfile new file mode 100644 index 00000000..249b4abb --- /dev/null +++ b/IOS/Playground/Podfile @@ -0,0 +1,9 @@ +# Uncomment this line to define a global platform for your project + +platform :ios, "8.0" + +target 'Demo' do + pod 'LuaViewSDK', :path => '../../' + pod 'luaviewEx', :path => '../luaviewEx' +end + diff --git a/IOS/Playground/Podfile.lock b/IOS/Playground/Podfile.lock new file mode 100644 index 00000000..24f6cec2 --- /dev/null +++ b/IOS/Playground/Podfile.lock @@ -0,0 +1,28 @@ +PODS: + - luaviewEx (0.1.0): + - LuaViewSDK + - MJRefresh + - SDWebImage (~> 3.7.5) + - LuaViewSDK (0.5.0) + - MJRefresh (3.1.12) + - SDWebImage (3.7.6): + - SDWebImage/Core (= 3.7.6) + - SDWebImage/Core (3.7.6) + +DEPENDENCIES: + - luaviewEx (from `../luaviewEx`) + - LuaViewSDK (from `../../`) + +EXTERNAL SOURCES: + luaviewEx: + :path: ../luaviewEx + LuaViewSDK: + :path: ../../ + +SPEC CHECKSUMS: + luaviewEx: a5e511e0e83280315ebff29f8bdc2c2cc7fb466b + LuaViewSDK: 04f40a2b25e485669ca03ae93fd45f8a145164ce + MJRefresh: 11e1c9d86f2093ddcdbda7836bc2da477ddf568d + SDWebImage: 485df4197e8008e0a23d95854d6a73050b9ddc3c + +COCOAPODS: 0.39.0 diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/JUFLXCSSParser.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/JUFLXCSSParser.h new file mode 120000 index 00000000..e17ad976 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/JUFLXCSSParser.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/layout/JUFLXCSSParser.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/JUFLXLayoutDefine.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/JUFLXLayoutDefine.h new file mode 120000 index 00000000..c2375856 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/JUFLXLayoutDefine.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/layout/JUFLXLayoutDefine.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/JUFLXLayoutKit.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/JUFLXLayoutKit.h new file mode 120000 index 00000000..7c18c0fc --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/JUFLXLayoutKit.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/layout/JUFLXLayoutKit.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/JUFLXLinearLayoutView.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/JUFLXLinearLayoutView.h new file mode 120000 index 00000000..87e746c9 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/JUFLXLinearLayoutView.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/layout/LayoutExtensions/JUFLXLinearLayoutView.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/JUFLXNode.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/JUFLXNode.h new file mode 120000 index 00000000..7b840ff0 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/JUFLXNode.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/layout/JUFLXNode.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/JUFLXTargeNamespace.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/JUFLXTargeNamespace.h new file mode 120000 index 00000000..78db51b9 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/JUFLXTargeNamespace.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/layout/JUFLXTargeNamespace.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVAlert.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVAlert.h new file mode 120000 index 00000000..8f1ae5bd --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVAlert.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVAlert.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVAnimate.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVAnimate.h new file mode 120000 index 00000000..237f4b04 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVAnimate.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVAnimate.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVAnimator.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVAnimator.h new file mode 120000 index 00000000..bc887639 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVAnimator.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVAnimator.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVAudioPlayer.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVAudioPlayer.h new file mode 120000 index 00000000..3ffac7bd --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVAudioPlayer.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVAudioPlayer.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVBaseView.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVBaseView.h new file mode 120000 index 00000000..128d1ff9 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVBaseView.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVBaseView.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVBlock.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVBlock.h new file mode 120000 index 00000000..b5b0d1ff --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVBlock.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/LVBlock.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVBundle.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVBundle.h new file mode 120000 index 00000000..ec12604f --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVBundle.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/LVBundle.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVButton.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVButton.h new file mode 120000 index 00000000..64acf490 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVButton.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVButton.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVCanvas.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVCanvas.h new file mode 120000 index 00000000..7e0720be --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVCanvas.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVCanvas.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVClassInfo.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVClassInfo.h new file mode 120000 index 00000000..96a071c5 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVClassInfo.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVClassInfo.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVCollectionView.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVCollectionView.h new file mode 120000 index 00000000..cde10d90 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVCollectionView.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVCollectionView.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVCollectionViewCell.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVCollectionViewCell.h new file mode 120000 index 00000000..3374f0d6 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVCollectionViewCell.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVCollectionViewCell.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVCollectionViewDelegate.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVCollectionViewDelegate.h new file mode 120000 index 00000000..f455dd7e --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVCollectionViewDelegate.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVCollectionViewDelegate.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVCustomPanel.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVCustomPanel.h new file mode 120000 index 00000000..788f12dd --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVCustomPanel.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVCustomPanel.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVCustomView.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVCustomView.h new file mode 120000 index 00000000..f13a1e1f --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVCustomView.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVCustomView.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVDB.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVDB.h new file mode 120000 index 00000000..ca87a670 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVDB.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVDB.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVData.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVData.h new file mode 120000 index 00000000..cdb7c8cc --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVData.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVData.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVDate.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVDate.h new file mode 120000 index 00000000..428f8338 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVDate.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVDate.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVDebugConnection.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVDebugConnection.h new file mode 120000 index 00000000..71f21d7d --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVDebugConnection.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvdebug/LVDebugConnection.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVDebuger.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVDebuger.h new file mode 120000 index 00000000..34378826 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVDebuger.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvdebug/LVDebuger.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVDownloader.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVDownloader.h new file mode 120000 index 00000000..781edfe0 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVDownloader.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVDownloader.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVEmptyRefreshCollectionView.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVEmptyRefreshCollectionView.h new file mode 120000 index 00000000..3cda83b8 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVEmptyRefreshCollectionView.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVEmptyRefreshCollectionView.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVEvent.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVEvent.h new file mode 120000 index 00000000..2a7b48a6 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVEvent.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVEvent.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVExGlobalFunc.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVExGlobalFunc.h new file mode 120000 index 00000000..57a84c3a --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVExGlobalFunc.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVExGlobalFunc.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVFile.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVFile.h new file mode 120000 index 00000000..4769d1fe --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVFile.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVFile.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVFlowLayout.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVFlowLayout.h new file mode 120000 index 00000000..dba95247 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVFlowLayout.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVFlowLayout.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVGesture.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVGesture.h new file mode 120000 index 00000000..fb4e3432 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVGesture.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVGesture.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVGrammarChanger.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVGrammarChanger.h new file mode 120000 index 00000000..0fd019e5 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVGrammarChanger.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVGrammarChanger.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVHeads.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVHeads.h new file mode 120000 index 00000000..f45881a6 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVHeads.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVHeads.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVHttp.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVHttp.h new file mode 120000 index 00000000..473b354b --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVHttp.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVHttp.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVHttpResponse.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVHttpResponse.h new file mode 120000 index 00000000..e59408dc --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVHttpResponse.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVHttpResponse.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVImage.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVImage.h new file mode 120000 index 00000000..2351d7bd --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVImage.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVImage.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVLabel.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVLabel.h new file mode 120000 index 00000000..62285209 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVLabel.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVLabel.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVLoadingIndicator.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVLoadingIndicator.h new file mode 120000 index 00000000..7ba1b20d --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVLoadingIndicator.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVLoadingIndicator.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVLongPressGesture.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVLongPressGesture.h new file mode 120000 index 00000000..a28ae9e1 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVLongPressGesture.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVLongPressGesture.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVLuaObjBox.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVLuaObjBox.h new file mode 120000 index 00000000..7105b644 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVLuaObjBox.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVLuaObjBox.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVMethod.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVMethod.h new file mode 120000 index 00000000..e67fd503 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVMethod.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVMethod.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVNativeObjBox.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVNativeObjBox.h new file mode 120000 index 00000000..e0aac498 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVNativeObjBox.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVNativeObjBox.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVNavigation.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVNavigation.h new file mode 120000 index 00000000..9dbeb8c1 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVNavigation.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVNavigation.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVNetworkStatus.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVNetworkStatus.h new file mode 120000 index 00000000..7132949b --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVNetworkStatus.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVNetworkStatus.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVNinePatchImage.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVNinePatchImage.h new file mode 120000 index 00000000..173534a8 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVNinePatchImage.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVNinePatchImage.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVPagerIndicator.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVPagerIndicator.h new file mode 120000 index 00000000..ef7403ef --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVPagerIndicator.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVPagerIndicator.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVPagerView.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVPagerView.h new file mode 120000 index 00000000..ff6eb156 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVPagerView.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVPagerView.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVPagerViewCell.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVPagerViewCell.h new file mode 120000 index 00000000..dd56fabf --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVPagerViewCell.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVPagerViewCell.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVPanGesture.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVPanGesture.h new file mode 120000 index 00000000..3660ca35 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVPanGesture.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVPanGesture.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVPinchGesture.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVPinchGesture.h new file mode 120000 index 00000000..99958fa3 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVPinchGesture.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVPinchGesture.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVPkgInfo.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVPkgInfo.h new file mode 120000 index 00000000..32c06367 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVPkgInfo.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/PKG/LVPkgInfo.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVPkgManager.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVPkgManager.h new file mode 120000 index 00000000..9a11307f --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVPkgManager.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/PKG/LVPkgManager.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVPointerValueBox.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVPointerValueBox.h new file mode 120000 index 00000000..f9875a02 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVPointerValueBox.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVPointerValueBox.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVRSA.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVRSA.h new file mode 120000 index 00000000..edb56813 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVRSA.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/RSA/LVRSA.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVRefreshComponent.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVRefreshComponent.h new file mode 120000 index 00000000..686fc8db --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVRefreshComponent.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVRefreshComponent.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVRefreshConst.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVRefreshConst.h new file mode 120000 index 00000000..dec673e1 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVRefreshConst.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVRefreshConst.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVRefreshHeader.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVRefreshHeader.h new file mode 120000 index 00000000..61564a99 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVRefreshHeader.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVRefreshHeader.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVRotationGesture.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVRotationGesture.h new file mode 120000 index 00000000..bd9ee09b --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVRotationGesture.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVRotationGesture.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVScrollView.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVScrollView.h new file mode 120000 index 00000000..de1ff645 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVScrollView.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVScrollView.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVScrollViewDelegate.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVScrollViewDelegate.h new file mode 120000 index 00000000..67e59fbf --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVScrollViewDelegate.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVScrollViewDelegate.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVStruct.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVStruct.h new file mode 120000 index 00000000..d8e823f5 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVStruct.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVStruct.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVStyledString.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVStyledString.h new file mode 120000 index 00000000..6c968184 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVStyledString.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVStyledString.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVSwipeGesture.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVSwipeGesture.h new file mode 120000 index 00000000..e23b73d2 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVSwipeGesture.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVSwipeGesture.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVSystem.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVSystem.h new file mode 120000 index 00000000..651e2ff5 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVSystem.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVSystem.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVTapGesture.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVTapGesture.h new file mode 120000 index 00000000..d93376d5 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVTapGesture.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVTapGesture.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVTextField.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVTextField.h new file mode 120000 index 00000000..f6b9265d --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVTextField.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVTextField.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVTimer.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVTimer.h new file mode 120000 index 00000000..43ef6166 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVTimer.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVTimer.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVToast.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVToast.h new file mode 120000 index 00000000..2de07ea9 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVToast.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVToast.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVTransform3D.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVTransform3D.h new file mode 120000 index 00000000..eaacf285 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVTransform3D.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVTransform3D.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVTypeConvert.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVTypeConvert.h new file mode 120000 index 00000000..bfacee74 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVTypeConvert.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVTypeConvert.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVUtil.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVUtil.h new file mode 120000 index 00000000..1f2ec0b4 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVUtil.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVUtil.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVWebView.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVWebView.h new file mode 120000 index 00000000..aa1d7675 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVWebView.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVWebView.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVZipArchive.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVZipArchive.h new file mode 120000 index 00000000..8f1122ea --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LVZipArchive.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/PKG/LVZipArchive.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LView.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LView.h new file mode 120000 index 00000000..9d7bbad2 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LView.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/LView.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LViewController.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LViewController.h new file mode 120000 index 00000000..75ee9c1f --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LViewController.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/LViewController.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/Layout.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/Layout.h new file mode 120000 index 00000000..7661f0a4 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/Layout.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/layout/Layout.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LuaView.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LuaView.h new file mode 120000 index 00000000..0b4ecc84 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LuaView.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/LuaView.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LuaViewCore.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LuaViewCore.h new file mode 120000 index 00000000..cb6eabee --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/LuaViewCore.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/LuaViewCore.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/NSObject+LuaView.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/NSObject+LuaView.h new file mode 120000 index 00000000..6350fab4 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/NSObject+LuaView.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/NSObject+LuaView.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/UIScrollView+LVRefresh.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/UIScrollView+LVRefresh.h new file mode 120000 index 00000000..65b36da9 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/UIScrollView+LVRefresh.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/UIScrollView+LVRefresh.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/UIScrollView+LuaView.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/UIScrollView+LuaView.h new file mode 120000 index 00000000..93b2060b --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/UIScrollView+LuaView.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/UIScrollView+LuaView.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/UIView+JUFLXNode.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/UIView+JUFLXNode.h new file mode 120000 index 00000000..241b2a67 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/UIView+JUFLXNode.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/layout/UIView+JUFLXNode.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/UIView+LuaView.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/UIView+LuaView.h new file mode 120000 index 00000000..760461e3 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/UIView+LuaView.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/UIView+LuaView.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/lapi.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/lapi.h new file mode 120000 index 00000000..4083678e --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/lapi.h @@ -0,0 +1 @@ +../../../../../lua/lua/lapi.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/lauxlib.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/lauxlib.h new file mode 120000 index 00000000..4ce76453 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/lauxlib.h @@ -0,0 +1 @@ +../../../../../lua/lua/lauxlib.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/lcode.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/lcode.h new file mode 120000 index 00000000..1ce67879 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/lcode.h @@ -0,0 +1 @@ +../../../../../lua/lua/lcode.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/ldebug.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/ldebug.h new file mode 120000 index 00000000..7d1e851d --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/ldebug.h @@ -0,0 +1 @@ +../../../../../lua/lua/ldebug.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/ldo.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/ldo.h new file mode 120000 index 00000000..c06b3ef8 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/ldo.h @@ -0,0 +1 @@ +../../../../../lua/lua/ldo.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/lfunc.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/lfunc.h new file mode 120000 index 00000000..0a5672db --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/lfunc.h @@ -0,0 +1 @@ +../../../../../lua/lua/lfunc.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/lgc.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/lgc.h new file mode 120000 index 00000000..6999a7ba --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/lgc.h @@ -0,0 +1 @@ +../../../../../lua/lua/lgc.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/llex.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/llex.h new file mode 120000 index 00000000..442bf396 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/llex.h @@ -0,0 +1 @@ +../../../../../lua/lua/llex.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/llimits.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/llimits.h new file mode 120000 index 00000000..929aaf7b --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/llimits.h @@ -0,0 +1 @@ +../../../../../lua/lua/llimits.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/lmem.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/lmem.h new file mode 120000 index 00000000..256168b3 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/lmem.h @@ -0,0 +1 @@ +../../../../../lua/lua/lmem.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/lobject.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/lobject.h new file mode 120000 index 00000000..8442f4d6 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/lobject.h @@ -0,0 +1 @@ +../../../../../lua/lua/lobject.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/lopcodes.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/lopcodes.h new file mode 120000 index 00000000..3e7619ab --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/lopcodes.h @@ -0,0 +1 @@ +../../../../../lua/lua/lopcodes.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/lparser.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/lparser.h new file mode 120000 index 00000000..85c9ecb7 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/lparser.h @@ -0,0 +1 @@ +../../../../../lua/lua/lparser.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/lstate.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/lstate.h new file mode 120000 index 00000000..81ded74d --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/lstate.h @@ -0,0 +1 @@ +../../../../../lua/lua/lstate.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/lstring.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/lstring.h new file mode 120000 index 00000000..e72bf060 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/lstring.h @@ -0,0 +1 @@ +../../../../../lua/lua/lstring.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/ltable.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/ltable.h new file mode 120000 index 00000000..645ce75d --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/ltable.h @@ -0,0 +1 @@ +../../../../../lua/lua/ltable.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/ltm.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/ltm.h new file mode 120000 index 00000000..7a360f05 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/ltm.h @@ -0,0 +1 @@ +../../../../../lua/lua/ltm.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/lua.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/lua.h new file mode 120000 index 00000000..ed4c0152 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/lua.h @@ -0,0 +1 @@ +../../../../../lua/lua/lua.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/luaconf.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/luaconf.h new file mode 120000 index 00000000..5746f909 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/luaconf.h @@ -0,0 +1 @@ +../../../../../lua/lua/luaconf.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/lualib.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/lualib.h new file mode 120000 index 00000000..f6cfe2d7 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/lualib.h @@ -0,0 +1 @@ +../../../../../lua/lua/lualib.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/lundump.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/lundump.h new file mode 120000 index 00000000..195260e0 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/lundump.h @@ -0,0 +1 @@ +../../../../../lua/lua/lundump.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/lvm.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/lvm.h new file mode 120000 index 00000000..0fb76f04 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/lvm.h @@ -0,0 +1 @@ +../../../../../lua/lua/lvm.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/LuaViewSDK/lzio.h b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/lzio.h new file mode 120000 index 00000000..86be10b0 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/LuaViewSDK/lzio.h @@ -0,0 +1 @@ +../../../../../lua/lua/lzio.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/MJRefresh/MJRefresh.h b/IOS/Playground/Pods/Headers/Private/MJRefresh/MJRefresh.h new file mode 120000 index 00000000..d83fdd64 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/MJRefresh/MJRefresh.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/MJRefresh.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/MJRefresh/MJRefreshAutoFooter.h b/IOS/Playground/Pods/Headers/Private/MJRefresh/MJRefreshAutoFooter.h new file mode 120000 index 00000000..5bb1fbc5 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/MJRefresh/MJRefreshAutoFooter.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/Base/MJRefreshAutoFooter.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/MJRefresh/MJRefreshAutoGifFooter.h b/IOS/Playground/Pods/Headers/Private/MJRefresh/MJRefreshAutoGifFooter.h new file mode 120000 index 00000000..1435437b --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/MJRefresh/MJRefreshAutoGifFooter.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/Custom/Footer/Auto/MJRefreshAutoGifFooter.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/MJRefresh/MJRefreshAutoNormalFooter.h b/IOS/Playground/Pods/Headers/Private/MJRefresh/MJRefreshAutoNormalFooter.h new file mode 120000 index 00000000..6b87abe4 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/MJRefresh/MJRefreshAutoNormalFooter.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/Custom/Footer/Auto/MJRefreshAutoNormalFooter.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/MJRefresh/MJRefreshAutoStateFooter.h b/IOS/Playground/Pods/Headers/Private/MJRefresh/MJRefreshAutoStateFooter.h new file mode 120000 index 00000000..19b2053a --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/MJRefresh/MJRefreshAutoStateFooter.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/Custom/Footer/Auto/MJRefreshAutoStateFooter.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/MJRefresh/MJRefreshBackFooter.h b/IOS/Playground/Pods/Headers/Private/MJRefresh/MJRefreshBackFooter.h new file mode 120000 index 00000000..3df4973f --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/MJRefresh/MJRefreshBackFooter.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/Base/MJRefreshBackFooter.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/MJRefresh/MJRefreshBackGifFooter.h b/IOS/Playground/Pods/Headers/Private/MJRefresh/MJRefreshBackGifFooter.h new file mode 120000 index 00000000..e5d5f96d --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/MJRefresh/MJRefreshBackGifFooter.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/Custom/Footer/Back/MJRefreshBackGifFooter.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/MJRefresh/MJRefreshBackNormalFooter.h b/IOS/Playground/Pods/Headers/Private/MJRefresh/MJRefreshBackNormalFooter.h new file mode 120000 index 00000000..c578c7f5 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/MJRefresh/MJRefreshBackNormalFooter.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/Custom/Footer/Back/MJRefreshBackNormalFooter.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/MJRefresh/MJRefreshBackStateFooter.h b/IOS/Playground/Pods/Headers/Private/MJRefresh/MJRefreshBackStateFooter.h new file mode 120000 index 00000000..3317188d --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/MJRefresh/MJRefreshBackStateFooter.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/Custom/Footer/Back/MJRefreshBackStateFooter.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/MJRefresh/MJRefreshComponent.h b/IOS/Playground/Pods/Headers/Private/MJRefresh/MJRefreshComponent.h new file mode 120000 index 00000000..35cb1b14 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/MJRefresh/MJRefreshComponent.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/Base/MJRefreshComponent.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/MJRefresh/MJRefreshConst.h b/IOS/Playground/Pods/Headers/Private/MJRefresh/MJRefreshConst.h new file mode 120000 index 00000000..035954b9 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/MJRefresh/MJRefreshConst.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/MJRefreshConst.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/MJRefresh/MJRefreshFooter.h b/IOS/Playground/Pods/Headers/Private/MJRefresh/MJRefreshFooter.h new file mode 120000 index 00000000..743dda22 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/MJRefresh/MJRefreshFooter.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/Base/MJRefreshFooter.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/MJRefresh/MJRefreshGifHeader.h b/IOS/Playground/Pods/Headers/Private/MJRefresh/MJRefreshGifHeader.h new file mode 120000 index 00000000..aa6afbd0 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/MJRefresh/MJRefreshGifHeader.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/Custom/Header/MJRefreshGifHeader.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/MJRefresh/MJRefreshHeader.h b/IOS/Playground/Pods/Headers/Private/MJRefresh/MJRefreshHeader.h new file mode 120000 index 00000000..3a38b267 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/MJRefresh/MJRefreshHeader.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/Base/MJRefreshHeader.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/MJRefresh/MJRefreshNormalHeader.h b/IOS/Playground/Pods/Headers/Private/MJRefresh/MJRefreshNormalHeader.h new file mode 120000 index 00000000..b5cc1640 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/MJRefresh/MJRefreshNormalHeader.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/Custom/Header/MJRefreshNormalHeader.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/MJRefresh/MJRefreshStateHeader.h b/IOS/Playground/Pods/Headers/Private/MJRefresh/MJRefreshStateHeader.h new file mode 120000 index 00000000..7bd25cf7 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/MJRefresh/MJRefreshStateHeader.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/Custom/Header/MJRefreshStateHeader.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/MJRefresh/NSBundle+MJRefresh.h b/IOS/Playground/Pods/Headers/Private/MJRefresh/NSBundle+MJRefresh.h new file mode 120000 index 00000000..2a628b44 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/MJRefresh/NSBundle+MJRefresh.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/NSBundle+MJRefresh.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/MJRefresh/UIScrollView+MJExtension.h b/IOS/Playground/Pods/Headers/Private/MJRefresh/UIScrollView+MJExtension.h new file mode 120000 index 00000000..1919784b --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/MJRefresh/UIScrollView+MJExtension.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/UIScrollView+MJExtension.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/MJRefresh/UIScrollView+MJRefresh.h b/IOS/Playground/Pods/Headers/Private/MJRefresh/UIScrollView+MJRefresh.h new file mode 120000 index 00000000..47b703d5 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/MJRefresh/UIScrollView+MJRefresh.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/UIScrollView+MJRefresh.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/MJRefresh/UIView+MJExtension.h b/IOS/Playground/Pods/Headers/Private/MJRefresh/UIView+MJExtension.h new file mode 120000 index 00000000..5f198134 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/MJRefresh/UIView+MJExtension.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/UIView+MJExtension.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/SDWebImage/NSData+ImageContentType.h b/IOS/Playground/Pods/Headers/Private/SDWebImage/NSData+ImageContentType.h new file mode 120000 index 00000000..84574987 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/SDWebImage/NSData+ImageContentType.h @@ -0,0 +1 @@ +../../../SDWebImage/SDWebImage/NSData+ImageContentType.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/SDWebImage/SDImageCache.h b/IOS/Playground/Pods/Headers/Private/SDWebImage/SDImageCache.h new file mode 120000 index 00000000..0040b06a --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/SDWebImage/SDImageCache.h @@ -0,0 +1 @@ +../../../SDWebImage/SDWebImage/SDImageCache.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/SDWebImage/SDWebImageCompat.h b/IOS/Playground/Pods/Headers/Private/SDWebImage/SDWebImageCompat.h new file mode 120000 index 00000000..6ca24784 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/SDWebImage/SDWebImageCompat.h @@ -0,0 +1 @@ +../../../SDWebImage/SDWebImage/SDWebImageCompat.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/SDWebImage/SDWebImageDecoder.h b/IOS/Playground/Pods/Headers/Private/SDWebImage/SDWebImageDecoder.h new file mode 120000 index 00000000..a2f3a683 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/SDWebImage/SDWebImageDecoder.h @@ -0,0 +1 @@ +../../../SDWebImage/SDWebImage/SDWebImageDecoder.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/SDWebImage/SDWebImageDownloader.h b/IOS/Playground/Pods/Headers/Private/SDWebImage/SDWebImageDownloader.h new file mode 120000 index 00000000..303b03b1 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/SDWebImage/SDWebImageDownloader.h @@ -0,0 +1 @@ +../../../SDWebImage/SDWebImage/SDWebImageDownloader.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/SDWebImage/SDWebImageDownloaderOperation.h b/IOS/Playground/Pods/Headers/Private/SDWebImage/SDWebImageDownloaderOperation.h new file mode 120000 index 00000000..99441c48 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/SDWebImage/SDWebImageDownloaderOperation.h @@ -0,0 +1 @@ +../../../SDWebImage/SDWebImage/SDWebImageDownloaderOperation.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/SDWebImage/SDWebImageManager.h b/IOS/Playground/Pods/Headers/Private/SDWebImage/SDWebImageManager.h new file mode 120000 index 00000000..1b818485 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/SDWebImage/SDWebImageManager.h @@ -0,0 +1 @@ +../../../SDWebImage/SDWebImage/SDWebImageManager.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/SDWebImage/SDWebImageOperation.h b/IOS/Playground/Pods/Headers/Private/SDWebImage/SDWebImageOperation.h new file mode 120000 index 00000000..20e5b89e --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/SDWebImage/SDWebImageOperation.h @@ -0,0 +1 @@ +../../../SDWebImage/SDWebImage/SDWebImageOperation.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/SDWebImage/SDWebImagePrefetcher.h b/IOS/Playground/Pods/Headers/Private/SDWebImage/SDWebImagePrefetcher.h new file mode 120000 index 00000000..50585c6d --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/SDWebImage/SDWebImagePrefetcher.h @@ -0,0 +1 @@ +../../../SDWebImage/SDWebImage/SDWebImagePrefetcher.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/SDWebImage/UIButton+WebCache.h b/IOS/Playground/Pods/Headers/Private/SDWebImage/UIButton+WebCache.h new file mode 120000 index 00000000..19d2d8e8 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/SDWebImage/UIButton+WebCache.h @@ -0,0 +1 @@ +../../../SDWebImage/SDWebImage/UIButton+WebCache.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/SDWebImage/UIImage+GIF.h b/IOS/Playground/Pods/Headers/Private/SDWebImage/UIImage+GIF.h new file mode 120000 index 00000000..14d5aadd --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/SDWebImage/UIImage+GIF.h @@ -0,0 +1 @@ +../../../SDWebImage/SDWebImage/UIImage+GIF.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/SDWebImage/UIImage+MultiFormat.h b/IOS/Playground/Pods/Headers/Private/SDWebImage/UIImage+MultiFormat.h new file mode 120000 index 00000000..1fb96501 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/SDWebImage/UIImage+MultiFormat.h @@ -0,0 +1 @@ +../../../SDWebImage/SDWebImage/UIImage+MultiFormat.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/SDWebImage/UIImageView+HighlightedWebCache.h b/IOS/Playground/Pods/Headers/Private/SDWebImage/UIImageView+HighlightedWebCache.h new file mode 120000 index 00000000..fd4dea41 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/SDWebImage/UIImageView+HighlightedWebCache.h @@ -0,0 +1 @@ +../../../SDWebImage/SDWebImage/UIImageView+HighlightedWebCache.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/SDWebImage/UIImageView+WebCache.h b/IOS/Playground/Pods/Headers/Private/SDWebImage/UIImageView+WebCache.h new file mode 120000 index 00000000..0c53a47b --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/SDWebImage/UIImageView+WebCache.h @@ -0,0 +1 @@ +../../../SDWebImage/SDWebImage/UIImageView+WebCache.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/SDWebImage/UIView+WebCacheOperation.h b/IOS/Playground/Pods/Headers/Private/SDWebImage/UIView+WebCacheOperation.h new file mode 120000 index 00000000..f9890c40 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/SDWebImage/UIView+WebCacheOperation.h @@ -0,0 +1 @@ +../../../SDWebImage/SDWebImage/UIView+WebCacheOperation.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/luaviewEx/LVExButton.h b/IOS/Playground/Pods/Headers/Private/luaviewEx/LVExButton.h new file mode 120000 index 00000000..af730472 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/luaviewEx/LVExButton.h @@ -0,0 +1 @@ +../../../../../luaviewEx/luaviewEx/Classes/LVExButton.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/luaviewEx/LVExCollectionView.h b/IOS/Playground/Pods/Headers/Private/luaviewEx/LVExCollectionView.h new file mode 120000 index 00000000..6e191207 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/luaviewEx/LVExCollectionView.h @@ -0,0 +1 @@ +../../../../../luaviewEx/luaviewEx/Classes/LVExCollectionView.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/luaviewEx/LVExImage.h b/IOS/Playground/Pods/Headers/Private/luaviewEx/LVExImage.h new file mode 120000 index 00000000..0e69df68 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/luaviewEx/LVExImage.h @@ -0,0 +1 @@ +../../../../../luaviewEx/luaviewEx/Classes/LVExImage.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Private/luaviewEx/LVViewController.h b/IOS/Playground/Pods/Headers/Private/luaviewEx/LVViewController.h new file mode 120000 index 00000000..9b3f6fe6 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Private/luaviewEx/LVViewController.h @@ -0,0 +1 @@ +../../../../../luaviewEx/luaviewEx/Classes/LVViewController.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/JUFLXCSSParser.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/JUFLXCSSParser.h new file mode 120000 index 00000000..e17ad976 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/JUFLXCSSParser.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/layout/JUFLXCSSParser.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/JUFLXLayoutDefine.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/JUFLXLayoutDefine.h new file mode 120000 index 00000000..c2375856 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/JUFLXLayoutDefine.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/layout/JUFLXLayoutDefine.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/JUFLXLayoutKit.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/JUFLXLayoutKit.h new file mode 120000 index 00000000..7c18c0fc --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/JUFLXLayoutKit.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/layout/JUFLXLayoutKit.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/JUFLXLinearLayoutView.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/JUFLXLinearLayoutView.h new file mode 120000 index 00000000..87e746c9 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/JUFLXLinearLayoutView.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/layout/LayoutExtensions/JUFLXLinearLayoutView.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/JUFLXNode.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/JUFLXNode.h new file mode 120000 index 00000000..7b840ff0 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/JUFLXNode.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/layout/JUFLXNode.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/JUFLXTargeNamespace.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/JUFLXTargeNamespace.h new file mode 120000 index 00000000..78db51b9 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/JUFLXTargeNamespace.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/layout/JUFLXTargeNamespace.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVAlert.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVAlert.h new file mode 120000 index 00000000..8f1ae5bd --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVAlert.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVAlert.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVAnimate.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVAnimate.h new file mode 120000 index 00000000..237f4b04 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVAnimate.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVAnimate.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVAnimator.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVAnimator.h new file mode 120000 index 00000000..bc887639 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVAnimator.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVAnimator.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVAudioPlayer.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVAudioPlayer.h new file mode 120000 index 00000000..3ffac7bd --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVAudioPlayer.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVAudioPlayer.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVBaseView.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVBaseView.h new file mode 120000 index 00000000..128d1ff9 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVBaseView.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVBaseView.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVBlock.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVBlock.h new file mode 120000 index 00000000..b5b0d1ff --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVBlock.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/LVBlock.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVBundle.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVBundle.h new file mode 120000 index 00000000..ec12604f --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVBundle.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/LVBundle.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVButton.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVButton.h new file mode 120000 index 00000000..64acf490 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVButton.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVButton.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVCanvas.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVCanvas.h new file mode 120000 index 00000000..7e0720be --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVCanvas.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVCanvas.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVClassInfo.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVClassInfo.h new file mode 120000 index 00000000..96a071c5 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVClassInfo.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVClassInfo.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVCollectionView.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVCollectionView.h new file mode 120000 index 00000000..cde10d90 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVCollectionView.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVCollectionView.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVCollectionViewCell.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVCollectionViewCell.h new file mode 120000 index 00000000..3374f0d6 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVCollectionViewCell.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVCollectionViewCell.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVCollectionViewDelegate.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVCollectionViewDelegate.h new file mode 120000 index 00000000..f455dd7e --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVCollectionViewDelegate.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVCollectionViewDelegate.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVCustomPanel.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVCustomPanel.h new file mode 120000 index 00000000..788f12dd --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVCustomPanel.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVCustomPanel.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVCustomView.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVCustomView.h new file mode 120000 index 00000000..f13a1e1f --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVCustomView.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVCustomView.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVDB.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVDB.h new file mode 120000 index 00000000..ca87a670 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVDB.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVDB.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVData.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVData.h new file mode 120000 index 00000000..cdb7c8cc --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVData.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVData.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVDate.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVDate.h new file mode 120000 index 00000000..428f8338 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVDate.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVDate.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVDebugConnection.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVDebugConnection.h new file mode 120000 index 00000000..71f21d7d --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVDebugConnection.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvdebug/LVDebugConnection.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVDebuger.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVDebuger.h new file mode 120000 index 00000000..34378826 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVDebuger.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvdebug/LVDebuger.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVDownloader.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVDownloader.h new file mode 120000 index 00000000..781edfe0 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVDownloader.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVDownloader.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVEmptyRefreshCollectionView.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVEmptyRefreshCollectionView.h new file mode 120000 index 00000000..3cda83b8 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVEmptyRefreshCollectionView.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVEmptyRefreshCollectionView.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVEvent.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVEvent.h new file mode 120000 index 00000000..2a7b48a6 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVEvent.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVEvent.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVExGlobalFunc.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVExGlobalFunc.h new file mode 120000 index 00000000..57a84c3a --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVExGlobalFunc.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVExGlobalFunc.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVFile.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVFile.h new file mode 120000 index 00000000..4769d1fe --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVFile.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVFile.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVFlowLayout.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVFlowLayout.h new file mode 120000 index 00000000..dba95247 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVFlowLayout.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVFlowLayout.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVGesture.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVGesture.h new file mode 120000 index 00000000..fb4e3432 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVGesture.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVGesture.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVGrammarChanger.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVGrammarChanger.h new file mode 120000 index 00000000..0fd019e5 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVGrammarChanger.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVGrammarChanger.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVHeads.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVHeads.h new file mode 120000 index 00000000..f45881a6 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVHeads.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVHeads.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVHttp.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVHttp.h new file mode 120000 index 00000000..473b354b --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVHttp.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVHttp.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVHttpResponse.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVHttpResponse.h new file mode 120000 index 00000000..e59408dc --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVHttpResponse.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVHttpResponse.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVImage.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVImage.h new file mode 120000 index 00000000..2351d7bd --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVImage.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVImage.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVLabel.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVLabel.h new file mode 120000 index 00000000..62285209 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVLabel.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVLabel.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVLoadingIndicator.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVLoadingIndicator.h new file mode 120000 index 00000000..7ba1b20d --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVLoadingIndicator.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVLoadingIndicator.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVLongPressGesture.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVLongPressGesture.h new file mode 120000 index 00000000..a28ae9e1 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVLongPressGesture.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVLongPressGesture.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVLuaObjBox.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVLuaObjBox.h new file mode 120000 index 00000000..7105b644 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVLuaObjBox.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVLuaObjBox.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVMethod.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVMethod.h new file mode 120000 index 00000000..e67fd503 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVMethod.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVMethod.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVNativeObjBox.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVNativeObjBox.h new file mode 120000 index 00000000..e0aac498 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVNativeObjBox.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVNativeObjBox.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVNavigation.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVNavigation.h new file mode 120000 index 00000000..9dbeb8c1 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVNavigation.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVNavigation.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVNetworkStatus.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVNetworkStatus.h new file mode 120000 index 00000000..7132949b --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVNetworkStatus.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVNetworkStatus.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVNinePatchImage.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVNinePatchImage.h new file mode 120000 index 00000000..173534a8 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVNinePatchImage.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVNinePatchImage.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVPagerIndicator.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVPagerIndicator.h new file mode 120000 index 00000000..ef7403ef --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVPagerIndicator.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVPagerIndicator.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVPagerView.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVPagerView.h new file mode 120000 index 00000000..ff6eb156 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVPagerView.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVPagerView.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVPagerViewCell.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVPagerViewCell.h new file mode 120000 index 00000000..dd56fabf --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVPagerViewCell.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVPagerViewCell.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVPanGesture.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVPanGesture.h new file mode 120000 index 00000000..3660ca35 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVPanGesture.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVPanGesture.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVPinchGesture.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVPinchGesture.h new file mode 120000 index 00000000..99958fa3 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVPinchGesture.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVPinchGesture.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVPkgInfo.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVPkgInfo.h new file mode 120000 index 00000000..32c06367 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVPkgInfo.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/PKG/LVPkgInfo.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVPkgManager.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVPkgManager.h new file mode 120000 index 00000000..9a11307f --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVPkgManager.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/PKG/LVPkgManager.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVPointerValueBox.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVPointerValueBox.h new file mode 120000 index 00000000..f9875a02 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVPointerValueBox.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVPointerValueBox.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVRSA.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVRSA.h new file mode 120000 index 00000000..edb56813 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVRSA.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/RSA/LVRSA.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVRefreshComponent.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVRefreshComponent.h new file mode 120000 index 00000000..686fc8db --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVRefreshComponent.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVRefreshComponent.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVRefreshConst.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVRefreshConst.h new file mode 120000 index 00000000..dec673e1 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVRefreshConst.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVRefreshConst.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVRefreshHeader.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVRefreshHeader.h new file mode 120000 index 00000000..61564a99 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVRefreshHeader.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVRefreshHeader.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVRotationGesture.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVRotationGesture.h new file mode 120000 index 00000000..bd9ee09b --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVRotationGesture.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVRotationGesture.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVScrollView.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVScrollView.h new file mode 120000 index 00000000..de1ff645 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVScrollView.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVScrollView.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVScrollViewDelegate.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVScrollViewDelegate.h new file mode 120000 index 00000000..67e59fbf --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVScrollViewDelegate.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVScrollViewDelegate.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVStruct.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVStruct.h new file mode 120000 index 00000000..d8e823f5 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVStruct.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVStruct.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVStyledString.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVStyledString.h new file mode 120000 index 00000000..6c968184 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVStyledString.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVStyledString.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVSwipeGesture.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVSwipeGesture.h new file mode 120000 index 00000000..e23b73d2 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVSwipeGesture.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVSwipeGesture.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVSystem.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVSystem.h new file mode 120000 index 00000000..651e2ff5 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVSystem.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVSystem.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVTapGesture.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVTapGesture.h new file mode 120000 index 00000000..d93376d5 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVTapGesture.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVTapGesture.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVTextField.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVTextField.h new file mode 120000 index 00000000..f6b9265d --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVTextField.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVTextField.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVTimer.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVTimer.h new file mode 120000 index 00000000..43ef6166 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVTimer.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVTimer.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVToast.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVToast.h new file mode 120000 index 00000000..2de07ea9 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVToast.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVToast.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVTransform3D.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVTransform3D.h new file mode 120000 index 00000000..eaacf285 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVTransform3D.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVTransform3D.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVTypeConvert.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVTypeConvert.h new file mode 120000 index 00000000..bfacee74 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVTypeConvert.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVTypeConvert.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVUtil.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVUtil.h new file mode 120000 index 00000000..1f2ec0b4 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVUtil.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVUtil.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVWebView.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVWebView.h new file mode 120000 index 00000000..aa1d7675 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVWebView.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/LVWebView.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVZipArchive.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVZipArchive.h new file mode 120000 index 00000000..8f1122ea --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LVZipArchive.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/PKG/LVZipArchive.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LView.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LView.h new file mode 120000 index 00000000..9d7bbad2 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LView.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/LView.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LViewController.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LViewController.h new file mode 120000 index 00000000..75ee9c1f --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LViewController.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/LViewController.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/Layout.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/Layout.h new file mode 120000 index 00000000..7661f0a4 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/Layout.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/layout/Layout.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LuaView.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LuaView.h new file mode 120000 index 00000000..0b4ecc84 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LuaView.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/LuaView.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LuaViewCore.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LuaViewCore.h new file mode 120000 index 00000000..cb6eabee --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/LuaViewCore.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/LuaViewCore.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/NSObject+LuaView.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/NSObject+LuaView.h new file mode 120000 index 00000000..6350fab4 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/NSObject+LuaView.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/NSObject+LuaView.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/UIScrollView+LVRefresh.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/UIScrollView+LVRefresh.h new file mode 120000 index 00000000..65b36da9 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/UIScrollView+LVRefresh.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/UIScrollView+LVRefresh.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/UIScrollView+LuaView.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/UIScrollView+LuaView.h new file mode 120000 index 00000000..93b2060b --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/UIScrollView+LuaView.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/UIScrollView+LuaView.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/UIView+JUFLXNode.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/UIView+JUFLXNode.h new file mode 120000 index 00000000..241b2a67 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/UIView+JUFLXNode.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/layout/UIView+JUFLXNode.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/UIView+LuaView.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/UIView+LuaView.h new file mode 120000 index 00000000..760461e3 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/UIView+LuaView.h @@ -0,0 +1 @@ +../../../../../SDK/LuaViewSDK/Classes/lvsdk/UIView+LuaView.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/lapi.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/lapi.h new file mode 120000 index 00000000..4083678e --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/lapi.h @@ -0,0 +1 @@ +../../../../../lua/lua/lapi.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/lauxlib.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/lauxlib.h new file mode 120000 index 00000000..4ce76453 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/lauxlib.h @@ -0,0 +1 @@ +../../../../../lua/lua/lauxlib.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/lcode.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/lcode.h new file mode 120000 index 00000000..1ce67879 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/lcode.h @@ -0,0 +1 @@ +../../../../../lua/lua/lcode.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/ldebug.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/ldebug.h new file mode 120000 index 00000000..7d1e851d --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/ldebug.h @@ -0,0 +1 @@ +../../../../../lua/lua/ldebug.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/ldo.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/ldo.h new file mode 120000 index 00000000..c06b3ef8 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/ldo.h @@ -0,0 +1 @@ +../../../../../lua/lua/ldo.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/lfunc.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/lfunc.h new file mode 120000 index 00000000..0a5672db --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/lfunc.h @@ -0,0 +1 @@ +../../../../../lua/lua/lfunc.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/lgc.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/lgc.h new file mode 120000 index 00000000..6999a7ba --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/lgc.h @@ -0,0 +1 @@ +../../../../../lua/lua/lgc.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/llex.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/llex.h new file mode 120000 index 00000000..442bf396 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/llex.h @@ -0,0 +1 @@ +../../../../../lua/lua/llex.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/llimits.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/llimits.h new file mode 120000 index 00000000..929aaf7b --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/llimits.h @@ -0,0 +1 @@ +../../../../../lua/lua/llimits.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/lmem.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/lmem.h new file mode 120000 index 00000000..256168b3 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/lmem.h @@ -0,0 +1 @@ +../../../../../lua/lua/lmem.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/lobject.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/lobject.h new file mode 120000 index 00000000..8442f4d6 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/lobject.h @@ -0,0 +1 @@ +../../../../../lua/lua/lobject.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/lopcodes.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/lopcodes.h new file mode 120000 index 00000000..3e7619ab --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/lopcodes.h @@ -0,0 +1 @@ +../../../../../lua/lua/lopcodes.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/lparser.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/lparser.h new file mode 120000 index 00000000..85c9ecb7 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/lparser.h @@ -0,0 +1 @@ +../../../../../lua/lua/lparser.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/lstate.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/lstate.h new file mode 120000 index 00000000..81ded74d --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/lstate.h @@ -0,0 +1 @@ +../../../../../lua/lua/lstate.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/lstring.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/lstring.h new file mode 120000 index 00000000..e72bf060 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/lstring.h @@ -0,0 +1 @@ +../../../../../lua/lua/lstring.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/ltable.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/ltable.h new file mode 120000 index 00000000..645ce75d --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/ltable.h @@ -0,0 +1 @@ +../../../../../lua/lua/ltable.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/ltm.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/ltm.h new file mode 120000 index 00000000..7a360f05 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/ltm.h @@ -0,0 +1 @@ +../../../../../lua/lua/ltm.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/lua.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/lua.h new file mode 120000 index 00000000..ed4c0152 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/lua.h @@ -0,0 +1 @@ +../../../../../lua/lua/lua.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/luaconf.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/luaconf.h new file mode 120000 index 00000000..5746f909 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/luaconf.h @@ -0,0 +1 @@ +../../../../../lua/lua/luaconf.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/lualib.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/lualib.h new file mode 120000 index 00000000..f6cfe2d7 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/lualib.h @@ -0,0 +1 @@ +../../../../../lua/lua/lualib.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/lundump.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/lundump.h new file mode 120000 index 00000000..195260e0 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/lundump.h @@ -0,0 +1 @@ +../../../../../lua/lua/lundump.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/lvm.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/lvm.h new file mode 120000 index 00000000..0fb76f04 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/lvm.h @@ -0,0 +1 @@ +../../../../../lua/lua/lvm.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/LuaViewSDK/lzio.h b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/lzio.h new file mode 120000 index 00000000..86be10b0 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/LuaViewSDK/lzio.h @@ -0,0 +1 @@ +../../../../../lua/lua/lzio.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/MJRefresh/MJRefresh.h b/IOS/Playground/Pods/Headers/Public/MJRefresh/MJRefresh.h new file mode 120000 index 00000000..d83fdd64 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/MJRefresh/MJRefresh.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/MJRefresh.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/MJRefresh/MJRefreshAutoFooter.h b/IOS/Playground/Pods/Headers/Public/MJRefresh/MJRefreshAutoFooter.h new file mode 120000 index 00000000..5bb1fbc5 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/MJRefresh/MJRefreshAutoFooter.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/Base/MJRefreshAutoFooter.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/MJRefresh/MJRefreshAutoGifFooter.h b/IOS/Playground/Pods/Headers/Public/MJRefresh/MJRefreshAutoGifFooter.h new file mode 120000 index 00000000..1435437b --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/MJRefresh/MJRefreshAutoGifFooter.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/Custom/Footer/Auto/MJRefreshAutoGifFooter.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/MJRefresh/MJRefreshAutoNormalFooter.h b/IOS/Playground/Pods/Headers/Public/MJRefresh/MJRefreshAutoNormalFooter.h new file mode 120000 index 00000000..6b87abe4 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/MJRefresh/MJRefreshAutoNormalFooter.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/Custom/Footer/Auto/MJRefreshAutoNormalFooter.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/MJRefresh/MJRefreshAutoStateFooter.h b/IOS/Playground/Pods/Headers/Public/MJRefresh/MJRefreshAutoStateFooter.h new file mode 120000 index 00000000..19b2053a --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/MJRefresh/MJRefreshAutoStateFooter.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/Custom/Footer/Auto/MJRefreshAutoStateFooter.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/MJRefresh/MJRefreshBackFooter.h b/IOS/Playground/Pods/Headers/Public/MJRefresh/MJRefreshBackFooter.h new file mode 120000 index 00000000..3df4973f --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/MJRefresh/MJRefreshBackFooter.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/Base/MJRefreshBackFooter.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/MJRefresh/MJRefreshBackGifFooter.h b/IOS/Playground/Pods/Headers/Public/MJRefresh/MJRefreshBackGifFooter.h new file mode 120000 index 00000000..e5d5f96d --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/MJRefresh/MJRefreshBackGifFooter.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/Custom/Footer/Back/MJRefreshBackGifFooter.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/MJRefresh/MJRefreshBackNormalFooter.h b/IOS/Playground/Pods/Headers/Public/MJRefresh/MJRefreshBackNormalFooter.h new file mode 120000 index 00000000..c578c7f5 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/MJRefresh/MJRefreshBackNormalFooter.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/Custom/Footer/Back/MJRefreshBackNormalFooter.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/MJRefresh/MJRefreshBackStateFooter.h b/IOS/Playground/Pods/Headers/Public/MJRefresh/MJRefreshBackStateFooter.h new file mode 120000 index 00000000..3317188d --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/MJRefresh/MJRefreshBackStateFooter.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/Custom/Footer/Back/MJRefreshBackStateFooter.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/MJRefresh/MJRefreshComponent.h b/IOS/Playground/Pods/Headers/Public/MJRefresh/MJRefreshComponent.h new file mode 120000 index 00000000..35cb1b14 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/MJRefresh/MJRefreshComponent.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/Base/MJRefreshComponent.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/MJRefresh/MJRefreshConst.h b/IOS/Playground/Pods/Headers/Public/MJRefresh/MJRefreshConst.h new file mode 120000 index 00000000..035954b9 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/MJRefresh/MJRefreshConst.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/MJRefreshConst.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/MJRefresh/MJRefreshFooter.h b/IOS/Playground/Pods/Headers/Public/MJRefresh/MJRefreshFooter.h new file mode 120000 index 00000000..743dda22 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/MJRefresh/MJRefreshFooter.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/Base/MJRefreshFooter.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/MJRefresh/MJRefreshGifHeader.h b/IOS/Playground/Pods/Headers/Public/MJRefresh/MJRefreshGifHeader.h new file mode 120000 index 00000000..aa6afbd0 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/MJRefresh/MJRefreshGifHeader.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/Custom/Header/MJRefreshGifHeader.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/MJRefresh/MJRefreshHeader.h b/IOS/Playground/Pods/Headers/Public/MJRefresh/MJRefreshHeader.h new file mode 120000 index 00000000..3a38b267 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/MJRefresh/MJRefreshHeader.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/Base/MJRefreshHeader.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/MJRefresh/MJRefreshNormalHeader.h b/IOS/Playground/Pods/Headers/Public/MJRefresh/MJRefreshNormalHeader.h new file mode 120000 index 00000000..b5cc1640 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/MJRefresh/MJRefreshNormalHeader.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/Custom/Header/MJRefreshNormalHeader.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/MJRefresh/MJRefreshStateHeader.h b/IOS/Playground/Pods/Headers/Public/MJRefresh/MJRefreshStateHeader.h new file mode 120000 index 00000000..7bd25cf7 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/MJRefresh/MJRefreshStateHeader.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/Custom/Header/MJRefreshStateHeader.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/MJRefresh/NSBundle+MJRefresh.h b/IOS/Playground/Pods/Headers/Public/MJRefresh/NSBundle+MJRefresh.h new file mode 120000 index 00000000..2a628b44 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/MJRefresh/NSBundle+MJRefresh.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/NSBundle+MJRefresh.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/MJRefresh/UIScrollView+MJExtension.h b/IOS/Playground/Pods/Headers/Public/MJRefresh/UIScrollView+MJExtension.h new file mode 120000 index 00000000..1919784b --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/MJRefresh/UIScrollView+MJExtension.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/UIScrollView+MJExtension.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/MJRefresh/UIScrollView+MJRefresh.h b/IOS/Playground/Pods/Headers/Public/MJRefresh/UIScrollView+MJRefresh.h new file mode 120000 index 00000000..47b703d5 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/MJRefresh/UIScrollView+MJRefresh.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/UIScrollView+MJRefresh.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/MJRefresh/UIView+MJExtension.h b/IOS/Playground/Pods/Headers/Public/MJRefresh/UIView+MJExtension.h new file mode 120000 index 00000000..5f198134 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/MJRefresh/UIView+MJExtension.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/UIView+MJExtension.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/SDWebImage/NSData+ImageContentType.h b/IOS/Playground/Pods/Headers/Public/SDWebImage/NSData+ImageContentType.h new file mode 120000 index 00000000..84574987 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/SDWebImage/NSData+ImageContentType.h @@ -0,0 +1 @@ +../../../SDWebImage/SDWebImage/NSData+ImageContentType.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/SDWebImage/SDImageCache.h b/IOS/Playground/Pods/Headers/Public/SDWebImage/SDImageCache.h new file mode 120000 index 00000000..0040b06a --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/SDWebImage/SDImageCache.h @@ -0,0 +1 @@ +../../../SDWebImage/SDWebImage/SDImageCache.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/SDWebImage/SDWebImageCompat.h b/IOS/Playground/Pods/Headers/Public/SDWebImage/SDWebImageCompat.h new file mode 120000 index 00000000..6ca24784 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/SDWebImage/SDWebImageCompat.h @@ -0,0 +1 @@ +../../../SDWebImage/SDWebImage/SDWebImageCompat.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/SDWebImage/SDWebImageDecoder.h b/IOS/Playground/Pods/Headers/Public/SDWebImage/SDWebImageDecoder.h new file mode 120000 index 00000000..a2f3a683 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/SDWebImage/SDWebImageDecoder.h @@ -0,0 +1 @@ +../../../SDWebImage/SDWebImage/SDWebImageDecoder.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/SDWebImage/SDWebImageDownloader.h b/IOS/Playground/Pods/Headers/Public/SDWebImage/SDWebImageDownloader.h new file mode 120000 index 00000000..303b03b1 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/SDWebImage/SDWebImageDownloader.h @@ -0,0 +1 @@ +../../../SDWebImage/SDWebImage/SDWebImageDownloader.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/SDWebImage/SDWebImageDownloaderOperation.h b/IOS/Playground/Pods/Headers/Public/SDWebImage/SDWebImageDownloaderOperation.h new file mode 120000 index 00000000..99441c48 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/SDWebImage/SDWebImageDownloaderOperation.h @@ -0,0 +1 @@ +../../../SDWebImage/SDWebImage/SDWebImageDownloaderOperation.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/SDWebImage/SDWebImageManager.h b/IOS/Playground/Pods/Headers/Public/SDWebImage/SDWebImageManager.h new file mode 120000 index 00000000..1b818485 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/SDWebImage/SDWebImageManager.h @@ -0,0 +1 @@ +../../../SDWebImage/SDWebImage/SDWebImageManager.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/SDWebImage/SDWebImageOperation.h b/IOS/Playground/Pods/Headers/Public/SDWebImage/SDWebImageOperation.h new file mode 120000 index 00000000..20e5b89e --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/SDWebImage/SDWebImageOperation.h @@ -0,0 +1 @@ +../../../SDWebImage/SDWebImage/SDWebImageOperation.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/SDWebImage/SDWebImagePrefetcher.h b/IOS/Playground/Pods/Headers/Public/SDWebImage/SDWebImagePrefetcher.h new file mode 120000 index 00000000..50585c6d --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/SDWebImage/SDWebImagePrefetcher.h @@ -0,0 +1 @@ +../../../SDWebImage/SDWebImage/SDWebImagePrefetcher.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/SDWebImage/UIButton+WebCache.h b/IOS/Playground/Pods/Headers/Public/SDWebImage/UIButton+WebCache.h new file mode 120000 index 00000000..19d2d8e8 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/SDWebImage/UIButton+WebCache.h @@ -0,0 +1 @@ +../../../SDWebImage/SDWebImage/UIButton+WebCache.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/SDWebImage/UIImage+GIF.h b/IOS/Playground/Pods/Headers/Public/SDWebImage/UIImage+GIF.h new file mode 120000 index 00000000..14d5aadd --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/SDWebImage/UIImage+GIF.h @@ -0,0 +1 @@ +../../../SDWebImage/SDWebImage/UIImage+GIF.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/SDWebImage/UIImage+MultiFormat.h b/IOS/Playground/Pods/Headers/Public/SDWebImage/UIImage+MultiFormat.h new file mode 120000 index 00000000..1fb96501 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/SDWebImage/UIImage+MultiFormat.h @@ -0,0 +1 @@ +../../../SDWebImage/SDWebImage/UIImage+MultiFormat.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/SDWebImage/UIImageView+HighlightedWebCache.h b/IOS/Playground/Pods/Headers/Public/SDWebImage/UIImageView+HighlightedWebCache.h new file mode 120000 index 00000000..fd4dea41 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/SDWebImage/UIImageView+HighlightedWebCache.h @@ -0,0 +1 @@ +../../../SDWebImage/SDWebImage/UIImageView+HighlightedWebCache.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/SDWebImage/UIImageView+WebCache.h b/IOS/Playground/Pods/Headers/Public/SDWebImage/UIImageView+WebCache.h new file mode 120000 index 00000000..0c53a47b --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/SDWebImage/UIImageView+WebCache.h @@ -0,0 +1 @@ +../../../SDWebImage/SDWebImage/UIImageView+WebCache.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/SDWebImage/UIView+WebCacheOperation.h b/IOS/Playground/Pods/Headers/Public/SDWebImage/UIView+WebCacheOperation.h new file mode 120000 index 00000000..f9890c40 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/SDWebImage/UIView+WebCacheOperation.h @@ -0,0 +1 @@ +../../../SDWebImage/SDWebImage/UIView+WebCacheOperation.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/luaviewEx/LVExButton.h b/IOS/Playground/Pods/Headers/Public/luaviewEx/LVExButton.h new file mode 120000 index 00000000..af730472 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/luaviewEx/LVExButton.h @@ -0,0 +1 @@ +../../../../../luaviewEx/luaviewEx/Classes/LVExButton.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/luaviewEx/LVExCollectionView.h b/IOS/Playground/Pods/Headers/Public/luaviewEx/LVExCollectionView.h new file mode 120000 index 00000000..6e191207 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/luaviewEx/LVExCollectionView.h @@ -0,0 +1 @@ +../../../../../luaviewEx/luaviewEx/Classes/LVExCollectionView.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/luaviewEx/LVExImage.h b/IOS/Playground/Pods/Headers/Public/luaviewEx/LVExImage.h new file mode 120000 index 00000000..0e69df68 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/luaviewEx/LVExImage.h @@ -0,0 +1 @@ +../../../../../luaviewEx/luaviewEx/Classes/LVExImage.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Headers/Public/luaviewEx/LVViewController.h b/IOS/Playground/Pods/Headers/Public/luaviewEx/LVViewController.h new file mode 120000 index 00000000..9b3f6fe6 --- /dev/null +++ b/IOS/Playground/Pods/Headers/Public/luaviewEx/LVViewController.h @@ -0,0 +1 @@ +../../../../../luaviewEx/luaviewEx/Classes/LVViewController.h \ No newline at end of file diff --git a/IOS/Playground/Pods/Local Podspecs/LuaViewSDK.podspec.json b/IOS/Playground/Pods/Local Podspecs/LuaViewSDK.podspec.json new file mode 100644 index 00000000..d3830d59 --- /dev/null +++ b/IOS/Playground/Pods/Local Podspecs/LuaViewSDK.podspec.json @@ -0,0 +1,32 @@ +{ + "name": "LuaViewSDK", + "version": "0.5.0", + "summary": "LuaView SDK", + "description": "A longer description of LuaViewSDK.podspec in Markdown format.\n* LuaView", + "homepage": "http://gitlab.alibaba-inc.com/luaview/LuaViewSDK", + "license": { + "type": "The MIT License (MIT)", + "file": "LICENSE.txt" + }, + "authors": { + "城西": "xicheng.dxc@alibaba-inc.com" + }, + "platforms": { + "ios": "7.0" + }, + "source": { + "git": "https://github.com/alibaba/LuaViewSDK.git", + "tag": "v0.5.0" + }, + "source_files": [ + "IOS/SDK/LuaViewSDK/Classes/**/*.{h,m,c}", + "IOS/lua/lua/*.{h,m,c}" + ], + "frameworks": [ + "Foundation", + "UIKit", + "CoreGraphics" + ], + "libraries": "z", + "requires_arc": true +} diff --git a/IOS/Playground/Pods/Local Podspecs/luaviewEx.podspec.json b/IOS/Playground/Pods/Local Podspecs/luaviewEx.podspec.json new file mode 100644 index 00000000..29c25519 --- /dev/null +++ b/IOS/Playground/Pods/Local Podspecs/luaviewEx.podspec.json @@ -0,0 +1,43 @@ +{ + "name": "luaviewEx", + "version": "0.1.0", + "summary": "A short description of luaviewEx.", + "description": "TODO: Add long description of the pod here.", + "homepage": "https://github.com/yechunxiao19/luaviewEx", + "license": { + "type": "MIT", + "file": "LICENSE" + }, + "authors": { + "yechunxiao19": "chunxiao.ycx@alibaba-inc.com" + }, + "source": { + "git": "https://github.com/yechunxiao19/luaviewEx.git", + "tag": "0.1.0" + }, + "platforms": { + "ios": "8.0" + }, + "source_files": "luaviewEx/Classes/*", + "resource_bundles": { + "luaviewEx": [ + "luaviewEx/Assets/**/*.{lua}" + ] + }, + "resources": "luaviewEx/luaview/luaview.bundle", + "public_header_files": "Pod/Classes/*.h", + "dependencies": { + "LuaViewSDK": [ + + ], + "SDWebImage": [ + "~> 3.7.5" + ], + "MJRefresh": [ + + ] + }, + "xcconfig": { + "INFOPLIST_FILE": "../../luaviewEx/luaviewEx/Classes/luaviewEx-info.plist" + } +} diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LVBlock.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LVBlock.h new file mode 100644 index 00000000..28d52554 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LVBlock.h @@ -0,0 +1,35 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + +@interface LVBlock : NSObject + +@property (nonatomic,assign) int returnValueNum;// 返回值的数量 + +- (id) initWith:(lua_State*)L statckID:(int) idx; +- (id) initWith:(lua_State*)L globalName:(NSString*) globalName; + +/* + * 调用Lua function + */ +- (NSString*) callWithArgs:(NSArray*) args; +- (NSString*) callWithArgs:(NSArray*) args returnValueNum:(int) returnValueNum; + +/* + * 获取返回值 + */ +- (id) returnValue:(int)index; +- (id) returnValue; + + +- (void) pushFunctionToStack; + + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LVBlock.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LVBlock.m new file mode 100644 index 00000000..2faef2c6 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LVBlock.m @@ -0,0 +1,137 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVBlock.h" +#import "LuaViewCore.h" +#import "LVHeads.h" + +@interface LVBlock () +@property (nonatomic,weak) LuaViewCore* lview; +@property (nonatomic,strong) id retainKey; +@property (nonatomic,strong) NSArray* returnValues; +@end + +@implementation LVBlock + +- (id) initWith:(lua_State*)L statckID:(int) idx{ + self = [super init]; + if( self ){ + self.retainKey = [[NSMutableString alloc] init]; + self.lview = LV_LUASTATE_VIEW(L); + if( lua_type(L, idx)==LUA_TFUNCTION ) { + [LVUtil registryValue:L key:self.retainKey stack:idx]; + } + } + return self; +} + +- (id) initWith:(lua_State*)L globalName:(NSString*) globalName{ + self = [super init]; + if( self ){ + self.retainKey = [[NSMutableString alloc] init]; + self.lview = LV_LUASTATE_VIEW(L); + + if ( [globalName rangeOfString:@"."].length>0 ){ + [self resetFunctionByNames:globalName]; + } else { + lua_getglobal(L, globalName.UTF8String); + if( lua_type(L, -1)==LUA_TFUNCTION ) { + [LVUtil registryValue:L key:self.retainKey stack:-1]; + } + } + } + return self; +} + +-(void) resetFunctionByNames:(NSString*) globalName{ + NSArray * names = [globalName componentsSeparatedByString:@"."]; + lua_State* L = self.lview.l; + if( names.count>0 ){ + NSString* name0 = names.firstObject; + lua_getglobal(L, name0.UTF8String); + for( int i=1; i0 ) { + self.returnValues = values; + } else { + self.returnValues = nil; + } + //lua_settop(L, oldStackNum); + return ret; + } + return nil; +} + +-(void) pushFunctionToStack{ + lua_State* L = self.lview.l; + if( L ){ + [LVUtil pushRegistryValue:L key:self.retainKey]; + } +} + +-(id) returnValue{ + return [self returnValue:0]; +} + +-(id) returnValue:(int)index{ + if( index>=0 && index +#import +#import "LVHeads.h" + +@class LVRSA; + +@interface LVBundle : NSObject + +@property (nonatomic, readonly) NSArray* scriptPaths; +@property (nonatomic, readonly) NSArray* resourcePaths; + +@property (nonatomic, readonly) NSString *currentPath; + +- (void)changeCurrentPath:(NSString *)path; + +/** + * 可以是绝对路径也可以是相对bundle根目录的相对路径 + */ +- (void)addResourcePath:(NSString *)path; +- (void)removeResourcePath:(NSString *)path; + +- (void)addScriptPath:(NSString *)path; +- (void)removeScriptPath:(NSString *)path; + +- (NSString *)resourcePathWithName:(NSString *)name; + +- (NSData *)resourceWithName:(NSString *)name; +- (UIImage *)imageWithName:(NSString *)name; + +- (NSString *)scriptPathWithName:(NSString *)name; + +- (NSData *)scriptWithName:(NSString *)name; +- (NSData *)signedScriptWithName:(NSString *)name rsa:(LVRSA *)rsa; + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LVBundle.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LVBundle.m new file mode 100644 index 00000000..4d20d04d --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LVBundle.m @@ -0,0 +1,205 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVBundle.h" +#import "LVPkgManager.h" +#import "LVUtil.h" +#import "LVHeads.h" +#import "LView.h" + +@interface LVBundle () { + NSMutableArray *_scriptPaths; + NSMutableArray *_resourcePaths; + NSFileManager *_fileManager; + NSString *_currentPath; +} + +@property(nonatomic,strong) NSMutableDictionary* imageCaches; + +@end + +@implementation LVBundle + +@dynamic resourcePaths, scriptPaths; +@dynamic currentPath; + +- (id)init { + self = [super init]; + if(self) { + _fileManager = [NSFileManager defaultManager]; + _currentPath = [[NSBundle mainBundle] resourcePath]; + + _resourcePaths = [NSMutableArray arrayWithObjects:[LVUtil PathForCachesResource:nil], @".", nil]; + _scriptPaths = [NSMutableArray arrayWithObject:@"."]; + _imageCaches = [[NSMutableDictionary alloc] init]; + } + return self; +} + +- (NSString *)currentPath { + return _currentPath; +} + +- (void)changeCurrentPath:(NSString *)path { + NSAssert(path, @"current path could not be nil"); + BOOL isDir = NO; + if (![_fileManager fileExistsAtPath:path isDirectory:&isDir] || !isDir) { + NSAssert(NO, @"%@ not exists or is not a directory", path); + return; + } + + _currentPath = path; +} + +- (NSArray *)resourcePaths { + return [_resourcePaths copy]; +} + +- (void)addResourcePath:(NSString *)path { + NSAssert(path, @"path could not be nil"); + + [_resourcePaths insertObject:path atIndex:0]; +} + +- (void)removeResourcePath:(NSString *)path { + NSAssert(path, @"path could not be nil"); + + [_resourcePaths removeObject:path]; +} + +- (NSArray *)scriptPaths { + return [_scriptPaths copy]; +} + +- (void)addScriptPath:(NSString *)path { + NSAssert(path, @"path could not be nil"); + + [_scriptPaths insertObject:path atIndex:0]; +} + +- (void)removeScriptPath:(NSString *)path { + NSAssert(path, @"path could not be nil"); + + [_scriptPaths removeObject:path]; +} + +- (NSString *)absolutePath:(NSString *)path { + if (path == nil) { + return nil; + } else if ([path hasPrefix:@"/"]) { + return path; + } else { + return [_currentPath stringByAppendingPathComponent:path]; + } +} + +- (NSString *)resourcePathWithName:(NSString *)name { + if (name == nil) { + return nil; + } + + NSString *fullPath = nil; + for (NSString *dir in _resourcePaths) { + fullPath = [self absolutePath:[dir stringByAppendingPathComponent:name]]; + if ([_fileManager fileExistsAtPath:fullPath]) { + return fullPath; + } + } + + return nil; +} + +- (NSData *)resourceWithName:(NSString *)name { + if (name == nil) { + return nil; + } + + NSString *path = [self resourcePathWithName:name]; + if (path == nil) { + return nil; + } + + return [_fileManager contentsAtPath:path]; +} + +- (UIImage *)imageWithName:(NSString *)name { + if (name == nil) { + return nil; + } + UIImage* image = self.imageCaches[name]; + if( image ) { + return image; + } + NSString *path = [self resourcePathWithName:name]; + if( path ) { + image = [UIImage imageWithContentsOfFile:path]; + } else { + image = [UIImage imageNamed:name]; + } + if( image ){ + self.imageCaches[name] = image; + } + return image; +} + +- (NSString *)scriptPathWithName:(NSString *)name { + if (name == nil) { + return nil; + } + + NSString *ext = [name pathExtension]; + if (ext == nil || + !([LVScriptExts[0] isEqualToString:ext] || [LVScriptExts[1] isEqualToString:ext])) { + + NSAssert(nil, @"LuaView: %@ file is not supported!", ext); + return nil; + } + + NSString *fullPath = nil; + for (NSString *dir in _scriptPaths) { + fullPath = [self absolutePath:[dir stringByAppendingPathComponent:name]]; + if ([_fileManager fileExistsAtPath:fullPath]) { + return fullPath; + } + } + + return name; +} + +- (NSData *)scriptWithName:(NSString *)name { + if (name == nil) { + return nil; + } + NSAssert([[name pathExtension] isEqualToString:LVScriptExts[!LVSignedScriptExtIndex]], + @"%@ is not normal script", name); + + NSString *fullPath = [self scriptPathWithName:name]; + if (fullPath == nil) { + return nil; + } + + return [LVUtil dataReadFromFile:fullPath]; +} + +- (NSData *)signedScriptWithName:(NSString *)name rsa:(LVRSA *)rsa { + if (name == nil) { + return nil; + } + + NSAssert([[name pathExtension] isEqualToString:LVScriptExts[LVSignedScriptExtIndex]], + @"%@ is not signed script", name); + + NSString *fullPath = [self scriptPathWithName:name]; + if (fullPath == nil) { + return nil; + } + + return [LVPkgManager readLuaFile:fullPath rsa:rsa]; +} + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LView.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LView.h new file mode 100644 index 00000000..196dad6c --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LView.h @@ -0,0 +1,29 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import + +#import "LuaView.h" +#pragma mark -LuaView 类加载脚本调用接口 +@interface LView : LuaView + +@property (nonatomic,assign) BOOL changeGrammar;// 是否需要语法转换(原先luaview语法和lua标准语法的区别是‘.’和':'互换了),默认是非标准语法,需要转换 + +@property (nonatomic,assign) BOOL checkDebugerServer; // 是否检查调试器 + +// 设置证书地址 +- (void) setPublicKeyFilePath:(NSString*) filePath; + +-(LVBlock*) getLuaBlock:(NSString*) name; + +-(NSString*) callLua:(NSString*) functionName tag:(id) tag environment:(UIView*)environment args:(NSArray*) args; +-(NSString*) callLua:(NSString*) functionName environment:(UIView*) environment args:(NSArray*) args; +-(NSString*) callLua:(NSString*) functionName args:(NSArray*) args; + +@end + diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LView.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LView.m new file mode 100644 index 00000000..8aa0bb75 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LView.m @@ -0,0 +1,47 @@ + +#import "LView.h" +#import "LVRSA.h" + + +@implementation LView + + +-(BOOL) changeGrammar{ + return self.luaviewCore.changeGrammar; +} + +-(void) setChangeGrammar:(BOOL)changeGrammar{ + self.luaviewCore.changeGrammar = changeGrammar; +} + +-(BOOL) checkDebugerServer{ + return self.luaviewCore.checkDebugerServer; +} + +-(void) setCheckDebugerServer:(BOOL)checkDebugerServer{ + self.luaviewCore.checkDebugerServer = checkDebugerServer; +} + +// 设置证书地址 +- (void) setPublicKeyFilePath:(NSString*) filePath{ + [self.luaviewCore.rsa setPublicKeyFilePath:filePath]; +} + +-(NSString*) callLua:(NSString*) functionName tag:(id) tag environment:(UIView*)environment args:(NSArray*) args{ + return [self.luaviewCore callLua:functionName tag:tag environment:environment args:args]; +} + +-(NSString*) callLua:(NSString*) functionName environment:(UIView*) environment args:(NSArray*) args{ + return [self.luaviewCore callLua:functionName environment:environment args:args]; +} + +-(NSString*) callLua:(NSString*) functionName args:(NSArray*) args{ + return [self.luaviewCore callLua:functionName args:args]; +} + +-(LVBlock*) getLuaBlock:(NSString*) name{ + return [self.luaviewCore getLuaBlock:name]; +} + + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LViewController.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LViewController.h new file mode 100644 index 00000000..b0dd9658 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LViewController.h @@ -0,0 +1,33 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import + + +@class LuaView; + +typedef void(^LuaViewRegister)(LuaView* lv); + +@interface LViewController : UIViewController + +@property(nonatomic, readonly) LuaView *lv; +@property(nonatomic, readonly) NSString *mainScriptName; +@property(nonatomic, readonly) NSString *packagePath; + ++ (void)disableReloadKeyCommand:(BOOL)disable; + +- (instancetype)initWithPackage:(NSString *)path mainScript:(NSString *)scriptName; + +- (void)willCreateLuaView; +- (void)didCreateLuaView:(LuaView *) view; +- (void)willDestroyLuaView:(LuaView *) view; +- (void)didDestroyLuaView; + +@property(nonatomic,copy) LuaViewRegister luaviewRegister; + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LViewController.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LViewController.m new file mode 100644 index 00000000..d6dcf2dd --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LViewController.m @@ -0,0 +1,175 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LViewController.h" +#import "LuaView.h" +#import "LVUtil.h" + +#if DEBUG +#define LV_LOCAL_DEBUG 1 +#endif + +@interface LViewController () + +@property (nonatomic, strong) LuaView *lv; + +@property (nonatomic, strong) NSString *packagePath, *mainScriptName; + +@end + +static BOOL __disableReloadKeyCommand = NO; + +@implementation LViewController + ++ (void)disableReloadKeyCommand:(BOOL)disable { + __disableReloadKeyCommand = disable; +} + +- (instancetype)initWithPackage:(NSString *)path mainScript:(NSString *)scriptName { + if (self = [super init]) { + _packagePath = path; + _mainScriptName = scriptName; + } + + return self; +} + +-(void) dealloc{ + [self.lv releaseLuaView]; + self.lv = nil; +} + +- (void)viewDidLoad { + [super viewDidLoad]; + self.automaticallyAdjustsScrollViewInsets = NO; + self.edgesForExtendedLayout = UIRectEdgeNone; + + [self createLuaView]; +} + +- (BOOL)canBecomeFirstResponder { + return YES; +} + +#pragma mark - rewarding methods + +// TODO: reward memory warning + +- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event { + [self.lv motionBegan:motion withEvent:event]; +} + +- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event { + [self.lv motionCancelled:motion withEvent:event]; +} + +- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event { + [self.lv motionEnded:motion withEvent:event]; +} + +-(void) viewWillAppear:(BOOL)animated{ + [super viewWillAppear:animated]; + [self.navigationController setNavigationBarHidden:NO animated:YES]; + + [self.lv viewWillAppear]; +} + +-(void) viewDidAppear:(BOOL)animated{ + [super viewDidAppear:animated]; + [self becomeFirstResponder]; + + [self.lv viewDidAppear]; +} + +-(void) viewWillDisappear:(BOOL)animated{ + [super viewWillDisappear:animated]; + [self.lv viewWillDisAppear]; +} + +-(void) viewDidDisappear:(BOOL)animated{ + [super viewDidDisappear:animated]; + [self.lv viewDidDisAppear]; +} + +#pragma mark - luaview life cycle + +- (void)rebuildLuaView { + [self destroyLuaView]; + [self createLuaView]; +} + +- (void)createLuaView { + [self willCreateLuaView]; + + CGRect rect = self.view.bounds; + + self.lv = [[LuaView alloc] initWithFrame:rect]; + self.lv.viewController = self; + + if( self.luaviewRegister ) { + self.luaviewRegister(self.lv); + } + + [self didCreateLuaView:self.lv]; + + [self.view addSubview:self.lv]; + + [self runLocalPackage:self.packagePath mainScript:self.mainScriptName]; +} + +- (void)destroyLuaView { + [self willDestroyLuaView:self.lv]; + + [self.lv releaseLuaView]; + self.lv = nil; + + [self didDestroyLuaView]; +} + +- (void)runLocalPackage:(NSString *)packagePath mainScript:(NSString *)scriptName { + if (packagePath) { + [self.lv.bundle addScriptPath:packagePath]; + [self.lv.bundle addResourcePath:packagePath]; + } + [self.lv runFile:scriptName ?: @"main.lua"]; +} + +- (void)willCreateLuaView { } + +- (void)didCreateLuaView:(LView *)view { } + +- (void)willDestroyLuaView:(LView *)view { } + +- (void)didDestroyLuaView { } + +#pragma mark - debug + +#if LV_LOCAL_DEBUG + +/* + * Cmd + r 没有刷新时需要做如下设置: + * simulator -> Hardware -> Keyboard -> Connect Hardware Keyboard + * + * https://github.com/facebook/react-native/issues/306#issuecomment-86834162 + */ +- (NSArray *)keyCommands { + if (__disableReloadKeyCommand) { + return nil; + } + + UIKeyCommand *reloadKeyCommand = [UIKeyCommand + keyCommandWithInput:@"r" + modifierFlags:UIKeyModifierCommand + action:@selector(rebuildLuaView)]; + + return @[reloadKeyCommand]; +} + +#endif // LV_LOCAL_DEBUG + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LuaView.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LuaView.h new file mode 100644 index 00000000..8415b1dc --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LuaView.h @@ -0,0 +1,122 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LuaViewCore.h" + + +@class LuaView; + +#pragma mark - LuaView窗口大小变动回调 +@protocol LVCallback +- (void) luaviewFrameDidChange:(LuaView *)lView; +@end + + +@interface LuaView : UIView + +@property (nonatomic,weak) UIViewController* viewController;// 所在的ViewController +@property (nonatomic,strong) LVBundle* bundle; + +@property(nonatomic,weak) id callback; //用于LuaView回调( luaView大小改变 等回调) +@property (nonatomic,strong) LuaViewCore* luaviewCore; +@property (nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; + +-(void) viewWillAppear; +-(void) viewDidAppear; +-(void) viewWillDisAppear; +-(void) viewDidDisAppear; + +#pragma mark - 摇一摇回调 +// 摇一摇开始摇动 +- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event; +// 摇一摇取消摇动 +- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event; +// 摇一摇摇动结束 +- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event; + +-(void) releaseLuaView; + + +// + +/** + * load and run script + * + * @param fileName 本地文件名 + * + * @return 返回运行结果 + */ +-(NSString*) runFile:(NSString*) fileName; + +/** + * 运行一个包, main.lv是主入口 + * + * @param fileName 本地文件名 + * + * @return 返回运行结果 + */ +-(NSString*) runPackage:(NSString*) packageName; + +/** + * 运行一个包, main.lv是主入口 + * + * @param fileName 本地文件名 + * @args args 参数 + * + * @return 返回运行结果 + */ +-(NSString*) runPackage:(NSString*) packageName args:(NSArray*) args; + +/** + * 运行签名的脚本文件 + * + * @param fileName 本地文件名 + * + * @return 返回运行结果 + */ +-(NSString*) runSignFile:(NSString*) fileName; + +/** + * load and run script + * + * @param chars 脚本字符流 + * @param length 脚本字符流的长度 + * @param fileName 文件名,用于出错提示, 可以为空 + * + * @return 运行结果 + */ +-(NSString*) runData:(NSData*) data fileName:(NSString*) fileName; + +-(NSString*) runData:(NSData*) data fileName:(NSString*) fileName changeGrammar:(BOOL) changeGrammar; + +/** + * 加载签名的脚本文件,读取文件并调用lvL_loadbuffer + * + * @param fileName 本地文件名 + * + * @return 返回错误描述 + */ +-(NSString*) loadSignFile:(NSString *)fileName; + +/** + * 加载脚本文件,读取文件并调用lvL_loadbuffer + * + * @param fileName 本地文件名 + * + * @return 返回错误描述 + */ +-(NSString*) loadFile:(NSString *)fileName; + +- (void) setObject:(id)object forKeyedSubscript:(NSObject *)key; + + +-(lua_State*) l; // 获取 lua 状态机 + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LuaView.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LuaView.m new file mode 100644 index 00000000..bf51073b --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LuaView.m @@ -0,0 +1,346 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LuaView.h" +#import "LuaViewCore.h" + +@interface LuaView () +@property (nonatomic,assign) BOOL isOnShowed; +@end + +@implementation LuaView + + + +-(id) init{ + self = [super init]; + if( self ) { + } + return self; +} + +-(id) initWithFrame:(CGRect)frame{ + self = [super initWithFrame:frame]; + if( self ) { + [self createLuaViewCore]; + } + return self; +} + +/* + * 初始化LuaViewCore + */ +-(void) createLuaViewCore{ + self.luaviewCore = [[LuaViewCore alloc] init]; + [self.luaviewCore pushWindow:self]; + self.backgroundColor = [UIColor clearColor]; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(keyboardWillShow:) + name:UIKeyboardWillShowNotification + object:nil]; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(keyboardDidShow:) + name:UIKeyboardDidShowNotification + object:nil]; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(keyboardWillHide:) + name:UIKeyboardWillHideNotification + object:nil]; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(keyboardDidHide:) + name:UIKeyboardDidHideNotification + object:nil]; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(onForeground) + name:UIApplicationDidBecomeActiveNotification + object:nil]; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(onBackground) + name:UIApplicationDidEnterBackgroundNotification + object:nil]; +} + +-(void) dealloc{ + [[NSNotificationCenter defaultCenter] removeObserver:self]; +} + +-(UIViewController*) viewController{ + return self.luaviewCore.viewController; +} + +-(void) setViewController:(UIViewController *)viewController{ + self.luaviewCore.viewController = viewController; +} + +-(LVBundle*) bundle{ + return self.luaviewCore.bundle; +} + +-(void) setBundle:(LVBundle *)bundle{ + self.luaviewCore.bundle = bundle; +} + +-(void) releaseLuaView{ + [self.luaviewCore releaseLuaView]; +} + + +/** + * load and run script + * + * @param fileName 本地文件名 + * + * @return 返回运行结果 + */ +-(NSString*) runFile:(NSString*) fileName{ + return [self.luaviewCore runFile:fileName]; +} + +/** + * 运行一个包, main.lv是主入口 + * + * @param fileName 本地文件名 + * + * @return 返回运行结果 + */ +-(NSString*) runPackage:(NSString*) packageName{ + return [self.luaviewCore runPackage:packageName]; +} + +/** + * 运行一个包, main.lv是主入口 + * + * @param fileName 本地文件名 + * @args args 参数 + * + * @return 返回运行结果 + */ +-(NSString*) runPackage:(NSString*) packageName args:(NSArray*) args{ + return [self.luaviewCore runPackage:packageName args:args]; +} + +/** + * 运行签名的脚本文件 + * + * @param fileName 本地文件名 + * + * @return 返回运行结果 + */ +-(NSString*) runSignFile:(NSString*) fileName{ + return [self.luaviewCore runSignFile:fileName]; +} + +/** + * load and run script + * + * @param chars 脚本字符流 + * @param length 脚本字符流的长度 + * @param fileName 文件名,用于出错提示, 可以为空 + * + * @return 运行结果 + */ +-(NSString*) runData:(NSData*) data fileName:(NSString*) fileName{ + return [self.luaviewCore runData:data fileName:fileName]; +} + +-(NSString*) runData:(NSData*) data fileName:(NSString*) fileName changeGrammar:(BOOL) changeGrammar{ + return [self.luaviewCore runData:data fileName:fileName changeGrammar:changeGrammar]; +} + +/** + * 加载签名的脚本文件,读取文件并调用lvL_loadbuffer + * + * @param fileName 本地文件名 + * + * @return 返回错误描述 + */ +-(NSString*) loadSignFile:(NSString *)fileName{ + return [self.luaviewCore loadSignFile:fileName]; +} + +/** + * 加载脚本文件,读取文件并调用lvL_loadbuffer + * + * @param fileName 本地文件名 + * + * @return 返回错误描述 + */ +-(NSString*) loadFile:(NSString *)fileName{ + return [self.luaviewCore loadFile:fileName]; +} + +-(void) setFrame:(CGRect)frame{ + [super setFrame:frame]; + [self.callback luaviewFrameDidChange:self]; +} + +- (void)setObject:(id)object forKeyedSubscript:(NSObject *)key{ + [self.luaviewCore setObject:object forKeyedSubscript:key]; +} + + +#pragma mark - view appear + +-(void) viewWillAppear{ + lua_State* L = self.luaviewCore.l; + if( L ) { + lua_checkstack32(L); + [self lv_callLuaByKey1:@"ViewWillAppear"]; + } +} + +-(void) viewDidAppear{ + self.isOnShowed = YES; + lua_State* L = self.luaviewCore.l; + if( L ) { + lua_checkstack32(L); + [self lv_callLuaByKey1:@"onShow"];//@"ViewDidAppear" + } +} + +-(void) viewWillDisAppear{ + lua_State* L = self.luaviewCore.l; + if( L ) { + lua_checkstack32(L); + [self lv_callLuaByKey1:@"ViewWillDisAppear"]; + } +} + +-(void) viewDidDisAppear{ + self.isOnShowed = NO; + lua_State* L = self.luaviewCore.l; + if( L ) { + lua_checkstack32(L); + [self lv_callLuaByKey1:@"onHide"];//@"ViewDidDisAppear" + } +} + +-(void) onForeground { + lua_State* L = self.luaviewCore.l; + if( L && self.isOnShowed ) { + lua_checkstack32(L); + lua_pushboolean(L, YES); + [self lv_callLuaByKey1:@"onShow" key2:nil argN:1]; + } +} + +-(void) onBackground { + lua_State* L = self.luaviewCore.l; + if( L && self.isOnShowed ) { + lua_checkstack32(L); + lua_pushboolean(L, YES); + [self lv_callLuaByKey1:@"onHide" key2:nil argN:1]; + } +} + +- (void)didMoveToSuperview{ + [super didMoveToSuperview]; + + lua_State* L = self.luaviewCore.l; + if( L ) { + lua_checkstack32(L); + [self lv_callLuaByKey1:@"DidMoveToSuperview"]; + } +} + +- (void)didMoveToWindow{ + [super didMoveToWindow]; + + lua_State* L = self.luaviewCore.l; + if( L ) { + lua_checkstack32(L); + [self lv_callLuaByKey1:@"DidMoveToSuperview"]; + } +} + +-(void) layoutSubviews{ + [super layoutSubviews]; + + lua_State* L = self.luaviewCore.l; + if( L ) { + lua_checkstack32(L); + [self lv_callLuaByKey1:@STR_ON_LAYOUT]; + } +} + + +#pragma mark - keyboard + +-(void) keyboardWillShow:(NSNotification *)notification { + lua_State* L = self.luaviewCore.l; + if( L ) { + lua_checkstack32(L); + [self lv_callLuaByKey1:@"KeyboardWillShow"]; + } +} +-(void) keyboardDidShow:(NSNotification *)notification { + lua_State* L = self.luaviewCore.l; + if( L ) { + lua_checkstack32(L); + [self lv_callLuaByKey1:@"KeyboardDidShow"]; + } +} +-(void) keyboardWillHide:(NSNotification *)notification { + lua_State* L = self.luaviewCore.l; + if( L ) { + lua_checkstack32(L); + [self lv_callLuaByKey1:@"KeyboardWillHide"]; + } +} +-(void) keyboardDidHide:(NSNotification *)notification { + lua_State* L = self.luaviewCore.l; + if( L ) { + lua_checkstack32(L); + [self lv_callLuaByKey1:@"KeyboardDidHide"]; + } +} + +#pragma mark - 摇一摇相关方法 +// 摇一摇开始摇动 +- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event { + lua_State* L = self.luaviewCore.l; + if (event.subtype == UIEventSubtypeMotionShake) { + if( L ) { + lua_checkstack32(L); + [self lv_callLuaByKey1:@"ShakeBegin"]; + } + } +} + +// 摇一摇取消摇动 +- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event { + if (event.subtype == UIEventSubtypeMotionShake) { + lua_State* L = self.luaviewCore.l; + if( L ) { + lua_checkstack32(L); + [self lv_callLuaByKey1:@"ShakeCanceled"]; + } + } +} + +// 摇一摇摇动结束 +- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event { + if (event.subtype == UIEventSubtypeMotionShake) { + lua_State* L = self.luaviewCore.l; + if( L ) { + lua_checkstack32(L); + [self lv_callLuaByKey1:@"ShakeEnded"]; + } + } +} + +-(lua_State*) l{ + return self.luaviewCore.l; +} + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LuaViewCore.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LuaViewCore.h new file mode 100644 index 00000000..fc1baeba --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LuaViewCore.h @@ -0,0 +1,242 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" +#import "LVDebugConnection.h" + + +@class LView; +@class LVBlock; +@class LVBundle; +@protocol LVProtocal; + + +#pragma mark -LuaView 类加载脚本调用接口 +@interface LuaViewCore : NSObject + +@property (nonatomic,strong) LVRSA* rsa; + +@property (nonatomic,strong) LVBundle* bundle; + +/** + * 是否需要语法转换(原先luaview语法和lua标准语法的区别是‘.’和':'互换了),默认是标准语法,使用非标准语法需要转换成标准语法才设置成true + */ +@property (nonatomic,assign) BOOL changeGrammar; + +//--------------------------------------------------------------------- +/** +* 调试开关 +* +*/ +@property (nonatomic,assign) BOOL checkDebugerServer; // 是否检查调试器 +// @property (nonatomic,assign) BOOL openDebugger; // 开启调试 + + +//--------------------------------------------------------------------- +/** +* 加载脚本文件,读取文件并调用lvL_loadbuffer +* +* @param fileName 本地文件名 +* +* @return 返回错误描述 +*/ +-(NSString*) loadFile:(NSString *)fileName; + +/** +* 加载签名的脚本文件,读取文件并调用lvL_loadbuffer +* +* @param fileName 本地文件名 +* +* @return 返回错误描述 +*/ +-(NSString*) loadSignFile:(NSString *)fileName; + +/** + * 加载代码String + */ +- (NSString*) loadScript:(NSString*)script fileName:(NSString *)fileNam; + +/** +* 加载代码data +*/ +- (NSString*) loadData:(NSData *)data fileName:(NSString *)fileNam; + +/** +* load and run script +* +* @param fileName 本地文件名 +* +* @return 返回运行结果 +*/ +-(NSString*) runFile:(NSString*) fileName; + +/** +* 运行一个包, main.lv是主入口 +* +* @param fileName 本地文件名 +* +* @return 返回运行结果 +*/ +-(NSString*) runPackage:(NSString*) packageName; + +/** +* 运行一个包, main.lv是主入口 +* +* @param fileName 本地文件名 +* @args args 参数 +* +* @return 返回运行结果 +*/ +-(NSString*) runPackage:(NSString*) packageName args:(NSArray*) args; + +/** + * 加载包 + */ +- (NSString*) loadPackage:(NSString*) packageName; + +/** +* 运行签名的脚本文件 +* +* @param fileName 本地文件名 +* +* @return 返回运行结果 +*/ +-(NSString*) runSignFile:(NSString*) fileName; + +/** +* load and run script +* +* @param chars 脚本字符流 +* @param length 脚本字符流的长度 +* @param fileName 文件名,用于出错提示, 可以为空 +* +* @return 运行结果 +*/ +-(NSString*) runData:(NSData*) data fileName:(NSString*) fileName; + +-(NSString*) runData:(NSData*) data fileName:(NSString*) fileName changeGrammar:(BOOL) changeGrammar; + +/** +* +*调用lua脚本, functionName:lua的function名称, environment:运行窗口, args:传递参数 +* +*/ +-(NSString*) callLua:(NSString*) functionName tag:(id) tag environment:(UIView*)environment args:(NSArray*) args; +-(NSString*) callLua:(NSString*) functionName environment:(UIView*) environment args:(NSArray*) args; +-(NSString*) callLua:(NSString*) functionName args:(NSArray*) args; +-(LVBlock*) getLuaBlock:(NSString*) name; + +/** +* 释放虚拟机回收luaView +*/ +-(void) releaseLuaView; + +/** +* Layer模式优化性能 +*/ +@property (nonatomic,assign) BOOL closeLayerMode; + + +/** +* 图片首次出现是否使用动画 +*/ +@property (nonatomic,assign) BOOL disableAnimate; + +@property(nonatomic,copy) NSArray* registerClasses; + +@property (nonatomic,weak) UIViewController* viewController;// 所在的ViewController + +@end + + +#pragma mark - 设置资源搜索路径 +@interface LuaViewCore () + + +/* + * packageName: 包名 比如:"ppt" + * info格式: { "url" : "http://g.tbcdn.cn/ju/lua/3.2.12/ppt4.4.0.js" , "time":"2015-11-18 09:53"} + */ ++(void) downloadPackage:(NSString*)package withInfo:(NSDictionary*)info; + +@end + +#pragma mark - Register 注册外部api接口 +@interface LuaViewCore () + +- (void) setObject:(id)object forKeyedSubscript:(NSObject *)key; +- (void) registerObject:(id) object forName:(NSString*) name sel:(SEL) sel;// 只注册指定API +- (void) registerObject:(id) object forName:(NSString*) name sel:(SEL) sel weakMode:(BOOL) weakMode;// 只注册指定API +- (void) registerObject:(id) object forName:(NSString*) name;// 注册改对象的所有api +- (void) registerObject:(id) object forName:(NSString*) name weakMode:(BOOL) weakMode;// 注册改对象的所有api +- (void) unregisteObjectForName:(NSString*) name;// 取消注册对象 + + +- (void) registerLibs:(id) lib; +- (void) registerName:(NSString*) name withObject:(id) object; +- (void) registerPanel:(id) panel; +- (void) registerPanel:(id) panel forName:(NSString*) name; +- (void) unregister:(NSString*) name; + +@end + + + +#pragma mark - LViewBlock lua闭包参数获取使用 +@interface LuaViewCore () + +- (BOOL) argumentToBool:(int) index; +- (double) argumentToNumber:(int) index; +- (id) argumentToObject:(int) index; + +@end + + +#pragma mark - debugger 只是调试工具使用 +@interface LuaViewCore () + +-(void) callLuaToExecuteServerCmd; +@property (nonatomic,strong) LVDebugConnection* debugConnection; + +@end + + +#pragma mark - Property 系统使用的, 基本上不用关心细节 +@interface LuaViewCore () +@property (nonatomic,assign) BOOL runInSignModel;// 加密模式,优先加载加密脚本 +@property (nonatomic, weak) LuaViewCore* lv_luaviewCore; +@property (nonatomic, assign) LVUserDataInfo* lv_userData;// 脚本中的window对象 数据绑定 +@property (nonatomic, assign) lua_State* l; // lua 状态机 + +-(void) containerAddSubview:(UIView *)view; + + +@end + + + +//------------ 窗口渲染接口, 必须成对出现! 慎用! ------------------------------ +@interface LuaViewCore () +/** + * 渲染窗口 压栈 + * + */ +-(void) pushWindow:(UIView*) window; +-(void) pushRenderTarget:(UIView*) window; + +/** + * 渲染窗口 出栈 + */ +-(void) popWindow:(UIView*) window; +-(void) popRenderTarget:(UIView*) window; + +-(void) luaviewGC; + +@end + diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LuaViewCore.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LuaViewCore.m new file mode 100644 index 00000000..89835cc2 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LuaViewCore.m @@ -0,0 +1,653 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LuaViewCore.h" + + +#import "LuaViewCore.h" +#import "LVHeads.h" +#import "LVExGlobalFunc.h" +#import "LVTimer.h" +#import "LVDebuger.h" +#import "LVNativeObjBox.h" +#import "LVBlock.h" +#import "LVPkgManager.h" +#import "UIView+LuaView.h" +#import "LVDebugConnection.h" +#import "LVDebugConnection.h" +#import "LVCustomPanel.h" +#import +#import "LVRSA.h" +#import "LVBundle.h" +#import "LVButton.h" +#import "LVScrollView.h" +#import "LVTimer.h" +#import "LVUtil.h" +#import "LVPagerIndicator.h" +#import "LVLoadingIndicator.h" +#import "LVImage.h" +#import "LVWebView.h" +#import "LVLabel.h" +#import "LVBaseView.h" +#import "LVTransform3D.h" +#import "LVTextField.h" +#import "LVAnimate.h" +#import "LVAnimator.h" +#import "LVDate.h" +#import "LVAlert.h" +#import "LVSystem.h" +#import "LVDB.h" +#import "LVGesture.h" +#import "LVTapGesture.h" +#import "LVPanGesture.h" +#import "LVPinchGesture.h" +#import "LVRotationGesture.h" +#import "LVHttp.h" +#import "LVData.h" +#import "LVSwipeGesture.h" +#import "LVLongPressGesture.h" +#import "LVDebuger.h" +#import "LVDownloader.h" +#import "LVAudioPlayer.h" +#import "LVFile.h" +#import "LVStyledString.h" +#import "LVNativeObjBox.h" +#import "LVCollectionView.h" +#import "LVEmptyRefreshCollectionView.h" +#import "LVStruct.h" +#import "LVNavigation.h" +#import "LVCustomPanel.h" +#import "LVCustomView.h" +#import "LVPagerView.h" +#import "LVCanvas.h" +#import "LVEvent.h" + +@interface LuaViewCore () +@property (nonatomic,strong) id mySelf; +@property (nonatomic,assign) BOOL stateInited; +@property (nonatomic,assign) BOOL loadedDebugScript; +@property (atomic,assign) NSInteger callLuaTimes; +@property(nonatomic,weak) UIView* window; +@property (nonatomic,assign) int windowIdx; +@end + +@implementation LuaViewCore + +-(id) init{ + self = [super init]; + if( self ){ + [self myInit]; + [self registeLibs]; + } + return self; +} + +#pragma mark - init + +-(void) myInit{ + self.checkDebugerServer = YES; + self.disableAnimate = YES; + self.closeLayerMode = YES; + self.mySelf = self; + + + self.lv_luaviewCore = self; + self.rsa = [[LVRSA alloc] init]; + self.bundle = [[LVBundle alloc] init]; +} + +-(void) dealloc{ + [self.debugConnection closeAll]; +} + +#pragma mark - run +-(NSString*) runFile:(NSString*) fileName{ + self.runInSignModel = FALSE; + NSData* code = [self.bundle scriptWithName:fileName]; + + return [self runData:code fileName:fileName]; +} + +-(NSString*) runSignFile:(NSString*) fileName{ + self.runInSignModel = TRUE; + NSData* code = [self.bundle signedScriptWithName:fileName rsa:self.rsa]; + + return [self runData:code fileName:fileName]; +} + +- (NSString*) loadPackage:(NSString*) packageName{ + return [self runPackage:packageName]; +} + +-(NSString*) runPackage:(NSString*) packageName { + return [self runPackage:packageName args:nil]; +} + +-(NSString*) runPackage:(NSString*) packageName args:(NSArray*) args{ + self.runInSignModel = TRUE; + + NSString *packagePath = [LVPkgManager rootDirectoryOfPackage:packageName]; + [self.bundle addScriptPath:packagePath]; + [self.bundle addResourcePath:packagePath]; + + self.changeGrammar = [[LVPkgManager changeGrammarOfPackage:packageName] isEqualToString:@"true"]; + + NSString* fileName = @"main.lv"; + NSString* ret = [self runSignFile:fileName]; + lua_State* L = self.l; + if( ret==nil && L ) { + for( int i=0; i0 ) { + if( self.loadedDebugScript == NO ) { + self.loadedDebugScript = YES; + [self.debugConnection sendCmd:@"log" info:@"[LuaView][调试日志] 开始调试!\n"]; + [self loadDebugModel];// 加载调试模块 + } + } +} +#else +- (void) callLuaToExecuteServerCmd{ +} +#endif + +static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) { + (void)ud; + (void)osize; + if (nsize == 0) { + free(ptr); + return NULL; + } else { + return realloc(ptr, nsize); + } +} + + +-(void) registeLibs{ + if( !self.stateInited ) { + self.stateInited = YES; + self.l = lua_newstate(l_alloc, (__bridge void *)(self)); + luaL_openlibs(self.l); + NSArray* arr = nil; + arr = @[ + [LVSystem class], + [LVData class], + [LVStruct class], + [LVBaseView class], + [LVButton class], + [LVImage class], + [LVWebView class], + [LVLabel class], + [LVScrollView class], + [LVCollectionView class], + [LVEmptyRefreshCollectionView class], + [LVPagerView class], + [LVCustomView class], + [LVCanvas class], + [LVEvent class], + [LVTimer class], + [LVPagerIndicator class], + [LVCustomPanel class], + [LVTransform3D class], + [LVAnimator class], + [LVTextField class], + [LVAnimate class], + [LVDate class], + [LVAlert class], + [LVDB class], + [LVGesture class], + [LVTapGesture class], + [LVPinchGesture class], + [LVRotationGesture class], + [LVSwipeGesture class], + [LVLongPressGesture class], + [LVPanGesture class], + [LVLoadingIndicator class], + [LVHttp class], + [LVDownloader class], + [LVFile class], + [LVAudioPlayer class], + [LVStyledString class], + [LVNavigation class], + [LVExGlobalFunc class], + [LVNativeObjBox class], + [LVDebuger class], + ]; + self.registerClasses = arr; + [self registerAllClass]; + + // 默认支持RefreshCollectionView + self[@"RefreshCollectionView"] = [LVCollectionView class]; + } +} + +-(void) registerAllClass{ + lua_State* L = self.l; + //清理栈 + for( NSInteger i =0; i *)key{ + lua_State* L = self.l; + if ( L ==nil ){ + LVError( @"Lua State is released !!!"); + return; + } + if( [key isKindOfClass:[NSString class]] && class_isMetaClass(object_getClass(object)) ) { + if( [object respondsToSelector:@selector(lvClassDefine:globalName:)] ) { + [object lvClassDefine:L globalName:(NSString*)key]; + return; + } + } + if ( [key isKindOfClass:[NSString class]] ){ + [LVNativeObjBox registeObjectWithL:L nativeObject:object name:(NSString*)key sel:nil weakMode:YES]; + } +} + +-(void) unregisteObjectForName:(NSString*) name{ + lua_State* L = self.l; + if ( L ==nil ){ + LVError( @"Lua State is released !!!"); + return ; + } + [LVNativeObjBox unregisteObjectWithL:L name:name]; +} + +- (void) registerLibs:(id) lib{ + lua_State* L = self.l; + if( [lib respondsToSelector:@selector(lvClassDefine:globalName:)] ) { + [lib lvClassDefine:L globalName:nil]; + return; + } +} + +- (void) registerName:(NSString*) name withObject:(id) object{ + [self registerObject:object forName:name]; +} + +- (void) registerPanel:(id) panel{ + [self registerPanel:panel forName:nil]; +} + +- (void) registerPanel:(id) panel forName:(NSString*) name{ + lua_State* L = self.l; + if( [panel respondsToSelector:@selector(lvClassDefine:globalName:)] ) { + [panel lvClassDefine:L globalName:name]; + return; + } +} + +- (void) unregister:(NSString*) name{ + [self unregisteObjectForName:name]; +} +#pragma mark - package + ++(void) downloadPackage:(NSString*)packageName withInfo:(NSDictionary*)info{ + [LVPkgManager downloadPackage:packageName withInfo:info]; +} + +-(BOOL) argumentToBool:(int) index{ + lua_State* L = self.l; + if ( L ) { + return lua_toboolean(L, index); + } + return NO; +} + +-(double) argumentToNumber:(int) index{ + lua_State* L = self.l; + if ( L ) { + return lua_tonumber(L, index); + } + return 0; +} + +-(id) argumentToObject:(int) index{ + lua_State* L = self.l; + if ( L ) { + return lv_luaValueToNativeObject(L, index); + } + return 0; +} + +-(void) containerAddSubview:(UIView *)view{ + lv_addSubview(self, self.window, view); +} + +-(void) createWindow:(UIView *)window{ + self.window = window; + [LVExGlobalFunc registry:self.l window:self.window]; +} + +-(const char*) windowName{ + const char* name = [NSString stringWithFormat:@"core.window.%d",self.windowIdx].UTF8String; + return name; +} + +-(void) pushRenderTarget:(UIView *)window{ + [self pushWindow:window]; +} + +-(void) pushWindow:(UIView*) window{ + lua_State* L = self.l; + lua_checkstack(L,8); + + // 老的window 压栈 + const char* newWindowName = [self windowName]; + lua_getglobal(L, "window"); + lua_setglobal(L, newWindowName); + self.windowIdx ++; + + // 创建新的window + [self createWindow:window];//创建window +} + +-(void) popRenderTarget:(UIView *)window{ + [self popWindow:window]; +} + +-(void) popWindow:(UIView*) window{ + if( self.window==window ) { + lua_State* L = self.l; + lua_checkstack(L,8); + self.windowIdx --; + const char* oldWindowName = [self windowName]; + + // 出栈 + lua_getglobal(L, oldWindowName); + lua_setglobal(L, "window"); + lua_getglobal(L, "window"); + + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, -1); + if( user ) { + self.window = (__bridge UIView *)(user->object); + } + } else { + LVError(@"pop window!!!!"); + } +} + +-(void) luaviewGC { + // 清理luaview对应的内存 + lua_State *state = self.l; + if (state) { + lua_checkstack(state, 8); + lua_pushnil(state); + [LVUtil registryValue:state key:self stack:-1]; + LVBlock *block = [self getLuaBlock:@"System.gc"]; + [block callWithArgs:nil]; + } +} + + +@end + diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/PKG/LVPkgInfo.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/PKG/LVPkgInfo.h new file mode 100644 index 00000000..2f7eb2df --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/PKG/LVPkgInfo.h @@ -0,0 +1,46 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import + +#define LV_PKGINFO_URL @"url" +#define LV_PKGINFO_URL2 @"luaview_script_url" +#define LV_PKGINFO_SHA @"sha" +#define LV_PKGINFO_SHA256 @"sha256" + +#define LV_PKGINFO_SURL @"surl" +#define LV_PKGINFO_SSHA @"ssha" +#define LV_PKGINFO_SSHA256 @"ssha256" + +#define LV_PKGINFO_PACKAGE @"package" + +@interface LVPkgInfo : NSObject + +@property(nonatomic,copy) NSDictionary* originalDic; // 原始信息 + +@property(nonatomic,copy) NSString* url; // 下载地址 +@property(nonatomic,copy) NSString* sha256; // sha256 +@property(nonatomic,copy) NSString* timestamp; // 版本对比时间戳 +@property(nonatomic,assign) BOOL changeGrammar; // 是否需要语法转换(‘:’和'.'互换) +@property(nonatomic,copy) NSString* package; // sha256 + +/* + * + * 解析字典 -> model + * + */ +-(instancetype) init:(NSDictionary*) dic; + +/* + * + * model -> 字典信息 + * + */ +- (NSDictionary*) dictionaryInfo; + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/PKG/LVPkgInfo.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/PKG/LVPkgInfo.m new file mode 100644 index 00000000..ce81e9d3 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/PKG/LVPkgInfo.m @@ -0,0 +1,98 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVPkgInfo.h" +#import "LVUtil.h" + +@implementation LVPkgInfo + +-(instancetype) init:(NSDictionary*) dic{ + self = [super init]; + if( self ) { + NSString* url = nil; + NSString* sha = nil; + + url = [LVPkgInfo safe_string:dic forKey:LV_PKGINFO_SURL]; + sha = [LVPkgInfo safe_string:dic forKey:LV_PKGINFO_SSHA key2:LV_PKGINFO_SSHA256]; + if( url && sha ) { + self.url = url; + self.sha256 = sha; + self.changeGrammar = NO; + } else { + self.url = [LVPkgInfo safe_string:dic forKey:LV_PKGINFO_URL key2:LV_PKGINFO_URL2]; + self.sha256 = [LVPkgInfo safe_string:dic forKey:LV_PKGINFO_SHA key2:LV_PKGINFO_SHA256]; + self.changeGrammar = YES; + } + self.url = [self stringByDecodingURLFormat:self.url]; // 下载地址可能需要解码 + self.url = [self addHttpPrefix:self.url];// 下载地址可能需要加https前缀 + self.package = [LVPkgInfo safe_string:dic forKey:LV_PKGINFO_PACKAGE]; + if( self.package.length<=0 && self.url) { + self.package = [LVUtil MD5HashFromData:[self.url dataUsingEncoding:NSUTF8StringEncoding]]; + } + self.timestamp = self.url;//时间戳 用下载地址标示 + self.originalDic = dic; + } + return self; +} + +-(NSString*) addHttpPrefix:(NSString*) url{ + if( [url rangeOfString:@"://"].length>0 ){ + return url; + } + if( [url hasPrefix:@"//"] ) { + return [NSString stringWithFormat:@"https:%@",url]; + } + return url; +} + +- (NSString *)stringByDecodingURLFormat:(NSString*) str +{ + NSString *result = [str stringByReplacingOccurrencesOfString:@"+" withString:@" "]; + //result = [result stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; + result = [result stringByRemovingPercentEncoding]; + return result; +} + +- (NSDictionary*) dictionaryInfo{ + if( self.url && self.sha256 && self.package ) { + if( self.changeGrammar ) { + return @{LV_PKGINFO_URL:self.url, + LV_PKGINFO_SHA:self.sha256, + LV_PKGINFO_PACKAGE:self.package}; + } else { + return @{LV_PKGINFO_SURL:self.url , + LV_PKGINFO_SSHA:self.sha256, + LV_PKGINFO_PACKAGE:self.package}; + } + } + return nil; +} + ++(NSString*) safe_string:(NSDictionary*) dic forKey:(NSString*) key { + return [self safe_string:dic forKey:key key2:nil]; +} + ++(NSString*) safe_string:(NSDictionary*) dic forKey:(NSString*) key1 key2:(NSString*) key2{ + if( [dic isKindOfClass:[NSDictionary class]] ) { + if( key1 ) { + NSString* s = dic[key1]; + if( [s isKindOfClass:[NSString class]] ) { + return s; + } + } + if( key2 ) { + NSString* s = dic[key2]; + if( [s isKindOfClass:[NSString class]] ) { + return s; + } + } + } + return nil; +} + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/PKG/LVPkgManager.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/PKG/LVPkgManager.h new file mode 100644 index 00000000..a7e091fe --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/PKG/LVPkgManager.h @@ -0,0 +1,62 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVPkgInfo.h" + +#define LUAVIEW_ROOT_PATH @"LUAVIEW_5_11_0" +#define LUAVIEW_VERSION "5.16.0" +#define LUAVIEW_SDK_VERSION "0.5.0" + + +extern NSString * const LV_FILE_NAME_OF_PACKAGE_DOWNLOAD_URL; +extern NSString * const LV_FILE_NAME_OF_PACKAGE_TIMESTAMP; +extern NSString * const LV_FILE_NAME_OF_CHANGE_GRAMMAR; + +@class LVRSA; + +typedef enum : NSUInteger { + LV_DOWNLOAD_ERROR = -1, + LV_DOWNLOAD_CACHE = 0 , + LV_DOWNLOAD_NET = 1, +} LVDownloadDataType; + +typedef void(^LVDownloadCallback)(NSDictionary* info, NSString* error, LVDownloadDataType dataType); + +@interface LVPkgManager : NSObject + ++ (NSString *)rootDirectoryOfPackage:(NSString *)packageName; ++ (NSString *)pathForFileName:(NSString *)fileName package:(NSString *)packageName; + +// 解压失败是-1, 无需解压本地更加新是0, 解压成功是1 ++(int) unpackageFile:(NSString*) fileName packageName:(NSString*) packageName changeGrammar:(BOOL) changeGrammar; ++(int) unpackageData:(NSData*) data packageName:(NSString*) packageName changeGrammar:(BOOL) changeGrammar; + +// 返回值说明 0:本地和线上版本一样; 1:即将去下载; -1:错误 ++(NSInteger) downloadPackage:(NSString*)packageName withInfo:(NSDictionary*) info; +// 返回值说明 0:本地和线上版本一样; 1:即将去下载; -1:错误 ++(NSInteger) downloadPackage:(NSString*)packageName withInfo:(NSDictionary*) info callback:(LVDownloadCallback) callback; + ++(NSData*) readLuaFile:(NSString*) fileName rsa:(LVRSA*) rsa; +// download url ++(NSString*) downloadUrlOfPackage:(NSString*)packageName; ++(BOOL) setPackage:(NSString*)packageName downloadUrl:(NSString*) downloadUrl; +// timestamp ++(NSString*) timestampOfPackage:(NSString*)packageName; ++(BOOL) setPackage:(NSString*)packageName timestamp:(NSString*) time; +// changeGrammar ++(NSString*) changeGrammarOfPackage:(NSString*)packageName; ++(BOOL) setPackage:(NSString*)packageName changeGrammar:(NSString*) timestamp; + +// 返回值说明 0:本地和线上版本一样; -1:错误或者不相等 ++(int) compareDownloadUrlOfPackage:(NSString*)name withServerInfo:(NSDictionary*) info; + +//清理所有LuaView相关文件 ++(void) clearCachesPath; + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/PKG/LVPkgManager.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/PKG/LVPkgManager.m new file mode 100644 index 00000000..258a4a59 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/PKG/LVPkgManager.m @@ -0,0 +1,301 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVPkgManager.h" +#import "LVUtil.h" +#import "LVRSA.h" +#import "LVZipArchive.h" +#import "zlib.h" + +NSString * const LV_FILE_NAME_OF_PACKAGE_DOWNLOAD_URL = @"___download_url___"; +NSString * const LV_FILE_NAME_OF_PACKAGE_TIMESTAMP = @"___timestamp___"; +NSString * const LV_FILE_NAME_OF_CHANGE_GRAMMAR = @"___change_grammar___"; + +@implementation LVPkgManager + ++ (NSString *)rootDirectoryOfPackage:(NSString *)packageName { + NSString *path = [NSString stringWithFormat:@"%@/%@",LUAVIEW_ROOT_PATH, packageName]; + return [LVUtil PathForCachesResource:path]; +} + ++ (NSString *)pathForFileName:(NSString *)fileName package:(NSString *)packageName { + return [[self rootDirectoryOfPackage:packageName] stringByAppendingPathComponent:fileName]; +} + +//------------------------------ write/read file for package --------------------------------- ++(BOOL) writeFile:(NSData*)data packageName:(NSString*)packageName fileName:(NSString*)fileName { + NSString* path = [self pathForFileName:fileName package:packageName]; + if( [LVUtil saveData:data toFile:path] ){ + LVLog (@"writeFile: %@, %d", fileName, (int)data.length); + return YES; + } else { + LVError(@"writeFile: %@, %d", fileName, (int)data.length); + return NO; + } +} + ++(NSData*) readFileFromPackage:(NSString*)packageName fileName:(NSString*)fileName { + NSString *path = [self pathForFileName:fileName package:packageName]; + NSData* data =[LVUtil dataReadFromFile:path]; + return data; +} + +//----------------------------------- timestamp path ----------------------------------------- ++(NSString*) filePathOfPackageDownloadUrl:(NSString *)packageName { + return [self pathForFileName:LV_FILE_NAME_OF_PACKAGE_DOWNLOAD_URL package:packageName]; +} ++(NSString*) filePathOfPackageTimestamp:(NSString *)packageName { + return [self pathForFileName:LV_FILE_NAME_OF_PACKAGE_TIMESTAMP package:packageName]; +} ++(NSString*) filePathOfChangeGrammar:(NSString *)packageName { + return [self pathForFileName:LV_FILE_NAME_OF_CHANGE_GRAMMAR package:packageName]; +} +//------------------------------------------------------------------------------------------ ++(BOOL) deleteFileOfPackageDownloadUrl:(NSString*) packageName{ + NSString* path = [self filePathOfPackageDownloadUrl:packageName]; + return [LVUtil deleteFile:path]; +} ++(BOOL) deleteFileOfPackageTimestamp:(NSString*) packageName{ + NSString* path = [self filePathOfPackageTimestamp:packageName]; + return [LVUtil deleteFile:path]; +} +//------------------------------------ read/write package download url ----------------------------------- ++(NSString*) downloadUrlOfPackage:(NSString*)packageName{ + NSData* data = [self readFileFromPackage:packageName fileName:LV_FILE_NAME_OF_PACKAGE_DOWNLOAD_URL]; + if( data ) { + return [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; + } else { + return nil; + } +} + ++(BOOL) setPackage:(NSString*)packageName downloadUrl:(NSString*) timestamp{ + NSData* data = [timestamp dataUsingEncoding:NSUTF8StringEncoding]; + return [self writeFile:data packageName:packageName fileName:LV_FILE_NAME_OF_PACKAGE_DOWNLOAD_URL]; +} +//------------------------------------ read/write package timestamp ----------------------------------- ++(NSString*) timestampOfPackage:(NSString*)packageName { + NSData* data = [self readFileFromPackage:packageName fileName:LV_FILE_NAME_OF_PACKAGE_TIMESTAMP]; + if( data ) { + return [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; + } else { + return nil; + } +} + ++(BOOL) setPackage:(NSString*)packageName timestamp:(NSString*) timestamp{ + // time file + NSData* data = [timestamp dataUsingEncoding:NSUTF8StringEncoding]; + return [self writeFile:data packageName:packageName fileName:LV_FILE_NAME_OF_PACKAGE_TIMESTAMP]; +} +//------------------------------------ read/write change grammar ----------------------------------- ++(NSString*) changeGrammarOfPackage:(NSString*)packageName { + NSData* data = [self readFileFromPackage:packageName fileName:LV_FILE_NAME_OF_CHANGE_GRAMMAR]; + if( data ) { + return [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; + } else { + return nil; + } +} + ++(BOOL) setPackage:(NSString*)packageName changeGrammar:(NSString*) timestamp{ + // time file + NSData* data = [timestamp dataUsingEncoding:NSUTF8StringEncoding]; + return [self writeFile:data packageName:packageName fileName:LV_FILE_NAME_OF_CHANGE_GRAMMAR]; +} + +//------------------------------------------------------------------------------------------ ++(int) unpackageFile:(NSString*) fileName packageName:(NSString*) packageName changeGrammar:(BOOL) changeGrammar{ + NSString *path = [LVUtil PathForBundle:nil relativePath:fileName]; + + if( [LVUtil exist:path] ){ + NSData* pkgData = [LVUtil dataReadFromFile:path]; + return [self unpackageData:pkgData packageName:packageName changeGrammar:changeGrammar]; + } + return -1; +} +// 根据时间戳,检查是否需要更新 ++(BOOL) checkUpdateWithNewTS:(NSString*)newTS oldTS:(NSString*) oldTS{ + return newTS.length>0 && oldTS.length>0 && [newTS compare:oldTS]==NSOrderedDescending; +} + ++(int) unpackageData:(NSData*) pkgData packageName:(NSString*) packageName changeGrammar:(BOOL) changeGrammar{ + NSString *path = [self rootDirectoryOfPackage:packageName]; + if( pkgData && [LVUtil createPath:path] ){ + LVZipArchive *archive = [LVZipArchive archiveWithData:pkgData]; + + NSString* newTS = [archive timeIntervalStr]; + + NSString* oldTS = [self timestampOfPackage:packageName]; + // 首次下载 或者有 新的最新包 + if( (newTS && oldTS==nil) || [self checkUpdateWithNewTS:newTS oldTS:oldTS] ){ + BOOL result = [archive unzipToDirectory:path]; + if( result ) { + [self setPackage:packageName changeGrammar:(changeGrammar ? @"true":@"false") ]; + [self setPackage:packageName timestamp:newTS]; + return 1; + } + return -1; + } else { + LVLog(@" Not Need unpackage, %@, %@",packageName,newTS); + return 0; + } + } + return -1; +} + ++(NSString*) signfileNameOfOriginFile:(NSString*) fileName{ + return [NSString stringWithFormat:@"%@.sign",fileName]; +} + + ++(int) compareDownloadUrlOfPackage:(NSString*)packageName withServerInfo:(NSDictionary*) info{ + LVPkgInfo* pkgInfo = [[LVPkgInfo alloc] init:info]; + NSString* url1 = [self downloadUrlOfPackage:packageName]; + NSString* url2 = pkgInfo.url; + if( url1 && url2 && + [url1 isKindOfClass:[NSString class]] && [url2 isKindOfClass:[NSString class]] && + [url1 isEqualToString:url2] ){ + return 0; + } + return -1; +} + ++(NSInteger) downloadPackage:(NSString*)packageName withInfo:(NSDictionary*) info { + return [self downloadPackage:packageName withInfo:info callback:nil]; +} + ++(NSInteger) downloadPackage:(NSString*)packageName withInfo:(NSDictionary*) info callback:(LVDownloadCallback) callback{ + if( info ) { + if( [self compareDownloadUrlOfPackage:packageName withServerInfo:info] ){ + [self doDownloadPackage:packageName withInfo:info callback:callback]; + return LV_DOWNLOAD_NET; + } + return LV_DOWNLOAD_CACHE; + } + return LV_DOWNLOAD_ERROR; +} + ++(BOOL) sha256Check:(NSData*) data ret:(NSString*) string{ + NSData* temp = lv_SHA256HashBytes(data); + const unsigned char* bytes = temp.bytes; + NSMutableString* buffer = [[NSMutableString alloc] init]; + for( int i=0; i0 && pkgInfo.url.length>0 && pkgInfo.timestamp.length>0){ + [LVUtil download:pkgInfo.url callback:^(NSData *data) { + // 解包过程放在主线程执行!!!! + dispatch_async(dispatch_get_main_queue(), ^{ + if( data ){ + BOOL sha256OK = [self sha256Check:data ret:pkgInfo.sha256]; + if( sha256OK ){ + [self deleteFileOfPackageDownloadUrl:pkgName];// 开始解包, 删除时间戳文件 + if ( [self unpackageData:data packageName:pkgName changeGrammar:pkgInfo.changeGrammar]>=0 ) { + // 解包成功 + if( [self setPackage:pkgName downloadUrl:pkgInfo.url] ){// 写标记成功 + callback(pkgInfo.originalDic, nil, LV_DOWNLOAD_NET); + return ; + } + } + } + } else { + LVError(@"[downloadPackage] error: url=%@",pkgInfo.url); + } + callback(pkgInfo.originalDic, @"error", LV_DOWNLOAD_ERROR); + }); + }]; + } +} + ++(NSData*) readLuaFile:(NSString*) fileName rsa:(LVRSA*)rsa{ + NSString* signfileName = [self signfileNameOfOriginFile:fileName]; + NSData* signData = [LVUtil dataReadFromFile:signfileName]; + NSData* encodedfileData = [LVUtil dataReadFromFile:fileName]; + // LVLog(@"%@",[[NSString alloc] initWithData:fileData encoding:NSUTF8StringEncoding]); + if( [rsa verifyData:encodedfileData withSignedData:signData] ){ + NSData* fileData = LV_AES256DecryptDataWithKey(encodedfileData, [rsa aesKeyBytes]); + NSData* unzipedData = [self gzipUnpack:fileData]; + return unzipedData; + } + return nil; +} + ++ (NSData *)gzipUnpack:(NSData*) data +{ + if ([data length] == 0) return data; + + NSInteger full_length = [data length]; + NSInteger half_length = [data length] / 2; + + NSMutableData *decompressed = [NSMutableData dataWithLength: full_length + half_length]; + BOOL done = NO; + int status; + + z_stream strm; + strm.next_in = (Bytef *)[data bytes]; + strm.avail_in = (unsigned int)[data length]; + strm.total_out = 0; + strm.zalloc = Z_NULL; + strm.zfree = Z_NULL; + + if (inflateInit2(&strm, (15+32)) != Z_OK) return nil; + while (!done){ + if (strm.total_out >= [decompressed length]) + [decompressed increaseLengthBy: half_length]; + strm.next_out = [decompressed mutableBytes] + strm.total_out; + strm.avail_out = (unsigned int)( [decompressed length] - strm.total_out ); + + // Inflate another chunk. + status = inflate (&strm, Z_SYNC_FLUSH); + if (status == Z_STREAM_END) done = YES; + else if (status != Z_OK) break; + } + if (inflateEnd (&strm) != Z_OK) return nil; + + // Set real length. + if (done){ + [decompressed setLength: strm.total_out]; + return [NSData dataWithData: decompressed]; + } + return nil; +} + ++(void) clearCachesPath { + NSFileManager *fileManager = [NSFileManager defaultManager]; + NSString* rootPath = [LVUtil PathForCachesResource:LUAVIEW_ROOT_PATH]; + if( rootPath ) { + NSArray *contents = [fileManager contentsOfDirectoryAtPath:rootPath error:NULL]; + NSEnumerator *e = [contents objectEnumerator]; + NSString *filename; + while ((filename = [e nextObject])) { + if( [fileManager removeItemAtPath:[rootPath stringByAppendingPathComponent:filename] error:NULL] ) { + LVLog ( @"delete File: %@", filename ); + } else { + LVError( @"delete File: %@", filename ); + } + } + } +} + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/PKG/LVZipArchive.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/PKG/LVZipArchive.h new file mode 100644 index 00000000..45de2974 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/PKG/LVZipArchive.h @@ -0,0 +1,39 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import + +@interface LVZipEntry : NSObject + +@property(nonatomic, readonly) NSString *fileName; + +@property(nonatomic, readonly, getter=isSymlink) BOOL symlink; +@property(nonatomic, readonly, getter=isDirectory) BOOL directory; +@property(nonatomic, readonly) NSInteger permissions; +@property(nonatomic, readonly) NSDate *lastModDate; + +@property(nonatomic, readonly) NSData *data; +@property(nonatomic, readonly) NSData *inflatedData; + +@end + +@interface LVZipArchive : NSObject + +@property(nonatomic, readonly) NSData *data; +@property(nonatomic, readonly) NSArray *entries; + ++ (LVZipArchive *)archiveWithData:(NSData *)data; ++ (BOOL)unzipData:(NSData *)data toDirectory:(NSString *)path; + +- (BOOL)unzipToDirectory:(NSString *)path; + +- (NSDate *)lastModDate; //修改日期 + +-(NSString*) timeIntervalStr; //时间戳 + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/PKG/LVZipArchive.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/PKG/LVZipArchive.m new file mode 100644 index 00000000..791ceb3a --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/PKG/LVZipArchive.m @@ -0,0 +1,538 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVZipArchive.h" +#import "LVUtil.h" +#import + +static const UInt32 kCDHeaderMagicNumber = 0x02014B50; +static const UInt32 kCDHeaderFixedDataLength = 46; + +static const UInt32 kCDTrailerMagicNumber = 0x06054B50; + +static const UInt32 kLFHeaderMagicNumber = 0x04034B50; +static const UInt32 kLFHeaderFixedDataLength = 30; + +struct LVZipBuffer { + void *bytes; + NSInteger size; + NSInteger offset; +}; + +static bool buffer_initWithData(struct LVZipBuffer *buffer, NSData *data, NSUInteger offset) { + buffer->bytes = (void *)data.bytes; + buffer->size = data.length; + buffer->offset = offset; + + return true; +} + +static UInt16 buffer_readInt16(struct LVZipBuffer *buffer) { + UInt16 result = CFSwapInt16LittleToHost(*(UInt16 *)(buffer->bytes + buffer->offset)); + buffer->offset += 2; + + return result; +} + +static UInt32 buffer_readInt32(struct LVZipBuffer *buffer) { + UInt32 result = CFSwapInt32LittleToHost(*(UInt32 *)(buffer->bytes + buffer->offset)); + buffer->offset += 4; + + return result; +} + +static void *buffer_position(struct LVZipBuffer *buffer) { + return (void *)buffer->bytes + buffer->offset; +} + +static bool buffer_skip(struct LVZipBuffer *buffer, NSInteger length) { + NSInteger offset = buffer->offset + length; + if (offset < 0 || offset >= buffer->size) { + return false; + } + + buffer->offset = offset; + + return true; +} + +static bool buffer_seekInt32(struct LVZipBuffer *buffer, UInt32 value) { + NSInteger offset = buffer->size - 4; + + while (offset > 0) { + UInt32 temp = CFSwapInt32LittleToHost(*(UInt32 *)(buffer->bytes + offset)); + if (temp == value) { + buffer->offset = offset; + return true; + } + offset--; + } + + return false; +} + +struct LVZipTrailer { + UInt32 magicNumber; + UInt16 diskNumber; + UInt16 diskNumberWithStart; + UInt16 numberOfEntries; + UInt16 totalNumberOfEntries; + UInt32 sizeOfEntries; + UInt32 startOfEntries; + UInt16 commentLength; + char *comment; +}; + +static bool trailer_initWithData(struct LVZipTrailer *trailer, NSData *data) { + UInt32 trailerCheck = 0; + struct LVZipBuffer buffer = {0}; + buffer_initWithData(&buffer, data, [data length] - sizeof(trailerCheck)); + if (!buffer_seekInt32(&buffer, kCDTrailerMagicNumber)) { + return false; + } + if (buffer.offset < 1) { + return false; + } + + UInt32 mn = buffer_readInt32(&buffer); + assert(mn == kCDTrailerMagicNumber); + + trailer->magicNumber = mn; + trailer->diskNumber = buffer_readInt16(&buffer); + trailer->diskNumberWithStart = buffer_readInt16(&buffer); + trailer->numberOfEntries = buffer_readInt16(&buffer); + trailer->totalNumberOfEntries = buffer_readInt16(&buffer); + trailer->sizeOfEntries = buffer_readInt32(&buffer); + trailer->startOfEntries = buffer_readInt32(&buffer); + trailer->commentLength = buffer_readInt16(&buffer); + if (trailer->commentLength) { + trailer->comment = (char *)buffer_position(&buffer); + } + + return true; +} + +struct LVZipCDHeader { + UInt32 magicNumber; + UInt16 versionMadeBy; + UInt16 versionNeededToExtract; + UInt16 generalPurposeBitFlag; + UInt16 compressionMethod; + UInt32 lastModDate; + UInt32 crc; + UInt16 filenameLength; + UInt16 extraFieldLength; + UInt16 commentLength; + UInt16 diskNumberStart; + UInt16 internalFileAttributes; + UInt32 externalFileAttributes; + UInt64 localHeaderOffset; + + UInt64 compressedSize; + UInt64 uncompressedSize; + + char *filename; + void *extraField; + char *comment; + void *cachedData; +}; + +static bool cdheader_initWithData(struct LVZipCDHeader *header, void *start) { + struct LVZipBuffer buffer = { start, NSUIntegerMax, 0 }; + + UInt32 mn = buffer_readInt32(&buffer); + assert(mn == kCDHeaderMagicNumber); + + header->magicNumber = mn; + header->versionMadeBy = buffer_readInt16(&buffer); + header->versionNeededToExtract = buffer_readInt16(&buffer); + header->generalPurposeBitFlag = buffer_readInt16(&buffer); + header->compressionMethod = buffer_readInt16(&buffer); + header->lastModDate = buffer_readInt32(&buffer); + header->crc = buffer_readInt32(&buffer); + header->compressedSize = buffer_readInt32(&buffer); + header->uncompressedSize = buffer_readInt32(&buffer); + header->filenameLength = buffer_readInt16(&buffer); + header->extraFieldLength = buffer_readInt16(&buffer); + header->commentLength = buffer_readInt16(&buffer); + header->diskNumberStart = buffer_readInt16(&buffer); + header->internalFileAttributes = buffer_readInt16(&buffer); + header->externalFileAttributes = buffer_readInt32(&buffer); + header->localHeaderOffset = buffer_readInt32(&buffer); + + if (header->filenameLength) { + header->filename = (char *)buffer_position(&buffer); + buffer_skip(&buffer, header->filenameLength); + } + if (header->extraFieldLength) { + header->extraField = buffer_position(&buffer); + buffer_skip(&buffer, header->extraFieldLength); + } + if (header->commentLength) { + header->comment = (char *)buffer_position(&buffer); + } + + return true; +} + +static NSString *cdheader_getFileName(struct LVZipCDHeader *header) { + if (header->filenameLength == 0) { + return nil; + } + + NSData *data = [NSData dataWithBytes:header->filename length:header->filenameLength]; + NSString *name = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; + return name; +} + +static NSUInteger cdheader_getLength(struct LVZipCDHeader *header) { + return kCDHeaderFixedDataLength + + header->filenameLength + + header->commentLength + + header->extraFieldLength; +} + +static NSInteger cdheader_getPermissions(struct LVZipCDHeader *header) { + return (header->externalFileAttributes >> 16 & 0x1FF) ?: 0755U; +} + +static NSDate *cdheader_getLastModDate(struct LVZipCDHeader *header) { + // convert dos time + UInt32 dtime = header->lastModDate; + + NSDateComponents *comps = [NSDateComponents new]; + comps.year = (int)(((dtime >> 25) & 0x7f) + 1980); + comps.month = (int)((dtime >> 21) & 0x0f); + comps.day = (int)((dtime >> 16) & 0x1f); + comps.hour = (int)((dtime >> 11) & 0x1f); + comps.minute = (int)((dtime >> 5) & 0x3f); + comps.second = (int)((dtime << 1) & 0x3e); + + return [[NSCalendar currentCalendar] dateFromComponents:comps]; +} + +static NSInteger cdheader_getFileType(struct LVZipCDHeader *header) { + return header->externalFileAttributes >> 29 & 0x1F; +} + +static bool cdheader_isDirecotry(struct LVZipCDHeader *header) { + return cdheader_getFileType(header) == 0x02; +} + +static bool cdheader_isSymlink(struct LVZipCDHeader *header) { + return cdheader_getFileType(header) == 0x05; +} + +struct LVZipLFHeader { + UInt32 magicNumber; + UInt32 versionNeededToExtract; + UInt32 generalPurposeBitFlag; + UInt32 compressionMethod; + UInt32 lastModDate; + UInt32 crc; + UInt64 compressedSize; + UInt64 uncompressedSize; + UInt32 filenameLength; + UInt32 extraFieldLength; + char *filename; + void *extraField; +}; + +static bool lfheader_initWithData(struct LVZipLFHeader *header, void *start) { + struct LVZipBuffer buffer = { start, NSUIntegerMax, 0 }; + + UInt32 mn = buffer_readInt32(&buffer); + assert(mn == kLFHeaderMagicNumber); + + header->magicNumber = mn; + header->versionNeededToExtract = buffer_readInt16(&buffer); + header->generalPurposeBitFlag = buffer_readInt16(&buffer); + header->compressionMethod = buffer_readInt16(&buffer); + header->lastModDate = buffer_readInt32(&buffer); + header->crc = buffer_readInt32(&buffer); + header->compressedSize = buffer_readInt32(&buffer); + header->uncompressedSize = buffer_readInt32(&buffer); + header->filenameLength = buffer_readInt16(&buffer); + header->extraFieldLength = buffer_readInt16(&buffer); + + if (header->filenameLength > 0) { + header->filename = (char *)buffer_position(&buffer); + buffer_skip(&buffer, header->filenameLength); + } + if (header->extraFieldLength > 0) { + header->extraField = (char *)buffer_position(&buffer); + } + + return true; +} + +static NSUInteger lfheader_getLength(struct LVZipLFHeader *header) { + return kLFHeaderFixedDataLength + + header->filenameLength + + header->extraFieldLength; +} + +@interface LVZipArchive () + +@property(nonatomic, strong) NSData *data; +@property(nonatomic, strong) NSArray *entries; + +@end + +@interface LVZipEntry () + +@property(nonatomic, assign) struct LVZipCDHeader internalHeader; +@property(nonatomic, strong) NSData *data; + +@end + +@implementation LVZipArchive + ++ (LVZipArchive *)archiveWithData:(NSData *)data { + struct LVZipTrailer trailer = {0}; + if (!trailer_initWithData(&trailer, data)) { + return nil; + } + + LVZipArchive *archive = [self new]; + archive.data = data; + + NSMutableArray *entries = [NSMutableArray array]; + struct LVZipCDHeader header = {0}; + LVZipEntry *entry = nil; + unsigned long long offset = trailer.startOfEntries; + for (NSUInteger i = 0; i < trailer.totalNumberOfEntries; i++) { + if (cdheader_initWithData(&header, (void *)(data.bytes + offset))) { + entry = [LVZipEntry new]; + entry.internalHeader = header; + [archive fillContentOfEntry:entry]; + [entries addObject:entry]; + + offset += cdheader_getLength(&header); + } else { + break; + } + } + + archive.entries = entries; + + return archive; +} + +- (NSDate *) lastModDate { + NSDate* date0 = self.entries.firstObject.lastModDate; + for( LVZipEntry * entry in self.entries ){ + NSDate* date2 = entry.lastModDate; + if( [date2 timeIntervalSinceDate:date0]>0 ) { + date0 = date2; + } + } + return date0; +} + +- (NSString*) timeIntervalStr{ + NSDate* date = [self lastModDate]; + long long s = (long long)( [date timeIntervalSince1970] ); + NSString *timeStr = [NSString stringWithFormat:@"%lld", s]; + return timeStr; +} + ++ (BOOL)unzipData:(NSData *)data toDirectory:(NSString *)path { + LVZipArchive *archive = [self archiveWithData:data]; + return [archive unzipToDirectory:path]; +} + +- (BOOL)unzipToDirectory:(NSString *)path { + if (path == nil) { + return NO; + } + + NSFileManager *fm = [NSFileManager defaultManager]; + if (![fm createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:NULL]) { + LVLog(@"create directory(%@) error!", path); + return NO; + } + + NSDictionary *attrs = nil; + NSData *inflatedData = nil; + NSString *fileName = nil, *fullPath = nil; + NSError *error = nil; + for (LVZipEntry *entry in self.entries) { + error = nil; + attrs = [self attributes:entry]; + inflatedData = entry.inflatedData; + fileName = entry.fileName; + fullPath = [path stringByAppendingPathComponent:fileName]; + + if ([entry isDirectory]) { + BOOL r = [fm createDirectoryAtPath:fullPath + withIntermediateDirectories:YES + attributes:attrs + error:&error]; + if (!r) { + LVLog(@"create directory(%@) entry error:", fileName, error); + return NO; + } + } else if ([entry isSymlink]) { + NSString *dest = [[NSString alloc] initWithData:inflatedData + encoding:NSUTF8StringEncoding]; + BOOL r = [fm createSymbolicLinkAtPath:fullPath + withDestinationPath:dest + error:&error]; + if (!r) { + LVLog(@"create symlink(%@) entry error:", fileName, error); + return NO; + } + [fm setAttributes:attrs ofItemAtPath:fullPath error:NULL]; + } else { + NSString *dir = [fileName stringByDeletingLastPathComponent]; + if ([dir length] > 0) { + NSString *fullDirPath = [path stringByAppendingPathComponent:dir]; + BOOL isDir = NO, r = NO; + if (![fm fileExistsAtPath:fullDirPath isDirectory:&isDir]) { + r = [fm createDirectoryAtPath:fullDirPath + withIntermediateDirectories:YES + attributes:nil + error:&error]; + if (!r) { + LVLog(@"create file(%@)'s parent directory error:%@", fileName, error); + return NO; + } + } else if (!isDir) { + r = [fm removeItemAtPath:fullDirPath error:&error]; + if (!r) { + LVLog(@"remove exist file(%@) error:%@", dir, error); + return NO; + } + r = [fm createDirectoryAtPath:fullDirPath + withIntermediateDirectories:YES + attributes:nil + error:NULL]; + if (!r) { + LVLog(@"create file(%@)'s parent directory error:%@", fileName, error); + return NO; + } + } + } + + BOOL r = [fm createFileAtPath:fullPath contents:inflatedData attributes:attrs]; + if (!r) { + LVLog(@"create file(%@) entry error", fileName); + return NO; + } + } + } + + return YES; +} + +- (void)fillContentOfEntry:(LVZipEntry *)entry { + if ([entry isDirectory]) { + return; + } + + struct LVZipLFHeader lfHeader = {0}; + void *start = (void *)(self.data.bytes + entry.internalHeader.localHeaderOffset); + if (!lfheader_initWithData(&lfHeader, start)) { + return; + } + + NSUInteger location = (NSUInteger)entry.internalHeader.localHeaderOffset + lfheader_getLength(&lfHeader); + NSUInteger length = (NSUInteger)entry.internalHeader.compressedSize; + entry.data = [self.data subdataWithRange:NSMakeRange(location, length)]; +} + +- (NSDictionary *)attributes:(LVZipEntry *)entry { + if ([entry isDirectory] || [entry isSymlink]) { + return nil; + } + + return @{ NSFilePosixPermissions: @([entry permissions]), + NSFileCreationDate: [entry lastModDate], + NSFileModificationDate: [entry lastModDate] }; +} + +@end + +@implementation LVZipEntry + +@synthesize inflatedData = _inflatedData; +@dynamic fileName, symlink, directory, permissions, lastModDate; + +- (NSString *)fileName { + return cdheader_getFileName(&_internalHeader); +} + +- (NSInteger)permissions { + return cdheader_getPermissions(&_internalHeader); +} + +- (BOOL)isDirectory { + return cdheader_isDirecotry(&_internalHeader) || [[self fileName] hasSuffix:@"/"]; +} + +- (BOOL)isSymlink { + return cdheader_isSymlink(&_internalHeader); +} + +- (NSDate *)lastModDate { + return cdheader_getLastModDate(&_internalHeader); +} + +- (NSData *)inflatedData { + if (_inflatedData) { + return _inflatedData; + } + + if (!_data) { + return nil; + } + + if (_internalHeader.compressionMethod == Z_NO_COMPRESSION || [self isSymlink]) { + _inflatedData = _data; + } else { + _inflatedData = [self inflateData:_data]; + } + + return _inflatedData; +} + +- (NSData *) inflateData:(NSData *)data { + NSUInteger length = [data length]; + NSUInteger halfLength = length / 2; + + NSMutableData *inflatedData = [NSMutableData dataWithLength:length + halfLength]; + BOOL done = NO; + int status; + + z_stream strm; + + strm.next_in = (Bytef *)data.bytes; + strm.avail_in = (unsigned int)[data length]; + strm.total_out = 0; + strm.zalloc = Z_NULL; + strm.zfree = Z_NULL; + + if (inflateInit2(&strm, -MAX_WBITS) != Z_OK) return nil; + while (!done) { + if (strm.total_out >= [inflatedData length]) + [inflatedData increaseLengthBy:halfLength]; + strm.next_out = [inflatedData mutableBytes] + strm.total_out; + strm.avail_out = (unsigned int)([inflatedData length] - strm.total_out); + status = inflate(&strm, Z_SYNC_FLUSH); + if (status == Z_STREAM_END) done = YES; + else if (status != Z_OK) break; + } + if (inflateEnd(&strm) == Z_OK && done) + [inflatedData setLength:strm.total_out]; + else + inflatedData = nil; + return inflatedData; +} + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/RSA/LVRSA.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/RSA/LVRSA.h new file mode 100644 index 00000000..2806d47c --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/RSA/LVRSA.h @@ -0,0 +1,24 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import + +@interface LVRSA : NSObject + +-(BOOL) verifyData:(NSData*)data withSignedData:(NSData*) sign; + +-(NSData*) aesKeyBytes; + +/* + * 设置证书名 + */ +- (void) setPublicKeyFilePath:(NSString*) filePath; + +NSData* lv_SHA256HashBytes(NSData *fileData); + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/RSA/LVRSA.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/RSA/LVRSA.m new file mode 100644 index 00000000..5852c768 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/RSA/LVRSA.m @@ -0,0 +1,252 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVRSA.h" +#import +#import +#import +#import +#import +#import "LVUtil.h" + +@implementation LVRSA { + NSData* g_keyBytes; + SecKeyRef g_publicKey; + NSString* g_publicKeyFilePath; +} + +-(void) dealloc{ + LVReleaseAndNull(g_publicKey); +} + +NSError* lv_verifySignSHA1WithRSA(NSData *fileData, SecKeyRef pubKeyRef, NSData *signedData); + +-(BOOL) verifyData:(NSData*)data withSignedData:(NSData*) signedData{ + SecKeyRef key = [self getPublicKey]; + NSError* error = lv_verifySignSHA1WithRSA(data, key, signedData); + if( error == nil ){ + return YES; + } + LVLog(@"%@",error); + return NO; +} + +-(NSData*) aesKeyBytes{ + if( g_keyBytes==nil ) { + NSData *certificateData = [self publickKeyData]; + g_keyBytes = [LVUtil MD5HashDataFromData:certificateData]; + } + return g_keyBytes; +} + +//公共秘钥的引用: +- (SecKeyRef)getPublicKey{ + if( g_publicKey == NULL ){ + g_publicKey = [self getPublicKey0]; + } + return g_publicKey; +} + +- (void) setPublicKeyFilePath:(NSString*) filePath{ + g_publicKeyFilePath = filePath; +} + +-(NSData*) publickKeyData{ + if( g_publicKeyFilePath==nil ) + g_publicKeyFilePath = [[NSBundle mainBundle] pathForResource:@"public_key" ofType:@"der"]; + + NSData *certificateData = [NSData dataWithContentsOfFile:g_publicKeyFilePath]; + return certificateData; +} + +- (SecKeyRef)getPublicKey0 +{ + NSData *certificateData = [self publickKeyData]; + if ( certificateData==nil ){ + return NULL; + } + SecCertificateRef myCertificate = NULL; + myCertificate = SecCertificateCreateWithData(kCFAllocatorDefault, (__bridge CFDataRef)certificateData); + SecPolicyRef myPolicy = SecPolicyCreateBasicX509(); + SecTrustRef myTrust = NULL; + OSStatus status = SecTrustCreateWithCertificates(myCertificate,myPolicy,&myTrust); + SecTrustResultType trustResult; + if (status == noErr) { + status = SecTrustEvaluate(myTrust, &trustResult); + if( status == noErr ){ + LVReleaseAndNull(myPolicy); + LVReleaseAndNull(myCertificate); + SecKeyRef ret = SecTrustCopyPublicKey(myTrust); + LVReleaseAndNull(myTrust); + return ret; + } + } + LVReleaseAndNull(myPolicy); + LVReleaseAndNull(myCertificate); + return NULL; +} + +//加密: +- (NSData*)rsaEncryptWithData:(NSData*)data usingKey:(SecKeyRef)key{ + + size_t cipherBufferSize = SecKeyGetBlockSize(key); + uint8_t *cipherBuffer = malloc(cipherBufferSize * sizeof(uint8_t)); + memset((void *)cipherBuffer, 0*0, cipherBufferSize); + + NSData *plainTextBytes = data; + size_t blockSize = cipherBufferSize - 11; + size_t blockCount = (size_t)ceil([plainTextBytes length] / (double)blockSize); + NSMutableData *encryptedData = [NSMutableData dataWithCapacity:0]; + + for (int i=0; i0 && key.length>0 ) { + NSUInteger dataLength = [data length]; + + // See the doc: For block ciphers, the output size will always be less than or + // equal to the input size plus the size of one block. + // That's why we need to add the size of one block here + size_t bufferSize = (dataLength + kCCKeySizeAES256); + void *buffer = malloc(bufferSize); + bzero(buffer, sizeof(bufferSize)); + + size_t numBytesDecrypted = 0; + CCCryptorStatus cryptStatus = CCCrypt(kCCDecrypt, kCCAlgorithmAES128, kCCOptionPKCS7Padding, + key.bytes, key.length, + NULL /* initialization vector (optional) */, + [data bytes], dataLength, /* input */ + buffer, bufferSize, /* output */ + &numBytesDecrypted); + + if ( cryptStatus == kCCSuccess ) { + return [NSData dataWithBytesNoCopy:buffer length:numBytesDecrypted]; + } + + free(buffer); //free the buffer; + return nil; + } + return nil; +} + +#define kChosenDigestLength CC_SHA1_DIGEST_LENGTH // SHA-1消息摘要的数据位数160位 +NSData* lv_SHA1HashBytes(NSData *fileData){ + CC_SHA1_CTX ctx; + uint8_t * hashBytes = NULL; + NSData * hash = nil; + + // Malloc a buffer to hold hash. + hashBytes = malloc( kChosenDigestLength * sizeof(uint8_t) ); + memset((void *)hashBytes, 0x0, kChosenDigestLength); + // Initialize the context. + CC_SHA1_Init(&ctx); + // Perform the hash. + CC_SHA1_Update(&ctx, (void *)[fileData bytes], (CC_LONG)[fileData length]); + // Finalize the output. + CC_SHA1_Final(hashBytes, &ctx); + + // Build up the SHA1 blob. + hash = [NSData dataWithBytes:(const void *)hashBytes length:(NSUInteger)kChosenDigestLength]; + if (hashBytes) free(hashBytes); + + return hash; +} + + +NSData* lv_SHA256HashBytes(NSData *fileData){ + CC_SHA256_CTX ctx; + uint8_t * hashBytes = NULL; + NSData * hash = nil; + + // Malloc a buffer to hold hash. + hashBytes = malloc( CC_SHA256_DIGEST_LENGTH * sizeof(uint8_t) ); + memset((void *)hashBytes, 0x0, CC_SHA256_DIGEST_LENGTH); + // Initialize the context. + CC_SHA256_Init(&ctx); + // Perform the hash. + CC_SHA256_Update(&ctx, (void *)[fileData bytes], (CC_LONG)[fileData length]); + // Finalize the output. + CC_SHA256_Final(hashBytes, &ctx); + + // Build up the SHA256 blob. + hash = [NSData dataWithBytes:(const void *)hashBytes length:(NSUInteger)CC_SHA256_DIGEST_LENGTH]; + if ( hashBytes ) { + free(hashBytes); + } + return hash; +} + +NSError* lv_verifySignSHA1WithRSA(NSData *fileData, SecKeyRef pubKeyRef, NSData *signedData){ + if(!fileData || !pubKeyRef || !signedData){ + return [NSError errorWithDomain:@"" code:-1 userInfo:@{@"desc":[NSString stringWithFormat:@"input error fileData=%p pubKeyRef=%p signedData=%p", fileData, pubKeyRef, signedData]}]; + } + OSStatus sanityCheck = noErr; + + NSData *hash = lv_SHA1HashBytes(fileData); + size_t signedHashBytesSize = SecKeyGetBlockSize(pubKeyRef); + //kSecPaddingPKCS1SHA1 kSecPaddingPKCS1MD5 + sanityCheck = SecKeyRawVerify(pubKeyRef, kSecPaddingPKCS1SHA1, [hash bytes], kChosenDigestLength, [signedData bytes], signedHashBytesSize); + + // NS Log(@"data=%@\n hash=%@\n signed=%@", fileData, hash, signedData); + if (sanityCheck == noErr){ + return nil; + }else{ + return [NSError errorWithDomain:@"" code:sanityCheck userInfo:@{@"desc":[NSString stringWithFormat:@"verifySign failed OSStatus=%d", (int)sanityCheck]}]; + } +} + +@end + + + diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXCSSParser.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXCSSParser.h new file mode 100644 index 00000000..3970828e --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXCSSParser.h @@ -0,0 +1,77 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import + +@class JUFLXNode; +@interface JUFLXCSSParser : NSObject + ++ (void)parseInlineCSS:(NSString *)inlineCSS toNode:(JUFLXNode *)node; + +@end + + +/* + * --------------------------------------------------------------------------- + * The valid css value + * --------------------------------------------------------------------------- + */ +/* +NSString * const kHRCSSPosition = @"position"; +NSString * const kHRCSSPositionAbsolute = @"absolute"; +NSString * const kHRCSSPositionTop = @"top"; +NSString * const kHRCSSPositionLeft = @"left"; +NSString * const kHRCSSPositionBottom = @"bottom"; +NSString * const kHRCSSPositionRight = @"right"; + +NSString * const kHRCSSDirection = @"flex-direction"; +NSString * const kHRCSSDirectionRow = @"row"; +NSString * const kHRCSSDirectionRowReverse = @"row-reverse"; +NSString * const kHRCSSDirectionColumn = @"column"; +NSString * const kHRCSSDirectionColumnReverse = @"column-reverse"; + +NSString * const kHRCSSAlignItems = @"align-items"; +NSString * const kHRCSSAlignContent = @"align-content"; +NSString * const kHRCSSAlignSelf = @"align-self"; +NSString * const kHRCSSAlignAuto = @"auto"; +NSString * const kHRCSSAlignStart = @"flex-start"; +NSString * const kHRCSSAlignCenter = @"center"; +NSString * const kHRCSSAlignEnd = @"flex-end"; +NSString * const kHRCSSAlignStretch = @"stretch"; + +NSString * const kHRCSSJustification = @"justify-content"; +NSString * const kHRCSSJustificationStart = @"flex-start"; +NSString * const kHRCSSJustificationCenter = @"center"; +NSString * const kHRCSSJustificationEnd = @"flex-end"; +NSString * const kHRCSSJustificationBetween = @"space-between"; +NSString * const kHRCSSJustificationAround = @"space-around"; + +NSString * const kHRCSSFlex = @"flex"; +NSString * const kHRCSSFlexWrap = @"flex-wrap"; + +NSString * const kHRCSSDimensionWidth = @"width"; +NSString * const kHRCSSDimensionHeight = @"height"; + +NSString * const kHRCSSMinDimensionWidth = @"min-width"; +NSString * const kHRCSSMinDimensionHeight = @"min-height"; + +NSString * const kHRCSSMaxDimensionWidth = @"max-width"; +NSString * const kHRCSSMaxDimensionHeight = @"max-height"; + +NSString * const kHRCSSMargin = @"margin"; +NSString * const kHRCSSMarginLeft = @"margin-left"; +NSString * const kHRCSSMarginTop = @"margin-top"; +NSString * const kHRCSSMarginBottom = @"margin-bottom"; +NSString * const kHRCSSMarginRight = @"margin-right"; + +NSString * const kHRCSSPadding = @"padding"; +NSString * const kHRCSSPaddingLeft = @"padding-left"; +NSString * const kHRCSSPaddingTop = @"padding-top"; +NSString * const kHRCSSPaddingBottom = @"padding-bottom"; +NSString * const kHRCSSPaddingRight = @"padding-right"; +*/ diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXCSSParser.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXCSSParser.m new file mode 100644 index 00000000..3d0e663d --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXCSSParser.m @@ -0,0 +1,326 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ +#import "JUFLXCSSParser.h" +#import "JUFLXNode.h" + +static inline BOOL isValidFloatString(NSString *floatString) { + BOOL valid = NO; + if (floatString && [floatString isKindOfClass:[NSString class]]) { + CGFloat fv = [floatString floatValue]; + valid = fv != NSNotFound; + } + + return valid; +} + +static inline CGFloat getFloatFromString(NSString *string, CGFloat defaultValue) { + CGFloat result = defaultValue; + if (isValidFloatString(string)) { + result = [string floatValue]; + } + + return result; +} + +NSString * const kHRCSSPosition = @"position"; +NSString * const kHRCSSPositionAbsolute = @"absolute"; +NSString * const kHRCSSPositionTop = @"top"; +NSString * const kHRCSSPositionLeft = @"left"; +NSString * const kHRCSSPositionBottom = @"bottom"; +NSString * const kHRCSSPositionRight = @"right"; + +NSString * const kHRCSSDirection = @"flex-direction"; +NSString * const kHRCSSDirectionRow = @"row"; +NSString * const kHRCSSDirectionRowReverse = @"row-reverse"; +NSString * const kHRCSSDirectionColumn = @"column"; +NSString * const kHRCSSDirectionColumnReverse = @"column-reverse"; + +NSString * const kHRCSSAlignItems = @"align-items"; +NSString * const kHRCSSAlignContent = @"align-content"; +NSString * const kHRCSSAlignSelf = @"align-self"; +NSString * const kHRCSSAlignAuto = @"auto"; +NSString * const kHRCSSAlignStart = @"flex-start"; +NSString * const kHRCSSAlignCenter = @"center"; +NSString * const kHRCSSAlignEnd = @"flex-end"; +NSString * const kHRCSSAlignStretch = @"stretch"; + +NSString * const kHRCSSjustifyContent = @"justify-content"; +NSString * const kHRCSSjustifyContentStart = @"flex-start"; +NSString * const kHRCSSjustifyContentCenter = @"center"; +NSString * const kHRCSSjustifyContentEnd = @"flex-end"; +NSString * const kHRCSSjustifyContentBetween = @"space-between"; +NSString * const kHRCSSjustifyContentAround = @"space-around"; + +NSString * const kHRCSSFlex = @"flex"; +NSString * const kHRCSSFlexWrap = @"flex-wrap"; + +NSString * const kHRCSSDimensionSize = @"size"; +NSString * const kHRCSSDimensionWidth = @"width"; +NSString * const kHRCSSDimensionHeight = @"height"; + +NSString * const kHRCSSMinDimensionWidth = @"min-width"; +NSString * const kHRCSSMinDimensionHeight = @"min-height"; + +NSString * const kHRCSSMaxDimensionWidth = @"max-width"; +NSString * const kHRCSSMaxDimensionHeight = @"max-height"; + +NSString * const kHRCSSMargin = @"margin"; +NSString * const kHRCSSMarginLeft = @"margin-left"; +NSString * const kHRCSSMarginTop = @"margin-top"; +NSString * const kHRCSSMarginBottom = @"margin-bottom"; +NSString * const kHRCSSMarginRight = @"margin-right"; + +NSString * const kHRCSSPadding = @"padding"; +NSString * const kHRCSSPaddingLeft = @"padding-left"; +NSString * const kHRCSSPaddingTop = @"padding-top"; +NSString * const kHRCSSPaddingBottom = @"padding-bottom"; +NSString * const kHRCSSPaddingRight = @"padding-right"; + +NSString * const kHRCSSSizeToFit = @"sizetofit"; + +@implementation JUFLXCSSParser + +/** + * Stand is @"diretion:row;alignitems:auto;justifyContent:start" + */ ++ (NSDictionary *)transferInlineCSS:(NSString *)inlineCSS { + if ([inlineCSS hasPrefix:@"{"]) inlineCSS = [inlineCSS substringFromIndex:1]; + if ([inlineCSS hasSuffix:@"}"]) inlineCSS = [inlineCSS substringToIndex:inlineCSS.length - 1]; + + + NSArray *inlineArray = [inlineCSS componentsSeparatedByString:@","]; + if (inlineArray.count == 0) { + if (inlineCSS.length > 0) { + NSLog(@"===>JUFLXNode inlineCSS string maybe be wrong, check it %@", inlineCSS); + return nil; + } + }; + + NSMutableDictionary *result = [NSMutableDictionary dictionary]; + NSCharacterSet *whiteAndNewLine = [NSCharacterSet whitespaceAndNewlineCharacterSet]; + + for (NSString *kv in inlineArray) { + NSArray *kvArray = [kv componentsSeparatedByString:@":"]; + if (kvArray.count == 2) { + NSString *key = kvArray[0]; + NSString *value = kvArray[1]; + if ([key isKindOfClass:[NSString class]] + && key.length > 0 + && [value isKindOfClass:[NSString class]] + && value.length > 0) { + + key = [[key stringByTrimmingCharactersInSet:whiteAndNewLine] lowercaseString]; + value = [[value stringByTrimmingCharactersInSet:whiteAndNewLine] lowercaseString]; + result[key] = value; + } + } + } + + return result; +} + ++ (NSSet *)validInlineCssKeys { + static dispatch_once_t onceToken; + static NSSet *set; + dispatch_once(&onceToken, ^{ + set = [NSSet setWithObjects: + kHRCSSPosition, + kHRCSSPositionTop, + kHRCSSPositionLeft, + kHRCSSPositionBottom, + kHRCSSPositionRight, + kHRCSSDirection, + kHRCSSAlignItems, + kHRCSSAlignContent, + kHRCSSjustifyContent, + kHRCSSFlexWrap, + kHRCSSAlignSelf, + kHRCSSFlex, + kHRCSSDimensionSize, + kHRCSSDimensionWidth, + kHRCSSDimensionHeight, + kHRCSSMinDimensionWidth, + kHRCSSMinDimensionHeight, + kHRCSSMaxDimensionWidth, + kHRCSSMaxDimensionHeight, + kHRCSSMargin, + kHRCSSMarginTop, + kHRCSSMarginLeft, + kHRCSSMarginBottom, + kHRCSSMarginRight, + kHRCSSPadding, + kHRCSSPaddingTop, + kHRCSSPaddingLeft, + kHRCSSPaddingBottom, + kHRCSSPaddingRight, + kHRCSSSizeToFit, + nil]; + }); + return set; + +} + ++ (NSDictionary *)validDirections { + static dispatch_once_t onceToken; + static NSDictionary *dic; + dispatch_once(&onceToken, ^{ + dic = @{kHRCSSDirectionColumn : @(JUFLXLayoutDirectionColumn), + kHRCSSDirectionRow : @(JUFLXLayoutDirectionRow), + kHRCSSDirectionRowReverse : @(JUFLXLayoutDirectionRowReverse), + kHRCSSDirectionColumnReverse : @(JUFLXLayoutDirectionColumnReverse)}; + }); + return dic; +} + ++ (NSDictionary *)validAlignments { + static dispatch_once_t onceToken; + static NSDictionary *dic; + dispatch_once(&onceToken, ^{ + dic = @{kHRCSSAlignAuto : @(JUFLXLayoutAlignmentAuto), + kHRCSSAlignStart : @(JUFLXLayoutAlignmentStart), + kHRCSSAlignCenter : @(JUFLXLayoutAlignmentCenter), + kHRCSSAlignEnd : @(JUFLXLayoutAlignmentEnd), + kHRCSSAlignStretch : @(JUFLXLayoutAlignmentStretch)}; + }); + return dic; +} + ++ (NSDictionary *)validjustifyContents { + static dispatch_once_t onceToken; + static NSDictionary *dic; + dispatch_once(&onceToken, ^{ + dic = @{kHRCSSjustifyContentStart : @(JUFLXLayoutJustifyContentStart), + kHRCSSjustifyContentCenter : @(JUFLXLayoutJustifyContentCenter), + kHRCSSjustifyContentEnd : @(JUFLXLayoutJustifyContentEnd), + kHRCSSjustifyContentBetween : @(JUFLXLayoutJustifyContentBetween), + kHRCSSjustifyContentAround : @(JUFLXLayoutJustifyContentAround), + }; + }); + return dic; + +} + ++ (NSInteger)mappedEnumValueInDictionary:(NSDictionary *)dic withKey:(NSString *)key { + NSString *value = [dic objectForKey:key]; + if (!value) { + NSLog(@"%@ isn't a valid key in valid Dic %@", key, dic); + NSUInteger initialValue = 0; + if ([key isEqualToString:kHRCSSDirection]) { + initialValue = JUFLXLayoutDirectionRow; + + } else if ([key isEqualToString:kHRCSSAlignItems]) { + initialValue = JUFLXLayoutAlignmentStretch; + + } else if ([key isEqualToString:kHRCSSjustifyContent]) { + initialValue = JUFLXLayoutJustifyContentStart; + + } else if ([key isEqualToString:kHRCSSAlignSelf]) { + initialValue = JUFLXLayoutAlignmentAuto; + + } else if ([key isEqualToString:kHRCSSAlignContent]) { + initialValue = JUFLXLayoutAlignmentStretch; + } + + return initialValue; + } + + return [value integerValue]; +} + ++ (void)parseInlineCSS:(NSString *)inlineCSS toNode:(JUFLXNode *)node { + NSDictionary *inlineDic = [self transferInlineCSS:inlineCSS]; + + //filter the invalid key and log +#if DEBUG + id predicateBlock = ^BOOL(id evaluatedObject, NSDictionary *bindings) { + return ![[self validInlineCssKeys] containsObject:evaluatedObject]; + }; + NSArray *invalidKeys = [inlineDic.allKeys filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:predicateBlock]]; + if (invalidKeys.count) { + NSLog(@"<---JUFLXNode---> valid keys %@ doesn't contain these keys %@ \n Please check -> JUFLXNode.h", [self validInlineCssKeys], invalidKeys); + } +#endif + + NSString *position = inlineDic[kHRCSSPosition]; + node.absolute = [position isKindOfClass:[NSString class]] && [position.lowercaseString isEqualToString:@"absolute"]; + CGFloat positionTop = getFloatFromString(inlineDic[kHRCSSPositionTop], node.absoluteEdges.top); + CGFloat positionLeft = getFloatFromString(inlineDic[kHRCSSPositionLeft], node.absoluteEdges.left); + CGFloat positionBottom = getFloatFromString(inlineDic[kHRCSSPositionBottom], node.absoluteEdges.bottom); + CGFloat positionRight = getFloatFromString(inlineDic[kHRCSSPositionRight], node.absoluteEdges.right); + node.absoluteEdges = UIEdgeInsetsMake(positionTop, positionLeft, positionBottom, positionRight); + + NSString *direction = inlineDic[kHRCSSDirection]; + if (direction) node.direction = [self mappedEnumValueInDictionary:[self validDirections] withKey:direction]; + + NSString *alignItems = inlineDic[kHRCSSAlignItems]; + if (alignItems) node.alignItems = [self mappedEnumValueInDictionary:[self validAlignments] withKey:alignItems]; + + NSString *alignSelf = inlineDic[kHRCSSAlignSelf]; + if (alignSelf) node.alignSelf = [self mappedEnumValueInDictionary:[self validAlignments] withKey:alignSelf]; + + NSString *alignContent = inlineDic[kHRCSSAlignContent]; + if (alignContent) node.alignContent = [self mappedEnumValueInDictionary:[self validAlignments] withKey:alignContent]; + + NSString *justifyContent = inlineDic[kHRCSSjustifyContent]; + if (justifyContent) node.justifyContent = [self mappedEnumValueInDictionary:[self validjustifyContents] withKey:justifyContent]; + + + node.flex = getFloatFromString(inlineDic[kHRCSSFlex], node.flex); + + node.flexWrap = getFloatFromString(inlineDic[kHRCSSFlexWrap], node.flexWrap); + + NSString *size = inlineDic[kHRCSSDimensionSize]; + if (isValidFloatString(size)) { + CGFloat sizef = [size floatValue]; + node.dimensions = CGSizeMake(sizef, sizef); + } + + CGFloat width = getFloatFromString(inlineDic[kHRCSSDimensionWidth], node.dimensions.width); + CGFloat height = getFloatFromString(inlineDic[kHRCSSDimensionHeight], node.dimensions.height); + node.dimensions = CGSizeMake(width, height); + + CGFloat minWidth = getFloatFromString(inlineDic[kHRCSSMinDimensionWidth], node.minDimensions.width); + CGFloat minHeight = getFloatFromString(inlineDic[kHRCSSMinDimensionHeight], node.minDimensions.height); + node.minDimensions = CGSizeMake(minWidth, minHeight); + + CGFloat maxWidth = getFloatFromString(inlineDic[kHRCSSMaxDimensionWidth], node.maxDimensions.width); + CGFloat maxHeight = getFloatFromString(inlineDic[kHRCSSMaxDimensionHeight], node.maxDimensions.height); + node.maxDimensions = CGSizeMake(maxWidth, maxHeight); + + NSString *margin = inlineDic[kHRCSSMargin]; + if (isValidFloatString(margin)) { + CGFloat marginf = [margin floatValue]; + node.margin = UIEdgeInsetsMake(marginf, marginf, marginf, marginf); + } + + CGFloat marginTop = getFloatFromString(inlineDic[kHRCSSMarginTop], node.margin.top); + CGFloat marginLeft = getFloatFromString(inlineDic[kHRCSSMarginLeft], node.margin.left); + CGFloat marginBottom = getFloatFromString(inlineDic[kHRCSSMarginBottom], node.margin.bottom); + CGFloat marginRight = getFloatFromString(inlineDic[kHRCSSMarginRight], node.margin.right); + node.margin = UIEdgeInsetsMake(marginTop, marginLeft, marginBottom, marginRight); + + NSString *padding = inlineDic[kHRCSSPadding]; + if (isValidFloatString(padding)) { + CGFloat paddingf = [padding floatValue]; + node.padding = UIEdgeInsetsMake(paddingf, paddingf, paddingf, paddingf); + } + + CGFloat paddingTop = getFloatFromString(inlineDic[kHRCSSPaddingTop], node.padding.top); + CGFloat paddingLeft = getFloatFromString(inlineDic[kHRCSSPaddingLeft], node.padding.left); + CGFloat paddingBottom = getFloatFromString(inlineDic[kHRCSSPaddingBottom], node.padding.bottom); + CGFloat paddingRight = getFloatFromString(inlineDic[kHRCSSPaddingRight], node.padding.right); + node.padding = UIEdgeInsetsMake(paddingTop, paddingLeft, paddingBottom, paddingRight); + + CGFloat sizeToFit = getFloatFromString(inlineDic[kHRCSSSizeToFit], 0); + if (sizeToFit > 0) { + node.sizeToFit = YES; + } +} + + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXLayoutDefine.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXLayoutDefine.h new file mode 100644 index 00000000..cb54abcf --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXLayoutDefine.h @@ -0,0 +1,19 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + + +#define JUFLX_LAYOUT_NAMESPACE JUFLX + +#ifdef JUFLX_LAYOUT_NAMESPACE +// prefix all GData class names with JUFLX_LAYOUT_NAMESPACE for this target + #import "JUFLXTargeNamespace.h" +#endif + +#import "Layout.h" + + diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXLayoutKit.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXLayoutKit.h new file mode 100644 index 00000000..48b2c36f --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXLayoutKit.h @@ -0,0 +1,23 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "JUFLXNode.h" +#import "JUFLXCSSParser.h" +#import "UIView+JUFLXNode.h" +#import "JUFLXLinearLayoutView.h" + +//! Project version number for JUFLXLayoutKit. +FOUNDATION_EXPORT double JUFLXLayoutKitVersionNumber; + +//! Project version string for JUFLXLayoutKit. +FOUNDATION_EXPORT const unsigned char JUFLXLayoutKitVersionString[]; + +// In this header, you should import all the public headers of your framework using statements like #import + + diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXNode.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXNode.h new file mode 100644 index 00000000..2afd6bd1 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXNode.h @@ -0,0 +1,316 @@ +/* + * --------------------------------------------------------------------------- + * * Build base on Facebook's css_layout https://github.com/facebook/css-layout + * * css-layout based on http://www.w3.org/TR/css3-flexbox/ + * --------------------------------------------------------------------------- + */ + + +#import +#import +#import "JUFLXLayoutDefine.h" + +FOUNDATION_EXTERN CGFloat const JUFLXLayoutFloatUnDefined; + +/** + * Check -> http://www.w3.org/TR/css3-flexbox/#flex-direction-property + */ +typedef NS_ENUM(NSInteger, JUFLXLayoutDirection){ + /** + * inlineCSS -> row, → + */ + JUFLXLayoutDirectionRow = CSS_FLEX_DIRECTION_ROW, + /** + * inlineCSS -> row-reverse, ← + */ + JUFLXLayoutDirectionRowReverse = CSS_FLEX_DIRECTION_ROW_REVERSE, + /** + * inlineCSS -> column, ⬇️ + */ + JUFLXLayoutDirectionColumn = CSS_FLEX_DIRECTION_COLUMN, + /** + * inlineCSS -> column-reverse, ↑ + */ + JUFLXLayoutDirectionColumnReverse = CSS_FLEX_DIRECTION_COLUMN_REVERSE, +}; + +/** + * Check -> http://www.w3.org/TR/css3-flexbox/#propdef-align-items + * Check -> http://www.w3.org/TR/css3-flexbox/#propdef-align-content + * Check -> http://www.w3.org/TR/css3-flexbox/#propdef-align-self + */ +typedef NS_ENUM(NSInteger, JUFLXLayoutAlignment){ + /** + * inlineCSS -> auto + */ + JUFLXLayoutAlignmentAuto = CSS_ALIGN_AUTO, + /** + * inlineCSS -> flex-start + */ + JUFLXLayoutAlignmentStart = CSS_ALIGN_FLEX_START, + /** + * inlineCSS -> center + */ + JUFLXLayoutAlignmentCenter = CSS_ALIGN_CENTER, + /** + * inlineCSS -> flex-end + */ + JUFLXLayoutAlignmentEnd = CSS_ALIGN_FLEX_END, + /** + * inlineCSS -> stretch + */ + JUFLXLayoutAlignmentStretch = CSS_ALIGN_STRETCH +}; + +/** + * Check -> http://www.w3.org/TR/css3-flexbox/#propdef-justify-content + */ +typedef NS_ENUM(NSInteger, JUFLXLayoutJustifyContent){ + /** + * inlineCSS -> flex-start + */ + JUFLXLayoutJustifyContentStart = CSS_JUSTIFY_FLEX_START, + /** + * inlineCSS -> center + */ + JUFLXLayoutJustifyContentCenter = CSS_JUSTIFY_CENTER, + /** + * inlineCSS -> flex-end + */ + JUFLXLayoutJustifyContentEnd = CSS_JUSTIFY_FLEX_END, + /** + * inlineCSS -> space-between + */ + JUFLXLayoutJustifyContentBetween = CSS_JUSTIFY_SPACE_BETWEEN, + /** + * inlineCSS -> space-around + */ + JUFLXLayoutJustifyContentAround = CSS_JUSTIFY_SPACE_AROUND +}; + + + +@interface JUFLXNode : NSObject { +@public + BOOL _dirty; +} + +/** + * layout.c's node, the model of css box. + */ +@property (nonatomic, assign, readonly) css_node_t *node; + +/** + * The view initilized with. + */ +@property (nonatomic, weak, readonly) UIView *view; + +/** + * After node layout, the node's frame of the whole calculation. + */ +@property (nonatomic, assign, readonly) CGRect frame; + +/** + * The node's children node. + */ +@property (nonatomic, strong) NSArray *childNodes; + +/** + * Default is view's frame's origin + */ +@property (nonatomic, assign) CGPoint viewOrigin; + +/* + * --------------------------------------------------------------------------- + * As Container's property + * --------------------------------------------------------------------------- + */ + +/** + * If use flex box relative layout + * Default is NO + */ +@property (nonatomic, assign) BOOL absolute; + +/** + * When the position is absolute, use this adjust the position with father + * Default is {0, 0, 0, 0} + */ +@property (nonatomic, assign) UIEdgeInsets absoluteEdges; + +/** + * Check -> http://www.w3.org/TR/css3-flexbox/#flex-direction-property + * inlineCSS -> flex-direction + * Default is row + */ +@property (nonatomic, assign) JUFLXLayoutDirection direction; + +/** + * Check -> http://www.w3.org/TR/css3-flexbox/#propdef-align-items + * inlineCSS -> align-items + * Default is stretch + */ +@property (nonatomic, assign) JUFLXLayoutAlignment alignItems; + +/** + * Check -> http://www.w3.org/TR/css3-flexbox/#propdef-align-content + * inlineCSS -> align-content + * Default is stretch + * Here we don't support the between and around + */ +@property (nonatomic, assign) JUFLXLayoutAlignment alignContent; + +/** + * Check -> http://www.w3.org/TR/css3-flexbox/#propdef-justify-content + * inlineCSS -> justify-content + * Default is start + */ +@property (nonatomic, assign) JUFLXLayoutJustifyContent justifyContent; + +/** + * Check -> http://www.w3.org/TR/css3-flexbox/#flex-wrap-property + * When the container size doesn't satisfy, if use a new depends on this. + * inlineCSS -> flex-wrap + * Here we don't support wrap-reverse + */ +@property (nonatomic, assign) BOOL flexWrap; + + +/* + * --------------------------------------------------------------------------- + * As Child's property + * --------------------------------------------------------------------------- + */ + +/** + * Check -> http://www.w3.org/TR/css3-flexbox/#propdef-align-self + * inlineCSS -> align-self + * Default is auto, means depend on containers' alignItems; + */ +@property (nonatomic, assign) JUFLXLayoutAlignment alignSelf; + +/** + * Means two thing: 1. If self use the remaining space 2. how much would u share with others + * Flex-grow, eg: A node has three children---a,b,c; a.flex = 1, b.flex = 2, c.flex = 1, then a's size will be 1 / (1 + 2 + 1), + * b is 2 / (1 + 2 + 1), c is 1 / (1 + 2 + 1) + * inlineCSS -> flex + * Here we only support flex-grow as flex, not include shrink. + * Default is 0 + */ +@property (nonatomic, assign) CGFloat flex; + +/* + * --------------------------------------------------------------------------- + * As box's property + * --------------------------------------------------------------------------- + */ + +/** + * The style dimensions, default is the view's size, if you set it to {nan, nan}, + * The result frame depends on children's total size, so the children's size should be measured. + * inlineCSS ->size, width, height + * It won't be affected by JUFLXLayoutAlignment + */ +@property (nonatomic, assign) CGSize dimensions; + +/** + * ensure the min dimension of the view size. + * inlineCSS -> min-width, min-height + * Default is {0,0} + */ +@property (nonatomic, assign) CGSize minDimensions; + +/** + * ensure the max dimension of the view size. + * inlineCSS -> max-width, max-height + * Default is {0,0} + */ +@property (nonatomic, assign) CGSize maxDimensions; + +/** + * The margin of the view. + * inlineCSS -> margin, margin-top, margin-left, margin-bottom, margin-right + */ +@property (nonatomic, assign) UIEdgeInsets margin; + +/** + * The padding of the view. + * inlineCSS -> padding, padding-top, padding-left, padding-bottom, padding-right + */ +@property (nonatomic, assign) UIEdgeInsets padding; + +/** + * When encouter the view size should be calculated like text size, use this block. + * If direction is row, then width is the parent's node's frame's width, otherwise is nan. + * It will be affected by JUFLXLayoutAlignment + */ +@property (nonatomic, copy) CGSize (^measure)(CGFloat width); + +/** + * If isSizeToFit == YES, the measure block CGSize (^measure)(CGFloat width) will returned by view's + * sizeThatFits: size, the property will be override by measure block; + * Default is YES; + * It will be affected by JUFLXLayoutAlignment + * inlineCSS -> sizetofit: 1 + */ +@property (nonatomic, assign, getter=isSizeToFit) BOOL sizeToFit; + ++ (instancetype)nodeWithView:(UIView *)view; + +/** + * Create a node + * + * @param view the root view + * @param childNodes an array of JUFLXNodes + * + * @return node + */ ++ (instancetype)nodeWithView:(UIView *)view children:(NSArray *)childNodes; + +/** + * Copy the node attributes to a new view and children + * + * @param view another view + * + * @return a copy node not include the measure block + */ +- (instancetype)copyNodeWithView:(UIView *)view; +- (instancetype)copyNodeWithView:(UIView *)view + children:(NSArray *)childNodes; + + +- (instancetype)initWithView:(UIView *)view; +- (instancetype)initWithView:(UIView *)view children:(NSArray *)childNodes; + +/** + * Bind the node's property to inline css + * + * @param inlineCSS + * @see JUFLXCSSParser to learn the writing rule; + */ +- (void)bindingInlineCSS:(NSString *)inlineCSS; + +/** + * Manually layout the node + * + * @param aysnc move the node calculation back thread + * @param block completion + */ +- (void)layoutAsync:(BOOL)async completionBlock:(void(^)(CGRect frame))block; + +/** + * Layout the view tree if aysnc + */ +- (void)layoutAsync:(BOOL)async; + +/** + * Layout the view tree async + */ +- (void)layout; + +/** + * If log, use NSLog, default is NO; + */ +@property (nonatomic, assign) BOOL debugLogEnabled; + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXNode.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXNode.m new file mode 100644 index 00000000..bdce16d6 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXNode.m @@ -0,0 +1,418 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "JUFLXNode.h" +#import "UIView+JUFLXNode.h" +#import +#import "JUFLXCSSParser.h" + +@interface UIView (JUFLXNodeSetter) + +- (void)setJu_flxNode:(JUFLXNode *)node; +- (NodeDidFinishLayout)ju_flxNodeDidFinishLayoutBlock; + +@end + +CGFloat const JUFLXLayoutFloatUnDefined = CSS_UNDEFINED; + +static bool alwaysDirty(void *context) { + JUFLXNode *self = (__bridge JUFLXNode *)context; + return self->_dirty; +} + +static css_node_t *getChild(void *context, int i) { + JUFLXNode *self = (__bridge JUFLXNode *)context; + JUFLXNode *child = self.childNodes[i]; + return child.node; +} + +static css_dim_t measureNode(void *context, float width) { + JUFLXNode *self = (__bridge JUFLXNode *)context; + CGSize size = self.measure(width); + return (css_dim_t){ size.width, size.height }; +} + +@implementation JUFLXNode { + css_node_t *_node; + NSArray *_childNodes; + CGPoint _viewOrigin; +} + +@synthesize node = _node, dimensions = _dimensions, view = _view, viewOrigin = _viewOrigin; + +- (void)dealloc { + free_css_node(_node); +} + +- (instancetype)init { + return [self initWithView:[UIView new]]; +} + +- (instancetype)initWithView:(UIView *)view { + return [self initWithView:view children:nil]; +} + +- (instancetype)initWithView:(UIView *)view children:(NSArray *)childNodes { + if (self = [super init]) { + _debugLogEnabled = NO; + _dirty = YES; + _node = new_css_node(); + _node->context = (__bridge void *)self; + _node->is_dirty = alwaysDirty; + _node->get_child = getChild; + + //as container initial + self.absolute = NO; + self.absoluteEdges = UIEdgeInsetsZero; + self.direction = JUFLXLayoutDirectionColumn; + self.alignItems = JUFLXLayoutAlignmentStretch; + self.alignContent = JUFLXLayoutAlignmentStretch; + self.justifyContent = JUFLXLayoutJustifyContentStart; + self.flexWrap = NO; + + //as child initial + self.alignSelf = JUFLXLayoutAlignmentAuto; + self.margin = UIEdgeInsetsZero; + self.padding = UIEdgeInsetsZero; + self.flex = 0; + self.sizeToFit = NO; + + _view = view; + _viewOrigin = view.frame.origin; + [_view setJu_flxNode:self]; + + self.childNodes = childNodes; + } + + return self; +} + ++ (instancetype)nodeWithView:(UIView *)view { + return [self nodeWithView:view children:nil]; +} + ++ (instancetype)nodeWithView:(UIView *)view children:(NSArray *)childNodes { + return [[[self class] alloc] initWithView:view children:(NSArray *)childNodes]; +} + +- (instancetype)copyNodeWithView:(UIView *)view { + return [self copyNodeWithView:view children:nil]; +} + +- (instancetype)copyNodeWithView:(UIView *)view children:(NSArray *)childNodes { + JUFLXNode *node = [[self class] nodeWithView:view children:childNodes]; + node.direction = self.direction; + node.alignItems = self.alignItems; + node.alignContent = self.alignContent; + node.justifyContent = self.justifyContent; + node.flexWrap = self.flexWrap; + node.alignSelf = self.alignSelf; + node.flex = self.flex; + node.dimensions = self.dimensions; + node.minDimensions = self.minDimensions; + node.maxDimensions = self.maxDimensions; + node.margin = self.margin; + node.padding = self.padding; + node.sizeToFit = self.sizeToFit; + + return node; +} + +- (void)setChildNodes:(NSArray *)childNodes { + [self _resetOriginNodeViews]; + _childNodes = childNodes; + _node->children_count = (int)_childNodes.count; + [self generateViewTreeWithView:_view childNodes:_childNodes]; +} + +- (void)generateViewTreeWithView:(UIView *)view childNodes:(NSArray *)childNodes { + for (JUFLXNode *childNode in childNodes) { + [view addSubview:childNode.view]; + // only generate the node has child nodes + if ([childNode isContainer]) { + [self generateViewTreeWithView:childNode.view childNodes:childNode.childNodes]; + } + } +} + +- (BOOL)isContainer { + return _childNodes.count > 0; +} + +- (CGRect)frame { + return (CGRect) { + .origin.x = self.node->layout.position[CSS_LEFT] + _viewOrigin.x, + .origin.y = self.node->layout.position[CSS_TOP] + _viewOrigin.y, + .size.width = self.node->layout.dimensions[CSS_WIDTH], + .size.height = self.node->layout.dimensions[CSS_HEIGHT] + }; +} + +- (void)_resetOriginNodeViews { + for (JUFLXNode *subNode in _childNodes) { + if ([subNode isContainer]) { + [subNode _resetOriginNodeViews]; + } + [subNode.view removeFromSuperview]; + } +} + +- (void)_layoutWithNode { + NSTimeInterval start = CFAbsoluteTimeGetCurrent(); + + [self _resetNode]; + layoutNode(_node, self.dimensions.width, _node->style.direction); + + if (_debugLogEnabled) { + NSLog(@"%@ layout all nodes takes time %f \n on thread %@", NSStringFromClass(self.class), CFAbsoluteTimeGetCurrent() - start, [NSThread currentThread]); + } +} + +- (void)_assignNodeFrame { + self.view.frame = self.frame; + + if (self.view.ju_flxNodeDidFinishLayoutBlock) { + self.view.ju_flxNodeDidFinishLayoutBlock(self); + } + + for (JUFLXNode *subNode in _childNodes) { + if ([subNode isContainer]) { + [subNode _assignNodeFrame]; + } else { + NSLog(@"subNode frame is %@", NSStringFromCGRect(subNode.frame)); + subNode.view.frame = subNode.frame; + + if (subNode.view.ju_flxNodeDidFinishLayoutBlock) { + subNode.view.ju_flxNodeDidFinishLayoutBlock(subNode); + } + } + } +} + +- (void)_resetNode { + for (JUFLXNode *subNode in _childNodes) { + [subNode _resetNode]; + } + + self.node->layout.position[CSS_LEFT] = 0; + self.node->layout.position[CSS_TOP] = 0; + self.node->layout.position[CSS_RIGHT] = 0; + self.node->layout.position[CSS_BOTTOM] = 0; + + self.node->layout.dimensions[CSS_WIDTH] = CSS_UNDEFINED; + self.node->layout.dimensions[CSS_HEIGHT] = CSS_UNDEFINED; +} + +- (void)layoutAsync:(BOOL)aysnc completionBlock:(void(^)(CGRect frame))block { + _dirty = YES; + if (aysnc) { + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{ + [self _layoutWithNode]; + dispatch_async(dispatch_get_main_queue(), ^{ + [self _assignNodeFrame]; + _dirty = NO; + if (block) { + block(self.frame); + } + }); + }); + } else { + [self _layoutWithNode]; + [self _assignNodeFrame]; + _dirty = NO; + if (block) { + block(self.frame); + } + } +} + +- (void)layoutAsync:(BOOL)aysnc { + [self layoutAsync:aysnc completionBlock:NULL]; +} + +- (void)layout { + [self layoutAsync:NO completionBlock:NULL]; +} + +- (void)setNeedsLayout { + if (_dirty) { + [self layout]; + } +} + +- (void)setAbsolute:(BOOL)absolute { + if (_absolute == absolute) return; + _absolute = absolute; + _node->style.position_type = _absolute ? CSS_POSITION_ABSOLUTE : CSS_POSITION_RELATIVE; + _dirty = YES; +} + +- (void)setAbsoluteEdges:(UIEdgeInsets)absoluteEdges { + if (UIEdgeInsetsEqualToEdgeInsets(_absoluteEdges, absoluteEdges)) return; + _absoluteEdges = absoluteEdges; + _node->style.position[CSS_LEFT] = _absoluteEdges.left; + _node->style.position[CSS_TOP] = _absoluteEdges.top; + _node->style.position[CSS_RIGHT] = _absoluteEdges.right; + _node->style.position[CSS_BOTTOM] = _absoluteEdges.bottom; + _dirty = YES; +} + +- (CGSize)dimensions { + if (CGSizeEqualToSize(_dimensions, CGSizeZero)) { + _dimensions = self.view.bounds.size; + _node->style.dimensions[CSS_WIDTH] = _dimensions.width; + _node->style.dimensions[CSS_HEIGHT] = _dimensions.height; + } + return _dimensions; +} + +- (void)setDimensions:(CGSize)size { + if (CGSizeEqualToSize(_dimensions, size)) return; + _dimensions = size; + _node->style.dimensions[CSS_WIDTH] = size.width; + _node->style.dimensions[CSS_HEIGHT] = size.height; + _dirty = YES; +} + +- (void)setMinDimensions:(CGSize)size { + if (CGSizeEqualToSize(_minDimensions, size)) return; + _minDimensions = size; + _node->style.minDimensions[CSS_WIDTH] = size.width; + _node->style.minDimensions[CSS_HEIGHT] = size.height; + _dirty = YES; +} + +- (void)setMaxDimensions:(CGSize)size { + if (CGSizeEqualToSize(_maxDimensions, size)) return; + _maxDimensions = size; + _node->style.maxDimensions[CSS_WIDTH] = size.width; + _node->style.maxDimensions[CSS_HEIGHT] = size.height; + _dirty = YES; +} + +- (void)setMargin:(UIEdgeInsets)margin { + if (UIEdgeInsetsEqualToEdgeInsets(_margin, margin)) return; + _margin = margin; + _node->style.margin[CSS_LEFT] = margin.left; + _node->style.margin[CSS_TOP] = margin.top; + _node->style.margin[CSS_RIGHT] = margin.right; + _node->style.margin[CSS_BOTTOM] = margin.bottom; + _dirty = YES; +} + +- (void)setPadding:(UIEdgeInsets)padding { + if (UIEdgeInsetsEqualToEdgeInsets(_padding, padding)) return; + _padding = padding; + _node->style.padding[CSS_LEFT] = padding.left; + _node->style.padding[CSS_TOP] = padding.top; + _node->style.padding[CSS_RIGHT] = padding.right; + _node->style.padding[CSS_BOTTOM] = padding.bottom; + _dirty = YES; +} + +- (void)setDirection:(JUFLXLayoutDirection)direction { + if (_direction == direction) return; + _direction = direction; + _node->style.flex_direction = (int)_direction; + _dirty = YES; +} + +- (void)setAlignContent:(JUFLXLayoutAlignment)alignContent { + if (_alignContent == alignContent) return; + _alignContent = alignContent; + _node->style.align_content = (int)alignContent; + _dirty = YES; +} + +- (void)setAlignItems:(JUFLXLayoutAlignment)alignItems { + if (_alignItems == alignItems) return; + _alignItems = alignItems; + _node->style.align_items = (int)_alignItems; + _dirty = YES; +} + +- (void)setJustifyContent:(JUFLXLayoutJustifyContent)justifyContent { + if (_justifyContent == justifyContent) return; + _justifyContent = justifyContent; + _node->style.justify_content = (int)_justifyContent; + _dirty = YES; +} + +- (void)setFlexWrap:(BOOL)flexWrap { + if (_flexWrap == flexWrap) return; + _flexWrap = flexWrap; + _node->style.flex_wrap = _flexWrap; + _dirty = YES; +} + +- (void)setAlignSelf:(JUFLXLayoutAlignment)alignSelf { + if (_alignSelf == alignSelf) return; + _alignSelf = alignSelf; + _node->style.align_self = (int)_alignSelf; + _dirty = YES; +} + +- (void)setFlex:(CGFloat)flex { + if (_flex == flex) return; + _flex = flex; + _node->style.flex = _flex; + _dirty = YES; +} + +- (void)setMeasure:(CGSize (^)(CGFloat))measure { + if (measure) { + _measure = [measure copy]; + _node->measure = (_measure != nil ? measureNode : NULL); + } +} + +- (void)setSizeToFit:(BOOL)sizeToFit { + if (_sizeToFit == sizeToFit) return; + _sizeToFit = sizeToFit; + if (_sizeToFit) { + __weak typeof(self) wself = self; + self.measure = ^CGSize(CGFloat width) { + return [wself.view sizeThatFits:CGSizeMake(width, CGFLOAT_MAX)]; + }; + } + _dirty = YES; +} + +- (void)bindingInlineCSS:(NSString *)inlineCSS { + [JUFLXCSSParser parseInlineCSS:inlineCSS toNode:self]; +} + +- (NSString *)description { + NSString *selfDescription = [super description]; + if (_debugLogEnabled) { + selfDescription = [NSString stringWithFormat:@"{node's view is %@ and child nodes is \n %@", self.view, self.childNodes]; + print_css_node(_node, CSS_PRINT_STYLE | CSS_PRINT_CHILDREN | CSS_PRINT_LAYOUT); + + } + return selfDescription; +} + +@end + +@implementation UIView (JUFLXNodeSetter) + +- (void)setJu_flxNode:(JUFLXNode *)node { + JUFLXNode *currentNode = objc_getAssociatedObject(self, &JUFLXNodeUIViewNodeKey); + + if (currentNode && node != currentNode) { + NSLog(@"<---JUFLXNode Warning!--->, You are trying set a view %@ with another node %@, pay attention to this view's subViews", self, node); + } + + objc_setAssociatedObject(self, &JUFLXNodeUIViewNodeKey, node, OBJC_ASSOCIATION_RETAIN_NONATOMIC); +} + +- (NodeDidFinishLayout)ju_flxNodeDidFinishLayoutBlock { + return objc_getAssociatedObject(self, &JUFLXNodeUIViewDidFinishBlockKey); +} + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXTargeNamespace.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXTargeNamespace.h new file mode 100644 index 00000000..5359a4db --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXTargeNamespace.h @@ -0,0 +1,39 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#if defined(JUFLX_LAYOUT_NAMESPACE) + + #define _JUFLX_NS_SYMBOL_INNER(namespace, symbol) namespace ## _ ## symbol + #define _JUFLX_NS_SYMBOL_MIDDLE(namespace, symbol) _JUFLX_NS_SYMBOL_INNER(namespace, symbol) + #define _JUFLX_NS_SYMBOL(symbol) _JUFLX_NS_SYMBOL_MIDDLE(JUFLX_LAYOUT_NAMESPACE, symbol) + + #define _JUFLX_NS_STRING_INNER(namespace) #namespace + #define _JUFLX_NS_STRING_MIDDLE(namespace) _JUFLX_NS_STRING_INNER(namespace) + #define JUFLX_LAYOUT_NAMESPACE_STRING _JUFLX_NS_STRING_MIDDLE(JUFLX_LAYOUT_NAMESPACE) + + #define css_direction_t _JUFLX_NS_SYMBOL(css_direction_t) + #define css_flex_direction_t _JUFLX_NS_SYMBOL(css_flex_direction_t) + #define css_justify_t _JUFLX_NS_SYMBOL(css_justify_t) + #define css_align_t _JUFLX_NS_SYMBOL(css_align_t) + #define css_position_type_t _JUFLX_NS_SYMBOL(css_position_type_t) + #define css_wrap_type_t _JUFLX_NS_SYMBOL(css_wrap_type_t) + #define css_position_t _JUFLX_NS_SYMBOL(css_position_t) + #define css_dimension_t _JUFLX_NS_SYMBOL(css_dimension_t) + #define css_layout_t _JUFLX_NS_SYMBOL(css_layout_t) + #define css_dim_t _JUFLX_NS_SYMBOL(css_dim_t) + #define css_style_t _JUFLX_NS_SYMBOL(css_style_t) + #define css_node_t _JUFLX_NS_SYMBOL(css_node_t) + #define new_css_node _JUFLX_NS_SYMBOL(new_css_node) + #define init_css_node _JUFLX_NS_SYMBOL(init_css_node) + #define free_css_node _JUFLX_NS_SYMBOL(free_css_node) + #define css_print_options_t _JUFLX_NS_SYMBOL(css_print_options_t) + #define print_css_node _JUFLX_NS_SYMBOL(print_css_node) + #define layoutNode _JUFLX_NS_SYMBOL(layoutNode) + #define isUndefined _JUFLX_NS_SYMBOL(isUndefined) + +#endif diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/Layout.c b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/Layout.c new file mode 100644 index 00000000..cccf3685 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/Layout.c @@ -0,0 +1,1141 @@ +/** + * Copyright (c) 2014, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +#include +#include +#include +#include + +#include "JUFLXLayoutDefine.h" + +#ifdef _MSC_VER +#include +#define isnan _isnan + +/* define fmaxf if < VC12 */ +#if _MSC_VER < 1800 +__forceinline const float fmaxf(const float a, const float b) { + return (a > b) ? a : b; +} +#endif +#endif + +bool isUndefined(float value) { + return isnan(value); +} + +static bool eq(float a, float b) { + if (isUndefined(a)) { + return isUndefined(b); + } + return fabs(a - b) < 0.0001; +} + +void init_css_node(css_node_t *node) { + node->style.align_items = CSS_ALIGN_STRETCH; + node->style.align_content = CSS_ALIGN_FLEX_START; + + node->style.direction = CSS_DIRECTION_INHERIT; + node->style.flex_direction = CSS_FLEX_DIRECTION_COLUMN; + + // Some of the fields default to undefined and not 0 + node->style.dimensions[CSS_WIDTH] = CSS_UNDEFINED; + node->style.dimensions[CSS_HEIGHT] = CSS_UNDEFINED; + + node->style.minDimensions[CSS_WIDTH] = CSS_UNDEFINED; + node->style.minDimensions[CSS_HEIGHT] = CSS_UNDEFINED; + + node->style.maxDimensions[CSS_WIDTH] = CSS_UNDEFINED; + node->style.maxDimensions[CSS_HEIGHT] = CSS_UNDEFINED; + + node->style.position[CSS_LEFT] = CSS_UNDEFINED; + node->style.position[CSS_TOP] = CSS_UNDEFINED; + node->style.position[CSS_RIGHT] = CSS_UNDEFINED; + node->style.position[CSS_BOTTOM] = CSS_UNDEFINED; + + node->style.margin[CSS_START] = CSS_UNDEFINED; + node->style.margin[CSS_END] = CSS_UNDEFINED; + node->style.padding[CSS_START] = CSS_UNDEFINED; + node->style.padding[CSS_END] = CSS_UNDEFINED; + node->style.border[CSS_START] = CSS_UNDEFINED; + node->style.border[CSS_END] = CSS_UNDEFINED; + + node->layout.dimensions[CSS_WIDTH] = CSS_UNDEFINED; + node->layout.dimensions[CSS_HEIGHT] = CSS_UNDEFINED; + + // Such that the comparison is always going to be false + node->layout.last_requested_dimensions[CSS_WIDTH] = -1; + node->layout.last_requested_dimensions[CSS_HEIGHT] = -1; + node->layout.last_parent_max_width = -1; + node->layout.last_direction = (css_direction_t)-1; + node->layout.should_update = true; +} + +css_node_t *new_css_node() { + css_node_t *node = (css_node_t *)calloc(1, sizeof(*node)); + init_css_node(node); + return node; +} + +void free_css_node(css_node_t *node) { + free(node); +} + +static void indent(int n) { + for (int i = 0; i < n; ++i) { + printf(" "); + } +} + +static void print_number_0(const char *str, float number) { + if (!eq(number, 0)) { + printf("%s: %g, ", str, number); + } +} + +static void print_number_nan(const char *str, float number) { + if (!isnan(number)) { + printf("%s: %g, ", str, number); + } +} + +static bool four_equal(float four[4]) { + return + eq(four[0], four[1]) && + eq(four[0], four[2]) && + eq(four[0], four[3]); +} + + +static void print_css_node_rec( + css_node_t *node, + css_print_options_t options, + int level +) { + indent(level); + printf("{"); + + if (node->print) { + node->print(node->context); + } + + if (options & CSS_PRINT_LAYOUT) { + printf("layout: {"); + printf("width: %g, ", node->layout.dimensions[CSS_WIDTH]); + printf("height: %g, ", node->layout.dimensions[CSS_HEIGHT]); + printf("top: %g, ", node->layout.position[CSS_TOP]); + printf("left: %g", node->layout.position[CSS_LEFT]); + printf("}, "); + } + + if (options & CSS_PRINT_STYLE) { + if (node->style.flex_direction == CSS_FLEX_DIRECTION_COLUMN) { + printf("flexDirection: 'column', "); + } else if (node->style.flex_direction == CSS_FLEX_DIRECTION_COLUMN_REVERSE) { + printf("flexDirection: 'columnReverse', "); + } else if (node->style.flex_direction == CSS_FLEX_DIRECTION_ROW) { + printf("flexDirection: 'row', "); + } else if (node->style.flex_direction == CSS_FLEX_DIRECTION_ROW_REVERSE) { + printf("flexDirection: 'rowReverse', "); + } + + if (node->style.justify_content == CSS_JUSTIFY_CENTER) { + printf("justifyContent: 'center', "); + } else if (node->style.justify_content == CSS_JUSTIFY_FLEX_END) { + printf("justifyContent: 'flex-end', "); + } else if (node->style.justify_content == CSS_JUSTIFY_SPACE_AROUND) { + printf("justifyContent: 'space-around', "); + } else if (node->style.justify_content == CSS_JUSTIFY_SPACE_BETWEEN) { + printf("justifyContent: 'space-between', "); + } + + if (node->style.align_items == CSS_ALIGN_CENTER) { + printf("alignItems: 'center', "); + } else if (node->style.align_items == CSS_ALIGN_FLEX_END) { + printf("alignItems: 'flex-end', "); + } else if (node->style.align_items == CSS_ALIGN_STRETCH) { + printf("alignItems: 'stretch', "); + } + + if (node->style.align_content == CSS_ALIGN_CENTER) { + printf("alignContent: 'center', "); + } else if (node->style.align_content == CSS_ALIGN_FLEX_END) { + printf("alignContent: 'flex-end', "); + } else if (node->style.align_content == CSS_ALIGN_STRETCH) { + printf("alignContent: 'stretch', "); + } + + if (node->style.align_self == CSS_ALIGN_FLEX_START) { + printf("alignSelf: 'flex-start', "); + } else if (node->style.align_self == CSS_ALIGN_CENTER) { + printf("alignSelf: 'center', "); + } else if (node->style.align_self == CSS_ALIGN_FLEX_END) { + printf("alignSelf: 'flex-end', "); + } else if (node->style.align_self == CSS_ALIGN_STRETCH) { + printf("alignSelf: 'stretch', "); + } + + print_number_nan("flex", node->style.flex); + + if (four_equal(node->style.margin)) { + print_number_0("margin", node->style.margin[CSS_LEFT]); + } else { + print_number_0("marginLeft", node->style.margin[CSS_LEFT]); + print_number_0("marginRight", node->style.margin[CSS_RIGHT]); + print_number_0("marginTop", node->style.margin[CSS_TOP]); + print_number_0("marginBottom", node->style.margin[CSS_BOTTOM]); + print_number_0("marginStart", node->style.margin[CSS_START]); + print_number_0("marginEnd", node->style.margin[CSS_END]); + } + + if (four_equal(node->style.padding)) { + print_number_0("padding", node->style.margin[CSS_LEFT]); + } else { + print_number_0("paddingLeft", node->style.padding[CSS_LEFT]); + print_number_0("paddingRight", node->style.padding[CSS_RIGHT]); + print_number_0("paddingTop", node->style.padding[CSS_TOP]); + print_number_0("paddingBottom", node->style.padding[CSS_BOTTOM]); + print_number_0("paddingStart", node->style.padding[CSS_START]); + print_number_0("paddingEnd", node->style.padding[CSS_END]); + } + + if (four_equal(node->style.border)) { + print_number_0("borderWidth", node->style.border[CSS_LEFT]); + } else { + print_number_0("borderLeftWidth", node->style.border[CSS_LEFT]); + print_number_0("borderRightWidth", node->style.border[CSS_RIGHT]); + print_number_0("borderTopWidth", node->style.border[CSS_TOP]); + print_number_0("borderBottomWidth", node->style.border[CSS_BOTTOM]); + print_number_0("borderStartWidth", node->style.border[CSS_START]); + print_number_0("borderEndWidth", node->style.border[CSS_END]); + } + + print_number_nan("width", node->style.dimensions[CSS_WIDTH]); + print_number_nan("height", node->style.dimensions[CSS_HEIGHT]); + + if (node->style.position_type == CSS_POSITION_ABSOLUTE) { + printf("position: 'absolute', "); + } + + print_number_nan("left", node->style.position[CSS_LEFT]); + print_number_nan("right", node->style.position[CSS_RIGHT]); + print_number_nan("top", node->style.position[CSS_TOP]); + print_number_nan("bottom", node->style.position[CSS_BOTTOM]); + } + + if (options & CSS_PRINT_CHILDREN && node->children_count > 0) { + printf("children: [\n"); + for (int i = 0; i < node->children_count; ++i) { + print_css_node_rec(node->get_child(node->context, i), options, level + 1); + } + indent(level); + printf("]},\n"); + } else { + printf("},\n"); + } +} + +void print_css_node(css_node_t *node, css_print_options_t options) { + print_css_node_rec(node, options, 0); +} + + +static css_position_t leading[4] = { + /* CSS_FLEX_DIRECTION_COLUMN = */ CSS_TOP, + /* CSS_FLEX_DIRECTION_COLUMN_REVERSE = */ CSS_BOTTOM, + /* CSS_FLEX_DIRECTION_ROW = */ CSS_LEFT, + /* CSS_FLEX_DIRECTION_ROW_REVERSE = */ CSS_RIGHT +}; +static css_position_t trailing[4] = { + /* CSS_FLEX_DIRECTION_COLUMN = */ CSS_BOTTOM, + /* CSS_FLEX_DIRECTION_COLUMN_REVERSE = */ CSS_TOP, + /* CSS_FLEX_DIRECTION_ROW = */ CSS_RIGHT, + /* CSS_FLEX_DIRECTION_ROW_REVERSE = */ CSS_LEFT +}; +static css_position_t pos[4] = { + /* CSS_FLEX_DIRECTION_COLUMN = */ CSS_TOP, + /* CSS_FLEX_DIRECTION_COLUMN_REVERSE = */ CSS_BOTTOM, + /* CSS_FLEX_DIRECTION_ROW = */ CSS_LEFT, + /* CSS_FLEX_DIRECTION_ROW_REVERSE = */ CSS_RIGHT +}; +static css_dimension_t dim[4] = { + /* CSS_FLEX_DIRECTION_COLUMN = */ CSS_HEIGHT, + /* CSS_FLEX_DIRECTION_COLUMN_REVERSE = */ CSS_HEIGHT, + /* CSS_FLEX_DIRECTION_ROW = */ CSS_WIDTH, + /* CSS_FLEX_DIRECTION_ROW_REVERSE = */ CSS_WIDTH +}; + +static bool isRowDirection(css_flex_direction_t flex_direction) { + return flex_direction == CSS_FLEX_DIRECTION_ROW || + flex_direction == CSS_FLEX_DIRECTION_ROW_REVERSE; +} + +static bool isColumnDirection(css_flex_direction_t flex_direction) { + return flex_direction == CSS_FLEX_DIRECTION_COLUMN || + flex_direction == CSS_FLEX_DIRECTION_COLUMN_REVERSE; +} + +static float getLeadingMargin(css_node_t *node, css_flex_direction_t axis) { + if (isRowDirection(axis) && !isUndefined(node->style.margin[CSS_START])) { + return node->style.margin[CSS_START]; + } + + return node->style.margin[leading[axis]]; +} + +static float getTrailingMargin(css_node_t *node, css_flex_direction_t axis) { + if (isRowDirection(axis) && !isUndefined(node->style.margin[CSS_END])) { + return node->style.margin[CSS_END]; + } + + return node->style.margin[trailing[axis]]; +} + +static float getLeadingPadding(css_node_t *node, css_flex_direction_t axis) { + if (isRowDirection(axis) && + !isUndefined(node->style.padding[CSS_START]) && + node->style.padding[CSS_START] >= 0) { + return node->style.padding[CSS_START]; + } + + if (node->style.padding[leading[axis]] >= 0) { + return node->style.padding[leading[axis]]; + } + + return 0; +} + +static float getTrailingPadding(css_node_t *node, css_flex_direction_t axis) { + if (isRowDirection(axis) && + !isUndefined(node->style.padding[CSS_END]) && + node->style.padding[CSS_END] >= 0) { + return node->style.padding[CSS_END]; + } + + if (node->style.padding[trailing[axis]] >= 0) { + return node->style.padding[trailing[axis]]; + } + + return 0; +} + +static float getLeadingBorder(css_node_t *node, css_flex_direction_t axis) { + if (isRowDirection(axis) && + !isUndefined(node->style.border[CSS_START]) && + node->style.border[CSS_START] >= 0) { + return node->style.border[CSS_START]; + } + + if (node->style.border[leading[axis]] >= 0) { + return node->style.border[leading[axis]]; + } + + return 0; +} + +static float getTrailingBorder(css_node_t *node, css_flex_direction_t axis) { + if (isRowDirection(axis) && + !isUndefined(node->style.border[CSS_END]) && + node->style.border[CSS_END] >= 0) { + return node->style.border[CSS_END]; + } + + if (node->style.border[trailing[axis]] >= 0) { + return node->style.border[trailing[axis]]; + } + + return 0; +} + +static float getLeadingPaddingAndBorder(css_node_t *node, css_flex_direction_t axis) { + return getLeadingPadding(node, axis) + getLeadingBorder(node, axis); +} + +static float getTrailingPaddingAndBorder(css_node_t *node, css_flex_direction_t axis) { + return getTrailingPadding(node, axis) + getTrailingBorder(node, axis); +} + +static float getBorderAxis(css_node_t *node, css_flex_direction_t axis) { + return getLeadingBorder(node, axis) + getTrailingBorder(node, axis); +} + +static float getMarginAxis(css_node_t *node, css_flex_direction_t axis) { + return getLeadingMargin(node, axis) + getTrailingMargin(node, axis); +} + +static float getPaddingAndBorderAxis(css_node_t *node, css_flex_direction_t axis) { + return getLeadingPaddingAndBorder(node, axis) + getTrailingPaddingAndBorder(node, axis); +} + +static css_position_type_t getPositionType(css_node_t *node) { + return node->style.position_type; +} + +static css_justify_t getJustifyContent(css_node_t *node) { + return node->style.justify_content; +} + +static css_align_t getAlignContent(css_node_t *node) { + return node->style.align_content; +} + +static css_align_t getAlignItem(css_node_t *node, css_node_t *child) { + if (child->style.align_self != CSS_ALIGN_AUTO) { + return child->style.align_self; + } + return node->style.align_items; +} + +static css_direction_t resolveDirection(css_node_t *node, css_direction_t parentDirection) { + css_direction_t direction = node->style.direction; + + if (direction == CSS_DIRECTION_INHERIT) { + direction = parentDirection > CSS_DIRECTION_INHERIT ? parentDirection : CSS_DIRECTION_LTR; + } + + return direction; +} + +static css_flex_direction_t getFlexDirection(css_node_t *node) { + return node->style.flex_direction; +} + +static css_flex_direction_t resolveAxis(css_flex_direction_t flex_direction, css_direction_t direction) { + if (direction == CSS_DIRECTION_RTL) { + if (flex_direction == CSS_FLEX_DIRECTION_ROW) { + return CSS_FLEX_DIRECTION_ROW_REVERSE; + } else if (flex_direction == CSS_FLEX_DIRECTION_ROW_REVERSE) { + return CSS_FLEX_DIRECTION_ROW; + } + } + + return flex_direction; +} + +static css_flex_direction_t getCrossFlexDirection(css_flex_direction_t flex_direction, css_direction_t direction) { + if (isColumnDirection(flex_direction)) { + return resolveAxis(CSS_FLEX_DIRECTION_ROW, direction); + } else { + return CSS_FLEX_DIRECTION_COLUMN; + } +} + +static float getFlex(css_node_t *node) { + return node->style.flex; +} + +static bool isFlex(css_node_t *node) { + return ( + getPositionType(node) == CSS_POSITION_RELATIVE && + getFlex(node) > 0 + ); +} + +static bool isFlexWrap(css_node_t *node) { + return node->style.flex_wrap == CSS_WRAP; +} + +static float getDimWithMargin(css_node_t *node, css_flex_direction_t axis) { + return node->layout.dimensions[dim[axis]] + + getLeadingMargin(node, axis) + + getTrailingMargin(node, axis); +} + +static bool isDimDefined(css_node_t *node, css_flex_direction_t axis) { + float value = node->style.dimensions[dim[axis]]; + return !isUndefined(value) && value > 0.0; +} + +static bool isPosDefined(css_node_t *node, css_position_t position) { + return !isUndefined(node->style.position[position]); +} + +static bool isMeasureDefined(css_node_t *node) { + return node->measure; +} + +static float getPosition(css_node_t *node, css_position_t position) { + float result = node->style.position[position]; + if (!isUndefined(result)) { + return result; + } + return 0; +} + +static float boundAxis(css_node_t *node, css_flex_direction_t axis, float value) { + float min = CSS_UNDEFINED; + float max = CSS_UNDEFINED; + + if (isColumnDirection(axis)) { + min = node->style.minDimensions[CSS_HEIGHT]; + max = node->style.maxDimensions[CSS_HEIGHT]; + } else if (isRowDirection(axis)) { + min = node->style.minDimensions[CSS_WIDTH]; + max = node->style.maxDimensions[CSS_WIDTH]; + } + + float boundValue = value; + + if (!isUndefined(max) && max >= 0.0 && boundValue > max) { + boundValue = max; + } + if (!isUndefined(min) && min >= 0.0 && boundValue < min) { + boundValue = min; + } + + return boundValue; +} + +// When the user specifically sets a value for width or height +static void setDimensionFromStyle(css_node_t *node, css_flex_direction_t axis) { + // The parent already computed us a width or height. We just skip it + if (!isUndefined(node->layout.dimensions[dim[axis]])) { + return; + } + // We only run if there's a width or height defined + if (!isDimDefined(node, axis)) { + return; + } + + // The dimensions can never be smaller than the padding and border + node->layout.dimensions[dim[axis]] = fmaxf( + boundAxis(node, axis, node->style.dimensions[dim[axis]]), + getPaddingAndBorderAxis(node, axis) + ); +} + +static void setTrailingPosition(css_node_t *node, css_node_t *child, css_flex_direction_t axis) { + child->layout.position[trailing[axis]] = node->layout.dimensions[dim[axis]] - + child->layout.dimensions[dim[axis]] - child->layout.position[pos[axis]]; + } + +// If both left and right are defined, then use left. Otherwise return +// +left or -right depending on which is defined. +static float getRelativePosition(css_node_t *node, css_flex_direction_t axis) { + float lead = node->style.position[leading[axis]]; + if (!isUndefined(lead)) { + return lead; + } + return -getPosition(node, trailing[axis]); +} + +static void layoutNodeImpl(css_node_t *node, float parentMaxWidth, css_direction_t parentDirection) { + /** START_GENERATED **/ + css_direction_t direction = resolveDirection(node, parentDirection); + css_flex_direction_t mainAxis = resolveAxis(getFlexDirection(node), direction); + css_flex_direction_t crossAxis = getCrossFlexDirection(mainAxis, direction); + css_flex_direction_t resolvedRowAxis = resolveAxis(CSS_FLEX_DIRECTION_ROW, direction); + + // Handle width and height style attributes + setDimensionFromStyle(node, mainAxis); + setDimensionFromStyle(node, crossAxis); + + // Set the resolved resolution in the node's layout + node->layout.direction = direction; + + // The position is set by the parent, but we need to complete it with a + // delta composed of the margin and left/top/right/bottom + node->layout.position[leading[mainAxis]] += getLeadingMargin(node, mainAxis) + + getRelativePosition(node, mainAxis); + node->layout.position[trailing[mainAxis]] += getTrailingMargin(node, mainAxis) + + getRelativePosition(node, mainAxis); + node->layout.position[leading[crossAxis]] += getLeadingMargin(node, crossAxis) + + getRelativePosition(node, crossAxis); + node->layout.position[trailing[crossAxis]] += getTrailingMargin(node, crossAxis) + + getRelativePosition(node, crossAxis); + + if (isMeasureDefined(node)) { + float width = CSS_UNDEFINED; + if (isDimDefined(node, resolvedRowAxis)) { + width = node->style.dimensions[CSS_WIDTH]; + } else if (!isUndefined(node->layout.dimensions[dim[resolvedRowAxis]])) { + width = node->layout.dimensions[dim[resolvedRowAxis]]; + } else { + width = parentMaxWidth - + getMarginAxis(node, resolvedRowAxis); + } + width -= getPaddingAndBorderAxis(node, resolvedRowAxis); + + // We only need to give a dimension for the text if we haven't got any + // for it computed yet. It can either be from the style attribute or because + // the element is flexible. + bool isRowUndefined = !isDimDefined(node, resolvedRowAxis) && + isUndefined(node->layout.dimensions[dim[resolvedRowAxis]]); + bool isColumnUndefined = !isDimDefined(node, CSS_FLEX_DIRECTION_COLUMN) && + isUndefined(node->layout.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]]); + + // Let's not measure the text if we already know both dimensions + if (isRowUndefined || isColumnUndefined) { + css_dim_t measureDim = node->measure( + node->context, + + width + ); + if (isRowUndefined) { + node->layout.dimensions[CSS_WIDTH] = measureDim.dimensions[CSS_WIDTH] + + getPaddingAndBorderAxis(node, resolvedRowAxis); + } + if (isColumnUndefined) { + node->layout.dimensions[CSS_HEIGHT] = measureDim.dimensions[CSS_HEIGHT] + + getPaddingAndBorderAxis(node, CSS_FLEX_DIRECTION_COLUMN); + } + } + if (node->children_count == 0) { + return; + } + } + + int i; + int ii; + css_node_t* child; + css_flex_direction_t axis; + + // Pre-fill some dimensions straight from the parent + for (i = 0; i < node->children_count; ++i) { + child = node->get_child(node->context, i); + // Pre-fill cross axis dimensions when the child is using stretch before + // we call the recursive layout pass + if (getAlignItem(node, child) == CSS_ALIGN_STRETCH && + getPositionType(child) == CSS_POSITION_RELATIVE && + !isUndefined(node->layout.dimensions[dim[crossAxis]]) && + !isDimDefined(child, crossAxis)) { + child->layout.dimensions[dim[crossAxis]] = fmaxf( + boundAxis(child, crossAxis, node->layout.dimensions[dim[crossAxis]] - + getPaddingAndBorderAxis(node, crossAxis) - + getMarginAxis(child, crossAxis)), + // You never want to go smaller than padding + getPaddingAndBorderAxis(child, crossAxis) + ); + } else if (getPositionType(child) == CSS_POSITION_ABSOLUTE) { + // Pre-fill dimensions when using absolute position and both offsets for the axis are defined (either both + // left and right or top and bottom). + for (ii = 0; ii < 2; ii++) { + axis = (ii != 0) ? CSS_FLEX_DIRECTION_ROW : CSS_FLEX_DIRECTION_COLUMN; + if (!isUndefined(node->layout.dimensions[dim[axis]]) && + !isDimDefined(child, axis) && + isPosDefined(child, leading[axis]) && + isPosDefined(child, trailing[axis])) { + child->layout.dimensions[dim[axis]] = fmaxf( + boundAxis(child, axis, node->layout.dimensions[dim[axis]] - + getPaddingAndBorderAxis(node, axis) - + getMarginAxis(child, axis) - + getPosition(child, leading[axis]) - + getPosition(child, trailing[axis])), + // You never want to go smaller than padding + getPaddingAndBorderAxis(child, axis) + ); + } + } + } + } + + float definedMainDim = CSS_UNDEFINED; + if (!isUndefined(node->layout.dimensions[dim[mainAxis]])) { + definedMainDim = node->layout.dimensions[dim[mainAxis]] - + getPaddingAndBorderAxis(node, mainAxis); + } + + // We want to execute the next two loops one per line with flex-wrap + int startLine = 0; + int endLine = 0; + // int nextOffset = 0; + int alreadyComputedNextLayout = 0; + // We aggregate the total dimensions of the container in those two variables + float linesCrossDim = 0; + float linesMainDim = 0; + int linesCount = 0; + while (endLine < node->children_count) { + // Layout non flexible children and count children by type + + // mainContentDim is accumulation of the dimensions and margin of all the + // non flexible children. This will be used in order to either set the + // dimensions of the node if none already exist, or to compute the + // remaining space left for the flexible children. + float mainContentDim = 0; + + // There are three kind of children, non flexible, flexible and absolute. + // We need to know how many there are in order to distribute the space. + int flexibleChildrenCount = 0; + float totalFlexible = 0; + int nonFlexibleChildrenCount = 0; + + float maxWidth; + for (i = startLine; i < node->children_count; ++i) { + child = node->get_child(node->context, i); + float nextContentDim = 0; + + // It only makes sense to consider a child flexible if we have a computed + // dimension for the node-> + if (!isUndefined(node->layout.dimensions[dim[mainAxis]]) && isFlex(child)) { + flexibleChildrenCount++; + totalFlexible += getFlex(child); + + // Even if we don't know its exact size yet, we already know the padding, + // border and margin. We'll use this partial information, which represents + // the smallest possible size for the child, to compute the remaining + // available space. + nextContentDim = getPaddingAndBorderAxis(child, mainAxis) + + getMarginAxis(child, mainAxis); + + } else { + maxWidth = CSS_UNDEFINED; + if (!isRowDirection(mainAxis)) { + maxWidth = parentMaxWidth - + getMarginAxis(node, resolvedRowAxis) - + getPaddingAndBorderAxis(node, resolvedRowAxis); + + if (isDimDefined(node, resolvedRowAxis)) { + maxWidth = node->layout.dimensions[dim[resolvedRowAxis]] - + getPaddingAndBorderAxis(node, resolvedRowAxis); + } + } + + // This is the main recursive call. We layout non flexible children. + if (alreadyComputedNextLayout == 0) { + layoutNode(child, maxWidth, direction); + } + + // Absolute positioned elements do not take part of the layout, so we + // don't use them to compute mainContentDim + if (getPositionType(child) == CSS_POSITION_RELATIVE) { + nonFlexibleChildrenCount++; + // At this point we know the final size and margin of the element. + nextContentDim = getDimWithMargin(child, mainAxis); + } + } + + // The element we are about to add would make us go to the next line + if (isFlexWrap(node) && + !isUndefined(node->layout.dimensions[dim[mainAxis]]) && + mainContentDim + nextContentDim > definedMainDim && + // If there's only one element, then it's bigger than the content + // and needs its own line + i != startLine) { + nonFlexibleChildrenCount--; + alreadyComputedNextLayout = 1; + break; + } + alreadyComputedNextLayout = 0; + mainContentDim += nextContentDim; + endLine = i + 1; + } + + // Layout flexible children and allocate empty space + + // In order to position the elements in the main axis, we have two + // controls. The space between the beginning and the first element + // and the space between each two elements. + float leadingMainDim = 0; + float betweenMainDim = 0; + + // The remaining available space that needs to be allocated + float remainingMainDim = 0; + if (!isUndefined(node->layout.dimensions[dim[mainAxis]])) { + remainingMainDim = definedMainDim - mainContentDim; + } else { + remainingMainDim = fmaxf(mainContentDim, 0) - mainContentDim; + } + + // If there are flexible children in the mix, they are going to fill the + // remaining space + if (flexibleChildrenCount != 0) { + float flexibleMainDim = remainingMainDim / totalFlexible; + float baseMainDim; + float boundMainDim; + + // Iterate over every child in the axis. If the flex share of remaining + // space doesn't meet min/max bounds, remove this child from flex + // calculations. + for (i = startLine; i < endLine; ++i) { + child = node->get_child(node->context, i); + if (isFlex(child)) { + baseMainDim = flexibleMainDim * getFlex(child) + + getPaddingAndBorderAxis(child, mainAxis); + boundMainDim = boundAxis(child, mainAxis, baseMainDim); + + if (baseMainDim != boundMainDim) { + remainingMainDim -= boundMainDim; + totalFlexible -= getFlex(child); + } + } + } + flexibleMainDim = remainingMainDim / totalFlexible; + + // The non flexible children can overflow the container, in this case + // we should just assume that there is no space available. + if (flexibleMainDim < 0) { + flexibleMainDim = 0; + } + // We iterate over the full array and only apply the action on flexible + // children. This is faster than actually allocating a new array that + // contains only flexible children. + for (i = startLine; i < endLine; ++i) { + child = node->get_child(node->context, i); + if (isFlex(child)) { + // At this point we know the final size of the element in the main + // dimension + child->layout.dimensions[dim[mainAxis]] = boundAxis(child, mainAxis, + flexibleMainDim * getFlex(child) + getPaddingAndBorderAxis(child, mainAxis) + ); + + maxWidth = CSS_UNDEFINED; + if (isDimDefined(node, resolvedRowAxis)) { + maxWidth = node->layout.dimensions[dim[resolvedRowAxis]] - + getPaddingAndBorderAxis(node, resolvedRowAxis); + } else if (!isRowDirection(mainAxis)) { + maxWidth = parentMaxWidth - + getMarginAxis(node, resolvedRowAxis) - + getPaddingAndBorderAxis(node, resolvedRowAxis); + } + + // And we recursively call the layout algorithm for this child + layoutNode(child, maxWidth, direction); + } + } + + // We use justifyContent to figure out how to allocate the remaining + // space available + } else { + css_justify_t justifyContent = getJustifyContent(node); + if (justifyContent == CSS_JUSTIFY_CENTER) { + leadingMainDim = remainingMainDim / 2; + } else if (justifyContent == CSS_JUSTIFY_FLEX_END) { + leadingMainDim = remainingMainDim; + } else if (justifyContent == CSS_JUSTIFY_SPACE_BETWEEN) { + remainingMainDim = fmaxf(remainingMainDim, 0); + if (flexibleChildrenCount + nonFlexibleChildrenCount - 1 != 0) { + betweenMainDim = remainingMainDim / + (flexibleChildrenCount + nonFlexibleChildrenCount - 1); + } else { + betweenMainDim = 0; + } + } else if (justifyContent == CSS_JUSTIFY_SPACE_AROUND) { + // Space on the edges is half of the space between elements + betweenMainDim = remainingMainDim / + (flexibleChildrenCount + nonFlexibleChildrenCount); + leadingMainDim = betweenMainDim / 2; + } + } + + // Position elements in the main axis and compute dimensions + + // At this point, all the children have their dimensions set. We need to + // find their position. In order to do that, we accumulate data in + // variables that are also useful to compute the total dimensions of the + // container! + float crossDim = 0; + float mainDim = leadingMainDim + + getLeadingPaddingAndBorder(node, mainAxis); + + for (i = startLine; i < endLine; ++i) { + child = node->get_child(node->context, i); + child->line_index = linesCount; + + if (getPositionType(child) == CSS_POSITION_ABSOLUTE && + isPosDefined(child, leading[mainAxis])) { + // In case the child is position absolute and has left/top being + // defined, we override the position to whatever the user said + // (and margin/border). + child->layout.position[pos[mainAxis]] = getPosition(child, leading[mainAxis]) + + getLeadingBorder(node, mainAxis) + + getLeadingMargin(child, mainAxis); + } else { + // If the child is position absolute (without top/left) or relative, + // we put it at the current accumulated offset. + child->layout.position[pos[mainAxis]] += mainDim; + + // Define the trailing position accordingly. + if (!isUndefined(node->layout.dimensions[dim[mainAxis]])) { + setTrailingPosition(node, child, mainAxis); + } + } + + // Now that we placed the element, we need to update the variables + // We only need to do that for relative elements. Absolute elements + // do not take part in that phase. + if (getPositionType(child) == CSS_POSITION_RELATIVE) { + // The main dimension is the sum of all the elements dimension plus + // the spacing. + mainDim += betweenMainDim + getDimWithMargin(child, mainAxis); + // The cross dimension is the max of the elements dimension since there + // can only be one element in that cross dimension. + crossDim = fmaxf(crossDim, boundAxis(child, crossAxis, getDimWithMargin(child, crossAxis))); + } + } + + float containerCrossAxis = node->layout.dimensions[dim[crossAxis]]; + if (isUndefined(node->layout.dimensions[dim[crossAxis]])) { + containerCrossAxis = fmaxf( + // For the cross dim, we add both sides at the end because the value + // is aggregate via a max function. Intermediate negative values + // can mess this computation otherwise + boundAxis(node, crossAxis, crossDim + getPaddingAndBorderAxis(node, crossAxis)), + getPaddingAndBorderAxis(node, crossAxis) + ); + } + + // Position elements in the cross axis + for (i = startLine; i < endLine; ++i) { + child = node->get_child(node->context, i); + + if (getPositionType(child) == CSS_POSITION_ABSOLUTE && + isPosDefined(child, leading[crossAxis])) { + // In case the child is absolutely positionned and has a + // top/left/bottom/right being set, we override all the previously + // computed positions to set it correctly. + child->layout.position[pos[crossAxis]] = getPosition(child, leading[crossAxis]) + + getLeadingBorder(node, crossAxis) + + getLeadingMargin(child, crossAxis); + + } else { + float leadingCrossDim = getLeadingPaddingAndBorder(node, crossAxis); + + // For a relative children, we're either using alignItems (parent) or + // alignSelf (child) in order to determine the position in the cross axis + if (getPositionType(child) == CSS_POSITION_RELATIVE) { + css_align_t alignItem = getAlignItem(node, child); + if (alignItem == CSS_ALIGN_STRETCH) { + // You can only stretch if the dimension has not already been set + // previously. + if (!isDimDefined(child, crossAxis)) { + child->layout.dimensions[dim[crossAxis]] = fmaxf( + boundAxis(child, crossAxis, containerCrossAxis - + getPaddingAndBorderAxis(node, crossAxis) - + getMarginAxis(child, crossAxis)), + // You never want to go smaller than padding + getPaddingAndBorderAxis(child, crossAxis) + ); + } + } else if (alignItem != CSS_ALIGN_FLEX_START) { + // The remaining space between the parent dimensions+padding and child + // dimensions+margin. + float remainingCrossDim = containerCrossAxis - + getPaddingAndBorderAxis(node, crossAxis) - + getDimWithMargin(child, crossAxis); + + if (alignItem == CSS_ALIGN_CENTER) { + leadingCrossDim += remainingCrossDim / 2; + } else { // CSS_ALIGN_FLEX_END + leadingCrossDim += remainingCrossDim; + } + } + } + + // And we apply the position + child->layout.position[pos[crossAxis]] += linesCrossDim + leadingCrossDim; + + // Define the trailing position accordingly. + if (!isUndefined(node->layout.dimensions[dim[crossAxis]])) { + setTrailingPosition(node, child, crossAxis); + } + } + } + + linesCrossDim += crossDim; + linesMainDim = fmaxf(linesMainDim, mainDim); + linesCount += 1; + startLine = endLine; + } + + // + // + // Note(prenaux): More than one line, we need to layout the crossAxis + // according to alignContent. + // + // Note that we could probably remove and handle the one line case + // here too, but for the moment this is safer since it won't interfere with + // previously working code. + // + // See specs: + // http://www.w3.org/TR/2012/CR-css3-flexbox-20120918/#layout-algorithm + // section 9.4 + // + if (linesCount > 1 && + !isUndefined(node->layout.dimensions[dim[crossAxis]])) { + float nodeCrossAxisInnerSize = node->layout.dimensions[dim[crossAxis]] - + getPaddingAndBorderAxis(node, crossAxis); + float remainingAlignContentDim = nodeCrossAxisInnerSize - linesCrossDim; + + float crossDimLead = 0; + float currentLead = getLeadingPaddingAndBorder(node, crossAxis); + + css_align_t alignContent = getAlignContent(node); + if (alignContent == CSS_ALIGN_FLEX_END) { + currentLead += remainingAlignContentDim; + } else if (alignContent == CSS_ALIGN_CENTER) { + currentLead += remainingAlignContentDim / 2; + } else if (alignContent == CSS_ALIGN_STRETCH) { + if (nodeCrossAxisInnerSize > linesCrossDim) { + crossDimLead = (remainingAlignContentDim / linesCount); + } + } + + int endIndex = 0; + for (i = 0; i < linesCount; ++i) { + int startIndex = endIndex; + + // compute the line's height and find the endIndex + float lineHeight = 0; + for (ii = startIndex; ii < node->children_count; ++ii) { + child = node->get_child(node->context, ii); + if (getPositionType(child) != CSS_POSITION_RELATIVE) { + continue; + } + if (child->line_index != i) { + break; + } + if (!isUndefined(child->layout.dimensions[dim[crossAxis]])) { + lineHeight = fmaxf( + lineHeight, + child->layout.dimensions[dim[crossAxis]] + getMarginAxis(child, crossAxis) + ); + } + } + endIndex = ii; + lineHeight += crossDimLead; + + for (ii = startIndex; ii < endIndex; ++ii) { + child = node->get_child(node->context, ii); + if (getPositionType(child) != CSS_POSITION_RELATIVE) { + continue; + } + + css_align_t alignContentAlignItem = getAlignItem(node, child); + if (alignContentAlignItem == CSS_ALIGN_FLEX_START) { + child->layout.position[pos[crossAxis]] = currentLead + getLeadingMargin(child, crossAxis); + } else if (alignContentAlignItem == CSS_ALIGN_FLEX_END) { + child->layout.position[pos[crossAxis]] = currentLead + lineHeight - getTrailingMargin(child, crossAxis) - child->layout.dimensions[dim[crossAxis]]; + } else if (alignContentAlignItem == CSS_ALIGN_CENTER) { + float childHeight = child->layout.dimensions[dim[crossAxis]]; + child->layout.position[pos[crossAxis]] = currentLead + (lineHeight - childHeight) / 2; + } else if (alignContentAlignItem == CSS_ALIGN_STRETCH) { + child->layout.position[pos[crossAxis]] = currentLead + getLeadingMargin(child, crossAxis); + // TODO(prenaux): Correctly set the height of items with undefined + // (auto) crossAxis dimension. + } + } + + currentLead += lineHeight; + } + } + + bool needsMainTrailingPos = false; + bool needsCrossTrailingPos = false; + + // If the user didn't specify a width or height, and it has not been set + // by the container, then we set it via the children. + if (isUndefined(node->layout.dimensions[dim[mainAxis]])) { + node->layout.dimensions[dim[mainAxis]] = fmaxf( + // We're missing the last padding at this point to get the final + // dimension + boundAxis(node, mainAxis, linesMainDim + getTrailingPaddingAndBorder(node, mainAxis)), + // We can never assign a width smaller than the padding and borders + getPaddingAndBorderAxis(node, mainAxis) + ); + + needsMainTrailingPos = true; + } + + if (isUndefined(node->layout.dimensions[dim[crossAxis]])) { + node->layout.dimensions[dim[crossAxis]] = fmaxf( + // For the cross dim, we add both sides at the end because the value + // is aggregate via a max function. Intermediate negative values + // can mess this computation otherwise + boundAxis(node, crossAxis, linesCrossDim + getPaddingAndBorderAxis(node, crossAxis)), + getPaddingAndBorderAxis(node, crossAxis) + ); + + needsCrossTrailingPos = true; + } + + // Set trailing position if necessary + if (needsMainTrailingPos || needsCrossTrailingPos) { + for (i = 0; i < node->children_count; ++i) { + child = node->get_child(node->context, i); + + if (needsMainTrailingPos) { + setTrailingPosition(node, child, mainAxis); + } + + if (needsCrossTrailingPos) { + setTrailingPosition(node, child, crossAxis); + } + } + } + + // Calculate dimensions for absolutely positioned elements + for (i = 0; i < node->children_count; ++i) { + child = node->get_child(node->context, i); + if (getPositionType(child) == CSS_POSITION_ABSOLUTE) { + // Pre-fill dimensions when using absolute position and both offsets for the axis are defined (either both + // left and right or top and bottom). + for (ii = 0; ii < 2; ii++) { + axis = (ii != 0) ? CSS_FLEX_DIRECTION_ROW : CSS_FLEX_DIRECTION_COLUMN; + if (!isUndefined(node->layout.dimensions[dim[axis]]) && + !isDimDefined(child, axis) && + isPosDefined(child, leading[axis]) && + isPosDefined(child, trailing[axis])) { + child->layout.dimensions[dim[axis]] = fmaxf( + boundAxis(child, axis, node->layout.dimensions[dim[axis]] - + getBorderAxis(node, axis) - + getMarginAxis(child, axis) - + getPosition(child, leading[axis]) - + getPosition(child, trailing[axis]) + ), + // You never want to go smaller than padding + getPaddingAndBorderAxis(child, axis) + ); + } + } + for (ii = 0; ii < 2; ii++) { + axis = (ii != 0) ? CSS_FLEX_DIRECTION_ROW : CSS_FLEX_DIRECTION_COLUMN; + if (isPosDefined(child, trailing[axis]) && + !isPosDefined(child, leading[axis])) { + child->layout.position[leading[axis]] = + node->layout.dimensions[dim[axis]] - + child->layout.dimensions[dim[axis]] - + getPosition(child, trailing[axis]); + } + } + } + } + /** END_GENERATED **/ +} + +void layoutNode(css_node_t *node, float parentMaxWidth, css_direction_t parentDirection) { + css_layout_t *layout = &node->layout; + css_direction_t direction = node->style.direction; + layout->should_update = true; + + bool skipLayout = + !node->is_dirty(node->context) && + eq(layout->last_requested_dimensions[CSS_WIDTH], layout->dimensions[CSS_WIDTH]) && + eq(layout->last_requested_dimensions[CSS_HEIGHT], layout->dimensions[CSS_HEIGHT]) && + eq(layout->last_parent_max_width, parentMaxWidth); + eq(layout->last_direction, direction); + + if (skipLayout) { + layout->dimensions[CSS_WIDTH] = layout->last_dimensions[CSS_WIDTH]; + layout->dimensions[CSS_HEIGHT] = layout->last_dimensions[CSS_HEIGHT]; + layout->position[CSS_TOP] = layout->last_position[CSS_TOP]; + layout->position[CSS_LEFT] = layout->last_position[CSS_LEFT]; + } else { + layout->last_requested_dimensions[CSS_WIDTH] = layout->dimensions[CSS_WIDTH]; + layout->last_requested_dimensions[CSS_HEIGHT] = layout->dimensions[CSS_HEIGHT]; + layout->last_parent_max_width = parentMaxWidth; + layout->last_direction = direction; + + layoutNodeImpl(node, parentMaxWidth, parentDirection); + + layout->last_dimensions[CSS_WIDTH] = layout->dimensions[CSS_WIDTH]; + layout->last_dimensions[CSS_HEIGHT] = layout->dimensions[CSS_HEIGHT]; + layout->last_position[CSS_TOP] = layout->position[CSS_TOP]; + layout->last_position[CSS_LEFT] = layout->position[CSS_LEFT]; + } +} diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/Layout.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/Layout.h new file mode 100644 index 00000000..54d31589 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/Layout.h @@ -0,0 +1,163 @@ +/** + * Copyright (c) 2014, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +#ifndef __LAYOUT_H +#define __LAYOUT_H + +#include +#ifndef __cplusplus +#include +#endif + +// Not defined in MSVC++ +#ifndef NAN +static const unsigned long __nan[2] = {0xffffffff, 0x7fffffff}; +#define NAN (*(const float *)__nan) +#endif + +#define CSS_UNDEFINED NAN + +typedef enum { + CSS_DIRECTION_INHERIT = 0, + CSS_DIRECTION_LTR, + CSS_DIRECTION_RTL +} css_direction_t; + +typedef enum { + CSS_FLEX_DIRECTION_COLUMN = 0, + CSS_FLEX_DIRECTION_COLUMN_REVERSE, + CSS_FLEX_DIRECTION_ROW, + CSS_FLEX_DIRECTION_ROW_REVERSE +} css_flex_direction_t; + +typedef enum { + CSS_JUSTIFY_FLEX_START = 0, + CSS_JUSTIFY_CENTER, + CSS_JUSTIFY_FLEX_END, + CSS_JUSTIFY_SPACE_BETWEEN, + CSS_JUSTIFY_SPACE_AROUND +} css_justify_t; + +// Note: auto is only a valid value for alignSelf. It is NOT a valid value for +// alignItems. +typedef enum { + CSS_ALIGN_AUTO = 0, + CSS_ALIGN_FLEX_START, + CSS_ALIGN_CENTER, + CSS_ALIGN_FLEX_END, + CSS_ALIGN_STRETCH +} css_align_t; + +typedef enum { + CSS_POSITION_RELATIVE = 0, + CSS_POSITION_ABSOLUTE +} css_position_type_t; + +typedef enum { + CSS_NOWRAP = 0, + CSS_WRAP +} css_wrap_type_t; + +// Note: left and top are shared between position[2] and position[4], so +// they have to be before right and bottom. +typedef enum { + CSS_LEFT = 0, + CSS_TOP, + CSS_RIGHT, + CSS_BOTTOM, + CSS_START, + CSS_END, + CSS_POSITION_COUNT +} css_position_t; + +typedef enum { + CSS_WIDTH = 0, + CSS_HEIGHT +} css_dimension_t; + +typedef struct { + float position[4]; + float dimensions[2]; + css_direction_t direction; + + // Instead of recomputing the entire layout every single time, we + // cache some information to break early when nothing changed + bool should_update; + float last_requested_dimensions[2]; + float last_parent_max_width; + float last_dimensions[2]; + float last_position[2]; + css_direction_t last_direction; +} css_layout_t; + +typedef struct { + float dimensions[2]; +} css_dim_t; + +typedef struct { + css_direction_t direction; + css_flex_direction_t flex_direction; + css_justify_t justify_content; + css_align_t align_content; + css_align_t align_items; + css_align_t align_self; + css_position_type_t position_type; + css_wrap_type_t flex_wrap; + float flex; + float margin[6]; + float position[4]; + /** + * You should skip all the rules that contain negative values for the + * following attributes. For example: + * {padding: 10, paddingLeft: -5} + * should output: + * {left: 10 ...} + * the following two are incorrect: + * {left: -5 ...} + * {left: 0 ...} + */ + float padding[6]; + float border[6]; + float dimensions[2]; + float minDimensions[2]; + float maxDimensions[2]; +} css_style_t; + +typedef struct css_node { + css_style_t style; + css_layout_t layout; + int children_count; + int line_index; + + css_dim_t (*measure)(void *context, float width); + void (*print)(void *context); + struct css_node* (*get_child)(void *context, int i); + bool (*is_dirty)(void *context); + void *context; +} css_node_t; + + +// Lifecycle of nodes and children +css_node_t *new_css_node(void); +void init_css_node(css_node_t *node); +void free_css_node(css_node_t *node); + +// Print utilities +typedef enum { + CSS_PRINT_LAYOUT = 1, + CSS_PRINT_STYLE = 2, + CSS_PRINT_CHILDREN = 4, +} css_print_options_t; +void print_css_node(css_node_t *node, css_print_options_t options); + +// Function that computes the layout! +void layoutNode(css_node_t *node, float maxWidth, css_direction_t parentDirection); +bool isUndefined(float value); + +#endif diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/LayoutExtensions/JUFLXLinearLayoutView.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/LayoutExtensions/JUFLXLinearLayoutView.h new file mode 100644 index 00000000..abbec9c9 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/LayoutExtensions/JUFLXLinearLayoutView.h @@ -0,0 +1,39 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "JUFLXNode.h" + +/** + * Try to solve two kinds of problems. + * 1. Know all the child views' size and layout them, bonus this container can be autoAdjustFrame + * according to child views' size and contentInset and lineSpacing; + * 2. Know some child view's size(not all), auto flex the remain views in this container. + * + * If you want more customization, sugguest JUFLXNode, also this class is build on this, and it support it. + */ +@interface JUFLXLinearLayoutView : UIView + +@property (nonatomic, strong) NSArray *childViews; + +@property (nonatomic, assign) UIEdgeInsets contentInset; + +@property (nonatomic, assign) JUFLXLayoutDirection layoutDirection; + +/** + * If it is yes, the scrollView frame size will be changed depend on childViews' total size. + * If some views' size is not be setted, set it to be YES won't flex those pending views' size + * default is NO. + */ +@property (nonatomic, assign) BOOL autoAdjustFrameSize; + +@property (nonatomic, assign) CGFloat lineSpacing; + +- (void)layout; + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/LayoutExtensions/JUFLXLinearLayoutView.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/LayoutExtensions/JUFLXLinearLayoutView.m new file mode 100644 index 00000000..734d2f30 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/LayoutExtensions/JUFLXLinearLayoutView.m @@ -0,0 +1,180 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "JUFLXLinearLayoutView.h" +#import "UIView+JUFLXNode.h" + +@implementation JUFLXLinearLayoutView { + BOOL _dirty; +} + +@synthesize contentInset = _contentInset, layoutDirection = _layoutDirection, autoAdjustFrameSize = _autoAdjustFrameSize, lineSpacing = _lineSpacing; + +- (instancetype)init { + self = [super init]; + if (self) { + [self commonInit]; + } + + return self; +} + +- (instancetype)initWithFrame:(CGRect)frame { + self = [super initWithFrame:frame]; + if (self) { + [self commonInit]; + } + + return self; +} + +- (instancetype)initWithCoder:(NSCoder *)coder { + self = [super initWithCoder:coder]; + if (self) { + [self commonInit]; + } + + return self; +} + +- (void)commonInit { + _contentInset = UIEdgeInsetsZero; + _layoutDirection = JUFLXLayoutDirectionColumn; + self.ju_flxNode.direction = _layoutDirection; + _autoAdjustFrameSize = NO; + _lineSpacing = 0; +} + +- (void)setAutoAdjustFrameSize:(BOOL)autoAdjustFrameSize { + if (_autoAdjustFrameSize == autoAdjustFrameSize) return; + + _autoAdjustFrameSize = autoAdjustFrameSize; + + CGFloat dimWidth = CGRectGetWidth(self.frame); + CGFloat dimHeight = CGRectGetHeight(self.frame); + + switch (self.layoutDirection) { + case JUFLXLayoutDirectionRow: + case JUFLXLayoutDirectionRowReverse: { + dimWidth = JUFLXLayoutFloatUnDefined; + break; + } + case JUFLXLayoutDirectionColumn: + case JUFLXLayoutDirectionColumnReverse: { + dimHeight = JUFLXLayoutFloatUnDefined; + break; + } + default: { + break; + } + } + + if (_autoAdjustFrameSize) { + self.ju_flxNode.dimensions = CGSizeMake(dimWidth, dimHeight); + } +} + +- (void)setChildViews:(NSArray *)childViews { + if ([_childViews isEqual:childViews]) return; + + _childViews = childViews; + _childViews = [_childViews filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings) { + BOOL isViewClass = [evaluatedObject isKindOfClass:[UIView class]]; + NSAssert(isViewClass, @"views should be class of UIViews"); + + return isViewClass; + }]]; + + for (UIView *view in self.childViews) { + // if the view is not support self sizing, the we flex it + if (!view.ju_flxNode.measure && view.ju_flxNode.flex == 0 && CGSizeEqualToSize(view.ju_flxNode.dimensions, CGSizeZero)) { + view.ju_flxNode.flex = 1; + } + } + + [self setNeedsUpdateChildViews]; + + self.ju_flxNode.childNodes = [self.childViews valueForKey:@"ju_flxNode"]; + + _dirty = YES; +} + +- (void)setContentInset:(UIEdgeInsets)contentInset { + if (UIEdgeInsetsEqualToEdgeInsets(_contentInset, contentInset)) return; + + _contentInset = contentInset; + [self setNeedsUpdateChildViews]; + + _dirty = YES; +} + +- (void)setLayoutDirection:(JUFLXLayoutDirection)layoutDirection { + if (_layoutDirection == layoutDirection) return; + + _layoutDirection = layoutDirection; + self.ju_flxNode.direction = _layoutDirection; + [self setNeedsUpdateChildViews]; + + _dirty = YES; +} + +- (void)setLineSpacing:(CGFloat)lineSpacing { + if (_lineSpacing == lineSpacing) return; + + _lineSpacing = lineSpacing; + [self setNeedsUpdateChildViews]; + + _dirty = YES; +} + +- (void)setNeedsUpdateChildViews { + BOOL isVerticalLayout = (self.ju_flxNode.direction == JUFLXLayoutDirectionColumn || self.ju_flxNode.direction == JUFLXLayoutDirectionColumnReverse); + [self.childViews enumerateObjectsUsingBlock:^(UIView *view, NSUInteger idx, BOOL *stop) { + UIEdgeInsets edge = UIEdgeInsetsZero; + + if (idx == 0) { + if (isVerticalLayout) { + edge = UIEdgeInsetsMake(_contentInset.top, _contentInset.left, 0, _contentInset.right); + } + else { + edge = UIEdgeInsetsMake(_contentInset.top, _contentInset.left, _contentInset.bottom, 0); + } + } + else if (idx == self.childViews.count - 1) { + if (isVerticalLayout) { + edge = UIEdgeInsetsMake(_lineSpacing, _contentInset.left, _contentInset.bottom, _contentInset.right); + } + else { + edge = UIEdgeInsetsMake(_contentInset.top, _lineSpacing, _contentInset.bottom, _contentInset.right); + } + } + else { + if (isVerticalLayout) { + edge = UIEdgeInsetsMake(_lineSpacing, _contentInset.left, 0, _contentInset.right); + } + else { + edge = UIEdgeInsetsMake(_contentInset.top, _lineSpacing, _contentInset.bottom, 0); + } + } + + view.ju_flxNode.margin = edge; + }]; +} + +- (void)setNeedsReload { + if (_dirty) { + [self layout]; + } +} + +- (void)layout { + [self.ju_flxNode layout]; + _dirty = NO; +} + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/UIView+JUFLXNode.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/UIView+JUFLXNode.h new file mode 100644 index 00000000..3e53f298 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/UIView+JUFLXNode.h @@ -0,0 +1,168 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "JUFLXNode.h" + +typedef void (^NodeDidFinishLayout)(JUFLXNode *node); + +@interface UIView (JUFLXNodeGetter) + +- (JUFLXNode *)ju_flxNode; +- (BOOL)ju_hasFlxNode; +- (void)setJu_flxNodeDidFinishLayoutBlock:(NodeDidFinishLayout)block; + +@end + +@interface UIView (JUFLXNodes) + +@property (nonatomic, strong) NSArray *flx_childViews; +/** + * Default is view's frame's origin + */ +//@property (nonatomic, assign) CGPoint flx_viewOrigin; + +/* + * --------------------------------------------------------------------------- + * As Container's property + * --------------------------------------------------------------------------- + */ + +@property (nonatomic, assign) BOOL flx_absolute; + +@property (nonatomic, assign) UIEdgeInsets flx_absoluteEdgeInsets; + +/** + * Check -> http://www.w3.org/TR/css3-flexbox/#flex-direction-property + * inlineCSS -> flex-direction + * Default is row + */ +@property (nonatomic, assign) JUFLXLayoutDirection flx_direction; + +/** + * Check -> http://www.w3.org/TR/css3-flexbox/#propdef-align-items + * inlineCSS -> align-items + * Default is stretch + */ +@property (nonatomic, assign) JUFLXLayoutAlignment flx_alignItems; + +/** + * Check -> http://www.w3.org/TR/css3-flexbox/#propdef-align-content + * inlineCSS -> align-content + * Default is stretch + * Here we don't support the between and around + */ +@property (nonatomic, assign) JUFLXLayoutAlignment flx_alignContent; + +/** + * Check -> http://www.w3.org/TR/css3-flexbox/#propdef-justify-content + * inlineCSS -> justify-content + * Default is start + */ +@property (nonatomic, assign) JUFLXLayoutJustifyContent flx_justifyContent; + +/** + * Check -> http://www.w3.org/TR/css3-flexbox/#flex-wrap-property + * When the container size doesn't satisfy, if use a new depends on this. + * inlineCSS -> flex-wrap + * Here we don't support wrap-reverse + */ +@property (nonatomic, assign) BOOL flx_flexWrap; + + +/* + * --------------------------------------------------------------------------- + * As Child's property + * --------------------------------------------------------------------------- + */ + +/** + * Check -> http://www.w3.org/TR/css3-flexbox/#propdef-align-self + * inlineCSS -> align-self + * Default is auto, means depend on containers' alignItems; + */ +@property (nonatomic, assign) JUFLXLayoutAlignment flx_alignSelf; + +/** + * Means two thing: 1. If self use the remaining space 2. how much would u share with others + * Flex-grow, eg: A node has three children---a,b,c; a.flex = 1, b.flex = 2, c.flex = 1, then a's size will be 1 / (1 + 2 + 1), + * b is 2 / (1 + 2 + 1), c is 1 / (1 + 2 + 1) + * inlineCSS -> flex + * Here we only support flex-grow as flex, not include shrink. + * Default is 0 + */ +@property (nonatomic, assign) CGFloat flx_flex; + +/* + * --------------------------------------------------------------------------- + * As box's property + * --------------------------------------------------------------------------- + */ + +/** + * The style dimensions, default is the view's size, if you set it to {nan, nan}, + * The result frame depends on children's total size, so the children's size should be measured. + * inlineCSS ->size, width, height + * It won't be affected by JUFLXLayoutAlignment + */ +@property (nonatomic, assign) CGSize flx_dimensions; + +/** + * ensure the min dimension of the view size. + * inlineCSS -> min-width, min-height + * Default is {0,0} + */ +@property (nonatomic, assign) CGSize flx_minDimensions; + +/** + * ensure the max dimension of the view size. + * inlineCSS -> max-width, max-height + * Default is {0,0} + */ +@property (nonatomic, assign) CGSize flx_maxDimensions; + +/** + * The margin of the view. + * inlineCSS -> margin, margin-top, margin-left, margin-bottom, margin-right + */ +@property (nonatomic, assign) UIEdgeInsets flx_margin; + +/** + * The padding of the view. + * inlineCSS -> padding, padding-top, padding-left, padding-bottom, padding-right + */ +@property (nonatomic, assign) UIEdgeInsets flx_padding; + +/** + * When encouter the view size should be calculated like text size, use this block. + * If direction is row, then width is the parent's node's frame's width, otherwise is nan. + * It will be affected by JUFLXLayoutAlignment + */ +@property (nonatomic, copy) CGSize (^flx_measure)(CGFloat width); + +/** + * If isSizeToFit == YES, the measure block CGSize (^measure)(CGFloat width) will returned by view's + * sizeThatFits: size, the property will be override by measure block; + * Default is YES; + * It will be affected by JUFLXLayoutAlignment + * inlineCSS -> sizetofit: 1 + */ +@property (nonatomic, assign) BOOL flx_sizeToFit; + +- (void)flx_bindingInlineCSS:(NSString *)inlineCSS; + +- (void)flx_layout; + +- (void)flx_layoutAsync:(BOOL)async; + +- (void)flx_layoutAsync:(BOOL)async completion:(void(^)(CGRect frame))block; + +@end + +FOUNDATION_EXTERN NSString * const JUFLXNodeUIViewNodeKey; +FOUNDATION_EXTERN NSString * const JUFLXNodeUIViewDidFinishBlockKey; diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/UIView+JUFLXNode.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/UIView+JUFLXNode.m new file mode 100644 index 00000000..0a6533a1 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/UIView+JUFLXNode.m @@ -0,0 +1,191 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "UIView+JUFLXNode.h" +#import +#import "JUFLXNode.h" + +NSString * const JUFLXNodeUIViewNodeKey = @"hrnode.JUFLXNodeUIViewNodeKey"; +NSString * const JUFLXNodeUIViewDidFinishBlockKey = @"hrnode.JUFLXNodeUIViewDidFinishBlockKey"; + +@implementation UIView (JUFLXNodeGetter) + +- (JUFLXNode *)ju_flxNode { + JUFLXNode *node = objc_getAssociatedObject(self, &JUFLXNodeUIViewNodeKey); + if (!node) { + node = [JUFLXNode nodeWithView:self]; + } + return node; +} + +- (BOOL)ju_hasFlxNode { + JUFLXNode *node = objc_getAssociatedObject(self, &JUFLXNodeUIViewNodeKey); + return node != nil; +} + +- (void)setJu_flxNodeDidFinishLayoutBlock:(NodeDidFinishLayout)block { + objc_setAssociatedObject(self, &JUFLXNodeUIViewDidFinishBlockKey, block, OBJC_ASSOCIATION_COPY_NONATOMIC); +} + +@end + +@implementation UIView (JUFLXNodes) + +- (NSArray *)flx_childViews { + return [self.ju_flxNode.childNodes valueForKey:@"view"]; +} + +- (void)setFlx_childViews:(NSArray *)flx_childViews { + self.ju_flxNode.childNodes = [flx_childViews valueForKey:@"ju_flxNode"]; +} + +- (UIEdgeInsets)flx_absoluteEdgeInsets { + return self.ju_flxNode.absoluteEdges; +} + +- (void)setFlx_absoluteEdgeInsets:(UIEdgeInsets)flx_absoluteEdgeInsets { + self.ju_flxNode.absoluteEdges = flx_absoluteEdgeInsets; +} + +- (BOOL)flx_absolute { + return self.ju_flxNode.absolute; +} + +- (void)setFlx_absolute:(BOOL)flx_absolute { + self.ju_flxNode.absolute = flx_absolute; +} + +- (JUFLXLayoutDirection)flx_direction { + return self.ju_flxNode.direction; +} + +- (void)setFlx_direction:(JUFLXLayoutDirection)flx_direction { + self.ju_flxNode.direction = flx_direction; +} + +- (JUFLXLayoutAlignment)flx_alignItems { + return self.ju_flxNode.alignItems; +} + +- (void)setFlx_alignItems:(JUFLXLayoutAlignment)flx_alignItems { + self.ju_flxNode.alignItems = flx_alignItems; +} + +- (JUFLXLayoutAlignment)flx_alignContent { + return self.ju_flxNode.alignContent; +} + +- (void)setFlx_alignContent:(JUFLXLayoutAlignment)flx_alignContent { + self.ju_flxNode.alignContent = flx_alignContent; +} + +- (JUFLXLayoutJustifyContent)flx_justifyContent { + return self.ju_flxNode.justifyContent; +} + +- (void)setFlx_justifyContent:(JUFLXLayoutJustifyContent)flx_justifyContent { + self.ju_flxNode.justifyContent = flx_justifyContent; +} + +- (BOOL)flx_flexWrap { + return self.ju_flxNode.flexWrap; +} + +- (void)setFlx_flexWrap:(BOOL)flx_flexWrap { + self.ju_flxNode.flexWrap = flx_flexWrap; +} + +- (JUFLXLayoutAlignment)flx_alignSelf { + return self.ju_flxNode.alignSelf; +} + +- (void)setFlx_alignSelf:(JUFLXLayoutAlignment)flx_alignSelf { + self.ju_flxNode.alignSelf = flx_alignSelf; +} + +- (CGFloat)flx_flex { + return self.ju_flxNode.flex; +} + +- (void)setFlx_flex:(CGFloat)flx_flex { + self.ju_flxNode.flex = flx_flex; +} + +- (CGSize)flx_dimensions { + return self.ju_flxNode.dimensions; +} + +-(void)setFlx_dimensions:(CGSize)flx_dimensions { + self.ju_flxNode.dimensions = flx_dimensions; +} + +- (CGSize)flx_minDimensions { + return self.ju_flxNode.minDimensions; +} + +- (void)setFlx_minDimensions:(CGSize)flx_minDimensions { + self.ju_flxNode.minDimensions = flx_minDimensions; +} + +- (CGSize)flx_maxDimensions { + return self.ju_flxNode.maxDimensions; +} + +- (void)setFlx_maxDimensions:(CGSize)flx_maxDimensions { + self.ju_flxNode.maxDimensions = flx_maxDimensions; +} + +- (UIEdgeInsets)flx_margin { + return self.ju_flxNode.margin; +} + +- (void)setFlx_margin:(UIEdgeInsets)flx_margin { + self.ju_flxNode.margin = flx_margin; +} + +- (UIEdgeInsets)flx_padding { + return self.ju_flxNode.padding; +} + +- (void)setFlx_padding:(UIEdgeInsets)flx_padding { + self.ju_flxNode.padding = flx_padding; +} + +- (void)setFlx_measure:(CGSize (^)(CGFloat))flx_measure { + self.ju_flxNode.measure = flx_measure; +} + +- (CGSize (^)(CGFloat))flx_measure { + return self.ju_flxNode.measure; +} + +- (BOOL)flx_sizeToFit { + return self.ju_flxNode.isSizeToFit; +} + +- (void)setFlx_sizeToFit:(BOOL)flx_sizeToFit { + self.ju_flxNode.sizeToFit = flx_sizeToFit; +} + +- (void)flx_bindingInlineCSS:(NSString *)inlineCSS { + [self.ju_flxNode bindingInlineCSS:inlineCSS]; +} + +- (void)flx_layout { + [self.ju_flxNode layout]; +} + +- (void)flx_layoutAsync:(BOOL)async { + [self.ju_flxNode layoutAsync:async]; +} + +- (void)flx_layoutAsync:(BOOL)async completion:(void(^)(CGRect frame))block { + [self.ju_flxNode layoutAsync:async completionBlock:block]; +} + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvdebug/LVDebugConnection.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvdebug/LVDebugConnection.h new file mode 100644 index 00000000..7550d329 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvdebug/LVDebugConnection.h @@ -0,0 +1,37 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + +@interface LVDebugConnection : NSObject + +@property (nonatomic,assign) BOOL printToServer; +@property (nonatomic,weak) LuaViewCore* lview; +@property (atomic,strong) NSMutableArray* receivedArray; + +- (BOOL) isOk; + +- (NSString*) getCmd; + +- (NSInteger) waitUntilConnectionEnd; + +- (void) sendCmd:(NSString*) cmdName info:(NSString*) info; +- (void) sendCmd:(NSString*) cmdName info:(NSString*) info args:(NSDictionary*) args; +- (void) sendCmd:(NSString*) cmdName fileName:(NSString*)fileName info:(NSString*) info; +- (void) sendCmd:(NSString*) cmdName fileName:(NSString*)fileName info:(NSString*) info args:(NSDictionary*) args; + +-(void) closeAll; + +// 设置调试器的IP和端口, 用于远程调试 ++(void) setDebugerIP:(NSString*) ip port:(int) port; + +#ifdef DEBUG ++(void) openUrlServer:( void(^)(NSDictionary* args) ) callback; +#endif +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvdebug/LVDebugConnection.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvdebug/LVDebugConnection.m new file mode 100644 index 00000000..3ac8f40c --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvdebug/LVDebugConnection.m @@ -0,0 +1,348 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVDebugConnection.h" +#import +#import +#import +#import +#import +#import +#import +#import +#import "LVUtil.h" +#import "LView.h" + + +#define SOCKET_ERROR (-1) +#define SOCKET_CONNECTINTG (0) +#define SOCKET_SUCCESS (1) + +// 调试器的默认IP和端口 +static NSString* SERVER_IP = @"127.0.0.1"; +static int SERVER_PORT = 9876; + +@interface LVDebugConnection () +@property(nonatomic,strong) NSThread* myThread; +@property(nonatomic,assign) BOOL canWrite; +@property(nonatomic,assign) NSInteger state; +@property(atomic,strong) NSMutableArray* sendArray; +@end + +@implementation LVDebugConnection{ + CFSocketRef _socket; +} + +-(id) init{ + self = [super init]; + if( self ) { + static int index = 0; + self.myThread = [[NSThread alloc] initWithTarget:self selector:@selector(run:) object:nil]; + self.myThread.name = [NSString stringWithFormat:@"LuaView.Debuger.%d",index]; + self.sendArray = [[NSMutableArray alloc] init]; + self.receivedArray = [[NSMutableArray alloc] init]; + [self startThread]; + } + return self; +} + +- (void) dealloc{ + [self closeAll]; +} + +-(BOOL) isOk{ + return self.state>0; +} +- (NSInteger) waitUntilConnectionEnd{ + for(;self.state==SOCKET_CONNECTINTG;) { + [NSThread sleepForTimeInterval:0.01]; + } + return self.state; +} + +-(void) startThread{ + [self.myThread start]; //启动线程 +} + ++(void) setDebugerIP:(NSString*) ip port:(int) port{ + SERVER_IP = ip; + SERVER_PORT = port; +} + +-(void) run:(id) obj{ + @autoreleasepool { + [self Connect:SERVER_IP port:SERVER_PORT]; + + NSRunLoop *runLoop = [NSRunLoop currentRunLoop]; + [runLoop addPort:[NSMachPort port] forMode:NSDefaultRunLoopMode]; + [runLoop run]; + } +} + +- (NSString*) getCmd{ + NSString* cmd = self.receivedArray.lastObject; + if( cmd ) { + [self.receivedArray removeLastObject]; + } + return cmd; +} + +- (void) sendCmd:(NSString*) cmdName info:(NSString*) info{ + [self sendCmd:cmdName fileName:nil info:info]; +} + +- (void) sendCmd:(NSString*) cmdName info:(NSString*) info args:(NSDictionary*) args{ + [self sendCmd:cmdName fileName:nil info:info args:args]; +} + +- (void) sendCmd:(NSString*) cmdName fileName:(NSString*)fileName info:(NSString*) info{ + [self sendCmd:cmdName fileName:fileName info:info args:nil]; +} + +- (void) sendCmd:(NSString*) cmdName fileName:(NSString*)fileName info:(NSString*) info args:(NSDictionary*) args{ + NSMutableString* buffer = [[NSMutableString alloc] init]; + if ( cmdName ) { + [buffer appendFormat:@"Cmd-Name:%@\n",cmdName]; + } + if ( fileName ){ + [buffer appendFormat:@"File-Name:%@\n",fileName]; + } + NSArray* keys = args.allKeys; + for( int i=0; i0) { + LVLog(@"[调试日志][收到指令] %@ ", cmd); + [debuger.receivedArray insertObject:cmd atIndex:0]; + } + // 关闭掉socket + if ( cmd.length<=0 ){ + [debuger closeAll]; + [debuger.receivedArray insertObject:@"close" atIndex:0]; + [debuger.receivedArray insertObject:@"close" atIndex:0]; + } else { + [debuger.lview callLuaToExecuteServerCmd]; + } + break; + } + case kCFSocketWriteCallBack: { + debuger.canWrite = YES; + [debuger sendOneData]; + break; + } + case kCFSocketConnectCallBack: + if( data ) { + // LVLog(@"Debuger Socket Connect failed" ); + debuger.state = SOCKET_ERROR; + } else { + LVLog(@"Debuger Socket connect Success"); + debuger.state = SOCKET_SUCCESS; + } + break; + default: { + LVLog(@"connect type %d", (int)type ); + break; + } + } +} +#endif + +-(void) sendOneData{ + NSData* data = self.sendArray.lastObject; + if( self.canWrite && data) { + [self.sendArray removeLastObject]; + if( data ) { + NSInteger sendLength = send(CFSocketGetNative(_socket), data.bytes, data.length, 0); + if( sendLength!=data.length ) { + LVError(@"Debuger socket Send length Error : %d != %d", (int)sendLength, (int)data.length); + } + } + } +} + +///////////////////监听来自服务器的信息/////////////////// + +#ifdef DEBUG +static NSString* readString(CFSocketRef socket) +{ + unsigned char head[4] = {0}; + NSUInteger readLength0 = 0; + if( recv( CFSocketGetNative(socket), head, sizeof(head), 0 )==sizeof(head) ) { + NSUInteger d0 = head[0]; + NSUInteger d1 = head[1]; + NSUInteger d2 = head[2]; + NSUInteger d3 = head[3]; + readLength0 = (d0<<24) + (d1<<16) + (d2<<8) + d3; + } + + unsigned char buffer[512] = {0}; + NSUInteger readLen = readLength0; + NSMutableData* data = [[NSMutableData alloc] init]; + for(;readLen>0;){ + NSUInteger bufferLen = readLen>=sizeof(buffer)?sizeof(buffer):readLen; + NSUInteger recvLen = recv( CFSocketGetNative(socket), buffer, bufferLen, 0 ); + if ( recvLen>0 ) { + [data appendBytes:buffer length:recvLen]; + readLen -= recvLen; + } else { + break; + } + } + NSString* ret = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; + return ret; +} +#endif +/////////////////////////发送信息给服务器//////////////////////// +- (void) sendString:(NSString *)string +{ + if( self.canWrite ) { + NSData* data = [string dataUsingEncoding:NSUTF8StringEncoding]; + NSUInteger len = data.length; + NSMutableData* buffer = [[NSMutableData alloc] init]; + unsigned char head[4] = {0}; + head[0] = (len>>24); + head[1] = (len>>16); + head[2] = (len>>8); + head[3] = (len); + [buffer appendBytes:head length:4]; + [buffer appendData:data]; + + [self.sendArray insertObject:buffer atIndex:0]; + + [self sendOneData]; + } +} + + +#ifdef DEBUG ++ (id)jsonObject:(NSString *)s{ + NSData* data = [s dataUsingEncoding:NSUTF8StringEncoding]; + @try { + NSError *error = nil; + NSJSONReadingOptions options = 0; + id obj = [NSJSONSerialization JSONObjectWithData:data options:options error:&error]; + if (error) { + return nil; + } + return obj; + } @catch (NSException *exception) { + return nil; + } +} + ++(void) openUrlServer:( void(^)(NSDictionary* args) ) callback{ + dispatch_async(dispatch_get_global_queue(0, 0), ^{ + // 处理耗时操作的代码块... + + LVDebugConnection* debugConnection = [[LVDebugConnection alloc] init]; + if( [debugConnection waitUntilConnectionEnd]>0 ) { + [debugConnection sendCmd:@"debugger" info:@"true"]; + for(;;) { + NSString* cmd = [debugConnection getCmd]; + if( cmd ) { + NSDictionary* dic = [LVDebugConnection jsonObject:cmd]; + if( dic && [dic isKindOfClass:[NSDictionary class]] ) { + //通知主线程刷新 + dispatch_async(dispatch_get_main_queue(), ^{ + //回调或者说是通知主线程刷新, + if( callback ) { + callback( dic ); + } + }); + } + break; + } else { + [NSThread sleepForTimeInterval:0.1]; + } + } + [debugConnection closeAll]; + } else { + [debugConnection closeAll]; + } + + }); +} +#endif + + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvdebug/LVDebugLua.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvdebug/LVDebugLua.m new file mode 100644 index 00000000..af59ae89 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvdebug/LVDebugLua.m @@ -0,0 +1,759 @@ + +// debug.lua +char g_debug_lua[10674] = { + '_','D','E','B','U','G','_','F','I','L','E',' ','=',' ','"','d','e','b','u','g','.','l','u','a','"',0xa, + // _DEBUG_FILE = "debug.lua" + 0xa, + 'd','e','b','u','g','.','b','p','s',' ','=',' ','{',0xa, + // debug.bps = { + ' ',' ',' ',' ','m','a','x',' ','=',' ','0',',',0xa, + // max = 0, + ' ',' ',' ',' ','t','r','a','c','e',' ','=',' ','f','a','l','s','e',',',0xa, + // trace = false, + ' ',' ',' ',' ','l','a','s','t','_','c','m','d',' ','=',' ','"','"',',',0xa, + // last_cmd = "", + ' ',' ',' ',' ','n','e','x','t',' ','=',' ','f','a','l','s','e',',',0xa, + // next = false, + ' ',' ',' ',' ','c','u','r','_','f','u','n','c',' ','=',' ','n','i','l',',',0xa, + // cur_func = nil, + ' ',' ',' ',' ','t','r','a','c','e','_','c','o','u','n','t',' ','=',' ','0',',',0xa, + // trace_count = 0, + ' ',' ',' ',' ','v','a','r','_','t','b','l',' ','=',' ','n','i','l',',',0xa, + // var_tbl = nil, + '}',0xa, + // } + 0xa, + 'f','u','n','c','t','i','o','n',' ','d','e','b','u','g','_','l','o','g','(',' ','l','o','g','_','s','t','r',' ',')',0xa, + // function debug_log( log_str ) + ' ',' ',' ',' ','p','r','i','n','t','(',' ','"','[','L','u','a','V','i','e','w',']','[',0xe8,0xb0,0x83,0xe8,0xaf,0x95,0xe6,0x97,0xa5,0xe5,0xbf,0x97,']',' ','"',' ','.','.',' ','l','o','g','_','s','t','r',' ',')',';',0xa, + // print( "[LuaView][调试日志] " .. log_str ); + 'e','n','d',0xa, + // end + 0xa, + 'f','u','n','c','t','i','o','n',' ','d','e','b','u','g','_','p','r','i','n','t','_','v','a','r','_','0','(',' ','n','a','m','e',',',' ','v','a','l','u','e',',',' ','l','e','v','e','l',' ',')',0xa, + // function debug_print_var_0( name, value, level ) + ' ',' ',' ',' ','l','o','c','a','l',' ','r','e','t',' ','=',' ','"','"',';',0xa, + // local ret = ""; + ' ',' ',' ',' ','l','o','c','a','l',' ','p','r','e','f','i','x',' ','=',' ','s','t','r','i','n','g','.','r','e','p','(',' ','"',' ',' ',' ',' ','"',',',' ','l','e','v','e','l',' ',')',0xa, + // local prefix = string.rep( " ", level ) + ' ',' ',' ',' ','l','o','c','a','l',' ','s','t','r',' ','=',' ','s','t','r','i','n','g','.','f','o','r','m','a','t','(',' ','"','%','s','%','s',' ','=',' ','%','s','"',',',' ','p','r','e','f','i','x',',',' ','n','a','m','e',',',' ','t','o','s','t','r','i','n','g','(','v','a','l','u','e',')',' ',')',0xa, + // local str = string.format( "%s%s = %s", prefix, name, tostring(value) ) + 0xa, + ' ',' ',' ',' ','i','f',' ','t','y','p','e','(',' ','v','a','l','u','e',' ',')',' ','=','=',' ','"','t','a','b','l','e','"',' ','t','h','e','n',0xa, + // if type( value ) == "table" then + ' ',' ',' ',' ',' ',' ',' ',' ','i','f',' ','d','e','b','u','g','.','v','a','r','_','t','b','l','[','v','a','l','u','e',']',' ','t','h','e','n',0xa, + // if debug.var_tbl[value] then + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','-','-',0xe5,0xb7,0xb2,0xe5,0x9c,0xa8,0xe4,0xb8,0xb4,0xe6,0x97,0xb6,0xe8,0xa1,0xa8,0xe4,0xb8,0xad,0xe7,0x9a,0x84,',',0xe5,0x8f,0xaa,0xe6,0x89,0x93,0xe5,0x8d,0xb0,0xe8,0xa1,0xa8,0xe5,0x9c,0xb0,0xe5,0x9d,0x80,0xa, + // --已在临时表中的,只打印表地址 + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','r','e','t',' ','=',' ','r','e','t',' ','.','.',' ','t','o','s','t','r','i','n','g','(','s','t','r',')',' ','.','.',' ',0x27,0x5c,'n',0x27,';',0xa, + // ret = ret .. tostring(str) .. '\n'; + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','r','e','t','u','r','n',' ','r','e','t',';',0xa, + // return ret; + ' ',' ',' ',' ',' ',' ',' ',' ','e','n','d',0xa, + // end + 0xa, + ' ',' ',' ',' ',' ',' ',' ',' ','-','-',0xe5,0x8a,0xa0,0xe5,0x88,0xb0,0xe4,0xb8,0xb4,0xe6,0x97,0xb6,0xe8,0xa1,0xa8,0xe4,0xb8,0xad,',',0xe4,0xbb,0xa5,0xe5,0x85,0x8d,0xe8,0xa1,0xa8,0xe5,0x87,0xba,0xe7,0x8e,0xb0,0xe5,0xbe,0xaa,0xe7,0x8e,0xaf,0xe5,0xbc,0x95,0xe7,0x94,0xa8,0xe6,0x97,0xb6,',',0xe6,0x89,0x93,0xe5,0x8d,0xb0,0xe4,0xb9,0x9f,0xe4,0xba,0xa7,0xe7,0x94,0x9f,0xe6,0xad,0xbb,0xe5,0xbe,0xaa,0xe7,0x8e,0xaf,0xa, + // --加到临时表中,以免表出现循环引用时,打印也产生死循环 + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','.','v','a','r','_','t','b','l','[','v','a','l','u','e',']',' ','=',' ','t','r','u','e',0xa, + // debug.var_tbl[value] = true + ' ',' ',' ',' ',' ',' ',' ',' ','-','-',0xe6,0x89,0x93,0xe5,0x8d,0xb0,0xe8,0xa1,0xa8,0xe4,0xb8,0xad,0xe6,0x89,0x80,0xe6,0x9c,0x89,0xe6,0x95,0xb0,0xe6,0x8d,0xae,0xa, + // --打印表中所有数据 + ' ',' ',' ',' ',' ',' ',' ',' ','r','e','t',' ','=',' ','r','e','t',' ','.','.',' ','s','t','r','i','n','g','.','f','o','r','m','a','t','(',' ','"','%','s','%','s',' ','=',' ','{','"',',',' ','p','r','e','f','i','x',',',' ','n','a','m','e',' ',')',' ','.','.',' ',0x27,0x5c,'n',0x27,';',0xa, + // ret = ret .. string.format( "%s%s = {", prefix, name ) .. '\n'; + ' ',' ',' ',' ',' ',' ',' ',' ','f','o','r',' ','k',',',' ','v',' ','i','n',' ','p','a','i','r','s','(',' ','v','a','l','u','e',' ',')',' ','d','o',0xa, + // for k, v in pairs( value ) do + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','i','f',' ','t','y','p','e','(',' ','k',' ',')',' ','=','=',' ','"','s','t','r','i','n','g','"',' ','t','h','e','n',0xa, + // if type( k ) == "string" then + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','e','l','s','e',0xa, + // else + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','k',' ','=',' ','t','o','s','t','r','i','n','g','(','k',')',';',0xa, + // k = tostring(k); + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','-','-',0xe4,0xb8,0x8d,0xe6,0x89,0x93,0xe5,0x8d,0xb0,' ','"','_','"',0xe5,0xbc,0x80,0xe5,0xa4,0xb4,0xe7,0x9a,0x84,0xe5,0x86,0x85,0xe9,0x83,0xa8,0xe5,0x8f,0x98,0xe9,0x87,0x8f,0xa, + // --不打印 "_"开头的内部变量 + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','-','-','i','f',' ','s','t','r','i','n','g','.','s','u','b','(',' ','k',',',' ','1',',',' ','1',' ',')',' ','~','=',' ','"','_','"',' ','t','h','e','n',0xa, + // --if string.sub( k, 1, 1 ) ~= "_" then + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','r','e','t',' ','=',' ','r','e','t',' ','.','.',' ','d','e','b','u','g','_','p','r','i','n','t','_','v','a','r','_','0','(',' ','k',',',' ','v',',',' ','l','e','v','e','l',' ','+',' ','1',' ',')',0xa, + // ret = ret .. debug_print_var_0( k, v, level + 1 ) + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','-','-','e','n','d',0xa, + // --end + ' ',' ',' ',' ',' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ',' ',' ',' ',' ','r','e','t',' ','=',' ','r','e','t',' ','.','.',' ','p','r','e','f','i','x',' ','.','.',' ','"','}','"',' ','.','.',' ',0x27,0x5c,'n',0x27,';',0xa, + // ret = ret .. prefix .. "}" .. '\n'; + ' ',' ',' ',' ','e','l','s','e','i','f',' ','t','y','p','e','(',' ','v','a','l','u','e',' ',')',' ','=','=',' ','"','s','t','r','i','n','g','"',' ','t','h','e','n',0xa, + // elseif type( value ) == "string" then + ' ',' ',' ',' ',' ',' ',' ',' ','r','e','t',' ','=',' ','r','e','t',' ','.','.',' ','t','o','s','t','r','i','n','g','(','s','t','r',')',' ','.','.',' ',0x27,0x5c,'n',0x27,';',0xa, + // ret = ret .. tostring(str) .. '\n'; + ' ',' ',' ',' ','e','l','s','e',0xa, + // else + ' ',' ',' ',' ',' ',' ',' ',' ','r','e','t',' ','=',' ','r','e','t',' ','.','.',' ','t','o','s','t','r','i','n','g','(','s','t','r',')',' ','.','.',' ',0x27,0x5c,'n',0x27,';',0xa, + // ret = ret .. tostring(str) .. '\n'; + ' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ','r','e','t','u','r','n',' ','r','e','t',';',0xa, + // return ret; + 'e','n','d',0xa, + // end + 0xa, + 'f','u','n','c','t','i','o','n',' ','d','e','b','u','g','_','p','r','i','n','t','_','v','a','r','(',' ','n','a','m','e',',',' ','v','a','l','u','e',',',' ','l','e','v','e','l',' ',')',0xa, + // function debug_print_var( name, value, level ) + ' ',' ',' ',' ','l','o','c','a','l',' ','s',' ','=',' ','d','e','b','u','g','_','p','r','i','n','t','_','v','a','r','_','0','(',' ','n','a','m','e',',',' ','v','a','l','u','e',',',' ','l','e','v','e','l',' ',')',';',0xa, + // local s = debug_print_var_0( name, value, level ); + ' ',' ',' ',' ','i','f','(',' ','s',' ',')',' ','t','h','e','n',0xa, + // if( s ) then + ' ',' ',' ',' ',' ',' ',' ',' ','s',' ','=',' ','s',':','s','u','b','(','1',',',' ','s',':','l','e','n','(',')','-','1',' ',')',';',0xa, + // s = s:sub(1, s:len()-1 ); + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','l','o','g','(',' ','s',' ',')',';',0xa, + // debug_log( s ); + ' ',' ',' ',' ','e','l','s','e',0xa, + // else + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','l','o','g','(',' ','s',' ',')',';',0xa, + // debug_log( s ); + ' ',' ',' ',' ','e','n','d',0xa, + // end + 'e','n','d',0xa, + // end + 0xa, + 'f','u','n','c','t','i','o','n',' ','d','e','b','u','g','_','p','r','i','n','t','_','e','x','p','r','(',' ','v','a','r',' ',')',0xa, + // function debug_print_expr( var ) + ' ',' ',' ',' ','i','f',' ','(',' ','v','a','r','=','=','n','i','l',' ',')',' ','t','h','e','n',0xa, + // if ( var==nil ) then + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','l','o','g','(','"','d','e','b','u','g','_','p','r','i','n','t','_','e','x','p','r',' ','v','a','r','=','=','n','i','l','"',')',';',0xa, + // debug_log("debug_print_expr var==nil"); + ' ',' ',' ',' ',' ',' ',' ',' ','r','e','t','u','r','n',';',0xa, + // return; + ' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ','-','-',0xe6,0xb8,0x85,0xe7,0xa9,0xba,0xe4,0xb8,0xb4,0xe6,0x97,0xb6,0xe5,0x8f,0x98,0xe9,0x87,0x8f,0xe8,0xa1,0xa8,0xa, + // --清空临时变量表 + ' ',' ',' ',' ','d','e','b','u','g','.','v','a','r','_','t','b','l',' ','=',' ','{','}',0xa, + // debug.var_tbl = {} + 0xa, + ' ',' ',' ',' ','l','o','c','a','l',' ','i','n','d','e','x',' ','=',' ','1',0xa, + // local index = 1 + ' ',' ',' ',' ','-','-',0xe6,0x89,0xbe,0xe5,0xb1,0x80,0xe9,0x83,0xa8,0xe5,0x8f,0x98,0xe9,0x87,0x8f,0xa, + // --找局部变量 + ' ',' ',' ',' ','w','h','i','l','e',' ','t','r','u','e',' ','d','o',0xa, + // while true do + ' ',' ',' ',' ',' ',' ',' ',' ','l','o','c','a','l',' ','n','a','m','e',',',' ','v','a','l','u','e',' ','=',' ','d','e','b','u','g','.','g','e','t','l','o','c','a','l','(',' ','4',',',' ','i','n','d','e','x',' ',')',0xa, + // local name, value = debug.getlocal( 4, index ) + ' ',' ',' ',' ',' ',' ',' ',' ','i','f',' ','n','o','t',' ','n','a','m','e',' ','t','h','e','n',' ',0xa, + // if not name then + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','b','r','e','a','k',' ',0xa, + // break + ' ',' ',' ',' ',' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ',' ',' ',' ',' ','i','n','d','e','x',' ','=',' ','i','n','d','e','x',' ','+',' ','1',0xa, + // index = index + 1 + 0xa, + ' ',' ',' ',' ',' ',' ',' ',' ','i','f',' ','n','a','m','e',' ','=','=',' ','v','a','r',' ','t','h','e','n',0xa, + // if name == var then + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','p','r','i','n','t','_','v','a','r','(',' ','v','a','r',',',' ','v','a','l','u','e',',',' ','0',' ',')',0xa, + // debug_print_var( var, value, 0 ) + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','r','e','t','u','r','n',0xa, + // return + ' ',' ',' ',' ',' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ','e','n','d',0xa, + // end + 0xa, + ' ',' ',' ',' ','-','-',' ','t','r','y',' ','u','p','v','a','l','u','e','s',0xa, + // -- try upvalues + ' ',' ',' ',' ','l','o','c','a','l',' ','f','u','n','c',' ','=',' ','d','e','b','u','g','.','g','e','t','i','n','f','o','(','4',',','"','f','"',')','.','f','u','n','c',0xa, + // local func = debug.getinfo(4,"f").func + ' ',' ',' ',' ','l','o','c','a','l',' ','i','n','d','e','x',' ','=',' ','1',0xa, + // local index = 1 + ' ',' ',' ',' ','w','h','i','l','e',' ','t','r','u','e',' ','d','o',0xa, + // while true do + ' ',' ',' ',' ',' ',' ',' ',' ','l','o','c','a','l',' ','n','a','m','e',',',' ','v','a','l','u','e',' ','=',' ','d','e','b','u','g','.','g','e','t','u','p','v','a','l','u','e','(','f','u','n','c',',',' ','i','n','d','e','x',')',0xa, + // local name, value = debug.getupvalue(func, index) + ' ',' ',' ',' ',' ',' ',' ',' ','i','f',' ','n','o','t',' ','n','a','m','e',' ','t','h','e','n',' ',0xa, + // if not name then + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','b','r','e','a','k',' ',0xa, + // break + ' ',' ',' ',' ',' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ',' ',' ',' ',' ','i','f',' ','n','a','m','e',' ','=','=',' ','v','a','r',' ','t','h','e','n',' ',0xa, + // if name == var then + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','p','r','i','n','t','_','v','a','r','(',' ','v','a','r',',',' ','v','a','l','u','e',',',' ','0',' ',')',0xa, + // debug_print_var( var, value, 0 ) + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','r','e','t','u','r','n',0xa, + // return + ' ',' ',' ',' ',' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ',' ',' ',' ','i','n','d','e','x',' ','=',' ','i','n','d','e','x',' ','+',' ','1',0xa, + // index = index + 1 + ' ',' ',' ',' ','e','n','d',0xa, + // end + 0xa, + ' ',' ',' ',' ','-','-',0xe6,0x89,0xbe,0xe5,0x85,0xa8,0xe5,0xb1,0x80,0xe5,0x8f,0x98,0xe9,0x87,0x8f,0xa, + // --找全局变量 + ' ',' ',' ',' ','i','f',' ','_','G','[','v','a','r',']',' ','~','=',' ','n','i','l',' ','t','h','e','n',0xa, + // if _G[var] ~= nil then + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','p','r','i','n','t','_','v','a','r','(',' ','v','a','r',',',' ','_','G','[','v','a','r',']',',',' ','0',' ',')',0xa, + // debug_print_var( var, _G[var], 0 ) + ' ',' ',' ',' ',' ',' ',' ',' ','r','e','t','u','r','n',0xa, + // return + ' ',' ',' ',' ','e','n','d',0xa, + // end + 0xa, + ' ',' ',' ',' ','d','e','b','u','g','_','l','o','g','(',' ','v','a','r',' ','.','.',' ','"',' ','i','s',' ','i','n','v','a','l','i','d','"',' ',')',0xa, + // debug_log( var .. " is invalid" ) + 'e','n','d',0xa, + // end + 0xa, + 0xa, + 'f','u','n','c','t','i','o','n',' ','d','e','b','u','g','_','r','u','n','_','e','x','p','r','(',' ','s',' ',')',0xa, + // function debug_run_expr( s ) + ' ',' ',' ',' ','l','o','a','d','J','s','o','n','(','s',')',0xa, + // loadJson(s) + 'e','n','d',0xa, + // end + 0xa, + 'f','u','n','c','t','i','o','n',' ','a','d','d','_','b','r','e','a','k','p','o','i','n','t','(',' ','e','x','p','r',' ',')',0xa, + // function add_breakpoint( expr ) + ' ',' ',' ',' ','l','o','c','a','l',' ','s','i',' ','=',' ','s','t','r','i','n','g','.','f','i','n','d','(',' ','e','x','p','r',',',' ','"',':','"',' ',')',0xa, + // local si = string.find( expr, ":" ) + ' ',' ',' ',' ','i','f',' ','n','i','l',' ','=','=',' ','s','i',' ','t','h','e','n',0xa, + // if nil == si then + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','l','o','g','(',' ','"','a','d','d',' ','b','r','e','a','k','p','o','i','n','t',' ','e','r','r','o','r',',',' ','e','x','p','r',' ','(','"',' ','.','.',' ','e','x','p','r',' ','.','.',' ','"',')',' ','i','n','v','a','l','i','d','"',' ',')',0xa, + // debug_log( "add breakpoint error, expr (" .. expr .. ") invalid" ) + ' ',' ',' ',' ',' ',' ',' ',' ','r','e','t','u','r','n',0xa, + // return + ' ',' ',' ',' ','e','n','d',0xa, + // end + 0xa, + ' ',' ',' ',' ','l','o','c','a','l',' ','l','i','n','e',' ','=',' ','s','t','r','i','n','g','.','s','u','b','(',' ','e','x','p','r',',',' ','s','i',' ','+',' ','1',' ',')',0xa, + // local line = string.sub( expr, si + 1 ) + ' ',' ',' ',' ','l','o','c','a','l',' ','l','i','n','e',' ','=',' ','t','o','n','u','m','b','e','r','(',' ','l','i','n','e',' ',')',0xa, + // local line = tonumber( line ) + ' ',' ',' ',' ','l','o','c','a','l',' ','s','o','u','r','c','e',' ','=',' ','s','t','r','i','n','g','.','s','u','b','(',' ','e','x','p','r',',',' ','1',',',' ','s','i',' ','-',' ','1',' ',')',0xa, + // local source = string.sub( expr, 1, si - 1 ) + 0xa, + ' ',' ',' ',' ','-','-',0xe5,0x85,0x88,0xe6,0x9f,0xa5,0xe6,0x89,0xbe,0xe6,0x9c,0x89,0xe4,0xb8,0x8d,0xe6,0x9c,0x89,0xe7,0x9b,0xb8,0xe5,0x90,0x8c,0xe6,0x96,0xad,0xe7,0x82,0xb9,0xa, + // --先查找有不有相同断点 + ' ',' ',' ',' ','i','f',' ','(',' ','(',' ','d','e','b','u','g','.','b','p','s','[','l','i','n','e',']',' ','~','=',' ','n','i','l',' ',')',' ','a','n','d',' ','(',' ','d','e','b','u','g','.','b','p','s','[','l','i','n','e',']','[','s','o','u','r','c','e',']',' ','~','=',' ','n','i','l',' ',')',' ',')',' ','t','h','e','n',0xa, + // if ( ( debug.bps[line] ~= nil ) and ( debug.bps[line][source] ~= nil ) ) then + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','l','o','g','(',' ','s','t','r','i','n','g','.','f','o','r','m','a','t','(',' ','"','b','r','e','a','k','p','o','i','n','t',' ','%','s',':','%','d',' ','e','x','i','s','t','e','d','"',',',' ','s','o','u','r','c','e',',',' ','l','i','n','e',' ',')',' ',')',0xa, + // debug_log( string.format( "breakpoint %s:%d existed", source, line ) ) + ' ',' ',' ',' ',' ',' ',' ',' ','r','e','t','u','r','n',0xa, + // return + ' ',' ',' ',' ','e','n','d',0xa, + // end + 0xa, + ' ',' ',' ',' ','l','o','c','a','l',' ','t','b','l',' ','=',' ','{','}',0xa, + // local tbl = {} + ' ',' ',' ',' ','t','b','l','.','s','o','u','r','c','e',' ','=',' ','s','o','u','r','c','e',0xa, + // tbl.source = source + ' ',' ',' ',' ','t','b','l','.','l','i','n','e',' ','=',' ','l','i','n','e',0xa, + // tbl.line = line + ' ',' ',' ',' ','t','b','l','.','a','c','t','i','v','e',' ','=',' ','t','r','u','e',0xa, + // tbl.active = true + ' ',' ',' ',' ','t','b','l','.','n','u','m','b','e','r',' ','=',' ','d','e','b','u','g','.','b','p','s','.','m','a','x',' ','+',' ','1',0xa, + // tbl.number = debug.bps.max + 1 + 0xa, + ' ',' ',' ',' ','i','f',' ','d','e','b','u','g','.','b','p','s','[','l','i','n','e',']',' ','=','=',' ','n','i','l',' ','t','h','e','n',0xa, + // if debug.bps[line] == nil then + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','.','b','p','s','[','l','i','n','e',']',' ','=',' ','{','}',0xa, + // debug.bps[line] = {} + ' ',' ',' ',' ','e','n','d',0xa, + // end + 0xa, + ' ',' ',' ',' ','d','e','b','u','g','.','b','p','s','[','l','i','n','e',']','[','s','o','u','r','c','e',']',' ','=',' ','t','b','l',0xa, + // debug.bps[line][source] = tbl + ' ',' ',' ',' ','d','e','b','u','g','.','b','p','s','.','m','a','x',' ','=',' ','d','e','b','u','g','.','b','p','s','.','m','a','x',' ','+',' ','1',0xa, + // debug.bps.max = debug.bps.max + 1 + ' ',' ',' ',' ','d','e','b','u','g','_','l','o','g','(',' ','s','t','r','i','n','g','.','f','o','r','m','a','t','(',' ','"',0xe5,0x8a,0xa0,0xe6,0x96,0xad,0xe7,0x82,0xb9,'(','%','s',':','%','d',')','"',',',' ','s','o','u','r','c','e',',',' ','l','i','n','e',' ',')',' ',')',0xa, + // debug_log( string.format( "加断点(%s:%d)", source, line ) ) + 'e','n','d',0xa, + // end + 0xa, + 'f','u','n','c','t','i','o','n',' ','r','e','m','o','v','e','_','b','r','e','a','k','p','o','i','n','t','(',' ','e','x','p','r',' ',')',0xa, + // function remove_breakpoint( expr ) + ' ',' ',' ',' ','l','o','c','a','l',' ','s','i',' ','=',' ','s','t','r','i','n','g','.','f','i','n','d','(',' ','e','x','p','r',',',' ','"',':','"',' ',')',0xa, + // local si = string.find( expr, ":" ) + ' ',' ',' ',' ','i','f',' ','n','i','l',' ','=','=',' ','s','i',' ','t','h','e','n',0xa, + // if nil == si then + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','l','o','g','(',' ','"','r','e','m','o','v','e',' ','b','r','e','a','k','p','o','i','n','t',' ','e','r','r','o','r',',',' ','e','x','p','r',' ','(','"',' ','.','.',' ','e','x','p','r',' ','.','.',' ','"',')',' ','i','n','v','a','l','i','d','"',' ',')',0xa, + // debug_log( "remove breakpoint error, expr (" .. expr .. ") invalid" ) + ' ',' ',' ',' ',' ',' ',' ',' ','r','e','t','u','r','n',0xa, + // return + ' ',' ',' ',' ','e','n','d',0xa, + // end + 0xa, + ' ',' ',' ',' ','l','o','c','a','l',' ','l','i','n','e',' ','=',' ','s','t','r','i','n','g','.','s','u','b','(',' ','e','x','p','r',',',' ','s','i',' ','+',' ','1',' ',')',0xa, + // local line = string.sub( expr, si + 1 ) + ' ',' ',' ',' ','l','o','c','a','l',' ','l','i','n','e',' ','=',' ','t','o','n','u','m','b','e','r','(',' ','l','i','n','e',' ',')',0xa, + // local line = tonumber( line ) + ' ',' ',' ',' ','l','o','c','a','l',' ','s','o','u','r','c','e',' ','=',' ','s','t','r','i','n','g','.','s','u','b','(',' ','e','x','p','r',',',' ','1',',',' ','s','i',' ','-',' ','1',' ',')',0xa, + // local source = string.sub( expr, 1, si - 1 ) + 0xa, + ' ',' ',' ',' ','-','-',0xe5,0x85,0x88,0xe6,0x9f,0xa5,0xe6,0x89,0xbe,0xe6,0x9c,0x89,0xe4,0xb8,0x8d,0xe6,0x9c,0x89,0xe7,0x9b,0xb8,0xe5,0x90,0x8c,0xe6,0x96,0xad,0xe7,0x82,0xb9,0xa, + // --先查找有不有相同断点 + ' ',' ',' ',' ','i','f','(',' ','(',' ','d','e','b','u','g','.','b','p','s','[','l','i','n','e',']',' ','~','=',' ','n','i','l',' ',')',' ','a','n','d',' ','(',' ','d','e','b','u','g','.','b','p','s','[','l','i','n','e',']','[','s','o','u','r','c','e',']',' ','~','=',' ','n','i','l',' ',')',' ',')','t','h','e','n',0xa, + // if( ( debug.bps[line] ~= nil ) and ( debug.bps[line][source] ~= nil ) )then + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','.','b','p','s','[','l','i','n','e',']','[','s','o','u','r','c','e',']',' ','=',' ','n','i','l',';',0xa, + // debug.bps[line][source] = nil; + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','l','o','g','(',' ','s','t','r','i','n','g','.','f','o','r','m','a','t','(',' ','"',0xe5,0x88,0xa0,0xe7,0x82,0xb9,0xe6,0x96,0xad,'(','%','s',':','%','d',')','"',',',' ','s','o','u','r','c','e',',',' ','l','i','n','e',' ',')',' ',')',0xa, + // debug_log( string.format( "删点断(%s:%d)", source, line ) ) + ' ',' ',' ',' ',' ',' ',' ',' ','r','e','t','u','r','n',0xa, + // return + ' ',' ',' ',' ','e','l','s','e',0xa, + // else + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','l','o','g','(',' ','s','t','r','i','n','g','.','f','o','r','m','a','t','(',' ','"','n','o','t',' ','f','o','u','n','d',' ','b','r','e','a','k','p','o','i','n','t',' ','%','s',':','%','d',' ','e','x','i','s','t','e','d','"',',',' ','s','o','u','r','c','e',',',' ','l','i','n','e',' ',')',' ',')',0xa, + // debug_log( string.format( "not found breakpoint %s:%d existed", source, line ) ) + ' ',' ',' ',' ',' ',' ',' ',' ','r','e','t','u','r','n',0xa, + // return + ' ',' ',' ',' ','e','n','d',0xa, + // end + 'e','n','d',0xa, + // end + 0xa, + 'f','u','n','c','t','i','o','n',' ','d','e','b','u','g','_','s','h','o','w','_','b','p','(',')',0xa, + // function debug_show_bp() + ' ',' ',' ',' ','f','o','r',' ','k',',',' ','v',' ','i','n',' ','p','a','i','r','s','(',' ','d','e','b','u','g','.','b','p','s',' ',')',' ','d','o',0xa, + // for k, v in pairs( debug.bps ) do + ' ',' ',' ',' ',' ',' ',' ',' ','i','f',' ','t','y','p','e','(',' ','v',' ',')',' ','=','=',' ','"','t','a','b','l','e','"',' ','t','h','e','n',0xa, + // if type( v ) == "table" then + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','f','o','r',' ','k','1',',',' ','v','1',' ','i','n',' ','p','a','i','r','s','(',' ','v',' ',')',' ','d','o',0xa, + // for k1, v1 in pairs( v ) do + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','l','o','c','a','l',' ','s','t','r',' ','=',' ','s','t','r','i','n','g','.','f','o','r','m','a','t','(',' ','"','b','p',' ','n','u','m',':','%','d',' ',' ','%','s',':','%','d',' ',' ','a','c','t','i','v','e',':','"',',',0xa, + // local str = string.format( "bp num:%d %s:%d active:", + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','v','1','.','n','u','m','b','e','r',',',0xa, + // v1.number, + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','v','1','.','s','o','u','r','c','e',',',0xa, + // v1.source, + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','v','1','.','l','i','n','e',' ',')',0xa, + // v1.line ) + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','i','f',' ','v','1','.','a','c','t','i','v','e',' ','t','h','e','n',0xa, + // if v1.active then + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','s','t','r',' ','=',' ','s','t','r',' ','.','.',' ','"','e','n','a','b','l','e','"',0xa, + // str = str .. "enable" + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','e','l','s','e',0xa, + // else + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','s','t','r',' ','=',' ','s','t','r',' ','.','.',' ','"','d','i','s','a','b','l','e','"',0xa, + // str = str .. "disable" + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','l','o','g','(',' ','s','t','r',' ',')',0xa, + // debug_log( str ) + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ',' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ','e','n','d',0xa, + // end + 'e','n','d',0xa, + // end + 0xa, + 'f','u','n','c','t','i','o','n',' ','d','e','b','u','g','_','d','e','l','_','b','p','(',' ','e','x','p','r',' ',')',0xa, + // function debug_del_bp( expr ) + ' ',' ',' ',' ','l','o','c','a','l',' ','n','u','m','b','e','r',' ','=',' ','t','o','n','u','m','b','e','r','(',' ','e','x','p','r',' ',')',0xa, + // local number = tonumber( expr ) + ' ',' ',' ',' ','f','o','r',' ','k',',',' ','v',' ','i','n',' ','p','a','i','r','s','(',' ','d','e','b','u','g','.','b','p','s',' ',')',' ','d','o',0xa, + // for k, v in pairs( debug.bps ) do + ' ',' ',' ',' ',' ',' ',' ',' ','i','f',' ','t','y','p','e','(',' ','v',' ',')',' ','=','=',' ','"','t','a','b','l','e','"',' ','t','h','e','n',0xa, + // if type( v ) == "table" then + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','f','o','r',' ','k','1',',',' ','v','1',' ','i','n',' ','p','a','i','r','s','(',' ','v',' ',')',' ','d','o',0xa, + // for k1, v1 in pairs( v ) do + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','i','f',' ','v','1','.','n','u','m','b','e','r',' ','=','=',' ','n','u','m','b','e','r',' ','t','h','e','n',0xa, + // if v1.number == number then + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','.','b','p','s','[','k',']','[','k','1',']',' ','=',' ','n','i','l',0xa, + // debug.bps[k][k1] = nil + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','l','o','g','(',' ','"','r','e','m','o','v','e',' ','b','p',':','"',' ','.','.',' ','n','u','m','b','e','r',' ','.','.',' ','"',' ','o','k','"',' ',')',0xa, + // debug_log( "remove bp:" .. number .. " ok" ) + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ',' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ','e','n','d',0xa, + // end + 'e','n','d',0xa, + // end + 0xa, + 'f','u','n','c','t','i','o','n',' ','d','e','b','u','g','_','e','n','a','b','l','e','_','b','p','(',' ','e','x','p','r',' ',')',0xa, + // function debug_enable_bp( expr ) + ' ',' ',' ',' ','l','o','c','a','l',' ','n','u','m','b','e','r',' ','=',' ','t','o','n','u','m','b','e','r','(',' ','e','x','p','r',' ',')',0xa, + // local number = tonumber( expr ) + ' ',' ',' ',' ','f','o','r',' ','k',',',' ','v',' ','i','n',' ','p','a','i','r','s','(',' ','d','e','b','u','g','.','b','p','s',' ',')',' ','d','o',0xa, + // for k, v in pairs( debug.bps ) do + ' ',' ',' ',' ',' ',' ',' ',' ','i','f',' ','t','y','p','e','(',' ','v',' ',')',' ','=','=',' ','"','t','a','b','l','e','"',' ','t','h','e','n',0xa, + // if type( v ) == "table" then + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','f','o','r',' ','k','1',',',' ','v','1',' ','i','n',' ','p','a','i','r','s','(',' ','v',' ',')',' ','d','o',0xa, + // for k1, v1 in pairs( v ) do + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','i','f',' ','v','1','.','n','u','m','b','e','r',' ','=','=',' ','n','u','m','b','e','r',' ','t','h','e','n',0xa, + // if v1.number == number then + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','v','1','.','a','c','t','i','v','e',' ','=',' ','t','r','u','e',0xa, + // v1.active = true + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','l','o','g','(',' ','"','e','n','a','b','l','e',' ','b','p',':','"',' ','.','.',' ','n','u','m','b','e','r',' ',')',0xa, + // debug_log( "enable bp:" .. number ) + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ',' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ','e','n','d',0xa, + // end + 'e','n','d',0xa, + // end + 0xa, + 'f','u','n','c','t','i','o','n',' ','d','e','b','u','g','_','d','i','s','a','b','l','e','_','b','p','(',' ','e','x','p','r',' ',')',0xa, + // function debug_disable_bp( expr ) + ' ',' ',' ',' ','l','o','c','a','l',' ','n','u','m','b','e','r',' ','=',' ','t','o','n','u','m','b','e','r','(',' ','e','x','p','r',' ',')',0xa, + // local number = tonumber( expr ) + ' ',' ',' ',' ','f','o','r',' ','k',',',' ','v',' ','i','n',' ','p','a','i','r','s','(',' ','d','e','b','u','g','.','b','p','s',' ',')',' ','d','o',0xa, + // for k, v in pairs( debug.bps ) do + ' ',' ',' ',' ',' ',' ',' ',' ','i','f',' ','t','y','p','e','(',' ','v',' ',')',' ','=','=',' ','"','t','a','b','l','e','"',' ','t','h','e','n',0xa, + // if type( v ) == "table" then + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','f','o','r',' ','k','1',',',' ','v','1',' ','i','n',' ','p','a','i','r','s','(',' ','v',' ',')',' ','d','o',0xa, + // for k1, v1 in pairs( v ) do + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','i','f',' ','v','1','.','n','u','m','b','e','r',' ','=','=',' ','n','u','m','b','e','r',' ','t','h','e','n',0xa, + // if v1.number == number then + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','v','1','.','a','c','t','i','v','e',' ','=',' ','f','a','l','s','e',0xa, + // v1.active = false + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','l','o','g','(',' ','"','d','i','s','a','b','l','e',' ','b','p',':','"',' ','.','.',' ','n','u','m','b','e','r',' ',')',0xa, + // debug_log( "disable bp:" .. number ) + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ',' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ','e','n','d',0xa, + // end + 'e','n','d',0xa, + // end + 0xa, + 'f','u','n','c','t','i','o','n',' ','d','e','b','u','g','_','h','e','l','p','(',')',0xa, + // function debug_help() + ' ',' ',' ',' ','p','r','i','n','t','(',' ','"','h',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','h','e','l','p',' ','i','n','f','o','"',' ',')',0xa, + // print( "h help info" ) + ' ',' ',' ',' ','p','r','i','n','t','(',' ','"','c',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','c','o','n','t','i','n','u','e','"',' ',')',0xa, + // print( "c continue" ) + ' ',' ',' ',' ','p','r','i','n','t','(',' ','"','s',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','t','r','a','c','e','"',' ',')',0xa, + // print( "s trace" ) + ' ',' ',' ',' ','p','r','i','n','t','(',' ','"','n',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','n','e','x','t','"',' ',')',0xa, + // print( "n next" ) + ' ',' ',' ',' ','p','r','i','n','t','(',' ','"','p',' ','v','a','r',' ',' ',' ',' ',' ',' ',' ',' ',' ','p','r','i','n','t',' ','v','a','r','i','a','b','l','e','"',' ',')',0xa, + // print( "p var print variable" ) + ' ',' ',' ',' ','p','r','i','n','t','(',' ','"','r','u','n',' ','e','x','p','r','e','s','s','i','o','n',' ',' ',' ',' ',' ',' ','r','u','n',' ','e','x','p','r','e','s','s','i','o','n',' ','c','o','d','e','"',' ',')',0xa, + // print( "run expression run expression code" ) + ' ',' ',' ',' ','p','r','i','n','t','(',' ','"','b',' ',' ','s','r','c',':','l','i','n','e',' ',' ',' ','a','d','d',' ','b','r','e','a','k','p','o','i','n','t','"',' ',')',0xa, + // print( "b src:line add breakpoint" ) + ' ',' ',' ',' ','p','r','i','n','t','(',' ','"','r','b',' ','s','r','c',':','l','i','n','e',' ',' ',' ','r','e','m','o','v','e',' ','b','r','e','a','k','p','o','i','n','t','"',' ',')',0xa, + // print( "rb src:line remove breakpoint" ) + ' ',' ',' ',' ','p','r','i','n','t','(',' ','"','b','l',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','l','i','s','t',' ','b','r','e','a','k','p','o','i','n','t','"',' ',')',0xa, + // print( "bl list breakpoint" ) + ' ',' ',' ',' ','p','r','i','n','t','(',' ','"','b','t',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','p','r','i','n','t',' ','t','r','a','c','e','b','a','c','k','"',' ',')',0xa, + // print( "bt print traceback" ) + 'e','n','d',0xa, + // end + 0xa, + 'f','u','n','c','t','i','o','n',' ','d','e','b','u','g','_','r','u','n','i','n','g','_','e','x','e','c','u','t','e','(',' ','c','m','d',' ',')',0xa, + // function debug_runing_execute( cmd ) + ' ',' ',' ',' ','i','f','(',' ','c','m','d','=','=','n','i','l',' ',')',' ','t','h','e','n',' ',0xa, + // if( cmd==nil ) then + ' ',' ',' ',' ',0x9,'r','e','t','u','r','n',';',0xa, + // return; + ' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ','l','o','c','a','l',' ','c',' ','=',' ','c','m','d',0xa, + // local c = cmd + ' ',' ',' ',' ','l','o','c','a','l',' ','e','x','p','r',' ','=',' ','"','"',0xa, + // local expr = "" + ' ',' ',' ',' ','l','o','c','a','l',' ','s','i',' ','=',' ','s','t','r','i','n','g','.','f','i','n','d','(',' ','c','m','d',',',' ','"',' ','"',' ',')',0xa, + // local si = string.find( cmd, " " ) + ' ',' ',' ',' ','i','f',' ','s','i',' ','~','=',' ','n','i','l',' ','t','h','e','n',0xa, + // if si ~= nil then + ' ',' ',' ',' ',' ',' ',' ',' ','c',' ','=',' ','s','t','r','i','n','g','.','s','u','b','(',' ','c','m','d',',',' ','1',',',' ','s','i',' ','-',' ','1',' ',')',0xa, + // c = string.sub( cmd, 1, si - 1 ) + ' ',' ',' ',' ',' ',' ',' ',' ','e','x','p','r',' ','=',' ','s','t','r','i','n','g','.','s','u','b','(',' ','c','m','d',',',' ','s','t','r','i','n','g','.','f','i','n','d','(',' ','c','m','d',',',' ','"',' ','%','w','"',' ',')',' ','+',' ','1',' ',')',0xa, + // expr = string.sub( cmd, string.find( cmd, " %w" ) + 1 ) + ' ',' ',' ',' ','e','n','d',0xa, + // end + 0xa, + ' ',' ',' ',' ','i','f',' ','c',' ','=','=',' ','"','b','"',' ','t','h','e','n',0xa, + // if c == "b" then + ' ',' ',' ',' ',' ',' ',' ',' ','a','d','d','_','b','r','e','a','k','p','o','i','n','t','(',' ','e','x','p','r',' ',')',0xa, + // add_breakpoint( expr ) + ' ',' ',' ',' ','e','l','s','e','i','f',' ','c',' ','=','=',' ','"','r','b','"',' ','t','h','e','n',0xa, + // elseif c == "rb" then + ' ',' ',' ',' ',' ',' ',' ',' ','r','e','m','o','v','e','_','b','r','e','a','k','p','o','i','n','t','(',' ','e','x','p','r',' ',')',0xa, + // remove_breakpoint( expr ) + ' ',' ',' ',' ','e','l','s','e','i','f',' ','c',' ','=','=',' ','"','p','"',' ','t','h','e','n',0xa, + // elseif c == "p" then + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','p','r','i','n','t','_','e','x','p','r','(',' ','e','x','p','r',' ',')',0xa, + // debug_print_expr( expr ) + ' ',' ',' ',' ','e','n','d',0xa, + // end + 'e','n','d',0xa, + // end + 0xa, + 'f','u','n','c','t','i','o','n',' ','d','e','b','u','g','_','e','x','e','c','u','t','e','_','c','m','d','(',' ','e','n','v',' ',')',0xa, + // function debug_execute_cmd( env ) + ' ',' ',' ',' ','-','-','p','r','i','n','t','(',' ','"','(','l','d','b',')',' ','"',' ',')',0xa, + // --print( "(ldb) " ) + ' ',' ',' ',' ','l','o','c','a','l',' ','c','m','d',' ','=',' ','d','e','b','u','g','.','r','e','a','d','C','m','d','(',')',0xa, + // local cmd = debug.readCmd() + ' ',' ',' ',' ','i','f',' ','(',' ','c','m','d',' ','=','=','n','i','l',' ',')',' ','t','h','e','n',0xa, + // if ( cmd ==nil ) then + ' ',' ',' ',' ',0x9,'d','e','b','u','g','.','s','l','e','e','p','(','0','.','0','1',')',';',0xa, + // debug.sleep(0.01); + ' ',' ',' ',' ',0x9,'r','e','t','u','r','n',' ','f','a','l','s','e',';',0xa, + // return false; + ' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ','-','-',0xe5,0x8f,0x96,0xe4,0xb8,0x8a,0xe4,0xb8,0x80,0xe6,0xac,0xa1,0xe7,0x9a,0x84,0xe5,0x91,0xbd,0xe4,0xbb,0xa4,',',0xe6,0x96,0xb9,0xe4,0xbe,0xbf,0xe8,0xb0,0x83,0xe8,0xaf,0x95,0xa, + // --取上一次的命令,方便调试 + ' ',' ',' ',' ','-','-',' ','i','f',' ','c','m','d',' ','~','=',' ','"','"',' ','t','h','e','n',0xa, + // -- if cmd ~= "" then + ' ',' ',' ',' ','-','-',' ',' ',' ',' ',' ','d','e','b','u','g','.','b','p','s','.','l','a','s','t','_','c','m','d',' ','=',' ','c','m','d',0xa, + // -- debug.bps.last_cmd = cmd + ' ',' ',' ',' ','-','-',' ','e','l','s','e',0xa, + // -- else + ' ',' ',' ',' ','-','-',' ',' ',' ',' ',' ','c','m','d',' ','=',' ','d','e','b','u','g','.','b','p','s','.','l','a','s','t','_','c','m','d',0xa, + // -- cmd = debug.bps.last_cmd + ' ',' ',' ',' ','-','-',' ','e','n','d',0xa, + // -- end + 0xa, + ' ',' ',' ',' ','l','o','c','a','l',' ','c',' ','=',' ','c','m','d',0xa, + // local c = cmd + ' ',' ',' ',' ','l','o','c','a','l',' ','e','x','p','r',' ','=',' ','"','"',0xa, + // local expr = "" + ' ',' ',' ',' ','l','o','c','a','l',' ','s','i',' ','=',' ','s','t','r','i','n','g','.','f','i','n','d','(',' ','c','m','d',',',' ','"',' ','"',' ',')',0xa, + // local si = string.find( cmd, " " ) + ' ',' ',' ',' ','i','f',' ','s','i',' ','~','=',' ','n','i','l',' ','t','h','e','n',0xa, + // if si ~= nil then + ' ',' ',' ',' ',' ',' ',' ',' ','c',' ','=',' ','s','t','r','i','n','g','.','s','u','b','(',' ','c','m','d',',',' ','1',',',' ','s','i',' ','-',' ','1',' ',')',0xa, + // c = string.sub( cmd, 1, si - 1 ) + ' ',' ',' ',' ',' ',' ',' ',' ','-','-',' ','l','o','c','a','l',' ','i','n','d','e','x',' ','=',' ','s','t','r','i','n','g','.','f','i','n','d','(',' ','c','m','d',',',' ','"',' ','%','w','"',' ',')',';',0xa, + // -- local index = string.find( cmd, " %w" ); + ' ',' ',' ',' ',' ',' ',' ',' ','-','-',' ','i','f',' ','(',' ','i','n','d','e','x',' ',')',' ','t','h','e','n',0xa, + // -- if ( index ) then + ' ',' ',' ',' ',' ',' ',' ',' ','-','-',' ',' ',' ',' ',' ','e','x','p','r',' ','=',' ','s','t','r','i','n','g','.','s','u','b','(',' ','c','m','d',',',' ','i','n','d','e','x',' ','+',' ','1',' ',')',';',0xa, + // -- expr = string.sub( cmd, index + 1 ); + ' ',' ',' ',' ',' ',' ',' ',' ','-','-',' ','e','n','d',0xa, + // -- end + ' ',' ',' ',' ',' ',' ',' ',' ','e','x','p','r',' ','=',' ','s','t','r','i','n','g','.','s','u','b','(','c','m','d',',',' ','s','i',' ','+',' ','1',' ',')',';',0xa, + // expr = string.sub(cmd, si + 1 ); + ' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ','i','f',' ','c','=','=','"','c','l','o','s','e','"',' ','t','h','e','n',0xa, + // if c=="close" then + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','c','l','o','s','e','(',')',';',0xa, + // debug_close(); + ' ',' ',' ',' ',' ',' ',' ',' ','r','e','t','u','r','n',' ','t','r','u','e',';',0xa, + // return true; + ' ',' ',' ',' ','e','l','s','e','i','f',' ','c','=','=','"','n','o','n','e','"',' ','t','h','e','n',0xa, + // elseif c=="none" then + ' ',' ',' ',' ',' ',' ',' ',' ','r','e','t','u','r','n',' ','f','a','l','s','e',';',0xa, + // return false; + ' ',' ',' ',' ','e','l','s','e','i','f',' ','c',' ','=','=',' ','"','c','"',' ','t','h','e','n',0xa, + // elseif c == "c" then + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','.','b','p','s','.','t','r','a','c','e',' ','=',' ','f','a','l','s','e',0xa, + // debug.bps.trace = false + ' ',' ',' ',' ',' ',' ',' ',' ','r','e','t','u','r','n',' ','t','r','u','e',0xa, + // return true + ' ',' ',' ',' ','e','l','s','e','i','f',' ','c',' ','=','=',' ','"','s','"',' ','t','h','e','n',0xa, + // elseif c == "s" then + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','.','b','p','s','.','t','r','a','c','e',' ','=',' ','t','r','u','e',0xa, + // debug.bps.trace = true + ' ',' ',' ',' ',' ',' ',' ',' ','r','e','t','u','r','n',' ','t','r','u','e',0xa, + // return true + ' ',' ',' ',' ','e','l','s','e','i','f',' ','c',' ','=','=',' ','"','n','"',' ','t','h','e','n',0xa, + // elseif c == "n" then + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','.','b','p','s','.','t','r','a','c','e',' ','=',' ','f','a','l','s','e',0xa, + // debug.bps.trace = false + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','.','b','p','s','.','n','e','x','t',' ','=',' ','t','r','u','e',0xa, + // debug.bps.next = true + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','.','b','p','s','.','c','u','r','_','f','u','n','c',' ','=',' ','e','n','v','.','f','u','n','c',0xa, + // debug.bps.cur_func = env.func + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','.','b','p','s','.','t','r','a','c','e','_','c','o','u','n','t',' ','=',' ','d','e','b','u','g','.','t','r','a','c','e','b','a','c','k','_','c','o','u','n','t','(',')',' ','-',' ','1',0xa, + // debug.bps.trace_count = debug.traceback_count() - 1 + ' ',' ',' ',' ',' ',' ',' ',' ','r','e','t','u','r','n',' ','t','r','u','e',0xa, + // return true + ' ',' ',' ',' ','e','l','s','e','i','f',' ','c',' ','=','=',' ','"','p','"',' ','t','h','e','n',0xa, + // elseif c == "p" then + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','p','r','i','n','t','_','e','x','p','r','(',' ','e','x','p','r',' ',')',0xa, + // debug_print_expr( expr ) + ' ',' ',' ',' ','e','l','s','e','i','f',' ','c',' ','=','=',' ','"','r','u','n','"',' ','t','h','e','n',0xa, + // elseif c == "run" then + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','r','u','n','_','e','x','p','r','(',' ','e','x','p','r',' ',')',0xa, + // debug_run_expr( expr ) + ' ',' ',' ',' ','e','l','s','e','i','f',' ','c',' ','=','=',' ','"','b','"',' ','t','h','e','n',0xa, + // elseif c == "b" then + ' ',' ',' ',' ',' ',' ',' ',' ','a','d','d','_','b','r','e','a','k','p','o','i','n','t','(',' ','e','x','p','r',' ',')',0xa, + // add_breakpoint( expr ) + ' ',' ',' ',' ','e','l','s','e','i','f',' ','c',' ','=','=',' ','"','r','b','"',' ','t','h','e','n',0xa, + // elseif c == "rb" then + ' ',' ',' ',' ',' ',' ',' ',' ','r','e','m','o','v','e','_','b','r','e','a','k','p','o','i','n','t','(',' ','e','x','p','r',' ',')',0xa, + // remove_breakpoint( expr ) + ' ',' ',' ',' ','e','l','s','e','i','f',' ','c',' ','=','=',' ','"','b','l','"',' ','t','h','e','n',0xa, + // elseif c == "bl" then + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','s','h','o','w','_','b','p','(',')',0xa, + // debug_show_bp() + ' ',' ',' ',' ','e','l','s','e','i','f',' ','c',' ','=','=',' ','"','d','"',' ','t','h','e','n',0xa, + // elseif c == "d" then + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','d','e','l','_','b','p','(',' ','e','x','p','r',' ',')',0xa, + // debug_del_bp( expr ) + ' ',' ',' ',' ','e','l','s','e','i','f',' ','c',' ','=','=',' ','"','b','e','"',' ','t','h','e','n',0xa, + // elseif c == "be" then + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','e','n','a','b','l','e','_','b','p','(',' ','e','x','p','r',' ',')',0xa, + // debug_enable_bp( expr ) + ' ',' ',' ',' ','e','l','s','e','i','f',' ','c',' ','=','=',' ','"','b','d','"',' ','t','h','e','n',0xa, + // elseif c == "bd" then + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','d','i','s','a','b','l','e','_','b','p','(',' ','e','x','p','r',' ',')',0xa, + // debug_disable_bp( expr ) + ' ',' ',' ',' ','e','l','s','e','i','f',' ','c',' ','=','=',' ','"','b','t','"',' ','t','h','e','n',0xa, + // elseif c == "bt" then + ' ',' ',' ',' ',' ',' ',' ',' ','l','o','c','a','l',' ','t','r','a','c','e',' ','=',' ','d','e','b','u','g','.','t','r','a','c','e','b','a','c','k','(','"','"',',',' ','3',')',';',0xa, + // local trace = debug.traceback("", 3); + ' ',' ',' ',' ',' ',' ',' ',' ','p','r','i','n','t','(',' ','t','r','a','c','e',' ',')',';',0xa, + // print( trace ); + ' ',' ',' ',' ','e','l','s','e','i','f',' ','c',' ','=','=',' ','"','s','t','a','c','k','"',' ','t','h','e','n',0xa, + // elseif c == "stack" then + ' ',' ',' ',' ',' ',' ',' ',' ','l','o','c','a','l',' ','t','r','a','c','e',' ','=',' ','d','e','b','u','g','.','t','r','a','c','e','b','a','c','k','(','"','"',',',' ','3',')',';',0xa, + // local trace = debug.traceback("", 3); + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','.','w','r','i','t','e','C','m','d','(','"','s','t','a','c','k','"',',',' ','t','r','a','c','e',',',' ','n','i','l',')',';',0xa, + // debug.writeCmd("stack", trace, nil); + ' ',' ',' ',' ','e','l','s','e','i','f',' ','c',' ','=','=',' ','"','h','"',' ','t','h','e','n',0xa, + // elseif c == "h" then + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','h','e','l','p','(',')',0xa, + // debug_help() + ' ',' ',' ',' ','e','l','s','e',0xa, + // else + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','l','o','g','(',' ','"','i','n','v','a','l','i','d',' ','c','m','d',':','"',' ','.','.',' ','c','m','d',' ',')',0xa, + // debug_log( "invalid cmd:" .. cmd ) + ' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ','r','e','t','u','r','n',' ','f','a','l','s','e',0xa, + // return false + 'e','n','d',0xa, + // end + 0xa, + 'f','u','n','c','t','i','o','n',' ','d','e','b','u','g','_','t','r','a','c','e','(',' ','e','v','e','n','t',',',' ','l','i','n','e',' ',')',0xa, + // function debug_trace( event, line ) + ' ',' ',' ',' ','l','o','c','a','l',' ','e','n','v',' ','=',' ','d','e','b','u','g','.','g','e','t','i','n','f','o','(',' ','2',' ',')',0xa, + // local env = debug.getinfo( 2 ) + 0xa, + ' ',' ',' ',' ','i','f',' ','e','n','v','.','s','o','u','r','c','e',' ','=','=',' ','_','D','E','B','U','G','_','F','I','L','E',' ','t','h','e','n',0xa, + // if env.source == _DEBUG_FILE then + ' ',' ',' ',' ',' ',' ',' ',' ','r','e','t','u','r','n',0xa, + // return + ' ',' ',' ',' ','e','n','d',0xa, + // end + 0xa, + ' ',' ',' ',' ','-','-',0xe5,0x88,0xa4,0xe6,0x96,0xad,0xe6,0x98,0xaf,0xe5,0x90,0xa6,0xe5,0x9c,0xa8,'n','e','x','t',0xe8,0xb0,0x83,0xe8,0xaf,0x95,0xa, + // --判断是否在next调试 + ' ',' ',' ',' ','i','f',' ','d','e','b','u','g','.','b','p','s','.','n','e','x','t',' ',' ','t','h','e','n',0xa, + // if debug.bps.next then + ' ',' ',' ',' ',' ',' ',' ',' ','l','o','c','a','l',' ','t','r','a','c','e','_','c','o','u','n','t',' ','=',' ','d','e','b','u','g','.','t','r','a','c','e','b','a','c','k','_','c','o','u','n','t','(',')',0xa, + // local trace_count = debug.traceback_count() + ' ',' ',' ',' ',' ',' ',' ',' ','-','-',0xe5,0x87,0xbd,0xe6,0x95,0xb0,0xe8,0xbf,0x94,0xe5,0x9b,0x9e,0xe4,0xba,0x86,',',0xe8,0xb0,0x83,0xe7,0x94,0xa8,0xe6,0xa0,0x88,0xe6,0x95,0xb0,0xe9,0x87,0x8f,0xe5,0xb0,0xb1,0xe4,0xbc,0x9a,0xe6,0xaf,0x94,0xe7,0x8e,0xb0,0xe5,0x9c,0xa8,0xe5,0xb0,0x8f,0xa, + // --函数返回了,调用栈数量就会比现在小 + ' ',' ',' ',' ',' ',' ',' ',' ','i','f',' ','t','r','a','c','e','_','c','o','u','n','t',' ','<',' ','d','e','b','u','g','.','b','p','s','.','t','r','a','c','e','_','c','o','u','n','t',' ','t','h','e','n',0xa, + // if trace_count < debug.bps.trace_count then + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','.','b','p','s','.','n','e','x','t',' ','=',' ','f','a','l','s','e',0xa, + // debug.bps.next = false + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','.','b','p','s','.','t','r','a','c','e',' ','=',' ','t','r','u','e',0xa, + // debug.bps.trace = true + ' ',' ',' ',' ',' ',' ',' ',' ','e','l','s','e','i','f',' ','t','r','a','c','e','_','c','o','u','n','t',' ','=','=',' ','d','e','b','u','g','.','b','p','s','.','t','r','a','c','e','_','c','o','u','n','t',' ','t','h','e','n',0xa, + // elseif trace_count == debug.bps.trace_count then + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','i','f',' ','d','e','b','u','g','.','b','p','s','.','c','u','r','_','f','u','n','c',' ','=','=',' ','e','n','v','.','f','u','n','c',' ','t','h','e','n',0xa, + // if debug.bps.cur_func == env.func then + 0x9,' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','.','b','p','s','.','n','e','x','t',' ','=',' ','f','a','l','s','e',0xa, + // debug.bps.next = false + 0x9,' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','.','b','p','s','.','t','r','a','c','e',' ','=',' ','t','r','u','e',0xa, + // debug.bps.trace = true + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ',' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ',' ','e','n','d',0xa, + // end + 0xa, + ' ',' ',' ',' ','-','-',0xe5,0x88,0xa4,0xe6,0x96,0xad,0xe6,0x98,0xaf,0xe5,0x90,0xa6,0xe6,0x9c,0x89,0xe6,0x96,0xad,0xe7,0x82,0xb9,0xa, + // --判断是否有断点 + ' ',' ',' ',' ','i','f','(',' ','(',' ','n','o','t',' ','d','e','b','u','g','.','b','p','s','.','t','r','a','c','e',' ',')',' ','a','n','d',' ','(',' ','d','e','b','u','g','.','b','p','s','[','l','i','n','e',']',' ','~','=',' ','n','i','l',' ',')',' ',')',' ','t','h','e','n',0xa, + // if( ( not debug.bps.trace ) and ( debug.bps[line] ~= nil ) ) then + ' ',' ',' ',' ',' ',' ',' ',' ','l','o','c','a','l',' ','t','b','l',' ','=',' ','d','e','b','u','g','.','b','p','s','[','l','i','n','e',']','[','e','n','v','.','s','o','u','r','c','e',']',0xa, + // local tbl = debug.bps[line][env.source] + ' ',' ',' ',' ',' ',' ',' ',' ','i','f','(',' ',' ','(',' ','t','b','l',' ','~','=',' ','n','i','l',' ',')',' ','a','n','d',' ','t','b','l','.','a','c','t','i','v','e',' ',' ',')','t','h','e','n',0xa, + // if( ( tbl ~= nil ) and tbl.active )then + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','-','-',0xe5,0xa6,0x82,0xe6,0x9e,0x9c,0xe5,0x9c,0xa8,'n','e','x','t',0xe6,0x97,0xb6,',',0xe7,0xa2,0xb0,0xe5,0x88,0xb0,0xe6,0x96,0xad,0xe7,0x82,0xb9,0xe4,0xba,0x86,',',0xe5,0xb0,0xb1,0xe6,0xb8,0x85,0xe9,0x99,0xa4,0xe5,0x8d,0x95,0xe6,0xad,0xa5,0xe8,0xbf,0x90,0xe8,0xa1,0x8c,0xe7,0x8a,0xb6,0xe6,0x80,0x81,0xa, + // --如果在next时,碰到断点了,就清除单步运行状态 + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','.','b','p','s','.','n','e','x','t',' ','=',' ','f','a','l','s','e',0xa, + // debug.bps.next = false + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','.','b','p','s','.','t','r','a','c','e',' ','=',' ','t','r','u','e',0xa, + // debug.bps.trace = true + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','-','-',' ','d','e','b','u','g','_','l','o','g','(',' ','"',0xe7,0xa2,0xb0,0xe5,0x88,0xb0,0xe6,0x96,0xad,0xe7,0x82,0xb9,' ','"',' ','.','.',' ','e','n','v','.','s','o','u','r','c','e',' ','.','.',' ','"',' ','-',' ','"',' ','.','.',' ','l','i','n','e',' ',')',0xa, + // -- debug_log( "碰到断点 " .. env.source .. " - " .. line ) + ' ',' ',' ',' ',' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ','e','n','d',0xa, + // end + 0xa, + ' ',' ',' ',' ','i','f',' ','d','e','b','u','g','.','b','p','s','.','t','r','a','c','e',' ','t','h','e','n',0xa, + // if debug.bps.trace then + ' ',' ',' ',' ',' ',' ',' ',' ','l','o','c','a','l',' ','s','r','c',' ','=',' ','d','e','b','u','g','.','g','e','t','_','f','i','l','e','_','l','i','n','e','(',' ','e','n','v','.','s','o','u','r','c','e',',',' ','l','i','n','e',' ',')',0xa, + // local src = debug.get_file_line( env.source, line ) + ' ',' ',' ',' ',' ',' ',' ',' ','l','o','c','a','l',' ','f','u','n','n','a','m','e',' ','=',' ','e','n','v','.','n','a','m','e',' ','o','r',' ','"','u','n','k','n','o','w','"',0xa, + // local funname = env.name or "unknow" + ' ',' ',' ',' ',' ',' ',' ',' ','-','-','d','e','b','u','g','_','l','o','g','(',' ','s','t','r','i','n','g','.','f','o','r','m','a','t','(',' ','"','%','s',':','%','d','(','%','s',')',' ',' ','%','s','"',',',' ','e','n','v','.','s','o','u','r','c','e',',',' ','l','i','n','e',',',' ','f','u','n','n','a','m','e',',',' ','s','r','c',' ',')',' ',')',0xa, + // --debug_log( string.format( "%s:%d(%s) %s", env.source, line, funname, src ) ) + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','.','r','u','n','n','i','n','g','L','i','n','e','(',' ','e','n','v','.','s','o','u','r','c','e',',',' ','l','i','n','e',' ',')',';',0xa, + // debug.runningLine( env.source, line ); + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','.','b','p','s','.','c','u','r','_','f','i','l','e',' ','=',' ','e','n','v','.','s','o','u','r','c','e',';',0xa, + // debug.bps.cur_file = env.source; + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','.','b','p','s','.','c','u','r','_','l','i','n','e',' ','=',' ','l','i','n','e',0xa, + // debug.bps.cur_line = line + ' ',' ',' ',' ',' ',' ',' ',' ','w','h','i','l','e',' ','n','o','t',' ','d','e','b','u','g','_','e','x','e','c','u','t','e','_','c','m','d','(',' ','e','n','v',' ',')',' ','d','o',0xa, + // while not debug_execute_cmd( env ) do + ' ',' ',' ',' ',' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ',' ',' ',' ',' ','r','e','t','u','r','n',';',0xa, + // return; + ' ',' ',' ',' ','e','n','d',0xa, + // end + 'e','n','d',0xa, + // end + 0xa, + 'f','u','n','c','t','i','o','n',' ','b','e','g','i','n','_','d','e','b','u','g','(',')',0xa, + // function begin_debug() + ' ',' ',' ',' ','d','e','b','u','g','.','b','p','s','.','t','r','a','c','e',' ','=',' ','t','r','u','e',0xa, + // debug.bps.trace = true + ' ',' ',' ',' ','d','e','b','u','g','.','s','e','t','h','o','o','k','(',' ','d','e','b','u','g','_','t','r','a','c','e',',',' ','"','l','"',' ',')',0xa, + // debug.sethook( debug_trace, "l" ) + 'e','n','d',0xa, + // end + 0xa, + '-','-',0xe5,0x85,0xb3,0xe9,0x97,0xad,'d','e','b','u','g','g','e','r',0xa, + // --关闭debugger + 'f','u','n','c','t','i','o','n',' ','d','e','b','u','g','_','c','l','o','s','e','(',')',0xa, + // function debug_close() + ' ',' ',' ',' ','d','e','b','u','g','.','b','p','s','.','t','r','a','c','e',' ','=',' ','f','a','l','s','e',0xa, + // debug.bps.trace = false + ' ',' ',' ',' ','d','e','b','u','g','.','b','p','s','.','n','e','x','t',' ','=',' ','f','a','l','s','e',0xa, + // debug.bps.next = false + ' ',' ',' ',' ','d','e','b','u','g','.','s','e','t','h','o','o','k','(',')',0xa, + // debug.sethook() + 'e','n','d',0xa, + // end + 0xa, + 'd','e','b','u','g','_','l','o','g','(','"','l','o','a','d',' ','d','e','b','u','g',' ','m','o','d','e','l','"',')',';',0xa, + // debug_log("load debug model"); + 'd','e','b','u','g','.','p','r','i','n','t','T','o','S','e','r','v','e','r','(','t','r','u','e',')',';',0xa, + // debug.printToServer(true); + 0xa, + 0xa, + 'b','e','g','i','n','_','d','e','b','u','g','(',')',';',' ','-','-',' ','l','a','s','t',' ','l','i','n','e',0xa, + // begin_debug(); -- last line + 0xa, + 0 +}; + diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvdebug/LVDebuger.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvdebug/LVDebuger.h new file mode 100644 index 00000000..782a9375 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvdebug/LVDebuger.h @@ -0,0 +1,19 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + +extern void lv_printToServer(lua_State* L, const char* cs, int withTabChar); + +@interface LVDebuger : NSObject + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvdebug/LVDebuger.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvdebug/LVDebuger.m new file mode 100644 index 00000000..011f339f --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvdebug/LVDebuger.m @@ -0,0 +1,128 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVDebuger.h" +#import "LVHeads.h" +#import "LVDebugConnection.h" +#import "LView.h" +#import "LVHeads.h" + +@implementation LVDebuger + + +static int DebugReadCmd (lua_State *L) { + LuaViewCore* luaView = LV_LUASTATE_VIEW(L); + + NSString* cmd = [luaView.debugConnection getCmd]; + if( cmd ){ + lua_pushstring(L, cmd.UTF8String); + } else { + lua_pushnil(L); + } + return 1; +} + +static int DebugWriteCmd (lua_State *L) { + LuaViewCore* luaView = LV_LUASTATE_VIEW(L); + NSString* cmd = lv_paramString(L, 1); + NSString* info = lv_paramString(L, 2); + NSDictionary* args = lv_luaTableToDictionary(L, 3); + + [luaView.debugConnection sendCmd:cmd info:info args:args]; + return 0; +} + +static int DebugSleep (lua_State *L) { + float time = lua_tonumber(L, 1); + if( time>0 ) { + [NSThread sleepForTimeInterval:time]; + } + return 0; +} + +static int DebugPrintToServer (lua_State *L) { + LuaViewCore* luaView = LV_LUASTATE_VIEW(L); + BOOL open = lua_toboolean(L, 1); + luaView.debugConnection.printToServer = !!open; + return 0; +} + +static int runningLine (lua_State *L) { + NSString* fileName = lv_paramString(L, 1); + if( fileName == nil ){ + fileName = @"unkown"; + } + int lineNumber = lua_tonumber(L, 2); + + NSString* lineInfo = [NSString stringWithFormat:@"%d",lineNumber]; + LuaViewCore* luaView = LV_LUASTATE_VIEW(L); + [luaView.debugConnection sendCmd:@"running" fileName:fileName info:lineInfo args:@{@"Line-Number":lineInfo}]; + return 0; +} + +static int get_file_line( lua_State *L ) +{ + lua_pushstring(L, "one line code"); + return 1; +} + +static int db_traceback_count (lua_State *L) { + lua_Debug ar; + int index = 1; + while (lua_getstack(L, index, &ar)) + index++; + lua_pushnumber( L, index - 1 ); + return 1; +} + +static const luaL_Reg dblib[] = { + {"readCmd", DebugReadCmd}, + {"writeCmd", DebugWriteCmd}, + {"sleep", DebugSleep}, + {"printToServer", DebugPrintToServer}, + {"runningLine", runningLine}, + {"get_file_line", get_file_line}, + {"traceback_count", db_traceback_count}, + {NULL, NULL} +}; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + luaL_register(L, LUA_DBLIBNAME, dblib); + return 0; +} + +// 把日志传送到服务器 +void lv_printToServer(lua_State* L, const char* cs, int withTabChar){ + LuaViewCore* lview = LV_LUASTATE_VIEW(L); + if( lview.debugConnection.printToServer ){ + NSMutableData* data = [[NSMutableData alloc] init]; + if( withTabChar ){ + [data appendBytes:" " length:4]; + } + [data appendBytes:cs length:strlen(cs)]; + + [lview.debugConnection sendCmd:@"log" info:[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]]; + } +} + +// 可变参数实例 +//void lv_print(NSString*format, ...) { +// va_list argumentList; +// va_start(argumentList, format); +// NSMutableString * message = [[NSMutableString alloc] initWithFormat:format +// arguments:argumentList]; +// [message appendString:@"\n"]; +// lv_printToServer(message.UTF8String,0); +// va_end(argumentList); +//} + + + +@end + + diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAlert.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAlert.h new file mode 100644 index 00000000..999e8b15 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAlert.h @@ -0,0 +1,22 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + +@interface LVAlert : UIAlertView + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; + +-(id) init:(lua_State*) l argNum:(int)num; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAlert.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAlert.m new file mode 100644 index 00000000..33b3fc86 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAlert.m @@ -0,0 +1,134 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVAlert.h" +#import "LVBaseView.h" +#import "LView.h" +#import "LVToast.h" +#import "LVHeads.h" + +@interface LVAlert () +@property(nonatomic,strong) NSArray* cmdArray; +@property(nonatomic,assign) int argNum; +@property(nonatomic,assign) int functionNum; +@end + +@implementation LVAlert{ +} + +-(void) dealloc{ + lua_State* L = self.lv_luaviewCore.l; + for ( int i=0; i=1 && index<=max ){ + return lv_paramString(L, index); + } + return nil; +} + +static int lvNewAlertView (lua_State *L) { + int num = lua_gettop(L); + LVAlert* alertView = [[LVAlert alloc] init:L argNum:num]; + if( num>0 ){ + int argID= 0; + for ( int i=1; i<=num; i++ ) { + if( lua_type(L, i) == LUA_TFUNCTION ) { + NSString* tag = alertView.cmdArray[argID++]; + [LVUtil registryValue:L key:tag stack:i]; + alertView.argNum = argID; + } + } + [alertView show]; + } + return 0; +} + + +static int toast (lua_State *L) { + int num = lua_gettop(L); + if( num>0 ){ + NSString* s = lv_paramString(L, 1); + if( s ==nil ) { + s = @" "; + } + // CGSize size = [UIScreen mainScreen].bounds.size; + [LVToast showWithText:s duration:2]; + } + return 0; +} + + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + + // 自动消失的提示框 + lv_defineGlobalFunc("Toast", toast, L); + + // 系统Alert提示框 + [LVUtil reg:L clas:self cfunc:lvNewAlertView globalName:globalName defaultName:@"Alert"]; + const struct luaL_Reg memberFunctions [] = { + {NULL, NULL} + }; + + lv_createClassMetaTable(L, META_TABLE_UIAlertView); + + //luaL_openlib(L, NULL, [LVBaseView lvMemberFunctions], 0); + luaL_openlib(L, NULL, memberFunctions, 0); + return 1; +} + + + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAnimate.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAnimate.h new file mode 100644 index 00000000..52845eae --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAnimate.h @@ -0,0 +1,21 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + +@interface LVAnimate : UIView + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; + +-(id) init:(lua_State*) l; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAnimate.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAnimate.m new file mode 100644 index 00000000..1c306132 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAnimate.m @@ -0,0 +1,137 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + + +#import "LVAnimate.h" +#import "LVUtil.h" +#import "LView.h" +#import "LVHeads.h" + + +@interface LVAnimate () +@property(nonatomic,strong) id mySelf; +@property(nonatomic,assign) float time; +@end + + +@implementation LVAnimate + +-(id) init:(lua_State*) L{ + self = [super init]; + if( self ){ + self.mySelf = self; + self.lv_luaviewCore = LV_LUASTATE_VIEW(L); + } + return self; +} + +-(void) dealloc{ + self.lv_luaviewCore = nil; + self.lv_userData = nil; +} + + +static int lvNewAnimate (lua_State *L) { + int argNum = lua_gettop(L); + if( argNum>=1 ){ + LVAnimate* animate = [[LVAnimate alloc] init:L]; + + int stackID = 1; + + float delay = 0; + float duration = 0.3; + UIViewAnimationOptions option = 0; + CGFloat dampingRatio = 0;//0~1 + CGFloat velocity = 0;//0~1 + + if( lua_type(L, stackID)==LUA_TNUMBER ){ + duration = lua_tonumber(L,stackID++); + } + if( lua_type(L, stackID)==LUA_TNUMBER ){ + delay = lua_tonumber(L,stackID++); + } + + if( lua_type(L, stackID)==LUA_TNUMBER ){ + dampingRatio = lua_tonumber(L,stackID++); + } + + if( lua_type(L, stackID)==LUA_TNUMBER ){ + velocity = lua_tonumber(L,stackID++); + } + + if( lua_type(L, stackID)==LUA_TNUMBER ){ + option = lua_tonumber(L,stackID++); + } + + lua_createtable(L, 0, 8);// table + if( argNum>=stackID && lua_type(L,stackID)==LUA_TFUNCTION ){ + lua_pushstring(L, "animations");// key + lua_pushvalue(L, stackID);//value + lua_settable(L, -3); + stackID++; + } + if( argNum>=stackID && lua_type(L,stackID)==LUA_TFUNCTION ){ + lua_pushstring(L, "completion");// key + lua_pushvalue(L, stackID );//value + lua_settable(L, -3); + } + + [LVUtil registryValue:L key:animate stack:-1]; + + + if( dampingRatio>0 ) { + [UIView animateWithDuration:duration + delay:delay + usingSpringWithDamping:dampingRatio + initialSpringVelocity:velocity + options:option animations:^{ + if( animate.lv_luaviewCore && animate.lv_luaviewCore.l ) { + lua_checkstack32( animate.lv_luaviewCore.l); + [LVUtil call:animate.lv_luaviewCore.l lightUserData:animate key1:"animations" key2:NULL nargs:0]; + } + } completion:^(BOOL finished) { + lua_State* l = animate.lv_luaviewCore.l; + if( l ) { + lua_settop(l, 0); + lua_checkstack32(l); + [LVUtil call:l lightUserData:animate key1:"completion" key2:NULL nargs:0]; + + [LVUtil unregistry:l key:animate]; + } + animate.mySelf = nil; + }]; + } else { + [UIView animateWithDuration:duration + delay:delay + options:option animations:^{ + if( animate.lv_luaviewCore && animate.lv_luaviewCore.l ) { + lua_checkstack32( animate.lv_luaviewCore.l); + [LVUtil call:animate.lv_luaviewCore.l lightUserData:animate key1:"animations" key2:NULL nargs:0]; + } + } completion:^(BOOL finished) { + lua_State* l = animate.lv_luaviewCore.l; + if( l ) { + lua_settop(l, 0); + lua_checkstack32(l); + [LVUtil call:l lightUserData:animate key1:"completion" key2:NULL nargs:0]; + + [LVUtil unregistry:l key:animate]; + } + animate.mySelf = nil; + }]; + } + } + return 0; /* new userdatum is already on the stack */ +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewAnimate globalName:globalName defaultName:@"Animate"]; + return 1; +} + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAnimator.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAnimator.h new file mode 100644 index 00000000..726c1fc1 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAnimator.h @@ -0,0 +1,51 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import +#import "LVHeads.h" +#import "ltable.h" + +typedef NS_ENUM(int, LVAniamtorInterpolator) { + LVLinearInterpolator = 0, + LVAccelerateInterpolator, + LVDecelerateInterpolator, + LVAccelerateDecelerateInterpolator, + LVAnticipateInterpolator, + LVAnticipateOvershootInterpolator, + LVOvershootInterpolator, +}; + +@interface LVAnimator : NSObject + +@property(nonatomic, copy) NSString *keyPath; +@property(nonatomic, copy) NSValue *toValue; + +@property(nonatomic, assign) float duration; +@property(nonatomic, assign) float delay; +@property(nonatomic, assign) int repeatCount; +@property(nonatomic, assign) BOOL autoreverses; +@property(nonatomic, assign) LVAniamtorInterpolator interpolator; // default is linear + +@property(nonatomic, weak) UIView *target; + +@property(nonatomic, weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic, assign) LVUserDataInfo* lv_userData; + +@property(nonatomic, readonly, getter=isRunning) BOOL running; +@property(nonatomic, readonly, getter=isPaused) BOOL paused; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +- (void)start; +- (void)cancel; + +- (void)pause; +- (void)resume; + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAnimator.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAnimator.m new file mode 100644 index 00000000..5840fe15 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAnimator.m @@ -0,0 +1,766 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVAnimator.h" +#import "LVHeads.h" +#import "LVUtil.h" +#import "LuaViewCore.h" +#import "LVTransform3D.h" +#import + +typedef NS_ENUM(int, LVAnimatorCallback) { + kLVAnimatorCallbackOnStart = 1, + kLVAnimatorCallbackOnEnd, + kLVAnimatorCallbackOnCancel, + kLVAnimatorCallbackOnPause, + kLVAnimatorCallbackOnResume, +}; + +static char *callbackKeys[] = { "", "onStart", "onEnd", "onCancel", "onPause", "onResume" }; + +@implementation LVAnimator { + NSString *_animationKey; + CABasicAnimation *_pausedAnimation; + NSTimeInterval _timeOffset; +} + +@dynamic running, paused; + +-(id) lv_nativeObject{ + return self; +} + +static int lvNewAnimator(lua_State *L) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVAnimator class]]; + + LVAnimator *animator = [c new]; + + NEW_USERDATA(userData, Animator); + userData->object = CFBridgingRetain(animator); + + animator.lv_userData = userData; + animator.lv_luaviewCore = LV_LUASTATE_VIEW(L); + + luaL_getmetatable(L, META_TABLE_Animator); + lua_setmetatable(L, -2); + + return 1; +} + +static int __gc(lua_State *L) { + LVUserDataInfo *data = (LVUserDataInfo *)lua_touserdata(L, 1); + if (LVIsType(data, Animator) && data->object) { + LVAnimator *animator = (__bridge LVAnimator *)data->object; + + CFBridgingRelease((__bridge CFTypeRef)(animator)); + data->object = nil; + + animator.lv_luaviewCore = nil; + animator.lv_userData = NULL; + } + + return 0; +} + +static int __tostring(lua_State *L) { + LVUserDataInfo *data = (LVUserDataInfo *)lua_touserdata(L, 1); + if (LVIsType(data, Animator)) { + LVAnimator *animator = (__bridge LVAnimator *)data->object; + NSString *s = [NSString stringWithFormat:@"Animator<%@>: %@", animator.keyPath, animator.toValue]; + lua_pushstring(L, s.UTF8String); + + return 1; + } + + return 0; +} + +static int __eq(lua_State *L) { + LVUserDataInfo *data1 = (LVUserDataInfo *)lua_touserdata(L, 1); + LVUserDataInfo *data2 = (LVUserDataInfo *)lua_touserdata(L, 2); + + if (LVIsType(data1, Animator) && LVIsType(data2, Animator)) { + LVAnimator *a1 = (__bridge LVAnimator *)data1->object; + LVAnimator *a2 = (__bridge LVAnimator *)data2->object; + + BOOL eq = [a1 isEqual:a2]; + lua_pushboolean(L, eq); + + return 1; + } + + return 0; +} + +static int clone(lua_State *L) { + LVUserDataInfo *data = (LVUserDataInfo *)lua_touserdata(L, 1); + if (LVIsType(data, Animator)) { + LVAnimator *animator = [(__bridge LVAnimator *)data->object copy]; + + NEW_USERDATA(userData, Animator); + userData->object = CFBridgingRetain(animator); + + animator.lv_userData = userData; + animator.lv_luaviewCore = LV_LUASTATE_VIEW(L); + + luaL_getmetatable(L, META_TABLE_Animator); + lua_setmetatable(L, -2); + + return 1; + } + + return 0; +} + +static int with(lua_State *L) { + LVUserDataInfo *adata = (LVUserDataInfo *)lua_touserdata(L, 1); + LVUserDataInfo *vdata = (LVUserDataInfo *)lua_touserdata(L, 2); + + if (LVIsType(adata, Animator) && LVIsType(vdata, View)) { + LVAnimator *animator = (__bridge LVAnimator *)adata->object; + animator.target = (__bridge UIView *)vdata->object; + } + + lv_pushUserdata(L, adata); + + return 1; +} + +static int start(lua_State *L) { + LVUserDataInfo *data = (LVUserDataInfo *)lua_touserdata(L, 1); + + if (LVIsType(data, Animator)) { + LVAnimator *animator = (__bridge LVAnimator *)data->object; + if (animator.running) { + LVLog(@"Animation of key:%@ is running!", animator.keyPath); + } else { + [animator start]; + } + } + + lv_pushUserdata(L, data); + + return 1; +} + +static int cancel(lua_State *L) { + LVUserDataInfo *data = (LVUserDataInfo *)lua_touserdata(L, 1); + + if (LVIsType(data, Animator)) { + LVAnimator *animator = (__bridge LVAnimator *)data->object; + [animator cancel]; + } + + lv_pushUserdata(L, data); + + return 1; +} + +static int isRunning(lua_State *L) { + LVUserDataInfo *data = (LVUserDataInfo *)lua_touserdata(L, 1); + + if (LVIsType(data, Animator)) { + LVAnimator *animator = (__bridge LVAnimator *)data->object; + lua_pushboolean(L, animator.running); + } else { + lua_pushboolean(L, 0); + } + + return 1; +} + +static int pauseAnimator(lua_State *L) { + LVUserDataInfo *data = (LVUserDataInfo *)lua_touserdata(L, 1); + + if (LVIsType(data, Animator)) { + LVAnimator *animator = (__bridge LVAnimator *)data->object; + [animator pause]; + } + + lv_pushUserdata(L, data); + + return 1; +} + +static int resumeAnimator(lua_State *L) { + LVUserDataInfo *data = (LVUserDataInfo *)lua_touserdata(L, 1); + + if (LVIsType(data, Animator)) { + LVAnimator *animator = (__bridge LVAnimator *)data->object; + [animator resume]; + } + + lv_pushUserdata(L, data); + + return 1; +} + +static int isPaused(lua_State *L) { + LVUserDataInfo *data = (LVUserDataInfo *)lua_touserdata(L, 1); + + if (LVIsType(data, Animator)) { + LVAnimator *animator = (__bridge LVAnimator *)data->object; + lua_pushboolean(L, animator.paused); + } else { + lua_pushboolean(L, 0); + } + + return 1; +} + +static int duration(lua_State *L) { + LVUserDataInfo *data = (LVUserDataInfo *)lua_touserdata(L, 1); + float value = lua_tonumber(L, 2); + + if (LVIsType(data, Animator)) { + LVAnimator *animator = (__bridge LVAnimator *)data->object; + + animator.duration = value; + } + + lv_pushUserdata(L, data); + + return 1; +} + +static int delay(lua_State *L) { + LVUserDataInfo *data = (LVUserDataInfo *)lua_touserdata(L, 1); + float value = lua_tonumber(L, 2); + + if (LVIsType(data, Animator)) { + LVAnimator *animator = (__bridge LVAnimator *)data->object; + + animator.delay = value; + } + + lv_pushUserdata(L, data); + + return 1; +} + +static int repeatCount(lua_State *L) { + LVUserDataInfo *data = (LVUserDataInfo *)lua_touserdata(L, 1); + int value = (int)lua_tointeger(L, 2); + + if (LVIsType(data, Animator)) { + LVAnimator *animator = (__bridge LVAnimator *)data->object; + + animator.repeatCount = value; + } + + lv_pushUserdata(L, data); + + return 1; +} + +static int autoreverses(lua_State *L) { + LVUserDataInfo *data = (LVUserDataInfo *)lua_touserdata(L, 1); + BOOL autoreverses = !!lua_toboolean(L, 2); + + if (LVIsType(data, Animator)) { + LVAnimator *animator = (__bridge LVAnimator *)data->object; + + animator.autoreverses = autoreverses; + } + + lv_pushUserdata(L, data); + + return 1; +} + +static int interpolator(lua_State *L) { + LVUserDataInfo *data = (LVUserDataInfo *)lua_touserdata(L, 1); + LVAniamtorInterpolator interpolator = lua_tonumber(L, 2); + + if (LVIsType(data, Animator)) { + LVAnimator *animator = (__bridge LVAnimator *)data->object; + + animator.interpolator = interpolator; + } + + lv_pushUserdata(L, data); + + return 1; +} + +static int setCallback(lua_State *L, int idx) { + LVUserDataInfo *data = (LVUserDataInfo *)lua_touserdata(L, 1); + + if (LVIsType(data, Animator)) { + lua_pushvalue(L, 1); + if (lua_type(L, 2) == LUA_TFUNCTION) { + lua_pushvalue(L, 2); + } else { + lua_pushnil(L); + } + + lv_udataRef(L, idx); + } + + lv_pushUserdata(L, data); + + return 1; +} + +static int onStart(lua_State *L) { + return setCallback(L, kLVAnimatorCallbackOnStart); +} + +static int onEnd(lua_State *L) { + return setCallback(L, kLVAnimatorCallbackOnEnd); +} + +static int onCancel(lua_State *L) { + return setCallback(L, kLVAnimatorCallbackOnCancel); +} + +static int onPause(lua_State *L) { + return setCallback(L, kLVAnimatorCallbackOnPause); +} + +static int onResume(lua_State *L) { + return setCallback(L, kLVAnimatorCallbackOnResume); +} + +static int callback(lua_State *L) { + LVUserDataInfo *data = (LVUserDataInfo *)lua_touserdata(L, 1); + if (LVIsType(data, Animator) && lua_type(L, 2) == LUA_TTABLE) { + lua_pushvalue(L, 2); + lua_pushnil(L); + + while (lua_next(L, -2)) { + if (lua_type(L, -2) != LUA_TSTRING) { + continue; + } + const char* key = lua_tostring(L, -2); + int idx = 0; + for (int i = 0; i < sizeof(callbackKeys) / sizeof(callbackKeys[0]); ++i) { + if (strcmp(key, callbackKeys[i]) == 0) { + idx = i; + break; + } + } + + if (idx != 0) { + lua_pushvalue(L, 1); + if (lua_type(L, -2) == LUA_TFUNCTION) { + lua_pushvalue(L, -2); + } else { + lua_pushnil(L); + } + lv_udataRef(L, idx); + lua_pop(L, 2); + } else { + lua_pop(L, 1); + } + } + lua_pop(L, 1); + } + + lv_pushUserdata(L, data); + + return 1; +} + +static int updateValue(lua_State *L, NSString *keyPath, id value) { + LVUserDataInfo *data = (LVUserDataInfo *)lua_touserdata(L, 1); + if (LVIsType(data, Animator)) { + LVAnimator *animator = (__bridge LVAnimator *)data->object; + if (keyPath) { + animator.keyPath = keyPath; + } + + animator.toValue = value; + } + + lua_settop(L, 1); + + return 1; +} + +static int updateFloat(lua_State *L, NSString *keyPath) { + float value = lua_tonumber(L, 2); + + return updateValue(L, keyPath, @(value)); +} + +static int updatePoint(lua_State *L, NSString *keyPath) { + float x = lua_tonumber(L, 2), y = lua_tonumber(L, 3); + NSValue *point = [NSValue valueWithCGPoint:CGPointMake(x, y)]; + + return updateValue(L, keyPath, point); +} + +static int alpha(lua_State *L) { + return updateFloat(L, @"opacity"); +} + +static int rotation(lua_State *L) { + return updateFloat(L, @"transform.rotation"); +} + +static int scale(lua_State *L) { + // default y = x + if (lua_gettop(L) == 2) { + lua_pushnumber(L, lua_tonumber(L, 2)); + } + return updatePoint(L, @"transform.scale"); +} + +static int scaleX(lua_State *L) { + return updateFloat(L, @"transform.scale.x"); +} + +static int scaleY(lua_State *L) { + return updateFloat(L, @"transform.scale.y"); +} + +static int translation(lua_State *L) { + return updatePoint(L, @"transform.translation"); +} + +static int translationX(lua_State *L) { + return updateFloat(L, @"transform.translation.x"); +} + +static int translationY(lua_State *L) { + return updateFloat(L, @"transform.translation.y"); +} + +static int value(lua_State *L) { + return updateFloat(L, nil); +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewAnimator globalName:globalName defaultName:@"Animation"]; + + const struct luaL_Reg memberFunctions[] = { + { "__gc", __gc }, + { "__tostring", __tostring }, + { "__eq", __eq }, + + { "clone", clone }, + + { "with", with }, + { "duration", duration }, + { "delay", delay }, + { "repeatCount", repeatCount }, + { "reverses", autoreverses }, // 和安卓特性不一样 + { "interpolator", interpolator }, + + { "cancel", cancel }, + { "start", start }, + { "isRunning", isRunning }, + + { "pause", pauseAnimator }, + { "resume", resumeAnimator }, + { "isPaused", isPaused }, + + { "callback", callback }, + { callbackKeys[kLVAnimatorCallbackOnStart], onStart }, + { callbackKeys[kLVAnimatorCallbackOnEnd], onEnd }, + { callbackKeys[kLVAnimatorCallbackOnCancel], onCancel }, + { callbackKeys[kLVAnimatorCallbackOnPause], onPause }, + { callbackKeys[kLVAnimatorCallbackOnResume], onResume }, + + { "alpha", alpha }, + { "rotation", rotation }, + { "scale", scale }, + { "scaleX", scaleX }, + { "scaleY", scaleY }, + { "translation", translation }, + { "translationX", translationX }, + { "translationY", translationY }, + { "value", value }, // IOS支持一个, 安卓支持多个值 + //{ "values", value }, + + { NULL, NULL} + }; + + lv_createClassMetaTable(L, META_TABLE_Animator); + luaL_openlib(L, NULL, memberFunctions, 0); + + return 1; +} + +- (instancetype)init { + if (self = [super init]) { + _autoreverses = YES; + } + + return self; +} + +- (instancetype)copyWithZone:(NSZone *)zone { + LVAnimator *animator = [[[self class] allocWithZone:zone] init]; + animator.keyPath = [self.keyPath copy]; + animator.toValue = [self.toValue copy]; + + animator.duration = self.duration; + animator.delay = self.delay; + animator.repeatCount = self.repeatCount; + animator.autoreverses = self.autoreverses; + + animator.target = self.target; + + return animator; +} + +- (instancetype)mutableCopyWithZone:(NSZone *)zone { + return [self copyWithZone:zone]; +} + +- (NSUInteger)hash { + return self.keyPath.hash; +} + +- (BOOL)isEqual:(id)object { + if (object == nil) { + return NO; + } + if (![object isKindOfClass:[self class]]) { + return NO; + } + + LVAnimator *a1 = (LVAnimator *)object; + return lv_objcEqual(self.keyPath, a1.keyPath) && + lv_objcEqual(self.toValue, a1.toValue) && + self.duration == a1.duration && + self.delay == a1.delay && + self.repeatCount == a1.repeatCount && + self.autoreverses == a1.autoreverses; +} + +- (CAMediaTimingFunction *)buildTimingFunction:(LVAniamtorInterpolator)interpolator { + switch (interpolator) { + case LVAnticipateInterpolator: + return [CAMediaTimingFunction functionWithControlPoints:0.5 :-0.6 :0.75 :0.5]; + case LVAnticipateOvershootInterpolator: + return [CAMediaTimingFunction functionWithControlPoints:0.5 :-0.55 :0.5 :1.55]; + case LVOvershootInterpolator: + return [CAMediaTimingFunction functionWithControlPoints:0.3 :0.9 :0.75 :1.3]; + case LVAccelerateDecelerateInterpolator: + return [CAMediaTimingFunction functionWithName:@"easeInEaseOut"]; + case LVAccelerateInterpolator: + return [CAMediaTimingFunction functionWithName:@"easeIn"]; + case LVDecelerateInterpolator: + return [CAMediaTimingFunction functionWithName:@"easeOut"]; + case LVLinearInterpolator: + default: + return [CAMediaTimingFunction functionWithName:@"linear"]; + } +} + +- (CAAnimation *)buildAnimation { + CAAnimation *animation = nil; + CALayer *layer = self.target.layer.presentationLayer ?: self.target.layer; + + if ([self.keyPath isEqualToString:@"transform.scale"]) { + CGPoint point = [self.toValue CGPointValue]; + + NSString *kx = @"transform.scale.x"; + CABasicAnimation *ax = [CABasicAnimation animationWithKeyPath:kx]; + ax.fromValue = [layer valueForKeyPath:kx]; + ax.toValue = @(point.x); + + NSString *ky = @"transform.scale.y"; + CABasicAnimation *ay = [CABasicAnimation animationWithKeyPath:ky]; + ay.fromValue = [layer valueForKeyPath:ky]; + ay.toValue = @(point.y); + + CAAnimationGroup *group = [CAAnimationGroup animation]; + group.animations = @[ax, ay]; + + animation = group; + } else if ([self.keyPath isEqualToString:@"transform.rotation"]) { + CABasicAnimation *a = [CABasicAnimation animationWithKeyPath:@"transform.rotation"]; + a.fromValue = [layer valueForKeyPath:@"transform.rotation"]; + a.toValue = @(((NSNumber *)self.toValue).floatValue * M_PI / 180.0); + + animation = a; + } else { + CABasicAnimation *a = [CABasicAnimation animationWithKeyPath:self.keyPath]; + a.fromValue = [layer valueForKeyPath:self.keyPath]; + a.toValue = self.toValue; + + animation = a; + } + + animation.delegate = (id)self; + animation.duration = self.duration; + animation.fillMode = @"both"; + + if (self.repeatCount > 0) { + animation.repeatCount = self.repeatCount; + if (animation.autoreverses) { + animation.repeatCount += 0.5; + } + animation.autoreverses = self.autoreverses; + } else if (self.repeatCount < 0) { + animation.repeatCount = HUGE_VALF; + animation.autoreverses = self.autoreverses; + } + + animation.timingFunction = [self buildTimingFunction:self.interpolator]; + animation.beginTime = CACurrentMediaTime() + self.delay; + + return animation; +} + +static void syncValue(CAAnimation *animation, CALayer *layer) { + if (!animation || !layer) { + return; + } + + if ([animation isKindOfClass:[CAAnimationGroup class]]) { + for (CAAnimation *a in ((CAAnimationGroup *)animation).animations) { + syncValue(a, layer); + } + } else if ([animation isKindOfClass:[CABasicAnimation class]]) { + CABasicAnimation *a = (CABasicAnimation *)animation; + [layer setValue:a.toValue forKeyPath:a.keyPath]; + } +} + +- (void)syncAnimatingValue:(CALayer *)layer { + if (!layer.presentationLayer) { + return; + } + + NSString *keyPath = nil; + if ([self.keyPath isEqualToString:@"opacity"]) { + keyPath = @"opacity"; + } else { + keyPath = @"transform"; + } + NSValue *current = [layer.presentationLayer valueForKeyPath:keyPath]; + [layer setValue:current forKeyPath:keyPath]; +} + +- (void)start { + if (self.running) { + LVLog(@"Animator(%p keyPath:%@) is running!", self.lv_userData, self.keyPath); + return; + } + if (self.keyPath.length == 0 || self.toValue == nil) { + LVLog(@"Animator keyPath and value cannot be nil!"); + return; + } + + CAAnimation *animation = nil; + if (self.target != nil && (animation = [self buildAnimation])) { + _animationKey = [NSString stringWithFormat:@"LVAnimator:%@", self.keyPath]; + + CALayer *layer = self.target.layer; + if ([layer animationForKey:_animationKey]) { + LVLog(@"warning: Animation of keyPath:%@ is running", self.keyPath); + } + + syncValue(animation, layer); + [layer addAnimation:animation forKey:_animationKey]; + [self callback:kLVAnimatorCallbackOnStart]; + } +} + +- (void)cancel { + if (!self.running) { + LVLog(@"warning: Animation of keyPath:%@ is not running", self.keyPath); + return; + } + + if (self.paused) { + _animationKey = nil; + _pausedAnimation = nil; + _timeOffset = 0.0; + [self callback:kLVAnimatorCallbackOnCancel]; + + // call onEnd, same as Android SDK + [self callback:kLVAnimatorCallbackOnEnd]; + } else { + CALayer *layer = self.target.layer; + [self syncAnimatingValue:layer]; + [layer removeAnimationForKey:_animationKey]; + } +} + +- (BOOL)isRunning { + return _animationKey != nil; +} + +- (void)pause { + if (!self.running) { + LVLog(@"Animator(%p) is not running!", self.lv_userData); + return; + } + if (self.paused) { + LVLog(@"Animator(%p) is already paused!", self.lv_userData); + return; + } + + CALayer *layer = self.target.layer; + [self syncAnimatingValue:layer]; + + _pausedAnimation = [[layer animationForKey:_animationKey] copy]; + _timeOffset = CACurrentMediaTime() - _pausedAnimation.beginTime; + + [layer removeAnimationForKey:_animationKey]; +} + +- (void)resume { + CALayer *layer = self.target.layer; + + _pausedAnimation.beginTime = CACurrentMediaTime() - _timeOffset; + + syncValue(_pausedAnimation, layer); + [layer addAnimation:_pausedAnimation forKey:_animationKey]; + + _timeOffset = 0.0; + _pausedAnimation = nil; + + [self callback:kLVAnimatorCallbackOnResume]; +} + +- (BOOL)isPaused { + return _pausedAnimation != nil; +} + +#pragma mark - animation delegate + +- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag { + if (self.paused) { + [self callback:kLVAnimatorCallbackOnPause]; + } else { + _animationKey = nil; + _pausedAnimation = nil; + _timeOffset = 0.0; + + if (!flag) { + [self callback:kLVAnimatorCallbackOnCancel]; + } + + // call onEnd, same as Android SDK + [self callback:kLVAnimatorCallbackOnEnd]; + } +} + +- (void)callback:(LVAnimatorCallback)idx { + lua_State* l = self.lv_luaviewCore.l; + if (l && self.lv_userData) { + int stackIndex = lua_gettop(l); + + lv_pushUserdata(l, self.lv_userData); + lv_pushUDataRef(l, idx); + lv_runFunction(l); + + if (lua_gettop(l) > stackIndex) { + lua_settop(l, stackIndex); + } + } +} + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAudioPlayer.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAudioPlayer.h new file mode 100644 index 00000000..dd866691 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAudioPlayer.h @@ -0,0 +1,26 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + + +@interface LVAudioPlayer : NSObject + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; + +-(id) init:(lua_State*) l; + +-(void) play; +-(void) stop; + + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAudioPlayer.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAudioPlayer.m new file mode 100644 index 00000000..f946507a --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAudioPlayer.m @@ -0,0 +1,187 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVAudioPlayer.h" +#import +#import "LView.h" +#import "LVHeads.h" + +@interface LVAudioPlayer () +@property(nonatomic,assign) BOOL playing; +@end + +@implementation LVAudioPlayer{ + AVAudioPlayer* audioPlayer; +} + +static void releaseUserDataAudioPlayer(LVUserDataInfo* user){ + if( user && user->object ){ + LVAudioPlayer* palyer = CFBridgingRelease(user->object); + user->object = NULL; + if( palyer ){ + [palyer stop]; + palyer.lv_userData = NULL; + palyer.lv_luaviewCore = nil; + } + } +} + +-(void) dealloc{ + releaseUserDataAudioPlayer(_lv_userData); +} + +-(id) init:(lua_State*) L{ + self = [super init]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(L); + } + return self; +} + +-(void) setPlayFileName0:(NSString*) fileName bundle:(LVBundle*) bundle{ + NSString* path = [bundle resourcePathWithName:fileName]; + if( path ) { + NSURL* url = [[NSURL alloc] initWithString:path]; + NSError* error = nil; + audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];//使用本地URL创建 + if( error ) { + NSLog(@"[LuaView][error]%@",error); + } + } + if( self.playing ) { + [self play]; + } +} + +-(void) setPlayFileName:(NSString*) fileName bundle:(LVBundle*) bundle{ + if( fileName ==nil ) + return; + if( [LVUtil isExternalUrl:fileName] ){ + [LVUtil download:fileName callback:^(NSData *fileData) { + NSString* suffix = [fileName componentsSeparatedByString:@"."].lastObject; + NSData* theFileNameData = [fileName dataUsingEncoding:NSUTF8StringEncoding]; + NSString* md5Path = [LVUtil MD5HashFromData:theFileNameData]; + md5Path = [NSString stringWithFormat:@"%@.%@",md5Path,suffix];//Mp3文件一定要加后缀,否则无法播放 + if( [LVUtil saveData:fileData toFile:[LVUtil PathForCachesResource:md5Path]] ) { + [self setPlayFileName0:md5Path bundle:bundle]; + } + }]; + } else { + [self setPlayFileName0:fileName bundle:bundle]; + } +} + +-(void) play { + [audioPlayer play]; + self.playing = YES; +} + +-(void) stop { + [audioPlayer stop]; + self.playing = NO; +} + +- (id) lv_nativeObject{ + return audioPlayer; +} + + +#pragma -mark AudioPlayer + +static int lvNewAudioPlayer (lua_State *L) { + if( lua_gettop(L)>=1 ) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVAudioPlayer class]]; + + LVAudioPlayer* player = [[c alloc] init:L]; + LuaViewCore* lview = LV_LUASTATE_VIEW(L); + NSString* fileName = lv_paramString(L, 1); + [player setPlayFileName:fileName bundle:lview.bundle]; + + { + NEW_USERDATA(userData, AudioPlayer); + userData->object = CFBridgingRetain(player); + player.lv_userData = userData; + + luaL_getmetatable(L, META_TABLE_AudioPlayer ); + lua_setmetatable(L, -2); + } + return 1; + } + return 0; +} + +static int play (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + + if( user && LVIsType(user, AudioPlayer) ){ + LVAudioPlayer* player = (__bridge LVAudioPlayer *)(user->object); + if( player ){ + [player play]; + lua_pushvalue(L,1); + return 1; + } + } + return 0; +} + +static int stop (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVAudioPlayer* player = (__bridge LVAudioPlayer *)(user->object); + if( player ){ + [player stop]; + } + } + return 0; +} + +static int __gc (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + releaseUserDataAudioPlayer(user); + return 0; +} + +static int __tostring (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVAudioPlayer* player = (__bridge LVAudioPlayer *)(user->object); + NSString* s = [NSString stringWithFormat:@"LVUserDataAudioPlayer: %@", player ]; + lua_pushstring(L, s.UTF8String); + return 1; + } + return 0; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewAudioPlayer globalName:globalName defaultName:@"AudioPlayer"]; + + const struct luaL_Reg memberFunctions [] = { + {"play", play }, + {"stop", stop }, + // pause + // resume + // callback { onComplete onError } + + // playing + // looping + // pausing + + {"__gc", __gc }, + {"__tostring", __tostring }, + {NULL, NULL} + }; + lv_createClassMetaTable(L, META_TABLE_AudioPlayer); + + luaL_openlib(L, NULL, memberFunctions, 0); + return 1; +} + +@end + + + diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVBaseView.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVBaseView.h new file mode 100644 index 00000000..c34e144d --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVBaseView.h @@ -0,0 +1,34 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + +@interface LVBaseView : UIView + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; +@property(nonatomic,assign) NSUInteger lv_align; + +@property(nonatomic,strong) CAShapeLayer* lv_shapeLayer; +@property(nonatomic,assign) BOOL lv_canvas; +@property(nonatomic,strong) NSString * lv_identifier; + +-(id) init:(lua_State*) l; + ++(const luaL_Reg*) baseMemberFunctions; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +@end + + +/** + * callback回调统一处理API + */ +extern int lv_setCallbackByKey(lua_State *L, const char* key, BOOL addGesture); diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVBaseView.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVBaseView.m new file mode 100644 index 00000000..fa1003e1 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVBaseView.m @@ -0,0 +1,1726 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVBaseView.h" +#import "LView.h" +#import "LVTransform3D.h" +#import "LVAnimator.h" +#import +#import "LVStruct.h" +#import "JUFLXLayoutKit.h" +#import "UIView+JUFLXNode.h" +#import "LVGesture.h" +#import "LVHeads.h" + +@interface LVBaseView () +@property(nonatomic,assign) BOOL lv_isCallbackAddClickGesture;// 支持Callback 点击事件 +@end + +@implementation LVBaseView + + +-(id) init:(lua_State*) L{ + self = [super init]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(L); + self.clipsToBounds = YES; + self.lv_isCallbackAddClickGesture = YES; + } + return self; +} + +static void releaseUserDataView(LVUserDataInfo* userdata){ + if( userdata && userdata->object ){ + UIView* view = CFBridgingRelease(userdata->object); + userdata->object = NULL; + if( view ){ + view.lv_userData = NULL; + view.lv_luaviewCore = nil; + if( !userdata->isWindow ) { + [view removeFromSuperview]; + [view.layer removeFromSuperlayer]; + } + } + } +} + +-(void) dealloc { +} + +#pragma -mark center +static int center (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + CGPoint center = view.center; + if ( lua_gettop(L)>=2 ) { + if ( lua_isuserdata(L, 2) ) { + LVUserDataInfo* user = lua_touserdata(L, 2); + if ( LVIsType(user, Struct) ) { + LVStruct* stru = (__bridge LVStruct *)(user->object); + if( [stru dataPointer] ) { + memcpy(¢er, [stru dataPointer], sizeof(CGPoint)); + } + } else { + LVError(@"LVBaseView.setCenter1"); + } + } else { + if( lua_isnumber(L, 2) ){ + center.x = lua_tonumber(L, 2);// 2 + } + if( lua_isnumber(L, 3) ){ + center.y = lua_tonumber(L, 3);// 3 + } + } + if( isnan(center.x) || isnan(center.y) ){ + LVError(@"LVBaseView.setCenter2"); + } else { + view.center = center; + } + view.lv_align = 0; + return 0; + } else { + lua_pushnumber(L, center.x ); + lua_pushnumber(L, center.y ); + return 2; + } + } + } + return 0; +} + +static int centerX(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + CGPoint center = view.center; + if ( lua_gettop(L)>=2 ) { + if( lua_isnumber(L, 2) ){ + center.x = lua_tonumber(L, 2);// 2 + } + if( isnan(center.x) || isnan(center.y) ){ + LVError(@"LVBaseView.setCenterX2"); + } else { + view.center = center; + } + return 0; + } else { + lua_pushnumber(L, center.x ); + return 1; + } + } + } + return 0; +} + +static int centerY(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + CGPoint center = view.center; + if ( lua_gettop(L)>=2 ) { + if( lua_isnumber(L, 2) ){ + center.y = lua_tonumber(L, 2);// 2 + } + if( isnan(center.x) || isnan(center.y) ){ + LVError(@"LVBaseView.setCenterX2"); + } else { + view.center = center; + } + return 0; + } else { + lua_pushnumber(L, center.y ); + return 1; + } + } + } + return 0; +} + +#pragma -mark frame +static int frame (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + CGRect r = view.frame; + if( lua_gettop(L)>=2 ) { + if ( lua_isuserdata(L, 2) ) { + LVUserDataInfo* user = lua_touserdata(L, 2); + if ( LVIsType(user, Struct) ) { + LVStruct* stru = (__bridge LVStruct *)(user->object); + if( [stru dataPointer] ) { + memcpy(&r, [stru dataPointer], sizeof(CGRect)); + } + } else { + LVError(@"LVBaseView.setFrame1"); + } + } else { + if( lua_isnumber(L, 2) ){ + r.origin.x = lua_tonumber(L, 2);// 2 + } + if( lua_isnumber(L, 3) ){ + r.origin.y = lua_tonumber(L, 3);// 3 + } + if( lua_isnumber(L, 4) ){ + r.size.width = lua_tonumber(L, 4);// 4 + } + if( lua_isnumber(L, 5) ){ + r.size.height = lua_tonumber(L, 5);// 5 + } + } + if( isnan(r.origin.x) || isnan(r.origin.y) || isnan(r.size.width) || isnan(r.size.height) ){ + LVError(@"LVBaseView.setFrame2: %s", NSStringFromCGRect(r) ); + } else { + view.frame = r; + } + view.lv_align = 0; + return 0; + } else { + lua_pushnumber(L, r.origin.x ); + lua_pushnumber(L, r.origin.y ); + lua_pushnumber(L, r.size.width ); + lua_pushnumber(L, r.size.height ); + return 4; + } + } + } + return 0; +} + +#pragma -mark frame +static int size (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + CGRect r = view.frame; + if ( lua_gettop(L)>=2 ) { + if ( lua_isuserdata(L, 2) ) { + LVUserDataInfo* user = lua_touserdata(L, 2); + if ( LVIsType(user, Struct) ) { + LVStruct* stru = (__bridge LVStruct *)(user->object); + if( [stru dataPointer] ) { + memcpy(&r.size, [stru dataPointer], sizeof(CGSize)); + } + } else { + LVError(@"LVBaseView.setSize1"); + } + } else { + if( lua_isnumber(L, 2) ){ + r.size.width = lua_tonumber(L, 2);// 4 + } + if( lua_isnumber(L, 3) ){ + r.size.height = lua_tonumber(L, 3);// 5 + } + } + if( isnan(r.origin.x) || isnan(r.origin.y) || isnan(r.size.width) || isnan(r.size.height) ){ + LVError(@"LVBaseView.setSize2: %s", NSStringFromCGRect(r) ); + } else { + view.frame = r; + } + return 0; + } else { + lua_pushnumber(L, r.size.width ); + lua_pushnumber(L, r.size.height ); + return 2; + } + } + } + return 0; +} + +static int origin (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + CGRect r = view.frame; + if ( lua_gettop(L)>=2 ) { + if ( lua_isuserdata(L, 2) ) { + LVUserDataInfo* user = lua_touserdata(L, 2); + if ( LVIsType(user, Struct) ) { + LVStruct* stru = (__bridge LVStruct *)(user->object); + if( [stru dataPointer] ) { + memcpy(&r.origin, [stru dataPointer], sizeof(CGPoint)); + } + } else { + LVError(@"LVBaseView.setOrigin1"); + } + } else { + if( lua_isnumber(L, 2) ){ + r.origin.x = lua_tonumber(L, 2);// 2 + } + if( lua_isnumber(L, 3) ){ + r.origin.y = lua_tonumber(L, 3);// 3 + } + } + if( isnan(r.origin.x) || isnan(r.origin.y) || isnan(r.size.width) || isnan(r.size.height) ){ + LVError(@"LVBaseView.setOrigin2: %s", NSStringFromCGRect(r) ); + } else { + view.frame = r; + } + view.lv_align = 0; + return 0; + } else { + lua_pushnumber(L, r.origin.x ); + lua_pushnumber(L, r.origin.y ); + return 2; + } + } + } + return 0; +} + +static int x (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + CGRect r = view.frame; + if ( lua_gettop(L)>=2 ) { + r.origin.x = lua_tonumber(L, 2);// 2 + if( isnan(r.origin.x) || isnan(r.origin.y) || isnan(r.size.width) || isnan(r.size.height) ){ + LVError(@"LVBaseView.y2: %s", NSStringFromCGRect(r) ); + } else { + view.frame = r; + } + view.lv_align = 0; + return 0; + } else { + lua_pushnumber(L, r.origin.x ); + return 1; + } + } + } + return 0; +} + +#pragma - mark flxNode +static int flxChildViews(lua_State *L) +{ + LVUserDataInfo *user = (LVUserDataInfo *)lua_touserdata(L, 1); + if (user) { + UIView *view = (__bridge UIView *)(user->object); + int childNum = lua_gettop(L); + if (view && childNum>=2 ) { + NSArray *arr = (NSArray*)lv_luaValueToNativeObject(L, 2); + if ([arr isKindOfClass:[NSArray class]] && arr.count > 0) { + NSMutableArray* childs = [[NSMutableArray alloc] init]; + for( int i=0; iobject); + if( temp ) { + [childs addObject:temp.ju_flxNode]; + } + } + view.ju_flxNode.childNodes = childs; + return 0; + } + } + return 0; +} + +static int flxBindingInlineCSS(lua_State *L) +{ + LVUserDataInfo *user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ) { + UIView *view = (__bridge UIView *)(user->object); + + int childNum = lua_gettop(L); + if (view && childNum==2) { + if (lua_type(L, 2) == LUA_TSTRING) { + [view.ju_flxNode bindingInlineCSS:[NSString stringWithUTF8String:lua_tostring(L, 2)]]; + return 0; + } + } + } + return 0; +} + +//static int flxMeasure(lua_State *L) +//{ +// LVUserDataView *user = (LVUserDataView *)lua_touserdata(L, 1); +// UIView *view = (__bridge UIView *)(user->view); +// int childNum = lua_gettop(L); +// if (view && childNum == 2) { +// if (lua_type(L, 2) == LUA_TFUNCTION) { +// lua_pushvalue(L, 1); +// lua_pushvalue(L, 2); +// lv_udataRef(L, USERDATA_FLEX_DELEGATE); +// } +// view.ju_flxNode.measure = ^CGSize(CGFloat width) { +// lv_pushUserdata(L, user ); +// lv_pushUDataRef(L, USERDATA_FLEX_DELEGATE ); +// lua_pushnumber(L, width); +// lv_runFunctionWithArgs(L, 1, 2); +// CGSize size = CGSizeZero; +// size.width = lua_tonumber(L, -2); +// size.height = lua_tonumber(L, -1); +// return size; +// }; +// +// } +// return 0; +//} + +static int flxLayout(lua_State *L) +{ + LVUserDataInfo *user = (LVUserDataInfo *)lua_touserdata(L, 1); + if (user) { + BOOL async = FALSE; + int argNum = lua_gettop(L); + for ( int i=1; i<=argNum; i++ ) { + if ( lua_type(L, i)==LUA_TBOOLEAN ){ + async = lua_toboolean(L, i); + } + if( lua_type(L, i) == LUA_TFUNCTION ) { + lua_pushvalue(L, 1); + lua_pushvalue(L, i); + lv_udataRef(L, USERDATA_FLEX_DELEGATE); + } + } + UIView *view = (__bridge UIView *)(user->object); + [view.ju_flxNode layoutAsync:async completionBlock:^(CGRect frame) { + lv_pushUserdata(L, user ); + lv_pushUDataRef(L, USERDATA_FLEX_DELEGATE ); + lv_runFunction(L); + }]; + } + return 0; +} + + +static int y (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + CGRect r = view.frame; + if ( lua_gettop(L)>=2 ) { + r.origin.y = lua_tonumber(L, 2);// 2 + if( isnan(r.origin.x) || isnan(r.origin.y) || isnan(r.size.width) || isnan(r.size.height) ){ + LVError(@"LVBaseView.y2: %s", NSStringFromCGRect(r) ); + } else { + view.frame = r; + } + view.lv_align = 0; + return 0; + } else { + lua_pushnumber(L, r.origin.y ); + return 1; + } + } + } + return 0; +} + +static int bottom (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + CGRect r = view.frame; + if ( lua_gettop(L)>=2 ) { + r.origin.y = lua_tonumber(L, 2)-r.size.height;// 2 + if( isnan(r.origin.x) || isnan(r.origin.y) || isnan(r.size.width) || isnan(r.size.height) ){ + LVError(@"LVBaseView.y2: %s", NSStringFromCGRect(r) ); + } else { + view.frame = r; + } + view.lv_align = 0; + return 0; + } else { + lua_pushnumber(L, r.origin.y + r.size.height ); + return 1; + } + } + } + return 0; +} + +static int right (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + CGRect r = view.frame; + if ( lua_gettop(L)>=2 ) { + r.origin.x = lua_tonumber(L, 2)-r.size.width;// 2 + if( isnan(r.origin.x) || isnan(r.origin.y) || isnan(r.size.width) || isnan(r.size.height) ){ + LVError(@"LVBaseView.y2: %s", NSStringFromCGRect(r) ); + } else { + view.frame = r; + } + view.lv_align = 0; + return 0; + } else { + lua_pushnumber(L, r.origin.x + r.size.width ); + return 1; + } + } + } + return 0; +} + +static int width (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + CGRect r = view.frame; + if ( lua_gettop(L)>=2 ) { + r.size.width = lua_tonumber(L, 2);// 2 + if( isnan(r.origin.x) || isnan(r.origin.y) || isnan(r.size.width) || isnan(r.size.height) ){ + LVError(@"LVBaseView.y2: %s", NSStringFromCGRect(r) ); + } else { + view.frame = r; + } + return 0; + } else { + lua_pushnumber(L, r.size.width ); + return 1; + } + } + } + return 0; +} + +static int height (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + CGRect r = view.frame; + if ( lua_gettop(L)>=2 ) { + r.size.height = lua_tonumber(L, 2);// 2 + if( isnan(r.origin.x) || isnan(r.origin.y) || isnan(r.size.width) || isnan(r.size.height) ){ + LVError(@"LVBaseView.y2: %s", NSStringFromCGRect(r) ); + } else { + view.frame = r; + } + return 0; + } else { + lua_pushnumber(L, r.size.height ); + return 1; + } + } + } + return 0; +} + +static int addGestureRecognizer (lua_State *L) { + LVUserDataInfo * userDataView = (LVUserDataInfo *)lua_touserdata(L, 1); + LVUserDataInfo * userDataGesture = (LVUserDataInfo *)lua_touserdata(L, 2); + if( userDataView && LVIsType(userDataGesture, Gesture) ){ + UIView* view = (__bridge UIView *)(userDataView->object); + UIGestureRecognizer* gesture = (__bridge UIGestureRecognizer *)(userDataGesture->object); + if( view && gesture ){ + [view addGestureRecognizer:gesture]; + lua_pushvalue(L,1); + return 1; + } + } + return 0; +} + +static int removeGestureRecognizer (lua_State *L) { + LVUserDataInfo * userDataView = (LVUserDataInfo *)lua_touserdata(L, 1); + LVUserDataInfo * userDataGesture = (LVUserDataInfo *)lua_touserdata(L, 2); + if( userDataView && LVIsType(userDataGesture, Gesture) ){ + UIView* view = (__bridge UIView *)(userDataView->object); + UIGestureRecognizer* gesture = (__bridge UIGestureRecognizer *)(userDataGesture->object); + if( view && gesture ){ + [view removeGestureRecognizer:gesture]; + lua_pushvalue(L,1); + return 1; + } + } + return 0; +} + +static int addSubview (lua_State *L) { + LVUserDataInfo * father = (LVUserDataInfo *)lua_touserdata(L, 1); + LVUserDataInfo * son = (LVUserDataInfo *)lua_touserdata(L, 2); + LuaViewCore* luaview = LV_LUASTATE_VIEW(L); + if( father && LVIsType(son, View) ){ + UIView* superview = (__bridge UIView *)(father->object); + UIView* subview = (__bridge UIView *)(son->object); + if( superview && subview ){ + lv_addSubview(luaview, superview, subview); + [subview lv_alignSelfWithSuperRect:superview.frame]; + lua_pushvalue(L,1); + return 1; + } + } + return 0; +} + + +static int getNativeView (lua_State *L) { + LVUserDataInfo * userData = (LVUserDataInfo *)lua_touserdata(L, 1); + if( userData ){ + UIView* view = (__bridge UIView *)(userData->object); + if( view ){ + id object = [view lv_getNativeView]; + lv_pushNativeObjectWithBox(L, object); + return 1; + } + } + return 0; +} + +#pragma -mark 运行环境 +static int children (lua_State *L) { + LuaViewCore* lview = LV_LUASTATE_VIEW(L); + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + + UIView* newWindow = (__bridge UIView *)(user->object); + if ( lview && newWindow && lua_type(L, 2)==LUA_TFUNCTION ) { + lua_settop(L, 2); + [lview pushWindow:newWindow]; + lv_runFunctionWithArgs(L, 1, 0); + [lview popWindow:newWindow]; + } + return 0; +} + + +static int removeFromSuperview (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + [view removeFromSuperview]; + [view.layer removeFromSuperlayer]; + lua_pushvalue(L,1); + return 1; + } + } + return 0; +} + +static int removeAllSubviews (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + NSArray* subviews = view.subviews; + for( UIView* child in subviews ) { + [child removeFromSuperview]; + } + NSArray* sublayers = view.layer.sublayers; + for(CALayer * sublayer in sublayers ) { + [sublayer removeFromSuperlayer]; + } + lua_pushvalue(L,1); + return 1; + } + } + return 0; +} + +static int layerMode(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + if ( lua_gettop(L)>=2 ) { + UIView* superview = view.superview; + BOOL yes = lua_toboolean(L, 2); + if( yes ) { + [view removeFromSuperview]; + [superview.layer addSublayer:view.layer]; + } else { + [view.layer removeFromSuperlayer]; + [superview addSubview:view]; + } + return 0; + } else { + //lua_pushboolean(L, view.hidden ); + //return 1; + } + } + } + return 0; +} + +#pragma -mark hidden +//__deprecated_msg("Use hide") +static int hidden(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + if ( lua_gettop(L)>=2 ) { + BOOL yes = lua_toboolean(L, 2); + view.hidden = yes; + return 0; + } else { + lua_pushboolean(L, view.hidden ); + return 1; + } + } + } + return 0; +} + +static int hide(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + view.hidden = YES; + return 0; + } + } + return 0; +} + +static int show(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + view.hidden = NO; + return 0; + } + } + return 0; +} + +static int isShow(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + lua_pushboolean(L, !view.hidden ); + return 1; + } + } + return 0; +} + +static int isHide(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + lua_pushboolean(L, view.hidden ); + return 1; + } + } + return 0; +} + +static int becomeFirstResponder(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + if( view.canBecomeFirstResponder ) + [view becomeFirstResponder]; + + lua_pushvalue(L,1); + return 1; + } + } + return 0; +} + +static int resignFirstResponder(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + if( view.canResignFirstResponder) + [view resignFirstResponder]; + + lua_pushvalue(L,1); + return 1; + } + } + return 0; +} + +static int isFirstResponder(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + lua_pushboolean(L, view.isFirstResponder?1:0 ); + return 1; + } + } + return 0; +} + +#pragma -mark userInteractionEnabled +static int userInteractionEnabled(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + if ( lua_gettop(L)>=2 ) { + BOOL yes = lua_toboolean(L, 2); + view.userInteractionEnabled = yes; + return 0; + } else { + lua_pushboolean(L, view.userInteractionEnabled ); + return 1; + } + } + } + return 0; +} + +#pragma -mark backgroundColor +static int backgroundColor (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( [view isKindOfClass:[UIView class]] ){ + if( lua_gettop(L)>=2 ) { + UIColor* color = lv_getColorFromStack(L, 2); + view.backgroundColor = color; + return 0; + } else { + UIColor* color = view.backgroundColor; + NSUInteger c = 0; + CGFloat a = 0; + if( lv_uicolor2int(color, &c,&a) ){ + lua_pushnumber(L, c ); + lua_pushnumber(L, a); + return 2; + } + } + } + } + return 0; +} + +#pragma -mark alpha +static int alpha (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if ( lua_gettop(L)>=2 ) { + CALayer* layer = view.layer; + + double alpha = lua_tonumber(L, 2);// 2 + layer.opacity = alpha; + + lua_pop(L, 1); + return 1; + } else { + CALayer* layer = view.layer.presentationLayer ?: view.layer; + + float alpha = layer.opacity; + lua_pushnumber(L, alpha ); + return 1; + } + } + return 0; +} + +#pragma -mark cornerRadius +static int cornerRadius (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( lua_gettop(L)>=2 ) { + double r = lua_tonumber(L, 2);// 2 + view.layer.cornerRadius = r; + return 0; + } else { + float r = view.layer.cornerRadius; + lua_pushnumber(L, r ); + return 1; + } + } + return 0; +} + +#pragma -mark borderWidth +static int borderWidth (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( lua_gettop(L)>=2 ) { + double width = lua_tonumber(L, 2);// 2 + view.layer.borderWidth = width; + return 0; + } else { + float w = view.layer.borderWidth; + lua_pushnumber(L, w ); + return 1; + } + } + return 0; +} + +#pragma -mark shadow +static int setShadowPath (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + [view layer].shadowPath =[UIBezierPath bezierPathWithRect:view.bounds].CGPath; + lua_pushvalue(L,1); + return 1; + } + return 0; +} +static int setMasksToBounds (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + BOOL masksToBounds = lua_toboolean(L, 2);// 2 + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + view.layer.masksToBounds = masksToBounds; + lua_pushvalue(L,1); + return 1; + } + return 0; +} + +static int setShadowOffset (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + float x = lua_tonumber(L, 2);// 2 + float y = lua_tonumber(L, 3);// 2 + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + [view.layer setShadowOffset:CGSizeMake(x, y)]; + lua_pushvalue(L,1); + return 1; + } + return 0; +} + +static int setShadowRadius (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + float radius = lua_tonumber(L, 2);// 2 + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + [view.layer setShadowRadius:radius]; + lua_pushvalue(L,1); + return 1; + } + return 0; +} + +static int setShadowOpacity (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + float opacity = lua_tonumber(L, 2);// 2 + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + [view.layer setShadowOpacity:opacity]; + lua_pushvalue(L,1); + return 1; + } + return 0; +} + +static int setShadowColor (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user && lua_gettop(L)>=2 ){ + UIView* view = (__bridge UIView *)(user->object); + UIColor* color = lv_getColorFromStack(L, 2); + [view.layer setShadowColor:color.CGColor]; + lua_pushvalue(L,1); + return 1; + } + return 0; +} + + +#pragma -mark borderColor + +UIColor* lv_UIColorFromRGBA(NSInteger rgbValue, float alphaValue){ + return [UIColor + colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 + green: ((float)((rgbValue & 0x00FF00) >> 8 ))/255.0 + blue: ((float)((rgbValue & 0x0000FF) ))/255.0 + alpha:alphaValue]; + +} + +static int borderColor (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if ( lua_gettop(L)>=2 ) { + UIColor* color = lv_getColorFromStack(L, 2); + view.layer.borderColor = color.CGColor; + lua_pushvalue(L,1); + return 1; + } else { + UIColor* color = [UIColor colorWithCGColor:view.layer.borderColor]; + NSUInteger c = 0; + CGFloat a = 0; + if( lv_uicolor2int(color, &c, &a) ){ + lua_pushnumber(L, c ); + lua_pushnumber(L, a); + return 2; + } + } + } + return 0; +} + +static int borderDash (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + int argN = lua_gettop(L); + if ( argN>=2 ) { + NSMutableArray* arr = [[NSMutableArray alloc] initWithCapacity:argN]; + for( int i=2; i<=argN; i++) { + if( lua_type(L, i)==LUA_TNUMBER ) { + int v = lua_tonumber(L, i); + [arr addObject:[NSNumber numberWithInt:v]]; + } + } + //虚线边框 + if( arr.count>0 ) { + [view lv_createShapelayer:arr]; + } else { + view.lv_shapeLayer.lineDashPattern = nil; + [view.lv_shapeLayer removeFromSuperlayer]; + view.lv_shapeLayer = nil; + } + return 0; + } else { + NSArray* numbers = view.lv_shapeLayer.lineDashPattern; + for( int i=0; iobject); + if( view ){ + if( lua_gettop(L)>=2 ) { + BOOL yes = lua_toboolean(L, 2); + view.clipsToBounds = yes; + return 0; + } else { + lua_pushnumber(L, view.clipsToBounds ); + return 1; + } + } + } + return 0; +} + +static int adjustSize(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + [view sizeToFit]; + } + } + return 0; +} + +#pragma -mark transformRoteAndScale + +typedef void (TransformSetter)(CATransform3D *, CGFloat); +typedef double (TransformGetter)(CATransform3D *); + +static int transformFuncOneArg(lua_State *L, TransformSetter setter, TransformGetter getter) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + UIView *view = (__bridge UIView *)(user->object); + + if( user ){ + if ( lua_gettop(L) > 1 ) { + CALayer* layer = view.layer; + + double x = lua_tonumber(L, 2); + CATransform3D t = layer.transform; + setter(&t, x); + + layer.transform = t; + + lua_pop(L, 1); + return 1; + } else { + CALayer* layer = view.layer.presentationLayer ?: view.layer; + + CATransform3D t = layer.transform; + double x = getter(&t); + + lua_pushnumber(L, x); + return 1; + } + } + return 0; +} + +static int transformFuncTwoArg(lua_State *L, + TransformSetter xsetter, TransformSetter ysetter, + TransformGetter xgetter, TransformGetter ygetter) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + UIView *view = (__bridge UIView *)(user->object); + + if( user ){ + int argNum = lua_gettop(L); + if ( argNum > 1 ) { + CALayer* layer = view.layer; + + double x = lua_tonumber(L, 2), y = lua_tonumber(L, 3); + CATransform3D t = layer.transform; + xsetter(&t, x); + ysetter(&t, y); + + layer.transform = t; + + lua_pop(L, 1); + return 1; + } else { + CALayer* layer = view.layer.presentationLayer ?: view.layer; + + CATransform3D t = layer.transform; + double x = xgetter(&t), y = ygetter(&t); + + lua_pushnumber(L, x); + lua_pushnumber(L, y); + return 2; + } + } + return 0; +} + +inline static double degreeToRadian(double d) { + return d * M_PI / 180; +} + +inline static double radianToDegree(double r) { + return r / M_PI * 180; +} + +static void transform3DSetDegreeRotation(CATransform3D *t, CGFloat v) { + double r = degreeToRadian(v); + CATransform3DSetRotation(t, r); +} + +static double transform3DGetDegreeRotation(CATransform3D *t) { + double r = CATransform3DGetRotation(t); + return radianToDegree(r); +} + +static int rotationZ (lua_State *L) { + return transformFuncOneArg(L, transform3DSetDegreeRotation, + transform3DGetDegreeRotation); +} + +static int rotationX (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( lua_gettop(L)>=2 ) { + CALayer *layer = view.layer; + + double angle = degreeToRadian(lua_tonumber(L, 2)); + layer.transform = CATransform3DMakeRotation(angle, 1, 0, 0); + + lua_pop(L, 1); + return 1; + } else { + CALayer *layer = view.layer.presentationLayer ?: view.layer; + + double angle = [[layer valueForKeyPath:@"transform.rotation.x"] doubleValue]; + lua_pushnumber(L, angle); + return 1; + } + } + return 0; +} + +static int rotationY (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( lua_gettop(L)>=2 ) { + CALayer *layer = view.layer; + + double angle = degreeToRadian(lua_tonumber(L, 2)); + layer.transform = CATransform3DMakeRotation(angle, 0, 1, 0); + + lua_pop(L, 1); + return 1; + } else { + CALayer *layer = view.layer.presentationLayer ?: view.layer; + + double angle = [[layer valueForKeyPath:@"transform.rotation.y"] doubleValue]; + lua_pushnumber(L, angle); + return 1; + } + } + return 0; +} + +static int scale (lua_State *L) { + if (lua_gettop(L) == 2) { + lua_pushnumber(L, lua_tonumber(L, 2)); + } + return transformFuncTwoArg(L, CATransform3DSetScaleX, CATransform3DSetScaleY, + CATransform3DGetScaleX, CATransform3DGetScaleY); +} + +static int scaleX (lua_State *L) { + return transformFuncOneArg(L, CATransform3DSetScaleX, CATransform3DGetScaleX); +} + +static int scaleY (lua_State *L) { + return transformFuncOneArg(L, CATransform3DSetScaleY, CATransform3DGetScaleY); +} + +static int translation (lua_State *L) { + return transformFuncTwoArg(L, CATransform3DSetTranslationX, CATransform3DSetTranslationY, + CATransform3DGetTranslationX, CATransform3DGetTranslationY); +} + +static int translationX (lua_State *L) { + return transformFuncOneArg(L, CATransform3DSetTranslationX, CATransform3DGetTranslationX); +} + +static int translationY (lua_State *L) { + return transformFuncOneArg(L, CATransform3DSetTranslationY, CATransform3DGetTranslationY); +} + +static int transform3D (lua_State *L) { + LVUserDataInfo* user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if ( lua_gettop(L)>=2 ) { + LVUserDataInfo* userdata = (LVUserDataInfo *)lua_touserdata(L, 2); + if ( LVIsType(userdata, Transform3D)) { + CALayer *layer = view.layer; + + LVTransform3D* tran = (__bridge LVTransform3D *)(userdata->object); + layer.transform = tran.transform; + + lua_pop(L, 1); + return 1; + } + } else { + CALayer *layer = view.layer.presentationLayer ?: view.layer; + + CATransform3D t = layer.transform; + [LVTransform3D pushTransform3D:L transform3d:t]; + return 1; + } + } + return 0; +} + +static int startAnimation(lua_State *L) { + LVUserDataInfo* vdata = (LVUserDataInfo *)lua_touserdata(L, 1); + if( vdata ){ + LVUserDataInfo *adata = NULL; + LVAnimator *animator = nil; + int top = lua_gettop(L); + for (int i = 2; i <= top; ++i) { + adata = lua_touserdata(L, i); + if (!LVIsType(adata, Animator)) { + continue; + } + + animator = (__bridge LVAnimator *)(adata->object); + if (animator == nil) { + continue; + } + + animator.target = (__bridge UIView *)(vdata->object); + [animator start]; + } + } + + return 0; +} + +static int stopAnimation(lua_State *L) { + LVUserDataInfo* user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + [view.layer removeAllAnimations]; + } + + return 0; +} + +#pragma -mark anchorPoint +static int anchorPoint (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( lua_gettop(L)>=2 ) { + double x = lua_tonumber(L, 2);// 2 + double y = lua_tonumber(L, 3);// 3 + view.layer.anchorPoint = CGPointMake(x, y); + return 0; + } else { + CGPoint p = view.layer.anchorPoint; + lua_pushnumber(L, p.x ); + lua_pushnumber(L, p.y ); + return 2; + } + } + return 0; +} + +int lv_setCallbackByKey(lua_State *L, const char* key, BOOL addGesture) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + if ( lua_gettop(L)>=2 ) { + UIView* view = (__bridge UIView *)(user->object); + if( addGesture ) { + [view lv_callbackAddClickGesture];// 检测是否添加手势 + } + lua_checkstack(L, 8); + lua_pushvalue(L, 1); + lv_pushUDataRef(L, USERDATA_KEY_DELEGATE); + if( lua_type(L, -1)==LUA_TNIL ) { + lua_settop(L, 2); + lua_pushvalue(L, 1); + lua_createtable(L, 0, 0); + lv_udataRef(L, USERDATA_KEY_DELEGATE ); + + lua_settop(L, 2); + lua_pushvalue(L, 1); + lv_pushUDataRef(L, USERDATA_KEY_DELEGATE); + } + lua_pushvalue(L, 2); + if( key==NULL && lua_type(L, -1) == LUA_TTABLE ) { + // 如果是表格 设置每个Key + lua_pushnil(L); + while (lua_next(L, -2)) + { + NSString* key = lv_paramString(L, -2); + lua_setfield(L, -4, key.UTF8String); + } + } else { + // 如果是方法设置默认key + lua_setfield(L, -2, (key ? key:STR_ON_CLICK) ); + } + return 0; + } else { + lv_pushUDataRef(L, USERDATA_KEY_DELEGATE); + if ( key ) { + if ( lua_type(L, -1)==LUA_TTABLE ) { + lua_getfield(L, -1, key); + } else { + lua_pushnil(L); + } + } + return 1; + } + } + return 0; +} + +static int callback (lua_State *L) { + return lv_setCallbackByKey(L, NULL, YES); +} + +static int onLayout (lua_State *L) { + return lv_setCallbackByKey(L, STR_ON_LAYOUT, NO); +} + +static int onClick (lua_State *L) { + return lv_setCallbackByKey(L, STR_ON_CLICK, YES); +} + +static void removeOnTouchEventGesture(UIView* view){ + NSArray< UIGestureRecognizer *> * gestures = view.gestureRecognizers; + for( LVGesture* g in gestures ) { + if( [g isKindOfClass:[LVGesture class]] ) { + if( g.onTouchEventCallback ) { + [view removeGestureRecognizer:g]; + break; + } + } + } +} + +static int onTouch (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + int ret = lv_setCallbackByKey(L, STR_ON_TOUCH, NO); + if( user ){ + __weak UIView* view = (__bridge UIView *)(user->object); + removeOnTouchEventGesture(view); + + LVGesture* gesture = [[LVGesture alloc] init:L]; + gesture.onTouchEventCallback = ^(LVGesture* gesture, int argN){ + [view lv_callLuaByKey1:@STR_ON_TOUCH key2:nil argN:1]; + }; + [view addGestureRecognizer:gesture]; + } + return ret; +} + +#pragma -mark __gc +static int __gc (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + releaseUserDataView(user); + return 0; +} + +static int __tostring (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + NSString* s = [NSString stringWithFormat:@"%@",view]; + lua_pushstring(L, s.UTF8String); + return 1; + } + } + return 0; +} + +- (void) layoutSubviews{ + [super layoutSubviews]; + [self lv_alignSubviews]; + [self lv_callLuaByKey1:@STR_ON_LAYOUT]; +} + +static int releaseObject(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + //[LVUtil unregistry:L key:(__bridge id)user->view]; + UIView* view = (__bridge UIView *)(user->object); + [view removeFromSuperview]; + [view.layer removeFromSuperlayer]; + if( [view isKindOfClass:[LuaViewCore class]] ){ + LuaViewCore* lView = (LuaViewCore*)view; + lView.l = NULL; + G(L)->ud = NULL; + [lView releaseLuaView]; + } + } + return 0; +} +//--------------------------- +//static int __newindex (lua_State *L) { +// NSString* key = lv_paramString(L, 2); +// if( key ){ +// lv_getmetatable( L, 1 ); +// lua_getfield(L, -1, key.UTF8String); +// if( lua_type(L, -1)==LUA_TFUNCTION ) { +// lua_CFunction function = lua_tocfunction(L,-1); +// if( function ) { +// lua_remove(L, 2); +// lua_settop(L, 2); +// return function(L); +// } +// } +// } +// LVError(@"not found property: %@", key); +// return 0; +//} + + +static int align (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + int argNum = lua_gettop(L); + if ( argNum>=2 ) { + NSUInteger align = 0; + for (int i=2; i<=argNum; i++ ) { + align |= (NSUInteger)lua_tointeger(L, i); + } + view.lv_align = align; + [view lv_alignSelfWithSuperRect:view.superview.frame]; + return 0; + } else { + lua_pushnumber(L, view.lv_align ); + return 1; + } + } + } + return 0; +} + +static int alignInfo (lua_State *L, int align) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + view.lv_align = align; + [view lv_alignSelfWithSuperRect:view.superview.frame]; + } + } + return 0; +} + +static int alignLeft(lua_State *L ) { + return alignInfo(L, LV_ALIGN_LEFT); +} + +static int alignRight(lua_State *L ) { + return alignInfo(L, LV_ALIGN_RIGHT); +} + +static int alignTop(lua_State *L ) { + return alignInfo(L, LV_ALIGN_TOP); +} + +static int alignBottom(lua_State *L ) { + return alignInfo(L, LV_ALIGN_BOTTOM); +} + +static int alignCenter(lua_State *L ) { + return alignInfo(L, LV_ALIGN_H_CENTER|LV_ALIGN_V_CENTER); +} + +static int effects (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if ( [view isKindOfClass:[UIView class]] ) { + int effectType = lua_tonumber(L, 2); + switch (effectType) { + case EFFECT_NONE: + break; + case EFFECT_CLICK:{ + NSInteger color = lua_tonumber(L, 3); + CGFloat alpha = lua_tonumber(L, 4); + [view lv_effectClick:color alpha:alpha]; + break; + } + case EFFECT_PARALLAX:{ + CGFloat dx = lua_tonumber(L, 3); + CGFloat dy = lua_tonumber(L, 4); + [view lv_effectParallax:dx dy:dy]; + break; + } + default: + break; + } + } + } + return 0; +} + +static int invalidate (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if ( [view isKindOfClass:[UIView class]] ) { + [view setNeedsDisplay]; + } + } + return 0; +} + +static const struct luaL_Reg baseMemberFunctions [] = { + {"hidden", hidden }, + // visible + + {"hide", hide },//__deprecated_msg("Use hidden") + {"isHide", isHide },//__deprecated_msg("Use hidden") + + {"show", show },//__deprecated_msg("Use visible") + {"isShow", isShow },//__deprecated_msg("Use visible") + + {"enabled", userInteractionEnabled }, + {"clipsToBounds", clipsToBounds },// for IOS + + {"backgroundColor", backgroundColor }, + + {"alpha", alpha }, + + {"cornerRadius", cornerRadius }, + + {"borderWidth", borderWidth }, + + {"borderColor", borderColor }, + {"borderDash", borderDash }, + + {"shadowPath", setShadowPath }, // for IOS + {"masksToBounds", setMasksToBounds },// for IOS + {"shadowOffset", setShadowOffset },// for IOS + {"shadowRadius", setShadowRadius },// for IOS + {"shadowOpacity", setShadowOpacity },// for IOS + {"shadowColor", setShadowColor },// for IOS + + {"frame", frame }, + + {"size", size }, + + {"origin", origin },//__deprecated_msg("Use xy") + {"xy", origin }, + + {"center", center}, + {"centerX", centerX}, + {"centerY", centerY}, + + {"x", x}, + {"y", y}, + + {"left", x}, + {"top", y}, + {"bottom", bottom}, + {"right", right}, + + {"width", width}, + {"height", height}, + + {"adjustSize", adjustSize},// 带讨论 + + {"addGesture", addGestureRecognizer }, //__deprecated_msg("Use onTouch") + {"removeGesture", removeGestureRecognizer }, //__deprecated_msg("Use onTouch") + + {"addView", addSubview }, + {"children", children }, + {"removeFromSuper", removeFromSuperview }, + {"removeFromParent", removeFromSuperview }, //__deprecated_msg("Use removeFromSuper") + {"removeAllViews", removeAllSubviews }, + //{"bringToFront", bringToFront}, + + {"rotation", rotationZ }, + {"rotationX", rotationX }, + {"rotationY", rotationY }, + {"rotationZ", rotationZ },//__deprecated_msg("Use rotation") + + {"scale", scale }, + {"scaleX", scaleX }, + {"scaleY", scaleY }, + + {"translation", translation }, + {"translationX", translationX }, + {"translationY", translationY }, + + {"anchorPoint", anchorPoint }, + + {"callback", callback }, + {"onLayout", onLayout }, + {"onClick", onClick }, + {"onTouch", onTouch }, + // onShow + // onHide + // onLongClick + + {"hasFocus", isFirstResponder }, + {"requestFocus", becomeFirstResponder }, + {"cancelFocus", resignFirstResponder }, //__deprecated_msg("Use hidden") + {"clearFocus", resignFirstResponder }, + + {"transform3D", transform3D }, //__deprecated_msg("Use") + + {"startAnimation", startAnimation }, + {"stopAnimation", stopAnimation }, + + + {"__gc", __gc }, + + {"__tostring", __tostring}, + + // {"__newindex", __newindex }, + + {"flexChildren", flxChildViews }, + {"flxLayout", flxLayout },// 安卓无 + {"flexCss", flxBindingInlineCSS}, + + // align + {"align", align}, + {"alignLeft", alignLeft}, + {"alignRight", alignRight}, + {"alignTop", alignTop}, + {"alignBottom", alignBottom}, + {"alignCenter", alignCenter}, + // padding + // margin + + // getNativeView + {"getNativeView", getNativeView}, //__deprecated_msg("Use nativeView") + {"nativeView", getNativeView}, + + {"effects",effects}, // IOS 视差效果 + {"layerMode",layerMode}, // for IOS + + {"invalidate",invalidate}, + {NULL, NULL} +}; + +static const struct luaL_Reg luaViewMemberFunctions [] = { + {"release", releaseObject}, + {NULL, NULL }, +}; + ++(const luaL_Reg*) baseMemberFunctions{ + return baseMemberFunctions; +} + +#pragma -mark UIView +static int lvNewView (lua_State *L) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVBaseView class]]; + + LVBaseView* view = [[c alloc] init:L]; + { + NEW_USERDATA(userData, View); + userData->object = CFBridgingRetain(view); + view.lv_userData = userData; + + luaL_getmetatable(L, META_TABLE_UIView ); + lua_setmetatable(L, -2); + + LuaViewCore* luaviewCore = LV_LUASTATE_VIEW(L); + if( luaviewCore ){ + [luaviewCore containerAddSubview:view]; + } + } + return 1; /* new userdatum is already on the stack */ +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewView globalName:globalName defaultName:@"View"]; + + lv_createClassMetaTable(L, META_TABLE_UIView); + + luaL_openlib(L, NULL, [LVBaseView baseMemberFunctions], 0); + + + lv_createClassMetaTable(L, META_TABLE_LuaView); + luaL_openlib(L, NULL, [LVBaseView baseMemberFunctions], 0); + luaL_openlib(L, NULL, luaViewMemberFunctions, 0); + return 1; +} + +//---------------------------------------------------------------------------------------- + +-(NSString*) description{ + return [NSString stringWithFormat:@"", (int)[self hash], NSStringFromCGRect(self.frame) ]; +} + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVButton.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVButton.h new file mode 100644 index 00000000..c26d5a99 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVButton.h @@ -0,0 +1,28 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" +#import "LView.h" + + +@interface LVButton : UIButton + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; +@property(nonatomic,assign) NSUInteger lv_align; +@property(nonatomic,strong) CAShapeLayer* lv_shapeLayer; + +-(id) init:(lua_State*) l; +-(void) setWebImageUrl:(NSString*)url forState:(UIControlState) state finished:(LVLoadFinished) finished; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +-(void) lvButtonCallBack; + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVButton.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVButton.m new file mode 100644 index 00000000..ada32ee8 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVButton.m @@ -0,0 +1,313 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVButton.h" +#import "LVBaseView.h" +#import "LVImage.h" +#import "LVUtil.h" +#import "LView.h" +#import "LVStyledString.h" +#import "UIView+LuaView.h" +#import "NSObject+LuaView.h" +#import "LVHeads.h" + +@interface LVButton() +@end + +@implementation LVButton + +-(id) init:(lua_State*) l{ + self = [super init]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + [self addTarget:self action:@selector(lvButtonCallBack) forControlEvents:UIControlEventTouchUpInside]; + + // 默认黑色字 + [self setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; + self.clipsToBounds = YES; + self.titleLabel.font = [UIFont systemFontOfSize:14];// 默认字体大小 + } + return self; +} + +-(void) dealloc{ +} + +-(NSString*) description{ + return [NSString stringWithFormat:@"", (int)[self hash], NSStringFromCGRect(self.frame) ]; +} + +-(void) lvButtonCallBack{ + [self lv_buttonCallBack]; +} + +-(void) setWebImageUrl:(NSString*)url forState:(UIControlState) state finished:(LVLoadFinished) finished{ +} + +-(void) setImageUrl:(NSString*) url placeholder:(UIImage *)placeholder state:(UIControlState) state { + if( [LVUtil isExternalUrl:url] ){ + [self setWebImageUrl:url forState:state finished:nil]; + } else { + if( url ) { + LVBundle* bundle = self.lv_luaviewCore.bundle; + [self setImage:[bundle imageWithName:url] forState:state]; + } + } +} + +#pragma -mark Button +static int lvNewButton (lua_State *L) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVButton class]]; + + { + LVButton* button = [[c alloc] init:L]; + { + NEW_USERDATA(userData, View); + userData->object = CFBridgingRetain(button); + button.lv_userData = userData; + + luaL_getmetatable(L, META_TABLE_UIButton ); + lua_setmetatable(L, -2); + } + LuaViewCore* father = LV_LUASTATE_VIEW(L); + if( father ){ + [father containerAddSubview:button]; + } + } + return 1; /* new userdatum is already on the stack */ +} + +static int selected (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVButton* button = (__bridge LVButton *)(user->object); + if( button ){ + if ( lua_gettop(L)>=2 ) { + BOOL yes = lua_toboolean(L, 2); + button.selected = yes; + return 0; + } else { + lua_pushboolean(L, button.selected ); + return 1; + } + } + } + return 0; +} + +static int enabled (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVButton* button = (__bridge LVButton *)(user->object); + if ( lua_gettop(L)>=2 ){ + BOOL yes = lua_toboolean(L, 2); + button.enabled = yes; + return 0; + } else { + lua_pushboolean(L, button.enabled); + return 1; + } + } + return 0; +} + +static int image (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + NSString* normalImage = lv_paramString(L, 2);// 2 + NSString* hightLightImage = lv_paramString(L, 3);// 2 + //NSString* disableImage = lv_paramString(L, 4);// 2 + //NSString* selectedImage = lv_paramString(L, 5);// 2 + LVButton* button = (__bridge LVButton *)(user->object); + if( [button isKindOfClass:[LVButton class]] ){ + [button setImageUrl:normalImage placeholder:nil state:UIControlStateNormal]; + [button setImageUrl:hightLightImage placeholder:nil state:UIControlStateHighlighted]; + //[button setImageUrl:disableImage placeholder:nil state:UIControlStateDisabled]; + //[button setImageUrl:selectedImage placeholder:nil state:UIControlStateSelected]; + + lua_pushvalue(L, 1); + return 1; + } + } + return 0; +} + +static const UIControlState g_states[] = {UIControlStateNormal,UIControlStateHighlighted,UIControlStateDisabled,UIControlStateSelected}; +static int title (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVButton* button = (__bridge LVButton *)(user->object); + if( [button isKindOfClass:[LVButton class]] ){ + int num = lua_gettop(L); + if ( num>=2 ) {// setValue + for (int i=2,j=0; i<=num && j<4; i++ ){ + if ( lua_type(L, i) == LUA_TSTRING ) { + NSString* text1 = lv_paramString(L, i); + if( text1 ) { + [button setTitle:text1 forState:g_states[j++]]; + } + } else if( lua_type(L, 2)==LUA_TUSERDATA ){ + LVUserDataInfo * user2 = lua_touserdata(L, 2); + if( user2 && LVIsType(user2, StyledString) ) { + LVStyledString* attString = (__bridge LVStyledString *)(user2->object); + [button setAttributedTitle:attString.mutableStyledString forState:g_states[j++] ]; + [button.titleLabel sizeToFit]; + } + }else if ( lua_type(L, i) == LUA_TNUMBER ) { + float f = lua_tonumber(L, i); + [button setTitle:[NSString stringWithFormat:@"%f",f] forState:g_states[j++]]; + } + } + return 0; + } else { // getValue + for (int j=0; j<4; j++ ){ + NSString* text1 = [button titleForState:g_states[j++] ]; + lua_pushstring(L, text1.UTF8String); + } + return 4; + } + } + } + return 0; +} + +static int titleColor (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVButton* button = (__bridge LVButton *)(user->object); + if( [button isKindOfClass:[LVButton class]] ){ + int num = lua_gettop(L); + if ( num>=2 ) { + for (int i=2,j=0; i<=num && j<4; i++ ){ + if( lua_type(L, i)==LUA_TNUMBER ) { + UIColor* c = lv_getColorFromStack(L, i); + [button setTitleColor:c forState:g_states[j++]]; + } + } + return 0; + } else { + int retvalueNum = 0; + for (int j=0; j<4; j++ ){ + UIColor* c = [button titleColorForState:g_states[j++] ]; + NSUInteger color=0 ; + CGFloat a = 0; + if( lv_uicolor2int(c, &color, &a) ){ + lua_pushnumber(L, color); + lua_pushnumber(L, a); + retvalueNum += 2; + } + } + return retvalueNum; + } + } + } + return 0; +} + +static int font (lua_State *L) { + LuaViewCore* luaView = LV_LUASTATE_VIEW(L); + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVButton* view = (__bridge LVButton *)(user->object); + if( [view isKindOfClass:[LVButton class]] ){ + int num = lua_gettop(L); + if( num>=2 ) { + if( num>=3 && lua_type(L, 2)==LUA_TSTRING ) { + NSString* fontName = lv_paramString(L, 2); + float fontSize = lua_tonumber(L, 3); + view.titleLabel.font = [LVUtil fontWithName:fontName size:fontSize bundle:luaView.bundle]; + } else { + float fontSize = lua_tonumber(L, 2); + view.titleLabel.font = [UIFont systemFontOfSize:fontSize]; + } + return 0; + } else { + UIFont* font = view.titleLabel.font; + lua_pushstring(L, font.fontName.UTF8String); + lua_pushnumber(L, font.pointSize); + return 2; + } + } + } + return 0; +} + +static int fontSize (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVButton* view = (__bridge LVButton *)(user->object); + if( [view isKindOfClass:[LVButton class]] ){ + int num = lua_gettop(L); + if( num>=2 ) { + float fontSize = lua_tonumber(L, 2); + view.titleLabel.font = [UIFont systemFontOfSize:fontSize]; + return 0; + } else { + UIFont* font = view.titleLabel.font; + lua_pushnumber(L, font.pointSize); + return 1; + } + } + } + return 0; +} + +//static int showsTouchWhenHighlighted(lua_State *L) { +// LVUserDataView * user = (LVUserDataView *)lua_touserdata(L, 1); +// if( user ){ +// LVButton* button = (__bridge LVButton *)(user->view); +// if( lua_gettop(L)<=1 ) { +// lua_pushboolean(L, button.showsTouchWhenHighlighted ); +// return 1; +// } else { +// BOOL yes = lua_toboolean(L, 2); +// button.showsTouchWhenHighlighted = yes; +// return 0; +// } +// } +// return 0; +//} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewButton globalName:globalName defaultName:@"Button"]; + + const struct luaL_Reg memberFunctions [] = { + {"image", image}, + + {"font", font}, + {"fontSize", fontSize}, + {"textSize", fontSize}, // __deprecated_msg("Use lines") + + + {"titleColor", titleColor}, // __deprecated_msg("Use lines") + {"title", title}, // __deprecated_msg("Use lines") + {"textColor", titleColor}, + {"text", title}, + + {"selected", selected}, // __deprecated_msg("Use lines") + {"enabled", enabled}, // __deprecated_msg("Use lines") + + //{"showsTouchWhenHighlighted", showsTouchWhenHighlighted}, + {NULL, NULL} + }; + + lv_createClassMetaTable(L,META_TABLE_UIButton); + + luaL_openlib(L, NULL, [LVBaseView baseMemberFunctions], 0); + luaL_openlib(L, NULL, memberFunctions, 0); + + const char* keys[] = { "addView", NULL};// 移除多余API + lv_luaTableRemoveKeys(L, keys ); + + return 1; +} + + +//---------------------------------------------------------------------------------------- + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCanvas.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCanvas.h new file mode 100644 index 00000000..7a324e3d --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCanvas.h @@ -0,0 +1,28 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import +#import "LVHeads.h" + +@interface LVCanvas : NSObject + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; + +@property(nonatomic,assign) CGContextRef contentRef; + +@property(nonatomic,assign) CGPathDrawingMode drawingMode; + +-(id) init:(lua_State*) l; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + ++(LVCanvas*) createLuaCanvas:(lua_State *)L contentRef:(CGContextRef) contentRef; + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCanvas.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCanvas.m new file mode 100644 index 00000000..c2140faf --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCanvas.m @@ -0,0 +1,733 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVCanvas.h" +#import "LView.h" +#import "LVBundle.h" +#import "LVData.h" +#import "LVImage.h" + +#define LV_ANGLE_RADIANS(angle) (M_PI*angle/180) + +@interface LVCanvas () +@property(nonatomic,strong) UIColor* color; +@property(nonatomic,assign) CGFloat strokeWidth; +@property(nonatomic,assign) CGFloat alpha; +@property(nonatomic,assign) UIFont* font; +@property(nonatomic,assign) CGAffineTransform concatCTM; +@property(nonatomic,assign) CGFloat scaleX; +@property(nonatomic,assign) CGFloat scaleY; +@property(nonatomic,assign) CGFloat skewX; +@property(nonatomic,assign) CGFloat skewY; +@property(nonatomic,assign) CGPoint translate; +@end + +@implementation LVCanvas + + +-(id) init:(lua_State *)l{ + self = [super init]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + } + return self; +} + +-(void) setContentRef:(CGContextRef)contentRef{ + _contentRef = contentRef; + [self resetPaint]; +} + +-(id) lv_nativeObject{ + return self; +} + +-(void) setColor:(UIColor *)color{ + _color = color; + if( _contentRef ) { + CGContextSetStrokeColorWithColor(_contentRef,self.color.CGColor); + CGContextSetFillColorWithColor(_contentRef,self.color.CGColor); + } +} + +-(void) setAlpha:(CGFloat)alpha{ + _alpha = alpha; + if (_contentRef) { +// CGFloat r = 0; +// CGFloat g = 0; +// CGFloat b = 0; +// CGFloat a = 0; +// if( [_color getRed:&r green:&g blue:&b alpha:&a] ){ +// CGContextSetRGBStrokeColor(_contentRef, r, g, b, _alpha); +// CGContextSetRGBFillColor(_contentRef, r, g, b, _alpha); +// } + // 控制左右的绘图alpha + CGContextSetAlpha(_contentRef,alpha); + } +} + +static int nativeObj (lua_State *L) { + LVUserDataInfo * userData = (LVUserDataInfo *)lua_touserdata(L, 1); + if( userData ){ + LVCanvas* view = (__bridge LVCanvas *)(userData->object); + if( view ){ + id object = [view lv_nativeObject]; + lv_pushNativeObjectWithBox(L, object); + return 1; + } + } + return 0; +} + +static int canvas_drawPoint (lua_State *L) { + LVUserDataInfo * user1 = (LVUserDataInfo *)lua_touserdata(L, 1); + LVCanvas* canvas = (__bridge LVCanvas *)(user1->object); + if( LVIsType(user1, Canvas) ){ + CGFloat x1 = lua_tonumber(L, 2); + CGFloat y1 = lua_tonumber(L, 3); + [canvas drawLine:x1-0.5 :y1-0.5 :x1+0.5 :y1+0.5]; + return 1; + } + return 0; +} + +-(void) drawLine:(CGFloat) x1 :(CGFloat)y1 :(CGFloat) x2 :(CGFloat) y2{ + if( _contentRef ) { + CGPoint aPoints[2]; + aPoints[0] = CGPointMake(x1, y1); + aPoints[1] = CGPointMake(x2, y2); + CGContextAddLines(_contentRef, aPoints, 2); + CGContextDrawPath(_contentRef, kCGPathStroke); //根据坐标绘制路径 + } +} + +static int canvas_drawLine (lua_State *L) { + LVUserDataInfo * user1 = (LVUserDataInfo *)lua_touserdata(L, 1); + LVCanvas* canvas = (__bridge LVCanvas *)(user1->object); + if( LVIsType(user1, Canvas) ){ + CGFloat x1 = lua_tonumber(L, 2); + CGFloat y1 = lua_tonumber(L, 3); + CGFloat x2 = lua_tonumber(L, 4); + CGFloat y2 = lua_tonumber(L, 5); + [canvas drawLine:x1 :y1 :x2 :y2]; + return 1; + } + return 0; +} + +-(void) drawRect:(CGFloat)x :(CGFloat)y :(CGFloat)w :(CGFloat)h{ + if( _contentRef ) { + CGContextAddRect(_contentRef, CGRectMake(x, y, w, h)); + CGContextDrawPath(_contentRef, self.drawingMode); + } +} + +static int canvas_drawRect (lua_State *L) { + LVUserDataInfo * user1 = (LVUserDataInfo *)lua_touserdata(L, 1); + LVCanvas* canvas = (__bridge LVCanvas *)(user1->object); + if( LVIsType(user1, Canvas) ){ + CGFloat x1 = lua_tonumber(L, 2); + CGFloat y1 = lua_tonumber(L, 3); + CGFloat x2 = lua_tonumber(L, 4); + CGFloat y2 = lua_tonumber(L, 5); + [canvas drawRect:x1 :y1 :x2 :y2]; + return 1; + } + return 0; +} + +-(void) drawRoundRect:(CGFloat) x :(CGFloat)y :(CGFloat)w :(CGFloat)h :(CGFloat)rx :(CGFloat)ry{ + CGContextRef context = _contentRef; + if( context ) { + // 简便起见,这里把圆角半径设置为长和宽平均值的1/10 + CGFloat radius = rx; + + // 获取CGContext,注意UIKit里用的是一个专门的函数 + CGContextRef context = UIGraphicsGetCurrentContext(); + // 移动到初始点 + CGContextMoveToPoint(context,x+ radius,y+ 0); + + // 绘制第1条线和第1个1/4圆弧 + CGContextAddLineToPoint(context, x+ w - radius, y+0); + CGContextAddArc(context, x+w - radius, y+ radius, radius, -0.5 * M_PI, 0.0, 0); + + // 绘制第2条线和第2个1/4圆弧 + CGContextAddLineToPoint(context, x+ w, y+ h - radius); + CGContextAddArc(context, x+ w - radius, y+ h - radius, radius, 0.0, 0.5 * M_PI, 0); + + // 绘制第3条线和第3个1/4圆弧 + CGContextAddLineToPoint(context, x+radius, y+ h); + CGContextAddArc(context, x+ radius, y+ h-radius, radius, 0.5 * M_PI, M_PI, 0); + + // 绘制第4条线和第4个1/4圆弧 + CGContextAddLineToPoint(context, x+ 0, y+ radius); + CGContextAddArc(context, x+ radius, y+ radius, radius, M_PI, 1.5 * M_PI, 0); + + // 闭合路径 + CGContextClosePath(context); + CGContextDrawPath(context, self.drawingMode); + } +} + +static int canvas_drawRoundRect (lua_State *L) { + LVUserDataInfo * user1 = (LVUserDataInfo *)lua_touserdata(L, 1); + LVCanvas* canvas = (__bridge LVCanvas *)(user1->object); + if( LVIsType(user1, Canvas) ){ + CGFloat x = lua_tonumber(L, 2); + CGFloat y = lua_tonumber(L, 3); + CGFloat w = lua_tonumber(L, 4); + CGFloat h = lua_tonumber(L, 5); + CGFloat rx = lua_tonumber(L, 6); + CGFloat ry = lua_tonumber(L, 7); + [canvas drawRoundRect:x :y :w :h :rx :ry]; + return 1; + } + return 0; +} + +-(void) drawEllipse:(CGFloat) x :(CGFloat)y :(CGFloat)w :(CGFloat)h { + CGContextRef context = _contentRef; + if( context && w>=0 && h>= 0 ) { + //画椭圆 + CGContextAddEllipseInRect(context, CGRectMake(x, y, w, h)); //椭圆 + CGContextDrawPath(context, self.drawingMode); + } +} + +-(void) drawText:(NSString *)text :(UIFont *)font :(CGRect)rect{ + CGContextRef context = _contentRef; + if (context && text) { + //写文字 + NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:font,NSFontAttributeName,self.color,NSForegroundColorAttributeName,nil]; + [text drawInRect:rect withAttributes:attributes]; + } +} + +-(void) drawText:(NSString *)text :(UIFont *)font :(CGFloat)x :(CGFloat) y{ + CGContextRef context = _contentRef; + if (context && text) { + //画文字 + NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:font,NSFontAttributeName,self.color,NSForegroundColorAttributeName,nil]; + [text drawAtPoint:CGPointMake(x, y) withAttributes:attributes]; + } +} + +static int canvas_drawEllipse (lua_State *L) { + LVUserDataInfo * user1 = (LVUserDataInfo *)lua_touserdata(L, 1); + LVCanvas* canvas = (__bridge LVCanvas *)(user1->object); + if( LVIsType(user1, Canvas) ){ + CGFloat x = lua_tonumber(L, 2); + CGFloat y = lua_tonumber(L, 3); + CGFloat w = lua_tonumber(L, 4); + CGFloat h = w; + if( lua_type(L, 5)==LUA_TNUMBER ) { + h = lua_tonumber(L, 5); + } + [canvas drawEllipse:x :y :w :h]; + return 1; + } + return 0; +} + +static int canvas_drawCircle (lua_State *L) { + LVUserDataInfo * user1 = (LVUserDataInfo *)lua_touserdata(L, 1); + LVCanvas* canvas = (__bridge LVCanvas *)(user1->object); + if( LVIsType(user1, Canvas) ){ + CGFloat x = lua_tonumber(L, 2); + CGFloat y = lua_tonumber(L, 3); + CGFloat r = lua_tonumber(L, 4); + [canvas drawEllipse:x-r :y-r :r*2 :r*2]; + return 1; + } + return 0; +} + +static int canvas_color (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVCanvas* canvas = (__bridge LVCanvas *)(user->object); + if( lua_gettop(L)>=2 ) { + UIColor* color = lv_getColorFromStack(L, 2); + canvas.color = color; + return 0; + } else { + UIColor* color = canvas.color; + NSUInteger c = 0; + CGFloat a = 0; + if( lv_uicolor2int(color, &c,&a) ){ + lua_pushnumber(L, c ); + lua_pushnumber(L, a); + return 2; + } + } + } + return 0; +} + +-(void) setStrokeWidth:(CGFloat)strokeWidth{ + _strokeWidth = strokeWidth; + if( _contentRef ) { + CGContextSetLineWidth(_contentRef, strokeWidth); + } +} + +static int canvas_strokeWidth (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVCanvas* canvas = (__bridge LVCanvas *)(user->object); + if( lua_gettop(L)>=2 ) { + canvas.strokeWidth = lua_tonumber(L, 2); + return 0; + } else { + lua_pushnumber(L, canvas.strokeWidth ); + return 1; + } + } + return 0; +} + +static int canvas_style (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVCanvas* canvas = (__bridge LVCanvas *)(user->object); + if( lua_gettop(L)>=2 ) { + canvas.drawingMode = lua_tonumber(L, 2); + return 0; + } else { + lua_pushnumber(L, canvas.drawingMode ); + return 1; + } + } + return 0; +} + +-(void) resetPaint{ + [self clipRect:0 :0 :10240 :10240]; + self.color = [UIColor blackColor]; + self.strokeWidth = 0.5; + self.alpha = 1; + self.drawingMode = kCGPathFill; + self.font = [UIFont systemFontOfSize:12]; + [self scale:1 :1]; + [self rotate:0 :0 :0]; + [self translate:0 :0]; + [self skew:0 :0]; +} + +static int canvas_resetPaint (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVCanvas* canvas = (__bridge LVCanvas *)(user->object); + [canvas resetPaint]; + } + return 0; +} + +static int canvas_alpha (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVCanvas* canvas = (__bridge LVCanvas *)(user->object); + if( lua_gettop(L)>=2 ) { + CGFloat alpha = lua_tonumber(L, 2); + canvas.alpha = alpha; + return 0; + } + } + return 0; +} + +static int canvas_textSize (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVCanvas* canvas = (__bridge LVCanvas *)(user->object); + if( lua_gettop(L)>=2 ) { + CGFloat font = lua_tonumber(L, 2); + canvas.font = [UIFont systemFontOfSize:font]; + return 0; + } else { + return 0; + } + } + return 0; +} + +static int canvas_bold (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVCanvas* canvas = (__bridge LVCanvas *)(user->object); + if( lua_gettop(L)>=2 ) { + CGFloat bold = lua_toboolean(L, 2); + if (bold) { + canvas.font = [UIFont boldSystemFontOfSize:canvas.font.pointSize]; + }else{ + canvas.font = [UIFont systemFontOfSize:canvas.font.pointSize]; + } + return 0; + } else { + return 0; + } + } + return 0; +} + +-(void) clipRect:(CGFloat)x :(CGFloat)y :(CGFloat)w :(CGFloat)h{ + if( _contentRef ) { + CGContextClipToRect(_contentRef,CGRectMake(x, y, w, h)); + } +} + +static int canvas_clipRect (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user && lua_gettop(L)>=5 ){ + LVCanvas* canvas = (__bridge LVCanvas *)(user->object); + CGFloat x = lua_tonumber(L, 2); + CGFloat y = lua_tonumber(L, 3); + CGFloat w = lua_tonumber(L, 4); + CGFloat h = lua_tonumber(L, 5); + [canvas clipRect:x :y :w :h]; + } + return 0; +} + +static int drawText (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVCanvas* canvas = (__bridge LVCanvas *)(user->object); + if( lua_gettop(L)>=2 ) { + const char* text = lua_tolstring(L, 2, NULL); + NSString *str = [NSString stringWithCString:text encoding:NSUTF8StringEncoding]; + CGFloat x = lua_tonumber(L, 3); + CGFloat y = lua_tonumber(L, 4); + CGFloat h = canvas.font.lineHeight; + CGFloat leading = canvas.font.leading ; + CGFloat descender = canvas.font.descender; + CGRect rect = CGRectMake(x, y - (h+leading+descender), h * str.length, h ); + [canvas drawText:str :canvas.font :rect]; + return 0; + } else { + return 0; + } + } + return 0; +} + +static int canvas_drawOval (lua_State *L) { + return canvas_drawEllipse(L); +} + +-(void) drawArc:(CGFloat)x :(CGFloat)y :(CGFloat)w :(CGFloat)h :(CGFloat)startAngle :(CGFloat)endAngle :(BOOL) includeCenter{ + if( _contentRef ) { + x += w/2; + y += h/2; + if( includeCenter ) { + CGContextMoveToPoint(_contentRef, x, y); + } + CGContextAddArc(_contentRef, x, y, w/2, LV_ANGLE_RADIANS(startAngle), LV_ANGLE_RADIANS(endAngle), NO); + CGContextClosePath(_contentRef); + CGContextDrawPath(_contentRef, self.drawingMode); + } +} + +static int canvas_drawArc (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + CGFloat x = lua_tonumber(L, 2); + CGFloat y = lua_tonumber(L, 3); + CGFloat w = lua_tonumber(L, 4); + CGFloat h = lua_tonumber(L, 5); + CGFloat startAngle = lua_tonumber(L, 6); + CGFloat endAngle = lua_tonumber(L, 7); + BOOL includeCenter = lua_toboolean(L, 8); + LVCanvas* canvas = (__bridge LVCanvas *)(user->object); + [canvas drawArc:x :y :w :h :startAngle :endAngle :includeCenter]; + } + return 0; +} + +-(void) drawImage:(UIImage*)image :(CGFloat)x :(CGFloat)y :(CGFloat)w :(CGFloat)h { + if( _contentRef && image) { + CGContextSaveGState(_contentRef); + //CGAffineTransform t1 = CGAffineTransformMake(1, self.skewY, self.skewX, 1, 0, 0); + CGAffineTransform t2 = CGAffineTransformMake(1, 0, 0, -1, 0, 0); + //CGAffineTransform t3 = CGAffineTransformConcat(t1, t2); + CGContextConcatCTM(_contentRef, t2 ); + CGContextDrawImage(_contentRef, CGRectMake(x, -y-h , w, h), image.CGImage); + CGContextRestoreGState(_contentRef); + } +} + +static int canvas_drawImage (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVCanvas* canvas = (__bridge LVCanvas *)(user->object); + UIImage* image = nil; + if ( lua_type(L, 2)==LUA_TSTRING ) { + NSString* imageName = lv_paramString(L, 2);// 2 + image = [canvas.lv_luaviewCore.bundle imageWithName:imageName]; + } else if ( lua_type(L, 2)==LUA_TUSERDATA ) { + LVUserDataInfo * userdata = (LVUserDataInfo *)lua_touserdata(L, 2); + if( LVIsType(userdata, View) ){ + LVImage* lvImage = (__bridge LVImage *)(userdata->object); + if( [lvImage isKindOfClass:[LVImage class]] ) { + image = lvImage.image; + } + } else if( LVIsType(userdata, Data) ) { + LVData* lvdata = (__bridge LVData *)(userdata->object); + image = [[UIImage alloc] initWithData:lvdata.data]; + } + } + if( image ) { + CGFloat x = lua_tonumber(L, 3); + CGFloat y = lua_tonumber(L, 4); + CGFloat w = lua_tonumber(L, 5); + CGFloat h = lua_tonumber(L, 6); + [canvas drawImage:image :x :y :w :h]; + } + } + return 0; +} + +-(void) saveGState { + if( _contentRef ) { + CGContextSaveGState(_contentRef); + } +} + +static int canvas_save (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVCanvas* canvas = (__bridge LVCanvas *)(user->object); + [canvas saveGState]; + } + return 0; +} + +-(void) restoreGState { + if( _contentRef ) { + CGContextRestoreGState(_contentRef); + } +} + +static int canvas_restore (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVCanvas* canvas = (__bridge LVCanvas *)(user->object); + [canvas restoreGState]; + } + return 0; +} + +-(void) rotate:(CGFloat) angle :(CGFloat)x :(CGFloat) y{ + if( _contentRef ) { + CGContextTranslateCTM(_contentRef, x, y); + CGContextRotateCTM(_contentRef,LV_ANGLE_RADIANS(angle) ); + CGContextTranslateCTM(_contentRef, -x, -y); + } +} + +static int canvas_rotate (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVCanvas* canvas = (__bridge LVCanvas *)(user->object); + CGFloat angle = lua_tonumber(L, 2); + CGFloat x = 0; + if( lua_type(L, 3) ) { + x = lua_tonumber(L, 3); + } + CGFloat y = 0; + if( lua_type(L, 4) ) { + y = lua_tonumber(L, 4); + } + [canvas rotate:angle :x :y];; + } + return 0; +} + +-(void) skew:(CGFloat)sx :(CGFloat)sy { + if( _contentRef ) { + self.skewX = sx; + self.skewY = sy; + CGAffineTransform transform = CGAffineTransformMake(1, sy, sx, 1, 0, 0); + CGContextConcatCTM(_contentRef,transform); + } +} + +-(void) setConcatCTM:(CGAffineTransform) transform{ + CGContextConcatCTM(_contentRef,transform); +} + +-(CGAffineTransform) concatCTM{ + return CGContextGetCTM(_contentRef); +} + +static int canvas_skew (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVCanvas* canvas = (__bridge LVCanvas *)(user->object); + CGFloat sx = lua_tonumber(L, 2); + CGFloat sy = 0; + if (lua_type(L, 3)==LUA_TNUMBER ) { + sy = lua_tonumber(L, 3); + } + [canvas skew:sx :sy]; + } + return 0; +} + +-(void) scale:(CGFloat)scaleX :(CGFloat)scaleY { + if( _contentRef ) { + self.scaleX = scaleX; + self.scaleY = scaleY; + CGContextScaleCTM(_contentRef, scaleX, scaleY); + } +} + +static int canvas_scale (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVCanvas* canvas = (__bridge LVCanvas *)(user->object); + CGFloat scaleX = lua_tonumber(L, 2); + CGFloat scaleY = scaleX; + if( lua_type(L, 3)==LUA_TNUMBER ) { + scaleY = lua_tonumber(L, 3); + } + [canvas scale:scaleX :scaleY]; + } + return 0; +} + +-(void) translate:(CGFloat)x :(CGFloat)y { + self.translate = CGPointMake(x, y); + if( _contentRef ) { + CGContextTranslateCTM(_contentRef, x, y); + } +} + +static int canvas_translate (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVCanvas* canvas = (__bridge LVCanvas *)(user->object); + CGFloat x = lua_tonumber(L, 2); + CGFloat y = lua_tonumber(L, 3); + [canvas translate:x :y]; + } + return 0; +} + +static void releaseCanvasUserData(LVUserDataInfo* user){ + if( user && user->object ){ + LVCanvas* canvas = CFBridgingRelease(user->object); + user->object = NULL; + if( canvas ){ + canvas.lv_userData = NULL; + canvas.lv_luaviewCore = nil; + canvas.contentRef = nil; + } + } +} + +static int lvCanvasGC (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + releaseCanvasUserData(user); + return 0; +} + +static int lvNewCanvas (lua_State *L) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVCanvas class]]; + + LVCanvas* canvas = [[c alloc] init:L]; + + { + NEW_USERDATA(userData, Canvas); + userData->object = CFBridgingRetain(canvas); + canvas.lv_userData = userData; + + luaL_getmetatable(L, META_TABLE_Canvas ); + lua_setmetatable(L, -2); + } + return 1; +} + ++(LVCanvas*) createLuaCanvas:(lua_State *)L contentRef:(CGContextRef) contentRef{ + LVCanvas* lvCanvas = [[LVCanvas alloc] init:L]; + lvCanvas.contentRef = contentRef; + { + NEW_USERDATA(userData, Canvas); + userData->object = CFBridgingRetain(lvCanvas); + lvCanvas.lv_userData = userData; + + luaL_getmetatable(L, META_TABLE_Canvas ); + lua_setmetatable(L, -2); + } + return lvCanvas; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewCanvas globalName:globalName defaultName:@"Canvas"]; + + const struct luaL_Reg memberFunctions [] = { + {"__gc", lvCanvasGC }, + {"nativeObj", nativeObj}, + + // size + // font + + {"drawPoint",canvas_drawPoint}, + {"drawLine",canvas_drawLine}, + {"drawRect",canvas_drawRect}, + {"drawRoundRect",canvas_drawRoundRect}, + {"drawCircle",canvas_drawCircle}, + {"drawEllipse",canvas_drawEllipse}, //__deprecated_msg("Use rotation") + {"drawText",drawText}, + {"drawOval",canvas_drawOval}, + {"drawArc",canvas_drawArc}, + {"drawImage",canvas_drawImage}, + + {"color",canvas_color}, + {"alpha",canvas_alpha}, + {"strokeWidth",canvas_strokeWidth}, + {"style",canvas_style}, + {"textSize",canvas_textSize}, + + {"resetPaint",canvas_resetPaint}, + {"save",canvas_save}, + {"restore",canvas_restore}, + + {"rotate",canvas_rotate}, + {"skew",canvas_skew}, + {"scale",canvas_scale}, + {"translate",canvas_translate}, + {"bold",canvas_bold}, + + + {"clipRect",canvas_clipRect}, + + {NULL, NULL} + }; + + lv_createClassMetaTable(L, META_TABLE_Canvas); + luaL_openlib(L, NULL, memberFunctions, 0); + + + { + // PaintStyle 常量 + lua_settop(L, 0); + NSDictionary* v = nil; + v = @{ + @"FILL": @(kCGPathFill), + @"EOFILL": @(kCGPathEOFill),//__deprecated_msg("") + @"STROKE": @(kCGPathStroke), + @"FILLSTROKE": @(kCGPathFillStroke), + @"EOFILLSTROKE": @(kCGPathEOFillStroke),//__deprecated_msg("") + }; + [LVUtil defineGlobal:@"PaintStyle" value:v L:L]; + } + return 0; +} + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVClassInfo.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVClassInfo.h new file mode 100644 index 00000000..e35c8791 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVClassInfo.h @@ -0,0 +1,24 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import + +@class LVMethod; + +@interface LVClassInfo : NSObject + + +- (void) addMethod:(LVMethod*) method key:(NSString*) key; +- (LVMethod*) getMethod:(NSString*) methodName; + +- (BOOL) existMethod:(NSString*) methodName; +- (void) setMethod:(NSString*) methodName exist:(BOOL) exist; + ++ (LVClassInfo*) classInfo:(NSString*) className; + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVClassInfo.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVClassInfo.m new file mode 100644 index 00000000..efc29e77 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVClassInfo.m @@ -0,0 +1,64 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVClassInfo.h" +#import "LVMethod.h" + +@interface LVClassInfo () +@property (nonatomic,strong) NSMutableDictionary* methods; +@property (nonatomic,strong) NSMutableDictionary* apiHash; +@end + +static NSMutableDictionary* g_allClassInfo = nil; + +@implementation LVClassInfo + +-(instancetype) init{ + self = [super init]; + if( self ) { + self.methods = [[NSMutableDictionary alloc] init]; + self.apiHash = [[NSMutableDictionary alloc] init]; + } + return self; +} + ++(LVClassInfo*) classInfo:(NSString*) className { + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + g_allClassInfo = [[NSMutableDictionary alloc] init]; + }); + + if( className==nil ) { + return nil; + } + LVClassInfo* classInfo = g_allClassInfo[className]; + if( classInfo==nil ) { + classInfo = [[LVClassInfo alloc] init]; + g_allClassInfo[className] = classInfo; + } + return classInfo; +} + +-(void) addMethod:(LVMethod*) method key:(NSString*) key{ + self.methods[key] = method; +} + +-(LVMethod*) getMethod:(NSString*) methodName{ + return self.methods[methodName]; +} + +-(BOOL) existMethod:(NSString*) methodName{ + return self.apiHash[methodName] != nil; +} + +-(void) setMethod:(NSString*) methodName exist:(BOOL) exist{ + if( exist ) { + self.apiHash[methodName] = @(exist); + } +} +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCollectionView.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCollectionView.h new file mode 100644 index 00000000..49d40688 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCollectionView.h @@ -0,0 +1,29 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" +#import "UIScrollView+LuaView.h" +#import "LVFlowLayout.h" + +@interface LVCollectionView : UICollectionView + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; +@property(nonatomic,assign) NSUInteger lv_align; +@property(nonatomic,strong) CAShapeLayer* lv_shapeLayer; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +- (id) init:(lua_State*) l; + +@property(nonatomic,weak) id lvScrollViewDelegate; + +@property(nonatomic,strong) LVFlowLayout* lvflowLayout; + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCollectionView.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCollectionView.m new file mode 100644 index 00000000..7df944d6 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCollectionView.m @@ -0,0 +1,275 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVCollectionView.h" +#import "LVCollectionViewCell.h" +#import "LView.h" +#import "LVBaseView.h" +#import "LVScrollView.h" +#import "UIScrollView+LuaView.h" +#import "LVCollectionViewDelegate.h" +#import "LVFlowLayout.h" +#import "LVHeads.h" + +@interface LVCollectionView () +@property (nonatomic,strong) LVCollectionViewDelegate* collectionViewDelegate; +@end + + +@implementation LVCollectionView + +-(id) init:(lua_State*) l { + LVFlowLayout* flowLayout = [[LVFlowLayout alloc] init]; + self = [super initWithFrame:CGRectMake(0, 0, 0, 0) collectionViewLayout:flowLayout]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + self.collectionViewDelegate = [[LVCollectionViewDelegate alloc] init:self]; + self.delegate = self.collectionViewDelegate; + self.dataSource = self.collectionViewDelegate; + self.backgroundColor = [UIColor clearColor]; + + self.lvflowLayout = flowLayout; + self.collectionViewDelegate.lvCollectionView = self; + self.collectionViewDelegate.lvflowLayout = flowLayout; + + self.alwaysBounceVertical = YES; // 垂直总是有弹性动画 + self.scrollsToTop = NO; + } + return self; +} + +-(void) setLvScrollViewDelegate:(id)lvScrollViewDelegate{ + _lvScrollViewDelegate = lvScrollViewDelegate; + self.collectionViewDelegate.delegate = lvScrollViewDelegate; +} + +-(void) dealloc{ +} + +-(void) reloadData{ + [super reloadData]; +} + +-(void) reloadDataASync{ + dispatch_async(dispatch_get_main_queue(), ^{ + [self performSelector:@selector(reloadData) withObject:nil afterDelay:0.001 inModes:@[NSRunLoopCommonModes]]; + }); +} + +-(void) layoutSubviews{ + [super layoutSubviews]; + if ( self.lv_luaviewCore.l ) { + lua_settop(self.lv_luaviewCore.l, 0); + } + [self lv_callLuaByKey1:@STR_ON_LAYOUT]; +} + +// 重载以实现可能的定制需求, contentOffset +- (void) luaviewSetContentOffset:(CGPoint)contentOffset animated:(BOOL)animated{ + [self setContentOffset:contentOffset animated:animated]; +} + +// 重载以实现可能的定制需求, RectToVisible +- (void) luaviewScrollRectToVisible:(CGRect)rect animated:(BOOL)animated{ + [self scrollRectToVisible:rect animated:animated]; +} + +// 重载以实现可能的定制需求, scrollToTop +- (void) luaviewScrollToTopWithAnimated:(BOOL)animated{ + [self scrollRectToVisible:CGRectMake(0, 0, 320, 10) animated:animated]; +} + + + +#pragma -mark lvNewCollectionView +static int lvNewCollectionView(lua_State *L) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVCollectionView class]]; + + LVCollectionView* collectionView = [[c alloc] init:L]; + [collectionView lv_initRefreshHeader]; + + NEW_USERDATA(userData, View); + userData->object = CFBridgingRetain(collectionView); + collectionView.lv_userData = userData; + luaL_getmetatable(L, META_TABLE_UICollectionView ); + lua_setmetatable(L, -2); + + if ( lua_gettop(L)>=1 && lua_type(L, 1)==LUA_TTABLE ) { + lua_pushvalue(L, 1); + lv_udataRef(L, USERDATA_KEY_DELEGATE ); + } + + LuaViewCore* lview = LV_LUASTATE_VIEW(L); + if( lview ){ + [lview containerAddSubview:collectionView]; + } + return 1; +} + +static int reload (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVCollectionView* tableView = (__bridge LVCollectionView *)(user->object); + //reload接口异步拉起,确保layout中也能调用reload + [tableView reloadDataASync]; + lua_pushvalue(L, 1); + return 1; + } + return 0; +} + +static int miniSpacing (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVCollectionView* tableView = (__bridge LVCollectionView *)(user->object); + if( lua_gettop(L)>=3 ) { + CGFloat value1 = lua_tonumber(L, 2); + CGFloat value2 = lua_tonumber(L, 3); + tableView.lvflowLayout.minimumLineSpacing = value1; + tableView.lvflowLayout.minimumInteritemSpacing = value2; + return 0; + } else if( lua_gettop(L)>=2 ) { + CGFloat value1 = lua_tonumber(L, 2); + tableView.lvflowLayout.minimumLineSpacing = value1; + tableView.lvflowLayout.minimumInteritemSpacing = value1; + return 0; + } else { + CGFloat value1 = tableView.lvflowLayout.minimumLineSpacing; + CGFloat value2 = tableView.lvflowLayout.minimumInteritemSpacing; + lua_pushnumber(L, value1); + lua_pushnumber(L, value2); + return 2; + } + } + return 0; +} + +static int scrollDirection (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVCollectionView* tableView = (__bridge LVCollectionView *)(user->object); + if( lua_gettop(L)>=2 ) { + int value1 = lua_tonumber(L, 2); + tableView.lvflowLayout.scrollDirection = value1; + return 0; + } else { + CGFloat value1 = tableView.lvflowLayout.scrollDirection; + lua_pushnumber(L, value1); + return 1; + } + } + return 0; +} + +static int scrollToCell (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( LVIsType(user, View) ){ + LVCollectionView* collectionView = (__bridge LVCollectionView *)(user->object); + if( [collectionView isKindOfClass:[LVCollectionView class]] ) { + int nargs = lua_gettop(L); + if( nargs>=3 ){ + int section = lua_tonumber(L, 2); + int row = lua_tonumber(L, 3); + CGFloat offsetY = 0; + BOOL animation = YES; + for( int i=4; i<=nargs; i++ ) { + if( nargs>=i && lua_type(L, i)==LUA_TNUMBER ) { + offsetY = lua_tonumber(L, i); + } + if( nargs>=i && lua_type(L, i)==LUA_TBOOLEAN ) { + animation = lua_toboolean(L, i); + } + } + + int nativeSection = section-1; + int nativeRow = row-1 ; + if( 0<=nativeSection && nativeSection0 ) { + CGFloat y = r.origin.y + offsetY; + CGSize contentSize = collectionView.contentSize; + CGRect bounds = collectionView.bounds; + // 越界检查 + if( y + bounds.size.height > contentSize.height ) { + y = contentSize.height - bounds.size.height; + } + if( y < 0 ) { + y = 0; + } + [collectionView luaviewSetContentOffset:CGPointMake(0, y) animated:animation]; + } + } + return 0; + } + } + } + return 0; +} + +static int scrollToTop(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( LVIsType(user, View) ){ + LVCollectionView* tableView = (__bridge LVCollectionView *)(user->object); + if( [tableView isKindOfClass:[LVCollectionView class]] ) { + BOOL animation = YES; + if( lua_gettop(L)>=2 ) { + animation = lua_tonumber(L, 2); + } + [tableView luaviewScrollToTopWithAnimated:animation]; + return 0; + } + } + return 0; +} + ++(NSString*) globalName{ + return @"CollectionView"; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + + [LVUtil reg:L clas:self cfunc:lvNewCollectionView globalName:globalName defaultName:[self globalName]]; + + const struct luaL_Reg memberFunctions [] = { + // refreshEnable // IOS 为实现 + {"reload", reload},// 安卓支持section row + + {"miniSpacing", miniSpacing}, + + {"scrollDirection", scrollDirection},// for IOS + + + {"scrollToCell", scrollToCell}, + {"scrollToTop", scrollToTop}, + {NULL, NULL} + }; + + lv_createClassMetaTable(L ,META_TABLE_UICollectionView); + + luaL_openlib(L, NULL, [LVBaseView baseMemberFunctions], 0); + luaL_openlib(L, NULL, [LVScrollView memberFunctions], 0); + luaL_openlib(L, NULL, memberFunctions, 0); + + const char* keys[] = { "addView", NULL};// 移除多余API + lv_luaTableRemoveKeys(L, keys ); + return 1; +} + + + +-(NSString*) description{ + return [NSString stringWithFormat:@"", + (int)[self hash], NSStringFromCGRect(self.frame) , NSStringFromCGSize(self.contentSize)]; +} + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCollectionViewCell.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCollectionViewCell.h new file mode 100644 index 00000000..65ee9217 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCollectionViewCell.h @@ -0,0 +1,21 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + +@interface LVCollectionViewCell : UICollectionViewCell + +@property (nonatomic, assign) BOOL isInited; + +-(void) pushTableToStack; + +-(void) doInitWithLView:(LuaViewCore*) lview; + + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCollectionViewCell.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCollectionViewCell.m new file mode 100644 index 00000000..e16e0861 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCollectionViewCell.m @@ -0,0 +1,65 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVCollectionViewCell.h" +#import "LVHeads.h" +#import "LView.h" +#import "lapi.h" + +@interface LVCollectionViewCell () +@property (nonatomic,weak) LuaViewCore* lv_luaviewCore; +@end + + + +@implementation LVCollectionViewCell + + +-(void) dealloc{ + lua_State* L = self.lv_luaviewCore.l; + if( L ) { + [LVUtil unregistry:L key:self]; + } +} + +-(void) doInitWithLView:(LuaViewCore*) lview{ + self.lv_luaviewCore = lview; + lua_State* L = lview.l; + if( L ) { + lua_createtable(L, 0, 0); + [LVUtil registryValue:L key:self stack:-1]; + lv_luaTableSetWeakWindow(L, self.contentView); + } +} + +-(void) pushTableToStack{ + lua_State* L = self.lv_luaviewCore.l; + if( L ) { + [LVUtil pushRegistryValue:L key:self]; + } +} + +-(NSString*) description{ + return [NSString stringWithFormat:@"", (int)[self hash], NSStringFromCGRect(self.frame)]; +} + +- (void) layoutSubviews{ + [super layoutSubviews]; + + CGRect rect = self.frame; + NSArray* subviews = [self.contentView subviews]; + for( UIView* view in subviews){ + [view lv_alignSelfWithSuperRect:rect]; + } +} + +// 修复gif图片滚动会消失问题 +-(void) prepareForReuse{ +} + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCollectionViewDelegate.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCollectionViewDelegate.h new file mode 100644 index 00000000..be2fc4bd --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCollectionViewDelegate.h @@ -0,0 +1,22 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVScrollViewDelegate.h" + +#define IDENTIFIER "Id" +#define DEFAULT_CELL_IDENTIFIER @"LVCollectionCell.default.identifier" + +@class LVCollectionView; +@class LVFlowLayout; + +@interface LVCollectionViewDelegate : LVScrollViewDelegate + +@property(nonatomic,weak) LVCollectionView* lvCollectionView; +@property(nonatomic,weak) LVFlowLayout* lvflowLayout; + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCollectionViewDelegate.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCollectionViewDelegate.m new file mode 100644 index 00000000..88c0b036 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCollectionViewDelegate.m @@ -0,0 +1,362 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVCollectionViewDelegate.h" +#import "LVCollectionView.h" +#import "LVCollectionViewCell.h" +#import "LView.h" +#import "UIView+LuaView.h" +#import "LVHeads.h" + + +static inline NSInteger mapRow(NSInteger row){ + return row + 1; +} + +static inline NSInteger mapSection(NSInteger section){ + return section + 1; +} + +@interface LVCollectionViewDelegate () + +@property(nonatomic, strong) NSMutableSet *registeredIds; + + +@end + + +@implementation LVCollectionViewDelegate + +- (void)tryRegisterId:(NSString *)identifier inCollectionView:(UICollectionView *)view { + if (self.registeredIds == nil) { + self.registeredIds = [NSMutableSet set]; + } + if (![self.registeredIds containsObject:identifier]) { + [view registerClass:[LVCollectionViewCell class] forCellWithReuseIdentifier:identifier]; + [self.registeredIds addObject:identifier]; + } +} + +- (UICollectionViewCell*) collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { + NSInteger section = indexPath.section; + NSInteger row = indexPath.row; + BOOL pinned = NO; + NSString* identifier = [self retStringCallKey1:"Cell" key2:IDENTIFIER mapedSection:mapSection(section) mapedRow:mapRow(row) pinned:&pinned]; + if( identifier == nil ){ + identifier = DEFAULT_CELL_IDENTIFIER; + } + // 制定的cell 是否悬浮 + if( pinned ) { + [self.lvflowLayout addPinnedIndexPath:indexPath]; + } else { + [self.lvflowLayout delPinnedIndexPath:indexPath]; + } + [self tryRegisterId:identifier inCollectionView:collectionView]; + LVCollectionViewCell* cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath]; + cell.contentView.frame = cell.bounds;//脚本的window是ContentView大小可能和Cell不同步 + LuaViewCore* lview = self.owner.lv_luaviewCore; + lua_State* L = lview.l; + UIView* newWindow = cell.contentView; + [lview pushWindow:newWindow]; + if ( L ) { + if( !cell.isInited ){ + cell.isInited = YES; + [cell doInitWithLView:lview]; + + // 创建cell初始化 + lua_settop(L, 0); + lua_checkstack(L, 12); + [cell pushTableToStack];//arg1: cell + lua_pushnumber(L, mapSection(section) );//arg2: section + lua_pushnumber(L, mapRow(row) );//arg3: row + + lv_pushUserdata(L, self.owner.lv_userData); + lv_pushUDataRef(L, USERDATA_KEY_DELEGATE); + [LVUtil call:L key1:"Cell" key2:identifier.UTF8String key3:"Init" nargs:3 nrets:0 retType:LUA_TNONE]; + } + { // 通知布局调整 + // 参数 cell,section,row + lua_settop(L, 0); + lua_checkstack(L, 12); + [cell pushTableToStack];//arg1: cell + lua_pushnumber(L, mapSection(section) );//arg2: section + lua_pushnumber(L, mapRow(row) );//arg3: row + + lv_pushUserdata(L, self.owner.lv_userData); + lv_pushUDataRef(L, USERDATA_KEY_DELEGATE); + [LVUtil call:L key1:"Cell" key2:identifier.UTF8String key3:"Layout" nargs:3 nrets:0 retType:LUA_TNONE]; + } + } + [lview popWindow:newWindow]; + return cell; +} + +// section数量 +- (NSInteger) numberOfSectionsInCollectionView:(UICollectionView *)collectionView{ + lua_State* l = self.owner.lv_luaviewCore.l; + if( l && self.owner.lv_userData ){ + lv_pushUserdata(l, self.owner.lv_userData); + lv_pushUDataRef(l, USERDATA_KEY_DELEGATE); + if( [LVUtil call:l key1:"Section" key2:"SectionCount" key3:NULL nargs:0 nrets:1 retType:LUA_TNUMBER] ==0 ) { + if( lua_type(l, -1)==LUA_TNUMBER ) { + NSInteger num = lua_tonumber(l, -1); + num = (num>0 ? num : 0); + return num; + } + } + return 1; + } + return 0; +} +// 每个区域的行数 +- (NSInteger) collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{ + lua_State* l = self.owner.lv_luaviewCore.l; + if( l ){ + // args + lua_pushnumber(l, mapSection(section) ); + + // table + lv_pushUserdata(l, self.owner.lv_userData); + lv_pushUDataRef(l, USERDATA_KEY_DELEGATE); + if( [LVUtil call:l key1:"Section" key2:"RowCount" key3:NULL nargs:1 nrets:1 retType:LUA_TNUMBER] ==0 ) { + if( lua_type(l, -1)==LUA_TNUMBER ) { + NSInteger num = lua_tonumber(l, -1); + num = (num>0 ? num : 0); + return num; + } + } + } + return 0; +} +//------- +#pragma mark --UICollectionViewDelegateFlowLayout +//定义每个UICollectionView 的大小 +- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath +{ + NSInteger section = indexPath.section; + NSInteger row = indexPath.row; + NSString* identifier = [self retStringCallKey1:"Cell" key2:IDENTIFIER mapedSection:mapSection(section) mapedRow:mapRow(row) pinned:NULL]; + if( identifier ) { + CGSize size = [self retSizeCallKey1:"Cell" key2:identifier.UTF8String key3:"Size" mapedSection:mapSection(section) mapedRow:mapRow(row) ]; + if( size.width<0 || isnan(size.width) ) { + size.width = 0; + } + if( size.height<0 || isnan(size.height) ) { + size.height = 0; + } + return size; + } else { + return CGSizeMake(self.owner.frame.size.width, 1); + } +} +//定义每个UICollectionView 的间距 +-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section +{ + UIEdgeInsets insets = [self retInsetCallKey1:"Section" key2:"EdgeInsets" mapedSection:mapSection(section) mapedRow:mapRow(0)]; + //insets.top = self.flowLayout.minimumLineSpacing; + return insets; +} +//定义每个UICollectionView 纵向的间距 +- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section { + // return self.flowLayout.minimumLineSpacing; + CGFloat spacing = [self retFloatCallKey1:"Section" key2:"Spacing" mapedSection:mapSection(section) ]; + return spacing; +} + +- (CGFloat) retFloatCallKey1:(const char*) funcName key2:(const char*) key2 mapedSection:(NSInteger) mapedSection { + lua_State* l = self.owner.lv_luaviewCore.l; + if( l ){ + lua_checkstack(l, 12); + lua_pushnumber(l, mapedSection); + + lv_pushUserdata(l, self.owner.lv_userData); + lv_pushUDataRef(l, USERDATA_KEY_DELEGATE); + if( [LVUtil call:l key1:funcName key2:key2 key3:NULL nargs:1 nrets:1 retType:LUA_TNUMBER] ==0 ) { + if( lua_type(l, -1)==LUA_TNUMBER ) { + CGFloat heigth = lua_tonumber(l, -1); + return heigth; + } + } + } + return 0; +} + +- (NSString*) retStringCallKey1:(const char*) key1 key2:(const char*)key2 + mapedSection:(NSInteger) mapedSection mapedRow:(NSInteger) mapedRow pinned:(BOOL*) pinned{ + lua_State* l = self.owner.lv_luaviewCore.l; + if( l ){ + // args + lua_checkstack(l, 12); + lua_pushnumber(l, mapedSection); + lua_pushnumber(l, mapedRow); + + // table + lv_pushUserdata(l, self.owner.lv_userData); + lv_pushUDataRef(l, USERDATA_KEY_DELEGATE); + + if( [LVUtil call:l key1:key1 key2:key2 key3:NULL nargs:2 nrets:2 retType:LUA_TSTRING] ==0 ) { + if( lua_type(l, -2)==LUA_TSTRING ){ + NSString* value = lv_paramString(l, -2); + BOOL yes = lua_toboolean(l, -1); + if( pinned ) { + *pinned = yes; + } + return value; + } + } + } + return nil; +} + +- (CGSize) retSizeCallKey1:(const char*) key1 key2:(const char*)key2 key3:(const char*)key3 + mapedSection:(NSInteger) mapedSection mapedRow:(NSInteger) mapedRow { + lua_State* l = self.owner.lv_luaviewCore.l; + if( l ){ + // args + lua_checkstack(l, 12); + lua_pushnumber(l, mapedSection); + lua_pushnumber(l, mapedRow); + + // table + lv_pushUserdata(l, self.owner.lv_userData); + lv_pushUDataRef(l, USERDATA_KEY_DELEGATE); + + if( [LVUtil call:l key1:key1 key2:key2 key3:key3 nargs:2 nrets:2 retType:LUA_TNONE] ==0 ) { + CGSize size = {0}; + if( lua_type(l, -1) ==LUA_TNIL ) { + size.width = self.owner.frame.size.width; + size.height = lua_tonumber(l, -2); + } else{ + size.width = lua_tonumber(l, -2); + size.height = lua_tonumber(l, -1); + } + return size; + } + } + return CGSizeMake(self.owner.frame.size.width, 1); +} +- (UIEdgeInsets) retInsetCallKey1:(const char*) key1 key2:(const char*)key2 + mapedSection:(NSInteger) mapSection mapedRow:(NSInteger)mapedRow { + lua_State* l = self.owner.lv_luaviewCore.l; + if( l ){ + // args + lua_checkstack(l, 12); + lua_pushnumber(l, mapSection); + lua_pushnumber(l, mapedRow); + + // table + lv_pushUserdata(l, self.owner.lv_userData); + lv_pushUDataRef(l, USERDATA_KEY_DELEGATE); + + if( [LVUtil call:l key1:key1 key2:key2 key3:NULL nargs:2 nrets:4 retType:LUA_TNONE] ==0 ) { + UIEdgeInsets egeInsets = {0}; + egeInsets.top = lua_tonumber(l, -4); + egeInsets.left = lua_tonumber(l, -3); + egeInsets.bottom = lua_tonumber(l, -2); + egeInsets.right = lua_tonumber(l, -1); + return egeInsets; + } + } + return UIEdgeInsetsMake(0, 0, 0, 0); +} + +- (void) collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { + NSInteger section = indexPath.section; + NSInteger row = indexPath.row; + lua_State* l = self.owner.lv_luaviewCore.l; + if( l ){ + NSString* identifier = [self retStringCallKey1:"Cell" key2:IDENTIFIER mapedSection:mapSection(section) mapedRow:mapRow(row) pinned:NULL]; + if ( identifier ) { + // 参数 cell,section,row + lua_settop(l, 0); + lua_checkstack(l, 12); + lua_pushnil(l);// cell + lua_pushnumber(l, mapSection(section) ); + lua_pushnumber(l, mapRow(row) ); + + // table + lv_pushUserdata(l, self.owner.lv_userData); + lv_pushUDataRef(l, USERDATA_KEY_DELEGATE); + + if( [LVUtil call:l key1:"Cell" key2:identifier.UTF8String key3:STR_CALLBACK key4:STR_ON_CLICK nargs:3 nrets:0 retType:LUA_TNONE]==0 ) { + } + } + } +} + +-(void) callWithScrollArgsForKey:(NSString*) functionName{ + UICollectionView* tableView = (UICollectionView*)self.owner; + NSArray* indexPaths = [tableView indexPathsForVisibleItems]; + int visibleCount = 0; + NSIndexPath* indexPath0 = nil; + + for( NSIndexPath* indexPath in indexPaths ) { + visibleCount ++; + if( indexPath0== nil ) { + indexPath0 = indexPath; + } + } + lua_State* L = self.owner.lv_luaviewCore.l; + if( L && indexPath0 ) { + NSInteger section = indexPath0.section; + NSInteger row = indexPath0.row; + + lua_settop(L, 0); + lua_pushnumber(L, mapSection(section) ); + lua_pushnumber(L, mapRow(row) ); + lua_pushnumber(L, visibleCount ); + [self.owner lv_callLuaByKey1:functionName key2:nil argN:3]; + } +} + +- (void)scrollViewDidScroll:(UIScrollView *)scrollView{ + [self callWithScrollArgsForKey:@"Scrolling"]; + if( [self.delegate respondsToSelector:@selector(scrollViewDidScroll:)] ) { + [self.delegate scrollViewDidScroll:scrollView]; + } +} + +- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{ + [self callWithScrollArgsForKey:@"ScrollBegin"]; + if( [self.delegate respondsToSelector:@selector(scrollViewWillBeginDragging:)] ) { + [self.delegate scrollViewWillBeginDragging:scrollView]; + } +} + +- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{ + [self callWithScrollArgsForKey:@"ScrollEnd"]; + if( [self.delegate respondsToSelector:@selector(scrollViewDidEndDecelerating:)] ) { + [self.delegate scrollViewDidEndDecelerating:scrollView]; + } +} + +- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView{ + [self callWithScrollArgsForKey:@"ScrollEnd"]; + if( [self.delegate respondsToSelector:@selector(scrollViewDidEndScrollingAnimation:)] ) { + [self.delegate scrollViewDidEndScrollingAnimation:scrollView]; + } +} + +- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{ + if( !decelerate ) { + [self callWithScrollArgsForKey:@"ScrollEnd"]; + } + if( [self.delegate respondsToSelector:@selector(scrollViewDidEndDragging:willDecelerate:)] ) { + [self.delegate scrollViewDidEndDragging:scrollView willDecelerate:decelerate]; + } +} + +// IOS 特有事件, 状态栏回顶 +- (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView{ + [self callWithScrollArgsForKey:@"ScrollToTop"]; + if( [self.delegate respondsToSelector:@selector(scrollViewDidScrollToTop:)] ) { + [self.delegate scrollViewDidScrollToTop:scrollView]; + } +} + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCustomPanel.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCustomPanel.h new file mode 100644 index 00000000..241ada7d --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCustomPanel.h @@ -0,0 +1,26 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + +@interface LVCustomPanel : UIView + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; +@property(nonatomic,assign) NSUInteger lv_align; +@property(nonatomic,strong) CAShapeLayer* lv_shapeLayer; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +- (void) callLuaWithArgument:(NSString*) info; +- (void) callLuaWithArguments:(NSArray*) args; +// callLuaFunction() +// callLuaCallback + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCustomPanel.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCustomPanel.m new file mode 100644 index 00000000..fa0b094a --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCustomPanel.m @@ -0,0 +1,100 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVCustomPanel.h" +#import "LVBaseView.h" +#import "LView.h" +#import "LVHeads.h" + +@implementation LVCustomPanel + +- (void) callLuaWithArgument:(NSString*) info { + [self callLuaWithArguments:@[ (info?info:@"") ]]; +} + +- (void) callLuaWithArguments:(NSArray*) args{ + // 外部回调脚本一定要在主线程调用 + dispatch_block_t f = ^(){ + lua_State* L = self.lv_luaviewCore.l; + if( L && self.lv_userData ){ + lua_checkstack(L,32); + int num = lua_gettop(L); + for( int i=0; i=4 ) { + r = CGRectMake(lua_tonumber(L, 1), lua_tonumber(L, 2), lua_tonumber(L, 3), lua_tonumber(L, 4)); + } + LVCustomPanel* errorNotice = [[c alloc] initWithFrame:r]; + { + NEW_USERDATA(userData, View); + userData->object = CFBridgingRetain(errorNotice); + errorNotice.lv_userData = userData; + errorNotice.lv_luaviewCore = LV_LUASTATE_VIEW(L); + + luaL_getmetatable(L, META_TABLE_CustomPanel ); + lua_setmetatable(L, -2); + } + LuaViewCore* view = LV_LUASTATE_VIEW(L); + if( view ){ + [view containerAddSubview:errorNotice]; + } + return 1; /* new userdatum is already on the stack */ +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewCustomPanelView globalName:globalName defaultName:@"CustomPanel"]; + + const struct luaL_Reg memberFunctions [] = { + {NULL, NULL} + }; + + lv_createClassMetaTable(L, META_TABLE_CustomPanel); + + luaL_openlib(L, NULL, [LVBaseView baseMemberFunctions], 0); + luaL_openlib(L, NULL, memberFunctions, 0); + return 1; +} + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCustomView.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCustomView.h new file mode 100644 index 00000000..4865143d --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCustomView.h @@ -0,0 +1,24 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + +@interface LVCustomView : UIView + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; +@property(nonatomic,assign) NSUInteger lv_align; +@property(nonatomic,strong) CAShapeLayer* lv_shapeLayer; +@property(nonatomic,assign) BOOL lv_canvas; + +-(id) init:(lua_State*) l; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCustomView.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCustomView.m new file mode 100644 index 00000000..1c28125d --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCustomView.m @@ -0,0 +1,85 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVCustomView.h" +#import "LVBaseView.h" +#import "LView.h" +#import "LVCanvas.h" + +@interface LVCustomView () +@property(nonatomic,assign) BOOL lv_isCallbackAddClickGesture;// 支持Callback 点击事件 +@end + +@implementation LVCustomView + +-(id) init:(lua_State*) l{ + self = [super init]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + self.backgroundColor = [UIColor clearColor]; + self.clipsToBounds = YES; + } + return self; +} + +-(void) drawRect:(CGRect)rect{ + [super drawRect:rect]; + + lua_State* L = self.lv_luaviewCore.l; + if( L ) { + lua_settop(L, 0); + CGContextRef contextRef = UIGraphicsGetCurrentContext(); + LVCanvas* canvas = [LVCanvas createLuaCanvas:L contentRef:contextRef]; + [self lv_callLuaByKey1:@STR_ON_DRAW key2:nil argN:1]; + canvas.contentRef = NULL; + } +} + +#pragma -mark CustomView +static int lvNewCustomView (lua_State *L) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVCustomView class]]; + + { + LVCustomView* customView = [[c alloc] init:L]; + { + NEW_USERDATA(userData, View); + userData->object = CFBridgingRetain(customView); + customView.lv_userData = userData; + + luaL_getmetatable(L, META_TABLE_CustomView ); + lua_setmetatable(L, -2); + } + LuaViewCore* father = LV_LUASTATE_VIEW(L); + if( father ){ + [father containerAddSubview:customView]; + } + } + return 1; /* new userdatum is already on the stack */ +} + +static int onDraw (lua_State *L) { + return lv_setCallbackByKey(L, STR_ON_DRAW, NO); +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewCustomView globalName:globalName defaultName:@"CustomView"]; + + const struct luaL_Reg memberFunctions [] = { + {"onDraw" , onDraw}, + {NULL, NULL} + }; + + lv_createClassMetaTable(L,META_TABLE_CustomView); + + luaL_openlib(L, NULL, [LVBaseView baseMemberFunctions], 0); + luaL_openlib(L, NULL, memberFunctions, 0); + + return 1; +} + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVDB.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVDB.h new file mode 100644 index 00000000..c1c8f6b4 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVDB.h @@ -0,0 +1,16 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + +@interface LVDB : NSObject + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVDB.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVDB.m new file mode 100644 index 00000000..db677ea5 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVDB.m @@ -0,0 +1,92 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVDB.h" +#import "LVHeads.h" + +@implementation LVDB + + + +static int db_get (lua_State *L) { + lv_clearFirstTableValue(L); + NSString* key = lv_paramString(L, 1); + NSString* defaultValue = nil; + if( lua_gettop(L)>=2 && lua_type(L, 2)==LUA_TNUMBER ) { + double v = lua_tonumber(L, 2); + defaultValue = [NSString stringWithFormat:@"%lf",v]; + } else { + defaultValue = lv_paramString(L, 2); + } + if( key.length>0 ) { + NSString* value = [[NSUserDefaults standardUserDefaults] objectForKey:key]; + if( value == nil ) + value = defaultValue; + lua_pushstring(L, value.UTF8String); + return 1; /* number of results */ + } else { + return 0; + } +} + +static BOOL needSub(NSString* s){ + if( [s rangeOfString:@"."].length>0 ){ + if( [s hasSuffix:@"0"] || [s hasSuffix:@"."] ){ + return YES; + } + } + return NO; +} + +static NSString* clearString(NSString* s){ + if( needSub(s) ){ + NSMutableString* buf = [[NSMutableString alloc] initWithString:s]; + for( ;buf.length>0; ){ + if( needSub(buf) ){ + NSRange range = {0}; + range.length = 1; + range.location = buf.length-1; + [buf deleteCharactersInRange:range]; + } else { + break; + } + } + return buf; + } + return s; +} + +static int db_set (lua_State *L) { + lv_clearFirstTableValue(L); + if( lua_gettop(L)>=2 ) { + NSString* key = lv_paramString(L, 1); + NSString* value = lv_paramString(L, 2); + if( value==nil && (lua_type(L, 2)==LUA_TNUMBER) ){ + value = [NSString stringWithFormat:@"%f",lua_tonumber(L, 2)]; + value = clearString(value); + } + if( key.length>0 && value.length>0 ){ + [[NSUserDefaults standardUserDefaults] setObject:value forKey:key]; + [[NSUserDefaults standardUserDefaults] synchronize]; + } + } + return 0; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + const struct luaL_Reg functions [] = { + {"get", db_get}, + {"set", db_set}, + {LUAVIEW_SYS_TABLE_KEY, db_set}, + {NULL, NULL} + }; + luaL_openlib(L, "DB", functions, 0); + return 0; +} + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVData.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVData.h new file mode 100644 index 00000000..d152a4de --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVData.h @@ -0,0 +1,26 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + + +//LVData +@interface LVData : NSObject + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; + +@property(nonatomic,strong) NSMutableData* data;//真实的数据 + +-(id) init:(lua_State*) l; ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + ++(int) createDataObject:(lua_State *)L data:(NSData*) data; + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVData.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVData.m new file mode 100644 index 00000000..ec037483 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVData.m @@ -0,0 +1,219 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVData.h" +#import "LVHeads.h" + +@interface LVData () +@end + +@implementation LVData + +-(id) init:(lua_State *)l{ + self = [super init]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + self.data = [[NSMutableData alloc] init]; + } + return self; +} + +-(id) lv_nativeObject{ + return self.data; +} + +static void releaseUserDataData(LVUserDataInfo* user){ + if( user && user->object ){ + LVData* data = CFBridgingRelease(user->object); + user->object = NULL; + if( data ){ + data.lv_userData = NULL; + data.lv_luaviewCore = nil; + data.data = nil; + } + } +} + +static int lvDataGC (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + releaseUserDataData(user); + return 0; +} + +static int lvNewData (lua_State *L) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVData class]]; + + LVData* data = [[c alloc] init:L]; + int argN = lua_gettop(L); + if( argN>0 ) { + if ( lua_type(L, 1)==LUA_TSTRING ) {// 支持字符串转 NSData + NSString* s = lv_paramString(L, 1); + const char* chars = s.UTF8String; + [data.data appendBytes:chars length:strlen(chars) ]; + } else { + int num = lua_tonumber(L, 1); + if( num>0 ){ + [data.data setLength:num]; + } + } + } + + { + NEW_USERDATA(userData, Data); + userData->object = CFBridgingRetain(data); + data.lv_userData = userData; + + luaL_getmetatable(L, META_TABLE_Data ); + lua_setmetatable(L, -2); + } + return 1; +} + ++(int) createDataObject:(lua_State *)L data:(NSData*) data{ + return [self createDataObject:L data1:data data2:nil]; +} + ++(int) createDataObject:(lua_State *)L data1:(NSData*) data1 data2:(NSData*) data2{ + LVData* lvdata = [[LVData alloc] init:L]; + if( data1 ) { + [lvdata.data setData:data1]; + } + if( data2 ) { + [lvdata.data appendData:data2]; + } + { + NEW_USERDATA(userData, Data); + userData->object = CFBridgingRetain(lvdata); + lvdata.lv_userData = userData; + + luaL_getmetatable(L, META_TABLE_Data ); + lua_setmetatable(L, -2); + } + return 1; +} + +static int __tostring (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVData* data = (__bridge LVData *)(user->object); + NSStringEncoding encode = NSUTF8StringEncoding; + if( lua_gettop(L)>=2 && lua_type(L, 2)==LUA_TNUMBER ) { + encode = lua_tonumber(L, 2); + } + NSString* s = [[NSString alloc] initWithData:data.data encoding:encode]; + if( s==nil ){ + NSStringEncoding gbkEncoding = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000); + s = [[NSString alloc] initWithData:data.data encoding:gbkEncoding]; + if ( s==nil ) { + s = [[NSString alloc] initWithFormat:@"{ UserDataType=data, length=%ld }",(long)data.data.length]; + } + } + lua_pushstring(L, s.UTF8String); + return 1; + } + return 0; +} + +static int __index (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + LVData* lvData = (__bridge LVData *)(user->object); + NSMutableData* data = lvData.data; + if( lvData && lvData.data){ + if( lua_type(L, 2)==LUA_TNUMBER ){ + int index = lua_tonumber(L, 2)-1; + if( index>=0 && indexobject); + NSMutableData* data = lvData.data; + if( lvData && lvData.data){ + if( lua_type(L, 2)==LUA_TNUMBER ){ + int index = lua_tonumber(L, 2)-1; + int value = lua_tonumber(L, 3); + if( index>=0 && indexobject); + LVData* lvData2 = (__bridge LVData *)(user2->object); + if( LVIsType(user1, Data) && LVIsType(user2, Data) && lvData1.data && lvData2.data ){ + [LVData createDataObject:L data1:lvData1.data data2:lvData2.data]; + return 1; + } + return 0; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewData globalName:globalName defaultName:@"Data"]; + + const struct luaL_Reg memberFunctions [] = { + // toJson 判断是否json + // toString 判断是否字符串 + // toTable + // append + + {"__index", __index }, + {"__newindex", __newindex }, + + {"__add", __add }, + + {"__gc", lvDataGC }, + + {"__tostring", __tostring }, + {NULL, NULL} + }; + + lv_createClassMetaTable(L, META_TABLE_Data); + + luaL_openlib(L, NULL, memberFunctions, 0); + return 0; +} + + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVDate.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVDate.h new file mode 100644 index 00000000..e9b31766 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVDate.h @@ -0,0 +1,24 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import + + +@interface LVDate : NSObject + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; + +@property(nonatomic,strong) NSDate* date; + +- (id) lv_nativeObject; // 返回native对象 + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVDate.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVDate.m new file mode 100644 index 00000000..0e9ebe55 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVDate.m @@ -0,0 +1,184 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVHeads.h" +#import "LVDate.h" +#import "LVHeads.h" + + + +@implementation LVDate + +-(id) init:(NSDate*) d{ + self = [super init]; + if( self ) { + self.date = d; + } + return self; +} + +-(id) lv_nativeObject{ + return self.date; +} + +static NSString* string09(NSString* s, NSUInteger len){ + NSMutableString* buf = [[NSMutableString alloc] init]; + for( int i=0; iobject = CFBridgingRetain(d); + + luaL_getmetatable(L, META_TABLE_Date ); + lua_setmetatable(L, -2); + } + } + return 1; /* new userdatum is already on the stack */ +} + + +static int __GC (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( LVIsType(user, Date) && user->object ){ + CFBridgingRelease(user->object); + user->object = NULL; + } + return 0; +} + +static int __tostring (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( LVIsType(user, Date) ){ + LVDate* date = (__bridge LVDate *)(user->object); + NSString* s = [NSString stringWithFormat:@"%@", date.date ]; + lua_pushstring(L, s.UTF8String); + return 1; + } + return 0; +} + +static int format (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + NSString* formatString = lv_paramString(L, 2); + if( LVIsType(user, Date) ){ + LVDate* date = (__bridge LVDate *)(user->object); + if( date ) { + NSString* ret = nil; + if( formatString ){ + NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; + [formatter setDateFormat:formatString]; + ret = [formatter stringFromDate:date.date]; + } else { + ret = [NSString stringWithFormat:@"%@", date.date ]; + } + lua_pushstring(L, ret.UTF8String); + return 1; + } + } + return 0; +} + +static int __sub (lua_State *L) { + LVUserDataInfo * user1 = (LVUserDataInfo *)lua_touserdata(L, 1); + LVUserDataInfo * user2 = (LVUserDataInfo *)lua_touserdata(L, 2); + if( LVIsType(user1, Date) && LVIsType(user2, Date) ){ + LVDate* date1 = (__bridge LVDate *)(user1->object); + LVDate* date2 = (__bridge LVDate *)(user2->object); + double time = [date1.date timeIntervalSinceDate:date2.date]; + lua_pushnumber(L, time); + return 1; + } + return 0; +} + +static int __eq (lua_State *L) { + LVUserDataInfo * user1 = (LVUserDataInfo *)lua_touserdata(L, 1); + LVUserDataInfo * user2 = (LVUserDataInfo *)lua_touserdata(L, 2); + if( LVIsType(user1, Date) && LVIsType(user2, Date) ){ + LVDate* date1 = (__bridge LVDate *)(user1->object); + LVDate* date2 = (__bridge LVDate *)(user2->object); + BOOL yes = [date1.date isEqualToDate:date2.date]; + lua_pushboolean(L, (yes?1:0) ); + return 1; + } + return 0; +} + +static int timeInterval (lua_State *L) { + LVUserDataInfo * user1 = (LVUserDataInfo *)lua_touserdata(L, 1); + if( LVIsType(user1, Date) ){ + LVDate* date1 = (__bridge LVDate *)(user1->object); + double time = [date1.date timeIntervalSince1970]; + lua_pushnumber(L, time); + return 1; + } + return 0; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewDate globalName:globalName defaultName:@"Date"]; + + const struct luaL_Reg memberFunctions [] = { + {"__gc", __GC }, + {"__sub", __sub}, + {"__eq", __eq}, + {"timeInterval", timeInterval }, + + {"__tostring", __tostring }, + {"format", format }, + {NULL, NULL} + }; + + lv_createClassMetaTable(L, META_TABLE_Date); + + luaL_openlib(L, NULL, memberFunctions, 0); + return 1; +} + + +@end + + + diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVDownloader.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVDownloader.h new file mode 100644 index 00000000..b696dd49 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVDownloader.h @@ -0,0 +1,25 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + + +@interface LVDownloader : NSObject + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; + +@property(nonatomic,copy) id luaObjRetainKey; + +-(id) init:(lua_State*) l; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +@end + diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVDownloader.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVDownloader.m new file mode 100644 index 00000000..dd7b2329 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVDownloader.m @@ -0,0 +1,146 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVDownloader.h" +#import "LVUtil.h" +#import "LVData.h" +#import "LView.h" +#import "LVHeads.h" + +@interface LVDownloader () +@property(nonatomic,strong) NSData* data; +@property(nonatomic,strong) id strongSelf; +@end + + +@implementation LVDownloader + + +static void releaseUserDataDownloader(LVUserDataInfo* user){ + if( user && user->object ){ + LVDownloader* downloader = CFBridgingRelease(user->object); + user->object = NULL; + if( downloader ){ + downloader.lv_userData = nil; + downloader.lv_luaviewCore = nil; + } + } +} + +-(void) dealloc{ + releaseUserDataDownloader(_lv_userData); +} + +-(id) lv_nativeObject{ + return nil; +} + +-(id) init:(lua_State*) l{ + self = [super init]; + if( self ){ + self.luaObjRetainKey = [[NSMutableString alloc] init]; + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + self.strongSelf = self; + } + return self; +} + + +#pragma -mark downloader +static int lvNewDownloader (lua_State *L) { + if( lua_gettop(L)>=2 ) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVDownloader class]]; + + LVDownloader* downloader = [[c alloc] init:L]; + NSString* url = lv_paramString(L, 1); // 1: url + //NSString* fileName = lvL_paramString(L, 2);// 2: fileName + // 3: callback + if( lua_type(L, -1) == LUA_TFUNCTION ) { + [LVUtil registryValue:L key:downloader stack:-1]; + } + + { + NEW_USERDATA(userData, Downloader); + userData->object = CFBridgingRetain(downloader); + downloader.lv_userData = userData; + + luaL_getmetatable(L, META_TABLE_Downloader ); + lua_setmetatable(L, -2); + + [LVUtil registryValue:L key:downloader.luaObjRetainKey stack:-1]; + } + [LVUtil download:url callback:^(NSData *data) { + downloader.data = data; + [downloader performSelectorOnMainThread:@selector(didFileLoaded) withObject:nil waitUntilDone:NO]; + }]; + return 1; + } else { + LVError(@"downloader( Callback==nil )!!!"); + } + return 0; +} + +-(void) didFileLoaded{ + lua_State* L = self.lv_luaviewCore.l; + if( L ){ + if( self.data ) { + [LVData createDataObject:L data:self.data]; + } else { + lua_pushnil(L); + } + [LVUtil call:L lightUserData:self key1:nil key2:nil nargs:1]; + + [LVUtil unregistry:L key:self.luaObjRetainKey]; + [LVUtil unregistry:L key:self]; + } + self.strongSelf = nil; +} + + static int __gc (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + releaseUserDataDownloader(user); + return 0; +} + +static int __tostring (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVDownloader* downloader = (__bridge LVDownloader *)(user->object); + NSString* s = [NSString stringWithFormat:@"LVUserDataDownloader: %@", downloader ]; + lua_pushstring(L, s.UTF8String); + return 1; + } + return 0; +} + +static int PathOfResource (lua_State *L) { + NSString* fileName = lv_paramString(L, 1); + LuaViewCore* lview = LV_LUASTATE_VIEW(L); + NSString* path = [lview.bundle resourcePathWithName:fileName]; + lua_pushstring(L, path.UTF8String); + return 1; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + lv_defineGlobalFunc("PathOfResource", PathOfResource, L); + + [LVUtil reg:L clas:self cfunc:lvNewDownloader globalName:globalName defaultName:@"Download"]; // __deprecated_msg("") + const struct luaL_Reg memberFunctions [] = { + {"__gc", __gc }, + + {"__tostring", __tostring }, + {NULL, NULL} + }; + + lv_createClassMetaTable(L, META_TABLE_Downloader); + + luaL_openlib(L, NULL, memberFunctions, 0); + return 1; +} + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVEmptyRefreshCollectionView.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVEmptyRefreshCollectionView.h new file mode 100644 index 00000000..c80eda03 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVEmptyRefreshCollectionView.h @@ -0,0 +1,17 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" +#import "UIScrollView+LuaView.h" +#import "LVCollectionView.h" + +// for IOS +@interface LVEmptyRefreshCollectionView : LVCollectionView + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVEmptyRefreshCollectionView.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVEmptyRefreshCollectionView.m new file mode 100644 index 00000000..8c28b925 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVEmptyRefreshCollectionView.m @@ -0,0 +1,45 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVEmptyRefreshCollectionView.h" +#import "LVRefreshHeader.h" + +@implementation LVEmptyRefreshCollectionView + +// 下拉刷新 +-(void) lv_initRefreshHeader{// 初始化下拉刷新功能 + LVRefreshHeader* refreshHeader = [[LVRefreshHeader alloc] init]; + self.lv_refresh_header = refreshHeader; + + __weak typeof(self) weakSelf = self; + refreshHeader.refreshingBlock = ^(){ + [weakSelf lv_refreshHeaderToRefresh]; + }; +} + +- (void) lv_hiddenRefreshHeader:(BOOL) hidden{ + self.lv_refresh_header.hidden = hidden; +} + +- (void) lv_beginRefreshing{// 进入刷新状态 + [self.lv_refresh_header beginRefreshing]; +} + +- (void) lv_endRefreshing{// 结束刷新状态 + [self.lv_refresh_header endRefreshing]; +} + +- (BOOL) lv_isRefreshing{// 是否正在刷新 + return self.lv_refresh_header.isRefreshing; +} + ++(NSString*) globalName{ + return @"EmptyRefreshCollectionView"; +} + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVEvent.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVEvent.h new file mode 100644 index 00000000..e4944422 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVEvent.h @@ -0,0 +1,35 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import +#import "LVHeads.h" + +#define LVTouchEventType_DOWN 1010 +#define LVTouchEventType_MOVE 1020 +#define LVTouchEventType_CANCEL 1030 +#define LVTouchEventType_UP 1040 + +@interface LVEvent : NSObject + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; + +@property(nonatomic,weak) UIEvent* event; + +@property(nonatomic,assign) NSInteger eventType; + +@property(nonatomic,weak) UIGestureRecognizer* gesture; + +-(id) init:(lua_State *)l gesture:(UIGestureRecognizer*) gesture; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + ++(LVEvent*) createLuaEvent:(lua_State *)L event:(UIEvent*) event gesture:(UIGestureRecognizer*) gesture; + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVEvent.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVEvent.m new file mode 100644 index 00000000..1e665a9c --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVEvent.m @@ -0,0 +1,229 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVEvent.h" + +@interface LVEvent () +@property(nonatomic,strong) NSArray * touches; +@property(nonatomic,assign) CGPoint point; +@property(nonatomic,strong) UITouch* touch; +@end + +@implementation LVEvent + +-(id) init:(lua_State *)l gesture:(UIGestureRecognizer*) gesture{ + self = [super init]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + self.gesture = gesture; + } + return self; +} + +-(void) setEvent:(UIEvent *)event{ + _event = event; + self.touches = event.allTouches.allObjects; + self.touch = self.touches.firstObject; + self.point = [self.touch locationInView:self.gesture.view]; +} + +-(id) lv_nativeObject{ + return self; +} + +static void releaseEventUserData(LVUserDataInfo* user){ + if( user && user->object ){ + LVEvent* lvEvent = CFBridgingRelease(user->object); + user->object = NULL; + if( lvEvent ){ + lvEvent.lv_userData = NULL; + lvEvent.lv_luaviewCore = nil; + lvEvent.event = nil; + lvEvent.touches = nil; + } + } +} + +static int lvEventGC (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + releaseEventUserData(user); + return 0; +} + +static int lvNewEvent (lua_State *L) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVEvent class]]; + + LVEvent* lvEvent = [[c alloc] init:L gesture:nil]; + + { + NEW_USERDATA(userData, Event); + userData->object = CFBridgingRetain(lvEvent); + lvEvent.lv_userData = userData; + + luaL_getmetatable(L, META_TABLE_Event ); + lua_setmetatable(L, -2); + } + return 1; +} + ++(LVEvent*) createLuaEvent:(lua_State *)L event:(UIEvent*) event gesture:(UIGestureRecognizer*) gesture{ + LVEvent* lvEvent = [[LVEvent alloc] init:L gesture:gesture]; + lvEvent.event = event; + { + NEW_USERDATA(userData, Event); + userData->object = CFBridgingRetain(lvEvent); + lvEvent.lv_userData = userData; + + luaL_getmetatable(L, META_TABLE_Event ); + lua_setmetatable(L, -2); + } + return lvEvent; +} + +static int nativeObj (lua_State *L) { + LVUserDataInfo * userData = (LVUserDataInfo *)lua_touserdata(L, 1); + if( userData ){ + LVEvent* lvEvent = (__bridge LVEvent *)(userData->object); + if( lvEvent ){ + id object = lvEvent.event; + lv_pushNativeObjectWithBox(L, object); + return 1; + } + } + return 0; +} + +static int action (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVEvent* lvEvent = (__bridge LVEvent *)(user->object); + if( lvEvent.eventType ) { + lua_pushnumber(L, lvEvent.eventType ); + } else { + UIEventType type = lvEvent.event.type; + lua_pushnumber(L, type ); + } + return 1; + } + return 0; +} + +static int pointer (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVEvent* lvEvent = (__bridge LVEvent *)(user->object); + CGPoint point = lvEvent.point; + NSDictionary* dic = @{ + @"x":@(point.x), + @"y":@(point.y) + }; + lv_pushNativeObject(L, dic ); + return 1; + } + return 0; +} + +static int x (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVEvent* lvEvent = (__bridge LVEvent *)(user->object); + CGPoint point = lvEvent.point; + lua_pushnumber(L, point.x ); + return 1; + } + return 0; +} + +static int y (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVEvent* lvEvent = (__bridge LVEvent *)(user->object); + CGPoint point = lvEvent.point; + lua_pushnumber(L, point.y ); + return 1; + } + return 0; +} + +static int event_id (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVEvent* lvEvent = (__bridge LVEvent *)(user->object); + lua_pushnumber(L, lvEvent.touch.timestamp ); + return 1; + } + return 0; +} + +static int __index (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + if ( lua_type(L, 2)==LUA_TSTRING ){ + lua_checkstack(L, 4); + lua_settop(L, 2); + luaL_getmetatable(L, META_TABLE_EventFunc ); + lua_pushvalue(L, 2); + lua_gettable(L, -2); + lua_remove(L, -2); + lua_remove(L, -2); + lua_CFunction cfunc = lua_tocfunction(L, -1); + if( cfunc ) { + lua_settop(L, 1); + return cfunc(L); + } + } + } + return 0; /* new userdatum is already on the stack */ +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewEvent globalName:globalName defaultName:@"Event"]; + + { + const struct luaL_Reg memberFunctions [] = { + {"__gc", lvEventGC }, + {"nativeObj", nativeObj}, + {"__index", __index }, + + {NULL, NULL} + }; + + lv_createClassMetaTable(L, META_TABLE_Event); + luaL_openlib(L, NULL, memberFunctions, 0); + } + { + + const struct luaL_Reg memberFunctions [] = { + {"id", event_id}, + {"action", action}, + {"pointer", pointer}, + {"x", x}, + {"y", y}, + {NULL, NULL} + }; + + lv_createClassMetaTable(L, META_TABLE_EventFunc); + luaL_openlib(L, NULL, memberFunctions, 0); + } + { + + NSDictionary* v = nil; + v = @{ + @"DOWN":@(LVTouchEventType_DOWN), + @"MOVE":@(LVTouchEventType_MOVE), + @"OUTSIDE":@(UIEventTypeRemoteControl), + @"PRESSES":@(UIEventTypePresses),// for IOS + @"UP":@(LVTouchEventType_UP), + @"CANCEL":@(LVTouchEventType_CANCEL), + }; + [LVUtil defineGlobal:@"TouchEvent" value:v L:L]; + } + return 0; +} + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVExGlobalFunc.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVExGlobalFunc.h new file mode 100644 index 00000000..b1e5feb6 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVExGlobalFunc.h @@ -0,0 +1,20 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import +#import "LVHeads.h" +#import "LView.h" + +@interface LVExGlobalFunc : NSObject + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + ++(void) registry:(lua_State*)L window:(UIView*)window; + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVExGlobalFunc.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVExGlobalFunc.m new file mode 100644 index 00000000..94018036 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVExGlobalFunc.m @@ -0,0 +1,187 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVExGlobalFunc.h" +#import "LVUtil.h" +#import "LVHeads.h" +#import "LVNativeObjBox.h" +#import "LVDebuger.h" + + +//------------------------------------------------------------------------ +@implementation LVExGlobalFunc + +static int lv_print (lua_State *L) { +#ifdef DEBUG + int n = lua_gettop(L); /* number of arguments */ + int i; + NSMutableString* buf = [[NSMutableString alloc] init]; + lua_getglobal(L, "tostring"); + for (i=1; i<=n; i++) { + const char *s = NULL; + lua_pushvalue(L, -1); /* function to be called */ + lua_pushvalue(L, i); /* value to print */ + lua_call(L, 1, 1); + s = lua_tostring(L, -1); /* get result */ + if (s == NULL) + return luaL_error(L, LUA_QL("tostring") " must return a string to " LUA_QL("print")); + if ( i>1 ) { + [buf appendString:@"\t"]; + } + NSString* str = [NSString stringWithUTF8String:s]; + [buf appendFormat:@"%@",str]; + lua_pop(L, 1); /* pop result */ + } + NSLog(@"%@",buf); + [buf appendString:@"\n"]; + lv_printToServer(L, buf.UTF8String, 0); +#endif + return 0; +} + +#pragma -mark registryApi +// 全局静态常量 和 静态方法 ++(void) registryStaticMethod:(lua_State *)L lView:(LuaViewCore *)lView{ + lv_defineGlobalFunc("print", lv_print, L); + + lv_defineGlobalFunc("loadJson", loadJson, L); + + lv_defineGlobalFunc("Unicode", unicode, L); + + // 替换pakcage.loaders中的loader_lv + lua_getglobal(L, LUA_LOADLIBNAME); + lua_getfield(L, 1, "loaders"); + if (!lua_istable(L, -1)) { + return; + } + + lua_pushnumber(L, 2); + lua_pushcfunction(L, loaderForLuaView); + lua_settable(L, -3); +} + +// 注册函数 ++(void) registryApi:(lua_State*)L lView:(LuaViewCore*)lView{ + + + return; +} + +// 注册系统对象 window ++(void) registry:(lua_State*)L window:(UIView*)window{ + NEW_USERDATA(userData, View); + userData->object = CFBridgingRetain(window); + window.lv_userData = userData; + window.lv_luaviewCore = LV_LUASTATE_VIEW(L); + userData->isWindow = 1; + + luaL_getmetatable(L, META_TABLE_LuaView ); + lua_setmetatable(L, -2); + + lua_setglobal(L, "window"); +} +//------------------------------------------------------------------------------------ + +static int loadJson (lua_State *L) { + NSString* json = lv_paramString(L, 1); + if( json ){ + json = [NSString stringWithFormat:@"return %@",json]; + luaL_loadstring(L, json.UTF8String); + if( lua_type(L, -1) == LUA_TFUNCTION ) { + int errorCode = lua_pcall( L, 0, 1, 0); + if( errorCode == 0 ){ + return 1; + } else { + LVError( @"loadJson : %s", lua_tostring(L, -1) ); + } + } else { + LVError( @"loadJson : %s", lua_tostring(L, -1) ); + } + } + return 0; /* number of results */ +} + +static int unicode(lua_State *L) { + int num = lua_gettop(L); + NSMutableString* buf = [[NSMutableString alloc] init]; + for( int i=1; i<=num; i++ ) { + if( lua_type(L, i) == LUA_TNUMBER ) { + unichar c = lua_tonumber(L, i); + [buf appendFormat:@"%C",c]; + } else { + break; + } + } + if( buf.length>0 ) { + lua_pushstring(L, buf.UTF8String); + return 1; + } + return 0; /* number of results */ +} + +static int loaderForLuaView (lua_State *L) { + static NSString *pathFormats[] = { @"%@.%@", @"%@/init.%@" }; + + NSString* moduleName = lv_paramString(L, 1); + if( moduleName ){ + // submodule + moduleName = [moduleName stringByReplacingOccurrencesOfString:@"." withString:@"/"]; + + LuaViewCore* lview = LV_LUASTATE_VIEW(L); + if( lview ) { + __block NSString *fullName = nil, *format = nil, *ext = nil; + BOOL(^findFile)() = ^BOOL() { // set fullName and return YES if found + NSString *name = [NSString stringWithFormat:format, moduleName, ext]; + + if( [lview.bundle scriptPathWithName:name] ) { + fullName = name; + return YES; + } else { + return NO; + } + }; + + for( int i = 0; i < sizeof(pathFormats) / sizeof(pathFormats[0]); ++i ) { + format = pathFormats[i]; + + if( lview.runInSignModel ) { + ext = LVScriptExts[LVSignedScriptExtIndex]; + if (findFile()) { + return [lview loadSignFile:fullName] == nil ? 1 : 0; + } + } + + ext = LVScriptExts[!LVSignedScriptExtIndex]; + if (findFile()) { + return [lview loadFile:fullName] == nil ? 1 : 0; + } + } + } + } + + // not found + return 0; +} + + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + LuaViewCore* lView = LV_LUASTATE_VIEW(L); + // 注册静态全局方法和常量 + [LVExGlobalFunc registryStaticMethod:L lView:lView]; + + //外链注册器 + [LVNativeObjBox lvClassDefine:L globalName:nil]; + // 调试 + [LVDebuger lvClassDefine:L globalName:nil]; + //清理栈 + lua_settop(L, 0); + return 0; +} + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVFile.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVFile.h new file mode 100644 index 00000000..3f1cc393 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVFile.h @@ -0,0 +1,15 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ +#import +#import "LVHeads.h" + +@interface LVFile : NSObject + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVFile.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVFile.m new file mode 100644 index 00000000..ac9414fe --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVFile.m @@ -0,0 +1,134 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVFile.h" +#import "LVHeads.h" +#import "LVData.h" +#import "LView.h" +#import "LVHeads.h" + +@implementation LVFile + +static void saveCallback(lua_State *L, int callbackIndex, NSString* fileName, int errorInfo ) { + if( callbackIndex ) { + lua_checkstack32(L); + lua_pushboolean(L, errorInfo); + lua_pushvalue(L,callbackIndex); + lv_runFunctionWithArgs(L, 1, 0); + } +} + +static BOOL readCallback(lua_State *L, int callbackIndex, NSString* fileName, NSData* data) { + if( callbackIndex ) { + lua_checkstack32(L); + [LVData createDataObject:L data:data]; + lua_pushvalue(L,callbackIndex); + lv_runFunctionWithArgs(L, 1, 0); + return YES; + } + return NO; +} + +static int file_save (lua_State *L) { + int num = lua_gettop(L); + if( num>=2 ) { + LVUserDataInfo * userData = NULL; + NSString* fileName = nil; + int callbackIndex = 0; + for( int i=1; i<=num; i++ ) { + if( lua_type(L, i)==LUA_TUSERDATA && userData==nil ) { + userData = (LVUserDataInfo *)lua_touserdata(L, i); + } + if( lua_type(L, i)==LUA_TSTRING && fileName==nil ) { + fileName = lv_paramString(L, i); + } + if( lua_type(L,i)==LUA_TFUNCTION ) { + callbackIndex = i; + } + } + if ( fileName && userData ) { + LVData* lvData1 = (__bridge LVData *)(userData->object); + if( LVIsType(userData, Data) && lvData1.data){ + if( [LVUtil saveData:lvData1.data toFile:[LVUtil PathForCachesResource:fileName]] ){ + saveCallback(L, callbackIndex, fileName, YES); + lua_pushboolean(L, 1); + return 1; + } else { + saveCallback(L, callbackIndex, fileName, NO); + } + } + } + } + lua_pushboolean(L, 0); + return 1; +} + +static int file_read(lua_State *L){ + int num = lua_gettop(L); + if( L && num>=1 ){ + NSString* fileName = nil; + int callbackIndex = 0; + for( int i=1; i<=num; i++ ) { + if( lua_type(L, i)==LUA_TSTRING && fileName==nil ) { + fileName = lv_paramString(L, i); + } + if( lua_type(L,i)==LUA_TFUNCTION ) { + callbackIndex = i; + } + } + if ( fileName ) { + LuaViewCore* lview = LV_LUASTATE_VIEW(L); + NSData* data = [lview.bundle resourceWithName:fileName]; + if( data ){ + if( readCallback(L, callbackIndex, fileName, data) ){ + } else { + [LVData createDataObject:L data:data]; + } + return 1; + } else { + readCallback(L, callbackIndex, fileName, nil); + } + } + } + return 0; +} + +static int file_exist(lua_State *L){ + if( L && lua_gettop(L)>=1 ){ + NSString* fileName = lv_paramString(L, -1); + LuaViewCore* lview = LV_LUASTATE_VIEW(L); + if( [lview.bundle resourcePathWithName:fileName] ){ + lua_pushboolean(L, 1); + return 1; + } + } + lua_pushboolean(L, 0); + return 1; +} + +static int file_path (lua_State *L) { + NSString* fileName = lv_paramString(L, -1); + LuaViewCore* lview = LV_LUASTATE_VIEW(L); + NSString* path = [lview.bundle resourcePathWithName:fileName]; + lua_pushstring(L, path.UTF8String); + return 1; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + const struct luaL_Reg function [] = { + {"save", file_save}, + {"read", file_read}, + {"exist", file_exist}, + {"path", file_path}, + {NULL, NULL} + }; + luaL_openlib(L, "File", function, 0); + return 0; +} + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVFlowLayout.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVFlowLayout.h new file mode 100644 index 00000000..90f06ef5 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVFlowLayout.h @@ -0,0 +1,19 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import + +@interface LVFlowLayout : UICollectionViewFlowLayout + +-(void) resetPinnedDic; +-(void) addPinnedIndexPath:(NSIndexPath*)indexPath; +-(void) delPinnedIndexPath:(NSIndexPath*)indexPath; +-(BOOL) isPinned:(NSIndexPath*)indexPath; +-(BOOL) pinnedDicIsNil; + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVFlowLayout.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVFlowLayout.m new file mode 100644 index 00000000..43fb603e --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVFlowLayout.m @@ -0,0 +1,111 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVFlowLayout.h" + +@interface LVFlowLayout () +@property(nonatomic, strong) NSMutableDictionary* pinnedDic; +@end + +@implementation LVFlowLayout + +-(id)init +{ + self = [super init]; + if ( self ){ + } + return self; +} + +- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect +{ + NSMutableArray *superLayoutAttArray = [[super layoutAttributesForElementsInRect:rect] mutableCopy]; + NSArray* keys = self.pinnedDic.allKeys; + // 排序 + keys = [keys sortedArrayUsingComparator:^NSComparisonResult(NSIndexPath* obj1, NSIndexPath* obj2) { + return [obj1 compare:obj2]; + }]; + + UICollectionViewLayoutAttributes* prevAtt = nil; + NSInteger pinnedTimes = 0; + for( NSInteger i=((NSInteger)keys.count)-1; i>=0; i-- ) { + NSIndexPath* indexPath = keys[i]; + UICollectionViewLayoutAttributes* a = [self layoutAttributesForItemAtIndexPath:indexPath]; + if( a ) { + CGRect frame = a.frame; + CGFloat minY = self.collectionView.contentOffset.y; + // 浮层:不能小于屏幕offset + if( frame.origin.y < minY ) { + frame.origin.y = minY; + a.frame = frame; + a.zIndex = 10 + i; + pinnedTimes ++; + + if( prevAtt ) { + // 但是浮层不能盖住上一个浮层 + CGFloat maxY = prevAtt.frame.origin.y - frame.size.height; + if( frame.origin.y>maxY ) { + frame.origin.y = maxY; + a.frame = frame; + a.zIndex = 10 + i; + } + } + } + [superLayoutAttArray addObject:a]; + prevAtt = a; + if( pinnedTimes > 1 ) { + // 这两行一定要有!!!!原因还有待确认@城西 + a.alpha = 0; + a.zIndex = -1; + break; + } else { + a.alpha = 1; + } + } + } + return superLayoutAttArray; +} + +-(BOOL) shouldInvalidateLayoutForBoundsChange:(CGRect)newBound +{ + return self.pinnedDic!=nil; +} + +-(void) resetPinnedDic{ + self.pinnedDic = [[NSMutableDictionary alloc] initWithCapacity:8]; +} + +-(void) addPinnedIndexPath:(NSIndexPath*)indexPath { + if( indexPath ) { + if( self.pinnedDic==nil ) { + [self resetPinnedDic]; + } + self.pinnedDic[indexPath] = @(YES); + } +} + +-(void) delPinnedIndexPath:(NSIndexPath*)indexPath{ + if( indexPath ) { + [self.pinnedDic removeObjectForKey:indexPath]; + } +} + +-(BOOL) isPinned:(NSIndexPath*)indexPath{ + if( indexPath ) { + return (self.pinnedDic[indexPath]!=nil); + } + return NO; +} + +-(BOOL) pinnedDicIsNil{ + return self.pinnedDic==nil; +} + +@end + + diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVGesture.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVGesture.h new file mode 100644 index 00000000..020aa3cf --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVGesture.h @@ -0,0 +1,33 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" +#import "NSObject+LuaView.h" + +@class LVGesture; + +typedef void(^LVGestureOnTouchEventCallback)(LVGesture* gesture, int argN); + +@interface LVGesture : UIGestureRecognizer + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; + +@property(nonatomic,copy) LVGestureOnTouchEventCallback onTouchEventCallback; + +-(id) init:(lua_State*) l; + ++(const luaL_Reg*) baseMemberFunctions; + ++(void) releaseUD:(LVUserDataInfo *) user; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVGesture.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVGesture.m new file mode 100644 index 00000000..76f1eee1 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVGesture.m @@ -0,0 +1,228 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVGesture.h" +#import "LView.h" +#import +#import "LVEvent.h" +#import "LVHeads.h" + +@implementation LVGesture + +-(id) init:(lua_State*) l{ + self = [super initWithTarget:self action:@selector(handleGesture:)]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + self.delegate = self; + } + return self; +} + +-(void) handleGesture:(LVGesture*)sender { + [self handleGesture:sender event:nil eventType:0]; +} + +-(void) handleGesture:(LVGesture*)sender event:(UIEvent*) event eventType:(NSInteger) eventType{ + lua_State* l = self.lv_luaviewCore.l; + if ( l ){ + lua_settop(l, 0); + lua_checkstack32(l); + + if( self.onTouchEventCallback ) { + LVEvent* lvEvent = nil; + lvEvent = [LVEvent createLuaEvent:l event:event gesture:self]; + lvEvent.eventType = eventType; + self.onTouchEventCallback(self,1); + lvEvent.event = nil; + } else { + lv_pushUserdata(l,self.lv_userData); + } + [LVUtil call:l lightUserData:self key1:"callback" key2:NULL nargs:1]; + } +} + +- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ + [super touchesBegan:touches withEvent:event]; + [self handleGesture:self event:event eventType:LVTouchEventType_DOWN]; +} + +- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{ + [super touchesMoved:touches withEvent:event]; + [self handleGesture:self event:event eventType:LVTouchEventType_MOVE]; +} + +- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{ + [super touchesEnded:touches withEvent:event]; + [self handleGesture:self event:event eventType:LVTouchEventType_MOVE]; + [self handleGesture:self event:event eventType:LVTouchEventType_UP]; + +} + +- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{ + [super touchesCancelled:touches withEvent:event]; + [self handleGesture:self event:event eventType:LVTouchEventType_CANCEL]; +} + + +static void releaseUserData(LVUserDataInfo * user){ + if( user && user->object ){ + UIGestureRecognizer* gesture = CFBridgingRelease(user->object); + user->object = NULL; + if( gesture ){ + gesture.lv_luaviewCore = nil; + gesture.lv_userData = NULL; + } + } +} + +static int __GC (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + releaseUserData(user); + return 0; +} + + +static int __tostring (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIGestureRecognizer* gesture = (__bridge UIGestureRecognizer *)(user->object); + NSString* s = [NSString stringWithFormat:@"LVUserDataGesture: %@", gesture ]; + lua_pushstring(L, s.UTF8String); + return 1; + } + return 0; +} + +static int location (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIGestureRecognizer* gesture = (__bridge UIGestureRecognizer *)(user->object); + CGPoint p = [gesture locationInView:gesture.view]; + lua_pushnumber(L, p.x); + lua_pushnumber(L, p.y); + return 2; + } + return 0; +} + +static int state (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIGestureRecognizer* gesture = (__bridge UIGestureRecognizer *)(user->object); + NSInteger state = gesture.state; + lua_pushnumber(L, state); + return 1; + } + return 0; +} + +static int nativeGesture (lua_State *L) { + LVUserDataInfo * userData = (LVUserDataInfo *)lua_touserdata(L, 1); + if( userData ){ + UIGestureRecognizer* gesture = (__bridge UIGestureRecognizer *)(userData->object); + if( gesture && [gesture isKindOfClass:[UIGestureRecognizer class]] ){ + lv_pushNativeObjectWithBox(L, gesture); + return 1; + } + } + return 0; +} + +static const struct luaL_Reg baseMemberFunctions [] = { + {"nativeGesture", nativeGesture }, + + {"location", location }, + {"state", state }, + {"__gc", __GC }, + {"__tostring", __tostring }, + {NULL, NULL} +}; + ++(const luaL_Reg*) baseMemberFunctions{ + return baseMemberFunctions; +} + ++(void) releaseUD:(LVUserDataInfo *) user{ + releaseUserData(user); +} + +static int lvNewGesture (lua_State *L) { + { + Class c = [LVUtil upvalueClass:L defaultClass:[LVGesture class]]; + + LVGesture* gesture = [[c alloc] init:L]; + + if( lua_type(L, 1) != LUA_TNIL ) { + [LVUtil registryValue:L key:gesture stack:1]; + } + + { + NEW_USERDATA(userData, Gesture); + gesture.lv_userData = userData; + userData->object = CFBridgingRetain(gesture); + + luaL_getmetatable(L, META_TABLE_Gesture ); + lua_setmetatable(L, -2); + } + } + return 1; /* new userdatum is already on the stack */ +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + + [LVUtil reg:L clas:self cfunc:lvNewGesture globalName:globalName defaultName:@"Gesture"]; + + lv_createClassMetaTable(L, META_TABLE_Gesture); + + luaL_openlib(L, NULL, [LVGesture baseMemberFunctions], 0); + lua_settop(L, 0); + { + NSDictionary* v = nil; + v = @{ + @"POSSIBLE":@(UIGestureRecognizerStatePossible), + @"BEGIN":@(UIGestureRecognizerStateBegan), + @"CHANGED":@(UIGestureRecognizerStateChanged), + @"END":@(UIGestureRecognizerStateEnded), + @"CANCEL":@(UIGestureRecognizerStateCancelled), + @"FAILED":@(UIGestureRecognizerStateFailed), + }; + [LVUtil defineGlobal:@"GestureState" value:v L:L]; + } + + return 0; +} + +// delegate + +- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{ + if( gestureRecognizer ==self ) { + return YES; + } + return NO; +} + +- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{ + return YES; +} + +- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{ + if( gestureRecognizer ==self ) { + return YES; + } + return NO; +} + +- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceivePress:(UIPress *)press{ + if( gestureRecognizer ==self ) { + return YES; + } + return NO; +} + + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVGrammarChanger.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVGrammarChanger.h new file mode 100644 index 00000000..de45ed03 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVGrammarChanger.h @@ -0,0 +1,17 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import + + + +extern NSData* lv_toStandLuaGrammar(NSData* data); + + +@interface LVGrammarChanger : NSObject +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVGrammarChanger.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVGrammarChanger.m new file mode 100644 index 00000000..b046d1bc --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVGrammarChanger.m @@ -0,0 +1,209 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVGrammarChanger.h" + +@implementation LVGrammarChanger + +@end + + + +// ‘.’ 和‘:’ 相互转化代码 +#define LV_TYPE_WORD_FIRST (1) +#define LV_TYPE_WORD_SECOND (2) +#define LV_TYPE_NUMBER (4) +#define LV_TYPE_CHAR_SPACE (8) +#define LV_TYPE_CHAR_NOTES (16) +#define LV_TYPE_CHAR_POINT (32) + +static int g_charTypes[256] = {0}; +static void charTypesInited(){ + g_charTypes['_'] = LV_TYPE_WORD_FIRST|LV_TYPE_WORD_SECOND; + for( char c = 'a'; c<='z'; c++ ) { + g_charTypes[c] = LV_TYPE_WORD_FIRST|LV_TYPE_WORD_SECOND; + } + for( char c = 'A'; c<='Z'; c++ ) { + g_charTypes[c] = LV_TYPE_WORD_FIRST|LV_TYPE_WORD_SECOND; + } + for( char c = '0'; c<='9'; c++ ) { + g_charTypes[c] = LV_TYPE_NUMBER | LV_TYPE_WORD_SECOND; + } + g_charTypes[' '] = LV_TYPE_CHAR_SPACE; + g_charTypes['\n'] = LV_TYPE_CHAR_SPACE; + g_charTypes['.'] = LV_TYPE_CHAR_POINT; + g_charTypes[':'] = LV_TYPE_CHAR_POINT; + g_charTypes['-'] = LV_TYPE_CHAR_NOTES; +} + +inline static NSInteger skipNotes(const unsigned char* cs, NSInteger i, NSInteger length){ + for( int m=0 ; m<2 && i0 ) { + NSInteger length = data.length; + unsigned char* cs = malloc(length+64); + memset(cs, 0, length+64); + [data getBytes:cs length:length]; + for ( NSInteger i=0; ii ) { + i = i2; + i = skipSpace(cs, i, length); + if( checkNextChar(cs, i, length, '(') || checkNextChar(cs, i, length, '{') ) { + unsigned char tempChar = cs[i0]; + if( (char)tempChar=='.' ) { + cs[i0] = ':'; + } else { + cs[i0] = '.'; + } + break; + } + } + } + break; + } + + default: + i = skipOther(cs, i, length); + break; + } + + } + NSData* newData = [[NSData alloc] initWithBytes:cs length:length]; + free(cs); + return newData; + } + return nil; +} diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVHeads.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVHeads.h new file mode 100644 index 00000000..8215e6e9 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVHeads.h @@ -0,0 +1,226 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#ifndef JU_LVHeads_h +#define JU_LVHeads_h +//-------------------------------------------------------------------------------- + +#import + +#import "lua.h" +#import "lauxlib.h" +#import "lualib.h" +#import "lstate.h" +#import "lgc.h" +#import "lapi.h" + +/** + * the index of signed scripts' extionsion(@"lv") in LVScriptExts[] + */ +extern const int LVSignedScriptExtIndex; + +/** + * supported script extensions: { @"lv", @"lua" } + */ +extern NSString * const LVScriptExts[2]; + +#import "LVUtil.h" +#import "LVGrammarChanger.h" +//-------------------------------------------------------------------------------- +#define LV_ALIGN_LEFT (1) +#define LV_ALIGN_H_CENTER (2) +#define LV_ALIGN_RIGHT (4) + +#define LV_ALIGN_TOP (8) +#define LV_ALIGN_V_CENTER (16) +#define LV_ALIGN_BOTTOM (32) + +//------------------------------ +#define LVReleaseAndNull( a ) if(a) { CFRelease(a); a = NULL; } +//------------------------------ + + +#define USERDATA_KEY_DELEGATE 1 +#define USERDATA_KEY_CALLBACK 2 +#define USERDATA_FLEX_DELEGATE 8 + +//---------------创建用户数据------------------------------------------------------- +#define NEW_USERDATA(var, typeName) \ + LVUserDataInfo* var = ( (LVUserDataInfo*)lua_newuserdata( L, sizeof(LVUserDataInfo)) ); \ + lv_createUDataLuatable(L,-1);\ + var->type = LVType_##typeName; \ + var->isWindow = 0; \ +// + + +//----------------用户数据的类型检查-----i-------------------------------------------- +#define LVIsType( user,T) (user && user->type==LVType_##T) + +//----------------用户数据类型 ID--------------------------------------------------- + +extern const char* LVType_View; +extern const char* LVType_Data; +extern const char* LVType_Date; +extern const char* LVType_Http; +extern const char* LVType_Timer; +extern const char* LVType_Transform3D; +extern const char* LVType_Animator; +extern const char* LVType_Gesture; +extern const char* LVType_Downloader; +extern const char* LVType_AudioPlayer; +extern const char* LVType_StyledString; +extern const char* LVType_NativeObject; +extern const char* LVType_Struct; +extern const char* LVType_Canvas; +extern const char* LVType_Event; + + +//----------------View的用户数据结构------------------------------------------------ +typedef struct _LVUserDataInfo { + const char* type;// 用户类型 + const void* object;// 真实的用户对象 + int isWindow; +} LVUserDataInfo; + +//-------------------------------------------------------------------------------- +@class LuaViewCore; +@protocol LVProtocal +@required +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; +- (id) lv_nativeObject; // 返回native对象 +@end + +@protocol LVClassProtocal +@required ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +@end + + +//-----------------------metatable------------------------------------------------ +#define META_TABLE_UIButton "UI.Button" +#define META_TABLE_UIScrollView "UI.ScrollView" +#define META_TABLE_UIView "UI.View" +#define META_TABLE_LuaView "UI.LuaView" +#define META_TABLE_CustomPanel "UI.CustomPanel" +#define META_TABLE_CustomView "UI.CustomView" +#define META_TABLE_Canvas "UI.Canvas" +#define META_TABLE_Event "UI.Event" +#define META_TABLE_EventFunc "UI.EventFunc" +#define META_TABLE_UIViewNewIndex "UI.View.NewIndex" +#define META_TABLE_PagerIndicator "UI.PagerIndicator" +#define META_TABLE_LoadingIndicator "UI.LoadingIndicator" +#define META_TABLE_UIImageView "UI.ImageView" +#define META_TABLE_UIWebView "UI.WebView" +#define META_TABLE_UILabel "UI.Label" +#define META_TABLE_UITextField "UI.TextField" +#define META_TABLE_UITableView "UI.TableView" +#define META_TABLE_UITableViewCell "UI.TableView.Cell" +#define META_TABLE_UICollectionView "UI.CollectionView" +#define META_TABLE_UICollectionViewCell "UI.CollectionView.Cell" +#define META_TABLE_UIPageView "UI.PagerView" +#define META_TABLE_UIAlertView "UI.AlertView" +#define META_TABLE_Transform3D "UI.Transfrom3D" +#define META_TABLE_Animator "UI.Animator" + +#define META_TABLE_Timer "LV.Timer" +#define META_TABLE_Http "LV.Http" +#define META_TABLE_Gesture "LV.Gesture" +#define META_TABLE_PanGesture "LV.Pan.Gesturer" +#define META_TABLE_TapGesture "LV.Tap.Gesture" +#define META_TABLE_PinchGesture "LV.Pinch.Gesture" +#define META_TABLE_RotaionGesture "LV.Rotaion.Gesture" +#define META_TABLE_SwipeGesture "LV.Swipe.Gesture" +#define META_TABLE_LongPressGesture "LV.LongPress.Gesture" +#define META_TABLE_Date "LV.Date" +#define META_TABLE_Data "LV.Data" +#define META_TABLE_Struct "LV.Struct" +#define META_TABLE_Downloader "LV.Downloader" +#define META_TABLE_AudioPlayer "LV.AudioPlayer" +#define META_TABLE_AttributedString "LV.AttributedString" +#define META_TABLE_NativeObject "LV.nativeObjBox" +#define META_TABLE_System "LV.System" + +#define STR_CALLBACK "Callback" +#define STR_ON_LAYOUT "onLayout" +#define STR_ON_CLICK "onClick" +#define STR_ON_DRAW "onDraw" +#define STR_ON_TOUCH "onTouch" +#define STR_onPageStarted "onPageStarted" +#define STR_onPageFinished "onPageFinished" +#define STR_onReceivedError "onReceivedError" + +// lua对象 -> NSString +NSString* lv_paramString(lua_State* L, int idx ); + +// run +NSString* lv_runFunction(lua_State* l); +NSString* lv_runFunctionWithArgs(lua_State* l, int nargs, int nret); + + + +//-------------------------------------------------------------------------------- +@interface LVHeads : NSObject +@end + + +typedef enum:int{ + LVTypeID_NONE = 0, + LVTypeID_void, + LVTypeID_BOOL, + LVTypeID_bool, + LVTypeID_char, + LVTypeID_unsignedchar, + LVTypeID_short, + LVTypeID_unsignedshort, + LVTypeID_int, + LVTypeID_unsignedint, + LVTypeID_NSInteger, + LVTypeID_NSUInteger, + LVTypeID_longlong, + LVTypeID_unsigedlonglong, + LVTypeID_float, + LVTypeID_CGFloat, + LVTypeID_double, + LVTypeID_charP, + LVTypeID_voidP, + LVTypeID_id, + LVTypeID_Class, + LVTypeID_idP, + LVTypeID_struct, +}LVTypeIDEnum; + + +LVTypeIDEnum lua_typeID(const char* type); + +#define isNormalRect(r) ( !( isnan(r.origin.x) || isnan(r.origin.y) || isnan(r.size.width) || isnan(r.size.height) ) ) +#define isNormalSize(s) ( !( isnan(s.width) || isnan(s.height) ) ) +#define isNormalPoint(p) ( !( isnan(p.x) || isnan(p.y) ) ) +#define isNormalEdgeInsets(e) ( !( isnan(e.top) || isnan(e.left) || isnan(e.bottom) || isnan(e.right) ) ) + + +typedef void(^LVLoadFinished)(id errorInfo); + +#import "UIView+LuaView.h" +#import "NSObject+LuaView.h" +#import "UIScrollView+LuaView.h" +#import "LVBundle.h" + +#define EFFECT_NONE 0 +#define EFFECT_CLICK 1 +#define EFFECT_PARALLAX 2 + +#define LV_LUASTATE_VIEW(L) ( (__bridge LuaViewCore *)( G(L)->ud ) ) +#define LUAVIEW_SYS_TABLE_KEY "..::luaview::.." + +#ifndef MakeSureNotNil +#define MakeSureNotNil(__obj) ((__obj) ? (__obj) : @"") +#endif + +#endif diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVHeads.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVHeads.m new file mode 100644 index 00000000..acd9739c --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVHeads.m @@ -0,0 +1,33 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVHeads.h" + + +@implementation LVHeads + +NSString * const LVScriptExts[] = {@"lv", @"lua"}; +const int LVSignedScriptExtIndex = 0; + +const char* LVType_View = "LVType_UserDataView"; +const char* LVType_Data = "LVType_UserDataData"; +const char* LVType_Date = "LVType_UserDataDate"; +const char* LVType_Http = "LVType_UserDataHttp"; +const char* LVType_Timer = "LVType_UserDataTimer"; +const char* LVType_Transform3D = "LVType_UserDataTransform3D"; +const char* LVType_Animator = "LVType_UserDataAnimator"; +const char* LVType_Gesture = "LVType_UserDataGesture"; +const char* LVType_Downloader = "LVType_UserDataDownloader"; +const char* LVType_AudioPlayer = "LVType_UserDataAudioPlayer"; +const char* LVType_StyledString = "LVType_UserDataStyledString"; +const char* LVType_NativeObject = "LVType_UserDataNativeObject"; +const char* LVType_Struct = "LVType_UserDataStruct"; +const char* LVType_Canvas = "LVType_UserDataCanvas"; +const char* LVType_Event = "LVType_UserDataEvent"; + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVHttp.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVHttp.h new file mode 100644 index 00000000..8abfe042 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVHttp.h @@ -0,0 +1,27 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + + +@interface LVHttp : NSObject + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; + +-(id) init:(lua_State*) l; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +/* + * https检查是否是信任的域名, 改方法 可以被覆盖 + */ ++(BOOL) isTrustedHost:(NSString*) host; + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVHttp.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVHttp.m new file mode 100644 index 00000000..40f79e8a --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVHttp.m @@ -0,0 +1,323 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVHttp.h" +#import "LVHttpResponse.h" +#import "LVData.h" +#import "LView.h" +#import "LVHeads.h" + +@interface LVHttp () +@property(nonatomic,strong) id mySelf; +@property(nonatomic,strong) LVHttpResponse* response; +@property(nonatomic,strong) id function; +@property(nonatomic,assign) CGFloat timeout; +@property(nonatomic,strong) NSURLConnection* connection; +@end + +@implementation LVHttp + +static void releaseUserDataHttp(LVUserDataInfo* user){ + if( user && user->object ){ + LVHttp* http = CFBridgingRelease(user->object); + user->object = NULL; + if( http ){ + http.lv_userData = NULL; + http.lv_luaviewCore = nil; + http.mySelf = nil; + } + } +} + +-(void) dealloc{ +} + +-(id) init:(lua_State*) l{ + self = [super init]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + self.mySelf = self; + self.function = [[NSMutableString alloc] init]; + self.response = [[LVHttpResponse alloc] init]; + self.timeout = 30.0; + } + return self; +} + +-(void) requesetEndToDo{ + lua_State* l = self.lv_luaviewCore.l; + if( l ){ + lua_checkstack32(l); + [LVUtil pushRegistryValue:l key:self]; + [LVUtil call:l lightUserData:self.function key1:"callback" key2:NULL nargs:1]; + [LVUtil unregistry:l key:self]; + } + self.response = nil; + self.mySelf = nil; +} + +- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace { + return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]; +} + + ++(BOOL) isTrustedHost:(NSString*) host{ + NSArray* trustedHosts = @[@".alicdn.com",@".tbcdn.com",@".taobao.com",@".tmall.com",@".juhuasuan.com"]; + for( NSString* host in trustedHosts ) { + if( [host hasSuffix:host] ) { + return YES; + } + } + return NO; +} + +- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge { + if ( [challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust] ){ + if ( [LVHttp isTrustedHost:challenge.protectionSpace.host] ) { + [challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge]; + } + } + [challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge]; +} + +-(void) connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{ + self.response.error = error; + [self performSelectorOnMainThread:@selector(requesetEndToDo) withObject:nil waitUntilDone:NO]; +} + +-(void) connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{ + if( self.response.data == nil ) { + self.response.data = [[NSMutableData alloc] init]; + } + [self.response.data appendData:data]; +} + +-(void) connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{ + self.response.response = response; + if( [response isKindOfClass:[NSHTTPURLResponse class]] ){ + self.response.httpResponse = (NSHTTPURLResponse*)response; + } +} +-(void) connectionDidFinishLoading:(NSURLConnection *)connection{ + [self performSelectorOnMainThread:@selector(requesetEndToDo) withObject:nil waitUntilDone:NO]; +} + +-(void) connectionDidReceiveData:(NSData *)data{ + if( self.response.data == nil ) { + self.response.data = [[NSMutableData alloc] init]; + } + [self.response.data appendData:data]; +} + +-(void) connectionDidReceiveResponse:(NSURLResponse *)response{ + self.response.response = response; + if( [response isKindOfClass:[NSHTTPURLResponse class]] ){ + self.response.httpResponse = (NSHTTPURLResponse*)response; + } +} +-(void) connectionDidFinishLoading{ + [self performSelectorOnMainThread:@selector(requesetEndToDo) withObject:nil waitUntilDone:NO]; +} + +-(id) lv_nativeObject{ + return self; +} + +static int lvNewHttpObject (lua_State *L ) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVHttp class]]; + + LVHttp* http = [[c alloc] init:L]; + { + NEW_USERDATA(userData, Http); + userData->object = CFBridgingRetain(http); + http.lv_userData = userData; + + luaL_getmetatable(L, META_TABLE_Http ); + lua_setmetatable(L, -2); + } + [LVUtil registryValue:L key:http stack:-1]; + return 1; +} + +static int get (lua_State *L) { + int argN = lua_gettop(L); + if( argN>=2 ){ + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( LVIsType(user, Http) ) { + LVHttp* http = (__bridge LVHttp *)(user->object); + NSString* urlStr = lv_paramString(L, 2); + + if( lua_type(L, 3) != LUA_TNIL ) { + [LVUtil registryValue:L key:http.function stack:3]; + } + NSURL *url = [NSURL URLWithString:urlStr]; + NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; + [request setHTTPMethod:@"GET"]; + [request setTimeoutInterval:http.timeout]; + + NSOperationQueue *queue = [[NSOperationQueue alloc]init]; + __weak LVHttp* weakHttp = http; + [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) { + [weakHttp connectionDidReceiveResponse:response]; + [weakHttp connectionDidReceiveData:data]; + [weakHttp connectionDidFinishLoading]; + }]; + } + } + return 0; /* new userdatum is already on the stack */ +} + +static int post (lua_State *L) { + int argN = lua_gettop(L); + if( argN>=3 ){ + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( LVIsType(user, Http) ) { + // 1:url 2:heads 3:data 4:callback + NSString* urlStr = lv_paramString(L, 2); + LVHttp* http = (__bridge LVHttp *)(user->object); + NSDictionary* dic = nil; + NSData* data = nil; + for( int i=3 ; i<=argN ; i++ ) { + int type = lua_type(L, i); + if( type==LUA_TSTRING ) {// 数据 + NSString* s = lv_paramString(L, i); + data = [s dataUsingEncoding:NSUTF8StringEncoding]; + } + if( type==LUA_TTABLE ) {// 数据 + id tempDic = lv_luaTableToDictionary(L, i); + NSString* s = [LVUtil objectToString:tempDic]; + data = [s dataUsingEncoding:NSUTF8StringEncoding]; + } + + if( type==LUA_TFUNCTION ) { + [LVUtil registryValue:L key:http.function stack:4]; + } + } + NSURL *url = [NSURL URLWithString:urlStr]; + NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; + [request setHTTPMethod:@"POST"]; + [request setTimeoutInterval:http.timeout]; + + // http头信息 + if( dic.count>0 ){ + for (NSString *key in dic) { + NSString* value = dic[key]; + [request setValue:value forHTTPHeaderField:key]; + } + } + + // data + if( data.length>0 ){ + [request setHTTPBody:data]; + } + + NSOperationQueue *queue = [[NSOperationQueue alloc]init]; + __weak LVHttp* weakHttp = http; + [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) { + [weakHttp connectionDidReceiveResponse:response]; + [weakHttp connectionDidReceiveData:data]; + [weakHttp connectionDidFinishLoading]; + }]; + } + } + return 0; /* new userdatum is already on the stack */ +} + +static int __gc (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + releaseUserDataHttp(user); + return 0; +} + +static int __tostring (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user && LVIsType(user, Http) ){ + LVHttp* http = (__bridge LVHttp *)(user->object); + NSString* s = [NSString stringWithFormat:@"LVUserDataHttp: %@\n response.data.length=%ld\n error:%@", + http.response.response, + (long)http.response.data.length, + http.response.error ]; + lua_pushstring(L, s.UTF8String); + return 1; + } + return 0; +} + +static int data (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user && LVIsType(user, Http) ){ + LVHttp* http = (__bridge LVHttp *)(user->object); + // NSString* s = [NSString stringWithFormat:@"LVUserDataHttp: %@\n response.data.length=%ld\n error:%@", + // http.response.response, + // http.response.data.length, + // http.response.error ]; + return [LVData createDataObject:L data:http.response.data]; + } + return 0; +} +static int responseStatusCode (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user && LVIsType(user, Http) ){ + LVHttp* http = (__bridge LVHttp *)(user->object); + NSHTTPURLResponse* httpResponse = http.response.httpResponse; + lua_pushnumber(L, httpResponse.statusCode); + return 1; + } + return 0; +} +static int responseHeaderFields (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user && LVIsType(user, Http) ){ + LVHttp* http = (__bridge LVHttp *)(user->object); + NSHTTPURLResponse* response = http.response.httpResponse; + lv_pushNativeObject(L,response.allHeaderFields); + return 1; + } + return 0; +} +static int cancel (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user && LVIsType(user, Http) ){ + LVHttp* http = (__bridge LVHttp *)(user->object); + [http.connection cancel]; + return 0; + } + return 0; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + { + const struct luaL_Reg memberFunctions [] = { + {"__gc", __gc }, + + {"__tostring", __tostring }, + + {"data", data }, + {"code", responseStatusCode }, + {"header", responseHeaderFields }, + // IOS: meesage 服务端错误信息 + // timeout + // retryTimes + + {"get", get }, + {"post", post }, + + {"cancel", cancel }, + + {NULL, NULL} + }; + + lv_createClassMetaTable(L, META_TABLE_Http); + + luaL_openlib(L, NULL, memberFunctions, 0); + } + [LVUtil reg:L clas:self cfunc:lvNewHttpObject globalName:globalName defaultName:@"Http"]; + return 1; +} + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVHttpResponse.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVHttpResponse.h new file mode 100644 index 00000000..0bc65809 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVHttpResponse.h @@ -0,0 +1,18 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import + +@interface LVHttpResponse : NSObject + +@property(nonatomic,strong) NSURLResponse *response; +@property(nonatomic,strong) NSHTTPURLResponse *httpResponse; +@property(nonatomic,strong) NSMutableData *data; +@property(nonatomic,strong) NSError *error; + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVHttpResponse.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVHttpResponse.m new file mode 100644 index 00000000..8fffcb9e --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVHttpResponse.m @@ -0,0 +1,13 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVHttpResponse.h" + +@implementation LVHttpResponse + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVImage.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVImage.h new file mode 100644 index 00000000..be97771e --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVImage.h @@ -0,0 +1,41 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" +#import "LView.h" + + +@interface LVImage : UIImageView + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; +@property(nonatomic,assign) NSUInteger lv_align; +@property(nonatomic,strong) CAShapeLayer* lv_shapeLayer; + +-(id) init:(lua_State*) l; + +-(void) setImageByName:(NSString*) imageName; +-(void) setImageByData:(NSData*) data; +-(void) setWebImageUrl:(NSURL*) url finished:(LVLoadFinished) finished; +-(void) effectParallax:(CGFloat)dx dy:(CGFloat)dy ; +-(void) effectClick:(NSInteger)color alpha:(CGFloat)alpha; + +/* + * Lua 脚本回调 + */ +-(void) callLuaDelegate:(id) obj; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +/** + * 图片首次出现是否使用动画 + */ +@property (nonatomic,assign) BOOL disableAnimate; + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVImage.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVImage.m new file mode 100644 index 00000000..ca5d6375 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVImage.m @@ -0,0 +1,295 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVImage.h" +#import "LVBaseView.h" +#import "LVUtil.h" +#import "LVData.h" +#import +#import "LVNinePatchImage.h" +#import "LVHeads.h" + +@interface LVImage () +@property (nonatomic,strong) id functionTag; +@property (nonatomic,strong) UIImageView* blurImageView; +@property (nonatomic,strong) UIVisualEffectView *blurEffectView; +@property (nonatomic,assign) BOOL needCallLuaFunc; +@property (nonatomic,strong) UITapGestureRecognizer* tapGesture; +@property (nonatomic,strong) id errorInfo; +@property(nonatomic,assign) BOOL lv_isCallbackAddClickGesture;// 支持Callback 点击事件 +@end + +@implementation LVImage + + +-(id) init:(lua_State*) l{ + self = [super init]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + self.contentMode = UIViewContentModeScaleAspectFill; + self.functionTag = [[NSMutableString alloc] init]; + self.backgroundColor = [UIColor clearColor]; + self.clipsToBounds = YES; + self.lv_isCallbackAddClickGesture = YES; + self.disableAnimate = self.lv_luaviewCore.disableAnimate; + } + return self; +} + +-(void) setWebImageUrl:(NSURL*) url finished:(LVLoadFinished) finished{ +} + +-(void) callLuaDelegate:(id) obj{ + lua_State* L = self.lv_luaviewCore.l; + if( L ) { + lua_checkstack(L, 4); + lua_pushboolean(L, obj?0:1); + [LVUtil pushRegistryValue:L key:self.functionTag]; + lv_runFunctionWithArgs(L, 1, 0); + } + [LVUtil unregistry:L key:self.functionTag]; +} + +-(void) setImageByName:(NSString*) imageName{ + if( imageName==nil ) + return; + + if( [LVUtil isExternalUrl:imageName] ){ + //CDN image + __weak LVImage* weakImageView = self; + [self setWebImageUrl:[NSURL URLWithString:imageName] finished:^(id errorInfo){ + if( weakImageView.needCallLuaFunc ) { + weakImageView.errorInfo = errorInfo; + [weakImageView performSelectorOnMainThread:@selector(callLuaDelegate:) withObject:errorInfo waitUntilDone:NO]; + } + }]; + } else { + // local Image + UIImage* image = [self.lv_luaviewCore.bundle imageWithName:imageName]; + if ( [LVNinePatchImage isNinePathImageName:imageName] ) { + image = [LVNinePatchImage createNinePatchImage:image]; + [self setImage:image]; + } else { + [self setImage:image]; + } + } +} + +-(void) lv_effectParallax:(CGFloat)dx dy:(CGFloat)dy{ + [self effectParallax:dx dy:dy]; +} + +-(void) effectParallax:(CGFloat)dx dy:(CGFloat)dy { +} + +-(void) effectClick:(NSInteger)color alpha:(CGFloat)alpha { +} + +-(void) setImageByData:(NSData*) data{ + if ( data ) { + UIImage* image = [[UIImage alloc] initWithData:data]; + [self setImage:image]; + } +} + +-(void) canelWebImageLoading{ + // [self cancelCurrentImageLoad]; // 取消上一次CDN加载 +} +-(void) cancelImageLoadAndClearCallback:(lua_State*)L{ + [self canelWebImageLoading]; + [NSObject cancelPreviousPerformRequestsWithTarget:self]; // 取消回调脚本 + [LVUtil unregistry:L key:self.functionTag]; // 清除脚本回调 +} + +-(void) dealloc{ + LVUserDataInfo* userData = self.lv_userData; + if( userData ){ + userData->object = NULL; + } +} + +#pragma -mark ImageView +static int lvNewImageView(lua_State *L) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVImage class]]; + + NSString* imageName = lv_paramString(L, 1); + + LVImage* imageView = [[c alloc] init:L]; + [imageView setImageByName:imageName]; + { + NEW_USERDATA(userData, View); + userData->object = CFBridgingRetain(imageView); + imageView.lv_userData = userData; + + luaL_getmetatable(L, META_TABLE_UIImageView ); + lua_setmetatable(L, -2); + } + LuaViewCore* view = LV_LUASTATE_VIEW(L); + if( view ){ + [view containerAddSubview:imageView]; + } + return 1; /* new userdatum is already on the stack */ +} + +static int setImage (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVImage* imageView = (__bridge LVImage *)(user->object); + if ( [imageView isKindOfClass:[LVImage class]] ) { + [imageView cancelImageLoadAndClearCallback:L]; + if( lua_type(L, 3) == LUA_TFUNCTION ) { + [LVUtil registryValue:L key:imageView.functionTag stack:3]; + imageView.needCallLuaFunc = YES; + } else { + imageView.needCallLuaFunc = NO; + } + if ( lua_type(L, 2)==LUA_TSTRING ) { + NSString* imageName = lv_paramString(L, 2);// 2 + if( imageName ){ + [imageView setImageByName:imageName]; + lua_pushvalue(L,1); + return 1; + } + } else if ( lua_type(L, 2)==LUA_TUSERDATA ) { + LVUserDataInfo * userdata = (LVUserDataInfo *)lua_touserdata(L, 2); + LVData* lvdata = (__bridge LVData *)(userdata->object); + if( LVIsType(userdata, Data) ) { + [imageView setImageByData:lvdata.data]; + lua_pushvalue(L,1); + return 1; + } + } else { + // 清理图片 + imageView.image = nil; + } + } + } + return 0; +} + +static int scaleType (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVImage* imageView = (__bridge LVImage *)(user->object); + if ( [imageView isKindOfClass:[LVImage class]] ) { + if( lua_gettop(L)>=2 ) { + int model = lua_tonumber(L, 2);// 2 + [imageView setContentMode:model]; + return 0; + } else { + UIViewContentMode model = imageView.contentMode; + lua_pushnumber(L, model); + return 1; + } + } + } + return 0; +} + +static int startAnimating (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( L && user ){ + LVImage* imageView = (__bridge LVImage *)(user->object); + if ( [imageView isKindOfClass:[LVImage class]] ) { + NSArray* urlArray = lv_luaTableToArray(L,2); + float repeatCount = 1; + float duration = 0.3; + if( lua_gettop(L)>=3 ){ + duration = lua_tonumber(L, 3); + } + if( lua_gettop(L)>=4 ){ + repeatCount = lua_tonumber(L, 4); + } + LuaViewCore* lview = LV_LUASTATE_VIEW(L); + LVBundle* bundle = lview.bundle; + NSMutableArray *arrayM=[NSMutableArray array]; + for (NSString* url in urlArray) { + UIImage* image = [bundle imageWithName:url]; + if( image ) { + [arrayM addObject:image]; + } + } + [imageView setAnimationImages:arrayM];//设置动画数组 + [imageView setAnimationDuration:duration];//设置动画播放时间 + [imageView setAnimationRepeatCount:repeatCount];//设置动画播放次数 + [imageView startAnimating];//开始动画 + } + } + return 0; +} + +static int stopAnimating (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVImage* imageView = (__bridge LVImage *)(user->object); + if ( [imageView isKindOfClass:[LVImage class]] ) { + [imageView stopAnimating]; + return 0; + } + } + return 0; +} + +static int isAnimating (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVImage* imageView = (__bridge LVImage *)(user->object); + if ( [imageView isKindOfClass:[LVImage class]] ) { + lua_pushboolean(L, imageView.isAnimating?1:0); + return 1; + } + } + lua_pushboolean(L, 0); + return 1; +} + +static int disableAnimate (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVImage* imageView = (__bridge LVImage *)(user->object); + if ( [imageView isKindOfClass:[LVImage class]] ) { + BOOL disableAnimate = lua_toboolean(L, 2); + imageView.disableAnimate = disableAnimate; + } + } + return 0; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + + [LVUtil reg:L clas:self cfunc:lvNewImageView globalName:globalName defaultName:@"Image"]; + + const struct luaL_Reg memberFunctions [] = { + {"image", setImage}, + {"scaleType", scaleType}, + + {"startAnimationImages", startAnimating},//__deprecated_msg("") + {"stopAnimationImages", stopAnimating},//__deprecated_msg("") + {"isAnimationImages", isAnimating},//__deprecated_msg("") + + {"disableAnimate", disableAnimate},//__deprecated_msg("") + {NULL, NULL} + }; + + lv_createClassMetaTable(L, META_TABLE_UIImageView); + + luaL_openlib(L, NULL, [LVBaseView baseMemberFunctions], 0); + luaL_openlib(L, NULL, memberFunctions, 0); + + const char* keys[] = { "addView", NULL};// 移除多余API + lv_luaTableRemoveKeys(L, keys ); + return 1; +} + + +//---------------------------------------------------------------------------------------- +-(NSString*) description{ + return [NSString stringWithFormat:@"", (int)[self hash], NSStringFromCGRect(self.frame) ]; +} + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLabel.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLabel.h new file mode 100644 index 00000000..5f7b4664 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLabel.h @@ -0,0 +1,23 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + +@interface LVLabel : UILabel + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; +@property(nonatomic,assign) NSUInteger lv_align; +@property(nonatomic,strong) CAShapeLayer* lv_shapeLayer; + +-(id) init:(NSString*)imageName l:(lua_State*) l; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLabel.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLabel.m new file mode 100644 index 00000000..49a619da --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLabel.m @@ -0,0 +1,281 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ +#import "LVLabel.h" +#import "LVBaseView.h" +#import "LView.h" +#import "LVStyledString.h" +#import "LVHeads.h" + +@interface LVLabel () +@property(nonatomic,assign) BOOL lv_isCallbackAddClickGesture;// 支持Callback 点击事件 +@end + +@implementation LVLabel + + +-(id) init:(NSString*)imageName l:(lua_State*) l{ + self = [super init]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + self.text = imageName; + self.backgroundColor = [UIColor clearColor]; + self.textAlignment = NSTextAlignmentLeft; + self.lv_isCallbackAddClickGesture = YES; + self.clipsToBounds = YES; + self.font = [UIFont systemFontOfSize:14];// 默认字体大小 + } + return self; +} + +-(void) dealloc{ +} + +#pragma -mark UILabel +static int lvNewLabel(lua_State *L) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVLabel class]]; + { + NSString* text = lv_paramString(L, 1);// 5 + LVLabel* label = [[c alloc] init:text l:L]; + + { + NEW_USERDATA(userData, View); + userData->object = CFBridgingRetain(label); + label.lv_userData = userData; + + luaL_getmetatable(L, META_TABLE_UILabel ); + lua_setmetatable(L, -2); + } + LuaViewCore* view = LV_LUASTATE_VIEW(L); + if( view ){ + [view containerAddSubview:label]; + } + } + return 1; /* new userdatum is already on the stack */ +} + +static int text (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ) { + LVLabel* view = (__bridge LVLabel *)(user->object); + if ( [view isKindOfClass:[LVLabel class]] ) { + if( lua_gettop(L)>=2 ) { + if ( lua_isnoneornil(L, 2 ) ) { + view.text = nil; + } else if( lua_type(L, 2)==LUA_TNUMBER ){ + CGFloat text = lua_tonumber(L, 2);// 2 + view.text = [NSString stringWithFormat:@"%f",text]; + return 0; + } else if( lua_type(L, 2)==LUA_TSTRING ){ + NSString* text = lv_paramString(L, 2);// 2 + view.text = text; + return 0; + } else if( lua_type(L, 2)==LUA_TUSERDATA ){ + LVUserDataInfo * user2 = lua_touserdata(L, 2);// 2 + if( user2 && LVIsType(user2, StyledString) ) { + LVLabel* view = (__bridge LVLabel *)(user->object); + LVStyledString* attString = (__bridge LVStyledString *)(user2->object); + [view setAttributedText:attString.mutableStyledString]; + return 0; + } + } + } else { + NSString* text = view.text; + lua_pushstring(L, text.UTF8String); + return 1; + } + } + } + return 0; +} + +static int lineCount(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVLabel* view = (__bridge LVLabel *)(user->object); + if( lua_gettop(L)>=2 ) { + int number = lua_tonumber(L, 2);// 2 + if( [view isKindOfClass:[LVLabel class]] ){ + view.numberOfLines = number; + return 0; + } + } else { + lua_pushnumber(L, view.numberOfLines ); + return 1; + } + } + return 0; +} + +static int adjustFontSize(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + BOOL yes = lua_toboolean(L, 2);// 2 + LVLabel* view = (__bridge LVLabel *)(user->object); + if( [view isKindOfClass:[LVLabel class]] ){ + view.adjustsFontSizeToFitWidth = yes; + + lua_pushvalue(L,1); + return 1; + } + } + return 0; +} + +static int textColor (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVLabel* view = (__bridge LVLabel *)(user->object); + if( lua_gettop(L)>=2 ) { + if( [view isKindOfClass:[LVLabel class]] ){ + UIColor* color = lv_getColorFromStack(L, 2); + view.textColor = color; + return 0; + } + } else { + UIColor* color = view.textColor; + NSUInteger c = 0; + CGFloat a = 0; + if( lv_uicolor2int(color, &c, &a) ){ + lua_pushnumber(L, c ); + lua_pushnumber(L, a); + return 2; + } + } + } + return 0; +} + +static int font (lua_State *L) { + LuaViewCore* luaView = LV_LUASTATE_VIEW(L); + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( luaView && user ){ + LVLabel* view = (__bridge LVLabel *)(user->object); + if( [view isKindOfClass:[LVLabel class]] ){ + if( lua_gettop(L)>=2 ) { + if( lua_gettop(L)>=3 && lua_type(L, 2)==LUA_TSTRING ) { + NSString* fontName = lv_paramString(L, 2); + float fontSize = lua_tonumber(L, 3); + UIFont* font = [LVUtil fontWithName:fontName size:fontSize bundle:luaView.bundle]; + view.font = font; + } else { + float fontSize = lua_tonumber(L, 2); + view.font = [UIFont systemFontOfSize:fontSize]; + } + return 0; + } else { + UIFont* font = view.font; + NSString* fontName = font.fontName; + CGFloat fontSize = font.pointSize; + lua_pushstring(L, fontName.UTF8String); + lua_pushnumber(L, fontSize); + return 2; + } + } + } + return 0; +} + + +static int fontSize (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVLabel* view = (__bridge LVLabel *)(user->object); + if( [view isKindOfClass:[LVLabel class]] ){ + if( lua_gettop(L)>=2 ) { + float fontSize = lua_tonumber(L, 2); + view.font = [UIFont systemFontOfSize:fontSize]; + return 0; + } else { + UIFont* font = view.font; + CGFloat fontSize = font.pointSize; + lua_pushnumber(L, fontSize); + return 1; + } + } + } + return 0; +} + +static int textAlignment (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVLabel* view = (__bridge LVLabel *)(user->object); + if( lua_gettop(L)>=2 ) { + NSInteger align = lua_tonumber(L, 2);// 2 + if( [view isKindOfClass:[LVLabel class]] ){ + view.textAlignment = align; + return 0; + } + } else { + int align = view.textAlignment; + lua_pushnumber(L, align ); + return 1; + } + } + return 0; +} + +static int ellipsize (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVLabel* view = (__bridge LVLabel *)(user->object); + if( lua_gettop(L)>=2 ) { + NSInteger lineBreakMode = lua_tonumber(L, 2);// 2 + if( [view isKindOfClass:[LVLabel class]] ){ + view.lineBreakMode = lineBreakMode; + return 0; + } + } else { + int lineBreakMode = view.lineBreakMode; + lua_pushnumber(L, lineBreakMode ); + return 1; + } + } + return 0; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewLabel globalName:globalName defaultName:@"Label"]; + + const struct luaL_Reg memberFunctions [] = { + {"text", text}, + + {"textColor", textColor}, + + {"font", font}, + {"fontSize", fontSize}, + {"textSize", fontSize}, // __deprecated_msg("Use fontSize") + + {"ellipsize", ellipsize}, + {"textAlign", textAlignment}, + {"gravity", textAlignment},// 上中下 IOS 不支持,需要考虑支持 + + {"lineCount", lineCount}, // __deprecated_msg("Use lines") + // lines + + {"adjustFontSize", adjustFontSize}, + + {NULL, NULL} + }; + + lv_createClassMetaTable(L, META_TABLE_UILabel); + + luaL_openlib(L, NULL, [LVBaseView baseMemberFunctions], 0); + luaL_openlib(L, NULL, memberFunctions, 0); + + const char* keys[] = { "addView", NULL};// 移除多余API + lv_luaTableRemoveKeys(L, keys ); + return 1; +} + + +-(NSString*) description{ + return [NSString stringWithFormat:@"", (int)[self hash], NSStringFromCGRect(self.frame) ]; +} + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLoadingIndicator.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLoadingIndicator.h new file mode 100644 index 00000000..d73af1bc --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLoadingIndicator.h @@ -0,0 +1,24 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + +@interface LVLoadingIndicator : UIActivityIndicatorView + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; +@property(nonatomic,assign) NSUInteger lv_align; +@property(nonatomic,strong) CAShapeLayer* lv_shapeLayer; + +-(id) init:(lua_State*) l; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLoadingIndicator.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLoadingIndicator.m new file mode 100644 index 00000000..d09977cd --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLoadingIndicator.m @@ -0,0 +1,137 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVLoadingIndicator.h" +#import "LVBaseView.h" +#import "LView.h" +#import "LVHeads.h" + + +@implementation LVLoadingIndicator + + + +-(id) init:(lua_State*) l{ + self = [super init]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + self.clipsToBounds = YES; + self.userInteractionEnabled = NO; + } + return self; +} + +-(void) dealloc{ +} + +#pragma -mark lvNewActivityIndicator +static int lvNewLoadingIndicator (lua_State *L) { + { + Class c = [LVUtil upvalueClass:L defaultClass:[LVLoadingIndicator class]]; + + LVLoadingIndicator* pageControl = [[c alloc] init:L]; + + { + NEW_USERDATA(userData, View); + userData->object = CFBridgingRetain(pageControl); + + luaL_getmetatable(L, META_TABLE_LoadingIndicator ); + lua_setmetatable(L, -2); + } + LuaViewCore* view = LV_LUASTATE_VIEW(L); + if( view ){ + [view containerAddSubview:pageControl]; + } + } + return 1; /* new userdatum is already on the stack */ +} + +static int startAnimating(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVLoadingIndicator* view = (__bridge LVLoadingIndicator *)(user->object); + if( view ){ + [view startAnimating]; + } + } + return 0; +} + +static int stopAnimating(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVLoadingIndicator* view = (__bridge LVLoadingIndicator *)(user->object); + if( view ){ + [view stopAnimating]; + } + } + return 0; +} + +static int isAnimating(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVLoadingIndicator* view = (__bridge LVLoadingIndicator *)(user->object); + if( view ){ + lua_pushboolean(L, view.isAnimating); + return 1; + } + } + return 0; +} + +static int color(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVLoadingIndicator* view = (__bridge LVLoadingIndicator *)(user->object); + if( view ){ + if( lua_gettop(L)>=2 ) { + UIColor* color = lv_getColorFromStack(L, 2); + view.color = color; + return 0; + } else { + UIColor* color = view.color; + NSUInteger c = 0; + CGFloat a = 1; + if( lv_uicolor2int(color, &c, &a) ){ + lua_pushnumber(L, c ); + lua_pushnumber(L, a); + return 2; + } + } + } + } + return 0; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewLoadingIndicator globalName:globalName defaultName:@"LoadingIndicator"]; + + const struct luaL_Reg memberFunctions [] = { + {"start", startAnimating }, + {"stop", stopAnimating }, + {"show", startAnimating },//__deprecated_msg("Use start") + {"hide", stopAnimating },//__deprecated_msg("Use stop") + {"isAnimating", isAnimating }, + {"color", color}, + {NULL, NULL} + }; + + lv_createClassMetaTable(L, META_TABLE_LoadingIndicator); + + luaL_openlib(L, NULL, [LVBaseView baseMemberFunctions], 0); + luaL_openlib(L, NULL, memberFunctions, 0); + + const char* keys[] = { "addView", NULL};// 移除多余API + lv_luaTableRemoveKeys(L, keys ); + return 1; +} + + + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLongPressGesture.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLongPressGesture.h new file mode 100644 index 00000000..10fe1e1c --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLongPressGesture.h @@ -0,0 +1,23 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" +#import "NSObject+LuaView.h" + +@interface LVLongPressGesture : UILongPressGestureRecognizer + + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; + +-(id) init:(lua_State*) l; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLongPressGesture.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLongPressGesture.m new file mode 100644 index 00000000..b023ab83 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLongPressGesture.m @@ -0,0 +1,97 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVLongPressGesture.h" +#import "LVGesture.h" +#import "LView.h" +#import "LVHeads.h" + +@implementation LVLongPressGesture + + +-(void) dealloc{ + LVLog(@"LVLongPressGesture.dealloc"); + [LVGesture releaseUD:_lv_userData]; +} + +-(id) init:(lua_State*) l{ + self = [super initWithTarget:self action:@selector(handleGesture:)]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + } + return self; +} + +-(void) handleGesture:(LVLongPressGesture*)sender { + lua_State* l = self.lv_luaviewCore.l; + if ( l ){ + lua_checkstack32(l); + lv_pushUserdata(l,self.lv_userData); + [LVUtil call:l lightUserData:self key1:"callback" key2:NULL nargs:1]; + } +} + + +static int lvNewLongGesture (lua_State *L) { + { + Class c = [LVUtil upvalueClass:L defaultClass:[LVLongPressGesture class]]; + + LVLongPressGesture* gesture = [[c alloc] init:L]; + + if( lua_type(L, 1) != LUA_TNIL ) { + [LVUtil registryValue:L key:gesture stack:1]; + } + + { + NEW_USERDATA(userData, Gesture); + gesture.lv_userData = userData; + userData->object = CFBridgingRetain(gesture); + + luaL_getmetatable(L, META_TABLE_LongPressGesture ); + lua_setmetatable(L, -2); + } + } + return 1; /* new userdatum is already on the stack */ +} + +static int setTouchCount (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( LVIsType(user, Gesture) ){ + LVLongPressGesture* gesture = (__bridge LVLongPressGesture *)(user->object); + if( lua_gettop(L)>=2 ){ + float num = lua_tonumber(L, 2); + gesture.numberOfTouchesRequired = num; + return 0; + } else { + float num = gesture.numberOfTouchesRequired; + lua_pushnumber(L, num); + return 1; + } + } + return 0; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewLongGesture globalName:globalName defaultName:@"LongPressGesture"]; + + lv_createClassMetaTable(L, META_TABLE_LongPressGesture); + + luaL_openlib(L, NULL, [LVGesture baseMemberFunctions], 0); + + { + const struct luaL_Reg memberFunctions [] = { + {"touchCount", setTouchCount}, + {NULL, NULL} + }; + luaL_openlib(L, NULL, memberFunctions, 0); + } + return 1; +} + + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLuaObjBox.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLuaObjBox.h new file mode 100644 index 00000000..d4a23bf4 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLuaObjBox.h @@ -0,0 +1,18 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LView.h" + +@interface LVLuaObjBox : NSObject + +- (id) init:(lua_State*)L stackID:(int) stackID; + +- (void) setProtocols:(NSArray*) protocols; + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLuaObjBox.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLuaObjBox.m new file mode 100644 index 00000000..36f60cd8 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLuaObjBox.m @@ -0,0 +1,211 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVLuaObjBox.h" +#import +#import "LuaViewCore.h" +#import "LVTypeConvert.h" +#import "LVHeads.h" + +@interface LVLuaObjBox () +@property (nonatomic, strong) NSMutableArray* protocolArray; +@property (nonatomic, weak) LuaViewCore* lview; +@property (nonatomic, strong) NSMutableDictionary* methodSigHashtable; +@end + + +@implementation LVLuaObjBox + + +- (id) init:(lua_State*)L stackID:(int) stackID{ + self = [super init]; + if( self ){ + self.methodSigHashtable = [[NSMutableDictionary alloc] init]; + + self.lview = LV_LUASTATE_VIEW(L); + [LVUtil registryValue:L key:self stack:stackID]; + } + return self; +} + +- (void) dealloc{ + LuaViewCore* lview = self.lview; + if( lview) { + lua_State* L = lview.l; + if( L ) { + [LVUtil unregistry:L key:self]; + } + } +} + + +// static +static BOOL lv_object_isProtocol(id obj ) { + static Class ProtocolClass = NULL; + if( ProtocolClass == NULL ) { + ProtocolClass = objc_getClass("Protocol"); + } + return ( [obj class]==ProtocolClass ); +} + +- (void) setProtocols:(NSArray *)protocols{ + if ( self.protocolArray ==nil ) { + self.protocolArray = [[NSMutableArray alloc] init]; + } + for( id obj in protocols ){ + [self addProtocol:obj]; + } +} + +- (void) addProtocol:(id) obj{ + if ( obj==nil ) + return ; + + if ( (class_isMetaClass(object_getClass(obj)) || lv_object_isProtocol(obj)) ) { + [self addProtocolOnce:obj]; + } else if ( [obj isKindOfClass:[NSString class]] ) { + if ( [self addProtocolOnce:NSProtocolFromString(obj)]==FALSE ){ + if ( [self addProtocolOnce:NSClassFromString(obj)]==FALSE ) { + LVError( @"addProtocol: %@", obj); + return ; + } + } + } else { + [self addProtocolOnce:[obj class]]; + } +} + +- (BOOL) addProtocolOnce:(id) class{ + if ( class ) { + if ( class_isMetaClass(object_getClass(class)) || lv_object_isProtocol(class) ) { + if( ![self.protocolArray containsObject:class] ) { + [self.protocolArray addObject:class]; + return YES; + } + } + } + return NO; +} + + +- (BOOL)respondsToSelector:(SEL)aSelector { + return YES; +} + +- (NSMethodSignature *)methodSignatureForSelector:(SEL)selector +{ + NSString* key = NSStringFromSelector(selector); + NSMethodSignature* sig = self.methodSigHashtable[key]; + if( sig ){ + return sig; + } + for (id type in self.protocolArray ){ + struct objc_method_description* desc = NULL; + + if( lv_object_isProtocol(type) ){ // protocol + Protocol* protocol = type; + struct objc_method_description temp = protocol_getMethodDescription( protocol, selector, YES, YES); + if( temp.types==NULL || temp.name==NULL ) { + temp = protocol_getMethodDescription( protocol, selector, NO, YES); + } + desc = &temp; + } else if( class_isMetaClass(object_getClass(type)) ) { // class + Class class = (Class)type; + Method method = class_getInstanceMethod( class, selector ); + if ( method==NULL ){ + method = class_getClassMethod( class, selector ); + } + if ( method ) { + desc = method_getDescription( method ); + } + } + if( desc && desc->types && desc->name ) { + NSMethodSignature* sig = [NSMethodSignature signatureWithObjCTypes:desc->types]; + self.methodSigHashtable[key] = sig; + return sig; + } + } + return nil; +} + +- (NSString*) nativeFuncNameToLuaFuncName:(NSString*) funcName{ + NSMutableString* s = [[NSMutableString alloc] initWithString:funcName]; + if ( [funcName hasSuffix:@":"] ){ + [s deleteCharactersInRange:NSMakeRange(s.length-1,1)]; + } + [s replaceOccurrencesOfString:@":" withString:@"_" options:NSCaseInsensitiveSearch range:NSMakeRange(0,s.length)]; + return s; +} + +-(NSString*) propertyName:(NSString*) key{ + if( key.length>3 ) { + NSString* string = [[NSString alloc] initWithString:[key substringFromIndex:3]]; + NSString* string0 = [string substringToIndex:1]; + NSString* string1 = [string substringFromIndex:1]; + NSString* ret = [NSString stringWithFormat:@"%@%@",string0.lowercaseString, string1]; + return ret; + } + return key; +} + +- (void)forwardInvocation:(NSInvocation *)invocation +{ + NSString *key = NSStringFromSelector([invocation selector]); + LuaViewCore* lview = self.lview; + lua_State* L = lview.l; + if ( lview && L) { + int luaArgNum = 1; + [LVUtil pushRegistryValue:L key:self]; + int argsNum = (int)invocation.methodSignature.numberOfArguments; + + key = [self nativeFuncNameToLuaFuncName:key]; + int haveReturnValue = [self haveReturnValueOfInvocation:invocation]; + const char* keyName = key.UTF8String; + if ( lv_isLuaObjectHaveProperty(L, -1, keyName) ) { + for ( int i=2; i3 &&[key hasPrefix:@"set"] ){ + NSString* property = [self propertyName:key]; + const char* propertyName = property.UTF8String; + if ( lv_isLuaObjectHaveProperty(L, -1, propertyName) ) { + lua_pushstring(L, propertyName); + lv_pushInvocationArgToLuaStack(invocation, 2, L); + lua_settable(L, -3); + return; + } + } + LVError(@"LuaObjBox.forwardInvocation: not found function: %@", key); + } +} + +- (int) haveReturnValueOfInvocation:(NSInvocation*) invocation{ + const char* type = [invocation.methodSignature methodReturnType]; + if ( type ){ + if( strcmp(@encode(void),type)==0 ) { + return 0; + } + return 1; + } + return 0; +} +// class_copyPropertyList +// class_copyMethodList + +@end + + + diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVMethod.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVMethod.h new file mode 100644 index 00000000..9231d119 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVMethod.h @@ -0,0 +1,22 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + +@interface LVMethod : NSObject + +@property (nonatomic,assign) SEL sel; +@property (nonatomic,copy) NSString* selName; +@property (nonatomic,assign) NSInteger nargs; + +-(id) initWithSel:(SEL)sel; + +-(int) callObj:(id) obj args:(lua_State*)L; + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVMethod.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVMethod.m new file mode 100644 index 00000000..646959a5 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVMethod.m @@ -0,0 +1,71 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVMethod.h" +#import "LVHeads.h" +#import "LVTypeConvert.h" + + +@interface LVMethod () +@property(nonatomic,strong) NSMethodSignature * methodSig; +@end + +@implementation LVMethod + +-(id) initWithSel:(SEL)sel{ + self = [super init]; + if( self ){ + self.sel = sel; + self.selName = NSStringFromSelector(sel); + self.nargs = [self checkSelectorArgsNumber:NSStringFromSelector(sel)]; + } + return self; +} + +-(NSInteger) checkSelectorArgsNumber:(NSString*)s{ + NSInteger num = 0; + for( int i=0; i +#import "LVHeads.h" +#import "LVMethod.h" + + +//LVData +@interface LVNativeObjBox : NSObject + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; + +@property(nonatomic,assign) BOOL weakMode; +@property(nonatomic,strong) id realObject; +@property(nonatomic,weak) id realObjectWeak; +@property(nonatomic,assign) BOOL openAllMethod; + +-(id) init:(lua_State*) l nativeObject:(id)nativeObject; +-(void) addMethod:(LVMethod*) method; +-(int) performMethod:(NSString*) methodName L:(lua_State*)L; + +- (NSString *)className; +- (BOOL)isOCClass; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +/* + * 注册native对象到脚本中, sel可以为空(如果为空注册所有api) + */ ++(int) registeObjectWithL:(lua_State *)L nativeObject:(id) nativeObject name:(NSString*) luaName sel:(SEL) sel weakMode:(BOOL) weakMode; + +/* + * 清除脚本中注册的native对象 + */ ++(int) unregisteObjectWithL:(lua_State *)L name:(NSString*) name; + + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNativeObjBox.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNativeObjBox.m new file mode 100644 index 00000000..ee1d468f --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNativeObjBox.m @@ -0,0 +1,302 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVNativeObjBox.h" +#import "LVHeads.h" +#import +#import "LVClassInfo.h" + +static NSArray* ARG_ARR = nil; + +@interface LVNativeObjBox () +@property (nonatomic,strong) LVClassInfo* classInfo; +@end + + +@implementation LVNativeObjBox + +-(id) init:(lua_State*) l nativeObject:(id)nativeObject{ + self = [super init]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + self.realObject = nativeObject; + + NSString* className = NSStringFromClass([nativeObject class]); + self.classInfo = [LVClassInfo classInfo:className]; + } + return self; +} + +- (BOOL) isEqual:(LVNativeObjBox *)another{ + if (![another isMemberOfClass:[self class]]) { + return false; + } + + return self.realObject == another.realObject || [self.realObject isEqual:another.realObject]; +} + +- (NSUInteger)hash { + return [self.realObject hash]; +} + +- (BOOL) isOCClass{ + return self.realObject && class_isMetaClass(object_getClass(self.realObject)); +} + +- (NSString *)className { + return NSStringFromClass([self.realObject class]); +} + +- (void) setWeakMode:(BOOL)weakMode{ + _weakMode = weakMode; + if( weakMode ) { + if( self.realObject ) { + self.realObjectWeak = self.realObject; + } + self.realObject = nil; + } else { + if( self.realObjectWeak ) { + self.realObject = self.realObjectWeak; + } + self.realObjectWeak = nil; + } +} + +- (id) realObject{ + return _realObject ? _realObject : _realObjectWeak; +} + +- (id) lv_nativeObject{ + return [self realObject]; +} + +-(void) addMethod:(LVMethod*) method { + [self.classInfo addMethod:method key:method.selName]; +} + +-(int) performMethod:(NSString*) methodName L:(lua_State*)L{ + if( methodName ) { + LVMethod* method = [self.classInfo getMethod:methodName]; + if ( method ) { + return [method callObj:self.realObject args:L ]; + } else if( self.openAllMethod ) { + //动态创建API + SEL sel = NSSelectorFromString(methodName); + LVMethod* method = [[LVMethod alloc] initWithSel:sel]; + [self.classInfo addMethod:method key:methodName]; + return [method callObj:self.realObject args:L]; + } else { + LVError(@"not found method: %@", methodName); + } + } + return 0; +} + +static int funcNameFromLuaToOC(NSMutableString* funcName){ + if( funcName.length>0 && [funcName characterAtIndex:0]=='#' ) { + NSRange range = NSMakeRange(0, 1); + [funcName deleteCharactersInRange:range]; + return -1; + } else { + return (int)[funcName replaceOccurrencesOfString:@"_" withString:@":" options:NSLiteralSearch range:NSMakeRange(0,funcName.length)]; + } +} + +// 检查API是否纯在 +- (BOOL) isApiExist:(NSString*) methodName{ + BOOL ret = [self.classInfo existMethod:methodName]; + if( ret ) { + return YES; + } else { + NSMutableString* ocMethodName = [[NSMutableString alloc] initWithString:methodName]; + funcNameFromLuaToOC(ocMethodName); + id nativeObj = self.realObject; + for ( int i=0; i<5; i++ ) { + SEL sel = NSSelectorFromString(ocMethodName); + if( [nativeObj respondsToSelector:sel] ){ + [self.classInfo setMethod:methodName exist:YES]; + return YES; + } + [ocMethodName appendString:@":"]; + } + } + //self.apiHashtable[methodName] = @(NO); + return NO; +} + +static void releaseNativeObject(LVUserDataInfo* user){ + if( user && user->object ){ + LVNativeObjBox* data = CFBridgingRelease(user->object); + user->object = NULL; + if( data ){ + data.lv_userData = nil; + data.lv_luaviewCore = nil; + data.realObject = nil; + } + } +} + +static int __gc (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + releaseNativeObject(user); + return 0; +} + ++(int) registeObjectWithL:(lua_State *)L nativeObject:(id) nativeObject name:(NSString*) name sel:(SEL) sel weakMode:(BOOL)weakMode { + if ( L==nil ){ + LVError( @"Lua State is released !!!"); + return 0; + } + if( nativeObject && name ) { + lua_checkstack(L, 64); + lua_getglobal(L, name.UTF8String); + + LVNativeObjBox* nativeObjBox = nil; + if( lua_type(L, -1)==LUA_TUSERDATA ) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, -1); + if( LVIsType(user, NativeObject) ){ + LVNativeObjBox* temp = (__bridge LVNativeObjBox *)(user->object); + if( temp.realObject==nativeObject ){ + nativeObjBox = temp; + } + } + } + if( nativeObjBox == nil ){ + nativeObjBox = [[LVNativeObjBox alloc] init:L nativeObject:nativeObject]; + } + + if ( sel ) { + LVMethod* method = [[LVMethod alloc] initWithSel:sel]; + [nativeObjBox addMethod:method]; + } else { + nativeObjBox.openAllMethod = YES; + } + nativeObjBox.weakMode = weakMode; + + NEW_USERDATA(userData, NativeObject); + userData->object = CFBridgingRetain(nativeObjBox); + nativeObjBox.lv_userData = userData; + luaL_getmetatable(L, META_TABLE_NativeObject ); + lua_setmetatable(L, -2); + + lua_setglobal(L, name.UTF8String); + } else if ( nativeObject==nil ){ + [LVNativeObjBox unregisteObjectWithL:L name:name]; + } + return 1; +} + + ++(int) unregisteObjectWithL:(lua_State *)L name:(NSString*) name{ + if ( L && name ) { + lua_pushnil(L); + lua_setglobal(L, name.UTF8String); + } + return 0; +} + +static int __tostring (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVNativeObjBox* nativeObjBox = (__bridge LVNativeObjBox *)(user->object); + NSString* s = [[NSString alloc] initWithFormat:@"{ UserDataType=NativeObject, %@ }",nativeObjBox.realObject]; + lua_pushstring(L, s.UTF8String); + return 1; + } + return 0; +} + +static void ifNotEnoughArgsTagAppendMore(NSMutableString* funcName, int num, int luaArgsNum){ + int addNum = luaArgsNum-1-num; + if( 0<=addNum && addNumobject); + NSMutableString* funcName = [NSMutableString stringWithFormat:@"%s",lua_tostring(L, lua_upvalueindex(2)) ]; + int luaArgsNum = lua_gettop(L); + + int _num = funcNameFromLuaToOC(funcName); + if( _num>=0 ) { + ifNotEnoughArgsTagAppendMore(funcName, _num, luaArgsNum); + } + return [nativeObjBox performMethod:funcName L:L]; + } + LVError(@"callNativeObjectFunction"); + return 0; +} + + +static int __index (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + NSString* functionName = lv_paramString(L, 2); + + LVNativeObjBox* nativeObjBox = (__bridge LVNativeObjBox *)(user->object); + id object = nativeObjBox.realObject; + if( nativeObjBox && object && [nativeObjBox isApiExist:functionName] ){ + lua_pushcclosure(L, callNativeObjectFunction, 2); + return 1; + } + return 0; /* new userdatum is already on the stack */ +} + +static int __eq (lua_State *L) { + if (lua_gettop(L) < 2) { + return 0; + } + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + LVUserDataInfo * another = (LVUserDataInfo *)lua_touserdata(L, 2); + if (another != NULL) { + LVNativeObjBox * box1 = (__bridge LVNativeObjBox *)(user->object); + LVNativeObjBox * box2 = (__bridge LVNativeObjBox *)(user->object); + lua_pushboolean(L, [box1 isEqual:box2]); + return 1; + } + return 0; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + // OC常量定义 + if( ARG_ARR==nil ) { + ARG_ARR = @[ + @"", + @":", + @"::", + @":::", + @"::::", + @":::::", + @"::::::", + @":::::::",]; + } + + const struct luaL_Reg memberFunctions [] = { + {"__gc", __gc }, + {"__tostring", __tostring }, + {"__eq", __eq }, + {"__index", __index }, + {NULL, NULL} + }; + + lv_createClassMetaTable(L, META_TABLE_NativeObject); + luaL_openlib(L, NULL, memberFunctions, 0); + + + return 0; +} + + + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNavigation.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNavigation.h new file mode 100644 index 00000000..6828e71a --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNavigation.h @@ -0,0 +1,23 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + +@interface LVNavigation : NSObject + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +// 空实现去除编译警告 +-(void) lv_setNavigationItemTitleView:(UIView*) view; +-(void) lv_setNavigationItemTitle:(NSString*) title; +-(void) lv_setNavigationItemLeftBarButtonItems:(NSArray*) items; +-(void) lv_setNavigationItemRightBarButtonItems:(NSArray*) items; +-(void) lv_setNavigationBarBackgroundImage:(UIImage*) image; + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNavigation.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNavigation.m new file mode 100644 index 00000000..e2cae30d --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNavigation.m @@ -0,0 +1,160 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVNavigation.h" +#import "LView.h" +#import "LVStyledString.h" +#import "LVHeads.h" + +@implementation LVNavigation + +// 空实现去除编译警告 +-(void) lv_setNavigationItemTitleView:(UIView*) view{ +} +-(void) lv_setNavigationItemTitle:(NSString*) title{ +} +-(void) lv_setNavigationItemLeftBarButtonItems:(NSArray*) items{ +} +-(void) lv_setNavigationItemRightBarButtonItems:(NSArray*) items{ +} +-(void) lv_setNavigationBarBackgroundImage:(UIImage*) image{ +} + +static void setViewControllerTitleView(UIViewController* vc, UIView* view){ + if([view isKindOfClass:[UIView class]] ) {// 第三种: View + if( [vc respondsToSelector:@selector(lv_setNavigationItemTitleView:)] ) { + [vc performSelector:@selector(lv_setNavigationItemTitleView:) withObject:view]; + } else { + vc.navigationItem.titleView = view; + } + } +} + +static int setTitle (lua_State *L) { + lv_clearFirstTableValue(L); + LuaViewCore* lview = LV_LUASTATE_VIEW(L); + UIViewController* vc = lview.viewController; + if( vc && lua_gettop(L)>=1 ) { + if( lua_type(L, 1)== LUA_TSTRING ) {// 第一种: string + NSString* title = lv_paramString(L, 1); + if( [vc respondsToSelector:@selector(lv_setNavigationItemTitle:)] ) { + [vc performSelector:@selector(lv_setNavigationItemTitle:) withObject:title]; + } else { + vc.navigationItem.title = title; + } + return 0; + } else if( lua_type(L, 1)== LUA_TUSERDATA ) {//第二种: 复合文本 + LVUserDataInfo * user2 = lua_touserdata(L, 1); + if( user2 && LVIsType(user2, StyledString) ) { + UILabel* label = [[UILabel alloc] init]; + LVStyledString* attString = (__bridge LVStyledString *)(user2->object); + [label setAttributedText:attString.mutableStyledString]; + [label sizeToFit]; + setViewControllerTitleView(vc, label); + return 0; + } + } + id object = lv_luaValueToNativeObject(L, 1);// 第三种: View + setViewControllerTitleView(vc, object); + return 0; + } + return 0; +} + ++(NSArray*) getNavigationItems:(lua_State*)L{ + NSMutableArray* array = [[NSMutableArray alloc] init]; + int num = lua_gettop(L); + for ( int i=1; i<=num; i++ ) { + id object = lv_luaValueToNativeObject(L, i); + if ( [object isKindOfClass:[UIView class]] ) { + [array addObject:[[UIBarButtonItem alloc] initWithCustomView:object]]; + } + } + return array; +} + +static int setLeftButton (lua_State *L) { + lv_clearFirstTableValue(L); + LuaViewCore* lview = LV_LUASTATE_VIEW(L); + UIViewController* vc = lview.viewController; + if( vc && lua_gettop(L)>=1 ) { + NSArray* buttonItems = [LVNavigation getNavigationItems:L]; + if( [vc respondsToSelector:@selector(lv_setNavigationItemLeftBarButtonItems:)] ) { + [vc performSelector:@selector(lv_setNavigationItemLeftBarButtonItems:) withObject:buttonItems]; + } else { + vc.navigationItem.leftBarButtonItems = buttonItems; + } + } + return 0; /* number of results */ +} + +static int setRightButton (lua_State *L) { + lv_clearFirstTableValue(L); + LuaViewCore* lview = LV_LUASTATE_VIEW(L); + UIViewController* vc = lview.viewController; + if( vc && lua_gettop(L)>=1 ) { + NSArray* buttonItems = [LVNavigation getNavigationItems:L]; + if( [vc respondsToSelector:@selector(lv_setNavigationItemRightBarButtonItems:)] ){ + [vc performSelector:@selector(lv_setNavigationItemRightBarButtonItems:) withObject:buttonItems]; + } else { + vc.navigationItem.rightBarButtonItems = buttonItems; + } + } + return 0; /* number of results */ +} + +static int setBackground(lua_State*L ) { + lv_clearFirstTableValue(L); + LuaViewCore* lview = LV_LUASTATE_VIEW(L); + UIViewController* vc = lview.viewController; + if( vc && lua_gettop(L)>=1 ) { + id obj = lv_luaValueToNativeObject(L, 1); + if( [obj isKindOfClass:[UIImageView class]] ) { + UIImageView* imgView = obj; + UIImage* image = imgView.image; + float scale = [UIScreen mainScreen].scale; + if( image.scale=1 ) { + NSInteger value = lua_tonumber(L, 2); + [[UIApplication sharedApplication] setStatusBarStyle:value]; + } + return 0; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + const struct luaL_Reg fs [] = { + {"title", setTitle}, + {"left", setLeftButton}, + {"right", setRightButton}, + {"background", setBackground}, + {"statusBarStyle", setStatusBarStyle}, // for IOS + {LUAVIEW_SYS_TABLE_KEY, setBackground}, + {NULL, NULL} + }; + luaL_openlib(L, "Navigation", fs, 0); + return 0; +} + +@end + + + diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNetworkStatus.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNetworkStatus.h new file mode 100644 index 00000000..b27f5162 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNetworkStatus.h @@ -0,0 +1,34 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import + +#define NW_NETWOEK_STATUS_NOTIFY @"TBNetworkStatusChangeNotify" + +typedef enum { + NotReachable = 0, + ReachableViaWiFi, + ReachableVia2G, + ReachableVia3G, + ReachableVia4G +} LVNetworkStatusEnum; + +@interface LVNetworkStatus : NSObject + ++ (LVNetworkStatus *)shareInstance; + +- (LVNetworkStatusEnum)currentNetworkStatus; + +- (LVNetworkStatusEnum)preNetworkStatus; + +- (NSString *)currentNetworkStatusString; + + + + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNetworkStatus.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNetworkStatus.m new file mode 100644 index 00000000..dffb3a6d --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNetworkStatus.m @@ -0,0 +1,259 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVNetworkStatus.h" +#import +#import +#import +#import +#import +#import +#import +#import + +#import +#import + +#import + +static char *const StrKeyReachabilityQueue = "com.luaview.NetworkSDKReachabilityQueue"; +static dispatch_queue_t reachabilityQueue; + +@implementation LVNetworkStatus +{ + LVNetworkStatusEnum _currentNetworkStatus; + LVNetworkStatusEnum _preNetworkStatus; + SCNetworkReachabilityRef _reachabilityRef; + CTTelephonyNetworkInfo *netInfo; +} + ++ (LVNetworkStatus *)shareInstance +{ + static LVNetworkStatus *s_SPDYNetworkStatusManager = nil; + + @synchronized([self class]) + { + if (!s_SPDYNetworkStatusManager) + { + s_SPDYNetworkStatusManager = [[LVNetworkStatus alloc] init]; + } + } + + return s_SPDYNetworkStatusManager; +} + +- (id)init +{ + self = [super init]; + if (self) + { + struct sockaddr_in zeroAddress; + bzero(&zeroAddress, sizeof(zeroAddress)); + zeroAddress.sin_len = sizeof(zeroAddress); + zeroAddress.sin_family = AF_INET; + _reachabilityRef = SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, (const struct sockaddr*)&zeroAddress); + netInfo = [[CTTelephonyNetworkInfo alloc] init]; + + //开始解析当前网络状态 + [self _reachabilityStatus]; + + //开始监控网络变化 + [self _startNotifier]; + } + + return self; +} + +- (BOOL)_startNotifier +{ + if (!_reachabilityRef) + { + struct sockaddr_in zeroAddress; + bzero(&zeroAddress, sizeof(zeroAddress)); + zeroAddress.sin_len = sizeof(zeroAddress); + zeroAddress.sin_family = AF_INET; + _reachabilityRef = SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, (const struct sockaddr*)&zeroAddress); + } + + if (_reachabilityRef) + { + SCNetworkReachabilityContext context = {0, (__bridge void *)(self), NULL, NULL, NULL}; + + if(SCNetworkReachabilitySetCallback(_reachabilityRef, ReachabilityCallback, &context)) + { + reachabilityQueue = dispatch_queue_create(StrKeyReachabilityQueue, DISPATCH_QUEUE_SERIAL); + SCNetworkReachabilitySetDispatchQueue(_reachabilityRef, reachabilityQueue); + + return YES; + } + } + + return NO; +} + +- (LVNetworkStatusEnum)currentNetworkStatus +{ + return _currentNetworkStatus; +} + +- (LVNetworkStatusEnum)preNetworkStatus +{ + return _preNetworkStatus; +} + +- (NSString *)currentNetworkStatusString +{ + switch (_currentNetworkStatus) + { + case NotReachable: + return @"unknown"; + + case ReachableVia2G: + return @"2g"; + + case ReachableVia3G: + return @"3g"; + + case ReachableVia4G: + return @"4g"; + + case ReachableViaWiFi: + return @"wifi"; + } +} + +- (LVNetworkStatusEnum)_reachabilityStatus +{ + if (_reachabilityRef) + { + SCNetworkReachabilityFlags flags = 0; + if (SCNetworkReachabilityGetFlags(_reachabilityRef, &flags)) + { + _preNetworkStatus = _currentNetworkStatus; + _currentNetworkStatus = [self _networkStatusForReachabilityFlags:flags]; + } + } + return _currentNetworkStatus; +} + +- (BOOL)checkInternetConnection +{ + struct sockaddr_in zeroAddress; + + bzero(&zeroAddress, sizeof(zeroAddress)); + zeroAddress.sin_len = sizeof(zeroAddress); + zeroAddress.sin_family = AF_INET; + + SCNetworkReachabilityRef defaultRouteReachability = SCNetworkReachabilityCreateWithAddress(NULL, (struct sockaddr *)&zeroAddress); + SCNetworkReachabilityFlags flags; + + BOOL didRetrieveFlags = SCNetworkReachabilityGetFlags(defaultRouteReachability, &flags); + + CFRelease(defaultRouteReachability); + + if (!didRetrieveFlags) + { + return NO; + } + + BOOL isReachable = flags & kSCNetworkFlagsReachable; + BOOL needsConnection = flags & kSCNetworkFlagsConnectionRequired; + + return (isReachable && !needsConnection) ? YES : NO; +} + +- (LVNetworkStatusEnum) currentNetworkStatusForiOS7:(LVNetworkStatusEnum) status +{ + NSString *nettype = netInfo.currentRadioAccessTechnology; + + if (nettype) + { + if([CTRadioAccessTechnologyGPRS isEqualToString:nettype]) + { + return ReachableVia2G; + } + else if([CTRadioAccessTechnologyLTE isEqualToString: nettype] + || [CTRadioAccessTechnologyeHRPD isEqualToString: nettype]) + { + return ReachableVia4G; + } + + } + + return status; +} + +- (LVNetworkStatusEnum)_networkStatusForReachabilityFlags:(SCNetworkReachabilityFlags)flags +{ + if ((flags & kSCNetworkReachabilityFlagsReachable) == 0 || ![self checkInternetConnection]) + { + // The target host is not reachable. + return NotReachable; + } + + LVNetworkStatusEnum returnValue = NotReachable; + + if ((flags & kSCNetworkReachabilityFlagsConnectionRequired) == 0) + { + returnValue = ReachableViaWiFi; + } + + if ((((flags & kSCNetworkReachabilityFlagsConnectionOnDemand ) != 0) || + (flags & kSCNetworkReachabilityFlagsConnectionOnTraffic) != 0)) + { + if ((flags & kSCNetworkReachabilityFlagsInterventionRequired) == 0) + { + returnValue = ReachableViaWiFi; + } + } + + if ((flags & kSCNetworkReachabilityFlagsIsWWAN) == kSCNetworkReachabilityFlagsIsWWAN) + { + returnValue = ReachableVia4G; + } + + if ((flags & kSCNetworkReachabilityFlagsIsWWAN) == kSCNetworkReachabilityFlagsIsWWAN) + { + if((flags & kSCNetworkReachabilityFlagsReachable) == kSCNetworkReachabilityFlagsReachable) + { + if ((flags & kSCNetworkReachabilityFlagsTransientConnection) == kSCNetworkReachabilityFlagsTransientConnection) + { + returnValue = ReachableVia3G; + + if((flags & kSCNetworkReachabilityFlagsConnectionRequired) == kSCNetworkReachabilityFlagsConnectionRequired) + { + returnValue = ReachableVia2G; + } + } + } + } + + if ( returnValue != ReachableViaWiFi ) + { + returnValue = [self currentNetworkStatusForiOS7: returnValue]; + } + + return returnValue; +} + +//网络变化回调函数 +static void ReachabilityCallback(SCNetworkReachabilityRef target, SCNetworkReachabilityFlags flags, void* info) +{ + + [[LVNetworkStatus shareInstance] _reachabilityStatus]; +} + +- (void)dealloc +{ + if (_reachabilityRef) + { + CFRelease(_reachabilityRef); + } +} + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNinePatchImage.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNinePatchImage.h new file mode 100755 index 00000000..b2831f89 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNinePatchImage.h @@ -0,0 +1,11 @@ + + +#import + +@interface LVNinePatchImage : NSObject + ++ (UIImage*) createNinePatchImageNamed:(NSString*)name; ++ (UIImage*) createNinePatchImage:(UIImage*)image; ++ (BOOL) isNinePathImageName:(NSString*) name; + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNinePatchImage.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNinePatchImage.m new file mode 100755 index 00000000..f4e99ba7 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNinePatchImage.m @@ -0,0 +1,167 @@ + + +#import "LVNinePatchImage.h" +#import "LVUtil.h" + +#define BYTES_PER_PIXEL 4 + +@implementation LVNinePatchImage + ++ (unsigned char*)getRGBAsFromImage:(UIImage*)image count:(NSInteger)count { + CGImageRef imageRef = [image CGImage]; + NSUInteger width = CGImageGetWidth(imageRef); + NSUInteger height = CGImageGetHeight(imageRef); + CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); + + unsigned char* rawData = (unsigned char*)calloc(height * width * 4, sizeof(unsigned char)); + + NSUInteger bytesPerRow = BYTES_PER_PIXEL * width; + NSUInteger bitsPerComponent = 8; + CGContextRef context = CGBitmapContextCreate(rawData, width, height, + bitsPerComponent, bytesPerRow, colorSpace, + kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big); + CGColorSpaceRelease(colorSpace); + + CGContextDrawImage(context, CGRectMake(0, 0, width, height), imageRef); + CGContextRelease(context); + return rawData; +} + +inline static CGFloat getImageAphaAtPoint(const unsigned char* rawData, NSInteger width, NSInteger height , NSInteger pointX, NSInteger pointY){ + NSInteger bytesPerRow = BYTES_PER_PIXEL * width; + NSInteger byteIndex = (bytesPerRow * pointY) + pointX * BYTES_PER_PIXEL ; + CGFloat alpha = (rawData[byteIndex + 3] * 1.0) / 255.0; + return alpha; +} + ++ (BOOL) isNinePathImageName:(NSString*) name{ + if ( [name hasSuffix:@".9"] || [name hasSuffix:@".9.png"] || [name hasSuffix:@".9@2x.png"] ) { + return YES; + } + return NO; +} + ++ (UIImage*)createNinePatchImageNamed:(NSString*)name { + if ( [self isNinePathImageName:name] ) { + UIImage* oriImage = [UIImage imageNamed:name]; + if ( oriImage==nil ) { + LVLog(@"createNinePatchImageNamed: The input image is nil"); + return nil; + } + return [self createResizableImageFromNinePatchImage:oriImage]; + } + LVLog(@"createNinePatchImageNamed: Image name is not ended with .9"); + return nil; +} + ++ (UIImage*)createNinePatchImage:(UIImage*)image +{ + return [self createResizableImageFromNinePatchImage:image]; +} + ++ (UIImage*)crop:(CGRect)r image0:(UIImage*)image0 +{ + r = CGRectMake(r.origin.x * image0.scale, + r.origin.y * image0.scale, + r.size.width * image0.scale, + r.size.height * image0.scale); + + CGImageRef imageRef = CGImageCreateWithImageInRect([image0 CGImage], r); + UIImage* ret = [UIImage imageWithCGImage:imageRef + scale:image0.scale + orientation:image0.imageOrientation]; + CGImageRelease(imageRef); + return ret; +} + ++ (UIImage*)createResizableImageFromNinePatchImage:(UIImage*)ninePatchImage +{ + CGImageRef imageRef = [ninePatchImage CGImage]; + NSInteger width = CGImageGetWidth(imageRef); + NSInteger height = CGImageGetHeight(imageRef); + + + NSMutableArray* topBarRgba = [NSMutableArray arrayWithCapacity:0]; + NSMutableArray* leftBarRgba = [NSMutableArray arrayWithCapacity:0]; + { + const unsigned char* rawData = [self getRGBAsFromImage:ninePatchImage count:width*height ]; + for( int x=1; x= 0; i--) { + NSNumber* alpha = topBarRgba[i]; + if ( alpha.floatValue == 1) { + right = i; + break; + } + } + // LVLog(@"The .9 PNG format error!!!. right==-1"); + for (int i = left + 1; i <= right - 1; i++) { + NSNumber* alpha = topBarRgba[i]; + if ( alpha.floatValue < 1) { + LVLog(@"The 9-patch PNG format is not support. 1"); + break; + } + } + count = (int) leftBarRgba.count; + for (int i = 0; i <= count - 1; i++) { + NSNumber* alpha = leftBarRgba[i]; + if ( alpha.floatValue == 1) { + top = i; + break; + } + } + //LVLog(@"The .9 PNG format error!!!. top==-1"); + for (int i = count - 1; i >= 0; i--) { + NSNumber* alpha = leftBarRgba[i]; + if ( alpha.floatValue == 1) { + bottom = i; + break; + } + } + //LVLog(@"The .9 PNG format error!!!. bottom==-1"); + for (int i = top + 1; i <= bottom - 1; i++) { + NSNumber* alpha = leftBarRgba[i]; + if ( alpha.floatValue == 0) { + LVLog(@"The 9-patch PNG format is not support.2"); + break; + } + } + if ( top>=0 && left>=0 && bottom>=0 && right>=0 ) { + UIImage* cropImg = [self crop:CGRectMake(1, 1, ninePatchImage.size.width - 2, ninePatchImage.size.height - 2) image0:ninePatchImage]; + float scale0 = cropImg.scale; + float scale2 = [UIScreen mainScreen].scale; + if ( scale2>scale0 ) { + cropImg = [[UIImage alloc] initWithCGImage:cropImg.CGImage + scale:scale2 + orientation:UIImageOrientationUp]; + float big = scale0/scale2; + UIImage* retImg = [cropImg resizableImageWithCapInsets:UIEdgeInsetsMake(top*big, left*big, bottom*big, right*big)]; + return retImg; + } else { + UIImage* retImg = [cropImg resizableImageWithCapInsets:UIEdgeInsetsMake(top, left, bottom, right) ]; + return retImg; + } + } + return ninePatchImage; +} + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPagerIndicator.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPagerIndicator.h new file mode 100644 index 00000000..e61773af --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPagerIndicator.h @@ -0,0 +1,31 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + +@class LVPagerView; + +@interface LVPagerIndicator : UIPageControl + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; +@property(nonatomic,assign) NSUInteger lv_align; +@property(nonatomic,strong) CAShapeLayer* lv_shapeLayer; + + +-(id) init:(lua_State*) l; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +/* + 关联PagerIndicator用的 + */ +@property(nonatomic,weak) LVPagerView* pagerView; + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPagerIndicator.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPagerIndicator.m new file mode 100644 index 00000000..2e07b189 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPagerIndicator.m @@ -0,0 +1,163 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVPagerIndicator.h" +#import "LVBaseView.h" +#import "LView.h" +#import "LVPagerView.h" +#import "LVHeads.h" + +@implementation LVPagerIndicator + + +-(id) init:(lua_State*) l{ + self = [super init]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + self.clipsToBounds = YES; + self.userInteractionEnabled = NO; + } + return self; +} + +-(void) dealloc{ +} + +#pragma -mark PageControl +static int lvNewPagerIndicator (lua_State *L) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVPagerIndicator class]]; + + LVPagerIndicator* pageControl = [[c alloc] init:L]; + + { + NEW_USERDATA(userData, View); + userData->object = CFBridgingRetain(pageControl); + + luaL_getmetatable(L, META_TABLE_PagerIndicator ); + lua_setmetatable(L, -2); + } + LuaViewCore* view = LV_LUASTATE_VIEW(L); + if( view ){ + [view containerAddSubview:pageControl]; + } + return 1; /* new userdatum is already on the stack */ +} + +//static int setPageCount(lua_State *L) { +// LVUserDataView * user = (LVUserDataView *)lua_touserdata(L, 1); +// if( user ){ +// LVPagerIndicator* view = (__bridge LVPagerIndicator *)(user->view); +// if( view ){ +// if( lua_gettop(L)>=2 ) { +// int number = lua_tonumber(L, 2); +// view.numberOfPages = number; +// return 0; +// } else { +// lua_pushnumber(L, view.numberOfPages ); +// return 1; +// } +// } +// } +// return 0; +//} + +static int setCurrentPage(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVPagerIndicator* view = (__bridge LVPagerIndicator *)(user->object); + if( view ){ + if( lua_gettop(L)>=2 ) { + int currentPage = lua_tonumber(L, 2); + //view.currentPage = currentPage-1; + [view.pagerView setCurrentPageIdx:currentPage-1 animation:YES]; + return 0; + } else { + lua_pushnumber(L, view.currentPage+1 ); + return 1; + } + } + } + return 0; +} + +static int pageIndicatorTintColor(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVPagerIndicator* view = (__bridge LVPagerIndicator *)(user->object); + if( view ){ + if( lua_gettop(L)>=2 ) { + UIColor* color = lv_getColorFromStack(L, 2); + view.pageIndicatorTintColor = color; + return 0; + } else { + UIColor* color = view.pageIndicatorTintColor; + NSUInteger c = 0; + CGFloat a = 0; + if( lv_uicolor2int(color, &c, &a) ){ + lua_pushnumber(L, c ); + lua_pushnumber(L, a); + return 2; + } + } + } + } + return 0; +} + +static int currentPageIndicatorTintColor(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVPagerIndicator* view = (__bridge LVPagerIndicator *)(user->object); + if( view ){ + if( lua_gettop(L)>=2 ) { + UIColor* color = lv_getColorFromStack(L, 2); + view.currentPageIndicatorTintColor = color; + return 0; + } else { + UIColor* color = view.currentPageIndicatorTintColor; + NSUInteger c = 0; + CGFloat a = 0; + if( lv_uicolor2int(color, &c, &a) ){ + lua_pushnumber(L, c ); + lua_pushnumber(L, a); + return 2; + } + } + } + } + return 0; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewPagerIndicator globalName:globalName defaultName:@"PagerIndicator"]; + + const struct luaL_Reg memberFunctions [] = { + {"currentPage", setCurrentPage }, + + {"pageColor", pageIndicatorTintColor },//__deprecated_msg("Use unselectedColor") + {"currentPageColor", currentPageIndicatorTintColor },//__deprecated_msg("Use selectedColor") + + {"unselectedColor", pageIndicatorTintColor }, + {"selectedColor", currentPageIndicatorTintColor }, + {NULL, NULL} + }; + + lv_createClassMetaTable(L, META_TABLE_PagerIndicator); + + luaL_openlib(L, NULL, [LVBaseView baseMemberFunctions], 0); + luaL_openlib(L, NULL, memberFunctions, 0); + + const char* keys[] = { "addView", NULL};// 移除多余API + lv_luaTableRemoveKeys(L, keys ); + return 1; +} + + +//---------------------------------------------------------------------------------------- + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPagerView.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPagerView.h new file mode 100644 index 00000000..0e11dc78 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPagerView.h @@ -0,0 +1,28 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + +@class LVPagerIndicator; +@interface LVPagerView : UIView + + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; +@property(nonatomic,assign) NSUInteger lv_align; +@property(nonatomic,strong) CAShapeLayer* lv_shapeLayer; + + +-(id) init:(lua_State*) l; ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +-(void) setIndicator:(LVPagerIndicator*) indicator; +-(void) setCurrentPageIdx:(NSInteger) pageIdx animation:(BOOL) animation; + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPagerView.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPagerView.m new file mode 100644 index 00000000..1b129212 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPagerView.m @@ -0,0 +1,738 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVPagerView.h" +#import "LView.h" +#import "LVBaseView.h" +#import "LVScrollView.h" +#import "LVPagerViewCell.h" +#import "LVPagerIndicator.h" +#import "LVHeads.h" +#import "LuaViewCore.h" + +static inline NSInteger mapPageIdx(NSInteger pageIdx){ + return pageIdx + 1; +} + +static inline NSInteger unmapPageIdx(NSInteger pageIdx){ + return pageIdx - 1; +} + +#define IDENTIFIER "Id" + +// lua 对应的数据 key +#define USERDATA_KEY_DELEGATE 1 + +#define DEFAULT_CELL_IDENTIFIER @"LVCollectionCell.default.identifier" + +@interface LVPagerView () +@property (nonatomic,strong) UICollectionViewFlowLayout *flowLayout; +@property (nonatomic,strong) NSMutableDictionary* identifierDic; +@property (nonatomic,strong) NSMutableArray* cellArray; + + +@property (nonatomic,assign) NSInteger pageIdx0; +@property (nonatomic,assign) NSInteger pageIdx; +@property (nonatomic,weak) LVPagerIndicator* pagerIndicator; + +@property (nonatomic,strong) NSTimer *timer; + +@property (nonatomic,assign) CGPoint nextOffset; +@property (nonatomic,assign) BOOL looping; +@property (nonatomic,assign) NSInteger isScrollEndTimes; + +@property (nonatomic,strong) UIScrollView *scrollview; +@property (nonatomic,assign) CGFloat sideLeft; +@property (nonatomic,assign) CGFloat sideRight; + +@property (nonatomic,assign) BOOL doubleMode; + +@property (nonatomic,assign) float autoScrollInterval; +@end + + +@implementation LVPagerView + +-(id) init:(lua_State*) l { + self = [super init]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + self.backgroundColor = [UIColor clearColor]; + self.cellArray = [[NSMutableArray alloc] init]; + self.scrollview = ({ + UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)]; + scroll.pagingEnabled = YES; + scroll.clipsToBounds = NO; + scroll; + }) ; + + [self addSubview:self.scrollview]; + self.clipsToBounds = YES; + + self.scrollview.pagingEnabled = YES; + self.scrollview.showsHorizontalScrollIndicator = NO; + self.scrollview.delegate = self; + self.scrollview.scrollsToTop = NO; + self.pageIdx = 0; + self.isScrollEndTimes = 0; + } + return self; +} + +-(void) createAllCell { + NSInteger num = [self numberOfPagesInPageView]; + if( num==2 && ( self.sideLeft!=0 || self.sideRight!=0 ) ) { + // 开始双倍模式 + num = 4; + self.doubleMode = YES; + } else { + self.doubleMode = NO; + } + if( numself.cellArray.count ) { + for( int i=((int)self.cellArray.count); i0 ) { + i += self.pageIdx0; + i += 1000 * count; + return i%count; + } + return i; +} + +// xindex 映射 index +-(NSInteger) xindex2index:(NSInteger) i{ + NSUInteger count = self.cellArray.count; + if( count>0 ) { + i -= self.pageIdx0; + i += 1000 * count; + return i%count; + } + return i; +} + +-(void) resetCellFrame{ + {// ScrollView的滚动大小 + CGRect rect = self.bounds; + rect.origin.x = self.sideLeft; + rect.size.width -= self.sideLeft + self.sideRight; + self.scrollview.frame = rect; + } + NSUInteger count = self.cellArray.count; + CGSize size = self.scrollview.frame.size; + for( NSUInteger i=0; i0 ) { + CGPoint p = self.scrollview.contentOffset; + if( self.looping ) { + if( self.cellArray.count>2 ) { + if( p.x < width*0.5 ) { + self.pageIdx0 += 1; + self.scrollview.contentOffset = CGPointMake( p.x + width, 0); + [self resetCellFrame]; + } else if( p.x> width*1.5 ){ + self.pageIdx0 -= 1; + self.scrollview.contentOffset = CGPointMake( p.x - width, 0); + [self resetCellFrame]; + } + } else { + if( p.x< 0 ) { + self.pageIdx0 += 1; + self.scrollview.contentOffset = CGPointMake( p.x + width, 0); + [self resetCellFrame]; + } else if( p.x>=width ){ + self.pageIdx0 -= 1; + self.scrollview.contentOffset = CGPointMake( p.x - width, 0); + [self resetCellFrame]; + } + } + } + } +} + +-(void) setFrame:(CGRect)frame{ + [super setFrame:frame]; + [self resetCellFrame]; +} + +-(void) checkCellVisible{ + CGPoint p = self.scrollview.contentOffset; + CGRect r0 = self.scrollview.bounds; + r0.origin = p; + r0.origin.x -= self.sideLeft; + r0.size.width += self.sideLeft + self.sideRight; + for( int i=0; i=0 && index=2 ) { + pageIdx = pageIdx-2; + } + if( !cell.isInited ){ + cell.isInited = YES; + [cell doInitWithLView:lview]; + + // 创建cell初始化 + lua_settop(l, 0); + lua_checkstack(l, 12); + [cell pushTableToStack];//arg1: cell + lua_pushnumber(l, mapPageIdx(pageIdx) );//arg2: section + + lv_pushUserdata(l, self.lv_userData); + lv_pushUDataRef(l, USERDATA_KEY_DELEGATE); + [LVUtil call:l key1:"Pages" key2:"Init" key3:NULL nargs:2 nrets:0 retType:LUA_TNONE]; + } + { // 通知布局调整 + // 参数 cell,section,row + lua_settop(l, 0); + lua_checkstack(l, 12); + [cell pushTableToStack];//arg1: cell + lua_pushnumber(l, mapPageIdx(pageIdx) );//arg2: section + + lv_pushUserdata(l, self.lv_userData); + lv_pushUDataRef(l, USERDATA_KEY_DELEGATE); + [LVUtil call:l key1:"Pages" key2:"Layout" key3:NULL nargs:2 nrets:0 retType:LUA_TNONE]; + } + } + [lview popWindow:newWindow]; + return cell; +} + +// section数量 +- (NSInteger) numberOfPagesInPageView{ + lua_State* l = self.lv_luaviewCore.l; + if( l && self.lv_userData ){ + lv_pushUserdata(l, self.lv_userData); + lv_pushUDataRef(l, USERDATA_KEY_DELEGATE); + if( [LVUtil call:l key1:"PageCount" key2:NULL key3:NULL nargs:0 nrets:1 retType:LUA_TNUMBER] ==0 ) { + if( lua_type(l, -1)==LUA_TNUMBER ) { + NSInteger num = lua_tonumber(l, -1); + return num; + } + } + return 1; + } + return 1; +} + +-(void) setPageIndicatorIdx:(NSInteger)pageIdx{ + if( pageIdx>=0 && pageIdx=2 ) { + self.pagerIndicator.currentPage = pageIdx-2; + } else { + self.pagerIndicator.currentPage = pageIdx; + } + } +} + + +-(void) setIndicator:(LVPagerIndicator*) indicator{ + self.pagerIndicator = indicator; + self.pagerIndicator.pagerView = self; + if( self.doubleMode ) { + self.pagerIndicator.numberOfPages = 2; + } else { + self.pagerIndicator.numberOfPages = self.cellArray.count; + } + [self setPageIndicatorIdx:self.pageIdx]; +} + +-(void) setCurrentPageIdx:(NSInteger) pageIdx animation:(BOOL) animation{ + float offsetX = [self index2xindex:pageIdx] * self.scrollview.frame.size.width ; + if( offsetX<=0 ){ + offsetX = 0; + } + float maxOffset = self.scrollview.contentSize.width - self.scrollview.frame.size.width; + if( offsetX > maxOffset ){ + offsetX = maxOffset; + } + //[self setContentOffset:CGPointMake(offsetX, 0) animated:animation]; + self.nextOffset = CGPointMake(offsetX, 0); + if( animation ) { + [self performSelectorOnMainThread:@selector(changeOffsetWithAnimation:) withObject:nil waitUntilDone:NO]; + } else { + [self performSelectorOnMainThread:@selector(changeOffsetNoAnimation:) withObject:nil waitUntilDone:NO]; + } +} + +// 有动画 +-(void) changeOffsetWithAnimation:(NSNumber*) value{ + if( self.lv_luaviewCore ) { + [self.scrollview setContentOffset:self.nextOffset animated:YES]; + } +} + +// 无动画 +-(void) changeOffsetNoAnimation:(NSNumber*) value{ + if( self.lv_luaviewCore ) { + [self.scrollview setContentOffset:self.nextOffset animated:NO]; + } +} + +#pragma -mark lvNewCollectionView +static int lvNewPagerView (lua_State *L) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVPagerView class]]; + + if( lua_gettop(L)<=0 ) { + lua_createtable(L, 8, 0); + } + + if ( lua_gettop(L)>=1 && lua_type(L, 1)==LUA_TTABLE ) { + LVPagerView* pageView = [[c alloc] init:L]; + + NEW_USERDATA(userData, View); + userData->object = CFBridgingRetain(pageView); + pageView.lv_userData = userData; + luaL_getmetatable(L, META_TABLE_UIPageView ); + lua_setmetatable(L, -2); + + LuaViewCore* lview = LV_LUASTATE_VIEW(L); + if( lview ){ + [lview containerAddSubview:pageView]; + } + + int stackNum = lua_gettop(L); + lua_pushvalue(L, 1); + lv_udataRef(L, USERDATA_KEY_DELEGATE ); + + [pageView createAllCell]; + lua_settop(L, stackNum); + + lv_pushUserdata(L, pageView.lv_userData); + return 1; + } + return 0; +} + +-(void) reloadData{ + for( UIView* view in self.cellArray ) { + [view removeFromSuperview]; + } + [self createAllCell]; + [self moveCenter]; + [self checkCellVisible]; + self.autoScrollInterval = self.autoScrollInterval; +} + +-(void) reloadDataASync{ + dispatch_async(dispatch_get_main_queue(), ^{ + [self performSelector:@selector(reloadData) withObject:nil afterDelay:0.001 inModes:@[NSRunLoopCommonModes]]; + }); +} + +static int reload (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVPagerView* pageView = (__bridge LVPagerView *)(user->object); + [pageView reloadDataASync]; + lua_pushvalue(L, 1); + return 1; + } + return 0; +} + +static int showScrollBar(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIScrollView* view = (__bridge UIScrollView *)(user->object); + if( lua_gettop(L)>=2 ) { + BOOL yes1 = lua_toboolean(L, 2); + view.showsHorizontalScrollIndicator = yes1; + return 0; + } else { + lua_pushboolean(L, view.showsHorizontalScrollIndicator ); + return 1; + } + } + return 0; +} + +static int setCurrentPage(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVPagerView* view = (__bridge LVPagerView *)(user->object); + if( lua_gettop(L)>=2 ) { + int luaPageIdx = lua_tonumber(L, 2); + BOOL animated = YES; + if( lua_gettop(L)>=3 ) { + animated = lua_toboolean(L, 3); + } + [view setCurrentPageIdx:unmapPageIdx(luaPageIdx) animation:animated]; + lua_settop(L, 1); + return 1; + } else { + NSInteger currentPageIdx = view.pageIdx; + lua_pushnumber( L, mapPageIdx(currentPageIdx) ); + return 1; + } + } + return 0; +} + +-(void) setAutoScrollInterval:(float) interval{ + _autoScrollInterval = interval; + NSInteger totalPages = self.cellArray.count; + if ( totalPages < 2 ){//小于两个没有效果 + [self stopTimer]; + return ; + } + if ( interval > 0.02 ) {//start timer + [self startTimer:interval repeat:YES]; + } else {//stop timer + [self stopTimer]; + } +} + +static int autoScroll(lua_State *L){ + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if(user){ + LVPagerView * view = (__bridge LVPagerView *)(user -> object); + + if(lua_gettop(L) >= 2) { + float interval = lua_tonumber(L, 2); + [view setAutoScrollInterval:interval]; + } + } + return 0; +} + +static int looping(lua_State *L){ + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if(user){ + LVPagerView * view = (__bridge LVPagerView *)(user -> object); + if( lua_gettop(L)>=2 ) { + BOOL ret = lua_toboolean(L, 2); + view.looping = ret; + return 0; + } else { + BOOL yes = view.looping; + lua_pushboolean(L, yes); + return 1; + } + } + return 0; +} + +#pragma -mark Timer +-(void) stopTimer{ + if( self.timer ) { + [self.timer invalidate]; + self.timer = nil; + } +} + +- (void) startTimer:(NSTimeInterval) interval repeat:(BOOL) repeat{ + self.looping = YES; + [self stopTimer]; + //create new timer + self.timer = [NSTimer scheduledTimerWithTimeInterval:interval target:self selector:@selector(scrollTimer:) userInfo:nil repeats:repeat]; +} + +- (void) scrollTimer:(NSTimer *) timer { + if( self.isScrollEndTimes>1 ) { + //更改方向 + NSInteger width = self.scrollview.frame.size.width; + CGPoint p = self.scrollview.contentOffset; + p.x += width; + p.x = ((NSInteger)p.x) /width * width; + self.nextOffset = p; + [self performSelectorOnMainThread:@selector(changeOffsetWithAnimation:) withObject:nil waitUntilDone:NO]; + } else { + self.isScrollEndTimes ++; + } +} + +static int indicator(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVPagerView* view = (__bridge LVPagerView *)(user->object); + if( lua_gettop(L)>=2 ) { + if ( lua_type(L, 2)==LUA_TNIL ) { + view.pagerIndicator = nil; + [view setIndicator:nil];// 设置Indicator + lua_pushvalue(L, 1); + lv_pushUDataRef(L, USERDATA_KEY_DELEGATE ); + lua_pushnil(L);// value + lua_setfield(L, -2, "Indicator"); + } else { + LVUserDataInfo * user2 = (LVUserDataInfo *)lua_touserdata(L, 2); + if( LVIsType(user2, View) ) { + LVPagerIndicator* pagerIndicator = (__bridge LVPagerIndicator *)(user2->object); + if( [pagerIndicator isKindOfClass:[LVPagerIndicator class]] ) { + [view setIndicator:pagerIndicator];// 设置Indicator + lua_pushvalue(L, 1); + lv_pushUDataRef(L, USERDATA_KEY_DELEGATE ); + lua_pushvalue(L, 2);// value + lua_setfield(L, -2, "Indicator"); + } + } + } + return 0; + } else { + lv_pushUDataRef(L, USERDATA_KEY_DELEGATE ); + lua_getfield(L, -2, "Indicator"); + return 1; + } + } + return 0; +} + +static int previewSide(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVPagerView* pagerview = (__bridge LVPagerView *)(user->object); + if( lua_gettop(L)>=3 ) { + CGFloat sideLeft = lua_tonumber(L, 2); + CGFloat sideRight = lua_tonumber(L, 3); + pagerview.sideLeft = sideLeft; + pagerview.sideRight = sideRight; + pagerview.frame = pagerview.frame; + if( pagerview.cellArray.count==2 ) { + [pagerview reloadDataASync]; + } + return 0; + } else { + lua_pushnumber(L, pagerview.sideLeft); + lua_pushnumber(L, pagerview.sideRight); + return 2; + } + } + return 0; +} + +#pragma -mark __gc +static void releaseUserDataView(LVUserDataInfo* userdata){ + if( userdata && userdata->object ){ + LVPagerView* view = CFBridgingRelease(userdata->object); + userdata->object = NULL; + if( view ){ + [view.timer invalidate]; + view.scrollview.delegate = nil; + [view.scrollview removeFromSuperview]; + NSArray* subviews = view.scrollview.subviews; + for( UIView* view in subviews ) { + [view removeFromSuperview]; + } + view.scrollview.scrollEnabled = NO; + view.scrollview = nil; + + view.lv_userData = nil; + view.lv_luaviewCore = nil; + [view removeFromSuperview]; + } + } +} + +static int __gc (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + releaseUserDataView(user); + return 0; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewPagerView globalName:globalName defaultName:@"PagerView"]; + + const struct luaL_Reg memberFunctions [] = { + {"reload", reload}, + {"showScrollBar", showScrollBar }, + {"currentPage", setCurrentPage }, + {"autoScroll", autoScroll}, // IOS: 需要支持正反滚动 + {"looping", looping}, + {"indicator", indicator}, + + {"previewSide", previewSide}, + + {"__gc", __gc }, + {NULL, NULL} + }; + + lv_createClassMetaTable(L ,META_TABLE_UIPageView); + + luaL_openlib(L, NULL, [LVBaseView baseMemberFunctions], 0); + luaL_openlib(L, NULL, [LVScrollView memberFunctions], 0); + luaL_openlib(L, NULL, memberFunctions, 0); + + const char* keys[] = { "addView", NULL};// 移除多余API + lv_luaTableRemoveKeys(L, keys ); + return 1; +} + + +- (void) callLuaWithScrolling{ + CGFloat offsetX = self.scrollview.contentOffset.x; + CGFloat pageWidth = self.scrollview.frame.size.width; + CGFloat pageIndex = offsetX/pageWidth; + + self.pageIdx = [self xindex2index:pageIndex]; + [self setPageIndicatorIdx:[self xindex2index:pageIndex + 0.5]]; + + lua_State* l = self.lv_luaviewCore.l; + if( l && self.lv_userData ){ + lua_settop(l, 0); + lua_checkstack32(l); + double intPart = 0; + double floatPart = modf( pageIndex, &intPart); + NSInteger pageIdx = self.pageIdx; + if( self.doubleMode&& pageIdx>=2 ) { + pageIdx -= 2; + } + lua_pushnumber(l, mapPageIdx( pageIdx ) ); + lua_pushnumber(l, floatPart); + lua_pushnumber(l, offsetX - intPart*pageWidth); + + lv_pushUserdata(l, self.lv_userData); + lv_pushUDataRef(l, USERDATA_KEY_DELEGATE); + + [LVUtil call:l key1:STR_CALLBACK key2:"Scrolling" key3:NULL nargs:3 nrets:0 retType:LUA_TNONE]; + } +} + +- (void) callLuaWithScrollEnded{ + { + CGFloat offsetX = self.scrollview.contentOffset.x; + CGFloat pageWidth = self.scrollview.frame.size.width; + CGFloat pageIndex = offsetX/pageWidth; + + self.pageIdx = [self xindex2index:pageIndex + 0.1]; + [self setPageIndicatorIdx:[self xindex2index:pageIndex + 0.1]]; + } + lua_State* l = self.lv_luaviewCore.l; + if( l && self.lv_userData ){ + lua_checkstack32(l); + NSInteger pageIdx = self.pageIdx; + if( self.doubleMode&& pageIdx>=2 ) { + pageIdx -= 2; + } + lua_pushnumber(l, mapPageIdx(pageIdx) ); + + lv_pushUserdata(l, self.lv_userData); + lv_pushUDataRef(l, USERDATA_KEY_DELEGATE); + + [LVUtil call:l key1:STR_CALLBACK key2:"ScrollEnd" key3:NULL nargs:1 nrets:0 retType:LUA_TNONE]; + } +} + +- (void)scrollViewDidScroll:(UIScrollView *)scrollView{ + [self moveCenter]; + [self checkCellVisible]; + + [self callLuaWithScrolling]; +} + +- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{ + self.isScrollEndTimes = 0; + [self lv_callLuaByKey1:@STR_CALLBACK key2:@"ScrollBegin" argN:0]; +} +- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView{ + //[self lv_callLuaByKey1:@STR_CALLBACK key2:@"BeginDecelerating"]; +} + +- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{ + [self callLuaWithScrolling]; + [self callLuaWithScrollEnded]; + self.isScrollEndTimes = 0; +} + +- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView{ + [self callLuaWithScrolling]; + [self callLuaWithScrollEnded]; +} + +- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event +{ + UIView *view = [super hitTest:point withEvent:event]; + if ([view isEqual:self]) + { + UIScrollView* scrollview = self.scrollview; + for (UIView *subview in scrollview.subviews) + { + CGPoint offset = CGPointMake(point.x - scrollview.frame.origin.x + scrollview.contentOffset.x - subview.frame.origin.x, + point.y - scrollview.frame.origin.y + scrollview.contentOffset.y - subview.frame.origin.y); + + if ((view = [subview hitTest:offset withEvent:event])) + { + return view; + } + } + return scrollview; + } + return view; +} + +-(NSString*) description{ + return [NSString stringWithFormat:@"", (int)[self hash], NSStringFromCGRect(self.frame) ]; +} +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPagerViewCell.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPagerViewCell.h new file mode 100644 index 00000000..8ee66ffc --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPagerViewCell.h @@ -0,0 +1,23 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LuaViewCore.h" + +@interface LVPagerViewCell : UIView + +@property (nonatomic, assign) NSInteger index; +@property (nonatomic, assign) BOOL isInited; + +-(void) pushTableToStack; + +-(void) doInitWithLView:(LuaViewCore*) lview; + +-(UIView*) contentView; + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPagerViewCell.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPagerViewCell.m new file mode 100644 index 00000000..66dc12ae --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPagerViewCell.m @@ -0,0 +1,66 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVPagerViewCell.h" +#import "LuaViewCore.h" +#import "lapi.h" + +@interface LVPagerViewCell () +@property (nonatomic,weak) LuaViewCore* lv_luaviewCore; +@end + +@implementation LVPagerViewCell + + + +-(void) dealloc{ + lua_State* L = self.lv_luaviewCore.l; + if( L ) { + [LVUtil unregistry:L key:self]; + } +} + +-(void) doInitWithLView:(LuaViewCore*) lview{ + self.lv_luaviewCore = lview; + lua_State* L = lview.l; + if( L ) { + lua_createtable(L, 0, 0); + [LVUtil registryValue:L key:self stack:-1]; + lv_luaTableSetWeakWindow(L, self); + } +} + +-(void) pushTableToStack{ + lua_State* L = self.lv_luaviewCore.l; + if( L ) { + [LVUtil pushRegistryValue:L key:self]; + } +} + +-(UIView*) contentView{ + return self; +} + +-(NSString*) description{ + return [NSString stringWithFormat:@"", (int)[self hash], NSStringFromCGRect(self.frame)]; +} + +- (void) layoutSubviews{ + [super layoutSubviews]; + [self lv_alignSubviews]; +} + +-(instancetype) init{ + self = [super init]; + if ( self ) { + self.clipsToBounds = YES; + } + return self; +} + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPanGesture.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPanGesture.h new file mode 100644 index 00000000..222b2889 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPanGesture.h @@ -0,0 +1,23 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" +#import "NSObject+LuaView.h" + +@interface LVPanGesture : UIPanGestureRecognizer + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; + +-(id) init:(lua_State*) l; + + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPanGesture.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPanGesture.m new file mode 100644 index 00000000..0eeada88 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPanGesture.m @@ -0,0 +1,74 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVPanGesture.h" +#import "LVGesture.h" +#import "LView.h" +#import "LVHeads.h" + +@implementation LVPanGesture + + +-(void) dealloc{ + [LVGesture releaseUD:_lv_userData]; +} + +-(id) init:(lua_State*) l{ + self = [super initWithTarget:self action:@selector(handleGesture:)]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + } + return self; +} + +-(void) handleGesture:(LVPanGesture*)sender { + lua_State* l = self.lv_luaviewCore.l; + if ( l ){ + lua_checkstack32(l); + lv_pushUserdata(l,self.lv_userData); + [LVUtil call:l lightUserData:self key1:"callback" key2:NULL nargs:1]; + } +} + +static int lvNewPanGestureRecognizer (lua_State *L) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVPanGesture class]]; + { + LVPanGesture* gesture = [[c alloc] init:L]; + + if( lua_type(L, 1) == LUA_TFUNCTION ) { + [LVUtil registryValue:L key:gesture stack:1]; + } + + { + NEW_USERDATA(userData, Gesture); + gesture.lv_userData = userData; + userData->object = CFBridgingRetain(gesture); + + luaL_getmetatable(L, META_TABLE_PanGesture ); + lua_setmetatable(L, -2); + } + } + return 1; /* new userdatum is already on the stack */ +} + + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewPanGestureRecognizer globalName:globalName defaultName:@"PanGesture"]; + + const struct luaL_Reg memberFunctions [] = { + {NULL, NULL} + }; + + lv_createClassMetaTable(L, META_TABLE_PanGesture); + + luaL_openlib(L, NULL, [LVGesture baseMemberFunctions], 0); + luaL_openlib(L, NULL, memberFunctions, 0); + return 1; +} + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPinchGesture.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPinchGesture.h new file mode 100644 index 00000000..991a608a --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPinchGesture.h @@ -0,0 +1,24 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "NSObject+LuaView.h" +#import "LVHeads.h" + +@interface LVPinchGesture : UIPinchGestureRecognizer + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; + +-(id) init:(lua_State*) l; + + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPinchGesture.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPinchGesture.m new file mode 100644 index 00000000..1acd2e8a --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPinchGesture.m @@ -0,0 +1,87 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVPinchGesture.h" +#import "LVGesture.h" +#import "LView.h" +#import "LVHeads.h" + +@implementation LVPinchGesture + +-(void) dealloc{ + LVLog(@"LVPinchGesture.dealloc"); + [LVGesture releaseUD:_lv_userData]; +} + +-(id) init:(lua_State*) l{ + self = [super initWithTarget:self action:@selector(handleGesture:)]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + } + return self; +} + +-(void) handleGesture:(LVPinchGesture*)sender { + lua_State* l = self.lv_luaviewCore.l; + if ( l ){ + lua_checkstack32(l); + lv_pushUserdata(l,self.lv_userData); + [LVUtil call:l lightUserData:self key1:"callback" key2:NULL nargs:1]; + } +} + +static int lvNewPinchGestureRecognizer (lua_State *L) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVPinchGesture class]]; + { + LVPinchGesture* gesture = [[c alloc] init:L]; + + if( lua_type(L, 1) != LUA_TFUNCTION ) { + [LVUtil registryValue:L key:gesture stack:1]; + } + + { + NEW_USERDATA(userData, Gesture); + gesture.lv_userData = userData; + userData->object = CFBridgingRetain(gesture); + + luaL_getmetatable(L, META_TABLE_PinchGesture ); + lua_setmetatable(L, -2); + } + } + return 1; /* new userdatum is already on the stack */ +} + +static int scale (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( LVIsType(user, Gesture) ){ + LVPinchGesture* gesture = (__bridge LVPinchGesture *)(user->object); + float s = gesture.scale; + lua_pushnumber(L, s); + return 1; + } + return 0; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewPinchGestureRecognizer globalName:globalName defaultName:@"PinchGesture"]; + + lv_createClassMetaTable(L ,META_TABLE_PinchGesture); + + luaL_openlib(L, NULL, [LVGesture baseMemberFunctions], 0); + + { + const struct luaL_Reg memberFunctions [] = { + {"scale", scale}, + {NULL, NULL} + }; + luaL_openlib(L, NULL, memberFunctions, 0); + } + return 1; +} + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPointerValueBox.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPointerValueBox.h new file mode 100644 index 00000000..8286f1d6 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPointerValueBox.h @@ -0,0 +1,17 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import + +@interface LVPointerValueBox : NSObject + +-(id) initWithPointer:(void*) pointer; + +@property (nonatomic, assign) void* pointer; + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPointerValueBox.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPointerValueBox.m new file mode 100644 index 00000000..08c050d0 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPointerValueBox.m @@ -0,0 +1,22 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVPointerValueBox.h" + +@implementation LVPointerValueBox + +-(id) initWithPointer:(void*) pointer{ + self = [super init]; + if ( self ){ + self.pointer = pointer; + } + return self; +} + + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRefreshComponent.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRefreshComponent.h new file mode 100644 index 00000000..003cc6d6 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRefreshComponent.h @@ -0,0 +1,81 @@ + +#import +#import "LVRefreshConst.h" +#import "UIScrollView+LVRefresh.h" + +/** 刷新控件的状态 */ +typedef NS_ENUM(NSInteger, LVRefreshState) { + /** 普通闲置状态 */ + LVRefreshStateIdle = 1, + /** 松开就可以进行刷新的状态 */ + LVRefreshStatePulling, + /** 正在刷新中的状态 */ + LVRefreshStateRefreshing, + /** 即将刷新的状态 */ + LVRefreshStateWillRefresh, + /** 所有数据加载完毕,没有更多的数据了 */ + LVRefreshStateNoMoreData +}; + +/** 进入刷新状态的回调 */ +typedef void (^LVRefreshComponentRefreshingBlock)(); + +/** 刷新控件的基类 */ +@interface LVRefreshComponent : UIView +{ + /** 记录scrollView刚开始的inset */ + UIEdgeInsets _scrollViewOriginalInset; + /** 父控件 */ + __weak UIScrollView *_scrollView; +} +#pragma mark - 刷新回调 +/** 正在刷新的回调 */ +@property (copy, nonatomic) LVRefreshComponentRefreshingBlock refreshingBlock; +/** 设置回调对象和回调方法 */ +- (void)setRefreshingTarget:(id)target refreshingAction:(SEL)action; +/** 回调对象 */ +@property (weak, nonatomic) id refreshingTarget; +/** 回调方法 */ +@property (assign, nonatomic) SEL refreshingAction; +/** 触发回调(交给子类去调用) */ +- (void)executeRefreshingCallback; + +#pragma mark - 刷新状态控制 +/** 进入刷新状态 */ +- (void)beginRefreshing; +/** 结束刷新状态 */ +- (void)endRefreshing; +/** 是否正在刷新 */ +- (BOOL)isRefreshing; +/** 刷新状态 一般交给子类内部实现 */ +@property (assign, nonatomic) LVRefreshState state; + +#pragma mark - 交给子类去访问 +/** 记录scrollView刚开始的inset */ +@property (assign, nonatomic, readonly) UIEdgeInsets scrollViewOriginalInset; +/** 父控件 */ +@property (weak, nonatomic, readonly) UIScrollView *scrollView; + +#pragma mark - 交给子类们去实现 +/** 初始化 */ +- (void)prepare NS_REQUIRES_SUPER; +/** 摆放子控件frame */ +- (void)placeSubviews NS_REQUIRES_SUPER; +/** 当scrollView的contentOffset发生改变的时候调用 */ +- (void)scrollViewContentOffsetDidChange:(NSDictionary *)change NS_REQUIRES_SUPER; +/** 当scrollView的contentSize发生改变的时候调用 */ +- (void)scrollViewContentSizeDidChange:(NSDictionary *)change NS_REQUIRES_SUPER; +/** 当scrollView的拖拽状态发生改变的时候调用 */ +- (void)scrollViewPanStateDidChange:(NSDictionary *)change NS_REQUIRES_SUPER; + + +#pragma mark - 其他 +/** 拉拽的百分比(交给子类重写) */ +@property (assign, nonatomic) CGFloat pullingPercent; +/** 根据拖拽比例自动切换透明度 */ +@property (assign, nonatomic, getter=isAutomaticallyChangeAlpha) BOOL automaticallyChangeAlpha; +@end + +@interface UILabel(LVRefresh) ++ (instancetype)label; +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRefreshComponent.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRefreshComponent.m new file mode 100644 index 00000000..236d6ef0 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRefreshComponent.m @@ -0,0 +1,227 @@ + + +#import "LVRefreshComponent.h" +#import "LVRefreshConst.h" +#import +#import + + + +@interface LVRefreshComponent() +@property (strong, nonatomic) UIPanGestureRecognizer *pan; +@end + +@implementation LVRefreshComponent +#pragma mark - 初始化 +- (instancetype)initWithFrame:(CGRect)frame +{ + if (self = [super initWithFrame:frame]) { + // 准备工作 + [self prepare]; + + // 默认是普通状态 + self.state = LVRefreshStateIdle; + } + return self; +} + +- (void)prepare +{ + // 基本属性 + self.autoresizingMask = UIViewAutoresizingFlexibleWidth; + self.backgroundColor = [UIColor clearColor]; +} + +- (void)layoutSubviews +{ + [super layoutSubviews]; + + [self placeSubviews]; +} + +- (void)placeSubviews{} + +- (void)willMoveToSuperview:(UIView *)newSuperview +{ + [super willMoveToSuperview:newSuperview]; + + // 如果不是UIScrollView,不做任何事情 + if (newSuperview && ![newSuperview isKindOfClass:[UIScrollView class]]) return; + + // 旧的父控件移除监听 + [self removeObservers]; + + if (newSuperview) { // 新的父控件 + // 设置宽度 + { + CGRect f = self.frame; + f.size.width = newSuperview.frame.size.width; + self.frame = f; + } + // 设置位置 + { + CGRect f = self.frame; + f.origin.x = 0; + self.frame = f; + } + + // 记录UIScrollView + _scrollView = (UIScrollView *)newSuperview; + // 设置永远支持垂直弹簧效果 + _scrollView.alwaysBounceVertical = YES; + // 记录UIScrollView最开始的contentInset + _scrollViewOriginalInset = _scrollView.contentInset; + + // 添加监听 + [self addObservers]; + } +} + +- (void)drawRect:(CGRect)rect +{ + [super drawRect:rect]; + + if (self.state == LVRefreshStateWillRefresh) { + // 预防view还没显示出来就调用了beginRefreshing + self.state = LVRefreshStateRefreshing; + } +} + +#pragma mark - KVO监听 +- (void)addObservers +{ + NSKeyValueObservingOptions options = NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld; + [self.scrollView addObserver:self forKeyPath:LVRefreshKeyPathContentOffset options:options context:nil]; + [self.scrollView addObserver:self forKeyPath:LVRefreshKeyPathContentSize options:options context:nil]; + self.pan = self.scrollView.panGestureRecognizer; + [self.pan addObserver:self forKeyPath:LVRefreshKeyPathPanState options:options context:nil]; +} + +- (void)removeObservers +{ + [self.superview removeObserver:self forKeyPath:LVRefreshKeyPathContentOffset]; + [self.superview removeObserver:self forKeyPath:LVRefreshKeyPathContentSize];; + [self.pan removeObserver:self forKeyPath:LVRefreshKeyPathPanState]; + self.pan = nil; +} + +- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context +{ + // 遇到这些情况就直接返回 + if (!self.userInteractionEnabled) return; + + // 这个就算看不见也需要处理 + if ([keyPath isEqualToString:LVRefreshKeyPathContentSize]) { + [self scrollViewContentSizeDidChange:change]; + } + + // 看不见 + if (self.hidden) return; + if ([keyPath isEqualToString:LVRefreshKeyPathContentOffset]) { + [self scrollViewContentOffsetDidChange:change]; + } else if ([keyPath isEqualToString:LVRefreshKeyPathPanState]) { + [self scrollViewPanStateDidChange:change]; + } +} + +- (void)scrollViewContentOffsetDidChange:(NSDictionary *)change{} +- (void)scrollViewContentSizeDidChange:(NSDictionary *)change{} +- (void)scrollViewPanStateDidChange:(NSDictionary *)change{} + +#pragma mark - 公共方法 +#pragma mark 设置回调对象和回调方法 +- (void)setRefreshingTarget:(id)target refreshingAction:(SEL)action +{ + self.refreshingTarget = target; + self.refreshingAction = action; +} + +#pragma mark 进入刷新状态 +- (void)beginRefreshing +{ + [UIView animateWithDuration:LVRefreshFastAnimationDuration animations:^{ + self.alpha = 1.0; + }]; + self.pullingPercent = 1.0; + // 只要正在刷新,就完全显示 + if (self.window) { + self.state = LVRefreshStateRefreshing; + } else { + self.state = LVRefreshStateWillRefresh; + // 刷新(预防从另一个控制器回到这个控制器的情况,回来要重新刷新一下) + [self setNeedsDisplay]; + } +} + +#pragma mark 结束刷新状态 +- (void)endRefreshing +{ + self.state = LVRefreshStateIdle; +} + +#pragma mark 是否正在刷新 +- (BOOL)isRefreshing +{ + return self.state == LVRefreshStateRefreshing || self.state == LVRefreshStateWillRefresh; +} + +#pragma mark 自动切换透明度 +- (void)setAutoChangeAlpha:(BOOL)autoChangeAlpha +{ + self.automaticallyChangeAlpha = autoChangeAlpha; +} + +- (BOOL)isAutoChangeAlpha +{ + return self.isAutomaticallyChangeAlpha; +} + +- (void)setAutomaticallyChangeAlpha:(BOOL)automaticallyChangeAlpha +{ + _automaticallyChangeAlpha = automaticallyChangeAlpha; + + if (self.isRefreshing) return; + + if (automaticallyChangeAlpha) { + self.alpha = self.pullingPercent; + } else { + self.alpha = 1.0; + } +} + +#pragma mark 根据拖拽进度设置透明度 +- (void)setPullingPercent:(CGFloat)pullingPercent +{ + _pullingPercent = pullingPercent; + + if (self.isRefreshing) return; + + if (self.isAutomaticallyChangeAlpha) { + self.alpha = pullingPercent; + } +} + +#pragma mark - 内部方法 +- (void)executeRefreshingCallback +{ + dispatch_async(dispatch_get_main_queue(), ^{ + if (self.refreshingBlock) { + self.refreshingBlock(); + } + if ([self.refreshingTarget respondsToSelector:self.refreshingAction]) { + LVRefreshMsgSend(LVRefreshMsgTarget(self.refreshingTarget), self.refreshingAction, self); + } + }); +} +@end + +@implementation UILabel(LVRefresh) ++ (instancetype)label +{ + UILabel *label = [[self alloc] init]; + label.autoresizingMask = UIViewAutoresizingFlexibleWidth; + label.textAlignment = NSTextAlignmentCenter; + label.backgroundColor = [UIColor clearColor]; + return label; +} +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRefreshConst.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRefreshConst.h new file mode 100644 index 00000000..04e8a95e --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRefreshConst.h @@ -0,0 +1,25 @@ + +#import +#import + + +//// 运行时objc_msgSend +#define LVRefreshMsgSend(...) ((void (*)(void *, SEL, UIView *))objc_msgSend)(__VA_ARGS__) +#define LVRefreshMsgTarget(target) (__bridge void *)(target) + + +//// 常量 +UIKIT_EXTERN const CGFloat LVRefreshHeaderHeight; +UIKIT_EXTERN const CGFloat LVRefreshFastAnimationDuration; +UIKIT_EXTERN const CGFloat LVRefreshSlowAnimationDuration; + +UIKIT_EXTERN NSString *const LVRefreshKeyPathContentOffset; +UIKIT_EXTERN NSString *const LVRefreshKeyPathContentSize; +UIKIT_EXTERN NSString *const LVRefreshKeyPathContentInset; +UIKIT_EXTERN NSString *const LVRefreshKeyPathPanState; + +// 状态检查 +#define LVRefreshCheckState \ +LVRefreshState oldState = self.state; \ +if (state == oldState) return; \ +[super setState:state]; diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRefreshConst.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRefreshConst.m new file mode 100644 index 00000000..8ffa2d45 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRefreshConst.m @@ -0,0 +1,12 @@ + +#import + +const CGFloat LVRefreshHeaderHeight = 54.0; +const CGFloat LVRefreshFooterHeight = 44.0; +const CGFloat LVRefreshFastAnimationDuration = 0.25; +const CGFloat LVRefreshSlowAnimationDuration = 0.4; + +NSString *const LVRefreshKeyPathContentOffset = @"contentOffset"; +NSString *const LVRefreshKeyPathContentInset = @"contentInset"; +NSString *const LVRefreshKeyPathContentSize = @"contentSize"; +NSString *const LVRefreshKeyPathPanState = @"state"; diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRefreshHeader.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRefreshHeader.h new file mode 100644 index 00000000..b0002ccf --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRefreshHeader.h @@ -0,0 +1,18 @@ + +#import "LVRefreshComponent.h" + +@interface LVRefreshHeader : LVRefreshComponent +/** 创建header */ ++ (instancetype)headerWithRefreshingBlock:(LVRefreshComponentRefreshingBlock)refreshingBlock; +/** 创建header */ ++ (instancetype)headerWithRefreshingTarget:(id)target refreshingAction:(SEL)action; + +/** 这个key用来存储上一次下拉刷新成功的时间 */ +@property (copy, nonatomic) NSString *lastUpdatedTimeKey; +/** 上一次下拉刷新成功的时间 */ +@property (strong, nonatomic, readonly) NSDate *lastUpdatedTime; + +/** 忽略多少scrollView的contentInset的top */ +@property (assign, nonatomic) CGFloat ignoredScrollViewContentInsetTop; + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRefreshHeader.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRefreshHeader.m new file mode 100644 index 00000000..7ce1ebae --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRefreshHeader.m @@ -0,0 +1,181 @@ + + +#import "LVRefreshHeader.h" + +@interface LVRefreshHeader() +@property (assign, nonatomic) CGFloat insetTDelta; +@end + +@implementation LVRefreshHeader +#pragma mark - 构造方法 ++ (instancetype)headerWithRefreshingBlock:(LVRefreshComponentRefreshingBlock)refreshingBlock +{ + LVRefreshHeader *cmp = [[self alloc] init]; + cmp.refreshingBlock = refreshingBlock; + return cmp; +} ++ (instancetype)headerWithRefreshingTarget:(id)target refreshingAction:(SEL)action +{ + LVRefreshHeader *cmp = [[self alloc] init]; + [cmp setRefreshingTarget:target refreshingAction:action]; + return cmp; +} +#pragma mark - 覆盖父类的方法 +- (void)prepare +{ + [super prepare]; + + // 设置key + self.lastUpdatedTimeKey = @"LVRefreshHeaderLastUpdatedTimeKey"; + + // 设置高度f + { + CGRect frame = self.frame; + frame.size.height = LVRefreshHeaderHeight; + self.frame = frame; + } +} + +- (void)placeSubviews +{ + [super placeSubviews]; + + // 设置y值(当自己的高度发生改变了,肯定要重新调整Y值,所以放到placeSubviews方法中设置y值) + { + CGRect frame = self.frame; + frame.origin.y = - frame.size.height - self.ignoredScrollViewContentInsetTop; + self.frame = frame; + } +} + +- (void)scrollViewContentOffsetDidChange:(NSDictionary *)change +{ + [super scrollViewContentOffsetDidChange:change]; + + // 在刷新的refreshing状态 + if (self.state == LVRefreshStateRefreshing) { + if (self.window == nil) return; + + // sectionheader停留解决 + CGPoint offset = self.scrollView.contentOffset; + CGFloat insetT = - offset.y > _scrollViewOriginalInset.top ? - offset.y : _scrollViewOriginalInset.top; + { + CGRect f = self.frame; + insetT = insetT > f.size.height + _scrollViewOriginalInset.top ? f.size.height + _scrollViewOriginalInset.top : insetT; + } + { + UIEdgeInsets inset = self.scrollView.contentInset; + inset.top = insetT; + self.scrollView.contentInset = inset; + } + + self.insetTDelta = _scrollViewOriginalInset.top - insetT; + return; + } + + // 跳转到下一个控制器时,contentInset可能会变 + _scrollViewOriginalInset = self.scrollView.contentInset; + + // 当前的contentOffset + CGPoint offset = self.scrollView.contentOffset; + CGFloat offsetY = offset.y; + // 头部控件刚好出现的offsetY + CGFloat happenOffsetY = - self.scrollViewOriginalInset.top; + + // 如果是向上滚动到看不见头部控件,直接返回 + // >= -> > + if (offsetY > happenOffsetY) return; + + // 普通 和 即将刷新 的临界点 + CGRect f = self.frame; + CGFloat normal2pullingOffsetY = happenOffsetY - f.size.height; + CGFloat pullingPercent = (happenOffsetY - offsetY) / f.size.height; + + if (self.scrollView.isDragging) { // 如果正在拖拽 + self.pullingPercent = pullingPercent; + if (self.state == LVRefreshStateIdle && offsetY < normal2pullingOffsetY) { + // 转为即将刷新状态 + self.state = LVRefreshStatePulling; + } else if (self.state == LVRefreshStatePulling && offsetY >= normal2pullingOffsetY) { + // 转为普通状态 + self.state = LVRefreshStateIdle; + } + } else if (self.state == LVRefreshStatePulling) {// 即将刷新 && 手松开 + // 开始刷新 + [self beginRefreshing]; + } else if (pullingPercent < 1) { + self.pullingPercent = pullingPercent; + } +} + +- (void)setState:(LVRefreshState)state +{ + LVRefreshCheckState + + // 根据状态做事情 + if (state == LVRefreshStateIdle) { + if (oldState != LVRefreshStateRefreshing) return; + + // 保存刷新时间 + [[NSUserDefaults standardUserDefaults] setObject:[NSDate date] forKey:self.lastUpdatedTimeKey]; + [[NSUserDefaults standardUserDefaults] synchronize]; + + // 恢复inset和offset + [UIView animateWithDuration:LVRefreshSlowAnimationDuration animations:^{ + { + UIEdgeInsets inset = self.scrollView.contentInset; + inset.top += self.insetTDelta; + self.scrollView.contentInset = inset; + } + // 自动调整透明度 + if (self.isAutomaticallyChangeAlpha) self.alpha = 0.0; + } completion:^(BOOL finished) { + self.pullingPercent = 0.0; + }]; + } else if (state == LVRefreshStateRefreshing) { + [UIView animateWithDuration:LVRefreshFastAnimationDuration animations:^{ + // 增加滚动区域 + CGRect f = self.frame; + CGFloat top = self.scrollViewOriginalInset.top + f.size.height; + { + UIEdgeInsets inset = self.scrollView.contentInset; + inset.top = top; + self.scrollView.contentInset = inset; + } + + // 设置滚动位置 + { + CGPoint offset = self.scrollView.contentOffset; + offset.y = - top; + self.scrollView.contentOffset = offset; + } + } completion:^(BOOL finished) { + [self executeRefreshingCallback]; + }]; + } +} + +- (void)drawRect:(CGRect)rect +{ + [super drawRect:rect]; + + +} + +#pragma mark - 公共方法 +- (void)endRefreshing +{ + if ([self.scrollView isKindOfClass:[UICollectionView class]]) { + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + [super endRefreshing]; + }); + } else { + [super endRefreshing]; + } +} + +- (NSDate *)lastUpdatedTime +{ + return [[NSUserDefaults standardUserDefaults] objectForKey:self.lastUpdatedTimeKey]; +} +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRotationGesture.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRotationGesture.h new file mode 100644 index 00000000..6f1c248f --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRotationGesture.h @@ -0,0 +1,22 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" +#import "NSObject+LuaView.h" + +@interface LVRotationGesture : UIRotationGestureRecognizer + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; + +-(id) init:(lua_State*) l; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRotationGesture.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRotationGesture.m new file mode 100644 index 00000000..5ace6f9a --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRotationGesture.m @@ -0,0 +1,88 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVRotationGesture.h" +#import "LVGesture.h" +#import "LView.h" +#import "LVHeads.h" + +@implementation LVRotationGesture + +-(void) dealloc{ + LVLog(@"LVRotationGesture.dealloc"); + [LVGesture releaseUD:_lv_userData]; +} + +-(id) init:(lua_State*) l{ + self = [super initWithTarget:self action:@selector(handleGesture:)]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + } + return self; +} + +-(void) handleGesture:(LVRotationGesture*)sender { + lua_State* l = self.lv_luaviewCore.l; + if ( l ){ + lua_checkstack32(l); + lv_pushUserdata(l,self.lv_userData); + [LVUtil call:l lightUserData:self key1:"callback" key2:NULL nargs:1]; + } +} + +static int lvNewRotationGestureRecognizer (lua_State *L) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVRotationGesture class]]; + { + LVRotationGesture* gesture = [[c alloc] init:L]; + + if( lua_type(L, 1) == LUA_TFUNCTION ) { + [LVUtil registryValue:L key:gesture stack:1]; + } + + { + NEW_USERDATA(userData, Gesture); + gesture.lv_userData = userData; + userData->object = CFBridgingRetain(gesture); + + luaL_getmetatable(L, META_TABLE_RotaionGesture ); + lua_setmetatable(L, -2); + } + } + return 1; /* new userdatum is already on the stack */ +} + +static int rotation (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( LVIsType(user, Gesture) ){ + LVRotationGesture* gesture = (__bridge LVRotationGesture *)(user->object); + float s = gesture.rotation; + lua_pushnumber(L, s); + return 1; + } + return 0; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewRotationGestureRecognizer globalName:globalName defaultName:@"RotationGesture"]; + + lv_createClassMetaTable(L ,META_TABLE_RotaionGesture); + + luaL_openlib(L, NULL, [LVGesture baseMemberFunctions], 0); + + { + const struct luaL_Reg memberFunctions [] = { + {"rotation", rotation}, + {NULL, NULL} + }; + luaL_openlib(L, NULL, memberFunctions, 0); + } + return 1; +} + + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVScrollView.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVScrollView.h new file mode 100644 index 00000000..2f48ec67 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVScrollView.h @@ -0,0 +1,28 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" +#import "UIScrollView+LuaView.h" + +@interface LVScrollView : UIScrollView + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; +@property(nonatomic,assign) NSUInteger lv_align; +@property(nonatomic,strong) CAShapeLayer* lv_shapeLayer; + +-(id) init:(lua_State*) l; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + ++(const struct luaL_Reg*) memberFunctions; + +@property(nonatomic,weak) id lvScrollViewDelegate; + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVScrollView.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVScrollView.m new file mode 100644 index 00000000..f913f0c6 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVScrollView.m @@ -0,0 +1,395 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVScrollView.h" +#import "LVBaseView.h" +#import "LVUtil.h" +#import "UIScrollView+LuaView.h" +#import "LVScrollViewDelegate.h" +#import "LVHeads.h" +#import "LView.h" + +@interface LVScrollView () +@property (nonatomic,strong) LVScrollViewDelegate* scrollViewDelegate; +@end + +@implementation LVScrollView + + +-(id) init:(lua_State*) l{ + self = [super init]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + self.scrollViewDelegate = [[LVScrollViewDelegate alloc] init:self]; + self.delegate = self.scrollViewDelegate; + self.alwaysBounceHorizontal = YES; + self.alwaysBounceVertical = NO; + self.showsHorizontalScrollIndicator = NO; + self.showsVerticalScrollIndicator = NO; + self.scrollsToTop = NO; + } + return self; +} + +-(void) setLvScrollViewDelegate:(id)lvScrollViewDelegate{ + _lvScrollViewDelegate = lvScrollViewDelegate; + self.scrollViewDelegate.delegate = lvScrollViewDelegate; +} + +-(void) dealloc{ +} + +- (BOOL)touchesShouldCancelInContentView:(UIView *)view { + return YES; +} + +- (void) layoutSubviews{ + [super layoutSubviews]; + [self lv_alignSubviews]; + [self lv_callLuaByKey1:@STR_ON_LAYOUT]; +} + +#pragma -mark ScrollView +static int lvNewScrollView (lua_State *L) { + { + Class c = [LVUtil upvalueClass:L defaultClass:[LVScrollView class]]; + + LVScrollView* scrollView = [[c alloc] init:L]; + + NEW_USERDATA(userData, View); + userData->object = CFBridgingRetain(scrollView); + scrollView.lv_userData = userData; + + //创建delegate用的事件存储器 + lua_createtable(L, 0, 0); + lv_udataRef(L, USERDATA_KEY_DELEGATE ); + + luaL_getmetatable(L, META_TABLE_UIScrollView ); + lua_setmetatable(L, -2); + + LuaViewCore* view = LV_LUASTATE_VIEW(L); + if( view ){ + [view containerAddSubview:scrollView]; + } + } + return 1; /* new userdatum is already on the stack */ +} + +static int contentSize (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIScrollView* view = (__bridge UIScrollView *)(user->object); + if( [view isKindOfClass:[UIScrollView class]] ){ + if( lua_gettop(L)>=2 ) { + double w = lua_tonumber(L, 2);// 2 + double h = lua_tonumber(L, 3);// 3 + CGSize s = CGSizeMake( w, h ); + if ( isNormalSize(s) ) { + view.contentSize = s; + } + return 0; + } else { + CGSize s = view.contentSize; + lua_pushnumber(L, s.width ); + lua_pushnumber(L, s.height ); + return 2; + } + } + } + return 0; +} + +static int contentOffset (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIScrollView* view = (__bridge UIScrollView *)(user->object); + if( lua_gettop(L)>=2 ) { + double x = lua_tonumber(L, 2);// 2 + double y = lua_tonumber(L, 3);// 3 + BOOL yes = NO; + if( lua_gettop(L)>=4 ) + yes = lua_toboolean(L, 4);// 3 + if( [view isKindOfClass:[UIScrollView class]] ){ + CGPoint p = CGPointMake(x, y); + if( isNormalPoint(p) ) { + CGRect r = view.frame; + r.origin.x = x; + r.origin.y = y; + if( x > view.contentSize.width-view.frame.size.width ) { + x = view.contentSize.width-view.frame.size.width; + } + if( x < 0 ) { + x = 0; + } + if( y > view.contentSize.height-view.frame.size.height ) { + y = view.contentSize.height-view.frame.size.height; + } + if( y < 0 ) { + y = 0; + } + [view setContentOffset:CGPointMake(x, y) animated:yes]; + } + return 0; + } + } else { + CGPoint p = view.contentOffset; + lua_pushnumber(L, p.x ); + lua_pushnumber(L, p.y ); + return 2; + } + } + return 0; +} + +static int contentInset (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIScrollView* view = (__bridge UIScrollView *)(user->object); + if( [view isKindOfClass:[UIScrollView class]] ){ + int num = lua_gettop(L); + if( num>=2 ) { + UIEdgeInsets edgeInsets = view.contentInset; + if( num>=2 ) + edgeInsets.top = lua_tonumber(L, 2); + if( num>=3 ) + edgeInsets.left = lua_tonumber(L, 3); + if( num>=4 ) + edgeInsets.bottom = lua_tonumber(L, 4); + if( num>=5 ) + edgeInsets.right = lua_tonumber(L, 5); + if( isNormalEdgeInsets(edgeInsets) ) { + view.contentInset = edgeInsets; + view.scrollIndicatorInsets = edgeInsets; + } + return 0; + } else { + UIEdgeInsets edgeInsets = view.contentInset; + lua_pushnumber(L, edgeInsets.top ); + lua_pushnumber(L, edgeInsets.left ); + lua_pushnumber(L, edgeInsets.bottom ); + lua_pushnumber(L, edgeInsets.right ); + return 4; + } + } + } + return 0; +} + +//static int pageEnable (lua_State *L) { +// LVUserDataView * user = (LVUserDataView *)lua_touserdata(L, 1); +// if( user ){ +// UIScrollView* view = (__bridge UIScrollView *)(user->view); +// if( [view isKindOfClass:[UIScrollView class]] ){ +// if( lua_gettop(L)>=2 ) { +// BOOL yes = lua_toboolean(L, 2);// 2 +// view.pagingEnabled = yes; +// return 0; +// } else { +// lua_pushnumber(L, view.pagingEnabled ); +// return 1; +// } +// } +// } +// return 0; +//} + +static int showScrollIndicator (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIScrollView* view = (__bridge UIScrollView *)(user->object); + if( [view isKindOfClass:[UIScrollView class]] ){ + if( lua_gettop(L)>=2 ) { + BOOL yes1 = lua_toboolean(L, 2); + BOOL yes2 = lua_toboolean(L, 3); + view.showsHorizontalScrollIndicator = yes1; + view.showsVerticalScrollIndicator = yes2; + return 0; + } else { + lua_pushboolean(L, view.showsHorizontalScrollIndicator ); + lua_pushboolean(L, view.showsVerticalScrollIndicator ); + return 2; + } + } + } + return 0; +} + +//static int initRefreshHeader (lua_State *L) { +// LVUserDataView * user = (LVUserDataView *)lua_touserdata(L, 1); +// if( user ){ +// UIScrollView* scrollView = (__bridge UIScrollView *)(user->view); +// [scrollView lv_initRefreshHeader]; +// } +// return 0; +//} + +static int startHeaderRefreshing (lua_State *L){ + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVScrollView* scrollView = (__bridge LVScrollView *)(user->object); + [scrollView lv_beginRefreshing]; + } + return 0; +} + +static int stopHeaderRefreshing (lua_State *L){ + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVScrollView* scrollView = (__bridge LVScrollView *)(user->object); + [scrollView lv_endRefreshing]; + } + return 0; +} + +static int isHeaderRefreshing (lua_State *L){ + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVScrollView* scrollView = (__bridge LVScrollView *)(user->object); + BOOL yes = [scrollView lv_isRefreshing]; + lua_pushboolean(L, yes); + return 1; + } + return 0; +} + +//static int footerNoticeNoMoreData (lua_State *L){ +// LVUserDataView * user = (LVUserDataView *)lua_touserdata(L, 1); +// if( user ){ +// LVScrollView* scrollView = (__bridge LVScrollView *)(user->view); +// [scrollView lv_noticeNoMoreData]; +// } +// return 0; +//} +// +//static int footerResetNoMoreData (lua_State *L){ +// LVUserDataView * user = (LVUserDataView *)lua_touserdata(L, 1); +// if( user ){ +// LVScrollView* scrollView = (__bridge LVScrollView *)(user->view); +// [scrollView lv_resetNoMoreData]; +// } +// return 0; +//} +// +//static int hiddenRefreshFooter (lua_State *L){ +// LVUserDataView * user = (LVUserDataView *)lua_touserdata(L, 1); +// if( user ){ +// LVScrollView* scrollView = (__bridge LVScrollView *)(user->view); +// BOOL hidden = lua_toboolean(L, 2); +// [scrollView lv_hiddenRefreshFooter:hidden]; +// } +// return 0; +//} + +//static int alwaysBounce(lua_State *L) { +// LVUserDataView * user = (LVUserDataView *)lua_touserdata(L, 1); +// if( user ){ +// UIScrollView* view = (__bridge UIScrollView *)(user->view); +// if( [view isKindOfClass:[UIScrollView class]] ){ +// if( lua_gettop(L)>=2 ) { +// BOOL yesVertical = lua_toboolean(L, 2); +// BOOL yesHorizontal = lua_toboolean(L, 3); +// view.alwaysBounceVertical = yesVertical; +// view.alwaysBounceHorizontal = yesHorizontal; +// return 0; +// } else { +// lua_pushboolean(L, view.alwaysBounceVertical); +// lua_pushboolean(L, view.alwaysBounceHorizontal); +// return 2; +// } +// } +// } +// return 0; +//} + +static int callback (lua_State *L) { + return lv_setCallbackByKey(L, nil, NO); +} + +static void releaseUserDataView(LVUserDataInfo* userdata){ + if( userdata && userdata->object ){ + UIView* view = CFBridgingRelease(userdata->object); + userdata->object = NULL; + if( view ){ + view.lv_userData = nil; + view.lv_luaviewCore = nil; + [view removeFromSuperview]; + [view.layer removeFromSuperlayer]; + if( [view isKindOfClass:[UICollectionView class]] ) { + UICollectionView* collectionView = (UICollectionView*)view; + collectionView.delegate = nil; + collectionView.dataSource = nil; + collectionView.scrollEnabled = NO; + } else if( [view isKindOfClass:[UIScrollView class]] ) { + UIScrollView* scrollView = (UIScrollView*)view; + scrollView.delegate = nil; + scrollView.scrollEnabled = NO; + } + } + } +} + +#pragma -mark __gc +static int __gc (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + releaseUserDataView(user); + return 0; +} + +static const struct luaL_Reg memberFunctions [] = { + {"callback", callback },// 回调 + {"initParams", callback },// 回调 + + {"contentSize", contentSize },// for IOS + {"offset", contentOffset },// + // offsetBy + + {"contentInset", contentInset },// for IOS + + {"showScrollIndicator", showScrollIndicator },// for IOS + + // 下拉刷新 + // {"initRefreshing", initRefreshHeader}, + {"startRefreshing", startHeaderRefreshing},// for IOS ScrollView + {"stopRefreshing", stopHeaderRefreshing},// for IOS ScrollView + {"isRefreshing", isHeaderRefreshing},// for IOS ScrollView + + // 上拉加载更多 + // {"footerNoticeNoMoreData", footerNoticeNoMoreData}, + // {"footerResetNoMoreData", footerResetNoMoreData}, + // {"hiddenRefreshFooter", hiddenRefreshFooter}, + + {"__gc", __gc }, + {NULL, NULL} +}; + ++(const struct luaL_Reg*) memberFunctions{ + return memberFunctions; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewScrollView globalName:globalName defaultName:@"HScrollView"]; + [LVUtil reg:L clas:self cfunc:lvNewScrollView globalName:globalName defaultName:@"HorizontalScrollView"]; + + lv_createClassMetaTable(L ,META_TABLE_UIScrollView); + + luaL_openlib(L, NULL, [LVBaseView baseMemberFunctions], 0); + luaL_openlib(L, NULL, memberFunctions, 0); + + const char* keys[] = { "startRefreshing", "stopRefreshing", "isRefreshing", NULL};// 移除多余API + lv_luaTableRemoveKeys(L, keys ); + return 1; +} + + +//---------------------------------------------------------------------------------------- + +-(NSString*) description{ + return [NSString stringWithFormat:@"", (int)[self hash], + NSStringFromCGRect(self.frame),NSStringFromCGSize(self.contentSize) ]; +} +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVScrollViewDelegate.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVScrollViewDelegate.h new file mode 100644 index 00000000..94f8592a --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVScrollViewDelegate.h @@ -0,0 +1,18 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ +#import +#import + +@interface LVScrollViewDelegate : NSObject + +@property(nonatomic,weak) UIView* owner; +@property(nonatomic,weak) id delegate; + +-(id) init:(UIView*) view; + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVScrollViewDelegate.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVScrollViewDelegate.m new file mode 100644 index 00000000..30c73d8a --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVScrollViewDelegate.m @@ -0,0 +1,72 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVScrollViewDelegate.h" +#import "UIView+LuaView.h" + + +@implementation LVScrollViewDelegate + +-(id) init:(UIView*) tableView{ + self = [super init]; + if( self ){ + self.owner = tableView; + } + return self; +} + +- (void)scrollViewDidScroll:(UIScrollView *)scrollView{ + [self.owner lv_callLuaByKey1:@"Scrolling"]; + if( [self.delegate respondsToSelector:@selector(scrollViewDidScroll:)] ) { + [self.delegate scrollViewDidScroll:scrollView]; + } +} + +- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView{ + if( [self.delegate respondsToSelector:@selector(scrollViewWillBeginDecelerating:)] ) { + [self.delegate scrollViewWillBeginDecelerating:scrollView]; + } +} + +- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{ + [self.owner lv_callLuaByKey1:@"ScrollEnd"]; + if( [self.delegate respondsToSelector:@selector(scrollViewDidEndDecelerating:)] ) { + [self.delegate scrollViewDidEndDecelerating:scrollView]; + } +} + +- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView{ + [self.owner lv_callLuaByKey1:@"ScrollEnd"]; + if( [self.delegate respondsToSelector:@selector(scrollViewDidEndScrollingAnimation:)] ) { + [self.delegate scrollViewDidEndScrollingAnimation:scrollView]; + } +} + +- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{ + [self.owner lv_callLuaByKey1:@"ScrollBegin"]; + if( [self.delegate respondsToSelector:@selector(scrollViewWillBeginDragging:)] ) { + [self.delegate scrollViewWillBeginDragging:scrollView]; + } +} + +- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset { + [self.owner lv_callLuaByKey1:@"DragEnd"]; +} + +- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{ + [self.owner lv_callLuaByKey1:@"DragEnd"]; + if( !decelerate ) { + [self.owner lv_callLuaByKey1:@"ScrollEnd"]; + } + if( [self.delegate respondsToSelector:@selector(scrollViewDidEndDragging:willDecelerate:)] ) { + [self.delegate scrollViewDidEndDragging:scrollView willDecelerate:decelerate]; + } +} + + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVStruct.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVStruct.h new file mode 100644 index 00000000..65b98c9b --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVStruct.h @@ -0,0 +1,26 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + +#define LV_STRUCT_MAX_LEN 16 + +@interface LVStruct : NSObject +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; +- (id) lv_nativeObject; // 返回native对象 + + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + ++(int) pushStructToLua:(lua_State*)L data:(void*)data; + +-(CGFloat*) dataPointer; + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVStruct.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVStruct.m new file mode 100644 index 00000000..ddefbe58 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVStruct.m @@ -0,0 +1,223 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVStruct.h" +#import "LVTypeConvert.h" +#import "LVHeads.h" + + + +@implementation LVStruct{ + CGFloat data[LV_STRUCT_MAX_LEN]; +} + +-(void) setIndex:(NSInteger)index byValue:(CGFloat) value{ + if( index>=0 && index=0 && indexobject = CFBridgingRetain(lvstruct); + lvstruct.lv_userData = userData; + + int num = lua_gettop(L); + + for (int i=1,index=0; (i<=num) && (indexobject = CFBridgingRetain(lvstruct); + lvstruct.lv_userData = userData; + + memcpy( [lvstruct dataPointer], data, LV_STRUCT_MAX_LEN*sizeof(CGFloat) ); + luaL_getmetatable(L, META_TABLE_Struct ); + lua_setmetatable(L, -2); + return 1; +} + + +static int setValue (lua_State *L) { + int argNum = lua_gettop(L); + if( argNum>=3 ) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + unsigned int index = lua_tonumber(L, 2); + CGFloat value = lua_tonumber(L, 3); + if ( index>=LV_STRUCT_MAX_LEN ) { + LVError(@"LVStruct.set index:%d", index ); + return 0; + } + if( LVIsType(user, Struct) ){ + LVStruct* lvstruct = (__bridge LVStruct *)(user->object); + if ( argNum>=4 ) { + int type = lua_tonumber(L, 4); + if( [lvstruct dataPointer] ) { + lv_setValueWithType( [lvstruct dataPointer], index, value, type); + } + } else { + [lvstruct setIndex:index byValue:value]; + } + return 0; + } + } + return 0; +} + +static int getValue (lua_State *L) { + int argNum = lua_gettop(L); + if( argNum>=2 ) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + unsigned int index = lua_tonumber(L, 2); + if ( index>=LV_STRUCT_MAX_LEN ) { + LVError(@"LVStruct.get index:%d", index ); + return 0; + } + if( LVIsType(user, Struct) ){ + LVStruct* stru = (__bridge LVStruct *)(user->object); + if ( argNum>=3 ) { + int type = lua_tonumber(L, 3); + CGFloat value = lv_getValueWithType( [stru dataPointer], index, type); + lua_pushnumber(L, value); + return 1; + } else { + CGFloat value = [stru getValueByIndex:index]; + lua_pushnumber(L, value); + return 1; + } + } + } + return 0; +} + +static int __eq (lua_State *L) { + if( lua_gettop(L)==2 ) { + LVUserDataInfo * user1 = (LVUserDataInfo *)lua_touserdata(L, 1); + LVUserDataInfo * user2 = (LVUserDataInfo *)lua_touserdata(L, 2); + if( LVIsType(user1, Struct) && LVIsType(user2, Struct) ){ + LVStruct* s1 = (__bridge LVStruct *)(user1->object); + LVStruct* s2 = (__bridge LVStruct *)(user2->object); + int size = LV_STRUCT_MAX_LEN; + BOOL yes = NO; + if( [s1 dataPointer] && [s2 dataPointer] ) { + yes = !memcmp( [s1 dataPointer], [s2 dataPointer], size); + } + lua_pushboolean(L, (yes?1:0) ); + return 1; + } + } + return 0; +} + +static int __tostring (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( LVIsType(user, Struct) ){ + NSString* s = [NSString stringWithFormat:@"LVUserDataStruct: %d", (int)user ]; + lua_pushstring(L, s.UTF8String); + return 1; + } + return 0; +} + +static int __index (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + if ( lua_type(L, 2)==LUA_TNUMBER ) { + return getValue(L); + } else if ( lua_type(L, 2)==LUA_TSTRING ){ + NSString* key = lv_paramString(L, 2); + if ( [key isEqualToString:@"get"] ) { + lua_pushcfunction(L, getValue); + return 1; + } + if ( [key isEqualToString:@"set"] ) { + lua_pushcfunction(L, setValue); + return 1; + } + } + } + return 0; /* new userdatum is already on the stack */ +} + +static int __newindex (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + if( lua_type(L, 2)==LUA_TNUMBER ){ + return setValue(L); + } else if( lua_type(L, 3)==LUA_TSTRING ){ + + } + } + return 0; /* new userdatum is already on the stack */ +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + lv_defineGlobalFunc("Struct", lvNewStruct, L); + lv_defineGlobalFunc("Rect", lvNewStruct, L); + lv_defineGlobalFunc("Size", lvNewStruct, L); + lv_defineGlobalFunc("Point", lvNewStruct, L); + + const struct luaL_Reg memberFunctions [] = { + {"__index", __index }, + {"__newindex", __newindex }, + {"__eq", __eq}, + + {"set", setValue}, + {"get", getValue}, + + {"__tostring", __tostring}, + + {NULL, NULL} + }; + + lv_createClassMetaTable(L ,META_TABLE_Struct); + + luaL_openlib(L, NULL, memberFunctions, 0); + +// { +// const struct luaL_Reg memberFunctions2 [] = { +// {"__index", __index }, +// {"__newindex", __newindex }, +// {NULL, NULL} +// }; +// lv_createClassMetaTable(L ,"META_TABLE_Struct" ); +// luaL_openlib(L, NULL, memberFunctions2, 0); +// +// luaL_getmetatable(L, META_TABLE_Struct ); +// luaL_getmetatable(L, "META_TABLE_Struct" ); +// lua_setmetatable(L, -2); +// } + return 1; +} + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVStyledString.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVStyledString.h new file mode 100644 index 00000000..42a2001d --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVStyledString.h @@ -0,0 +1,24 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + + +//LVData +@interface LVStyledString : NSObject + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; + +@property(nonatomic,strong) NSMutableAttributedString* mutableStyledString;//真实的数据 + +-(id) init:(lua_State*) l; ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVStyledString.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVStyledString.m new file mode 100644 index 00000000..094a76b8 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVStyledString.m @@ -0,0 +1,311 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVStyledString.h" +#import "LVHeads.h" +#import "LView.h" + +@interface LVStyledString () +@end + +@implementation LVStyledString + +-(id) init:(lua_State *)l{ + self = [super init]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + } + return self; +} + +- (id) lv_nativeObject{ + return self.mutableStyledString; +} + +static void releaseUserDataData(LVUserDataInfo* user){ + if( user && user->object ){ + LVStyledString* data = CFBridgingRelease(user->object); + user->object = NULL; + if( data ){ + data.lv_userData = NULL; + data.lv_luaviewCore = nil; + data.mutableStyledString = nil; + } + } +} + +static int __attributedString_gc (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + releaseUserDataData(user); + return 0; +} + +static UIFont* getFont(NSString* fontName, NSNumber* fontSize, NSString* fontWeigth, NSString* fontStyle, LVBundle* bundle){ + fontSize = fontSize ? fontSize : @(14);// bugfix: 不设置字体大小, 只设置粗体斜体无效, 所以给定默认字体大小14 + if( [fontName isKindOfClass:[NSString class]] ){ + return [LVUtil fontWithName:fontName size:fontSize.floatValue bundle:bundle]; + } + if ( [fontStyle isKindOfClass:[NSString class]] && + [fontStyle compare:@"italic" options:NSCaseInsensitiveSearch]==NSOrderedSame ) { + return [UIFont italicSystemFontOfSize:fontSize.floatValue]; + } + if( [fontWeigth isKindOfClass:[NSString class]] && + [fontWeigth compare:@"bold" options:NSCaseInsensitiveSearch]==NSOrderedSame ){ + // TODO: 支持数值? + return [UIFont boldSystemFontOfSize:fontSize.floatValue]; + } + return [UIFont systemFontOfSize:fontSize.floatValue]; +} + +// 设置字体 +static void resetFont(NSMutableAttributedString* attString, NSDictionary* dic, NSRange range, LVBundle* bundle){ + NSString* fontName = dic[@"fontName"]; + NSNumber* fontSize = dic[@"fontSize"]; + NSString* fontWeight = dic[@"fontWeight"]; + NSString* fontStyle = dic[@"fontStyle"]; + UIFont* font = getFont(fontName, fontSize, fontWeight, fontStyle, bundle); + if( font ) { + [attString addAttribute:NSFontAttributeName value:font range:range]; + } +} + +// 设置前景色 +static void resetForegroundColor(NSMutableAttributedString* attString, NSDictionary* dic, NSRange range){ + NSNumber* value = dic[@"fontColor"]; + float alpha = 1; + if( value ) { + alpha = (value.integerValue>>24) & 0xff; + alpha /= 255.0; + if( alpha == 0) { + alpha = 1; + } + UIColor* color = lv_UIColorFromRGBA(value.integerValue , alpha ); + [attString addAttribute:NSForegroundColorAttributeName value:color range:range]; + } +} + +// 设置背景色 +static void resetBackgroundColor(NSMutableAttributedString* attString, NSDictionary* dic, NSRange range){ + NSNumber* value = dic[@"backgroundColor"]; + float alpha = 1; + if( value ) { + alpha = (value.integerValue>>24) & 0xff; + alpha /= 255.0; + if( alpha == 0) { + alpha = 1; + } + UIColor* color = lv_UIColorFromRGBA(value.integerValue , alpha ); + [attString addAttribute:NSBackgroundColorAttributeName value:color range:range]; + } +} + +static BOOL isNotZeroOrFalse( id value ){ + if( [value isKindOfClass:[NSNumber class]] ) { + NSNumber* v = value; + if( v.intValue == 0 ){ + return NO; + } + if( v.boolValue== NO ) { + return NO; + } + } + return YES; +} + +// 设置划线 +static void resetStriketrhroughSytle(NSMutableAttributedString* attString, NSDictionary* dic, NSRange range){ + NSNumber* value = dic[@"strikethrough"]; + if( value && isNotZeroOrFalse(value) ){ + [attString addAttribute:NSStrikethroughStyleAttributeName value:value range:range]; + } else { + // IOS 8 系统bugfix( 有中划线和我无中划线都要设置属性, 否则有中划线不会出现 ) + [attString addAttribute:NSStrikethroughStyleAttributeName value:@(NSUnderlineStyleNone) range:range]; + } +} + +//下划线 +static void resetUnderLineStyle(NSMutableAttributedString* attString, NSDictionary* dic, NSRange range){ + NSNumber* value = dic[@"underline"]; + if( value && isNotZeroOrFalse(value) ){ + [attString addAttribute:NSUnderlineStyleAttributeName value:value range:range]; + } +} + +//设置字间距 +static void resetCharSpace(NSMutableAttributedString* attString, NSDictionary* dic, NSRange range){ + NSNumber* value = dic[@"charSpace"]; + if( value ){ + [attString addAttribute:(id)NSKernAttributeName value:value range:range]; + } +} + +//设置行间距 +static void resetLineSpace(NSMutableAttributedString* attString, NSDictionary* dic, NSRange range){ + NSNumber* value = dic[@"lineSpace"]; + if( value ) { + NSMutableParagraphStyle * paragraphStyle1 = [[NSMutableParagraphStyle alloc] init]; + paragraphStyle1.lineBreakMode = NSLineBreakByTruncatingTail; + [paragraphStyle1 setLineSpacing:value.intValue]; + [attString addAttribute:(id)NSParagraphStyleAttributeName value:paragraphStyle1 range:range]; + } +} + + +static void resetAttributedString(NSMutableAttributedString* attString, NSDictionary* dic, NSRange range ,LVBundle* bundle){ + resetFont(attString, dic, range, bundle); + resetForegroundColor(attString, dic, range); + resetBackgroundColor(attString, dic, range); + resetStriketrhroughSytle(attString, dic, range); + resetUnderLineStyle(attString, dic, range); + resetCharSpace(attString, dic, range); + resetLineSpace(attString, dic, range); +} + +static int lvNewAttributedString (lua_State *L) { + LuaViewCore* luaView = LV_LUASTATE_VIEW(L); + LVStyledString* attString = [[LVStyledString alloc] init:L]; + if( luaView && lua_gettop(L)>=2 ) { + if( ( lua_type(L, 1)==LUA_TSTRING || lua_type(L, 1)==LUA_TNUMBER ) && lua_type(L, 2)==LUA_TTABLE ){ + NSString* s = nil; + size_t n = 0; + const char* chars = lua_tolstring(L, 1, &n ); + s = [NSString stringWithUTF8String:chars]; + + // 字符串格式非法,导致crash + if( s==nil ) { + s = @""; + } + + attString.mutableStyledString = [[NSMutableAttributedString alloc] initWithString:s]; + + NSDictionary* dic = lv_luaTableToDictionary(L,2); + NSRange range = {0}; + range.location = 0; + range.length = s.length; + if( [dic isKindOfClass:[NSDictionary class]] ) { + resetAttributedString(attString.mutableStyledString, dic, range, luaView.bundle); + } + } + } + + { + NEW_USERDATA(userData, StyledString); + userData->object = CFBridgingRetain(attString); + attString.lv_userData = userData; + + luaL_getmetatable(L, META_TABLE_AttributedString ); + lua_setmetatable(L, -2); + } + return 1; +} + +static int __tostring (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVStyledString* attString = (__bridge LVStyledString *)(user->object); + NSString* s = attString.mutableStyledString.string; + if( s==nil ){ + s = [[NSString alloc] initWithFormat:@"{ UserDataType=AttributedString, null }" ]; + } + lua_pushstring(L, s.UTF8String); + return 1; + } + return 0; +} + +static int append (lua_State *L) { + LVUserDataInfo * user1 = (LVUserDataInfo *)lua_touserdata(L, 1); + LVUserDataInfo * user2 = (LVUserDataInfo *)lua_touserdata(L, 2); + LVStyledString* string1 = (__bridge LVStyledString *)(user1->object); + LVStyledString* string2 = (__bridge LVStyledString *)(user2->object); + if( LVIsType(user1, StyledString) && LVIsType(user2, StyledString) + && string1.mutableStyledString && string2.mutableStyledString ){ + [string1.mutableStyledString appendAttributedString: string2.mutableStyledString]; + return 1; + } + return 0; +} + +static int __add (lua_State *L) { + if( lua_type(L, 2)==LUA_TUSERDATA ) { + LVUserDataInfo * user1 = (LVUserDataInfo *)lua_touserdata(L, 1); + LVUserDataInfo * user2 = (LVUserDataInfo *)lua_touserdata(L, 2); + if( LVIsType(user1, StyledString) && LVIsType(user2, StyledString) ){ + LVStyledString* user1AttString = (__bridge LVStyledString *)(user1->object); + LVStyledString* user2AttString = (__bridge LVStyledString *)(user2->object); + + LVStyledString* attString = [[LVStyledString alloc] init:L]; + attString.mutableStyledString = [[NSMutableAttributedString alloc] init]; + if( user1AttString && user1AttString.mutableStyledString) + [attString.mutableStyledString appendAttributedString:user1AttString.mutableStyledString]; + if( user2AttString && user2AttString.mutableStyledString) + [attString.mutableStyledString appendAttributedString:user2AttString.mutableStyledString]; + { + NEW_USERDATA(userData, StyledString); + userData->object = CFBridgingRetain(attString); + attString.lv_userData = userData; + + luaL_getmetatable(L, META_TABLE_AttributedString ); + lua_setmetatable(L, -2); + } + return 1; + } + } else if( lua_type(L, 2)==LUA_TSTRING || lua_type(L, 2)==LUA_TNUMBER ) { + LVUserDataInfo * user1 = (LVUserDataInfo *)lua_touserdata(L, 1); + NSString* stringArg = nil; + if( lua_type(L, 2)==LUA_TSTRING ) { + stringArg = lv_paramString(L, 2); + } else { + size_t n = 0; + const char* chars = lua_tolstring(L, 2, &n ); + stringArg = [NSString stringWithUTF8String:chars]; + } + if( LVIsType(user1, StyledString) ){ + LVStyledString* user1AttString = (__bridge LVStyledString *)(user1->object); + + LVStyledString* attString = [[LVStyledString alloc] init:L]; + attString.mutableStyledString = [[NSMutableAttributedString alloc] init]; + if( user1AttString && user1AttString.mutableStyledString) + [attString.mutableStyledString appendAttributedString:user1AttString.mutableStyledString]; + if( stringArg ) { + [attString.mutableStyledString appendAttributedString:[[NSMutableAttributedString alloc] initWithString:stringArg]]; + } + { + NEW_USERDATA(userData, StyledString); + userData->object = CFBridgingRetain(attString); + attString.lv_userData = userData; + + luaL_getmetatable(L, META_TABLE_AttributedString ); + lua_setmetatable(L, -2); + } + return 1; + } + } + return 0; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewAttributedString globalName:globalName defaultName:@"StyledString"]; + + const struct luaL_Reg memberFunctions [] = { + {"append", append }, + + {"__add", __add }, + {"__gc", __attributedString_gc }, + + {"__tostring", __tostring }, + {NULL, NULL} + }; + lv_createClassMetaTable(L, META_TABLE_AttributedString); + + luaL_openlib(L, NULL, memberFunctions, 0); + return 0; +} + + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVSwipeGesture.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVSwipeGesture.h new file mode 100644 index 00000000..261d1d84 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVSwipeGesture.h @@ -0,0 +1,22 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" +#import "NSObject+LuaView.h" + +@interface LVSwipeGesture : UISwipeGestureRecognizer + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; + +-(id) init:(lua_State*) l; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVSwipeGesture.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVSwipeGesture.m new file mode 100644 index 00000000..3731ac60 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVSwipeGesture.m @@ -0,0 +1,124 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVSwipeGesture.h" +#import "LVGesture.h" +#import "LView.h" +#import "LVHeads.h" + +@implementation LVSwipeGesture + + +-(void) dealloc{ + LVLog(@"LVSwipeGesture.dealloc"); + [LVGesture releaseUD:_lv_userData]; +} + +-(id) init:(lua_State*) l{ + self = [super initWithTarget:self action:@selector(handleGesture:)]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + } + return self; +} + +-(void) handleGesture:(LVSwipeGesture*)sender { + lua_State* l = self.lv_luaviewCore.l; + if ( l ){ + lua_checkstack32(l); + lv_pushUserdata(l,self.lv_userData); + [LVUtil call:l lightUserData:self key1:"callback" key2:NULL nargs:1]; + } +} + +static int lvSwipeGestureRecognizer (lua_State *L) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVSwipeGesture class]]; + { + LVSwipeGesture* gesture = [[c alloc] init:L]; + + if( lua_type(L, 1) == LUA_TFUNCTION ) { + [LVUtil registryValue:L key:gesture stack:1]; + } + + { + NEW_USERDATA(userData, Gesture); + gesture.lv_userData = userData; + userData->object = CFBridgingRetain(gesture); + + luaL_getmetatable(L, META_TABLE_SwipeGesture ); + lua_setmetatable(L, -2); + } + } + return 1; /* new userdatum is already on the stack */ +} + +static int touchCount (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( LVIsType(user, Gesture) ){ + LVSwipeGesture* gesture = (__bridge LVSwipeGesture *)(user->object); + if( lua_gettop(L)>=2 ) { + float num = lua_tonumber(L, 2); + gesture.numberOfTouchesRequired = num; + return 0; + } else { + float num = gesture.numberOfTouchesRequired; + lua_pushnumber(L, num); + return 1; + } + } + return 0; +} + +static int direction (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( LVIsType(user, Gesture) ){ + LVSwipeGesture* gesture = (__bridge LVSwipeGesture *)(user->object); + if ( lua_gettop(L)>=2 ) { + float num = lua_tonumber(L, 2); + gesture.direction = num; + return 0; + } else { + float direction = gesture.direction; + lua_pushnumber(L, direction); + return 1; + } + } + return 0; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + { + lua_settop(L, 0); + NSDictionary* v = nil; + v = @{ + @"LEFT":@(UISwipeGestureRecognizerDirectionLeft), + @"RIGHT":@(UISwipeGestureRecognizerDirectionRight), + @"UP":@(UISwipeGestureRecognizerDirectionUp), + @"DOWN":@(UISwipeGestureRecognizerDirectionDown), + }; + [LVUtil defineGlobal:@"GestureDirection" value:v L:L]; + } + + [LVUtil reg:L clas:self cfunc:lvSwipeGestureRecognizer globalName:globalName defaultName:@"SwipeGesture"]; + + lv_createClassMetaTable(L ,META_TABLE_SwipeGesture); + luaL_openlib(L, NULL, [LVGesture baseMemberFunctions], 0); + { + const struct luaL_Reg memberFunctions [] = { + {"touchCount", touchCount}, + {"direction", direction}, + {NULL, NULL} + }; + luaL_openlib(L, NULL, memberFunctions, 0); + } + return 1; +} + + + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVSystem.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVSystem.h new file mode 100644 index 00000000..fe138d49 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVSystem.h @@ -0,0 +1,21 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + +@interface LVSystem : NSObject + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +/* + * 获取网络状态, 需要重载API获取网络链接信息: 2g 3g 4g wifi 未知类型返回unkown 断网返回"none" + */ ++(NSString*) netWorkType; + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVSystem.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVSystem.m new file mode 100644 index 00000000..cdf379f5 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVSystem.m @@ -0,0 +1,303 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVSystem.h" +#import "LView.h" +#import "LVPkgManager.h" +#import +#import "LVHeads.h" +#import "LVNetworkStatus.h" +#import "LVAnimator.h" + +@implementation LVSystem + + +// lv 扩展API +static int vmVersion (lua_State *L) { + lua_pushstring(L, LUAVIEW_VERSION ) ; + return 1; /* number of results */ +} + +// lv 扩展API +static int sdkVersion (lua_State *L) { + lua_pushstring(L, LUAVIEW_SDK_VERSION ) ; + return 1; /* number of results */ +} + +// lv 扩展API +static int osVersion (lua_State *L) { + NSString* v = [[UIDevice currentDevice] systemVersion]; + lua_pushstring(L, v.UTF8String); + return 1; /* number of results */ +} + +static int ios (lua_State *L) { + lua_pushboolean(L, 1); + return 1; +} + +static int android (lua_State *L) { + lua_pushboolean(L, 0); + return 1; +} + + ++(NSString*) netWorkType{ + return [[LVNetworkStatus shareInstance] currentNetworkStatusString]; +} + +static int netWorkType (lua_State *L) { + NSString* type = [LVSystem netWorkType]; + lua_pushstring(L, type.UTF8String); + return 1; +} + +static int layerMode (lua_State *L) { + if( lua_gettop(L)>0 ){ + BOOL yes = lua_toboolean(L, -1); + LuaViewCore* luaview = LV_LUASTATE_VIEW(L); + luaview.closeLayerMode = !yes; + } + return 0; +} + +// 屏幕常亮 +static int keepScreenOn (lua_State *L) { + if( lua_gettop(L)>0 ){ + BOOL yes = lua_toboolean(L, -1); + [[UIApplication sharedApplication] setIdleTimerDisabled:yes] ; + } + return 0; +} + +static int scale (lua_State *L) { + CGFloat s = [UIScreen mainScreen].scale; + lua_pushnumber( L, s); + return 1; /* number of results */ +} + + +// lv 扩展API +static int platform (lua_State *L) { + NSString* name = [[UIDevice currentDevice] systemName]; + NSString* version = [[UIDevice currentDevice] systemVersion]; + NSString* buf = [NSString stringWithFormat:@"%@;%@",name,version]; + lua_pushstring(L, [buf UTF8String] ) ; + return 1; /* number of results */ +} + +static int device (lua_State *L) { + NSString* name = [[UIDevice currentDevice] localizedModel]; + NSString* version = [[UIDevice currentDevice] model]; + NSString* buf = [NSString stringWithFormat:@"%@;%@",name,version]; + lua_pushstring(L, [buf UTF8String] ) ; + return 1; /* number of results */ +} + +// lv 扩展API +static int screenSize (lua_State *L) { + CGSize s = [UIScreen mainScreen].bounds.size; + lua_pushnumber(L, s.width ); + lua_pushnumber(L, s.height ); + return 2; /* number of results */ +} + +static int static_gc (lua_State *L) { + lua_gc(L, 2, 0); + return 0; +} + +static int vibrate(lua_State*L){ + AudioServicesPlaySystemSound(kSystemSoundID_Vibrate); + return 1; +} + +static int lvClassLoader(lua_State*L){ + NSString* s = lv_paramString(L, -1); + id obj = NSClassFromString(s); + lv_pushNativeObject(L, obj); + return 1; +} + +static int stringToTable(lua_State*L){ + if( lua_type(L, -1) == LUA_TSTRING ) { + NSString* s = lv_paramString(L, -1); + if( s ) { + id obj = [LVUtil stringToObject:s]; + lv_pushNativeObject(L, obj); + return 1; + } + } + return 0; +} + +static int tableToString(lua_State*L){ + if( lua_type(L, -1) == LUA_TTABLE ) { + id obj = lv_luaValueToNativeObject(L,-1); + NSString* s = [LVUtil objectToString:obj]; + lua_pushstring(L, s.UTF8String); + return 1; + } + return 0; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + { + // System API + const struct luaL_Reg staticFunctions [] = { + {"screenSize", screenSize}, + {"gc",static_gc}, + {"osVersion", osVersion}, + {"vmVersion", vmVersion}, + {"sdkVersion", sdkVersion}, + {"scale", scale}, + {"platform",platform}, + {"device",device}, + {"ios", ios}, + {"android", android}, + {"network", netWorkType}, + {"keepScreenOn", keepScreenOn},// 保持屏幕常亮接口 + {"layerMode", layerMode},// (for IOS) 是否开启layer模式 + {NULL, NULL} + }; + luaL_openlib(L, "System", staticFunctions, 0); + } + { + // Json Table相互转换 + const struct luaL_Reg fs [] = { + {"toString", tableToString}, + {"toJson", tableToString}, + {"toTable",stringToTable}, + {NULL, NULL} + }; + luaL_openlib(L, "Json", fs, 0); + } + // ---- 常量注册 ---- + { + // Align 常量 + lua_settop(L, 0); + NSDictionary* v = nil; + v = @{ + @"LEFT": @(LV_ALIGN_LEFT), + @"RIGHT": @(LV_ALIGN_RIGHT), + @"TOP": @(LV_ALIGN_TOP), + @"BOTTOM": @(LV_ALIGN_BOTTOM), + @"H_CENTER":@(LV_ALIGN_H_CENTER),// 水平居中 + @"V_CENTER":@(LV_ALIGN_V_CENTER),// 垂直居中 + @"CENTER": @(LV_ALIGN_H_CENTER|LV_ALIGN_V_CENTER),// 上下左右都居中 + }; + [LVUtil defineGlobal:@"Align" value:v L:L]; + } + { + lua_settop(L, 0); + NSDictionary* v = nil; + v = @{ + @"LEFT":@(NSTextAlignmentLeft), + @"RIGHT":@(NSTextAlignmentRight), + @"CENTER":@(NSTextAlignmentCenter),// 上下左右都居中 + }; + [LVUtil defineGlobal:@"TextAlign" value:v L:L]; + } + { + //文本太多 "..." 出现的问题 + lua_settop(L, 0); + NSDictionary* v = nil; + v = @{ + @"START":@(NSLineBreakByTruncatingHead), + @"MIDDLE":@(NSLineBreakByTruncatingMiddle), + @"END":@(NSLineBreakByTruncatingTail), + @"MARQUEE":@(NSLineBreakByCharWrapping), + }; + [LVUtil defineGlobal:@"Ellipsize" value:v L:L]; + } + { + //字体Style + lua_settop(L, 0); + NSDictionary* v = nil; + v = @{ + @"NORMAL":@"normal",//正常 + @"ITALIC":@"italic",//斜体 + @"OBLIQUE":@"oblique",//倾斜 //__deprecated_msg("") + // BOLD IOS 不支持 + // + }; + [LVUtil defineGlobal:@"FontStyle" value:v L:L]; + } + { + //字体Weight(粗体、正常) + lua_settop(L, 0); + NSDictionary* v = nil; + v = @{ + @"NORMAL":@"normal", + @"BOLD":@"bold", + }; + [LVUtil defineGlobal:@"FontWeight" value:v L:L]; + } + { + //图片缩放常量 + lua_settop(L, 0); + NSDictionary* v = nil; + v = @{ + @"CENTER":@(UIViewContentModeCenter),//按图片的原来size居中显示,当图片长/宽超过View的长/宽,则截取图片的居中部分显示 + @"CENTER_CROP":@(UIViewContentModeScaleAspectFill),//将图片等比居中显示,完全覆盖view,尽可能小; + @"CENTER_INSIDE":@(UIViewContentModeScaleAspectFit),//将图片的内容完整居中显示,尽可能的大 + @"FIT_CENTER":@(UIViewContentModeScaleAspectFit),//将图片的内容完整居中显示,尽可能的大 + @"FIT_END":@(UIViewContentModeScaleAspectFill),//把图片按比例扩大(缩小)到View的宽度,显示在View的下部分位置 + @"FIT_START":@(UIViewContentModeScaleAspectFill),//把图片按比例扩大(缩小)到View的宽度,显示在View的上部分位置 + @"FIT_XY":@(UIViewContentModeScaleToFill),//把图片按照指定的大小在View中显示 + @"MATRIX":@(UIViewContentModeScaleAspectFill),//用matrix来绘制 + }; + [LVUtil defineGlobal:@"ScaleType" value:v L:L]; + } + { + lua_settop(L, 0); + NSDictionary* v = nil; + v = @{ + @"LINEAR" : @(LVLinearInterpolator), + @"ACCELERATE" : @(LVAccelerateInterpolator), + @"DECELERATE" : @(LVDecelerateInterpolator), + @"ACCELERATE_DECELERATE" : @(LVAccelerateDecelerateInterpolator), + @"ANTICIPATE": @(LVAnticipateInterpolator), + @"OVERSHOOT": @(LVOvershootInterpolator), + @"ANTICIPATE_OVERSHOOT": @(LVAnticipateOvershootInterpolator), + }; + [LVUtil defineGlobal:@"Interpolator" value:v L:L]; + } + { + // 坑位浮动Pinned + lua_settop(L, 0); + NSDictionary* v = nil; + v = @{ + @"YES":@(YES), + @"Yes":@(YES),//__deprecated_msg("Use YES") + @"yes":@(YES),//__deprecated_msg("Use YES") + }; + [LVUtil defineGlobal:@"Pinned" value:v L:L]; + } + + { + // ViewEffect define + lua_settop(L, 0); + NSDictionary* v = nil; + v = @{ + @"NONE":@(EFFECT_NONE), + @"CLICK":@(EFFECT_CLICK), + @"PARALLAX":@(EFFECT_PARALLAX), + }; + [LVUtil defineGlobal:@"ViewEffect" value:v L:L]; + } + + // 震动 完全不兼容安卓, 安卓是类, vabrate(数组) cancel() hasVabrate(); + lv_defineGlobalFunc("Vibrate", vibrate, L); + + // create class api + lv_defineGlobalFunc("__class__", lvClassLoader, L); + return 0; +} + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTapGesture.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTapGesture.h new file mode 100644 index 00000000..5872fd83 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTapGesture.h @@ -0,0 +1,25 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import +#import "LVHeads.h" +#import "NSObject+LuaView.h" + +@interface LVTapGesture : UITapGestureRecognizer + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; + +-(id) init:(lua_State*) l; + + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTapGesture.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTapGesture.m new file mode 100644 index 00000000..d77bff3a --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTapGesture.m @@ -0,0 +1,77 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVTapGesture.h" +#import "LVGesture.h" +#import "LView.h" +#import "LVHeads.h" + +@implementation LVTapGesture + + +-(void) dealloc{ + LVLog(@"LVTapGesture.dealloc"); + [LVGesture releaseUD:_lv_userData]; +} + +-(id) init:(lua_State*) l{ + self = [super initWithTarget:self action:@selector(handleGesture:)]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + } + return self; +} + + + +-(void) handleGesture:(LVTapGesture*)sender { + lua_State* l = self.lv_luaviewCore.l; + if ( l ){ + lua_checkstack32(l); + lv_pushUserdata(l, self.lv_userData); + [LVUtil call:l lightUserData:self key1:"callback" key2:NULL nargs:1]; + } +} + +static int lvNewTapGestureRecognizer (lua_State *L) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVTapGesture class]]; + { + LVTapGesture* gesture = [[c alloc] init:L]; + + if( lua_type(L, 1) == LUA_TFUNCTION ) { + [LVUtil registryValue:L key:gesture stack:1]; + } + + { + NEW_USERDATA(userData, Gesture); + gesture.lv_userData = userData; + userData->object = CFBridgingRetain(gesture); + + luaL_getmetatable(L, META_TABLE_TapGesture ); + lua_setmetatable(L, -2); + } + } + return 1; /* new userdatum is already on the stack */ +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewTapGestureRecognizer globalName:globalName defaultName:@"TapGesture"]; + + const struct luaL_Reg memberFunctions [] = { + {NULL, NULL} + }; + + lv_createClassMetaTable(L ,META_TABLE_TapGesture); + + luaL_openlib(L, NULL, [LVGesture baseMemberFunctions], 0); + luaL_openlib(L, NULL, memberFunctions, 0); + return 1; +} + + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTextField.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTextField.h new file mode 100644 index 00000000..d7621512 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTextField.h @@ -0,0 +1,24 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + + +@interface LVTextField : UITextField + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; +@property(nonatomic,assign) NSUInteger lv_align; +@property(nonatomic,strong) CAShapeLayer* lv_shapeLayer; + +-(id) init:(lua_State*) l; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTextField.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTextField.m new file mode 100644 index 00000000..9ee202b2 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTextField.m @@ -0,0 +1,206 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVTextField.h" +#import "LVBaseView.h" +#import "LView.h" +#import "LVStyledString.h" +#import "LVHeads.h" + +@interface LVTextField () + +@end + +@implementation LVTextField + + +-(id) init:(lua_State*) l{ + self = [super initWithFrame:CGRectMake(0, 0, 100, 40)]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + self.delegate = self; + self.backgroundColor = [UIColor clearColor]; + self.clipsToBounds = YES; + self.font = [UIFont systemFontOfSize:14];// 默认字体大小 + } + return self; +} + +-(void) dealloc{ +} + +- (void)textFieldDidBeginEditing:(UITextField *)textField{ + // became first responder + lua_State* l = self.lv_luaviewCore.l; + if( l ) { + lua_checkstack32(l); + [self lv_callLuaByKey1:@"BeginEditing"]; + } +} + +- (void)textFieldDidEndEditing:(UITextField *)textField{ + lua_State* l = self.lv_luaviewCore.l; + if( l ) { + lua_checkstack32(l); + [self lv_callLuaByKey1:@"EndEditing"]; + } +} + +- (BOOL)textFieldShouldClear:(UITextField *)textField{ +// lua_State* l = self.lv_luaviewCore.l; +// if( l ) { +// lua_checkstack32(l); +// if( [LVUtil call:l lightUserData:self key:"清理"] ){ +// if( lv_isboolean(l, -1) ){ +// return lua_toboolean(l, -1); +// } +// } +// } + return YES; +} + +- (BOOL)textFieldShouldReturn:(UITextField *)textField{ +// lua_State* l = self.lv_luaviewCore.l; +// if( l ) { +// lua_checkstack32(l); +// if( [LVUtil call:l lightUserData:self key:"返回"]==0 ){ +// if( lv_isboolean(l, -1) ){ +// return lua_toboolean(l, -1); +// } +// } +// } + return YES; +} + +- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{ + return YES; +} + +#pragma -mark lvNewTextField +static int lvNewTextField (lua_State *L) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVTextField class]]; + + LVTextField* textFiled = [[c alloc] init:L]; + { + NEW_USERDATA(userData, View); + userData->object = CFBridgingRetain(textFiled); + textFiled.lv_userData = userData; + + luaL_getmetatable(L, META_TABLE_UITextField ); + lua_setmetatable(L, -2); + } + LuaViewCore* lview = LV_LUASTATE_VIEW(L); + if( lview ){ + [lview containerAddSubview:textFiled]; + } + return 1; /* new userdatum is already on the stack */ +} + +static int text (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVTextField* view = (__bridge LVTextField *)(user->object); + if( [view isKindOfClass:[LVTextField class]] ){ + if ( lua_gettop(L)>=2 ) { + if( lua_type(L, 2)==LUA_TUSERDATA ) { + LVUserDataInfo * user2 = lua_touserdata(L, 2);// 2 + if( user2 && LVIsType(user2, StyledString) ) { + LVStyledString* attString = (__bridge LVStyledString *)(user2->object); + view.attributedText = attString.mutableStyledString; + } + } else if( lua_type(L, 2)==LUA_TSTRING ) { + NSString* text = lv_paramString(L, 2);// 2 + view.text = text; + } + return 0; + } else { + NSString* s = view.text; + if( s ) { + lua_pushstring(L, s.UTF8String); + return 1; + } + + NSAttributedString* att = view.attributedText; + if( att ) { + LVStyledString* attString = [[LVStyledString alloc] init:L]; + attString.mutableStyledString = [[NSMutableAttributedString alloc] init]; + [attString.mutableStyledString appendAttributedString:att]; + + NEW_USERDATA(userData, StyledString); + userData->object = CFBridgingRetain(attString); + attString.lv_userData = userData; + + luaL_getmetatable(L, META_TABLE_AttributedString ); + lua_setmetatable(L, -2); + return 1; + } else { + lua_pushnil(L); + } + return 1; + } + } + } + return 0; +} + +static int placeholder (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVTextField* view = (__bridge LVTextField *)(user->object); + if( [view isKindOfClass:[LVTextField class]] ){ + if ( lua_gettop(L)>=2 ) { + if( lua_type(L, 2)==LUA_TSTRING ) { + NSString* text = lv_paramString(L, 2);// 2 + view.placeholder = text; + } else if( lua_type(L, 2)==LUA_TUSERDATA ) { + LVUserDataInfo * user2 = lua_touserdata(L, 2);// 2 + if( user2 && LVIsType(user2, StyledString) ) { + LVStyledString* attString = (__bridge LVStyledString *)(user2->object); + view.attributedPlaceholder = attString.mutableStyledString; + } + } + return 0; + } else { + NSString* s = view.placeholder; + if( s ) { + lua_pushstring(L, s.UTF8String); + } else { + lua_pushnil(L); + } + } + return 1; + } + } + return 0; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewTextField globalName:globalName defaultName:@"TextField"]; + + const struct luaL_Reg memberFunctions [] = { + {"text", text}, + {"hint", placeholder}, + {"placeholder", placeholder}, //__deprecated_msg("Use hint") + {NULL, NULL} + }; + + lv_createClassMetaTable(L ,META_TABLE_UITextField); + + luaL_openlib(L, NULL, [LVBaseView baseMemberFunctions], 0); + luaL_openlib(L, NULL, memberFunctions, 0); + + const char* keys[] = { "addView", NULL};// 移除多余API + lv_luaTableRemoveKeys(L, keys ); + return 1; +} + +-(NSString*) description{ + return [NSString stringWithFormat:@"", (int)[self hash], NSStringFromCGRect(self.frame) ]; +} + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTimer.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTimer.h new file mode 100644 index 00000000..1d12e3de --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTimer.h @@ -0,0 +1,27 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + + +@interface LVTimer : NSObject + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; + +-(id) init:(lua_State*) l; + +-(void) startTimer; +-(void) cancel; + + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTimer.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTimer.m new file mode 100644 index 00000000..0615dbb0 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTimer.m @@ -0,0 +1,232 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVTimer.h" +#import "LView.h" +#import "LVHeads.h" +#import "LVHeads.h" + +@interface LVTimer () +@property(nonatomic,assign) BOOL repeat; +@property(nonatomic,assign) NSTimeInterval delay; +@property(nonatomic,assign) NSTimeInterval interval; +@end + +@implementation LVTimer{ + NSTimer* timer; +} + +static void releaseUserDataTimer(LVUserDataInfo* user){ + if( user && user->object ){ + LVTimer* timer = CFBridgingRelease(user->object); + user->object = NULL; + if( timer ){ + [timer cancel]; + timer.lv_userData = nil; + timer.lv_luaviewCore = nil; + } + } +} + +-(void) dealloc{ + releaseUserDataTimer(_lv_userData); +} + +-(id) init:(lua_State*) l{ + self = [super init]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + self.delay = 0; // 默认延时 + self.repeat = NO; // 默认重复次数 + self.interval = 1; // 默认间隔1秒 + } + return self; +} + +-(void) timerCallBack{ + lua_State* l = self.lv_luaviewCore.l; + if( l && self.lv_userData ){ + lv_pushUserdata(l, self.lv_userData); + lv_pushUDataRef(l, USERDATA_KEY_DELEGATE ); + lv_runFunction(l); + } +} + + +-(void) startTimer{ + [self cancel]; + if( self.delay>0 ) { + NSDate* date = [[NSDate alloc] initWithTimeIntervalSinceNow:self.delay]; + timer = [[NSTimer alloc] initWithFireDate:date interval:self.interval target:self selector:@selector(timerCallBack) userInfo:nil repeats:self.repeat]; + [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes]; + } else { + timer = [NSTimer scheduledTimerWithTimeInterval:self.interval target:self selector:@selector(timerCallBack) userInfo:nil repeats:self.repeat]; + [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes]; + } +} + +-(void) cancel { + [timer invalidate]; + timer = nil; +} + +-(id) lv_nativeObject{ + return timer; +} + + +#pragma -mark Timer + +static int lvNewTimer (lua_State *L) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVTimer class]]; + + LVTimer* timer = [[c alloc] init:L]; + { + NEW_USERDATA(userData, Timer); + userData->object = CFBridgingRetain(timer); + timer.lv_userData = userData; + + luaL_getmetatable(L, META_TABLE_Timer ); + lua_setmetatable(L, -2); + } + if( lua_type(L, 1) == LUA_TFUNCTION ) { + lua_pushvalue(L, 1); + lv_udataRef(L, USERDATA_KEY_DELEGATE); + } + return 1; +} + +static int setCallback (lua_State *L) { + if( lua_type(L, 2) == LUA_TFUNCTION ) { + lua_pushvalue(L, 1); + lua_pushvalue(L, 2); + lv_udataRef(L, USERDATA_KEY_DELEGATE); + } + lua_settop(L, 1); + return 1; +} + +static int start (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + LVTimer* timer = (__bridge LVTimer *)(user->object); + if( lua_gettop(L)>=2 ) { + timer.interval = lua_tonumber(L, 2); + } + if( lua_gettop(L)>=3 ) { + timer.repeat = lua_toboolean(L, 3); + } + if( user ){ + if( timer ){ + [timer startTimer]; + lua_pushvalue(L,1); + return 1; + } + } + return 0; +} + +static int cancel (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVTimer* timer = (__bridge LVTimer *)(user->object); + if( timer ){ + [timer cancel]; + } + } + return 0; +} + +static int delay (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + double delay = lua_tonumber(L, 2); + if( user ){ + LVTimer* timer = (__bridge LVTimer *)(user->object); + if( timer ){ + timer.delay = delay; + lua_pushvalue(L,1); + return 1; + } + } + return 0; +} + +static int repeat (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + BOOL repeat = lua_toboolean(L, 2); + if( user ){ + LVTimer* timer = (__bridge LVTimer *)(user->object); + if( timer ){ + timer.repeat = repeat; + lua_pushvalue(L,1); + return 1; + } + } + return 0; +} + +static int interval (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + double interval = lua_tonumber(L, 2); + if( user ){ + LVTimer* timer = (__bridge LVTimer *)(user->object); + if( timer ){ + timer.interval = interval; + lua_pushvalue(L,1); + return 1; + } + } + return 0; +} + +static int __gc (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + releaseUserDataTimer(user); + return 0; +} + +static int __tostring (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVTimer* timer = (__bridge LVTimer *)(user->object); + NSString* s = [NSString stringWithFormat:@"LVUserDataTimer: %@", timer ]; + lua_pushstring(L, s.UTF8String); + return 1; + } + return 0; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewTimer globalName:globalName defaultName:@"Timer"]; + + const struct luaL_Reg memberFunctions [] = { + {"callback",setCallback}, + + {"start", start }, + {"cancel", cancel }, + {"stop", cancel }, //__deprecated_msg("Use hidden") + + + {"delay", delay }, + {"repeat", repeat }, + {"repeatCount", repeat }, //__deprecated_msg("Use hidden") + {"interval", interval }, + + {"__gc", __gc }, + + {"__tostring", __tostring }, + {NULL, NULL} + }; + + lv_createClassMetaTable(L ,META_TABLE_Timer); + + luaL_openlib(L, NULL, memberFunctions, 0); + return 1; +} + + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVToast.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVToast.h new file mode 100644 index 00000000..6434ea06 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVToast.h @@ -0,0 +1,25 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import + +#define DEFAULT_DISPLAY_DURATION 2.0f + +@interface LVToast : NSObject + ++ (void)showWithText:(NSString *) text; ++ (void)showWithText:(NSString *) text duration:(CGFloat)duration; + ++ (void)showWithText:(NSString *) text topOffset:(CGFloat) topOffset; ++ (void)showWithText:(NSString *) text topOffset:(CGFloat) topOffset duration:(CGFloat) duration; + ++ (void)showWithText:(NSString *) text bottomOffset:(CGFloat) bottomOffset; ++ (void)showWithText:(NSString *) text bottomOffset:(CGFloat) bottomOffset duration:(CGFloat) duration; + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVToast.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVToast.m new file mode 100644 index 00000000..34c1b2df --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVToast.m @@ -0,0 +1,185 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVToast.h" + +#import + + +@interface LVToast () + +- (id)initWithText:(NSString *)text_; +- (void)setDuration:(CGFloat) duration_; + +- (void)toastTaped:(UIButton *)sender_; + +- (void)showAnimation; +- (void)hideAnimation; + +- (void)show; +- (void)showFromTopOffset:(CGFloat) topOffset_; +- (void)showFromBottomOffset:(CGFloat) bottomOffset_; + +@end + + +@implementation LVToast{ + NSString *text; + UIButton *contentView; + CGFloat duration; +} + +- (void)dealloc{ + [[NSNotificationCenter defaultCenter] removeObserver:self + name:UIDeviceOrientationDidChangeNotification + object:[UIDevice currentDevice]]; +} + + +- (id)initWithText:(NSString *)text_{ + if (self = [super init]) { + + text = [text_ copy]; + + UIFont *font = [UIFont boldSystemFontOfSize:14]; + + CGSize textSize = [text boundingRectWithSize:CGSizeMake(280, MAXFLOAT) + options:(NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading) + attributes:@{NSFontAttributeName: font } + context:nil].size; + UILabel *textLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, textSize.width + 12, textSize.height + 12)]; + textLabel.backgroundColor = [UIColor clearColor]; + textLabel.textColor = [UIColor whiteColor]; + textLabel.textAlignment = NSTextAlignmentCenter; + textLabel.font = font; + textLabel.text = text; + textLabel.numberOfLines = 0; + + contentView = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, textLabel.frame.size.width, textLabel.frame.size.height)]; + contentView.layer.cornerRadius = 5.0f; + contentView.layer.borderWidth = 1.0f; + contentView.layer.borderColor = [[UIColor grayColor] colorWithAlphaComponent:0.5].CGColor; + contentView.backgroundColor = [UIColor colorWithRed:0.2f + green:0.2f + blue:0.2f + alpha:0.75f]; + [contentView addSubview:textLabel]; + contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth; + [contentView addTarget:self + action:@selector(toastTaped:) + forControlEvents:UIControlEventTouchDown]; + contentView.alpha = 0.0f; + + + duration = DEFAULT_DISPLAY_DURATION; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(deviceOrientationDidChanged:) + name:UIDeviceOrientationDidChangeNotification + object:[UIDevice currentDevice]]; + } + return self; +} + +- (void)deviceOrientationDidChanged:(NSNotification *)notify_{ + [self hideAnimation]; +} + +-(void)dismissToast{ + [contentView removeFromSuperview]; +} + +-(void)toastTaped:(UIButton *)sender_{ + [self hideAnimation]; +} + +- (void)setDuration:(CGFloat) duration_{ + duration = duration_; +} + +-(void)showAnimation{ + [UIView beginAnimations:@"show" context:NULL]; + [UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; + [UIView setAnimationDuration:0.3]; + contentView.alpha = 1.0f; + [UIView commitAnimations]; +} + +-(void)hideAnimation{ + [UIView beginAnimations:@"hide" context:NULL]; + [UIView setAnimationCurve:UIViewAnimationCurveEaseOut]; + [UIView setAnimationDelegate:self]; + [UIView setAnimationDidStopSelector:@selector(dismissToast)]; + [UIView setAnimationDuration:0.3]; + contentView.alpha = 0.0f; + [UIView commitAnimations]; +} + +- (void)show{ + UIWindow *window = [UIApplication sharedApplication].keyWindow; + contentView.center = window.center; + [window addSubview:contentView]; + [self showAnimation]; + [self performSelector:@selector(hideAnimation) withObject:nil afterDelay:duration]; +} + +- (void)showFromTopOffset:(CGFloat) top_{ + UIWindow *window = [UIApplication sharedApplication].keyWindow; + contentView.center = CGPointMake(window.center.x, top_ + contentView.frame.size.height/2); + [window addSubview:contentView]; + [self showAnimation]; + [self performSelector:@selector(hideAnimation) withObject:nil afterDelay:duration]; +} + +- (void)showFromBottomOffset:(CGFloat) bottom_{ + UIWindow *window = [UIApplication sharedApplication].keyWindow; + contentView.center = CGPointMake(window.center.x, window.frame.size.height-(bottom_ + contentView.frame.size.height/2)); + [window addSubview:contentView]; + [self showAnimation]; + [self performSelector:@selector(hideAnimation) withObject:nil afterDelay:duration]; +} + + ++ (void)showWithText:(NSString *)text_{ + [LVToast showWithText:text_ duration:DEFAULT_DISPLAY_DURATION]; +} + ++ (void)showWithText:(NSString *)text_ + duration:(CGFloat)duration_{ + LVToast *toast = [[LVToast alloc] initWithText:text_]; + [toast setDuration:duration_]; + [toast show]; +} + ++ (void)showWithText:(NSString *)text_ + topOffset:(CGFloat)topOffset_{ + [LVToast showWithText:text_ topOffset:topOffset_ duration:DEFAULT_DISPLAY_DURATION]; +} + ++ (void)showWithText:(NSString *)text_ + topOffset:(CGFloat)topOffset_ + duration:(CGFloat)duration_{ + LVToast *toast = [[LVToast alloc] initWithText:text_]; + [toast setDuration:duration_]; + [toast showFromTopOffset:topOffset_]; +} + ++ (void)showWithText:(NSString *)text_ + bottomOffset:(CGFloat)bottomOffset_{ + [LVToast showWithText:text_ bottomOffset:bottomOffset_ duration:DEFAULT_DISPLAY_DURATION]; +} + ++ (void)showWithText:(NSString *)text_ + bottomOffset:(CGFloat)bottomOffset_ + duration:(CGFloat)duration_{ + LVToast *toast = [[LVToast alloc] initWithText:text_]; + [toast setDuration:duration_]; + [toast showFromBottomOffset:bottomOffset_]; +} + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTransform3D.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTransform3D.h new file mode 100644 index 00000000..42ba1a9e --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTransform3D.h @@ -0,0 +1,46 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + +@interface LVTransform3D : NSObject + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; +- (id) lv_nativeObject; // 返回native对象 + +@property(nonatomic,assign) CATransform3D transform; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + ++(int) pushTransform3D:(lua_State *)L transform3d:(CATransform3D) t; + +@end + +/* rotation和scale函数只适用于没有x、y轴rotation的矩阵 */ + +extern void CATransform3DSetRotation(CATransform3D *t, CGFloat v); /* z-axis */ + +extern double CATransform3DGetRotation(CATransform3D *t); /* returns [-M_PI, M_PI] */ + +extern void CATransform3DSetScaleX(CATransform3D *t, CGFloat v); +extern void CATransform3DSetScaleY(CATransform3D *t, CGFloat v); +extern void CATransform3DSetScaleZ(CATransform3D *t, CGFloat v); + +extern double CATransform3DGetScaleX(CATransform3D *t); +extern double CATransform3DGetScaleY(CATransform3D *t); +extern double CATransform3DGetScaleZ(CATransform3D *t); + +extern void CATransform3DSetTranslationX(CATransform3D *t, CGFloat v); +extern void CATransform3DSetTranslationY(CATransform3D *t, CGFloat v); +extern void CATransform3DSetTranslationZ(CATransform3D *t, CGFloat v); + +extern double CATransform3DGetTranslationX(CATransform3D *t); +extern double CATransform3DGetTranslationY(CATransform3D *t); +extern double CATransform3DGetTranslationZ(CATransform3D *t); diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTransform3D.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTransform3D.m new file mode 100644 index 00000000..78699e4b --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTransform3D.m @@ -0,0 +1,308 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVTransform3D.h" +#import "LVHeads.h" +#import "LVHeads.h" + +@implementation LVTransform3D + +-(id) lv_nativeObject{ + return nil; +} + +static int lvNewTransform3D (lua_State *L) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVTransform3D class]]; + + { + NEW_USERDATA(userData, Transform3D); + LVTransform3D* trans = [[c alloc] init]; + userData->object = CFBridgingRetain(trans); + trans.transform = CATransform3DIdentity; + luaL_getmetatable(L, META_TABLE_Transform3D ); + lua_setmetatable(L, -2); + } + return 1; /* new userdatum is already on the stack */ +} + ++(int) pushTransform3D:(lua_State *)L transform3d:(CATransform3D) t{ + { + NEW_USERDATA(userData, Transform3D); + LVTransform3D* trans = [[LVTransform3D alloc] init]; + userData->object = CFBridgingRetain(trans); + trans.transform = t; + luaL_getmetatable(L, META_TABLE_Transform3D ); + lua_setmetatable(L, -2); + } + return 1; +} + + +static int translation (lua_State *L) { + if( lua_gettop(L)==4 ) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + double x = lua_tonumber(L, 2);// 2 + double y = lua_tonumber(L, 3);// 3 + double z = lua_tonumber(L, 4);// 4 + if( LVIsType(user, Transform3D) ){ + LVTransform3D* tran = (__bridge LVTransform3D *)(user->object); + tran.transform = CATransform3DTranslate(tran.transform, x, y, z); + lua_pushvalue(L,1); + return 1; + } + } + return 0; +} + +static int scale (lua_State *L) { + if( lua_gettop(L)==4 ) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + double x = lua_tonumber(L, 2);// 2 + double y = lua_tonumber(L, 3);// 3 + double z = lua_tonumber(L, 4);// 4 + if( LVIsType(user, Transform3D) ){ + LVTransform3D* tran = (__bridge LVTransform3D *)(user->object); + tran.transform = CATransform3DScale(tran.transform, x, y, z); + lua_pushvalue(L,1); + return 1; + } + } + return 0; +} + +static int rotate (lua_State *L) { + if( lua_gettop(L)==5 ) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + double angle = lua_tonumber(L, 2); + double x = lua_tonumber(L, 3); + double y = lua_tonumber(L, 4); + double z = lua_tonumber(L, 5); + if( LVIsType(user, Transform3D) ){ + LVTransform3D* tran = (__bridge LVTransform3D *)(user->object); + tran.transform = CATransform3DRotate(tran.transform, angle, x, y, z); + lua_pushvalue(L,1); + return 1; + } + } + return 0; +} + +static int isIdentity (lua_State *L) { + if( lua_gettop(L)==1 ) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( LVIsType(user, Transform3D) ){ + LVTransform3D* tran = (__bridge LVTransform3D *)(user->object); + BOOL yes = CATransform3DIsIdentity(tran.transform ); + int ret = (yes ? 1 : 0); + lua_pushboolean(L, ret); + return 1; + } + } + return 0; +} + +static int reset (lua_State *L) { + if( lua_gettop(L)==1 ) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( LVIsType(user, Transform3D) ){ + LVTransform3D* tran = (__bridge LVTransform3D *)(user->object); + tran.transform = CATransform3DIdentity; + lua_pushvalue(L,1); + return 1; + } + } + return 0; +} + +static int transform_set (lua_State *L) { + if( lua_gettop(L)==2 ) { + LVUserDataInfo * user1 = (LVUserDataInfo *)lua_touserdata(L, 1); + LVUserDataInfo * user2 = (LVUserDataInfo *)lua_touserdata(L, 2); + if( LVIsType(user1, Transform3D) && LVIsType(user2, Transform3D) ){ + LVTransform3D* tran1 = (__bridge LVTransform3D *)(user1->object); + LVTransform3D* tran2 = (__bridge LVTransform3D *)(user2->object); + tran1.transform = tran2.transform; + lua_pushvalue(L,1); + return 1; + } + } + return 0; +} + +static int concat (lua_State *L) { + if( lua_gettop(L)==2 ) { + LVUserDataInfo * user1 = (LVUserDataInfo *)lua_touserdata(L, 1); + LVUserDataInfo * user2 = (LVUserDataInfo *)lua_touserdata(L, 2); + if( LVIsType(user1, Transform3D) && LVIsType(user2, Transform3D) ){ + LVTransform3D* tran1 = (__bridge LVTransform3D *)(user1->object); + LVTransform3D* tran2 = (__bridge LVTransform3D *)(user2->object); + tran1.transform = CATransform3DConcat(tran1.transform, tran2.transform); + + lua_pushvalue(L,1); + return 1; + } + } + return 0; +} + +static int __mul (lua_State *L) { + if( lua_gettop(L)==2 ) { + LVUserDataInfo * user1 = (LVUserDataInfo *)lua_touserdata(L, 1); + LVUserDataInfo * user2 = (LVUserDataInfo *)lua_touserdata(L, 2); + if( LVIsType(user1, Transform3D) && LVIsType(user2, Transform3D) ){ + LVTransform3D* tran1 = (__bridge LVTransform3D *)(user1->object); + LVTransform3D* tran2 = (__bridge LVTransform3D *)(user2->object); + NEW_USERDATA(user, Transform3D); + + LVTransform3D* trans = [[LVTransform3D alloc] init]; + user->object = CFBridgingRetain(trans); + + trans.transform = CATransform3DIdentity; + luaL_getmetatable(L, META_TABLE_Transform3D ); + lua_setmetatable(L, -2); + + trans.transform = CATransform3DConcat(tran1.transform, tran2.transform); + return 1; + } + } + return 0; +} + +static int __eq (lua_State *L) { + if( lua_gettop(L)==2 ) { + LVUserDataInfo * user1 = (LVUserDataInfo *)lua_touserdata(L, 1); + LVUserDataInfo * user2 = (LVUserDataInfo *)lua_touserdata(L, 2); + if( LVIsType(user1, Transform3D) && LVIsType(user2, Transform3D) ){ + LVTransform3D* tran1 = (__bridge LVTransform3D *)(user1->object); + LVTransform3D* tran2 = (__bridge LVTransform3D *)(user2->object); + BOOL yes = CATransform3DEqualToTransform( tran1.transform, tran2.transform); + lua_pushboolean(L, (yes?1:0) ); + return 1; + } + } + return 0; +} + +static int __tostring (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( LVIsType(user, Transform3D) ){ + NSString* s = [NSString stringWithFormat:@"LVUserDataTransform3D: %d", (int)user ]; + lua_pushstring(L, s.UTF8String); + return 1; + } + return 0; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewTransform3D globalName:globalName defaultName:@"Transform3D"]; + + const struct luaL_Reg memberFunctions [] = { + {"__eq", __eq}, + {"__mul", __mul}, + {"rotate", rotate}, + {"scale", scale}, + {"translation", translation}, + + {"isIdentity", isIdentity}, + {"reset", reset}, + + {"set", transform_set}, + {"concat", concat}, + + {"__tostring", __tostring}, + + {NULL, NULL} + }; + + lv_createClassMetaTable(L ,META_TABLE_Transform3D); + + luaL_openlib(L, NULL, memberFunctions, 0); + return 1; +} + +@end + +void CATransform3DSetRotation(CATransform3D *t, CGFloat v) { + double scaleX = CATransform3DGetScaleX(t), scaleY = CATransform3DGetScaleY(t); + t->m11 = scaleX * cos(v); + t->m12 = scaleX * sin(v); + t->m21 = -(scaleY * sin(v)); + t->m22 = scaleY * cos(v); +} + +double CATransform3DGetRotation(CATransform3D *t) { + return atan2(t->m12, t->m11); +} + +void CATransform3DSetScaleX(CATransform3D *t, CGFloat v) { + double r = CATransform3DGetRotation(t); + t->m11 = v * cos(r); + t->m12 = v * sin(r); +} + +double CATransform3DGetScaleX(CATransform3D *t) { + double r = CATransform3DGetRotation(t); + + if (t->m11 != 0) { + return t->m11 / cos(r); + } else if (t->m12 != 0) { + return t->m12 / sin(r); + } else { + return 0; + } +} + +void CATransform3DSetScaleY(CATransform3D *t, CGFloat v) { + double r = CATransform3DGetRotation(t); + t->m21 = -(v * sin(r)); + t->m22 = v * cos(r); +} + +double CATransform3DGetScaleY(CATransform3D *t) { + double r = CATransform3DGetRotation(t); + + if (t->m21 != 0) { + return -(t->m21 / sin(r)); + } else if (t->m22 != 0) { + return t->m22 / cos(r); + } else { + return 0; + } +} + +void CATransform3DSetScaleZ(CATransform3D *t, CGFloat v) { + t->m33 = v; +} + +double CATransform3DGetScaleZ(CATransform3D *t) { + return t->m33; +} + +void CATransform3DSetTranslationX(CATransform3D *t, CGFloat v) { + t->m41 = v; +} + +double CATransform3DGetTranslationX(CATransform3D *t) { + return t->m41; +} + +void CATransform3DSetTranslationY(CATransform3D *t, CGFloat v) { + t->m42 = v; +} + +double CATransform3DGetTranslationY(CATransform3D *t) { + return t->m42; +} + +void CATransform3DSetTranslationZ(CATransform3D *t, CGFloat v) { + t->m43 = v; +} + +double CATransform3DGetTranslationZ(CATransform3D *t) { + return t->m43; +} diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTypeConvert.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTypeConvert.h new file mode 100644 index 00000000..0ea3f45a --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTypeConvert.h @@ -0,0 +1,24 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" +#import "LVUtil.h" + +@interface LVTypeConvert : NSObject + +int lv_pushInvocationReturnValueToLuaStack(NSInvocation* invocation, lua_State* L); +id lv_setInvocationReturnValueByLuaStack(NSInvocation* invocation, lua_State* L, int stackID); + +int lv_pushInvocationArgToLuaStack(NSInvocation* invocation, int index, lua_State* L); +int lv_setInvocationArgByLuaStack(NSInvocation* invocation, int index, lua_State* L, int stackID); + +int lv_setValueWithType(void* p, int index, double value, int type ); +double lv_getValueWithType(void* p, int index, int type ); + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTypeConvert.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTypeConvert.m new file mode 100644 index 00000000..c670d378 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTypeConvert.m @@ -0,0 +1,696 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVTypeConvert.h" +#import "LVHeads.h" +#import "LVStruct.h" +#import "LVHeads.h" +#import + +@implementation LVTypeConvert + +static int typeIdx(const char* type){ + if( type ) { + unsigned char c0 = type[0]; + unsigned char c1 = type[1]; + if ( c1==0 ){ + return 256*0 + c0; + } else if ( c0=='r' ) { // const + return 256*1 + c1; + } else if ( c0=='^' ) { // 指针 + return 256*2 + c1; + } else if ( c0=='{' ) { // 结构体 + return 256*3 + 0; + } else { + LVError(@"LVUtil.typeIdx: %s", type); + return 0; + } + } + return 0; +} + +LVTypeIDEnum lua_typeID(const char* type){ + static LVTypeIDEnum typesDic[256*4] = {0}; + static BOOL inited = NO; + if( !inited ) { + inited = YES; + + typesDic[typeIdx(@encode(void))] = LVTypeID_void; + typesDic[typeIdx(@encode(bool))] = LVTypeID_bool; + typesDic[typeIdx(@encode(BOOL))] = LVTypeID_BOOL; + typesDic[typeIdx(@encode(char))] = LVTypeID_char; + typesDic[typeIdx(@encode(unsigned char))] = LVTypeID_unsignedchar; + typesDic[typeIdx(@encode(short))] = LVTypeID_short; + typesDic[typeIdx(@encode(unsigned short))] = LVTypeID_unsignedshort; + typesDic[typeIdx(@encode(int))] = LVTypeID_int; + typesDic[typeIdx(@encode(unsigned int))] = LVTypeID_unsignedint; + typesDic[typeIdx(@encode(NSInteger))] = LVTypeID_NSInteger; + typesDic[typeIdx(@encode(NSUInteger))] = LVTypeID_NSUInteger; + typesDic[typeIdx(@encode(long long))] = LVTypeID_longlong; + typesDic[typeIdx(@encode(unsigned long long))] = LVTypeID_unsigedlonglong; + typesDic[typeIdx(@encode(float))] = LVTypeID_float; + typesDic[typeIdx(@encode(CGFloat))] = LVTypeID_CGFloat; + typesDic[typeIdx(@encode(double))] = LVTypeID_double; + + typesDic[typeIdx(@encode(BOOL*))] = LVTypeID_charP; + typesDic[typeIdx(@encode(char*))] = LVTypeID_charP; + typesDic[typeIdx(@encode(short*))] = LVTypeID_charP; + typesDic[typeIdx(@encode(int*))] = LVTypeID_charP; + typesDic[typeIdx(@encode(NSInteger*))] = LVTypeID_charP; + typesDic[typeIdx(@encode(long*))] = LVTypeID_charP; + typesDic[typeIdx(@encode(float*))] = LVTypeID_charP; + typesDic[typeIdx(@encode(CGFloat*))] = LVTypeID_charP; + typesDic[typeIdx(@encode(double*))] = LVTypeID_charP; + typesDic[typeIdx(@encode(unsigned char*))] = LVTypeID_charP; + typesDic[typeIdx(@encode(unsigned short*))] = LVTypeID_charP; + typesDic[typeIdx(@encode(unsigned int*))] = LVTypeID_charP; + typesDic[typeIdx(@encode(NSUInteger*))] = LVTypeID_charP; + typesDic[typeIdx(@encode(unsigned long*))] = LVTypeID_charP; + typesDic[typeIdx(@encode(void*))] = LVTypeID_voidP; + typesDic[typeIdx(@encode(void**))] = LVTypeID_voidP; + + typesDic[typeIdx(@encode(const BOOL*))] = LVTypeID_charP; + typesDic[typeIdx(@encode(const char*))] = LVTypeID_charP; + typesDic[typeIdx(@encode(const short*))] = LVTypeID_charP; + typesDic[typeIdx(@encode(const int*))] = LVTypeID_charP; + typesDic[typeIdx(@encode(const long*))] = LVTypeID_charP; + typesDic[typeIdx(@encode(const float*))] = LVTypeID_charP; + typesDic[typeIdx(@encode(const double*))] = LVTypeID_charP; + + typesDic[typeIdx(@encode(const void*))] = LVTypeID_voidP; + typesDic[typeIdx("^{")] = LVTypeID_voidP; + typesDic[typeIdx(@encode(id))] = LVTypeID_id; + typesDic[typeIdx(@encode(Class))] = LVTypeID_Class; + + typesDic[typeIdx(@encode(CGRect))] = LVTypeID_struct; + } + return typesDic[ typeIdx(type) ]; +} + +int lv_setValueWithType(void* p, int index, double value, int type ){ + if ( p ) { + switch (type) { + case 'b': + case 'B': { + BOOL* cp = p; + cp[index] = (BOOL)value; + return 1; + } + case 'c': + case 'C': { + char* cp = p; + cp[index] = (char)value; + return 1; + } + case 's': + case 'S': { + short* cp = p; + cp[index] = (short)value; + return 1; + } + case 'i': + case 'I': { + int* cp = p; + cp[index] = (int)value; + return 1; + } + case 'l': + case 'L': { + long* cp = p; + cp[index] = (long)value; + return 1; + } + case 'q': + case 'Q': { + long long* cp = p; + cp[index] = (long long)value; + return 1; + } + case 'f': { + float* cp = p; + cp[index] = (float)value; + return 1; + } + case 'd': { + double* cp = p; + cp[index] = (double)value; + return 1; + } + default: { + LVError(@"lv_setValueWithType: %c", type); + return 0; + } + } + } + return 0; +} + +double lv_getValueWithType(void* p, int index, int type ){ + if ( p ) { + switch (type) { + case 'b': + case 'B': { + BOOL* cp = p; + return cp[index]; + } + case 'c': + case 'C': { + char* cp = p; + return cp[index]; + } + case 's': + case 'S': { + short* cp = p; + return cp[index]; + } + case 'i': + case 'I': { + int* cp = p; + return cp[index]; + } + case 'l': + case 'L': { + long* cp = p; + return cp[index]; + } + case 'q': + case 'Q': { + long long* cp = p; + return cp[index]; + } + case 'f': { + float* cp = p; + return cp[index]; + } + case 'd': { + double* cp = p; + return cp[index]; + } + default: { + LVError(@"lv_getValueWithType: %c", type); + return 0; + } + } + } + return 0; +} + +int lv_pushInvocationReturnValueToLuaStack(NSInvocation* invocation, lua_State* L){ + const char* type = [invocation.methodSignature methodReturnType]; + if ( type ){ + switch ( lua_typeID(type) ) { + case LVTypeID_void: + return 0; + case LVTypeID_BOOL: { + BOOL result = 0; + [invocation getReturnValue: &result]; + lua_pushboolean(L, result); + return 1; + } + case LVTypeID_bool: { + bool result = 0; + [invocation getReturnValue: &result]; + lua_pushboolean(L, result); + return 1; + } + case LVTypeID_Class: + case LVTypeID_id: { + void* result = nil; + [invocation getReturnValue: &result]; + lv_pushNativeObject(L,(__bridge id)result); + return 1; + } + case LVTypeID_char: { + char result = 0; + [invocation getReturnValue: &result]; + lua_pushnumber(L, result); + return 1; + } + case LVTypeID_unsignedchar: { + unsigned char result = 0; + [invocation getReturnValue: &result]; + lua_pushnumber(L, result); + return 1; + } + case LVTypeID_short: { + short result = 0; + [invocation getReturnValue: &result]; + lua_pushnumber(L, result); + return 1; + } + case LVTypeID_unsignedshort: { + unsigned short result = 0; + [invocation getReturnValue: &result]; + lua_pushnumber(L, result); + return 1; + } + case LVTypeID_int: { + int result = 0; + [invocation getReturnValue: &result]; + lua_pushnumber(L, result); + return 1; + } + case LVTypeID_unsignedint: { + unsigned int result = 0; + [invocation getReturnValue: &result]; + lua_pushnumber(L, result); + return 1; + } + case LVTypeID_NSInteger: { + NSInteger result = 0; + [invocation getReturnValue: &result]; + lua_pushnumber(L, result); + return 1; + } + case LVTypeID_NSUInteger: { + NSUInteger result = 0; + [invocation getReturnValue: &result]; + lua_pushnumber(L, result); + return 1; + } + case LVTypeID_longlong: { + long long result = 0; + [invocation getReturnValue: &result]; + lua_pushnumber(L, result); + return 1; + } + case LVTypeID_unsigedlonglong: { + unsigned long long result = 0; + [invocation getReturnValue: &result]; + lua_pushnumber(L, result); + return 1; + } + case LVTypeID_float: { + float result = 0; + [invocation getReturnValue: &result]; + lua_pushnumber(L, result); + return 1; + } + case LVTypeID_CGFloat: { + CGFloat result = 0; + [invocation getReturnValue: &result]; + lua_pushnumber(L, result); + return 1; + } + case LVTypeID_double: { + double result = 0; + [invocation getReturnValue: &result]; + lua_pushnumber(L, result); + return 1; + } + case LVTypeID_charP: { + char* result = 0; + [invocation getReturnValue: &result]; + lua_pushlightuserdata(L, result); + return 1; + } + case LVTypeID_voidP: { + void* result = 0; + [invocation getReturnValue: &result]; + lua_pushlightuserdata(L, result); + return 1; + } + case LVTypeID_struct:{ + CGFloat result[LV_STRUCT_MAX_LEN] = {0}; + [invocation getReturnValue: result]; + [LVStruct pushStructToLua:L data:result]; + return 1; + } + default: + LVError(@"LVMethod.pushReturnToLuaStack"); + break; + } + } + return 0; +} + +int lv_setInvocationArgByLuaStack(NSInvocation* invocation, int index, lua_State* L, int stackID){ + const char* type = [invocation.methodSignature getArgumentTypeAtIndex:index]; + if ( type ){ + switch ( lua_typeID(type) ) { + case LVTypeID_BOOL: { + BOOL value = lua_toboolean(L, stackID); + [invocation setArgument: &value atIndex:index]; + return 1; + } + case LVTypeID_bool: { + bool value = lua_toboolean(L, stackID); + [invocation setArgument: &value atIndex:index]; + return 1; + } + case LVTypeID_Class: + case LVTypeID_id: { + id nativeObject = lv_luaValueToNativeObject(L, stackID); + [invocation setArgument:&nativeObject atIndex:index]; + return 1; + } + case LVTypeID_char: { + char value = lua_tonumber(L, stackID); + [invocation setArgument: &value atIndex:index]; + return 1; + } + case LVTypeID_unsignedchar: { + unsigned char value = lua_tonumber(L, stackID); + [invocation setArgument: &value atIndex:index]; + return 1; + } + case LVTypeID_short: { + short value = lua_tonumber(L, stackID); + [invocation setArgument: &value atIndex:index]; + return 1; + } + case LVTypeID_unsignedshort: { + unsigned short value = lua_tonumber(L, stackID); + [invocation setArgument: &value atIndex:index]; + return 1; + } + case LVTypeID_int: { + int value = lua_tonumber(L, stackID); + [invocation setArgument: &value atIndex:index]; + return 1; + } + case LVTypeID_unsignedint: { + unsigned int value = lua_tonumber(L, stackID); + [invocation setArgument: &value atIndex:index]; + return 1; + } + case LVTypeID_NSInteger: { + NSInteger value = lua_tonumber(L, stackID); + [invocation setArgument: &value atIndex:index]; + return 1; + } + case LVTypeID_NSUInteger: { + NSUInteger value = lua_tonumber(L, stackID); + [invocation setArgument: &value atIndex:index]; + return 1; + } + case LVTypeID_longlong: { + long long value = lua_tonumber(L, stackID); + [invocation setArgument: &value atIndex:index]; + return 1; + } + case LVTypeID_unsigedlonglong: { + unsigned long long value = lua_tonumber(L, stackID); + [invocation setArgument: &value atIndex:index]; + return 1; + } + case LVTypeID_float: { + float value = lua_tonumber(L, stackID); + [invocation setArgument: &value atIndex:index]; + return 1; + } + case LVTypeID_CGFloat: { + CGFloat value = lua_tonumber(L, stackID); + [invocation setArgument: &value atIndex:index]; + return 1; + } + case LVTypeID_double: { + double value = lua_tonumber(L, stackID); + [invocation setArgument: &value atIndex:index]; + return 1; + } + case LVTypeID_charP: { + char* value = lua_touserdata(L, stackID); + [invocation setArgument: &value atIndex:index]; + return 1; + } + case LVTypeID_voidP: { + void* value = lua_touserdata(L, stackID); + [invocation setArgument: &value atIndex:index]; + return 1; + } + case LVTypeID_struct: { + LVUserDataInfo* user = lua_touserdata(L, stackID); + if ( LVIsType(user, Struct) ) { + LVStruct* stru = (__bridge LVStruct *)(user->object); + if( [stru dataPointer] ) { + [invocation setArgument:[stru dataPointer] atIndex:index]; + } + } + return 1; + } + default: { + NSInteger value = 0; + [invocation setArgument: &value atIndex:index]; + LVError(@"setIvocationArgument:index:byLua:"); + break; + } + } + } + //否则将参数设置为空 + NSInteger value = 0; + [invocation setArgument: &value atIndex:index]; + return 0; +} + +id lv_setInvocationReturnValueByLuaStack(NSInvocation* invocation, lua_State* L, int stackID){ + const char* type = [invocation.methodSignature methodReturnType]; + if ( type ) { + switch ( lua_typeID(type) ) { + case LVTypeID_void: + return nil; + case LVTypeID_BOOL: { + BOOL result = lua_toboolean(L, stackID); + [invocation setReturnValue: &result]; + return nil; + } + case LVTypeID_bool: { + bool result = lua_toboolean(L, stackID); + [invocation setReturnValue: &result]; + return nil; + } + case LVTypeID_Class: + case LVTypeID_id: { + id object = lv_luaValueToNativeObject(L, stackID); + [invocation setReturnValue:&object]; + return object; + } + case LVTypeID_char: { + char result = lua_tonumber(L, stackID); + [invocation setReturnValue: &result]; + return nil; + } + case LVTypeID_unsignedchar: { + unsigned char result = lua_tonumber(L, stackID); + [invocation setReturnValue: &result]; + return nil; + } + case LVTypeID_short: { + short result = lua_tonumber(L, stackID); + [invocation setReturnValue: &result]; + return nil; + } + case LVTypeID_unsignedshort: { + unsigned short result = lua_tonumber(L, stackID); + [invocation setReturnValue: &result]; + return nil; + } + case LVTypeID_int: { + int result = lua_tonumber(L, stackID); + [invocation setReturnValue: &result]; + return nil; + } + case LVTypeID_unsignedint: { + unsigned int result = lua_tonumber(L, stackID); + [invocation setReturnValue: &result]; + return nil; + } + case LVTypeID_NSInteger: { + NSInteger result = lua_tonumber(L, stackID); + [invocation setReturnValue: &result]; + return nil; + } + case LVTypeID_NSUInteger: { + NSUInteger result = lua_tonumber(L, stackID); + [invocation setReturnValue: &result]; + return nil; + } + case LVTypeID_longlong: { + long long result = lua_tonumber(L, stackID); + [invocation setReturnValue: &result]; + return nil; + } + case LVTypeID_unsigedlonglong: { + unsigned long long result = lua_tonumber(L, stackID); + [invocation setReturnValue: &result]; + return nil; + } + case LVTypeID_float: { + float result = lua_tonumber(L, stackID); + [invocation setReturnValue: &result]; + return nil; + } + case LVTypeID_CGFloat: { + CGFloat result = lua_tonumber(L, stackID); + [invocation setReturnValue: &result]; + return nil; + } + case LVTypeID_double: { + double result = lua_tonumber(L, stackID); + [invocation setReturnValue: &result]; + return nil; + } + case LVTypeID_charP: { + char* result = lua_touserdata(L,stackID); + [invocation setReturnValue: &result]; + return nil; + } + case LVTypeID_voidP: { + char* result = lua_touserdata(L,stackID); + [invocation setReturnValue: &result]; + return nil; + } + case LVTypeID_struct: { + LVUserDataInfo* user = lua_touserdata(L,stackID); + if ( LVIsType(user, Struct) ) { + LVStruct* stru = (__bridge LVStruct *)(user->object); + if( [stru dataPointer] ) { + [invocation setReturnValue: [stru dataPointer]]; + } + } + return nil; + } + default: + LVError( @"LVLuaObjBox.setInvocationReturnValue:withLuaObject:"); + break; + } + } + return nil ; +} + +int lv_pushInvocationArgToLuaStack(NSInvocation* invocation, int index, lua_State* L ){ + const char* type = [invocation.methodSignature getArgumentTypeAtIndex:index]; + switch ( lua_typeID(type) ) { + case LVTypeID_BOOL: { + BOOL value = 0; + [invocation getArgument: &value atIndex:index]; + lua_pushnumber(L, value); + return 1; + } + case LVTypeID_bool: { + bool value = 0; + [invocation getArgument: &value atIndex:index]; + lua_pushnumber(L, value); + return 1; + } + case LVTypeID_Class: + case LVTypeID_id: { + void* value = nil; + [invocation getArgument:&value atIndex:index]; + lv_pushNativeObject(L, (__bridge id)value); + return 1; + } + case LVTypeID_char: { + char value = 0; + [invocation getArgument: &value atIndex:index]; + lua_pushnumber(L, value); + return 1; + } + case LVTypeID_unsignedchar: { + unsigned char value = 0; + [invocation getArgument: &value atIndex:index]; + lua_pushnumber(L, value); + return 1; + } + case LVTypeID_short: { + short value = 0; + [invocation getArgument: &value atIndex:index]; + lua_pushnumber(L, value); + return 1; + } + case LVTypeID_unsignedshort: { + unsigned short value = 0; + [invocation getArgument: &value atIndex:index]; + lua_pushnumber(L, value); + return 1; + } + case LVTypeID_int: { + int value = 0; + [invocation getArgument: &value atIndex:index]; + lua_pushnumber(L, value); + return 1; + } + case LVTypeID_unsignedint: { + unsigned int value = 0; + [invocation getArgument: &value atIndex:index]; + lua_pushnumber(L, value); + return 1; + } + case LVTypeID_NSInteger: { + NSInteger value = 0; + [invocation getArgument: &value atIndex:index]; + lua_pushnumber(L, value); + return 1; + } + case LVTypeID_NSUInteger: { + NSUInteger value = 0; + [invocation getArgument: &value atIndex:index]; + lua_pushnumber(L, value); + return 1; + } + case LVTypeID_longlong: { + long long value = 0; + [invocation getArgument: &value atIndex:index]; + lua_pushnumber(L, value); + return 1; + } + case LVTypeID_unsigedlonglong: { + unsigned long long value = 0; + [invocation getArgument: &value atIndex:index]; + lua_pushnumber(L, value); + return 1; + } + case LVTypeID_float: { + float value = 0; + [invocation getArgument: &value atIndex:index]; + lua_pushnumber(L, value); + return 1; + } + case LVTypeID_CGFloat: { + CGFloat value = 0; + [invocation getArgument: &value atIndex:index]; + lua_pushnumber(L, value); + return 1; + } + case LVTypeID_double: { + double value = 0; + [invocation getArgument: &value atIndex:index]; + lua_pushnumber(L, value); + return 1; + } + case LVTypeID_charP: { + char* value = 0; + [invocation getArgument: &value atIndex:index]; + lua_pushlightuserdata(L,value); + return 1; + } + case LVTypeID_voidP: { + void* value = 0; + [invocation getArgument: &value atIndex:index]; + lua_pushlightuserdata(L,value); + return 1; + } + case LVTypeID_struct: { + CGFloat result[LV_STRUCT_MAX_LEN] = {0}; + [invocation getArgument:result atIndex:index]; + [LVStruct pushStructToLua:L data:result]; + return 1; + } + default:{ + LVError(@"LVLuaObjBox.pushInvocation:argIndex:toLua:"); + //否则将参数设置为空 + NSInteger value = 0; + [invocation setArgument: &value atIndex:index]; + return 1; + } + } +} + + + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVUtil.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVUtil.h new file mode 100644 index 00000000..23e4b6fd --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVUtil.h @@ -0,0 +1,232 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import +#import "LVHeads.h" + +@class LVBundle; +@class LuaViewCore; + +typedef void(^LVFuncDownloadEndCallback)(NSData* data); + +@interface LVUtil : NSObject + +/** + * 调用lua对应的方法(如果是function直接调用, 如果是table用key去查找后再调用) + * + * @param l luastate + * @param table 用户数据 + * @param key + * + * @return stackNumber + */ ++(NSString*) call:(lua_State*) l lightUserData:(id) lightUserData key1:(const char*)key1 key2:(const char*)key2 nargs:(int)nargs; + ++(NSString*) call:(lua_State*) l key1:(const char*)key1 key2:(const char*)key2 key3:(const char*)key3 + nargs:(int)nargs nrets:(int)nret + retType:(int) retType; + ++(NSString*) call:(lua_State*) l key1:(const char*)key1 key2:(const char*)key2 key3:(const char*)key3 key4:(const char*)key4 + nargs:(int)nargs nrets:(int)nret + retType:(int) retType; + +/* + * download file + */ ++(void) download:(NSString*) url callback:(LVFuncDownloadEndCallback) nextStep; + +/* + * NSData -> 文件 + */ ++(BOOL) saveData:(NSData*) data toFile:(NSString*) fileName; + +/* + * 文件 -> NSData + */ ++(NSData*) dataReadFromFile:(NSString*) fileName; + + +/* + * 删除文件 + */ ++(BOOL) deleteFile:(NSString*)path; + +/* + * NSCachesDirectory: 相对路径 -> 绝对路径 + */ ++ (NSString*) PathForCachesResource:(NSString* )relativePath ; + +/* + * NSDocumentDirectory: 相对路径 -> 绝对路径 + */ ++ (NSString*) PathForDocumentsResource:(NSString*) relativePath; + +/* + * + */ ++ (NSString*) PathForBundle:(NSBundle*) bundle relativePath:(NSString*) relativePath; + +/* + * 创建目录 + */ ++(BOOL) createPath:(NSString*) path; + ++(BOOL) exist:(NSString*) path; + +/* + * json解析 + */ ++(id) stringToObject:(NSString*) s; ++(NSString*) objectToString:(id) obj; + +/* + * MD5 + */ ++ (NSString*) MD5HashFromData:(NSData*) data; ++ (NSData*) MD5HashDataFromData:(NSData*) data; + +NSData *LV_AES256DecryptDataWithKey(NSData *data, NSData* key); + +// 全局注册表添加/删除 ++ (void) registryValue:(lua_State*) L key:(id) key stack:(int) valueIndex; ++ (void) unregistry:(lua_State*) L key:(id) key; ++ (void) pushRegistryValue:(lua_State*) L key:(id) key; + +// UData 关联脚本object +void lv_udataRef(lua_State* L, int key); // -2: userdata -1: value +void lv_udataUnref(lua_State* L, int key); // -1: userdata +void lv_pushUDataRef(lua_State* L, int key); // -1: userdata + +int lv_createUDataLuatable (lua_State *L, int objindex); +//int lv_setUDataLuatable (lua_State *L, int objindex); +int lv_getUDataLuatable (lua_State *L, int objindex); +/* + * Create Class MetaTable + */ +void lv_createClassMetaTable(lua_State* L, const char* name); + +/* + * Push userData to stack + */ +void lv_pushUserdata(lua_State* L, void* p); + +/* + * table -> NSDictionary + */ +id lv_luaTableToDictionary(lua_State* L, int index); + +/* + * table -> NSArray + */ +NSArray* lv_luaTableToArray(lua_State* L, int idx); + +/* + * oc对象(所有类型) 转成 luavalue + */ +void lv_pushNativeObject(lua_State* L , id value ); + +/* + * oc对象(非基本类型) 转成 luavalue + */ +void lv_pushNativeObjectWithBox(lua_State* L,id nativeObject); + +/* + * luavalue 转成 oc对象 + */ +id lv_luaValueToNativeObject(lua_State* L, int idx); + +/* + * 获取LuaTable对象的 keys + */ +NSArray* lv_luaTableKeys(lua_State* L, int index); + +/* + * 移除LuaTable对象的 指定Keys + */ +void lv_luaTableRemoveKeys(lua_State* L, const char** keys); + +/* + * lua table是否包含属性 + */ +BOOL lv_isLuaObjectHaveProperty(lua_State* L, int idx, const char* key); + +/* + * lua table添加window属性 + */ +void lv_luaTableSetWeakWindow(lua_State* L, UIView* cell); + +/** + * 重置lua虚拟机的栈大小位置 + * + * @param l lua state + */ +void lua_checkstack32(lua_State* l); + +/** + * 清理首个无效参数 + * + * @param l lua state + */ +void lv_clearFirstTableValue(lua_State* l); + +/* + * uicolor -> int + */ +BOOL lv_uicolor2int(UIColor* color,NSUInteger* c, CGFloat* alpha); + +UIColor* lv_getColorFromStack(lua_State* L, int stackID); + + +/* + * Is External Url + */ ++(BOOL) isExternalUrl:(NSString*) url; + +UIColor* lv_UIColorFromRGBA(NSInteger aRGB ,float alpha); + ++(BOOL) ios8; + + ++ (int) loadFont:(NSString*) fileName package:(LVBundle*)bundle; ++ (UIFont *)fontWithName:(NSString *)fontName size:(CGFloat)fontSize bundle:(LVBundle*)bundle; + +void LVLog( NSString* format, ... ); +void LVError( NSString* format, ... ); + +//---------------------------------------- +int lv_callbackFunction(lua_State* l, const char* functionName); + +BOOL lv_objcEqual(id obj1, id obj2); + ++(void) reg:(lua_State*)L clas:(id) c cfunc:(lua_CFunction) cfunc globalName:(NSString*)globalName defaultName:(NSString*) defaultName; + ++(Class) upvalueClass:(lua_State*)L defaultClass:(Class) defaultClass; + ++(void) defineGlobal:(NSString*)globalName value:(id) value L:(lua_State*)L; +void lv_defineGlobalFunc(const char* globalName, lua_CFunction func, lua_State* L); + +void lv_addSubview(LuaViewCore* lv, UIView* superview, UIView* subview); + +extern NSString* safe_stringForKey(NSDictionary*dic, id key); +extern NSDictionary * safe_dictionaryForKey(NSDictionary* dic, id key); +NSDate * safe_dateForKey(NSDictionary* dic, id key ); + + + ++ (NSTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval)inTimeInterval + block:(void (^)(NSTimer *timer))block + repeats:(BOOL)inRepeats; +/* + * 显示Lua的调用堆栈 + */ ++ (NSString*) luaTrace:(lua_State*) L; + +@end + + diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVUtil.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVUtil.m new file mode 100644 index 00000000..44c2dd80 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVUtil.m @@ -0,0 +1,969 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVUtil.h" +#import +#import "LVBlock.h" +#import "LVNativeObjBox.h" +#import "LVPkgManager.h" +#import "LVLuaObjBox.h" +#import "LVPointerValueBox.h" +#import "LVDebuger.h" +#import "LVHeads.h" +#import + +@implementation LVUtil + + ++(BOOL) isExternalUrl:(NSString*) url{ + return [url hasPrefix:@"https://"] || [url hasPrefix:@"http://"]; +} + ++(NSString*) call:(lua_State*) l lightUserData:(id) lightUserData key1:(const char*) key1 key2:(const char*)key2 nargs:(int)nargs { + if( l ){ + lua_checkstack32(l); + lua_pushlightuserdata(l, (__bridge void *)lightUserData);// key=view + lua_gettable(l, LUA_REGISTRYINDEX);/* table = registry[&Key] */ + + return [LVUtil call:l key1:key1 key2:key2 nargs:nargs nrets:0]; + } + return nil; +} + ++(NSString*) call:(lua_State*) l key1:(const char*) key1 key2:(const char*)key2 nargs:(int)nargs nrets:(int)nret{ + return [LVUtil call:l key1:key1 key2:key2 key3:NULL nargs:nargs nrets:nret retType:-8]; +} + ++(NSString*) call:(lua_State*) l key1:(const char*) key1 key2:(const char*)key2 key3:(const char*)key3 + nargs:(int)nargs nrets:(int)nret + retType:(int) retType{ + return [self call:l key1:key1 key2:key2 key3:key3 key4:NULL nargs:nargs nrets:nret retType:retType]; +} + ++(NSString*) call:(lua_State*) l key1:(const char*) key1 key2:(const char*)key2 key3:(const char*)key3 key4:(const char*)key4 + nargs:(int)nargs nrets:(int)nret + retType:(int) retType{ + if( l ){ + if( lua_type(l, -1)==LUA_TNIL ){ + return @"LVUtil: call nil function"; + } else if( lua_type(l, -1)==LUA_TTABLE && key1){//table + lua_getfield(l, -1, key1); + lua_remove(l, -2); + + if( lua_type(l, -1)==LUA_TTABLE && key2){//table + lua_getfield(l, -1, key2); + lua_remove(l, -2); + + if( lua_type(l, -1)==LUA_TTABLE && key3){//table + lua_getfield(l, -1, key3); + lua_remove(l, -2); + + if( lua_type(l, -1)==LUA_TTABLE && key4){//table + lua_getfield(l, -1, key4); + lua_remove(l, -2); + } + } + } + } + int type = lua_type(l, -1); + if ( type==retType && nret==1 ) { + return nil; + } + if( type == LUA_TFUNCTION ){//function + return lv_runFunctionWithArgs(l, nargs, nret); + } + } + return @"LVUtil:lua_State is nil"; +} + +NSString* lv_runFunction(lua_State* l){ + return lv_runFunctionWithArgs(l, 0, 0); +} + +NSString* lv_runFunctionWithArgs(lua_State* l, int nargs, int nret){ + if( l && lua_type(l, -1) == LUA_TFUNCTION ) { + if( nargs>0 ){ + lua_insert(l, -nargs-1); + } + int errorCode = lua_pcall( l, nargs, nret, 0); + if ( errorCode != 0 ) { + const char* s = lua_tostring(l, -1); + LVError( @"%s", s ); +#ifdef DEBUG + NSString* string = [NSString stringWithFormat:@"[LuaView][error] %s",s]; + lv_printToServer(l, string.UTF8String, 0); +#endif + return [NSString stringWithFormat:@"%s",s]; + } + return nil; + } + return @"function is nil error"; +} + +#define api_incr_top(L) {api_check(L, L->top < L->ci->top); L->top++;} +void lv_pushUserdata(lua_State* L, void* p){///是否正确 ???????? + if( p ) { + Udata* u = (Udata*)p; + u -= 1; + lua_lock(L); + luaC_checkGC(L); + setuvalue(L, L->top, u); + api_incr_top(L); + lua_unlock(L); + } else { + lua_pushnil(L); + } +} + +id lv_luaTableToDictionary(lua_State* L ,int index){ + if( lua_type(L, index)!=LUA_TTABLE ) { + return nil; + } + lua_checkstack(L, 128); + NSMutableDictionary* dic = nil; + NSMutableArray* array = nil; + //lua_settop(L, 8); + // Push another reference to the table on top of the stack (so we know + // where it is, and this function can work for negative, positive and + // pseudo indices + lua_pushvalue(L, index); + // stack now contains: -1 => table + lua_pushnil(L); + // stack now contains: -1 => nil; -2 => table + while (lua_next(L, -2)) + { + int keyType = lua_type(L, -2); + + id value = nil; + if( lua_type(L, -1)==LUA_TSTRING ){ + value = lv_paramString(L, -1); + } else if( lua_type(L, -1)==LUA_TNUMBER ){ + value = @(lua_tonumber(L, -1) ); + } else if( lua_type(L, -1)==LUA_TTABLE ){ + value = lv_luaTableToDictionary(L,-1); + } else if( lua_type(L, -1)==LUA_TBOOLEAN ){ + value = @( ((BOOL)lua_toboolean(L, -1)) ); + } else if ( lua_type(L, -1)==LUA_TUSERDATA ) { + LVUserDataInfo* user = (LVUserDataInfo*)lua_touserdata(L, -1); + id obj = (__bridge id)(user->object); + if( [obj respondsToSelector:@selector(lv_nativeObject)] ){ + value = [obj lv_nativeObject]; + } else { + LVError(@"lv_luaTableToDictionary.1"); + } + } else { + LVError(@"lv_luaTableToDictionary.2"); + } + // stack now contains: -1 => value; -2 => key; -3 => table + if( value ) { + if( keyType== LUA_TNUMBER ) { + // number key + if( array == nil ) { + array = [[NSMutableArray alloc] init]; + } + [array addObject:value]; + } else { // string + NSString* key = lv_paramString(L, -2); + if( key ) { + if( dic == nil ) { + dic = [[NSMutableDictionary alloc] init]; + } + [dic setObject:value forKey:key]; + } + } + } + lua_pop(L, 1); + // stack now contains: -1 => key; -2 => table + } + lua_pop(L, 1); + + if( [dic count]>0 ) { + return dic; + } + if ( array.count>0 ) { + return array; + } + // Stack is now the same as it was on entry to this function + return @{}; +} + +NSArray* lv_luaTableKeys(lua_State* L, int index){ + lua_checkstack(L, 128); + NSMutableArray* keys = [[NSMutableArray alloc] init]; + //lua_settop(L, 8); + // Push another reference to the table on top of the stack (so we know + // where it is, and this function can work for negative, positive and + // pseudo indices + if ( lua_type(L, index)!= LUA_TTABLE ){ + return nil; + } + lua_pushvalue(L, index); + // stack now contains: -1 => table + lua_pushnil(L); + // stack now contains: -1 => nil; -2 => table + while (lua_next(L, -2)) + { + NSString* key = lv_paramString(L, -2); + // stack now contains: -1 => value; -2 => key; -3 => table + if( key ) { + [keys addObject:key]; + } + lua_pop(L, 1); + // stack now contains: -1 => key; -2 => table + } + lua_pop(L, 1); + // Stack is now the same as it was on entry to this function + if( keys.count>0 ){ + return keys; + } + return nil; +} + +NSArray* lv_luaTableToArray(lua_State* L,int stackID) +{ + if( lua_type(L, stackID)==LUA_TTABLE) { + int count = luaL_getn(L, stackID); + NSMutableArray* array = [[NSMutableArray alloc] init]; + + for (int i = 0; i < count; i++) + { + lua_rawgeti(L, stackID, i+1); + NSString* s = lv_paramString(L, -1); + [array addObject:s]; + lua_pop(L,1); + } + return array; + } + return nil; +} + +#pragma -mark registry + ++ (void) registryValue:(lua_State*)L key:(id) key stack:(int) stackID{ + if( L ) { + lua_checkstack(L, 4); + lua_pushvalue(L, stackID ); // value + lua_pushlightuserdata(L, (__bridge void *)(key) ); // key + lua_insert(L, -2); // key <==> value 互换 + lua_settable(L, LUA_REGISTRYINDEX);// registry[&Key] = fucntion + } +} + ++ (void) unregistry:(lua_State*) L key:(id) key{ + if( L ) { + lua_checkstack(L, 2); + lua_pushlightuserdata(L, (__bridge void *)(key) ); // key + lua_pushnil(L); // nil + lua_settable(L, LUA_REGISTRYINDEX);// registry[&Key] = nil + } +} + ++ (void) pushRegistryValue:(lua_State*) L key:(id) key{ + if( L ){ + lua_pushlightuserdata(L, (__bridge void *)(key));// key=button + lua_gettable(L, LUA_REGISTRYINDEX);/* value = registry[&Key] */ + } +} + +void lv_createClassMetaTable(lua_State* L , const char* name ){ + luaL_newmetatable(L, name ); + lua_pushstring(L, "__index");//必须要的。 + lua_pushvalue(L, -2); /* pushes the metatable */ + lua_settable(L, -3); /* metatable.__index = metatable */ +} + +void lua_checkstack32(lua_State* l){ + if( l ){ + lua_checkstack( l, 32); + } +} + +void lv_clearFirstTableValue(lua_State* L){ + int num = lua_gettop(L); + if( num>1 && lua_type(L, 1)==LUA_TTABLE ) { + lua_checkstack(L, 4); + lua_getfield(L, 1, LUAVIEW_SYS_TABLE_KEY); + if( lua_isnil(L, -1) ) { + lua_settop(L, num); + } else { + lua_settop(L, num); + lua_remove(L, 1); + } + } +} + +BOOL lv_uicolor2int(UIColor* color,NSUInteger* c, CGFloat* alphaP){ + CGFloat r = 0; + CGFloat g = 0; + CGFloat b = 0; + CGFloat a = 0; + if( [color getRed:&r green:&g blue:&b alpha:&a] ){ + NSUInteger red = (r*255); + NSUInteger green = (g*255); + NSUInteger blue = (b*255); + *c = (red<<16) | (green<<8) | blue; + *alphaP = a; + return YES; + } + return NO; +} + +UIColor* lv_getColorFromStack(lua_State* L, int stackID){ + if ( lua_type(L, stackID)==LUA_TSTRING ) { +// NSString* s = lv_paramString(L, stackID); +// if( s.length>0 && [s characterAtIndex:0]=='#' ) { +// s = [s substringFromIndex:1]; +// NSScanner * scanner = [[NSScanner alloc] initWithString:s] ; +// unsigned long long color = 0; +// [scanner scanHexLongLong:&color]; +// float a = 1; +// if( s.length>=8 ) { +// a = ( (color>>24)&0xff )/255.0; +// } +// float r = ( (color>>16)&0xff )/255.0; +// float g = ( (color>>8)&0xff )/255.0; +// float b = ( (color>>0)&0xff )/255.0; +// UIColor* colorObj = [UIColor colorWithRed:r green:g blue:b alpha:a]; +// return colorObj; +// } + } else if( lua_type(L,stackID)==LUA_TNUMBER ) { + NSUInteger color = lua_tonumber(L, stackID); + float a = 1; + float r = ( (color>>16)&0xff )/255.0; + float g = ( (color>>8)&0xff )/255.0; + float b = ( (color>>0)&0xff )/255.0; + int stackID3 = stackID + 1; + if ( lua_gettop(L)>=stackID3 && lua_type(L,stackID3)==LUA_TNUMBER ) { + a = lua_tonumber(L, stackID+1 ); + if( a>1 ) { + a = 1; + } + if( a<0 ) { + a = 0; + } + } + UIColor* colorObj = [UIColor colorWithRed:r green:g blue:b alpha:a]; + return colorObj; + } + return [UIColor blackColor]; +} + ++(void) download:(NSString*) urlStr callback:(LVFuncDownloadEndCallback) nextStep{ + if( [urlStr hasPrefix:@"//"] ) { + urlStr = [NSString stringWithFormat:@"https:%@",urlStr]; + } + if( [urlStr.lowercaseString hasPrefix:@"http://"] ){ + urlStr = [NSString stringWithFormat:@"https://%@",[urlStr substringFromIndex:7]]; + } + NSURL *url = [NSURL URLWithString:urlStr]; + NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; + [request setHTTPMethod:@"GET"]; + [request setTimeoutInterval:30.0]; + + NSOperationQueue *queue = [[NSOperationQueue alloc]init]; + [NSURLConnection sendAsynchronousRequest:request + queue:queue + completionHandler:^(NSURLResponse *response, NSData *data, NSError *error){ + if( error==nil && data ){ + nextStep(data); + } else { + nextStep(nil); + } + }]; +} + +#pragma file data + ++(BOOL) saveData:(NSData*) data toFile:(NSString*) path{ + if( path ){ + BOOL ret = [data writeToFile:path atomically:YES]; + if( !ret ) { + NSLog(@"[LuaView][error] saveFile: %@", path); + } + return ret; + } + return NO; +} + ++(NSData*) dataReadFromFile:(NSString*)path { + if( path ){ + NSFileManager* fm = [NSFileManager defaultManager]; + NSData* data = [fm contentsAtPath:path]; + return data; + } + return nil; +} + ++(BOOL) deleteFile:(NSString*)path { + if( [self exist:path] ){ + NSFileManager* fm = [NSFileManager defaultManager]; + NSError* err; + [fm removeItemAtPath:path error:&err]; + return err==nil; + } + return YES; +} + ++(BOOL) exist:(NSString*) path{ + BOOL directory = NO; + NSFileManager *fileManage = [NSFileManager defaultManager]; + if ( [fileManage fileExistsAtPath:path isDirectory:&directory] && !directory) { + return YES; + } + return NO; +} + ++ (NSString*) PathForBundle:(NSBundle*) bundle relativePath:(NSString*) relativePath { + NSString* resourcePath = [(nil == bundle ? [NSBundle mainBundle] : bundle) resourcePath]; + return [resourcePath stringByAppendingPathComponent:relativePath]; +} + ++ (NSString*) PathForDocumentsResource:(NSString*) relativePath { + static NSString* documentsPath = nil; + if (nil == documentsPath) { + NSArray* dirs = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); + documentsPath = [dirs objectAtIndex:0]; + } + return [documentsPath stringByAppendingPathComponent:relativePath]; +} + ++ (NSString*) PathForCachesResource:(NSString* )relativePath { + static NSString* cachesPath = nil; + if (nil == cachesPath) { + NSArray* dirs = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); + cachesPath = [dirs objectAtIndex:0]; + } + return [cachesPath stringByAppendingPathComponent:relativePath]; +} + ++(BOOL) createPath:(NSString*) path{ + NSFileManager *fileManage = [NSFileManager defaultManager]; + if ( ![fileManage fileExistsAtPath:path] ) { + NSError* error = nil; + [fileManage createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:&error]; + if( error ) + return NO; + else + return YES; + } + return YES; +} + ++(id) stringToObject:(NSString*) s{ + if( s==nil ) + return nil; + NSData* data = [s dataUsingEncoding:NSUTF8StringEncoding]; + NSError* error = nil; + id dic = [NSJSONSerialization JSONObjectWithData:data + options:NSJSONReadingAllowFragments + error:&error]; + return dic; +} + ++(NSString*) objectToString:(id) obj{ + if( obj ==nil ) + return nil; + NSError* error = nil; + NSData* data = [NSJSONSerialization dataWithJSONObject:obj options:0 error:&error]; + if( data && error==nil ) { + return [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding]; + } + return nil; +} + ++ (NSString*) MD5HashFromData:(NSData*) data { + unsigned char bs[CC_MD5_DIGEST_LENGTH]; + bzero(bs, sizeof(bs)); + CC_MD5_CTX context; + CC_MD5_Init(&context); + size_t bytesHashedNum = 0; + while (bytesHashedNum < [data length]) { + CC_LONG updateSize = 1024 * 1024; + if (([data length] - bytesHashedNum) < (size_t)updateSize) { + updateSize = (CC_LONG)([data length] - bytesHashedNum); + } + CC_MD5_Update(&context, (char *)[data bytes] + bytesHashedNum, updateSize); + bytesHashedNum += updateSize; + } + CC_MD5_Final(bs, &context); + + return [NSString stringWithFormat: + @"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", + bs[0], bs[1], bs[2], bs[3], bs[4], bs[5], bs[6], bs[7], + bs[8], bs[9], bs[10], bs[11], bs[12], bs[13], bs[14],bs[15]]; +} + ++ (NSData*) MD5HashDataFromData:(NSData*) data { + unsigned char bs[CC_MD5_DIGEST_LENGTH]; + bzero(bs, sizeof(bs)); + CC_MD5_CTX context; + CC_MD5_Init(&context); + size_t bytesHashedNum = 0; + while (bytesHashedNum < [data length]) { + CC_LONG updateSize = 1024 * 1024; + if (([data length] - bytesHashedNum) < (size_t)updateSize) { + updateSize = (CC_LONG)([data length] - bytesHashedNum); + } + CC_MD5_Update(&context, (char *)[data bytes] + bytesHashedNum, updateSize); + bytesHashedNum += updateSize; + } + CC_MD5_Final(bs, &context); + + return [[NSData alloc] initWithBytes:bs length:16]; +} + +BOOL lv_isLuaObjectHaveProperty(lua_State* L, int idx, const char* key){ + if (lua_type(L, idx) == LUA_TTABLE ) { + lua_checkstack(L, 8); + lua_pushvalue(L, idx); + lua_getfield(L, -1, key); + BOOL ret = lua_type(L, -1)!=LUA_TNIL; + lua_pop(L, 2); + return ret; + } + return NO; +} + +static id luaObjBox(lua_State* L, int idx){ + LVLuaObjBox* box = [[LVLuaObjBox alloc] init:L stackID:idx]; + return box; +} + +id lv_luaValueToNativeObject(lua_State* L, int idx){ + int type = lua_type(L, idx); + switch ( type ) { + case LUA_TNIL: { + return nil; + } + case LUA_TUSERDATA: { + LVUserDataInfo* user = (LVUserDataInfo*)lua_touserdata(L, idx); + id obj = (__bridge id)(user->object); + if( [obj respondsToSelector:@selector(lv_nativeObject)] ){ + return [obj lv_nativeObject]; + } + LVError(@"lv_luaValueToNativeObject.1"); + return obj; + } + case LUA_TLIGHTUSERDATA:{ + LVPointerValueBox* box = [[LVPointerValueBox alloc] init]; + box.pointer = lua_touserdata(L, idx); + return box; + } + case LUA_TBOOLEAN: { + return [[NSNumber alloc] initWithBool:lua_toboolean(L, idx)]; + } + case LUA_TNUMBER: { + return @( lua_tonumber(L, idx) ); + } + case LUA_TSTRING: { + return lv_paramString(L, idx); + } + case LUA_TTABLE: { + if ( lv_isLuaObjectHaveProperty(L, idx, "__obj") ) { + return luaObjBox(L, idx); + } else { + return lv_luaTableToDictionary(L, idx); + } + } + case LUA_TFUNCTION: { + return [[LVBlock alloc] initWith:L statckID:idx]; + } + default: { + LVError(@"lv_luaObjectToNativeObject.2"); + return nil; + } + } +} + + + +void lv_pushNativeObject(lua_State* L, id value){ + lua_checkstack(L, 4); + if( [value isKindOfClass:[NSString class]] ) { + NSString* s = value; + lua_pushstring(L, s.UTF8String); + return; + } else if( [value isKindOfClass:[NSDictionary class]] ) { + NSDictionary* dictionary = value; + lua_newtable(L); + for (NSString *key in dictionary) { + NSString* value = dictionary[key]; + lua_checkstack(L, 4); + lua_pushstring(L, key.UTF8String); + lv_pushNativeObject(L,value); + lua_settable(L, -3); + } + return; + } else if( [value isKindOfClass:[NSArray class]] ) { + NSArray* array = value; + lua_newtable(L); + for (int i=0; iobject = CFBridgingRetain(nativeObjBox); + nativeObjBox.lv_userData = userData; + luaL_getmetatable(L, META_TABLE_NativeObject ); + lua_setmetatable(L, -2); +} + +// 获取参数-》字符串类型 +NSString* lv_paramString(lua_State* L, int idx ){ + if( lua_gettop(L)>=ABS(idx) && lua_type(L, idx) == LUA_TSTRING ) { + size_t n = 0; + const char* chars = luaL_checklstring(L, idx, &n ); + NSString* s = @""; + if( chars && n>0 ){ + s = [NSString stringWithUTF8String:chars]; + } + return s; + } + return nil; +} + ++(BOOL) ios8{ + static BOOL yes = NO; + static BOOL inited = NO; + if( !inited ) { + inited = YES; + yes = ([[[UIDevice currentDevice] systemVersion] compare:@"8.0"] != NSOrderedAscending); + } + return yes; +} + +void lv_pushUDataRef(lua_State* L, int key) { + // -1:userdata + if( lua_gettop(L)>=1 && lua_type(L, -1)==LUA_TUSERDATA ) { + lua_checkstack(L, 2); + + if( lv_getUDataLuatable(L, -1) ) { + lua_remove(L, -2); + } + if( lua_type(L, -1)==LUA_TTABLE ) { + lua_pushnumber(L, key); + lua_gettable(L, -2); + lua_remove(L, -2); + } else { + LVError( @"lv_pushUDataRef.1" ); + } + } else { + LVError( @"lv_pushUDataRef.2" ); + } +} + +void lv_udataRef(lua_State* L, int key ){ + //-2: userdata -1: value + if( lua_gettop(L)>=2 && lua_type(L, -2)==LUA_TUSERDATA ) { + lua_checkstack(L, 8); + + lv_getUDataLuatable(L, -2);//table + if( lua_type(L, -1)==LUA_TTABLE ) { + lua_pushnumber(L, key);// key + lua_pushvalue(L, -3);//value + lua_settable(L, -3); + lua_pop(L, 2); + } else { + LVError( @"lv_udataRef" ); + } + } +} + +void lv_udataUnref(lua_State* L, int key) { + // -1:userdata + if( lua_gettop(L)>=1 && lua_type(L, -1)==LUA_TUSERDATA ) { + lua_checkstack(L, 8); + + lv_getUDataLuatable(L, -1); + if( lua_type(L, -1)==LUA_TTABLE ) { + lua_pushnumber(L, key); + lua_pushnil(L); + lua_settable(L, -3); + lua_pop(L, 1); + } else { + LVError( @"lv_udataUnref" ); + } + } +} + +static int lv_setUDataLuatable (lua_State *L, int index) { + if( lua_type(L, index)==LUA_TUSERDATA ){ + lua_setfenv(L, index); + return 1; + } + return 0; +} + +int lv_getUDataLuatable (lua_State *L, int index) { + if( lua_type(L, index)==LUA_TUSERDATA ){ + lua_getfenv(L, index); + return 1; + } + return 0; +} + +int lv_createUDataLuatable (lua_State *L, int index){ + lua_checkstack(L, 8); + lua_pushvalue(L, index); + lua_createtable(L, 8, 0); + lv_setUDataLuatable(L, -2); + lua_pop(L, 1); + return 1; +} + +void lv_luaTableSetWeakWindow(lua_State* L, UIView* cell){ + lua_pushstring(L, "window"); + + NEW_USERDATA(userData, View); + userData->object = CFBridgingRetain(cell); + + luaL_getmetatable(L, META_TABLE_UIView ); + lua_setmetatable(L, -2); + + lua_settable(L, -3); +} + +void lv_luaTableRemoveKeys(lua_State* L, const char** keys){ + if ( lua_type(L, -1)== LUA_TTABLE ) { + for ( int i=0; ;i++ ){ + const char* key = keys[i]; + if( key ) { + lua_pushnil(L); + lua_setfield(L, -2, key); + } else { + break; + } + } + } +} + + +int lv_callbackFunction(lua_State* L, const char* functionName){ + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + if ( lua_gettop(L)>=2 && lua_type(L, 2)==LUA_TFUNCTION ) { + lua_pushvalue(L, 1); + lv_pushUDataRef(L, USERDATA_KEY_DELEGATE); + if( lua_type(L, -1)==LUA_TNIL ) { + lua_createtable(L, 0, 0); + lv_udataRef(L, USERDATA_KEY_DELEGATE); + } + lua_pushstring(L, functionName); + lua_pushvalue(L, 2); + lua_settable(L, -3); + return 0; + } else { + lv_pushUDataRef(L, USERDATA_KEY_DELEGATE); + lua_pushstring(L, functionName); + lua_gettable(L, -2); + return 1; + } + } + return 0; +} + +BOOL lv_objcEqual(id obj1, id obj2) { + return obj1 == obj2 || [obj1 isEqual:obj2]; +} + ++ (UIFont *)fontWithName:(NSString *)fontName size:(CGFloat)fontSize bundle:(LVBundle*)bundle{ + UIFont* font = [UIFont fontWithName:fontName size:fontSize]; + if( font == nil ) { + [LVUtil loadFont:fontName package:bundle]; + font = [UIFont fontWithName:fontName size:fontSize]; + } + return font; +} + ++(int) loadFont:(NSString*) fileName package:(LVBundle*)bundle{ + int ret = 0; + if( [fileName.lowercaseString hasSuffix:@".ttf"]==NO ) { + fileName = [NSString stringWithFormat:@"%@.ttf",fileName]; + } + NSData *inData = [bundle resourceWithName:fileName];/* your font-file data */; + CFErrorRef error; + CGDataProviderRef provider = CGDataProviderCreateWithCFData((CFDataRef)inData); + CGFontRef font = CGFontCreateWithDataProvider(provider); + if (! CTFontManagerRegisterGraphicsFont(font, &error)) { + CFStringRef errorDescription = CFErrorCopyDescription(error); + NSLog(@"Failed to load font: %@", errorDescription); + LVReleaseAndNull(errorDescription); + ret = -1; + } + LVReleaseAndNull(font); + LVReleaseAndNull(provider); + return ret; +} + + ++(void) reg:(lua_State*)L clas:(id) c cfunc:(lua_CFunction) cfunc globalName:(NSString*)globalName defaultName:(NSString*) defaultName{ + if( defaultName || globalName ) { + lua_checkstack(L, 12); + NSString* className = NSStringFromClass(c); + lua_pushstring(L, className.UTF8String); + lua_pushcclosure(L, cfunc, 1); + + lua_setglobal(L, globalName ? globalName.UTF8String : defaultName.UTF8String ); + } +} + ++(Class) upvalueClass:(lua_State*)L defaultClass:(Class) defaultClass{ + const char* classNameChars = lua_tostring(L, lua_upvalueindex(1)); + NSMutableString* className = [NSMutableString stringWithFormat:@"%s",classNameChars]; + Class c = NSClassFromString(className); + if( c == nil ) { + c = defaultClass; + } + return c; +} + ++(void) defineGlobal:(NSString*)globalName value:(id) value L:(lua_State*)L { + if( globalName && value ) { + lua_checkstack(L, 12); + lv_pushNativeObject(L, value); + lua_setglobal(L, globalName.UTF8String); + } else { + LVError(@"define Global Value"); + } +} + +void lv_defineGlobalFunc(const char* globalName, lua_CFunction func, lua_State* L) { + if( globalName && func ) { + lua_checkstack(L, 12); + lua_pushcfunction(L, func); + lua_setglobal(L, globalName); + } else { + LVError(@"define Global Function"); + } +} + +void lv_addSubview(LuaViewCore* lv, UIView* superview, UIView* subview){ + [subview removeFromSuperview]; + [subview.layer removeFromSuperlayer]; + if( lv.closeLayerMode + || [superview isKindOfClass:[UIScrollView class]] + || [subview isKindOfClass:[UIScrollView class]] ) { + [superview addSubview:subview]; + } else { + [superview.layer addSublayer:subview.layer]; + } +} + + +static id objectForKey(NSDictionary* dic, id key, Class clazz){ + id obj = [dic objectForKey:key]; + if ([obj isKindOfClass:clazz]) { + return obj; + } + return nil; +} + +NSString* safe_stringForKey(NSDictionary*dic, id key) { + NSString *obj = objectForKey(dic, key, [NSString class] ); + return obj; +} + +NSDictionary * safe_dictionaryForKey(NSDictionary* dic, id key) { + NSDictionary *obj = objectForKey( dic, key, [NSDictionary class] ); + return obj; +} + +NSDate * safe_dateForKey(NSDictionary* dic, id key ){ + NSDate *obj = objectForKey(dic, key, [NSDate class] ); + return obj; +} + + + ++ (NSTimer *) scheduledTimerWithTimeInterval:(NSTimeInterval)inTimeInterval + block:(void (^)(NSTimer *timer))block + repeats:(BOOL)inRepeats { + NSParameterAssert(block != nil); + return [NSTimer scheduledTimerWithTimeInterval:inTimeInterval + target:self + selector:@selector(lv_executeBlockFromTimer:) + userInfo:[block copy] + repeats:inRepeats]; +} + ++ (void)lv_executeBlockFromTimer:(NSTimer *)aTimer { + void (^block)(NSTimer *) = [aTimer userInfo]; + if (block) + block(aTimer); +} + ++ (NSString*) luaTrace:(lua_State*) L{ + // 打印lua调用栈开始 + lua_getglobal(L, "debug"); + lua_getfield(L, -1, "traceback"); + int iError = lua_pcall( L,//VMachine + 0,//Argument Count + 1,//Return Value Count + 0); + const char* s = lua_tostring(L, -1); + NSString* stack = [NSString stringWithFormat:@"%s",s]; + NSLog(@"err:%d \n %@", iError, stack); + return stack; +} + + +void LVLog( NSString* format, ... ){ +#ifdef DEBUG + va_list params; //定义一个指向个数可变的参数列表指针; + va_start(params,format);//va_start 得到第一个可变参数地址, + NSString* s = [[NSString alloc] initWithFormat:format arguments:params]; + NSLog(@"[LuaView]%@", s); + va_end(params); +#endif +} + +void LVError( NSString* format, ... ){ +#ifdef DEBUG + va_list params; //定义一个指向个数可变的参数列表指针; + va_start(params,format);//va_start 得到第一个可变参数地址, + NSString* s = [[NSString alloc] initWithFormat:format arguments:params]; + NSLog(@"[LuaView][error]%@", s); + va_end(params); +#endif +} + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVWebView.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVWebView.h new file mode 100644 index 00000000..f4a02780 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVWebView.h @@ -0,0 +1,43 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" +#import "LView.h" + +@interface LVWebView : UIView + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; +@property(nonatomic,assign) NSUInteger lv_align; +@property(nonatomic,strong) CAShapeLayer* lv_shapeLayer; + +-(id) init:(lua_State*) l; + + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +//-------------------------------------- +-(void) createWebView; +-(BOOL) canGoBack; +-(void) goBack; +-(BOOL) canGoForward; +-(void) goForward; +-(void) reload; +-(void) stopLoading; +-(BOOL) isLoading; +-(NSString*) title; +-(void) loadUrl:(NSString*) url; +-(NSString*) url; + +// 开启下拉刷新(是、否) +-(void) setPullRefreshEnable:(BOOL) t; +// 返回下拉刷新是否开启 +-(BOOL) pullRefreshEnable; + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVWebView.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVWebView.m new file mode 100644 index 00000000..fd2660ca --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVWebView.m @@ -0,0 +1,346 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVWebView.h" +#import "LVBaseView.h" +#import "NSObject+LuaView.h" + +@interface LVWebView () +@property(nonatomic,strong) UIWebView* webView; +@end + +@implementation LVWebView + + +-(id) init:(lua_State*) l{ + self = [super init]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + self.contentMode = UIViewContentModeScaleAspectFill; + self.backgroundColor = [UIColor clearColor]; + self.clipsToBounds = YES; + [self createWebView]; + } + return self; +} + +- (void)webViewDidStartLoad:(UIWebView *)webView{ + lua_State* L = self.lv_luaviewCore.l; + if( L && self.lv_userData ){ + lua_settop(L, 0); + [self lv_callLuaByKey1:@STR_onPageStarted]; + } +} + +- (void)webViewDidFinishLoad:(UIWebView *)webView{ + lua_State* L = self.lv_luaviewCore.l; + if( L && self.lv_userData ){ + lua_settop(L, 0); + [self lv_callLuaByKey1:@STR_onPageFinished]; + } +} + +- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{ + lua_State* L = self.lv_luaviewCore.l; + if( L && self.lv_userData ){ + lua_settop(L, 0); + NSInteger errorCode = error.code; + NSString* errorInfo = [NSString stringWithFormat:@"%@",error]; + NSString* url = webView.request.URL.absoluteString; + lua_pushnumber(L, errorCode); + lua_pushstring(L, errorInfo.UTF8String); + lua_pushstring(L, url.UTF8String); + [self lv_callLuaByKey1:@STR_onReceivedError key2:nil argN:3]; + } +} + +// 创建webView +-(void) createWebView{ + self.webView = [[UIWebView alloc] init]; + self.webView.delegate = self; + [self addSubview:self.webView]; +} + +-(BOOL) canGoBack{ + return self.webView.canGoBack; +} + +-(void) goBack{ + [self.webView goBack]; +} + +-(BOOL) canGoForward{ + return self.webView.canGoForward; +} + +-(void) goForward{ + [self.webView goForward]; +} + +-(void) reload{ + [self.webView reload]; +} + +-(void) stopLoading{ + [self.webView stopLoading]; +} + +-(BOOL) isLoading{ + return [self.webView isLoading]; +} + +-(NSString*) title{ + NSString *theTitle=[self.webView stringByEvaluatingJavaScriptFromString:@"document.title"]; + return theTitle; +} + +-(void) loadUrl:(NSString*) url{ + if( url ) { + NSURL * nsurl = [[NSURL alloc] initWithString:url]; + [self.webView loadRequest:[NSURLRequest requestWithURL:nsurl]]; + } +} + +-(NSString*) url{ + return self.webView.request.URL.absoluteString; +} + +-(void) setPullRefreshEnable:(BOOL) t{ +} + +-(BOOL) pullRefreshEnable{ + return NO; +} + +-(void) layoutSubviews{ + [super layoutSubviews]; + self.webView.frame = self.bounds; +} + +-(void) dealloc{ + LVUserDataInfo* userData = self.lv_userData; + if( userData ){ + userData->object = NULL; + } +} + +#pragma -mark webView +static int lvNewWebView(lua_State *L) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVWebView class]]; + + NSString* url = lv_paramString(L, 1); + + LVWebView* webView = [[c alloc] init:L]; + [webView loadUrl:url]; + { + NEW_USERDATA(userData, View); + userData->object = CFBridgingRetain(webView); + webView.lv_userData = userData; + + luaL_getmetatable(L, META_TABLE_UIWebView ); + lua_setmetatable(L, -2); + } + LuaViewCore* view = LV_LUASTATE_VIEW(L); + if( view ){ + [view containerAddSubview:webView]; + } + return 1; /* new userdatum is already on the stack */ +} + +static int canGoBack (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVWebView* webView = (__bridge LVWebView *)(user->object); + if ( [webView isKindOfClass:[LVWebView class]] ) { + BOOL ret = [webView canGoBack]; + lua_pushboolean(L, ret); + return 1; + } + } + lua_pushboolean(L, 0); + return 1; +} + +static int goBack (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVWebView* webView = (__bridge LVWebView *)(user->object); + if ( [webView isKindOfClass:[LVWebView class]] ) { + [webView goBack]; + return 0; + } + } + return 0; +} + +static int canGoForward (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVWebView* webView = (__bridge LVWebView *)(user->object); + if ( [webView isKindOfClass:[LVWebView class]] ) { + BOOL ret = [webView canGoForward]; + lua_pushboolean(L, ret); + return 1; + } + } + lua_pushboolean(L, 0); + return 1; +} + +static int goForward (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVWebView* webView = (__bridge LVWebView *)(user->object); + if ( [webView isKindOfClass:[LVWebView class]] ) { + [webView goForward]; + return 0; + } + } + return 0; +} + +static int reload (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVWebView* webView = (__bridge LVWebView *)(user->object); + if ( [webView isKindOfClass:[LVWebView class]] ) { + [webView reload]; + return 0; + } + } + return 0; +} + +static int stopLoading (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVWebView* webView = (__bridge LVWebView *)(user->object); + if ( [webView isKindOfClass:[LVWebView class]] ) { + [webView stopLoading]; + return 0; + } + } + return 0; +} + +static int isLoading (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVWebView* webView = (__bridge LVWebView *)(user->object); + if ( [webView isKindOfClass:[LVWebView class]] ) { + BOOL ret = [webView isLoading]; + lua_pushboolean(L, ret); + return 1; + } + } + lua_pushboolean(L, 0); + return 1; +} + +static int title (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVWebView* webView = (__bridge LVWebView *)(user->object); + if ( [webView isKindOfClass:[LVWebView class]] ) { + NSString* title = [webView title]; + lua_pushstring(L, title.UTF8String); + return 1; + } + } + return 0; +} + +static int loadUrl (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVWebView* webView = (__bridge LVWebView *)(user->object); + if ( [webView isKindOfClass:[LVWebView class]] ) { + if ( lua_type(L, 2)==LUA_TSTRING ) { + NSString* url = lv_paramString(L, 2);// 2 + [webView loadUrl:url]; + } else if ( lua_type(L, 2)==LUA_TUSERDATA ) { + } else { + } + } + } + return 0; +} + +static int url (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVWebView* webView = (__bridge LVWebView *)(user->object); + if ( [webView isKindOfClass:[LVWebView class]] ) { + NSString* s = [webView url]; + lua_pushstring(L, s.UTF8String); + return 1; + } + } + return 0; +} + +static int pullRefreshEnable (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ) { + LVWebView* webView = (__bridge LVWebView *)(user->object); + if ( [webView isKindOfClass:[LVWebView class]] ) { + if( lua_gettop(L)>=2 ){ + BOOL yes = lua_toboolean(L, 2); + [webView setPullRefreshEnable:yes]; + return 0; + } else { + BOOL ret = [webView pullRefreshEnable]; + lua_pushboolean(L, ret); + return 1; + } + } + } + return 0; +} + +static int callback (lua_State *L) { + return lv_setCallbackByKey(L, STR_CALLBACK, NO); +} + + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewWebView globalName:globalName defaultName:@"WebView"]; + + const struct luaL_Reg memberFunctions [] = { + {"canGoBack", canGoBack}, + {"goBack", goBack}, + + {"canGoForward", canGoForward}, + {"goForward", goForward}, + + {"reload", reload}, + {"stopLoading", stopLoading}, + {"isLoading", isLoading}, + + {"title", title}, + {"loadUrl", loadUrl}, + {"url", url}, + + {"pullRefreshEnable",pullRefreshEnable}, + + {"callback", callback}, + {NULL, NULL} + }; + + lv_createClassMetaTable(L, META_TABLE_UIWebView); + + luaL_openlib(L, NULL, [LVBaseView baseMemberFunctions], 0); + luaL_openlib(L, NULL, memberFunctions, 0); + + const char* keys[] = { "addView", NULL};// 移除多余API + lv_luaTableRemoveKeys(L, keys ); + return 1; +} + + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/NSObject+LuaView.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/NSObject+LuaView.h new file mode 100644 index 00000000..a83ddc29 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/NSObject+LuaView.h @@ -0,0 +1,24 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ +#import +#import "LVHeads.h" + + +@interface NSObject(NSObjectLuaView) + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; +- (id) lv_nativeObject; + +- (void) lv_callLuaByKey1:(NSString*) key1; +- (void) lv_callLuaByKey1:(NSString*) key1 key2:(NSString*) key2 argN:(int) argN; +-(NSString*) lv_callLua:(NSString*) functionName args:(NSArray*) args; + +- (void) lv_buttonCallBack; + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/NSObject+LuaView.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/NSObject+LuaView.m new file mode 100644 index 00000000..59c01a15 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/NSObject+LuaView.m @@ -0,0 +1,84 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "NSObject+LuaView.h" +#import "LuaViewCore.h" + +@implementation NSObject(NSObjectLuaView) + +- (LuaViewCore*) lv_luaviewCore{ + return nil; +} + +- (void) setLv_luaviewCore:(LuaViewCore *)lv_luaviewCore{ +} + +- (LVUserDataInfo*)lv_userData{ + return nil; +} + +- (void) setLv_userData:(LVUserDataInfo *)userData{ +} + +- (void) lv_callLuaByKey1:(NSString*) key1{ + [self lv_callLuaByKey1:key1 key2:nil argN:0]; +} + +- (void) lv_callLuaByKey1:(NSString*) key1 key2:(NSString*) key2 argN:(int)argN{ + lua_State* l = self.lv_luaviewCore.l; + if( l && self.lv_userData && key1){ + lua_checkstack32(l); + lv_pushUserdata(l, self.lv_userData); + lv_pushUDataRef(l, USERDATA_KEY_DELEGATE); + if( lua_type(l, -1) == LUA_TTABLE ) { + lua_getfield(l, -1, STR_CALLBACK); + if( lua_type(l, -1)==LUA_TNIL ) { + lua_remove(l, -1); + } else { + lua_remove(l, -2); + } + } + [LVUtil call:l key1:key1.UTF8String key2:key2.UTF8String key3:NULL nargs:argN nrets:0 retType:LUA_TNONE]; + } +} + +-(NSString*) lv_callLua:(NSString*) functionName args:(NSArray*) args{ + lua_State* L = self.lv_luaviewCore.l; + if( L ){ + lua_checkstack(L, (int)args.count*2 + 2); + + for( int i=0; i +#import "LVRefreshConst.h" + +@class LVRefreshHeader; + +@interface UIScrollView (LVRefresh) +/** 下拉刷新控件 */ +@property (strong, nonatomic) LVRefreshHeader * lv_refresh_header; + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/UIScrollView+LVRefresh.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/UIScrollView+LVRefresh.m new file mode 100644 index 00000000..ba9169e5 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/UIScrollView+LVRefresh.m @@ -0,0 +1,34 @@ + +#import "UIScrollView+LVRefresh.h" +#import "LVRefreshHeader.h" +#import + + + +@implementation UIScrollView (LVRefresh) + +#pragma mark - header +static const char LVRefreshHeaderKey = '\0'; +- (void)setLv_refresh_header:(LVRefreshHeader *)header +{ + if (header != self.lv_refresh_header) { + // 删除旧的,添加新的 + [self.lv_refresh_header removeFromSuperview]; + [self insertSubview:header atIndex:0]; + + // 存储新的 + [self willChangeValueForKey:@"lv_refresh_header"]; // KVO + objc_setAssociatedObject(self, &LVRefreshHeaderKey, + header, OBJC_ASSOCIATION_ASSIGN); + [self didChangeValueForKey:@"lv_refresh_header"]; // KVO + } +} + +- (LVRefreshHeader *)lv_refresh_header +{ + return objc_getAssociatedObject(self, &LVRefreshHeaderKey); +} + + +@end + diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/UIScrollView+LuaView.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/UIScrollView+LuaView.h new file mode 100644 index 00000000..a5100279 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/UIScrollView+LuaView.h @@ -0,0 +1,41 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" +#import "UIView+LuaView.h" + + +@interface UIScrollView (UIScrollViewLuaView) + + +// 下拉刷新组件 需要重载的API +- (void) lv_initRefreshHeader;// 开启下拉刷新功能 +- (void) lv_hiddenRefreshHeader:(BOOL) hidden; +- (void) lv_beginRefreshing;// 进入刷新状态 +- (void) lv_endRefreshing;// 结束刷新状态 +- (BOOL) lv_isRefreshing;// 是否正在刷新 + +// 加载更多组件 需要重载的API +- (void) lv_initRefreshFooter;// 开启上拉加载更多功能 +- (void) lv_hiddenRefreshFooter:(BOOL) hidden; +- (void) lv_noticeNoMoreData;// 提示没有更多的数据 +- (void) lv_resetNoMoreData;// 重置没有更多的数据(消除没有更多数据的状态) + +/* + * 回调脚本开始下拉刷新 + */ +- (void) lv_refreshHeaderToRefresh; + +/* + * 回调脚本开始加载更多 + */ +- (void) lv_refreshFooterToLoadMore; + + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/UIScrollView+LuaView.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/UIScrollView+LuaView.m new file mode 100644 index 00000000..8c85c9c8 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/UIScrollView+LuaView.m @@ -0,0 +1,57 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "UIScrollView+LuaView.h" +#import "LuaViewCore.h" +#import "NSObject+LuaView.h" + + +@implementation UIScrollView (UIScrollViewLuaView) + + +// 下拉刷新 +-(void) lv_initRefreshHeader{// 初始化下拉刷新功能 +} + +- (void) lv_hiddenRefreshHeader:(BOOL) hidden{ +} + +- (void) lv_beginRefreshing{// 进入刷新状态 +} + +- (void) lv_endRefreshing{// 结束刷新状态 +} + +- (BOOL) lv_isRefreshing{// 是否正在刷新 + return NO; +} + +// 加载更多 +- (void) lv_initRefreshFooter{// 初始化上拉加载更多功能 +} +- (void) lv_hiddenRefreshFooter:(BOOL) hidden{ +} + +- (void) lv_noticeNoMoreData{// 提示没有更多的数据 +} + +- (void) lv_resetNoMoreData{// 重置没有更多的数据(消除没有更多数据的状态) +} + +- (void) lv_refreshHeaderToRefresh{ + // 开始下拉刷新调用 + [self lv_callLuaByKey1:@"PullDown"]; +} + +- (void) lv_refreshFooterToLoadMore{ + // 开始上拉刷新调用 + [self lv_callLuaByKey1:@"PullUpRefresh"]; +} + + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/UIView+LuaView.h b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/UIView+LuaView.h new file mode 100644 index 00000000..c353cda2 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/UIView+LuaView.h @@ -0,0 +1,37 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + +@interface UIView(UIViewLuaView) + + + +@property(nonatomic,assign) NSUInteger lv_align; +@property(nonatomic,assign) BOOL lv_isCallbackAddClickGesture;// 设置Callback时需要注册手势回调,才设置成true + +-(void) lv_callbackAddClickGesture;// 回调添加 + +- (void) lv_alignSubviews; + +- (void) lv_alignSelfWithSuperRect:(CGRect) rect; + +-(id) lv_getNativeView; + +// shapelayer +@property(nonatomic,strong) CAShapeLayer* lv_shapeLayer; +-(CALayer*) lv_layer; +-(void) lv_createShapelayer:(NSArray*) arr; + +-(void) lv_effectParallax:(CGFloat)dx dy:(CGFloat)dy; +-(void) lv_effectClick:(NSInteger)color alpha:(CGFloat)alpha; + +@property(nonatomic,assign) BOOL lv_canvas; + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/UIView+LuaView.m b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/UIView+LuaView.m new file mode 100644 index 00000000..6424f266 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/UIView+LuaView.m @@ -0,0 +1,127 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "UIView+LuaView.h" +#import "LuaViewCore.h" +#import "LVHeads.h" +#import "NSObject+LuaView.h" + +@implementation UIView (UIViewLuaView) + +-(BOOL) lv_isCallbackAddClickGesture{ + return NO; +} +-(void) setLv_isCallbackAddClickGesture:(BOOL)lv_isCallbackAddClickGesture{ +} + +-(void) lv_callbackAddClickGesture { + if( self.lv_isCallbackAddClickGesture ){ + self.lv_isCallbackAddClickGesture = NO; + UITapGestureRecognizer* gesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(lv_buttonCallBack)]; + self.userInteractionEnabled = YES; + [self addGestureRecognizer:gesture]; + } +} + +// align + +-(NSUInteger) lv_align{ + return 0; +} + +-(void) setLv_align:(NSUInteger)lv_align{ +} + +- (void) lv_alignSubviews { + CGRect rect = self.frame; + NSArray* subviews = [self subviews]; + for( UIView* view in subviews){ + [view lv_alignSelfWithSuperRect:rect]; + } +} + +- (void) lv_alignSelfWithSuperRect:(CGRect) rect{ + NSUInteger ali = self.lv_align; + if( ali ){ + CGRect r0 = [self frame]; + CGRect r = r0; + if( ali&LV_ALIGN_LEFT ) { + r.origin.x = 0; + } else if( ali&LV_ALIGN_H_CENTER ) { + r.origin.x = (rect.size.width-r.size.width)/2; + } else if( ali&LV_ALIGN_RIGHT ) { + r.origin.x = rect.size.width-r.size.width; + } + if( ali&LV_ALIGN_TOP ) { + r.origin.y = 0; + } else if( ali&LV_ALIGN_V_CENTER ) { + r.origin.y = (rect.size.height-r.size.height)/2; + } else if( ali&LV_ALIGN_BOTTOM ) { + r.origin.y = (rect.size.height-r.size.height); + } + if( !CGRectEqualToRect(r0, r) ) { + self.frame = r; + } + } +} + +-(id) lv_getNativeView{ + return self; +} + +-(CAShapeLayer*) lv_shapeLayer{ + return nil; +} + +-(void) setLv_shapeLayer:(CAShapeLayer *)lv_shapeLayer{ +} + +-(CALayer*) lv_layer{ + if( self.lv_shapeLayer ){ + return self.lv_shapeLayer; + } + return self.layer; +} + +-(void) lv_createShapelayer:(NSArray*)arr{ + [self.lv_shapeLayer removeFromSuperlayer]; + self.lv_shapeLayer = nil; + + CAShapeLayer *borderLayer = [CAShapeLayer layer]; + borderLayer.bounds = self.bounds; + borderLayer.position = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds)); + borderLayer.lineWidth = self.layer.borderWidth; + + borderLayer.fillColor = [UIColor clearColor].CGColor; + borderLayer.strokeColor = self.layer.borderColor; + borderLayer.path = [UIBezierPath bezierPathWithRoundedRect:borderLayer.bounds cornerRadius:self.layer.cornerRadius].CGPath; + borderLayer.lineDashPattern = arr; + self.lv_shapeLayer = borderLayer; + + if( self.lv_shapeLayer ) { + self.layer.borderColor = [UIColor clearColor].CGColor; + [self.layer addSublayer:self.lv_shapeLayer]; + } +} + +-(void) lv_effectParallax:(CGFloat)dx dy:(CGFloat)dy{ + // 视差效果 +} + +-(void) lv_effectClick:(NSInteger)color alpha:(CGFloat)alpha{ + // 点击特效 +} + +-(BOOL) lv_canvas{ + return NO; +} + +-(void) setLv_canvas:(BOOL)lv_canvas{ +} + +@end diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lapi.c b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lapi.c new file mode 100644 index 00000000..5d5145d2 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lapi.c @@ -0,0 +1,1087 @@ +/* +** $Id: lapi.c,v 2.55.1.5 2008/07/04 18:41:18 roberto Exp $ +** Lua API +** See Copyright Notice in lua.h +*/ + + +#include +#include +#include +#include + +#define lapi_c +#define LUA_CORE + +#include "lua.h" + +#include "lapi.h" +#include "ldebug.h" +#include "ldo.h" +#include "lfunc.h" +#include "lgc.h" +#include "lmem.h" +#include "lobject.h" +#include "lstate.h" +#include "lstring.h" +#include "ltable.h" +#include "ltm.h" +#include "lundump.h" +#include "lvm.h" + + + +const char lua_ident[] = + "$Lua: " LUA_RELEASE " " LUA_COPYRIGHT " $\n" + "$Authors: " LUA_AUTHORS " $\n" + "$URL: www.lua.org $\n"; + + + +#define api_checknelems(L, n) api_check(L, (n) <= (L->top - L->base)) + +#define api_checkvalidindex(L, i) api_check(L, (i) != luaO_nilobject) + +#define api_incr_top(L) {api_check(L, L->top < L->ci->top); L->top++;} + + + +static TValue *index2adr (lua_State *L, int idx) { + if (idx > 0) { + TValue *o = L->base + (idx - 1); + api_check(L, idx <= L->ci->top - L->base); + if (o >= L->top) return cast(TValue *, luaO_nilobject); + else return o; + } + else if (idx > LUA_REGISTRYINDEX) { + api_check(L, idx != 0 && -idx <= L->top - L->base); + return L->top + idx; + } + else switch (idx) { /* pseudo-indices */ + case LUA_REGISTRYINDEX: return registry(L); + case LUA_ENVIRONINDEX: { + Closure *func = curr_func(L); + sethvalue(L, &L->env, func->c.env); + return &L->env; + } + case LUA_GLOBALSINDEX: return gt(L); + default: { + Closure *func = curr_func(L); + idx = LUA_GLOBALSINDEX - idx; + return (idx <= func->c.nupvalues) + ? &func->c.upvalue[idx-1] + : cast(TValue *, luaO_nilobject); + } + } +} + + +static Table *getcurrenv (lua_State *L) { + if (L->ci == L->base_ci) /* no enclosing function? */ + return hvalue(gt(L)); /* use global table as environment */ + else { + Closure *func = curr_func(L); + return func->c.env; + } +} + + +void luaA_pushobject (lua_State *L, const TValue *o) { + setobj2s(L, L->top, o); + api_incr_top(L); +} + + +LUA_API int lua_checkstack (lua_State *L, int size) { + int res = 1; + lua_lock(L); + if (size > LUAI_MAXCSTACK || (L->top - L->base + size) > LUAI_MAXCSTACK) + res = 0; /* stack overflow */ + else if (size > 0) { + luaD_checkstack(L, size); + if (L->ci->top < L->top + size) + L->ci->top = L->top + size; + } + lua_unlock(L); + return res; +} + + +LUA_API void lua_xmove (lua_State *from, lua_State *to, int n) { + int i; + if (from == to) return; + lua_lock(to); + api_checknelems(from, n); + api_check(from, G(from) == G(to)); + api_check(from, to->ci->top - to->top >= n); + from->top -= n; + for (i = 0; i < n; i++) { + setobj2s(to, to->top++, from->top + i); + } + lua_unlock(to); +} + + +LUA_API void lua_setlevel (lua_State *from, lua_State *to) { + to->nCcalls = from->nCcalls; +} + + +LUA_API lua_CFunction lua_atpanic (lua_State *L, lua_CFunction panicf) { + lua_CFunction old; + lua_lock(L); + old = G(L)->panic; + G(L)->panic = panicf; + lua_unlock(L); + return old; +} + + +LUA_API lua_State *lua_newthread (lua_State *L) { + lua_State *L1; + lua_lock(L); + luaC_checkGC(L); + L1 = luaE_newthread(L); + setthvalue(L, L->top, L1); + api_incr_top(L); + lua_unlock(L); + luai_userstatethread(L, L1); + return L1; +} + + + +/* +** basic stack manipulation +*/ + + +LUA_API int lua_gettop (lua_State *L) { + return cast_int(L->top - L->base); +} + + +LUA_API void lua_settop (lua_State *L, int idx) { + lua_lock(L); + if (idx >= 0) { + api_check(L, idx <= L->stack_last - L->base); + while (L->top < L->base + idx) + setnilvalue(L->top++); + L->top = L->base + idx; + } + else { + api_check(L, -(idx+1) <= (L->top - L->base)); + L->top += idx+1; /* `subtract' index (index is negative) */ + } + lua_unlock(L); +} + + +LUA_API void lua_remove (lua_State *L, int idx) { + StkId p; + lua_lock(L); + p = index2adr(L, idx); + api_checkvalidindex(L, p); + while (++p < L->top) setobjs2s(L, p-1, p); + L->top--; + lua_unlock(L); +} + + +LUA_API void lua_insert (lua_State *L, int idx) { + StkId p; + StkId q; + lua_lock(L); + p = index2adr(L, idx); + api_checkvalidindex(L, p); + for (q = L->top; q>p; q--) setobjs2s(L, q, q-1); + setobjs2s(L, p, L->top); + lua_unlock(L); +} + + +LUA_API void lua_replace (lua_State *L, int idx) { + StkId o; + lua_lock(L); + /* explicit test for incompatible code */ + if (idx == LUA_ENVIRONINDEX && L->ci == L->base_ci) + luaG_runerror(L, "no calling environment"); + api_checknelems(L, 1); + o = index2adr(L, idx); + api_checkvalidindex(L, o); + if (idx == LUA_ENVIRONINDEX) { + Closure *func = curr_func(L); + api_check(L, ttistable(L->top - 1)); + func->c.env = hvalue(L->top - 1); + luaC_barrier(L, func, L->top - 1); + } + else { + setobj(L, o, L->top - 1); + if (idx < LUA_GLOBALSINDEX) /* function upvalue? */ + luaC_barrier(L, curr_func(L), L->top - 1); + } + L->top--; + lua_unlock(L); +} + + +LUA_API void lua_pushvalue (lua_State *L, int idx) { + lua_lock(L); + setobj2s(L, L->top, index2adr(L, idx)); + api_incr_top(L); + lua_unlock(L); +} + + + +/* +** access functions (stack -> C) +*/ + + +LUA_API int lua_type (lua_State *L, int idx) { + StkId o = index2adr(L, idx); + return (o == luaO_nilobject) ? LUA_TNONE : ttype(o); +} + + +LUA_API const char *lua_typename (lua_State *L, int t) { + UNUSED(L); + return (t == LUA_TNONE) ? "no value" : luaT_typenames[t]; +} + + +LUA_API int lua_iscfunction (lua_State *L, int idx) { + StkId o = index2adr(L, idx); + return iscfunction(o); +} + + +LUA_API int lua_isnumber (lua_State *L, int idx) { + TValue n; + const TValue *o = index2adr(L, idx); + return tonumber(o, &n); +} + + +LUA_API int lua_isstring (lua_State *L, int idx) { + int t = lua_type(L, idx); + return (t == LUA_TSTRING || t == LUA_TNUMBER); +} + + +LUA_API int lua_isuserdata (lua_State *L, int idx) { + const TValue *o = index2adr(L, idx); + return (ttisuserdata(o) || ttislightuserdata(o)); +} + + +LUA_API int lua_rawequal (lua_State *L, int index1, int index2) { + StkId o1 = index2adr(L, index1); + StkId o2 = index2adr(L, index2); + return (o1 == luaO_nilobject || o2 == luaO_nilobject) ? 0 + : luaO_rawequalObj(o1, o2); +} + + +LUA_API int lua_equal (lua_State *L, int index1, int index2) { + StkId o1, o2; + int i; + lua_lock(L); /* may call tag method */ + o1 = index2adr(L, index1); + o2 = index2adr(L, index2); + i = (o1 == luaO_nilobject || o2 == luaO_nilobject) ? 0 : equalobj(L, o1, o2); + lua_unlock(L); + return i; +} + + +LUA_API int lua_lessthan (lua_State *L, int index1, int index2) { + StkId o1, o2; + int i; + lua_lock(L); /* may call tag method */ + o1 = index2adr(L, index1); + o2 = index2adr(L, index2); + i = (o1 == luaO_nilobject || o2 == luaO_nilobject) ? 0 + : luaV_lessthan(L, o1, o2); + lua_unlock(L); + return i; +} + + + +LUA_API lua_Number lua_tonumber (lua_State *L, int idx) { + TValue n; + const TValue *o = index2adr(L, idx); + if (tonumber(o, &n)) + return nvalue(o); + else + return 0; +} + + +LUA_API lua_Integer lua_tointeger (lua_State *L, int idx) { + TValue n; + const TValue *o = index2adr(L, idx); + if (tonumber(o, &n)) { + lua_Integer res; + lua_Number num = nvalue(o); + lua_number2integer(res, num); + return res; + } + else + return 0; +} + + +LUA_API int lua_toboolean (lua_State *L, int idx) { + const TValue *o = index2adr(L, idx); + return !l_isfalse(o); +} + + +LUA_API const char *lua_tolstring (lua_State *L, int idx, size_t *len) { + StkId o = index2adr(L, idx); + if (!ttisstring(o)) { + lua_lock(L); /* `luaV_tostring' may create a new string */ + if (!luaV_tostring(L, o)) { /* conversion failed? */ + if (len != NULL) *len = 0; + lua_unlock(L); + return NULL; + } + luaC_checkGC(L); + o = index2adr(L, idx); /* previous call may reallocate the stack */ + lua_unlock(L); + } + if (len != NULL) *len = tsvalue(o)->len; + return svalue(o); +} + + +LUA_API size_t lua_objlen (lua_State *L, int idx) { + StkId o = index2adr(L, idx); + switch (ttype(o)) { + case LUA_TSTRING: return tsvalue(o)->len; + case LUA_TUSERDATA: return uvalue(o)->len; + case LUA_TTABLE: return luaH_getn(hvalue(o)); + case LUA_TNUMBER: { + size_t l; + lua_lock(L); /* `luaV_tostring' may create a new string */ + l = (luaV_tostring(L, o) ? tsvalue(o)->len : 0); + lua_unlock(L); + return l; + } + default: return 0; + } +} + + +LUA_API lua_CFunction lua_tocfunction (lua_State *L, int idx) { + StkId o = index2adr(L, idx); + return (!iscfunction(o)) ? NULL : clvalue(o)->c.f; +} + + +LUA_API void *lua_touserdata (lua_State *L, int idx) { + StkId o = index2adr(L, idx); + switch (ttype(o)) { + case LUA_TUSERDATA: return (rawuvalue(o) + 1); + case LUA_TLIGHTUSERDATA: return pvalue(o); + default: return NULL; + } +} + + +LUA_API lua_State *lua_tothread (lua_State *L, int idx) { + StkId o = index2adr(L, idx); + return (!ttisthread(o)) ? NULL : thvalue(o); +} + + +LUA_API const void *lua_topointer (lua_State *L, int idx) { + StkId o = index2adr(L, idx); + switch (ttype(o)) { + case LUA_TTABLE: return hvalue(o); + case LUA_TFUNCTION: return clvalue(o); + case LUA_TTHREAD: return thvalue(o); + case LUA_TUSERDATA: + case LUA_TLIGHTUSERDATA: + return lua_touserdata(L, idx); + default: return NULL; + } +} + + + +/* +** push functions (C -> stack) +*/ + + +LUA_API void lua_pushnil (lua_State *L) { + lua_lock(L); + setnilvalue(L->top); + api_incr_top(L); + lua_unlock(L); +} + + +LUA_API void lua_pushnumber (lua_State *L, lua_Number n) { + lua_lock(L); + setnvalue(L->top, n); + api_incr_top(L); + lua_unlock(L); +} + + +LUA_API void lua_pushinteger (lua_State *L, lua_Integer n) { + lua_lock(L); + setnvalue(L->top, cast_num(n)); + api_incr_top(L); + lua_unlock(L); +} + + +LUA_API void lua_pushlstring (lua_State *L, const char *s, size_t len) { + lua_lock(L); + luaC_checkGC(L); + setsvalue2s(L, L->top, luaS_newlstr(L, s, len)); + api_incr_top(L); + lua_unlock(L); +} + + +LUA_API void lua_pushstring (lua_State *L, const char *s) { + if (s == NULL) + lua_pushnil(L); + else + lua_pushlstring(L, s, strlen(s)); +} + + +LUA_API const char *lua_pushvfstring (lua_State *L, const char *fmt, + va_list argp) { + const char *ret; + lua_lock(L); + luaC_checkGC(L); + ret = luaO_pushvfstring(L, fmt, argp); + lua_unlock(L); + return ret; +} + + +LUA_API const char *lua_pushfstring (lua_State *L, const char *fmt, ...) { + const char *ret; + va_list argp; + lua_lock(L); + luaC_checkGC(L); + va_start(argp, fmt); + ret = luaO_pushvfstring(L, fmt, argp); + va_end(argp); + lua_unlock(L); + return ret; +} + + +LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) { + Closure *cl; + lua_lock(L); + luaC_checkGC(L); + api_checknelems(L, n); + cl = luaF_newCclosure(L, n, getcurrenv(L)); + cl->c.f = fn; + L->top -= n; + while (n--) + setobj2n(L, &cl->c.upvalue[n], L->top+n); + setclvalue(L, L->top, cl); + lua_assert(iswhite(obj2gco(cl))); + api_incr_top(L); + lua_unlock(L); +} + + +LUA_API void lua_pushboolean (lua_State *L, int b) { + lua_lock(L); + setbvalue(L->top, (b != 0)); /* ensure that true is 1 */ + api_incr_top(L); + lua_unlock(L); +} + + +LUA_API void lua_pushlightuserdata (lua_State *L, void *p) { + lua_lock(L); + setpvalue(L->top, p); + api_incr_top(L); + lua_unlock(L); +} + + +LUA_API int lua_pushthread (lua_State *L) { + lua_lock(L); + setthvalue(L, L->top, L); + api_incr_top(L); + lua_unlock(L); + return (G(L)->mainthread == L); +} + + + +/* +** get functions (Lua -> stack) +*/ + + +LUA_API void lua_gettable (lua_State *L, int idx) { + StkId t; + lua_lock(L); + t = index2adr(L, idx); + api_checkvalidindex(L, t); + luaV_gettable(L, t, L->top - 1, L->top - 1); + lua_unlock(L); +} + + +LUA_API void lua_getfield (lua_State *L, int idx, const char *k) { + StkId t; + TValue key; + lua_lock(L); + t = index2adr(L, idx); + api_checkvalidindex(L, t); + setsvalue(L, &key, luaS_new(L, k)); + luaV_gettable(L, t, &key, L->top); + api_incr_top(L); + lua_unlock(L); +} + + +LUA_API void lua_rawget (lua_State *L, int idx) { + StkId t; + lua_lock(L); + t = index2adr(L, idx); + api_check(L, ttistable(t)); + setobj2s(L, L->top - 1, luaH_get(hvalue(t), L->top - 1)); + lua_unlock(L); +} + + +LUA_API void lua_rawgeti (lua_State *L, int idx, int n) { + StkId o; + lua_lock(L); + o = index2adr(L, idx); + api_check(L, ttistable(o)); + setobj2s(L, L->top, luaH_getnum(hvalue(o), n)); + api_incr_top(L); + lua_unlock(L); +} + + +LUA_API void lua_createtable (lua_State *L, int narray, int nrec) { + lua_lock(L); + luaC_checkGC(L); + sethvalue(L, L->top, luaH_new(L, narray, nrec)); + api_incr_top(L); + lua_unlock(L); +} + + +LUA_API int lua_getmetatable (lua_State *L, int objindex) { + const TValue *obj; + Table *mt = NULL; + int res; + lua_lock(L); + obj = index2adr(L, objindex); + switch (ttype(obj)) { + case LUA_TTABLE: + mt = hvalue(obj)->metatable; + break; + case LUA_TUSERDATA: + mt = uvalue(obj)->metatable; + break; + default: + mt = G(L)->mt[ttype(obj)]; + break; + } + if (mt == NULL) + res = 0; + else { + sethvalue(L, L->top, mt); + api_incr_top(L); + res = 1; + } + lua_unlock(L); + return res; +} + + +LUA_API void lua_getfenv (lua_State *L, int idx) { + StkId o; + lua_lock(L); + o = index2adr(L, idx); + api_checkvalidindex(L, o); + switch (ttype(o)) { + case LUA_TFUNCTION: + sethvalue(L, L->top, clvalue(o)->c.env); + break; + case LUA_TUSERDATA: + sethvalue(L, L->top, uvalue(o)->env); + break; + case LUA_TTHREAD: + setobj2s(L, L->top, gt(thvalue(o))); + break; + default: + setnilvalue(L->top); + break; + } + api_incr_top(L); + lua_unlock(L); +} + + +/* +** set functions (stack -> Lua) +*/ + + +LUA_API void lua_settable (lua_State *L, int idx) { + StkId t; + lua_lock(L); + api_checknelems(L, 2); + t = index2adr(L, idx); + api_checkvalidindex(L, t); + luaV_settable(L, t, L->top - 2, L->top - 1); + L->top -= 2; /* pop index and value */ + lua_unlock(L); +} + + +LUA_API void lua_setfield (lua_State *L, int idx, const char *k) { + StkId t; + TValue key; + lua_lock(L); + api_checknelems(L, 1); + t = index2adr(L, idx); + api_checkvalidindex(L, t); + setsvalue(L, &key, luaS_new(L, k)); + luaV_settable(L, t, &key, L->top - 1); + L->top--; /* pop value */ + lua_unlock(L); +} + + +LUA_API void lua_rawset (lua_State *L, int idx) { + StkId t; + lua_lock(L); + api_checknelems(L, 2); + t = index2adr(L, idx); + api_check(L, ttistable(t)); + setobj2t(L, luaH_set(L, hvalue(t), L->top-2), L->top-1); + luaC_barriert(L, hvalue(t), L->top-1); + L->top -= 2; + lua_unlock(L); +} + + +LUA_API void lua_rawseti (lua_State *L, int idx, int n) { + StkId o; + lua_lock(L); + api_checknelems(L, 1); + o = index2adr(L, idx); + api_check(L, ttistable(o)); + setobj2t(L, luaH_setnum(L, hvalue(o), n), L->top-1); + luaC_barriert(L, hvalue(o), L->top-1); + L->top--; + lua_unlock(L); +} + + +LUA_API int lua_setmetatable (lua_State *L, int objindex) { + TValue *obj; + Table *mt; + lua_lock(L); + api_checknelems(L, 1); + obj = index2adr(L, objindex); + api_checkvalidindex(L, obj); + if (ttisnil(L->top - 1)) + mt = NULL; + else { + api_check(L, ttistable(L->top - 1)); + mt = hvalue(L->top - 1); + } + switch (ttype(obj)) { + case LUA_TTABLE: { + hvalue(obj)->metatable = mt; + if (mt) + luaC_objbarriert(L, hvalue(obj), mt); + break; + } + case LUA_TUSERDATA: { + uvalue(obj)->metatable = mt; + if (mt) + luaC_objbarrier(L, rawuvalue(obj), mt); + break; + } + default: { + G(L)->mt[ttype(obj)] = mt; + break; + } + } + L->top--; + lua_unlock(L); + return 1; +} + + +LUA_API int lua_setfenv (lua_State *L, int idx) { + StkId o; + int res = 1; + lua_lock(L); + api_checknelems(L, 1); + o = index2adr(L, idx); + api_checkvalidindex(L, o); + api_check(L, ttistable(L->top - 1)); + switch (ttype(o)) { + case LUA_TFUNCTION: + clvalue(o)->c.env = hvalue(L->top - 1); + break; + case LUA_TUSERDATA: + uvalue(o)->env = hvalue(L->top - 1); + break; + case LUA_TTHREAD: + sethvalue(L, gt(thvalue(o)), hvalue(L->top - 1)); + break; + default: + res = 0; + break; + } + if (res) luaC_objbarrier(L, gcvalue(o), hvalue(L->top - 1)); + L->top--; + lua_unlock(L); + return res; +} + + +/* +** `load' and `call' functions (run Lua code) +*/ + + +#define adjustresults(L,nres) \ + { if (nres == LUA_MULTRET && L->top >= L->ci->top) L->ci->top = L->top; } + + +#define checkresults(L,na,nr) \ + api_check(L, (nr) == LUA_MULTRET || (L->ci->top - L->top >= (nr) - (na))) + + +LUA_API void lua_call (lua_State *L, int nargs, int nresults) { + StkId func; + lua_lock(L); + api_checknelems(L, nargs+1); + checkresults(L, nargs, nresults); + func = L->top - (nargs+1); + luaD_call(L, func, nresults); + adjustresults(L, nresults); + lua_unlock(L); +} + + + +/* +** Execute a protected call. +*/ +struct CallS { /* data to `f_call' */ + StkId func; + int nresults; +}; + + +static void f_call (lua_State *L, void *ud) { + struct CallS *c = cast(struct CallS *, ud); + luaD_call(L, c->func, c->nresults); +} + + + +LUA_API int lua_pcall (lua_State *L, int nargs, int nresults, int errfunc) { + struct CallS c; + int status; + ptrdiff_t func; + lua_lock(L); + api_checknelems(L, nargs+1); + checkresults(L, nargs, nresults); + if (errfunc == 0) + func = 0; + else { + StkId o = index2adr(L, errfunc); + api_checkvalidindex(L, o); + func = savestack(L, o); + } + c.func = L->top - (nargs+1); /* function to be called */ + c.nresults = nresults; + status = luaD_pcall(L, f_call, &c, savestack(L, c.func), func); + adjustresults(L, nresults); + lua_unlock(L); + return status; +} + + +/* +** Execute a protected C call. +*/ +struct CCallS { /* data to `f_Ccall' */ + lua_CFunction func; + void *ud; +}; + + +static void f_Ccall (lua_State *L, void *ud) { + struct CCallS *c = cast(struct CCallS *, ud); + Closure *cl; + cl = luaF_newCclosure(L, 0, getcurrenv(L)); + cl->c.f = c->func; + setclvalue(L, L->top, cl); /* push function */ + api_incr_top(L); + setpvalue(L->top, c->ud); /* push only argument */ + api_incr_top(L); + luaD_call(L, L->top - 2, 0); +} + + +LUA_API int lua_cpcall (lua_State *L, lua_CFunction func, void *ud) { + struct CCallS c; + int status; + lua_lock(L); + c.func = func; + c.ud = ud; + status = luaD_pcall(L, f_Ccall, &c, savestack(L, L->top), 0); + lua_unlock(L); + return status; +} + + +LUA_API int lua_load (lua_State *L, lua_Reader reader, void *data, + const char *chunkname) { + ZIO z; + int status; + lua_lock(L); + if (!chunkname) chunkname = "?"; + luaZ_init(L, &z, reader, data); + status = luaD_protectedparser(L, &z, chunkname); + lua_unlock(L); + return status; +} + + +LUA_API int lua_dump (lua_State *L, lua_Writer writer, void *data) { + int status; + TValue *o; + lua_lock(L); + api_checknelems(L, 1); + o = L->top - 1; + if (isLfunction(o)) + status = luaU_dump(L, clvalue(o)->l.p, writer, data, 0); + else + status = 1; + lua_unlock(L); + return status; +} + + +LUA_API int lua_status (lua_State *L) { + return L->status; +} + + +/* +** Garbage-collection function +*/ + +LUA_API int lua_gc (lua_State *L, int what, int data) { + int res = 0; + global_State *g; + lua_lock(L); + g = G(L); + switch (what) { + case LUA_GCSTOP: { + g->GCthreshold = MAX_LUMEM; + break; + } + case LUA_GCRESTART: { + g->GCthreshold = g->totalbytes; + break; + } + case LUA_GCCOLLECT: { + luaC_fullgc(L); + break; + } + case LUA_GCCOUNT: { + /* GC values are expressed in Kbytes: #bytes/2^10 */ + res = cast_int(g->totalbytes >> 10); + break; + } + case LUA_GCCOUNTB: { + res = cast_int(g->totalbytes & 0x3ff); + break; + } + case LUA_GCSTEP: { + lu_mem a = (cast(lu_mem, data) << 10); + if (a <= g->totalbytes) + g->GCthreshold = g->totalbytes - a; + else + g->GCthreshold = 0; + while (g->GCthreshold <= g->totalbytes) { + luaC_step(L); + if (g->gcstate == GCSpause) { /* end of cycle? */ + res = 1; /* signal it */ + break; + } + } + break; + } + case LUA_GCSETPAUSE: { + res = g->gcpause; + g->gcpause = data; + break; + } + case LUA_GCSETSTEPMUL: { + res = g->gcstepmul; + g->gcstepmul = data; + break; + } + default: res = -1; /* invalid option */ + } + lua_unlock(L); + return res; +} + + + +/* +** miscellaneous functions +*/ + + +LUA_API int lua_error (lua_State *L) { + lua_lock(L); + api_checknelems(L, 1); + luaG_errormsg(L); + lua_unlock(L); + return 0; /* to avoid warnings */ +} + + +LUA_API int lua_next (lua_State *L, int idx) { + StkId t; + int more; + lua_lock(L); + t = index2adr(L, idx); + api_check(L, ttistable(t)); + more = luaH_next(L, hvalue(t), L->top - 1); + if (more) { + api_incr_top(L); + } + else /* no more elements */ + L->top -= 1; /* remove key */ + lua_unlock(L); + return more; +} + + +LUA_API void lua_concat (lua_State *L, int n) { + lua_lock(L); + api_checknelems(L, n); + if (n >= 2) { + luaC_checkGC(L); + luaV_concat(L, n, cast_int(L->top - L->base) - 1); + L->top -= (n-1); + } + else if (n == 0) { /* push empty string */ + setsvalue2s(L, L->top, luaS_newlstr(L, "", 0)); + api_incr_top(L); + } + /* else n == 1; nothing to do */ + lua_unlock(L); +} + + +LUA_API lua_Alloc lua_getallocf (lua_State *L, void **ud) { + lua_Alloc f; + lua_lock(L); + if (ud) *ud = G(L)->ud; + f = G(L)->frealloc; + lua_unlock(L); + return f; +} + + +LUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud) { + lua_lock(L); + G(L)->ud = ud; + G(L)->frealloc = f; + lua_unlock(L); +} + + +LUA_API void *lua_newuserdata (lua_State *L, size_t size) { + Udata *u; + lua_lock(L); + luaC_checkGC(L); + u = luaS_newudata(L, size, getcurrenv(L)); + setuvalue(L, L->top, u); + api_incr_top(L); + lua_unlock(L); + return u + 1; +} + + + + +static const char *aux_upvalue (StkId fi, int n, TValue **val) { + Closure *f; + if (!ttisfunction(fi)) return NULL; + f = clvalue(fi); + if (f->c.isC) { + if (!(1 <= n && n <= f->c.nupvalues)) return NULL; + *val = &f->c.upvalue[n-1]; + return ""; + } + else { + Proto *p = f->l.p; + if (!(1 <= n && n <= p->sizeupvalues)) return NULL; + *val = f->l.upvals[n-1]->v; + return getstr(p->upvalues[n-1]); + } +} + + +LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n) { + const char *name; + TValue *val; + lua_lock(L); + name = aux_upvalue(index2adr(L, funcindex), n, &val); + if (name) { + setobj2s(L, L->top, val); + api_incr_top(L); + } + lua_unlock(L); + return name; +} + + +LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n) { + const char *name; + TValue *val; + StkId fi; + lua_lock(L); + fi = index2adr(L, funcindex); + api_checknelems(L, 1); + name = aux_upvalue(fi, n, &val); + if (name) { + L->top--; + setobj(L, val, L->top); + luaC_barrier(L, clvalue(fi), L->top); + } + lua_unlock(L); + return name; +} + diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lapi.h b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lapi.h new file mode 100644 index 00000000..2c3fab24 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lapi.h @@ -0,0 +1,16 @@ +/* +** $Id: lapi.h,v 2.2.1.1 2007/12/27 13:02:25 roberto Exp $ +** Auxiliary functions from Lua API +** See Copyright Notice in lua.h +*/ + +#ifndef lapi_h +#define lapi_h + + +#include "lobject.h" + + +LUAI_FUNC void luaA_pushobject (lua_State *L, const TValue *o); + +#endif diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lauxlib.c b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lauxlib.c new file mode 100644 index 00000000..10f14e2c --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lauxlib.c @@ -0,0 +1,652 @@ +/* +** $Id: lauxlib.c,v 1.159.1.3 2008/01/21 13:20:51 roberto Exp $ +** Auxiliary functions for building Lua libraries +** See Copyright Notice in lua.h +*/ + + +#include +#include +#include +#include +#include +#include + + +/* This file uses only the official API of Lua. +** Any function declared here could be written as an application function. +*/ + +#define lauxlib_c +#define LUA_LIB + +#include "lua.h" + +#include "lauxlib.h" + + +#define FREELIST_REF 0 /* free list of references */ + + +/* convert a stack index to positive */ +#define abs_index(L, i) ((i) > 0 || (i) <= LUA_REGISTRYINDEX ? (i) : \ + lua_gettop(L) + (i) + 1) + + +/* +** {====================================================== +** Error-report functions +** ======================================================= +*/ + + +LUALIB_API int luaL_argerror (lua_State *L, int narg, const char *extramsg) { + lua_Debug ar; + if (!lua_getstack(L, 0, &ar)) /* no stack frame? */ + return luaL_error(L, "bad argument #%d (%s)", narg, extramsg); + lua_getinfo(L, "n", &ar); + if (strcmp(ar.namewhat, "method") == 0) { + narg--; /* do not count `self' */ + if (narg == 0) /* error is in the self argument itself? */ + return luaL_error(L, "calling " LUA_QS " on bad self (%s)", + ar.name, extramsg); + } + if (ar.name == NULL) + ar.name = "?"; + return luaL_error(L, "bad argument #%d to " LUA_QS " (%s)", + narg, ar.name, extramsg); +} + + +LUALIB_API int luaL_typerror (lua_State *L, int narg, const char *tname) { + const char *msg = lua_pushfstring(L, "%s expected, got %s", + tname, luaL_typename(L, narg)); + return luaL_argerror(L, narg, msg); +} + + +static void tag_error (lua_State *L, int narg, int tag) { + luaL_typerror(L, narg, lua_typename(L, tag)); +} + + +LUALIB_API void luaL_where (lua_State *L, int level) { + lua_Debug ar; + if (lua_getstack(L, level, &ar)) { /* check function at level */ + lua_getinfo(L, "Sl", &ar); /* get info about it */ + if (ar.currentline > 0) { /* is there info? */ + lua_pushfstring(L, "%s:%d: ", ar.short_src, ar.currentline); + return; + } + } + lua_pushliteral(L, ""); /* else, no information available... */ +} + + +LUALIB_API int luaL_error (lua_State *L, const char *fmt, ...) { + va_list argp; + va_start(argp, fmt); + luaL_where(L, 1); + lua_pushvfstring(L, fmt, argp); + va_end(argp); + lua_concat(L, 2); + return lua_error(L); +} + +/* }====================================================== */ + + +LUALIB_API int luaL_checkoption (lua_State *L, int narg, const char *def, + const char *const lst[]) { + const char *name = (def) ? luaL_optstring(L, narg, def) : + luaL_checkstring(L, narg); + int i; + for (i=0; lst[i]; i++) + if (strcmp(lst[i], name) == 0) + return i; + return luaL_argerror(L, narg, + lua_pushfstring(L, "invalid option " LUA_QS, name)); +} + + +LUALIB_API int luaL_newmetatable (lua_State *L, const char *tname) { + lua_getfield(L, LUA_REGISTRYINDEX, tname); /* get registry.name */ + if (!lua_isnil(L, -1)) /* name already in use? */ + return 0; /* leave previous value on top, but return 0 */ + lua_pop(L, 1); + lua_newtable(L); /* create metatable */ + lua_pushvalue(L, -1); + lua_setfield(L, LUA_REGISTRYINDEX, tname); /* registry.name = metatable */ + return 1; +} + + +LUALIB_API void *luaL_checkudata (lua_State *L, int ud, const char *tname) { + void *p = lua_touserdata(L, ud); + if (p != NULL) { /* value is a userdata? */ + if (lua_getmetatable(L, ud)) { /* does it have a metatable? */ + lua_getfield(L, LUA_REGISTRYINDEX, tname); /* get correct metatable */ + if (lua_rawequal(L, -1, -2)) { /* does it have the correct mt? */ + lua_pop(L, 2); /* remove both metatables */ + return p; + } + } + } + luaL_typerror(L, ud, tname); /* else error */ + return NULL; /* to avoid warnings */ +} + + +LUALIB_API void luaL_checkstack (lua_State *L, int space, const char *mes) { + if (!lua_checkstack(L, space)) + luaL_error(L, "stack overflow (%s)", mes); +} + + +LUALIB_API void luaL_checktype (lua_State *L, int narg, int t) { + if (lua_type(L, narg) != t) + tag_error(L, narg, t); +} + + +LUALIB_API void luaL_checkany (lua_State *L, int narg) { + if (lua_type(L, narg) == LUA_TNONE) + luaL_argerror(L, narg, "value expected"); +} + + +LUALIB_API const char *luaL_checklstring (lua_State *L, int narg, size_t *len) { + const char *s = lua_tolstring(L, narg, len); + if (!s) tag_error(L, narg, LUA_TSTRING); + return s; +} + + +LUALIB_API const char *luaL_optlstring (lua_State *L, int narg, + const char *def, size_t *len) { + if (lua_isnoneornil(L, narg)) { + if (len) + *len = (def ? strlen(def) : 0); + return def; + } + else return luaL_checklstring(L, narg, len); +} + + +LUALIB_API lua_Number luaL_checknumber (lua_State *L, int narg) { + lua_Number d = lua_tonumber(L, narg); + if (d == 0 && !lua_isnumber(L, narg)) /* avoid extra test when d is not 0 */ + tag_error(L, narg, LUA_TNUMBER); + return d; +} + + +LUALIB_API lua_Number luaL_optnumber (lua_State *L, int narg, lua_Number def) { + return luaL_opt(L, luaL_checknumber, narg, def); +} + + +LUALIB_API lua_Integer luaL_checkinteger (lua_State *L, int narg) { + lua_Integer d = lua_tointeger(L, narg); + if (d == 0 && !lua_isnumber(L, narg)) /* avoid extra test when d is not 0 */ + tag_error(L, narg, LUA_TNUMBER); + return d; +} + + +LUALIB_API lua_Integer luaL_optinteger (lua_State *L, int narg, + lua_Integer def) { + return luaL_opt(L, luaL_checkinteger, narg, def); +} + + +LUALIB_API int luaL_getmetafield (lua_State *L, int obj, const char *event) { + if (!lua_getmetatable(L, obj)) /* no metatable? */ + return 0; + lua_pushstring(L, event); + lua_rawget(L, -2); + if (lua_isnil(L, -1)) { + lua_pop(L, 2); /* remove metatable and metafield */ + return 0; + } + else { + lua_remove(L, -2); /* remove only metatable */ + return 1; + } +} + + +LUALIB_API int luaL_callmeta (lua_State *L, int obj, const char *event) { + obj = abs_index(L, obj); + if (!luaL_getmetafield(L, obj, event)) /* no metafield? */ + return 0; + lua_pushvalue(L, obj); + lua_call(L, 1, 1); + return 1; +} + + +LUALIB_API void (luaL_register) (lua_State *L, const char *libname, + const luaL_Reg *l) { + luaI_openlib(L, libname, l, 0); +} + + +static int libsize (const luaL_Reg *l) { + int size = 0; + for (; l->name; l++) size++; + return size; +} + + +LUALIB_API void luaI_openlib (lua_State *L, const char *libname, + const luaL_Reg *l, int nup) { + if (libname) { + int size = libsize(l); + /* check whether lib already exists */ + luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 1); + lua_getfield(L, -1, libname); /* get _LOADED[libname] */ + if (!lua_istable(L, -1)) { /* not found? */ + lua_pop(L, 1); /* remove previous result */ + /* try global variable (and create one if it does not exist) */ + if (luaL_findtable(L, LUA_GLOBALSINDEX, libname, size) != NULL) + luaL_error(L, "name conflict for module " LUA_QS, libname); + lua_pushvalue(L, -1); + lua_setfield(L, -3, libname); /* _LOADED[libname] = new table */ + } + lua_remove(L, -2); /* remove _LOADED table */ + lua_insert(L, -(nup+1)); /* move library table to below upvalues */ + } + for (; l->name; l++) { + int i; + for (i=0; ifunc, nup); + lua_setfield(L, -(nup+2), l->name); + } + lua_pop(L, nup); /* remove upvalues */ +} + + + +/* +** {====================================================== +** getn-setn: size for arrays +** ======================================================= +*/ + +#if defined(LUA_COMPAT_GETN) + +static int checkint (lua_State *L, int topop) { + int n = (lua_type(L, -1) == LUA_TNUMBER) ? lua_tointeger(L, -1) : -1; + lua_pop(L, topop); + return n; +} + + +static void getsizes (lua_State *L) { + lua_getfield(L, LUA_REGISTRYINDEX, "LUA_SIZES"); + if (lua_isnil(L, -1)) { /* no `size' table? */ + lua_pop(L, 1); /* remove nil */ + lua_newtable(L); /* create it */ + lua_pushvalue(L, -1); /* `size' will be its own metatable */ + lua_setmetatable(L, -2); + lua_pushliteral(L, "kv"); + lua_setfield(L, -2, "__mode"); /* metatable(N).__mode = "kv" */ + lua_pushvalue(L, -1); + lua_setfield(L, LUA_REGISTRYINDEX, "LUA_SIZES"); /* store in register */ + } +} + + +LUALIB_API void luaL_setn (lua_State *L, int t, int n) { + t = abs_index(L, t); + lua_pushliteral(L, "n"); + lua_rawget(L, t); + if (checkint(L, 1) >= 0) { /* is there a numeric field `n'? */ + lua_pushliteral(L, "n"); /* use it */ + lua_pushinteger(L, n); + lua_rawset(L, t); + } + else { /* use `sizes' */ + getsizes(L); + lua_pushvalue(L, t); + lua_pushinteger(L, n); + lua_rawset(L, -3); /* sizes[t] = n */ + lua_pop(L, 1); /* remove `sizes' */ + } +} + + +LUALIB_API int luaL_getn (lua_State *L, int t) { + int n; + t = abs_index(L, t); + lua_pushliteral(L, "n"); /* try t.n */ + lua_rawget(L, t); + if ((n = checkint(L, 1)) >= 0) return n; + getsizes(L); /* else try sizes[t] */ + lua_pushvalue(L, t); + lua_rawget(L, -2); + if ((n = checkint(L, 2)) >= 0) return n; + return (int)lua_objlen(L, t); +} + +#endif + +/* }====================================================== */ + + + +LUALIB_API const char *luaL_gsub (lua_State *L, const char *s, const char *p, + const char *r) { + const char *wild; + size_t l = strlen(p); + luaL_Buffer b; + luaL_buffinit(L, &b); + while ((wild = strstr(s, p)) != NULL) { + luaL_addlstring(&b, s, wild - s); /* push prefix */ + luaL_addstring(&b, r); /* push replacement in place of pattern */ + s = wild + l; /* continue after `p' */ + } + luaL_addstring(&b, s); /* push last suffix */ + luaL_pushresult(&b); + return lua_tostring(L, -1); +} + + +LUALIB_API const char *luaL_findtable (lua_State *L, int idx, + const char *fname, int szhint) { + const char *e; + lua_pushvalue(L, idx); + do { + e = strchr(fname, '.'); + if (e == NULL) e = fname + strlen(fname); + lua_pushlstring(L, fname, e - fname); + lua_rawget(L, -2); + if (lua_isnil(L, -1)) { /* no such field? */ + lua_pop(L, 1); /* remove this nil */ + lua_createtable(L, 0, (*e == '.' ? 1 : szhint)); /* new table for field */ + lua_pushlstring(L, fname, e - fname); + lua_pushvalue(L, -2); + lua_settable(L, -4); /* set new table into field */ + } + else if (!lua_istable(L, -1)) { /* field has a non-table value? */ + lua_pop(L, 2); /* remove table and value */ + return fname; /* return problematic part of the name */ + } + lua_remove(L, -2); /* remove previous table */ + fname = e + 1; + } while (*e == '.'); + return NULL; +} + + + +/* +** {====================================================== +** Generic Buffer manipulation +** ======================================================= +*/ + + +#define bufflen(B) ((B)->p - (B)->buffer) +#define bufffree(B) ((size_t)(LUAL_BUFFERSIZE - bufflen(B))) + +#define LIMIT (LUA_MINSTACK/2) + + +static int emptybuffer (luaL_Buffer *B) { + size_t l = bufflen(B); + if (l == 0) return 0; /* put nothing on stack */ + else { + lua_pushlstring(B->L, B->buffer, l); + B->p = B->buffer; + B->lvl++; + return 1; + } +} + + +static void adjuststack (luaL_Buffer *B) { + if (B->lvl > 1) { + lua_State *L = B->L; + int toget = 1; /* number of levels to concat */ + size_t toplen = lua_strlen(L, -1); + do { + size_t l = lua_strlen(L, -(toget+1)); + if (B->lvl - toget + 1 >= LIMIT || toplen > l) { + toplen += l; + toget++; + } + else break; + } while (toget < B->lvl); + lua_concat(L, toget); + B->lvl = B->lvl - toget + 1; + } +} + + +LUALIB_API char *luaL_prepbuffer (luaL_Buffer *B) { + if (emptybuffer(B)) + adjuststack(B); + return B->buffer; +} + + +LUALIB_API void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l) { + while (l--) + luaL_addchar(B, *s++); +} + + +LUALIB_API void luaL_addstring (luaL_Buffer *B, const char *s) { + luaL_addlstring(B, s, strlen(s)); +} + + +LUALIB_API void luaL_pushresult (luaL_Buffer *B) { + emptybuffer(B); + lua_concat(B->L, B->lvl); + B->lvl = 1; +} + + +LUALIB_API void luaL_addvalue (luaL_Buffer *B) { + lua_State *L = B->L; + size_t vl; + const char *s = lua_tolstring(L, -1, &vl); + if (vl <= bufffree(B)) { /* fit into buffer? */ + memcpy(B->p, s, vl); /* put it there */ + B->p += vl; + lua_pop(L, 1); /* remove from stack */ + } + else { + if (emptybuffer(B)) + lua_insert(L, -2); /* put buffer before new value */ + B->lvl++; /* add new value into B stack */ + adjuststack(B); + } +} + + +LUALIB_API void luaL_buffinit (lua_State *L, luaL_Buffer *B) { + B->L = L; + B->p = B->buffer; + B->lvl = 0; +} + +/* }====================================================== */ + + +LUALIB_API int luaL_ref (lua_State *L, int t) { + int ref; + t = abs_index(L, t); + if (lua_isnil(L, -1)) { + lua_pop(L, 1); /* remove from stack */ + return LUA_REFNIL; /* `nil' has a unique fixed reference */ + } + lua_rawgeti(L, t, FREELIST_REF); /* get first free element */ + ref = (int)lua_tointeger(L, -1); /* ref = t[FREELIST_REF] */ + lua_pop(L, 1); /* remove it from stack */ + if (ref != 0) { /* any free element? */ + lua_rawgeti(L, t, ref); /* remove it from list */ + lua_rawseti(L, t, FREELIST_REF); /* (t[FREELIST_REF] = t[ref]) */ + } + else { /* no free elements */ + ref = (int)lua_objlen(L, t); + ref++; /* create new reference */ + } + lua_rawseti(L, t, ref); + return ref; +} + + +LUALIB_API void luaL_unref (lua_State *L, int t, int ref) { + if (ref >= 0) { + t = abs_index(L, t); + lua_rawgeti(L, t, FREELIST_REF); + lua_rawseti(L, t, ref); /* t[ref] = t[FREELIST_REF] */ + lua_pushinteger(L, ref); + lua_rawseti(L, t, FREELIST_REF); /* t[FREELIST_REF] = ref */ + } +} + + + +/* +** {====================================================== +** Load functions +** ======================================================= +*/ + +typedef struct LoadF { + int extraline; + FILE *f; + char buff[LUAL_BUFFERSIZE]; +} LoadF; + + +static const char *getF (lua_State *L, void *ud, size_t *size) { + LoadF *lf = (LoadF *)ud; + (void)L; + if (lf->extraline) { + lf->extraline = 0; + *size = 1; + return "\n"; + } + if (feof(lf->f)) return NULL; + *size = fread(lf->buff, 1, sizeof(lf->buff), lf->f); + return (*size > 0) ? lf->buff : NULL; +} + + +static int errfile (lua_State *L, const char *what, int fnameindex) { + const char *serr = strerror(errno); + const char *filename = lua_tostring(L, fnameindex) + 1; + lua_pushfstring(L, "cannot %s %s: %s", what, filename, serr); + lua_remove(L, fnameindex); + return LUA_ERRFILE; +} + + +LUALIB_API int luaL_loadfile (lua_State *L, const char *filename) { + LoadF lf; + int status, readstatus; + int c; + int fnameindex = lua_gettop(L) + 1; /* index of filename on the stack */ + lf.extraline = 0; + if (filename == NULL) { + lua_pushliteral(L, "=stdin"); + lf.f = stdin; + } + else { + lua_pushfstring(L, "@%s", filename); + lf.f = fopen(filename, "r"); + if (lf.f == NULL) return errfile(L, "open", fnameindex); + } + c = getc(lf.f); + if (c == '#') { /* Unix exec. file? */ + lf.extraline = 1; + while ((c = getc(lf.f)) != EOF && c != '\n') ; /* skip first line */ + if (c == '\n') c = getc(lf.f); + } + if (c == LUA_SIGNATURE[0] && filename) { /* binary file? */ + lf.f = freopen(filename, "rb", lf.f); /* reopen in binary mode */ + if (lf.f == NULL) return errfile(L, "reopen", fnameindex); + /* skip eventual `#!...' */ + while ((c = getc(lf.f)) != EOF && c != LUA_SIGNATURE[0]) ; + lf.extraline = 0; + } + ungetc(c, lf.f); + status = lua_load(L, getF, &lf, lua_tostring(L, -1)); + readstatus = ferror(lf.f); + if (filename) fclose(lf.f); /* close file (even in case of errors) */ + if (readstatus) { + lua_settop(L, fnameindex); /* ignore results from `lua_load' */ + return errfile(L, "read", fnameindex); + } + lua_remove(L, fnameindex); + return status; +} + + +typedef struct LoadS { + const char *s; + size_t size; +} LoadS; + + +static const char *getS (lua_State *L, void *ud, size_t *size) { + LoadS *ls = (LoadS *)ud; + (void)L; + if (ls->size == 0) return NULL; + *size = ls->size; + ls->size = 0; + return ls->s; +} + + +LUALIB_API int luaL_loadbuffer (lua_State *L, const char *buff, size_t size, + const char *name) { + LoadS ls; + ls.s = buff; + ls.size = size; + return lua_load(L, getS, &ls, name); +} + + +LUALIB_API int (luaL_loadstring) (lua_State *L, const char *s) { + return luaL_loadbuffer(L, s, strlen(s), s); +} + + + +/* }====================================================== */ + + +static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) { + (void)ud; + (void)osize; + if (nsize == 0) { + free(ptr); + return NULL; + } + else + return realloc(ptr, nsize); +} + + +static int panic (lua_State *L) { + (void)L; /* to avoid warnings */ + fprintf(stderr, "PANIC: unprotected error in call to Lua API (%s)\n", + lua_tostring(L, -1)); + return 0; +} + + +LUALIB_API lua_State *luaL_newstate (void) { + lua_State *L = lua_newstate(l_alloc, NULL); + if (L) lua_atpanic(L, &panic); + return L; +} + diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lauxlib.h b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lauxlib.h new file mode 100644 index 00000000..34258235 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lauxlib.h @@ -0,0 +1,174 @@ +/* +** $Id: lauxlib.h,v 1.88.1.1 2007/12/27 13:02:25 roberto Exp $ +** Auxiliary functions for building Lua libraries +** See Copyright Notice in lua.h +*/ + + +#ifndef lauxlib_h +#define lauxlib_h + + +#include +#include + +#include "lua.h" + + +#if defined(LUA_COMPAT_GETN) +LUALIB_API int (luaL_getn) (lua_State *L, int t); +LUALIB_API void (luaL_setn) (lua_State *L, int t, int n); +#else +#define luaL_getn(L,i) ((int)lua_objlen(L, i)) +#define luaL_setn(L,i,j) ((void)0) /* no op! */ +#endif + +#if defined(LUA_COMPAT_OPENLIB) +#define luaI_openlib luaL_openlib +#endif + + +/* extra error code for `luaL_load' */ +#define LUA_ERRFILE (LUA_ERRERR+1) + + +typedef struct luaL_Reg { + const char *name; + lua_CFunction func; +} luaL_Reg; + + + +LUALIB_API void (luaI_openlib) (lua_State *L, const char *libname, + const luaL_Reg *l, int nup); +LUALIB_API void (luaL_register) (lua_State *L, const char *libname, + const luaL_Reg *l); +LUALIB_API int (luaL_getmetafield) (lua_State *L, int obj, const char *e); +LUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e); +LUALIB_API int (luaL_typerror) (lua_State *L, int narg, const char *tname); +LUALIB_API int (luaL_argerror) (lua_State *L, int numarg, const char *extramsg); +LUALIB_API const char *(luaL_checklstring) (lua_State *L, int numArg, + size_t *l); +LUALIB_API const char *(luaL_optlstring) (lua_State *L, int numArg, + const char *def, size_t *l); +LUALIB_API lua_Number (luaL_checknumber) (lua_State *L, int numArg); +LUALIB_API lua_Number (luaL_optnumber) (lua_State *L, int nArg, lua_Number def); + +LUALIB_API lua_Integer (luaL_checkinteger) (lua_State *L, int numArg); +LUALIB_API lua_Integer (luaL_optinteger) (lua_State *L, int nArg, + lua_Integer def); + +LUALIB_API void (luaL_checkstack) (lua_State *L, int sz, const char *msg); +LUALIB_API void (luaL_checktype) (lua_State *L, int narg, int t); +LUALIB_API void (luaL_checkany) (lua_State *L, int narg); + +LUALIB_API int (luaL_newmetatable) (lua_State *L, const char *tname); +LUALIB_API void *(luaL_checkudata) (lua_State *L, int ud, const char *tname); + +LUALIB_API void (luaL_where) (lua_State *L, int lvl); +LUALIB_API int (luaL_error) (lua_State *L, const char *fmt, ...); + +LUALIB_API int (luaL_checkoption) (lua_State *L, int narg, const char *def, + const char *const lst[]); + +LUALIB_API int (luaL_ref) (lua_State *L, int t); +LUALIB_API void (luaL_unref) (lua_State *L, int t, int ref); + +LUALIB_API int (luaL_loadfile) (lua_State *L, const char *filename); +LUALIB_API int (luaL_loadbuffer) (lua_State *L, const char *buff, size_t sz, + const char *name); +LUALIB_API int (luaL_loadstring) (lua_State *L, const char *s); + +LUALIB_API lua_State *(luaL_newstate) (void); + + +LUALIB_API const char *(luaL_gsub) (lua_State *L, const char *s, const char *p, + const char *r); + +LUALIB_API const char *(luaL_findtable) (lua_State *L, int idx, + const char *fname, int szhint); + + + + +/* +** =============================================================== +** some useful macros +** =============================================================== +*/ + +#define luaL_argcheck(L, cond,numarg,extramsg) \ + ((void)((cond) || luaL_argerror(L, (numarg), (extramsg)))) +#define luaL_checkstring(L,n) (luaL_checklstring(L, (n), NULL)) +#define luaL_optstring(L,n,d) (luaL_optlstring(L, (n), (d), NULL)) +#define luaL_checkint(L,n) ((int)luaL_checkinteger(L, (n))) +#define luaL_optint(L,n,d) ((int)luaL_optinteger(L, (n), (d))) +#define luaL_checklong(L,n) ((long)luaL_checkinteger(L, (n))) +#define luaL_optlong(L,n,d) ((long)luaL_optinteger(L, (n), (d))) + +#define luaL_typename(L,i) lua_typename(L, lua_type(L,(i))) + +#define luaL_dofile(L, fn) \ + (luaL_loadfile(L, fn) || lua_pcall(L, 0, LUA_MULTRET, 0)) + +#define luaL_dostring(L, s) \ + (luaL_loadstring(L, s) || lua_pcall(L, 0, LUA_MULTRET, 0)) + +#define luaL_getmetatable(L,n) (lua_getfield(L, LUA_REGISTRYINDEX, (n))) + +#define luaL_opt(L,f,n,d) (lua_isnoneornil(L,(n)) ? (d) : f(L,(n))) + +/* +** {====================================================== +** Generic Buffer manipulation +** ======================================================= +*/ + + + +typedef struct luaL_Buffer { + char *p; /* current position in buffer */ + int lvl; /* number of strings in the stack (level) */ + lua_State *L; + char buffer[LUAL_BUFFERSIZE]; +} luaL_Buffer; + +#define luaL_addchar(B,c) \ + ((void)((B)->p < ((B)->buffer+LUAL_BUFFERSIZE) || luaL_prepbuffer(B)), \ + (*(B)->p++ = (char)(c))) + +/* compatibility only */ +#define luaL_putchar(B,c) luaL_addchar(B,c) + +#define luaL_addsize(B,n) ((B)->p += (n)) + +LUALIB_API void (luaL_buffinit) (lua_State *L, luaL_Buffer *B); +LUALIB_API char *(luaL_prepbuffer) (luaL_Buffer *B); +LUALIB_API void (luaL_addlstring) (luaL_Buffer *B, const char *s, size_t l); +LUALIB_API void (luaL_addstring) (luaL_Buffer *B, const char *s); +LUALIB_API void (luaL_addvalue) (luaL_Buffer *B); +LUALIB_API void (luaL_pushresult) (luaL_Buffer *B); + + +/* }====================================================== */ + + +/* compatibility with ref system */ + +/* pre-defined references */ +#define LUA_NOREF (-2) +#define LUA_REFNIL (-1) + +#define lua_ref(L,lock) ((lock) ? luaL_ref(L, LUA_REGISTRYINDEX) : \ + (lua_pushstring(L, "unlocked references are obsolete"), lua_error(L), 0)) + +#define lua_unref(L,ref) luaL_unref(L, LUA_REGISTRYINDEX, (ref)) + +#define lua_getref(L,ref) lua_rawgeti(L, LUA_REGISTRYINDEX, (ref)) + + +#define luaL_reg luaL_Reg + +#endif + + diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lbaselib.c b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lbaselib.c new file mode 100644 index 00000000..2a4c079d --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lbaselib.c @@ -0,0 +1,653 @@ +/* +** $Id: lbaselib.c,v 1.191.1.6 2008/02/14 16:46:22 roberto Exp $ +** Basic library +** See Copyright Notice in lua.h +*/ + + + +#include +#include +#include +#include + +#define lbaselib_c +#define LUA_LIB + +#include "lua.h" + +#include "lauxlib.h" +#include "lualib.h" + + + + +/* +** If your system does not support `stdout', you can just remove this function. +** If you need, you can define your own `print' function, following this +** model but changing `fputs' to put the strings at a proper place +** (a console window or a log file, for instance). +*/ +static int luaB_print (lua_State *L) { + int n = lua_gettop(L); /* number of arguments */ + int i; + lua_getglobal(L, "tostring"); + for (i=1; i<=n; i++) { + const char *s; + lua_pushvalue(L, -1); /* function to be called */ + lua_pushvalue(L, i); /* value to print */ + lua_call(L, 1, 1); + s = lua_tostring(L, -1); /* get result */ + if (s == NULL) + return luaL_error(L, LUA_QL("tostring") " must return a string to " + LUA_QL("print")); + if (i>1) fputs("\t", stdout); + fputs(s, stdout); + lua_pop(L, 1); /* pop result */ + } + fputs("\n", stdout); + return 0; +} + + +static int luaB_tonumber (lua_State *L) { + int base = luaL_optint(L, 2, 10); + if (base == 10) { /* standard conversion */ + luaL_checkany(L, 1); + if (lua_isnumber(L, 1)) { + lua_pushnumber(L, lua_tonumber(L, 1)); + return 1; + } + } + else { + const char *s1 = luaL_checkstring(L, 1); + char *s2; + unsigned long n; + luaL_argcheck(L, 2 <= base && base <= 36, 2, "base out of range"); + n = strtoul(s1, &s2, base); + if (s1 != s2) { /* at least one valid digit? */ + while (isspace((unsigned char)(*s2))) s2++; /* skip trailing spaces */ + if (*s2 == '\0') { /* no invalid trailing characters? */ + lua_pushnumber(L, (lua_Number)n); + return 1; + } + } + } + lua_pushnil(L); /* else not a number */ + return 1; +} + + +static int luaB_error (lua_State *L) { + int level = luaL_optint(L, 2, 1); + lua_settop(L, 1); + if (lua_isstring(L, 1) && level > 0) { /* add extra information? */ + luaL_where(L, level); + lua_pushvalue(L, 1); + lua_concat(L, 2); + } + return lua_error(L); +} + + +static int luaB_getmetatable (lua_State *L) { + luaL_checkany(L, 1); + if (!lua_getmetatable(L, 1)) { + lua_pushnil(L); + return 1; /* no metatable */ + } + luaL_getmetafield(L, 1, "__metatable"); + return 1; /* returns either __metatable field (if present) or metatable */ +} + + +static int luaB_setmetatable (lua_State *L) { + int t = lua_type(L, 2); + luaL_checktype(L, 1, LUA_TTABLE); + luaL_argcheck(L, t == LUA_TNIL || t == LUA_TTABLE, 2, + "nil or table expected"); + if (luaL_getmetafield(L, 1, "__metatable")) + luaL_error(L, "cannot change a protected metatable"); + lua_settop(L, 2); + lua_setmetatable(L, 1); + return 1; +} + + +static void getfunc (lua_State *L, int opt) { + if (lua_isfunction(L, 1)) lua_pushvalue(L, 1); + else { + lua_Debug ar; + int level = opt ? luaL_optint(L, 1, 1) : luaL_checkint(L, 1); + luaL_argcheck(L, level >= 0, 1, "level must be non-negative"); + if (lua_getstack(L, level, &ar) == 0) + luaL_argerror(L, 1, "invalid level"); + lua_getinfo(L, "f", &ar); + if (lua_isnil(L, -1)) + luaL_error(L, "no function environment for tail call at level %d", + level); + } +} + + +static int luaB_getfenv (lua_State *L) { + getfunc(L, 1); + if (lua_iscfunction(L, -1)) /* is a C function? */ + lua_pushvalue(L, LUA_GLOBALSINDEX); /* return the thread's global env. */ + else + lua_getfenv(L, -1); + return 1; +} + + +static int luaB_setfenv (lua_State *L) { + luaL_checktype(L, 2, LUA_TTABLE); + getfunc(L, 0); + lua_pushvalue(L, 2); + if (lua_isnumber(L, 1) && lua_tonumber(L, 1) == 0) { + /* change environment of current thread */ + lua_pushthread(L); + lua_insert(L, -2); + lua_setfenv(L, -2); + return 0; + } + else if (lua_iscfunction(L, -2) || lua_setfenv(L, -2) == 0) + luaL_error(L, + LUA_QL("setfenv") " cannot change environment of given object"); + return 1; +} + + +static int luaB_rawequal (lua_State *L) { + luaL_checkany(L, 1); + luaL_checkany(L, 2); + lua_pushboolean(L, lua_rawequal(L, 1, 2)); + return 1; +} + + +static int luaB_rawget (lua_State *L) { + luaL_checktype(L, 1, LUA_TTABLE); + luaL_checkany(L, 2); + lua_settop(L, 2); + lua_rawget(L, 1); + return 1; +} + +static int luaB_rawset (lua_State *L) { + luaL_checktype(L, 1, LUA_TTABLE); + luaL_checkany(L, 2); + luaL_checkany(L, 3); + lua_settop(L, 3); + lua_rawset(L, 1); + return 1; +} + + +static int luaB_gcinfo (lua_State *L) { + lua_pushinteger(L, lua_getgccount(L)); + return 1; +} + + +static int luaB_collectgarbage (lua_State *L) { + static const char *const opts[] = {"stop", "restart", "collect", + "count", "step", "setpause", "setstepmul", NULL}; + static const int optsnum[] = {LUA_GCSTOP, LUA_GCRESTART, LUA_GCCOLLECT, + LUA_GCCOUNT, LUA_GCSTEP, LUA_GCSETPAUSE, LUA_GCSETSTEPMUL}; + int o = luaL_checkoption(L, 1, "collect", opts); + int ex = luaL_optint(L, 2, 0); + int res = lua_gc(L, optsnum[o], ex); + switch (optsnum[o]) { + case LUA_GCCOUNT: { + int b = lua_gc(L, LUA_GCCOUNTB, 0); + lua_pushnumber(L, res + ((lua_Number)b/1024)); + return 1; + } + case LUA_GCSTEP: { + lua_pushboolean(L, res); + return 1; + } + default: { + lua_pushnumber(L, res); + return 1; + } + } +} + + +static int luaB_type (lua_State *L) { + luaL_checkany(L, 1); + lua_pushstring(L, luaL_typename(L, 1)); + return 1; +} + + +static int luaB_next (lua_State *L) { + luaL_checktype(L, 1, LUA_TTABLE); + lua_settop(L, 2); /* create a 2nd argument if there isn't one */ + if (lua_next(L, 1)) + return 2; + else { + lua_pushnil(L); + return 1; + } +} + + +static int luaB_pairs (lua_State *L) { + luaL_checktype(L, 1, LUA_TTABLE); + lua_pushvalue(L, lua_upvalueindex(1)); /* return generator, */ + lua_pushvalue(L, 1); /* state, */ + lua_pushnil(L); /* and initial value */ + return 3; +} + + +static int ipairsaux (lua_State *L) { + int i = luaL_checkint(L, 2); + luaL_checktype(L, 1, LUA_TTABLE); + i++; /* next value */ + lua_pushinteger(L, i); + lua_rawgeti(L, 1, i); + return (lua_isnil(L, -1)) ? 0 : 2; +} + + +static int luaB_ipairs (lua_State *L) { + luaL_checktype(L, 1, LUA_TTABLE); + lua_pushvalue(L, lua_upvalueindex(1)); /* return generator, */ + lua_pushvalue(L, 1); /* state, */ + lua_pushinteger(L, 0); /* and initial value */ + return 3; +} + + +static int load_aux (lua_State *L, int status) { + if (status == 0) /* OK? */ + return 1; + else { + lua_pushnil(L); + lua_insert(L, -2); /* put before error message */ + return 2; /* return nil plus error message */ + } +} + + +static int luaB_loadstring (lua_State *L) { + size_t l; + const char *s = luaL_checklstring(L, 1, &l); + const char *chunkname = luaL_optstring(L, 2, s); + return load_aux(L, luaL_loadbuffer(L, s, l, chunkname)); +} + + +static int luaB_loadfile (lua_State *L) { + const char *fname = luaL_optstring(L, 1, NULL); + return load_aux(L, luaL_loadfile(L, fname)); +} + + +/* +** Reader for generic `load' function: `lua_load' uses the +** stack for internal stuff, so the reader cannot change the +** stack top. Instead, it keeps its resulting string in a +** reserved slot inside the stack. +*/ +static const char *generic_reader (lua_State *L, void *ud, size_t *size) { + (void)ud; /* to avoid warnings */ + luaL_checkstack(L, 2, "too many nested functions"); + lua_pushvalue(L, 1); /* get function */ + lua_call(L, 0, 1); /* call it */ + if (lua_isnil(L, -1)) { + *size = 0; + return NULL; + } + else if (lua_isstring(L, -1)) { + lua_replace(L, 3); /* save string in a reserved stack slot */ + return lua_tolstring(L, 3, size); + } + else luaL_error(L, "reader function must return a string"); + return NULL; /* to avoid warnings */ +} + + +static int luaB_load (lua_State *L) { + int status; + const char *cname = luaL_optstring(L, 2, "=(load)"); + luaL_checktype(L, 1, LUA_TFUNCTION); + lua_settop(L, 3); /* function, eventual name, plus one reserved slot */ + status = lua_load(L, generic_reader, NULL, cname); + return load_aux(L, status); +} + + +static int luaB_dofile (lua_State *L) { + const char *fname = luaL_optstring(L, 1, NULL); + int n = lua_gettop(L); + if (luaL_loadfile(L, fname) != 0) lua_error(L); + lua_call(L, 0, LUA_MULTRET); + return lua_gettop(L) - n; +} + + +static int luaB_assert (lua_State *L) { + luaL_checkany(L, 1); + if (!lua_toboolean(L, 1)) + return luaL_error(L, "%s", luaL_optstring(L, 2, "assertion failed!")); + return lua_gettop(L); +} + + +static int luaB_unpack (lua_State *L) { + int i, e, n; + luaL_checktype(L, 1, LUA_TTABLE); + i = luaL_optint(L, 2, 1); + e = luaL_opt(L, luaL_checkint, 3, luaL_getn(L, 1)); + if (i > e) return 0; /* empty range */ + n = e - i + 1; /* number of elements */ + if (n <= 0 || !lua_checkstack(L, n)) /* n <= 0 means arith. overflow */ + return luaL_error(L, "too many results to unpack"); + lua_rawgeti(L, 1, i); /* push arg[i] (avoiding overflow problems) */ + while (i++ < e) /* push arg[i + 1...e] */ + lua_rawgeti(L, 1, i); + return n; +} + + +static int luaB_select (lua_State *L) { + int n = lua_gettop(L); + if (lua_type(L, 1) == LUA_TSTRING && *lua_tostring(L, 1) == '#') { + lua_pushinteger(L, n-1); + return 1; + } + else { + int i = luaL_checkint(L, 1); + if (i < 0) i = n + i; + else if (i > n) i = n; + luaL_argcheck(L, 1 <= i, 1, "index out of range"); + return n - i; + } +} + + +static int luaB_pcall (lua_State *L) { + int status; + luaL_checkany(L, 1); + status = lua_pcall(L, lua_gettop(L) - 1, LUA_MULTRET, 0); + lua_pushboolean(L, (status == 0)); + lua_insert(L, 1); + return lua_gettop(L); /* return status + all results */ +} + + +static int luaB_xpcall (lua_State *L) { + int status; + luaL_checkany(L, 2); + lua_settop(L, 2); + lua_insert(L, 1); /* put error function under function to be called */ + status = lua_pcall(L, 0, LUA_MULTRET, 1); + lua_pushboolean(L, (status == 0)); + lua_replace(L, 1); + return lua_gettop(L); /* return status + all results */ +} + + +static int luaB_tostring (lua_State *L) { + luaL_checkany(L, 1); + if (luaL_callmeta(L, 1, "__tostring")) /* is there a metafield? */ + return 1; /* use its value */ + switch (lua_type(L, 1)) { + case LUA_TNUMBER: + lua_pushstring(L, lua_tostring(L, 1)); + break; + case LUA_TSTRING: + lua_pushvalue(L, 1); + break; + case LUA_TBOOLEAN: + lua_pushstring(L, (lua_toboolean(L, 1) ? "true" : "false")); + break; + case LUA_TNIL: + lua_pushliteral(L, "nil"); + break; + default: + lua_pushfstring(L, "%s: %p", luaL_typename(L, 1), lua_topointer(L, 1)); + break; + } + return 1; +} + + +static int luaB_newproxy (lua_State *L) { + lua_settop(L, 1); + lua_newuserdata(L, 0); /* create proxy */ + if (lua_toboolean(L, 1) == 0) + return 1; /* no metatable */ + else if (lua_isboolean(L, 1)) { + lua_newtable(L); /* create a new metatable `m' ... */ + lua_pushvalue(L, -1); /* ... and mark `m' as a valid metatable */ + lua_pushboolean(L, 1); + lua_rawset(L, lua_upvalueindex(1)); /* weaktable[m] = true */ + } + else { + int validproxy = 0; /* to check if weaktable[metatable(u)] == true */ + if (lua_getmetatable(L, 1)) { + lua_rawget(L, lua_upvalueindex(1)); + validproxy = lua_toboolean(L, -1); + lua_pop(L, 1); /* remove value */ + } + luaL_argcheck(L, validproxy, 1, "boolean or proxy expected"); + lua_getmetatable(L, 1); /* metatable is valid; get it */ + } + lua_setmetatable(L, 2); + return 1; +} + + +static const luaL_Reg base_funcs[] = { + {"assert", luaB_assert}, + {"collectgarbage", luaB_collectgarbage}, + {"dofile", luaB_dofile}, + {"error", luaB_error}, + {"gcinfo", luaB_gcinfo}, + {"getfenv", luaB_getfenv}, + {"getmetatable", luaB_getmetatable}, + {"loadfile", luaB_loadfile}, + {"load", luaB_load}, + {"loadstring", luaB_loadstring}, + {"next", luaB_next}, + {"pcall", luaB_pcall}, + {"print", luaB_print}, + {"rawequal", luaB_rawequal}, + {"rawget", luaB_rawget}, + {"rawset", luaB_rawset}, + {"select", luaB_select}, + {"setfenv", luaB_setfenv}, + {"setmetatable", luaB_setmetatable}, + {"tonumber", luaB_tonumber}, + {"tostring", luaB_tostring}, + {"type", luaB_type}, + {"unpack", luaB_unpack}, + {"xpcall", luaB_xpcall}, + {NULL, NULL} +}; + + +/* +** {====================================================== +** Coroutine library +** ======================================================= +*/ + +#define CO_RUN 0 /* running */ +#define CO_SUS 1 /* suspended */ +#define CO_NOR 2 /* 'normal' (it resumed another coroutine) */ +#define CO_DEAD 3 + +static const char *const statnames[] = + {"running", "suspended", "normal", "dead"}; + +static int costatus (lua_State *L, lua_State *co) { + if (L == co) return CO_RUN; + switch (lua_status(co)) { + case LUA_YIELD: + return CO_SUS; + case 0: { + lua_Debug ar; + if (lua_getstack(co, 0, &ar) > 0) /* does it have frames? */ + return CO_NOR; /* it is running */ + else if (lua_gettop(co) == 0) + return CO_DEAD; + else + return CO_SUS; /* initial state */ + } + default: /* some error occured */ + return CO_DEAD; + } +} + + +static int luaB_costatus (lua_State *L) { + lua_State *co = lua_tothread(L, 1); + luaL_argcheck(L, co, 1, "coroutine expected"); + lua_pushstring(L, statnames[costatus(L, co)]); + return 1; +} + + +static int auxresume (lua_State *L, lua_State *co, int narg) { + int status = costatus(L, co); + if (!lua_checkstack(co, narg)) + luaL_error(L, "too many arguments to resume"); + if (status != CO_SUS) { + lua_pushfstring(L, "cannot resume %s coroutine", statnames[status]); + return -1; /* error flag */ + } + lua_xmove(L, co, narg); + lua_setlevel(L, co); + status = lua_resume(co, narg); + if (status == 0 || status == LUA_YIELD) { + int nres = lua_gettop(co); + if (!lua_checkstack(L, nres + 1)) + luaL_error(L, "too many results to resume"); + lua_xmove(co, L, nres); /* move yielded values */ + return nres; + } + else { + lua_xmove(co, L, 1); /* move error message */ + return -1; /* error flag */ + } +} + + +static int luaB_coresume (lua_State *L) { + lua_State *co = lua_tothread(L, 1); + int r; + luaL_argcheck(L, co, 1, "coroutine expected"); + r = auxresume(L, co, lua_gettop(L) - 1); + if (r < 0) { + lua_pushboolean(L, 0); + lua_insert(L, -2); + return 2; /* return false + error message */ + } + else { + lua_pushboolean(L, 1); + lua_insert(L, -(r + 1)); + return r + 1; /* return true + `resume' returns */ + } +} + + +static int luaB_auxwrap (lua_State *L) { + lua_State *co = lua_tothread(L, lua_upvalueindex(1)); + int r = auxresume(L, co, lua_gettop(L)); + if (r < 0) { + if (lua_isstring(L, -1)) { /* error object is a string? */ + luaL_where(L, 1); /* add extra info */ + lua_insert(L, -2); + lua_concat(L, 2); + } + lua_error(L); /* propagate error */ + } + return r; +} + + +static int luaB_cocreate (lua_State *L) { + lua_State *NL = lua_newthread(L); + luaL_argcheck(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), 1, + "Lua function expected"); + lua_pushvalue(L, 1); /* move function to top */ + lua_xmove(L, NL, 1); /* move function from L to NL */ + return 1; +} + + +static int luaB_cowrap (lua_State *L) { + luaB_cocreate(L); + lua_pushcclosure(L, luaB_auxwrap, 1); + return 1; +} + + +static int luaB_yield (lua_State *L) { + return lua_yield(L, lua_gettop(L)); +} + + +static int luaB_corunning (lua_State *L) { + if (lua_pushthread(L)) + lua_pushnil(L); /* main thread is not a coroutine */ + return 1; +} + + +static const luaL_Reg co_funcs[] = { + {"create", luaB_cocreate}, + {"resume", luaB_coresume}, + {"running", luaB_corunning}, + {"status", luaB_costatus}, + {"wrap", luaB_cowrap}, + {"yield", luaB_yield}, + {NULL, NULL} +}; + +/* }====================================================== */ + + +static void auxopen (lua_State *L, const char *name, + lua_CFunction f, lua_CFunction u) { + lua_pushcfunction(L, u); + lua_pushcclosure(L, f, 1); + lua_setfield(L, -2, name); +} + + +static void base_open (lua_State *L) { + /* set global _G */ + lua_pushvalue(L, LUA_GLOBALSINDEX); + lua_setglobal(L, "_G"); + /* open lib into global table */ + luaL_register(L, "_G", base_funcs); + lua_pushliteral(L, LUA_VERSION); + lua_setglobal(L, "_VERSION"); /* set global _VERSION */ + /* `ipairs' and `pairs' need auxliliary functions as upvalues */ + auxopen(L, "ipairs", luaB_ipairs, ipairsaux); + auxopen(L, "pairs", luaB_pairs, luaB_next); + /* `newproxy' needs a weaktable as upvalue */ + lua_createtable(L, 0, 1); /* new table `w' */ + lua_pushvalue(L, -1); /* `w' will be its own metatable */ + lua_setmetatable(L, -2); + lua_pushliteral(L, "kv"); + lua_setfield(L, -2, "__mode"); /* metatable(w).__mode = "kv" */ + lua_pushcclosure(L, luaB_newproxy, 1); + lua_setglobal(L, "newproxy"); /* set global `newproxy' */ +} + + +LUALIB_API int luaopen_base (lua_State *L) { + base_open(L); + luaL_register(L, LUA_COLIBNAME, co_funcs); + return 2; +} + diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lcode.c b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lcode.c new file mode 100644 index 00000000..cff626b7 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lcode.c @@ -0,0 +1,839 @@ +/* +** $Id: lcode.c,v 2.25.1.3 2007/12/28 15:32:23 roberto Exp $ +** Code generator for Lua +** See Copyright Notice in lua.h +*/ + + +#include + +#define lcode_c +#define LUA_CORE + +#include "lua.h" + +#include "lcode.h" +#include "ldebug.h" +#include "ldo.h" +#include "lgc.h" +#include "llex.h" +#include "lmem.h" +#include "lobject.h" +#include "lopcodes.h" +#include "lparser.h" +#include "ltable.h" + + +#define hasjumps(e) ((e)->t != (e)->f) + + +static int isnumeral(expdesc *e) { + return (e->k == VKNUM && e->t == NO_JUMP && e->f == NO_JUMP); +} + + +void luaK_nil (FuncState *fs, int from, int n) { + Instruction *previous; + if (fs->pc > fs->lasttarget) { /* no jumps to current position? */ + if (fs->pc == 0) { /* function start? */ + if (from >= fs->nactvar) + return; /* positions are already clean */ + } + else { + previous = &fs->f->code[fs->pc-1]; + if (GET_OPCODE(*previous) == OP_LOADNIL) { + int pfrom = GETARG_A(*previous); + int pto = GETARG_B(*previous); + if (pfrom <= from && from <= pto+1) { /* can connect both? */ + if (from+n-1 > pto) + SETARG_B(*previous, from+n-1); + return; + } + } + } + } + luaK_codeABC(fs, OP_LOADNIL, from, from+n-1, 0); /* else no optimization */ +} + + +int luaK_jump (FuncState *fs) { + int jpc = fs->jpc; /* save list of jumps to here */ + int j; + fs->jpc = NO_JUMP; + j = luaK_codeAsBx(fs, OP_JMP, 0, NO_JUMP); + luaK_concat(fs, &j, jpc); /* keep them on hold */ + return j; +} + + +void luaK_ret (FuncState *fs, int first, int nret) { + luaK_codeABC(fs, OP_RETURN, first, nret+1, 0); +} + + +static int condjump (FuncState *fs, OpCode op, int A, int B, int C) { + luaK_codeABC(fs, op, A, B, C); + return luaK_jump(fs); +} + + +static void fixjump (FuncState *fs, int pc, int dest) { + Instruction *jmp = &fs->f->code[pc]; + int offset = dest-(pc+1); + lua_assert(dest != NO_JUMP); + if (abs(offset) > MAXARG_sBx) + luaX_syntaxerror(fs->ls, "control structure too long"); + SETARG_sBx(*jmp, offset); +} + + +/* +** returns current `pc' and marks it as a jump target (to avoid wrong +** optimizations with consecutive instructions not in the same basic block). +*/ +int luaK_getlabel (FuncState *fs) { + fs->lasttarget = fs->pc; + return fs->pc; +} + + +static int getjump (FuncState *fs, int pc) { + int offset = GETARG_sBx(fs->f->code[pc]); + if (offset == NO_JUMP) /* point to itself represents end of list */ + return NO_JUMP; /* end of list */ + else + return (pc+1)+offset; /* turn offset into absolute position */ +} + + +static Instruction *getjumpcontrol (FuncState *fs, int pc) { + Instruction *pi = &fs->f->code[pc]; + if (pc >= 1 && testTMode(GET_OPCODE(*(pi-1)))) + return pi-1; + else + return pi; +} + + +/* +** check whether list has any jump that do not produce a value +** (or produce an inverted value) +*/ +static int need_value (FuncState *fs, int list) { + for (; list != NO_JUMP; list = getjump(fs, list)) { + Instruction i = *getjumpcontrol(fs, list); + if (GET_OPCODE(i) != OP_TESTSET) return 1; + } + return 0; /* not found */ +} + + +static int patchtestreg (FuncState *fs, int node, int reg) { + Instruction *i = getjumpcontrol(fs, node); + if (GET_OPCODE(*i) != OP_TESTSET) + return 0; /* cannot patch other instructions */ + if (reg != NO_REG && reg != GETARG_B(*i)) + SETARG_A(*i, reg); + else /* no register to put value or register already has the value */ + *i = CREATE_ABC(OP_TEST, GETARG_B(*i), 0, GETARG_C(*i)); + + return 1; +} + + +static void removevalues (FuncState *fs, int list) { + for (; list != NO_JUMP; list = getjump(fs, list)) + patchtestreg(fs, list, NO_REG); +} + + +static void patchlistaux (FuncState *fs, int list, int vtarget, int reg, + int dtarget) { + while (list != NO_JUMP) { + int next = getjump(fs, list); + if (patchtestreg(fs, list, reg)) + fixjump(fs, list, vtarget); + else + fixjump(fs, list, dtarget); /* jump to default target */ + list = next; + } +} + + +static void dischargejpc (FuncState *fs) { + patchlistaux(fs, fs->jpc, fs->pc, NO_REG, fs->pc); + fs->jpc = NO_JUMP; +} + + +void luaK_patchlist (FuncState *fs, int list, int target) { + if (target == fs->pc) + luaK_patchtohere(fs, list); + else { + lua_assert(target < fs->pc); + patchlistaux(fs, list, target, NO_REG, target); + } +} + + +void luaK_patchtohere (FuncState *fs, int list) { + luaK_getlabel(fs); + luaK_concat(fs, &fs->jpc, list); +} + + +void luaK_concat (FuncState *fs, int *l1, int l2) { + if (l2 == NO_JUMP) return; + else if (*l1 == NO_JUMP) + *l1 = l2; + else { + int list = *l1; + int next; + while ((next = getjump(fs, list)) != NO_JUMP) /* find last element */ + list = next; + fixjump(fs, list, l2); + } +} + + +void luaK_checkstack (FuncState *fs, int n) { + int newstack = fs->freereg + n; + if (newstack > fs->f->maxstacksize) { + if (newstack >= MAXSTACK) + luaX_syntaxerror(fs->ls, "function or expression too complex"); + fs->f->maxstacksize = cast_byte(newstack); + } +} + + +void luaK_reserveregs (FuncState *fs, int n) { + luaK_checkstack(fs, n); + fs->freereg += n; +} + + +static void freereg (FuncState *fs, int reg) { + if (!ISK(reg) && reg >= fs->nactvar) { + fs->freereg--; + lua_assert(reg == fs->freereg); + } +} + + +static void freeexp (FuncState *fs, expdesc *e) { + if (e->k == VNONRELOC) + freereg(fs, e->u.s.info); +} + + +static int addk (FuncState *fs, TValue *k, TValue *v) { + lua_State *L = fs->L; + TValue *idx = luaH_set(L, fs->h, k); + Proto *f = fs->f; + int oldsize = f->sizek; + if (ttisnumber(idx)) { + lua_assert(luaO_rawequalObj(&fs->f->k[cast_int(nvalue(idx))], v)); + return cast_int(nvalue(idx)); + } + else { /* constant not found; create a new entry */ + setnvalue(idx, cast_num(fs->nk)); + luaM_growvector(L, f->k, fs->nk, f->sizek, TValue, + MAXARG_Bx, "constant table overflow"); + while (oldsize < f->sizek) setnilvalue(&f->k[oldsize++]); + setobj(L, &f->k[fs->nk], v); + luaC_barrier(L, f, v); + return fs->nk++; + } +} + + +int luaK_stringK (FuncState *fs, TString *s) { + TValue o; + setsvalue(fs->L, &o, s); + return addk(fs, &o, &o); +} + + +int luaK_numberK (FuncState *fs, lua_Number r) { + TValue o; + setnvalue(&o, r); + return addk(fs, &o, &o); +} + + +static int boolK (FuncState *fs, int b) { + TValue o; + setbvalue(&o, b); + return addk(fs, &o, &o); +} + + +static int nilK (FuncState *fs) { + TValue k, v; + setnilvalue(&v); + /* cannot use nil as key; instead use table itself to represent nil */ + sethvalue(fs->L, &k, fs->h); + return addk(fs, &k, &v); +} + + +void luaK_setreturns (FuncState *fs, expdesc *e, int nresults) { + if (e->k == VCALL) { /* expression is an open function call? */ + SETARG_C(getcode(fs, e), nresults+1); + } + else if (e->k == VVARARG) { + SETARG_B(getcode(fs, e), nresults+1); + SETARG_A(getcode(fs, e), fs->freereg); + luaK_reserveregs(fs, 1); + } +} + + +void luaK_setoneret (FuncState *fs, expdesc *e) { + if (e->k == VCALL) { /* expression is an open function call? */ + e->k = VNONRELOC; + e->u.s.info = GETARG_A(getcode(fs, e)); + } + else if (e->k == VVARARG) { + SETARG_B(getcode(fs, e), 2); + e->k = VRELOCABLE; /* can relocate its simple result */ + } +} + + +void luaK_dischargevars (FuncState *fs, expdesc *e) { + switch (e->k) { + case VLOCAL: { + e->k = VNONRELOC; + break; + } + case VUPVAL: { + e->u.s.info = luaK_codeABC(fs, OP_GETUPVAL, 0, e->u.s.info, 0); + e->k = VRELOCABLE; + break; + } + case VGLOBAL: { + e->u.s.info = luaK_codeABx(fs, OP_GETGLOBAL, 0, e->u.s.info); + e->k = VRELOCABLE; + break; + } + case VINDEXED: { + freereg(fs, e->u.s.aux); + freereg(fs, e->u.s.info); + e->u.s.info = luaK_codeABC(fs, OP_GETTABLE, 0, e->u.s.info, e->u.s.aux); + e->k = VRELOCABLE; + break; + } + case VVARARG: + case VCALL: { + luaK_setoneret(fs, e); + break; + } + default: break; /* there is one value available (somewhere) */ + } +} + + +static int code_label (FuncState *fs, int A, int b, int jump) { + luaK_getlabel(fs); /* those instructions may be jump targets */ + return luaK_codeABC(fs, OP_LOADBOOL, A, b, jump); +} + + +static void discharge2reg (FuncState *fs, expdesc *e, int reg) { + luaK_dischargevars(fs, e); + switch (e->k) { + case VNIL: { + luaK_nil(fs, reg, 1); + break; + } + case VFALSE: case VTRUE: { + luaK_codeABC(fs, OP_LOADBOOL, reg, e->k == VTRUE, 0); + break; + } + case VK: { + luaK_codeABx(fs, OP_LOADK, reg, e->u.s.info); + break; + } + case VKNUM: { + luaK_codeABx(fs, OP_LOADK, reg, luaK_numberK(fs, e->u.nval)); + break; + } + case VRELOCABLE: { + Instruction *pc = &getcode(fs, e); + SETARG_A(*pc, reg); + break; + } + case VNONRELOC: { + if (reg != e->u.s.info) + luaK_codeABC(fs, OP_MOVE, reg, e->u.s.info, 0); + break; + } + default: { + lua_assert(e->k == VVOID || e->k == VJMP); + return; /* nothing to do... */ + } + } + e->u.s.info = reg; + e->k = VNONRELOC; +} + + +static void discharge2anyreg (FuncState *fs, expdesc *e) { + if (e->k != VNONRELOC) { + luaK_reserveregs(fs, 1); + discharge2reg(fs, e, fs->freereg-1); + } +} + + +static void exp2reg (FuncState *fs, expdesc *e, int reg) { + discharge2reg(fs, e, reg); + if (e->k == VJMP) + luaK_concat(fs, &e->t, e->u.s.info); /* put this jump in `t' list */ + if (hasjumps(e)) { + int final; /* position after whole expression */ + int p_f = NO_JUMP; /* position of an eventual LOAD false */ + int p_t = NO_JUMP; /* position of an eventual LOAD true */ + if (need_value(fs, e->t) || need_value(fs, e->f)) { + int fj = (e->k == VJMP) ? NO_JUMP : luaK_jump(fs); + p_f = code_label(fs, reg, 0, 1); + p_t = code_label(fs, reg, 1, 0); + luaK_patchtohere(fs, fj); + } + final = luaK_getlabel(fs); + patchlistaux(fs, e->f, final, reg, p_f); + patchlistaux(fs, e->t, final, reg, p_t); + } + e->f = e->t = NO_JUMP; + e->u.s.info = reg; + e->k = VNONRELOC; +} + + +void luaK_exp2nextreg (FuncState *fs, expdesc *e) { + luaK_dischargevars(fs, e); + freeexp(fs, e); + luaK_reserveregs(fs, 1); + exp2reg(fs, e, fs->freereg - 1); +} + + +int luaK_exp2anyreg (FuncState *fs, expdesc *e) { + luaK_dischargevars(fs, e); + if (e->k == VNONRELOC) { + if (!hasjumps(e)) return e->u.s.info; /* exp is already in a register */ + if (e->u.s.info >= fs->nactvar) { /* reg. is not a local? */ + exp2reg(fs, e, e->u.s.info); /* put value on it */ + return e->u.s.info; + } + } + luaK_exp2nextreg(fs, e); /* default */ + return e->u.s.info; +} + + +void luaK_exp2val (FuncState *fs, expdesc *e) { + if (hasjumps(e)) + luaK_exp2anyreg(fs, e); + else + luaK_dischargevars(fs, e); +} + + +int luaK_exp2RK (FuncState *fs, expdesc *e) { + luaK_exp2val(fs, e); + switch (e->k) { + case VKNUM: + case VTRUE: + case VFALSE: + case VNIL: { + if (fs->nk <= MAXINDEXRK) { /* constant fit in RK operand? */ + e->u.s.info = (e->k == VNIL) ? nilK(fs) : + (e->k == VKNUM) ? luaK_numberK(fs, e->u.nval) : + boolK(fs, (e->k == VTRUE)); + e->k = VK; + return RKASK(e->u.s.info); + } + else break; + } + case VK: { + if (e->u.s.info <= MAXINDEXRK) /* constant fit in argC? */ + return RKASK(e->u.s.info); + else break; + } + default: break; + } + /* not a constant in the right range: put it in a register */ + return luaK_exp2anyreg(fs, e); +} + + +void luaK_storevar (FuncState *fs, expdesc *var, expdesc *ex) { + switch (var->k) { + case VLOCAL: { + freeexp(fs, ex); + exp2reg(fs, ex, var->u.s.info); + return; + } + case VUPVAL: { + int e = luaK_exp2anyreg(fs, ex); + luaK_codeABC(fs, OP_SETUPVAL, e, var->u.s.info, 0); + break; + } + case VGLOBAL: { + int e = luaK_exp2anyreg(fs, ex); + luaK_codeABx(fs, OP_SETGLOBAL, e, var->u.s.info); + break; + } + case VINDEXED: { + int e = luaK_exp2RK(fs, ex); + luaK_codeABC(fs, OP_SETTABLE, var->u.s.info, var->u.s.aux, e); + break; + } + default: { + lua_assert(0); /* invalid var kind to store */ + break; + } + } + freeexp(fs, ex); +} + + +void luaK_self (FuncState *fs, expdesc *e, expdesc *key) { + int func; + luaK_exp2anyreg(fs, e); + freeexp(fs, e); + func = fs->freereg; + luaK_reserveregs(fs, 2); + luaK_codeABC(fs, OP_SELF, func, e->u.s.info, luaK_exp2RK(fs, key)); + freeexp(fs, key); + e->u.s.info = func; + e->k = VNONRELOC; +} + + +static void invertjump (FuncState *fs, expdesc *e) { + Instruction *pc = getjumpcontrol(fs, e->u.s.info); + lua_assert(testTMode(GET_OPCODE(*pc)) && GET_OPCODE(*pc) != OP_TESTSET && + GET_OPCODE(*pc) != OP_TEST); + SETARG_A(*pc, !(GETARG_A(*pc))); +} + + +static int jumponcond (FuncState *fs, expdesc *e, int cond) { + if (e->k == VRELOCABLE) { + Instruction ie = getcode(fs, e); + if (GET_OPCODE(ie) == OP_NOT) { + fs->pc--; /* remove previous OP_NOT */ + return condjump(fs, OP_TEST, GETARG_B(ie), 0, !cond); + } + /* else go through */ + } + discharge2anyreg(fs, e); + freeexp(fs, e); + return condjump(fs, OP_TESTSET, NO_REG, e->u.s.info, cond); +} + + +void luaK_goiftrue (FuncState *fs, expdesc *e) { + int pc; /* pc of last jump */ + luaK_dischargevars(fs, e); + switch (e->k) { + case VK: case VKNUM: case VTRUE: { + pc = NO_JUMP; /* always true; do nothing */ + break; + } + case VFALSE: { + pc = luaK_jump(fs); /* always jump */ + break; + } + case VJMP: { + invertjump(fs, e); + pc = e->u.s.info; + break; + } + default: { + pc = jumponcond(fs, e, 0); + break; + } + } + luaK_concat(fs, &e->f, pc); /* insert last jump in `f' list */ + luaK_patchtohere(fs, e->t); + e->t = NO_JUMP; +} + + +static void luaK_goiffalse (FuncState *fs, expdesc *e) { + int pc; /* pc of last jump */ + luaK_dischargevars(fs, e); + switch (e->k) { + case VNIL: case VFALSE: { + pc = NO_JUMP; /* always false; do nothing */ + break; + } + case VTRUE: { + pc = luaK_jump(fs); /* always jump */ + break; + } + case VJMP: { + pc = e->u.s.info; + break; + } + default: { + pc = jumponcond(fs, e, 1); + break; + } + } + luaK_concat(fs, &e->t, pc); /* insert last jump in `t' list */ + luaK_patchtohere(fs, e->f); + e->f = NO_JUMP; +} + + +static void codenot (FuncState *fs, expdesc *e) { + luaK_dischargevars(fs, e); + switch (e->k) { + case VNIL: case VFALSE: { + e->k = VTRUE; + break; + } + case VK: case VKNUM: case VTRUE: { + e->k = VFALSE; + break; + } + case VJMP: { + invertjump(fs, e); + break; + } + case VRELOCABLE: + case VNONRELOC: { + discharge2anyreg(fs, e); + freeexp(fs, e); + e->u.s.info = luaK_codeABC(fs, OP_NOT, 0, e->u.s.info, 0); + e->k = VRELOCABLE; + break; + } + default: { + lua_assert(0); /* cannot happen */ + break; + } + } + /* interchange true and false lists */ + { int temp = e->f; e->f = e->t; e->t = temp; } + removevalues(fs, e->f); + removevalues(fs, e->t); +} + + +void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) { + t->u.s.aux = luaK_exp2RK(fs, k); + t->k = VINDEXED; +} + + +static int constfolding (OpCode op, expdesc *e1, expdesc *e2) { + lua_Number v1, v2, r; + if (!isnumeral(e1) || !isnumeral(e2)) return 0; + v1 = e1->u.nval; + v2 = e2->u.nval; + switch (op) { + case OP_ADD: r = luai_numadd(v1, v2); break; + case OP_SUB: r = luai_numsub(v1, v2); break; + case OP_MUL: r = luai_nummul(v1, v2); break; + case OP_DIV: + if (v2 == 0) return 0; /* do not attempt to divide by 0 */ + r = luai_numdiv(v1, v2); break; + case OP_MOD: + if (v2 == 0) return 0; /* do not attempt to divide by 0 */ + r = luai_nummod(v1, v2); break; + case OP_POW: r = luai_numpow(v1, v2); break; + case OP_UNM: r = luai_numunm(v1); break; + case OP_LEN: return 0; /* no constant folding for 'len' */ + default: lua_assert(0); r = 0; break; + } + if (luai_numisnan(r)) return 0; /* do not attempt to produce NaN */ + e1->u.nval = r; + return 1; +} + + +static void codearith (FuncState *fs, OpCode op, expdesc *e1, expdesc *e2) { + if (constfolding(op, e1, e2)) + return; + else { + int o2 = (op != OP_UNM && op != OP_LEN) ? luaK_exp2RK(fs, e2) : 0; + int o1 = luaK_exp2RK(fs, e1); + if (o1 > o2) { + freeexp(fs, e1); + freeexp(fs, e2); + } + else { + freeexp(fs, e2); + freeexp(fs, e1); + } + e1->u.s.info = luaK_codeABC(fs, op, 0, o1, o2); + e1->k = VRELOCABLE; + } +} + + +static void codecomp (FuncState *fs, OpCode op, int cond, expdesc *e1, + expdesc *e2) { + int o1 = luaK_exp2RK(fs, e1); + int o2 = luaK_exp2RK(fs, e2); + freeexp(fs, e2); + freeexp(fs, e1); + if (cond == 0 && op != OP_EQ) { + int temp; /* exchange args to replace by `<' or `<=' */ + temp = o1; o1 = o2; o2 = temp; /* o1 <==> o2 */ + cond = 1; + } + e1->u.s.info = condjump(fs, op, cond, o1, o2); + e1->k = VJMP; +} + + +void luaK_prefix (FuncState *fs, UnOpr op, expdesc *e) { + expdesc e2; + e2.t = e2.f = NO_JUMP; e2.k = VKNUM; e2.u.nval = 0; + switch (op) { + case OPR_MINUS: { + if (!isnumeral(e)) + luaK_exp2anyreg(fs, e); /* cannot operate on non-numeric constants */ + codearith(fs, OP_UNM, e, &e2); + break; + } + case OPR_NOT: codenot(fs, e); break; + case OPR_LEN: { + luaK_exp2anyreg(fs, e); /* cannot operate on constants */ + codearith(fs, OP_LEN, e, &e2); + break; + } + default: lua_assert(0); + } +} + + +void luaK_infix (FuncState *fs, BinOpr op, expdesc *v) { + switch (op) { + case OPR_AND: { + luaK_goiftrue(fs, v); + break; + } + case OPR_OR: { + luaK_goiffalse(fs, v); + break; + } + case OPR_CONCAT: { + luaK_exp2nextreg(fs, v); /* operand must be on the `stack' */ + break; + } + case OPR_ADD: case OPR_SUB: case OPR_MUL: case OPR_DIV: + case OPR_MOD: case OPR_POW: { + if (!isnumeral(v)) luaK_exp2RK(fs, v); + break; + } + default: { + luaK_exp2RK(fs, v); + break; + } + } +} + + +void luaK_posfix (FuncState *fs, BinOpr op, expdesc *e1, expdesc *e2) { + switch (op) { + case OPR_AND: { + lua_assert(e1->t == NO_JUMP); /* list must be closed */ + luaK_dischargevars(fs, e2); + luaK_concat(fs, &e2->f, e1->f); + *e1 = *e2; + break; + } + case OPR_OR: { + lua_assert(e1->f == NO_JUMP); /* list must be closed */ + luaK_dischargevars(fs, e2); + luaK_concat(fs, &e2->t, e1->t); + *e1 = *e2; + break; + } + case OPR_CONCAT: { + luaK_exp2val(fs, e2); + if (e2->k == VRELOCABLE && GET_OPCODE(getcode(fs, e2)) == OP_CONCAT) { + lua_assert(e1->u.s.info == GETARG_B(getcode(fs, e2))-1); + freeexp(fs, e1); + SETARG_B(getcode(fs, e2), e1->u.s.info); + e1->k = VRELOCABLE; e1->u.s.info = e2->u.s.info; + } + else { + luaK_exp2nextreg(fs, e2); /* operand must be on the 'stack' */ + codearith(fs, OP_CONCAT, e1, e2); + } + break; + } + case OPR_ADD: codearith(fs, OP_ADD, e1, e2); break; + case OPR_SUB: codearith(fs, OP_SUB, e1, e2); break; + case OPR_MUL: codearith(fs, OP_MUL, e1, e2); break; + case OPR_DIV: codearith(fs, OP_DIV, e1, e2); break; + case OPR_MOD: codearith(fs, OP_MOD, e1, e2); break; + case OPR_POW: codearith(fs, OP_POW, e1, e2); break; + case OPR_EQ: codecomp(fs, OP_EQ, 1, e1, e2); break; + case OPR_NE: codecomp(fs, OP_EQ, 0, e1, e2); break; + case OPR_LT: codecomp(fs, OP_LT, 1, e1, e2); break; + case OPR_LE: codecomp(fs, OP_LE, 1, e1, e2); break; + case OPR_GT: codecomp(fs, OP_LT, 0, e1, e2); break; + case OPR_GE: codecomp(fs, OP_LE, 0, e1, e2); break; + default: lua_assert(0); + } +} + + +void luaK_fixline (FuncState *fs, int line) { + fs->f->lineinfo[fs->pc - 1] = line; +} + + +static int luaK_code (FuncState *fs, Instruction i, int line) { + Proto *f = fs->f; + dischargejpc(fs); /* `pc' will change */ + /* put new instruction in code array */ + luaM_growvector(fs->L, f->code, fs->pc, f->sizecode, Instruction, + MAX_INT, "code size overflow"); + f->code[fs->pc] = i; + /* save corresponding line information */ + luaM_growvector(fs->L, f->lineinfo, fs->pc, f->sizelineinfo, int, + MAX_INT, "code size overflow"); + f->lineinfo[fs->pc] = line; + return fs->pc++; +} + + +int luaK_codeABC (FuncState *fs, OpCode o, int a, int b, int c) { + lua_assert(getOpMode(o) == iABC); + lua_assert(getBMode(o) != OpArgN || b == 0); + lua_assert(getCMode(o) != OpArgN || c == 0); + return luaK_code(fs, CREATE_ABC(o, a, b, c), fs->ls->lastline); +} + + +int luaK_codeABx (FuncState *fs, OpCode o, int a, unsigned int bc) { + lua_assert(getOpMode(o) == iABx || getOpMode(o) == iAsBx); + lua_assert(getCMode(o) == OpArgN); + return luaK_code(fs, CREATE_ABx(o, a, bc), fs->ls->lastline); +} + + +void luaK_setlist (FuncState *fs, int base, int nelems, int tostore) { + int c = (nelems - 1)/LFIELDS_PER_FLUSH + 1; + int b = (tostore == LUA_MULTRET) ? 0 : tostore; + lua_assert(tostore != 0); + if (c <= MAXARG_C) + luaK_codeABC(fs, OP_SETLIST, base, b, c); + else { + luaK_codeABC(fs, OP_SETLIST, base, b, 0); + luaK_code(fs, cast(Instruction, c), fs->ls->lastline); + } + fs->freereg = base + 1; /* free registers with list values */ +} + diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lcode.h b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lcode.h new file mode 100644 index 00000000..b941c607 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lcode.h @@ -0,0 +1,76 @@ +/* +** $Id: lcode.h,v 1.48.1.1 2007/12/27 13:02:25 roberto Exp $ +** Code generator for Lua +** See Copyright Notice in lua.h +*/ + +#ifndef lcode_h +#define lcode_h + +#include "llex.h" +#include "lobject.h" +#include "lopcodes.h" +#include "lparser.h" + + +/* +** Marks the end of a patch list. It is an invalid value both as an absolute +** address, and as a list link (would link an element to itself). +*/ +#define NO_JUMP (-1) + + +/* +** grep "ORDER OPR" if you change these enums +*/ +typedef enum BinOpr { + OPR_ADD, OPR_SUB, OPR_MUL, OPR_DIV, OPR_MOD, OPR_POW, + OPR_CONCAT, + OPR_NE, OPR_EQ, + OPR_LT, OPR_LE, OPR_GT, OPR_GE, + OPR_AND, OPR_OR, + OPR_NOBINOPR +} BinOpr; + + +typedef enum UnOpr { OPR_MINUS, OPR_NOT, OPR_LEN, OPR_NOUNOPR } UnOpr; + + +#define getcode(fs,e) ((fs)->f->code[(e)->u.s.info]) + +#define luaK_codeAsBx(fs,o,A,sBx) luaK_codeABx(fs,o,A,(sBx)+MAXARG_sBx) + +#define luaK_setmultret(fs,e) luaK_setreturns(fs, e, LUA_MULTRET) + +LUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx); +LUAI_FUNC int luaK_codeABC (FuncState *fs, OpCode o, int A, int B, int C); +LUAI_FUNC void luaK_fixline (FuncState *fs, int line); +LUAI_FUNC void luaK_nil (FuncState *fs, int from, int n); +LUAI_FUNC void luaK_reserveregs (FuncState *fs, int n); +LUAI_FUNC void luaK_checkstack (FuncState *fs, int n); +LUAI_FUNC int luaK_stringK (FuncState *fs, TString *s); +LUAI_FUNC int luaK_numberK (FuncState *fs, lua_Number r); +LUAI_FUNC void luaK_dischargevars (FuncState *fs, expdesc *e); +LUAI_FUNC int luaK_exp2anyreg (FuncState *fs, expdesc *e); +LUAI_FUNC void luaK_exp2nextreg (FuncState *fs, expdesc *e); +LUAI_FUNC void luaK_exp2val (FuncState *fs, expdesc *e); +LUAI_FUNC int luaK_exp2RK (FuncState *fs, expdesc *e); +LUAI_FUNC void luaK_self (FuncState *fs, expdesc *e, expdesc *key); +LUAI_FUNC void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k); +LUAI_FUNC void luaK_goiftrue (FuncState *fs, expdesc *e); +LUAI_FUNC void luaK_storevar (FuncState *fs, expdesc *var, expdesc *e); +LUAI_FUNC void luaK_setreturns (FuncState *fs, expdesc *e, int nresults); +LUAI_FUNC void luaK_setoneret (FuncState *fs, expdesc *e); +LUAI_FUNC int luaK_jump (FuncState *fs); +LUAI_FUNC void luaK_ret (FuncState *fs, int first, int nret); +LUAI_FUNC void luaK_patchlist (FuncState *fs, int list, int target); +LUAI_FUNC void luaK_patchtohere (FuncState *fs, int list); +LUAI_FUNC void luaK_concat (FuncState *fs, int *l1, int l2); +LUAI_FUNC int luaK_getlabel (FuncState *fs); +LUAI_FUNC void luaK_prefix (FuncState *fs, UnOpr op, expdesc *v); +LUAI_FUNC void luaK_infix (FuncState *fs, BinOpr op, expdesc *v); +LUAI_FUNC void luaK_posfix (FuncState *fs, BinOpr op, expdesc *v1, expdesc *v2); +LUAI_FUNC void luaK_setlist (FuncState *fs, int base, int nelems, int tostore); + + +#endif diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/ldblib.c b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/ldblib.c new file mode 100644 index 00000000..67de1222 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/ldblib.c @@ -0,0 +1,397 @@ +/* +** $Id: ldblib.c,v 1.104.1.3 2008/01/21 13:11:21 roberto Exp $ +** Interface from Lua to its debug API +** See Copyright Notice in lua.h +*/ + + +#include +#include +#include + +#define ldblib_c +#define LUA_LIB + +#include "lua.h" + +#include "lauxlib.h" +#include "lualib.h" + + + +static int db_getregistry (lua_State *L) { + lua_pushvalue(L, LUA_REGISTRYINDEX); + return 1; +} + + +static int db_getmetatable (lua_State *L) { + luaL_checkany(L, 1); + if (!lua_getmetatable(L, 1)) { + lua_pushnil(L); /* no metatable */ + } + return 1; +} + + +static int db_setmetatable (lua_State *L) { + int t = lua_type(L, 2); + luaL_argcheck(L, t == LUA_TNIL || t == LUA_TTABLE, 2, + "nil or table expected"); + lua_settop(L, 2); + lua_pushboolean(L, lua_setmetatable(L, 1)); + return 1; +} + + +static int db_getfenv (lua_State *L) { + lua_getfenv(L, 1); + return 1; +} + + +static int db_setfenv (lua_State *L) { + luaL_checktype(L, 2, LUA_TTABLE); + lua_settop(L, 2); + if (lua_setfenv(L, 1) == 0) + luaL_error(L, LUA_QL("setfenv") + " cannot change environment of given object"); + return 1; +} + + +static void settabss (lua_State *L, const char *i, const char *v) { + lua_pushstring(L, v); + lua_setfield(L, -2, i); +} + + +static void settabsi (lua_State *L, const char *i, int v) { + lua_pushinteger(L, v); + lua_setfield(L, -2, i); +} + + +static lua_State *getthread (lua_State *L, int *arg) { + if (lua_isthread(L, 1)) { + *arg = 1; + return lua_tothread(L, 1); + } + else { + *arg = 0; + return L; + } +} + + +static void treatstackoption (lua_State *L, lua_State *L1, const char *fname) { + if (L == L1) { + lua_pushvalue(L, -2); + lua_remove(L, -3); + } + else + lua_xmove(L1, L, 1); + lua_setfield(L, -2, fname); +} + + +static int db_getinfo (lua_State *L) { + lua_Debug ar; + int arg; + lua_State *L1 = getthread(L, &arg); + const char *options = luaL_optstring(L, arg+2, "flnSu"); + if (lua_isnumber(L, arg+1)) { + if (!lua_getstack(L1, (int)lua_tointeger(L, arg+1), &ar)) { + lua_pushnil(L); /* level out of range */ + return 1; + } + } + else if (lua_isfunction(L, arg+1)) { + lua_pushfstring(L, ">%s", options); + options = lua_tostring(L, -1); + lua_pushvalue(L, arg+1); + lua_xmove(L, L1, 1); + } + else + return luaL_argerror(L, arg+1, "function or level expected"); + if (!lua_getinfo(L1, options, &ar)) + return luaL_argerror(L, arg+2, "invalid option"); + lua_createtable(L, 0, 2); + if (strchr(options, 'S')) { + settabss(L, "source", ar.source); + settabss(L, "short_src", ar.short_src); + settabsi(L, "linedefined", ar.linedefined); + settabsi(L, "lastlinedefined", ar.lastlinedefined); + settabss(L, "what", ar.what); + } + if (strchr(options, 'l')) + settabsi(L, "currentline", ar.currentline); + if (strchr(options, 'u')) + settabsi(L, "nups", ar.nups); + if (strchr(options, 'n')) { + settabss(L, "name", ar.name); + settabss(L, "namewhat", ar.namewhat); + } + if (strchr(options, 'L')) + treatstackoption(L, L1, "activelines"); + if (strchr(options, 'f')) + treatstackoption(L, L1, "func"); + return 1; /* return table */ +} + + +static int db_getlocal (lua_State *L) { + int arg; + lua_State *L1 = getthread(L, &arg); + lua_Debug ar; + const char *name; + if (!lua_getstack(L1, luaL_checkint(L, arg+1), &ar)) /* out of range? */ + return luaL_argerror(L, arg+1, "level out of range"); + name = lua_getlocal(L1, &ar, luaL_checkint(L, arg+2)); + if (name) { + lua_xmove(L1, L, 1); + lua_pushstring(L, name); + lua_pushvalue(L, -2); + return 2; + } + else { + lua_pushnil(L); + return 1; + } +} + + +static int db_setlocal (lua_State *L) { + int arg; + lua_State *L1 = getthread(L, &arg); + lua_Debug ar; + if (!lua_getstack(L1, luaL_checkint(L, arg+1), &ar)) /* out of range? */ + return luaL_argerror(L, arg+1, "level out of range"); + luaL_checkany(L, arg+3); + lua_settop(L, arg+3); + lua_xmove(L, L1, 1); + lua_pushstring(L, lua_setlocal(L1, &ar, luaL_checkint(L, arg+2))); + return 1; +} + + +static int auxupvalue (lua_State *L, int get) { + const char *name; + int n = luaL_checkint(L, 2); + luaL_checktype(L, 1, LUA_TFUNCTION); + if (lua_iscfunction(L, 1)) return 0; /* cannot touch C upvalues from Lua */ + name = get ? lua_getupvalue(L, 1, n) : lua_setupvalue(L, 1, n); + if (name == NULL) return 0; + lua_pushstring(L, name); + lua_insert(L, -(get+1)); + return get + 1; +} + + +static int db_getupvalue (lua_State *L) { + return auxupvalue(L, 1); +} + + +static int db_setupvalue (lua_State *L) { + luaL_checkany(L, 3); + return auxupvalue(L, 0); +} + + + +static const char KEY_HOOK = 'h'; + + +static void hookf (lua_State *L, lua_Debug *ar) { + static const char *const hooknames[] = + {"call", "return", "line", "count", "tail return"}; + lua_pushlightuserdata(L, (void *)&KEY_HOOK); + lua_rawget(L, LUA_REGISTRYINDEX); + lua_pushlightuserdata(L, L); + lua_rawget(L, -2); + if (lua_isfunction(L, -1)) { + lua_pushstring(L, hooknames[(int)ar->event]); + if (ar->currentline >= 0) + lua_pushinteger(L, ar->currentline); + else lua_pushnil(L); + lua_assert(lua_getinfo(L, "lS", ar)); + lua_call(L, 2, 0); + } +} + + +static int makemask (const char *smask, int count) { + int mask = 0; + if (strchr(smask, 'c')) mask |= LUA_MASKCALL; + if (strchr(smask, 'r')) mask |= LUA_MASKRET; + if (strchr(smask, 'l')) mask |= LUA_MASKLINE; + if (count > 0) mask |= LUA_MASKCOUNT; + return mask; +} + + +static char *unmakemask (int mask, char *smask) { + int i = 0; + if (mask & LUA_MASKCALL) smask[i++] = 'c'; + if (mask & LUA_MASKRET) smask[i++] = 'r'; + if (mask & LUA_MASKLINE) smask[i++] = 'l'; + smask[i] = '\0'; + return smask; +} + + +static void gethooktable (lua_State *L) { + lua_pushlightuserdata(L, (void *)&KEY_HOOK); + lua_rawget(L, LUA_REGISTRYINDEX); + if (!lua_istable(L, -1)) { + lua_pop(L, 1); + lua_createtable(L, 0, 1); + lua_pushlightuserdata(L, (void *)&KEY_HOOK); + lua_pushvalue(L, -2); + lua_rawset(L, LUA_REGISTRYINDEX); + } +} + + +static int db_sethook (lua_State *L) { + int arg, mask, count; + lua_Hook func; + lua_State *L1 = getthread(L, &arg); + if (lua_isnoneornil(L, arg+1)) { + lua_settop(L, arg+1); + func = NULL; mask = 0; count = 0; /* turn off hooks */ + } + else { + const char *smask = luaL_checkstring(L, arg+2); + luaL_checktype(L, arg+1, LUA_TFUNCTION); + count = luaL_optint(L, arg+3, 0); + func = hookf; mask = makemask(smask, count); + } + gethooktable(L); + lua_pushlightuserdata(L, L1); + lua_pushvalue(L, arg+1); + lua_rawset(L, -3); /* set new hook */ + lua_pop(L, 1); /* remove hook table */ + lua_sethook(L1, func, mask, count); /* set hooks */ + return 0; +} + + +static int db_gethook (lua_State *L) { + int arg; + lua_State *L1 = getthread(L, &arg); + char buff[5]; + int mask = lua_gethookmask(L1); + lua_Hook hook = lua_gethook(L1); + if (hook != NULL && hook != hookf) /* external hook? */ + lua_pushliteral(L, "external hook"); + else { + gethooktable(L); + lua_pushlightuserdata(L, L1); + lua_rawget(L, -2); /* get hook */ + lua_remove(L, -2); /* remove hook table */ + } + lua_pushstring(L, unmakemask(mask, buff)); + lua_pushinteger(L, lua_gethookcount(L1)); + return 3; +} + + +static int db_debug (lua_State *L) { + for (;;) { + char buffer[250]; + fputs("lua_debug> ", stderr); + if (fgets(buffer, sizeof(buffer), stdin) == 0 || + strcmp(buffer, "cont\n") == 0) + return 0; + if (luaL_loadbuffer(L, buffer, strlen(buffer), "=(debug command)") || + lua_pcall(L, 0, 0, 0)) { + fputs(lua_tostring(L, -1), stderr); + fputs("\n", stderr); + } + lua_settop(L, 0); /* remove eventual returns */ + } +} + + +#define LEVELS1 12 /* size of the first part of the stack */ +#define LEVELS2 10 /* size of the second part of the stack */ + +static int db_errorfb (lua_State *L) { + int level; + int firstpart = 1; /* still before eventual `...' */ + int arg; + lua_State *L1 = getthread(L, &arg); + lua_Debug ar; + if (lua_isnumber(L, arg+2)) { + level = (int)lua_tointeger(L, arg+2); + lua_pop(L, 1); + } + else + level = (L == L1) ? 1 : 0; /* level 0 may be this own function */ + if (lua_gettop(L) == arg) + lua_pushliteral(L, ""); + else if (!lua_isstring(L, arg+1)) return 1; /* message is not a string */ + else lua_pushliteral(L, "\n"); + lua_pushliteral(L, "stack traceback:"); + while (lua_getstack(L1, level++, &ar)) { + if (level > LEVELS1 && firstpart) { + /* no more than `LEVELS2' more levels? */ + if (!lua_getstack(L1, level+LEVELS2, &ar)) + level--; /* keep going */ + else { + lua_pushliteral(L, "\n\t..."); /* too many levels */ + while (lua_getstack(L1, level+LEVELS2, &ar)) /* find last levels */ + level++; + } + firstpart = 0; + continue; + } + lua_pushliteral(L, "\n\t"); + lua_getinfo(L1, "Snl", &ar); + lua_pushfstring(L, "%s:", ar.short_src); + if (ar.currentline > 0) + lua_pushfstring(L, "%d:", ar.currentline); + if (*ar.namewhat != '\0') /* is there a name? */ + lua_pushfstring(L, " in function " LUA_QS, ar.name); + else { + if (*ar.what == 'm') /* main? */ + lua_pushfstring(L, " in main chunk"); + else if (*ar.what == 'C' || *ar.what == 't') + lua_pushliteral(L, " ?"); /* C function or tail call */ + else + lua_pushfstring(L, " in function <%s:%d>", + ar.short_src, ar.linedefined); + } + lua_concat(L, lua_gettop(L) - arg); + } + lua_concat(L, lua_gettop(L) - arg); + return 1; +} + + +static const luaL_Reg dblib[] = { + {"debug", db_debug}, + {"getfenv", db_getfenv}, + {"gethook", db_gethook}, + {"getinfo", db_getinfo}, + {"getlocal", db_getlocal}, + {"getregistry", db_getregistry}, + {"getmetatable", db_getmetatable}, + {"getupvalue", db_getupvalue}, + {"setfenv", db_setfenv}, + {"sethook", db_sethook}, + {"setlocal", db_setlocal}, + {"setmetatable", db_setmetatable}, + {"setupvalue", db_setupvalue}, + {"traceback", db_errorfb}, + {NULL, NULL} +}; + + +LUALIB_API int luaopen_debug (lua_State *L) { + luaL_register(L, LUA_DBLIBNAME, dblib); + return 1; +} + diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/ldebug.c b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/ldebug.c new file mode 100644 index 00000000..50ad3d38 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/ldebug.c @@ -0,0 +1,638 @@ +/* +** $Id: ldebug.c,v 2.29.1.6 2008/05/08 16:56:26 roberto Exp $ +** Debug Interface +** See Copyright Notice in lua.h +*/ + + +#include +#include +#include + + +#define ldebug_c +#define LUA_CORE + +#include "lua.h" + +#include "lapi.h" +#include "lcode.h" +#include "ldebug.h" +#include "ldo.h" +#include "lfunc.h" +#include "lobject.h" +#include "lopcodes.h" +#include "lstate.h" +#include "lstring.h" +#include "ltable.h" +#include "ltm.h" +#include "lvm.h" + + + +static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name); + + +static int currentpc (lua_State *L, CallInfo *ci) { + if (!isLua(ci)) return -1; /* function is not a Lua function? */ + if (ci == L->ci) + ci->savedpc = L->savedpc; + return pcRel(ci->savedpc, ci_func(ci)->l.p); +} + + +static int currentline (lua_State *L, CallInfo *ci) { + int pc = currentpc(L, ci); + if (pc < 0) + return -1; /* only active lua functions have current-line information */ + else + return getline(ci_func(ci)->l.p, pc); +} + + +/* +** this function can be called asynchronous (e.g. during a signal) +*/ +LUA_API int lua_sethook (lua_State *L, lua_Hook func, int mask, int count) { + if (func == NULL || mask == 0) { /* turn off hooks? */ + mask = 0; + func = NULL; + } + L->hook = func; + L->basehookcount = count; + resethookcount(L); + L->hookmask = cast_byte(mask); + return 1; +} + + +LUA_API lua_Hook lua_gethook (lua_State *L) { + return L->hook; +} + + +LUA_API int lua_gethookmask (lua_State *L) { + return L->hookmask; +} + + +LUA_API int lua_gethookcount (lua_State *L) { + return L->basehookcount; +} + + +LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar) { + int status; + CallInfo *ci; + lua_lock(L); + for (ci = L->ci; level > 0 && ci > L->base_ci; ci--) { + level--; + if (f_isLua(ci)) /* Lua function? */ + level -= ci->tailcalls; /* skip lost tail calls */ + } + if (level == 0 && ci > L->base_ci) { /* level found? */ + status = 1; + ar->i_ci = cast_int(ci - L->base_ci); + } + else if (level < 0) { /* level is of a lost tail call? */ + status = 1; + ar->i_ci = 0; + } + else status = 0; /* no such level */ + lua_unlock(L); + return status; +} + + +static Proto *getluaproto (CallInfo *ci) { + return (isLua(ci) ? ci_func(ci)->l.p : NULL); +} + + +static const char *findlocal (lua_State *L, CallInfo *ci, int n) { + const char *name; + Proto *fp = getluaproto(ci); + if (fp && (name = luaF_getlocalname(fp, n, currentpc(L, ci))) != NULL) + return name; /* is a local variable in a Lua function */ + else { + StkId limit = (ci == L->ci) ? L->top : (ci+1)->func; + if (limit - ci->base >= n && n > 0) /* is 'n' inside 'ci' stack? */ + return "(*temporary)"; + else + return NULL; + } +} + + +LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) { + CallInfo *ci = L->base_ci + ar->i_ci; + const char *name = findlocal(L, ci, n); + lua_lock(L); + if (name) + luaA_pushobject(L, ci->base + (n - 1)); + lua_unlock(L); + return name; +} + + +LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) { + CallInfo *ci = L->base_ci + ar->i_ci; + const char *name = findlocal(L, ci, n); + lua_lock(L); + if (name) + setobjs2s(L, ci->base + (n - 1), L->top - 1); + L->top--; /* pop value */ + lua_unlock(L); + return name; +} + + +static void funcinfo (lua_Debug *ar, Closure *cl) { + if (cl->c.isC) { + ar->source = "=[C]"; + ar->linedefined = -1; + ar->lastlinedefined = -1; + ar->what = "C"; + } + else { + ar->source = getstr(cl->l.p->source); + ar->linedefined = cl->l.p->linedefined; + ar->lastlinedefined = cl->l.p->lastlinedefined; + ar->what = (ar->linedefined == 0) ? "main" : "Lua"; + } + luaO_chunkid(ar->short_src, ar->source, LUA_IDSIZE); +} + + +static void info_tailcall (lua_Debug *ar) { + ar->name = ar->namewhat = ""; + ar->what = "tail"; + ar->lastlinedefined = ar->linedefined = ar->currentline = -1; + ar->source = "=(tail call)"; + luaO_chunkid(ar->short_src, ar->source, LUA_IDSIZE); + ar->nups = 0; +} + + +static void collectvalidlines (lua_State *L, Closure *f) { + if (f == NULL || f->c.isC) { + setnilvalue(L->top); + } + else { + Table *t = luaH_new(L, 0, 0); + int *lineinfo = f->l.p->lineinfo; + int i; + for (i=0; il.p->sizelineinfo; i++) + setbvalue(luaH_setnum(L, t, lineinfo[i]), 1); + sethvalue(L, L->top, t); + } + incr_top(L); +} + + +static int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar, + Closure *f, CallInfo *ci) { + int status = 1; + if (f == NULL) { + info_tailcall(ar); + return status; + } + for (; *what; what++) { + switch (*what) { + case 'S': { + funcinfo(ar, f); + break; + } + case 'l': { + ar->currentline = (ci) ? currentline(L, ci) : -1; + break; + } + case 'u': { + ar->nups = f->c.nupvalues; + break; + } + case 'n': { + ar->namewhat = (ci) ? getfuncname(L, ci, &ar->name) : NULL; + if (ar->namewhat == NULL) { + ar->namewhat = ""; /* not found */ + ar->name = NULL; + } + break; + } + case 'L': + case 'f': /* handled by lua_getinfo */ + break; + default: status = 0; /* invalid option */ + } + } + return status; +} + + +LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) { + int status; + Closure *f = NULL; + CallInfo *ci = NULL; + lua_lock(L); + if (*what == '>') { + StkId func = L->top - 1; + luai_apicheck(L, ttisfunction(func)); + what++; /* skip the '>' */ + f = clvalue(func); + L->top--; /* pop function */ + } + else if (ar->i_ci != 0) { /* no tail call? */ + ci = L->base_ci + ar->i_ci; + lua_assert(ttisfunction(ci->func)); + f = clvalue(ci->func); + } + status = auxgetinfo(L, what, ar, f, ci); + if (strchr(what, 'f')) { + if (f == NULL) setnilvalue(L->top); + else setclvalue(L, L->top, f); + incr_top(L); + } + if (strchr(what, 'L')) + collectvalidlines(L, f); + lua_unlock(L); + return status; +} + + +/* +** {====================================================== +** Symbolic Execution and code checker +** ======================================================= +*/ + +#define check(x) if (!(x)) return 0; + +#define checkjump(pt,pc) check(0 <= pc && pc < pt->sizecode) + +#define checkreg(pt,reg) check((reg) < (pt)->maxstacksize) + + + +static int precheck (const Proto *pt) { + check(pt->maxstacksize <= MAXSTACK); + check(pt->numparams+(pt->is_vararg & VARARG_HASARG) <= pt->maxstacksize); + check(!(pt->is_vararg & VARARG_NEEDSARG) || + (pt->is_vararg & VARARG_HASARG)); + check(pt->sizeupvalues <= pt->nups); + check(pt->sizelineinfo == pt->sizecode || pt->sizelineinfo == 0); + check(pt->sizecode > 0 && GET_OPCODE(pt->code[pt->sizecode-1]) == OP_RETURN); + return 1; +} + + +#define checkopenop(pt,pc) luaG_checkopenop((pt)->code[(pc)+1]) + +int luaG_checkopenop (Instruction i) { + switch (GET_OPCODE(i)) { + case OP_CALL: + case OP_TAILCALL: + case OP_RETURN: + case OP_SETLIST: { + check(GETARG_B(i) == 0); + return 1; + } + default: return 0; /* invalid instruction after an open call */ + } +} + + +static int checkArgMode (const Proto *pt, int r, enum OpArgMask mode) { + switch (mode) { + case OpArgN: check(r == 0); break; + case OpArgU: break; + case OpArgR: checkreg(pt, r); break; + case OpArgK: + check(ISK(r) ? INDEXK(r) < pt->sizek : r < pt->maxstacksize); + break; + } + return 1; +} + + +static Instruction symbexec (const Proto *pt, int lastpc, int reg) { + int pc; + int last; /* stores position of last instruction that changed `reg' */ + last = pt->sizecode-1; /* points to final return (a `neutral' instruction) */ + check(precheck(pt)); + for (pc = 0; pc < lastpc; pc++) { + Instruction i = pt->code[pc]; + OpCode op = GET_OPCODE(i); + int a = GETARG_A(i); + int b = 0; + int c = 0; + check(op < NUM_OPCODES); + checkreg(pt, a); + switch (getOpMode(op)) { + case iABC: { + b = GETARG_B(i); + c = GETARG_C(i); + check(checkArgMode(pt, b, getBMode(op))); + check(checkArgMode(pt, c, getCMode(op))); + break; + } + case iABx: { + b = GETARG_Bx(i); + if (getBMode(op) == OpArgK) check(b < pt->sizek); + break; + } + case iAsBx: { + b = GETARG_sBx(i); + if (getBMode(op) == OpArgR) { + int dest = pc+1+b; + check(0 <= dest && dest < pt->sizecode); + if (dest > 0) { + int j; + /* check that it does not jump to a setlist count; this + is tricky, because the count from a previous setlist may + have the same value of an invalid setlist; so, we must + go all the way back to the first of them (if any) */ + for (j = 0; j < dest; j++) { + Instruction d = pt->code[dest-1-j]; + if (!(GET_OPCODE(d) == OP_SETLIST && GETARG_C(d) == 0)) break; + } + /* if 'j' is even, previous value is not a setlist (even if + it looks like one) */ + check((j&1) == 0); + } + } + break; + } + } + if (testAMode(op)) { + if (a == reg) last = pc; /* change register `a' */ + } + if (testTMode(op)) { + check(pc+2 < pt->sizecode); /* check skip */ + check(GET_OPCODE(pt->code[pc+1]) == OP_JMP); + } + switch (op) { + case OP_LOADBOOL: { + if (c == 1) { /* does it jump? */ + check(pc+2 < pt->sizecode); /* check its jump */ + check(GET_OPCODE(pt->code[pc+1]) != OP_SETLIST || + GETARG_C(pt->code[pc+1]) != 0); + } + break; + } + case OP_LOADNIL: { + if (a <= reg && reg <= b) + last = pc; /* set registers from `a' to `b' */ + break; + } + case OP_GETUPVAL: + case OP_SETUPVAL: { + check(b < pt->nups); + break; + } + case OP_GETGLOBAL: + case OP_SETGLOBAL: { + check(ttisstring(&pt->k[b])); + break; + } + case OP_SELF: { + checkreg(pt, a+1); + if (reg == a+1) last = pc; + break; + } + case OP_CONCAT: { + check(b < c); /* at least two operands */ + break; + } + case OP_TFORLOOP: { + check(c >= 1); /* at least one result (control variable) */ + checkreg(pt, a+2+c); /* space for results */ + if (reg >= a+2) last = pc; /* affect all regs above its base */ + break; + } + case OP_FORLOOP: + case OP_FORPREP: + checkreg(pt, a+3); + /* go through */ + case OP_JMP: { + int dest = pc+1+b; + /* not full check and jump is forward and do not skip `lastpc'? */ + if (reg != NO_REG && pc < dest && dest <= lastpc) + pc += b; /* do the jump */ + break; + } + case OP_CALL: + case OP_TAILCALL: { + if (b != 0) { + checkreg(pt, a+b-1); + } + c--; /* c = num. returns */ + if (c == LUA_MULTRET) { + check(checkopenop(pt, pc)); + } + else if (c != 0) + checkreg(pt, a+c-1); + if (reg >= a) last = pc; /* affect all registers above base */ + break; + } + case OP_RETURN: { + b--; /* b = num. returns */ + if (b > 0) checkreg(pt, a+b-1); + break; + } + case OP_SETLIST: { + if (b > 0) checkreg(pt, a + b); + if (c == 0) { + pc++; + check(pc < pt->sizecode - 1); + } + break; + } + case OP_CLOSURE: { + int nup, j; + check(b < pt->sizep); + nup = pt->p[b]->nups; + check(pc + nup < pt->sizecode); + for (j = 1; j <= nup; j++) { + OpCode op1 = GET_OPCODE(pt->code[pc + j]); + check(op1 == OP_GETUPVAL || op1 == OP_MOVE); + } + if (reg != NO_REG) /* tracing? */ + pc += nup; /* do not 'execute' these pseudo-instructions */ + break; + } + case OP_VARARG: { + check((pt->is_vararg & VARARG_ISVARARG) && + !(pt->is_vararg & VARARG_NEEDSARG)); + b--; + if (b == LUA_MULTRET) check(checkopenop(pt, pc)); + checkreg(pt, a+b-1); + break; + } + default: break; + } + } + return pt->code[last]; +} + +#undef check +#undef checkjump +#undef checkreg + +/* }====================================================== */ + + +int luaG_checkcode (const Proto *pt) { + return (symbexec(pt, pt->sizecode, NO_REG) != 0); +} + + +static const char *kname (Proto *p, int c) { + if (ISK(c) && ttisstring(&p->k[INDEXK(c)])) + return svalue(&p->k[INDEXK(c)]); + else + return "?"; +} + + +static const char *getobjname (lua_State *L, CallInfo *ci, int stackpos, + const char **name) { + if (isLua(ci)) { /* a Lua function? */ + Proto *p = ci_func(ci)->l.p; + int pc = currentpc(L, ci); + Instruction i; + *name = luaF_getlocalname(p, stackpos+1, pc); + if (*name) /* is a local? */ + return "local"; + i = symbexec(p, pc, stackpos); /* try symbolic execution */ + lua_assert(pc != -1); + switch (GET_OPCODE(i)) { + case OP_GETGLOBAL: { + int g = GETARG_Bx(i); /* global index */ + lua_assert(ttisstring(&p->k[g])); + *name = svalue(&p->k[g]); + return "global"; + } + case OP_MOVE: { + int a = GETARG_A(i); + int b = GETARG_B(i); /* move from `b' to `a' */ + if (b < a) + return getobjname(L, ci, b, name); /* get name for `b' */ + break; + } + case OP_GETTABLE: { + int k = GETARG_C(i); /* key index */ + *name = kname(p, k); + return "field"; + } + case OP_GETUPVAL: { + int u = GETARG_B(i); /* upvalue index */ + *name = p->upvalues ? getstr(p->upvalues[u]) : "?"; + return "upvalue"; + } + case OP_SELF: { + int k = GETARG_C(i); /* key index */ + *name = kname(p, k); + return "method"; + } + default: break; + } + } + return NULL; /* no useful name found */ +} + + +static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name) { + Instruction i; + if ((isLua(ci) && ci->tailcalls > 0) || !isLua(ci - 1)) + return NULL; /* calling function is not Lua (or is unknown) */ + ci--; /* calling function */ + i = ci_func(ci)->l.p->code[currentpc(L, ci)]; + if (GET_OPCODE(i) == OP_CALL || GET_OPCODE(i) == OP_TAILCALL || + GET_OPCODE(i) == OP_TFORLOOP) + return getobjname(L, ci, GETARG_A(i), name); + else + return NULL; /* no useful name can be found */ +} + + +/* only ANSI way to check whether a pointer points to an array */ +static int isinstack (CallInfo *ci, const TValue *o) { + StkId p; + for (p = ci->base; p < ci->top; p++) + if (o == p) return 1; + return 0; +} + + +void luaG_typeerror (lua_State *L, const TValue *o, const char *op) { + const char *name = NULL; + const char *t = luaT_typenames[ttype(o)]; + const char *kind = (isinstack(L->ci, o)) ? + getobjname(L, L->ci, cast_int(o - L->base), &name) : + NULL; + if (kind) + luaG_runerror(L, "attempt to %s %s " LUA_QS " (a %s value)", + op, kind, name, t); + else + luaG_runerror(L, "attempt to %s a %s value", op, t); +} + + +void luaG_concaterror (lua_State *L, StkId p1, StkId p2) { + if (ttisstring(p1) || ttisnumber(p1)) p1 = p2; + lua_assert(!ttisstring(p1) && !ttisnumber(p1)); + luaG_typeerror(L, p1, "concatenate"); +} + + +void luaG_aritherror (lua_State *L, const TValue *p1, const TValue *p2) { + TValue temp; + if (luaV_tonumber(p1, &temp) == NULL) + p2 = p1; /* first operand is wrong */ + luaG_typeerror(L, p2, "perform arithmetic on"); +} + + +int luaG_ordererror (lua_State *L, const TValue *p1, const TValue *p2) { + const char *t1 = luaT_typenames[ttype(p1)]; + const char *t2 = luaT_typenames[ttype(p2)]; + if (t1[2] == t2[2]) + luaG_runerror(L, "attempt to compare two %s values", t1); + else + luaG_runerror(L, "attempt to compare %s with %s", t1, t2); + return 0; +} + + +static void addinfo (lua_State *L, const char *msg) { + CallInfo *ci = L->ci; + if (isLua(ci)) { /* is Lua code? */ + char buff[LUA_IDSIZE]; /* add file:line information */ + int line = currentline(L, ci); + luaO_chunkid(buff, getstr(getluaproto(ci)->source), LUA_IDSIZE); + luaO_pushfstring(L, "%s:%d: %s", buff, line, msg); + } +} + + +void luaG_errormsg (lua_State *L) { + if (L->errfunc != 0) { /* is there an error handling function? */ + StkId errfunc = restorestack(L, L->errfunc); + if (!ttisfunction(errfunc)) luaD_throw(L, LUA_ERRERR); + setobjs2s(L, L->top, L->top - 1); /* move argument */ + setobjs2s(L, L->top - 1, errfunc); /* push function */ + incr_top(L); + luaD_call(L, L->top - 2, 1); /* call it */ + } + luaD_throw(L, LUA_ERRRUN); +} + + +void luaG_runerror (lua_State *L, const char *fmt, ...) { + va_list argp; + va_start(argp, fmt); + addinfo(L, luaO_pushvfstring(L, fmt, argp)); + va_end(argp); + luaG_errormsg(L); +} + diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/ldebug.h b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/ldebug.h new file mode 100644 index 00000000..ba28a972 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/ldebug.h @@ -0,0 +1,33 @@ +/* +** $Id: ldebug.h,v 2.3.1.1 2007/12/27 13:02:25 roberto Exp $ +** Auxiliary functions from Debug Interface module +** See Copyright Notice in lua.h +*/ + +#ifndef ldebug_h +#define ldebug_h + + +#include "lstate.h" + + +#define pcRel(pc, p) (cast(int, (pc) - (p)->code) - 1) + +#define getline(f,pc) (((f)->lineinfo) ? (f)->lineinfo[pc] : 0) + +#define resethookcount(L) (L->hookcount = L->basehookcount) + + +LUAI_FUNC void luaG_typeerror (lua_State *L, const TValue *o, + const char *opname); +LUAI_FUNC void luaG_concaterror (lua_State *L, StkId p1, StkId p2); +LUAI_FUNC void luaG_aritherror (lua_State *L, const TValue *p1, + const TValue *p2); +LUAI_FUNC int luaG_ordererror (lua_State *L, const TValue *p1, + const TValue *p2); +LUAI_FUNC void luaG_runerror (lua_State *L, const char *fmt, ...); +LUAI_FUNC void luaG_errormsg (lua_State *L); +LUAI_FUNC int luaG_checkcode (const Proto *pt); +LUAI_FUNC int luaG_checkopenop (Instruction i); + +#endif diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/ldo.c b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/ldo.c new file mode 100644 index 00000000..8de05f72 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/ldo.c @@ -0,0 +1,518 @@ +/* +** $Id: ldo.c,v 2.38.1.3 2008/01/18 22:31:22 roberto Exp $ +** Stack and Call structure of Lua +** See Copyright Notice in lua.h +*/ + + +#include +#include +#include + +#define ldo_c +#define LUA_CORE + +#include "lua.h" + +#include "ldebug.h" +#include "ldo.h" +#include "lfunc.h" +#include "lgc.h" +#include "lmem.h" +#include "lobject.h" +#include "lopcodes.h" +#include "lparser.h" +#include "lstate.h" +#include "lstring.h" +#include "ltable.h" +#include "ltm.h" +#include "lundump.h" +#include "lvm.h" +#include "lzio.h" + + + + +/* +** {====================================================== +** Error-recovery functions +** ======================================================= +*/ + + +/* chain list of long jump buffers */ +struct lua_longjmp { + struct lua_longjmp *previous; + luai_jmpbuf b; + volatile int status; /* error code */ +}; + + +void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop) { + switch (errcode) { + case LUA_ERRMEM: { + setsvalue2s(L, oldtop, luaS_newliteral(L, MEMERRMSG)); + break; + } + case LUA_ERRERR: { + setsvalue2s(L, oldtop, luaS_newliteral(L, "error in error handling")); + break; + } + case LUA_ERRSYNTAX: + case LUA_ERRRUN: { + setobjs2s(L, oldtop, L->top - 1); /* error message on current top */ + break; + } + } + L->top = oldtop + 1; +} + + +static void restore_stack_limit (lua_State *L) { + lua_assert(L->stack_last - L->stack == L->stacksize - EXTRA_STACK - 1); + if (L->size_ci > LUAI_MAXCALLS) { /* there was an overflow? */ + int inuse = cast_int(L->ci - L->base_ci); + if (inuse + 1 < LUAI_MAXCALLS) /* can `undo' overflow? */ + luaD_reallocCI(L, LUAI_MAXCALLS); + } +} + + +static void resetstack (lua_State *L, int status) { + L->ci = L->base_ci; + L->base = L->ci->base; + luaF_close(L, L->base); /* close eventual pending closures */ + luaD_seterrorobj(L, status, L->base); + L->nCcalls = L->baseCcalls; + L->allowhook = 1; + restore_stack_limit(L); + L->errfunc = 0; + L->errorJmp = NULL; +} + + +void luaD_throw (lua_State *L, int errcode) { + if (L->errorJmp) { + L->errorJmp->status = errcode; + LUAI_THROW(L, L->errorJmp); + } + else { + L->status = cast_byte(errcode); + if (G(L)->panic) { + resetstack(L, errcode); + lua_unlock(L); + G(L)->panic(L); + } + exit(EXIT_FAILURE); + } +} + + +int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud) { + struct lua_longjmp lj; + lj.status = 0; + lj.previous = L->errorJmp; /* chain new error handler */ + L->errorJmp = &lj; + LUAI_TRY(L, &lj, + (*f)(L, ud); + ); + L->errorJmp = lj.previous; /* restore old error handler */ + return lj.status; +} + +/* }====================================================== */ + + +static void correctstack (lua_State *L, TValue *oldstack) { + CallInfo *ci; + GCObject *up; + L->top = (L->top - oldstack) + L->stack; + for (up = L->openupval; up != NULL; up = up->gch.next) + gco2uv(up)->v = (gco2uv(up)->v - oldstack) + L->stack; + for (ci = L->base_ci; ci <= L->ci; ci++) { + ci->top = (ci->top - oldstack) + L->stack; + ci->base = (ci->base - oldstack) + L->stack; + ci->func = (ci->func - oldstack) + L->stack; + } + L->base = (L->base - oldstack) + L->stack; +} + + +void luaD_reallocstack (lua_State *L, int newsize) { + TValue *oldstack = L->stack; + int realsize = newsize + 1 + EXTRA_STACK; + lua_assert(L->stack_last - L->stack == L->stacksize - EXTRA_STACK - 1); + luaM_reallocvector(L, L->stack, L->stacksize, realsize, TValue); + L->stacksize = realsize; + L->stack_last = L->stack+newsize; + correctstack(L, oldstack); +} + + +void luaD_reallocCI (lua_State *L, int newsize) { + CallInfo *oldci = L->base_ci; + luaM_reallocvector(L, L->base_ci, L->size_ci, newsize, CallInfo); + L->size_ci = newsize; + L->ci = (L->ci - oldci) + L->base_ci; + L->end_ci = L->base_ci + L->size_ci - 1; +} + + +void luaD_growstack (lua_State *L, int n) { + if (n <= L->stacksize) /* double size is enough? */ + luaD_reallocstack(L, 2*L->stacksize); + else + luaD_reallocstack(L, L->stacksize + n); +} + + +static CallInfo *growCI (lua_State *L) { + if (L->size_ci > LUAI_MAXCALLS) /* overflow while handling overflow? */ + luaD_throw(L, LUA_ERRERR); + else { + luaD_reallocCI(L, 2*L->size_ci); + if (L->size_ci > LUAI_MAXCALLS) + luaG_runerror(L, "stack overflow"); + } + return ++L->ci; +} + + +void luaD_callhook (lua_State *L, int event, int line) { + lua_Hook hook = L->hook; + if (hook && L->allowhook) { + ptrdiff_t top = savestack(L, L->top); + ptrdiff_t ci_top = savestack(L, L->ci->top); + lua_Debug ar; + ar.event = event; + ar.currentline = line; + if (event == LUA_HOOKTAILRET) + ar.i_ci = 0; /* tail call; no debug information about it */ + else + ar.i_ci = cast_int(L->ci - L->base_ci); + luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */ + L->ci->top = L->top + LUA_MINSTACK; + lua_assert(L->ci->top <= L->stack_last); + L->allowhook = 0; /* cannot call hooks inside a hook */ + lua_unlock(L); + (*hook)(L, &ar); + lua_lock(L); + lua_assert(!L->allowhook); + L->allowhook = 1; + L->ci->top = restorestack(L, ci_top); + L->top = restorestack(L, top); + } +} + + +static StkId adjust_varargs (lua_State *L, Proto *p, int actual) { + int i; + int nfixargs = p->numparams; + Table *htab = NULL; + StkId base, fixed; + for (; actual < nfixargs; ++actual) + setnilvalue(L->top++); +#if defined(LUA_COMPAT_VARARG) + if (p->is_vararg & VARARG_NEEDSARG) { /* compat. with old-style vararg? */ + int nvar = actual - nfixargs; /* number of extra arguments */ + lua_assert(p->is_vararg & VARARG_HASARG); + luaC_checkGC(L); + htab = luaH_new(L, nvar, 1); /* create `arg' table */ + for (i=0; itop - nvar + i); + /* store counter in field `n' */ + setnvalue(luaH_setstr(L, htab, luaS_newliteral(L, "n")), cast_num(nvar)); + } +#endif + /* move fixed parameters to final position */ + fixed = L->top - actual; /* first fixed argument */ + base = L->top; /* final position of first argument */ + for (i=0; itop++, fixed+i); + setnilvalue(fixed+i); + } + /* add `arg' parameter */ + if (htab) { + sethvalue(L, L->top++, htab); + lua_assert(iswhite(obj2gco(htab))); + } + return base; +} + + +static StkId tryfuncTM (lua_State *L, StkId func) { + const TValue *tm = luaT_gettmbyobj(L, func, TM_CALL); + StkId p; + ptrdiff_t funcr = savestack(L, func); + if (!ttisfunction(tm)) + luaG_typeerror(L, func, "call"); + /* Open a hole inside the stack at `func' */ + for (p = L->top; p > func; p--) setobjs2s(L, p, p-1); + incr_top(L); + func = restorestack(L, funcr); /* previous call may change stack */ + setobj2s(L, func, tm); /* tag method is the new function to be called */ + return func; +} + + + +#define inc_ci(L) \ + ((L->ci == L->end_ci) ? growCI(L) : \ + (condhardstacktests(luaD_reallocCI(L, L->size_ci)), ++L->ci)) + + +int luaD_precall (lua_State *L, StkId func, int nresults) { + LClosure *cl; + ptrdiff_t funcr; + if (!ttisfunction(func)) /* `func' is not a function? */ + func = tryfuncTM(L, func); /* check the `function' tag method */ + funcr = savestack(L, func); + cl = &clvalue(func)->l; + L->ci->savedpc = L->savedpc; + if (!cl->isC) { /* Lua function? prepare its call */ + CallInfo *ci; + StkId st, base; + Proto *p = cl->p; + luaD_checkstack(L, p->maxstacksize); + func = restorestack(L, funcr); + if (!p->is_vararg) { /* no varargs? */ + base = func + 1; + if (L->top > base + p->numparams) + L->top = base + p->numparams; + } + else { /* vararg function */ + int nargs = cast_int(L->top - func) - 1; + base = adjust_varargs(L, p, nargs); + func = restorestack(L, funcr); /* previous call may change the stack */ + } + ci = inc_ci(L); /* now `enter' new function */ + ci->func = func; + L->base = ci->base = base; + ci->top = L->base + p->maxstacksize; + lua_assert(ci->top <= L->stack_last); + L->savedpc = p->code; /* starting point */ + ci->tailcalls = 0; + ci->nresults = nresults; + for (st = L->top; st < ci->top; st++) + setnilvalue(st); + L->top = ci->top; + if (L->hookmask & LUA_MASKCALL) { + L->savedpc++; /* hooks assume 'pc' is already incremented */ + luaD_callhook(L, LUA_HOOKCALL, -1); + L->savedpc--; /* correct 'pc' */ + } + return PCRLUA; + } + else { /* if is a C function, call it */ + CallInfo *ci; + int n; + luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */ + ci = inc_ci(L); /* now `enter' new function */ + ci->func = restorestack(L, funcr); + L->base = ci->base = ci->func + 1; + ci->top = L->top + LUA_MINSTACK; + lua_assert(ci->top <= L->stack_last); + ci->nresults = nresults; + if (L->hookmask & LUA_MASKCALL) + luaD_callhook(L, LUA_HOOKCALL, -1); + lua_unlock(L); + n = (*curr_func(L)->c.f)(L); /* do the actual call */ + lua_lock(L); + if (n < 0) /* yielding? */ + return PCRYIELD; + else { + luaD_poscall(L, L->top - n); + return PCRC; + } + } +} + + +static StkId callrethooks (lua_State *L, StkId firstResult) { + ptrdiff_t fr = savestack(L, firstResult); /* next call may change stack */ + luaD_callhook(L, LUA_HOOKRET, -1); + if (f_isLua(L->ci)) { /* Lua function? */ + while ((L->hookmask & LUA_MASKRET) && L->ci->tailcalls--) /* tail calls */ + luaD_callhook(L, LUA_HOOKTAILRET, -1); + } + return restorestack(L, fr); +} + + +int luaD_poscall (lua_State *L, StkId firstResult) { + StkId res; + int wanted, i; + CallInfo *ci; + if (L->hookmask & LUA_MASKRET) + firstResult = callrethooks(L, firstResult); + ci = L->ci--; + res = ci->func; /* res == final position of 1st result */ + wanted = ci->nresults; + L->base = (ci - 1)->base; /* restore base */ + L->savedpc = (ci - 1)->savedpc; /* restore savedpc */ + /* move results to correct place */ + for (i = wanted; i != 0 && firstResult < L->top; i--) + setobjs2s(L, res++, firstResult++); + while (i-- > 0) + setnilvalue(res++); + L->top = res; + return (wanted - LUA_MULTRET); /* 0 iff wanted == LUA_MULTRET */ +} + + +/* +** Call a function (C or Lua). The function to be called is at *func. +** The arguments are on the stack, right after the function. +** When returns, all the results are on the stack, starting at the original +** function position. +*/ +void luaD_call (lua_State *L, StkId func, int nResults) { + if (++L->nCcalls >= LUAI_MAXCCALLS) { + if (L->nCcalls == LUAI_MAXCCALLS) + luaG_runerror(L, "C stack overflow"); + else if (L->nCcalls >= (LUAI_MAXCCALLS + (LUAI_MAXCCALLS>>3))) + luaD_throw(L, LUA_ERRERR); /* error while handing stack error */ + } + if (luaD_precall(L, func, nResults) == PCRLUA) /* is a Lua function? */ + luaV_execute(L, 1); /* call it */ + L->nCcalls--; + luaC_checkGC(L); +} + + +static void resume (lua_State *L, void *ud) { + StkId firstArg = cast(StkId, ud); + CallInfo *ci = L->ci; + if (L->status == 0) { /* start coroutine? */ + lua_assert(ci == L->base_ci && firstArg > L->base); + if (luaD_precall(L, firstArg - 1, LUA_MULTRET) != PCRLUA) + return; + } + else { /* resuming from previous yield */ + lua_assert(L->status == LUA_YIELD); + L->status = 0; + if (!f_isLua(ci)) { /* `common' yield? */ + /* finish interrupted execution of `OP_CALL' */ + lua_assert(GET_OPCODE(*((ci-1)->savedpc - 1)) == OP_CALL || + GET_OPCODE(*((ci-1)->savedpc - 1)) == OP_TAILCALL); + if (luaD_poscall(L, firstArg)) /* complete it... */ + L->top = L->ci->top; /* and correct top if not multiple results */ + } + else /* yielded inside a hook: just continue its execution */ + L->base = L->ci->base; + } + luaV_execute(L, cast_int(L->ci - L->base_ci)); +} + + +static int resume_error (lua_State *L, const char *msg) { + L->top = L->ci->base; + setsvalue2s(L, L->top, luaS_new(L, msg)); + incr_top(L); + lua_unlock(L); + return LUA_ERRRUN; +} + + +LUA_API int lua_resume (lua_State *L, int nargs) { + int status; + lua_lock(L); + if (L->status != LUA_YIELD && (L->status != 0 || L->ci != L->base_ci)) + return resume_error(L, "cannot resume non-suspended coroutine"); + if (L->nCcalls >= LUAI_MAXCCALLS) + return resume_error(L, "C stack overflow"); + luai_userstateresume(L, nargs); + lua_assert(L->errfunc == 0); + L->baseCcalls = ++L->nCcalls; + status = luaD_rawrunprotected(L, resume, L->top - nargs); + if (status != 0) { /* error? */ + L->status = cast_byte(status); /* mark thread as `dead' */ + luaD_seterrorobj(L, status, L->top); + L->ci->top = L->top; + } + else { + lua_assert(L->nCcalls == L->baseCcalls); + status = L->status; + } + --L->nCcalls; + lua_unlock(L); + return status; +} + + +LUA_API int lua_yield (lua_State *L, int nresults) { + luai_userstateyield(L, nresults); + lua_lock(L); + if (L->nCcalls > L->baseCcalls) + luaG_runerror(L, "attempt to yield across metamethod/C-call boundary"); + L->base = L->top - nresults; /* protect stack slots below */ + L->status = LUA_YIELD; + lua_unlock(L); + return -1; +} + + +int luaD_pcall (lua_State *L, Pfunc func, void *u, + ptrdiff_t old_top, ptrdiff_t ef) { + int status; + unsigned short oldnCcalls = L->nCcalls; + ptrdiff_t old_ci = saveci(L, L->ci); + lu_byte old_allowhooks = L->allowhook; + ptrdiff_t old_errfunc = L->errfunc; + L->errfunc = ef; + status = luaD_rawrunprotected(L, func, u); + if (status != 0) { /* an error occurred? */ + StkId oldtop = restorestack(L, old_top); + luaF_close(L, oldtop); /* close eventual pending closures */ + luaD_seterrorobj(L, status, oldtop); + L->nCcalls = oldnCcalls; + L->ci = restoreci(L, old_ci); + L->base = L->ci->base; + L->savedpc = L->ci->savedpc; + L->allowhook = old_allowhooks; + restore_stack_limit(L); + } + L->errfunc = old_errfunc; + return status; +} + + + +/* +** Execute a protected parser. +*/ +struct SParser { /* data to `f_parser' */ + ZIO *z; + Mbuffer buff; /* buffer to be used by the scanner */ + const char *name; +}; + +static void f_parser (lua_State *L, void *ud) { + int i; + Proto *tf; + Closure *cl; + struct SParser *p = cast(struct SParser *, ud); + int c = luaZ_lookahead(p->z); + luaC_checkGC(L); + tf = ((c == LUA_SIGNATURE[0]) ? luaU_undump : luaY_parser)(L, p->z, + &p->buff, p->name); + cl = luaF_newLclosure(L, tf->nups, hvalue(gt(L))); + cl->l.p = tf; + for (i = 0; i < tf->nups; i++) /* initialize eventual upvalues */ + cl->l.upvals[i] = luaF_newupval(L); + setclvalue(L, L->top, cl); + incr_top(L); +} + + +int luaD_protectedparser (lua_State *L, ZIO *z, const char *name) { + struct SParser p; + int status; + p.z = z; p.name = name; + luaZ_initbuffer(L, &p.buff); + status = luaD_pcall(L, f_parser, &p, savestack(L, L->top), L->errfunc); + luaZ_freebuffer(L, &p.buff); + return status; +} + + diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/ldo.h b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/ldo.h new file mode 100644 index 00000000..98fddac5 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/ldo.h @@ -0,0 +1,57 @@ +/* +** $Id: ldo.h,v 2.7.1.1 2007/12/27 13:02:25 roberto Exp $ +** Stack and Call structure of Lua +** See Copyright Notice in lua.h +*/ + +#ifndef ldo_h +#define ldo_h + + +#include "lobject.h" +#include "lstate.h" +#include "lzio.h" + + +#define luaD_checkstack(L,n) \ + if ((char *)L->stack_last - (char *)L->top <= (n)*(int)sizeof(TValue)) \ + luaD_growstack(L, n); \ + else condhardstacktests(luaD_reallocstack(L, L->stacksize - EXTRA_STACK - 1)); + + +#define incr_top(L) {luaD_checkstack(L,1); L->top++;} + +#define savestack(L,p) ((char *)(p) - (char *)L->stack) +#define restorestack(L,n) ((TValue *)((char *)L->stack + (n))) + +#define saveci(L,p) ((char *)(p) - (char *)L->base_ci) +#define restoreci(L,n) ((CallInfo *)((char *)L->base_ci + (n))) + + +/* results from luaD_precall */ +#define PCRLUA 0 /* initiated a call to a Lua function */ +#define PCRC 1 /* did a call to a C function */ +#define PCRYIELD 2 /* C funtion yielded */ + + +/* type of protected functions, to be ran by `runprotected' */ +typedef void (*Pfunc) (lua_State *L, void *ud); + +LUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name); +LUAI_FUNC void luaD_callhook (lua_State *L, int event, int line); +LUAI_FUNC int luaD_precall (lua_State *L, StkId func, int nresults); +LUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults); +LUAI_FUNC int luaD_pcall (lua_State *L, Pfunc func, void *u, + ptrdiff_t oldtop, ptrdiff_t ef); +LUAI_FUNC int luaD_poscall (lua_State *L, StkId firstResult); +LUAI_FUNC void luaD_reallocCI (lua_State *L, int newsize); +LUAI_FUNC void luaD_reallocstack (lua_State *L, int newsize); +LUAI_FUNC void luaD_growstack (lua_State *L, int n); + +LUAI_FUNC void luaD_throw (lua_State *L, int errcode); +LUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud); + +LUAI_FUNC void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop); + +#endif + diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/ldump.c b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/ldump.c new file mode 100644 index 00000000..c9d3d487 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/ldump.c @@ -0,0 +1,164 @@ +/* +** $Id: ldump.c,v 2.8.1.1 2007/12/27 13:02:25 roberto Exp $ +** save precompiled Lua chunks +** See Copyright Notice in lua.h +*/ + +#include + +#define ldump_c +#define LUA_CORE + +#include "lua.h" + +#include "lobject.h" +#include "lstate.h" +#include "lundump.h" + +typedef struct { + lua_State* L; + lua_Writer writer; + void* data; + int strip; + int status; +} DumpState; + +#define DumpMem(b,n,size,D) DumpBlock(b,(n)*(size),D) +#define DumpVar(x,D) DumpMem(&x,1,sizeof(x),D) + +static void DumpBlock(const void* b, size_t size, DumpState* D) +{ + if (D->status==0) + { + lua_unlock(D->L); + D->status=(*D->writer)(D->L,b,size,D->data); + lua_lock(D->L); + } +} + +static void DumpChar(int y, DumpState* D) +{ + char x=(char)y; + DumpVar(x,D); +} + +static void DumpInt(int x, DumpState* D) +{ + DumpVar(x,D); +} + +static void DumpNumber(lua_Number x, DumpState* D) +{ + DumpVar(x,D); +} + +static void DumpVector(const void* b, int n, size_t size, DumpState* D) +{ + DumpInt(n,D); + DumpMem(b,n,size,D); +} + +static void DumpString(const TString* s, DumpState* D) +{ + if (s==NULL || getstr(s)==NULL) + { + size_t size=0; + DumpVar(size,D); + } + else + { + size_t size=s->tsv.len+1; /* include trailing '\0' */ + DumpVar(size,D); + DumpBlock(getstr(s),size,D); + } +} + +#define DumpCode(f,D) DumpVector(f->code,f->sizecode,sizeof(Instruction),D) + +static void DumpFunction(const Proto* f, const TString* p, DumpState* D); + +static void DumpConstants(const Proto* f, DumpState* D) +{ + int i,n=f->sizek; + DumpInt(n,D); + for (i=0; ik[i]; + DumpChar(ttype(o),D); + switch (ttype(o)) + { + case LUA_TNIL: + break; + case LUA_TBOOLEAN: + DumpChar(bvalue(o),D); + break; + case LUA_TNUMBER: + DumpNumber(nvalue(o),D); + break; + case LUA_TSTRING: + DumpString(rawtsvalue(o),D); + break; + default: + lua_assert(0); /* cannot happen */ + break; + } + } + n=f->sizep; + DumpInt(n,D); + for (i=0; ip[i],f->source,D); +} + +static void DumpDebug(const Proto* f, DumpState* D) +{ + int i,n; + n= (D->strip) ? 0 : f->sizelineinfo; + DumpVector(f->lineinfo,n,sizeof(int),D); + n= (D->strip) ? 0 : f->sizelocvars; + DumpInt(n,D); + for (i=0; ilocvars[i].varname,D); + DumpInt(f->locvars[i].startpc,D); + DumpInt(f->locvars[i].endpc,D); + } + n= (D->strip) ? 0 : f->sizeupvalues; + DumpInt(n,D); + for (i=0; iupvalues[i],D); +} + +static void DumpFunction(const Proto* f, const TString* p, DumpState* D) +{ + DumpString((f->source==p || D->strip) ? NULL : f->source,D); + DumpInt(f->linedefined,D); + DumpInt(f->lastlinedefined,D); + DumpChar(f->nups,D); + DumpChar(f->numparams,D); + DumpChar(f->is_vararg,D); + DumpChar(f->maxstacksize,D); + DumpCode(f,D); + DumpConstants(f,D); + DumpDebug(f,D); +} + +static void DumpHeader(DumpState* D) +{ + char h[LUAC_HEADERSIZE]; + luaU_header(h); + DumpBlock(h,LUAC_HEADERSIZE,D); +} + +/* +** dump Lua function as precompiled chunk +*/ +int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip) +{ + DumpState D; + D.L=L; + D.writer=w; + D.data=data; + D.strip=strip; + D.status=0; + DumpHeader(&D); + DumpFunction(f,NULL,&D); + return D.status; +} diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lfunc.c b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lfunc.c new file mode 100644 index 00000000..813e88f5 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lfunc.c @@ -0,0 +1,174 @@ +/* +** $Id: lfunc.c,v 2.12.1.2 2007/12/28 14:58:43 roberto Exp $ +** Auxiliary functions to manipulate prototypes and closures +** See Copyright Notice in lua.h +*/ + + +#include + +#define lfunc_c +#define LUA_CORE + +#include "lua.h" + +#include "lfunc.h" +#include "lgc.h" +#include "lmem.h" +#include "lobject.h" +#include "lstate.h" + + + +Closure *luaF_newCclosure (lua_State *L, int nelems, Table *e) { + Closure *c = cast(Closure *, luaM_malloc(L, sizeCclosure(nelems))); + luaC_link(L, obj2gco(c), LUA_TFUNCTION); + c->c.isC = 1; + c->c.env = e; + c->c.nupvalues = cast_byte(nelems); + return c; +} + + +Closure *luaF_newLclosure (lua_State *L, int nelems, Table *e) { + Closure *c = cast(Closure *, luaM_malloc(L, sizeLclosure(nelems))); + luaC_link(L, obj2gco(c), LUA_TFUNCTION); + c->l.isC = 0; + c->l.env = e; + c->l.nupvalues = cast_byte(nelems); + while (nelems--) c->l.upvals[nelems] = NULL; + return c; +} + + +UpVal *luaF_newupval (lua_State *L) { + UpVal *uv = luaM_new(L, UpVal); + luaC_link(L, obj2gco(uv), LUA_TUPVAL); + uv->v = &uv->u.value; + setnilvalue(uv->v); + return uv; +} + + +UpVal *luaF_findupval (lua_State *L, StkId level) { + global_State *g = G(L); + GCObject **pp = &L->openupval; + UpVal *p; + UpVal *uv; + while (*pp != NULL && (p = ngcotouv(*pp))->v >= level) { + lua_assert(p->v != &p->u.value); + if (p->v == level) { /* found a corresponding upvalue? */ + if (isdead(g, obj2gco(p))) /* is it dead? */ + changewhite(obj2gco(p)); /* ressurect it */ + return p; + } + pp = &p->next; + } + uv = luaM_new(L, UpVal); /* not found: create a new one */ + uv->tt = LUA_TUPVAL; + uv->marked = luaC_white(g); + uv->v = level; /* current value lives in the stack */ + uv->next = *pp; /* chain it in the proper position */ + *pp = obj2gco(uv); + uv->u.l.prev = &g->uvhead; /* double link it in `uvhead' list */ + uv->u.l.next = g->uvhead.u.l.next; + uv->u.l.next->u.l.prev = uv; + g->uvhead.u.l.next = uv; + lua_assert(uv->u.l.next->u.l.prev == uv && uv->u.l.prev->u.l.next == uv); + return uv; +} + + +static void unlinkupval (UpVal *uv) { + lua_assert(uv->u.l.next->u.l.prev == uv && uv->u.l.prev->u.l.next == uv); + uv->u.l.next->u.l.prev = uv->u.l.prev; /* remove from `uvhead' list */ + uv->u.l.prev->u.l.next = uv->u.l.next; +} + + +void luaF_freeupval (lua_State *L, UpVal *uv) { + if (uv->v != &uv->u.value) /* is it open? */ + unlinkupval(uv); /* remove from open list */ + luaM_free(L, uv); /* free upvalue */ +} + + +void luaF_close (lua_State *L, StkId level) { + UpVal *uv; + global_State *g = G(L); + while (L->openupval != NULL && (uv = ngcotouv(L->openupval))->v >= level) { + GCObject *o = obj2gco(uv); + lua_assert(!isblack(o) && uv->v != &uv->u.value); + L->openupval = uv->next; /* remove from `open' list */ + if (isdead(g, o)) + luaF_freeupval(L, uv); /* free upvalue */ + else { + unlinkupval(uv); + setobj(L, &uv->u.value, uv->v); + uv->v = &uv->u.value; /* now current value lives here */ + luaC_linkupval(L, uv); /* link upvalue into `gcroot' list */ + } + } +} + + +Proto *luaF_newproto (lua_State *L) { + Proto *f = luaM_new(L, Proto); + luaC_link(L, obj2gco(f), LUA_TPROTO); + f->k = NULL; + f->sizek = 0; + f->p = NULL; + f->sizep = 0; + f->code = NULL; + f->sizecode = 0; + f->sizelineinfo = 0; + f->sizeupvalues = 0; + f->nups = 0; + f->upvalues = NULL; + f->numparams = 0; + f->is_vararg = 0; + f->maxstacksize = 0; + f->lineinfo = NULL; + f->sizelocvars = 0; + f->locvars = NULL; + f->linedefined = 0; + f->lastlinedefined = 0; + f->source = NULL; + return f; +} + + +void luaF_freeproto (lua_State *L, Proto *f) { + luaM_freearray(L, f->code, f->sizecode, Instruction); + luaM_freearray(L, f->p, f->sizep, Proto *); + luaM_freearray(L, f->k, f->sizek, TValue); + luaM_freearray(L, f->lineinfo, f->sizelineinfo, int); + luaM_freearray(L, f->locvars, f->sizelocvars, struct LocVar); + luaM_freearray(L, f->upvalues, f->sizeupvalues, TString *); + luaM_free(L, f); +} + + +void luaF_freeclosure (lua_State *L, Closure *c) { + int size = (c->c.isC) ? sizeCclosure(c->c.nupvalues) : + sizeLclosure(c->l.nupvalues); + luaM_freemem(L, c, size); +} + + +/* +** Look for n-th local variable at line `line' in function `func'. +** Returns NULL if not found. +*/ +const char *luaF_getlocalname (const Proto *f, int local_number, int pc) { + int i; + for (i = 0; isizelocvars && f->locvars[i].startpc <= pc; i++) { + if (pc < f->locvars[i].endpc) { /* is variable active? */ + local_number--; + if (local_number == 0) + return getstr(f->locvars[i].varname); + } + } + return NULL; /* not found */ +} + diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lfunc.h b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lfunc.h new file mode 100644 index 00000000..a68cf515 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lfunc.h @@ -0,0 +1,34 @@ +/* +** $Id: lfunc.h,v 2.4.1.1 2007/12/27 13:02:25 roberto Exp $ +** Auxiliary functions to manipulate prototypes and closures +** See Copyright Notice in lua.h +*/ + +#ifndef lfunc_h +#define lfunc_h + + +#include "lobject.h" + + +#define sizeCclosure(n) (cast(int, sizeof(CClosure)) + \ + cast(int, sizeof(TValue)*((n)-1))) + +#define sizeLclosure(n) (cast(int, sizeof(LClosure)) + \ + cast(int, sizeof(TValue *)*((n)-1))) + + +LUAI_FUNC Proto *luaF_newproto (lua_State *L); +LUAI_FUNC Closure *luaF_newCclosure (lua_State *L, int nelems, Table *e); +LUAI_FUNC Closure *luaF_newLclosure (lua_State *L, int nelems, Table *e); +LUAI_FUNC UpVal *luaF_newupval (lua_State *L); +LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level); +LUAI_FUNC void luaF_close (lua_State *L, StkId level); +LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f); +LUAI_FUNC void luaF_freeclosure (lua_State *L, Closure *c); +LUAI_FUNC void luaF_freeupval (lua_State *L, UpVal *uv); +LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number, + int pc); + + +#endif diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lgc.c b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lgc.c new file mode 100644 index 00000000..d9e0b782 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lgc.c @@ -0,0 +1,711 @@ +/* +** $Id: lgc.c,v 2.38.1.1 2007/12/27 13:02:25 roberto Exp $ +** Garbage Collector +** See Copyright Notice in lua.h +*/ + +#include + +#define lgc_c +#define LUA_CORE + +#include "lua.h" + +#include "ldebug.h" +#include "ldo.h" +#include "lfunc.h" +#include "lgc.h" +#include "lmem.h" +#include "lobject.h" +#include "lstate.h" +#include "lstring.h" +#include "ltable.h" +#include "ltm.h" + + +#define GCSTEPSIZE 1024u +#define GCSWEEPMAX 40 +#define GCSWEEPCOST 10 +#define GCFINALIZECOST 100 + + +#define maskmarks cast_byte(~(bitmask(BLACKBIT)|WHITEBITS)) + +#define makewhite(g,x) \ + ((x)->gch.marked = cast_byte(((x)->gch.marked & maskmarks) | luaC_white(g))) + +#define white2gray(x) reset2bits((x)->gch.marked, WHITE0BIT, WHITE1BIT) +#define black2gray(x) resetbit((x)->gch.marked, BLACKBIT) + +#define stringmark(s) reset2bits((s)->tsv.marked, WHITE0BIT, WHITE1BIT) + + +#define isfinalized(u) testbit((u)->marked, FINALIZEDBIT) +#define markfinalized(u) l_setbit((u)->marked, FINALIZEDBIT) + + +#define KEYWEAK bitmask(KEYWEAKBIT) +#define VALUEWEAK bitmask(VALUEWEAKBIT) + + + +#define markvalue(g,o) { checkconsistency(o); \ + if (iscollectable(o) && iswhite(gcvalue(o))) reallymarkobject(g,gcvalue(o)); } + +#define markobject(g,t) { if (iswhite(obj2gco(t))) \ + reallymarkobject(g, obj2gco(t)); } + + +#define setthreshold(g) (g->GCthreshold = (g->estimate/100) * g->gcpause) + + +static void removeentry (Node *n) { + lua_assert(ttisnil(gval(n))); + if (iscollectable(gkey(n))) + setttype(gkey(n), LUA_TDEADKEY); /* dead key; remove it */ +} + + +static void reallymarkobject (global_State *g, GCObject *o) { + lua_assert(iswhite(o) && !isdead(g, o)); + white2gray(o); + switch (o->gch.tt) { + case LUA_TSTRING: { + return; + } + case LUA_TUSERDATA: { + Table *mt = gco2u(o)->metatable; + gray2black(o); /* udata are never gray */ + if (mt) markobject(g, mt); + markobject(g, gco2u(o)->env); + return; + } + case LUA_TUPVAL: { + UpVal *uv = gco2uv(o); + markvalue(g, uv->v); + if (uv->v == &uv->u.value) /* closed? */ + gray2black(o); /* open upvalues are never black */ + return; + } + case LUA_TFUNCTION: { + gco2cl(o)->c.gclist = g->gray; + g->gray = o; + break; + } + case LUA_TTABLE: { + gco2h(o)->gclist = g->gray; + g->gray = o; + break; + } + case LUA_TTHREAD: { + gco2th(o)->gclist = g->gray; + g->gray = o; + break; + } + case LUA_TPROTO: { + gco2p(o)->gclist = g->gray; + g->gray = o; + break; + } + default: lua_assert(0); + } +} + + +static void marktmu (global_State *g) { + GCObject *u = g->tmudata; + if (u) { + do { + u = u->gch.next; + makewhite(g, u); /* may be marked, if left from previous GC */ + reallymarkobject(g, u); + } while (u != g->tmudata); + } +} + + +/* move `dead' udata that need finalization to list `tmudata' */ +size_t luaC_separateudata (lua_State *L, int all) { + global_State *g = G(L); + size_t deadmem = 0; + GCObject **p = &g->mainthread->next; + GCObject *curr; + while ((curr = *p) != NULL) { + if (!(iswhite(curr) || all) || isfinalized(gco2u(curr))) + p = &curr->gch.next; /* don't bother with them */ + else if (fasttm(L, gco2u(curr)->metatable, TM_GC) == NULL) { + markfinalized(gco2u(curr)); /* don't need finalization */ + p = &curr->gch.next; + } + else { /* must call its gc method */ + deadmem += sizeudata(gco2u(curr)); + markfinalized(gco2u(curr)); + *p = curr->gch.next; + /* link `curr' at the end of `tmudata' list */ + if (g->tmudata == NULL) /* list is empty? */ + g->tmudata = curr->gch.next = curr; /* creates a circular list */ + else { + curr->gch.next = g->tmudata->gch.next; + g->tmudata->gch.next = curr; + g->tmudata = curr; + } + } + } + return deadmem; +} + + +static int traversetable (global_State *g, Table *h) { + int i; + int weakkey = 0; + int weakvalue = 0; + const TValue *mode; + if (h->metatable) + markobject(g, h->metatable); + mode = gfasttm(g, h->metatable, TM_MODE); + if (mode && ttisstring(mode)) { /* is there a weak mode? */ + weakkey = (strchr(svalue(mode), 'k') != NULL); + weakvalue = (strchr(svalue(mode), 'v') != NULL); + if (weakkey || weakvalue) { /* is really weak? */ + h->marked &= ~(KEYWEAK | VALUEWEAK); /* clear bits */ + h->marked |= cast_byte((weakkey << KEYWEAKBIT) | + (weakvalue << VALUEWEAKBIT)); + h->gclist = g->weak; /* must be cleared after GC, ... */ + g->weak = obj2gco(h); /* ... so put in the appropriate list */ + } + } + if (weakkey && weakvalue) return 1; + if (!weakvalue) { + i = h->sizearray; + while (i--) + markvalue(g, &h->array[i]); + } + i = sizenode(h); + while (i--) { + Node *n = gnode(h, i); + lua_assert(ttype(gkey(n)) != LUA_TDEADKEY || ttisnil(gval(n))); + if (ttisnil(gval(n))) + removeentry(n); /* remove empty entries */ + else { + lua_assert(!ttisnil(gkey(n))); + if (!weakkey) markvalue(g, gkey(n)); + if (!weakvalue) markvalue(g, gval(n)); + } + } + return weakkey || weakvalue; +} + + +/* +** All marks are conditional because a GC may happen while the +** prototype is still being created +*/ +static void traverseproto (global_State *g, Proto *f) { + int i; + if (f->source) stringmark(f->source); + for (i=0; isizek; i++) /* mark literals */ + markvalue(g, &f->k[i]); + for (i=0; isizeupvalues; i++) { /* mark upvalue names */ + if (f->upvalues[i]) + stringmark(f->upvalues[i]); + } + for (i=0; isizep; i++) { /* mark nested protos */ + if (f->p[i]) + markobject(g, f->p[i]); + } + for (i=0; isizelocvars; i++) { /* mark local-variable names */ + if (f->locvars[i].varname) + stringmark(f->locvars[i].varname); + } +} + + + +static void traverseclosure (global_State *g, Closure *cl) { + markobject(g, cl->c.env); + if (cl->c.isC) { + int i; + for (i=0; ic.nupvalues; i++) /* mark its upvalues */ + markvalue(g, &cl->c.upvalue[i]); + } + else { + int i; + lua_assert(cl->l.nupvalues == cl->l.p->nups); + markobject(g, cl->l.p); + for (i=0; il.nupvalues; i++) /* mark its upvalues */ + markobject(g, cl->l.upvals[i]); + } +} + + +static void checkstacksizes (lua_State *L, StkId max) { + int ci_used = cast_int(L->ci - L->base_ci); /* number of `ci' in use */ + int s_used = cast_int(max - L->stack); /* part of stack in use */ + if (L->size_ci > LUAI_MAXCALLS) /* handling overflow? */ + return; /* do not touch the stacks */ + if (4*ci_used < L->size_ci && 2*BASIC_CI_SIZE < L->size_ci) + luaD_reallocCI(L, L->size_ci/2); /* still big enough... */ + condhardstacktests(luaD_reallocCI(L, ci_used + 1)); + if (4*s_used < L->stacksize && + 2*(BASIC_STACK_SIZE+EXTRA_STACK) < L->stacksize) + luaD_reallocstack(L, L->stacksize/2); /* still big enough... */ + condhardstacktests(luaD_reallocstack(L, s_used)); +} + + +static void traversestack (global_State *g, lua_State *l) { + StkId o, lim; + CallInfo *ci; + markvalue(g, gt(l)); + lim = l->top; + for (ci = l->base_ci; ci <= l->ci; ci++) { + lua_assert(ci->top <= l->stack_last); + if (lim < ci->top) lim = ci->top; + } + for (o = l->stack; o < l->top; o++) + markvalue(g, o); + for (; o <= lim; o++) + setnilvalue(o); + checkstacksizes(l, lim); +} + + +/* +** traverse one gray object, turning it to black. +** Returns `quantity' traversed. +*/ +static l_mem propagatemark (global_State *g) { + GCObject *o = g->gray; + lua_assert(isgray(o)); + gray2black(o); + switch (o->gch.tt) { + case LUA_TTABLE: { + Table *h = gco2h(o); + g->gray = h->gclist; + if (traversetable(g, h)) /* table is weak? */ + black2gray(o); /* keep it gray */ + return sizeof(Table) + sizeof(TValue) * h->sizearray + + sizeof(Node) * sizenode(h); + } + case LUA_TFUNCTION: { + Closure *cl = gco2cl(o); + g->gray = cl->c.gclist; + traverseclosure(g, cl); + return (cl->c.isC) ? sizeCclosure(cl->c.nupvalues) : + sizeLclosure(cl->l.nupvalues); + } + case LUA_TTHREAD: { + lua_State *th = gco2th(o); + g->gray = th->gclist; + th->gclist = g->grayagain; + g->grayagain = o; + black2gray(o); + traversestack(g, th); + return sizeof(lua_State) + sizeof(TValue) * th->stacksize + + sizeof(CallInfo) * th->size_ci; + } + case LUA_TPROTO: { + Proto *p = gco2p(o); + g->gray = p->gclist; + traverseproto(g, p); + return sizeof(Proto) + sizeof(Instruction) * p->sizecode + + sizeof(Proto *) * p->sizep + + sizeof(TValue) * p->sizek + + sizeof(int) * p->sizelineinfo + + sizeof(LocVar) * p->sizelocvars + + sizeof(TString *) * p->sizeupvalues; + } + default: lua_assert(0); return 0; + } +} + + +static size_t propagateall (global_State *g) { + size_t m = 0; + while (g->gray) m += propagatemark(g); + return m; +} + + +/* +** The next function tells whether a key or value can be cleared from +** a weak table. Non-collectable objects are never removed from weak +** tables. Strings behave as `values', so are never removed too. for +** other objects: if really collected, cannot keep them; for userdata +** being finalized, keep them in keys, but not in values +*/ +static int iscleared (const TValue *o, int iskey) { + if (!iscollectable(o)) return 0; + if (ttisstring(o)) { + stringmark(rawtsvalue(o)); /* strings are `values', so are never weak */ + return 0; + } + return iswhite(gcvalue(o)) || + (ttisuserdata(o) && (!iskey && isfinalized(uvalue(o)))); +} + + +/* +** clear collected entries from weaktables +*/ +static void cleartable (GCObject *l) { + while (l) { + Table *h = gco2h(l); + int i = h->sizearray; + lua_assert(testbit(h->marked, VALUEWEAKBIT) || + testbit(h->marked, KEYWEAKBIT)); + if (testbit(h->marked, VALUEWEAKBIT)) { + while (i--) { + TValue *o = &h->array[i]; + if (iscleared(o, 0)) /* value was collected? */ + setnilvalue(o); /* remove value */ + } + } + i = sizenode(h); + while (i--) { + Node *n = gnode(h, i); + if (!ttisnil(gval(n)) && /* non-empty entry? */ + (iscleared(key2tval(n), 1) || iscleared(gval(n), 0))) { + setnilvalue(gval(n)); /* remove value ... */ + removeentry(n); /* remove entry from table */ + } + } + l = h->gclist; + } +} + + +static void freeobj (lua_State *L, GCObject *o) { + switch (o->gch.tt) { + case LUA_TPROTO: luaF_freeproto(L, gco2p(o)); break; + case LUA_TFUNCTION: luaF_freeclosure(L, gco2cl(o)); break; + case LUA_TUPVAL: luaF_freeupval(L, gco2uv(o)); break; + case LUA_TTABLE: luaH_free(L, gco2h(o)); break; + case LUA_TTHREAD: { + lua_assert(gco2th(o) != L && gco2th(o) != G(L)->mainthread); + luaE_freethread(L, gco2th(o)); + break; + } + case LUA_TSTRING: { + G(L)->strt.nuse--; + luaM_freemem(L, o, sizestring(gco2ts(o))); + break; + } + case LUA_TUSERDATA: { + luaM_freemem(L, o, sizeudata(gco2u(o))); + break; + } + default: lua_assert(0); + } +} + + + +#define sweepwholelist(L,p) sweeplist(L,p,MAX_LUMEM) + + +static GCObject **sweeplist (lua_State *L, GCObject **p, lu_mem count) { + GCObject *curr; + global_State *g = G(L); + int deadmask = otherwhite(g); + while ((curr = *p) != NULL && count-- > 0) { + if (curr->gch.tt == LUA_TTHREAD) /* sweep open upvalues of each thread */ + sweepwholelist(L, &gco2th(curr)->openupval); + if ((curr->gch.marked ^ WHITEBITS) & deadmask) { /* not dead? */ + lua_assert(!isdead(g, curr) || testbit(curr->gch.marked, FIXEDBIT)); + makewhite(g, curr); /* make it white (for next cycle) */ + p = &curr->gch.next; + } + else { /* must erase `curr' */ + lua_assert(isdead(g, curr) || deadmask == bitmask(SFIXEDBIT)); + *p = curr->gch.next; + if (curr == g->rootgc) /* is the first element of the list? */ + g->rootgc = curr->gch.next; /* adjust first */ + freeobj(L, curr); + } + } + return p; +} + + +static void checkSizes (lua_State *L) { + global_State *g = G(L); + /* check size of string hash */ + if (g->strt.nuse < cast(lu_int32, g->strt.size/4) && + g->strt.size > MINSTRTABSIZE*2) + luaS_resize(L, g->strt.size/2); /* table is too big */ + /* check size of buffer */ + if (luaZ_sizebuffer(&g->buff) > LUA_MINBUFFER*2) { /* buffer too big? */ + size_t newsize = luaZ_sizebuffer(&g->buff) / 2; + luaZ_resizebuffer(L, &g->buff, newsize); + } +} + + +static void GCTM (lua_State *L) { + global_State *g = G(L); + GCObject *o = g->tmudata->gch.next; /* get first element */ + Udata *udata = rawgco2u(o); + const TValue *tm; + /* remove udata from `tmudata' */ + if (o == g->tmudata) /* last element? */ + g->tmudata = NULL; + else + g->tmudata->gch.next = udata->uv.next; + udata->uv.next = g->mainthread->next; /* return it to `root' list */ + g->mainthread->next = o; + makewhite(g, o); + tm = fasttm(L, udata->uv.metatable, TM_GC); + if (tm != NULL) { + lu_byte oldah = L->allowhook; + lu_mem oldt = g->GCthreshold; + L->allowhook = 0; /* stop debug hooks during GC tag method */ + g->GCthreshold = 2*g->totalbytes; /* avoid GC steps */ + setobj2s(L, L->top, tm); + setuvalue(L, L->top+1, udata); + L->top += 2; + luaD_call(L, L->top - 2, 0); + L->allowhook = oldah; /* restore hooks */ + g->GCthreshold = oldt; /* restore threshold */ + } +} + + +/* +** Call all GC tag methods +*/ +void luaC_callGCTM (lua_State *L) { + while (G(L)->tmudata) + GCTM(L); +} + + +void luaC_freeall (lua_State *L) { + global_State *g = G(L); + int i; + g->currentwhite = WHITEBITS | bitmask(SFIXEDBIT); /* mask to collect all elements */ + sweepwholelist(L, &g->rootgc); + for (i = 0; i < g->strt.size; i++) /* free all string lists */ + sweepwholelist(L, &g->strt.hash[i]); +} + + +static void markmt (global_State *g) { + int i; + for (i=0; imt[i]) markobject(g, g->mt[i]); +} + + +/* mark root set */ +static void markroot (lua_State *L) { + global_State *g = G(L); + g->gray = NULL; + g->grayagain = NULL; + g->weak = NULL; + markobject(g, g->mainthread); + /* make global table be traversed before main stack */ + markvalue(g, gt(g->mainthread)); + markvalue(g, registry(L)); + markmt(g); + g->gcstate = GCSpropagate; +} + + +static void remarkupvals (global_State *g) { + UpVal *uv; + for (uv = g->uvhead.u.l.next; uv != &g->uvhead; uv = uv->u.l.next) { + lua_assert(uv->u.l.next->u.l.prev == uv && uv->u.l.prev->u.l.next == uv); + if (isgray(obj2gco(uv))) + markvalue(g, uv->v); + } +} + + +static void atomic (lua_State *L) { + global_State *g = G(L); + size_t udsize; /* total size of userdata to be finalized */ + /* remark occasional upvalues of (maybe) dead threads */ + remarkupvals(g); + /* traverse objects cautch by write barrier and by 'remarkupvals' */ + propagateall(g); + /* remark weak tables */ + g->gray = g->weak; + g->weak = NULL; + lua_assert(!iswhite(obj2gco(g->mainthread))); + markobject(g, L); /* mark running thread */ + markmt(g); /* mark basic metatables (again) */ + propagateall(g); + /* remark gray again */ + g->gray = g->grayagain; + g->grayagain = NULL; + propagateall(g); + udsize = luaC_separateudata(L, 0); /* separate userdata to be finalized */ + marktmu(g); /* mark `preserved' userdata */ + udsize += propagateall(g); /* remark, to propagate `preserveness' */ + cleartable(g->weak); /* remove collected objects from weak tables */ + /* flip current white */ + g->currentwhite = cast_byte(otherwhite(g)); + g->sweepstrgc = 0; + g->sweepgc = &g->rootgc; + g->gcstate = GCSsweepstring; + g->estimate = g->totalbytes - udsize; /* first estimate */ +} + + +static l_mem singlestep (lua_State *L) { + global_State *g = G(L); + /*lua_checkmemory(L);*/ + switch (g->gcstate) { + case GCSpause: { + markroot(L); /* start a new collection */ + return 0; + } + case GCSpropagate: { + if (g->gray) + return propagatemark(g); + else { /* no more `gray' objects */ + atomic(L); /* finish mark phase */ + return 0; + } + } + case GCSsweepstring: { + lu_mem old = g->totalbytes; + sweepwholelist(L, &g->strt.hash[g->sweepstrgc++]); + if (g->sweepstrgc >= g->strt.size) /* nothing more to sweep? */ + g->gcstate = GCSsweep; /* end sweep-string phase */ + lua_assert(old >= g->totalbytes); + g->estimate -= old - g->totalbytes; + return GCSWEEPCOST; + } + case GCSsweep: { + lu_mem old = g->totalbytes; + g->sweepgc = sweeplist(L, g->sweepgc, GCSWEEPMAX); + if (*g->sweepgc == NULL) { /* nothing more to sweep? */ + checkSizes(L); + g->gcstate = GCSfinalize; /* end sweep phase */ + } + lua_assert(old >= g->totalbytes); + g->estimate -= old - g->totalbytes; + return GCSWEEPMAX*GCSWEEPCOST; + } + case GCSfinalize: { + if (g->tmudata) { + GCTM(L); + if (g->estimate > GCFINALIZECOST) + g->estimate -= GCFINALIZECOST; + return GCFINALIZECOST; + } + else { + g->gcstate = GCSpause; /* end collection */ + g->gcdept = 0; + return 0; + } + } + default: lua_assert(0); return 0; + } +} + + +void luaC_step (lua_State *L) { + global_State *g = G(L); + l_mem lim = (GCSTEPSIZE/100) * g->gcstepmul; + if (lim == 0) + lim = (MAX_LUMEM-1)/2; /* no limit */ + g->gcdept += g->totalbytes - g->GCthreshold; + do { + lim -= singlestep(L); + if (g->gcstate == GCSpause) + break; + } while (lim > 0); + if (g->gcstate != GCSpause) { + if (g->gcdept < GCSTEPSIZE) + g->GCthreshold = g->totalbytes + GCSTEPSIZE; /* - lim/g->gcstepmul;*/ + else { + g->gcdept -= GCSTEPSIZE; + g->GCthreshold = g->totalbytes; + } + } + else { + lua_assert(g->totalbytes >= g->estimate); + setthreshold(g); + } +} + + +void luaC_fullgc (lua_State *L) { + global_State *g = G(L); + if (g->gcstate <= GCSpropagate) { + /* reset sweep marks to sweep all elements (returning them to white) */ + g->sweepstrgc = 0; + g->sweepgc = &g->rootgc; + /* reset other collector lists */ + g->gray = NULL; + g->grayagain = NULL; + g->weak = NULL; + g->gcstate = GCSsweepstring; + } + lua_assert(g->gcstate != GCSpause && g->gcstate != GCSpropagate); + /* finish any pending sweep phase */ + while (g->gcstate != GCSfinalize) { + lua_assert(g->gcstate == GCSsweepstring || g->gcstate == GCSsweep); + singlestep(L); + } + markroot(L); + while (g->gcstate != GCSpause) { + singlestep(L); + } + setthreshold(g); +} + + +void luaC_barrierf (lua_State *L, GCObject *o, GCObject *v) { + global_State *g = G(L); + lua_assert(isblack(o) && iswhite(v) && !isdead(g, v) && !isdead(g, o)); + lua_assert(g->gcstate != GCSfinalize && g->gcstate != GCSpause); + lua_assert(ttype(&o->gch) != LUA_TTABLE); + /* must keep invariant? */ + if (g->gcstate == GCSpropagate) + reallymarkobject(g, v); /* restore invariant */ + else /* don't mind */ + makewhite(g, o); /* mark as white just to avoid other barriers */ +} + + +void luaC_barrierback (lua_State *L, Table *t) { + global_State *g = G(L); + GCObject *o = obj2gco(t); + lua_assert(isblack(o) && !isdead(g, o)); + lua_assert(g->gcstate != GCSfinalize && g->gcstate != GCSpause); + black2gray(o); /* make table gray (again) */ + t->gclist = g->grayagain; + g->grayagain = o; +} + + +void luaC_link (lua_State *L, GCObject *o, lu_byte tt) { + global_State *g = G(L); + o->gch.next = g->rootgc; + g->rootgc = o; + o->gch.marked = luaC_white(g); + o->gch.tt = tt; +} + + +void luaC_linkupval (lua_State *L, UpVal *uv) { + global_State *g = G(L); + GCObject *o = obj2gco(uv); + o->gch.next = g->rootgc; /* link upvalue into `rootgc' list */ + g->rootgc = o; + if (isgray(o)) { + if (g->gcstate == GCSpropagate) { + gray2black(o); /* closed upvalues need barrier */ + luaC_barrier(L, uv, uv->v); + } + else { /* sweep phase: sweep it (turning it into white) */ + makewhite(g, o); + lua_assert(g->gcstate != GCSfinalize && g->gcstate != GCSpause); + } + } +} + diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lgc.h b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lgc.h new file mode 100644 index 00000000..5a8dc605 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lgc.h @@ -0,0 +1,110 @@ +/* +** $Id: lgc.h,v 2.15.1.1 2007/12/27 13:02:25 roberto Exp $ +** Garbage Collector +** See Copyright Notice in lua.h +*/ + +#ifndef lgc_h +#define lgc_h + + +#include "lobject.h" + + +/* +** Possible states of the Garbage Collector +*/ +#define GCSpause 0 +#define GCSpropagate 1 +#define GCSsweepstring 2 +#define GCSsweep 3 +#define GCSfinalize 4 + + +/* +** some userful bit tricks +*/ +#define resetbits(x,m) ((x) &= cast(lu_byte, ~(m))) +#define setbits(x,m) ((x) |= (m)) +#define testbits(x,m) ((x) & (m)) +#define bitmask(b) (1<<(b)) +#define bit2mask(b1,b2) (bitmask(b1) | bitmask(b2)) +#define l_setbit(x,b) setbits(x, bitmask(b)) +#define resetbit(x,b) resetbits(x, bitmask(b)) +#define testbit(x,b) testbits(x, bitmask(b)) +#define set2bits(x,b1,b2) setbits(x, (bit2mask(b1, b2))) +#define reset2bits(x,b1,b2) resetbits(x, (bit2mask(b1, b2))) +#define test2bits(x,b1,b2) testbits(x, (bit2mask(b1, b2))) + + + +/* +** Layout for bit use in `marked' field: +** bit 0 - object is white (type 0) +** bit 1 - object is white (type 1) +** bit 2 - object is black +** bit 3 - for userdata: has been finalized +** bit 3 - for tables: has weak keys +** bit 4 - for tables: has weak values +** bit 5 - object is fixed (should not be collected) +** bit 6 - object is "super" fixed (only the main thread) +*/ + + +#define WHITE0BIT 0 +#define WHITE1BIT 1 +#define BLACKBIT 2 +#define FINALIZEDBIT 3 +#define KEYWEAKBIT 3 +#define VALUEWEAKBIT 4 +#define FIXEDBIT 5 +#define SFIXEDBIT 6 +#define WHITEBITS bit2mask(WHITE0BIT, WHITE1BIT) + + +#define iswhite(x) test2bits((x)->gch.marked, WHITE0BIT, WHITE1BIT) +#define isblack(x) testbit((x)->gch.marked, BLACKBIT) +#define isgray(x) (!isblack(x) && !iswhite(x)) + +#define otherwhite(g) (g->currentwhite ^ WHITEBITS) +#define isdead(g,v) ((v)->gch.marked & otherwhite(g) & WHITEBITS) + +#define changewhite(x) ((x)->gch.marked ^= WHITEBITS) +#define gray2black(x) l_setbit((x)->gch.marked, BLACKBIT) + +#define valiswhite(x) (iscollectable(x) && iswhite(gcvalue(x))) + +#define luaC_white(g) cast(lu_byte, (g)->currentwhite & WHITEBITS) + + +#define luaC_checkGC(L) { \ + condhardstacktests(luaD_reallocstack(L, L->stacksize - EXTRA_STACK - 1)); \ + if (G(L)->totalbytes >= G(L)->GCthreshold) \ + luaC_step(L); } + + +#define luaC_barrier(L,p,v) { if (valiswhite(v) && isblack(obj2gco(p))) \ + luaC_barrierf(L,obj2gco(p),gcvalue(v)); } + +#define luaC_barriert(L,t,v) { if (valiswhite(v) && isblack(obj2gco(t))) \ + luaC_barrierback(L,t); } + +#define luaC_objbarrier(L,p,o) \ + { if (iswhite(obj2gco(o)) && isblack(obj2gco(p))) \ + luaC_barrierf(L,obj2gco(p),obj2gco(o)); } + +#define luaC_objbarriert(L,t,o) \ + { if (iswhite(obj2gco(o)) && isblack(obj2gco(t))) luaC_barrierback(L,t); } + +LUAI_FUNC size_t luaC_separateudata (lua_State *L, int all); +LUAI_FUNC void luaC_callGCTM (lua_State *L); +LUAI_FUNC void luaC_freeall (lua_State *L); +LUAI_FUNC void luaC_step (lua_State *L); +LUAI_FUNC void luaC_fullgc (lua_State *L); +LUAI_FUNC void luaC_link (lua_State *L, GCObject *o, lu_byte tt); +LUAI_FUNC void luaC_linkupval (lua_State *L, UpVal *uv); +LUAI_FUNC void luaC_barrierf (lua_State *L, GCObject *o, GCObject *v); +LUAI_FUNC void luaC_barrierback (lua_State *L, Table *t); + + +#endif diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/linit.c b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/linit.c new file mode 100644 index 00000000..c1f90dfa --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/linit.c @@ -0,0 +1,38 @@ +/* +** $Id: linit.c,v 1.14.1.1 2007/12/27 13:02:25 roberto Exp $ +** Initialization of libraries for lua.c +** See Copyright Notice in lua.h +*/ + + +#define linit_c +#define LUA_LIB + +#include "lua.h" + +#include "lualib.h" +#include "lauxlib.h" + + +static const luaL_Reg lualibs[] = { + {"", luaopen_base}, + {LUA_LOADLIBNAME, luaopen_package}, + {LUA_TABLIBNAME, luaopen_table}, + {LUA_IOLIBNAME, luaopen_io}, + {LUA_OSLIBNAME, luaopen_os}, + {LUA_STRLIBNAME, luaopen_string}, + {LUA_MATHLIBNAME, luaopen_math}, + {LUA_DBLIBNAME, luaopen_debug}, + {NULL, NULL} +}; + + +LUALIB_API void luaL_openlibs (lua_State *L) { + const luaL_Reg *lib = lualibs; + for (; lib->func; lib++) { + lua_pushcfunction(L, lib->func); + lua_pushstring(L, lib->name); + lua_call(L, 1, 0); + } +} + diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/liolib.c b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/liolib.c new file mode 100644 index 00000000..e79ed1cb --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/liolib.c @@ -0,0 +1,553 @@ +/* +** $Id: liolib.c,v 2.73.1.3 2008/01/18 17:47:43 roberto Exp $ +** Standard I/O (and system) library +** See Copyright Notice in lua.h +*/ + + +#include +#include +#include +#include + +#define liolib_c +#define LUA_LIB + +#include "lua.h" + +#include "lauxlib.h" +#include "lualib.h" + + + +#define IO_INPUT 1 +#define IO_OUTPUT 2 + + +static const char *const fnames[] = {"input", "output"}; + + +static int pushresult (lua_State *L, int i, const char *filename) { + int en = errno; /* calls to Lua API may change this value */ + if (i) { + lua_pushboolean(L, 1); + return 1; + } + else { + lua_pushnil(L); + if (filename) + lua_pushfstring(L, "%s: %s", filename, strerror(en)); + else + lua_pushfstring(L, "%s", strerror(en)); + lua_pushinteger(L, en); + return 3; + } +} + + +static void fileerror (lua_State *L, int arg, const char *filename) { + lua_pushfstring(L, "%s: %s", filename, strerror(errno)); + luaL_argerror(L, arg, lua_tostring(L, -1)); +} + + +#define tofilep(L) ((FILE **)luaL_checkudata(L, 1, LUA_FILEHANDLE)) + + +static int io_type (lua_State *L) { + void *ud; + luaL_checkany(L, 1); + ud = lua_touserdata(L, 1); + lua_getfield(L, LUA_REGISTRYINDEX, LUA_FILEHANDLE); + if (ud == NULL || !lua_getmetatable(L, 1) || !lua_rawequal(L, -2, -1)) + lua_pushnil(L); /* not a file */ + else if (*((FILE **)ud) == NULL) + lua_pushliteral(L, "closed file"); + else + lua_pushliteral(L, "file"); + return 1; +} + + +static FILE *tofile (lua_State *L) { + FILE **f = tofilep(L); + if (*f == NULL) + luaL_error(L, "attempt to use a closed file"); + return *f; +} + + + +/* +** When creating file handles, always creates a `closed' file handle +** before opening the actual file; so, if there is a memory error, the +** file is not left opened. +*/ +static FILE **newfile (lua_State *L) { + FILE **pf = (FILE **)lua_newuserdata(L, sizeof(FILE *)); + *pf = NULL; /* file handle is currently `closed' */ + luaL_getmetatable(L, LUA_FILEHANDLE); + lua_setmetatable(L, -2); + return pf; +} + + +/* +** function to (not) close the standard files stdin, stdout, and stderr +*/ +static int io_noclose (lua_State *L) { + lua_pushnil(L); + lua_pushliteral(L, "cannot close standard file"); + return 2; +} + + +/* +** function to close 'popen' files +*/ +static int io_pclose (lua_State *L) { + FILE **p = tofilep(L); + int ok = lua_pclose(L, *p); + *p = NULL; + return pushresult(L, ok, NULL); +} + + +/* +** function to close regular files +*/ +static int io_fclose (lua_State *L) { + FILE **p = tofilep(L); + int ok = (fclose(*p) == 0); + *p = NULL; + return pushresult(L, ok, NULL); +} + + +static int aux_close (lua_State *L) { + lua_getfenv(L, 1); + lua_getfield(L, -1, "__close"); + return (lua_tocfunction(L, -1))(L); +} + + +static int io_close (lua_State *L) { + if (lua_isnone(L, 1)) + lua_rawgeti(L, LUA_ENVIRONINDEX, IO_OUTPUT); + tofile(L); /* make sure argument is a file */ + return aux_close(L); +} + + +static int io_gc (lua_State *L) { + FILE *f = *tofilep(L); + /* ignore closed files */ + if (f != NULL) + aux_close(L); + return 0; +} + + +static int io_tostring (lua_State *L) { + FILE *f = *tofilep(L); + if (f == NULL) + lua_pushliteral(L, "file (closed)"); + else + lua_pushfstring(L, "file (%p)", f); + return 1; +} + + +static int io_open (lua_State *L) { + const char *filename = luaL_checkstring(L, 1); + const char *mode = luaL_optstring(L, 2, "r"); + FILE **pf = newfile(L); + *pf = fopen(filename, mode); + return (*pf == NULL) ? pushresult(L, 0, filename) : 1; +} + + +/* +** this function has a separated environment, which defines the +** correct __close for 'popen' files +*/ +static int io_popen (lua_State *L) { + const char *filename = luaL_checkstring(L, 1); + const char *mode = luaL_optstring(L, 2, "r"); + FILE **pf = newfile(L); + *pf = lua_popen(L, filename, mode); + return (*pf == NULL) ? pushresult(L, 0, filename) : 1; +} + + +static int io_tmpfile (lua_State *L) { + FILE **pf = newfile(L); + *pf = tmpfile(); + return (*pf == NULL) ? pushresult(L, 0, NULL) : 1; +} + + +static FILE *getiofile (lua_State *L, int findex) { + FILE *f; + lua_rawgeti(L, LUA_ENVIRONINDEX, findex); + f = *(FILE **)lua_touserdata(L, -1); + if (f == NULL) + luaL_error(L, "standard %s file is closed", fnames[findex - 1]); + return f; +} + + +static int g_iofile (lua_State *L, int f, const char *mode) { + if (!lua_isnoneornil(L, 1)) { + const char *filename = lua_tostring(L, 1); + if (filename) { + FILE **pf = newfile(L); + *pf = fopen(filename, mode); + if (*pf == NULL) + fileerror(L, 1, filename); + } + else { + tofile(L); /* check that it's a valid file handle */ + lua_pushvalue(L, 1); + } + lua_rawseti(L, LUA_ENVIRONINDEX, f); + } + /* return current value */ + lua_rawgeti(L, LUA_ENVIRONINDEX, f); + return 1; +} + + +static int io_input (lua_State *L) { + return g_iofile(L, IO_INPUT, "r"); +} + + +static int io_output (lua_State *L) { + return g_iofile(L, IO_OUTPUT, "w"); +} + + +static int io_readline (lua_State *L); + + +static void aux_lines (lua_State *L, int idx, int toclose) { + lua_pushvalue(L, idx); + lua_pushboolean(L, toclose); /* close/not close file when finished */ + lua_pushcclosure(L, io_readline, 2); +} + + +static int f_lines (lua_State *L) { + tofile(L); /* check that it's a valid file handle */ + aux_lines(L, 1, 0); + return 1; +} + + +static int io_lines (lua_State *L) { + if (lua_isnoneornil(L, 1)) { /* no arguments? */ + /* will iterate over default input */ + lua_rawgeti(L, LUA_ENVIRONINDEX, IO_INPUT); + return f_lines(L); + } + else { + const char *filename = luaL_checkstring(L, 1); + FILE **pf = newfile(L); + *pf = fopen(filename, "r"); + if (*pf == NULL) + fileerror(L, 1, filename); + aux_lines(L, lua_gettop(L), 1); + return 1; + } +} + + +/* +** {====================================================== +** READ +** ======================================================= +*/ + + +static int read_number (lua_State *L, FILE *f) { + lua_Number d; + if (fscanf(f, LUA_NUMBER_SCAN, &d) == 1) { + lua_pushnumber(L, d); + return 1; + } + else return 0; /* read fails */ +} + + +static int test_eof (lua_State *L, FILE *f) { + int c = getc(f); + ungetc(c, f); + lua_pushlstring(L, NULL, 0); + return (c != EOF); +} + + +static int read_line (lua_State *L, FILE *f) { + luaL_Buffer b; + luaL_buffinit(L, &b); + for (;;) { + size_t l; + char *p = luaL_prepbuffer(&b); + if (fgets(p, LUAL_BUFFERSIZE, f) == NULL) { /* eof? */ + luaL_pushresult(&b); /* close buffer */ + return (lua_objlen(L, -1) > 0); /* check whether read something */ + } + l = strlen(p); + if (l == 0 || p[l-1] != '\n') + luaL_addsize(&b, l); + else { + luaL_addsize(&b, l - 1); /* do not include `eol' */ + luaL_pushresult(&b); /* close buffer */ + return 1; /* read at least an `eol' */ + } + } +} + + +static int read_chars (lua_State *L, FILE *f, size_t n) { + size_t rlen; /* how much to read */ + size_t nr; /* number of chars actually read */ + luaL_Buffer b; + luaL_buffinit(L, &b); + rlen = LUAL_BUFFERSIZE; /* try to read that much each time */ + do { + char *p = luaL_prepbuffer(&b); + if (rlen > n) rlen = n; /* cannot read more than asked */ + nr = fread(p, sizeof(char), rlen, f); + luaL_addsize(&b, nr); + n -= nr; /* still have to read `n' chars */ + } while (n > 0 && nr == rlen); /* until end of count or eof */ + luaL_pushresult(&b); /* close buffer */ + return (n == 0 || lua_objlen(L, -1) > 0); +} + + +static int g_read (lua_State *L, FILE *f, int first) { + int nargs = lua_gettop(L) - 1; + int success; + int n; + clearerr(f); + if (nargs == 0) { /* no arguments? */ + success = read_line(L, f); + n = first+1; /* to return 1 result */ + } + else { /* ensure stack space for all results and for auxlib's buffer */ + luaL_checkstack(L, nargs+LUA_MINSTACK, "too many arguments"); + success = 1; + for (n = first; nargs-- && success; n++) { + if (lua_type(L, n) == LUA_TNUMBER) { + size_t l = (size_t)lua_tointeger(L, n); + success = (l == 0) ? test_eof(L, f) : read_chars(L, f, l); + } + else { + const char *p = lua_tostring(L, n); + luaL_argcheck(L, p && p[0] == '*', n, "invalid option"); + switch (p[1]) { + case 'n': /* number */ + success = read_number(L, f); + break; + case 'l': /* line */ + success = read_line(L, f); + break; + case 'a': /* file */ + read_chars(L, f, ~((size_t)0)); /* read MAX_SIZE_T chars */ + success = 1; /* always success */ + break; + default: + return luaL_argerror(L, n, "invalid format"); + } + } + } + } + if (ferror(f)) + return pushresult(L, 0, NULL); + if (!success) { + lua_pop(L, 1); /* remove last result */ + lua_pushnil(L); /* push nil instead */ + } + return n - first; +} + + +static int io_read (lua_State *L) { + return g_read(L, getiofile(L, IO_INPUT), 1); +} + + +static int f_read (lua_State *L) { + return g_read(L, tofile(L), 2); +} + + +static int io_readline (lua_State *L) { + FILE *f = *(FILE **)lua_touserdata(L, lua_upvalueindex(1)); + int sucess; + if (f == NULL) /* file is already closed? */ + luaL_error(L, "file is already closed"); + sucess = read_line(L, f); + if (ferror(f)) + return luaL_error(L, "%s", strerror(errno)); + if (sucess) return 1; + else { /* EOF */ + if (lua_toboolean(L, lua_upvalueindex(2))) { /* generator created file? */ + lua_settop(L, 0); + lua_pushvalue(L, lua_upvalueindex(1)); + aux_close(L); /* close it */ + } + return 0; + } +} + +/* }====================================================== */ + + +static int g_write (lua_State *L, FILE *f, int arg) { + int nargs = lua_gettop(L) - 1; + int status = 1; + for (; nargs--; arg++) { + if (lua_type(L, arg) == LUA_TNUMBER) { + /* optimization: could be done exactly as for strings */ + status = status && + fprintf(f, LUA_NUMBER_FMT, lua_tonumber(L, arg)) > 0; + } + else { + size_t l; + const char *s = luaL_checklstring(L, arg, &l); + status = status && (fwrite(s, sizeof(char), l, f) == l); + } + } + return pushresult(L, status, NULL); +} + + +static int io_write (lua_State *L) { + return g_write(L, getiofile(L, IO_OUTPUT), 1); +} + + +static int f_write (lua_State *L) { + return g_write(L, tofile(L), 2); +} + + +static int f_seek (lua_State *L) { + static const int mode[] = {SEEK_SET, SEEK_CUR, SEEK_END}; + static const char *const modenames[] = {"set", "cur", "end", NULL}; + FILE *f = tofile(L); + int op = luaL_checkoption(L, 2, "cur", modenames); + long offset = luaL_optlong(L, 3, 0); + op = fseek(f, offset, mode[op]); + if (op) + return pushresult(L, 0, NULL); /* error */ + else { + lua_pushinteger(L, ftell(f)); + return 1; + } +} + + +static int f_setvbuf (lua_State *L) { + static const int mode[] = {_IONBF, _IOFBF, _IOLBF}; + static const char *const modenames[] = {"no", "full", "line", NULL}; + FILE *f = tofile(L); + int op = luaL_checkoption(L, 2, NULL, modenames); + lua_Integer sz = luaL_optinteger(L, 3, LUAL_BUFFERSIZE); + int res = setvbuf(f, NULL, mode[op], sz); + return pushresult(L, res == 0, NULL); +} + + + +static int io_flush (lua_State *L) { + return pushresult(L, fflush(getiofile(L, IO_OUTPUT)) == 0, NULL); +} + + +static int f_flush (lua_State *L) { + return pushresult(L, fflush(tofile(L)) == 0, NULL); +} + + +static const luaL_Reg iolib[] = { + {"close", io_close}, + {"flush", io_flush}, + {"input", io_input}, + {"lines", io_lines}, + {"open", io_open}, + {"output", io_output}, + {"popen", io_popen}, + {"read", io_read}, + {"tmpfile", io_tmpfile}, + {"type", io_type}, + {"write", io_write}, + {NULL, NULL} +}; + + +static const luaL_Reg flib[] = { + {"close", io_close}, + {"flush", f_flush}, + {"lines", f_lines}, + {"read", f_read}, + {"seek", f_seek}, + {"setvbuf", f_setvbuf}, + {"write", f_write}, + {"__gc", io_gc}, + {"__tostring", io_tostring}, + {NULL, NULL} +}; + + +static void createmeta (lua_State *L) { + luaL_newmetatable(L, LUA_FILEHANDLE); /* create metatable for file handles */ + lua_pushvalue(L, -1); /* push metatable */ + lua_setfield(L, -2, "__index"); /* metatable.__index = metatable */ + luaL_register(L, NULL, flib); /* file methods */ +} + + +static void createstdfile (lua_State *L, FILE *f, int k, const char *fname) { + *newfile(L) = f; + if (k > 0) { + lua_pushvalue(L, -1); + lua_rawseti(L, LUA_ENVIRONINDEX, k); + } + lua_pushvalue(L, -2); /* copy environment */ + lua_setfenv(L, -2); /* set it */ + lua_setfield(L, -3, fname); +} + + +static void newfenv (lua_State *L, lua_CFunction cls) { + lua_createtable(L, 0, 1); + lua_pushcfunction(L, cls); + lua_setfield(L, -2, "__close"); +} + + +LUALIB_API int luaopen_io (lua_State *L) { + createmeta(L); + /* create (private) environment (with fields IO_INPUT, IO_OUTPUT, __close) */ + newfenv(L, io_fclose); + lua_replace(L, LUA_ENVIRONINDEX); + /* open library */ + luaL_register(L, LUA_IOLIBNAME, iolib); + /* create (and set) default files */ + newfenv(L, io_noclose); /* close function for default files */ + createstdfile(L, stdin, IO_INPUT, "stdin"); + createstdfile(L, stdout, IO_OUTPUT, "stdout"); + createstdfile(L, stderr, 0, "stderr"); + lua_pop(L, 1); /* pop environment for default files */ + lua_getfield(L, -1, "popen"); + newfenv(L, io_pclose); /* create environment for 'popen' */ + lua_setfenv(L, -2); /* set fenv for 'popen' */ + lua_pop(L, 1); /* pop 'popen' */ + return 1; +} + diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/llex.c b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/llex.c new file mode 100644 index 00000000..6dc31935 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/llex.c @@ -0,0 +1,461 @@ +/* +** $Id: llex.c,v 2.20.1.1 2007/12/27 13:02:25 roberto Exp $ +** Lexical Analyzer +** See Copyright Notice in lua.h +*/ + + +#include +#include +#include + +#define llex_c +#define LUA_CORE + +#include "lua.h" + +#include "ldo.h" +#include "llex.h" +#include "lobject.h" +#include "lparser.h" +#include "lstate.h" +#include "lstring.h" +#include "ltable.h" +#include "lzio.h" + + + +#define next(ls) (ls->current = zgetc(ls->z)) + + + + +#define currIsNewline(ls) (ls->current == '\n' || ls->current == '\r') + + +/* ORDER RESERVED */ +const char *const luaX_tokens [] = { + "and", "break", "do", "else", "elseif", + "end", "false", "for", "function", "if", + "in", "local", "nil", "not", "or", "repeat", + "return", "then", "true", "until", "while", + "..", "...", "==", ">=", "<=", "~=", + "", "", "", "", + NULL +}; + + +#define save_and_next(ls) (save(ls, ls->current), next(ls)) + + +static void save (LexState *ls, int c) { + Mbuffer *b = ls->buff; + if (b->n + 1 > b->buffsize) { + size_t newsize; + if (b->buffsize >= MAX_SIZET/2) + luaX_lexerror(ls, "lexical element too long", 0); + newsize = b->buffsize * 2; + luaZ_resizebuffer(ls->L, b, newsize); + } + b->buffer[b->n++] = cast(char, c); +} + + +void luaX_init (lua_State *L) { + int i; + for (i=0; itsv.reserved = cast_byte(i+1); /* reserved word */ + } +} + + +#define MAXSRC 80 + + +const char *luaX_token2str (LexState *ls, int token) { + if (token < FIRST_RESERVED) { + lua_assert(token == cast(unsigned char, token)); + return (iscntrl(token)) ? luaO_pushfstring(ls->L, "char(%d)", token) : + luaO_pushfstring(ls->L, "%c", token); + } + else + return luaX_tokens[token-FIRST_RESERVED]; +} + + +static const char *txtToken (LexState *ls, int token) { + switch (token) { + case TK_NAME: + case TK_STRING: + case TK_NUMBER: + save(ls, '\0'); + return luaZ_buffer(ls->buff); + default: + return luaX_token2str(ls, token); + } +} + + +void luaX_lexerror (LexState *ls, const char *msg, int token) { + char buff[MAXSRC]; + luaO_chunkid(buff, getstr(ls->source), MAXSRC); + msg = luaO_pushfstring(ls->L, "%s:%d: %s", buff, ls->linenumber, msg); + if (token) + luaO_pushfstring(ls->L, "%s near " LUA_QS, msg, txtToken(ls, token)); + luaD_throw(ls->L, LUA_ERRSYNTAX); +} + + +void luaX_syntaxerror (LexState *ls, const char *msg) { + luaX_lexerror(ls, msg, ls->t.token); +} + + +TString *luaX_newstring (LexState *ls, const char *str, size_t l) { + lua_State *L = ls->L; + TString *ts = luaS_newlstr(L, str, l); + TValue *o = luaH_setstr(L, ls->fs->h, ts); /* entry for `str' */ + if (ttisnil(o)) + setbvalue(o, 1); /* make sure `str' will not be collected */ + return ts; +} + + +static void inclinenumber (LexState *ls) { + int old = ls->current; + lua_assert(currIsNewline(ls)); + next(ls); /* skip `\n' or `\r' */ + if (currIsNewline(ls) && ls->current != old) + next(ls); /* skip `\n\r' or `\r\n' */ + if (++ls->linenumber >= MAX_INT) + luaX_syntaxerror(ls, "chunk has too many lines"); +} + + +void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source) { + ls->decpoint = '.'; + ls->L = L; + ls->lookahead.token = TK_EOS; /* no look-ahead token */ + ls->z = z; + ls->fs = NULL; + ls->linenumber = 1; + ls->lastline = 1; + ls->source = source; + luaZ_resizebuffer(ls->L, ls->buff, LUA_MINBUFFER); /* initialize buffer */ + next(ls); /* read first char */ +} + + + +/* +** ======================================================= +** LEXICAL ANALYZER +** ======================================================= +*/ + + + +static int check_next (LexState *ls, const char *set) { + if (!strchr(set, ls->current)) + return 0; + save_and_next(ls); + return 1; +} + + +static void buffreplace (LexState *ls, char from, char to) { + size_t n = luaZ_bufflen(ls->buff); + char *p = luaZ_buffer(ls->buff); + while (n--) + if (p[n] == from) p[n] = to; +} + + +static void trydecpoint (LexState *ls, SemInfo *seminfo) { + /* format error: try to update decimal point separator */ + struct lconv *cv = localeconv(); + char old = ls->decpoint; + ls->decpoint = (cv ? cv->decimal_point[0] : '.'); + buffreplace(ls, old, ls->decpoint); /* try updated decimal separator */ + if (!luaO_str2d(luaZ_buffer(ls->buff), &seminfo->r)) { + /* format error with correct decimal point: no more options */ + buffreplace(ls, ls->decpoint, '.'); /* undo change (for error message) */ + luaX_lexerror(ls, "malformed number", TK_NUMBER); + } +} + + +/* LUA_NUMBER */ +static void read_numeral (LexState *ls, SemInfo *seminfo) { + lua_assert(isdigit(ls->current)); + do { + save_and_next(ls); + } while (isdigit(ls->current) || ls->current == '.'); + if (check_next(ls, "Ee")) /* `E'? */ + check_next(ls, "+-"); /* optional exponent sign */ + while (isalnum(ls->current) || ls->current == '_') + save_and_next(ls); + save(ls, '\0'); + buffreplace(ls, '.', ls->decpoint); /* follow locale for decimal point */ + if (!luaO_str2d(luaZ_buffer(ls->buff), &seminfo->r)) /* format error? */ + trydecpoint(ls, seminfo); /* try to update decimal point separator */ +} + + +static int skip_sep (LexState *ls) { + int count = 0; + int s = ls->current; + lua_assert(s == '[' || s == ']'); + save_and_next(ls); + while (ls->current == '=') { + save_and_next(ls); + count++; + } + return (ls->current == s) ? count : (-count) - 1; +} + + +static void read_long_string (LexState *ls, SemInfo *seminfo, int sep) { + int cont = 0; + (void)(cont); /* avoid warnings when `cont' is not used */ + save_and_next(ls); /* skip 2nd `[' */ + if (currIsNewline(ls)) /* string starts with a newline? */ + inclinenumber(ls); /* skip it */ + for (;;) { + switch (ls->current) { + case EOZ: + luaX_lexerror(ls, (seminfo) ? "unfinished long string" : + "unfinished long comment", TK_EOS); + break; /* to avoid warnings */ +#if defined(LUA_COMPAT_LSTR) + case '[': { + if (skip_sep(ls) == sep) { + save_and_next(ls); /* skip 2nd `[' */ + cont++; +#if LUA_COMPAT_LSTR == 1 + if (sep == 0) + luaX_lexerror(ls, "nesting of [[...]] is deprecated", '['); +#endif + } + break; + } +#endif + case ']': { + if (skip_sep(ls) == sep) { + save_and_next(ls); /* skip 2nd `]' */ +#if defined(LUA_COMPAT_LSTR) && LUA_COMPAT_LSTR == 2 + cont--; + if (sep == 0 && cont >= 0) break; +#endif + goto endloop; + } + break; + } + case '\n': + case '\r': { + save(ls, '\n'); + inclinenumber(ls); + if (!seminfo) luaZ_resetbuffer(ls->buff); /* avoid wasting space */ + break; + } + default: { + if (seminfo) save_and_next(ls); + else next(ls); + } + } + } endloop: + if (seminfo) + seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + (2 + sep), + luaZ_bufflen(ls->buff) - 2*(2 + sep)); +} + + +static void read_string (LexState *ls, int del, SemInfo *seminfo) { + save_and_next(ls); + while (ls->current != del) { + switch (ls->current) { + case EOZ: + luaX_lexerror(ls, "unfinished string", TK_EOS); + continue; /* to avoid warnings */ + case '\n': + case '\r': + luaX_lexerror(ls, "unfinished string", TK_STRING); + continue; /* to avoid warnings */ + case '\\': { + int c; + next(ls); /* do not save the `\' */ + switch (ls->current) { + case 'a': c = '\a'; break; + case 'b': c = '\b'; break; + case 'f': c = '\f'; break; + case 'n': c = '\n'; break; + case 'r': c = '\r'; break; + case 't': c = '\t'; break; + case 'v': c = '\v'; break; + case '\n': /* go through */ + case '\r': save(ls, '\n'); inclinenumber(ls); continue; + case EOZ: continue; /* will raise an error next loop */ + default: { + if (!isdigit(ls->current)) + save_and_next(ls); /* handles \\, \", \', and \? */ + else { /* \xxx */ + int i = 0; + c = 0; + do { + c = 10*c + (ls->current-'0'); + next(ls); + } while (++i<3 && isdigit(ls->current)); + if (c > UCHAR_MAX) + luaX_lexerror(ls, "escape sequence too large", TK_STRING); + save(ls, c); + } + continue; + } + } + save(ls, c); + next(ls); + continue; + } + default: + save_and_next(ls); + } + } + save_and_next(ls); /* skip delimiter */ + seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + 1, + luaZ_bufflen(ls->buff) - 2); +} + + +static int llex (LexState *ls, SemInfo *seminfo) { + luaZ_resetbuffer(ls->buff); + for (;;) { + switch (ls->current) { + case '\n': + case '\r': { + inclinenumber(ls); + continue; + } + case '-': { + next(ls); + if (ls->current != '-') return '-'; + /* else is a comment */ + next(ls); + if (ls->current == '[') { + int sep = skip_sep(ls); + luaZ_resetbuffer(ls->buff); /* `skip_sep' may dirty the buffer */ + if (sep >= 0) { + read_long_string(ls, NULL, sep); /* long comment */ + luaZ_resetbuffer(ls->buff); + continue; + } + } + /* else short comment */ + while (!currIsNewline(ls) && ls->current != EOZ) + next(ls); + continue; + } + case '[': { + int sep = skip_sep(ls); + if (sep >= 0) { + read_long_string(ls, seminfo, sep); + return TK_STRING; + } + else if (sep == -1) return '['; + else luaX_lexerror(ls, "invalid long string delimiter", TK_STRING); + } + case '=': { + next(ls); + if (ls->current != '=') return '='; + else { next(ls); return TK_EQ; } + } + case '<': { + next(ls); + if (ls->current != '=') return '<'; + else { next(ls); return TK_LE; } + } + case '>': { + next(ls); + if (ls->current != '=') return '>'; + else { next(ls); return TK_GE; } + } + case '~': { + next(ls); + if (ls->current != '=') return '~'; + else { next(ls); return TK_NE; } + } + case '"': + case '\'': { + read_string(ls, ls->current, seminfo); + return TK_STRING; + } + case '.': { + save_and_next(ls); + if (check_next(ls, ".")) { + if (check_next(ls, ".")) + return TK_DOTS; /* ... */ + else return TK_CONCAT; /* .. */ + } + else if (!isdigit(ls->current)) return '.'; + else { + read_numeral(ls, seminfo); + return TK_NUMBER; + } + } + case EOZ: { + return TK_EOS; + } + default: { + if (isspace(ls->current)) { + lua_assert(!currIsNewline(ls)); + next(ls); + continue; + } + else if (isdigit(ls->current)) { + read_numeral(ls, seminfo); + return TK_NUMBER; + } + else if (isalpha(ls->current) || ls->current == '_') { + /* identifier or reserved word */ + TString *ts; + do { + save_and_next(ls); + } while (isalnum(ls->current) || ls->current == '_'); + ts = luaX_newstring(ls, luaZ_buffer(ls->buff), + luaZ_bufflen(ls->buff)); + if (ts->tsv.reserved > 0) /* reserved word? */ + return ts->tsv.reserved - 1 + FIRST_RESERVED; + else { + seminfo->ts = ts; + return TK_NAME; + } + } + else { + int c = ls->current; + next(ls); + return c; /* single-char tokens (+ - / ...) */ + } + } + } + } +} + + +void luaX_next (LexState *ls) { + ls->lastline = ls->linenumber; + if (ls->lookahead.token != TK_EOS) { /* is there a look-ahead token? */ + ls->t = ls->lookahead; /* use this one */ + ls->lookahead.token = TK_EOS; /* and discharge it */ + } + else + ls->t.token = llex(ls, &ls->t.seminfo); /* read next token */ +} + + +void luaX_lookahead (LexState *ls) { + lua_assert(ls->lookahead.token == TK_EOS); + ls->lookahead.token = llex(ls, &ls->lookahead.seminfo); +} + diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/llex.h b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/llex.h new file mode 100644 index 00000000..a9201cee --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/llex.h @@ -0,0 +1,81 @@ +/* +** $Id: llex.h,v 1.58.1.1 2007/12/27 13:02:25 roberto Exp $ +** Lexical Analyzer +** See Copyright Notice in lua.h +*/ + +#ifndef llex_h +#define llex_h + +#include "lobject.h" +#include "lzio.h" + + +#define FIRST_RESERVED 257 + +/* maximum length of a reserved word */ +#define TOKEN_LEN (sizeof("function")/sizeof(char)) + + +/* +* WARNING: if you change the order of this enumeration, +* grep "ORDER RESERVED" +*/ +enum RESERVED { + /* terminal symbols denoted by reserved words */ + TK_AND = FIRST_RESERVED, TK_BREAK, + TK_DO, TK_ELSE, TK_ELSEIF, TK_END, TK_FALSE, TK_FOR, TK_FUNCTION, + TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT, + TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE, + /* other terminal symbols */ + TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, TK_NUMBER, + TK_NAME, TK_STRING, TK_EOS +}; + +/* number of reserved words */ +#define NUM_RESERVED (cast(int, TK_WHILE-FIRST_RESERVED+1)) + + +/* array with token `names' */ +LUAI_DATA const char *const luaX_tokens []; + + +typedef union { + lua_Number r; + TString *ts; +} SemInfo; /* semantics information */ + + +typedef struct Token { + int token; + SemInfo seminfo; +} Token; + + +typedef struct LexState { + int current; /* current character (charint) */ + int linenumber; /* input line counter */ + int lastline; /* line of last token `consumed' */ + Token t; /* current token */ + Token lookahead; /* look ahead token */ + struct FuncState *fs; /* `FuncState' is private to the parser */ + struct lua_State *L; + ZIO *z; /* input stream */ + Mbuffer *buff; /* buffer for tokens */ + TString *source; /* current source name */ + char decpoint; /* locale decimal point */ +} LexState; + + +LUAI_FUNC void luaX_init (lua_State *L); +LUAI_FUNC void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, + TString *source); +LUAI_FUNC TString *luaX_newstring (LexState *ls, const char *str, size_t l); +LUAI_FUNC void luaX_next (LexState *ls); +LUAI_FUNC void luaX_lookahead (LexState *ls); +LUAI_FUNC void luaX_lexerror (LexState *ls, const char *msg, int token); +LUAI_FUNC void luaX_syntaxerror (LexState *ls, const char *s); +LUAI_FUNC const char *luaX_token2str (LexState *ls, int token); + + +#endif diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/llimits.h b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/llimits.h new file mode 100644 index 00000000..ca8dcb72 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/llimits.h @@ -0,0 +1,128 @@ +/* +** $Id: llimits.h,v 1.69.1.1 2007/12/27 13:02:25 roberto Exp $ +** Limits, basic types, and some other `installation-dependent' definitions +** See Copyright Notice in lua.h +*/ + +#ifndef llimits_h +#define llimits_h + + +#include +#include + + +#include "lua.h" + + +typedef LUAI_UINT32 lu_int32; + +typedef LUAI_UMEM lu_mem; + +typedef LUAI_MEM l_mem; + + + +/* chars used as small naturals (so that `char' is reserved for characters) */ +typedef unsigned char lu_byte; + + +#define MAX_SIZET ((size_t)(~(size_t)0)-2) + +#define MAX_LUMEM ((lu_mem)(~(lu_mem)0)-2) + + +#define MAX_INT (INT_MAX-2) /* maximum value of an int (-2 for safety) */ + +/* +** conversion of pointer to integer +** this is for hashing only; there is no problem if the integer +** cannot hold the whole pointer value +*/ +#define IntPoint(p) ((unsigned int)(lu_mem)(p)) + + + +/* type to ensure maximum alignment */ +typedef LUAI_USER_ALIGNMENT_T L_Umaxalign; + + +/* result of a `usual argument conversion' over lua_Number */ +typedef LUAI_UACNUMBER l_uacNumber; + + +/* internal assertions for in-house debugging */ +#ifdef lua_assert + +#define check_exp(c,e) (lua_assert(c), (e)) +#define api_check(l,e) lua_assert(e) + +#else + +#define lua_assert(c) ((void)0) +#define check_exp(c,e) (e) +#define api_check luai_apicheck + +#endif + + +#ifndef UNUSED +#define UNUSED(x) ((void)(x)) /* to avoid warnings */ +#endif + + +#ifndef cast +#define cast(t, exp) ((t)(exp)) +#endif + +#define cast_byte(i) cast(lu_byte, (i)) +#define cast_num(i) cast(lua_Number, (i)) +#define cast_int(i) cast(int, (i)) + + + +/* +** type for virtual-machine instructions +** must be an unsigned with (at least) 4 bytes (see details in lopcodes.h) +*/ +typedef lu_int32 Instruction; + + + +/* maximum stack for a Lua function */ +#define MAXSTACK 250 + + + +/* minimum size for the string table (must be power of 2) */ +#ifndef MINSTRTABSIZE +#define MINSTRTABSIZE 32 +#endif + + +/* minimum size for string buffer */ +#ifndef LUA_MINBUFFER +#define LUA_MINBUFFER 32 +#endif + + +#ifndef lua_lock +#define lua_lock(L) ((void) 0) +#define lua_unlock(L) ((void) 0) +#endif + +#ifndef luai_threadyield +#define luai_threadyield(L) {lua_unlock(L); lua_lock(L);} +#endif + + +/* +** macro to control inclusion of some hard tests on stack reallocation +*/ +#ifndef HARDSTACKTESTS +#define condhardstacktests(x) ((void)0) +#else +#define condhardstacktests(x) x +#endif + +#endif diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lmathlib.c b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lmathlib.c new file mode 100644 index 00000000..441fbf73 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lmathlib.c @@ -0,0 +1,263 @@ +/* +** $Id: lmathlib.c,v 1.67.1.1 2007/12/27 13:02:25 roberto Exp $ +** Standard mathematical library +** See Copyright Notice in lua.h +*/ + + +#include +#include + +#define lmathlib_c +#define LUA_LIB + +#include "lua.h" + +#include "lauxlib.h" +#include "lualib.h" + + +#undef PI +#define PI (3.14159265358979323846) +#define RADIANS_PER_DEGREE (PI/180.0) + + + +static int math_abs (lua_State *L) { + lua_pushnumber(L, fabs(luaL_checknumber(L, 1))); + return 1; +} + +static int math_sin (lua_State *L) { + lua_pushnumber(L, sin(luaL_checknumber(L, 1))); + return 1; +} + +static int math_sinh (lua_State *L) { + lua_pushnumber(L, sinh(luaL_checknumber(L, 1))); + return 1; +} + +static int math_cos (lua_State *L) { + lua_pushnumber(L, cos(luaL_checknumber(L, 1))); + return 1; +} + +static int math_cosh (lua_State *L) { + lua_pushnumber(L, cosh(luaL_checknumber(L, 1))); + return 1; +} + +static int math_tan (lua_State *L) { + lua_pushnumber(L, tan(luaL_checknumber(L, 1))); + return 1; +} + +static int math_tanh (lua_State *L) { + lua_pushnumber(L, tanh(luaL_checknumber(L, 1))); + return 1; +} + +static int math_asin (lua_State *L) { + lua_pushnumber(L, asin(luaL_checknumber(L, 1))); + return 1; +} + +static int math_acos (lua_State *L) { + lua_pushnumber(L, acos(luaL_checknumber(L, 1))); + return 1; +} + +static int math_atan (lua_State *L) { + lua_pushnumber(L, atan(luaL_checknumber(L, 1))); + return 1; +} + +static int math_atan2 (lua_State *L) { + lua_pushnumber(L, atan2(luaL_checknumber(L, 1), luaL_checknumber(L, 2))); + return 1; +} + +static int math_ceil (lua_State *L) { + lua_pushnumber(L, ceil(luaL_checknumber(L, 1))); + return 1; +} + +static int math_floor (lua_State *L) { + lua_pushnumber(L, floor(luaL_checknumber(L, 1))); + return 1; +} + +static int math_fmod (lua_State *L) { + lua_pushnumber(L, fmod(luaL_checknumber(L, 1), luaL_checknumber(L, 2))); + return 1; +} + +static int math_modf (lua_State *L) { + double ip; + double fp = modf(luaL_checknumber(L, 1), &ip); + lua_pushnumber(L, ip); + lua_pushnumber(L, fp); + return 2; +} + +static int math_sqrt (lua_State *L) { + lua_pushnumber(L, sqrt(luaL_checknumber(L, 1))); + return 1; +} + +static int math_pow (lua_State *L) { + lua_pushnumber(L, pow(luaL_checknumber(L, 1), luaL_checknumber(L, 2))); + return 1; +} + +static int math_log (lua_State *L) { + lua_pushnumber(L, log(luaL_checknumber(L, 1))); + return 1; +} + +static int math_log10 (lua_State *L) { + lua_pushnumber(L, log10(luaL_checknumber(L, 1))); + return 1; +} + +static int math_exp (lua_State *L) { + lua_pushnumber(L, exp(luaL_checknumber(L, 1))); + return 1; +} + +static int math_deg (lua_State *L) { + lua_pushnumber(L, luaL_checknumber(L, 1)/RADIANS_PER_DEGREE); + return 1; +} + +static int math_rad (lua_State *L) { + lua_pushnumber(L, luaL_checknumber(L, 1)*RADIANS_PER_DEGREE); + return 1; +} + +static int math_frexp (lua_State *L) { + int e; + lua_pushnumber(L, frexp(luaL_checknumber(L, 1), &e)); + lua_pushinteger(L, e); + return 2; +} + +static int math_ldexp (lua_State *L) { + lua_pushnumber(L, ldexp(luaL_checknumber(L, 1), luaL_checkint(L, 2))); + return 1; +} + + + +static int math_min (lua_State *L) { + int n = lua_gettop(L); /* number of arguments */ + lua_Number dmin = luaL_checknumber(L, 1); + int i; + for (i=2; i<=n; i++) { + lua_Number d = luaL_checknumber(L, i); + if (d < dmin) + dmin = d; + } + lua_pushnumber(L, dmin); + return 1; +} + + +static int math_max (lua_State *L) { + int n = lua_gettop(L); /* number of arguments */ + lua_Number dmax = luaL_checknumber(L, 1); + int i; + for (i=2; i<=n; i++) { + lua_Number d = luaL_checknumber(L, i); + if (d > dmax) + dmax = d; + } + lua_pushnumber(L, dmax); + return 1; +} + + +static int math_random (lua_State *L) { + /* the `%' avoids the (rare) case of r==1, and is needed also because on + some systems (SunOS!) `rand()' may return a value larger than RAND_MAX */ + lua_Number r = (lua_Number)(rand()%RAND_MAX) / (lua_Number)RAND_MAX; + switch (lua_gettop(L)) { /* check number of arguments */ + case 0: { /* no arguments */ + lua_pushnumber(L, r); /* Number between 0 and 1 */ + break; + } + case 1: { /* only upper limit */ + int u = luaL_checkint(L, 1); + luaL_argcheck(L, 1<=u, 1, "interval is empty"); + lua_pushnumber(L, floor(r*u)+1); /* int between 1 and `u' */ + break; + } + case 2: { /* lower and upper limits */ + int l = luaL_checkint(L, 1); + int u = luaL_checkint(L, 2); + luaL_argcheck(L, l<=u, 2, "interval is empty"); + lua_pushnumber(L, floor(r*(u-l+1))+l); /* int between `l' and `u' */ + break; + } + default: return luaL_error(L, "wrong number of arguments"); + } + return 1; +} + + +static int math_randomseed (lua_State *L) { + srand(luaL_checkint(L, 1)); + return 0; +} + + +static const luaL_Reg mathlib[] = { + {"abs", math_abs}, + {"acos", math_acos}, + {"asin", math_asin}, + {"atan2", math_atan2}, + {"atan", math_atan}, + {"ceil", math_ceil}, + {"cosh", math_cosh}, + {"cos", math_cos}, + {"deg", math_deg}, + {"exp", math_exp}, + {"floor", math_floor}, + {"fmod", math_fmod}, + {"frexp", math_frexp}, + {"ldexp", math_ldexp}, + {"log10", math_log10}, + {"log", math_log}, + {"max", math_max}, + {"min", math_min}, + {"modf", math_modf}, + {"pow", math_pow}, + {"rad", math_rad}, + {"random", math_random}, + {"randomseed", math_randomseed}, + {"sinh", math_sinh}, + {"sin", math_sin}, + {"sqrt", math_sqrt}, + {"tanh", math_tanh}, + {"tan", math_tan}, + {NULL, NULL} +}; + + +/* +** Open math library +*/ +LUALIB_API int luaopen_math (lua_State *L) { + luaL_register(L, LUA_MATHLIBNAME, mathlib); + lua_pushnumber(L, PI); + lua_setfield(L, -2, "pi"); + lua_pushnumber(L, HUGE_VAL); + lua_setfield(L, -2, "huge"); +#if defined(LUA_COMPAT_MOD) + lua_getfield(L, -1, "fmod"); + lua_setfield(L, -2, "mod"); +#endif + return 1; +} + diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lmem.c b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lmem.c new file mode 100644 index 00000000..ae7d8c96 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lmem.c @@ -0,0 +1,86 @@ +/* +** $Id: lmem.c,v 1.70.1.1 2007/12/27 13:02:25 roberto Exp $ +** Interface to Memory Manager +** See Copyright Notice in lua.h +*/ + + +#include + +#define lmem_c +#define LUA_CORE + +#include "lua.h" + +#include "ldebug.h" +#include "ldo.h" +#include "lmem.h" +#include "lobject.h" +#include "lstate.h" + + + +/* +** About the realloc function: +** void * frealloc (void *ud, void *ptr, size_t osize, size_t nsize); +** (`osize' is the old size, `nsize' is the new size) +** +** Lua ensures that (ptr == NULL) iff (osize == 0). +** +** * frealloc(ud, NULL, 0, x) creates a new block of size `x' +** +** * frealloc(ud, p, x, 0) frees the block `p' +** (in this specific case, frealloc must return NULL). +** particularly, frealloc(ud, NULL, 0, 0) does nothing +** (which is equivalent to free(NULL) in ANSI C) +** +** frealloc returns NULL if it cannot create or reallocate the area +** (any reallocation to an equal or smaller size cannot fail!) +*/ + + + +#define MINSIZEARRAY 4 + + +void *luaM_growaux_ (lua_State *L, void *block, int *size, size_t size_elems, + int limit, const char *errormsg) { + void *newblock; + int newsize; + if (*size >= limit/2) { /* cannot double it? */ + if (*size >= limit) /* cannot grow even a little? */ + luaG_runerror(L, errormsg); + newsize = limit; /* still have at least one free place */ + } + else { + newsize = (*size)*2; + if (newsize < MINSIZEARRAY) + newsize = MINSIZEARRAY; /* minimum size */ + } + newblock = luaM_reallocv(L, block, *size, newsize, size_elems); + *size = newsize; /* update only when everything else is OK */ + return newblock; +} + + +void *luaM_toobig (lua_State *L) { + luaG_runerror(L, "memory allocation error: block too big"); + return NULL; /* to avoid warnings */ +} + + + +/* +** generic allocation routine. +*/ +void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) { + global_State *g = G(L); + lua_assert((osize == 0) == (block == NULL)); + block = (*g->frealloc)(g->ud, block, osize, nsize); + if (block == NULL && nsize > 0) + luaD_throw(L, LUA_ERRMEM); + lua_assert((nsize == 0) == (block == NULL)); + g->totalbytes = (g->totalbytes - osize) + nsize; + return block; +} + diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lmem.h b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lmem.h new file mode 100644 index 00000000..7c2dcb32 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lmem.h @@ -0,0 +1,49 @@ +/* +** $Id: lmem.h,v 1.31.1.1 2007/12/27 13:02:25 roberto Exp $ +** Interface to Memory Manager +** See Copyright Notice in lua.h +*/ + +#ifndef lmem_h +#define lmem_h + + +#include + +#include "llimits.h" +#include "lua.h" + +#define MEMERRMSG "not enough memory" + + +#define luaM_reallocv(L,b,on,n,e) \ + ((cast(size_t, (n)+1) <= MAX_SIZET/(e)) ? /* +1 to avoid warnings */ \ + luaM_realloc_(L, (b), (on)*(e), (n)*(e)) : \ + luaM_toobig(L)) + +#define luaM_freemem(L, b, s) luaM_realloc_(L, (b), (s), 0) +#define luaM_free(L, b) luaM_realloc_(L, (b), sizeof(*(b)), 0) +#define luaM_freearray(L, b, n, t) luaM_reallocv(L, (b), n, 0, sizeof(t)) + +#define luaM_malloc(L,t) luaM_realloc_(L, NULL, 0, (t)) +#define luaM_new(L,t) cast(t *, luaM_malloc(L, sizeof(t))) +#define luaM_newvector(L,n,t) \ + cast(t *, luaM_reallocv(L, NULL, 0, n, sizeof(t))) + +#define luaM_growvector(L,v,nelems,size,t,limit,e) \ + if ((nelems)+1 > (size)) \ + ((v)=cast(t *, luaM_growaux_(L,v,&(size),sizeof(t),limit,e))) + +#define luaM_reallocvector(L, v,oldn,n,t) \ + ((v)=cast(t *, luaM_reallocv(L, v, oldn, n, sizeof(t)))) + + +LUAI_FUNC void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize, + size_t size); +LUAI_FUNC void *luaM_toobig (lua_State *L); +LUAI_FUNC void *luaM_growaux_ (lua_State *L, void *block, int *size, + size_t size_elem, int limit, + const char *errormsg); + +#endif + diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/loadlib.c b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/loadlib.c new file mode 100644 index 00000000..0d401eba --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/loadlib.c @@ -0,0 +1,666 @@ +/* +** $Id: loadlib.c,v 1.52.1.3 2008/08/06 13:29:28 roberto Exp $ +** Dynamic library loader for Lua +** See Copyright Notice in lua.h +** +** This module contains an implementation of loadlib for Unix systems +** that have dlfcn, an implementation for Darwin (Mac OS X), an +** implementation for Windows, and a stub for other systems. +*/ + + +#include +#include + + +#define loadlib_c +#define LUA_LIB + +#include "lua.h" + +#include "lauxlib.h" +#include "lualib.h" + + +/* prefix for open functions in C libraries */ +#define LUA_POF "luaopen_" + +/* separator for open functions in C libraries */ +#define LUA_OFSEP "_" + + +#define LIBPREFIX "LOADLIB: " + +#define POF LUA_POF +#define LIB_FAIL "open" + + +/* error codes for ll_loadfunc */ +#define ERRLIB 1 +#define ERRFUNC 2 + +#define setprogdir(L) ((void)0) + + +static void ll_unloadlib (void *lib); +static void *ll_load (lua_State *L, const char *path); +static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym); + + + +#if defined(LUA_DL_DLOPEN) +/* +** {======================================================================== +** This is an implementation of loadlib based on the dlfcn interface. +** The dlfcn interface is available in Linux, SunOS, Solaris, IRIX, FreeBSD, +** NetBSD, AIX 4.2, HPUX 11, and probably most other Unix flavors, at least +** as an emulation layer on top of native functions. +** ========================================================================= +*/ + +#include + +static void ll_unloadlib (void *lib) { + dlclose(lib); +} + + +static void *ll_load (lua_State *L, const char *path) { + void *lib = dlopen(path, RTLD_NOW); + if (lib == NULL) lua_pushstring(L, dlerror()); + return lib; +} + + +static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) { + lua_CFunction f = (lua_CFunction)dlsym(lib, sym); + if (f == NULL) lua_pushstring(L, dlerror()); + return f; +} + +/* }====================================================== */ + + + +#elif defined(LUA_DL_DLL) +/* +** {====================================================================== +** This is an implementation of loadlib for Windows using native functions. +** ======================================================================= +*/ + +#include + + +#undef setprogdir + +static void setprogdir (lua_State *L) { + char buff[MAX_PATH + 1]; + char *lb; + DWORD nsize = sizeof(buff)/sizeof(char); + DWORD n = GetModuleFileNameA(NULL, buff, nsize); + if (n == 0 || n == nsize || (lb = strrchr(buff, '\\')) == NULL) + luaL_error(L, "unable to get ModuleFileName"); + else { + *lb = '\0'; + luaL_gsub(L, lua_tostring(L, -1), LUA_EXECDIR, buff); + lua_remove(L, -2); /* remove original string */ + } +} + + +static void pusherror (lua_State *L) { + int error = GetLastError(); + char buffer[128]; + if (FormatMessageA(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM, + NULL, error, 0, buffer, sizeof(buffer), NULL)) + lua_pushstring(L, buffer); + else + lua_pushfstring(L, "system error %d\n", error); +} + +static void ll_unloadlib (void *lib) { + FreeLibrary((HINSTANCE)lib); +} + + +static void *ll_load (lua_State *L, const char *path) { + HINSTANCE lib = LoadLibraryA(path); + if (lib == NULL) pusherror(L); + return lib; +} + + +static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) { + lua_CFunction f = (lua_CFunction)GetProcAddress((HINSTANCE)lib, sym); + if (f == NULL) pusherror(L); + return f; +} + +/* }====================================================== */ + + + +#elif defined(LUA_DL_DYLD) +/* +** {====================================================================== +** Native Mac OS X / Darwin Implementation +** ======================================================================= +*/ + +#include + + +/* Mac appends a `_' before C function names */ +#undef POF +#define POF "_" LUA_POF + + +static void pusherror (lua_State *L) { + const char *err_str; + const char *err_file; + NSLinkEditErrors err; + int err_num; + NSLinkEditError(&err, &err_num, &err_file, &err_str); + lua_pushstring(L, err_str); +} + + +static const char *errorfromcode (NSObjectFileImageReturnCode ret) { + switch (ret) { + case NSObjectFileImageInappropriateFile: + return "file is not a bundle"; + case NSObjectFileImageArch: + return "library is for wrong CPU type"; + case NSObjectFileImageFormat: + return "bad format"; + case NSObjectFileImageAccess: + return "cannot access file"; + case NSObjectFileImageFailure: + default: + return "unable to load library"; + } +} + + +static void ll_unloadlib (void *lib) { + NSUnLinkModule((NSModule)lib, NSUNLINKMODULE_OPTION_RESET_LAZY_REFERENCES); +} + + +static void *ll_load (lua_State *L, const char *path) { + NSObjectFileImage img; + NSObjectFileImageReturnCode ret; + /* this would be a rare case, but prevents crashing if it happens */ + if(!_dyld_present()) { + lua_pushliteral(L, "dyld not present"); + return NULL; + } + ret = NSCreateObjectFileImageFromFile(path, &img); + if (ret == NSObjectFileImageSuccess) { + NSModule mod = NSLinkModule(img, path, NSLINKMODULE_OPTION_PRIVATE | + NSLINKMODULE_OPTION_RETURN_ON_ERROR); + NSDestroyObjectFileImage(img); + if (mod == NULL) pusherror(L); + return mod; + } + lua_pushstring(L, errorfromcode(ret)); + return NULL; +} + + +static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) { + NSSymbol nss = NSLookupSymbolInModule((NSModule)lib, sym); + if (nss == NULL) { + lua_pushfstring(L, "symbol " LUA_QS " not found", sym); + return NULL; + } + return (lua_CFunction)NSAddressOfSymbol(nss); +} + +/* }====================================================== */ + + + +#else +/* +** {====================================================== +** Fallback for other systems +** ======================================================= +*/ + +#undef LIB_FAIL +#define LIB_FAIL "absent" + + +#define DLMSG "dynamic libraries not enabled; check your Lua installation" + + +static void ll_unloadlib (void *lib) { + (void)lib; /* to avoid warnings */ +} + + +static void *ll_load (lua_State *L, const char *path) { + (void)path; /* to avoid warnings */ + lua_pushliteral(L, DLMSG); + return NULL; +} + + +static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) { + (void)lib; (void)sym; /* to avoid warnings */ + lua_pushliteral(L, DLMSG); + return NULL; +} + +/* }====================================================== */ +#endif + + + +static void **ll_register (lua_State *L, const char *path) { + void **plib; + lua_pushfstring(L, "%s%s", LIBPREFIX, path); + lua_gettable(L, LUA_REGISTRYINDEX); /* check library in registry? */ + if (!lua_isnil(L, -1)) /* is there an entry? */ + plib = (void **)lua_touserdata(L, -1); + else { /* no entry yet; create one */ + lua_pop(L, 1); + plib = (void **)lua_newuserdata(L, sizeof(const void *)); + *plib = NULL; + luaL_getmetatable(L, "_LOADLIB"); + lua_setmetatable(L, -2); + lua_pushfstring(L, "%s%s", LIBPREFIX, path); + lua_pushvalue(L, -2); + lua_settable(L, LUA_REGISTRYINDEX); + } + return plib; +} + + +/* +** __gc tag method: calls library's `ll_unloadlib' function with the lib +** handle +*/ +static int gctm (lua_State *L) { + void **lib = (void **)luaL_checkudata(L, 1, "_LOADLIB"); + if (*lib) ll_unloadlib(*lib); + *lib = NULL; /* mark library as closed */ + return 0; +} + + +static int ll_loadfunc (lua_State *L, const char *path, const char *sym) { + void **reg = ll_register(L, path); + if (*reg == NULL) *reg = ll_load(L, path); + if (*reg == NULL) + return ERRLIB; /* unable to load library */ + else { + lua_CFunction f = ll_sym(L, *reg, sym); + if (f == NULL) + return ERRFUNC; /* unable to find function */ + lua_pushcfunction(L, f); + return 0; /* return function */ + } +} + + +static int ll_loadlib (lua_State *L) { + const char *path = luaL_checkstring(L, 1); + const char *init = luaL_checkstring(L, 2); + int stat = ll_loadfunc(L, path, init); + if (stat == 0) /* no errors? */ + return 1; /* return the loaded function */ + else { /* error; error message is on stack top */ + lua_pushnil(L); + lua_insert(L, -2); + lua_pushstring(L, (stat == ERRLIB) ? LIB_FAIL : "init"); + return 3; /* return nil, error message, and where */ + } +} + + + +/* +** {====================================================== +** 'require' function +** ======================================================= +*/ + + +static int readable (const char *filename) { + FILE *f = fopen(filename, "r"); /* try to open file */ + if (f == NULL) return 0; /* open failed */ + fclose(f); + return 1; +} + + +static const char *pushnexttemplate (lua_State *L, const char *path) { + const char *l; + while (*path == *LUA_PATHSEP) path++; /* skip separators */ + if (*path == '\0') return NULL; /* no more templates */ + l = strchr(path, *LUA_PATHSEP); /* find next separator */ + if (l == NULL) l = path + strlen(path); + lua_pushlstring(L, path, l - path); /* template */ + return l; +} + + +static const char *findfile (lua_State *L, const char *name, + const char *pname) { + const char *path; + name = luaL_gsub(L, name, ".", LUA_DIRSEP); + lua_getfield(L, LUA_ENVIRONINDEX, pname); + path = lua_tostring(L, -1); + if (path == NULL) + luaL_error(L, LUA_QL("package.%s") " must be a string", pname); + lua_pushliteral(L, ""); /* error accumulator */ + while ((path = pushnexttemplate(L, path)) != NULL) { + const char *filename; + filename = luaL_gsub(L, lua_tostring(L, -1), LUA_PATH_MARK, name); + lua_remove(L, -2); /* remove path template */ + if (readable(filename)) /* does file exist and is readable? */ + return filename; /* return that file name */ + lua_pushfstring(L, "\n\tno file " LUA_QS, filename); + lua_remove(L, -2); /* remove file name */ + lua_concat(L, 2); /* add entry to possible error message */ + } + return NULL; /* not found */ +} + + +static void loaderror (lua_State *L, const char *filename) { + luaL_error(L, "error loading module " LUA_QS " from file " LUA_QS ":\n\t%s", + lua_tostring(L, 1), filename, lua_tostring(L, -1)); +} + + +static int loader_Lua (lua_State *L) { + const char *filename; + const char *name = luaL_checkstring(L, 1); + filename = findfile(L, name, "path"); + if (filename == NULL) return 1; /* library not found in this path */ + if (luaL_loadfile(L, filename) != 0) + loaderror(L, filename); + return 1; /* library loaded successfully */ +} + + +static const char *mkfuncname (lua_State *L, const char *modname) { + const char *funcname; + const char *mark = strchr(modname, *LUA_IGMARK); + if (mark) modname = mark + 1; + funcname = luaL_gsub(L, modname, ".", LUA_OFSEP); + funcname = lua_pushfstring(L, POF"%s", funcname); + lua_remove(L, -2); /* remove 'gsub' result */ + return funcname; +} + + +static int loader_C (lua_State *L) { + const char *funcname; + const char *name = luaL_checkstring(L, 1); + const char *filename = findfile(L, name, "cpath"); + if (filename == NULL) return 1; /* library not found in this path */ + funcname = mkfuncname(L, name); + if (ll_loadfunc(L, filename, funcname) != 0) + loaderror(L, filename); + return 1; /* library loaded successfully */ +} + + +static int loader_Croot (lua_State *L) { + const char *funcname; + const char *filename; + const char *name = luaL_checkstring(L, 1); + const char *p = strchr(name, '.'); + int stat; + if (p == NULL) return 0; /* is root */ + lua_pushlstring(L, name, p - name); + filename = findfile(L, lua_tostring(L, -1), "cpath"); + if (filename == NULL) return 1; /* root not found */ + funcname = mkfuncname(L, name); + if ((stat = ll_loadfunc(L, filename, funcname)) != 0) { + if (stat != ERRFUNC) loaderror(L, filename); /* real error */ + lua_pushfstring(L, "\n\tno module " LUA_QS " in file " LUA_QS, + name, filename); + return 1; /* function not found */ + } + return 1; +} + + +static int loader_preload (lua_State *L) { + const char *name = luaL_checkstring(L, 1); + lua_getfield(L, LUA_ENVIRONINDEX, "preload"); + if (!lua_istable(L, -1)) + luaL_error(L, LUA_QL("package.preload") " must be a table"); + lua_getfield(L, -1, name); + if (lua_isnil(L, -1)) /* not found? */ + lua_pushfstring(L, "\n\tno field package.preload['%s']", name); + return 1; +} + + +static const int sentinel_ = 0; +#define sentinel ((void *)&sentinel_) + + +static int ll_require (lua_State *L) { + const char *name = luaL_checkstring(L, 1); + int i; + lua_settop(L, 1); /* _LOADED table will be at index 2 */ + lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED"); + lua_getfield(L, 2, name); + if (lua_toboolean(L, -1)) { /* is it there? */ + if (lua_touserdata(L, -1) == sentinel) /* check loops */ + luaL_error(L, "loop or previous error loading module " LUA_QS, name); + return 1; /* package is already loaded */ + } + /* else must load it; iterate over available loaders */ + lua_getfield(L, LUA_ENVIRONINDEX, "loaders"); + if (!lua_istable(L, -1)) + luaL_error(L, LUA_QL("package.loaders") " must be a table"); + lua_pushliteral(L, ""); /* error message accumulator */ + for (i=1; ; i++) { + lua_rawgeti(L, -2, i); /* get a loader */ + if (lua_isnil(L, -1)) + luaL_error(L, "module " LUA_QS " not found:%s", + name, lua_tostring(L, -2)); + lua_pushstring(L, name); + lua_call(L, 1, 1); /* call it */ + if (lua_isfunction(L, -1)) /* did it find module? */ + break; /* module loaded successfully */ + else if (lua_isstring(L, -1)) /* loader returned error message? */ + lua_concat(L, 2); /* accumulate it */ + else + lua_pop(L, 1); + } + lua_pushlightuserdata(L, sentinel); + lua_setfield(L, 2, name); /* _LOADED[name] = sentinel */ + lua_pushstring(L, name); /* pass name as argument to module */ + lua_call(L, 1, 1); /* run loaded module */ + if (!lua_isnil(L, -1)) /* non-nil return? */ + lua_setfield(L, 2, name); /* _LOADED[name] = returned value */ + lua_getfield(L, 2, name); + if (lua_touserdata(L, -1) == sentinel) { /* module did not set a value? */ + lua_pushboolean(L, 1); /* use true as result */ + lua_pushvalue(L, -1); /* extra copy to be returned */ + lua_setfield(L, 2, name); /* _LOADED[name] = true */ + } + return 1; +} + +/* }====================================================== */ + + + +/* +** {====================================================== +** 'module' function +** ======================================================= +*/ + + +static void setfenv (lua_State *L) { + lua_Debug ar; + if (lua_getstack(L, 1, &ar) == 0 || + lua_getinfo(L, "f", &ar) == 0 || /* get calling function */ + lua_iscfunction(L, -1)) + luaL_error(L, LUA_QL("module") " not called from a Lua function"); + lua_pushvalue(L, -2); + lua_setfenv(L, -2); + lua_pop(L, 1); +} + + +static void dooptions (lua_State *L, int n) { + int i; + for (i = 2; i <= n; i++) { + lua_pushvalue(L, i); /* get option (a function) */ + lua_pushvalue(L, -2); /* module */ + lua_call(L, 1, 0); + } +} + + +static void modinit (lua_State *L, const char *modname) { + const char *dot; + lua_pushvalue(L, -1); + lua_setfield(L, -2, "_M"); /* module._M = module */ + lua_pushstring(L, modname); + lua_setfield(L, -2, "_NAME"); + dot = strrchr(modname, '.'); /* look for last dot in module name */ + if (dot == NULL) dot = modname; + else dot++; + /* set _PACKAGE as package name (full module name minus last part) */ + lua_pushlstring(L, modname, dot - modname); + lua_setfield(L, -2, "_PACKAGE"); +} + + +static int ll_module (lua_State *L) { + const char *modname = luaL_checkstring(L, 1); + int loaded = lua_gettop(L) + 1; /* index of _LOADED table */ + lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED"); + lua_getfield(L, loaded, modname); /* get _LOADED[modname] */ + if (!lua_istable(L, -1)) { /* not found? */ + lua_pop(L, 1); /* remove previous result */ + /* try global variable (and create one if it does not exist) */ + if (luaL_findtable(L, LUA_GLOBALSINDEX, modname, 1) != NULL) + return luaL_error(L, "name conflict for module " LUA_QS, modname); + lua_pushvalue(L, -1); + lua_setfield(L, loaded, modname); /* _LOADED[modname] = new table */ + } + /* check whether table already has a _NAME field */ + lua_getfield(L, -1, "_NAME"); + if (!lua_isnil(L, -1)) /* is table an initialized module? */ + lua_pop(L, 1); + else { /* no; initialize it */ + lua_pop(L, 1); + modinit(L, modname); + } + lua_pushvalue(L, -1); + setfenv(L); + dooptions(L, loaded - 1); + return 0; +} + + +static int ll_seeall (lua_State *L) { + luaL_checktype(L, 1, LUA_TTABLE); + if (!lua_getmetatable(L, 1)) { + lua_createtable(L, 0, 1); /* create new metatable */ + lua_pushvalue(L, -1); + lua_setmetatable(L, 1); + } + lua_pushvalue(L, LUA_GLOBALSINDEX); + lua_setfield(L, -2, "__index"); /* mt.__index = _G */ + return 0; +} + + +/* }====================================================== */ + + + +/* auxiliary mark (for internal use) */ +#define AUXMARK "\1" + +static void setpath (lua_State *L, const char *fieldname, const char *envname, + const char *def) { + const char *path = getenv(envname); + if (path == NULL) /* no environment variable? */ + lua_pushstring(L, def); /* use default */ + else { + /* replace ";;" by ";AUXMARK;" and then AUXMARK by default path */ + path = luaL_gsub(L, path, LUA_PATHSEP LUA_PATHSEP, + LUA_PATHSEP AUXMARK LUA_PATHSEP); + luaL_gsub(L, path, AUXMARK, def); + lua_remove(L, -2); + } + setprogdir(L); + lua_setfield(L, -2, fieldname); +} + + +static const luaL_Reg pk_funcs[] = { + {"loadlib", ll_loadlib}, + {"seeall", ll_seeall}, + {NULL, NULL} +}; + + +static const luaL_Reg ll_funcs[] = { + {"module", ll_module}, + {"require", ll_require}, + {NULL, NULL} +}; + + +static const lua_CFunction loaders[] = + {loader_preload, loader_Lua, loader_C, loader_Croot, NULL}; + + +LUALIB_API int luaopen_package (lua_State *L) { + int i; + /* create new type _LOADLIB */ + luaL_newmetatable(L, "_LOADLIB"); + lua_pushcfunction(L, gctm); + lua_setfield(L, -2, "__gc"); + /* create `package' table */ + luaL_register(L, LUA_LOADLIBNAME, pk_funcs); +#if defined(LUA_COMPAT_LOADLIB) + lua_getfield(L, -1, "loadlib"); + lua_setfield(L, LUA_GLOBALSINDEX, "loadlib"); +#endif + lua_pushvalue(L, -1); + lua_replace(L, LUA_ENVIRONINDEX); + /* create `loaders' table */ + lua_createtable(L, 0, sizeof(loaders)/sizeof(loaders[0]) - 1); + /* fill it with pre-defined loaders */ + for (i=0; loaders[i] != NULL; i++) { + lua_pushcfunction(L, loaders[i]); + lua_rawseti(L, -2, i+1); + } + lua_setfield(L, -2, "loaders"); /* put it in field `loaders' */ + setpath(L, "path", LUA_PATH, LUA_PATH_DEFAULT); /* set field `path' */ + setpath(L, "cpath", LUA_CPATH, LUA_CPATH_DEFAULT); /* set field `cpath' */ + /* store config information */ + lua_pushliteral(L, LUA_DIRSEP "\n" LUA_PATHSEP "\n" LUA_PATH_MARK "\n" + LUA_EXECDIR "\n" LUA_IGMARK); + lua_setfield(L, -2, "config"); + /* set field `loaded' */ + luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 2); + lua_setfield(L, -2, "loaded"); + /* set field `preload' */ + lua_newtable(L); + lua_setfield(L, -2, "preload"); + lua_pushvalue(L, LUA_GLOBALSINDEX); + luaL_register(L, NULL, ll_funcs); /* open lib into global table */ + lua_pop(L, 1); + return 1; /* return 'package' table */ +} + diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lobject.c b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lobject.c new file mode 100644 index 00000000..4ff50732 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lobject.c @@ -0,0 +1,214 @@ +/* +** $Id: lobject.c,v 2.22.1.1 2007/12/27 13:02:25 roberto Exp $ +** Some generic functions over Lua objects +** See Copyright Notice in lua.h +*/ + +#include +#include +#include +#include +#include + +#define lobject_c +#define LUA_CORE + +#include "lua.h" + +#include "ldo.h" +#include "lmem.h" +#include "lobject.h" +#include "lstate.h" +#include "lstring.h" +#include "lvm.h" + + + +const TValue luaO_nilobject_ = {{NULL}, LUA_TNIL}; + + +/* +** converts an integer to a "floating point byte", represented as +** (eeeeexxx), where the real value is (1xxx) * 2^(eeeee - 1) if +** eeeee != 0 and (xxx) otherwise. +*/ +int luaO_int2fb (unsigned int x) { + int e = 0; /* expoent */ + while (x >= 16) { + x = (x+1) >> 1; + e++; + } + if (x < 8) return x; + else return ((e+1) << 3) | (cast_int(x) - 8); +} + + +/* converts back */ +int luaO_fb2int (int x) { + int e = (x >> 3) & 31; + if (e == 0) return x; + else return ((x & 7)+8) << (e - 1); +} + + +int luaO_log2 (unsigned int x) { + static const lu_byte log_2[256] = { + 0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5, + 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, + 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, + 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, + 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, + 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, + 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, + 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8 + }; + int l = -1; + while (x >= 256) { l += 8; x >>= 8; } + return l + log_2[x]; + +} + + +int luaO_rawequalObj (const TValue *t1, const TValue *t2) { + if (ttype(t1) != ttype(t2)) return 0; + else switch (ttype(t1)) { + case LUA_TNIL: + return 1; + case LUA_TNUMBER: + return luai_numeq(nvalue(t1), nvalue(t2)); + case LUA_TBOOLEAN: + return bvalue(t1) == bvalue(t2); /* boolean true must be 1 !! */ + case LUA_TLIGHTUSERDATA: + return pvalue(t1) == pvalue(t2); + default: + lua_assert(iscollectable(t1)); + return gcvalue(t1) == gcvalue(t2); + } +} + + +int luaO_str2d (const char *s, lua_Number *result) { + char *endptr; + *result = lua_str2number(s, &endptr); + if (endptr == s) return 0; /* conversion failed */ + if (*endptr == 'x' || *endptr == 'X') /* maybe an hexadecimal constant? */ + *result = cast_num(strtoul(s, &endptr, 16)); + if (*endptr == '\0') return 1; /* most common case */ + while (isspace(cast(unsigned char, *endptr))) endptr++; + if (*endptr != '\0') return 0; /* invalid trailing characters? */ + return 1; +} + + + +static void pushstr (lua_State *L, const char *str) { + setsvalue2s(L, L->top, luaS_new(L, str)); + incr_top(L); +} + + +/* this function handles only `%d', `%c', %f, %p, and `%s' formats */ +const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) { + int n = 1; + pushstr(L, ""); + for (;;) { + const char *e = strchr(fmt, '%'); + if (e == NULL) break; + setsvalue2s(L, L->top, luaS_newlstr(L, fmt, e-fmt)); + incr_top(L); + switch (*(e+1)) { + case 's': { + const char *s = va_arg(argp, char *); + if (s == NULL) s = "(null)"; + pushstr(L, s); + break; + } + case 'c': { + char buff[2]; + buff[0] = cast(char, va_arg(argp, int)); + buff[1] = '\0'; + pushstr(L, buff); + break; + } + case 'd': { + setnvalue(L->top, cast_num(va_arg(argp, int))); + incr_top(L); + break; + } + case 'f': { + setnvalue(L->top, cast_num(va_arg(argp, l_uacNumber))); + incr_top(L); + break; + } + case 'p': { + char buff[4*sizeof(void *) + 8]; /* should be enough space for a `%p' */ + sprintf(buff, "%p", va_arg(argp, void *)); + pushstr(L, buff); + break; + } + case '%': { + pushstr(L, "%"); + break; + } + default: { + char buff[3]; + buff[0] = '%'; + buff[1] = *(e+1); + buff[2] = '\0'; + pushstr(L, buff); + break; + } + } + n += 2; + fmt = e+2; + } + pushstr(L, fmt); + luaV_concat(L, n+1, cast_int(L->top - L->base) - 1); + L->top -= n; + return svalue(L->top - 1); +} + + +const char *luaO_pushfstring (lua_State *L, const char *fmt, ...) { + const char *msg; + va_list argp; + va_start(argp, fmt); + msg = luaO_pushvfstring(L, fmt, argp); + va_end(argp); + return msg; +} + + +void luaO_chunkid (char *out, const char *source, size_t bufflen) { + if (*source == '=') { + strncpy(out, source+1, bufflen); /* remove first char */ + out[bufflen-1] = '\0'; /* ensures null termination */ + } + else { /* out = "source", or "...source" */ + if (*source == '@') { + size_t l; + source++; /* skip the `@' */ + bufflen -= sizeof(" '...' "); + l = strlen(source); + strcpy(out, ""); + if (l > bufflen) { + source += (l-bufflen); /* get last part of file name */ + strcat(out, "..."); + } + strcat(out, source); + } + else { /* out = [string "string"] */ + size_t len = strcspn(source, "\n\r"); /* stop at first newline */ + bufflen -= sizeof(" [string \"...\"] "); + if (len > bufflen) len = bufflen; + strcpy(out, "[string \""); + if (source[len] != '\0') { /* must truncate? */ + strncat(out, source, len); + strcat(out, "..."); + } + else + strcat(out, source); + strcat(out, "\"]"); + } + } +} diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lobject.h b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lobject.h new file mode 100644 index 00000000..f1e447ef --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lobject.h @@ -0,0 +1,381 @@ +/* +** $Id: lobject.h,v 2.20.1.2 2008/08/06 13:29:48 roberto Exp $ +** Type definitions for Lua objects +** See Copyright Notice in lua.h +*/ + + +#ifndef lobject_h +#define lobject_h + + +#include + + +#include "llimits.h" +#include "lua.h" + + +/* tags for values visible from Lua */ +#define LAST_TAG LUA_TTHREAD + +#define NUM_TAGS (LAST_TAG+1) + + +/* +** Extra tags for non-values +*/ +#define LUA_TPROTO (LAST_TAG+1) +#define LUA_TUPVAL (LAST_TAG+2) +#define LUA_TDEADKEY (LAST_TAG+3) + + +/* +** Union of all collectable objects +*/ +typedef union GCObject GCObject; + + +/* +** Common Header for all collectable objects (in macro form, to be +** included in other objects) +*/ +#define CommonHeader GCObject *next; lu_byte tt; lu_byte marked + + +/* +** Common header in struct form +*/ +typedef struct GCheader { + CommonHeader; +} GCheader; + + + + +/* +** Union of all Lua values +*/ +typedef union { + GCObject *gc; + void *p; + lua_Number n; + int b; +} Value; + + +/* +** Tagged Values +*/ + +#define TValuefields Value value; int tt + +typedef struct lua_TValue { + TValuefields; +} TValue; + + +/* Macros to test type */ +#define ttisnil(o) (ttype(o) == LUA_TNIL) +#define ttisnumber(o) (ttype(o) == LUA_TNUMBER) +#define ttisstring(o) (ttype(o) == LUA_TSTRING) +#define ttistable(o) (ttype(o) == LUA_TTABLE) +#define ttisfunction(o) (ttype(o) == LUA_TFUNCTION) +#define ttisboolean(o) (ttype(o) == LUA_TBOOLEAN) +#define ttisuserdata(o) (ttype(o) == LUA_TUSERDATA) +#define ttisthread(o) (ttype(o) == LUA_TTHREAD) +#define ttislightuserdata(o) (ttype(o) == LUA_TLIGHTUSERDATA) + +/* Macros to access values */ +#define ttype(o) ((o)->tt) +#define gcvalue(o) check_exp(iscollectable(o), (o)->value.gc) +#define pvalue(o) check_exp(ttislightuserdata(o), (o)->value.p) +#define nvalue(o) check_exp(ttisnumber(o), (o)->value.n) +#define rawtsvalue(o) check_exp(ttisstring(o), &(o)->value.gc->ts) +#define tsvalue(o) (&rawtsvalue(o)->tsv) +#define rawuvalue(o) check_exp(ttisuserdata(o), &(o)->value.gc->u) +#define uvalue(o) (&rawuvalue(o)->uv) +#define clvalue(o) check_exp(ttisfunction(o), &(o)->value.gc->cl) +#define hvalue(o) check_exp(ttistable(o), &(o)->value.gc->h) +#define bvalue(o) check_exp(ttisboolean(o), (o)->value.b) +#define thvalue(o) check_exp(ttisthread(o), &(o)->value.gc->th) + +#define l_isfalse(o) (ttisnil(o) || (ttisboolean(o) && bvalue(o) == 0)) + +/* +** for internal debug only +*/ +#define checkconsistency(obj) \ + lua_assert(!iscollectable(obj) || (ttype(obj) == (obj)->value.gc->gch.tt)) + +#define checkliveness(g,obj) \ + lua_assert(!iscollectable(obj) || \ + ((ttype(obj) == (obj)->value.gc->gch.tt) && !isdead(g, (obj)->value.gc))) + + +/* Macros to set values */ +#define setnilvalue(obj) ((obj)->tt=LUA_TNIL) + +#define setnvalue(obj,x) \ + { TValue *i_o=(obj); i_o->value.n=(x); i_o->tt=LUA_TNUMBER; } + +#define setpvalue(obj,x) \ + { TValue *i_o=(obj); i_o->value.p=(x); i_o->tt=LUA_TLIGHTUSERDATA; } + +#define setbvalue(obj,x) \ + { TValue *i_o=(obj); i_o->value.b=(x); i_o->tt=LUA_TBOOLEAN; } + +#define setsvalue(L,obj,x) \ + { TValue *i_o=(obj); \ + i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TSTRING; \ + checkliveness(G(L),i_o); } + +#define setuvalue(L,obj,x) \ + { TValue *i_o=(obj); \ + i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TUSERDATA; \ + checkliveness(G(L),i_o); } + +#define setthvalue(L,obj,x) \ + { TValue *i_o=(obj); \ + i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TTHREAD; \ + checkliveness(G(L),i_o); } + +#define setclvalue(L,obj,x) \ + { TValue *i_o=(obj); \ + i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TFUNCTION; \ + checkliveness(G(L),i_o); } + +#define sethvalue(L,obj,x) \ + { TValue *i_o=(obj); \ + i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TTABLE; \ + checkliveness(G(L),i_o); } + +#define setptvalue(L,obj,x) \ + { TValue *i_o=(obj); \ + i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TPROTO; \ + checkliveness(G(L),i_o); } + + + + +#define setobj(L,obj1,obj2) \ + { const TValue *o2=(obj2); TValue *o1=(obj1); \ + o1->value = o2->value; o1->tt=o2->tt; \ + checkliveness(G(L),o1); } + + +/* +** different types of sets, according to destination +*/ + +/* from stack to (same) stack */ +#define setobjs2s setobj +/* to stack (not from same stack) */ +#define setobj2s setobj +#define setsvalue2s setsvalue +#define sethvalue2s sethvalue +#define setptvalue2s setptvalue +/* from table to same table */ +#define setobjt2t setobj +/* to table */ +#define setobj2t setobj +/* to new object */ +#define setobj2n setobj +#define setsvalue2n setsvalue + +#define setttype(obj, tt) (ttype(obj) = (tt)) + + +#define iscollectable(o) (ttype(o) >= LUA_TSTRING) + + + +typedef TValue *StkId; /* index to stack elements */ + + +/* +** String headers for string table +*/ +typedef union TString { + L_Umaxalign dummy; /* ensures maximum alignment for strings */ + struct { + CommonHeader; + lu_byte reserved; + unsigned int hash; + size_t len; + } tsv; +} TString; + + +#define getstr(ts) cast(const char *, (ts) + 1) +#define svalue(o) getstr(rawtsvalue(o)) + + + +typedef union Udata { + L_Umaxalign dummy; /* ensures maximum alignment for `local' udata */ + struct { + CommonHeader; + struct Table *metatable; + struct Table *env; + size_t len; + } uv; +} Udata; + + + + +/* +** Function Prototypes +*/ +typedef struct Proto { + CommonHeader; + TValue *k; /* constants used by the function */ + Instruction *code; + struct Proto **p; /* functions defined inside the function */ + int *lineinfo; /* map from opcodes to source lines */ + struct LocVar *locvars; /* information about local variables */ + TString **upvalues; /* upvalue names */ + TString *source; + int sizeupvalues; + int sizek; /* size of `k' */ + int sizecode; + int sizelineinfo; + int sizep; /* size of `p' */ + int sizelocvars; + int linedefined; + int lastlinedefined; + GCObject *gclist; + lu_byte nups; /* number of upvalues */ + lu_byte numparams; + lu_byte is_vararg; + lu_byte maxstacksize; +} Proto; + + +/* masks for new-style vararg */ +#define VARARG_HASARG 1 +#define VARARG_ISVARARG 2 +#define VARARG_NEEDSARG 4 + + +typedef struct LocVar { + TString *varname; + int startpc; /* first point where variable is active */ + int endpc; /* first point where variable is dead */ +} LocVar; + + + +/* +** Upvalues +*/ + +typedef struct UpVal { + CommonHeader; + TValue *v; /* points to stack or to its own value */ + union { + TValue value; /* the value (when closed) */ + struct { /* double linked list (when open) */ + struct UpVal *prev; + struct UpVal *next; + } l; + } u; +} UpVal; + + +/* +** Closures +*/ + +#define ClosureHeader \ + CommonHeader; lu_byte isC; lu_byte nupvalues; GCObject *gclist; \ + struct Table *env + +typedef struct CClosure { + ClosureHeader; + lua_CFunction f; + TValue upvalue[1]; +} CClosure; + + +typedef struct LClosure { + ClosureHeader; + struct Proto *p; + UpVal *upvals[1]; +} LClosure; + + +typedef union Closure { + CClosure c; + LClosure l; +} Closure; + + +#define iscfunction(o) (ttype(o) == LUA_TFUNCTION && clvalue(o)->c.isC) +#define isLfunction(o) (ttype(o) == LUA_TFUNCTION && !clvalue(o)->c.isC) + + +/* +** Tables +*/ + +typedef union TKey { + struct { + TValuefields; + struct Node *next; /* for chaining */ + } nk; + TValue tvk; +} TKey; + + +typedef struct Node { + TValue i_val; + TKey i_key; +} Node; + + +typedef struct Table { + CommonHeader; + lu_byte flags; /* 1<

lsizenode)) + + +#define luaO_nilobject (&luaO_nilobject_) + +LUAI_DATA const TValue luaO_nilobject_; + +#define ceillog2(x) (luaO_log2((x)-1) + 1) + +LUAI_FUNC int luaO_log2 (unsigned int x); +LUAI_FUNC int luaO_int2fb (unsigned int x); +LUAI_FUNC int luaO_fb2int (int x); +LUAI_FUNC int luaO_rawequalObj (const TValue *t1, const TValue *t2); +LUAI_FUNC int luaO_str2d (const char *s, lua_Number *result); +LUAI_FUNC const char *luaO_pushvfstring (lua_State *L, const char *fmt, + va_list argp); +LUAI_FUNC const char *luaO_pushfstring (lua_State *L, const char *fmt, ...); +LUAI_FUNC void luaO_chunkid (char *out, const char *source, size_t len); + + +#endif + diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lopcodes.c b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lopcodes.c new file mode 100644 index 00000000..4cc74523 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lopcodes.c @@ -0,0 +1,102 @@ +/* +** $Id: lopcodes.c,v 1.37.1.1 2007/12/27 13:02:25 roberto Exp $ +** See Copyright Notice in lua.h +*/ + + +#define lopcodes_c +#define LUA_CORE + + +#include "lopcodes.h" + + +/* ORDER OP */ + +const char *const luaP_opnames[NUM_OPCODES+1] = { + "MOVE", + "LOADK", + "LOADBOOL", + "LOADNIL", + "GETUPVAL", + "GETGLOBAL", + "GETTABLE", + "SETGLOBAL", + "SETUPVAL", + "SETTABLE", + "NEWTABLE", + "SELF", + "ADD", + "SUB", + "MUL", + "DIV", + "MOD", + "POW", + "UNM", + "NOT", + "LEN", + "CONCAT", + "JMP", + "EQ", + "LT", + "LE", + "TEST", + "TESTSET", + "CALL", + "TAILCALL", + "RETURN", + "FORLOOP", + "FORPREP", + "TFORLOOP", + "SETLIST", + "CLOSE", + "CLOSURE", + "VARARG", + NULL +}; + + +#define opmode(t,a,b,c,m) (((t)<<7) | ((a)<<6) | ((b)<<4) | ((c)<<2) | (m)) + +const lu_byte luaP_opmodes[NUM_OPCODES] = { +/* T A B C mode opcode */ + opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_MOVE */ + ,opmode(0, 1, OpArgK, OpArgN, iABx) /* OP_LOADK */ + ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_LOADBOOL */ + ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_LOADNIL */ + ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_GETUPVAL */ + ,opmode(0, 1, OpArgK, OpArgN, iABx) /* OP_GETGLOBAL */ + ,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_GETTABLE */ + ,opmode(0, 0, OpArgK, OpArgN, iABx) /* OP_SETGLOBAL */ + ,opmode(0, 0, OpArgU, OpArgN, iABC) /* OP_SETUPVAL */ + ,opmode(0, 0, OpArgK, OpArgK, iABC) /* OP_SETTABLE */ + ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_NEWTABLE */ + ,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_SELF */ + ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_ADD */ + ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_SUB */ + ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_MUL */ + ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_DIV */ + ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_MOD */ + ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_POW */ + ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_UNM */ + ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_NOT */ + ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_LEN */ + ,opmode(0, 1, OpArgR, OpArgR, iABC) /* OP_CONCAT */ + ,opmode(0, 0, OpArgR, OpArgN, iAsBx) /* OP_JMP */ + ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_EQ */ + ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_LT */ + ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_LE */ + ,opmode(1, 1, OpArgR, OpArgU, iABC) /* OP_TEST */ + ,opmode(1, 1, OpArgR, OpArgU, iABC) /* OP_TESTSET */ + ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_CALL */ + ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_TAILCALL */ + ,opmode(0, 0, OpArgU, OpArgN, iABC) /* OP_RETURN */ + ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_FORLOOP */ + ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_FORPREP */ + ,opmode(1, 0, OpArgN, OpArgU, iABC) /* OP_TFORLOOP */ + ,opmode(0, 0, OpArgU, OpArgU, iABC) /* OP_SETLIST */ + ,opmode(0, 0, OpArgN, OpArgN, iABC) /* OP_CLOSE */ + ,opmode(0, 1, OpArgU, OpArgN, iABx) /* OP_CLOSURE */ + ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_VARARG */ +}; + diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lopcodes.h b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lopcodes.h new file mode 100644 index 00000000..41224d6e --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lopcodes.h @@ -0,0 +1,268 @@ +/* +** $Id: lopcodes.h,v 1.125.1.1 2007/12/27 13:02:25 roberto Exp $ +** Opcodes for Lua virtual machine +** See Copyright Notice in lua.h +*/ + +#ifndef lopcodes_h +#define lopcodes_h + +#include "llimits.h" + + +/*=========================================================================== + We assume that instructions are unsigned numbers. + All instructions have an opcode in the first 6 bits. + Instructions can have the following fields: + `A' : 8 bits + `B' : 9 bits + `C' : 9 bits + `Bx' : 18 bits (`B' and `C' together) + `sBx' : signed Bx + + A signed argument is represented in excess K; that is, the number + value is the unsigned value minus K. K is exactly the maximum value + for that argument (so that -max is represented by 0, and +max is + represented by 2*max), which is half the maximum for the corresponding + unsigned argument. +===========================================================================*/ + + +enum OpMode {iABC, iABx, iAsBx}; /* basic instruction format */ + + +/* +** size and position of opcode arguments. +*/ +#define SIZE_C 9 +#define SIZE_B 9 +#define SIZE_Bx (SIZE_C + SIZE_B) +#define SIZE_A 8 + +#define SIZE_OP 6 + +#define POS_OP 0 +#define POS_A (POS_OP + SIZE_OP) +#define POS_C (POS_A + SIZE_A) +#define POS_B (POS_C + SIZE_C) +#define POS_Bx POS_C + + +/* +** limits for opcode arguments. +** we use (signed) int to manipulate most arguments, +** so they must fit in LUAI_BITSINT-1 bits (-1 for sign) +*/ +#if SIZE_Bx < LUAI_BITSINT-1 +#define MAXARG_Bx ((1<>1) /* `sBx' is signed */ +#else +#define MAXARG_Bx MAX_INT +#define MAXARG_sBx MAX_INT +#endif + + +#define MAXARG_A ((1<>POS_OP) & MASK1(SIZE_OP,0))) +#define SET_OPCODE(i,o) ((i) = (((i)&MASK0(SIZE_OP,POS_OP)) | \ + ((cast(Instruction, o)<>POS_A) & MASK1(SIZE_A,0))) +#define SETARG_A(i,u) ((i) = (((i)&MASK0(SIZE_A,POS_A)) | \ + ((cast(Instruction, u)<>POS_B) & MASK1(SIZE_B,0))) +#define SETARG_B(i,b) ((i) = (((i)&MASK0(SIZE_B,POS_B)) | \ + ((cast(Instruction, b)<>POS_C) & MASK1(SIZE_C,0))) +#define SETARG_C(i,b) ((i) = (((i)&MASK0(SIZE_C,POS_C)) | \ + ((cast(Instruction, b)<>POS_Bx) & MASK1(SIZE_Bx,0))) +#define SETARG_Bx(i,b) ((i) = (((i)&MASK0(SIZE_Bx,POS_Bx)) | \ + ((cast(Instruction, b)< C) then pc++ */ +OP_TESTSET,/* A B C if (R(B) <=> C) then R(A) := R(B) else pc++ */ + +OP_CALL,/* A B C R(A), ... ,R(A+C-2) := R(A)(R(A+1), ... ,R(A+B-1)) */ +OP_TAILCALL,/* A B C return R(A)(R(A+1), ... ,R(A+B-1)) */ +OP_RETURN,/* A B return R(A), ... ,R(A+B-2) (see note) */ + +OP_FORLOOP,/* A sBx R(A)+=R(A+2); + if R(A) =) R(A)*/ +OP_CLOSURE,/* A Bx R(A) := closure(KPROTO[Bx], R(A), ... ,R(A+n)) */ + +OP_VARARG/* A B R(A), R(A+1), ..., R(A+B-1) = vararg */ +} OpCode; + + +#define NUM_OPCODES (cast(int, OP_VARARG) + 1) + + + +/*=========================================================================== + Notes: + (*) In OP_CALL, if (B == 0) then B = top. C is the number of returns - 1, + and can be 0: OP_CALL then sets `top' to last_result+1, so + next open instruction (OP_CALL, OP_RETURN, OP_SETLIST) may use `top'. + + (*) In OP_VARARG, if (B == 0) then use actual number of varargs and + set top (like in OP_CALL with C == 0). + + (*) In OP_RETURN, if (B == 0) then return up to `top' + + (*) In OP_SETLIST, if (B == 0) then B = `top'; + if (C == 0) then next `instruction' is real C + + (*) For comparisons, A specifies what condition the test should accept + (true or false). + + (*) All `skips' (pc++) assume that next instruction is a jump +===========================================================================*/ + + +/* +** masks for instruction properties. The format is: +** bits 0-1: op mode +** bits 2-3: C arg mode +** bits 4-5: B arg mode +** bit 6: instruction set register A +** bit 7: operator is a test +*/ + +enum OpArgMask { + OpArgN, /* argument is not used */ + OpArgU, /* argument is used */ + OpArgR, /* argument is a register or a jump offset */ + OpArgK /* argument is a constant or register/constant */ +}; + +LUAI_DATA const lu_byte luaP_opmodes[NUM_OPCODES]; + +#define getOpMode(m) (cast(enum OpMode, luaP_opmodes[m] & 3)) +#define getBMode(m) (cast(enum OpArgMask, (luaP_opmodes[m] >> 4) & 3)) +#define getCMode(m) (cast(enum OpArgMask, (luaP_opmodes[m] >> 2) & 3)) +#define testAMode(m) (luaP_opmodes[m] & (1 << 6)) +#define testTMode(m) (luaP_opmodes[m] & (1 << 7)) + + +LUAI_DATA const char *const luaP_opnames[NUM_OPCODES+1]; /* opcode names */ + + +/* number of list items to accumulate before a SETLIST instruction */ +#define LFIELDS_PER_FLUSH 50 + + +#endif diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/loslib.c b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/loslib.c new file mode 100644 index 00000000..da06a572 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/loslib.c @@ -0,0 +1,243 @@ +/* +** $Id: loslib.c,v 1.19.1.3 2008/01/18 16:38:18 roberto Exp $ +** Standard Operating System library +** See Copyright Notice in lua.h +*/ + + +#include +#include +#include +#include +#include + +#define loslib_c +#define LUA_LIB + +#include "lua.h" + +#include "lauxlib.h" +#include "lualib.h" + + +static int os_pushresult (lua_State *L, int i, const char *filename) { + int en = errno; /* calls to Lua API may change this value */ + if (i) { + lua_pushboolean(L, 1); + return 1; + } + else { + lua_pushnil(L); + lua_pushfstring(L, "%s: %s", filename, strerror(en)); + lua_pushinteger(L, en); + return 3; + } +} + + +static int os_execute (lua_State *L) { + lua_pushinteger(L, system(luaL_optstring(L, 1, NULL))); + return 1; +} + + +static int os_remove (lua_State *L) { + const char *filename = luaL_checkstring(L, 1); + return os_pushresult(L, remove(filename) == 0, filename); +} + + +static int os_rename (lua_State *L) { + const char *fromname = luaL_checkstring(L, 1); + const char *toname = luaL_checkstring(L, 2); + return os_pushresult(L, rename(fromname, toname) == 0, fromname); +} + + +static int os_tmpname (lua_State *L) { + char buff[LUA_TMPNAMBUFSIZE]; + int err; + lua_tmpnam(buff, err); + if (err) + return luaL_error(L, "unable to generate a unique filename"); + lua_pushstring(L, buff); + return 1; +} + + +static int os_getenv (lua_State *L) { + lua_pushstring(L, getenv(luaL_checkstring(L, 1))); /* if NULL push nil */ + return 1; +} + + +static int os_clock (lua_State *L) { + lua_pushnumber(L, ((lua_Number)clock())/(lua_Number)CLOCKS_PER_SEC); + return 1; +} + + +/* +** {====================================================== +** Time/Date operations +** { year=%Y, month=%m, day=%d, hour=%H, min=%M, sec=%S, +** wday=%w+1, yday=%j, isdst=? } +** ======================================================= +*/ + +static void setfield (lua_State *L, const char *key, int value) { + lua_pushinteger(L, value); + lua_setfield(L, -2, key); +} + +static void setboolfield (lua_State *L, const char *key, int value) { + if (value < 0) /* undefined? */ + return; /* does not set field */ + lua_pushboolean(L, value); + lua_setfield(L, -2, key); +} + +static int getboolfield (lua_State *L, const char *key) { + int res; + lua_getfield(L, -1, key); + res = lua_isnil(L, -1) ? -1 : lua_toboolean(L, -1); + lua_pop(L, 1); + return res; +} + + +static int getfield (lua_State *L, const char *key, int d) { + int res; + lua_getfield(L, -1, key); + if (lua_isnumber(L, -1)) + res = (int)lua_tointeger(L, -1); + else { + if (d < 0) + return luaL_error(L, "field " LUA_QS " missing in date table", key); + res = d; + } + lua_pop(L, 1); + return res; +} + + +static int os_date (lua_State *L) { + const char *s = luaL_optstring(L, 1, "%c"); + time_t t = luaL_opt(L, (time_t)luaL_checknumber, 2, time(NULL)); + struct tm *stm; + if (*s == '!') { /* UTC? */ + stm = gmtime(&t); + s++; /* skip `!' */ + } + else + stm = localtime(&t); + if (stm == NULL) /* invalid date? */ + lua_pushnil(L); + else if (strcmp(s, "*t") == 0) { + lua_createtable(L, 0, 9); /* 9 = number of fields */ + setfield(L, "sec", stm->tm_sec); + setfield(L, "min", stm->tm_min); + setfield(L, "hour", stm->tm_hour); + setfield(L, "day", stm->tm_mday); + setfield(L, "month", stm->tm_mon+1); + setfield(L, "year", stm->tm_year+1900); + setfield(L, "wday", stm->tm_wday+1); + setfield(L, "yday", stm->tm_yday+1); + setboolfield(L, "isdst", stm->tm_isdst); + } + else { + char cc[3]; + luaL_Buffer b; + cc[0] = '%'; cc[2] = '\0'; + luaL_buffinit(L, &b); + for (; *s; s++) { + if (*s != '%' || *(s + 1) == '\0') /* no conversion specifier? */ + luaL_addchar(&b, *s); + else { + size_t reslen; + char buff[200]; /* should be big enough for any conversion result */ + cc[1] = *(++s); + reslen = strftime(buff, sizeof(buff), cc, stm); + luaL_addlstring(&b, buff, reslen); + } + } + luaL_pushresult(&b); + } + return 1; +} + + +static int os_time (lua_State *L) { + time_t t; + if (lua_isnoneornil(L, 1)) /* called without args? */ + t = time(NULL); /* get current time */ + else { + struct tm ts; + luaL_checktype(L, 1, LUA_TTABLE); + lua_settop(L, 1); /* make sure table is at the top */ + ts.tm_sec = getfield(L, "sec", 0); + ts.tm_min = getfield(L, "min", 0); + ts.tm_hour = getfield(L, "hour", 12); + ts.tm_mday = getfield(L, "day", -1); + ts.tm_mon = getfield(L, "month", -1) - 1; + ts.tm_year = getfield(L, "year", -1) - 1900; + ts.tm_isdst = getboolfield(L, "isdst"); + t = mktime(&ts); + } + if (t == (time_t)(-1)) + lua_pushnil(L); + else + lua_pushnumber(L, (lua_Number)t); + return 1; +} + + +static int os_difftime (lua_State *L) { + lua_pushnumber(L, difftime((time_t)(luaL_checknumber(L, 1)), + (time_t)(luaL_optnumber(L, 2, 0)))); + return 1; +} + +/* }====================================================== */ + + +static int os_setlocale (lua_State *L) { + static const int cat[] = {LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, + LC_NUMERIC, LC_TIME}; + static const char *const catnames[] = {"all", "collate", "ctype", "monetary", + "numeric", "time", NULL}; + const char *l = luaL_optstring(L, 1, NULL); + int op = luaL_checkoption(L, 2, "all", catnames); + lua_pushstring(L, setlocale(cat[op], l)); + return 1; +} + + +static int os_exit (lua_State *L) { + exit(luaL_optint(L, 1, EXIT_SUCCESS)); +} + +static const luaL_Reg syslib[] = { + {"clock", os_clock}, + {"date", os_date}, + {"difftime", os_difftime}, + {"execute", os_execute}, + {"exit", os_exit}, + {"getenv", os_getenv}, + {"remove", os_remove}, + {"rename", os_rename}, + {"setlocale", os_setlocale}, + {"time", os_time}, + {"tmpname", os_tmpname}, + {NULL, NULL} +}; + +/* }====================================================== */ + + + +LUALIB_API int luaopen_os (lua_State *L) { + luaL_register(L, LUA_OSLIBNAME, syslib); + return 1; +} + diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lparser.c b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lparser.c new file mode 100644 index 00000000..1e2a9a88 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lparser.c @@ -0,0 +1,1339 @@ +/* +** $Id: lparser.c,v 2.42.1.3 2007/12/28 15:32:23 roberto Exp $ +** Lua Parser +** See Copyright Notice in lua.h +*/ + + +#include + +#define lparser_c +#define LUA_CORE + +#include "lua.h" + +#include "lcode.h" +#include "ldebug.h" +#include "ldo.h" +#include "lfunc.h" +#include "llex.h" +#include "lmem.h" +#include "lobject.h" +#include "lopcodes.h" +#include "lparser.h" +#include "lstate.h" +#include "lstring.h" +#include "ltable.h" + + + +#define hasmultret(k) ((k) == VCALL || (k) == VVARARG) + +#define getlocvar(fs, i) ((fs)->f->locvars[(fs)->actvar[i]]) + +#define luaY_checklimit(fs,v,l,m) if ((v)>(l)) errorlimit(fs,l,m) + + +/* +** nodes for block list (list of active blocks) +*/ +typedef struct BlockCnt { + struct BlockCnt *previous; /* chain */ + int breaklist; /* list of jumps out of this loop */ + lu_byte nactvar; /* # active locals outside the breakable structure */ + lu_byte upval; /* true if some variable in the block is an upvalue */ + lu_byte isbreakable; /* true if `block' is a loop */ +} BlockCnt; + + + +/* +** prototypes for recursive non-terminal functions +*/ +static void chunk (LexState *ls); +static void expr (LexState *ls, expdesc *v); + + +static void anchor_token (LexState *ls) { + if (ls->t.token == TK_NAME || ls->t.token == TK_STRING) { + TString *ts = ls->t.seminfo.ts; + luaX_newstring(ls, getstr(ts), ts->tsv.len); + } +} + + +static void error_expected (LexState *ls, int token) { + luaX_syntaxerror(ls, + luaO_pushfstring(ls->L, LUA_QS " expected", luaX_token2str(ls, token))); +} + + +static void errorlimit (FuncState *fs, int limit, const char *what) { + const char *msg = (fs->f->linedefined == 0) ? + luaO_pushfstring(fs->L, "main function has more than %d %s", limit, what) : + luaO_pushfstring(fs->L, "function at line %d has more than %d %s", + fs->f->linedefined, limit, what); + luaX_lexerror(fs->ls, msg, 0); +} + + +static int testnext (LexState *ls, int c) { + if (ls->t.token == c) { + luaX_next(ls); + return 1; + } + else return 0; +} + + +static void check (LexState *ls, int c) { + if (ls->t.token != c) + error_expected(ls, c); +} + +static void checknext (LexState *ls, int c) { + check(ls, c); + luaX_next(ls); +} + + +#define check_condition(ls,c,msg) { if (!(c)) luaX_syntaxerror(ls, msg); } + + + +static void check_match (LexState *ls, int what, int who, int where) { + if (!testnext(ls, what)) { + if (where == ls->linenumber) + error_expected(ls, what); + else { + luaX_syntaxerror(ls, luaO_pushfstring(ls->L, + LUA_QS " expected (to close " LUA_QS " at line %d)", + luaX_token2str(ls, what), luaX_token2str(ls, who), where)); + } + } +} + + +static TString *str_checkname (LexState *ls) { + TString *ts; + check(ls, TK_NAME); + ts = ls->t.seminfo.ts; + luaX_next(ls); + return ts; +} + + +static void init_exp (expdesc *e, expkind k, int i) { + e->f = e->t = NO_JUMP; + e->k = k; + e->u.s.info = i; +} + + +static void codestring (LexState *ls, expdesc *e, TString *s) { + init_exp(e, VK, luaK_stringK(ls->fs, s)); +} + + +static void checkname(LexState *ls, expdesc *e) { + codestring(ls, e, str_checkname(ls)); +} + + +static int registerlocalvar (LexState *ls, TString *varname) { + FuncState *fs = ls->fs; + Proto *f = fs->f; + int oldsize = f->sizelocvars; + luaM_growvector(ls->L, f->locvars, fs->nlocvars, f->sizelocvars, + LocVar, SHRT_MAX, "too many local variables"); + while (oldsize < f->sizelocvars) f->locvars[oldsize++].varname = NULL; + f->locvars[fs->nlocvars].varname = varname; + luaC_objbarrier(ls->L, f, varname); + return fs->nlocvars++; +} + + +#define new_localvarliteral(ls,v,n) \ + new_localvar(ls, luaX_newstring(ls, "" v, (sizeof(v)/sizeof(char))-1), n) + + +static void new_localvar (LexState *ls, TString *name, int n) { + FuncState *fs = ls->fs; + luaY_checklimit(fs, fs->nactvar+n+1, LUAI_MAXVARS, "local variables"); + fs->actvar[fs->nactvar+n] = cast(unsigned short, registerlocalvar(ls, name)); +} + + +static void adjustlocalvars (LexState *ls, int nvars) { + FuncState *fs = ls->fs; + fs->nactvar = cast_byte(fs->nactvar + nvars); + for (; nvars; nvars--) { + getlocvar(fs, fs->nactvar - nvars).startpc = fs->pc; + } +} + + +static void removevars (LexState *ls, int tolevel) { + FuncState *fs = ls->fs; + while (fs->nactvar > tolevel) + getlocvar(fs, --fs->nactvar).endpc = fs->pc; +} + + +static int indexupvalue (FuncState *fs, TString *name, expdesc *v) { + int i; + Proto *f = fs->f; + int oldsize = f->sizeupvalues; + for (i=0; inups; i++) { + if (fs->upvalues[i].k == v->k && fs->upvalues[i].info == v->u.s.info) { + lua_assert(f->upvalues[i] == name); + return i; + } + } + /* new one */ + luaY_checklimit(fs, f->nups + 1, LUAI_MAXUPVALUES, "upvalues"); + luaM_growvector(fs->L, f->upvalues, f->nups, f->sizeupvalues, + TString *, MAX_INT, ""); + while (oldsize < f->sizeupvalues) f->upvalues[oldsize++] = NULL; + f->upvalues[f->nups] = name; + luaC_objbarrier(fs->L, f, name); + lua_assert(v->k == VLOCAL || v->k == VUPVAL); + fs->upvalues[f->nups].k = cast_byte(v->k); + fs->upvalues[f->nups].info = cast_byte(v->u.s.info); + return f->nups++; +} + + +static int searchvar (FuncState *fs, TString *n) { + int i; + for (i=fs->nactvar-1; i >= 0; i--) { + if (n == getlocvar(fs, i).varname) + return i; + } + return -1; /* not found */ +} + + +static void markupval (FuncState *fs, int level) { + BlockCnt *bl = fs->bl; + while (bl && bl->nactvar > level) bl = bl->previous; + if (bl) bl->upval = 1; +} + + +static int singlevaraux (FuncState *fs, TString *n, expdesc *var, int base) { + if (fs == NULL) { /* no more levels? */ + init_exp(var, VGLOBAL, NO_REG); /* default is global variable */ + return VGLOBAL; + } + else { + int v = searchvar(fs, n); /* look up at current level */ + if (v >= 0) { + init_exp(var, VLOCAL, v); + if (!base) + markupval(fs, v); /* local will be used as an upval */ + return VLOCAL; + } + else { /* not found at current level; try upper one */ + if (singlevaraux(fs->prev, n, var, 0) == VGLOBAL) + return VGLOBAL; + var->u.s.info = indexupvalue(fs, n, var); /* else was LOCAL or UPVAL */ + var->k = VUPVAL; /* upvalue in this level */ + return VUPVAL; + } + } +} + + +static void singlevar (LexState *ls, expdesc *var) { + TString *varname = str_checkname(ls); + FuncState *fs = ls->fs; + if (singlevaraux(fs, varname, var, 1) == VGLOBAL) + var->u.s.info = luaK_stringK(fs, varname); /* info points to global name */ +} + + +static void adjust_assign (LexState *ls, int nvars, int nexps, expdesc *e) { + FuncState *fs = ls->fs; + int extra = nvars - nexps; + if (hasmultret(e->k)) { + extra++; /* includes call itself */ + if (extra < 0) extra = 0; + luaK_setreturns(fs, e, extra); /* last exp. provides the difference */ + if (extra > 1) luaK_reserveregs(fs, extra-1); + } + else { + if (e->k != VVOID) luaK_exp2nextreg(fs, e); /* close last expression */ + if (extra > 0) { + int reg = fs->freereg; + luaK_reserveregs(fs, extra); + luaK_nil(fs, reg, extra); + } + } +} + + +static void enterlevel (LexState *ls) { + if (++ls->L->nCcalls > LUAI_MAXCCALLS) + luaX_lexerror(ls, "chunk has too many syntax levels", 0); +} + + +#define leavelevel(ls) ((ls)->L->nCcalls--) + + +static void enterblock (FuncState *fs, BlockCnt *bl, lu_byte isbreakable) { + bl->breaklist = NO_JUMP; + bl->isbreakable = isbreakable; + bl->nactvar = fs->nactvar; + bl->upval = 0; + bl->previous = fs->bl; + fs->bl = bl; + lua_assert(fs->freereg == fs->nactvar); +} + + +static void leaveblock (FuncState *fs) { + BlockCnt *bl = fs->bl; + fs->bl = bl->previous; + removevars(fs->ls, bl->nactvar); + if (bl->upval) + luaK_codeABC(fs, OP_CLOSE, bl->nactvar, 0, 0); + /* a block either controls scope or breaks (never both) */ + lua_assert(!bl->isbreakable || !bl->upval); + lua_assert(bl->nactvar == fs->nactvar); + fs->freereg = fs->nactvar; /* free registers */ + luaK_patchtohere(fs, bl->breaklist); +} + + +static void pushclosure (LexState *ls, FuncState *func, expdesc *v) { + FuncState *fs = ls->fs; + Proto *f = fs->f; + int oldsize = f->sizep; + int i; + luaM_growvector(ls->L, f->p, fs->np, f->sizep, Proto *, + MAXARG_Bx, "constant table overflow"); + while (oldsize < f->sizep) f->p[oldsize++] = NULL; + f->p[fs->np++] = func->f; + luaC_objbarrier(ls->L, f, func->f); + init_exp(v, VRELOCABLE, luaK_codeABx(fs, OP_CLOSURE, 0, fs->np-1)); + for (i=0; if->nups; i++) { + OpCode o = (func->upvalues[i].k == VLOCAL) ? OP_MOVE : OP_GETUPVAL; + luaK_codeABC(fs, o, 0, func->upvalues[i].info, 0); + } +} + + +static void open_func (LexState *ls, FuncState *fs) { + lua_State *L = ls->L; + Proto *f = luaF_newproto(L); + fs->f = f; + fs->prev = ls->fs; /* linked list of funcstates */ + fs->ls = ls; + fs->L = L; + ls->fs = fs; + fs->pc = 0; + fs->lasttarget = -1; + fs->jpc = NO_JUMP; + fs->freereg = 0; + fs->nk = 0; + fs->np = 0; + fs->nlocvars = 0; + fs->nactvar = 0; + fs->bl = NULL; + f->source = ls->source; + f->maxstacksize = 2; /* registers 0/1 are always valid */ + fs->h = luaH_new(L, 0, 0); + /* anchor table of constants and prototype (to avoid being collected) */ + sethvalue2s(L, L->top, fs->h); + incr_top(L); + setptvalue2s(L, L->top, f); + incr_top(L); +} + + +static void close_func (LexState *ls) { + lua_State *L = ls->L; + FuncState *fs = ls->fs; + Proto *f = fs->f; + removevars(ls, 0); + luaK_ret(fs, 0, 0); /* final return */ + luaM_reallocvector(L, f->code, f->sizecode, fs->pc, Instruction); + f->sizecode = fs->pc; + luaM_reallocvector(L, f->lineinfo, f->sizelineinfo, fs->pc, int); + f->sizelineinfo = fs->pc; + luaM_reallocvector(L, f->k, f->sizek, fs->nk, TValue); + f->sizek = fs->nk; + luaM_reallocvector(L, f->p, f->sizep, fs->np, Proto *); + f->sizep = fs->np; + luaM_reallocvector(L, f->locvars, f->sizelocvars, fs->nlocvars, LocVar); + f->sizelocvars = fs->nlocvars; + luaM_reallocvector(L, f->upvalues, f->sizeupvalues, f->nups, TString *); + f->sizeupvalues = f->nups; + lua_assert(luaG_checkcode(f)); + lua_assert(fs->bl == NULL); + ls->fs = fs->prev; + L->top -= 2; /* remove table and prototype from the stack */ + /* last token read was anchored in defunct function; must reanchor it */ + if (fs) anchor_token(ls); +} + + +Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, const char *name) { + struct LexState lexstate; + struct FuncState funcstate; + lexstate.buff = buff; + luaX_setinput(L, &lexstate, z, luaS_new(L, name)); + open_func(&lexstate, &funcstate); + funcstate.f->is_vararg = VARARG_ISVARARG; /* main func. is always vararg */ + luaX_next(&lexstate); /* read first token */ + chunk(&lexstate); + check(&lexstate, TK_EOS); + close_func(&lexstate); + lua_assert(funcstate.prev == NULL); + lua_assert(funcstate.f->nups == 0); + lua_assert(lexstate.fs == NULL); + return funcstate.f; +} + + + +/*============================================================*/ +/* GRAMMAR RULES */ +/*============================================================*/ + + +static void field (LexState *ls, expdesc *v) { + /* field -> ['.' | ':'] NAME */ + FuncState *fs = ls->fs; + expdesc key; + luaK_exp2anyreg(fs, v); + luaX_next(ls); /* skip the dot or colon */ + checkname(ls, &key); + luaK_indexed(fs, v, &key); +} + + +static void yindex (LexState *ls, expdesc *v) { + /* index -> '[' expr ']' */ + luaX_next(ls); /* skip the '[' */ + expr(ls, v); + luaK_exp2val(ls->fs, v); + checknext(ls, ']'); +} + + +/* +** {====================================================================== +** Rules for Constructors +** ======================================================================= +*/ + + +struct ConsControl { + expdesc v; /* last list item read */ + expdesc *t; /* table descriptor */ + int nh; /* total number of `record' elements */ + int na; /* total number of array elements */ + int tostore; /* number of array elements pending to be stored */ +}; + + +static void recfield (LexState *ls, struct ConsControl *cc) { + /* recfield -> (NAME | `['exp1`]') = exp1 */ + FuncState *fs = ls->fs; + int reg = ls->fs->freereg; + expdesc key, val; + int rkkey; + if (ls->t.token == TK_NAME) { + luaY_checklimit(fs, cc->nh, MAX_INT, "items in a constructor"); + checkname(ls, &key); + } + else /* ls->t.token == '[' */ + yindex(ls, &key); + cc->nh++; + checknext(ls, '='); + rkkey = luaK_exp2RK(fs, &key); + expr(ls, &val); + luaK_codeABC(fs, OP_SETTABLE, cc->t->u.s.info, rkkey, luaK_exp2RK(fs, &val)); + fs->freereg = reg; /* free registers */ +} + + +static void closelistfield (FuncState *fs, struct ConsControl *cc) { + if (cc->v.k == VVOID) return; /* there is no list item */ + luaK_exp2nextreg(fs, &cc->v); + cc->v.k = VVOID; + if (cc->tostore == LFIELDS_PER_FLUSH) { + luaK_setlist(fs, cc->t->u.s.info, cc->na, cc->tostore); /* flush */ + cc->tostore = 0; /* no more items pending */ + } +} + + +static void lastlistfield (FuncState *fs, struct ConsControl *cc) { + if (cc->tostore == 0) return; + if (hasmultret(cc->v.k)) { + luaK_setmultret(fs, &cc->v); + luaK_setlist(fs, cc->t->u.s.info, cc->na, LUA_MULTRET); + cc->na--; /* do not count last expression (unknown number of elements) */ + } + else { + if (cc->v.k != VVOID) + luaK_exp2nextreg(fs, &cc->v); + luaK_setlist(fs, cc->t->u.s.info, cc->na, cc->tostore); + } +} + + +static void listfield (LexState *ls, struct ConsControl *cc) { + expr(ls, &cc->v); + luaY_checklimit(ls->fs, cc->na, MAX_INT, "items in a constructor"); + cc->na++; + cc->tostore++; +} + + +static void constructor (LexState *ls, expdesc *t) { + /* constructor -> ?? */ + FuncState *fs = ls->fs; + int line = ls->linenumber; + int pc = luaK_codeABC(fs, OP_NEWTABLE, 0, 0, 0); + struct ConsControl cc; + cc.na = cc.nh = cc.tostore = 0; + cc.t = t; + init_exp(t, VRELOCABLE, pc); + init_exp(&cc.v, VVOID, 0); /* no value (yet) */ + luaK_exp2nextreg(ls->fs, t); /* fix it at stack top (for gc) */ + checknext(ls, '{'); + do { + lua_assert(cc.v.k == VVOID || cc.tostore > 0); + if (ls->t.token == '}') break; + closelistfield(fs, &cc); + switch(ls->t.token) { + case TK_NAME: { /* may be listfields or recfields */ + luaX_lookahead(ls); + if (ls->lookahead.token != '=') /* expression? */ + listfield(ls, &cc); + else + recfield(ls, &cc); + break; + } + case '[': { /* constructor_item -> recfield */ + recfield(ls, &cc); + break; + } + default: { /* constructor_part -> listfield */ + listfield(ls, &cc); + break; + } + } + } while (testnext(ls, ',') || testnext(ls, ';')); + check_match(ls, '}', '{', line); + lastlistfield(fs, &cc); + SETARG_B(fs->f->code[pc], luaO_int2fb(cc.na)); /* set initial array size */ + SETARG_C(fs->f->code[pc], luaO_int2fb(cc.nh)); /* set initial table size */ +} + +/* }====================================================================== */ + + + +static void parlist (LexState *ls) { + /* parlist -> [ param { `,' param } ] */ + FuncState *fs = ls->fs; + Proto *f = fs->f; + int nparams = 0; + f->is_vararg = 0; + if (ls->t.token != ')') { /* is `parlist' not empty? */ + do { + switch (ls->t.token) { + case TK_NAME: { /* param -> NAME */ + new_localvar(ls, str_checkname(ls), nparams++); + break; + } + case TK_DOTS: { /* param -> `...' */ + luaX_next(ls); +#if defined(LUA_COMPAT_VARARG) + /* use `arg' as default name */ + new_localvarliteral(ls, "arg", nparams++); + f->is_vararg = VARARG_HASARG | VARARG_NEEDSARG; +#endif + f->is_vararg |= VARARG_ISVARARG; + break; + } + default: luaX_syntaxerror(ls, " or " LUA_QL("...") " expected"); + } + } while (!f->is_vararg && testnext(ls, ',')); + } + adjustlocalvars(ls, nparams); + f->numparams = cast_byte(fs->nactvar - (f->is_vararg & VARARG_HASARG)); + luaK_reserveregs(fs, fs->nactvar); /* reserve register for parameters */ +} + + +static void body (LexState *ls, expdesc *e, int needself, int line) { + /* body -> `(' parlist `)' chunk END */ + FuncState new_fs; + open_func(ls, &new_fs); + new_fs.f->linedefined = line; + checknext(ls, '('); + if (needself) { + new_localvarliteral(ls, "self", 0); + adjustlocalvars(ls, 1); + } + parlist(ls); + checknext(ls, ')'); + chunk(ls); + new_fs.f->lastlinedefined = ls->linenumber; + check_match(ls, TK_END, TK_FUNCTION, line); + close_func(ls); + pushclosure(ls, &new_fs, e); +} + + +static int explist1 (LexState *ls, expdesc *v) { + /* explist1 -> expr { `,' expr } */ + int n = 1; /* at least one expression */ + expr(ls, v); + while (testnext(ls, ',')) { + luaK_exp2nextreg(ls->fs, v); + expr(ls, v); + n++; + } + return n; +} + + +static void funcargs (LexState *ls, expdesc *f) { + FuncState *fs = ls->fs; + expdesc args; + int base, nparams; + int line = ls->linenumber; + switch (ls->t.token) { + case '(': { /* funcargs -> `(' [ explist1 ] `)' */ + if (line != ls->lastline) + luaX_syntaxerror(ls,"ambiguous syntax (function call x new statement)"); + luaX_next(ls); + if (ls->t.token == ')') /* arg list is empty? */ + args.k = VVOID; + else { + explist1(ls, &args); + luaK_setmultret(fs, &args); + } + check_match(ls, ')', '(', line); + break; + } + case '{': { /* funcargs -> constructor */ + constructor(ls, &args); + break; + } + case TK_STRING: { /* funcargs -> STRING */ + codestring(ls, &args, ls->t.seminfo.ts); + luaX_next(ls); /* must use `seminfo' before `next' */ + break; + } + default: { + luaX_syntaxerror(ls, "function arguments expected"); + return; + } + } + lua_assert(f->k == VNONRELOC); + base = f->u.s.info; /* base register for call */ + if (hasmultret(args.k)) + nparams = LUA_MULTRET; /* open call */ + else { + if (args.k != VVOID) + luaK_exp2nextreg(fs, &args); /* close last argument */ + nparams = fs->freereg - (base+1); + } + init_exp(f, VCALL, luaK_codeABC(fs, OP_CALL, base, nparams+1, 2)); + luaK_fixline(fs, line); + fs->freereg = base+1; /* call remove function and arguments and leaves + (unless changed) one result */ +} + + + + +/* +** {====================================================================== +** Expression parsing +** ======================================================================= +*/ + + +static void prefixexp (LexState *ls, expdesc *v) { + /* prefixexp -> NAME | '(' expr ')' */ + switch (ls->t.token) { + case '(': { + int line = ls->linenumber; + luaX_next(ls); + expr(ls, v); + check_match(ls, ')', '(', line); + luaK_dischargevars(ls->fs, v); + return; + } + case TK_NAME: { + singlevar(ls, v); + return; + } + default: { + luaX_syntaxerror(ls, "unexpected symbol"); + return; + } + } +} + + +static void primaryexp (LexState *ls, expdesc *v) { + /* primaryexp -> + prefixexp { `.' NAME | `[' exp `]' | `:' NAME funcargs | funcargs } */ + FuncState *fs = ls->fs; + prefixexp(ls, v); + for (;;) { + switch (ls->t.token) { + case '.': { /* field */ + field(ls, v); + break; + } + case '[': { /* `[' exp1 `]' */ + expdesc key; + luaK_exp2anyreg(fs, v); + yindex(ls, &key); + luaK_indexed(fs, v, &key); + break; + } + case ':': { /* `:' NAME funcargs */ + expdesc key; + luaX_next(ls); + checkname(ls, &key); + luaK_self(fs, v, &key); + funcargs(ls, v); + break; + } + case '(': case TK_STRING: case '{': { /* funcargs */ + luaK_exp2nextreg(fs, v); + funcargs(ls, v); + break; + } + default: return; + } + } +} + + +static void simpleexp (LexState *ls, expdesc *v) { + /* simpleexp -> NUMBER | STRING | NIL | true | false | ... | + constructor | FUNCTION body | primaryexp */ + switch (ls->t.token) { + case TK_NUMBER: { + init_exp(v, VKNUM, 0); + v->u.nval = ls->t.seminfo.r; + break; + } + case TK_STRING: { + codestring(ls, v, ls->t.seminfo.ts); + break; + } + case TK_NIL: { + init_exp(v, VNIL, 0); + break; + } + case TK_TRUE: { + init_exp(v, VTRUE, 0); + break; + } + case TK_FALSE: { + init_exp(v, VFALSE, 0); + break; + } + case TK_DOTS: { /* vararg */ + FuncState *fs = ls->fs; + check_condition(ls, fs->f->is_vararg, + "cannot use " LUA_QL("...") " outside a vararg function"); + fs->f->is_vararg &= ~VARARG_NEEDSARG; /* don't need 'arg' */ + init_exp(v, VVARARG, luaK_codeABC(fs, OP_VARARG, 0, 1, 0)); + break; + } + case '{': { /* constructor */ + constructor(ls, v); + return; + } + case TK_FUNCTION: { + luaX_next(ls); + body(ls, v, 0, ls->linenumber); + return; + } + default: { + primaryexp(ls, v); + return; + } + } + luaX_next(ls); +} + + +static UnOpr getunopr (int op) { + switch (op) { + case TK_NOT: return OPR_NOT; + case '-': return OPR_MINUS; + case '#': return OPR_LEN; + default: return OPR_NOUNOPR; + } +} + + +static BinOpr getbinopr (int op) { + switch (op) { + case '+': return OPR_ADD; + case '-': return OPR_SUB; + case '*': return OPR_MUL; + case '/': return OPR_DIV; + case '%': return OPR_MOD; + case '^': return OPR_POW; + case TK_CONCAT: return OPR_CONCAT; + case TK_NE: return OPR_NE; + case TK_EQ: return OPR_EQ; + case '<': return OPR_LT; + case TK_LE: return OPR_LE; + case '>': return OPR_GT; + case TK_GE: return OPR_GE; + case TK_AND: return OPR_AND; + case TK_OR: return OPR_OR; + default: return OPR_NOBINOPR; + } +} + + +static const struct { + lu_byte left; /* left priority for each binary operator */ + lu_byte right; /* right priority */ +} priority[] = { /* ORDER OPR */ + {6, 6}, {6, 6}, {7, 7}, {7, 7}, {7, 7}, /* `+' `-' `/' `%' */ + {10, 9}, {5, 4}, /* power and concat (right associative) */ + {3, 3}, {3, 3}, /* equality and inequality */ + {3, 3}, {3, 3}, {3, 3}, {3, 3}, /* order */ + {2, 2}, {1, 1} /* logical (and/or) */ +}; + +#define UNARY_PRIORITY 8 /* priority for unary operators */ + + +/* +** subexpr -> (simpleexp | unop subexpr) { binop subexpr } +** where `binop' is any binary operator with a priority higher than `limit' +*/ +static BinOpr subexpr (LexState *ls, expdesc *v, unsigned int limit) { + BinOpr op; + UnOpr uop; + enterlevel(ls); + uop = getunopr(ls->t.token); + if (uop != OPR_NOUNOPR) { + luaX_next(ls); + subexpr(ls, v, UNARY_PRIORITY); + luaK_prefix(ls->fs, uop, v); + } + else simpleexp(ls, v); + /* expand while operators have priorities higher than `limit' */ + op = getbinopr(ls->t.token); + while (op != OPR_NOBINOPR && priority[op].left > limit) { + expdesc v2; + BinOpr nextop; + luaX_next(ls); + luaK_infix(ls->fs, op, v); + /* read sub-expression with higher priority */ + nextop = subexpr(ls, &v2, priority[op].right); + luaK_posfix(ls->fs, op, v, &v2); + op = nextop; + } + leavelevel(ls); + return op; /* return first untreated operator */ +} + + +static void expr (LexState *ls, expdesc *v) { + subexpr(ls, v, 0); +} + +/* }==================================================================== */ + + + +/* +** {====================================================================== +** Rules for Statements +** ======================================================================= +*/ + + +static int block_follow (int token) { + switch (token) { + case TK_ELSE: case TK_ELSEIF: case TK_END: + case TK_UNTIL: case TK_EOS: + return 1; + default: return 0; + } +} + + +static void block (LexState *ls) { + /* block -> chunk */ + FuncState *fs = ls->fs; + BlockCnt bl; + enterblock(fs, &bl, 0); + chunk(ls); + lua_assert(bl.breaklist == NO_JUMP); + leaveblock(fs); +} + + +/* +** structure to chain all variables in the left-hand side of an +** assignment +*/ +struct LHS_assign { + struct LHS_assign *prev; + expdesc v; /* variable (global, local, upvalue, or indexed) */ +}; + + +/* +** check whether, in an assignment to a local variable, the local variable +** is needed in a previous assignment (to a table). If so, save original +** local value in a safe place and use this safe copy in the previous +** assignment. +*/ +static void check_conflict (LexState *ls, struct LHS_assign *lh, expdesc *v) { + FuncState *fs = ls->fs; + int extra = fs->freereg; /* eventual position to save local variable */ + int conflict = 0; + for (; lh; lh = lh->prev) { + if (lh->v.k == VINDEXED) { + if (lh->v.u.s.info == v->u.s.info) { /* conflict? */ + conflict = 1; + lh->v.u.s.info = extra; /* previous assignment will use safe copy */ + } + if (lh->v.u.s.aux == v->u.s.info) { /* conflict? */ + conflict = 1; + lh->v.u.s.aux = extra; /* previous assignment will use safe copy */ + } + } + } + if (conflict) { + luaK_codeABC(fs, OP_MOVE, fs->freereg, v->u.s.info, 0); /* make copy */ + luaK_reserveregs(fs, 1); + } +} + + +static void assignment (LexState *ls, struct LHS_assign *lh, int nvars) { + expdesc e; + check_condition(ls, VLOCAL <= lh->v.k && lh->v.k <= VINDEXED, + "syntax error"); + if (testnext(ls, ',')) { /* assignment -> `,' primaryexp assignment */ + struct LHS_assign nv; + nv.prev = lh; + primaryexp(ls, &nv.v); + if (nv.v.k == VLOCAL) + check_conflict(ls, lh, &nv.v); + luaY_checklimit(ls->fs, nvars, LUAI_MAXCCALLS - ls->L->nCcalls, + "variables in assignment"); + assignment(ls, &nv, nvars+1); + } + else { /* assignment -> `=' explist1 */ + int nexps; + checknext(ls, '='); + nexps = explist1(ls, &e); + if (nexps != nvars) { + adjust_assign(ls, nvars, nexps, &e); + if (nexps > nvars) + ls->fs->freereg -= nexps - nvars; /* remove extra values */ + } + else { + luaK_setoneret(ls->fs, &e); /* close last expression */ + luaK_storevar(ls->fs, &lh->v, &e); + return; /* avoid default */ + } + } + init_exp(&e, VNONRELOC, ls->fs->freereg-1); /* default assignment */ + luaK_storevar(ls->fs, &lh->v, &e); +} + + +static int cond (LexState *ls) { + /* cond -> exp */ + expdesc v; + expr(ls, &v); /* read condition */ + if (v.k == VNIL) v.k = VFALSE; /* `falses' are all equal here */ + luaK_goiftrue(ls->fs, &v); + return v.f; +} + + +static void breakstat (LexState *ls) { + FuncState *fs = ls->fs; + BlockCnt *bl = fs->bl; + int upval = 0; + while (bl && !bl->isbreakable) { + upval |= bl->upval; + bl = bl->previous; + } + if (!bl) + luaX_syntaxerror(ls, "no loop to break"); + if (upval) + luaK_codeABC(fs, OP_CLOSE, bl->nactvar, 0, 0); + luaK_concat(fs, &bl->breaklist, luaK_jump(fs)); +} + + +static void whilestat (LexState *ls, int line) { + /* whilestat -> WHILE cond DO block END */ + FuncState *fs = ls->fs; + int whileinit; + int condexit; + BlockCnt bl; + luaX_next(ls); /* skip WHILE */ + whileinit = luaK_getlabel(fs); + condexit = cond(ls); + enterblock(fs, &bl, 1); + checknext(ls, TK_DO); + block(ls); + luaK_patchlist(fs, luaK_jump(fs), whileinit); + check_match(ls, TK_END, TK_WHILE, line); + leaveblock(fs); + luaK_patchtohere(fs, condexit); /* false conditions finish the loop */ +} + + +static void repeatstat (LexState *ls, int line) { + /* repeatstat -> REPEAT block UNTIL cond */ + int condexit; + FuncState *fs = ls->fs; + int repeat_init = luaK_getlabel(fs); + BlockCnt bl1, bl2; + enterblock(fs, &bl1, 1); /* loop block */ + enterblock(fs, &bl2, 0); /* scope block */ + luaX_next(ls); /* skip REPEAT */ + chunk(ls); + check_match(ls, TK_UNTIL, TK_REPEAT, line); + condexit = cond(ls); /* read condition (inside scope block) */ + if (!bl2.upval) { /* no upvalues? */ + leaveblock(fs); /* finish scope */ + luaK_patchlist(ls->fs, condexit, repeat_init); /* close the loop */ + } + else { /* complete semantics when there are upvalues */ + breakstat(ls); /* if condition then break */ + luaK_patchtohere(ls->fs, condexit); /* else... */ + leaveblock(fs); /* finish scope... */ + luaK_patchlist(ls->fs, luaK_jump(fs), repeat_init); /* and repeat */ + } + leaveblock(fs); /* finish loop */ +} + + +static int exp1 (LexState *ls) { + expdesc e; + int k; + expr(ls, &e); + k = e.k; + luaK_exp2nextreg(ls->fs, &e); + return k; +} + + +static void forbody (LexState *ls, int base, int line, int nvars, int isnum) { + /* forbody -> DO block */ + BlockCnt bl; + FuncState *fs = ls->fs; + int prep, endfor; + adjustlocalvars(ls, 3); /* control variables */ + checknext(ls, TK_DO); + prep = isnum ? luaK_codeAsBx(fs, OP_FORPREP, base, NO_JUMP) : luaK_jump(fs); + enterblock(fs, &bl, 0); /* scope for declared variables */ + adjustlocalvars(ls, nvars); + luaK_reserveregs(fs, nvars); + block(ls); + leaveblock(fs); /* end of scope for declared variables */ + luaK_patchtohere(fs, prep); + endfor = (isnum) ? luaK_codeAsBx(fs, OP_FORLOOP, base, NO_JUMP) : + luaK_codeABC(fs, OP_TFORLOOP, base, 0, nvars); + luaK_fixline(fs, line); /* pretend that `OP_FOR' starts the loop */ + luaK_patchlist(fs, (isnum ? endfor : luaK_jump(fs)), prep + 1); +} + + +static void fornum (LexState *ls, TString *varname, int line) { + /* fornum -> NAME = exp1,exp1[,exp1] forbody */ + FuncState *fs = ls->fs; + int base = fs->freereg; + new_localvarliteral(ls, "(for index)", 0); + new_localvarliteral(ls, "(for limit)", 1); + new_localvarliteral(ls, "(for step)", 2); + new_localvar(ls, varname, 3); + checknext(ls, '='); + exp1(ls); /* initial value */ + checknext(ls, ','); + exp1(ls); /* limit */ + if (testnext(ls, ',')) + exp1(ls); /* optional step */ + else { /* default step = 1 */ + luaK_codeABx(fs, OP_LOADK, fs->freereg, luaK_numberK(fs, 1)); + luaK_reserveregs(fs, 1); + } + forbody(ls, base, line, 1, 1); +} + + +static void forlist (LexState *ls, TString *indexname) { + /* forlist -> NAME {,NAME} IN explist1 forbody */ + FuncState *fs = ls->fs; + expdesc e; + int nvars = 0; + int line; + int base = fs->freereg; + /* create control variables */ + new_localvarliteral(ls, "(for generator)", nvars++); + new_localvarliteral(ls, "(for state)", nvars++); + new_localvarliteral(ls, "(for control)", nvars++); + /* create declared variables */ + new_localvar(ls, indexname, nvars++); + while (testnext(ls, ',')) + new_localvar(ls, str_checkname(ls), nvars++); + checknext(ls, TK_IN); + line = ls->linenumber; + adjust_assign(ls, 3, explist1(ls, &e), &e); + luaK_checkstack(fs, 3); /* extra space to call generator */ + forbody(ls, base, line, nvars - 3, 0); +} + + +static void forstat (LexState *ls, int line) { + /* forstat -> FOR (fornum | forlist) END */ + FuncState *fs = ls->fs; + TString *varname; + BlockCnt bl; + enterblock(fs, &bl, 1); /* scope for loop and control variables */ + luaX_next(ls); /* skip `for' */ + varname = str_checkname(ls); /* first variable name */ + switch (ls->t.token) { + case '=': fornum(ls, varname, line); break; + case ',': case TK_IN: forlist(ls, varname); break; + default: luaX_syntaxerror(ls, LUA_QL("=") " or " LUA_QL("in") " expected"); + } + check_match(ls, TK_END, TK_FOR, line); + leaveblock(fs); /* loop scope (`break' jumps to this point) */ +} + + +static int test_then_block (LexState *ls) { + /* test_then_block -> [IF | ELSEIF] cond THEN block */ + int condexit; + luaX_next(ls); /* skip IF or ELSEIF */ + condexit = cond(ls); + checknext(ls, TK_THEN); + block(ls); /* `then' part */ + return condexit; +} + + +static void ifstat (LexState *ls, int line) { + /* ifstat -> IF cond THEN block {ELSEIF cond THEN block} [ELSE block] END */ + FuncState *fs = ls->fs; + int flist; + int escapelist = NO_JUMP; + flist = test_then_block(ls); /* IF cond THEN block */ + while (ls->t.token == TK_ELSEIF) { + luaK_concat(fs, &escapelist, luaK_jump(fs)); + luaK_patchtohere(fs, flist); + flist = test_then_block(ls); /* ELSEIF cond THEN block */ + } + if (ls->t.token == TK_ELSE) { + luaK_concat(fs, &escapelist, luaK_jump(fs)); + luaK_patchtohere(fs, flist); + luaX_next(ls); /* skip ELSE (after patch, for correct line info) */ + block(ls); /* `else' part */ + } + else + luaK_concat(fs, &escapelist, flist); + luaK_patchtohere(fs, escapelist); + check_match(ls, TK_END, TK_IF, line); +} + + +static void localfunc (LexState *ls) { + expdesc v, b; + FuncState *fs = ls->fs; + new_localvar(ls, str_checkname(ls), 0); + init_exp(&v, VLOCAL, fs->freereg); + luaK_reserveregs(fs, 1); + adjustlocalvars(ls, 1); + body(ls, &b, 0, ls->linenumber); + luaK_storevar(fs, &v, &b); + /* debug information will only see the variable after this point! */ + getlocvar(fs, fs->nactvar - 1).startpc = fs->pc; +} + + +static void localstat (LexState *ls) { + /* stat -> LOCAL NAME {`,' NAME} [`=' explist1] */ + int nvars = 0; + int nexps; + expdesc e; + do { + new_localvar(ls, str_checkname(ls), nvars++); + } while (testnext(ls, ',')); + if (testnext(ls, '=')) + nexps = explist1(ls, &e); + else { + e.k = VVOID; + nexps = 0; + } + adjust_assign(ls, nvars, nexps, &e); + adjustlocalvars(ls, nvars); +} + + +static int funcname (LexState *ls, expdesc *v) { + /* funcname -> NAME {field} [`:' NAME] */ + int needself = 0; + singlevar(ls, v); + while (ls->t.token == '.') + field(ls, v); + if (ls->t.token == ':') { + needself = 1; + field(ls, v); + } + return needself; +} + + +static void funcstat (LexState *ls, int line) { + /* funcstat -> FUNCTION funcname body */ + int needself; + expdesc v, b; + luaX_next(ls); /* skip FUNCTION */ + needself = funcname(ls, &v); + body(ls, &b, needself, line); + luaK_storevar(ls->fs, &v, &b); + luaK_fixline(ls->fs, line); /* definition `happens' in the first line */ +} + + +static void exprstat (LexState *ls) { + /* stat -> func | assignment */ + FuncState *fs = ls->fs; + struct LHS_assign v; + primaryexp(ls, &v.v); + if (v.v.k == VCALL) /* stat -> func */ + SETARG_C(getcode(fs, &v.v), 1); /* call statement uses no results */ + else { /* stat -> assignment */ + v.prev = NULL; + assignment(ls, &v, 1); + } +} + + +static void retstat (LexState *ls) { + /* stat -> RETURN explist */ + FuncState *fs = ls->fs; + expdesc e; + int first, nret; /* registers with returned values */ + luaX_next(ls); /* skip RETURN */ + if (block_follow(ls->t.token) || ls->t.token == ';') + first = nret = 0; /* return no values */ + else { + nret = explist1(ls, &e); /* optional return values */ + if (hasmultret(e.k)) { + luaK_setmultret(fs, &e); + if (e.k == VCALL && nret == 1) { /* tail call? */ + SET_OPCODE(getcode(fs,&e), OP_TAILCALL); + lua_assert(GETARG_A(getcode(fs,&e)) == fs->nactvar); + } + first = fs->nactvar; + nret = LUA_MULTRET; /* return all values */ + } + else { + if (nret == 1) /* only one single value? */ + first = luaK_exp2anyreg(fs, &e); + else { + luaK_exp2nextreg(fs, &e); /* values must go to the `stack' */ + first = fs->nactvar; /* return all `active' values */ + lua_assert(nret == fs->freereg - first); + } + } + } + luaK_ret(fs, first, nret); +} + + +static int statement (LexState *ls) { + int line = ls->linenumber; /* may be needed for error messages */ + switch (ls->t.token) { + case TK_IF: { /* stat -> ifstat */ + ifstat(ls, line); + return 0; + } + case TK_WHILE: { /* stat -> whilestat */ + whilestat(ls, line); + return 0; + } + case TK_DO: { /* stat -> DO block END */ + luaX_next(ls); /* skip DO */ + block(ls); + check_match(ls, TK_END, TK_DO, line); + return 0; + } + case TK_FOR: { /* stat -> forstat */ + forstat(ls, line); + return 0; + } + case TK_REPEAT: { /* stat -> repeatstat */ + repeatstat(ls, line); + return 0; + } + case TK_FUNCTION: { + funcstat(ls, line); /* stat -> funcstat */ + return 0; + } + case TK_LOCAL: { /* stat -> localstat */ + luaX_next(ls); /* skip LOCAL */ + if (testnext(ls, TK_FUNCTION)) /* local function? */ + localfunc(ls); + else + localstat(ls); + return 0; + } + case TK_RETURN: { /* stat -> retstat */ + retstat(ls); + return 1; /* must be last statement */ + } + case TK_BREAK: { /* stat -> breakstat */ + luaX_next(ls); /* skip BREAK */ + breakstat(ls); + return 1; /* must be last statement */ + } + default: { + exprstat(ls); + return 0; /* to avoid warnings */ + } + } +} + + +static void chunk (LexState *ls) { + /* chunk -> { stat [`;'] } */ + int islast = 0; + enterlevel(ls); + while (!islast && !block_follow(ls->t.token)) { + islast = statement(ls); + testnext(ls, ';'); + lua_assert(ls->fs->f->maxstacksize >= ls->fs->freereg && + ls->fs->freereg >= ls->fs->nactvar); + ls->fs->freereg = ls->fs->nactvar; /* free registers */ + } + leavelevel(ls); +} + +/* }====================================================================== */ diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lparser.h b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lparser.h new file mode 100644 index 00000000..18836afd --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lparser.h @@ -0,0 +1,82 @@ +/* +** $Id: lparser.h,v 1.57.1.1 2007/12/27 13:02:25 roberto Exp $ +** Lua Parser +** See Copyright Notice in lua.h +*/ + +#ifndef lparser_h +#define lparser_h + +#include "llimits.h" +#include "lobject.h" +#include "lzio.h" + + +/* +** Expression descriptor +*/ + +typedef enum { + VVOID, /* no value */ + VNIL, + VTRUE, + VFALSE, + VK, /* info = index of constant in `k' */ + VKNUM, /* nval = numerical value */ + VLOCAL, /* info = local register */ + VUPVAL, /* info = index of upvalue in `upvalues' */ + VGLOBAL, /* info = index of table; aux = index of global name in `k' */ + VINDEXED, /* info = table register; aux = index register (or `k') */ + VJMP, /* info = instruction pc */ + VRELOCABLE, /* info = instruction pc */ + VNONRELOC, /* info = result register */ + VCALL, /* info = instruction pc */ + VVARARG /* info = instruction pc */ +} expkind; + +typedef struct expdesc { + expkind k; + union { + struct { int info, aux; } s; + lua_Number nval; + } u; + int t; /* patch list of `exit when true' */ + int f; /* patch list of `exit when false' */ +} expdesc; + + +typedef struct upvaldesc { + lu_byte k; + lu_byte info; +} upvaldesc; + + +struct BlockCnt; /* defined in lparser.c */ + + +/* state needed to generate code for a given function */ +typedef struct FuncState { + Proto *f; /* current function header */ + Table *h; /* table to find (and reuse) elements in `k' */ + struct FuncState *prev; /* enclosing function */ + struct LexState *ls; /* lexical state */ + struct lua_State *L; /* copy of the Lua state */ + struct BlockCnt *bl; /* chain of current blocks */ + int pc; /* next position to code (equivalent to `ncode') */ + int lasttarget; /* `pc' of last `jump target' */ + int jpc; /* list of pending jumps to `pc' */ + int freereg; /* first free register */ + int nk; /* number of elements in `k' */ + int np; /* number of elements in `p' */ + short nlocvars; /* number of elements in `locvars' */ + lu_byte nactvar; /* number of active local variables */ + upvaldesc upvalues[LUAI_MAXUPVALUES]; /* upvalues */ + unsigned short actvar[LUAI_MAXVARS]; /* declared-variable stack */ +} FuncState; + + +LUAI_FUNC Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, + const char *name); + + +#endif diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lstate.c b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lstate.c new file mode 100644 index 00000000..4313b83a --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lstate.c @@ -0,0 +1,214 @@ +/* +** $Id: lstate.c,v 2.36.1.2 2008/01/03 15:20:39 roberto Exp $ +** Global State +** See Copyright Notice in lua.h +*/ + + +#include + +#define lstate_c +#define LUA_CORE + +#include "lua.h" + +#include "ldebug.h" +#include "ldo.h" +#include "lfunc.h" +#include "lgc.h" +#include "llex.h" +#include "lmem.h" +#include "lstate.h" +#include "lstring.h" +#include "ltable.h" +#include "ltm.h" + + +#define state_size(x) (sizeof(x) + LUAI_EXTRASPACE) +#define fromstate(l) (cast(lu_byte *, (l)) - LUAI_EXTRASPACE) +#define tostate(l) (cast(lua_State *, cast(lu_byte *, l) + LUAI_EXTRASPACE)) + + +/* +** Main thread combines a thread state and the global state +*/ +typedef struct LG { + lua_State l; + global_State g; +} LG; + + + +static void stack_init (lua_State *L1, lua_State *L) { + /* initialize CallInfo array */ + L1->base_ci = luaM_newvector(L, BASIC_CI_SIZE, CallInfo); + L1->ci = L1->base_ci; + L1->size_ci = BASIC_CI_SIZE; + L1->end_ci = L1->base_ci + L1->size_ci - 1; + /* initialize stack array */ + L1->stack = luaM_newvector(L, BASIC_STACK_SIZE + EXTRA_STACK, TValue); + L1->stacksize = BASIC_STACK_SIZE + EXTRA_STACK; + L1->top = L1->stack; + L1->stack_last = L1->stack+(L1->stacksize - EXTRA_STACK)-1; + /* initialize first ci */ + L1->ci->func = L1->top; + setnilvalue(L1->top++); /* `function' entry for this `ci' */ + L1->base = L1->ci->base = L1->top; + L1->ci->top = L1->top + LUA_MINSTACK; +} + + +static void freestack (lua_State *L, lua_State *L1) { + luaM_freearray(L, L1->base_ci, L1->size_ci, CallInfo); + luaM_freearray(L, L1->stack, L1->stacksize, TValue); +} + + +/* +** open parts that may cause memory-allocation errors +*/ +static void f_luaopen (lua_State *L, void *ud) { + global_State *g = G(L); + UNUSED(ud); + stack_init(L, L); /* init stack */ + sethvalue(L, gt(L), luaH_new(L, 0, 2)); /* table of globals */ + sethvalue(L, registry(L), luaH_new(L, 0, 2)); /* registry */ + luaS_resize(L, MINSTRTABSIZE); /* initial size of string table */ + luaT_init(L); + luaX_init(L); + luaS_fix(luaS_newliteral(L, MEMERRMSG)); + g->GCthreshold = 4*g->totalbytes; +} + + +static void preinit_state (lua_State *L, global_State *g) { + G(L) = g; + L->stack = NULL; + L->stacksize = 0; + L->errorJmp = NULL; + L->hook = NULL; + L->hookmask = 0; + L->basehookcount = 0; + L->allowhook = 1; + resethookcount(L); + L->openupval = NULL; + L->size_ci = 0; + L->nCcalls = L->baseCcalls = 0; + L->status = 0; + L->base_ci = L->ci = NULL; + L->savedpc = NULL; + L->errfunc = 0; + setnilvalue(gt(L)); +} + + +static void close_state (lua_State *L) { + global_State *g = G(L); + luaF_close(L, L->stack); /* close all upvalues for this thread */ + luaC_freeall(L); /* collect all objects */ + lua_assert(g->rootgc == obj2gco(L)); + lua_assert(g->strt.nuse == 0); + luaM_freearray(L, G(L)->strt.hash, G(L)->strt.size, TString *); + luaZ_freebuffer(L, &g->buff); + freestack(L, L); + lua_assert(g->totalbytes == sizeof(LG)); + (*g->frealloc)(g->ud, fromstate(L), state_size(LG), 0); +} + + +lua_State *luaE_newthread (lua_State *L) { + lua_State *L1 = tostate(luaM_malloc(L, state_size(lua_State))); + luaC_link(L, obj2gco(L1), LUA_TTHREAD); + preinit_state(L1, G(L)); + stack_init(L1, L); /* init stack */ + setobj2n(L, gt(L1), gt(L)); /* share table of globals */ + L1->hookmask = L->hookmask; + L1->basehookcount = L->basehookcount; + L1->hook = L->hook; + resethookcount(L1); + lua_assert(iswhite(obj2gco(L1))); + return L1; +} + + +void luaE_freethread (lua_State *L, lua_State *L1) { + luaF_close(L1, L1->stack); /* close all upvalues for this thread */ + lua_assert(L1->openupval == NULL); + luai_userstatefree(L1); + freestack(L, L1); + luaM_freemem(L, fromstate(L1), state_size(lua_State)); +} + + +LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) { + int i; + lua_State *L; + global_State *g; + void *l = (*f)(ud, NULL, 0, state_size(LG)); + if (l == NULL) return NULL; + L = tostate(l); + g = &((LG *)L)->g; + L->next = NULL; + L->tt = LUA_TTHREAD; + g->currentwhite = bit2mask(WHITE0BIT, FIXEDBIT); + L->marked = luaC_white(g); + set2bits(L->marked, FIXEDBIT, SFIXEDBIT); + preinit_state(L, g); + g->frealloc = f; + g->ud = ud; + g->mainthread = L; + g->uvhead.u.l.prev = &g->uvhead; + g->uvhead.u.l.next = &g->uvhead; + g->GCthreshold = 0; /* mark it as unfinished state */ + g->strt.size = 0; + g->strt.nuse = 0; + g->strt.hash = NULL; + setnilvalue(registry(L)); + luaZ_initbuffer(L, &g->buff); + g->panic = NULL; + g->gcstate = GCSpause; + g->rootgc = obj2gco(L); + g->sweepstrgc = 0; + g->sweepgc = &g->rootgc; + g->gray = NULL; + g->grayagain = NULL; + g->weak = NULL; + g->tmudata = NULL; + g->totalbytes = sizeof(LG); + g->gcpause = LUAI_GCPAUSE; + g->gcstepmul = LUAI_GCMUL; + g->gcdept = 0; + for (i=0; imt[i] = NULL; + if (luaD_rawrunprotected(L, f_luaopen, NULL) != 0) { + /* memory allocation error: free partial state */ + close_state(L); + L = NULL; + } + else + luai_userstateopen(L); + return L; +} + + +static void callallgcTM (lua_State *L, void *ud) { + UNUSED(ud); + luaC_callGCTM(L); /* call GC metamethods for all udata */ +} + + +LUA_API void lua_close (lua_State *L) { + L = G(L)->mainthread; /* only the main thread can be closed */ + lua_lock(L); + luaF_close(L, L->stack); /* close all upvalues for this thread */ + luaC_separateudata(L, 1); /* separate udata that have GC metamethods */ + L->errfunc = 0; /* no error function during GC metamethods */ + do { /* repeat until no more errors */ + L->ci = L->base_ci; + L->base = L->top = L->ci->base; + L->nCcalls = L->baseCcalls = 0; + } while (luaD_rawrunprotected(L, callallgcTM, NULL) != 0); + lua_assert(G(L)->tmudata == NULL); + luai_userstateclose(L); + close_state(L); +} + diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lstate.h b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lstate.h new file mode 100644 index 00000000..3bc575b6 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lstate.h @@ -0,0 +1,169 @@ +/* +** $Id: lstate.h,v 2.24.1.2 2008/01/03 15:20:39 roberto Exp $ +** Global State +** See Copyright Notice in lua.h +*/ + +#ifndef lstate_h +#define lstate_h + +#include "lua.h" + +#include "lobject.h" +#include "ltm.h" +#include "lzio.h" + + + +struct lua_longjmp; /* defined in ldo.c */ + + +/* table of globals */ +#define gt(L) (&L->l_gt) + +/* registry */ +#define registry(L) (&G(L)->l_registry) + + +/* extra stack space to handle TM calls and some other extras */ +#define EXTRA_STACK 5 + + +#define BASIC_CI_SIZE 8 + +#define BASIC_STACK_SIZE (2*LUA_MINSTACK) + + + +typedef struct stringtable { + GCObject **hash; + lu_int32 nuse; /* number of elements */ + int size; +} stringtable; + + +/* +** informations about a call +*/ +typedef struct CallInfo { + StkId base; /* base for this function */ + StkId func; /* function index in the stack */ + StkId top; /* top for this function */ + const Instruction *savedpc; + int nresults; /* expected number of results from this function */ + int tailcalls; /* number of tail calls lost under this entry */ +} CallInfo; + + + +#define curr_func(L) (clvalue(L->ci->func)) +#define ci_func(ci) (clvalue((ci)->func)) +#define f_isLua(ci) (!ci_func(ci)->c.isC) +#define isLua(ci) (ttisfunction((ci)->func) && f_isLua(ci)) + + +/* +** `global state', shared by all threads of this state +*/ +typedef struct global_State { + stringtable strt; /* hash table for strings */ + lua_Alloc frealloc; /* function to reallocate memory */ + void *ud; /* auxiliary data to `frealloc' */ + lu_byte currentwhite; + lu_byte gcstate; /* state of garbage collector */ + int sweepstrgc; /* position of sweep in `strt' */ + GCObject *rootgc; /* list of all collectable objects */ + GCObject **sweepgc; /* position of sweep in `rootgc' */ + GCObject *gray; /* list of gray objects */ + GCObject *grayagain; /* list of objects to be traversed atomically */ + GCObject *weak; /* list of weak tables (to be cleared) */ + GCObject *tmudata; /* last element of list of userdata to be GC */ + Mbuffer buff; /* temporary buffer for string concatentation */ + lu_mem GCthreshold; + lu_mem totalbytes; /* number of bytes currently allocated */ + lu_mem estimate; /* an estimate of number of bytes actually in use */ + lu_mem gcdept; /* how much GC is `behind schedule' */ + int gcpause; /* size of pause between successive GCs */ + int gcstepmul; /* GC `granularity' */ + lua_CFunction panic; /* to be called in unprotected errors */ + TValue l_registry; + struct lua_State *mainthread; + UpVal uvhead; /* head of double-linked list of all open upvalues */ + struct Table *mt[NUM_TAGS]; /* metatables for basic types */ + TString *tmname[TM_N]; /* array with tag-method names */ +} global_State; + + +/* +** `per thread' state +*/ +struct lua_State { + CommonHeader; + lu_byte status; + StkId top; /* first free slot in the stack */ + StkId base; /* base of current function */ + global_State *l_G; + CallInfo *ci; /* call info for current function */ + const Instruction *savedpc; /* `savedpc' of current function */ + StkId stack_last; /* last free slot in the stack */ + StkId stack; /* stack base */ + CallInfo *end_ci; /* points after end of ci array*/ + CallInfo *base_ci; /* array of CallInfo's */ + int stacksize; + int size_ci; /* size of array `base_ci' */ + unsigned short nCcalls; /* number of nested C calls */ + unsigned short baseCcalls; /* nested C calls when resuming coroutine */ + lu_byte hookmask; + lu_byte allowhook; + int basehookcount; + int hookcount; + lua_Hook hook; + TValue l_gt; /* table of globals */ + TValue env; /* temporary place for environments */ + GCObject *openupval; /* list of open upvalues in this stack */ + GCObject *gclist; + struct lua_longjmp *errorJmp; /* current error recover point */ + ptrdiff_t errfunc; /* current error handling function (stack index) */ +}; + + +#define G(L) (L->l_G) + + +/* +** Union of all collectable objects +*/ +union GCObject { + GCheader gch; + union TString ts; + union Udata u; + union Closure cl; + struct Table h; + struct Proto p; + struct UpVal uv; + struct lua_State th; /* thread */ +}; + + +/* macros to convert a GCObject into a specific value */ +#define rawgco2ts(o) check_exp((o)->gch.tt == LUA_TSTRING, &((o)->ts)) +#define gco2ts(o) (&rawgco2ts(o)->tsv) +#define rawgco2u(o) check_exp((o)->gch.tt == LUA_TUSERDATA, &((o)->u)) +#define gco2u(o) (&rawgco2u(o)->uv) +#define gco2cl(o) check_exp((o)->gch.tt == LUA_TFUNCTION, &((o)->cl)) +#define gco2h(o) check_exp((o)->gch.tt == LUA_TTABLE, &((o)->h)) +#define gco2p(o) check_exp((o)->gch.tt == LUA_TPROTO, &((o)->p)) +#define gco2uv(o) check_exp((o)->gch.tt == LUA_TUPVAL, &((o)->uv)) +#define ngcotouv(o) \ + check_exp((o) == NULL || (o)->gch.tt == LUA_TUPVAL, &((o)->uv)) +#define gco2th(o) check_exp((o)->gch.tt == LUA_TTHREAD, &((o)->th)) + +/* macro to convert any Lua object into a GCObject */ +#define obj2gco(v) (cast(GCObject *, (v))) + + +LUAI_FUNC lua_State *luaE_newthread (lua_State *L); +LUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1); + +#endif + diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lstring.c b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lstring.c new file mode 100644 index 00000000..49113151 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lstring.c @@ -0,0 +1,111 @@ +/* +** $Id: lstring.c,v 2.8.1.1 2007/12/27 13:02:25 roberto Exp $ +** String table (keeps all strings handled by Lua) +** See Copyright Notice in lua.h +*/ + + +#include + +#define lstring_c +#define LUA_CORE + +#include "lua.h" + +#include "lmem.h" +#include "lobject.h" +#include "lstate.h" +#include "lstring.h" + + + +void luaS_resize (lua_State *L, int newsize) { + GCObject **newhash; + stringtable *tb; + int i; + if (G(L)->gcstate == GCSsweepstring) + return; /* cannot resize during GC traverse */ + newhash = luaM_newvector(L, newsize, GCObject *); + tb = &G(L)->strt; + for (i=0; isize; i++) { + GCObject *p = tb->hash[i]; + while (p) { /* for each node in the list */ + GCObject *next = p->gch.next; /* save next */ + unsigned int h = gco2ts(p)->hash; + int h1 = lmod(h, newsize); /* new position */ + lua_assert(cast_int(h%newsize) == lmod(h, newsize)); + p->gch.next = newhash[h1]; /* chain it */ + newhash[h1] = p; + p = next; + } + } + luaM_freearray(L, tb->hash, tb->size, TString *); + tb->size = newsize; + tb->hash = newhash; +} + + +static TString *newlstr (lua_State *L, const char *str, size_t l, + unsigned int h) { + TString *ts; + stringtable *tb; + if (l+1 > (MAX_SIZET - sizeof(TString))/sizeof(char)) + luaM_toobig(L); + ts = cast(TString *, luaM_malloc(L, (l+1)*sizeof(char)+sizeof(TString))); + ts->tsv.len = l; + ts->tsv.hash = h; + ts->tsv.marked = luaC_white(G(L)); + ts->tsv.tt = LUA_TSTRING; + ts->tsv.reserved = 0; + memcpy(ts+1, str, l*sizeof(char)); + ((char *)(ts+1))[l] = '\0'; /* ending 0 */ + tb = &G(L)->strt; + h = lmod(h, tb->size); + ts->tsv.next = tb->hash[h]; /* chain new entry */ + tb->hash[h] = obj2gco(ts); + tb->nuse++; + if (tb->nuse > cast(lu_int32, tb->size) && tb->size <= MAX_INT/2) + luaS_resize(L, tb->size*2); /* too crowded */ + return ts; +} + + +TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { + GCObject *o; + unsigned int h = cast(unsigned int, l); /* seed */ + size_t step = (l>>5)+1; /* if string is too long, don't hash all its chars */ + size_t l1; + for (l1=l; l1>=step; l1-=step) /* compute hash */ + h = h ^ ((h<<5)+(h>>2)+cast(unsigned char, str[l1-1])); + for (o = G(L)->strt.hash[lmod(h, G(L)->strt.size)]; + o != NULL; + o = o->gch.next) { + TString *ts = rawgco2ts(o); + if (ts->tsv.len == l && (memcmp(str, getstr(ts), l) == 0)) { + /* string may be dead */ + if (isdead(G(L), o)) changewhite(o); + return ts; + } + } + return newlstr(L, str, l, h); /* not found */ +} + + +Udata *luaS_newudata (lua_State *L, size_t s, Table *e) { + Udata *u; + if (s > MAX_SIZET - sizeof(Udata)) + luaM_toobig(L); + u = cast(Udata *, luaM_malloc(L, s + sizeof(Udata))); + u->uv.marked = luaC_white(G(L)); /* is not finalized */ + u->uv.tt = LUA_TUSERDATA; + u->uv.len = s; + u->uv.metatable = NULL; + u->uv.env = e; + /* chain it on udata list (after main thread) */ + u->uv.next = G(L)->mainthread->next; + G(L)->mainthread->next = obj2gco(u); + return u; +} + diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lstring.h b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lstring.h new file mode 100644 index 00000000..73a2ff8b --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lstring.h @@ -0,0 +1,31 @@ +/* +** $Id: lstring.h,v 1.43.1.1 2007/12/27 13:02:25 roberto Exp $ +** String table (keep all strings handled by Lua) +** See Copyright Notice in lua.h +*/ + +#ifndef lstring_h +#define lstring_h + + +#include "lgc.h" +#include "lobject.h" +#include "lstate.h" + + +#define sizestring(s) (sizeof(union TString)+((s)->len+1)*sizeof(char)) + +#define sizeudata(u) (sizeof(union Udata)+(u)->len) + +#define luaS_new(L, s) (luaS_newlstr(L, s, strlen(s))) +#define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \ + (sizeof(s)/sizeof(char))-1)) + +#define luaS_fix(s) l_setbit((s)->tsv.marked, FIXEDBIT) + +LUAI_FUNC void luaS_resize (lua_State *L, int newsize); +LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s, Table *e); +LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l); + + +#endif diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lstrlib.c b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lstrlib.c new file mode 100644 index 00000000..1b4763d4 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lstrlib.c @@ -0,0 +1,869 @@ +/* +** $Id: lstrlib.c,v 1.132.1.4 2008/07/11 17:27:21 roberto Exp $ +** Standard library for string operations and pattern-matching +** See Copyright Notice in lua.h +*/ + + +#include +#include +#include +#include +#include + +#define lstrlib_c +#define LUA_LIB + +#include "lua.h" + +#include "lauxlib.h" +#include "lualib.h" + + +/* macro to `unsign' a character */ +#define uchar(c) ((unsigned char)(c)) + + + +static int str_len (lua_State *L) { + size_t l; + luaL_checklstring(L, 1, &l); + lua_pushinteger(L, l); + return 1; +} + + +static ptrdiff_t posrelat (ptrdiff_t pos, size_t len) { + /* relative string position: negative means back from end */ + if (pos < 0) pos += (ptrdiff_t)len + 1; + return (pos >= 0) ? pos : 0; +} + + +static int str_sub (lua_State *L) { + size_t l; + const char *s = luaL_checklstring(L, 1, &l); + ptrdiff_t start = posrelat(luaL_checkinteger(L, 2), l); + ptrdiff_t end = posrelat(luaL_optinteger(L, 3, -1), l); + if (start < 1) start = 1; + if (end > (ptrdiff_t)l) end = (ptrdiff_t)l; + if (start <= end) + lua_pushlstring(L, s+start-1, end-start+1); + else lua_pushliteral(L, ""); + return 1; +} + + +static int str_reverse (lua_State *L) { + size_t l; + luaL_Buffer b; + const char *s = luaL_checklstring(L, 1, &l); + luaL_buffinit(L, &b); + while (l--) luaL_addchar(&b, s[l]); + luaL_pushresult(&b); + return 1; +} + + +static int str_lower (lua_State *L) { + size_t l; + size_t i; + luaL_Buffer b; + const char *s = luaL_checklstring(L, 1, &l); + luaL_buffinit(L, &b); + for (i=0; i 0) + luaL_addlstring(&b, s, l); + luaL_pushresult(&b); + return 1; +} + + +static int str_byte (lua_State *L) { + size_t l; + const char *s = luaL_checklstring(L, 1, &l); + ptrdiff_t posi = posrelat(luaL_optinteger(L, 2, 1), l); + ptrdiff_t pose = posrelat(luaL_optinteger(L, 3, posi), l); + int n, i; + if (posi <= 0) posi = 1; + if ((size_t)pose > l) pose = l; + if (posi > pose) return 0; /* empty interval; return no values */ + n = (int)(pose - posi + 1); + if (posi + n <= pose) /* overflow? */ + luaL_error(L, "string slice too long"); + luaL_checkstack(L, n, "string slice too long"); + for (i=0; i= ms->level || ms->capture[l].len == CAP_UNFINISHED) + return luaL_error(ms->L, "invalid capture index"); + return l; +} + + +static int capture_to_close (MatchState *ms) { + int level = ms->level; + for (level--; level>=0; level--) + if (ms->capture[level].len == CAP_UNFINISHED) return level; + return luaL_error(ms->L, "invalid pattern capture"); +} + + +static const char *classend (MatchState *ms, const char *p) { + switch (*p++) { + case L_ESC: { + if (*p == '\0') + luaL_error(ms->L, "malformed pattern (ends with " LUA_QL("%%") ")"); + return p+1; + } + case '[': { + if (*p == '^') p++; + do { /* look for a `]' */ + if (*p == '\0') + luaL_error(ms->L, "malformed pattern (missing " LUA_QL("]") ")"); + if (*(p++) == L_ESC && *p != '\0') + p++; /* skip escapes (e.g. `%]') */ + } while (*p != ']'); + return p+1; + } + default: { + return p; + } + } +} + + +static int match_class (int c, int cl) { + int res; + switch (tolower(cl)) { + case 'a' : res = isalpha(c); break; + case 'c' : res = iscntrl(c); break; + case 'd' : res = isdigit(c); break; + case 'l' : res = islower(c); break; + case 'p' : res = ispunct(c); break; + case 's' : res = isspace(c); break; + case 'u' : res = isupper(c); break; + case 'w' : res = isalnum(c); break; + case 'x' : res = isxdigit(c); break; + case 'z' : res = (c == 0); break; + default: return (cl == c); + } + return (islower(cl) ? res : !res); +} + + +static int matchbracketclass (int c, const char *p, const char *ec) { + int sig = 1; + if (*(p+1) == '^') { + sig = 0; + p++; /* skip the `^' */ + } + while (++p < ec) { + if (*p == L_ESC) { + p++; + if (match_class(c, uchar(*p))) + return sig; + } + else if ((*(p+1) == '-') && (p+2 < ec)) { + p+=2; + if (uchar(*(p-2)) <= c && c <= uchar(*p)) + return sig; + } + else if (uchar(*p) == c) return sig; + } + return !sig; +} + + +static int singlematch (int c, const char *p, const char *ep) { + switch (*p) { + case '.': return 1; /* matches any char */ + case L_ESC: return match_class(c, uchar(*(p+1))); + case '[': return matchbracketclass(c, p, ep-1); + default: return (uchar(*p) == c); + } +} + + +static const char *match (MatchState *ms, const char *s, const char *p); + + +static const char *matchbalance (MatchState *ms, const char *s, + const char *p) { + if (*p == 0 || *(p+1) == 0) + luaL_error(ms->L, "unbalanced pattern"); + if (*s != *p) return NULL; + else { + int b = *p; + int e = *(p+1); + int cont = 1; + while (++s < ms->src_end) { + if (*s == e) { + if (--cont == 0) return s+1; + } + else if (*s == b) cont++; + } + } + return NULL; /* string ends out of balance */ +} + + +static const char *max_expand (MatchState *ms, const char *s, + const char *p, const char *ep) { + ptrdiff_t i = 0; /* counts maximum expand for item */ + while ((s+i)src_end && singlematch(uchar(*(s+i)), p, ep)) + i++; + /* keeps trying to match with the maximum repetitions */ + while (i>=0) { + const char *res = match(ms, (s+i), ep+1); + if (res) return res; + i--; /* else didn't match; reduce 1 repetition to try again */ + } + return NULL; +} + + +static const char *min_expand (MatchState *ms, const char *s, + const char *p, const char *ep) { + for (;;) { + const char *res = match(ms, s, ep+1); + if (res != NULL) + return res; + else if (ssrc_end && singlematch(uchar(*s), p, ep)) + s++; /* try with one more repetition */ + else return NULL; + } +} + + +static const char *start_capture (MatchState *ms, const char *s, + const char *p, int what) { + const char *res; + int level = ms->level; + if (level >= LUA_MAXCAPTURES) luaL_error(ms->L, "too many captures"); + ms->capture[level].init = s; + ms->capture[level].len = what; + ms->level = level+1; + if ((res=match(ms, s, p)) == NULL) /* match failed? */ + ms->level--; /* undo capture */ + return res; +} + + +static const char *end_capture (MatchState *ms, const char *s, + const char *p) { + int l = capture_to_close(ms); + const char *res; + ms->capture[l].len = s - ms->capture[l].init; /* close capture */ + if ((res = match(ms, s, p)) == NULL) /* match failed? */ + ms->capture[l].len = CAP_UNFINISHED; /* undo capture */ + return res; +} + + +static const char *match_capture (MatchState *ms, const char *s, int l) { + size_t len; + l = check_capture(ms, l); + len = ms->capture[l].len; + if ((size_t)(ms->src_end-s) >= len && + memcmp(ms->capture[l].init, s, len) == 0) + return s+len; + else return NULL; +} + + +static const char *match (MatchState *ms, const char *s, const char *p) { + init: /* using goto's to optimize tail recursion */ + switch (*p) { + case '(': { /* start capture */ + if (*(p+1) == ')') /* position capture? */ + return start_capture(ms, s, p+2, CAP_POSITION); + else + return start_capture(ms, s, p+1, CAP_UNFINISHED); + } + case ')': { /* end capture */ + return end_capture(ms, s, p+1); + } + case L_ESC: { + switch (*(p+1)) { + case 'b': { /* balanced string? */ + s = matchbalance(ms, s, p+2); + if (s == NULL) return NULL; + p+=4; goto init; /* else return match(ms, s, p+4); */ + } + case 'f': { /* frontier? */ + const char *ep; char previous; + p += 2; + if (*p != '[') + luaL_error(ms->L, "missing " LUA_QL("[") " after " + LUA_QL("%%f") " in pattern"); + ep = classend(ms, p); /* points to what is next */ + previous = (s == ms->src_init) ? '\0' : *(s-1); + if (matchbracketclass(uchar(previous), p, ep-1) || + !matchbracketclass(uchar(*s), p, ep-1)) return NULL; + p=ep; goto init; /* else return match(ms, s, ep); */ + } + default: { + if (isdigit(uchar(*(p+1)))) { /* capture results (%0-%9)? */ + s = match_capture(ms, s, uchar(*(p+1))); + if (s == NULL) return NULL; + p+=2; goto init; /* else return match(ms, s, p+2) */ + } + goto dflt; /* case default */ + } + } + } + case '\0': { /* end of pattern */ + return s; /* match succeeded */ + } + case '$': { + if (*(p+1) == '\0') /* is the `$' the last char in pattern? */ + return (s == ms->src_end) ? s : NULL; /* check end of string */ + else goto dflt; + } + default: dflt: { /* it is a pattern item */ + const char *ep = classend(ms, p); /* points to what is next */ + int m = ssrc_end && singlematch(uchar(*s), p, ep); + switch (*ep) { + case '?': { /* optional */ + const char *res; + if (m && ((res=match(ms, s+1, ep+1)) != NULL)) + return res; + p=ep+1; goto init; /* else return match(ms, s, ep+1); */ + } + case '*': { /* 0 or more repetitions */ + return max_expand(ms, s, p, ep); + } + case '+': { /* 1 or more repetitions */ + return (m ? max_expand(ms, s+1, p, ep) : NULL); + } + case '-': { /* 0 or more repetitions (minimum) */ + return min_expand(ms, s, p, ep); + } + default: { + if (!m) return NULL; + s++; p=ep; goto init; /* else return match(ms, s+1, ep); */ + } + } + } + } +} + + + +static const char *lmemfind (const char *s1, size_t l1, + const char *s2, size_t l2) { + if (l2 == 0) return s1; /* empty strings are everywhere */ + else if (l2 > l1) return NULL; /* avoids a negative `l1' */ + else { + const char *init; /* to search for a `*s2' inside `s1' */ + l2--; /* 1st char will be checked by `memchr' */ + l1 = l1-l2; /* `s2' cannot be found after that */ + while (l1 > 0 && (init = (const char *)memchr(s1, *s2, l1)) != NULL) { + init++; /* 1st char is already checked */ + if (memcmp(init, s2+1, l2) == 0) + return init-1; + else { /* correct `l1' and `s1' to try again */ + l1 -= init-s1; + s1 = init; + } + } + return NULL; /* not found */ + } +} + + +static void push_onecapture (MatchState *ms, int i, const char *s, + const char *e) { + if (i >= ms->level) { + if (i == 0) /* ms->level == 0, too */ + lua_pushlstring(ms->L, s, e - s); /* add whole match */ + else + luaL_error(ms->L, "invalid capture index"); + } + else { + ptrdiff_t l = ms->capture[i].len; + if (l == CAP_UNFINISHED) luaL_error(ms->L, "unfinished capture"); + if (l == CAP_POSITION) + lua_pushinteger(ms->L, ms->capture[i].init - ms->src_init + 1); + else + lua_pushlstring(ms->L, ms->capture[i].init, l); + } +} + + +static int push_captures (MatchState *ms, const char *s, const char *e) { + int i; + int nlevels = (ms->level == 0 && s) ? 1 : ms->level; + luaL_checkstack(ms->L, nlevels, "too many captures"); + for (i = 0; i < nlevels; i++) + push_onecapture(ms, i, s, e); + return nlevels; /* number of strings pushed */ +} + + +static int str_find_aux (lua_State *L, int find) { + size_t l1, l2; + const char *s = luaL_checklstring(L, 1, &l1); + const char *p = luaL_checklstring(L, 2, &l2); + ptrdiff_t init = posrelat(luaL_optinteger(L, 3, 1), l1) - 1; + if (init < 0) init = 0; + else if ((size_t)(init) > l1) init = (ptrdiff_t)l1; + if (find && (lua_toboolean(L, 4) || /* explicit request? */ + strpbrk(p, SPECIALS) == NULL)) { /* or no special characters? */ + /* do a plain search */ + const char *s2 = lmemfind(s+init, l1-init, p, l2); + if (s2) { + lua_pushinteger(L, s2-s+1); + lua_pushinteger(L, s2-s+l2); + return 2; + } + } + else { + MatchState ms; + int anchor = (*p == '^') ? (p++, 1) : 0; + const char *s1=s+init; + ms.L = L; + ms.src_init = s; + ms.src_end = s+l1; + do { + const char *res; + ms.level = 0; + if ((res=match(&ms, s1, p)) != NULL) { + if (find) { + lua_pushinteger(L, s1-s+1); /* start */ + lua_pushinteger(L, res-s); /* end */ + return push_captures(&ms, NULL, 0) + 2; + } + else + return push_captures(&ms, s1, res); + } + } while (s1++ < ms.src_end && !anchor); + } + lua_pushnil(L); /* not found */ + return 1; +} + + +static int str_find (lua_State *L) { + return str_find_aux(L, 1); +} + + +static int str_match (lua_State *L) { + return str_find_aux(L, 0); +} + + +static int gmatch_aux (lua_State *L) { + MatchState ms; + size_t ls; + const char *s = lua_tolstring(L, lua_upvalueindex(1), &ls); + const char *p = lua_tostring(L, lua_upvalueindex(2)); + const char *src; + ms.L = L; + ms.src_init = s; + ms.src_end = s+ls; + for (src = s + (size_t)lua_tointeger(L, lua_upvalueindex(3)); + src <= ms.src_end; + src++) { + const char *e; + ms.level = 0; + if ((e = match(&ms, src, p)) != NULL) { + lua_Integer newstart = e-s; + if (e == src) newstart++; /* empty match? go at least one position */ + lua_pushinteger(L, newstart); + lua_replace(L, lua_upvalueindex(3)); + return push_captures(&ms, src, e); + } + } + return 0; /* not found */ +} + + +static int gmatch (lua_State *L) { + luaL_checkstring(L, 1); + luaL_checkstring(L, 2); + lua_settop(L, 2); + lua_pushinteger(L, 0); + lua_pushcclosure(L, gmatch_aux, 3); + return 1; +} + + +static int gfind_nodef (lua_State *L) { + return luaL_error(L, LUA_QL("string.gfind") " was renamed to " + LUA_QL("string.gmatch")); +} + + +static void add_s (MatchState *ms, luaL_Buffer *b, const char *s, + const char *e) { + size_t l, i; + const char *news = lua_tolstring(ms->L, 3, &l); + for (i = 0; i < l; i++) { + if (news[i] != L_ESC) + luaL_addchar(b, news[i]); + else { + i++; /* skip ESC */ + if (!isdigit(uchar(news[i]))) + luaL_addchar(b, news[i]); + else if (news[i] == '0') + luaL_addlstring(b, s, e - s); + else { + push_onecapture(ms, news[i] - '1', s, e); + luaL_addvalue(b); /* add capture to accumulated result */ + } + } + } +} + + +static void add_value (MatchState *ms, luaL_Buffer *b, const char *s, + const char *e) { + lua_State *L = ms->L; + switch (lua_type(L, 3)) { + case LUA_TNUMBER: + case LUA_TSTRING: { + add_s(ms, b, s, e); + return; + } + case LUA_TFUNCTION: { + int n; + lua_pushvalue(L, 3); + n = push_captures(ms, s, e); + lua_call(L, n, 1); + break; + } + case LUA_TTABLE: { + push_onecapture(ms, 0, s, e); + lua_gettable(L, 3); + break; + } + } + if (!lua_toboolean(L, -1)) { /* nil or false? */ + lua_pop(L, 1); + lua_pushlstring(L, s, e - s); /* keep original text */ + } + else if (!lua_isstring(L, -1)) + luaL_error(L, "invalid replacement value (a %s)", luaL_typename(L, -1)); + luaL_addvalue(b); /* add result to accumulator */ +} + + +static int str_gsub (lua_State *L) { + size_t srcl; + const char *src = luaL_checklstring(L, 1, &srcl); + const char *p = luaL_checkstring(L, 2); + int tr = lua_type(L, 3); + int max_s = luaL_optint(L, 4, srcl+1); + int anchor = (*p == '^') ? (p++, 1) : 0; + int n = 0; + MatchState ms; + luaL_Buffer b; + luaL_argcheck(L, tr == LUA_TNUMBER || tr == LUA_TSTRING || + tr == LUA_TFUNCTION || tr == LUA_TTABLE, 3, + "string/function/table expected"); + luaL_buffinit(L, &b); + ms.L = L; + ms.src_init = src; + ms.src_end = src+srcl; + while (n < max_s) { + const char *e; + ms.level = 0; + e = match(&ms, src, p); + if (e) { + n++; + add_value(&ms, &b, src, e); + } + if (e && e>src) /* non empty match? */ + src = e; /* skip it */ + else if (src < ms.src_end) + luaL_addchar(&b, *src++); + else break; + if (anchor) break; + } + luaL_addlstring(&b, src, ms.src_end-src); + luaL_pushresult(&b); + lua_pushinteger(L, n); /* number of substitutions */ + return 2; +} + +/* }====================================================== */ + + +/* maximum size of each formatted item (> len(format('%99.99f', -1e308))) */ +#define MAX_ITEM 512 +/* valid flags in a format specification */ +#define FLAGS "-+ #0" +/* +** maximum size of each format specification (such as '%-099.99d') +** (+10 accounts for %99.99x plus margin of error) +*/ +#define MAX_FORMAT (sizeof(FLAGS) + sizeof(LUA_INTFRMLEN) + 10) + + +static void addquoted (lua_State *L, luaL_Buffer *b, int arg) { + size_t l; + const char *s = luaL_checklstring(L, arg, &l); + luaL_addchar(b, '"'); + while (l--) { + switch (*s) { + case '"': case '\\': case '\n': { + luaL_addchar(b, '\\'); + luaL_addchar(b, *s); + break; + } + case '\r': { + luaL_addlstring(b, "\\r", 2); + break; + } + case '\0': { + luaL_addlstring(b, "\\000", 4); + break; + } + default: { + luaL_addchar(b, *s); + break; + } + } + s++; + } + luaL_addchar(b, '"'); +} + +static const char *scanformat (lua_State *L, const char *strfrmt, char *form) { + const char *p = strfrmt; + while (*p != '\0' && strchr(FLAGS, *p) != NULL) p++; /* skip flags */ + if ((size_t)(p - strfrmt) >= sizeof(FLAGS)) + luaL_error(L, "invalid format (repeated flags)"); + if (isdigit(uchar(*p))) p++; /* skip width */ + if (isdigit(uchar(*p))) p++; /* (2 digits at most) */ + if (*p == '.') { + p++; + if (isdigit(uchar(*p))) p++; /* skip precision */ + if (isdigit(uchar(*p))) p++; /* (2 digits at most) */ + } + if (isdigit(uchar(*p))) + luaL_error(L, "invalid format (width or precision too long)"); + *(form++) = '%'; + strncpy(form, strfrmt, p - strfrmt + 1); + form += p - strfrmt + 1; + *form = '\0'; + return p; +} + + +static void addintlen (char *form) { + size_t l = strlen(form); + char spec = form[l - 1]; + strcpy(form + l - 1, LUA_INTFRMLEN); + form[l + sizeof(LUA_INTFRMLEN) - 2] = spec; + form[l + sizeof(LUA_INTFRMLEN) - 1] = '\0'; +} + + +static int str_format (lua_State *L) { + int arg = 1; + size_t sfl; + const char *strfrmt = luaL_checklstring(L, arg, &sfl); + const char *strfrmt_end = strfrmt+sfl; + luaL_Buffer b; + luaL_buffinit(L, &b); + while (strfrmt < strfrmt_end) { + if (*strfrmt != L_ESC) + luaL_addchar(&b, *strfrmt++); + else if (*++strfrmt == L_ESC) + luaL_addchar(&b, *strfrmt++); /* %% */ + else { /* format item */ + char form[MAX_FORMAT]; /* to store the format (`%...') */ + char buff[MAX_ITEM]; /* to store the formatted item */ + arg++; + strfrmt = scanformat(L, strfrmt, form); + switch (*strfrmt++) { + case 'c': { + sprintf(buff, form, (int)luaL_checknumber(L, arg)); + break; + } + case 'd': case 'i': { + addintlen(form); + sprintf(buff, form, (LUA_INTFRM_T)luaL_checknumber(L, arg)); + break; + } + case 'o': case 'u': case 'x': case 'X': { + addintlen(form); + sprintf(buff, form, (unsigned LUA_INTFRM_T)luaL_checknumber(L, arg)); + break; + } + case 'e': case 'E': case 'f': + case 'g': case 'G': { + sprintf(buff, form, (double)luaL_checknumber(L, arg)); + break; + } + case 'q': { + addquoted(L, &b, arg); + continue; /* skip the 'addsize' at the end */ + } + case 's': { + size_t l; + const char *s = luaL_checklstring(L, arg, &l); + if (!strchr(form, '.') && l >= 100) { + /* no precision and string is too long to be formatted; + keep original string */ + lua_pushvalue(L, arg); + luaL_addvalue(&b); + continue; /* skip the `addsize' at the end */ + } + else { + sprintf(buff, form, s); + break; + } + } + default: { /* also treat cases `pnLlh' */ + return luaL_error(L, "invalid option " LUA_QL("%%%c") " to " + LUA_QL("format"), *(strfrmt - 1)); + } + } + luaL_addlstring(&b, buff, strlen(buff)); + } + } + luaL_pushresult(&b); + return 1; +} + + +static const luaL_Reg strlib[] = { + {"byte", str_byte}, + {"char", str_char}, + {"dump", str_dump}, + {"find", str_find}, + {"format", str_format}, + {"gfind", gfind_nodef}, + {"gmatch", gmatch}, + {"gsub", str_gsub}, + {"len", str_len}, + {"lower", str_lower}, + {"match", str_match}, + {"rep", str_rep}, + {"reverse", str_reverse}, + {"sub", str_sub}, + {"upper", str_upper}, + {NULL, NULL} +}; + + +static void createmetatable (lua_State *L) { + lua_createtable(L, 0, 1); /* create metatable for strings */ + lua_pushliteral(L, ""); /* dummy string */ + lua_pushvalue(L, -2); + lua_setmetatable(L, -2); /* set string metatable */ + lua_pop(L, 1); /* pop dummy string */ + lua_pushvalue(L, -2); /* string library... */ + lua_setfield(L, -2, "__index"); /* ...is the __index metamethod */ + lua_pop(L, 1); /* pop metatable */ +} + + +/* +** Open string library +*/ +LUALIB_API int luaopen_string (lua_State *L) { + luaL_register(L, LUA_STRLIBNAME, strlib); +#if defined(LUA_COMPAT_GFIND) + lua_getfield(L, -1, "gmatch"); + lua_setfield(L, -2, "gfind"); +#endif + createmetatable(L); + return 1; +} + diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/ltable.c b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/ltable.c new file mode 100644 index 00000000..ec84f4fa --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/ltable.c @@ -0,0 +1,588 @@ +/* +** $Id: ltable.c,v 2.32.1.2 2007/12/28 15:32:23 roberto Exp $ +** Lua tables (hash) +** See Copyright Notice in lua.h +*/ + + +/* +** Implementation of tables (aka arrays, objects, or hash tables). +** Tables keep its elements in two parts: an array part and a hash part. +** Non-negative integer keys are all candidates to be kept in the array +** part. The actual size of the array is the largest `n' such that at +** least half the slots between 0 and n are in use. +** Hash uses a mix of chained scatter table with Brent's variation. +** A main invariant of these tables is that, if an element is not +** in its main position (i.e. the `original' position that its hash gives +** to it), then the colliding element is in its own main position. +** Hence even when the load factor reaches 100%, performance remains good. +*/ + +#include +#include + +#define ltable_c +#define LUA_CORE + +#include "lua.h" + +#include "ldebug.h" +#include "ldo.h" +#include "lgc.h" +#include "lmem.h" +#include "lobject.h" +#include "lstate.h" +#include "ltable.h" + + +/* +** max size of array part is 2^MAXBITS +*/ +#if LUAI_BITSINT > 26 +#define MAXBITS 26 +#else +#define MAXBITS (LUAI_BITSINT-2) +#endif + +#define MAXASIZE (1 << MAXBITS) + + +#define hashpow2(t,n) (gnode(t, lmod((n), sizenode(t)))) + +#define hashstr(t,str) hashpow2(t, (str)->tsv.hash) +#define hashboolean(t,p) hashpow2(t, p) + + +/* +** for some types, it is better to avoid modulus by power of 2, as +** they tend to have many 2 factors. +*/ +#define hashmod(t,n) (gnode(t, ((n) % ((sizenode(t)-1)|1)))) + + +#define hashpointer(t,p) hashmod(t, IntPoint(p)) + + +/* +** number of ints inside a lua_Number +*/ +#define numints cast_int(sizeof(lua_Number)/sizeof(int)) + + + +#define dummynode (&dummynode_) + +static const Node dummynode_ = { + {{NULL}, LUA_TNIL}, /* value */ + {{{NULL}, LUA_TNIL, NULL}} /* key */ +}; + + +/* +** hash for lua_Numbers +*/ +static Node *hashnum (const Table *t, lua_Number n) { + unsigned int a[numints]; + int i; + if (luai_numeq(n, 0)) /* avoid problems with -0 */ + return gnode(t, 0); + memcpy(a, &n, sizeof(a)); + for (i = 1; i < numints; i++) a[0] += a[i]; + return hashmod(t, a[0]); +} + + + +/* +** returns the `main' position of an element in a table (that is, the index +** of its hash value) +*/ +static Node *mainposition (const Table *t, const TValue *key) { + switch (ttype(key)) { + case LUA_TNUMBER: + return hashnum(t, nvalue(key)); + case LUA_TSTRING: + return hashstr(t, rawtsvalue(key)); + case LUA_TBOOLEAN: + return hashboolean(t, bvalue(key)); + case LUA_TLIGHTUSERDATA: + return hashpointer(t, pvalue(key)); + default: + return hashpointer(t, gcvalue(key)); + } +} + + +/* +** returns the index for `key' if `key' is an appropriate key to live in +** the array part of the table, -1 otherwise. +*/ +static int arrayindex (const TValue *key) { + if (ttisnumber(key)) { + lua_Number n = nvalue(key); + int k; + lua_number2int(k, n); + if (luai_numeq(cast_num(k), n)) + return k; + } + return -1; /* `key' did not match some condition */ +} + + +/* +** returns the index of a `key' for table traversals. First goes all +** elements in the array part, then elements in the hash part. The +** beginning of a traversal is signalled by -1. +*/ +static int findindex (lua_State *L, Table *t, StkId key) { + int i; + if (ttisnil(key)) return -1; /* first iteration */ + i = arrayindex(key); + if (0 < i && i <= t->sizearray) /* is `key' inside array part? */ + return i-1; /* yes; that's the index (corrected to C) */ + else { + Node *n = mainposition(t, key); + do { /* check whether `key' is somewhere in the chain */ + /* key may be dead already, but it is ok to use it in `next' */ + if (luaO_rawequalObj(key2tval(n), key) || + (ttype(gkey(n)) == LUA_TDEADKEY && iscollectable(key) && + gcvalue(gkey(n)) == gcvalue(key))) { + i = cast_int(n - gnode(t, 0)); /* key index in hash table */ + /* hash elements are numbered after array ones */ + return i + t->sizearray; + } + else n = gnext(n); + } while (n); + luaG_runerror(L, "invalid key to " LUA_QL("next")); /* key not found */ + return 0; /* to avoid warnings */ + } +} + + +int luaH_next (lua_State *L, Table *t, StkId key) { + int i = findindex(L, t, key); /* find original element */ + for (i++; i < t->sizearray; i++) { /* try first array part */ + if (!ttisnil(&t->array[i])) { /* a non-nil value? */ + setnvalue(key, cast_num(i+1)); + setobj2s(L, key+1, &t->array[i]); + return 1; + } + } + for (i -= t->sizearray; i < sizenode(t); i++) { /* then hash part */ + if (!ttisnil(gval(gnode(t, i)))) { /* a non-nil value? */ + setobj2s(L, key, key2tval(gnode(t, i))); + setobj2s(L, key+1, gval(gnode(t, i))); + return 1; + } + } + return 0; /* no more elements */ +} + + +/* +** {============================================================= +** Rehash +** ============================================================== +*/ + + +static int computesizes (int nums[], int *narray) { + int i; + int twotoi; /* 2^i */ + int a = 0; /* number of elements smaller than 2^i */ + int na = 0; /* number of elements to go to array part */ + int n = 0; /* optimal size for array part */ + for (i = 0, twotoi = 1; twotoi/2 < *narray; i++, twotoi *= 2) { + if (nums[i] > 0) { + a += nums[i]; + if (a > twotoi/2) { /* more than half elements present? */ + n = twotoi; /* optimal size (till now) */ + na = a; /* all elements smaller than n will go to array part */ + } + } + if (a == *narray) break; /* all elements already counted */ + } + *narray = n; + lua_assert(*narray/2 <= na && na <= *narray); + return na; +} + + +static int countint (const TValue *key, int *nums) { + int k = arrayindex(key); + if (0 < k && k <= MAXASIZE) { /* is `key' an appropriate array index? */ + nums[ceillog2(k)]++; /* count as such */ + return 1; + } + else + return 0; +} + + +static int numusearray (const Table *t, int *nums) { + int lg; + int ttlg; /* 2^lg */ + int ause = 0; /* summation of `nums' */ + int i = 1; /* count to traverse all array keys */ + for (lg=0, ttlg=1; lg<=MAXBITS; lg++, ttlg*=2) { /* for each slice */ + int lc = 0; /* counter */ + int lim = ttlg; + if (lim > t->sizearray) { + lim = t->sizearray; /* adjust upper limit */ + if (i > lim) + break; /* no more elements to count */ + } + /* count elements in range (2^(lg-1), 2^lg] */ + for (; i <= lim; i++) { + if (!ttisnil(&t->array[i-1])) + lc++; + } + nums[lg] += lc; + ause += lc; + } + return ause; +} + + +static int numusehash (const Table *t, int *nums, int *pnasize) { + int totaluse = 0; /* total number of elements */ + int ause = 0; /* summation of `nums' */ + int i = sizenode(t); + while (i--) { + Node *n = &t->node[i]; + if (!ttisnil(gval(n))) { + ause += countint(key2tval(n), nums); + totaluse++; + } + } + *pnasize += ause; + return totaluse; +} + + +static void setarrayvector (lua_State *L, Table *t, int size) { + int i; + luaM_reallocvector(L, t->array, t->sizearray, size, TValue); + for (i=t->sizearray; iarray[i]); + t->sizearray = size; +} + + +static void setnodevector (lua_State *L, Table *t, int size) { + int lsize; + if (size == 0) { /* no elements to hash part? */ + t->node = cast(Node *, dummynode); /* use common `dummynode' */ + lsize = 0; + } + else { + int i; + lsize = ceillog2(size); + if (lsize > MAXBITS) + luaG_runerror(L, "table overflow"); + size = twoto(lsize); + t->node = luaM_newvector(L, size, Node); + for (i=0; ilsizenode = cast_byte(lsize); + t->lastfree = gnode(t, size); /* all positions are free */ +} + + +static void resize (lua_State *L, Table *t, int nasize, int nhsize) { + int i; + int oldasize = t->sizearray; + int oldhsize = t->lsizenode; + Node *nold = t->node; /* save old hash ... */ + if (nasize > oldasize) /* array part must grow? */ + setarrayvector(L, t, nasize); + /* create new hash part with appropriate size */ + setnodevector(L, t, nhsize); + if (nasize < oldasize) { /* array part must shrink? */ + t->sizearray = nasize; + /* re-insert elements from vanishing slice */ + for (i=nasize; iarray[i])) + setobjt2t(L, luaH_setnum(L, t, i+1), &t->array[i]); + } + /* shrink array */ + luaM_reallocvector(L, t->array, oldasize, nasize, TValue); + } + /* re-insert elements from hash part */ + for (i = twoto(oldhsize) - 1; i >= 0; i--) { + Node *old = nold+i; + if (!ttisnil(gval(old))) + setobjt2t(L, luaH_set(L, t, key2tval(old)), gval(old)); + } + if (nold != dummynode) + luaM_freearray(L, nold, twoto(oldhsize), Node); /* free old array */ +} + + +void luaH_resizearray (lua_State *L, Table *t, int nasize) { + int nsize = (t->node == dummynode) ? 0 : sizenode(t); + resize(L, t, nasize, nsize); +} + + +static void rehash (lua_State *L, Table *t, const TValue *ek) { + int nasize, na; + int nums[MAXBITS+1]; /* nums[i] = number of keys between 2^(i-1) and 2^i */ + int i; + int totaluse; + for (i=0; i<=MAXBITS; i++) nums[i] = 0; /* reset counts */ + nasize = numusearray(t, nums); /* count keys in array part */ + totaluse = nasize; /* all those keys are integer keys */ + totaluse += numusehash(t, nums, &nasize); /* count keys in hash part */ + /* count extra key */ + nasize += countint(ek, nums); + totaluse++; + /* compute new size for array part */ + na = computesizes(nums, &nasize); + /* resize the table to new computed sizes */ + resize(L, t, nasize, totaluse - na); +} + + + +/* +** }============================================================= +*/ + + +Table *luaH_new (lua_State *L, int narray, int nhash) { + Table *t = luaM_new(L, Table); + luaC_link(L, obj2gco(t), LUA_TTABLE); + t->metatable = NULL; + t->flags = cast_byte(~0); + /* temporary values (kept only if some malloc fails) */ + t->array = NULL; + t->sizearray = 0; + t->lsizenode = 0; + t->node = cast(Node *, dummynode); + setarrayvector(L, t, narray); + setnodevector(L, t, nhash); + return t; +} + + +void luaH_free (lua_State *L, Table *t) { + if (t->node != dummynode) + luaM_freearray(L, t->node, sizenode(t), Node); + luaM_freearray(L, t->array, t->sizearray, TValue); + luaM_free(L, t); +} + + +static Node *getfreepos (Table *t) { + while (t->lastfree-- > t->node) { + if (ttisnil(gkey(t->lastfree))) + return t->lastfree; + } + return NULL; /* could not find a free place */ +} + + + +/* +** inserts a new key into a hash table; first, check whether key's main +** position is free. If not, check whether colliding node is in its main +** position or not: if it is not, move colliding node to an empty place and +** put new key in its main position; otherwise (colliding node is in its main +** position), new key goes to an empty position. +*/ +static TValue *newkey (lua_State *L, Table *t, const TValue *key) { + Node *mp = mainposition(t, key); + if (!ttisnil(gval(mp)) || mp == dummynode) { + Node *othern; + Node *n = getfreepos(t); /* get a free place */ + if (n == NULL) { /* cannot find a free place? */ + rehash(L, t, key); /* grow table */ + return luaH_set(L, t, key); /* re-insert key into grown table */ + } + lua_assert(n != dummynode); + othern = mainposition(t, key2tval(mp)); + if (othern != mp) { /* is colliding node out of its main position? */ + /* yes; move colliding node into free position */ + while (gnext(othern) != mp) othern = gnext(othern); /* find previous */ + gnext(othern) = n; /* redo the chain with `n' in place of `mp' */ + *n = *mp; /* copy colliding node into free pos. (mp->next also goes) */ + gnext(mp) = NULL; /* now `mp' is free */ + setnilvalue(gval(mp)); + } + else { /* colliding node is in its own main position */ + /* new node will go into free position */ + gnext(n) = gnext(mp); /* chain new position */ + gnext(mp) = n; + mp = n; + } + } + gkey(mp)->value = key->value; gkey(mp)->tt = key->tt; + luaC_barriert(L, t, key); + lua_assert(ttisnil(gval(mp))); + return gval(mp); +} + + +/* +** search function for integers +*/ +const TValue *luaH_getnum (Table *t, int key) { + /* (1 <= key && key <= t->sizearray) */ + if (cast(unsigned int, key-1) < cast(unsigned int, t->sizearray)) + return &t->array[key-1]; + else { + lua_Number nk = cast_num(key); + Node *n = hashnum(t, nk); + do { /* check whether `key' is somewhere in the chain */ + if (ttisnumber(gkey(n)) && luai_numeq(nvalue(gkey(n)), nk)) + return gval(n); /* that's it */ + else n = gnext(n); + } while (n); + return luaO_nilobject; + } +} + + +/* +** search function for strings +*/ +const TValue *luaH_getstr (Table *t, TString *key) { + Node *n = hashstr(t, key); + do { /* check whether `key' is somewhere in the chain */ + if (ttisstring(gkey(n)) && rawtsvalue(gkey(n)) == key) + return gval(n); /* that's it */ + else n = gnext(n); + } while (n); + return luaO_nilobject; +} + + +/* +** main search function +*/ +const TValue *luaH_get (Table *t, const TValue *key) { + switch (ttype(key)) { + case LUA_TNIL: return luaO_nilobject; + case LUA_TSTRING: return luaH_getstr(t, rawtsvalue(key)); + case LUA_TNUMBER: { + int k; + lua_Number n = nvalue(key); + lua_number2int(k, n); + if (luai_numeq(cast_num(k), nvalue(key))) /* index is int? */ + return luaH_getnum(t, k); /* use specialized version */ + /* else go through */ + } + default: { + Node *n = mainposition(t, key); + do { /* check whether `key' is somewhere in the chain */ + if (luaO_rawequalObj(key2tval(n), key)) + return gval(n); /* that's it */ + else n = gnext(n); + } while (n); + return luaO_nilobject; + } + } +} + + +TValue *luaH_set (lua_State *L, Table *t, const TValue *key) { + const TValue *p = luaH_get(t, key); + t->flags = 0; + if (p != luaO_nilobject) + return cast(TValue *, p); + else { + if (ttisnil(key)) luaG_runerror(L, "table index is nil"); + else if (ttisnumber(key) && luai_numisnan(nvalue(key))) + luaG_runerror(L, "table index is NaN"); + return newkey(L, t, key); + } +} + + +TValue *luaH_setnum (lua_State *L, Table *t, int key) { + const TValue *p = luaH_getnum(t, key); + if (p != luaO_nilobject) + return cast(TValue *, p); + else { + TValue k; + setnvalue(&k, cast_num(key)); + return newkey(L, t, &k); + } +} + + +TValue *luaH_setstr (lua_State *L, Table *t, TString *key) { + const TValue *p = luaH_getstr(t, key); + if (p != luaO_nilobject) + return cast(TValue *, p); + else { + TValue k; + setsvalue(L, &k, key); + return newkey(L, t, &k); + } +} + + +static int unbound_search (Table *t, unsigned int j) { + unsigned int i = j; /* i is zero or a present index */ + j++; + /* find `i' and `j' such that i is present and j is not */ + while (!ttisnil(luaH_getnum(t, j))) { + i = j; + j *= 2; + if (j > cast(unsigned int, MAX_INT)) { /* overflow? */ + /* table was built with bad purposes: resort to linear search */ + i = 1; + while (!ttisnil(luaH_getnum(t, i))) i++; + return i - 1; + } + } + /* now do a binary search between them */ + while (j - i > 1) { + unsigned int m = (i+j)/2; + if (ttisnil(luaH_getnum(t, m))) j = m; + else i = m; + } + return i; +} + + +/* +** Try to find a boundary in table `t'. A `boundary' is an integer index +** such that t[i] is non-nil and t[i+1] is nil (and 0 if t[1] is nil). +*/ +int luaH_getn (Table *t) { + unsigned int j = t->sizearray; + if (j > 0 && ttisnil(&t->array[j - 1])) { + /* there is a boundary in the array part: (binary) search for it */ + unsigned int i = 0; + while (j - i > 1) { + unsigned int m = (i+j)/2; + if (ttisnil(&t->array[m - 1])) j = m; + else i = m; + } + return i; + } + /* else must find a boundary in hash part */ + else if (t->node == dummynode) /* hash part is empty? */ + return j; /* that is easy... */ + else return unbound_search(t, j); +} + + + +#if defined(LUA_DEBUG) + +Node *luaH_mainposition (const Table *t, const TValue *key) { + return mainposition(t, key); +} + +int luaH_isdummy (Node *n) { return n == dummynode; } + +#endif diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/ltable.h b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/ltable.h new file mode 100644 index 00000000..f5b9d5ea --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/ltable.h @@ -0,0 +1,40 @@ +/* +** $Id: ltable.h,v 2.10.1.1 2007/12/27 13:02:25 roberto Exp $ +** Lua tables (hash) +** See Copyright Notice in lua.h +*/ + +#ifndef ltable_h +#define ltable_h + +#include "lobject.h" + + +#define gnode(t,i) (&(t)->node[i]) +#define gkey(n) (&(n)->i_key.nk) +#define gval(n) (&(n)->i_val) +#define gnext(n) ((n)->i_key.nk.next) + +#define key2tval(n) (&(n)->i_key.tvk) + + +LUAI_FUNC const TValue *luaH_getnum (Table *t, int key); +LUAI_FUNC TValue *luaH_setnum (lua_State *L, Table *t, int key); +LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key); +LUAI_FUNC TValue *luaH_setstr (lua_State *L, Table *t, TString *key); +LUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key); +LUAI_FUNC TValue *luaH_set (lua_State *L, Table *t, const TValue *key); +LUAI_FUNC Table *luaH_new (lua_State *L, int narray, int lnhash); +LUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, int nasize); +LUAI_FUNC void luaH_free (lua_State *L, Table *t); +LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key); +LUAI_FUNC int luaH_getn (Table *t); + + +#if defined(LUA_DEBUG) +LUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key); +LUAI_FUNC int luaH_isdummy (Node *n); +#endif + + +#endif diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/ltablib.c b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/ltablib.c new file mode 100644 index 00000000..b6d9cb4a --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/ltablib.c @@ -0,0 +1,287 @@ +/* +** $Id: ltablib.c,v 1.38.1.3 2008/02/14 16:46:58 roberto Exp $ +** Library for Table Manipulation +** See Copyright Notice in lua.h +*/ + + +#include + +#define ltablib_c +#define LUA_LIB + +#include "lua.h" + +#include "lauxlib.h" +#include "lualib.h" + + +#define aux_getn(L,n) (luaL_checktype(L, n, LUA_TTABLE), luaL_getn(L, n)) + + +static int foreachi (lua_State *L) { + int i; + int n = aux_getn(L, 1); + luaL_checktype(L, 2, LUA_TFUNCTION); + for (i=1; i <= n; i++) { + lua_pushvalue(L, 2); /* function */ + lua_pushinteger(L, i); /* 1st argument */ + lua_rawgeti(L, 1, i); /* 2nd argument */ + lua_call(L, 2, 1); + if (!lua_isnil(L, -1)) + return 1; + lua_pop(L, 1); /* remove nil result */ + } + return 0; +} + + +static int foreach (lua_State *L) { + luaL_checktype(L, 1, LUA_TTABLE); + luaL_checktype(L, 2, LUA_TFUNCTION); + lua_pushnil(L); /* first key */ + while (lua_next(L, 1)) { + lua_pushvalue(L, 2); /* function */ + lua_pushvalue(L, -3); /* key */ + lua_pushvalue(L, -3); /* value */ + lua_call(L, 2, 1); + if (!lua_isnil(L, -1)) + return 1; + lua_pop(L, 2); /* remove value and result */ + } + return 0; +} + + +static int maxn (lua_State *L) { + lua_Number max = 0; + luaL_checktype(L, 1, LUA_TTABLE); + lua_pushnil(L); /* first key */ + while (lua_next(L, 1)) { + lua_pop(L, 1); /* remove value */ + if (lua_type(L, -1) == LUA_TNUMBER) { + lua_Number v = lua_tonumber(L, -1); + if (v > max) max = v; + } + } + lua_pushnumber(L, max); + return 1; +} + + +static int getn (lua_State *L) { + lua_pushinteger(L, aux_getn(L, 1)); + return 1; +} + + +static int setn (lua_State *L) { + luaL_checktype(L, 1, LUA_TTABLE); +#ifndef luaL_setn + luaL_setn(L, 1, luaL_checkint(L, 2)); +#else + luaL_error(L, LUA_QL("setn") " is obsolete"); +#endif + lua_pushvalue(L, 1); + return 1; +} + + +static int tinsert (lua_State *L) { + int e = aux_getn(L, 1) + 1; /* first empty element */ + int pos; /* where to insert new element */ + switch (lua_gettop(L)) { + case 2: { /* called with only 2 arguments */ + pos = e; /* insert new element at the end */ + break; + } + case 3: { + int i; + pos = luaL_checkint(L, 2); /* 2nd argument is the position */ + if (pos > e) e = pos; /* `grow' array if necessary */ + for (i = e; i > pos; i--) { /* move up elements */ + lua_rawgeti(L, 1, i-1); + lua_rawseti(L, 1, i); /* t[i] = t[i-1] */ + } + break; + } + default: { + return luaL_error(L, "wrong number of arguments to " LUA_QL("insert")); + } + } + luaL_setn(L, 1, e); /* new size */ + lua_rawseti(L, 1, pos); /* t[pos] = v */ + return 0; +} + + +static int tremove (lua_State *L) { + int e = aux_getn(L, 1); + int pos = luaL_optint(L, 2, e); + if (!(1 <= pos && pos <= e)) /* position is outside bounds? */ + return 0; /* nothing to remove */ + luaL_setn(L, 1, e - 1); /* t.n = n-1 */ + lua_rawgeti(L, 1, pos); /* result = t[pos] */ + for ( ;pos= P */ + while (lua_rawgeti(L, 1, ++i), sort_comp(L, -1, -2)) { + if (i>u) luaL_error(L, "invalid order function for sorting"); + lua_pop(L, 1); /* remove a[i] */ + } + /* repeat --j until a[j] <= P */ + while (lua_rawgeti(L, 1, --j), sort_comp(L, -3, -1)) { + if (j + +#define ltm_c +#define LUA_CORE + +#include "lua.h" + +#include "lobject.h" +#include "lstate.h" +#include "lstring.h" +#include "ltable.h" +#include "ltm.h" + + + +const char *const luaT_typenames[] = { + "nil", "boolean", "userdata", "number", + "string", "table", "function", "userdata", "thread", + "proto", "upval" +}; + + +void luaT_init (lua_State *L) { + static const char *const luaT_eventname[] = { /* ORDER TM */ + "__index", "__newindex", + "__gc", "__mode", "__eq", + "__add", "__sub", "__mul", "__div", "__mod", + "__pow", "__unm", "__len", "__lt", "__le", + "__concat", "__call" + }; + int i; + for (i=0; itmname[i] = luaS_new(L, luaT_eventname[i]); + luaS_fix(G(L)->tmname[i]); /* never collect these names */ + } +} + + +/* +** function to be used with macro "fasttm": optimized for absence of +** tag methods +*/ +const TValue *luaT_gettm (Table *events, TMS event, TString *ename) { + const TValue *tm = luaH_getstr(events, ename); + lua_assert(event <= TM_EQ); + if (ttisnil(tm)) { /* no tag method? */ + events->flags |= cast_byte(1u<metatable; + break; + case LUA_TUSERDATA: + mt = uvalue(o)->metatable; + break; + default: + mt = G(L)->mt[ttype(o)]; + } + return (mt ? luaH_getstr(mt, G(L)->tmname[event]) : luaO_nilobject); +} + diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/ltm.h b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/ltm.h new file mode 100644 index 00000000..64343b78 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/ltm.h @@ -0,0 +1,54 @@ +/* +** $Id: ltm.h,v 2.6.1.1 2007/12/27 13:02:25 roberto Exp $ +** Tag methods +** See Copyright Notice in lua.h +*/ + +#ifndef ltm_h +#define ltm_h + + +#include "lobject.h" + + +/* +* WARNING: if you change the order of this enumeration, +* grep "ORDER TM" +*/ +typedef enum { + TM_INDEX, + TM_NEWINDEX, + TM_GC, + TM_MODE, + TM_EQ, /* last tag method with `fast' access */ + TM_ADD, + TM_SUB, + TM_MUL, + TM_DIV, + TM_MOD, + TM_POW, + TM_UNM, + TM_LEN, + TM_LT, + TM_LE, + TM_CONCAT, + TM_CALL, + TM_N /* number of elements in the enum */ +} TMS; + + + +#define gfasttm(g,et,e) ((et) == NULL ? NULL : \ + ((et)->flags & (1u<<(e))) ? NULL : luaT_gettm(et, e, (g)->tmname[e])) + +#define fasttm(l,et,e) gfasttm(G(l), et, e) + +LUAI_DATA const char *const luaT_typenames[]; + + +LUAI_FUNC const TValue *luaT_gettm (Table *events, TMS event, TString *ename); +LUAI_FUNC const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, + TMS event); +LUAI_FUNC void luaT_init (lua_State *L); + +#endif diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lua.c b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lua.c new file mode 100644 index 00000000..3a466093 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lua.c @@ -0,0 +1,392 @@ +/* +** $Id: lua.c,v 1.160.1.2 2007/12/28 15:32:23 roberto Exp $ +** Lua stand-alone interpreter +** See Copyright Notice in lua.h +*/ + + +#include +#include +#include +#include + +#define lua_c + +#include "lua.h" + +#include "lauxlib.h" +#include "lualib.h" + + + +static lua_State *globalL = NULL; + +static const char *progname = LUA_PROGNAME; + + + +static void lstop (lua_State *L, lua_Debug *ar) { + (void)ar; /* unused arg. */ + lua_sethook(L, NULL, 0, 0); + luaL_error(L, "interrupted!"); +} + + +static void laction (int i) { + signal(i, SIG_DFL); /* if another SIGINT happens before lstop, + terminate process (default action) */ + lua_sethook(globalL, lstop, LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 1); +} + + +static void print_usage (void) { + fprintf(stderr, + "usage: %s [options] [script [args]].\n" + "Available options are:\n" + " -e stat execute string " LUA_QL("stat") "\n" + " -l name require library " LUA_QL("name") "\n" + " -i enter interactive mode after executing " LUA_QL("script") "\n" + " -v show version information\n" + " -- stop handling options\n" + " - execute stdin and stop handling options\n" + , + progname); + fflush(stderr); +} + + +static void l_message (const char *pname, const char *msg) { + if (pname) fprintf(stderr, "%s: ", pname); + fprintf(stderr, "%s\n", msg); + fflush(stderr); +} + + +static int report (lua_State *L, int status) { + if (status && !lua_isnil(L, -1)) { + const char *msg = lua_tostring(L, -1); + if (msg == NULL) msg = "(error object is not a string)"; + l_message(progname, msg); + lua_pop(L, 1); + } + return status; +} + + +static int traceback (lua_State *L) { + if (!lua_isstring(L, 1)) /* 'message' not a string? */ + return 1; /* keep it intact */ + lua_getfield(L, LUA_GLOBALSINDEX, "debug"); + if (!lua_istable(L, -1)) { + lua_pop(L, 1); + return 1; + } + lua_getfield(L, -1, "traceback"); + if (!lua_isfunction(L, -1)) { + lua_pop(L, 2); + return 1; + } + lua_pushvalue(L, 1); /* pass error message */ + lua_pushinteger(L, 2); /* skip this function and traceback */ + lua_call(L, 2, 1); /* call debug.traceback */ + return 1; +} + + +static int docall (lua_State *L, int narg, int clear) { + int status; + int base = lua_gettop(L) - narg; /* function index */ + lua_pushcfunction(L, traceback); /* push traceback function */ + lua_insert(L, base); /* put it under chunk and args */ + signal(SIGINT, laction); + status = lua_pcall(L, narg, (clear ? 0 : LUA_MULTRET), base); + signal(SIGINT, SIG_DFL); + lua_remove(L, base); /* remove traceback function */ + /* force a complete garbage collection in case of errors */ + if (status != 0) lua_gc(L, LUA_GCCOLLECT, 0); + return status; +} + + +static void print_version (void) { + l_message(NULL, LUA_RELEASE " " LUA_COPYRIGHT); +} + + +static int getargs (lua_State *L, char **argv, int n) { + int narg; + int i; + int argc = 0; + while (argv[argc]) argc++; /* count total number of arguments */ + narg = argc - (n + 1); /* number of arguments to the script */ + luaL_checkstack(L, narg + 3, "too many arguments to script"); + for (i=n+1; i < argc; i++) + lua_pushstring(L, argv[i]); + lua_createtable(L, narg, n + 1); + for (i=0; i < argc; i++) { + lua_pushstring(L, argv[i]); + lua_rawseti(L, -2, i - n); + } + return narg; +} + + +static int dofile (lua_State *L, const char *name) { + int status = luaL_loadfile(L, name) || docall(L, 0, 1); + return report(L, status); +} + + +static int dostring (lua_State *L, const char *s, const char *name) { + int status = luaL_loadbuffer(L, s, strlen(s), name) || docall(L, 0, 1); + return report(L, status); +} + + +static int dolibrary (lua_State *L, const char *name) { + lua_getglobal(L, "require"); + lua_pushstring(L, name); + return report(L, docall(L, 1, 1)); +} + + +static const char *get_prompt (lua_State *L, int firstline) { + const char *p; + lua_getfield(L, LUA_GLOBALSINDEX, firstline ? "_PROMPT" : "_PROMPT2"); + p = lua_tostring(L, -1); + if (p == NULL) p = (firstline ? LUA_PROMPT : LUA_PROMPT2); + lua_pop(L, 1); /* remove global */ + return p; +} + + +static int incomplete (lua_State *L, int status) { + if (status == LUA_ERRSYNTAX) { + size_t lmsg; + const char *msg = lua_tolstring(L, -1, &lmsg); + const char *tp = msg + lmsg - (sizeof(LUA_QL("")) - 1); + if (strstr(msg, LUA_QL("")) == tp) { + lua_pop(L, 1); + return 1; + } + } + return 0; /* else... */ +} + + +static int pushline (lua_State *L, int firstline) { + char buffer[LUA_MAXINPUT]; + char *b = buffer; + size_t l; + const char *prmt = get_prompt(L, firstline); + if (lua_readline(L, b, prmt) == 0) + return 0; /* no input */ + l = strlen(b); + if (l > 0 && b[l-1] == '\n') /* line ends with newline? */ + b[l-1] = '\0'; /* remove it */ + if (firstline && b[0] == '=') /* first line starts with `=' ? */ + lua_pushfstring(L, "return %s", b+1); /* change it to `return' */ + else + lua_pushstring(L, b); + lua_freeline(L, b); + return 1; +} + + +static int loadline (lua_State *L) { + int status; + lua_settop(L, 0); + if (!pushline(L, 1)) + return -1; /* no input */ + for (;;) { /* repeat until gets a complete line */ + status = luaL_loadbuffer(L, lua_tostring(L, 1), lua_strlen(L, 1), "=stdin"); + if (!incomplete(L, status)) break; /* cannot try to add lines? */ + if (!pushline(L, 0)) /* no more input? */ + return -1; + lua_pushliteral(L, "\n"); /* add a new line... */ + lua_insert(L, -2); /* ...between the two lines */ + lua_concat(L, 3); /* join them */ + } + lua_saveline(L, 1); + lua_remove(L, 1); /* remove line */ + return status; +} + + +static void dotty (lua_State *L) { + int status; + const char *oldprogname = progname; + progname = NULL; + while ((status = loadline(L)) != -1) { + if (status == 0) status = docall(L, 0, 0); + report(L, status); + if (status == 0 && lua_gettop(L) > 0) { /* any result to print? */ + lua_getglobal(L, "print"); + lua_insert(L, 1); + if (lua_pcall(L, lua_gettop(L)-1, 0, 0) != 0) + l_message(progname, lua_pushfstring(L, + "error calling " LUA_QL("print") " (%s)", + lua_tostring(L, -1))); + } + } + lua_settop(L, 0); /* clear stack */ + fputs("\n", stdout); + fflush(stdout); + progname = oldprogname; +} + + +static int handle_script (lua_State *L, char **argv, int n) { + int status; + const char *fname; + int narg = getargs(L, argv, n); /* collect arguments */ + lua_setglobal(L, "arg"); + fname = argv[n]; + if (strcmp(fname, "-") == 0 && strcmp(argv[n-1], "--") != 0) + fname = NULL; /* stdin */ + status = luaL_loadfile(L, fname); + lua_insert(L, -(narg+1)); + if (status == 0) + status = docall(L, narg, 0); + else + lua_pop(L, narg); + return report(L, status); +} + + +/* check that argument has no extra characters at the end */ +#define notail(x) {if ((x)[2] != '\0') return -1;} + + +static int collectargs (char **argv, int *pi, int *pv, int *pe) { + int i; + for (i = 1; argv[i] != NULL; i++) { + if (argv[i][0] != '-') /* not an option? */ + return i; + switch (argv[i][1]) { /* option */ + case '-': + notail(argv[i]); + return (argv[i+1] != NULL ? i+1 : 0); + case '\0': + return i; + case 'i': + notail(argv[i]); + *pi = 1; /* go through */ + case 'v': + notail(argv[i]); + *pv = 1; + break; + case 'e': + *pe = 1; /* go through */ + case 'l': + if (argv[i][2] == '\0') { + i++; + if (argv[i] == NULL) return -1; + } + break; + default: return -1; /* invalid option */ + } + } + return 0; +} + + +static int runargs (lua_State *L, char **argv, int n) { + int i; + for (i = 1; i < n; i++) { + if (argv[i] == NULL) continue; + lua_assert(argv[i][0] == '-'); + switch (argv[i][1]) { /* option */ + case 'e': { + const char *chunk = argv[i] + 2; + if (*chunk == '\0') chunk = argv[++i]; + lua_assert(chunk != NULL); + if (dostring(L, chunk, "=(command line)") != 0) + return 1; + break; + } + case 'l': { + const char *filename = argv[i] + 2; + if (*filename == '\0') filename = argv[++i]; + lua_assert(filename != NULL); + if (dolibrary(L, filename)) + return 1; /* stop if file fails */ + break; + } + default: break; + } + } + return 0; +} + + +static int handle_luainit (lua_State *L) { + const char *init = getenv(LUA_INIT); + if (init == NULL) return 0; /* status OK */ + else if (init[0] == '@') + return dofile(L, init+1); + else + return dostring(L, init, "=" LUA_INIT); +} + + +struct Smain { + int argc; + char **argv; + int status; +}; + + +static int pmain (lua_State *L) { + struct Smain *s = (struct Smain *)lua_touserdata(L, 1); + char **argv = s->argv; + int script; + int has_i = 0, has_v = 0, has_e = 0; + globalL = L; + if (argv[0] && argv[0][0]) progname = argv[0]; + lua_gc(L, LUA_GCSTOP, 0); /* stop collector during initialization */ + luaL_openlibs(L); /* open libraries */ + lua_gc(L, LUA_GCRESTART, 0); + s->status = handle_luainit(L); + if (s->status != 0) return 0; + script = collectargs(argv, &has_i, &has_v, &has_e); + if (script < 0) { /* invalid args? */ + print_usage(); + s->status = 1; + return 0; + } + if (has_v) print_version(); + s->status = runargs(L, argv, (script > 0) ? script : s->argc); + if (s->status != 0) return 0; + if (script) + s->status = handle_script(L, argv, script); + if (s->status != 0) return 0; + if (has_i) + dotty(L); + else if (script == 0 && !has_e && !has_v) { + if (lua_stdin_is_tty()) { + print_version(); + dotty(L); + } + else dofile(L, NULL); /* executes stdin as a file */ + } + return 0; +} + + +int main (int argc, char **argv) { + int status; + struct Smain s; + lua_State *L = lua_open(); /* create state */ + if (L == NULL) { + l_message(argv[0], "cannot create state: not enough memory"); + return EXIT_FAILURE; + } + s.argc = argc; + s.argv = argv; + status = lua_cpcall(L, &pmain, &s); + report(L, status); + lua_close(L); + return (status || s.status) ? EXIT_FAILURE : EXIT_SUCCESS; +} + diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lua.h b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lua.h new file mode 100644 index 00000000..e4bdfd3b --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lua.h @@ -0,0 +1,388 @@ +/* +** $Id: lua.h,v 1.218.1.5 2008/08/06 13:30:12 roberto Exp $ +** Lua - An Extensible Extension Language +** Lua.org, PUC-Rio, Brazil (http://www.lua.org) +** See Copyright Notice at the end of this file +*/ + + +#ifndef lua_h +#define lua_h + +#include +#include + + +#include "luaconf.h" + + +#define LUA_VERSION "Lua 5.1" +#define LUA_RELEASE "Lua 5.1.4" +#define LUA_VERSION_NUM 501 +#define LUA_COPYRIGHT "Copyright (C) 1994-2008 Lua.org, PUC-Rio" +#define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo & W. Celes" + + +/* mark for precompiled code (`Lua') */ +#define LUA_SIGNATURE "\033Lua" + +/* option for multiple returns in `lua_pcall' and `lua_call' */ +#define LUA_MULTRET (-1) + + +/* +** pseudo-indices +*/ +#define LUA_REGISTRYINDEX (-10000) +#define LUA_ENVIRONINDEX (-10001) +#define LUA_GLOBALSINDEX (-10002) +#define lua_upvalueindex(i) (LUA_GLOBALSINDEX-(i)) + + +/* thread status; 0 is OK */ +#define LUA_YIELD 1 +#define LUA_ERRRUN 2 +#define LUA_ERRSYNTAX 3 +#define LUA_ERRMEM 4 +#define LUA_ERRERR 5 + + +typedef struct lua_State lua_State; + +typedef int (*lua_CFunction) (lua_State *L); + + +/* +** functions that read/write blocks when loading/dumping Lua chunks +*/ +typedef const char * (*lua_Reader) (lua_State *L, void *ud, size_t *sz); + +typedef int (*lua_Writer) (lua_State *L, const void* p, size_t sz, void* ud); + + +/* +** prototype for memory-allocation functions +*/ +typedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize); + + +/* +** basic types +*/ +#define LUA_TNONE (-1) + +#define LUA_TNIL 0 +#define LUA_TBOOLEAN 1 +#define LUA_TLIGHTUSERDATA 2 +#define LUA_TNUMBER 3 +#define LUA_TSTRING 4 +#define LUA_TTABLE 5 +#define LUA_TFUNCTION 6 +#define LUA_TUSERDATA 7 +#define LUA_TTHREAD 8 + + + +/* minimum Lua stack available to a C function */ +#define LUA_MINSTACK 20 + + +/* +** generic extra include file +*/ +#if defined(LUA_USER_H) +#include LUA_USER_H +#endif + + +/* type of numbers in Lua */ +typedef LUA_NUMBER lua_Number; + + +/* type for integer functions */ +typedef LUA_INTEGER lua_Integer; + + + +/* +** state manipulation +*/ +LUA_API lua_State *(lua_newstate) (lua_Alloc f, void *ud); +LUA_API void (lua_close) (lua_State *L); +LUA_API lua_State *(lua_newthread) (lua_State *L); + +LUA_API lua_CFunction (lua_atpanic) (lua_State *L, lua_CFunction panicf); + + +/* +** basic stack manipulation +*/ +LUA_API int (lua_gettop) (lua_State *L); +LUA_API void (lua_settop) (lua_State *L, int idx); +LUA_API void (lua_pushvalue) (lua_State *L, int idx); +LUA_API void (lua_remove) (lua_State *L, int idx); +LUA_API void (lua_insert) (lua_State *L, int idx); +LUA_API void (lua_replace) (lua_State *L, int idx); +LUA_API int (lua_checkstack) (lua_State *L, int sz); + +LUA_API void (lua_xmove) (lua_State *from, lua_State *to, int n); + + +/* +** access functions (stack -> C) +*/ + +LUA_API int (lua_isnumber) (lua_State *L, int idx); +LUA_API int (lua_isstring) (lua_State *L, int idx); +LUA_API int (lua_iscfunction) (lua_State *L, int idx); +LUA_API int (lua_isuserdata) (lua_State *L, int idx); +LUA_API int (lua_type) (lua_State *L, int idx); +LUA_API const char *(lua_typename) (lua_State *L, int tp); + +LUA_API int (lua_equal) (lua_State *L, int idx1, int idx2); +LUA_API int (lua_rawequal) (lua_State *L, int idx1, int idx2); +LUA_API int (lua_lessthan) (lua_State *L, int idx1, int idx2); + +LUA_API lua_Number (lua_tonumber) (lua_State *L, int idx); +LUA_API lua_Integer (lua_tointeger) (lua_State *L, int idx); +LUA_API int (lua_toboolean) (lua_State *L, int idx); +LUA_API const char *(lua_tolstring) (lua_State *L, int idx, size_t *len); +LUA_API size_t (lua_objlen) (lua_State *L, int idx); +LUA_API lua_CFunction (lua_tocfunction) (lua_State *L, int idx); +LUA_API void *(lua_touserdata) (lua_State *L, int idx); +LUA_API lua_State *(lua_tothread) (lua_State *L, int idx); +LUA_API const void *(lua_topointer) (lua_State *L, int idx); + + +/* +** push functions (C -> stack) +*/ +LUA_API void (lua_pushnil) (lua_State *L); +LUA_API void (lua_pushnumber) (lua_State *L, lua_Number n); +LUA_API void (lua_pushinteger) (lua_State *L, lua_Integer n); +LUA_API void (lua_pushlstring) (lua_State *L, const char *s, size_t l); +LUA_API void (lua_pushstring) (lua_State *L, const char *s); +LUA_API const char *(lua_pushvfstring) (lua_State *L, const char *fmt, + va_list argp); +LUA_API const char *(lua_pushfstring) (lua_State *L, const char *fmt, ...); +LUA_API void (lua_pushcclosure) (lua_State *L, lua_CFunction fn, int n); +LUA_API void (lua_pushboolean) (lua_State *L, int b); +LUA_API void (lua_pushlightuserdata) (lua_State *L, void *p); +LUA_API int (lua_pushthread) (lua_State *L); + + +/* +** get functions (Lua -> stack) +*/ +LUA_API void (lua_gettable) (lua_State *L, int idx); +LUA_API void (lua_getfield) (lua_State *L, int idx, const char *k); +LUA_API void (lua_rawget) (lua_State *L, int idx); +LUA_API void (lua_rawgeti) (lua_State *L, int idx, int n); +LUA_API void (lua_createtable) (lua_State *L, int narr, int nrec); +LUA_API void *(lua_newuserdata) (lua_State *L, size_t sz); +LUA_API int (lua_getmetatable) (lua_State *L, int objindex); +LUA_API void (lua_getfenv) (lua_State *L, int idx); + + +/* +** set functions (stack -> Lua) +*/ +LUA_API void (lua_settable) (lua_State *L, int idx); +LUA_API void (lua_setfield) (lua_State *L, int idx, const char *k); +LUA_API void (lua_rawset) (lua_State *L, int idx); +LUA_API void (lua_rawseti) (lua_State *L, int idx, int n); +LUA_API int (lua_setmetatable) (lua_State *L, int objindex); +LUA_API int (lua_setfenv) (lua_State *L, int idx); + + +/* +** `load' and `call' functions (load and run Lua code) +*/ +LUA_API void (lua_call) (lua_State *L, int nargs, int nresults); +LUA_API int (lua_pcall) (lua_State *L, int nargs, int nresults, int errfunc); +LUA_API int (lua_cpcall) (lua_State *L, lua_CFunction func, void *ud); +LUA_API int (lua_load) (lua_State *L, lua_Reader reader, void *dt, + const char *chunkname); + +LUA_API int (lua_dump) (lua_State *L, lua_Writer writer, void *data); + + +/* +** coroutine functions +*/ +LUA_API int (lua_yield) (lua_State *L, int nresults); +LUA_API int (lua_resume) (lua_State *L, int narg); +LUA_API int (lua_status) (lua_State *L); + +/* +** garbage-collection function and options +*/ + +#define LUA_GCSTOP 0 +#define LUA_GCRESTART 1 +#define LUA_GCCOLLECT 2 +#define LUA_GCCOUNT 3 +#define LUA_GCCOUNTB 4 +#define LUA_GCSTEP 5 +#define LUA_GCSETPAUSE 6 +#define LUA_GCSETSTEPMUL 7 + +LUA_API int (lua_gc) (lua_State *L, int what, int data); + + +/* +** miscellaneous functions +*/ + +LUA_API int (lua_error) (lua_State *L); + +LUA_API int (lua_next) (lua_State *L, int idx); + +LUA_API void (lua_concat) (lua_State *L, int n); + +LUA_API lua_Alloc (lua_getallocf) (lua_State *L, void **ud); +LUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud); + + + +/* +** =============================================================== +** some useful macros +** =============================================================== +*/ + +#define lua_pop(L,n) lua_settop(L, -(n)-1) + +#define lua_newtable(L) lua_createtable(L, 0, 0) + +#define lua_register(L,n,f) (lua_pushcfunction(L, (f)), lua_setglobal(L, (n))) + +#define lua_pushcfunction(L,f) lua_pushcclosure(L, (f), 0) + +#define lua_strlen(L,i) lua_objlen(L, (i)) + +#define lua_isfunction(L,n) (lua_type(L, (n)) == LUA_TFUNCTION) +#define lua_istable(L,n) (lua_type(L, (n)) == LUA_TTABLE) +#define lua_islightuserdata(L,n) (lua_type(L, (n)) == LUA_TLIGHTUSERDATA) +#define lua_isnil(L,n) (lua_type(L, (n)) == LUA_TNIL) +#define lua_isboolean(L,n) (lua_type(L, (n)) == LUA_TBOOLEAN) +#define lua_isthread(L,n) (lua_type(L, (n)) == LUA_TTHREAD) +#define lua_isnone(L,n) (lua_type(L, (n)) == LUA_TNONE) +#define lua_isnoneornil(L, n) (lua_type(L, (n)) <= 0) + +#define lua_pushliteral(L, s) \ + lua_pushlstring(L, "" s, (sizeof(s)/sizeof(char))-1) + +#define lua_setglobal(L,s) lua_setfield(L, LUA_GLOBALSINDEX, (s)) +#define lua_getglobal(L,s) lua_getfield(L, LUA_GLOBALSINDEX, (s)) + +#define lua_tostring(L,i) lua_tolstring(L, (i), NULL) + + + +/* +** compatibility macros and functions +*/ + +#define lua_open() luaL_newstate() + +#define lua_getregistry(L) lua_pushvalue(L, LUA_REGISTRYINDEX) + +#define lua_getgccount(L) lua_gc(L, LUA_GCCOUNT, 0) + +#define lua_Chunkreader lua_Reader +#define lua_Chunkwriter lua_Writer + + +/* hack */ +LUA_API void lua_setlevel (lua_State *from, lua_State *to); + + +/* +** {====================================================================== +** Debug API +** ======================================================================= +*/ + + +/* +** Event codes +*/ +#define LUA_HOOKCALL 0 +#define LUA_HOOKRET 1 +#define LUA_HOOKLINE 2 +#define LUA_HOOKCOUNT 3 +#define LUA_HOOKTAILRET 4 + + +/* +** Event masks +*/ +#define LUA_MASKCALL (1 << LUA_HOOKCALL) +#define LUA_MASKRET (1 << LUA_HOOKRET) +#define LUA_MASKLINE (1 << LUA_HOOKLINE) +#define LUA_MASKCOUNT (1 << LUA_HOOKCOUNT) + +typedef struct lua_Debug lua_Debug; /* activation record */ + + +/* Functions to be called by the debuger in specific events */ +typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar); + + +LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar); +LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar); +LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n); +LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n); +LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n); +LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n); + +LUA_API int lua_sethook (lua_State *L, lua_Hook func, int mask, int count); +LUA_API lua_Hook lua_gethook (lua_State *L); +LUA_API int lua_gethookmask (lua_State *L); +LUA_API int lua_gethookcount (lua_State *L); + + +struct lua_Debug { + int event; + const char *name; /* (n) */ + const char *namewhat; /* (n) `global', `local', `field', `method' */ + const char *what; /* (S) `Lua', `C', `main', `tail' */ + const char *source; /* (S) */ + int currentline; /* (l) */ + int nups; /* (u) number of upvalues */ + int linedefined; /* (S) */ + int lastlinedefined; /* (S) */ + char short_src[LUA_IDSIZE]; /* (S) */ + /* private part */ + int i_ci; /* active function */ +}; + +/* }====================================================================== */ + + +/****************************************************************************** +* Copyright (C) 1994-2008 Lua.org, PUC-Rio. All rights reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining +* a copy of this software and associated documentation files (the +* "Software"), to deal in the Software without restriction, including +* without limitation the rights to use, copy, modify, merge, publish, +* distribute, sublicense, and/or sell copies of the Software, and to +* permit persons to whom the Software is furnished to do so, subject to +* the following conditions: +* +* The above copyright notice and this permission notice shall be +* included in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +******************************************************************************/ + + +#endif diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/luac.c b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/luac.c new file mode 100644 index 00000000..d0701739 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/luac.c @@ -0,0 +1,200 @@ +/* +** $Id: luac.c,v 1.54 2006/06/02 17:37:11 lhf Exp $ +** Lua compiler (saves bytecodes to files; also list bytecodes) +** See Copyright Notice in lua.h +*/ + +#include +#include +#include +#include + +#define luac_c +#define LUA_CORE + +#include "lua.h" +#include "lauxlib.h" + +#include "ldo.h" +#include "lfunc.h" +#include "lmem.h" +#include "lobject.h" +#include "lopcodes.h" +#include "lstring.h" +#include "lundump.h" + +#define PROGNAME "luac" /* default program name */ +#define OUTPUT PROGNAME ".out" /* default output file */ + +static int listing=0; /* list bytecodes? */ +static int dumping=1; /* dump bytecodes? */ +static int stripping=0; /* strip debug information? */ +static char Output[]={ OUTPUT }; /* default output file name */ +static const char* output=Output; /* actual output file name */ +static const char* progname=PROGNAME; /* actual program name */ + +static void fatal(const char* message) +{ + fprintf(stderr,"%s: %s\n",progname,message); + exit(EXIT_FAILURE); +} + +static void cannot(const char* what) +{ + fprintf(stderr,"%s: cannot %s %s: %s\n",progname,what,output,strerror(errno)); + exit(EXIT_FAILURE); +} + +static void usage(const char* message) +{ + if (*message=='-') + fprintf(stderr,"%s: unrecognized option " LUA_QS "\n",progname,message); + else + fprintf(stderr,"%s: %s\n",progname,message); + fprintf(stderr, + "usage: %s [options] [filenames].\n" + "Available options are:\n" + " - process stdin\n" + " -l list\n" + " -o name output to file " LUA_QL("name") " (default is \"%s\")\n" + " -p parse only\n" + " -s strip debug information\n" + " -v show version information\n" + " -- stop handling options\n", + progname,Output); + exit(EXIT_FAILURE); +} + +#define IS(s) (strcmp(argv[i],s)==0) + +static int doargs(int argc, char* argv[]) +{ + int i; + int version=0; + if (argv[0]!=NULL && *argv[0]!=0) progname=argv[0]; + for (i=1; itop+(i))->l.p) + +static const Proto* combine(lua_State* L, int n) +{ + if (n==1) + return toproto(L,-1); + else + { + int i,pc; + Proto* f=luaF_newproto(L); + setptvalue2s(L,L->top,f); incr_top(L); + f->source=luaS_newliteral(L,"=(" PROGNAME ")"); + f->maxstacksize=1; + pc=2*n+1; + f->code=luaM_newvector(L,pc,Instruction); + f->sizecode=pc; + f->p=luaM_newvector(L,n,Proto*); + f->sizep=n; + pc=0; + for (i=0; ip[i]=toproto(L,i-n-1); + f->code[pc++]=CREATE_ABx(OP_CLOSURE,0,i); + f->code[pc++]=CREATE_ABC(OP_CALL,0,1,1); + } + f->code[pc++]=CREATE_ABC(OP_RETURN,0,1,0); + return f; + } +} + +static int writer(lua_State* L, const void* p, size_t size, void* u) +{ + UNUSED(L); + return (fwrite(p,size,1,(FILE*)u)!=1) && (size!=0); +} + +struct Smain { + int argc; + char** argv; +}; + +static int pmain(lua_State* L) +{ + struct Smain* s = (struct Smain*)lua_touserdata(L, 1); + int argc=s->argc; + char** argv=s->argv; + const Proto* f; + int i; + if (!lua_checkstack(L,argc)) fatal("too many input files"); + for (i=0; i1); + if (dumping) + { + FILE* D= (output==NULL) ? stdout : fopen(output,"wb"); + if (D==NULL) cannot("open"); + lua_lock(L); + luaU_dump(L,f,writer,D,stripping); + lua_unlock(L); + if (ferror(D)) cannot("write"); + if (fclose(D)) cannot("close"); + } + return 0; +} + +int main(int argc, char* argv[]) +{ + lua_State* L; + struct Smain s; + int i=doargs(argc,argv); + argc-=i; argv+=i; + if (argc<=0) usage("no input files given"); + L=lua_open(); + if (L==NULL) fatal("not enough memory for state"); + s.argc=argc; + s.argv=argv; + if (lua_cpcall(L,pmain,&s)!=0) fatal(lua_tostring(L,-1)); + lua_close(L); + return EXIT_SUCCESS; +} diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/luaconf.h b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/luaconf.h new file mode 100644 index 00000000..bec30482 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/luaconf.h @@ -0,0 +1,763 @@ +/* +** $Id: luaconf.h,v 1.82.1.7 2008/02/11 16:25:08 roberto Exp $ +** Configuration file for Lua +** See Copyright Notice in lua.h +*/ + + +#ifndef lconfig_h +#define lconfig_h + +#include +#include + + +/* +** ================================================================== +** Search for "@@" to find all configurable definitions. +** =================================================================== +*/ + + +/* +@@ LUA_ANSI controls the use of non-ansi features. +** CHANGE it (define it) if you want Lua to avoid the use of any +** non-ansi feature or library. +*/ +#if defined(__STRICT_ANSI__) +#define LUA_ANSI +#endif + + +#if !defined(LUA_ANSI) && defined(_WIN32) +#define LUA_WIN +#endif + +#if defined(LUA_USE_LINUX) +#define LUA_USE_POSIX +#define LUA_USE_DLOPEN /* needs an extra library: -ldl */ +#define LUA_USE_READLINE /* needs some extra libraries */ +#endif + +#if defined(LUA_USE_MACOSX) +#define LUA_USE_POSIX +#define LUA_DL_DYLD /* does not need extra library */ +#endif + + + +/* +@@ LUA_USE_POSIX includes all functionallity listed as X/Open System +@* Interfaces Extension (XSI). +** CHANGE it (define it) if your system is XSI compatible. +*/ +#if defined(LUA_USE_POSIX) +#define LUA_USE_MKSTEMP +#define LUA_USE_ISATTY +#define LUA_USE_POPEN +#define LUA_USE_ULONGJMP +#endif + + +/* +@@ LUA_PATH and LUA_CPATH are the names of the environment variables that +@* Lua check to set its paths. +@@ LUA_INIT is the name of the environment variable that Lua +@* checks for initialization code. +** CHANGE them if you want different names. +*/ +#define LUA_PATH "LUA_PATH" +#define LUA_CPATH "LUA_CPATH" +#define LUA_INIT "LUA_INIT" + + +/* +@@ LUA_PATH_DEFAULT is the default path that Lua uses to look for +@* Lua libraries. +@@ LUA_CPATH_DEFAULT is the default path that Lua uses to look for +@* C libraries. +** CHANGE them if your machine has a non-conventional directory +** hierarchy or if you want to install your libraries in +** non-conventional directories. +*/ +#if defined(_WIN32) +/* +** In Windows, any exclamation mark ('!') in the path is replaced by the +** path of the directory of the executable file of the current process. +*/ +#define LUA_LDIR "!\\lua\\" +#define LUA_CDIR "!\\" +#define LUA_PATH_DEFAULT \ + ".\\?.lua;" LUA_LDIR"?.lua;" LUA_LDIR"?\\init.lua;" \ + LUA_CDIR"?.lua;" LUA_CDIR"?\\init.lua" +#define LUA_CPATH_DEFAULT \ + ".\\?.dll;" LUA_CDIR"?.dll;" LUA_CDIR"loadall.dll" + +#else +#define LUA_ROOT "/usr/local/" +#define LUA_LDIR LUA_ROOT "share/lua/5.1/" +#define LUA_CDIR LUA_ROOT "lib/lua/5.1/" +#define LUA_PATH_DEFAULT \ + "./?.lua;" LUA_LDIR"?.lua;" LUA_LDIR"?/init.lua;" \ + LUA_CDIR"?.lua;" LUA_CDIR"?/init.lua" +#define LUA_CPATH_DEFAULT \ + "./?.so;" LUA_CDIR"?.so;" LUA_CDIR"loadall.so" +#endif + + +/* +@@ LUA_DIRSEP is the directory separator (for submodules). +** CHANGE it if your machine does not use "/" as the directory separator +** and is not Windows. (On Windows Lua automatically uses "\".) +*/ +#if defined(_WIN32) +#define LUA_DIRSEP "\\" +#else +#define LUA_DIRSEP "/" +#endif + + +/* +@@ LUA_PATHSEP is the character that separates templates in a path. +@@ LUA_PATH_MARK is the string that marks the substitution points in a +@* template. +@@ LUA_EXECDIR in a Windows path is replaced by the executable's +@* directory. +@@ LUA_IGMARK is a mark to ignore all before it when bulding the +@* luaopen_ function name. +** CHANGE them if for some reason your system cannot use those +** characters. (E.g., if one of those characters is a common character +** in file/directory names.) Probably you do not need to change them. +*/ +#define LUA_PATHSEP ";" +#define LUA_PATH_MARK "?" +#define LUA_EXECDIR "!" +#define LUA_IGMARK "-" + + +/* +@@ LUA_INTEGER is the integral type used by lua_pushinteger/lua_tointeger. +** CHANGE that if ptrdiff_t is not adequate on your machine. (On most +** machines, ptrdiff_t gives a good choice between int or long.) +*/ +#define LUA_INTEGER ptrdiff_t + + +/* +@@ LUA_API is a mark for all core API functions. +@@ LUALIB_API is a mark for all standard library functions. +** CHANGE them if you need to define those functions in some special way. +** For instance, if you want to create one Windows DLL with the core and +** the libraries, you may want to use the following definition (define +** LUA_BUILD_AS_DLL to get it). +*/ +#if defined(LUA_BUILD_AS_DLL) + +#if defined(LUA_CORE) || defined(LUA_LIB) +#define LUA_API __declspec(dllexport) +#else +#define LUA_API __declspec(dllimport) +#endif + +#else + +#define LUA_API extern + +#endif + +/* more often than not the libs go together with the core */ +#define LUALIB_API LUA_API + + +/* +@@ LUAI_FUNC is a mark for all extern functions that are not to be +@* exported to outside modules. +@@ LUAI_DATA is a mark for all extern (const) variables that are not to +@* be exported to outside modules. +** CHANGE them if you need to mark them in some special way. Elf/gcc +** (versions 3.2 and later) mark them as "hidden" to optimize access +** when Lua is compiled as a shared library. +*/ +#if defined(luaall_c) +#define LUAI_FUNC static +#define LUAI_DATA /* empty */ + +#elif defined(__GNUC__) && ((__GNUC__*100 + __GNUC_MINOR__) >= 302) && \ + defined(__ELF__) +#define LUAI_FUNC __attribute__((visibility("hidden"))) extern +#define LUAI_DATA LUAI_FUNC + +#else +#define LUAI_FUNC extern +#define LUAI_DATA extern +#endif + + + +/* +@@ LUA_QL describes how error messages quote program elements. +** CHANGE it if you want a different appearance. +*/ +#define LUA_QL(x) "'" x "'" +#define LUA_QS LUA_QL("%s") + + +/* +@@ LUA_IDSIZE gives the maximum size for the description of the source +@* of a function in debug information. +** CHANGE it if you want a different size. +*/ +#define LUA_IDSIZE 256 + + +/* +** {================================================================== +** Stand-alone configuration +** =================================================================== +*/ + +#if defined(lua_c) || defined(luaall_c) + +/* +@@ lua_stdin_is_tty detects whether the standard input is a 'tty' (that +@* is, whether we're running lua interactively). +** CHANGE it if you have a better definition for non-POSIX/non-Windows +** systems. +*/ +#if defined(LUA_USE_ISATTY) +#include +#define lua_stdin_is_tty() isatty(0) +#elif defined(LUA_WIN) +#include +#include +#define lua_stdin_is_tty() _isatty(_fileno(stdin)) +#else +#define lua_stdin_is_tty() 1 /* assume stdin is a tty */ +#endif + + +/* +@@ LUA_PROMPT is the default prompt used by stand-alone Lua. +@@ LUA_PROMPT2 is the default continuation prompt used by stand-alone Lua. +** CHANGE them if you want different prompts. (You can also change the +** prompts dynamically, assigning to globals _PROMPT/_PROMPT2.) +*/ +#define LUA_PROMPT "> " +#define LUA_PROMPT2 ">> " + + +/* +@@ LUA_PROGNAME is the default name for the stand-alone Lua program. +** CHANGE it if your stand-alone interpreter has a different name and +** your system is not able to detect that name automatically. +*/ +#define LUA_PROGNAME "lua" + + +/* +@@ LUA_MAXINPUT is the maximum length for an input line in the +@* stand-alone interpreter. +** CHANGE it if you need longer lines. +*/ +#define LUA_MAXINPUT 512 + + +/* +@@ lua_readline defines how to show a prompt and then read a line from +@* the standard input. +@@ lua_saveline defines how to "save" a read line in a "history". +@@ lua_freeline defines how to free a line read by lua_readline. +** CHANGE them if you want to improve this functionality (e.g., by using +** GNU readline and history facilities). +*/ +#if defined(LUA_USE_READLINE) +#include +#include +#include +#define lua_readline(L,b,p) ((void)L, ((b)=readline(p)) != NULL) +#define lua_saveline(L,idx) \ + if (lua_strlen(L,idx) > 0) /* non-empty line? */ \ + add_history(lua_tostring(L, idx)); /* add it to history */ +#define lua_freeline(L,b) ((void)L, free(b)) +#else +#define lua_readline(L,b,p) \ + ((void)L, fputs(p, stdout), fflush(stdout), /* show prompt */ \ + fgets(b, LUA_MAXINPUT, stdin) != NULL) /* get line */ +#define lua_saveline(L,idx) { (void)L; (void)idx; } +#define lua_freeline(L,b) { (void)L; (void)b; } +#endif + +#endif + +/* }================================================================== */ + + +/* +@@ LUAI_GCPAUSE defines the default pause between garbage-collector cycles +@* as a percentage. +** CHANGE it if you want the GC to run faster or slower (higher values +** mean larger pauses which mean slower collection.) You can also change +** this value dynamically. +*/ +#define LUAI_GCPAUSE 200 /* 200% (wait memory to double before next GC) */ + + +/* +@@ LUAI_GCMUL defines the default speed of garbage collection relative to +@* memory allocation as a percentage. +** CHANGE it if you want to change the granularity of the garbage +** collection. (Higher values mean coarser collections. 0 represents +** infinity, where each step performs a full collection.) You can also +** change this value dynamically. +*/ +#define LUAI_GCMUL 200 /* GC runs 'twice the speed' of memory allocation */ + + + +/* +@@ LUA_COMPAT_GETN controls compatibility with old getn behavior. +** CHANGE it (define it) if you want exact compatibility with the +** behavior of setn/getn in Lua 5.0. +*/ +#undef LUA_COMPAT_GETN + +/* +@@ LUA_COMPAT_LOADLIB controls compatibility about global loadlib. +** CHANGE it to undefined as soon as you do not need a global 'loadlib' +** function (the function is still available as 'package.loadlib'). +*/ +#undef LUA_COMPAT_LOADLIB + +/* +@@ LUA_COMPAT_VARARG controls compatibility with old vararg feature. +** CHANGE it to undefined as soon as your programs use only '...' to +** access vararg parameters (instead of the old 'arg' table). +*/ +#define LUA_COMPAT_VARARG + +/* +@@ LUA_COMPAT_MOD controls compatibility with old math.mod function. +** CHANGE it to undefined as soon as your programs use 'math.fmod' or +** the new '%' operator instead of 'math.mod'. +*/ +#define LUA_COMPAT_MOD + +/* +@@ LUA_COMPAT_LSTR controls compatibility with old long string nesting +@* facility. +** CHANGE it to 2 if you want the old behaviour, or undefine it to turn +** off the advisory error when nesting [[...]]. +*/ +#define LUA_COMPAT_LSTR 1 + +/* +@@ LUA_COMPAT_GFIND controls compatibility with old 'string.gfind' name. +** CHANGE it to undefined as soon as you rename 'string.gfind' to +** 'string.gmatch'. +*/ +#define LUA_COMPAT_GFIND + +/* +@@ LUA_COMPAT_OPENLIB controls compatibility with old 'luaL_openlib' +@* behavior. +** CHANGE it to undefined as soon as you replace to 'luaL_register' +** your uses of 'luaL_openlib' +*/ +#define LUA_COMPAT_OPENLIB + + + +/* +@@ luai_apicheck is the assert macro used by the Lua-C API. +** CHANGE luai_apicheck if you want Lua to perform some checks in the +** parameters it gets from API calls. This may slow down the interpreter +** a bit, but may be quite useful when debugging C code that interfaces +** with Lua. A useful redefinition is to use assert.h. +*/ +#if defined(LUA_USE_APICHECK) +#include +#define luai_apicheck(L,o) { (void)L; assert(o); } +#else +#define luai_apicheck(L,o) { (void)L; } +#endif + + +/* +@@ LUAI_BITSINT defines the number of bits in an int. +** CHANGE here if Lua cannot automatically detect the number of bits of +** your machine. Probably you do not need to change this. +*/ +/* avoid overflows in comparison */ +#if INT_MAX-20 < 32760 +#define LUAI_BITSINT 16 +#elif INT_MAX > 2147483640L +/* int has at least 32 bits */ +#define LUAI_BITSINT 32 +#else +#error "you must define LUA_BITSINT with number of bits in an integer" +#endif + + +/* +@@ LUAI_UINT32 is an unsigned integer with at least 32 bits. +@@ LUAI_INT32 is an signed integer with at least 32 bits. +@@ LUAI_UMEM is an unsigned integer big enough to count the total +@* memory used by Lua. +@@ LUAI_MEM is a signed integer big enough to count the total memory +@* used by Lua. +** CHANGE here if for some weird reason the default definitions are not +** good enough for your machine. (The definitions in the 'else' +** part always works, but may waste space on machines with 64-bit +** longs.) Probably you do not need to change this. +*/ +#if LUAI_BITSINT >= 32 +#define LUAI_UINT32 unsigned int +#define LUAI_INT32 int +#define LUAI_MAXINT32 INT_MAX +#define LUAI_UMEM size_t +#define LUAI_MEM ptrdiff_t +#else +/* 16-bit ints */ +#define LUAI_UINT32 unsigned long +#define LUAI_INT32 long +#define LUAI_MAXINT32 LONG_MAX +#define LUAI_UMEM unsigned long +#define LUAI_MEM long +#endif + + +/* +@@ LUAI_MAXCALLS limits the number of nested calls. +** CHANGE it if you need really deep recursive calls. This limit is +** arbitrary; its only purpose is to stop infinite recursion before +** exhausting memory. +*/ +#define LUAI_MAXCALLS 20000 + + +/* +@@ LUAI_MAXCSTACK limits the number of Lua stack slots that a C function +@* can use. +** CHANGE it if you need lots of (Lua) stack space for your C +** functions. This limit is arbitrary; its only purpose is to stop C +** functions to consume unlimited stack space. (must be smaller than +** -LUA_REGISTRYINDEX) +*/ +#define LUAI_MAXCSTACK 8000 + + + +/* +** {================================================================== +** CHANGE (to smaller values) the following definitions if your system +** has a small C stack. (Or you may want to change them to larger +** values if your system has a large C stack and these limits are +** too rigid for you.) Some of these constants control the size of +** stack-allocated arrays used by the compiler or the interpreter, while +** others limit the maximum number of recursive calls that the compiler +** or the interpreter can perform. Values too large may cause a C stack +** overflow for some forms of deep constructs. +** =================================================================== +*/ + + +/* +@@ LUAI_MAXCCALLS is the maximum depth for nested C calls (short) and +@* syntactical nested non-terminals in a program. +*/ +#define LUAI_MAXCCALLS 200 + + +/* +@@ LUAI_MAXVARS is the maximum number of local variables per function +@* (must be smaller than 250). +*/ +#define LUAI_MAXVARS 200 + + +/* +@@ LUAI_MAXUPVALUES is the maximum number of upvalues per function +@* (must be smaller than 250). +*/ +#define LUAI_MAXUPVALUES 60 + + +/* +@@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system. +*/ +#define LUAL_BUFFERSIZE BUFSIZ + +/* }================================================================== */ + + + + +/* +** {================================================================== +@@ LUA_NUMBER is the type of numbers in Lua. +** CHANGE the following definitions only if you want to build Lua +** with a number type different from double. You may also need to +** change lua_number2int & lua_number2integer. +** =================================================================== +*/ + +#define LUA_NUMBER_DOUBLE +#define LUA_NUMBER double + +/* +@@ LUAI_UACNUMBER is the result of an 'usual argument conversion' +@* over a number. +*/ +#define LUAI_UACNUMBER double + + +/* +@@ LUA_NUMBER_SCAN is the format for reading numbers. +@@ LUA_NUMBER_FMT is the format for writing numbers. +@@ lua_number2str converts a number to a string. +@@ LUAI_MAXNUMBER2STR is maximum size of previous conversion. +@@ lua_str2number converts a string to a number. +*/ +#define LUA_NUMBER_SCAN "%lf" +#define LUA_NUMBER_FMT "%.14g" +#define lua_number2str(s,n) sprintf((s), LUA_NUMBER_FMT, (n)) +#define LUAI_MAXNUMBER2STR 32 /* 16 digits, sign, point, and \0 */ +#define lua_str2number(s,p) strtod((s), (p)) + + +/* +@@ The luai_num* macros define the primitive operations over numbers. +*/ +#if defined(LUA_CORE) +#include +#define luai_numadd(a,b) ((a)+(b)) +#define luai_numsub(a,b) ((a)-(b)) +#define luai_nummul(a,b) ((a)*(b)) +#define luai_numdiv(a,b) ((a)/(b)) +#define luai_nummod(a,b) ((a) - floor((a)/(b))*(b)) +#define luai_numpow(a,b) (pow(a,b)) +#define luai_numunm(a) (-(a)) +#define luai_numeq(a,b) ((a)==(b)) +#define luai_numlt(a,b) ((a)<(b)) +#define luai_numle(a,b) ((a)<=(b)) +#define luai_numisnan(a) (!luai_numeq((a), (a))) +#endif + + +/* +@@ lua_number2int is a macro to convert lua_Number to int. +@@ lua_number2integer is a macro to convert lua_Number to lua_Integer. +** CHANGE them if you know a faster way to convert a lua_Number to +** int (with any rounding method and without throwing errors) in your +** system. In Pentium machines, a naive typecast from double to int +** in C is extremely slow, so any alternative is worth trying. +*/ + +/* On a Pentium, resort to a trick */ +#if defined(LUA_NUMBER_DOUBLE) && !defined(LUA_ANSI) && !defined(__SSE2__) && \ + (defined(__i386) || defined (_M_IX86) || defined(__i386__)) + +/* On a Microsoft compiler, use assembler */ +#if defined(_MSC_VER) + +#define lua_number2int(i,d) __asm fld d __asm fistp i +#define lua_number2integer(i,n) lua_number2int(i, n) + +/* the next trick should work on any Pentium, but sometimes clashes + with a DirectX idiosyncrasy */ +#else + +union luai_Cast { double l_d; long l_l; }; +#define lua_number2int(i,d) \ + { volatile union luai_Cast u; u.l_d = (d) + 6755399441055744.0; (i) = u.l_l; } +#define lua_number2integer(i,n) lua_number2int(i, n) + +#endif + + +/* this option always works, but may be slow */ +#else +#define lua_number2int(i,d) ((i)=(int)(d)) +#define lua_number2integer(i,d) ((i)=(lua_Integer)(d)) + +#endif + +/* }================================================================== */ + + +/* +@@ LUAI_USER_ALIGNMENT_T is a type that requires maximum alignment. +** CHANGE it if your system requires alignments larger than double. (For +** instance, if your system supports long doubles and they must be +** aligned in 16-byte boundaries, then you should add long double in the +** union.) Probably you do not need to change this. +*/ +#define LUAI_USER_ALIGNMENT_T union { double u; void *s; long l; } + + +/* +@@ LUAI_THROW/LUAI_TRY define how Lua does exception handling. +** CHANGE them if you prefer to use longjmp/setjmp even with C++ +** or if want/don't to use _longjmp/_setjmp instead of regular +** longjmp/setjmp. By default, Lua handles errors with exceptions when +** compiling as C++ code, with _longjmp/_setjmp when asked to use them, +** and with longjmp/setjmp otherwise. +*/ +#if defined(__cplusplus) +/* C++ exceptions */ +#define LUAI_THROW(L,c) throw(c) +#define LUAI_TRY(L,c,a) try { a } catch(...) \ + { if ((c)->status == 0) (c)->status = -1; } +#define luai_jmpbuf int /* dummy variable */ + +#elif defined(LUA_USE_ULONGJMP) +/* in Unix, try _longjmp/_setjmp (more efficient) */ +#define LUAI_THROW(L,c) _longjmp((c)->b, 1) +#define LUAI_TRY(L,c,a) if (_setjmp((c)->b) == 0) { a } +#define luai_jmpbuf jmp_buf + +#else +/* default handling with long jumps */ +#define LUAI_THROW(L,c) longjmp((c)->b, 1) +#define LUAI_TRY(L,c,a) if (setjmp((c)->b) == 0) { a } +#define luai_jmpbuf jmp_buf + +#endif + + +/* +@@ LUA_MAXCAPTURES is the maximum number of captures that a pattern +@* can do during pattern-matching. +** CHANGE it if you need more captures. This limit is arbitrary. +*/ +#define LUA_MAXCAPTURES 32 + + +/* +@@ lua_tmpnam is the function that the OS library uses to create a +@* temporary name. +@@ LUA_TMPNAMBUFSIZE is the maximum size of a name created by lua_tmpnam. +** CHANGE them if you have an alternative to tmpnam (which is considered +** insecure) or if you want the original tmpnam anyway. By default, Lua +** uses tmpnam except when POSIX is available, where it uses mkstemp. +*/ +#if defined(loslib_c) || defined(luaall_c) + +#if defined(LUA_USE_MKSTEMP) +#include +#define LUA_TMPNAMBUFSIZE 32 +#define lua_tmpnam(b,e) { \ + strcpy(b, "/tmp/lua_XXXXXX"); \ + e = mkstemp(b); \ + if (e != -1) close(e); \ + e = (e == -1); } + +#else +#define LUA_TMPNAMBUFSIZE L_tmpnam +#define lua_tmpnam(b,e) { e = (tmpnam(b) == NULL); } +#endif + +#endif + + +/* +@@ lua_popen spawns a new process connected to the current one through +@* the file streams. +** CHANGE it if you have a way to implement it in your system. +*/ +#if defined(LUA_USE_POPEN) + +#define lua_popen(L,c,m) ((void)L, fflush(NULL), popen(c,m)) +#define lua_pclose(L,file) ((void)L, (pclose(file) != -1)) + +#elif defined(LUA_WIN) + +#define lua_popen(L,c,m) ((void)L, _popen(c,m)) +#define lua_pclose(L,file) ((void)L, (_pclose(file) != -1)) + +#else + +#define lua_popen(L,c,m) ((void)((void)c, m), \ + luaL_error(L, LUA_QL("popen") " not supported"), (FILE*)0) +#define lua_pclose(L,file) ((void)((void)L, file), 0) + +#endif + +/* +@@ LUA_DL_* define which dynamic-library system Lua should use. +** CHANGE here if Lua has problems choosing the appropriate +** dynamic-library system for your platform (either Windows' DLL, Mac's +** dyld, or Unix's dlopen). If your system is some kind of Unix, there +** is a good chance that it has dlopen, so LUA_DL_DLOPEN will work for +** it. To use dlopen you also need to adapt the src/Makefile (probably +** adding -ldl to the linker options), so Lua does not select it +** automatically. (When you change the makefile to add -ldl, you must +** also add -DLUA_USE_DLOPEN.) +** If you do not want any kind of dynamic library, undefine all these +** options. +** By default, _WIN32 gets LUA_DL_DLL and MAC OS X gets LUA_DL_DYLD. +*/ +#if defined(LUA_USE_DLOPEN) +#define LUA_DL_DLOPEN +#endif + +#if defined(LUA_WIN) +#define LUA_DL_DLL +#endif + + +/* +@@ LUAI_EXTRASPACE allows you to add user-specific data in a lua_State +@* (the data goes just *before* the lua_State pointer). +** CHANGE (define) this if you really need that. This value must be +** a multiple of the maximum alignment required for your machine. +*/ +#define LUAI_EXTRASPACE 0 + + +/* +@@ luai_userstate* allow user-specific actions on threads. +** CHANGE them if you defined LUAI_EXTRASPACE and need to do something +** extra when a thread is created/deleted/resumed/yielded. +*/ +#define luai_userstateopen(L) ((void)L) +#define luai_userstateclose(L) ((void)L) +#define luai_userstatethread(L,L1) ((void)L) +#define luai_userstatefree(L) ((void)L) +#define luai_userstateresume(L,n) ((void)L) +#define luai_userstateyield(L,n) ((void)L) + + +/* +@@ LUA_INTFRMLEN is the length modifier for integer conversions +@* in 'string.format'. +@@ LUA_INTFRM_T is the integer type correspoding to the previous length +@* modifier. +** CHANGE them if your system supports long long or does not support long. +*/ + +#if defined(LUA_USELONGLONG) + +#define LUA_INTFRMLEN "ll" +#define LUA_INTFRM_T long long + +#else + +#define LUA_INTFRMLEN "l" +#define LUA_INTFRM_T long + +#endif + + + +/* =================================================================== */ + +/* +** Local configuration. You can use this space to add your redefinitions +** without modifying the main part of the file. +*/ + + + +#endif + diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lualib.h b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lualib.h new file mode 100644 index 00000000..469417f6 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lualib.h @@ -0,0 +1,53 @@ +/* +** $Id: lualib.h,v 1.36.1.1 2007/12/27 13:02:25 roberto Exp $ +** Lua standard libraries +** See Copyright Notice in lua.h +*/ + + +#ifndef lualib_h +#define lualib_h + +#include "lua.h" + + +/* Key to file-handle type */ +#define LUA_FILEHANDLE "FILE*" + + +#define LUA_COLIBNAME "coroutine" +LUALIB_API int (luaopen_base) (lua_State *L); + +#define LUA_TABLIBNAME "table" +LUALIB_API int (luaopen_table) (lua_State *L); + +#define LUA_IOLIBNAME "io" +LUALIB_API int (luaopen_io) (lua_State *L); + +#define LUA_OSLIBNAME "os" +LUALIB_API int (luaopen_os) (lua_State *L); + +#define LUA_STRLIBNAME "string" +LUALIB_API int (luaopen_string) (lua_State *L); + +#define LUA_MATHLIBNAME "math" +LUALIB_API int (luaopen_math) (lua_State *L); + +#define LUA_DBLIBNAME "debug" +LUALIB_API int (luaopen_debug) (lua_State *L); + +#define LUA_LOADLIBNAME "package" +LUALIB_API int (luaopen_package) (lua_State *L); + + +/* open all previous libraries */ +LUALIB_API void (luaL_openlibs) (lua_State *L); + + + +#ifndef lua_assert +#define lua_assert(x) ((void)0) +#endif + + +#endif diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lundump.c b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lundump.c new file mode 100644 index 00000000..8010a457 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lundump.c @@ -0,0 +1,227 @@ +/* +** $Id: lundump.c,v 2.7.1.4 2008/04/04 19:51:41 roberto Exp $ +** load precompiled Lua chunks +** See Copyright Notice in lua.h +*/ + +#include + +#define lundump_c +#define LUA_CORE + +#include "lua.h" + +#include "ldebug.h" +#include "ldo.h" +#include "lfunc.h" +#include "lmem.h" +#include "lobject.h" +#include "lstring.h" +#include "lundump.h" +#include "lzio.h" + +typedef struct { + lua_State* L; + ZIO* Z; + Mbuffer* b; + const char* name; +} LoadState; + +#ifdef LUAC_TRUST_BINARIES +#define IF(c,s) +#define error(S,s) +#else +#define IF(c,s) if (c) error(S,s) + +static void error(LoadState* S, const char* why) +{ + luaO_pushfstring(S->L,"%s: %s in precompiled chunk",S->name,why); + luaD_throw(S->L,LUA_ERRSYNTAX); +} +#endif + +#define LoadMem(S,b,n,size) LoadBlock(S,b,(n)*(size)) +#define LoadByte(S) (lu_byte)LoadChar(S) +#define LoadVar(S,x) LoadMem(S,&x,1,sizeof(x)) +#define LoadVector(S,b,n,size) LoadMem(S,b,n,size) + +static void LoadBlock(LoadState* S, void* b, size_t size) +{ + size_t r=luaZ_read(S->Z,b,size); + IF (r!=0, "unexpected end"); +} + +static int LoadChar(LoadState* S) +{ + char x; + LoadVar(S,x); + return x; +} + +static int LoadInt(LoadState* S) +{ + int x; + LoadVar(S,x); + IF (x<0, "bad integer"); + return x; +} + +static lua_Number LoadNumber(LoadState* S) +{ + lua_Number x; + LoadVar(S,x); + return x; +} + +static TString* LoadString(LoadState* S) +{ + size_t size; + LoadVar(S,size); + if (size==0) + return NULL; + else + { + char* s=luaZ_openspace(S->L,S->b,size); + LoadBlock(S,s,size); + return luaS_newlstr(S->L,s,size-1); /* remove trailing '\0' */ + } +} + +static void LoadCode(LoadState* S, Proto* f) +{ + int n=LoadInt(S); + f->code=luaM_newvector(S->L,n,Instruction); + f->sizecode=n; + LoadVector(S,f->code,n,sizeof(Instruction)); +} + +static Proto* LoadFunction(LoadState* S, TString* p); + +static void LoadConstants(LoadState* S, Proto* f) +{ + int i,n; + n=LoadInt(S); + f->k=luaM_newvector(S->L,n,TValue); + f->sizek=n; + for (i=0; ik[i]); + for (i=0; ik[i]; + int t=LoadChar(S); + switch (t) + { + case LUA_TNIL: + setnilvalue(o); + break; + case LUA_TBOOLEAN: + setbvalue(o,LoadChar(S)!=0); + break; + case LUA_TNUMBER: + setnvalue(o,LoadNumber(S)); + break; + case LUA_TSTRING: + setsvalue2n(S->L,o,LoadString(S)); + break; + default: + error(S,"bad constant"); + break; + } + } + n=LoadInt(S); + f->p=luaM_newvector(S->L,n,Proto*); + f->sizep=n; + for (i=0; ip[i]=NULL; + for (i=0; ip[i]=LoadFunction(S,f->source); +} + +static void LoadDebug(LoadState* S, Proto* f) +{ + int i,n; + n=LoadInt(S); + f->lineinfo=luaM_newvector(S->L,n,int); + f->sizelineinfo=n; + LoadVector(S,f->lineinfo,n,sizeof(int)); + n=LoadInt(S); + f->locvars=luaM_newvector(S->L,n,LocVar); + f->sizelocvars=n; + for (i=0; ilocvars[i].varname=NULL; + for (i=0; ilocvars[i].varname=LoadString(S); + f->locvars[i].startpc=LoadInt(S); + f->locvars[i].endpc=LoadInt(S); + } + n=LoadInt(S); + f->upvalues=luaM_newvector(S->L,n,TString*); + f->sizeupvalues=n; + for (i=0; iupvalues[i]=NULL; + for (i=0; iupvalues[i]=LoadString(S); +} + +static Proto* LoadFunction(LoadState* S, TString* p) +{ + Proto* f; + if (++S->L->nCcalls > LUAI_MAXCCALLS) error(S,"code too deep"); + f=luaF_newproto(S->L); + setptvalue2s(S->L,S->L->top,f); incr_top(S->L); + f->source=LoadString(S); if (f->source==NULL) f->source=p; + f->linedefined=LoadInt(S); + f->lastlinedefined=LoadInt(S); + f->nups=LoadByte(S); + f->numparams=LoadByte(S); + f->is_vararg=LoadByte(S); + f->maxstacksize=LoadByte(S); + LoadCode(S,f); + LoadConstants(S,f); + LoadDebug(S,f); + IF (!luaG_checkcode(f), "bad code"); + S->L->top--; + S->L->nCcalls--; + return f; +} + +static void LoadHeader(LoadState* S) +{ + char h[LUAC_HEADERSIZE]; + char s[LUAC_HEADERSIZE]; + luaU_header(h); + LoadBlock(S,s,LUAC_HEADERSIZE); + IF (memcmp(h,s,LUAC_HEADERSIZE)!=0, "bad header"); +} + +/* +** load precompiled chunk +*/ +Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name) +{ + LoadState S; + if (*name=='@' || *name=='=') + S.name=name+1; + else if (*name==LUA_SIGNATURE[0]) + S.name="binary string"; + else + S.name=name; + S.L=L; + S.Z=Z; + S.b=buff; + LoadHeader(&S); + return LoadFunction(&S,luaS_newliteral(L,"=?")); +} + +/* +* make header +*/ +void luaU_header (char* h) +{ + int x=1; + memcpy(h,LUA_SIGNATURE,sizeof(LUA_SIGNATURE)-1); + h+=sizeof(LUA_SIGNATURE)-1; + *h++=(char)LUAC_VERSION; + *h++=(char)LUAC_FORMAT; + *h++=(char)*(char*)&x; /* endianness */ + *h++=(char)sizeof(int); + *h++=(char)sizeof(size_t); + *h++=(char)sizeof(Instruction); + *h++=(char)sizeof(lua_Number); + *h++=(char)(((lua_Number)0.5)==0); /* is lua_Number integral? */ +} diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lundump.h b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lundump.h new file mode 100644 index 00000000..c80189db --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lundump.h @@ -0,0 +1,36 @@ +/* +** $Id: lundump.h,v 1.37.1.1 2007/12/27 13:02:25 roberto Exp $ +** load precompiled Lua chunks +** See Copyright Notice in lua.h +*/ + +#ifndef lundump_h +#define lundump_h + +#include "lobject.h" +#include "lzio.h" + +/* load one chunk; from lundump.c */ +LUAI_FUNC Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name); + +/* make header; from lundump.c */ +LUAI_FUNC void luaU_header (char* h); + +/* dump one chunk; from ldump.c */ +LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip); + +#ifdef luac_c +/* print one chunk; from print.c */ +LUAI_FUNC void luaU_print (const Proto* f, int full); +#endif + +/* for header of binary files -- this is Lua 5.1 */ +#define LUAC_VERSION 0x51 + +/* for header of binary files -- this is the official format */ +#define LUAC_FORMAT 0 + +/* size of header of binary files */ +#define LUAC_HEADERSIZE 12 + +#endif diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lvm.c b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lvm.c new file mode 100644 index 00000000..ee3256ab --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lvm.c @@ -0,0 +1,763 @@ +/* +** $Id: lvm.c,v 2.63.1.3 2007/12/28 15:32:23 roberto Exp $ +** Lua virtual machine +** See Copyright Notice in lua.h +*/ + + +#include +#include +#include + +#define lvm_c +#define LUA_CORE + +#include "lua.h" + +#include "ldebug.h" +#include "ldo.h" +#include "lfunc.h" +#include "lgc.h" +#include "lobject.h" +#include "lopcodes.h" +#include "lstate.h" +#include "lstring.h" +#include "ltable.h" +#include "ltm.h" +#include "lvm.h" + + + +/* limit for table tag-method chains (to avoid loops) */ +#define MAXTAGLOOP 100 + + +const TValue *luaV_tonumber (const TValue *obj, TValue *n) { + lua_Number num; + if (ttisnumber(obj)) return obj; + if (ttisstring(obj) && luaO_str2d(svalue(obj), &num)) { + setnvalue(n, num); + return n; + } + else + return NULL; +} + + +int luaV_tostring (lua_State *L, StkId obj) { + if (!ttisnumber(obj)) + return 0; + else { + char s[LUAI_MAXNUMBER2STR]; + lua_Number n = nvalue(obj); + lua_number2str(s, n); + setsvalue2s(L, obj, luaS_new(L, s)); + return 1; + } +} + + +static void traceexec (lua_State *L, const Instruction *pc) { + lu_byte mask = L->hookmask; + const Instruction *oldpc = L->savedpc; + L->savedpc = pc; + if ((mask & LUA_MASKCOUNT) && L->hookcount == 0) { + resethookcount(L); + luaD_callhook(L, LUA_HOOKCOUNT, -1); + } + if (mask & LUA_MASKLINE) { + Proto *p = ci_func(L->ci)->l.p; + int npc = pcRel(pc, p); + int newline = getline(p, npc); + /* call linehook when enter a new function, when jump back (loop), + or when enter a new line */ + if (npc == 0 || pc <= oldpc || newline != getline(p, pcRel(oldpc, p))) + luaD_callhook(L, LUA_HOOKLINE, newline); + } +} + + +static void callTMres (lua_State *L, StkId res, const TValue *f, + const TValue *p1, const TValue *p2) { + ptrdiff_t result = savestack(L, res); + setobj2s(L, L->top, f); /* push function */ + setobj2s(L, L->top+1, p1); /* 1st argument */ + setobj2s(L, L->top+2, p2); /* 2nd argument */ + luaD_checkstack(L, 3); + L->top += 3; + luaD_call(L, L->top - 3, 1); + res = restorestack(L, result); + L->top--; + setobjs2s(L, res, L->top); +} + + + +static void callTM (lua_State *L, const TValue *f, const TValue *p1, + const TValue *p2, const TValue *p3) { + setobj2s(L, L->top, f); /* push function */ + setobj2s(L, L->top+1, p1); /* 1st argument */ + setobj2s(L, L->top+2, p2); /* 2nd argument */ + setobj2s(L, L->top+3, p3); /* 3th argument */ + luaD_checkstack(L, 4); + L->top += 4; + luaD_call(L, L->top - 4, 0); +} + + +void luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val) { + int loop; + for (loop = 0; loop < MAXTAGLOOP; loop++) { + const TValue *tm; + if (ttistable(t)) { /* `t' is a table? */ + Table *h = hvalue(t); + const TValue *res = luaH_get(h, key); /* do a primitive get */ + if (!ttisnil(res) || /* result is no nil? */ + (tm = fasttm(L, h->metatable, TM_INDEX)) == NULL) { /* or no TM? */ + setobj2s(L, val, res); + return; + } + /* else will try the tag method */ + } + else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_INDEX))) + luaG_typeerror(L, t, "index"); + if (ttisfunction(tm)) { + callTMres(L, val, tm, t, key); + return; + } + t = tm; /* else repeat with `tm' */ + } + luaG_runerror(L, "loop in gettable"); +} + + +void luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val) { + int loop; + for (loop = 0; loop < MAXTAGLOOP; loop++) { + const TValue *tm; + if (ttistable(t)) { /* `t' is a table? */ + Table *h = hvalue(t); + TValue *oldval = luaH_set(L, h, key); /* do a primitive set */ + if (!ttisnil(oldval) || /* result is no nil? */ + (tm = fasttm(L, h->metatable, TM_NEWINDEX)) == NULL) { /* or no TM? */ + setobj2t(L, oldval, val); + luaC_barriert(L, h, val); + return; + } + /* else will try the tag method */ + } + else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_NEWINDEX))) + luaG_typeerror(L, t, "index"); + if (ttisfunction(tm)) { + callTM(L, tm, t, key, val); + return; + } + t = tm; /* else repeat with `tm' */ + } + luaG_runerror(L, "loop in settable"); +} + + +static int call_binTM (lua_State *L, const TValue *p1, const TValue *p2, + StkId res, TMS event) { + const TValue *tm = luaT_gettmbyobj(L, p1, event); /* try first operand */ + if (ttisnil(tm)) + tm = luaT_gettmbyobj(L, p2, event); /* try second operand */ + if (ttisnil(tm)) return 0; + callTMres(L, res, tm, p1, p2); + return 1; +} + + +static const TValue *get_compTM (lua_State *L, Table *mt1, Table *mt2, + TMS event) { + const TValue *tm1 = fasttm(L, mt1, event); + const TValue *tm2; + if (tm1 == NULL) return NULL; /* no metamethod */ + if (mt1 == mt2) return tm1; /* same metatables => same metamethods */ + tm2 = fasttm(L, mt2, event); + if (tm2 == NULL) return NULL; /* no metamethod */ + if (luaO_rawequalObj(tm1, tm2)) /* same metamethods? */ + return tm1; + return NULL; +} + + +static int call_orderTM (lua_State *L, const TValue *p1, const TValue *p2, + TMS event) { + const TValue *tm1 = luaT_gettmbyobj(L, p1, event); + const TValue *tm2; + if (ttisnil(tm1)) return -1; /* no metamethod? */ + tm2 = luaT_gettmbyobj(L, p2, event); + if (!luaO_rawequalObj(tm1, tm2)) /* different metamethods? */ + return -1; + callTMres(L, L->top, tm1, p1, p2); + return !l_isfalse(L->top); +} + + +static int l_strcmp (const TString *ls, const TString *rs) { + const char *l = getstr(ls); + size_t ll = ls->tsv.len; + const char *r = getstr(rs); + size_t lr = rs->tsv.len; + for (;;) { + int temp = strcoll(l, r); + if (temp != 0) return temp; + else { /* strings are equal up to a `\0' */ + size_t len = strlen(l); /* index of first `\0' in both strings */ + if (len == lr) /* r is finished? */ + return (len == ll) ? 0 : 1; + else if (len == ll) /* l is finished? */ + return -1; /* l is smaller than r (because r is not finished) */ + /* both strings longer than `len'; go on comparing (after the `\0') */ + len++; + l += len; ll -= len; r += len; lr -= len; + } + } +} + + +int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r) { + int res; + if (ttype(l) != ttype(r)) + return luaG_ordererror(L, l, r); + else if (ttisnumber(l)) + return luai_numlt(nvalue(l), nvalue(r)); + else if (ttisstring(l)) + return l_strcmp(rawtsvalue(l), rawtsvalue(r)) < 0; + else if ((res = call_orderTM(L, l, r, TM_LT)) != -1) + return res; + return luaG_ordererror(L, l, r); +} + + +static int lessequal (lua_State *L, const TValue *l, const TValue *r) { + int res; + if (ttype(l) != ttype(r)) + return luaG_ordererror(L, l, r); + else if (ttisnumber(l)) + return luai_numle(nvalue(l), nvalue(r)); + else if (ttisstring(l)) + return l_strcmp(rawtsvalue(l), rawtsvalue(r)) <= 0; + else if ((res = call_orderTM(L, l, r, TM_LE)) != -1) /* first try `le' */ + return res; + else if ((res = call_orderTM(L, r, l, TM_LT)) != -1) /* else try `lt' */ + return !res; + return luaG_ordererror(L, l, r); +} + + +int luaV_equalval (lua_State *L, const TValue *t1, const TValue *t2) { + const TValue *tm; + lua_assert(ttype(t1) == ttype(t2)); + switch (ttype(t1)) { + case LUA_TNIL: return 1; + case LUA_TNUMBER: return luai_numeq(nvalue(t1), nvalue(t2)); + case LUA_TBOOLEAN: return bvalue(t1) == bvalue(t2); /* true must be 1 !! */ + case LUA_TLIGHTUSERDATA: return pvalue(t1) == pvalue(t2); + case LUA_TUSERDATA: { + if (uvalue(t1) == uvalue(t2)) return 1; + tm = get_compTM(L, uvalue(t1)->metatable, uvalue(t2)->metatable, + TM_EQ); + break; /* will try TM */ + } + case LUA_TTABLE: { + if (hvalue(t1) == hvalue(t2)) return 1; + tm = get_compTM(L, hvalue(t1)->metatable, hvalue(t2)->metatable, TM_EQ); + break; /* will try TM */ + } + default: return gcvalue(t1) == gcvalue(t2); + } + if (tm == NULL) return 0; /* no TM? */ + callTMres(L, L->top, tm, t1, t2); /* call TM */ + return !l_isfalse(L->top); +} + + +void luaV_concat (lua_State *L, int total, int last) { + do { + StkId top = L->base + last + 1; + int n = 2; /* number of elements handled in this pass (at least 2) */ + if (!(ttisstring(top-2) || ttisnumber(top-2)) || !tostring(L, top-1)) { + if (!call_binTM(L, top-2, top-1, top-2, TM_CONCAT)) + luaG_concaterror(L, top-2, top-1); + } else if (tsvalue(top-1)->len == 0) /* second op is empty? */ + (void)tostring(L, top - 2); /* result is first op (as string) */ + else { + /* at least two string values; get as many as possible */ + size_t tl = tsvalue(top-1)->len; + char *buffer; + int i; + /* collect total length */ + for (n = 1; n < total && tostring(L, top-n-1); n++) { + size_t l = tsvalue(top-n-1)->len; + if (l >= MAX_SIZET - tl) luaG_runerror(L, "string length overflow"); + tl += l; + } + buffer = luaZ_openspace(L, &G(L)->buff, tl); + tl = 0; + for (i=n; i>0; i--) { /* concat all strings */ + size_t l = tsvalue(top-i)->len; + memcpy(buffer+tl, svalue(top-i), l); + tl += l; + } + setsvalue2s(L, top-n, luaS_newlstr(L, buffer, tl)); + } + total -= n-1; /* got `n' strings to create 1 new */ + last -= n-1; + } while (total > 1); /* repeat until only 1 result left */ +} + + +static void Arith (lua_State *L, StkId ra, const TValue *rb, + const TValue *rc, TMS op) { + TValue tempb, tempc; + const TValue *b, *c; + if ((b = luaV_tonumber(rb, &tempb)) != NULL && + (c = luaV_tonumber(rc, &tempc)) != NULL) { + lua_Number nb = nvalue(b), nc = nvalue(c); + switch (op) { + case TM_ADD: setnvalue(ra, luai_numadd(nb, nc)); break; + case TM_SUB: setnvalue(ra, luai_numsub(nb, nc)); break; + case TM_MUL: setnvalue(ra, luai_nummul(nb, nc)); break; + case TM_DIV: setnvalue(ra, luai_numdiv(nb, nc)); break; + case TM_MOD: setnvalue(ra, luai_nummod(nb, nc)); break; + case TM_POW: setnvalue(ra, luai_numpow(nb, nc)); break; + case TM_UNM: setnvalue(ra, luai_numunm(nb)); break; + default: lua_assert(0); break; + } + } + else if (!call_binTM(L, rb, rc, ra, op)) + luaG_aritherror(L, rb, rc); +} + + + +/* +** some macros for common tasks in `luaV_execute' +*/ + +#define runtime_check(L, c) { if (!(c)) break; } + +#define RA(i) (base+GETARG_A(i)) +/* to be used after possible stack reallocation */ +#define RB(i) check_exp(getBMode(GET_OPCODE(i)) == OpArgR, base+GETARG_B(i)) +#define RC(i) check_exp(getCMode(GET_OPCODE(i)) == OpArgR, base+GETARG_C(i)) +#define RKB(i) check_exp(getBMode(GET_OPCODE(i)) == OpArgK, \ + ISK(GETARG_B(i)) ? k+INDEXK(GETARG_B(i)) : base+GETARG_B(i)) +#define RKC(i) check_exp(getCMode(GET_OPCODE(i)) == OpArgK, \ + ISK(GETARG_C(i)) ? k+INDEXK(GETARG_C(i)) : base+GETARG_C(i)) +#define KBx(i) check_exp(getBMode(GET_OPCODE(i)) == OpArgK, k+GETARG_Bx(i)) + + +#define dojump(L,pc,i) {(pc) += (i); luai_threadyield(L);} + + +#define Protect(x) { L->savedpc = pc; {x;}; base = L->base; } + + +#define arith_op(op,tm) { \ + TValue *rb = RKB(i); \ + TValue *rc = RKC(i); \ + if (ttisnumber(rb) && ttisnumber(rc)) { \ + lua_Number nb = nvalue(rb), nc = nvalue(rc); \ + setnvalue(ra, op(nb, nc)); \ + } \ + else \ + Protect(Arith(L, ra, rb, rc, tm)); \ + } + + + +void luaV_execute (lua_State *L, int nexeccalls) { + LClosure *cl; + StkId base; + TValue *k; + const Instruction *pc; + reentry: /* entry point */ + lua_assert(isLua(L->ci)); + pc = L->savedpc; + cl = &clvalue(L->ci->func)->l; + base = L->base; + k = cl->p->k; + /* main loop of interpreter */ + for (;;) { + const Instruction i = *pc++; + StkId ra; + if ((L->hookmask & (LUA_MASKLINE | LUA_MASKCOUNT)) && + (--L->hookcount == 0 || L->hookmask & LUA_MASKLINE)) { + traceexec(L, pc); + if (L->status == LUA_YIELD) { /* did hook yield? */ + L->savedpc = pc - 1; + return; + } + base = L->base; + } + /* warning!! several calls may realloc the stack and invalidate `ra' */ + ra = RA(i); + lua_assert(base == L->base && L->base == L->ci->base); + lua_assert(base <= L->top && L->top <= L->stack + L->stacksize); + lua_assert(L->top == L->ci->top || luaG_checkopenop(i)); + switch (GET_OPCODE(i)) { + case OP_MOVE: { + setobjs2s(L, ra, RB(i)); + continue; + } + case OP_LOADK: { + setobj2s(L, ra, KBx(i)); + continue; + } + case OP_LOADBOOL: { + setbvalue(ra, GETARG_B(i)); + if (GETARG_C(i)) pc++; /* skip next instruction (if C) */ + continue; + } + case OP_LOADNIL: { + TValue *rb = RB(i); + do { + setnilvalue(rb--); + } while (rb >= ra); + continue; + } + case OP_GETUPVAL: { + int b = GETARG_B(i); + setobj2s(L, ra, cl->upvals[b]->v); + continue; + } + case OP_GETGLOBAL: { + TValue g; + TValue *rb = KBx(i); + sethvalue(L, &g, cl->env); + lua_assert(ttisstring(rb)); + Protect(luaV_gettable(L, &g, rb, ra)); + continue; + } + case OP_GETTABLE: { + Protect(luaV_gettable(L, RB(i), RKC(i), ra)); + continue; + } + case OP_SETGLOBAL: { + TValue g; + sethvalue(L, &g, cl->env); + lua_assert(ttisstring(KBx(i))); + Protect(luaV_settable(L, &g, KBx(i), ra)); + continue; + } + case OP_SETUPVAL: { + UpVal *uv = cl->upvals[GETARG_B(i)]; + setobj(L, uv->v, ra); + luaC_barrier(L, uv, ra); + continue; + } + case OP_SETTABLE: { + Protect(luaV_settable(L, ra, RKB(i), RKC(i))); + continue; + } + case OP_NEWTABLE: { + int b = GETARG_B(i); + int c = GETARG_C(i); + sethvalue(L, ra, luaH_new(L, luaO_fb2int(b), luaO_fb2int(c))); + Protect(luaC_checkGC(L)); + continue; + } + case OP_SELF: { + StkId rb = RB(i); + setobjs2s(L, ra+1, rb); + Protect(luaV_gettable(L, rb, RKC(i), ra)); + continue; + } + case OP_ADD: { + arith_op(luai_numadd, TM_ADD); + continue; + } + case OP_SUB: { + arith_op(luai_numsub, TM_SUB); + continue; + } + case OP_MUL: { + arith_op(luai_nummul, TM_MUL); + continue; + } + case OP_DIV: { + arith_op(luai_numdiv, TM_DIV); + continue; + } + case OP_MOD: { + arith_op(luai_nummod, TM_MOD); + continue; + } + case OP_POW: { + arith_op(luai_numpow, TM_POW); + continue; + } + case OP_UNM: { + TValue *rb = RB(i); + if (ttisnumber(rb)) { + lua_Number nb = nvalue(rb); + setnvalue(ra, luai_numunm(nb)); + } + else { + Protect(Arith(L, ra, rb, rb, TM_UNM)); + } + continue; + } + case OP_NOT: { + int res = l_isfalse(RB(i)); /* next assignment may change this value */ + setbvalue(ra, res); + continue; + } + case OP_LEN: { + const TValue *rb = RB(i); + switch (ttype(rb)) { + case LUA_TTABLE: { + setnvalue(ra, cast_num(luaH_getn(hvalue(rb)))); + break; + } + case LUA_TSTRING: { + setnvalue(ra, cast_num(tsvalue(rb)->len)); + break; + } + default: { /* try metamethod */ + Protect( + if (!call_binTM(L, rb, luaO_nilobject, ra, TM_LEN)) + luaG_typeerror(L, rb, "get length of"); + ) + } + } + continue; + } + case OP_CONCAT: { + int b = GETARG_B(i); + int c = GETARG_C(i); + Protect(luaV_concat(L, c-b+1, c); luaC_checkGC(L)); + setobjs2s(L, RA(i), base+b); + continue; + } + case OP_JMP: { + dojump(L, pc, GETARG_sBx(i)); + continue; + } + case OP_EQ: { + TValue *rb = RKB(i); + TValue *rc = RKC(i); + Protect( + if (equalobj(L, rb, rc) == GETARG_A(i)) + dojump(L, pc, GETARG_sBx(*pc)); + ) + pc++; + continue; + } + case OP_LT: { + Protect( + if (luaV_lessthan(L, RKB(i), RKC(i)) == GETARG_A(i)) + dojump(L, pc, GETARG_sBx(*pc)); + ) + pc++; + continue; + } + case OP_LE: { + Protect( + if (lessequal(L, RKB(i), RKC(i)) == GETARG_A(i)) + dojump(L, pc, GETARG_sBx(*pc)); + ) + pc++; + continue; + } + case OP_TEST: { + if (l_isfalse(ra) != GETARG_C(i)) + dojump(L, pc, GETARG_sBx(*pc)); + pc++; + continue; + } + case OP_TESTSET: { + TValue *rb = RB(i); + if (l_isfalse(rb) != GETARG_C(i)) { + setobjs2s(L, ra, rb); + dojump(L, pc, GETARG_sBx(*pc)); + } + pc++; + continue; + } + case OP_CALL: { + int b = GETARG_B(i); + int nresults = GETARG_C(i) - 1; + if (b != 0) L->top = ra+b; /* else previous instruction set top */ + L->savedpc = pc; + switch (luaD_precall(L, ra, nresults)) { + case PCRLUA: { + nexeccalls++; + goto reentry; /* restart luaV_execute over new Lua function */ + } + case PCRC: { + /* it was a C function (`precall' called it); adjust results */ + if (nresults >= 0) L->top = L->ci->top; + base = L->base; + continue; + } + default: { + return; /* yield */ + } + } + } + case OP_TAILCALL: { + int b = GETARG_B(i); + if (b != 0) L->top = ra+b; /* else previous instruction set top */ + L->savedpc = pc; + lua_assert(GETARG_C(i) - 1 == LUA_MULTRET); + switch (luaD_precall(L, ra, LUA_MULTRET)) { + case PCRLUA: { + /* tail call: put new frame in place of previous one */ + CallInfo *ci = L->ci - 1; /* previous frame */ + int aux; + StkId func = ci->func; + StkId pfunc = (ci+1)->func; /* previous function index */ + if (L->openupval) luaF_close(L, ci->base); + L->base = ci->base = ci->func + ((ci+1)->base - pfunc); + for (aux = 0; pfunc+aux < L->top; aux++) /* move frame down */ + setobjs2s(L, func+aux, pfunc+aux); + ci->top = L->top = func+aux; /* correct top */ + lua_assert(L->top == L->base + clvalue(func)->l.p->maxstacksize); + ci->savedpc = L->savedpc; + ci->tailcalls++; /* one more call lost */ + L->ci--; /* remove new frame */ + goto reentry; + } + case PCRC: { /* it was a C function (`precall' called it) */ + base = L->base; + continue; + } + default: { + return; /* yield */ + } + } + } + case OP_RETURN: { + int b = GETARG_B(i); + if (b != 0) L->top = ra+b-1; + if (L->openupval) luaF_close(L, base); + L->savedpc = pc; + b = luaD_poscall(L, ra); + if (--nexeccalls == 0) /* was previous function running `here'? */ + return; /* no: return */ + else { /* yes: continue its execution */ + if (b) L->top = L->ci->top; + lua_assert(isLua(L->ci)); + lua_assert(GET_OPCODE(*((L->ci)->savedpc - 1)) == OP_CALL); + goto reentry; + } + } + case OP_FORLOOP: { + lua_Number step = nvalue(ra+2); + lua_Number idx = luai_numadd(nvalue(ra), step); /* increment index */ + lua_Number limit = nvalue(ra+1); + if (luai_numlt(0, step) ? luai_numle(idx, limit) + : luai_numle(limit, idx)) { + dojump(L, pc, GETARG_sBx(i)); /* jump back */ + setnvalue(ra, idx); /* update internal index... */ + setnvalue(ra+3, idx); /* ...and external index */ + } + continue; + } + case OP_FORPREP: { + const TValue *init = ra; + const TValue *plimit = ra+1; + const TValue *pstep = ra+2; + L->savedpc = pc; /* next steps may throw errors */ + if (!tonumber(init, ra)) + luaG_runerror(L, LUA_QL("for") " initial value must be a number"); + else if (!tonumber(plimit, ra+1)) + luaG_runerror(L, LUA_QL("for") " limit must be a number"); + else if (!tonumber(pstep, ra+2)) + luaG_runerror(L, LUA_QL("for") " step must be a number"); + setnvalue(ra, luai_numsub(nvalue(ra), nvalue(pstep))); + dojump(L, pc, GETARG_sBx(i)); + continue; + } + case OP_TFORLOOP: { + StkId cb = ra + 3; /* call base */ + setobjs2s(L, cb+2, ra+2); + setobjs2s(L, cb+1, ra+1); + setobjs2s(L, cb, ra); + L->top = cb+3; /* func. + 2 args (state and index) */ + Protect(luaD_call(L, cb, GETARG_C(i))); + L->top = L->ci->top; + cb = RA(i) + 3; /* previous call may change the stack */ + if (!ttisnil(cb)) { /* continue loop? */ + setobjs2s(L, cb-1, cb); /* save control variable */ + dojump(L, pc, GETARG_sBx(*pc)); /* jump back */ + } + pc++; + continue; + } + case OP_SETLIST: { + int n = GETARG_B(i); + int c = GETARG_C(i); + int last; + Table *h; + if (n == 0) { + n = cast_int(L->top - ra) - 1; + L->top = L->ci->top; + } + if (c == 0) c = cast_int(*pc++); + runtime_check(L, ttistable(ra)); + h = hvalue(ra); + last = ((c-1)*LFIELDS_PER_FLUSH) + n; + if (last > h->sizearray) /* needs more space? */ + luaH_resizearray(L, h, last); /* pre-alloc it at once */ + for (; n > 0; n--) { + TValue *val = ra+n; + setobj2t(L, luaH_setnum(L, h, last--), val); + luaC_barriert(L, h, val); + } + continue; + } + case OP_CLOSE: { + luaF_close(L, ra); + continue; + } + case OP_CLOSURE: { + Proto *p; + Closure *ncl; + int nup, j; + p = cl->p->p[GETARG_Bx(i)]; + nup = p->nups; + ncl = luaF_newLclosure(L, nup, cl->env); + ncl->l.p = p; + for (j=0; jl.upvals[j] = cl->upvals[GETARG_B(*pc)]; + else { + lua_assert(GET_OPCODE(*pc) == OP_MOVE); + ncl->l.upvals[j] = luaF_findupval(L, base + GETARG_B(*pc)); + } + } + setclvalue(L, ra, ncl); + Protect(luaC_checkGC(L)); + continue; + } + case OP_VARARG: { + int b = GETARG_B(i) - 1; + int j; + CallInfo *ci = L->ci; + int n = cast_int(ci->base - ci->func) - cl->p->numparams - 1; + if (b == LUA_MULTRET) { + Protect(luaD_checkstack(L, n)); + ra = RA(i); /* previous call may change the stack */ + b = n; + L->top = ra + n; + } + for (j = 0; j < b; j++) { + if (j < n) { + setobjs2s(L, ra + j, ci->base - n + j); + } + else { + setnilvalue(ra + j); + } + } + continue; + } + } + } +} + diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lvm.h b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lvm.h new file mode 100644 index 00000000..bfe4f567 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lvm.h @@ -0,0 +1,36 @@ +/* +** $Id: lvm.h,v 2.5.1.1 2007/12/27 13:02:25 roberto Exp $ +** Lua virtual machine +** See Copyright Notice in lua.h +*/ + +#ifndef lvm_h +#define lvm_h + + +#include "ldo.h" +#include "lobject.h" +#include "ltm.h" + + +#define tostring(L,o) ((ttype(o) == LUA_TSTRING) || (luaV_tostring(L, o))) + +#define tonumber(o,n) (ttype(o) == LUA_TNUMBER || \ + (((o) = luaV_tonumber(o,n)) != NULL)) + +#define equalobj(L,o1,o2) \ + (ttype(o1) == ttype(o2) && luaV_equalval(L, o1, o2)) + + +LUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r); +LUAI_FUNC int luaV_equalval (lua_State *L, const TValue *t1, const TValue *t2); +LUAI_FUNC const TValue *luaV_tonumber (const TValue *obj, TValue *n); +LUAI_FUNC int luaV_tostring (lua_State *L, StkId obj); +LUAI_FUNC void luaV_gettable (lua_State *L, const TValue *t, TValue *key, + StkId val); +LUAI_FUNC void luaV_settable (lua_State *L, const TValue *t, TValue *key, + StkId val); +LUAI_FUNC void luaV_execute (lua_State *L, int nexeccalls); +LUAI_FUNC void luaV_concat (lua_State *L, int total, int last); + +#endif diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lzio.c b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lzio.c new file mode 100644 index 00000000..293edd59 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lzio.c @@ -0,0 +1,82 @@ +/* +** $Id: lzio.c,v 1.31.1.1 2007/12/27 13:02:25 roberto Exp $ +** a generic input stream interface +** See Copyright Notice in lua.h +*/ + + +#include + +#define lzio_c +#define LUA_CORE + +#include "lua.h" + +#include "llimits.h" +#include "lmem.h" +#include "lstate.h" +#include "lzio.h" + + +int luaZ_fill (ZIO *z) { + size_t size; + lua_State *L = z->L; + const char *buff; + lua_unlock(L); + buff = z->reader(L, z->data, &size); + lua_lock(L); + if (buff == NULL || size == 0) return EOZ; + z->n = size - 1; + z->p = buff; + return char2int(*(z->p++)); +} + + +int luaZ_lookahead (ZIO *z) { + if (z->n == 0) { + if (luaZ_fill(z) == EOZ) + return EOZ; + else { + z->n++; /* luaZ_fill removed first byte; put back it */ + z->p--; + } + } + return char2int(*z->p); +} + + +void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) { + z->L = L; + z->reader = reader; + z->data = data; + z->n = 0; + z->p = NULL; +} + + +/* --------------------------------------------------------------- read --- */ +size_t luaZ_read (ZIO *z, void *b, size_t n) { + while (n) { + size_t m; + if (luaZ_lookahead(z) == EOZ) + return n; /* return number of missing bytes */ + m = (n <= z->n) ? n : z->n; /* min. between n and z->n */ + memcpy(b, z->p, m); + z->n -= m; + z->p += m; + b = (char *)b + m; + n -= m; + } + return 0; +} + +/* ------------------------------------------------------------------------ */ +char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n) { + if (n > buff->buffsize) { + if (n < LUA_MINBUFFER) n = LUA_MINBUFFER; + luaZ_resizebuffer(L, buff, n); + } + return buff->buffer; +} + + diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lzio.h b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lzio.h new file mode 100644 index 00000000..51d695d8 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/lzio.h @@ -0,0 +1,67 @@ +/* +** $Id: lzio.h,v 1.21.1.1 2007/12/27 13:02:25 roberto Exp $ +** Buffered streams +** See Copyright Notice in lua.h +*/ + + +#ifndef lzio_h +#define lzio_h + +#include "lua.h" + +#include "lmem.h" + + +#define EOZ (-1) /* end of stream */ + +typedef struct Zio ZIO; + +#define char2int(c) cast(int, cast(unsigned char, (c))) + +#define zgetc(z) (((z)->n--)>0 ? char2int(*(z)->p++) : luaZ_fill(z)) + +typedef struct Mbuffer { + char *buffer; + size_t n; + size_t buffsize; +} Mbuffer; + +#define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0) + +#define luaZ_buffer(buff) ((buff)->buffer) +#define luaZ_sizebuffer(buff) ((buff)->buffsize) +#define luaZ_bufflen(buff) ((buff)->n) + +#define luaZ_resetbuffer(buff) ((buff)->n = 0) + + +#define luaZ_resizebuffer(L, buff, size) \ + (luaM_reallocvector(L, (buff)->buffer, (buff)->buffsize, size, char), \ + (buff)->buffsize = size) + +#define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0) + + +LUAI_FUNC char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n); +LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, + void *data); +LUAI_FUNC size_t luaZ_read (ZIO* z, void* b, size_t n); /* read next n bytes */ +LUAI_FUNC int luaZ_lookahead (ZIO *z); + + + +/* --------- Private Part ------------------ */ + +struct Zio { + size_t n; /* bytes still unread */ + const char *p; /* current position in buffer */ + lua_Reader reader; + void* data; /* additional data */ + lua_State *L; /* Lua state (for reader) */ +}; + + +LUAI_FUNC int luaZ_fill (ZIO *z); + +#endif diff --git a/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/print.c b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/print.c new file mode 100644 index 00000000..e240cfc3 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/IOS/lua/lua/print.c @@ -0,0 +1,227 @@ +/* +** $Id: print.c,v 1.55a 2006/05/31 13:30:05 lhf Exp $ +** print bytecodes +** See Copyright Notice in lua.h +*/ + +#include +#include + +#define luac_c +#define LUA_CORE + +#include "ldebug.h" +#include "lobject.h" +#include "lopcodes.h" +#include "lundump.h" + +#define PrintFunction luaU_print + +#define Sizeof(x) ((int)sizeof(x)) +#define VOID(p) ((const void*)(p)) + +static void PrintString(const TString* ts) +{ + const char* s=getstr(ts); + size_t i,n=ts->tsv.len; + putchar('"'); + for (i=0; ik[i]; + switch (ttype(o)) + { + case LUA_TNIL: + printf("nil"); + break; + case LUA_TBOOLEAN: + printf(bvalue(o) ? "true" : "false"); + break; + case LUA_TNUMBER: + printf(LUA_NUMBER_FMT,nvalue(o)); + break; + case LUA_TSTRING: + PrintString(rawtsvalue(o)); + break; + default: /* cannot happen */ + printf("? type=%d",ttype(o)); + break; + } +} + +static void PrintCode(const Proto* f) +{ + const Instruction* code=f->code; + int pc,n=f->sizecode; + for (pc=0; pc0) printf("[%d]\t",line); else printf("[-]\t"); + printf("%-9s\t",luaP_opnames[o]); + switch (getOpMode(o)) + { + case iABC: + printf("%d",a); + if (getBMode(o)!=OpArgN) printf(" %d",ISK(b) ? (-1-INDEXK(b)) : b); + if (getCMode(o)!=OpArgN) printf(" %d",ISK(c) ? (-1-INDEXK(c)) : c); + break; + case iABx: + if (getBMode(o)==OpArgK) printf("%d %d",a,-1-bx); else printf("%d %d",a,bx); + break; + case iAsBx: + if (o==OP_JMP) printf("%d",sbx); else printf("%d %d",a,sbx); + break; + } + switch (o) + { + case OP_LOADK: + printf("\t; "); PrintConstant(f,bx); + break; + case OP_GETUPVAL: + case OP_SETUPVAL: + printf("\t; %s", (f->sizeupvalues>0) ? getstr(f->upvalues[b]) : "-"); + break; + case OP_GETGLOBAL: + case OP_SETGLOBAL: + printf("\t; %s",svalue(&f->k[bx])); + break; + case OP_GETTABLE: + case OP_SELF: + if (ISK(c)) { printf("\t; "); PrintConstant(f,INDEXK(c)); } + break; + case OP_SETTABLE: + case OP_ADD: + case OP_SUB: + case OP_MUL: + case OP_DIV: + case OP_POW: + case OP_EQ: + case OP_LT: + case OP_LE: + if (ISK(b) || ISK(c)) + { + printf("\t; "); + if (ISK(b)) PrintConstant(f,INDEXK(b)); else printf("-"); + printf(" "); + if (ISK(c)) PrintConstant(f,INDEXK(c)); else printf("-"); + } + break; + case OP_JMP: + case OP_FORLOOP: + case OP_FORPREP: + printf("\t; to %d",sbx+pc+2); + break; + case OP_CLOSURE: + printf("\t; %p",VOID(f->p[bx])); + break; + case OP_SETLIST: + if (c==0) printf("\t; %d",(int)code[++pc]); + else printf("\t; %d",c); + break; + default: + break; + } + printf("\n"); + } +} + +#define SS(x) (x==1)?"":"s" +#define S(x) x,SS(x) + +static void PrintHeader(const Proto* f) +{ + const char* s=getstr(f->source); + if (*s=='@' || *s=='=') + s++; + else if (*s==LUA_SIGNATURE[0]) + s="(bstring)"; + else + s="(string)"; + printf("\n%s <%s:%d,%d> (%d instruction%s, %d bytes at %p)\n", + (f->linedefined==0)?"main":"function",s, + f->linedefined,f->lastlinedefined, + S(f->sizecode),f->sizecode*Sizeof(Instruction),VOID(f)); + printf("%d%s param%s, %d slot%s, %d upvalue%s, ", + f->numparams,f->is_vararg?"+":"",SS(f->numparams), + S(f->maxstacksize),S(f->nups)); + printf("%d local%s, %d constant%s, %d function%s\n", + S(f->sizelocvars),S(f->sizek),S(f->sizep)); +} + +static void PrintConstants(const Proto* f) +{ + int i,n=f->sizek; + printf("constants (%d) for %p:\n",n,VOID(f)); + for (i=0; isizelocvars; + printf("locals (%d) for %p:\n",n,VOID(f)); + for (i=0; ilocvars[i].varname),f->locvars[i].startpc+1,f->locvars[i].endpc+1); + } +} + +static void PrintUpvalues(const Proto* f) +{ + int i,n=f->sizeupvalues; + printf("upvalues (%d) for %p:\n",n,VOID(f)); + if (f->upvalues==NULL) return; + for (i=0; iupvalues[i])); + } +} + +void PrintFunction(const Proto* f, int full) +{ + int i,n=f->sizep; + PrintHeader(f); + PrintCode(f); + if (full) + { + PrintConstants(f); + PrintLocals(f); + PrintUpvalues(f); + } + for (i=0; ip[i],full); +} diff --git a/IOS/Playground/Pods/LuaViewSDK/LICENSE.txt b/IOS/Playground/Pods/LuaViewSDK/LICENSE.txt new file mode 100644 index 00000000..5546ac5f --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/LICENSE.txt @@ -0,0 +1,17 @@ +The MIT License (MIT) +Copyright (c) 2017 Alibaba Group +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/IOS/Playground/Pods/LuaViewSDK/README.md b/IOS/Playground/Pods/LuaViewSDK/README.md new file mode 100644 index 00000000..6dde4ed3 --- /dev/null +++ b/IOS/Playground/Pods/LuaViewSDK/README.md @@ -0,0 +1,38 @@ +# 欢迎来到LuaViewSDK + +LuaViewSDK是一个跨iOS和Android平台的界面动态化解决方案,使用同一套Lua脚本在iOS和Android平台构建原生页面,同时兼具了H5的灵活性和Native的高性能 + +## 为什么选择Lua + +为了解决类似的问题,市面上有许多类似的方案,比如React Native和Weex,他们使用了JS框架,配合DSL来进行界面布局,使用JS引擎进行脚本动态解析,实现了动态化的Native界面渲染能力。LuaViewSDK使用lua虚拟机进行脚本解析,通过构建lua与native之间的一系列基础bridge功能,从另一个角度实现了动态化的native能力。相比于基于JS虚拟机的解决方案,LuaViewSDK有如下特性: + +- lua虚拟机极为轻量高效。单个lua虚拟机只消耗大约200到300k的内存空间,同屏渲染几十个LuaView没有任何负担 +- Lua天生就是作为一个极其轻量、可嵌入的设计实现,它更适合做API的封装或是数据传输的中间层。在App的开发上,更适合作为胶水语言,来直接操作native对象 +- 使用App开发人员更为熟悉的Native编程模式,直接创建和操作各种界面对象 +- 轻松桥接native组件,只需要一行代码即可实现在LuaView脚本中操作用户自定义的native功能 + +## 试用Playground App + +LuaViewSDK Playground App下载地址 [Download](https://github.com/alibaba/LuaViewSDK/releases) + +## 如何使用LuaViewSDK + +- [使用说明](https://alibaba.github.io/LuaViewSDK/guide.html) +- [接口文档](https://alibaba.github.io/LuaViewSDK/apimenu.html) + +## 开发者 + +- [董希成](xicheng.dxc@alibaba-inc.com) +- [陈松涛](songtao.cst@alibaba-inc.com) + +## 许可证 + +[MIT](https://github.com/alibaba/LuaViewSDK/blob/master/LICENSE.txt) + +## 社区 + +[Github Wiki](https://github.com/alibaba/LuaViewSDK/wiki) + +QQ群:539262083 + +Twitter:[@luaview](https://twitter.com/luaview) \ No newline at end of file diff --git a/IOS/Playground/Pods/MJRefresh/LICENSE b/IOS/Playground/Pods/MJRefresh/LICENSE new file mode 100644 index 00000000..11bf2345 --- /dev/null +++ b/IOS/Playground/Pods/MJRefresh/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2013-2015 MJRefresh (https://github.com/CoderMJLee/MJRefresh) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/IOS/Playground/Pods/MJRefresh/MJRefresh/Base/MJRefreshAutoFooter.h b/IOS/Playground/Pods/MJRefresh/MJRefresh/Base/MJRefreshAutoFooter.h new file mode 100644 index 00000000..82a02497 --- /dev/null +++ b/IOS/Playground/Pods/MJRefresh/MJRefresh/Base/MJRefreshAutoFooter.h @@ -0,0 +1,20 @@ +// +// MJRefreshAutoFooter.h +// MJRefreshExample +// +// Created by MJ Lee on 15/4/24. +// Copyright (c) 2015年 小码哥. All rights reserved. +// + +#import "MJRefreshFooter.h" + +@interface MJRefreshAutoFooter : MJRefreshFooter +/** 是否自动刷新(默认为YES) */ +@property (assign, nonatomic, getter=isAutomaticallyRefresh) BOOL automaticallyRefresh; + +/** 当底部控件出现多少时就自动刷新(默认为1.0,也就是底部控件完全出现时,才会自动刷新) */ +@property (assign, nonatomic) CGFloat appearencePercentTriggerAutoRefresh MJRefreshDeprecated("请使用triggerAutomaticallyRefreshPercent属性"); + +/** 当底部控件出现多少时就自动刷新(默认为1.0,也就是底部控件完全出现时,才会自动刷新) */ +@property (assign, nonatomic) CGFloat triggerAutomaticallyRefreshPercent; +@end diff --git a/IOS/Playground/Pods/MJRefresh/MJRefresh/Base/MJRefreshAutoFooter.m b/IOS/Playground/Pods/MJRefresh/MJRefresh/Base/MJRefreshAutoFooter.m new file mode 100644 index 00000000..7327096b --- /dev/null +++ b/IOS/Playground/Pods/MJRefresh/MJRefresh/Base/MJRefreshAutoFooter.m @@ -0,0 +1,139 @@ +// +// MJRefreshAutoFooter.m +// MJRefreshExample +// +// Created by MJ Lee on 15/4/24. +// Copyright (c) 2015年 小码哥. All rights reserved. +// + +#import "MJRefreshAutoFooter.h" + +@interface MJRefreshAutoFooter() +@end + +@implementation MJRefreshAutoFooter + +#pragma mark - 初始化 +- (void)willMoveToSuperview:(UIView *)newSuperview +{ + [super willMoveToSuperview:newSuperview]; + + if (newSuperview) { // 新的父控件 + if (self.hidden == NO) { + self.scrollView.mj_insetB += self.mj_h; + } + + // 设置位置 + self.mj_y = _scrollView.mj_contentH; + } else { // 被移除了 + if (self.hidden == NO) { + self.scrollView.mj_insetB -= self.mj_h; + } + } +} + +#pragma mark - 过期方法 +- (void)setAppearencePercentTriggerAutoRefresh:(CGFloat)appearencePercentTriggerAutoRefresh +{ + self.triggerAutomaticallyRefreshPercent = appearencePercentTriggerAutoRefresh; +} + +- (CGFloat)appearencePercentTriggerAutoRefresh +{ + return self.triggerAutomaticallyRefreshPercent; +} + +#pragma mark - 实现父类的方法 +- (void)prepare +{ + [super prepare]; + + // 默认底部控件100%出现时才会自动刷新 + self.triggerAutomaticallyRefreshPercent = 1.0; + + // 设置为默认状态 + self.automaticallyRefresh = YES; +} + +- (void)scrollViewContentSizeDidChange:(NSDictionary *)change +{ + [super scrollViewContentSizeDidChange:change]; + + // 设置位置 + self.mj_y = self.scrollView.mj_contentH; +} + +- (void)scrollViewContentOffsetDidChange:(NSDictionary *)change +{ + [super scrollViewContentOffsetDidChange:change]; + + if (self.state != MJRefreshStateIdle || !self.automaticallyRefresh || self.mj_y == 0) return; + + if (_scrollView.mj_insetT + _scrollView.mj_contentH > _scrollView.mj_h) { // 内容超过一个屏幕 + // 这里的_scrollView.mj_contentH替换掉self.mj_y更为合理 + if (_scrollView.mj_offsetY >= _scrollView.mj_contentH - _scrollView.mj_h + self.mj_h * self.triggerAutomaticallyRefreshPercent + _scrollView.mj_insetB - self.mj_h) { + // 防止手松开时连续调用 + CGPoint old = [change[@"old"] CGPointValue]; + CGPoint new = [change[@"new"] CGPointValue]; + if (new.y <= old.y) return; + + // 当底部刷新控件完全出现时,才刷新 + [self beginRefreshing]; + } + } +} + +- (void)scrollViewPanStateDidChange:(NSDictionary *)change +{ + [super scrollViewPanStateDidChange:change]; + + if (self.state != MJRefreshStateIdle) return; + + if (_scrollView.panGestureRecognizer.state == UIGestureRecognizerStateEnded) {// 手松开 + if (_scrollView.mj_insetT + _scrollView.mj_contentH <= _scrollView.mj_h) { // 不够一个屏幕 + if (_scrollView.mj_offsetY >= - _scrollView.mj_insetT) { // 向上拽 + [self beginRefreshing]; + } + } else { // 超出一个屏幕 + if (_scrollView.mj_offsetY >= _scrollView.mj_contentH + _scrollView.mj_insetB - _scrollView.mj_h) { + [self beginRefreshing]; + } + } + } +} + +- (void)setState:(MJRefreshState)state +{ + MJRefreshCheckState + + if (state == MJRefreshStateRefreshing) { + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + [self executeRefreshingCallback]; + }); + } else if (state == MJRefreshStateNoMoreData || state == MJRefreshStateIdle) { + if (MJRefreshStateRefreshing == oldState) { + if (self.endRefreshingCompletionBlock) { + self.endRefreshingCompletionBlock(); + } + } + } +} + +- (void)setHidden:(BOOL)hidden +{ + BOOL lastHidden = self.isHidden; + + [super setHidden:hidden]; + + if (!lastHidden && hidden) { + self.state = MJRefreshStateIdle; + + self.scrollView.mj_insetB -= self.mj_h; + } else if (lastHidden && !hidden) { + self.scrollView.mj_insetB += self.mj_h; + + // 设置位置 + self.mj_y = _scrollView.mj_contentH; + } +} +@end diff --git a/IOS/Playground/Pods/MJRefresh/MJRefresh/Base/MJRefreshBackFooter.h b/IOS/Playground/Pods/MJRefresh/MJRefresh/Base/MJRefreshBackFooter.h new file mode 100644 index 00000000..347083cf --- /dev/null +++ b/IOS/Playground/Pods/MJRefresh/MJRefresh/Base/MJRefreshBackFooter.h @@ -0,0 +1,13 @@ +// +// MJRefreshBackFooter.h +// MJRefreshExample +// +// Created by MJ Lee on 15/4/24. +// Copyright (c) 2015年 小码哥. All rights reserved. +// + +#import "MJRefreshFooter.h" + +@interface MJRefreshBackFooter : MJRefreshFooter + +@end diff --git a/IOS/Playground/Pods/MJRefresh/MJRefresh/Base/MJRefreshBackFooter.m b/IOS/Playground/Pods/MJRefresh/MJRefresh/Base/MJRefreshBackFooter.m new file mode 100644 index 00000000..83978adc --- /dev/null +++ b/IOS/Playground/Pods/MJRefresh/MJRefresh/Base/MJRefreshBackFooter.m @@ -0,0 +1,160 @@ +// +// MJRefreshBackFooter.m +// MJRefreshExample +// +// Created by MJ Lee on 15/4/24. +// Copyright (c) 2015年 小码哥. All rights reserved. +// + +#import "MJRefreshBackFooter.h" + +@interface MJRefreshBackFooter() +@property (assign, nonatomic) NSInteger lastRefreshCount; +@property (assign, nonatomic) CGFloat lastBottomDelta; +@end + +@implementation MJRefreshBackFooter + +#pragma mark - 初始化 +- (void)willMoveToSuperview:(UIView *)newSuperview +{ + [super willMoveToSuperview:newSuperview]; + + [self scrollViewContentSizeDidChange:nil]; +} + +#pragma mark - 实现父类的方法 +- (void)scrollViewContentOffsetDidChange:(NSDictionary *)change +{ + [super scrollViewContentOffsetDidChange:change]; + + // 如果正在刷新,直接返回 + if (self.state == MJRefreshStateRefreshing) return; + + _scrollViewOriginalInset = self.scrollView.contentInset; + + // 当前的contentOffset + CGFloat currentOffsetY = self.scrollView.mj_offsetY; + // 尾部控件刚好出现的offsetY + CGFloat happenOffsetY = [self happenOffsetY]; + // 如果是向下滚动到看不见尾部控件,直接返回 + if (currentOffsetY <= happenOffsetY) return; + + CGFloat pullingPercent = (currentOffsetY - happenOffsetY) / self.mj_h; + + // 如果已全部加载,仅设置pullingPercent,然后返回 + if (self.state == MJRefreshStateNoMoreData) { + self.pullingPercent = pullingPercent; + return; + } + + if (self.scrollView.isDragging) { + self.pullingPercent = pullingPercent; + // 普通 和 即将刷新 的临界点 + CGFloat normal2pullingOffsetY = happenOffsetY + self.mj_h; + + if (self.state == MJRefreshStateIdle && currentOffsetY > normal2pullingOffsetY) { + // 转为即将刷新状态 + self.state = MJRefreshStatePulling; + } else if (self.state == MJRefreshStatePulling && currentOffsetY <= normal2pullingOffsetY) { + // 转为普通状态 + self.state = MJRefreshStateIdle; + } + } else if (self.state == MJRefreshStatePulling) {// 即将刷新 && 手松开 + // 开始刷新 + [self beginRefreshing]; + } else if (pullingPercent < 1) { + self.pullingPercent = pullingPercent; + } +} + +- (void)scrollViewContentSizeDidChange:(NSDictionary *)change +{ + [super scrollViewContentSizeDidChange:change]; + + // 内容的高度 + CGFloat contentHeight = self.scrollView.mj_contentH + self.ignoredScrollViewContentInsetBottom; + // 表格的高度 + CGFloat scrollHeight = self.scrollView.mj_h - self.scrollViewOriginalInset.top - self.scrollViewOriginalInset.bottom + self.ignoredScrollViewContentInsetBottom; + // 设置位置和尺寸 + self.mj_y = MAX(contentHeight, scrollHeight); +} + +- (void)setState:(MJRefreshState)state +{ + MJRefreshCheckState + + // 根据状态来设置属性 + if (state == MJRefreshStateNoMoreData || state == MJRefreshStateIdle) { + // 刷新完毕 + if (MJRefreshStateRefreshing == oldState) { + [UIView animateWithDuration:MJRefreshSlowAnimationDuration animations:^{ + self.scrollView.mj_insetB -= self.lastBottomDelta; + + // 自动调整透明度 + if (self.isAutomaticallyChangeAlpha) self.alpha = 0.0; + } completion:^(BOOL finished) { + self.pullingPercent = 0.0; + + if (self.endRefreshingCompletionBlock) { + self.endRefreshingCompletionBlock(); + } + }]; + } + + CGFloat deltaH = [self heightForContentBreakView]; + // 刚刷新完毕 + if (MJRefreshStateRefreshing == oldState && deltaH > 0 && self.scrollView.mj_totalDataCount != self.lastRefreshCount) { + self.scrollView.mj_offsetY = self.scrollView.mj_offsetY; + } + } else if (state == MJRefreshStateRefreshing) { + // 记录刷新前的数量 + self.lastRefreshCount = self.scrollView.mj_totalDataCount; + + [UIView animateWithDuration:MJRefreshFastAnimationDuration animations:^{ + CGFloat bottom = self.mj_h + self.scrollViewOriginalInset.bottom; + CGFloat deltaH = [self heightForContentBreakView]; + if (deltaH < 0) { // 如果内容高度小于view的高度 + bottom -= deltaH; + } + self.lastBottomDelta = bottom - self.scrollView.mj_insetB; + self.scrollView.mj_insetB = bottom; + self.scrollView.mj_offsetY = [self happenOffsetY] + self.mj_h; + } completion:^(BOOL finished) { + [self executeRefreshingCallback]; + }]; + } +} + +- (void)endRefreshing +{ + dispatch_async(dispatch_get_main_queue(), ^{ + self.state = MJRefreshStateIdle; + }); +} + +- (void)endRefreshingWithNoMoreData +{ + dispatch_async(dispatch_get_main_queue(), ^{ + self.state = MJRefreshStateNoMoreData; + }); +} +#pragma mark - 私有方法 +#pragma mark 获得scrollView的内容 超出 view 的高度 +- (CGFloat)heightForContentBreakView +{ + CGFloat h = self.scrollView.frame.size.height - self.scrollViewOriginalInset.bottom - self.scrollViewOriginalInset.top; + return self.scrollView.contentSize.height - h; +} + +#pragma mark 刚好看到上拉刷新控件时的contentOffset.y +- (CGFloat)happenOffsetY +{ + CGFloat deltaH = [self heightForContentBreakView]; + if (deltaH > 0) { + return deltaH - self.scrollViewOriginalInset.top; + } else { + return - self.scrollViewOriginalInset.top; + } +} +@end diff --git a/IOS/Playground/Pods/MJRefresh/MJRefresh/Base/MJRefreshComponent.h b/IOS/Playground/Pods/MJRefresh/MJRefresh/Base/MJRefreshComponent.h new file mode 100644 index 00000000..9e96c898 --- /dev/null +++ b/IOS/Playground/Pods/MJRefresh/MJRefresh/Base/MJRefreshComponent.h @@ -0,0 +1,106 @@ +// 代码地址: https://github.com/CoderMJLee/MJRefresh +// 代码地址: http://code4app.com/ios/%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90%E4%B8%8B%E6%8B%89%E4%B8%8A%E6%8B%89%E5%88%B7%E6%96%B0/52326ce26803fabc46000000 +// MJRefreshComponent.h +// MJRefreshExample +// +// Created by MJ Lee on 15/3/4. +// Copyright (c) 2015年 小码哥. All rights reserved. +// 刷新控件的基类 + +#import +#import "MJRefreshConst.h" +#import "UIView+MJExtension.h" +#import "UIScrollView+MJExtension.h" +#import "UIScrollView+MJRefresh.h" +#import "NSBundle+MJRefresh.h" + +/** 刷新控件的状态 */ +typedef NS_ENUM(NSInteger, MJRefreshState) { + /** 普通闲置状态 */ + MJRefreshStateIdle = 1, + /** 松开就可以进行刷新的状态 */ + MJRefreshStatePulling, + /** 正在刷新中的状态 */ + MJRefreshStateRefreshing, + /** 即将刷新的状态 */ + MJRefreshStateWillRefresh, + /** 所有数据加载完毕,没有更多的数据了 */ + MJRefreshStateNoMoreData +}; + +/** 进入刷新状态的回调 */ +typedef void (^MJRefreshComponentRefreshingBlock)(); +/** 开始刷新后的回调(进入刷新状态后的回调) */ +typedef void (^MJRefreshComponentbeginRefreshingCompletionBlock)(); +/** 结束刷新后的回调 */ +typedef void (^MJRefreshComponentEndRefreshingCompletionBlock)(); + +/** 刷新控件的基类 */ +@interface MJRefreshComponent : UIView +{ + /** 记录scrollView刚开始的inset */ + UIEdgeInsets _scrollViewOriginalInset; + /** 父控件 */ + __weak UIScrollView *_scrollView; +} +#pragma mark - 刷新回调 +/** 正在刷新的回调 */ +@property (copy, nonatomic) MJRefreshComponentRefreshingBlock refreshingBlock; +/** 设置回调对象和回调方法 */ +- (void)setRefreshingTarget:(id)target refreshingAction:(SEL)action; + +/** 回调对象 */ +@property (weak, nonatomic) id refreshingTarget; +/** 回调方法 */ +@property (assign, nonatomic) SEL refreshingAction; +/** 触发回调(交给子类去调用) */ +- (void)executeRefreshingCallback; + +#pragma mark - 刷新状态控制 +/** 进入刷新状态 */ +- (void)beginRefreshing; +- (void)beginRefreshingWithCompletionBlock:(void (^)())completionBlock; +/** 开始刷新后的回调(进入刷新状态后的回调) */ +@property (copy, nonatomic) MJRefreshComponentbeginRefreshingCompletionBlock beginRefreshingCompletionBlock; +/** 结束刷新的回调 */ +@property (copy, nonatomic) MJRefreshComponentEndRefreshingCompletionBlock endRefreshingCompletionBlock; +/** 结束刷新状态 */ +- (void)endRefreshing; +- (void)endRefreshingWithCompletionBlock:(void (^)())completionBlock; +/** 是否正在刷新 */ +- (BOOL)isRefreshing; +/** 刷新状态 一般交给子类内部实现 */ +@property (assign, nonatomic) MJRefreshState state; + +#pragma mark - 交给子类去访问 +/** 记录scrollView刚开始的inset */ +@property (assign, nonatomic, readonly) UIEdgeInsets scrollViewOriginalInset; +/** 父控件 */ +@property (weak, nonatomic, readonly) UIScrollView *scrollView; + +#pragma mark - 交给子类们去实现 +/** 初始化 */ +- (void)prepare NS_REQUIRES_SUPER; +/** 摆放子控件frame */ +- (void)placeSubviews NS_REQUIRES_SUPER; +/** 当scrollView的contentOffset发生改变的时候调用 */ +- (void)scrollViewContentOffsetDidChange:(NSDictionary *)change NS_REQUIRES_SUPER; +/** 当scrollView的contentSize发生改变的时候调用 */ +- (void)scrollViewContentSizeDidChange:(NSDictionary *)change NS_REQUIRES_SUPER; +/** 当scrollView的拖拽状态发生改变的时候调用 */ +- (void)scrollViewPanStateDidChange:(NSDictionary *)change NS_REQUIRES_SUPER; + + +#pragma mark - 其他 +/** 拉拽的百分比(交给子类重写) */ +@property (assign, nonatomic) CGFloat pullingPercent; +/** 根据拖拽比例自动切换透明度 */ +@property (assign, nonatomic, getter=isAutoChangeAlpha) BOOL autoChangeAlpha MJRefreshDeprecated("请使用automaticallyChangeAlpha属性"); +/** 根据拖拽比例自动切换透明度 */ +@property (assign, nonatomic, getter=isAutomaticallyChangeAlpha) BOOL automaticallyChangeAlpha; +@end + +@interface UILabel(MJRefresh) ++ (instancetype)mj_label; +- (CGFloat)mj_textWith; +@end diff --git a/IOS/Playground/Pods/MJRefresh/MJRefresh/Base/MJRefreshComponent.m b/IOS/Playground/Pods/MJRefresh/MJRefresh/Base/MJRefreshComponent.m new file mode 100644 index 00000000..fec5ed7f --- /dev/null +++ b/IOS/Playground/Pods/MJRefresh/MJRefresh/Base/MJRefreshComponent.m @@ -0,0 +1,274 @@ +// 代码地址: https://github.com/CoderMJLee/MJRefresh +// 代码地址: http://code4app.com/ios/%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90%E4%B8%8B%E6%8B%89%E4%B8%8A%E6%8B%89%E5%88%B7%E6%96%B0/52326ce26803fabc46000000 +// MJRefreshComponent.m +// MJRefreshExample +// +// Created by MJ Lee on 15/3/4. +// Copyright (c) 2015年 小码哥. All rights reserved. +// + +#import "MJRefreshComponent.h" +#import "MJRefreshConst.h" + +@interface MJRefreshComponent() +@property (strong, nonatomic) UIPanGestureRecognizer *pan; +@end + +@implementation MJRefreshComponent +#pragma mark - 初始化 +- (instancetype)initWithFrame:(CGRect)frame +{ + if (self = [super initWithFrame:frame]) { + // 准备工作 + [self prepare]; + + // 默认是普通状态 + self.state = MJRefreshStateIdle; + } + return self; +} + +- (void)prepare +{ + // 基本属性 + self.autoresizingMask = UIViewAutoresizingFlexibleWidth; + self.backgroundColor = [UIColor clearColor]; +} + +- (void)layoutSubviews +{ + [self placeSubviews]; + + [super layoutSubviews]; +} + +- (void)placeSubviews{} + +- (void)willMoveToSuperview:(UIView *)newSuperview +{ + [super willMoveToSuperview:newSuperview]; + + // 如果不是UIScrollView,不做任何事情 + if (newSuperview && ![newSuperview isKindOfClass:[UIScrollView class]]) return; + + // 旧的父控件移除监听 + [self removeObservers]; + + if (newSuperview) { // 新的父控件 + // 设置宽度 + self.mj_w = newSuperview.mj_w; + // 设置位置 + self.mj_x = 0; + + // 记录UIScrollView + _scrollView = (UIScrollView *)newSuperview; + // 设置永远支持垂直弹簧效果 + _scrollView.alwaysBounceVertical = YES; + // 记录UIScrollView最开始的contentInset + _scrollViewOriginalInset = _scrollView.contentInset; + + // 添加监听 + [self addObservers]; + } +} + +- (void)drawRect:(CGRect)rect +{ + [super drawRect:rect]; + + if (self.state == MJRefreshStateWillRefresh) { + // 预防view还没显示出来就调用了beginRefreshing + self.state = MJRefreshStateRefreshing; + } +} + +#pragma mark - KVO监听 +- (void)addObservers +{ + NSKeyValueObservingOptions options = NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld; + [self.scrollView addObserver:self forKeyPath:MJRefreshKeyPathContentOffset options:options context:nil]; + [self.scrollView addObserver:self forKeyPath:MJRefreshKeyPathContentSize options:options context:nil]; + self.pan = self.scrollView.panGestureRecognizer; + [self.pan addObserver:self forKeyPath:MJRefreshKeyPathPanState options:options context:nil]; +} + +- (void)removeObservers +{ + [self.superview removeObserver:self forKeyPath:MJRefreshKeyPathContentOffset]; + [self.superview removeObserver:self forKeyPath:MJRefreshKeyPathContentSize];; + [self.pan removeObserver:self forKeyPath:MJRefreshKeyPathPanState]; + self.pan = nil; +} + +- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context +{ + // 遇到这些情况就直接返回 + if (!self.userInteractionEnabled) return; + + // 这个就算看不见也需要处理 + if ([keyPath isEqualToString:MJRefreshKeyPathContentSize]) { + [self scrollViewContentSizeDidChange:change]; + } + + // 看不见 + if (self.hidden) return; + if ([keyPath isEqualToString:MJRefreshKeyPathContentOffset]) { + [self scrollViewContentOffsetDidChange:change]; + } else if ([keyPath isEqualToString:MJRefreshKeyPathPanState]) { + [self scrollViewPanStateDidChange:change]; + } +} + +- (void)scrollViewContentOffsetDidChange:(NSDictionary *)change{} +- (void)scrollViewContentSizeDidChange:(NSDictionary *)change{} +- (void)scrollViewPanStateDidChange:(NSDictionary *)change{} + +#pragma mark - 公共方法 +#pragma mark 设置回调对象和回调方法 +- (void)setRefreshingTarget:(id)target refreshingAction:(SEL)action +{ + self.refreshingTarget = target; + self.refreshingAction = action; +} + +- (void)setState:(MJRefreshState)state +{ + _state = state; + + // 加入主队列的目的是等setState:方法调用完毕、设置完文字后再去布局子控件 + dispatch_async(dispatch_get_main_queue(), ^{ + [self setNeedsLayout]; + }); +} + +#pragma mark 进入刷新状态 +- (void)beginRefreshing +{ + [UIView animateWithDuration:MJRefreshFastAnimationDuration animations:^{ + self.alpha = 1.0; + }]; + self.pullingPercent = 1.0; + // 只要正在刷新,就完全显示 + if (self.window) { + self.state = MJRefreshStateRefreshing; + } else { + // 预防正在刷新中时,调用本方法使得header inset回置失败 + if (self.state != MJRefreshStateRefreshing) { + self.state = MJRefreshStateWillRefresh; + // 刷新(预防从另一个控制器回到这个控制器的情况,回来要重新刷新一下) + [self setNeedsDisplay]; + } + } +} + +- (void)beginRefreshingWithCompletionBlock:(void (^)())completionBlock +{ + self.beginRefreshingCompletionBlock = completionBlock; + + [self beginRefreshing]; +} + +#pragma mark 结束刷新状态 +- (void)endRefreshing +{ + self.state = MJRefreshStateIdle; +} + +- (void)endRefreshingWithCompletionBlock:(void (^)())completionBlock +{ + self.endRefreshingCompletionBlock = completionBlock; + + [self endRefreshing]; +} + +#pragma mark 是否正在刷新 +- (BOOL)isRefreshing +{ + return self.state == MJRefreshStateRefreshing || self.state == MJRefreshStateWillRefresh; +} + +#pragma mark 自动切换透明度 +- (void)setAutoChangeAlpha:(BOOL)autoChangeAlpha +{ + self.automaticallyChangeAlpha = autoChangeAlpha; +} + +- (BOOL)isAutoChangeAlpha +{ + return self.isAutomaticallyChangeAlpha; +} + +- (void)setAutomaticallyChangeAlpha:(BOOL)automaticallyChangeAlpha +{ + _automaticallyChangeAlpha = automaticallyChangeAlpha; + + if (self.isRefreshing) return; + + if (automaticallyChangeAlpha) { + self.alpha = self.pullingPercent; + } else { + self.alpha = 1.0; + } +} + +#pragma mark 根据拖拽进度设置透明度 +- (void)setPullingPercent:(CGFloat)pullingPercent +{ + _pullingPercent = pullingPercent; + + if (self.isRefreshing) return; + + if (self.isAutomaticallyChangeAlpha) { + self.alpha = pullingPercent; + } +} + +#pragma mark - 内部方法 +- (void)executeRefreshingCallback +{ + dispatch_async(dispatch_get_main_queue(), ^{ + if (self.refreshingBlock) { + self.refreshingBlock(); + } + if ([self.refreshingTarget respondsToSelector:self.refreshingAction]) { + MJRefreshMsgSend(MJRefreshMsgTarget(self.refreshingTarget), self.refreshingAction, self); + } + if (self.beginRefreshingCompletionBlock) { + self.beginRefreshingCompletionBlock(); + } + }); +} +@end + +@implementation UILabel(MJRefresh) ++ (instancetype)mj_label +{ + UILabel *label = [[self alloc] init]; + label.font = MJRefreshLabelFont; + label.textColor = MJRefreshLabelTextColor; + label.autoresizingMask = UIViewAutoresizingFlexibleWidth; + label.textAlignment = NSTextAlignmentCenter; + label.backgroundColor = [UIColor clearColor]; + return label; +} + +- (CGFloat)mj_textWith { + CGFloat stringWidth = 0; + CGSize size = CGSizeMake(MAXFLOAT, MAXFLOAT); + if (self.text.length > 0) { +#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000 + stringWidth =[self.text + boundingRectWithSize:size + options:NSStringDrawingUsesLineFragmentOrigin + attributes:@{NSFontAttributeName:self.font} + context:nil].size.width; +#else + + stringWidth = [self.text sizeWithFont:self.font + constrainedToSize:size + lineBreakMode:NSLineBreakByCharWrapping].width; +#endif + } + return stringWidth; +} +@end \ No newline at end of file diff --git a/IOS/Playground/Pods/MJRefresh/MJRefresh/Base/MJRefreshFooter.h b/IOS/Playground/Pods/MJRefresh/MJRefresh/Base/MJRefreshFooter.h new file mode 100644 index 00000000..22d23e52 --- /dev/null +++ b/IOS/Playground/Pods/MJRefresh/MJRefresh/Base/MJRefreshFooter.h @@ -0,0 +1,30 @@ +// 代码地址: https://github.com/CoderMJLee/MJRefresh +// 代码地址: http://code4app.com/ios/%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90%E4%B8%8B%E6%8B%89%E4%B8%8A%E6%8B%89%E5%88%B7%E6%96%B0/52326ce26803fabc46000000 +// MJRefreshFooter.h +// MJRefreshExample +// +// Created by MJ Lee on 15/3/5. +// Copyright (c) 2015年 小码哥. All rights reserved. +// 上拉刷新控件 + +#import "MJRefreshComponent.h" + +@interface MJRefreshFooter : MJRefreshComponent +/** 创建footer */ ++ (instancetype)footerWithRefreshingBlock:(MJRefreshComponentRefreshingBlock)refreshingBlock; +/** 创建footer */ ++ (instancetype)footerWithRefreshingTarget:(id)target refreshingAction:(SEL)action; + +/** 提示没有更多的数据 */ +- (void)endRefreshingWithNoMoreData; +- (void)noticeNoMoreData MJRefreshDeprecated("使用endRefreshingWithNoMoreData"); + +/** 重置没有更多的数据(消除没有更多数据的状态) */ +- (void)resetNoMoreData; + +/** 忽略多少scrollView的contentInset的bottom */ +@property (assign, nonatomic) CGFloat ignoredScrollViewContentInsetBottom; + +/** 自动根据有无数据来显示和隐藏(有数据就显示,没有数据隐藏。默认是NO) */ +@property (assign, nonatomic, getter=isAutomaticallyHidden) BOOL automaticallyHidden; +@end diff --git a/IOS/Playground/Pods/MJRefresh/MJRefresh/Base/MJRefreshFooter.m b/IOS/Playground/Pods/MJRefresh/MJRefresh/Base/MJRefreshFooter.m new file mode 100644 index 00000000..69f65e7d --- /dev/null +++ b/IOS/Playground/Pods/MJRefresh/MJRefresh/Base/MJRefreshFooter.m @@ -0,0 +1,74 @@ +// 代码地址: https://github.com/CoderMJLee/MJRefresh +// 代码地址: http://code4app.com/ios/%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90%E4%B8%8B%E6%8B%89%E4%B8%8A%E6%8B%89%E5%88%B7%E6%96%B0/52326ce26803fabc46000000 +// MJRefreshFooter.m +// MJRefreshExample +// +// Created by MJ Lee on 15/3/5. +// Copyright (c) 2015年 小码哥. All rights reserved. +// + +#import "MJRefreshFooter.h" + +@interface MJRefreshFooter() + +@end + +@implementation MJRefreshFooter +#pragma mark - 构造方法 ++ (instancetype)footerWithRefreshingBlock:(MJRefreshComponentRefreshingBlock)refreshingBlock +{ + MJRefreshFooter *cmp = [[self alloc] init]; + cmp.refreshingBlock = refreshingBlock; + return cmp; +} ++ (instancetype)footerWithRefreshingTarget:(id)target refreshingAction:(SEL)action +{ + MJRefreshFooter *cmp = [[self alloc] init]; + [cmp setRefreshingTarget:target refreshingAction:action]; + return cmp; +} + +#pragma mark - 重写父类的方法 +- (void)prepare +{ + [super prepare]; + + // 设置自己的高度 + self.mj_h = MJRefreshFooterHeight; + + // 默认不会自动隐藏 + self.automaticallyHidden = NO; +} + +- (void)willMoveToSuperview:(UIView *)newSuperview +{ + [super willMoveToSuperview:newSuperview]; + + if (newSuperview) { + // 监听scrollView数据的变化 + if ([self.scrollView isKindOfClass:[UITableView class]] || [self.scrollView isKindOfClass:[UICollectionView class]]) { + [self.scrollView setMj_reloadDataBlock:^(NSInteger totalDataCount) { + if (self.isAutomaticallyHidden) { + self.hidden = (totalDataCount == 0); + } + }]; + } + } +} + +#pragma mark - 公共方法 +- (void)endRefreshingWithNoMoreData +{ + self.state = MJRefreshStateNoMoreData; +} + +- (void)noticeNoMoreData +{ + [self endRefreshingWithNoMoreData]; +} + +- (void)resetNoMoreData +{ + self.state = MJRefreshStateIdle; +} +@end diff --git a/IOS/Playground/Pods/MJRefresh/MJRefresh/Base/MJRefreshHeader.h b/IOS/Playground/Pods/MJRefresh/MJRefresh/Base/MJRefreshHeader.h new file mode 100644 index 00000000..08160245 --- /dev/null +++ b/IOS/Playground/Pods/MJRefresh/MJRefresh/Base/MJRefreshHeader.h @@ -0,0 +1,25 @@ +// 代码地址: https://github.com/CoderMJLee/MJRefresh +// 代码地址: http://code4app.com/ios/%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90%E4%B8%8B%E6%8B%89%E4%B8%8A%E6%8B%89%E5%88%B7%E6%96%B0/52326ce26803fabc46000000 +// MJRefreshHeader.h +// MJRefreshExample +// +// Created by MJ Lee on 15/3/4. +// Copyright (c) 2015年 小码哥. All rights reserved. +// 下拉刷新控件:负责监控用户下拉的状态 + +#import "MJRefreshComponent.h" + +@interface MJRefreshHeader : MJRefreshComponent +/** 创建header */ ++ (instancetype)headerWithRefreshingBlock:(MJRefreshComponentRefreshingBlock)refreshingBlock; +/** 创建header */ ++ (instancetype)headerWithRefreshingTarget:(id)target refreshingAction:(SEL)action; + +/** 这个key用来存储上一次下拉刷新成功的时间 */ +@property (copy, nonatomic) NSString *lastUpdatedTimeKey; +/** 上一次下拉刷新成功的时间 */ +@property (strong, nonatomic, readonly) NSDate *lastUpdatedTime; + +/** 忽略多少scrollView的contentInset的top */ +@property (assign, nonatomic) CGFloat ignoredScrollViewContentInsetTop; +@end diff --git a/IOS/Playground/Pods/MJRefresh/MJRefresh/Base/MJRefreshHeader.m b/IOS/Playground/Pods/MJRefresh/MJRefresh/Base/MJRefreshHeader.m new file mode 100644 index 00000000..070cea6c --- /dev/null +++ b/IOS/Playground/Pods/MJRefresh/MJRefresh/Base/MJRefreshHeader.m @@ -0,0 +1,153 @@ +// 代码地址: https://github.com/CoderMJLee/MJRefresh +// 代码地址: http://code4app.com/ios/%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90%E4%B8%8B%E6%8B%89%E4%B8%8A%E6%8B%89%E5%88%B7%E6%96%B0/52326ce26803fabc46000000 +// MJRefreshHeader.m +// MJRefreshExample +// +// Created by MJ Lee on 15/3/4. +// Copyright (c) 2015年 小码哥. All rights reserved. +// + +#import "MJRefreshHeader.h" + +@interface MJRefreshHeader() +@property (assign, nonatomic) CGFloat insetTDelta; +@end + +@implementation MJRefreshHeader +#pragma mark - 构造方法 ++ (instancetype)headerWithRefreshingBlock:(MJRefreshComponentRefreshingBlock)refreshingBlock +{ + MJRefreshHeader *cmp = [[self alloc] init]; + cmp.refreshingBlock = refreshingBlock; + return cmp; +} ++ (instancetype)headerWithRefreshingTarget:(id)target refreshingAction:(SEL)action +{ + MJRefreshHeader *cmp = [[self alloc] init]; + [cmp setRefreshingTarget:target refreshingAction:action]; + return cmp; +} + +#pragma mark - 覆盖父类的方法 +- (void)prepare +{ + [super prepare]; + + // 设置key + self.lastUpdatedTimeKey = MJRefreshHeaderLastUpdatedTimeKey; + + // 设置高度 + self.mj_h = MJRefreshHeaderHeight; +} + +- (void)placeSubviews +{ + [super placeSubviews]; + + // 设置y值(当自己的高度发生改变了,肯定要重新调整Y值,所以放到placeSubviews方法中设置y值) + self.mj_y = - self.mj_h - self.ignoredScrollViewContentInsetTop; +} + +- (void)scrollViewContentOffsetDidChange:(NSDictionary *)change +{ + [super scrollViewContentOffsetDidChange:change]; + + // 在刷新的refreshing状态 + if (self.state == MJRefreshStateRefreshing) { + if (self.window == nil) return; + + // sectionheader停留解决 + CGFloat insetT = - self.scrollView.mj_offsetY > _scrollViewOriginalInset.top ? - self.scrollView.mj_offsetY : _scrollViewOriginalInset.top; + insetT = insetT > self.mj_h + _scrollViewOriginalInset.top ? self.mj_h + _scrollViewOriginalInset.top : insetT; + self.scrollView.mj_insetT = insetT; + + self.insetTDelta = _scrollViewOriginalInset.top - insetT; + return; + } + + // 跳转到下一个控制器时,contentInset可能会变 + _scrollViewOriginalInset = self.scrollView.contentInset; + + // 当前的contentOffset + CGFloat offsetY = self.scrollView.mj_offsetY; + // 头部控件刚好出现的offsetY + CGFloat happenOffsetY = - self.scrollViewOriginalInset.top; + + // 如果是向上滚动到看不见头部控件,直接返回 + // >= -> > + if (offsetY > happenOffsetY) return; + + // 普通 和 即将刷新 的临界点 + CGFloat normal2pullingOffsetY = happenOffsetY - self.mj_h; + CGFloat pullingPercent = (happenOffsetY - offsetY) / self.mj_h; + + if (self.scrollView.isDragging) { // 如果正在拖拽 + self.pullingPercent = pullingPercent; + if (self.state == MJRefreshStateIdle && offsetY < normal2pullingOffsetY) { + // 转为即将刷新状态 + self.state = MJRefreshStatePulling; + } else if (self.state == MJRefreshStatePulling && offsetY >= normal2pullingOffsetY) { + // 转为普通状态 + self.state = MJRefreshStateIdle; + } + } else if (self.state == MJRefreshStatePulling) {// 即将刷新 && 手松开 + // 开始刷新 + [self beginRefreshing]; + } else if (pullingPercent < 1) { + self.pullingPercent = pullingPercent; + } +} + +- (void)setState:(MJRefreshState)state +{ + MJRefreshCheckState + + // 根据状态做事情 + if (state == MJRefreshStateIdle) { + if (oldState != MJRefreshStateRefreshing) return; + + // 保存刷新时间 + [[NSUserDefaults standardUserDefaults] setObject:[NSDate date] forKey:self.lastUpdatedTimeKey]; + [[NSUserDefaults standardUserDefaults] synchronize]; + + // 恢复inset和offset + [UIView animateWithDuration:MJRefreshSlowAnimationDuration animations:^{ + self.scrollView.mj_insetT += self.insetTDelta; + + // 自动调整透明度 + if (self.isAutomaticallyChangeAlpha) self.alpha = 0.0; + } completion:^(BOOL finished) { + self.pullingPercent = 0.0; + + if (self.endRefreshingCompletionBlock) { + self.endRefreshingCompletionBlock(); + } + }]; + } else if (state == MJRefreshStateRefreshing) { + dispatch_async(dispatch_get_main_queue(), ^{ + [UIView animateWithDuration:MJRefreshFastAnimationDuration animations:^{ + CGFloat top = self.scrollViewOriginalInset.top + self.mj_h; + // 增加滚动区域top + self.scrollView.mj_insetT = top; + // 设置滚动位置 + [self.scrollView setContentOffset:CGPointMake(0, -top) animated:NO]; + } completion:^(BOOL finished) { + [self executeRefreshingCallback]; + }]; + }); + } +} + +#pragma mark - 公共方法 +- (void)endRefreshing +{ + dispatch_async(dispatch_get_main_queue(), ^{ + self.state = MJRefreshStateIdle; + }); +} + +- (NSDate *)lastUpdatedTime +{ + return [[NSUserDefaults standardUserDefaults] objectForKey:self.lastUpdatedTimeKey]; +} +@end diff --git a/IOS/Playground/Pods/MJRefresh/MJRefresh/Custom/Footer/Auto/MJRefreshAutoGifFooter.h b/IOS/Playground/Pods/MJRefresh/MJRefresh/Custom/Footer/Auto/MJRefreshAutoGifFooter.h new file mode 100644 index 00000000..6a127e6c --- /dev/null +++ b/IOS/Playground/Pods/MJRefresh/MJRefresh/Custom/Footer/Auto/MJRefreshAutoGifFooter.h @@ -0,0 +1,17 @@ +// +// MJRefreshAutoGifFooter.h +// MJRefreshExample +// +// Created by MJ Lee on 15/4/24. +// Copyright (c) 2015年 小码哥. All rights reserved. +// + +#import "MJRefreshAutoStateFooter.h" + +@interface MJRefreshAutoGifFooter : MJRefreshAutoStateFooter +@property (weak, nonatomic, readonly) UIImageView *gifView; + +/** 设置state状态下的动画图片images 动画持续时间duration*/ +- (void)setImages:(NSArray *)images duration:(NSTimeInterval)duration forState:(MJRefreshState)state; +- (void)setImages:(NSArray *)images forState:(MJRefreshState)state; +@end diff --git a/IOS/Playground/Pods/MJRefresh/MJRefresh/Custom/Footer/Auto/MJRefreshAutoGifFooter.m b/IOS/Playground/Pods/MJRefresh/MJRefresh/Custom/Footer/Auto/MJRefreshAutoGifFooter.m new file mode 100644 index 00000000..25071381 --- /dev/null +++ b/IOS/Playground/Pods/MJRefresh/MJRefresh/Custom/Footer/Auto/MJRefreshAutoGifFooter.m @@ -0,0 +1,116 @@ +// +// MJRefreshAutoGifFooter.m +// MJRefreshExample +// +// Created by MJ Lee on 15/4/24. +// Copyright (c) 2015年 小码哥. All rights reserved. +// + +#import "MJRefreshAutoGifFooter.h" + +@interface MJRefreshAutoGifFooter() +{ + __unsafe_unretained UIImageView *_gifView; +} +/** 所有状态对应的动画图片 */ +@property (strong, nonatomic) NSMutableDictionary *stateImages; +/** 所有状态对应的动画时间 */ +@property (strong, nonatomic) NSMutableDictionary *stateDurations; +@end + +@implementation MJRefreshAutoGifFooter +#pragma mark - 懒加载 +- (UIImageView *)gifView +{ + if (!_gifView) { + UIImageView *gifView = [[UIImageView alloc] init]; + [self addSubview:_gifView = gifView]; + } + return _gifView; +} + +- (NSMutableDictionary *)stateImages +{ + if (!_stateImages) { + self.stateImages = [NSMutableDictionary dictionary]; + } + return _stateImages; +} + +- (NSMutableDictionary *)stateDurations +{ + if (!_stateDurations) { + self.stateDurations = [NSMutableDictionary dictionary]; + } + return _stateDurations; +} + +#pragma mark - 公共方法 +- (void)setImages:(NSArray *)images duration:(NSTimeInterval)duration forState:(MJRefreshState)state +{ + if (images == nil) return; + + self.stateImages[@(state)] = images; + self.stateDurations[@(state)] = @(duration); + + /* 根据图片设置控件的高度 */ + UIImage *image = [images firstObject]; + if (image.size.height > self.mj_h) { + self.mj_h = image.size.height; + } +} + +- (void)setImages:(NSArray *)images forState:(MJRefreshState)state +{ + [self setImages:images duration:images.count * 0.1 forState:state]; +} + +#pragma mark - 实现父类的方法 +- (void)prepare +{ + [super prepare]; + + // 初始化间距 + self.labelLeftInset = 20; +} + +- (void)placeSubviews +{ + [super placeSubviews]; + + if (self.gifView.constraints.count) return; + + self.gifView.frame = self.bounds; + if (self.isRefreshingTitleHidden) { + self.gifView.contentMode = UIViewContentModeCenter; + } else { + self.gifView.contentMode = UIViewContentModeRight; + self.gifView.mj_w = self.mj_w * 0.5 - self.labelLeftInset - self.stateLabel.mj_textWith * 0.5; + } +} + +- (void)setState:(MJRefreshState)state +{ + MJRefreshCheckState + + // 根据状态做事情 + if (state == MJRefreshStateRefreshing) { + NSArray *images = self.stateImages[@(state)]; + if (images.count == 0) return; + [self.gifView stopAnimating]; + + self.gifView.hidden = NO; + if (images.count == 1) { // 单张图片 + self.gifView.image = [images lastObject]; + } else { // 多张图片 + self.gifView.animationImages = images; + self.gifView.animationDuration = [self.stateDurations[@(state)] doubleValue]; + [self.gifView startAnimating]; + } + } else if (state == MJRefreshStateNoMoreData || state == MJRefreshStateIdle) { + [self.gifView stopAnimating]; + self.gifView.hidden = YES; + } +} +@end + diff --git a/IOS/Playground/Pods/MJRefresh/MJRefresh/Custom/Footer/Auto/MJRefreshAutoNormalFooter.h b/IOS/Playground/Pods/MJRefresh/MJRefresh/Custom/Footer/Auto/MJRefreshAutoNormalFooter.h new file mode 100644 index 00000000..5549cff5 --- /dev/null +++ b/IOS/Playground/Pods/MJRefresh/MJRefresh/Custom/Footer/Auto/MJRefreshAutoNormalFooter.h @@ -0,0 +1,14 @@ +// +// MJRefreshAutoNormalFooter.h +// MJRefreshExample +// +// Created by MJ Lee on 15/4/24. +// Copyright (c) 2015年 小码哥. All rights reserved. +// + +#import "MJRefreshAutoStateFooter.h" + +@interface MJRefreshAutoNormalFooter : MJRefreshAutoStateFooter +/** 菊花的样式 */ +@property (assign, nonatomic) UIActivityIndicatorViewStyle activityIndicatorViewStyle; +@end diff --git a/IOS/Playground/Pods/MJRefresh/MJRefresh/Custom/Footer/Auto/MJRefreshAutoNormalFooter.m b/IOS/Playground/Pods/MJRefresh/MJRefresh/Custom/Footer/Auto/MJRefreshAutoNormalFooter.m new file mode 100644 index 00000000..dae90606 --- /dev/null +++ b/IOS/Playground/Pods/MJRefresh/MJRefresh/Custom/Footer/Auto/MJRefreshAutoNormalFooter.m @@ -0,0 +1,69 @@ +// +// MJRefreshAutoNormalFooter.m +// MJRefreshExample +// +// Created by MJ Lee on 15/4/24. +// Copyright (c) 2015年 小码哥. All rights reserved. +// + +#import "MJRefreshAutoNormalFooter.h" + +@interface MJRefreshAutoNormalFooter() +@property (weak, nonatomic) UIActivityIndicatorView *loadingView; +@end + +@implementation MJRefreshAutoNormalFooter +#pragma mark - 懒加载子控件 +- (UIActivityIndicatorView *)loadingView +{ + if (!_loadingView) { + UIActivityIndicatorView *loadingView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:self.activityIndicatorViewStyle]; + loadingView.hidesWhenStopped = YES; + [self addSubview:_loadingView = loadingView]; + } + return _loadingView; +} + +- (void)setActivityIndicatorViewStyle:(UIActivityIndicatorViewStyle)activityIndicatorViewStyle +{ + _activityIndicatorViewStyle = activityIndicatorViewStyle; + + self.loadingView = nil; + [self setNeedsLayout]; +} +#pragma mark - 重写父类的方法 +- (void)prepare +{ + [super prepare]; + + self.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray; +} + +- (void)placeSubviews +{ + [super placeSubviews]; + + if (self.loadingView.constraints.count) return; + + // 圈圈 + CGFloat loadingCenterX = self.mj_w * 0.5; + if (!self.isRefreshingTitleHidden) { + loadingCenterX -= self.stateLabel.mj_textWith * 0.5 + self.labelLeftInset; + } + CGFloat loadingCenterY = self.mj_h * 0.5; + self.loadingView.center = CGPointMake(loadingCenterX, loadingCenterY); +} + +- (void)setState:(MJRefreshState)state +{ + MJRefreshCheckState + + // 根据状态做事情 + if (state == MJRefreshStateNoMoreData || state == MJRefreshStateIdle) { + [self.loadingView stopAnimating]; + } else if (state == MJRefreshStateRefreshing) { + [self.loadingView startAnimating]; + } +} + +@end diff --git a/IOS/Playground/Pods/MJRefresh/MJRefresh/Custom/Footer/Auto/MJRefreshAutoStateFooter.h b/IOS/Playground/Pods/MJRefresh/MJRefresh/Custom/Footer/Auto/MJRefreshAutoStateFooter.h new file mode 100644 index 00000000..9fe7915b --- /dev/null +++ b/IOS/Playground/Pods/MJRefresh/MJRefresh/Custom/Footer/Auto/MJRefreshAutoStateFooter.h @@ -0,0 +1,22 @@ +// +// MJRefreshAutoStateFooter.h +// MJRefreshExample +// +// Created by MJ Lee on 15/6/13. +// Copyright © 2015年 小码哥. All rights reserved. +// + +#import "MJRefreshAutoFooter.h" + +@interface MJRefreshAutoStateFooter : MJRefreshAutoFooter +/** 文字距离圈圈、箭头的距离 */ +@property (assign, nonatomic) CGFloat labelLeftInset; +/** 显示刷新状态的label */ +@property (weak, nonatomic, readonly) UILabel *stateLabel; + +/** 设置state状态下的文字 */ +- (void)setTitle:(NSString *)title forState:(MJRefreshState)state; + +/** 隐藏刷新状态的文字 */ +@property (assign, nonatomic, getter=isRefreshingTitleHidden) BOOL refreshingTitleHidden; +@end diff --git a/IOS/Playground/Pods/MJRefresh/MJRefresh/Custom/Footer/Auto/MJRefreshAutoStateFooter.m b/IOS/Playground/Pods/MJRefresh/MJRefresh/Custom/Footer/Auto/MJRefreshAutoStateFooter.m new file mode 100644 index 00000000..d16547de --- /dev/null +++ b/IOS/Playground/Pods/MJRefresh/MJRefresh/Custom/Footer/Auto/MJRefreshAutoStateFooter.m @@ -0,0 +1,92 @@ +// +// MJRefreshAutoStateFooter.m +// MJRefreshExample +// +// Created by MJ Lee on 15/6/13. +// Copyright © 2015年 小码哥. All rights reserved. +// + +#import "MJRefreshAutoStateFooter.h" + +@interface MJRefreshAutoStateFooter() +{ + /** 显示刷新状态的label */ + __unsafe_unretained UILabel *_stateLabel; +} +/** 所有状态对应的文字 */ +@property (strong, nonatomic) NSMutableDictionary *stateTitles; +@end + +@implementation MJRefreshAutoStateFooter +#pragma mark - 懒加载 +- (NSMutableDictionary *)stateTitles +{ + if (!_stateTitles) { + self.stateTitles = [NSMutableDictionary dictionary]; + } + return _stateTitles; +} + +- (UILabel *)stateLabel +{ + if (!_stateLabel) { + [self addSubview:_stateLabel = [UILabel mj_label]]; + } + return _stateLabel; +} + +#pragma mark - 公共方法 +- (void)setTitle:(NSString *)title forState:(MJRefreshState)state +{ + if (title == nil) return; + self.stateTitles[@(state)] = title; + self.stateLabel.text = self.stateTitles[@(self.state)]; +} + +#pragma mark - 私有方法 +- (void)stateLabelClick +{ + if (self.state == MJRefreshStateIdle) { + [self beginRefreshing]; + } +} + +#pragma mark - 重写父类的方法 +- (void)prepare +{ + [super prepare]; + + // 初始化间距 + self.labelLeftInset = MJRefreshLabelLeftInset; + + // 初始化文字 + [self setTitle:[NSBundle mj_localizedStringForKey:MJRefreshAutoFooterIdleText] forState:MJRefreshStateIdle]; + [self setTitle:[NSBundle mj_localizedStringForKey:MJRefreshAutoFooterRefreshingText] forState:MJRefreshStateRefreshing]; + [self setTitle:[NSBundle mj_localizedStringForKey:MJRefreshAutoFooterNoMoreDataText] forState:MJRefreshStateNoMoreData]; + + // 监听label + self.stateLabel.userInteractionEnabled = YES; + [self.stateLabel addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(stateLabelClick)]]; +} + +- (void)placeSubviews +{ + [super placeSubviews]; + + if (self.stateLabel.constraints.count) return; + + // 状态标签 + self.stateLabel.frame = self.bounds; +} + +- (void)setState:(MJRefreshState)state +{ + MJRefreshCheckState + + if (self.isRefreshingTitleHidden && state == MJRefreshStateRefreshing) { + self.stateLabel.text = nil; + } else { + self.stateLabel.text = self.stateTitles[@(state)]; + } +} +@end \ No newline at end of file diff --git a/IOS/Playground/Pods/MJRefresh/MJRefresh/Custom/Footer/Back/MJRefreshBackGifFooter.h b/IOS/Playground/Pods/MJRefresh/MJRefresh/Custom/Footer/Back/MJRefreshBackGifFooter.h new file mode 100644 index 00000000..b29af869 --- /dev/null +++ b/IOS/Playground/Pods/MJRefresh/MJRefresh/Custom/Footer/Back/MJRefreshBackGifFooter.h @@ -0,0 +1,17 @@ +// +// MJRefreshBackGifFooter.h +// MJRefreshExample +// +// Created by MJ Lee on 15/4/24. +// Copyright (c) 2015年 小码哥. All rights reserved. +// + +#import "MJRefreshBackStateFooter.h" + +@interface MJRefreshBackGifFooter : MJRefreshBackStateFooter +@property (weak, nonatomic, readonly) UIImageView *gifView; + +/** 设置state状态下的动画图片images 动画持续时间duration*/ +- (void)setImages:(NSArray *)images duration:(NSTimeInterval)duration forState:(MJRefreshState)state; +- (void)setImages:(NSArray *)images forState:(MJRefreshState)state; +@end diff --git a/IOS/Playground/Pods/MJRefresh/MJRefresh/Custom/Footer/Back/MJRefreshBackGifFooter.m b/IOS/Playground/Pods/MJRefresh/MJRefresh/Custom/Footer/Back/MJRefreshBackGifFooter.m new file mode 100644 index 00000000..fa97c72c --- /dev/null +++ b/IOS/Playground/Pods/MJRefresh/MJRefresh/Custom/Footer/Back/MJRefreshBackGifFooter.m @@ -0,0 +1,127 @@ +// +// MJRefreshBackGifFooter.m +// MJRefreshExample +// +// Created by MJ Lee on 15/4/24. +// Copyright (c) 2015年 小码哥. All rights reserved. +// + +#import "MJRefreshBackGifFooter.h" + +@interface MJRefreshBackGifFooter() +{ + __unsafe_unretained UIImageView *_gifView; +} +/** 所有状态对应的动画图片 */ +@property (strong, nonatomic) NSMutableDictionary *stateImages; +/** 所有状态对应的动画时间 */ +@property (strong, nonatomic) NSMutableDictionary *stateDurations; +@end + +@implementation MJRefreshBackGifFooter +#pragma mark - 懒加载 +- (UIImageView *)gifView +{ + if (!_gifView) { + UIImageView *gifView = [[UIImageView alloc] init]; + [self addSubview:_gifView = gifView]; + } + return _gifView; +} + +- (NSMutableDictionary *)stateImages +{ + if (!_stateImages) { + self.stateImages = [NSMutableDictionary dictionary]; + } + return _stateImages; +} + +- (NSMutableDictionary *)stateDurations +{ + if (!_stateDurations) { + self.stateDurations = [NSMutableDictionary dictionary]; + } + return _stateDurations; +} + +#pragma mark - 公共方法 +- (void)setImages:(NSArray *)images duration:(NSTimeInterval)duration forState:(MJRefreshState)state +{ + if (images == nil) return; + + self.stateImages[@(state)] = images; + self.stateDurations[@(state)] = @(duration); + + /* 根据图片设置控件的高度 */ + UIImage *image = [images firstObject]; + if (image.size.height > self.mj_h) { + self.mj_h = image.size.height; + } +} + +- (void)setImages:(NSArray *)images forState:(MJRefreshState)state +{ + [self setImages:images duration:images.count * 0.1 forState:state]; +} + +#pragma mark - 实现父类的方法 +- (void)prepare +{ + [super prepare]; + + // 初始化间距 + self.labelLeftInset = 20; +} + +- (void)setPullingPercent:(CGFloat)pullingPercent +{ + [super setPullingPercent:pullingPercent]; + NSArray *images = self.stateImages[@(MJRefreshStateIdle)]; + if (self.state != MJRefreshStateIdle || images.count == 0) return; + [self.gifView stopAnimating]; + NSUInteger index = images.count * pullingPercent; + if (index >= images.count) index = images.count - 1; + self.gifView.image = images[index]; +} + +- (void)placeSubviews +{ + [super placeSubviews]; + + if (self.gifView.constraints.count) return; + + self.gifView.frame = self.bounds; + if (self.stateLabel.hidden) { + self.gifView.contentMode = UIViewContentModeCenter; + } else { + self.gifView.contentMode = UIViewContentModeRight; + self.gifView.mj_w = self.mj_w * 0.5 - self.labelLeftInset - self.stateLabel.mj_textWith * 0.5; + } +} + +- (void)setState:(MJRefreshState)state +{ + MJRefreshCheckState + + // 根据状态做事情 + if (state == MJRefreshStatePulling || state == MJRefreshStateRefreshing) { + NSArray *images = self.stateImages[@(state)]; + if (images.count == 0) return; + + self.gifView.hidden = NO; + [self.gifView stopAnimating]; + if (images.count == 1) { // 单张图片 + self.gifView.image = [images lastObject]; + } else { // 多张图片 + self.gifView.animationImages = images; + self.gifView.animationDuration = [self.stateDurations[@(state)] doubleValue]; + [self.gifView startAnimating]; + } + } else if (state == MJRefreshStateIdle) { + self.gifView.hidden = NO; + } else if (state == MJRefreshStateNoMoreData) { + self.gifView.hidden = YES; + } +} +@end diff --git a/IOS/Playground/Pods/MJRefresh/MJRefresh/Custom/Footer/Back/MJRefreshBackNormalFooter.h b/IOS/Playground/Pods/MJRefresh/MJRefresh/Custom/Footer/Back/MJRefreshBackNormalFooter.h new file mode 100644 index 00000000..90e8b776 --- /dev/null +++ b/IOS/Playground/Pods/MJRefresh/MJRefresh/Custom/Footer/Back/MJRefreshBackNormalFooter.h @@ -0,0 +1,15 @@ +// +// MJRefreshBackNormalFooter.h +// MJRefreshExample +// +// Created by MJ Lee on 15/4/24. +// Copyright (c) 2015年 小码哥. All rights reserved. +// + +#import "MJRefreshBackStateFooter.h" + +@interface MJRefreshBackNormalFooter : MJRefreshBackStateFooter +@property (weak, nonatomic, readonly) UIImageView *arrowView; +/** 菊花的样式 */ +@property (assign, nonatomic) UIActivityIndicatorViewStyle activityIndicatorViewStyle; +@end diff --git a/IOS/Playground/Pods/MJRefresh/MJRefresh/Custom/Footer/Back/MJRefreshBackNormalFooter.m b/IOS/Playground/Pods/MJRefresh/MJRefresh/Custom/Footer/Back/MJRefreshBackNormalFooter.m new file mode 100644 index 00000000..30e5ecf7 --- /dev/null +++ b/IOS/Playground/Pods/MJRefresh/MJRefresh/Custom/Footer/Back/MJRefreshBackNormalFooter.m @@ -0,0 +1,120 @@ +// +// MJRefreshBackNormalFooter.m +// MJRefreshExample +// +// Created by MJ Lee on 15/4/24. +// Copyright (c) 2015年 小码哥. All rights reserved. +// + +#import "MJRefreshBackNormalFooter.h" +#import "NSBundle+MJRefresh.h" + +@interface MJRefreshBackNormalFooter() +{ + __unsafe_unretained UIImageView *_arrowView; +} +@property (weak, nonatomic) UIActivityIndicatorView *loadingView; +@end + +@implementation MJRefreshBackNormalFooter +#pragma mark - 懒加载子控件 +- (UIImageView *)arrowView +{ + if (!_arrowView) { + UIImageView *arrowView = [[UIImageView alloc] initWithImage:[NSBundle mj_arrowImage]]; + [self addSubview:_arrowView = arrowView]; + } + return _arrowView; +} + + +- (UIActivityIndicatorView *)loadingView +{ + if (!_loadingView) { + UIActivityIndicatorView *loadingView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:self.activityIndicatorViewStyle]; + loadingView.hidesWhenStopped = YES; + [self addSubview:_loadingView = loadingView]; + } + return _loadingView; +} + +- (void)setActivityIndicatorViewStyle:(UIActivityIndicatorViewStyle)activityIndicatorViewStyle +{ + _activityIndicatorViewStyle = activityIndicatorViewStyle; + + self.loadingView = nil; + [self setNeedsLayout]; +} +#pragma mark - 重写父类的方法 +- (void)prepare +{ + [super prepare]; + + self.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray; +} + +- (void)placeSubviews +{ + [super placeSubviews]; + + // 箭头的中心点 + CGFloat arrowCenterX = self.mj_w * 0.5; + if (!self.stateLabel.hidden) { + arrowCenterX -= self.labelLeftInset + self.stateLabel.mj_textWith * 0.5; + } + CGFloat arrowCenterY = self.mj_h * 0.5; + CGPoint arrowCenter = CGPointMake(arrowCenterX, arrowCenterY); + + // 箭头 + if (self.arrowView.constraints.count == 0) { + self.arrowView.mj_size = self.arrowView.image.size; + self.arrowView.center = arrowCenter; + } + + // 圈圈 + if (self.loadingView.constraints.count == 0) { + self.loadingView.center = arrowCenter; + } + + self.arrowView.tintColor = self.stateLabel.textColor; +} + +- (void)setState:(MJRefreshState)state +{ + MJRefreshCheckState + + // 根据状态做事情 + if (state == MJRefreshStateIdle) { + if (oldState == MJRefreshStateRefreshing) { + self.arrowView.transform = CGAffineTransformMakeRotation(0.000001 - M_PI); + [UIView animateWithDuration:MJRefreshSlowAnimationDuration animations:^{ + self.loadingView.alpha = 0.0; + } completion:^(BOOL finished) { + self.loadingView.alpha = 1.0; + [self.loadingView stopAnimating]; + + self.arrowView.hidden = NO; + }]; + } else { + self.arrowView.hidden = NO; + [self.loadingView stopAnimating]; + [UIView animateWithDuration:MJRefreshFastAnimationDuration animations:^{ + self.arrowView.transform = CGAffineTransformMakeRotation(0.000001 - M_PI); + }]; + } + } else if (state == MJRefreshStatePulling) { + self.arrowView.hidden = NO; + [self.loadingView stopAnimating]; + [UIView animateWithDuration:MJRefreshFastAnimationDuration animations:^{ + self.arrowView.transform = CGAffineTransformIdentity; + }]; + } else if (state == MJRefreshStateRefreshing) { + self.arrowView.hidden = YES; + [self.loadingView startAnimating]; + } else if (state == MJRefreshStateNoMoreData) { + self.arrowView.hidden = YES; + [self.loadingView stopAnimating]; + } +} + +@end diff --git a/IOS/Playground/Pods/MJRefresh/MJRefresh/Custom/Footer/Back/MJRefreshBackStateFooter.h b/IOS/Playground/Pods/MJRefresh/MJRefresh/Custom/Footer/Back/MJRefreshBackStateFooter.h new file mode 100644 index 00000000..99b1483d --- /dev/null +++ b/IOS/Playground/Pods/MJRefresh/MJRefresh/Custom/Footer/Back/MJRefreshBackStateFooter.h @@ -0,0 +1,21 @@ +// +// MJRefreshBackStateFooter.h +// MJRefreshExample +// +// Created by MJ Lee on 15/6/13. +// Copyright © 2015年 小码哥. All rights reserved. +// + +#import "MJRefreshBackFooter.h" + +@interface MJRefreshBackStateFooter : MJRefreshBackFooter +/** 文字距离圈圈、箭头的距离 */ +@property (assign, nonatomic) CGFloat labelLeftInset; +/** 显示刷新状态的label */ +@property (weak, nonatomic, readonly) UILabel *stateLabel; +/** 设置state状态下的文字 */ +- (void)setTitle:(NSString *)title forState:(MJRefreshState)state; + +/** 获取state状态下的title */ +- (NSString *)titleForState:(MJRefreshState)state; +@end diff --git a/IOS/Playground/Pods/MJRefresh/MJRefresh/Custom/Footer/Back/MJRefreshBackStateFooter.m b/IOS/Playground/Pods/MJRefresh/MJRefresh/Custom/Footer/Back/MJRefreshBackStateFooter.m new file mode 100644 index 00000000..cc784d00 --- /dev/null +++ b/IOS/Playground/Pods/MJRefresh/MJRefresh/Custom/Footer/Back/MJRefreshBackStateFooter.m @@ -0,0 +1,82 @@ +// +// MJRefreshBackStateFooter.m +// MJRefreshExample +// +// Created by MJ Lee on 15/6/13. +// Copyright © 2015年 小码哥. All rights reserved. +// + +#import "MJRefreshBackStateFooter.h" + +@interface MJRefreshBackStateFooter() +{ + /** 显示刷新状态的label */ + __unsafe_unretained UILabel *_stateLabel; +} +/** 所有状态对应的文字 */ +@property (strong, nonatomic) NSMutableDictionary *stateTitles; +@end + +@implementation MJRefreshBackStateFooter +#pragma mark - 懒加载 +- (NSMutableDictionary *)stateTitles +{ + if (!_stateTitles) { + self.stateTitles = [NSMutableDictionary dictionary]; + } + return _stateTitles; +} + +- (UILabel *)stateLabel +{ + if (!_stateLabel) { + [self addSubview:_stateLabel = [UILabel mj_label]]; + } + return _stateLabel; +} + +#pragma mark - 公共方法 +- (void)setTitle:(NSString *)title forState:(MJRefreshState)state +{ + if (title == nil) return; + self.stateTitles[@(state)] = title; + self.stateLabel.text = self.stateTitles[@(self.state)]; +} + +- (NSString *)titleForState:(MJRefreshState)state { + return self.stateTitles[@(state)]; +} + +#pragma mark - 重写父类的方法 +- (void)prepare +{ + [super prepare]; + + // 初始化间距 + self.labelLeftInset = MJRefreshLabelLeftInset; + + // 初始化文字 + [self setTitle:[NSBundle mj_localizedStringForKey:MJRefreshBackFooterIdleText] forState:MJRefreshStateIdle]; + [self setTitle:[NSBundle mj_localizedStringForKey:MJRefreshBackFooterPullingText] forState:MJRefreshStatePulling]; + [self setTitle:[NSBundle mj_localizedStringForKey:MJRefreshBackFooterRefreshingText] forState:MJRefreshStateRefreshing]; + [self setTitle:[NSBundle mj_localizedStringForKey:MJRefreshBackFooterNoMoreDataText] forState:MJRefreshStateNoMoreData]; +} + +- (void)placeSubviews +{ + [super placeSubviews]; + + if (self.stateLabel.constraints.count) return; + + // 状态标签 + self.stateLabel.frame = self.bounds; +} + +- (void)setState:(MJRefreshState)state +{ + MJRefreshCheckState + + // 设置状态文字 + self.stateLabel.text = self.stateTitles[@(state)]; +} +@end diff --git a/IOS/Playground/Pods/MJRefresh/MJRefresh/Custom/Header/MJRefreshGifHeader.h b/IOS/Playground/Pods/MJRefresh/MJRefresh/Custom/Header/MJRefreshGifHeader.h new file mode 100644 index 00000000..ce3ed428 --- /dev/null +++ b/IOS/Playground/Pods/MJRefresh/MJRefresh/Custom/Header/MJRefreshGifHeader.h @@ -0,0 +1,17 @@ +// +// MJRefreshGifHeader.h +// MJRefreshExample +// +// Created by MJ Lee on 15/4/24. +// Copyright (c) 2015年 小码哥. All rights reserved. +// + +#import "MJRefreshStateHeader.h" + +@interface MJRefreshGifHeader : MJRefreshStateHeader +@property (weak, nonatomic, readonly) UIImageView *gifView; + +/** 设置state状态下的动画图片images 动画持续时间duration*/ +- (void)setImages:(NSArray *)images duration:(NSTimeInterval)duration forState:(MJRefreshState)state; +- (void)setImages:(NSArray *)images forState:(MJRefreshState)state; +@end diff --git a/IOS/Playground/Pods/MJRefresh/MJRefresh/Custom/Header/MJRefreshGifHeader.m b/IOS/Playground/Pods/MJRefresh/MJRefresh/Custom/Header/MJRefreshGifHeader.m new file mode 100644 index 00000000..f8bcc9ba --- /dev/null +++ b/IOS/Playground/Pods/MJRefresh/MJRefresh/Custom/Header/MJRefreshGifHeader.m @@ -0,0 +1,133 @@ +// +// MJRefreshGifHeader.m +// MJRefreshExample +// +// Created by MJ Lee on 15/4/24. +// Copyright (c) 2015年 小码哥. All rights reserved. +// + +#import "MJRefreshGifHeader.h" + +@interface MJRefreshGifHeader() +{ + __unsafe_unretained UIImageView *_gifView; +} +/** 所有状态对应的动画图片 */ +@property (strong, nonatomic) NSMutableDictionary *stateImages; +/** 所有状态对应的动画时间 */ +@property (strong, nonatomic) NSMutableDictionary *stateDurations; +@end + +@implementation MJRefreshGifHeader +#pragma mark - 懒加载 +- (UIImageView *)gifView +{ + if (!_gifView) { + UIImageView *gifView = [[UIImageView alloc] init]; + [self addSubview:_gifView = gifView]; + } + return _gifView; +} + +- (NSMutableDictionary *)stateImages +{ + if (!_stateImages) { + self.stateImages = [NSMutableDictionary dictionary]; + } + return _stateImages; +} + +- (NSMutableDictionary *)stateDurations +{ + if (!_stateDurations) { + self.stateDurations = [NSMutableDictionary dictionary]; + } + return _stateDurations; +} + +#pragma mark - 公共方法 +- (void)setImages:(NSArray *)images duration:(NSTimeInterval)duration forState:(MJRefreshState)state +{ + if (images == nil) return; + + self.stateImages[@(state)] = images; + self.stateDurations[@(state)] = @(duration); + + /* 根据图片设置控件的高度 */ + UIImage *image = [images firstObject]; + if (image.size.height > self.mj_h) { + self.mj_h = image.size.height; + } +} + +- (void)setImages:(NSArray *)images forState:(MJRefreshState)state +{ + [self setImages:images duration:images.count * 0.1 forState:state]; +} + +#pragma mark - 实现父类的方法 +- (void)prepare +{ + [super prepare]; + + // 初始化间距 + self.labelLeftInset = 20; +} + +- (void)setPullingPercent:(CGFloat)pullingPercent +{ + [super setPullingPercent:pullingPercent]; + NSArray *images = self.stateImages[@(MJRefreshStateIdle)]; + if (self.state != MJRefreshStateIdle || images.count == 0) return; + // 停止动画 + [self.gifView stopAnimating]; + // 设置当前需要显示的图片 + NSUInteger index = images.count * pullingPercent; + if (index >= images.count) index = images.count - 1; + self.gifView.image = images[index]; +} + +- (void)placeSubviews +{ + [super placeSubviews]; + + if (self.gifView.constraints.count) return; + + self.gifView.frame = self.bounds; + if (self.stateLabel.hidden && self.lastUpdatedTimeLabel.hidden) { + self.gifView.contentMode = UIViewContentModeCenter; + } else { + self.gifView.contentMode = UIViewContentModeRight; + + CGFloat stateWidth = self.stateLabel.mj_textWith; + CGFloat timeWidth = 0.0; + if (!self.lastUpdatedTimeLabel.hidden) { + timeWidth = self.lastUpdatedTimeLabel.mj_textWith; + } + CGFloat textWidth = MAX(stateWidth, timeWidth); + self.gifView.mj_w = self.mj_w * 0.5 - textWidth * 0.5 - self.labelLeftInset; + } +} + +- (void)setState:(MJRefreshState)state +{ + MJRefreshCheckState + + // 根据状态做事情 + if (state == MJRefreshStatePulling || state == MJRefreshStateRefreshing) { + NSArray *images = self.stateImages[@(state)]; + if (images.count == 0) return; + + [self.gifView stopAnimating]; + if (images.count == 1) { // 单张图片 + self.gifView.image = [images lastObject]; + } else { // 多张图片 + self.gifView.animationImages = images; + self.gifView.animationDuration = [self.stateDurations[@(state)] doubleValue]; + [self.gifView startAnimating]; + } + } else if (state == MJRefreshStateIdle) { + [self.gifView stopAnimating]; + } +} +@end diff --git a/IOS/Playground/Pods/MJRefresh/MJRefresh/Custom/Header/MJRefreshNormalHeader.h b/IOS/Playground/Pods/MJRefresh/MJRefresh/Custom/Header/MJRefreshNormalHeader.h new file mode 100644 index 00000000..547d05e7 --- /dev/null +++ b/IOS/Playground/Pods/MJRefresh/MJRefresh/Custom/Header/MJRefreshNormalHeader.h @@ -0,0 +1,15 @@ +// +// MJRefreshNormalHeader.h +// MJRefreshExample +// +// Created by MJ Lee on 15/4/24. +// Copyright (c) 2015年 小码哥. All rights reserved. +// + +#import "MJRefreshStateHeader.h" + +@interface MJRefreshNormalHeader : MJRefreshStateHeader +@property (weak, nonatomic, readonly) UIImageView *arrowView; +/** 菊花的样式 */ +@property (assign, nonatomic) UIActivityIndicatorViewStyle activityIndicatorViewStyle; +@end diff --git a/IOS/Playground/Pods/MJRefresh/MJRefresh/Custom/Header/MJRefreshNormalHeader.m b/IOS/Playground/Pods/MJRefresh/MJRefresh/Custom/Header/MJRefreshNormalHeader.m new file mode 100644 index 00000000..32d8de70 --- /dev/null +++ b/IOS/Playground/Pods/MJRefresh/MJRefresh/Custom/Header/MJRefreshNormalHeader.m @@ -0,0 +1,127 @@ +// +// MJRefreshNormalHeader.m +// MJRefreshExample +// +// Created by MJ Lee on 15/4/24. +// Copyright (c) 2015年 小码哥. All rights reserved. +// + +#import "MJRefreshNormalHeader.h" +#import "NSBundle+MJRefresh.h" + +@interface MJRefreshNormalHeader() +{ + __unsafe_unretained UIImageView *_arrowView; +} +@property (weak, nonatomic) UIActivityIndicatorView *loadingView; +@end + +@implementation MJRefreshNormalHeader +#pragma mark - 懒加载子控件 +- (UIImageView *)arrowView +{ + if (!_arrowView) { + UIImageView *arrowView = [[UIImageView alloc] initWithImage:[NSBundle mj_arrowImage]]; + [self addSubview:_arrowView = arrowView]; + } + return _arrowView; +} + +- (UIActivityIndicatorView *)loadingView +{ + if (!_loadingView) { + UIActivityIndicatorView *loadingView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:self.activityIndicatorViewStyle]; + loadingView.hidesWhenStopped = YES; + [self addSubview:_loadingView = loadingView]; + } + return _loadingView; +} + +#pragma mark - 公共方法 +- (void)setActivityIndicatorViewStyle:(UIActivityIndicatorViewStyle)activityIndicatorViewStyle +{ + _activityIndicatorViewStyle = activityIndicatorViewStyle; + + self.loadingView = nil; + [self setNeedsLayout]; +} + +#pragma mark - 重写父类的方法 +- (void)prepare +{ + [super prepare]; + + self.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray; +} + +- (void)placeSubviews +{ + [super placeSubviews]; + + // 箭头的中心点 + CGFloat arrowCenterX = self.mj_w * 0.5; + if (!self.stateLabel.hidden) { + CGFloat stateWidth = self.stateLabel.mj_textWith; + CGFloat timeWidth = 0.0; + if (!self.lastUpdatedTimeLabel.hidden) { + timeWidth = self.lastUpdatedTimeLabel.mj_textWith; + } + CGFloat textWidth = MAX(stateWidth, timeWidth); + arrowCenterX -= textWidth / 2 + self.labelLeftInset; + } + CGFloat arrowCenterY = self.mj_h * 0.5; + CGPoint arrowCenter = CGPointMake(arrowCenterX, arrowCenterY); + + // 箭头 + if (self.arrowView.constraints.count == 0) { + self.arrowView.mj_size = self.arrowView.image.size; + self.arrowView.center = arrowCenter; + } + + // 圈圈 + if (self.loadingView.constraints.count == 0) { + self.loadingView.center = arrowCenter; + } + + self.arrowView.tintColor = self.stateLabel.textColor; +} + +- (void)setState:(MJRefreshState)state +{ + MJRefreshCheckState + + // 根据状态做事情 + if (state == MJRefreshStateIdle) { + if (oldState == MJRefreshStateRefreshing) { + self.arrowView.transform = CGAffineTransformIdentity; + + [UIView animateWithDuration:MJRefreshSlowAnimationDuration animations:^{ + self.loadingView.alpha = 0.0; + } completion:^(BOOL finished) { + // 如果执行完动画发现不是idle状态,就直接返回,进入其他状态 + if (self.state != MJRefreshStateIdle) return; + + self.loadingView.alpha = 1.0; + [self.loadingView stopAnimating]; + self.arrowView.hidden = NO; + }]; + } else { + [self.loadingView stopAnimating]; + self.arrowView.hidden = NO; + [UIView animateWithDuration:MJRefreshFastAnimationDuration animations:^{ + self.arrowView.transform = CGAffineTransformIdentity; + }]; + } + } else if (state == MJRefreshStatePulling) { + [self.loadingView stopAnimating]; + self.arrowView.hidden = NO; + [UIView animateWithDuration:MJRefreshFastAnimationDuration animations:^{ + self.arrowView.transform = CGAffineTransformMakeRotation(0.000001 - M_PI); + }]; + } else if (state == MJRefreshStateRefreshing) { + self.loadingView.alpha = 1.0; // 防止refreshing -> idle的动画完毕动作没有被执行 + [self.loadingView startAnimating]; + self.arrowView.hidden = YES; + } +} +@end diff --git a/IOS/Playground/Pods/MJRefresh/MJRefresh/Custom/Header/MJRefreshStateHeader.h b/IOS/Playground/Pods/MJRefresh/MJRefresh/Custom/Header/MJRefreshStateHeader.h new file mode 100644 index 00000000..1f3dbc40 --- /dev/null +++ b/IOS/Playground/Pods/MJRefresh/MJRefresh/Custom/Header/MJRefreshStateHeader.h @@ -0,0 +1,25 @@ +// +// MJRefreshStateHeader.h +// MJRefreshExample +// +// Created by MJ Lee on 15/4/24. +// Copyright (c) 2015年 小码哥. All rights reserved. +// + +#import "MJRefreshHeader.h" + +@interface MJRefreshStateHeader : MJRefreshHeader +#pragma mark - 刷新时间相关 +/** 利用这个block来决定显示的更新时间文字 */ +@property (copy, nonatomic) NSString *(^lastUpdatedTimeText)(NSDate *lastUpdatedTime); +/** 显示上一次刷新时间的label */ +@property (weak, nonatomic, readonly) UILabel *lastUpdatedTimeLabel; + +#pragma mark - 状态相关 +/** 文字距离圈圈、箭头的距离 */ +@property (assign, nonatomic) CGFloat labelLeftInset; +/** 显示刷新状态的label */ +@property (weak, nonatomic, readonly) UILabel *stateLabel; +/** 设置state状态下的文字 */ +- (void)setTitle:(NSString *)title forState:(MJRefreshState)state; +@end diff --git a/IOS/Playground/Pods/MJRefresh/MJRefresh/Custom/Header/MJRefreshStateHeader.m b/IOS/Playground/Pods/MJRefresh/MJRefresh/Custom/Header/MJRefreshStateHeader.m new file mode 100644 index 00000000..ca78b526 --- /dev/null +++ b/IOS/Playground/Pods/MJRefresh/MJRefresh/Custom/Header/MJRefreshStateHeader.m @@ -0,0 +1,167 @@ +// +// MJRefreshStateHeader.m +// MJRefreshExample +// +// Created by MJ Lee on 15/4/24. +// Copyright (c) 2015年 小码哥. All rights reserved. +// + +#import "MJRefreshStateHeader.h" + +@interface MJRefreshStateHeader() +{ + /** 显示上一次刷新时间的label */ + __unsafe_unretained UILabel *_lastUpdatedTimeLabel; + /** 显示刷新状态的label */ + __unsafe_unretained UILabel *_stateLabel; +} +/** 所有状态对应的文字 */ +@property (strong, nonatomic) NSMutableDictionary *stateTitles; +@end + +@implementation MJRefreshStateHeader +#pragma mark - 懒加载 +- (NSMutableDictionary *)stateTitles +{ + if (!_stateTitles) { + self.stateTitles = [NSMutableDictionary dictionary]; + } + return _stateTitles; +} + +- (UILabel *)stateLabel +{ + if (!_stateLabel) { + [self addSubview:_stateLabel = [UILabel mj_label]]; + } + return _stateLabel; +} + +- (UILabel *)lastUpdatedTimeLabel +{ + if (!_lastUpdatedTimeLabel) { + [self addSubview:_lastUpdatedTimeLabel = [UILabel mj_label]]; + } + return _lastUpdatedTimeLabel; +} + +#pragma mark - 公共方法 +- (void)setTitle:(NSString *)title forState:(MJRefreshState)state +{ + if (title == nil) return; + self.stateTitles[@(state)] = title; + self.stateLabel.text = self.stateTitles[@(self.state)]; +} + +#pragma mark - 日历获取在9.x之后的系统使用currentCalendar会出异常。在8.0之后使用系统新API。 +- (NSCalendar *)currentCalendar { + if ([NSCalendar respondsToSelector:@selector(calendarWithIdentifier:)]) { + return [NSCalendar calendarWithIdentifier:NSCalendarIdentifierGregorian]; + } + return [NSCalendar currentCalendar]; +} + +#pragma mark key的处理 +- (void)setLastUpdatedTimeKey:(NSString *)lastUpdatedTimeKey +{ + [super setLastUpdatedTimeKey:lastUpdatedTimeKey]; + + // 如果label隐藏了,就不用再处理 + if (self.lastUpdatedTimeLabel.hidden) return; + + NSDate *lastUpdatedTime = [[NSUserDefaults standardUserDefaults] objectForKey:lastUpdatedTimeKey]; + + // 如果有block + if (self.lastUpdatedTimeText) { + self.lastUpdatedTimeLabel.text = self.lastUpdatedTimeText(lastUpdatedTime); + return; + } + + if (lastUpdatedTime) { + // 1.获得年月日 + NSCalendar *calendar = [self currentCalendar]; + NSUInteger unitFlags = NSCalendarUnitYear| NSCalendarUnitMonth | NSCalendarUnitDay |NSCalendarUnitHour |NSCalendarUnitMinute; + NSDateComponents *cmp1 = [calendar components:unitFlags fromDate:lastUpdatedTime]; + NSDateComponents *cmp2 = [calendar components:unitFlags fromDate:[NSDate date]]; + + // 2.格式化日期 + NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; + BOOL isToday = NO; + if ([cmp1 day] == [cmp2 day]) { // 今天 + formatter.dateFormat = @" HH:mm"; + isToday = YES; + } else if ([cmp1 year] == [cmp2 year]) { // 今年 + formatter.dateFormat = @"MM-dd HH:mm"; + } else { + formatter.dateFormat = @"yyyy-MM-dd HH:mm"; + } + NSString *time = [formatter stringFromDate:lastUpdatedTime]; + + // 3.显示日期 + self.lastUpdatedTimeLabel.text = [NSString stringWithFormat:@"%@%@%@", + [NSBundle mj_localizedStringForKey:MJRefreshHeaderLastTimeText], + isToday ? [NSBundle mj_localizedStringForKey:MJRefreshHeaderDateTodayText] : @"", + time]; + } else { + self.lastUpdatedTimeLabel.text = [NSString stringWithFormat:@"%@%@", + [NSBundle mj_localizedStringForKey:MJRefreshHeaderLastTimeText], + [NSBundle mj_localizedStringForKey:MJRefreshHeaderNoneLastDateText]]; + } +} + +#pragma mark - 覆盖父类的方法 +- (void)prepare +{ + [super prepare]; + + // 初始化间距 + self.labelLeftInset = MJRefreshLabelLeftInset; + + // 初始化文字 + [self setTitle:[NSBundle mj_localizedStringForKey:MJRefreshHeaderIdleText] forState:MJRefreshStateIdle]; + [self setTitle:[NSBundle mj_localizedStringForKey:MJRefreshHeaderPullingText] forState:MJRefreshStatePulling]; + [self setTitle:[NSBundle mj_localizedStringForKey:MJRefreshHeaderRefreshingText] forState:MJRefreshStateRefreshing]; +} + +- (void)placeSubviews +{ + [super placeSubviews]; + + if (self.stateLabel.hidden) return; + + BOOL noConstrainsOnStatusLabel = self.stateLabel.constraints.count == 0; + + if (self.lastUpdatedTimeLabel.hidden) { + // 状态 + if (noConstrainsOnStatusLabel) self.stateLabel.frame = self.bounds; + } else { + CGFloat stateLabelH = self.mj_h * 0.5; + // 状态 + if (noConstrainsOnStatusLabel) { + self.stateLabel.mj_x = 0; + self.stateLabel.mj_y = 0; + self.stateLabel.mj_w = self.mj_w; + self.stateLabel.mj_h = stateLabelH; + } + + // 更新时间 + if (self.lastUpdatedTimeLabel.constraints.count == 0) { + self.lastUpdatedTimeLabel.mj_x = 0; + self.lastUpdatedTimeLabel.mj_y = stateLabelH; + self.lastUpdatedTimeLabel.mj_w = self.mj_w; + self.lastUpdatedTimeLabel.mj_h = self.mj_h - self.lastUpdatedTimeLabel.mj_y; + } + } +} + +- (void)setState:(MJRefreshState)state +{ + MJRefreshCheckState + + // 设置状态文字 + self.stateLabel.text = self.stateTitles[@(state)]; + + // 重新设置key(重新显示时间) + self.lastUpdatedTimeKey = self.lastUpdatedTimeKey; +} +@end diff --git a/IOS/Playground/Pods/MJRefresh/MJRefresh/MJRefresh.bundle/arrow@2x.png b/IOS/Playground/Pods/MJRefresh/MJRefresh/MJRefresh.bundle/arrow@2x.png new file mode 100755 index 00000000..b1078de8 Binary files /dev/null and b/IOS/Playground/Pods/MJRefresh/MJRefresh/MJRefresh.bundle/arrow@2x.png differ diff --git a/IOS/Playground/Pods/MJRefresh/MJRefresh/MJRefresh.bundle/en.lproj/Localizable.strings b/IOS/Playground/Pods/MJRefresh/MJRefresh/MJRefresh.bundle/en.lproj/Localizable.strings new file mode 100644 index 00000000..a75f6b18 Binary files /dev/null and b/IOS/Playground/Pods/MJRefresh/MJRefresh/MJRefresh.bundle/en.lproj/Localizable.strings differ diff --git a/IOS/Playground/Pods/MJRefresh/MJRefresh/MJRefresh.bundle/zh-Hans.lproj/Localizable.strings b/IOS/Playground/Pods/MJRefresh/MJRefresh/MJRefresh.bundle/zh-Hans.lproj/Localizable.strings new file mode 100644 index 00000000..0a36d7e1 Binary files /dev/null and b/IOS/Playground/Pods/MJRefresh/MJRefresh/MJRefresh.bundle/zh-Hans.lproj/Localizable.strings differ diff --git a/IOS/Playground/Pods/MJRefresh/MJRefresh/MJRefresh.bundle/zh-Hant.lproj/Localizable.strings b/IOS/Playground/Pods/MJRefresh/MJRefresh/MJRefresh.bundle/zh-Hant.lproj/Localizable.strings new file mode 100644 index 00000000..7924bba7 --- /dev/null +++ b/IOS/Playground/Pods/MJRefresh/MJRefresh/MJRefresh.bundle/zh-Hant.lproj/Localizable.strings @@ -0,0 +1,16 @@ +"MJRefreshHeaderIdleText" = "下拉可以刷新"; +"MJRefreshHeaderPullingText" = "鬆開立即刷新"; +"MJRefreshHeaderRefreshingText" = "正在刷新數據中..."; + +"MJRefreshAutoFooterIdleText" = "點擊或上拉加載更多"; +"MJRefreshAutoFooterRefreshingText" = "正在加載更多的數據..."; +"MJRefreshAutoFooterNoMoreDataText" = "已經全部加載完畢"; + +"MJRefreshBackFooterIdleText" = "上拉可以加載更多"; +"MJRefreshBackFooterPullingText" = "鬆開立即加載更多"; +"MJRefreshBackFooterRefreshingText" = "正在加載更多的數據..."; +"MJRefreshBackFooterNoMoreDataText" = "已經全部加載完畢"; + +"MJRefreshHeaderLastTimeText" = "最後更新:"; +"MJRefreshHeaderDateTodayText" = "今天"; +"MJRefreshHeaderNoneLastDateText" = "無記錄"; diff --git a/IOS/Playground/Pods/MJRefresh/MJRefresh/MJRefresh.h b/IOS/Playground/Pods/MJRefresh/MJRefresh/MJRefresh.h new file mode 100644 index 00000000..196e6ecb --- /dev/null +++ b/IOS/Playground/Pods/MJRefresh/MJRefresh/MJRefresh.h @@ -0,0 +1,14 @@ +// 代码地址: https://github.com/CoderMJLee/MJRefresh +// 代码地址: http://code4app.com/ios/%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90%E4%B8%8B%E6%8B%89%E4%B8%8A%E6%8B%89%E5%88%B7%E6%96%B0/52326ce26803fabc46000000 + +#import "UIScrollView+MJRefresh.h" +#import "UIScrollView+MJExtension.h" +#import "UIView+MJExtension.h" + +#import "MJRefreshNormalHeader.h" +#import "MJRefreshGifHeader.h" + +#import "MJRefreshBackNormalFooter.h" +#import "MJRefreshBackGifFooter.h" +#import "MJRefreshAutoNormalFooter.h" +#import "MJRefreshAutoGifFooter.h" \ No newline at end of file diff --git a/IOS/Playground/Pods/MJRefresh/MJRefresh/MJRefreshConst.h b/IOS/Playground/Pods/MJRefresh/MJRefresh/MJRefreshConst.h new file mode 100644 index 00000000..4a720212 --- /dev/null +++ b/IOS/Playground/Pods/MJRefresh/MJRefresh/MJRefreshConst.h @@ -0,0 +1,67 @@ +// 代码地址: https://github.com/CoderMJLee/MJRefresh +// 代码地址: http://code4app.com/ios/%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90%E4%B8%8B%E6%8B%89%E4%B8%8A%E6%8B%89%E5%88%B7%E6%96%B0/52326ce26803fabc46000000 +#import +#import + +// 弱引用 +#define MJWeakSelf __weak typeof(self) weakSelf = self; + +// 日志输出 +#ifdef DEBUG +#define MJRefreshLog(...) NSLog(__VA_ARGS__) +#else +#define MJRefreshLog(...) +#endif + +// 过期提醒 +#define MJRefreshDeprecated(instead) NS_DEPRECATED(2_0, 2_0, 2_0, 2_0, instead) + +// 运行时objc_msgSend +#define MJRefreshMsgSend(...) ((void (*)(void *, SEL, UIView *))objc_msgSend)(__VA_ARGS__) +#define MJRefreshMsgTarget(target) (__bridge void *)(target) + +// RGB颜色 +#define MJRefreshColor(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0] + +// 文字颜色 +#define MJRefreshLabelTextColor MJRefreshColor(90, 90, 90) + +// 字体大小 +#define MJRefreshLabelFont [UIFont boldSystemFontOfSize:14] + +// 常量 +UIKIT_EXTERN const CGFloat MJRefreshLabelLeftInset; +UIKIT_EXTERN const CGFloat MJRefreshHeaderHeight; +UIKIT_EXTERN const CGFloat MJRefreshFooterHeight; +UIKIT_EXTERN const CGFloat MJRefreshFastAnimationDuration; +UIKIT_EXTERN const CGFloat MJRefreshSlowAnimationDuration; + +UIKIT_EXTERN NSString *const MJRefreshKeyPathContentOffset; +UIKIT_EXTERN NSString *const MJRefreshKeyPathContentSize; +UIKIT_EXTERN NSString *const MJRefreshKeyPathContentInset; +UIKIT_EXTERN NSString *const MJRefreshKeyPathPanState; + +UIKIT_EXTERN NSString *const MJRefreshHeaderLastUpdatedTimeKey; + +UIKIT_EXTERN NSString *const MJRefreshHeaderIdleText; +UIKIT_EXTERN NSString *const MJRefreshHeaderPullingText; +UIKIT_EXTERN NSString *const MJRefreshHeaderRefreshingText; + +UIKIT_EXTERN NSString *const MJRefreshAutoFooterIdleText; +UIKIT_EXTERN NSString *const MJRefreshAutoFooterRefreshingText; +UIKIT_EXTERN NSString *const MJRefreshAutoFooterNoMoreDataText; + +UIKIT_EXTERN NSString *const MJRefreshBackFooterIdleText; +UIKIT_EXTERN NSString *const MJRefreshBackFooterPullingText; +UIKIT_EXTERN NSString *const MJRefreshBackFooterRefreshingText; +UIKIT_EXTERN NSString *const MJRefreshBackFooterNoMoreDataText; + +UIKIT_EXTERN NSString *const MJRefreshHeaderLastTimeText; +UIKIT_EXTERN NSString *const MJRefreshHeaderDateTodayText; +UIKIT_EXTERN NSString *const MJRefreshHeaderNoneLastDateText; + +// 状态检查 +#define MJRefreshCheckState \ +MJRefreshState oldState = self.state; \ +if (state == oldState) return; \ +[super setState:state]; diff --git a/IOS/Playground/Pods/MJRefresh/MJRefresh/MJRefreshConst.m b/IOS/Playground/Pods/MJRefresh/MJRefresh/MJRefreshConst.m new file mode 100644 index 00000000..7c0733ee --- /dev/null +++ b/IOS/Playground/Pods/MJRefresh/MJRefresh/MJRefreshConst.m @@ -0,0 +1,33 @@ +// 代码地址: https://github.com/CoderMJLee/MJRefresh +// 代码地址: http://code4app.com/ios/%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90%E4%B8%8B%E6%8B%89%E4%B8%8A%E6%8B%89%E5%88%B7%E6%96%B0/52326ce26803fabc46000000 +#import + +const CGFloat MJRefreshLabelLeftInset = 25; +const CGFloat MJRefreshHeaderHeight = 54.0; +const CGFloat MJRefreshFooterHeight = 44.0; +const CGFloat MJRefreshFastAnimationDuration = 0.25; +const CGFloat MJRefreshSlowAnimationDuration = 0.4; + +NSString *const MJRefreshKeyPathContentOffset = @"contentOffset"; +NSString *const MJRefreshKeyPathContentInset = @"contentInset"; +NSString *const MJRefreshKeyPathContentSize = @"contentSize"; +NSString *const MJRefreshKeyPathPanState = @"state"; + +NSString *const MJRefreshHeaderLastUpdatedTimeKey = @"MJRefreshHeaderLastUpdatedTimeKey"; + +NSString *const MJRefreshHeaderIdleText = @"MJRefreshHeaderIdleText"; +NSString *const MJRefreshHeaderPullingText = @"MJRefreshHeaderPullingText"; +NSString *const MJRefreshHeaderRefreshingText = @"MJRefreshHeaderRefreshingText"; + +NSString *const MJRefreshAutoFooterIdleText = @"MJRefreshAutoFooterIdleText"; +NSString *const MJRefreshAutoFooterRefreshingText = @"MJRefreshAutoFooterRefreshingText"; +NSString *const MJRefreshAutoFooterNoMoreDataText = @"MJRefreshAutoFooterNoMoreDataText"; + +NSString *const MJRefreshBackFooterIdleText = @"MJRefreshBackFooterIdleText"; +NSString *const MJRefreshBackFooterPullingText = @"MJRefreshBackFooterPullingText"; +NSString *const MJRefreshBackFooterRefreshingText = @"MJRefreshBackFooterRefreshingText"; +NSString *const MJRefreshBackFooterNoMoreDataText = @"MJRefreshBackFooterNoMoreDataText"; + +NSString *const MJRefreshHeaderLastTimeText = @"MJRefreshHeaderLastTimeText"; +NSString *const MJRefreshHeaderDateTodayText = @"MJRefreshHeaderDateTodayText"; +NSString *const MJRefreshHeaderNoneLastDateText = @"MJRefreshHeaderNoneLastDateText"; \ No newline at end of file diff --git a/IOS/Playground/Pods/MJRefresh/MJRefresh/NSBundle+MJRefresh.h b/IOS/Playground/Pods/MJRefresh/MJRefresh/NSBundle+MJRefresh.h new file mode 100644 index 00000000..01df06c6 --- /dev/null +++ b/IOS/Playground/Pods/MJRefresh/MJRefresh/NSBundle+MJRefresh.h @@ -0,0 +1,16 @@ +// +// NSBundle+MJRefresh.h +// MJRefreshExample +// +// Created by MJ Lee on 16/6/13. +// Copyright © 2016年 小码哥. All rights reserved. +// + +#import + +@interface NSBundle (MJRefresh) ++ (instancetype)mj_refreshBundle; ++ (UIImage *)mj_arrowImage; ++ (NSString *)mj_localizedStringForKey:(NSString *)key value:(NSString *)value; ++ (NSString *)mj_localizedStringForKey:(NSString *)key; +@end diff --git a/IOS/Playground/Pods/MJRefresh/MJRefresh/NSBundle+MJRefresh.m b/IOS/Playground/Pods/MJRefresh/MJRefresh/NSBundle+MJRefresh.m new file mode 100644 index 00000000..c155ad49 --- /dev/null +++ b/IOS/Playground/Pods/MJRefresh/MJRefresh/NSBundle+MJRefresh.m @@ -0,0 +1,61 @@ +// +// NSBundle+MJRefresh.m +// MJRefreshExample +// +// Created by MJ Lee on 16/6/13. +// Copyright © 2016年 小码哥. All rights reserved. +// + +#import "NSBundle+MJRefresh.h" +#import "MJRefreshComponent.h" + +@implementation NSBundle (MJRefresh) ++ (instancetype)mj_refreshBundle +{ + static NSBundle *refreshBundle = nil; + if (refreshBundle == nil) { + // 这里不使用mainBundle是为了适配pod 1.x和0.x + refreshBundle = [NSBundle bundleWithPath:[[NSBundle bundleForClass:[MJRefreshComponent class]] pathForResource:@"MJRefresh" ofType:@"bundle"]]; + } + return refreshBundle; +} + ++ (UIImage *)mj_arrowImage +{ + static UIImage *arrowImage = nil; + if (arrowImage == nil) { + arrowImage = [[UIImage imageWithContentsOfFile:[[self mj_refreshBundle] pathForResource:@"arrow@2x" ofType:@"png"]] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; + } + return arrowImage; +} + ++ (NSString *)mj_localizedStringForKey:(NSString *)key +{ + return [self mj_localizedStringForKey:key value:nil]; +} + ++ (NSString *)mj_localizedStringForKey:(NSString *)key value:(NSString *)value +{ + static NSBundle *bundle = nil; + if (bundle == nil) { + // (iOS获取的语言字符串比较不稳定)目前框架只处理en、zh-Hans、zh-Hant三种情况,其他按照系统默认处理 + NSString *language = [NSLocale preferredLanguages].firstObject; + if ([language hasPrefix:@"en"]) { + language = @"en"; + } else if ([language hasPrefix:@"zh"]) { + if ([language rangeOfString:@"Hans"].location != NSNotFound) { + language = @"zh-Hans"; // 简体中文 + } else { // zh-Hant\zh-HK\zh-TW + language = @"zh-Hant"; // 繁體中文 + } + } else { + language = @"en"; + } + + // 从MJRefresh.bundle中查找资源 + bundle = [NSBundle bundleWithPath:[[NSBundle mj_refreshBundle] pathForResource:language ofType:@"lproj"]]; + } + value = [bundle localizedStringForKey:key value:value table:nil]; + return [[NSBundle mainBundle] localizedStringForKey:key value:value table:nil]; +} +@end diff --git a/IOS/Playground/Pods/MJRefresh/MJRefresh/UIScrollView+MJExtension.h b/IOS/Playground/Pods/MJRefresh/MJRefresh/UIScrollView+MJExtension.h new file mode 100644 index 00000000..734110f3 --- /dev/null +++ b/IOS/Playground/Pods/MJRefresh/MJRefresh/UIScrollView+MJExtension.h @@ -0,0 +1,23 @@ +// 代码地址: https://github.com/CoderMJLee/MJRefresh +// 代码地址: http://code4app.com/ios/%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90%E4%B8%8B%E6%8B%89%E4%B8%8A%E6%8B%89%E5%88%B7%E6%96%B0/52326ce26803fabc46000000 +// UIScrollView+Extension.h +// MJRefreshExample +// +// Created by MJ Lee on 14-5-28. +// Copyright (c) 2014年 小码哥. All rights reserved. +// + +#import + +@interface UIScrollView (MJExtension) +@property (assign, nonatomic) CGFloat mj_insetT; +@property (assign, nonatomic) CGFloat mj_insetB; +@property (assign, nonatomic) CGFloat mj_insetL; +@property (assign, nonatomic) CGFloat mj_insetR; + +@property (assign, nonatomic) CGFloat mj_offsetX; +@property (assign, nonatomic) CGFloat mj_offsetY; + +@property (assign, nonatomic) CGFloat mj_contentW; +@property (assign, nonatomic) CGFloat mj_contentH; +@end diff --git a/IOS/Playground/Pods/MJRefresh/MJRefresh/UIScrollView+MJExtension.m b/IOS/Playground/Pods/MJRefresh/MJRefresh/UIScrollView+MJExtension.m new file mode 100644 index 00000000..6a13f5fe --- /dev/null +++ b/IOS/Playground/Pods/MJRefresh/MJRefresh/UIScrollView+MJExtension.m @@ -0,0 +1,110 @@ +// 代码地址: https://github.com/CoderMJLee/MJRefresh +// 代码地址: http://code4app.com/ios/%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90%E4%B8%8B%E6%8B%89%E4%B8%8A%E6%8B%89%E5%88%B7%E6%96%B0/52326ce26803fabc46000000 +// UIScrollView+Extension.m +// MJRefreshExample +// +// Created by MJ Lee on 14-5-28. +// Copyright (c) 2014年 小码哥. All rights reserved. +// + +#import "UIScrollView+MJExtension.h" +#import + +@implementation UIScrollView (MJExtension) + +- (void)setMj_insetT:(CGFloat)mj_insetT +{ + UIEdgeInsets inset = self.contentInset; + inset.top = mj_insetT; + self.contentInset = inset; +} + +- (CGFloat)mj_insetT +{ + return self.contentInset.top; +} + +- (void)setMj_insetB:(CGFloat)mj_insetB +{ + UIEdgeInsets inset = self.contentInset; + inset.bottom = mj_insetB; + self.contentInset = inset; +} + +- (CGFloat)mj_insetB +{ + return self.contentInset.bottom; +} + +- (void)setMj_insetL:(CGFloat)mj_insetL +{ + UIEdgeInsets inset = self.contentInset; + inset.left = mj_insetL; + self.contentInset = inset; +} + +- (CGFloat)mj_insetL +{ + return self.contentInset.left; +} + +- (void)setMj_insetR:(CGFloat)mj_insetR +{ + UIEdgeInsets inset = self.contentInset; + inset.right = mj_insetR; + self.contentInset = inset; +} + +- (CGFloat)mj_insetR +{ + return self.contentInset.right; +} + +- (void)setMj_offsetX:(CGFloat)mj_offsetX +{ + CGPoint offset = self.contentOffset; + offset.x = mj_offsetX; + self.contentOffset = offset; +} + +- (CGFloat)mj_offsetX +{ + return self.contentOffset.x; +} + +- (void)setMj_offsetY:(CGFloat)mj_offsetY +{ + CGPoint offset = self.contentOffset; + offset.y = mj_offsetY; + self.contentOffset = offset; +} + +- (CGFloat)mj_offsetY +{ + return self.contentOffset.y; +} + +- (void)setMj_contentW:(CGFloat)mj_contentW +{ + CGSize size = self.contentSize; + size.width = mj_contentW; + self.contentSize = size; +} + +- (CGFloat)mj_contentW +{ + return self.contentSize.width; +} + +- (void)setMj_contentH:(CGFloat)mj_contentH +{ + CGSize size = self.contentSize; + size.height = mj_contentH; + self.contentSize = size; +} + +- (CGFloat)mj_contentH +{ + return self.contentSize.height; +} +@end diff --git a/IOS/Playground/Pods/MJRefresh/MJRefresh/UIScrollView+MJRefresh.h b/IOS/Playground/Pods/MJRefresh/MJRefresh/UIScrollView+MJRefresh.h new file mode 100644 index 00000000..17d47153 --- /dev/null +++ b/IOS/Playground/Pods/MJRefresh/MJRefresh/UIScrollView+MJRefresh.h @@ -0,0 +1,26 @@ +// 代码地址: https://github.com/CoderMJLee/MJRefresh +// 代码地址: http://code4app.com/ios/%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90%E4%B8%8B%E6%8B%89%E4%B8%8A%E6%8B%89%E5%88%B7%E6%96%B0/52326ce26803fabc46000000 +// UIScrollView+MJRefresh.h +// MJRefreshExample +// +// Created by MJ Lee on 15/3/4. +// Copyright (c) 2015年 小码哥. All rights reserved. +// 给ScrollView增加下拉刷新、上拉刷新的功能 + +#import +#import "MJRefreshConst.h" + +@class MJRefreshHeader, MJRefreshFooter; + +@interface UIScrollView (MJRefresh) +/** 下拉刷新控件 */ +@property (strong, nonatomic) MJRefreshHeader *mj_header; +@property (strong, nonatomic) MJRefreshHeader *header MJRefreshDeprecated("使用mj_header"); +/** 上拉刷新控件 */ +@property (strong, nonatomic) MJRefreshFooter *mj_footer; +@property (strong, nonatomic) MJRefreshFooter *footer MJRefreshDeprecated("使用mj_footer"); + +#pragma mark - other +- (NSInteger)mj_totalDataCount; +@property (copy, nonatomic) void (^mj_reloadDataBlock)(NSInteger totalDataCount); +@end diff --git a/IOS/Playground/Pods/MJRefresh/MJRefresh/UIScrollView+MJRefresh.m b/IOS/Playground/Pods/MJRefresh/MJRefresh/UIScrollView+MJRefresh.m new file mode 100644 index 00000000..b1b99426 --- /dev/null +++ b/IOS/Playground/Pods/MJRefresh/MJRefresh/UIScrollView+MJRefresh.m @@ -0,0 +1,163 @@ +// 代码地址: https://github.com/CoderMJLee/MJRefresh +// 代码地址: http://code4app.com/ios/%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90%E4%B8%8B%E6%8B%89%E4%B8%8A%E6%8B%89%E5%88%B7%E6%96%B0/52326ce26803fabc46000000 +// UIScrollView+MJRefresh.m +// MJRefreshExample +// +// Created by MJ Lee on 15/3/4. +// Copyright (c) 2015年 小码哥. All rights reserved. +// + +#import "UIScrollView+MJRefresh.h" +#import "MJRefreshHeader.h" +#import "MJRefreshFooter.h" +#import + +@implementation NSObject (MJRefresh) + ++ (void)exchangeInstanceMethod1:(SEL)method1 method2:(SEL)method2 +{ + method_exchangeImplementations(class_getInstanceMethod(self, method1), class_getInstanceMethod(self, method2)); +} + ++ (void)exchangeClassMethod1:(SEL)method1 method2:(SEL)method2 +{ + method_exchangeImplementations(class_getClassMethod(self, method1), class_getClassMethod(self, method2)); +} + +@end + +@implementation UIScrollView (MJRefresh) + +#pragma mark - header +static const char MJRefreshHeaderKey = '\0'; +- (void)setMj_header:(MJRefreshHeader *)mj_header +{ + if (mj_header != self.mj_header) { + // 删除旧的,添加新的 + [self.mj_header removeFromSuperview]; + [self insertSubview:mj_header atIndex:0]; + + // 存储新的 + [self willChangeValueForKey:@"mj_header"]; // KVO + objc_setAssociatedObject(self, &MJRefreshHeaderKey, + mj_header, OBJC_ASSOCIATION_ASSIGN); + [self didChangeValueForKey:@"mj_header"]; // KVO + } +} + +- (MJRefreshHeader *)mj_header +{ + return objc_getAssociatedObject(self, &MJRefreshHeaderKey); +} + +#pragma mark - footer +static const char MJRefreshFooterKey = '\0'; +- (void)setMj_footer:(MJRefreshFooter *)mj_footer +{ + if (mj_footer != self.mj_footer) { + // 删除旧的,添加新的 + [self.mj_footer removeFromSuperview]; + [self insertSubview:mj_footer atIndex:0]; + + // 存储新的 + [self willChangeValueForKey:@"mj_footer"]; // KVO + objc_setAssociatedObject(self, &MJRefreshFooterKey, + mj_footer, OBJC_ASSOCIATION_ASSIGN); + [self didChangeValueForKey:@"mj_footer"]; // KVO + } +} + +- (MJRefreshFooter *)mj_footer +{ + return objc_getAssociatedObject(self, &MJRefreshFooterKey); +} + +#pragma mark - 过期 +- (void)setFooter:(MJRefreshFooter *)footer +{ + self.mj_footer = footer; +} + +- (MJRefreshFooter *)footer +{ + return self.mj_footer; +} + +- (void)setHeader:(MJRefreshHeader *)header +{ + self.mj_header = header; +} + +- (MJRefreshHeader *)header +{ + return self.mj_header; +} + +#pragma mark - other +- (NSInteger)mj_totalDataCount +{ + NSInteger totalCount = 0; + if ([self isKindOfClass:[UITableView class]]) { + UITableView *tableView = (UITableView *)self; + + for (NSInteger section = 0; section + +@interface UIView (MJExtension) +@property (assign, nonatomic) CGFloat mj_x; +@property (assign, nonatomic) CGFloat mj_y; +@property (assign, nonatomic) CGFloat mj_w; +@property (assign, nonatomic) CGFloat mj_h; +@property (assign, nonatomic) CGSize mj_size; +@property (assign, nonatomic) CGPoint mj_origin; +@end diff --git a/IOS/Playground/Pods/MJRefresh/MJRefresh/UIView+MJExtension.m b/IOS/Playground/Pods/MJRefresh/MJRefresh/UIView+MJExtension.m new file mode 100644 index 00000000..7e8eda2d --- /dev/null +++ b/IOS/Playground/Pods/MJRefresh/MJRefresh/UIView+MJExtension.m @@ -0,0 +1,84 @@ +// 代码地址: https://github.com/CoderMJLee/MJRefresh +// 代码地址: http://code4app.com/ios/%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90%E4%B8%8B%E6%8B%89%E4%B8%8A%E6%8B%89%E5%88%B7%E6%96%B0/52326ce26803fabc46000000 +// UIView+Extension.m +// MJRefreshExample +// +// Created by MJ Lee on 14-5-28. +// Copyright (c) 2014年 小码哥. All rights reserved. +// + +#import "UIView+MJExtension.h" + +@implementation UIView (MJExtension) +- (void)setMj_x:(CGFloat)mj_x +{ + CGRect frame = self.frame; + frame.origin.x = mj_x; + self.frame = frame; +} + +- (CGFloat)mj_x +{ + return self.frame.origin.x; +} + +- (void)setMj_y:(CGFloat)mj_y +{ + CGRect frame = self.frame; + frame.origin.y = mj_y; + self.frame = frame; +} + +- (CGFloat)mj_y +{ + return self.frame.origin.y; +} + +- (void)setMj_w:(CGFloat)mj_w +{ + CGRect frame = self.frame; + frame.size.width = mj_w; + self.frame = frame; +} + +- (CGFloat)mj_w +{ + return self.frame.size.width; +} + +- (void)setMj_h:(CGFloat)mj_h +{ + CGRect frame = self.frame; + frame.size.height = mj_h; + self.frame = frame; +} + +- (CGFloat)mj_h +{ + return self.frame.size.height; +} + +- (void)setMj_size:(CGSize)mj_size +{ + CGRect frame = self.frame; + frame.size = mj_size; + self.frame = frame; +} + +- (CGSize)mj_size +{ + return self.frame.size; +} + +- (void)setMj_origin:(CGPoint)mj_origin +{ + CGRect frame = self.frame; + frame.origin = mj_origin; + self.frame = frame; +} + +- (CGPoint)mj_origin +{ + return self.frame.origin; +} +@end diff --git a/IOS/Playground/Pods/MJRefresh/README.md b/IOS/Playground/Pods/MJRefresh/README.md new file mode 100644 index 00000000..aa400578 --- /dev/null +++ b/IOS/Playground/Pods/MJRefresh/README.md @@ -0,0 +1,362 @@ +![(logo)](http://images.cnitblog.com/blog2015/497279/201505/051004492043385.png) +## MJRefresh +* An easy way to use pull-to-refresh + +## Contents +* Getting Started + * [Features【Support what kinds of controls to refresh】](#Support what kinds of controls to refresh) + * [Installation【How to use MJRefresh】](#How to use MJRefresh) + * [Who's using【More than hundreds of Apps are using MJRefresh】](#>More than hundreds of Apps are using MJRefresh) + * [Classes【The Class Structure Chart of MJRefresh】](#The Class Structure Chart of MJRefresh) +* Comment API + * [MJRefreshComponent.h](#MJRefreshComponent.h) + * [MJRefreshHeader.h](#MJRefreshHeader.h) + * [MJRefreshFooter.h](#MJRefreshFooter.h) + * [MJRefreshAutoFooter.h](#MJRefreshAutoFooter.h) +* Examples + * [Reference](#Reference) + * [The drop-down refresh 01-Default](#The drop-down refresh 01-Default) + * [The drop-down refresh 02-Animation image](#The drop-down refresh 02-Animation image) + * [The drop-down refresh 03-Hide the time](#The drop-down refresh 03-Hide the time) + * [The drop-down refresh 04-Hide status and time](#The drop-down refresh 04-Hide status and time) + * [The drop-down refresh 05-DIY title](#The drop-down refresh 05-DIY title) + * [The drop-down refresh 06-DIY the control of refresh](#The drop-down refresh 06-DIY the control of refresh) + * [The pull to refresh 01-Default](#The pull to refresh 01-Default) + * [The pull to refresh 02-Animation image](#The pull to refresh 02-Animation image) + * [The pull to refresh 03-Hide the title of refresh status](#The pull to refresh 03-Hide the title of refresh status) + * [The pull to refresh 04-All loaded](#The pull to refresh 04-All loaded) + * [The pull to refresh 05-DIY title](#The pull to refresh 05-DIY title) + * [The pull to refresh 06-Hidden After loaded](#The pull to refresh 06-Hidden After loaded) + * [The pull to refresh 07-Automatic back of the pull01](#上The pull to refresh 07-Automatic back of the pull01) + * [The pull to refresh 08-Automatic back of the pull02](#The pull to refresh 08-Automatic back of the pull02) + * [The pull to refresh 09-DIY the control of refresh(Automatic refresh)](#The pull to refresh 09-DIY the control of refresh(Automatic refresh)) + * [The pull to refresh 10-DIY the control of refresh(Automatic back)](#The pull to refresh 10-DIY the control of refresh(Automatic back)) + * [UICollectionView01-The pull and drop-down refresh](#UICollectionView01-The pull and drop-down refresh) + * [UIWebView01-The drop-down refresh](#UIWebView01-The drop-down refresh) +* [Hope](#Hope) + +## Support what kinds of controls to refresh +* `UIScrollView`、`UITableView`、`UICollectionView`、`UIWebView` + +## How to use MJRefresh +* Installation with CocoaPods:`pod 'MJRefresh'` +* Manual import: + * Drag All files in the `MJRefresh` folder to project + * Import the main file:`#import "MJRefresh.h"` + +```objc +Base Custom +MJRefresh.bundle MJRefresh.h +MJRefreshConst.h MJRefreshConst.m +UIScrollView+MJExtension.h UIScrollView+MJExtension.m +UIScrollView+MJRefresh.h UIScrollView+MJRefresh.m +UIView+MJExtension.h UIView+MJExtension.m +``` + +## More than hundreds of Apps are using MJRefresh + +* More information of App can focus on:[M了个J-博客园](http://www.cnblogs.com/mjios/p/4409853.html) + +## The Class Structure Chart of MJRefresh +![](http://images0.cnblogs.com/blog2015/497279/201506/132232456139177.png) +- `The class of red text` in the chart:You can use them directly + - The drop-down refresh control types + - Normal:`MJRefreshNormalHeader` + - Gif:`MJRefreshGifHeader` + - The pull to refresh control types + - Auto refresh + - Normal:`MJRefreshAutoNormalFooter` + - Gif:`MJRefreshAutoGifFooter` + - Auto Back + - Normal:`MJRefreshBackNormalFooter` + - Gif:`MJRefreshBackGifFooter` +- `The class of non-red text` in the chart:For inheritance,to use DIY the control of refresh +- About how to DIY the control of refresh,You can refer the Class in below Chart
+ + +## MJRefreshComponent.h +```objc +/** The Base Class of refresh control */ +@interface MJRefreshComponent : UIView +#pragma mark - Control the state of Refresh + +/** BeginRefreshing */ +- (void)beginRefreshing; +/** EndRefreshing */ +- (void)endRefreshing; +/** IsRefreshing */ +- (BOOL)isRefreshing; + +#pragma mark - Other +/** According to the drag ratio to change alpha automatically */ +@property (assign, nonatomic, getter=isAutomaticallyChangeAlpha) BOOL automaticallyChangeAlpha; +@end +``` + +## MJRefreshHeader.h +```objc +@interface MJRefreshHeader : MJRefreshComponent +/** Creat header */ ++ (instancetype)headerWithRefreshingBlock:(MJRefreshComponentRefreshingBlock)refreshingBlock; +/** Creat header */ ++ (instancetype)headerWithRefreshingTarget:(id)target refreshingAction:(SEL)action; + +/** This key is used to storage the time that the last time of drown-down successfully */ +@property (copy, nonatomic) NSString *lastUpdatedTimeKey; +/** The last time of drown-down successfully */ +@property (strong, nonatomic, readonly) NSDate *lastUpdatedTime; + +/** Ignored scrollView contentInset top */ +@property (assign, nonatomic) CGFloat ignoredScrollViewContentInsetTop; +@end +``` + +## MJRefreshFooter.h +```objc +@interface MJRefreshFooter : MJRefreshComponent +/** Creat footer */ ++ (instancetype)footerWithRefreshingBlock:(MJRefreshComponentRefreshingBlock)refreshingBlock; +/** Creat footer */ ++ (instancetype)footerWithRefreshingTarget:(id)target refreshingAction:(SEL)action; + +/** NoticeNoMoreData */ +- (void)noticeNoMoreData; +/** ResetNoMoreData(Clear the status of NoMoreData ) */ +- (void)resetNoMoreData; + +/** Ignored scrollView contentInset bottom */ +@property (assign, nonatomic) CGFloat ignoredScrollViewContentInsetBottom; + +/** Automaticlly show or hidden by the count of data(Show-have data,Hidden- no data) */ +@property (assign, nonatomic) BOOL automaticallyHidden; +@end +``` + +## MJRefreshAutoFooter.h +```objc +@interface MJRefreshAutoFooter : MJRefreshFooter +/** Is Automatically Refresh(Default is Yes) */ +@property (assign, nonatomic, getter=isAutomaticallyRefresh) BOOL automaticallyRefresh; + +/** When there is much at the bottom of the control is automatically refresh(Default is 1.0,Is at the bottom of the control appears in full, will refresh automatically) */ +@property (assign, nonatomic) CGFloat triggerAutomaticallyRefreshPercent; +@end +``` + +## Reference +```objc +* Due to there are more functions of this framework,Don't write specific text describe its usage +* You can directly reference examples MJTableViewController、MJCollectionViewController、MJWebViewController,More intuitive and fast. +``` + + +## The drop-down refresh 01-Default + +```objc +self.tableView.header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{ + //Call this Block When enter the refresh status automatically +}]; +或 +// Set the callback(Once you enter the refresh status,then call the action of target,that is call [self loadNewData]) +self.tableView.header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNewData)]; + +// Enter the refresh status immediately +[self.tableView.header beginRefreshing]; +``` +![(下拉刷新01-普通)](http://images0.cnblogs.com/blog2015/497279/201506/141204343486151.gif) + +## The drop-down refresh 02-Animation image +```objc +// Set the callback(一Once you enter the refresh status,then call the action of target,that is call [self loadNewData]) +MJRefreshGifHeader *header = [MJRefreshGifHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNewData)]; +// Set the ordinary state of animated images +[header setImages:idleImages forState:MJRefreshStateIdle]; +// Set the pulling state of animated images(Enter the status of refreshing as soon as loosen) +[header setImages:pullingImages forState:MJRefreshStatePulling]; +// Set the refreshing state of animated images +[header setImages:refreshingImages forState:MJRefreshStateRefreshing]; +// Set header +self.tableView.mj_header = header; +``` +![(下拉刷新02-动画图片)](http://images0.cnblogs.com/blog2015/497279/201506/141204402238389.gif) + +## The drop-down refresh 03-Hide the time +```objc +// Hide the time +header.lastUpdatedTimeLabel.hidden = YES; +``` +![(下拉刷新03-隐藏时间)](http://images0.cnblogs.com/blog2015/497279/201506/141204456132944.gif) + +## The drop-down refresh 04-Hide status and time +```objc +// Hide the time +header.lastUpdatedTimeLabel.hidden = YES; + +// Hide the status +header.stateLabel.hidden = YES; +``` +![(下拉刷新04-隐藏状态和时间0)](http://images0.cnblogs.com/blog2015/497279/201506/141204508639539.gif) + +## The drop-down refresh 05-DIY title +```objc +// Set title +[header setTitle:@"Pull down to refresh" forState:MJRefreshStateIdle]; +[header setTitle:@"Release to refresh" forState:MJRefreshStatePulling]; +[header setTitle:@"Loading ..." forState:MJRefreshStateRefreshing]; + +// Set font +header.stateLabel.font = [UIFont systemFontOfSize:15]; +header.lastUpdatedTimeLabel.font = [UIFont systemFontOfSize:14]; + +// Set textColor +header.stateLabel.textColor = [UIColor redColor]; +header.lastUpdatedTimeLabel.textColor = [UIColor blueColor]; +``` +![(下拉刷新05-自定义文字)](http://images0.cnblogs.com/blog2015/497279/201506/141204563633593.gif) + +## The drop-down refresh 06-DIY the control of refresh +```objc +self.tableView.mj_header = [MJDIYHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNewData)]; +// Implementation reference to MJDIYHeader.h和MJDIYHeader.m +``` +![(下拉刷新06-自定义刷新控件)](http://images0.cnblogs.com/blog2015/497279/201506/141205019261159.gif) + +## The pull to refresh 01-Default +```objc +self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{ + //Call this Block When enter the refresh status automatically +}]; +或 +// Set the callback(Once you enter the refresh status,then call the action of target,that is call [self loadMoreData]) +self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)]; +``` +![(上拉刷新01-默认)](http://images0.cnblogs.com/blog2015/497279/201506/141205090047696.gif) + +## The pull to refresh 02-Animation image +```objc +// Set the callback(Once you enter the refresh status,then call the action of target,that is call [self loadMoreData]) +MJRefreshAutoGifFooter *footer = [MJRefreshAutoGifFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)]; + +// Set the refresh image +[footer setImages:refreshingImages forState:MJRefreshStateRefreshing]; + +// Set footer +self.tableView.mj_footer = footer; +``` +![(上拉刷新02-动画图片)](http://images0.cnblogs.com/blog2015/497279/201506/141205141445793.gif) + +## The pull to refresh 03-Hide the title of refresh status +```objc +// Hide the title of refresh status +footer.refreshingTitleHidden = YES; +// If does have not above method,then use footer.stateLabel.hidden = YES; +``` +![(上拉刷新03-隐藏刷新状态的文字)](http://images0.cnblogs.com/blog2015/497279/201506/141205200985774.gif) + +## The pull to refresh 04-All loaded +```objc +//Become the status of NoMoreData +[footer noticeNoMoreData]; +``` +![(上拉刷新04-全部加载完毕)](http://images0.cnblogs.com/blog2015/497279/201506/141205248634686.gif) + +## The pull to refresh 05-DIY title +```objc +// Set title +[footer setTitle:@"Click or drag up to refresh" forState:MJRefreshStateIdle]; +[footer setTitle:@"Loading more ..." forState:MJRefreshStateRefreshing]; +[footer setTitle:@"No more data" forState:MJRefreshStateNoMoreData]; + +// Set font +footer.stateLabel.font = [UIFont systemFontOfSize:17]; + +// Set textColor +footer.stateLabel.textColor = [UIColor blueColor]; +``` +![(上拉刷新05-自定义文字)](http://images0.cnblogs.com/blog2015/497279/201506/141205295511153.gif) + +## The pull to refresh 06-Hidden After loaded +```objc +//Hidden current control of the pull to refresh +self.tableView.mj_footer.hidden = YES; +``` +![(上拉刷新06-加载后隐藏)](http://images0.cnblogs.com/blog2015/497279/201506/141205343481821.gif) + +## The pull to refresh 07-Automatic back of the pull01 +```objc +self.tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)]; +``` +![(上拉刷新07-自动回弹的上拉01)](http://images0.cnblogs.com/blog2015/497279/201506/141205392239231.gif) + +## The pull to refresh 08-Automatic back of the pull02 +```objc +MJRefreshBackGifFooter *footer = [MJRefreshBackGifFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)]; + +// Set the normal state of the animated image +[footer setImages:idleImages forState:MJRefreshStateIdle]; +// Set the pulling state of animated images(Enter the status of refreshing as soon as loosen) +[footer setImages:pullingImages forState:MJRefreshStatePulling]; +// Set the refreshing state of animated images +[footer setImages:refreshingImages forState:MJRefreshStateRefreshing]; + +// Set footer +self.tableView.mj_footer = footer; +``` +![(上拉刷新07-自动回弹的上拉02)](http://images0.cnblogs.com/blog2015/497279/201506/141205441443628.gif) + +## The pull to refresh 09-DIY the control of refresh(Automatic refresh) +```objc +self.tableView.mj_footer = [MJDIYAutoFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)]; +// Implementation reference to MJDIYAutoFooter.h和MJDIYAutoFooter.m +``` +![(上拉刷新09-自定义刷新控件(自动刷新))](http://images0.cnblogs.com/blog2015/497279/201506/141205500195866.gif) + +## The pull to refresh 10-DIY the control of refresh(Automatic back) +```objc +self.tableView.mj_footer = [MJDIYBackFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)]; +// Implementation reference to MJDIYBackFooter.h和MJDIYBackFooter.m +``` +![(上拉刷新10-自定义刷新控件(自动回弹))](http://images0.cnblogs.com/blog2015/497279/201506/141205560666819.gif) + +## UICollectionView01-The pull and drop-down refresh +```objc +// The drop-down refresh +self.collectionView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{ + //Call this Block When enter the refresh status automatically +}]; + +// The pull to refresh +self.collectionView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{ + //Call this Block When enter the refresh status automatically +}]; +``` +![(UICollectionView01-上下拉刷新)](http://images0.cnblogs.com/blog2015/497279/201506/141206021603758.gif) + +## UIWebView01-The drop-down refresh +```objc +//Add the control of The drop-down refresh +self.webView.scrollView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{ + //Call this Block When enter the refresh status automatically +}]; +``` +![(UICollectionView01-上下拉刷新)](http://images0.cnblogs.com/blog2015/497279/201506/141206080514524.gif) + +## Remind +* ARC +* iOS>=6.0 +* iPhone \ iPad screen anyway + +## Hope +* If you find bug when used,Hope you can Issues me,Thank you or try to download the latest code of this framework to see the BUG has been fixed or not) +* If you find the function is not enough when used,Hope you can Issues me,I very much to add more useful function to this framework ,Thank you ! +* If you want to contribute code for MJRefresh,please Pull Requests me +* If you use MJRefresh in your develop app,Hope you can go to[CocoaControls](https://www.cocoacontrols.com/controls/mjrefresh)to add the iTunes path + of you app,I Will install your app,and according to the usage of many app,to be a better design and improve to MJRefresh,Thank you ! + * StepO1(WeChat is just an Example,Explore“Your app name itunes”) +![(step01)](http://ww4.sinaimg.cn/mw1024/800cdf9ctw1eq0viiv5rsj20sm0ea41t.jpg) + * StepO2 +![(step02)](http://ww2.sinaimg.cn/mw1024/800cdf9ctw1eq0vilejxlj20tu0me7a0.jpg) + * StepO3 +![(step03)](http://ww1.sinaimg.cn/mw1024/800cdf9ctw1eq0viocpo5j20wc0dc0un.jpg) + * StepO4 +![(step04)](http://ww3.sinaimg.cn/mw1024/800cdf9ctw1eq0vir137xj20si0gewgu.jpg) diff --git a/IOS/Playground/Pods/Manifest.lock b/IOS/Playground/Pods/Manifest.lock new file mode 100644 index 00000000..24f6cec2 --- /dev/null +++ b/IOS/Playground/Pods/Manifest.lock @@ -0,0 +1,28 @@ +PODS: + - luaviewEx (0.1.0): + - LuaViewSDK + - MJRefresh + - SDWebImage (~> 3.7.5) + - LuaViewSDK (0.5.0) + - MJRefresh (3.1.12) + - SDWebImage (3.7.6): + - SDWebImage/Core (= 3.7.6) + - SDWebImage/Core (3.7.6) + +DEPENDENCIES: + - luaviewEx (from `../luaviewEx`) + - LuaViewSDK (from `../../`) + +EXTERNAL SOURCES: + luaviewEx: + :path: ../luaviewEx + LuaViewSDK: + :path: ../../ + +SPEC CHECKSUMS: + luaviewEx: a5e511e0e83280315ebff29f8bdc2c2cc7fb466b + LuaViewSDK: 04f40a2b25e485669ca03ae93fd45f8a145164ce + MJRefresh: 11e1c9d86f2093ddcdbda7836bc2da477ddf568d + SDWebImage: 485df4197e8008e0a23d95854d6a73050b9ddc3c + +COCOAPODS: 0.39.0 diff --git a/IOS/Playground/Pods/Pods.xcodeproj/project.pbxproj b/IOS/Playground/Pods/Pods.xcodeproj/project.pbxproj new file mode 100644 index 00000000..041dc42e --- /dev/null +++ b/IOS/Playground/Pods/Pods.xcodeproj/project.pbxproj @@ -0,0 +1,10255 @@ + + + + + archiveVersion + 1 + classes + + objectVersion + 46 + objects + + 00488347FBD3CC25591CEB62F96C8289 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + MJRefreshAutoNormalFooter.m + path + MJRefresh/Custom/Footer/Auto/MJRefreshAutoNormalFooter.m + sourceTree + <group> + + 0069C69D4E50900D4B6DB88721929F18 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVGesture.h + sourceTree + <group> + + 00DB86496A3A3D9FAF2E919F9EBBEAE1 + + baseConfigurationReference + 9F92270DCACF8D923B9153BBF8998633 + buildSettings + + ENABLE_STRICT_OBJC_MSGSEND + YES + GCC_PREFIX_HEADER + Target Support Files/LuaViewSDK/LuaViewSDK-prefix.pch + IPHONEOS_DEPLOYMENT_TARGET + 8.0 + MTL_ENABLE_DEBUG_INFO + NO + OTHER_LDFLAGS + + OTHER_LIBTOOLFLAGS + + PRIVATE_HEADERS_FOLDER_PATH + + PRODUCT_NAME + $(TARGET_NAME) + PUBLIC_HEADERS_FOLDER_PATH + + SDKROOT + iphoneos + SKIP_INSTALL + YES + + isa + XCBuildConfiguration + name + Release + + 011C51690A7646EDEE9277B3A40293A4 + + buildActionMask + 2147483647 + files + + isa + PBXFrameworksBuildPhase + runOnlyForDeploymentPostprocessing + 0 + + 01730232DD754F790B27162853B22ED3 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + JUFLXLinearLayoutView.h + sourceTree + <group> + + 0177FC64DC60D2EE0DF584CE5FC5F66E + + fileRef + 65A2C298D65EFC5B359821B8872CB809 + isa + PBXBuildFile + + 0209E35EBB89158BE1EEE63A003EFA02 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVPkgInfo.h + sourceTree + <group> + + 0281BDDA769AFF211481D7738496989D + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVNinePatchImage.h + sourceTree + <group> + + 028E09B81C239295EB2B3008FFBFA151 + + buildActionMask + 2147483647 + files + + 763770F29895252BF40B99CD5D4EA4A5 + 135BEBB31E749A99440FD600E5940FF6 + 1956AC05FCF697332BA9015C86C6F882 + 15F58E66DAF567EB49184105B405891A + + isa + PBXHeadersBuildPhase + runOnlyForDeploymentPostprocessing + 0 + + 02D9BD86B8E170A9A8AC5E3D481EF2C6 + + fileRef + 88C0AC96CA31ADC0432FCA03474C0C9D + isa + PBXBuildFile + + 0337A51DB5994C8994C2A8DA56DC7F48 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVRSA.h + sourceTree + <group> + + 03782A4641772CAFDF1C6A58B50D0C6B + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVNavigation.m + sourceTree + <group> + + 04398C72E6C55DFAD9B02065B62FC649 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + MJRefreshStateHeader.h + path + MJRefresh/Custom/Header/MJRefreshStateHeader.h + sourceTree + <group> + + 046765D495C9057D3B5DDABCA3A95502 + + fileRef + 18FC55E7A2AA58B1092D833C3A201243 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 046DE20980BF0D1ED96192F78A9F3B33 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + text.xcconfig + path + MJRefresh.xcconfig + sourceTree + <group> + + 05146DF4C72F6DE622B3482E83AD4A13 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVCustomPanel.m + sourceTree + <group> + + 0524A59F048FE513757D78AFF6074DD9 + + fileRef + 4C26E8911DD624CEEA25A8569E14C0EE + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 0534ACA88092EB85C6F1DE09FB52C1E4 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LuaViewSDK-dummy.m + sourceTree + <group> + + 0557238855F7958B0BD4F1C060DE3E89 + + fileRef + D09ECEBEA5E66FD2DF0A6ECE2FAB2BCC + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 05691A6D5154EAE340DEA4A95F90C68A + + fileRef + E86E8B315217720BAB0CDC4E78AE3604 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 07282814DCAF1910BC004FD25EFAB618 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVLoadingIndicator.m + sourceTree + <group> + + 077FBD97BCFAB1B7BCC73DCD43861B0B + + fileRef + DDF1B84675F3FD174AD5BD30E6CBF2F0 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 084241B9DC5DC7A2F68E1E7FE94FDEAF + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + UIScrollView+LVRefresh.m + sourceTree + <group> + + 08957A35CBC7E56DF6CE78CBC5BF5B8C + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVBlock.m + sourceTree + <group> + + 09335FBC624A24A1C3642B6D7D45EADC + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + JUFLXCSSParser.m + sourceTree + <group> + + 09812FC481F673CDE2428CAC41614458 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + MJRefreshHeader.h + path + MJRefresh/Base/MJRefreshHeader.h + sourceTree + <group> + + 0A363F72760068456ED56A18B3F3316F + + fileRef + 70665FCF0DE698CEA01ED3BF3313739F + isa + PBXBuildFile + + 0ACF60098C0CFEF30A3C0E47D4159668 + + fileRef + C46C1EF777315A011CEDF14E291E5A72 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 0B35943C35122E6E109566190302ACE7 + + buildActionMask + 2147483647 + files + + 67B191A8E2B9C2FB3ED480CECF48B49D + 0ACF60098C0CFEF30A3C0E47D4159668 + 0F043AB02232B1343CF5F9D60E167CE8 + E4D382C3285C5DF3780CBF5E0EB434AD + A8DC7BDC3F3A0C051E525C9C39BC2492 + 225B344FAD231860F01CA7091A0CAB8E + B4EBDDE43EC6E13D8A715D0F9A0B759C + 9DCEEBE0F83EA19FF82D54789139BD73 + 49E3940009490371B28511581FE8D6FC + 355A3B0609865F729861222E5EB88A38 + 4F8882E58A6AE23CB96516C6BD8A3671 + F3FEA1222D8D1B7BC11CE0DC513F8120 + 93B70581D4C9B003008D4A0BA7A2232F + 5197F0B2921DB5FA553B2720ECD82A52 + EF4B7C2304E2238BEE32984C0037A3D2 + + isa + PBXHeadersBuildPhase + runOnlyForDeploymentPostprocessing + 0 + + 0B4274E3A6B1C5DA65EFA100AAA70ACE + + fileRef + 1EFA9AF0945D053F5211C3347AE83BEE + isa + PBXBuildFile + + 0BAEE4701F44450AF3E2ED674A624E86 + + fileRef + F99BA1FA74A12DFF25DA5709B546F551 + isa + PBXBuildFile + + 0BC295DE4727C46FB2A213137259B35B + + fileRef + D5CAC3DA5EE1AD2C7A5ABBD65FE3C59D + isa + PBXBuildFile + + 0C0101F9AF8D83E8C07022ED9AF7A9B5 + + fileRef + E9147195251E0E11AD9BEC4D2227EA9B + isa + PBXBuildFile + + 0C3B1B32D99F31A53712FE54384DED9B + + fileRef + EB485310B5B8619A748A5DEEEFF8C7FE + isa + PBXBuildFile + + 0C8D38F782DB467E338AFDABFF185635 + + fileRef + 2BD1B6C16B749F5AF1280ABB7EBEDB68 + isa + PBXBuildFile + + 0D77ABD68A4337BB644F781E07E23EB8 + + fileRef + 2230F2079225B9F62BAB22ADDB779CC1 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 0D951028230A613A6FABAF9C2ED681AB + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVScrollView.m + sourceTree + <group> + + 0DE4D405F7D8E386510FD640EE2C1FA8 + + fileRef + D53480A24F0018010DEE441009153B07 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 0E0686BFE33F9DDAB4D19E995480F7BE + + fileRef + 7EFF7E9CC8716B1EADBAA3B34EEE5EAC + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 0E0EDB175E8DDD8757716C987E6345F1 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVRSA.m + sourceTree + <group> + + 0E20491F4F04EFE0E6B2624C3135FB5F + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVLabel.h + sourceTree + <group> + + 0E347E52967978AE8A29E0E86041381A + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVLuaObjBox.h + sourceTree + <group> + + 0E4C71A0883D883D2EC58F33F9F59FF9 + + children + + A544A8CB3168DE44318B021F0C4274D4 + + isa + PBXGroup + name + luaviewEx + path + luaviewEx + sourceTree + <group> + + 0F043AB02232B1343CF5F9D60E167CE8 + + fileRef + 47447F822E904AC8D6A5E82A55016A52 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 0F6E434EFE109168E32511196484D4F8 + + fileRef + 53D6E5C9CBA5F03006A11B68D3D95468 + isa + PBXBuildFile + + 0FD4F671E6E8DA28BD4A5E73D1D4BC82 + + fileRef + 40F3ADC7C956412AEF1B29B263D033C6 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 107D55D61A4636DE8BA66B963823103B + + explicitFileType + wrapper.cfbundle + includeInIndex + 0 + isa + PBXFileReference + name + luaviewEx.bundle + path + luaviewEx.bundle + sourceTree + BUILT_PRODUCTS_DIR + + 10FFFE940EB64D3925A0C3C367BEBD61 + + baseConfigurationReference + 046DE20980BF0D1ED96192F78A9F3B33 + buildSettings + + ENABLE_STRICT_OBJC_MSGSEND + YES + GCC_PREFIX_HEADER + Target Support Files/MJRefresh/MJRefresh-prefix.pch + IPHONEOS_DEPLOYMENT_TARGET + 8.0 + MTL_ENABLE_DEBUG_INFO + YES + OTHER_LDFLAGS + + OTHER_LIBTOOLFLAGS + + PRIVATE_HEADERS_FOLDER_PATH + + PRODUCT_NAME + $(TARGET_NAME) + PUBLIC_HEADERS_FOLDER_PATH + + SDKROOT + iphoneos + SKIP_INSTALL + YES + + isa + XCBuildConfiguration + name + Debug + + 1100D9ED94AE6338FFDA6931A921B42E + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + UIScrollView+MJRefresh.m + path + MJRefresh/UIScrollView+MJRefresh.m + sourceTree + <group> + + 111420667E7F2A177D6D703D47E67556 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + text.script.sh + path + Pods-Demo-frameworks.sh + sourceTree + <group> + + 1176A753062D5C5D75833ACEB61B43A0 + + includeInIndex + 1 + isa + PBXFileReference + path + luac.c + sourceTree + <group> + + 11790AEABCF39AACA03BE811C84830F5 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVPagerIndicator.h + sourceTree + <group> + + 11E5398B435F64954287A2D342445329 + + fileRef + 648F0330C94DC6589C158523099F6158 + isa + PBXBuildFile + settings + + COMPILER_FLAGS + -DOS_OBJECT_USE_OBJC=0 + + + 11EE8118F85D2DC8070CB83AC30DD02D + + fileRef + C9F21D916FDC1AC048E348E299283081 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 11F5B2A5F47A138BD2CCF2FB2416493D + + includeInIndex + 1 + isa + PBXFileReference + path + liolib.c + sourceTree + <group> + + 128D58162055B047C51D86A1D442573B + + fileRef + D349ED1F73391A240C8B8E9CD2DA7C3E + isa + PBXBuildFile + + 1308ADF1BADA3AA8A92FDE73A663787D + + fileRef + 3E3B35F64BBD671E298088C15B7393BA + isa + PBXBuildFile + + 135BEBB31E749A99440FD600E5940FF6 + + fileRef + 8306329169090362CB141FBA8435F64D + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 13A7620016E596D02BD795846283AF3C + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LuaView.h + sourceTree + <group> + + 13DC702D891F455192182ED17BC34770 + + fileRef + 74B430389E22FD25ECF9232BAA88F7D3 + isa + PBXBuildFile + + 13F1E6A9AC1DAB47E8F3F6239D8032B8 + + fileRef + 1100D9ED94AE6338FFDA6931A921B42E + isa + PBXBuildFile + + 13FC308356BE30CC76F40FC7AD64554A + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + SDImageCache.m + path + SDWebImage/SDImageCache.m + sourceTree + <group> + + 143F3334F0EA46492CDB8852A174193F + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVPanGesture.m + sourceTree + <group> + + 14B8B9B15ECBE87983FF987239AB2D7B + + children + + 31E4C72577D34E089E65548C02EAF060 + + isa + PBXGroup + name + Frameworks + sourceTree + <group> + + 14CE973C98BCFE2CA63DF9A742F66569 + + fileRef + 13A7620016E596D02BD795846283AF3C + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 153B765CE8AD38E26965073FE2DE15AE + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + wrapper.plug-in + name + MJRefresh.bundle + path + MJRefresh/MJRefresh.bundle + sourceTree + <group> + + 1588932714FCB49248FC29EA8238A8F7 + + fileRef + 68A8B216570A7B3871B5BA19DB93950B + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 15F58E66DAF567EB49184105B405891A + + fileRef + 3F1D737696EBBC729E68A3C60EAF2F93 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 16843938C648237C8CAC81B5320B5F39 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + UIScrollView+MJExtension.m + path + MJRefresh/UIScrollView+MJExtension.m + sourceTree + <group> + + 1756A8D7E6B7D922A045FA36CDA275A0 + + fileRef + 9A82DB7DD554C9E85AD3EFFA6C542260 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 178A8E6D0EA5FAEA241FC56358B39A5B + + buildActionMask + 2147483647 + files + + E76DE396354ECAA11277F37907E12FE7 + 8469CAC241069ACC421B17248ED1C118 + 85493EC5AE88F0BB63531F4CBAE4B820 + + isa + PBXFrameworksBuildPhase + runOnlyForDeploymentPostprocessing + 0 + + 17B71DFA61AC754D923F842C63CBF6A8 + + fileRef + AC02134060C86A6645D20B2B8D1DCF73 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 182B279C4AE343381DC15D1861FA1E1E + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVWebView.h + sourceTree + <group> + + 185F2A7CBB42DFA6F9D171BF6661B089 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + lua.h + sourceTree + <group> + + 18DA5A556955B4F7FE5E281E7BEA37C7 + + fileRef + 52B2155FD2A473541D7FEF05165041DC + isa + PBXBuildFile + + 18FBF186487AAD9AA2A675431D9D1F22 + + fileRef + D12AEF57FA46A5ABDB96B0EE268F3C03 + isa + PBXBuildFile + + 18FC55E7A2AA58B1092D833C3A201243 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVCollectionView.h + sourceTree + <group> + + 1956AC05FCF697332BA9015C86C6F882 + + fileRef + 3CA4506700C9BDB658F10D7F789983C3 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 19800E4D9F28F1423BE14E39A3E4A865 + + fileRef + 5A6D4F8193304D1E43BF6F17B433B8C2 + isa + PBXBuildFile + + 1A38EE516FF7ACB089D5DF171C1C500B + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVExCollectionView.m + sourceTree + <group> + + 1A45B0E798B34E1189EF818C912D78A7 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + NSData+ImageContentType.m + path + SDWebImage/NSData+ImageContentType.m + sourceTree + <group> + + 1A7FC013AFEA93159B064CDE76F9C3DA + + fileRef + 1D28065CDC689C0CAA02ECA4D99F4EEE + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 1B04371E67EC2B2015B108FD848BCFC7 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVPagerViewCell.m + sourceTree + <group> + + 1B269A79B1296BAA0AD98E2F8512F4AF + + explicitFileType + archive.ar + includeInIndex + 0 + isa + PBXFileReference + name + libMJRefresh.a + path + libMJRefresh.a + sourceTree + BUILT_PRODUCTS_DIR + + 1B58180185A80744B543A9B346759BCF + + explicitFileType + archive.ar + includeInIndex + 0 + isa + PBXFileReference + name + libLuaViewSDK.a + path + libLuaViewSDK.a + sourceTree + BUILT_PRODUCTS_DIR + + 1C3FA2159C6D603331366253373F76A9 + + fileRef + 93F57328890CBD41C124EB0AF10B1F4F + isa + PBXBuildFile + settings + + COMPILER_FLAGS + -DOS_OBJECT_USE_OBJC=0 + + + 1C7DD8869EC78DBFE3F563240B7A9EA5 + + fileRef + 8DC7D7B476F660C2250067B1F74E47D6 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 1D28065CDC689C0CAA02ECA4D99F4EEE + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVAlert.h + sourceTree + <group> + + 1D3B449F78B6BEFE4B3E6D8D7A1DB3A0 + + fileRef + A330621447BE705174FA9138F96957BA + isa + PBXBuildFile + + 1EE74E74E0A41F0D521810824CD32B55 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + SDWebImageCompat.m + path + SDWebImage/SDWebImageCompat.m + sourceTree + <group> + + 1EFA9AF0945D053F5211C3347AE83BEE + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVViewController.m + sourceTree + <group> + + 202F270B05D27D84805A7263ED30F087 + + fileRef + 41F337BB92269F62AB427528FA16501B + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 207EFA12AAA77DB5AA7C8CCD22F8929C + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + UIView+WebCacheOperation.m + path + SDWebImage/UIView+WebCacheOperation.m + sourceTree + <group> + + 21D94823F69A197BB17A50E03C83A865 + + fileRef + AC84A33033DFE29523E204D805A919ED + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 2230F2079225B9F62BAB22ADDB779CC1 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + lvm.h + sourceTree + <group> + + 225B344FAD231860F01CA7091A0CAB8E + + fileRef + EA635DA51B921749209EE5E0FD68A065 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 2300B4A751ED386AA126C27E45CDF588 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + MJRefreshFooter.m + path + MJRefresh/Base/MJRefreshFooter.m + sourceTree + <group> + + 238BC3EF368DB6136B5741FDE888C8AF + + baseConfigurationReference + A24C870F09AD5EB0FD238F5985B6A0EF + buildSettings + + ENABLE_STRICT_OBJC_MSGSEND + YES + GCC_PREFIX_HEADER + Target Support Files/luaviewEx/luaviewEx-prefix.pch + IPHONEOS_DEPLOYMENT_TARGET + 8.0 + MTL_ENABLE_DEBUG_INFO + YES + OTHER_LDFLAGS + + OTHER_LIBTOOLFLAGS + + PRIVATE_HEADERS_FOLDER_PATH + + PRODUCT_NAME + $(TARGET_NAME) + PUBLIC_HEADERS_FOLDER_PATH + + SDKROOT + iphoneos + SKIP_INSTALL + YES + + isa + XCBuildConfiguration + name + Debug + + 23FBFC7BA4421F1EA9D8A9B6ED868E43 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + luaviewEx-dummy.m + sourceTree + <group> + + 24985E299C50D6EA5B6F65A96C23A6FA + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVToast.m + sourceTree + <group> + + 257C68D5BBF7DB619C983BD8A8D64CF0 + + fileRef + 4655D2A0BA28DDF4EA6E5F8A9C547F27 + isa + PBXBuildFile + + 25F8ABDD1532A296D8F95098E2E0A972 + + isa + PBXFileReference + lastKnownFileType + wrapper.framework + name + Foundation.framework + path + Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.0.sdk/System/Library/Frameworks/Foundation.framework + sourceTree + DEVELOPER_DIR + + 25F9EE94AE7AF0C4ED35B883A17FEE6D + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + lstring.h + sourceTree + <group> + + 27D84310F981F3E905B2A8A05D54BC5A + + fileRef + 9699AEE717090D3F6BB2E069B1D3F202 + isa + PBXBuildFile + + 27FA2D8906DD4F937A0A9C1BF0216041 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + JUFLXLinearLayoutView.m + sourceTree + <group> + + 28587B962BF1C1C6D7FF6A499334D169 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + SDWebImageDecoder.h + path + SDWebImage/SDWebImageDecoder.h + sourceTree + <group> + + 28AEC8C06FEAE1E55EECCC77DFECD002 + + fileRef + B3FB2B7E053D86661135FE06C5F87591 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 290C7E36D40B8B10B5003CF70DBCDB3C + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVScrollView.h + sourceTree + <group> + + 29793D4CD0F70C98787EB90A858B866D + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVNinePatchImage.m + sourceTree + <group> + + 298A6E76D4609E4DD748F7A0B5058A47 + + children + + F07F668E46955FC5E926C760A0598B3C + B29CF767D9C91558C51533ACD62C6953 + 348F8A233625C26B1D77220F0D803D8E + ADF4B57B40B0DDEE9FA7B619894FA0F7 + E5820222B31E493A0C3A07B6C559016E + 2BC2F5AD1A6D3EA238BBE269BC23B347 + 8A1F06898602CDD0A78A85D83BB242CA + + isa + PBXGroup + name + kit + path + kit + sourceTree + <group> + + 29DA1A8FCA95821FCCFA1E178ED40007 + + includeInIndex + 1 + isa + PBXFileReference + path + lzio.c + sourceTree + <group> + + 29F78858354DBAB936125BF9ABA2E6C5 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVMethod.m + sourceTree + <group> + + 2A057CEC7805963AEC968D52AF26801B + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVLongPressGesture.m + sourceTree + <group> + + 2A2C66C5B9F0116FD8909DE10413432A + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + lapi.h + sourceTree + <group> + + 2A3D8905FED90C95EF0CA9CD6FD22248 + + children + + 6D8F7AC3418604B39588E40806799991 + 1B58180185A80744B543A9B346759BCF + 1B269A79B1296BAA0AD98E2F8512F4AF + BCA2EC0484FF8D42B4603EA2477BAAB8 + 838F7D9ED6147CD048D86BC072B9D41E + 107D55D61A4636DE8BA66B963823103B + + isa + PBXGroup + name + Products + sourceTree + <group> + + 2A613341E55CD55DECB97E5667DFCF29 + + fileRef + 04398C72E6C55DFAD9B02065B62FC649 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 2AA265A03762A4ED86C67A85B0D45BD3 + + fileRef + 4606EFB57FB5066F39397C739BF84CC6 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 2AB0F59C7F97CC7B8D41743BF7D4A0E3 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVNavigation.h + sourceTree + <group> + + 2ACE817433802BA8E77DDB9B9EDC7AAE + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LuaViewCore.m + sourceTree + <group> + + 2ADE7B74B2C418956E5FFE77F789DF61 + + isa + PBXTargetDependency + name + MJRefresh + target + 9AC35F1DE54EB28C844CAC19E05D5095 + targetProxy + 40E980DA4B6F380D5AD6DBF8E43D20FD + + 2AE72648774F93E65F255FE384690161 + + isa + PBXTargetDependency + name + MJRefresh + target + 9AC35F1DE54EB28C844CAC19E05D5095 + targetProxy + BB1C328D536B8ADFD30FCA9B434578DD + + 2AFB043380061347E950F7F5CFF33C32 + + fileRef + 30F33A2D9D9467011EBC18ECD91DA6D0 + isa + PBXBuildFile + + 2B80A2F7CEAB7A0DAEA25437A3D07446 + + fileRef + FEC5A9842DD28C22DBD0D0B3CF60EB38 + isa + PBXBuildFile + + 2BA3C917C6086A279F6B10D0A29D21F9 + + fileRef + 3F479EBA3C68D808C1571DB9D1E123C2 + isa + PBXBuildFile + + 2BC2F5AD1A6D3EA238BBE269BC23B347 + + includeInIndex + 1 + isa + PBXFileReference + path + sys.lua + sourceTree + <group> + + 2BD1B6C16B749F5AF1280ABB7EBEDB68 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVCollectionViewDelegate.m + sourceTree + <group> + + 2BE8EFE72F4FCDF1B804A4902016F2AA + + fileRef + 8A1AA383C04F4B4FE460C97AFF881E03 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 2C4BF365CE5FC518D1CC6489715D12A0 + + fileRef + DB560486479DDDD377EEF25306A3EAFD + isa + PBXBuildFile + + 2CAA5C0284F787A6090F6BAC02BD6FA7 + + fileRef + 78482F44635EAEE1E97518CA8E012BD9 + isa + PBXBuildFile + + 2CE8F04F1B87E46F188C3E79A3E7E632 + + fileRef + 08957A35CBC7E56DF6CE78CBC5BF5B8C + isa + PBXBuildFile + + 2D109731797C16F162C393B7EDC8CEBB + + includeInIndex + 1 + isa + PBXFileReference + path + lfunc.c + sourceTree + <group> + + 2D26AAA839209BDEB393111BD6B5AA9A + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + text.plist.xml + path + luaviewEx-info.plist + sourceTree + <group> + + 2D67118429E02A2F2E0FF7503F2864E1 + + fileRef + FDF43F1175E8CEF86FD60EE66B0C9901 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 2D8E8EC45A3A1A1D94AE762CB5028504 + + buildConfigurations + + A70CDAD61F90AC503C7D04CC22DA2923 + FB45FFD90572718D82AB9092B750F0CA + + defaultConfigurationIsVisible + 0 + defaultConfigurationName + Release + isa + XCConfigurationList + + 2E54C4285C2C276EAC1EBAC04C14F68F + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + MJRefreshAutoGifFooter.m + path + MJRefresh/Custom/Footer/Auto/MJRefreshAutoGifFooter.m + sourceTree + <group> + + 2F979F6ACAA073B19634E2BA16AC053C + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVEmptyRefreshCollectionView.h + sourceTree + <group> + + 2FAAABF17BC79FA8FD0C04DB14C5D3ED + + fileRef + 3A9EF7E2C2E6E1B66B2FD76A48F2D9F0 + isa + PBXBuildFile + + 2FCD639841C341855AA4F5F53D6934BC + + fileRef + 16843938C648237C8CAC81B5320B5F39 + isa + PBXBuildFile + + 2FE46EC96485818C89D7B45BA9234409 + + fileRef + 50B82175C6E762013B79388F8F47FA64 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 3023A66A4CFCABCEB3DD519B52734B3E + + fileRef + 6EB625D3C0904EA032BD4FF18F08F504 + isa + PBXBuildFile + + 306D7A60B8274399E237C738DBE566F9 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + JUFLXTargeNamespace.h + sourceTree + <group> + + 30A338DD47C8132F8933C24F92587BC7 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + llex.h + sourceTree + <group> + + 30B6CD7FA08488E701AAEEEE69524B0E + + fileRef + 13FC308356BE30CC76F40FC7AD64554A + isa + PBXBuildFile + settings + + COMPILER_FLAGS + -DOS_OBJECT_USE_OBJC=0 + + + 30F33A2D9D9467011EBC18ECD91DA6D0 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVFlowLayout.m + sourceTree + <group> + + 315138DB1523B1BEA7346EA032464BB9 + + fileRef + 5FE8AC69826BCB6A0364DEB2554AF819 + isa + PBXBuildFile + + 3172CFE0CF1E9C3B42AE1EC62DE29788 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + MJRefreshConst.h + path + MJRefresh/MJRefreshConst.h + sourceTree + <group> + + 31E4C72577D34E089E65548C02EAF060 + + children + + FA9C85076DEB156BACB490133D4BA212 + 25F8ABDD1532A296D8F95098E2E0A972 + E9147195251E0E11AD9BEC4D2227EA9B + 3AC8A9CDF659CBBCA1320C8046434793 + + isa + PBXGroup + name + iOS + sourceTree + <group> + + 321201220989F9A82975E3F33C5D3810 + + fileRef + 1A38EE516FF7ACB089D5DF171C1C500B + isa + PBXBuildFile + + 32CE3E4C2DD0CF037AAD237165E85B7C + + fileRef + 37695D0A05BED6ABF1F579FD9E99554A + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 3335AE7C3E8931A3729ED7A2E4001A6D + + children + + 69996EEA1EF53A0BE18F7F2C29EB18B8 + + isa + PBXGroup + name + SDK + path + SDK + sourceTree + <group> + + 33C0035DE5EA0FA943B3EB0B2F06D333 + + children + + 9F92270DCACF8D923B9153BBF8998633 + 0534ACA88092EB85C6F1DE09FB52C1E4 + 38430E9C4497E39BB90C126694ACD5E1 + + isa + PBXGroup + name + Support Files + path + IOS/Playground/Pods/Target Support Files/LuaViewSDK + sourceTree + <group> + + 340D996E5E6AB982BEB8E2A65A335AE0 + + fileRef + 6A13D12EEC9DC6DEDCBA4329471CAF1C + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 34103EE62B851EC9916E8A77FBBB148F + + fileRef + C323AB62E7B642E70AE36A96CBE0224E + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 3415B5711281517B4105C3A0B5E362CF + + fileRef + 1A45B0E798B34E1189EF818C912D78A7 + isa + PBXBuildFile + settings + + COMPILER_FLAGS + -DOS_OBJECT_USE_OBJC=0 + + + 343F19CF510DDF196F2A2CB298B0A510 + + fileRef + C29E281BD407EA1E9FF4583F7E492710 + isa + PBXBuildFile + + 348B1AF87760A3CCE93BA87530F10E04 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVStyledString.h + sourceTree + <group> + + 348F8A233625C26B1D77220F0D803D8E + + includeInIndex + 1 + isa + PBXFileReference + path + pica.lua + sourceTree + <group> + + 355A3B0609865F729861222E5EB88A38 + + fileRef + 3A86ABA74245357265A063BA94F9F700 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 35CE884E04E758BA7E2AFE50093EF18E + + isa + PBXTargetDependency + name + luaviewEx-luaviewEx + target + C290B4F7BB8A778F7A2AF018EE5FADB2 + targetProxy + D1F548C6DE1AFF9BA9CC67D083AAECC2 + + 3602DBCB7489B22028326F079F87E1D7 + + fileRef + 1176A753062D5C5D75833ACEB61B43A0 + isa + PBXBuildFile + + 36851C6227466105D493FFF23813F8E4 + + fileRef + B1004751E08F54D9C4EB7E6140087333 + isa + PBXBuildFile + + 36893488B2DB0EEA4E31146D66822D87 + + fileRef + 8276641C1150A8C82B9FDA758C0584B8 + isa + PBXBuildFile + settings + + COMPILER_FLAGS + -DOS_OBJECT_USE_OBJC=0 + + + 368BE3BE3BBA301878FFA823CE66B396 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + JUFLXCSSParser.h + sourceTree + <group> + + 36BC801C70F848C3CDF4520508916EF1 + + fileRef + 11790AEABCF39AACA03BE811C84830F5 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 37695D0A05BED6ABF1F579FD9E99554A + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVPagerView.h + sourceTree + <group> + + 3771D065C4364EE639435EE856A96A9D + + children + + EF4D170AC70386955DA726196014FE48 + 1A45B0E798B34E1189EF818C912D78A7 + C46C1EF777315A011CEDF14E291E5A72 + 13FC308356BE30CC76F40FC7AD64554A + 47447F822E904AC8D6A5E82A55016A52 + 1EE74E74E0A41F0D521810824CD32B55 + 28587B962BF1C1C6D7FF6A499334D169 + 9F57030CDD579F1DBC6E7C388F349C53 + BEF0D115FB13016A3121AD78BA006B14 + 660EF3BC8F89F4322E806B097DBD0339 + EA635DA51B921749209EE5E0FD68A065 + BF9EE48CC6AA0659A6AA22FE3879A369 + CC9C067A4572D72BFAC894C14C3D102C + 41254C3A0D0DC1E1AF3F89F410551EAB + 5469984FA164FC0AACE23B19A4BE44C1 + CE0D4CC14A9991B37123BA163AB5E18E + 648F0330C94DC6589C158523099F6158 + 3A86ABA74245357265A063BA94F9F700 + C18E08C2A4DA6073DABE1DF3C5656FB3 + D4E8D3FA06BC49528D8A991F98D7AC27 + 5D6D43DC320B0EEA77FCBB71A0767141 + C24EFDD1BF0C59D941292EA33D14FAD7 + 93F57328890CBD41C124EB0AF10B1F4F + EE59907F54D7D76447835CACEC77F65A + 8276641C1150A8C82B9FDA758C0584B8 + D7B91D04701A73CA3B558049CCCD0E09 + EB7BBEEAD9550FE792CA33AFFB49757E + A600AD735D6B2205314D42333E17E522 + 207EFA12AAA77DB5AA7C8CCD22F8929C + + isa + PBXGroup + name + Core + sourceTree + <group> + + 377B345153866024C525006D1C851AF1 + + fileRef + 409856ED10C8655803DCBABABF8CDCA9 + isa + PBXBuildFile + + 37A808B1B5C22884F6C6C281A28601BD + + fileRef + 29DA1A8FCA95821FCCFA1E178ED40007 + isa + PBXBuildFile + + 37FAB69E15555AFBD466EF12EA178655 + + children + + 01730232DD754F790B27162853B22ED3 + 27FA2D8906DD4F937A0A9C1BF0216041 + + isa + PBXGroup + name + LayoutExtensions + path + LayoutExtensions + sourceTree + <group> + + 38430E9C4497E39BB90C126694ACD5E1 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LuaViewSDK-prefix.pch + sourceTree + <group> + + 3868CA615CF17F32115555E6C8E69485 + + fileRef + 48BC94706ED0F1B8FD935772E6EBF997 + isa + PBXBuildFile + + 396C87EE0AA4B806979FB5BF72B590FD + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVData.m + sourceTree + <group> + + 3978A4D5F882FD7B57A64C642659038A + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVClassInfo.h + sourceTree + <group> + + 3A59FA484998DB5F7E476DDAF37CB5A4 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVPkgManager.h + sourceTree + <group> + + 3A86ABA74245357265A063BA94F9F700 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + UIButton+WebCache.h + path + SDWebImage/UIButton+WebCache.h + sourceTree + <group> + + 3A9EF7E2C2E6E1B66B2FD76A48F2D9F0 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVTransform3D.m + sourceTree + <group> + + 3ABBBCC580EA95EE98AC7C9B4551E03E + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVTapGesture.h + sourceTree + <group> + + 3AC8A9CDF659CBBCA1320C8046434793 + + isa + PBXFileReference + lastKnownFileType + wrapper.framework + name + UIKit.framework + path + Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.0.sdk/System/Library/Frameworks/UIKit.framework + sourceTree + DEVELOPER_DIR + + 3B30502F210F85DBBEA561C0BCFE8A22 + + fileRef + B5550F3748103756054ED054554A6778 + isa + PBXBuildFile + + 3B4D54EC5356558BBEBDEA71AFC367AA + + isa + PBXTargetDependency + name + SDWebImage + target + 86C582DB039C2092AB70FE04FD45E436 + targetProxy + 6E2FC36EE1B8888738631373AFC9C725 + + 3C85B6EEC1328439E1C830EDFEC9C0D3 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + MJRefreshAutoNormalFooter.h + path + MJRefresh/Custom/Footer/Auto/MJRefreshAutoNormalFooter.h + sourceTree + <group> + + 3CA4506700C9BDB658F10D7F789983C3 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVExImage.h + sourceTree + <group> + + 3D441A790368BA67192D448BB061ECAD + + baseConfigurationReference + A24C870F09AD5EB0FD238F5985B6A0EF + buildSettings + + ENABLE_STRICT_OBJC_MSGSEND + YES + PRODUCT_NAME + luaviewEx + SDKROOT + iphoneos + SKIP_INSTALL + YES + WRAPPER_EXTENSION + bundle + + isa + XCBuildConfiguration + name + Debug + + 3D61E9C25101C9A7C4F68EA4EDDA8C1D + + fileRef + E5820222B31E493A0C3A07B6C559016E + isa + PBXBuildFile + + 3DDC1AB7994BEA0D3137BB1E9144A281 + + children + + 153B765CE8AD38E26965073FE2DE15AE + + isa + PBXGroup + name + Resources + sourceTree + <group> + + 3DEEC2A0022DF6A997466DF847D4AC57 + + fileRef + 8423C840B31734512F55FE12F7DEA797 + isa + PBXBuildFile + + 3E3B35F64BBD671E298088C15B7393BA + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVEvent.m + sourceTree + <group> + + 3E9A0367C6AA92183B76C3BAA7F2E63E + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVAnimate.m + sourceTree + <group> + + 3F1D737696EBBC729E68A3C60EAF2F93 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVViewController.h + sourceTree + <group> + + 3F479EBA3C68D808C1571DB9D1E123C2 + + includeInIndex + 1 + isa + PBXFileReference + path + ldo.c + sourceTree + <group> + + 3F79D09B649802083832E8054268C853 + + fileRef + 8304D148F5CA1DEEF71F60C222E9758D + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 3F7CA8B54243D5879C5432DD04A4CFE8 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + lgc.h + sourceTree + <group> + + 3F80604355A58ADDF479268A9FC35629 + + fileRef + 143F3334F0EA46492CDB8852A174193F + isa + PBXBuildFile + + 3FE29B6FF57A1C9756EED3732C87F422 + + includeInIndex + 1 + isa + PBXFileReference + path + lcode.c + sourceTree + <group> + + 3FF2E884BB70C9815AD1F3D1158B474C + + fileRef + 3978A4D5F882FD7B57A64C642659038A + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 409856ED10C8655803DCBABABF8CDCA9 + + includeInIndex + 1 + isa + PBXFileReference + path + loadlib.c + sourceTree + <group> + + 40C0BE58FF476ABB4150234A1F243BE8 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + text.plist.xml + path + Pods-Demo-acknowledgements.plist + sourceTree + <group> + + 40E980DA4B6F380D5AD6DBF8E43D20FD + + containerPortal + D41D8CD98F00B204E9800998ECF8427E + isa + PBXContainerItemProxy + proxyType + 1 + remoteGlobalIDString + 9AC35F1DE54EB28C844CAC19E05D5095 + remoteInfo + MJRefresh + + 40F3ADC7C956412AEF1B29B263D033C6 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVExGlobalFunc.h + sourceTree + <group> + + 41254C3A0D0DC1E1AF3F89F410551EAB + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + SDWebImageManager.m + path + SDWebImage/SDWebImageManager.m + sourceTree + <group> + + 413A1B350BC4E2840EC6B7F768834B25 + + includeInIndex + 1 + isa + PBXFileReference + path + lstring.c + sourceTree + <group> + + 417628C5AB133E3820D200D2C504A4A8 + + fileRef + 05146DF4C72F6DE622B3482E83AD4A13 + isa + PBXBuildFile + + 4176F658CFF9600AFE6C1D54CC08F215 + + buildActionMask + 2147483647 + files + + isa + PBXSourcesBuildPhase + runOnlyForDeploymentPostprocessing + 0 + + 41794AAC220BE91DA5E4576ED92D886C + + fileRef + 6ADB003D91876455C480FC897DAEFC0C + isa + PBXBuildFile + + 41F2BFDCB233A10CA0F9FAE16D9FDBA1 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + ldo.h + sourceTree + <group> + + 41F337BB92269F62AB427528FA16501B + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVBlock.h + sourceTree + <group> + + 42E242563E7B39DE4D2A3CEBDD3791B3 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + UIScrollView+LuaView.h + sourceTree + <group> + + 436EF80C9C6BE9FAF29ADBA88DF4EA43 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + JUFLXLayoutDefine.h + sourceTree + <group> + + 43F27D44CB41541D3D1BA8B25842E2F2 + + fileRef + A89371DD012A68160E5CD71FD773B168 + isa + PBXBuildFile + + 4442C696FE39C7A55558985FD0ECD80F + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVCollectionViewDelegate.h + sourceTree + <group> + + 4574670DDB3FD6BD2C621CEBE3BBBA6B + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + MJRefreshAutoFooter.h + path + MJRefresh/Base/MJRefreshAutoFooter.h + sourceTree + <group> + + 457F7148333E0151B49C4ECBF318D59F + + fileRef + 6CE8BA1CC153472DEA5348F243B6C213 + isa + PBXBuildFile + + 4590F66CFBBF00A2335C58E7D0EFA120 + + baseConfigurationReference + 046DE20980BF0D1ED96192F78A9F3B33 + buildSettings + + ENABLE_STRICT_OBJC_MSGSEND + YES + GCC_PREFIX_HEADER + Target Support Files/MJRefresh/MJRefresh-prefix.pch + IPHONEOS_DEPLOYMENT_TARGET + 8.0 + MTL_ENABLE_DEBUG_INFO + NO + OTHER_LDFLAGS + + OTHER_LIBTOOLFLAGS + + PRIVATE_HEADERS_FOLDER_PATH + + PRODUCT_NAME + $(TARGET_NAME) + PUBLIC_HEADERS_FOLDER_PATH + + SDKROOT + iphoneos + SKIP_INSTALL + YES + + isa + XCBuildConfiguration + name + Release + + 45AD08573C692305302552D469CB2BD7 + + children + + D21DBF15312A3EDAC3D56BBEC5E6E0AB + 4574670DDB3FD6BD2C621CEBE3BBBA6B + 9699AEE717090D3F6BB2E069B1D3F202 + 9E56A950A523AF42E0BE2DA712B49B59 + 2E54C4285C2C276EAC1EBAC04C14F68F + 3C85B6EEC1328439E1C830EDFEC9C0D3 + 00488347FBD3CC25591CEB62F96C8289 + C323AB62E7B642E70AE36A96CBE0224E + 8C7BEE87A14BA5D0F76EA64D084F1A4E + 5C0830C9974133371583CD34FDFF87C3 + A330621447BE705174FA9138F96957BA + 9FFB35B3F018590030459C786B08B2F3 + FC2A5EA8CF19876ACA547F5571BE8E47 + E5EED4DD19A8E92777CFC22FF262A0CA + A2BA69A9B7C5EECB89993DED249AF06E + 4D39C512556D7FCD68C18D059F7F71CE + 87A0C6CC09D42598458459294742E11F + BDA86D0FD83C42AA566D217D2CD53E99 + 65A2C298D65EFC5B359821B8872CB809 + 3172CFE0CF1E9C3B42AE1EC62DE29788 + CA82E9BEF6B9FB3705F4F38D7B116628 + 8539600F54252E5FBC866DCA02EF1759 + 2300B4A751ED386AA126C27E45CDF588 + 6E9F50EA7AF8CAC8A44A18346E92060C + 7D46154A7C1EEFA233E5869A4BBA6CB7 + 09812FC481F673CDE2428CAC41614458 + 78567B2D2C3DB8D0A00936D224FD02FA + 64ACB0FBB5D56CCADEFE5D63086EFD88 + 741C079B7C1BC49D17B301E512906A4B + 04398C72E6C55DFAD9B02065B62FC649 + EB485310B5B8619A748A5DEEEFF8C7FE + 6107113B45C44620700E66AA61893EFD + 49594237A643B228FF63841F615C833C + FEC654FB4657F839ABBE23B2CBEFF577 + 16843938C648237C8CAC81B5320B5F39 + 96286368DBD96F09E58156FE69D442F9 + 1100D9ED94AE6338FFDA6931A921B42E + 5F7910408326053D74B3A4AEDE4BA336 + 6C15D01D64AB135BFB9D9878FB67C6BB + 3DDC1AB7994BEA0D3137BB1E9144A281 + DAC0F4716E8B8D51CDDD258065F8F833 + + isa + PBXGroup + name + MJRefresh + path + MJRefresh + sourceTree + <group> + + 45B3E02FDFBD5FFF514F0804DDD82F30 + + fileRef + 6ADC425DC7BFD5CF703F10B85943A730 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 4606EFB57FB5066F39397C739BF84CC6 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVButton.h + sourceTree + <group> + + 461C624817D2B27A70ADF7B3B645A9A3 + + fileRef + 9B4D175520321FCF1AA45EE33A27A2D0 + isa + PBXBuildFile + + 4655D2A0BA28DDF4EA6E5F8A9C547F27 + + includeInIndex + 1 + isa + PBXFileReference + path + lopcodes.c + sourceTree + <group> + + 467F9F9B4008403710513C6090F407E1 + + fileRef + FDB6110C621265090FE681745870492C + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 46B06AE59DEC7D9A99D69A95CBD3BC37 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LView.h + sourceTree + <group> + + 46DBBC6251901BECBCD8E7091E8191A9 + + includeInIndex + 1 + isa + PBXFileReference + path + ltm.c + sourceTree + <group> + + 470CC2A2EF2E758648B5A1B557448907 + + fileRef + 2F979F6ACAA073B19634E2BA16AC053C + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 47447F822E904AC8D6A5E82A55016A52 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + SDWebImageCompat.h + path + SDWebImage/SDWebImageCompat.h + sourceTree + <group> + + 47566D1C2F4D37A210642A43E68CEA09 + + includeInIndex + 1 + isa + PBXFileReference + path + loslib.c + sourceTree + <group> + + 47A11CEDE14C1CCF86BB294E0906EBF7 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVTextField.m + sourceTree + <group> + + 48409AA22B2FB990D7DC70F2DD9643BC + + fileRef + 3C85B6EEC1328439E1C830EDFEC9C0D3 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 48A3B5709CC1D4959D702174B6A3C032 + + baseConfigurationReference + 9EF5814F71502908E43FAE2674061C95 + buildSettings + + ENABLE_STRICT_OBJC_MSGSEND + YES + IPHONEOS_DEPLOYMENT_TARGET + 8.0 + MACH_O_TYPE + staticlib + MTL_ENABLE_DEBUG_INFO + NO + OTHER_LDFLAGS + + OTHER_LIBTOOLFLAGS + + PODS_ROOT + $(SRCROOT) + PRODUCT_NAME + $(TARGET_NAME) + SDKROOT + iphoneos + SKIP_INSTALL + YES + + isa + XCBuildConfiguration + name + Release + + 48BC94706ED0F1B8FD935772E6EBF997 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVAnimator.m + sourceTree + <group> + + 49594237A643B228FF63841F615C833C + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + NSBundle+MJRefresh.m + path + MJRefresh/NSBundle+MJRefresh.m + sourceTree + <group> + + 49E3940009490371B28511581FE8D6FC + + fileRef + CE0D4CC14A9991B37123BA163AB5E18E + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 4AC7BF99BA86DB548275898882B20E8A + + fileRef + 4574670DDB3FD6BD2C621CEBE3BBBA6B + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 4B88A0E05758471836E5FAE593F35253 + + fileRef + 348F8A233625C26B1D77220F0D803D8E + isa + PBXBuildFile + + 4B9548C88C2542194FB30537F1D4EA35 + + fileRef + 4C3DF57E5A7F53CC7BEBB0A0E9714E53 + isa + PBXBuildFile + + 4BAE51A305848F4F211246D3D71D9352 + + fileRef + 660EF3BC8F89F4322E806B097DBD0339 + isa + PBXBuildFile + settings + + COMPILER_FLAGS + -DOS_OBJECT_USE_OBJC=0 + + + 4C0112C4E5A2D86AA0014763347AFFCC + + fileRef + 2BC2F5AD1A6D3EA238BBE269BC23B347 + isa + PBXBuildFile + + 4C0F7F7CDC4D238A667370DBE4547AA1 + + fileRef + CF4CBF5DE8C3747B873AA4D15CAFD2EC + isa + PBXBuildFile + + 4C26E8911DD624CEEA25A8569E14C0EE + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + UIView+JUFLXNode.h + sourceTree + <group> + + 4C347D45C0D15332983087936AC0CE82 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + ldebug.h + sourceTree + <group> + + 4C3DF57E5A7F53CC7BEBB0A0E9714E53 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVGesture.m + sourceTree + <group> + + 4C773573A7DC6AD33C835DE783C1EE6D + + fileRef + 5A586456AC18C2CF5115BB55C9569997 + isa + PBXBuildFile + + 4C79F51DCA2597370D2EF0D5085BC662 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + text.script.sh + path + Pods-Demo-resources.sh + sourceTree + <group> + + 4C9DE4A0935A9DE9FE2554816FB5CA1F + + fileRef + 907739E0BFCC67F1A0134909CD0062BE + isa + PBXBuildFile + + 4CB07ED2447146541E045018FD241CD2 + + fileRef + 5563C227F4CFD0BB18C46F1A4D3E87CD + isa + PBXBuildFile + + 4CD886EF1C0728613450008CCC22F07A + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVGrammarChanger.m + sourceTree + <group> + + 4CE95F3F7F0B9DE5150B385E98AEE0BA + + fileRef + 0209E35EBB89158BE1EEE63A003EFA02 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 4D39C512556D7FCD68C18D059F7F71CE + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + MJRefreshBackStateFooter.h + path + MJRefresh/Custom/Footer/Back/MJRefreshBackStateFooter.h + sourceTree + <group> + + 4DC59F2036EB1022243C11D812DFC233 + + fileRef + 07282814DCAF1910BC004FD25EFAB618 + isa + PBXBuildFile + + 4E212E1A5EF66FA8DFDD53AC6D5BD4C2 + + children + + A24C870F09AD5EB0FD238F5985B6A0EF + 23FBFC7BA4421F1EA9D8A9B6ED868E43 + CF2EE622517E7C9291ACF880ED4F382D + + isa + PBXGroup + name + Support Files + path + ../Playground/Pods/Target Support Files/luaviewEx + sourceTree + <group> + + 4E7F57362B7F28AC3C5046B88802795D + + children + + CC8B0F53E92326E86E80F3EF085EFD8F + + isa + PBXGroup + name + luaview + path + luaview + sourceTree + <group> + + 4EF1225C45527E651350701A3F7C09BD + + fileRef + 8A1F06898602CDD0A78A85D83BB242CA + isa + PBXBuildFile + + 4F8882E58A6AE23CB96516C6BD8A3671 + + fileRef + D4E8D3FA06BC49528D8A991F98D7AC27 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 501C4944BE8D6558127A3515B5ED7B14 + + includeInIndex + 1 + isa + PBXFileReference + path + ldump.c + sourceTree + <group> + + 50B82175C6E762013B79388F8F47FA64 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + ltable.h + sourceTree + <group> + + 50EAAA4F38A292843B98C548875F0906 + + fileRef + D142B1D5BCF35B7080DA051377DA4A2A + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 5197F0B2921DB5FA553B2720ECD82A52 + + fileRef + D7B91D04701A73CA3B558049CCCD0E09 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 51D07662E3A06201708447B9E508893E + + fileRef + 084241B9DC5DC7A2F68E1E7FE94FDEAF + isa + PBXBuildFile + + 524DF2A621890393D2577CD3024C6E26 + + fileRef + 5C0830C9974133371583CD34FDFF87C3 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 52B2155FD2A473541D7FEF05165041DC + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVPagerView.m + sourceTree + <group> + + 533807B79DD8E8A4D977402B20A0E8CD + + fileRef + 368BE3BE3BBA301878FFA823CE66B396 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 53740A50BB4D7B5B987229EEB1AA96B0 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVTypeConvert.h + sourceTree + <group> + + 537AA66BF9E146C99B5978D8E4ED97B5 + + buildActionMask + 2147483647 + files + + B568311845136064B35ABCB47F2FB2C3 + A40A5BB0C59CB3172B6F36D930EEDD07 + 4B88A0E05758471836E5FAE593F35253 + 757F22D31DBD66F4958B653301D41523 + 3D61E9C25101C9A7C4F68EA4EDDA8C1D + 4C0112C4E5A2D86AA0014763347AFFCC + 4EF1225C45527E651350701A3F7C09BD + + isa + PBXResourcesBuildPhase + runOnlyForDeploymentPostprocessing + 0 + + 53964CCABE279C441CAD05C64619E7D4 + + fileRef + FEC654FB4657F839ABBE23B2CBEFF577 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 53A3E35D9C54046E1DA273C64D9AAF2A + + includeInIndex + 1 + isa + PBXFileReference + path + linit.c + sourceTree + <group> + + 53D6E5C9CBA5F03006A11B68D3D95468 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVCollectionView.m + sourceTree + <group> + + 53ED692B1BC969E7D33B2F9945AF9299 + + fileRef + 4C347D45C0D15332983087936AC0CE82 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 5428DADCEEB326157DCEF0040460F704 + + fileRef + 290C7E36D40B8B10B5003CF70DBCDB3C + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 5469984FA164FC0AACE23B19A4BE44C1 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + SDWebImageOperation.h + path + SDWebImage/SDWebImageOperation.h + sourceTree + <group> + + 5559AC81BEB04601F5AA311721824962 + + includeInIndex + 1 + isa + PBXFileReference + path + print.c + sourceTree + <group> + + 5563C227F4CFD0BB18C46F1A4D3E87CD + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVRefreshConst.m + sourceTree + <group> + + 5634BCD8C43E92653BCAA469F1823D00 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVRotationGesture.h + sourceTree + <group> + + 563ED884287349E36EFDEC65B3723922 + + fileRef + 7898632516013BE019048DFEA6E3E811 + isa + PBXBuildFile + + 566BFAA69E2D42EB24C4D860C62D29F5 + + fileRef + DDD8041E4CC6B92551EA7601114170CF + isa + PBXBuildFile + + 5707A271779152F07EC77A7EB7ABD103 + + buildConfigurationList + CF7DA1BF393A2E4987445AD51981272B + buildPhases + + 761D9DCB4D1F974E59EB97C6EA9310B7 + 59379EB9A6D97452CC7D8F912EA06F00 + + buildRules + + dependencies + + E1D0089FB1058478C4ACDB55A089B47E + 2AE72648774F93E65F255FE384690161 + E182D13A0387591244DE25403CED7A1D + F169905FB2516EBBDF450B34D2697422 + + isa + PBXNativeTarget + name + Pods-Demo + productName + Pods-Demo + productReference + BCA2EC0484FF8D42B4603EA2477BAAB8 + productType + com.apple.product-type.library.static + + 573ADC3C891FBA670A36BD45C3D7C6D2 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVEmptyRefreshCollectionView.m + sourceTree + <group> + + 5840CBAFBE72AF044DE77CC10AB2552B + + fileRef + 03782A4641772CAFDF1C6A58B50D0C6B + isa + PBXBuildFile + + 587BBF03B923895B38467C43D72F6D17 + + fileRef + 436EF80C9C6BE9FAF29ADBA88DF4EA43 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 58EE2C602B835CC8F94DDE44687F7A25 + + fileRef + EB42B71A313362AD456F13A76E695788 + isa + PBXBuildFile + + 591836F8255DF1C90A855CAF49D5BA0D + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVDebugConnection.m + sourceTree + <group> + + 59379EB9A6D97452CC7D8F912EA06F00 + + buildActionMask + 2147483647 + files + + FF20B0465ACB4DFBEEC97383ECCC6D49 + + isa + PBXFrameworksBuildPhase + runOnlyForDeploymentPostprocessing + 0 + + 59B2766E8BB4240AF5018C051626DBC8 + + fileRef + F4496B73254185F5F0B1BC1B34947547 + isa + PBXBuildFile + + 59C899DC82B9AAA9CFFC5FE08B5D86CF + + fileRef + E3038A78003298A17C854ABA37E85170 + isa + PBXBuildFile + + 5A28D175F6DF84855662E020BEF79988 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVMethod.h + sourceTree + <group> + + 5A586456AC18C2CF5115BB55C9569997 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVWebView.m + sourceTree + <group> + + 5A6D4F8193304D1E43BF6F17B433B8C2 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVLuaObjBox.m + sourceTree + <group> + + 5A7748C9171BA5B1CE37D01BFB368940 + + fileRef + 3FE29B6FF57A1C9756EED3732C87F422 + isa + PBXBuildFile + + 5A93B171C1E1EDF75E0EFDF1C2DF28FC + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVAnimate.h + sourceTree + <group> + + 5B0F8823D4C55B465C0FAEC9BF9B2EF8 + + fileRef + 5559AC81BEB04601F5AA311721824962 + isa + PBXBuildFile + + 5BAB87E97D5102AD7C495D32161017F5 + + containerPortal + D41D8CD98F00B204E9800998ECF8427E + isa + PBXContainerItemProxy + proxyType + 1 + remoteGlobalIDString + 897DBCA022EEA6EEEE3413D5C335650E + remoteInfo + luaviewEx + + 5C0830C9974133371583CD34FDFF87C3 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + MJRefreshBackFooter.h + path + MJRefresh/Base/MJRefreshBackFooter.h + sourceTree + <group> + + 5D6D43DC320B0EEA77FCBB71A0767141 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + UIImage+GIF.m + path + SDWebImage/UIImage+GIF.m + sourceTree + <group> + + 5D6DBF00422365D3597783C26B241087 + + baseConfigurationReference + A24C870F09AD5EB0FD238F5985B6A0EF + buildSettings + + ENABLE_STRICT_OBJC_MSGSEND + YES + GCC_PREFIX_HEADER + Target Support Files/luaviewEx/luaviewEx-prefix.pch + IPHONEOS_DEPLOYMENT_TARGET + 8.0 + MTL_ENABLE_DEBUG_INFO + NO + OTHER_LDFLAGS + + OTHER_LIBTOOLFLAGS + + PRIVATE_HEADERS_FOLDER_PATH + + PRODUCT_NAME + $(TARGET_NAME) + PUBLIC_HEADERS_FOLDER_PATH + + SDKROOT + iphoneos + SKIP_INSTALL + YES + + isa + XCBuildConfiguration + name + Release + + 5D9C728BD89F17472B0497A4E2516448 + + fileRef + 11F5B2A5F47A138BD2CCF2FB2416493D + isa + PBXBuildFile + + 5DE9729F0A95752FB7D28AB276EE6255 + + children + + 368BE3BE3BBA301878FFA823CE66B396 + 09335FBC624A24A1C3642B6D7D45EADC + 436EF80C9C6BE9FAF29ADBA88DF4EA43 + 97FED081F595C4AC2A873EFD0086F796 + 7EFF7E9CC8716B1EADBAA3B34EEE5EAC + 74B430389E22FD25ECF9232BAA88F7D3 + 306D7A60B8274399E237C738DBE566F9 + E58175612E1B5AA5F33833093611F375 + D09ECEBEA5E66FD2DF0A6ECE2FAB2BCC + 4C26E8911DD624CEEA25A8569E14C0EE + 5DF600C7B7E6DE889926E0C8E2D896D3 + 37FAB69E15555AFBD466EF12EA178655 + + isa + PBXGroup + name + layout + path + layout + sourceTree + <group> + + 5DF600C7B7E6DE889926E0C8E2D896D3 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + UIView+JUFLXNode.m + sourceTree + <group> + + 5F0ED6343850C31C0C0AD29F9E68B2BD + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + text.xcconfig + path + SDWebImage.xcconfig + sourceTree + <group> + + 5F33F15DC5938861D75B66C5AE3B33DB + + fileRef + D34DFB5388EB47DDA90900423E201EC0 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 5F7910408326053D74B3A4AEDE4BA336 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + UIView+MJExtension.h + path + MJRefresh/UIView+MJExtension.h + sourceTree + <group> + + 5FA4EA555E34F7BD719E19D5BFBB4A3B + + fileRef + 6C15D01D64AB135BFB9D9878FB67C6BB + isa + PBXBuildFile + + 5FB6039AF893F51EF15C3750514269CA + + fileRef + 66EA1CE472726D534DCF74F4F71A74B7 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 5FDC9110C37E3DAB16FAC25BA44AB29A + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + lopcodes.h + sourceTree + <group> + + 5FDDDA6FA2FC2F9497F18BC0D8232208 + + fileRef + 01730232DD754F790B27162853B22ED3 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 5FE8AC69826BCB6A0364DEB2554AF819 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVPkgManager.m + sourceTree + <group> + + 6020DBAA71982AD31F66B3807AF5BBA8 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + NSObject+LuaView.m + sourceTree + <group> + + 604D52241F4D1C186EF8EC534C033C3E + + fileRef + 09335FBC624A24A1C3642B6D7D45EADC + isa + PBXBuildFile + + 605A00C3A9A581747761FDA0F0E81F6E + + children + + 809B17D0F089DEBC55260F1E9A01A8E0 + 2A2C66C5B9F0116FD8909DE10413432A + 8C08311EA0B714A95E8F50FC157229C5 + E1BFC584DB7723999816B0D32FE17B0A + C29E281BD407EA1E9FF4583F7E492710 + 3FE29B6FF57A1C9756EED3732C87F422 + 6ADC425DC7BFD5CF703F10B85943A730 + D2F983E998B021AB8223EC8BC9E70211 + B6C43969278258FEFF529D78CFF31785 + 4C347D45C0D15332983087936AC0CE82 + 3F479EBA3C68D808C1571DB9D1E123C2 + 41F2BFDCB233A10CA0F9FAE16D9FDBA1 + 501C4944BE8D6558127A3515B5ED7B14 + 2D109731797C16F162C393B7EDC8CEBB + FB1912F1A67413BD21D9073261B60344 + A5F3A21C1DFA894F14F556DFC2BAACC7 + 3F7CA8B54243D5879C5432DD04A4CFE8 + 53A3E35D9C54046E1DA273C64D9AAF2A + 11F5B2A5F47A138BD2CCF2FB2416493D + F4496B73254185F5F0B1BC1B34947547 + 30A338DD47C8132F8933C24F92587BC7 + E6890D3D99BF75884486558215E27FA1 + 907739E0BFCC67F1A0134909CD0062BE + AC0BC35EC99B1DC651D9B96EA5A7F906 + C8C4C3ECD8CB6AA0DE543993F6E5F91D + 409856ED10C8655803DCBABABF8CDCA9 + 870EC3CFAD191AF3B628C14C7EBA9C69 + 8304D148F5CA1DEEF71F60C222E9758D + 4655D2A0BA28DDF4EA6E5F8A9C547F27 + 5FDC9110C37E3DAB16FAC25BA44AB29A + 47566D1C2F4D37A210642A43E68CEA09 + B5550F3748103756054ED054554A6778 + DDF1B84675F3FD174AD5BD30E6CBF2F0 + DB560486479DDDD377EEF25306A3EAFD + 66EA1CE472726D534DCF74F4F71A74B7 + 413A1B350BC4E2840EC6B7F768834B25 + 25F9EE94AE7AF0C4ED35B883A17FEE6D + E4A93CB04BA6834644426E250C1D2439 + B1004751E08F54D9C4EB7E6140087333 + 50B82175C6E762013B79388F8F47FA64 + 60A3E7ED03589290861C1454F4339DD0 + 46DBBC6251901BECBCD8E7091E8191A9 + 68A8B216570A7B3871B5BA19DB93950B + 6EB625D3C0904EA032BD4FF18F08F504 + 185F2A7CBB42DFA6F9D171BF6661B089 + 1176A753062D5C5D75833ACEB61B43A0 + A37F23A7A0EE7BCC163D74266A85804D + C9F21D916FDC1AC048E348E299283081 + 9364907161F20CB65D50DB69A9A853A3 + EBE7FC492303CCA909B8C62B348A8DF1 + F78FBB2B2E733FFB239613964835C963 + 2230F2079225B9F62BAB22ADDB779CC1 + 29DA1A8FCA95821FCCFA1E178ED40007 + B6AED20A7DCBF097E69389473CF25460 + 5559AC81BEB04601F5AA311721824962 + + isa + PBXGroup + name + lua + path + lua + sourceTree + <group> + + 608C5F501EBE6402D33CFF280E41BDED + + children + + 0337A51DB5994C8994C2A8DA56DC7F48 + 0E0EDB175E8DDD8757716C987E6345F1 + + isa + PBXGroup + name + RSA + path + RSA + sourceTree + <group> + + 60A3E7ED03589290861C1454F4339DD0 + + includeInIndex + 1 + isa + PBXFileReference + path + ltablib.c + sourceTree + <group> + + 60B5CB22A100B61F7E0975960E45EEC1 + + fileRef + 573ADC3C891FBA670A36BD45C3D7C6D2 + isa + PBXBuildFile + + 6107113B45C44620700E66AA61893EFD + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + NSBundle+MJRefresh.h + path + MJRefresh/NSBundle+MJRefresh.h + sourceTree + <group> + + 61F09CD705317B289FA824E3684A04FC + + fileRef + 7D46154A7C1EEFA233E5869A4BBA6CB7 + isa + PBXBuildFile + + 627EACDA0FDDF7E65439BD3957806484 + + fileRef + E7C38BF8D49BFCC3A3D3D2891917452F + isa + PBXBuildFile + + 6290A1FDB0302CF140ED162AE9E23A9D + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVSystem.h + sourceTree + <group> + + 62D36155060BA026F558EE6D085AB788 + + containerPortal + D41D8CD98F00B204E9800998ECF8427E + isa + PBXContainerItemProxy + proxyType + 1 + remoteGlobalIDString + 86C582DB039C2092AB70FE04FD45E436 + remoteInfo + SDWebImage + + 636D8806E3D4B9E2603676555687DD38 + + fileRef + 9E56A950A523AF42E0BE2DA712B49B59 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 63C62608781B69EF4AA9A1C482AF0ABA + + fileRef + BC324585A8C218375DA84B28852462AA + isa + PBXBuildFile + + 648F0330C94DC6589C158523099F6158 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + SDWebImagePrefetcher.m + path + SDWebImage/SDWebImagePrefetcher.m + sourceTree + <group> + + 64A25D16FDEC9C77614F766628348ECA + + fileRef + AC0BC35EC99B1DC651D9B96EA5A7F906 + isa + PBXBuildFile + + 64ACB0FBB5D56CCADEFE5D63086EFD88 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + MJRefreshNormalHeader.h + path + MJRefresh/Custom/Header/MJRefreshNormalHeader.h + sourceTree + <group> + + 64F6D21A4BF0BC37F6B44EA6DF283427 + + fileRef + 5F7910408326053D74B3A4AEDE4BA336 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 6510C2DD0BAE8A26B02DC7EF9019779F + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + text + path + Pods-Demo-acknowledgements.markdown + sourceTree + <group> + + 65A2C298D65EFC5B359821B8872CB809 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + MJRefreshComponent.m + path + MJRefresh/Base/MJRefreshComponent.m + sourceTree + <group> + + 660EF3BC8F89F4322E806B097DBD0339 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + SDWebImageDownloader.m + path + SDWebImage/SDWebImageDownloader.m + sourceTree + <group> + + 66A861F86546D0E3FB551371DB022B3F + + fileRef + 25F8ABDD1532A296D8F95098E2E0A972 + isa + PBXBuildFile + + 66CDF57C0565C682D5F756E4656745DF + + fileRef + 41254C3A0D0DC1E1AF3F89F410551EAB + isa + PBXBuildFile + settings + + COMPILER_FLAGS + -DOS_OBJECT_USE_OBJC=0 + + + 66D5DAD27199B721A3E8AD84DA1603F1 + + fileRef + E4A93CB04BA6834644426E250C1D2439 + isa + PBXBuildFile + + 66EA1CE472726D534DCF74F4F71A74B7 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + lstate.h + sourceTree + <group> + + 67A54FF33AEDA7F8E07C700BCA80109F + + fileRef + 76A62C4FE04E529148E38E1EA271B193 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 67B191A8E2B9C2FB3ED480CECF48B49D + + fileRef + EF4D170AC70386955DA726196014FE48 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 67D181C705D1DD2E17973635456580E7 + + children + + 903DDA772361FC9B6A7D70DDB870ECFE + 6510C2DD0BAE8A26B02DC7EF9019779F + 40C0BE58FF476ABB4150234A1F243BE8 + 70665FCF0DE698CEA01ED3BF3313739F + 111420667E7F2A177D6D703D47E67556 + 4C79F51DCA2597370D2EF0D5085BC662 + CDFAD82872C4A9CA55B64E1A7A350B9D + 9EF5814F71502908E43FAE2674061C95 + + isa + PBXGroup + name + Pods-Demo + path + Target Support Files/Pods-Demo + sourceTree + <group> + + 68A8B216570A7B3871B5BA19DB93950B + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + ltm.h + sourceTree + <group> + + 6927E60D52BD2AAB3B1037D376F4B96E + + fileRef + FC2A5EA8CF19876ACA547F5571BE8E47 + isa + PBXBuildFile + + 69613788FAA3F6DBE5B5A988DF47D9EA + + fileRef + 0069C69D4E50900D4B6DB88721929F18 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 697F132F2DFCA6F7BD385E8B69106518 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVPointerValueBox.h + sourceTree + <group> + + 69996EEA1EF53A0BE18F7F2C29EB18B8 + + children + + FDAE87F570F4B6B60ACA1DFC69C5336D + + isa + PBXGroup + name + LuaViewSDK + path + LuaViewSDK + sourceTree + <group> + + 69A3904202D1A7F11DCE525D3F3B38C3 + + fileRef + 8915253C09B57480829F50053606D981 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 6A13D12EEC9DC6DEDCBA4329471CAF1C + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + NSObject+LuaView.h + sourceTree + <group> + + 6A40240141D724C5010327A97127565C + + fileRef + EC96CF865FD43B9874A7B151951B95EF + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 6A6DD776E4FC2CA9F48E27224C462079 + + fileRef + A5E8C236BD13650324DEE1616B8D0467 + isa + PBXBuildFile + + 6ADB003D91876455C480FC897DAEFC0C + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVExButton.m + sourceTree + <group> + + 6ADC425DC7BFD5CF703F10B85943A730 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + lcode.h + sourceTree + <group> + + 6B73EC8D9BB6A4B6CB933EB8447291DC + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVClassInfo.m + sourceTree + <group> + + 6B835B3B0A891FFF7F8C057FB52E6651 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVBundle.m + sourceTree + <group> + + 6C15D01D64AB135BFB9D9878FB67C6BB + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + UIView+MJExtension.m + path + MJRefresh/UIView+MJExtension.m + sourceTree + <group> + + 6CE8BA1CC153472DEA5348F243B6C213 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVCanvas.m + sourceTree + <group> + + 6D8F7AC3418604B39588E40806799991 + + explicitFileType + archive.ar + includeInIndex + 0 + isa + PBXFileReference + name + libluaviewEx.a + path + libluaviewEx.a + sourceTree + BUILT_PRODUCTS_DIR + + 6DA0850995A2DD2970A196D5D73D3F6D + + fileRef + 4D39C512556D7FCD68C18D059F7F71CE + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 6E2FC36EE1B8888738631373AFC9C725 + + containerPortal + D41D8CD98F00B204E9800998ECF8427E + isa + PBXContainerItemProxy + proxyType + 1 + remoteGlobalIDString + 86C582DB039C2092AB70FE04FD45E436 + remoteInfo + SDWebImage + + 6E9F50EA7AF8CAC8A44A18346E92060C + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + MJRefreshGifHeader.h + path + MJRefresh/Custom/Header/MJRefreshGifHeader.h + sourceTree + <group> + + 6EB625D3C0904EA032BD4FF18F08F504 + + includeInIndex + 1 + isa + PBXFileReference + path + lua.c + sourceTree + <group> + + 6F95E177A7FEF401098084AAB78D975F + + fileRef + 64ACB0FBB5D56CCADEFE5D63086EFD88 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 704624A404920F906F8C4758158BFFE9 + + fileRef + 2E54C4285C2C276EAC1EBAC04C14F68F + isa + PBXBuildFile + + 705A081A86B0567189C003FE14CE5AF8 + + fileRef + 41F2BFDCB233A10CA0F9FAE16D9FDBA1 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 705FEA1290E1E307F7E501305528AC9F + + fileRef + 348B1AF87760A3CCE93BA87530F10E04 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 70665FCF0DE698CEA01ED3BF3313739F + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + Pods-Demo-dummy.m + sourceTree + <group> + + 7126E933CA554994994B6B3C3DB740E1 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVTimer.m + sourceTree + <group> + + 71A27EA5520E60D7261D034013A0B58C + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVNetworkStatus.m + sourceTree + <group> + + 73B52856D8CFBE4DDFA2B42F2BE01351 + + fileRef + 49594237A643B228FF63841F615C833C + isa + PBXBuildFile + + 73D0302E0FE7DA259C8715A87FF93171 + + fileRef + F91B57533C10FED7ACC1CAFEC2A2988C + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 741C079B7C1BC49D17B301E512906A4B + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + MJRefreshNormalHeader.m + path + MJRefresh/Custom/Header/MJRefreshNormalHeader.m + sourceTree + <group> + + 7474B8DDEE60A53040790F23FC92F3E0 + + children + + 0209E35EBB89158BE1EEE63A003EFA02 + C0C1E2A64507633B73DE3820676BB30D + 3A59FA484998DB5F7E476DDAF37CB5A4 + 5FE8AC69826BCB6A0364DEB2554AF819 + EEC731BC28352575CDF493AE5FB08AE5 + 9B4D175520321FCF1AA45EE33A27A2D0 + + isa + PBXGroup + name + PKG + path + PKG + sourceTree + <group> + + 74B430389E22FD25ECF9232BAA88F7D3 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + JUFLXNode.m + sourceTree + <group> + + 755324115C8D1BCE7BF14D9717EF2465 + + fileRef + 93F16614598E109BF6A8B1FA41F055A9 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 757F22D31DBD66F4958B653301D41523 + + fileRef + ADF4B57B40B0DDEE9FA7B619894FA0F7 + isa + PBXBuildFile + + 761D9DCB4D1F974E59EB97C6EA9310B7 + + buildActionMask + 2147483647 + files + + 0A363F72760068456ED56A18B3F3316F + + isa + PBXSourcesBuildPhase + runOnlyForDeploymentPostprocessing + 0 + + 763770F29895252BF40B99CD5D4EA4A5 + + fileRef + A32240776FAF42C343B7A838642234E8 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 76A62C4FE04E529148E38E1EA271B193 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVCustomPanel.h + sourceTree + <group> + + 76C98BE4E806F9CD8011621FCE9E2978 + + children + + FE97AE03D7376502147B56A323F0D285 + 4E7F57362B7F28AC3C5046B88802795D + + isa + PBXGroup + name + luaviewEx + path + luaviewEx + sourceTree + <group> + + 772AFA7BF54733867C9EC68BBAFE61F5 + + fileRef + 6B835B3B0A891FFF7F8C057FB52E6651 + isa + PBXBuildFile + + 773E6539C49AB6B66E95636A85B80F70 + + fileRef + 25F9EE94AE7AF0C4ED35B883A17FEE6D + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 78482F44635EAEE1E97518CA8E012BD9 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVAlert.m + sourceTree + <group> + + 785612BB1A58824B613A2F943FFC272C + + fileRef + 2AB0F59C7F97CC7B8D41743BF7D4A0E3 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 78567B2D2C3DB8D0A00936D224FD02FA + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + MJRefreshHeader.m + path + MJRefresh/Base/MJRefreshHeader.m + sourceTree + <group> + + 7862B0EECC1DAFDEAD730E8B9BEA62B2 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVDB.h + sourceTree + <group> + + 7898632516013BE019048DFEA6E3E811 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVPagerIndicator.m + sourceTree + <group> + + 79084E68181498DC2C09BB7E681B2C51 + + baseConfigurationReference + 5F0ED6343850C31C0C0AD29F9E68B2BD + buildSettings + + ENABLE_STRICT_OBJC_MSGSEND + YES + GCC_PREFIX_HEADER + Target Support Files/SDWebImage/SDWebImage-prefix.pch + IPHONEOS_DEPLOYMENT_TARGET + 8.0 + MTL_ENABLE_DEBUG_INFO + YES + OTHER_LDFLAGS + + OTHER_LIBTOOLFLAGS + + PRIVATE_HEADERS_FOLDER_PATH + + PRODUCT_NAME + $(TARGET_NAME) + PUBLIC_HEADERS_FOLDER_PATH + + SDKROOT + iphoneos + SKIP_INSTALL + YES + + isa + XCBuildConfiguration + name + Debug + + 797A41941830FE4580315B8F781707DC + + fileRef + 5D6D43DC320B0EEA77FCBB71A0767141 + isa + PBXBuildFile + settings + + COMPILER_FLAGS + -DOS_OBJECT_USE_OBJC=0 + + + 798A49D9F93FD554BF5F9B552EB94CE2 + + children + + 67D181C705D1DD2E17973635456580E7 + + isa + PBXGroup + name + Targets Support Files + sourceTree + <group> + + 79A6F7AFCA22BC1ECB24C87CB7BB7BF8 + + fileRef + D21DBF15312A3EDAC3D56BBEC5E6E0AB + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 7A64DB3261E77E3E16ECE8CEC90065A1 + + fileRef + 87A0C6CC09D42598458459294742E11F + isa + PBXBuildFile + + 7A6529CB909734DAD2EBA40AEA09612A + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVCustomView.m + sourceTree + <group> + + 7A6841D14A4341D1CF5364B24F6236B0 + + fileRef + 591836F8255DF1C90A855CAF49D5BA0D + isa + PBXBuildFile + + 7A897E10D01BE231C45DDBD18901136D + + fileRef + 8539600F54252E5FBC866DCA02EF1759 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 7B34C97DBA61C215A4B0343673F59865 + + fileRef + BF9EE48CC6AA0659A6AA22FE3879A369 + isa + PBXBuildFile + settings + + COMPILER_FLAGS + -DOS_OBJECT_USE_OBJC=0 + + + 7B51E6C8E8C50AE87094DCC0450B5384 + + fileRef + 25F8ABDD1532A296D8F95098E2E0A972 + isa + PBXBuildFile + + 7B8A6BAF1B8BA02E0423F4F7CDC150E8 + + children + + BEDC26C028197B219DD378338825ECBE + 33C0035DE5EA0FA943B3EB0B2F06D333 + + isa + PBXGroup + name + LuaViewSDK + path + ../../.. + sourceTree + <group> + + 7BB607681B5BECC1D593ACCEFCAE3E2E + + fileRef + 88A0C1BA6D68C3D29D4E157FDAEAE4ED + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 7C6DA1A9E2A1C3813C9B70ED5D1C04C5 + + fileRef + 7126E933CA554994994B6B3C3DB740E1 + isa + PBXBuildFile + + 7D46154A7C1EEFA233E5869A4BBA6CB7 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + MJRefreshGifHeader.m + path + MJRefresh/Custom/Header/MJRefreshGifHeader.m + sourceTree + <group> + + 7D89A5849B6E33E1EAE67D09C73506C7 + + children + + 9A82DB7DD554C9E85AD3EFFA6C542260 + 591836F8255DF1C90A855CAF49D5BA0D + E86E8B315217720BAB0CDC4E78AE3604 + F1024CD9FEB146FF5D4458F5FD0EA873 + B89C6AFE954AA91D49330EC2B411725A + + isa + PBXGroup + name + lvdebug + path + lvdebug + sourceTree + <group> + + 7DB346D0F39D3F0E887471402A8071AB + + children + + BA6428E9F66FD5A23C0A2E06ED26CD2F + 8D7FAA97713CD52F7236EBD175767B61 + 14B8B9B15ECBE87983FF987239AB2D7B + A70C2A383ADA2FCA85B5C36C1F0BE5DD + 2A3D8905FED90C95EF0CA9CD6FD22248 + 798A49D9F93FD554BF5F9B552EB94CE2 + + isa + PBXGroup + sourceTree + <group> + + 7E1FF24F595B689AAF460593A7CFE95E + + fileRef + 0E0EDB175E8DDD8757716C987E6345F1 + isa + PBXBuildFile + + 7E416774B2996337C3D0E99E086F047B + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVAudioPlayer.h + sourceTree + <group> + + 7E4420F5CC78E5ECB3DBD72879FF0A71 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVTypeConvert.m + sourceTree + <group> + + 7EA30A973267891588C3B6E0C6C9C067 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + UIScrollView+LuaView.m + sourceTree + <group> + + 7EFF7E9CC8716B1EADBAA3B34EEE5EAC + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + JUFLXNode.h + sourceTree + <group> + + 80045B5072145A6462B7F17AD6038B57 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LViewController.m + sourceTree + <group> + + 809B17D0F089DEBC55260F1E9A01A8E0 + + includeInIndex + 1 + isa + PBXFileReference + path + lapi.c + sourceTree + <group> + + 80C1446A8DBDD5E5F32E9375DE64A64D + + fileRef + 9364907161F20CB65D50DB69A9A853A3 + isa + PBXBuildFile + + 817B590920DF968A31CEAC1E2F2B93A0 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVHttpResponse.m + sourceTree + <group> + + 81840C2A6ADA09777E9ED7D07AA0409B + + fileRef + 1B04371E67EC2B2015B108FD848BCFC7 + isa + PBXBuildFile + + 8276641C1150A8C82B9FDA758C0584B8 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + UIImageView+HighlightedWebCache.m + path + SDWebImage/UIImageView+HighlightedWebCache.m + sourceTree + <group> + + 8304D148F5CA1DEEF71F60C222E9758D + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + lobject.h + sourceTree + <group> + + 8306329169090362CB141FBA8435F64D + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVExCollectionView.h + sourceTree + <group> + + 838F7D9ED6147CD048D86BC072B9D41E + + explicitFileType + archive.ar + includeInIndex + 0 + isa + PBXFileReference + name + libSDWebImage.a + path + libSDWebImage.a + sourceTree + BUILT_PRODUCTS_DIR + + 83BC99394E5FFEB037B2A63457D47A30 + + fileRef + CEC1FDAA6941E91F05D82D71B4694840 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 841597C166F12A9F4C5512610BF8C598 + + fileRef + A298FC7F1076DE7D251D916D727A9907 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 8423C840B31734512F55FE12F7DEA797 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVScrollViewDelegate.m + sourceTree + <group> + + 8469CAC241069ACC421B17248ED1C118 + + fileRef + 25F8ABDD1532A296D8F95098E2E0A972 + isa + PBXBuildFile + + 84B176DBB2DD9964E0A03317269AD603 + + fileRef + 9B214ED7CC89E2A54E2C502E7AB8DB5B + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 84C83C0F6A9BAA96E6FF199DFE0A5F25 + + fileRef + F93D1A7E5BF9BE65D2C6925F102D15FE + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 8539600F54252E5FBC866DCA02EF1759 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + MJRefreshFooter.h + path + MJRefresh/Base/MJRefreshFooter.h + sourceTree + <group> + + 85493EC5AE88F0BB63531F4CBAE4B820 + + fileRef + 3AC8A9CDF659CBBCA1320C8046434793 + isa + PBXBuildFile + + 8605A604B36138B640EE777D884D8EB6 + + fileRef + C387C869345121E7D5349E78BD30A054 + isa + PBXBuildFile + + 86C582DB039C2092AB70FE04FD45E436 + + buildConfigurationList + D50A811A8469B70B0D951EEC2800878A + buildPhases + + C240F3087E66DD2E4943EA83FB00B54E + DD828C74E015AC80F828E2E30ED6B2BA + 0B35943C35122E6E109566190302ACE7 + + buildRules + + dependencies + + isa + PBXNativeTarget + name + SDWebImage + productName + SDWebImage + productReference + 838F7D9ED6147CD048D86BC072B9D41E + productType + com.apple.product-type.library.static + + 870EC3CFAD191AF3B628C14C7EBA9C69 + + includeInIndex + 1 + isa + PBXFileReference + path + lobject.c + sourceTree + <group> + + 87A0C6CC09D42598458459294742E11F + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + MJRefreshBackStateFooter.m + path + MJRefresh/Custom/Footer/Back/MJRefreshBackStateFooter.m + sourceTree + <group> + + 87CCB0F1730772D937C6A00574181DEF + + fileRef + 0534ACA88092EB85C6F1DE09FB52C1E4 + isa + PBXBuildFile + + 88A0C1BA6D68C3D29D4E157FDAEAE4ED + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + UIView+LuaView.h + sourceTree + <group> + + 88C0AC96CA31ADC0432FCA03474C0C9D + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVRefreshHeader.m + sourceTree + <group> + + 88D556157C0CA6FF501F0527A9048898 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LView.m + sourceTree + <group> + + 8915253C09B57480829F50053606D981 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVLoadingIndicator.h + sourceTree + <group> + + 892E625B3B2F6778E3C3AE8073A7405D + + fileRef + 71A27EA5520E60D7261D034013A0B58C + isa + PBXBuildFile + + 897DBCA022EEA6EEEE3413D5C335650E + + buildConfigurationList + E19B46575CE394CE24851C0D1679D623 + buildPhases + + FC0A35AACB219A49FA8BB55CBC659A79 + FFB85E30A4362FCC270FFBAC5A8B82D4 + 028E09B81C239295EB2B3008FFBFA151 + + buildRules + + dependencies + + AD7254CA2663FC5BBF53C1B8DD6E8EE4 + 2ADE7B74B2C418956E5FFE77F789DF61 + 3B4D54EC5356558BBEBDEA71AFC367AA + 35CE884E04E758BA7E2AFE50093EF18E + + isa + PBXNativeTarget + name + luaviewEx + productName + luaviewEx + productReference + 6D8F7AC3418604B39588E40806799991 + productType + com.apple.product-type.library.static + + 89B3AE3519D907C0220AC85B9CDA2192 + + fileRef + B6C43969278258FEFF529D78CFF31785 + isa + PBXBuildFile + + 8A0EE704985B3194C4A04E72E46D7F31 + + fileRef + 5DF600C7B7E6DE889926E0C8E2D896D3 + isa + PBXBuildFile + + 8A1AA383C04F4B4FE460C97AFF881E03 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVHttp.h + sourceTree + <group> + + 8A1F06898602CDD0A78A85D83BB242CA + + includeInIndex + 1 + isa + PBXFileReference + path + util.lua + sourceTree + <group> + + 8A2D6614ED52A191768AD7E21CC02782 + + buildActionMask + 2147483647 + files + + 66A861F86546D0E3FB551371DB022B3F + + isa + PBXFrameworksBuildPhase + runOnlyForDeploymentPostprocessing + 0 + + 8B20892071442D8FE3585F90D53D7A78 + + fileRef + C48CF6A9E431034B4E8959A3CC050148 + isa + PBXBuildFile + + 8B24DA0221402891873036ABDB05ED11 + + fileRef + 42E242563E7B39DE4D2A3CEBDD3791B3 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 8BC52B162491217C2CD341A1527491E3 + + fileRef + D40EBA7C2A2635C8D497951B5BFAF12B + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 8C08311EA0B714A95E8F50FC157229C5 + + includeInIndex + 1 + isa + PBXFileReference + path + lauxlib.c + sourceTree + <group> + + 8C6F15529DF4D308EC80AB9BAA189B1E + + fileRef + E58175612E1B5AA5F33833093611F375 + isa + PBXBuildFile + + 8C7BEE87A14BA5D0F76EA64D084F1A4E + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + MJRefreshAutoStateFooter.m + path + MJRefresh/Custom/Footer/Auto/MJRefreshAutoStateFooter.m + sourceTree + <group> + + 8C7DF7454C0B572A71EEE807BD65870E + + fileRef + F78FBB2B2E733FFB239613964835C963 + isa + PBXBuildFile + + 8D04B6E284341540BD82079EC270F698 + + baseConfigurationReference + 9F92270DCACF8D923B9153BBF8998633 + buildSettings + + ENABLE_STRICT_OBJC_MSGSEND + YES + GCC_PREFIX_HEADER + Target Support Files/LuaViewSDK/LuaViewSDK-prefix.pch + IPHONEOS_DEPLOYMENT_TARGET + 8.0 + MTL_ENABLE_DEBUG_INFO + YES + OTHER_LDFLAGS + + OTHER_LIBTOOLFLAGS + + PRIVATE_HEADERS_FOLDER_PATH + + PRODUCT_NAME + $(TARGET_NAME) + PUBLIC_HEADERS_FOLDER_PATH + + SDKROOT + iphoneos + SKIP_INSTALL + YES + + isa + XCBuildConfiguration + name + Debug + + 8D7FAA97713CD52F7236EBD175767B61 + + children + + CF0B06D68FFC2B969822825FF8293704 + 7B8A6BAF1B8BA02E0423F4F7CDC150E8 + + isa + PBXGroup + name + Development Pods + sourceTree + <group> + + 8DC7D7B476F660C2250067B1F74E47D6 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVData.h + sourceTree + <group> + + 8DE12BB40B340FFE3AD7F6CB858312C3 + + buildConfigurations + + 10FFFE940EB64D3925A0C3C367BEBD61 + 4590F66CFBBF00A2335C58E7D0EFA120 + + defaultConfigurationIsVisible + 0 + defaultConfigurationName + Release + isa + XCConfigurationList + + 8E666DE133DB689B0080C832470E745C + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + SDWebImage-dummy.m + sourceTree + <group> + + 8EDC8988CFFFA84502F524392D3FA01D + + fileRef + A87FBF59E1E0B08C03B937D02B2143FE + isa + PBXBuildFile + + 8F748F91D55DA1BD22C64EF7C9C825FF + + fileRef + 09812FC481F673CDE2428CAC41614458 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 8FE053ED8A9ED5BCE33A332F54721527 + + fileRef + BAA5D3F826C7C5CFB67B35038B590421 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 903DDA772361FC9B6A7D70DDB870ECFE + + includeInIndex + 1 + isa + PBXFileReference + path + copy-framework-resources.rb + sourceTree + <group> + + 9048B80C486492717FFE3CFA18B3E016 + + baseConfigurationReference + A24C870F09AD5EB0FD238F5985B6A0EF + buildSettings + + ENABLE_STRICT_OBJC_MSGSEND + YES + PRODUCT_NAME + luaviewEx + SDKROOT + iphoneos + SKIP_INSTALL + YES + WRAPPER_EXTENSION + bundle + + isa + XCBuildConfiguration + name + Release + + 9072EDACE27EC0FA2A19863A0A8550F9 + + baseConfigurationReference + 5F0ED6343850C31C0C0AD29F9E68B2BD + buildSettings + + ENABLE_STRICT_OBJC_MSGSEND + YES + GCC_PREFIX_HEADER + Target Support Files/SDWebImage/SDWebImage-prefix.pch + IPHONEOS_DEPLOYMENT_TARGET + 8.0 + MTL_ENABLE_DEBUG_INFO + NO + OTHER_LDFLAGS + + OTHER_LIBTOOLFLAGS + + PRIVATE_HEADERS_FOLDER_PATH + + PRODUCT_NAME + $(TARGET_NAME) + PUBLIC_HEADERS_FOLDER_PATH + + SDKROOT + iphoneos + SKIP_INSTALL + YES + + isa + XCBuildConfiguration + name + Release + + 907739E0BFCC67F1A0134909CD0062BE + + includeInIndex + 1 + isa + PBXFileReference + path + lmathlib.c + sourceTree + <group> + + 90F61C1B0444F77E612DB67FD3FA5212 + + buildConfigurations + + 3D441A790368BA67192D448BB061ECAD + 9048B80C486492717FFE3CFA18B3E016 + + defaultConfigurationIsVisible + 0 + defaultConfigurationName + Release + isa + XCConfigurationList + + 91278AA6890375CEF7CABA2872B8B4CC + + fileRef + 9FFB35B3F018590030459C786B08B2F3 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 91B94BB95CC9FEBF50D47DFFC5FFCD88 + + fileRef + 396C87EE0AA4B806979FB5BF72B590FD + isa + PBXBuildFile + + 91F505936CB16A1F2B556231E2252545 + + fileRef + 306D7A60B8274399E237C738DBE566F9 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 924A92CE6BA9A55477BC6540C3181B60 + + fileRef + 6290A1FDB0302CF140ED162AE9E23A9D + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 92C9C24626EAC668B0901B98F6C49CB7 + + fileRef + 8C08311EA0B714A95E8F50FC157229C5 + isa + PBXBuildFile + + 9326E21C6FAE1344EC08B49E9C11A246 + + fileRef + 2ACE817433802BA8E77DDB9B9EDC7AAE + isa + PBXBuildFile + + 9364907161F20CB65D50DB69A9A853A3 + + includeInIndex + 1 + isa + PBXFileReference + path + lundump.c + sourceTree + <group> + + 93B70581D4C9B003008D4A0BA7A2232F + + fileRef + EE59907F54D7D76447835CACEC77F65A + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 93F16614598E109BF6A8B1FA41F055A9 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVDate.h + sourceTree + <group> + + 93F57328890CBD41C124EB0AF10B1F4F + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + UIImage+MultiFormat.m + path + SDWebImage/UIImage+MultiFormat.m + sourceTree + <group> + + 943F714F95D8A897CF199DB41767EEE2 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVPinchGesture.h + sourceTree + <group> + + 9452384A062A9CDEAD4042834DB6702A + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVRefreshHeader.h + sourceTree + <group> + + 9562CC1BD4511D4CD98785D3EA3D6249 + + fileRef + 00488347FBD3CC25591CEB62F96C8289 + isa + PBXBuildFile + + 956C5BE492C35A2116CA2CECD7795085 + + buildConfigurationList + A5CBA93722079504FF7D26FD30E2E5D1 + buildPhases + + D00FE05DACB72541D4D58EF762E3FAD0 + 178A8E6D0EA5FAEA241FC56358B39A5B + E8A5AFBEE221C159CA81030D4A658EED + + buildRules + + dependencies + + isa + PBXNativeTarget + name + LuaViewSDK + productName + LuaViewSDK + productReference + 1B58180185A80744B543A9B346759BCF + productType + com.apple.product-type.library.static + + 959652CBAB972B8AEBFBB392031F0212 + + fileRef + 97FED081F595C4AC2A873EFD0086F796 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 95F01F40BB3572F283688C42746B1A50 + + fileRef + 3E9A0367C6AA92183B76C3BAA7F2E63E + isa + PBXBuildFile + + 9608D459B61D89D22939B2FF2C1392BC + + fileRef + 9C43DE662F6C895DA12CCA6C85D6EA34 + isa + PBXBuildFile + + 96286368DBD96F09E58156FE69D442F9 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + UIScrollView+MJRefresh.h + path + MJRefresh/UIScrollView+MJRefresh.h + sourceTree + <group> + + 963A6B7FD891AD92EE8609736ACBBB0D + + fileRef + 413A1B350BC4E2840EC6B7F768834B25 + isa + PBXBuildFile + + 964A184485B106E9E613FC1D1EA58FD8 + + fileRef + 741C079B7C1BC49D17B301E512906A4B + isa + PBXBuildFile + + 9699AEE717090D3F6BB2E069B1D3F202 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + MJRefreshAutoFooter.m + path + MJRefresh/Base/MJRefreshAutoFooter.m + sourceTree + <group> + + 97F26F4F58443DE9CE75A5FF98F14A31 + + fileRef + B1508D43CB6FB14F78655D6F6E1F60CF + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 97FED081F595C4AC2A873EFD0086F796 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + JUFLXLayoutKit.h + sourceTree + <group> + + 989164B527C231435B4F8BC45518577F + + fileRef + 943F714F95D8A897CF199DB41767EEE2 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 98AB6A2344ACE639419CF3B33DD07B23 + + fileRef + A5F3A21C1DFA894F14F556DFC2BAACC7 + isa + PBXBuildFile + + 991139F569CC64E620BC0344F5DABCF0 + + fileRef + CB3CFF857464FA2F76B12B45B1374DB0 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 995D146BEAFF10317A1D6C6541B8069B + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVTimer.h + sourceTree + <group> + + 99D89F8FFCEA14AD0D7535F9B158DB76 + + fileRef + 7862B0EECC1DAFDEAD730E8B9BEA62B2 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 9A82DB7DD554C9E85AD3EFFA6C542260 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVDebugConnection.h + sourceTree + <group> + + 9AC35F1DE54EB28C844CAC19E05D5095 + + buildConfigurationList + 8DE12BB40B340FFE3AD7F6CB858312C3 + buildPhases + + E67F9C9362C51A3AFA082A39691BF49B + 8A2D6614ED52A191768AD7E21CC02782 + DF733814C807457EF90B1729E10A3090 + + buildRules + + dependencies + + isa + PBXNativeTarget + name + MJRefresh + productName + MJRefresh + productReference + 1B269A79B1296BAA0AD98E2F8512F4AF + productType + com.apple.product-type.library.static + + 9B214ED7CC89E2A54E2C502E7AB8DB5B + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVHeads.h + sourceTree + <group> + + 9B459902DEE511B48255C3D87497FA12 + + fileRef + 4CD886EF1C0728613450008CCC22F07A + isa + PBXBuildFile + + 9B4D175520321FCF1AA45EE33A27A2D0 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVZipArchive.m + sourceTree + <group> + + 9B67196018324E9026D33B89AC1AC21A + + fileRef + 6B73EC8D9BB6A4B6CB933EB8447291DC + isa + PBXBuildFile + + 9C235D35E1ED95A35F2F8574CD762385 + + fileRef + B61E38BFD4DB638553ABD75F0451216D + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 9C43DE662F6C895DA12CCA6C85D6EA34 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVExGlobalFunc.m + sourceTree + <group> + + 9CB0C123A2A3203CA0BAB6D681EF87EC + + fileRef + 7E416774B2996337C3D0E99E086F047B + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 9DCEEBE0F83EA19FF82D54789139BD73 + + fileRef + 5469984FA164FC0AACE23B19A4BE44C1 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 9DE2FE925C195BEFFE225277AA043A13 + + fileRef + F5D648D9050C305B35AD0620836F415A + isa + PBXBuildFile + + 9E56A950A523AF42E0BE2DA712B49B59 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + MJRefreshAutoGifFooter.h + path + MJRefresh/Custom/Footer/Auto/MJRefreshAutoGifFooter.h + sourceTree + <group> + + 9EF5814F71502908E43FAE2674061C95 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + text.xcconfig + path + Pods-Demo.release.xcconfig + sourceTree + <group> + + 9F1EDE358215935E8A9E0C0F9071DDE4 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVButton.m + sourceTree + <group> + + 9F42EEFBB24C46A65C809847F700CF00 + + fileRef + 817B590920DF968A31CEAC1E2F2B93A0 + isa + PBXBuildFile + + 9F57030CDD579F1DBC6E7C388F349C53 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + SDWebImageDecoder.m + path + SDWebImage/SDWebImageDecoder.m + sourceTree + <group> + + 9F92270DCACF8D923B9153BBF8998633 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + text.xcconfig + path + LuaViewSDK.xcconfig + sourceTree + <group> + + 9FFB35B3F018590030459C786B08B2F3 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + MJRefreshBackGifFooter.h + path + MJRefresh/Custom/Footer/Back/MJRefreshBackGifFooter.h + sourceTree + <group> + + A0DECF9E223A7F117B5E3BBC24715C31 + + fileRef + 23FBFC7BA4421F1EA9D8A9B6ED868E43 + isa + PBXBuildFile + + A19E9359717732DB16195FEC28054C2F + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + MJRefresh-dummy.m + sourceTree + <group> + + A24C870F09AD5EB0FD238F5985B6A0EF + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + text.xcconfig + path + luaviewEx.xcconfig + sourceTree + <group> + + A298FC7F1076DE7D251D916D727A9907 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVCustomView.h + sourceTree + <group> + + A2BA69A9B7C5EECB89993DED249AF06E + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + MJRefreshBackNormalFooter.m + path + MJRefresh/Custom/Footer/Back/MJRefreshBackNormalFooter.m + sourceTree + <group> + + A31553C0508D4AA224F19034560566E5 + + fileRef + D2F983E998B021AB8223EC8BC9E70211 + isa + PBXBuildFile + + A32240776FAF42C343B7A838642234E8 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVExButton.h + sourceTree + <group> + + A330621447BE705174FA9138F96957BA + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + MJRefreshBackFooter.m + path + MJRefresh/Base/MJRefreshBackFooter.m + sourceTree + <group> + + A37F23A7A0EE7BCC163D74266A85804D + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + luaconf.h + sourceTree + <group> + + A40A5BB0C59CB3172B6F36D930EEDD07 + + fileRef + B29CF767D9C91558C51533ACD62C6953 + isa + PBXBuildFile + + A44CE95CF7D39500BD4B40F72A622EF7 + + fileRef + 5FDC9110C37E3DAB16FAC25BA44AB29A + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + A544A8CB3168DE44318B021F0C4274D4 + + children + + 2D26AAA839209BDEB393111BD6B5AA9A + A32240776FAF42C343B7A838642234E8 + 6ADB003D91876455C480FC897DAEFC0C + 8306329169090362CB141FBA8435F64D + 1A38EE516FF7ACB089D5DF171C1C500B + 3CA4506700C9BDB658F10D7F789983C3 + C387C869345121E7D5349E78BD30A054 + 3F1D737696EBBC729E68A3C60EAF2F93 + 1EFA9AF0945D053F5211C3347AE83BEE + + isa + PBXGroup + name + Classes + path + Classes + sourceTree + <group> + + A5CBA93722079504FF7D26FD30E2E5D1 + + buildConfigurations + + 8D04B6E284341540BD82079EC270F698 + 00DB86496A3A3D9FAF2E919F9EBBEAE1 + + defaultConfigurationIsVisible + 0 + defaultConfigurationName + Release + isa + XCConfigurationList + + A5DC432335E5E6FFEE3B570AF7E1FBDA + + fileRef + 29F78858354DBAB936125BF9ABA2E6C5 + isa + PBXBuildFile + + A5E8C236BD13650324DEE1616B8D0467 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVStyledString.m + sourceTree + <group> + + A5F2658443C295DAC623887414762FAD + + fileRef + 0281BDDA769AFF211481D7738496989D + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + A5F3A21C1DFA894F14F556DFC2BAACC7 + + includeInIndex + 1 + isa + PBXFileReference + path + lgc.c + sourceTree + <group> + + A600AD735D6B2205314D42333E17E522 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + UIView+WebCacheOperation.h + path + SDWebImage/UIView+WebCacheOperation.h + sourceTree + <group> + + A6E6436AD216A57AAEEA891EA1E68406 + + fileRef + 185F2A7CBB42DFA6F9D171BF6661B089 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + A70C2A383ADA2FCA85B5C36C1F0BE5DD + + children + + 45AD08573C692305302552D469CB2BD7 + F4235B80C987036C9FC3997D6B861D2B + + isa + PBXGroup + name + Pods + sourceTree + <group> + + A70CDAD61F90AC503C7D04CC22DA2923 + + buildSettings + + ALWAYS_SEARCH_USER_PATHS + NO + CLANG_CXX_LANGUAGE_STANDARD + gnu++0x + CLANG_CXX_LIBRARY + libc++ + CLANG_ENABLE_MODULES + YES + CLANG_ENABLE_OBJC_ARC + YES + CLANG_WARN_BOOL_CONVERSION + YES + CLANG_WARN_CONSTANT_CONVERSION + YES + CLANG_WARN_DIRECT_OBJC_ISA_USAGE + YES + CLANG_WARN_EMPTY_BODY + YES + CLANG_WARN_ENUM_CONVERSION + YES + CLANG_WARN_INT_CONVERSION + YES + CLANG_WARN_OBJC_ROOT_CLASS + YES + CLANG_WARN_UNREACHABLE_CODE + YES + CLANG_WARN__DUPLICATE_METHOD_MATCH + YES + COPY_PHASE_STRIP + NO + GCC_C_LANGUAGE_STANDARD + gnu99 + GCC_DYNAMIC_NO_PIC + NO + GCC_OPTIMIZATION_LEVEL + 0 + GCC_PREPROCESSOR_DEFINITIONS + + DEBUG=1 + $(inherited) + + GCC_SYMBOLS_PRIVATE_EXTERN + NO + GCC_WARN_64_TO_32_BIT_CONVERSION + YES + GCC_WARN_ABOUT_RETURN_TYPE + YES + GCC_WARN_UNDECLARED_SELECTOR + YES + GCC_WARN_UNINITIALIZED_AUTOS + YES + GCC_WARN_UNUSED_FUNCTION + YES + GCC_WARN_UNUSED_VARIABLE + YES + IPHONEOS_DEPLOYMENT_TARGET + 8.0 + ONLY_ACTIVE_ARCH + YES + STRIP_INSTALLED_PRODUCT + NO + SYMROOT + ${SRCROOT}/../build + + isa + XCBuildConfiguration + name + Debug + + A73D0CAF4E189898D748EC4504970EDB + + fileRef + F73C73AAE60625F8E1C29D731BC37FB4 + isa + PBXBuildFile + + A85775D3BDDC00D28A749AF8A2661162 + + fileRef + 60A3E7ED03589290861C1454F4339DD0 + isa + PBXBuildFile + + A87FBF59E1E0B08C03B937D02B2143FE + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVHttp.m + sourceTree + <group> + + A89371DD012A68160E5CD71FD773B168 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVPointerValueBox.m + sourceTree + <group> + + A8DC7BDC3F3A0C051E525C9C39BC2492 + + fileRef + BEF0D115FB13016A3121AD78BA006B14 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + A922468882C625BF3C3CB2C4BB21AAA5 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + SDWebImage-prefix.pch + sourceTree + <group> + + A9730048C76B9ED53ADA1BEA2A6EE513 + + fileRef + B52EE726CABC6085A18DE6A281F33637 + isa + PBXBuildFile + + A97695856BD999EC1F73090B42D18BD0 + + fileRef + ED61215E10852429E53E300EF5C0AC6B + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + A9957623689AB95440AB1FF44E6389D0 + + fileRef + 8C7BEE87A14BA5D0F76EA64D084F1A4E + isa + PBXBuildFile + + A9D97C57FD5DF50F24F726D7303F54DA + + fileRef + 182B279C4AE343381DC15D1861FA1E1E + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + AA8A044FA216D03FB0A78BE5C4620D1F + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVRefreshComponent.m + sourceTree + <group> + + AAB24CDB6EBA27242F84E52BBD6338AD + + fileRef + F56914674DA0AF1E6AC010FC7113D74C + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + AAC78A77396DCEA383011F3A5D24ADA4 + + fileRef + 8E666DE133DB689B0080C832470E745C + isa + PBXBuildFile + + AB0F7E7DDCB792D2EAFE524823A86230 + + fileRef + C61A5A44452BEA0578A57C50C3AA6489 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + ABE8F315730961AC4B78DFDC632A2318 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVStruct.m + sourceTree + <group> + + ABEB11952370C9E22534E5B57DCF7261 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVNativeObjBox.h + sourceTree + <group> + + AC02134060C86A6645D20B2B8D1DCF73 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVUtil.h + sourceTree + <group> + + AC0BC35EC99B1DC651D9B96EA5A7F906 + + includeInIndex + 1 + isa + PBXFileReference + path + lmem.c + sourceTree + <group> + + AC655C389FF138BBD4966CFEE486EC3B + + fileRef + 5A93B171C1E1EDF75E0EFDF1C2DF28FC + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + AC84A33033DFE29523E204D805A919ED + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVImage.h + sourceTree + <group> + + AD7254CA2663FC5BBF53C1B8DD6E8EE4 + + isa + PBXTargetDependency + name + LuaViewSDK + target + 956C5BE492C35A2116CA2CECD7795085 + targetProxy + ED9FF67B3F29DAEEB47B3914D0B0F1BB + + ADF4B57B40B0DDEE9FA7B619894FA0F7 + + includeInIndex + 1 + isa + PBXFileReference + path + slaxdom.lua + sourceTree + <group> + + AF4CCF4B30DF6F3F9CBF4699C679D58D + + fileRef + C18E08C2A4DA6073DABE1DF3C5656FB3 + isa + PBXBuildFile + settings + + COMPILER_FLAGS + -DOS_OBJECT_USE_OBJC=0 + + + AFE5A06B46DD842B63C93FD1EAD29ABD + + fileRef + F5941C112F5CD9BE394432513C70D6C2 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + B08FCB4B91D87BBB8AA714246AD07930 + + fileRef + 6107113B45C44620700E66AA61893EFD + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + B0ED78A5646556E0A601611DEDFBB8EB + + fileRef + 2A057CEC7805963AEC968D52AF26801B + isa + PBXBuildFile + + B1004751E08F54D9C4EB7E6140087333 + + includeInIndex + 1 + isa + PBXFileReference + path + ltable.c + sourceTree + <group> + + B1508D43CB6FB14F78655D6F6E1F60CF + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVCollectionViewCell.h + sourceTree + <group> + + B1FC96F4A467683AAD8007E38F5DF4A7 + + fileRef + 53740A50BB4D7B5B987229EEB1AA96B0 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + B2697219E243EBAADF5F49FD31C51093 + + children + + 605A00C3A9A581747761FDA0F0E81F6E + + isa + PBXGroup + name + lua + path + lua + sourceTree + <group> + + B29CF767D9C91558C51533ACD62C6953 + + includeInIndex + 1 + isa + PBXFileReference + path + object.lua + sourceTree + <group> + + B313F553BA68B14AD5C5FE10235F6A1A + + fileRef + 47566D1C2F4D37A210642A43E68CEA09 + isa + PBXBuildFile + + B36B94A086AD4C43B97E7F2281266A0C + + fileRef + 96286368DBD96F09E58156FE69D442F9 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + B3BF3085D6CD2EF50CF3431C0FB56296 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVCollectionViewCell.m + sourceTree + <group> + + B3FB2B7E053D86661135FE06C5F87591 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVFile.h + sourceTree + <group> + + B4816AFACB2486F043DF806BE95D1E1A + + fileRef + 1EE74E74E0A41F0D521810824CD32B55 + isa + PBXBuildFile + settings + + COMPILER_FLAGS + -DOS_OBJECT_USE_OBJC=0 + + + B4EBDDE43EC6E13D8A715D0F9A0B759C + + fileRef + CC9C067A4572D72BFAC894C14C3D102C + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + B52EE726CABC6085A18DE6A281F33637 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVAudioPlayer.m + sourceTree + <group> + + B5550F3748103756054ED054554A6778 + + includeInIndex + 1 + isa + PBXFileReference + path + lparser.c + sourceTree + <group> + + B568311845136064B35ABCB47F2FB2C3 + + fileRef + F07F668E46955FC5E926C760A0598B3C + isa + PBXBuildFile + + B5B3CBFE61E48ECF6DAA22322D0901B8 + + fileRef + 7E4420F5CC78E5ECB3DBD72879FF0A71 + isa + PBXBuildFile + + B5E0919F738A590066F0B62223C2713E + + fileRef + 809B17D0F089DEBC55260F1E9A01A8E0 + isa + PBXBuildFile + + B61E38BFD4DB638553ABD75F0451216D + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVRefreshConst.h + sourceTree + <group> + + B657D9F448E6E884EBE3C42D119F4B36 + + fileRef + A19E9359717732DB16195FEC28054C2F + isa + PBXBuildFile + + B6A9EA0DA3FD3F553A9C9B8ACFC1C322 + + fileRef + 4442C696FE39C7A55558985FD0ECD80F + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + B6AED20A7DCBF097E69389473CF25460 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + lzio.h + sourceTree + <group> + + B6C43969278258FEFF529D78CFF31785 + + includeInIndex + 1 + isa + PBXFileReference + path + ldebug.c + sourceTree + <group> + + B81AC49B8BA0BEE07CC8501A6B82A4FC + + fileRef + 27FA2D8906DD4F937A0A9C1BF0216041 + isa + PBXBuildFile + + B852107F161F577E28111713B96DBA8F + + fileRef + E5EED4DD19A8E92777CFC22FF262A0CA + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + B89C6AFE954AA91D49330EC2B411725A + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVDebugLua.m + sourceTree + <group> + + B9672F2F82401F219FEC3719092D0BC3 + + fileRef + 46DBBC6251901BECBCD8E7091E8191A9 + isa + PBXBuildFile + + BA2B9DBFEE98A1F5274FE50EA63D7B9B + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVBaseView.h + sourceTree + <group> + + BA6428E9F66FD5A23C0A2E06ED26CD2F + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + text + name + Podfile + path + ../Podfile + sourceTree + SOURCE_ROOT + xcLanguageSpecificationIdentifier + xcode.lang.ruby + + BAA5D3F826C7C5CFB67B35038B590421 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVNetworkStatus.h + sourceTree + <group> + + BB1C328D536B8ADFD30FCA9B434578DD + + containerPortal + D41D8CD98F00B204E9800998ECF8427E + isa + PBXContainerItemProxy + proxyType + 1 + remoteGlobalIDString + 9AC35F1DE54EB28C844CAC19E05D5095 + remoteInfo + MJRefresh + + BBFA4FF6BF894C3451A9281C994FB186 + + fileRef + 24985E299C50D6EA5B6F65A96C23A6FA + isa + PBXBuildFile + + BC324585A8C218375DA84B28852462AA + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVSystem.m + sourceTree + <group> + + BC75C69EBF2DB696D673F72E10A9F3E4 + + fileRef + EEC731BC28352575CDF493AE5FB08AE5 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + BC87F9FB379FA9C88FA4079484EA4B88 + + fileRef + 9F57030CDD579F1DBC6E7C388F349C53 + isa + PBXBuildFile + settings + + COMPILER_FLAGS + -DOS_OBJECT_USE_OBJC=0 + + + BCA2EC0484FF8D42B4603EA2477BAAB8 + + explicitFileType + archive.ar + includeInIndex + 0 + isa + PBXFileReference + name + libPods-Demo.a + path + libPods-Demo.a + sourceTree + BUILT_PRODUCTS_DIR + + BD41CD6C6660450A1A0502C81B86666A + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVHttpResponse.h + sourceTree + <group> + + BD902278B1F2B51F4B300C01414D911E + + fileRef + 46B06AE59DEC7D9A99D69A95CBD3BC37 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + BDA86D0FD83C42AA566D217D2CD53E99 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + MJRefreshComponent.h + path + MJRefresh/Base/MJRefreshComponent.h + sourceTree + <group> + + BEDC26C028197B219DD378338825ECBE + + children + + B2697219E243EBAADF5F49FD31C51093 + 3335AE7C3E8931A3729ED7A2E4001A6D + + isa + PBXGroup + name + IOS + path + IOS + sourceTree + <group> + + BEF0D115FB13016A3121AD78BA006B14 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + SDWebImageDownloader.h + path + SDWebImage/SDWebImageDownloader.h + sourceTree + <group> + + BEF35EE7528257D4C51CDD2862B579F3 + + fileRef + FA72E8189879480F7787E445A534EC41 + isa + PBXBuildFile + + BF26A477A93BD9A1B046D9046F6ACC2C + + fileRef + 47A11CEDE14C1CCF86BB294E0906EBF7 + isa + PBXBuildFile + + BF3CD1971ADFB35725B8F1967EB65EA3 + + fileRef + 0D951028230A613A6FABAF9C2ED681AB + isa + PBXBuildFile + + BF9EE48CC6AA0659A6AA22FE3879A369 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + SDWebImageDownloaderOperation.m + path + SDWebImage/SDWebImageDownloaderOperation.m + sourceTree + <group> + + BFD7A4A7361F9A70965AF43BCC7352DA + + baseConfigurationReference + CDFAD82872C4A9CA55B64E1A7A350B9D + buildSettings + + ENABLE_STRICT_OBJC_MSGSEND + YES + IPHONEOS_DEPLOYMENT_TARGET + 8.0 + MACH_O_TYPE + staticlib + MTL_ENABLE_DEBUG_INFO + YES + OTHER_LDFLAGS + + OTHER_LIBTOOLFLAGS + + PODS_ROOT + $(SRCROOT) + PRODUCT_NAME + $(TARGET_NAME) + SDKROOT + iphoneos + SKIP_INSTALL + YES + + isa + XCBuildConfiguration + name + Debug + + C0527A9935CB020F35D16F41918CA7A4 + + fileRef + 78567B2D2C3DB8D0A00936D224FD02FA + isa + PBXBuildFile + + C0C1E2A64507633B73DE3820676BB30D + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVPkgInfo.m + sourceTree + <group> + + C0EF1345E2EDE17A2F0F1C7084D0864C + + fileRef + 6E9F50EA7AF8CAC8A44A18346E92060C + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + C14C9CAA9E22AEE07CB8112DEE03B3FA + + fileRef + 501C4944BE8D6558127A3515B5ED7B14 + isa + PBXBuildFile + + C18E08C2A4DA6073DABE1DF3C5656FB3 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + UIButton+WebCache.m + path + SDWebImage/UIButton+WebCache.m + sourceTree + <group> + + C240F3087E66DD2E4943EA83FB00B54E + + buildActionMask + 2147483647 + files + + 3415B5711281517B4105C3A0B5E362CF + 30B6CD7FA08488E701AAEEEE69524B0E + AAC78A77396DCEA383011F3A5D24ADA4 + B4816AFACB2486F043DF806BE95D1E1A + BC87F9FB379FA9C88FA4079484EA4B88 + 4BAE51A305848F4F211246D3D71D9352 + 7B34C97DBA61C215A4B0343673F59865 + 66CDF57C0565C682D5F756E4656745DF + 11E5398B435F64954287A2D342445329 + AF4CCF4B30DF6F3F9CBF4699C679D58D + 797A41941830FE4580315B8F781707DC + 1C3FA2159C6D603331366253373F76A9 + 36893488B2DB0EEA4E31146D66822D87 + C547600783B48BDD21452C730A9D3039 + E9084EB874AFB6487CB8A1FB1734E253 + + isa + PBXSourcesBuildPhase + runOnlyForDeploymentPostprocessing + 0 + + C24EFDD1BF0C59D941292EA33D14FAD7 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + UIImage+MultiFormat.h + path + SDWebImage/UIImage+MultiFormat.h + sourceTree + <group> + + C290B4F7BB8A778F7A2AF018EE5FADB2 + + buildConfigurationList + 90F61C1B0444F77E612DB67FD3FA5212 + buildPhases + + 4176F658CFF9600AFE6C1D54CC08F215 + 011C51690A7646EDEE9277B3A40293A4 + 537AA66BF9E146C99B5978D8E4ED97B5 + + buildRules + + dependencies + + isa + PBXNativeTarget + name + luaviewEx-luaviewEx + productName + luaviewEx-luaviewEx + productReference + 107D55D61A4636DE8BA66B963823103B + productType + com.apple.product-type.bundle + + C29E281BD407EA1E9FF4583F7E492710 + + includeInIndex + 1 + isa + PBXFileReference + path + lbaselib.c + sourceTree + <group> + + C3159D56649FD2406AC4DC7B2D12247E + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVFlowLayout.h + sourceTree + <group> + + C323AB62E7B642E70AE36A96CBE0224E + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + MJRefreshAutoStateFooter.h + path + MJRefresh/Custom/Footer/Auto/MJRefreshAutoStateFooter.h + sourceTree + <group> + + C38409D12CA6F9D9A5E911EA6B41CDAC + + fileRef + C5506410A6238A1F694D9CB7238F5667 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + C387C869345121E7D5349E78BD30A054 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVExImage.m + sourceTree + <group> + + C46C1EF777315A011CEDF14E291E5A72 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + SDImageCache.h + path + SDWebImage/SDImageCache.h + sourceTree + <group> + + C48CF6A9E431034B4E8959A3CC050148 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + UIView+LuaView.m + sourceTree + <group> + + C496DD454DC097BF63F0D3A8B52D9786 + + fileRef + A37F23A7A0EE7BCC163D74266A85804D + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + C50CFC813D4C0BE98BE4528AD0B5A7B4 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + MJRefresh-prefix.pch + sourceTree + <group> + + C543BE2C350C1698F28E75C947685B94 + + fileRef + 0E20491F4F04EFE0E6B2624C3135FB5F + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + C547600783B48BDD21452C730A9D3039 + + fileRef + EB7BBEEAD9550FE792CA33AFFB49757E + isa + PBXBuildFile + settings + + COMPILER_FLAGS + -DOS_OBJECT_USE_OBJC=0 + + + C5506410A6238A1F694D9CB7238F5667 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVTransform3D.h + sourceTree + <group> + + C550E00E550ED1525E1242091AE7008F + + fileRef + 25F8ABDD1532A296D8F95098E2E0A972 + isa + PBXBuildFile + + C5A01DF93F3D6B48609520278E647387 + + fileRef + 2D109731797C16F162C393B7EDC8CEBB + isa + PBXBuildFile + + C5DE95B97F7A6B9E1A6E8C111862843D + + fileRef + F09EFD0B77BCC310A147FCD4621FB9B7 + isa + PBXBuildFile + + C61A5A44452BEA0578A57C50C3AA6489 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVEvent.h + sourceTree + <group> + + C649079242667E7BABD909F322336C18 + + fileRef + 6020DBAA71982AD31F66B3807AF5BBA8 + isa + PBXBuildFile + + C8C4C3ECD8CB6AA0DE543993F6E5F91D + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + lmem.h + sourceTree + <group> + + C8F55B472CAD7AEDB068A0A1EB1D9FF4 + + fileRef + F6D49F1DBCF586CF4DD1C2308BEBFEC4 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + C91C5A40BE761243624FA8BFC2900746 + + containerPortal + D41D8CD98F00B204E9800998ECF8427E + isa + PBXContainerItemProxy + proxyType + 1 + remoteGlobalIDString + 956C5BE492C35A2116CA2CECD7795085 + remoteInfo + LuaViewSDK + + C9327210BE3579CA80996A84B1928625 + + fileRef + CA82E9BEF6B9FB3705F4F38D7B116628 + isa + PBXBuildFile + + C9E2F7902B8D839390116F7BCA68DE45 + + children + + 5F0ED6343850C31C0C0AD29F9E68B2BD + 8E666DE133DB689B0080C832470E745C + A922468882C625BF3C3CB2C4BB21AAA5 + + isa + PBXGroup + name + Support Files + path + ../Target Support Files/SDWebImage + sourceTree + <group> + + C9F21D916FDC1AC048E348E299283081 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + lualib.h + sourceTree + <group> + + CA82E9BEF6B9FB3705F4F38D7B116628 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + MJRefreshConst.m + path + MJRefresh/MJRefreshConst.m + sourceTree + <group> + + CB3CE364FCC608BBC950551503D108CB + + fileRef + 3F7CA8B54243D5879C5432DD04A4CFE8 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + CB3CFF857464FA2F76B12B45B1374DB0 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVScrollViewDelegate.h + sourceTree + <group> + + CC171CC602AB1623D62F7B69800B0451 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVPagerViewCell.h + sourceTree + <group> + + CC8588D32F9731CEB9D06BEB1C6991D9 + + fileRef + BA2B9DBFEE98A1F5274FE50EA63D7B9B + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + CC8B0F53E92326E86E80F3EF085EFD8F + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + wrapper.plug-in + path + luaview.bundle + sourceTree + <group> + + CC9C067A4572D72BFAC894C14C3D102C + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + SDWebImageManager.h + path + SDWebImage/SDWebImageManager.h + sourceTree + <group> + + CCBF448F08FF10B8B94FEE5E94EF8CE6 + + fileRef + F6817491FA6EAAB7C1B3871DFCFD50CC + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + CD1D45F979FEBC8D4DE618289EF4854F + + fileRef + CC171CC602AB1623D62F7B69800B0451 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + CDBF665214248E73C84CC7E8DD1BC3D5 + + fileRef + 7A6529CB909734DAD2EBA40AEA09612A + isa + PBXBuildFile + + CDFAD82872C4A9CA55B64E1A7A350B9D + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + text.xcconfig + path + Pods-Demo.debug.xcconfig + sourceTree + <group> + + CE0D4CC14A9991B37123BA163AB5E18E + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + SDWebImagePrefetcher.h + path + SDWebImage/SDWebImagePrefetcher.h + sourceTree + <group> + + CE67A811E548573768F6737EC972657F + + fileRef + C0C1E2A64507633B73DE3820676BB30D + isa + PBXBuildFile + + CEC1FDAA6941E91F05D82D71B4694840 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + UIScrollView+LVRefresh.h + sourceTree + <group> + + CF0B06D68FFC2B969822825FF8293704 + + children + + 0E4C71A0883D883D2EC58F33F9F59FF9 + EA4EEB6F12B63745A8FBBCB7A9D76579 + 4E212E1A5EF66FA8DFDD53AC6D5BD4C2 + + isa + PBXGroup + name + luaviewEx + path + ../../luaviewEx + sourceTree + <group> + + CF2EE622517E7C9291ACF880ED4F382D + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + luaviewEx-prefix.pch + sourceTree + <group> + + CF4CBF5DE8C3747B873AA4D15CAFD2EC + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVPinchGesture.m + sourceTree + <group> + + CF7DA1BF393A2E4987445AD51981272B + + buildConfigurations + + BFD7A4A7361F9A70965AF43BCC7352DA + 48A3B5709CC1D4959D702174B6A3C032 + + defaultConfigurationIsVisible + 0 + defaultConfigurationName + Release + isa + XCConfigurationList + + D00FE05DACB72541D4D58EF762E3FAD0 + + buildActionMask + 2147483647 + files + + 604D52241F4D1C186EF8EC534C033C3E + B81AC49B8BA0BEE07CC8501A6B82A4FC + 13DC702D891F455192182ED17BC34770 + B5E0919F738A590066F0B62223C2713E + 92C9C24626EAC668B0901B98F6C49CB7 + 8C6F15529DF4D308EC80AB9BAA189B1E + 343F19CF510DDF196F2A2CB298B0A510 + 5A7748C9171BA5B1CE37D01BFB368940 + A31553C0508D4AA224F19034560566E5 + 89B3AE3519D907C0220AC85B9CDA2192 + 2BA3C917C6086A279F6B10D0A29D21F9 + C14C9CAA9E22AEE07CB8112DEE03B3FA + C5A01DF93F3D6B48609520278E647387 + 98AB6A2344ACE639419CF3B33DD07B23 + F3109D062951AA8999CF7924F771F8FA + 5D9C728BD89F17472B0497A4E2516448 + 59B2766E8BB4240AF5018C051626DBC8 + 4C9DE4A0935A9DE9FE2554816FB5CA1F + 64A25D16FDEC9C77614F766628348ECA + 377B345153866024C525006D1C851AF1 + F3043DD328703B41F65C173902479797 + 257C68D5BBF7DB619C983BD8A8D64CF0 + B313F553BA68B14AD5C5FE10235F6A1A + 3B30502F210F85DBBEA561C0BCFE8A22 + 2C4BF365CE5FC518D1CC6489715D12A0 + 963A6B7FD891AD92EE8609736ACBBB0D + 66D5DAD27199B721A3E8AD84DA1603F1 + 36851C6227466105D493FFF23813F8E4 + A85775D3BDDC00D28A749AF8A2661162 + B9672F2F82401F219FEC3719092D0BC3 + 3023A66A4CFCABCEB3DD519B52734B3E + 3602DBCB7489B22028326F079F87E1D7 + 59C899DC82B9AAA9CFFC5FE08B5D86CF + 9326E21C6FAE1344EC08B49E9C11A246 + 87CCB0F1730772D937C6A00574181DEF + 80C1446A8DBDD5E5F32E9375DE64A64D + 2CAA5C0284F787A6090F6BAC02BD6FA7 + 95F01F40BB3572F283688C42746B1A50 + 3868CA615CF17F32115555E6C8E69485 + A9730048C76B9ED53ADA1BEA2A6EE513 + 0BC295DE4727C46FB2A213137259B35B + 2CE8F04F1B87E46F188C3E79A3E7E632 + 772AFA7BF54733867C9EC68BBAFE61F5 + F537CDB34F31A64B346EBDC9E2C01266 + 457F7148333E0151B49C4ECBF318D59F + 9B67196018324E9026D33B89AC1AC21A + 0F6E434EFE109168E32511196484D4F8 + EBF8EFC76854A187E6CB669EECC5A92C + 0C8D38F782DB467E338AFDABFF185635 + 417628C5AB133E3820D200D2C504A4A8 + CDBF665214248E73C84CC7E8DD1BC3D5 + 91B94BB95CC9FEBF50D47DFFC5FFCD88 + BEF35EE7528257D4C51CDD2862B579F3 + 0BAEE4701F44450AF3E2ED674A624E86 + 7A6841D14A4341D1CF5364B24F6236B0 + D53714F7F3B7B61FC7CD23E3D7F378C8 + F5D694550B75896BDFFBCE6D00AFFBF2 + 58EE2C602B835CC8F94DDE44687F7A25 + 60B5CB22A100B61F7E0975960E45EEC1 + 1308ADF1BADA3AA8A92FDE73A663787D + 9608D459B61D89D22939B2FF2C1392BC + 128D58162055B047C51D86A1D442573B + 2AFB043380061347E950F7F5CFF33C32 + 4B9548C88C2542194FB30537F1D4EA35 + 9B459902DEE511B48255C3D87497FA12 + 9DE2FE925C195BEFFE225277AA043A13 + 8EDC8988CFFFA84502F524392D3FA01D + 9F42EEFBB24C46A65C809847F700CF00 + D5EEBF1BF7A18B15ACC78F578C08DEE7 + E98DD83F0005DDBAF7E134712A41D2D5 + C5DE95B97F7A6B9E1A6E8C111862843D + 566BFAA69E2D42EB24C4D860C62D29F5 + 4DC59F2036EB1022243C11D812DFC233 + B0ED78A5646556E0A601611DEDFBB8EB + 19800E4D9F28F1423BE14E39A3E4A865 + 8C7DF7454C0B572A71EEE807BD65870E + A5DC432335E5E6FFEE3B570AF7E1FBDA + A73D0CAF4E189898D748EC4504970EDB + 5840CBAFBE72AF044DE77CC10AB2552B + 892E625B3B2F6778E3C3AE8073A7405D + F5A99BE1F5516A45976552D5A45A4564 + 563ED884287349E36EFDEC65B3723922 + 18DA5A556955B4F7FE5E281E7BEA37C7 + 81840C2A6ADA09777E9ED7D07AA0409B + 3F80604355A58ADDF479268A9FC35629 + 4C0F7F7CDC4D238A667370DBE4547AA1 + CE67A811E548573768F6737EC972657F + 315138DB1523B1BEA7346EA032464BB9 + 43F27D44CB41541D3D1BA8B25842E2F2 + D48F974F638C4B1171E5605111CD77EE + 4CB07ED2447146541E045018FD241CD2 + 02D9BD86B8E170A9A8AC5E3D481EF2C6 + 18FBF186487AAD9AA2A675431D9D1F22 + 7E1FF24F595B689AAF460593A7CFE95E + BF3CD1971ADFB35725B8F1967EB65EA3 + 3DEEC2A0022DF6A997466DF847D4AC57 + E481587C97BA48675E34A474B9C1E9A4 + 6A6DD776E4FC2CA9F48E27224C462079 + 627EACDA0FDDF7E65439BD3957806484 + 63C62608781B69EF4AA9A1C482AF0ABA + 2B80A2F7CEAB7A0DAEA25437A3D07446 + BF26A477A93BD9A1B046D9046F6ACC2C + 7C6DA1A9E2A1C3813C9B70ED5D1C04C5 + BBFA4FF6BF894C3451A9281C994FB186 + 2FAAABF17BC79FA8FD0C04DB14C5D3ED + B5B3CBFE61E48ECF6DAA22322D0901B8 + E21ABE391FB21A024686088C0EAE9B02 + 4C773573A7DC6AD33C835DE783C1EE6D + 461C624817D2B27A70ADF7B3B645A9A3 + 37A808B1B5C22884F6C6C281A28601BD + C649079242667E7BABD909F322336C18 + 5B0F8823D4C55B465C0FAEC9BF9B2EF8 + E9ED724D5BAFA233953EFF035E2CE3C3 + 51D07662E3A06201708447B9E508893E + 8A0EE704985B3194C4A04E72E46D7F31 + 8B20892071442D8FE3585F90D53D7A78 + + isa + PBXSourcesBuildPhase + runOnlyForDeploymentPostprocessing + 0 + + D09ECEBEA5E66FD2DF0A6ECE2FAB2BCC + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + Layout.h + sourceTree + <group> + + D12AEF57FA46A5ABDB96B0EE268F3C03 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVRotationGesture.m + sourceTree + <group> + + D142B1D5BCF35B7080DA051377DA4A2A + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVSwipeGesture.h + sourceTree + <group> + + D194636F859BB134BB3FD92546B6728C + + fileRef + E1BFC584DB7723999816B0D32FE17B0A + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + D1F548C6DE1AFF9BA9CC67D083AAECC2 + + containerPortal + D41D8CD98F00B204E9800998ECF8427E + isa + PBXContainerItemProxy + proxyType + 1 + remoteGlobalIDString + C290B4F7BB8A778F7A2AF018EE5FADB2 + remoteInfo + luaviewEx-luaviewEx + + D21DBF15312A3EDAC3D56BBEC5E6E0AB + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + MJRefresh.h + path + MJRefresh/MJRefresh.h + sourceTree + <group> + + D2F983E998B021AB8223EC8BC9E70211 + + includeInIndex + 1 + isa + PBXFileReference + path + ldblib.c + sourceTree + <group> + + D349ED1F73391A240C8B8E9CD2DA7C3E + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVFile.m + sourceTree + <group> + + D34DFB5388EB47DDA90900423E201EC0 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVLongPressGesture.h + sourceTree + <group> + + D40EBA7C2A2635C8D497951B5BFAF12B + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVStruct.h + sourceTree + <group> + + D41D8CD98F00B204E9800998ECF8427E + + attributes + + LastSwiftUpdateCheck + 0700 + LastUpgradeCheck + 0700 + + buildConfigurationList + 2D8E8EC45A3A1A1D94AE762CB5028504 + compatibilityVersion + Xcode 3.2 + developmentRegion + English + hasScannedForEncodings + 0 + isa + PBXProject + knownRegions + + en + + mainGroup + 7DB346D0F39D3F0E887471402A8071AB + productRefGroup + 2A3D8905FED90C95EF0CA9CD6FD22248 + projectDirPath + + projectReferences + + projectRoot + + targets + + 897DBCA022EEA6EEEE3413D5C335650E + C290B4F7BB8A778F7A2AF018EE5FADB2 + 956C5BE492C35A2116CA2CECD7795085 + 9AC35F1DE54EB28C844CAC19E05D5095 + 5707A271779152F07EC77A7EB7ABD103 + 86C582DB039C2092AB70FE04FD45E436 + + + D48F974F638C4B1171E5605111CD77EE + + fileRef + AA8A044FA216D03FB0A78BE5C4620D1F + isa + PBXBuildFile + + D4E8D3FA06BC49528D8A991F98D7AC27 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + UIImage+GIF.h + path + SDWebImage/UIImage+GIF.h + sourceTree + <group> + + D50A811A8469B70B0D951EEC2800878A + + buildConfigurations + + 79084E68181498DC2C09BB7E681B2C51 + 9072EDACE27EC0FA2A19863A0A8550F9 + + defaultConfigurationIsVisible + 0 + defaultConfigurationName + Release + isa + XCConfigurationList + + D53480A24F0018010DEE441009153B07 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LViewController.h + sourceTree + <group> + + D53714F7F3B7B61FC7CD23E3D7F378C8 + + fileRef + F1024CD9FEB146FF5D4458F5FD0EA873 + isa + PBXBuildFile + + D5CAC3DA5EE1AD2C7A5ABBD65FE3C59D + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVBaseView.m + sourceTree + <group> + + D5EEBF1BF7A18B15ACC78F578C08DEE7 + + fileRef + 88D556157C0CA6FF501F0527A9048898 + isa + PBXBuildFile + + D6420D745013D90D711A68699A12C3AA + + fileRef + 2300B4A751ED386AA126C27E45CDF588 + isa + PBXBuildFile + + D7B91D04701A73CA3B558049CCCD0E09 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + UIImageView+WebCache.h + path + SDWebImage/UIImageView+WebCache.h + sourceTree + <group> + + D8AE3D56C229519D899C15B467F5E6DC + + fileRef + 3A59FA484998DB5F7E476DDAF37CB5A4 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + D95C8AC0DEF6515B8EF80DBC2EC281AB + + fileRef + C3159D56649FD2406AC4DC7B2D12247E + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + DA796CB3E18D553347A8A69E472DA35C + + fileRef + 3ABBBCC580EA95EE98AC7C9B4551E03E + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + DAC0F4716E8B8D51CDDD258065F8F833 + + children + + 046DE20980BF0D1ED96192F78A9F3B33 + A19E9359717732DB16195FEC28054C2F + C50CFC813D4C0BE98BE4528AD0B5A7B4 + + isa + PBXGroup + name + Support Files + path + ../Target Support Files/MJRefresh + sourceTree + <group> + + DAF823CD1382D26E463687236DFA4AED + + fileRef + EBE7FC492303CCA909B8C62B348A8DF1 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + DB560486479DDDD377EEF25306A3EAFD + + includeInIndex + 1 + isa + PBXFileReference + path + lstate.c + sourceTree + <group> + + DBF6C42ACBEE5CCEF4557F3C74ADE8C6 + + fileRef + BD41CD6C6660450A1A0502C81B86666A + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + DD824AE62915B7346D318977A5C4ED9C + + children + + 1D28065CDC689C0CAA02ECA4D99F4EEE + 78482F44635EAEE1E97518CA8E012BD9 + 5A93B171C1E1EDF75E0EFDF1C2DF28FC + 3E9A0367C6AA92183B76C3BAA7F2E63E + FDB6110C621265090FE681745870492C + 48BC94706ED0F1B8FD935772E6EBF997 + 7E416774B2996337C3D0E99E086F047B + B52EE726CABC6085A18DE6A281F33637 + BA2B9DBFEE98A1F5274FE50EA63D7B9B + D5CAC3DA5EE1AD2C7A5ABBD65FE3C59D + 4606EFB57FB5066F39397C739BF84CC6 + 9F1EDE358215935E8A9E0C0F9071DDE4 + F5941C112F5CD9BE394432513C70D6C2 + 6CE8BA1CC153472DEA5348F243B6C213 + 3978A4D5F882FD7B57A64C642659038A + 6B73EC8D9BB6A4B6CB933EB8447291DC + 18FC55E7A2AA58B1092D833C3A201243 + 53D6E5C9CBA5F03006A11B68D3D95468 + B1508D43CB6FB14F78655D6F6E1F60CF + B3BF3085D6CD2EF50CF3431C0FB56296 + 4442C696FE39C7A55558985FD0ECD80F + 2BD1B6C16B749F5AF1280ABB7EBEDB68 + 76A62C4FE04E529148E38E1EA271B193 + 05146DF4C72F6DE622B3482E83AD4A13 + A298FC7F1076DE7D251D916D727A9907 + 7A6529CB909734DAD2EBA40AEA09612A + 8DC7D7B476F660C2250067B1F74E47D6 + 396C87EE0AA4B806979FB5BF72B590FD + 93F16614598E109BF6A8B1FA41F055A9 + FA72E8189879480F7787E445A534EC41 + 7862B0EECC1DAFDEAD730E8B9BEA62B2 + F99BA1FA74A12DFF25DA5709B546F551 + F56914674DA0AF1E6AC010FC7113D74C + EB42B71A313362AD456F13A76E695788 + 2F979F6ACAA073B19634E2BA16AC053C + 573ADC3C891FBA670A36BD45C3D7C6D2 + C61A5A44452BEA0578A57C50C3AA6489 + 3E3B35F64BBD671E298088C15B7393BA + 40F3ADC7C956412AEF1B29B263D033C6 + 9C43DE662F6C895DA12CCA6C85D6EA34 + B3FB2B7E053D86661135FE06C5F87591 + D349ED1F73391A240C8B8E9CD2DA7C3E + C3159D56649FD2406AC4DC7B2D12247E + 30F33A2D9D9467011EBC18ECD91DA6D0 + 0069C69D4E50900D4B6DB88721929F18 + 4C3DF57E5A7F53CC7BEBB0A0E9714E53 + F6817491FA6EAAB7C1B3871DFCFD50CC + 4CD886EF1C0728613450008CCC22F07A + 9B214ED7CC89E2A54E2C502E7AB8DB5B + F5D648D9050C305B35AD0620836F415A + 8A1AA383C04F4B4FE460C97AFF881E03 + A87FBF59E1E0B08C03B937D02B2143FE + BD41CD6C6660450A1A0502C81B86666A + 817B590920DF968A31CEAC1E2F2B93A0 + AC84A33033DFE29523E204D805A919ED + F09EFD0B77BCC310A147FCD4621FB9B7 + 0E20491F4F04EFE0E6B2624C3135FB5F + DDD8041E4CC6B92551EA7601114170CF + 8915253C09B57480829F50053606D981 + 07282814DCAF1910BC004FD25EFAB618 + D34DFB5388EB47DDA90900423E201EC0 + 2A057CEC7805963AEC968D52AF26801B + 0E347E52967978AE8A29E0E86041381A + 5A6D4F8193304D1E43BF6F17B433B8C2 + 5A28D175F6DF84855662E020BEF79988 + 29F78858354DBAB936125BF9ABA2E6C5 + ABEB11952370C9E22534E5B57DCF7261 + F73C73AAE60625F8E1C29D731BC37FB4 + 2AB0F59C7F97CC7B8D41743BF7D4A0E3 + 03782A4641772CAFDF1C6A58B50D0C6B + BAA5D3F826C7C5CFB67B35038B590421 + 71A27EA5520E60D7261D034013A0B58C + 0281BDDA769AFF211481D7738496989D + 29793D4CD0F70C98787EB90A858B866D + 11790AEABCF39AACA03BE811C84830F5 + 7898632516013BE019048DFEA6E3E811 + 37695D0A05BED6ABF1F579FD9E99554A + 52B2155FD2A473541D7FEF05165041DC + CC171CC602AB1623D62F7B69800B0451 + 1B04371E67EC2B2015B108FD848BCFC7 + F6D49F1DBCF586CF4DD1C2308BEBFEC4 + 143F3334F0EA46492CDB8852A174193F + 943F714F95D8A897CF199DB41767EEE2 + CF4CBF5DE8C3747B873AA4D15CAFD2EC + 697F132F2DFCA6F7BD385E8B69106518 + A89371DD012A68160E5CD71FD773B168 + F91B57533C10FED7ACC1CAFEC2A2988C + AA8A044FA216D03FB0A78BE5C4620D1F + B61E38BFD4DB638553ABD75F0451216D + 5563C227F4CFD0BB18C46F1A4D3E87CD + 9452384A062A9CDEAD4042834DB6702A + 88C0AC96CA31ADC0432FCA03474C0C9D + 5634BCD8C43E92653BCAA469F1823D00 + D12AEF57FA46A5ABDB96B0EE268F3C03 + 290C7E36D40B8B10B5003CF70DBCDB3C + 0D951028230A613A6FABAF9C2ED681AB + CB3CFF857464FA2F76B12B45B1374DB0 + 8423C840B31734512F55FE12F7DEA797 + D40EBA7C2A2635C8D497951B5BFAF12B + ABE8F315730961AC4B78DFDC632A2318 + 348B1AF87760A3CCE93BA87530F10E04 + A5E8C236BD13650324DEE1616B8D0467 + D142B1D5BCF35B7080DA051377DA4A2A + E7C38BF8D49BFCC3A3D3D2891917452F + 6290A1FDB0302CF140ED162AE9E23A9D + BC324585A8C218375DA84B28852462AA + 3ABBBCC580EA95EE98AC7C9B4551E03E + FEC5A9842DD28C22DBD0D0B3CF60EB38 + EC96CF865FD43B9874A7B151951B95EF + 47A11CEDE14C1CCF86BB294E0906EBF7 + 995D146BEAFF10317A1D6C6541B8069B + 7126E933CA554994994B6B3C3DB740E1 + FDF43F1175E8CEF86FD60EE66B0C9901 + 24985E299C50D6EA5B6F65A96C23A6FA + C5506410A6238A1F694D9CB7238F5667 + 3A9EF7E2C2E6E1B66B2FD76A48F2D9F0 + 53740A50BB4D7B5B987229EEB1AA96B0 + 7E4420F5CC78E5ECB3DBD72879FF0A71 + AC02134060C86A6645D20B2B8D1DCF73 + DE4DF11EE1662D1C7A78EBCB7B56B2A5 + 182B279C4AE343381DC15D1861FA1E1E + 5A586456AC18C2CF5115BB55C9569997 + 6A13D12EEC9DC6DEDCBA4329471CAF1C + 6020DBAA71982AD31F66B3807AF5BBA8 + 42E242563E7B39DE4D2A3CEBDD3791B3 + 7EA30A973267891588C3B6E0C6C9C067 + CEC1FDAA6941E91F05D82D71B4694840 + 084241B9DC5DC7A2F68E1E7FE94FDEAF + 88A0C1BA6D68C3D29D4E157FDAEAE4ED + C48CF6A9E431034B4E8959A3CC050148 + + isa + PBXGroup + name + lvsdk + path + lvsdk + sourceTree + <group> + + DD828C74E015AC80F828E2E30ED6B2BA + + buildActionMask + 2147483647 + files + + 7B51E6C8E8C50AE87094DCC0450B5384 + 0C0101F9AF8D83E8C07022ED9AF7A9B5 + + isa + PBXFrameworksBuildPhase + runOnlyForDeploymentPostprocessing + 0 + + DDD8041E4CC6B92551EA7601114170CF + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVLabel.m + sourceTree + <group> + + DDF1B84675F3FD174AD5BD30E6CBF2F0 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + lparser.h + sourceTree + <group> + + DE4DF11EE1662D1C7A78EBCB7B56B2A5 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVUtil.m + sourceTree + <group> + + DEB54CFEC43C0CBB0D5AE26FC6B67AB5 + + fileRef + 2A2C66C5B9F0116FD8909DE10413432A + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + DF733814C807457EF90B1729E10A3090 + + buildActionMask + 2147483647 + files + + 79A6F7AFCA22BC1ECB24C87CB7BB7BF8 + 4AC7BF99BA86DB548275898882B20E8A + 636D8806E3D4B9E2603676555687DD38 + 48409AA22B2FB990D7DC70F2DD9643BC + 34103EE62B851EC9916E8A77FBBB148F + 524DF2A621890393D2577CD3024C6E26 + 91278AA6890375CEF7CABA2872B8B4CC + B852107F161F577E28111713B96DBA8F + 6DA0850995A2DD2970A196D5D73D3F6D + F6D0821B44AE3A9644B44DDFB2D983D0 + EDF55E6E6C67683F82E6A28E46763992 + 7A897E10D01BE231C45DDBD18901136D + C0EF1345E2EDE17A2F0F1C7084D0864C + 8F748F91D55DA1BD22C64EF7C9C825FF + 6F95E177A7FEF401098084AAB78D975F + 2A613341E55CD55DECB97E5667DFCF29 + B08FCB4B91D87BBB8AA714246AD07930 + 53964CCABE279C441CAD05C64619E7D4 + B36B94A086AD4C43B97E7F2281266A0C + 64F6D21A4BF0BC37F6B44EA6DF283427 + + isa + PBXHeadersBuildPhase + runOnlyForDeploymentPostprocessing + 0 + + E182D13A0387591244DE25403CED7A1D + + isa + PBXTargetDependency + name + SDWebImage + target + 86C582DB039C2092AB70FE04FD45E436 + targetProxy + 62D36155060BA026F558EE6D085AB788 + + E19B46575CE394CE24851C0D1679D623 + + buildConfigurations + + 238BC3EF368DB6136B5741FDE888C8AF + 5D6DBF00422365D3597783C26B241087 + + defaultConfigurationIsVisible + 0 + defaultConfigurationName + Release + isa + XCConfigurationList + + E1BFC584DB7723999816B0D32FE17B0A + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + lauxlib.h + sourceTree + <group> + + E1D0089FB1058478C4ACDB55A089B47E + + isa + PBXTargetDependency + name + LuaViewSDK + target + 956C5BE492C35A2116CA2CECD7795085 + targetProxy + C91C5A40BE761243624FA8BFC2900746 + + E21ABE391FB21A024686088C0EAE9B02 + + fileRef + DE4DF11EE1662D1C7A78EBCB7B56B2A5 + isa + PBXBuildFile + + E3038A78003298A17C854ABA37E85170 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LuaView.m + sourceTree + <group> + + E481587C97BA48675E34A474B9C1E9A4 + + fileRef + ABE8F315730961AC4B78DFDC632A2318 + isa + PBXBuildFile + + E4A93CB04BA6834644426E250C1D2439 + + includeInIndex + 1 + isa + PBXFileReference + path + lstrlib.c + sourceTree + <group> + + E4D382C3285C5DF3780CBF5E0EB434AD + + fileRef + 28587B962BF1C1C6D7FF6A499334D169 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + E58175612E1B5AA5F33833093611F375 + + includeInIndex + 1 + isa + PBXFileReference + path + Layout.c + sourceTree + <group> + + E5820222B31E493A0C3A07B6C559016E + + includeInIndex + 1 + isa + PBXFileReference + path + slaxml.lua + sourceTree + <group> + + E5EED4DD19A8E92777CFC22FF262A0CA + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + MJRefreshBackNormalFooter.h + path + MJRefresh/Custom/Footer/Back/MJRefreshBackNormalFooter.h + sourceTree + <group> + + E67F9C9362C51A3AFA082A39691BF49B + + buildActionMask + 2147483647 + files + + B657D9F448E6E884EBE3C42D119F4B36 + 27D84310F981F3E905B2A8A05D54BC5A + 704624A404920F906F8C4758158BFFE9 + 9562CC1BD4511D4CD98785D3EA3D6249 + A9957623689AB95440AB1FF44E6389D0 + 1D3B449F78B6BEFE4B3E6D8D7A1DB3A0 + 6927E60D52BD2AAB3B1037D376F4B96E + FB1B8D87EDCFFB7AF23E12659B2ABEAC + 7A64DB3261E77E3E16ECE8CEC90065A1 + 0177FC64DC60D2EE0DF584CE5FC5F66E + C9327210BE3579CA80996A84B1928625 + D6420D745013D90D711A68699A12C3AA + 61F09CD705317B289FA824E3684A04FC + C0527A9935CB020F35D16F41918CA7A4 + 964A184485B106E9E613FC1D1EA58FD8 + 0C3B1B32D99F31A53712FE54384DED9B + 73B52856D8CFBE4DDFA2B42F2BE01351 + 2FCD639841C341855AA4F5F53D6934BC + 13F1E6A9AC1DAB47E8F3F6239D8032B8 + 5FA4EA555E34F7BD719E19D5BFBB4A3B + + isa + PBXSourcesBuildPhase + runOnlyForDeploymentPostprocessing + 0 + + E6890D3D99BF75884486558215E27FA1 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + llimits.h + sourceTree + <group> + + E731C9926A6C35E92C8B417737E47BE4 + + fileRef + ABEB11952370C9E22534E5B57DCF7261 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + E76DE396354ECAA11277F37907E12FE7 + + fileRef + FA9C85076DEB156BACB490133D4BA212 + isa + PBXBuildFile + + E7C38BF8D49BFCC3A3D3D2891917452F + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVSwipeGesture.m + sourceTree + <group> + + E86E8B315217720BAB0CDC4E78AE3604 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVDebuger.h + sourceTree + <group> + + E8A5AFBEE221C159CA81030D4A658EED + + buildActionMask + 2147483647 + files + + 533807B79DD8E8A4D977402B20A0E8CD + 587BBF03B923895B38467C43D72F6D17 + 959652CBAB972B8AEBFBB392031F0212 + 5FDDDA6FA2FC2F9497F18BC0D8232208 + 0E0686BFE33F9DDAB4D19E995480F7BE + 91F505936CB16A1F2B556231E2252545 + DEB54CFEC43C0CBB0D5AE26FC6B67AB5 + D194636F859BB134BB3FD92546B6728C + 0557238855F7958B0BD4F1C060DE3E89 + 45B3E02FDFBD5FFF514F0804DDD82F30 + 53ED692B1BC969E7D33B2F9945AF9299 + 705A081A86B0567189C003FE14CE5AF8 + E91AA50B63463E77842B02E76459362F + CB3CE364FCC608BBC950551503D108CB + ED32CBAB1075D79B616C6A7C462592D2 + EB60E25ACD7427085B4A6108F91F5813 + EB51F9D6F1F553C5540DD33D076C5EDF + 3F79D09B649802083832E8054268C853 + A44CE95CF7D39500BD4B40F72A622EF7 + 077FBD97BCFAB1B7BCC73DCD43861B0B + 5FB6039AF893F51EF15C3750514269CA + 773E6539C49AB6B66E95636A85B80F70 + 2FE46EC96485818C89D7B45BA9234409 + 1588932714FCB49248FC29EA8238A8F7 + A6E6436AD216A57AAEEA891EA1E68406 + C496DD454DC097BF63F0D3A8B52D9786 + 11EE8118F85D2DC8070CB83AC30DD02D + 14CE973C98BCFE2CA63DF9A742F66569 + 84C83C0F6A9BAA96E6FF199DFE0A5F25 + DAF823CD1382D26E463687236DFA4AED + 1A7FC013AFEA93159B064CDE76F9C3DA + AC655C389FF138BBD4966CFEE486EC3B + 467F9F9B4008403710513C6090F407E1 + 9CB0C123A2A3203CA0BAB6D681EF87EC + CC8588D32F9731CEB9D06BEB1C6991D9 + 202F270B05D27D84805A7263ED30F087 + A97695856BD999EC1F73090B42D18BD0 + 2AA265A03762A4ED86C67A85B0D45BD3 + AFE5A06B46DD842B63C93FD1EAD29ABD + 3FF2E884BB70C9815AD1F3D1158B474C + 046765D495C9057D3B5DDABCA3A95502 + 97F26F4F58443DE9CE75A5FF98F14A31 + B6A9EA0DA3FD3F553A9C9B8ACFC1C322 + 67A54FF33AEDA7F8E07C700BCA80109F + 841597C166F12A9F4C5512610BF8C598 + 1C7DD8869EC78DBFE3F563240B7A9EA5 + 755324115C8D1BCE7BF14D9717EF2465 + 99D89F8FFCEA14AD0D7535F9B158DB76 + 1756A8D7E6B7D922A045FA36CDA275A0 + 05691A6D5154EAE340DEA4A95F90C68A + AAB24CDB6EBA27242F84E52BBD6338AD + 470CC2A2EF2E758648B5A1B557448907 + AB0F7E7DDCB792D2EAFE524823A86230 + 0FD4F671E6E8DA28BD4A5E73D1D4BC82 + 28AEC8C06FEAE1E55EECCC77DFECD002 + D95C8AC0DEF6515B8EF80DBC2EC281AB + 69613788FAA3F6DBE5B5A988DF47D9EA + CCBF448F08FF10B8B94FEE5E94EF8CE6 + 84B176DBB2DD9964E0A03317269AD603 + 2BE8EFE72F4FCDF1B804A4902016F2AA + DBF6C42ACBEE5CCEF4557F3C74ADE8C6 + BD902278B1F2B51F4B300C01414D911E + 0DE4D405F7D8E386510FD640EE2C1FA8 + 21D94823F69A197BB17A50E03C83A865 + C543BE2C350C1698F28E75C947685B94 + 69A3904202D1A7F11DCE525D3F3B38C3 + 5F33F15DC5938861D75B66C5AE3B33DB + F0BD0C1C185A1A3C837B306F1FB3453C + 0D77ABD68A4337BB644F781E07E23EB8 + F9321A44D9CCFD3BE6E5E6616A9C0245 + E731C9926A6C35E92C8B417737E47BE4 + 785612BB1A58824B613A2F943FFC272C + 8FE053ED8A9ED5BCE33A332F54721527 + A5F2658443C295DAC623887414762FAD + 36BC801C70F848C3CDF4520508916EF1 + 32CE3E4C2DD0CF037AAD237165E85B7C + CD1D45F979FEBC8D4DE618289EF4854F + C8F55B472CAD7AEDB068A0A1EB1D9FF4 + 989164B527C231435B4F8BC45518577F + 4CE95F3F7F0B9DE5150B385E98AEE0BA + D8AE3D56C229519D899C15B467F5E6DC + F694A8D983FD70E8241E8FDE85ADC4E1 + 73D0302E0FE7DA259C8715A87FF93171 + 9C235D35E1ED95A35F2F8574CD762385 + FE6A6DAA9A53F4B822F21FC841180847 + EE87C7DD79330ED1447946A4C4C512F9 + F60FBACFD3EC9B82683CE17539F624A9 + 5428DADCEEB326157DCEF0040460F704 + 991139F569CC64E620BC0344F5DABCF0 + 8BC52B162491217C2CD341A1527491E3 + 705FEA1290E1E307F7E501305528AC9F + 50EAAA4F38A292843B98C548875F0906 + 924A92CE6BA9A55477BC6540C3181B60 + DA796CB3E18D553347A8A69E472DA35C + 6A40240141D724C5010327A97127565C + F147C895C33259F6F6CFD9AFE9A99F61 + 2D67118429E02A2F2E0FF7503F2864E1 + C38409D12CA6F9D9A5E911EA6B41CDAC + B1FC96F4A467683AAD8007E38F5DF4A7 + 17B71DFA61AC754D923F842C63CBF6A8 + A9D97C57FD5DF50F24F726D7303F54DA + BC75C69EBF2DB696D673F72E10A9F3E4 + EA5040AFD80D4D571D61AAC1848111C6 + 340D996E5E6AB982BEB8E2A65A335AE0 + 8B24DA0221402891873036ABDB05ED11 + 83BC99394E5FFEB037B2A63457D47A30 + 0524A59F048FE513757D78AFF6074DD9 + 7BB607681B5BECC1D593ACCEFCAE3E2E + + isa + PBXHeadersBuildPhase + runOnlyForDeploymentPostprocessing + 0 + + E9084EB874AFB6487CB8A1FB1734E253 + + fileRef + 207EFA12AAA77DB5AA7C8CCD22F8929C + isa + PBXBuildFile + settings + + COMPILER_FLAGS + -DOS_OBJECT_USE_OBJC=0 + + + E9147195251E0E11AD9BEC4D2227EA9B + + isa + PBXFileReference + lastKnownFileType + wrapper.framework + name + ImageIO.framework + path + Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.0.sdk/System/Library/Frameworks/ImageIO.framework + sourceTree + DEVELOPER_DIR + + E91AA50B63463E77842B02E76459362F + + fileRef + FB1912F1A67413BD21D9073261B60344 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + E98DD83F0005DDBAF7E134712A41D2D5 + + fileRef + 80045B5072145A6462B7F17AD6038B57 + isa + PBXBuildFile + + E9ED724D5BAFA233953EFF035E2CE3C3 + + fileRef + 7EA30A973267891588C3B6E0C6C9C067 + isa + PBXBuildFile + + EA4EEB6F12B63745A8FBBCB7A9D76579 + + children + + 76C98BE4E806F9CD8011621FCE9E2978 + + isa + PBXGroup + name + Resources + sourceTree + <group> + + EA5040AFD80D4D571D61AAC1848111C6 + + fileRef + B6AED20A7DCBF097E69389473CF25460 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + EA635DA51B921749209EE5E0FD68A065 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + SDWebImageDownloaderOperation.h + path + SDWebImage/SDWebImageDownloaderOperation.h + sourceTree + <group> + + EB42B71A313362AD456F13A76E695788 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVDownloader.m + sourceTree + <group> + + EB485310B5B8619A748A5DEEEFF8C7FE + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + MJRefreshStateHeader.m + path + MJRefresh/Custom/Header/MJRefreshStateHeader.m + sourceTree + <group> + + EB51F9D6F1F553C5540DD33D076C5EDF + + fileRef + C8C4C3ECD8CB6AA0DE543993F6E5F91D + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + EB60E25ACD7427085B4A6108F91F5813 + + fileRef + E6890D3D99BF75884486558215E27FA1 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + EB7BBEEAD9550FE792CA33AFFB49757E + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + UIImageView+WebCache.m + path + SDWebImage/UIImageView+WebCache.m + sourceTree + <group> + + EBE7FC492303CCA909B8C62B348A8DF1 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + lundump.h + sourceTree + <group> + + EBF8EFC76854A187E6CB669EECC5A92C + + fileRef + B3BF3085D6CD2EF50CF3431C0FB56296 + isa + PBXBuildFile + + EC96CF865FD43B9874A7B151951B95EF + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVTextField.h + sourceTree + <group> + + ED32CBAB1075D79B616C6A7C462592D2 + + fileRef + 30A338DD47C8132F8933C24F92587BC7 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + ED61215E10852429E53E300EF5C0AC6B + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVBundle.h + sourceTree + <group> + + ED9FF67B3F29DAEEB47B3914D0B0F1BB + + containerPortal + D41D8CD98F00B204E9800998ECF8427E + isa + PBXContainerItemProxy + proxyType + 1 + remoteGlobalIDString + 956C5BE492C35A2116CA2CECD7795085 + remoteInfo + LuaViewSDK + + EDF55E6E6C67683F82E6A28E46763992 + + fileRef + 3172CFE0CF1E9C3B42AE1EC62DE29788 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + EE59907F54D7D76447835CACEC77F65A + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + UIImageView+HighlightedWebCache.h + path + SDWebImage/UIImageView+HighlightedWebCache.h + sourceTree + <group> + + EE87C7DD79330ED1447946A4C4C512F9 + + fileRef + 5634BCD8C43E92653BCAA469F1823D00 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + EEC731BC28352575CDF493AE5FB08AE5 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVZipArchive.h + sourceTree + <group> + + EF4B7C2304E2238BEE32984C0037A3D2 + + fileRef + A600AD735D6B2205314D42333E17E522 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + EF4D170AC70386955DA726196014FE48 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + NSData+ImageContentType.h + path + SDWebImage/NSData+ImageContentType.h + sourceTree + <group> + + F07F668E46955FC5E926C760A0598B3C + + includeInIndex + 1 + isa + PBXFileReference + path + main.lua + sourceTree + <group> + + F09EFD0B77BCC310A147FCD4621FB9B7 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVImage.m + sourceTree + <group> + + F0BD0C1C185A1A3C837B306F1FB3453C + + fileRef + 0E347E52967978AE8A29E0E86041381A + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + F1024CD9FEB146FF5D4458F5FD0EA873 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVDebuger.m + sourceTree + <group> + + F147C895C33259F6F6CFD9AFE9A99F61 + + fileRef + 995D146BEAFF10317A1D6C6541B8069B + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + F169905FB2516EBBDF450B34D2697422 + + isa + PBXTargetDependency + name + luaviewEx + target + 897DBCA022EEA6EEEE3413D5C335650E + targetProxy + 5BAB87E97D5102AD7C495D32161017F5 + + F3043DD328703B41F65C173902479797 + + fileRef + 870EC3CFAD191AF3B628C14C7EBA9C69 + isa + PBXBuildFile + + F3109D062951AA8999CF7924F771F8FA + + fileRef + 53A3E35D9C54046E1DA273C64D9AAF2A + isa + PBXBuildFile + + F3FEA1222D8D1B7BC11CE0DC513F8120 + + fileRef + C24EFDD1BF0C59D941292EA33D14FAD7 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + F4235B80C987036C9FC3997D6B861D2B + + children + + 3771D065C4364EE639435EE856A96A9D + C9E2F7902B8D839390116F7BCA68DE45 + + isa + PBXGroup + name + SDWebImage + path + SDWebImage + sourceTree + <group> + + F4496B73254185F5F0B1BC1B34947547 + + includeInIndex + 1 + isa + PBXFileReference + path + llex.c + sourceTree + <group> + + F537CDB34F31A64B346EBDC9E2C01266 + + fileRef + 9F1EDE358215935E8A9E0C0F9071DDE4 + isa + PBXBuildFile + + F56914674DA0AF1E6AC010FC7113D74C + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVDownloader.h + sourceTree + <group> + + F5941C112F5CD9BE394432513C70D6C2 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVCanvas.h + sourceTree + <group> + + F5A4CCD3902416405C0EFCC477645637 + + fileRef + 2D26AAA839209BDEB393111BD6B5AA9A + isa + PBXBuildFile + + F5A99BE1F5516A45976552D5A45A4564 + + fileRef + 29793D4CD0F70C98787EB90A858B866D + isa + PBXBuildFile + + F5D648D9050C305B35AD0620836F415A + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVHeads.m + sourceTree + <group> + + F5D694550B75896BDFFBCE6D00AFFBF2 + + fileRef + B89C6AFE954AA91D49330EC2B411725A + isa + PBXBuildFile + + F60FBACFD3EC9B82683CE17539F624A9 + + fileRef + 0337A51DB5994C8994C2A8DA56DC7F48 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + F6817491FA6EAAB7C1B3871DFCFD50CC + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVGrammarChanger.h + sourceTree + <group> + + F694A8D983FD70E8241E8FDE85ADC4E1 + + fileRef + 697F132F2DFCA6F7BD385E8B69106518 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + F6D0821B44AE3A9644B44DDFB2D983D0 + + fileRef + BDA86D0FD83C42AA566D217D2CD53E99 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + F6D49F1DBCF586CF4DD1C2308BEBFEC4 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVPanGesture.h + sourceTree + <group> + + F73C73AAE60625F8E1C29D731BC37FB4 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVNativeObjBox.m + sourceTree + <group> + + F78FBB2B2E733FFB239613964835C963 + + includeInIndex + 1 + isa + PBXFileReference + path + lvm.c + sourceTree + <group> + + F91B57533C10FED7ACC1CAFEC2A2988C + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVRefreshComponent.h + sourceTree + <group> + + F9321A44D9CCFD3BE6E5E6616A9C0245 + + fileRef + 5A28D175F6DF84855662E020BEF79988 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + F93D1A7E5BF9BE65D2C6925F102D15FE + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LuaViewCore.h + sourceTree + <group> + + F99BA1FA74A12DFF25DA5709B546F551 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVDB.m + sourceTree + <group> + + FA72E8189879480F7787E445A534EC41 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVDate.m + sourceTree + <group> + + FA9C85076DEB156BACB490133D4BA212 + + isa + PBXFileReference + lastKnownFileType + wrapper.framework + name + CoreGraphics.framework + path + Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.0.sdk/System/Library/Frameworks/CoreGraphics.framework + sourceTree + DEVELOPER_DIR + + FB1912F1A67413BD21D9073261B60344 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + lfunc.h + sourceTree + <group> + + FB1B8D87EDCFFB7AF23E12659B2ABEAC + + fileRef + A2BA69A9B7C5EECB89993DED249AF06E + isa + PBXBuildFile + + FB45FFD90572718D82AB9092B750F0CA + + buildSettings + + ALWAYS_SEARCH_USER_PATHS + NO + CLANG_CXX_LANGUAGE_STANDARD + gnu++0x + CLANG_CXX_LIBRARY + libc++ + CLANG_ENABLE_MODULES + YES + CLANG_ENABLE_OBJC_ARC + YES + CLANG_WARN_BOOL_CONVERSION + YES + CLANG_WARN_CONSTANT_CONVERSION + YES + CLANG_WARN_DIRECT_OBJC_ISA_USAGE + YES + CLANG_WARN_EMPTY_BODY + YES + CLANG_WARN_ENUM_CONVERSION + YES + CLANG_WARN_INT_CONVERSION + YES + CLANG_WARN_OBJC_ROOT_CLASS + YES + CLANG_WARN_UNREACHABLE_CODE + YES + CLANG_WARN__DUPLICATE_METHOD_MATCH + YES + COPY_PHASE_STRIP + YES + ENABLE_NS_ASSERTIONS + NO + GCC_C_LANGUAGE_STANDARD + gnu99 + GCC_PREPROCESSOR_DEFINITIONS + + RELEASE=1 + + GCC_WARN_64_TO_32_BIT_CONVERSION + YES + GCC_WARN_ABOUT_RETURN_TYPE + YES + GCC_WARN_UNDECLARED_SELECTOR + YES + GCC_WARN_UNINITIALIZED_AUTOS + YES + GCC_WARN_UNUSED_FUNCTION + YES + GCC_WARN_UNUSED_VARIABLE + YES + IPHONEOS_DEPLOYMENT_TARGET + 8.0 + STRIP_INSTALLED_PRODUCT + NO + SYMROOT + ${SRCROOT}/../build + VALIDATE_PRODUCT + YES + + isa + XCBuildConfiguration + name + Release + + FC0A35AACB219A49FA8BB55CBC659A79 + + buildActionMask + 2147483647 + files + + A0DECF9E223A7F117B5E3BBC24715C31 + F5A4CCD3902416405C0EFCC477645637 + 41794AAC220BE91DA5E4576ED92D886C + 321201220989F9A82975E3F33C5D3810 + 8605A604B36138B640EE777D884D8EB6 + 0B4274E3A6B1C5DA65EFA100AAA70ACE + + isa + PBXSourcesBuildPhase + runOnlyForDeploymentPostprocessing + 0 + + FC2A5EA8CF19876ACA547F5571BE8E47 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + MJRefreshBackGifFooter.m + path + MJRefresh/Custom/Footer/Back/MJRefreshBackGifFooter.m + sourceTree + <group> + + FDAE87F570F4B6B60ACA1DFC69C5336D + + children + + 13A7620016E596D02BD795846283AF3C + E3038A78003298A17C854ABA37E85170 + F93D1A7E5BF9BE65D2C6925F102D15FE + 2ACE817433802BA8E77DDB9B9EDC7AAE + 41F337BB92269F62AB427528FA16501B + 08957A35CBC7E56DF6CE78CBC5BF5B8C + ED61215E10852429E53E300EF5C0AC6B + 6B835B3B0A891FFF7F8C057FB52E6651 + 46B06AE59DEC7D9A99D69A95CBD3BC37 + 88D556157C0CA6FF501F0527A9048898 + D53480A24F0018010DEE441009153B07 + 80045B5072145A6462B7F17AD6038B57 + 5DE9729F0A95752FB7D28AB276EE6255 + 7D89A5849B6E33E1EAE67D09C73506C7 + DD824AE62915B7346D318977A5C4ED9C + 7474B8DDEE60A53040790F23FC92F3E0 + 608C5F501EBE6402D33CFF280E41BDED + + isa + PBXGroup + name + Classes + path + Classes + sourceTree + <group> + + FDB6110C621265090FE681745870492C + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVAnimator.h + sourceTree + <group> + + FDF43F1175E8CEF86FD60EE66B0C9901 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVToast.h + sourceTree + <group> + + FE6A6DAA9A53F4B822F21FC841180847 + + fileRef + 9452384A062A9CDEAD4042834DB6702A + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + FE97AE03D7376502147B56A323F0D285 + + children + + 298A6E76D4609E4DD748F7A0B5058A47 + + isa + PBXGroup + name + Assets + path + Assets + sourceTree + <group> + + FEC5A9842DD28C22DBD0D0B3CF60EB38 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVTapGesture.m + sourceTree + <group> + + FEC654FB4657F839ABBE23B2CBEFF577 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + UIScrollView+MJExtension.h + path + MJRefresh/UIScrollView+MJExtension.h + sourceTree + <group> + + FF20B0465ACB4DFBEEC97383ECCC6D49 + + fileRef + 25F8ABDD1532A296D8F95098E2E0A972 + isa + PBXBuildFile + + FFB85E30A4362FCC270FFBAC5A8B82D4 + + buildActionMask + 2147483647 + files + + C550E00E550ED1525E1242091AE7008F + + isa + PBXFrameworksBuildPhase + runOnlyForDeploymentPostprocessing + 0 + + + rootObject + D41D8CD98F00B204E9800998ECF8427E + + diff --git a/IOS/Playground/Pods/Pods.xcodeproj/xcshareddata/xcschemes/LuaViewSDK.xcscheme b/IOS/Playground/Pods/Pods.xcodeproj/xcshareddata/xcschemes/LuaViewSDK.xcscheme new file mode 100644 index 00000000..3eefd8c7 --- /dev/null +++ b/IOS/Playground/Pods/Pods.xcodeproj/xcshareddata/xcschemes/LuaViewSDK.xcscheme @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/IOS/Playground/Pods/Pods.xcodeproj/xcshareddata/xcschemes/lua.xcscheme b/IOS/Playground/Pods/Pods.xcodeproj/xcshareddata/xcschemes/lua.xcscheme new file mode 100644 index 00000000..a37d69e5 --- /dev/null +++ b/IOS/Playground/Pods/Pods.xcodeproj/xcshareddata/xcschemes/lua.xcscheme @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/IOS/Playground/Pods/Pods.xcodeproj/xcshareddata/xcschemes/luaviewEx.xcscheme b/IOS/Playground/Pods/Pods.xcodeproj/xcshareddata/xcschemes/luaviewEx.xcscheme new file mode 100644 index 00000000..4bcd6146 --- /dev/null +++ b/IOS/Playground/Pods/Pods.xcodeproj/xcshareddata/xcschemes/luaviewEx.xcscheme @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/IOS/Playground/Pods/SDWebImage/LICENSE b/IOS/Playground/Pods/SDWebImage/LICENSE new file mode 100644 index 00000000..810cf88a --- /dev/null +++ b/IOS/Playground/Pods/SDWebImage/LICENSE @@ -0,0 +1,20 @@ +Copyright (c) 2016 Olivier Poitrey rs@dailymotion.com + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished +to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + diff --git a/IOS/Playground/Pods/SDWebImage/README.md b/IOS/Playground/Pods/SDWebImage/README.md new file mode 100644 index 00000000..37771588 --- /dev/null +++ b/IOS/Playground/Pods/SDWebImage/README.md @@ -0,0 +1,334 @@ +Web Image +========= +[![Build Status](http://img.shields.io/travis/rs/SDWebImage/master.svg?style=flat)](https://travis-ci.org/rs/SDWebImage) +[![Pod Version](http://img.shields.io/cocoapods/v/SDWebImage.svg?style=flat)](http://cocoadocs.org/docsets/SDWebImage/) +[![Pod Platform](http://img.shields.io/cocoapods/p/SDWebImage.svg?style=flat)](http://cocoadocs.org/docsets/SDWebImage/) +[![Pod License](http://img.shields.io/cocoapods/l/SDWebImage.svg?style=flat)](https://www.apache.org/licenses/LICENSE-2.0.html) +[![Dependency Status](https://www.versioneye.com/objective-c/sdwebimage/3.3/badge.svg?style=flat)](https://www.versioneye.com/objective-c/sdwebimage/3.3) +[![Reference Status](https://www.versioneye.com/objective-c/sdwebimage/reference_badge.svg?style=flat)](https://www.versioneye.com/objective-c/sdwebimage/references) +[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/rs/SDWebImage) + +This library provides a category for UIImageView with support for remote images coming from the web. + +It provides: + +- An `UIImageView` category adding web image and cache management to the Cocoa Touch framework +- An asynchronous image downloader +- An asynchronous memory + disk image caching with automatic cache expiration handling +- Animated GIF support +- WebP format support +- A background image decompression +- A guarantee that the same URL won't be downloaded several times +- A guarantee that bogus URLs won't be retried again and again +- A guarantee that main thread will never be blocked +- Performances! +- Use GCD and ARC +- Arm64 support + +NOTE: The version 3.0 of SDWebImage isn't fully backward compatible with 2.0 and requires iOS 5.1.1 +minimum deployment version. If you need iOS < 5.0 support, please use the last [2.0 version](https://github.com/rs/SDWebImage/tree/2.0-compat). + +[How is SDWebImage better than X?](https://github.com/rs/SDWebImage/wiki/How-is-SDWebImage-better-than-X%3F) + +Who Uses It +---------- + +Find out [who uses SDWebImage](https://github.com/rs/SDWebImage/wiki/Who-Uses-SDWebImage) and add your app to the list. + +How To Use +---------- + +API documentation is available at [CocoaDocs - SDWebImage](http://cocoadocs.org/docsets/SDWebImage/) + +### Using UIImageView+WebCache category with UITableView + +Just #import the UIImageView+WebCache.h header, and call the sd_setImageWithURL:placeholderImage: +method from the tableView:cellForRowAtIndexPath: UITableViewDataSource method. Everything will be +handled for you, from async downloads to caching management. + +```objective-c +#import + +... + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { + static NSString *MyIdentifier = @"MyIdentifier"; + + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier]; + if (cell == nil) { + cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault + reuseIdentifier:MyIdentifier] autorelease]; + } + + // Here we use the new provided sd_setImageWithURL: method to load the web image + [cell.imageView sd_setImageWithURL:[NSURL URLWithString:@"http://www.domain.com/path/to/image.jpg"] + placeholderImage:[UIImage imageNamed:@"placeholder.png"]]; + + cell.textLabel.text = @"My Text"; + return cell; +} +``` + +### Using blocks + +With blocks, you can be notified about the image download progress and whenever the image retrieval +has completed with success or not: + +```objective-c +// Here we use the new provided sd_setImageWithURL: method to load the web image +[cell.imageView sd_setImageWithURL:[NSURL URLWithString:@"http://www.domain.com/path/to/image.jpg"] + placeholderImage:[UIImage imageNamed:@"placeholder.png"] + completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { + ... completion code here ... + }]; +``` + +Note: neither your success nor failure block will be call if your image request is canceled before completion. + +### Using SDWebImageManager + +The SDWebImageManager is the class behind the UIImageView+WebCache category. It ties the +asynchronous downloader with the image cache store. You can use this class directly to benefit +from web image downloading with caching in another context than a UIView (ie: with Cocoa). + +Here is a simple example of how to use SDWebImageManager: + +```objective-c +SDWebImageManager *manager = [SDWebImageManager sharedManager]; +[manager downloadImageWithURL:imageURL + options:0 + progress:^(NSInteger receivedSize, NSInteger expectedSize) { + // progression tracking code + } + completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { + if (image) { + // do something with image + } + }]; +``` + +### Using Asynchronous Image Downloader Independently + +It's also possible to use the async image downloader independently: + +```objective-c +SDWebImageDownloader *downloader = [SDWebImageDownloader sharedDownloader]; +[downloader downloadImageWithURL:imageURL + options:0 + progress:^(NSInteger receivedSize, NSInteger expectedSize) { + // progression tracking code + } + completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) { + if (image && finished) { + // do something with image + } + }]; +``` + +### Using Asynchronous Image Caching Independently + +It is also possible to use the async based image cache store independently. SDImageCache +maintains a memory cache and an optional disk cache. Disk cache write operations are performed +asynchronous so it doesn't add unnecessary latency to the UI. + +The SDImageCache class provides a singleton instance for convenience but you can create your own +instance if you want to create separated cache namespace. + +To lookup the cache, you use the `queryDiskCacheForKey:done:` method. If the method returns nil, it means the cache +doesn't currently own the image. You are thus responsible for generating and caching it. The cache +key is an application unique identifier for the image to cache. It is generally the absolute URL of +the image. + +```objective-c +SDImageCache *imageCache = [[SDImageCache alloc] initWithNamespace:@"myNamespace"]; +[imageCache queryDiskCacheForKey:myCacheKey done:^(UIImage *image) { + // image is not nil if image was found +}]; +``` + +By default SDImageCache will lookup the disk cache if an image can't be found in the memory cache. +You can prevent this from happening by calling the alternative method `imageFromMemoryCacheForKey:`. + +To store an image into the cache, you use the storeImage:forKey: method: + +```objective-c +[[SDImageCache sharedImageCache] storeImage:myImage forKey:myCacheKey]; +``` + +By default, the image will be stored in memory cache as well as on disk cache (asynchronously). If +you want only the memory cache, use the alternative method storeImage:forKey:toDisk: with a negative +third argument. + +### Using cache key filter + +Sometime, you may not want to use the image URL as cache key because part of the URL is dynamic +(i.e.: for access control purpose). SDWebImageManager provides a way to set a cache key filter that +takes the NSURL as input, and output a cache key NSString. + +The following example sets a filter in the application delegate that will remove any query-string from +the URL before to use it as a cache key: + +```objective-c +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + SDWebImageManager.sharedManager.cacheKeyFilter = ^(NSURL *url) { + url = [[NSURL alloc] initWithScheme:url.scheme host:url.host path:url.path]; + return [url absoluteString]; + }; + + // Your app init code... + return YES; +} +``` + + +Common Problems +--------------- + +### Using dynamic image size with UITableViewCell + +UITableView determines the size of the image by the first image set for a cell. If your remote images +don't have the same size as your placeholder image, you may experience strange anamorphic scaling issue. +The following article gives a way to workaround this issue: + +[http://www.wrichards.com/blog/2011/11/sdwebimage-fixed-width-cell-images/](http://www.wrichards.com/blog/2011/11/sdwebimage-fixed-width-cell-images/) + + +### Handle image refresh + +SDWebImage does very aggressive caching by default. It ignores all kind of caching control header returned by the HTTP server and cache the returned images with no time restriction. It implies your images URLs are static URLs pointing to images that never change. If the pointed image happen to change, some parts of the URL should change accordingly. + +If you don't control the image server you're using, you may not be able to change the URL when its content is updated. This is the case for Facebook avatar URLs for instance. In such case, you may use the `SDWebImageRefreshCached` flag. This will slightly degrade the performance but will respect the HTTP caching control headers: + +``` objective-c +[imageView sd_setImageWithURL:[NSURL URLWithString:@"https://graph.facebook.com/olivier.poitrey/picture"] + placeholderImage:[UIImage imageNamed:@"avatar-placeholder.png"] + options:SDWebImageRefreshCached]; +``` + +### Add a progress indicator + +See this category: https://github.com/JJSaccolo/UIActivityIndicator-for-SDWebImage + +Installation +------------ + +There are three ways to use SDWebImage in your project: +- using CocoaPods +- copying all the files into your project +- importing the project as a static library + +### Installation with CocoaPods + +[CocoaPods](http://cocoapods.org/) is a dependency manager for Objective-C, which automates and simplifies the process of using 3rd-party libraries in your projects. See the [Get Started](http://cocoapods.org/#get_started) section for more details. + +#### Podfile +``` +platform :ios, '6.1' +pod 'SDWebImage', '~>3.7' +``` + +If you are using Swift, be sure to add `use_frameworks!` and set your target to iOS 8+: +``` +platform :ios, '8.0' +use_frameworks! +``` + +#### Subspecs + +There are 3 subspecs available now: `Core`, `MapKit` and `WebP` (this means you can install only some of the SDWebImage modules. By default, you get just `Core`, so if you need `WebP`, you need to specify it). + +Podfile example: +``` +pod 'SDWebImage/WebP' +``` + +### Installation with Carthage (iOS 8+) + +[Carthage](https://github.com/Carthage/Carthage) is a lightweight dependency manager for Swift and Objective-C. It leverages CocoaTouch modules and is less invasive than CocoaPods. + +To install with carthage, follow the instruction on [Carthage](https://github.com/Carthage/Carthage) + +#### Cartfile +``` +github "rs/SDWebImage" +``` + +#### Usage +Swift + +If you installed using CocoaPods: +``` +import SDWebImage +``` + +If you installed manually: +``` +import WebImage +``` + +Objective-C + +``` +@import WebImage; +``` + +### Installation by cloning the repository + +In order to gain access to all the files from the repository, you should clone it. +``` +git clone --recursive https://github.com/rs/SDWebImage.git +``` + +### Add the SDWebImage project to your project + +- Download and unzip the last version of the framework from the [download page](https://github.com/rs/SDWebImage/releases) +- Right-click on the project navigator and select "Add Files to "Your Project": +- In the dialog, select SDWebImage.framework: +- Check the "Copy items into destination group's folder (if needed)" checkbox + +### Add dependencies + +- In you application project app’s target settings, find the "Build Phases" section and open the "Link Binary With Libraries" block: +- Click the "+" button again and select the "ImageIO.framework", this is needed by the progressive download feature: + +### Add Linker Flag + +Open the "Build Settings" tab, in the "Linking" section, locate the "Other Linker Flags" setting and add the "-ObjC" flag: + +![Other Linker Flags](http://dl.dropbox.com/u/123346/SDWebImage/10_other_linker_flags.jpg) + +Alternatively, if this causes compilation problems with frameworks that extend optional libraries, such as Parse, RestKit or opencv2, instead of the -ObjC flag use: +``` +-force_load SDWebImage.framework/Versions/Current/SDWebImage +``` + +If you're using Cocoa Pods and have any frameworks that extend optional libraries, such as Parsen RestKit or opencv2, instead of the -ObjC flag use: +``` +-force_load $(TARGET_BUILD_DIR)/libPods.a +``` +and this: +``` +$(inherited) +``` + +### Import headers in your source files + +In the source files where you need to use the library, import the header file: + +```objective-c +#import +``` + +### Build Project + +At this point your workspace should build without error. If you are having problem, post to the Issue and the +community can help you solve it. + +Future Enhancements +------------------- + +- LRU memory cache cleanup instead of reset on memory warning + +## Licenses + +All source code is licensed under the [MIT License](https://raw.github.com/rs/SDWebImage/master/LICENSE). diff --git a/IOS/Playground/Pods/SDWebImage/SDWebImage/NSData+ImageContentType.h b/IOS/Playground/Pods/SDWebImage/SDWebImage/NSData+ImageContentType.h new file mode 100644 index 00000000..69c76dc7 --- /dev/null +++ b/IOS/Playground/Pods/SDWebImage/SDWebImage/NSData+ImageContentType.h @@ -0,0 +1,26 @@ +// +// Created by Fabrice Aneche on 06/01/14. +// Copyright (c) 2014 Dailymotion. All rights reserved. +// + +#import + +@interface NSData (ImageContentType) + +/** + * Compute the content type for an image data + * + * @param data the input data + * + * @return the content type as string (i.e. image/jpeg, image/gif) + */ ++ (NSString *)sd_contentTypeForImageData:(NSData *)data; + +@end + + +@interface NSData (ImageContentTypeDeprecated) + ++ (NSString *)contentTypeForImageData:(NSData *)data __deprecated_msg("Use `sd_contentTypeForImageData:`"); + +@end diff --git a/IOS/Playground/Pods/SDWebImage/SDWebImage/NSData+ImageContentType.m b/IOS/Playground/Pods/SDWebImage/SDWebImage/NSData+ImageContentType.m new file mode 100644 index 00000000..0941cfaa --- /dev/null +++ b/IOS/Playground/Pods/SDWebImage/SDWebImage/NSData+ImageContentType.m @@ -0,0 +1,49 @@ +// +// Created by Fabrice Aneche on 06/01/14. +// Copyright (c) 2014 Dailymotion. All rights reserved. +// + +#import "NSData+ImageContentType.h" + + +@implementation NSData (ImageContentType) + ++ (NSString *)sd_contentTypeForImageData:(NSData *)data { + uint8_t c; + [data getBytes:&c length:1]; + switch (c) { + case 0xFF: + return @"image/jpeg"; + case 0x89: + return @"image/png"; + case 0x47: + return @"image/gif"; + case 0x49: + case 0x4D: + return @"image/tiff"; + case 0x52: + // R as RIFF for WEBP + if ([data length] < 12) { + return nil; + } + + NSString *testString = [[NSString alloc] initWithData:[data subdataWithRange:NSMakeRange(0, 12)] encoding:NSASCIIStringEncoding]; + if ([testString hasPrefix:@"RIFF"] && [testString hasSuffix:@"WEBP"]) { + return @"image/webp"; + } + + return nil; + } + return nil; +} + +@end + + +@implementation NSData (ImageContentTypeDeprecated) + ++ (NSString *)contentTypeForImageData:(NSData *)data { + return [self sd_contentTypeForImageData:data]; +} + +@end diff --git a/IOS/Playground/Pods/SDWebImage/SDWebImage/SDImageCache.h b/IOS/Playground/Pods/SDWebImage/SDWebImage/SDImageCache.h new file mode 100644 index 00000000..6704541e --- /dev/null +++ b/IOS/Playground/Pods/SDWebImage/SDWebImage/SDImageCache.h @@ -0,0 +1,280 @@ +/* + * This file is part of the SDWebImage package. + * (c) Olivier Poitrey + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +#import +#import "SDWebImageCompat.h" + +typedef NS_ENUM(NSInteger, SDImageCacheType) { + /** + * The image wasn't available the SDWebImage caches, but was downloaded from the web. + */ + SDImageCacheTypeNone, + /** + * The image was obtained from the disk cache. + */ + SDImageCacheTypeDisk, + /** + * The image was obtained from the memory cache. + */ + SDImageCacheTypeMemory +}; + +typedef void(^SDWebImageQueryCompletedBlock)(UIImage *image, SDImageCacheType cacheType); + +typedef void(^SDWebImageCheckCacheCompletionBlock)(BOOL isInCache); + +typedef void(^SDWebImageCalculateSizeBlock)(NSUInteger fileCount, NSUInteger totalSize); + +/** + * SDImageCache maintains a memory cache and an optional disk cache. Disk cache write operations are performed + * asynchronous so it doesn’t add unnecessary latency to the UI. + */ +@interface SDImageCache : NSObject + +/** + * Decompressing images that are downloaded and cached can improve performance but can consume lot of memory. + * Defaults to YES. Set this to NO if you are experiencing a crash due to excessive memory consumption. + */ +@property (assign, nonatomic) BOOL shouldDecompressImages; + +/** + * disable iCloud backup [defaults to YES] + */ +@property (assign, nonatomic) BOOL shouldDisableiCloud; + +/** + * use memory cache [defaults to YES] + */ +@property (assign, nonatomic) BOOL shouldCacheImagesInMemory; + +/** + * The maximum "total cost" of the in-memory image cache. The cost function is the number of pixels held in memory. + */ +@property (assign, nonatomic) NSUInteger maxMemoryCost; + +/** + * The maximum number of objects the cache should hold. + */ +@property (assign, nonatomic) NSUInteger maxMemoryCountLimit; + +/** + * The maximum length of time to keep an image in the cache, in seconds + */ +@property (assign, nonatomic) NSInteger maxCacheAge; + +/** + * The maximum size of the cache, in bytes. + */ +@property (assign, nonatomic) NSUInteger maxCacheSize; + +/** + * Returns global shared cache instance + * + * @return SDImageCache global instance + */ ++ (SDImageCache *)sharedImageCache; + +/** + * Init a new cache store with a specific namespace + * + * @param ns The namespace to use for this cache store + */ +- (id)initWithNamespace:(NSString *)ns; + +/** + * Init a new cache store with a specific namespace and directory + * + * @param ns The namespace to use for this cache store + * @param directory Directory to cache disk images in + */ +- (id)initWithNamespace:(NSString *)ns diskCacheDirectory:(NSString *)directory; + +-(NSString *)makeDiskCachePath:(NSString*)fullNamespace; + +/** + * Add a read-only cache path to search for images pre-cached by SDImageCache + * Useful if you want to bundle pre-loaded images with your app + * + * @param path The path to use for this read-only cache path + */ +- (void)addReadOnlyCachePath:(NSString *)path; + +/** + * Store an image into memory and disk cache at the given key. + * + * @param image The image to store + * @param key The unique image cache key, usually it's image absolute URL + */ +- (void)storeImage:(UIImage *)image forKey:(NSString *)key; + +/** + * Store an image into memory and optionally disk cache at the given key. + * + * @param image The image to store + * @param key The unique image cache key, usually it's image absolute URL + * @param toDisk Store the image to disk cache if YES + */ +- (void)storeImage:(UIImage *)image forKey:(NSString *)key toDisk:(BOOL)toDisk; + +/** + * Store an image into memory and optionally disk cache at the given key. + * + * @param image The image to store + * @param recalculate BOOL indicates if imageData can be used or a new data should be constructed from the UIImage + * @param imageData The image data as returned by the server, this representation will be used for disk storage + * instead of converting the given image object into a storable/compressed image format in order + * to save quality and CPU + * @param key The unique image cache key, usually it's image absolute URL + * @param toDisk Store the image to disk cache if YES + */ +- (void)storeImage:(UIImage *)image recalculateFromImage:(BOOL)recalculate imageData:(NSData *)imageData forKey:(NSString *)key toDisk:(BOOL)toDisk; + +/** + * Store image NSData into disk cache at the given key. + * + * @param imageData The image data to store + * @param key The unique image cache key, usually it's image absolute URL + */ +- (void)storeImageDataToDisk:(NSData *)imageData forKey:(NSString *)key; + +/** + * Query the disk cache asynchronously. + * + * @param key The unique key used to store the wanted image + */ +- (NSOperation *)queryDiskCacheForKey:(NSString *)key done:(SDWebImageQueryCompletedBlock)doneBlock; + +/** + * Query the memory cache synchronously. + * + * @param key The unique key used to store the wanted image + */ +- (UIImage *)imageFromMemoryCacheForKey:(NSString *)key; + +/** + * Query the disk cache synchronously after checking the memory cache. + * + * @param key The unique key used to store the wanted image + */ +- (UIImage *)imageFromDiskCacheForKey:(NSString *)key; + +/** + * Remove the image from memory and disk cache synchronously + * + * @param key The unique image cache key + */ +- (void)removeImageForKey:(NSString *)key; + + +/** + * Remove the image from memory and disk cache asynchronously + * + * @param key The unique image cache key + * @param completion An block that should be executed after the image has been removed (optional) + */ +- (void)removeImageForKey:(NSString *)key withCompletion:(SDWebImageNoParamsBlock)completion; + +/** + * Remove the image from memory and optionally disk cache asynchronously + * + * @param key The unique image cache key + * @param fromDisk Also remove cache entry from disk if YES + */ +- (void)removeImageForKey:(NSString *)key fromDisk:(BOOL)fromDisk; + +/** + * Remove the image from memory and optionally disk cache asynchronously + * + * @param key The unique image cache key + * @param fromDisk Also remove cache entry from disk if YES + * @param completion An block that should be executed after the image has been removed (optional) + */ +- (void)removeImageForKey:(NSString *)key fromDisk:(BOOL)fromDisk withCompletion:(SDWebImageNoParamsBlock)completion; + +/** + * Clear all memory cached images + */ +- (void)clearMemory; + +/** + * Clear all disk cached images. Non-blocking method - returns immediately. + * @param completion An block that should be executed after cache expiration completes (optional) + */ +- (void)clearDiskOnCompletion:(SDWebImageNoParamsBlock)completion; + +/** + * Clear all disk cached images + * @see clearDiskOnCompletion: + */ +- (void)clearDisk; + +/** + * Remove all expired cached image from disk. Non-blocking method - returns immediately. + * @param completionBlock An block that should be executed after cache expiration completes (optional) + */ +- (void)cleanDiskWithCompletionBlock:(SDWebImageNoParamsBlock)completionBlock; + +/** + * Remove all expired cached image from disk + * @see cleanDiskWithCompletionBlock: + */ +- (void)cleanDisk; + +/** + * Get the size used by the disk cache + */ +- (NSUInteger)getSize; + +/** + * Get the number of images in the disk cache + */ +- (NSUInteger)getDiskCount; + +/** + * Asynchronously calculate the disk cache's size. + */ +- (void)calculateSizeWithCompletionBlock:(SDWebImageCalculateSizeBlock)completionBlock; + +/** + * Async check if image exists in disk cache already (does not load the image) + * + * @param key the key describing the url + * @param completionBlock the block to be executed when the check is done. + * @note the completion block will be always executed on the main queue + */ +- (void)diskImageExistsWithKey:(NSString *)key completion:(SDWebImageCheckCacheCompletionBlock)completionBlock; + +/** + * Check if image exists in disk cache already (does not load the image) + * + * @param key the key describing the url + * + * @return YES if an image exists for the given key + */ +- (BOOL)diskImageExistsWithKey:(NSString *)key; + +/** + * Get the cache path for a certain key (needs the cache path root folder) + * + * @param key the key (can be obtained from url using cacheKeyForURL) + * @param path the cache path root folder + * + * @return the cache path + */ +- (NSString *)cachePathForKey:(NSString *)key inPath:(NSString *)path; + +/** + * Get the default cache path for a certain key + * + * @param key the key (can be obtained from url using cacheKeyForURL) + * + * @return the default cache path + */ +- (NSString *)defaultCachePathForKey:(NSString *)key; + +@end diff --git a/IOS/Playground/Pods/SDWebImage/SDWebImage/SDImageCache.m b/IOS/Playground/Pods/SDWebImage/SDWebImage/SDImageCache.m new file mode 100644 index 00000000..fe244824 --- /dev/null +++ b/IOS/Playground/Pods/SDWebImage/SDWebImage/SDImageCache.m @@ -0,0 +1,657 @@ +/* + * This file is part of the SDWebImage package. + * (c) Olivier Poitrey + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +#import "SDImageCache.h" +#import "SDWebImageDecoder.h" +#import "UIImage+MultiFormat.h" +#import + +// See https://github.com/rs/SDWebImage/pull/1141 for discussion +@interface AutoPurgeCache : NSCache +@end + +@implementation AutoPurgeCache + +- (id)init +{ + self = [super init]; + if (self) { + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(removeAllObjects) name:UIApplicationDidReceiveMemoryWarningNotification object:nil]; + } + return self; +} + +- (void)dealloc +{ + [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidReceiveMemoryWarningNotification object:nil]; + +} + +@end + +static const NSInteger kDefaultCacheMaxCacheAge = 60 * 60 * 24 * 7; // 1 week +// PNG signature bytes and data (below) +static unsigned char kPNGSignatureBytes[8] = {0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A}; +static NSData *kPNGSignatureData = nil; + +BOOL ImageDataHasPNGPreffix(NSData *data); + +BOOL ImageDataHasPNGPreffix(NSData *data) { + NSUInteger pngSignatureLength = [kPNGSignatureData length]; + if ([data length] >= pngSignatureLength) { + if ([[data subdataWithRange:NSMakeRange(0, pngSignatureLength)] isEqualToData:kPNGSignatureData]) { + return YES; + } + } + + return NO; +} + +FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { + return image.size.height * image.size.width * image.scale * image.scale; +} + +@interface SDImageCache () + +@property (strong, nonatomic) NSCache *memCache; +@property (strong, nonatomic) NSString *diskCachePath; +@property (strong, nonatomic) NSMutableArray *customPaths; +@property (SDDispatchQueueSetterSementics, nonatomic) dispatch_queue_t ioQueue; + +@end + + +@implementation SDImageCache { + NSFileManager *_fileManager; +} + ++ (SDImageCache *)sharedImageCache { + static dispatch_once_t once; + static id instance; + dispatch_once(&once, ^{ + instance = [self new]; + }); + return instance; +} + +- (id)init { + return [self initWithNamespace:@"default"]; +} + +- (id)initWithNamespace:(NSString *)ns { + NSString *path = [self makeDiskCachePath:ns]; + return [self initWithNamespace:ns diskCacheDirectory:path]; +} + +- (id)initWithNamespace:(NSString *)ns diskCacheDirectory:(NSString *)directory { + if ((self = [super init])) { + NSString *fullNamespace = [@"com.hackemist.SDWebImageCache." stringByAppendingString:ns]; + + // initialise PNG signature data + kPNGSignatureData = [NSData dataWithBytes:kPNGSignatureBytes length:8]; + + // Create IO serial queue + _ioQueue = dispatch_queue_create("com.hackemist.SDWebImageCache", DISPATCH_QUEUE_SERIAL); + + // Init default values + _maxCacheAge = kDefaultCacheMaxCacheAge; + + // Init the memory cache + _memCache = [[AutoPurgeCache alloc] init]; + _memCache.name = fullNamespace; + + // Init the disk cache + if (directory != nil) { + _diskCachePath = [directory stringByAppendingPathComponent:fullNamespace]; + } else { + NSString *path = [self makeDiskCachePath:ns]; + _diskCachePath = path; + } + + // Set decompression to YES + _shouldDecompressImages = YES; + + // memory cache enabled + _shouldCacheImagesInMemory = YES; + + // Disable iCloud + _shouldDisableiCloud = YES; + + dispatch_sync(_ioQueue, ^{ + _fileManager = [NSFileManager new]; + }); + +#if TARGET_OS_IOS + // Subscribe to app events + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(clearMemory) + name:UIApplicationDidReceiveMemoryWarningNotification + object:nil]; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(cleanDisk) + name:UIApplicationWillTerminateNotification + object:nil]; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(backgroundCleanDisk) + name:UIApplicationDidEnterBackgroundNotification + object:nil]; +#endif + } + + return self; +} + +- (void)dealloc { + [[NSNotificationCenter defaultCenter] removeObserver:self]; + SDDispatchQueueRelease(_ioQueue); +} + +- (void)addReadOnlyCachePath:(NSString *)path { + if (!self.customPaths) { + self.customPaths = [NSMutableArray new]; + } + + if (![self.customPaths containsObject:path]) { + [self.customPaths addObject:path]; + } +} + +- (NSString *)cachePathForKey:(NSString *)key inPath:(NSString *)path { + NSString *filename = [self cachedFileNameForKey:key]; + return [path stringByAppendingPathComponent:filename]; +} + +- (NSString *)defaultCachePathForKey:(NSString *)key { + return [self cachePathForKey:key inPath:self.diskCachePath]; +} + +#pragma mark SDImageCache (private) + +- (NSString *)cachedFileNameForKey:(NSString *)key { + const char *str = [key UTF8String]; + if (str == NULL) { + str = ""; + } + unsigned char r[CC_MD5_DIGEST_LENGTH]; + CC_MD5(str, (CC_LONG)strlen(str), r); + NSString *filename = [NSString stringWithFormat:@"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%@", + r[0], r[1], r[2], r[3], r[4], r[5], r[6], r[7], r[8], r[9], r[10], + r[11], r[12], r[13], r[14], r[15], [[key pathExtension] isEqualToString:@""] ? @"" : [NSString stringWithFormat:@".%@", [key pathExtension]]]; + + return filename; +} + +#pragma mark ImageCache + +// Init the disk cache +-(NSString *)makeDiskCachePath:(NSString*)fullNamespace{ + NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); + return [paths[0] stringByAppendingPathComponent:fullNamespace]; +} + +- (void)storeImage:(UIImage *)image recalculateFromImage:(BOOL)recalculate imageData:(NSData *)imageData forKey:(NSString *)key toDisk:(BOOL)toDisk { + if (!image || !key) { + return; + } + // if memory cache is enabled + if (self.shouldCacheImagesInMemory) { + NSUInteger cost = SDCacheCostForImage(image); + [self.memCache setObject:image forKey:key cost:cost]; + } + + if (toDisk) { + dispatch_async(self.ioQueue, ^{ + NSData *data = imageData; + + if (image && (recalculate || !data)) { +#if TARGET_OS_IPHONE + // We need to determine if the image is a PNG or a JPEG + // PNGs are easier to detect because they have a unique signature (http://www.w3.org/TR/PNG-Structure.html) + // The first eight bytes of a PNG file always contain the following (decimal) values: + // 137 80 78 71 13 10 26 10 + + // If the imageData is nil (i.e. if trying to save a UIImage directly or the image was transformed on download) + // and the image has an alpha channel, we will consider it PNG to avoid losing the transparency + int alphaInfo = CGImageGetAlphaInfo(image.CGImage); + BOOL hasAlpha = !(alphaInfo == kCGImageAlphaNone || + alphaInfo == kCGImageAlphaNoneSkipFirst || + alphaInfo == kCGImageAlphaNoneSkipLast); + BOOL imageIsPng = hasAlpha; + + // But if we have an image data, we will look at the preffix + if ([imageData length] >= [kPNGSignatureData length]) { + imageIsPng = ImageDataHasPNGPreffix(imageData); + } + + if (imageIsPng) { + data = UIImagePNGRepresentation(image); + } + else { + data = UIImageJPEGRepresentation(image, (CGFloat)1.0); + } +#else + data = [NSBitmapImageRep representationOfImageRepsInArray:image.representations usingType: NSJPEGFileType properties:nil]; +#endif + } + + [self storeImageDataToDisk:data forKey:key]; + }); + } +} + +- (void)storeImage:(UIImage *)image forKey:(NSString *)key { + [self storeImage:image recalculateFromImage:YES imageData:nil forKey:key toDisk:YES]; +} + +- (void)storeImage:(UIImage *)image forKey:(NSString *)key toDisk:(BOOL)toDisk { + [self storeImage:image recalculateFromImage:YES imageData:nil forKey:key toDisk:toDisk]; +} + +- (void)storeImageDataToDisk:(NSData *)imageData forKey:(NSString *)key { + + if (!imageData) { + return; + } + + if (![_fileManager fileExistsAtPath:_diskCachePath]) { + [_fileManager createDirectoryAtPath:_diskCachePath withIntermediateDirectories:YES attributes:nil error:NULL]; + } + + // get cache Path for image key + NSString *cachePathForKey = [self defaultCachePathForKey:key]; + // transform to NSUrl + NSURL *fileURL = [NSURL fileURLWithPath:cachePathForKey]; + + [_fileManager createFileAtPath:cachePathForKey contents:imageData attributes:nil]; + + // disable iCloud backup + if (self.shouldDisableiCloud) { + [fileURL setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:nil]; + } +} + +- (BOOL)diskImageExistsWithKey:(NSString *)key { + BOOL exists = NO; + + // this is an exception to access the filemanager on another queue than ioQueue, but we are using the shared instance + // from apple docs on NSFileManager: The methods of the shared NSFileManager object can be called from multiple threads safely. + exists = [[NSFileManager defaultManager] fileExistsAtPath:[self defaultCachePathForKey:key]]; + + // fallback because of https://github.com/rs/SDWebImage/pull/976 that added the extension to the disk file name + // checking the key with and without the extension + if (!exists) { + exists = [[NSFileManager defaultManager] fileExistsAtPath:[[self defaultCachePathForKey:key] stringByDeletingPathExtension]]; + } + + return exists; +} + +- (void)diskImageExistsWithKey:(NSString *)key completion:(SDWebImageCheckCacheCompletionBlock)completionBlock { + dispatch_async(_ioQueue, ^{ + BOOL exists = [_fileManager fileExistsAtPath:[self defaultCachePathForKey:key]]; + + // fallback because of https://github.com/rs/SDWebImage/pull/976 that added the extension to the disk file name + // checking the key with and without the extension + if (!exists) { + exists = [_fileManager fileExistsAtPath:[[self defaultCachePathForKey:key] stringByDeletingPathExtension]]; + } + + if (completionBlock) { + dispatch_async(dispatch_get_main_queue(), ^{ + completionBlock(exists); + }); + } + }); +} + +- (UIImage *)imageFromMemoryCacheForKey:(NSString *)key { + return [self.memCache objectForKey:key]; +} + +- (UIImage *)imageFromDiskCacheForKey:(NSString *)key { + + // First check the in-memory cache... + UIImage *image = [self imageFromMemoryCacheForKey:key]; + if (image) { + return image; + } + + // Second check the disk cache... + UIImage *diskImage = [self diskImageForKey:key]; + if (diskImage && self.shouldCacheImagesInMemory) { + NSUInteger cost = SDCacheCostForImage(diskImage); + [self.memCache setObject:diskImage forKey:key cost:cost]; + } + + return diskImage; +} + +- (NSData *)diskImageDataBySearchingAllPathsForKey:(NSString *)key { + NSString *defaultPath = [self defaultCachePathForKey:key]; + NSData *data = [NSData dataWithContentsOfFile:defaultPath]; + if (data) { + return data; + } + + // fallback because of https://github.com/rs/SDWebImage/pull/976 that added the extension to the disk file name + // checking the key with and without the extension + data = [NSData dataWithContentsOfFile:[defaultPath stringByDeletingPathExtension]]; + if (data) { + return data; + } + + NSArray *customPaths = [self.customPaths copy]; + for (NSString *path in customPaths) { + NSString *filePath = [self cachePathForKey:key inPath:path]; + NSData *imageData = [NSData dataWithContentsOfFile:filePath]; + if (imageData) { + return imageData; + } + + // fallback because of https://github.com/rs/SDWebImage/pull/976 that added the extension to the disk file name + // checking the key with and without the extension + imageData = [NSData dataWithContentsOfFile:[filePath stringByDeletingPathExtension]]; + if (imageData) { + return imageData; + } + } + + return nil; +} + +- (UIImage *)diskImageForKey:(NSString *)key { + NSData *data = [self diskImageDataBySearchingAllPathsForKey:key]; + if (data) { + UIImage *image = [UIImage sd_imageWithData:data]; + image = [self scaledImageForKey:key image:image]; + if (self.shouldDecompressImages) { + image = [UIImage decodedImageWithImage:image]; + } + return image; + } + else { + return nil; + } +} + +- (UIImage *)scaledImageForKey:(NSString *)key image:(UIImage *)image { + return SDScaledImageForKey(key, image); +} + +- (NSOperation *)queryDiskCacheForKey:(NSString *)key done:(SDWebImageQueryCompletedBlock)doneBlock { + if (!doneBlock) { + return nil; + } + + if (!key) { + doneBlock(nil, SDImageCacheTypeNone); + return nil; + } + + // First check the in-memory cache... + UIImage *image = [self imageFromMemoryCacheForKey:key]; + if (image) { + doneBlock(image, SDImageCacheTypeMemory); + return nil; + } + + NSOperation *operation = [NSOperation new]; + dispatch_async(self.ioQueue, ^{ + if (operation.isCancelled) { + return; + } + + @autoreleasepool { + UIImage *diskImage = [self diskImageForKey:key]; + if (diskImage && self.shouldCacheImagesInMemory) { + NSUInteger cost = SDCacheCostForImage(diskImage); + [self.memCache setObject:diskImage forKey:key cost:cost]; + } + + dispatch_async(dispatch_get_main_queue(), ^{ + doneBlock(diskImage, SDImageCacheTypeDisk); + }); + } + }); + + return operation; +} + +- (void)removeImageForKey:(NSString *)key { + [self removeImageForKey:key withCompletion:nil]; +} + +- (void)removeImageForKey:(NSString *)key withCompletion:(SDWebImageNoParamsBlock)completion { + [self removeImageForKey:key fromDisk:YES withCompletion:completion]; +} + +- (void)removeImageForKey:(NSString *)key fromDisk:(BOOL)fromDisk { + [self removeImageForKey:key fromDisk:fromDisk withCompletion:nil]; +} + +- (void)removeImageForKey:(NSString *)key fromDisk:(BOOL)fromDisk withCompletion:(SDWebImageNoParamsBlock)completion { + + if (key == nil) { + return; + } + + if (self.shouldCacheImagesInMemory) { + [self.memCache removeObjectForKey:key]; + } + + if (fromDisk) { + dispatch_async(self.ioQueue, ^{ + [_fileManager removeItemAtPath:[self defaultCachePathForKey:key] error:nil]; + + if (completion) { + dispatch_async(dispatch_get_main_queue(), ^{ + completion(); + }); + } + }); + } else if (completion){ + completion(); + } + +} + +- (void)setMaxMemoryCost:(NSUInteger)maxMemoryCost { + self.memCache.totalCostLimit = maxMemoryCost; +} + +- (NSUInteger)maxMemoryCost { + return self.memCache.totalCostLimit; +} + +- (NSUInteger)maxMemoryCountLimit { + return self.memCache.countLimit; +} + +- (void)setMaxMemoryCountLimit:(NSUInteger)maxCountLimit { + self.memCache.countLimit = maxCountLimit; +} + +- (void)clearMemory { + [self.memCache removeAllObjects]; +} + +- (void)clearDisk { + [self clearDiskOnCompletion:nil]; +} + +- (void)clearDiskOnCompletion:(SDWebImageNoParamsBlock)completion +{ + dispatch_async(self.ioQueue, ^{ + [_fileManager removeItemAtPath:self.diskCachePath error:nil]; + [_fileManager createDirectoryAtPath:self.diskCachePath + withIntermediateDirectories:YES + attributes:nil + error:NULL]; + + if (completion) { + dispatch_async(dispatch_get_main_queue(), ^{ + completion(); + }); + } + }); +} + +- (void)cleanDisk { + [self cleanDiskWithCompletionBlock:nil]; +} + +- (void)cleanDiskWithCompletionBlock:(SDWebImageNoParamsBlock)completionBlock { + dispatch_async(self.ioQueue, ^{ + NSURL *diskCacheURL = [NSURL fileURLWithPath:self.diskCachePath isDirectory:YES]; + NSArray *resourceKeys = @[NSURLIsDirectoryKey, NSURLContentModificationDateKey, NSURLTotalFileAllocatedSizeKey]; + + // This enumerator prefetches useful properties for our cache files. + NSDirectoryEnumerator *fileEnumerator = [_fileManager enumeratorAtURL:diskCacheURL + includingPropertiesForKeys:resourceKeys + options:NSDirectoryEnumerationSkipsHiddenFiles + errorHandler:NULL]; + + NSDate *expirationDate = [NSDate dateWithTimeIntervalSinceNow:-self.maxCacheAge]; + NSMutableDictionary *cacheFiles = [NSMutableDictionary dictionary]; + NSUInteger currentCacheSize = 0; + + // Enumerate all of the files in the cache directory. This loop has two purposes: + // + // 1. Removing files that are older than the expiration date. + // 2. Storing file attributes for the size-based cleanup pass. + NSMutableArray *urlsToDelete = [[NSMutableArray alloc] init]; + for (NSURL *fileURL in fileEnumerator) { + NSDictionary *resourceValues = [fileURL resourceValuesForKeys:resourceKeys error:NULL]; + + // Skip directories. + if ([resourceValues[NSURLIsDirectoryKey] boolValue]) { + continue; + } + + // Remove files that are older than the expiration date; + NSDate *modificationDate = resourceValues[NSURLContentModificationDateKey]; + if ([[modificationDate laterDate:expirationDate] isEqualToDate:expirationDate]) { + [urlsToDelete addObject:fileURL]; + continue; + } + + // Store a reference to this file and account for its total size. + NSNumber *totalAllocatedSize = resourceValues[NSURLTotalFileAllocatedSizeKey]; + currentCacheSize += [totalAllocatedSize unsignedIntegerValue]; + [cacheFiles setObject:resourceValues forKey:fileURL]; + } + + for (NSURL *fileURL in urlsToDelete) { + [_fileManager removeItemAtURL:fileURL error:nil]; + } + + // If our remaining disk cache exceeds a configured maximum size, perform a second + // size-based cleanup pass. We delete the oldest files first. + if (self.maxCacheSize > 0 && currentCacheSize > self.maxCacheSize) { + // Target half of our maximum cache size for this cleanup pass. + const NSUInteger desiredCacheSize = self.maxCacheSize / 2; + + // Sort the remaining cache files by their last modification time (oldest first). + NSArray *sortedFiles = [cacheFiles keysSortedByValueWithOptions:NSSortConcurrent + usingComparator:^NSComparisonResult(id obj1, id obj2) { + return [obj1[NSURLContentModificationDateKey] compare:obj2[NSURLContentModificationDateKey]]; + }]; + + // Delete files until we fall below our desired cache size. + for (NSURL *fileURL in sortedFiles) { + if ([_fileManager removeItemAtURL:fileURL error:nil]) { + NSDictionary *resourceValues = cacheFiles[fileURL]; + NSNumber *totalAllocatedSize = resourceValues[NSURLTotalFileAllocatedSizeKey]; + currentCacheSize -= [totalAllocatedSize unsignedIntegerValue]; + + if (currentCacheSize < desiredCacheSize) { + break; + } + } + } + } + if (completionBlock) { + dispatch_async(dispatch_get_main_queue(), ^{ + completionBlock(); + }); + } + }); +} + +- (void)backgroundCleanDisk { + Class UIApplicationClass = NSClassFromString(@"UIApplication"); + if(!UIApplicationClass || ![UIApplicationClass respondsToSelector:@selector(sharedApplication)]) { + return; + } + UIApplication *application = [UIApplication performSelector:@selector(sharedApplication)]; + __block UIBackgroundTaskIdentifier bgTask = [application beginBackgroundTaskWithExpirationHandler:^{ + // Clean up any unfinished task business by marking where you + // stopped or ending the task outright. + [application endBackgroundTask:bgTask]; + bgTask = UIBackgroundTaskInvalid; + }]; + + // Start the long-running task and return immediately. + [self cleanDiskWithCompletionBlock:^{ + [application endBackgroundTask:bgTask]; + bgTask = UIBackgroundTaskInvalid; + }]; +} + +- (NSUInteger)getSize { + __block NSUInteger size = 0; + dispatch_sync(self.ioQueue, ^{ + NSDirectoryEnumerator *fileEnumerator = [_fileManager enumeratorAtPath:self.diskCachePath]; + for (NSString *fileName in fileEnumerator) { + NSString *filePath = [self.diskCachePath stringByAppendingPathComponent:fileName]; + NSDictionary *attrs = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:nil]; + size += [attrs fileSize]; + } + }); + return size; +} + +- (NSUInteger)getDiskCount { + __block NSUInteger count = 0; + dispatch_sync(self.ioQueue, ^{ + NSDirectoryEnumerator *fileEnumerator = [_fileManager enumeratorAtPath:self.diskCachePath]; + count = [[fileEnumerator allObjects] count]; + }); + return count; +} + +- (void)calculateSizeWithCompletionBlock:(SDWebImageCalculateSizeBlock)completionBlock { + NSURL *diskCacheURL = [NSURL fileURLWithPath:self.diskCachePath isDirectory:YES]; + + dispatch_async(self.ioQueue, ^{ + NSUInteger fileCount = 0; + NSUInteger totalSize = 0; + + NSDirectoryEnumerator *fileEnumerator = [_fileManager enumeratorAtURL:diskCacheURL + includingPropertiesForKeys:@[NSFileSize] + options:NSDirectoryEnumerationSkipsHiddenFiles + errorHandler:NULL]; + + for (NSURL *fileURL in fileEnumerator) { + NSNumber *fileSize; + [fileURL getResourceValue:&fileSize forKey:NSURLFileSizeKey error:NULL]; + totalSize += [fileSize unsignedIntegerValue]; + fileCount += 1; + } + + if (completionBlock) { + dispatch_async(dispatch_get_main_queue(), ^{ + completionBlock(fileCount, totalSize); + }); + } + }); +} + +@end diff --git a/IOS/Playground/Pods/SDWebImage/SDWebImage/SDWebImageCompat.h b/IOS/Playground/Pods/SDWebImage/SDWebImage/SDWebImageCompat.h new file mode 100644 index 00000000..3c21b413 --- /dev/null +++ b/IOS/Playground/Pods/SDWebImage/SDWebImage/SDWebImageCompat.h @@ -0,0 +1,72 @@ +/* + * This file is part of the SDWebImage package. + * (c) Olivier Poitrey + * (c) Jamie Pinkham + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +#import + +#ifdef __OBJC_GC__ +#error SDWebImage does not support Objective-C Garbage Collection +#endif + +#if __IPHONE_OS_VERSION_MIN_REQUIRED != 20000 && __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_5_0 +#error SDWebImage doesn't support Deployment Target version < 5.0 +#endif + +#if !TARGET_OS_IPHONE +#import +#ifndef UIImage +#define UIImage NSImage +#endif +#ifndef UIImageView +#define UIImageView NSImageView +#endif +#else + +#import + +#endif + +#ifndef NS_ENUM +#define NS_ENUM(_type, _name) enum _name : _type _name; enum _name : _type +#endif + +#ifndef NS_OPTIONS +#define NS_OPTIONS(_type, _name) enum _name : _type _name; enum _name : _type +#endif + +#if OS_OBJECT_USE_OBJC + #undef SDDispatchQueueRelease + #undef SDDispatchQueueSetterSementics + #define SDDispatchQueueRelease(q) + #define SDDispatchQueueSetterSementics strong +#else +#undef SDDispatchQueueRelease +#undef SDDispatchQueueSetterSementics +#define SDDispatchQueueRelease(q) (dispatch_release(q)) +#define SDDispatchQueueSetterSementics assign +#endif + +extern UIImage *SDScaledImageForKey(NSString *key, UIImage *image); + +typedef void(^SDWebImageNoParamsBlock)(); + +extern NSString *const SDWebImageErrorDomain; + +#define dispatch_main_sync_safe(block)\ + if ([NSThread isMainThread]) {\ + block();\ + } else {\ + dispatch_sync(dispatch_get_main_queue(), block);\ + } + +#define dispatch_main_async_safe(block)\ + if ([NSThread isMainThread]) {\ + block();\ + } else {\ + dispatch_async(dispatch_get_main_queue(), block);\ + } diff --git a/IOS/Playground/Pods/SDWebImage/SDWebImage/SDWebImageCompat.m b/IOS/Playground/Pods/SDWebImage/SDWebImage/SDWebImageCompat.m new file mode 100644 index 00000000..57d94135 --- /dev/null +++ b/IOS/Playground/Pods/SDWebImage/SDWebImage/SDWebImageCompat.m @@ -0,0 +1,51 @@ +// +// SDWebImageCompat.m +// SDWebImage +// +// Created by Olivier Poitrey on 11/12/12. +// Copyright (c) 2012 Dailymotion. All rights reserved. +// + +#import "SDWebImageCompat.h" + +#if !__has_feature(objc_arc) +#error SDWebImage is ARC only. Either turn on ARC for the project or use -fobjc-arc flag +#endif + +inline UIImage *SDScaledImageForKey(NSString *key, UIImage *image) { + if (!image) { + return nil; + } + + if ([image.images count] > 0) { + NSMutableArray *scaledImages = [NSMutableArray array]; + + for (UIImage *tempImage in image.images) { + [scaledImages addObject:SDScaledImageForKey(key, tempImage)]; + } + + return [UIImage animatedImageWithImages:scaledImages duration:image.duration]; + } + else { + if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) { + CGFloat scale = 1; + if (key.length >= 8) { + NSRange range = [key rangeOfString:@"@2x."]; + if (range.location != NSNotFound) { + scale = 2.0; + } + + range = [key rangeOfString:@"@3x."]; + if (range.location != NSNotFound) { + scale = 3.0; + } + } + + UIImage *scaledImage = [[UIImage alloc] initWithCGImage:image.CGImage scale:scale orientation:image.imageOrientation]; + image = scaledImage; + } + return image; + } +} + +NSString *const SDWebImageErrorDomain = @"SDWebImageErrorDomain"; diff --git a/IOS/Playground/Pods/SDWebImage/SDWebImage/SDWebImageDecoder.h b/IOS/Playground/Pods/SDWebImage/SDWebImage/SDWebImageDecoder.h new file mode 100644 index 00000000..0176a7ba --- /dev/null +++ b/IOS/Playground/Pods/SDWebImage/SDWebImage/SDWebImageDecoder.h @@ -0,0 +1,18 @@ +/* + * This file is part of the SDWebImage package. + * (c) Olivier Poitrey + * + * Created by james on 9/28/11. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +#import +#import "SDWebImageCompat.h" + +@interface UIImage (ForceDecode) + ++ (UIImage *)decodedImageWithImage:(UIImage *)image; + +@end diff --git a/IOS/Playground/Pods/SDWebImage/SDWebImage/SDWebImageDecoder.m b/IOS/Playground/Pods/SDWebImage/SDWebImage/SDWebImageDecoder.m new file mode 100644 index 00000000..2bb5472f --- /dev/null +++ b/IOS/Playground/Pods/SDWebImage/SDWebImage/SDWebImageDecoder.m @@ -0,0 +1,92 @@ +/* + * This file is part of the SDWebImage package. + * (c) Olivier Poitrey + * + * Created by james on 9/28/11. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +#import "SDWebImageDecoder.h" + +@implementation UIImage (ForceDecode) + ++ (UIImage *)decodedImageWithImage:(UIImage *)image { + // while downloading huge amount of images + // autorelease the bitmap context + // and all vars to help system to free memory + // when there are memory warning. + // on iOS7, do not forget to call + // [[SDImageCache sharedImageCache] clearMemory]; + + if (image == nil) { // Prevent "CGBitmapContextCreateImage: invalid context 0x0" error + return nil; + } + + @autoreleasepool{ + // do not decode animated images + if (image.images != nil) { + return image; + } + + CGImageRef imageRef = image.CGImage; + + CGImageAlphaInfo alpha = CGImageGetAlphaInfo(imageRef); + BOOL anyAlpha = (alpha == kCGImageAlphaFirst || + alpha == kCGImageAlphaLast || + alpha == kCGImageAlphaPremultipliedFirst || + alpha == kCGImageAlphaPremultipliedLast); + if (anyAlpha) { + return image; + } + + // current + CGColorSpaceModel imageColorSpaceModel = CGColorSpaceGetModel(CGImageGetColorSpace(imageRef)); + CGColorSpaceRef colorspaceRef = CGImageGetColorSpace(imageRef); + + BOOL unsupportedColorSpace = (imageColorSpaceModel == kCGColorSpaceModelUnknown || + imageColorSpaceModel == kCGColorSpaceModelMonochrome || + imageColorSpaceModel == kCGColorSpaceModelCMYK || + imageColorSpaceModel == kCGColorSpaceModelIndexed); + if (unsupportedColorSpace) { + colorspaceRef = CGColorSpaceCreateDeviceRGB(); + } + + size_t width = CGImageGetWidth(imageRef); + size_t height = CGImageGetHeight(imageRef); + NSUInteger bytesPerPixel = 4; + NSUInteger bytesPerRow = bytesPerPixel * width; + NSUInteger bitsPerComponent = 8; + + + // kCGImageAlphaNone is not supported in CGBitmapContextCreate. + // Since the original image here has no alpha info, use kCGImageAlphaNoneSkipLast + // to create bitmap graphics contexts without alpha info. + CGContextRef context = CGBitmapContextCreate(NULL, + width, + height, + bitsPerComponent, + bytesPerRow, + colorspaceRef, + kCGBitmapByteOrderDefault|kCGImageAlphaNoneSkipLast); + + // Draw the image into the context and retrieve the new bitmap image without alpha + CGContextDrawImage(context, CGRectMake(0, 0, width, height), imageRef); + CGImageRef imageRefWithoutAlpha = CGBitmapContextCreateImage(context); + UIImage *imageWithoutAlpha = [UIImage imageWithCGImage:imageRefWithoutAlpha + scale:image.scale + orientation:image.imageOrientation]; + + if (unsupportedColorSpace) { + CGColorSpaceRelease(colorspaceRef); + } + + CGContextRelease(context); + CGImageRelease(imageRefWithoutAlpha); + + return imageWithoutAlpha; + } +} + +@end diff --git a/IOS/Playground/Pods/SDWebImage/SDWebImage/SDWebImageDownloader.h b/IOS/Playground/Pods/SDWebImage/SDWebImage/SDWebImageDownloader.h new file mode 100644 index 00000000..d440e043 --- /dev/null +++ b/IOS/Playground/Pods/SDWebImage/SDWebImage/SDWebImageDownloader.h @@ -0,0 +1,196 @@ +/* + * This file is part of the SDWebImage package. + * (c) Olivier Poitrey + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +#import +#import "SDWebImageCompat.h" +#import "SDWebImageOperation.h" + +typedef NS_OPTIONS(NSUInteger, SDWebImageDownloaderOptions) { + SDWebImageDownloaderLowPriority = 1 << 0, + SDWebImageDownloaderProgressiveDownload = 1 << 1, + + /** + * By default, request prevent the use of NSURLCache. With this flag, NSURLCache + * is used with default policies. + */ + SDWebImageDownloaderUseNSURLCache = 1 << 2, + + /** + * Call completion block with nil image/imageData if the image was read from NSURLCache + * (to be combined with `SDWebImageDownloaderUseNSURLCache`). + */ + + SDWebImageDownloaderIgnoreCachedResponse = 1 << 3, + /** + * In iOS 4+, continue the download of the image if the app goes to background. This is achieved by asking the system for + * extra time in background to let the request finish. If the background task expires the operation will be cancelled. + */ + + SDWebImageDownloaderContinueInBackground = 1 << 4, + + /** + * Handles cookies stored in NSHTTPCookieStore by setting + * NSMutableURLRequest.HTTPShouldHandleCookies = YES; + */ + SDWebImageDownloaderHandleCookies = 1 << 5, + + /** + * Enable to allow untrusted SSL certificates. + * Useful for testing purposes. Use with caution in production. + */ + SDWebImageDownloaderAllowInvalidSSLCertificates = 1 << 6, + + /** + * Put the image in the high priority queue. + */ + SDWebImageDownloaderHighPriority = 1 << 7, +}; + +typedef NS_ENUM(NSInteger, SDWebImageDownloaderExecutionOrder) { + /** + * Default value. All download operations will execute in queue style (first-in-first-out). + */ + SDWebImageDownloaderFIFOExecutionOrder, + + /** + * All download operations will execute in stack style (last-in-first-out). + */ + SDWebImageDownloaderLIFOExecutionOrder +}; + +extern NSString *const SDWebImageDownloadStartNotification; +extern NSString *const SDWebImageDownloadStopNotification; + +typedef void(^SDWebImageDownloaderProgressBlock)(NSInteger receivedSize, NSInteger expectedSize); + +typedef void(^SDWebImageDownloaderCompletedBlock)(UIImage *image, NSData *data, NSError *error, BOOL finished); + +typedef NSDictionary *(^SDWebImageDownloaderHeadersFilterBlock)(NSURL *url, NSDictionary *headers); + +/** + * Asynchronous downloader dedicated and optimized for image loading. + */ +@interface SDWebImageDownloader : NSObject + +/** + * Decompressing images that are downloaded and cached can improve performance but can consume lot of memory. + * Defaults to YES. Set this to NO if you are experiencing a crash due to excessive memory consumption. + */ +@property (assign, nonatomic) BOOL shouldDecompressImages; + +@property (assign, nonatomic) NSInteger maxConcurrentDownloads; + +/** + * Shows the current amount of downloads that still need to be downloaded + */ +@property (readonly, nonatomic) NSUInteger currentDownloadCount; + + +/** + * The timeout value (in seconds) for the download operation. Default: 15.0. + */ +@property (assign, nonatomic) NSTimeInterval downloadTimeout; + + +/** + * Changes download operations execution order. Default value is `SDWebImageDownloaderFIFOExecutionOrder`. + */ +@property (assign, nonatomic) SDWebImageDownloaderExecutionOrder executionOrder; + +/** + * Singleton method, returns the shared instance + * + * @return global shared instance of downloader class + */ ++ (SDWebImageDownloader *)sharedDownloader; + +/** + * Set the default URL credential to be set for request operations. + */ +@property (strong, nonatomic) NSURLCredential *urlCredential; + +/** + * Set username + */ +@property (strong, nonatomic) NSString *username; + +/** + * Set password + */ +@property (strong, nonatomic) NSString *password; + +/** + * Set filter to pick headers for downloading image HTTP request. + * + * This block will be invoked for each downloading image request, returned + * NSDictionary will be used as headers in corresponding HTTP request. + */ +@property (nonatomic, copy) SDWebImageDownloaderHeadersFilterBlock headersFilter; + +/** + * Set a value for a HTTP header to be appended to each download HTTP request. + * + * @param value The value for the header field. Use `nil` value to remove the header. + * @param field The name of the header field to set. + */ +- (void)setValue:(NSString *)value forHTTPHeaderField:(NSString *)field; + +/** + * Returns the value of the specified HTTP header field. + * + * @return The value associated with the header field field, or `nil` if there is no corresponding header field. + */ +- (NSString *)valueForHTTPHeaderField:(NSString *)field; + +/** + * Sets a subclass of `SDWebImageDownloaderOperation` as the default + * `NSOperation` to be used each time SDWebImage constructs a request + * operation to download an image. + * + * @param operationClass The subclass of `SDWebImageDownloaderOperation` to set + * as default. Passing `nil` will revert to `SDWebImageDownloaderOperation`. + */ +- (void)setOperationClass:(Class)operationClass; + +/** + * Creates a SDWebImageDownloader async downloader instance with a given URL + * + * The delegate will be informed when the image is finish downloaded or an error has happen. + * + * @see SDWebImageDownloaderDelegate + * + * @param url The URL to the image to download + * @param options The options to be used for this download + * @param progressBlock A block called repeatedly while the image is downloading + * @param completedBlock A block called once the download is completed. + * If the download succeeded, the image parameter is set, in case of error, + * error parameter is set with the error. The last parameter is always YES + * if SDWebImageDownloaderProgressiveDownload isn't use. With the + * SDWebImageDownloaderProgressiveDownload option, this block is called + * repeatedly with the partial image object and the finished argument set to NO + * before to be called a last time with the full image and finished argument + * set to YES. In case of error, the finished argument is always YES. + * + * @return A cancellable SDWebImageOperation + */ +- (id )downloadImageWithURL:(NSURL *)url + options:(SDWebImageDownloaderOptions)options + progress:(SDWebImageDownloaderProgressBlock)progressBlock + completed:(SDWebImageDownloaderCompletedBlock)completedBlock; + +/** + * Sets the download queue suspension state + */ +- (void)setSuspended:(BOOL)suspended; + +/** + * Cancels all download operations in the queue + */ +- (void)cancelAllDownloads; + +@end diff --git a/IOS/Playground/Pods/SDWebImage/SDWebImage/SDWebImageDownloader.m b/IOS/Playground/Pods/SDWebImage/SDWebImage/SDWebImageDownloader.m new file mode 100644 index 00000000..96aefa77 --- /dev/null +++ b/IOS/Playground/Pods/SDWebImage/SDWebImage/SDWebImageDownloader.m @@ -0,0 +1,236 @@ +/* + * This file is part of the SDWebImage package. + * (c) Olivier Poitrey + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +#import "SDWebImageDownloader.h" +#import "SDWebImageDownloaderOperation.h" +#import + +static NSString *const kProgressCallbackKey = @"progress"; +static NSString *const kCompletedCallbackKey = @"completed"; + +@interface SDWebImageDownloader () + +@property (strong, nonatomic) NSOperationQueue *downloadQueue; +@property (weak, nonatomic) NSOperation *lastAddedOperation; +@property (assign, nonatomic) Class operationClass; +@property (strong, nonatomic) NSMutableDictionary *URLCallbacks; +@property (strong, nonatomic) NSMutableDictionary *HTTPHeaders; +// This queue is used to serialize the handling of the network responses of all the download operation in a single queue +@property (SDDispatchQueueSetterSementics, nonatomic) dispatch_queue_t barrierQueue; + +@end + +@implementation SDWebImageDownloader + ++ (void)initialize { + // Bind SDNetworkActivityIndicator if available (download it here: http://github.com/rs/SDNetworkActivityIndicator ) + // To use it, just add #import "SDNetworkActivityIndicator.h" in addition to the SDWebImage import + if (NSClassFromString(@"SDNetworkActivityIndicator")) { + +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Warc-performSelector-leaks" + id activityIndicator = [NSClassFromString(@"SDNetworkActivityIndicator") performSelector:NSSelectorFromString(@"sharedActivityIndicator")]; +#pragma clang diagnostic pop + + // Remove observer in case it was previously added. + [[NSNotificationCenter defaultCenter] removeObserver:activityIndicator name:SDWebImageDownloadStartNotification object:nil]; + [[NSNotificationCenter defaultCenter] removeObserver:activityIndicator name:SDWebImageDownloadStopNotification object:nil]; + + [[NSNotificationCenter defaultCenter] addObserver:activityIndicator + selector:NSSelectorFromString(@"startActivity") + name:SDWebImageDownloadStartNotification object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:activityIndicator + selector:NSSelectorFromString(@"stopActivity") + name:SDWebImageDownloadStopNotification object:nil]; + } +} + ++ (SDWebImageDownloader *)sharedDownloader { + static dispatch_once_t once; + static id instance; + dispatch_once(&once, ^{ + instance = [self new]; + }); + return instance; +} + +- (id)init { + if ((self = [super init])) { + _operationClass = [SDWebImageDownloaderOperation class]; + _shouldDecompressImages = YES; + _executionOrder = SDWebImageDownloaderFIFOExecutionOrder; + _downloadQueue = [NSOperationQueue new]; + _downloadQueue.maxConcurrentOperationCount = 6; + _URLCallbacks = [NSMutableDictionary new]; +#ifdef SD_WEBP + _HTTPHeaders = [@{@"Accept": @"image/webp,image/*;q=0.8"} mutableCopy]; +#else + _HTTPHeaders = [@{@"Accept": @"image/*;q=0.8"} mutableCopy]; +#endif + _barrierQueue = dispatch_queue_create("com.hackemist.SDWebImageDownloaderBarrierQueue", DISPATCH_QUEUE_CONCURRENT); + _downloadTimeout = 15.0; + } + return self; +} + +- (void)dealloc { + [self.downloadQueue cancelAllOperations]; + SDDispatchQueueRelease(_barrierQueue); +} + +- (void)setValue:(NSString *)value forHTTPHeaderField:(NSString *)field { + if (value) { + self.HTTPHeaders[field] = value; + } + else { + [self.HTTPHeaders removeObjectForKey:field]; + } +} + +- (NSString *)valueForHTTPHeaderField:(NSString *)field { + return self.HTTPHeaders[field]; +} + +- (void)setMaxConcurrentDownloads:(NSInteger)maxConcurrentDownloads { + _downloadQueue.maxConcurrentOperationCount = maxConcurrentDownloads; +} + +- (NSUInteger)currentDownloadCount { + return _downloadQueue.operationCount; +} + +- (NSInteger)maxConcurrentDownloads { + return _downloadQueue.maxConcurrentOperationCount; +} + +- (void)setOperationClass:(Class)operationClass { + _operationClass = operationClass ?: [SDWebImageDownloaderOperation class]; +} + +- (id )downloadImageWithURL:(NSURL *)url options:(SDWebImageDownloaderOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageDownloaderCompletedBlock)completedBlock { + __block SDWebImageDownloaderOperation *operation; + __weak __typeof(self)wself = self; + + [self addProgressCallback:progressBlock completedBlock:completedBlock forURL:url createCallback:^{ + NSTimeInterval timeoutInterval = wself.downloadTimeout; + if (timeoutInterval == 0.0) { + timeoutInterval = 15.0; + } + + // In order to prevent from potential duplicate caching (NSURLCache + SDImageCache) we disable the cache for image requests if told otherwise + NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url cachePolicy:(options & SDWebImageDownloaderUseNSURLCache ? NSURLRequestUseProtocolCachePolicy : NSURLRequestReloadIgnoringLocalCacheData) timeoutInterval:timeoutInterval]; + request.HTTPShouldHandleCookies = (options & SDWebImageDownloaderHandleCookies); + request.HTTPShouldUsePipelining = YES; + if (wself.headersFilter) { + request.allHTTPHeaderFields = wself.headersFilter(url, [wself.HTTPHeaders copy]); + } + else { + request.allHTTPHeaderFields = wself.HTTPHeaders; + } + operation = [[wself.operationClass alloc] initWithRequest:request + options:options + progress:^(NSInteger receivedSize, NSInteger expectedSize) { + SDWebImageDownloader *sself = wself; + if (!sself) return; + __block NSArray *callbacksForURL; + dispatch_sync(sself.barrierQueue, ^{ + callbacksForURL = [sself.URLCallbacks[url] copy]; + }); + for (NSDictionary *callbacks in callbacksForURL) { + dispatch_async(dispatch_get_main_queue(), ^{ + SDWebImageDownloaderProgressBlock callback = callbacks[kProgressCallbackKey]; + if (callback) callback(receivedSize, expectedSize); + }); + } + } + completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) { + SDWebImageDownloader *sself = wself; + if (!sself) return; + __block NSArray *callbacksForURL; + dispatch_barrier_sync(sself.barrierQueue, ^{ + callbacksForURL = [sself.URLCallbacks[url] copy]; + if (finished) { + [sself.URLCallbacks removeObjectForKey:url]; + } + }); + for (NSDictionary *callbacks in callbacksForURL) { + SDWebImageDownloaderCompletedBlock callback = callbacks[kCompletedCallbackKey]; + if (callback) callback(image, data, error, finished); + } + } + cancelled:^{ + SDWebImageDownloader *sself = wself; + if (!sself) return; + dispatch_barrier_async(sself.barrierQueue, ^{ + [sself.URLCallbacks removeObjectForKey:url]; + }); + }]; + operation.shouldDecompressImages = wself.shouldDecompressImages; + + if (wself.urlCredential) { + operation.credential = wself.urlCredential; + } else if (wself.username && wself.password) { + operation.credential = [NSURLCredential credentialWithUser:wself.username password:wself.password persistence:NSURLCredentialPersistenceForSession]; + } + + if (options & SDWebImageDownloaderHighPriority) { + operation.queuePriority = NSOperationQueuePriorityHigh; + } else if (options & SDWebImageDownloaderLowPriority) { + operation.queuePriority = NSOperationQueuePriorityLow; + } + + [wself.downloadQueue addOperation:operation]; + if (wself.executionOrder == SDWebImageDownloaderLIFOExecutionOrder) { + // Emulate LIFO execution order by systematically adding new operations as last operation's dependency + [wself.lastAddedOperation addDependency:operation]; + wself.lastAddedOperation = operation; + } + }]; + + return operation; +} + +- (void)addProgressCallback:(SDWebImageDownloaderProgressBlock)progressBlock completedBlock:(SDWebImageDownloaderCompletedBlock)completedBlock forURL:(NSURL *)url createCallback:(SDWebImageNoParamsBlock)createCallback { + // The URL will be used as the key to the callbacks dictionary so it cannot be nil. If it is nil immediately call the completed block with no image or data. + if (url == nil) { + if (completedBlock != nil) { + completedBlock(nil, nil, nil, NO); + } + return; + } + + dispatch_barrier_sync(self.barrierQueue, ^{ + BOOL first = NO; + if (!self.URLCallbacks[url]) { + self.URLCallbacks[url] = [NSMutableArray new]; + first = YES; + } + + // Handle single download of simultaneous download request for the same URL + NSMutableArray *callbacksForURL = self.URLCallbacks[url]; + NSMutableDictionary *callbacks = [NSMutableDictionary new]; + if (progressBlock) callbacks[kProgressCallbackKey] = [progressBlock copy]; + if (completedBlock) callbacks[kCompletedCallbackKey] = [completedBlock copy]; + [callbacksForURL addObject:callbacks]; + self.URLCallbacks[url] = callbacksForURL; + + if (first) { + createCallback(); + } + }); +} + +- (void)setSuspended:(BOOL)suspended { + [self.downloadQueue setSuspended:suspended]; +} + +- (void)cancelAllDownloads { + [self.downloadQueue cancelAllOperations]; +} + +@end diff --git a/IOS/Playground/Pods/SDWebImage/SDWebImage/SDWebImageDownloaderOperation.h b/IOS/Playground/Pods/SDWebImage/SDWebImage/SDWebImageDownloaderOperation.h new file mode 100644 index 00000000..dd48b228 --- /dev/null +++ b/IOS/Playground/Pods/SDWebImage/SDWebImage/SDWebImageDownloaderOperation.h @@ -0,0 +1,78 @@ +/* + * This file is part of the SDWebImage package. + * (c) Olivier Poitrey + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +#import +#import "SDWebImageDownloader.h" +#import "SDWebImageOperation.h" + +extern NSString *const SDWebImageDownloadStartNotification; +extern NSString *const SDWebImageDownloadReceiveResponseNotification; +extern NSString *const SDWebImageDownloadStopNotification; +extern NSString *const SDWebImageDownloadFinishNotification; + +@interface SDWebImageDownloaderOperation : NSOperation + +/** + * The request used by the operation's connection. + */ +@property (strong, nonatomic, readonly) NSURLRequest *request; + + +@property (assign, nonatomic) BOOL shouldDecompressImages; + +/** + * Whether the URL connection should consult the credential storage for authenticating the connection. `YES` by default. + * + * This is the value that is returned in the `NSURLConnectionDelegate` method `-connectionShouldUseCredentialStorage:`. + */ +@property (nonatomic, assign) BOOL shouldUseCredentialStorage; + +/** + * The credential used for authentication challenges in `-connection:didReceiveAuthenticationChallenge:`. + * + * This will be overridden by any shared credentials that exist for the username or password of the request URL, if present. + */ +@property (nonatomic, strong) NSURLCredential *credential; + +/** + * The SDWebImageDownloaderOptions for the receiver. + */ +@property (assign, nonatomic, readonly) SDWebImageDownloaderOptions options; + +/** + * The expected size of data. + */ +@property (assign, nonatomic) NSInteger expectedSize; + +/** + * The response returned by the operation's connection. + */ +@property (strong, nonatomic) NSURLResponse *response; + +/** + * Initializes a `SDWebImageDownloaderOperation` object + * + * @see SDWebImageDownloaderOperation + * + * @param request the URL request + * @param options downloader options + * @param progressBlock the block executed when a new chunk of data arrives. + * @note the progress block is executed on a background queue + * @param completedBlock the block executed when the download is done. + * @note the completed block is executed on the main queue for success. If errors are found, there is a chance the block will be executed on a background queue + * @param cancelBlock the block executed if the download (operation) is cancelled + * + * @return the initialized instance + */ +- (id)initWithRequest:(NSURLRequest *)request + options:(SDWebImageDownloaderOptions)options + progress:(SDWebImageDownloaderProgressBlock)progressBlock + completed:(SDWebImageDownloaderCompletedBlock)completedBlock + cancelled:(SDWebImageNoParamsBlock)cancelBlock; + +@end diff --git a/IOS/Playground/Pods/SDWebImage/SDWebImage/SDWebImageDownloaderOperation.m b/IOS/Playground/Pods/SDWebImage/SDWebImage/SDWebImageDownloaderOperation.m new file mode 100644 index 00000000..5a8bd11f --- /dev/null +++ b/IOS/Playground/Pods/SDWebImage/SDWebImage/SDWebImageDownloaderOperation.m @@ -0,0 +1,466 @@ +/* + * This file is part of the SDWebImage package. + * (c) Olivier Poitrey + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +#import "SDWebImageDownloaderOperation.h" +#import "SDWebImageDecoder.h" +#import "UIImage+MultiFormat.h" +#import +#import "SDWebImageManager.h" + +NSString *const SDWebImageDownloadStartNotification = @"SDWebImageDownloadStartNotification"; +NSString *const SDWebImageDownloadReceiveResponseNotification = @"SDWebImageDownloadReceiveResponseNotification"; +NSString *const SDWebImageDownloadStopNotification = @"SDWebImageDownloadStopNotification"; +NSString *const SDWebImageDownloadFinishNotification = @"SDWebImageDownloadFinishNotification"; + +@interface SDWebImageDownloaderOperation () + +@property (copy, nonatomic) SDWebImageDownloaderProgressBlock progressBlock; +@property (copy, nonatomic) SDWebImageDownloaderCompletedBlock completedBlock; +@property (copy, nonatomic) SDWebImageNoParamsBlock cancelBlock; + +@property (assign, nonatomic, getter = isExecuting) BOOL executing; +@property (assign, nonatomic, getter = isFinished) BOOL finished; +@property (strong, nonatomic) NSMutableData *imageData; +@property (strong, nonatomic) NSURLConnection *connection; +@property (strong, atomic) NSThread *thread; + +#if TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_4_0 +@property (assign, nonatomic) UIBackgroundTaskIdentifier backgroundTaskId; +#endif + +@end + +@implementation SDWebImageDownloaderOperation { + size_t width, height; + UIImageOrientation orientation; + BOOL responseFromCached; +} + +@synthesize executing = _executing; +@synthesize finished = _finished; + +- (id)initWithRequest:(NSURLRequest *)request + options:(SDWebImageDownloaderOptions)options + progress:(SDWebImageDownloaderProgressBlock)progressBlock + completed:(SDWebImageDownloaderCompletedBlock)completedBlock + cancelled:(SDWebImageNoParamsBlock)cancelBlock { + if ((self = [super init])) { + _request = request; + _shouldDecompressImages = YES; + _shouldUseCredentialStorage = YES; + _options = options; + _progressBlock = [progressBlock copy]; + _completedBlock = [completedBlock copy]; + _cancelBlock = [cancelBlock copy]; + _executing = NO; + _finished = NO; + _expectedSize = 0; + responseFromCached = YES; // Initially wrong until `connection:willCacheResponse:` is called or not called + } + return self; +} + +- (void)start { + @synchronized (self) { + if (self.isCancelled) { + self.finished = YES; + [self reset]; + return; + } + +#if TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_4_0 + Class UIApplicationClass = NSClassFromString(@"UIApplication"); + BOOL hasApplication = UIApplicationClass && [UIApplicationClass respondsToSelector:@selector(sharedApplication)]; + if (hasApplication && [self shouldContinueWhenAppEntersBackground]) { + __weak __typeof__ (self) wself = self; + UIApplication * app = [UIApplicationClass performSelector:@selector(sharedApplication)]; + self.backgroundTaskId = [app beginBackgroundTaskWithExpirationHandler:^{ + __strong __typeof (wself) sself = wself; + + if (sself) { + [sself cancel]; + + [app endBackgroundTask:sself.backgroundTaskId]; + sself.backgroundTaskId = UIBackgroundTaskInvalid; + } + }]; + } +#endif + + self.executing = YES; + self.connection = [[NSURLConnection alloc] initWithRequest:self.request delegate:self startImmediately:NO]; + self.thread = [NSThread currentThread]; + } + + [self.connection start]; + + if (self.connection) { + if (self.progressBlock) { + self.progressBlock(0, NSURLResponseUnknownLength); + } + dispatch_async(dispatch_get_main_queue(), ^{ + [[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadStartNotification object:self]; + }); + + if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_5_1) { + // Make sure to run the runloop in our background thread so it can process downloaded data + // Note: we use a timeout to work around an issue with NSURLConnection cancel under iOS 5 + // not waking up the runloop, leading to dead threads (see https://github.com/rs/SDWebImage/issues/466) + CFRunLoopRunInMode(kCFRunLoopDefaultMode, 10, false); + } + else { + CFRunLoopRun(); + } + + if (!self.isFinished) { + [self.connection cancel]; + [self connection:self.connection didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorTimedOut userInfo:@{NSURLErrorFailingURLErrorKey : self.request.URL}]]; + } + } + else { + if (self.completedBlock) { + self.completedBlock(nil, nil, [NSError errorWithDomain:NSURLErrorDomain code:0 userInfo:@{NSLocalizedDescriptionKey : @"Connection can't be initialized"}], YES); + } + } + +#if TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_4_0 + Class UIApplicationClass = NSClassFromString(@"UIApplication"); + if(!UIApplicationClass || ![UIApplicationClass respondsToSelector:@selector(sharedApplication)]) { + return; + } + if (self.backgroundTaskId != UIBackgroundTaskInvalid) { + UIApplication * app = [UIApplication performSelector:@selector(sharedApplication)]; + [app endBackgroundTask:self.backgroundTaskId]; + self.backgroundTaskId = UIBackgroundTaskInvalid; + } +#endif +} + +- (void)cancel { + @synchronized (self) { + if (self.thread) { + [self performSelector:@selector(cancelInternalAndStop) onThread:self.thread withObject:nil waitUntilDone:NO]; + } + else { + [self cancelInternal]; + } + } +} + +- (void)cancelInternalAndStop { + if (self.isFinished) return; + [self cancelInternal]; + CFRunLoopStop(CFRunLoopGetCurrent()); +} + +- (void)cancelInternal { + if (self.isFinished) return; + [super cancel]; + if (self.cancelBlock) self.cancelBlock(); + + if (self.connection) { + [self.connection cancel]; + dispatch_async(dispatch_get_main_queue(), ^{ + [[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadStopNotification object:self]; + }); + + // As we cancelled the connection, its callback won't be called and thus won't + // maintain the isFinished and isExecuting flags. + if (self.isExecuting) self.executing = NO; + if (!self.isFinished) self.finished = YES; + } + + [self reset]; +} + +- (void)done { + self.finished = YES; + self.executing = NO; + [self reset]; +} + +- (void)reset { + self.cancelBlock = nil; + self.completedBlock = nil; + self.progressBlock = nil; + self.connection = nil; + self.imageData = nil; + self.thread = nil; +} + +- (void)setFinished:(BOOL)finished { + [self willChangeValueForKey:@"isFinished"]; + _finished = finished; + [self didChangeValueForKey:@"isFinished"]; +} + +- (void)setExecuting:(BOOL)executing { + [self willChangeValueForKey:@"isExecuting"]; + _executing = executing; + [self didChangeValueForKey:@"isExecuting"]; +} + +- (BOOL)isConcurrent { + return YES; +} + +#pragma mark NSURLConnection (delegate) + +- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { + + //'304 Not Modified' is an exceptional one + if (![response respondsToSelector:@selector(statusCode)] || ([((NSHTTPURLResponse *)response) statusCode] < 400 && [((NSHTTPURLResponse *)response) statusCode] != 304)) { + NSInteger expected = response.expectedContentLength > 0 ? (NSInteger)response.expectedContentLength : 0; + self.expectedSize = expected; + if (self.progressBlock) { + self.progressBlock(0, expected); + } + + self.imageData = [[NSMutableData alloc] initWithCapacity:expected]; + self.response = response; + dispatch_async(dispatch_get_main_queue(), ^{ + [[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadReceiveResponseNotification object:self]; + }); + } + else { + NSUInteger code = [((NSHTTPURLResponse *)response) statusCode]; + + //This is the case when server returns '304 Not Modified'. It means that remote image is not changed. + //In case of 304 we need just cancel the operation and return cached image from the cache. + if (code == 304) { + [self cancelInternal]; + } else { + [self.connection cancel]; + } + dispatch_async(dispatch_get_main_queue(), ^{ + [[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadStopNotification object:self]; + }); + + if (self.completedBlock) { + self.completedBlock(nil, nil, [NSError errorWithDomain:NSURLErrorDomain code:[((NSHTTPURLResponse *)response) statusCode] userInfo:nil], YES); + } + CFRunLoopStop(CFRunLoopGetCurrent()); + [self done]; + } +} + +- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { + [self.imageData appendData:data]; + + if ((self.options & SDWebImageDownloaderProgressiveDownload) && self.expectedSize > 0 && self.completedBlock) { + // The following code is from http://www.cocoaintheshell.com/2011/05/progressive-images-download-imageio/ + // Thanks to the author @Nyx0uf + + // Get the total bytes downloaded + const NSInteger totalSize = self.imageData.length; + + // Update the data source, we must pass ALL the data, not just the new bytes + CGImageSourceRef imageSource = CGImageSourceCreateWithData((__bridge CFDataRef)self.imageData, NULL); + + if (width + height == 0) { + CFDictionaryRef properties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, NULL); + if (properties) { + NSInteger orientationValue = -1; + CFTypeRef val = CFDictionaryGetValue(properties, kCGImagePropertyPixelHeight); + if (val) CFNumberGetValue(val, kCFNumberLongType, &height); + val = CFDictionaryGetValue(properties, kCGImagePropertyPixelWidth); + if (val) CFNumberGetValue(val, kCFNumberLongType, &width); + val = CFDictionaryGetValue(properties, kCGImagePropertyOrientation); + if (val) CFNumberGetValue(val, kCFNumberNSIntegerType, &orientationValue); + CFRelease(properties); + + // When we draw to Core Graphics, we lose orientation information, + // which means the image below born of initWithCGIImage will be + // oriented incorrectly sometimes. (Unlike the image born of initWithData + // in connectionDidFinishLoading.) So save it here and pass it on later. + orientation = [[self class] orientationFromPropertyValue:(orientationValue == -1 ? 1 : orientationValue)]; + } + + } + + if (width + height > 0 && totalSize < self.expectedSize) { + // Create the image + CGImageRef partialImageRef = CGImageSourceCreateImageAtIndex(imageSource, 0, NULL); + +#ifdef TARGET_OS_IPHONE + // Workaround for iOS anamorphic image + if (partialImageRef) { + const size_t partialHeight = CGImageGetHeight(partialImageRef); + CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); + CGContextRef bmContext = CGBitmapContextCreate(NULL, width, height, 8, width * 4, colorSpace, kCGBitmapByteOrderDefault | kCGImageAlphaPremultipliedFirst); + CGColorSpaceRelease(colorSpace); + if (bmContext) { + CGContextDrawImage(bmContext, (CGRect){.origin.x = 0.0f, .origin.y = 0.0f, .size.width = width, .size.height = partialHeight}, partialImageRef); + CGImageRelease(partialImageRef); + partialImageRef = CGBitmapContextCreateImage(bmContext); + CGContextRelease(bmContext); + } + else { + CGImageRelease(partialImageRef); + partialImageRef = nil; + } + } +#endif + + if (partialImageRef) { + UIImage *image = [UIImage imageWithCGImage:partialImageRef scale:1 orientation:orientation]; + NSString *key = [[SDWebImageManager sharedManager] cacheKeyForURL:self.request.URL]; + UIImage *scaledImage = [self scaledImageForKey:key image:image]; + if (self.shouldDecompressImages) { + image = [UIImage decodedImageWithImage:scaledImage]; + } + else { + image = scaledImage; + } + CGImageRelease(partialImageRef); + dispatch_main_sync_safe(^{ + if (self.completedBlock) { + self.completedBlock(image, nil, nil, NO); + } + }); + } + } + + CFRelease(imageSource); + } + + if (self.progressBlock) { + self.progressBlock(self.imageData.length, self.expectedSize); + } +} + ++ (UIImageOrientation)orientationFromPropertyValue:(NSInteger)value { + switch (value) { + case 1: + return UIImageOrientationUp; + case 3: + return UIImageOrientationDown; + case 8: + return UIImageOrientationLeft; + case 6: + return UIImageOrientationRight; + case 2: + return UIImageOrientationUpMirrored; + case 4: + return UIImageOrientationDownMirrored; + case 5: + return UIImageOrientationLeftMirrored; + case 7: + return UIImageOrientationRightMirrored; + default: + return UIImageOrientationUp; + } +} + +- (UIImage *)scaledImageForKey:(NSString *)key image:(UIImage *)image { + return SDScaledImageForKey(key, image); +} + +- (void)connectionDidFinishLoading:(NSURLConnection *)aConnection { + SDWebImageDownloaderCompletedBlock completionBlock = self.completedBlock; + @synchronized(self) { + CFRunLoopStop(CFRunLoopGetCurrent()); + self.thread = nil; + self.connection = nil; + dispatch_async(dispatch_get_main_queue(), ^{ + [[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadStopNotification object:self]; + [[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadFinishNotification object:self]; + }); + } + + if (![[NSURLCache sharedURLCache] cachedResponseForRequest:_request]) { + responseFromCached = NO; + } + + if (completionBlock) { + if (self.options & SDWebImageDownloaderIgnoreCachedResponse && responseFromCached) { + completionBlock(nil, nil, nil, YES); + } else if (self.imageData) { + UIImage *image = [UIImage sd_imageWithData:self.imageData]; + NSString *key = [[SDWebImageManager sharedManager] cacheKeyForURL:self.request.URL]; + image = [self scaledImageForKey:key image:image]; + + // Do not force decoding animated GIFs + if (!image.images) { + if (self.shouldDecompressImages) { + image = [UIImage decodedImageWithImage:image]; + } + } + if (CGSizeEqualToSize(image.size, CGSizeZero)) { + completionBlock(nil, nil, [NSError errorWithDomain:SDWebImageErrorDomain code:0 userInfo:@{NSLocalizedDescriptionKey : @"Downloaded image has 0 pixels"}], YES); + } + else { + completionBlock(image, self.imageData, nil, YES); + } + } else { + completionBlock(nil, nil, [NSError errorWithDomain:SDWebImageErrorDomain code:0 userInfo:@{NSLocalizedDescriptionKey : @"Image data is nil"}], YES); + } + } + self.completionBlock = nil; + [self done]; +} + +- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { + @synchronized(self) { + CFRunLoopStop(CFRunLoopGetCurrent()); + self.thread = nil; + self.connection = nil; + dispatch_async(dispatch_get_main_queue(), ^{ + [[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadStopNotification object:self]; + }); + } + + if (self.completedBlock) { + self.completedBlock(nil, nil, error, YES); + } + self.completionBlock = nil; + [self done]; +} + +- (NSCachedURLResponse *)connection:(NSURLConnection *)connection willCacheResponse:(NSCachedURLResponse *)cachedResponse { + responseFromCached = NO; // If this method is called, it means the response wasn't read from cache + if (self.request.cachePolicy == NSURLRequestReloadIgnoringLocalCacheData) { + // Prevents caching of responses + return nil; + } + else { + return cachedResponse; + } +} + +- (BOOL)shouldContinueWhenAppEntersBackground { + return self.options & SDWebImageDownloaderContinueInBackground; +} + +- (BOOL)connectionShouldUseCredentialStorage:(NSURLConnection __unused *)connection { + return self.shouldUseCredentialStorage; +} + +- (void)connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge{ + if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) { + if (!(self.options & SDWebImageDownloaderAllowInvalidSSLCertificates) && + [challenge.sender respondsToSelector:@selector(performDefaultHandlingForAuthenticationChallenge:)]) { + [challenge.sender performDefaultHandlingForAuthenticationChallenge:challenge]; + } else { + NSURLCredential *credential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]; + [[challenge sender] useCredential:credential forAuthenticationChallenge:challenge]; + } + } else { + if ([challenge previousFailureCount] == 0) { + if (self.credential) { + [[challenge sender] useCredential:self.credential forAuthenticationChallenge:challenge]; + } else { + [[challenge sender] continueWithoutCredentialForAuthenticationChallenge:challenge]; + } + } else { + [[challenge sender] continueWithoutCredentialForAuthenticationChallenge:challenge]; + } + } +} + +@end diff --git a/IOS/Playground/Pods/SDWebImage/SDWebImage/SDWebImageManager.h b/IOS/Playground/Pods/SDWebImage/SDWebImage/SDWebImageManager.h new file mode 100644 index 00000000..8750730a --- /dev/null +++ b/IOS/Playground/Pods/SDWebImage/SDWebImage/SDWebImageManager.h @@ -0,0 +1,298 @@ +/* + * This file is part of the SDWebImage package. + * (c) Olivier Poitrey + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +#import "SDWebImageCompat.h" +#import "SDWebImageOperation.h" +#import "SDWebImageDownloader.h" +#import "SDImageCache.h" + +typedef NS_OPTIONS(NSUInteger, SDWebImageOptions) { + /** + * By default, when a URL fail to be downloaded, the URL is blacklisted so the library won't keep trying. + * This flag disable this blacklisting. + */ + SDWebImageRetryFailed = 1 << 0, + + /** + * By default, image downloads are started during UI interactions, this flags disable this feature, + * leading to delayed download on UIScrollView deceleration for instance. + */ + SDWebImageLowPriority = 1 << 1, + + /** + * This flag disables on-disk caching + */ + SDWebImageCacheMemoryOnly = 1 << 2, + + /** + * This flag enables progressive download, the image is displayed progressively during download as a browser would do. + * By default, the image is only displayed once completely downloaded. + */ + SDWebImageProgressiveDownload = 1 << 3, + + /** + * Even if the image is cached, respect the HTTP response cache control, and refresh the image from remote location if needed. + * The disk caching will be handled by NSURLCache instead of SDWebImage leading to slight performance degradation. + * This option helps deal with images changing behind the same request URL, e.g. Facebook graph api profile pics. + * If a cached image is refreshed, the completion block is called once with the cached image and again with the final image. + * + * Use this flag only if you can't make your URLs static with embedded cache busting parameter. + */ + SDWebImageRefreshCached = 1 << 4, + + /** + * In iOS 4+, continue the download of the image if the app goes to background. This is achieved by asking the system for + * extra time in background to let the request finish. If the background task expires the operation will be cancelled. + */ + SDWebImageContinueInBackground = 1 << 5, + + /** + * Handles cookies stored in NSHTTPCookieStore by setting + * NSMutableURLRequest.HTTPShouldHandleCookies = YES; + */ + SDWebImageHandleCookies = 1 << 6, + + /** + * Enable to allow untrusted SSL certificates. + * Useful for testing purposes. Use with caution in production. + */ + SDWebImageAllowInvalidSSLCertificates = 1 << 7, + + /** + * By default, images are loaded in the order in which they were queued. This flag moves them to + * the front of the queue. + */ + SDWebImageHighPriority = 1 << 8, + + /** + * By default, placeholder images are loaded while the image is loading. This flag will delay the loading + * of the placeholder image until after the image has finished loading. + */ + SDWebImageDelayPlaceholder = 1 << 9, + + /** + * We usually don't call transformDownloadedImage delegate method on animated images, + * as most transformation code would mangle it. + * Use this flag to transform them anyway. + */ + SDWebImageTransformAnimatedImage = 1 << 10, + + /** + * By default, image is added to the imageView after download. But in some cases, we want to + * have the hand before setting the image (apply a filter or add it with cross-fade animation for instance) + * Use this flag if you want to manually set the image in the completion when success + */ + SDWebImageAvoidAutoSetImage = 1 << 11 +}; + +typedef void(^SDWebImageCompletionBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL); + +typedef void(^SDWebImageCompletionWithFinishedBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL); + +typedef NSString *(^SDWebImageCacheKeyFilterBlock)(NSURL *url); + + +@class SDWebImageManager; + +@protocol SDWebImageManagerDelegate + +@optional + +/** + * Controls which image should be downloaded when the image is not found in the cache. + * + * @param imageManager The current `SDWebImageManager` + * @param imageURL The url of the image to be downloaded + * + * @return Return NO to prevent the downloading of the image on cache misses. If not implemented, YES is implied. + */ +- (BOOL)imageManager:(SDWebImageManager *)imageManager shouldDownloadImageForURL:(NSURL *)imageURL; + +/** + * Allows to transform the image immediately after it has been downloaded and just before to cache it on disk and memory. + * NOTE: This method is called from a global queue in order to not to block the main thread. + * + * @param imageManager The current `SDWebImageManager` + * @param image The image to transform + * @param imageURL The url of the image to transform + * + * @return The transformed image object. + */ +- (UIImage *)imageManager:(SDWebImageManager *)imageManager transformDownloadedImage:(UIImage *)image withURL:(NSURL *)imageURL; + +@end + +/** + * The SDWebImageManager is the class behind the UIImageView+WebCache category and likes. + * It ties the asynchronous downloader (SDWebImageDownloader) with the image cache store (SDImageCache). + * You can use this class directly to benefit from web image downloading with caching in another context than + * a UIView. + * + * Here is a simple example of how to use SDWebImageManager: + * + * @code + +SDWebImageManager *manager = [SDWebImageManager sharedManager]; +[manager downloadImageWithURL:imageURL + options:0 + progress:nil + completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { + if (image) { + // do something with image + } + }]; + + * @endcode + */ +@interface SDWebImageManager : NSObject + +@property (weak, nonatomic) id delegate; + +@property (strong, nonatomic, readonly) SDImageCache *imageCache; +@property (strong, nonatomic, readonly) SDWebImageDownloader *imageDownloader; + +/** + * The cache filter is a block used each time SDWebImageManager need to convert an URL into a cache key. This can + * be used to remove dynamic part of an image URL. + * + * The following example sets a filter in the application delegate that will remove any query-string from the + * URL before to use it as a cache key: + * + * @code + +[[SDWebImageManager sharedManager] setCacheKeyFilter:^(NSURL *url) { + url = [[NSURL alloc] initWithScheme:url.scheme host:url.host path:url.path]; + return [url absoluteString]; +}]; + + * @endcode + */ +@property (nonatomic, copy) SDWebImageCacheKeyFilterBlock cacheKeyFilter; + +/** + * Returns global SDWebImageManager instance. + * + * @return SDWebImageManager shared instance + */ ++ (SDWebImageManager *)sharedManager; + +/** + * Downloads the image at the given URL if not present in cache or return the cached version otherwise. + * + * @param url The URL to the image + * @param options A mask to specify options to use for this request + * @param progressBlock A block called while image is downloading + * @param completedBlock A block called when operation has been completed. + * + * This parameter is required. + * + * This block has no return value and takes the requested UIImage as first parameter. + * In case of error the image parameter is nil and the second parameter may contain an NSError. + * + * The third parameter is an `SDImageCacheType` enum indicating if the image was retrieved from the local cache + * or from the memory cache or from the network. + * + * The last parameter is set to NO when the SDWebImageProgressiveDownload option is used and the image is + * downloading. This block is thus called repeatedly with a partial image. When image is fully downloaded, the + * block is called a last time with the full image and the last parameter set to YES. + * + * @return Returns an NSObject conforming to SDWebImageOperation. Should be an instance of SDWebImageDownloaderOperation + */ +- (id )downloadImageWithURL:(NSURL *)url + options:(SDWebImageOptions)options + progress:(SDWebImageDownloaderProgressBlock)progressBlock + completed:(SDWebImageCompletionWithFinishedBlock)completedBlock; + +/** + * Saves image to cache for given URL + * + * @param image The image to cache + * @param url The URL to the image + * + */ + +- (void)saveImageToCache:(UIImage *)image forURL:(NSURL *)url; + +/** + * Cancel all current operations + */ +- (void)cancelAll; + +/** + * Check one or more operations running + */ +- (BOOL)isRunning; + +/** + * Check if image has already been cached + * + * @param url image url + * + * @return if the image was already cached + */ +- (BOOL)cachedImageExistsForURL:(NSURL *)url; + +/** + * Check if image has already been cached on disk only + * + * @param url image url + * + * @return if the image was already cached (disk only) + */ +- (BOOL)diskImageExistsForURL:(NSURL *)url; + +/** + * Async check if image has already been cached + * + * @param url image url + * @param completionBlock the block to be executed when the check is finished + * + * @note the completion block is always executed on the main queue + */ +- (void)cachedImageExistsForURL:(NSURL *)url + completion:(SDWebImageCheckCacheCompletionBlock)completionBlock; + +/** + * Async check if image has already been cached on disk only + * + * @param url image url + * @param completionBlock the block to be executed when the check is finished + * + * @note the completion block is always executed on the main queue + */ +- (void)diskImageExistsForURL:(NSURL *)url + completion:(SDWebImageCheckCacheCompletionBlock)completionBlock; + + +/** + *Return the cache key for a given URL + */ +- (NSString *)cacheKeyForURL:(NSURL *)url; + +@end + + +#pragma mark - Deprecated + +typedef void(^SDWebImageCompletedBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType) __deprecated_msg("Block type deprecated. Use `SDWebImageCompletionBlock`"); +typedef void(^SDWebImageCompletedWithFinishedBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished) __deprecated_msg("Block type deprecated. Use `SDWebImageCompletionWithFinishedBlock`"); + + +@interface SDWebImageManager (Deprecated) + +/** + * Downloads the image at the given URL if not present in cache or return the cached version otherwise. + * + * @deprecated This method has been deprecated. Use `downloadImageWithURL:options:progress:completed:` + */ +- (id )downloadWithURL:(NSURL *)url + options:(SDWebImageOptions)options + progress:(SDWebImageDownloaderProgressBlock)progressBlock + completed:(SDWebImageCompletedWithFinishedBlock)completedBlock __deprecated_msg("Method deprecated. Use `downloadImageWithURL:options:progress:completed:`"); + +@end diff --git a/IOS/Playground/Pods/SDWebImage/SDWebImage/SDWebImageManager.m b/IOS/Playground/Pods/SDWebImage/SDWebImage/SDWebImageManager.m new file mode 100644 index 00000000..c804ee9a --- /dev/null +++ b/IOS/Playground/Pods/SDWebImage/SDWebImage/SDWebImageManager.m @@ -0,0 +1,370 @@ +/* + * This file is part of the SDWebImage package. + * (c) Olivier Poitrey + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +#import "SDWebImageManager.h" +#import + +@interface SDWebImageCombinedOperation : NSObject + +@property (assign, nonatomic, getter = isCancelled) BOOL cancelled; +@property (copy, nonatomic) SDWebImageNoParamsBlock cancelBlock; +@property (strong, nonatomic) NSOperation *cacheOperation; + +@end + +@interface SDWebImageManager () + +@property (strong, nonatomic, readwrite) SDImageCache *imageCache; +@property (strong, nonatomic, readwrite) SDWebImageDownloader *imageDownloader; +@property (strong, nonatomic) NSMutableSet *failedURLs; +@property (strong, nonatomic) NSMutableArray *runningOperations; + +@end + +@implementation SDWebImageManager + ++ (id)sharedManager { + static dispatch_once_t once; + static id instance; + dispatch_once(&once, ^{ + instance = [self new]; + }); + return instance; +} + +- (id)init { + if ((self = [super init])) { + _imageCache = [self createCache]; + _imageDownloader = [SDWebImageDownloader sharedDownloader]; + _failedURLs = [NSMutableSet new]; + _runningOperations = [NSMutableArray new]; + } + return self; +} + +- (SDImageCache *)createCache { + return [SDImageCache sharedImageCache]; +} + +- (NSString *)cacheKeyForURL:(NSURL *)url { + if (self.cacheKeyFilter) { + return self.cacheKeyFilter(url); + } + else { + return [url absoluteString]; + } +} + +- (BOOL)cachedImageExistsForURL:(NSURL *)url { + NSString *key = [self cacheKeyForURL:url]; + if ([self.imageCache imageFromMemoryCacheForKey:key] != nil) return YES; + return [self.imageCache diskImageExistsWithKey:key]; +} + +- (BOOL)diskImageExistsForURL:(NSURL *)url { + NSString *key = [self cacheKeyForURL:url]; + return [self.imageCache diskImageExistsWithKey:key]; +} + +- (void)cachedImageExistsForURL:(NSURL *)url + completion:(SDWebImageCheckCacheCompletionBlock)completionBlock { + NSString *key = [self cacheKeyForURL:url]; + + BOOL isInMemoryCache = ([self.imageCache imageFromMemoryCacheForKey:key] != nil); + + if (isInMemoryCache) { + // making sure we call the completion block on the main queue + dispatch_async(dispatch_get_main_queue(), ^{ + if (completionBlock) { + completionBlock(YES); + } + }); + return; + } + + [self.imageCache diskImageExistsWithKey:key completion:^(BOOL isInDiskCache) { + // the completion block of checkDiskCacheForImageWithKey:completion: is always called on the main queue, no need to further dispatch + if (completionBlock) { + completionBlock(isInDiskCache); + } + }]; +} + +- (void)diskImageExistsForURL:(NSURL *)url + completion:(SDWebImageCheckCacheCompletionBlock)completionBlock { + NSString *key = [self cacheKeyForURL:url]; + + [self.imageCache diskImageExistsWithKey:key completion:^(BOOL isInDiskCache) { + // the completion block of checkDiskCacheForImageWithKey:completion: is always called on the main queue, no need to further dispatch + if (completionBlock) { + completionBlock(isInDiskCache); + } + }]; +} + +- (id )downloadImageWithURL:(NSURL *)url + options:(SDWebImageOptions)options + progress:(SDWebImageDownloaderProgressBlock)progressBlock + completed:(SDWebImageCompletionWithFinishedBlock)completedBlock { + // Invoking this method without a completedBlock is pointless + NSAssert(completedBlock != nil, @"If you mean to prefetch the image, use -[SDWebImagePrefetcher prefetchURLs] instead"); + + // Very common mistake is to send the URL using NSString object instead of NSURL. For some strange reason, XCode won't + // throw any warning for this type mismatch. Here we failsafe this error by allowing URLs to be passed as NSString. + if ([url isKindOfClass:NSString.class]) { + url = [NSURL URLWithString:(NSString *)url]; + } + + // Prevents app crashing on argument type error like sending NSNull instead of NSURL + if (![url isKindOfClass:NSURL.class]) { + url = nil; + } + + __block SDWebImageCombinedOperation *operation = [SDWebImageCombinedOperation new]; + __weak SDWebImageCombinedOperation *weakOperation = operation; + + BOOL isFailedUrl = NO; + @synchronized (self.failedURLs) { + isFailedUrl = [self.failedURLs containsObject:url]; + } + + if (url.absoluteString.length == 0 || (!(options & SDWebImageRetryFailed) && isFailedUrl)) { + dispatch_main_sync_safe(^{ + NSError *error = [NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorFileDoesNotExist userInfo:nil]; + completedBlock(nil, error, SDImageCacheTypeNone, YES, url); + }); + return operation; + } + + @synchronized (self.runningOperations) { + [self.runningOperations addObject:operation]; + } + NSString *key = [self cacheKeyForURL:url]; + + operation.cacheOperation = [self.imageCache queryDiskCacheForKey:key done:^(UIImage *image, SDImageCacheType cacheType) { + if (operation.isCancelled) { + @synchronized (self.runningOperations) { + [self.runningOperations removeObject:operation]; + } + + return; + } + + if ((!image || options & SDWebImageRefreshCached) && (![self.delegate respondsToSelector:@selector(imageManager:shouldDownloadImageForURL:)] || [self.delegate imageManager:self shouldDownloadImageForURL:url])) { + if (image && options & SDWebImageRefreshCached) { + dispatch_main_sync_safe(^{ + // If image was found in the cache but SDWebImageRefreshCached is provided, notify about the cached image + // AND try to re-download it in order to let a chance to NSURLCache to refresh it from server. + completedBlock(image, nil, cacheType, YES, url); + }); + } + + // download if no image or requested to refresh anyway, and download allowed by delegate + SDWebImageDownloaderOptions downloaderOptions = 0; + if (options & SDWebImageLowPriority) downloaderOptions |= SDWebImageDownloaderLowPriority; + if (options & SDWebImageProgressiveDownload) downloaderOptions |= SDWebImageDownloaderProgressiveDownload; + if (options & SDWebImageRefreshCached) downloaderOptions |= SDWebImageDownloaderUseNSURLCache; + if (options & SDWebImageContinueInBackground) downloaderOptions |= SDWebImageDownloaderContinueInBackground; + if (options & SDWebImageHandleCookies) downloaderOptions |= SDWebImageDownloaderHandleCookies; + if (options & SDWebImageAllowInvalidSSLCertificates) downloaderOptions |= SDWebImageDownloaderAllowInvalidSSLCertificates; + if (options & SDWebImageHighPriority) downloaderOptions |= SDWebImageDownloaderHighPriority; + if (image && options & SDWebImageRefreshCached) { + // force progressive off if image already cached but forced refreshing + downloaderOptions &= ~SDWebImageDownloaderProgressiveDownload; + // ignore image read from NSURLCache if image if cached but force refreshing + downloaderOptions |= SDWebImageDownloaderIgnoreCachedResponse; + } + id subOperation = [self.imageDownloader downloadImageWithURL:url options:downloaderOptions progress:progressBlock completed:^(UIImage *downloadedImage, NSData *data, NSError *error, BOOL finished) { + __strong __typeof(weakOperation) strongOperation = weakOperation; + if (!strongOperation || strongOperation.isCancelled) { + // Do nothing if the operation was cancelled + // See #699 for more details + // if we would call the completedBlock, there could be a race condition between this block and another completedBlock for the same object, so if this one is called second, we will overwrite the new data + } + else if (error) { + dispatch_main_sync_safe(^{ + if (strongOperation && !strongOperation.isCancelled) { + completedBlock(nil, error, SDImageCacheTypeNone, finished, url); + } + }); + + if ( error.code != NSURLErrorNotConnectedToInternet + && error.code != NSURLErrorCancelled + && error.code != NSURLErrorTimedOut + && error.code != NSURLErrorInternationalRoamingOff + && error.code != NSURLErrorDataNotAllowed + && error.code != NSURLErrorCannotFindHost + && error.code != NSURLErrorCannotConnectToHost) { + @synchronized (self.failedURLs) { + [self.failedURLs addObject:url]; + } + } + } + else { + if ((options & SDWebImageRetryFailed)) { + @synchronized (self.failedURLs) { + [self.failedURLs removeObject:url]; + } + } + + BOOL cacheOnDisk = !(options & SDWebImageCacheMemoryOnly); + + if (options & SDWebImageRefreshCached && image && !downloadedImage) { + // Image refresh hit the NSURLCache cache, do not call the completion block + } + else if (downloadedImage && (!downloadedImage.images || (options & SDWebImageTransformAnimatedImage)) && [self.delegate respondsToSelector:@selector(imageManager:transformDownloadedImage:withURL:)]) { + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{ + UIImage *transformedImage = [self.delegate imageManager:self transformDownloadedImage:downloadedImage withURL:url]; + + if (transformedImage && finished) { + BOOL imageWasTransformed = ![transformedImage isEqual:downloadedImage]; + [self.imageCache storeImage:transformedImage recalculateFromImage:imageWasTransformed imageData:(imageWasTransformed ? nil : data) forKey:key toDisk:cacheOnDisk]; + } + + dispatch_main_sync_safe(^{ + if (strongOperation && !strongOperation.isCancelled) { + completedBlock(transformedImage, nil, SDImageCacheTypeNone, finished, url); + } + }); + }); + } + else { + if (downloadedImage && finished) { + [self.imageCache storeImage:downloadedImage recalculateFromImage:NO imageData:data forKey:key toDisk:cacheOnDisk]; + } + + dispatch_main_sync_safe(^{ + if (strongOperation && !strongOperation.isCancelled) { + completedBlock(downloadedImage, nil, SDImageCacheTypeNone, finished, url); + } + }); + } + } + + if (finished) { + @synchronized (self.runningOperations) { + if (strongOperation) { + [self.runningOperations removeObject:strongOperation]; + } + } + } + }]; + operation.cancelBlock = ^{ + [subOperation cancel]; + + @synchronized (self.runningOperations) { + __strong __typeof(weakOperation) strongOperation = weakOperation; + if (strongOperation) { + [self.runningOperations removeObject:strongOperation]; + } + } + }; + } + else if (image) { + dispatch_main_sync_safe(^{ + __strong __typeof(weakOperation) strongOperation = weakOperation; + if (strongOperation && !strongOperation.isCancelled) { + completedBlock(image, nil, cacheType, YES, url); + } + }); + @synchronized (self.runningOperations) { + [self.runningOperations removeObject:operation]; + } + } + else { + // Image not in cache and download disallowed by delegate + dispatch_main_sync_safe(^{ + __strong __typeof(weakOperation) strongOperation = weakOperation; + if (strongOperation && !weakOperation.isCancelled) { + completedBlock(nil, nil, SDImageCacheTypeNone, YES, url); + } + }); + @synchronized (self.runningOperations) { + [self.runningOperations removeObject:operation]; + } + } + }]; + + return operation; +} + +- (void)saveImageToCache:(UIImage *)image forURL:(NSURL *)url { + if (image && url) { + NSString *key = [self cacheKeyForURL:url]; + [self.imageCache storeImage:image forKey:key toDisk:YES]; + } +} + +- (void)cancelAll { + @synchronized (self.runningOperations) { + NSArray *copiedOperations = [self.runningOperations copy]; + [copiedOperations makeObjectsPerformSelector:@selector(cancel)]; + [self.runningOperations removeObjectsInArray:copiedOperations]; + } +} + +- (BOOL)isRunning { + BOOL isRunning = NO; + @synchronized(self.runningOperations) { + isRunning = (self.runningOperations.count > 0); + } + return isRunning; +} + +@end + + +@implementation SDWebImageCombinedOperation + +- (void)setCancelBlock:(SDWebImageNoParamsBlock)cancelBlock { + // check if the operation is already cancelled, then we just call the cancelBlock + if (self.isCancelled) { + if (cancelBlock) { + cancelBlock(); + } + _cancelBlock = nil; // don't forget to nil the cancelBlock, otherwise we will get crashes + } else { + _cancelBlock = [cancelBlock copy]; + } +} + +- (void)cancel { + self.cancelled = YES; + if (self.cacheOperation) { + [self.cacheOperation cancel]; + self.cacheOperation = nil; + } + if (self.cancelBlock) { + self.cancelBlock(); + + // TODO: this is a temporary fix to #809. + // Until we can figure the exact cause of the crash, going with the ivar instead of the setter +// self.cancelBlock = nil; + _cancelBlock = nil; + } +} + +@end + + +@implementation SDWebImageManager (Deprecated) + +// deprecated method, uses the non deprecated method +// adapter for the completion block +- (id )downloadWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedWithFinishedBlock)completedBlock { + return [self downloadImageWithURL:url + options:options + progress:progressBlock + completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { + if (completedBlock) { + completedBlock(image, error, cacheType, finished); + } + }]; +} + +@end diff --git a/IOS/Playground/Pods/SDWebImage/SDWebImage/SDWebImageOperation.h b/IOS/Playground/Pods/SDWebImage/SDWebImage/SDWebImageOperation.h new file mode 100644 index 00000000..71094ee3 --- /dev/null +++ b/IOS/Playground/Pods/SDWebImage/SDWebImage/SDWebImageOperation.h @@ -0,0 +1,15 @@ +/* + * This file is part of the SDWebImage package. + * (c) Olivier Poitrey + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +#import + +@protocol SDWebImageOperation + +- (void)cancel; + +@end diff --git a/IOS/Playground/Pods/SDWebImage/SDWebImage/SDWebImagePrefetcher.h b/IOS/Playground/Pods/SDWebImage/SDWebImage/SDWebImagePrefetcher.h new file mode 100644 index 00000000..6c31b15f --- /dev/null +++ b/IOS/Playground/Pods/SDWebImage/SDWebImage/SDWebImagePrefetcher.h @@ -0,0 +1,108 @@ +/* + * This file is part of the SDWebImage package. + * (c) Olivier Poitrey + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +#import +#import "SDWebImageManager.h" + +@class SDWebImagePrefetcher; + +@protocol SDWebImagePrefetcherDelegate + +@optional + +/** + * Called when an image was prefetched. + * + * @param imagePrefetcher The current image prefetcher + * @param imageURL The image url that was prefetched + * @param finishedCount The total number of images that were prefetched (successful or not) + * @param totalCount The total number of images that were to be prefetched + */ +- (void)imagePrefetcher:(SDWebImagePrefetcher *)imagePrefetcher didPrefetchURL:(NSURL *)imageURL finishedCount:(NSUInteger)finishedCount totalCount:(NSUInteger)totalCount; + +/** + * Called when all images are prefetched. + * @param imagePrefetcher The current image prefetcher + * @param totalCount The total number of images that were prefetched (whether successful or not) + * @param skippedCount The total number of images that were skipped + */ +- (void)imagePrefetcher:(SDWebImagePrefetcher *)imagePrefetcher didFinishWithTotalCount:(NSUInteger)totalCount skippedCount:(NSUInteger)skippedCount; + +@end + +typedef void(^SDWebImagePrefetcherProgressBlock)(NSUInteger noOfFinishedUrls, NSUInteger noOfTotalUrls); +typedef void(^SDWebImagePrefetcherCompletionBlock)(NSUInteger noOfFinishedUrls, NSUInteger noOfSkippedUrls); + +/** + * Prefetch some URLs in the cache for future use. Images are downloaded in low priority. + */ +@interface SDWebImagePrefetcher : NSObject + +/** + * The web image manager + */ +@property (strong, nonatomic, readonly) SDWebImageManager *manager; + +/** + * Maximum number of URLs to prefetch at the same time. Defaults to 3. + */ +@property (nonatomic, assign) NSUInteger maxConcurrentDownloads; + +/** + * SDWebImageOptions for prefetcher. Defaults to SDWebImageLowPriority. + */ +@property (nonatomic, assign) SDWebImageOptions options; + +/** + * Queue options for Prefetcher. Defaults to Main Queue. + */ +@property (nonatomic, assign) dispatch_queue_t prefetcherQueue; + +@property (weak, nonatomic) id delegate; + +/** + * Return the global image prefetcher instance. + */ ++ (SDWebImagePrefetcher *)sharedImagePrefetcher; + +/** + * Allows you to instantiate a prefetcher with any arbitrary image manager. + */ +- (id)initWithImageManager:(SDWebImageManager *)manager; + +/** + * Assign list of URLs to let SDWebImagePrefetcher to queue the prefetching, + * currently one image is downloaded at a time, + * and skips images for failed downloads and proceed to the next image in the list + * + * @param urls list of URLs to prefetch + */ +- (void)prefetchURLs:(NSArray *)urls; + +/** + * Assign list of URLs to let SDWebImagePrefetcher to queue the prefetching, + * currently one image is downloaded at a time, + * and skips images for failed downloads and proceed to the next image in the list + * + * @param urls list of URLs to prefetch + * @param progressBlock block to be called when progress updates; + * first parameter is the number of completed (successful or not) requests, + * second parameter is the total number of images originally requested to be prefetched + * @param completionBlock block to be called when prefetching is completed + * first param is the number of completed (successful or not) requests, + * second parameter is the number of skipped requests + */ +- (void)prefetchURLs:(NSArray *)urls progress:(SDWebImagePrefetcherProgressBlock)progressBlock completed:(SDWebImagePrefetcherCompletionBlock)completionBlock; + +/** + * Remove and cancel queued list + */ +- (void)cancelPrefetching; + + +@end diff --git a/IOS/Playground/Pods/SDWebImage/SDWebImage/SDWebImagePrefetcher.m b/IOS/Playground/Pods/SDWebImage/SDWebImage/SDWebImagePrefetcher.m new file mode 100644 index 00000000..f518d441 --- /dev/null +++ b/IOS/Playground/Pods/SDWebImage/SDWebImage/SDWebImagePrefetcher.m @@ -0,0 +1,140 @@ +/* + * This file is part of the SDWebImage package. + * (c) Olivier Poitrey + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +#import "SDWebImagePrefetcher.h" + +@interface SDWebImagePrefetcher () + +@property (strong, nonatomic) SDWebImageManager *manager; +@property (strong, nonatomic) NSArray *prefetchURLs; +@property (assign, nonatomic) NSUInteger requestedCount; +@property (assign, nonatomic) NSUInteger skippedCount; +@property (assign, nonatomic) NSUInteger finishedCount; +@property (assign, nonatomic) NSTimeInterval startedTime; +@property (copy, nonatomic) SDWebImagePrefetcherCompletionBlock completionBlock; +@property (copy, nonatomic) SDWebImagePrefetcherProgressBlock progressBlock; + +@end + +@implementation SDWebImagePrefetcher + ++ (SDWebImagePrefetcher *)sharedImagePrefetcher { + static dispatch_once_t once; + static id instance; + dispatch_once(&once, ^{ + instance = [self new]; + }); + return instance; +} + +- (id)init { + return [self initWithImageManager:[SDWebImageManager new]]; +} + +- (id)initWithImageManager:(SDWebImageManager *)manager { + if ((self = [super init])) { + _manager = manager; + _options = SDWebImageLowPriority; + _prefetcherQueue = dispatch_get_main_queue(); + self.maxConcurrentDownloads = 3; + } + return self; +} + +- (void)setMaxConcurrentDownloads:(NSUInteger)maxConcurrentDownloads { + self.manager.imageDownloader.maxConcurrentDownloads = maxConcurrentDownloads; +} + +- (NSUInteger)maxConcurrentDownloads { + return self.manager.imageDownloader.maxConcurrentDownloads; +} + +- (void)startPrefetchingAtIndex:(NSUInteger)index { + if (index >= self.prefetchURLs.count) return; + self.requestedCount++; + [self.manager downloadImageWithURL:self.prefetchURLs[index] options:self.options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { + if (!finished) return; + self.finishedCount++; + + if (image) { + if (self.progressBlock) { + self.progressBlock(self.finishedCount,[self.prefetchURLs count]); + } + } + else { + if (self.progressBlock) { + self.progressBlock(self.finishedCount,[self.prefetchURLs count]); + } + // Add last failed + self.skippedCount++; + } + if ([self.delegate respondsToSelector:@selector(imagePrefetcher:didPrefetchURL:finishedCount:totalCount:)]) { + [self.delegate imagePrefetcher:self + didPrefetchURL:self.prefetchURLs[index] + finishedCount:self.finishedCount + totalCount:self.prefetchURLs.count + ]; + } + if (self.prefetchURLs.count > self.requestedCount) { + dispatch_async(self.prefetcherQueue, ^{ + [self startPrefetchingAtIndex:self.requestedCount]; + }); + } else if (self.finishedCount == self.requestedCount) { + [self reportStatus]; + if (self.completionBlock) { + self.completionBlock(self.finishedCount, self.skippedCount); + self.completionBlock = nil; + } + self.progressBlock = nil; + } + }]; +} + +- (void)reportStatus { + NSUInteger total = [self.prefetchURLs count]; + if ([self.delegate respondsToSelector:@selector(imagePrefetcher:didFinishWithTotalCount:skippedCount:)]) { + [self.delegate imagePrefetcher:self + didFinishWithTotalCount:(total - self.skippedCount) + skippedCount:self.skippedCount + ]; + } +} + +- (void)prefetchURLs:(NSArray *)urls { + [self prefetchURLs:urls progress:nil completed:nil]; +} + +- (void)prefetchURLs:(NSArray *)urls progress:(SDWebImagePrefetcherProgressBlock)progressBlock completed:(SDWebImagePrefetcherCompletionBlock)completionBlock { + [self cancelPrefetching]; // Prevent duplicate prefetch request + self.startedTime = CFAbsoluteTimeGetCurrent(); + self.prefetchURLs = urls; + self.completionBlock = completionBlock; + self.progressBlock = progressBlock; + + if (urls.count == 0) { + if (completionBlock) { + completionBlock(0,0); + } + } else { + // Starts prefetching from the very first image on the list with the max allowed concurrency + NSUInteger listCount = self.prefetchURLs.count; + for (NSUInteger i = 0; i < self.maxConcurrentDownloads && self.requestedCount < listCount; i++) { + [self startPrefetchingAtIndex:i]; + } + } +} + +- (void)cancelPrefetching { + self.prefetchURLs = nil; + self.skippedCount = 0; + self.requestedCount = 0; + self.finishedCount = 0; + [self.manager cancelAll]; +} + +@end diff --git a/IOS/Playground/Pods/SDWebImage/SDWebImage/UIButton+WebCache.h b/IOS/Playground/Pods/SDWebImage/SDWebImage/UIButton+WebCache.h new file mode 100644 index 00000000..ecf5ced3 --- /dev/null +++ b/IOS/Playground/Pods/SDWebImage/SDWebImage/UIButton+WebCache.h @@ -0,0 +1,229 @@ +/* + * This file is part of the SDWebImage package. + * (c) Olivier Poitrey + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +#import "SDWebImageCompat.h" +#import "SDWebImageManager.h" + +/** + * Integrates SDWebImage async downloading and caching of remote images with UIButtonView. + */ +@interface UIButton (WebCache) + +/** + * Get the current image URL. + */ +- (NSURL *)sd_currentImageURL; + +/** + * Get the image URL for a control state. + * + * @param state Which state you want to know the URL for. The values are described in UIControlState. + */ +- (NSURL *)sd_imageURLForState:(UIControlState)state; + +/** + * Set the imageView `image` with an `url`. + * + * The download is asynchronous and cached. + * + * @param url The url for the image. + * @param state The state that uses the specified title. The values are described in UIControlState. + */ +- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state; + +/** + * Set the imageView `image` with an `url` and a placeholder. + * + * The download is asynchronous and cached. + * + * @param url The url for the image. + * @param state The state that uses the specified title. The values are described in UIControlState. + * @param placeholder The image to be set initially, until the image request finishes. + * @see sd_setImageWithURL:placeholderImage:options: + */ +- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder; + +/** + * Set the imageView `image` with an `url`, placeholder and custom options. + * + * The download is asynchronous and cached. + * + * @param url The url for the image. + * @param state The state that uses the specified title. The values are described in UIControlState. + * @param placeholder The image to be set initially, until the image request finishes. + * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. + */ +- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options; + +/** + * Set the imageView `image` with an `url`. + * + * The download is asynchronous and cached. + * + * @param url The url for the image. + * @param state The state that uses the specified title. The values are described in UIControlState. + * @param completedBlock A block called when operation has been completed. This block has no return value + * and takes the requested UIImage as first parameter. In case of error the image parameter + * is nil and the second parameter may contain an NSError. The third parameter is a Boolean + * indicating if the image was retrieved from the local cache or from the network. + * The fourth parameter is the original image url. + */ +- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletionBlock)completedBlock; + +/** + * Set the imageView `image` with an `url`, placeholder. + * + * The download is asynchronous and cached. + * + * @param url The url for the image. + * @param state The state that uses the specified title. The values are described in UIControlState. + * @param placeholder The image to be set initially, until the image request finishes. + * @param completedBlock A block called when operation has been completed. This block has no return value + * and takes the requested UIImage as first parameter. In case of error the image parameter + * is nil and the second parameter may contain an NSError. The third parameter is a Boolean + * indicating if the image was retrieved from the local cache or from the network. + * The fourth parameter is the original image url. + */ +- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock; + +/** + * Set the imageView `image` with an `url`, placeholder and custom options. + * + * The download is asynchronous and cached. + * + * @param url The url for the image. + * @param state The state that uses the specified title. The values are described in UIControlState. + * @param placeholder The image to be set initially, until the image request finishes. + * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. + * @param completedBlock A block called when operation has been completed. This block has no return value + * and takes the requested UIImage as first parameter. In case of error the image parameter + * is nil and the second parameter may contain an NSError. The third parameter is a Boolean + * indicating if the image was retrieved from the local cache or from the network. + * The fourth parameter is the original image url. + */ +- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock; + +/** + * Set the backgroundImageView `image` with an `url`. + * + * The download is asynchronous and cached. + * + * @param url The url for the image. + * @param state The state that uses the specified title. The values are described in UIControlState. + */ +- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state; + +/** + * Set the backgroundImageView `image` with an `url` and a placeholder. + * + * The download is asynchronous and cached. + * + * @param url The url for the image. + * @param state The state that uses the specified title. The values are described in UIControlState. + * @param placeholder The image to be set initially, until the image request finishes. + * @see sd_setImageWithURL:placeholderImage:options: + */ +- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder; + +/** + * Set the backgroundImageView `image` with an `url`, placeholder and custom options. + * + * The download is asynchronous and cached. + * + * @param url The url for the image. + * @param state The state that uses the specified title. The values are described in UIControlState. + * @param placeholder The image to be set initially, until the image request finishes. + * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. + */ +- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options; + +/** + * Set the backgroundImageView `image` with an `url`. + * + * The download is asynchronous and cached. + * + * @param url The url for the image. + * @param state The state that uses the specified title. The values are described in UIControlState. + * @param completedBlock A block called when operation has been completed. This block has no return value + * and takes the requested UIImage as first parameter. In case of error the image parameter + * is nil and the second parameter may contain an NSError. The third parameter is a Boolean + * indicating if the image was retrieved from the local cache or from the network. + * The fourth parameter is the original image url. + */ +- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletionBlock)completedBlock; + +/** + * Set the backgroundImageView `image` with an `url`, placeholder. + * + * The download is asynchronous and cached. + * + * @param url The url for the image. + * @param state The state that uses the specified title. The values are described in UIControlState. + * @param placeholder The image to be set initially, until the image request finishes. + * @param completedBlock A block called when operation has been completed. This block has no return value + * and takes the requested UIImage as first parameter. In case of error the image parameter + * is nil and the second parameter may contain an NSError. The third parameter is a Boolean + * indicating if the image was retrieved from the local cache or from the network. + * The fourth parameter is the original image url. + */ +- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock; + +/** + * Set the backgroundImageView `image` with an `url`, placeholder and custom options. + * + * The download is asynchronous and cached. + * + * @param url The url for the image. + * @param placeholder The image to be set initially, until the image request finishes. + * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. + * @param completedBlock A block called when operation has been completed. This block has no return value + * and takes the requested UIImage as first parameter. In case of error the image parameter + * is nil and the second parameter may contain an NSError. The third parameter is a Boolean + * indicating if the image was retrieved from the local cache or from the network. + * The fourth parameter is the original image url. + */ +- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock; + +/** + * Cancel the current image download + */ +- (void)sd_cancelImageLoadForState:(UIControlState)state; + +/** + * Cancel the current backgroundImage download + */ +- (void)sd_cancelBackgroundImageLoadForState:(UIControlState)state; + +@end + + +@interface UIButton (WebCacheDeprecated) + +- (NSURL *)currentImageURL __deprecated_msg("Use `sd_currentImageURL`"); +- (NSURL *)imageURLForState:(UIControlState)state __deprecated_msg("Use `sd_imageURLForState:`"); + +- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:forState:`"); +- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:forState:placeholderImage:`"); +- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:forState:placeholderImage:options:`"); + +- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:forState:completed:`"); +- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:forState:placeholderImage:completed:`"); +- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:forState:placeholderImage:options:completed:`"); + +- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state __deprecated_msg("Method deprecated. Use `sd_setBackgroundImageWithURL:forState:`"); +- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder __deprecated_msg("Method deprecated. Use `sd_setBackgroundImageWithURL:forState:placeholderImage:`"); +- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options __deprecated_msg("Method deprecated. Use `sd_setBackgroundImageWithURL:forState:placeholderImage:options:`"); + +- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setBackgroundImageWithURL:forState:completed:`"); +- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setBackgroundImageWithURL:forState:placeholderImage:completed:`"); +- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setBackgroundImageWithURL:forState:placeholderImage:options:completed:`"); + +- (void)cancelCurrentImageLoad __deprecated_msg("Use `sd_cancelImageLoadForState:`"); +- (void)cancelBackgroundImageLoadForState:(UIControlState)state __deprecated_msg("Use `sd_cancelBackgroundImageLoadForState:`"); + +@end diff --git a/IOS/Playground/Pods/SDWebImage/SDWebImage/UIButton+WebCache.m b/IOS/Playground/Pods/SDWebImage/SDWebImage/UIButton+WebCache.m new file mode 100644 index 00000000..ce2175d2 --- /dev/null +++ b/IOS/Playground/Pods/SDWebImage/SDWebImage/UIButton+WebCache.m @@ -0,0 +1,270 @@ +/* + * This file is part of the SDWebImage package. + * (c) Olivier Poitrey + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +#import "UIButton+WebCache.h" +#import "objc/runtime.h" +#import "UIView+WebCacheOperation.h" + +static char imageURLStorageKey; + +@implementation UIButton (WebCache) + +- (NSURL *)sd_currentImageURL { + NSURL *url = self.imageURLStorage[@(self.state)]; + + if (!url) { + url = self.imageURLStorage[@(UIControlStateNormal)]; + } + + return url; +} + +- (NSURL *)sd_imageURLForState:(UIControlState)state { + return self.imageURLStorage[@(state)]; +} + +- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state { + [self sd_setImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil]; +} + +- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder { + [self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:nil]; +} + +- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options { + [self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:options completed:nil]; +} + +- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletionBlock)completedBlock { + [self sd_setImageWithURL:url forState:state placeholderImage:nil options:0 completed:completedBlock]; +} + +- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock { + [self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:completedBlock]; +} + +- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock { + + [self setImage:placeholder forState:state]; + [self sd_cancelImageLoadForState:state]; + + if (!url) { + [self.imageURLStorage removeObjectForKey:@(state)]; + + dispatch_main_async_safe(^{ + if (completedBlock) { + NSError *error = [NSError errorWithDomain:SDWebImageErrorDomain code:-1 userInfo:@{NSLocalizedDescriptionKey : @"Trying to load a nil url"}]; + completedBlock(nil, error, SDImageCacheTypeNone, url); + } + }); + + return; + } + + self.imageURLStorage[@(state)] = url; + + __weak __typeof(self)wself = self; + id operation = [SDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { + if (!wself) return; + dispatch_main_sync_safe(^{ + __strong UIButton *sself = wself; + if (!sself) return; + if (image && (options & SDWebImageAvoidAutoSetImage) && completedBlock) + { + completedBlock(image, error, cacheType, url); + return; + } + else if (image) { + [sself setImage:image forState:state]; + } + if (completedBlock && finished) { + completedBlock(image, error, cacheType, url); + } + }); + }]; + [self sd_setImageLoadOperation:operation forState:state]; +} + +- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state { + [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil]; +} + +- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder { + [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:nil]; +} + +- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options { + [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:options completed:nil]; +} + +- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletionBlock)completedBlock { + [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:nil options:0 completed:completedBlock]; +} + +- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock { + [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:completedBlock]; +} + +- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock { + [self sd_cancelBackgroundImageLoadForState:state]; + + [self setBackgroundImage:placeholder forState:state]; + + if (url) { + __weak __typeof(self)wself = self; + id operation = [SDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { + if (!wself) return; + dispatch_main_sync_safe(^{ + __strong UIButton *sself = wself; + if (!sself) return; + if (image && (options & SDWebImageAvoidAutoSetImage) && completedBlock) + { + completedBlock(image, error, cacheType, url); + return; + } + else if (image) { + [sself setBackgroundImage:image forState:state]; + } + if (completedBlock && finished) { + completedBlock(image, error, cacheType, url); + } + }); + }]; + [self sd_setBackgroundImageLoadOperation:operation forState:state]; + } else { + dispatch_main_async_safe(^{ + NSError *error = [NSError errorWithDomain:SDWebImageErrorDomain code:-1 userInfo:@{NSLocalizedDescriptionKey : @"Trying to load a nil url"}]; + if (completedBlock) { + completedBlock(nil, error, SDImageCacheTypeNone, url); + } + }); + } +} + +- (void)sd_setImageLoadOperation:(id)operation forState:(UIControlState)state { + [self sd_setImageLoadOperation:operation forKey:[NSString stringWithFormat:@"UIButtonImageOperation%@", @(state)]]; +} + +- (void)sd_cancelImageLoadForState:(UIControlState)state { + [self sd_cancelImageLoadOperationWithKey:[NSString stringWithFormat:@"UIButtonImageOperation%@", @(state)]]; +} + +- (void)sd_setBackgroundImageLoadOperation:(id)operation forState:(UIControlState)state { + [self sd_setImageLoadOperation:operation forKey:[NSString stringWithFormat:@"UIButtonBackgroundImageOperation%@", @(state)]]; +} + +- (void)sd_cancelBackgroundImageLoadForState:(UIControlState)state { + [self sd_cancelImageLoadOperationWithKey:[NSString stringWithFormat:@"UIButtonBackgroundImageOperation%@", @(state)]]; +} + +- (NSMutableDictionary *)imageURLStorage { + NSMutableDictionary *storage = objc_getAssociatedObject(self, &imageURLStorageKey); + if (!storage) + { + storage = [NSMutableDictionary dictionary]; + objc_setAssociatedObject(self, &imageURLStorageKey, storage, OBJC_ASSOCIATION_RETAIN_NONATOMIC); + } + + return storage; +} + +@end + + +@implementation UIButton (WebCacheDeprecated) + +- (NSURL *)currentImageURL { + return [self sd_currentImageURL]; +} + +- (NSURL *)imageURLForState:(UIControlState)state { + return [self sd_imageURLForState:state]; +} + +- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state { + [self sd_setImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil]; +} + +- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder { + [self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:nil]; +} + +- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options { + [self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:options completed:nil]; +} + +- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletedBlock)completedBlock { + [self sd_setImageWithURL:url forState:state placeholderImage:nil options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { + if (completedBlock) { + completedBlock(image, error, cacheType); + } + }]; +} + +- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock { + [self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { + if (completedBlock) { + completedBlock(image, error, cacheType); + } + }]; +} + +- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock { + [self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:options completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { + if (completedBlock) { + completedBlock(image, error, cacheType); + } + }]; +} + +- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state { + [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil]; +} + +- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder { + [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:nil]; +} + +- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options { + [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:options completed:nil]; +} + +- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletedBlock)completedBlock { + [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:nil options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { + if (completedBlock) { + completedBlock(image, error, cacheType); + } + }]; +} + +- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock { + [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { + if (completedBlock) { + completedBlock(image, error, cacheType); + } + }]; +} + +- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock { + [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:options completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { + if (completedBlock) { + completedBlock(image, error, cacheType); + } + }]; +} + +- (void)cancelCurrentImageLoad { + // in a backwards compatible manner, cancel for current state + [self sd_cancelImageLoadForState:self.state]; +} + +- (void)cancelBackgroundImageLoadForState:(UIControlState)state { + [self sd_cancelBackgroundImageLoadForState:state]; +} + +@end diff --git a/IOS/Playground/Pods/SDWebImage/SDWebImage/UIImage+GIF.h b/IOS/Playground/Pods/SDWebImage/SDWebImage/UIImage+GIF.h new file mode 100755 index 00000000..084f4241 --- /dev/null +++ b/IOS/Playground/Pods/SDWebImage/SDWebImage/UIImage+GIF.h @@ -0,0 +1,19 @@ +// +// UIImage+GIF.h +// LBGIFImage +// +// Created by Laurin Brandner on 06.01.12. +// Copyright (c) 2012 __MyCompanyName__. All rights reserved. +// + +#import + +@interface UIImage (GIF) + ++ (UIImage *)sd_animatedGIFNamed:(NSString *)name; + ++ (UIImage *)sd_animatedGIFWithData:(NSData *)data; + +- (UIImage *)sd_animatedImageByScalingAndCroppingToSize:(CGSize)size; + +@end diff --git a/IOS/Playground/Pods/SDWebImage/SDWebImage/UIImage+GIF.m b/IOS/Playground/Pods/SDWebImage/SDWebImage/UIImage+GIF.m new file mode 100755 index 00000000..bf74a367 --- /dev/null +++ b/IOS/Playground/Pods/SDWebImage/SDWebImage/UIImage+GIF.m @@ -0,0 +1,161 @@ +// +// UIImage+GIF.m +// LBGIFImage +// +// Created by Laurin Brandner on 06.01.12. +// Copyright (c) 2012 __MyCompanyName__. All rights reserved. +// + +#import "UIImage+GIF.h" +#import + +@implementation UIImage (GIF) + ++ (UIImage *)sd_animatedGIFWithData:(NSData *)data { + if (!data) { + return nil; + } + + CGImageSourceRef source = CGImageSourceCreateWithData((__bridge CFDataRef)data, NULL); + + size_t count = CGImageSourceGetCount(source); + + UIImage *animatedImage; + + if (count <= 1) { + animatedImage = [[UIImage alloc] initWithData:data]; + } + else { + NSMutableArray *images = [NSMutableArray array]; + + NSTimeInterval duration = 0.0f; + + for (size_t i = 0; i < count; i++) { + CGImageRef image = CGImageSourceCreateImageAtIndex(source, i, NULL); + if (!image) { + continue; + } + + duration += [self sd_frameDurationAtIndex:i source:source]; + + [images addObject:[UIImage imageWithCGImage:image scale:[UIScreen mainScreen].scale orientation:UIImageOrientationUp]]; + + CGImageRelease(image); + } + + if (!duration) { + duration = (1.0f / 10.0f) * count; + } + + animatedImage = [UIImage animatedImageWithImages:images duration:duration]; + } + + CFRelease(source); + + return animatedImage; +} + ++ (float)sd_frameDurationAtIndex:(NSUInteger)index source:(CGImageSourceRef)source { + float frameDuration = 0.1f; + CFDictionaryRef cfFrameProperties = CGImageSourceCopyPropertiesAtIndex(source, index, nil); + NSDictionary *frameProperties = (__bridge NSDictionary *)cfFrameProperties; + NSDictionary *gifProperties = frameProperties[(NSString *)kCGImagePropertyGIFDictionary]; + + NSNumber *delayTimeUnclampedProp = gifProperties[(NSString *)kCGImagePropertyGIFUnclampedDelayTime]; + if (delayTimeUnclampedProp) { + frameDuration = [delayTimeUnclampedProp floatValue]; + } + else { + + NSNumber *delayTimeProp = gifProperties[(NSString *)kCGImagePropertyGIFDelayTime]; + if (delayTimeProp) { + frameDuration = [delayTimeProp floatValue]; + } + } + + // Many annoying ads specify a 0 duration to make an image flash as quickly as possible. + // We follow Firefox's behavior and use a duration of 100 ms for any frames that specify + // a duration of <= 10 ms. See and + // for more information. + + if (frameDuration < 0.011f) { + frameDuration = 0.100f; + } + + CFRelease(cfFrameProperties); + return frameDuration; +} + ++ (UIImage *)sd_animatedGIFNamed:(NSString *)name { + CGFloat scale = [UIScreen mainScreen].scale; + + if (scale > 1.0f) { + NSString *retinaPath = [[NSBundle mainBundle] pathForResource:[name stringByAppendingString:@"@2x"] ofType:@"gif"]; + + NSData *data = [NSData dataWithContentsOfFile:retinaPath]; + + if (data) { + return [UIImage sd_animatedGIFWithData:data]; + } + + NSString *path = [[NSBundle mainBundle] pathForResource:name ofType:@"gif"]; + + data = [NSData dataWithContentsOfFile:path]; + + if (data) { + return [UIImage sd_animatedGIFWithData:data]; + } + + return [UIImage imageNamed:name]; + } + else { + NSString *path = [[NSBundle mainBundle] pathForResource:name ofType:@"gif"]; + + NSData *data = [NSData dataWithContentsOfFile:path]; + + if (data) { + return [UIImage sd_animatedGIFWithData:data]; + } + + return [UIImage imageNamed:name]; + } +} + +- (UIImage *)sd_animatedImageByScalingAndCroppingToSize:(CGSize)size { + if (CGSizeEqualToSize(self.size, size) || CGSizeEqualToSize(size, CGSizeZero)) { + return self; + } + + CGSize scaledSize = size; + CGPoint thumbnailPoint = CGPointZero; + + CGFloat widthFactor = size.width / self.size.width; + CGFloat heightFactor = size.height / self.size.height; + CGFloat scaleFactor = (widthFactor > heightFactor) ? widthFactor : heightFactor; + scaledSize.width = self.size.width * scaleFactor; + scaledSize.height = self.size.height * scaleFactor; + + if (widthFactor > heightFactor) { + thumbnailPoint.y = (size.height - scaledSize.height) * 0.5; + } + else if (widthFactor < heightFactor) { + thumbnailPoint.x = (size.width - scaledSize.width) * 0.5; + } + + NSMutableArray *scaledImages = [NSMutableArray array]; + + for (UIImage *image in self.images) { + UIGraphicsBeginImageContextWithOptions(size, NO, 0.0); + + [image drawInRect:CGRectMake(thumbnailPoint.x, thumbnailPoint.y, scaledSize.width, scaledSize.height)]; + UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); + + [scaledImages addObject:newImage]; + + UIGraphicsEndImageContext(); + } + + return [UIImage animatedImageWithImages:scaledImages duration:self.duration]; +} + +@end diff --git a/IOS/Playground/Pods/SDWebImage/SDWebImage/UIImage+MultiFormat.h b/IOS/Playground/Pods/SDWebImage/SDWebImage/UIImage+MultiFormat.h new file mode 100644 index 00000000..186ebc0a --- /dev/null +++ b/IOS/Playground/Pods/SDWebImage/SDWebImage/UIImage+MultiFormat.h @@ -0,0 +1,15 @@ +// +// UIImage+MultiFormat.h +// SDWebImage +// +// Created by Olivier Poitrey on 07/06/13. +// Copyright (c) 2013 Dailymotion. All rights reserved. +// + +#import + +@interface UIImage (MultiFormat) + ++ (UIImage *)sd_imageWithData:(NSData *)data; + +@end diff --git a/IOS/Playground/Pods/SDWebImage/SDWebImage/UIImage+MultiFormat.m b/IOS/Playground/Pods/SDWebImage/SDWebImage/UIImage+MultiFormat.m new file mode 100644 index 00000000..a8307544 --- /dev/null +++ b/IOS/Playground/Pods/SDWebImage/SDWebImage/UIImage+MultiFormat.m @@ -0,0 +1,118 @@ +// +// UIImage+MultiFormat.m +// SDWebImage +// +// Created by Olivier Poitrey on 07/06/13. +// Copyright (c) 2013 Dailymotion. All rights reserved. +// + +#import "UIImage+MultiFormat.h" +#import "UIImage+GIF.h" +#import "NSData+ImageContentType.h" +#import + +#ifdef SD_WEBP +#import "UIImage+WebP.h" +#endif + +@implementation UIImage (MultiFormat) + ++ (UIImage *)sd_imageWithData:(NSData *)data { + if (!data) { + return nil; + } + + UIImage *image; + NSString *imageContentType = [NSData sd_contentTypeForImageData:data]; + if ([imageContentType isEqualToString:@"image/gif"]) { + image = [UIImage sd_animatedGIFWithData:data]; + } +#ifdef SD_WEBP + else if ([imageContentType isEqualToString:@"image/webp"]) + { + image = [UIImage sd_imageWithWebPData:data]; + } +#endif + else { + image = [[UIImage alloc] initWithData:data]; + UIImageOrientation orientation = [self sd_imageOrientationFromImageData:data]; + if (orientation != UIImageOrientationUp) { + image = [UIImage imageWithCGImage:image.CGImage + scale:image.scale + orientation:orientation]; + } + } + + + return image; +} + + ++(UIImageOrientation)sd_imageOrientationFromImageData:(NSData *)imageData { + UIImageOrientation result = UIImageOrientationUp; + CGImageSourceRef imageSource = CGImageSourceCreateWithData((__bridge CFDataRef)imageData, NULL); + if (imageSource) { + CFDictionaryRef properties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, NULL); + if (properties) { + CFTypeRef val; + int exifOrientation; + val = CFDictionaryGetValue(properties, kCGImagePropertyOrientation); + if (val) { + CFNumberGetValue(val, kCFNumberIntType, &exifOrientation); + result = [self sd_exifOrientationToiOSOrientation:exifOrientation]; + } // else - if it's not set it remains at up + CFRelease((CFTypeRef) properties); + } else { + //NSLog(@"NO PROPERTIES, FAIL"); + } + CFRelease(imageSource); + } + return result; +} + +#pragma mark EXIF orientation tag converter +// Convert an EXIF image orientation to an iOS one. +// reference see here: http://sylvana.net/jpegcrop/exif_orientation.html ++ (UIImageOrientation) sd_exifOrientationToiOSOrientation:(int)exifOrientation { + UIImageOrientation orientation = UIImageOrientationUp; + switch (exifOrientation) { + case 1: + orientation = UIImageOrientationUp; + break; + + case 3: + orientation = UIImageOrientationDown; + break; + + case 8: + orientation = UIImageOrientationLeft; + break; + + case 6: + orientation = UIImageOrientationRight; + break; + + case 2: + orientation = UIImageOrientationUpMirrored; + break; + + case 4: + orientation = UIImageOrientationDownMirrored; + break; + + case 5: + orientation = UIImageOrientationLeftMirrored; + break; + + case 7: + orientation = UIImageOrientationRightMirrored; + break; + default: + break; + } + return orientation; +} + + + +@end diff --git a/IOS/Playground/Pods/SDWebImage/SDWebImage/UIImageView+HighlightedWebCache.h b/IOS/Playground/Pods/SDWebImage/SDWebImage/UIImageView+HighlightedWebCache.h new file mode 100644 index 00000000..c1d8feaf --- /dev/null +++ b/IOS/Playground/Pods/SDWebImage/SDWebImage/UIImageView+HighlightedWebCache.h @@ -0,0 +1,100 @@ +/* + * This file is part of the SDWebImage package. + * (c) Olivier Poitrey + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +#import +#import "SDWebImageCompat.h" +#import "SDWebImageManager.h" + +/** + * Integrates SDWebImage async downloading and caching of remote images with UIImageView for highlighted state. + */ +@interface UIImageView (HighlightedWebCache) + +/** + * Set the imageView `highlightedImage` with an `url`. + * + * The download is asynchronous and cached. + * + * @param url The url for the image. + */ +- (void)sd_setHighlightedImageWithURL:(NSURL *)url; + +/** + * Set the imageView `highlightedImage` with an `url` and custom options. + * + * The download is asynchronous and cached. + * + * @param url The url for the image. + * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. + */ +- (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options; + +/** + * Set the imageView `highlightedImage` with an `url`. + * + * The download is asynchronous and cached. + * + * @param url The url for the image. + * @param completedBlock A block called when operation has been completed. This block has no return value + * and takes the requested UIImage as first parameter. In case of error the image parameter + * is nil and the second parameter may contain an NSError. The third parameter is a Boolean + * indicating if the image was retrieved from the local cache or from the network. + * The fourth parameter is the original image url. + */ +- (void)sd_setHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock; + +/** + * Set the imageView `highlightedImage` with an `url` and custom options. + * + * The download is asynchronous and cached. + * + * @param url The url for the image. + * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. + * @param completedBlock A block called when operation has been completed. This block has no return value + * and takes the requested UIImage as first parameter. In case of error the image parameter + * is nil and the second parameter may contain an NSError. The third parameter is a Boolean + * indicating if the image was retrieved from the local cache or from the network. + * The fourth parameter is the original image url. + */ +- (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock; + +/** + * Set the imageView `highlightedImage` with an `url` and custom options. + * + * The download is asynchronous and cached. + * + * @param url The url for the image. + * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. + * @param progressBlock A block called while image is downloading + * @param completedBlock A block called when operation has been completed. This block has no return value + * and takes the requested UIImage as first parameter. In case of error the image parameter + * is nil and the second parameter may contain an NSError. The third parameter is a Boolean + * indicating if the image was retrieved from the local cache or from the network. + * The fourth parameter is the original image url. + */ +- (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock; + +/** + * Cancel the current download + */ +- (void)sd_cancelCurrentHighlightedImageLoad; + +@end + + +@interface UIImageView (HighlightedWebCacheDeprecated) + +- (void)setHighlightedImageWithURL:(NSURL *)url __deprecated_msg("Method deprecated. Use `sd_setHighlightedImageWithURL:`"); +- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options __deprecated_msg("Method deprecated. Use `sd_setHighlightedImageWithURL:options:`"); +- (void)setHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setHighlightedImageWithURL:completed:`"); +- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setHighlightedImageWithURL:options:completed:`"); +- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setHighlightedImageWithURL:options:progress:completed:`"); + +- (void)cancelCurrentHighlightedImageLoad __deprecated_msg("Use `sd_cancelCurrentHighlightedImageLoad`"); + +@end diff --git a/IOS/Playground/Pods/SDWebImage/SDWebImage/UIImageView+HighlightedWebCache.m b/IOS/Playground/Pods/SDWebImage/SDWebImage/UIImageView+HighlightedWebCache.m new file mode 100644 index 00000000..921134e5 --- /dev/null +++ b/IOS/Playground/Pods/SDWebImage/SDWebImage/UIImageView+HighlightedWebCache.m @@ -0,0 +1,112 @@ +/* + * This file is part of the SDWebImage package. + * (c) Olivier Poitrey + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +#import "UIImageView+HighlightedWebCache.h" +#import "UIView+WebCacheOperation.h" + +#define UIImageViewHighlightedWebCacheOperationKey @"highlightedImage" + +@implementation UIImageView (HighlightedWebCache) + +- (void)sd_setHighlightedImageWithURL:(NSURL *)url { + [self sd_setHighlightedImageWithURL:url options:0 progress:nil completed:nil]; +} + +- (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options { + [self sd_setHighlightedImageWithURL:url options:options progress:nil completed:nil]; +} + +- (void)sd_setHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock { + [self sd_setHighlightedImageWithURL:url options:0 progress:nil completed:completedBlock]; +} + +- (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock { + [self sd_setHighlightedImageWithURL:url options:options progress:nil completed:completedBlock]; +} + +- (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock { + [self sd_cancelCurrentHighlightedImageLoad]; + + if (url) { + __weak __typeof(self)wself = self; + id operation = [SDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { + if (!wself) return; + dispatch_main_sync_safe (^ + { + if (!wself) return; + if (image && (options & SDWebImageAvoidAutoSetImage) && completedBlock) + { + completedBlock(image, error, cacheType, url); + return; + } + else if (image) { + wself.highlightedImage = image; + [wself setNeedsLayout]; + } + if (completedBlock && finished) { + completedBlock(image, error, cacheType, url); + } + }); + }]; + [self sd_setImageLoadOperation:operation forKey:UIImageViewHighlightedWebCacheOperationKey]; + } else { + dispatch_main_async_safe(^{ + NSError *error = [NSError errorWithDomain:SDWebImageErrorDomain code:-1 userInfo:@{NSLocalizedDescriptionKey : @"Trying to load a nil url"}]; + if (completedBlock) { + completedBlock(nil, error, SDImageCacheTypeNone, url); + } + }); + } +} + +- (void)sd_cancelCurrentHighlightedImageLoad { + [self sd_cancelImageLoadOperationWithKey:UIImageViewHighlightedWebCacheOperationKey]; +} + +@end + + +@implementation UIImageView (HighlightedWebCacheDeprecated) + +- (void)setHighlightedImageWithURL:(NSURL *)url { + [self sd_setHighlightedImageWithURL:url options:0 progress:nil completed:nil]; +} + +- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options { + [self sd_setHighlightedImageWithURL:url options:options progress:nil completed:nil]; +} + +- (void)setHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock { + [self sd_setHighlightedImageWithURL:url options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { + if (completedBlock) { + completedBlock(image, error, cacheType); + } + }]; +} + +- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock { + [self sd_setHighlightedImageWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { + if (completedBlock) { + completedBlock(image, error, cacheType); + } + }]; +} + +- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock { + [self sd_setHighlightedImageWithURL:url options:0 progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { + if (completedBlock) { + completedBlock(image, error, cacheType); + } + }]; +} + +- (void)cancelCurrentHighlightedImageLoad { + [self sd_cancelCurrentHighlightedImageLoad]; +} + +@end diff --git a/IOS/Playground/Pods/SDWebImage/SDWebImage/UIImageView+WebCache.h b/IOS/Playground/Pods/SDWebImage/SDWebImage/UIImageView+WebCache.h new file mode 100644 index 00000000..37ae1eb3 --- /dev/null +++ b/IOS/Playground/Pods/SDWebImage/SDWebImage/UIImageView+WebCache.h @@ -0,0 +1,215 @@ +/* + * This file is part of the SDWebImage package. + * (c) Olivier Poitrey + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +#import "SDWebImageCompat.h" +#import "SDWebImageManager.h" + +/** + * Integrates SDWebImage async downloading and caching of remote images with UIImageView. + * + * Usage with a UITableViewCell sub-class: + * + * @code + +#import + +... + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath +{ + static NSString *MyIdentifier = @"MyIdentifier"; + + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier]; + + if (cell == nil) { + cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier] + autorelease]; + } + + // Here we use the provided sd_setImageWithURL: method to load the web image + // Ensure you use a placeholder image otherwise cells will be initialized with no image + [cell.imageView sd_setImageWithURL:[NSURL URLWithString:@"http://example.com/image.jpg"] + placeholderImage:[UIImage imageNamed:@"placeholder"]]; + + cell.textLabel.text = @"My Text"; + return cell; +} + + * @endcode + */ +@interface UIImageView (WebCache) + +/** + * Get the current image URL. + * + * Note that because of the limitations of categories this property can get out of sync + * if you use sd_setImage: directly. + */ +- (NSURL *)sd_imageURL; + +/** + * Set the imageView `image` with an `url`. + * + * The download is asynchronous and cached. + * + * @param url The url for the image. + */ +- (void)sd_setImageWithURL:(NSURL *)url; + +/** + * Set the imageView `image` with an `url` and a placeholder. + * + * The download is asynchronous and cached. + * + * @param url The url for the image. + * @param placeholder The image to be set initially, until the image request finishes. + * @see sd_setImageWithURL:placeholderImage:options: + */ +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder; + +/** + * Set the imageView `image` with an `url`, placeholder and custom options. + * + * The download is asynchronous and cached. + * + * @param url The url for the image. + * @param placeholder The image to be set initially, until the image request finishes. + * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. + */ +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options; + +/** + * Set the imageView `image` with an `url`. + * + * The download is asynchronous and cached. + * + * @param url The url for the image. + * @param completedBlock A block called when operation has been completed. This block has no return value + * and takes the requested UIImage as first parameter. In case of error the image parameter + * is nil and the second parameter may contain an NSError. The third parameter is a Boolean + * indicating if the image was retrieved from the local cache or from the network. + * The fourth parameter is the original image url. + */ +- (void)sd_setImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock; + +/** + * Set the imageView `image` with an `url`, placeholder. + * + * The download is asynchronous and cached. + * + * @param url The url for the image. + * @param placeholder The image to be set initially, until the image request finishes. + * @param completedBlock A block called when operation has been completed. This block has no return value + * and takes the requested UIImage as first parameter. In case of error the image parameter + * is nil and the second parameter may contain an NSError. The third parameter is a Boolean + * indicating if the image was retrieved from the local cache or from the network. + * The fourth parameter is the original image url. + */ +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock; + +/** + * Set the imageView `image` with an `url`, placeholder and custom options. + * + * The download is asynchronous and cached. + * + * @param url The url for the image. + * @param placeholder The image to be set initially, until the image request finishes. + * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. + * @param completedBlock A block called when operation has been completed. This block has no return value + * and takes the requested UIImage as first parameter. In case of error the image parameter + * is nil and the second parameter may contain an NSError. The third parameter is a Boolean + * indicating if the image was retrieved from the local cache or from the network. + * The fourth parameter is the original image url. + */ +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock; + +/** + * Set the imageView `image` with an `url`, placeholder and custom options. + * + * The download is asynchronous and cached. + * + * @param url The url for the image. + * @param placeholder The image to be set initially, until the image request finishes. + * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. + * @param progressBlock A block called while image is downloading + * @param completedBlock A block called when operation has been completed. This block has no return value + * and takes the requested UIImage as first parameter. In case of error the image parameter + * is nil and the second parameter may contain an NSError. The third parameter is a Boolean + * indicating if the image was retrieved from the local cache or from the network. + * The fourth parameter is the original image url. + */ +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock; + +/** + * Set the imageView `image` with an `url` and optionally a placeholder image. + * + * The download is asynchronous and cached. + * + * @param url The url for the image. + * @param placeholder The image to be set initially, until the image request finishes. + * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. + * @param progressBlock A block called while image is downloading + * @param completedBlock A block called when operation has been completed. This block has no return value + * and takes the requested UIImage as first parameter. In case of error the image parameter + * is nil and the second parameter may contain an NSError. The third parameter is a Boolean + * indicating if the image was retrieved from the local cache or from the network. + * The fourth parameter is the original image url. + */ +- (void)sd_setImageWithPreviousCachedImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock; + +/** + * Download an array of images and starts them in an animation loop + * + * @param arrayOfURLs An array of NSURL + */ +- (void)sd_setAnimationImagesWithURLs:(NSArray *)arrayOfURLs; + +/** + * Cancel the current download + */ +- (void)sd_cancelCurrentImageLoad; + +- (void)sd_cancelCurrentAnimationImagesLoad; + +/** + * Show activity UIActivityIndicatorView + */ +- (void)setShowActivityIndicatorView:(BOOL)show; + +/** + * set desired UIActivityIndicatorViewStyle + * + * @param style The style of the UIActivityIndicatorView + */ +- (void)setIndicatorStyle:(UIActivityIndicatorViewStyle)style; + +@end + + +@interface UIImageView (WebCacheDeprecated) + +- (NSURL *)imageURL __deprecated_msg("Use `sd_imageURL`"); + +- (void)setImageWithURL:(NSURL *)url __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:`"); +- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:`"); +- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:options`"); + +- (void)setImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:completed:`"); +- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:completed:`"); +- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:options:completed:`"); +- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:options:progress:completed:`"); + +- (void)sd_setImageWithPreviousCachedImageWithURL:(NSURL *)url andPlaceholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithPreviousCachedImageWithURL:placeholderImage:options:progress:completed:`"); + +- (void)setAnimationImagesWithURLs:(NSArray *)arrayOfURLs __deprecated_msg("Use `sd_setAnimationImagesWithURLs:`"); + +- (void)cancelCurrentArrayLoad __deprecated_msg("Use `sd_cancelCurrentAnimationImagesLoad`"); + +- (void)cancelCurrentImageLoad __deprecated_msg("Use `sd_cancelCurrentImageLoad`"); + +@end diff --git a/IOS/Playground/Pods/SDWebImage/SDWebImage/UIImageView+WebCache.m b/IOS/Playground/Pods/SDWebImage/SDWebImage/UIImageView+WebCache.m new file mode 100644 index 00000000..889305b2 --- /dev/null +++ b/IOS/Playground/Pods/SDWebImage/SDWebImage/UIImageView+WebCache.m @@ -0,0 +1,281 @@ +/* + * This file is part of the SDWebImage package. + * (c) Olivier Poitrey + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +#import "UIImageView+WebCache.h" +#import "objc/runtime.h" +#import "UIView+WebCacheOperation.h" + +static char imageURLKey; +static char TAG_ACTIVITY_INDICATOR; +static char TAG_ACTIVITY_STYLE; +static char TAG_ACTIVITY_SHOW; + +@implementation UIImageView (WebCache) + +- (void)sd_setImageWithURL:(NSURL *)url { + [self sd_setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:nil]; +} + +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder { + [self sd_setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:nil]; +} + +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options { + [self sd_setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:nil]; +} + +- (void)sd_setImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock { + [self sd_setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:completedBlock]; +} + +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock { + [self sd_setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:completedBlock]; +} + +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock { + [self sd_setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:completedBlock]; +} + +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock { + [self sd_cancelCurrentImageLoad]; + objc_setAssociatedObject(self, &imageURLKey, url, OBJC_ASSOCIATION_RETAIN_NONATOMIC); + + if (!(options & SDWebImageDelayPlaceholder)) { + dispatch_main_async_safe(^{ + self.image = placeholder; + }); + } + + if (url) { + + // check if activityView is enabled or not + if ([self showActivityIndicatorView]) { + [self addActivityIndicator]; + } + + __weak __typeof(self)wself = self; + id operation = [SDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { + [wself removeActivityIndicator]; + if (!wself) return; + dispatch_main_sync_safe(^{ + if (!wself) return; + if (image && (options & SDWebImageAvoidAutoSetImage) && completedBlock) + { + completedBlock(image, error, cacheType, url); + return; + } + else if (image) { + wself.image = image; + [wself setNeedsLayout]; + } else { + if ((options & SDWebImageDelayPlaceholder)) { + wself.image = placeholder; + [wself setNeedsLayout]; + } + } + if (completedBlock && finished) { + completedBlock(image, error, cacheType, url); + } + }); + }]; + [self sd_setImageLoadOperation:operation forKey:@"UIImageViewImageLoad"]; + } else { + dispatch_main_async_safe(^{ + [self removeActivityIndicator]; + if (completedBlock) { + NSError *error = [NSError errorWithDomain:SDWebImageErrorDomain code:-1 userInfo:@{NSLocalizedDescriptionKey : @"Trying to load a nil url"}]; + completedBlock(nil, error, SDImageCacheTypeNone, url); + } + }); + } +} + +- (void)sd_setImageWithPreviousCachedImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock { + NSString *key = [[SDWebImageManager sharedManager] cacheKeyForURL:url]; + UIImage *lastPreviousCachedImage = [[SDImageCache sharedImageCache] imageFromDiskCacheForKey:key]; + + [self sd_setImageWithURL:url placeholderImage:lastPreviousCachedImage ?: placeholder options:options progress:progressBlock completed:completedBlock]; +} + +- (NSURL *)sd_imageURL { + return objc_getAssociatedObject(self, &imageURLKey); +} + +- (void)sd_setAnimationImagesWithURLs:(NSArray *)arrayOfURLs { + [self sd_cancelCurrentAnimationImagesLoad]; + __weak __typeof(self)wself = self; + + NSMutableArray *operationsArray = [[NSMutableArray alloc] init]; + + for (NSURL *logoImageURL in arrayOfURLs) { + id operation = [SDWebImageManager.sharedManager downloadImageWithURL:logoImageURL options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { + if (!wself) return; + dispatch_main_sync_safe(^{ + __strong UIImageView *sself = wself; + [sself stopAnimating]; + if (sself && image) { + NSMutableArray *currentImages = [[sself animationImages] mutableCopy]; + if (!currentImages) { + currentImages = [[NSMutableArray alloc] init]; + } + [currentImages addObject:image]; + + sself.animationImages = currentImages; + [sself setNeedsLayout]; + } + [sself startAnimating]; + }); + }]; + [operationsArray addObject:operation]; + } + + [self sd_setImageLoadOperation:[NSArray arrayWithArray:operationsArray] forKey:@"UIImageViewAnimationImages"]; +} + +- (void)sd_cancelCurrentImageLoad { + [self sd_cancelImageLoadOperationWithKey:@"UIImageViewImageLoad"]; +} + +- (void)sd_cancelCurrentAnimationImagesLoad { + [self sd_cancelImageLoadOperationWithKey:@"UIImageViewAnimationImages"]; +} + + +#pragma mark - +- (UIActivityIndicatorView *)activityIndicator { + return (UIActivityIndicatorView *)objc_getAssociatedObject(self, &TAG_ACTIVITY_INDICATOR); +} + +- (void)setActivityIndicator:(UIActivityIndicatorView *)activityIndicator { + objc_setAssociatedObject(self, &TAG_ACTIVITY_INDICATOR, activityIndicator, OBJC_ASSOCIATION_RETAIN); +} + +- (void)setShowActivityIndicatorView:(BOOL)show{ + objc_setAssociatedObject(self, &TAG_ACTIVITY_SHOW, [NSNumber numberWithBool:show], OBJC_ASSOCIATION_RETAIN); +} + +- (BOOL)showActivityIndicatorView{ + return [objc_getAssociatedObject(self, &TAG_ACTIVITY_SHOW) boolValue]; +} + +- (void)setIndicatorStyle:(UIActivityIndicatorViewStyle)style{ + objc_setAssociatedObject(self, &TAG_ACTIVITY_STYLE, [NSNumber numberWithInt:style], OBJC_ASSOCIATION_RETAIN); +} + +- (int)getIndicatorStyle{ + return [objc_getAssociatedObject(self, &TAG_ACTIVITY_STYLE) intValue]; +} + +- (void)addActivityIndicator { + if (!self.activityIndicator) { + self.activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:[self getIndicatorStyle]]; + self.activityIndicator.translatesAutoresizingMaskIntoConstraints = NO; + + dispatch_main_async_safe(^{ + [self addSubview:self.activityIndicator]; + + [self addConstraint:[NSLayoutConstraint constraintWithItem:self.activityIndicator + attribute:NSLayoutAttributeCenterX + relatedBy:NSLayoutRelationEqual + toItem:self + attribute:NSLayoutAttributeCenterX + multiplier:1.0 + constant:0.0]]; + [self addConstraint:[NSLayoutConstraint constraintWithItem:self.activityIndicator + attribute:NSLayoutAttributeCenterY + relatedBy:NSLayoutRelationEqual + toItem:self + attribute:NSLayoutAttributeCenterY + multiplier:1.0 + constant:0.0]]; + }); + } + + dispatch_main_async_safe(^{ + [self.activityIndicator startAnimating]; + }); + +} + +- (void)removeActivityIndicator { + if (self.activityIndicator) { + [self.activityIndicator removeFromSuperview]; + self.activityIndicator = nil; + } +} + +@end + + +@implementation UIImageView (WebCacheDeprecated) + +- (NSURL *)imageURL { + return [self sd_imageURL]; +} + +- (void)setImageWithURL:(NSURL *)url { + [self sd_setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:nil]; +} + +- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder { + [self sd_setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:nil]; +} + +- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options { + [self sd_setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:nil]; +} + +- (void)setImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock { + [self sd_setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { + if (completedBlock) { + completedBlock(image, error, cacheType); + } + }]; +} + +- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock { + [self sd_setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { + if (completedBlock) { + completedBlock(image, error, cacheType); + } + }]; +} + +- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock { + [self sd_setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { + if (completedBlock) { + completedBlock(image, error, cacheType); + } + }]; +} + +- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock { + [self sd_setImageWithURL:url placeholderImage:placeholder options:options progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { + if (completedBlock) { + completedBlock(image, error, cacheType); + } + }]; +} + +- (void)sd_setImageWithPreviousCachedImageWithURL:(NSURL *)url andPlaceholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock { + [self sd_setImageWithPreviousCachedImageWithURL:url placeholderImage:placeholder options:options progress:progressBlock completed:completedBlock]; +} + +- (void)cancelCurrentArrayLoad { + [self sd_cancelCurrentAnimationImagesLoad]; +} + +- (void)cancelCurrentImageLoad { + [self sd_cancelCurrentImageLoad]; +} + +- (void)setAnimationImagesWithURLs:(NSArray *)arrayOfURLs { + [self sd_setAnimationImagesWithURLs:arrayOfURLs]; +} + +@end diff --git a/IOS/Playground/Pods/SDWebImage/SDWebImage/UIView+WebCacheOperation.h b/IOS/Playground/Pods/SDWebImage/SDWebImage/UIView+WebCacheOperation.h new file mode 100644 index 00000000..67190362 --- /dev/null +++ b/IOS/Playground/Pods/SDWebImage/SDWebImage/UIView+WebCacheOperation.h @@ -0,0 +1,36 @@ +/* + * This file is part of the SDWebImage package. + * (c) Olivier Poitrey + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +#import +#import "SDWebImageManager.h" + +@interface UIView (WebCacheOperation) + +/** + * Set the image load operation (storage in a UIView based dictionary) + * + * @param operation the operation + * @param key key for storing the operation + */ +- (void)sd_setImageLoadOperation:(id)operation forKey:(NSString *)key; + +/** + * Cancel all operations for the current UIView and key + * + * @param key key for identifying the operations + */ +- (void)sd_cancelImageLoadOperationWithKey:(NSString *)key; + +/** + * Just remove the operations corresponding to the current UIView and key without cancelling them + * + * @param key key for identifying the operations + */ +- (void)sd_removeImageLoadOperationWithKey:(NSString *)key; + +@end diff --git a/IOS/Playground/Pods/SDWebImage/SDWebImage/UIView+WebCacheOperation.m b/IOS/Playground/Pods/SDWebImage/SDWebImage/UIView+WebCacheOperation.m new file mode 100644 index 00000000..92194780 --- /dev/null +++ b/IOS/Playground/Pods/SDWebImage/SDWebImage/UIView+WebCacheOperation.m @@ -0,0 +1,55 @@ +/* + * This file is part of the SDWebImage package. + * (c) Olivier Poitrey + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +#import "UIView+WebCacheOperation.h" +#import "objc/runtime.h" + +static char loadOperationKey; + +@implementation UIView (WebCacheOperation) + +- (NSMutableDictionary *)operationDictionary { + NSMutableDictionary *operations = objc_getAssociatedObject(self, &loadOperationKey); + if (operations) { + return operations; + } + operations = [NSMutableDictionary dictionary]; + objc_setAssociatedObject(self, &loadOperationKey, operations, OBJC_ASSOCIATION_RETAIN_NONATOMIC); + return operations; +} + +- (void)sd_setImageLoadOperation:(id)operation forKey:(NSString *)key { + [self sd_cancelImageLoadOperationWithKey:key]; + NSMutableDictionary *operationDictionary = [self operationDictionary]; + [operationDictionary setObject:operation forKey:key]; +} + +- (void)sd_cancelImageLoadOperationWithKey:(NSString *)key { + // Cancel in progress downloader from queue + NSMutableDictionary *operationDictionary = [self operationDictionary]; + id operations = [operationDictionary objectForKey:key]; + if (operations) { + if ([operations isKindOfClass:[NSArray class]]) { + for (id operation in operations) { + if (operation) { + [operation cancel]; + } + } + } else if ([operations conformsToProtocol:@protocol(SDWebImageOperation)]){ + [(id) operations cancel]; + } + [operationDictionary removeObjectForKey:key]; + } +} + +- (void)sd_removeImageLoadOperationWithKey:(NSString *)key { + NSMutableDictionary *operationDictionary = [self operationDictionary]; + [operationDictionary removeObjectForKey:key]; +} + +@end diff --git a/IOS/Playground/Pods/Target Support Files/LuaViewSDK/LuaViewSDK-dummy.m b/IOS/Playground/Pods/Target Support Files/LuaViewSDK/LuaViewSDK-dummy.m new file mode 100644 index 00000000..962a7e44 --- /dev/null +++ b/IOS/Playground/Pods/Target Support Files/LuaViewSDK/LuaViewSDK-dummy.m @@ -0,0 +1,5 @@ +#import +@interface PodsDummy_LuaViewSDK : NSObject +@end +@implementation PodsDummy_LuaViewSDK +@end diff --git a/IOS/Playground/Pods/Target Support Files/LuaViewSDK/LuaViewSDK-prefix.pch b/IOS/Playground/Pods/Target Support Files/LuaViewSDK/LuaViewSDK-prefix.pch new file mode 100644 index 00000000..aa992a4a --- /dev/null +++ b/IOS/Playground/Pods/Target Support Files/LuaViewSDK/LuaViewSDK-prefix.pch @@ -0,0 +1,4 @@ +#ifdef __OBJC__ +#import +#endif + diff --git a/IOS/Playground/Pods/Target Support Files/LuaViewSDK/LuaViewSDK.xcconfig b/IOS/Playground/Pods/Target Support Files/LuaViewSDK/LuaViewSDK.xcconfig new file mode 100644 index 00000000..910cb48d --- /dev/null +++ b/IOS/Playground/Pods/Target Support Files/LuaViewSDK/LuaViewSDK.xcconfig @@ -0,0 +1,5 @@ +GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 +HEADER_SEARCH_PATHS = "${PODS_ROOT}/Headers/Private" "${PODS_ROOT}/Headers/Private/LuaViewSDK" "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/LuaViewSDK" "${PODS_ROOT}/Headers/Public/MJRefresh" "${PODS_ROOT}/Headers/Public/SDWebImage" "${PODS_ROOT}/Headers/Public/luaviewEx" +OTHER_LDFLAGS = -l"z" -framework "CoreGraphics" -framework "Foundation" -framework "UIKit" +PODS_ROOT = ${SRCROOT} +SKIP_INSTALL = YES \ No newline at end of file diff --git a/IOS/Playground/Pods/Target Support Files/MJRefresh/MJRefresh-dummy.m b/IOS/Playground/Pods/Target Support Files/MJRefresh/MJRefresh-dummy.m new file mode 100644 index 00000000..d43259d2 --- /dev/null +++ b/IOS/Playground/Pods/Target Support Files/MJRefresh/MJRefresh-dummy.m @@ -0,0 +1,5 @@ +#import +@interface PodsDummy_MJRefresh : NSObject +@end +@implementation PodsDummy_MJRefresh +@end diff --git a/IOS/Playground/Pods/Target Support Files/MJRefresh/MJRefresh-prefix.pch b/IOS/Playground/Pods/Target Support Files/MJRefresh/MJRefresh-prefix.pch new file mode 100644 index 00000000..aa992a4a --- /dev/null +++ b/IOS/Playground/Pods/Target Support Files/MJRefresh/MJRefresh-prefix.pch @@ -0,0 +1,4 @@ +#ifdef __OBJC__ +#import +#endif + diff --git a/IOS/Playground/Pods/Target Support Files/MJRefresh/MJRefresh.xcconfig b/IOS/Playground/Pods/Target Support Files/MJRefresh/MJRefresh.xcconfig new file mode 100644 index 00000000..1b7631df --- /dev/null +++ b/IOS/Playground/Pods/Target Support Files/MJRefresh/MJRefresh.xcconfig @@ -0,0 +1,4 @@ +GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 +HEADER_SEARCH_PATHS = "${PODS_ROOT}/Headers/Private" "${PODS_ROOT}/Headers/Private/MJRefresh" "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/LuaViewSDK" "${PODS_ROOT}/Headers/Public/MJRefresh" "${PODS_ROOT}/Headers/Public/SDWebImage" "${PODS_ROOT}/Headers/Public/luaviewEx" +PODS_ROOT = ${SRCROOT} +SKIP_INSTALL = YES \ No newline at end of file diff --git a/IOS/Playground/Pods/Target Support Files/Pods-Demo/Pods-Demo-acknowledgements.markdown b/IOS/Playground/Pods/Target Support Files/Pods-Demo/Pods-Demo-acknowledgements.markdown new file mode 100644 index 00000000..66d90ee0 --- /dev/null +++ b/IOS/Playground/Pods/Target Support Files/Pods-Demo/Pods-Demo-acknowledgements.markdown @@ -0,0 +1,94 @@ +# Acknowledgements +This application makes use of the following third party libraries: + +## LuaViewSDK + +The MIT License (MIT) +Copyright (c) 2017 Alibaba Group +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + + +## MJRefresh + +Copyright (c) 2013-2015 MJRefresh (https://github.com/CoderMJLee/MJRefresh) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + + +## SDWebImage + +Copyright (c) 2016 Olivier Poitrey rs@dailymotion.com + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished +to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + + + +## luaviewEx + +Copyright (c) 2017 yechunxiao19 + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + +Generated by CocoaPods - http://cocoapods.org diff --git a/IOS/Playground/Pods/Target Support Files/Pods-Demo/Pods-Demo-acknowledgements.plist b/IOS/Playground/Pods/Target Support Files/Pods-Demo/Pods-Demo-acknowledgements.plist new file mode 100644 index 00000000..657c9d05 --- /dev/null +++ b/IOS/Playground/Pods/Target Support Files/Pods-Demo/Pods-Demo-acknowledgements.plist @@ -0,0 +1,136 @@ + + + + + PreferenceSpecifiers + + + FooterText + This application makes use of the following third party libraries: + Title + Acknowledgements + Type + PSGroupSpecifier + + + FooterText + The MIT License (MIT) +Copyright (c) 2017 Alibaba Group +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + + Title + LuaViewSDK + Type + PSGroupSpecifier + + + FooterText + Copyright (c) 2013-2015 MJRefresh (https://github.com/CoderMJLee/MJRefresh) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + + Title + MJRefresh + Type + PSGroupSpecifier + + + FooterText + Copyright (c) 2016 Olivier Poitrey rs@dailymotion.com + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished +to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + + + Title + SDWebImage + Type + PSGroupSpecifier + + + FooterText + Copyright (c) 2017 yechunxiao19 <chunxiao.ycx@alibaba-inc.com> + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + + Title + luaviewEx + Type + PSGroupSpecifier + + + FooterText + Generated by CocoaPods - http://cocoapods.org + Title + + Type + PSGroupSpecifier + + + StringsTable + Acknowledgements + Title + Acknowledgements + + diff --git a/IOS/Playground/Pods/Target Support Files/Pods-Demo/Pods-Demo-dummy.m b/IOS/Playground/Pods/Target Support Files/Pods-Demo/Pods-Demo-dummy.m new file mode 100644 index 00000000..05b3bfe1 --- /dev/null +++ b/IOS/Playground/Pods/Target Support Files/Pods-Demo/Pods-Demo-dummy.m @@ -0,0 +1,5 @@ +#import +@interface PodsDummy_Pods_Demo : NSObject +@end +@implementation PodsDummy_Pods_Demo +@end diff --git a/IOS/Playground/Pods/Target Support Files/Pods-Demo/Pods-Demo-frameworks.sh b/IOS/Playground/Pods/Target Support Files/Pods-Demo/Pods-Demo-frameworks.sh new file mode 100755 index 00000000..6f763443 --- /dev/null +++ b/IOS/Playground/Pods/Target Support Files/Pods-Demo/Pods-Demo-frameworks.sh @@ -0,0 +1,84 @@ +#!/bin/sh +set -e + +echo "mkdir -p ${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" +mkdir -p "${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" + +SWIFT_STDLIB_PATH="${DT_TOOLCHAIN_DIR}/usr/lib/swift/${PLATFORM_NAME}" + +install_framework() +{ + if [ -r "${BUILT_PRODUCTS_DIR}/$1" ]; then + local source="${BUILT_PRODUCTS_DIR}/$1" + elif [ -r "${BUILT_PRODUCTS_DIR}/$(basename "$1")" ]; then + local source="${BUILT_PRODUCTS_DIR}/$(basename "$1")" + elif [ -r "$1" ]; then + local source="$1" + fi + + local destination="${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" + + if [ -L "${source}" ]; then + echo "Symlinked..." + source="$(readlink "${source}")" + fi + + # use filter instead of exclude so missing patterns dont' throw errors + echo "rsync -av --filter \"- CVS/\" --filter \"- .svn/\" --filter \"- .git/\" --filter \"- .hg/\" --filter \"- Headers\" --filter \"- PrivateHeaders\" --filter \"- Modules\" \"${source}\" \"${destination}\"" + rsync -av --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "${source}" "${destination}" + + local basename + basename="$(basename -s .framework "$1")" + binary="${destination}/${basename}.framework/${basename}" + if ! [ -r "$binary" ]; then + binary="${destination}/${basename}" + fi + + # Strip invalid architectures so "fat" simulator / device frameworks work on device + if [[ "$(file "$binary")" == *"dynamically linked shared library"* ]]; then + strip_invalid_archs "$binary" + fi + + # Resign the code if required by the build settings to avoid unstable apps + code_sign_if_enabled "${destination}/$(basename "$1")" + + # Embed linked Swift runtime libraries. No longer necessary as of Xcode 7. + if [ "${XCODE_VERSION_MAJOR}" -lt 7 ]; then + local swift_runtime_libs + swift_runtime_libs=$(xcrun otool -LX "$binary" | grep --color=never @rpath/libswift | sed -E s/@rpath\\/\(.+dylib\).*/\\1/g | uniq -u && exit ${PIPESTATUS[0]}) + for lib in $swift_runtime_libs; do + echo "rsync -auv \"${SWIFT_STDLIB_PATH}/${lib}\" \"${destination}\"" + rsync -auv "${SWIFT_STDLIB_PATH}/${lib}" "${destination}" + code_sign_if_enabled "${destination}/${lib}" + done + fi +} + +# Signs a framework with the provided identity +code_sign_if_enabled() { + if [ -n "${EXPANDED_CODE_SIGN_IDENTITY}" -a "${CODE_SIGNING_REQUIRED}" != "NO" -a "${CODE_SIGNING_ALLOWED}" != "NO" ]; then + # Use the current code_sign_identitiy + echo "Code Signing $1 with Identity ${EXPANDED_CODE_SIGN_IDENTITY_NAME}" + echo "/usr/bin/codesign --force --sign ${EXPANDED_CODE_SIGN_IDENTITY} --preserve-metadata=identifier,entitlements \"$1\"" + /usr/bin/codesign --force --sign ${EXPANDED_CODE_SIGN_IDENTITY} --preserve-metadata=identifier,entitlements "$1" + fi +} + +# Strip invalid architectures +strip_invalid_archs() { + binary="$1" + # Get architectures for current file + archs="$(lipo -info "$binary" | rev | cut -d ':' -f1 | rev)" + stripped="" + for arch in $archs; do + if ! [[ "${VALID_ARCHS}" == *"$arch"* ]]; then + # Strip non-valid architectures in-place + lipo -remove "$arch" -output "$binary" "$binary" || exit 1 + stripped="$stripped $arch" + fi + done + if [[ "$stripped" ]]; then + echo "Stripped $binary of architectures:$stripped" + fi +} + diff --git a/IOS/Playground/Pods/Target Support Files/Pods-Demo/Pods-Demo-resources.sh b/IOS/Playground/Pods/Target Support Files/Pods-Demo/Pods-Demo-resources.sh new file mode 100755 index 00000000..fe196f61 --- /dev/null +++ b/IOS/Playground/Pods/Target Support Files/Pods-Demo/Pods-Demo-resources.sh @@ -0,0 +1,105 @@ +#!/bin/sh +set -e + +mkdir -p "${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" + +RESOURCES_TO_COPY=${PODS_ROOT}/resources-to-copy-${TARGETNAME}.txt +> "$RESOURCES_TO_COPY" + +XCASSET_FILES=() + +realpath() { + DIRECTORY="$(cd "${1%/*}" && pwd)" + FILENAME="${1##*/}" + echo "$DIRECTORY/$FILENAME" +} + +install_resource() +{ + case $1 in + *.storyboard) + echo "ibtool --reference-external-strings-file --errors --warnings --notices --output-format human-readable-text --compile ${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \"$1\" .storyboard`.storyboardc ${PODS_ROOT}/$1 --sdk ${SDKROOT}" + ibtool --reference-external-strings-file --errors --warnings --notices --output-format human-readable-text --compile "${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \"$1\" .storyboard`.storyboardc" "${PODS_ROOT}/$1" --sdk "${SDKROOT}" + ;; + *.xib) + echo "ibtool --reference-external-strings-file --errors --warnings --notices --output-format human-readable-text --compile ${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \"$1\" .xib`.nib ${PODS_ROOT}/$1 --sdk ${SDKROOT}" + ibtool --reference-external-strings-file --errors --warnings --notices --output-format human-readable-text --compile "${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \"$1\" .xib`.nib" "${PODS_ROOT}/$1" --sdk "${SDKROOT}" + ;; + *.framework) + echo "mkdir -p ${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" + mkdir -p "${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" + echo "rsync -av ${PODS_ROOT}/$1 ${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" + rsync -av "${PODS_ROOT}/$1" "${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" + ;; + *.xcdatamodel) + echo "xcrun momc \"${PODS_ROOT}/$1\" \"${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$1"`.mom\"" + xcrun momc "${PODS_ROOT}/$1" "${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$1" .xcdatamodel`.mom" + ;; + *.xcdatamodeld) + echo "xcrun momc \"${PODS_ROOT}/$1\" \"${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$1" .xcdatamodeld`.momd\"" + xcrun momc "${PODS_ROOT}/$1" "${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$1" .xcdatamodeld`.momd" + ;; + *.xcmappingmodel) + echo "xcrun mapc \"${PODS_ROOT}/$1\" \"${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$1" .xcmappingmodel`.cdm\"" + xcrun mapc "${PODS_ROOT}/$1" "${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$1" .xcmappingmodel`.cdm" + ;; + *.xcassets) + ABSOLUTE_XCASSET_FILE=$(realpath "${PODS_ROOT}/$1") + XCASSET_FILES+=("$ABSOLUTE_XCASSET_FILE") + ;; + /*) + echo "$1" + echo "$1" >> "$RESOURCES_TO_COPY" + ;; + *) + echo "${PODS_ROOT}/$1" + echo "${PODS_ROOT}/$1" >> "$RESOURCES_TO_COPY" + ;; + esac +} +if [[ "$CONFIGURATION" == "Debug" ]]; then + install_resource "MJRefresh/MJRefresh/MJRefresh.bundle" + install_resource "../../luaviewEx/luaviewEx/luaview/luaview.bundle" + install_resource "${BUILT_PRODUCTS_DIR}/luaviewEx.bundle" +fi +if [[ "$CONFIGURATION" == "Release" ]]; then + install_resource "MJRefresh/MJRefresh/MJRefresh.bundle" + install_resource "../../luaviewEx/luaviewEx/luaview/luaview.bundle" + install_resource "${BUILT_PRODUCTS_DIR}/luaviewEx.bundle" +fi + +mkdir -p "${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" +rsync -avr --copy-links --no-relative --exclude '*/.svn/*' --files-from="$RESOURCES_TO_COPY" / "${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" +if [[ "${ACTION}" == "install" ]] && [[ "${SKIP_INSTALL}" == "NO" ]]; then + mkdir -p "${INSTALL_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" + rsync -avr --copy-links --no-relative --exclude '*/.svn/*' --files-from="$RESOURCES_TO_COPY" / "${INSTALL_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" +fi +rm -f "$RESOURCES_TO_COPY" + +if [[ -n "${WRAPPER_EXTENSION}" ]] && [ "`xcrun --find actool`" ] && [ -n "$XCASSET_FILES" ] +then + case "${TARGETED_DEVICE_FAMILY}" in + 1,2) + TARGET_DEVICE_ARGS="--target-device ipad --target-device iphone" + ;; + 1) + TARGET_DEVICE_ARGS="--target-device iphone" + ;; + 2) + TARGET_DEVICE_ARGS="--target-device ipad" + ;; + *) + TARGET_DEVICE_ARGS="--target-device mac" + ;; + esac + + # Find all other xcassets (this unfortunately includes those of path pods and other targets). + OTHER_XCASSETS=$(find "$PWD" -iname "*.xcassets" -type d) + while read line; do + if [[ $line != "`realpath $PODS_ROOT`*" ]]; then + XCASSET_FILES+=("$line") + fi + done <<<"$OTHER_XCASSETS" + + printf "%s\0" "${XCASSET_FILES[@]}" | xargs -0 xcrun actool --output-format human-readable-text --notices --warnings --platform "${PLATFORM_NAME}" --minimum-deployment-target "${IPHONEOS_DEPLOYMENT_TARGET}" ${TARGET_DEVICE_ARGS} --compress-pngs --compile "${BUILT_PRODUCTS_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" +fi diff --git a/IOS/Playground/Pods/Target Support Files/Pods-Demo/Pods-Demo.debug.xcconfig b/IOS/Playground/Pods/Target Support Files/Pods-Demo/Pods-Demo.debug.xcconfig new file mode 100644 index 00000000..547af2a7 --- /dev/null +++ b/IOS/Playground/Pods/Target Support Files/Pods-Demo/Pods-Demo.debug.xcconfig @@ -0,0 +1,6 @@ +GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 +HEADER_SEARCH_PATHS = $(inherited) "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/LuaViewSDK" "${PODS_ROOT}/Headers/Public/MJRefresh" "${PODS_ROOT}/Headers/Public/SDWebImage" "${PODS_ROOT}/Headers/Public/luaviewEx" +INFOPLIST_FILE = ../../luaviewEx/luaviewEx/Classes/luaviewEx-info.plist +OTHER_CFLAGS = $(inherited) -isystem "${PODS_ROOT}/Headers/Public" -isystem "${PODS_ROOT}/Headers/Public/LuaViewSDK" -isystem "${PODS_ROOT}/Headers/Public/MJRefresh" -isystem "${PODS_ROOT}/Headers/Public/SDWebImage" -isystem "${PODS_ROOT}/Headers/Public/luaviewEx" +OTHER_LDFLAGS = $(inherited) -ObjC -l"LuaViewSDK" -l"MJRefresh" -l"SDWebImage" -l"luaviewEx" -l"z" -framework "CoreGraphics" -framework "Foundation" -framework "ImageIO" -framework "UIKit" +PODS_ROOT = ${SRCROOT}/Pods \ No newline at end of file diff --git a/IOS/Playground/Pods/Target Support Files/Pods-Demo/Pods-Demo.release.xcconfig b/IOS/Playground/Pods/Target Support Files/Pods-Demo/Pods-Demo.release.xcconfig new file mode 100644 index 00000000..547af2a7 --- /dev/null +++ b/IOS/Playground/Pods/Target Support Files/Pods-Demo/Pods-Demo.release.xcconfig @@ -0,0 +1,6 @@ +GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 +HEADER_SEARCH_PATHS = $(inherited) "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/LuaViewSDK" "${PODS_ROOT}/Headers/Public/MJRefresh" "${PODS_ROOT}/Headers/Public/SDWebImage" "${PODS_ROOT}/Headers/Public/luaviewEx" +INFOPLIST_FILE = ../../luaviewEx/luaviewEx/Classes/luaviewEx-info.plist +OTHER_CFLAGS = $(inherited) -isystem "${PODS_ROOT}/Headers/Public" -isystem "${PODS_ROOT}/Headers/Public/LuaViewSDK" -isystem "${PODS_ROOT}/Headers/Public/MJRefresh" -isystem "${PODS_ROOT}/Headers/Public/SDWebImage" -isystem "${PODS_ROOT}/Headers/Public/luaviewEx" +OTHER_LDFLAGS = $(inherited) -ObjC -l"LuaViewSDK" -l"MJRefresh" -l"SDWebImage" -l"luaviewEx" -l"z" -framework "CoreGraphics" -framework "Foundation" -framework "ImageIO" -framework "UIKit" +PODS_ROOT = ${SRCROOT}/Pods \ No newline at end of file diff --git a/IOS/Playground/Pods/Target Support Files/Pods-Demo/copy-framework-resources.rb b/IOS/Playground/Pods/Target Support Files/Pods-Demo/copy-framework-resources.rb new file mode 100755 index 00000000..08383e0b --- /dev/null +++ b/IOS/Playground/Pods/Target Support Files/Pods-Demo/copy-framework-resources.rb @@ -0,0 +1,62 @@ +#!/usr/bin/env ruby +# encoding: UTF-8 + +require 'Xcodeproj' +require 'fileutils' + +Encoding.default_external = Encoding::UTF_8 +Encoding.default_internal = Encoding::UTF_8 + +current_target_name = ENV["TARGET_NAME"] +project = Xcodeproj::Project.open(ENV["PROJECT_FILE_PATH"]) + +# 分析环境变量参数 +def parse_args(args) + index = 0 + arg_list = [] + while args && args.length > 0 && args.length > index + space_index = args.index(" ", index) + space_index = -1 if space_index.nil? + arg = args[0..space_index] + if arg.count("\"") % 2 == 0 && arg.count("'") % 2 == 0 + arg_list << arg.strip + args = space_index >= 0 ? args[space_index+1..-1] : nil + index = 0 + end + end + arg_list +end + +def find_key(array, key) + for dic in array + if dic.keys[0] == key + return dic[key] + end + end +end + +current_target = project.targets.find { |target| target.name == current_target_name } + +frameworks = current_target.frameworks_build_phases.files.map{|file| file.file_ref.nil? ? "" : File.basename(file.file_ref.path) }.select { |x| File.extname(x) == ".framework"} + +FRAMEWORK_SEARCH_PATHS = [] +parse_args(ENV['FRAMEWORK_SEARCH_PATHS']).each { |arg| FRAMEWORK_SEARCH_PATHS << arg.gsub("\"", "") } + +for framework in frameworks + FRAMEWORK_SEARCH_PATHS.each do |path| + framework_path = File.join(path, framework) + if File.directory?(framework_path) + ignore_list = ["Info.plist", ".DS_Store"] + if File.directory?(File.join(framework_path, "Resources")) + list = Dir.glob(File.join(framework_path, "Resources/*")) + else + ignore_list += [File.basename(framework, '.framework'), "Headers", "PrivateHeaders", "Modules", "Versions", "_CodeSignature"] + list = Dir.glob(File.join(framework_path, "*")) + end + list.reject!{|entry| ignore_list.include?(File.basename(entry)) } + list.each { |file| puts file} + FileUtils.cp_r list, File.join(ENV["TARGET_BUILD_DIR"], ENV["UNLOCALIZED_RESOURCES_FOLDER_PATH"]) + break + end + end +end diff --git a/IOS/Playground/Pods/Target Support Files/SDWebImage/SDWebImage-dummy.m b/IOS/Playground/Pods/Target Support Files/SDWebImage/SDWebImage-dummy.m new file mode 100644 index 00000000..86d2b5f6 --- /dev/null +++ b/IOS/Playground/Pods/Target Support Files/SDWebImage/SDWebImage-dummy.m @@ -0,0 +1,5 @@ +#import +@interface PodsDummy_SDWebImage : NSObject +@end +@implementation PodsDummy_SDWebImage +@end diff --git a/IOS/Playground/Pods/Target Support Files/SDWebImage/SDWebImage-prefix.pch b/IOS/Playground/Pods/Target Support Files/SDWebImage/SDWebImage-prefix.pch new file mode 100644 index 00000000..aa992a4a --- /dev/null +++ b/IOS/Playground/Pods/Target Support Files/SDWebImage/SDWebImage-prefix.pch @@ -0,0 +1,4 @@ +#ifdef __OBJC__ +#import +#endif + diff --git a/IOS/Playground/Pods/Target Support Files/SDWebImage/SDWebImage.xcconfig b/IOS/Playground/Pods/Target Support Files/SDWebImage/SDWebImage.xcconfig new file mode 100644 index 00000000..b829b7d2 --- /dev/null +++ b/IOS/Playground/Pods/Target Support Files/SDWebImage/SDWebImage.xcconfig @@ -0,0 +1,5 @@ +GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 +HEADER_SEARCH_PATHS = "${PODS_ROOT}/Headers/Private" "${PODS_ROOT}/Headers/Private/SDWebImage" "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/LuaViewSDK" "${PODS_ROOT}/Headers/Public/MJRefresh" "${PODS_ROOT}/Headers/Public/SDWebImage" "${PODS_ROOT}/Headers/Public/luaviewEx" +OTHER_LDFLAGS = -framework "ImageIO" +PODS_ROOT = ${SRCROOT} +SKIP_INSTALL = YES \ No newline at end of file diff --git a/IOS/Playground/Pods/Target Support Files/luaviewEx/luaviewEx-dummy.m b/IOS/Playground/Pods/Target Support Files/luaviewEx/luaviewEx-dummy.m new file mode 100644 index 00000000..e2548d6b --- /dev/null +++ b/IOS/Playground/Pods/Target Support Files/luaviewEx/luaviewEx-dummy.m @@ -0,0 +1,5 @@ +#import +@interface PodsDummy_luaviewEx : NSObject +@end +@implementation PodsDummy_luaviewEx +@end diff --git a/IOS/Playground/Pods/Target Support Files/luaviewEx/luaviewEx-prefix.pch b/IOS/Playground/Pods/Target Support Files/luaviewEx/luaviewEx-prefix.pch new file mode 100644 index 00000000..aa992a4a --- /dev/null +++ b/IOS/Playground/Pods/Target Support Files/luaviewEx/luaviewEx-prefix.pch @@ -0,0 +1,4 @@ +#ifdef __OBJC__ +#import +#endif + diff --git a/IOS/Playground/Pods/Target Support Files/luaviewEx/luaviewEx.xcconfig b/IOS/Playground/Pods/Target Support Files/luaviewEx/luaviewEx.xcconfig new file mode 100644 index 00000000..87af4637 --- /dev/null +++ b/IOS/Playground/Pods/Target Support Files/luaviewEx/luaviewEx.xcconfig @@ -0,0 +1,5 @@ +GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 +HEADER_SEARCH_PATHS = "${PODS_ROOT}/Headers/Private" "${PODS_ROOT}/Headers/Private/luaviewEx" "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/LuaViewSDK" "${PODS_ROOT}/Headers/Public/MJRefresh" "${PODS_ROOT}/Headers/Public/SDWebImage" "${PODS_ROOT}/Headers/Public/luaviewEx" +INFOPLIST_FILE = ../../luaviewEx/luaviewEx/Classes/luaviewEx-info.plist +PODS_ROOT = ${SRCROOT} +SKIP_INSTALL = YES \ No newline at end of file diff --git a/IOS/Playground/luaviewExt/Info.plist b/IOS/Playground/luaviewExt/Info.plist new file mode 100644 index 00000000..31ab1283 --- /dev/null +++ b/IOS/Playground/luaviewExt/Info.plist @@ -0,0 +1,26 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + BNDL + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + NSHumanReadableCopyright + Copyright © 2017年 juhuasuan. All rights reserved. + NSPrincipalClass + + + diff --git a/IOS/SDK/.gitignore b/IOS/SDK/.gitignore new file mode 100644 index 00000000..389a2b20 --- /dev/null +++ b/IOS/SDK/.gitignore @@ -0,0 +1 @@ +Pods/ diff --git a/IOS/SDK/Dummy/Dummy-Prefix.pch b/IOS/SDK/Dummy/Dummy-Prefix.pch new file mode 100644 index 00000000..34a94774 --- /dev/null +++ b/IOS/SDK/Dummy/Dummy-Prefix.pch @@ -0,0 +1,41 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#ifndef Dummy_Prefix_pch +#define Dummy_Prefix_pch + +// Include any system framework and library headers here that should be included in all compilation units. +// You will also need to set the Prefix Header build setting of one or more of your targets to reference this file. + +#ifdef __OBJC__ + +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import + +#endif + + +#endif /* Dummy_Prefix_pch */ diff --git a/IOS/SDK/Dummy/Dummy.h b/IOS/SDK/Dummy/Dummy.h new file mode 100644 index 00000000..b97140c8 --- /dev/null +++ b/IOS/SDK/Dummy/Dummy.h @@ -0,0 +1,13 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import + +@interface Dummy : NSObject + +@end diff --git a/IOS/SDK/Dummy/Dummy.m b/IOS/SDK/Dummy/Dummy.m new file mode 100644 index 00000000..106900be --- /dev/null +++ b/IOS/SDK/Dummy/Dummy.m @@ -0,0 +1,13 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "Dummy.h" + +@implementation Dummy + +@end diff --git a/IOS/SDK/LuaViewSDK.xcodeproj/project.pbxproj b/IOS/SDK/LuaViewSDK.xcodeproj/project.pbxproj new file mode 100644 index 00000000..92918cc7 --- /dev/null +++ b/IOS/SDK/LuaViewSDK.xcodeproj/project.pbxproj @@ -0,0 +1,1654 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + 224569A41F0B62DA000CDE49 /* LVCamera.h in Headers */ = {isa = PBXBuildFile; fileRef = 224569A21F0B62DA000CDE49 /* LVCamera.h */; }; + 224569A51F0B62DA000CDE49 /* LVCamera.m in Sources */ = {isa = PBXBuildFile; fileRef = 224569A31F0B62DA000CDE49 /* LVCamera.m */; }; + 3C02D1D91C31106E00213386 /* LVAnimator.h in Headers */ = {isa = PBXBuildFile; fileRef = 3C02D1D71C31106E00213386 /* LVAnimator.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 3C02D1DA1C31106E00213386 /* LVAnimator.m in Sources */ = {isa = PBXBuildFile; fileRef = 3C02D1D81C31106E00213386 /* LVAnimator.m */; }; + 3C98A53A1C7C0C100001508E /* LViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = 3C98A5381C7C0C100001508E /* LViewController.h */; }; + 3C98A53B1C7C0C100001508E /* LViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3C98A5391C7C0C100001508E /* LViewController.m */; }; + 3C98A5421C7C56270001508E /* LViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3C98A5391C7C0C100001508E /* LViewController.m */; }; + 3CC1B5531C96B59D001DEEC0 /* LVZipArchive.h in Headers */ = {isa = PBXBuildFile; fileRef = 3CC1B5511C96B59D001DEEC0 /* LVZipArchive.h */; }; + 3CC1B5541C96B59D001DEEC0 /* LVZipArchive.m in Sources */ = {isa = PBXBuildFile; fileRef = 3CC1B5521C96B59D001DEEC0 /* LVZipArchive.m */; }; + 3CC1B5551C96B5BC001DEEC0 /* LVZipArchive.m in Sources */ = {isa = PBXBuildFile; fileRef = 3CC1B5521C96B59D001DEEC0 /* LVZipArchive.m */; }; + 3CFF77B21C74740800847C05 /* LVPkgManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 84D446F11AF75BD8000A3911 /* LVPkgManager.m */; }; + 3CFF77B41C74740800847C05 /* LVRSA.m in Sources */ = {isa = PBXBuildFile; fileRef = 84B1E3801AEF24480054B9F1 /* LVRSA.m */; }; + 3CFF77B51C74740800847C05 /* LVDebugLua.m in Sources */ = {isa = PBXBuildFile; fileRef = 842142A21ACD3427001FD0ED /* LVDebugLua.m */; }; + 3CFF77B61C74740800847C05 /* LVDebuger.m in Sources */ = {isa = PBXBuildFile; fileRef = 91ACCE761AC531160034D9B3 /* LVDebuger.m */; }; + 3CFF77B71C74740800847C05 /* LVDebugConnection.m in Sources */ = {isa = PBXBuildFile; fileRef = 84BC621F1BA95A3F0019B02E /* LVDebugConnection.m */; }; + 3CFF77B81C74740800847C05 /* LVBaseView.m in Sources */ = {isa = PBXBuildFile; fileRef = 846481A91A64C61F00DE6204 /* LVBaseView.m */; }; + 3CFF77B91C74740800847C05 /* UIScrollView+LuaView.m in Sources */ = {isa = PBXBuildFile; fileRef = 84F4A01E1B4B9E600062A7B2 /* UIScrollView+LuaView.m */; }; + 3CFF77BA1C74740800847C05 /* UIView+LuaView.m in Sources */ = {isa = PBXBuildFile; fileRef = 843447491B61DDED0039B98A /* UIView+LuaView.m */; }; + 3CFF77BB1C74740800847C05 /* LVButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 846481AB1A64C61F00DE6204 /* LVButton.m */; }; + 3CFF77BC1C74740800847C05 /* LVImage.m in Sources */ = {isa = PBXBuildFile; fileRef = 846481AF1A64C61F00DE6204 /* LVImage.m */; }; + 3CFF77BD1C74740800847C05 /* LVNinePatchImage.m in Sources */ = {isa = PBXBuildFile; fileRef = 8446F15C1BDF57F2007E4064 /* LVNinePatchImage.m */; }; + 3CFF77BE1C74740800847C05 /* LVLabel.m in Sources */ = {isa = PBXBuildFile; fileRef = 846481B11A64C61F00DE6204 /* LVLabel.m */; }; + 3CFF77BF1C74740800847C05 /* LVTextField.m in Sources */ = {isa = PBXBuildFile; fileRef = 846481B71A64C61F00DE6204 /* LVTextField.m */; }; + 3CFF77C01C74740800847C05 /* LVLoadingIndicator.m in Sources */ = {isa = PBXBuildFile; fileRef = 84B58E391B65CC260048F33D /* LVLoadingIndicator.m */; }; + 3CFF77C11C74740800847C05 /* LVPagerIndicator.m in Sources */ = {isa = PBXBuildFile; fileRef = 846481B31A64C61F00DE6204 /* LVPagerIndicator.m */; }; + 3CFF77C51C74740800847C05 /* LVPagerView.m in Sources */ = {isa = PBXBuildFile; fileRef = 84799AF41BAFECA00070E214 /* LVPagerView.m */; }; + 3CFF77C61C74740800847C05 /* LVPagerViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 84799AF91BAFEFDA0070E214 /* LVPagerViewCell.m */; }; + 3CFF77C71C74740800847C05 /* LVCollectionView.m in Sources */ = {isa = PBXBuildFile; fileRef = 848CA35E1B29669A00C70321 /* LVCollectionView.m */; }; + 3CFF77C81C74740800847C05 /* LVCollectionViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 848CA3631B29748800C70321 /* LVCollectionViewCell.m */; }; + 3CFF77C91C74740800847C05 /* LVCollectionViewDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 8481E0641BD7B29100FDFEEA /* LVCollectionViewDelegate.m */; }; + 3CFF77CA1C74740800847C05 /* LVScrollView.m in Sources */ = {isa = PBXBuildFile; fileRef = 846481B51A64C61F00DE6204 /* LVScrollView.m */; }; + 3CFF77CB1C74740800847C05 /* LVScrollViewDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 8481E05A1BD7AC8000FDFEEA /* LVScrollViewDelegate.m */; }; + 3CFF77CC1C74740800847C05 /* LVCustomPanel.m in Sources */ = {isa = PBXBuildFile; fileRef = 84056E711B5CA5990078F9D6 /* LVCustomPanel.m */; }; + 3CFF77CD1C74740800847C05 /* LVAlert.m in Sources */ = {isa = PBXBuildFile; fileRef = 842D726D1A6643DB00936AD2 /* LVAlert.m */; }; + 3CFF77CE1C74740800847C05 /* LVToast.m in Sources */ = {isa = PBXBuildFile; fileRef = 8468C9701BDA177C002D4B1E /* LVToast.m */; }; + 3CFF77CF1C74740800847C05 /* LVAnimate.m in Sources */ = {isa = PBXBuildFile; fileRef = 846481A71A64C61F00DE6204 /* LVAnimate.m */; }; + 3CFF77D01C74740800847C05 /* LVAnimator.m in Sources */ = {isa = PBXBuildFile; fileRef = 3C02D1D81C31106E00213386 /* LVAnimator.m */; }; + 3CFF77D11C74740800847C05 /* LVStyledString.m in Sources */ = {isa = PBXBuildFile; fileRef = 84342D8D1AE0E02B00ECB4EF /* LVStyledString.m */; }; + 3CFF77D21C74740800847C05 /* LVTransform3D.m in Sources */ = {isa = PBXBuildFile; fileRef = 846481BB1A64C61F00DE6204 /* LVTransform3D.m */; }; + 3CFF77D31C74740800847C05 /* LVData.m in Sources */ = {isa = PBXBuildFile; fileRef = 84C3B7291A84622A00923404 /* LVData.m */; }; + 3CFF77D41C74740800847C05 /* LVDate.m in Sources */ = {isa = PBXBuildFile; fileRef = 846E879A1A653DEC000D14DA /* LVDate.m */; }; + 3CFF77D51C74740800847C05 /* LVTimer.m in Sources */ = {isa = PBXBuildFile; fileRef = 846481B91A64C61F00DE6204 /* LVTimer.m */; }; + 3CFF77D61C74740800847C05 /* LVStruct.m in Sources */ = {isa = PBXBuildFile; fileRef = 84185DC01B451E28003E0ECE /* LVStruct.m */; }; + 3CFF77D71C74740900847C05 /* LVGesture.m in Sources */ = {isa = PBXBuildFile; fileRef = 8410D9AF1A70A51C00B22E49 /* LVGesture.m */; }; + 3CFF77D81C74740900847C05 /* LVLongPressGesture.m in Sources */ = {isa = PBXBuildFile; fileRef = 9171D4A31AADD0300040DAA3 /* LVLongPressGesture.m */; }; + 3CFF77D91C74740900847C05 /* LVPanGesture.m in Sources */ = {isa = PBXBuildFile; fileRef = 8410D9AA1A70A00400B22E49 /* LVPanGesture.m */; }; + 3CFF77DA1C74740900847C05 /* LVPinchGesture.m in Sources */ = {isa = PBXBuildFile; fileRef = 91882E8A1AAD45A400107DFC /* LVPinchGesture.m */; }; + 3CFF77DB1C74740900847C05 /* LVRotationGesture.m in Sources */ = {isa = PBXBuildFile; fileRef = 91882E8F1AAD934D00107DFC /* LVRotationGesture.m */; }; + 3CFF77DC1C74740900847C05 /* LVSwipeGesture.m in Sources */ = {isa = PBXBuildFile; fileRef = 918B9F1C1AADA0AC00FC7283 /* LVSwipeGesture.m */; }; + 3CFF77DD1C74740900847C05 /* LVTapGesture.m in Sources */ = {isa = PBXBuildFile; fileRef = 84DF1DA51A6F5BC9009F970A /* LVTapGesture.m */; }; + 3CFF77DF1C74740900847C05 /* LVHttp.m in Sources */ = {isa = PBXBuildFile; fileRef = 8454D1401A7F732500774565 /* LVHttp.m */; }; + 3CFF77E01C74740900847C05 /* LVHttpResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = 8454D1451A7FA7A400774565 /* LVHttpResponse.m */; }; + 3CFF77E11C74740900847C05 /* LVAudioPlayer.m in Sources */ = {isa = PBXBuildFile; fileRef = 842532461ADCB7C0003C05BF /* LVAudioPlayer.m */; }; + 3CFF77E21C74740900847C05 /* LVDB.m in Sources */ = {isa = PBXBuildFile; fileRef = 849708361A67653A00E913F4 /* LVDB.m */; }; + 3CFF77E31C74740900847C05 /* LVDownloader.m in Sources */ = {isa = PBXBuildFile; fileRef = 8425324B1ADCBD3A003C05BF /* LVDownloader.m */; }; + 3CFF77E41C74740900847C05 /* LVFile.m in Sources */ = {isa = PBXBuildFile; fileRef = 84765E2C1ADE37A7002506CB /* LVFile.m */; }; + 3CFF77E51C74740900847C05 /* LVNavigation.m in Sources */ = {isa = PBXBuildFile; fileRef = 84DD8F881B560933001C83E9 /* LVNavigation.m */; }; + 3CFF77E61C74740900847C05 /* LVSystem.m in Sources */ = {isa = PBXBuildFile; fileRef = 8497083B1A6765B000E913F4 /* LVSystem.m */; }; + 3CFF77E81C74740900847C05 /* LVMethod.m in Sources */ = {isa = PBXBuildFile; fileRef = 84CF56791AEA15A500A49B36 /* LVMethod.m */; }; + 3CFF77E91C74740900847C05 /* LVNativeObjBox.m in Sources */ = {isa = PBXBuildFile; fileRef = 84CF56741AE9184000A49B36 /* LVNativeObjBox.m */; }; + 3CFF77EA1C74740900847C05 /* LVLuaObjBox.m in Sources */ = {isa = PBXBuildFile; fileRef = 84DCB2B01B39349A00244C39 /* LVLuaObjBox.m */; }; + 3CFF77EB1C74740900847C05 /* LVPointerValueBox.m in Sources */ = {isa = PBXBuildFile; fileRef = 84DDB85C1B43BAEB006ACE9A /* LVPointerValueBox.m */; }; + 3CFF77EC1C74740900847C05 /* LVUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = 846481BD1A64C61F00DE6204 /* LVUtil.m */; }; + 3CFF77ED1C74740900847C05 /* LVTypeConvert.m in Sources */ = {isa = PBXBuildFile; fileRef = 84DCF03A1B44D91800AD723B /* LVTypeConvert.m */; }; + 3CFF77EE1C74740900847C05 /* LVExGlobalFunc.m in Sources */ = {isa = PBXBuildFile; fileRef = 842D72681A6639A200936AD2 /* LVExGlobalFunc.m */; }; + 3CFF77EF1C74740900847C05 /* LVHeads.m in Sources */ = {isa = PBXBuildFile; fileRef = 846481AD1A64C61F00DE6204 /* LVHeads.m */; }; + 3CFF77F01C74740900847C05 /* LView.m in Sources */ = {isa = PBXBuildFile; fileRef = 840AD5321A5EAB4A0075CB58 /* LView.m */; }; + 3CFF77F11C74740900847C05 /* LVBundle.m in Sources */ = {isa = PBXBuildFile; fileRef = 84E85C191C33B84B007DE3DF /* LVBundle.m */; }; + 3CFF77F21C74740900847C05 /* LVBlock.m in Sources */ = {isa = PBXBuildFile; fileRef = 84E446971AEE0655009C9A8A /* LVBlock.m */; }; + 840BCEDA1CB7602C00D816AD /* LVNetworkStatus.h in Headers */ = {isa = PBXBuildFile; fileRef = 840BCED81CB7602C00D816AD /* LVNetworkStatus.h */; }; + 840BCEDB1CB7602C00D816AD /* LVNetworkStatus.m in Sources */ = {isa = PBXBuildFile; fileRef = 840BCED91CB7602C00D816AD /* LVNetworkStatus.m */; }; + 840BCEE41CB78E8300D816AD /* LVNetworkStatus.m in Sources */ = {isa = PBXBuildFile; fileRef = 840BCED91CB7602C00D816AD /* LVNetworkStatus.m */; }; + 84C1D7CB1C16C3CD0058E974 /* LuaViewSDK-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 84C1D7CA1C16C3CD0058E974 /* LuaViewSDK-Info.plist */; }; + 84C1D7D41C16C3F90058E974 /* LVPkgManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 84D446F11AF75BD8000A3911 /* LVPkgManager.m */; }; + 84C1D7D61C16C3FA0058E974 /* LVRSA.m in Sources */ = {isa = PBXBuildFile; fileRef = 84B1E3801AEF24480054B9F1 /* LVRSA.m */; }; + 84C1D7D71C16C3FA0058E974 /* LVDebugLua.m in Sources */ = {isa = PBXBuildFile; fileRef = 842142A21ACD3427001FD0ED /* LVDebugLua.m */; }; + 84C1D7D81C16C3FA0058E974 /* LVDebuger.m in Sources */ = {isa = PBXBuildFile; fileRef = 91ACCE761AC531160034D9B3 /* LVDebuger.m */; }; + 84C1D7D91C16C3FA0058E974 /* LVDebugConnection.m in Sources */ = {isa = PBXBuildFile; fileRef = 84BC621F1BA95A3F0019B02E /* LVDebugConnection.m */; }; + 84C1D7DA1C16C3FA0058E974 /* LVBaseView.m in Sources */ = {isa = PBXBuildFile; fileRef = 846481A91A64C61F00DE6204 /* LVBaseView.m */; }; + 84C1D7DB1C16C3FA0058E974 /* UIScrollView+LuaView.m in Sources */ = {isa = PBXBuildFile; fileRef = 84F4A01E1B4B9E600062A7B2 /* UIScrollView+LuaView.m */; }; + 84C1D7DC1C16C3FA0058E974 /* UIView+LuaView.m in Sources */ = {isa = PBXBuildFile; fileRef = 843447491B61DDED0039B98A /* UIView+LuaView.m */; }; + 84C1D7DD1C16C3FA0058E974 /* LVButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 846481AB1A64C61F00DE6204 /* LVButton.m */; }; + 84C1D7DE1C16C3FA0058E974 /* LVImage.m in Sources */ = {isa = PBXBuildFile; fileRef = 846481AF1A64C61F00DE6204 /* LVImage.m */; }; + 84C1D7DF1C16C3FA0058E974 /* LVNinePatchImage.m in Sources */ = {isa = PBXBuildFile; fileRef = 8446F15C1BDF57F2007E4064 /* LVNinePatchImage.m */; }; + 84C1D7E01C16C3FA0058E974 /* LVLabel.m in Sources */ = {isa = PBXBuildFile; fileRef = 846481B11A64C61F00DE6204 /* LVLabel.m */; }; + 84C1D7E11C16C3FA0058E974 /* LVTextField.m in Sources */ = {isa = PBXBuildFile; fileRef = 846481B71A64C61F00DE6204 /* LVTextField.m */; }; + 84C1D7E21C16C3FA0058E974 /* LVLoadingIndicator.m in Sources */ = {isa = PBXBuildFile; fileRef = 84B58E391B65CC260048F33D /* LVLoadingIndicator.m */; }; + 84C1D7E31C16C3FA0058E974 /* LVPagerIndicator.m in Sources */ = {isa = PBXBuildFile; fileRef = 846481B31A64C61F00DE6204 /* LVPagerIndicator.m */; }; + 84C1D7E71C16C3FA0058E974 /* LVPagerView.m in Sources */ = {isa = PBXBuildFile; fileRef = 84799AF41BAFECA00070E214 /* LVPagerView.m */; }; + 84C1D7E81C16C3FA0058E974 /* LVPagerViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 84799AF91BAFEFDA0070E214 /* LVPagerViewCell.m */; }; + 84C1D7E91C16C3FA0058E974 /* LVCollectionView.m in Sources */ = {isa = PBXBuildFile; fileRef = 848CA35E1B29669A00C70321 /* LVCollectionView.m */; }; + 84C1D7EA1C16C3FA0058E974 /* LVCollectionViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 848CA3631B29748800C70321 /* LVCollectionViewCell.m */; }; + 84C1D7EB1C16C3FA0058E974 /* LVCollectionViewDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 8481E0641BD7B29100FDFEEA /* LVCollectionViewDelegate.m */; }; + 84C1D7EC1C16C3FA0058E974 /* LVScrollView.m in Sources */ = {isa = PBXBuildFile; fileRef = 846481B51A64C61F00DE6204 /* LVScrollView.m */; }; + 84C1D7ED1C16C3FA0058E974 /* LVScrollViewDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 8481E05A1BD7AC8000FDFEEA /* LVScrollViewDelegate.m */; }; + 84C1D7EE1C16C3FA0058E974 /* LVCustomPanel.m in Sources */ = {isa = PBXBuildFile; fileRef = 84056E711B5CA5990078F9D6 /* LVCustomPanel.m */; }; + 84C1D7EF1C16C3FA0058E974 /* LVAlert.m in Sources */ = {isa = PBXBuildFile; fileRef = 842D726D1A6643DB00936AD2 /* LVAlert.m */; }; + 84C1D7F01C16C3FA0058E974 /* LVToast.m in Sources */ = {isa = PBXBuildFile; fileRef = 8468C9701BDA177C002D4B1E /* LVToast.m */; }; + 84C1D7F11C16C3FA0058E974 /* LVAnimate.m in Sources */ = {isa = PBXBuildFile; fileRef = 846481A71A64C61F00DE6204 /* LVAnimate.m */; }; + 84C1D7F21C16C3FA0058E974 /* LVStyledString.m in Sources */ = {isa = PBXBuildFile; fileRef = 84342D8D1AE0E02B00ECB4EF /* LVStyledString.m */; }; + 84C1D7F31C16C3FA0058E974 /* LVTransform3D.m in Sources */ = {isa = PBXBuildFile; fileRef = 846481BB1A64C61F00DE6204 /* LVTransform3D.m */; }; + 84C1D7F41C16C3FA0058E974 /* LVData.m in Sources */ = {isa = PBXBuildFile; fileRef = 84C3B7291A84622A00923404 /* LVData.m */; }; + 84C1D7F51C16C3FA0058E974 /* LVDate.m in Sources */ = {isa = PBXBuildFile; fileRef = 846E879A1A653DEC000D14DA /* LVDate.m */; }; + 84C1D7F61C16C3FA0058E974 /* LVTimer.m in Sources */ = {isa = PBXBuildFile; fileRef = 846481B91A64C61F00DE6204 /* LVTimer.m */; }; + 84C1D7F71C16C3FA0058E974 /* LVStruct.m in Sources */ = {isa = PBXBuildFile; fileRef = 84185DC01B451E28003E0ECE /* LVStruct.m */; }; + 84C1D7F81C16C3FA0058E974 /* LVGesture.m in Sources */ = {isa = PBXBuildFile; fileRef = 8410D9AF1A70A51C00B22E49 /* LVGesture.m */; }; + 84C1D7F91C16C3FA0058E974 /* LVLongPressGesture.m in Sources */ = {isa = PBXBuildFile; fileRef = 9171D4A31AADD0300040DAA3 /* LVLongPressGesture.m */; }; + 84C1D7FA1C16C3FA0058E974 /* LVPanGesture.m in Sources */ = {isa = PBXBuildFile; fileRef = 8410D9AA1A70A00400B22E49 /* LVPanGesture.m */; }; + 84C1D7FB1C16C3FA0058E974 /* LVPinchGesture.m in Sources */ = {isa = PBXBuildFile; fileRef = 91882E8A1AAD45A400107DFC /* LVPinchGesture.m */; }; + 84C1D7FC1C16C3FA0058E974 /* LVRotationGesture.m in Sources */ = {isa = PBXBuildFile; fileRef = 91882E8F1AAD934D00107DFC /* LVRotationGesture.m */; }; + 84C1D7FD1C16C3FA0058E974 /* LVSwipeGesture.m in Sources */ = {isa = PBXBuildFile; fileRef = 918B9F1C1AADA0AC00FC7283 /* LVSwipeGesture.m */; }; + 84C1D7FE1C16C3FA0058E974 /* LVTapGesture.m in Sources */ = {isa = PBXBuildFile; fileRef = 84DF1DA51A6F5BC9009F970A /* LVTapGesture.m */; }; + 84C1D8001C16C3FA0058E974 /* LVHttp.m in Sources */ = {isa = PBXBuildFile; fileRef = 8454D1401A7F732500774565 /* LVHttp.m */; }; + 84C1D8011C16C3FA0058E974 /* LVHttpResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = 8454D1451A7FA7A400774565 /* LVHttpResponse.m */; }; + 84C1D8021C16C3FA0058E974 /* LVAudioPlayer.m in Sources */ = {isa = PBXBuildFile; fileRef = 842532461ADCB7C0003C05BF /* LVAudioPlayer.m */; }; + 84C1D8031C16C3FA0058E974 /* LVDB.m in Sources */ = {isa = PBXBuildFile; fileRef = 849708361A67653A00E913F4 /* LVDB.m */; }; + 84C1D8041C16C3FA0058E974 /* LVDownloader.m in Sources */ = {isa = PBXBuildFile; fileRef = 8425324B1ADCBD3A003C05BF /* LVDownloader.m */; }; + 84C1D8051C16C3FA0058E974 /* LVFile.m in Sources */ = {isa = PBXBuildFile; fileRef = 84765E2C1ADE37A7002506CB /* LVFile.m */; }; + 84C1D8061C16C3FA0058E974 /* LVNavigation.m in Sources */ = {isa = PBXBuildFile; fileRef = 84DD8F881B560933001C83E9 /* LVNavigation.m */; }; + 84C1D8071C16C3FA0058E974 /* LVSystem.m in Sources */ = {isa = PBXBuildFile; fileRef = 8497083B1A6765B000E913F4 /* LVSystem.m */; }; + 84C1D8091C16C3FA0058E974 /* LVMethod.m in Sources */ = {isa = PBXBuildFile; fileRef = 84CF56791AEA15A500A49B36 /* LVMethod.m */; }; + 84C1D80A1C16C3FA0058E974 /* LVNativeObjBox.m in Sources */ = {isa = PBXBuildFile; fileRef = 84CF56741AE9184000A49B36 /* LVNativeObjBox.m */; }; + 84C1D80B1C16C3FA0058E974 /* LVLuaObjBox.m in Sources */ = {isa = PBXBuildFile; fileRef = 84DCB2B01B39349A00244C39 /* LVLuaObjBox.m */; }; + 84C1D80C1C16C3FA0058E974 /* LVPointerValueBox.m in Sources */ = {isa = PBXBuildFile; fileRef = 84DDB85C1B43BAEB006ACE9A /* LVPointerValueBox.m */; }; + 84C1D80D1C16C3FA0058E974 /* LVUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = 846481BD1A64C61F00DE6204 /* LVUtil.m */; }; + 84C1D80E1C16C3FA0058E974 /* LVTypeConvert.m in Sources */ = {isa = PBXBuildFile; fileRef = 84DCF03A1B44D91800AD723B /* LVTypeConvert.m */; }; + 84C1D80F1C16C3FA0058E974 /* LVExGlobalFunc.m in Sources */ = {isa = PBXBuildFile; fileRef = 842D72681A6639A200936AD2 /* LVExGlobalFunc.m */; }; + 84C1D8101C16C3FA0058E974 /* LVHeads.m in Sources */ = {isa = PBXBuildFile; fileRef = 846481AD1A64C61F00DE6204 /* LVHeads.m */; }; + 84C1D8111C16C3FA0058E974 /* LView.m in Sources */ = {isa = PBXBuildFile; fileRef = 840AD5321A5EAB4A0075CB58 /* LView.m */; }; + 84C1D8131C16C3FA0058E974 /* LVBlock.m in Sources */ = {isa = PBXBuildFile; fileRef = 84E446971AEE0655009C9A8A /* LVBlock.m */; }; + 84C1D8341C16C4490058E974 /* LVPkgManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 84D446F01AF75BD8000A3911 /* LVPkgManager.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 84C1D8361C16C4490058E974 /* LVRSA.h in Headers */ = {isa = PBXBuildFile; fileRef = 84B1E37F1AEF24480054B9F1 /* LVRSA.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 84C1D8371C16C4490058E974 /* LVDebuger.h in Headers */ = {isa = PBXBuildFile; fileRef = 91ACCE751AC531160034D9B3 /* LVDebuger.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 84C1D8381C16C4490058E974 /* LVDebugConnection.h in Headers */ = {isa = PBXBuildFile; fileRef = 84BC621E1BA95A3F0019B02E /* LVDebugConnection.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 84C1D8391C16C4490058E974 /* LVBaseView.h in Headers */ = {isa = PBXBuildFile; fileRef = 846481A81A64C61F00DE6204 /* LVBaseView.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 84C1D83A1C16C4490058E974 /* UIScrollView+LuaView.h in Headers */ = {isa = PBXBuildFile; fileRef = 84F4A01D1B4B9E600062A7B2 /* UIScrollView+LuaView.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 84C1D83B1C16C44A0058E974 /* UIView+LuaView.h in Headers */ = {isa = PBXBuildFile; fileRef = 843447481B61DDED0039B98A /* UIView+LuaView.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 84C1D83C1C16C44A0058E974 /* LVButton.h in Headers */ = {isa = PBXBuildFile; fileRef = 846481AA1A64C61F00DE6204 /* LVButton.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 84C1D83D1C16C44A0058E974 /* LVImage.h in Headers */ = {isa = PBXBuildFile; fileRef = 846481AE1A64C61F00DE6204 /* LVImage.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 84C1D83E1C16C44A0058E974 /* LVNinePatchImage.h in Headers */ = {isa = PBXBuildFile; fileRef = 8446F15B1BDF57F2007E4064 /* LVNinePatchImage.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 84C1D83F1C16C44A0058E974 /* LVLabel.h in Headers */ = {isa = PBXBuildFile; fileRef = 846481B01A64C61F00DE6204 /* LVLabel.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 84C1D8401C16C44A0058E974 /* LVTextField.h in Headers */ = {isa = PBXBuildFile; fileRef = 846481B61A64C61F00DE6204 /* LVTextField.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 84C1D8411C16C44A0058E974 /* LVLoadingIndicator.h in Headers */ = {isa = PBXBuildFile; fileRef = 84B58E381B65CC260048F33D /* LVLoadingIndicator.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 84C1D8421C16C44A0058E974 /* LVPagerIndicator.h in Headers */ = {isa = PBXBuildFile; fileRef = 846481B21A64C61F00DE6204 /* LVPagerIndicator.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 84C1D8461C16C44A0058E974 /* LVPagerView.h in Headers */ = {isa = PBXBuildFile; fileRef = 84799AF31BAFECA00070E214 /* LVPagerView.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 84C1D8471C16C44A0058E974 /* LVPagerViewCell.h in Headers */ = {isa = PBXBuildFile; fileRef = 84799AF81BAFEFDA0070E214 /* LVPagerViewCell.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 84C1D8481C16C44A0058E974 /* LVCollectionView.h in Headers */ = {isa = PBXBuildFile; fileRef = 848CA35D1B29669A00C70321 /* LVCollectionView.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 84C1D8491C16C44A0058E974 /* LVCollectionViewCell.h in Headers */ = {isa = PBXBuildFile; fileRef = 848CA3621B29748800C70321 /* LVCollectionViewCell.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 84C1D84A1C16C44A0058E974 /* LVCollectionViewDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 8481E0631BD7B29100FDFEEA /* LVCollectionViewDelegate.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 84C1D84B1C16C44A0058E974 /* LVScrollView.h in Headers */ = {isa = PBXBuildFile; fileRef = 846481B41A64C61F00DE6204 /* LVScrollView.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 84C1D84C1C16C44A0058E974 /* LVScrollViewDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 8481E0591BD7AC8000FDFEEA /* LVScrollViewDelegate.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 84C1D84D1C16C44A0058E974 /* LVCustomPanel.h in Headers */ = {isa = PBXBuildFile; fileRef = 84056E701B5CA5990078F9D6 /* LVCustomPanel.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 84C1D84E1C16C44A0058E974 /* LVAlert.h in Headers */ = {isa = PBXBuildFile; fileRef = 842D726C1A6643DB00936AD2 /* LVAlert.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 84C1D84F1C16C44A0058E974 /* LVToast.h in Headers */ = {isa = PBXBuildFile; fileRef = 8468C96F1BDA177C002D4B1E /* LVToast.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 84C1D8501C16C44A0058E974 /* LVAnimate.h in Headers */ = {isa = PBXBuildFile; fileRef = 846481A61A64C61F00DE6204 /* LVAnimate.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 84C1D8511C16C44B0058E974 /* LVStyledString.h in Headers */ = {isa = PBXBuildFile; fileRef = 84342D8C1AE0E02B00ECB4EF /* LVStyledString.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 84C1D8521C16C44B0058E974 /* LVTransform3D.h in Headers */ = {isa = PBXBuildFile; fileRef = 846481BA1A64C61F00DE6204 /* LVTransform3D.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 84C1D8531C16C44B0058E974 /* LVData.h in Headers */ = {isa = PBXBuildFile; fileRef = 84C3B7281A84622A00923404 /* LVData.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 84C1D8541C16C44B0058E974 /* LVDate.h in Headers */ = {isa = PBXBuildFile; fileRef = 846E87991A653DEC000D14DA /* LVDate.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 84C1D8551C16C44B0058E974 /* LVTimer.h in Headers */ = {isa = PBXBuildFile; fileRef = 846481B81A64C61F00DE6204 /* LVTimer.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 84C1D8561C16C44B0058E974 /* LVStruct.h in Headers */ = {isa = PBXBuildFile; fileRef = 84185DBF1B451E28003E0ECE /* LVStruct.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 84C1D8571C16C44B0058E974 /* LVGesture.h in Headers */ = {isa = PBXBuildFile; fileRef = 8410D9AE1A70A51C00B22E49 /* LVGesture.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 84C1D8581C16C44B0058E974 /* LVLongPressGesture.h in Headers */ = {isa = PBXBuildFile; fileRef = 9171D4A21AADD0300040DAA3 /* LVLongPressGesture.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 84C1D8591C16C44B0058E974 /* LVPanGesture.h in Headers */ = {isa = PBXBuildFile; fileRef = 8410D9A91A70A00400B22E49 /* LVPanGesture.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 84C1D85A1C16C44B0058E974 /* LVPinchGesture.h in Headers */ = {isa = PBXBuildFile; fileRef = 91882E891AAD45A400107DFC /* LVPinchGesture.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 84C1D85B1C16C44B0058E974 /* LVRotationGesture.h in Headers */ = {isa = PBXBuildFile; fileRef = 91882E8E1AAD934D00107DFC /* LVRotationGesture.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 84C1D85C1C16C44C0058E974 /* LVSwipeGesture.h in Headers */ = {isa = PBXBuildFile; fileRef = 918B9F1B1AADA0AC00FC7283 /* LVSwipeGesture.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 84C1D85D1C16C44C0058E974 /* LVTapGesture.h in Headers */ = {isa = PBXBuildFile; fileRef = 84DF1DA41A6F5BC9009F970A /* LVTapGesture.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 84C1D85F1C16C44C0058E974 /* LVHttp.h in Headers */ = {isa = PBXBuildFile; fileRef = 8454D13F1A7F732500774565 /* LVHttp.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 84C1D8601C16C44C0058E974 /* LVHttpResponse.h in Headers */ = {isa = PBXBuildFile; fileRef = 8454D1441A7FA7A400774565 /* LVHttpResponse.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 84C1D8611C16C44C0058E974 /* LVAudioPlayer.h in Headers */ = {isa = PBXBuildFile; fileRef = 842532451ADCB7C0003C05BF /* LVAudioPlayer.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 84C1D8621C16C44C0058E974 /* LVDB.h in Headers */ = {isa = PBXBuildFile; fileRef = 849708351A67653A00E913F4 /* LVDB.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 84C1D8631C16C44C0058E974 /* LVDownloader.h in Headers */ = {isa = PBXBuildFile; fileRef = 8425324A1ADCBD3A003C05BF /* LVDownloader.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 84C1D8641C16C44D0058E974 /* LVFile.h in Headers */ = {isa = PBXBuildFile; fileRef = 84765E2B1ADE37A7002506CB /* LVFile.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 84C1D8651C16C44D0058E974 /* LVNavigation.h in Headers */ = {isa = PBXBuildFile; fileRef = 84DD8F871B560933001C83E9 /* LVNavigation.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 84C1D8661C16C44D0058E974 /* LVSystem.h in Headers */ = {isa = PBXBuildFile; fileRef = 8497083A1A6765B000E913F4 /* LVSystem.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 84C1D8681C16C44D0058E974 /* LVMethod.h in Headers */ = {isa = PBXBuildFile; fileRef = 84CF56781AEA15A500A49B36 /* LVMethod.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 84C1D8691C16C44D0058E974 /* LVNativeObjBox.h in Headers */ = {isa = PBXBuildFile; fileRef = 84CF56731AE9184000A49B36 /* LVNativeObjBox.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 84C1D86A1C16C44E0058E974 /* LVLuaObjBox.h in Headers */ = {isa = PBXBuildFile; fileRef = 84DCB2AF1B39349A00244C39 /* LVLuaObjBox.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 84C1D86B1C16C44E0058E974 /* LVPointerValueBox.h in Headers */ = {isa = PBXBuildFile; fileRef = 84DDB85B1B43BAEB006ACE9A /* LVPointerValueBox.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 84C1D86C1C16C44E0058E974 /* LVUtil.h in Headers */ = {isa = PBXBuildFile; fileRef = 846481BC1A64C61F00DE6204 /* LVUtil.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 84C1D86D1C16C44E0058E974 /* LVTypeConvert.h in Headers */ = {isa = PBXBuildFile; fileRef = 84DCF0391B44D91800AD723B /* LVTypeConvert.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 84C1D86E1C16C44E0058E974 /* LVExGlobalFunc.h in Headers */ = {isa = PBXBuildFile; fileRef = 842D72671A6639A200936AD2 /* LVExGlobalFunc.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 84C1D86F1C16C44E0058E974 /* LVHeads.h in Headers */ = {isa = PBXBuildFile; fileRef = 846481AC1A64C61F00DE6204 /* LVHeads.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 84C1D8871C16C4540058E974 /* LView.h in Headers */ = {isa = PBXBuildFile; fileRef = 840AD5311A5EAB4A0075CB58 /* LView.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 84C1D8891C16C4550058E974 /* LVBlock.h in Headers */ = {isa = PBXBuildFile; fileRef = 84E446961AEE0655009C9A8A /* LVBlock.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 84C1D8A11C16CC870058E974 /* Dummy.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 84C1D8911C16CA540058E974 /* Dummy.h */; }; + 84C1D8A21C16CC930058E974 /* Dummy.m in Sources */ = {isa = PBXBuildFile; fileRef = 84C1D8921C16CA540058E974 /* Dummy.m */; }; + 84E85C1A1C33B84B007DE3DF /* LVBundle.h in Headers */ = {isa = PBXBuildFile; fileRef = 84E85C181C33B84B007DE3DF /* LVBundle.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 84E85C1C1C33B84B007DE3DF /* LVBundle.m in Sources */ = {isa = PBXBuildFile; fileRef = 84E85C191C33B84B007DE3DF /* LVBundle.m */; }; + 9112709A1DFAC65F001F8047 /* LVEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 911270981DFAC65F001F8047 /* LVEvent.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 9112709B1DFAC65F001F8047 /* LVEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 911270991DFAC65F001F8047 /* LVEvent.m */; }; + 9112709C1DFAC65F001F8047 /* LVEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 911270991DFAC65F001F8047 /* LVEvent.m */; }; + 914D5F3B1DD3275D00CEA3FF /* LVClassInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 914D5F391DD3275D00CEA3FF /* LVClassInfo.h */; }; + 914D5F3C1DD3275D00CEA3FF /* LVClassInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 914D5F3A1DD3275D00CEA3FF /* LVClassInfo.m */; }; + 914D5F3D1DD3276400CEA3FF /* LVClassInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 914D5F3A1DD3275D00CEA3FF /* LVClassInfo.m */; }; + 91666CF61E6ECDE8005BC162 /* NSObject+LuaView.h in Headers */ = {isa = PBXBuildFile; fileRef = 91666CF41E6ECDE8005BC162 /* NSObject+LuaView.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 91666CF71E6ECDE8005BC162 /* NSObject+LuaView.m in Sources */ = {isa = PBXBuildFile; fileRef = 91666CF51E6ECDE8005BC162 /* NSObject+LuaView.m */; }; + 91666CF81E6ECDE8005BC162 /* NSObject+LuaView.m in Sources */ = {isa = PBXBuildFile; fileRef = 91666CF51E6ECDE8005BC162 /* NSObject+LuaView.m */; }; + 91695AA91E11004B0088EFD6 /* UIScrollView+LVRefresh.h in Headers */ = {isa = PBXBuildFile; fileRef = 91695AA11E11004B0088EFD6 /* UIScrollView+LVRefresh.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 91695AAA1E11004B0088EFD6 /* UIScrollView+LVRefresh.m in Sources */ = {isa = PBXBuildFile; fileRef = 91695AA21E11004B0088EFD6 /* UIScrollView+LVRefresh.m */; }; + 91695AAB1E11004B0088EFD6 /* UIScrollView+LVRefresh.m in Sources */ = {isa = PBXBuildFile; fileRef = 91695AA21E11004B0088EFD6 /* UIScrollView+LVRefresh.m */; }; + 91695AAC1E11004B0088EFD6 /* LVRefreshConst.h in Headers */ = {isa = PBXBuildFile; fileRef = 91695AA31E11004B0088EFD6 /* LVRefreshConst.h */; }; + 91695AAD1E11004B0088EFD6 /* LVRefreshConst.m in Sources */ = {isa = PBXBuildFile; fileRef = 91695AA41E11004B0088EFD6 /* LVRefreshConst.m */; }; + 91695AAE1E11004B0088EFD6 /* LVRefreshConst.m in Sources */ = {isa = PBXBuildFile; fileRef = 91695AA41E11004B0088EFD6 /* LVRefreshConst.m */; }; + 91695AAF1E11004B0088EFD6 /* LVRefreshComponent.h in Headers */ = {isa = PBXBuildFile; fileRef = 91695AA51E11004B0088EFD6 /* LVRefreshComponent.h */; }; + 91695AB01E11004B0088EFD6 /* LVRefreshComponent.m in Sources */ = {isa = PBXBuildFile; fileRef = 91695AA61E11004B0088EFD6 /* LVRefreshComponent.m */; }; + 91695AB11E11004B0088EFD6 /* LVRefreshComponent.m in Sources */ = {isa = PBXBuildFile; fileRef = 91695AA61E11004B0088EFD6 /* LVRefreshComponent.m */; }; + 91695AB21E11004B0088EFD6 /* LVRefreshHeader.h in Headers */ = {isa = PBXBuildFile; fileRef = 91695AA71E11004B0088EFD6 /* LVRefreshHeader.h */; }; + 91695AB31E11004B0088EFD6 /* LVRefreshHeader.m in Sources */ = {isa = PBXBuildFile; fileRef = 91695AA81E11004B0088EFD6 /* LVRefreshHeader.m */; }; + 91695AB41E11004B0088EFD6 /* LVRefreshHeader.m in Sources */ = {isa = PBXBuildFile; fileRef = 91695AA81E11004B0088EFD6 /* LVRefreshHeader.m */; }; + 91695AB81E1222DD0088EFD6 /* LVEmptyRefreshCollectionView.h in Headers */ = {isa = PBXBuildFile; fileRef = 91695AB61E1222DD0088EFD6 /* LVEmptyRefreshCollectionView.h */; }; + 91695AB91E1222DD0088EFD6 /* LVEmptyRefreshCollectionView.m in Sources */ = {isa = PBXBuildFile; fileRef = 91695AB71E1222DD0088EFD6 /* LVEmptyRefreshCollectionView.m */; }; + 91695ABA1E1222DD0088EFD6 /* LVEmptyRefreshCollectionView.m in Sources */ = {isa = PBXBuildFile; fileRef = 91695AB71E1222DD0088EFD6 /* LVEmptyRefreshCollectionView.m */; }; + 9190C01A1EA868670051E919 /* LVBitmap.h in Headers */ = {isa = PBXBuildFile; fileRef = 9190C0181EA868670051E919 /* LVBitmap.h */; }; + 9190C01B1EA868670051E919 /* LVBitmap.m in Sources */ = {isa = PBXBuildFile; fileRef = 9190C0191EA868670051E919 /* LVBitmap.m */; }; + 91A8CFF91E1F649F006D1609 /* LVPkgInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 91A8CFF71E1F649F006D1609 /* LVPkgInfo.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 91A8CFFA1E1F649F006D1609 /* LVPkgInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 91A8CFF81E1F649F006D1609 /* LVPkgInfo.m */; }; + 91A8CFFB1E1F649F006D1609 /* LVPkgInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 91A8CFF81E1F649F006D1609 /* LVPkgInfo.m */; }; + 91B1A4831E6E871E000F71B3 /* LuaViewCore.h in Headers */ = {isa = PBXBuildFile; fileRef = 91B1A4811E6E871E000F71B3 /* LuaViewCore.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 91B1A4841E6E871E000F71B3 /* LuaViewCore.m in Sources */ = {isa = PBXBuildFile; fileRef = 91B1A4821E6E871E000F71B3 /* LuaViewCore.m */; }; + 91B1A4851E6E871E000F71B3 /* LuaViewCore.m in Sources */ = {isa = PBXBuildFile; fileRef = 91B1A4821E6E871E000F71B3 /* LuaViewCore.m */; }; + 91B1A4881E6E873F000F71B3 /* LuaView.h in Headers */ = {isa = PBXBuildFile; fileRef = 91B1A4861E6E873F000F71B3 /* LuaView.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 91B1A4891E6E873F000F71B3 /* LuaView.m in Sources */ = {isa = PBXBuildFile; fileRef = 91B1A4871E6E873F000F71B3 /* LuaView.m */; }; + 91B1A48A1E6E873F000F71B3 /* LuaView.m in Sources */ = {isa = PBXBuildFile; fileRef = 91B1A4871E6E873F000F71B3 /* LuaView.m */; }; + 91C55C721DD07185000BCB0B /* LVFlowLayout.h in Headers */ = {isa = PBXBuildFile; fileRef = 91C55C701DD07185000BCB0B /* LVFlowLayout.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 91C55C731DD07185000BCB0B /* LVFlowLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = 91C55C711DD07185000BCB0B /* LVFlowLayout.m */; }; + 91C55C741DD07DAF000BCB0B /* LVFlowLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = 91C55C711DD07185000BCB0B /* LVFlowLayout.m */; }; + 91F678841DF520920042D6FC /* LVCustomView.h in Headers */ = {isa = PBXBuildFile; fileRef = 91F678821DF520920042D6FC /* LVCustomView.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 91F678851DF520920042D6FC /* LVCustomView.m in Sources */ = {isa = PBXBuildFile; fileRef = 91F678831DF520920042D6FC /* LVCustomView.m */; }; + 91F678861DF5209B0042D6FC /* LVCustomView.m in Sources */ = {isa = PBXBuildFile; fileRef = 91F678831DF520920042D6FC /* LVCustomView.m */; }; + 91F678891DF561D40042D6FC /* LVCanvas.h in Headers */ = {isa = PBXBuildFile; fileRef = 91F678871DF561D40042D6FC /* LVCanvas.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 91F6788A1DF561D40042D6FC /* LVCanvas.m in Sources */ = {isa = PBXBuildFile; fileRef = 91F678881DF561D40042D6FC /* LVCanvas.m */; }; + 91F6788B1DF561D40042D6FC /* LVCanvas.m in Sources */ = {isa = PBXBuildFile; fileRef = 91F678881DF561D40042D6FC /* LVCanvas.m */; }; + BE9CD4F81CACC02800D6AC94 /* JUFLXTargeNamespace.h in Headers */ = {isa = PBXBuildFile; fileRef = BE9CD4F61CACC02800D6AC94 /* JUFLXTargeNamespace.h */; }; + BE9CD4F91CACC02800D6AC94 /* JUFLXLayoutDefine.h in Headers */ = {isa = PBXBuildFile; fileRef = BE9CD4F71CACC02800D6AC94 /* JUFLXLayoutDefine.h */; }; + BEEB28CE1CA90EC200EC2D86 /* JUFLXCSSParser.h in Headers */ = {isa = PBXBuildFile; fileRef = BEEB28C21CA90EC200EC2D86 /* JUFLXCSSParser.h */; }; + BEEB28CF1CA90EC200EC2D86 /* JUFLXCSSParser.m in Sources */ = {isa = PBXBuildFile; fileRef = BEEB28C31CA90EC200EC2D86 /* JUFLXCSSParser.m */; }; + BEEB28D01CA90EC200EC2D86 /* JUFLXLayoutKit.h in Headers */ = {isa = PBXBuildFile; fileRef = BEEB28C41CA90EC200EC2D86 /* JUFLXLayoutKit.h */; }; + BEEB28D11CA90EC200EC2D86 /* JUFLXNode.h in Headers */ = {isa = PBXBuildFile; fileRef = BEEB28C51CA90EC200EC2D86 /* JUFLXNode.h */; }; + BEEB28D21CA90EC200EC2D86 /* JUFLXNode.m in Sources */ = {isa = PBXBuildFile; fileRef = BEEB28C61CA90EC200EC2D86 /* JUFLXNode.m */; }; + BEEB28D31CA90EC200EC2D86 /* Layout.c in Sources */ = {isa = PBXBuildFile; fileRef = BEEB28C71CA90EC200EC2D86 /* Layout.c */; }; + BEEB28D41CA90EC200EC2D86 /* Layout.h in Headers */ = {isa = PBXBuildFile; fileRef = BEEB28C81CA90EC200EC2D86 /* Layout.h */; }; + BEEB28D51CA90EC200EC2D86 /* JUFLXLinearLayoutView.h in Headers */ = {isa = PBXBuildFile; fileRef = BEEB28CA1CA90EC200EC2D86 /* JUFLXLinearLayoutView.h */; }; + BEEB28D61CA90EC200EC2D86 /* JUFLXLinearLayoutView.m in Sources */ = {isa = PBXBuildFile; fileRef = BEEB28CB1CA90EC200EC2D86 /* JUFLXLinearLayoutView.m */; }; + BEEB28D71CA90EC200EC2D86 /* UIView+JUFLXNode.h in Headers */ = {isa = PBXBuildFile; fileRef = BEEB28CC1CA90EC200EC2D86 /* UIView+JUFLXNode.h */; }; + BEEB28D81CA90EC200EC2D86 /* UIView+JUFLXNode.m in Sources */ = {isa = PBXBuildFile; fileRef = BEEB28CD1CA90EC200EC2D86 /* UIView+JUFLXNode.m */; }; + BEEB28DF1CA91B8600EC2D86 /* JUFLXCSSParser.m in Sources */ = {isa = PBXBuildFile; fileRef = BEEB28C31CA90EC200EC2D86 /* JUFLXCSSParser.m */; }; + BEEB28E01CA91B8900EC2D86 /* JUFLXNode.m in Sources */ = {isa = PBXBuildFile; fileRef = BEEB28C61CA90EC200EC2D86 /* JUFLXNode.m */; }; + BEEB28E11CA91B9000EC2D86 /* Layout.c in Sources */ = {isa = PBXBuildFile; fileRef = BEEB28C71CA90EC200EC2D86 /* Layout.c */; }; + BEEB28E21CA91B9500EC2D86 /* JUFLXLinearLayoutView.m in Sources */ = {isa = PBXBuildFile; fileRef = BEEB28CB1CA90EC200EC2D86 /* JUFLXLinearLayoutView.m */; }; + BEEB28E31CA91B9900EC2D86 /* UIView+JUFLXNode.m in Sources */ = {isa = PBXBuildFile; fileRef = BEEB28CD1CA90EC200EC2D86 /* UIView+JUFLXNode.m */; }; +/* End PBXBuildFile section */ + +/* Begin PBXCopyFilesBuildPhase section */ + 3CFF77A71C7473A800847C05 /* CopyFiles */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = "include/$(PRODUCT_NAME)"; + dstSubfolderSpec = 16; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 84C1D8961C16CB820058E974 /* CopyFiles */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = "include/$(PRODUCT_NAME)"; + dstSubfolderSpec = 16; + files = ( + 84C1D8A11C16CC870058E974 /* Dummy.h in CopyFiles */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + 151AA3B1FB2503E3C4CD0FC9 /* Pods-Dummy.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Dummy.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Dummy/Pods-Dummy.debug.xcconfig"; sourceTree = ""; }; + 158CD13BD2B405C24DFE7560 /* Pods-Dummy.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Dummy.release.xcconfig"; path = "Pods/Target Support Files/Pods-Dummy/Pods-Dummy.release.xcconfig"; sourceTree = ""; }; + 224569A21F0B62DA000CDE49 /* LVCamera.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVCamera.h; sourceTree = ""; }; + 224569A31F0B62DA000CDE49 /* LVCamera.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVCamera.m; sourceTree = ""; }; + 3661550721FB71AF60C9B439 /* Pods-LuaViewSDK.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-LuaViewSDK.release.xcconfig"; path = "Pods/Target Support Files/Pods-LuaViewSDK/Pods-LuaViewSDK.release.xcconfig"; sourceTree = ""; }; + 3C02D1D71C31106E00213386 /* LVAnimator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVAnimator.h; sourceTree = ""; }; + 3C02D1D81C31106E00213386 /* LVAnimator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVAnimator.m; sourceTree = ""; }; + 3C98A5381C7C0C100001508E /* LViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LViewController.h; path = ../LViewController.h; sourceTree = ""; }; + 3C98A5391C7C0C100001508E /* LViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = LViewController.m; path = ../LViewController.m; sourceTree = ""; }; + 3CC1B5511C96B59D001DEEC0 /* LVZipArchive.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LVZipArchive.h; path = PKG/LVZipArchive.h; sourceTree = ""; }; + 3CC1B5521C96B59D001DEEC0 /* LVZipArchive.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = LVZipArchive.m; path = PKG/LVZipArchive.m; sourceTree = ""; }; + 3CFF77A91C7473A800847C05 /* libLuaViewLib.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libLuaViewLib.a; sourceTree = BUILT_PRODUCTS_DIR; }; + 84056E701B5CA5990078F9D6 /* LVCustomPanel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVCustomPanel.h; sourceTree = ""; }; + 84056E711B5CA5990078F9D6 /* LVCustomPanel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVCustomPanel.m; sourceTree = ""; }; + 840AD5311A5EAB4A0075CB58 /* LView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LView.h; path = ../LView.h; sourceTree = ""; }; + 840AD5321A5EAB4A0075CB58 /* LView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = LView.m; path = ../LView.m; sourceTree = ""; }; + 840BCED81CB7602C00D816AD /* LVNetworkStatus.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVNetworkStatus.h; sourceTree = ""; }; + 840BCED91CB7602C00D816AD /* LVNetworkStatus.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVNetworkStatus.m; sourceTree = ""; }; + 8410D9A91A70A00400B22E49 /* LVPanGesture.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVPanGesture.h; sourceTree = ""; }; + 8410D9AA1A70A00400B22E49 /* LVPanGesture.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVPanGesture.m; sourceTree = ""; }; + 8410D9AE1A70A51C00B22E49 /* LVGesture.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVGesture.h; sourceTree = ""; }; + 8410D9AF1A70A51C00B22E49 /* LVGesture.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVGesture.m; sourceTree = ""; }; + 84185DBF1B451E28003E0ECE /* LVStruct.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVStruct.h; sourceTree = ""; }; + 84185DC01B451E28003E0ECE /* LVStruct.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVStruct.m; sourceTree = ""; }; + 8418E3A91A5E704100158125 /* LuaViewSDK-Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "LuaViewSDK-Prefix.pch"; sourceTree = ""; }; + 842142A21ACD3427001FD0ED /* LVDebugLua.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = LVDebugLua.m; path = lvdebug/LVDebugLua.m; sourceTree = ""; }; + 842142A51ACD3E2C001FD0ED /* debug.lua */ = {isa = PBXFileReference; lastKnownFileType = text; name = debug.lua; path = lvdebug/debug.lua; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.ruby; }; + 842532451ADCB7C0003C05BF /* LVAudioPlayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVAudioPlayer.h; sourceTree = ""; }; + 842532461ADCB7C0003C05BF /* LVAudioPlayer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVAudioPlayer.m; sourceTree = ""; }; + 8425324A1ADCBD3A003C05BF /* LVDownloader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVDownloader.h; sourceTree = ""; }; + 8425324B1ADCBD3A003C05BF /* LVDownloader.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVDownloader.m; sourceTree = ""; }; + 842D72671A6639A200936AD2 /* LVExGlobalFunc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVExGlobalFunc.h; sourceTree = ""; }; + 842D72681A6639A200936AD2 /* LVExGlobalFunc.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVExGlobalFunc.m; sourceTree = ""; }; + 842D726C1A6643DB00936AD2 /* LVAlert.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVAlert.h; sourceTree = ""; }; + 842D726D1A6643DB00936AD2 /* LVAlert.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVAlert.m; sourceTree = ""; }; + 84342D8C1AE0E02B00ECB4EF /* LVStyledString.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVStyledString.h; sourceTree = ""; }; + 84342D8D1AE0E02B00ECB4EF /* LVStyledString.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVStyledString.m; sourceTree = ""; }; + 843447481B61DDED0039B98A /* UIView+LuaView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+LuaView.h"; sourceTree = ""; }; + 843447491B61DDED0039B98A /* UIView+LuaView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+LuaView.m"; sourceTree = ""; }; + 8446F15B1BDF57F2007E4064 /* LVNinePatchImage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVNinePatchImage.h; sourceTree = ""; }; + 8446F15C1BDF57F2007E4064 /* LVNinePatchImage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVNinePatchImage.m; sourceTree = ""; }; + 8454D13F1A7F732500774565 /* LVHttp.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVHttp.h; sourceTree = ""; }; + 8454D1401A7F732500774565 /* LVHttp.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVHttp.m; sourceTree = ""; }; + 8454D1441A7FA7A400774565 /* LVHttpResponse.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVHttpResponse.h; sourceTree = ""; }; + 8454D1451A7FA7A400774565 /* LVHttpResponse.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVHttpResponse.m; sourceTree = ""; }; + 846481A61A64C61F00DE6204 /* LVAnimate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVAnimate.h; sourceTree = ""; }; + 846481A71A64C61F00DE6204 /* LVAnimate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVAnimate.m; sourceTree = ""; }; + 846481A81A64C61F00DE6204 /* LVBaseView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVBaseView.h; sourceTree = ""; }; + 846481A91A64C61F00DE6204 /* LVBaseView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVBaseView.m; sourceTree = ""; }; + 846481AA1A64C61F00DE6204 /* LVButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVButton.h; sourceTree = ""; }; + 846481AB1A64C61F00DE6204 /* LVButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVButton.m; sourceTree = ""; }; + 846481AC1A64C61F00DE6204 /* LVHeads.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVHeads.h; sourceTree = ""; }; + 846481AD1A64C61F00DE6204 /* LVHeads.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVHeads.m; sourceTree = ""; }; + 846481AE1A64C61F00DE6204 /* LVImage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVImage.h; sourceTree = ""; }; + 846481AF1A64C61F00DE6204 /* LVImage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVImage.m; sourceTree = ""; }; + 846481B01A64C61F00DE6204 /* LVLabel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVLabel.h; sourceTree = ""; }; + 846481B11A64C61F00DE6204 /* LVLabel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVLabel.m; sourceTree = ""; }; + 846481B21A64C61F00DE6204 /* LVPagerIndicator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVPagerIndicator.h; sourceTree = ""; }; + 846481B31A64C61F00DE6204 /* LVPagerIndicator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVPagerIndicator.m; sourceTree = ""; }; + 846481B41A64C61F00DE6204 /* LVScrollView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVScrollView.h; sourceTree = ""; }; + 846481B51A64C61F00DE6204 /* LVScrollView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVScrollView.m; sourceTree = ""; }; + 846481B61A64C61F00DE6204 /* LVTextField.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVTextField.h; sourceTree = ""; }; + 846481B71A64C61F00DE6204 /* LVTextField.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVTextField.m; sourceTree = ""; }; + 846481B81A64C61F00DE6204 /* LVTimer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVTimer.h; sourceTree = ""; }; + 846481B91A64C61F00DE6204 /* LVTimer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVTimer.m; sourceTree = ""; }; + 846481BA1A64C61F00DE6204 /* LVTransform3D.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVTransform3D.h; sourceTree = ""; }; + 846481BB1A64C61F00DE6204 /* LVTransform3D.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVTransform3D.m; sourceTree = ""; }; + 846481BC1A64C61F00DE6204 /* LVUtil.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVUtil.h; sourceTree = ""; }; + 846481BD1A64C61F00DE6204 /* LVUtil.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVUtil.m; sourceTree = ""; }; + 8468C96F1BDA177C002D4B1E /* LVToast.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVToast.h; sourceTree = ""; }; + 8468C9701BDA177C002D4B1E /* LVToast.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVToast.m; sourceTree = ""; }; + 846E87991A653DEC000D14DA /* LVDate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVDate.h; sourceTree = ""; }; + 846E879A1A653DEC000D14DA /* LVDate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVDate.m; sourceTree = ""; }; + 84765E2B1ADE37A7002506CB /* LVFile.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVFile.h; sourceTree = ""; }; + 84765E2C1ADE37A7002506CB /* LVFile.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVFile.m; sourceTree = ""; }; + 84799AF31BAFECA00070E214 /* LVPagerView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVPagerView.h; sourceTree = ""; }; + 84799AF41BAFECA00070E214 /* LVPagerView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVPagerView.m; sourceTree = ""; }; + 84799AF81BAFEFDA0070E214 /* LVPagerViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVPagerViewCell.h; sourceTree = ""; }; + 84799AF91BAFEFDA0070E214 /* LVPagerViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVPagerViewCell.m; sourceTree = ""; }; + 8481E0591BD7AC8000FDFEEA /* LVScrollViewDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVScrollViewDelegate.h; sourceTree = ""; }; + 8481E05A1BD7AC8000FDFEEA /* LVScrollViewDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVScrollViewDelegate.m; sourceTree = ""; }; + 8481E0631BD7B29100FDFEEA /* LVCollectionViewDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVCollectionViewDelegate.h; sourceTree = ""; }; + 8481E0641BD7B29100FDFEEA /* LVCollectionViewDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVCollectionViewDelegate.m; sourceTree = ""; }; + 848CA35D1B29669A00C70321 /* LVCollectionView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVCollectionView.h; sourceTree = ""; }; + 848CA35E1B29669A00C70321 /* LVCollectionView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVCollectionView.m; sourceTree = ""; }; + 848CA3621B29748800C70321 /* LVCollectionViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVCollectionViewCell.h; sourceTree = ""; }; + 848CA3631B29748800C70321 /* LVCollectionViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVCollectionViewCell.m; sourceTree = ""; }; + 849708351A67653A00E913F4 /* LVDB.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVDB.h; sourceTree = ""; }; + 849708361A67653A00E913F4 /* LVDB.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVDB.m; sourceTree = ""; }; + 8497083A1A6765B000E913F4 /* LVSystem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVSystem.h; sourceTree = ""; }; + 8497083B1A6765B000E913F4 /* LVSystem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVSystem.m; sourceTree = ""; }; + 84B1E37F1AEF24480054B9F1 /* LVRSA.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LVRSA.h; path = RSA/LVRSA.h; sourceTree = ""; }; + 84B1E3801AEF24480054B9F1 /* LVRSA.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = LVRSA.m; path = RSA/LVRSA.m; sourceTree = ""; }; + 84B58E381B65CC260048F33D /* LVLoadingIndicator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVLoadingIndicator.h; sourceTree = ""; }; + 84B58E391B65CC260048F33D /* LVLoadingIndicator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVLoadingIndicator.m; sourceTree = ""; }; + 84BC621E1BA95A3F0019B02E /* LVDebugConnection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LVDebugConnection.h; path = lvdebug/LVDebugConnection.h; sourceTree = ""; }; + 84BC621F1BA95A3F0019B02E /* LVDebugConnection.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = LVDebugConnection.m; path = lvdebug/LVDebugConnection.m; sourceTree = ""; }; + 84C1D7C41C16C3CD0058E974 /* LuaViewSDK.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework.static; includeInIndex = 0; path = LuaViewSDK.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 84C1D7CA1C16C3CD0058E974 /* LuaViewSDK-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "LuaViewSDK-Info.plist"; sourceTree = ""; }; + 84C1D7D01C16C3CD0058E974 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 84C1D8901C16CA540058E974 /* Dummy-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Dummy-Prefix.pch"; sourceTree = ""; }; + 84C1D8911C16CA540058E974 /* Dummy.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Dummy.h; sourceTree = ""; }; + 84C1D8921C16CA540058E974 /* Dummy.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = Dummy.m; sourceTree = ""; }; + 84C1D8981C16CB820058E974 /* libDummy.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libDummy.a; sourceTree = BUILT_PRODUCTS_DIR; }; + 84C3B7281A84622A00923404 /* LVData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVData.h; sourceTree = ""; }; + 84C3B7291A84622A00923404 /* LVData.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVData.m; sourceTree = ""; }; + 84CF56731AE9184000A49B36 /* LVNativeObjBox.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVNativeObjBox.h; sourceTree = ""; }; + 84CF56741AE9184000A49B36 /* LVNativeObjBox.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVNativeObjBox.m; sourceTree = ""; }; + 84CF56781AEA15A500A49B36 /* LVMethod.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVMethod.h; sourceTree = ""; }; + 84CF56791AEA15A500A49B36 /* LVMethod.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVMethod.m; sourceTree = ""; }; + 84D446F01AF75BD8000A3911 /* LVPkgManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LVPkgManager.h; path = PKG/LVPkgManager.h; sourceTree = ""; }; + 84D446F11AF75BD8000A3911 /* LVPkgManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = LVPkgManager.m; path = PKG/LVPkgManager.m; sourceTree = ""; }; + 84DCB2AF1B39349A00244C39 /* LVLuaObjBox.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVLuaObjBox.h; sourceTree = ""; }; + 84DCB2B01B39349A00244C39 /* LVLuaObjBox.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVLuaObjBox.m; sourceTree = ""; }; + 84DCF0391B44D91800AD723B /* LVTypeConvert.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVTypeConvert.h; sourceTree = ""; }; + 84DCF03A1B44D91800AD723B /* LVTypeConvert.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVTypeConvert.m; sourceTree = ""; }; + 84DD8F871B560933001C83E9 /* LVNavigation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVNavigation.h; sourceTree = ""; }; + 84DD8F881B560933001C83E9 /* LVNavigation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVNavigation.m; sourceTree = ""; }; + 84DDB85B1B43BAEB006ACE9A /* LVPointerValueBox.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVPointerValueBox.h; sourceTree = ""; }; + 84DDB85C1B43BAEB006ACE9A /* LVPointerValueBox.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVPointerValueBox.m; sourceTree = ""; }; + 84DF1DA41A6F5BC9009F970A /* LVTapGesture.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVTapGesture.h; sourceTree = ""; }; + 84DF1DA51A6F5BC9009F970A /* LVTapGesture.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVTapGesture.m; sourceTree = ""; }; + 84E446961AEE0655009C9A8A /* LVBlock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LVBlock.h; path = ../LVBlock.h; sourceTree = ""; }; + 84E446971AEE0655009C9A8A /* LVBlock.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = LVBlock.m; path = ../LVBlock.m; sourceTree = ""; }; + 84E85C181C33B84B007DE3DF /* LVBundle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LVBundle.h; path = ../LVBundle.h; sourceTree = ""; }; + 84E85C191C33B84B007DE3DF /* LVBundle.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = LVBundle.m; path = ../LVBundle.m; sourceTree = ""; }; + 84F4A01D1B4B9E600062A7B2 /* UIScrollView+LuaView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIScrollView+LuaView.h"; sourceTree = ""; }; + 84F4A01E1B4B9E600062A7B2 /* UIScrollView+LuaView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIScrollView+LuaView.m"; sourceTree = ""; }; + 911270981DFAC65F001F8047 /* LVEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVEvent.h; sourceTree = ""; }; + 911270991DFAC65F001F8047 /* LVEvent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVEvent.m; sourceTree = ""; }; + 914D5F391DD3275D00CEA3FF /* LVClassInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVClassInfo.h; sourceTree = ""; }; + 914D5F3A1DD3275D00CEA3FF /* LVClassInfo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVClassInfo.m; sourceTree = ""; }; + 91666CF41E6ECDE8005BC162 /* NSObject+LuaView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSObject+LuaView.h"; sourceTree = ""; }; + 91666CF51E6ECDE8005BC162 /* NSObject+LuaView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSObject+LuaView.m"; sourceTree = ""; }; + 91695AA11E11004B0088EFD6 /* UIScrollView+LVRefresh.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIScrollView+LVRefresh.h"; sourceTree = ""; }; + 91695AA21E11004B0088EFD6 /* UIScrollView+LVRefresh.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIScrollView+LVRefresh.m"; sourceTree = ""; }; + 91695AA31E11004B0088EFD6 /* LVRefreshConst.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVRefreshConst.h; sourceTree = ""; }; + 91695AA41E11004B0088EFD6 /* LVRefreshConst.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVRefreshConst.m; sourceTree = ""; }; + 91695AA51E11004B0088EFD6 /* LVRefreshComponent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVRefreshComponent.h; sourceTree = ""; }; + 91695AA61E11004B0088EFD6 /* LVRefreshComponent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVRefreshComponent.m; sourceTree = ""; }; + 91695AA71E11004B0088EFD6 /* LVRefreshHeader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVRefreshHeader.h; sourceTree = ""; }; + 91695AA81E11004B0088EFD6 /* LVRefreshHeader.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVRefreshHeader.m; sourceTree = ""; }; + 91695AB61E1222DD0088EFD6 /* LVEmptyRefreshCollectionView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVEmptyRefreshCollectionView.h; sourceTree = ""; }; + 91695AB71E1222DD0088EFD6 /* LVEmptyRefreshCollectionView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVEmptyRefreshCollectionView.m; sourceTree = ""; }; + 9171D4A21AADD0300040DAA3 /* LVLongPressGesture.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVLongPressGesture.h; sourceTree = ""; }; + 9171D4A31AADD0300040DAA3 /* LVLongPressGesture.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVLongPressGesture.m; sourceTree = ""; }; + 91882E891AAD45A400107DFC /* LVPinchGesture.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVPinchGesture.h; sourceTree = ""; }; + 91882E8A1AAD45A400107DFC /* LVPinchGesture.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVPinchGesture.m; sourceTree = ""; }; + 91882E8E1AAD934D00107DFC /* LVRotationGesture.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVRotationGesture.h; sourceTree = ""; }; + 91882E8F1AAD934D00107DFC /* LVRotationGesture.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVRotationGesture.m; sourceTree = ""; }; + 918B9F1B1AADA0AC00FC7283 /* LVSwipeGesture.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVSwipeGesture.h; sourceTree = ""; }; + 918B9F1C1AADA0AC00FC7283 /* LVSwipeGesture.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVSwipeGesture.m; sourceTree = ""; }; + 9190C0181EA868670051E919 /* LVBitmap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVBitmap.h; sourceTree = ""; }; + 9190C0191EA868670051E919 /* LVBitmap.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVBitmap.m; sourceTree = ""; }; + 91A8CFF71E1F649F006D1609 /* LVPkgInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LVPkgInfo.h; path = PKG/LVPkgInfo.h; sourceTree = ""; }; + 91A8CFF81E1F649F006D1609 /* LVPkgInfo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = LVPkgInfo.m; path = PKG/LVPkgInfo.m; sourceTree = ""; }; + 91ACCE751AC531160034D9B3 /* LVDebuger.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LVDebuger.h; path = lvdebug/LVDebuger.h; sourceTree = ""; }; + 91ACCE761AC531160034D9B3 /* LVDebuger.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = LVDebuger.m; path = lvdebug/LVDebuger.m; sourceTree = ""; }; + 91B1A4811E6E871E000F71B3 /* LuaViewCore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LuaViewCore.h; path = ../LuaViewCore.h; sourceTree = ""; }; + 91B1A4821E6E871E000F71B3 /* LuaViewCore.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = LuaViewCore.m; path = ../LuaViewCore.m; sourceTree = ""; }; + 91B1A4861E6E873F000F71B3 /* LuaView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LuaView.h; path = ../LuaView.h; sourceTree = ""; }; + 91B1A4871E6E873F000F71B3 /* LuaView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = LuaView.m; path = ../LuaView.m; sourceTree = ""; }; + 91C55C701DD07185000BCB0B /* LVFlowLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVFlowLayout.h; sourceTree = ""; }; + 91C55C711DD07185000BCB0B /* LVFlowLayout.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVFlowLayout.m; sourceTree = ""; }; + 91F678821DF520920042D6FC /* LVCustomView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVCustomView.h; sourceTree = ""; }; + 91F678831DF520920042D6FC /* LVCustomView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVCustomView.m; sourceTree = ""; }; + 91F678871DF561D40042D6FC /* LVCanvas.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVCanvas.h; sourceTree = ""; }; + 91F678881DF561D40042D6FC /* LVCanvas.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVCanvas.m; sourceTree = ""; }; + B5514152BD5F276559AFAC71 /* Pods-LuaViewLib.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-LuaViewLib.release.xcconfig"; path = "Pods/Target Support Files/Pods-LuaViewLib/Pods-LuaViewLib.release.xcconfig"; sourceTree = ""; }; + BE9CD4F61CACC02800D6AC94 /* JUFLXTargeNamespace.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JUFLXTargeNamespace.h; sourceTree = ""; }; + BE9CD4F71CACC02800D6AC94 /* JUFLXLayoutDefine.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JUFLXLayoutDefine.h; sourceTree = ""; }; + BEEB28C21CA90EC200EC2D86 /* JUFLXCSSParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JUFLXCSSParser.h; sourceTree = ""; }; + BEEB28C31CA90EC200EC2D86 /* JUFLXCSSParser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JUFLXCSSParser.m; sourceTree = ""; }; + BEEB28C41CA90EC200EC2D86 /* JUFLXLayoutKit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JUFLXLayoutKit.h; sourceTree = ""; }; + BEEB28C51CA90EC200EC2D86 /* JUFLXNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JUFLXNode.h; sourceTree = ""; }; + BEEB28C61CA90EC200EC2D86 /* JUFLXNode.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JUFLXNode.m; sourceTree = ""; }; + BEEB28C71CA90EC200EC2D86 /* Layout.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = Layout.c; sourceTree = ""; }; + BEEB28C81CA90EC200EC2D86 /* Layout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Layout.h; sourceTree = ""; }; + BEEB28CA1CA90EC200EC2D86 /* JUFLXLinearLayoutView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JUFLXLinearLayoutView.h; sourceTree = ""; }; + BEEB28CB1CA90EC200EC2D86 /* JUFLXLinearLayoutView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JUFLXLinearLayoutView.m; sourceTree = ""; }; + BEEB28CC1CA90EC200EC2D86 /* UIView+JUFLXNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+JUFLXNode.h"; sourceTree = ""; }; + BEEB28CD1CA90EC200EC2D86 /* UIView+JUFLXNode.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+JUFLXNode.m"; sourceTree = ""; }; + C69ACE7EAE9092DECFD123A6 /* Pods-LuaViewSDK.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-LuaViewSDK.debug.xcconfig"; path = "Pods/Target Support Files/Pods-LuaViewSDK/Pods-LuaViewSDK.debug.xcconfig"; sourceTree = ""; }; + C79D55641FDB95CB5F122A8A /* Pods-LuaViewLib.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-LuaViewLib.debug.xcconfig"; path = "Pods/Target Support Files/Pods-LuaViewLib/Pods-LuaViewLib.debug.xcconfig"; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 3CFF77A61C7473A800847C05 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 84C1D7BF1C16C3CD0058E974 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 84C1D8951C16CB820058E974 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 224569A11F0B6130000CDE49 /* camera */ = { + isa = PBXGroup; + children = ( + 224569A21F0B62DA000CDE49 /* LVCamera.h */, + 224569A31F0B62DA000CDE49 /* LVCamera.m */, + ); + name = camera; + sourceTree = ""; + }; + 8418E3411A5E67FC00158125 /* LuaViewSDK */ = { + isa = PBXGroup; + children = ( + 8418E3A61A5E704100158125 /* Classes */, + 8418E3AE1A5E704600158125 /* Supporting Files */, + ); + path = LuaViewSDK; + sourceTree = ""; + }; + 8418E3A61A5E704100158125 /* Classes */ = { + isa = PBXGroup; + children = ( + BEEB28C11CA90EC200EC2D86 /* layout */, + 84D446EF1AF75BB6000A3911 /* PKG */, + 84B1E37E1AEF24330054B9F1 /* RSA */, + 91ACCE741AC530CA0034D9B3 /* lvdebug */, + 846481A51A64C61F00DE6204 /* lvsdk */, + ); + path = Classes; + sourceTree = ""; + }; + 8418E3AE1A5E704600158125 /* Supporting Files */ = { + isa = PBXGroup; + children = ( + 8418E3A91A5E704100158125 /* LuaViewSDK-Prefix.pch */, + 84C1D7CA1C16C3CD0058E974 /* LuaViewSDK-Info.plist */, + 84C1D7D01C16C3CD0058E974 /* Info.plist */, + ); + name = "Supporting Files"; + sourceTree = ""; + }; + 8443179F1BC6191500968368 /* items */ = { + isa = PBXGroup; + children = ( + 846481AA1A64C61F00DE6204 /* LVButton.h */, + 846481AB1A64C61F00DE6204 /* LVButton.m */, + 846481AE1A64C61F00DE6204 /* LVImage.h */, + 846481AF1A64C61F00DE6204 /* LVImage.m */, + 9190C0181EA868670051E919 /* LVBitmap.h */, + 9190C0191EA868670051E919 /* LVBitmap.m */, + 8446F15B1BDF57F2007E4064 /* LVNinePatchImage.h */, + 8446F15C1BDF57F2007E4064 /* LVNinePatchImage.m */, + 846481B01A64C61F00DE6204 /* LVLabel.h */, + 846481B11A64C61F00DE6204 /* LVLabel.m */, + 846481B61A64C61F00DE6204 /* LVTextField.h */, + 846481B71A64C61F00DE6204 /* LVTextField.m */, + 84B58E381B65CC260048F33D /* LVLoadingIndicator.h */, + 84B58E391B65CC260048F33D /* LVLoadingIndicator.m */, + 846481B21A64C61F00DE6204 /* LVPagerIndicator.h */, + 846481B31A64C61F00DE6204 /* LVPagerIndicator.m */, + ); + name = items; + sourceTree = ""; + }; + 844317A01BC6194700968368 /* container */ = { + isa = PBXGroup; + children = ( + 91695AA01E11003E0088EFD6 /* refresh */, + 84799AF31BAFECA00070E214 /* LVPagerView.h */, + 84799AF41BAFECA00070E214 /* LVPagerView.m */, + 84799AF81BAFEFDA0070E214 /* LVPagerViewCell.h */, + 84799AF91BAFEFDA0070E214 /* LVPagerViewCell.m */, + 848CA35D1B29669A00C70321 /* LVCollectionView.h */, + 848CA35E1B29669A00C70321 /* LVCollectionView.m */, + 91695AB61E1222DD0088EFD6 /* LVEmptyRefreshCollectionView.h */, + 91695AB71E1222DD0088EFD6 /* LVEmptyRefreshCollectionView.m */, + 848CA3621B29748800C70321 /* LVCollectionViewCell.h */, + 848CA3631B29748800C70321 /* LVCollectionViewCell.m */, + 8481E0631BD7B29100FDFEEA /* LVCollectionViewDelegate.h */, + 8481E0641BD7B29100FDFEEA /* LVCollectionViewDelegate.m */, + 91C55C701DD07185000BCB0B /* LVFlowLayout.h */, + 91C55C711DD07185000BCB0B /* LVFlowLayout.m */, + 846481B41A64C61F00DE6204 /* LVScrollView.h */, + 846481B51A64C61F00DE6204 /* LVScrollView.m */, + 8481E0591BD7AC8000FDFEEA /* LVScrollViewDelegate.h */, + 8481E05A1BD7AC8000FDFEEA /* LVScrollViewDelegate.m */, + ); + name = container; + sourceTree = ""; + }; + 844317A11BC6198800968368 /* customView */ = { + isa = PBXGroup; + children = ( + 91F678821DF520920042D6FC /* LVCustomView.h */, + 91F678831DF520920042D6FC /* LVCustomView.m */, + 91F678871DF561D40042D6FC /* LVCanvas.h */, + 91F678881DF561D40042D6FC /* LVCanvas.m */, + 84056E701B5CA5990078F9D6 /* LVCustomPanel.h */, + 84056E711B5CA5990078F9D6 /* LVCustomPanel.m */, + ); + name = customView; + sourceTree = ""; + }; + 844317A31BC61C1F00968368 /* alert */ = { + isa = PBXGroup; + children = ( + 842D726C1A6643DB00936AD2 /* LVAlert.h */, + 842D726D1A6643DB00936AD2 /* LVAlert.m */, + 8468C96F1BDA177C002D4B1E /* LVToast.h */, + 8468C9701BDA177C002D4B1E /* LVToast.m */, + ); + name = alert; + sourceTree = ""; + }; + 844317A41BC61C3000968368 /* animate */ = { + isa = PBXGroup; + children = ( + 846481A61A64C61F00DE6204 /* LVAnimate.h */, + 846481A71A64C61F00DE6204 /* LVAnimate.m */, + 3C02D1D71C31106E00213386 /* LVAnimator.h */, + 3C02D1D81C31106E00213386 /* LVAnimator.m */, + ); + name = animate; + sourceTree = ""; + }; + 844317A51BC61CA000968368 /* navigation */ = { + isa = PBXGroup; + children = ( + 84DD8F871B560933001C83E9 /* LVNavigation.h */, + 84DD8F881B560933001C83E9 /* LVNavigation.m */, + ); + name = navigation; + sourceTree = ""; + }; + 844317A61BC61E3900968368 /* system */ = { + isa = PBXGroup; + children = ( + 842D72671A6639A200936AD2 /* LVExGlobalFunc.h */, + 842D72681A6639A200936AD2 /* LVExGlobalFunc.m */, + 8497083A1A6765B000E913F4 /* LVSystem.h */, + 8497083B1A6765B000E913F4 /* LVSystem.m */, + 840BCED81CB7602C00D816AD /* LVNetworkStatus.h */, + 840BCED91CB7602C00D816AD /* LVNetworkStatus.m */, + ); + name = system; + sourceTree = ""; + }; + 844317A71BC61E8000968368 /* base */ = { + isa = PBXGroup; + children = ( + 846481A81A64C61F00DE6204 /* LVBaseView.h */, + 846481A91A64C61F00DE6204 /* LVBaseView.m */, + 84F4A01D1B4B9E600062A7B2 /* UIScrollView+LuaView.h */, + 84F4A01E1B4B9E600062A7B2 /* UIScrollView+LuaView.m */, + 843447481B61DDED0039B98A /* UIView+LuaView.h */, + 843447491B61DDED0039B98A /* UIView+LuaView.m */, + 91666CF41E6ECDE8005BC162 /* NSObject+LuaView.h */, + 91666CF51E6ECDE8005BC162 /* NSObject+LuaView.m */, + ); + name = base; + sourceTree = ""; + }; + 846481A51A64C61F00DE6204 /* lvsdk */ = { + isa = PBXGroup; + children = ( + 91B1A4861E6E873F000F71B3 /* LuaView.h */, + 91B1A4811E6E871E000F71B3 /* LuaViewCore.h */, + 84E446961AEE0655009C9A8A /* LVBlock.h */, + 84E85C181C33B84B007DE3DF /* LVBundle.h */, + 846481AC1A64C61F00DE6204 /* LVHeads.h */, + 840AD5311A5EAB4A0075CB58 /* LView.h */, + 3C98A5381C7C0C100001508E /* LViewController.h */, + 91B1A4871E6E873F000F71B3 /* LuaView.m */, + 91B1A4821E6E871E000F71B3 /* LuaViewCore.m */, + 84E446971AEE0655009C9A8A /* LVBlock.m */, + 84E85C191C33B84B007DE3DF /* LVBundle.m */, + 846481AD1A64C61F00DE6204 /* LVHeads.m */, + 840AD5321A5EAB4A0075CB58 /* LView.m */, + 3C98A5391C7C0C100001508E /* LViewController.m */, + 84A52C001AE7990B00E464AC /* audio */, + 84A52C021AE7995D00E464AC /* basic */, + 224569A11F0B6130000CDE49 /* camera */, + 84A52BFF1AE798A100E464AC /* file */, + 84A52BFE1AE7988A00E464AC /* gesture */, + 844317A51BC61CA000968368 /* navigation */, + 84A52BFD1AE7986600E464AC /* net */, + 84CF566B1AE8EC0B00A49B36 /* objectbox */, + 844317A61BC61E3900968368 /* system */, + 84A52BFC1AE7985D00E464AC /* ui */, + 84A52C011AE7992600E464AC /* util */, + ); + path = lvsdk; + sourceTree = ""; + }; + 848B5C151A0A4CA000F59678 = { + isa = PBXGroup; + children = ( + 8418E3411A5E67FC00158125 /* LuaViewSDK */, + 848B5C1F1A0A4CA000F59678 /* Products */, + 84C1D88F1C16CA540058E974 /* Dummy */, + EA5CB9E14864FE837EDFDF23 /* Pods */, + C19F1AC2F989D051D5BD6B0C /* Frameworks */, + ); + sourceTree = ""; + }; + 848B5C1F1A0A4CA000F59678 /* Products */ = { + isa = PBXGroup; + children = ( + 84C1D7C41C16C3CD0058E974 /* LuaViewSDK.framework */, + 84C1D8981C16CB820058E974 /* libDummy.a */, + 3CFF77A91C7473A800847C05 /* libLuaViewLib.a */, + ); + name = Products; + sourceTree = ""; + }; + 84A52BFC1AE7985D00E464AC /* ui */ = { + isa = PBXGroup; + children = ( + 844317A71BC61E8000968368 /* base */, + 8443179F1BC6191500968368 /* items */, + 844317A01BC6194700968368 /* container */, + 844317A11BC6198800968368 /* customView */, + 844317A31BC61C1F00968368 /* alert */, + 844317A41BC61C3000968368 /* animate */, + ); + name = ui; + sourceTree = ""; + }; + 84A52BFD1AE7986600E464AC /* net */ = { + isa = PBXGroup; + children = ( + 8454D13F1A7F732500774565 /* LVHttp.h */, + 8454D1401A7F732500774565 /* LVHttp.m */, + 8454D1441A7FA7A400774565 /* LVHttpResponse.h */, + 8454D1451A7FA7A400774565 /* LVHttpResponse.m */, + ); + name = net; + sourceTree = ""; + }; + 84A52BFE1AE7988A00E464AC /* gesture */ = { + isa = PBXGroup; + children = ( + 8410D9AE1A70A51C00B22E49 /* LVGesture.h */, + 8410D9AF1A70A51C00B22E49 /* LVGesture.m */, + 911270981DFAC65F001F8047 /* LVEvent.h */, + 911270991DFAC65F001F8047 /* LVEvent.m */, + 9171D4A21AADD0300040DAA3 /* LVLongPressGesture.h */, + 9171D4A31AADD0300040DAA3 /* LVLongPressGesture.m */, + 8410D9A91A70A00400B22E49 /* LVPanGesture.h */, + 8410D9AA1A70A00400B22E49 /* LVPanGesture.m */, + 91882E891AAD45A400107DFC /* LVPinchGesture.h */, + 91882E8A1AAD45A400107DFC /* LVPinchGesture.m */, + 91882E8E1AAD934D00107DFC /* LVRotationGesture.h */, + 91882E8F1AAD934D00107DFC /* LVRotationGesture.m */, + 918B9F1B1AADA0AC00FC7283 /* LVSwipeGesture.h */, + 918B9F1C1AADA0AC00FC7283 /* LVSwipeGesture.m */, + 84DF1DA41A6F5BC9009F970A /* LVTapGesture.h */, + 84DF1DA51A6F5BC9009F970A /* LVTapGesture.m */, + ); + name = gesture; + sourceTree = ""; + }; + 84A52BFF1AE798A100E464AC /* file */ = { + isa = PBXGroup; + children = ( + 849708351A67653A00E913F4 /* LVDB.h */, + 849708361A67653A00E913F4 /* LVDB.m */, + 8425324A1ADCBD3A003C05BF /* LVDownloader.h */, + 8425324B1ADCBD3A003C05BF /* LVDownloader.m */, + 84765E2B1ADE37A7002506CB /* LVFile.h */, + 84765E2C1ADE37A7002506CB /* LVFile.m */, + ); + name = file; + sourceTree = ""; + }; + 84A52C001AE7990B00E464AC /* audio */ = { + isa = PBXGroup; + children = ( + 842532451ADCB7C0003C05BF /* LVAudioPlayer.h */, + 842532461ADCB7C0003C05BF /* LVAudioPlayer.m */, + ); + name = audio; + sourceTree = ""; + }; + 84A52C011AE7992600E464AC /* util */ = { + isa = PBXGroup; + children = ( + 846481BC1A64C61F00DE6204 /* LVUtil.h */, + 846481BD1A64C61F00DE6204 /* LVUtil.m */, + 84DCF0391B44D91800AD723B /* LVTypeConvert.h */, + 84DCF03A1B44D91800AD723B /* LVTypeConvert.m */, + ); + name = util; + sourceTree = ""; + }; + 84A52C021AE7995D00E464AC /* basic */ = { + isa = PBXGroup; + children = ( + 84342D8C1AE0E02B00ECB4EF /* LVStyledString.h */, + 84342D8D1AE0E02B00ECB4EF /* LVStyledString.m */, + 846481BA1A64C61F00DE6204 /* LVTransform3D.h */, + 846481BB1A64C61F00DE6204 /* LVTransform3D.m */, + 84C3B7281A84622A00923404 /* LVData.h */, + 84C3B7291A84622A00923404 /* LVData.m */, + 846E87991A653DEC000D14DA /* LVDate.h */, + 846E879A1A653DEC000D14DA /* LVDate.m */, + 846481B81A64C61F00DE6204 /* LVTimer.h */, + 846481B91A64C61F00DE6204 /* LVTimer.m */, + 84185DBF1B451E28003E0ECE /* LVStruct.h */, + 84185DC01B451E28003E0ECE /* LVStruct.m */, + ); + name = basic; + sourceTree = ""; + }; + 84B1E37E1AEF24330054B9F1 /* RSA */ = { + isa = PBXGroup; + children = ( + 84B1E37F1AEF24480054B9F1 /* LVRSA.h */, + 84B1E3801AEF24480054B9F1 /* LVRSA.m */, + ); + name = RSA; + sourceTree = ""; + }; + 84C1D88F1C16CA540058E974 /* Dummy */ = { + isa = PBXGroup; + children = ( + 84C1D8931C16CA660058E974 /* Support Files */, + 84C1D8911C16CA540058E974 /* Dummy.h */, + 84C1D8921C16CA540058E974 /* Dummy.m */, + ); + path = Dummy; + sourceTree = ""; + }; + 84C1D8931C16CA660058E974 /* Support Files */ = { + isa = PBXGroup; + children = ( + 84C1D8901C16CA540058E974 /* Dummy-Prefix.pch */, + ); + name = "Support Files"; + sourceTree = ""; + }; + 84CF566B1AE8EC0B00A49B36 /* objectbox */ = { + isa = PBXGroup; + children = ( + 84CF56781AEA15A500A49B36 /* LVMethod.h */, + 84CF56791AEA15A500A49B36 /* LVMethod.m */, + 914D5F391DD3275D00CEA3FF /* LVClassInfo.h */, + 914D5F3A1DD3275D00CEA3FF /* LVClassInfo.m */, + 84CF56731AE9184000A49B36 /* LVNativeObjBox.h */, + 84CF56741AE9184000A49B36 /* LVNativeObjBox.m */, + 84DCB2AF1B39349A00244C39 /* LVLuaObjBox.h */, + 84DCB2B01B39349A00244C39 /* LVLuaObjBox.m */, + 84DDB85B1B43BAEB006ACE9A /* LVPointerValueBox.h */, + 84DDB85C1B43BAEB006ACE9A /* LVPointerValueBox.m */, + ); + name = objectbox; + sourceTree = ""; + }; + 84D446EF1AF75BB6000A3911 /* PKG */ = { + isa = PBXGroup; + children = ( + 91A8CFF71E1F649F006D1609 /* LVPkgInfo.h */, + 91A8CFF81E1F649F006D1609 /* LVPkgInfo.m */, + 84D446F01AF75BD8000A3911 /* LVPkgManager.h */, + 84D446F11AF75BD8000A3911 /* LVPkgManager.m */, + 3CC1B5511C96B59D001DEEC0 /* LVZipArchive.h */, + 3CC1B5521C96B59D001DEEC0 /* LVZipArchive.m */, + ); + name = PKG; + sourceTree = ""; + }; + 91695AA01E11003E0088EFD6 /* refresh */ = { + isa = PBXGroup; + children = ( + 91695AA11E11004B0088EFD6 /* UIScrollView+LVRefresh.h */, + 91695AA21E11004B0088EFD6 /* UIScrollView+LVRefresh.m */, + 91695AA31E11004B0088EFD6 /* LVRefreshConst.h */, + 91695AA41E11004B0088EFD6 /* LVRefreshConst.m */, + 91695AA51E11004B0088EFD6 /* LVRefreshComponent.h */, + 91695AA61E11004B0088EFD6 /* LVRefreshComponent.m */, + 91695AA71E11004B0088EFD6 /* LVRefreshHeader.h */, + 91695AA81E11004B0088EFD6 /* LVRefreshHeader.m */, + ); + name = refresh; + sourceTree = ""; + }; + 91ACCE741AC530CA0034D9B3 /* lvdebug */ = { + isa = PBXGroup; + children = ( + 842142A51ACD3E2C001FD0ED /* debug.lua */, + 842142A21ACD3427001FD0ED /* LVDebugLua.m */, + 91ACCE751AC531160034D9B3 /* LVDebuger.h */, + 91ACCE761AC531160034D9B3 /* LVDebuger.m */, + 84BC621E1BA95A3F0019B02E /* LVDebugConnection.h */, + 84BC621F1BA95A3F0019B02E /* LVDebugConnection.m */, + ); + name = lvdebug; + sourceTree = ""; + }; + BEEB28C11CA90EC200EC2D86 /* layout */ = { + isa = PBXGroup; + children = ( + BE9CD4F61CACC02800D6AC94 /* JUFLXTargeNamespace.h */, + BE9CD4F71CACC02800D6AC94 /* JUFLXLayoutDefine.h */, + BEEB28C21CA90EC200EC2D86 /* JUFLXCSSParser.h */, + BEEB28C31CA90EC200EC2D86 /* JUFLXCSSParser.m */, + BEEB28C41CA90EC200EC2D86 /* JUFLXLayoutKit.h */, + BEEB28C51CA90EC200EC2D86 /* JUFLXNode.h */, + BEEB28C61CA90EC200EC2D86 /* JUFLXNode.m */, + BEEB28C71CA90EC200EC2D86 /* Layout.c */, + BEEB28C81CA90EC200EC2D86 /* Layout.h */, + BEEB28C91CA90EC200EC2D86 /* LayoutExtensions */, + BEEB28CC1CA90EC200EC2D86 /* UIView+JUFLXNode.h */, + BEEB28CD1CA90EC200EC2D86 /* UIView+JUFLXNode.m */, + ); + path = layout; + sourceTree = ""; + }; + BEEB28C91CA90EC200EC2D86 /* LayoutExtensions */ = { + isa = PBXGroup; + children = ( + BEEB28CA1CA90EC200EC2D86 /* JUFLXLinearLayoutView.h */, + BEEB28CB1CA90EC200EC2D86 /* JUFLXLinearLayoutView.m */, + ); + path = LayoutExtensions; + sourceTree = ""; + }; + C19F1AC2F989D051D5BD6B0C /* Frameworks */ = { + isa = PBXGroup; + children = ( + ); + name = Frameworks; + sourceTree = ""; + }; + EA5CB9E14864FE837EDFDF23 /* Pods */ = { + isa = PBXGroup; + children = ( + 151AA3B1FB2503E3C4CD0FC9 /* Pods-Dummy.debug.xcconfig */, + 158CD13BD2B405C24DFE7560 /* Pods-Dummy.release.xcconfig */, + C79D55641FDB95CB5F122A8A /* Pods-LuaViewLib.debug.xcconfig */, + B5514152BD5F276559AFAC71 /* Pods-LuaViewLib.release.xcconfig */, + C69ACE7EAE9092DECFD123A6 /* Pods-LuaViewSDK.debug.xcconfig */, + 3661550721FB71AF60C9B439 /* Pods-LuaViewSDK.release.xcconfig */, + ); + name = Pods; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXHeadersBuildPhase section */ + 84C1D7C01C16C3CD0058E974 /* Headers */ = { + isa = PBXHeadersBuildPhase; + buildActionMask = 2147483647; + files = ( + 84C1D8341C16C4490058E974 /* LVPkgManager.h in Headers */, + 84C1D8361C16C4490058E974 /* LVRSA.h in Headers */, + 84C1D8371C16C4490058E974 /* LVDebuger.h in Headers */, + 84C1D8381C16C4490058E974 /* LVDebugConnection.h in Headers */, + 84C1D8391C16C4490058E974 /* LVBaseView.h in Headers */, + 84C1D83A1C16C4490058E974 /* UIScrollView+LuaView.h in Headers */, + 91666CF61E6ECDE8005BC162 /* NSObject+LuaView.h in Headers */, + 91F678891DF561D40042D6FC /* LVCanvas.h in Headers */, + 84C1D83B1C16C44A0058E974 /* UIView+LuaView.h in Headers */, + 84C1D83C1C16C44A0058E974 /* LVButton.h in Headers */, + 84C1D83D1C16C44A0058E974 /* LVImage.h in Headers */, + 91695AAC1E11004B0088EFD6 /* LVRefreshConst.h in Headers */, + 84C1D83E1C16C44A0058E974 /* LVNinePatchImage.h in Headers */, + 84C1D83F1C16C44A0058E974 /* LVLabel.h in Headers */, + 84C1D8401C16C44A0058E974 /* LVTextField.h in Headers */, + BEEB28D01CA90EC200EC2D86 /* JUFLXLayoutKit.h in Headers */, + 84C1D8411C16C44A0058E974 /* LVLoadingIndicator.h in Headers */, + 84C1D8421C16C44A0058E974 /* LVPagerIndicator.h in Headers */, + 91B1A4831E6E871E000F71B3 /* LuaViewCore.h in Headers */, + 91C55C721DD07185000BCB0B /* LVFlowLayout.h in Headers */, + 84C1D8461C16C44A0058E974 /* LVPagerView.h in Headers */, + 84C1D8471C16C44A0058E974 /* LVPagerViewCell.h in Headers */, + 84C1D8481C16C44A0058E974 /* LVCollectionView.h in Headers */, + 84C1D8491C16C44A0058E974 /* LVCollectionViewCell.h in Headers */, + 84C1D84A1C16C44A0058E974 /* LVCollectionViewDelegate.h in Headers */, + 84C1D84B1C16C44A0058E974 /* LVScrollView.h in Headers */, + 84C1D84C1C16C44A0058E974 /* LVScrollViewDelegate.h in Headers */, + 84C1D84D1C16C44A0058E974 /* LVCustomPanel.h in Headers */, + 840BCEDA1CB7602C00D816AD /* LVNetworkStatus.h in Headers */, + BE9CD4F91CACC02800D6AC94 /* JUFLXLayoutDefine.h in Headers */, + 84C1D84E1C16C44A0058E974 /* LVAlert.h in Headers */, + 84C1D84F1C16C44A0058E974 /* LVToast.h in Headers */, + 84C1D8501C16C44A0058E974 /* LVAnimate.h in Headers */, + 84C1D8511C16C44B0058E974 /* LVStyledString.h in Headers */, + 91695AAF1E11004B0088EFD6 /* LVRefreshComponent.h in Headers */, + 84C1D8521C16C44B0058E974 /* LVTransform3D.h in Headers */, + BEEB28D51CA90EC200EC2D86 /* JUFLXLinearLayoutView.h in Headers */, + 91B1A4881E6E873F000F71B3 /* LuaView.h in Headers */, + 84C1D8531C16C44B0058E974 /* LVData.h in Headers */, + 84C1D8541C16C44B0058E974 /* LVDate.h in Headers */, + 84C1D8551C16C44B0058E974 /* LVTimer.h in Headers */, + 91A8CFF91E1F649F006D1609 /* LVPkgInfo.h in Headers */, + 9112709A1DFAC65F001F8047 /* LVEvent.h in Headers */, + 224569A41F0B62DA000CDE49 /* LVCamera.h in Headers */, + 3C98A53A1C7C0C100001508E /* LViewController.h in Headers */, + 84C1D8561C16C44B0058E974 /* LVStruct.h in Headers */, + 3CC1B5531C96B59D001DEEC0 /* LVZipArchive.h in Headers */, + 84C1D8571C16C44B0058E974 /* LVGesture.h in Headers */, + 84C1D8581C16C44B0058E974 /* LVLongPressGesture.h in Headers */, + 91695AA91E11004B0088EFD6 /* UIScrollView+LVRefresh.h in Headers */, + BEEB28D11CA90EC200EC2D86 /* JUFLXNode.h in Headers */, + 84C1D8591C16C44B0058E974 /* LVPanGesture.h in Headers */, + 84C1D85A1C16C44B0058E974 /* LVPinchGesture.h in Headers */, + 84C1D85B1C16C44B0058E974 /* LVRotationGesture.h in Headers */, + 84C1D85C1C16C44C0058E974 /* LVSwipeGesture.h in Headers */, + 84C1D85D1C16C44C0058E974 /* LVTapGesture.h in Headers */, + 84C1D85F1C16C44C0058E974 /* LVHttp.h in Headers */, + 84C1D8601C16C44C0058E974 /* LVHttpResponse.h in Headers */, + 84C1D8611C16C44C0058E974 /* LVAudioPlayer.h in Headers */, + 84C1D8621C16C44C0058E974 /* LVDB.h in Headers */, + 84C1D8631C16C44C0058E974 /* LVDownloader.h in Headers */, + 84C1D8641C16C44D0058E974 /* LVFile.h in Headers */, + 84C1D8651C16C44D0058E974 /* LVNavigation.h in Headers */, + 84C1D8661C16C44D0058E974 /* LVSystem.h in Headers */, + 84C1D8681C16C44D0058E974 /* LVMethod.h in Headers */, + BEEB28D71CA90EC200EC2D86 /* UIView+JUFLXNode.h in Headers */, + 84C1D8691C16C44D0058E974 /* LVNativeObjBox.h in Headers */, + 84C1D86A1C16C44E0058E974 /* LVLuaObjBox.h in Headers */, + 84C1D86B1C16C44E0058E974 /* LVPointerValueBox.h in Headers */, + 9190C01A1EA868670051E919 /* LVBitmap.h in Headers */, + 84C1D86C1C16C44E0058E974 /* LVUtil.h in Headers */, + 84C1D86D1C16C44E0058E974 /* LVTypeConvert.h in Headers */, + 84C1D86E1C16C44E0058E974 /* LVExGlobalFunc.h in Headers */, + 84C1D86F1C16C44E0058E974 /* LVHeads.h in Headers */, + 84C1D8891C16C4550058E974 /* LVBlock.h in Headers */, + 84C1D8871C16C4540058E974 /* LView.h in Headers */, + BE9CD4F81CACC02800D6AC94 /* JUFLXTargeNamespace.h in Headers */, + 91695AB21E11004B0088EFD6 /* LVRefreshHeader.h in Headers */, + 914D5F3B1DD3275D00CEA3FF /* LVClassInfo.h in Headers */, + 91695AB81E1222DD0088EFD6 /* LVEmptyRefreshCollectionView.h in Headers */, + 91F678841DF520920042D6FC /* LVCustomView.h in Headers */, + 3C02D1D91C31106E00213386 /* LVAnimator.h in Headers */, + BEEB28D41CA90EC200EC2D86 /* Layout.h in Headers */, + 84E85C1A1C33B84B007DE3DF /* LVBundle.h in Headers */, + BEEB28CE1CA90EC200EC2D86 /* JUFLXCSSParser.h in Headers */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXHeadersBuildPhase section */ + +/* Begin PBXNativeTarget section */ + 3CFF77A81C7473A800847C05 /* LuaViewLib */ = { + isa = PBXNativeTarget; + buildConfigurationList = 3CFF77B11C7473A800847C05 /* Build configuration list for PBXNativeTarget "LuaViewLib" */; + buildPhases = ( + 2ECF16A6A7C83B6C40DDB427 /* [CP] Check Pods Manifest.lock */, + 3CFF77A51C7473A800847C05 /* Sources */, + 3CFF77A61C7473A800847C05 /* Frameworks */, + 3CFF77A71C7473A800847C05 /* CopyFiles */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = LuaViewLib; + productName = LuaViewLib; + productReference = 3CFF77A91C7473A800847C05 /* libLuaViewLib.a */; + productType = "com.apple.product-type.library.static"; + }; + 84C1D7C31C16C3CD0058E974 /* LuaViewSDK */ = { + isa = PBXNativeTarget; + buildConfigurationList = 84C1D7D11C16C3CD0058E974 /* Build configuration list for PBXNativeTarget "LuaViewSDK" */; + buildPhases = ( + E9D678F4467BB7BE53C63EDF /* [CP] Check Pods Manifest.lock */, + 84C1D7BE1C16C3CD0058E974 /* Sources */, + 84C1D7BF1C16C3CD0058E974 /* Frameworks */, + 84C1D7C01C16C3CD0058E974 /* Headers */, + 84C1D7C11C16C3CD0058E974 /* Resources */, + 84C1D7C21C16C3CD0058E974 /* ShellScript */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = LuaViewSDK; + productName = LuaViewSDK; + productReference = 84C1D7C41C16C3CD0058E974 /* LuaViewSDK.framework */; + productType = "com.apple.product-type.framework.static"; + }; + 84C1D8971C16CB820058E974 /* Dummy */ = { + isa = PBXNativeTarget; + buildConfigurationList = 84C1D89E1C16CB820058E974 /* Build configuration list for PBXNativeTarget "Dummy" */; + buildPhases = ( + 81791EE4E62461FA6F2D0061 /* [CP] Check Pods Manifest.lock */, + 84C1D8941C16CB820058E974 /* Sources */, + 84C1D8951C16CB820058E974 /* Frameworks */, + 84C1D8961C16CB820058E974 /* CopyFiles */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = Dummy; + productName = Dummy; + productReference = 84C1D8981C16CB820058E974 /* libDummy.a */; + productType = "com.apple.product-type.library.static"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 848B5C161A0A4CA000F59678 /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 0700; + ORGANIZATIONNAME = dongxicheng; + TargetAttributes = { + 3CFF77A81C7473A800847C05 = { + CreatedOnToolsVersion = 7.2; + }; + 84C1D7C31C16C3CD0058E974 = { + CreatedOnToolsVersion = 7.1.1; + }; + 84C1D8971C16CB820058E974 = { + CreatedOnToolsVersion = 7.1.1; + }; + }; + }; + buildConfigurationList = 848B5C191A0A4CA000F59678 /* Build configuration list for PBXProject "LuaViewSDK" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 848B5C151A0A4CA000F59678; + productRefGroup = 848B5C1F1A0A4CA000F59678 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 84C1D7C31C16C3CD0058E974 /* LuaViewSDK */, + 84C1D8971C16CB820058E974 /* Dummy */, + 3CFF77A81C7473A800847C05 /* LuaViewLib */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 84C1D7C11C16C3CD0058E974 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 84C1D7CB1C16C3CD0058E974 /* LuaViewSDK-Info.plist in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXShellScriptBuildPhase section */ + 2ECF16A6A7C83B6C40DDB427 /* [CP] Check Pods Manifest.lock */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "[CP] Check Pods Manifest.lock"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n"; + showEnvVarsInLog = 0; + }; + 81791EE4E62461FA6F2D0061 /* [CP] Check Pods Manifest.lock */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "[CP] Check Pods Manifest.lock"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n"; + showEnvVarsInLog = 0; + }; + 84C1D7C21C16C3CD0058E974 /* ShellScript */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /usr/bin/python; + shellScript = "# TAG: BUILD SCRIPT (do not remove this comment)\n# Build script generated using https://github.com/kstenerud/iOS-Universal-Framework Mk 8 (beta 2012-06-16)\nimport logging\n\n\n##############################################################################\n#\n# Configuration\n#\n##############################################################################\n\n# Select which kind of framework to build.\n#\n# Note: Due to issues with Xcode's build process, if you select\n# 'embeddedframework', it will still show the regular framework\n# (as a symlink) along side of the embedded framework. Be sure to\n# instruct your users to copy/move the embedded framework in this case!\n#\n# If your framework contains resources such as images, nibs, momds, plists,\n# zipfiles and such, choose 'embeddedframework'.\n#\n# If your framework contains no resources, choose 'framework'.\n#\nconfig_framework_type = 'framework'\n#config_framework_type = 'embeddedframework'\n\n# Open the build directory in Finder when the universal framework is\n# successfully built.\n#\n# This value can be overridden by setting the UFW_OPEN_BUILD_DIR env variable\n# to True or False.\n#\n# Recommended setting: True\n#\nconfig_open_build_dir = False\n\n# If true, ensures that all public headers are stored in the framework under\n# the same directory hierarchy as they were in the source tree.\n#\n# Xcode by default places all headers at the same top level, but every other\n# build tool in the known universe preserves directory structure. For simple\n# libraries it doesn't really matter much, but for ports of existing software\n# packages or for bigger libraries, it makes sense to have more structure.\n#\n# The default is set to \"False\" since that's what most Xcode users are used to.\n#\n# Recommended setting: True for deep hierarchy projects, False otherwise.\n#\nconfig_deep_header_hierarchy = False\n\n# Specify where the top of the public header hierarchy is. This path is\n# relative to the project's dir (PROJECT_DIR). You can reference environment\n# variables using templating syntax (e.g. \"${TARGET_NAME}/Some/Subdir\")\n#\n# NOTE: Only used if config_deep_header_hierarchy is True.\n#\n# If this is set to None, the script will attempt to figure out for itself\n# where the top of the header hierarchy is by looking for common path prefixes\n# in the public header files. This process can fail if:\n# - You only have one public header file.\n# - Your source header files don't all have a common root.\n#\n# A common approach is to use \"${TARGET_NAME}\", working under the assumption\n# that all of your header files share the common root of a directory under\n# your project with the same name as your target (which is the Xcode default).\n#\n# Recommended setting: \"${TARGET_NAME}\"\n#\nconfig_deep_header_top = \"${TARGET_NAME}\"\n\n# Warn when \"DerivedData\" is detected in any of the header, library, or\n# framework search paths. In almost all cases, references to directories under\n# DerivedData are added as a result of an Xcode bug and must be manually\n# removed.\n#\n# Recommended setting: True\n#\nconfig_warn_derived_data = True\n\n# Warn if no headers were marked public in this framework.\n#\n# Recommended setting: True\n#\nconfig_warn_no_public_headers = False\n\n# Cause the build to fail if any warnings are issued.\n#\n# Recommended setting: True\n#\nconfig_fail_on_warnings = True\n\n# Minimum log level\n#\n# Recommended setting: logging.INFO\n#\nconfig_log_level = logging.INFO\n\n\n##############################################################################\n#\n# Don't touch anything below here unless you know what you're doing.\n#\n##############################################################################\n\nimport collections\nimport json\nimport os\nimport re\nimport shlex\nimport shutil\nimport string\nimport subprocess\nimport sys\nimport time\nimport traceback\n\n\n##############################################################################\n#\n# Globals\n#\n##############################################################################\n\nlog = logging.getLogger('UFW')\n\nissued_warnings = False\n\n\n##############################################################################\n#\n# Classes\n#\n##############################################################################\n\n# Allows the slave build to communicate with the master build.\n#\nclass BuildState:\n\n def __init__(self):\n self.reload()\n\n def reset(self):\n self.slave_platform = None\n self.slave_architectures = []\n self.slave_linked_archive_paths = []\n self.slave_built_fw_path = None\n self.slave_built_embedded_fw_path = None\n\n def set_slave_properties(self, architectures,\n linked_archive_paths,\n built_fw_path,\n built_embedded_fw_path):\n self.slave_platform = os.environ['PLATFORM_NAME']\n self.slave_architectures = architectures\n self.slave_linked_archive_paths = linked_archive_paths\n self.slave_built_fw_path = built_fw_path\n self.slave_built_embedded_fw_path = built_embedded_fw_path\n\n def get_save_path(self):\n return os.path.join(os.environ['PROJECT_TEMP_DIR'], \"ufw_build_state.json\")\n\n def persist(self):\n filename = self.get_save_path()\n parent = os.path.dirname(filename)\n if not os.path.isdir(parent):\n os.makedirs(parent)\n with open(filename, \"w\") as f:\n f.write(json.dumps(self.__dict__))\n\n def reload(self):\n self.reset()\n filename = self.get_save_path()\n if os.path.exists(filename):\n with open(filename, \"r\") as f:\n new_dict = json.loads(f.read())\n if new_dict is not None:\n self.__dict__ = dict(self.__dict__.items() + new_dict.items())\n\n\n# Holds information about the current project and build environment.\n#\nclass Project:\n\n def __init__(self, filename):\n sourcecode_types = ['sourcecode.c.c',\n 'sourcecode.c.objc',\n 'sourcecode.cpp.cpp',\n 'sourcecode.cpp.objcpp',\n 'sourcecode.asm.asm',\n 'sourcecode.asm.llvm',\n 'sourcecode.nasm']\n\n self.build_state = BuildState()\n self.project_data = self.load_from_file(filename)\n self.target = filter(lambda x: x['name'] == os.environ['TARGET_NAME'], self.project_data['targets'])[0]\n self.public_headers = self.get_build_phase_files('PBXHeadersBuildPhase', lambda x: x.get('settings', False) and x['settings'].get('ATTRIBUTES', False) and 'Public' in x['settings']['ATTRIBUTES'])\n self.static_libraries = self.get_build_phase_files('PBXFrameworksBuildPhase', lambda x: x['fileRef']['fileType'] == 'archive.ar' and x['fileRef']['sourceTree'] not in ['DEVELOPER_DIR', 'SDKROOT'])\n self.static_frameworks = self.get_build_phase_files('PBXFrameworksBuildPhase', lambda x: x['fileRef']['fileType'] == 'wrapper.framework' and x['fileRef']['sourceTree'] not in ['DEVELOPER_DIR', 'SDKROOT'])\n self.compilable_sources = self.get_build_phase_files('PBXSourcesBuildPhase', lambda x: x['fileRef']['fileType'] in sourcecode_types)\n self.header_paths = [os.path.join(*x['pathComponents']) for x in self.public_headers]\n\n self.headers_dir = os.path.join(os.environ['TARGET_BUILD_DIR'], os.environ['CONTENTS_FOLDER_PATH'], 'Headers')\n self.libtool_path = os.path.join(os.environ['DT_TOOLCHAIN_DIR'], 'usr', 'bin', 'libtool')\n self.project_filename = os.path.join(os.environ['PROJECT_FILE_PATH'], \"project.pbxproj\")\n self.local_exe_path = os.path.join(os.environ['TARGET_BUILD_DIR'], os.environ['EXECUTABLE_PATH'])\n self.local_architectures = os.environ['ARCHS'].split(' ')\n self.local_built_fw_path = os.path.join(os.environ['TARGET_BUILD_DIR'], os.environ['WRAPPER_NAME'])\n self.local_built_embedded_fw_path = os.path.splitext(self.local_built_fw_path)[0] + \".embeddedframework\"\n self.local_linked_archive_paths = [self.get_linked_ufw_archive_path(arch) for arch in self.local_architectures]\n self.local_platform = os.environ['PLATFORM_NAME']\n other_platforms = os.environ['SUPPORTED_PLATFORMS'].split(' ')\n other_platforms.remove(self.local_platform)\n self.other_platform = other_platforms[0]\n\n sdk_name = os.environ['SDK_NAME']\n if not sdk_name.startswith(self.local_platform):\n raise Exception(\"%s didn't start with %s\" % (sdk_name, self.local_platform))\n self.sdk_version = sdk_name[len(self.local_platform):]\n\n # Load an Xcode project file.\n #\n def load_from_file(self, filename):\n project_file = json.loads(subprocess.check_output([\"plutil\", \"-convert\", \"json\", \"-o\", \"-\", filename]))\n all_objects = project_file['objects']\n del project_file['objects']\n for obj in all_objects.values():\n self.fix_keys(obj)\n self.unpack_objects(self.build_dereference_list(all_objects, None, None, project_file))\n self.unpack_objects(self.build_dereference_list(all_objects, None, None, all_objects.values()))\n project_data = project_file['rootObject']\n self.build_full_paths(project_data, splitpath(os.environ['SOURCE_ROOT']))\n return project_data\n\n def is_key(self, obj): \n return isinstance(obj, basestring) and len(obj) == 24 and re.search('^[0-9a-fA-F]+$', obj) is not None\n \n def build_dereference_list(self, all_objects, parent, key, obj):\n deref_list = []\n if self.is_key(obj):\n dereferenced = all_objects.get(obj, obj)\n if dereferenced is not obj:\n deref_list.append((parent, key, obj, dereferenced))\n elif isinstance(obj, collections.Mapping):\n for k, v in obj.iteritems():\n deref_list += self.build_dereference_list(all_objects, obj, k, v)\n elif isinstance(obj, collections.Iterable) and not isinstance(obj, basestring):\n for item in obj:\n deref_list += self.build_dereference_list(all_objects, obj, None, item)\n return deref_list\n \n def unpack_objects(self, deref_list):\n for parent, key, orig, obj in deref_list:\n if key is None:\n parent.remove(orig)\n parent.append(obj)\n else:\n parent[key] = obj\n\n # Store the full path, separated into components, to a node inside the node\n # as \"pathComponents\". Also recurse into that node if it's a group.\n #\n def build_full_paths(self, node, base_path):\n # Some nodes are relative to a different source tree, specified as an\n # env variable.\n if node.get('sourceTree', '') != '':\n new_base_path = os.environ.get(node['sourceTree'], None)\n if new_base_path:\n base_path = splitpath(new_base_path)\n # Add the current node's path, if any.\n if node.get('path', False):\n base_path = base_path + splitpath(node['path'])\n node['pathComponents'] = base_path\n # Recurse if this is a group.\n if node['isa'] == 'PBXGroup':\n for child in node['children']:\n self.build_full_paths(child, base_path)\n elif node['isa'] == 'PBXProject':\n self.build_full_paths(node['mainGroup'], base_path)\n self.build_full_paths(node['productRefGroup'], base_path)\n for child in node['targets']:\n self.build_full_paths(child, base_path)\n projectRefs = node.get('projectReferences', None)\n if projectRefs is not None and len(projectRefs) > 0:\n for child in projectRefs[0].values():\n self.build_full_paths(child, base_path)\n\n # Fix up any inconvenient keys.\n #\n def fix_keys(self, obj):\n key_remappings = {'lastKnownFileType': 'fileType', 'explicitFileType': 'fileType'}\n for key in list(set(key_remappings.keys()) & set(obj.keys())):\n obj[key_remappings[key]] = obj[key]\n del obj[key]\n\n # Get the files from a build phase.\n #\n def get_build_phase_files(self, build_phase_name, filter_func):\n build_phase = filter(lambda x: x['isa'] == build_phase_name, self.target['buildPhases'])[0]\n build_files = filter(filter_func, build_phase['files'])\n return [x['fileRef'] for x in build_files]\n\n # Get the truncated paths of all headers that start with the specified\n # relative path. Paths are read and returned as fully separated lists.\n # e.g. ['Some', 'Path', 'To', 'A', 'Header'] with relative_path of\n # ['Some', 'Path'] gets truncated to ['To', 'A', 'Header']\n #\n def movable_headers_relative_to(self, relative_path):\n rel_path_length = len(relative_path)\n result = filter(lambda path: len(path) >= rel_path_length and\n path[:rel_path_length] == relative_path, self.header_paths)\n return [path[rel_path_length:] for path in result]\n\n # Get the full path to where a linkable archive (library or framework)\n # is supposed to be.\n #\n def get_linked_archive_path(self, architecture):\n return os.path.join(os.environ['OBJECT_FILE_DIR_%s' % os.environ['CURRENT_VARIANT']],\n architecture,\n os.environ['EXECUTABLE_NAME'])\n\n # Get the full path to our custom linked archive of the project.\n #\n def get_linked_ufw_archive_path(self, architecture):\n return self.get_linked_archive_path(architecture) + \".ufwbuild\"\n\n # Get the full path to the executable of an archive.\n #\n def get_exe_path(self, node):\n path = os.path.join(*node['pathComponents'])\n if node['fileType'] == 'wrapper.framework':\n # Frameworks are directories, so go one deeper\n path = os.path.join(path, os.path.splitext(node['pathComponents'][-1])[0])\n return path\n\n # Get the path to the directory containing the archive.\n #\n def get_containing_path(self, node):\n return os.path.join(*node['pathComponents'])\n \n def get_archive_search_paths(self):\n log.info(\"Search paths = %s\" % set([self.get_containing_path(fw) for fw in self.static_frameworks] + [self.get_containing_path(fw) for fw in self.static_libraries]))\n return set([self.get_containing_path(fw) for fw in self.static_frameworks] + [self.get_containing_path(fw) for fw in self.static_libraries])\n\n # Command to link all objects of a single architecture.\n #\n def get_single_arch_link_command(self, architecture):\n cmd = [self.libtool_path,\n \"-static\",\n \"-arch_only\", architecture,\n \"-syslibroot\", os.environ['SDKROOT'],\n \"-L%s\" % os.environ['TARGET_BUILD_DIR'],\n \"-filelist\", os.environ['LINK_FILE_LIST_%s_%s' % (os.environ['CURRENT_VARIANT'], architecture)]]\n if os.environ.get('OTHER_LDFLAGS', False):\n cmd += [os.environ['OTHER_LDFLAGS']]\n if os.environ.get('WARNING_LDFLAGS', False):\n cmd += [os.environ['WARNING_LDFLAGS']]\n# cmd += [\"-L%s\" % libpath for libpath in self.get_archive_search_paths()]\n cmd += [self.get_exe_path(fw) for fw in self.static_frameworks]\n cmd += [self.get_exe_path(lib) for lib in self.static_libraries]\n cmd += [\"-o\", self.get_linked_ufw_archive_path(architecture)]\n return cmd\n\n # Command to link all local architectures for the current configuration\n # into an archive. This reads all libraries + the UFW-built archives and\n # overwrites the final product.\n #\n def get_local_archs_link_command(self):\n cmd = [self.libtool_path,\n \"-static\"]\n cmd += self.local_linked_archive_paths\n cmd += [self.get_exe_path(fw) for fw in self.static_frameworks]\n cmd += [self.get_exe_path(lib) for lib in self.static_libraries]\n cmd += [\"-o\", os.path.join(os.environ['TARGET_BUILD_DIR'], os.environ['EXECUTABLE_PATH'])]\n return cmd\n\n # Command to link all architectures into a universal archive.\n # This reads all UFW-built archives and overwrites the final product.\n #\n def get_all_archs_link_command(self):\n cmd = [self.libtool_path,\n \"-static\"]\n cmd += self.local_linked_archive_paths + self.build_state.slave_linked_archive_paths\n cmd += [\"-o\", os.path.join(os.environ['TARGET_BUILD_DIR'], os.environ['EXECUTABLE_PATH'])]\n return cmd\n\n # Build up an environment for the slave process. This uses BUILD_ROOT\n # and TEMP_ROOT to convert all environment variables to values suitable\n # for the slave build environment so that xcodebuild doesn't try to build\n # in the project directory under \"build\".\n #\n def get_slave_environment(self):\n ignored = ['LD_MAP_FILE_PATH',\n 'HEADER_SEARCH_PATHS',\n 'LIBRARY_SEARCH_PATHS',\n 'FRAMEWORK_SEARCH_PATHS']\n build_root = os.environ['BUILD_ROOT']\n temp_root = os.environ['TEMP_ROOT']\n newenv = {}\n for key, value in os.environ.items():\n if key not in ignored and not key.startswith('LINK_FILE_LIST_') and not key.startswith('LD_DEPENDENCY_'):\n if build_root in value or temp_root in value:\n newenv[key] = value.replace(self.local_platform, self.other_platform)\n return newenv\n\n # Command to invoke xcodebuild on the slave platform.\n #\n def get_slave_project_build_command(self):\n cmd = [\"xcodebuild\",\n \"-project\",\n os.environ['PROJECT_FILE_PATH'],\n \"-target\",\n os.environ['TARGET_NAME'],\n \"-configuration\",\n os.environ['CONFIGURATION'],\n \"-sdk\",\n self.other_platform + self.sdk_version]\n cmd += [\"%s=%s\" % (key, value) for key, value in self.get_slave_environment().items()]\n cmd += [\"UFW_MASTER_PLATFORM=\" + os.environ['PLATFORM_NAME']]\n cmd += [os.environ['ACTION']]\n return cmd\n\n\n\n##############################################################################\n#\n# Utility Functions\n#\n##############################################################################\n\n# Split a path into a list of path components.\n#\ndef splitpath(path, maxdepth=20):\n (head, tail) = os.path.split(path)\n return splitpath(head, maxdepth - 1) + [tail] if maxdepth and head and head != path else [ head or tail ]\n\n# Remove all subdirectories under a path.\n#\ndef remove_subdirs(path, ignore_files):\n if os.path.exists(path):\n for filename in filter(lambda x: x not in ignore_files, os.listdir(path)):\n fullpath = os.path.join(path, filename)\n if os.path.isdir(fullpath):\n log.info(\"Remove %s\" % fullpath)\n shutil.rmtree(fullpath)\n\n# Make whatever parent paths are necessary for a path to exist.\n#\ndef ensure_path_exists(path):\n if not os.path.isdir(path):\n os.makedirs(path)\n\n# Make whatever parent paths are necessary for a path's parent to exist.\n#\ndef ensure_parent_exists(path):\n parent = os.path.dirname(path)\n if not os.path.isdir(parent):\n os.makedirs(parent)\n\n# Remove a file or dir if it exists.\n#\ndef remove_path(path):\n if os.path.exists(path):\n if os.path.isdir(path) and not os.path.islink(path):\n shutil.rmtree(path)\n else:\n os.remove(path)\n\n# Move a file or dir, replacing the destination if it exists.\n#\ndef move_file(src, dst):\n if src == dst:\n return\n log.info(\"Move %s to %s\" % (src, dst))\n ensure_parent_exists(dst)\n remove_path(dst)\n shutil.move(src, dst)\n\n# Copy a file or dir, replacing the destination if it exists already.\n#\ndef copy_overwrite(src, dst):\n if src != dst:\n remove_path(dst)\n ensure_parent_exists(dst)\n shutil.copytree(src, dst, symlinks=True)\n\n# Attempt to symlink link_path -> link_to.\n# link_to must be a path relative to link_path's parent and must exist.\n# If link_path already exists, do nothing.\n#\ndef attempt_symlink(link_path, link_to):\n # Only allow linking to an existing file\n os.stat(os.path.abspath(os.path.join(link_path, \"..\", link_to)))\n\n # Only make the link if it hasn't already been made\n if not os.path.exists(link_path):\n log.info(\"Symlink %s -> %s\" % (link_path, link_to))\n os.symlink(link_to, link_path)\n\n# Takes the last entry in an array-based path and returns a normal path\n# relative to base_path.\n#\ndef top_level_file_path(base_path, path_list):\n return os.path.join(base_path, os.path.split(path_list[-1])[-1])\n\n# Takes all entries in an array-based path and returns a normal path\n# relative to base_path.\n#\ndef full_file_path(base_path, path_list):\n return os.path.join(*([base_path] + path_list))\n\n# Print a command before executing it.\n# Also print out all output from the command to STDOUT.\n#\ndef print_and_call(cmd):\n log.info(\"Cmd \" + \" \".join(cmd))\n p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)\n result = p.communicate()[0]\n if len(result) > 0:\n log.info(result)\n if p.returncode != 0:\n raise subprocess.CalledProcessError(p.returncode, cmd)\n\n# Special print-and-call command for the slave build that strips out\n# xcodebuild's spammy list of environment variables.\n#\ndef print_and_call_slave_build(cmd, other_platform):\n separator = '=== BUILD NATIVE TARGET '\n p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)\n result = p.communicate()[0].split(separator)\n if len(result) == 1:\n result = result[0]\n else:\n result = separator + result[1]\n log.info(\"Cmd \" + \" \".join(cmd) + \"\\n\" + result)\n if p.returncode != 0:\n raise subprocess.CalledProcessError(p.returncode, cmd)\n\n# Issue a warning and record that a warning has been issued.\n#\ndef issue_warning(msg, *args, **kwargs):\n global issued_warnings\n issued_warnings = True\n log.warn(msg, *args, **kwargs)\n\n\n\n##############################################################################\n#\n# Main Application\n#\n##############################################################################\n\n# Check if we are running as master.\n#\ndef is_master():\n return os.environ.get('UFW_MASTER_PLATFORM', os.environ['PLATFORM_NAME']) == os.environ['PLATFORM_NAME']\n\n# DerivedData should almost never appear in any framework, library, or header\n# search paths. However, Xcode will sometimes add them in, so we check to make\n# sure.\n#\ndef check_for_derived_data_in_search_paths(project):\n search_path_keys = [\"FRAMEWORK_SEARCH_PATHS\", \"LIBRARY_SEARCH_PATHS\", \"HEADER_SEARCH_PATHS\"]\n build_configs = project.target['buildConfigurationList']['buildConfigurations']\n build_settings = filter(lambda x: x['name'] == os.environ['CONFIGURATION'], build_configs)[0]['buildSettings']\n \n found_something = False\n for path_key in filter(lambda x: x in build_settings, search_path_keys):\n path = build_settings[path_key]\n if \"DerivedData\" in path:\n found_something = True\n log.warn(\"Derived data in %s\" % path)\n issue_warning(\"'%s' contains reference to 'DerivedData'.\" % path_key)\n if found_something:\n log.warn(\"Check your build settings and remove any entries that contain paths inside the DerivedData folder.\")\n log.warn(\"Otherwise you can disable this warning by changing 'config_warn_derived_data' in this script.\")\n\n# Link local architectures into their respective archives.\n#\ndef link_local_archs(project):\n for arch in project.local_architectures:\n print_and_call(project.get_single_arch_link_command(arch))\n\n# Link only the local architectures into the final product, not the slave\n# architectures. For iphoneos, this will be armv6, armv7. For simulator, this\n# will be i386.\n#\ndef link_combine_local_archs(project):\n print_and_call(project.get_local_archs_link_command())\n\n# Link all architectures into the final product.\n#\ndef link_combine_all_archs(project):\n print_and_call(project.get_all_archs_link_command())\n\n# Check if we should open the build directory after a successful build.\n#\ndef should_open_build_dir():\n env_setting = os.environ.get('UFW_OPEN_BUILD_DIR', None)\n if env_setting is not None:\n return env_setting\n\n return config_open_build_dir\n\n# Open the build dir in Finder.\n#\ndef open_build_dir():\n print_and_call(['open', os.environ['TARGET_BUILD_DIR']])\n\n# Check if the build was started by selecting \"Archive\" under \"Product\" in\n# Xcode.\n#\ndef is_archive_build():\n # ACTION is always 'build', but perhaps Apple will fix this someday?\n archive_build = os.environ['ACTION'] == 'archive'\n\n if not archive_build:\n # This can be passed in as an env variable when building from command line.\n archive_build = os.environ.get('UFW_ACTION', None) == 'archive'\n\n build_dir = splitpath(os.environ['BUILD_DIR'])\n if not archive_build:\n # This partial path is used when you select \"archive\" from within Xcode.\n archive_build = 'ArchiveIntermediates' in build_dir\n\n # It only counts as a full archive build if this target is being built into\n # its own build dir (not being built as a dependency of another target)\n #if archive_build:\n #archive_build = os.environ['TARGET_NAME'] in build_dir\n \n return archive_build\n\n# Xcode by default throws all public headers into the top level directory.\n# This function moves them to their expected deep hierarchy.\n#\ndef build_deep_header_hierarchy(project):\n header_path_top = config_deep_header_top\n if not header_path_top:\n header_path_top = os.path.commonprefix(project.header_paths)\n else:\n header_path_top = splitpath(header_path_top)\n\n built_headers_path = os.path.join(os.environ['TARGET_BUILD_DIR'], os.environ['PUBLIC_HEADERS_FOLDER_PATH'])\n movable_headers = project.movable_headers_relative_to(header_path_top)\n\n # Remove subdirs if they only contain files that have been rebuilt\n ignore_headers = filter(lambda x: not os.path.isfile(top_level_file_path(built_headers_path, x)), movable_headers)\n remove_subdirs(built_headers_path, [file[0] for file in ignore_headers])\n\n # Move rebuilt headers into their proper subdirs\n for header in movable_headers:\n move_file(top_level_file_path(built_headers_path, header), full_file_path(built_headers_path, header))\n\ndef tb_get_file_name(path):\n f_list = os.listdir(path)\n log.debug(f_list)\n dest_list = []\n for key in f_list:\n if key == 'Headers' or key == 'Resources' or key == 'Versions' or key == os.environ['TARGET_NAME']:\n log.debug(\"do no thing\")\n else:\n dest_list.append(key)\n return dest_list\ndef tb_compare_version(version1, version2):\n int_ver1 = int(version1)\n int_ver2 = int(version2)\n if int_ver2 >= int_ver1:\n return True\n return False\n#Source directory and files is\n\n\n# MyFramework.framework\n# |--Headers\n# |--all resource files\n# |--MyFramework\n# So this is not standard file structure, this function do make files and directory to the standard files structure\n# Dest directory and files is\n# MyFramework.framework\n# |--Headers\n# |--all resource files\n# `--Versions\n# |--A\n# | |--MyFramework\n# | |--Headers\n# | `-- Resources\n# | |-- Info.plist\n# | |-- MyViewController.nib\n# | `-- en.lproj\n# | `-- InfoPlist.strings\ndef tb_format_file_and_directory(project):\n base_dir = project.local_built_fw_path\n log.debug(base_dir)\n\n resource_files = tb_get_file_name(base_dir)\n\n versions_path = os.path.join(base_dir, \"Versions\")\n log.debug(versions_path)\n ensure_path_exists(versions_path)\n\n framework_version_path = os.path.join(versions_path, os.environ['FRAMEWORK_VERSION'])\n ensure_path_exists(framework_version_path)\n\n dest_headers_path = os.path.join(framework_version_path, \"Headers\")\n ensure_path_exists(dest_headers_path)\n\n #Moves Headers to Versions/A/Headers\n src_headers_path = os.path.join(base_dir, \"Headers\")\n if os.path.isdir(src_headers_path):\n if not os.path.islink(src_headers_path):\n move_file(src_headers_path, dest_headers_path)\n\n#Moves Resource files to Versions/A/Resources\n des_res_path = os.path.join(framework_version_path, \"Resources\")\n ensure_path_exists(des_res_path)\n for i in resource_files :\n dest_res_file_path = os.path.join(des_res_path, i)\n src_res_file_path = os.path.join(base_dir, i)\n move_file(src_res_file_path, dest_res_file_path)\n\n #Moves MyFramework to Versions/A/MyFramework\n src_framework_path = os.path.join(base_dir, os.environ['TARGET_NAME'])\n dest_framework_path= os.path.join(framework_version_path, os.environ['TARGET_NAME'])\n move_file(src_framework_path, dest_framework_path)\n \n \n# Add all symlinks needed to make a full framework structure:\n#\n# MyFramework.framework\n# |-- MyFramework -> Versions/Current/MyFramework\n# |-- Headers -> Versions/Current/Headers\n# |-- Resources -> Versions/Current/Resources\n# `-- Versions\n# |-- A\n# | |-- MyFramework\n# | |-- Headers\n# | | `-- MyFramework.h\n# | `-- Resources\n# | |-- Info.plist\n# | |-- MyViewController.nib\n# | `-- en.lproj\n# | `-- InfoPlist.strings\n# `-- Current -> A\n#\ndef add_symlinks_to_framework(project):\n base_dir = project.local_built_fw_path\n attempt_symlink(os.path.join(base_dir, \"Versions\", \"Current\"), os.environ['FRAMEWORK_VERSION'])\n if os.path.isdir(os.path.join(base_dir, \"Versions\", \"Current\", \"Headers\")):\n attempt_symlink(os.path.join(base_dir, \"Headers\"), os.path.join(\"Versions\", \"Current\", \"Headers\"))\n if os.path.isdir(os.path.join(base_dir, \"Versions\", \"Current\", \"Resources\")):\n attempt_symlink(os.path.join(base_dir, \"Resources\"), os.path.join(\"Versions\", \"Current\", \"Resources\"))\n attempt_symlink(os.path.join(base_dir, os.environ['EXECUTABLE_NAME']), os.path.join(\"Versions\", \"Current\", os.environ['EXECUTABLE_NAME']))\n\n# Build an embedded framework structure.\n# An embedded framework contains the actual framework, plus a \"Resources\"\n# directory containing symlinks to all resources found in the actual framework,\n# with the exception of \"Info.plist\" and anything ending in \".lproj\":\n#\n# MyFramework.embeddedframework\n# |-- MyFramework.framework\n# | |-- MyFramework -> Versions/Current/MyFramework\n# | |-- Headers -> Versions/Current/Headers\n# | |-- Resources -> Versions/Current/Resources\n# | `-- Versions\n# | |-- A\n# | | |-- MyFramework\n# | | |-- Headers\n# | | | `-- MyFramework.h\n# | | `-- Resources\n# | | |-- Info.plist\n# | | |-- MyViewController.nib\n# | | `-- en.lproj\n# | | `-- InfoPlist.strings\n# | `-- Current -> A\n# `-- Resources\n# `-- MyViewController.nib -> ../MyFramework.framework/Resources/MyViewController.nib\n#\ndef build_embedded_framework(project):\n fw_path = project.local_built_fw_path\n embedded_path = project.local_built_embedded_fw_path\n fw_name = os.environ['WRAPPER_NAME']\n\n if (os.path.islink(fw_path)):\n # If the framework path is a link, the build result already in embeddedframework.\n # Just recreate embeddedframework's Resources\n remove_path(os.path.join(embedded_path, \"Resources\"))\n else:\n remove_path(embedded_path)\n ensure_path_exists(embedded_path)\n copy_overwrite(fw_path, os.path.join(embedded_path, fw_name))\n\n # Create embeddedframework's Resources \n ensure_path_exists(os.path.join(embedded_path, \"Resources\"))\n symlink_source = os.path.join(\"..\", fw_name, \"Resources\")\n symlink_path = os.path.join(embedded_path, \"Resources\")\n if os.path.isdir(os.path.join(fw_path, \"Resources\")):\n for file in filter(lambda x: x != \"Info.plist\" and not x.endswith(\".lproj\"), os.listdir(os.path.join(fw_path, \"Resources\"))):\n attempt_symlink(os.path.join(symlink_path, file), os.path.join(symlink_source, file))\n\n # Remove the normal framework and replace it with a symlink to the copy\n # in the embedded framework. This is needed because Xcode runs its strip\n # phase AFTER the script runs.\n embed_fw_wrapper = os.path.splitext(os.environ['WRAPPER_NAME'])[0] + \".embeddedframework\"\n remove_path(fw_path)\n attempt_symlink(fw_path, os.path.join(embed_fw_wrapper, os.environ['WRAPPER_NAME']))\n\n\n# Run the build process in slave mode to build the other configuration\n# (device/simulator).\n#\ndef run_slave_build(project):\n print_and_call_slave_build(project.get_slave_project_build_command(), project.other_platform)\n\n# Run the build process.\n#\ndef run_build():\n project = Project(os.path.join(os.environ['PROJECT_FILE_PATH'], \"project.pbxproj\"))\n\n # Issue warnings only if we're master.\n if is_master():\n if len(project.compilable_sources) == 0:\n raise Exception(\"No compilable sources found. Please add at least one source file to build target %s.\" % os.environ['TARGET_NAME'])\n\n if config_warn_derived_data:\n check_for_derived_data_in_search_paths(project)\n if config_warn_no_public_headers and len(project.public_headers) == 0:\n issue_warning('No headers in build target %s were marked public. Please move at least one header to \"Public\" in the \"Copy Headers\" build phase.' % os.environ['TARGET_NAME'])\n\n # Only build slave if this is an archive build.\n if is_archive_build():\n if is_master():\n log.debug(\"Building as MASTER\")\n # The slave-side linker tries to include this (nonexistent) path as\n # a library path.\n ensure_path_exists(project.get_slave_environment()['BUILT_PRODUCTS_DIR'])\n project.build_state.persist()\n run_slave_build(project)\n project.build_state.reload()\n else:\n log.debug(\"Building as SLAVE\")\n project.build_state.reload()\n project.build_state.set_slave_properties(project.local_architectures,\n project.local_linked_archive_paths,\n project.local_built_fw_path,\n project.local_built_embedded_fw_path)\n project.build_state.persist()\n\n link_local_archs(project)\n \n # Only do a universal binary when building an archive.\n if is_archive_build() and is_master():\n link_combine_all_archs(project)\n else:\n link_combine_local_archs(project)\n\n if config_deep_header_hierarchy:\n build_deep_header_hierarchy(project)\n\n xcode_version = os.environ['XCODE_VERSION_MAJOR']\n\n if tb_compare_version('0700', xcode_version):\n tb_format_file_and_directory(project)\n\n add_symlinks_to_framework(project)\n \n if is_master():\n if config_framework_type == 'embeddedframework':\n build_embedded_framework(project)\n elif config_framework_type != 'framework':\n raise Exception(\"%s: Unknown framework type for config_framework_type\" % config_framework_type)\n\n\nif __name__ == \"__main__\":\n log_handler = logging.StreamHandler()\n log_handler.setFormatter(logging.Formatter(\"%(name)s (\" + os.environ['PLATFORM_NAME'] + \"): %(levelname)s: %(message)s\"))\n log.addHandler(log_handler)\n log.setLevel(config_log_level)\n\n error_code = 0\n prefix = \"M\" if is_master() else \"S\"\n log_handler.setFormatter(logging.Formatter(\"%(name)s (\" + prefix + \" \" + os.environ['PLATFORM_NAME'] + \"): %(levelname)s: %(message)s\"))\n\n log.debug(\"Begin build process\")\n\n if config_deep_header_top:\n config_deep_header_top = string.Template(config_deep_header_top).substitute(os.environ)\n\n try:\n run_build()\n if issued_warnings:\n if config_fail_on_warnings:\n error_code = 1\n log.warn(\"Build completed with warnings\")\n else:\n log.info(\"Build completed\")\n if not is_archive_build():\n log.info(\"Note: This is *NOT* a universal framework build. To build as a universal framework, do an archive build.\")\n log.info(\"To do an archive build from command line, use \\\"xcodebuild -configuration Release UFW_ACTION=archive clean build\\\"\")\n except Exception:\n traceback.print_exc(file=sys.stdout)\n error_code = 1\n log.error(\"Build failed\")\n finally:\n if error_code == 0 and is_archive_build() and is_master():\n log.info(\"Built framework is in \" + os.environ['TARGET_BUILD_DIR'])\n if should_open_build_dir():\n open_build_dir()\n sys.exit(error_code)\n"; + showEnvVarsInLog = 0; + }; + E9D678F4467BB7BE53C63EDF /* [CP] Check Pods Manifest.lock */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "[CP] Check Pods Manifest.lock"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n"; + showEnvVarsInLog = 0; + }; +/* End PBXShellScriptBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 3CFF77A51C7473A800847C05 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 91695ABA1E1222DD0088EFD6 /* LVEmptyRefreshCollectionView.m in Sources */, + 3CC1B5551C96B5BC001DEEC0 /* LVZipArchive.m in Sources */, + 91695AB11E11004B0088EFD6 /* LVRefreshComponent.m in Sources */, + BEEB28E11CA91B9000EC2D86 /* Layout.c in Sources */, + 3C98A5421C7C56270001508E /* LViewController.m in Sources */, + BEEB28E31CA91B9900EC2D86 /* UIView+JUFLXNode.m in Sources */, + 9112709C1DFAC65F001F8047 /* LVEvent.m in Sources */, + 91695AB41E11004B0088EFD6 /* LVRefreshHeader.m in Sources */, + 3CFF77B21C74740800847C05 /* LVPkgManager.m in Sources */, + 3CFF77B41C74740800847C05 /* LVRSA.m in Sources */, + 91695AAE1E11004B0088EFD6 /* LVRefreshConst.m in Sources */, + 3CFF77B51C74740800847C05 /* LVDebugLua.m in Sources */, + BEEB28E01CA91B8900EC2D86 /* JUFLXNode.m in Sources */, + 3CFF77B61C74740800847C05 /* LVDebuger.m in Sources */, + 3CFF77B71C74740800847C05 /* LVDebugConnection.m in Sources */, + 3CFF77B81C74740800847C05 /* LVBaseView.m in Sources */, + 3CFF77B91C74740800847C05 /* UIScrollView+LuaView.m in Sources */, + 91A8CFFB1E1F649F006D1609 /* LVPkgInfo.m in Sources */, + 3CFF77BA1C74740800847C05 /* UIView+LuaView.m in Sources */, + 3CFF77BB1C74740800847C05 /* LVButton.m in Sources */, + 3CFF77BC1C74740800847C05 /* LVImage.m in Sources */, + 3CFF77BD1C74740800847C05 /* LVNinePatchImage.m in Sources */, + 3CFF77BE1C74740800847C05 /* LVLabel.m in Sources */, + 3CFF77BF1C74740800847C05 /* LVTextField.m in Sources */, + 91666CF81E6ECDE8005BC162 /* NSObject+LuaView.m in Sources */, + 3CFF77C01C74740800847C05 /* LVLoadingIndicator.m in Sources */, + 3CFF77C11C74740800847C05 /* LVPagerIndicator.m in Sources */, + 914D5F3D1DD3276400CEA3FF /* LVClassInfo.m in Sources */, + 3CFF77C51C74740800847C05 /* LVPagerView.m in Sources */, + 3CFF77C61C74740800847C05 /* LVPagerViewCell.m in Sources */, + 3CFF77C71C74740800847C05 /* LVCollectionView.m in Sources */, + 91F678861DF5209B0042D6FC /* LVCustomView.m in Sources */, + 91695AAB1E11004B0088EFD6 /* UIScrollView+LVRefresh.m in Sources */, + 3CFF77C81C74740800847C05 /* LVCollectionViewCell.m in Sources */, + 3CFF77C91C74740800847C05 /* LVCollectionViewDelegate.m in Sources */, + 3CFF77CA1C74740800847C05 /* LVScrollView.m in Sources */, + 3CFF77CB1C74740800847C05 /* LVScrollViewDelegate.m in Sources */, + 3CFF77CC1C74740800847C05 /* LVCustomPanel.m in Sources */, + 3CFF77CD1C74740800847C05 /* LVAlert.m in Sources */, + 3CFF77CE1C74740800847C05 /* LVToast.m in Sources */, + 3CFF77CF1C74740800847C05 /* LVAnimate.m in Sources */, + 3CFF77D01C74740800847C05 /* LVAnimator.m in Sources */, + 3CFF77D11C74740800847C05 /* LVStyledString.m in Sources */, + 3CFF77D21C74740800847C05 /* LVTransform3D.m in Sources */, + 3CFF77D31C74740800847C05 /* LVData.m in Sources */, + 3CFF77D41C74740800847C05 /* LVDate.m in Sources */, + 3CFF77D51C74740800847C05 /* LVTimer.m in Sources */, + 3CFF77D61C74740800847C05 /* LVStruct.m in Sources */, + 3CFF77D71C74740900847C05 /* LVGesture.m in Sources */, + 3CFF77D81C74740900847C05 /* LVLongPressGesture.m in Sources */, + 3CFF77D91C74740900847C05 /* LVPanGesture.m in Sources */, + 840BCEE41CB78E8300D816AD /* LVNetworkStatus.m in Sources */, + 91F6788B1DF561D40042D6FC /* LVCanvas.m in Sources */, + 3CFF77DA1C74740900847C05 /* LVPinchGesture.m in Sources */, + 3CFF77DB1C74740900847C05 /* LVRotationGesture.m in Sources */, + 91B1A48A1E6E873F000F71B3 /* LuaView.m in Sources */, + 3CFF77DC1C74740900847C05 /* LVSwipeGesture.m in Sources */, + 3CFF77DD1C74740900847C05 /* LVTapGesture.m in Sources */, + 3CFF77DF1C74740900847C05 /* LVHttp.m in Sources */, + 3CFF77E01C74740900847C05 /* LVHttpResponse.m in Sources */, + 3CFF77E11C74740900847C05 /* LVAudioPlayer.m in Sources */, + 91B1A4851E6E871E000F71B3 /* LuaViewCore.m in Sources */, + 3CFF77E21C74740900847C05 /* LVDB.m in Sources */, + 3CFF77E31C74740900847C05 /* LVDownloader.m in Sources */, + 3CFF77E41C74740900847C05 /* LVFile.m in Sources */, + 3CFF77E51C74740900847C05 /* LVNavigation.m in Sources */, + 3CFF77E61C74740900847C05 /* LVSystem.m in Sources */, + 3CFF77E81C74740900847C05 /* LVMethod.m in Sources */, + 3CFF77E91C74740900847C05 /* LVNativeObjBox.m in Sources */, + 3CFF77EA1C74740900847C05 /* LVLuaObjBox.m in Sources */, + 3CFF77EB1C74740900847C05 /* LVPointerValueBox.m in Sources */, + 3CFF77EC1C74740900847C05 /* LVUtil.m in Sources */, + 3CFF77ED1C74740900847C05 /* LVTypeConvert.m in Sources */, + BEEB28E21CA91B9500EC2D86 /* JUFLXLinearLayoutView.m in Sources */, + 3CFF77EE1C74740900847C05 /* LVExGlobalFunc.m in Sources */, + 3CFF77EF1C74740900847C05 /* LVHeads.m in Sources */, + 91C55C741DD07DAF000BCB0B /* LVFlowLayout.m in Sources */, + 3CFF77F01C74740900847C05 /* LView.m in Sources */, + 3CFF77F11C74740900847C05 /* LVBundle.m in Sources */, + 3CFF77F21C74740900847C05 /* LVBlock.m in Sources */, + BEEB28DF1CA91B8600EC2D86 /* JUFLXCSSParser.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 84C1D7BE1C16C3CD0058E974 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 91695AB91E1222DD0088EFD6 /* LVEmptyRefreshCollectionView.m in Sources */, + 3CC1B5541C96B59D001DEEC0 /* LVZipArchive.m in Sources */, + 91695AB01E11004B0088EFD6 /* LVRefreshComponent.m in Sources */, + BEEB28D31CA90EC200EC2D86 /* Layout.c in Sources */, + 3C98A53B1C7C0C100001508E /* LViewController.m in Sources */, + BEEB28D81CA90EC200EC2D86 /* UIView+JUFLXNode.m in Sources */, + 9112709B1DFAC65F001F8047 /* LVEvent.m in Sources */, + 84E85C1C1C33B84B007DE3DF /* LVBundle.m in Sources */, + 91695AB31E11004B0088EFD6 /* LVRefreshHeader.m in Sources */, + 84C1D7D41C16C3F90058E974 /* LVPkgManager.m in Sources */, + 91695AAD1E11004B0088EFD6 /* LVRefreshConst.m in Sources */, + 84C1D7D61C16C3FA0058E974 /* LVRSA.m in Sources */, + BEEB28D21CA90EC200EC2D86 /* JUFLXNode.m in Sources */, + 91A8CFFA1E1F649F006D1609 /* LVPkgInfo.m in Sources */, + 84C1D7D71C16C3FA0058E974 /* LVDebugLua.m in Sources */, + 84C1D7D81C16C3FA0058E974 /* LVDebuger.m in Sources */, + 84C1D7D91C16C3FA0058E974 /* LVDebugConnection.m in Sources */, + 84C1D7DA1C16C3FA0058E974 /* LVBaseView.m in Sources */, + 84C1D7DB1C16C3FA0058E974 /* UIScrollView+LuaView.m in Sources */, + 84C1D7DC1C16C3FA0058E974 /* UIView+LuaView.m in Sources */, + 84C1D7DD1C16C3FA0058E974 /* LVButton.m in Sources */, + 84C1D7DE1C16C3FA0058E974 /* LVImage.m in Sources */, + 84C1D7DF1C16C3FA0058E974 /* LVNinePatchImage.m in Sources */, + 84C1D7E01C16C3FA0058E974 /* LVLabel.m in Sources */, + 91666CF71E6ECDE8005BC162 /* NSObject+LuaView.m in Sources */, + 84C1D7E11C16C3FA0058E974 /* LVTextField.m in Sources */, + 84C1D7E21C16C3FA0058E974 /* LVLoadingIndicator.m in Sources */, + 84C1D7E31C16C3FA0058E974 /* LVPagerIndicator.m in Sources */, + 914D5F3C1DD3275D00CEA3FF /* LVClassInfo.m in Sources */, + 3C02D1DA1C31106E00213386 /* LVAnimator.m in Sources */, + 84C1D7E71C16C3FA0058E974 /* LVPagerView.m in Sources */, + 9190C01B1EA868670051E919 /* LVBitmap.m in Sources */, + 91F678851DF520920042D6FC /* LVCustomView.m in Sources */, + 91695AAA1E11004B0088EFD6 /* UIScrollView+LVRefresh.m in Sources */, + 84C1D7E81C16C3FA0058E974 /* LVPagerViewCell.m in Sources */, + 84C1D7E91C16C3FA0058E974 /* LVCollectionView.m in Sources */, + 84C1D7EA1C16C3FA0058E974 /* LVCollectionViewCell.m in Sources */, + 84C1D7EB1C16C3FA0058E974 /* LVCollectionViewDelegate.m in Sources */, + 84C1D7EC1C16C3FA0058E974 /* LVScrollView.m in Sources */, + 84C1D7ED1C16C3FA0058E974 /* LVScrollViewDelegate.m in Sources */, + 84C1D7EE1C16C3FA0058E974 /* LVCustomPanel.m in Sources */, + 84C1D7EF1C16C3FA0058E974 /* LVAlert.m in Sources */, + 84C1D7F01C16C3FA0058E974 /* LVToast.m in Sources */, + 84C1D7F11C16C3FA0058E974 /* LVAnimate.m in Sources */, + 84C1D7F21C16C3FA0058E974 /* LVStyledString.m in Sources */, + 84C1D7F31C16C3FA0058E974 /* LVTransform3D.m in Sources */, + 84C1D7F41C16C3FA0058E974 /* LVData.m in Sources */, + 84C1D7F51C16C3FA0058E974 /* LVDate.m in Sources */, + 84C1D7F61C16C3FA0058E974 /* LVTimer.m in Sources */, + 84C1D7F71C16C3FA0058E974 /* LVStruct.m in Sources */, + 84C1D7F81C16C3FA0058E974 /* LVGesture.m in Sources */, + 84C1D7F91C16C3FA0058E974 /* LVLongPressGesture.m in Sources */, + 84C1D7FA1C16C3FA0058E974 /* LVPanGesture.m in Sources */, + 91F6788A1DF561D40042D6FC /* LVCanvas.m in Sources */, + 84C1D7FB1C16C3FA0058E974 /* LVPinchGesture.m in Sources */, + 224569A51F0B62DA000CDE49 /* LVCamera.m in Sources */, + 84C1D7FC1C16C3FA0058E974 /* LVRotationGesture.m in Sources */, + 91B1A4891E6E873F000F71B3 /* LuaView.m in Sources */, + 84C1D7FD1C16C3FA0058E974 /* LVSwipeGesture.m in Sources */, + 84C1D7FE1C16C3FA0058E974 /* LVTapGesture.m in Sources */, + 84C1D8001C16C3FA0058E974 /* LVHttp.m in Sources */, + 840BCEDB1CB7602C00D816AD /* LVNetworkStatus.m in Sources */, + 84C1D8011C16C3FA0058E974 /* LVHttpResponse.m in Sources */, + 91B1A4841E6E871E000F71B3 /* LuaViewCore.m in Sources */, + 84C1D8021C16C3FA0058E974 /* LVAudioPlayer.m in Sources */, + 84C1D8031C16C3FA0058E974 /* LVDB.m in Sources */, + 84C1D8041C16C3FA0058E974 /* LVDownloader.m in Sources */, + 84C1D8051C16C3FA0058E974 /* LVFile.m in Sources */, + 84C1D8061C16C3FA0058E974 /* LVNavigation.m in Sources */, + 84C1D8071C16C3FA0058E974 /* LVSystem.m in Sources */, + 84C1D8091C16C3FA0058E974 /* LVMethod.m in Sources */, + 84C1D80A1C16C3FA0058E974 /* LVNativeObjBox.m in Sources */, + 84C1D80B1C16C3FA0058E974 /* LVLuaObjBox.m in Sources */, + 84C1D80C1C16C3FA0058E974 /* LVPointerValueBox.m in Sources */, + 84C1D80D1C16C3FA0058E974 /* LVUtil.m in Sources */, + BEEB28D61CA90EC200EC2D86 /* JUFLXLinearLayoutView.m in Sources */, + 84C1D80E1C16C3FA0058E974 /* LVTypeConvert.m in Sources */, + 84C1D80F1C16C3FA0058E974 /* LVExGlobalFunc.m in Sources */, + 91C55C731DD07185000BCB0B /* LVFlowLayout.m in Sources */, + 84C1D8101C16C3FA0058E974 /* LVHeads.m in Sources */, + 84C1D8111C16C3FA0058E974 /* LView.m in Sources */, + 84C1D8131C16C3FA0058E974 /* LVBlock.m in Sources */, + BEEB28CF1CA90EC200EC2D86 /* JUFLXCSSParser.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 84C1D8941C16CB820058E974 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 84C1D8A21C16CC930058E974 /* Dummy.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + 3CFF77AF1C7473A800847C05 /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = C79D55641FDB95CB5F122A8A /* Pods-LuaViewLib.debug.xcconfig */; + buildSettings = { + CODE_SIGN_IDENTITY = "iPhone Developer"; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + DEBUG_INFORMATION_FORMAT = dwarf; + GCC_NO_COMMON_BLOCKS = YES; + IPHONEOS_DEPLOYMENT_TARGET = 9.2; + ONLY_ACTIVE_ARCH = YES; + OTHER_LDFLAGS = "-ObjC"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SKIP_INSTALL = YES; + }; + name = Debug; + }; + 3CFF77B01C7473A800847C05 /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = B5514152BD5F276559AFAC71 /* Pods-LuaViewLib.release.xcconfig */; + buildSettings = { + CODE_SIGN_IDENTITY = "iPhone Distribution"; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + GCC_NO_COMMON_BLOCKS = YES; + IPHONEOS_DEPLOYMENT_TARGET = 9.2; + OTHER_LDFLAGS = "-ObjC"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SKIP_INSTALL = YES; + }; + name = Release; + }; + 848B5C3F1A0A4CA000F59678 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CODE_SIGN_IDENTITY = "iPhone Developer: Shi Jie Qin (FSAP8479L6)"; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer: Shi Jie Qin (FSAP8479L6)"; + COPY_PHASE_STRIP = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_SYMBOLS_PRIVATE_EXTERN = NO; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 7.0; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = NO; + SDKROOT = iphoneos; + VALID_ARCHS = "arm64 armv7s armv7"; + }; + name = Debug; + }; + 848B5C401A0A4CA000F59678 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CODE_SIGN_IDENTITY = "iPhone Developer: Shi Jie Qin (FSAP8479L6)"; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer: Shi Jie Qin (FSAP8479L6)"; + COPY_PHASE_STRIP = YES; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 7.0; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = iphoneos; + VALIDATE_PRODUCT = YES; + VALID_ARCHS = "arm64 armv7s armv7"; + }; + name = Release; + }; + 84C1D7D21C16C3CD0058E974 /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = C69ACE7EAE9092DECFD123A6 /* Pods-LuaViewSDK.debug.xcconfig */; + buildSettings = { + ARCHS = "$(ARCHS_STANDARD)"; + CLANG_ENABLE_MODULES = NO; + CLANG_ENABLE_MODULE_DEBUGGING = YES; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + DEFINES_MODULE = YES; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + FRAMEWORK_VERSION = A; + GCC_NO_COMMON_BLOCKS = YES; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + LV_USE_APICHECK, + "lv_assert=assert", + ); + GCC_TREAT_WARNINGS_AS_ERRORS = YES; + INFOPLIST_FILE = LuaViewSDK/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + ONLY_ACTIVE_ARCH = NO; + OTHER_CFLAGS = ( + "$(inherited)", + "-Wno-unused-command-line-argument", + ); + OTHER_CPLUSPLUSFLAGS = ( + "$(OTHER_CFLAGS)", + "-Wno-unused-command-line-argument", + "$(inherited)", + ); + OTHER_LDFLAGS = ""; + PRODUCT_BUNDLE_IDENTIFIER = com.taobao.LuaViewSDK.LuaViewSDK; + PRODUCT_NAME = "$(TARGET_NAME)"; + SKIP_INSTALL = YES; + VALID_ARCHS = "arm64 armv7 x86_64 i386"; + WRAPPER_EXTENSION = framework; + }; + name = Debug; + }; + 84C1D7D31C16C3CD0058E974 /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 3661550721FB71AF60C9B439 /* Pods-LuaViewSDK.release.xcconfig */; + buildSettings = { + ARCHS = "$(ARCHS_STANDARD)"; + CLANG_ENABLE_MODULES = NO; + CLANG_ENABLE_MODULE_DEBUGGING = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + DEFINES_MODULE = YES; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + FRAMEWORK_VERSION = A; + GCC_NO_COMMON_BLOCKS = YES; + GCC_TREAT_WARNINGS_AS_ERRORS = YES; + INFOPLIST_FILE = LuaViewSDK/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + OTHER_CFLAGS = "-fembed-bitcode"; + OTHER_LDFLAGS = ""; + PRODUCT_BUNDLE_IDENTIFIER = com.taobao.LuaViewSDK.LuaViewSDK; + PRODUCT_NAME = "$(TARGET_NAME)"; + SKIP_INSTALL = YES; + VALID_ARCHS = "arm64 armv7 x86_64 i386"; + WRAPPER_EXTENSION = framework; + }; + name = Release; + }; + 84C1D89F1C16CB820058E974 /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 151AA3B1FB2503E3C4CD0FC9 /* Pods-Dummy.debug.xcconfig */; + buildSettings = { + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + DEBUG_INFORMATION_FORMAT = dwarf; + GCC_NO_COMMON_BLOCKS = YES; + IPHONEOS_DEPLOYMENT_TARGET = 9.1; + ONLY_ACTIVE_ARCH = YES; + OTHER_LDFLAGS = "-ObjC"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SKIP_INSTALL = YES; + }; + name = Debug; + }; + 84C1D8A01C16CB820058E974 /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 158CD13BD2B405C24DFE7560 /* Pods-Dummy.release.xcconfig */; + buildSettings = { + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + GCC_NO_COMMON_BLOCKS = YES; + IPHONEOS_DEPLOYMENT_TARGET = 9.1; + OTHER_LDFLAGS = "-ObjC"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SKIP_INSTALL = YES; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 3CFF77B11C7473A800847C05 /* Build configuration list for PBXNativeTarget "LuaViewLib" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 3CFF77AF1C7473A800847C05 /* Debug */, + 3CFF77B01C7473A800847C05 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 848B5C191A0A4CA000F59678 /* Build configuration list for PBXProject "LuaViewSDK" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 848B5C3F1A0A4CA000F59678 /* Debug */, + 848B5C401A0A4CA000F59678 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 84C1D7D11C16C3CD0058E974 /* Build configuration list for PBXNativeTarget "LuaViewSDK" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 84C1D7D21C16C3CD0058E974 /* Debug */, + 84C1D7D31C16C3CD0058E974 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 84C1D89E1C16CB820058E974 /* Build configuration list for PBXNativeTarget "Dummy" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 84C1D89F1C16CB820058E974 /* Debug */, + 84C1D8A01C16CB820058E974 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 848B5C161A0A4CA000F59678 /* Project object */; +} diff --git a/IOS/SDK/LuaViewSDK.xcworkspace/contents.xcworkspacedata b/IOS/SDK/LuaViewSDK.xcworkspace/contents.xcworkspacedata new file mode 100644 index 00000000..2ee6283f --- /dev/null +++ b/IOS/SDK/LuaViewSDK.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,10 @@ + + + + + + + diff --git a/IOS/SDK/LuaViewSDK/Classes/LVBlock.h b/IOS/SDK/LuaViewSDK/Classes/LVBlock.h new file mode 100644 index 00000000..28d52554 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/LVBlock.h @@ -0,0 +1,35 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + +@interface LVBlock : NSObject + +@property (nonatomic,assign) int returnValueNum;// 返回值的数量 + +- (id) initWith:(lua_State*)L statckID:(int) idx; +- (id) initWith:(lua_State*)L globalName:(NSString*) globalName; + +/* + * 调用Lua function + */ +- (NSString*) callWithArgs:(NSArray*) args; +- (NSString*) callWithArgs:(NSArray*) args returnValueNum:(int) returnValueNum; + +/* + * 获取返回值 + */ +- (id) returnValue:(int)index; +- (id) returnValue; + + +- (void) pushFunctionToStack; + + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/LVBlock.m b/IOS/SDK/LuaViewSDK/Classes/LVBlock.m new file mode 100644 index 00000000..2faef2c6 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/LVBlock.m @@ -0,0 +1,137 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVBlock.h" +#import "LuaViewCore.h" +#import "LVHeads.h" + +@interface LVBlock () +@property (nonatomic,weak) LuaViewCore* lview; +@property (nonatomic,strong) id retainKey; +@property (nonatomic,strong) NSArray* returnValues; +@end + +@implementation LVBlock + +- (id) initWith:(lua_State*)L statckID:(int) idx{ + self = [super init]; + if( self ){ + self.retainKey = [[NSMutableString alloc] init]; + self.lview = LV_LUASTATE_VIEW(L); + if( lua_type(L, idx)==LUA_TFUNCTION ) { + [LVUtil registryValue:L key:self.retainKey stack:idx]; + } + } + return self; +} + +- (id) initWith:(lua_State*)L globalName:(NSString*) globalName{ + self = [super init]; + if( self ){ + self.retainKey = [[NSMutableString alloc] init]; + self.lview = LV_LUASTATE_VIEW(L); + + if ( [globalName rangeOfString:@"."].length>0 ){ + [self resetFunctionByNames:globalName]; + } else { + lua_getglobal(L, globalName.UTF8String); + if( lua_type(L, -1)==LUA_TFUNCTION ) { + [LVUtil registryValue:L key:self.retainKey stack:-1]; + } + } + } + return self; +} + +-(void) resetFunctionByNames:(NSString*) globalName{ + NSArray * names = [globalName componentsSeparatedByString:@"."]; + lua_State* L = self.lview.l; + if( names.count>0 ){ + NSString* name0 = names.firstObject; + lua_getglobal(L, name0.UTF8String); + for( int i=1; i0 ) { + self.returnValues = values; + } else { + self.returnValues = nil; + } + //lua_settop(L, oldStackNum); + return ret; + } + return nil; +} + +-(void) pushFunctionToStack{ + lua_State* L = self.lview.l; + if( L ){ + [LVUtil pushRegistryValue:L key:self.retainKey]; + } +} + +-(id) returnValue{ + return [self returnValue:0]; +} + +-(id) returnValue:(int)index{ + if( index>=0 && index +#import +#import "LVHeads.h" + +@class LVRSA; + +@interface LVBundle : NSObject + +@property (nonatomic, readonly) NSArray* scriptPaths; +@property (nonatomic, readonly) NSArray* resourcePaths; + +@property (nonatomic, readonly) NSString *currentPath; + +- (void)changeCurrentPath:(NSString *)path; + +/** + * 可以是绝对路径也可以是相对bundle根目录的相对路径 + */ +- (void)addResourcePath:(NSString *)path; +- (void)removeResourcePath:(NSString *)path; + +- (void)addScriptPath:(NSString *)path; +- (void)removeScriptPath:(NSString *)path; + +- (NSString *)resourcePathWithName:(NSString *)name; + +- (NSData *)resourceWithName:(NSString *)name; +- (UIImage *)imageWithName:(NSString *)name; + +- (NSString *)scriptPathWithName:(NSString *)name; + +- (NSData *)scriptWithName:(NSString *)name; +- (NSData *)signedScriptWithName:(NSString *)name rsa:(LVRSA *)rsa; + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/LVBundle.m b/IOS/SDK/LuaViewSDK/Classes/LVBundle.m new file mode 100644 index 00000000..4d20d04d --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/LVBundle.m @@ -0,0 +1,205 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVBundle.h" +#import "LVPkgManager.h" +#import "LVUtil.h" +#import "LVHeads.h" +#import "LView.h" + +@interface LVBundle () { + NSMutableArray *_scriptPaths; + NSMutableArray *_resourcePaths; + NSFileManager *_fileManager; + NSString *_currentPath; +} + +@property(nonatomic,strong) NSMutableDictionary* imageCaches; + +@end + +@implementation LVBundle + +@dynamic resourcePaths, scriptPaths; +@dynamic currentPath; + +- (id)init { + self = [super init]; + if(self) { + _fileManager = [NSFileManager defaultManager]; + _currentPath = [[NSBundle mainBundle] resourcePath]; + + _resourcePaths = [NSMutableArray arrayWithObjects:[LVUtil PathForCachesResource:nil], @".", nil]; + _scriptPaths = [NSMutableArray arrayWithObject:@"."]; + _imageCaches = [[NSMutableDictionary alloc] init]; + } + return self; +} + +- (NSString *)currentPath { + return _currentPath; +} + +- (void)changeCurrentPath:(NSString *)path { + NSAssert(path, @"current path could not be nil"); + BOOL isDir = NO; + if (![_fileManager fileExistsAtPath:path isDirectory:&isDir] || !isDir) { + NSAssert(NO, @"%@ not exists or is not a directory", path); + return; + } + + _currentPath = path; +} + +- (NSArray *)resourcePaths { + return [_resourcePaths copy]; +} + +- (void)addResourcePath:(NSString *)path { + NSAssert(path, @"path could not be nil"); + + [_resourcePaths insertObject:path atIndex:0]; +} + +- (void)removeResourcePath:(NSString *)path { + NSAssert(path, @"path could not be nil"); + + [_resourcePaths removeObject:path]; +} + +- (NSArray *)scriptPaths { + return [_scriptPaths copy]; +} + +- (void)addScriptPath:(NSString *)path { + NSAssert(path, @"path could not be nil"); + + [_scriptPaths insertObject:path atIndex:0]; +} + +- (void)removeScriptPath:(NSString *)path { + NSAssert(path, @"path could not be nil"); + + [_scriptPaths removeObject:path]; +} + +- (NSString *)absolutePath:(NSString *)path { + if (path == nil) { + return nil; + } else if ([path hasPrefix:@"/"]) { + return path; + } else { + return [_currentPath stringByAppendingPathComponent:path]; + } +} + +- (NSString *)resourcePathWithName:(NSString *)name { + if (name == nil) { + return nil; + } + + NSString *fullPath = nil; + for (NSString *dir in _resourcePaths) { + fullPath = [self absolutePath:[dir stringByAppendingPathComponent:name]]; + if ([_fileManager fileExistsAtPath:fullPath]) { + return fullPath; + } + } + + return nil; +} + +- (NSData *)resourceWithName:(NSString *)name { + if (name == nil) { + return nil; + } + + NSString *path = [self resourcePathWithName:name]; + if (path == nil) { + return nil; + } + + return [_fileManager contentsAtPath:path]; +} + +- (UIImage *)imageWithName:(NSString *)name { + if (name == nil) { + return nil; + } + UIImage* image = self.imageCaches[name]; + if( image ) { + return image; + } + NSString *path = [self resourcePathWithName:name]; + if( path ) { + image = [UIImage imageWithContentsOfFile:path]; + } else { + image = [UIImage imageNamed:name]; + } + if( image ){ + self.imageCaches[name] = image; + } + return image; +} + +- (NSString *)scriptPathWithName:(NSString *)name { + if (name == nil) { + return nil; + } + + NSString *ext = [name pathExtension]; + if (ext == nil || + !([LVScriptExts[0] isEqualToString:ext] || [LVScriptExts[1] isEqualToString:ext])) { + + NSAssert(nil, @"LuaView: %@ file is not supported!", ext); + return nil; + } + + NSString *fullPath = nil; + for (NSString *dir in _scriptPaths) { + fullPath = [self absolutePath:[dir stringByAppendingPathComponent:name]]; + if ([_fileManager fileExistsAtPath:fullPath]) { + return fullPath; + } + } + + return name; +} + +- (NSData *)scriptWithName:(NSString *)name { + if (name == nil) { + return nil; + } + NSAssert([[name pathExtension] isEqualToString:LVScriptExts[!LVSignedScriptExtIndex]], + @"%@ is not normal script", name); + + NSString *fullPath = [self scriptPathWithName:name]; + if (fullPath == nil) { + return nil; + } + + return [LVUtil dataReadFromFile:fullPath]; +} + +- (NSData *)signedScriptWithName:(NSString *)name rsa:(LVRSA *)rsa { + if (name == nil) { + return nil; + } + + NSAssert([[name pathExtension] isEqualToString:LVScriptExts[LVSignedScriptExtIndex]], + @"%@ is not signed script", name); + + NSString *fullPath = [self scriptPathWithName:name]; + if (fullPath == nil) { + return nil; + } + + return [LVPkgManager readLuaFile:fullPath rsa:rsa]; +} + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/LView.h b/IOS/SDK/LuaViewSDK/Classes/LView.h new file mode 100644 index 00000000..8bb7c2de --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/LView.h @@ -0,0 +1,27 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import + +#import "LuaView.h" +#pragma mark -LuaView 类加载脚本调用接口 +@interface LView : LuaView + +@property (nonatomic,assign) BOOL checkDebugerServer; // 是否检查调试器 + +// 设置证书地址 +- (void) setPublicKeyFilePath:(NSString*) filePath; + +-(LVBlock*) getLuaBlock:(NSString*) name; + +-(NSString*) callLua:(NSString*) functionName tag:(id) tag environment:(UIView*)environment args:(NSArray*) args; +-(NSString*) callLua:(NSString*) functionName environment:(UIView*) environment args:(NSArray*) args; +-(NSString*) callLua:(NSString*) functionName args:(NSArray*) args; + +@end + diff --git a/IOS/SDK/LuaViewSDK/Classes/LView.m b/IOS/SDK/LuaViewSDK/Classes/LView.m new file mode 100644 index 00000000..e65b99a3 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/LView.m @@ -0,0 +1,38 @@ + +#import "LView.h" +#import "LVRSA.h" + + +@implementation LView + +-(BOOL) checkDebugerServer{ + return self.luaviewCore.checkDebugerServer; +} + +-(void) setCheckDebugerServer:(BOOL)checkDebugerServer{ + self.luaviewCore.checkDebugerServer = checkDebugerServer; +} + +// 设置证书地址 +- (void) setPublicKeyFilePath:(NSString*) filePath{ + [self.luaviewCore.rsa setPublicKeyFilePath:filePath]; +} + +-(NSString*) callLua:(NSString*) functionName tag:(id) tag environment:(UIView*)environment args:(NSArray*) args{ + return [self.luaviewCore callLua:functionName tag:tag environment:environment args:args]; +} + +-(NSString*) callLua:(NSString*) functionName environment:(UIView*) environment args:(NSArray*) args{ + return [self.luaviewCore callLua:functionName environment:environment args:args]; +} + +-(NSString*) callLua:(NSString*) functionName args:(NSArray*) args{ + return [self.luaviewCore callLua:functionName args:args]; +} + +-(LVBlock*) getLuaBlock:(NSString*) name{ + return [self.luaviewCore getLuaBlock:name]; +} + + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/LViewController.h b/IOS/SDK/LuaViewSDK/Classes/LViewController.h new file mode 100644 index 00000000..b0dd9658 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/LViewController.h @@ -0,0 +1,33 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import + + +@class LuaView; + +typedef void(^LuaViewRegister)(LuaView* lv); + +@interface LViewController : UIViewController + +@property(nonatomic, readonly) LuaView *lv; +@property(nonatomic, readonly) NSString *mainScriptName; +@property(nonatomic, readonly) NSString *packagePath; + ++ (void)disableReloadKeyCommand:(BOOL)disable; + +- (instancetype)initWithPackage:(NSString *)path mainScript:(NSString *)scriptName; + +- (void)willCreateLuaView; +- (void)didCreateLuaView:(LuaView *) view; +- (void)willDestroyLuaView:(LuaView *) view; +- (void)didDestroyLuaView; + +@property(nonatomic,copy) LuaViewRegister luaviewRegister; + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/LViewController.m b/IOS/SDK/LuaViewSDK/Classes/LViewController.m new file mode 100644 index 00000000..d6dcf2dd --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/LViewController.m @@ -0,0 +1,175 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LViewController.h" +#import "LuaView.h" +#import "LVUtil.h" + +#if DEBUG +#define LV_LOCAL_DEBUG 1 +#endif + +@interface LViewController () + +@property (nonatomic, strong) LuaView *lv; + +@property (nonatomic, strong) NSString *packagePath, *mainScriptName; + +@end + +static BOOL __disableReloadKeyCommand = NO; + +@implementation LViewController + ++ (void)disableReloadKeyCommand:(BOOL)disable { + __disableReloadKeyCommand = disable; +} + +- (instancetype)initWithPackage:(NSString *)path mainScript:(NSString *)scriptName { + if (self = [super init]) { + _packagePath = path; + _mainScriptName = scriptName; + } + + return self; +} + +-(void) dealloc{ + [self.lv releaseLuaView]; + self.lv = nil; +} + +- (void)viewDidLoad { + [super viewDidLoad]; + self.automaticallyAdjustsScrollViewInsets = NO; + self.edgesForExtendedLayout = UIRectEdgeNone; + + [self createLuaView]; +} + +- (BOOL)canBecomeFirstResponder { + return YES; +} + +#pragma mark - rewarding methods + +// TODO: reward memory warning + +- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event { + [self.lv motionBegan:motion withEvent:event]; +} + +- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event { + [self.lv motionCancelled:motion withEvent:event]; +} + +- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event { + [self.lv motionEnded:motion withEvent:event]; +} + +-(void) viewWillAppear:(BOOL)animated{ + [super viewWillAppear:animated]; + [self.navigationController setNavigationBarHidden:NO animated:YES]; + + [self.lv viewWillAppear]; +} + +-(void) viewDidAppear:(BOOL)animated{ + [super viewDidAppear:animated]; + [self becomeFirstResponder]; + + [self.lv viewDidAppear]; +} + +-(void) viewWillDisappear:(BOOL)animated{ + [super viewWillDisappear:animated]; + [self.lv viewWillDisAppear]; +} + +-(void) viewDidDisappear:(BOOL)animated{ + [super viewDidDisappear:animated]; + [self.lv viewDidDisAppear]; +} + +#pragma mark - luaview life cycle + +- (void)rebuildLuaView { + [self destroyLuaView]; + [self createLuaView]; +} + +- (void)createLuaView { + [self willCreateLuaView]; + + CGRect rect = self.view.bounds; + + self.lv = [[LuaView alloc] initWithFrame:rect]; + self.lv.viewController = self; + + if( self.luaviewRegister ) { + self.luaviewRegister(self.lv); + } + + [self didCreateLuaView:self.lv]; + + [self.view addSubview:self.lv]; + + [self runLocalPackage:self.packagePath mainScript:self.mainScriptName]; +} + +- (void)destroyLuaView { + [self willDestroyLuaView:self.lv]; + + [self.lv releaseLuaView]; + self.lv = nil; + + [self didDestroyLuaView]; +} + +- (void)runLocalPackage:(NSString *)packagePath mainScript:(NSString *)scriptName { + if (packagePath) { + [self.lv.bundle addScriptPath:packagePath]; + [self.lv.bundle addResourcePath:packagePath]; + } + [self.lv runFile:scriptName ?: @"main.lua"]; +} + +- (void)willCreateLuaView { } + +- (void)didCreateLuaView:(LView *)view { } + +- (void)willDestroyLuaView:(LView *)view { } + +- (void)didDestroyLuaView { } + +#pragma mark - debug + +#if LV_LOCAL_DEBUG + +/* + * Cmd + r 没有刷新时需要做如下设置: + * simulator -> Hardware -> Keyboard -> Connect Hardware Keyboard + * + * https://github.com/facebook/react-native/issues/306#issuecomment-86834162 + */ +- (NSArray *)keyCommands { + if (__disableReloadKeyCommand) { + return nil; + } + + UIKeyCommand *reloadKeyCommand = [UIKeyCommand + keyCommandWithInput:@"r" + modifierFlags:UIKeyModifierCommand + action:@selector(rebuildLuaView)]; + + return @[reloadKeyCommand]; +} + +#endif // LV_LOCAL_DEBUG + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/LuaView.h b/IOS/SDK/LuaViewSDK/Classes/LuaView.h new file mode 100644 index 00000000..a4f13e19 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/LuaView.h @@ -0,0 +1,120 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LuaViewCore.h" + + +@class LuaView; + +#pragma mark - LuaView窗口大小变动回调 +@protocol LVCallback +- (void) luaviewFrameDidChange:(LuaView *)lView; +@end + + +@interface LuaView : UIView + +@property (nonatomic,weak) UIViewController* viewController;// 所在的ViewController +@property (nonatomic,strong) LVBundle* bundle; + +@property(nonatomic,weak) id callback; //用于LuaView回调( luaView大小改变 等回调) +@property (nonatomic,strong) LuaViewCore* luaviewCore; +@property (nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; + +-(void) viewWillAppear; +-(void) viewDidAppear; +-(void) viewWillDisAppear; +-(void) viewDidDisAppear; + +#pragma mark - 摇一摇回调 +// 摇一摇开始摇动 +- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event; +// 摇一摇取消摇动 +- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event; +// 摇一摇摇动结束 +- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event; + +-(void) releaseLuaView; + + +// + +/** + * load and run script + * + * @param fileName 本地文件名 + * + * @return 返回运行结果 + */ +-(NSString*) runFile:(NSString*) fileName; + +/** + * 运行一个包, main.lv是主入口 + * + * @param fileName 本地文件名 + * + * @return 返回运行结果 + */ +-(NSString*) runPackage:(NSString*) packageName; + +/** + * 运行一个包, main.lv是主入口 + * + * @param fileName 本地文件名 + * @args args 参数 + * + * @return 返回运行结果 + */ +-(NSString*) runPackage:(NSString*) packageName args:(NSArray*) args; + +/** + * 运行签名的脚本文件 + * + * @param fileName 本地文件名 + * + * @return 返回运行结果 + */ +-(NSString*) runSignFile:(NSString*) fileName; + +/** + * load and run script + * + * @param chars 脚本字符流 + * @param length 脚本字符流的长度 + * @param fileName 文件名,用于出错提示, 可以为空 + * + * @return 运行结果 + */ +-(NSString*) runData:(NSData*) data fileName:(NSString*) fileName; + +/** + * 加载签名的脚本文件,读取文件并调用lvL_loadbuffer + * + * @param fileName 本地文件名 + * + * @return 返回错误描述 + */ +-(NSString*) loadSignFile:(NSString *)fileName; + +/** + * 加载脚本文件,读取文件并调用lvL_loadbuffer + * + * @param fileName 本地文件名 + * + * @return 返回错误描述 + */ +-(NSString*) loadFile:(NSString *)fileName; + +- (void) setObject:(id)object forKeyedSubscript:(NSObject *)key; + + +-(lua_State*) l; // 获取 lua 状态机 + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/LuaView.m b/IOS/SDK/LuaViewSDK/Classes/LuaView.m new file mode 100644 index 00000000..5b52336d --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/LuaView.m @@ -0,0 +1,342 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LuaView.h" +#import "LuaViewCore.h" + +@interface LuaView () +@property (nonatomic,assign) BOOL isOnShowed; +@end + +@implementation LuaView + + + +-(id) init{ + self = [super init]; + if( self ) { + } + return self; +} + +-(id) initWithFrame:(CGRect)frame{ + self = [super initWithFrame:frame]; + if( self ) { + [self createLuaViewCore]; + } + return self; +} + +/* + * 初始化LuaViewCore + */ +-(void) createLuaViewCore{ + self.luaviewCore = [[LuaViewCore alloc] init]; + [self.luaviewCore pushWindow:self]; + self.backgroundColor = [UIColor clearColor]; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(keyboardWillShow:) + name:UIKeyboardWillShowNotification + object:nil]; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(keyboardDidShow:) + name:UIKeyboardDidShowNotification + object:nil]; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(keyboardWillHide:) + name:UIKeyboardWillHideNotification + object:nil]; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(keyboardDidHide:) + name:UIKeyboardDidHideNotification + object:nil]; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(onForeground) + name:UIApplicationDidBecomeActiveNotification + object:nil]; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(onBackground) + name:UIApplicationDidEnterBackgroundNotification + object:nil]; +} + +-(void) dealloc{ + [[NSNotificationCenter defaultCenter] removeObserver:self]; +} + +-(UIViewController*) viewController{ + return self.luaviewCore.viewController; +} + +-(void) setViewController:(UIViewController *)viewController{ + self.luaviewCore.viewController = viewController; +} + +-(LVBundle*) bundle{ + return self.luaviewCore.bundle; +} + +-(void) setBundle:(LVBundle *)bundle{ + self.luaviewCore.bundle = bundle; +} + +-(void) releaseLuaView{ + [self.luaviewCore releaseLuaView]; +} + + +/** + * load and run script + * + * @param fileName 本地文件名 + * + * @return 返回运行结果 + */ +-(NSString*) runFile:(NSString*) fileName{ + return [self.luaviewCore runFile:fileName]; +} + +/** + * 运行一个包, main.lv是主入口 + * + * @param fileName 本地文件名 + * + * @return 返回运行结果 + */ +-(NSString*) runPackage:(NSString*) packageName{ + return [self.luaviewCore runPackage:packageName]; +} + +/** + * 运行一个包, main.lv是主入口 + * + * @param fileName 本地文件名 + * @args args 参数 + * + * @return 返回运行结果 + */ +-(NSString*) runPackage:(NSString*) packageName args:(NSArray*) args{ + return [self.luaviewCore runPackage:packageName args:args]; +} + +/** + * 运行签名的脚本文件 + * + * @param fileName 本地文件名 + * + * @return 返回运行结果 + */ +-(NSString*) runSignFile:(NSString*) fileName{ + return [self.luaviewCore runSignFile:fileName]; +} + +/** + * load and run script + * + * @param chars 脚本字符流 + * @param length 脚本字符流的长度 + * @param fileName 文件名,用于出错提示, 可以为空 + * + * @return 运行结果 + */ +-(NSString*) runData:(NSData*) data fileName:(NSString*) fileName{ + return [self.luaviewCore runData:data fileName:fileName]; +} + +/** + * 加载签名的脚本文件,读取文件并调用lvL_loadbuffer + * + * @param fileName 本地文件名 + * + * @return 返回错误描述 + */ +-(NSString*) loadSignFile:(NSString *)fileName{ + return [self.luaviewCore loadSignFile:fileName]; +} + +/** + * 加载脚本文件,读取文件并调用lvL_loadbuffer + * + * @param fileName 本地文件名 + * + * @return 返回错误描述 + */ +-(NSString*) loadFile:(NSString *)fileName{ + return [self.luaviewCore loadFile:fileName]; +} + +-(void) setFrame:(CGRect)frame{ + [super setFrame:frame]; + [self.callback luaviewFrameDidChange:self]; +} + +- (void)setObject:(id)object forKeyedSubscript:(NSObject *)key{ + [self.luaviewCore setObject:object forKeyedSubscript:key]; +} + + +#pragma mark - view appear + +-(void) viewWillAppear{ + lua_State* L = self.luaviewCore.l; + if( L ) { + lua_checkstack32(L); + [self lv_callLuaCallback:@"ViewWillAppear"]; + } +} + +-(void) viewDidAppear{ + self.isOnShowed = YES; + lua_State* L = self.luaviewCore.l; + if( L ) { + lua_checkstack32(L); + [self lv_callLuaCallback:@"onShow"];//@"ViewDidAppear" + } +} + +-(void) viewWillDisAppear{ + lua_State* L = self.luaviewCore.l; + if( L ) { + lua_checkstack32(L); + [self lv_callLuaCallback:@"ViewWillDisAppear"]; + } +} + +-(void) viewDidDisAppear{ + self.isOnShowed = NO; + lua_State* L = self.luaviewCore.l; + if( L ) { + lua_checkstack32(L); + [self lv_callLuaCallback:@"onHide"];//@"ViewDidDisAppear" + } +} + +-(void) onForeground { + lua_State* L = self.luaviewCore.l; + if( L && self.isOnShowed ) { + lua_checkstack32(L); + lua_pushboolean(L, YES); + [self lv_callLuaCallback:@"onShow" key2:nil argN:1]; + } +} + +-(void) onBackground { + lua_State* L = self.luaviewCore.l; + if( L && self.isOnShowed ) { + lua_checkstack32(L); + lua_pushboolean(L, YES); + [self lv_callLuaCallback:@"onHide" key2:nil argN:1]; + } +} + +- (void)didMoveToSuperview{ + [super didMoveToSuperview]; + + lua_State* L = self.luaviewCore.l; + if( L ) { + lua_checkstack32(L); + [self lv_callLuaCallback:@"DidMoveToSuperview"]; + } +} + +- (void)didMoveToWindow{ + [super didMoveToWindow]; + + lua_State* L = self.luaviewCore.l; + if( L ) { + lua_checkstack32(L); + [self lv_callLuaCallback:@"DidMoveToSuperview"]; + } +} + +-(void) layoutSubviews{ + [super layoutSubviews]; + + lua_State* L = self.luaviewCore.l; + if( L ) { + lua_checkstack32(L); + [self lv_callLuaCallback:@STR_ON_LAYOUT]; + } +} + + +#pragma mark - keyboard + +-(void) keyboardWillShow:(NSNotification *)notification { + lua_State* L = self.luaviewCore.l; + if( L ) { + lua_checkstack32(L); + [self lv_callLuaCallback:@"KeyboardWillShow"]; + } +} +-(void) keyboardDidShow:(NSNotification *)notification { + lua_State* L = self.luaviewCore.l; + if( L ) { + lua_checkstack32(L); + [self lv_callLuaCallback:@"KeyboardDidShow"]; + } +} +-(void) keyboardWillHide:(NSNotification *)notification { + lua_State* L = self.luaviewCore.l; + if( L ) { + lua_checkstack32(L); + [self lv_callLuaCallback:@"KeyboardWillHide"]; + } +} +-(void) keyboardDidHide:(NSNotification *)notification { + lua_State* L = self.luaviewCore.l; + if( L ) { + lua_checkstack32(L); + [self lv_callLuaCallback:@"KeyboardDidHide"]; + } +} + +#pragma mark - 摇一摇相关方法 +// 摇一摇开始摇动 +- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event { + lua_State* L = self.luaviewCore.l; + if (event.subtype == UIEventSubtypeMotionShake) { + if( L ) { + lua_checkstack32(L); + [self lv_callLuaCallback:@"ShakeBegin"]; + } + } +} + +// 摇一摇取消摇动 +- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event { + if (event.subtype == UIEventSubtypeMotionShake) { + lua_State* L = self.luaviewCore.l; + if( L ) { + lua_checkstack32(L); + [self lv_callLuaCallback:@"ShakeCanceled"]; + } + } +} + +// 摇一摇摇动结束 +- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event { + if (event.subtype == UIEventSubtypeMotionShake) { + lua_State* L = self.luaviewCore.l; + if( L ) { + lua_checkstack32(L); + [self lv_callLuaCallback:@"ShakeEnded"]; + } + } +} + +-(lua_State*) l{ + return self.luaviewCore.l; +} + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/LuaViewCore.h b/IOS/SDK/LuaViewSDK/Classes/LuaViewCore.h new file mode 100644 index 00000000..13d787eb --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/LuaViewCore.h @@ -0,0 +1,246 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" +#import "LVDebugConnection.h" + + +@class LView; +@class LVBlock; +@class LVBundle; +@protocol LVProtocal; + + +#pragma mark -LuaView 类加载脚本调用接口 +@interface LuaViewCore : NSObject + +@property (nonatomic,strong) LVRSA* rsa; + +@property (nonatomic,strong) LVBundle* bundle; + +/** + * 是否需要语法转换(原先luaview语法和lua标准语法的区别是‘.’和':'互换了),默认是标准语法,使用非标准语法需要转换成标准语法才设置成true + */ +//不再支持changeGrammer, 缺省只支持标准语法,不进行转换 +//@property (nonatomic,assign) BOOL changeGrammar; + +//--------------------------------------------------------------------- +/** +* 调试开关 +* +*/ +@property (nonatomic,assign) BOOL checkDebugerServer; // 是否检查调试器 +// @property (nonatomic,assign) BOOL openDebugger; // 开启调试 + + +//--------------------------------------------------------------------- +/** +* 加载脚本文件,读取文件并调用lvL_loadbuffer +* +* @param fileName 本地文件名 +* +* @return 返回错误描述 +*/ +-(NSString*) loadFile:(NSString *)fileName; + +/** +* 加载签名的脚本文件,读取文件并调用lvL_loadbuffer +* +* @param fileName 本地文件名 +* +* @return 返回错误描述 +*/ +-(NSString*) loadSignFile:(NSString *)fileName; + +/** + * 加载代码String + */ +- (NSString*) loadScript:(NSString*)script fileName:(NSString *)fileNam; + +/** +* 加载代码data +*/ +- (NSString*) loadData:(NSData *)data fileName:(NSString *)fileNam; + +/** +* load and run script +* +* @param fileName 本地文件名 +* +* @return 返回运行结果 +*/ +-(NSString*) runFile:(NSString*) fileName; + +/** +* 运行一个包, main.lv是主入口 +* +* @param fileName 本地文件名 +* +* @return 返回运行结果 +*/ +-(NSString*) runPackage:(NSString*) packageName; + +/** +* 运行一个包, main.lv是主入口 +* +* @param fileName 本地文件名 +* @args args 参数 +* +* @return 返回运行结果 +*/ +-(NSString*) runPackage:(NSString*) packageName args:(NSArray*) args; + +/** + * 加载包 + */ +- (NSString*) loadPackage:(NSString*) packageName; + +/** +* 运行签名的脚本文件 +* +* @param fileName 本地文件名 +* +* @return 返回运行结果 +*/ +-(NSString*) runSignFile:(NSString*) fileName; + +/** +* load and run script +* +* @param chars 脚本字符流 +* @param length 脚本字符流的长度 +* @param fileName 文件名,用于出错提示, 可以为空 +* +* @return 运行结果 +*/ +-(NSString*) runData:(NSData*) data fileName:(NSString*) fileName; +// +//-(NSString*) runData:(NSData*) data fileName:(NSString*) fileName changeGrammar:(BOOL) changeGrammar; + +/** +* +*调用lua脚本, functionName:lua的function名称, environment:运行窗口, args:传递参数 +* +*/ +-(NSString*) callLua:(NSString*) functionName tag:(id) tag environment:(UIView*)environment args:(NSArray*) args; +-(NSString*) callLua:(NSString*) functionName environment:(UIView*) environment args:(NSArray*) args; +-(NSString*) callLua:(NSString*) functionName args:(NSArray*) args; +-(LVBlock*) getLuaBlock:(NSString*) name; + +/** +* 释放虚拟机回收luaView +*/ +-(void) releaseLuaView; + +/** +* Layer模式优化性能 +*/ +@property (nonatomic,assign) BOOL closeLayerMode; + + +/** +* 图片首次出现是否使用动画 +*/ +@property (nonatomic,assign) BOOL disableAnimate; + +@property(nonatomic,copy) NSArray* registerClasses; + +@property (nonatomic,weak) UIViewController* viewController;// 所在的ViewController + +@end + + +#pragma mark - 设置资源搜索路径 +@interface LuaViewCore () + + +/* + * packageName: 包名 比如:"ppt" + * info格式: { "url" : "http://g.tbcdn.cn/ju/lua/3.2.12/ppt4.4.0.js" , "time":"2015-11-18 09:53"} + */ ++(void) downloadPackage:(NSString*)package withInfo:(NSDictionary*)info; + +@end + +#pragma mark - Register 注册外部api接口 +@interface LuaViewCore () + +- (void) setObject:(id)object forKeyedSubscript:(NSObject *)key; +- (void) registerObject:(id) object forName:(NSString*) name sel:(SEL) sel;// 只注册指定API +- (void) registerObject:(id) object forName:(NSString*) name sel:(SEL) sel weakMode:(BOOL) weakMode;// 只注册指定API +- (void) registerObject:(id) object forName:(NSString*) name;// 注册改对象的所有api +- (void) registerObject:(id) object forName:(NSString*) name weakMode:(BOOL) weakMode;// 注册改对象的所有api +- (void) unregisteObjectForName:(NSString*) name;// 取消注册对象 + + +- (void) registerLibs:(id) lib; +- (void) registerName:(NSString*) name withObject:(id) object; +- (void) registerPanel:(id) panel; +- (void) registerPanel:(id) panel forName:(NSString*) name; +- (void) unregister:(NSString*) name; + +@end + + + +#pragma mark - LViewBlock lua闭包参数获取使用 +@interface LuaViewCore () + +- (BOOL) argumentToBool:(int) index; +- (double) argumentToNumber:(int) index; +- (id) argumentToObject:(int) index; + +@end + + +#pragma mark - debugger 只是调试工具使用 +@interface LuaViewCore () + +-(void) callLuaToExecuteServerCmd; + +#ifdef DEBUG +@property (nonatomic,strong) LVDebugConnection* debugConnection; +#endif + +@end + + +#pragma mark - Property 系统使用的, 基本上不用关心细节 +@interface LuaViewCore () +@property (nonatomic,assign) BOOL runInSignModel;// 加密模式,优先加载加密脚本 +@property (nonatomic, weak) LuaViewCore* lv_luaviewCore; +@property (nonatomic, assign) LVUserDataInfo* lv_userData;// 脚本中的window对象 数据绑定 +@property (nonatomic, assign) lua_State* l; // lua 状态机 + +-(void) containerAddSubview:(UIView *)view; + + +@end + + + +//------------ 窗口渲染接口, 必须成对出现! 慎用! ------------------------------ +@interface LuaViewCore () +/** + * 渲染窗口 压栈 + * + */ +-(void) pushWindow:(UIView*) window; +-(void) pushRenderTarget:(UIView*) window; + +/** + * 渲染窗口 出栈 + */ +-(void) popWindow:(UIView*) window; +-(void) popRenderTarget:(UIView*) window; + +-(void) luaviewGC; + +@end + diff --git a/IOS/SDK/LuaViewSDK/Classes/LuaViewCore.m b/IOS/SDK/LuaViewSDK/Classes/LuaViewCore.m new file mode 100644 index 00000000..12212174 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/LuaViewCore.m @@ -0,0 +1,649 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LuaViewCore.h" + + +#import "LuaViewCore.h" +#import "LVHeads.h" +#import "LVExGlobalFunc.h" +#import "LVTimer.h" +#import "LVDebuger.h" +#import "LVNativeObjBox.h" +#import "LVBlock.h" +#import "LVPkgManager.h" +#import "UIView+LuaView.h" +#import "LVDebugConnection.h" +#import "LVDebugConnection.h" +#import "LVCustomPanel.h" +#import +#import "LVRSA.h" +#import "LVBundle.h" +#import "LVButton.h" +#import "LVScrollView.h" +#import "LVTimer.h" +#import "LVUtil.h" +#import "LVPagerIndicator.h" +#import "LVLoadingIndicator.h" +#import "LVImage.h" +//#import "LVWebView.h" +#import "LVLabel.h" +#import "LVBaseView.h" +#import "LVTransform3D.h" +#import "LVTextField.h" +#import "LVAnimate.h" +#import "LVAnimator.h" +#import "LVDate.h" +#import "LVAlert.h" +#import "LVSystem.h" +#import "LVDB.h" +#import "LVGesture.h" +#import "LVTapGesture.h" +#import "LVPanGesture.h" +#import "LVPinchGesture.h" +#import "LVRotationGesture.h" +#import "LVHttp.h" +#import "LVData.h" +#import "LVSwipeGesture.h" +#import "LVLongPressGesture.h" +#import "LVDebuger.h" +#import "LVDownloader.h" +#import "LVAudioPlayer.h" +#import "LVFile.h" +#import "LVStyledString.h" +#import "LVNativeObjBox.h" +#import "LVCollectionView.h" +#import "LVEmptyRefreshCollectionView.h" +#import "LVStruct.h" +#import "LVNavigation.h" +#import "LVCustomPanel.h" +#import "LVCustomView.h" +#import "LVPagerView.h" +#import "LVCanvas.h" +#import "LVEvent.h" +#import "LVBitmap.h" +#import "LVCamera.h" + +@interface LuaViewCore () +@property (nonatomic,strong) id mySelf; +@property (nonatomic,assign) BOOL stateInited; +@property (nonatomic,assign) BOOL loadedDebugScript; +@property (atomic,assign) NSInteger callLuaTimes; +@property(nonatomic,weak) UIView* window; +@property (nonatomic,assign) int windowIdx; +@end + +@implementation LuaViewCore + +-(id) init{ + self = [super init]; + if( self ){ + [self myInit]; + [self registeLibs]; + } + return self; +} + +#pragma mark - init + +-(void) myInit{ + self.checkDebugerServer = YES; + self.disableAnimate = YES; + self.closeLayerMode = YES; + self.mySelf = self; + + + self.lv_luaviewCore = self; + self.rsa = [[LVRSA alloc] init]; + self.bundle = [[LVBundle alloc] init]; +} + +-(void) dealloc{ +#ifdef DEBUG + [self.debugConnection closeAll]; +#endif +} + +#pragma mark - run +-(NSString*) runFile:(NSString*) fileName{ + self.runInSignModel = FALSE; + NSData* code = [self.bundle scriptWithName:fileName]; + + return [self runData:code fileName:fileName]; +} + +-(NSString*) runSignFile:(NSString*) fileName{ + self.runInSignModel = TRUE; + NSData* code = [self.bundle signedScriptWithName:fileName rsa:self.rsa]; + + return [self runData:code fileName:fileName]; +} + +- (NSString*) loadPackage:(NSString*) packageName{ + return [self runPackage:packageName]; +} + +-(NSString*) runPackage:(NSString*) packageName { + return [self runPackage:packageName args:nil]; +} + +-(NSString*) runPackage:(NSString*) packageName args:(NSArray*) args{ + self.runInSignModel = TRUE; + + NSString *packagePath = [LVPkgManager rootDirectoryOfPackage:packageName]; + [self.bundle addScriptPath:packagePath]; + [self.bundle addResourcePath:packagePath]; + + NSString* fileName = @"main.lv"; + NSString* ret = [self runSignFile:fileName]; + lua_State* L = self.l; + if( ret==nil && L ) { + for( int i=0; i0 ) { + if( self.loadedDebugScript == NO ) { + self.loadedDebugScript = YES; + [self.debugConnection sendCmd:@"log" info:@"[LuaView][调试日志] 开始调试!\n"]; + [self loadDebugModel];// 加载调试模块 + } + } +} +#else +- (void) callLuaToExecuteServerCmd{ +} +#endif + +static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) { + (void)ud; + (void)osize; + if (nsize == 0) { + free(ptr); + return NULL; + } else { + return realloc(ptr, nsize); + } +} + + +-(void) registeLibs{ + if( !self.stateInited ) { + self.stateInited = YES; + self.l = lua_newstate(l_alloc, (__bridge void *)(self)); + luaL_openlibs(self.l); + NSArray* arr = nil; + arr = @[ + [LVSystem class], + [LVData class], + [LVStruct class], + [LVBaseView class], + [LVButton class], + [LVImage class], + [LVBitmap class], +// [LVWebView class], + [LVLabel class], + [LVScrollView class], + [LVCollectionView class], + [LVEmptyRefreshCollectionView class], + [LVPagerView class], + [LVCustomView class], + [LVCanvas class], + [LVEvent class], + [LVTimer class], + [LVPagerIndicator class], + [LVCustomPanel class], + [LVTransform3D class], + [LVAnimator class], + [LVTextField class], + [LVAnimate class], + [LVDate class], + [LVAlert class], + [LVDB class], + [LVGesture class], + [LVTapGesture class], + [LVPinchGesture class], + [LVRotationGesture class], + [LVSwipeGesture class], + [LVLongPressGesture class], + [LVPanGesture class], + [LVLoadingIndicator class], + [LVHttp class], + [LVDownloader class], + [LVFile class], + [LVAudioPlayer class], + [LVStyledString class], + [LVNavigation class], + [LVExGlobalFunc class], + [LVNativeObjBox class], + [LVDebuger class], + [LVCamera class], + ]; + self.registerClasses = arr; + [self registerAllClass]; + + // 默认支持RefreshCollectionView + self[@"RefreshCollectionView"] = [LVCollectionView class]; + } +} + +-(void) registerAllClass{ + lua_State* L = self.l; + //清理栈 + for( NSInteger i =0; i *)key{ + lua_State* L = self.l; + if ( L ==nil ){ + LVError( @"Lua State is released !!!"); + return; + } + if( [key isKindOfClass:[NSString class]] && class_isMetaClass(object_getClass(object)) ) { + if( [object respondsToSelector:@selector(lvClassDefine:globalName:)] ) { + [object lvClassDefine:L globalName:(NSString*)key]; + return; + } + } + if ( [key isKindOfClass:[NSString class]] ){ + [LVNativeObjBox registeObjectWithL:L nativeObject:object name:(NSString*)key sel:nil weakMode:YES]; + } +} + +-(void) unregisteObjectForName:(NSString*) name{ + lua_State* L = self.l; + if ( L ==nil ){ + LVError( @"Lua State is released !!!"); + return ; + } + [LVNativeObjBox unregisteObjectWithL:L name:name]; +} + +- (void) registerLibs:(id) lib{ + lua_State* L = self.l; + if( [lib respondsToSelector:@selector(lvClassDefine:globalName:)] ) { + [lib lvClassDefine:L globalName:nil]; + return; + } +} + +- (void) registerName:(NSString*) name withObject:(id) object{ + [self registerObject:object forName:name]; +} + +- (void) registerPanel:(id) panel{ + [self registerPanel:panel forName:nil]; +} + +- (void) registerPanel:(id) panel forName:(NSString*) name{ + lua_State* L = self.l; + if( [panel respondsToSelector:@selector(lvClassDefine:globalName:)] ) { + [panel lvClassDefine:L globalName:name]; + return; + } +} + +- (void) unregister:(NSString*) name{ + [self unregisteObjectForName:name]; +} +#pragma mark - package + ++(void) downloadPackage:(NSString*)packageName withInfo:(NSDictionary*)info{ + [LVPkgManager downloadPackage:packageName withInfo:info]; +} + +-(BOOL) argumentToBool:(int) index{ + lua_State* L = self.l; + if ( L ) { + return lua_toboolean(L, index); + } + return NO; +} + +-(double) argumentToNumber:(int) index{ + lua_State* L = self.l; + if ( L ) { + return lua_tonumber(L, index); + } + return 0; +} + +-(id) argumentToObject:(int) index{ + lua_State* L = self.l; + if ( L ) { + return lv_luaValueToNativeObject(L, index); + } + return 0; +} + +-(void) containerAddSubview:(UIView *)view{ + lv_addSubview(self, self.window, view); +} + +-(void) createWindow:(UIView *)window{ + self.window = window; + [LVExGlobalFunc registry:self.l window:self.window]; +} + +-(const char*) windowName{ + const char* name = [NSString stringWithFormat:@"core.window.%d",self.windowIdx].UTF8String; + return name; +} + +-(void) pushRenderTarget:(UIView *)window{ + [self pushWindow:window]; +} + +-(void) pushWindow:(UIView*) window{ + lua_State* L = self.l; + lua_checkstack(L,8); + + // 老的window 压栈 + const char* newWindowName = [self windowName]; + lua_getglobal(L, "window"); + lua_setglobal(L, newWindowName); + self.windowIdx ++; + + // 创建新的window + [self createWindow:window];//创建window +} + +-(void) popRenderTarget:(UIView *)window{ + [self popWindow:window]; +} + +-(void) popWindow:(UIView*) window{ + if( self.window==window ) { + lua_State* L = self.l; + lua_checkstack(L,8); + self.windowIdx --; + const char* oldWindowName = [self windowName]; + + // 出栈 + lua_getglobal(L, oldWindowName); + lua_setglobal(L, "window"); + lua_getglobal(L, "window"); + + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, -1); + if( user ) { + self.window = (__bridge UIView *)(user->object); + } + } else { + LVError(@"pop window!!!!"); + } +} + +-(void) luaviewGC { + // 清理luaview对应的内存 + lua_State *state = self.l; + if (state) { + lua_checkstack(state, 8); + lua_pushnil(state); + [LVUtil registryValue:state key:self stack:-1]; + LVBlock *block = [self getLuaBlock:@"System.gc"]; + [block callWithArgs:nil]; + } +} + + +@end + diff --git a/IOS/SDK/LuaViewSDK/Classes/PKG/LVPkgInfo.h b/IOS/SDK/LuaViewSDK/Classes/PKG/LVPkgInfo.h new file mode 100644 index 00000000..5cc53fd7 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/PKG/LVPkgInfo.h @@ -0,0 +1,46 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import + +#define LV_PKGINFO_URL @"url" +#define LV_PKGINFO_URL2 @"luaview_script_url" +#define LV_PKGINFO_SHA @"sha" +#define LV_PKGINFO_SHA256 @"sha256" + +#define LV_PKGINFO_SURL @"surl" +#define LV_PKGINFO_SSHA @"ssha" +#define LV_PKGINFO_SSHA256 @"ssha256" + +#define LV_PKGINFO_PACKAGE @"package" + +@interface LVPkgInfo : NSObject + +@property(nonatomic,copy) NSDictionary* originalDic; // 原始信息 + +@property(nonatomic,copy) NSString* url; // 下载地址 +@property(nonatomic,copy) NSString* sha256; // sha256 +@property(nonatomic,copy) NSString* timestamp; // 版本对比时间戳 +//@property(nonatomic,assign) BOOL changeGrammar; // 是否需要语法转换(‘:’和'.'互换) +@property(nonatomic,copy) NSString* package; // sha256 + +/* + * + * 解析字典 -> model + * + */ +-(instancetype) init:(NSDictionary*) dic; + +/* + * + * model -> 字典信息 + * + */ +- (NSDictionary*) dictionaryInfo; + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/PKG/LVPkgInfo.m b/IOS/SDK/LuaViewSDK/Classes/PKG/LVPkgInfo.m new file mode 100644 index 00000000..1efd3120 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/PKG/LVPkgInfo.m @@ -0,0 +1,94 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVPkgInfo.h" +#import "LVUtil.h" + +@implementation LVPkgInfo + +-(instancetype) init:(NSDictionary*) dic{ + self = [super init]; + if( self ) { + NSString* url = [LVPkgInfo safe_string:dic forKey:LV_PKGINFO_SURL]; + + if (!url){ + url = [LVPkgInfo safe_string:dic forKey:LV_PKGINFO_URL]; + } + NSString* sha = [LVPkgInfo safe_string:dic forKey:LV_PKGINFO_SSHA key2:LV_PKGINFO_SSHA256]; + + if (!sha){ + sha = [LVPkgInfo safe_string:dic forKey:LV_PKGINFO_SHA key2:LV_PKGINFO_SHA256]; + } + + if( url && sha ) { + self.url = url; + self.sha256 = sha; + } + + self.url = [self stringByDecodingURLFormat:self.url]; // 下载地址可能需要解码 + self.url = [self addHttpPrefix:self.url];// 下载地址可能需要加https前缀 + self.package = [LVPkgInfo safe_string:dic forKey:LV_PKGINFO_PACKAGE]; + if( self.package.length<=0 && self.url) { + self.package = [LVUtil MD5HashFromData:[self.url dataUsingEncoding:NSUTF8StringEncoding]]; + } + self.timestamp = self.url;//时间戳 用下载地址标示 + self.originalDic = dic; + } + return self; +} + +-(NSString*) addHttpPrefix:(NSString*) url{ + if( [url rangeOfString:@"://"].length>0 ){ + return url; + } + if( [url hasPrefix:@"//"] ) { + return [NSString stringWithFormat:@"https:%@",url]; + } + return url; +} + +- (NSString *)stringByDecodingURLFormat:(NSString*) str +{ + NSString *result = [str stringByReplacingOccurrencesOfString:@"+" withString:@" "]; + //result = [result stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; + result = [result stringByRemovingPercentEncoding]; + return result; +} + +- (NSDictionary*) dictionaryInfo{ + if( self.url && self.sha256 && self.package ) { + return @{LV_PKGINFO_SURL:self.url , + LV_PKGINFO_SSHA:self.sha256, + LV_PKGINFO_PACKAGE:self.package}; + } + return nil; +} + ++(NSString*) safe_string:(NSDictionary*) dic forKey:(NSString*) key { + return [self safe_string:dic forKey:key key2:nil]; +} + ++(NSString*) safe_string:(NSDictionary*) dic forKey:(NSString*) key1 key2:(NSString*) key2{ + if( [dic isKindOfClass:[NSDictionary class]] ) { + if( key1 ) { + NSString* s = dic[key1]; + if( [s isKindOfClass:[NSString class]] ) { + return s; + } + } + if( key2 ) { + NSString* s = dic[key2]; + if( [s isKindOfClass:[NSString class]] ) { + return s; + } + } + } + return nil; +} + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/PKG/LVPkgManager.h b/IOS/SDK/LuaViewSDK/Classes/PKG/LVPkgManager.h new file mode 100644 index 00000000..521e4e88 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/PKG/LVPkgManager.h @@ -0,0 +1,61 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVPkgInfo.h" + +#define LUAVIEW_ROOT_PATH @"LUAVIEW_5_11_0" +#define LUAVIEW_VERSION "5.16.0" +#define LUAVIEW_SDK_VERSION "0.5.3" + + +extern NSString * const LV_FILE_NAME_OF_PACKAGE_DOWNLOAD_URL; +extern NSString * const LV_FILE_NAME_OF_PACKAGE_TIMESTAMP; +extern NSString * const LV_FILE_NAME_OF_CHANGE_GRAMMAR; + +@class LVRSA; + +typedef enum : NSUInteger { + LV_DOWNLOAD_ERROR = -1, + LV_DOWNLOAD_CACHE = 0 , + LV_DOWNLOAD_NET = 1, +} LVDownloadDataType; + +typedef void(^LVDownloadCallback)(NSDictionary* info, NSString* error, LVDownloadDataType dataType); + +@interface LVPkgManager : NSObject + ++ (NSString *)rootDirectoryOfPackage:(NSString *)packageName; ++ (NSString *)pathForFileName:(NSString *)fileName package:(NSString *)packageName; + +// 解压失败是-1, 无需解压本地更加新是0, 解压成功是1 ++(int) unpackageFile:(NSString*) fileName packageName:(NSString*) packageName; ++(int) unpackageData:(NSData*) data packageName:(NSString*) packageName; + +// 返回值说明 0:本地和线上版本一样; 1:即将去下载; -1:错误 ++(NSInteger) downloadPackage:(NSString*)packageName withInfo:(NSDictionary*) info; +// 返回值说明 0:本地和线上版本一样; 1:即将去下载; -1:错误 ++(NSInteger) downloadPackage:(NSString*)packageName withInfo:(NSDictionary*) info callback:(LVDownloadCallback) callback; ++(NSInteger) unpackageData:(NSData*)data packageName:(NSString*)packageName withInfo:(LVPkgInfo*) info callback:(LVDownloadCallback) callback; + + ++(NSData*) readLuaFile:(NSString*) fileName rsa:(LVRSA*) rsa; +// download url ++(NSString*) downloadUrlOfPackage:(NSString*)packageName; ++(BOOL) setPackage:(NSString*)packageName downloadUrl:(NSString*) downloadUrl; +// timestamp ++(NSString*) timestampOfPackage:(NSString*)packageName; ++(BOOL) setPackage:(NSString*)packageName timestamp:(NSString*) time; + +// 返回值说明 0:本地和线上版本一样; -1:错误或者不相等 ++(int) compareDownloadUrlOfPackage:(NSString*)name withServerInfo:(NSDictionary*) info; + +//清理所有LuaView相关文件 ++(void) clearCachesPath; + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/PKG/LVPkgManager.m b/IOS/SDK/LuaViewSDK/Classes/PKG/LVPkgManager.m new file mode 100644 index 00000000..c05c9fb9 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/PKG/LVPkgManager.m @@ -0,0 +1,298 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVPkgManager.h" +#import "LVUtil.h" +#import "LVRSA.h" +#import "LVZipArchive.h" +#import "zlib.h" + +NSString * const LV_FILE_NAME_OF_PACKAGE_DOWNLOAD_URL = @"___download_url___"; +NSString * const LV_FILE_NAME_OF_PACKAGE_TIMESTAMP = @"___timestamp___"; + +@implementation LVPkgManager + ++ (NSString *)rootDirectoryOfPackage:(NSString *)packageName { + NSString *path = [NSString stringWithFormat:@"%@/%@",LUAVIEW_ROOT_PATH, packageName]; + return [LVUtil PathForCachesResource:path]; +} + ++ (NSString *)pathForFileName:(NSString *)fileName package:(NSString *)packageName { + return [[self rootDirectoryOfPackage:packageName] stringByAppendingPathComponent:fileName]; +} + +//------------------------------ write/read file for package --------------------------------- ++(BOOL) writeFile:(NSData*)data packageName:(NSString*)packageName fileName:(NSString*)fileName { + NSString* path = [self pathForFileName:fileName package:packageName]; + if( [LVUtil saveData:data toFile:path] ){ + LVLog (@"writeFile: %@, %d", fileName, (int)data.length); + return YES; + } else { + LVError(@"writeFile: %@, %d", fileName, (int)data.length); + return NO; + } +} + ++(NSData*) readFileFromPackage:(NSString*)packageName fileName:(NSString*)fileName { + NSString *path = [self pathForFileName:fileName package:packageName]; + NSData* data =[LVUtil dataReadFromFile:path]; + return data; +} + +//----------------------------------- timestamp path ----------------------------------------- ++(NSString*) filePathOfPackageDownloadUrl:(NSString *)packageName { + return [self pathForFileName:LV_FILE_NAME_OF_PACKAGE_DOWNLOAD_URL package:packageName]; +} ++(NSString*) filePathOfPackageTimestamp:(NSString *)packageName { + return [self pathForFileName:LV_FILE_NAME_OF_PACKAGE_TIMESTAMP package:packageName]; +} +//------------------------------------------------------------------------------------------ ++(BOOL) deleteFileOfPackageDownloadUrl:(NSString*) packageName{ + NSString* path = [self filePathOfPackageDownloadUrl:packageName]; + return [LVUtil deleteFile:path]; +} ++(BOOL) deleteFileOfPackageTimestamp:(NSString*) packageName{ + NSString* path = [self filePathOfPackageTimestamp:packageName]; + return [LVUtil deleteFile:path]; +} +//------------------------------------ read/write package download url ----------------------------------- ++(NSString*) downloadUrlOfPackage:(NSString*)packageName{ + NSData* data = [self readFileFromPackage:packageName fileName:LV_FILE_NAME_OF_PACKAGE_DOWNLOAD_URL]; + if( data ) { + return [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; + } else { + return nil; + } +} + ++(BOOL) setPackage:(NSString*)packageName downloadUrl:(NSString*) timestamp{ + NSData* data = [timestamp dataUsingEncoding:NSUTF8StringEncoding]; + return [self writeFile:data packageName:packageName fileName:LV_FILE_NAME_OF_PACKAGE_DOWNLOAD_URL]; +} +//------------------------------------ read/write package timestamp ----------------------------------- ++(NSString*) timestampOfPackage:(NSString*)packageName { + NSData* data = [self readFileFromPackage:packageName fileName:LV_FILE_NAME_OF_PACKAGE_TIMESTAMP]; + if( data ) { + return [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; + } else { + return nil; + } +} + ++(BOOL) setPackage:(NSString*)packageName timestamp:(NSString*) timestamp{ + // time file + NSData* data = [timestamp dataUsingEncoding:NSUTF8StringEncoding]; + return [self writeFile:data packageName:packageName fileName:LV_FILE_NAME_OF_PACKAGE_TIMESTAMP]; +} + + +//------------------------------------------------------------------------------------------ ++(int) unpackageFile:(NSString*) fileName packageName:(NSString*) packageName{ + NSString *path = [LVUtil PathForBundle:nil relativePath:fileName]; + + if( [LVUtil exist:path] ){ + NSData* pkgData = [LVUtil dataReadFromFile:path]; + return [self unpackageData:pkgData packageName:packageName]; + } + return -1; +} +// 根据时间戳,检查是否需要更新 ++(BOOL) checkUpdateWithNewTS:(NSString*)newTS oldTS:(NSString*) oldTS{ + return newTS.length>0 && oldTS.length>0 && [newTS compare:oldTS]==NSOrderedDescending; +} + ++(int) unpackageData:(NSData*) pkgData packageName:(NSString*) packageName{ + NSString *path = [self rootDirectoryOfPackage:packageName]; + if( pkgData && [LVUtil createPath:path] ){ + LVZipArchive *archive = [LVZipArchive archiveWithData:pkgData]; + + NSString* newTS = [archive timeIntervalStr]; + + NSString* oldTS = [self timestampOfPackage:packageName]; + // 首次下载 或者有 新的最新包 + if( (newTS && oldTS==nil) || [self checkUpdateWithNewTS:newTS oldTS:oldTS] ){ + BOOL result = [archive unzipToDirectory:path]; + if( result ) { + [self setPackage:packageName timestamp:newTS]; + return 1; + } + return -1; + } else { + LVLog(@" Not Need unpackage, %@, %@",packageName,newTS); + return 0; + } + } + return -1; +} + ++(NSString*) signfileNameOfOriginFile:(NSString*) fileName{ + return [NSString stringWithFormat:@"%@.sign",fileName]; +} + + ++(int) compareDownloadUrlOfPackage:(NSString*)packageName withServerInfo:(NSDictionary*) info{ + LVPkgInfo* pkgInfo = [[LVPkgInfo alloc] init:info]; + NSString* url1 = [self downloadUrlOfPackage:packageName]; + NSString* url2 = pkgInfo.url; + if( url1 && url2 && + [url1 isKindOfClass:[NSString class]] && [url2 isKindOfClass:[NSString class]] && + [url1 isEqualToString:url2] ){ + return 0; + } + return -1; +} + ++(NSInteger) downloadPackage:(NSString*)packageName withInfo:(NSDictionary*) info { + return [self downloadPackage:packageName withInfo:info callback:nil]; +} + ++(NSInteger) downloadPackage:(NSString*)packageName withInfo:(NSDictionary*) info callback:(LVDownloadCallback) callback{ + if( info ) { + if( [self compareDownloadUrlOfPackage:packageName withServerInfo:info] ){ + [self doDownloadPackage:packageName withInfo:info callback:callback]; + return LV_DOWNLOAD_NET; + } + + if (callback){ + callback(info, nil, LV_DOWNLOAD_CACHE); + } + return LV_DOWNLOAD_CACHE; + } + + if (callback){ + callback(info, nil, LV_DOWNLOAD_ERROR); + } + + return LV_DOWNLOAD_ERROR; +} + ++(BOOL) sha256Check:(NSData*) data ret:(NSString*) string{ + NSData* temp = lv_SHA256HashBytes(data); + const unsigned char* bytes = temp.bytes; + NSMutableString* buffer = [[NSMutableString alloc] init]; + for( int i=0; i0 && pkgInfo.url.length>0 && pkgInfo.timestamp.length>0){ + [LVUtil download:pkgInfo.url callback:^(NSData *data) { + // 解包过程放在主线程执行!!!! + dispatch_async(dispatch_get_main_queue(), ^{ + [weakSelf unpackageData:data packageName:pkgName withInfo:pkgInfo callback:callback]; + }); + }]; + } +} + ++(NSInteger) unpackageData:(NSData*)data packageName:(NSString*)pkgName withInfo:(LVPkgInfo*)pkgInfo callback:(LVDownloadCallback) callback{ + + if( data ){ + BOOL sha256OK = [self sha256Check:data ret:pkgInfo.sha256]; + if( sha256OK ){ + [self deleteFileOfPackageDownloadUrl:pkgName];// 开始解包, 删除时间戳文件 + + NSInteger result = [self unpackageData:data packageName:pkgName]; + if ( result >= 0 ) { + // 解包成功 + if( [self setPackage:pkgName downloadUrl:pkgInfo.url] && callback){// 写标记成功 + callback(pkgInfo.originalDic, nil, LV_DOWNLOAD_NET); + } + + return result; + } + } + } else { + LVError(@"[downloadPackage] error: url=%@",pkgInfo.url); + } + + callback(pkgInfo.originalDic, @"error", LV_DOWNLOAD_ERROR); + + return -1; +} + ++(NSData*) readLuaFile:(NSString*) fileName rsa:(LVRSA*)rsa{ + NSString* signfileName = [self signfileNameOfOriginFile:fileName]; + NSData* signData = [LVUtil dataReadFromFile:signfileName]; + NSData* encodedfileData = [LVUtil dataReadFromFile:fileName]; + // LVLog(@"%@",[[NSString alloc] initWithData:fileData encoding:NSUTF8StringEncoding]); + if( [rsa verifyData:encodedfileData withSignedData:signData] ){ + NSData* fileData = LV_AES256DecryptDataWithKey(encodedfileData, [rsa aesKeyBytes]); + NSData* unzipedData = [self gzipUnpack:fileData]; + return unzipedData; + } + return nil; +} + ++ (NSData *)gzipUnpack:(NSData*) data +{ + if ([data length] == 0) return data; + + NSInteger full_length = [data length]; + NSInteger half_length = [data length] / 2; + + NSMutableData *decompressed = [NSMutableData dataWithLength: full_length + half_length]; + BOOL done = NO; + int status; + + z_stream strm; + strm.next_in = (Bytef *)[data bytes]; + strm.avail_in = (unsigned int)[data length]; + strm.total_out = 0; + strm.zalloc = Z_NULL; + strm.zfree = Z_NULL; + + if (inflateInit2(&strm, (15+32)) != Z_OK) return nil; + while (!done){ + if (strm.total_out >= [decompressed length]) + [decompressed increaseLengthBy: half_length]; + strm.next_out = [decompressed mutableBytes] + strm.total_out; + strm.avail_out = (unsigned int)( [decompressed length] - strm.total_out ); + + // Inflate another chunk. + status = inflate (&strm, Z_SYNC_FLUSH); + if (status == Z_STREAM_END) done = YES; + else if (status != Z_OK) break; + } + if (inflateEnd (&strm) != Z_OK) return nil; + + // Set real length. + if (done){ + [decompressed setLength: strm.total_out]; + return [NSData dataWithData: decompressed]; + } + return nil; +} + ++(void) clearCachesPath { + NSFileManager *fileManager = [NSFileManager defaultManager]; + NSString* rootPath = [LVUtil PathForCachesResource:LUAVIEW_ROOT_PATH]; + if( rootPath ) { + NSArray *contents = [fileManager contentsOfDirectoryAtPath:rootPath error:NULL]; + NSEnumerator *e = [contents objectEnumerator]; + NSString *filename; + while ((filename = [e nextObject])) { + if( [fileManager removeItemAtPath:[rootPath stringByAppendingPathComponent:filename] error:NULL] ) { + LVLog ( @"delete File: %@", filename ); + } else { + LVError( @"delete File: %@", filename ); + } + } + } +} + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/PKG/LVZipArchive.h b/IOS/SDK/LuaViewSDK/Classes/PKG/LVZipArchive.h new file mode 100644 index 00000000..45de2974 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/PKG/LVZipArchive.h @@ -0,0 +1,39 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import + +@interface LVZipEntry : NSObject + +@property(nonatomic, readonly) NSString *fileName; + +@property(nonatomic, readonly, getter=isSymlink) BOOL symlink; +@property(nonatomic, readonly, getter=isDirectory) BOOL directory; +@property(nonatomic, readonly) NSInteger permissions; +@property(nonatomic, readonly) NSDate *lastModDate; + +@property(nonatomic, readonly) NSData *data; +@property(nonatomic, readonly) NSData *inflatedData; + +@end + +@interface LVZipArchive : NSObject + +@property(nonatomic, readonly) NSData *data; +@property(nonatomic, readonly) NSArray *entries; + ++ (LVZipArchive *)archiveWithData:(NSData *)data; ++ (BOOL)unzipData:(NSData *)data toDirectory:(NSString *)path; + +- (BOOL)unzipToDirectory:(NSString *)path; + +- (NSDate *)lastModDate; //修改日期 + +-(NSString*) timeIntervalStr; //时间戳 + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/PKG/LVZipArchive.m b/IOS/SDK/LuaViewSDK/Classes/PKG/LVZipArchive.m new file mode 100644 index 00000000..791ceb3a --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/PKG/LVZipArchive.m @@ -0,0 +1,538 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVZipArchive.h" +#import "LVUtil.h" +#import + +static const UInt32 kCDHeaderMagicNumber = 0x02014B50; +static const UInt32 kCDHeaderFixedDataLength = 46; + +static const UInt32 kCDTrailerMagicNumber = 0x06054B50; + +static const UInt32 kLFHeaderMagicNumber = 0x04034B50; +static const UInt32 kLFHeaderFixedDataLength = 30; + +struct LVZipBuffer { + void *bytes; + NSInteger size; + NSInteger offset; +}; + +static bool buffer_initWithData(struct LVZipBuffer *buffer, NSData *data, NSUInteger offset) { + buffer->bytes = (void *)data.bytes; + buffer->size = data.length; + buffer->offset = offset; + + return true; +} + +static UInt16 buffer_readInt16(struct LVZipBuffer *buffer) { + UInt16 result = CFSwapInt16LittleToHost(*(UInt16 *)(buffer->bytes + buffer->offset)); + buffer->offset += 2; + + return result; +} + +static UInt32 buffer_readInt32(struct LVZipBuffer *buffer) { + UInt32 result = CFSwapInt32LittleToHost(*(UInt32 *)(buffer->bytes + buffer->offset)); + buffer->offset += 4; + + return result; +} + +static void *buffer_position(struct LVZipBuffer *buffer) { + return (void *)buffer->bytes + buffer->offset; +} + +static bool buffer_skip(struct LVZipBuffer *buffer, NSInteger length) { + NSInteger offset = buffer->offset + length; + if (offset < 0 || offset >= buffer->size) { + return false; + } + + buffer->offset = offset; + + return true; +} + +static bool buffer_seekInt32(struct LVZipBuffer *buffer, UInt32 value) { + NSInteger offset = buffer->size - 4; + + while (offset > 0) { + UInt32 temp = CFSwapInt32LittleToHost(*(UInt32 *)(buffer->bytes + offset)); + if (temp == value) { + buffer->offset = offset; + return true; + } + offset--; + } + + return false; +} + +struct LVZipTrailer { + UInt32 magicNumber; + UInt16 diskNumber; + UInt16 diskNumberWithStart; + UInt16 numberOfEntries; + UInt16 totalNumberOfEntries; + UInt32 sizeOfEntries; + UInt32 startOfEntries; + UInt16 commentLength; + char *comment; +}; + +static bool trailer_initWithData(struct LVZipTrailer *trailer, NSData *data) { + UInt32 trailerCheck = 0; + struct LVZipBuffer buffer = {0}; + buffer_initWithData(&buffer, data, [data length] - sizeof(trailerCheck)); + if (!buffer_seekInt32(&buffer, kCDTrailerMagicNumber)) { + return false; + } + if (buffer.offset < 1) { + return false; + } + + UInt32 mn = buffer_readInt32(&buffer); + assert(mn == kCDTrailerMagicNumber); + + trailer->magicNumber = mn; + trailer->diskNumber = buffer_readInt16(&buffer); + trailer->diskNumberWithStart = buffer_readInt16(&buffer); + trailer->numberOfEntries = buffer_readInt16(&buffer); + trailer->totalNumberOfEntries = buffer_readInt16(&buffer); + trailer->sizeOfEntries = buffer_readInt32(&buffer); + trailer->startOfEntries = buffer_readInt32(&buffer); + trailer->commentLength = buffer_readInt16(&buffer); + if (trailer->commentLength) { + trailer->comment = (char *)buffer_position(&buffer); + } + + return true; +} + +struct LVZipCDHeader { + UInt32 magicNumber; + UInt16 versionMadeBy; + UInt16 versionNeededToExtract; + UInt16 generalPurposeBitFlag; + UInt16 compressionMethod; + UInt32 lastModDate; + UInt32 crc; + UInt16 filenameLength; + UInt16 extraFieldLength; + UInt16 commentLength; + UInt16 diskNumberStart; + UInt16 internalFileAttributes; + UInt32 externalFileAttributes; + UInt64 localHeaderOffset; + + UInt64 compressedSize; + UInt64 uncompressedSize; + + char *filename; + void *extraField; + char *comment; + void *cachedData; +}; + +static bool cdheader_initWithData(struct LVZipCDHeader *header, void *start) { + struct LVZipBuffer buffer = { start, NSUIntegerMax, 0 }; + + UInt32 mn = buffer_readInt32(&buffer); + assert(mn == kCDHeaderMagicNumber); + + header->magicNumber = mn; + header->versionMadeBy = buffer_readInt16(&buffer); + header->versionNeededToExtract = buffer_readInt16(&buffer); + header->generalPurposeBitFlag = buffer_readInt16(&buffer); + header->compressionMethod = buffer_readInt16(&buffer); + header->lastModDate = buffer_readInt32(&buffer); + header->crc = buffer_readInt32(&buffer); + header->compressedSize = buffer_readInt32(&buffer); + header->uncompressedSize = buffer_readInt32(&buffer); + header->filenameLength = buffer_readInt16(&buffer); + header->extraFieldLength = buffer_readInt16(&buffer); + header->commentLength = buffer_readInt16(&buffer); + header->diskNumberStart = buffer_readInt16(&buffer); + header->internalFileAttributes = buffer_readInt16(&buffer); + header->externalFileAttributes = buffer_readInt32(&buffer); + header->localHeaderOffset = buffer_readInt32(&buffer); + + if (header->filenameLength) { + header->filename = (char *)buffer_position(&buffer); + buffer_skip(&buffer, header->filenameLength); + } + if (header->extraFieldLength) { + header->extraField = buffer_position(&buffer); + buffer_skip(&buffer, header->extraFieldLength); + } + if (header->commentLength) { + header->comment = (char *)buffer_position(&buffer); + } + + return true; +} + +static NSString *cdheader_getFileName(struct LVZipCDHeader *header) { + if (header->filenameLength == 0) { + return nil; + } + + NSData *data = [NSData dataWithBytes:header->filename length:header->filenameLength]; + NSString *name = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; + return name; +} + +static NSUInteger cdheader_getLength(struct LVZipCDHeader *header) { + return kCDHeaderFixedDataLength + + header->filenameLength + + header->commentLength + + header->extraFieldLength; +} + +static NSInteger cdheader_getPermissions(struct LVZipCDHeader *header) { + return (header->externalFileAttributes >> 16 & 0x1FF) ?: 0755U; +} + +static NSDate *cdheader_getLastModDate(struct LVZipCDHeader *header) { + // convert dos time + UInt32 dtime = header->lastModDate; + + NSDateComponents *comps = [NSDateComponents new]; + comps.year = (int)(((dtime >> 25) & 0x7f) + 1980); + comps.month = (int)((dtime >> 21) & 0x0f); + comps.day = (int)((dtime >> 16) & 0x1f); + comps.hour = (int)((dtime >> 11) & 0x1f); + comps.minute = (int)((dtime >> 5) & 0x3f); + comps.second = (int)((dtime << 1) & 0x3e); + + return [[NSCalendar currentCalendar] dateFromComponents:comps]; +} + +static NSInteger cdheader_getFileType(struct LVZipCDHeader *header) { + return header->externalFileAttributes >> 29 & 0x1F; +} + +static bool cdheader_isDirecotry(struct LVZipCDHeader *header) { + return cdheader_getFileType(header) == 0x02; +} + +static bool cdheader_isSymlink(struct LVZipCDHeader *header) { + return cdheader_getFileType(header) == 0x05; +} + +struct LVZipLFHeader { + UInt32 magicNumber; + UInt32 versionNeededToExtract; + UInt32 generalPurposeBitFlag; + UInt32 compressionMethod; + UInt32 lastModDate; + UInt32 crc; + UInt64 compressedSize; + UInt64 uncompressedSize; + UInt32 filenameLength; + UInt32 extraFieldLength; + char *filename; + void *extraField; +}; + +static bool lfheader_initWithData(struct LVZipLFHeader *header, void *start) { + struct LVZipBuffer buffer = { start, NSUIntegerMax, 0 }; + + UInt32 mn = buffer_readInt32(&buffer); + assert(mn == kLFHeaderMagicNumber); + + header->magicNumber = mn; + header->versionNeededToExtract = buffer_readInt16(&buffer); + header->generalPurposeBitFlag = buffer_readInt16(&buffer); + header->compressionMethod = buffer_readInt16(&buffer); + header->lastModDate = buffer_readInt32(&buffer); + header->crc = buffer_readInt32(&buffer); + header->compressedSize = buffer_readInt32(&buffer); + header->uncompressedSize = buffer_readInt32(&buffer); + header->filenameLength = buffer_readInt16(&buffer); + header->extraFieldLength = buffer_readInt16(&buffer); + + if (header->filenameLength > 0) { + header->filename = (char *)buffer_position(&buffer); + buffer_skip(&buffer, header->filenameLength); + } + if (header->extraFieldLength > 0) { + header->extraField = (char *)buffer_position(&buffer); + } + + return true; +} + +static NSUInteger lfheader_getLength(struct LVZipLFHeader *header) { + return kLFHeaderFixedDataLength + + header->filenameLength + + header->extraFieldLength; +} + +@interface LVZipArchive () + +@property(nonatomic, strong) NSData *data; +@property(nonatomic, strong) NSArray *entries; + +@end + +@interface LVZipEntry () + +@property(nonatomic, assign) struct LVZipCDHeader internalHeader; +@property(nonatomic, strong) NSData *data; + +@end + +@implementation LVZipArchive + ++ (LVZipArchive *)archiveWithData:(NSData *)data { + struct LVZipTrailer trailer = {0}; + if (!trailer_initWithData(&trailer, data)) { + return nil; + } + + LVZipArchive *archive = [self new]; + archive.data = data; + + NSMutableArray *entries = [NSMutableArray array]; + struct LVZipCDHeader header = {0}; + LVZipEntry *entry = nil; + unsigned long long offset = trailer.startOfEntries; + for (NSUInteger i = 0; i < trailer.totalNumberOfEntries; i++) { + if (cdheader_initWithData(&header, (void *)(data.bytes + offset))) { + entry = [LVZipEntry new]; + entry.internalHeader = header; + [archive fillContentOfEntry:entry]; + [entries addObject:entry]; + + offset += cdheader_getLength(&header); + } else { + break; + } + } + + archive.entries = entries; + + return archive; +} + +- (NSDate *) lastModDate { + NSDate* date0 = self.entries.firstObject.lastModDate; + for( LVZipEntry * entry in self.entries ){ + NSDate* date2 = entry.lastModDate; + if( [date2 timeIntervalSinceDate:date0]>0 ) { + date0 = date2; + } + } + return date0; +} + +- (NSString*) timeIntervalStr{ + NSDate* date = [self lastModDate]; + long long s = (long long)( [date timeIntervalSince1970] ); + NSString *timeStr = [NSString stringWithFormat:@"%lld", s]; + return timeStr; +} + ++ (BOOL)unzipData:(NSData *)data toDirectory:(NSString *)path { + LVZipArchive *archive = [self archiveWithData:data]; + return [archive unzipToDirectory:path]; +} + +- (BOOL)unzipToDirectory:(NSString *)path { + if (path == nil) { + return NO; + } + + NSFileManager *fm = [NSFileManager defaultManager]; + if (![fm createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:NULL]) { + LVLog(@"create directory(%@) error!", path); + return NO; + } + + NSDictionary *attrs = nil; + NSData *inflatedData = nil; + NSString *fileName = nil, *fullPath = nil; + NSError *error = nil; + for (LVZipEntry *entry in self.entries) { + error = nil; + attrs = [self attributes:entry]; + inflatedData = entry.inflatedData; + fileName = entry.fileName; + fullPath = [path stringByAppendingPathComponent:fileName]; + + if ([entry isDirectory]) { + BOOL r = [fm createDirectoryAtPath:fullPath + withIntermediateDirectories:YES + attributes:attrs + error:&error]; + if (!r) { + LVLog(@"create directory(%@) entry error:", fileName, error); + return NO; + } + } else if ([entry isSymlink]) { + NSString *dest = [[NSString alloc] initWithData:inflatedData + encoding:NSUTF8StringEncoding]; + BOOL r = [fm createSymbolicLinkAtPath:fullPath + withDestinationPath:dest + error:&error]; + if (!r) { + LVLog(@"create symlink(%@) entry error:", fileName, error); + return NO; + } + [fm setAttributes:attrs ofItemAtPath:fullPath error:NULL]; + } else { + NSString *dir = [fileName stringByDeletingLastPathComponent]; + if ([dir length] > 0) { + NSString *fullDirPath = [path stringByAppendingPathComponent:dir]; + BOOL isDir = NO, r = NO; + if (![fm fileExistsAtPath:fullDirPath isDirectory:&isDir]) { + r = [fm createDirectoryAtPath:fullDirPath + withIntermediateDirectories:YES + attributes:nil + error:&error]; + if (!r) { + LVLog(@"create file(%@)'s parent directory error:%@", fileName, error); + return NO; + } + } else if (!isDir) { + r = [fm removeItemAtPath:fullDirPath error:&error]; + if (!r) { + LVLog(@"remove exist file(%@) error:%@", dir, error); + return NO; + } + r = [fm createDirectoryAtPath:fullDirPath + withIntermediateDirectories:YES + attributes:nil + error:NULL]; + if (!r) { + LVLog(@"create file(%@)'s parent directory error:%@", fileName, error); + return NO; + } + } + } + + BOOL r = [fm createFileAtPath:fullPath contents:inflatedData attributes:attrs]; + if (!r) { + LVLog(@"create file(%@) entry error", fileName); + return NO; + } + } + } + + return YES; +} + +- (void)fillContentOfEntry:(LVZipEntry *)entry { + if ([entry isDirectory]) { + return; + } + + struct LVZipLFHeader lfHeader = {0}; + void *start = (void *)(self.data.bytes + entry.internalHeader.localHeaderOffset); + if (!lfheader_initWithData(&lfHeader, start)) { + return; + } + + NSUInteger location = (NSUInteger)entry.internalHeader.localHeaderOffset + lfheader_getLength(&lfHeader); + NSUInteger length = (NSUInteger)entry.internalHeader.compressedSize; + entry.data = [self.data subdataWithRange:NSMakeRange(location, length)]; +} + +- (NSDictionary *)attributes:(LVZipEntry *)entry { + if ([entry isDirectory] || [entry isSymlink]) { + return nil; + } + + return @{ NSFilePosixPermissions: @([entry permissions]), + NSFileCreationDate: [entry lastModDate], + NSFileModificationDate: [entry lastModDate] }; +} + +@end + +@implementation LVZipEntry + +@synthesize inflatedData = _inflatedData; +@dynamic fileName, symlink, directory, permissions, lastModDate; + +- (NSString *)fileName { + return cdheader_getFileName(&_internalHeader); +} + +- (NSInteger)permissions { + return cdheader_getPermissions(&_internalHeader); +} + +- (BOOL)isDirectory { + return cdheader_isDirecotry(&_internalHeader) || [[self fileName] hasSuffix:@"/"]; +} + +- (BOOL)isSymlink { + return cdheader_isSymlink(&_internalHeader); +} + +- (NSDate *)lastModDate { + return cdheader_getLastModDate(&_internalHeader); +} + +- (NSData *)inflatedData { + if (_inflatedData) { + return _inflatedData; + } + + if (!_data) { + return nil; + } + + if (_internalHeader.compressionMethod == Z_NO_COMPRESSION || [self isSymlink]) { + _inflatedData = _data; + } else { + _inflatedData = [self inflateData:_data]; + } + + return _inflatedData; +} + +- (NSData *) inflateData:(NSData *)data { + NSUInteger length = [data length]; + NSUInteger halfLength = length / 2; + + NSMutableData *inflatedData = [NSMutableData dataWithLength:length + halfLength]; + BOOL done = NO; + int status; + + z_stream strm; + + strm.next_in = (Bytef *)data.bytes; + strm.avail_in = (unsigned int)[data length]; + strm.total_out = 0; + strm.zalloc = Z_NULL; + strm.zfree = Z_NULL; + + if (inflateInit2(&strm, -MAX_WBITS) != Z_OK) return nil; + while (!done) { + if (strm.total_out >= [inflatedData length]) + [inflatedData increaseLengthBy:halfLength]; + strm.next_out = [inflatedData mutableBytes] + strm.total_out; + strm.avail_out = (unsigned int)([inflatedData length] - strm.total_out); + status = inflate(&strm, Z_SYNC_FLUSH); + if (status == Z_STREAM_END) done = YES; + else if (status != Z_OK) break; + } + if (inflateEnd(&strm) == Z_OK && done) + [inflatedData setLength:strm.total_out]; + else + inflatedData = nil; + return inflatedData; +} + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/RSA/LVRSA.h b/IOS/SDK/LuaViewSDK/Classes/RSA/LVRSA.h new file mode 100644 index 00000000..2806d47c --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/RSA/LVRSA.h @@ -0,0 +1,24 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import + +@interface LVRSA : NSObject + +-(BOOL) verifyData:(NSData*)data withSignedData:(NSData*) sign; + +-(NSData*) aesKeyBytes; + +/* + * 设置证书名 + */ +- (void) setPublicKeyFilePath:(NSString*) filePath; + +NSData* lv_SHA256HashBytes(NSData *fileData); + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/RSA/LVRSA.m b/IOS/SDK/LuaViewSDK/Classes/RSA/LVRSA.m new file mode 100644 index 00000000..5852c768 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/RSA/LVRSA.m @@ -0,0 +1,252 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVRSA.h" +#import +#import +#import +#import +#import +#import "LVUtil.h" + +@implementation LVRSA { + NSData* g_keyBytes; + SecKeyRef g_publicKey; + NSString* g_publicKeyFilePath; +} + +-(void) dealloc{ + LVReleaseAndNull(g_publicKey); +} + +NSError* lv_verifySignSHA1WithRSA(NSData *fileData, SecKeyRef pubKeyRef, NSData *signedData); + +-(BOOL) verifyData:(NSData*)data withSignedData:(NSData*) signedData{ + SecKeyRef key = [self getPublicKey]; + NSError* error = lv_verifySignSHA1WithRSA(data, key, signedData); + if( error == nil ){ + return YES; + } + LVLog(@"%@",error); + return NO; +} + +-(NSData*) aesKeyBytes{ + if( g_keyBytes==nil ) { + NSData *certificateData = [self publickKeyData]; + g_keyBytes = [LVUtil MD5HashDataFromData:certificateData]; + } + return g_keyBytes; +} + +//公共秘钥的引用: +- (SecKeyRef)getPublicKey{ + if( g_publicKey == NULL ){ + g_publicKey = [self getPublicKey0]; + } + return g_publicKey; +} + +- (void) setPublicKeyFilePath:(NSString*) filePath{ + g_publicKeyFilePath = filePath; +} + +-(NSData*) publickKeyData{ + if( g_publicKeyFilePath==nil ) + g_publicKeyFilePath = [[NSBundle mainBundle] pathForResource:@"public_key" ofType:@"der"]; + + NSData *certificateData = [NSData dataWithContentsOfFile:g_publicKeyFilePath]; + return certificateData; +} + +- (SecKeyRef)getPublicKey0 +{ + NSData *certificateData = [self publickKeyData]; + if ( certificateData==nil ){ + return NULL; + } + SecCertificateRef myCertificate = NULL; + myCertificate = SecCertificateCreateWithData(kCFAllocatorDefault, (__bridge CFDataRef)certificateData); + SecPolicyRef myPolicy = SecPolicyCreateBasicX509(); + SecTrustRef myTrust = NULL; + OSStatus status = SecTrustCreateWithCertificates(myCertificate,myPolicy,&myTrust); + SecTrustResultType trustResult; + if (status == noErr) { + status = SecTrustEvaluate(myTrust, &trustResult); + if( status == noErr ){ + LVReleaseAndNull(myPolicy); + LVReleaseAndNull(myCertificate); + SecKeyRef ret = SecTrustCopyPublicKey(myTrust); + LVReleaseAndNull(myTrust); + return ret; + } + } + LVReleaseAndNull(myPolicy); + LVReleaseAndNull(myCertificate); + return NULL; +} + +//加密: +- (NSData*)rsaEncryptWithData:(NSData*)data usingKey:(SecKeyRef)key{ + + size_t cipherBufferSize = SecKeyGetBlockSize(key); + uint8_t *cipherBuffer = malloc(cipherBufferSize * sizeof(uint8_t)); + memset((void *)cipherBuffer, 0*0, cipherBufferSize); + + NSData *plainTextBytes = data; + size_t blockSize = cipherBufferSize - 11; + size_t blockCount = (size_t)ceil([plainTextBytes length] / (double)blockSize); + NSMutableData *encryptedData = [NSMutableData dataWithCapacity:0]; + + for (int i=0; i0 && key.length>0 ) { + NSUInteger dataLength = [data length]; + + // See the doc: For block ciphers, the output size will always be less than or + // equal to the input size plus the size of one block. + // That's why we need to add the size of one block here + size_t bufferSize = (dataLength + kCCKeySizeAES256); + void *buffer = malloc(bufferSize); + bzero(buffer, sizeof(bufferSize)); + + size_t numBytesDecrypted = 0; + CCCryptorStatus cryptStatus = CCCrypt(kCCDecrypt, kCCAlgorithmAES128, kCCOptionPKCS7Padding, + key.bytes, key.length, + NULL /* initialization vector (optional) */, + [data bytes], dataLength, /* input */ + buffer, bufferSize, /* output */ + &numBytesDecrypted); + + if ( cryptStatus == kCCSuccess ) { + return [NSData dataWithBytesNoCopy:buffer length:numBytesDecrypted]; + } + + free(buffer); //free the buffer; + return nil; + } + return nil; +} + +#define kChosenDigestLength CC_SHA1_DIGEST_LENGTH // SHA-1消息摘要的数据位数160位 +NSData* lv_SHA1HashBytes(NSData *fileData){ + CC_SHA1_CTX ctx; + uint8_t * hashBytes = NULL; + NSData * hash = nil; + + // Malloc a buffer to hold hash. + hashBytes = malloc( kChosenDigestLength * sizeof(uint8_t) ); + memset((void *)hashBytes, 0x0, kChosenDigestLength); + // Initialize the context. + CC_SHA1_Init(&ctx); + // Perform the hash. + CC_SHA1_Update(&ctx, (void *)[fileData bytes], (CC_LONG)[fileData length]); + // Finalize the output. + CC_SHA1_Final(hashBytes, &ctx); + + // Build up the SHA1 blob. + hash = [NSData dataWithBytes:(const void *)hashBytes length:(NSUInteger)kChosenDigestLength]; + if (hashBytes) free(hashBytes); + + return hash; +} + + +NSData* lv_SHA256HashBytes(NSData *fileData){ + CC_SHA256_CTX ctx; + uint8_t * hashBytes = NULL; + NSData * hash = nil; + + // Malloc a buffer to hold hash. + hashBytes = malloc( CC_SHA256_DIGEST_LENGTH * sizeof(uint8_t) ); + memset((void *)hashBytes, 0x0, CC_SHA256_DIGEST_LENGTH); + // Initialize the context. + CC_SHA256_Init(&ctx); + // Perform the hash. + CC_SHA256_Update(&ctx, (void *)[fileData bytes], (CC_LONG)[fileData length]); + // Finalize the output. + CC_SHA256_Final(hashBytes, &ctx); + + // Build up the SHA256 blob. + hash = [NSData dataWithBytes:(const void *)hashBytes length:(NSUInteger)CC_SHA256_DIGEST_LENGTH]; + if ( hashBytes ) { + free(hashBytes); + } + return hash; +} + +NSError* lv_verifySignSHA1WithRSA(NSData *fileData, SecKeyRef pubKeyRef, NSData *signedData){ + if(!fileData || !pubKeyRef || !signedData){ + return [NSError errorWithDomain:@"" code:-1 userInfo:@{@"desc":[NSString stringWithFormat:@"input error fileData=%p pubKeyRef=%p signedData=%p", fileData, pubKeyRef, signedData]}]; + } + OSStatus sanityCheck = noErr; + + NSData *hash = lv_SHA1HashBytes(fileData); + size_t signedHashBytesSize = SecKeyGetBlockSize(pubKeyRef); + //kSecPaddingPKCS1SHA1 kSecPaddingPKCS1MD5 + sanityCheck = SecKeyRawVerify(pubKeyRef, kSecPaddingPKCS1SHA1, [hash bytes], kChosenDigestLength, [signedData bytes], signedHashBytesSize); + + // NS Log(@"data=%@\n hash=%@\n signed=%@", fileData, hash, signedData); + if (sanityCheck == noErr){ + return nil; + }else{ + return [NSError errorWithDomain:@"" code:sanityCheck userInfo:@{@"desc":[NSString stringWithFormat:@"verifySign failed OSStatus=%d", (int)sanityCheck]}]; + } +} + +@end + + + diff --git a/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXCSSParser.h b/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXCSSParser.h new file mode 100644 index 00000000..3970828e --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXCSSParser.h @@ -0,0 +1,77 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import + +@class JUFLXNode; +@interface JUFLXCSSParser : NSObject + ++ (void)parseInlineCSS:(NSString *)inlineCSS toNode:(JUFLXNode *)node; + +@end + + +/* + * --------------------------------------------------------------------------- + * The valid css value + * --------------------------------------------------------------------------- + */ +/* +NSString * const kHRCSSPosition = @"position"; +NSString * const kHRCSSPositionAbsolute = @"absolute"; +NSString * const kHRCSSPositionTop = @"top"; +NSString * const kHRCSSPositionLeft = @"left"; +NSString * const kHRCSSPositionBottom = @"bottom"; +NSString * const kHRCSSPositionRight = @"right"; + +NSString * const kHRCSSDirection = @"flex-direction"; +NSString * const kHRCSSDirectionRow = @"row"; +NSString * const kHRCSSDirectionRowReverse = @"row-reverse"; +NSString * const kHRCSSDirectionColumn = @"column"; +NSString * const kHRCSSDirectionColumnReverse = @"column-reverse"; + +NSString * const kHRCSSAlignItems = @"align-items"; +NSString * const kHRCSSAlignContent = @"align-content"; +NSString * const kHRCSSAlignSelf = @"align-self"; +NSString * const kHRCSSAlignAuto = @"auto"; +NSString * const kHRCSSAlignStart = @"flex-start"; +NSString * const kHRCSSAlignCenter = @"center"; +NSString * const kHRCSSAlignEnd = @"flex-end"; +NSString * const kHRCSSAlignStretch = @"stretch"; + +NSString * const kHRCSSJustification = @"justify-content"; +NSString * const kHRCSSJustificationStart = @"flex-start"; +NSString * const kHRCSSJustificationCenter = @"center"; +NSString * const kHRCSSJustificationEnd = @"flex-end"; +NSString * const kHRCSSJustificationBetween = @"space-between"; +NSString * const kHRCSSJustificationAround = @"space-around"; + +NSString * const kHRCSSFlex = @"flex"; +NSString * const kHRCSSFlexWrap = @"flex-wrap"; + +NSString * const kHRCSSDimensionWidth = @"width"; +NSString * const kHRCSSDimensionHeight = @"height"; + +NSString * const kHRCSSMinDimensionWidth = @"min-width"; +NSString * const kHRCSSMinDimensionHeight = @"min-height"; + +NSString * const kHRCSSMaxDimensionWidth = @"max-width"; +NSString * const kHRCSSMaxDimensionHeight = @"max-height"; + +NSString * const kHRCSSMargin = @"margin"; +NSString * const kHRCSSMarginLeft = @"margin-left"; +NSString * const kHRCSSMarginTop = @"margin-top"; +NSString * const kHRCSSMarginBottom = @"margin-bottom"; +NSString * const kHRCSSMarginRight = @"margin-right"; + +NSString * const kHRCSSPadding = @"padding"; +NSString * const kHRCSSPaddingLeft = @"padding-left"; +NSString * const kHRCSSPaddingTop = @"padding-top"; +NSString * const kHRCSSPaddingBottom = @"padding-bottom"; +NSString * const kHRCSSPaddingRight = @"padding-right"; +*/ diff --git a/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXCSSParser.m b/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXCSSParser.m new file mode 100644 index 00000000..3d0e663d --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXCSSParser.m @@ -0,0 +1,326 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ +#import "JUFLXCSSParser.h" +#import "JUFLXNode.h" + +static inline BOOL isValidFloatString(NSString *floatString) { + BOOL valid = NO; + if (floatString && [floatString isKindOfClass:[NSString class]]) { + CGFloat fv = [floatString floatValue]; + valid = fv != NSNotFound; + } + + return valid; +} + +static inline CGFloat getFloatFromString(NSString *string, CGFloat defaultValue) { + CGFloat result = defaultValue; + if (isValidFloatString(string)) { + result = [string floatValue]; + } + + return result; +} + +NSString * const kHRCSSPosition = @"position"; +NSString * const kHRCSSPositionAbsolute = @"absolute"; +NSString * const kHRCSSPositionTop = @"top"; +NSString * const kHRCSSPositionLeft = @"left"; +NSString * const kHRCSSPositionBottom = @"bottom"; +NSString * const kHRCSSPositionRight = @"right"; + +NSString * const kHRCSSDirection = @"flex-direction"; +NSString * const kHRCSSDirectionRow = @"row"; +NSString * const kHRCSSDirectionRowReverse = @"row-reverse"; +NSString * const kHRCSSDirectionColumn = @"column"; +NSString * const kHRCSSDirectionColumnReverse = @"column-reverse"; + +NSString * const kHRCSSAlignItems = @"align-items"; +NSString * const kHRCSSAlignContent = @"align-content"; +NSString * const kHRCSSAlignSelf = @"align-self"; +NSString * const kHRCSSAlignAuto = @"auto"; +NSString * const kHRCSSAlignStart = @"flex-start"; +NSString * const kHRCSSAlignCenter = @"center"; +NSString * const kHRCSSAlignEnd = @"flex-end"; +NSString * const kHRCSSAlignStretch = @"stretch"; + +NSString * const kHRCSSjustifyContent = @"justify-content"; +NSString * const kHRCSSjustifyContentStart = @"flex-start"; +NSString * const kHRCSSjustifyContentCenter = @"center"; +NSString * const kHRCSSjustifyContentEnd = @"flex-end"; +NSString * const kHRCSSjustifyContentBetween = @"space-between"; +NSString * const kHRCSSjustifyContentAround = @"space-around"; + +NSString * const kHRCSSFlex = @"flex"; +NSString * const kHRCSSFlexWrap = @"flex-wrap"; + +NSString * const kHRCSSDimensionSize = @"size"; +NSString * const kHRCSSDimensionWidth = @"width"; +NSString * const kHRCSSDimensionHeight = @"height"; + +NSString * const kHRCSSMinDimensionWidth = @"min-width"; +NSString * const kHRCSSMinDimensionHeight = @"min-height"; + +NSString * const kHRCSSMaxDimensionWidth = @"max-width"; +NSString * const kHRCSSMaxDimensionHeight = @"max-height"; + +NSString * const kHRCSSMargin = @"margin"; +NSString * const kHRCSSMarginLeft = @"margin-left"; +NSString * const kHRCSSMarginTop = @"margin-top"; +NSString * const kHRCSSMarginBottom = @"margin-bottom"; +NSString * const kHRCSSMarginRight = @"margin-right"; + +NSString * const kHRCSSPadding = @"padding"; +NSString * const kHRCSSPaddingLeft = @"padding-left"; +NSString * const kHRCSSPaddingTop = @"padding-top"; +NSString * const kHRCSSPaddingBottom = @"padding-bottom"; +NSString * const kHRCSSPaddingRight = @"padding-right"; + +NSString * const kHRCSSSizeToFit = @"sizetofit"; + +@implementation JUFLXCSSParser + +/** + * Stand is @"diretion:row;alignitems:auto;justifyContent:start" + */ ++ (NSDictionary *)transferInlineCSS:(NSString *)inlineCSS { + if ([inlineCSS hasPrefix:@"{"]) inlineCSS = [inlineCSS substringFromIndex:1]; + if ([inlineCSS hasSuffix:@"}"]) inlineCSS = [inlineCSS substringToIndex:inlineCSS.length - 1]; + + + NSArray *inlineArray = [inlineCSS componentsSeparatedByString:@","]; + if (inlineArray.count == 0) { + if (inlineCSS.length > 0) { + NSLog(@"===>JUFLXNode inlineCSS string maybe be wrong, check it %@", inlineCSS); + return nil; + } + }; + + NSMutableDictionary *result = [NSMutableDictionary dictionary]; + NSCharacterSet *whiteAndNewLine = [NSCharacterSet whitespaceAndNewlineCharacterSet]; + + for (NSString *kv in inlineArray) { + NSArray *kvArray = [kv componentsSeparatedByString:@":"]; + if (kvArray.count == 2) { + NSString *key = kvArray[0]; + NSString *value = kvArray[1]; + if ([key isKindOfClass:[NSString class]] + && key.length > 0 + && [value isKindOfClass:[NSString class]] + && value.length > 0) { + + key = [[key stringByTrimmingCharactersInSet:whiteAndNewLine] lowercaseString]; + value = [[value stringByTrimmingCharactersInSet:whiteAndNewLine] lowercaseString]; + result[key] = value; + } + } + } + + return result; +} + ++ (NSSet *)validInlineCssKeys { + static dispatch_once_t onceToken; + static NSSet *set; + dispatch_once(&onceToken, ^{ + set = [NSSet setWithObjects: + kHRCSSPosition, + kHRCSSPositionTop, + kHRCSSPositionLeft, + kHRCSSPositionBottom, + kHRCSSPositionRight, + kHRCSSDirection, + kHRCSSAlignItems, + kHRCSSAlignContent, + kHRCSSjustifyContent, + kHRCSSFlexWrap, + kHRCSSAlignSelf, + kHRCSSFlex, + kHRCSSDimensionSize, + kHRCSSDimensionWidth, + kHRCSSDimensionHeight, + kHRCSSMinDimensionWidth, + kHRCSSMinDimensionHeight, + kHRCSSMaxDimensionWidth, + kHRCSSMaxDimensionHeight, + kHRCSSMargin, + kHRCSSMarginTop, + kHRCSSMarginLeft, + kHRCSSMarginBottom, + kHRCSSMarginRight, + kHRCSSPadding, + kHRCSSPaddingTop, + kHRCSSPaddingLeft, + kHRCSSPaddingBottom, + kHRCSSPaddingRight, + kHRCSSSizeToFit, + nil]; + }); + return set; + +} + ++ (NSDictionary *)validDirections { + static dispatch_once_t onceToken; + static NSDictionary *dic; + dispatch_once(&onceToken, ^{ + dic = @{kHRCSSDirectionColumn : @(JUFLXLayoutDirectionColumn), + kHRCSSDirectionRow : @(JUFLXLayoutDirectionRow), + kHRCSSDirectionRowReverse : @(JUFLXLayoutDirectionRowReverse), + kHRCSSDirectionColumnReverse : @(JUFLXLayoutDirectionColumnReverse)}; + }); + return dic; +} + ++ (NSDictionary *)validAlignments { + static dispatch_once_t onceToken; + static NSDictionary *dic; + dispatch_once(&onceToken, ^{ + dic = @{kHRCSSAlignAuto : @(JUFLXLayoutAlignmentAuto), + kHRCSSAlignStart : @(JUFLXLayoutAlignmentStart), + kHRCSSAlignCenter : @(JUFLXLayoutAlignmentCenter), + kHRCSSAlignEnd : @(JUFLXLayoutAlignmentEnd), + kHRCSSAlignStretch : @(JUFLXLayoutAlignmentStretch)}; + }); + return dic; +} + ++ (NSDictionary *)validjustifyContents { + static dispatch_once_t onceToken; + static NSDictionary *dic; + dispatch_once(&onceToken, ^{ + dic = @{kHRCSSjustifyContentStart : @(JUFLXLayoutJustifyContentStart), + kHRCSSjustifyContentCenter : @(JUFLXLayoutJustifyContentCenter), + kHRCSSjustifyContentEnd : @(JUFLXLayoutJustifyContentEnd), + kHRCSSjustifyContentBetween : @(JUFLXLayoutJustifyContentBetween), + kHRCSSjustifyContentAround : @(JUFLXLayoutJustifyContentAround), + }; + }); + return dic; + +} + ++ (NSInteger)mappedEnumValueInDictionary:(NSDictionary *)dic withKey:(NSString *)key { + NSString *value = [dic objectForKey:key]; + if (!value) { + NSLog(@"%@ isn't a valid key in valid Dic %@", key, dic); + NSUInteger initialValue = 0; + if ([key isEqualToString:kHRCSSDirection]) { + initialValue = JUFLXLayoutDirectionRow; + + } else if ([key isEqualToString:kHRCSSAlignItems]) { + initialValue = JUFLXLayoutAlignmentStretch; + + } else if ([key isEqualToString:kHRCSSjustifyContent]) { + initialValue = JUFLXLayoutJustifyContentStart; + + } else if ([key isEqualToString:kHRCSSAlignSelf]) { + initialValue = JUFLXLayoutAlignmentAuto; + + } else if ([key isEqualToString:kHRCSSAlignContent]) { + initialValue = JUFLXLayoutAlignmentStretch; + } + + return initialValue; + } + + return [value integerValue]; +} + ++ (void)parseInlineCSS:(NSString *)inlineCSS toNode:(JUFLXNode *)node { + NSDictionary *inlineDic = [self transferInlineCSS:inlineCSS]; + + //filter the invalid key and log +#if DEBUG + id predicateBlock = ^BOOL(id evaluatedObject, NSDictionary *bindings) { + return ![[self validInlineCssKeys] containsObject:evaluatedObject]; + }; + NSArray *invalidKeys = [inlineDic.allKeys filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:predicateBlock]]; + if (invalidKeys.count) { + NSLog(@"<---JUFLXNode---> valid keys %@ doesn't contain these keys %@ \n Please check -> JUFLXNode.h", [self validInlineCssKeys], invalidKeys); + } +#endif + + NSString *position = inlineDic[kHRCSSPosition]; + node.absolute = [position isKindOfClass:[NSString class]] && [position.lowercaseString isEqualToString:@"absolute"]; + CGFloat positionTop = getFloatFromString(inlineDic[kHRCSSPositionTop], node.absoluteEdges.top); + CGFloat positionLeft = getFloatFromString(inlineDic[kHRCSSPositionLeft], node.absoluteEdges.left); + CGFloat positionBottom = getFloatFromString(inlineDic[kHRCSSPositionBottom], node.absoluteEdges.bottom); + CGFloat positionRight = getFloatFromString(inlineDic[kHRCSSPositionRight], node.absoluteEdges.right); + node.absoluteEdges = UIEdgeInsetsMake(positionTop, positionLeft, positionBottom, positionRight); + + NSString *direction = inlineDic[kHRCSSDirection]; + if (direction) node.direction = [self mappedEnumValueInDictionary:[self validDirections] withKey:direction]; + + NSString *alignItems = inlineDic[kHRCSSAlignItems]; + if (alignItems) node.alignItems = [self mappedEnumValueInDictionary:[self validAlignments] withKey:alignItems]; + + NSString *alignSelf = inlineDic[kHRCSSAlignSelf]; + if (alignSelf) node.alignSelf = [self mappedEnumValueInDictionary:[self validAlignments] withKey:alignSelf]; + + NSString *alignContent = inlineDic[kHRCSSAlignContent]; + if (alignContent) node.alignContent = [self mappedEnumValueInDictionary:[self validAlignments] withKey:alignContent]; + + NSString *justifyContent = inlineDic[kHRCSSjustifyContent]; + if (justifyContent) node.justifyContent = [self mappedEnumValueInDictionary:[self validjustifyContents] withKey:justifyContent]; + + + node.flex = getFloatFromString(inlineDic[kHRCSSFlex], node.flex); + + node.flexWrap = getFloatFromString(inlineDic[kHRCSSFlexWrap], node.flexWrap); + + NSString *size = inlineDic[kHRCSSDimensionSize]; + if (isValidFloatString(size)) { + CGFloat sizef = [size floatValue]; + node.dimensions = CGSizeMake(sizef, sizef); + } + + CGFloat width = getFloatFromString(inlineDic[kHRCSSDimensionWidth], node.dimensions.width); + CGFloat height = getFloatFromString(inlineDic[kHRCSSDimensionHeight], node.dimensions.height); + node.dimensions = CGSizeMake(width, height); + + CGFloat minWidth = getFloatFromString(inlineDic[kHRCSSMinDimensionWidth], node.minDimensions.width); + CGFloat minHeight = getFloatFromString(inlineDic[kHRCSSMinDimensionHeight], node.minDimensions.height); + node.minDimensions = CGSizeMake(minWidth, minHeight); + + CGFloat maxWidth = getFloatFromString(inlineDic[kHRCSSMaxDimensionWidth], node.maxDimensions.width); + CGFloat maxHeight = getFloatFromString(inlineDic[kHRCSSMaxDimensionHeight], node.maxDimensions.height); + node.maxDimensions = CGSizeMake(maxWidth, maxHeight); + + NSString *margin = inlineDic[kHRCSSMargin]; + if (isValidFloatString(margin)) { + CGFloat marginf = [margin floatValue]; + node.margin = UIEdgeInsetsMake(marginf, marginf, marginf, marginf); + } + + CGFloat marginTop = getFloatFromString(inlineDic[kHRCSSMarginTop], node.margin.top); + CGFloat marginLeft = getFloatFromString(inlineDic[kHRCSSMarginLeft], node.margin.left); + CGFloat marginBottom = getFloatFromString(inlineDic[kHRCSSMarginBottom], node.margin.bottom); + CGFloat marginRight = getFloatFromString(inlineDic[kHRCSSMarginRight], node.margin.right); + node.margin = UIEdgeInsetsMake(marginTop, marginLeft, marginBottom, marginRight); + + NSString *padding = inlineDic[kHRCSSPadding]; + if (isValidFloatString(padding)) { + CGFloat paddingf = [padding floatValue]; + node.padding = UIEdgeInsetsMake(paddingf, paddingf, paddingf, paddingf); + } + + CGFloat paddingTop = getFloatFromString(inlineDic[kHRCSSPaddingTop], node.padding.top); + CGFloat paddingLeft = getFloatFromString(inlineDic[kHRCSSPaddingLeft], node.padding.left); + CGFloat paddingBottom = getFloatFromString(inlineDic[kHRCSSPaddingBottom], node.padding.bottom); + CGFloat paddingRight = getFloatFromString(inlineDic[kHRCSSPaddingRight], node.padding.right); + node.padding = UIEdgeInsetsMake(paddingTop, paddingLeft, paddingBottom, paddingRight); + + CGFloat sizeToFit = getFloatFromString(inlineDic[kHRCSSSizeToFit], 0); + if (sizeToFit > 0) { + node.sizeToFit = YES; + } +} + + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXLayoutDefine.h b/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXLayoutDefine.h new file mode 100644 index 00000000..cb54abcf --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXLayoutDefine.h @@ -0,0 +1,19 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + + +#define JUFLX_LAYOUT_NAMESPACE JUFLX + +#ifdef JUFLX_LAYOUT_NAMESPACE +// prefix all GData class names with JUFLX_LAYOUT_NAMESPACE for this target + #import "JUFLXTargeNamespace.h" +#endif + +#import "Layout.h" + + diff --git a/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXLayoutKit.h b/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXLayoutKit.h new file mode 100644 index 00000000..48b2c36f --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXLayoutKit.h @@ -0,0 +1,23 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "JUFLXNode.h" +#import "JUFLXCSSParser.h" +#import "UIView+JUFLXNode.h" +#import "JUFLXLinearLayoutView.h" + +//! Project version number for JUFLXLayoutKit. +FOUNDATION_EXPORT double JUFLXLayoutKitVersionNumber; + +//! Project version string for JUFLXLayoutKit. +FOUNDATION_EXPORT const unsigned char JUFLXLayoutKitVersionString[]; + +// In this header, you should import all the public headers of your framework using statements like #import + + diff --git a/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXNode.h b/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXNode.h new file mode 100644 index 00000000..2afd6bd1 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXNode.h @@ -0,0 +1,316 @@ +/* + * --------------------------------------------------------------------------- + * * Build base on Facebook's css_layout https://github.com/facebook/css-layout + * * css-layout based on http://www.w3.org/TR/css3-flexbox/ + * --------------------------------------------------------------------------- + */ + + +#import +#import +#import "JUFLXLayoutDefine.h" + +FOUNDATION_EXTERN CGFloat const JUFLXLayoutFloatUnDefined; + +/** + * Check -> http://www.w3.org/TR/css3-flexbox/#flex-direction-property + */ +typedef NS_ENUM(NSInteger, JUFLXLayoutDirection){ + /** + * inlineCSS -> row, → + */ + JUFLXLayoutDirectionRow = CSS_FLEX_DIRECTION_ROW, + /** + * inlineCSS -> row-reverse, ← + */ + JUFLXLayoutDirectionRowReverse = CSS_FLEX_DIRECTION_ROW_REVERSE, + /** + * inlineCSS -> column, ⬇️ + */ + JUFLXLayoutDirectionColumn = CSS_FLEX_DIRECTION_COLUMN, + /** + * inlineCSS -> column-reverse, ↑ + */ + JUFLXLayoutDirectionColumnReverse = CSS_FLEX_DIRECTION_COLUMN_REVERSE, +}; + +/** + * Check -> http://www.w3.org/TR/css3-flexbox/#propdef-align-items + * Check -> http://www.w3.org/TR/css3-flexbox/#propdef-align-content + * Check -> http://www.w3.org/TR/css3-flexbox/#propdef-align-self + */ +typedef NS_ENUM(NSInteger, JUFLXLayoutAlignment){ + /** + * inlineCSS -> auto + */ + JUFLXLayoutAlignmentAuto = CSS_ALIGN_AUTO, + /** + * inlineCSS -> flex-start + */ + JUFLXLayoutAlignmentStart = CSS_ALIGN_FLEX_START, + /** + * inlineCSS -> center + */ + JUFLXLayoutAlignmentCenter = CSS_ALIGN_CENTER, + /** + * inlineCSS -> flex-end + */ + JUFLXLayoutAlignmentEnd = CSS_ALIGN_FLEX_END, + /** + * inlineCSS -> stretch + */ + JUFLXLayoutAlignmentStretch = CSS_ALIGN_STRETCH +}; + +/** + * Check -> http://www.w3.org/TR/css3-flexbox/#propdef-justify-content + */ +typedef NS_ENUM(NSInteger, JUFLXLayoutJustifyContent){ + /** + * inlineCSS -> flex-start + */ + JUFLXLayoutJustifyContentStart = CSS_JUSTIFY_FLEX_START, + /** + * inlineCSS -> center + */ + JUFLXLayoutJustifyContentCenter = CSS_JUSTIFY_CENTER, + /** + * inlineCSS -> flex-end + */ + JUFLXLayoutJustifyContentEnd = CSS_JUSTIFY_FLEX_END, + /** + * inlineCSS -> space-between + */ + JUFLXLayoutJustifyContentBetween = CSS_JUSTIFY_SPACE_BETWEEN, + /** + * inlineCSS -> space-around + */ + JUFLXLayoutJustifyContentAround = CSS_JUSTIFY_SPACE_AROUND +}; + + + +@interface JUFLXNode : NSObject { +@public + BOOL _dirty; +} + +/** + * layout.c's node, the model of css box. + */ +@property (nonatomic, assign, readonly) css_node_t *node; + +/** + * The view initilized with. + */ +@property (nonatomic, weak, readonly) UIView *view; + +/** + * After node layout, the node's frame of the whole calculation. + */ +@property (nonatomic, assign, readonly) CGRect frame; + +/** + * The node's children node. + */ +@property (nonatomic, strong) NSArray *childNodes; + +/** + * Default is view's frame's origin + */ +@property (nonatomic, assign) CGPoint viewOrigin; + +/* + * --------------------------------------------------------------------------- + * As Container's property + * --------------------------------------------------------------------------- + */ + +/** + * If use flex box relative layout + * Default is NO + */ +@property (nonatomic, assign) BOOL absolute; + +/** + * When the position is absolute, use this adjust the position with father + * Default is {0, 0, 0, 0} + */ +@property (nonatomic, assign) UIEdgeInsets absoluteEdges; + +/** + * Check -> http://www.w3.org/TR/css3-flexbox/#flex-direction-property + * inlineCSS -> flex-direction + * Default is row + */ +@property (nonatomic, assign) JUFLXLayoutDirection direction; + +/** + * Check -> http://www.w3.org/TR/css3-flexbox/#propdef-align-items + * inlineCSS -> align-items + * Default is stretch + */ +@property (nonatomic, assign) JUFLXLayoutAlignment alignItems; + +/** + * Check -> http://www.w3.org/TR/css3-flexbox/#propdef-align-content + * inlineCSS -> align-content + * Default is stretch + * Here we don't support the between and around + */ +@property (nonatomic, assign) JUFLXLayoutAlignment alignContent; + +/** + * Check -> http://www.w3.org/TR/css3-flexbox/#propdef-justify-content + * inlineCSS -> justify-content + * Default is start + */ +@property (nonatomic, assign) JUFLXLayoutJustifyContent justifyContent; + +/** + * Check -> http://www.w3.org/TR/css3-flexbox/#flex-wrap-property + * When the container size doesn't satisfy, if use a new depends on this. + * inlineCSS -> flex-wrap + * Here we don't support wrap-reverse + */ +@property (nonatomic, assign) BOOL flexWrap; + + +/* + * --------------------------------------------------------------------------- + * As Child's property + * --------------------------------------------------------------------------- + */ + +/** + * Check -> http://www.w3.org/TR/css3-flexbox/#propdef-align-self + * inlineCSS -> align-self + * Default is auto, means depend on containers' alignItems; + */ +@property (nonatomic, assign) JUFLXLayoutAlignment alignSelf; + +/** + * Means two thing: 1. If self use the remaining space 2. how much would u share with others + * Flex-grow, eg: A node has three children---a,b,c; a.flex = 1, b.flex = 2, c.flex = 1, then a's size will be 1 / (1 + 2 + 1), + * b is 2 / (1 + 2 + 1), c is 1 / (1 + 2 + 1) + * inlineCSS -> flex + * Here we only support flex-grow as flex, not include shrink. + * Default is 0 + */ +@property (nonatomic, assign) CGFloat flex; + +/* + * --------------------------------------------------------------------------- + * As box's property + * --------------------------------------------------------------------------- + */ + +/** + * The style dimensions, default is the view's size, if you set it to {nan, nan}, + * The result frame depends on children's total size, so the children's size should be measured. + * inlineCSS ->size, width, height + * It won't be affected by JUFLXLayoutAlignment + */ +@property (nonatomic, assign) CGSize dimensions; + +/** + * ensure the min dimension of the view size. + * inlineCSS -> min-width, min-height + * Default is {0,0} + */ +@property (nonatomic, assign) CGSize minDimensions; + +/** + * ensure the max dimension of the view size. + * inlineCSS -> max-width, max-height + * Default is {0,0} + */ +@property (nonatomic, assign) CGSize maxDimensions; + +/** + * The margin of the view. + * inlineCSS -> margin, margin-top, margin-left, margin-bottom, margin-right + */ +@property (nonatomic, assign) UIEdgeInsets margin; + +/** + * The padding of the view. + * inlineCSS -> padding, padding-top, padding-left, padding-bottom, padding-right + */ +@property (nonatomic, assign) UIEdgeInsets padding; + +/** + * When encouter the view size should be calculated like text size, use this block. + * If direction is row, then width is the parent's node's frame's width, otherwise is nan. + * It will be affected by JUFLXLayoutAlignment + */ +@property (nonatomic, copy) CGSize (^measure)(CGFloat width); + +/** + * If isSizeToFit == YES, the measure block CGSize (^measure)(CGFloat width) will returned by view's + * sizeThatFits: size, the property will be override by measure block; + * Default is YES; + * It will be affected by JUFLXLayoutAlignment + * inlineCSS -> sizetofit: 1 + */ +@property (nonatomic, assign, getter=isSizeToFit) BOOL sizeToFit; + ++ (instancetype)nodeWithView:(UIView *)view; + +/** + * Create a node + * + * @param view the root view + * @param childNodes an array of JUFLXNodes + * + * @return node + */ ++ (instancetype)nodeWithView:(UIView *)view children:(NSArray *)childNodes; + +/** + * Copy the node attributes to a new view and children + * + * @param view another view + * + * @return a copy node not include the measure block + */ +- (instancetype)copyNodeWithView:(UIView *)view; +- (instancetype)copyNodeWithView:(UIView *)view + children:(NSArray *)childNodes; + + +- (instancetype)initWithView:(UIView *)view; +- (instancetype)initWithView:(UIView *)view children:(NSArray *)childNodes; + +/** + * Bind the node's property to inline css + * + * @param inlineCSS + * @see JUFLXCSSParser to learn the writing rule; + */ +- (void)bindingInlineCSS:(NSString *)inlineCSS; + +/** + * Manually layout the node + * + * @param aysnc move the node calculation back thread + * @param block completion + */ +- (void)layoutAsync:(BOOL)async completionBlock:(void(^)(CGRect frame))block; + +/** + * Layout the view tree if aysnc + */ +- (void)layoutAsync:(BOOL)async; + +/** + * Layout the view tree async + */ +- (void)layout; + +/** + * If log, use NSLog, default is NO; + */ +@property (nonatomic, assign) BOOL debugLogEnabled; + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXNode.m b/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXNode.m new file mode 100644 index 00000000..bdce16d6 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXNode.m @@ -0,0 +1,418 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "JUFLXNode.h" +#import "UIView+JUFLXNode.h" +#import +#import "JUFLXCSSParser.h" + +@interface UIView (JUFLXNodeSetter) + +- (void)setJu_flxNode:(JUFLXNode *)node; +- (NodeDidFinishLayout)ju_flxNodeDidFinishLayoutBlock; + +@end + +CGFloat const JUFLXLayoutFloatUnDefined = CSS_UNDEFINED; + +static bool alwaysDirty(void *context) { + JUFLXNode *self = (__bridge JUFLXNode *)context; + return self->_dirty; +} + +static css_node_t *getChild(void *context, int i) { + JUFLXNode *self = (__bridge JUFLXNode *)context; + JUFLXNode *child = self.childNodes[i]; + return child.node; +} + +static css_dim_t measureNode(void *context, float width) { + JUFLXNode *self = (__bridge JUFLXNode *)context; + CGSize size = self.measure(width); + return (css_dim_t){ size.width, size.height }; +} + +@implementation JUFLXNode { + css_node_t *_node; + NSArray *_childNodes; + CGPoint _viewOrigin; +} + +@synthesize node = _node, dimensions = _dimensions, view = _view, viewOrigin = _viewOrigin; + +- (void)dealloc { + free_css_node(_node); +} + +- (instancetype)init { + return [self initWithView:[UIView new]]; +} + +- (instancetype)initWithView:(UIView *)view { + return [self initWithView:view children:nil]; +} + +- (instancetype)initWithView:(UIView *)view children:(NSArray *)childNodes { + if (self = [super init]) { + _debugLogEnabled = NO; + _dirty = YES; + _node = new_css_node(); + _node->context = (__bridge void *)self; + _node->is_dirty = alwaysDirty; + _node->get_child = getChild; + + //as container initial + self.absolute = NO; + self.absoluteEdges = UIEdgeInsetsZero; + self.direction = JUFLXLayoutDirectionColumn; + self.alignItems = JUFLXLayoutAlignmentStretch; + self.alignContent = JUFLXLayoutAlignmentStretch; + self.justifyContent = JUFLXLayoutJustifyContentStart; + self.flexWrap = NO; + + //as child initial + self.alignSelf = JUFLXLayoutAlignmentAuto; + self.margin = UIEdgeInsetsZero; + self.padding = UIEdgeInsetsZero; + self.flex = 0; + self.sizeToFit = NO; + + _view = view; + _viewOrigin = view.frame.origin; + [_view setJu_flxNode:self]; + + self.childNodes = childNodes; + } + + return self; +} + ++ (instancetype)nodeWithView:(UIView *)view { + return [self nodeWithView:view children:nil]; +} + ++ (instancetype)nodeWithView:(UIView *)view children:(NSArray *)childNodes { + return [[[self class] alloc] initWithView:view children:(NSArray *)childNodes]; +} + +- (instancetype)copyNodeWithView:(UIView *)view { + return [self copyNodeWithView:view children:nil]; +} + +- (instancetype)copyNodeWithView:(UIView *)view children:(NSArray *)childNodes { + JUFLXNode *node = [[self class] nodeWithView:view children:childNodes]; + node.direction = self.direction; + node.alignItems = self.alignItems; + node.alignContent = self.alignContent; + node.justifyContent = self.justifyContent; + node.flexWrap = self.flexWrap; + node.alignSelf = self.alignSelf; + node.flex = self.flex; + node.dimensions = self.dimensions; + node.minDimensions = self.minDimensions; + node.maxDimensions = self.maxDimensions; + node.margin = self.margin; + node.padding = self.padding; + node.sizeToFit = self.sizeToFit; + + return node; +} + +- (void)setChildNodes:(NSArray *)childNodes { + [self _resetOriginNodeViews]; + _childNodes = childNodes; + _node->children_count = (int)_childNodes.count; + [self generateViewTreeWithView:_view childNodes:_childNodes]; +} + +- (void)generateViewTreeWithView:(UIView *)view childNodes:(NSArray *)childNodes { + for (JUFLXNode *childNode in childNodes) { + [view addSubview:childNode.view]; + // only generate the node has child nodes + if ([childNode isContainer]) { + [self generateViewTreeWithView:childNode.view childNodes:childNode.childNodes]; + } + } +} + +- (BOOL)isContainer { + return _childNodes.count > 0; +} + +- (CGRect)frame { + return (CGRect) { + .origin.x = self.node->layout.position[CSS_LEFT] + _viewOrigin.x, + .origin.y = self.node->layout.position[CSS_TOP] + _viewOrigin.y, + .size.width = self.node->layout.dimensions[CSS_WIDTH], + .size.height = self.node->layout.dimensions[CSS_HEIGHT] + }; +} + +- (void)_resetOriginNodeViews { + for (JUFLXNode *subNode in _childNodes) { + if ([subNode isContainer]) { + [subNode _resetOriginNodeViews]; + } + [subNode.view removeFromSuperview]; + } +} + +- (void)_layoutWithNode { + NSTimeInterval start = CFAbsoluteTimeGetCurrent(); + + [self _resetNode]; + layoutNode(_node, self.dimensions.width, _node->style.direction); + + if (_debugLogEnabled) { + NSLog(@"%@ layout all nodes takes time %f \n on thread %@", NSStringFromClass(self.class), CFAbsoluteTimeGetCurrent() - start, [NSThread currentThread]); + } +} + +- (void)_assignNodeFrame { + self.view.frame = self.frame; + + if (self.view.ju_flxNodeDidFinishLayoutBlock) { + self.view.ju_flxNodeDidFinishLayoutBlock(self); + } + + for (JUFLXNode *subNode in _childNodes) { + if ([subNode isContainer]) { + [subNode _assignNodeFrame]; + } else { + NSLog(@"subNode frame is %@", NSStringFromCGRect(subNode.frame)); + subNode.view.frame = subNode.frame; + + if (subNode.view.ju_flxNodeDidFinishLayoutBlock) { + subNode.view.ju_flxNodeDidFinishLayoutBlock(subNode); + } + } + } +} + +- (void)_resetNode { + for (JUFLXNode *subNode in _childNodes) { + [subNode _resetNode]; + } + + self.node->layout.position[CSS_LEFT] = 0; + self.node->layout.position[CSS_TOP] = 0; + self.node->layout.position[CSS_RIGHT] = 0; + self.node->layout.position[CSS_BOTTOM] = 0; + + self.node->layout.dimensions[CSS_WIDTH] = CSS_UNDEFINED; + self.node->layout.dimensions[CSS_HEIGHT] = CSS_UNDEFINED; +} + +- (void)layoutAsync:(BOOL)aysnc completionBlock:(void(^)(CGRect frame))block { + _dirty = YES; + if (aysnc) { + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{ + [self _layoutWithNode]; + dispatch_async(dispatch_get_main_queue(), ^{ + [self _assignNodeFrame]; + _dirty = NO; + if (block) { + block(self.frame); + } + }); + }); + } else { + [self _layoutWithNode]; + [self _assignNodeFrame]; + _dirty = NO; + if (block) { + block(self.frame); + } + } +} + +- (void)layoutAsync:(BOOL)aysnc { + [self layoutAsync:aysnc completionBlock:NULL]; +} + +- (void)layout { + [self layoutAsync:NO completionBlock:NULL]; +} + +- (void)setNeedsLayout { + if (_dirty) { + [self layout]; + } +} + +- (void)setAbsolute:(BOOL)absolute { + if (_absolute == absolute) return; + _absolute = absolute; + _node->style.position_type = _absolute ? CSS_POSITION_ABSOLUTE : CSS_POSITION_RELATIVE; + _dirty = YES; +} + +- (void)setAbsoluteEdges:(UIEdgeInsets)absoluteEdges { + if (UIEdgeInsetsEqualToEdgeInsets(_absoluteEdges, absoluteEdges)) return; + _absoluteEdges = absoluteEdges; + _node->style.position[CSS_LEFT] = _absoluteEdges.left; + _node->style.position[CSS_TOP] = _absoluteEdges.top; + _node->style.position[CSS_RIGHT] = _absoluteEdges.right; + _node->style.position[CSS_BOTTOM] = _absoluteEdges.bottom; + _dirty = YES; +} + +- (CGSize)dimensions { + if (CGSizeEqualToSize(_dimensions, CGSizeZero)) { + _dimensions = self.view.bounds.size; + _node->style.dimensions[CSS_WIDTH] = _dimensions.width; + _node->style.dimensions[CSS_HEIGHT] = _dimensions.height; + } + return _dimensions; +} + +- (void)setDimensions:(CGSize)size { + if (CGSizeEqualToSize(_dimensions, size)) return; + _dimensions = size; + _node->style.dimensions[CSS_WIDTH] = size.width; + _node->style.dimensions[CSS_HEIGHT] = size.height; + _dirty = YES; +} + +- (void)setMinDimensions:(CGSize)size { + if (CGSizeEqualToSize(_minDimensions, size)) return; + _minDimensions = size; + _node->style.minDimensions[CSS_WIDTH] = size.width; + _node->style.minDimensions[CSS_HEIGHT] = size.height; + _dirty = YES; +} + +- (void)setMaxDimensions:(CGSize)size { + if (CGSizeEqualToSize(_maxDimensions, size)) return; + _maxDimensions = size; + _node->style.maxDimensions[CSS_WIDTH] = size.width; + _node->style.maxDimensions[CSS_HEIGHT] = size.height; + _dirty = YES; +} + +- (void)setMargin:(UIEdgeInsets)margin { + if (UIEdgeInsetsEqualToEdgeInsets(_margin, margin)) return; + _margin = margin; + _node->style.margin[CSS_LEFT] = margin.left; + _node->style.margin[CSS_TOP] = margin.top; + _node->style.margin[CSS_RIGHT] = margin.right; + _node->style.margin[CSS_BOTTOM] = margin.bottom; + _dirty = YES; +} + +- (void)setPadding:(UIEdgeInsets)padding { + if (UIEdgeInsetsEqualToEdgeInsets(_padding, padding)) return; + _padding = padding; + _node->style.padding[CSS_LEFT] = padding.left; + _node->style.padding[CSS_TOP] = padding.top; + _node->style.padding[CSS_RIGHT] = padding.right; + _node->style.padding[CSS_BOTTOM] = padding.bottom; + _dirty = YES; +} + +- (void)setDirection:(JUFLXLayoutDirection)direction { + if (_direction == direction) return; + _direction = direction; + _node->style.flex_direction = (int)_direction; + _dirty = YES; +} + +- (void)setAlignContent:(JUFLXLayoutAlignment)alignContent { + if (_alignContent == alignContent) return; + _alignContent = alignContent; + _node->style.align_content = (int)alignContent; + _dirty = YES; +} + +- (void)setAlignItems:(JUFLXLayoutAlignment)alignItems { + if (_alignItems == alignItems) return; + _alignItems = alignItems; + _node->style.align_items = (int)_alignItems; + _dirty = YES; +} + +- (void)setJustifyContent:(JUFLXLayoutJustifyContent)justifyContent { + if (_justifyContent == justifyContent) return; + _justifyContent = justifyContent; + _node->style.justify_content = (int)_justifyContent; + _dirty = YES; +} + +- (void)setFlexWrap:(BOOL)flexWrap { + if (_flexWrap == flexWrap) return; + _flexWrap = flexWrap; + _node->style.flex_wrap = _flexWrap; + _dirty = YES; +} + +- (void)setAlignSelf:(JUFLXLayoutAlignment)alignSelf { + if (_alignSelf == alignSelf) return; + _alignSelf = alignSelf; + _node->style.align_self = (int)_alignSelf; + _dirty = YES; +} + +- (void)setFlex:(CGFloat)flex { + if (_flex == flex) return; + _flex = flex; + _node->style.flex = _flex; + _dirty = YES; +} + +- (void)setMeasure:(CGSize (^)(CGFloat))measure { + if (measure) { + _measure = [measure copy]; + _node->measure = (_measure != nil ? measureNode : NULL); + } +} + +- (void)setSizeToFit:(BOOL)sizeToFit { + if (_sizeToFit == sizeToFit) return; + _sizeToFit = sizeToFit; + if (_sizeToFit) { + __weak typeof(self) wself = self; + self.measure = ^CGSize(CGFloat width) { + return [wself.view sizeThatFits:CGSizeMake(width, CGFLOAT_MAX)]; + }; + } + _dirty = YES; +} + +- (void)bindingInlineCSS:(NSString *)inlineCSS { + [JUFLXCSSParser parseInlineCSS:inlineCSS toNode:self]; +} + +- (NSString *)description { + NSString *selfDescription = [super description]; + if (_debugLogEnabled) { + selfDescription = [NSString stringWithFormat:@"{node's view is %@ and child nodes is \n %@", self.view, self.childNodes]; + print_css_node(_node, CSS_PRINT_STYLE | CSS_PRINT_CHILDREN | CSS_PRINT_LAYOUT); + + } + return selfDescription; +} + +@end + +@implementation UIView (JUFLXNodeSetter) + +- (void)setJu_flxNode:(JUFLXNode *)node { + JUFLXNode *currentNode = objc_getAssociatedObject(self, &JUFLXNodeUIViewNodeKey); + + if (currentNode && node != currentNode) { + NSLog(@"<---JUFLXNode Warning!--->, You are trying set a view %@ with another node %@, pay attention to this view's subViews", self, node); + } + + objc_setAssociatedObject(self, &JUFLXNodeUIViewNodeKey, node, OBJC_ASSOCIATION_RETAIN_NONATOMIC); +} + +- (NodeDidFinishLayout)ju_flxNodeDidFinishLayoutBlock { + return objc_getAssociatedObject(self, &JUFLXNodeUIViewDidFinishBlockKey); +} + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXTargeNamespace.h b/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXTargeNamespace.h new file mode 100644 index 00000000..5359a4db --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXTargeNamespace.h @@ -0,0 +1,39 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#if defined(JUFLX_LAYOUT_NAMESPACE) + + #define _JUFLX_NS_SYMBOL_INNER(namespace, symbol) namespace ## _ ## symbol + #define _JUFLX_NS_SYMBOL_MIDDLE(namespace, symbol) _JUFLX_NS_SYMBOL_INNER(namespace, symbol) + #define _JUFLX_NS_SYMBOL(symbol) _JUFLX_NS_SYMBOL_MIDDLE(JUFLX_LAYOUT_NAMESPACE, symbol) + + #define _JUFLX_NS_STRING_INNER(namespace) #namespace + #define _JUFLX_NS_STRING_MIDDLE(namespace) _JUFLX_NS_STRING_INNER(namespace) + #define JUFLX_LAYOUT_NAMESPACE_STRING _JUFLX_NS_STRING_MIDDLE(JUFLX_LAYOUT_NAMESPACE) + + #define css_direction_t _JUFLX_NS_SYMBOL(css_direction_t) + #define css_flex_direction_t _JUFLX_NS_SYMBOL(css_flex_direction_t) + #define css_justify_t _JUFLX_NS_SYMBOL(css_justify_t) + #define css_align_t _JUFLX_NS_SYMBOL(css_align_t) + #define css_position_type_t _JUFLX_NS_SYMBOL(css_position_type_t) + #define css_wrap_type_t _JUFLX_NS_SYMBOL(css_wrap_type_t) + #define css_position_t _JUFLX_NS_SYMBOL(css_position_t) + #define css_dimension_t _JUFLX_NS_SYMBOL(css_dimension_t) + #define css_layout_t _JUFLX_NS_SYMBOL(css_layout_t) + #define css_dim_t _JUFLX_NS_SYMBOL(css_dim_t) + #define css_style_t _JUFLX_NS_SYMBOL(css_style_t) + #define css_node_t _JUFLX_NS_SYMBOL(css_node_t) + #define new_css_node _JUFLX_NS_SYMBOL(new_css_node) + #define init_css_node _JUFLX_NS_SYMBOL(init_css_node) + #define free_css_node _JUFLX_NS_SYMBOL(free_css_node) + #define css_print_options_t _JUFLX_NS_SYMBOL(css_print_options_t) + #define print_css_node _JUFLX_NS_SYMBOL(print_css_node) + #define layoutNode _JUFLX_NS_SYMBOL(layoutNode) + #define isUndefined _JUFLX_NS_SYMBOL(isUndefined) + +#endif diff --git a/IOS/SDK/LuaViewSDK/Classes/layout/Layout.c b/IOS/SDK/LuaViewSDK/Classes/layout/Layout.c new file mode 100644 index 00000000..cccf3685 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/layout/Layout.c @@ -0,0 +1,1141 @@ +/** + * Copyright (c) 2014, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +#include +#include +#include +#include + +#include "JUFLXLayoutDefine.h" + +#ifdef _MSC_VER +#include +#define isnan _isnan + +/* define fmaxf if < VC12 */ +#if _MSC_VER < 1800 +__forceinline const float fmaxf(const float a, const float b) { + return (a > b) ? a : b; +} +#endif +#endif + +bool isUndefined(float value) { + return isnan(value); +} + +static bool eq(float a, float b) { + if (isUndefined(a)) { + return isUndefined(b); + } + return fabs(a - b) < 0.0001; +} + +void init_css_node(css_node_t *node) { + node->style.align_items = CSS_ALIGN_STRETCH; + node->style.align_content = CSS_ALIGN_FLEX_START; + + node->style.direction = CSS_DIRECTION_INHERIT; + node->style.flex_direction = CSS_FLEX_DIRECTION_COLUMN; + + // Some of the fields default to undefined and not 0 + node->style.dimensions[CSS_WIDTH] = CSS_UNDEFINED; + node->style.dimensions[CSS_HEIGHT] = CSS_UNDEFINED; + + node->style.minDimensions[CSS_WIDTH] = CSS_UNDEFINED; + node->style.minDimensions[CSS_HEIGHT] = CSS_UNDEFINED; + + node->style.maxDimensions[CSS_WIDTH] = CSS_UNDEFINED; + node->style.maxDimensions[CSS_HEIGHT] = CSS_UNDEFINED; + + node->style.position[CSS_LEFT] = CSS_UNDEFINED; + node->style.position[CSS_TOP] = CSS_UNDEFINED; + node->style.position[CSS_RIGHT] = CSS_UNDEFINED; + node->style.position[CSS_BOTTOM] = CSS_UNDEFINED; + + node->style.margin[CSS_START] = CSS_UNDEFINED; + node->style.margin[CSS_END] = CSS_UNDEFINED; + node->style.padding[CSS_START] = CSS_UNDEFINED; + node->style.padding[CSS_END] = CSS_UNDEFINED; + node->style.border[CSS_START] = CSS_UNDEFINED; + node->style.border[CSS_END] = CSS_UNDEFINED; + + node->layout.dimensions[CSS_WIDTH] = CSS_UNDEFINED; + node->layout.dimensions[CSS_HEIGHT] = CSS_UNDEFINED; + + // Such that the comparison is always going to be false + node->layout.last_requested_dimensions[CSS_WIDTH] = -1; + node->layout.last_requested_dimensions[CSS_HEIGHT] = -1; + node->layout.last_parent_max_width = -1; + node->layout.last_direction = (css_direction_t)-1; + node->layout.should_update = true; +} + +css_node_t *new_css_node() { + css_node_t *node = (css_node_t *)calloc(1, sizeof(*node)); + init_css_node(node); + return node; +} + +void free_css_node(css_node_t *node) { + free(node); +} + +static void indent(int n) { + for (int i = 0; i < n; ++i) { + printf(" "); + } +} + +static void print_number_0(const char *str, float number) { + if (!eq(number, 0)) { + printf("%s: %g, ", str, number); + } +} + +static void print_number_nan(const char *str, float number) { + if (!isnan(number)) { + printf("%s: %g, ", str, number); + } +} + +static bool four_equal(float four[4]) { + return + eq(four[0], four[1]) && + eq(four[0], four[2]) && + eq(four[0], four[3]); +} + + +static void print_css_node_rec( + css_node_t *node, + css_print_options_t options, + int level +) { + indent(level); + printf("{"); + + if (node->print) { + node->print(node->context); + } + + if (options & CSS_PRINT_LAYOUT) { + printf("layout: {"); + printf("width: %g, ", node->layout.dimensions[CSS_WIDTH]); + printf("height: %g, ", node->layout.dimensions[CSS_HEIGHT]); + printf("top: %g, ", node->layout.position[CSS_TOP]); + printf("left: %g", node->layout.position[CSS_LEFT]); + printf("}, "); + } + + if (options & CSS_PRINT_STYLE) { + if (node->style.flex_direction == CSS_FLEX_DIRECTION_COLUMN) { + printf("flexDirection: 'column', "); + } else if (node->style.flex_direction == CSS_FLEX_DIRECTION_COLUMN_REVERSE) { + printf("flexDirection: 'columnReverse', "); + } else if (node->style.flex_direction == CSS_FLEX_DIRECTION_ROW) { + printf("flexDirection: 'row', "); + } else if (node->style.flex_direction == CSS_FLEX_DIRECTION_ROW_REVERSE) { + printf("flexDirection: 'rowReverse', "); + } + + if (node->style.justify_content == CSS_JUSTIFY_CENTER) { + printf("justifyContent: 'center', "); + } else if (node->style.justify_content == CSS_JUSTIFY_FLEX_END) { + printf("justifyContent: 'flex-end', "); + } else if (node->style.justify_content == CSS_JUSTIFY_SPACE_AROUND) { + printf("justifyContent: 'space-around', "); + } else if (node->style.justify_content == CSS_JUSTIFY_SPACE_BETWEEN) { + printf("justifyContent: 'space-between', "); + } + + if (node->style.align_items == CSS_ALIGN_CENTER) { + printf("alignItems: 'center', "); + } else if (node->style.align_items == CSS_ALIGN_FLEX_END) { + printf("alignItems: 'flex-end', "); + } else if (node->style.align_items == CSS_ALIGN_STRETCH) { + printf("alignItems: 'stretch', "); + } + + if (node->style.align_content == CSS_ALIGN_CENTER) { + printf("alignContent: 'center', "); + } else if (node->style.align_content == CSS_ALIGN_FLEX_END) { + printf("alignContent: 'flex-end', "); + } else if (node->style.align_content == CSS_ALIGN_STRETCH) { + printf("alignContent: 'stretch', "); + } + + if (node->style.align_self == CSS_ALIGN_FLEX_START) { + printf("alignSelf: 'flex-start', "); + } else if (node->style.align_self == CSS_ALIGN_CENTER) { + printf("alignSelf: 'center', "); + } else if (node->style.align_self == CSS_ALIGN_FLEX_END) { + printf("alignSelf: 'flex-end', "); + } else if (node->style.align_self == CSS_ALIGN_STRETCH) { + printf("alignSelf: 'stretch', "); + } + + print_number_nan("flex", node->style.flex); + + if (four_equal(node->style.margin)) { + print_number_0("margin", node->style.margin[CSS_LEFT]); + } else { + print_number_0("marginLeft", node->style.margin[CSS_LEFT]); + print_number_0("marginRight", node->style.margin[CSS_RIGHT]); + print_number_0("marginTop", node->style.margin[CSS_TOP]); + print_number_0("marginBottom", node->style.margin[CSS_BOTTOM]); + print_number_0("marginStart", node->style.margin[CSS_START]); + print_number_0("marginEnd", node->style.margin[CSS_END]); + } + + if (four_equal(node->style.padding)) { + print_number_0("padding", node->style.margin[CSS_LEFT]); + } else { + print_number_0("paddingLeft", node->style.padding[CSS_LEFT]); + print_number_0("paddingRight", node->style.padding[CSS_RIGHT]); + print_number_0("paddingTop", node->style.padding[CSS_TOP]); + print_number_0("paddingBottom", node->style.padding[CSS_BOTTOM]); + print_number_0("paddingStart", node->style.padding[CSS_START]); + print_number_0("paddingEnd", node->style.padding[CSS_END]); + } + + if (four_equal(node->style.border)) { + print_number_0("borderWidth", node->style.border[CSS_LEFT]); + } else { + print_number_0("borderLeftWidth", node->style.border[CSS_LEFT]); + print_number_0("borderRightWidth", node->style.border[CSS_RIGHT]); + print_number_0("borderTopWidth", node->style.border[CSS_TOP]); + print_number_0("borderBottomWidth", node->style.border[CSS_BOTTOM]); + print_number_0("borderStartWidth", node->style.border[CSS_START]); + print_number_0("borderEndWidth", node->style.border[CSS_END]); + } + + print_number_nan("width", node->style.dimensions[CSS_WIDTH]); + print_number_nan("height", node->style.dimensions[CSS_HEIGHT]); + + if (node->style.position_type == CSS_POSITION_ABSOLUTE) { + printf("position: 'absolute', "); + } + + print_number_nan("left", node->style.position[CSS_LEFT]); + print_number_nan("right", node->style.position[CSS_RIGHT]); + print_number_nan("top", node->style.position[CSS_TOP]); + print_number_nan("bottom", node->style.position[CSS_BOTTOM]); + } + + if (options & CSS_PRINT_CHILDREN && node->children_count > 0) { + printf("children: [\n"); + for (int i = 0; i < node->children_count; ++i) { + print_css_node_rec(node->get_child(node->context, i), options, level + 1); + } + indent(level); + printf("]},\n"); + } else { + printf("},\n"); + } +} + +void print_css_node(css_node_t *node, css_print_options_t options) { + print_css_node_rec(node, options, 0); +} + + +static css_position_t leading[4] = { + /* CSS_FLEX_DIRECTION_COLUMN = */ CSS_TOP, + /* CSS_FLEX_DIRECTION_COLUMN_REVERSE = */ CSS_BOTTOM, + /* CSS_FLEX_DIRECTION_ROW = */ CSS_LEFT, + /* CSS_FLEX_DIRECTION_ROW_REVERSE = */ CSS_RIGHT +}; +static css_position_t trailing[4] = { + /* CSS_FLEX_DIRECTION_COLUMN = */ CSS_BOTTOM, + /* CSS_FLEX_DIRECTION_COLUMN_REVERSE = */ CSS_TOP, + /* CSS_FLEX_DIRECTION_ROW = */ CSS_RIGHT, + /* CSS_FLEX_DIRECTION_ROW_REVERSE = */ CSS_LEFT +}; +static css_position_t pos[4] = { + /* CSS_FLEX_DIRECTION_COLUMN = */ CSS_TOP, + /* CSS_FLEX_DIRECTION_COLUMN_REVERSE = */ CSS_BOTTOM, + /* CSS_FLEX_DIRECTION_ROW = */ CSS_LEFT, + /* CSS_FLEX_DIRECTION_ROW_REVERSE = */ CSS_RIGHT +}; +static css_dimension_t dim[4] = { + /* CSS_FLEX_DIRECTION_COLUMN = */ CSS_HEIGHT, + /* CSS_FLEX_DIRECTION_COLUMN_REVERSE = */ CSS_HEIGHT, + /* CSS_FLEX_DIRECTION_ROW = */ CSS_WIDTH, + /* CSS_FLEX_DIRECTION_ROW_REVERSE = */ CSS_WIDTH +}; + +static bool isRowDirection(css_flex_direction_t flex_direction) { + return flex_direction == CSS_FLEX_DIRECTION_ROW || + flex_direction == CSS_FLEX_DIRECTION_ROW_REVERSE; +} + +static bool isColumnDirection(css_flex_direction_t flex_direction) { + return flex_direction == CSS_FLEX_DIRECTION_COLUMN || + flex_direction == CSS_FLEX_DIRECTION_COLUMN_REVERSE; +} + +static float getLeadingMargin(css_node_t *node, css_flex_direction_t axis) { + if (isRowDirection(axis) && !isUndefined(node->style.margin[CSS_START])) { + return node->style.margin[CSS_START]; + } + + return node->style.margin[leading[axis]]; +} + +static float getTrailingMargin(css_node_t *node, css_flex_direction_t axis) { + if (isRowDirection(axis) && !isUndefined(node->style.margin[CSS_END])) { + return node->style.margin[CSS_END]; + } + + return node->style.margin[trailing[axis]]; +} + +static float getLeadingPadding(css_node_t *node, css_flex_direction_t axis) { + if (isRowDirection(axis) && + !isUndefined(node->style.padding[CSS_START]) && + node->style.padding[CSS_START] >= 0) { + return node->style.padding[CSS_START]; + } + + if (node->style.padding[leading[axis]] >= 0) { + return node->style.padding[leading[axis]]; + } + + return 0; +} + +static float getTrailingPadding(css_node_t *node, css_flex_direction_t axis) { + if (isRowDirection(axis) && + !isUndefined(node->style.padding[CSS_END]) && + node->style.padding[CSS_END] >= 0) { + return node->style.padding[CSS_END]; + } + + if (node->style.padding[trailing[axis]] >= 0) { + return node->style.padding[trailing[axis]]; + } + + return 0; +} + +static float getLeadingBorder(css_node_t *node, css_flex_direction_t axis) { + if (isRowDirection(axis) && + !isUndefined(node->style.border[CSS_START]) && + node->style.border[CSS_START] >= 0) { + return node->style.border[CSS_START]; + } + + if (node->style.border[leading[axis]] >= 0) { + return node->style.border[leading[axis]]; + } + + return 0; +} + +static float getTrailingBorder(css_node_t *node, css_flex_direction_t axis) { + if (isRowDirection(axis) && + !isUndefined(node->style.border[CSS_END]) && + node->style.border[CSS_END] >= 0) { + return node->style.border[CSS_END]; + } + + if (node->style.border[trailing[axis]] >= 0) { + return node->style.border[trailing[axis]]; + } + + return 0; +} + +static float getLeadingPaddingAndBorder(css_node_t *node, css_flex_direction_t axis) { + return getLeadingPadding(node, axis) + getLeadingBorder(node, axis); +} + +static float getTrailingPaddingAndBorder(css_node_t *node, css_flex_direction_t axis) { + return getTrailingPadding(node, axis) + getTrailingBorder(node, axis); +} + +static float getBorderAxis(css_node_t *node, css_flex_direction_t axis) { + return getLeadingBorder(node, axis) + getTrailingBorder(node, axis); +} + +static float getMarginAxis(css_node_t *node, css_flex_direction_t axis) { + return getLeadingMargin(node, axis) + getTrailingMargin(node, axis); +} + +static float getPaddingAndBorderAxis(css_node_t *node, css_flex_direction_t axis) { + return getLeadingPaddingAndBorder(node, axis) + getTrailingPaddingAndBorder(node, axis); +} + +static css_position_type_t getPositionType(css_node_t *node) { + return node->style.position_type; +} + +static css_justify_t getJustifyContent(css_node_t *node) { + return node->style.justify_content; +} + +static css_align_t getAlignContent(css_node_t *node) { + return node->style.align_content; +} + +static css_align_t getAlignItem(css_node_t *node, css_node_t *child) { + if (child->style.align_self != CSS_ALIGN_AUTO) { + return child->style.align_self; + } + return node->style.align_items; +} + +static css_direction_t resolveDirection(css_node_t *node, css_direction_t parentDirection) { + css_direction_t direction = node->style.direction; + + if (direction == CSS_DIRECTION_INHERIT) { + direction = parentDirection > CSS_DIRECTION_INHERIT ? parentDirection : CSS_DIRECTION_LTR; + } + + return direction; +} + +static css_flex_direction_t getFlexDirection(css_node_t *node) { + return node->style.flex_direction; +} + +static css_flex_direction_t resolveAxis(css_flex_direction_t flex_direction, css_direction_t direction) { + if (direction == CSS_DIRECTION_RTL) { + if (flex_direction == CSS_FLEX_DIRECTION_ROW) { + return CSS_FLEX_DIRECTION_ROW_REVERSE; + } else if (flex_direction == CSS_FLEX_DIRECTION_ROW_REVERSE) { + return CSS_FLEX_DIRECTION_ROW; + } + } + + return flex_direction; +} + +static css_flex_direction_t getCrossFlexDirection(css_flex_direction_t flex_direction, css_direction_t direction) { + if (isColumnDirection(flex_direction)) { + return resolveAxis(CSS_FLEX_DIRECTION_ROW, direction); + } else { + return CSS_FLEX_DIRECTION_COLUMN; + } +} + +static float getFlex(css_node_t *node) { + return node->style.flex; +} + +static bool isFlex(css_node_t *node) { + return ( + getPositionType(node) == CSS_POSITION_RELATIVE && + getFlex(node) > 0 + ); +} + +static bool isFlexWrap(css_node_t *node) { + return node->style.flex_wrap == CSS_WRAP; +} + +static float getDimWithMargin(css_node_t *node, css_flex_direction_t axis) { + return node->layout.dimensions[dim[axis]] + + getLeadingMargin(node, axis) + + getTrailingMargin(node, axis); +} + +static bool isDimDefined(css_node_t *node, css_flex_direction_t axis) { + float value = node->style.dimensions[dim[axis]]; + return !isUndefined(value) && value > 0.0; +} + +static bool isPosDefined(css_node_t *node, css_position_t position) { + return !isUndefined(node->style.position[position]); +} + +static bool isMeasureDefined(css_node_t *node) { + return node->measure; +} + +static float getPosition(css_node_t *node, css_position_t position) { + float result = node->style.position[position]; + if (!isUndefined(result)) { + return result; + } + return 0; +} + +static float boundAxis(css_node_t *node, css_flex_direction_t axis, float value) { + float min = CSS_UNDEFINED; + float max = CSS_UNDEFINED; + + if (isColumnDirection(axis)) { + min = node->style.minDimensions[CSS_HEIGHT]; + max = node->style.maxDimensions[CSS_HEIGHT]; + } else if (isRowDirection(axis)) { + min = node->style.minDimensions[CSS_WIDTH]; + max = node->style.maxDimensions[CSS_WIDTH]; + } + + float boundValue = value; + + if (!isUndefined(max) && max >= 0.0 && boundValue > max) { + boundValue = max; + } + if (!isUndefined(min) && min >= 0.0 && boundValue < min) { + boundValue = min; + } + + return boundValue; +} + +// When the user specifically sets a value for width or height +static void setDimensionFromStyle(css_node_t *node, css_flex_direction_t axis) { + // The parent already computed us a width or height. We just skip it + if (!isUndefined(node->layout.dimensions[dim[axis]])) { + return; + } + // We only run if there's a width or height defined + if (!isDimDefined(node, axis)) { + return; + } + + // The dimensions can never be smaller than the padding and border + node->layout.dimensions[dim[axis]] = fmaxf( + boundAxis(node, axis, node->style.dimensions[dim[axis]]), + getPaddingAndBorderAxis(node, axis) + ); +} + +static void setTrailingPosition(css_node_t *node, css_node_t *child, css_flex_direction_t axis) { + child->layout.position[trailing[axis]] = node->layout.dimensions[dim[axis]] - + child->layout.dimensions[dim[axis]] - child->layout.position[pos[axis]]; + } + +// If both left and right are defined, then use left. Otherwise return +// +left or -right depending on which is defined. +static float getRelativePosition(css_node_t *node, css_flex_direction_t axis) { + float lead = node->style.position[leading[axis]]; + if (!isUndefined(lead)) { + return lead; + } + return -getPosition(node, trailing[axis]); +} + +static void layoutNodeImpl(css_node_t *node, float parentMaxWidth, css_direction_t parentDirection) { + /** START_GENERATED **/ + css_direction_t direction = resolveDirection(node, parentDirection); + css_flex_direction_t mainAxis = resolveAxis(getFlexDirection(node), direction); + css_flex_direction_t crossAxis = getCrossFlexDirection(mainAxis, direction); + css_flex_direction_t resolvedRowAxis = resolveAxis(CSS_FLEX_DIRECTION_ROW, direction); + + // Handle width and height style attributes + setDimensionFromStyle(node, mainAxis); + setDimensionFromStyle(node, crossAxis); + + // Set the resolved resolution in the node's layout + node->layout.direction = direction; + + // The position is set by the parent, but we need to complete it with a + // delta composed of the margin and left/top/right/bottom + node->layout.position[leading[mainAxis]] += getLeadingMargin(node, mainAxis) + + getRelativePosition(node, mainAxis); + node->layout.position[trailing[mainAxis]] += getTrailingMargin(node, mainAxis) + + getRelativePosition(node, mainAxis); + node->layout.position[leading[crossAxis]] += getLeadingMargin(node, crossAxis) + + getRelativePosition(node, crossAxis); + node->layout.position[trailing[crossAxis]] += getTrailingMargin(node, crossAxis) + + getRelativePosition(node, crossAxis); + + if (isMeasureDefined(node)) { + float width = CSS_UNDEFINED; + if (isDimDefined(node, resolvedRowAxis)) { + width = node->style.dimensions[CSS_WIDTH]; + } else if (!isUndefined(node->layout.dimensions[dim[resolvedRowAxis]])) { + width = node->layout.dimensions[dim[resolvedRowAxis]]; + } else { + width = parentMaxWidth - + getMarginAxis(node, resolvedRowAxis); + } + width -= getPaddingAndBorderAxis(node, resolvedRowAxis); + + // We only need to give a dimension for the text if we haven't got any + // for it computed yet. It can either be from the style attribute or because + // the element is flexible. + bool isRowUndefined = !isDimDefined(node, resolvedRowAxis) && + isUndefined(node->layout.dimensions[dim[resolvedRowAxis]]); + bool isColumnUndefined = !isDimDefined(node, CSS_FLEX_DIRECTION_COLUMN) && + isUndefined(node->layout.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]]); + + // Let's not measure the text if we already know both dimensions + if (isRowUndefined || isColumnUndefined) { + css_dim_t measureDim = node->measure( + node->context, + + width + ); + if (isRowUndefined) { + node->layout.dimensions[CSS_WIDTH] = measureDim.dimensions[CSS_WIDTH] + + getPaddingAndBorderAxis(node, resolvedRowAxis); + } + if (isColumnUndefined) { + node->layout.dimensions[CSS_HEIGHT] = measureDim.dimensions[CSS_HEIGHT] + + getPaddingAndBorderAxis(node, CSS_FLEX_DIRECTION_COLUMN); + } + } + if (node->children_count == 0) { + return; + } + } + + int i; + int ii; + css_node_t* child; + css_flex_direction_t axis; + + // Pre-fill some dimensions straight from the parent + for (i = 0; i < node->children_count; ++i) { + child = node->get_child(node->context, i); + // Pre-fill cross axis dimensions when the child is using stretch before + // we call the recursive layout pass + if (getAlignItem(node, child) == CSS_ALIGN_STRETCH && + getPositionType(child) == CSS_POSITION_RELATIVE && + !isUndefined(node->layout.dimensions[dim[crossAxis]]) && + !isDimDefined(child, crossAxis)) { + child->layout.dimensions[dim[crossAxis]] = fmaxf( + boundAxis(child, crossAxis, node->layout.dimensions[dim[crossAxis]] - + getPaddingAndBorderAxis(node, crossAxis) - + getMarginAxis(child, crossAxis)), + // You never want to go smaller than padding + getPaddingAndBorderAxis(child, crossAxis) + ); + } else if (getPositionType(child) == CSS_POSITION_ABSOLUTE) { + // Pre-fill dimensions when using absolute position and both offsets for the axis are defined (either both + // left and right or top and bottom). + for (ii = 0; ii < 2; ii++) { + axis = (ii != 0) ? CSS_FLEX_DIRECTION_ROW : CSS_FLEX_DIRECTION_COLUMN; + if (!isUndefined(node->layout.dimensions[dim[axis]]) && + !isDimDefined(child, axis) && + isPosDefined(child, leading[axis]) && + isPosDefined(child, trailing[axis])) { + child->layout.dimensions[dim[axis]] = fmaxf( + boundAxis(child, axis, node->layout.dimensions[dim[axis]] - + getPaddingAndBorderAxis(node, axis) - + getMarginAxis(child, axis) - + getPosition(child, leading[axis]) - + getPosition(child, trailing[axis])), + // You never want to go smaller than padding + getPaddingAndBorderAxis(child, axis) + ); + } + } + } + } + + float definedMainDim = CSS_UNDEFINED; + if (!isUndefined(node->layout.dimensions[dim[mainAxis]])) { + definedMainDim = node->layout.dimensions[dim[mainAxis]] - + getPaddingAndBorderAxis(node, mainAxis); + } + + // We want to execute the next two loops one per line with flex-wrap + int startLine = 0; + int endLine = 0; + // int nextOffset = 0; + int alreadyComputedNextLayout = 0; + // We aggregate the total dimensions of the container in those two variables + float linesCrossDim = 0; + float linesMainDim = 0; + int linesCount = 0; + while (endLine < node->children_count) { + // Layout non flexible children and count children by type + + // mainContentDim is accumulation of the dimensions and margin of all the + // non flexible children. This will be used in order to either set the + // dimensions of the node if none already exist, or to compute the + // remaining space left for the flexible children. + float mainContentDim = 0; + + // There are three kind of children, non flexible, flexible and absolute. + // We need to know how many there are in order to distribute the space. + int flexibleChildrenCount = 0; + float totalFlexible = 0; + int nonFlexibleChildrenCount = 0; + + float maxWidth; + for (i = startLine; i < node->children_count; ++i) { + child = node->get_child(node->context, i); + float nextContentDim = 0; + + // It only makes sense to consider a child flexible if we have a computed + // dimension for the node-> + if (!isUndefined(node->layout.dimensions[dim[mainAxis]]) && isFlex(child)) { + flexibleChildrenCount++; + totalFlexible += getFlex(child); + + // Even if we don't know its exact size yet, we already know the padding, + // border and margin. We'll use this partial information, which represents + // the smallest possible size for the child, to compute the remaining + // available space. + nextContentDim = getPaddingAndBorderAxis(child, mainAxis) + + getMarginAxis(child, mainAxis); + + } else { + maxWidth = CSS_UNDEFINED; + if (!isRowDirection(mainAxis)) { + maxWidth = parentMaxWidth - + getMarginAxis(node, resolvedRowAxis) - + getPaddingAndBorderAxis(node, resolvedRowAxis); + + if (isDimDefined(node, resolvedRowAxis)) { + maxWidth = node->layout.dimensions[dim[resolvedRowAxis]] - + getPaddingAndBorderAxis(node, resolvedRowAxis); + } + } + + // This is the main recursive call. We layout non flexible children. + if (alreadyComputedNextLayout == 0) { + layoutNode(child, maxWidth, direction); + } + + // Absolute positioned elements do not take part of the layout, so we + // don't use them to compute mainContentDim + if (getPositionType(child) == CSS_POSITION_RELATIVE) { + nonFlexibleChildrenCount++; + // At this point we know the final size and margin of the element. + nextContentDim = getDimWithMargin(child, mainAxis); + } + } + + // The element we are about to add would make us go to the next line + if (isFlexWrap(node) && + !isUndefined(node->layout.dimensions[dim[mainAxis]]) && + mainContentDim + nextContentDim > definedMainDim && + // If there's only one element, then it's bigger than the content + // and needs its own line + i != startLine) { + nonFlexibleChildrenCount--; + alreadyComputedNextLayout = 1; + break; + } + alreadyComputedNextLayout = 0; + mainContentDim += nextContentDim; + endLine = i + 1; + } + + // Layout flexible children and allocate empty space + + // In order to position the elements in the main axis, we have two + // controls. The space between the beginning and the first element + // and the space between each two elements. + float leadingMainDim = 0; + float betweenMainDim = 0; + + // The remaining available space that needs to be allocated + float remainingMainDim = 0; + if (!isUndefined(node->layout.dimensions[dim[mainAxis]])) { + remainingMainDim = definedMainDim - mainContentDim; + } else { + remainingMainDim = fmaxf(mainContentDim, 0) - mainContentDim; + } + + // If there are flexible children in the mix, they are going to fill the + // remaining space + if (flexibleChildrenCount != 0) { + float flexibleMainDim = remainingMainDim / totalFlexible; + float baseMainDim; + float boundMainDim; + + // Iterate over every child in the axis. If the flex share of remaining + // space doesn't meet min/max bounds, remove this child from flex + // calculations. + for (i = startLine; i < endLine; ++i) { + child = node->get_child(node->context, i); + if (isFlex(child)) { + baseMainDim = flexibleMainDim * getFlex(child) + + getPaddingAndBorderAxis(child, mainAxis); + boundMainDim = boundAxis(child, mainAxis, baseMainDim); + + if (baseMainDim != boundMainDim) { + remainingMainDim -= boundMainDim; + totalFlexible -= getFlex(child); + } + } + } + flexibleMainDim = remainingMainDim / totalFlexible; + + // The non flexible children can overflow the container, in this case + // we should just assume that there is no space available. + if (flexibleMainDim < 0) { + flexibleMainDim = 0; + } + // We iterate over the full array and only apply the action on flexible + // children. This is faster than actually allocating a new array that + // contains only flexible children. + for (i = startLine; i < endLine; ++i) { + child = node->get_child(node->context, i); + if (isFlex(child)) { + // At this point we know the final size of the element in the main + // dimension + child->layout.dimensions[dim[mainAxis]] = boundAxis(child, mainAxis, + flexibleMainDim * getFlex(child) + getPaddingAndBorderAxis(child, mainAxis) + ); + + maxWidth = CSS_UNDEFINED; + if (isDimDefined(node, resolvedRowAxis)) { + maxWidth = node->layout.dimensions[dim[resolvedRowAxis]] - + getPaddingAndBorderAxis(node, resolvedRowAxis); + } else if (!isRowDirection(mainAxis)) { + maxWidth = parentMaxWidth - + getMarginAxis(node, resolvedRowAxis) - + getPaddingAndBorderAxis(node, resolvedRowAxis); + } + + // And we recursively call the layout algorithm for this child + layoutNode(child, maxWidth, direction); + } + } + + // We use justifyContent to figure out how to allocate the remaining + // space available + } else { + css_justify_t justifyContent = getJustifyContent(node); + if (justifyContent == CSS_JUSTIFY_CENTER) { + leadingMainDim = remainingMainDim / 2; + } else if (justifyContent == CSS_JUSTIFY_FLEX_END) { + leadingMainDim = remainingMainDim; + } else if (justifyContent == CSS_JUSTIFY_SPACE_BETWEEN) { + remainingMainDim = fmaxf(remainingMainDim, 0); + if (flexibleChildrenCount + nonFlexibleChildrenCount - 1 != 0) { + betweenMainDim = remainingMainDim / + (flexibleChildrenCount + nonFlexibleChildrenCount - 1); + } else { + betweenMainDim = 0; + } + } else if (justifyContent == CSS_JUSTIFY_SPACE_AROUND) { + // Space on the edges is half of the space between elements + betweenMainDim = remainingMainDim / + (flexibleChildrenCount + nonFlexibleChildrenCount); + leadingMainDim = betweenMainDim / 2; + } + } + + // Position elements in the main axis and compute dimensions + + // At this point, all the children have their dimensions set. We need to + // find their position. In order to do that, we accumulate data in + // variables that are also useful to compute the total dimensions of the + // container! + float crossDim = 0; + float mainDim = leadingMainDim + + getLeadingPaddingAndBorder(node, mainAxis); + + for (i = startLine; i < endLine; ++i) { + child = node->get_child(node->context, i); + child->line_index = linesCount; + + if (getPositionType(child) == CSS_POSITION_ABSOLUTE && + isPosDefined(child, leading[mainAxis])) { + // In case the child is position absolute and has left/top being + // defined, we override the position to whatever the user said + // (and margin/border). + child->layout.position[pos[mainAxis]] = getPosition(child, leading[mainAxis]) + + getLeadingBorder(node, mainAxis) + + getLeadingMargin(child, mainAxis); + } else { + // If the child is position absolute (without top/left) or relative, + // we put it at the current accumulated offset. + child->layout.position[pos[mainAxis]] += mainDim; + + // Define the trailing position accordingly. + if (!isUndefined(node->layout.dimensions[dim[mainAxis]])) { + setTrailingPosition(node, child, mainAxis); + } + } + + // Now that we placed the element, we need to update the variables + // We only need to do that for relative elements. Absolute elements + // do not take part in that phase. + if (getPositionType(child) == CSS_POSITION_RELATIVE) { + // The main dimension is the sum of all the elements dimension plus + // the spacing. + mainDim += betweenMainDim + getDimWithMargin(child, mainAxis); + // The cross dimension is the max of the elements dimension since there + // can only be one element in that cross dimension. + crossDim = fmaxf(crossDim, boundAxis(child, crossAxis, getDimWithMargin(child, crossAxis))); + } + } + + float containerCrossAxis = node->layout.dimensions[dim[crossAxis]]; + if (isUndefined(node->layout.dimensions[dim[crossAxis]])) { + containerCrossAxis = fmaxf( + // For the cross dim, we add both sides at the end because the value + // is aggregate via a max function. Intermediate negative values + // can mess this computation otherwise + boundAxis(node, crossAxis, crossDim + getPaddingAndBorderAxis(node, crossAxis)), + getPaddingAndBorderAxis(node, crossAxis) + ); + } + + // Position elements in the cross axis + for (i = startLine; i < endLine; ++i) { + child = node->get_child(node->context, i); + + if (getPositionType(child) == CSS_POSITION_ABSOLUTE && + isPosDefined(child, leading[crossAxis])) { + // In case the child is absolutely positionned and has a + // top/left/bottom/right being set, we override all the previously + // computed positions to set it correctly. + child->layout.position[pos[crossAxis]] = getPosition(child, leading[crossAxis]) + + getLeadingBorder(node, crossAxis) + + getLeadingMargin(child, crossAxis); + + } else { + float leadingCrossDim = getLeadingPaddingAndBorder(node, crossAxis); + + // For a relative children, we're either using alignItems (parent) or + // alignSelf (child) in order to determine the position in the cross axis + if (getPositionType(child) == CSS_POSITION_RELATIVE) { + css_align_t alignItem = getAlignItem(node, child); + if (alignItem == CSS_ALIGN_STRETCH) { + // You can only stretch if the dimension has not already been set + // previously. + if (!isDimDefined(child, crossAxis)) { + child->layout.dimensions[dim[crossAxis]] = fmaxf( + boundAxis(child, crossAxis, containerCrossAxis - + getPaddingAndBorderAxis(node, crossAxis) - + getMarginAxis(child, crossAxis)), + // You never want to go smaller than padding + getPaddingAndBorderAxis(child, crossAxis) + ); + } + } else if (alignItem != CSS_ALIGN_FLEX_START) { + // The remaining space between the parent dimensions+padding and child + // dimensions+margin. + float remainingCrossDim = containerCrossAxis - + getPaddingAndBorderAxis(node, crossAxis) - + getDimWithMargin(child, crossAxis); + + if (alignItem == CSS_ALIGN_CENTER) { + leadingCrossDim += remainingCrossDim / 2; + } else { // CSS_ALIGN_FLEX_END + leadingCrossDim += remainingCrossDim; + } + } + } + + // And we apply the position + child->layout.position[pos[crossAxis]] += linesCrossDim + leadingCrossDim; + + // Define the trailing position accordingly. + if (!isUndefined(node->layout.dimensions[dim[crossAxis]])) { + setTrailingPosition(node, child, crossAxis); + } + } + } + + linesCrossDim += crossDim; + linesMainDim = fmaxf(linesMainDim, mainDim); + linesCount += 1; + startLine = endLine; + } + + // + // + // Note(prenaux): More than one line, we need to layout the crossAxis + // according to alignContent. + // + // Note that we could probably remove and handle the one line case + // here too, but for the moment this is safer since it won't interfere with + // previously working code. + // + // See specs: + // http://www.w3.org/TR/2012/CR-css3-flexbox-20120918/#layout-algorithm + // section 9.4 + // + if (linesCount > 1 && + !isUndefined(node->layout.dimensions[dim[crossAxis]])) { + float nodeCrossAxisInnerSize = node->layout.dimensions[dim[crossAxis]] - + getPaddingAndBorderAxis(node, crossAxis); + float remainingAlignContentDim = nodeCrossAxisInnerSize - linesCrossDim; + + float crossDimLead = 0; + float currentLead = getLeadingPaddingAndBorder(node, crossAxis); + + css_align_t alignContent = getAlignContent(node); + if (alignContent == CSS_ALIGN_FLEX_END) { + currentLead += remainingAlignContentDim; + } else if (alignContent == CSS_ALIGN_CENTER) { + currentLead += remainingAlignContentDim / 2; + } else if (alignContent == CSS_ALIGN_STRETCH) { + if (nodeCrossAxisInnerSize > linesCrossDim) { + crossDimLead = (remainingAlignContentDim / linesCount); + } + } + + int endIndex = 0; + for (i = 0; i < linesCount; ++i) { + int startIndex = endIndex; + + // compute the line's height and find the endIndex + float lineHeight = 0; + for (ii = startIndex; ii < node->children_count; ++ii) { + child = node->get_child(node->context, ii); + if (getPositionType(child) != CSS_POSITION_RELATIVE) { + continue; + } + if (child->line_index != i) { + break; + } + if (!isUndefined(child->layout.dimensions[dim[crossAxis]])) { + lineHeight = fmaxf( + lineHeight, + child->layout.dimensions[dim[crossAxis]] + getMarginAxis(child, crossAxis) + ); + } + } + endIndex = ii; + lineHeight += crossDimLead; + + for (ii = startIndex; ii < endIndex; ++ii) { + child = node->get_child(node->context, ii); + if (getPositionType(child) != CSS_POSITION_RELATIVE) { + continue; + } + + css_align_t alignContentAlignItem = getAlignItem(node, child); + if (alignContentAlignItem == CSS_ALIGN_FLEX_START) { + child->layout.position[pos[crossAxis]] = currentLead + getLeadingMargin(child, crossAxis); + } else if (alignContentAlignItem == CSS_ALIGN_FLEX_END) { + child->layout.position[pos[crossAxis]] = currentLead + lineHeight - getTrailingMargin(child, crossAxis) - child->layout.dimensions[dim[crossAxis]]; + } else if (alignContentAlignItem == CSS_ALIGN_CENTER) { + float childHeight = child->layout.dimensions[dim[crossAxis]]; + child->layout.position[pos[crossAxis]] = currentLead + (lineHeight - childHeight) / 2; + } else if (alignContentAlignItem == CSS_ALIGN_STRETCH) { + child->layout.position[pos[crossAxis]] = currentLead + getLeadingMargin(child, crossAxis); + // TODO(prenaux): Correctly set the height of items with undefined + // (auto) crossAxis dimension. + } + } + + currentLead += lineHeight; + } + } + + bool needsMainTrailingPos = false; + bool needsCrossTrailingPos = false; + + // If the user didn't specify a width or height, and it has not been set + // by the container, then we set it via the children. + if (isUndefined(node->layout.dimensions[dim[mainAxis]])) { + node->layout.dimensions[dim[mainAxis]] = fmaxf( + // We're missing the last padding at this point to get the final + // dimension + boundAxis(node, mainAxis, linesMainDim + getTrailingPaddingAndBorder(node, mainAxis)), + // We can never assign a width smaller than the padding and borders + getPaddingAndBorderAxis(node, mainAxis) + ); + + needsMainTrailingPos = true; + } + + if (isUndefined(node->layout.dimensions[dim[crossAxis]])) { + node->layout.dimensions[dim[crossAxis]] = fmaxf( + // For the cross dim, we add both sides at the end because the value + // is aggregate via a max function. Intermediate negative values + // can mess this computation otherwise + boundAxis(node, crossAxis, linesCrossDim + getPaddingAndBorderAxis(node, crossAxis)), + getPaddingAndBorderAxis(node, crossAxis) + ); + + needsCrossTrailingPos = true; + } + + // Set trailing position if necessary + if (needsMainTrailingPos || needsCrossTrailingPos) { + for (i = 0; i < node->children_count; ++i) { + child = node->get_child(node->context, i); + + if (needsMainTrailingPos) { + setTrailingPosition(node, child, mainAxis); + } + + if (needsCrossTrailingPos) { + setTrailingPosition(node, child, crossAxis); + } + } + } + + // Calculate dimensions for absolutely positioned elements + for (i = 0; i < node->children_count; ++i) { + child = node->get_child(node->context, i); + if (getPositionType(child) == CSS_POSITION_ABSOLUTE) { + // Pre-fill dimensions when using absolute position and both offsets for the axis are defined (either both + // left and right or top and bottom). + for (ii = 0; ii < 2; ii++) { + axis = (ii != 0) ? CSS_FLEX_DIRECTION_ROW : CSS_FLEX_DIRECTION_COLUMN; + if (!isUndefined(node->layout.dimensions[dim[axis]]) && + !isDimDefined(child, axis) && + isPosDefined(child, leading[axis]) && + isPosDefined(child, trailing[axis])) { + child->layout.dimensions[dim[axis]] = fmaxf( + boundAxis(child, axis, node->layout.dimensions[dim[axis]] - + getBorderAxis(node, axis) - + getMarginAxis(child, axis) - + getPosition(child, leading[axis]) - + getPosition(child, trailing[axis]) + ), + // You never want to go smaller than padding + getPaddingAndBorderAxis(child, axis) + ); + } + } + for (ii = 0; ii < 2; ii++) { + axis = (ii != 0) ? CSS_FLEX_DIRECTION_ROW : CSS_FLEX_DIRECTION_COLUMN; + if (isPosDefined(child, trailing[axis]) && + !isPosDefined(child, leading[axis])) { + child->layout.position[leading[axis]] = + node->layout.dimensions[dim[axis]] - + child->layout.dimensions[dim[axis]] - + getPosition(child, trailing[axis]); + } + } + } + } + /** END_GENERATED **/ +} + +void layoutNode(css_node_t *node, float parentMaxWidth, css_direction_t parentDirection) { + css_layout_t *layout = &node->layout; + css_direction_t direction = node->style.direction; + layout->should_update = true; + + bool skipLayout = + !node->is_dirty(node->context) && + eq(layout->last_requested_dimensions[CSS_WIDTH], layout->dimensions[CSS_WIDTH]) && + eq(layout->last_requested_dimensions[CSS_HEIGHT], layout->dimensions[CSS_HEIGHT]) && + eq(layout->last_parent_max_width, parentMaxWidth); + eq(layout->last_direction, direction); + + if (skipLayout) { + layout->dimensions[CSS_WIDTH] = layout->last_dimensions[CSS_WIDTH]; + layout->dimensions[CSS_HEIGHT] = layout->last_dimensions[CSS_HEIGHT]; + layout->position[CSS_TOP] = layout->last_position[CSS_TOP]; + layout->position[CSS_LEFT] = layout->last_position[CSS_LEFT]; + } else { + layout->last_requested_dimensions[CSS_WIDTH] = layout->dimensions[CSS_WIDTH]; + layout->last_requested_dimensions[CSS_HEIGHT] = layout->dimensions[CSS_HEIGHT]; + layout->last_parent_max_width = parentMaxWidth; + layout->last_direction = direction; + + layoutNodeImpl(node, parentMaxWidth, parentDirection); + + layout->last_dimensions[CSS_WIDTH] = layout->dimensions[CSS_WIDTH]; + layout->last_dimensions[CSS_HEIGHT] = layout->dimensions[CSS_HEIGHT]; + layout->last_position[CSS_TOP] = layout->position[CSS_TOP]; + layout->last_position[CSS_LEFT] = layout->position[CSS_LEFT]; + } +} diff --git a/IOS/SDK/LuaViewSDK/Classes/layout/Layout.h b/IOS/SDK/LuaViewSDK/Classes/layout/Layout.h new file mode 100644 index 00000000..54d31589 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/layout/Layout.h @@ -0,0 +1,163 @@ +/** + * Copyright (c) 2014, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +#ifndef __LAYOUT_H +#define __LAYOUT_H + +#include +#ifndef __cplusplus +#include +#endif + +// Not defined in MSVC++ +#ifndef NAN +static const unsigned long __nan[2] = {0xffffffff, 0x7fffffff}; +#define NAN (*(const float *)__nan) +#endif + +#define CSS_UNDEFINED NAN + +typedef enum { + CSS_DIRECTION_INHERIT = 0, + CSS_DIRECTION_LTR, + CSS_DIRECTION_RTL +} css_direction_t; + +typedef enum { + CSS_FLEX_DIRECTION_COLUMN = 0, + CSS_FLEX_DIRECTION_COLUMN_REVERSE, + CSS_FLEX_DIRECTION_ROW, + CSS_FLEX_DIRECTION_ROW_REVERSE +} css_flex_direction_t; + +typedef enum { + CSS_JUSTIFY_FLEX_START = 0, + CSS_JUSTIFY_CENTER, + CSS_JUSTIFY_FLEX_END, + CSS_JUSTIFY_SPACE_BETWEEN, + CSS_JUSTIFY_SPACE_AROUND +} css_justify_t; + +// Note: auto is only a valid value for alignSelf. It is NOT a valid value for +// alignItems. +typedef enum { + CSS_ALIGN_AUTO = 0, + CSS_ALIGN_FLEX_START, + CSS_ALIGN_CENTER, + CSS_ALIGN_FLEX_END, + CSS_ALIGN_STRETCH +} css_align_t; + +typedef enum { + CSS_POSITION_RELATIVE = 0, + CSS_POSITION_ABSOLUTE +} css_position_type_t; + +typedef enum { + CSS_NOWRAP = 0, + CSS_WRAP +} css_wrap_type_t; + +// Note: left and top are shared between position[2] and position[4], so +// they have to be before right and bottom. +typedef enum { + CSS_LEFT = 0, + CSS_TOP, + CSS_RIGHT, + CSS_BOTTOM, + CSS_START, + CSS_END, + CSS_POSITION_COUNT +} css_position_t; + +typedef enum { + CSS_WIDTH = 0, + CSS_HEIGHT +} css_dimension_t; + +typedef struct { + float position[4]; + float dimensions[2]; + css_direction_t direction; + + // Instead of recomputing the entire layout every single time, we + // cache some information to break early when nothing changed + bool should_update; + float last_requested_dimensions[2]; + float last_parent_max_width; + float last_dimensions[2]; + float last_position[2]; + css_direction_t last_direction; +} css_layout_t; + +typedef struct { + float dimensions[2]; +} css_dim_t; + +typedef struct { + css_direction_t direction; + css_flex_direction_t flex_direction; + css_justify_t justify_content; + css_align_t align_content; + css_align_t align_items; + css_align_t align_self; + css_position_type_t position_type; + css_wrap_type_t flex_wrap; + float flex; + float margin[6]; + float position[4]; + /** + * You should skip all the rules that contain negative values for the + * following attributes. For example: + * {padding: 10, paddingLeft: -5} + * should output: + * {left: 10 ...} + * the following two are incorrect: + * {left: -5 ...} + * {left: 0 ...} + */ + float padding[6]; + float border[6]; + float dimensions[2]; + float minDimensions[2]; + float maxDimensions[2]; +} css_style_t; + +typedef struct css_node { + css_style_t style; + css_layout_t layout; + int children_count; + int line_index; + + css_dim_t (*measure)(void *context, float width); + void (*print)(void *context); + struct css_node* (*get_child)(void *context, int i); + bool (*is_dirty)(void *context); + void *context; +} css_node_t; + + +// Lifecycle of nodes and children +css_node_t *new_css_node(void); +void init_css_node(css_node_t *node); +void free_css_node(css_node_t *node); + +// Print utilities +typedef enum { + CSS_PRINT_LAYOUT = 1, + CSS_PRINT_STYLE = 2, + CSS_PRINT_CHILDREN = 4, +} css_print_options_t; +void print_css_node(css_node_t *node, css_print_options_t options); + +// Function that computes the layout! +void layoutNode(css_node_t *node, float maxWidth, css_direction_t parentDirection); +bool isUndefined(float value); + +#endif diff --git a/IOS/SDK/LuaViewSDK/Classes/layout/LayoutExtensions/JUFLXLinearLayoutView.h b/IOS/SDK/LuaViewSDK/Classes/layout/LayoutExtensions/JUFLXLinearLayoutView.h new file mode 100644 index 00000000..abbec9c9 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/layout/LayoutExtensions/JUFLXLinearLayoutView.h @@ -0,0 +1,39 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "JUFLXNode.h" + +/** + * Try to solve two kinds of problems. + * 1. Know all the child views' size and layout them, bonus this container can be autoAdjustFrame + * according to child views' size and contentInset and lineSpacing; + * 2. Know some child view's size(not all), auto flex the remain views in this container. + * + * If you want more customization, sugguest JUFLXNode, also this class is build on this, and it support it. + */ +@interface JUFLXLinearLayoutView : UIView + +@property (nonatomic, strong) NSArray *childViews; + +@property (nonatomic, assign) UIEdgeInsets contentInset; + +@property (nonatomic, assign) JUFLXLayoutDirection layoutDirection; + +/** + * If it is yes, the scrollView frame size will be changed depend on childViews' total size. + * If some views' size is not be setted, set it to be YES won't flex those pending views' size + * default is NO. + */ +@property (nonatomic, assign) BOOL autoAdjustFrameSize; + +@property (nonatomic, assign) CGFloat lineSpacing; + +- (void)layout; + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/layout/LayoutExtensions/JUFLXLinearLayoutView.m b/IOS/SDK/LuaViewSDK/Classes/layout/LayoutExtensions/JUFLXLinearLayoutView.m new file mode 100644 index 00000000..734d2f30 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/layout/LayoutExtensions/JUFLXLinearLayoutView.m @@ -0,0 +1,180 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "JUFLXLinearLayoutView.h" +#import "UIView+JUFLXNode.h" + +@implementation JUFLXLinearLayoutView { + BOOL _dirty; +} + +@synthesize contentInset = _contentInset, layoutDirection = _layoutDirection, autoAdjustFrameSize = _autoAdjustFrameSize, lineSpacing = _lineSpacing; + +- (instancetype)init { + self = [super init]; + if (self) { + [self commonInit]; + } + + return self; +} + +- (instancetype)initWithFrame:(CGRect)frame { + self = [super initWithFrame:frame]; + if (self) { + [self commonInit]; + } + + return self; +} + +- (instancetype)initWithCoder:(NSCoder *)coder { + self = [super initWithCoder:coder]; + if (self) { + [self commonInit]; + } + + return self; +} + +- (void)commonInit { + _contentInset = UIEdgeInsetsZero; + _layoutDirection = JUFLXLayoutDirectionColumn; + self.ju_flxNode.direction = _layoutDirection; + _autoAdjustFrameSize = NO; + _lineSpacing = 0; +} + +- (void)setAutoAdjustFrameSize:(BOOL)autoAdjustFrameSize { + if (_autoAdjustFrameSize == autoAdjustFrameSize) return; + + _autoAdjustFrameSize = autoAdjustFrameSize; + + CGFloat dimWidth = CGRectGetWidth(self.frame); + CGFloat dimHeight = CGRectGetHeight(self.frame); + + switch (self.layoutDirection) { + case JUFLXLayoutDirectionRow: + case JUFLXLayoutDirectionRowReverse: { + dimWidth = JUFLXLayoutFloatUnDefined; + break; + } + case JUFLXLayoutDirectionColumn: + case JUFLXLayoutDirectionColumnReverse: { + dimHeight = JUFLXLayoutFloatUnDefined; + break; + } + default: { + break; + } + } + + if (_autoAdjustFrameSize) { + self.ju_flxNode.dimensions = CGSizeMake(dimWidth, dimHeight); + } +} + +- (void)setChildViews:(NSArray *)childViews { + if ([_childViews isEqual:childViews]) return; + + _childViews = childViews; + _childViews = [_childViews filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings) { + BOOL isViewClass = [evaluatedObject isKindOfClass:[UIView class]]; + NSAssert(isViewClass, @"views should be class of UIViews"); + + return isViewClass; + }]]; + + for (UIView *view in self.childViews) { + // if the view is not support self sizing, the we flex it + if (!view.ju_flxNode.measure && view.ju_flxNode.flex == 0 && CGSizeEqualToSize(view.ju_flxNode.dimensions, CGSizeZero)) { + view.ju_flxNode.flex = 1; + } + } + + [self setNeedsUpdateChildViews]; + + self.ju_flxNode.childNodes = [self.childViews valueForKey:@"ju_flxNode"]; + + _dirty = YES; +} + +- (void)setContentInset:(UIEdgeInsets)contentInset { + if (UIEdgeInsetsEqualToEdgeInsets(_contentInset, contentInset)) return; + + _contentInset = contentInset; + [self setNeedsUpdateChildViews]; + + _dirty = YES; +} + +- (void)setLayoutDirection:(JUFLXLayoutDirection)layoutDirection { + if (_layoutDirection == layoutDirection) return; + + _layoutDirection = layoutDirection; + self.ju_flxNode.direction = _layoutDirection; + [self setNeedsUpdateChildViews]; + + _dirty = YES; +} + +- (void)setLineSpacing:(CGFloat)lineSpacing { + if (_lineSpacing == lineSpacing) return; + + _lineSpacing = lineSpacing; + [self setNeedsUpdateChildViews]; + + _dirty = YES; +} + +- (void)setNeedsUpdateChildViews { + BOOL isVerticalLayout = (self.ju_flxNode.direction == JUFLXLayoutDirectionColumn || self.ju_flxNode.direction == JUFLXLayoutDirectionColumnReverse); + [self.childViews enumerateObjectsUsingBlock:^(UIView *view, NSUInteger idx, BOOL *stop) { + UIEdgeInsets edge = UIEdgeInsetsZero; + + if (idx == 0) { + if (isVerticalLayout) { + edge = UIEdgeInsetsMake(_contentInset.top, _contentInset.left, 0, _contentInset.right); + } + else { + edge = UIEdgeInsetsMake(_contentInset.top, _contentInset.left, _contentInset.bottom, 0); + } + } + else if (idx == self.childViews.count - 1) { + if (isVerticalLayout) { + edge = UIEdgeInsetsMake(_lineSpacing, _contentInset.left, _contentInset.bottom, _contentInset.right); + } + else { + edge = UIEdgeInsetsMake(_contentInset.top, _lineSpacing, _contentInset.bottom, _contentInset.right); + } + } + else { + if (isVerticalLayout) { + edge = UIEdgeInsetsMake(_lineSpacing, _contentInset.left, 0, _contentInset.right); + } + else { + edge = UIEdgeInsetsMake(_contentInset.top, _lineSpacing, _contentInset.bottom, 0); + } + } + + view.ju_flxNode.margin = edge; + }]; +} + +- (void)setNeedsReload { + if (_dirty) { + [self layout]; + } +} + +- (void)layout { + [self.ju_flxNode layout]; + _dirty = NO; +} + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/layout/UIView+JUFLXNode.h b/IOS/SDK/LuaViewSDK/Classes/layout/UIView+JUFLXNode.h new file mode 100644 index 00000000..3e53f298 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/layout/UIView+JUFLXNode.h @@ -0,0 +1,168 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "JUFLXNode.h" + +typedef void (^NodeDidFinishLayout)(JUFLXNode *node); + +@interface UIView (JUFLXNodeGetter) + +- (JUFLXNode *)ju_flxNode; +- (BOOL)ju_hasFlxNode; +- (void)setJu_flxNodeDidFinishLayoutBlock:(NodeDidFinishLayout)block; + +@end + +@interface UIView (JUFLXNodes) + +@property (nonatomic, strong) NSArray *flx_childViews; +/** + * Default is view's frame's origin + */ +//@property (nonatomic, assign) CGPoint flx_viewOrigin; + +/* + * --------------------------------------------------------------------------- + * As Container's property + * --------------------------------------------------------------------------- + */ + +@property (nonatomic, assign) BOOL flx_absolute; + +@property (nonatomic, assign) UIEdgeInsets flx_absoluteEdgeInsets; + +/** + * Check -> http://www.w3.org/TR/css3-flexbox/#flex-direction-property + * inlineCSS -> flex-direction + * Default is row + */ +@property (nonatomic, assign) JUFLXLayoutDirection flx_direction; + +/** + * Check -> http://www.w3.org/TR/css3-flexbox/#propdef-align-items + * inlineCSS -> align-items + * Default is stretch + */ +@property (nonatomic, assign) JUFLXLayoutAlignment flx_alignItems; + +/** + * Check -> http://www.w3.org/TR/css3-flexbox/#propdef-align-content + * inlineCSS -> align-content + * Default is stretch + * Here we don't support the between and around + */ +@property (nonatomic, assign) JUFLXLayoutAlignment flx_alignContent; + +/** + * Check -> http://www.w3.org/TR/css3-flexbox/#propdef-justify-content + * inlineCSS -> justify-content + * Default is start + */ +@property (nonatomic, assign) JUFLXLayoutJustifyContent flx_justifyContent; + +/** + * Check -> http://www.w3.org/TR/css3-flexbox/#flex-wrap-property + * When the container size doesn't satisfy, if use a new depends on this. + * inlineCSS -> flex-wrap + * Here we don't support wrap-reverse + */ +@property (nonatomic, assign) BOOL flx_flexWrap; + + +/* + * --------------------------------------------------------------------------- + * As Child's property + * --------------------------------------------------------------------------- + */ + +/** + * Check -> http://www.w3.org/TR/css3-flexbox/#propdef-align-self + * inlineCSS -> align-self + * Default is auto, means depend on containers' alignItems; + */ +@property (nonatomic, assign) JUFLXLayoutAlignment flx_alignSelf; + +/** + * Means two thing: 1. If self use the remaining space 2. how much would u share with others + * Flex-grow, eg: A node has three children---a,b,c; a.flex = 1, b.flex = 2, c.flex = 1, then a's size will be 1 / (1 + 2 + 1), + * b is 2 / (1 + 2 + 1), c is 1 / (1 + 2 + 1) + * inlineCSS -> flex + * Here we only support flex-grow as flex, not include shrink. + * Default is 0 + */ +@property (nonatomic, assign) CGFloat flx_flex; + +/* + * --------------------------------------------------------------------------- + * As box's property + * --------------------------------------------------------------------------- + */ + +/** + * The style dimensions, default is the view's size, if you set it to {nan, nan}, + * The result frame depends on children's total size, so the children's size should be measured. + * inlineCSS ->size, width, height + * It won't be affected by JUFLXLayoutAlignment + */ +@property (nonatomic, assign) CGSize flx_dimensions; + +/** + * ensure the min dimension of the view size. + * inlineCSS -> min-width, min-height + * Default is {0,0} + */ +@property (nonatomic, assign) CGSize flx_minDimensions; + +/** + * ensure the max dimension of the view size. + * inlineCSS -> max-width, max-height + * Default is {0,0} + */ +@property (nonatomic, assign) CGSize flx_maxDimensions; + +/** + * The margin of the view. + * inlineCSS -> margin, margin-top, margin-left, margin-bottom, margin-right + */ +@property (nonatomic, assign) UIEdgeInsets flx_margin; + +/** + * The padding of the view. + * inlineCSS -> padding, padding-top, padding-left, padding-bottom, padding-right + */ +@property (nonatomic, assign) UIEdgeInsets flx_padding; + +/** + * When encouter the view size should be calculated like text size, use this block. + * If direction is row, then width is the parent's node's frame's width, otherwise is nan. + * It will be affected by JUFLXLayoutAlignment + */ +@property (nonatomic, copy) CGSize (^flx_measure)(CGFloat width); + +/** + * If isSizeToFit == YES, the measure block CGSize (^measure)(CGFloat width) will returned by view's + * sizeThatFits: size, the property will be override by measure block; + * Default is YES; + * It will be affected by JUFLXLayoutAlignment + * inlineCSS -> sizetofit: 1 + */ +@property (nonatomic, assign) BOOL flx_sizeToFit; + +- (void)flx_bindingInlineCSS:(NSString *)inlineCSS; + +- (void)flx_layout; + +- (void)flx_layoutAsync:(BOOL)async; + +- (void)flx_layoutAsync:(BOOL)async completion:(void(^)(CGRect frame))block; + +@end + +FOUNDATION_EXTERN NSString * const JUFLXNodeUIViewNodeKey; +FOUNDATION_EXTERN NSString * const JUFLXNodeUIViewDidFinishBlockKey; diff --git a/IOS/SDK/LuaViewSDK/Classes/layout/UIView+JUFLXNode.m b/IOS/SDK/LuaViewSDK/Classes/layout/UIView+JUFLXNode.m new file mode 100644 index 00000000..0a6533a1 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/layout/UIView+JUFLXNode.m @@ -0,0 +1,191 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "UIView+JUFLXNode.h" +#import +#import "JUFLXNode.h" + +NSString * const JUFLXNodeUIViewNodeKey = @"hrnode.JUFLXNodeUIViewNodeKey"; +NSString * const JUFLXNodeUIViewDidFinishBlockKey = @"hrnode.JUFLXNodeUIViewDidFinishBlockKey"; + +@implementation UIView (JUFLXNodeGetter) + +- (JUFLXNode *)ju_flxNode { + JUFLXNode *node = objc_getAssociatedObject(self, &JUFLXNodeUIViewNodeKey); + if (!node) { + node = [JUFLXNode nodeWithView:self]; + } + return node; +} + +- (BOOL)ju_hasFlxNode { + JUFLXNode *node = objc_getAssociatedObject(self, &JUFLXNodeUIViewNodeKey); + return node != nil; +} + +- (void)setJu_flxNodeDidFinishLayoutBlock:(NodeDidFinishLayout)block { + objc_setAssociatedObject(self, &JUFLXNodeUIViewDidFinishBlockKey, block, OBJC_ASSOCIATION_COPY_NONATOMIC); +} + +@end + +@implementation UIView (JUFLXNodes) + +- (NSArray *)flx_childViews { + return [self.ju_flxNode.childNodes valueForKey:@"view"]; +} + +- (void)setFlx_childViews:(NSArray *)flx_childViews { + self.ju_flxNode.childNodes = [flx_childViews valueForKey:@"ju_flxNode"]; +} + +- (UIEdgeInsets)flx_absoluteEdgeInsets { + return self.ju_flxNode.absoluteEdges; +} + +- (void)setFlx_absoluteEdgeInsets:(UIEdgeInsets)flx_absoluteEdgeInsets { + self.ju_flxNode.absoluteEdges = flx_absoluteEdgeInsets; +} + +- (BOOL)flx_absolute { + return self.ju_flxNode.absolute; +} + +- (void)setFlx_absolute:(BOOL)flx_absolute { + self.ju_flxNode.absolute = flx_absolute; +} + +- (JUFLXLayoutDirection)flx_direction { + return self.ju_flxNode.direction; +} + +- (void)setFlx_direction:(JUFLXLayoutDirection)flx_direction { + self.ju_flxNode.direction = flx_direction; +} + +- (JUFLXLayoutAlignment)flx_alignItems { + return self.ju_flxNode.alignItems; +} + +- (void)setFlx_alignItems:(JUFLXLayoutAlignment)flx_alignItems { + self.ju_flxNode.alignItems = flx_alignItems; +} + +- (JUFLXLayoutAlignment)flx_alignContent { + return self.ju_flxNode.alignContent; +} + +- (void)setFlx_alignContent:(JUFLXLayoutAlignment)flx_alignContent { + self.ju_flxNode.alignContent = flx_alignContent; +} + +- (JUFLXLayoutJustifyContent)flx_justifyContent { + return self.ju_flxNode.justifyContent; +} + +- (void)setFlx_justifyContent:(JUFLXLayoutJustifyContent)flx_justifyContent { + self.ju_flxNode.justifyContent = flx_justifyContent; +} + +- (BOOL)flx_flexWrap { + return self.ju_flxNode.flexWrap; +} + +- (void)setFlx_flexWrap:(BOOL)flx_flexWrap { + self.ju_flxNode.flexWrap = flx_flexWrap; +} + +- (JUFLXLayoutAlignment)flx_alignSelf { + return self.ju_flxNode.alignSelf; +} + +- (void)setFlx_alignSelf:(JUFLXLayoutAlignment)flx_alignSelf { + self.ju_flxNode.alignSelf = flx_alignSelf; +} + +- (CGFloat)flx_flex { + return self.ju_flxNode.flex; +} + +- (void)setFlx_flex:(CGFloat)flx_flex { + self.ju_flxNode.flex = flx_flex; +} + +- (CGSize)flx_dimensions { + return self.ju_flxNode.dimensions; +} + +-(void)setFlx_dimensions:(CGSize)flx_dimensions { + self.ju_flxNode.dimensions = flx_dimensions; +} + +- (CGSize)flx_minDimensions { + return self.ju_flxNode.minDimensions; +} + +- (void)setFlx_minDimensions:(CGSize)flx_minDimensions { + self.ju_flxNode.minDimensions = flx_minDimensions; +} + +- (CGSize)flx_maxDimensions { + return self.ju_flxNode.maxDimensions; +} + +- (void)setFlx_maxDimensions:(CGSize)flx_maxDimensions { + self.ju_flxNode.maxDimensions = flx_maxDimensions; +} + +- (UIEdgeInsets)flx_margin { + return self.ju_flxNode.margin; +} + +- (void)setFlx_margin:(UIEdgeInsets)flx_margin { + self.ju_flxNode.margin = flx_margin; +} + +- (UIEdgeInsets)flx_padding { + return self.ju_flxNode.padding; +} + +- (void)setFlx_padding:(UIEdgeInsets)flx_padding { + self.ju_flxNode.padding = flx_padding; +} + +- (void)setFlx_measure:(CGSize (^)(CGFloat))flx_measure { + self.ju_flxNode.measure = flx_measure; +} + +- (CGSize (^)(CGFloat))flx_measure { + return self.ju_flxNode.measure; +} + +- (BOOL)flx_sizeToFit { + return self.ju_flxNode.isSizeToFit; +} + +- (void)setFlx_sizeToFit:(BOOL)flx_sizeToFit { + self.ju_flxNode.sizeToFit = flx_sizeToFit; +} + +- (void)flx_bindingInlineCSS:(NSString *)inlineCSS { + [self.ju_flxNode bindingInlineCSS:inlineCSS]; +} + +- (void)flx_layout { + [self.ju_flxNode layout]; +} + +- (void)flx_layoutAsync:(BOOL)async { + [self.ju_flxNode layoutAsync:async]; +} + +- (void)flx_layoutAsync:(BOOL)async completion:(void(^)(CGRect frame))block { + [self.ju_flxNode layoutAsync:async completionBlock:block]; +} + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvdebug/LVDebugConnection.h b/IOS/SDK/LuaViewSDK/Classes/lvdebug/LVDebugConnection.h new file mode 100644 index 00000000..886a2fce --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvdebug/LVDebugConnection.h @@ -0,0 +1,41 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + +#ifdef DEBUG +//--------------------------------------------------------- +@interface LVDebugConnection : NSObject + +@property (nonatomic,assign) BOOL printToServer; +@property (nonatomic,weak) LuaViewCore* lview; +@property (atomic,strong) NSMutableArray* receivedArray; + +- (BOOL) isOk; + +- (NSString*) getCmd; + +- (NSInteger) waitUntilConnectionEnd; + +- (void) sendCmd:(NSString*) cmdName info:(NSString*) info; +- (void) sendCmd:(NSString*) cmdName info:(NSString*) info args:(NSDictionary*) args; +- (void) sendCmd:(NSString*) cmdName fileName:(NSString*)fileName info:(NSString*) info; +- (void) sendCmd:(NSString*) cmdName fileName:(NSString*)fileName info:(NSString*) info args:(NSDictionary*) args; + +-(void) closeAll; + +// 设置调试器的IP和端口, 用于远程调试 ++(void) setDebugerIP:(NSString*) ip port:(int) port; + ++(void) openUrlServer:( void(^)(NSDictionary* args) ) callback; + +@end + +//--------------------------------------------------------- +#endif diff --git a/IOS/SDK/LuaViewSDK/Classes/lvdebug/LVDebugConnection.m b/IOS/SDK/LuaViewSDK/Classes/lvdebug/LVDebugConnection.m new file mode 100644 index 00000000..1d3eae89 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvdebug/LVDebugConnection.m @@ -0,0 +1,350 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVDebugConnection.h" +#import +#import +#import +#import +#import +#import +#import +#import +#import "LVUtil.h" +#import "LView.h" + +#ifdef DEBUG +//--------------------------------------------------------- + +#define SOCKET_ERROR (-1) +#define SOCKET_CONNECTINTG (0) +#define SOCKET_SUCCESS (1) + +// 调试器的默认IP和端口 +static NSString* SERVER_IP = @"127.0.0.1"; +static int SERVER_PORT = 9876; + +@interface LVDebugConnection () +@property(nonatomic,strong) NSThread* myThread; +@property(nonatomic,assign) BOOL canWrite; +@property(nonatomic,assign) NSInteger state; +@property(atomic,strong) NSMutableArray* sendArray; +@end + +@implementation LVDebugConnection{ + CFSocketRef _socket; +} + +-(id) init{ + self = [super init]; + if( self ) { + static int index = 0; + self.myThread = [[NSThread alloc] initWithTarget:self selector:@selector(run:) object:nil]; + self.myThread.name = [NSString stringWithFormat:@"LuaView.Debuger.%d",index]; + self.sendArray = [[NSMutableArray alloc] init]; + self.receivedArray = [[NSMutableArray alloc] init]; + [self startThread]; + } + return self; +} + +- (void) dealloc{ + [self closeAll]; +} + +-(BOOL) isOk{ + return self.state>0; +} +- (NSInteger) waitUntilConnectionEnd{ + for(;self.state==SOCKET_CONNECTINTG;) { + [NSThread sleepForTimeInterval:0.01]; + } + return self.state; +} + +-(void) startThread{ + [self.myThread start]; //启动线程 +} + ++(void) setDebugerIP:(NSString*) ip port:(int) port{ + SERVER_IP = ip; + SERVER_PORT = port; +} + +-(void) run:(id) obj{ + @autoreleasepool { + [self Connect:SERVER_IP port:SERVER_PORT]; + + NSRunLoop *runLoop = [NSRunLoop currentRunLoop]; + [runLoop addPort:[NSMachPort port] forMode:NSDefaultRunLoopMode]; + [runLoop run]; + } +} + +- (NSString*) getCmd{ + NSString* cmd = self.receivedArray.lastObject; + if( cmd ) { + [self.receivedArray removeLastObject]; + } + return cmd; +} + +- (void) sendCmd:(NSString*) cmdName info:(NSString*) info{ + [self sendCmd:cmdName fileName:nil info:info]; +} + +- (void) sendCmd:(NSString*) cmdName info:(NSString*) info args:(NSDictionary*) args{ + [self sendCmd:cmdName fileName:nil info:info args:args]; +} + +- (void) sendCmd:(NSString*) cmdName fileName:(NSString*)fileName info:(NSString*) info{ + [self sendCmd:cmdName fileName:fileName info:info args:nil]; +} + +- (void) sendCmd:(NSString*) cmdName fileName:(NSString*)fileName info:(NSString*) info args:(NSDictionary*) args{ + NSMutableString* buffer = [[NSMutableString alloc] init]; + if ( cmdName ) { + [buffer appendFormat:@"Cmd-Name:%@\n",cmdName]; + } + if ( fileName ){ + [buffer appendFormat:@"File-Name:%@\n",fileName]; + } + NSArray* keys = args.allKeys; + for( int i=0; i0) { + LVLog(@"[调试日志][收到指令] %@ ", cmd); + [debuger.receivedArray insertObject:cmd atIndex:0]; + } + // 关闭掉socket + if ( cmd.length<=0 ){ + [debuger closeAll]; + [debuger.receivedArray insertObject:@"close" atIndex:0]; + [debuger.receivedArray insertObject:@"close" atIndex:0]; + } else { + [debuger.lview callLuaToExecuteServerCmd]; + } + break; + } + case kCFSocketWriteCallBack: { + debuger.canWrite = YES; + [debuger sendOneData]; + break; + } + case kCFSocketConnectCallBack: + if( data ) { + // LVLog(@"Debuger Socket Connect failed" ); + debuger.state = SOCKET_ERROR; + } else { + LVLog(@"Debuger Socket connect Success"); + debuger.state = SOCKET_SUCCESS; + } + break; + default: { + LVLog(@"connect type %d", (int)type ); + break; + } + } +} + + +-(void) sendOneData{ + NSData* data = self.sendArray.lastObject; + if( self.canWrite && data) { + [self.sendArray removeLastObject]; + if( data ) { + NSInteger sendLength = send(CFSocketGetNative(_socket), data.bytes, data.length, 0); + if( sendLength!=data.length ) { + LVError(@"Debuger socket Send length Error : %d != %d", (int)sendLength, (int)data.length); + } + } + } +} + +///////////////////监听来自服务器的信息/////////////////// + + +static NSString* readString(CFSocketRef socket) +{ + unsigned char head[4] = {0}; + NSUInteger readLength0 = 0; + if( recv( CFSocketGetNative(socket), head, sizeof(head), 0 )==sizeof(head) ) { + NSUInteger d0 = head[0]; + NSUInteger d1 = head[1]; + NSUInteger d2 = head[2]; + NSUInteger d3 = head[3]; + readLength0 = (d0<<24) + (d1<<16) + (d2<<8) + d3; + } + + unsigned char buffer[512] = {0}; + NSUInteger readLen = readLength0; + NSMutableData* data = [[NSMutableData alloc] init]; + for(;readLen>0;){ + NSUInteger bufferLen = readLen>=sizeof(buffer)?sizeof(buffer):readLen; + NSUInteger recvLen = recv( CFSocketGetNative(socket), buffer, bufferLen, 0 ); + if ( recvLen>0 ) { + [data appendBytes:buffer length:recvLen]; + readLen -= recvLen; + } else { + break; + } + } + NSString* ret = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; + return ret; +} + +/////////////////////////发送信息给服务器//////////////////////// +- (void) sendString:(NSString *)string +{ + if( self.canWrite ) { + NSData* data = [string dataUsingEncoding:NSUTF8StringEncoding]; + NSUInteger len = data.length; + NSMutableData* buffer = [[NSMutableData alloc] init]; + unsigned char head[4] = {0}; + head[0] = (len>>24); + head[1] = (len>>16); + head[2] = (len>>8); + head[3] = (len); + [buffer appendBytes:head length:4]; + [buffer appendData:data]; + + [self.sendArray insertObject:buffer atIndex:0]; + + [self sendOneData]; + } +} + + ++ (id)jsonObject:(NSString *)s{ + NSData* data = [s dataUsingEncoding:NSUTF8StringEncoding]; + @try { + NSError *error = nil; + NSJSONReadingOptions options = 0; + id obj = [NSJSONSerialization JSONObjectWithData:data options:options error:&error]; + if (error) { + return nil; + } + return obj; + } @catch (NSException *exception) { + return nil; + } +} + ++(void) openUrlServer:( void(^)(NSDictionary* args) ) callback{ + dispatch_async(dispatch_get_global_queue(0, 0), ^{ + // 处理耗时操作的代码块... + + LVDebugConnection* debugConnection = [[LVDebugConnection alloc] init]; + if( [debugConnection waitUntilConnectionEnd]>0 ) { + [debugConnection sendCmd:@"debugger" info:@"true"]; + for(;;) { + NSString* cmd = [debugConnection getCmd]; + if( cmd ) { + NSDictionary* dic = [LVDebugConnection jsonObject:cmd]; + if( dic && [dic isKindOfClass:[NSDictionary class]] ) { + //通知主线程刷新 + dispatch_async(dispatch_get_main_queue(), ^{ + //回调或者说是通知主线程刷新, + if( callback ) { + callback( dic ); + } + }); + } + break; + } else { + [NSThread sleepForTimeInterval:0.1]; + } + } + [debugConnection closeAll]; + } else { + [debugConnection closeAll]; + } + + }); +} + + + + +@end + +//--------------------------------------------------------- +#endif diff --git a/IOS/SDK/LuaViewSDK/Classes/lvdebug/LVDebugLua.m b/IOS/SDK/LuaViewSDK/Classes/lvdebug/LVDebugLua.m new file mode 100644 index 00000000..84d0d6be --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvdebug/LVDebugLua.m @@ -0,0 +1,763 @@ + + +#ifdef DEBUG + +// debug.lua +char g_debug_lua[10674] = { + '_','D','E','B','U','G','_','F','I','L','E',' ','=',' ','"','d','e','b','u','g','.','l','u','a','"',0xa, + // _DEBUG_FILE = "debug.lua" + 0xa, + 'd','e','b','u','g','.','b','p','s',' ','=',' ','{',0xa, + // debug.bps = { + ' ',' ',' ',' ','m','a','x',' ','=',' ','0',',',0xa, + // max = 0, + ' ',' ',' ',' ','t','r','a','c','e',' ','=',' ','f','a','l','s','e',',',0xa, + // trace = false, + ' ',' ',' ',' ','l','a','s','t','_','c','m','d',' ','=',' ','"','"',',',0xa, + // last_cmd = "", + ' ',' ',' ',' ','n','e','x','t',' ','=',' ','f','a','l','s','e',',',0xa, + // next = false, + ' ',' ',' ',' ','c','u','r','_','f','u','n','c',' ','=',' ','n','i','l',',',0xa, + // cur_func = nil, + ' ',' ',' ',' ','t','r','a','c','e','_','c','o','u','n','t',' ','=',' ','0',',',0xa, + // trace_count = 0, + ' ',' ',' ',' ','v','a','r','_','t','b','l',' ','=',' ','n','i','l',',',0xa, + // var_tbl = nil, + '}',0xa, + // } + 0xa, + 'f','u','n','c','t','i','o','n',' ','d','e','b','u','g','_','l','o','g','(',' ','l','o','g','_','s','t','r',' ',')',0xa, + // function debug_log( log_str ) + ' ',' ',' ',' ','p','r','i','n','t','(',' ','"','[','L','u','a','V','i','e','w',']','[',0xe8,0xb0,0x83,0xe8,0xaf,0x95,0xe6,0x97,0xa5,0xe5,0xbf,0x97,']',' ','"',' ','.','.',' ','l','o','g','_','s','t','r',' ',')',';',0xa, + // print( "[LuaView][调试日志] " .. log_str ); + 'e','n','d',0xa, + // end + 0xa, + 'f','u','n','c','t','i','o','n',' ','d','e','b','u','g','_','p','r','i','n','t','_','v','a','r','_','0','(',' ','n','a','m','e',',',' ','v','a','l','u','e',',',' ','l','e','v','e','l',' ',')',0xa, + // function debug_print_var_0( name, value, level ) + ' ',' ',' ',' ','l','o','c','a','l',' ','r','e','t',' ','=',' ','"','"',';',0xa, + // local ret = ""; + ' ',' ',' ',' ','l','o','c','a','l',' ','p','r','e','f','i','x',' ','=',' ','s','t','r','i','n','g','.','r','e','p','(',' ','"',' ',' ',' ',' ','"',',',' ','l','e','v','e','l',' ',')',0xa, + // local prefix = string.rep( " ", level ) + ' ',' ',' ',' ','l','o','c','a','l',' ','s','t','r',' ','=',' ','s','t','r','i','n','g','.','f','o','r','m','a','t','(',' ','"','%','s','%','s',' ','=',' ','%','s','"',',',' ','p','r','e','f','i','x',',',' ','n','a','m','e',',',' ','t','o','s','t','r','i','n','g','(','v','a','l','u','e',')',' ',')',0xa, + // local str = string.format( "%s%s = %s", prefix, name, tostring(value) ) + 0xa, + ' ',' ',' ',' ','i','f',' ','t','y','p','e','(',' ','v','a','l','u','e',' ',')',' ','=','=',' ','"','t','a','b','l','e','"',' ','t','h','e','n',0xa, + // if type( value ) == "table" then + ' ',' ',' ',' ',' ',' ',' ',' ','i','f',' ','d','e','b','u','g','.','v','a','r','_','t','b','l','[','v','a','l','u','e',']',' ','t','h','e','n',0xa, + // if debug.var_tbl[value] then + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','-','-',0xe5,0xb7,0xb2,0xe5,0x9c,0xa8,0xe4,0xb8,0xb4,0xe6,0x97,0xb6,0xe8,0xa1,0xa8,0xe4,0xb8,0xad,0xe7,0x9a,0x84,',',0xe5,0x8f,0xaa,0xe6,0x89,0x93,0xe5,0x8d,0xb0,0xe8,0xa1,0xa8,0xe5,0x9c,0xb0,0xe5,0x9d,0x80,0xa, + // --已在临时表中的,只打印表地址 + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','r','e','t',' ','=',' ','r','e','t',' ','.','.',' ','t','o','s','t','r','i','n','g','(','s','t','r',')',' ','.','.',' ',0x27,0x5c,'n',0x27,';',0xa, + // ret = ret .. tostring(str) .. '\n'; + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','r','e','t','u','r','n',' ','r','e','t',';',0xa, + // return ret; + ' ',' ',' ',' ',' ',' ',' ',' ','e','n','d',0xa, + // end + 0xa, + ' ',' ',' ',' ',' ',' ',' ',' ','-','-',0xe5,0x8a,0xa0,0xe5,0x88,0xb0,0xe4,0xb8,0xb4,0xe6,0x97,0xb6,0xe8,0xa1,0xa8,0xe4,0xb8,0xad,',',0xe4,0xbb,0xa5,0xe5,0x85,0x8d,0xe8,0xa1,0xa8,0xe5,0x87,0xba,0xe7,0x8e,0xb0,0xe5,0xbe,0xaa,0xe7,0x8e,0xaf,0xe5,0xbc,0x95,0xe7,0x94,0xa8,0xe6,0x97,0xb6,',',0xe6,0x89,0x93,0xe5,0x8d,0xb0,0xe4,0xb9,0x9f,0xe4,0xba,0xa7,0xe7,0x94,0x9f,0xe6,0xad,0xbb,0xe5,0xbe,0xaa,0xe7,0x8e,0xaf,0xa, + // --加到临时表中,以免表出现循环引用时,打印也产生死循环 + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','.','v','a','r','_','t','b','l','[','v','a','l','u','e',']',' ','=',' ','t','r','u','e',0xa, + // debug.var_tbl[value] = true + ' ',' ',' ',' ',' ',' ',' ',' ','-','-',0xe6,0x89,0x93,0xe5,0x8d,0xb0,0xe8,0xa1,0xa8,0xe4,0xb8,0xad,0xe6,0x89,0x80,0xe6,0x9c,0x89,0xe6,0x95,0xb0,0xe6,0x8d,0xae,0xa, + // --打印表中所有数据 + ' ',' ',' ',' ',' ',' ',' ',' ','r','e','t',' ','=',' ','r','e','t',' ','.','.',' ','s','t','r','i','n','g','.','f','o','r','m','a','t','(',' ','"','%','s','%','s',' ','=',' ','{','"',',',' ','p','r','e','f','i','x',',',' ','n','a','m','e',' ',')',' ','.','.',' ',0x27,0x5c,'n',0x27,';',0xa, + // ret = ret .. string.format( "%s%s = {", prefix, name ) .. '\n'; + ' ',' ',' ',' ',' ',' ',' ',' ','f','o','r',' ','k',',',' ','v',' ','i','n',' ','p','a','i','r','s','(',' ','v','a','l','u','e',' ',')',' ','d','o',0xa, + // for k, v in pairs( value ) do + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','i','f',' ','t','y','p','e','(',' ','k',' ',')',' ','=','=',' ','"','s','t','r','i','n','g','"',' ','t','h','e','n',0xa, + // if type( k ) == "string" then + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','e','l','s','e',0xa, + // else + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','k',' ','=',' ','t','o','s','t','r','i','n','g','(','k',')',';',0xa, + // k = tostring(k); + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','-','-',0xe4,0xb8,0x8d,0xe6,0x89,0x93,0xe5,0x8d,0xb0,' ','"','_','"',0xe5,0xbc,0x80,0xe5,0xa4,0xb4,0xe7,0x9a,0x84,0xe5,0x86,0x85,0xe9,0x83,0xa8,0xe5,0x8f,0x98,0xe9,0x87,0x8f,0xa, + // --不打印 "_"开头的内部变量 + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','-','-','i','f',' ','s','t','r','i','n','g','.','s','u','b','(',' ','k',',',' ','1',',',' ','1',' ',')',' ','~','=',' ','"','_','"',' ','t','h','e','n',0xa, + // --if string.sub( k, 1, 1 ) ~= "_" then + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','r','e','t',' ','=',' ','r','e','t',' ','.','.',' ','d','e','b','u','g','_','p','r','i','n','t','_','v','a','r','_','0','(',' ','k',',',' ','v',',',' ','l','e','v','e','l',' ','+',' ','1',' ',')',0xa, + // ret = ret .. debug_print_var_0( k, v, level + 1 ) + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','-','-','e','n','d',0xa, + // --end + ' ',' ',' ',' ',' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ',' ',' ',' ',' ','r','e','t',' ','=',' ','r','e','t',' ','.','.',' ','p','r','e','f','i','x',' ','.','.',' ','"','}','"',' ','.','.',' ',0x27,0x5c,'n',0x27,';',0xa, + // ret = ret .. prefix .. "}" .. '\n'; + ' ',' ',' ',' ','e','l','s','e','i','f',' ','t','y','p','e','(',' ','v','a','l','u','e',' ',')',' ','=','=',' ','"','s','t','r','i','n','g','"',' ','t','h','e','n',0xa, + // elseif type( value ) == "string" then + ' ',' ',' ',' ',' ',' ',' ',' ','r','e','t',' ','=',' ','r','e','t',' ','.','.',' ','t','o','s','t','r','i','n','g','(','s','t','r',')',' ','.','.',' ',0x27,0x5c,'n',0x27,';',0xa, + // ret = ret .. tostring(str) .. '\n'; + ' ',' ',' ',' ','e','l','s','e',0xa, + // else + ' ',' ',' ',' ',' ',' ',' ',' ','r','e','t',' ','=',' ','r','e','t',' ','.','.',' ','t','o','s','t','r','i','n','g','(','s','t','r',')',' ','.','.',' ',0x27,0x5c,'n',0x27,';',0xa, + // ret = ret .. tostring(str) .. '\n'; + ' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ','r','e','t','u','r','n',' ','r','e','t',';',0xa, + // return ret; + 'e','n','d',0xa, + // end + 0xa, + 'f','u','n','c','t','i','o','n',' ','d','e','b','u','g','_','p','r','i','n','t','_','v','a','r','(',' ','n','a','m','e',',',' ','v','a','l','u','e',',',' ','l','e','v','e','l',' ',')',0xa, + // function debug_print_var( name, value, level ) + ' ',' ',' ',' ','l','o','c','a','l',' ','s',' ','=',' ','d','e','b','u','g','_','p','r','i','n','t','_','v','a','r','_','0','(',' ','n','a','m','e',',',' ','v','a','l','u','e',',',' ','l','e','v','e','l',' ',')',';',0xa, + // local s = debug_print_var_0( name, value, level ); + ' ',' ',' ',' ','i','f','(',' ','s',' ',')',' ','t','h','e','n',0xa, + // if( s ) then + ' ',' ',' ',' ',' ',' ',' ',' ','s',' ','=',' ','s',':','s','u','b','(','1',',',' ','s',':','l','e','n','(',')','-','1',' ',')',';',0xa, + // s = s:sub(1, s:len()-1 ); + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','l','o','g','(',' ','s',' ',')',';',0xa, + // debug_log( s ); + ' ',' ',' ',' ','e','l','s','e',0xa, + // else + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','l','o','g','(',' ','s',' ',')',';',0xa, + // debug_log( s ); + ' ',' ',' ',' ','e','n','d',0xa, + // end + 'e','n','d',0xa, + // end + 0xa, + 'f','u','n','c','t','i','o','n',' ','d','e','b','u','g','_','p','r','i','n','t','_','e','x','p','r','(',' ','v','a','r',' ',')',0xa, + // function debug_print_expr( var ) + ' ',' ',' ',' ','i','f',' ','(',' ','v','a','r','=','=','n','i','l',' ',')',' ','t','h','e','n',0xa, + // if ( var==nil ) then + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','l','o','g','(','"','d','e','b','u','g','_','p','r','i','n','t','_','e','x','p','r',' ','v','a','r','=','=','n','i','l','"',')',';',0xa, + // debug_log("debug_print_expr var==nil"); + ' ',' ',' ',' ',' ',' ',' ',' ','r','e','t','u','r','n',';',0xa, + // return; + ' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ','-','-',0xe6,0xb8,0x85,0xe7,0xa9,0xba,0xe4,0xb8,0xb4,0xe6,0x97,0xb6,0xe5,0x8f,0x98,0xe9,0x87,0x8f,0xe8,0xa1,0xa8,0xa, + // --清空临时变量表 + ' ',' ',' ',' ','d','e','b','u','g','.','v','a','r','_','t','b','l',' ','=',' ','{','}',0xa, + // debug.var_tbl = {} + 0xa, + ' ',' ',' ',' ','l','o','c','a','l',' ','i','n','d','e','x',' ','=',' ','1',0xa, + // local index = 1 + ' ',' ',' ',' ','-','-',0xe6,0x89,0xbe,0xe5,0xb1,0x80,0xe9,0x83,0xa8,0xe5,0x8f,0x98,0xe9,0x87,0x8f,0xa, + // --找局部变量 + ' ',' ',' ',' ','w','h','i','l','e',' ','t','r','u','e',' ','d','o',0xa, + // while true do + ' ',' ',' ',' ',' ',' ',' ',' ','l','o','c','a','l',' ','n','a','m','e',',',' ','v','a','l','u','e',' ','=',' ','d','e','b','u','g','.','g','e','t','l','o','c','a','l','(',' ','4',',',' ','i','n','d','e','x',' ',')',0xa, + // local name, value = debug.getlocal( 4, index ) + ' ',' ',' ',' ',' ',' ',' ',' ','i','f',' ','n','o','t',' ','n','a','m','e',' ','t','h','e','n',' ',0xa, + // if not name then + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','b','r','e','a','k',' ',0xa, + // break + ' ',' ',' ',' ',' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ',' ',' ',' ',' ','i','n','d','e','x',' ','=',' ','i','n','d','e','x',' ','+',' ','1',0xa, + // index = index + 1 + 0xa, + ' ',' ',' ',' ',' ',' ',' ',' ','i','f',' ','n','a','m','e',' ','=','=',' ','v','a','r',' ','t','h','e','n',0xa, + // if name == var then + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','p','r','i','n','t','_','v','a','r','(',' ','v','a','r',',',' ','v','a','l','u','e',',',' ','0',' ',')',0xa, + // debug_print_var( var, value, 0 ) + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','r','e','t','u','r','n',0xa, + // return + ' ',' ',' ',' ',' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ','e','n','d',0xa, + // end + 0xa, + ' ',' ',' ',' ','-','-',' ','t','r','y',' ','u','p','v','a','l','u','e','s',0xa, + // -- try upvalues + ' ',' ',' ',' ','l','o','c','a','l',' ','f','u','n','c',' ','=',' ','d','e','b','u','g','.','g','e','t','i','n','f','o','(','4',',','"','f','"',')','.','f','u','n','c',0xa, + // local func = debug.getinfo(4,"f").func + ' ',' ',' ',' ','l','o','c','a','l',' ','i','n','d','e','x',' ','=',' ','1',0xa, + // local index = 1 + ' ',' ',' ',' ','w','h','i','l','e',' ','t','r','u','e',' ','d','o',0xa, + // while true do + ' ',' ',' ',' ',' ',' ',' ',' ','l','o','c','a','l',' ','n','a','m','e',',',' ','v','a','l','u','e',' ','=',' ','d','e','b','u','g','.','g','e','t','u','p','v','a','l','u','e','(','f','u','n','c',',',' ','i','n','d','e','x',')',0xa, + // local name, value = debug.getupvalue(func, index) + ' ',' ',' ',' ',' ',' ',' ',' ','i','f',' ','n','o','t',' ','n','a','m','e',' ','t','h','e','n',' ',0xa, + // if not name then + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','b','r','e','a','k',' ',0xa, + // break + ' ',' ',' ',' ',' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ',' ',' ',' ',' ','i','f',' ','n','a','m','e',' ','=','=',' ','v','a','r',' ','t','h','e','n',' ',0xa, + // if name == var then + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','p','r','i','n','t','_','v','a','r','(',' ','v','a','r',',',' ','v','a','l','u','e',',',' ','0',' ',')',0xa, + // debug_print_var( var, value, 0 ) + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','r','e','t','u','r','n',0xa, + // return + ' ',' ',' ',' ',' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ',' ',' ',' ','i','n','d','e','x',' ','=',' ','i','n','d','e','x',' ','+',' ','1',0xa, + // index = index + 1 + ' ',' ',' ',' ','e','n','d',0xa, + // end + 0xa, + ' ',' ',' ',' ','-','-',0xe6,0x89,0xbe,0xe5,0x85,0xa8,0xe5,0xb1,0x80,0xe5,0x8f,0x98,0xe9,0x87,0x8f,0xa, + // --找全局变量 + ' ',' ',' ',' ','i','f',' ','_','G','[','v','a','r',']',' ','~','=',' ','n','i','l',' ','t','h','e','n',0xa, + // if _G[var] ~= nil then + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','p','r','i','n','t','_','v','a','r','(',' ','v','a','r',',',' ','_','G','[','v','a','r',']',',',' ','0',' ',')',0xa, + // debug_print_var( var, _G[var], 0 ) + ' ',' ',' ',' ',' ',' ',' ',' ','r','e','t','u','r','n',0xa, + // return + ' ',' ',' ',' ','e','n','d',0xa, + // end + 0xa, + ' ',' ',' ',' ','d','e','b','u','g','_','l','o','g','(',' ','v','a','r',' ','.','.',' ','"',' ','i','s',' ','i','n','v','a','l','i','d','"',' ',')',0xa, + // debug_log( var .. " is invalid" ) + 'e','n','d',0xa, + // end + 0xa, + 0xa, + 'f','u','n','c','t','i','o','n',' ','d','e','b','u','g','_','r','u','n','_','e','x','p','r','(',' ','s',' ',')',0xa, + // function debug_run_expr( s ) + ' ',' ',' ',' ','l','o','a','d','J','s','o','n','(','s',')',0xa, + // loadJson(s) + 'e','n','d',0xa, + // end + 0xa, + 'f','u','n','c','t','i','o','n',' ','a','d','d','_','b','r','e','a','k','p','o','i','n','t','(',' ','e','x','p','r',' ',')',0xa, + // function add_breakpoint( expr ) + ' ',' ',' ',' ','l','o','c','a','l',' ','s','i',' ','=',' ','s','t','r','i','n','g','.','f','i','n','d','(',' ','e','x','p','r',',',' ','"',':','"',' ',')',0xa, + // local si = string.find( expr, ":" ) + ' ',' ',' ',' ','i','f',' ','n','i','l',' ','=','=',' ','s','i',' ','t','h','e','n',0xa, + // if nil == si then + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','l','o','g','(',' ','"','a','d','d',' ','b','r','e','a','k','p','o','i','n','t',' ','e','r','r','o','r',',',' ','e','x','p','r',' ','(','"',' ','.','.',' ','e','x','p','r',' ','.','.',' ','"',')',' ','i','n','v','a','l','i','d','"',' ',')',0xa, + // debug_log( "add breakpoint error, expr (" .. expr .. ") invalid" ) + ' ',' ',' ',' ',' ',' ',' ',' ','r','e','t','u','r','n',0xa, + // return + ' ',' ',' ',' ','e','n','d',0xa, + // end + 0xa, + ' ',' ',' ',' ','l','o','c','a','l',' ','l','i','n','e',' ','=',' ','s','t','r','i','n','g','.','s','u','b','(',' ','e','x','p','r',',',' ','s','i',' ','+',' ','1',' ',')',0xa, + // local line = string.sub( expr, si + 1 ) + ' ',' ',' ',' ','l','o','c','a','l',' ','l','i','n','e',' ','=',' ','t','o','n','u','m','b','e','r','(',' ','l','i','n','e',' ',')',0xa, + // local line = tonumber( line ) + ' ',' ',' ',' ','l','o','c','a','l',' ','s','o','u','r','c','e',' ','=',' ','s','t','r','i','n','g','.','s','u','b','(',' ','e','x','p','r',',',' ','1',',',' ','s','i',' ','-',' ','1',' ',')',0xa, + // local source = string.sub( expr, 1, si - 1 ) + 0xa, + ' ',' ',' ',' ','-','-',0xe5,0x85,0x88,0xe6,0x9f,0xa5,0xe6,0x89,0xbe,0xe6,0x9c,0x89,0xe4,0xb8,0x8d,0xe6,0x9c,0x89,0xe7,0x9b,0xb8,0xe5,0x90,0x8c,0xe6,0x96,0xad,0xe7,0x82,0xb9,0xa, + // --先查找有不有相同断点 + ' ',' ',' ',' ','i','f',' ','(',' ','(',' ','d','e','b','u','g','.','b','p','s','[','l','i','n','e',']',' ','~','=',' ','n','i','l',' ',')',' ','a','n','d',' ','(',' ','d','e','b','u','g','.','b','p','s','[','l','i','n','e',']','[','s','o','u','r','c','e',']',' ','~','=',' ','n','i','l',' ',')',' ',')',' ','t','h','e','n',0xa, + // if ( ( debug.bps[line] ~= nil ) and ( debug.bps[line][source] ~= nil ) ) then + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','l','o','g','(',' ','s','t','r','i','n','g','.','f','o','r','m','a','t','(',' ','"','b','r','e','a','k','p','o','i','n','t',' ','%','s',':','%','d',' ','e','x','i','s','t','e','d','"',',',' ','s','o','u','r','c','e',',',' ','l','i','n','e',' ',')',' ',')',0xa, + // debug_log( string.format( "breakpoint %s:%d existed", source, line ) ) + ' ',' ',' ',' ',' ',' ',' ',' ','r','e','t','u','r','n',0xa, + // return + ' ',' ',' ',' ','e','n','d',0xa, + // end + 0xa, + ' ',' ',' ',' ','l','o','c','a','l',' ','t','b','l',' ','=',' ','{','}',0xa, + // local tbl = {} + ' ',' ',' ',' ','t','b','l','.','s','o','u','r','c','e',' ','=',' ','s','o','u','r','c','e',0xa, + // tbl.source = source + ' ',' ',' ',' ','t','b','l','.','l','i','n','e',' ','=',' ','l','i','n','e',0xa, + // tbl.line = line + ' ',' ',' ',' ','t','b','l','.','a','c','t','i','v','e',' ','=',' ','t','r','u','e',0xa, + // tbl.active = true + ' ',' ',' ',' ','t','b','l','.','n','u','m','b','e','r',' ','=',' ','d','e','b','u','g','.','b','p','s','.','m','a','x',' ','+',' ','1',0xa, + // tbl.number = debug.bps.max + 1 + 0xa, + ' ',' ',' ',' ','i','f',' ','d','e','b','u','g','.','b','p','s','[','l','i','n','e',']',' ','=','=',' ','n','i','l',' ','t','h','e','n',0xa, + // if debug.bps[line] == nil then + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','.','b','p','s','[','l','i','n','e',']',' ','=',' ','{','}',0xa, + // debug.bps[line] = {} + ' ',' ',' ',' ','e','n','d',0xa, + // end + 0xa, + ' ',' ',' ',' ','d','e','b','u','g','.','b','p','s','[','l','i','n','e',']','[','s','o','u','r','c','e',']',' ','=',' ','t','b','l',0xa, + // debug.bps[line][source] = tbl + ' ',' ',' ',' ','d','e','b','u','g','.','b','p','s','.','m','a','x',' ','=',' ','d','e','b','u','g','.','b','p','s','.','m','a','x',' ','+',' ','1',0xa, + // debug.bps.max = debug.bps.max + 1 + ' ',' ',' ',' ','d','e','b','u','g','_','l','o','g','(',' ','s','t','r','i','n','g','.','f','o','r','m','a','t','(',' ','"',0xe5,0x8a,0xa0,0xe6,0x96,0xad,0xe7,0x82,0xb9,'(','%','s',':','%','d',')','"',',',' ','s','o','u','r','c','e',',',' ','l','i','n','e',' ',')',' ',')',0xa, + // debug_log( string.format( "加断点(%s:%d)", source, line ) ) + 'e','n','d',0xa, + // end + 0xa, + 'f','u','n','c','t','i','o','n',' ','r','e','m','o','v','e','_','b','r','e','a','k','p','o','i','n','t','(',' ','e','x','p','r',' ',')',0xa, + // function remove_breakpoint( expr ) + ' ',' ',' ',' ','l','o','c','a','l',' ','s','i',' ','=',' ','s','t','r','i','n','g','.','f','i','n','d','(',' ','e','x','p','r',',',' ','"',':','"',' ',')',0xa, + // local si = string.find( expr, ":" ) + ' ',' ',' ',' ','i','f',' ','n','i','l',' ','=','=',' ','s','i',' ','t','h','e','n',0xa, + // if nil == si then + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','l','o','g','(',' ','"','r','e','m','o','v','e',' ','b','r','e','a','k','p','o','i','n','t',' ','e','r','r','o','r',',',' ','e','x','p','r',' ','(','"',' ','.','.',' ','e','x','p','r',' ','.','.',' ','"',')',' ','i','n','v','a','l','i','d','"',' ',')',0xa, + // debug_log( "remove breakpoint error, expr (" .. expr .. ") invalid" ) + ' ',' ',' ',' ',' ',' ',' ',' ','r','e','t','u','r','n',0xa, + // return + ' ',' ',' ',' ','e','n','d',0xa, + // end + 0xa, + ' ',' ',' ',' ','l','o','c','a','l',' ','l','i','n','e',' ','=',' ','s','t','r','i','n','g','.','s','u','b','(',' ','e','x','p','r',',',' ','s','i',' ','+',' ','1',' ',')',0xa, + // local line = string.sub( expr, si + 1 ) + ' ',' ',' ',' ','l','o','c','a','l',' ','l','i','n','e',' ','=',' ','t','o','n','u','m','b','e','r','(',' ','l','i','n','e',' ',')',0xa, + // local line = tonumber( line ) + ' ',' ',' ',' ','l','o','c','a','l',' ','s','o','u','r','c','e',' ','=',' ','s','t','r','i','n','g','.','s','u','b','(',' ','e','x','p','r',',',' ','1',',',' ','s','i',' ','-',' ','1',' ',')',0xa, + // local source = string.sub( expr, 1, si - 1 ) + 0xa, + ' ',' ',' ',' ','-','-',0xe5,0x85,0x88,0xe6,0x9f,0xa5,0xe6,0x89,0xbe,0xe6,0x9c,0x89,0xe4,0xb8,0x8d,0xe6,0x9c,0x89,0xe7,0x9b,0xb8,0xe5,0x90,0x8c,0xe6,0x96,0xad,0xe7,0x82,0xb9,0xa, + // --先查找有不有相同断点 + ' ',' ',' ',' ','i','f','(',' ','(',' ','d','e','b','u','g','.','b','p','s','[','l','i','n','e',']',' ','~','=',' ','n','i','l',' ',')',' ','a','n','d',' ','(',' ','d','e','b','u','g','.','b','p','s','[','l','i','n','e',']','[','s','o','u','r','c','e',']',' ','~','=',' ','n','i','l',' ',')',' ',')','t','h','e','n',0xa, + // if( ( debug.bps[line] ~= nil ) and ( debug.bps[line][source] ~= nil ) )then + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','.','b','p','s','[','l','i','n','e',']','[','s','o','u','r','c','e',']',' ','=',' ','n','i','l',';',0xa, + // debug.bps[line][source] = nil; + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','l','o','g','(',' ','s','t','r','i','n','g','.','f','o','r','m','a','t','(',' ','"',0xe5,0x88,0xa0,0xe7,0x82,0xb9,0xe6,0x96,0xad,'(','%','s',':','%','d',')','"',',',' ','s','o','u','r','c','e',',',' ','l','i','n','e',' ',')',' ',')',0xa, + // debug_log( string.format( "删点断(%s:%d)", source, line ) ) + ' ',' ',' ',' ',' ',' ',' ',' ','r','e','t','u','r','n',0xa, + // return + ' ',' ',' ',' ','e','l','s','e',0xa, + // else + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','l','o','g','(',' ','s','t','r','i','n','g','.','f','o','r','m','a','t','(',' ','"','n','o','t',' ','f','o','u','n','d',' ','b','r','e','a','k','p','o','i','n','t',' ','%','s',':','%','d',' ','e','x','i','s','t','e','d','"',',',' ','s','o','u','r','c','e',',',' ','l','i','n','e',' ',')',' ',')',0xa, + // debug_log( string.format( "not found breakpoint %s:%d existed", source, line ) ) + ' ',' ',' ',' ',' ',' ',' ',' ','r','e','t','u','r','n',0xa, + // return + ' ',' ',' ',' ','e','n','d',0xa, + // end + 'e','n','d',0xa, + // end + 0xa, + 'f','u','n','c','t','i','o','n',' ','d','e','b','u','g','_','s','h','o','w','_','b','p','(',')',0xa, + // function debug_show_bp() + ' ',' ',' ',' ','f','o','r',' ','k',',',' ','v',' ','i','n',' ','p','a','i','r','s','(',' ','d','e','b','u','g','.','b','p','s',' ',')',' ','d','o',0xa, + // for k, v in pairs( debug.bps ) do + ' ',' ',' ',' ',' ',' ',' ',' ','i','f',' ','t','y','p','e','(',' ','v',' ',')',' ','=','=',' ','"','t','a','b','l','e','"',' ','t','h','e','n',0xa, + // if type( v ) == "table" then + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','f','o','r',' ','k','1',',',' ','v','1',' ','i','n',' ','p','a','i','r','s','(',' ','v',' ',')',' ','d','o',0xa, + // for k1, v1 in pairs( v ) do + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','l','o','c','a','l',' ','s','t','r',' ','=',' ','s','t','r','i','n','g','.','f','o','r','m','a','t','(',' ','"','b','p',' ','n','u','m',':','%','d',' ',' ','%','s',':','%','d',' ',' ','a','c','t','i','v','e',':','"',',',0xa, + // local str = string.format( "bp num:%d %s:%d active:", + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','v','1','.','n','u','m','b','e','r',',',0xa, + // v1.number, + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','v','1','.','s','o','u','r','c','e',',',0xa, + // v1.source, + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','v','1','.','l','i','n','e',' ',')',0xa, + // v1.line ) + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','i','f',' ','v','1','.','a','c','t','i','v','e',' ','t','h','e','n',0xa, + // if v1.active then + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','s','t','r',' ','=',' ','s','t','r',' ','.','.',' ','"','e','n','a','b','l','e','"',0xa, + // str = str .. "enable" + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','e','l','s','e',0xa, + // else + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','s','t','r',' ','=',' ','s','t','r',' ','.','.',' ','"','d','i','s','a','b','l','e','"',0xa, + // str = str .. "disable" + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','l','o','g','(',' ','s','t','r',' ',')',0xa, + // debug_log( str ) + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ',' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ','e','n','d',0xa, + // end + 'e','n','d',0xa, + // end + 0xa, + 'f','u','n','c','t','i','o','n',' ','d','e','b','u','g','_','d','e','l','_','b','p','(',' ','e','x','p','r',' ',')',0xa, + // function debug_del_bp( expr ) + ' ',' ',' ',' ','l','o','c','a','l',' ','n','u','m','b','e','r',' ','=',' ','t','o','n','u','m','b','e','r','(',' ','e','x','p','r',' ',')',0xa, + // local number = tonumber( expr ) + ' ',' ',' ',' ','f','o','r',' ','k',',',' ','v',' ','i','n',' ','p','a','i','r','s','(',' ','d','e','b','u','g','.','b','p','s',' ',')',' ','d','o',0xa, + // for k, v in pairs( debug.bps ) do + ' ',' ',' ',' ',' ',' ',' ',' ','i','f',' ','t','y','p','e','(',' ','v',' ',')',' ','=','=',' ','"','t','a','b','l','e','"',' ','t','h','e','n',0xa, + // if type( v ) == "table" then + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','f','o','r',' ','k','1',',',' ','v','1',' ','i','n',' ','p','a','i','r','s','(',' ','v',' ',')',' ','d','o',0xa, + // for k1, v1 in pairs( v ) do + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','i','f',' ','v','1','.','n','u','m','b','e','r',' ','=','=',' ','n','u','m','b','e','r',' ','t','h','e','n',0xa, + // if v1.number == number then + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','.','b','p','s','[','k',']','[','k','1',']',' ','=',' ','n','i','l',0xa, + // debug.bps[k][k1] = nil + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','l','o','g','(',' ','"','r','e','m','o','v','e',' ','b','p',':','"',' ','.','.',' ','n','u','m','b','e','r',' ','.','.',' ','"',' ','o','k','"',' ',')',0xa, + // debug_log( "remove bp:" .. number .. " ok" ) + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ',' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ','e','n','d',0xa, + // end + 'e','n','d',0xa, + // end + 0xa, + 'f','u','n','c','t','i','o','n',' ','d','e','b','u','g','_','e','n','a','b','l','e','_','b','p','(',' ','e','x','p','r',' ',')',0xa, + // function debug_enable_bp( expr ) + ' ',' ',' ',' ','l','o','c','a','l',' ','n','u','m','b','e','r',' ','=',' ','t','o','n','u','m','b','e','r','(',' ','e','x','p','r',' ',')',0xa, + // local number = tonumber( expr ) + ' ',' ',' ',' ','f','o','r',' ','k',',',' ','v',' ','i','n',' ','p','a','i','r','s','(',' ','d','e','b','u','g','.','b','p','s',' ',')',' ','d','o',0xa, + // for k, v in pairs( debug.bps ) do + ' ',' ',' ',' ',' ',' ',' ',' ','i','f',' ','t','y','p','e','(',' ','v',' ',')',' ','=','=',' ','"','t','a','b','l','e','"',' ','t','h','e','n',0xa, + // if type( v ) == "table" then + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','f','o','r',' ','k','1',',',' ','v','1',' ','i','n',' ','p','a','i','r','s','(',' ','v',' ',')',' ','d','o',0xa, + // for k1, v1 in pairs( v ) do + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','i','f',' ','v','1','.','n','u','m','b','e','r',' ','=','=',' ','n','u','m','b','e','r',' ','t','h','e','n',0xa, + // if v1.number == number then + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','v','1','.','a','c','t','i','v','e',' ','=',' ','t','r','u','e',0xa, + // v1.active = true + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','l','o','g','(',' ','"','e','n','a','b','l','e',' ','b','p',':','"',' ','.','.',' ','n','u','m','b','e','r',' ',')',0xa, + // debug_log( "enable bp:" .. number ) + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ',' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ','e','n','d',0xa, + // end + 'e','n','d',0xa, + // end + 0xa, + 'f','u','n','c','t','i','o','n',' ','d','e','b','u','g','_','d','i','s','a','b','l','e','_','b','p','(',' ','e','x','p','r',' ',')',0xa, + // function debug_disable_bp( expr ) + ' ',' ',' ',' ','l','o','c','a','l',' ','n','u','m','b','e','r',' ','=',' ','t','o','n','u','m','b','e','r','(',' ','e','x','p','r',' ',')',0xa, + // local number = tonumber( expr ) + ' ',' ',' ',' ','f','o','r',' ','k',',',' ','v',' ','i','n',' ','p','a','i','r','s','(',' ','d','e','b','u','g','.','b','p','s',' ',')',' ','d','o',0xa, + // for k, v in pairs( debug.bps ) do + ' ',' ',' ',' ',' ',' ',' ',' ','i','f',' ','t','y','p','e','(',' ','v',' ',')',' ','=','=',' ','"','t','a','b','l','e','"',' ','t','h','e','n',0xa, + // if type( v ) == "table" then + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','f','o','r',' ','k','1',',',' ','v','1',' ','i','n',' ','p','a','i','r','s','(',' ','v',' ',')',' ','d','o',0xa, + // for k1, v1 in pairs( v ) do + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','i','f',' ','v','1','.','n','u','m','b','e','r',' ','=','=',' ','n','u','m','b','e','r',' ','t','h','e','n',0xa, + // if v1.number == number then + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','v','1','.','a','c','t','i','v','e',' ','=',' ','f','a','l','s','e',0xa, + // v1.active = false + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','l','o','g','(',' ','"','d','i','s','a','b','l','e',' ','b','p',':','"',' ','.','.',' ','n','u','m','b','e','r',' ',')',0xa, + // debug_log( "disable bp:" .. number ) + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ',' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ','e','n','d',0xa, + // end + 'e','n','d',0xa, + // end + 0xa, + 'f','u','n','c','t','i','o','n',' ','d','e','b','u','g','_','h','e','l','p','(',')',0xa, + // function debug_help() + ' ',' ',' ',' ','p','r','i','n','t','(',' ','"','h',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','h','e','l','p',' ','i','n','f','o','"',' ',')',0xa, + // print( "h help info" ) + ' ',' ',' ',' ','p','r','i','n','t','(',' ','"','c',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','c','o','n','t','i','n','u','e','"',' ',')',0xa, + // print( "c continue" ) + ' ',' ',' ',' ','p','r','i','n','t','(',' ','"','s',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','t','r','a','c','e','"',' ',')',0xa, + // print( "s trace" ) + ' ',' ',' ',' ','p','r','i','n','t','(',' ','"','n',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','n','e','x','t','"',' ',')',0xa, + // print( "n next" ) + ' ',' ',' ',' ','p','r','i','n','t','(',' ','"','p',' ','v','a','r',' ',' ',' ',' ',' ',' ',' ',' ',' ','p','r','i','n','t',' ','v','a','r','i','a','b','l','e','"',' ',')',0xa, + // print( "p var print variable" ) + ' ',' ',' ',' ','p','r','i','n','t','(',' ','"','r','u','n',' ','e','x','p','r','e','s','s','i','o','n',' ',' ',' ',' ',' ',' ','r','u','n',' ','e','x','p','r','e','s','s','i','o','n',' ','c','o','d','e','"',' ',')',0xa, + // print( "run expression run expression code" ) + ' ',' ',' ',' ','p','r','i','n','t','(',' ','"','b',' ',' ','s','r','c',':','l','i','n','e',' ',' ',' ','a','d','d',' ','b','r','e','a','k','p','o','i','n','t','"',' ',')',0xa, + // print( "b src:line add breakpoint" ) + ' ',' ',' ',' ','p','r','i','n','t','(',' ','"','r','b',' ','s','r','c',':','l','i','n','e',' ',' ',' ','r','e','m','o','v','e',' ','b','r','e','a','k','p','o','i','n','t','"',' ',')',0xa, + // print( "rb src:line remove breakpoint" ) + ' ',' ',' ',' ','p','r','i','n','t','(',' ','"','b','l',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','l','i','s','t',' ','b','r','e','a','k','p','o','i','n','t','"',' ',')',0xa, + // print( "bl list breakpoint" ) + ' ',' ',' ',' ','p','r','i','n','t','(',' ','"','b','t',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','p','r','i','n','t',' ','t','r','a','c','e','b','a','c','k','"',' ',')',0xa, + // print( "bt print traceback" ) + 'e','n','d',0xa, + // end + 0xa, + 'f','u','n','c','t','i','o','n',' ','d','e','b','u','g','_','r','u','n','i','n','g','_','e','x','e','c','u','t','e','(',' ','c','m','d',' ',')',0xa, + // function debug_runing_execute( cmd ) + ' ',' ',' ',' ','i','f','(',' ','c','m','d','=','=','n','i','l',' ',')',' ','t','h','e','n',' ',0xa, + // if( cmd==nil ) then + ' ',' ',' ',' ',0x9,'r','e','t','u','r','n',';',0xa, + // return; + ' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ','l','o','c','a','l',' ','c',' ','=',' ','c','m','d',0xa, + // local c = cmd + ' ',' ',' ',' ','l','o','c','a','l',' ','e','x','p','r',' ','=',' ','"','"',0xa, + // local expr = "" + ' ',' ',' ',' ','l','o','c','a','l',' ','s','i',' ','=',' ','s','t','r','i','n','g','.','f','i','n','d','(',' ','c','m','d',',',' ','"',' ','"',' ',')',0xa, + // local si = string.find( cmd, " " ) + ' ',' ',' ',' ','i','f',' ','s','i',' ','~','=',' ','n','i','l',' ','t','h','e','n',0xa, + // if si ~= nil then + ' ',' ',' ',' ',' ',' ',' ',' ','c',' ','=',' ','s','t','r','i','n','g','.','s','u','b','(',' ','c','m','d',',',' ','1',',',' ','s','i',' ','-',' ','1',' ',')',0xa, + // c = string.sub( cmd, 1, si - 1 ) + ' ',' ',' ',' ',' ',' ',' ',' ','e','x','p','r',' ','=',' ','s','t','r','i','n','g','.','s','u','b','(',' ','c','m','d',',',' ','s','t','r','i','n','g','.','f','i','n','d','(',' ','c','m','d',',',' ','"',' ','%','w','"',' ',')',' ','+',' ','1',' ',')',0xa, + // expr = string.sub( cmd, string.find( cmd, " %w" ) + 1 ) + ' ',' ',' ',' ','e','n','d',0xa, + // end + 0xa, + ' ',' ',' ',' ','i','f',' ','c',' ','=','=',' ','"','b','"',' ','t','h','e','n',0xa, + // if c == "b" then + ' ',' ',' ',' ',' ',' ',' ',' ','a','d','d','_','b','r','e','a','k','p','o','i','n','t','(',' ','e','x','p','r',' ',')',0xa, + // add_breakpoint( expr ) + ' ',' ',' ',' ','e','l','s','e','i','f',' ','c',' ','=','=',' ','"','r','b','"',' ','t','h','e','n',0xa, + // elseif c == "rb" then + ' ',' ',' ',' ',' ',' ',' ',' ','r','e','m','o','v','e','_','b','r','e','a','k','p','o','i','n','t','(',' ','e','x','p','r',' ',')',0xa, + // remove_breakpoint( expr ) + ' ',' ',' ',' ','e','l','s','e','i','f',' ','c',' ','=','=',' ','"','p','"',' ','t','h','e','n',0xa, + // elseif c == "p" then + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','p','r','i','n','t','_','e','x','p','r','(',' ','e','x','p','r',' ',')',0xa, + // debug_print_expr( expr ) + ' ',' ',' ',' ','e','n','d',0xa, + // end + 'e','n','d',0xa, + // end + 0xa, + 'f','u','n','c','t','i','o','n',' ','d','e','b','u','g','_','e','x','e','c','u','t','e','_','c','m','d','(',' ','e','n','v',' ',')',0xa, + // function debug_execute_cmd( env ) + ' ',' ',' ',' ','-','-','p','r','i','n','t','(',' ','"','(','l','d','b',')',' ','"',' ',')',0xa, + // --print( "(ldb) " ) + ' ',' ',' ',' ','l','o','c','a','l',' ','c','m','d',' ','=',' ','d','e','b','u','g','.','r','e','a','d','C','m','d','(',')',0xa, + // local cmd = debug.readCmd() + ' ',' ',' ',' ','i','f',' ','(',' ','c','m','d',' ','=','=','n','i','l',' ',')',' ','t','h','e','n',0xa, + // if ( cmd ==nil ) then + ' ',' ',' ',' ',0x9,'d','e','b','u','g','.','s','l','e','e','p','(','0','.','0','1',')',';',0xa, + // debug.sleep(0.01); + ' ',' ',' ',' ',0x9,'r','e','t','u','r','n',' ','f','a','l','s','e',';',0xa, + // return false; + ' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ','-','-',0xe5,0x8f,0x96,0xe4,0xb8,0x8a,0xe4,0xb8,0x80,0xe6,0xac,0xa1,0xe7,0x9a,0x84,0xe5,0x91,0xbd,0xe4,0xbb,0xa4,',',0xe6,0x96,0xb9,0xe4,0xbe,0xbf,0xe8,0xb0,0x83,0xe8,0xaf,0x95,0xa, + // --取上一次的命令,方便调试 + ' ',' ',' ',' ','-','-',' ','i','f',' ','c','m','d',' ','~','=',' ','"','"',' ','t','h','e','n',0xa, + // -- if cmd ~= "" then + ' ',' ',' ',' ','-','-',' ',' ',' ',' ',' ','d','e','b','u','g','.','b','p','s','.','l','a','s','t','_','c','m','d',' ','=',' ','c','m','d',0xa, + // -- debug.bps.last_cmd = cmd + ' ',' ',' ',' ','-','-',' ','e','l','s','e',0xa, + // -- else + ' ',' ',' ',' ','-','-',' ',' ',' ',' ',' ','c','m','d',' ','=',' ','d','e','b','u','g','.','b','p','s','.','l','a','s','t','_','c','m','d',0xa, + // -- cmd = debug.bps.last_cmd + ' ',' ',' ',' ','-','-',' ','e','n','d',0xa, + // -- end + 0xa, + ' ',' ',' ',' ','l','o','c','a','l',' ','c',' ','=',' ','c','m','d',0xa, + // local c = cmd + ' ',' ',' ',' ','l','o','c','a','l',' ','e','x','p','r',' ','=',' ','"','"',0xa, + // local expr = "" + ' ',' ',' ',' ','l','o','c','a','l',' ','s','i',' ','=',' ','s','t','r','i','n','g','.','f','i','n','d','(',' ','c','m','d',',',' ','"',' ','"',' ',')',0xa, + // local si = string.find( cmd, " " ) + ' ',' ',' ',' ','i','f',' ','s','i',' ','~','=',' ','n','i','l',' ','t','h','e','n',0xa, + // if si ~= nil then + ' ',' ',' ',' ',' ',' ',' ',' ','c',' ','=',' ','s','t','r','i','n','g','.','s','u','b','(',' ','c','m','d',',',' ','1',',',' ','s','i',' ','-',' ','1',' ',')',0xa, + // c = string.sub( cmd, 1, si - 1 ) + ' ',' ',' ',' ',' ',' ',' ',' ','-','-',' ','l','o','c','a','l',' ','i','n','d','e','x',' ','=',' ','s','t','r','i','n','g','.','f','i','n','d','(',' ','c','m','d',',',' ','"',' ','%','w','"',' ',')',';',0xa, + // -- local index = string.find( cmd, " %w" ); + ' ',' ',' ',' ',' ',' ',' ',' ','-','-',' ','i','f',' ','(',' ','i','n','d','e','x',' ',')',' ','t','h','e','n',0xa, + // -- if ( index ) then + ' ',' ',' ',' ',' ',' ',' ',' ','-','-',' ',' ',' ',' ',' ','e','x','p','r',' ','=',' ','s','t','r','i','n','g','.','s','u','b','(',' ','c','m','d',',',' ','i','n','d','e','x',' ','+',' ','1',' ',')',';',0xa, + // -- expr = string.sub( cmd, index + 1 ); + ' ',' ',' ',' ',' ',' ',' ',' ','-','-',' ','e','n','d',0xa, + // -- end + ' ',' ',' ',' ',' ',' ',' ',' ','e','x','p','r',' ','=',' ','s','t','r','i','n','g','.','s','u','b','(','c','m','d',',',' ','s','i',' ','+',' ','1',' ',')',';',0xa, + // expr = string.sub(cmd, si + 1 ); + ' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ','i','f',' ','c','=','=','"','c','l','o','s','e','"',' ','t','h','e','n',0xa, + // if c=="close" then + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','c','l','o','s','e','(',')',';',0xa, + // debug_close(); + ' ',' ',' ',' ',' ',' ',' ',' ','r','e','t','u','r','n',' ','t','r','u','e',';',0xa, + // return true; + ' ',' ',' ',' ','e','l','s','e','i','f',' ','c','=','=','"','n','o','n','e','"',' ','t','h','e','n',0xa, + // elseif c=="none" then + ' ',' ',' ',' ',' ',' ',' ',' ','r','e','t','u','r','n',' ','f','a','l','s','e',';',0xa, + // return false; + ' ',' ',' ',' ','e','l','s','e','i','f',' ','c',' ','=','=',' ','"','c','"',' ','t','h','e','n',0xa, + // elseif c == "c" then + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','.','b','p','s','.','t','r','a','c','e',' ','=',' ','f','a','l','s','e',0xa, + // debug.bps.trace = false + ' ',' ',' ',' ',' ',' ',' ',' ','r','e','t','u','r','n',' ','t','r','u','e',0xa, + // return true + ' ',' ',' ',' ','e','l','s','e','i','f',' ','c',' ','=','=',' ','"','s','"',' ','t','h','e','n',0xa, + // elseif c == "s" then + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','.','b','p','s','.','t','r','a','c','e',' ','=',' ','t','r','u','e',0xa, + // debug.bps.trace = true + ' ',' ',' ',' ',' ',' ',' ',' ','r','e','t','u','r','n',' ','t','r','u','e',0xa, + // return true + ' ',' ',' ',' ','e','l','s','e','i','f',' ','c',' ','=','=',' ','"','n','"',' ','t','h','e','n',0xa, + // elseif c == "n" then + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','.','b','p','s','.','t','r','a','c','e',' ','=',' ','f','a','l','s','e',0xa, + // debug.bps.trace = false + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','.','b','p','s','.','n','e','x','t',' ','=',' ','t','r','u','e',0xa, + // debug.bps.next = true + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','.','b','p','s','.','c','u','r','_','f','u','n','c',' ','=',' ','e','n','v','.','f','u','n','c',0xa, + // debug.bps.cur_func = env.func + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','.','b','p','s','.','t','r','a','c','e','_','c','o','u','n','t',' ','=',' ','d','e','b','u','g','.','t','r','a','c','e','b','a','c','k','_','c','o','u','n','t','(',')',' ','-',' ','1',0xa, + // debug.bps.trace_count = debug.traceback_count() - 1 + ' ',' ',' ',' ',' ',' ',' ',' ','r','e','t','u','r','n',' ','t','r','u','e',0xa, + // return true + ' ',' ',' ',' ','e','l','s','e','i','f',' ','c',' ','=','=',' ','"','p','"',' ','t','h','e','n',0xa, + // elseif c == "p" then + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','p','r','i','n','t','_','e','x','p','r','(',' ','e','x','p','r',' ',')',0xa, + // debug_print_expr( expr ) + ' ',' ',' ',' ','e','l','s','e','i','f',' ','c',' ','=','=',' ','"','r','u','n','"',' ','t','h','e','n',0xa, + // elseif c == "run" then + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','r','u','n','_','e','x','p','r','(',' ','e','x','p','r',' ',')',0xa, + // debug_run_expr( expr ) + ' ',' ',' ',' ','e','l','s','e','i','f',' ','c',' ','=','=',' ','"','b','"',' ','t','h','e','n',0xa, + // elseif c == "b" then + ' ',' ',' ',' ',' ',' ',' ',' ','a','d','d','_','b','r','e','a','k','p','o','i','n','t','(',' ','e','x','p','r',' ',')',0xa, + // add_breakpoint( expr ) + ' ',' ',' ',' ','e','l','s','e','i','f',' ','c',' ','=','=',' ','"','r','b','"',' ','t','h','e','n',0xa, + // elseif c == "rb" then + ' ',' ',' ',' ',' ',' ',' ',' ','r','e','m','o','v','e','_','b','r','e','a','k','p','o','i','n','t','(',' ','e','x','p','r',' ',')',0xa, + // remove_breakpoint( expr ) + ' ',' ',' ',' ','e','l','s','e','i','f',' ','c',' ','=','=',' ','"','b','l','"',' ','t','h','e','n',0xa, + // elseif c == "bl" then + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','s','h','o','w','_','b','p','(',')',0xa, + // debug_show_bp() + ' ',' ',' ',' ','e','l','s','e','i','f',' ','c',' ','=','=',' ','"','d','"',' ','t','h','e','n',0xa, + // elseif c == "d" then + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','d','e','l','_','b','p','(',' ','e','x','p','r',' ',')',0xa, + // debug_del_bp( expr ) + ' ',' ',' ',' ','e','l','s','e','i','f',' ','c',' ','=','=',' ','"','b','e','"',' ','t','h','e','n',0xa, + // elseif c == "be" then + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','e','n','a','b','l','e','_','b','p','(',' ','e','x','p','r',' ',')',0xa, + // debug_enable_bp( expr ) + ' ',' ',' ',' ','e','l','s','e','i','f',' ','c',' ','=','=',' ','"','b','d','"',' ','t','h','e','n',0xa, + // elseif c == "bd" then + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','d','i','s','a','b','l','e','_','b','p','(',' ','e','x','p','r',' ',')',0xa, + // debug_disable_bp( expr ) + ' ',' ',' ',' ','e','l','s','e','i','f',' ','c',' ','=','=',' ','"','b','t','"',' ','t','h','e','n',0xa, + // elseif c == "bt" then + ' ',' ',' ',' ',' ',' ',' ',' ','l','o','c','a','l',' ','t','r','a','c','e',' ','=',' ','d','e','b','u','g','.','t','r','a','c','e','b','a','c','k','(','"','"',',',' ','3',')',';',0xa, + // local trace = debug.traceback("", 3); + ' ',' ',' ',' ',' ',' ',' ',' ','p','r','i','n','t','(',' ','t','r','a','c','e',' ',')',';',0xa, + // print( trace ); + ' ',' ',' ',' ','e','l','s','e','i','f',' ','c',' ','=','=',' ','"','s','t','a','c','k','"',' ','t','h','e','n',0xa, + // elseif c == "stack" then + ' ',' ',' ',' ',' ',' ',' ',' ','l','o','c','a','l',' ','t','r','a','c','e',' ','=',' ','d','e','b','u','g','.','t','r','a','c','e','b','a','c','k','(','"','"',',',' ','3',')',';',0xa, + // local trace = debug.traceback("", 3); + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','.','w','r','i','t','e','C','m','d','(','"','s','t','a','c','k','"',',',' ','t','r','a','c','e',',',' ','n','i','l',')',';',0xa, + // debug.writeCmd("stack", trace, nil); + ' ',' ',' ',' ','e','l','s','e','i','f',' ','c',' ','=','=',' ','"','h','"',' ','t','h','e','n',0xa, + // elseif c == "h" then + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','h','e','l','p','(',')',0xa, + // debug_help() + ' ',' ',' ',' ','e','l','s','e',0xa, + // else + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','l','o','g','(',' ','"','i','n','v','a','l','i','d',' ','c','m','d',':','"',' ','.','.',' ','c','m','d',' ',')',0xa, + // debug_log( "invalid cmd:" .. cmd ) + ' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ','r','e','t','u','r','n',' ','f','a','l','s','e',0xa, + // return false + 'e','n','d',0xa, + // end + 0xa, + 'f','u','n','c','t','i','o','n',' ','d','e','b','u','g','_','t','r','a','c','e','(',' ','e','v','e','n','t',',',' ','l','i','n','e',' ',')',0xa, + // function debug_trace( event, line ) + ' ',' ',' ',' ','l','o','c','a','l',' ','e','n','v',' ','=',' ','d','e','b','u','g','.','g','e','t','i','n','f','o','(',' ','2',' ',')',0xa, + // local env = debug.getinfo( 2 ) + 0xa, + ' ',' ',' ',' ','i','f',' ','e','n','v','.','s','o','u','r','c','e',' ','=','=',' ','_','D','E','B','U','G','_','F','I','L','E',' ','t','h','e','n',0xa, + // if env.source == _DEBUG_FILE then + ' ',' ',' ',' ',' ',' ',' ',' ','r','e','t','u','r','n',0xa, + // return + ' ',' ',' ',' ','e','n','d',0xa, + // end + 0xa, + ' ',' ',' ',' ','-','-',0xe5,0x88,0xa4,0xe6,0x96,0xad,0xe6,0x98,0xaf,0xe5,0x90,0xa6,0xe5,0x9c,0xa8,'n','e','x','t',0xe8,0xb0,0x83,0xe8,0xaf,0x95,0xa, + // --判断是否在next调试 + ' ',' ',' ',' ','i','f',' ','d','e','b','u','g','.','b','p','s','.','n','e','x','t',' ',' ','t','h','e','n',0xa, + // if debug.bps.next then + ' ',' ',' ',' ',' ',' ',' ',' ','l','o','c','a','l',' ','t','r','a','c','e','_','c','o','u','n','t',' ','=',' ','d','e','b','u','g','.','t','r','a','c','e','b','a','c','k','_','c','o','u','n','t','(',')',0xa, + // local trace_count = debug.traceback_count() + ' ',' ',' ',' ',' ',' ',' ',' ','-','-',0xe5,0x87,0xbd,0xe6,0x95,0xb0,0xe8,0xbf,0x94,0xe5,0x9b,0x9e,0xe4,0xba,0x86,',',0xe8,0xb0,0x83,0xe7,0x94,0xa8,0xe6,0xa0,0x88,0xe6,0x95,0xb0,0xe9,0x87,0x8f,0xe5,0xb0,0xb1,0xe4,0xbc,0x9a,0xe6,0xaf,0x94,0xe7,0x8e,0xb0,0xe5,0x9c,0xa8,0xe5,0xb0,0x8f,0xa, + // --函数返回了,调用栈数量就会比现在小 + ' ',' ',' ',' ',' ',' ',' ',' ','i','f',' ','t','r','a','c','e','_','c','o','u','n','t',' ','<',' ','d','e','b','u','g','.','b','p','s','.','t','r','a','c','e','_','c','o','u','n','t',' ','t','h','e','n',0xa, + // if trace_count < debug.bps.trace_count then + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','.','b','p','s','.','n','e','x','t',' ','=',' ','f','a','l','s','e',0xa, + // debug.bps.next = false + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','.','b','p','s','.','t','r','a','c','e',' ','=',' ','t','r','u','e',0xa, + // debug.bps.trace = true + ' ',' ',' ',' ',' ',' ',' ',' ','e','l','s','e','i','f',' ','t','r','a','c','e','_','c','o','u','n','t',' ','=','=',' ','d','e','b','u','g','.','b','p','s','.','t','r','a','c','e','_','c','o','u','n','t',' ','t','h','e','n',0xa, + // elseif trace_count == debug.bps.trace_count then + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','i','f',' ','d','e','b','u','g','.','b','p','s','.','c','u','r','_','f','u','n','c',' ','=','=',' ','e','n','v','.','f','u','n','c',' ','t','h','e','n',0xa, + // if debug.bps.cur_func == env.func then + 0x9,' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','.','b','p','s','.','n','e','x','t',' ','=',' ','f','a','l','s','e',0xa, + // debug.bps.next = false + 0x9,' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','.','b','p','s','.','t','r','a','c','e',' ','=',' ','t','r','u','e',0xa, + // debug.bps.trace = true + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ',' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ',' ','e','n','d',0xa, + // end + 0xa, + ' ',' ',' ',' ','-','-',0xe5,0x88,0xa4,0xe6,0x96,0xad,0xe6,0x98,0xaf,0xe5,0x90,0xa6,0xe6,0x9c,0x89,0xe6,0x96,0xad,0xe7,0x82,0xb9,0xa, + // --判断是否有断点 + ' ',' ',' ',' ','i','f','(',' ','(',' ','n','o','t',' ','d','e','b','u','g','.','b','p','s','.','t','r','a','c','e',' ',')',' ','a','n','d',' ','(',' ','d','e','b','u','g','.','b','p','s','[','l','i','n','e',']',' ','~','=',' ','n','i','l',' ',')',' ',')',' ','t','h','e','n',0xa, + // if( ( not debug.bps.trace ) and ( debug.bps[line] ~= nil ) ) then + ' ',' ',' ',' ',' ',' ',' ',' ','l','o','c','a','l',' ','t','b','l',' ','=',' ','d','e','b','u','g','.','b','p','s','[','l','i','n','e',']','[','e','n','v','.','s','o','u','r','c','e',']',0xa, + // local tbl = debug.bps[line][env.source] + ' ',' ',' ',' ',' ',' ',' ',' ','i','f','(',' ',' ','(',' ','t','b','l',' ','~','=',' ','n','i','l',' ',')',' ','a','n','d',' ','t','b','l','.','a','c','t','i','v','e',' ',' ',')','t','h','e','n',0xa, + // if( ( tbl ~= nil ) and tbl.active )then + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','-','-',0xe5,0xa6,0x82,0xe6,0x9e,0x9c,0xe5,0x9c,0xa8,'n','e','x','t',0xe6,0x97,0xb6,',',0xe7,0xa2,0xb0,0xe5,0x88,0xb0,0xe6,0x96,0xad,0xe7,0x82,0xb9,0xe4,0xba,0x86,',',0xe5,0xb0,0xb1,0xe6,0xb8,0x85,0xe9,0x99,0xa4,0xe5,0x8d,0x95,0xe6,0xad,0xa5,0xe8,0xbf,0x90,0xe8,0xa1,0x8c,0xe7,0x8a,0xb6,0xe6,0x80,0x81,0xa, + // --如果在next时,碰到断点了,就清除单步运行状态 + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','.','b','p','s','.','n','e','x','t',' ','=',' ','f','a','l','s','e',0xa, + // debug.bps.next = false + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','.','b','p','s','.','t','r','a','c','e',' ','=',' ','t','r','u','e',0xa, + // debug.bps.trace = true + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','-','-',' ','d','e','b','u','g','_','l','o','g','(',' ','"',0xe7,0xa2,0xb0,0xe5,0x88,0xb0,0xe6,0x96,0xad,0xe7,0x82,0xb9,' ','"',' ','.','.',' ','e','n','v','.','s','o','u','r','c','e',' ','.','.',' ','"',' ','-',' ','"',' ','.','.',' ','l','i','n','e',' ',')',0xa, + // -- debug_log( "碰到断点 " .. env.source .. " - " .. line ) + ' ',' ',' ',' ',' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ','e','n','d',0xa, + // end + 0xa, + ' ',' ',' ',' ','i','f',' ','d','e','b','u','g','.','b','p','s','.','t','r','a','c','e',' ','t','h','e','n',0xa, + // if debug.bps.trace then + ' ',' ',' ',' ',' ',' ',' ',' ','l','o','c','a','l',' ','s','r','c',' ','=',' ','d','e','b','u','g','.','g','e','t','_','f','i','l','e','_','l','i','n','e','(',' ','e','n','v','.','s','o','u','r','c','e',',',' ','l','i','n','e',' ',')',0xa, + // local src = debug.get_file_line( env.source, line ) + ' ',' ',' ',' ',' ',' ',' ',' ','l','o','c','a','l',' ','f','u','n','n','a','m','e',' ','=',' ','e','n','v','.','n','a','m','e',' ','o','r',' ','"','u','n','k','n','o','w','"',0xa, + // local funname = env.name or "unknow" + ' ',' ',' ',' ',' ',' ',' ',' ','-','-','d','e','b','u','g','_','l','o','g','(',' ','s','t','r','i','n','g','.','f','o','r','m','a','t','(',' ','"','%','s',':','%','d','(','%','s',')',' ',' ','%','s','"',',',' ','e','n','v','.','s','o','u','r','c','e',',',' ','l','i','n','e',',',' ','f','u','n','n','a','m','e',',',' ','s','r','c',' ',')',' ',')',0xa, + // --debug_log( string.format( "%s:%d(%s) %s", env.source, line, funname, src ) ) + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','.','r','u','n','n','i','n','g','L','i','n','e','(',' ','e','n','v','.','s','o','u','r','c','e',',',' ','l','i','n','e',' ',')',';',0xa, + // debug.runningLine( env.source, line ); + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','.','b','p','s','.','c','u','r','_','f','i','l','e',' ','=',' ','e','n','v','.','s','o','u','r','c','e',';',0xa, + // debug.bps.cur_file = env.source; + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','.','b','p','s','.','c','u','r','_','l','i','n','e',' ','=',' ','l','i','n','e',0xa, + // debug.bps.cur_line = line + ' ',' ',' ',' ',' ',' ',' ',' ','w','h','i','l','e',' ','n','o','t',' ','d','e','b','u','g','_','e','x','e','c','u','t','e','_','c','m','d','(',' ','e','n','v',' ',')',' ','d','o',0xa, + // while not debug_execute_cmd( env ) do + ' ',' ',' ',' ',' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ',' ',' ',' ',' ','r','e','t','u','r','n',';',0xa, + // return; + ' ',' ',' ',' ','e','n','d',0xa, + // end + 'e','n','d',0xa, + // end + 0xa, + 'f','u','n','c','t','i','o','n',' ','b','e','g','i','n','_','d','e','b','u','g','(',')',0xa, + // function begin_debug() + ' ',' ',' ',' ','d','e','b','u','g','.','b','p','s','.','t','r','a','c','e',' ','=',' ','t','r','u','e',0xa, + // debug.bps.trace = true + ' ',' ',' ',' ','d','e','b','u','g','.','s','e','t','h','o','o','k','(',' ','d','e','b','u','g','_','t','r','a','c','e',',',' ','"','l','"',' ',')',0xa, + // debug.sethook( debug_trace, "l" ) + 'e','n','d',0xa, + // end + 0xa, + '-','-',0xe5,0x85,0xb3,0xe9,0x97,0xad,'d','e','b','u','g','g','e','r',0xa, + // --关闭debugger + 'f','u','n','c','t','i','o','n',' ','d','e','b','u','g','_','c','l','o','s','e','(',')',0xa, + // function debug_close() + ' ',' ',' ',' ','d','e','b','u','g','.','b','p','s','.','t','r','a','c','e',' ','=',' ','f','a','l','s','e',0xa, + // debug.bps.trace = false + ' ',' ',' ',' ','d','e','b','u','g','.','b','p','s','.','n','e','x','t',' ','=',' ','f','a','l','s','e',0xa, + // debug.bps.next = false + ' ',' ',' ',' ','d','e','b','u','g','.','s','e','t','h','o','o','k','(',')',0xa, + // debug.sethook() + 'e','n','d',0xa, + // end + 0xa, + 'd','e','b','u','g','_','l','o','g','(','"','l','o','a','d',' ','d','e','b','u','g',' ','m','o','d','e','l','"',')',';',0xa, + // debug_log("load debug model"); + 'd','e','b','u','g','.','p','r','i','n','t','T','o','S','e','r','v','e','r','(','t','r','u','e',')',';',0xa, + // debug.printToServer(true); + 0xa, + 0xa, + 'b','e','g','i','n','_','d','e','b','u','g','(',')',';',' ','-','-',' ','l','a','s','t',' ','l','i','n','e',0xa, + // begin_debug(); -- last line + 0xa, + 0 +}; +#endif + diff --git a/IOS/SDK/LuaViewSDK/Classes/lvdebug/LVDebuger.h b/IOS/SDK/LuaViewSDK/Classes/lvdebug/LVDebuger.h new file mode 100644 index 00000000..782a9375 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvdebug/LVDebuger.h @@ -0,0 +1,19 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + +extern void lv_printToServer(lua_State* L, const char* cs, int withTabChar); + +@interface LVDebuger : NSObject + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvdebug/LVDebuger.m b/IOS/SDK/LuaViewSDK/Classes/lvdebug/LVDebuger.m new file mode 100644 index 00000000..f0c3c3d0 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvdebug/LVDebuger.m @@ -0,0 +1,140 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVDebuger.h" +#import "LVHeads.h" +#import "LVDebugConnection.h" +#import "LView.h" +#import "LVHeads.h" + +@implementation LVDebuger + +#ifdef DEBUG +//--------------------------------------------------------- + +static int DebugReadCmd (lua_State *L) { + LuaViewCore* luaView = LV_LUASTATE_VIEW(L); + + NSString* cmd = [luaView.debugConnection getCmd]; + if( cmd ){ + lua_pushstring(L, cmd.UTF8String); + } else { + lua_pushnil(L); + } + return 1; +} + +static int DebugWriteCmd (lua_State *L) { + LuaViewCore* luaView = LV_LUASTATE_VIEW(L); + NSString* cmd = lv_paramString(L, 1); + NSString* info = lv_paramString(L, 2); + NSDictionary* args = lv_luaTableToDictionary(L, 3); + + [luaView.debugConnection sendCmd:cmd info:info args:args]; + return 0; +} + +static int DebugSleep (lua_State *L) { + float time = lua_tonumber(L, 1); + if( time>0 ) { + [NSThread sleepForTimeInterval:time]; + } + return 0; +} + +static int DebugPrintToServer (lua_State *L) { + LuaViewCore* luaView = LV_LUASTATE_VIEW(L); + BOOL open = lua_toboolean(L, 1); + luaView.debugConnection.printToServer = !!open; + return 0; +} + +static int runningLine (lua_State *L) { + NSString* fileName = lv_paramString(L, 1); + if( fileName == nil ){ + fileName = @"unkown"; + } + int lineNumber = lua_tonumber(L, 2); + + NSString* lineInfo = [NSString stringWithFormat:@"%d",lineNumber]; + LuaViewCore* luaView = LV_LUASTATE_VIEW(L); + [luaView.debugConnection sendCmd:@"running" fileName:fileName info:lineInfo args:@{@"Line-Number":lineInfo}]; + return 0; +} + +static int get_file_line( lua_State *L ) +{ + lua_pushstring(L, "one line code"); + return 1; +} + +static int db_traceback_count (lua_State *L) { + lua_Debug ar; + int index = 1; + while (lua_getstack(L, index, &ar)) + index++; + lua_pushnumber( L, index - 1 ); + return 1; +} + +static const luaL_Reg dblib[] = { + {"readCmd", DebugReadCmd}, + {"writeCmd", DebugWriteCmd}, + {"sleep", DebugSleep}, + {"printToServer", DebugPrintToServer}, + {"runningLine", runningLine}, + {"get_file_line", get_file_line}, + {"traceback_count", db_traceback_count}, + {NULL, NULL} +}; + + +// 把日志传送到服务器 +void lv_printToServer(lua_State* L, const char* cs, int withTabChar){ + LuaViewCore* lview = LV_LUASTATE_VIEW(L); + if( lview.debugConnection.printToServer ){ + NSMutableData* data = [[NSMutableData alloc] init]; + if( withTabChar ){ + [data appendBytes:" " length:4]; + } + [data appendBytes:cs length:strlen(cs)]; + + [lview.debugConnection sendCmd:@"log" info:[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]]; + } +} + +// 可变参数实例 +//void lv_print(NSString*format, ...) { +// va_list argumentList; +// va_start(argumentList, format); +// NSMutableString * message = [[NSMutableString alloc] initWithFormat:format +// arguments:argumentList]; +// [message appendString:@"\n"]; +// lv_printToServer(message.UTF8String,0); +// va_end(argumentList); +//} + + + +//--------------------------------------------------------- +#endif + + + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ +#ifdef DEBUG + luaL_register(L, LUA_DBLIBNAME, dblib); +#endif + + return 0; +} + + +@end + + diff --git a/IOS/SDK/LuaViewSDK/Classes/lvdebug/debug.lua b/IOS/SDK/LuaViewSDK/Classes/lvdebug/debug.lua new file mode 100644 index 00000000..dcf224ce --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvdebug/debug.lua @@ -0,0 +1,398 @@ +_DEBUG_FILE = "debug.lua" + +debug.bps = { + max = 0, + trace = false, + last_cmd = "", + next = false, + cur_func = nil, + trace_count = 0, + var_tbl = nil, +} + +function debug_log( log_str ) + print( "[LuaView][调试日志] " .. log_str ); +end + +function debug_print_var_0( name, value, level ) + local ret = ""; + local prefix = string.rep( " ", level ) + local str = string.format( "%s%s = %s", prefix, name, tostring(value) ) + + if type( value ) == "table" then + if debug.var_tbl[value] then + --已在临时表中的,只打印表地址 + ret = ret .. tostring(str) .. '\n'; + return ret; + end + + --加到临时表中,以免表出现循环引用时,打印也产生死循环 + debug.var_tbl[value] = true + --打印表中所有数据 + ret = ret .. string.format( "%s%s = {", prefix, name ) .. '\n'; + for k, v in pairs( value ) do + if type( k ) == "string" then + else + k = tostring(k); + end + --不打印 "_"开头的内部变量 + --if string.sub( k, 1, 1 ) ~= "_" then + ret = ret .. debug_print_var_0( k, v, level + 1 ) + --end + end + ret = ret .. prefix .. "}" .. '\n'; + elseif type( value ) == "string" then + ret = ret .. tostring(str) .. '\n'; + else + ret = ret .. tostring(str) .. '\n'; + end + return ret; +end + +function debug_print_var( name, value, level ) + local s = debug_print_var_0( name, value, level ); + if( s ) then + s = s:sub(1, s:len()-1 ); + debug_log( s ); + else + debug_log( s ); + end +end + +function debug_print_expr( var ) + if ( var==nil ) then + debug_log("debug_print_expr var==nil"); + return; + end + --清空临时变量表 + debug.var_tbl = {} + + local index = 1 + --找局部变量 + while true do + local name, value = debug.getlocal( 4, index ) + if not name then + break + end + index = index + 1 + + if name == var then + debug_print_var( var, value, 0 ) + return + end + end + + -- try upvalues + local func = debug.getinfo(4,"f").func + local index = 1 + while true do + local name, value = debug.getupvalue(func, index) + if not name then + break + end + if name == var then + debug_print_var( var, value, 0 ) + return + end + index = index + 1 + end + + --找全局变量 + if _G[var] ~= nil then + debug_print_var( var, _G[var], 0 ) + return + end + + debug_log( var .. " is invalid" ) +end + + +function debug_run_expr( s ) + loadJson(s) +end + +function add_breakpoint( expr ) + local si = string.find( expr, ":" ) + if nil == si then + debug_log( "add breakpoint error, expr (" .. expr .. ") invalid" ) + return + end + + local line = string.sub( expr, si + 1 ) + local line = tonumber( line ) + local source = string.sub( expr, 1, si - 1 ) + + --先查找有不有相同断点 + if ( ( debug.bps[line] ~= nil ) and ( debug.bps[line][source] ~= nil ) ) then + debug_log( string.format( "breakpoint %s:%d existed", source, line ) ) + return + end + + local tbl = {} + tbl.source = source + tbl.line = line + tbl.active = true + tbl.number = debug.bps.max + 1 + + if debug.bps[line] == nil then + debug.bps[line] = {} + end + + debug.bps[line][source] = tbl + debug.bps.max = debug.bps.max + 1 + debug_log( string.format( "加断点(%s:%d)", source, line ) ) +end + +function remove_breakpoint( expr ) + local si = string.find( expr, ":" ) + if nil == si then + debug_log( "remove breakpoint error, expr (" .. expr .. ") invalid" ) + return + end + + local line = string.sub( expr, si + 1 ) + local line = tonumber( line ) + local source = string.sub( expr, 1, si - 1 ) + + --先查找有不有相同断点 + if( ( debug.bps[line] ~= nil ) and ( debug.bps[line][source] ~= nil ) )then + debug.bps[line][source] = nil; + debug_log( string.format( "删点断(%s:%d)", source, line ) ) + return + else + debug_log( string.format( "not found breakpoint %s:%d existed", source, line ) ) + return + end +end + +function debug_show_bp() + for k, v in pairs( debug.bps ) do + if type( v ) == "table" then + for k1, v1 in pairs( v ) do + local str = string.format( "bp num:%d %s:%d active:", + v1.number, + v1.source, + v1.line ) + if v1.active then + str = str .. "enable" + else + str = str .. "disable" + end + debug_log( str ) + end + end + end +end + +function debug_del_bp( expr ) + local number = tonumber( expr ) + for k, v in pairs( debug.bps ) do + if type( v ) == "table" then + for k1, v1 in pairs( v ) do + if v1.number == number then + debug.bps[k][k1] = nil + debug_log( "remove bp:" .. number .. " ok" ) + end + end + end + end +end + +function debug_enable_bp( expr ) + local number = tonumber( expr ) + for k, v in pairs( debug.bps ) do + if type( v ) == "table" then + for k1, v1 in pairs( v ) do + if v1.number == number then + v1.active = true + debug_log( "enable bp:" .. number ) + end + end + end + end +end + +function debug_disable_bp( expr ) + local number = tonumber( expr ) + for k, v in pairs( debug.bps ) do + if type( v ) == "table" then + for k1, v1 in pairs( v ) do + if v1.number == number then + v1.active = false + debug_log( "disable bp:" .. number ) + end + end + end + end +end + +function debug_help() + print( "h help info" ) + print( "c continue" ) + print( "s trace" ) + print( "n next" ) + print( "p var print variable" ) + print( "run expression run expression code" ) + print( "b src:line add breakpoint" ) + print( "rb src:line remove breakpoint" ) + print( "bl list breakpoint" ) + print( "bt print traceback" ) +end + +function debug_runing_execute( cmd ) + if( cmd==nil ) then + return; + end + local c = cmd + local expr = "" + local si = string.find( cmd, " " ) + if si ~= nil then + c = string.sub( cmd, 1, si - 1 ) + expr = string.sub( cmd, string.find( cmd, " %w" ) + 1 ) + end + + if c == "b" then + add_breakpoint( expr ) + elseif c == "rb" then + remove_breakpoint( expr ) + elseif c == "p" then + debug_print_expr( expr ) + end +end + +function debug_execute_cmd( env ) + --print( "(ldb) " ) + local cmd = debug.readCmd() + if ( cmd ==nil ) then + debug.sleep(0.01); + return false; + end + --取上一次的命令,方便调试 + -- if cmd ~= "" then + -- debug.bps.last_cmd = cmd + -- else + -- cmd = debug.bps.last_cmd + -- end + + local c = cmd + local expr = "" + local si = string.find( cmd, " " ) + if si ~= nil then + c = string.sub( cmd, 1, si - 1 ) + -- local index = string.find( cmd, " %w" ); + -- if ( index ) then + -- expr = string.sub( cmd, index + 1 ); + -- end + expr = string.sub(cmd, si + 1 ); + end + if c=="close" then + debug_close(); + return true; + elseif c=="none" then + return false; + elseif c == "c" then + debug.bps.trace = false + return true + elseif c == "s" then + debug.bps.trace = true + return true + elseif c == "n" then + debug.bps.trace = false + debug.bps.next = true + debug.bps.cur_func = env.func + debug.bps.trace_count = debug.traceback_count() - 1 + return true + elseif c == "p" then + debug_print_expr( expr ) + elseif c == "run" then + debug_run_expr( expr ) + elseif c == "b" then + add_breakpoint( expr ) + elseif c == "rb" then + remove_breakpoint( expr ) + elseif c == "bl" then + debug_show_bp() + elseif c == "d" then + debug_del_bp( expr ) + elseif c == "be" then + debug_enable_bp( expr ) + elseif c == "bd" then + debug_disable_bp( expr ) + elseif c == "bt" then + local trace = debug.traceback("", 3); + print( trace ); + elseif c == "stack" then + local trace = debug.traceback("", 3); + debug.writeCmd("stack", trace, nil); + elseif c == "h" then + debug_help() + else + debug_log( "invalid cmd:" .. cmd ) + end + return false +end + +function debug_trace( event, line ) + local env = debug.getinfo( 2 ) + + if env.source == _DEBUG_FILE then + return + end + + --判断是否在next调试 + if debug.bps.next then + local trace_count = debug.traceback_count() + --函数返回了,调用栈数量就会比现在小 + if trace_count < debug.bps.trace_count then + debug.bps.next = false + debug.bps.trace = true + elseif trace_count == debug.bps.trace_count then + if debug.bps.cur_func == env.func then + debug.bps.next = false + debug.bps.trace = true + end + end + end + + --判断是否有断点 + if( ( not debug.bps.trace ) and ( debug.bps[line] ~= nil ) ) then + local tbl = debug.bps[line][env.source] + if( ( tbl ~= nil ) and tbl.active )then + --如果在next时,碰到断点了,就清除单步运行状态 + debug.bps.next = false + debug.bps.trace = true + -- debug_log( "碰到断点 " .. env.source .. " - " .. line ) + end + end + + if debug.bps.trace then + local src = debug.get_file_line( env.source, line ) + local funname = env.name or "unknow" + --debug_log( string.format( "%s:%d(%s) %s", env.source, line, funname, src ) ) + debug.runningLine( env.source, line ); + debug.bps.cur_file = env.source; + debug.bps.cur_line = line + while not debug_execute_cmd( env ) do + end + return; + end +end + +function begin_debug() + debug.bps.trace = true + debug.sethook( debug_trace, "l" ) +end + +--关闭debugger +function debug_close() + debug.bps.trace = false + debug.bps.next = false + debug.sethook() +end + +debug_log("load debug model"); +debug.printToServer(true); + + +begin_debug(); -- last line + diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAlert.h b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAlert.h new file mode 100644 index 00000000..999e8b15 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAlert.h @@ -0,0 +1,22 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + +@interface LVAlert : UIAlertView + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; + +-(id) init:(lua_State*) l argNum:(int)num; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAlert.m b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAlert.m new file mode 100644 index 00000000..33b3fc86 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAlert.m @@ -0,0 +1,134 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVAlert.h" +#import "LVBaseView.h" +#import "LView.h" +#import "LVToast.h" +#import "LVHeads.h" + +@interface LVAlert () +@property(nonatomic,strong) NSArray* cmdArray; +@property(nonatomic,assign) int argNum; +@property(nonatomic,assign) int functionNum; +@end + +@implementation LVAlert{ +} + +-(void) dealloc{ + lua_State* L = self.lv_luaviewCore.l; + for ( int i=0; i=1 && index<=max ){ + return lv_paramString(L, index); + } + return nil; +} + +static int lvNewAlertView (lua_State *L) { + int num = lua_gettop(L); + LVAlert* alertView = [[LVAlert alloc] init:L argNum:num]; + if( num>0 ){ + int argID= 0; + for ( int i=1; i<=num; i++ ) { + if( lua_type(L, i) == LUA_TFUNCTION ) { + NSString* tag = alertView.cmdArray[argID++]; + [LVUtil registryValue:L key:tag stack:i]; + alertView.argNum = argID; + } + } + [alertView show]; + } + return 0; +} + + +static int toast (lua_State *L) { + int num = lua_gettop(L); + if( num>0 ){ + NSString* s = lv_paramString(L, 1); + if( s ==nil ) { + s = @" "; + } + // CGSize size = [UIScreen mainScreen].bounds.size; + [LVToast showWithText:s duration:2]; + } + return 0; +} + + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + + // 自动消失的提示框 + lv_defineGlobalFunc("Toast", toast, L); + + // 系统Alert提示框 + [LVUtil reg:L clas:self cfunc:lvNewAlertView globalName:globalName defaultName:@"Alert"]; + const struct luaL_Reg memberFunctions [] = { + {NULL, NULL} + }; + + lv_createClassMetaTable(L, META_TABLE_UIAlertView); + + //luaL_openlib(L, NULL, [LVBaseView lvMemberFunctions], 0); + luaL_openlib(L, NULL, memberFunctions, 0); + return 1; +} + + + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAnimate.h b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAnimate.h new file mode 100644 index 00000000..52845eae --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAnimate.h @@ -0,0 +1,21 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + +@interface LVAnimate : UIView + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; + +-(id) init:(lua_State*) l; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAnimate.m b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAnimate.m new file mode 100644 index 00000000..1c306132 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAnimate.m @@ -0,0 +1,137 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + + +#import "LVAnimate.h" +#import "LVUtil.h" +#import "LView.h" +#import "LVHeads.h" + + +@interface LVAnimate () +@property(nonatomic,strong) id mySelf; +@property(nonatomic,assign) float time; +@end + + +@implementation LVAnimate + +-(id) init:(lua_State*) L{ + self = [super init]; + if( self ){ + self.mySelf = self; + self.lv_luaviewCore = LV_LUASTATE_VIEW(L); + } + return self; +} + +-(void) dealloc{ + self.lv_luaviewCore = nil; + self.lv_userData = nil; +} + + +static int lvNewAnimate (lua_State *L) { + int argNum = lua_gettop(L); + if( argNum>=1 ){ + LVAnimate* animate = [[LVAnimate alloc] init:L]; + + int stackID = 1; + + float delay = 0; + float duration = 0.3; + UIViewAnimationOptions option = 0; + CGFloat dampingRatio = 0;//0~1 + CGFloat velocity = 0;//0~1 + + if( lua_type(L, stackID)==LUA_TNUMBER ){ + duration = lua_tonumber(L,stackID++); + } + if( lua_type(L, stackID)==LUA_TNUMBER ){ + delay = lua_tonumber(L,stackID++); + } + + if( lua_type(L, stackID)==LUA_TNUMBER ){ + dampingRatio = lua_tonumber(L,stackID++); + } + + if( lua_type(L, stackID)==LUA_TNUMBER ){ + velocity = lua_tonumber(L,stackID++); + } + + if( lua_type(L, stackID)==LUA_TNUMBER ){ + option = lua_tonumber(L,stackID++); + } + + lua_createtable(L, 0, 8);// table + if( argNum>=stackID && lua_type(L,stackID)==LUA_TFUNCTION ){ + lua_pushstring(L, "animations");// key + lua_pushvalue(L, stackID);//value + lua_settable(L, -3); + stackID++; + } + if( argNum>=stackID && lua_type(L,stackID)==LUA_TFUNCTION ){ + lua_pushstring(L, "completion");// key + lua_pushvalue(L, stackID );//value + lua_settable(L, -3); + } + + [LVUtil registryValue:L key:animate stack:-1]; + + + if( dampingRatio>0 ) { + [UIView animateWithDuration:duration + delay:delay + usingSpringWithDamping:dampingRatio + initialSpringVelocity:velocity + options:option animations:^{ + if( animate.lv_luaviewCore && animate.lv_luaviewCore.l ) { + lua_checkstack32( animate.lv_luaviewCore.l); + [LVUtil call:animate.lv_luaviewCore.l lightUserData:animate key1:"animations" key2:NULL nargs:0]; + } + } completion:^(BOOL finished) { + lua_State* l = animate.lv_luaviewCore.l; + if( l ) { + lua_settop(l, 0); + lua_checkstack32(l); + [LVUtil call:l lightUserData:animate key1:"completion" key2:NULL nargs:0]; + + [LVUtil unregistry:l key:animate]; + } + animate.mySelf = nil; + }]; + } else { + [UIView animateWithDuration:duration + delay:delay + options:option animations:^{ + if( animate.lv_luaviewCore && animate.lv_luaviewCore.l ) { + lua_checkstack32( animate.lv_luaviewCore.l); + [LVUtil call:animate.lv_luaviewCore.l lightUserData:animate key1:"animations" key2:NULL nargs:0]; + } + } completion:^(BOOL finished) { + lua_State* l = animate.lv_luaviewCore.l; + if( l ) { + lua_settop(l, 0); + lua_checkstack32(l); + [LVUtil call:l lightUserData:animate key1:"completion" key2:NULL nargs:0]; + + [LVUtil unregistry:l key:animate]; + } + animate.mySelf = nil; + }]; + } + } + return 0; /* new userdatum is already on the stack */ +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewAnimate globalName:globalName defaultName:@"Animate"]; + return 1; +} + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAnimator.h b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAnimator.h new file mode 100644 index 00000000..726c1fc1 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAnimator.h @@ -0,0 +1,51 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import +#import "LVHeads.h" +#import "ltable.h" + +typedef NS_ENUM(int, LVAniamtorInterpolator) { + LVLinearInterpolator = 0, + LVAccelerateInterpolator, + LVDecelerateInterpolator, + LVAccelerateDecelerateInterpolator, + LVAnticipateInterpolator, + LVAnticipateOvershootInterpolator, + LVOvershootInterpolator, +}; + +@interface LVAnimator : NSObject + +@property(nonatomic, copy) NSString *keyPath; +@property(nonatomic, copy) NSValue *toValue; + +@property(nonatomic, assign) float duration; +@property(nonatomic, assign) float delay; +@property(nonatomic, assign) int repeatCount; +@property(nonatomic, assign) BOOL autoreverses; +@property(nonatomic, assign) LVAniamtorInterpolator interpolator; // default is linear + +@property(nonatomic, weak) UIView *target; + +@property(nonatomic, weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic, assign) LVUserDataInfo* lv_userData; + +@property(nonatomic, readonly, getter=isRunning) BOOL running; +@property(nonatomic, readonly, getter=isPaused) BOOL paused; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +- (void)start; +- (void)cancel; + +- (void)pause; +- (void)resume; + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAnimator.m b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAnimator.m new file mode 100644 index 00000000..5840fe15 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAnimator.m @@ -0,0 +1,766 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVAnimator.h" +#import "LVHeads.h" +#import "LVUtil.h" +#import "LuaViewCore.h" +#import "LVTransform3D.h" +#import + +typedef NS_ENUM(int, LVAnimatorCallback) { + kLVAnimatorCallbackOnStart = 1, + kLVAnimatorCallbackOnEnd, + kLVAnimatorCallbackOnCancel, + kLVAnimatorCallbackOnPause, + kLVAnimatorCallbackOnResume, +}; + +static char *callbackKeys[] = { "", "onStart", "onEnd", "onCancel", "onPause", "onResume" }; + +@implementation LVAnimator { + NSString *_animationKey; + CABasicAnimation *_pausedAnimation; + NSTimeInterval _timeOffset; +} + +@dynamic running, paused; + +-(id) lv_nativeObject{ + return self; +} + +static int lvNewAnimator(lua_State *L) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVAnimator class]]; + + LVAnimator *animator = [c new]; + + NEW_USERDATA(userData, Animator); + userData->object = CFBridgingRetain(animator); + + animator.lv_userData = userData; + animator.lv_luaviewCore = LV_LUASTATE_VIEW(L); + + luaL_getmetatable(L, META_TABLE_Animator); + lua_setmetatable(L, -2); + + return 1; +} + +static int __gc(lua_State *L) { + LVUserDataInfo *data = (LVUserDataInfo *)lua_touserdata(L, 1); + if (LVIsType(data, Animator) && data->object) { + LVAnimator *animator = (__bridge LVAnimator *)data->object; + + CFBridgingRelease((__bridge CFTypeRef)(animator)); + data->object = nil; + + animator.lv_luaviewCore = nil; + animator.lv_userData = NULL; + } + + return 0; +} + +static int __tostring(lua_State *L) { + LVUserDataInfo *data = (LVUserDataInfo *)lua_touserdata(L, 1); + if (LVIsType(data, Animator)) { + LVAnimator *animator = (__bridge LVAnimator *)data->object; + NSString *s = [NSString stringWithFormat:@"Animator<%@>: %@", animator.keyPath, animator.toValue]; + lua_pushstring(L, s.UTF8String); + + return 1; + } + + return 0; +} + +static int __eq(lua_State *L) { + LVUserDataInfo *data1 = (LVUserDataInfo *)lua_touserdata(L, 1); + LVUserDataInfo *data2 = (LVUserDataInfo *)lua_touserdata(L, 2); + + if (LVIsType(data1, Animator) && LVIsType(data2, Animator)) { + LVAnimator *a1 = (__bridge LVAnimator *)data1->object; + LVAnimator *a2 = (__bridge LVAnimator *)data2->object; + + BOOL eq = [a1 isEqual:a2]; + lua_pushboolean(L, eq); + + return 1; + } + + return 0; +} + +static int clone(lua_State *L) { + LVUserDataInfo *data = (LVUserDataInfo *)lua_touserdata(L, 1); + if (LVIsType(data, Animator)) { + LVAnimator *animator = [(__bridge LVAnimator *)data->object copy]; + + NEW_USERDATA(userData, Animator); + userData->object = CFBridgingRetain(animator); + + animator.lv_userData = userData; + animator.lv_luaviewCore = LV_LUASTATE_VIEW(L); + + luaL_getmetatable(L, META_TABLE_Animator); + lua_setmetatable(L, -2); + + return 1; + } + + return 0; +} + +static int with(lua_State *L) { + LVUserDataInfo *adata = (LVUserDataInfo *)lua_touserdata(L, 1); + LVUserDataInfo *vdata = (LVUserDataInfo *)lua_touserdata(L, 2); + + if (LVIsType(adata, Animator) && LVIsType(vdata, View)) { + LVAnimator *animator = (__bridge LVAnimator *)adata->object; + animator.target = (__bridge UIView *)vdata->object; + } + + lv_pushUserdata(L, adata); + + return 1; +} + +static int start(lua_State *L) { + LVUserDataInfo *data = (LVUserDataInfo *)lua_touserdata(L, 1); + + if (LVIsType(data, Animator)) { + LVAnimator *animator = (__bridge LVAnimator *)data->object; + if (animator.running) { + LVLog(@"Animation of key:%@ is running!", animator.keyPath); + } else { + [animator start]; + } + } + + lv_pushUserdata(L, data); + + return 1; +} + +static int cancel(lua_State *L) { + LVUserDataInfo *data = (LVUserDataInfo *)lua_touserdata(L, 1); + + if (LVIsType(data, Animator)) { + LVAnimator *animator = (__bridge LVAnimator *)data->object; + [animator cancel]; + } + + lv_pushUserdata(L, data); + + return 1; +} + +static int isRunning(lua_State *L) { + LVUserDataInfo *data = (LVUserDataInfo *)lua_touserdata(L, 1); + + if (LVIsType(data, Animator)) { + LVAnimator *animator = (__bridge LVAnimator *)data->object; + lua_pushboolean(L, animator.running); + } else { + lua_pushboolean(L, 0); + } + + return 1; +} + +static int pauseAnimator(lua_State *L) { + LVUserDataInfo *data = (LVUserDataInfo *)lua_touserdata(L, 1); + + if (LVIsType(data, Animator)) { + LVAnimator *animator = (__bridge LVAnimator *)data->object; + [animator pause]; + } + + lv_pushUserdata(L, data); + + return 1; +} + +static int resumeAnimator(lua_State *L) { + LVUserDataInfo *data = (LVUserDataInfo *)lua_touserdata(L, 1); + + if (LVIsType(data, Animator)) { + LVAnimator *animator = (__bridge LVAnimator *)data->object; + [animator resume]; + } + + lv_pushUserdata(L, data); + + return 1; +} + +static int isPaused(lua_State *L) { + LVUserDataInfo *data = (LVUserDataInfo *)lua_touserdata(L, 1); + + if (LVIsType(data, Animator)) { + LVAnimator *animator = (__bridge LVAnimator *)data->object; + lua_pushboolean(L, animator.paused); + } else { + lua_pushboolean(L, 0); + } + + return 1; +} + +static int duration(lua_State *L) { + LVUserDataInfo *data = (LVUserDataInfo *)lua_touserdata(L, 1); + float value = lua_tonumber(L, 2); + + if (LVIsType(data, Animator)) { + LVAnimator *animator = (__bridge LVAnimator *)data->object; + + animator.duration = value; + } + + lv_pushUserdata(L, data); + + return 1; +} + +static int delay(lua_State *L) { + LVUserDataInfo *data = (LVUserDataInfo *)lua_touserdata(L, 1); + float value = lua_tonumber(L, 2); + + if (LVIsType(data, Animator)) { + LVAnimator *animator = (__bridge LVAnimator *)data->object; + + animator.delay = value; + } + + lv_pushUserdata(L, data); + + return 1; +} + +static int repeatCount(lua_State *L) { + LVUserDataInfo *data = (LVUserDataInfo *)lua_touserdata(L, 1); + int value = (int)lua_tointeger(L, 2); + + if (LVIsType(data, Animator)) { + LVAnimator *animator = (__bridge LVAnimator *)data->object; + + animator.repeatCount = value; + } + + lv_pushUserdata(L, data); + + return 1; +} + +static int autoreverses(lua_State *L) { + LVUserDataInfo *data = (LVUserDataInfo *)lua_touserdata(L, 1); + BOOL autoreverses = !!lua_toboolean(L, 2); + + if (LVIsType(data, Animator)) { + LVAnimator *animator = (__bridge LVAnimator *)data->object; + + animator.autoreverses = autoreverses; + } + + lv_pushUserdata(L, data); + + return 1; +} + +static int interpolator(lua_State *L) { + LVUserDataInfo *data = (LVUserDataInfo *)lua_touserdata(L, 1); + LVAniamtorInterpolator interpolator = lua_tonumber(L, 2); + + if (LVIsType(data, Animator)) { + LVAnimator *animator = (__bridge LVAnimator *)data->object; + + animator.interpolator = interpolator; + } + + lv_pushUserdata(L, data); + + return 1; +} + +static int setCallback(lua_State *L, int idx) { + LVUserDataInfo *data = (LVUserDataInfo *)lua_touserdata(L, 1); + + if (LVIsType(data, Animator)) { + lua_pushvalue(L, 1); + if (lua_type(L, 2) == LUA_TFUNCTION) { + lua_pushvalue(L, 2); + } else { + lua_pushnil(L); + } + + lv_udataRef(L, idx); + } + + lv_pushUserdata(L, data); + + return 1; +} + +static int onStart(lua_State *L) { + return setCallback(L, kLVAnimatorCallbackOnStart); +} + +static int onEnd(lua_State *L) { + return setCallback(L, kLVAnimatorCallbackOnEnd); +} + +static int onCancel(lua_State *L) { + return setCallback(L, kLVAnimatorCallbackOnCancel); +} + +static int onPause(lua_State *L) { + return setCallback(L, kLVAnimatorCallbackOnPause); +} + +static int onResume(lua_State *L) { + return setCallback(L, kLVAnimatorCallbackOnResume); +} + +static int callback(lua_State *L) { + LVUserDataInfo *data = (LVUserDataInfo *)lua_touserdata(L, 1); + if (LVIsType(data, Animator) && lua_type(L, 2) == LUA_TTABLE) { + lua_pushvalue(L, 2); + lua_pushnil(L); + + while (lua_next(L, -2)) { + if (lua_type(L, -2) != LUA_TSTRING) { + continue; + } + const char* key = lua_tostring(L, -2); + int idx = 0; + for (int i = 0; i < sizeof(callbackKeys) / sizeof(callbackKeys[0]); ++i) { + if (strcmp(key, callbackKeys[i]) == 0) { + idx = i; + break; + } + } + + if (idx != 0) { + lua_pushvalue(L, 1); + if (lua_type(L, -2) == LUA_TFUNCTION) { + lua_pushvalue(L, -2); + } else { + lua_pushnil(L); + } + lv_udataRef(L, idx); + lua_pop(L, 2); + } else { + lua_pop(L, 1); + } + } + lua_pop(L, 1); + } + + lv_pushUserdata(L, data); + + return 1; +} + +static int updateValue(lua_State *L, NSString *keyPath, id value) { + LVUserDataInfo *data = (LVUserDataInfo *)lua_touserdata(L, 1); + if (LVIsType(data, Animator)) { + LVAnimator *animator = (__bridge LVAnimator *)data->object; + if (keyPath) { + animator.keyPath = keyPath; + } + + animator.toValue = value; + } + + lua_settop(L, 1); + + return 1; +} + +static int updateFloat(lua_State *L, NSString *keyPath) { + float value = lua_tonumber(L, 2); + + return updateValue(L, keyPath, @(value)); +} + +static int updatePoint(lua_State *L, NSString *keyPath) { + float x = lua_tonumber(L, 2), y = lua_tonumber(L, 3); + NSValue *point = [NSValue valueWithCGPoint:CGPointMake(x, y)]; + + return updateValue(L, keyPath, point); +} + +static int alpha(lua_State *L) { + return updateFloat(L, @"opacity"); +} + +static int rotation(lua_State *L) { + return updateFloat(L, @"transform.rotation"); +} + +static int scale(lua_State *L) { + // default y = x + if (lua_gettop(L) == 2) { + lua_pushnumber(L, lua_tonumber(L, 2)); + } + return updatePoint(L, @"transform.scale"); +} + +static int scaleX(lua_State *L) { + return updateFloat(L, @"transform.scale.x"); +} + +static int scaleY(lua_State *L) { + return updateFloat(L, @"transform.scale.y"); +} + +static int translation(lua_State *L) { + return updatePoint(L, @"transform.translation"); +} + +static int translationX(lua_State *L) { + return updateFloat(L, @"transform.translation.x"); +} + +static int translationY(lua_State *L) { + return updateFloat(L, @"transform.translation.y"); +} + +static int value(lua_State *L) { + return updateFloat(L, nil); +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewAnimator globalName:globalName defaultName:@"Animation"]; + + const struct luaL_Reg memberFunctions[] = { + { "__gc", __gc }, + { "__tostring", __tostring }, + { "__eq", __eq }, + + { "clone", clone }, + + { "with", with }, + { "duration", duration }, + { "delay", delay }, + { "repeatCount", repeatCount }, + { "reverses", autoreverses }, // 和安卓特性不一样 + { "interpolator", interpolator }, + + { "cancel", cancel }, + { "start", start }, + { "isRunning", isRunning }, + + { "pause", pauseAnimator }, + { "resume", resumeAnimator }, + { "isPaused", isPaused }, + + { "callback", callback }, + { callbackKeys[kLVAnimatorCallbackOnStart], onStart }, + { callbackKeys[kLVAnimatorCallbackOnEnd], onEnd }, + { callbackKeys[kLVAnimatorCallbackOnCancel], onCancel }, + { callbackKeys[kLVAnimatorCallbackOnPause], onPause }, + { callbackKeys[kLVAnimatorCallbackOnResume], onResume }, + + { "alpha", alpha }, + { "rotation", rotation }, + { "scale", scale }, + { "scaleX", scaleX }, + { "scaleY", scaleY }, + { "translation", translation }, + { "translationX", translationX }, + { "translationY", translationY }, + { "value", value }, // IOS支持一个, 安卓支持多个值 + //{ "values", value }, + + { NULL, NULL} + }; + + lv_createClassMetaTable(L, META_TABLE_Animator); + luaL_openlib(L, NULL, memberFunctions, 0); + + return 1; +} + +- (instancetype)init { + if (self = [super init]) { + _autoreverses = YES; + } + + return self; +} + +- (instancetype)copyWithZone:(NSZone *)zone { + LVAnimator *animator = [[[self class] allocWithZone:zone] init]; + animator.keyPath = [self.keyPath copy]; + animator.toValue = [self.toValue copy]; + + animator.duration = self.duration; + animator.delay = self.delay; + animator.repeatCount = self.repeatCount; + animator.autoreverses = self.autoreverses; + + animator.target = self.target; + + return animator; +} + +- (instancetype)mutableCopyWithZone:(NSZone *)zone { + return [self copyWithZone:zone]; +} + +- (NSUInteger)hash { + return self.keyPath.hash; +} + +- (BOOL)isEqual:(id)object { + if (object == nil) { + return NO; + } + if (![object isKindOfClass:[self class]]) { + return NO; + } + + LVAnimator *a1 = (LVAnimator *)object; + return lv_objcEqual(self.keyPath, a1.keyPath) && + lv_objcEqual(self.toValue, a1.toValue) && + self.duration == a1.duration && + self.delay == a1.delay && + self.repeatCount == a1.repeatCount && + self.autoreverses == a1.autoreverses; +} + +- (CAMediaTimingFunction *)buildTimingFunction:(LVAniamtorInterpolator)interpolator { + switch (interpolator) { + case LVAnticipateInterpolator: + return [CAMediaTimingFunction functionWithControlPoints:0.5 :-0.6 :0.75 :0.5]; + case LVAnticipateOvershootInterpolator: + return [CAMediaTimingFunction functionWithControlPoints:0.5 :-0.55 :0.5 :1.55]; + case LVOvershootInterpolator: + return [CAMediaTimingFunction functionWithControlPoints:0.3 :0.9 :0.75 :1.3]; + case LVAccelerateDecelerateInterpolator: + return [CAMediaTimingFunction functionWithName:@"easeInEaseOut"]; + case LVAccelerateInterpolator: + return [CAMediaTimingFunction functionWithName:@"easeIn"]; + case LVDecelerateInterpolator: + return [CAMediaTimingFunction functionWithName:@"easeOut"]; + case LVLinearInterpolator: + default: + return [CAMediaTimingFunction functionWithName:@"linear"]; + } +} + +- (CAAnimation *)buildAnimation { + CAAnimation *animation = nil; + CALayer *layer = self.target.layer.presentationLayer ?: self.target.layer; + + if ([self.keyPath isEqualToString:@"transform.scale"]) { + CGPoint point = [self.toValue CGPointValue]; + + NSString *kx = @"transform.scale.x"; + CABasicAnimation *ax = [CABasicAnimation animationWithKeyPath:kx]; + ax.fromValue = [layer valueForKeyPath:kx]; + ax.toValue = @(point.x); + + NSString *ky = @"transform.scale.y"; + CABasicAnimation *ay = [CABasicAnimation animationWithKeyPath:ky]; + ay.fromValue = [layer valueForKeyPath:ky]; + ay.toValue = @(point.y); + + CAAnimationGroup *group = [CAAnimationGroup animation]; + group.animations = @[ax, ay]; + + animation = group; + } else if ([self.keyPath isEqualToString:@"transform.rotation"]) { + CABasicAnimation *a = [CABasicAnimation animationWithKeyPath:@"transform.rotation"]; + a.fromValue = [layer valueForKeyPath:@"transform.rotation"]; + a.toValue = @(((NSNumber *)self.toValue).floatValue * M_PI / 180.0); + + animation = a; + } else { + CABasicAnimation *a = [CABasicAnimation animationWithKeyPath:self.keyPath]; + a.fromValue = [layer valueForKeyPath:self.keyPath]; + a.toValue = self.toValue; + + animation = a; + } + + animation.delegate = (id)self; + animation.duration = self.duration; + animation.fillMode = @"both"; + + if (self.repeatCount > 0) { + animation.repeatCount = self.repeatCount; + if (animation.autoreverses) { + animation.repeatCount += 0.5; + } + animation.autoreverses = self.autoreverses; + } else if (self.repeatCount < 0) { + animation.repeatCount = HUGE_VALF; + animation.autoreverses = self.autoreverses; + } + + animation.timingFunction = [self buildTimingFunction:self.interpolator]; + animation.beginTime = CACurrentMediaTime() + self.delay; + + return animation; +} + +static void syncValue(CAAnimation *animation, CALayer *layer) { + if (!animation || !layer) { + return; + } + + if ([animation isKindOfClass:[CAAnimationGroup class]]) { + for (CAAnimation *a in ((CAAnimationGroup *)animation).animations) { + syncValue(a, layer); + } + } else if ([animation isKindOfClass:[CABasicAnimation class]]) { + CABasicAnimation *a = (CABasicAnimation *)animation; + [layer setValue:a.toValue forKeyPath:a.keyPath]; + } +} + +- (void)syncAnimatingValue:(CALayer *)layer { + if (!layer.presentationLayer) { + return; + } + + NSString *keyPath = nil; + if ([self.keyPath isEqualToString:@"opacity"]) { + keyPath = @"opacity"; + } else { + keyPath = @"transform"; + } + NSValue *current = [layer.presentationLayer valueForKeyPath:keyPath]; + [layer setValue:current forKeyPath:keyPath]; +} + +- (void)start { + if (self.running) { + LVLog(@"Animator(%p keyPath:%@) is running!", self.lv_userData, self.keyPath); + return; + } + if (self.keyPath.length == 0 || self.toValue == nil) { + LVLog(@"Animator keyPath and value cannot be nil!"); + return; + } + + CAAnimation *animation = nil; + if (self.target != nil && (animation = [self buildAnimation])) { + _animationKey = [NSString stringWithFormat:@"LVAnimator:%@", self.keyPath]; + + CALayer *layer = self.target.layer; + if ([layer animationForKey:_animationKey]) { + LVLog(@"warning: Animation of keyPath:%@ is running", self.keyPath); + } + + syncValue(animation, layer); + [layer addAnimation:animation forKey:_animationKey]; + [self callback:kLVAnimatorCallbackOnStart]; + } +} + +- (void)cancel { + if (!self.running) { + LVLog(@"warning: Animation of keyPath:%@ is not running", self.keyPath); + return; + } + + if (self.paused) { + _animationKey = nil; + _pausedAnimation = nil; + _timeOffset = 0.0; + [self callback:kLVAnimatorCallbackOnCancel]; + + // call onEnd, same as Android SDK + [self callback:kLVAnimatorCallbackOnEnd]; + } else { + CALayer *layer = self.target.layer; + [self syncAnimatingValue:layer]; + [layer removeAnimationForKey:_animationKey]; + } +} + +- (BOOL)isRunning { + return _animationKey != nil; +} + +- (void)pause { + if (!self.running) { + LVLog(@"Animator(%p) is not running!", self.lv_userData); + return; + } + if (self.paused) { + LVLog(@"Animator(%p) is already paused!", self.lv_userData); + return; + } + + CALayer *layer = self.target.layer; + [self syncAnimatingValue:layer]; + + _pausedAnimation = [[layer animationForKey:_animationKey] copy]; + _timeOffset = CACurrentMediaTime() - _pausedAnimation.beginTime; + + [layer removeAnimationForKey:_animationKey]; +} + +- (void)resume { + CALayer *layer = self.target.layer; + + _pausedAnimation.beginTime = CACurrentMediaTime() - _timeOffset; + + syncValue(_pausedAnimation, layer); + [layer addAnimation:_pausedAnimation forKey:_animationKey]; + + _timeOffset = 0.0; + _pausedAnimation = nil; + + [self callback:kLVAnimatorCallbackOnResume]; +} + +- (BOOL)isPaused { + return _pausedAnimation != nil; +} + +#pragma mark - animation delegate + +- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag { + if (self.paused) { + [self callback:kLVAnimatorCallbackOnPause]; + } else { + _animationKey = nil; + _pausedAnimation = nil; + _timeOffset = 0.0; + + if (!flag) { + [self callback:kLVAnimatorCallbackOnCancel]; + } + + // call onEnd, same as Android SDK + [self callback:kLVAnimatorCallbackOnEnd]; + } +} + +- (void)callback:(LVAnimatorCallback)idx { + lua_State* l = self.lv_luaviewCore.l; + if (l && self.lv_userData) { + int stackIndex = lua_gettop(l); + + lv_pushUserdata(l, self.lv_userData); + lv_pushUDataRef(l, idx); + lv_runFunction(l); + + if (lua_gettop(l) > stackIndex) { + lua_settop(l, stackIndex); + } + } +} + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAudioPlayer.h b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAudioPlayer.h new file mode 100644 index 00000000..dd866691 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAudioPlayer.h @@ -0,0 +1,26 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + + +@interface LVAudioPlayer : NSObject + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; + +-(id) init:(lua_State*) l; + +-(void) play; +-(void) stop; + + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAudioPlayer.m b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAudioPlayer.m new file mode 100644 index 00000000..2cac5b6e --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAudioPlayer.m @@ -0,0 +1,248 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVAudioPlayer.h" +#import +#import "LView.h" +#import "LVHeads.h" + +@interface LVAudioPlayer () + +@property(nonatomic,assign) BOOL playing; +@property (nonatomic, copy) NSString *fileName; + +@property (nonatomic, assign) CGFloat volume; + +@end + +@implementation LVAudioPlayer{ + AVAudioPlayer* audioPlayer; +} + +static void releaseUserDataAudioPlayer(LVUserDataInfo* user){ + if( user && user->object ){ + LVAudioPlayer* palyer = CFBridgingRelease(user->object); + user->object = NULL; + if( palyer ){ + [palyer stop]; + palyer.lv_userData = NULL; + palyer.lv_luaviewCore = nil; + } + } +} + +-(void) dealloc{ + releaseUserDataAudioPlayer(_lv_userData); +} + +-(id) init:(lua_State*) L{ + self = [super init]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(L); + _volume = -1; + } + return self; +} + +-(void) setPlayFileName0:(NSString*) fileName bundle:(LVBundle*) bundle{ + + NSString* path = [bundle resourcePathWithName:fileName]; + if( path ) { + NSURL* url = [[NSURL alloc] initWithString:path]; + NSError* error = nil; + [self stop]; + audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];//使用本地URL创建 + audioPlayer.delegate = self; + + [self setVolume:_volume]; + + if( error ) { + NSLog(@"[LuaView][error]%@",error); + }else{ + self.fileName = fileName; + } + } + + [self play]; +} + +-(void) setPlayFileName:(NSString*) fileName bundle:(LVBundle*) bundle{ + if( fileName ==nil ) + return; + if( [LVUtil isExternalUrl:fileName] ){ + + __weak typeof (self) wself = self; + [LVUtil download:fileName callback:^(NSData *fileData) { + NSString* suffix = [fileName componentsSeparatedByString:@"."].lastObject; + NSData* theFileNameData = [fileName dataUsingEncoding:NSUTF8StringEncoding]; + NSString* md5Path = [LVUtil MD5HashFromData:theFileNameData]; + md5Path = [NSString stringWithFormat:@"%@.%@",md5Path,suffix];//Mp3文件一定要加后缀,否则无法播放 + if( [LVUtil saveData:fileData toFile:[LVUtil PathForCachesResource:md5Path]] ) { + [wself setPlayFileName0:md5Path bundle:bundle]; + } + }]; + } else { + [self setPlayFileName0:fileName bundle:bundle]; + } +} + +-(void) play { + if (!self.playing){ + [audioPlayer play]; + [self setVolume:0.5]; + self.playing = YES; + } +} + +-(void) stop { + [audioPlayer stop]; + self.playing = NO; +} + +-(void)setVolume:(CGFloat)volume{ + if ([[[UIDevice currentDevice] systemVersion] compare:@"10.0" options:NSNumericSearch] == NSOrderedDescending){ + if (volume < 0 || volume > 1){ + return; + } + _volume = volume; + [audioPlayer setVolume:volume fadeDuration:0]; + } +} + +- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag{ + self.playing = NO; +} + +- (id) lv_nativeObject{ + return audioPlayer; +} + +#pragma -mark AudioPlayer + +static int lvNewAudioPlayer (lua_State *L) { + + Class c = [LVUtil upvalueClass:L defaultClass:[LVAudioPlayer class]]; + + LVAudioPlayer* player = [[c alloc] init:L]; + LuaViewCore* lview = LV_LUASTATE_VIEW(L); + + if( lua_gettop(L)>=1 ) { + NSString* fileName = lv_paramString(L, 1); + [player setPlayFileName:fileName bundle:lview.bundle]; + } + + { + NEW_USERDATA(userData, AudioPlayer); + userData->object = CFBridgingRetain(player); + player.lv_userData = userData; + + luaL_getmetatable(L, META_TABLE_AudioPlayer ); + lua_setmetatable(L, -2); + } + return 1; +} + +static int play (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + + if( user && LVIsType(user, AudioPlayer) ){ + LVAudioPlayer* player = (__bridge LVAudioPlayer *)(user->object); + if( player ){ + + if( lua_gettop(L)>=2 ) { + NSString* fileName = lv_paramString(L, 2); + + if (![player.fileName isEqualToString:fileName]){ + [player stop]; + LuaViewCore* lview = LV_LUASTATE_VIEW(L); + [player setPlayFileName:fileName bundle:lview.bundle]; + } + } + + [player play]; + lua_pushvalue(L,1); + return 1; + } + } + return 0; +} + +static int stop (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVAudioPlayer* player = (__bridge LVAudioPlayer *)(user->object); + if( player ){ + [player stop]; + } + } + return 0; +} + +static int setVolume(lua_State *L){ + //设置音量接口只有在iOS10.0以上才生效 + LVUserDataInfo *user = (LVUserDataInfo *)lua_touserdata(L, 1); + if (user){ + LVAudioPlayer *player = (__bridge LVAudioPlayer *)(user->object); + if (player){ + if( lua_gettop(L)>=2 ) { + float volume = lua_tonumber(L, 2); + + [player setVolume:volume]; + } + } + } + + return 0; +} + +static int __gc (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + releaseUserDataAudioPlayer(user); + return 0; +} + +static int __tostring (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVAudioPlayer* player = (__bridge LVAudioPlayer *)(user->object); + NSString* s = [NSString stringWithFormat:@"LVUserDataAudioPlayer: %@", player ]; + lua_pushstring(L, s.UTF8String); + return 1; + } + return 0; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewAudioPlayer globalName:globalName defaultName:@"AudioPlayer"]; + + const struct luaL_Reg memberFunctions [] = { + {"play", play }, + {"stop", stop }, + {"setVolume", setVolume}, + // pause + // resume + // callback { onComplete onError } + + // playing + // looping + // pausing + + {"__gc", __gc }, + {"__tostring", __tostring }, + {NULL, NULL} + }; + lv_createClassMetaTable(L, META_TABLE_AudioPlayer); + + luaL_openlib(L, NULL, memberFunctions, 0); + return 1; +} + +@end + + + diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVBaseView.h b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVBaseView.h new file mode 100644 index 00000000..c34e144d --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVBaseView.h @@ -0,0 +1,34 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + +@interface LVBaseView : UIView + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; +@property(nonatomic,assign) NSUInteger lv_align; + +@property(nonatomic,strong) CAShapeLayer* lv_shapeLayer; +@property(nonatomic,assign) BOOL lv_canvas; +@property(nonatomic,strong) NSString * lv_identifier; + +-(id) init:(lua_State*) l; + ++(const luaL_Reg*) baseMemberFunctions; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +@end + + +/** + * callback回调统一处理API + */ +extern int lv_setCallbackByKey(lua_State *L, const char* key, BOOL addGesture); diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVBaseView.m b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVBaseView.m new file mode 100644 index 00000000..d6cbcab9 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVBaseView.m @@ -0,0 +1,1826 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVBaseView.h" +#import "LView.h" +#import "LVTransform3D.h" +#import "LVAnimator.h" +#import +#import "LVStruct.h" +#import "JUFLXLayoutKit.h" +#import "UIView+JUFLXNode.h" +#import "LVGesture.h" +#import "LVHeads.h" + +@interface LVBaseView () +@property(nonatomic,assign) BOOL lv_isCallbackAddClickGesture;// 支持Callback 点击事件 +@end + +@implementation LVBaseView + + +-(id) init:(lua_State*) L{ + self = [super init]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(L); + self.clipsToBounds = YES; + self.lv_isCallbackAddClickGesture = YES; + } + return self; +} + +static void releaseUserDataView(LVUserDataInfo* userdata){ + if( userdata && userdata->object ){ + UIView* view = CFBridgingRelease(userdata->object); + userdata->object = NULL; + if( view ){ + view.lv_userData = NULL; + view.lv_luaviewCore = nil; + if( !userdata->isWindow ) { + [view removeFromSuperview]; + [view.layer removeFromSuperlayer]; + } + } + } +} + +-(void) dealloc { +} + +#pragma -mark center +static int center (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + CGPoint center = view.center; + if ( lua_gettop(L)>=2 ) { + if ( lua_isuserdata(L, 2) ) { + LVUserDataInfo* user = lua_touserdata(L, 2); + if ( LVIsType(user, Struct) ) { + LVStruct* stru = (__bridge LVStruct *)(user->object); + if( [stru dataPointer] ) { + memcpy(¢er, [stru dataPointer], sizeof(CGPoint)); + } + } else { + LVError(@"LVBaseView.setCenter1"); + } + } else { + if( lua_isnumber(L, 2) ){ + center.x = lua_tonumber(L, 2);// 2 + } + if( lua_isnumber(L, 3) ){ + center.y = lua_tonumber(L, 3);// 3 + } + } + if( isnan(center.x) || isnan(center.y) ){ + LVError(@"LVBaseView.setCenter2"); + } else { + view.center = center; + } + view.lv_align = 0; + return 0; + } else { + lua_pushnumber(L, center.x ); + lua_pushnumber(L, center.y ); + return 2; + } + } + } + return 0; +} + +static int centerX(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + CGPoint center = view.center; + if ( lua_gettop(L)>=2 ) { + if( lua_isnumber(L, 2) ){ + center.x = lua_tonumber(L, 2);// 2 + } + if( isnan(center.x) || isnan(center.y) ){ + LVError(@"LVBaseView.setCenterX2"); + } else { + view.center = center; + } + return 0; + } else { + lua_pushnumber(L, center.x ); + return 1; + } + } + } + return 0; +} + +static int centerY(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + CGPoint center = view.center; + if ( lua_gettop(L)>=2 ) { + if( lua_isnumber(L, 2) ){ + center.y = lua_tonumber(L, 2);// 2 + } + if( isnan(center.x) || isnan(center.y) ){ + LVError(@"LVBaseView.setCenterX2"); + } else { + view.center = center; + } + return 0; + } else { + lua_pushnumber(L, center.y ); + return 1; + } + } + } + return 0; +} + +#pragma -mark frame +static int frame (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + CGRect r = view.frame; + if( lua_gettop(L)>=2 ) { + if ( lua_isuserdata(L, 2) ) { + LVUserDataInfo* user = lua_touserdata(L, 2); + if ( LVIsType(user, Struct) ) { + LVStruct* stru = (__bridge LVStruct *)(user->object); + if( [stru dataPointer] ) { + memcpy(&r, [stru dataPointer], sizeof(CGRect)); + } + } else { + LVError(@"LVBaseView.setFrame1"); + } + } else { + if( lua_isnumber(L, 2) ){ + r.origin.x = lua_tonumber(L, 2);// 2 + } + if( lua_isnumber(L, 3) ){ + r.origin.y = lua_tonumber(L, 3);// 3 + } + if( lua_isnumber(L, 4) ){ + r.size.width = lua_tonumber(L, 4);// 4 + } + if( lua_isnumber(L, 5) ){ + r.size.height = lua_tonumber(L, 5);// 5 + } + } + if( isnan(r.origin.x) || isnan(r.origin.y) || isnan(r.size.width) || isnan(r.size.height) ){ + LVError(@"LVBaseView.setFrame2: %s", NSStringFromCGRect(r) ); + } else { + view.frame = r; + } + view.lv_align = 0; + return 0; + } else { + lua_pushnumber(L, r.origin.x ); + lua_pushnumber(L, r.origin.y ); + lua_pushnumber(L, r.size.width ); + lua_pushnumber(L, r.size.height ); + return 4; + } + } + } + return 0; +} + +#pragma -mark frame +static int size (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + CGRect r = view.frame; + if ( lua_gettop(L)>=2 ) { + if ( lua_isuserdata(L, 2) ) { + LVUserDataInfo* user = lua_touserdata(L, 2); + if ( LVIsType(user, Struct) ) { + LVStruct* stru = (__bridge LVStruct *)(user->object); + if( [stru dataPointer] ) { + memcpy(&r.size, [stru dataPointer], sizeof(CGSize)); + } + } else { + LVError(@"LVBaseView.setSize1"); + } + } else { + if( lua_isnumber(L, 2) ){ + r.size.width = lua_tonumber(L, 2);// 4 + } + if( lua_isnumber(L, 3) ){ + r.size.height = lua_tonumber(L, 3);// 5 + } + } + if( isnan(r.origin.x) || isnan(r.origin.y) || isnan(r.size.width) || isnan(r.size.height) ){ + LVError(@"LVBaseView.setSize2: %s", NSStringFromCGRect(r) ); + } else { + view.frame = r; + } + return 0; + } else { + lua_pushnumber(L, r.size.width ); + lua_pushnumber(L, r.size.height ); + return 2; + } + } + } + return 0; +} + +static int origin (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + CGRect r = view.frame; + if ( lua_gettop(L)>=2 ) { + if ( lua_isuserdata(L, 2) ) { + LVUserDataInfo* user = lua_touserdata(L, 2); + if ( LVIsType(user, Struct) ) { + LVStruct* stru = (__bridge LVStruct *)(user->object); + if( [stru dataPointer] ) { + memcpy(&r.origin, [stru dataPointer], sizeof(CGPoint)); + } + } else { + LVError(@"LVBaseView.setOrigin1"); + } + } else { + if( lua_isnumber(L, 2) ){ + r.origin.x = lua_tonumber(L, 2);// 2 + } + if( lua_isnumber(L, 3) ){ + r.origin.y = lua_tonumber(L, 3);// 3 + } + } + if( isnan(r.origin.x) || isnan(r.origin.y) || isnan(r.size.width) || isnan(r.size.height) ){ + LVError(@"LVBaseView.setOrigin2: %s", NSStringFromCGRect(r) ); + } else { + view.frame = r; + } + view.lv_align = 0; + return 0; + } else { + lua_pushnumber(L, r.origin.x ); + lua_pushnumber(L, r.origin.y ); + return 2; + } + } + } + return 0; +} + +static int x (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + CGRect r = view.frame; + if ( lua_gettop(L)>=2 ) { + r.origin.x = lua_tonumber(L, 2);// 2 + if( isnan(r.origin.x) || isnan(r.origin.y) || isnan(r.size.width) || isnan(r.size.height) ){ + LVError(@"LVBaseView.y2: %s", NSStringFromCGRect(r) ); + } else { + view.frame = r; + } + view.lv_align = 0; + return 0; + } else { + lua_pushnumber(L, r.origin.x ); + return 1; + } + } + } + return 0; +} + +#pragma - mark flxNode +static int flxChildViews(lua_State *L) +{ + LVUserDataInfo *user = (LVUserDataInfo *)lua_touserdata(L, 1); + if (user) { + UIView *view = (__bridge UIView *)(user->object); + int childNum = lua_gettop(L); + if (view && childNum>=2 ) { + NSArray *arr = (NSArray*)lv_luaValueToNativeObject(L, 2); + if ([arr isKindOfClass:[NSArray class]] && arr.count > 0) { + NSMutableArray* childs = [[NSMutableArray alloc] init]; + for( int i=0; iobject); + if( temp ) { + [childs addObject:temp.ju_flxNode]; + } + } + view.ju_flxNode.childNodes = childs; + return 0; + } + } + return 0; +} + +static int flxBindingInlineCSS(lua_State *L) +{ + LVUserDataInfo *user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ) { + UIView *view = (__bridge UIView *)(user->object); + + int childNum = lua_gettop(L); + if (view && childNum==2) { + if (lua_type(L, 2) == LUA_TSTRING) { + [view.ju_flxNode bindingInlineCSS:[NSString stringWithUTF8String:lua_tostring(L, 2)]]; + return 0; + } + } + } + return 0; +} + +//static int flxMeasure(lua_State *L) +//{ +// LVUserDataView *user = (LVUserDataView *)lua_touserdata(L, 1); +// UIView *view = (__bridge UIView *)(user->view); +// int childNum = lua_gettop(L); +// if (view && childNum == 2) { +// if (lua_type(L, 2) == LUA_TFUNCTION) { +// lua_pushvalue(L, 1); +// lua_pushvalue(L, 2); +// lv_udataRef(L, USERDATA_FLEX_DELEGATE); +// } +// view.ju_flxNode.measure = ^CGSize(CGFloat width) { +// lv_pushUserdata(L, user ); +// lv_pushUDataRef(L, USERDATA_FLEX_DELEGATE ); +// lua_pushnumber(L, width); +// lv_runFunctionWithArgs(L, 1, 2); +// CGSize size = CGSizeZero; +// size.width = lua_tonumber(L, -2); +// size.height = lua_tonumber(L, -1); +// return size; +// }; +// +// } +// return 0; +//} + +static int flxLayout(lua_State *L) +{ + LVUserDataInfo *user = (LVUserDataInfo *)lua_touserdata(L, 1); + if (user) { + BOOL async = FALSE; + int argNum = lua_gettop(L); + for ( int i=1; i<=argNum; i++ ) { + if ( lua_type(L, i)==LUA_TBOOLEAN ){ + async = lua_toboolean(L, i); + } + if( lua_type(L, i) == LUA_TFUNCTION ) { + lua_pushvalue(L, 1); + lua_pushvalue(L, i); + lv_udataRef(L, USERDATA_FLEX_DELEGATE); + } + } + UIView *view = (__bridge UIView *)(user->object); + [view.ju_flxNode layoutAsync:async completionBlock:^(CGRect frame) { + lv_pushUserdata(L, user ); + lv_pushUDataRef(L, USERDATA_FLEX_DELEGATE ); + lv_runFunction(L); + }]; + } + return 0; +} + + +static int y (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + CGRect r = view.frame; + if ( lua_gettop(L)>=2 ) { + r.origin.y = lua_tonumber(L, 2);// 2 + if( isnan(r.origin.x) || isnan(r.origin.y) || isnan(r.size.width) || isnan(r.size.height) ){ + LVError(@"LVBaseView.y2: %s", NSStringFromCGRect(r) ); + } else { + view.frame = r; + } + view.lv_align = 0; + return 0; + } else { + lua_pushnumber(L, r.origin.y ); + return 1; + } + } + } + return 0; +} + +static int bottom (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + CGRect r = view.frame; + if ( lua_gettop(L)>=2 ) { + r.origin.y = lua_tonumber(L, 2)-r.size.height;// 2 + if( isnan(r.origin.x) || isnan(r.origin.y) || isnan(r.size.width) || isnan(r.size.height) ){ + LVError(@"LVBaseView.y2: %s", NSStringFromCGRect(r) ); + } else { + view.frame = r; + } + view.lv_align = 0; + return 0; + } else { + lua_pushnumber(L, r.origin.y + r.size.height ); + return 1; + } + } + } + return 0; +} + +static int right (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + CGRect r = view.frame; + if ( lua_gettop(L)>=2 ) { + r.origin.x = lua_tonumber(L, 2)-r.size.width;// 2 + if( isnan(r.origin.x) || isnan(r.origin.y) || isnan(r.size.width) || isnan(r.size.height) ){ + LVError(@"LVBaseView.y2: %s", NSStringFromCGRect(r) ); + } else { + view.frame = r; + } + view.lv_align = 0; + return 0; + } else { + lua_pushnumber(L, r.origin.x + r.size.width ); + return 1; + } + } + } + return 0; +} + +static int width (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + CGRect r = view.frame; + if ( lua_gettop(L)>=2 ) { + r.size.width = lua_tonumber(L, 2);// 2 + if( isnan(r.origin.x) || isnan(r.origin.y) || isnan(r.size.width) || isnan(r.size.height) ){ + LVError(@"LVBaseView.y2: %s", NSStringFromCGRect(r) ); + } else { + view.frame = r; + } + return 0; + } else { + lua_pushnumber(L, r.size.width ); + return 1; + } + } + } + return 0; +} + +static int height (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + CGRect r = view.frame; + if ( lua_gettop(L)>=2 ) { + r.size.height = lua_tonumber(L, 2);// 2 + if( isnan(r.origin.x) || isnan(r.origin.y) || isnan(r.size.width) || isnan(r.size.height) ){ + LVError(@"LVBaseView.y2: %s", NSStringFromCGRect(r) ); + } else { + view.frame = r; + } + return 0; + } else { + lua_pushnumber(L, r.size.height ); + return 1; + } + } + } + return 0; +} + +static int addGestureRecognizer (lua_State *L) { + LVUserDataInfo * userDataView = (LVUserDataInfo *)lua_touserdata(L, 1); + LVUserDataInfo * userDataGesture = (LVUserDataInfo *)lua_touserdata(L, 2); + if( userDataView && LVIsType(userDataGesture, Gesture) ){ + UIView* view = (__bridge UIView *)(userDataView->object); + UIGestureRecognizer* gesture = (__bridge UIGestureRecognizer *)(userDataGesture->object); + if( view && gesture ){ + [view addGestureRecognizer:gesture]; + lua_pushvalue(L,1); + return 1; + } + } + return 0; +} + +static int removeGestureRecognizer (lua_State *L) { + LVUserDataInfo * userDataView = (LVUserDataInfo *)lua_touserdata(L, 1); + LVUserDataInfo * userDataGesture = (LVUserDataInfo *)lua_touserdata(L, 2); + if( userDataView && LVIsType(userDataGesture, Gesture) ){ + UIView* view = (__bridge UIView *)(userDataView->object); + UIGestureRecognizer* gesture = (__bridge UIGestureRecognizer *)(userDataGesture->object); + if( view && gesture ){ + [view removeGestureRecognizer:gesture]; + lua_pushvalue(L,1); + return 1; + } + } + return 0; +} + +static int addSubview (lua_State *L) { + LVUserDataInfo * father = (LVUserDataInfo *)lua_touserdata(L, 1); + LVUserDataInfo * son = (LVUserDataInfo *)lua_touserdata(L, 2); + LuaViewCore* luaview = LV_LUASTATE_VIEW(L); + if( father && LVIsType(son, View) ){ + UIView* superview = (__bridge UIView *)(father->object); + UIView* subview = (__bridge UIView *)(son->object); + if( superview && subview ){ + if( lua_gettop(L)>=3 && lua_type(L,3)==LUA_TNUMBER ){ + int index = lua_tonumber(L,3); + lv_addSubviewByIndex(luaview, superview, subview, index); + } else { + lv_addSubview(luaview, superview, subview); + } + [subview lv_alignSelfWithSuperRect:superview.frame]; + lua_pushvalue(L,1); + return 1; + } + } + return 0; +} + + +static int getNativeView (lua_State *L) { + LVUserDataInfo * userData = (LVUserDataInfo *)lua_touserdata(L, 1); + if( userData ){ + UIView* view = (__bridge UIView *)(userData->object); + if( view ){ + id object = [view lv_getNativeView]; + lv_pushNativeObjectWithBox(L, object); + return 1; + } + } + return 0; +} + +#pragma -mark 运行环境 +static int children (lua_State *L) { + LuaViewCore* lview = LV_LUASTATE_VIEW(L); + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + + UIView* newWindow = (__bridge UIView *)(user->object); + if ( lview && newWindow && lua_type(L, 2)==LUA_TFUNCTION ) { + lua_settop(L, 2); + [lview pushWindow:newWindow]; + lv_runFunctionWithArgs(L, 1, 0); + [lview popWindow:newWindow]; + } + return 0; +} + + +static int removeFromSuperview (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + [view removeFromSuperview]; + [view.layer removeFromSuperlayer]; + lua_pushvalue(L,1); + return 1; + } + } + return 0; +} + +static int removeAllSubviews (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + NSArray* subviews = view.subviews; + for( UIView* child in subviews ) { + [child removeFromSuperview]; + } + NSArray* sublayers = view.layer.sublayers; + for(CALayer * sublayer in sublayers ) { + [sublayer removeFromSuperlayer]; + } + lua_pushvalue(L,1); + return 1; + } + } + return 0; +} + + +static int bringToFront (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + UIView* superView = view.superview; + [superView bringSubviewToFront:view]; + lua_pushvalue(L,1); + return 1; + } + } + return 0; +} + +static int bringToBack (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + UIView* superView = view.superview; + [superView sendSubviewToBack:view]; + lua_pushvalue(L,1); + return 1; + } + } + return 0; +} + +static int layerMode(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + if ( lua_gettop(L)>=2 ) { + UIView* superview = view.superview; + BOOL yes = lua_toboolean(L, 2); + if( yes ) { + [view removeFromSuperview]; + [superview.layer addSublayer:view.layer]; + } else { + [view.layer removeFromSuperlayer]; + [superview addSubview:view]; + } + return 0; + } else { + //lua_pushboolean(L, view.hidden ); + //return 1; + } + } + } + return 0; +} + +#pragma -mark hidden +//__deprecated_msg("Use hide") +static int hidden(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + if ( lua_gettop(L)>=2 ) { + BOOL yes = lua_toboolean(L, 2); + view.hidden = yes; + return 0; + } else { + lua_pushboolean(L, view.hidden ); + return 1; + } + } + } + return 0; +} + +static int hide(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + view.hidden = YES; + return 0; + } + } + return 0; +} + +static int visible(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + if ( lua_gettop(L)>=2 ) { + BOOL yes = lua_toboolean(L, 2); + view.hidden = !yes; + return 0; + } else { + lua_pushboolean(L, !view.hidden ); + return 1; + } + } + } + return 0; +} + +static int show(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + view.hidden = NO; + return 0; + } + } + return 0; +} + +static int isShow(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + lua_pushboolean(L, !view.hidden ); + return 1; + } + } + return 0; +} + +static int isHide(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + lua_pushboolean(L, view.hidden ); + return 1; + } + } + return 0; +} + +static int becomeFirstResponder(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + if( view.canBecomeFirstResponder ) + [view becomeFirstResponder]; + + lua_pushvalue(L,1); + return 1; + } + } + return 0; +} + +static int resignFirstResponder(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + if( view.canResignFirstResponder) + [view resignFirstResponder]; + + lua_pushvalue(L,1); + return 1; + } + } + return 0; +} + +static int isFirstResponder(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + lua_pushboolean(L, view.isFirstResponder?1:0 ); + return 1; + } + } + return 0; +} + +#pragma -mark userInteractionEnabled +static int userInteractionEnabled(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + if ( lua_gettop(L)>=2 ) { + BOOL yes = lua_toboolean(L, 2); + view.userInteractionEnabled = yes; + return 0; + } else { + lua_pushboolean(L, view.userInteractionEnabled ); + return 1; + } + } + } + return 0; +} + +#pragma -mark backgroundColor +static int backgroundColor (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( [view isKindOfClass:[UIView class]] ){ + if( lua_gettop(L)>=2 ) { + UIColor* color = lv_getColorFromStack(L, 2); + view.backgroundColor = color; + return 0; + } else { + UIColor* color = view.backgroundColor; + NSUInteger c = 0; + CGFloat a = 0; + if( lv_uicolor2int(color, &c,&a) ){ + lua_pushnumber(L, c ); + lua_pushnumber(L, a); + return 2; + } + } + } + } + return 0; +} + +#pragma -mark alpha +static int alpha (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if ( lua_gettop(L)>=2 ) { + CALayer* layer = view.layer; + + double alpha = lua_tonumber(L, 2);// 2 + layer.opacity = alpha; + + lua_pop(L, 1); + return 1; + } else { + CALayer* layer = view.layer.presentationLayer ?: view.layer; + + float alpha = layer.opacity; + lua_pushnumber(L, alpha ); + return 1; + } + } + return 0; +} + +#pragma -mark cornerRadius +static int cornerRadius (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( lua_gettop(L)>=2 ) { + double r = lua_tonumber(L, 2);// 2 + view.layer.cornerRadius = r; + return 0; + } else { + float r = view.layer.cornerRadius; + lua_pushnumber(L, r ); + return 1; + } + } + return 0; +} + +#pragma -mark borderWidth +static int borderWidth (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( lua_gettop(L)>=2 ) { + double width = lua_tonumber(L, 2);// 2 + view.layer.borderWidth = width; + return 0; + } else { + float w = view.layer.borderWidth; + lua_pushnumber(L, w ); + return 1; + } + } + return 0; +} + +#pragma -mark shadow +static int setShadowPath (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + [view layer].shadowPath =[UIBezierPath bezierPathWithRect:view.bounds].CGPath; + lua_pushvalue(L,1); + return 1; + } + return 0; +} +static int setMasksToBounds (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + BOOL masksToBounds = lua_toboolean(L, 2);// 2 + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + view.layer.masksToBounds = masksToBounds; + lua_pushvalue(L,1); + return 1; + } + return 0; +} + +static int setShadowOffset (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + float x = lua_tonumber(L, 2);// 2 + float y = lua_tonumber(L, 3);// 2 + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + [view.layer setShadowOffset:CGSizeMake(x, y)]; + lua_pushvalue(L,1); + return 1; + } + return 0; +} + +static int setShadowRadius (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + float radius = lua_tonumber(L, 2);// 2 + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + [view.layer setShadowRadius:radius]; + lua_pushvalue(L,1); + return 1; + } + return 0; +} + +static int setShadowOpacity (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + float opacity = lua_tonumber(L, 2);// 2 + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + [view.layer setShadowOpacity:opacity]; + lua_pushvalue(L,1); + return 1; + } + return 0; +} + +static int setShadowColor (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user && lua_gettop(L)>=2 ){ + UIView* view = (__bridge UIView *)(user->object); + UIColor* color = lv_getColorFromStack(L, 2); + [view.layer setShadowColor:color.CGColor]; + lua_pushvalue(L,1); + return 1; + } + return 0; +} + + +#pragma -mark borderColor + +UIColor* lv_UIColorFromRGBA(NSInteger rgbValue, float alphaValue){ + return [UIColor + colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 + green: ((float)((rgbValue & 0x00FF00) >> 8 ))/255.0 + blue: ((float)((rgbValue & 0x0000FF) ))/255.0 + alpha:alphaValue]; + +} + +static int borderColor (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if ( lua_gettop(L)>=2 ) { + UIColor* color = lv_getColorFromStack(L, 2); + view.layer.borderColor = color.CGColor; + lua_pushvalue(L,1); + return 1; + } else { + UIColor* color = [UIColor colorWithCGColor:view.layer.borderColor]; + NSUInteger c = 0; + CGFloat a = 0; + if( lv_uicolor2int(color, &c, &a) ){ + lua_pushnumber(L, c ); + lua_pushnumber(L, a); + return 2; + } + } + } + return 0; +} + +static int borderDash (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + int argN = lua_gettop(L); + if ( argN>=2 ) { + NSMutableArray* arr = [[NSMutableArray alloc] initWithCapacity:argN]; + for( int i=2; i<=argN; i++) { + if( lua_type(L, i)==LUA_TNUMBER ) { + int v = lua_tonumber(L, i); + [arr addObject:[NSNumber numberWithInt:v]]; + } + } + //虚线边框 + if( arr.count>0 ) { + [view lv_createShapelayer:arr]; + } else { + view.lv_shapeLayer.lineDashPattern = nil; + [view.lv_shapeLayer removeFromSuperlayer]; + view.lv_shapeLayer = nil; + } + return 0; + } else { + NSArray* numbers = view.lv_shapeLayer.lineDashPattern; + for( int i=0; iobject); + if( view ){ + if( lua_gettop(L)>=2 ) { + BOOL yes = lua_toboolean(L, 2); + view.clipsToBounds = yes; + return 0; + } else { + lua_pushnumber(L, view.clipsToBounds ); + return 1; + } + } + } + return 0; +} + +static int adjustSize(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + [view sizeToFit]; + } + } + return 0; +} + +#pragma -mark transformRoteAndScale + +typedef void (TransformSetter)(CATransform3D *, CGFloat); +typedef double (TransformGetter)(CATransform3D *); + +static int transformFuncOneArg(lua_State *L, TransformSetter setter, TransformGetter getter) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + UIView *view = (__bridge UIView *)(user->object); + + if( user ){ + if ( lua_gettop(L) > 1 ) { + CALayer* layer = view.layer; + + double x = lua_tonumber(L, 2); + CATransform3D t = layer.transform; + setter(&t, x); + + layer.transform = t; + + lua_pop(L, 1); + return 1; + } else { + CALayer* layer = view.layer.presentationLayer ?: view.layer; + + CATransform3D t = layer.transform; + double x = getter(&t); + + lua_pushnumber(L, x); + return 1; + } + } + return 0; +} + +static int transformFuncTwoArg(lua_State *L, + TransformSetter xsetter, TransformSetter ysetter, + TransformGetter xgetter, TransformGetter ygetter) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + UIView *view = (__bridge UIView *)(user->object); + + if( user ){ + int argNum = lua_gettop(L); + if ( argNum > 1 ) { + CALayer* layer = view.layer; + + double x = lua_tonumber(L, 2), y = lua_tonumber(L, 3); + CATransform3D t = layer.transform; + xsetter(&t, x); + ysetter(&t, y); + + layer.transform = t; + + lua_pop(L, 1); + return 1; + } else { + CALayer* layer = view.layer.presentationLayer ?: view.layer; + + CATransform3D t = layer.transform; + double x = xgetter(&t), y = ygetter(&t); + + lua_pushnumber(L, x); + lua_pushnumber(L, y); + return 2; + } + } + return 0; +} + +inline static double degreeToRadian(double d) { + return d * M_PI / 180; +} + +inline static double radianToDegree(double r) { + return r / M_PI * 180; +} + +static void transform3DSetDegreeRotation(CATransform3D *t, CGFloat v) { + double r = degreeToRadian(v); + CATransform3DSetRotation(t, r); +} + +static double transform3DGetDegreeRotation(CATransform3D *t) { + double r = CATransform3DGetRotation(t); + return radianToDegree(r); +} + +static int rotationZ (lua_State *L) { + return transformFuncOneArg(L, transform3DSetDegreeRotation, + transform3DGetDegreeRotation); +} + +static int rotationX (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( lua_gettop(L)>=2 ) { + CALayer *layer = view.layer; + + double angle = degreeToRadian(lua_tonumber(L, 2)); + layer.transform = CATransform3DMakeRotation(angle, 1, 0, 0); + + lua_pop(L, 1); + return 1; + } else { + CALayer *layer = view.layer.presentationLayer ?: view.layer; + + double angle = [[layer valueForKeyPath:@"transform.rotation.x"] doubleValue]; + lua_pushnumber(L, angle); + return 1; + } + } + return 0; +} + +static int rotationY (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( lua_gettop(L)>=2 ) { + CALayer *layer = view.layer; + + double angle = degreeToRadian(lua_tonumber(L, 2)); + layer.transform = CATransform3DMakeRotation(angle, 0, 1, 0); + + lua_pop(L, 1); + return 1; + } else { + CALayer *layer = view.layer.presentationLayer ?: view.layer; + + double angle = [[layer valueForKeyPath:@"transform.rotation.y"] doubleValue]; + lua_pushnumber(L, angle); + return 1; + } + } + return 0; +} + +static int scale (lua_State *L) { + if (lua_gettop(L) == 2) { + lua_pushnumber(L, lua_tonumber(L, 2)); + } + return transformFuncTwoArg(L, CATransform3DSetScaleX, CATransform3DSetScaleY, + CATransform3DGetScaleX, CATransform3DGetScaleY); +} + +static int scaleX (lua_State *L) { + return transformFuncOneArg(L, CATransform3DSetScaleX, CATransform3DGetScaleX); +} + +static int scaleY (lua_State *L) { + return transformFuncOneArg(L, CATransform3DSetScaleY, CATransform3DGetScaleY); +} + +static int translation (lua_State *L) { + return transformFuncTwoArg(L, CATransform3DSetTranslationX, CATransform3DSetTranslationY, + CATransform3DGetTranslationX, CATransform3DGetTranslationY); +} + +static int translationX (lua_State *L) { + return transformFuncOneArg(L, CATransform3DSetTranslationX, CATransform3DGetTranslationX); +} + +static int translationY (lua_State *L) { + return transformFuncOneArg(L, CATransform3DSetTranslationY, CATransform3DGetTranslationY); +} + +static int transform3D (lua_State *L) { + LVUserDataInfo* user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if ( lua_gettop(L)>=2 ) { + LVUserDataInfo* userdata = (LVUserDataInfo *)lua_touserdata(L, 2); + if ( LVIsType(userdata, Transform3D)) { + CALayer *layer = view.layer; + + LVTransform3D* tran = (__bridge LVTransform3D *)(userdata->object); + layer.transform = tran.transform; + + lua_pop(L, 1); + return 1; + } + } else { + CALayer *layer = view.layer.presentationLayer ?: view.layer; + + CATransform3D t = layer.transform; + [LVTransform3D pushTransform3D:L transform3d:t]; + return 1; + } + } + return 0; +} + + +static int matrix (lua_State *L) { + LVUserDataInfo* user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if ( lua_gettop(L)>=2 ) { + if( lua_type(L, 2)== LUA_TTABLE ) { + NSArray* arr = lv_luaValueToNativeObject(L, 2); + if( [arr isKindOfClass:[NSArray class]] ) { + CGFloat a[12] = {0}; + for( int i=0; iobject); + if (animator == nil) { + continue; + } + + animator.target = (__bridge UIView *)(vdata->object); + [animator start]; + } + } + + return 0; +} + +static int stopAnimation(lua_State *L) { + LVUserDataInfo* user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + [view.layer removeAllAnimations]; + } + + return 0; +} + +#pragma -mark anchorPoint +static int anchorPoint (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( lua_gettop(L)>=2 ) { + double x = lua_tonumber(L, 2);// 2 + double y = lua_tonumber(L, 3);// 3 + view.layer.anchorPoint = CGPointMake(x, y); + return 0; + } else { + CGPoint p = view.layer.anchorPoint; + lua_pushnumber(L, p.x ); + lua_pushnumber(L, p.y ); + return 2; + } + } + return 0; +} + +int lv_setCallbackByKey(lua_State *L, const char* key, BOOL addGesture) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + if ( lua_gettop(L)>=2 ) { + UIView* view = (__bridge UIView *)(user->object); + if( addGesture ) { + [view lv_callbackAddClickGesture];// 检测是否添加手势 + } + lua_checkstack(L, 8); + lua_pushvalue(L, 1); + lv_pushUDataRef(L, USERDATA_KEY_DELEGATE); + if( lua_type(L, -1)==LUA_TNIL ) { + lua_settop(L, 2); + lua_pushvalue(L, 1); + lua_createtable(L, 0, 0); + lv_udataRef(L, USERDATA_KEY_DELEGATE ); + + lua_settop(L, 2); + lua_pushvalue(L, 1); + lv_pushUDataRef(L, USERDATA_KEY_DELEGATE); + } + lua_pushvalue(L, 2); + if( key==NULL && lua_type(L, -1) == LUA_TTABLE ) { + // 如果是表格 设置每个Key + lua_pushnil(L); + while (lua_next(L, -2)) + { + NSString* key = lv_paramString(L, -2); + lua_setfield(L, -4, key.UTF8String); + } + } else { + // 如果是方法设置默认key + lua_setfield(L, -2, (key ? key:STR_ON_CLICK) ); + } + return 0; + } else { + lv_pushUDataRef(L, USERDATA_KEY_DELEGATE); + if ( key ) { + if ( lua_type(L, -1)==LUA_TTABLE ) { + lua_getfield(L, -1, key); + } else { + lua_pushnil(L); + } + } + return 1; + } + } + return 0; +} + +static int callback (lua_State *L) { + return lv_setCallbackByKey(L, NULL, YES); +} + +static int onLayout (lua_State *L) { + return lv_setCallbackByKey(L, STR_ON_LAYOUT, NO); +} + +static int onClick (lua_State *L) { + return lv_setCallbackByKey(L, STR_ON_CLICK, YES); +} + +static int onShow (lua_State *L) { + return lv_setCallbackByKey(L, STR_ON_SHOW, NO); +} + +static int onHide (lua_State *L) { + return lv_setCallbackByKey(L, STR_ON_HIDE, NO); +} + +static void removeOnTouchEventGesture(UIView* view){ + NSArray< UIGestureRecognizer *> * gestures = view.gestureRecognizers; + for( LVGesture* g in gestures ) { + if( [g isKindOfClass:[LVGesture class]] ) { + if( g.onTouchEventCallback ) { + [view removeGestureRecognizer:g]; + break; + } + } + } +} + +static int onTouch (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + int ret = lv_setCallbackByKey(L, STR_ON_TOUCH, NO); + if( user ){ + __weak UIView* view = (__bridge UIView *)(user->object); + removeOnTouchEventGesture(view); + + LVGesture* gesture = [[LVGesture alloc] init:L]; + gesture.onTouchEventCallback = ^(LVGesture* gesture, int argN){ + [view lv_callLuaCallback:@STR_ON_TOUCH key2:nil argN:1]; + }; + [view addGestureRecognizer:gesture]; + } + return ret; +} + +#pragma -mark __gc +static int __gc (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + releaseUserDataView(user); + return 0; +} + +static int __tostring (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + NSString* s = [NSString stringWithFormat:@"%@",view]; + lua_pushstring(L, s.UTF8String); + return 1; + } + } + return 0; +} + +- (void) layoutSubviews{ + [super layoutSubviews]; + [self lv_alignSubviews]; + [self lv_callLuaCallback:@STR_ON_LAYOUT]; +} + +static int releaseObject(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + //[LVUtil unregistry:L key:(__bridge id)user->view]; + UIView* view = (__bridge UIView *)(user->object); + [view removeFromSuperview]; + [view.layer removeFromSuperlayer]; + if( [view isKindOfClass:[LuaViewCore class]] ){ + LuaViewCore* lView = (LuaViewCore*)view; + lView.l = NULL; + G(L)->ud = NULL; + [lView releaseLuaView]; + } + } + return 0; +} +//--------------------------- +//static int __newindex (lua_State *L) { +// NSString* key = lv_paramString(L, 2); +// if( key ){ +// lv_getmetatable( L, 1 ); +// lua_getfield(L, -1, key.UTF8String); +// if( lua_type(L, -1)==LUA_TFUNCTION ) { +// lua_CFunction function = lua_tocfunction(L,-1); +// if( function ) { +// lua_remove(L, 2); +// lua_settop(L, 2); +// return function(L); +// } +// } +// } +// LVError(@"not found property: %@", key); +// return 0; +//} + + +static int align (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + int argNum = lua_gettop(L); + if ( argNum>=2 ) { + NSUInteger align = 0; + for (int i=2; i<=argNum; i++ ) { + align |= (NSUInteger)lua_tointeger(L, i); + } + view.lv_align = align; + [view lv_alignSelfWithSuperRect:view.superview.frame]; + return 0; + } else { + lua_pushnumber(L, view.lv_align ); + return 1; + } + } + } + return 0; +} + +static int alignInfo (lua_State *L, int align) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + view.lv_align = align; + [view lv_alignSelfWithSuperRect:view.superview.frame]; + } + } + return 0; +} + +static int alignLeft(lua_State *L ) { + return alignInfo(L, LV_ALIGN_LEFT); +} + +static int alignRight(lua_State *L ) { + return alignInfo(L, LV_ALIGN_RIGHT); +} + +static int alignTop(lua_State *L ) { + return alignInfo(L, LV_ALIGN_TOP); +} + +static int alignBottom(lua_State *L ) { + return alignInfo(L, LV_ALIGN_BOTTOM); +} + +static int alignCenter(lua_State *L ) { + return alignInfo(L, LV_ALIGN_H_CENTER|LV_ALIGN_V_CENTER); +} + +static int effects (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if ( [view isKindOfClass:[UIView class]] ) { + int effectType = lua_tonumber(L, 2); + switch (effectType) { + case EFFECT_NONE: + break; + case EFFECT_CLICK:{ + NSInteger color = lua_tonumber(L, 3); + CGFloat alpha = lua_tonumber(L, 4); + [view lv_effectClick:color alpha:alpha]; + break; + } + case EFFECT_PARALLAX:{ + CGFloat dx = lua_tonumber(L, 3); + CGFloat dy = lua_tonumber(L, 4); + [view lv_effectParallax:dx dy:dy]; + break; + } + default: + break; + } + } + } + return 0; +} + +static int invalidate (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if ( [view isKindOfClass:[UIView class]] ) { + [view setNeedsDisplay]; + } + } + return 0; +} + +static const struct luaL_Reg baseMemberFunctions [] = { + {"hidden", hidden }, + {"visible", visible }, + + {"hide", hide },//__deprecated_msg("Use hidden") + {"isHide", isHide },//__deprecated_msg("Use hidden") + + {"show", show },//__deprecated_msg("Use visible") + {"isShow", isShow },//__deprecated_msg("Use visible") + + {"enabled", userInteractionEnabled }, + {"clipsToBounds", clipsToBounds },// for IOS + + {"backgroundColor", backgroundColor }, + + {"alpha", alpha }, + + {"cornerRadius", cornerRadius }, + + {"borderWidth", borderWidth }, + + {"borderColor", borderColor }, + {"borderDash", borderDash }, + + {"shadowPath", setShadowPath }, // for IOS + {"masksToBounds", setMasksToBounds },// for IOS + {"shadowOffset", setShadowOffset },// for IOS + {"shadowRadius", setShadowRadius },// for IOS + {"shadowOpacity", setShadowOpacity },// for IOS + {"shadowColor", setShadowColor },// for IOS + + {"frame", frame }, + + {"size", size }, + + {"origin", origin },//__deprecated_msg("Use xy") + {"xy", origin }, + + {"center", center}, + {"centerX", centerX}, + {"centerY", centerY}, + + {"x", x}, + {"y", y}, + + {"left", x}, + {"top", y}, + {"bottom", bottom}, + {"right", right}, + + {"width", width}, + {"height", height}, + + {"adjustSize", adjustSize},// 带讨论 + + {"addGesture", addGestureRecognizer }, //__deprecated_msg("Use onTouch") + {"removeGesture", removeGestureRecognizer }, //__deprecated_msg("Use onTouch") + + {"addView", addSubview }, + {"children", children }, + {"removeFromSuper", removeFromSuperview }, + {"removeFromParent", removeFromSuperview }, //__deprecated_msg("Use removeFromSuper") + {"removeAllViews", removeAllSubviews }, + + {"bringToFront", bringToFront}, + {"sendToBack", bringToBack}, + + {"rotation", rotationZ }, + {"rotationX", rotationX }, + {"rotationY", rotationY }, + {"rotationZ", rotationZ },//__deprecated_msg("Use rotation") + + {"scale", scale }, + {"scaleX", scaleX }, + {"scaleY", scaleY }, + + {"translation", translation }, + {"translationX", translationX }, + {"translationY", translationY }, + + {"anchorPoint", anchorPoint }, + + {"callback", callback }, + {"onLayout", onLayout }, + {"onClick", onClick }, + {"onTouch", onTouch }, + {"onShow", onShow }, + {"onHide", onHide }, + + // onLongClick + + {"hasFocus", isFirstResponder }, + {"requestFocus", becomeFirstResponder }, + {"cancelFocus", resignFirstResponder }, //__deprecated_msg("Use hidden") + {"clearFocus", resignFirstResponder }, + + {"transform3D", transform3D }, //__deprecated_msg("Use") + {"matrix", matrix }, + + {"startAnimation", startAnimation }, + {"stopAnimation", stopAnimation }, + + + {"__gc", __gc }, + + {"__tostring", __tostring}, + + // {"__newindex", __newindex }, + + {"flexChildren", flxChildViews }, + {"flxLayout", flxLayout },// 安卓无 + {"flexCss", flxBindingInlineCSS}, + + // align + {"align", align}, + {"alignLeft", alignLeft}, + {"alignRight", alignRight}, + {"alignTop", alignTop}, + {"alignBottom", alignBottom}, + {"alignCenter", alignCenter}, + // padding + // margin + + {"getNativeView", getNativeView}, //__deprecated_msg("Use nativeView") + {"nativeView", getNativeView}, + + {"effects",effects}, // IOS 视差效果 + {"layerMode",layerMode}, // for IOS + + {"invalidate",invalidate}, + {NULL, NULL} +}; + +static const struct luaL_Reg luaViewMemberFunctions [] = { + {"release", releaseObject}, + {NULL, NULL }, +}; + ++(const luaL_Reg*) baseMemberFunctions{ + return baseMemberFunctions; +} + +#pragma -mark UIView +static int lvNewView (lua_State *L) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVBaseView class]]; + + LVBaseView* view = [[c alloc] init:L]; + { + NEW_USERDATA(userData, View); + userData->object = CFBridgingRetain(view); + view.lv_userData = userData; + + luaL_getmetatable(L, META_TABLE_UIView ); + lua_setmetatable(L, -2); + + LuaViewCore* luaviewCore = LV_LUASTATE_VIEW(L); + if( luaviewCore ){ + [luaviewCore containerAddSubview:view]; + } + } + return 1; /* new userdatum is already on the stack */ +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewView globalName:globalName defaultName:@"View"]; + + lv_createClassMetaTable(L, META_TABLE_UIView); + + luaL_openlib(L, NULL, [LVBaseView baseMemberFunctions], 0); + + + lv_createClassMetaTable(L, META_TABLE_LuaView); + luaL_openlib(L, NULL, [LVBaseView baseMemberFunctions], 0); + luaL_openlib(L, NULL, luaViewMemberFunctions, 0); + return 1; +} + +//---------------------------------------------------------------------------------------- + +-(NSString*) description{ + return [NSString stringWithFormat:@"", (int)[self hash], NSStringFromCGRect(self.frame) ]; +} + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVBitmap.h b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVBitmap.h new file mode 100644 index 00000000..2497f050 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVBitmap.h @@ -0,0 +1,33 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" +#import "LView.h" + + +typedef void(^LVWebBitmapCompletionBlock)(UIImage *image, NSError *error, int cacheType, NSURL *imageURL); + + +@interface LVBitmap : NSObject + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; + +@property (nonatomic,strong) UIImage* nativeImage;// Bitmap实体对象 + +-(id) init:(lua_State*) l; + +-(void) loadBitmapByUrl:(NSString*) url finished:(LVWebBitmapCompletionBlock) finished; + +/* + * luaview所有扩展类的桥接协议: 只是一个静态协议, luaview统一调用该接口加载luaview扩展的类 + */ ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVBitmap.m b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVBitmap.m new file mode 100644 index 00000000..f4afda32 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVBitmap.m @@ -0,0 +1,215 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVBitmap.h" +#import "LVBaseView.h" +#import "LVUtil.h" +#import "LVData.h" +#import +#import "LVHeads.h" + +@interface LVBitmap () +@property (nonatomic,strong) id functionTag; +@property (nonatomic,assign) BOOL needCallLuaFunc; +@property (nonatomic,strong) id errorInfo; + +@end + +@implementation LVBitmap + + +-(id) init:(lua_State*) l{ + self = [super init]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + self.functionTag = [[NSMutableString alloc] init]; + } + return self; +} + +//加载完成回调 +-(void) callLuaWhenLoadCompleted:(id) obj{ + lua_State* L = self.lv_luaviewCore.l; + if( L ) { + lua_checkstack(L, 4); + lua_pushboolean(L, obj?0:1); + [LVUtil pushRegistryValue:L key:self.functionTag]; + lv_runFunctionWithArgs(L, 1, 0); + } + [LVUtil unregistry:L key:self.functionTag]; +} + +// 图片裁剪回调 +-(void) callLuaSpriteCompleted:(id) obj{ + lua_State* L = self.lv_luaviewCore.l; + if( L ) { + lua_checkstack(L, 4); + lv_pushUserdata(L, self.lv_userData); + [LVUtil pushRegistryValue:L key:self.functionTag]; + lv_runFunctionWithArgs(L, 1, 0); + } + [LVUtil unregistry:L key:self.functionTag]; +} + +// 加载 +-(void) loadBitmapByUrl:(NSString*) url finished:(LVWebBitmapCompletionBlock) finished{ + [LVUtil download:url callback:^(NSData *data) { + UIImage* image = [UIImage imageWithData:data]; + NSString* error = (data?nil:@"download error"); + NSError* err = nil; + if( error ) { + err = [NSError errorWithDomain:error code:0 userInfo:nil]; + } + if( finished ) { + finished(image, err, 0, [NSURL URLWithString:url] ); + } + }]; +} + +// 设置Bitmap url +-(void) setBitmapUrl:(NSString*) url{ + if( url==nil ) + return; + + if( [LVUtil isExternalUrl:url] ){ + __weak LVBitmap* weakBitmap = self; + [self loadBitmapByUrl:url finished:^(UIImage *image, NSError *error, int cacheType, NSURL *imageURL) { + + weakBitmap.nativeImage = image; + + if( weakBitmap.needCallLuaFunc ) { + weakBitmap.errorInfo = error; + [weakBitmap performSelectorOnMainThread:@selector(callLuaWhenLoadCompleted:) withObject:error waitUntilDone:NO]; + } + }]; + } else { + // local Image + NSData* data = [self.lv_luaviewCore.bundle resourceWithName:url]; + self.nativeImage = [[UIImage alloc] initWithData:data]; + } +} + +// 图片切割 +-(UIImage*) sprite:(CGFloat)x y:(CGFloat)y w:(CGFloat)w h:(CGFloat) h{ + return [LVUtil image:self.nativeImage croppingToRect:CGRectMake(x, y, w, h)]; +} + +-(void) dealloc{ + LVUserDataInfo* userData = self.lv_userData; + if( userData ){ + userData->object = NULL; + } +} + +#pragma -mark ImageView +/* + * lua脚本中 local bitmap = Bitmap() 对应的构造方法 + */ +static int lvNewBitmap(lua_State *L) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVBitmap class]]; + + NSString* url = lv_paramString(L, 1);// url + + LVBitmap* bitmap = [[c alloc] init:L]; + + if( lua_type(L, 2) == LUA_TFUNCTION ) { + [LVUtil registryValue:L key:bitmap.functionTag stack:2];// 图片加载完成回调 + bitmap.needCallLuaFunc = YES; + } else { + bitmap.needCallLuaFunc = NO; + } + + [bitmap setBitmapUrl:url]; + { + NEW_USERDATA(userData, Bitmap); + userData->object = CFBridgingRetain(bitmap); + bitmap.lv_userData = userData; + + luaL_getmetatable(L, META_TABLE_Bitmap ); + lua_setmetatable(L, -2); + } + return 1; /* new userdatum is already on the stack */ +} + +// Lua的Bitmap对象size接口对应的native实现 +static int size (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1);// 获取第一个参数(self,lua的userdata, 对象自身) + if( user ){ + LVBitmap* view = (__bridge LVBitmap *)(user->object); + if( view ){ + CGSize size = view.nativeImage.size;// 获取native size + lua_pushnumber(L, size.width );//参数压栈 + lua_pushnumber(L, size.height );//参数压栈 + return 2;// 返回两个参数 + } + } + return 0; +} + +// 切图接口 +static int sprite (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1);// 获取第一个参数(self,lua的userdata, 对象自身) + if( user && lua_gettop(L)>=5 ){ + // 获取lua传送过来的参数 + CGFloat x = lua_tonumber(L, 2); + CGFloat y = lua_tonumber(L, 3); + CGFloat w = lua_tonumber(L, 4); + CGFloat h = lua_tonumber(L, 5); + + + LVBitmap* view = (__bridge LVBitmap *)(user->object); + if( view ){ + // 创建新的bitmap对象(Native实例) + LVBitmap* bitmap = [[LVBitmap alloc] init:L]; + { + // 创建新的Bitmap对象(lua实例) + NEW_USERDATA(userData, Bitmap); + userData->object = CFBridgingRetain(bitmap); + bitmap.lv_userData = userData; + + luaL_getmetatable(L, META_TABLE_Bitmap ); + lua_setmetatable(L, -2); + + if( lua_type(L, 6) == LUA_TFUNCTION ) { + [LVUtil registryValue:L key:bitmap.functionTag stack:6]; + } + } + // 调用native图片切割对象 + bitmap.nativeImage = [view sprite:x y:y w:w h:h]; + // 出发回调 + [bitmap performSelectorOnMainThread:@selector(callLuaSpriteCompleted:) withObject:nil waitUntilDone:NO]; + return 1; + } + } + return 0; +} + +/* + * luaview所有扩展类的桥接协议: 只是一个静态协议, luaview统一调用该接口加载luaview扩展的类 + */ ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + + // 注册构造方法: "Bitmap" 对应的C函数(lvNewBitmap) + 对应的类Class(self/LVBitmap) + [LVUtil reg:L clas:self cfunc:lvNewBitmap globalName:globalName defaultName:@"Bitmap"]; + + // lua中Bitmap对象对应的方法列表 + const struct luaL_Reg memberFunctions [] = { + {"size", size}, + {"sprite", sprite}, + {NULL, NULL} + }; + + // 创建Label类的方法列表 + lv_createClassMetaTable(L, META_TABLE_Bitmap); + // 注册类方法列表 + luaL_openlib(L, NULL, memberFunctions, 0); + return 1; +} + + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVButton.h b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVButton.h new file mode 100644 index 00000000..dc4c222a --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVButton.h @@ -0,0 +1,36 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" +#import "LView.h" + + +/* + * luaview虚拟机注册的组件标准: 需要满足两个协议 LVProtocal(功能协议), LVClassProtocal(注册协议) + * + * + */ +@interface LVButton : UIButton + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; +@property(nonatomic,assign) NSUInteger lv_align; +@property(nonatomic,strong) CAShapeLayer* lv_shapeLayer; + +-(id) init:(lua_State*) l; +-(void) setWebImageUrl:(NSString*)url forState:(UIControlState) state finished:(LVLoadFinished) finished; + +-(void) lvButtonCallBack; + +/* + * luaview所有扩展类的桥接协议: 只是一个静态协议, luaview统一调用该接口加载luaview扩展的类 + */ ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVButton.m b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVButton.m new file mode 100644 index 00000000..d8ede291 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVButton.m @@ -0,0 +1,295 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVButton.h" +#import "LVBaseView.h" +#import "LVImage.h" +#import "LVUtil.h" +#import "LView.h" +#import "LVStyledString.h" +#import "UIView+LuaView.h" +#import "NSObject+LuaView.h" +#import "LVHeads.h" + +@interface LVButton() +@end + +@implementation LVButton + +-(id) init:(lua_State*) l{ + self = [super init]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + [self addTarget:self action:@selector(lvButtonCallBack) forControlEvents:UIControlEventTouchUpInside]; + + // 默认黑色字 + [self setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; + self.clipsToBounds = YES; + self.titleLabel.font = [UIFont systemFontOfSize:14];// 默认字体大小 + } + return self; +} + +-(void) dealloc{ +} + +-(NSString*) description{ + return [NSString stringWithFormat:@"", (int)[self hash], NSStringFromCGRect(self.frame) ]; +} + +-(void) lvButtonCallBack{ + [self lv_buttonCallBack]; +} + +-(void) setWebImageUrl:(NSString*)url forState:(UIControlState) state finished:(LVLoadFinished) finished{ +} + +-(void) setImageUrl:(NSString*) url placeholder:(UIImage *)placeholder state:(UIControlState) state { + if( [LVUtil isExternalUrl:url] ){ + [self setWebImageUrl:url forState:state finished:nil]; + } else { + if( url ) { + LVBundle* bundle = self.lv_luaviewCore.bundle; + [self setImage:[bundle imageWithName:url] forState:state]; + } + } +} + +#pragma -mark Button +static int lvNewButton (lua_State *L) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVButton class]]; + + { + LVButton* button = [[c alloc] init:L]; + { + NEW_USERDATA(userData, View); + userData->object = CFBridgingRetain(button); + button.lv_userData = userData; + + luaL_getmetatable(L, META_TABLE_UIButton ); + lua_setmetatable(L, -2); + } + LuaViewCore* father = LV_LUASTATE_VIEW(L); + if( father ){ + [father containerAddSubview:button]; + } + } + return 1; /* new userdatum is already on the stack */ +} + +static int selected (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVButton* button = (__bridge LVButton *)(user->object); + if( button ){ + if ( lua_gettop(L)>=2 ) { + BOOL yes = lua_toboolean(L, 2); + button.selected = yes; + return 0; + } else { + lua_pushboolean(L, button.selected ); + return 1; + } + } + } + return 0; +} + +static int enabled (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVButton* button = (__bridge LVButton *)(user->object); + if ( lua_gettop(L)>=2 ){ + BOOL yes = lua_toboolean(L, 2); + button.enabled = yes; + return 0; + } else { + lua_pushboolean(L, button.enabled); + return 1; + } + } + return 0; +} + +static int image (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + NSString* normalImage = lv_paramString(L, 2);// 2 + NSString* hightLightImage = lv_paramString(L, 3);// 2 + //NSString* disableImage = lv_paramString(L, 4);// 2 + //NSString* selectedImage = lv_paramString(L, 5);// 2 + LVButton* button = (__bridge LVButton *)(user->object); + if( [button isKindOfClass:[LVButton class]] ){ + [button setImageUrl:normalImage placeholder:nil state:UIControlStateNormal]; + [button setImageUrl:hightLightImage placeholder:nil state:UIControlStateHighlighted]; + //[button setImageUrl:disableImage placeholder:nil state:UIControlStateDisabled]; + //[button setImageUrl:selectedImage placeholder:nil state:UIControlStateSelected]; + + lua_pushvalue(L, 1); + return 1; + } + } + return 0; +} + +static const UIControlState g_states[] = {UIControlStateNormal,UIControlStateHighlighted,UIControlStateDisabled,UIControlStateSelected}; +static int title (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVButton* button = (__bridge LVButton *)(user->object); + if( [button isKindOfClass:[LVButton class]] ){ + int num = lua_gettop(L); + if ( num>=2 ) {// setValue + for (int i=2,j=0; i<=num && j<4; i++ ){ + if ( lua_type(L, i) == LUA_TSTRING ) { + NSString* text1 = lv_paramString(L, i); + if( text1 ) { + [button setTitle:text1 forState:g_states[j++]]; + } + } else if( lua_type(L, 2)==LUA_TUSERDATA ){ + LVUserDataInfo * user2 = lua_touserdata(L, 2); + if( user2 && LVIsType(user2, StyledString) ) { + LVStyledString* attString = (__bridge LVStyledString *)(user2->object); + [button setAttributedTitle:attString.mutableStyledString forState:g_states[j++] ]; + [button.titleLabel sizeToFit]; + } + }else if ( lua_type(L, i) == LUA_TNUMBER ) { + float f = lua_tonumber(L, i); + [button setTitle:[NSString stringWithFormat:@"%f",f] forState:g_states[j++]]; + } + } + return 0; + } else { // getValue + for (int j=0; j<4; j++ ){ + NSString* text1 = [button titleForState:g_states[j] ]; + lua_pushstring(L, text1.UTF8String); + } + return 4; + } + } + } + return 0; +} + +static int titleColor (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVButton* button = (__bridge LVButton *)(user->object); + if( [button isKindOfClass:[LVButton class]] ){ + int num = lua_gettop(L); + if ( num>=2 ) { + for (int i=2,j=0; i<=num && j<4; i++ ){ + if( lua_type(L, i)==LUA_TNUMBER ) { + UIColor* c = lv_getColorFromStack(L, i); + [button setTitleColor:c forState:g_states[j++]]; + } + } + return 0; + } else { + int retvalueNum = 0; + for (int j=0; j<4; j++ ){ + UIColor* c = [button titleColorForState:g_states[j++] ]; + NSUInteger color=0 ; + CGFloat a = 0; + if( lv_uicolor2int(c, &color, &a) ){ + lua_pushnumber(L, color); + lua_pushnumber(L, a); + retvalueNum += 2; + } + } + return retvalueNum; + } + } + } + return 0; +} + +static int font (lua_State *L) { + LuaViewCore* luaView = LV_LUASTATE_VIEW(L); + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVButton* view = (__bridge LVButton *)(user->object); + if( [view isKindOfClass:[LVButton class]] ){ + int num = lua_gettop(L); + if( num>=2 ) { + if( num>=3 && lua_type(L, 2)==LUA_TSTRING ) { + NSString* fontName = lv_paramString(L, 2); + float fontSize = lua_tonumber(L, 3); + view.titleLabel.font = [LVUtil fontWithName:fontName size:fontSize bundle:luaView.bundle]; + } else { + float fontSize = lua_tonumber(L, 2); + view.titleLabel.font = [UIFont systemFontOfSize:fontSize]; + } + return 0; + } else { + UIFont* font = view.titleLabel.font; + lua_pushstring(L, font.fontName.UTF8String); + lua_pushnumber(L, font.pointSize); + return 2; + } + } + } + return 0; +} + +static int fontSize (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVButton* view = (__bridge LVButton *)(user->object); + if( [view isKindOfClass:[LVButton class]] ){ + int num = lua_gettop(L); + if( num>=2 ) { + float fontSize = lua_tonumber(L, 2); + view.titleLabel.font = [UIFont systemFontOfSize:fontSize]; + return 0; + } else { + UIFont* font = view.titleLabel.font; + lua_pushnumber(L, font.pointSize); + return 1; + } + } + } + return 0; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewButton globalName:globalName defaultName:@"Button"]; + + const struct luaL_Reg memberFunctions [] = { + {"image", image}, + + {"font", font}, + {"fontSize", fontSize}, + {"textSize", fontSize}, // __deprecated_msg("Use lines") + + + {"titleColor", titleColor}, // __deprecated_msg("Use lines") + {"title", title}, // __deprecated_msg("Use lines") + {"textColor", titleColor}, + {"text", title}, + + {"selected", selected}, // __deprecated_msg("Use lines") + {"enabled", enabled}, // __deprecated_msg("Use lines") + {NULL, NULL} + }; + + lv_createClassMetaTable(L,META_TABLE_UIButton); + + luaL_openlib(L, NULL, [LVBaseView baseMemberFunctions], 0); + luaL_openlib(L, NULL, memberFunctions, 0); + + const char* keys[] = { "addView", NULL};// 移除多余API + lv_luaTableRemoveKeys(L, keys ); + + return 1; +} + + +//---------------------------------------------------------------------------------------- + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCamera.h b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCamera.h new file mode 100644 index 00000000..1efcf13e --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCamera.h @@ -0,0 +1,25 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" +#import "LView.h" + + +/* + * luaview虚拟机注册的组件标准: 需要满足两个协议 LVProtocal(功能协议), LVClassProtocal(注册协议) + * + * + */ + +@interface LVCamera : UIView + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCamera.m b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCamera.m new file mode 100644 index 00000000..f9ce6cdd --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCamera.m @@ -0,0 +1,415 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVCamera.h" +#import "LVBaseView.h" +#import +#import + +#define LVCAMERA_ONFACEDETECTED @"onFaceDetected" +#define LVCAMERA_ONPICTURETAKEN @"onPictureTaken" + +@interface LVCamera() + +@property (nonatomic, retain) NSConditionLock *pictureTakingLock; + +//摄像头视频层 +@property (nonatomic, strong) AVCaptureSession *session; +@property (nonatomic, strong) AVCaptureDeviceInput *inputDevice; +@property (nonatomic, strong) AVCaptureStillImageOutput *imageOutput; +//@property (nonatomic, strong) AVCaptureVideoDataOutput *captureOutput; +@property (nonatomic, strong) AVCaptureMetadataOutput *metaDataOutput; +@property (nonatomic, strong) AVCaptureVideoPreviewLayer *previewLayer; + +#ifdef DEBUG +@property (nonatomic, strong) CAShapeLayer *debugLayer; +#endif + +@end + +@implementation LVCamera + +#pragma mark - init and dealloc +-(instancetype) init:(lua_State*) l{ + self = [super init]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + self.pictureTakingLock = [[NSConditionLock alloc] init]; + [self createPreviewLayer]; + [self createDebugLayer]; + } + return self; +} + +-(void)dealloc{ + [self enableFlash:NO]; + releaseUserDataCamera(self.lv_userData); +} + +-(BOOL)createPreviewLayer{ + self.session = [[AVCaptureSession alloc] init]; + AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; + //更改这个设置的时候必须先锁定设备,修改完后再解锁,否则崩溃 + [device lockForConfiguration:nil]; + //初始化时关闭闪光灯 + [device setFlashMode:AVCaptureFlashModeOff]; + //设置持续性自动对焦 + if ([device isFocusModeSupported:AVCaptureFocusModeAutoFocus]){ + device.focusMode = AVCaptureFocusModeContinuousAutoFocus; + } + + [device unlockForConfiguration]; + + NSError *error = nil; + + self.inputDevice = [[AVCaptureDeviceInput alloc] initWithDevice:device error:&error]; + + if (error){ + return NO; + } + + if ([self.session canAddInput:self.inputDevice]) { + [self.session addInput:self.inputDevice]; + } + + self.imageOutput = [[AVCaptureStillImageOutput alloc] init]; + + //输出设置。AVVideoCodecJPEG 输出jpeg格式图片 + NSDictionary * outputSettings = [[NSDictionary alloc] initWithObjectsAndKeys:AVVideoCodecJPEG,AVVideoCodecKey, nil]; + [self.imageOutput setOutputSettings:outputSettings]; + + if ([self.session canAddOutput:self.imageOutput]) { + [self.session addOutput:self.imageOutput]; + } + + [self enableFaceDetect:YES]; + + self.previewLayer = [AVCaptureVideoPreviewLayer layerWithSession:self.session]; + self.previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill; + + [self.layer addSublayer:self.previewLayer]; + + return YES; +} + +-(void)createDebugLayer{ +#ifdef DEBUG + self.debugLayer = [[CAShapeLayer alloc] init]; + self.debugLayer.strokeColor = [UIColor redColor].CGColor; + self.debugLayer.fillColor = [UIColor clearColor].CGColor; + [self.layer addSublayer:self.debugLayer]; +#endif +} + +-(void)layoutSubviews{ + [super layoutSubviews]; + + self.previewLayer.frame = self.bounds; +} + +-(void)didMoveToWindow{ + [super didMoveToWindow]; + + if (self.window){ + [self.session startRunning]; + } +} + +-(void)willMoveToWindow:(UIWindow*)window{ + [super willMoveToWindow:window]; + + if (!window){ + [self.session stopRunning]; + } +} + +#pragma mark - flash control +-(void)enableFlash:(BOOL)flash{ + AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; + + if (!device.isFlashAvailable){ + return; + } + + if (device.position == AVCaptureDevicePositionBack){ + [device lockForConfiguration:nil]; + if (flash){ + device.flashMode = AVCaptureFlashModeOn; + }else{ + device.flashMode = AVCaptureFlashModeOff; + } + + [device unlockForConfiguration]; + } +} + +#pragma mark - queues +-(dispatch_queue_t)sessionQueue{ + static dispatch_once_t onceToken; + static dispatch_queue_t sessionQueue; + dispatch_once(&onceToken, ^{ + sessionQueue = dispatch_queue_create("com.luaviewsdk.VideoCaptureSessionQueue", DISPATCH_QUEUE_SERIAL); + }); + + return sessionQueue; +} + +#pragma mark - face detection +-(void)enableFaceDetect:(BOOL)enable{ + if (enable){ + if (self.metaDataOutput){ + [self.session removeOutput:self.metaDataOutput]; + } + + self.metaDataOutput = [[AVCaptureMetadataOutput alloc] init]; + [self.metaDataOutput setMetadataObjectsDelegate:self queue:[self sessionQueue]]; + + if ([self.session canAddOutput:self.metaDataOutput]){ + [self.session addOutput:self.metaDataOutput]; + } + + if ([self.metaDataOutput.availableMetadataObjectTypes containsObject:AVMetadataObjectTypeFace]){ + self.metaDataOutput.metadataObjectTypes = @[AVMetadataObjectTypeFace]; + } + + }else{ + if (self.metaDataOutput){ + [self.session removeOutput:self.metaDataOutput]; + self.metaDataOutput = nil; + } + } +} + +- (void)captureOutput:(AVCaptureOutput *)output didOutputMetadataObjects:(NSArray<__kindof AVMetadataObject *> *)metadataObjects fromConnection:(AVCaptureConnection *)connection{ +#ifdef DEBUG + dispatch_async(dispatch_get_main_queue(), ^{ + CGMutablePathRef path = CGPathCreateMutable(); +#endif + for (AVMetadataObject *metadata in metadataObjects){ + if ([metadata.type isEqualToString:AVMetadataObjectTypeFace]){ + CGRect face = [self.previewLayer rectForMetadataOutputRectOfInterest:metadata.bounds]; + dispatch_async(dispatch_get_main_queue(), ^{ + [self onFaceDetected:face]; + }); +#ifdef DEBUG + CGPathAddRect(path, NULL, face); +#endif + } + } +#ifdef DEBUG + self.debugLayer.path = path; + [self.debugLayer setNeedsDisplay]; + CGPathRelease(path); + }); +#endif +} + +-(void)drawFaceBoundInDebugLayer:(CGRect)bounds{ +#ifdef DEBUG + dispatch_async(dispatch_get_main_queue(), ^{ + CGPathRef path = CGPathCreateWithRect(bounds, NULL); + self.debugLayer.path = path; + [self.debugLayer setNeedsDisplay]; + CGPathRelease(path); + }); +#endif +} + +#pragma mark - taking picture +-(void)startTakingPicture:(BOOL)flash{ + if ([self.pictureTakingLock tryLock]){ + + [self enableFlash:YES]; + + AVCaptureConnection *imageConnection = [self.imageOutput connectionWithMediaType:AVMediaTypeVideo]; + UIDeviceOrientation curDeviceOrientation = [[UIDevice currentDevice] orientation]; + AVCaptureVideoOrientation avcaptureOrientation = (AVCaptureVideoOrientation)curDeviceOrientation; + + [imageConnection setVideoOrientation:avcaptureOrientation]; + [imageConnection setVideoScaleAndCropFactor:1]; + + __block typeof (self) wself = self; + [self.imageOutput captureStillImageAsynchronouslyFromConnection:imageConnection + completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) { + [wself enableFlash:NO]; + if (!error){ + NSData *jpegData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer]; + //回调图片 + [wself onPictureTaken:jpegData]; + } + + [wself.pictureTakingLock unlock]; + }]; + } +} + +#pragma mark - 回调 +-(void)onFaceDetected:(CGRect)bounds{ + lua_State* L = self.lv_luaviewCore.l; + if( L ) { + lua_checkstack32(L); + //第一个参数:x + lua_pushnumber(L, bounds.origin.x); + //第二个参数:y + lua_pushnumber(L, bounds.origin.y); + //第三个参数:宽 + lua_pushnumber(L, bounds.size.width); + //第四个参数:高 + lua_pushnumber(L, bounds.size.height); + + [self lv_callLuaCallback:LVCAMERA_ONFACEDETECTED key2:nil argN:4]; + } +} + +-(void)onPictureTaken:(NSData*)imageData{ + lua_State* L = self.lv_luaviewCore.l; + if( L ) { + lua_checkstack32(L); + if (imageData){ + //保存到本地文件再传给脚本层, 路径为temp/LVCamera + NSString *path = NSTemporaryDirectory(); + //获取当前毫秒数 + NSString *filename = [path stringByAppendingFormat:@"%.0f.jpg", (double)CFAbsoluteTimeGetCurrent()]; + + NSError *error = nil; + [imageData writeToFile:filename options:NSDataWritingAtomic error:&error]; + + UIImage *image = [UIImage imageWithData:imageData]; + + lua_pushstring(L, filename.UTF8String); + lua_pushnumber(L, image.size.width); + lua_pushnumber(L, image.size.height); + }else{ + lua_pushstring(L, ""); + lua_pushnumber(L, 0); + lua_pushnumber(L, 0); + } + + [self lv_callLuaCallback:LVCAMERA_ONPICTURETAKEN key2:nil argN:3]; + } +} + +#pragma mark - LuaViewSDK register methods + +static int lvNewCameraView (lua_State *L){ + Class c = [LVUtil upvalueClass:L defaultClass:[LVCamera class]]; + + LVCamera* camera = [[c alloc] init:L]; + + NEW_USERDATA(userData, View); + userData->object = CFBridgingRetain(camera); + camera.lv_userData = userData; + + luaL_getmetatable(L, META_TABLE_Camera); + lua_setmetatable(L, -2); + + LuaViewCore* father = LV_LUASTATE_VIEW(L); + if( father ){ + [father containerAddSubview:camera]; + } + + return 1; /* new userdatum is already on the stack */ +} + +static int lvHasPermission(lua_State *L){ + AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]; + if (authStatus == AVAuthorizationStatusRestricted || authStatus ==AVAuthorizationStatusDenied) + { + //无权限返回 + lua_pushboolean(L, 0); + } else { + lua_pushboolean(L, 1); + } + + return 1; +} + +static int lvEnableFaceDetect(lua_State *L){ + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVCamera* camera = (__bridge LVCamera *)(user->object); + if ( lua_gettop(L)>=2 ){ + BOOL enable = lua_toboolean(L, 2); + [camera enableFaceDetect:enable]; + return 0; + } + } + return 0; +} + +static int lvTakePicture(lua_State *L){ + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVCamera* camera = (__bridge LVCamera *)(user->object); + + BOOL flash = NO; + + if ( lua_gettop(L)>=2 ){ + flash = lua_toboolean(L, 2); + return 0; + } + + [camera startTakingPicture:flash]; + } + return 0; +} + +static int __gc(lua_State *L){ + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + releaseUserDataCamera(user); + + return 0; +} + +static int __tostring(lua_State *L){ + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVCamera* camera = (__bridge LVCamera *)(user->object); + NSString* s = [NSString stringWithFormat:@"LVUserDataCamera: %@", camera ]; + lua_pushstring(L, s.UTF8String); + return 1; + } + return 0; +} + +static void releaseUserDataCamera(LVUserDataInfo* user){ + if( user && user->object ){ + LVCamera* camera = CFBridgingRelease(user->object); + user->object = NULL; + if( camera ){ + camera.lv_userData = NULL; + camera.lv_luaviewCore = nil; + } + } +} + +// lua脚本层对应的库和类名 ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + + lv_defineGlobalFunc("CameraViewPermission", lvHasPermission, L); + + [LVUtil reg:L clas:self cfunc:lvNewCameraView globalName:globalName defaultName:@"CameraView"]; + + //方法列表 + const struct luaL_Reg memberFunctions [] = { + {"enableFaceDetect", lvEnableFaceDetect}, + {"takePicture", lvTakePicture}, + {"__gc", __gc }, + {"__tostring", __tostring }, + {NULL, NULL} + }; + + lv_createClassMetaTable(L,META_TABLE_Camera); + + luaL_openlib(L, NULL, [LVBaseView baseMemberFunctions], 0); + luaL_openlib(L, NULL, memberFunctions, 0); + + return 1; +} + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCanvas.h b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCanvas.h new file mode 100644 index 00000000..7a324e3d --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCanvas.h @@ -0,0 +1,28 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import +#import "LVHeads.h" + +@interface LVCanvas : NSObject + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; + +@property(nonatomic,assign) CGContextRef contentRef; + +@property(nonatomic,assign) CGPathDrawingMode drawingMode; + +-(id) init:(lua_State*) l; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + ++(LVCanvas*) createLuaCanvas:(lua_State *)L contentRef:(CGContextRef) contentRef; + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCanvas.m b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCanvas.m new file mode 100644 index 00000000..ea665289 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCanvas.m @@ -0,0 +1,737 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVCanvas.h" +#import "LView.h" +#import "LVBundle.h" +#import "LVData.h" +#import "LVImage.h" +#import "LVBitmap.h" + +#define LV_ANGLE_RADIANS(angle) (M_PI*angle/180) + +@interface LVCanvas () +@property(nonatomic,strong) UIColor* color; +@property(nonatomic,assign) CGFloat strokeWidth; +@property(nonatomic,assign) CGFloat alpha; +@property(nonatomic,assign) UIFont* font; +@property(nonatomic,assign) CGAffineTransform concatCTM; +@property(nonatomic,assign) CGFloat scaleX; +@property(nonatomic,assign) CGFloat scaleY; +@property(nonatomic,assign) CGFloat skewX; +@property(nonatomic,assign) CGFloat skewY; +@property(nonatomic,assign) CGPoint translate; +@end + +@implementation LVCanvas + + +-(id) init:(lua_State *)l{ + self = [super init]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + } + return self; +} + +-(void) setContentRef:(CGContextRef)contentRef{ + _contentRef = contentRef; + [self resetPaint]; +} + +-(id) lv_nativeObject{ + return self; +} + +-(void) setColor:(UIColor *)color{ + _color = color; + if( _contentRef ) { + CGContextSetStrokeColorWithColor(_contentRef,self.color.CGColor); + CGContextSetFillColorWithColor(_contentRef,self.color.CGColor); + } +} + +-(void) setAlpha:(CGFloat)alpha{ + _alpha = alpha; + if (_contentRef) { +// CGFloat r = 0; +// CGFloat g = 0; +// CGFloat b = 0; +// CGFloat a = 0; +// if( [_color getRed:&r green:&g blue:&b alpha:&a] ){ +// CGContextSetRGBStrokeColor(_contentRef, r, g, b, _alpha); +// CGContextSetRGBFillColor(_contentRef, r, g, b, _alpha); +// } + // 控制左右的绘图alpha + CGContextSetAlpha(_contentRef,alpha); + } +} + +static int nativeObj (lua_State *L) { + LVUserDataInfo * userData = (LVUserDataInfo *)lua_touserdata(L, 1); + if( userData ){ + LVCanvas* view = (__bridge LVCanvas *)(userData->object); + if( view ){ + id object = [view lv_nativeObject]; + lv_pushNativeObjectWithBox(L, object); + return 1; + } + } + return 0; +} + +static int canvas_drawPoint (lua_State *L) { + LVUserDataInfo * user1 = (LVUserDataInfo *)lua_touserdata(L, 1); + LVCanvas* canvas = (__bridge LVCanvas *)(user1->object); + if( LVIsType(user1, Canvas) ){ + CGFloat x1 = lua_tonumber(L, 2); + CGFloat y1 = lua_tonumber(L, 3); + [canvas drawLine:x1-0.5 :y1-0.5 :x1+0.5 :y1+0.5]; + return 1; + } + return 0; +} + +-(void) drawLine:(CGFloat) x1 :(CGFloat)y1 :(CGFloat) x2 :(CGFloat) y2{ + if( _contentRef ) { + CGPoint aPoints[2]; + aPoints[0] = CGPointMake(x1, y1); + aPoints[1] = CGPointMake(x2, y2); + CGContextAddLines(_contentRef, aPoints, 2); + CGContextDrawPath(_contentRef, kCGPathStroke); //根据坐标绘制路径 + } +} + +static int canvas_drawLine (lua_State *L) { + LVUserDataInfo * user1 = (LVUserDataInfo *)lua_touserdata(L, 1); + LVCanvas* canvas = (__bridge LVCanvas *)(user1->object); + if( LVIsType(user1, Canvas) ){ + CGFloat x1 = lua_tonumber(L, 2); + CGFloat y1 = lua_tonumber(L, 3); + CGFloat x2 = lua_tonumber(L, 4); + CGFloat y2 = lua_tonumber(L, 5); + [canvas drawLine:x1 :y1 :x2 :y2]; + return 1; + } + return 0; +} + +-(void) drawRect:(CGFloat)x :(CGFloat)y :(CGFloat)w :(CGFloat)h{ + if( _contentRef ) { + CGContextAddRect(_contentRef, CGRectMake(x, y, w, h)); + CGContextDrawPath(_contentRef, self.drawingMode); + } +} + +static int canvas_drawRect (lua_State *L) { + LVUserDataInfo * user1 = (LVUserDataInfo *)lua_touserdata(L, 1); + LVCanvas* canvas = (__bridge LVCanvas *)(user1->object); + if( LVIsType(user1, Canvas) ){ + CGFloat x1 = lua_tonumber(L, 2); + CGFloat y1 = lua_tonumber(L, 3); + CGFloat x2 = lua_tonumber(L, 4); + CGFloat y2 = lua_tonumber(L, 5); + [canvas drawRect:x1 :y1 :x2 :y2]; + return 1; + } + return 0; +} + +-(void) drawRoundRect:(CGFloat) x :(CGFloat)y :(CGFloat)w :(CGFloat)h :(CGFloat)rx :(CGFloat)ry{ + CGContextRef context = _contentRef; + if( context ) { + // 简便起见,这里把圆角半径设置为长和宽平均值的1/10 + CGFloat radius = rx; + + // 获取CGContext,注意UIKit里用的是一个专门的函数 + CGContextRef context = UIGraphicsGetCurrentContext(); + // 移动到初始点 + CGContextMoveToPoint(context,x+ radius,y+ 0); + + // 绘制第1条线和第1个1/4圆弧 + CGContextAddLineToPoint(context, x+ w - radius, y+0); + CGContextAddArc(context, x+w - radius, y+ radius, radius, -0.5 * M_PI, 0.0, 0); + + // 绘制第2条线和第2个1/4圆弧 + CGContextAddLineToPoint(context, x+ w, y+ h - radius); + CGContextAddArc(context, x+ w - radius, y+ h - radius, radius, 0.0, 0.5 * M_PI, 0); + + // 绘制第3条线和第3个1/4圆弧 + CGContextAddLineToPoint(context, x+radius, y+ h); + CGContextAddArc(context, x+ radius, y+ h-radius, radius, 0.5 * M_PI, M_PI, 0); + + // 绘制第4条线和第4个1/4圆弧 + CGContextAddLineToPoint(context, x+ 0, y+ radius); + CGContextAddArc(context, x+ radius, y+ radius, radius, M_PI, 1.5 * M_PI, 0); + + // 闭合路径 + CGContextClosePath(context); + CGContextDrawPath(context, self.drawingMode); + } +} + +static int canvas_drawRoundRect (lua_State *L) { + LVUserDataInfo * user1 = (LVUserDataInfo *)lua_touserdata(L, 1); + LVCanvas* canvas = (__bridge LVCanvas *)(user1->object); + if( LVIsType(user1, Canvas) ){ + CGFloat x = lua_tonumber(L, 2); + CGFloat y = lua_tonumber(L, 3); + CGFloat w = lua_tonumber(L, 4); + CGFloat h = lua_tonumber(L, 5); + CGFloat rx = lua_tonumber(L, 6); + CGFloat ry = lua_tonumber(L, 7); + [canvas drawRoundRect:x :y :w :h :rx :ry]; + return 1; + } + return 0; +} + +-(void) drawEllipse:(CGFloat) x :(CGFloat)y :(CGFloat)w :(CGFloat)h { + CGContextRef context = _contentRef; + if( context && w>=0 && h>= 0 ) { + //画椭圆 + CGContextAddEllipseInRect(context, CGRectMake(x, y, w, h)); //椭圆 + CGContextDrawPath(context, self.drawingMode); + } +} + +-(void) drawText:(NSString *)text :(UIFont *)font :(CGRect)rect{ + CGContextRef context = _contentRef; + if (context && text) { + //写文字 + NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:font,NSFontAttributeName,self.color,NSForegroundColorAttributeName,nil]; + [text drawInRect:rect withAttributes:attributes]; + } +} + +-(void) drawText:(NSString *)text :(UIFont *)font :(CGFloat)x :(CGFloat) y{ + CGContextRef context = _contentRef; + if (context && text) { + //画文字 + NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:font,NSFontAttributeName,self.color,NSForegroundColorAttributeName,nil]; + [text drawAtPoint:CGPointMake(x, y) withAttributes:attributes]; + } +} + +static int canvas_drawEllipse (lua_State *L) { + LVUserDataInfo * user1 = (LVUserDataInfo *)lua_touserdata(L, 1); + LVCanvas* canvas = (__bridge LVCanvas *)(user1->object); + if( LVIsType(user1, Canvas) ){ + CGFloat x = lua_tonumber(L, 2); + CGFloat y = lua_tonumber(L, 3); + CGFloat w = lua_tonumber(L, 4); + CGFloat h = w; + if( lua_type(L, 5)==LUA_TNUMBER ) { + h = lua_tonumber(L, 5); + } + [canvas drawEllipse:x :y :w :h]; + return 1; + } + return 0; +} + +static int canvas_drawCircle (lua_State *L) { + LVUserDataInfo * user1 = (LVUserDataInfo *)lua_touserdata(L, 1); + LVCanvas* canvas = (__bridge LVCanvas *)(user1->object); + if( LVIsType(user1, Canvas) ){ + CGFloat x = lua_tonumber(L, 2); + CGFloat y = lua_tonumber(L, 3); + CGFloat r = lua_tonumber(L, 4); + [canvas drawEllipse:x-r :y-r :r*2 :r*2]; + return 1; + } + return 0; +} + +static int canvas_color (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVCanvas* canvas = (__bridge LVCanvas *)(user->object); + if( lua_gettop(L)>=2 ) { + UIColor* color = lv_getColorFromStack(L, 2); + canvas.color = color; + return 0; + } else { + UIColor* color = canvas.color; + NSUInteger c = 0; + CGFloat a = 0; + if( lv_uicolor2int(color, &c,&a) ){ + lua_pushnumber(L, c ); + lua_pushnumber(L, a); + return 2; + } + } + } + return 0; +} + +-(void) setStrokeWidth:(CGFloat)strokeWidth{ + _strokeWidth = strokeWidth; + if( _contentRef ) { + CGContextSetLineWidth(_contentRef, strokeWidth); + } +} + +static int canvas_strokeWidth (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVCanvas* canvas = (__bridge LVCanvas *)(user->object); + if( lua_gettop(L)>=2 ) { + canvas.strokeWidth = lua_tonumber(L, 2); + return 0; + } else { + lua_pushnumber(L, canvas.strokeWidth ); + return 1; + } + } + return 0; +} + +static int canvas_style (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVCanvas* canvas = (__bridge LVCanvas *)(user->object); + if( lua_gettop(L)>=2 ) { + canvas.drawingMode = lua_tonumber(L, 2); + return 0; + } else { + lua_pushnumber(L, canvas.drawingMode ); + return 1; + } + } + return 0; +} + +-(void) resetPaint{ + [self clipRect:0 :0 :10240 :10240]; + self.color = [UIColor blackColor]; + self.strokeWidth = 0.5; + self.alpha = 1; + self.drawingMode = kCGPathFill; + self.font = [UIFont systemFontOfSize:12]; + [self scale:1 :1]; + [self rotate:0 :0 :0]; + [self translate:0 :0]; + [self skew:0 :0]; +} + +static int canvas_resetPaint (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVCanvas* canvas = (__bridge LVCanvas *)(user->object); + [canvas resetPaint]; + } + return 0; +} + +static int canvas_alpha (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVCanvas* canvas = (__bridge LVCanvas *)(user->object); + if( lua_gettop(L)>=2 ) { + CGFloat alpha = lua_tonumber(L, 2); + canvas.alpha = alpha; + return 0; + } + } + return 0; +} + +static int canvas_textSize (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVCanvas* canvas = (__bridge LVCanvas *)(user->object); + if( lua_gettop(L)>=2 ) { + CGFloat font = lua_tonumber(L, 2); + canvas.font = [UIFont systemFontOfSize:font]; + return 0; + } else { + return 0; + } + } + return 0; +} + +static int canvas_bold (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVCanvas* canvas = (__bridge LVCanvas *)(user->object); + if( lua_gettop(L)>=2 ) { + CGFloat bold = lua_toboolean(L, 2); + if (bold) { + canvas.font = [UIFont boldSystemFontOfSize:canvas.font.pointSize]; + }else{ + canvas.font = [UIFont systemFontOfSize:canvas.font.pointSize]; + } + return 0; + } else { + return 0; + } + } + return 0; +} + +-(void) clipRect:(CGFloat)x :(CGFloat)y :(CGFloat)w :(CGFloat)h{ + if( _contentRef ) { + CGContextClipToRect(_contentRef,CGRectMake(x, y, w, h)); + } +} + +static int canvas_clipRect (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user && lua_gettop(L)>=5 ){ + LVCanvas* canvas = (__bridge LVCanvas *)(user->object); + CGFloat x = lua_tonumber(L, 2); + CGFloat y = lua_tonumber(L, 3); + CGFloat w = lua_tonumber(L, 4); + CGFloat h = lua_tonumber(L, 5); + [canvas clipRect:x :y :w :h]; + } + return 0; +} + +static int drawText (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVCanvas* canvas = (__bridge LVCanvas *)(user->object); + if( lua_gettop(L)>=2 ) { + const char* text = lua_tolstring(L, 2, NULL); + NSString *str = [NSString stringWithCString:text encoding:NSUTF8StringEncoding]; + CGFloat x = lua_tonumber(L, 3); + CGFloat y = lua_tonumber(L, 4); + CGFloat h = canvas.font.lineHeight; + CGFloat leading = canvas.font.leading ; + CGFloat descender = canvas.font.descender; + CGRect rect = CGRectMake(x, y - (h+leading+descender), h * str.length, h ); + [canvas drawText:str :canvas.font :rect]; + return 0; + } else { + return 0; + } + } + return 0; +} + +static int canvas_drawOval (lua_State *L) { + return canvas_drawEllipse(L); +} + +-(void) drawArc:(CGFloat)x :(CGFloat)y :(CGFloat)w :(CGFloat)h :(CGFloat)startAngle :(CGFloat)endAngle :(BOOL) includeCenter{ + if( _contentRef ) { + x += w/2; + y += h/2; + if( includeCenter ) { + CGContextMoveToPoint(_contentRef, x, y); + } + CGContextAddArc(_contentRef, x, y, w/2, LV_ANGLE_RADIANS(startAngle), LV_ANGLE_RADIANS(endAngle), NO); + CGContextClosePath(_contentRef); + CGContextDrawPath(_contentRef, self.drawingMode); + } +} + +static int canvas_drawArc (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + CGFloat x = lua_tonumber(L, 2); + CGFloat y = lua_tonumber(L, 3); + CGFloat w = lua_tonumber(L, 4); + CGFloat h = lua_tonumber(L, 5); + CGFloat startAngle = lua_tonumber(L, 6); + CGFloat endAngle = lua_tonumber(L, 7); + BOOL includeCenter = lua_toboolean(L, 8); + LVCanvas* canvas = (__bridge LVCanvas *)(user->object); + [canvas drawArc:x :y :w :h :startAngle :endAngle :includeCenter]; + } + return 0; +} + +-(void) drawImage:(UIImage*)image :(CGFloat)x :(CGFloat)y :(CGFloat)w :(CGFloat)h { + if( _contentRef && image) { + CGContextSaveGState(_contentRef); + //CGAffineTransform t1 = CGAffineTransformMake(1, self.skewY, self.skewX, 1, 0, 0); + CGAffineTransform t2 = CGAffineTransformMake(1, 0, 0, -1, 0, 0); + //CGAffineTransform t3 = CGAffineTransformConcat(t1, t2); + CGContextConcatCTM(_contentRef, t2 ); + CGContextDrawImage(_contentRef, CGRectMake(x, -y-h , w, h), image.CGImage); + CGContextRestoreGState(_contentRef); + } +} + +static int canvas_drawImage (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVCanvas* canvas = (__bridge LVCanvas *)(user->object); + UIImage* image = nil; + if ( lua_type(L, 2)==LUA_TSTRING ) { + NSString* imageName = lv_paramString(L, 2);// 2 + image = [canvas.lv_luaviewCore.bundle imageWithName:imageName]; + } else if ( lua_type(L, 2)==LUA_TUSERDATA ) { + LVUserDataInfo * userdata = (LVUserDataInfo *)lua_touserdata(L, 2); + if( LVIsType(userdata, View) ){ + LVImage* lvImage = (__bridge LVImage *)(userdata->object); + if( [lvImage isKindOfClass:[LVImage class]] ) { + image = lvImage.image; + } + } else if( LVIsType(userdata, Bitmap) ) { + LVBitmap* bitmap = (__bridge LVBitmap *)(userdata->object); + image = bitmap.nativeImage; + } else if( LVIsType(userdata, Data) ) { + LVData* lvdata = (__bridge LVData *)(userdata->object); + image = [[UIImage alloc] initWithData:lvdata.data]; + } + } + if( image ) { + CGFloat x = lua_tonumber(L, 3); + CGFloat y = lua_tonumber(L, 4); + CGFloat w = lua_tonumber(L, 5); + CGFloat h = lua_tonumber(L, 6); + [canvas drawImage:image :x :y :w :h]; + } + } + return 0; +} + +-(void) saveGState { + if( _contentRef ) { + CGContextSaveGState(_contentRef); + } +} + +static int canvas_save (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVCanvas* canvas = (__bridge LVCanvas *)(user->object); + [canvas saveGState]; + } + return 0; +} + +-(void) restoreGState { + if( _contentRef ) { + CGContextRestoreGState(_contentRef); + } +} + +static int canvas_restore (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVCanvas* canvas = (__bridge LVCanvas *)(user->object); + [canvas restoreGState]; + } + return 0; +} + +-(void) rotate:(CGFloat) angle :(CGFloat)x :(CGFloat) y{ + if( _contentRef ) { + CGContextTranslateCTM(_contentRef, x, y); + CGContextRotateCTM(_contentRef,LV_ANGLE_RADIANS(angle) ); + CGContextTranslateCTM(_contentRef, -x, -y); + } +} + +static int canvas_rotate (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVCanvas* canvas = (__bridge LVCanvas *)(user->object); + CGFloat angle = lua_tonumber(L, 2); + CGFloat x = 0; + if( lua_type(L, 3) ) { + x = lua_tonumber(L, 3); + } + CGFloat y = 0; + if( lua_type(L, 4) ) { + y = lua_tonumber(L, 4); + } + [canvas rotate:angle :x :y];; + } + return 0; +} + +-(void) skew:(CGFloat)sx :(CGFloat)sy { + if( _contentRef ) { + self.skewX = sx; + self.skewY = sy; + CGAffineTransform transform = CGAffineTransformMake(1, sy, sx, 1, 0, 0); + CGContextConcatCTM(_contentRef,transform); + } +} + +-(void) setConcatCTM:(CGAffineTransform) transform{ + CGContextConcatCTM(_contentRef,transform); +} + +-(CGAffineTransform) concatCTM{ + return CGContextGetCTM(_contentRef); +} + +static int canvas_skew (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVCanvas* canvas = (__bridge LVCanvas *)(user->object); + CGFloat sx = lua_tonumber(L, 2); + CGFloat sy = 0; + if (lua_type(L, 3)==LUA_TNUMBER ) { + sy = lua_tonumber(L, 3); + } + [canvas skew:sx :sy]; + } + return 0; +} + +-(void) scale:(CGFloat)scaleX :(CGFloat)scaleY { + if( _contentRef ) { + self.scaleX = scaleX; + self.scaleY = scaleY; + CGContextScaleCTM(_contentRef, scaleX, scaleY); + } +} + +static int canvas_scale (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVCanvas* canvas = (__bridge LVCanvas *)(user->object); + CGFloat scaleX = lua_tonumber(L, 2); + CGFloat scaleY = scaleX; + if( lua_type(L, 3)==LUA_TNUMBER ) { + scaleY = lua_tonumber(L, 3); + } + [canvas scale:scaleX :scaleY]; + } + return 0; +} + +-(void) translate:(CGFloat)x :(CGFloat)y { + self.translate = CGPointMake(x, y); + if( _contentRef ) { + CGContextTranslateCTM(_contentRef, x, y); + } +} + +static int canvas_translate (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVCanvas* canvas = (__bridge LVCanvas *)(user->object); + CGFloat x = lua_tonumber(L, 2); + CGFloat y = lua_tonumber(L, 3); + [canvas translate:x :y]; + } + return 0; +} + +static void releaseCanvasUserData(LVUserDataInfo* user){ + if( user && user->object ){ + LVCanvas* canvas = CFBridgingRelease(user->object); + user->object = NULL; + if( canvas ){ + canvas.lv_userData = NULL; + canvas.lv_luaviewCore = nil; + canvas.contentRef = nil; + } + } +} + +static int lvCanvasGC (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + releaseCanvasUserData(user); + return 0; +} + +static int lvNewCanvas (lua_State *L) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVCanvas class]]; + + LVCanvas* canvas = [[c alloc] init:L]; + + { + NEW_USERDATA(userData, Canvas); + userData->object = CFBridgingRetain(canvas); + canvas.lv_userData = userData; + + luaL_getmetatable(L, META_TABLE_Canvas ); + lua_setmetatable(L, -2); + } + return 1; +} + ++(LVCanvas*) createLuaCanvas:(lua_State *)L contentRef:(CGContextRef) contentRef{ + LVCanvas* lvCanvas = [[LVCanvas alloc] init:L]; + lvCanvas.contentRef = contentRef; + { + NEW_USERDATA(userData, Canvas); + userData->object = CFBridgingRetain(lvCanvas); + lvCanvas.lv_userData = userData; + + luaL_getmetatable(L, META_TABLE_Canvas ); + lua_setmetatable(L, -2); + } + return lvCanvas; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewCanvas globalName:globalName defaultName:@"Canvas"]; + + const struct luaL_Reg memberFunctions [] = { + {"__gc", lvCanvasGC }, + {"nativeObj", nativeObj}, + + // size + // font + + {"drawPoint",canvas_drawPoint}, + {"drawLine",canvas_drawLine}, + {"drawRect",canvas_drawRect}, + {"drawRoundRect",canvas_drawRoundRect}, + {"drawCircle",canvas_drawCircle}, + {"drawEllipse",canvas_drawEllipse}, //__deprecated_msg("Use rotation") + {"drawText",drawText}, + {"drawOval",canvas_drawOval}, + {"drawArc",canvas_drawArc}, + {"drawImage",canvas_drawImage}, + + {"color",canvas_color}, + {"alpha",canvas_alpha}, + {"strokeWidth",canvas_strokeWidth}, + {"style",canvas_style}, + {"textSize",canvas_textSize}, + + {"resetPaint",canvas_resetPaint}, + {"save",canvas_save}, + {"restore",canvas_restore}, + + {"rotate",canvas_rotate}, + {"skew",canvas_skew}, + {"scale",canvas_scale}, + {"translate",canvas_translate}, + {"bold",canvas_bold}, + + + {"clipRect",canvas_clipRect}, + + {NULL, NULL} + }; + + lv_createClassMetaTable(L, META_TABLE_Canvas); + luaL_openlib(L, NULL, memberFunctions, 0); + + + { + // PaintStyle 常量 + lua_settop(L, 0); + NSDictionary* v = nil; + v = @{ + @"FILL": @(kCGPathFill), + @"EOFILL": @(kCGPathEOFill),//__deprecated_msg("") + @"STROKE": @(kCGPathStroke), + @"FILLSTROKE": @(kCGPathFillStroke), + @"EOFILLSTROKE": @(kCGPathEOFillStroke),//__deprecated_msg("") + }; + [LVUtil defineGlobal:@"PaintStyle" value:v L:L]; + } + return 0; +} + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVClassInfo.h b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVClassInfo.h new file mode 100644 index 00000000..e35c8791 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVClassInfo.h @@ -0,0 +1,24 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import + +@class LVMethod; + +@interface LVClassInfo : NSObject + + +- (void) addMethod:(LVMethod*) method key:(NSString*) key; +- (LVMethod*) getMethod:(NSString*) methodName; + +- (BOOL) existMethod:(NSString*) methodName; +- (void) setMethod:(NSString*) methodName exist:(BOOL) exist; + ++ (LVClassInfo*) classInfo:(NSString*) className; + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVClassInfo.m b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVClassInfo.m new file mode 100644 index 00000000..efc29e77 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVClassInfo.m @@ -0,0 +1,64 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVClassInfo.h" +#import "LVMethod.h" + +@interface LVClassInfo () +@property (nonatomic,strong) NSMutableDictionary* methods; +@property (nonatomic,strong) NSMutableDictionary* apiHash; +@end + +static NSMutableDictionary* g_allClassInfo = nil; + +@implementation LVClassInfo + +-(instancetype) init{ + self = [super init]; + if( self ) { + self.methods = [[NSMutableDictionary alloc] init]; + self.apiHash = [[NSMutableDictionary alloc] init]; + } + return self; +} + ++(LVClassInfo*) classInfo:(NSString*) className { + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + g_allClassInfo = [[NSMutableDictionary alloc] init]; + }); + + if( className==nil ) { + return nil; + } + LVClassInfo* classInfo = g_allClassInfo[className]; + if( classInfo==nil ) { + classInfo = [[LVClassInfo alloc] init]; + g_allClassInfo[className] = classInfo; + } + return classInfo; +} + +-(void) addMethod:(LVMethod*) method key:(NSString*) key{ + self.methods[key] = method; +} + +-(LVMethod*) getMethod:(NSString*) methodName{ + return self.methods[methodName]; +} + +-(BOOL) existMethod:(NSString*) methodName{ + return self.apiHash[methodName] != nil; +} + +-(void) setMethod:(NSString*) methodName exist:(BOOL) exist{ + if( exist ) { + self.apiHash[methodName] = @(exist); + } +} +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCollectionView.h b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCollectionView.h new file mode 100644 index 00000000..a44196de --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCollectionView.h @@ -0,0 +1,46 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" +#import "UIScrollView+LuaView.h" +#import "LVFlowLayout.h" + +/* + * 实现协议LVProtocal确保所有在luaview扩展类的实例对象都包含有这些基本的属性和方法, 是所有LuaView扩展类的实例对象的通用协议 + */ +@interface LVCollectionView : UICollectionView + +/* + * 所有在luaview扩展类的实例对象都包含有这些基本的属性和方法 + */ +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore;// 对应的lua运行内核 +@property(nonatomic,assign) LVUserDataInfo* lv_userData;// native对象对应的脚本对象 +@property(nonatomic,assign) NSUInteger lv_align; +@property(nonatomic,strong) CAShapeLayer* lv_shapeLayer; + +/* + * 构造方法 + */ +- (id) init:(lua_State*) l; + +/* + * delegate + datasource + */ +@property(nonatomic,weak) id lvScrollViewDelegate; + +/* + * CollectionView的布局管理器(位置支持某行吸顶功能需要自定义布局管理方式) + */ +@property(nonatomic,strong) LVFlowLayout* lvflowLayout; + +/* + * luaview所有扩展类的桥接协议: 只是一个静态协议, luaview统一调用该接口加载luaview扩展的类 + */ ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCollectionView.m b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCollectionView.m new file mode 100644 index 00000000..988b0112 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCollectionView.m @@ -0,0 +1,292 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVCollectionView.h" +#import "LVCollectionViewCell.h" +#import "LView.h" +#import "LVBaseView.h" +#import "LVScrollView.h" +#import "UIScrollView+LuaView.h" +#import "LVCollectionViewDelegate.h" +#import "LVFlowLayout.h" +#import "LVHeads.h" + +@interface LVCollectionView () +@property (nonatomic,strong) LVCollectionViewDelegate* collectionViewDelegate; +@end + + +@implementation LVCollectionView + +-(id) init:(lua_State*) l { + LVFlowLayout* flowLayout = [[LVFlowLayout alloc] init]; + self = [super initWithFrame:CGRectMake(0, 0, 0, 0) collectionViewLayout:flowLayout]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + self.collectionViewDelegate = [[LVCollectionViewDelegate alloc] init:self]; + self.delegate = self.collectionViewDelegate; + self.dataSource = self.collectionViewDelegate; + self.backgroundColor = [UIColor clearColor]; + + self.lvflowLayout = flowLayout; + self.collectionViewDelegate.lvCollectionView = self; + self.collectionViewDelegate.lvflowLayout = flowLayout; + + self.alwaysBounceVertical = YES; // 垂直总是有弹性动画 + self.scrollsToTop = NO; + + // 默认行间距都是0 + self.lvflowLayout.minimumLineSpacing = 0; + self.lvflowLayout.minimumInteritemSpacing = 0; + } + return self; +} + +-(void) setLvScrollViewDelegate:(id)lvScrollViewDelegate{ + _lvScrollViewDelegate = lvScrollViewDelegate; + self.collectionViewDelegate.delegate = lvScrollViewDelegate; +} + +-(void) dealloc{ +} + +-(void) reloadData{ + [super reloadData]; +} + +-(void) reloadDataASync{ + dispatch_async(dispatch_get_main_queue(), ^{ + [self performSelector:@selector(reloadData) withObject:nil afterDelay:0.001 inModes:@[NSRunLoopCommonModes]]; + }); +} + +-(void) layoutSubviews{ + [super layoutSubviews]; + if ( self.lv_luaviewCore.l ) { + lua_settop(self.lv_luaviewCore.l, 0); + } + [self lv_callLuaCallback:@STR_ON_LAYOUT]; +} + +// 重载以实现可能的定制需求, contentOffset +- (void) luaviewSetContentOffset:(CGPoint)contentOffset animated:(BOOL)animated{ + [self setContentOffset:contentOffset animated:animated]; +} + +// 重载以实现可能的定制需求, RectToVisible +- (void) luaviewScrollRectToVisible:(CGRect)rect animated:(BOOL)animated{ + [self scrollRectToVisible:rect animated:animated]; +} + +// 重载以实现可能的定制需求, scrollToTop +- (void) luaviewScrollToTopWithAnimated:(BOOL)animated{ + [self scrollRectToVisible:CGRectMake(0, 0, 320, 10) animated:animated]; +} + + + +#pragma -mark lvNewCollectionView +static int lvNewCollectionView(lua_State *L) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVCollectionView class]]; + + LVCollectionView* collectionView = [[c alloc] init:L]; + [collectionView lv_initRefreshHeader]; + + NEW_USERDATA(userData, View); + userData->object = CFBridgingRetain(collectionView); + collectionView.lv_userData = userData; + luaL_getmetatable(L, META_TABLE_UICollectionView ); + lua_setmetatable(L, -2); + + if ( lua_gettop(L)>=1 && lua_type(L, 1)==LUA_TTABLE ) { + lua_pushvalue(L, 1); + lv_udataRef(L, USERDATA_KEY_DELEGATE ); + } + + LuaViewCore* lview = LV_LUASTATE_VIEW(L); + if( lview ){ + [lview containerAddSubview:collectionView]; + } + return 1; +} + +static int reload (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVCollectionView* tableView = (__bridge LVCollectionView *)(user->object); + //reload接口异步拉起,确保layout中也能调用reload + [tableView reloadDataASync]; + lua_pushvalue(L, 1); + return 1; + } + return 0; +} + +static int miniSpacing (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVCollectionView* tableView = (__bridge LVCollectionView *)(user->object); + if( lua_gettop(L)>=3 ) { + CGFloat value1 = lua_tonumber(L, 2); + CGFloat value2 = lua_tonumber(L, 3); + tableView.lvflowLayout.minimumLineSpacing = value1; + tableView.lvflowLayout.minimumInteritemSpacing = value2; + return 0; + } else if( lua_gettop(L)>=2 ) { + CGFloat value1 = lua_tonumber(L, 2); + tableView.lvflowLayout.minimumLineSpacing = value1; + tableView.lvflowLayout.minimumInteritemSpacing = value1; + return 0; + } else { + CGFloat value1 = tableView.lvflowLayout.minimumLineSpacing; + CGFloat value2 = tableView.lvflowLayout.minimumInteritemSpacing; + lua_pushnumber(L, value1); + lua_pushnumber(L, value2); + return 2; + } + } + return 0; +} + +static int scrollDirection (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVCollectionView* tableView = (__bridge LVCollectionView *)(user->object); + if( lua_gettop(L)>=2 ) { + int value1 = lua_tonumber(L, 2); + tableView.lvflowLayout.scrollDirection = value1; + return 0; + } else { + CGFloat value1 = tableView.lvflowLayout.scrollDirection; + lua_pushnumber(L, value1); + return 1; + } + } + return 0; +} + +static int scrollToCell (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( LVIsType(user, View) ){ + LVCollectionView* collectionView = (__bridge LVCollectionView *)(user->object); + if( [collectionView isKindOfClass:[LVCollectionView class]] ) { + int nargs = lua_gettop(L); + if( nargs>=3 ){ + int section = lua_tonumber(L, 2); + int row = lua_tonumber(L, 3); + CGFloat offsetY = 0; + BOOL animation = YES; + for( int i=4; i<=nargs; i++ ) { + if( nargs>=i && lua_type(L, i)==LUA_TNUMBER ) { + offsetY = lua_tonumber(L, i); + } + if( nargs>=i && lua_type(L, i)==LUA_TBOOLEAN ) { + animation = lua_toboolean(L, i); + } + } + + int nativeSection = section-1; + int nativeRow = row-1 ; + if( 0<=nativeSection && nativeSection0 ) { + CGFloat y = r.origin.y + offsetY; + CGSize contentSize = collectionView.contentSize; + CGRect bounds = collectionView.bounds; + // 越界检查 + if( y + bounds.size.height > contentSize.height ) { + y = contentSize.height - bounds.size.height; + } + if( y < 0 ) { + y = 0; + } + [collectionView luaviewSetContentOffset:CGPointMake(0, y) animated:animation]; + } + } + return 0; + } + } + } + return 0; +} + +static int scrollToTop(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( LVIsType(user, View) ){ + LVCollectionView* tableView = (__bridge LVCollectionView *)(user->object); + if( [tableView isKindOfClass:[LVCollectionView class]] ) { + BOOL animation = YES; + if( lua_gettop(L)>=2 ) { + animation = lua_tonumber(L, 2); + } + [tableView luaviewScrollToTopWithAnimated:animation]; + return 0; + } + } + return 0; +} + ++(NSString*) globalName{ + return @"CollectionView"; +} + +static int initParams (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVCollectionView* tableView = (__bridge LVCollectionView *)(user->object); + //reload接口异步拉起,确保layout中也能调用reload + int ret = lv_setCallbackByKey(L, nil, NO); + [tableView reloadDataASync]; + return ret; + } + return 0; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + + [LVUtil reg:L clas:self cfunc:lvNewCollectionView globalName:globalName defaultName:[self globalName]]; + + const struct luaL_Reg memberFunctions [] = { + {"initParams", initParams }, + // refreshEnable // IOS 为实现 + {"reload", reload},// 安卓支持section row + + {"miniSpacing", miniSpacing}, + + {"scrollDirection", scrollDirection},// for IOS + + + {"scrollToCell", scrollToCell}, + {"scrollToTop", scrollToTop}, + {NULL, NULL} + }; + + lv_createClassMetaTable(L ,META_TABLE_UICollectionView); + + luaL_openlib(L, NULL, [LVBaseView baseMemberFunctions], 0); + luaL_openlib(L, NULL, [LVScrollView memberFunctions], 0); + luaL_openlib(L, NULL, memberFunctions, 0); + + const char* keys[] = { "addView", NULL};// 移除多余API + lv_luaTableRemoveKeys(L, keys ); + return 1; +} + + + +-(NSString*) description{ + return [NSString stringWithFormat:@"", + (int)[self hash], NSStringFromCGRect(self.frame) , NSStringFromCGSize(self.contentSize)]; +} + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCollectionViewCell.h b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCollectionViewCell.h new file mode 100644 index 00000000..65ee9217 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCollectionViewCell.h @@ -0,0 +1,21 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + +@interface LVCollectionViewCell : UICollectionViewCell + +@property (nonatomic, assign) BOOL isInited; + +-(void) pushTableToStack; + +-(void) doInitWithLView:(LuaViewCore*) lview; + + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCollectionViewCell.m b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCollectionViewCell.m new file mode 100644 index 00000000..e16e0861 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCollectionViewCell.m @@ -0,0 +1,65 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVCollectionViewCell.h" +#import "LVHeads.h" +#import "LView.h" +#import "lapi.h" + +@interface LVCollectionViewCell () +@property (nonatomic,weak) LuaViewCore* lv_luaviewCore; +@end + + + +@implementation LVCollectionViewCell + + +-(void) dealloc{ + lua_State* L = self.lv_luaviewCore.l; + if( L ) { + [LVUtil unregistry:L key:self]; + } +} + +-(void) doInitWithLView:(LuaViewCore*) lview{ + self.lv_luaviewCore = lview; + lua_State* L = lview.l; + if( L ) { + lua_createtable(L, 0, 0); + [LVUtil registryValue:L key:self stack:-1]; + lv_luaTableSetWeakWindow(L, self.contentView); + } +} + +-(void) pushTableToStack{ + lua_State* L = self.lv_luaviewCore.l; + if( L ) { + [LVUtil pushRegistryValue:L key:self]; + } +} + +-(NSString*) description{ + return [NSString stringWithFormat:@"", (int)[self hash], NSStringFromCGRect(self.frame)]; +} + +- (void) layoutSubviews{ + [super layoutSubviews]; + + CGRect rect = self.frame; + NSArray* subviews = [self.contentView subviews]; + for( UIView* view in subviews){ + [view lv_alignSelfWithSuperRect:rect]; + } +} + +// 修复gif图片滚动会消失问题 +-(void) prepareForReuse{ +} + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCollectionViewDelegate.h b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCollectionViewDelegate.h new file mode 100644 index 00000000..be2fc4bd --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCollectionViewDelegate.h @@ -0,0 +1,22 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVScrollViewDelegate.h" + +#define IDENTIFIER "Id" +#define DEFAULT_CELL_IDENTIFIER @"LVCollectionCell.default.identifier" + +@class LVCollectionView; +@class LVFlowLayout; + +@interface LVCollectionViewDelegate : LVScrollViewDelegate + +@property(nonatomic,weak) LVCollectionView* lvCollectionView; +@property(nonatomic,weak) LVFlowLayout* lvflowLayout; + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCollectionViewDelegate.m b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCollectionViewDelegate.m new file mode 100644 index 00000000..66fdd31e --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCollectionViewDelegate.m @@ -0,0 +1,364 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVCollectionViewDelegate.h" +#import "LVCollectionView.h" +#import "LVCollectionViewCell.h" +#import "LView.h" +#import "UIView+LuaView.h" +#import "LVHeads.h" + + +static inline NSInteger mapRow(NSInteger row){ + return row + 1; +} + +static inline NSInteger mapSection(NSInteger section){ + return section + 1; +} + +@interface LVCollectionViewDelegate () + +@property(nonatomic, strong) NSMutableSet *registeredIds; + + +@end + + +@implementation LVCollectionViewDelegate + +- (void)tryRegisterId:(NSString *)identifier inCollectionView:(UICollectionView *)view { + if (self.registeredIds == nil) { + self.registeredIds = [NSMutableSet set]; + } + if (![self.registeredIds containsObject:identifier]) { + [view registerClass:[LVCollectionViewCell class] forCellWithReuseIdentifier:identifier]; + [self.registeredIds addObject:identifier]; + } +} + +- (UICollectionViewCell*) collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { + NSInteger section = indexPath.section; + NSInteger row = indexPath.row; + BOOL pinned = NO; + NSString* identifier = [self retStringCallKey1:"Cell" key2:IDENTIFIER mapedSection:mapSection(section) mapedRow:mapRow(row) pinned:&pinned]; + if( identifier == nil ){ + identifier = DEFAULT_CELL_IDENTIFIER; + } + // 制定的cell 是否悬浮 + if( pinned ) { + [self.lvflowLayout addPinnedIndexPath:indexPath]; + } else { + [self.lvflowLayout delPinnedIndexPath:indexPath]; + } + [self tryRegisterId:identifier inCollectionView:collectionView]; + LVCollectionViewCell* cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath]; + cell.contentView.frame = cell.bounds;//脚本的window是ContentView大小可能和Cell不同步 + LuaViewCore* lview = self.owner.lv_luaviewCore; + lua_State* L = lview.l; + UIView* newWindow = cell.contentView; + [lview pushWindow:newWindow]; + if ( L ) { + if( !cell.isInited ){ + cell.isInited = YES; + [cell doInitWithLView:lview]; + + // 创建cell初始化 + lua_settop(L, 0); + lua_checkstack(L, 12); + [cell pushTableToStack];//arg1: cell + lua_pushnumber(L, mapSection(section) );//arg2: section + lua_pushnumber(L, mapRow(row) );//arg3: row + + lv_pushUserdata(L, self.owner.lv_userData); + lv_pushUDataRef(L, USERDATA_KEY_DELEGATE); + [LVUtil call:L key1:"Cell" key2:identifier.UTF8String key3:"Init" nargs:3 nrets:0 retType:LUA_TNONE]; + } + { // 通知布局调整 + // 参数 cell,section,row + lua_settop(L, 0); + lua_checkstack(L, 12); + [cell pushTableToStack];//arg1: cell + lua_pushnumber(L, mapSection(section) );//arg2: section + lua_pushnumber(L, mapRow(row) );//arg3: row + + lv_pushUserdata(L, self.owner.lv_userData); + lv_pushUDataRef(L, USERDATA_KEY_DELEGATE); + [LVUtil call:L key1:"Cell" key2:identifier.UTF8String key3:"Layout" nargs:3 nrets:0 retType:LUA_TNONE]; + } + } + [lview popWindow:newWindow]; + return cell; +} + +// section数量 +- (NSInteger) numberOfSectionsInCollectionView:(UICollectionView *)collectionView{ + lua_State* l = self.owner.lv_luaviewCore.l; + if( l && self.owner.lv_userData ){ + lv_pushUserdata(l, self.owner.lv_userData); + lv_pushUDataRef(l, USERDATA_KEY_DELEGATE); + if( [LVUtil call:l key1:"Section" key2:"SectionCount" key3:NULL nargs:0 nrets:1 retType:LUA_TNUMBER] ==0 ) { + if( lua_type(l, -1)==LUA_TNUMBER ) { + NSInteger num = lua_tonumber(l, -1); + num = (num>0 ? num : 0); + return num; + } + } + return 1; + } + return 0; +} +// 每个区域的行数 +- (NSInteger) collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{ + lua_State* l = self.owner.lv_luaviewCore.l; + if( l ){ + // args + lua_pushnumber(l, mapSection(section) ); + + // table + lv_pushUserdata(l, self.owner.lv_userData); + lv_pushUDataRef(l, USERDATA_KEY_DELEGATE); + if( [LVUtil call:l key1:"Section" key2:"RowCount" key3:NULL nargs:1 nrets:1 retType:LUA_TNUMBER] ==0 ) { + if( lua_type(l, -1)==LUA_TNUMBER ) { + NSInteger num = lua_tonumber(l, -1); + num = (num>0 ? num : 0); + return num; + } + } + } + return 0; +} +//------- +#pragma mark --UICollectionViewDelegateFlowLayout +//定义每个UICollectionView 的大小 +- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath +{ + NSInteger section = indexPath.section; + NSInteger row = indexPath.row; + NSString* identifier = [self retStringCallKey1:"Cell" key2:IDENTIFIER mapedSection:mapSection(section) mapedRow:mapRow(row) pinned:NULL]; + if( identifier ) { + CGSize size = [self retSizeCallKey1:"Cell" key2:identifier.UTF8String key3:"Size" mapedSection:mapSection(section) mapedRow:mapRow(row) ]; + if( size.width<0 || isnan(size.width) ) { + size.width = 0; + } + if( size.height<0 || isnan(size.height) ) { + size.height = 0; + } + return size; + } else { + return CGSizeMake(self.owner.frame.size.width, 1); + } +} +//定义每个UICollectionView 的间距 +-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section +{ + UIEdgeInsets insets = [self retInsetCallKey1:"Section" key2:"EdgeInsets" mapedSection:mapSection(section) mapedRow:mapRow(0)]; + //insets.top = self.flowLayout.minimumLineSpacing; + return insets; +} +//定义每个UICollectionView 纵向的间距 +- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section { + // return self.flowLayout.minimumLineSpacing; + CGFloat spacing = [self retFloatCallKey1:"Section" key2:"Spacing" mapedSection:mapSection(section) ]; + return spacing; +} + +- (CGFloat) retFloatCallKey1:(const char*) funcName key2:(const char*) key2 mapedSection:(NSInteger) mapedSection { + lua_State* l = self.owner.lv_luaviewCore.l; + if( l ){ + lua_checkstack(l, 12); + lua_pushnumber(l, mapedSection); + + lv_pushUserdata(l, self.owner.lv_userData); + lv_pushUDataRef(l, USERDATA_KEY_DELEGATE); + if( [LVUtil call:l key1:funcName key2:key2 key3:NULL nargs:1 nrets:1 retType:LUA_TNUMBER] ==0 ) { + if( lua_type(l, -1)==LUA_TNUMBER ) { + CGFloat heigth = lua_tonumber(l, -1); + return heigth; + } + } + } + return 0; +} + +- (NSString*) retStringCallKey1:(const char*) key1 key2:(const char*)key2 + mapedSection:(NSInteger) mapedSection mapedRow:(NSInteger) mapedRow pinned:(BOOL*) pinned{ + lua_State* l = self.owner.lv_luaviewCore.l; + if( l ){ + // args + lua_checkstack(l, 12); + lua_pushnumber(l, mapedSection); + lua_pushnumber(l, mapedRow); + + // table + lv_pushUserdata(l, self.owner.lv_userData); + lv_pushUDataRef(l, USERDATA_KEY_DELEGATE); + + if( [LVUtil call:l key1:key1 key2:key2 key3:NULL nargs:2 nrets:2 retType:LUA_TSTRING] ==0 ) { + if( lua_type(l, -2)==LUA_TSTRING ){ + NSString* value = lv_paramString(l, -2); + BOOL yes = lua_toboolean(l, -1); + if( pinned ) { + *pinned = yes; + } + return value; + } + } + } + return nil; +} + +- (CGSize) retSizeCallKey1:(const char*) key1 key2:(const char*)key2 key3:(const char*)key3 + mapedSection:(NSInteger) mapedSection mapedRow:(NSInteger) mapedRow { + lua_State* l = self.owner.lv_luaviewCore.l; + if( l ){ + // args + lua_checkstack(l, 12); + lua_pushnumber(l, mapedSection); + lua_pushnumber(l, mapedRow); + + // table + lv_pushUserdata(l, self.owner.lv_userData); + lv_pushUDataRef(l, USERDATA_KEY_DELEGATE); + + if( [LVUtil call:l key1:key1 key2:key2 key3:key3 nargs:2 nrets:2 retType:LUA_TNONE] ==0 ) { + CGSize size = {0}; + if( lua_type(l, -1) ==LUA_TNIL ) { + size.width = self.owner.frame.size.width; + size.height = lua_tonumber(l, -2); + } else{ + size.width = lua_tonumber(l, -2); + size.height = lua_tonumber(l, -1); + } + return size; + } + } + return CGSizeMake(self.owner.frame.size.width, 1); +} +- (UIEdgeInsets) retInsetCallKey1:(const char*) key1 key2:(const char*)key2 + mapedSection:(NSInteger) mapSection mapedRow:(NSInteger)mapedRow { + lua_State* l = self.owner.lv_luaviewCore.l; + if( l ){ + // args + lua_checkstack(l, 12); + lua_pushnumber(l, mapSection); + lua_pushnumber(l, mapedRow); + + // table + lv_pushUserdata(l, self.owner.lv_userData); + lv_pushUDataRef(l, USERDATA_KEY_DELEGATE); + + if( [LVUtil call:l key1:key1 key2:key2 key3:NULL nargs:2 nrets:4 retType:LUA_TNONE] ==0 ) { + UIEdgeInsets egeInsets = {0}; + egeInsets.top = lua_tonumber(l, -4); + egeInsets.left = lua_tonumber(l, -3); + egeInsets.bottom = lua_tonumber(l, -2); + egeInsets.right = lua_tonumber(l, -1); + return egeInsets; + } + } + return UIEdgeInsetsMake(0, 0, 0, 0); +} + +- (void) collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { + NSInteger section = indexPath.section; + NSInteger row = indexPath.row; + lua_State* l = self.owner.lv_luaviewCore.l; + if( l ){ + NSString* identifier = [self retStringCallKey1:"Cell" key2:IDENTIFIER mapedSection:mapSection(section) mapedRow:mapRow(row) pinned:NULL]; + if ( identifier ) { + // 参数 cell,section,row + lua_settop(l, 0); + lua_checkstack(l, 12); + lua_pushnil(l);// cell + lua_pushnumber(l, mapSection(section) ); + lua_pushnumber(l, mapRow(row) ); + + // table + lv_pushUserdata(l, self.owner.lv_userData); + lv_pushUDataRef(l, USERDATA_KEY_DELEGATE); + + if( [LVUtil call:l key1:"Cell" key2:identifier.UTF8String key3:STR_CALLBACK key4:STR_ON_CLICK nargs:3 nrets:0 retType:LUA_TNONE]==0 ) { + } + } + } +} + +-(void) callWithScrollArgsForKey:(NSString*) keyName{ + UICollectionView* tableView = (UICollectionView*)self.owner; + NSArray* indexPaths = [tableView indexPathsForVisibleItems]; + int visibleCount = 0; + NSIndexPath* indexPath0 = nil; + + for( NSIndexPath* indexPath in indexPaths ) { + visibleCount ++; + if( indexPath0== nil ) { + indexPath0 = indexPath; + } else if( indexPath.row +#import "LVHeads.h" + +@interface LVCustomPanel : UIView + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; +@property(nonatomic,assign) NSUInteger lv_align; +@property(nonatomic,strong) CAShapeLayer* lv_shapeLayer; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +- (void) callLuaWithArgument:(NSString*) info; +- (void) callLuaWithArguments:(NSArray*) args; +// callLuaFunction() +// callLuaCallback + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCustomPanel.m b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCustomPanel.m new file mode 100644 index 00000000..c8a2d0c8 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCustomPanel.m @@ -0,0 +1,100 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVCustomPanel.h" +#import "LVBaseView.h" +#import "LView.h" +#import "LVHeads.h" + +@implementation LVCustomPanel + +- (void) callLuaWithArgument:(NSString*) info { + [self callLuaWithArguments:@[ (info?info:@"") ]]; +} + +- (void) callLuaWithArguments:(NSArray*) args{ + // 外部回调脚本一定要在主线程调用 + dispatch_block_t f = ^(){ + lua_State* L = self.lv_luaviewCore.l; + if( L && self.lv_userData ){ + lua_checkstack(L,32); + int num = lua_gettop(L); + for( int i=0; i=4 ) { + r = CGRectMake(lua_tonumber(L, 1), lua_tonumber(L, 2), lua_tonumber(L, 3), lua_tonumber(L, 4)); + } + LVCustomPanel* errorNotice = [[c alloc] initWithFrame:r]; + { + NEW_USERDATA(userData, View); + userData->object = CFBridgingRetain(errorNotice); + errorNotice.lv_userData = userData; + errorNotice.lv_luaviewCore = LV_LUASTATE_VIEW(L); + + luaL_getmetatable(L, META_TABLE_CustomPanel ); + lua_setmetatable(L, -2); + } + LuaViewCore* view = LV_LUASTATE_VIEW(L); + if( view ){ + [view containerAddSubview:errorNotice]; + } + return 1; /* new userdatum is already on the stack */ +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewCustomPanelView globalName:globalName defaultName:@"CustomPanel"]; + + const struct luaL_Reg memberFunctions [] = { + {NULL, NULL} + }; + + lv_createClassMetaTable(L, META_TABLE_CustomPanel); + + luaL_openlib(L, NULL, [LVBaseView baseMemberFunctions], 0); + luaL_openlib(L, NULL, memberFunctions, 0); + return 1; +} + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCustomView.h b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCustomView.h new file mode 100644 index 00000000..4865143d --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCustomView.h @@ -0,0 +1,24 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + +@interface LVCustomView : UIView + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; +@property(nonatomic,assign) NSUInteger lv_align; +@property(nonatomic,strong) CAShapeLayer* lv_shapeLayer; +@property(nonatomic,assign) BOOL lv_canvas; + +-(id) init:(lua_State*) l; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCustomView.m b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCustomView.m new file mode 100644 index 00000000..38216b3a --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCustomView.m @@ -0,0 +1,85 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVCustomView.h" +#import "LVBaseView.h" +#import "LView.h" +#import "LVCanvas.h" + +@interface LVCustomView () +@property(nonatomic,assign) BOOL lv_isCallbackAddClickGesture;// 支持Callback 点击事件 +@end + +@implementation LVCustomView + +-(id) init:(lua_State*) l{ + self = [super init]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + self.backgroundColor = [UIColor clearColor]; + self.clipsToBounds = YES; + } + return self; +} + +-(void) drawRect:(CGRect)rect{ + [super drawRect:rect]; + + lua_State* L = self.lv_luaviewCore.l; + if( L ) { + lua_settop(L, 0); + CGContextRef contextRef = UIGraphicsGetCurrentContext(); + LVCanvas* canvas = [LVCanvas createLuaCanvas:L contentRef:contextRef]; + [self lv_callLuaCallback:@STR_ON_DRAW key2:nil argN:1]; + canvas.contentRef = NULL; + } +} + +#pragma -mark CustomView +static int lvNewCustomView (lua_State *L) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVCustomView class]]; + + { + LVCustomView* customView = [[c alloc] init:L]; + { + NEW_USERDATA(userData, View); + userData->object = CFBridgingRetain(customView); + customView.lv_userData = userData; + + luaL_getmetatable(L, META_TABLE_CustomView ); + lua_setmetatable(L, -2); + } + LuaViewCore* father = LV_LUASTATE_VIEW(L); + if( father ){ + [father containerAddSubview:customView]; + } + } + return 1; /* new userdatum is already on the stack */ +} + +static int onDraw (lua_State *L) { + return lv_setCallbackByKey(L, STR_ON_DRAW, NO); +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewCustomView globalName:globalName defaultName:@"CustomView"]; + + const struct luaL_Reg memberFunctions [] = { + {"onDraw" , onDraw}, + {NULL, NULL} + }; + + lv_createClassMetaTable(L,META_TABLE_CustomView); + + luaL_openlib(L, NULL, [LVBaseView baseMemberFunctions], 0); + luaL_openlib(L, NULL, memberFunctions, 0); + + return 1; +} + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVDB.h b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVDB.h new file mode 100644 index 00000000..c1c8f6b4 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVDB.h @@ -0,0 +1,16 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + +@interface LVDB : NSObject + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVDB.m b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVDB.m new file mode 100644 index 00000000..db677ea5 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVDB.m @@ -0,0 +1,92 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVDB.h" +#import "LVHeads.h" + +@implementation LVDB + + + +static int db_get (lua_State *L) { + lv_clearFirstTableValue(L); + NSString* key = lv_paramString(L, 1); + NSString* defaultValue = nil; + if( lua_gettop(L)>=2 && lua_type(L, 2)==LUA_TNUMBER ) { + double v = lua_tonumber(L, 2); + defaultValue = [NSString stringWithFormat:@"%lf",v]; + } else { + defaultValue = lv_paramString(L, 2); + } + if( key.length>0 ) { + NSString* value = [[NSUserDefaults standardUserDefaults] objectForKey:key]; + if( value == nil ) + value = defaultValue; + lua_pushstring(L, value.UTF8String); + return 1; /* number of results */ + } else { + return 0; + } +} + +static BOOL needSub(NSString* s){ + if( [s rangeOfString:@"."].length>0 ){ + if( [s hasSuffix:@"0"] || [s hasSuffix:@"."] ){ + return YES; + } + } + return NO; +} + +static NSString* clearString(NSString* s){ + if( needSub(s) ){ + NSMutableString* buf = [[NSMutableString alloc] initWithString:s]; + for( ;buf.length>0; ){ + if( needSub(buf) ){ + NSRange range = {0}; + range.length = 1; + range.location = buf.length-1; + [buf deleteCharactersInRange:range]; + } else { + break; + } + } + return buf; + } + return s; +} + +static int db_set (lua_State *L) { + lv_clearFirstTableValue(L); + if( lua_gettop(L)>=2 ) { + NSString* key = lv_paramString(L, 1); + NSString* value = lv_paramString(L, 2); + if( value==nil && (lua_type(L, 2)==LUA_TNUMBER) ){ + value = [NSString stringWithFormat:@"%f",lua_tonumber(L, 2)]; + value = clearString(value); + } + if( key.length>0 && value.length>0 ){ + [[NSUserDefaults standardUserDefaults] setObject:value forKey:key]; + [[NSUserDefaults standardUserDefaults] synchronize]; + } + } + return 0; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + const struct luaL_Reg functions [] = { + {"get", db_get}, + {"set", db_set}, + {LUAVIEW_SYS_TABLE_KEY, db_set}, + {NULL, NULL} + }; + luaL_openlib(L, "DB", functions, 0); + return 0; +} + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVData.h b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVData.h new file mode 100644 index 00000000..d152a4de --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVData.h @@ -0,0 +1,26 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + + +//LVData +@interface LVData : NSObject + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; + +@property(nonatomic,strong) NSMutableData* data;//真实的数据 + +-(id) init:(lua_State*) l; ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + ++(int) createDataObject:(lua_State *)L data:(NSData*) data; + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVData.m b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVData.m new file mode 100644 index 00000000..ec037483 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVData.m @@ -0,0 +1,219 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVData.h" +#import "LVHeads.h" + +@interface LVData () +@end + +@implementation LVData + +-(id) init:(lua_State *)l{ + self = [super init]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + self.data = [[NSMutableData alloc] init]; + } + return self; +} + +-(id) lv_nativeObject{ + return self.data; +} + +static void releaseUserDataData(LVUserDataInfo* user){ + if( user && user->object ){ + LVData* data = CFBridgingRelease(user->object); + user->object = NULL; + if( data ){ + data.lv_userData = NULL; + data.lv_luaviewCore = nil; + data.data = nil; + } + } +} + +static int lvDataGC (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + releaseUserDataData(user); + return 0; +} + +static int lvNewData (lua_State *L) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVData class]]; + + LVData* data = [[c alloc] init:L]; + int argN = lua_gettop(L); + if( argN>0 ) { + if ( lua_type(L, 1)==LUA_TSTRING ) {// 支持字符串转 NSData + NSString* s = lv_paramString(L, 1); + const char* chars = s.UTF8String; + [data.data appendBytes:chars length:strlen(chars) ]; + } else { + int num = lua_tonumber(L, 1); + if( num>0 ){ + [data.data setLength:num]; + } + } + } + + { + NEW_USERDATA(userData, Data); + userData->object = CFBridgingRetain(data); + data.lv_userData = userData; + + luaL_getmetatable(L, META_TABLE_Data ); + lua_setmetatable(L, -2); + } + return 1; +} + ++(int) createDataObject:(lua_State *)L data:(NSData*) data{ + return [self createDataObject:L data1:data data2:nil]; +} + ++(int) createDataObject:(lua_State *)L data1:(NSData*) data1 data2:(NSData*) data2{ + LVData* lvdata = [[LVData alloc] init:L]; + if( data1 ) { + [lvdata.data setData:data1]; + } + if( data2 ) { + [lvdata.data appendData:data2]; + } + { + NEW_USERDATA(userData, Data); + userData->object = CFBridgingRetain(lvdata); + lvdata.lv_userData = userData; + + luaL_getmetatable(L, META_TABLE_Data ); + lua_setmetatable(L, -2); + } + return 1; +} + +static int __tostring (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVData* data = (__bridge LVData *)(user->object); + NSStringEncoding encode = NSUTF8StringEncoding; + if( lua_gettop(L)>=2 && lua_type(L, 2)==LUA_TNUMBER ) { + encode = lua_tonumber(L, 2); + } + NSString* s = [[NSString alloc] initWithData:data.data encoding:encode]; + if( s==nil ){ + NSStringEncoding gbkEncoding = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000); + s = [[NSString alloc] initWithData:data.data encoding:gbkEncoding]; + if ( s==nil ) { + s = [[NSString alloc] initWithFormat:@"{ UserDataType=data, length=%ld }",(long)data.data.length]; + } + } + lua_pushstring(L, s.UTF8String); + return 1; + } + return 0; +} + +static int __index (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + LVData* lvData = (__bridge LVData *)(user->object); + NSMutableData* data = lvData.data; + if( lvData && lvData.data){ + if( lua_type(L, 2)==LUA_TNUMBER ){ + int index = lua_tonumber(L, 2)-1; + if( index>=0 && indexobject); + NSMutableData* data = lvData.data; + if( lvData && lvData.data){ + if( lua_type(L, 2)==LUA_TNUMBER ){ + int index = lua_tonumber(L, 2)-1; + int value = lua_tonumber(L, 3); + if( index>=0 && indexobject); + LVData* lvData2 = (__bridge LVData *)(user2->object); + if( LVIsType(user1, Data) && LVIsType(user2, Data) && lvData1.data && lvData2.data ){ + [LVData createDataObject:L data1:lvData1.data data2:lvData2.data]; + return 1; + } + return 0; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewData globalName:globalName defaultName:@"Data"]; + + const struct luaL_Reg memberFunctions [] = { + // toJson 判断是否json + // toString 判断是否字符串 + // toTable + // append + + {"__index", __index }, + {"__newindex", __newindex }, + + {"__add", __add }, + + {"__gc", lvDataGC }, + + {"__tostring", __tostring }, + {NULL, NULL} + }; + + lv_createClassMetaTable(L, META_TABLE_Data); + + luaL_openlib(L, NULL, memberFunctions, 0); + return 0; +} + + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVDate.h b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVDate.h new file mode 100644 index 00000000..e9b31766 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVDate.h @@ -0,0 +1,24 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import + + +@interface LVDate : NSObject + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; + +@property(nonatomic,strong) NSDate* date; + +- (id) lv_nativeObject; // 返回native对象 + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVDate.m b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVDate.m new file mode 100644 index 00000000..0e9ebe55 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVDate.m @@ -0,0 +1,184 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVHeads.h" +#import "LVDate.h" +#import "LVHeads.h" + + + +@implementation LVDate + +-(id) init:(NSDate*) d{ + self = [super init]; + if( self ) { + self.date = d; + } + return self; +} + +-(id) lv_nativeObject{ + return self.date; +} + +static NSString* string09(NSString* s, NSUInteger len){ + NSMutableString* buf = [[NSMutableString alloc] init]; + for( int i=0; iobject = CFBridgingRetain(d); + + luaL_getmetatable(L, META_TABLE_Date ); + lua_setmetatable(L, -2); + } + } + return 1; /* new userdatum is already on the stack */ +} + + +static int __GC (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( LVIsType(user, Date) && user->object ){ + CFBridgingRelease(user->object); + user->object = NULL; + } + return 0; +} + +static int __tostring (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( LVIsType(user, Date) ){ + LVDate* date = (__bridge LVDate *)(user->object); + NSString* s = [NSString stringWithFormat:@"%@", date.date ]; + lua_pushstring(L, s.UTF8String); + return 1; + } + return 0; +} + +static int format (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + NSString* formatString = lv_paramString(L, 2); + if( LVIsType(user, Date) ){ + LVDate* date = (__bridge LVDate *)(user->object); + if( date ) { + NSString* ret = nil; + if( formatString ){ + NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; + [formatter setDateFormat:formatString]; + ret = [formatter stringFromDate:date.date]; + } else { + ret = [NSString stringWithFormat:@"%@", date.date ]; + } + lua_pushstring(L, ret.UTF8String); + return 1; + } + } + return 0; +} + +static int __sub (lua_State *L) { + LVUserDataInfo * user1 = (LVUserDataInfo *)lua_touserdata(L, 1); + LVUserDataInfo * user2 = (LVUserDataInfo *)lua_touserdata(L, 2); + if( LVIsType(user1, Date) && LVIsType(user2, Date) ){ + LVDate* date1 = (__bridge LVDate *)(user1->object); + LVDate* date2 = (__bridge LVDate *)(user2->object); + double time = [date1.date timeIntervalSinceDate:date2.date]; + lua_pushnumber(L, time); + return 1; + } + return 0; +} + +static int __eq (lua_State *L) { + LVUserDataInfo * user1 = (LVUserDataInfo *)lua_touserdata(L, 1); + LVUserDataInfo * user2 = (LVUserDataInfo *)lua_touserdata(L, 2); + if( LVIsType(user1, Date) && LVIsType(user2, Date) ){ + LVDate* date1 = (__bridge LVDate *)(user1->object); + LVDate* date2 = (__bridge LVDate *)(user2->object); + BOOL yes = [date1.date isEqualToDate:date2.date]; + lua_pushboolean(L, (yes?1:0) ); + return 1; + } + return 0; +} + +static int timeInterval (lua_State *L) { + LVUserDataInfo * user1 = (LVUserDataInfo *)lua_touserdata(L, 1); + if( LVIsType(user1, Date) ){ + LVDate* date1 = (__bridge LVDate *)(user1->object); + double time = [date1.date timeIntervalSince1970]; + lua_pushnumber(L, time); + return 1; + } + return 0; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewDate globalName:globalName defaultName:@"Date"]; + + const struct luaL_Reg memberFunctions [] = { + {"__gc", __GC }, + {"__sub", __sub}, + {"__eq", __eq}, + {"timeInterval", timeInterval }, + + {"__tostring", __tostring }, + {"format", format }, + {NULL, NULL} + }; + + lv_createClassMetaTable(L, META_TABLE_Date); + + luaL_openlib(L, NULL, memberFunctions, 0); + return 1; +} + + +@end + + + diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVDownloader.h b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVDownloader.h new file mode 100644 index 00000000..b696dd49 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVDownloader.h @@ -0,0 +1,25 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + + +@interface LVDownloader : NSObject + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; + +@property(nonatomic,copy) id luaObjRetainKey; + +-(id) init:(lua_State*) l; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +@end + diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVDownloader.m b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVDownloader.m new file mode 100644 index 00000000..dd7b2329 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVDownloader.m @@ -0,0 +1,146 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVDownloader.h" +#import "LVUtil.h" +#import "LVData.h" +#import "LView.h" +#import "LVHeads.h" + +@interface LVDownloader () +@property(nonatomic,strong) NSData* data; +@property(nonatomic,strong) id strongSelf; +@end + + +@implementation LVDownloader + + +static void releaseUserDataDownloader(LVUserDataInfo* user){ + if( user && user->object ){ + LVDownloader* downloader = CFBridgingRelease(user->object); + user->object = NULL; + if( downloader ){ + downloader.lv_userData = nil; + downloader.lv_luaviewCore = nil; + } + } +} + +-(void) dealloc{ + releaseUserDataDownloader(_lv_userData); +} + +-(id) lv_nativeObject{ + return nil; +} + +-(id) init:(lua_State*) l{ + self = [super init]; + if( self ){ + self.luaObjRetainKey = [[NSMutableString alloc] init]; + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + self.strongSelf = self; + } + return self; +} + + +#pragma -mark downloader +static int lvNewDownloader (lua_State *L) { + if( lua_gettop(L)>=2 ) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVDownloader class]]; + + LVDownloader* downloader = [[c alloc] init:L]; + NSString* url = lv_paramString(L, 1); // 1: url + //NSString* fileName = lvL_paramString(L, 2);// 2: fileName + // 3: callback + if( lua_type(L, -1) == LUA_TFUNCTION ) { + [LVUtil registryValue:L key:downloader stack:-1]; + } + + { + NEW_USERDATA(userData, Downloader); + userData->object = CFBridgingRetain(downloader); + downloader.lv_userData = userData; + + luaL_getmetatable(L, META_TABLE_Downloader ); + lua_setmetatable(L, -2); + + [LVUtil registryValue:L key:downloader.luaObjRetainKey stack:-1]; + } + [LVUtil download:url callback:^(NSData *data) { + downloader.data = data; + [downloader performSelectorOnMainThread:@selector(didFileLoaded) withObject:nil waitUntilDone:NO]; + }]; + return 1; + } else { + LVError(@"downloader( Callback==nil )!!!"); + } + return 0; +} + +-(void) didFileLoaded{ + lua_State* L = self.lv_luaviewCore.l; + if( L ){ + if( self.data ) { + [LVData createDataObject:L data:self.data]; + } else { + lua_pushnil(L); + } + [LVUtil call:L lightUserData:self key1:nil key2:nil nargs:1]; + + [LVUtil unregistry:L key:self.luaObjRetainKey]; + [LVUtil unregistry:L key:self]; + } + self.strongSelf = nil; +} + + static int __gc (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + releaseUserDataDownloader(user); + return 0; +} + +static int __tostring (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVDownloader* downloader = (__bridge LVDownloader *)(user->object); + NSString* s = [NSString stringWithFormat:@"LVUserDataDownloader: %@", downloader ]; + lua_pushstring(L, s.UTF8String); + return 1; + } + return 0; +} + +static int PathOfResource (lua_State *L) { + NSString* fileName = lv_paramString(L, 1); + LuaViewCore* lview = LV_LUASTATE_VIEW(L); + NSString* path = [lview.bundle resourcePathWithName:fileName]; + lua_pushstring(L, path.UTF8String); + return 1; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + lv_defineGlobalFunc("PathOfResource", PathOfResource, L); + + [LVUtil reg:L clas:self cfunc:lvNewDownloader globalName:globalName defaultName:@"Download"]; // __deprecated_msg("") + const struct luaL_Reg memberFunctions [] = { + {"__gc", __gc }, + + {"__tostring", __tostring }, + {NULL, NULL} + }; + + lv_createClassMetaTable(L, META_TABLE_Downloader); + + luaL_openlib(L, NULL, memberFunctions, 0); + return 1; +} + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVEmptyRefreshCollectionView.h b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVEmptyRefreshCollectionView.h new file mode 100644 index 00000000..c80eda03 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVEmptyRefreshCollectionView.h @@ -0,0 +1,17 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" +#import "UIScrollView+LuaView.h" +#import "LVCollectionView.h" + +// for IOS +@interface LVEmptyRefreshCollectionView : LVCollectionView + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVEmptyRefreshCollectionView.m b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVEmptyRefreshCollectionView.m new file mode 100644 index 00000000..8c28b925 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVEmptyRefreshCollectionView.m @@ -0,0 +1,45 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVEmptyRefreshCollectionView.h" +#import "LVRefreshHeader.h" + +@implementation LVEmptyRefreshCollectionView + +// 下拉刷新 +-(void) lv_initRefreshHeader{// 初始化下拉刷新功能 + LVRefreshHeader* refreshHeader = [[LVRefreshHeader alloc] init]; + self.lv_refresh_header = refreshHeader; + + __weak typeof(self) weakSelf = self; + refreshHeader.refreshingBlock = ^(){ + [weakSelf lv_refreshHeaderToRefresh]; + }; +} + +- (void) lv_hiddenRefreshHeader:(BOOL) hidden{ + self.lv_refresh_header.hidden = hidden; +} + +- (void) lv_beginRefreshing{// 进入刷新状态 + [self.lv_refresh_header beginRefreshing]; +} + +- (void) lv_endRefreshing{// 结束刷新状态 + [self.lv_refresh_header endRefreshing]; +} + +- (BOOL) lv_isRefreshing{// 是否正在刷新 + return self.lv_refresh_header.isRefreshing; +} + ++(NSString*) globalName{ + return @"EmptyRefreshCollectionView"; +} + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVEvent.h b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVEvent.h new file mode 100644 index 00000000..e4944422 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVEvent.h @@ -0,0 +1,35 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import +#import "LVHeads.h" + +#define LVTouchEventType_DOWN 1010 +#define LVTouchEventType_MOVE 1020 +#define LVTouchEventType_CANCEL 1030 +#define LVTouchEventType_UP 1040 + +@interface LVEvent : NSObject + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; + +@property(nonatomic,weak) UIEvent* event; + +@property(nonatomic,assign) NSInteger eventType; + +@property(nonatomic,weak) UIGestureRecognizer* gesture; + +-(id) init:(lua_State *)l gesture:(UIGestureRecognizer*) gesture; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + ++(LVEvent*) createLuaEvent:(lua_State *)L event:(UIEvent*) event gesture:(UIGestureRecognizer*) gesture; + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVEvent.m b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVEvent.m new file mode 100644 index 00000000..1e665a9c --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVEvent.m @@ -0,0 +1,229 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVEvent.h" + +@interface LVEvent () +@property(nonatomic,strong) NSArray * touches; +@property(nonatomic,assign) CGPoint point; +@property(nonatomic,strong) UITouch* touch; +@end + +@implementation LVEvent + +-(id) init:(lua_State *)l gesture:(UIGestureRecognizer*) gesture{ + self = [super init]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + self.gesture = gesture; + } + return self; +} + +-(void) setEvent:(UIEvent *)event{ + _event = event; + self.touches = event.allTouches.allObjects; + self.touch = self.touches.firstObject; + self.point = [self.touch locationInView:self.gesture.view]; +} + +-(id) lv_nativeObject{ + return self; +} + +static void releaseEventUserData(LVUserDataInfo* user){ + if( user && user->object ){ + LVEvent* lvEvent = CFBridgingRelease(user->object); + user->object = NULL; + if( lvEvent ){ + lvEvent.lv_userData = NULL; + lvEvent.lv_luaviewCore = nil; + lvEvent.event = nil; + lvEvent.touches = nil; + } + } +} + +static int lvEventGC (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + releaseEventUserData(user); + return 0; +} + +static int lvNewEvent (lua_State *L) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVEvent class]]; + + LVEvent* lvEvent = [[c alloc] init:L gesture:nil]; + + { + NEW_USERDATA(userData, Event); + userData->object = CFBridgingRetain(lvEvent); + lvEvent.lv_userData = userData; + + luaL_getmetatable(L, META_TABLE_Event ); + lua_setmetatable(L, -2); + } + return 1; +} + ++(LVEvent*) createLuaEvent:(lua_State *)L event:(UIEvent*) event gesture:(UIGestureRecognizer*) gesture{ + LVEvent* lvEvent = [[LVEvent alloc] init:L gesture:gesture]; + lvEvent.event = event; + { + NEW_USERDATA(userData, Event); + userData->object = CFBridgingRetain(lvEvent); + lvEvent.lv_userData = userData; + + luaL_getmetatable(L, META_TABLE_Event ); + lua_setmetatable(L, -2); + } + return lvEvent; +} + +static int nativeObj (lua_State *L) { + LVUserDataInfo * userData = (LVUserDataInfo *)lua_touserdata(L, 1); + if( userData ){ + LVEvent* lvEvent = (__bridge LVEvent *)(userData->object); + if( lvEvent ){ + id object = lvEvent.event; + lv_pushNativeObjectWithBox(L, object); + return 1; + } + } + return 0; +} + +static int action (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVEvent* lvEvent = (__bridge LVEvent *)(user->object); + if( lvEvent.eventType ) { + lua_pushnumber(L, lvEvent.eventType ); + } else { + UIEventType type = lvEvent.event.type; + lua_pushnumber(L, type ); + } + return 1; + } + return 0; +} + +static int pointer (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVEvent* lvEvent = (__bridge LVEvent *)(user->object); + CGPoint point = lvEvent.point; + NSDictionary* dic = @{ + @"x":@(point.x), + @"y":@(point.y) + }; + lv_pushNativeObject(L, dic ); + return 1; + } + return 0; +} + +static int x (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVEvent* lvEvent = (__bridge LVEvent *)(user->object); + CGPoint point = lvEvent.point; + lua_pushnumber(L, point.x ); + return 1; + } + return 0; +} + +static int y (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVEvent* lvEvent = (__bridge LVEvent *)(user->object); + CGPoint point = lvEvent.point; + lua_pushnumber(L, point.y ); + return 1; + } + return 0; +} + +static int event_id (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVEvent* lvEvent = (__bridge LVEvent *)(user->object); + lua_pushnumber(L, lvEvent.touch.timestamp ); + return 1; + } + return 0; +} + +static int __index (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + if ( lua_type(L, 2)==LUA_TSTRING ){ + lua_checkstack(L, 4); + lua_settop(L, 2); + luaL_getmetatable(L, META_TABLE_EventFunc ); + lua_pushvalue(L, 2); + lua_gettable(L, -2); + lua_remove(L, -2); + lua_remove(L, -2); + lua_CFunction cfunc = lua_tocfunction(L, -1); + if( cfunc ) { + lua_settop(L, 1); + return cfunc(L); + } + } + } + return 0; /* new userdatum is already on the stack */ +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewEvent globalName:globalName defaultName:@"Event"]; + + { + const struct luaL_Reg memberFunctions [] = { + {"__gc", lvEventGC }, + {"nativeObj", nativeObj}, + {"__index", __index }, + + {NULL, NULL} + }; + + lv_createClassMetaTable(L, META_TABLE_Event); + luaL_openlib(L, NULL, memberFunctions, 0); + } + { + + const struct luaL_Reg memberFunctions [] = { + {"id", event_id}, + {"action", action}, + {"pointer", pointer}, + {"x", x}, + {"y", y}, + {NULL, NULL} + }; + + lv_createClassMetaTable(L, META_TABLE_EventFunc); + luaL_openlib(L, NULL, memberFunctions, 0); + } + { + + NSDictionary* v = nil; + v = @{ + @"DOWN":@(LVTouchEventType_DOWN), + @"MOVE":@(LVTouchEventType_MOVE), + @"OUTSIDE":@(UIEventTypeRemoteControl), + @"PRESSES":@(UIEventTypePresses),// for IOS + @"UP":@(LVTouchEventType_UP), + @"CANCEL":@(LVTouchEventType_CANCEL), + }; + [LVUtil defineGlobal:@"TouchEvent" value:v L:L]; + } + return 0; +} + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVExGlobalFunc.h b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVExGlobalFunc.h new file mode 100644 index 00000000..b1e5feb6 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVExGlobalFunc.h @@ -0,0 +1,20 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import +#import "LVHeads.h" +#import "LView.h" + +@interface LVExGlobalFunc : NSObject + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + ++(void) registry:(lua_State*)L window:(UIView*)window; + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVExGlobalFunc.m b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVExGlobalFunc.m new file mode 100644 index 00000000..94018036 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVExGlobalFunc.m @@ -0,0 +1,187 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVExGlobalFunc.h" +#import "LVUtil.h" +#import "LVHeads.h" +#import "LVNativeObjBox.h" +#import "LVDebuger.h" + + +//------------------------------------------------------------------------ +@implementation LVExGlobalFunc + +static int lv_print (lua_State *L) { +#ifdef DEBUG + int n = lua_gettop(L); /* number of arguments */ + int i; + NSMutableString* buf = [[NSMutableString alloc] init]; + lua_getglobal(L, "tostring"); + for (i=1; i<=n; i++) { + const char *s = NULL; + lua_pushvalue(L, -1); /* function to be called */ + lua_pushvalue(L, i); /* value to print */ + lua_call(L, 1, 1); + s = lua_tostring(L, -1); /* get result */ + if (s == NULL) + return luaL_error(L, LUA_QL("tostring") " must return a string to " LUA_QL("print")); + if ( i>1 ) { + [buf appendString:@"\t"]; + } + NSString* str = [NSString stringWithUTF8String:s]; + [buf appendFormat:@"%@",str]; + lua_pop(L, 1); /* pop result */ + } + NSLog(@"%@",buf); + [buf appendString:@"\n"]; + lv_printToServer(L, buf.UTF8String, 0); +#endif + return 0; +} + +#pragma -mark registryApi +// 全局静态常量 和 静态方法 ++(void) registryStaticMethod:(lua_State *)L lView:(LuaViewCore *)lView{ + lv_defineGlobalFunc("print", lv_print, L); + + lv_defineGlobalFunc("loadJson", loadJson, L); + + lv_defineGlobalFunc("Unicode", unicode, L); + + // 替换pakcage.loaders中的loader_lv + lua_getglobal(L, LUA_LOADLIBNAME); + lua_getfield(L, 1, "loaders"); + if (!lua_istable(L, -1)) { + return; + } + + lua_pushnumber(L, 2); + lua_pushcfunction(L, loaderForLuaView); + lua_settable(L, -3); +} + +// 注册函数 ++(void) registryApi:(lua_State*)L lView:(LuaViewCore*)lView{ + + + return; +} + +// 注册系统对象 window ++(void) registry:(lua_State*)L window:(UIView*)window{ + NEW_USERDATA(userData, View); + userData->object = CFBridgingRetain(window); + window.lv_userData = userData; + window.lv_luaviewCore = LV_LUASTATE_VIEW(L); + userData->isWindow = 1; + + luaL_getmetatable(L, META_TABLE_LuaView ); + lua_setmetatable(L, -2); + + lua_setglobal(L, "window"); +} +//------------------------------------------------------------------------------------ + +static int loadJson (lua_State *L) { + NSString* json = lv_paramString(L, 1); + if( json ){ + json = [NSString stringWithFormat:@"return %@",json]; + luaL_loadstring(L, json.UTF8String); + if( lua_type(L, -1) == LUA_TFUNCTION ) { + int errorCode = lua_pcall( L, 0, 1, 0); + if( errorCode == 0 ){ + return 1; + } else { + LVError( @"loadJson : %s", lua_tostring(L, -1) ); + } + } else { + LVError( @"loadJson : %s", lua_tostring(L, -1) ); + } + } + return 0; /* number of results */ +} + +static int unicode(lua_State *L) { + int num = lua_gettop(L); + NSMutableString* buf = [[NSMutableString alloc] init]; + for( int i=1; i<=num; i++ ) { + if( lua_type(L, i) == LUA_TNUMBER ) { + unichar c = lua_tonumber(L, i); + [buf appendFormat:@"%C",c]; + } else { + break; + } + } + if( buf.length>0 ) { + lua_pushstring(L, buf.UTF8String); + return 1; + } + return 0; /* number of results */ +} + +static int loaderForLuaView (lua_State *L) { + static NSString *pathFormats[] = { @"%@.%@", @"%@/init.%@" }; + + NSString* moduleName = lv_paramString(L, 1); + if( moduleName ){ + // submodule + moduleName = [moduleName stringByReplacingOccurrencesOfString:@"." withString:@"/"]; + + LuaViewCore* lview = LV_LUASTATE_VIEW(L); + if( lview ) { + __block NSString *fullName = nil, *format = nil, *ext = nil; + BOOL(^findFile)() = ^BOOL() { // set fullName and return YES if found + NSString *name = [NSString stringWithFormat:format, moduleName, ext]; + + if( [lview.bundle scriptPathWithName:name] ) { + fullName = name; + return YES; + } else { + return NO; + } + }; + + for( int i = 0; i < sizeof(pathFormats) / sizeof(pathFormats[0]); ++i ) { + format = pathFormats[i]; + + if( lview.runInSignModel ) { + ext = LVScriptExts[LVSignedScriptExtIndex]; + if (findFile()) { + return [lview loadSignFile:fullName] == nil ? 1 : 0; + } + } + + ext = LVScriptExts[!LVSignedScriptExtIndex]; + if (findFile()) { + return [lview loadFile:fullName] == nil ? 1 : 0; + } + } + } + } + + // not found + return 0; +} + + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + LuaViewCore* lView = LV_LUASTATE_VIEW(L); + // 注册静态全局方法和常量 + [LVExGlobalFunc registryStaticMethod:L lView:lView]; + + //外链注册器 + [LVNativeObjBox lvClassDefine:L globalName:nil]; + // 调试 + [LVDebuger lvClassDefine:L globalName:nil]; + //清理栈 + lua_settop(L, 0); + return 0; +} + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVFile.h b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVFile.h new file mode 100644 index 00000000..3f1cc393 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVFile.h @@ -0,0 +1,15 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ +#import +#import "LVHeads.h" + +@interface LVFile : NSObject + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVFile.m b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVFile.m new file mode 100644 index 00000000..bcdee0d8 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVFile.m @@ -0,0 +1,151 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVFile.h" +#import "LVHeads.h" +#import "LVData.h" +#import "LView.h" +#import "LVHeads.h" + +@implementation LVFile + +static void saveCallback(lua_State *L, int callbackIndex, NSString* fileName, int errorInfo ) { + if( callbackIndex ) { + lua_checkstack32(L); + lua_pushboolean(L, errorInfo); + lua_pushvalue(L,callbackIndex); + lv_runFunctionWithArgs(L, 1, 0); + } +} + +static BOOL readCallback(lua_State *L, int callbackIndex, NSString* fileName, NSData* data) { + if( callbackIndex ) { + lua_checkstack32(L); + [LVData createDataObject:L data:data]; + lua_pushvalue(L,callbackIndex); + lv_runFunctionWithArgs(L, 1, 0); + return YES; + } + return NO; +} + +//参数顺序 +//File.save(name, data, callback) +//name: string +//data: string or data +//callback: function (optional) +static int file_save (lua_State *L) { + int num = lua_gettop(L); + if( num>=2 ) { + LVUserDataInfo * contentData = NULL; + NSString * contentString = nil; + NSString * fileName = nil; + int callbackIndex = 0; + for( int i=1; i<=num; i++ ) { + if (i == 1 && lua_type(L, i) == LUA_TSTRING){ + fileName = lv_paramString(L, i); + }else if (i == 2){ + if (lua_type(L, i) == LUA_TSTRING){ + contentString = lv_paramString(L, i); + }else if (lua_type(L, i) == LUA_TUSERDATA){ + contentData = (LVUserDataInfo *)lua_touserdata(L, i); + } + }else if (i == 3 && lua_type(L, i) == LUA_TFUNCTION){ + callbackIndex = i; + } + } + + NSData *content; + + if (contentData){ + LVData* lvData1 = (__bridge LVData *)(contentData->object); + if( LVIsType(contentData, Data) && lvData1.data){ + content = lvData1.data; + } + }else if (contentString){ + content = [contentString dataUsingEncoding:NSUTF8StringEncoding]; + } + + if ( fileName && content ) { + if( [LVUtil saveData:content toFile:[LVUtil PathForCachesResource:fileName]] ){ + saveCallback(L, callbackIndex, fileName, YES); + lua_pushboolean(L, 1); + return 1; + } else { + saveCallback(L, callbackIndex, fileName, NO); + } + } + } + lua_pushboolean(L, 0); + return 1; +} + +static int file_read(lua_State *L){ + int num = lua_gettop(L); + if( L && num>=1 ){ + NSString* fileName = nil; + int callbackIndex = 0; + for( int i=1; i<=num; i++ ) { + if( lua_type(L, i)==LUA_TSTRING && fileName==nil ) { + fileName = lv_paramString(L, i); + } + if( lua_type(L,i)==LUA_TFUNCTION ) { + callbackIndex = i; + } + } + if ( fileName ) { + LuaViewCore* lview = LV_LUASTATE_VIEW(L); + NSData* data = [lview.bundle resourceWithName:fileName]; + if( data ){ + if( readCallback(L, callbackIndex, fileName, data) ){ + } else { + [LVData createDataObject:L data:data]; + } + return 1; + } else { + readCallback(L, callbackIndex, fileName, nil); + } + } + } + return 0; +} + +static int file_exist(lua_State *L){ + if( L && lua_gettop(L)>=1 ){ + NSString* fileName = lv_paramString(L, -1); + LuaViewCore* lview = LV_LUASTATE_VIEW(L); + if( [lview.bundle resourcePathWithName:fileName] ){ + lua_pushboolean(L, 1); + return 1; + } + } + lua_pushboolean(L, 0); + return 1; +} + +static int file_path (lua_State *L) { + NSString* fileName = lv_paramString(L, -1); + LuaViewCore* lview = LV_LUASTATE_VIEW(L); + NSString* path = [lview.bundle resourcePathWithName:fileName]; + lua_pushstring(L, path.UTF8String); + return 1; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + const struct luaL_Reg function [] = { + {"save", file_save}, + {"read", file_read}, + {"exist", file_exist}, + {"path", file_path}, + {NULL, NULL} + }; + luaL_openlib(L, "File", function, 0); + return 0; +} + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVFlowLayout.h b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVFlowLayout.h new file mode 100644 index 00000000..90f06ef5 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVFlowLayout.h @@ -0,0 +1,19 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import + +@interface LVFlowLayout : UICollectionViewFlowLayout + +-(void) resetPinnedDic; +-(void) addPinnedIndexPath:(NSIndexPath*)indexPath; +-(void) delPinnedIndexPath:(NSIndexPath*)indexPath; +-(BOOL) isPinned:(NSIndexPath*)indexPath; +-(BOOL) pinnedDicIsNil; + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVFlowLayout.m b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVFlowLayout.m new file mode 100644 index 00000000..43fb603e --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVFlowLayout.m @@ -0,0 +1,111 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVFlowLayout.h" + +@interface LVFlowLayout () +@property(nonatomic, strong) NSMutableDictionary* pinnedDic; +@end + +@implementation LVFlowLayout + +-(id)init +{ + self = [super init]; + if ( self ){ + } + return self; +} + +- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect +{ + NSMutableArray *superLayoutAttArray = [[super layoutAttributesForElementsInRect:rect] mutableCopy]; + NSArray* keys = self.pinnedDic.allKeys; + // 排序 + keys = [keys sortedArrayUsingComparator:^NSComparisonResult(NSIndexPath* obj1, NSIndexPath* obj2) { + return [obj1 compare:obj2]; + }]; + + UICollectionViewLayoutAttributes* prevAtt = nil; + NSInteger pinnedTimes = 0; + for( NSInteger i=((NSInteger)keys.count)-1; i>=0; i-- ) { + NSIndexPath* indexPath = keys[i]; + UICollectionViewLayoutAttributes* a = [self layoutAttributesForItemAtIndexPath:indexPath]; + if( a ) { + CGRect frame = a.frame; + CGFloat minY = self.collectionView.contentOffset.y; + // 浮层:不能小于屏幕offset + if( frame.origin.y < minY ) { + frame.origin.y = minY; + a.frame = frame; + a.zIndex = 10 + i; + pinnedTimes ++; + + if( prevAtt ) { + // 但是浮层不能盖住上一个浮层 + CGFloat maxY = prevAtt.frame.origin.y - frame.size.height; + if( frame.origin.y>maxY ) { + frame.origin.y = maxY; + a.frame = frame; + a.zIndex = 10 + i; + } + } + } + [superLayoutAttArray addObject:a]; + prevAtt = a; + if( pinnedTimes > 1 ) { + // 这两行一定要有!!!!原因还有待确认@城西 + a.alpha = 0; + a.zIndex = -1; + break; + } else { + a.alpha = 1; + } + } + } + return superLayoutAttArray; +} + +-(BOOL) shouldInvalidateLayoutForBoundsChange:(CGRect)newBound +{ + return self.pinnedDic!=nil; +} + +-(void) resetPinnedDic{ + self.pinnedDic = [[NSMutableDictionary alloc] initWithCapacity:8]; +} + +-(void) addPinnedIndexPath:(NSIndexPath*)indexPath { + if( indexPath ) { + if( self.pinnedDic==nil ) { + [self resetPinnedDic]; + } + self.pinnedDic[indexPath] = @(YES); + } +} + +-(void) delPinnedIndexPath:(NSIndexPath*)indexPath{ + if( indexPath ) { + [self.pinnedDic removeObjectForKey:indexPath]; + } +} + +-(BOOL) isPinned:(NSIndexPath*)indexPath{ + if( indexPath ) { + return (self.pinnedDic[indexPath]!=nil); + } + return NO; +} + +-(BOOL) pinnedDicIsNil{ + return self.pinnedDic==nil; +} + +@end + + diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVGesture.h b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVGesture.h new file mode 100644 index 00000000..020aa3cf --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVGesture.h @@ -0,0 +1,33 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" +#import "NSObject+LuaView.h" + +@class LVGesture; + +typedef void(^LVGestureOnTouchEventCallback)(LVGesture* gesture, int argN); + +@interface LVGesture : UIGestureRecognizer + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; + +@property(nonatomic,copy) LVGestureOnTouchEventCallback onTouchEventCallback; + +-(id) init:(lua_State*) l; + ++(const luaL_Reg*) baseMemberFunctions; + ++(void) releaseUD:(LVUserDataInfo *) user; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVGesture.m b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVGesture.m new file mode 100644 index 00000000..76f1eee1 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVGesture.m @@ -0,0 +1,228 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVGesture.h" +#import "LView.h" +#import +#import "LVEvent.h" +#import "LVHeads.h" + +@implementation LVGesture + +-(id) init:(lua_State*) l{ + self = [super initWithTarget:self action:@selector(handleGesture:)]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + self.delegate = self; + } + return self; +} + +-(void) handleGesture:(LVGesture*)sender { + [self handleGesture:sender event:nil eventType:0]; +} + +-(void) handleGesture:(LVGesture*)sender event:(UIEvent*) event eventType:(NSInteger) eventType{ + lua_State* l = self.lv_luaviewCore.l; + if ( l ){ + lua_settop(l, 0); + lua_checkstack32(l); + + if( self.onTouchEventCallback ) { + LVEvent* lvEvent = nil; + lvEvent = [LVEvent createLuaEvent:l event:event gesture:self]; + lvEvent.eventType = eventType; + self.onTouchEventCallback(self,1); + lvEvent.event = nil; + } else { + lv_pushUserdata(l,self.lv_userData); + } + [LVUtil call:l lightUserData:self key1:"callback" key2:NULL nargs:1]; + } +} + +- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ + [super touchesBegan:touches withEvent:event]; + [self handleGesture:self event:event eventType:LVTouchEventType_DOWN]; +} + +- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{ + [super touchesMoved:touches withEvent:event]; + [self handleGesture:self event:event eventType:LVTouchEventType_MOVE]; +} + +- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{ + [super touchesEnded:touches withEvent:event]; + [self handleGesture:self event:event eventType:LVTouchEventType_MOVE]; + [self handleGesture:self event:event eventType:LVTouchEventType_UP]; + +} + +- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{ + [super touchesCancelled:touches withEvent:event]; + [self handleGesture:self event:event eventType:LVTouchEventType_CANCEL]; +} + + +static void releaseUserData(LVUserDataInfo * user){ + if( user && user->object ){ + UIGestureRecognizer* gesture = CFBridgingRelease(user->object); + user->object = NULL; + if( gesture ){ + gesture.lv_luaviewCore = nil; + gesture.lv_userData = NULL; + } + } +} + +static int __GC (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + releaseUserData(user); + return 0; +} + + +static int __tostring (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIGestureRecognizer* gesture = (__bridge UIGestureRecognizer *)(user->object); + NSString* s = [NSString stringWithFormat:@"LVUserDataGesture: %@", gesture ]; + lua_pushstring(L, s.UTF8String); + return 1; + } + return 0; +} + +static int location (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIGestureRecognizer* gesture = (__bridge UIGestureRecognizer *)(user->object); + CGPoint p = [gesture locationInView:gesture.view]; + lua_pushnumber(L, p.x); + lua_pushnumber(L, p.y); + return 2; + } + return 0; +} + +static int state (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIGestureRecognizer* gesture = (__bridge UIGestureRecognizer *)(user->object); + NSInteger state = gesture.state; + lua_pushnumber(L, state); + return 1; + } + return 0; +} + +static int nativeGesture (lua_State *L) { + LVUserDataInfo * userData = (LVUserDataInfo *)lua_touserdata(L, 1); + if( userData ){ + UIGestureRecognizer* gesture = (__bridge UIGestureRecognizer *)(userData->object); + if( gesture && [gesture isKindOfClass:[UIGestureRecognizer class]] ){ + lv_pushNativeObjectWithBox(L, gesture); + return 1; + } + } + return 0; +} + +static const struct luaL_Reg baseMemberFunctions [] = { + {"nativeGesture", nativeGesture }, + + {"location", location }, + {"state", state }, + {"__gc", __GC }, + {"__tostring", __tostring }, + {NULL, NULL} +}; + ++(const luaL_Reg*) baseMemberFunctions{ + return baseMemberFunctions; +} + ++(void) releaseUD:(LVUserDataInfo *) user{ + releaseUserData(user); +} + +static int lvNewGesture (lua_State *L) { + { + Class c = [LVUtil upvalueClass:L defaultClass:[LVGesture class]]; + + LVGesture* gesture = [[c alloc] init:L]; + + if( lua_type(L, 1) != LUA_TNIL ) { + [LVUtil registryValue:L key:gesture stack:1]; + } + + { + NEW_USERDATA(userData, Gesture); + gesture.lv_userData = userData; + userData->object = CFBridgingRetain(gesture); + + luaL_getmetatable(L, META_TABLE_Gesture ); + lua_setmetatable(L, -2); + } + } + return 1; /* new userdatum is already on the stack */ +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + + [LVUtil reg:L clas:self cfunc:lvNewGesture globalName:globalName defaultName:@"Gesture"]; + + lv_createClassMetaTable(L, META_TABLE_Gesture); + + luaL_openlib(L, NULL, [LVGesture baseMemberFunctions], 0); + lua_settop(L, 0); + { + NSDictionary* v = nil; + v = @{ + @"POSSIBLE":@(UIGestureRecognizerStatePossible), + @"BEGIN":@(UIGestureRecognizerStateBegan), + @"CHANGED":@(UIGestureRecognizerStateChanged), + @"END":@(UIGestureRecognizerStateEnded), + @"CANCEL":@(UIGestureRecognizerStateCancelled), + @"FAILED":@(UIGestureRecognizerStateFailed), + }; + [LVUtil defineGlobal:@"GestureState" value:v L:L]; + } + + return 0; +} + +// delegate + +- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{ + if( gestureRecognizer ==self ) { + return YES; + } + return NO; +} + +- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{ + return YES; +} + +- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{ + if( gestureRecognizer ==self ) { + return YES; + } + return NO; +} + +- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceivePress:(UIPress *)press{ + if( gestureRecognizer ==self ) { + return YES; + } + return NO; +} + + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVHeads.h b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVHeads.h new file mode 100644 index 00000000..a2591a42 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVHeads.h @@ -0,0 +1,240 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#ifndef JU_LVHeads_h +#define JU_LVHeads_h +//-------------------------------------------------------------------------------- + +#import + +#import "lua.h" +#import "lauxlib.h" +#import "lualib.h" +#import "lstate.h" +#import "lgc.h" +#import "lapi.h" + +/** + * the index of signed scripts' extionsion(@"lv") in LVScriptExts[] + */ +extern const int LVSignedScriptExtIndex; + +/** + * supported script extensions: { @"lv", @"lua" } + */ +extern NSString * const LVScriptExts[2]; + +#import "LVUtil.h" +//-------------------------------------------------------------------------------- +#define LV_ALIGN_LEFT (1) +#define LV_ALIGN_H_CENTER (2) +#define LV_ALIGN_RIGHT (4) + +#define LV_ALIGN_TOP (8) +#define LV_ALIGN_V_CENTER (16) +#define LV_ALIGN_BOTTOM (32) + +//------------------------------ +#define LVReleaseAndNull( a ) if(a) { CFRelease(a); a = NULL; } +//------------------------------ + + +#define USERDATA_KEY_DELEGATE 1 +#define USERDATA_KEY_CALLBACK 2 +#define USERDATA_FLEX_DELEGATE 8 + +//---------------创建用户数据------------------------------------------------------- +#define NEW_USERDATA(var, typeName) \ + LVUserDataInfo* var = ( (LVUserDataInfo*)lua_newuserdata( L, sizeof(LVUserDataInfo)) ); \ + lv_createUDataLuatable(L,-1);\ + var->type = LVType_##typeName; \ + var->isWindow = 0; \ +// + + +//----------------用户数据的类型检查-----i-------------------------------------------- +#define LVIsType( user,T) (user && user->type==LVType_##T) + +//----------------用户数据类型 ID--------------------------------------------------- + +extern const char* LVType_View; +extern const char* LVType_Data; +extern const char* LVType_Date; +extern const char* LVType_Http; +extern const char* LVType_Timer; +extern const char* LVType_Transform3D; +extern const char* LVType_Animator; +extern const char* LVType_Gesture; +extern const char* LVType_Downloader; +extern const char* LVType_AudioPlayer; +extern const char* LVType_StyledString; +extern const char* LVType_NativeObject; +extern const char* LVType_Struct; +extern const char* LVType_Canvas; +extern const char* LVType_Event; +extern const char* LVType_Bitmap; + + +//----------------View的用户数据结构------------------------------------------------ +typedef struct _LVUserDataInfo { + const char* type;// 用户类型 + const void* object;// 真实的用户对象 + int isWindow; +} LVUserDataInfo; + +//-------------------------------------------------------------------------------- +/* + * 确保所有在luaview扩展类的实例对象都包含有这些基本的属性和方法, 是所有LuaView扩展类的实例对象的通用协议 + */ +@class LuaViewCore; +@protocol LVProtocal + +@required +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; + +@optional +- (id) lv_nativeObject; // 返回native对象 + +@end + +/* + * luaview所有扩展类的桥接协议: 只是一个静态协议, luaview统一调用该接口加载luaview扩展的类 + */ +@protocol LVClassProtocal +@required ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +@end + + +//-----------------------metatable------------------------------------------------ +#define META_TABLE_UIButton "UI.Button" +#define META_TABLE_UIScrollView "UI.ScrollView" +#define META_TABLE_UIView "UI.View" +#define META_TABLE_LuaView "UI.LuaView" +#define META_TABLE_CustomPanel "UI.CustomPanel" +#define META_TABLE_CustomView "UI.CustomView" +#define META_TABLE_Canvas "UI.Canvas" +#define META_TABLE_Event "UI.Event" +#define META_TABLE_EventFunc "UI.EventFunc" +#define META_TABLE_UIViewNewIndex "UI.View.NewIndex" +#define META_TABLE_PagerIndicator "UI.PagerIndicator" +#define META_TABLE_LoadingIndicator "UI.LoadingIndicator" +#define META_TABLE_UIImageView "UI.ImageView" +#define META_TABLE_Bitmap "UI.Bitmap" +#define META_TABLE_UIWebView "UI.WebView" +#define META_TABLE_UILabel "UI.Label" +#define META_TABLE_UITextField "UI.TextField" +#define META_TABLE_UITableView "UI.TableView" +#define META_TABLE_UITableViewCell "UI.TableView.Cell" +#define META_TABLE_UICollectionView "UI.CollectionView" +#define META_TABLE_UICollectionViewCell "UI.CollectionView.Cell" +#define META_TABLE_UIPageView "UI.PagerView" +#define META_TABLE_UIAlertView "UI.AlertView" +#define META_TABLE_Transform3D "UI.Transfrom3D" +#define META_TABLE_Animator "UI.Animator" +#define META_TABLE_Camera "UI.CameraView" + +#define META_TABLE_Timer "LV.Timer" +#define META_TABLE_Http "LV.Http" +#define META_TABLE_Gesture "LV.Gesture" +#define META_TABLE_PanGesture "LV.Pan.Gesturer" +#define META_TABLE_TapGesture "LV.Tap.Gesture" +#define META_TABLE_PinchGesture "LV.Pinch.Gesture" +#define META_TABLE_RotaionGesture "LV.Rotaion.Gesture" +#define META_TABLE_SwipeGesture "LV.Swipe.Gesture" +#define META_TABLE_LongPressGesture "LV.LongPress.Gesture" +#define META_TABLE_Date "LV.Date" +#define META_TABLE_Data "LV.Data" +#define META_TABLE_Struct "LV.Struct" +#define META_TABLE_Downloader "LV.Downloader" +#define META_TABLE_AudioPlayer "LV.AudioPlayer" +#define META_TABLE_AttributedString "LV.AttributedString" +#define META_TABLE_NativeObject "LV.nativeObjBox" +#define META_TABLE_System "LV.System" + +#define STR_CALLBACK "Callback" +#define STR_ON_LAYOUT "onLayout" +#define STR_ON_CLICK "onClick" +#define STR_ON_DRAW "onDraw" +#define STR_ON_TOUCH "onTouch" +#define STR_ON_SHOW "onShow" +#define STR_ON_HIDE "onHide" +#define STR_onPageStarted "onPageStarted" +#define STR_onPageFinished "onPageFinished" +#define STR_onReceivedError "onReceivedError" + +// lua对象 -> NSString +NSString* lv_paramString(lua_State* L, int idx ); + +// run +NSString* lv_runFunction(lua_State* l); +NSString* lv_runFunctionWithArgs(lua_State* l, int nargs, int nret); + + + +//-------------------------------------------------------------------------------- +@interface LVHeads : NSObject +@end + + +typedef enum:int{ + LVTypeID_NONE = 0, + LVTypeID_void, + LVTypeID_BOOL, + LVTypeID_bool, + LVTypeID_char, + LVTypeID_unsignedchar, + LVTypeID_short, + LVTypeID_unsignedshort, + LVTypeID_int, + LVTypeID_unsignedint, + LVTypeID_NSInteger, + LVTypeID_NSUInteger, + LVTypeID_longlong, + LVTypeID_unsigedlonglong, + LVTypeID_float, + LVTypeID_CGFloat, + LVTypeID_double, + LVTypeID_charP, + LVTypeID_voidP, + LVTypeID_id, + LVTypeID_Class, + LVTypeID_idP, + LVTypeID_struct, +}LVTypeIDEnum; + + +LVTypeIDEnum lua_typeID(const char* type); + +#define isNormalRect(r) ( !( isnan(r.origin.x) || isnan(r.origin.y) || isnan(r.size.width) || isnan(r.size.height) ) ) +#define isNormalSize(s) ( !( isnan(s.width) || isnan(s.height) ) ) +#define isNormalPoint(p) ( !( isnan(p.x) || isnan(p.y) ) ) +#define isNormalEdgeInsets(e) ( !( isnan(e.top) || isnan(e.left) || isnan(e.bottom) || isnan(e.right) ) ) + + +typedef void(^LVLoadFinished)(id errorInfo); + +#import "UIView+LuaView.h" +#import "NSObject+LuaView.h" +#import "UIScrollView+LuaView.h" +#import "LVBundle.h" + +#define EFFECT_NONE 0 +#define EFFECT_CLICK 1 +#define EFFECT_PARALLAX 2 + +#define LV_LUASTATE_VIEW(L) ( (__bridge LuaViewCore *)( G(L)->ud ) ) +#define LUAVIEW_SYS_TABLE_KEY "..::luaview::.." + +#ifndef MakeSureNotNil +#define MakeSureNotNil(__obj) ((__obj) ? (__obj) : @"") +#endif + +#endif diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVHeads.m b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVHeads.m new file mode 100644 index 00000000..d6d80578 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVHeads.m @@ -0,0 +1,34 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVHeads.h" + + +@implementation LVHeads + +NSString * const LVScriptExts[] = {@"lv", @"lua"}; +const int LVSignedScriptExtIndex = 0; + +const char* LVType_View = "LVType_UserDataView"; +const char* LVType_Data = "LVType_UserDataData"; +const char* LVType_Date = "LVType_UserDataDate"; +const char* LVType_Http = "LVType_UserDataHttp"; +const char* LVType_Timer = "LVType_UserDataTimer"; +const char* LVType_Transform3D = "LVType_UserDataTransform3D"; +const char* LVType_Animator = "LVType_UserDataAnimator"; +const char* LVType_Gesture = "LVType_UserDataGesture"; +const char* LVType_Downloader = "LVType_UserDataDownloader"; +const char* LVType_AudioPlayer = "LVType_UserDataAudioPlayer"; +const char* LVType_StyledString = "LVType_UserDataStyledString"; +const char* LVType_NativeObject = "LVType_UserDataNativeObject"; +const char* LVType_Struct = "LVType_UserDataStruct"; +const char* LVType_Canvas = "LVType_UserDataCanvas"; +const char* LVType_Event = "LVType_UserDataEvent"; +const char* LVType_Bitmap = "LVType_UserDataBitmap"; + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVHttp.h b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVHttp.h new file mode 100644 index 00000000..8abfe042 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVHttp.h @@ -0,0 +1,27 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + + +@interface LVHttp : NSObject + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; + +-(id) init:(lua_State*) l; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +/* + * https检查是否是信任的域名, 改方法 可以被覆盖 + */ ++(BOOL) isTrustedHost:(NSString*) host; + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVHttp.m b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVHttp.m new file mode 100644 index 00000000..40f79e8a --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVHttp.m @@ -0,0 +1,323 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVHttp.h" +#import "LVHttpResponse.h" +#import "LVData.h" +#import "LView.h" +#import "LVHeads.h" + +@interface LVHttp () +@property(nonatomic,strong) id mySelf; +@property(nonatomic,strong) LVHttpResponse* response; +@property(nonatomic,strong) id function; +@property(nonatomic,assign) CGFloat timeout; +@property(nonatomic,strong) NSURLConnection* connection; +@end + +@implementation LVHttp + +static void releaseUserDataHttp(LVUserDataInfo* user){ + if( user && user->object ){ + LVHttp* http = CFBridgingRelease(user->object); + user->object = NULL; + if( http ){ + http.lv_userData = NULL; + http.lv_luaviewCore = nil; + http.mySelf = nil; + } + } +} + +-(void) dealloc{ +} + +-(id) init:(lua_State*) l{ + self = [super init]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + self.mySelf = self; + self.function = [[NSMutableString alloc] init]; + self.response = [[LVHttpResponse alloc] init]; + self.timeout = 30.0; + } + return self; +} + +-(void) requesetEndToDo{ + lua_State* l = self.lv_luaviewCore.l; + if( l ){ + lua_checkstack32(l); + [LVUtil pushRegistryValue:l key:self]; + [LVUtil call:l lightUserData:self.function key1:"callback" key2:NULL nargs:1]; + [LVUtil unregistry:l key:self]; + } + self.response = nil; + self.mySelf = nil; +} + +- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace { + return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]; +} + + ++(BOOL) isTrustedHost:(NSString*) host{ + NSArray* trustedHosts = @[@".alicdn.com",@".tbcdn.com",@".taobao.com",@".tmall.com",@".juhuasuan.com"]; + for( NSString* host in trustedHosts ) { + if( [host hasSuffix:host] ) { + return YES; + } + } + return NO; +} + +- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge { + if ( [challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust] ){ + if ( [LVHttp isTrustedHost:challenge.protectionSpace.host] ) { + [challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge]; + } + } + [challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge]; +} + +-(void) connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{ + self.response.error = error; + [self performSelectorOnMainThread:@selector(requesetEndToDo) withObject:nil waitUntilDone:NO]; +} + +-(void) connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{ + if( self.response.data == nil ) { + self.response.data = [[NSMutableData alloc] init]; + } + [self.response.data appendData:data]; +} + +-(void) connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{ + self.response.response = response; + if( [response isKindOfClass:[NSHTTPURLResponse class]] ){ + self.response.httpResponse = (NSHTTPURLResponse*)response; + } +} +-(void) connectionDidFinishLoading:(NSURLConnection *)connection{ + [self performSelectorOnMainThread:@selector(requesetEndToDo) withObject:nil waitUntilDone:NO]; +} + +-(void) connectionDidReceiveData:(NSData *)data{ + if( self.response.data == nil ) { + self.response.data = [[NSMutableData alloc] init]; + } + [self.response.data appendData:data]; +} + +-(void) connectionDidReceiveResponse:(NSURLResponse *)response{ + self.response.response = response; + if( [response isKindOfClass:[NSHTTPURLResponse class]] ){ + self.response.httpResponse = (NSHTTPURLResponse*)response; + } +} +-(void) connectionDidFinishLoading{ + [self performSelectorOnMainThread:@selector(requesetEndToDo) withObject:nil waitUntilDone:NO]; +} + +-(id) lv_nativeObject{ + return self; +} + +static int lvNewHttpObject (lua_State *L ) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVHttp class]]; + + LVHttp* http = [[c alloc] init:L]; + { + NEW_USERDATA(userData, Http); + userData->object = CFBridgingRetain(http); + http.lv_userData = userData; + + luaL_getmetatable(L, META_TABLE_Http ); + lua_setmetatable(L, -2); + } + [LVUtil registryValue:L key:http stack:-1]; + return 1; +} + +static int get (lua_State *L) { + int argN = lua_gettop(L); + if( argN>=2 ){ + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( LVIsType(user, Http) ) { + LVHttp* http = (__bridge LVHttp *)(user->object); + NSString* urlStr = lv_paramString(L, 2); + + if( lua_type(L, 3) != LUA_TNIL ) { + [LVUtil registryValue:L key:http.function stack:3]; + } + NSURL *url = [NSURL URLWithString:urlStr]; + NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; + [request setHTTPMethod:@"GET"]; + [request setTimeoutInterval:http.timeout]; + + NSOperationQueue *queue = [[NSOperationQueue alloc]init]; + __weak LVHttp* weakHttp = http; + [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) { + [weakHttp connectionDidReceiveResponse:response]; + [weakHttp connectionDidReceiveData:data]; + [weakHttp connectionDidFinishLoading]; + }]; + } + } + return 0; /* new userdatum is already on the stack */ +} + +static int post (lua_State *L) { + int argN = lua_gettop(L); + if( argN>=3 ){ + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( LVIsType(user, Http) ) { + // 1:url 2:heads 3:data 4:callback + NSString* urlStr = lv_paramString(L, 2); + LVHttp* http = (__bridge LVHttp *)(user->object); + NSDictionary* dic = nil; + NSData* data = nil; + for( int i=3 ; i<=argN ; i++ ) { + int type = lua_type(L, i); + if( type==LUA_TSTRING ) {// 数据 + NSString* s = lv_paramString(L, i); + data = [s dataUsingEncoding:NSUTF8StringEncoding]; + } + if( type==LUA_TTABLE ) {// 数据 + id tempDic = lv_luaTableToDictionary(L, i); + NSString* s = [LVUtil objectToString:tempDic]; + data = [s dataUsingEncoding:NSUTF8StringEncoding]; + } + + if( type==LUA_TFUNCTION ) { + [LVUtil registryValue:L key:http.function stack:4]; + } + } + NSURL *url = [NSURL URLWithString:urlStr]; + NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; + [request setHTTPMethod:@"POST"]; + [request setTimeoutInterval:http.timeout]; + + // http头信息 + if( dic.count>0 ){ + for (NSString *key in dic) { + NSString* value = dic[key]; + [request setValue:value forHTTPHeaderField:key]; + } + } + + // data + if( data.length>0 ){ + [request setHTTPBody:data]; + } + + NSOperationQueue *queue = [[NSOperationQueue alloc]init]; + __weak LVHttp* weakHttp = http; + [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) { + [weakHttp connectionDidReceiveResponse:response]; + [weakHttp connectionDidReceiveData:data]; + [weakHttp connectionDidFinishLoading]; + }]; + } + } + return 0; /* new userdatum is already on the stack */ +} + +static int __gc (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + releaseUserDataHttp(user); + return 0; +} + +static int __tostring (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user && LVIsType(user, Http) ){ + LVHttp* http = (__bridge LVHttp *)(user->object); + NSString* s = [NSString stringWithFormat:@"LVUserDataHttp: %@\n response.data.length=%ld\n error:%@", + http.response.response, + (long)http.response.data.length, + http.response.error ]; + lua_pushstring(L, s.UTF8String); + return 1; + } + return 0; +} + +static int data (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user && LVIsType(user, Http) ){ + LVHttp* http = (__bridge LVHttp *)(user->object); + // NSString* s = [NSString stringWithFormat:@"LVUserDataHttp: %@\n response.data.length=%ld\n error:%@", + // http.response.response, + // http.response.data.length, + // http.response.error ]; + return [LVData createDataObject:L data:http.response.data]; + } + return 0; +} +static int responseStatusCode (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user && LVIsType(user, Http) ){ + LVHttp* http = (__bridge LVHttp *)(user->object); + NSHTTPURLResponse* httpResponse = http.response.httpResponse; + lua_pushnumber(L, httpResponse.statusCode); + return 1; + } + return 0; +} +static int responseHeaderFields (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user && LVIsType(user, Http) ){ + LVHttp* http = (__bridge LVHttp *)(user->object); + NSHTTPURLResponse* response = http.response.httpResponse; + lv_pushNativeObject(L,response.allHeaderFields); + return 1; + } + return 0; +} +static int cancel (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user && LVIsType(user, Http) ){ + LVHttp* http = (__bridge LVHttp *)(user->object); + [http.connection cancel]; + return 0; + } + return 0; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + { + const struct luaL_Reg memberFunctions [] = { + {"__gc", __gc }, + + {"__tostring", __tostring }, + + {"data", data }, + {"code", responseStatusCode }, + {"header", responseHeaderFields }, + // IOS: meesage 服务端错误信息 + // timeout + // retryTimes + + {"get", get }, + {"post", post }, + + {"cancel", cancel }, + + {NULL, NULL} + }; + + lv_createClassMetaTable(L, META_TABLE_Http); + + luaL_openlib(L, NULL, memberFunctions, 0); + } + [LVUtil reg:L clas:self cfunc:lvNewHttpObject globalName:globalName defaultName:@"Http"]; + return 1; +} + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVHttpResponse.h b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVHttpResponse.h new file mode 100644 index 00000000..0bc65809 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVHttpResponse.h @@ -0,0 +1,18 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import + +@interface LVHttpResponse : NSObject + +@property(nonatomic,strong) NSURLResponse *response; +@property(nonatomic,strong) NSHTTPURLResponse *httpResponse; +@property(nonatomic,strong) NSMutableData *data; +@property(nonatomic,strong) NSError *error; + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVHttpResponse.m b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVHttpResponse.m new file mode 100644 index 00000000..8fffcb9e --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVHttpResponse.m @@ -0,0 +1,13 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVHttpResponse.h" + +@implementation LVHttpResponse + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVImage.h b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVImage.h new file mode 100644 index 00000000..5f647a64 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVImage.h @@ -0,0 +1,44 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" +#import "LView.h" + + +@interface LVImage : UIImageView + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; +@property(nonatomic,assign) NSUInteger lv_align; +@property(nonatomic,strong) CAShapeLayer* lv_shapeLayer; + +-(id) init:(lua_State*) l; + +-(void) setImageByName:(NSString*) imageName; +-(void) setImageByData:(NSData*) data; +-(void) setWebImageUrl:(NSURL*) url finished:(LVLoadFinished) finished; +-(void) effectParallax:(CGFloat)dx dy:(CGFloat)dy ; +-(void) effectClick:(NSInteger)color alpha:(CGFloat)alpha; + +/* + * Lua 脚本回调 + */ +-(void) callLuaDelegate:(id) obj; + +/** + * 图片首次出现是否使用动画 + */ +@property (nonatomic,assign) BOOL disableAnimate; + +/* + * luaview所有扩展类的桥接协议: 只是一个静态协议, luaview统一调用该接口加载luaview扩展的类 + */ ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVImage.m b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVImage.m new file mode 100644 index 00000000..736b6e5b --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVImage.m @@ -0,0 +1,299 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVImage.h" +#import "LVBaseView.h" +#import "LVUtil.h" +#import "LVData.h" +#import +#import "LVNinePatchImage.h" +#import "LVHeads.h" +#import "LVBitmap.h" + +@interface LVImage () +@property (nonatomic,strong) id functionTag; +@property (nonatomic,assign) BOOL needCallLuaFunc; +@property (nonatomic,strong) id errorInfo; +@property (nonatomic,strong) UITapGestureRecognizer* tapGesture; +@property(nonatomic,assign) BOOL lv_isCallbackAddClickGesture;// 支持Callback 点击事件 +@end + +@implementation LVImage + + +-(id) init:(lua_State*) l{ + self = [super init]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + self.contentMode = UIViewContentModeScaleAspectFill; + self.functionTag = [[NSMutableString alloc] init]; + self.backgroundColor = [UIColor clearColor]; + self.clipsToBounds = YES; + self.lv_isCallbackAddClickGesture = YES; + self.disableAnimate = self.lv_luaviewCore.disableAnimate; + } + return self; +} + +-(void) setWebImageUrl:(NSURL*) url finished:(LVLoadFinished) finished{ +} + +-(void) callLuaDelegate:(id) obj{ + lua_State* L = self.lv_luaviewCore.l; + if( L ) { + lua_checkstack(L, 4); + lua_pushboolean(L, obj?0:1); + [LVUtil pushRegistryValue:L key:self.functionTag]; + lv_runFunctionWithArgs(L, 1, 0); + } + [LVUtil unregistry:L key:self.functionTag]; +} + +-(void) setImageByName:(NSString*) imageName{ + if( imageName==nil ) + return; + + if( [LVUtil isExternalUrl:imageName] ){ + //CDN image + __weak LVImage* weakImageView = self; + [self setWebImageUrl:[NSURL URLWithString:imageName] finished:^(id errorInfo){ + if( weakImageView.needCallLuaFunc ) { + weakImageView.errorInfo = errorInfo; + [weakImageView performSelectorOnMainThread:@selector(callLuaDelegate:) withObject:errorInfo waitUntilDone:NO]; + } + }]; + } else { + // local Image + UIImage* image = [self.lv_luaviewCore.bundle imageWithName:imageName]; + if ( [LVNinePatchImage isNinePathImageName:imageName] ) { + image = [LVNinePatchImage createNinePatchImage:image]; + [self setImage:image]; + } else { + [self setImage:image]; + } + } +} + +-(void) lv_effectParallax:(CGFloat)dx dy:(CGFloat)dy{ + [self effectParallax:dx dy:dy]; +} + +-(void) effectParallax:(CGFloat)dx dy:(CGFloat)dy { +} + +-(void) effectClick:(NSInteger)color alpha:(CGFloat)alpha { +} + +-(void) setImageByData:(NSData*) data{ + if ( data ) { + UIImage* image = [[UIImage alloc] initWithData:data]; + [self setImage:image]; + } +} + +-(void) canelWebImageLoading{ + // [self cancelCurrentImageLoad]; // 取消上一次CDN加载 +} +-(void) cancelImageLoadAndClearCallback:(lua_State*)L{ + [self canelWebImageLoading]; + [NSObject cancelPreviousPerformRequestsWithTarget:self]; // 取消回调脚本 + [LVUtil unregistry:L key:self.functionTag]; // 清除脚本回调 +} + +-(void) dealloc{ + LVUserDataInfo* userData = self.lv_userData; + if( userData ){ + userData->object = NULL; + } +} + +#pragma -mark ImageView +static int lvNewImageView(lua_State *L) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVImage class]]; + + NSString* imageName = lv_paramString(L, 1); + + LVImage* imageView = [[c alloc] init:L]; + [imageView setImageByName:imageName]; + { + NEW_USERDATA(userData, View); + userData->object = CFBridgingRetain(imageView); + imageView.lv_userData = userData; + + luaL_getmetatable(L, META_TABLE_UIImageView ); + lua_setmetatable(L, -2); + } + LuaViewCore* view = LV_LUASTATE_VIEW(L); + if( view ){ + [view containerAddSubview:imageView]; + } + return 1; /* new userdatum is already on the stack */ +} + +static int setImage (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVImage* imageView = (__bridge LVImage *)(user->object); + if ( [imageView isKindOfClass:[LVImage class]] ) { + [imageView cancelImageLoadAndClearCallback:L]; + if( lua_type(L, 3) == LUA_TFUNCTION ) { + [LVUtil registryValue:L key:imageView.functionTag stack:3]; + imageView.needCallLuaFunc = YES; + } else { + imageView.needCallLuaFunc = NO; + } + if ( lua_type(L, 2)==LUA_TSTRING ) { + NSString* imageName = lv_paramString(L, 2);// 2 + if( imageName ){ + [imageView setImageByName:imageName]; + lua_pushvalue(L,1); + return 1; + } + } else if ( lua_type(L, 2)==LUA_TUSERDATA ) { + LVUserDataInfo * userdata = (LVUserDataInfo *)lua_touserdata(L, 2); + if( LVIsType(userdata, Data) ) { + LVData* lvdata = (__bridge LVData *)(userdata->object); + [imageView setImageByData:lvdata.data]; + lua_pushvalue(L,1); + return 1; + } else if( LVIsType(userdata, Bitmap) ) { + LVBitmap* bitmap = (__bridge LVBitmap *)(userdata->object); + [imageView setImage:bitmap.nativeImage]; + lua_pushvalue(L,1); + return 1; + } + } else { + // 清理图片 + imageView.image = nil; + } + } + } + return 0; +} + +static int scaleType (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVImage* imageView = (__bridge LVImage *)(user->object); + if ( [imageView isKindOfClass:[LVImage class]] ) { + if( lua_gettop(L)>=2 ) { + int model = lua_tonumber(L, 2);// 2 + [imageView setContentMode:model]; + return 0; + } else { + UIViewContentMode model = imageView.contentMode; + lua_pushnumber(L, model); + return 1; + } + } + } + return 0; +} + +static int startAnimating (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( L && user ){ + LVImage* imageView = (__bridge LVImage *)(user->object); + if ( [imageView isKindOfClass:[LVImage class]] ) { + NSArray* urlArray = lv_luaTableToArray(L,2); + float repeatCount = 1; + float duration = 0.3; + if( lua_gettop(L)>=3 ){ + duration = lua_tonumber(L, 3); + } + if( lua_gettop(L)>=4 ){ + repeatCount = lua_tonumber(L, 4); + } + LuaViewCore* lview = LV_LUASTATE_VIEW(L); + LVBundle* bundle = lview.bundle; + NSMutableArray *arrayM=[NSMutableArray array]; + for (NSString* url in urlArray) { + UIImage* image = [bundle imageWithName:url]; + if( image ) { + [arrayM addObject:image]; + } + } + [imageView setAnimationImages:arrayM];//设置动画数组 + [imageView setAnimationDuration:duration];//设置动画播放时间 + [imageView setAnimationRepeatCount:repeatCount];//设置动画播放次数 + [imageView startAnimating];//开始动画 + } + } + return 0; +} + +static int stopAnimating (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVImage* imageView = (__bridge LVImage *)(user->object); + if ( [imageView isKindOfClass:[LVImage class]] ) { + [imageView stopAnimating]; + return 0; + } + } + return 0; +} + +static int isAnimating (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVImage* imageView = (__bridge LVImage *)(user->object); + if ( [imageView isKindOfClass:[LVImage class]] ) { + lua_pushboolean(L, imageView.isAnimating?1:0); + return 1; + } + } + lua_pushboolean(L, 0); + return 1; +} + +static int disableAnimate (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVImage* imageView = (__bridge LVImage *)(user->object); + if ( [imageView isKindOfClass:[LVImage class]] ) { + BOOL disableAnimate = lua_toboolean(L, 2); + imageView.disableAnimate = disableAnimate; + } + } + return 0; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + + [LVUtil reg:L clas:self cfunc:lvNewImageView globalName:globalName defaultName:@"Image"]; + + const struct luaL_Reg memberFunctions [] = { + {"image", setImage}, + {"scaleType", scaleType}, + + {"startAnimationImages", startAnimating},//__deprecated_msg("") + {"stopAnimationImages", stopAnimating},//__deprecated_msg("") + {"isAnimationImages", isAnimating},//__deprecated_msg("") + + {"disableAnimate", disableAnimate},//__deprecated_msg("") + {NULL, NULL} + }; + + lv_createClassMetaTable(L, META_TABLE_UIImageView); + + luaL_openlib(L, NULL, [LVBaseView baseMemberFunctions], 0); + luaL_openlib(L, NULL, memberFunctions, 0); + + const char* keys[] = { "addView", NULL};// 移除多余API + lv_luaTableRemoveKeys(L, keys ); + return 1; +} + + +//---------------------------------------------------------------------------------------- +-(NSString*) description{ + return [NSString stringWithFormat:@"", (int)[self hash], NSStringFromCGRect(self.frame) ]; +} + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLabel.h b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLabel.h new file mode 100644 index 00000000..66ca7757 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLabel.h @@ -0,0 +1,26 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + +@interface LVLabel : UILabel + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; +@property(nonatomic,assign) NSUInteger lv_align; +@property(nonatomic,strong) CAShapeLayer* lv_shapeLayer; + +-(id) init:(NSString*)imageName l:(lua_State*) l; + +/* + * luaview所有扩展类的桥接协议: 只是一个静态协议, luaview统一调用该接口加载luaview扩展的类 + */ ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLabel.m b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLabel.m new file mode 100644 index 00000000..007a1eaa --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLabel.m @@ -0,0 +1,331 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ +#import "LVLabel.h" +#import "LVBaseView.h" +#import "LView.h" +#import "LVStyledString.h" +#import "LVHeads.h" + +@interface LVLabel () +@property(nonatomic,assign) BOOL lv_isCallbackAddClickGesture;// 支持Callback 点击事件 +@end + +@implementation LVLabel + +-(id) init:(NSString*)imageName l:(lua_State*) l{ + self = [super init]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l);// 获取luaview运行内核 + self.text = imageName;// 初始化Label初始text + self.backgroundColor = [UIColor clearColor];// 默认背景色是透明色 + self.textAlignment = NSTextAlignmentLeft;// 默认是左对齐 + self.lv_isCallbackAddClickGesture = YES;// 默认允许添加事件监听 + self.clipsToBounds = YES;// 默认出界不可见 + self.font = [UIFont systemFontOfSize:14];// 默认字体大小 + } + return self; +} + +-(void) dealloc{ +} + +#pragma -mark UILabel +/* + * lua脚本中 local label = Label() 对应的构造方法 + */ +static int lvNewLabel(lua_State *L) { + // 获取构造方法对应的Class(Native类) + Class c = [LVUtil upvalueClass:L defaultClass:[LVLabel class]]; + { + NSString* text = lv_paramString(L, 1);// 获取脚本传过来的第一个参数(约定是字符串类型) + LVLabel* label = [[c alloc] init:text l:L];//通过Class和参数构造脚本对应的真实实例 + + { + NEW_USERDATA(userData, View);// 创建lua对象(userdata) + userData->object = CFBridgingRetain(label);// 脚本对象引用native对象 + label.lv_userData = userData;//native对象引用脚本对象 + + luaL_getmetatable(L, META_TABLE_UILabel ); // 获取Label对应的类方法列表 + lua_setmetatable(L, -2); // 设置刚才创建的lua对象的方法列表是类Label的方法列表 + } + LuaViewCore* view = LV_LUASTATE_VIEW(L);// 获取当前LuaView对应的LuaViewCore + if( view ){ + [view containerAddSubview:label]; // 把label对象加到LuaViewCore里面 + } + } + return 1; // 返回参数的个数 +} + +/* + * 脚本label实例对象label.text()方法对应的Native实现 + */ +static int text (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1);// 获取第一个参数永远是self(lua的userdata, 对象自身) + if( user ) { + LVLabel* view = (__bridge LVLabel *)(user->object);// 当前userdata对应的native对象 + if ( [view isKindOfClass:[LVLabel class]] ) {// 检查类型是否匹配(其实可以不用检查一般一定是对的) + if( lua_gettop(L)>=2 ) {// 检查是否参数大于等于两个(self+文本), 如果只要一个是取值操作, 两个是赋值操作 + if ( lua_isnoneornil(L, 2 ) ) { + // 如果参数的值是nil标识清空text操作 + view.text = nil; + } else if( lua_type(L, 2)==LUA_TNUMBER ){ + // 如果参数数值, 转换成字符串再赋值 + CGFloat text = lua_tonumber(L, 2);// 获取第二个参数, 第二个参数实际上对应脚本中的第一个参数 + view.text = [NSString stringWithFormat:@"%f",text]; + return 0; + } else if( lua_type(L, 2)==LUA_TSTRING ){ + // 如果是字符串, 直接赋值 + NSString* text = lv_paramString(L, 2);// 获取第二个参数, 第二个参数实际上对应脚本中的第一个参数 + view.text = text; + return 0; + } else if( lua_type(L, 2)==LUA_TUSERDATA ){ + // 如果是复合文本, 则获取复合文本对应的NSAttributedString后把复合文本赋值给Label + LVUserDataInfo * user2 = lua_touserdata(L, 2);// 2 + if( user2 && LVIsType(user2, StyledString) ) { + LVLabel* view = (__bridge LVLabel *)(user->object); + LVStyledString* attString = (__bridge LVStyledString *)(user2->object); + [view setAttributedText:attString.mutableStyledString]; + return 0; + } + } + } else { + // 脚本层无入参(除了self), 则 返回text + NSString* text = view.text; + lua_pushstring(L, text.UTF8String); + return 1;// 返回参数的个数 + } + } + } + return 0; +} + +/* + * 脚本label实例对象label.lineCount()方法对应的Native实现 + */ +static int lineCount(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1);// 获取第一个参数永远是self(lua的userdata, 对象自身) + if( user ){ + LVLabel* view = (__bridge LVLabel *)(user->object);// 获取userdata对应的native对象 + if( lua_gettop(L)>=2 ) {// 检查参数大于等于两个(self+lineCount), 如果只要一个是取值操作, 两个是赋值操作 + int number = lua_tonumber(L, 2);// 获取第二个参数, 第二个参数实际上对应脚本中的第一个参数 + if( [view isKindOfClass:[LVLabel class]] ){// 类型检查可以不做 + view.numberOfLines = number;// 设置文本的行数 + return 0; + } + } else { + // 脚本层无入参(除了self), 则 返回numberOfLines + lua_pushnumber(L, view.numberOfLines );// 返回文本的行数 + return 1;// 返回参数个数 + } + } + return 0; +} + +/* + * 脚本label实例对象label.adjustFontSize()方法对应的Native实现 + */ +static int adjustFontSize(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1);// 获取第一个参数永远是self(lua的userdata, 对象自身) + if( user ){ + BOOL yes = lua_toboolean(L, 2);// 获取第二个参数 bool值 + LVLabel* view = (__bridge LVLabel *)(user->object);// 获取userdata对应的native对象 + if( [view isKindOfClass:[LVLabel class]] ){ + view.adjustsFontSizeToFitWidth = yes;// 是否自适应字体 + + lua_pushvalue(L,1); + return 1; + } + } + return 0; +} + +/* + * 脚本label实例对象label.textColor()方法对应的Native实现 + */ +static int textColor (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1);// 获取第一个参数永远是self(lua的userdata, 对象自身) + if( user ){ + LVLabel* view = (__bridge LVLabel *)(user->object);// 获取userdata对应的native对象 + if( lua_gettop(L)>=2 ) {// 如果参数大于两个 + if( [view isKindOfClass:[LVLabel class]] ){ + UIColor* color = lv_getColorFromStack(L, 2); // 获取第二个参数的值(颜色) + view.textColor = color; // 设置颜色 + return 0; + } + } else { + // 脚本层无入参(除了self), 则 返回颜色值 + UIColor* color = view.textColor; + NSUInteger c = 0; + CGFloat a = 0; + if( lv_uicolor2int(color, &c, &a) ){ + lua_pushnumber(L, c ); // 颜色值 + lua_pushnumber(L, a);// 透明度 + return 2;// 返回参数的个数 + } + } + } + return 0; +} + +/* + * 脚本label实例对象label.font()方法对应的Native实现 + */ +static int font (lua_State *L) { + LuaViewCore* luaView = LV_LUASTATE_VIEW(L);// 获取LuaView的内核LuaViewCore + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1);// 获取第一个参数(self,lua的userdata, 对象自身) + if( luaView && user ){ + LVLabel* view = (__bridge LVLabel *)(user->object);// 获取self对应的native对象 + if( [view isKindOfClass:[LVLabel class]] ){ + if( lua_gettop(L)>=2 ) {// 参数大于两个 + if( lua_gettop(L)>=3 && lua_type(L, 2)==LUA_TSTRING ) { + // 参数大于等于三个: 第一个对象自身 第二个是字体名称, 第三个是字体大小 + NSString* fontName = lv_paramString(L, 2); + float fontSize = lua_tonumber(L, 3); + UIFont* font = [LVUtil fontWithName:fontName size:fontSize bundle:luaView.bundle]; + view.font = font; + } else { + // 只有两个参数: 第一个对象自身, 第二个字体大小 + float fontSize = lua_tonumber(L, 2); + view.font = [UIFont systemFontOfSize:fontSize]; + } + return 0; + } else { + // 脚本层无入参(除了self), 则 返回两个参数: 字体名称+字体大小 + UIFont* font = view.font; + NSString* fontName = font.fontName; + CGFloat fontSize = font.pointSize; + lua_pushstring(L, fontName.UTF8String); + lua_pushnumber(L, fontSize); + return 2;// 返回参数的个数 + } + } + } + return 0; +} + +/* + * 脚本label实例对象label.fontSize()方法对应的Native实现 + */ +static int fontSize (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1);// 获取第一个参数(self,lua的userdata, 对象自身) + if( user ){ + LVLabel* view = (__bridge LVLabel *)(user->object);// 获取self对应的native对象 + if( [view isKindOfClass:[LVLabel class]] ){ + if( lua_gettop(L)>=2 ) { + // 两个参数: 第一个对象自身, 第二个字体大小 + float fontSize = lua_tonumber(L, 2); + view.font = [UIFont systemFontOfSize:fontSize]; + return 0; + } else { + // 脚本层无入参(除了self), 则 返回字体大小 + UIFont* font = view.font; + CGFloat fontSize = font.pointSize; + lua_pushnumber(L, fontSize); + return 1; + } + } + } + return 0; +} + +/* + * 脚本label实例对象label.textAlign()方法对应的Native实现 + */ +static int textAlignment (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1);// 获取第一个参数(self,lua的userdata, 对象自身) + if( user ){ + LVLabel* view = (__bridge LVLabel *)(user->object);// 获取self对应的native对象 + if( lua_gettop(L)>=2 ) { + // 两个参数: 第一个对象自身, 第二个对齐方式 + NSInteger align = lua_tonumber(L, 2);// 获取第二个参数对齐方式 + if( [view isKindOfClass:[LVLabel class]] ){ + view.textAlignment = align; + return 0; + } + } else { + // 脚本层无入参(除了self), 则 返回 对齐方式的值 + int align = view.textAlignment; + lua_pushnumber(L, align ); + return 1; + } + } + return 0; +} + +/* + * 脚本label实例对象label.ellipsize()方法对应的Native实现 + */ +static int ellipsize (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1);// 获取第一个参数(self,lua的userdata, 对象自身) + if( user ){ + LVLabel* view = (__bridge LVLabel *)(user->object);// 获取self对应的native对象 + if( lua_gettop(L)>=2 ) { + // 两个参数: 第一个对象自身, 第二个参数lineBreakMode + NSInteger lineBreakMode = lua_tonumber(L, 2);// 2 + if( [view isKindOfClass:[LVLabel class]] ){ + view.lineBreakMode = lineBreakMode; + return 0; + } + } else { + // 脚本层无入参(除了self), 则 返回 lineBreakMode + int lineBreakMode = view.lineBreakMode; + lua_pushnumber(L, lineBreakMode ); + return 1; + } + } + return 0; +} + +/* + * luaview所有扩展类的桥接协议: 只是一个静态协议, luaview统一调用该接口加载luaview扩展的类 + */ ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + // 注册构造方法: "Label" 对应的C函数(lvNewLabel) + 对应的类Class(self/LVLabel) + [LVUtil reg:L clas:self cfunc:lvNewLabel globalName:globalName defaultName:@"Label"]; + + // lua Labe构造方法创建的对象对应的方法列表 + const struct luaL_Reg memberFunctions [] = { + {"text", text}, + + {"textColor", textColor}, + + {"font", font}, + {"fontSize", fontSize}, + {"textSize", fontSize}, // __deprecated_msg("Use fontSize") + + {"ellipsize", ellipsize}, + {"textAlign", textAlignment}, + {"gravity", textAlignment},// 上中下 IOS 不支持,需要考虑支持 + + {"lineCount", lineCount}, // __deprecated_msg("Use lines") + {"lines", lineCount}, + + {"adjustFontSize", adjustFontSize}, + + {NULL, NULL} + }; + + // 创建Label类的方法列表 + lv_createClassMetaTable(L, META_TABLE_UILabel); + + luaL_openlib(L, NULL, [LVBaseView baseMemberFunctions], 0); // 继承基类View的所有方法列表 + luaL_openlib(L, NULL, memberFunctions, 0); // 当前类Label特有的方法列表 + + const char* keys[] = { "addView", NULL};//列出需要移除的多余API + lv_luaTableRemoveKeys(L, keys );// 移除冗余API 兼容安卓 + return 1; +} + +/* + * 脚本中print(obj)的时候会调用该接口 显示该对象的相关信息 + */ +-(NSString*) description{ + return [NSString stringWithFormat:@"", (int)[self hash], NSStringFromCGRect(self.frame) ]; +} + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLoadingIndicator.h b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLoadingIndicator.h new file mode 100644 index 00000000..d73af1bc --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLoadingIndicator.h @@ -0,0 +1,24 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + +@interface LVLoadingIndicator : UIActivityIndicatorView + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; +@property(nonatomic,assign) NSUInteger lv_align; +@property(nonatomic,strong) CAShapeLayer* lv_shapeLayer; + +-(id) init:(lua_State*) l; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLoadingIndicator.m b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLoadingIndicator.m new file mode 100644 index 00000000..d09977cd --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLoadingIndicator.m @@ -0,0 +1,137 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVLoadingIndicator.h" +#import "LVBaseView.h" +#import "LView.h" +#import "LVHeads.h" + + +@implementation LVLoadingIndicator + + + +-(id) init:(lua_State*) l{ + self = [super init]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + self.clipsToBounds = YES; + self.userInteractionEnabled = NO; + } + return self; +} + +-(void) dealloc{ +} + +#pragma -mark lvNewActivityIndicator +static int lvNewLoadingIndicator (lua_State *L) { + { + Class c = [LVUtil upvalueClass:L defaultClass:[LVLoadingIndicator class]]; + + LVLoadingIndicator* pageControl = [[c alloc] init:L]; + + { + NEW_USERDATA(userData, View); + userData->object = CFBridgingRetain(pageControl); + + luaL_getmetatable(L, META_TABLE_LoadingIndicator ); + lua_setmetatable(L, -2); + } + LuaViewCore* view = LV_LUASTATE_VIEW(L); + if( view ){ + [view containerAddSubview:pageControl]; + } + } + return 1; /* new userdatum is already on the stack */ +} + +static int startAnimating(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVLoadingIndicator* view = (__bridge LVLoadingIndicator *)(user->object); + if( view ){ + [view startAnimating]; + } + } + return 0; +} + +static int stopAnimating(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVLoadingIndicator* view = (__bridge LVLoadingIndicator *)(user->object); + if( view ){ + [view stopAnimating]; + } + } + return 0; +} + +static int isAnimating(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVLoadingIndicator* view = (__bridge LVLoadingIndicator *)(user->object); + if( view ){ + lua_pushboolean(L, view.isAnimating); + return 1; + } + } + return 0; +} + +static int color(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVLoadingIndicator* view = (__bridge LVLoadingIndicator *)(user->object); + if( view ){ + if( lua_gettop(L)>=2 ) { + UIColor* color = lv_getColorFromStack(L, 2); + view.color = color; + return 0; + } else { + UIColor* color = view.color; + NSUInteger c = 0; + CGFloat a = 1; + if( lv_uicolor2int(color, &c, &a) ){ + lua_pushnumber(L, c ); + lua_pushnumber(L, a); + return 2; + } + } + } + } + return 0; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewLoadingIndicator globalName:globalName defaultName:@"LoadingIndicator"]; + + const struct luaL_Reg memberFunctions [] = { + {"start", startAnimating }, + {"stop", stopAnimating }, + {"show", startAnimating },//__deprecated_msg("Use start") + {"hide", stopAnimating },//__deprecated_msg("Use stop") + {"isAnimating", isAnimating }, + {"color", color}, + {NULL, NULL} + }; + + lv_createClassMetaTable(L, META_TABLE_LoadingIndicator); + + luaL_openlib(L, NULL, [LVBaseView baseMemberFunctions], 0); + luaL_openlib(L, NULL, memberFunctions, 0); + + const char* keys[] = { "addView", NULL};// 移除多余API + lv_luaTableRemoveKeys(L, keys ); + return 1; +} + + + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLongPressGesture.h b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLongPressGesture.h new file mode 100644 index 00000000..10fe1e1c --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLongPressGesture.h @@ -0,0 +1,23 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" +#import "NSObject+LuaView.h" + +@interface LVLongPressGesture : UILongPressGestureRecognizer + + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; + +-(id) init:(lua_State*) l; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLongPressGesture.m b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLongPressGesture.m new file mode 100644 index 00000000..b023ab83 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLongPressGesture.m @@ -0,0 +1,97 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVLongPressGesture.h" +#import "LVGesture.h" +#import "LView.h" +#import "LVHeads.h" + +@implementation LVLongPressGesture + + +-(void) dealloc{ + LVLog(@"LVLongPressGesture.dealloc"); + [LVGesture releaseUD:_lv_userData]; +} + +-(id) init:(lua_State*) l{ + self = [super initWithTarget:self action:@selector(handleGesture:)]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + } + return self; +} + +-(void) handleGesture:(LVLongPressGesture*)sender { + lua_State* l = self.lv_luaviewCore.l; + if ( l ){ + lua_checkstack32(l); + lv_pushUserdata(l,self.lv_userData); + [LVUtil call:l lightUserData:self key1:"callback" key2:NULL nargs:1]; + } +} + + +static int lvNewLongGesture (lua_State *L) { + { + Class c = [LVUtil upvalueClass:L defaultClass:[LVLongPressGesture class]]; + + LVLongPressGesture* gesture = [[c alloc] init:L]; + + if( lua_type(L, 1) != LUA_TNIL ) { + [LVUtil registryValue:L key:gesture stack:1]; + } + + { + NEW_USERDATA(userData, Gesture); + gesture.lv_userData = userData; + userData->object = CFBridgingRetain(gesture); + + luaL_getmetatable(L, META_TABLE_LongPressGesture ); + lua_setmetatable(L, -2); + } + } + return 1; /* new userdatum is already on the stack */ +} + +static int setTouchCount (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( LVIsType(user, Gesture) ){ + LVLongPressGesture* gesture = (__bridge LVLongPressGesture *)(user->object); + if( lua_gettop(L)>=2 ){ + float num = lua_tonumber(L, 2); + gesture.numberOfTouchesRequired = num; + return 0; + } else { + float num = gesture.numberOfTouchesRequired; + lua_pushnumber(L, num); + return 1; + } + } + return 0; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewLongGesture globalName:globalName defaultName:@"LongPressGesture"]; + + lv_createClassMetaTable(L, META_TABLE_LongPressGesture); + + luaL_openlib(L, NULL, [LVGesture baseMemberFunctions], 0); + + { + const struct luaL_Reg memberFunctions [] = { + {"touchCount", setTouchCount}, + {NULL, NULL} + }; + luaL_openlib(L, NULL, memberFunctions, 0); + } + return 1; +} + + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLuaObjBox.h b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLuaObjBox.h new file mode 100644 index 00000000..d4a23bf4 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLuaObjBox.h @@ -0,0 +1,18 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LView.h" + +@interface LVLuaObjBox : NSObject + +- (id) init:(lua_State*)L stackID:(int) stackID; + +- (void) setProtocols:(NSArray*) protocols; + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLuaObjBox.m b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLuaObjBox.m new file mode 100644 index 00000000..36f60cd8 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLuaObjBox.m @@ -0,0 +1,211 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVLuaObjBox.h" +#import +#import "LuaViewCore.h" +#import "LVTypeConvert.h" +#import "LVHeads.h" + +@interface LVLuaObjBox () +@property (nonatomic, strong) NSMutableArray* protocolArray; +@property (nonatomic, weak) LuaViewCore* lview; +@property (nonatomic, strong) NSMutableDictionary* methodSigHashtable; +@end + + +@implementation LVLuaObjBox + + +- (id) init:(lua_State*)L stackID:(int) stackID{ + self = [super init]; + if( self ){ + self.methodSigHashtable = [[NSMutableDictionary alloc] init]; + + self.lview = LV_LUASTATE_VIEW(L); + [LVUtil registryValue:L key:self stack:stackID]; + } + return self; +} + +- (void) dealloc{ + LuaViewCore* lview = self.lview; + if( lview) { + lua_State* L = lview.l; + if( L ) { + [LVUtil unregistry:L key:self]; + } + } +} + + +// static +static BOOL lv_object_isProtocol(id obj ) { + static Class ProtocolClass = NULL; + if( ProtocolClass == NULL ) { + ProtocolClass = objc_getClass("Protocol"); + } + return ( [obj class]==ProtocolClass ); +} + +- (void) setProtocols:(NSArray *)protocols{ + if ( self.protocolArray ==nil ) { + self.protocolArray = [[NSMutableArray alloc] init]; + } + for( id obj in protocols ){ + [self addProtocol:obj]; + } +} + +- (void) addProtocol:(id) obj{ + if ( obj==nil ) + return ; + + if ( (class_isMetaClass(object_getClass(obj)) || lv_object_isProtocol(obj)) ) { + [self addProtocolOnce:obj]; + } else if ( [obj isKindOfClass:[NSString class]] ) { + if ( [self addProtocolOnce:NSProtocolFromString(obj)]==FALSE ){ + if ( [self addProtocolOnce:NSClassFromString(obj)]==FALSE ) { + LVError( @"addProtocol: %@", obj); + return ; + } + } + } else { + [self addProtocolOnce:[obj class]]; + } +} + +- (BOOL) addProtocolOnce:(id) class{ + if ( class ) { + if ( class_isMetaClass(object_getClass(class)) || lv_object_isProtocol(class) ) { + if( ![self.protocolArray containsObject:class] ) { + [self.protocolArray addObject:class]; + return YES; + } + } + } + return NO; +} + + +- (BOOL)respondsToSelector:(SEL)aSelector { + return YES; +} + +- (NSMethodSignature *)methodSignatureForSelector:(SEL)selector +{ + NSString* key = NSStringFromSelector(selector); + NSMethodSignature* sig = self.methodSigHashtable[key]; + if( sig ){ + return sig; + } + for (id type in self.protocolArray ){ + struct objc_method_description* desc = NULL; + + if( lv_object_isProtocol(type) ){ // protocol + Protocol* protocol = type; + struct objc_method_description temp = protocol_getMethodDescription( protocol, selector, YES, YES); + if( temp.types==NULL || temp.name==NULL ) { + temp = protocol_getMethodDescription( protocol, selector, NO, YES); + } + desc = &temp; + } else if( class_isMetaClass(object_getClass(type)) ) { // class + Class class = (Class)type; + Method method = class_getInstanceMethod( class, selector ); + if ( method==NULL ){ + method = class_getClassMethod( class, selector ); + } + if ( method ) { + desc = method_getDescription( method ); + } + } + if( desc && desc->types && desc->name ) { + NSMethodSignature* sig = [NSMethodSignature signatureWithObjCTypes:desc->types]; + self.methodSigHashtable[key] = sig; + return sig; + } + } + return nil; +} + +- (NSString*) nativeFuncNameToLuaFuncName:(NSString*) funcName{ + NSMutableString* s = [[NSMutableString alloc] initWithString:funcName]; + if ( [funcName hasSuffix:@":"] ){ + [s deleteCharactersInRange:NSMakeRange(s.length-1,1)]; + } + [s replaceOccurrencesOfString:@":" withString:@"_" options:NSCaseInsensitiveSearch range:NSMakeRange(0,s.length)]; + return s; +} + +-(NSString*) propertyName:(NSString*) key{ + if( key.length>3 ) { + NSString* string = [[NSString alloc] initWithString:[key substringFromIndex:3]]; + NSString* string0 = [string substringToIndex:1]; + NSString* string1 = [string substringFromIndex:1]; + NSString* ret = [NSString stringWithFormat:@"%@%@",string0.lowercaseString, string1]; + return ret; + } + return key; +} + +- (void)forwardInvocation:(NSInvocation *)invocation +{ + NSString *key = NSStringFromSelector([invocation selector]); + LuaViewCore* lview = self.lview; + lua_State* L = lview.l; + if ( lview && L) { + int luaArgNum = 1; + [LVUtil pushRegistryValue:L key:self]; + int argsNum = (int)invocation.methodSignature.numberOfArguments; + + key = [self nativeFuncNameToLuaFuncName:key]; + int haveReturnValue = [self haveReturnValueOfInvocation:invocation]; + const char* keyName = key.UTF8String; + if ( lv_isLuaObjectHaveProperty(L, -1, keyName) ) { + for ( int i=2; i3 &&[key hasPrefix:@"set"] ){ + NSString* property = [self propertyName:key]; + const char* propertyName = property.UTF8String; + if ( lv_isLuaObjectHaveProperty(L, -1, propertyName) ) { + lua_pushstring(L, propertyName); + lv_pushInvocationArgToLuaStack(invocation, 2, L); + lua_settable(L, -3); + return; + } + } + LVError(@"LuaObjBox.forwardInvocation: not found function: %@", key); + } +} + +- (int) haveReturnValueOfInvocation:(NSInvocation*) invocation{ + const char* type = [invocation.methodSignature methodReturnType]; + if ( type ){ + if( strcmp(@encode(void),type)==0 ) { + return 0; + } + return 1; + } + return 0; +} +// class_copyPropertyList +// class_copyMethodList + +@end + + + diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVMethod.h b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVMethod.h new file mode 100644 index 00000000..9231d119 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVMethod.h @@ -0,0 +1,22 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + +@interface LVMethod : NSObject + +@property (nonatomic,assign) SEL sel; +@property (nonatomic,copy) NSString* selName; +@property (nonatomic,assign) NSInteger nargs; + +-(id) initWithSel:(SEL)sel; + +-(int) callObj:(id) obj args:(lua_State*)L; + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVMethod.m b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVMethod.m new file mode 100644 index 00000000..646959a5 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVMethod.m @@ -0,0 +1,71 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVMethod.h" +#import "LVHeads.h" +#import "LVTypeConvert.h" + + +@interface LVMethod () +@property(nonatomic,strong) NSMethodSignature * methodSig; +@end + +@implementation LVMethod + +-(id) initWithSel:(SEL)sel{ + self = [super init]; + if( self ){ + self.sel = sel; + self.selName = NSStringFromSelector(sel); + self.nargs = [self checkSelectorArgsNumber:NSStringFromSelector(sel)]; + } + return self; +} + +-(NSInteger) checkSelectorArgsNumber:(NSString*)s{ + NSInteger num = 0; + for( int i=0; i +#import "LVHeads.h" +#import "LVMethod.h" + + +//LVData +@interface LVNativeObjBox : NSObject + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; + +@property(nonatomic,assign) BOOL weakMode; +@property(nonatomic,strong) id realObject; +@property(nonatomic,weak) id realObjectWeak; +@property(nonatomic,assign) BOOL openAllMethod; + +-(id) init:(lua_State*) l nativeObject:(id)nativeObject; +-(void) addMethod:(LVMethod*) method; +-(int) performMethod:(NSString*) methodName L:(lua_State*)L; + +- (NSString *)className; +- (BOOL)isOCClass; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +/* + * 注册native对象到脚本中, sel可以为空(如果为空注册所有api) + */ ++(int) registeObjectWithL:(lua_State *)L nativeObject:(id) nativeObject name:(NSString*) luaName sel:(SEL) sel weakMode:(BOOL) weakMode; + +/* + * 清除脚本中注册的native对象 + */ ++(int) unregisteObjectWithL:(lua_State *)L name:(NSString*) name; + + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNativeObjBox.m b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNativeObjBox.m new file mode 100644 index 00000000..0ac3c6a6 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNativeObjBox.m @@ -0,0 +1,302 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVNativeObjBox.h" +#import "LVHeads.h" +#import +#import "LVClassInfo.h" + +static NSArray* ARG_ARR = nil; + +@interface LVNativeObjBox () +@property (nonatomic,strong) LVClassInfo* classInfo; +@end + + +@implementation LVNativeObjBox + +-(id) init:(lua_State*) l nativeObject:(id)nativeObject{ + self = [super init]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + self.realObject = nativeObject; + + NSString* className = NSStringFromClass([nativeObject class]); + self.classInfo = [LVClassInfo classInfo:className]; + } + return self; +} + +- (BOOL) isEqual:(LVNativeObjBox *)another{ + if (![another isMemberOfClass:[self class]]) { + return false; + } + + return self.realObject == another.realObject || [self.realObject isEqual:another.realObject]; +} + +- (NSUInteger)hash { + return [self.realObject hash]; +} + +- (BOOL) isOCClass{ + return self.realObject && class_isMetaClass(object_getClass(self.realObject)); +} + +- (NSString *)className { + return NSStringFromClass([self.realObject class]); +} + +- (void) setWeakMode:(BOOL)weakMode{ + _weakMode = weakMode; + if( weakMode ) { + if( self.realObject ) { + self.realObjectWeak = self.realObject; + } + self.realObject = nil; + } else { + if( self.realObjectWeak ) { + self.realObject = self.realObjectWeak; + } + self.realObjectWeak = nil; + } +} + +- (id) realObject{ + return _realObject ? _realObject : _realObjectWeak; +} + +- (id) lv_nativeObject{ + return [self realObject]; +} + +-(void) addMethod:(LVMethod*) method { + [self.classInfo addMethod:method key:method.selName]; +} + +-(int) performMethod:(NSString*) methodName L:(lua_State*)L{ + if( methodName ) { + LVMethod* method = [self.classInfo getMethod:methodName]; + if ( method ) { + return [method callObj:self.realObject args:L ]; + } else if( self.openAllMethod ) { + //动态创建API + SEL sel = NSSelectorFromString(methodName); + LVMethod* method = [[LVMethod alloc] initWithSel:sel]; + [self.classInfo addMethod:method key:methodName]; + return [method callObj:self.realObject args:L]; + } else { + LVError(@"not found method: %@", methodName); + } + } + return 0; +} + +static int funcNameFromLuaToOC(NSMutableString* funcName){ + if( funcName.length>0 && [funcName characterAtIndex:0]=='#' ) { + NSRange range = NSMakeRange(0, 1); + [funcName deleteCharactersInRange:range]; + return -1; + } else { + return (int)[funcName replaceOccurrencesOfString:@"_" withString:@":" options:NSLiteralSearch range:NSMakeRange(0,funcName.length)]; + } +} + +// 检查API是否纯在 +- (BOOL) isApiExist:(NSString*) methodName{ + BOOL ret = [self.classInfo existMethod:methodName]; + if( ret ) { + return YES; + } else { + NSMutableString* ocMethodName = [[NSMutableString alloc] initWithString:methodName]; + funcNameFromLuaToOC(ocMethodName); + id nativeObj = self.realObject; + for ( int i=0; i<7; i++ ) { + SEL sel = NSSelectorFromString(ocMethodName); + if( [nativeObj respondsToSelector:sel] ){ + [self.classInfo setMethod:methodName exist:YES]; + return YES; + } + [ocMethodName appendString:@":"]; + } + } + //self.apiHashtable[methodName] = @(NO); + return NO; +} + +static void releaseNativeObject(LVUserDataInfo* user){ + if( user && user->object ){ + LVNativeObjBox* data = CFBridgingRelease(user->object); + user->object = NULL; + if( data ){ + data.lv_userData = nil; + data.lv_luaviewCore = nil; + data.realObject = nil; + } + } +} + +static int __gc (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + releaseNativeObject(user); + return 0; +} + ++(int) registeObjectWithL:(lua_State *)L nativeObject:(id) nativeObject name:(NSString*) name sel:(SEL) sel weakMode:(BOOL)weakMode { + if ( L==nil ){ + LVError( @"Lua State is released !!!"); + return 0; + } + if( nativeObject && name ) { + lua_checkstack(L, 64); + lua_getglobal(L, name.UTF8String); + + LVNativeObjBox* nativeObjBox = nil; + if( lua_type(L, -1)==LUA_TUSERDATA ) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, -1); + if( LVIsType(user, NativeObject) ){ + LVNativeObjBox* temp = (__bridge LVNativeObjBox *)(user->object); + if( temp.realObject==nativeObject ){ + nativeObjBox = temp; + } + } + } + if( nativeObjBox == nil ){ + nativeObjBox = [[LVNativeObjBox alloc] init:L nativeObject:nativeObject]; + } + + if ( sel ) { + LVMethod* method = [[LVMethod alloc] initWithSel:sel]; + [nativeObjBox addMethod:method]; + } else { + nativeObjBox.openAllMethod = YES; + } + nativeObjBox.weakMode = weakMode; + + NEW_USERDATA(userData, NativeObject); + userData->object = CFBridgingRetain(nativeObjBox); + nativeObjBox.lv_userData = userData; + luaL_getmetatable(L, META_TABLE_NativeObject ); + lua_setmetatable(L, -2); + + lua_setglobal(L, name.UTF8String); + } else if ( nativeObject==nil ){ + [LVNativeObjBox unregisteObjectWithL:L name:name]; + } + return 1; +} + + ++(int) unregisteObjectWithL:(lua_State *)L name:(NSString*) name{ + if ( L && name ) { + lua_pushnil(L); + lua_setglobal(L, name.UTF8String); + } + return 0; +} + +static int __tostring (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVNativeObjBox* nativeObjBox = (__bridge LVNativeObjBox *)(user->object); + NSString* s = [[NSString alloc] initWithFormat:@"{ UserDataType=NativeObject, %@ }",nativeObjBox.realObject]; + lua_pushstring(L, s.UTF8String); + return 1; + } + return 0; +} + +static void ifNotEnoughArgsTagAppendMore(NSMutableString* funcName, int num, int luaArgsNum){ + int addNum = luaArgsNum-1-num; + if( 0<=addNum && addNumobject); + NSMutableString* funcName = [NSMutableString stringWithFormat:@"%s",lua_tostring(L, lua_upvalueindex(2)) ]; + int luaArgsNum = lua_gettop(L); + + int _num = funcNameFromLuaToOC(funcName); + if( _num>=0 ) { + ifNotEnoughArgsTagAppendMore(funcName, _num, luaArgsNum); + } + return [nativeObjBox performMethod:funcName L:L]; + } + LVError(@"callNativeObjectFunction"); + return 0; +} + + +static int __index (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + NSString* functionName = lv_paramString(L, 2); + + LVNativeObjBox* nativeObjBox = (__bridge LVNativeObjBox *)(user->object); + id object = nativeObjBox.realObject; + if( nativeObjBox && object && [nativeObjBox isApiExist:functionName] ){ + lua_pushcclosure(L, callNativeObjectFunction, 2); + return 1; + } + return 0; /* new userdatum is already on the stack */ +} + +static int __eq (lua_State *L) { + if (lua_gettop(L) < 2) { + return 0; + } + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + LVUserDataInfo * another = (LVUserDataInfo *)lua_touserdata(L, 2); + if (another != NULL) { + LVNativeObjBox * box1 = (__bridge LVNativeObjBox *)(user->object); + LVNativeObjBox * box2 = (__bridge LVNativeObjBox *)(user->object); + lua_pushboolean(L, [box1 isEqual:box2]); + return 1; + } + return 0; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + // OC常量定义 + if( ARG_ARR==nil ) { + ARG_ARR = @[ + @"", + @":", + @"::", + @":::", + @"::::", + @":::::", + @"::::::", + @":::::::",]; + } + + const struct luaL_Reg memberFunctions [] = { + {"__gc", __gc }, + {"__tostring", __tostring }, + {"__eq", __eq }, + {"__index", __index }, + {NULL, NULL} + }; + + lv_createClassMetaTable(L, META_TABLE_NativeObject); + luaL_openlib(L, NULL, memberFunctions, 0); + + + return 0; +} + + + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNavigation.h b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNavigation.h new file mode 100644 index 00000000..6828e71a --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNavigation.h @@ -0,0 +1,23 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + +@interface LVNavigation : NSObject + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +// 空实现去除编译警告 +-(void) lv_setNavigationItemTitleView:(UIView*) view; +-(void) lv_setNavigationItemTitle:(NSString*) title; +-(void) lv_setNavigationItemLeftBarButtonItems:(NSArray*) items; +-(void) lv_setNavigationItemRightBarButtonItems:(NSArray*) items; +-(void) lv_setNavigationBarBackgroundImage:(UIImage*) image; + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNavigation.m b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNavigation.m new file mode 100644 index 00000000..e2cae30d --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNavigation.m @@ -0,0 +1,160 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVNavigation.h" +#import "LView.h" +#import "LVStyledString.h" +#import "LVHeads.h" + +@implementation LVNavigation + +// 空实现去除编译警告 +-(void) lv_setNavigationItemTitleView:(UIView*) view{ +} +-(void) lv_setNavigationItemTitle:(NSString*) title{ +} +-(void) lv_setNavigationItemLeftBarButtonItems:(NSArray*) items{ +} +-(void) lv_setNavigationItemRightBarButtonItems:(NSArray*) items{ +} +-(void) lv_setNavigationBarBackgroundImage:(UIImage*) image{ +} + +static void setViewControllerTitleView(UIViewController* vc, UIView* view){ + if([view isKindOfClass:[UIView class]] ) {// 第三种: View + if( [vc respondsToSelector:@selector(lv_setNavigationItemTitleView:)] ) { + [vc performSelector:@selector(lv_setNavigationItemTitleView:) withObject:view]; + } else { + vc.navigationItem.titleView = view; + } + } +} + +static int setTitle (lua_State *L) { + lv_clearFirstTableValue(L); + LuaViewCore* lview = LV_LUASTATE_VIEW(L); + UIViewController* vc = lview.viewController; + if( vc && lua_gettop(L)>=1 ) { + if( lua_type(L, 1)== LUA_TSTRING ) {// 第一种: string + NSString* title = lv_paramString(L, 1); + if( [vc respondsToSelector:@selector(lv_setNavigationItemTitle:)] ) { + [vc performSelector:@selector(lv_setNavigationItemTitle:) withObject:title]; + } else { + vc.navigationItem.title = title; + } + return 0; + } else if( lua_type(L, 1)== LUA_TUSERDATA ) {//第二种: 复合文本 + LVUserDataInfo * user2 = lua_touserdata(L, 1); + if( user2 && LVIsType(user2, StyledString) ) { + UILabel* label = [[UILabel alloc] init]; + LVStyledString* attString = (__bridge LVStyledString *)(user2->object); + [label setAttributedText:attString.mutableStyledString]; + [label sizeToFit]; + setViewControllerTitleView(vc, label); + return 0; + } + } + id object = lv_luaValueToNativeObject(L, 1);// 第三种: View + setViewControllerTitleView(vc, object); + return 0; + } + return 0; +} + ++(NSArray*) getNavigationItems:(lua_State*)L{ + NSMutableArray* array = [[NSMutableArray alloc] init]; + int num = lua_gettop(L); + for ( int i=1; i<=num; i++ ) { + id object = lv_luaValueToNativeObject(L, i); + if ( [object isKindOfClass:[UIView class]] ) { + [array addObject:[[UIBarButtonItem alloc] initWithCustomView:object]]; + } + } + return array; +} + +static int setLeftButton (lua_State *L) { + lv_clearFirstTableValue(L); + LuaViewCore* lview = LV_LUASTATE_VIEW(L); + UIViewController* vc = lview.viewController; + if( vc && lua_gettop(L)>=1 ) { + NSArray* buttonItems = [LVNavigation getNavigationItems:L]; + if( [vc respondsToSelector:@selector(lv_setNavigationItemLeftBarButtonItems:)] ) { + [vc performSelector:@selector(lv_setNavigationItemLeftBarButtonItems:) withObject:buttonItems]; + } else { + vc.navigationItem.leftBarButtonItems = buttonItems; + } + } + return 0; /* number of results */ +} + +static int setRightButton (lua_State *L) { + lv_clearFirstTableValue(L); + LuaViewCore* lview = LV_LUASTATE_VIEW(L); + UIViewController* vc = lview.viewController; + if( vc && lua_gettop(L)>=1 ) { + NSArray* buttonItems = [LVNavigation getNavigationItems:L]; + if( [vc respondsToSelector:@selector(lv_setNavigationItemRightBarButtonItems:)] ){ + [vc performSelector:@selector(lv_setNavigationItemRightBarButtonItems:) withObject:buttonItems]; + } else { + vc.navigationItem.rightBarButtonItems = buttonItems; + } + } + return 0; /* number of results */ +} + +static int setBackground(lua_State*L ) { + lv_clearFirstTableValue(L); + LuaViewCore* lview = LV_LUASTATE_VIEW(L); + UIViewController* vc = lview.viewController; + if( vc && lua_gettop(L)>=1 ) { + id obj = lv_luaValueToNativeObject(L, 1); + if( [obj isKindOfClass:[UIImageView class]] ) { + UIImageView* imgView = obj; + UIImage* image = imgView.image; + float scale = [UIScreen mainScreen].scale; + if( image.scale=1 ) { + NSInteger value = lua_tonumber(L, 2); + [[UIApplication sharedApplication] setStatusBarStyle:value]; + } + return 0; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + const struct luaL_Reg fs [] = { + {"title", setTitle}, + {"left", setLeftButton}, + {"right", setRightButton}, + {"background", setBackground}, + {"statusBarStyle", setStatusBarStyle}, // for IOS + {LUAVIEW_SYS_TABLE_KEY, setBackground}, + {NULL, NULL} + }; + luaL_openlib(L, "Navigation", fs, 0); + return 0; +} + +@end + + + diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNetworkStatus.h b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNetworkStatus.h new file mode 100644 index 00000000..b27f5162 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNetworkStatus.h @@ -0,0 +1,34 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import + +#define NW_NETWOEK_STATUS_NOTIFY @"TBNetworkStatusChangeNotify" + +typedef enum { + NotReachable = 0, + ReachableViaWiFi, + ReachableVia2G, + ReachableVia3G, + ReachableVia4G +} LVNetworkStatusEnum; + +@interface LVNetworkStatus : NSObject + ++ (LVNetworkStatus *)shareInstance; + +- (LVNetworkStatusEnum)currentNetworkStatus; + +- (LVNetworkStatusEnum)preNetworkStatus; + +- (NSString *)currentNetworkStatusString; + + + + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNetworkStatus.m b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNetworkStatus.m new file mode 100644 index 00000000..dffb3a6d --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNetworkStatus.m @@ -0,0 +1,259 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVNetworkStatus.h" +#import +#import +#import +#import +#import +#import +#import +#import + +#import +#import + +#import + +static char *const StrKeyReachabilityQueue = "com.luaview.NetworkSDKReachabilityQueue"; +static dispatch_queue_t reachabilityQueue; + +@implementation LVNetworkStatus +{ + LVNetworkStatusEnum _currentNetworkStatus; + LVNetworkStatusEnum _preNetworkStatus; + SCNetworkReachabilityRef _reachabilityRef; + CTTelephonyNetworkInfo *netInfo; +} + ++ (LVNetworkStatus *)shareInstance +{ + static LVNetworkStatus *s_SPDYNetworkStatusManager = nil; + + @synchronized([self class]) + { + if (!s_SPDYNetworkStatusManager) + { + s_SPDYNetworkStatusManager = [[LVNetworkStatus alloc] init]; + } + } + + return s_SPDYNetworkStatusManager; +} + +- (id)init +{ + self = [super init]; + if (self) + { + struct sockaddr_in zeroAddress; + bzero(&zeroAddress, sizeof(zeroAddress)); + zeroAddress.sin_len = sizeof(zeroAddress); + zeroAddress.sin_family = AF_INET; + _reachabilityRef = SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, (const struct sockaddr*)&zeroAddress); + netInfo = [[CTTelephonyNetworkInfo alloc] init]; + + //开始解析当前网络状态 + [self _reachabilityStatus]; + + //开始监控网络变化 + [self _startNotifier]; + } + + return self; +} + +- (BOOL)_startNotifier +{ + if (!_reachabilityRef) + { + struct sockaddr_in zeroAddress; + bzero(&zeroAddress, sizeof(zeroAddress)); + zeroAddress.sin_len = sizeof(zeroAddress); + zeroAddress.sin_family = AF_INET; + _reachabilityRef = SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, (const struct sockaddr*)&zeroAddress); + } + + if (_reachabilityRef) + { + SCNetworkReachabilityContext context = {0, (__bridge void *)(self), NULL, NULL, NULL}; + + if(SCNetworkReachabilitySetCallback(_reachabilityRef, ReachabilityCallback, &context)) + { + reachabilityQueue = dispatch_queue_create(StrKeyReachabilityQueue, DISPATCH_QUEUE_SERIAL); + SCNetworkReachabilitySetDispatchQueue(_reachabilityRef, reachabilityQueue); + + return YES; + } + } + + return NO; +} + +- (LVNetworkStatusEnum)currentNetworkStatus +{ + return _currentNetworkStatus; +} + +- (LVNetworkStatusEnum)preNetworkStatus +{ + return _preNetworkStatus; +} + +- (NSString *)currentNetworkStatusString +{ + switch (_currentNetworkStatus) + { + case NotReachable: + return @"unknown"; + + case ReachableVia2G: + return @"2g"; + + case ReachableVia3G: + return @"3g"; + + case ReachableVia4G: + return @"4g"; + + case ReachableViaWiFi: + return @"wifi"; + } +} + +- (LVNetworkStatusEnum)_reachabilityStatus +{ + if (_reachabilityRef) + { + SCNetworkReachabilityFlags flags = 0; + if (SCNetworkReachabilityGetFlags(_reachabilityRef, &flags)) + { + _preNetworkStatus = _currentNetworkStatus; + _currentNetworkStatus = [self _networkStatusForReachabilityFlags:flags]; + } + } + return _currentNetworkStatus; +} + +- (BOOL)checkInternetConnection +{ + struct sockaddr_in zeroAddress; + + bzero(&zeroAddress, sizeof(zeroAddress)); + zeroAddress.sin_len = sizeof(zeroAddress); + zeroAddress.sin_family = AF_INET; + + SCNetworkReachabilityRef defaultRouteReachability = SCNetworkReachabilityCreateWithAddress(NULL, (struct sockaddr *)&zeroAddress); + SCNetworkReachabilityFlags flags; + + BOOL didRetrieveFlags = SCNetworkReachabilityGetFlags(defaultRouteReachability, &flags); + + CFRelease(defaultRouteReachability); + + if (!didRetrieveFlags) + { + return NO; + } + + BOOL isReachable = flags & kSCNetworkFlagsReachable; + BOOL needsConnection = flags & kSCNetworkFlagsConnectionRequired; + + return (isReachable && !needsConnection) ? YES : NO; +} + +- (LVNetworkStatusEnum) currentNetworkStatusForiOS7:(LVNetworkStatusEnum) status +{ + NSString *nettype = netInfo.currentRadioAccessTechnology; + + if (nettype) + { + if([CTRadioAccessTechnologyGPRS isEqualToString:nettype]) + { + return ReachableVia2G; + } + else if([CTRadioAccessTechnologyLTE isEqualToString: nettype] + || [CTRadioAccessTechnologyeHRPD isEqualToString: nettype]) + { + return ReachableVia4G; + } + + } + + return status; +} + +- (LVNetworkStatusEnum)_networkStatusForReachabilityFlags:(SCNetworkReachabilityFlags)flags +{ + if ((flags & kSCNetworkReachabilityFlagsReachable) == 0 || ![self checkInternetConnection]) + { + // The target host is not reachable. + return NotReachable; + } + + LVNetworkStatusEnum returnValue = NotReachable; + + if ((flags & kSCNetworkReachabilityFlagsConnectionRequired) == 0) + { + returnValue = ReachableViaWiFi; + } + + if ((((flags & kSCNetworkReachabilityFlagsConnectionOnDemand ) != 0) || + (flags & kSCNetworkReachabilityFlagsConnectionOnTraffic) != 0)) + { + if ((flags & kSCNetworkReachabilityFlagsInterventionRequired) == 0) + { + returnValue = ReachableViaWiFi; + } + } + + if ((flags & kSCNetworkReachabilityFlagsIsWWAN) == kSCNetworkReachabilityFlagsIsWWAN) + { + returnValue = ReachableVia4G; + } + + if ((flags & kSCNetworkReachabilityFlagsIsWWAN) == kSCNetworkReachabilityFlagsIsWWAN) + { + if((flags & kSCNetworkReachabilityFlagsReachable) == kSCNetworkReachabilityFlagsReachable) + { + if ((flags & kSCNetworkReachabilityFlagsTransientConnection) == kSCNetworkReachabilityFlagsTransientConnection) + { + returnValue = ReachableVia3G; + + if((flags & kSCNetworkReachabilityFlagsConnectionRequired) == kSCNetworkReachabilityFlagsConnectionRequired) + { + returnValue = ReachableVia2G; + } + } + } + } + + if ( returnValue != ReachableViaWiFi ) + { + returnValue = [self currentNetworkStatusForiOS7: returnValue]; + } + + return returnValue; +} + +//网络变化回调函数 +static void ReachabilityCallback(SCNetworkReachabilityRef target, SCNetworkReachabilityFlags flags, void* info) +{ + + [[LVNetworkStatus shareInstance] _reachabilityStatus]; +} + +- (void)dealloc +{ + if (_reachabilityRef) + { + CFRelease(_reachabilityRef); + } +} + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNinePatchImage.h b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNinePatchImage.h new file mode 100755 index 00000000..b2831f89 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNinePatchImage.h @@ -0,0 +1,11 @@ + + +#import + +@interface LVNinePatchImage : NSObject + ++ (UIImage*) createNinePatchImageNamed:(NSString*)name; ++ (UIImage*) createNinePatchImage:(UIImage*)image; ++ (BOOL) isNinePathImageName:(NSString*) name; + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNinePatchImage.m b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNinePatchImage.m new file mode 100755 index 00000000..f4e99ba7 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNinePatchImage.m @@ -0,0 +1,167 @@ + + +#import "LVNinePatchImage.h" +#import "LVUtil.h" + +#define BYTES_PER_PIXEL 4 + +@implementation LVNinePatchImage + ++ (unsigned char*)getRGBAsFromImage:(UIImage*)image count:(NSInteger)count { + CGImageRef imageRef = [image CGImage]; + NSUInteger width = CGImageGetWidth(imageRef); + NSUInteger height = CGImageGetHeight(imageRef); + CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); + + unsigned char* rawData = (unsigned char*)calloc(height * width * 4, sizeof(unsigned char)); + + NSUInteger bytesPerRow = BYTES_PER_PIXEL * width; + NSUInteger bitsPerComponent = 8; + CGContextRef context = CGBitmapContextCreate(rawData, width, height, + bitsPerComponent, bytesPerRow, colorSpace, + kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big); + CGColorSpaceRelease(colorSpace); + + CGContextDrawImage(context, CGRectMake(0, 0, width, height), imageRef); + CGContextRelease(context); + return rawData; +} + +inline static CGFloat getImageAphaAtPoint(const unsigned char* rawData, NSInteger width, NSInteger height , NSInteger pointX, NSInteger pointY){ + NSInteger bytesPerRow = BYTES_PER_PIXEL * width; + NSInteger byteIndex = (bytesPerRow * pointY) + pointX * BYTES_PER_PIXEL ; + CGFloat alpha = (rawData[byteIndex + 3] * 1.0) / 255.0; + return alpha; +} + ++ (BOOL) isNinePathImageName:(NSString*) name{ + if ( [name hasSuffix:@".9"] || [name hasSuffix:@".9.png"] || [name hasSuffix:@".9@2x.png"] ) { + return YES; + } + return NO; +} + ++ (UIImage*)createNinePatchImageNamed:(NSString*)name { + if ( [self isNinePathImageName:name] ) { + UIImage* oriImage = [UIImage imageNamed:name]; + if ( oriImage==nil ) { + LVLog(@"createNinePatchImageNamed: The input image is nil"); + return nil; + } + return [self createResizableImageFromNinePatchImage:oriImage]; + } + LVLog(@"createNinePatchImageNamed: Image name is not ended with .9"); + return nil; +} + ++ (UIImage*)createNinePatchImage:(UIImage*)image +{ + return [self createResizableImageFromNinePatchImage:image]; +} + ++ (UIImage*)crop:(CGRect)r image0:(UIImage*)image0 +{ + r = CGRectMake(r.origin.x * image0.scale, + r.origin.y * image0.scale, + r.size.width * image0.scale, + r.size.height * image0.scale); + + CGImageRef imageRef = CGImageCreateWithImageInRect([image0 CGImage], r); + UIImage* ret = [UIImage imageWithCGImage:imageRef + scale:image0.scale + orientation:image0.imageOrientation]; + CGImageRelease(imageRef); + return ret; +} + ++ (UIImage*)createResizableImageFromNinePatchImage:(UIImage*)ninePatchImage +{ + CGImageRef imageRef = [ninePatchImage CGImage]; + NSInteger width = CGImageGetWidth(imageRef); + NSInteger height = CGImageGetHeight(imageRef); + + + NSMutableArray* topBarRgba = [NSMutableArray arrayWithCapacity:0]; + NSMutableArray* leftBarRgba = [NSMutableArray arrayWithCapacity:0]; + { + const unsigned char* rawData = [self getRGBAsFromImage:ninePatchImage count:width*height ]; + for( int x=1; x= 0; i--) { + NSNumber* alpha = topBarRgba[i]; + if ( alpha.floatValue == 1) { + right = i; + break; + } + } + // LVLog(@"The .9 PNG format error!!!. right==-1"); + for (int i = left + 1; i <= right - 1; i++) { + NSNumber* alpha = topBarRgba[i]; + if ( alpha.floatValue < 1) { + LVLog(@"The 9-patch PNG format is not support. 1"); + break; + } + } + count = (int) leftBarRgba.count; + for (int i = 0; i <= count - 1; i++) { + NSNumber* alpha = leftBarRgba[i]; + if ( alpha.floatValue == 1) { + top = i; + break; + } + } + //LVLog(@"The .9 PNG format error!!!. top==-1"); + for (int i = count - 1; i >= 0; i--) { + NSNumber* alpha = leftBarRgba[i]; + if ( alpha.floatValue == 1) { + bottom = i; + break; + } + } + //LVLog(@"The .9 PNG format error!!!. bottom==-1"); + for (int i = top + 1; i <= bottom - 1; i++) { + NSNumber* alpha = leftBarRgba[i]; + if ( alpha.floatValue == 0) { + LVLog(@"The 9-patch PNG format is not support.2"); + break; + } + } + if ( top>=0 && left>=0 && bottom>=0 && right>=0 ) { + UIImage* cropImg = [self crop:CGRectMake(1, 1, ninePatchImage.size.width - 2, ninePatchImage.size.height - 2) image0:ninePatchImage]; + float scale0 = cropImg.scale; + float scale2 = [UIScreen mainScreen].scale; + if ( scale2>scale0 ) { + cropImg = [[UIImage alloc] initWithCGImage:cropImg.CGImage + scale:scale2 + orientation:UIImageOrientationUp]; + float big = scale0/scale2; + UIImage* retImg = [cropImg resizableImageWithCapInsets:UIEdgeInsetsMake(top*big, left*big, bottom*big, right*big)]; + return retImg; + } else { + UIImage* retImg = [cropImg resizableImageWithCapInsets:UIEdgeInsetsMake(top, left, bottom, right) ]; + return retImg; + } + } + return ninePatchImage; +} + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPagerIndicator.h b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPagerIndicator.h new file mode 100644 index 00000000..e61773af --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPagerIndicator.h @@ -0,0 +1,31 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + +@class LVPagerView; + +@interface LVPagerIndicator : UIPageControl + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; +@property(nonatomic,assign) NSUInteger lv_align; +@property(nonatomic,strong) CAShapeLayer* lv_shapeLayer; + + +-(id) init:(lua_State*) l; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +/* + 关联PagerIndicator用的 + */ +@property(nonatomic,weak) LVPagerView* pagerView; + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPagerIndicator.m b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPagerIndicator.m new file mode 100644 index 00000000..2e07b189 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPagerIndicator.m @@ -0,0 +1,163 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVPagerIndicator.h" +#import "LVBaseView.h" +#import "LView.h" +#import "LVPagerView.h" +#import "LVHeads.h" + +@implementation LVPagerIndicator + + +-(id) init:(lua_State*) l{ + self = [super init]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + self.clipsToBounds = YES; + self.userInteractionEnabled = NO; + } + return self; +} + +-(void) dealloc{ +} + +#pragma -mark PageControl +static int lvNewPagerIndicator (lua_State *L) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVPagerIndicator class]]; + + LVPagerIndicator* pageControl = [[c alloc] init:L]; + + { + NEW_USERDATA(userData, View); + userData->object = CFBridgingRetain(pageControl); + + luaL_getmetatable(L, META_TABLE_PagerIndicator ); + lua_setmetatable(L, -2); + } + LuaViewCore* view = LV_LUASTATE_VIEW(L); + if( view ){ + [view containerAddSubview:pageControl]; + } + return 1; /* new userdatum is already on the stack */ +} + +//static int setPageCount(lua_State *L) { +// LVUserDataView * user = (LVUserDataView *)lua_touserdata(L, 1); +// if( user ){ +// LVPagerIndicator* view = (__bridge LVPagerIndicator *)(user->view); +// if( view ){ +// if( lua_gettop(L)>=2 ) { +// int number = lua_tonumber(L, 2); +// view.numberOfPages = number; +// return 0; +// } else { +// lua_pushnumber(L, view.numberOfPages ); +// return 1; +// } +// } +// } +// return 0; +//} + +static int setCurrentPage(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVPagerIndicator* view = (__bridge LVPagerIndicator *)(user->object); + if( view ){ + if( lua_gettop(L)>=2 ) { + int currentPage = lua_tonumber(L, 2); + //view.currentPage = currentPage-1; + [view.pagerView setCurrentPageIdx:currentPage-1 animation:YES]; + return 0; + } else { + lua_pushnumber(L, view.currentPage+1 ); + return 1; + } + } + } + return 0; +} + +static int pageIndicatorTintColor(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVPagerIndicator* view = (__bridge LVPagerIndicator *)(user->object); + if( view ){ + if( lua_gettop(L)>=2 ) { + UIColor* color = lv_getColorFromStack(L, 2); + view.pageIndicatorTintColor = color; + return 0; + } else { + UIColor* color = view.pageIndicatorTintColor; + NSUInteger c = 0; + CGFloat a = 0; + if( lv_uicolor2int(color, &c, &a) ){ + lua_pushnumber(L, c ); + lua_pushnumber(L, a); + return 2; + } + } + } + } + return 0; +} + +static int currentPageIndicatorTintColor(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVPagerIndicator* view = (__bridge LVPagerIndicator *)(user->object); + if( view ){ + if( lua_gettop(L)>=2 ) { + UIColor* color = lv_getColorFromStack(L, 2); + view.currentPageIndicatorTintColor = color; + return 0; + } else { + UIColor* color = view.currentPageIndicatorTintColor; + NSUInteger c = 0; + CGFloat a = 0; + if( lv_uicolor2int(color, &c, &a) ){ + lua_pushnumber(L, c ); + lua_pushnumber(L, a); + return 2; + } + } + } + } + return 0; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewPagerIndicator globalName:globalName defaultName:@"PagerIndicator"]; + + const struct luaL_Reg memberFunctions [] = { + {"currentPage", setCurrentPage }, + + {"pageColor", pageIndicatorTintColor },//__deprecated_msg("Use unselectedColor") + {"currentPageColor", currentPageIndicatorTintColor },//__deprecated_msg("Use selectedColor") + + {"unselectedColor", pageIndicatorTintColor }, + {"selectedColor", currentPageIndicatorTintColor }, + {NULL, NULL} + }; + + lv_createClassMetaTable(L, META_TABLE_PagerIndicator); + + luaL_openlib(L, NULL, [LVBaseView baseMemberFunctions], 0); + luaL_openlib(L, NULL, memberFunctions, 0); + + const char* keys[] = { "addView", NULL};// 移除多余API + lv_luaTableRemoveKeys(L, keys ); + return 1; +} + + +//---------------------------------------------------------------------------------------- + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPagerView.h b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPagerView.h new file mode 100644 index 00000000..0e11dc78 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPagerView.h @@ -0,0 +1,28 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + +@class LVPagerIndicator; +@interface LVPagerView : UIView + + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; +@property(nonatomic,assign) NSUInteger lv_align; +@property(nonatomic,strong) CAShapeLayer* lv_shapeLayer; + + +-(id) init:(lua_State*) l; ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +-(void) setIndicator:(LVPagerIndicator*) indicator; +-(void) setCurrentPageIdx:(NSInteger) pageIdx animation:(BOOL) animation; + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPagerView.m b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPagerView.m new file mode 100644 index 00000000..39206851 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPagerView.m @@ -0,0 +1,750 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVPagerView.h" +#import "LView.h" +#import "LVBaseView.h" +#import "LVScrollView.h" +#import "LVPagerViewCell.h" +#import "LVPagerIndicator.h" +#import "LVHeads.h" +#import "LuaViewCore.h" + +static inline NSInteger mapPageIdx(NSInteger pageIdx){ + return pageIdx + 1; +} + +static inline NSInteger unmapPageIdx(NSInteger pageIdx){ + return pageIdx - 1; +} + +#define IDENTIFIER "Id" + +// lua 对应的数据 key +#define USERDATA_KEY_DELEGATE 1 + +#define DEFAULT_CELL_IDENTIFIER @"LVCollectionCell.default.identifier" + +@interface LVPagerView () +@property (nonatomic,strong) UICollectionViewFlowLayout *flowLayout; +@property (nonatomic,strong) NSMutableDictionary* identifierDic; +@property (nonatomic,strong) NSMutableArray* cellArray; + + +@property (nonatomic,assign) NSInteger pageIdx0; +@property (nonatomic,assign) NSInteger pageIdx; +@property (nonatomic,weak) LVPagerIndicator* pagerIndicator; + +@property (nonatomic,strong) NSTimer *timer; + +@property (nonatomic,assign) CGPoint nextOffset; +@property (nonatomic,assign) BOOL looping; +@property (nonatomic,assign) NSInteger isScrollEndTimes; + +@property (nonatomic,strong) UIScrollView *scrollview; +@property (nonatomic,assign) CGFloat sideLeft; +@property (nonatomic,assign) CGFloat sideRight; + +@property (nonatomic,assign) BOOL doubleMode; + +@property (nonatomic,assign) float autoScrollInterval; +@end + + +@implementation LVPagerView + +-(id) init:(lua_State*) l { + self = [super init]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + self.backgroundColor = [UIColor clearColor]; + self.cellArray = [[NSMutableArray alloc] init]; + self.scrollview = ({ + UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)]; + scroll.pagingEnabled = YES; + scroll.clipsToBounds = NO; + scroll; + }) ; + + [self addSubview:self.scrollview]; + self.clipsToBounds = YES; + + self.scrollview.pagingEnabled = YES; + self.scrollview.showsHorizontalScrollIndicator = NO; + self.scrollview.delegate = self; + self.scrollview.scrollsToTop = NO; + self.pageIdx = 0; + self.isScrollEndTimes = 0; + } + return self; +} + +-(void) createAllCell { + NSInteger num = [self numberOfPagesInPageView]; + if( num==2 && ( self.sideLeft!=0 || self.sideRight!=0 ) ) { + // 开始双倍模式 + num = 4; + self.doubleMode = YES; + } else { + self.doubleMode = NO; + } + if( numself.cellArray.count ) { + for( int i=((int)self.cellArray.count); i0 ) { + i += self.pageIdx0; + i += 1000 * count; + return i%count; + } + return i; +} + +// xindex 映射 index +-(NSInteger) xindex2index:(NSInteger) i{ + NSUInteger count = self.cellArray.count; + if( count>0 ) { + i -= self.pageIdx0; + i += 1000 * count; + return i%count; + } + return i; +} + +-(void) resetCellFrame{ + {// ScrollView的滚动大小 + CGRect rect = self.bounds; + rect.origin.x = self.sideLeft; + rect.size.width -= self.sideLeft + self.sideRight; + self.scrollview.frame = rect; + } + NSUInteger count = self.cellArray.count; + CGSize size = self.scrollview.frame.size; + for( NSUInteger i=0; i0 ) { + CGPoint p = self.scrollview.contentOffset; + if( self.looping ) { + if( self.cellArray.count>2 ) { + if( p.x < width*0.5 ) { + self.pageIdx0 += 1; + self.scrollview.contentOffset = CGPointMake( p.x + width, 0); + [self resetCellFrame]; + } else if( p.x> width*1.5 ){ + self.pageIdx0 -= 1; + self.scrollview.contentOffset = CGPointMake( p.x - width, 0); + [self resetCellFrame]; + } + } else { + if( p.x< 0 ) { + self.pageIdx0 += 1; + self.scrollview.contentOffset = CGPointMake( p.x + width, 0); + [self resetCellFrame]; + } else if( p.x>=width ){ + self.pageIdx0 -= 1; + self.scrollview.contentOffset = CGPointMake( p.x - width, 0); + [self resetCellFrame]; + } + } + } + } +} + +-(void) setFrame:(CGRect)frame{ + [super setFrame:frame]; + [self resetCellFrame]; +} + +-(void) checkCellVisible{ + CGPoint p = self.scrollview.contentOffset; + CGRect r0 = self.scrollview.bounds; + r0.origin = p; + r0.origin.x -= self.sideLeft; + r0.size.width += self.sideLeft + self.sideRight; + for( int i=0; i=0 && index=2 ) { + pageIdx = pageIdx-2; + } + if( !cell.isInited ){ + cell.isInited = YES; + [cell doInitWithLView:lview]; + + // 创建cell初始化 + lua_settop(l, 0); + lua_checkstack(l, 12); + [cell pushTableToStack];//arg1: cell + lua_pushnumber(l, mapPageIdx(pageIdx) );//arg2: section + + lv_pushUserdata(l, self.lv_userData); + lv_pushUDataRef(l, USERDATA_KEY_DELEGATE); + [LVUtil call:l key1:"Pages" key2:"Init" key3:NULL nargs:2 nrets:0 retType:LUA_TNONE]; + } + { // 通知布局调整 + // 参数 cell,section,row + lua_settop(l, 0); + lua_checkstack(l, 12); + [cell pushTableToStack];//arg1: cell + lua_pushnumber(l, mapPageIdx(pageIdx) );//arg2: section + + lv_pushUserdata(l, self.lv_userData); + lv_pushUDataRef(l, USERDATA_KEY_DELEGATE); + [LVUtil call:l key1:"Pages" key2:"Layout" key3:NULL nargs:2 nrets:0 retType:LUA_TNONE]; + } + } + [lview popWindow:newWindow]; + return cell; +} + +// section数量 +- (NSInteger) numberOfPagesInPageView{ + lua_State* l = self.lv_luaviewCore.l; + if( l && self.lv_userData ){ + lv_pushUserdata(l, self.lv_userData); + lv_pushUDataRef(l, USERDATA_KEY_DELEGATE); + if( [LVUtil call:l key1:"PageCount" key2:NULL key3:NULL nargs:0 nrets:1 retType:LUA_TNUMBER] ==0 ) { + if( lua_type(l, -1)==LUA_TNUMBER ) { + NSInteger num = lua_tonumber(l, -1); + return num; + } + } + return 1; + } + return 1; +} + +-(void) setPageIndicatorIdx:(NSInteger)pageIdx{ + if( pageIdx>=0 && pageIdx=2 ) { + self.pagerIndicator.currentPage = pageIdx-2; + } else { + self.pagerIndicator.currentPage = pageIdx; + } + } +} + + +-(void) setIndicator:(LVPagerIndicator*) indicator{ + self.pagerIndicator = indicator; + self.pagerIndicator.pagerView = self; + if( self.doubleMode ) { + self.pagerIndicator.numberOfPages = 2; + } else { + self.pagerIndicator.numberOfPages = self.cellArray.count; + } + [self setPageIndicatorIdx:self.pageIdx]; +} + +-(void) setCurrentPageIdx:(NSInteger) pageIdx animation:(BOOL) animation{ + float offsetX = [self index2xindex:pageIdx] * self.scrollview.frame.size.width ; + if( offsetX<=0 ){ + offsetX = 0; + } + float maxOffset = self.scrollview.contentSize.width - self.scrollview.frame.size.width; + if( offsetX > maxOffset ){ + offsetX = maxOffset; + } + //[self setContentOffset:CGPointMake(offsetX, 0) animated:animation]; + self.nextOffset = CGPointMake(offsetX, 0); + if( animation ) { + [self performSelectorOnMainThread:@selector(changeOffsetWithAnimation:) withObject:nil waitUntilDone:NO]; + } else { + [self performSelectorOnMainThread:@selector(changeOffsetNoAnimation:) withObject:nil waitUntilDone:NO]; + } +} + +// 有动画 +-(void) changeOffsetWithAnimation:(NSNumber*) value{ + if( self.lv_luaviewCore ) { + [self.scrollview setContentOffset:self.nextOffset animated:YES]; + } +} + +// 无动画 +-(void) changeOffsetNoAnimation:(NSNumber*) value{ + if( self.lv_luaviewCore ) { + [self.scrollview setContentOffset:self.nextOffset animated:NO]; + } +} + +#pragma -mark lvNewCollectionView +static int lvNewPagerView (lua_State *L) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVPagerView class]]; + + if( lua_gettop(L)<=0 ) { + lua_createtable(L, 8, 0); + } + + if ( lua_gettop(L)>=1 && lua_type(L, 1)==LUA_TTABLE ) { + LVPagerView* pageView = [[c alloc] init:L]; + + NEW_USERDATA(userData, View); + userData->object = CFBridgingRetain(pageView); + pageView.lv_userData = userData; + luaL_getmetatable(L, META_TABLE_UIPageView ); + lua_setmetatable(L, -2); + + LuaViewCore* lview = LV_LUASTATE_VIEW(L); + if( lview ){ + [lview containerAddSubview:pageView]; + } + + int stackNum = lua_gettop(L); + lua_pushvalue(L, 1); + lv_udataRef(L, USERDATA_KEY_DELEGATE ); + + [pageView createAllCell]; + lua_settop(L, stackNum); + + lv_pushUserdata(L, pageView.lv_userData); + return 1; + } + return 0; +} + +-(void) reloadData{ + for( UIView* view in self.cellArray ) { + [view removeFromSuperview]; + } + [self createAllCell]; + [self moveCenter]; + [self checkCellVisible]; + self.autoScrollInterval = self.autoScrollInterval; +} + +-(void) reloadDataASync{ + dispatch_async(dispatch_get_main_queue(), ^{ + [self performSelector:@selector(reloadData) withObject:nil afterDelay:0.001 inModes:@[NSRunLoopCommonModes]]; + }); +} + +static int reload (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVPagerView* pageView = (__bridge LVPagerView *)(user->object); + [pageView reloadDataASync]; + lua_pushvalue(L, 1); + return 1; + } + return 0; +} + +static int showScrollBar(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIScrollView* view = (__bridge UIScrollView *)(user->object); + if( lua_gettop(L)>=2 ) { + BOOL yes1 = lua_toboolean(L, 2); + view.showsHorizontalScrollIndicator = yes1; + return 0; + } else { + lua_pushboolean(L, view.showsHorizontalScrollIndicator ); + return 1; + } + } + return 0; +} + +static int setCurrentPage(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVPagerView* view = (__bridge LVPagerView *)(user->object); + if( lua_gettop(L)>=2 ) { + int luaPageIdx = lua_tonumber(L, 2); + BOOL animated = YES; + if( lua_gettop(L)>=3 ) { + animated = lua_toboolean(L, 3); + } + [view setCurrentPageIdx:unmapPageIdx(luaPageIdx) animation:animated]; + lua_settop(L, 1); + return 1; + } else { + NSInteger currentPageIdx = view.pageIdx; + lua_pushnumber( L, mapPageIdx(currentPageIdx) ); + return 1; + } + } + return 0; +} + +-(void) setAutoScrollInterval:(float) interval{ + _autoScrollInterval = interval; + NSInteger totalPages = self.cellArray.count; + if ( totalPages < 2 ){//小于两个没有效果 + [self stopTimer]; + return ; + } + if ( interval > 0.02 ) {//start timer + [self startTimer:interval repeat:YES]; + } else {//stop timer + [self stopTimer]; + } +} + +static int autoScroll(lua_State *L){ + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if(user){ + LVPagerView * view = (__bridge LVPagerView *)(user -> object); + + if(lua_gettop(L) >= 2) { + float interval = lua_tonumber(L, 2); + [view setAutoScrollInterval:interval]; + } + } + return 0; +} + +static int looping(lua_State *L){ + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if(user){ + LVPagerView * view = (__bridge LVPagerView *)(user -> object); + if( lua_gettop(L)>=2 ) { + BOOL ret = lua_toboolean(L, 2); + view.looping = ret; + return 0; + } else { + BOOL yes = view.looping; + lua_pushboolean(L, yes); + return 1; + } + } + return 0; +} + +#pragma -mark Timer +-(void) stopTimer{ + if( self.timer ) { + [self.timer invalidate]; + self.timer = nil; + } +} + +- (void) startTimer:(NSTimeInterval) interval repeat:(BOOL) repeat{ + self.looping = YES; + [self stopTimer]; + //create new timer + self.timer = [NSTimer scheduledTimerWithTimeInterval:interval target:self selector:@selector(scrollTimer:) userInfo:nil repeats:repeat]; +} + +- (void) scrollTimer:(NSTimer *) timer { + if( self.isScrollEndTimes>1 ) { + //更改方向 + NSInteger width = self.scrollview.frame.size.width; + CGPoint p = self.scrollview.contentOffset; + p.x += width; + p.x = ((NSInteger)p.x) /width * width; + self.nextOffset = p; + [self performSelectorOnMainThread:@selector(changeOffsetWithAnimation:) withObject:nil waitUntilDone:NO]; + } else { + self.isScrollEndTimes ++; + } +} + +static int indicator(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVPagerView* view = (__bridge LVPagerView *)(user->object); + if( lua_gettop(L)>=2 ) { + if ( lua_type(L, 2)==LUA_TNIL ) { + view.pagerIndicator = nil; + [view setIndicator:nil];// 设置Indicator + lua_pushvalue(L, 1); + lv_pushUDataRef(L, USERDATA_KEY_DELEGATE ); + lua_pushnil(L);// value + lua_setfield(L, -2, "Indicator"); + } else { + LVUserDataInfo * user2 = (LVUserDataInfo *)lua_touserdata(L, 2); + if( LVIsType(user2, View) ) { + LVPagerIndicator* pagerIndicator = (__bridge LVPagerIndicator *)(user2->object); + if( [pagerIndicator isKindOfClass:[LVPagerIndicator class]] ) { + [view setIndicator:pagerIndicator];// 设置Indicator + lua_pushvalue(L, 1); + lv_pushUDataRef(L, USERDATA_KEY_DELEGATE ); + lua_pushvalue(L, 2);// value + lua_setfield(L, -2, "Indicator"); + } + } + } + return 0; + } else { + lv_pushUDataRef(L, USERDATA_KEY_DELEGATE ); + lua_getfield(L, -2, "Indicator"); + return 1; + } + } + return 0; +} + +static int previewSide(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVPagerView* pagerview = (__bridge LVPagerView *)(user->object); + if( lua_gettop(L)>=3 ) { + CGFloat sideLeft = lua_tonumber(L, 2); + CGFloat sideRight = lua_tonumber(L, 3); + pagerview.sideLeft = sideLeft; + pagerview.sideRight = sideRight; + pagerview.frame = pagerview.frame; + if( pagerview.cellArray.count==2 ) { + [pagerview reloadDataASync]; + } + return 0; + } else { + lua_pushnumber(L, pagerview.sideLeft); + lua_pushnumber(L, pagerview.sideRight); + return 2; + } + } + return 0; +} + +#pragma -mark __gc +static void releaseUserDataView(LVUserDataInfo* userdata){ + if( userdata && userdata->object ){ + LVPagerView* view = CFBridgingRelease(userdata->object); + userdata->object = NULL; + if( view ){ + [view.timer invalidate]; + view.scrollview.delegate = nil; + [view.scrollview removeFromSuperview]; + NSArray* subviews = view.scrollview.subviews; + for( UIView* view in subviews ) { + [view removeFromSuperview]; + } + view.scrollview.scrollEnabled = NO; + view.scrollview = nil; + + view.lv_userData = nil; + view.lv_luaviewCore = nil; + [view removeFromSuperview]; + } + } +} + +static int __gc (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + releaseUserDataView(user); + return 0; +} + +static int initParams (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVPagerView* pageView = (__bridge LVPagerView *)(user->object); + int ret = lv_setCallbackByKey(L, nil, NO); + [pageView reloadDataASync]; + return ret; + } + return 0; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewPagerView globalName:globalName defaultName:@"PagerView"]; + + const struct luaL_Reg memberFunctions [] = { + {"initParams", initParams },// 回调 + {"reload", reload}, + {"showScrollBar", showScrollBar }, + {"currentPage", setCurrentPage }, + {"autoScroll", autoScroll}, // IOS: 需要支持正反滚动 + {"looping", looping}, + {"indicator", indicator}, + + {"previewSide", previewSide}, + + {"__gc", __gc }, + {NULL, NULL} + }; + + lv_createClassMetaTable(L ,META_TABLE_UIPageView); + + luaL_openlib(L, NULL, [LVBaseView baseMemberFunctions], 0); + luaL_openlib(L, NULL, [LVScrollView memberFunctions], 0); + luaL_openlib(L, NULL, memberFunctions, 0); + + const char* keys[] = { "addView", NULL};// 移除多余API + lv_luaTableRemoveKeys(L, keys ); + return 1; +} + + +- (void) callLuaWithScrolling{ + CGFloat offsetX = self.scrollview.contentOffset.x; + CGFloat pageWidth = self.scrollview.frame.size.width; + CGFloat pageIndex = offsetX/pageWidth; + + self.pageIdx = [self xindex2index:pageIndex]; + [self setPageIndicatorIdx:[self xindex2index:pageIndex + 0.5]]; + + lua_State* l = self.lv_luaviewCore.l; + if( l && self.lv_userData ){ + lua_settop(l, 0); + lua_checkstack32(l); + double intPart = 0; + double floatPart = modf( pageIndex, &intPart); + NSInteger pageIdx = self.pageIdx; + if( self.doubleMode&& pageIdx>=2 ) { + pageIdx -= 2; + } + lua_pushnumber(l, mapPageIdx( pageIdx ) ); + lua_pushnumber(l, floatPart); + lua_pushnumber(l, offsetX - intPart*pageWidth); + + lv_pushUserdata(l, self.lv_userData); + lv_pushUDataRef(l, USERDATA_KEY_DELEGATE); + + [LVUtil call:l key1:STR_CALLBACK key2:"Scrolling" key3:NULL nargs:3 nrets:0 retType:LUA_TNONE]; + } +} + +- (void) callLuaWithScrollEnded{ + { + CGFloat offsetX = self.scrollview.contentOffset.x; + CGFloat pageWidth = self.scrollview.frame.size.width; + CGFloat pageIndex = offsetX/pageWidth; + + self.pageIdx = [self xindex2index:pageIndex + 0.1]; + [self setPageIndicatorIdx:[self xindex2index:pageIndex + 0.1]]; + } + lua_State* l = self.lv_luaviewCore.l; + if( l && self.lv_userData ){ + lua_checkstack32(l); + NSInteger pageIdx = self.pageIdx; + if( self.doubleMode&& pageIdx>=2 ) { + pageIdx -= 2; + } + lua_pushnumber(l, mapPageIdx(pageIdx) ); + + lv_pushUserdata(l, self.lv_userData); + lv_pushUDataRef(l, USERDATA_KEY_DELEGATE); + + [LVUtil call:l key1:STR_CALLBACK key2:"ScrollEnd" key3:NULL nargs:1 nrets:0 retType:LUA_TNONE]; + } +} + +- (void)scrollViewDidScroll:(UIScrollView *)scrollView{ + [self moveCenter]; + [self checkCellVisible]; + + [self callLuaWithScrolling]; +} + +- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{ + self.isScrollEndTimes = 0; + [self lv_callLuaCallback:@STR_CALLBACK key2:@"ScrollBegin" argN:0]; +} +- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView{ + //[self lv_callLuaCallback:@STR_CALLBACK key2:@"BeginDecelerating"]; +} + +- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{ + [self callLuaWithScrolling]; + [self callLuaWithScrollEnded]; + self.isScrollEndTimes = 0; +} + +- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView{ + [self callLuaWithScrolling]; + [self callLuaWithScrollEnded]; +} + +- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event +{ + UIView *view = [super hitTest:point withEvent:event]; + if ([view isEqual:self]) + { + UIScrollView* scrollview = self.scrollview; + for (UIView *subview in scrollview.subviews) + { + CGPoint offset = CGPointMake(point.x - scrollview.frame.origin.x + scrollview.contentOffset.x - subview.frame.origin.x, + point.y - scrollview.frame.origin.y + scrollview.contentOffset.y - subview.frame.origin.y); + + if ((view = [subview hitTest:offset withEvent:event])) + { + return view; + } + } + return scrollview; + } + return view; +} + +-(NSString*) description{ + return [NSString stringWithFormat:@"", (int)[self hash], NSStringFromCGRect(self.frame) ]; +} +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPagerViewCell.h b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPagerViewCell.h new file mode 100644 index 00000000..8ee66ffc --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPagerViewCell.h @@ -0,0 +1,23 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LuaViewCore.h" + +@interface LVPagerViewCell : UIView + +@property (nonatomic, assign) NSInteger index; +@property (nonatomic, assign) BOOL isInited; + +-(void) pushTableToStack; + +-(void) doInitWithLView:(LuaViewCore*) lview; + +-(UIView*) contentView; + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPagerViewCell.m b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPagerViewCell.m new file mode 100644 index 00000000..66dc12ae --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPagerViewCell.m @@ -0,0 +1,66 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVPagerViewCell.h" +#import "LuaViewCore.h" +#import "lapi.h" + +@interface LVPagerViewCell () +@property (nonatomic,weak) LuaViewCore* lv_luaviewCore; +@end + +@implementation LVPagerViewCell + + + +-(void) dealloc{ + lua_State* L = self.lv_luaviewCore.l; + if( L ) { + [LVUtil unregistry:L key:self]; + } +} + +-(void) doInitWithLView:(LuaViewCore*) lview{ + self.lv_luaviewCore = lview; + lua_State* L = lview.l; + if( L ) { + lua_createtable(L, 0, 0); + [LVUtil registryValue:L key:self stack:-1]; + lv_luaTableSetWeakWindow(L, self); + } +} + +-(void) pushTableToStack{ + lua_State* L = self.lv_luaviewCore.l; + if( L ) { + [LVUtil pushRegistryValue:L key:self]; + } +} + +-(UIView*) contentView{ + return self; +} + +-(NSString*) description{ + return [NSString stringWithFormat:@"", (int)[self hash], NSStringFromCGRect(self.frame)]; +} + +- (void) layoutSubviews{ + [super layoutSubviews]; + [self lv_alignSubviews]; +} + +-(instancetype) init{ + self = [super init]; + if ( self ) { + self.clipsToBounds = YES; + } + return self; +} + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPanGesture.h b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPanGesture.h new file mode 100644 index 00000000..222b2889 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPanGesture.h @@ -0,0 +1,23 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" +#import "NSObject+LuaView.h" + +@interface LVPanGesture : UIPanGestureRecognizer + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; + +-(id) init:(lua_State*) l; + + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPanGesture.m b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPanGesture.m new file mode 100644 index 00000000..0eeada88 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPanGesture.m @@ -0,0 +1,74 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVPanGesture.h" +#import "LVGesture.h" +#import "LView.h" +#import "LVHeads.h" + +@implementation LVPanGesture + + +-(void) dealloc{ + [LVGesture releaseUD:_lv_userData]; +} + +-(id) init:(lua_State*) l{ + self = [super initWithTarget:self action:@selector(handleGesture:)]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + } + return self; +} + +-(void) handleGesture:(LVPanGesture*)sender { + lua_State* l = self.lv_luaviewCore.l; + if ( l ){ + lua_checkstack32(l); + lv_pushUserdata(l,self.lv_userData); + [LVUtil call:l lightUserData:self key1:"callback" key2:NULL nargs:1]; + } +} + +static int lvNewPanGestureRecognizer (lua_State *L) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVPanGesture class]]; + { + LVPanGesture* gesture = [[c alloc] init:L]; + + if( lua_type(L, 1) == LUA_TFUNCTION ) { + [LVUtil registryValue:L key:gesture stack:1]; + } + + { + NEW_USERDATA(userData, Gesture); + gesture.lv_userData = userData; + userData->object = CFBridgingRetain(gesture); + + luaL_getmetatable(L, META_TABLE_PanGesture ); + lua_setmetatable(L, -2); + } + } + return 1; /* new userdatum is already on the stack */ +} + + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewPanGestureRecognizer globalName:globalName defaultName:@"PanGesture"]; + + const struct luaL_Reg memberFunctions [] = { + {NULL, NULL} + }; + + lv_createClassMetaTable(L, META_TABLE_PanGesture); + + luaL_openlib(L, NULL, [LVGesture baseMemberFunctions], 0); + luaL_openlib(L, NULL, memberFunctions, 0); + return 1; +} + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPinchGesture.h b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPinchGesture.h new file mode 100644 index 00000000..991a608a --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPinchGesture.h @@ -0,0 +1,24 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "NSObject+LuaView.h" +#import "LVHeads.h" + +@interface LVPinchGesture : UIPinchGestureRecognizer + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; + +-(id) init:(lua_State*) l; + + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPinchGesture.m b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPinchGesture.m new file mode 100644 index 00000000..1acd2e8a --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPinchGesture.m @@ -0,0 +1,87 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVPinchGesture.h" +#import "LVGesture.h" +#import "LView.h" +#import "LVHeads.h" + +@implementation LVPinchGesture + +-(void) dealloc{ + LVLog(@"LVPinchGesture.dealloc"); + [LVGesture releaseUD:_lv_userData]; +} + +-(id) init:(lua_State*) l{ + self = [super initWithTarget:self action:@selector(handleGesture:)]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + } + return self; +} + +-(void) handleGesture:(LVPinchGesture*)sender { + lua_State* l = self.lv_luaviewCore.l; + if ( l ){ + lua_checkstack32(l); + lv_pushUserdata(l,self.lv_userData); + [LVUtil call:l lightUserData:self key1:"callback" key2:NULL nargs:1]; + } +} + +static int lvNewPinchGestureRecognizer (lua_State *L) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVPinchGesture class]]; + { + LVPinchGesture* gesture = [[c alloc] init:L]; + + if( lua_type(L, 1) != LUA_TFUNCTION ) { + [LVUtil registryValue:L key:gesture stack:1]; + } + + { + NEW_USERDATA(userData, Gesture); + gesture.lv_userData = userData; + userData->object = CFBridgingRetain(gesture); + + luaL_getmetatable(L, META_TABLE_PinchGesture ); + lua_setmetatable(L, -2); + } + } + return 1; /* new userdatum is already on the stack */ +} + +static int scale (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( LVIsType(user, Gesture) ){ + LVPinchGesture* gesture = (__bridge LVPinchGesture *)(user->object); + float s = gesture.scale; + lua_pushnumber(L, s); + return 1; + } + return 0; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewPinchGestureRecognizer globalName:globalName defaultName:@"PinchGesture"]; + + lv_createClassMetaTable(L ,META_TABLE_PinchGesture); + + luaL_openlib(L, NULL, [LVGesture baseMemberFunctions], 0); + + { + const struct luaL_Reg memberFunctions [] = { + {"scale", scale}, + {NULL, NULL} + }; + luaL_openlib(L, NULL, memberFunctions, 0); + } + return 1; +} + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPointerValueBox.h b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPointerValueBox.h new file mode 100644 index 00000000..8286f1d6 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPointerValueBox.h @@ -0,0 +1,17 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import + +@interface LVPointerValueBox : NSObject + +-(id) initWithPointer:(void*) pointer; + +@property (nonatomic, assign) void* pointer; + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPointerValueBox.m b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPointerValueBox.m new file mode 100644 index 00000000..08c050d0 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPointerValueBox.m @@ -0,0 +1,22 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVPointerValueBox.h" + +@implementation LVPointerValueBox + +-(id) initWithPointer:(void*) pointer{ + self = [super init]; + if ( self ){ + self.pointer = pointer; + } + return self; +} + + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRefreshComponent.h b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRefreshComponent.h new file mode 100644 index 00000000..003cc6d6 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRefreshComponent.h @@ -0,0 +1,81 @@ + +#import +#import "LVRefreshConst.h" +#import "UIScrollView+LVRefresh.h" + +/** 刷新控件的状态 */ +typedef NS_ENUM(NSInteger, LVRefreshState) { + /** 普通闲置状态 */ + LVRefreshStateIdle = 1, + /** 松开就可以进行刷新的状态 */ + LVRefreshStatePulling, + /** 正在刷新中的状态 */ + LVRefreshStateRefreshing, + /** 即将刷新的状态 */ + LVRefreshStateWillRefresh, + /** 所有数据加载完毕,没有更多的数据了 */ + LVRefreshStateNoMoreData +}; + +/** 进入刷新状态的回调 */ +typedef void (^LVRefreshComponentRefreshingBlock)(); + +/** 刷新控件的基类 */ +@interface LVRefreshComponent : UIView +{ + /** 记录scrollView刚开始的inset */ + UIEdgeInsets _scrollViewOriginalInset; + /** 父控件 */ + __weak UIScrollView *_scrollView; +} +#pragma mark - 刷新回调 +/** 正在刷新的回调 */ +@property (copy, nonatomic) LVRefreshComponentRefreshingBlock refreshingBlock; +/** 设置回调对象和回调方法 */ +- (void)setRefreshingTarget:(id)target refreshingAction:(SEL)action; +/** 回调对象 */ +@property (weak, nonatomic) id refreshingTarget; +/** 回调方法 */ +@property (assign, nonatomic) SEL refreshingAction; +/** 触发回调(交给子类去调用) */ +- (void)executeRefreshingCallback; + +#pragma mark - 刷新状态控制 +/** 进入刷新状态 */ +- (void)beginRefreshing; +/** 结束刷新状态 */ +- (void)endRefreshing; +/** 是否正在刷新 */ +- (BOOL)isRefreshing; +/** 刷新状态 一般交给子类内部实现 */ +@property (assign, nonatomic) LVRefreshState state; + +#pragma mark - 交给子类去访问 +/** 记录scrollView刚开始的inset */ +@property (assign, nonatomic, readonly) UIEdgeInsets scrollViewOriginalInset; +/** 父控件 */ +@property (weak, nonatomic, readonly) UIScrollView *scrollView; + +#pragma mark - 交给子类们去实现 +/** 初始化 */ +- (void)prepare NS_REQUIRES_SUPER; +/** 摆放子控件frame */ +- (void)placeSubviews NS_REQUIRES_SUPER; +/** 当scrollView的contentOffset发生改变的时候调用 */ +- (void)scrollViewContentOffsetDidChange:(NSDictionary *)change NS_REQUIRES_SUPER; +/** 当scrollView的contentSize发生改变的时候调用 */ +- (void)scrollViewContentSizeDidChange:(NSDictionary *)change NS_REQUIRES_SUPER; +/** 当scrollView的拖拽状态发生改变的时候调用 */ +- (void)scrollViewPanStateDidChange:(NSDictionary *)change NS_REQUIRES_SUPER; + + +#pragma mark - 其他 +/** 拉拽的百分比(交给子类重写) */ +@property (assign, nonatomic) CGFloat pullingPercent; +/** 根据拖拽比例自动切换透明度 */ +@property (assign, nonatomic, getter=isAutomaticallyChangeAlpha) BOOL automaticallyChangeAlpha; +@end + +@interface UILabel(LVRefresh) ++ (instancetype)label; +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRefreshComponent.m b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRefreshComponent.m new file mode 100644 index 00000000..236d6ef0 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRefreshComponent.m @@ -0,0 +1,227 @@ + + +#import "LVRefreshComponent.h" +#import "LVRefreshConst.h" +#import +#import + + + +@interface LVRefreshComponent() +@property (strong, nonatomic) UIPanGestureRecognizer *pan; +@end + +@implementation LVRefreshComponent +#pragma mark - 初始化 +- (instancetype)initWithFrame:(CGRect)frame +{ + if (self = [super initWithFrame:frame]) { + // 准备工作 + [self prepare]; + + // 默认是普通状态 + self.state = LVRefreshStateIdle; + } + return self; +} + +- (void)prepare +{ + // 基本属性 + self.autoresizingMask = UIViewAutoresizingFlexibleWidth; + self.backgroundColor = [UIColor clearColor]; +} + +- (void)layoutSubviews +{ + [super layoutSubviews]; + + [self placeSubviews]; +} + +- (void)placeSubviews{} + +- (void)willMoveToSuperview:(UIView *)newSuperview +{ + [super willMoveToSuperview:newSuperview]; + + // 如果不是UIScrollView,不做任何事情 + if (newSuperview && ![newSuperview isKindOfClass:[UIScrollView class]]) return; + + // 旧的父控件移除监听 + [self removeObservers]; + + if (newSuperview) { // 新的父控件 + // 设置宽度 + { + CGRect f = self.frame; + f.size.width = newSuperview.frame.size.width; + self.frame = f; + } + // 设置位置 + { + CGRect f = self.frame; + f.origin.x = 0; + self.frame = f; + } + + // 记录UIScrollView + _scrollView = (UIScrollView *)newSuperview; + // 设置永远支持垂直弹簧效果 + _scrollView.alwaysBounceVertical = YES; + // 记录UIScrollView最开始的contentInset + _scrollViewOriginalInset = _scrollView.contentInset; + + // 添加监听 + [self addObservers]; + } +} + +- (void)drawRect:(CGRect)rect +{ + [super drawRect:rect]; + + if (self.state == LVRefreshStateWillRefresh) { + // 预防view还没显示出来就调用了beginRefreshing + self.state = LVRefreshStateRefreshing; + } +} + +#pragma mark - KVO监听 +- (void)addObservers +{ + NSKeyValueObservingOptions options = NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld; + [self.scrollView addObserver:self forKeyPath:LVRefreshKeyPathContentOffset options:options context:nil]; + [self.scrollView addObserver:self forKeyPath:LVRefreshKeyPathContentSize options:options context:nil]; + self.pan = self.scrollView.panGestureRecognizer; + [self.pan addObserver:self forKeyPath:LVRefreshKeyPathPanState options:options context:nil]; +} + +- (void)removeObservers +{ + [self.superview removeObserver:self forKeyPath:LVRefreshKeyPathContentOffset]; + [self.superview removeObserver:self forKeyPath:LVRefreshKeyPathContentSize];; + [self.pan removeObserver:self forKeyPath:LVRefreshKeyPathPanState]; + self.pan = nil; +} + +- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context +{ + // 遇到这些情况就直接返回 + if (!self.userInteractionEnabled) return; + + // 这个就算看不见也需要处理 + if ([keyPath isEqualToString:LVRefreshKeyPathContentSize]) { + [self scrollViewContentSizeDidChange:change]; + } + + // 看不见 + if (self.hidden) return; + if ([keyPath isEqualToString:LVRefreshKeyPathContentOffset]) { + [self scrollViewContentOffsetDidChange:change]; + } else if ([keyPath isEqualToString:LVRefreshKeyPathPanState]) { + [self scrollViewPanStateDidChange:change]; + } +} + +- (void)scrollViewContentOffsetDidChange:(NSDictionary *)change{} +- (void)scrollViewContentSizeDidChange:(NSDictionary *)change{} +- (void)scrollViewPanStateDidChange:(NSDictionary *)change{} + +#pragma mark - 公共方法 +#pragma mark 设置回调对象和回调方法 +- (void)setRefreshingTarget:(id)target refreshingAction:(SEL)action +{ + self.refreshingTarget = target; + self.refreshingAction = action; +} + +#pragma mark 进入刷新状态 +- (void)beginRefreshing +{ + [UIView animateWithDuration:LVRefreshFastAnimationDuration animations:^{ + self.alpha = 1.0; + }]; + self.pullingPercent = 1.0; + // 只要正在刷新,就完全显示 + if (self.window) { + self.state = LVRefreshStateRefreshing; + } else { + self.state = LVRefreshStateWillRefresh; + // 刷新(预防从另一个控制器回到这个控制器的情况,回来要重新刷新一下) + [self setNeedsDisplay]; + } +} + +#pragma mark 结束刷新状态 +- (void)endRefreshing +{ + self.state = LVRefreshStateIdle; +} + +#pragma mark 是否正在刷新 +- (BOOL)isRefreshing +{ + return self.state == LVRefreshStateRefreshing || self.state == LVRefreshStateWillRefresh; +} + +#pragma mark 自动切换透明度 +- (void)setAutoChangeAlpha:(BOOL)autoChangeAlpha +{ + self.automaticallyChangeAlpha = autoChangeAlpha; +} + +- (BOOL)isAutoChangeAlpha +{ + return self.isAutomaticallyChangeAlpha; +} + +- (void)setAutomaticallyChangeAlpha:(BOOL)automaticallyChangeAlpha +{ + _automaticallyChangeAlpha = automaticallyChangeAlpha; + + if (self.isRefreshing) return; + + if (automaticallyChangeAlpha) { + self.alpha = self.pullingPercent; + } else { + self.alpha = 1.0; + } +} + +#pragma mark 根据拖拽进度设置透明度 +- (void)setPullingPercent:(CGFloat)pullingPercent +{ + _pullingPercent = pullingPercent; + + if (self.isRefreshing) return; + + if (self.isAutomaticallyChangeAlpha) { + self.alpha = pullingPercent; + } +} + +#pragma mark - 内部方法 +- (void)executeRefreshingCallback +{ + dispatch_async(dispatch_get_main_queue(), ^{ + if (self.refreshingBlock) { + self.refreshingBlock(); + } + if ([self.refreshingTarget respondsToSelector:self.refreshingAction]) { + LVRefreshMsgSend(LVRefreshMsgTarget(self.refreshingTarget), self.refreshingAction, self); + } + }); +} +@end + +@implementation UILabel(LVRefresh) ++ (instancetype)label +{ + UILabel *label = [[self alloc] init]; + label.autoresizingMask = UIViewAutoresizingFlexibleWidth; + label.textAlignment = NSTextAlignmentCenter; + label.backgroundColor = [UIColor clearColor]; + return label; +} +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRefreshConst.h b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRefreshConst.h new file mode 100644 index 00000000..04e8a95e --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRefreshConst.h @@ -0,0 +1,25 @@ + +#import +#import + + +//// 运行时objc_msgSend +#define LVRefreshMsgSend(...) ((void (*)(void *, SEL, UIView *))objc_msgSend)(__VA_ARGS__) +#define LVRefreshMsgTarget(target) (__bridge void *)(target) + + +//// 常量 +UIKIT_EXTERN const CGFloat LVRefreshHeaderHeight; +UIKIT_EXTERN const CGFloat LVRefreshFastAnimationDuration; +UIKIT_EXTERN const CGFloat LVRefreshSlowAnimationDuration; + +UIKIT_EXTERN NSString *const LVRefreshKeyPathContentOffset; +UIKIT_EXTERN NSString *const LVRefreshKeyPathContentSize; +UIKIT_EXTERN NSString *const LVRefreshKeyPathContentInset; +UIKIT_EXTERN NSString *const LVRefreshKeyPathPanState; + +// 状态检查 +#define LVRefreshCheckState \ +LVRefreshState oldState = self.state; \ +if (state == oldState) return; \ +[super setState:state]; diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRefreshConst.m b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRefreshConst.m new file mode 100644 index 00000000..8ffa2d45 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRefreshConst.m @@ -0,0 +1,12 @@ + +#import + +const CGFloat LVRefreshHeaderHeight = 54.0; +const CGFloat LVRefreshFooterHeight = 44.0; +const CGFloat LVRefreshFastAnimationDuration = 0.25; +const CGFloat LVRefreshSlowAnimationDuration = 0.4; + +NSString *const LVRefreshKeyPathContentOffset = @"contentOffset"; +NSString *const LVRefreshKeyPathContentInset = @"contentInset"; +NSString *const LVRefreshKeyPathContentSize = @"contentSize"; +NSString *const LVRefreshKeyPathPanState = @"state"; diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRefreshHeader.h b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRefreshHeader.h new file mode 100644 index 00000000..b0002ccf --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRefreshHeader.h @@ -0,0 +1,18 @@ + +#import "LVRefreshComponent.h" + +@interface LVRefreshHeader : LVRefreshComponent +/** 创建header */ ++ (instancetype)headerWithRefreshingBlock:(LVRefreshComponentRefreshingBlock)refreshingBlock; +/** 创建header */ ++ (instancetype)headerWithRefreshingTarget:(id)target refreshingAction:(SEL)action; + +/** 这个key用来存储上一次下拉刷新成功的时间 */ +@property (copy, nonatomic) NSString *lastUpdatedTimeKey; +/** 上一次下拉刷新成功的时间 */ +@property (strong, nonatomic, readonly) NSDate *lastUpdatedTime; + +/** 忽略多少scrollView的contentInset的top */ +@property (assign, nonatomic) CGFloat ignoredScrollViewContentInsetTop; + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRefreshHeader.m b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRefreshHeader.m new file mode 100644 index 00000000..7ce1ebae --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRefreshHeader.m @@ -0,0 +1,181 @@ + + +#import "LVRefreshHeader.h" + +@interface LVRefreshHeader() +@property (assign, nonatomic) CGFloat insetTDelta; +@end + +@implementation LVRefreshHeader +#pragma mark - 构造方法 ++ (instancetype)headerWithRefreshingBlock:(LVRefreshComponentRefreshingBlock)refreshingBlock +{ + LVRefreshHeader *cmp = [[self alloc] init]; + cmp.refreshingBlock = refreshingBlock; + return cmp; +} ++ (instancetype)headerWithRefreshingTarget:(id)target refreshingAction:(SEL)action +{ + LVRefreshHeader *cmp = [[self alloc] init]; + [cmp setRefreshingTarget:target refreshingAction:action]; + return cmp; +} +#pragma mark - 覆盖父类的方法 +- (void)prepare +{ + [super prepare]; + + // 设置key + self.lastUpdatedTimeKey = @"LVRefreshHeaderLastUpdatedTimeKey"; + + // 设置高度f + { + CGRect frame = self.frame; + frame.size.height = LVRefreshHeaderHeight; + self.frame = frame; + } +} + +- (void)placeSubviews +{ + [super placeSubviews]; + + // 设置y值(当自己的高度发生改变了,肯定要重新调整Y值,所以放到placeSubviews方法中设置y值) + { + CGRect frame = self.frame; + frame.origin.y = - frame.size.height - self.ignoredScrollViewContentInsetTop; + self.frame = frame; + } +} + +- (void)scrollViewContentOffsetDidChange:(NSDictionary *)change +{ + [super scrollViewContentOffsetDidChange:change]; + + // 在刷新的refreshing状态 + if (self.state == LVRefreshStateRefreshing) { + if (self.window == nil) return; + + // sectionheader停留解决 + CGPoint offset = self.scrollView.contentOffset; + CGFloat insetT = - offset.y > _scrollViewOriginalInset.top ? - offset.y : _scrollViewOriginalInset.top; + { + CGRect f = self.frame; + insetT = insetT > f.size.height + _scrollViewOriginalInset.top ? f.size.height + _scrollViewOriginalInset.top : insetT; + } + { + UIEdgeInsets inset = self.scrollView.contentInset; + inset.top = insetT; + self.scrollView.contentInset = inset; + } + + self.insetTDelta = _scrollViewOriginalInset.top - insetT; + return; + } + + // 跳转到下一个控制器时,contentInset可能会变 + _scrollViewOriginalInset = self.scrollView.contentInset; + + // 当前的contentOffset + CGPoint offset = self.scrollView.contentOffset; + CGFloat offsetY = offset.y; + // 头部控件刚好出现的offsetY + CGFloat happenOffsetY = - self.scrollViewOriginalInset.top; + + // 如果是向上滚动到看不见头部控件,直接返回 + // >= -> > + if (offsetY > happenOffsetY) return; + + // 普通 和 即将刷新 的临界点 + CGRect f = self.frame; + CGFloat normal2pullingOffsetY = happenOffsetY - f.size.height; + CGFloat pullingPercent = (happenOffsetY - offsetY) / f.size.height; + + if (self.scrollView.isDragging) { // 如果正在拖拽 + self.pullingPercent = pullingPercent; + if (self.state == LVRefreshStateIdle && offsetY < normal2pullingOffsetY) { + // 转为即将刷新状态 + self.state = LVRefreshStatePulling; + } else if (self.state == LVRefreshStatePulling && offsetY >= normal2pullingOffsetY) { + // 转为普通状态 + self.state = LVRefreshStateIdle; + } + } else if (self.state == LVRefreshStatePulling) {// 即将刷新 && 手松开 + // 开始刷新 + [self beginRefreshing]; + } else if (pullingPercent < 1) { + self.pullingPercent = pullingPercent; + } +} + +- (void)setState:(LVRefreshState)state +{ + LVRefreshCheckState + + // 根据状态做事情 + if (state == LVRefreshStateIdle) { + if (oldState != LVRefreshStateRefreshing) return; + + // 保存刷新时间 + [[NSUserDefaults standardUserDefaults] setObject:[NSDate date] forKey:self.lastUpdatedTimeKey]; + [[NSUserDefaults standardUserDefaults] synchronize]; + + // 恢复inset和offset + [UIView animateWithDuration:LVRefreshSlowAnimationDuration animations:^{ + { + UIEdgeInsets inset = self.scrollView.contentInset; + inset.top += self.insetTDelta; + self.scrollView.contentInset = inset; + } + // 自动调整透明度 + if (self.isAutomaticallyChangeAlpha) self.alpha = 0.0; + } completion:^(BOOL finished) { + self.pullingPercent = 0.0; + }]; + } else if (state == LVRefreshStateRefreshing) { + [UIView animateWithDuration:LVRefreshFastAnimationDuration animations:^{ + // 增加滚动区域 + CGRect f = self.frame; + CGFloat top = self.scrollViewOriginalInset.top + f.size.height; + { + UIEdgeInsets inset = self.scrollView.contentInset; + inset.top = top; + self.scrollView.contentInset = inset; + } + + // 设置滚动位置 + { + CGPoint offset = self.scrollView.contentOffset; + offset.y = - top; + self.scrollView.contentOffset = offset; + } + } completion:^(BOOL finished) { + [self executeRefreshingCallback]; + }]; + } +} + +- (void)drawRect:(CGRect)rect +{ + [super drawRect:rect]; + + +} + +#pragma mark - 公共方法 +- (void)endRefreshing +{ + if ([self.scrollView isKindOfClass:[UICollectionView class]]) { + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + [super endRefreshing]; + }); + } else { + [super endRefreshing]; + } +} + +- (NSDate *)lastUpdatedTime +{ + return [[NSUserDefaults standardUserDefaults] objectForKey:self.lastUpdatedTimeKey]; +} +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRotationGesture.h b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRotationGesture.h new file mode 100644 index 00000000..6f1c248f --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRotationGesture.h @@ -0,0 +1,22 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" +#import "NSObject+LuaView.h" + +@interface LVRotationGesture : UIRotationGestureRecognizer + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; + +-(id) init:(lua_State*) l; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRotationGesture.m b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRotationGesture.m new file mode 100644 index 00000000..5ace6f9a --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRotationGesture.m @@ -0,0 +1,88 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVRotationGesture.h" +#import "LVGesture.h" +#import "LView.h" +#import "LVHeads.h" + +@implementation LVRotationGesture + +-(void) dealloc{ + LVLog(@"LVRotationGesture.dealloc"); + [LVGesture releaseUD:_lv_userData]; +} + +-(id) init:(lua_State*) l{ + self = [super initWithTarget:self action:@selector(handleGesture:)]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + } + return self; +} + +-(void) handleGesture:(LVRotationGesture*)sender { + lua_State* l = self.lv_luaviewCore.l; + if ( l ){ + lua_checkstack32(l); + lv_pushUserdata(l,self.lv_userData); + [LVUtil call:l lightUserData:self key1:"callback" key2:NULL nargs:1]; + } +} + +static int lvNewRotationGestureRecognizer (lua_State *L) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVRotationGesture class]]; + { + LVRotationGesture* gesture = [[c alloc] init:L]; + + if( lua_type(L, 1) == LUA_TFUNCTION ) { + [LVUtil registryValue:L key:gesture stack:1]; + } + + { + NEW_USERDATA(userData, Gesture); + gesture.lv_userData = userData; + userData->object = CFBridgingRetain(gesture); + + luaL_getmetatable(L, META_TABLE_RotaionGesture ); + lua_setmetatable(L, -2); + } + } + return 1; /* new userdatum is already on the stack */ +} + +static int rotation (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( LVIsType(user, Gesture) ){ + LVRotationGesture* gesture = (__bridge LVRotationGesture *)(user->object); + float s = gesture.rotation; + lua_pushnumber(L, s); + return 1; + } + return 0; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewRotationGestureRecognizer globalName:globalName defaultName:@"RotationGesture"]; + + lv_createClassMetaTable(L ,META_TABLE_RotaionGesture); + + luaL_openlib(L, NULL, [LVGesture baseMemberFunctions], 0); + + { + const struct luaL_Reg memberFunctions [] = { + {"rotation", rotation}, + {NULL, NULL} + }; + luaL_openlib(L, NULL, memberFunctions, 0); + } + return 1; +} + + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVScrollView.h b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVScrollView.h new file mode 100644 index 00000000..2f48ec67 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVScrollView.h @@ -0,0 +1,28 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" +#import "UIScrollView+LuaView.h" + +@interface LVScrollView : UIScrollView + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; +@property(nonatomic,assign) NSUInteger lv_align; +@property(nonatomic,strong) CAShapeLayer* lv_shapeLayer; + +-(id) init:(lua_State*) l; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + ++(const struct luaL_Reg*) memberFunctions; + +@property(nonatomic,weak) id lvScrollViewDelegate; + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVScrollView.m b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVScrollView.m new file mode 100644 index 00000000..1b645023 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVScrollView.m @@ -0,0 +1,395 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVScrollView.h" +#import "LVBaseView.h" +#import "LVUtil.h" +#import "UIScrollView+LuaView.h" +#import "LVScrollViewDelegate.h" +#import "LVHeads.h" +#import "LView.h" + +@interface LVScrollView () +@property (nonatomic,strong) LVScrollViewDelegate* scrollViewDelegate; +@end + +@implementation LVScrollView + + +-(id) init:(lua_State*) l{ + self = [super init]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + self.scrollViewDelegate = [[LVScrollViewDelegate alloc] init:self]; + self.delegate = self.scrollViewDelegate; + self.alwaysBounceHorizontal = YES; + self.alwaysBounceVertical = NO; + self.showsHorizontalScrollIndicator = NO; + self.showsVerticalScrollIndicator = NO; + self.scrollsToTop = NO; + } + return self; +} + +-(void) setLvScrollViewDelegate:(id)lvScrollViewDelegate{ + _lvScrollViewDelegate = lvScrollViewDelegate; + self.scrollViewDelegate.delegate = lvScrollViewDelegate; +} + +-(void) dealloc{ +} + +- (BOOL)touchesShouldCancelInContentView:(UIView *)view { + return YES; +} + +- (void) layoutSubviews{ + [super layoutSubviews]; + [self lv_alignSubviews]; + [self lv_callLuaCallback:@STR_ON_LAYOUT]; +} + +#pragma -mark ScrollView +static int lvNewScrollView (lua_State *L) { + { + Class c = [LVUtil upvalueClass:L defaultClass:[LVScrollView class]]; + + LVScrollView* scrollView = [[c alloc] init:L]; + + NEW_USERDATA(userData, View); + userData->object = CFBridgingRetain(scrollView); + scrollView.lv_userData = userData; + + //创建delegate用的事件存储器 + lua_createtable(L, 0, 0); + lv_udataRef(L, USERDATA_KEY_DELEGATE ); + + luaL_getmetatable(L, META_TABLE_UIScrollView ); + lua_setmetatable(L, -2); + + LuaViewCore* view = LV_LUASTATE_VIEW(L); + if( view ){ + [view containerAddSubview:scrollView]; + } + } + return 1; /* new userdatum is already on the stack */ +} + +static int contentSize (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIScrollView* view = (__bridge UIScrollView *)(user->object); + if( [view isKindOfClass:[UIScrollView class]] ){ + if( lua_gettop(L)>=2 ) { + double w = lua_tonumber(L, 2);// 2 + double h = lua_tonumber(L, 3);// 3 + CGSize s = CGSizeMake( w, h ); + if ( isNormalSize(s) ) { + view.contentSize = s; + } + return 0; + } else { + CGSize s = view.contentSize; + lua_pushnumber(L, s.width ); + lua_pushnumber(L, s.height ); + return 2; + } + } + } + return 0; +} + +static int contentOffset (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIScrollView* view = (__bridge UIScrollView *)(user->object); + if( lua_gettop(L)>=2 ) { + double x = lua_tonumber(L, 2);// 2 + double y = lua_tonumber(L, 3);// 3 + BOOL yes = NO; + if( lua_gettop(L)>=4 ) + yes = lua_toboolean(L, 4);// 3 + if( [view isKindOfClass:[UIScrollView class]] ){ + CGPoint p = CGPointMake(x, y); + if( isNormalPoint(p) ) { + CGRect r = view.frame; + r.origin.x = x; + r.origin.y = y; + if( x > view.contentSize.width-view.frame.size.width ) { + x = view.contentSize.width-view.frame.size.width; + } + if( x < 0 ) { + x = 0; + } + if( y > view.contentSize.height-view.frame.size.height ) { + y = view.contentSize.height-view.frame.size.height; + } + if( y < 0 ) { + y = 0; + } + [view setContentOffset:CGPointMake(x, y) animated:yes]; + } + return 0; + } + } else { + CGPoint p = view.contentOffset; + lua_pushnumber(L, p.x ); + lua_pushnumber(L, p.y ); + return 2; + } + } + return 0; +} + +static int contentInset (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIScrollView* view = (__bridge UIScrollView *)(user->object); + if( [view isKindOfClass:[UIScrollView class]] ){ + int num = lua_gettop(L); + if( num>=2 ) { + UIEdgeInsets edgeInsets = view.contentInset; + if( num>=2 ) + edgeInsets.top = lua_tonumber(L, 2); + if( num>=3 ) + edgeInsets.left = lua_tonumber(L, 3); + if( num>=4 ) + edgeInsets.bottom = lua_tonumber(L, 4); + if( num>=5 ) + edgeInsets.right = lua_tonumber(L, 5); + if( isNormalEdgeInsets(edgeInsets) ) { + view.contentInset = edgeInsets; + view.scrollIndicatorInsets = edgeInsets; + } + return 0; + } else { + UIEdgeInsets edgeInsets = view.contentInset; + lua_pushnumber(L, edgeInsets.top ); + lua_pushnumber(L, edgeInsets.left ); + lua_pushnumber(L, edgeInsets.bottom ); + lua_pushnumber(L, edgeInsets.right ); + return 4; + } + } + } + return 0; +} + +//static int pageEnable (lua_State *L) { +// LVUserDataView * user = (LVUserDataView *)lua_touserdata(L, 1); +// if( user ){ +// UIScrollView* view = (__bridge UIScrollView *)(user->view); +// if( [view isKindOfClass:[UIScrollView class]] ){ +// if( lua_gettop(L)>=2 ) { +// BOOL yes = lua_toboolean(L, 2);// 2 +// view.pagingEnabled = yes; +// return 0; +// } else { +// lua_pushnumber(L, view.pagingEnabled ); +// return 1; +// } +// } +// } +// return 0; +//} + +static int showScrollIndicator (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIScrollView* view = (__bridge UIScrollView *)(user->object); + if( [view isKindOfClass:[UIScrollView class]] ){ + if( lua_gettop(L)>=2 ) { + BOOL yes1 = lua_toboolean(L, 2); + BOOL yes2 = lua_toboolean(L, 3); + view.showsHorizontalScrollIndicator = yes1; + view.showsVerticalScrollIndicator = yes2; + return 0; + } else { + lua_pushboolean(L, view.showsHorizontalScrollIndicator ); + lua_pushboolean(L, view.showsVerticalScrollIndicator ); + return 2; + } + } + } + return 0; +} + +//static int initRefreshHeader (lua_State *L) { +// LVUserDataView * user = (LVUserDataView *)lua_touserdata(L, 1); +// if( user ){ +// UIScrollView* scrollView = (__bridge UIScrollView *)(user->view); +// [scrollView lv_initRefreshHeader]; +// } +// return 0; +//} + +static int startHeaderRefreshing (lua_State *L){ + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVScrollView* scrollView = (__bridge LVScrollView *)(user->object); + [scrollView lv_beginRefreshing]; + } + return 0; +} + +static int stopHeaderRefreshing (lua_State *L){ + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVScrollView* scrollView = (__bridge LVScrollView *)(user->object); + [scrollView lv_endRefreshing]; + } + return 0; +} + +static int isHeaderRefreshing (lua_State *L){ + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVScrollView* scrollView = (__bridge LVScrollView *)(user->object); + BOOL yes = [scrollView lv_isRefreshing]; + lua_pushboolean(L, yes); + return 1; + } + return 0; +} + +//static int footerNoticeNoMoreData (lua_State *L){ +// LVUserDataView * user = (LVUserDataView *)lua_touserdata(L, 1); +// if( user ){ +// LVScrollView* scrollView = (__bridge LVScrollView *)(user->view); +// [scrollView lv_noticeNoMoreData]; +// } +// return 0; +//} +// +//static int footerResetNoMoreData (lua_State *L){ +// LVUserDataView * user = (LVUserDataView *)lua_touserdata(L, 1); +// if( user ){ +// LVScrollView* scrollView = (__bridge LVScrollView *)(user->view); +// [scrollView lv_resetNoMoreData]; +// } +// return 0; +//} +// +//static int hiddenRefreshFooter (lua_State *L){ +// LVUserDataView * user = (LVUserDataView *)lua_touserdata(L, 1); +// if( user ){ +// LVScrollView* scrollView = (__bridge LVScrollView *)(user->view); +// BOOL hidden = lua_toboolean(L, 2); +// [scrollView lv_hiddenRefreshFooter:hidden]; +// } +// return 0; +//} + +//static int alwaysBounce(lua_State *L) { +// LVUserDataView * user = (LVUserDataView *)lua_touserdata(L, 1); +// if( user ){ +// UIScrollView* view = (__bridge UIScrollView *)(user->view); +// if( [view isKindOfClass:[UIScrollView class]] ){ +// if( lua_gettop(L)>=2 ) { +// BOOL yesVertical = lua_toboolean(L, 2); +// BOOL yesHorizontal = lua_toboolean(L, 3); +// view.alwaysBounceVertical = yesVertical; +// view.alwaysBounceHorizontal = yesHorizontal; +// return 0; +// } else { +// lua_pushboolean(L, view.alwaysBounceVertical); +// lua_pushboolean(L, view.alwaysBounceHorizontal); +// return 2; +// } +// } +// } +// return 0; +//} + +static int callback (lua_State *L) { + return lv_setCallbackByKey(L, nil, NO); +} + +static void releaseUserDataView(LVUserDataInfo* userdata){ + if( userdata && userdata->object ){ + UIView* view = CFBridgingRelease(userdata->object); + userdata->object = NULL; + if( view ){ + view.lv_userData = nil; + view.lv_luaviewCore = nil; + [view removeFromSuperview]; + [view.layer removeFromSuperlayer]; + if( [view isKindOfClass:[UICollectionView class]] ) { + UICollectionView* collectionView = (UICollectionView*)view; + collectionView.delegate = nil; + collectionView.dataSource = nil; + collectionView.scrollEnabled = NO; + } else if( [view isKindOfClass:[UIScrollView class]] ) { + UIScrollView* scrollView = (UIScrollView*)view; + scrollView.delegate = nil; + scrollView.scrollEnabled = NO; + } + } + } +} + +#pragma -mark __gc +static int __gc (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + releaseUserDataView(user); + return 0; +} + +static const struct luaL_Reg memberFunctions [] = { + {"callback", callback },// 回调 + {"initParams", callback },// 回调 + + {"contentSize", contentSize },// for IOS + {"offset", contentOffset },// + // offsetBy + + {"contentInset", contentInset },// for IOS + + {"showScrollIndicator", showScrollIndicator },// for IOS + + // 下拉刷新 + // {"initRefreshing", initRefreshHeader}, + {"startRefreshing", startHeaderRefreshing},// for IOS ScrollView + {"stopRefreshing", stopHeaderRefreshing},// for IOS ScrollView + {"isRefreshing", isHeaderRefreshing},// for IOS ScrollView + + // 上拉加载更多 + // {"footerNoticeNoMoreData", footerNoticeNoMoreData}, + // {"footerResetNoMoreData", footerResetNoMoreData}, + // {"hiddenRefreshFooter", hiddenRefreshFooter}, + + {"__gc", __gc }, + {NULL, NULL} +}; + ++(const struct luaL_Reg*) memberFunctions{ + return memberFunctions; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewScrollView globalName:globalName defaultName:@"HScrollView"]; + [LVUtil reg:L clas:self cfunc:lvNewScrollView globalName:globalName defaultName:@"HorizontalScrollView"]; + + lv_createClassMetaTable(L ,META_TABLE_UIScrollView); + + luaL_openlib(L, NULL, [LVBaseView baseMemberFunctions], 0); + luaL_openlib(L, NULL, memberFunctions, 0); + + const char* keys[] = { "startRefreshing", "stopRefreshing", "isRefreshing", NULL};// 移除多余API + lv_luaTableRemoveKeys(L, keys ); + return 1; +} + + +//---------------------------------------------------------------------------------------- + +-(NSString*) description{ + return [NSString stringWithFormat:@"", (int)[self hash], + NSStringFromCGRect(self.frame),NSStringFromCGSize(self.contentSize) ]; +} +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVScrollViewDelegate.h b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVScrollViewDelegate.h new file mode 100644 index 00000000..94f8592a --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVScrollViewDelegate.h @@ -0,0 +1,18 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ +#import +#import + +@interface LVScrollViewDelegate : NSObject + +@property(nonatomic,weak) UIView* owner; +@property(nonatomic,weak) id delegate; + +-(id) init:(UIView*) view; + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVScrollViewDelegate.m b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVScrollViewDelegate.m new file mode 100644 index 00000000..5bc03a30 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVScrollViewDelegate.m @@ -0,0 +1,72 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVScrollViewDelegate.h" +#import "UIView+LuaView.h" + + +@implementation LVScrollViewDelegate + +-(id) init:(UIView*) tableView{ + self = [super init]; + if( self ){ + self.owner = tableView; + } + return self; +} + +- (void)scrollViewDidScroll:(UIScrollView *)scrollView{ + [self.owner lv_callLuaCallback:@"Scrolling"]; + if( [self.delegate respondsToSelector:@selector(scrollViewDidScroll:)] ) { + [self.delegate scrollViewDidScroll:scrollView]; + } +} + +- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView{ + if( [self.delegate respondsToSelector:@selector(scrollViewWillBeginDecelerating:)] ) { + [self.delegate scrollViewWillBeginDecelerating:scrollView]; + } +} + +- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{ + [self.owner lv_callLuaCallback:@"ScrollEnd"]; + if( [self.delegate respondsToSelector:@selector(scrollViewDidEndDecelerating:)] ) { + [self.delegate scrollViewDidEndDecelerating:scrollView]; + } +} + +- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView{ + [self.owner lv_callLuaCallback:@"ScrollEnd"]; + if( [self.delegate respondsToSelector:@selector(scrollViewDidEndScrollingAnimation:)] ) { + [self.delegate scrollViewDidEndScrollingAnimation:scrollView]; + } +} + +- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{ + [self.owner lv_callLuaCallback:@"ScrollBegin"]; + if( [self.delegate respondsToSelector:@selector(scrollViewWillBeginDragging:)] ) { + [self.delegate scrollViewWillBeginDragging:scrollView]; + } +} + +- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset { + [self.owner lv_callLuaCallback:@"DragEnd"]; +} + +- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{ + [self.owner lv_callLuaCallback:@"DragEnd"]; + if( !decelerate ) { + [self.owner lv_callLuaCallback:@"ScrollEnd"]; + } + if( [self.delegate respondsToSelector:@selector(scrollViewDidEndDragging:willDecelerate:)] ) { + [self.delegate scrollViewDidEndDragging:scrollView willDecelerate:decelerate]; + } +} + + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVStruct.h b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVStruct.h new file mode 100644 index 00000000..65b98c9b --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVStruct.h @@ -0,0 +1,26 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + +#define LV_STRUCT_MAX_LEN 16 + +@interface LVStruct : NSObject +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; +- (id) lv_nativeObject; // 返回native对象 + + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + ++(int) pushStructToLua:(lua_State*)L data:(void*)data; + +-(CGFloat*) dataPointer; + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVStruct.m b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVStruct.m new file mode 100644 index 00000000..ddefbe58 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVStruct.m @@ -0,0 +1,223 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVStruct.h" +#import "LVTypeConvert.h" +#import "LVHeads.h" + + + +@implementation LVStruct{ + CGFloat data[LV_STRUCT_MAX_LEN]; +} + +-(void) setIndex:(NSInteger)index byValue:(CGFloat) value{ + if( index>=0 && index=0 && indexobject = CFBridgingRetain(lvstruct); + lvstruct.lv_userData = userData; + + int num = lua_gettop(L); + + for (int i=1,index=0; (i<=num) && (indexobject = CFBridgingRetain(lvstruct); + lvstruct.lv_userData = userData; + + memcpy( [lvstruct dataPointer], data, LV_STRUCT_MAX_LEN*sizeof(CGFloat) ); + luaL_getmetatable(L, META_TABLE_Struct ); + lua_setmetatable(L, -2); + return 1; +} + + +static int setValue (lua_State *L) { + int argNum = lua_gettop(L); + if( argNum>=3 ) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + unsigned int index = lua_tonumber(L, 2); + CGFloat value = lua_tonumber(L, 3); + if ( index>=LV_STRUCT_MAX_LEN ) { + LVError(@"LVStruct.set index:%d", index ); + return 0; + } + if( LVIsType(user, Struct) ){ + LVStruct* lvstruct = (__bridge LVStruct *)(user->object); + if ( argNum>=4 ) { + int type = lua_tonumber(L, 4); + if( [lvstruct dataPointer] ) { + lv_setValueWithType( [lvstruct dataPointer], index, value, type); + } + } else { + [lvstruct setIndex:index byValue:value]; + } + return 0; + } + } + return 0; +} + +static int getValue (lua_State *L) { + int argNum = lua_gettop(L); + if( argNum>=2 ) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + unsigned int index = lua_tonumber(L, 2); + if ( index>=LV_STRUCT_MAX_LEN ) { + LVError(@"LVStruct.get index:%d", index ); + return 0; + } + if( LVIsType(user, Struct) ){ + LVStruct* stru = (__bridge LVStruct *)(user->object); + if ( argNum>=3 ) { + int type = lua_tonumber(L, 3); + CGFloat value = lv_getValueWithType( [stru dataPointer], index, type); + lua_pushnumber(L, value); + return 1; + } else { + CGFloat value = [stru getValueByIndex:index]; + lua_pushnumber(L, value); + return 1; + } + } + } + return 0; +} + +static int __eq (lua_State *L) { + if( lua_gettop(L)==2 ) { + LVUserDataInfo * user1 = (LVUserDataInfo *)lua_touserdata(L, 1); + LVUserDataInfo * user2 = (LVUserDataInfo *)lua_touserdata(L, 2); + if( LVIsType(user1, Struct) && LVIsType(user2, Struct) ){ + LVStruct* s1 = (__bridge LVStruct *)(user1->object); + LVStruct* s2 = (__bridge LVStruct *)(user2->object); + int size = LV_STRUCT_MAX_LEN; + BOOL yes = NO; + if( [s1 dataPointer] && [s2 dataPointer] ) { + yes = !memcmp( [s1 dataPointer], [s2 dataPointer], size); + } + lua_pushboolean(L, (yes?1:0) ); + return 1; + } + } + return 0; +} + +static int __tostring (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( LVIsType(user, Struct) ){ + NSString* s = [NSString stringWithFormat:@"LVUserDataStruct: %d", (int)user ]; + lua_pushstring(L, s.UTF8String); + return 1; + } + return 0; +} + +static int __index (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + if ( lua_type(L, 2)==LUA_TNUMBER ) { + return getValue(L); + } else if ( lua_type(L, 2)==LUA_TSTRING ){ + NSString* key = lv_paramString(L, 2); + if ( [key isEqualToString:@"get"] ) { + lua_pushcfunction(L, getValue); + return 1; + } + if ( [key isEqualToString:@"set"] ) { + lua_pushcfunction(L, setValue); + return 1; + } + } + } + return 0; /* new userdatum is already on the stack */ +} + +static int __newindex (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + if( lua_type(L, 2)==LUA_TNUMBER ){ + return setValue(L); + } else if( lua_type(L, 3)==LUA_TSTRING ){ + + } + } + return 0; /* new userdatum is already on the stack */ +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + lv_defineGlobalFunc("Struct", lvNewStruct, L); + lv_defineGlobalFunc("Rect", lvNewStruct, L); + lv_defineGlobalFunc("Size", lvNewStruct, L); + lv_defineGlobalFunc("Point", lvNewStruct, L); + + const struct luaL_Reg memberFunctions [] = { + {"__index", __index }, + {"__newindex", __newindex }, + {"__eq", __eq}, + + {"set", setValue}, + {"get", getValue}, + + {"__tostring", __tostring}, + + {NULL, NULL} + }; + + lv_createClassMetaTable(L ,META_TABLE_Struct); + + luaL_openlib(L, NULL, memberFunctions, 0); + +// { +// const struct luaL_Reg memberFunctions2 [] = { +// {"__index", __index }, +// {"__newindex", __newindex }, +// {NULL, NULL} +// }; +// lv_createClassMetaTable(L ,"META_TABLE_Struct" ); +// luaL_openlib(L, NULL, memberFunctions2, 0); +// +// luaL_getmetatable(L, META_TABLE_Struct ); +// luaL_getmetatable(L, "META_TABLE_Struct" ); +// lua_setmetatable(L, -2); +// } + return 1; +} + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVStyledString.h b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVStyledString.h new file mode 100644 index 00000000..42a2001d --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVStyledString.h @@ -0,0 +1,24 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + + +//LVData +@interface LVStyledString : NSObject + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; + +@property(nonatomic,strong) NSMutableAttributedString* mutableStyledString;//真实的数据 + +-(id) init:(lua_State*) l; ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVStyledString.m b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVStyledString.m new file mode 100644 index 00000000..094a76b8 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVStyledString.m @@ -0,0 +1,311 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVStyledString.h" +#import "LVHeads.h" +#import "LView.h" + +@interface LVStyledString () +@end + +@implementation LVStyledString + +-(id) init:(lua_State *)l{ + self = [super init]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + } + return self; +} + +- (id) lv_nativeObject{ + return self.mutableStyledString; +} + +static void releaseUserDataData(LVUserDataInfo* user){ + if( user && user->object ){ + LVStyledString* data = CFBridgingRelease(user->object); + user->object = NULL; + if( data ){ + data.lv_userData = NULL; + data.lv_luaviewCore = nil; + data.mutableStyledString = nil; + } + } +} + +static int __attributedString_gc (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + releaseUserDataData(user); + return 0; +} + +static UIFont* getFont(NSString* fontName, NSNumber* fontSize, NSString* fontWeigth, NSString* fontStyle, LVBundle* bundle){ + fontSize = fontSize ? fontSize : @(14);// bugfix: 不设置字体大小, 只设置粗体斜体无效, 所以给定默认字体大小14 + if( [fontName isKindOfClass:[NSString class]] ){ + return [LVUtil fontWithName:fontName size:fontSize.floatValue bundle:bundle]; + } + if ( [fontStyle isKindOfClass:[NSString class]] && + [fontStyle compare:@"italic" options:NSCaseInsensitiveSearch]==NSOrderedSame ) { + return [UIFont italicSystemFontOfSize:fontSize.floatValue]; + } + if( [fontWeigth isKindOfClass:[NSString class]] && + [fontWeigth compare:@"bold" options:NSCaseInsensitiveSearch]==NSOrderedSame ){ + // TODO: 支持数值? + return [UIFont boldSystemFontOfSize:fontSize.floatValue]; + } + return [UIFont systemFontOfSize:fontSize.floatValue]; +} + +// 设置字体 +static void resetFont(NSMutableAttributedString* attString, NSDictionary* dic, NSRange range, LVBundle* bundle){ + NSString* fontName = dic[@"fontName"]; + NSNumber* fontSize = dic[@"fontSize"]; + NSString* fontWeight = dic[@"fontWeight"]; + NSString* fontStyle = dic[@"fontStyle"]; + UIFont* font = getFont(fontName, fontSize, fontWeight, fontStyle, bundle); + if( font ) { + [attString addAttribute:NSFontAttributeName value:font range:range]; + } +} + +// 设置前景色 +static void resetForegroundColor(NSMutableAttributedString* attString, NSDictionary* dic, NSRange range){ + NSNumber* value = dic[@"fontColor"]; + float alpha = 1; + if( value ) { + alpha = (value.integerValue>>24) & 0xff; + alpha /= 255.0; + if( alpha == 0) { + alpha = 1; + } + UIColor* color = lv_UIColorFromRGBA(value.integerValue , alpha ); + [attString addAttribute:NSForegroundColorAttributeName value:color range:range]; + } +} + +// 设置背景色 +static void resetBackgroundColor(NSMutableAttributedString* attString, NSDictionary* dic, NSRange range){ + NSNumber* value = dic[@"backgroundColor"]; + float alpha = 1; + if( value ) { + alpha = (value.integerValue>>24) & 0xff; + alpha /= 255.0; + if( alpha == 0) { + alpha = 1; + } + UIColor* color = lv_UIColorFromRGBA(value.integerValue , alpha ); + [attString addAttribute:NSBackgroundColorAttributeName value:color range:range]; + } +} + +static BOOL isNotZeroOrFalse( id value ){ + if( [value isKindOfClass:[NSNumber class]] ) { + NSNumber* v = value; + if( v.intValue == 0 ){ + return NO; + } + if( v.boolValue== NO ) { + return NO; + } + } + return YES; +} + +// 设置划线 +static void resetStriketrhroughSytle(NSMutableAttributedString* attString, NSDictionary* dic, NSRange range){ + NSNumber* value = dic[@"strikethrough"]; + if( value && isNotZeroOrFalse(value) ){ + [attString addAttribute:NSStrikethroughStyleAttributeName value:value range:range]; + } else { + // IOS 8 系统bugfix( 有中划线和我无中划线都要设置属性, 否则有中划线不会出现 ) + [attString addAttribute:NSStrikethroughStyleAttributeName value:@(NSUnderlineStyleNone) range:range]; + } +} + +//下划线 +static void resetUnderLineStyle(NSMutableAttributedString* attString, NSDictionary* dic, NSRange range){ + NSNumber* value = dic[@"underline"]; + if( value && isNotZeroOrFalse(value) ){ + [attString addAttribute:NSUnderlineStyleAttributeName value:value range:range]; + } +} + +//设置字间距 +static void resetCharSpace(NSMutableAttributedString* attString, NSDictionary* dic, NSRange range){ + NSNumber* value = dic[@"charSpace"]; + if( value ){ + [attString addAttribute:(id)NSKernAttributeName value:value range:range]; + } +} + +//设置行间距 +static void resetLineSpace(NSMutableAttributedString* attString, NSDictionary* dic, NSRange range){ + NSNumber* value = dic[@"lineSpace"]; + if( value ) { + NSMutableParagraphStyle * paragraphStyle1 = [[NSMutableParagraphStyle alloc] init]; + paragraphStyle1.lineBreakMode = NSLineBreakByTruncatingTail; + [paragraphStyle1 setLineSpacing:value.intValue]; + [attString addAttribute:(id)NSParagraphStyleAttributeName value:paragraphStyle1 range:range]; + } +} + + +static void resetAttributedString(NSMutableAttributedString* attString, NSDictionary* dic, NSRange range ,LVBundle* bundle){ + resetFont(attString, dic, range, bundle); + resetForegroundColor(attString, dic, range); + resetBackgroundColor(attString, dic, range); + resetStriketrhroughSytle(attString, dic, range); + resetUnderLineStyle(attString, dic, range); + resetCharSpace(attString, dic, range); + resetLineSpace(attString, dic, range); +} + +static int lvNewAttributedString (lua_State *L) { + LuaViewCore* luaView = LV_LUASTATE_VIEW(L); + LVStyledString* attString = [[LVStyledString alloc] init:L]; + if( luaView && lua_gettop(L)>=2 ) { + if( ( lua_type(L, 1)==LUA_TSTRING || lua_type(L, 1)==LUA_TNUMBER ) && lua_type(L, 2)==LUA_TTABLE ){ + NSString* s = nil; + size_t n = 0; + const char* chars = lua_tolstring(L, 1, &n ); + s = [NSString stringWithUTF8String:chars]; + + // 字符串格式非法,导致crash + if( s==nil ) { + s = @""; + } + + attString.mutableStyledString = [[NSMutableAttributedString alloc] initWithString:s]; + + NSDictionary* dic = lv_luaTableToDictionary(L,2); + NSRange range = {0}; + range.location = 0; + range.length = s.length; + if( [dic isKindOfClass:[NSDictionary class]] ) { + resetAttributedString(attString.mutableStyledString, dic, range, luaView.bundle); + } + } + } + + { + NEW_USERDATA(userData, StyledString); + userData->object = CFBridgingRetain(attString); + attString.lv_userData = userData; + + luaL_getmetatable(L, META_TABLE_AttributedString ); + lua_setmetatable(L, -2); + } + return 1; +} + +static int __tostring (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVStyledString* attString = (__bridge LVStyledString *)(user->object); + NSString* s = attString.mutableStyledString.string; + if( s==nil ){ + s = [[NSString alloc] initWithFormat:@"{ UserDataType=AttributedString, null }" ]; + } + lua_pushstring(L, s.UTF8String); + return 1; + } + return 0; +} + +static int append (lua_State *L) { + LVUserDataInfo * user1 = (LVUserDataInfo *)lua_touserdata(L, 1); + LVUserDataInfo * user2 = (LVUserDataInfo *)lua_touserdata(L, 2); + LVStyledString* string1 = (__bridge LVStyledString *)(user1->object); + LVStyledString* string2 = (__bridge LVStyledString *)(user2->object); + if( LVIsType(user1, StyledString) && LVIsType(user2, StyledString) + && string1.mutableStyledString && string2.mutableStyledString ){ + [string1.mutableStyledString appendAttributedString: string2.mutableStyledString]; + return 1; + } + return 0; +} + +static int __add (lua_State *L) { + if( lua_type(L, 2)==LUA_TUSERDATA ) { + LVUserDataInfo * user1 = (LVUserDataInfo *)lua_touserdata(L, 1); + LVUserDataInfo * user2 = (LVUserDataInfo *)lua_touserdata(L, 2); + if( LVIsType(user1, StyledString) && LVIsType(user2, StyledString) ){ + LVStyledString* user1AttString = (__bridge LVStyledString *)(user1->object); + LVStyledString* user2AttString = (__bridge LVStyledString *)(user2->object); + + LVStyledString* attString = [[LVStyledString alloc] init:L]; + attString.mutableStyledString = [[NSMutableAttributedString alloc] init]; + if( user1AttString && user1AttString.mutableStyledString) + [attString.mutableStyledString appendAttributedString:user1AttString.mutableStyledString]; + if( user2AttString && user2AttString.mutableStyledString) + [attString.mutableStyledString appendAttributedString:user2AttString.mutableStyledString]; + { + NEW_USERDATA(userData, StyledString); + userData->object = CFBridgingRetain(attString); + attString.lv_userData = userData; + + luaL_getmetatable(L, META_TABLE_AttributedString ); + lua_setmetatable(L, -2); + } + return 1; + } + } else if( lua_type(L, 2)==LUA_TSTRING || lua_type(L, 2)==LUA_TNUMBER ) { + LVUserDataInfo * user1 = (LVUserDataInfo *)lua_touserdata(L, 1); + NSString* stringArg = nil; + if( lua_type(L, 2)==LUA_TSTRING ) { + stringArg = lv_paramString(L, 2); + } else { + size_t n = 0; + const char* chars = lua_tolstring(L, 2, &n ); + stringArg = [NSString stringWithUTF8String:chars]; + } + if( LVIsType(user1, StyledString) ){ + LVStyledString* user1AttString = (__bridge LVStyledString *)(user1->object); + + LVStyledString* attString = [[LVStyledString alloc] init:L]; + attString.mutableStyledString = [[NSMutableAttributedString alloc] init]; + if( user1AttString && user1AttString.mutableStyledString) + [attString.mutableStyledString appendAttributedString:user1AttString.mutableStyledString]; + if( stringArg ) { + [attString.mutableStyledString appendAttributedString:[[NSMutableAttributedString alloc] initWithString:stringArg]]; + } + { + NEW_USERDATA(userData, StyledString); + userData->object = CFBridgingRetain(attString); + attString.lv_userData = userData; + + luaL_getmetatable(L, META_TABLE_AttributedString ); + lua_setmetatable(L, -2); + } + return 1; + } + } + return 0; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewAttributedString globalName:globalName defaultName:@"StyledString"]; + + const struct luaL_Reg memberFunctions [] = { + {"append", append }, + + {"__add", __add }, + {"__gc", __attributedString_gc }, + + {"__tostring", __tostring }, + {NULL, NULL} + }; + lv_createClassMetaTable(L, META_TABLE_AttributedString); + + luaL_openlib(L, NULL, memberFunctions, 0); + return 0; +} + + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVSwipeGesture.h b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVSwipeGesture.h new file mode 100644 index 00000000..261d1d84 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVSwipeGesture.h @@ -0,0 +1,22 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" +#import "NSObject+LuaView.h" + +@interface LVSwipeGesture : UISwipeGestureRecognizer + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; + +-(id) init:(lua_State*) l; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVSwipeGesture.m b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVSwipeGesture.m new file mode 100644 index 00000000..3731ac60 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVSwipeGesture.m @@ -0,0 +1,124 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVSwipeGesture.h" +#import "LVGesture.h" +#import "LView.h" +#import "LVHeads.h" + +@implementation LVSwipeGesture + + +-(void) dealloc{ + LVLog(@"LVSwipeGesture.dealloc"); + [LVGesture releaseUD:_lv_userData]; +} + +-(id) init:(lua_State*) l{ + self = [super initWithTarget:self action:@selector(handleGesture:)]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + } + return self; +} + +-(void) handleGesture:(LVSwipeGesture*)sender { + lua_State* l = self.lv_luaviewCore.l; + if ( l ){ + lua_checkstack32(l); + lv_pushUserdata(l,self.lv_userData); + [LVUtil call:l lightUserData:self key1:"callback" key2:NULL nargs:1]; + } +} + +static int lvSwipeGestureRecognizer (lua_State *L) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVSwipeGesture class]]; + { + LVSwipeGesture* gesture = [[c alloc] init:L]; + + if( lua_type(L, 1) == LUA_TFUNCTION ) { + [LVUtil registryValue:L key:gesture stack:1]; + } + + { + NEW_USERDATA(userData, Gesture); + gesture.lv_userData = userData; + userData->object = CFBridgingRetain(gesture); + + luaL_getmetatable(L, META_TABLE_SwipeGesture ); + lua_setmetatable(L, -2); + } + } + return 1; /* new userdatum is already on the stack */ +} + +static int touchCount (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( LVIsType(user, Gesture) ){ + LVSwipeGesture* gesture = (__bridge LVSwipeGesture *)(user->object); + if( lua_gettop(L)>=2 ) { + float num = lua_tonumber(L, 2); + gesture.numberOfTouchesRequired = num; + return 0; + } else { + float num = gesture.numberOfTouchesRequired; + lua_pushnumber(L, num); + return 1; + } + } + return 0; +} + +static int direction (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( LVIsType(user, Gesture) ){ + LVSwipeGesture* gesture = (__bridge LVSwipeGesture *)(user->object); + if ( lua_gettop(L)>=2 ) { + float num = lua_tonumber(L, 2); + gesture.direction = num; + return 0; + } else { + float direction = gesture.direction; + lua_pushnumber(L, direction); + return 1; + } + } + return 0; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + { + lua_settop(L, 0); + NSDictionary* v = nil; + v = @{ + @"LEFT":@(UISwipeGestureRecognizerDirectionLeft), + @"RIGHT":@(UISwipeGestureRecognizerDirectionRight), + @"UP":@(UISwipeGestureRecognizerDirectionUp), + @"DOWN":@(UISwipeGestureRecognizerDirectionDown), + }; + [LVUtil defineGlobal:@"GestureDirection" value:v L:L]; + } + + [LVUtil reg:L clas:self cfunc:lvSwipeGestureRecognizer globalName:globalName defaultName:@"SwipeGesture"]; + + lv_createClassMetaTable(L ,META_TABLE_SwipeGesture); + luaL_openlib(L, NULL, [LVGesture baseMemberFunctions], 0); + { + const struct luaL_Reg memberFunctions [] = { + {"touchCount", touchCount}, + {"direction", direction}, + {NULL, NULL} + }; + luaL_openlib(L, NULL, memberFunctions, 0); + } + return 1; +} + + + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVSystem.h b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVSystem.h new file mode 100644 index 00000000..fe138d49 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVSystem.h @@ -0,0 +1,21 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + +@interface LVSystem : NSObject + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +/* + * 获取网络状态, 需要重载API获取网络链接信息: 2g 3g 4g wifi 未知类型返回unkown 断网返回"none" + */ ++(NSString*) netWorkType; + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVSystem.m b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVSystem.m new file mode 100644 index 00000000..cdf379f5 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVSystem.m @@ -0,0 +1,303 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVSystem.h" +#import "LView.h" +#import "LVPkgManager.h" +#import +#import "LVHeads.h" +#import "LVNetworkStatus.h" +#import "LVAnimator.h" + +@implementation LVSystem + + +// lv 扩展API +static int vmVersion (lua_State *L) { + lua_pushstring(L, LUAVIEW_VERSION ) ; + return 1; /* number of results */ +} + +// lv 扩展API +static int sdkVersion (lua_State *L) { + lua_pushstring(L, LUAVIEW_SDK_VERSION ) ; + return 1; /* number of results */ +} + +// lv 扩展API +static int osVersion (lua_State *L) { + NSString* v = [[UIDevice currentDevice] systemVersion]; + lua_pushstring(L, v.UTF8String); + return 1; /* number of results */ +} + +static int ios (lua_State *L) { + lua_pushboolean(L, 1); + return 1; +} + +static int android (lua_State *L) { + lua_pushboolean(L, 0); + return 1; +} + + ++(NSString*) netWorkType{ + return [[LVNetworkStatus shareInstance] currentNetworkStatusString]; +} + +static int netWorkType (lua_State *L) { + NSString* type = [LVSystem netWorkType]; + lua_pushstring(L, type.UTF8String); + return 1; +} + +static int layerMode (lua_State *L) { + if( lua_gettop(L)>0 ){ + BOOL yes = lua_toboolean(L, -1); + LuaViewCore* luaview = LV_LUASTATE_VIEW(L); + luaview.closeLayerMode = !yes; + } + return 0; +} + +// 屏幕常亮 +static int keepScreenOn (lua_State *L) { + if( lua_gettop(L)>0 ){ + BOOL yes = lua_toboolean(L, -1); + [[UIApplication sharedApplication] setIdleTimerDisabled:yes] ; + } + return 0; +} + +static int scale (lua_State *L) { + CGFloat s = [UIScreen mainScreen].scale; + lua_pushnumber( L, s); + return 1; /* number of results */ +} + + +// lv 扩展API +static int platform (lua_State *L) { + NSString* name = [[UIDevice currentDevice] systemName]; + NSString* version = [[UIDevice currentDevice] systemVersion]; + NSString* buf = [NSString stringWithFormat:@"%@;%@",name,version]; + lua_pushstring(L, [buf UTF8String] ) ; + return 1; /* number of results */ +} + +static int device (lua_State *L) { + NSString* name = [[UIDevice currentDevice] localizedModel]; + NSString* version = [[UIDevice currentDevice] model]; + NSString* buf = [NSString stringWithFormat:@"%@;%@",name,version]; + lua_pushstring(L, [buf UTF8String] ) ; + return 1; /* number of results */ +} + +// lv 扩展API +static int screenSize (lua_State *L) { + CGSize s = [UIScreen mainScreen].bounds.size; + lua_pushnumber(L, s.width ); + lua_pushnumber(L, s.height ); + return 2; /* number of results */ +} + +static int static_gc (lua_State *L) { + lua_gc(L, 2, 0); + return 0; +} + +static int vibrate(lua_State*L){ + AudioServicesPlaySystemSound(kSystemSoundID_Vibrate); + return 1; +} + +static int lvClassLoader(lua_State*L){ + NSString* s = lv_paramString(L, -1); + id obj = NSClassFromString(s); + lv_pushNativeObject(L, obj); + return 1; +} + +static int stringToTable(lua_State*L){ + if( lua_type(L, -1) == LUA_TSTRING ) { + NSString* s = lv_paramString(L, -1); + if( s ) { + id obj = [LVUtil stringToObject:s]; + lv_pushNativeObject(L, obj); + return 1; + } + } + return 0; +} + +static int tableToString(lua_State*L){ + if( lua_type(L, -1) == LUA_TTABLE ) { + id obj = lv_luaValueToNativeObject(L,-1); + NSString* s = [LVUtil objectToString:obj]; + lua_pushstring(L, s.UTF8String); + return 1; + } + return 0; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + { + // System API + const struct luaL_Reg staticFunctions [] = { + {"screenSize", screenSize}, + {"gc",static_gc}, + {"osVersion", osVersion}, + {"vmVersion", vmVersion}, + {"sdkVersion", sdkVersion}, + {"scale", scale}, + {"platform",platform}, + {"device",device}, + {"ios", ios}, + {"android", android}, + {"network", netWorkType}, + {"keepScreenOn", keepScreenOn},// 保持屏幕常亮接口 + {"layerMode", layerMode},// (for IOS) 是否开启layer模式 + {NULL, NULL} + }; + luaL_openlib(L, "System", staticFunctions, 0); + } + { + // Json Table相互转换 + const struct luaL_Reg fs [] = { + {"toString", tableToString}, + {"toJson", tableToString}, + {"toTable",stringToTable}, + {NULL, NULL} + }; + luaL_openlib(L, "Json", fs, 0); + } + // ---- 常量注册 ---- + { + // Align 常量 + lua_settop(L, 0); + NSDictionary* v = nil; + v = @{ + @"LEFT": @(LV_ALIGN_LEFT), + @"RIGHT": @(LV_ALIGN_RIGHT), + @"TOP": @(LV_ALIGN_TOP), + @"BOTTOM": @(LV_ALIGN_BOTTOM), + @"H_CENTER":@(LV_ALIGN_H_CENTER),// 水平居中 + @"V_CENTER":@(LV_ALIGN_V_CENTER),// 垂直居中 + @"CENTER": @(LV_ALIGN_H_CENTER|LV_ALIGN_V_CENTER),// 上下左右都居中 + }; + [LVUtil defineGlobal:@"Align" value:v L:L]; + } + { + lua_settop(L, 0); + NSDictionary* v = nil; + v = @{ + @"LEFT":@(NSTextAlignmentLeft), + @"RIGHT":@(NSTextAlignmentRight), + @"CENTER":@(NSTextAlignmentCenter),// 上下左右都居中 + }; + [LVUtil defineGlobal:@"TextAlign" value:v L:L]; + } + { + //文本太多 "..." 出现的问题 + lua_settop(L, 0); + NSDictionary* v = nil; + v = @{ + @"START":@(NSLineBreakByTruncatingHead), + @"MIDDLE":@(NSLineBreakByTruncatingMiddle), + @"END":@(NSLineBreakByTruncatingTail), + @"MARQUEE":@(NSLineBreakByCharWrapping), + }; + [LVUtil defineGlobal:@"Ellipsize" value:v L:L]; + } + { + //字体Style + lua_settop(L, 0); + NSDictionary* v = nil; + v = @{ + @"NORMAL":@"normal",//正常 + @"ITALIC":@"italic",//斜体 + @"OBLIQUE":@"oblique",//倾斜 //__deprecated_msg("") + // BOLD IOS 不支持 + // + }; + [LVUtil defineGlobal:@"FontStyle" value:v L:L]; + } + { + //字体Weight(粗体、正常) + lua_settop(L, 0); + NSDictionary* v = nil; + v = @{ + @"NORMAL":@"normal", + @"BOLD":@"bold", + }; + [LVUtil defineGlobal:@"FontWeight" value:v L:L]; + } + { + //图片缩放常量 + lua_settop(L, 0); + NSDictionary* v = nil; + v = @{ + @"CENTER":@(UIViewContentModeCenter),//按图片的原来size居中显示,当图片长/宽超过View的长/宽,则截取图片的居中部分显示 + @"CENTER_CROP":@(UIViewContentModeScaleAspectFill),//将图片等比居中显示,完全覆盖view,尽可能小; + @"CENTER_INSIDE":@(UIViewContentModeScaleAspectFit),//将图片的内容完整居中显示,尽可能的大 + @"FIT_CENTER":@(UIViewContentModeScaleAspectFit),//将图片的内容完整居中显示,尽可能的大 + @"FIT_END":@(UIViewContentModeScaleAspectFill),//把图片按比例扩大(缩小)到View的宽度,显示在View的下部分位置 + @"FIT_START":@(UIViewContentModeScaleAspectFill),//把图片按比例扩大(缩小)到View的宽度,显示在View的上部分位置 + @"FIT_XY":@(UIViewContentModeScaleToFill),//把图片按照指定的大小在View中显示 + @"MATRIX":@(UIViewContentModeScaleAspectFill),//用matrix来绘制 + }; + [LVUtil defineGlobal:@"ScaleType" value:v L:L]; + } + { + lua_settop(L, 0); + NSDictionary* v = nil; + v = @{ + @"LINEAR" : @(LVLinearInterpolator), + @"ACCELERATE" : @(LVAccelerateInterpolator), + @"DECELERATE" : @(LVDecelerateInterpolator), + @"ACCELERATE_DECELERATE" : @(LVAccelerateDecelerateInterpolator), + @"ANTICIPATE": @(LVAnticipateInterpolator), + @"OVERSHOOT": @(LVOvershootInterpolator), + @"ANTICIPATE_OVERSHOOT": @(LVAnticipateOvershootInterpolator), + }; + [LVUtil defineGlobal:@"Interpolator" value:v L:L]; + } + { + // 坑位浮动Pinned + lua_settop(L, 0); + NSDictionary* v = nil; + v = @{ + @"YES":@(YES), + @"Yes":@(YES),//__deprecated_msg("Use YES") + @"yes":@(YES),//__deprecated_msg("Use YES") + }; + [LVUtil defineGlobal:@"Pinned" value:v L:L]; + } + + { + // ViewEffect define + lua_settop(L, 0); + NSDictionary* v = nil; + v = @{ + @"NONE":@(EFFECT_NONE), + @"CLICK":@(EFFECT_CLICK), + @"PARALLAX":@(EFFECT_PARALLAX), + }; + [LVUtil defineGlobal:@"ViewEffect" value:v L:L]; + } + + // 震动 完全不兼容安卓, 安卓是类, vabrate(数组) cancel() hasVabrate(); + lv_defineGlobalFunc("Vibrate", vibrate, L); + + // create class api + lv_defineGlobalFunc("__class__", lvClassLoader, L); + return 0; +} + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTapGesture.h b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTapGesture.h new file mode 100644 index 00000000..5872fd83 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTapGesture.h @@ -0,0 +1,25 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import +#import "LVHeads.h" +#import "NSObject+LuaView.h" + +@interface LVTapGesture : UITapGestureRecognizer + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; + +-(id) init:(lua_State*) l; + + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTapGesture.m b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTapGesture.m new file mode 100644 index 00000000..d77bff3a --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTapGesture.m @@ -0,0 +1,77 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVTapGesture.h" +#import "LVGesture.h" +#import "LView.h" +#import "LVHeads.h" + +@implementation LVTapGesture + + +-(void) dealloc{ + LVLog(@"LVTapGesture.dealloc"); + [LVGesture releaseUD:_lv_userData]; +} + +-(id) init:(lua_State*) l{ + self = [super initWithTarget:self action:@selector(handleGesture:)]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + } + return self; +} + + + +-(void) handleGesture:(LVTapGesture*)sender { + lua_State* l = self.lv_luaviewCore.l; + if ( l ){ + lua_checkstack32(l); + lv_pushUserdata(l, self.lv_userData); + [LVUtil call:l lightUserData:self key1:"callback" key2:NULL nargs:1]; + } +} + +static int lvNewTapGestureRecognizer (lua_State *L) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVTapGesture class]]; + { + LVTapGesture* gesture = [[c alloc] init:L]; + + if( lua_type(L, 1) == LUA_TFUNCTION ) { + [LVUtil registryValue:L key:gesture stack:1]; + } + + { + NEW_USERDATA(userData, Gesture); + gesture.lv_userData = userData; + userData->object = CFBridgingRetain(gesture); + + luaL_getmetatable(L, META_TABLE_TapGesture ); + lua_setmetatable(L, -2); + } + } + return 1; /* new userdatum is already on the stack */ +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewTapGestureRecognizer globalName:globalName defaultName:@"TapGesture"]; + + const struct luaL_Reg memberFunctions [] = { + {NULL, NULL} + }; + + lv_createClassMetaTable(L ,META_TABLE_TapGesture); + + luaL_openlib(L, NULL, [LVGesture baseMemberFunctions], 0); + luaL_openlib(L, NULL, memberFunctions, 0); + return 1; +} + + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTextField.h b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTextField.h new file mode 100644 index 00000000..d7621512 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTextField.h @@ -0,0 +1,24 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + + +@interface LVTextField : UITextField + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; +@property(nonatomic,assign) NSUInteger lv_align; +@property(nonatomic,strong) CAShapeLayer* lv_shapeLayer; + +-(id) init:(lua_State*) l; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTextField.m b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTextField.m new file mode 100644 index 00000000..a14041da --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTextField.m @@ -0,0 +1,206 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVTextField.h" +#import "LVBaseView.h" +#import "LView.h" +#import "LVStyledString.h" +#import "LVHeads.h" + +@interface LVTextField () + +@end + +@implementation LVTextField + + +-(id) init:(lua_State*) l{ + self = [super initWithFrame:CGRectMake(0, 0, 100, 40)]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + self.delegate = self; + self.backgroundColor = [UIColor clearColor]; + self.clipsToBounds = YES; + self.font = [UIFont systemFontOfSize:14];// 默认字体大小 + } + return self; +} + +-(void) dealloc{ +} + +- (void)textFieldDidBeginEditing:(UITextField *)textField{ + // became first responder + lua_State* l = self.lv_luaviewCore.l; + if( l ) { + lua_checkstack32(l); + [self lv_callLuaCallback:@"BeginEditing"]; + } +} + +- (void)textFieldDidEndEditing:(UITextField *)textField{ + lua_State* l = self.lv_luaviewCore.l; + if( l ) { + lua_checkstack32(l); + [self lv_callLuaCallback:@"EndEditing"]; + } +} + +- (BOOL)textFieldShouldClear:(UITextField *)textField{ +// lua_State* l = self.lv_luaviewCore.l; +// if( l ) { +// lua_checkstack32(l); +// if( [LVUtil call:l lightUserData:self key:"清理"] ){ +// if( lv_isboolean(l, -1) ){ +// return lua_toboolean(l, -1); +// } +// } +// } + return YES; +} + +- (BOOL)textFieldShouldReturn:(UITextField *)textField{ +// lua_State* l = self.lv_luaviewCore.l; +// if( l ) { +// lua_checkstack32(l); +// if( [LVUtil call:l lightUserData:self key:"返回"]==0 ){ +// if( lv_isboolean(l, -1) ){ +// return lua_toboolean(l, -1); +// } +// } +// } + return YES; +} + +- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{ + return YES; +} + +#pragma -mark lvNewTextField +static int lvNewTextField (lua_State *L) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVTextField class]]; + + LVTextField* textFiled = [[c alloc] init:L]; + { + NEW_USERDATA(userData, View); + userData->object = CFBridgingRetain(textFiled); + textFiled.lv_userData = userData; + + luaL_getmetatable(L, META_TABLE_UITextField ); + lua_setmetatable(L, -2); + } + LuaViewCore* lview = LV_LUASTATE_VIEW(L); + if( lview ){ + [lview containerAddSubview:textFiled]; + } + return 1; /* new userdatum is already on the stack */ +} + +static int text (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVTextField* view = (__bridge LVTextField *)(user->object); + if( [view isKindOfClass:[LVTextField class]] ){ + if ( lua_gettop(L)>=2 ) { + if( lua_type(L, 2)==LUA_TUSERDATA ) { + LVUserDataInfo * user2 = lua_touserdata(L, 2);// 2 + if( user2 && LVIsType(user2, StyledString) ) { + LVStyledString* attString = (__bridge LVStyledString *)(user2->object); + view.attributedText = attString.mutableStyledString; + } + } else if( lua_type(L, 2)==LUA_TSTRING ) { + NSString* text = lv_paramString(L, 2);// 2 + view.text = text; + } + return 0; + } else { + NSString* s = view.text; + if( s ) { + lua_pushstring(L, s.UTF8String); + return 1; + } + + NSAttributedString* att = view.attributedText; + if( att ) { + LVStyledString* attString = [[LVStyledString alloc] init:L]; + attString.mutableStyledString = [[NSMutableAttributedString alloc] init]; + [attString.mutableStyledString appendAttributedString:att]; + + NEW_USERDATA(userData, StyledString); + userData->object = CFBridgingRetain(attString); + attString.lv_userData = userData; + + luaL_getmetatable(L, META_TABLE_AttributedString ); + lua_setmetatable(L, -2); + return 1; + } else { + lua_pushnil(L); + } + return 1; + } + } + } + return 0; +} + +static int placeholder (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVTextField* view = (__bridge LVTextField *)(user->object); + if( [view isKindOfClass:[LVTextField class]] ){ + if ( lua_gettop(L)>=2 ) { + if( lua_type(L, 2)==LUA_TSTRING ) { + NSString* text = lv_paramString(L, 2);// 2 + view.placeholder = text; + } else if( lua_type(L, 2)==LUA_TUSERDATA ) { + LVUserDataInfo * user2 = lua_touserdata(L, 2);// 2 + if( user2 && LVIsType(user2, StyledString) ) { + LVStyledString* attString = (__bridge LVStyledString *)(user2->object); + view.attributedPlaceholder = attString.mutableStyledString; + } + } + return 0; + } else { + NSString* s = view.placeholder; + if( s ) { + lua_pushstring(L, s.UTF8String); + } else { + lua_pushnil(L); + } + } + return 1; + } + } + return 0; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewTextField globalName:globalName defaultName:@"TextField"]; + + const struct luaL_Reg memberFunctions [] = { + {"text", text}, + {"hint", placeholder}, + {"placeholder", placeholder}, //__deprecated_msg("Use hint") + {NULL, NULL} + }; + + lv_createClassMetaTable(L ,META_TABLE_UITextField); + + luaL_openlib(L, NULL, [LVBaseView baseMemberFunctions], 0); + luaL_openlib(L, NULL, memberFunctions, 0); + + const char* keys[] = { "addView", NULL};// 移除多余API + lv_luaTableRemoveKeys(L, keys ); + return 1; +} + +-(NSString*) description{ + return [NSString stringWithFormat:@"", (int)[self hash], NSStringFromCGRect(self.frame) ]; +} + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTimer.h b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTimer.h new file mode 100644 index 00000000..1d12e3de --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTimer.h @@ -0,0 +1,27 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + + +@interface LVTimer : NSObject + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; + +-(id) init:(lua_State*) l; + +-(void) startTimer; +-(void) cancel; + + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTimer.m b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTimer.m new file mode 100644 index 00000000..2a68dddd --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTimer.m @@ -0,0 +1,233 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVTimer.h" +#import "LView.h" +#import "LVHeads.h" +#import "LVHeads.h" + +@interface LVTimer () +@property(nonatomic,assign) BOOL repeat; +@property(nonatomic,assign) NSTimeInterval delay; +@property(nonatomic,assign) NSTimeInterval interval; +@end + +@implementation LVTimer{ + NSTimer* timer; +} + +static void releaseUserDataTimer(LVUserDataInfo* user){ + if( user && user->object ){ + LVTimer* timer = CFBridgingRelease(user->object); + user->object = NULL; + if( timer ){ + [timer cancel]; + timer.lv_userData = nil; + timer.lv_luaviewCore = nil; + } + } +} + +-(void) dealloc{ + releaseUserDataTimer(_lv_userData); +} + +-(id) init:(lua_State*) l{ + self = [super init]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + self.delay = 0; // 默认延时 + self.repeat = NO; // 默认重复次数 + self.interval = 1; // 默认间隔1秒 + } + return self; +} + +-(void) timerCallBack{ + lua_State* l = self.lv_luaviewCore.l; + if( l && self.lv_userData ){ + lv_pushUserdata(l, self.lv_userData); + lv_pushUDataRef(l, USERDATA_KEY_DELEGATE ); + lv_runFunction(l); + } +} + + +-(void) startTimer{ + [self cancel]; + if( self.delay>0 ) { + NSDate* date = [[NSDate alloc] initWithTimeIntervalSinceNow:self.delay]; + timer = [[NSTimer alloc] initWithFireDate:date interval:self.interval target:self selector:@selector(timerCallBack) userInfo:nil repeats:self.repeat]; + [[NSRunLoop mainRunLoop] addTimer:timer forMode:NSRunLoopCommonModes]; + } else { + timer = [NSTimer scheduledTimerWithTimeInterval:self.interval target:self selector:@selector(timerCallBack) userInfo:nil repeats:self.repeat]; + [[NSRunLoop mainRunLoop] addTimer:timer forMode:NSRunLoopCommonModes]; + } +} + +-(void) cancel { + [timer invalidate]; + timer = nil; +} + +-(id) lv_nativeObject{ + return timer; +} + + +#pragma -mark Timer + +static int lvNewTimer (lua_State *L) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVTimer class]]; + + LVTimer* timer = [[c alloc] init:L]; + { + NEW_USERDATA(userData, Timer); + userData->object = CFBridgingRetain(timer); + timer.lv_userData = userData; + + luaL_getmetatable(L, META_TABLE_Timer ); + lua_setmetatable(L, -2); + } + if( lua_type(L, 1) == LUA_TFUNCTION ) { + lua_pushvalue(L, 1); + lv_udataRef(L, USERDATA_KEY_DELEGATE); + } + return 1; +} + +static int setCallback (lua_State *L) { + if( lua_type(L, 2) == LUA_TFUNCTION ) { + lua_pushvalue(L, 1); + lua_pushvalue(L, 2); + lv_udataRef(L, USERDATA_KEY_DELEGATE); + } + lua_settop(L, 1); + return 1; +} + +static int start (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + + if ( user ) { + LVTimer* timer = (__bridge LVTimer *)(user->object); + if( lua_gettop(L)>=2 ) { + timer.interval = lua_tonumber(L, 2); + } + if( lua_gettop(L)>=3 ) { + timer.repeat = lua_toboolean(L, 3); + } + if( timer ){ + [timer startTimer]; + lua_pushvalue(L,1); + return 1; + } + } + return 0; +} + +static int cancel (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVTimer* timer = (__bridge LVTimer *)(user->object); + if( timer ){ + [timer cancel]; + } + } + return 0; +} + +static int delay (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + double delay = lua_tonumber(L, 2); + if( user ){ + LVTimer* timer = (__bridge LVTimer *)(user->object); + if( timer ){ + timer.delay = delay; + lua_pushvalue(L,1); + return 1; + } + } + return 0; +} + +static int repeat (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + BOOL repeat = lua_toboolean(L, 2); + if( user ){ + LVTimer* timer = (__bridge LVTimer *)(user->object); + if( timer ){ + timer.repeat = repeat; + lua_pushvalue(L,1); + return 1; + } + } + return 0; +} + +static int interval (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + double interval = lua_tonumber(L, 2); + if( user ){ + LVTimer* timer = (__bridge LVTimer *)(user->object); + if( timer ){ + timer.interval = interval; + lua_pushvalue(L,1); + return 1; + } + } + return 0; +} + +static int __gc (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + releaseUserDataTimer(user); + return 0; +} + +static int __tostring (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVTimer* timer = (__bridge LVTimer *)(user->object); + NSString* s = [NSString stringWithFormat:@"LVUserDataTimer: %@", timer ]; + lua_pushstring(L, s.UTF8String); + return 1; + } + return 0; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewTimer globalName:globalName defaultName:@"Timer"]; + + const struct luaL_Reg memberFunctions [] = { + {"callback",setCallback}, + + {"start", start }, + {"cancel", cancel }, + {"stop", cancel }, //__deprecated_msg("Use hidden") + + + {"delay", delay }, + {"repeat", repeat }, + {"repeatCount", repeat }, //__deprecated_msg("Use hidden") + {"interval", interval }, + + {"__gc", __gc }, + + {"__tostring", __tostring }, + {NULL, NULL} + }; + + lv_createClassMetaTable(L ,META_TABLE_Timer); + + luaL_openlib(L, NULL, memberFunctions, 0); + return 1; +} + + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVToast.h b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVToast.h new file mode 100644 index 00000000..6434ea06 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVToast.h @@ -0,0 +1,25 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import + +#define DEFAULT_DISPLAY_DURATION 2.0f + +@interface LVToast : NSObject + ++ (void)showWithText:(NSString *) text; ++ (void)showWithText:(NSString *) text duration:(CGFloat)duration; + ++ (void)showWithText:(NSString *) text topOffset:(CGFloat) topOffset; ++ (void)showWithText:(NSString *) text topOffset:(CGFloat) topOffset duration:(CGFloat) duration; + ++ (void)showWithText:(NSString *) text bottomOffset:(CGFloat) bottomOffset; ++ (void)showWithText:(NSString *) text bottomOffset:(CGFloat) bottomOffset duration:(CGFloat) duration; + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVToast.m b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVToast.m new file mode 100644 index 00000000..34c1b2df --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVToast.m @@ -0,0 +1,185 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVToast.h" + +#import + + +@interface LVToast () + +- (id)initWithText:(NSString *)text_; +- (void)setDuration:(CGFloat) duration_; + +- (void)toastTaped:(UIButton *)sender_; + +- (void)showAnimation; +- (void)hideAnimation; + +- (void)show; +- (void)showFromTopOffset:(CGFloat) topOffset_; +- (void)showFromBottomOffset:(CGFloat) bottomOffset_; + +@end + + +@implementation LVToast{ + NSString *text; + UIButton *contentView; + CGFloat duration; +} + +- (void)dealloc{ + [[NSNotificationCenter defaultCenter] removeObserver:self + name:UIDeviceOrientationDidChangeNotification + object:[UIDevice currentDevice]]; +} + + +- (id)initWithText:(NSString *)text_{ + if (self = [super init]) { + + text = [text_ copy]; + + UIFont *font = [UIFont boldSystemFontOfSize:14]; + + CGSize textSize = [text boundingRectWithSize:CGSizeMake(280, MAXFLOAT) + options:(NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading) + attributes:@{NSFontAttributeName: font } + context:nil].size; + UILabel *textLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, textSize.width + 12, textSize.height + 12)]; + textLabel.backgroundColor = [UIColor clearColor]; + textLabel.textColor = [UIColor whiteColor]; + textLabel.textAlignment = NSTextAlignmentCenter; + textLabel.font = font; + textLabel.text = text; + textLabel.numberOfLines = 0; + + contentView = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, textLabel.frame.size.width, textLabel.frame.size.height)]; + contentView.layer.cornerRadius = 5.0f; + contentView.layer.borderWidth = 1.0f; + contentView.layer.borderColor = [[UIColor grayColor] colorWithAlphaComponent:0.5].CGColor; + contentView.backgroundColor = [UIColor colorWithRed:0.2f + green:0.2f + blue:0.2f + alpha:0.75f]; + [contentView addSubview:textLabel]; + contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth; + [contentView addTarget:self + action:@selector(toastTaped:) + forControlEvents:UIControlEventTouchDown]; + contentView.alpha = 0.0f; + + + duration = DEFAULT_DISPLAY_DURATION; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(deviceOrientationDidChanged:) + name:UIDeviceOrientationDidChangeNotification + object:[UIDevice currentDevice]]; + } + return self; +} + +- (void)deviceOrientationDidChanged:(NSNotification *)notify_{ + [self hideAnimation]; +} + +-(void)dismissToast{ + [contentView removeFromSuperview]; +} + +-(void)toastTaped:(UIButton *)sender_{ + [self hideAnimation]; +} + +- (void)setDuration:(CGFloat) duration_{ + duration = duration_; +} + +-(void)showAnimation{ + [UIView beginAnimations:@"show" context:NULL]; + [UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; + [UIView setAnimationDuration:0.3]; + contentView.alpha = 1.0f; + [UIView commitAnimations]; +} + +-(void)hideAnimation{ + [UIView beginAnimations:@"hide" context:NULL]; + [UIView setAnimationCurve:UIViewAnimationCurveEaseOut]; + [UIView setAnimationDelegate:self]; + [UIView setAnimationDidStopSelector:@selector(dismissToast)]; + [UIView setAnimationDuration:0.3]; + contentView.alpha = 0.0f; + [UIView commitAnimations]; +} + +- (void)show{ + UIWindow *window = [UIApplication sharedApplication].keyWindow; + contentView.center = window.center; + [window addSubview:contentView]; + [self showAnimation]; + [self performSelector:@selector(hideAnimation) withObject:nil afterDelay:duration]; +} + +- (void)showFromTopOffset:(CGFloat) top_{ + UIWindow *window = [UIApplication sharedApplication].keyWindow; + contentView.center = CGPointMake(window.center.x, top_ + contentView.frame.size.height/2); + [window addSubview:contentView]; + [self showAnimation]; + [self performSelector:@selector(hideAnimation) withObject:nil afterDelay:duration]; +} + +- (void)showFromBottomOffset:(CGFloat) bottom_{ + UIWindow *window = [UIApplication sharedApplication].keyWindow; + contentView.center = CGPointMake(window.center.x, window.frame.size.height-(bottom_ + contentView.frame.size.height/2)); + [window addSubview:contentView]; + [self showAnimation]; + [self performSelector:@selector(hideAnimation) withObject:nil afterDelay:duration]; +} + + ++ (void)showWithText:(NSString *)text_{ + [LVToast showWithText:text_ duration:DEFAULT_DISPLAY_DURATION]; +} + ++ (void)showWithText:(NSString *)text_ + duration:(CGFloat)duration_{ + LVToast *toast = [[LVToast alloc] initWithText:text_]; + [toast setDuration:duration_]; + [toast show]; +} + ++ (void)showWithText:(NSString *)text_ + topOffset:(CGFloat)topOffset_{ + [LVToast showWithText:text_ topOffset:topOffset_ duration:DEFAULT_DISPLAY_DURATION]; +} + ++ (void)showWithText:(NSString *)text_ + topOffset:(CGFloat)topOffset_ + duration:(CGFloat)duration_{ + LVToast *toast = [[LVToast alloc] initWithText:text_]; + [toast setDuration:duration_]; + [toast showFromTopOffset:topOffset_]; +} + ++ (void)showWithText:(NSString *)text_ + bottomOffset:(CGFloat)bottomOffset_{ + [LVToast showWithText:text_ bottomOffset:bottomOffset_ duration:DEFAULT_DISPLAY_DURATION]; +} + ++ (void)showWithText:(NSString *)text_ + bottomOffset:(CGFloat)bottomOffset_ + duration:(CGFloat)duration_{ + LVToast *toast = [[LVToast alloc] initWithText:text_]; + [toast setDuration:duration_]; + [toast showFromBottomOffset:bottomOffset_]; +} + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTransform3D.h b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTransform3D.h new file mode 100644 index 00000000..42ba1a9e --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTransform3D.h @@ -0,0 +1,46 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + +@interface LVTransform3D : NSObject + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; +- (id) lv_nativeObject; // 返回native对象 + +@property(nonatomic,assign) CATransform3D transform; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + ++(int) pushTransform3D:(lua_State *)L transform3d:(CATransform3D) t; + +@end + +/* rotation和scale函数只适用于没有x、y轴rotation的矩阵 */ + +extern void CATransform3DSetRotation(CATransform3D *t, CGFloat v); /* z-axis */ + +extern double CATransform3DGetRotation(CATransform3D *t); /* returns [-M_PI, M_PI] */ + +extern void CATransform3DSetScaleX(CATransform3D *t, CGFloat v); +extern void CATransform3DSetScaleY(CATransform3D *t, CGFloat v); +extern void CATransform3DSetScaleZ(CATransform3D *t, CGFloat v); + +extern double CATransform3DGetScaleX(CATransform3D *t); +extern double CATransform3DGetScaleY(CATransform3D *t); +extern double CATransform3DGetScaleZ(CATransform3D *t); + +extern void CATransform3DSetTranslationX(CATransform3D *t, CGFloat v); +extern void CATransform3DSetTranslationY(CATransform3D *t, CGFloat v); +extern void CATransform3DSetTranslationZ(CATransform3D *t, CGFloat v); + +extern double CATransform3DGetTranslationX(CATransform3D *t); +extern double CATransform3DGetTranslationY(CATransform3D *t); +extern double CATransform3DGetTranslationZ(CATransform3D *t); diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTransform3D.m b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTransform3D.m new file mode 100644 index 00000000..78699e4b --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTransform3D.m @@ -0,0 +1,308 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVTransform3D.h" +#import "LVHeads.h" +#import "LVHeads.h" + +@implementation LVTransform3D + +-(id) lv_nativeObject{ + return nil; +} + +static int lvNewTransform3D (lua_State *L) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVTransform3D class]]; + + { + NEW_USERDATA(userData, Transform3D); + LVTransform3D* trans = [[c alloc] init]; + userData->object = CFBridgingRetain(trans); + trans.transform = CATransform3DIdentity; + luaL_getmetatable(L, META_TABLE_Transform3D ); + lua_setmetatable(L, -2); + } + return 1; /* new userdatum is already on the stack */ +} + ++(int) pushTransform3D:(lua_State *)L transform3d:(CATransform3D) t{ + { + NEW_USERDATA(userData, Transform3D); + LVTransform3D* trans = [[LVTransform3D alloc] init]; + userData->object = CFBridgingRetain(trans); + trans.transform = t; + luaL_getmetatable(L, META_TABLE_Transform3D ); + lua_setmetatable(L, -2); + } + return 1; +} + + +static int translation (lua_State *L) { + if( lua_gettop(L)==4 ) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + double x = lua_tonumber(L, 2);// 2 + double y = lua_tonumber(L, 3);// 3 + double z = lua_tonumber(L, 4);// 4 + if( LVIsType(user, Transform3D) ){ + LVTransform3D* tran = (__bridge LVTransform3D *)(user->object); + tran.transform = CATransform3DTranslate(tran.transform, x, y, z); + lua_pushvalue(L,1); + return 1; + } + } + return 0; +} + +static int scale (lua_State *L) { + if( lua_gettop(L)==4 ) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + double x = lua_tonumber(L, 2);// 2 + double y = lua_tonumber(L, 3);// 3 + double z = lua_tonumber(L, 4);// 4 + if( LVIsType(user, Transform3D) ){ + LVTransform3D* tran = (__bridge LVTransform3D *)(user->object); + tran.transform = CATransform3DScale(tran.transform, x, y, z); + lua_pushvalue(L,1); + return 1; + } + } + return 0; +} + +static int rotate (lua_State *L) { + if( lua_gettop(L)==5 ) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + double angle = lua_tonumber(L, 2); + double x = lua_tonumber(L, 3); + double y = lua_tonumber(L, 4); + double z = lua_tonumber(L, 5); + if( LVIsType(user, Transform3D) ){ + LVTransform3D* tran = (__bridge LVTransform3D *)(user->object); + tran.transform = CATransform3DRotate(tran.transform, angle, x, y, z); + lua_pushvalue(L,1); + return 1; + } + } + return 0; +} + +static int isIdentity (lua_State *L) { + if( lua_gettop(L)==1 ) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( LVIsType(user, Transform3D) ){ + LVTransform3D* tran = (__bridge LVTransform3D *)(user->object); + BOOL yes = CATransform3DIsIdentity(tran.transform ); + int ret = (yes ? 1 : 0); + lua_pushboolean(L, ret); + return 1; + } + } + return 0; +} + +static int reset (lua_State *L) { + if( lua_gettop(L)==1 ) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( LVIsType(user, Transform3D) ){ + LVTransform3D* tran = (__bridge LVTransform3D *)(user->object); + tran.transform = CATransform3DIdentity; + lua_pushvalue(L,1); + return 1; + } + } + return 0; +} + +static int transform_set (lua_State *L) { + if( lua_gettop(L)==2 ) { + LVUserDataInfo * user1 = (LVUserDataInfo *)lua_touserdata(L, 1); + LVUserDataInfo * user2 = (LVUserDataInfo *)lua_touserdata(L, 2); + if( LVIsType(user1, Transform3D) && LVIsType(user2, Transform3D) ){ + LVTransform3D* tran1 = (__bridge LVTransform3D *)(user1->object); + LVTransform3D* tran2 = (__bridge LVTransform3D *)(user2->object); + tran1.transform = tran2.transform; + lua_pushvalue(L,1); + return 1; + } + } + return 0; +} + +static int concat (lua_State *L) { + if( lua_gettop(L)==2 ) { + LVUserDataInfo * user1 = (LVUserDataInfo *)lua_touserdata(L, 1); + LVUserDataInfo * user2 = (LVUserDataInfo *)lua_touserdata(L, 2); + if( LVIsType(user1, Transform3D) && LVIsType(user2, Transform3D) ){ + LVTransform3D* tran1 = (__bridge LVTransform3D *)(user1->object); + LVTransform3D* tran2 = (__bridge LVTransform3D *)(user2->object); + tran1.transform = CATransform3DConcat(tran1.transform, tran2.transform); + + lua_pushvalue(L,1); + return 1; + } + } + return 0; +} + +static int __mul (lua_State *L) { + if( lua_gettop(L)==2 ) { + LVUserDataInfo * user1 = (LVUserDataInfo *)lua_touserdata(L, 1); + LVUserDataInfo * user2 = (LVUserDataInfo *)lua_touserdata(L, 2); + if( LVIsType(user1, Transform3D) && LVIsType(user2, Transform3D) ){ + LVTransform3D* tran1 = (__bridge LVTransform3D *)(user1->object); + LVTransform3D* tran2 = (__bridge LVTransform3D *)(user2->object); + NEW_USERDATA(user, Transform3D); + + LVTransform3D* trans = [[LVTransform3D alloc] init]; + user->object = CFBridgingRetain(trans); + + trans.transform = CATransform3DIdentity; + luaL_getmetatable(L, META_TABLE_Transform3D ); + lua_setmetatable(L, -2); + + trans.transform = CATransform3DConcat(tran1.transform, tran2.transform); + return 1; + } + } + return 0; +} + +static int __eq (lua_State *L) { + if( lua_gettop(L)==2 ) { + LVUserDataInfo * user1 = (LVUserDataInfo *)lua_touserdata(L, 1); + LVUserDataInfo * user2 = (LVUserDataInfo *)lua_touserdata(L, 2); + if( LVIsType(user1, Transform3D) && LVIsType(user2, Transform3D) ){ + LVTransform3D* tran1 = (__bridge LVTransform3D *)(user1->object); + LVTransform3D* tran2 = (__bridge LVTransform3D *)(user2->object); + BOOL yes = CATransform3DEqualToTransform( tran1.transform, tran2.transform); + lua_pushboolean(L, (yes?1:0) ); + return 1; + } + } + return 0; +} + +static int __tostring (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( LVIsType(user, Transform3D) ){ + NSString* s = [NSString stringWithFormat:@"LVUserDataTransform3D: %d", (int)user ]; + lua_pushstring(L, s.UTF8String); + return 1; + } + return 0; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewTransform3D globalName:globalName defaultName:@"Transform3D"]; + + const struct luaL_Reg memberFunctions [] = { + {"__eq", __eq}, + {"__mul", __mul}, + {"rotate", rotate}, + {"scale", scale}, + {"translation", translation}, + + {"isIdentity", isIdentity}, + {"reset", reset}, + + {"set", transform_set}, + {"concat", concat}, + + {"__tostring", __tostring}, + + {NULL, NULL} + }; + + lv_createClassMetaTable(L ,META_TABLE_Transform3D); + + luaL_openlib(L, NULL, memberFunctions, 0); + return 1; +} + +@end + +void CATransform3DSetRotation(CATransform3D *t, CGFloat v) { + double scaleX = CATransform3DGetScaleX(t), scaleY = CATransform3DGetScaleY(t); + t->m11 = scaleX * cos(v); + t->m12 = scaleX * sin(v); + t->m21 = -(scaleY * sin(v)); + t->m22 = scaleY * cos(v); +} + +double CATransform3DGetRotation(CATransform3D *t) { + return atan2(t->m12, t->m11); +} + +void CATransform3DSetScaleX(CATransform3D *t, CGFloat v) { + double r = CATransform3DGetRotation(t); + t->m11 = v * cos(r); + t->m12 = v * sin(r); +} + +double CATransform3DGetScaleX(CATransform3D *t) { + double r = CATransform3DGetRotation(t); + + if (t->m11 != 0) { + return t->m11 / cos(r); + } else if (t->m12 != 0) { + return t->m12 / sin(r); + } else { + return 0; + } +} + +void CATransform3DSetScaleY(CATransform3D *t, CGFloat v) { + double r = CATransform3DGetRotation(t); + t->m21 = -(v * sin(r)); + t->m22 = v * cos(r); +} + +double CATransform3DGetScaleY(CATransform3D *t) { + double r = CATransform3DGetRotation(t); + + if (t->m21 != 0) { + return -(t->m21 / sin(r)); + } else if (t->m22 != 0) { + return t->m22 / cos(r); + } else { + return 0; + } +} + +void CATransform3DSetScaleZ(CATransform3D *t, CGFloat v) { + t->m33 = v; +} + +double CATransform3DGetScaleZ(CATransform3D *t) { + return t->m33; +} + +void CATransform3DSetTranslationX(CATransform3D *t, CGFloat v) { + t->m41 = v; +} + +double CATransform3DGetTranslationX(CATransform3D *t) { + return t->m41; +} + +void CATransform3DSetTranslationY(CATransform3D *t, CGFloat v) { + t->m42 = v; +} + +double CATransform3DGetTranslationY(CATransform3D *t) { + return t->m42; +} + +void CATransform3DSetTranslationZ(CATransform3D *t, CGFloat v) { + t->m43 = v; +} + +double CATransform3DGetTranslationZ(CATransform3D *t) { + return t->m43; +} diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTypeConvert.h b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTypeConvert.h new file mode 100644 index 00000000..0ea3f45a --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTypeConvert.h @@ -0,0 +1,24 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" +#import "LVUtil.h" + +@interface LVTypeConvert : NSObject + +int lv_pushInvocationReturnValueToLuaStack(NSInvocation* invocation, lua_State* L); +id lv_setInvocationReturnValueByLuaStack(NSInvocation* invocation, lua_State* L, int stackID); + +int lv_pushInvocationArgToLuaStack(NSInvocation* invocation, int index, lua_State* L); +int lv_setInvocationArgByLuaStack(NSInvocation* invocation, int index, lua_State* L, int stackID); + +int lv_setValueWithType(void* p, int index, double value, int type ); +double lv_getValueWithType(void* p, int index, int type ); + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTypeConvert.m b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTypeConvert.m new file mode 100644 index 00000000..c670d378 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTypeConvert.m @@ -0,0 +1,696 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVTypeConvert.h" +#import "LVHeads.h" +#import "LVStruct.h" +#import "LVHeads.h" +#import + +@implementation LVTypeConvert + +static int typeIdx(const char* type){ + if( type ) { + unsigned char c0 = type[0]; + unsigned char c1 = type[1]; + if ( c1==0 ){ + return 256*0 + c0; + } else if ( c0=='r' ) { // const + return 256*1 + c1; + } else if ( c0=='^' ) { // 指针 + return 256*2 + c1; + } else if ( c0=='{' ) { // 结构体 + return 256*3 + 0; + } else { + LVError(@"LVUtil.typeIdx: %s", type); + return 0; + } + } + return 0; +} + +LVTypeIDEnum lua_typeID(const char* type){ + static LVTypeIDEnum typesDic[256*4] = {0}; + static BOOL inited = NO; + if( !inited ) { + inited = YES; + + typesDic[typeIdx(@encode(void))] = LVTypeID_void; + typesDic[typeIdx(@encode(bool))] = LVTypeID_bool; + typesDic[typeIdx(@encode(BOOL))] = LVTypeID_BOOL; + typesDic[typeIdx(@encode(char))] = LVTypeID_char; + typesDic[typeIdx(@encode(unsigned char))] = LVTypeID_unsignedchar; + typesDic[typeIdx(@encode(short))] = LVTypeID_short; + typesDic[typeIdx(@encode(unsigned short))] = LVTypeID_unsignedshort; + typesDic[typeIdx(@encode(int))] = LVTypeID_int; + typesDic[typeIdx(@encode(unsigned int))] = LVTypeID_unsignedint; + typesDic[typeIdx(@encode(NSInteger))] = LVTypeID_NSInteger; + typesDic[typeIdx(@encode(NSUInteger))] = LVTypeID_NSUInteger; + typesDic[typeIdx(@encode(long long))] = LVTypeID_longlong; + typesDic[typeIdx(@encode(unsigned long long))] = LVTypeID_unsigedlonglong; + typesDic[typeIdx(@encode(float))] = LVTypeID_float; + typesDic[typeIdx(@encode(CGFloat))] = LVTypeID_CGFloat; + typesDic[typeIdx(@encode(double))] = LVTypeID_double; + + typesDic[typeIdx(@encode(BOOL*))] = LVTypeID_charP; + typesDic[typeIdx(@encode(char*))] = LVTypeID_charP; + typesDic[typeIdx(@encode(short*))] = LVTypeID_charP; + typesDic[typeIdx(@encode(int*))] = LVTypeID_charP; + typesDic[typeIdx(@encode(NSInteger*))] = LVTypeID_charP; + typesDic[typeIdx(@encode(long*))] = LVTypeID_charP; + typesDic[typeIdx(@encode(float*))] = LVTypeID_charP; + typesDic[typeIdx(@encode(CGFloat*))] = LVTypeID_charP; + typesDic[typeIdx(@encode(double*))] = LVTypeID_charP; + typesDic[typeIdx(@encode(unsigned char*))] = LVTypeID_charP; + typesDic[typeIdx(@encode(unsigned short*))] = LVTypeID_charP; + typesDic[typeIdx(@encode(unsigned int*))] = LVTypeID_charP; + typesDic[typeIdx(@encode(NSUInteger*))] = LVTypeID_charP; + typesDic[typeIdx(@encode(unsigned long*))] = LVTypeID_charP; + typesDic[typeIdx(@encode(void*))] = LVTypeID_voidP; + typesDic[typeIdx(@encode(void**))] = LVTypeID_voidP; + + typesDic[typeIdx(@encode(const BOOL*))] = LVTypeID_charP; + typesDic[typeIdx(@encode(const char*))] = LVTypeID_charP; + typesDic[typeIdx(@encode(const short*))] = LVTypeID_charP; + typesDic[typeIdx(@encode(const int*))] = LVTypeID_charP; + typesDic[typeIdx(@encode(const long*))] = LVTypeID_charP; + typesDic[typeIdx(@encode(const float*))] = LVTypeID_charP; + typesDic[typeIdx(@encode(const double*))] = LVTypeID_charP; + + typesDic[typeIdx(@encode(const void*))] = LVTypeID_voidP; + typesDic[typeIdx("^{")] = LVTypeID_voidP; + typesDic[typeIdx(@encode(id))] = LVTypeID_id; + typesDic[typeIdx(@encode(Class))] = LVTypeID_Class; + + typesDic[typeIdx(@encode(CGRect))] = LVTypeID_struct; + } + return typesDic[ typeIdx(type) ]; +} + +int lv_setValueWithType(void* p, int index, double value, int type ){ + if ( p ) { + switch (type) { + case 'b': + case 'B': { + BOOL* cp = p; + cp[index] = (BOOL)value; + return 1; + } + case 'c': + case 'C': { + char* cp = p; + cp[index] = (char)value; + return 1; + } + case 's': + case 'S': { + short* cp = p; + cp[index] = (short)value; + return 1; + } + case 'i': + case 'I': { + int* cp = p; + cp[index] = (int)value; + return 1; + } + case 'l': + case 'L': { + long* cp = p; + cp[index] = (long)value; + return 1; + } + case 'q': + case 'Q': { + long long* cp = p; + cp[index] = (long long)value; + return 1; + } + case 'f': { + float* cp = p; + cp[index] = (float)value; + return 1; + } + case 'd': { + double* cp = p; + cp[index] = (double)value; + return 1; + } + default: { + LVError(@"lv_setValueWithType: %c", type); + return 0; + } + } + } + return 0; +} + +double lv_getValueWithType(void* p, int index, int type ){ + if ( p ) { + switch (type) { + case 'b': + case 'B': { + BOOL* cp = p; + return cp[index]; + } + case 'c': + case 'C': { + char* cp = p; + return cp[index]; + } + case 's': + case 'S': { + short* cp = p; + return cp[index]; + } + case 'i': + case 'I': { + int* cp = p; + return cp[index]; + } + case 'l': + case 'L': { + long* cp = p; + return cp[index]; + } + case 'q': + case 'Q': { + long long* cp = p; + return cp[index]; + } + case 'f': { + float* cp = p; + return cp[index]; + } + case 'd': { + double* cp = p; + return cp[index]; + } + default: { + LVError(@"lv_getValueWithType: %c", type); + return 0; + } + } + } + return 0; +} + +int lv_pushInvocationReturnValueToLuaStack(NSInvocation* invocation, lua_State* L){ + const char* type = [invocation.methodSignature methodReturnType]; + if ( type ){ + switch ( lua_typeID(type) ) { + case LVTypeID_void: + return 0; + case LVTypeID_BOOL: { + BOOL result = 0; + [invocation getReturnValue: &result]; + lua_pushboolean(L, result); + return 1; + } + case LVTypeID_bool: { + bool result = 0; + [invocation getReturnValue: &result]; + lua_pushboolean(L, result); + return 1; + } + case LVTypeID_Class: + case LVTypeID_id: { + void* result = nil; + [invocation getReturnValue: &result]; + lv_pushNativeObject(L,(__bridge id)result); + return 1; + } + case LVTypeID_char: { + char result = 0; + [invocation getReturnValue: &result]; + lua_pushnumber(L, result); + return 1; + } + case LVTypeID_unsignedchar: { + unsigned char result = 0; + [invocation getReturnValue: &result]; + lua_pushnumber(L, result); + return 1; + } + case LVTypeID_short: { + short result = 0; + [invocation getReturnValue: &result]; + lua_pushnumber(L, result); + return 1; + } + case LVTypeID_unsignedshort: { + unsigned short result = 0; + [invocation getReturnValue: &result]; + lua_pushnumber(L, result); + return 1; + } + case LVTypeID_int: { + int result = 0; + [invocation getReturnValue: &result]; + lua_pushnumber(L, result); + return 1; + } + case LVTypeID_unsignedint: { + unsigned int result = 0; + [invocation getReturnValue: &result]; + lua_pushnumber(L, result); + return 1; + } + case LVTypeID_NSInteger: { + NSInteger result = 0; + [invocation getReturnValue: &result]; + lua_pushnumber(L, result); + return 1; + } + case LVTypeID_NSUInteger: { + NSUInteger result = 0; + [invocation getReturnValue: &result]; + lua_pushnumber(L, result); + return 1; + } + case LVTypeID_longlong: { + long long result = 0; + [invocation getReturnValue: &result]; + lua_pushnumber(L, result); + return 1; + } + case LVTypeID_unsigedlonglong: { + unsigned long long result = 0; + [invocation getReturnValue: &result]; + lua_pushnumber(L, result); + return 1; + } + case LVTypeID_float: { + float result = 0; + [invocation getReturnValue: &result]; + lua_pushnumber(L, result); + return 1; + } + case LVTypeID_CGFloat: { + CGFloat result = 0; + [invocation getReturnValue: &result]; + lua_pushnumber(L, result); + return 1; + } + case LVTypeID_double: { + double result = 0; + [invocation getReturnValue: &result]; + lua_pushnumber(L, result); + return 1; + } + case LVTypeID_charP: { + char* result = 0; + [invocation getReturnValue: &result]; + lua_pushlightuserdata(L, result); + return 1; + } + case LVTypeID_voidP: { + void* result = 0; + [invocation getReturnValue: &result]; + lua_pushlightuserdata(L, result); + return 1; + } + case LVTypeID_struct:{ + CGFloat result[LV_STRUCT_MAX_LEN] = {0}; + [invocation getReturnValue: result]; + [LVStruct pushStructToLua:L data:result]; + return 1; + } + default: + LVError(@"LVMethod.pushReturnToLuaStack"); + break; + } + } + return 0; +} + +int lv_setInvocationArgByLuaStack(NSInvocation* invocation, int index, lua_State* L, int stackID){ + const char* type = [invocation.methodSignature getArgumentTypeAtIndex:index]; + if ( type ){ + switch ( lua_typeID(type) ) { + case LVTypeID_BOOL: { + BOOL value = lua_toboolean(L, stackID); + [invocation setArgument: &value atIndex:index]; + return 1; + } + case LVTypeID_bool: { + bool value = lua_toboolean(L, stackID); + [invocation setArgument: &value atIndex:index]; + return 1; + } + case LVTypeID_Class: + case LVTypeID_id: { + id nativeObject = lv_luaValueToNativeObject(L, stackID); + [invocation setArgument:&nativeObject atIndex:index]; + return 1; + } + case LVTypeID_char: { + char value = lua_tonumber(L, stackID); + [invocation setArgument: &value atIndex:index]; + return 1; + } + case LVTypeID_unsignedchar: { + unsigned char value = lua_tonumber(L, stackID); + [invocation setArgument: &value atIndex:index]; + return 1; + } + case LVTypeID_short: { + short value = lua_tonumber(L, stackID); + [invocation setArgument: &value atIndex:index]; + return 1; + } + case LVTypeID_unsignedshort: { + unsigned short value = lua_tonumber(L, stackID); + [invocation setArgument: &value atIndex:index]; + return 1; + } + case LVTypeID_int: { + int value = lua_tonumber(L, stackID); + [invocation setArgument: &value atIndex:index]; + return 1; + } + case LVTypeID_unsignedint: { + unsigned int value = lua_tonumber(L, stackID); + [invocation setArgument: &value atIndex:index]; + return 1; + } + case LVTypeID_NSInteger: { + NSInteger value = lua_tonumber(L, stackID); + [invocation setArgument: &value atIndex:index]; + return 1; + } + case LVTypeID_NSUInteger: { + NSUInteger value = lua_tonumber(L, stackID); + [invocation setArgument: &value atIndex:index]; + return 1; + } + case LVTypeID_longlong: { + long long value = lua_tonumber(L, stackID); + [invocation setArgument: &value atIndex:index]; + return 1; + } + case LVTypeID_unsigedlonglong: { + unsigned long long value = lua_tonumber(L, stackID); + [invocation setArgument: &value atIndex:index]; + return 1; + } + case LVTypeID_float: { + float value = lua_tonumber(L, stackID); + [invocation setArgument: &value atIndex:index]; + return 1; + } + case LVTypeID_CGFloat: { + CGFloat value = lua_tonumber(L, stackID); + [invocation setArgument: &value atIndex:index]; + return 1; + } + case LVTypeID_double: { + double value = lua_tonumber(L, stackID); + [invocation setArgument: &value atIndex:index]; + return 1; + } + case LVTypeID_charP: { + char* value = lua_touserdata(L, stackID); + [invocation setArgument: &value atIndex:index]; + return 1; + } + case LVTypeID_voidP: { + void* value = lua_touserdata(L, stackID); + [invocation setArgument: &value atIndex:index]; + return 1; + } + case LVTypeID_struct: { + LVUserDataInfo* user = lua_touserdata(L, stackID); + if ( LVIsType(user, Struct) ) { + LVStruct* stru = (__bridge LVStruct *)(user->object); + if( [stru dataPointer] ) { + [invocation setArgument:[stru dataPointer] atIndex:index]; + } + } + return 1; + } + default: { + NSInteger value = 0; + [invocation setArgument: &value atIndex:index]; + LVError(@"setIvocationArgument:index:byLua:"); + break; + } + } + } + //否则将参数设置为空 + NSInteger value = 0; + [invocation setArgument: &value atIndex:index]; + return 0; +} + +id lv_setInvocationReturnValueByLuaStack(NSInvocation* invocation, lua_State* L, int stackID){ + const char* type = [invocation.methodSignature methodReturnType]; + if ( type ) { + switch ( lua_typeID(type) ) { + case LVTypeID_void: + return nil; + case LVTypeID_BOOL: { + BOOL result = lua_toboolean(L, stackID); + [invocation setReturnValue: &result]; + return nil; + } + case LVTypeID_bool: { + bool result = lua_toboolean(L, stackID); + [invocation setReturnValue: &result]; + return nil; + } + case LVTypeID_Class: + case LVTypeID_id: { + id object = lv_luaValueToNativeObject(L, stackID); + [invocation setReturnValue:&object]; + return object; + } + case LVTypeID_char: { + char result = lua_tonumber(L, stackID); + [invocation setReturnValue: &result]; + return nil; + } + case LVTypeID_unsignedchar: { + unsigned char result = lua_tonumber(L, stackID); + [invocation setReturnValue: &result]; + return nil; + } + case LVTypeID_short: { + short result = lua_tonumber(L, stackID); + [invocation setReturnValue: &result]; + return nil; + } + case LVTypeID_unsignedshort: { + unsigned short result = lua_tonumber(L, stackID); + [invocation setReturnValue: &result]; + return nil; + } + case LVTypeID_int: { + int result = lua_tonumber(L, stackID); + [invocation setReturnValue: &result]; + return nil; + } + case LVTypeID_unsignedint: { + unsigned int result = lua_tonumber(L, stackID); + [invocation setReturnValue: &result]; + return nil; + } + case LVTypeID_NSInteger: { + NSInteger result = lua_tonumber(L, stackID); + [invocation setReturnValue: &result]; + return nil; + } + case LVTypeID_NSUInteger: { + NSUInteger result = lua_tonumber(L, stackID); + [invocation setReturnValue: &result]; + return nil; + } + case LVTypeID_longlong: { + long long result = lua_tonumber(L, stackID); + [invocation setReturnValue: &result]; + return nil; + } + case LVTypeID_unsigedlonglong: { + unsigned long long result = lua_tonumber(L, stackID); + [invocation setReturnValue: &result]; + return nil; + } + case LVTypeID_float: { + float result = lua_tonumber(L, stackID); + [invocation setReturnValue: &result]; + return nil; + } + case LVTypeID_CGFloat: { + CGFloat result = lua_tonumber(L, stackID); + [invocation setReturnValue: &result]; + return nil; + } + case LVTypeID_double: { + double result = lua_tonumber(L, stackID); + [invocation setReturnValue: &result]; + return nil; + } + case LVTypeID_charP: { + char* result = lua_touserdata(L,stackID); + [invocation setReturnValue: &result]; + return nil; + } + case LVTypeID_voidP: { + char* result = lua_touserdata(L,stackID); + [invocation setReturnValue: &result]; + return nil; + } + case LVTypeID_struct: { + LVUserDataInfo* user = lua_touserdata(L,stackID); + if ( LVIsType(user, Struct) ) { + LVStruct* stru = (__bridge LVStruct *)(user->object); + if( [stru dataPointer] ) { + [invocation setReturnValue: [stru dataPointer]]; + } + } + return nil; + } + default: + LVError( @"LVLuaObjBox.setInvocationReturnValue:withLuaObject:"); + break; + } + } + return nil ; +} + +int lv_pushInvocationArgToLuaStack(NSInvocation* invocation, int index, lua_State* L ){ + const char* type = [invocation.methodSignature getArgumentTypeAtIndex:index]; + switch ( lua_typeID(type) ) { + case LVTypeID_BOOL: { + BOOL value = 0; + [invocation getArgument: &value atIndex:index]; + lua_pushnumber(L, value); + return 1; + } + case LVTypeID_bool: { + bool value = 0; + [invocation getArgument: &value atIndex:index]; + lua_pushnumber(L, value); + return 1; + } + case LVTypeID_Class: + case LVTypeID_id: { + void* value = nil; + [invocation getArgument:&value atIndex:index]; + lv_pushNativeObject(L, (__bridge id)value); + return 1; + } + case LVTypeID_char: { + char value = 0; + [invocation getArgument: &value atIndex:index]; + lua_pushnumber(L, value); + return 1; + } + case LVTypeID_unsignedchar: { + unsigned char value = 0; + [invocation getArgument: &value atIndex:index]; + lua_pushnumber(L, value); + return 1; + } + case LVTypeID_short: { + short value = 0; + [invocation getArgument: &value atIndex:index]; + lua_pushnumber(L, value); + return 1; + } + case LVTypeID_unsignedshort: { + unsigned short value = 0; + [invocation getArgument: &value atIndex:index]; + lua_pushnumber(L, value); + return 1; + } + case LVTypeID_int: { + int value = 0; + [invocation getArgument: &value atIndex:index]; + lua_pushnumber(L, value); + return 1; + } + case LVTypeID_unsignedint: { + unsigned int value = 0; + [invocation getArgument: &value atIndex:index]; + lua_pushnumber(L, value); + return 1; + } + case LVTypeID_NSInteger: { + NSInteger value = 0; + [invocation getArgument: &value atIndex:index]; + lua_pushnumber(L, value); + return 1; + } + case LVTypeID_NSUInteger: { + NSUInteger value = 0; + [invocation getArgument: &value atIndex:index]; + lua_pushnumber(L, value); + return 1; + } + case LVTypeID_longlong: { + long long value = 0; + [invocation getArgument: &value atIndex:index]; + lua_pushnumber(L, value); + return 1; + } + case LVTypeID_unsigedlonglong: { + unsigned long long value = 0; + [invocation getArgument: &value atIndex:index]; + lua_pushnumber(L, value); + return 1; + } + case LVTypeID_float: { + float value = 0; + [invocation getArgument: &value atIndex:index]; + lua_pushnumber(L, value); + return 1; + } + case LVTypeID_CGFloat: { + CGFloat value = 0; + [invocation getArgument: &value atIndex:index]; + lua_pushnumber(L, value); + return 1; + } + case LVTypeID_double: { + double value = 0; + [invocation getArgument: &value atIndex:index]; + lua_pushnumber(L, value); + return 1; + } + case LVTypeID_charP: { + char* value = 0; + [invocation getArgument: &value atIndex:index]; + lua_pushlightuserdata(L,value); + return 1; + } + case LVTypeID_voidP: { + void* value = 0; + [invocation getArgument: &value atIndex:index]; + lua_pushlightuserdata(L,value); + return 1; + } + case LVTypeID_struct: { + CGFloat result[LV_STRUCT_MAX_LEN] = {0}; + [invocation getArgument:result atIndex:index]; + [LVStruct pushStructToLua:L data:result]; + return 1; + } + default:{ + LVError(@"LVLuaObjBox.pushInvocation:argIndex:toLua:"); + //否则将参数设置为空 + NSInteger value = 0; + [invocation setArgument: &value atIndex:index]; + return 1; + } + } +} + + + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVUtil.h b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVUtil.h new file mode 100644 index 00000000..eca06bd8 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVUtil.h @@ -0,0 +1,293 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import +#import "LVHeads.h" + +@class LVBundle; +@class LuaViewCore; + +typedef void(^LVFuncDownloadEndCallback)(NSData* data); + +@interface LVUtil : NSObject + +/** + * 调用lua对应的方法(如果是function直接调用, 如果是table用key去查找后再调用) + * + * @param l luastate + * @param table 用户数据 + * @param key1 如果是table中查找对应的Key1 再调用 + * @param key2 如果是table中查找对应的Key1 再调用 + * @param key3 + * @param key4 + * + * @return stackNumber + */ ++(NSString*) call:(lua_State*) l lightUserData:(id) lightUserData key1:(const char*)key1 key2:(const char*)key2 nargs:(int)nargs; + +/** + * 调用lua对应的方法(如果是function直接调用, 如果是table用key1,key2,key3,key4去查找后再调用) + * + * @param l lua状态机 + * @param key1 key值 + * @param key2 key值 + * @param key3 key值 + * @param nargs 入参个数 + * @param nret lua函数返回值个数 + * @param retType 从表中获取的值, 如果已经是需要的返回值类型, 则直接返回 + * + * @return 调用失败信息(nil是成功) + */ ++(NSString*) call:(lua_State*) l key1:(const char*)key1 key2:(const char*)key2 key3:(const char*)key3 + nargs:(int)nargs nrets:(int)nret + retType:(int) retType; + +/** + * 调用lua对应的方法(如果是function直接调用, 如果是table用key1,key2,key3,key4去查找后再调用) + * + * @param l lua状态机 + * @param key1 key值 + * @param key2 key值 + * @param key3 key值 + * @param key4 key值 + * @param nargs 入参个数 + * @param nret lua函数返回值个数 + * @param retType 从表中获取的值, 如果已经是需要的返回值类型, 则直接返回 + * + * @return 调用失败信息(nil是成功) + */ ++(NSString*) call:(lua_State*) l key1:(const char*)key1 key2:(const char*)key2 key3:(const char*)key3 key4:(const char*)key4 + nargs:(int)nargs nrets:(int)nret + retType:(int) retType; + +/* + * download file + */ ++(void) download:(NSString*) url callback:(LVFuncDownloadEndCallback) nextStep; + +/* + * NSData -> 文件 + */ ++(BOOL) saveData:(NSData*) data toFile:(NSString*) fileName; + +/* + * 文件 -> NSData + */ ++(NSData*) dataReadFromFile:(NSString*) fileName; + + +/* + * 删除文件 + */ ++(BOOL) deleteFile:(NSString*)path; + +/* + * NSCachesDirectory: 相对路径 -> 绝对路径 + */ ++ (NSString*) PathForCachesResource:(NSString* )relativePath ; + +/* + * NSDocumentDirectory: 相对路径 -> 绝对路径 + */ ++ (NSString*) PathForDocumentsResource:(NSString*) relativePath; + +/* + * + */ ++ (NSString*) PathForBundle:(NSBundle*) bundle relativePath:(NSString*) relativePath; + +/* + * 创建目录 + */ ++(BOOL) createPath:(NSString*) path; + +/* + * 检查文件是否存在 + */ ++(BOOL) exist:(NSString*) path; + +/* + * json解析 + */ ++(id) stringToObject:(NSString*) s; ++(NSString*) objectToString:(id) obj; + +/* + * MD5 + */ ++ (NSString*) MD5HashFromData:(NSData*) data; ++ (NSData*) MD5HashDataFromData:(NSData*) data; + +NSData *LV_AES256DecryptDataWithKey(NSData *data, NSData* key); + +// 全局注册表添加/删除 ++ (void) registryValue:(lua_State*) L key:(id) key stack:(int) valueIndex; ++ (void) unregistry:(lua_State*) L key:(id) key; ++ (void) pushRegistryValue:(lua_State*) L key:(id) key; + +/* + * Is External Url + */ ++(BOOL) isExternalUrl:(NSString*) url; + +/* + * 检查系统版本是否IOS8以上 + */ ++(BOOL) ios8; + +/* + * 从指定bundle加载字体 + */ ++ (int) loadFont:(NSString*) fileName package:(LVBundle*)bundle; + +/* + * 从指定bundle创建字体, 如果字体不存在自动加载 + */ ++ (UIFont *)fontWithName:(NSString *)fontName size:(CGFloat)fontSize bundle:(LVBundle*)bundle; + +/* + * 创建定时器 + */ ++ (NSTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval)inTimeInterval + block:(void (^)(NSTimer *timer))block + repeats:(BOOL)inRepeats; +/* + * 显示Lua的调用堆栈 + */ ++ (NSString*) luaTrace:(lua_State*) L; + +/* + * UIImage 切图 实现 + */ ++ (UIImage*) image:(UIImage*)image croppingToRect:(CGRect)rect; + +/* + * 创建闭包 + * @param clas upvlaue的第一个值是类型 + */ ++(void) reg:(lua_State*)L clas:(id) clas cfunc:(lua_CFunction) cfunc globalName:(NSString*)globalName defaultName:(NSString*) defaultName; + ++(Class) upvalueClass:(lua_State*)L defaultClass:(Class) defaultClass; + +/* + * 定义lua全局变量 + * @param globalName 全局变量名 + * @param value 全局变量的值 + * @param + */ ++(void) defineGlobal:(NSString*)globalName value:(id) value L:(lua_State*)L; +//------------------考虑性能问题, 一下接口试用C实现---------------------- +// UData 关联脚本object +void lv_udataRef(lua_State* L, int key); // -2: userdata -1: value +void lv_udataUnref(lua_State* L, int key); // -1: userdata +void lv_pushUDataRef(lua_State* L, int key); // -1: userdata + +int lv_createUDataLuatable (lua_State *L, int objindex); +//int lv_setUDataLuatable (lua_State *L, int objindex); +int lv_getUDataLuatable (lua_State *L, int objindex); +/* + * Create Class MetaTable + */ +void lv_createClassMetaTable(lua_State* L, const char* name); + +/* + * Push userData to stack + */ +void lv_pushUserdata(lua_State* L, void* p); + +/* + * table -> NSDictionary + */ +id lv_luaTableToDictionary(lua_State* L, int index); + +/* + * table -> NSArray + */ +NSArray* lv_luaTableToArray(lua_State* L, int idx); + +/* + * oc对象(所有类型) 转成 luavalue + */ +void lv_pushNativeObject(lua_State* L , id value ); + +/* + * oc对象(非基本类型) 转成 luavalue + */ +void lv_pushNativeObjectWithBox(lua_State* L,id nativeObject); + +/* + * luavalue 转成 oc对象 + */ +id lv_luaValueToNativeObject(lua_State* L, int idx); + +/* + * 获取LuaTable对象的 keys + */ +NSArray* lv_luaTableKeys(lua_State* L, int index); + +/* + * 移除LuaTable对象的 指定Keys + */ +void lv_luaTableRemoveKeys(lua_State* L, const char** keys); + +/* + * lua table是否包含属性 + */ +BOOL lv_isLuaObjectHaveProperty(lua_State* L, int idx, const char* key); + +/* + * lua table添加window属性 + */ +void lv_luaTableSetWeakWindow(lua_State* L, UIView* cell); + +/** + * 重置lua虚拟机的栈大小位置 + * + * @param l lua state + */ +void lua_checkstack32(lua_State* l); + +/** + * 清理首个无效参数 + * + * @param l lua state + */ +void lv_clearFirstTableValue(lua_State* l); + +/* + * uicolor -> int + */ +BOOL lv_uicolor2int(UIColor* color,NSUInteger* c, CGFloat* alpha); + +UIColor* lv_getColorFromStack(lua_State* L, int stackID); + + +void LVLog( NSString* format, ... ); +void LVError( NSString* format, ... ); + +UIColor* lv_UIColorFromRGBA(NSInteger aRGB ,float alpha); + +int lv_callbackFunction(lua_State* l, const char* functionName); + +BOOL lv_objcEqual(id obj1, id obj2); + +void lv_defineGlobalFunc(const char* globalName, lua_CFunction func, lua_State* L); + +void lv_addSubview(LuaViewCore* lv, UIView* superview, UIView* subview); +void lv_addSubviewByIndex(LuaViewCore* lv, UIView* superview, UIView* subview, int index); + +extern NSString* safe_stringForKey(NSDictionary*dic, id key); +extern NSDictionary * safe_dictionaryForKey(NSDictionary* dic, id key); +NSDate * safe_dateForKey(NSDictionary* dic, id key ); + + + +@end + + diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVUtil.m b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVUtil.m new file mode 100644 index 00000000..c67febdd --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVUtil.m @@ -0,0 +1,1014 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVUtil.h" +#import +#import "LVBlock.h" +#import "LVNativeObjBox.h" +#import "LVPkgManager.h" +#import "LVLuaObjBox.h" +#import "LVPointerValueBox.h" +#import "LVDebuger.h" +#import "LVHeads.h" +#import + +@implementation LVUtil + + ++(BOOL) isExternalUrl:(NSString*) url{ + return [url hasPrefix:@"https://"] || [url hasPrefix:@"http://"]; +} + ++(NSString*) call:(lua_State*) l lightUserData:(id) lightUserData key1:(const char*) key1 key2:(const char*)key2 nargs:(int)nargs { + if( l ){ + lua_checkstack32(l); + lua_pushlightuserdata(l, (__bridge void *)lightUserData);// key=view + lua_gettable(l, LUA_REGISTRYINDEX);/* table = registry[&Key] */ + + return [LVUtil call:l key1:key1 key2:key2 nargs:nargs nrets:0]; + } + return nil; +} + ++(NSString*) call:(lua_State*) l key1:(const char*) key1 key2:(const char*)key2 nargs:(int)nargs nrets:(int)nret{ + return [LVUtil call:l key1:key1 key2:key2 key3:NULL nargs:nargs nrets:nret retType:-8]; +} + ++(NSString*) call:(lua_State*) l key1:(const char*) key1 key2:(const char*)key2 key3:(const char*)key3 + nargs:(int)nargs nrets:(int)nret + retType:(int) retType{ + return [self call:l key1:key1 key2:key2 key3:key3 key4:NULL nargs:nargs nrets:nret retType:retType]; +} + ++(NSString*) call:(lua_State*) l key1:(const char*) key1 key2:(const char*)key2 key3:(const char*)key3 key4:(const char*)key4 + nargs:(int)nargs nrets:(int)nret + retType:(int) retType{ + if( l ){ + if( lua_type(l, -1)==LUA_TNIL ){ + return @"LVUtil: call nil function"; + } else if( lua_type(l, -1)==LUA_TTABLE && key1){//table + lua_getfield(l, -1, key1); + lua_remove(l, -2); + + if( lua_type(l, -1)==LUA_TTABLE && key2){//table + lua_getfield(l, -1, key2); + lua_remove(l, -2); + + if( lua_type(l, -1)==LUA_TTABLE && key3){//table + lua_getfield(l, -1, key3); + lua_remove(l, -2); + + if( lua_type(l, -1)==LUA_TTABLE && key4){//table + lua_getfield(l, -1, key4); + lua_remove(l, -2); + } + } + } + } + int type = lua_type(l, -1); + if ( type==retType && nret==1 ) { + return nil; + } + if( type == LUA_TFUNCTION ){//function + return lv_runFunctionWithArgs(l, nargs, nret); + } + } + return @"LVUtil:lua_State is nil"; +} + +NSString* lv_runFunction(lua_State* l){ + return lv_runFunctionWithArgs(l, 0, 0); +} + +NSString* lv_runFunctionWithArgs(lua_State* l, int nargs, int nret){ + if( l && lua_type(l, -1) == LUA_TFUNCTION ) { + if( nargs>0 ){ + lua_insert(l, -nargs-1); + } + int errorCode = lua_pcall( l, nargs, nret, 0); + if ( errorCode != 0 ) { + const char* s = lua_tostring(l, -1); + LVError( @"%s", s ); +#ifdef DEBUG + NSString* string = [NSString stringWithFormat:@"[LuaView][error] %s",s]; + lv_printToServer(l, string.UTF8String, 0); +#endif + return [NSString stringWithFormat:@"%s",s]; + } + return nil; + } + return @"function is nil error"; +} + +#define api_incr_top(L) {api_check(L, L->top < L->ci->top); L->top++;} +void lv_pushUserdata(lua_State* L, void* p){///是否正确 ???????? + if( p ) { + Udata* u = (Udata*)p; + u -= 1; + lua_lock(L); + luaC_checkGC(L); + setuvalue(L, L->top, u); + api_incr_top(L); + lua_unlock(L); + } else { + lua_pushnil(L); + } +} + +id lv_luaTableToDictionary(lua_State* L ,int index){ + if( lua_type(L, index)!=LUA_TTABLE ) { + return nil; + } + lua_checkstack(L, 128); + NSMutableDictionary* dic = nil; + NSMutableArray* array = nil; + //lua_settop(L, 8); + // Push another reference to the table on top of the stack (so we know + // where it is, and this function can work for negative, positive and + // pseudo indices + lua_pushvalue(L, index); + // stack now contains: -1 => table + lua_pushnil(L); + // stack now contains: -1 => nil; -2 => table + while (lua_next(L, -2)) + { + int keyType = lua_type(L, -2); + + id value = nil; + if( lua_type(L, -1)==LUA_TSTRING ){ + value = lv_paramString(L, -1); + } else if( lua_type(L, -1)==LUA_TNUMBER ){ + value = @(lua_tonumber(L, -1) ); + } else if( lua_type(L, -1)==LUA_TTABLE ){ + value = lv_luaTableToDictionary(L,-1); + } else if( lua_type(L, -1)==LUA_TBOOLEAN ){ + value = @( ((BOOL)lua_toboolean(L, -1)) ); + } else if ( lua_type(L, -1)==LUA_TUSERDATA ) { + LVUserDataInfo* user = (LVUserDataInfo*)lua_touserdata(L, -1); + id obj = (__bridge id)(user->object); + if( [obj respondsToSelector:@selector(lv_nativeObject)] ){ + value = [obj lv_nativeObject]; + } else { + LVError(@"lv_luaTableToDictionary.1"); + } + } else { + LVError(@"lv_luaTableToDictionary.2"); + } + // stack now contains: -1 => value; -2 => key; -3 => table + if( value ) { + if( keyType== LUA_TNUMBER ) { + // number key + if( array == nil ) { + array = [[NSMutableArray alloc] init]; + } + [array addObject:value]; + } else { // string + NSString* key = lv_paramString(L, -2); + if( key ) { + if( dic == nil ) { + dic = [[NSMutableDictionary alloc] init]; + } + [dic setObject:value forKey:key]; + } + } + } + lua_pop(L, 1); + // stack now contains: -1 => key; -2 => table + } + lua_pop(L, 1); + + if( [dic count]>0 ) { + return dic; + } + if ( array.count>0 ) { + return array; + } + // Stack is now the same as it was on entry to this function + return @{}; +} + +NSArray* lv_luaTableKeys(lua_State* L, int index){ + lua_checkstack(L, 128); + NSMutableArray* keys = [[NSMutableArray alloc] init]; + //lua_settop(L, 8); + // Push another reference to the table on top of the stack (so we know + // where it is, and this function can work for negative, positive and + // pseudo indices + if ( lua_type(L, index)!= LUA_TTABLE ){ + return nil; + } + lua_pushvalue(L, index); + // stack now contains: -1 => table + lua_pushnil(L); + // stack now contains: -1 => nil; -2 => table + while (lua_next(L, -2)) + { + NSString* key = lv_paramString(L, -2); + // stack now contains: -1 => value; -2 => key; -3 => table + if( key ) { + [keys addObject:key]; + } + lua_pop(L, 1); + // stack now contains: -1 => key; -2 => table + } + lua_pop(L, 1); + // Stack is now the same as it was on entry to this function + if( keys.count>0 ){ + return keys; + } + return nil; +} + +NSArray* lv_luaTableToArray(lua_State* L,int stackID) +{ + if( lua_type(L, stackID)==LUA_TTABLE) { + int count = luaL_getn(L, stackID); + NSMutableArray* array = [[NSMutableArray alloc] init]; + + for (int i = 0; i < count; i++) + { + lua_rawgeti(L, stackID, i+1); + NSString* s = lv_paramString(L, -1); + [array addObject:s]; + lua_pop(L,1); + } + return array; + } + return nil; +} + +#pragma -mark registry + ++ (void) registryValue:(lua_State*)L key:(id) key stack:(int) stackID{ + if( L ) { + lua_checkstack(L, 4); + lua_pushvalue(L, stackID ); // value + lua_pushlightuserdata(L, (__bridge void *)(key) ); // key + lua_insert(L, -2); // key <==> value 互换 + lua_settable(L, LUA_REGISTRYINDEX);// registry[&Key] = fucntion + } +} + ++ (void) unregistry:(lua_State*) L key:(id) key{ + if( L ) { + lua_checkstack(L, 2); + lua_pushlightuserdata(L, (__bridge void *)(key) ); // key + lua_pushnil(L); // nil + lua_settable(L, LUA_REGISTRYINDEX);// registry[&Key] = nil + } +} + ++ (void) pushRegistryValue:(lua_State*) L key:(id) key{ + if( L ){ + lua_pushlightuserdata(L, (__bridge void *)(key));// key=button + lua_gettable(L, LUA_REGISTRYINDEX);/* value = registry[&Key] */ + } +} + +void lv_createClassMetaTable(lua_State* L , const char* name ){ + luaL_newmetatable(L, name ); + lua_pushstring(L, "__index");//必须要的。 + lua_pushvalue(L, -2); /* pushes the metatable */ + lua_settable(L, -3); /* metatable.__index = metatable */ +} + +void lua_checkstack32(lua_State* l){ + if( l ){ + lua_checkstack( l, 32); + } +} + +void lv_clearFirstTableValue(lua_State* L){ + int num = lua_gettop(L); + if( num>1 && lua_type(L, 1)==LUA_TTABLE ) { + lua_checkstack(L, 4); + lua_getfield(L, 1, LUAVIEW_SYS_TABLE_KEY); + if( lua_isnil(L, -1) ) { + lua_settop(L, num); + } else { + lua_settop(L, num); + lua_remove(L, 1); + } + } +} + +BOOL lv_uicolor2int(UIColor* color,NSUInteger* c, CGFloat* alphaP){ + CGFloat r = 0; + CGFloat g = 0; + CGFloat b = 0; + CGFloat a = 0; + if( [color getRed:&r green:&g blue:&b alpha:&a] ){ + NSUInteger red = (r*255); + NSUInteger green = (g*255); + NSUInteger blue = (b*255); + *c = (red<<16) | (green<<8) | blue; + *alphaP = a; + return YES; + } + return NO; +} + +UIColor* lv_getColorFromStack(lua_State* L, int stackID){ + if ( lua_type(L, stackID)==LUA_TSTRING ) { +// NSString* s = lv_paramString(L, stackID); +// if( s.length>0 && [s characterAtIndex:0]=='#' ) { +// s = [s substringFromIndex:1]; +// NSScanner * scanner = [[NSScanner alloc] initWithString:s] ; +// unsigned long long color = 0; +// [scanner scanHexLongLong:&color]; +// float a = 1; +// if( s.length>=8 ) { +// a = ( (color>>24)&0xff )/255.0; +// } +// float r = ( (color>>16)&0xff )/255.0; +// float g = ( (color>>8)&0xff )/255.0; +// float b = ( (color>>0)&0xff )/255.0; +// UIColor* colorObj = [UIColor colorWithRed:r green:g blue:b alpha:a]; +// return colorObj; +// } + } else if( lua_type(L,stackID)==LUA_TNUMBER ) { + NSUInteger color = lua_tonumber(L, stackID); + float a = 1; + float r = ( (color>>16)&0xff )/255.0; + float g = ( (color>>8)&0xff )/255.0; + float b = ( (color>>0)&0xff )/255.0; + int stackID3 = stackID + 1; + if ( lua_gettop(L)>=stackID3 && lua_type(L,stackID3)==LUA_TNUMBER ) { + a = lua_tonumber(L, stackID+1 ); + if( a>1 ) { + a = 1; + } + if( a<0 ) { + a = 0; + } + } + UIColor* colorObj = [UIColor colorWithRed:r green:g blue:b alpha:a]; + return colorObj; + } + return [UIColor blackColor]; +} + ++(void) download:(NSString*) urlStr callback:(LVFuncDownloadEndCallback) nextStep{ + if( [urlStr hasPrefix:@"//"] ) { + urlStr = [NSString stringWithFormat:@"https:%@",urlStr]; + } + if( [urlStr.lowercaseString hasPrefix:@"http://"] ){ + urlStr = [NSString stringWithFormat:@"https://%@",[urlStr substringFromIndex:7]]; + } + NSURL *url = [NSURL URLWithString:urlStr]; + NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; + [request setHTTPMethod:@"GET"]; + [request setTimeoutInterval:30.0]; + + NSOperationQueue *queue = [[NSOperationQueue alloc]init]; + [NSURLConnection sendAsynchronousRequest:request + queue:queue + completionHandler:^(NSURLResponse *response, NSData *data, NSError *error){ + if( error==nil && data ){ + nextStep(data); + } else { + nextStep(nil); + } + }]; +} + +#pragma file data + ++(BOOL) saveData:(NSData*) data toFile:(NSString*) path{ + if( path ){ + BOOL ret = [data writeToFile:path atomically:YES]; + if( !ret ) { + NSLog(@"[LuaView][error] saveFile: %@", path); + } + return ret; + } + return NO; +} + ++(NSData*) dataReadFromFile:(NSString*)path { + if( path ){ + NSFileManager* fm = [NSFileManager defaultManager]; + NSData* data = [fm contentsAtPath:path]; + return data; + } + return nil; +} + ++(BOOL) deleteFile:(NSString*)path { + if( [self exist:path] ){ + NSFileManager* fm = [NSFileManager defaultManager]; + NSError* err; + [fm removeItemAtPath:path error:&err]; + return err==nil; + } + return YES; +} + ++(BOOL) exist:(NSString*) path{ + BOOL directory = NO; + NSFileManager *fileManage = [NSFileManager defaultManager]; + if ( [fileManage fileExistsAtPath:path isDirectory:&directory] && !directory) { + return YES; + } + return NO; +} + ++ (NSString*) PathForBundle:(NSBundle*) bundle relativePath:(NSString*) relativePath { + NSString *resourcePath = [bundle resourcePath]; + + if (!resourcePath){ + resourcePath = @"/"; + } + + return [resourcePath stringByAppendingPathComponent:relativePath]; +} + ++ (NSString*) PathForDocumentsResource:(NSString*) relativePath { + static NSString* documentsPath = nil; + if (nil == documentsPath) { + NSArray* dirs = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); + documentsPath = [dirs objectAtIndex:0]; + } + return [documentsPath stringByAppendingPathComponent:relativePath]; +} + ++ (NSString*) PathForCachesResource:(NSString* )relativePath { + static NSString* cachesPath = nil; + if (nil == cachesPath) { + NSArray* dirs = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); + cachesPath = [dirs objectAtIndex:0]; + } + return [cachesPath stringByAppendingPathComponent:relativePath]; +} + ++(BOOL) createPath:(NSString*) path{ + NSFileManager *fileManage = [NSFileManager defaultManager]; + if ( ![fileManage fileExistsAtPath:path] ) { + NSError* error = nil; + [fileManage createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:&error]; + if( error ) + return NO; + else + return YES; + } + return YES; +} + ++(id) stringToObject:(NSString*) s{ + if( s==nil ) + return nil; + NSData* data = [s dataUsingEncoding:NSUTF8StringEncoding]; + NSError* error = nil; + id dic = [NSJSONSerialization JSONObjectWithData:data + options:NSJSONReadingAllowFragments + error:&error]; + return dic; +} + ++(NSString*) objectToString:(id) obj{ + if( obj ==nil ) + return nil; + NSError* error = nil; + NSData* data = [NSJSONSerialization dataWithJSONObject:obj options:0 error:&error]; + if( data && error==nil ) { + return [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding]; + } + return nil; +} + ++ (NSString*) MD5HashFromData:(NSData*) data { + unsigned char bs[CC_MD5_DIGEST_LENGTH]; + bzero(bs, sizeof(bs)); + CC_MD5_CTX context; + CC_MD5_Init(&context); + size_t bytesHashedNum = 0; + while (bytesHashedNum < [data length]) { + CC_LONG updateSize = 1024 * 1024; + if (([data length] - bytesHashedNum) < (size_t)updateSize) { + updateSize = (CC_LONG)([data length] - bytesHashedNum); + } + CC_MD5_Update(&context, (char *)[data bytes] + bytesHashedNum, updateSize); + bytesHashedNum += updateSize; + } + CC_MD5_Final(bs, &context); + + return [NSString stringWithFormat: + @"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", + bs[0], bs[1], bs[2], bs[3], bs[4], bs[5], bs[6], bs[7], + bs[8], bs[9], bs[10], bs[11], bs[12], bs[13], bs[14],bs[15]]; +} + ++ (NSData*) MD5HashDataFromData:(NSData*) data { + unsigned char bs[CC_MD5_DIGEST_LENGTH]; + bzero(bs, sizeof(bs)); + CC_MD5_CTX context; + CC_MD5_Init(&context); + size_t bytesHashedNum = 0; + while (bytesHashedNum < [data length]) { + CC_LONG updateSize = 1024 * 1024; + if (([data length] - bytesHashedNum) < (size_t)updateSize) { + updateSize = (CC_LONG)([data length] - bytesHashedNum); + } + CC_MD5_Update(&context, (char *)[data bytes] + bytesHashedNum, updateSize); + bytesHashedNum += updateSize; + } + CC_MD5_Final(bs, &context); + + return [[NSData alloc] initWithBytes:bs length:16]; +} + +BOOL lv_isLuaObjectHaveProperty(lua_State* L, int idx, const char* key){ + if (lua_type(L, idx) == LUA_TTABLE ) { + lua_checkstack(L, 8); + lua_pushvalue(L, idx); + lua_getfield(L, -1, key); + BOOL ret = lua_type(L, -1)!=LUA_TNIL; + lua_pop(L, 2); + return ret; + } + return NO; +} + +static id luaObjBox(lua_State* L, int idx){ + LVLuaObjBox* box = [[LVLuaObjBox alloc] init:L stackID:idx]; + return box; +} + +id lv_luaValueToNativeObject(lua_State* L, int idx){ + int type = lua_type(L, idx); + switch ( type ) { + case LUA_TNIL: { + return nil; + } + case LUA_TUSERDATA: { + LVUserDataInfo* user = (LVUserDataInfo*)lua_touserdata(L, idx); + id obj = (__bridge id)(user->object); + if( [obj respondsToSelector:@selector(lv_nativeObject)] ){ + return [obj lv_nativeObject]; + } + LVError(@"lv_luaValueToNativeObject.1"); + return obj; + } + case LUA_TLIGHTUSERDATA:{ + LVPointerValueBox* box = [[LVPointerValueBox alloc] init]; + box.pointer = lua_touserdata(L, idx); + return box; + } + case LUA_TBOOLEAN: { + return [[NSNumber alloc] initWithBool:lua_toboolean(L, idx)]; + } + case LUA_TNUMBER: { + return @( lua_tonumber(L, idx) ); + } + case LUA_TSTRING: { + return lv_paramString(L, idx); + } + case LUA_TTABLE: { + if ( lv_isLuaObjectHaveProperty(L, idx, "__obj") ) { + return luaObjBox(L, idx); + } else { + return lv_luaTableToDictionary(L, idx); + } + } + case LUA_TFUNCTION: { + return [[LVBlock alloc] initWith:L statckID:idx]; + } + default: { + LVError(@"lv_luaObjectToNativeObject.2"); + return nil; + } + } +} + + + +void lv_pushNativeObject(lua_State* L, id value){ + lua_checkstack(L, 4); + if( [value isKindOfClass:[NSString class]] ) { + NSString* s = value; + lua_pushstring(L, s.UTF8String); + return; + } else if( [value isKindOfClass:[NSDictionary class]] ) { + NSDictionary* dictionary = value; + lua_newtable(L); + for (NSString *key in dictionary) { + NSString* value = dictionary[key]; + lua_checkstack(L, 4); + lua_pushstring(L, key.UTF8String); + lv_pushNativeObject(L,value); + lua_settable(L, -3); + } + return; + } else if( [value isKindOfClass:[NSArray class]] ) { + NSArray* array = value; + lua_newtable(L); + for (int i=0; iobject = CFBridgingRetain(nativeObjBox); + nativeObjBox.lv_userData = userData; + luaL_getmetatable(L, META_TABLE_NativeObject ); + lua_setmetatable(L, -2); +} + +// 获取参数-》字符串类型 +NSString* lv_paramString(lua_State* L, int idx ){ + if( lua_gettop(L)>=ABS(idx) && lua_type(L, idx) == LUA_TSTRING ) { + size_t n = 0; + const char* chars = luaL_checklstring(L, idx, &n ); + NSString* s = @""; + if( chars && n>0 ){ + s = [NSString stringWithUTF8String:chars]; + } + return s; + } + return nil; +} + ++(BOOL) ios8{ + static BOOL yes = NO; + static BOOL inited = NO; + if( !inited ) { + inited = YES; + yes = ([[[UIDevice currentDevice] systemVersion] compare:@"8.0"] != NSOrderedAscending); + } + return yes; +} + +void lv_pushUDataRef(lua_State* L, int key) { + // -1:userdata + if( lua_gettop(L)>=1 && lua_type(L, -1)==LUA_TUSERDATA ) { + lua_checkstack(L, 2); + + if( lv_getUDataLuatable(L, -1) ) { + lua_remove(L, -2); + } + if( lua_type(L, -1)==LUA_TTABLE ) { + lua_pushnumber(L, key); + lua_gettable(L, -2); + lua_remove(L, -2); + } else { + LVError( @"lv_pushUDataRef.1" ); + } + } else { + LVError( @"lv_pushUDataRef.2" ); + } +} + +void lv_udataRef(lua_State* L, int key ){ + //-2: userdata -1: value + if( lua_gettop(L)>=2 && lua_type(L, -2)==LUA_TUSERDATA ) { + lua_checkstack(L, 8); + + lv_getUDataLuatable(L, -2);//table + if( lua_type(L, -1)==LUA_TTABLE ) { + lua_pushnumber(L, key);// key + lua_pushvalue(L, -3);//value + lua_settable(L, -3); + lua_pop(L, 2); + } else { + LVError( @"lv_udataRef" ); + } + } +} + +void lv_udataUnref(lua_State* L, int key) { + // -1:userdata + if( lua_gettop(L)>=1 && lua_type(L, -1)==LUA_TUSERDATA ) { + lua_checkstack(L, 8); + + lv_getUDataLuatable(L, -1); + if( lua_type(L, -1)==LUA_TTABLE ) { + lua_pushnumber(L, key); + lua_pushnil(L); + lua_settable(L, -3); + lua_pop(L, 1); + } else { + LVError( @"lv_udataUnref" ); + } + } +} + +static int lv_setUDataLuatable (lua_State *L, int index) { + if( lua_type(L, index)==LUA_TUSERDATA ){ + lua_setfenv(L, index); + return 1; + } + return 0; +} + +int lv_getUDataLuatable (lua_State *L, int index) { + if( lua_type(L, index)==LUA_TUSERDATA ){ + lua_getfenv(L, index); + return 1; + } + return 0; +} + +int lv_createUDataLuatable (lua_State *L, int index){ + lua_checkstack(L, 8); + lua_pushvalue(L, index); + lua_createtable(L, 8, 0); + lv_setUDataLuatable(L, -2); + lua_pop(L, 1); + return 1; +} + +void lv_luaTableSetWeakWindow(lua_State* L, UIView* cell){ + lua_pushstring(L, "window"); + + NEW_USERDATA(userData, View); + userData->object = CFBridgingRetain(cell); + + luaL_getmetatable(L, META_TABLE_UIView ); + lua_setmetatable(L, -2); + + lua_settable(L, -3); +} + +void lv_luaTableRemoveKeys(lua_State* L, const char** keys){ + if ( lua_type(L, -1)== LUA_TTABLE ) { + for ( int i=0; ;i++ ){ + const char* key = keys[i]; + if( key ) { + lua_pushnil(L); + lua_setfield(L, -2, key); + } else { + break; + } + } + } +} + + +int lv_callbackFunction(lua_State* L, const char* functionName){ + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + if ( lua_gettop(L)>=2 && lua_type(L, 2)==LUA_TFUNCTION ) { + lua_pushvalue(L, 1); + lv_pushUDataRef(L, USERDATA_KEY_DELEGATE); + if( lua_type(L, -1)==LUA_TNIL ) { + lua_createtable(L, 0, 0); + lv_udataRef(L, USERDATA_KEY_DELEGATE); + } + lua_pushstring(L, functionName); + lua_pushvalue(L, 2); + lua_settable(L, -3); + return 0; + } else { + lv_pushUDataRef(L, USERDATA_KEY_DELEGATE); + lua_pushstring(L, functionName); + lua_gettable(L, -2); + return 1; + } + } + return 0; +} + +BOOL lv_objcEqual(id obj1, id obj2) { + return obj1 == obj2 || [obj1 isEqual:obj2]; +} + ++ (UIFont *)fontWithName:(NSString *)fontName size:(CGFloat)fontSize bundle:(LVBundle*)bundle{ + UIFont* font = [UIFont fontWithName:fontName size:fontSize]; + if( font == nil ) { + [LVUtil loadFont:fontName package:bundle]; + font = [UIFont fontWithName:fontName size:fontSize]; + } + return font; +} + ++(int) loadFont:(NSString*) fileName package:(LVBundle*)bundle{ + int ret = 0; + if( [fileName.lowercaseString hasSuffix:@".ttf"]==NO ) { + fileName = [NSString stringWithFormat:@"%@.ttf",fileName]; + } + NSData *inData = [bundle resourceWithName:fileName];/* your font-file data */; + CFErrorRef error; + CGDataProviderRef provider = CGDataProviderCreateWithCFData((CFDataRef)inData); + CGFontRef font = CGFontCreateWithDataProvider(provider); + if (! CTFontManagerRegisterGraphicsFont(font, &error)) { + CFStringRef errorDescription = CFErrorCopyDescription(error); + NSLog(@"Failed to load font: %@", errorDescription); + LVReleaseAndNull(errorDescription); + ret = -1; + } + LVReleaseAndNull(font); + LVReleaseAndNull(provider); + return ret; +} + + ++(void) reg:(lua_State*)L clas:(id) c cfunc:(lua_CFunction) cfunc globalName:(NSString*)globalName defaultName:(NSString*) defaultName{ + if( defaultName || globalName ) { + lua_checkstack(L, 12); + NSString* className = NSStringFromClass(c); + lua_pushstring(L, className.UTF8String); + lua_pushcclosure(L, cfunc, 1); + + lua_setglobal(L, globalName ? globalName.UTF8String : defaultName.UTF8String ); + } +} + ++(Class) upvalueClass:(lua_State*)L defaultClass:(Class) defaultClass{ + const char* classNameChars = lua_tostring(L, lua_upvalueindex(1)); + NSMutableString* className = [NSMutableString stringWithFormat:@"%s",classNameChars]; + Class c = NSClassFromString(className); + if( c == nil ) { + c = defaultClass; + } + return c; +} + ++(void) defineGlobal:(NSString*)globalName value:(id) value L:(lua_State*)L { + if( globalName && value ) { + lua_checkstack(L, 12); + lv_pushNativeObject(L, value); + lua_setglobal(L, globalName.UTF8String); + } else { + LVError(@"define Global Value"); + } +} + +void lv_defineGlobalFunc(const char* globalName, lua_CFunction func, lua_State* L) { + if( globalName && func ) { + lua_checkstack(L, 12); + lua_pushcfunction(L, func); + lua_setglobal(L, globalName); + } else { + LVError(@"define Global Function"); + } +} + +void lv_addSubview(LuaViewCore* lv, UIView* superview, UIView* subview){ + [subview removeFromSuperview]; + [subview.layer removeFromSuperlayer]; + if( lv.closeLayerMode + || [superview isKindOfClass:[UIScrollView class]] + || [subview isKindOfClass:[UIScrollView class]] ) { + [superview addSubview:subview]; + } else { + [superview.layer addSublayer:subview.layer]; + } +} + +void lv_addSubviewByIndex(LuaViewCore* lv, UIView* superview, UIView* subview, int index){ + [subview removeFromSuperview]; + [subview.layer removeFromSuperlayer]; + if( lv.closeLayerMode + || [superview isKindOfClass:[UIScrollView class]] + || [subview isKindOfClass:[UIScrollView class]] ) { + [superview insertSubview:subview atIndex:index]; + } else { + [superview.layer addSublayer:subview.layer]; + } +} + +static id objectForKey(NSDictionary* dic, id key, Class clazz){ + id obj = [dic objectForKey:key]; + if ([obj isKindOfClass:clazz]) { + return obj; + } + return nil; +} + +NSString* safe_stringForKey(NSDictionary*dic, id key) { + NSString *obj = objectForKey(dic, key, [NSString class] ); + return obj; +} + +NSDictionary * safe_dictionaryForKey(NSDictionary* dic, id key) { + NSDictionary *obj = objectForKey( dic, key, [NSDictionary class] ); + return obj; +} + +NSDate * safe_dateForKey(NSDictionary* dic, id key ){ + NSDate *obj = objectForKey(dic, key, [NSDate class] ); + return obj; +} + + + ++ (NSTimer *) scheduledTimerWithTimeInterval:(NSTimeInterval)inTimeInterval + block:(void (^)(NSTimer *timer))block + repeats:(BOOL)inRepeats { + NSParameterAssert(block != nil); + return [NSTimer scheduledTimerWithTimeInterval:inTimeInterval + target:self + selector:@selector(lv_executeBlockFromTimer:) + userInfo:[block copy] + repeats:inRepeats]; +} + ++ (void)lv_executeBlockFromTimer:(NSTimer *)aTimer { + void (^block)(NSTimer *) = [aTimer userInfo]; + if (block) + block(aTimer); +} + ++ (NSString*) luaTrace:(lua_State*) L{ + // 打印lua调用栈开始 + lua_getglobal(L, "debug"); + lua_getfield(L, -1, "traceback"); + int iError = lua_pcall( L,//VMachine + 0,//Argument Count + 1,//Return Value Count + 0); + const char* s = lua_tostring(L, -1); + NSString* stack = [NSString stringWithFormat:@"%s",s]; + NSLog(@"err:%d \n %@", iError, stack); + return stack; +} + ++ (UIImage*) image:(UIImage*)image croppingToRect:(CGRect)rect +{ + UIGraphicsBeginImageContext(rect.size); + + CGContextRef currentContext = UIGraphicsGetCurrentContext(); + + CGRect clippedRect = CGRectMake(0, 0, rect.size.width, rect.size.height); + + CGContextClipToRect( currentContext, clippedRect); + + CGRect drawRect = CGRectMake(rect.origin.x * -1, + + rect.origin.y * -1, + + image.size.width, + + image.size.height); + + CGContextTranslateCTM(currentContext, 0.0, rect.size.height); + + CGContextScaleCTM(currentContext, 1.0, -1.0); + + CGContextDrawImage(currentContext, drawRect, image.CGImage); + + UIImage *cropped = UIGraphicsGetImageFromCurrentImageContext(); + + UIGraphicsEndImageContext(); + return cropped; +} + +void LVLog( NSString* format, ... ){ +#ifdef DEBUG + va_list params; //定义一个指向个数可变的参数列表指针; + va_start(params,format);//va_start 得到第一个可变参数地址, + NSString* s = [[NSString alloc] initWithFormat:format arguments:params]; + NSLog(@"[LuaView]%@", s); + va_end(params); +#endif +} + +void LVError( NSString* format, ... ){ +#ifdef DEBUG + va_list params; //定义一个指向个数可变的参数列表指针; + va_start(params,format);//va_start 得到第一个可变参数地址, + NSString* s = [[NSString alloc] initWithFormat:format arguments:params]; + NSLog(@"[LuaView][error]%@", s); + va_end(params); +#endif +} + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/NSObject+LuaView.h b/IOS/SDK/LuaViewSDK/Classes/lvsdk/NSObject+LuaView.h new file mode 100644 index 00000000..a1302f7b --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/NSObject+LuaView.h @@ -0,0 +1,24 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ +#import +#import "LVHeads.h" + + +@interface NSObject(NSObjectLuaView) + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; +- (id) lv_nativeObject; + +- (void) lv_callLuaCallback:(NSString*) key1; +- (void) lv_callLuaCallback:(NSString*) key1 key2:(NSString*) key2 argN:(int) argN; +- (NSString*) lv_callLuaFunc:(NSString*) funcName args:(NSArray*) args; + +- (void) lv_buttonCallBack; + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/NSObject+LuaView.m b/IOS/SDK/LuaViewSDK/Classes/lvsdk/NSObject+LuaView.m new file mode 100644 index 00000000..2dbab0f3 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/NSObject+LuaView.m @@ -0,0 +1,84 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "NSObject+LuaView.h" +#import "LuaViewCore.h" + +@implementation NSObject(NSObjectLuaView) + +- (LuaViewCore*) lv_luaviewCore{ + return nil; +} + +- (void) setLv_luaviewCore:(LuaViewCore *)lv_luaviewCore{ +} + +- (LVUserDataInfo*)lv_userData{ + return nil; +} + +- (void) setLv_userData:(LVUserDataInfo *)userData{ +} + +- (void) lv_callLuaCallback:(NSString*) key1{ + [self lv_callLuaCallback:key1 key2:nil argN:0]; +} + +- (void) lv_callLuaCallback:(NSString*) key1 key2:(NSString*) key2 argN:(int)argN{ + lua_State* l = self.lv_luaviewCore.l; + if( l && self.lv_userData && key1){ + lua_checkstack32(l); + lv_pushUserdata(l, self.lv_userData); + lv_pushUDataRef(l, USERDATA_KEY_DELEGATE); + if( lua_type(l, -1) == LUA_TTABLE ) { + lua_getfield(l, -1, STR_CALLBACK); + if( lua_type(l, -1)==LUA_TNIL ) { + lua_remove(l, -1); + } else { + lua_remove(l, -2); + } + } + [LVUtil call:l key1:key1.UTF8String key2:key2.UTF8String key3:NULL nargs:argN nrets:0 retType:LUA_TNONE]; + } +} + +-(NSString*) lv_callLuaFunc:(NSString*) functionName args:(NSArray*) args{ + lua_State* L = self.lv_luaviewCore.l; + if( L ){ + lua_checkstack(L, (int)args.count*2 + 2); + + for( int i=0; i +#import "LVRefreshConst.h" + +@class LVRefreshHeader; + +@interface UIScrollView (LVRefresh) +/** 下拉刷新控件 */ +@property (strong, nonatomic) LVRefreshHeader * lv_refresh_header; + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/UIScrollView+LVRefresh.m b/IOS/SDK/LuaViewSDK/Classes/lvsdk/UIScrollView+LVRefresh.m new file mode 100644 index 00000000..ba9169e5 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/UIScrollView+LVRefresh.m @@ -0,0 +1,34 @@ + +#import "UIScrollView+LVRefresh.h" +#import "LVRefreshHeader.h" +#import + + + +@implementation UIScrollView (LVRefresh) + +#pragma mark - header +static const char LVRefreshHeaderKey = '\0'; +- (void)setLv_refresh_header:(LVRefreshHeader *)header +{ + if (header != self.lv_refresh_header) { + // 删除旧的,添加新的 + [self.lv_refresh_header removeFromSuperview]; + [self insertSubview:header atIndex:0]; + + // 存储新的 + [self willChangeValueForKey:@"lv_refresh_header"]; // KVO + objc_setAssociatedObject(self, &LVRefreshHeaderKey, + header, OBJC_ASSOCIATION_ASSIGN); + [self didChangeValueForKey:@"lv_refresh_header"]; // KVO + } +} + +- (LVRefreshHeader *)lv_refresh_header +{ + return objc_getAssociatedObject(self, &LVRefreshHeaderKey); +} + + +@end + diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/UIScrollView+LuaView.h b/IOS/SDK/LuaViewSDK/Classes/lvsdk/UIScrollView+LuaView.h new file mode 100644 index 00000000..a5100279 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/UIScrollView+LuaView.h @@ -0,0 +1,41 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" +#import "UIView+LuaView.h" + + +@interface UIScrollView (UIScrollViewLuaView) + + +// 下拉刷新组件 需要重载的API +- (void) lv_initRefreshHeader;// 开启下拉刷新功能 +- (void) lv_hiddenRefreshHeader:(BOOL) hidden; +- (void) lv_beginRefreshing;// 进入刷新状态 +- (void) lv_endRefreshing;// 结束刷新状态 +- (BOOL) lv_isRefreshing;// 是否正在刷新 + +// 加载更多组件 需要重载的API +- (void) lv_initRefreshFooter;// 开启上拉加载更多功能 +- (void) lv_hiddenRefreshFooter:(BOOL) hidden; +- (void) lv_noticeNoMoreData;// 提示没有更多的数据 +- (void) lv_resetNoMoreData;// 重置没有更多的数据(消除没有更多数据的状态) + +/* + * 回调脚本开始下拉刷新 + */ +- (void) lv_refreshHeaderToRefresh; + +/* + * 回调脚本开始加载更多 + */ +- (void) lv_refreshFooterToLoadMore; + + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/UIScrollView+LuaView.m b/IOS/SDK/LuaViewSDK/Classes/lvsdk/UIScrollView+LuaView.m new file mode 100644 index 00000000..e3118184 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/UIScrollView+LuaView.m @@ -0,0 +1,57 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "UIScrollView+LuaView.h" +#import "LuaViewCore.h" +#import "NSObject+LuaView.h" + + +@implementation UIScrollView (UIScrollViewLuaView) + + +// 下拉刷新 +-(void) lv_initRefreshHeader{// 初始化下拉刷新功能 +} + +- (void) lv_hiddenRefreshHeader:(BOOL) hidden{ +} + +- (void) lv_beginRefreshing{// 进入刷新状态 +} + +- (void) lv_endRefreshing{// 结束刷新状态 +} + +- (BOOL) lv_isRefreshing{// 是否正在刷新 + return NO; +} + +// 加载更多 +- (void) lv_initRefreshFooter{// 初始化上拉加载更多功能 +} +- (void) lv_hiddenRefreshFooter:(BOOL) hidden{ +} + +- (void) lv_noticeNoMoreData{// 提示没有更多的数据 +} + +- (void) lv_resetNoMoreData{// 重置没有更多的数据(消除没有更多数据的状态) +} + +- (void) lv_refreshHeaderToRefresh{ + // 开始下拉刷新调用 + [self lv_callLuaCallback:@"PullDown"]; +} + +- (void) lv_refreshFooterToLoadMore{ + // 开始上拉刷新调用 + [self lv_callLuaCallback:@"PullUpRefresh"]; +} + + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/UIView+LuaView.h b/IOS/SDK/LuaViewSDK/Classes/lvsdk/UIView+LuaView.h new file mode 100644 index 00000000..c353cda2 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/UIView+LuaView.h @@ -0,0 +1,37 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + +@interface UIView(UIViewLuaView) + + + +@property(nonatomic,assign) NSUInteger lv_align; +@property(nonatomic,assign) BOOL lv_isCallbackAddClickGesture;// 设置Callback时需要注册手势回调,才设置成true + +-(void) lv_callbackAddClickGesture;// 回调添加 + +- (void) lv_alignSubviews; + +- (void) lv_alignSelfWithSuperRect:(CGRect) rect; + +-(id) lv_getNativeView; + +// shapelayer +@property(nonatomic,strong) CAShapeLayer* lv_shapeLayer; +-(CALayer*) lv_layer; +-(void) lv_createShapelayer:(NSArray*) arr; + +-(void) lv_effectParallax:(CGFloat)dx dy:(CGFloat)dy; +-(void) lv_effectClick:(NSInteger)color alpha:(CGFloat)alpha; + +@property(nonatomic,assign) BOOL lv_canvas; + +@end diff --git a/IOS/SDK/LuaViewSDK/Classes/lvsdk/UIView+LuaView.m b/IOS/SDK/LuaViewSDK/Classes/lvsdk/UIView+LuaView.m new file mode 100644 index 00000000..6424f266 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Classes/lvsdk/UIView+LuaView.m @@ -0,0 +1,127 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "UIView+LuaView.h" +#import "LuaViewCore.h" +#import "LVHeads.h" +#import "NSObject+LuaView.h" + +@implementation UIView (UIViewLuaView) + +-(BOOL) lv_isCallbackAddClickGesture{ + return NO; +} +-(void) setLv_isCallbackAddClickGesture:(BOOL)lv_isCallbackAddClickGesture{ +} + +-(void) lv_callbackAddClickGesture { + if( self.lv_isCallbackAddClickGesture ){ + self.lv_isCallbackAddClickGesture = NO; + UITapGestureRecognizer* gesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(lv_buttonCallBack)]; + self.userInteractionEnabled = YES; + [self addGestureRecognizer:gesture]; + } +} + +// align + +-(NSUInteger) lv_align{ + return 0; +} + +-(void) setLv_align:(NSUInteger)lv_align{ +} + +- (void) lv_alignSubviews { + CGRect rect = self.frame; + NSArray* subviews = [self subviews]; + for( UIView* view in subviews){ + [view lv_alignSelfWithSuperRect:rect]; + } +} + +- (void) lv_alignSelfWithSuperRect:(CGRect) rect{ + NSUInteger ali = self.lv_align; + if( ali ){ + CGRect r0 = [self frame]; + CGRect r = r0; + if( ali&LV_ALIGN_LEFT ) { + r.origin.x = 0; + } else if( ali&LV_ALIGN_H_CENTER ) { + r.origin.x = (rect.size.width-r.size.width)/2; + } else if( ali&LV_ALIGN_RIGHT ) { + r.origin.x = rect.size.width-r.size.width; + } + if( ali&LV_ALIGN_TOP ) { + r.origin.y = 0; + } else if( ali&LV_ALIGN_V_CENTER ) { + r.origin.y = (rect.size.height-r.size.height)/2; + } else if( ali&LV_ALIGN_BOTTOM ) { + r.origin.y = (rect.size.height-r.size.height); + } + if( !CGRectEqualToRect(r0, r) ) { + self.frame = r; + } + } +} + +-(id) lv_getNativeView{ + return self; +} + +-(CAShapeLayer*) lv_shapeLayer{ + return nil; +} + +-(void) setLv_shapeLayer:(CAShapeLayer *)lv_shapeLayer{ +} + +-(CALayer*) lv_layer{ + if( self.lv_shapeLayer ){ + return self.lv_shapeLayer; + } + return self.layer; +} + +-(void) lv_createShapelayer:(NSArray*)arr{ + [self.lv_shapeLayer removeFromSuperlayer]; + self.lv_shapeLayer = nil; + + CAShapeLayer *borderLayer = [CAShapeLayer layer]; + borderLayer.bounds = self.bounds; + borderLayer.position = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds)); + borderLayer.lineWidth = self.layer.borderWidth; + + borderLayer.fillColor = [UIColor clearColor].CGColor; + borderLayer.strokeColor = self.layer.borderColor; + borderLayer.path = [UIBezierPath bezierPathWithRoundedRect:borderLayer.bounds cornerRadius:self.layer.cornerRadius].CGPath; + borderLayer.lineDashPattern = arr; + self.lv_shapeLayer = borderLayer; + + if( self.lv_shapeLayer ) { + self.layer.borderColor = [UIColor clearColor].CGColor; + [self.layer addSublayer:self.lv_shapeLayer]; + } +} + +-(void) lv_effectParallax:(CGFloat)dx dy:(CGFloat)dy{ + // 视差效果 +} + +-(void) lv_effectClick:(NSInteger)color alpha:(CGFloat)alpha{ + // 点击特效 +} + +-(BOOL) lv_canvas{ + return NO; +} + +-(void) setLv_canvas:(BOOL)lv_canvas{ +} + +@end diff --git a/IOS/SDK/LuaViewSDK/Info.plist b/IOS/SDK/LuaViewSDK/Info.plist new file mode 100644 index 00000000..2d9178b8 --- /dev/null +++ b/IOS/SDK/LuaViewSDK/Info.plist @@ -0,0 +1,22 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + + diff --git a/IOS/SDK/LuaViewSDK/LuaViewSDK-Info.plist b/IOS/SDK/LuaViewSDK/LuaViewSDK-Info.plist new file mode 100644 index 00000000..c03188bc --- /dev/null +++ b/IOS/SDK/LuaViewSDK/LuaViewSDK-Info.plist @@ -0,0 +1,5 @@ + + + +CFBundleDevelopmentRegion + diff --git a/IOS/SDK/LuaViewSDK/LuaViewSDK-Prefix.pch b/IOS/SDK/LuaViewSDK/LuaViewSDK-Prefix.pch new file mode 100644 index 00000000..e69de29b diff --git a/IOS/SDK/Podfile b/IOS/SDK/Podfile new file mode 100644 index 00000000..cda98aaf --- /dev/null +++ b/IOS/SDK/Podfile @@ -0,0 +1,19 @@ +# Uncomment this line to define a global platform for your project +# platform :ios, '8.0' +# Uncomment this line if you're using Swift +# use_frameworks! + +platform :ios, "8.0" + +target 'LuaViewSDK' do + pod 'liblua', '5.1.4.3' +end + +target 'Dummy' do + +end + +target 'LuaViewLib' do + +end + diff --git a/IOS/SDK/Podfile.lock b/IOS/SDK/Podfile.lock new file mode 100644 index 00000000..b4792e26 --- /dev/null +++ b/IOS/SDK/Podfile.lock @@ -0,0 +1,12 @@ +PODS: + - liblua (5.1.4.3) + +DEPENDENCIES: + - liblua (= 5.1.4.3) + +SPEC CHECKSUMS: + liblua: 1e187e0fd4e6cec2f712463cff9ace4d17dedcb0 + +PODFILE CHECKSUM: 937b799726a57c8017dd1748fe5df4681972d211 + +COCOAPODS: 1.2.0 diff --git a/IOS/SDK/Pods/Manifest.lock b/IOS/SDK/Pods/Manifest.lock new file mode 100644 index 00000000..b4792e26 --- /dev/null +++ b/IOS/SDK/Pods/Manifest.lock @@ -0,0 +1,12 @@ +PODS: + - liblua (5.1.4.3) + +DEPENDENCIES: + - liblua (= 5.1.4.3) + +SPEC CHECKSUMS: + liblua: 1e187e0fd4e6cec2f712463cff9ace4d17dedcb0 + +PODFILE CHECKSUM: 937b799726a57c8017dd1748fe5df4681972d211 + +COCOAPODS: 1.2.0 diff --git a/IOS/SDK/Pods/Pods.xcodeproj/project.pbxproj b/IOS/SDK/Pods/Pods.xcodeproj/project.pbxproj new file mode 100644 index 00000000..0848bfa1 --- /dev/null +++ b/IOS/SDK/Pods/Pods.xcodeproj/project.pbxproj @@ -0,0 +1,626 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + 21DA712F769D001B386DB690AA99B68A /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6604A7D69453B4569E4E4827FB9155A9 /* Foundation.framework */; }; + 22EC2627DA2EA33B22E376A202C154B9 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6604A7D69453B4569E4E4827FB9155A9 /* Foundation.framework */; }; + 3373EFCD7F653DEDC9D947F96D1DE155 /* Pods-LuaViewLib-dummy.m in Sources */ = {isa = PBXBuildFile; fileRef = 30040E7B1FB9032D835FAB5C1FF15F0B /* Pods-LuaViewLib-dummy.m */; }; + 7ADDCF1BCB9863DD40E7078D178D42FC /* Pods-Dummy-dummy.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F554A9CA77276E6BDDFA9BCE0861D7B /* Pods-Dummy-dummy.m */; }; + 86B47FAC5D9A786542E45CB63F77505D /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6604A7D69453B4569E4E4827FB9155A9 /* Foundation.framework */; }; + B96F997B48EF2FE4979413FB565CB555 /* Pods-LuaViewSDK-dummy.m in Sources */ = {isa = PBXBuildFile; fileRef = ACBF966D65A9866E7D84114BB97E9DEA /* Pods-LuaViewSDK-dummy.m */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + 052F013870A94A6B1A6EFFCA6EA0C736 /* Pods-LuaViewLib-frameworks.sh */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.script.sh; path = "Pods-LuaViewLib-frameworks.sh"; sourceTree = ""; }; + 0BA8333E6C78D64DBCB1373E435FEDB1 /* libPods-Dummy.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; name = "libPods-Dummy.a"; path = "libPods-Dummy.a"; sourceTree = BUILT_PRODUCTS_DIR; }; + 0DDDB42DC3B54E98B7A6867BC96FF37F /* lcode.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = lcode.h; path = include/lcode.h; sourceTree = ""; }; + 11C2B6B6A4B84C26FDB9E0D97C50F4CD /* lua.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = lua.h; path = include/lua.h; sourceTree = ""; }; + 1362E4B105A1605411B72A5FC0685BEC /* Pods-LuaViewLib.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; path = "Pods-LuaViewLib.debug.xcconfig"; sourceTree = ""; }; + 17FD82A27CCFC34E78D7C5BAEF59D61B /* Pods-Dummy.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; path = "Pods-Dummy.debug.xcconfig"; sourceTree = ""; }; + 18605668A74AFF868DC06363EAB34813 /* Pods-LuaViewSDK.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; path = "Pods-LuaViewSDK.release.xcconfig"; sourceTree = ""; }; + 267AC7C3342785F1CBB02BC488A6775D /* lstate.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = lstate.h; path = include/lstate.h; sourceTree = ""; }; + 2E501966CDB068ED61DE910EE49DCDC3 /* copy-framework-resources.rb */ = {isa = PBXFileReference; includeInIndex = 1; path = "copy-framework-resources.rb"; sourceTree = ""; }; + 30040E7B1FB9032D835FAB5C1FF15F0B /* Pods-LuaViewLib-dummy.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; path = "Pods-LuaViewLib-dummy.m"; sourceTree = ""; }; + 312732138A25DD780E02CF2209411190 /* lgc.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = lgc.h; path = include/lgc.h; sourceTree = ""; }; + 36A47ACB460DF76ADB5929B8938C6A23 /* Pods-Dummy-acknowledgements.plist */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.plist.xml; path = "Pods-Dummy-acknowledgements.plist"; sourceTree = ""; }; + 3B7877CA5A1AE189235CA5D0D2A1BF59 /* Pods-LuaViewSDK-frameworks.sh */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.script.sh; path = "Pods-LuaViewSDK-frameworks.sh"; sourceTree = ""; }; + 3C6A9470FA6C41264147C65B429E502C /* lualib.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = lualib.h; path = include/lualib.h; sourceTree = ""; }; + 3DA6D56B67E30E87589C1E70079C227B /* Pods-Dummy-resources.sh */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.script.sh; path = "Pods-Dummy-resources.sh"; sourceTree = ""; }; + 3E811C995FA73A86D770ECC87C5749AA /* lauxlib.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = lauxlib.h; path = include/lauxlib.h; sourceTree = ""; }; + 3FDB703A110AB23F5AF9656DFCA2356F /* lvm.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = lvm.h; path = include/lvm.h; sourceTree = ""; }; + 4379951CCFAA63938B885ECD3EF10C91 /* Pods-LuaViewSDK.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; path = "Pods-LuaViewSDK.debug.xcconfig"; sourceTree = ""; }; + 43D9F6B5ACC6D96491C42B03C0C16D2A /* libPods-LuaViewSDK.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; name = "libPods-LuaViewSDK.a"; path = "libPods-LuaViewSDK.a"; sourceTree = BUILT_PRODUCTS_DIR; }; + 4B2FC280C9B91E636EEB5C312E3AC696 /* llex.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = llex.h; path = include/llex.h; sourceTree = ""; }; + 5E36E7472C428689D36FB77A26840863 /* Pods-LuaViewLib-acknowledgements.markdown */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; path = "Pods-LuaViewLib-acknowledgements.markdown"; sourceTree = ""; }; + 5E5B94E16BD206C75BD6B65A7ECAD961 /* ldo.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = ldo.h; path = include/ldo.h; sourceTree = ""; }; + 5F554A9CA77276E6BDDFA9BCE0861D7B /* Pods-Dummy-dummy.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; path = "Pods-Dummy-dummy.m"; sourceTree = ""; }; + 60BB9505F8A843D03B4D6504524849EB /* lundump.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = lundump.h; path = include/lundump.h; sourceTree = ""; }; + 6604A7D69453B4569E4E4827FB9155A9 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS10.3.sdk/System/Library/Frameworks/Foundation.framework; sourceTree = DEVELOPER_DIR; }; + 67FEC304990A97691115C546995C8834 /* Pods-LuaViewLib-resources.sh */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.script.sh; path = "Pods-LuaViewLib-resources.sh"; sourceTree = ""; }; + 75A5ECCAA7476792E52941F015CE6F3F /* Pods-Dummy-frameworks.sh */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.script.sh; path = "Pods-Dummy-frameworks.sh"; sourceTree = ""; }; + 7C336F9330C2BAD7144E267031E80DB9 /* Pods-LuaViewSDK-resources.sh */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.script.sh; path = "Pods-LuaViewSDK-resources.sh"; sourceTree = ""; }; + 7C789567719873177BF6E8332EC81F4D /* Pods-Dummy.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; path = "Pods-Dummy.release.xcconfig"; sourceTree = ""; }; + 82992175BDF8D6BFAA3804F0CAC51405 /* ltm.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = ltm.h; path = include/ltm.h; sourceTree = ""; }; + 8D1B536DFF548BF58F8C51E256CE3D24 /* luaconf.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = luaconf.h; path = include/luaconf.h; sourceTree = ""; }; + 905A308B35F8387C93621027CB59DCD8 /* Pods-Dummy-acknowledgements.markdown */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; path = "Pods-Dummy-acknowledgements.markdown"; sourceTree = ""; }; + 93A4A3777CF96A4AAC1D13BA6DCCEA73 /* Podfile */ = {isa = PBXFileReference; explicitFileType = text.script.ruby; includeInIndex = 1; lastKnownFileType = text; name = Podfile; path = ../Podfile; sourceTree = SOURCE_ROOT; xcLanguageSpecificationIdentifier = xcode.lang.ruby; }; + 9B4525398F9E82E4F82AE31C1926F88A /* lzio.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = lzio.h; path = include/lzio.h; sourceTree = ""; }; + A415A3124761D60699F51D4CFBB06649 /* llimits.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = llimits.h; path = include/llimits.h; sourceTree = ""; }; + ACBF966D65A9866E7D84114BB97E9DEA /* Pods-LuaViewSDK-dummy.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; path = "Pods-LuaViewSDK-dummy.m"; sourceTree = ""; }; + B2547B51976EAC7769ECD885B6722F76 /* lparser.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = lparser.h; path = include/lparser.h; sourceTree = ""; }; + B29970FF14BC57628904B992117C9CF1 /* lstring.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = lstring.h; path = include/lstring.h; sourceTree = ""; }; + B788D2F96A8E267E23A57BBC87B4F4E4 /* Pods-LuaViewSDK-acknowledgements.plist */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.plist.xml; path = "Pods-LuaViewSDK-acknowledgements.plist"; sourceTree = ""; }; + BB39C0FA9F5A310EC70419BC3B882CCB /* lopcodes.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = lopcodes.h; path = include/lopcodes.h; sourceTree = ""; }; + C1ED9902BE40F60630E814E9759605A4 /* liblua.a */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = archive.ar; name = liblua.a; path = lib/liblua.a; sourceTree = ""; }; + C82CF6B661F6D2E2D693FE14CB88BF6A /* copy-framework-resources.rb */ = {isa = PBXFileReference; includeInIndex = 1; path = "copy-framework-resources.rb"; sourceTree = ""; }; + D0083DAD99ECAF62C212607A6350A3E2 /* ldebug.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = ldebug.h; path = include/ldebug.h; sourceTree = ""; }; + D04E0E0F3A88D78832B339290FDB04F5 /* copy-framework-resources.rb */ = {isa = PBXFileReference; includeInIndex = 1; path = "copy-framework-resources.rb"; sourceTree = ""; }; + D3BBEA433DBC432E652C7A31C587436B /* Pods-LuaViewLib-acknowledgements.plist */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.plist.xml; path = "Pods-LuaViewLib-acknowledgements.plist"; sourceTree = ""; }; + D47A00253E8F5F2DF40001F00CCD78C0 /* ltable.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = ltable.h; path = include/ltable.h; sourceTree = ""; }; + DAB9D55CED32DDD0EC264DA9FB67DD27 /* lmem.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = lmem.h; path = include/lmem.h; sourceTree = ""; }; + DB62BD23CF003FA1B9267FEE59F027C1 /* lapi.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = lapi.h; path = include/lapi.h; sourceTree = ""; }; + E0C169C044022E026D92D501C31F62FE /* Pods-LuaViewLib.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; path = "Pods-LuaViewLib.release.xcconfig"; sourceTree = ""; }; + E69CBBB823A3BCF1B11E3782184EA9D8 /* lobject.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = lobject.h; path = include/lobject.h; sourceTree = ""; }; + ECFA9E11D4F508E194A653DB54B65D08 /* lfunc.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = lfunc.h; path = include/lfunc.h; sourceTree = ""; }; + F37FA65868A1450ACE4ADDFC719116A1 /* Pods-LuaViewSDK-acknowledgements.markdown */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; path = "Pods-LuaViewSDK-acknowledgements.markdown"; sourceTree = ""; }; + F46E23D3BB448308B5EC7963A364D83F /* libPods-LuaViewLib.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; name = "libPods-LuaViewLib.a"; path = "libPods-LuaViewLib.a"; sourceTree = BUILT_PRODUCTS_DIR; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 1A79EBAC49A8F00E1B4ED087EBE02B93 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 21DA712F769D001B386DB690AA99B68A /* Foundation.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + BAE001FC2B2DE2BADD54E44F067220B7 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 22EC2627DA2EA33B22E376A202C154B9 /* Foundation.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + EAF840E9E8BA2872EE9246B3D53048F6 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 86B47FAC5D9A786542E45CB63F77505D /* Foundation.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 0F2400327D703634AAC3360F79471872 /* Pods-Dummy */ = { + isa = PBXGroup; + children = ( + 2E501966CDB068ED61DE910EE49DCDC3 /* copy-framework-resources.rb */, + 905A308B35F8387C93621027CB59DCD8 /* Pods-Dummy-acknowledgements.markdown */, + 36A47ACB460DF76ADB5929B8938C6A23 /* Pods-Dummy-acknowledgements.plist */, + 5F554A9CA77276E6BDDFA9BCE0861D7B /* Pods-Dummy-dummy.m */, + 75A5ECCAA7476792E52941F015CE6F3F /* Pods-Dummy-frameworks.sh */, + 3DA6D56B67E30E87589C1E70079C227B /* Pods-Dummy-resources.sh */, + 17FD82A27CCFC34E78D7C5BAEF59D61B /* Pods-Dummy.debug.xcconfig */, + 7C789567719873177BF6E8332EC81F4D /* Pods-Dummy.release.xcconfig */, + ); + name = "Pods-Dummy"; + path = "Target Support Files/Pods-Dummy"; + sourceTree = ""; + }; + 2205558409404C0002E1DBB63B1FDA4F /* Pods-LuaViewSDK */ = { + isa = PBXGroup; + children = ( + C82CF6B661F6D2E2D693FE14CB88BF6A /* copy-framework-resources.rb */, + F37FA65868A1450ACE4ADDFC719116A1 /* Pods-LuaViewSDK-acknowledgements.markdown */, + B788D2F96A8E267E23A57BBC87B4F4E4 /* Pods-LuaViewSDK-acknowledgements.plist */, + ACBF966D65A9866E7D84114BB97E9DEA /* Pods-LuaViewSDK-dummy.m */, + 3B7877CA5A1AE189235CA5D0D2A1BF59 /* Pods-LuaViewSDK-frameworks.sh */, + 7C336F9330C2BAD7144E267031E80DB9 /* Pods-LuaViewSDK-resources.sh */, + 4379951CCFAA63938B885ECD3EF10C91 /* Pods-LuaViewSDK.debug.xcconfig */, + 18605668A74AFF868DC06363EAB34813 /* Pods-LuaViewSDK.release.xcconfig */, + ); + name = "Pods-LuaViewSDK"; + path = "Target Support Files/Pods-LuaViewSDK"; + sourceTree = ""; + }; + 3964458B8E7D205C9CB68AFAB56CCA86 /* liblua */ = { + isa = PBXGroup; + children = ( + DB62BD23CF003FA1B9267FEE59F027C1 /* lapi.h */, + 3E811C995FA73A86D770ECC87C5749AA /* lauxlib.h */, + 0DDDB42DC3B54E98B7A6867BC96FF37F /* lcode.h */, + D0083DAD99ECAF62C212607A6350A3E2 /* ldebug.h */, + 5E5B94E16BD206C75BD6B65A7ECAD961 /* ldo.h */, + ECFA9E11D4F508E194A653DB54B65D08 /* lfunc.h */, + 312732138A25DD780E02CF2209411190 /* lgc.h */, + 4B2FC280C9B91E636EEB5C312E3AC696 /* llex.h */, + A415A3124761D60699F51D4CFBB06649 /* llimits.h */, + DAB9D55CED32DDD0EC264DA9FB67DD27 /* lmem.h */, + E69CBBB823A3BCF1B11E3782184EA9D8 /* lobject.h */, + BB39C0FA9F5A310EC70419BC3B882CCB /* lopcodes.h */, + B2547B51976EAC7769ECD885B6722F76 /* lparser.h */, + 267AC7C3342785F1CBB02BC488A6775D /* lstate.h */, + B29970FF14BC57628904B992117C9CF1 /* lstring.h */, + D47A00253E8F5F2DF40001F00CCD78C0 /* ltable.h */, + 82992175BDF8D6BFAA3804F0CAC51405 /* ltm.h */, + 11C2B6B6A4B84C26FDB9E0D97C50F4CD /* lua.h */, + 8D1B536DFF548BF58F8C51E256CE3D24 /* luaconf.h */, + 3C6A9470FA6C41264147C65B429E502C /* lualib.h */, + 60BB9505F8A843D03B4D6504524849EB /* lundump.h */, + 3FDB703A110AB23F5AF9656DFCA2356F /* lvm.h */, + 9B4525398F9E82E4F82AE31C1926F88A /* lzio.h */, + BD6F68E26C817A30DFF125BAD7660196 /* Frameworks */, + ); + name = liblua; + path = liblua; + sourceTree = ""; + }; + 78A612D23682CAB99566BF2C1AF26BAA /* Pods */ = { + isa = PBXGroup; + children = ( + 3964458B8E7D205C9CB68AFAB56CCA86 /* liblua */, + ); + name = Pods; + sourceTree = ""; + }; + 7DB346D0F39D3F0E887471402A8071AB = { + isa = PBXGroup; + children = ( + 93A4A3777CF96A4AAC1D13BA6DCCEA73 /* Podfile */, + BC3CA7F9E30CC8F7E2DD044DD34432FC /* Frameworks */, + 78A612D23682CAB99566BF2C1AF26BAA /* Pods */, + B928F10BA4A05DF21354B54BB45B8B43 /* Products */, + 917E842DD0C954F07854EA416F8C63F4 /* Targets Support Files */, + ); + sourceTree = ""; + }; + 917E842DD0C954F07854EA416F8C63F4 /* Targets Support Files */ = { + isa = PBXGroup; + children = ( + 0F2400327D703634AAC3360F79471872 /* Pods-Dummy */, + D52EC4432E855BF9D804BF91AC33323D /* Pods-LuaViewLib */, + 2205558409404C0002E1DBB63B1FDA4F /* Pods-LuaViewSDK */, + ); + name = "Targets Support Files"; + sourceTree = ""; + }; + B928F10BA4A05DF21354B54BB45B8B43 /* Products */ = { + isa = PBXGroup; + children = ( + 0BA8333E6C78D64DBCB1373E435FEDB1 /* libPods-Dummy.a */, + F46E23D3BB448308B5EC7963A364D83F /* libPods-LuaViewLib.a */, + 43D9F6B5ACC6D96491C42B03C0C16D2A /* libPods-LuaViewSDK.a */, + ); + name = Products; + sourceTree = ""; + }; + BC3CA7F9E30CC8F7E2DD044DD34432FC /* Frameworks */ = { + isa = PBXGroup; + children = ( + D35AF013A5F0BAD4F32504907A52519E /* iOS */, + ); + name = Frameworks; + sourceTree = ""; + }; + BD6F68E26C817A30DFF125BAD7660196 /* Frameworks */ = { + isa = PBXGroup; + children = ( + C1ED9902BE40F60630E814E9759605A4 /* liblua.a */, + ); + name = Frameworks; + sourceTree = ""; + }; + D35AF013A5F0BAD4F32504907A52519E /* iOS */ = { + isa = PBXGroup; + children = ( + 6604A7D69453B4569E4E4827FB9155A9 /* Foundation.framework */, + ); + name = iOS; + sourceTree = ""; + }; + D52EC4432E855BF9D804BF91AC33323D /* Pods-LuaViewLib */ = { + isa = PBXGroup; + children = ( + D04E0E0F3A88D78832B339290FDB04F5 /* copy-framework-resources.rb */, + 5E36E7472C428689D36FB77A26840863 /* Pods-LuaViewLib-acknowledgements.markdown */, + D3BBEA433DBC432E652C7A31C587436B /* Pods-LuaViewLib-acknowledgements.plist */, + 30040E7B1FB9032D835FAB5C1FF15F0B /* Pods-LuaViewLib-dummy.m */, + 052F013870A94A6B1A6EFFCA6EA0C736 /* Pods-LuaViewLib-frameworks.sh */, + 67FEC304990A97691115C546995C8834 /* Pods-LuaViewLib-resources.sh */, + 1362E4B105A1605411B72A5FC0685BEC /* Pods-LuaViewLib.debug.xcconfig */, + E0C169C044022E026D92D501C31F62FE /* Pods-LuaViewLib.release.xcconfig */, + ); + name = "Pods-LuaViewLib"; + path = "Target Support Files/Pods-LuaViewLib"; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 4B9248CE7F8F66B425AF2AB9A326E015 /* Pods-LuaViewSDK */ = { + isa = PBXNativeTarget; + buildConfigurationList = 29D4E060B6661C2C14C5417518576F3E /* Build configuration list for PBXNativeTarget "Pods-LuaViewSDK" */; + buildPhases = ( + 39B40A37143072440C309588A61B9FAF /* Sources */, + BAE001FC2B2DE2BADD54E44F067220B7 /* Frameworks */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = "Pods-LuaViewSDK"; + productName = "Pods-LuaViewSDK"; + productReference = 43D9F6B5ACC6D96491C42B03C0C16D2A /* libPods-LuaViewSDK.a */; + productType = "com.apple.product-type.library.static"; + }; + 53FBD0EA3FFBA318039D7E07C44FB509 /* Pods-Dummy */ = { + isa = PBXNativeTarget; + buildConfigurationList = B08142893BE81AFFB2D0DBCB5773EF4C /* Build configuration list for PBXNativeTarget "Pods-Dummy" */; + buildPhases = ( + D7B5596C81D16784EDEFDE6D1A28B225 /* Sources */, + EAF840E9E8BA2872EE9246B3D53048F6 /* Frameworks */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = "Pods-Dummy"; + productName = "Pods-Dummy"; + productReference = 0BA8333E6C78D64DBCB1373E435FEDB1 /* libPods-Dummy.a */; + productType = "com.apple.product-type.library.static"; + }; + 8EEA3B1586E1628B265C1B9762A2E1FE /* Pods-LuaViewLib */ = { + isa = PBXNativeTarget; + buildConfigurationList = 8FD1832EAA068A2D71862F1A5A468BA4 /* Build configuration list for PBXNativeTarget "Pods-LuaViewLib" */; + buildPhases = ( + 129DA7004573FA1F95FC4183FB226A9B /* Sources */, + 1A79EBAC49A8F00E1B4ED087EBE02B93 /* Frameworks */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = "Pods-LuaViewLib"; + productName = "Pods-LuaViewLib"; + productReference = F46E23D3BB448308B5EC7963A364D83F /* libPods-LuaViewLib.a */; + productType = "com.apple.product-type.library.static"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + D41D8CD98F00B204E9800998ECF8427E /* Project object */ = { + isa = PBXProject; + attributes = { + LastSwiftUpdateCheck = 0830; + LastUpgradeCheck = 0700; + }; + buildConfigurationList = 2D8E8EC45A3A1A1D94AE762CB5028504 /* Build configuration list for PBXProject "Pods" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + ); + mainGroup = 7DB346D0F39D3F0E887471402A8071AB; + productRefGroup = B928F10BA4A05DF21354B54BB45B8B43 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 53FBD0EA3FFBA318039D7E07C44FB509 /* Pods-Dummy */, + 8EEA3B1586E1628B265C1B9762A2E1FE /* Pods-LuaViewLib */, + 4B9248CE7F8F66B425AF2AB9A326E015 /* Pods-LuaViewSDK */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXSourcesBuildPhase section */ + 129DA7004573FA1F95FC4183FB226A9B /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 3373EFCD7F653DEDC9D947F96D1DE155 /* Pods-LuaViewLib-dummy.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 39B40A37143072440C309588A61B9FAF /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + B96F997B48EF2FE4979413FB565CB555 /* Pods-LuaViewSDK-dummy.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + D7B5596C81D16784EDEFDE6D1A28B225 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 7ADDCF1BCB9863DD40E7078D178D42FC /* Pods-Dummy-dummy.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + 002215DD4349C411269E732A11239CCF /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 4379951CCFAA63938B885ECD3EF10C91 /* Pods-LuaViewSDK.debug.xcconfig */; + buildSettings = { + ARCHS = "$(ARCHS_STANDARD)"; + "CODE_SIGN_IDENTITY[sdk=appletvos*]" = ""; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; + "CODE_SIGN_IDENTITY[sdk=watchos*]" = ""; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_NO_COMMON_BLOCKS = YES; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + MACH_O_TYPE = staticlib; + MTL_ENABLE_DEBUG_INFO = YES; + OTHER_LDFLAGS = ""; + OTHER_LIBTOOLFLAGS = ""; + PODS_ROOT = "$(SRCROOT)"; + PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.${PRODUCT_NAME:rfc1034identifier}"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = iphoneos; + SKIP_INSTALL = YES; + }; + name = Debug; + }; + 18AB5737FEE2345B0B915B99B1DB2375 /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 18605668A74AFF868DC06363EAB34813 /* Pods-LuaViewSDK.release.xcconfig */; + buildSettings = { + ARCHS = "$(ARCHS_STANDARD)"; + "CODE_SIGN_IDENTITY[sdk=appletvos*]" = ""; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; + "CODE_SIGN_IDENTITY[sdk=watchos*]" = ""; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_NO_COMMON_BLOCKS = YES; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + MACH_O_TYPE = staticlib; + MTL_ENABLE_DEBUG_INFO = NO; + OTHER_LDFLAGS = ""; + OTHER_LIBTOOLFLAGS = ""; + PODS_ROOT = "$(SRCROOT)"; + PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.${PRODUCT_NAME:rfc1034identifier}"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = iphoneos; + SKIP_INSTALL = YES; + }; + name = Release; + }; + 34FE9531DA9AF2820790339988D5FF41 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CODE_SIGNING_REQUIRED = NO; + COPY_PHASE_STRIP = YES; + ENABLE_NS_ASSERTIONS = NO; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_PREPROCESSOR_DEFINITIONS = ( + "POD_CONFIGURATION_RELEASE=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + PROVISIONING_PROFILE_SPECIFIER = NO_SIGNING/; + STRIP_INSTALLED_PRODUCT = NO; + SYMROOT = "${SRCROOT}/../build"; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 4E9375D3D9F9193470641E8EAC529981 /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = E0C169C044022E026D92D501C31F62FE /* Pods-LuaViewLib.release.xcconfig */; + buildSettings = { + "CODE_SIGN_IDENTITY[sdk=appletvos*]" = ""; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; + "CODE_SIGN_IDENTITY[sdk=watchos*]" = ""; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_NO_COMMON_BLOCKS = YES; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + MACH_O_TYPE = staticlib; + MTL_ENABLE_DEBUG_INFO = NO; + OTHER_LDFLAGS = ""; + OTHER_LIBTOOLFLAGS = ""; + PODS_ROOT = "$(SRCROOT)"; + PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.${PRODUCT_NAME:rfc1034identifier}"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = iphoneos; + SKIP_INSTALL = YES; + }; + name = Release; + }; + 6AD60D4A93D4F220151EDD64F9F210BD /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 7C789567719873177BF6E8332EC81F4D /* Pods-Dummy.release.xcconfig */; + buildSettings = { + "CODE_SIGN_IDENTITY[sdk=appletvos*]" = ""; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; + "CODE_SIGN_IDENTITY[sdk=watchos*]" = ""; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_NO_COMMON_BLOCKS = YES; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + MACH_O_TYPE = staticlib; + MTL_ENABLE_DEBUG_INFO = NO; + OTHER_LDFLAGS = ""; + OTHER_LIBTOOLFLAGS = ""; + PODS_ROOT = "$(SRCROOT)"; + PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.${PRODUCT_NAME:rfc1034identifier}"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = iphoneos; + SKIP_INSTALL = YES; + }; + name = Release; + }; + A72F28E9C98DD174D627EA09BC317FDE /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 17FD82A27CCFC34E78D7C5BAEF59D61B /* Pods-Dummy.debug.xcconfig */; + buildSettings = { + "CODE_SIGN_IDENTITY[sdk=appletvos*]" = ""; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; + "CODE_SIGN_IDENTITY[sdk=watchos*]" = ""; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_NO_COMMON_BLOCKS = YES; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + MACH_O_TYPE = staticlib; + MTL_ENABLE_DEBUG_INFO = YES; + OTHER_LDFLAGS = ""; + OTHER_LIBTOOLFLAGS = ""; + PODS_ROOT = "$(SRCROOT)"; + PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.${PRODUCT_NAME:rfc1034identifier}"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = iphoneos; + SKIP_INSTALL = YES; + }; + name = Debug; + }; + AB0C24D072B5A053DA6715E8609391F1 /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 1362E4B105A1605411B72A5FC0685BEC /* Pods-LuaViewLib.debug.xcconfig */; + buildSettings = { + "CODE_SIGN_IDENTITY[sdk=appletvos*]" = ""; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; + "CODE_SIGN_IDENTITY[sdk=watchos*]" = ""; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_NO_COMMON_BLOCKS = YES; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + MACH_O_TYPE = staticlib; + MTL_ENABLE_DEBUG_INFO = YES; + OTHER_LDFLAGS = ""; + OTHER_LIBTOOLFLAGS = ""; + PODS_ROOT = "$(SRCROOT)"; + PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.${PRODUCT_NAME:rfc1034identifier}"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = iphoneos; + SKIP_INSTALL = YES; + }; + name = Debug; + }; + C104F7F091290C3D1E248192F07FE689 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CODE_SIGNING_REQUIRED = NO; + COPY_PHASE_STRIP = NO; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "POD_CONFIGURATION_DEBUG=1", + "DEBUG=1", + "$(inherited)", + ); + GCC_SYMBOLS_PRIVATE_EXTERN = NO; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + ONLY_ACTIVE_ARCH = YES; + PROVISIONING_PROFILE_SPECIFIER = NO_SIGNING/; + STRIP_INSTALLED_PRODUCT = NO; + SYMROOT = "${SRCROOT}/../build"; + }; + name = Debug; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 29D4E060B6661C2C14C5417518576F3E /* Build configuration list for PBXNativeTarget "Pods-LuaViewSDK" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 002215DD4349C411269E732A11239CCF /* Debug */, + 18AB5737FEE2345B0B915B99B1DB2375 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 2D8E8EC45A3A1A1D94AE762CB5028504 /* Build configuration list for PBXProject "Pods" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + C104F7F091290C3D1E248192F07FE689 /* Debug */, + 34FE9531DA9AF2820790339988D5FF41 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 8FD1832EAA068A2D71862F1A5A468BA4 /* Build configuration list for PBXNativeTarget "Pods-LuaViewLib" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + AB0C24D072B5A053DA6715E8609391F1 /* Debug */, + 4E9375D3D9F9193470641E8EAC529981 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + B08142893BE81AFFB2D0DBCB5773EF4C /* Build configuration list for PBXNativeTarget "Pods-Dummy" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + A72F28E9C98DD174D627EA09BC317FDE /* Debug */, + 6AD60D4A93D4F220151EDD64F9F210BD /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = D41D8CD98F00B204E9800998ECF8427E /* Project object */; +} diff --git a/IOS/SDK/Pods/Target Support Files/Pods-LuaViewSDK/Pods-LuaViewSDK-acknowledgements.markdown b/IOS/SDK/Pods/Target Support Files/Pods-LuaViewSDK/Pods-LuaViewSDK-acknowledgements.markdown new file mode 100644 index 00000000..6369d143 --- /dev/null +++ b/IOS/SDK/Pods/Target Support Files/Pods-LuaViewSDK/Pods-LuaViewSDK-acknowledgements.markdown @@ -0,0 +1,8 @@ +# Acknowledgements +This application makes use of the following third party libraries: + +## liblua + +Alibaba-INC copyright + +Generated by CocoaPods - https://cocoapods.org diff --git a/IOS/SDK/Pods/Target Support Files/Pods-LuaViewSDK/Pods-LuaViewSDK-acknowledgements.plist b/IOS/SDK/Pods/Target Support Files/Pods-LuaViewSDK/Pods-LuaViewSDK-acknowledgements.plist new file mode 100644 index 00000000..795b9a6d --- /dev/null +++ b/IOS/SDK/Pods/Target Support Files/Pods-LuaViewSDK/Pods-LuaViewSDK-acknowledgements.plist @@ -0,0 +1,40 @@ + + + + + PreferenceSpecifiers + + + FooterText + This application makes use of the following third party libraries: + Title + Acknowledgements + Type + PSGroupSpecifier + + + FooterText + Alibaba-INC copyright + + License + Copyright + Title + liblua + Type + PSGroupSpecifier + + + FooterText + Generated by CocoaPods - https://cocoapods.org + Title + + Type + PSGroupSpecifier + + + StringsTable + Acknowledgements + Title + Acknowledgements + + diff --git a/IOS/SDK/Pods/Target Support Files/Pods-LuaViewSDK/Pods-LuaViewSDK-dummy.m b/IOS/SDK/Pods/Target Support Files/Pods-LuaViewSDK/Pods-LuaViewSDK-dummy.m new file mode 100644 index 00000000..c5973cee --- /dev/null +++ b/IOS/SDK/Pods/Target Support Files/Pods-LuaViewSDK/Pods-LuaViewSDK-dummy.m @@ -0,0 +1,5 @@ +#import +@interface PodsDummy_Pods_LuaViewSDK : NSObject +@end +@implementation PodsDummy_Pods_LuaViewSDK +@end diff --git a/IOS/SDK/Pods/Target Support Files/Pods-LuaViewSDK/Pods-LuaViewSDK-frameworks.sh b/IOS/SDK/Pods/Target Support Files/Pods-LuaViewSDK/Pods-LuaViewSDK-frameworks.sh new file mode 100755 index 00000000..0f29f13c --- /dev/null +++ b/IOS/SDK/Pods/Target Support Files/Pods-LuaViewSDK/Pods-LuaViewSDK-frameworks.sh @@ -0,0 +1,92 @@ +#!/bin/sh +set -e + +echo "mkdir -p ${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" +mkdir -p "${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" + +SWIFT_STDLIB_PATH="${DT_TOOLCHAIN_DIR}/usr/lib/swift/${PLATFORM_NAME}" + +install_framework() +{ + if [ -r "${BUILT_PRODUCTS_DIR}/$1" ]; then + local source="${BUILT_PRODUCTS_DIR}/$1" + elif [ -r "${BUILT_PRODUCTS_DIR}/$(basename "$1")" ]; then + local source="${BUILT_PRODUCTS_DIR}/$(basename "$1")" + elif [ -r "$1" ]; then + local source="$1" + fi + + local destination="${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" + + if [ -L "${source}" ]; then + echo "Symlinked..." + source="$(readlink "${source}")" + fi + + # use filter instead of exclude so missing patterns dont' throw errors + echo "rsync -av --filter \"- CVS/\" --filter \"- .svn/\" --filter \"- .git/\" --filter \"- .hg/\" --filter \"- Headers\" --filter \"- PrivateHeaders\" --filter \"- Modules\" \"${source}\" \"${destination}\"" + rsync -av --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "${source}" "${destination}" + + local basename + basename="$(basename -s .framework "$1")" + binary="${destination}/${basename}.framework/${basename}" + if ! [ -r "$binary" ]; then + binary="${destination}/${basename}" + fi + + # Strip invalid architectures so "fat" simulator / device frameworks work on device + if [[ "$(file "$binary")" == *"dynamically linked shared library"* ]]; then + strip_invalid_archs "$binary" + fi + + # Resign the code if required by the build settings to avoid unstable apps + code_sign_if_enabled "${destination}/$(basename "$1")" + + # Embed linked Swift runtime libraries. No longer necessary as of Xcode 7. + if [ "${XCODE_VERSION_MAJOR}" -lt 7 ]; then + local swift_runtime_libs + swift_runtime_libs=$(xcrun otool -LX "$binary" | grep --color=never @rpath/libswift | sed -E s/@rpath\\/\(.+dylib\).*/\\1/g | uniq -u && exit ${PIPESTATUS[0]}) + for lib in $swift_runtime_libs; do + echo "rsync -auv \"${SWIFT_STDLIB_PATH}/${lib}\" \"${destination}\"" + rsync -auv "${SWIFT_STDLIB_PATH}/${lib}" "${destination}" + code_sign_if_enabled "${destination}/${lib}" + done + fi +} + +# Signs a framework with the provided identity +code_sign_if_enabled() { + if [ -n "${EXPANDED_CODE_SIGN_IDENTITY}" -a "${CODE_SIGNING_REQUIRED}" != "NO" -a "${CODE_SIGNING_ALLOWED}" != "NO" ]; then + # Use the current code_sign_identitiy + echo "Code Signing $1 with Identity ${EXPANDED_CODE_SIGN_IDENTITY_NAME}" + local code_sign_cmd="/usr/bin/codesign --force --sign ${EXPANDED_CODE_SIGN_IDENTITY} ${OTHER_CODE_SIGN_FLAGS} --preserve-metadata=identifier,entitlements '$1'" + + if [ "${COCOAPODS_PARALLEL_CODE_SIGN}" == "true" ]; then + code_sign_cmd="$code_sign_cmd &" + fi + echo "$code_sign_cmd" + eval "$code_sign_cmd" + fi +} + +# Strip invalid architectures +strip_invalid_archs() { + binary="$1" + # Get architectures for current file + archs="$(lipo -info "$binary" | rev | cut -d ':' -f1 | rev)" + stripped="" + for arch in $archs; do + if ! [[ "${VALID_ARCHS}" == *"$arch"* ]]; then + # Strip non-valid architectures in-place + lipo -remove "$arch" -output "$binary" "$binary" || exit 1 + stripped="$stripped $arch" + fi + done + if [[ "$stripped" ]]; then + echo "Stripped $binary of architectures:$stripped" + fi +} + +if [ "${COCOAPODS_PARALLEL_CODE_SIGN}" == "true" ]; then + wait +fi diff --git a/IOS/SDK/Pods/Target Support Files/Pods-LuaViewSDK/Pods-LuaViewSDK-resources.sh b/IOS/SDK/Pods/Target Support Files/Pods-LuaViewSDK/Pods-LuaViewSDK-resources.sh new file mode 100755 index 00000000..4602c68a --- /dev/null +++ b/IOS/SDK/Pods/Target Support Files/Pods-LuaViewSDK/Pods-LuaViewSDK-resources.sh @@ -0,0 +1,99 @@ +#!/bin/sh +set -e + +mkdir -p "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" + +RESOURCES_TO_COPY=${PODS_ROOT}/resources-to-copy-${TARGETNAME}.txt +> "$RESOURCES_TO_COPY" + +XCASSET_FILES=() + +case "${TARGETED_DEVICE_FAMILY}" in + 1,2) + TARGET_DEVICE_ARGS="--target-device ipad --target-device iphone" + ;; + 1) + TARGET_DEVICE_ARGS="--target-device iphone" + ;; + 2) + TARGET_DEVICE_ARGS="--target-device ipad" + ;; + 3) + TARGET_DEVICE_ARGS="--target-device tv" + ;; + *) + TARGET_DEVICE_ARGS="--target-device mac" + ;; +esac + +install_resource() +{ + if [[ "$1" = /* ]] ; then + RESOURCE_PATH="$1" + else + RESOURCE_PATH="${PODS_ROOT}/$1" + fi + if [[ ! -e "$RESOURCE_PATH" ]] ; then + cat << EOM +error: Resource "$RESOURCE_PATH" not found. Run 'pod install' to update the copy resources script. +EOM + exit 1 + fi + case $RESOURCE_PATH in + *.storyboard) + echo "ibtool --reference-external-strings-file --errors --warnings --notices --minimum-deployment-target ${!DEPLOYMENT_TARGET_SETTING_NAME} --output-format human-readable-text --compile ${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \"$RESOURCE_PATH\" .storyboard`.storyboardc $RESOURCE_PATH --sdk ${SDKROOT} ${TARGET_DEVICE_ARGS}" + ibtool --reference-external-strings-file --errors --warnings --notices --minimum-deployment-target ${!DEPLOYMENT_TARGET_SETTING_NAME} --output-format human-readable-text --compile "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \"$RESOURCE_PATH\" .storyboard`.storyboardc" "$RESOURCE_PATH" --sdk "${SDKROOT}" ${TARGET_DEVICE_ARGS} + ;; + *.xib) + echo "ibtool --reference-external-strings-file --errors --warnings --notices --minimum-deployment-target ${!DEPLOYMENT_TARGET_SETTING_NAME} --output-format human-readable-text --compile ${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \"$RESOURCE_PATH\" .xib`.nib $RESOURCE_PATH --sdk ${SDKROOT} ${TARGET_DEVICE_ARGS}" + ibtool --reference-external-strings-file --errors --warnings --notices --minimum-deployment-target ${!DEPLOYMENT_TARGET_SETTING_NAME} --output-format human-readable-text --compile "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \"$RESOURCE_PATH\" .xib`.nib" "$RESOURCE_PATH" --sdk "${SDKROOT}" ${TARGET_DEVICE_ARGS} + ;; + *.framework) + echo "mkdir -p ${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" + mkdir -p "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" + echo "rsync -av $RESOURCE_PATH ${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" + rsync -av "$RESOURCE_PATH" "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" + ;; + *.xcdatamodel) + echo "xcrun momc \"$RESOURCE_PATH\" \"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$RESOURCE_PATH"`.mom\"" + xcrun momc "$RESOURCE_PATH" "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$RESOURCE_PATH" .xcdatamodel`.mom" + ;; + *.xcdatamodeld) + echo "xcrun momc \"$RESOURCE_PATH\" \"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$RESOURCE_PATH" .xcdatamodeld`.momd\"" + xcrun momc "$RESOURCE_PATH" "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$RESOURCE_PATH" .xcdatamodeld`.momd" + ;; + *.xcmappingmodel) + echo "xcrun mapc \"$RESOURCE_PATH\" \"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$RESOURCE_PATH" .xcmappingmodel`.cdm\"" + xcrun mapc "$RESOURCE_PATH" "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$RESOURCE_PATH" .xcmappingmodel`.cdm" + ;; + *.xcassets) + ABSOLUTE_XCASSET_FILE="$RESOURCE_PATH" + XCASSET_FILES+=("$ABSOLUTE_XCASSET_FILE") + ;; + *) + echo "$RESOURCE_PATH" + echo "$RESOURCE_PATH" >> "$RESOURCES_TO_COPY" + ;; + esac +} + +mkdir -p "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" +rsync -avr --copy-links --no-relative --exclude '*/.svn/*' --files-from="$RESOURCES_TO_COPY" / "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" +if [[ "${ACTION}" == "install" ]] && [[ "${SKIP_INSTALL}" == "NO" ]]; then + mkdir -p "${INSTALL_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" + rsync -avr --copy-links --no-relative --exclude '*/.svn/*' --files-from="$RESOURCES_TO_COPY" / "${INSTALL_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" +fi +rm -f "$RESOURCES_TO_COPY" + +if [[ -n "${WRAPPER_EXTENSION}" ]] && [ "`xcrun --find actool`" ] && [ -n "$XCASSET_FILES" ] +then + # Find all other xcassets (this unfortunately includes those of path pods and other targets). + OTHER_XCASSETS=$(find "$PWD" -iname "*.xcassets" -type d) + while read line; do + if [[ $line != "${PODS_ROOT}*" ]]; then + XCASSET_FILES+=("$line") + fi + done <<<"$OTHER_XCASSETS" + + printf "%s\0" "${XCASSET_FILES[@]}" | xargs -0 xcrun actool --output-format human-readable-text --notices --warnings --platform "${PLATFORM_NAME}" --minimum-deployment-target "${!DEPLOYMENT_TARGET_SETTING_NAME}" ${TARGET_DEVICE_ARGS} --compress-pngs --compile "${BUILT_PRODUCTS_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" +fi diff --git a/IOS/SDK/Pods/Target Support Files/Pods-LuaViewSDK/Pods-LuaViewSDK.debug.xcconfig b/IOS/SDK/Pods/Target Support Files/Pods-LuaViewSDK/Pods-LuaViewSDK.debug.xcconfig new file mode 100644 index 00000000..a10b0e8b --- /dev/null +++ b/IOS/SDK/Pods/Target Support Files/Pods-LuaViewSDK/Pods-LuaViewSDK.debug.xcconfig @@ -0,0 +1,8 @@ +GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 +HEADER_SEARCH_PATHS = $(inherited) "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/liblua" +LIBRARY_SEARCH_PATHS = $(inherited) "${PODS_ROOT}/liblua/lib" +OTHER_CFLAGS = $(inherited) -isystem "${PODS_ROOT}/Headers/Public" -isystem "${PODS_ROOT}/Headers/Public/liblua" +OTHER_LDFLAGS = $(inherited) -ObjC -l"lua" +PODS_BUILD_DIR = $BUILD_DIR +PODS_CONFIGURATION_BUILD_DIR = $PODS_BUILD_DIR/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) +PODS_ROOT = ${SRCROOT}/Pods diff --git a/IOS/SDK/Pods/Target Support Files/Pods-LuaViewSDK/Pods-LuaViewSDK.release.xcconfig b/IOS/SDK/Pods/Target Support Files/Pods-LuaViewSDK/Pods-LuaViewSDK.release.xcconfig new file mode 100644 index 00000000..a10b0e8b --- /dev/null +++ b/IOS/SDK/Pods/Target Support Files/Pods-LuaViewSDK/Pods-LuaViewSDK.release.xcconfig @@ -0,0 +1,8 @@ +GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 +HEADER_SEARCH_PATHS = $(inherited) "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/liblua" +LIBRARY_SEARCH_PATHS = $(inherited) "${PODS_ROOT}/liblua/lib" +OTHER_CFLAGS = $(inherited) -isystem "${PODS_ROOT}/Headers/Public" -isystem "${PODS_ROOT}/Headers/Public/liblua" +OTHER_LDFLAGS = $(inherited) -ObjC -l"lua" +PODS_BUILD_DIR = $BUILD_DIR +PODS_CONFIGURATION_BUILD_DIR = $PODS_BUILD_DIR/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) +PODS_ROOT = ${SRCROOT}/Pods diff --git a/IOS/SDK/Pods/Target Support Files/Pods-LuaViewSDK/copy-framework-resources.rb b/IOS/SDK/Pods/Target Support Files/Pods-LuaViewSDK/copy-framework-resources.rb new file mode 100755 index 00000000..b448f657 --- /dev/null +++ b/IOS/SDK/Pods/Target Support Files/Pods-LuaViewSDK/copy-framework-resources.rb @@ -0,0 +1,63 @@ +#!/usr/bin/env ruby +# encoding: UTF-8 + +require 'Xcodeproj' +require 'fileutils' + +Encoding.default_external = Encoding::UTF_8 +Encoding.default_internal = Encoding::UTF_8 + +current_target_name = ENV["TARGET_NAME"] +project = Xcodeproj::Project.open(ENV["PROJECT_FILE_PATH"]) + +# 分析环境变量参数 +def parse_args(args) + index = 0 + arg_list = [] + while args && args.length > 0 && args.length > index + space_index = args.index(" ", index) + space_index = -1 if space_index.nil? + arg = args[0..space_index] + if arg.count("\"") % 2 == 0 && arg.count("'") % 2 == 0 + arg_list << arg.strip + args = space_index >= 0 ? args[space_index+1..-1] : nil + index = 0 + end + end + arg_list +end + +def find_key(array, key) + for dic in array + if dic.keys[0] == key + return dic[key] + end + end +end + +current_target = project.targets.find { |target| target.name == current_target_name } + +frameworks = current_target.frameworks_build_phases.files.map{|file| file.file_ref.nil? ? "" : File.basename(file.file_ref.path) }.select { |x| File.extname(x) == ".framework"} + +FRAMEWORK_SEARCH_PATHS = [] +parse_args(ENV['FRAMEWORK_SEARCH_PATHS']).each { |arg| FRAMEWORK_SEARCH_PATHS << arg.gsub("\"", "") } + +for framework in frameworks + FRAMEWORK_SEARCH_PATHS.each do |path| + framework_path = File.join(path, framework) + if File.directory?(framework_path) + ignore_list = ["Info.plist", ".DS_Store"] + if File.directory?(File.join(framework_path, "Resources")) + list = Dir.glob(File.join(framework_path, "Resources/*")) + else + #增加Resources的过滤,之前喵街引入的一库,存在Resources,但是指向的目录不存在。导致cp一个空的符号链接会报错 by兵长 20170706 + ignore_list += [File.basename(framework, '.framework'), "Headers", "PrivateHeaders", "Modules", "Versions", "_CodeSignature", "Resources"] + list = Dir.glob(File.join(framework_path, "*")) + end + list.reject!{|entry| ignore_list.include?(File.basename(entry)) } + list.each { |file| puts file} + FileUtils.cp_r list, File.join(ENV["TARGET_BUILD_DIR"], ENV["UNLOCALIZED_RESOURCES_FOLDER_PATH"]) + break + end + end +end diff --git a/IOS/SDK/TaobaoEnv b/IOS/SDK/TaobaoEnv new file mode 100644 index 00000000..26aaba0e --- /dev/null +++ b/IOS/SDK/TaobaoEnv @@ -0,0 +1 @@ +1.2.0 diff --git a/IOS/lua/DerivedData/ModuleCache/372F5EJFCGB7L/Darwin-38I6DLZ5IH61J.pcm b/IOS/lua/DerivedData/ModuleCache/372F5EJFCGB7L/Darwin-38I6DLZ5IH61J.pcm new file mode 100644 index 00000000..2d92f4bb Binary files /dev/null and b/IOS/lua/DerivedData/ModuleCache/372F5EJFCGB7L/Darwin-38I6DLZ5IH61J.pcm differ diff --git a/IOS/lua/DerivedData/ModuleCache/372F5EJFCGB7L/Darwin-38I6DLZ5IH61J.pcm.timestamp b/IOS/lua/DerivedData/ModuleCache/372F5EJFCGB7L/Darwin-38I6DLZ5IH61J.pcm.timestamp new file mode 100644 index 00000000..211c37ba --- /dev/null +++ b/IOS/lua/DerivedData/ModuleCache/372F5EJFCGB7L/Darwin-38I6DLZ5IH61J.pcm.timestamp @@ -0,0 +1 @@ +Timestamp file diff --git a/IOS/lua/DerivedData/ModuleCache/372F5EJFCGB7L/modules.idx b/IOS/lua/DerivedData/ModuleCache/372F5EJFCGB7L/modules.idx new file mode 100644 index 00000000..3f32ef49 Binary files /dev/null and b/IOS/lua/DerivedData/ModuleCache/372F5EJFCGB7L/modules.idx differ diff --git a/IOS/lua/DerivedData/ModuleCache/Session.modulevalidation b/IOS/lua/DerivedData/ModuleCache/Session.modulevalidation new file mode 100644 index 00000000..981057a7 --- /dev/null +++ b/IOS/lua/DerivedData/ModuleCache/Session.modulevalidation @@ -0,0 +1 @@ +Module build session file for module cache at /Users/oolongtea/Documents/work/LuaViewSDK/IOS/lua/DerivedData/ModuleCache diff --git a/IOS/lua/DerivedData/ModuleCache/modules.timestamp b/IOS/lua/DerivedData/ModuleCache/modules.timestamp new file mode 100644 index 00000000..e69de29b diff --git a/IOS/lua/DerivedData/lua/Build/Intermediates/lua.build/Debug-iphonesimulator/lua.build/Objects-normal/x86_64/lua.LinkFileList b/IOS/lua/DerivedData/lua/Build/Intermediates/lua.build/Debug-iphonesimulator/lua.build/Objects-normal/x86_64/lua.LinkFileList new file mode 100644 index 00000000..09b3c8b2 --- /dev/null +++ b/IOS/lua/DerivedData/lua/Build/Intermediates/lua.build/Debug-iphonesimulator/lua.build/Objects-normal/x86_64/lua.LinkFileList @@ -0,0 +1,32 @@ +/Users/oolongtea/Documents/work/LuaViewSDK/IOS/lua/DerivedData/lua/Build/Intermediates/lua.build/Debug-iphonesimulator/lua.build/Objects-normal/x86_64/lmem.o +/Users/oolongtea/Documents/work/LuaViewSDK/IOS/lua/DerivedData/lua/Build/Intermediates/lua.build/Debug-iphonesimulator/lua.build/Objects-normal/x86_64/lgc.o +/Users/oolongtea/Documents/work/LuaViewSDK/IOS/lua/DerivedData/lua/Build/Intermediates/lua.build/Debug-iphonesimulator/lua.build/Objects-normal/x86_64/lmathlib.o +/Users/oolongtea/Documents/work/LuaViewSDK/IOS/lua/DerivedData/lua/Build/Intermediates/lua.build/Debug-iphonesimulator/lua.build/Objects-normal/x86_64/lfunc.o +/Users/oolongtea/Documents/work/LuaViewSDK/IOS/lua/DerivedData/lua/Build/Intermediates/lua.build/Debug-iphonesimulator/lua.build/Objects-normal/x86_64/lua.o +/Users/oolongtea/Documents/work/LuaViewSDK/IOS/lua/DerivedData/lua/Build/Intermediates/lua.build/Debug-iphonesimulator/lua.build/Objects-normal/x86_64/print.o +/Users/oolongtea/Documents/work/LuaViewSDK/IOS/lua/DerivedData/lua/Build/Intermediates/lua.build/Debug-iphonesimulator/lua.build/Objects-normal/x86_64/lstate.o +/Users/oolongtea/Documents/work/LuaViewSDK/IOS/lua/DerivedData/lua/Build/Intermediates/lua.build/Debug-iphonesimulator/lua.build/Objects-normal/x86_64/ldump.o +/Users/oolongtea/Documents/work/LuaViewSDK/IOS/lua/DerivedData/lua/Build/Intermediates/lua.build/Debug-iphonesimulator/lua.build/Objects-normal/x86_64/liolib.o +/Users/oolongtea/Documents/work/LuaViewSDK/IOS/lua/DerivedData/lua/Build/Intermediates/lua.build/Debug-iphonesimulator/lua.build/Objects-normal/x86_64/lzio.o +/Users/oolongtea/Documents/work/LuaViewSDK/IOS/lua/DerivedData/lua/Build/Intermediates/lua.build/Debug-iphonesimulator/lua.build/Objects-normal/x86_64/lstring.o +/Users/oolongtea/Documents/work/LuaViewSDK/IOS/lua/DerivedData/lua/Build/Intermediates/lua.build/Debug-iphonesimulator/lua.build/Objects-normal/x86_64/ltm.o +/Users/oolongtea/Documents/work/LuaViewSDK/IOS/lua/DerivedData/lua/Build/Intermediates/lua.build/Debug-iphonesimulator/lua.build/Objects-normal/x86_64/ltable.o +/Users/oolongtea/Documents/work/LuaViewSDK/IOS/lua/DerivedData/lua/Build/Intermediates/lua.build/Debug-iphonesimulator/lua.build/Objects-normal/x86_64/ldo.o +/Users/oolongtea/Documents/work/LuaViewSDK/IOS/lua/DerivedData/lua/Build/Intermediates/lua.build/Debug-iphonesimulator/lua.build/Objects-normal/x86_64/lparser.o +/Users/oolongtea/Documents/work/LuaViewSDK/IOS/lua/DerivedData/lua/Build/Intermediates/lua.build/Debug-iphonesimulator/lua.build/Objects-normal/x86_64/lvm.o +/Users/oolongtea/Documents/work/LuaViewSDK/IOS/lua/DerivedData/lua/Build/Intermediates/lua.build/Debug-iphonesimulator/lua.build/Objects-normal/x86_64/lopcodes.o +/Users/oolongtea/Documents/work/LuaViewSDK/IOS/lua/DerivedData/lua/Build/Intermediates/lua.build/Debug-iphonesimulator/lua.build/Objects-normal/x86_64/lobject.o +/Users/oolongtea/Documents/work/LuaViewSDK/IOS/lua/DerivedData/lua/Build/Intermediates/lua.build/Debug-iphonesimulator/lua.build/Objects-normal/x86_64/linit.o +/Users/oolongtea/Documents/work/LuaViewSDK/IOS/lua/DerivedData/lua/Build/Intermediates/lua.build/Debug-iphonesimulator/lua.build/Objects-normal/x86_64/llex.o +/Users/oolongtea/Documents/work/LuaViewSDK/IOS/lua/DerivedData/lua/Build/Intermediates/lua.build/Debug-iphonesimulator/lua.build/Objects-normal/x86_64/lbaselib.o +/Users/oolongtea/Documents/work/LuaViewSDK/IOS/lua/DerivedData/lua/Build/Intermediates/lua.build/Debug-iphonesimulator/lua.build/Objects-normal/x86_64/loslib.o +/Users/oolongtea/Documents/work/LuaViewSDK/IOS/lua/DerivedData/lua/Build/Intermediates/lua.build/Debug-iphonesimulator/lua.build/Objects-normal/x86_64/lauxlib.o +/Users/oolongtea/Documents/work/LuaViewSDK/IOS/lua/DerivedData/lua/Build/Intermediates/lua.build/Debug-iphonesimulator/lua.build/Objects-normal/x86_64/lundump.o +/Users/oolongtea/Documents/work/LuaViewSDK/IOS/lua/DerivedData/lua/Build/Intermediates/lua.build/Debug-iphonesimulator/lua.build/Objects-normal/x86_64/ldblib.o +/Users/oolongtea/Documents/work/LuaViewSDK/IOS/lua/DerivedData/lua/Build/Intermediates/lua.build/Debug-iphonesimulator/lua.build/Objects-normal/x86_64/lcode.o +/Users/oolongtea/Documents/work/LuaViewSDK/IOS/lua/DerivedData/lua/Build/Intermediates/lua.build/Debug-iphonesimulator/lua.build/Objects-normal/x86_64/ldebug.o +/Users/oolongtea/Documents/work/LuaViewSDK/IOS/lua/DerivedData/lua/Build/Intermediates/lua.build/Debug-iphonesimulator/lua.build/Objects-normal/x86_64/lapi.o +/Users/oolongtea/Documents/work/LuaViewSDK/IOS/lua/DerivedData/lua/Build/Intermediates/lua.build/Debug-iphonesimulator/lua.build/Objects-normal/x86_64/lstrlib.o +/Users/oolongtea/Documents/work/LuaViewSDK/IOS/lua/DerivedData/lua/Build/Intermediates/lua.build/Debug-iphonesimulator/lua.build/Objects-normal/x86_64/loadlib.o +/Users/oolongtea/Documents/work/LuaViewSDK/IOS/lua/DerivedData/lua/Build/Intermediates/lua.build/Debug-iphonesimulator/lua.build/Objects-normal/x86_64/ltablib.o +/Users/oolongtea/Documents/work/LuaViewSDK/IOS/lua/DerivedData/lua/Build/Intermediates/lua.build/Debug-iphonesimulator/lua.build/Objects-normal/x86_64/luac.o diff --git a/IOS/lua/DerivedData/lua/Build/Intermediates/lua.build/Debug-iphonesimulator/lua.build/dgph b/IOS/lua/DerivedData/lua/Build/Intermediates/lua.build/Debug-iphonesimulator/lua.build/dgph new file mode 100644 index 00000000..564bacc2 Binary files /dev/null and b/IOS/lua/DerivedData/lua/Build/Intermediates/lua.build/Debug-iphonesimulator/lua.build/dgph differ diff --git a/IOS/lua/DerivedData/lua/Build/Intermediates/lua.build/Debug-iphonesimulator/lua.build/lua-all-non-framework-target-headers.hmap b/IOS/lua/DerivedData/lua/Build/Intermediates/lua.build/Debug-iphonesimulator/lua.build/lua-all-non-framework-target-headers.hmap new file mode 100644 index 00000000..dc511c47 Binary files /dev/null and b/IOS/lua/DerivedData/lua/Build/Intermediates/lua.build/Debug-iphonesimulator/lua.build/lua-all-non-framework-target-headers.hmap differ diff --git a/IOS/lua/DerivedData/lua/Build/Intermediates/lua.build/Debug-iphonesimulator/lua.build/lua-all-target-headers.hmap b/IOS/lua/DerivedData/lua/Build/Intermediates/lua.build/Debug-iphonesimulator/lua.build/lua-all-target-headers.hmap new file mode 100644 index 00000000..dc511c47 Binary files /dev/null and b/IOS/lua/DerivedData/lua/Build/Intermediates/lua.build/Debug-iphonesimulator/lua.build/lua-all-target-headers.hmap differ diff --git a/IOS/lua/DerivedData/lua/Build/Intermediates/lua.build/Debug-iphonesimulator/lua.build/lua-generated-files.hmap b/IOS/lua/DerivedData/lua/Build/Intermediates/lua.build/Debug-iphonesimulator/lua.build/lua-generated-files.hmap new file mode 100644 index 00000000..dd8b535d Binary files /dev/null and b/IOS/lua/DerivedData/lua/Build/Intermediates/lua.build/Debug-iphonesimulator/lua.build/lua-generated-files.hmap differ diff --git a/IOS/lua/DerivedData/lua/Build/Intermediates/lua.build/Debug-iphonesimulator/lua.build/lua-own-target-headers.hmap b/IOS/lua/DerivedData/lua/Build/Intermediates/lua.build/Debug-iphonesimulator/lua.build/lua-own-target-headers.hmap new file mode 100644 index 00000000..dc511c47 Binary files /dev/null and b/IOS/lua/DerivedData/lua/Build/Intermediates/lua.build/Debug-iphonesimulator/lua.build/lua-own-target-headers.hmap differ diff --git a/IOS/lua/DerivedData/lua/Build/Intermediates/lua.build/Debug-iphonesimulator/lua.build/lua-project-headers.hmap b/IOS/lua/DerivedData/lua/Build/Intermediates/lua.build/Debug-iphonesimulator/lua.build/lua-project-headers.hmap new file mode 100644 index 00000000..20c4817b Binary files /dev/null and b/IOS/lua/DerivedData/lua/Build/Intermediates/lua.build/Debug-iphonesimulator/lua.build/lua-project-headers.hmap differ diff --git a/IOS/lua/DerivedData/lua/Build/Intermediates/lua.build/Debug-iphonesimulator/lua.build/lua.hmap b/IOS/lua/DerivedData/lua/Build/Intermediates/lua.build/Debug-iphonesimulator/lua.build/lua.hmap new file mode 100644 index 00000000..7e8d4712 Binary files /dev/null and b/IOS/lua/DerivedData/lua/Build/Intermediates/lua.build/Debug-iphonesimulator/lua.build/lua.hmap differ diff --git a/IOS/lua/DerivedData/lua/Index/Debug/iphonesimulator10.2-x86_64/lua.xcindex/db.xcindexdb b/IOS/lua/DerivedData/lua/Index/Debug/iphonesimulator10.2-x86_64/lua.xcindex/db.xcindexdb new file mode 100644 index 00000000..4c05a191 Binary files /dev/null and b/IOS/lua/DerivedData/lua/Index/Debug/iphonesimulator10.2-x86_64/lua.xcindex/db.xcindexdb differ diff --git a/IOS/lua/DerivedData/lua/Index/Debug/iphonesimulator10.2-x86_64/lua.xcindex/db.xcindexdb-shm b/IOS/lua/DerivedData/lua/Index/Debug/iphonesimulator10.2-x86_64/lua.xcindex/db.xcindexdb-shm new file mode 100644 index 00000000..b6db706a Binary files /dev/null and b/IOS/lua/DerivedData/lua/Index/Debug/iphonesimulator10.2-x86_64/lua.xcindex/db.xcindexdb-shm differ diff --git a/IOS/lua/DerivedData/lua/Index/Debug/iphonesimulator10.2-x86_64/lua.xcindex/db.xcindexdb-wal b/IOS/lua/DerivedData/lua/Index/Debug/iphonesimulator10.2-x86_64/lua.xcindex/db.xcindexdb-wal new file mode 100644 index 00000000..e69de29b diff --git a/IOS/lua/DerivedData/lua/Index/Debug/iphonesimulator10.2-x86_64/lua.xcindex/db.xcindexdb.strings-cmp b/IOS/lua/DerivedData/lua/Index/Debug/iphonesimulator10.2-x86_64/lua.xcindex/db.xcindexdb.strings-cmp new file mode 100644 index 00000000..f76dd238 Binary files /dev/null and b/IOS/lua/DerivedData/lua/Index/Debug/iphonesimulator10.2-x86_64/lua.xcindex/db.xcindexdb.strings-cmp differ diff --git a/IOS/lua/DerivedData/lua/Index/Debug/iphonesimulator10.2-x86_64/lua.xcindex/db.xcindexdb.strings-dir b/IOS/lua/DerivedData/lua/Index/Debug/iphonesimulator10.2-x86_64/lua.xcindex/db.xcindexdb.strings-dir new file mode 100644 index 00000000..1ecd05a4 Binary files /dev/null and b/IOS/lua/DerivedData/lua/Index/Debug/iphonesimulator10.2-x86_64/lua.xcindex/db.xcindexdb.strings-dir differ diff --git a/IOS/lua/DerivedData/lua/Index/Debug/iphonesimulator10.2-x86_64/lua.xcindex/db.xcindexdb.strings-file b/IOS/lua/DerivedData/lua/Index/Debug/iphonesimulator10.2-x86_64/lua.xcindex/db.xcindexdb.strings-file new file mode 100644 index 00000000..a79f4649 Binary files /dev/null and b/IOS/lua/DerivedData/lua/Index/Debug/iphonesimulator10.2-x86_64/lua.xcindex/db.xcindexdb.strings-file differ diff --git a/IOS/lua/DerivedData/lua/Index/Debug/iphonesimulator10.2-x86_64/lua.xcindex/db.xcindexdb.strings-moduleurl b/IOS/lua/DerivedData/lua/Index/Debug/iphonesimulator10.2-x86_64/lua.xcindex/db.xcindexdb.strings-moduleurl new file mode 100644 index 00000000..080f46a4 Binary files /dev/null and b/IOS/lua/DerivedData/lua/Index/Debug/iphonesimulator10.2-x86_64/lua.xcindex/db.xcindexdb.strings-moduleurl differ diff --git a/IOS/lua/DerivedData/lua/Index/Debug/iphonesimulator10.2-x86_64/lua.xcindex/db.xcindexdb.strings-res b/IOS/lua/DerivedData/lua/Index/Debug/iphonesimulator10.2-x86_64/lua.xcindex/db.xcindexdb.strings-res new file mode 100644 index 00000000..dee8f8aa Binary files /dev/null and b/IOS/lua/DerivedData/lua/Index/Debug/iphonesimulator10.2-x86_64/lua.xcindex/db.xcindexdb.strings-res differ diff --git a/IOS/lua/DerivedData/lua/Index/Debug/iphonesimulator10.2-x86_64/lua.xcindex/db.xcindexdb.strings-sym b/IOS/lua/DerivedData/lua/Index/Debug/iphonesimulator10.2-x86_64/lua.xcindex/db.xcindexdb.strings-sym new file mode 100644 index 00000000..d1bc7e99 Binary files /dev/null and b/IOS/lua/DerivedData/lua/Index/Debug/iphonesimulator10.2-x86_64/lua.xcindex/db.xcindexdb.strings-sym differ diff --git a/IOS/lua/DerivedData/lua/Index/Debug/macosx10.12-x86_64h/lua.xcindex/db.xcindexdb b/IOS/lua/DerivedData/lua/Index/Debug/macosx10.12-x86_64h/lua.xcindex/db.xcindexdb new file mode 100644 index 00000000..0a6f94df Binary files /dev/null and b/IOS/lua/DerivedData/lua/Index/Debug/macosx10.12-x86_64h/lua.xcindex/db.xcindexdb differ diff --git a/IOS/lua/DerivedData/lua/Index/Debug/macosx10.12-x86_64h/lua.xcindex/db.xcindexdb-shm b/IOS/lua/DerivedData/lua/Index/Debug/macosx10.12-x86_64h/lua.xcindex/db.xcindexdb-shm new file mode 100644 index 00000000..4db2825d Binary files /dev/null and b/IOS/lua/DerivedData/lua/Index/Debug/macosx10.12-x86_64h/lua.xcindex/db.xcindexdb-shm differ diff --git a/IOS/lua/DerivedData/lua/Index/Debug/macosx10.12-x86_64h/lua.xcindex/db.xcindexdb-wal b/IOS/lua/DerivedData/lua/Index/Debug/macosx10.12-x86_64h/lua.xcindex/db.xcindexdb-wal new file mode 100644 index 00000000..e69de29b diff --git a/IOS/lua/DerivedData/lua/info.plist b/IOS/lua/DerivedData/lua/info.plist new file mode 100644 index 00000000..d2a50692 --- /dev/null +++ b/IOS/lua/DerivedData/lua/info.plist @@ -0,0 +1,10 @@ + + + + + LastAccessedDate + 2017-04-06T03:41:28Z + WorkspacePath + /Users/oolongtea/Documents/work/LuaViewSDK/IOS/lua/lua.xcodeproj + + diff --git a/IOS/lua/DerivedData/lua/scm.plist b/IOS/lua/DerivedData/lua/scm.plist new file mode 100644 index 00000000..97048d1e --- /dev/null +++ b/IOS/lua/DerivedData/lua/scm.plist @@ -0,0 +1,8 @@ + + + + + Version + 5 + + diff --git a/IOS/lua/lua.podspec b/IOS/lua/lua.podspec new file mode 100644 index 00000000..37b8e071 --- /dev/null +++ b/IOS/lua/lua.podspec @@ -0,0 +1,65 @@ + +Pod::Spec.new do |s| + + s.name = "lua" + s.version = "5.1.4" + s.summary = "lua" + + s.description = <<-DESC + A longer description of lua.podspec in Markdown format. + * LuaView + DESC + + s.homepage = "http://gitlab.alibaba-inc.com/luaview/lua" + + + s.license = { :type => 'GNU General Public Licence (GPL), Version 2.0', :file => 'LICENSE.txt' } + + s.author = { "城西" => "xicheng.dxc@alibaba-inc.com" } + + # ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― # + # + # If this Pod runs only on iOS or OS X, then specify the platform and + # the deployment target. You can optionally include the target after the platform. + # + + s.platform = :ios, "7.0" + + s.source = { :git => "git@gitlab.alibaba-inc.com:luaview/lua.git", :tag => "2.1.1.2" } + + s.source_files = "lua/**/*.{h,m,c}" + # s.exclude_files = "Classes/Exclude" + + + # ――― Resources ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # + # + # A list of resources included with the Pod. These are copied into the + # target bundle with a build phase script. Anything else will be cleaned. + # You can preserve files from being cleaned, please don't preserve + # non-essential files like tests, examples and documentation. + # + + # s.resource = "icon.png" + # s.resources = "Resources/*.png" + + # s.preserve_paths = "FilesToSave", "MoreFilesToSave" + + + # ――― Project Linking ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # + # + # Link your library with frameworks, or libraries. Libraries do not include + # the lib prefix of their name. + # + + s.frameworks = 'Foundation', 'UIKit', 'CoreGraphics' + s.libraries = 'z' + + # ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # + # + # If your library depends on compiler flags you can set them in the xcconfig hash + # where they will only apply to your library. If you depend on other Podspecs + # you can include multiple dependencies to ensure it works. + + s.requires_arc = true + +end diff --git a/IOS/lua/lua.xcodeproj/project.pbxproj b/IOS/lua/lua.xcodeproj/project.pbxproj new file mode 100644 index 00000000..58979fd8 --- /dev/null +++ b/IOS/lua/lua.xcodeproj/project.pbxproj @@ -0,0 +1,433 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + 91D465821E79775B000BA0B9 /* lua.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 91D4657F1E79775B000BA0B9 /* lua.h */; }; + 91D465BE1E7977BB000BA0B9 /* loadlib.c in Sources */ = {isa = PBXBuildFile; fileRef = 91D465891E7977BB000BA0B9 /* loadlib.c */; }; + 91D465BF1E7977BB000BA0B9 /* lstrlib.c in Sources */ = {isa = PBXBuildFile; fileRef = 91D4658A1E7977BB000BA0B9 /* lstrlib.c */; }; + 91D465C01E7977BB000BA0B9 /* lapi.c in Sources */ = {isa = PBXBuildFile; fileRef = 91D4658B1E7977BB000BA0B9 /* lapi.c */; }; + 91D465C11E7977BB000BA0B9 /* ldebug.c in Sources */ = {isa = PBXBuildFile; fileRef = 91D4658C1E7977BB000BA0B9 /* ldebug.c */; }; + 91D465C21E7977BB000BA0B9 /* lundump.c in Sources */ = {isa = PBXBuildFile; fileRef = 91D4658D1E7977BB000BA0B9 /* lundump.c */; }; + 91D465C31E7977BB000BA0B9 /* ltablib.c in Sources */ = {isa = PBXBuildFile; fileRef = 91D4658E1E7977BB000BA0B9 /* ltablib.c */; }; + 91D465C41E7977BB000BA0B9 /* lbaselib.c in Sources */ = {isa = PBXBuildFile; fileRef = 91D4658F1E7977BB000BA0B9 /* lbaselib.c */; }; + 91D465C51E7977BB000BA0B9 /* lauxlib.c in Sources */ = {isa = PBXBuildFile; fileRef = 91D465911E7977BB000BA0B9 /* lauxlib.c */; }; + 91D465C61E7977BB000BA0B9 /* ldblib.c in Sources */ = {isa = PBXBuildFile; fileRef = 91D465921E7977BB000BA0B9 /* ldblib.c */; }; + 91D465C71E7977BB000BA0B9 /* ldo.c in Sources */ = {isa = PBXBuildFile; fileRef = 91D465931E7977BB000BA0B9 /* ldo.c */; }; + 91D465C81E7977BB000BA0B9 /* liolib.c in Sources */ = {isa = PBXBuildFile; fileRef = 91D465941E7977BB000BA0B9 /* liolib.c */; }; + 91D465C91E7977BB000BA0B9 /* loslib.c in Sources */ = {isa = PBXBuildFile; fileRef = 91D465951E7977BB000BA0B9 /* loslib.c */; }; + 91D465CA1E7977BB000BA0B9 /* lstate.c in Sources */ = {isa = PBXBuildFile; fileRef = 91D465961E7977BB000BA0B9 /* lstate.c */; }; + 91D465CB1E7977BB000BA0B9 /* lcode.c in Sources */ = {isa = PBXBuildFile; fileRef = 91D465981E7977BB000BA0B9 /* lcode.c */; }; + 91D465CC1E7977BB000BA0B9 /* lparser.c in Sources */ = {isa = PBXBuildFile; fileRef = 91D465991E7977BB000BA0B9 /* lparser.c */; }; + 91D465CD1E7977BB000BA0B9 /* ltable.c in Sources */ = {isa = PBXBuildFile; fileRef = 91D4659A1E7977BB000BA0B9 /* ltable.c */; }; + 91D465CE1E7977BB000BA0B9 /* lua.c in Sources */ = {isa = PBXBuildFile; fileRef = 91D4659B1E7977BB000BA0B9 /* lua.c */; }; + 91D465CF1E7977BB000BA0B9 /* lvm.c in Sources */ = {isa = PBXBuildFile; fileRef = 91D4659C1E7977BB000BA0B9 /* lvm.c */; }; + 91D465D01E7977BB000BA0B9 /* lfunc.c in Sources */ = {isa = PBXBuildFile; fileRef = 91D4659D1E7977BB000BA0B9 /* lfunc.c */; }; + 91D465D11E7977BB000BA0B9 /* ldump.c in Sources */ = {isa = PBXBuildFile; fileRef = 91D465A31E7977BB000BA0B9 /* ldump.c */; }; + 91D465D21E7977BB000BA0B9 /* lgc.c in Sources */ = {isa = PBXBuildFile; fileRef = 91D465A51E7977BB000BA0B9 /* lgc.c */; }; + 91D465D31E7977BB000BA0B9 /* linit.c in Sources */ = {isa = PBXBuildFile; fileRef = 91D465A71E7977BB000BA0B9 /* linit.c */; }; + 91D465D41E7977BB000BA0B9 /* llex.c in Sources */ = {isa = PBXBuildFile; fileRef = 91D465A81E7977BB000BA0B9 /* llex.c */; }; + 91D465D51E7977BB000BA0B9 /* lmathlib.c in Sources */ = {isa = PBXBuildFile; fileRef = 91D465AB1E7977BB000BA0B9 /* lmathlib.c */; }; + 91D465D61E7977BB000BA0B9 /* lmem.c in Sources */ = {isa = PBXBuildFile; fileRef = 91D465AC1E7977BB000BA0B9 /* lmem.c */; }; + 91D465D71E7977BB000BA0B9 /* lobject.c in Sources */ = {isa = PBXBuildFile; fileRef = 91D465AE1E7977BB000BA0B9 /* lobject.c */; }; + 91D465D81E7977BB000BA0B9 /* lopcodes.c in Sources */ = {isa = PBXBuildFile; fileRef = 91D465AF1E7977BB000BA0B9 /* lopcodes.c */; }; + 91D465D91E7977BB000BA0B9 /* lstring.c in Sources */ = {isa = PBXBuildFile; fileRef = 91D465B21E7977BB000BA0B9 /* lstring.c */; }; + 91D465DA1E7977BB000BA0B9 /* ltm.c in Sources */ = {isa = PBXBuildFile; fileRef = 91D465B51E7977BB000BA0B9 /* ltm.c */; }; + 91D465DB1E7977BB000BA0B9 /* lzio.c in Sources */ = {isa = PBXBuildFile; fileRef = 91D465BA1E7977BB000BA0B9 /* lzio.c */; }; + 91D465DC1E7977BB000BA0B9 /* print.c in Sources */ = {isa = PBXBuildFile; fileRef = 91D465BC1E7977BB000BA0B9 /* print.c */; }; + 91D465DD1E7977BB000BA0B9 /* luac.c in Sources */ = {isa = PBXBuildFile; fileRef = 91D465BD1E7977BB000BA0B9 /* luac.c */; }; +/* End PBXBuildFile section */ + +/* Begin PBXCopyFilesBuildPhase section */ + 91D4657A1E79775B000BA0B9 /* CopyFiles */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = "include/$(PRODUCT_NAME)"; + dstSubfolderSpec = 16; + files = ( + 91D465821E79775B000BA0B9 /* lua.h in CopyFiles */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + 91D4657C1E79775B000BA0B9 /* liblua.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = liblua.a; sourceTree = BUILT_PRODUCTS_DIR; }; + 91D4657F1E79775B000BA0B9 /* lua.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = lua.h; sourceTree = ""; }; + 91D465881E7977BB000BA0B9 /* lobject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = lobject.h; sourceTree = ""; }; + 91D465891E7977BB000BA0B9 /* loadlib.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = loadlib.c; sourceTree = ""; }; + 91D4658A1E7977BB000BA0B9 /* lstrlib.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = lstrlib.c; sourceTree = ""; }; + 91D4658B1E7977BB000BA0B9 /* lapi.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = lapi.c; sourceTree = ""; }; + 91D4658C1E7977BB000BA0B9 /* ldebug.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ldebug.c; sourceTree = ""; }; + 91D4658D1E7977BB000BA0B9 /* lundump.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = lundump.c; sourceTree = ""; }; + 91D4658E1E7977BB000BA0B9 /* ltablib.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ltablib.c; sourceTree = ""; }; + 91D4658F1E7977BB000BA0B9 /* lbaselib.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = lbaselib.c; sourceTree = ""; }; + 91D465901E7977BB000BA0B9 /* luaconf.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = luaconf.h; sourceTree = ""; }; + 91D465911E7977BB000BA0B9 /* lauxlib.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = lauxlib.c; sourceTree = ""; }; + 91D465921E7977BB000BA0B9 /* ldblib.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ldblib.c; sourceTree = ""; }; + 91D465931E7977BB000BA0B9 /* ldo.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ldo.c; sourceTree = ""; }; + 91D465941E7977BB000BA0B9 /* liolib.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = liolib.c; sourceTree = ""; }; + 91D465951E7977BB000BA0B9 /* loslib.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = loslib.c; sourceTree = ""; }; + 91D465961E7977BB000BA0B9 /* lstate.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = lstate.c; sourceTree = ""; }; + 91D465971E7977BB000BA0B9 /* lstate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = lstate.h; sourceTree = ""; }; + 91D465981E7977BB000BA0B9 /* lcode.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = lcode.c; sourceTree = ""; }; + 91D465991E7977BB000BA0B9 /* lparser.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = lparser.c; sourceTree = ""; }; + 91D4659A1E7977BB000BA0B9 /* ltable.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ltable.c; sourceTree = ""; }; + 91D4659B1E7977BB000BA0B9 /* lua.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = lua.c; sourceTree = ""; }; + 91D4659C1E7977BB000BA0B9 /* lvm.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = lvm.c; sourceTree = ""; }; + 91D4659D1E7977BB000BA0B9 /* lfunc.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = lfunc.c; sourceTree = ""; }; + 91D4659E1E7977BB000BA0B9 /* lapi.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = lapi.h; sourceTree = ""; }; + 91D4659F1E7977BB000BA0B9 /* lauxlib.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = lauxlib.h; sourceTree = ""; }; + 91D465A01E7977BB000BA0B9 /* lcode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = lcode.h; sourceTree = ""; }; + 91D465A11E7977BB000BA0B9 /* ldebug.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ldebug.h; sourceTree = ""; }; + 91D465A21E7977BB000BA0B9 /* ldo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ldo.h; sourceTree = ""; }; + 91D465A31E7977BB000BA0B9 /* ldump.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ldump.c; sourceTree = ""; }; + 91D465A41E7977BB000BA0B9 /* lfunc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = lfunc.h; sourceTree = ""; }; + 91D465A51E7977BB000BA0B9 /* lgc.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = lgc.c; sourceTree = ""; }; + 91D465A61E7977BB000BA0B9 /* lgc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = lgc.h; sourceTree = ""; }; + 91D465A71E7977BB000BA0B9 /* linit.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = linit.c; sourceTree = ""; }; + 91D465A81E7977BB000BA0B9 /* llex.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = llex.c; sourceTree = ""; }; + 91D465A91E7977BB000BA0B9 /* llex.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = llex.h; sourceTree = ""; }; + 91D465AA1E7977BB000BA0B9 /* llimits.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = llimits.h; sourceTree = ""; }; + 91D465AB1E7977BB000BA0B9 /* lmathlib.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = lmathlib.c; sourceTree = ""; }; + 91D465AC1E7977BB000BA0B9 /* lmem.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = lmem.c; sourceTree = ""; }; + 91D465AD1E7977BB000BA0B9 /* lmem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = lmem.h; sourceTree = ""; }; + 91D465AE1E7977BB000BA0B9 /* lobject.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = lobject.c; sourceTree = ""; }; + 91D465AF1E7977BB000BA0B9 /* lopcodes.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = lopcodes.c; sourceTree = ""; }; + 91D465B01E7977BB000BA0B9 /* lopcodes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = lopcodes.h; sourceTree = ""; }; + 91D465B11E7977BB000BA0B9 /* lparser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = lparser.h; sourceTree = ""; }; + 91D465B21E7977BB000BA0B9 /* lstring.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = lstring.c; sourceTree = ""; }; + 91D465B31E7977BB000BA0B9 /* lstring.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = lstring.h; sourceTree = ""; }; + 91D465B41E7977BB000BA0B9 /* ltable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ltable.h; sourceTree = ""; }; + 91D465B51E7977BB000BA0B9 /* ltm.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ltm.c; sourceTree = ""; }; + 91D465B61E7977BB000BA0B9 /* ltm.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ltm.h; sourceTree = ""; }; + 91D465B71E7977BB000BA0B9 /* lualib.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = lualib.h; sourceTree = ""; }; + 91D465B81E7977BB000BA0B9 /* lundump.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = lundump.h; sourceTree = ""; }; + 91D465B91E7977BB000BA0B9 /* lvm.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = lvm.h; sourceTree = ""; }; + 91D465BA1E7977BB000BA0B9 /* lzio.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = lzio.c; sourceTree = ""; }; + 91D465BB1E7977BB000BA0B9 /* lzio.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = lzio.h; sourceTree = ""; }; + 91D465BC1E7977BB000BA0B9 /* print.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = print.c; sourceTree = ""; }; + 91D465BD1E7977BB000BA0B9 /* luac.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = luac.c; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 91D465791E79775B000BA0B9 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 91D465731E79775B000BA0B9 = { + isa = PBXGroup; + children = ( + 91D4657E1E79775B000BA0B9 /* lua */, + 91D4657D1E79775B000BA0B9 /* Products */, + ); + sourceTree = ""; + }; + 91D4657D1E79775B000BA0B9 /* Products */ = { + isa = PBXGroup; + children = ( + 91D4657C1E79775B000BA0B9 /* liblua.a */, + ); + name = Products; + sourceTree = ""; + }; + 91D4657E1E79775B000BA0B9 /* lua */ = { + isa = PBXGroup; + children = ( + 91D4657F1E79775B000BA0B9 /* lua.h */, + 91D465881E7977BB000BA0B9 /* lobject.h */, + 91D465891E7977BB000BA0B9 /* loadlib.c */, + 91D4658A1E7977BB000BA0B9 /* lstrlib.c */, + 91D4658B1E7977BB000BA0B9 /* lapi.c */, + 91D4658C1E7977BB000BA0B9 /* ldebug.c */, + 91D4658D1E7977BB000BA0B9 /* lundump.c */, + 91D4658E1E7977BB000BA0B9 /* ltablib.c */, + 91D4658F1E7977BB000BA0B9 /* lbaselib.c */, + 91D465901E7977BB000BA0B9 /* luaconf.h */, + 91D465911E7977BB000BA0B9 /* lauxlib.c */, + 91D465921E7977BB000BA0B9 /* ldblib.c */, + 91D465931E7977BB000BA0B9 /* ldo.c */, + 91D465941E7977BB000BA0B9 /* liolib.c */, + 91D465951E7977BB000BA0B9 /* loslib.c */, + 91D465961E7977BB000BA0B9 /* lstate.c */, + 91D465971E7977BB000BA0B9 /* lstate.h */, + 91D465981E7977BB000BA0B9 /* lcode.c */, + 91D465991E7977BB000BA0B9 /* lparser.c */, + 91D4659A1E7977BB000BA0B9 /* ltable.c */, + 91D4659B1E7977BB000BA0B9 /* lua.c */, + 91D4659C1E7977BB000BA0B9 /* lvm.c */, + 91D4659D1E7977BB000BA0B9 /* lfunc.c */, + 91D4659E1E7977BB000BA0B9 /* lapi.h */, + 91D4659F1E7977BB000BA0B9 /* lauxlib.h */, + 91D465A01E7977BB000BA0B9 /* lcode.h */, + 91D465A11E7977BB000BA0B9 /* ldebug.h */, + 91D465A21E7977BB000BA0B9 /* ldo.h */, + 91D465A31E7977BB000BA0B9 /* ldump.c */, + 91D465A41E7977BB000BA0B9 /* lfunc.h */, + 91D465A51E7977BB000BA0B9 /* lgc.c */, + 91D465A61E7977BB000BA0B9 /* lgc.h */, + 91D465A71E7977BB000BA0B9 /* linit.c */, + 91D465A81E7977BB000BA0B9 /* llex.c */, + 91D465A91E7977BB000BA0B9 /* llex.h */, + 91D465AA1E7977BB000BA0B9 /* llimits.h */, + 91D465AB1E7977BB000BA0B9 /* lmathlib.c */, + 91D465AC1E7977BB000BA0B9 /* lmem.c */, + 91D465AD1E7977BB000BA0B9 /* lmem.h */, + 91D465AE1E7977BB000BA0B9 /* lobject.c */, + 91D465AF1E7977BB000BA0B9 /* lopcodes.c */, + 91D465B01E7977BB000BA0B9 /* lopcodes.h */, + 91D465B11E7977BB000BA0B9 /* lparser.h */, + 91D465B21E7977BB000BA0B9 /* lstring.c */, + 91D465B31E7977BB000BA0B9 /* lstring.h */, + 91D465B41E7977BB000BA0B9 /* ltable.h */, + 91D465B51E7977BB000BA0B9 /* ltm.c */, + 91D465B61E7977BB000BA0B9 /* ltm.h */, + 91D465B71E7977BB000BA0B9 /* lualib.h */, + 91D465B81E7977BB000BA0B9 /* lundump.h */, + 91D465B91E7977BB000BA0B9 /* lvm.h */, + 91D465BA1E7977BB000BA0B9 /* lzio.c */, + 91D465BB1E7977BB000BA0B9 /* lzio.h */, + 91D465BC1E7977BB000BA0B9 /* print.c */, + 91D465BD1E7977BB000BA0B9 /* luac.c */, + ); + path = lua; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 91D4657B1E79775B000BA0B9 /* lua */ = { + isa = PBXNativeTarget; + buildConfigurationList = 91D465851E79775B000BA0B9 /* Build configuration list for PBXNativeTarget "lua" */; + buildPhases = ( + 91D465781E79775B000BA0B9 /* Sources */, + 91D465791E79775B000BA0B9 /* Frameworks */, + 91D4657A1E79775B000BA0B9 /* CopyFiles */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = lua; + productName = lua; + productReference = 91D4657C1E79775B000BA0B9 /* liblua.a */; + productType = "com.apple.product-type.library.static"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 91D465741E79775B000BA0B9 /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 0820; + ORGANIZATIONNAME = Alibaba; + TargetAttributes = { + 91D4657B1E79775B000BA0B9 = { + CreatedOnToolsVersion = 8.2.1; + DevelopmentTeam = 6L4X75AQK7; + ProvisioningStyle = Automatic; + }; + }; + }; + buildConfigurationList = 91D465771E79775B000BA0B9 /* Build configuration list for PBXProject "lua" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + ); + mainGroup = 91D465731E79775B000BA0B9; + productRefGroup = 91D4657D1E79775B000BA0B9 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 91D4657B1E79775B000BA0B9 /* lua */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXSourcesBuildPhase section */ + 91D465781E79775B000BA0B9 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 91D465D61E7977BB000BA0B9 /* lmem.c in Sources */, + 91D465D21E7977BB000BA0B9 /* lgc.c in Sources */, + 91D465D51E7977BB000BA0B9 /* lmathlib.c in Sources */, + 91D465D01E7977BB000BA0B9 /* lfunc.c in Sources */, + 91D465CE1E7977BB000BA0B9 /* lua.c in Sources */, + 91D465DC1E7977BB000BA0B9 /* print.c in Sources */, + 91D465CA1E7977BB000BA0B9 /* lstate.c in Sources */, + 91D465D11E7977BB000BA0B9 /* ldump.c in Sources */, + 91D465C81E7977BB000BA0B9 /* liolib.c in Sources */, + 91D465DB1E7977BB000BA0B9 /* lzio.c in Sources */, + 91D465D91E7977BB000BA0B9 /* lstring.c in Sources */, + 91D465DA1E7977BB000BA0B9 /* ltm.c in Sources */, + 91D465CD1E7977BB000BA0B9 /* ltable.c in Sources */, + 91D465C71E7977BB000BA0B9 /* ldo.c in Sources */, + 91D465CC1E7977BB000BA0B9 /* lparser.c in Sources */, + 91D465CF1E7977BB000BA0B9 /* lvm.c in Sources */, + 91D465D81E7977BB000BA0B9 /* lopcodes.c in Sources */, + 91D465D71E7977BB000BA0B9 /* lobject.c in Sources */, + 91D465D31E7977BB000BA0B9 /* linit.c in Sources */, + 91D465D41E7977BB000BA0B9 /* llex.c in Sources */, + 91D465C41E7977BB000BA0B9 /* lbaselib.c in Sources */, + 91D465C91E7977BB000BA0B9 /* loslib.c in Sources */, + 91D465C51E7977BB000BA0B9 /* lauxlib.c in Sources */, + 91D465C21E7977BB000BA0B9 /* lundump.c in Sources */, + 91D465C61E7977BB000BA0B9 /* ldblib.c in Sources */, + 91D465CB1E7977BB000BA0B9 /* lcode.c in Sources */, + 91D465C11E7977BB000BA0B9 /* ldebug.c in Sources */, + 91D465C01E7977BB000BA0B9 /* lapi.c in Sources */, + 91D465BF1E7977BB000BA0B9 /* lstrlib.c in Sources */, + 91D465BE1E7977BB000BA0B9 /* loadlib.c in Sources */, + 91D465C31E7977BB000BA0B9 /* ltablib.c in Sources */, + 91D465DD1E7977BB000BA0B9 /* luac.c in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + 91D465831E79775B000BA0B9 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 10.2; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + }; + name = Debug; + }; + 91D465841E79775B000BA0B9 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 10.2; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = iphoneos; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 91D465861E79775B000BA0B9 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + DEVELOPMENT_TEAM = 6L4X75AQK7; + OTHER_LDFLAGS = "-ObjC"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SKIP_INSTALL = YES; + }; + name = Debug; + }; + 91D465871E79775B000BA0B9 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + DEVELOPMENT_TEAM = 6L4X75AQK7; + OTHER_LDFLAGS = "-ObjC"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SKIP_INSTALL = YES; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 91D465771E79775B000BA0B9 /* Build configuration list for PBXProject "lua" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 91D465831E79775B000BA0B9 /* Debug */, + 91D465841E79775B000BA0B9 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 91D465851E79775B000BA0B9 /* Build configuration list for PBXNativeTarget "lua" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 91D465861E79775B000BA0B9 /* Debug */, + 91D465871E79775B000BA0B9 /* Release */, + ); + defaultConfigurationIsVisible = 0; + }; +/* End XCConfigurationList section */ + }; + rootObject = 91D465741E79775B000BA0B9 /* Project object */; +} diff --git a/IOS/lua/lua/TAGS_NOTES.md b/IOS/lua/lua/TAGS_NOTES.md new file mode 100644 index 00000000..51241cdd --- /dev/null +++ b/IOS/lua/lua/TAGS_NOTES.md @@ -0,0 +1,46 @@ +# LuaView SDK tag Release Notes + +# 打Tag标准 +* 聚客中使用jhs开头的tag, 纯数字开头的tag由摩天轮自动打标; + + + +## tag: 2.4.1.13 -> LuaViewSDK 5.5.0 +### Feature +* 新加功能: +* 1.新加cell吸顶 + 视差效果 + 3Dbox +* 2.新加View的Layer模式 +* 3.新加CustomView Canvas绘图组件 +* 4.新加onTouch API +* 5.http -> https + + + +## tag: 2.4.1.15 -> LuaViewSDK 5.7.0 +### Feature +* 新加功能: +* 1.PagerView左右留边 + + + +## tag: 2.4.1.8 -> LuaViewSDK 5.8.0 +### Feature +* 新加功能: +* 1.功能正常,内容为空的下拉刷新 + +## tag: 2.5.10.1 -> LuaViewSDK 5.10.0 +### Feature +* 新加功能: +* 1.lua虚拟机标准化 + + + + + + + + + + + + diff --git a/IOS/lua/lua/lapi.c b/IOS/lua/lua/lapi.c new file mode 100644 index 00000000..5d5145d2 --- /dev/null +++ b/IOS/lua/lua/lapi.c @@ -0,0 +1,1087 @@ +/* +** $Id: lapi.c,v 2.55.1.5 2008/07/04 18:41:18 roberto Exp $ +** Lua API +** See Copyright Notice in lua.h +*/ + + +#include +#include +#include +#include + +#define lapi_c +#define LUA_CORE + +#include "lua.h" + +#include "lapi.h" +#include "ldebug.h" +#include "ldo.h" +#include "lfunc.h" +#include "lgc.h" +#include "lmem.h" +#include "lobject.h" +#include "lstate.h" +#include "lstring.h" +#include "ltable.h" +#include "ltm.h" +#include "lundump.h" +#include "lvm.h" + + + +const char lua_ident[] = + "$Lua: " LUA_RELEASE " " LUA_COPYRIGHT " $\n" + "$Authors: " LUA_AUTHORS " $\n" + "$URL: www.lua.org $\n"; + + + +#define api_checknelems(L, n) api_check(L, (n) <= (L->top - L->base)) + +#define api_checkvalidindex(L, i) api_check(L, (i) != luaO_nilobject) + +#define api_incr_top(L) {api_check(L, L->top < L->ci->top); L->top++;} + + + +static TValue *index2adr (lua_State *L, int idx) { + if (idx > 0) { + TValue *o = L->base + (idx - 1); + api_check(L, idx <= L->ci->top - L->base); + if (o >= L->top) return cast(TValue *, luaO_nilobject); + else return o; + } + else if (idx > LUA_REGISTRYINDEX) { + api_check(L, idx != 0 && -idx <= L->top - L->base); + return L->top + idx; + } + else switch (idx) { /* pseudo-indices */ + case LUA_REGISTRYINDEX: return registry(L); + case LUA_ENVIRONINDEX: { + Closure *func = curr_func(L); + sethvalue(L, &L->env, func->c.env); + return &L->env; + } + case LUA_GLOBALSINDEX: return gt(L); + default: { + Closure *func = curr_func(L); + idx = LUA_GLOBALSINDEX - idx; + return (idx <= func->c.nupvalues) + ? &func->c.upvalue[idx-1] + : cast(TValue *, luaO_nilobject); + } + } +} + + +static Table *getcurrenv (lua_State *L) { + if (L->ci == L->base_ci) /* no enclosing function? */ + return hvalue(gt(L)); /* use global table as environment */ + else { + Closure *func = curr_func(L); + return func->c.env; + } +} + + +void luaA_pushobject (lua_State *L, const TValue *o) { + setobj2s(L, L->top, o); + api_incr_top(L); +} + + +LUA_API int lua_checkstack (lua_State *L, int size) { + int res = 1; + lua_lock(L); + if (size > LUAI_MAXCSTACK || (L->top - L->base + size) > LUAI_MAXCSTACK) + res = 0; /* stack overflow */ + else if (size > 0) { + luaD_checkstack(L, size); + if (L->ci->top < L->top + size) + L->ci->top = L->top + size; + } + lua_unlock(L); + return res; +} + + +LUA_API void lua_xmove (lua_State *from, lua_State *to, int n) { + int i; + if (from == to) return; + lua_lock(to); + api_checknelems(from, n); + api_check(from, G(from) == G(to)); + api_check(from, to->ci->top - to->top >= n); + from->top -= n; + for (i = 0; i < n; i++) { + setobj2s(to, to->top++, from->top + i); + } + lua_unlock(to); +} + + +LUA_API void lua_setlevel (lua_State *from, lua_State *to) { + to->nCcalls = from->nCcalls; +} + + +LUA_API lua_CFunction lua_atpanic (lua_State *L, lua_CFunction panicf) { + lua_CFunction old; + lua_lock(L); + old = G(L)->panic; + G(L)->panic = panicf; + lua_unlock(L); + return old; +} + + +LUA_API lua_State *lua_newthread (lua_State *L) { + lua_State *L1; + lua_lock(L); + luaC_checkGC(L); + L1 = luaE_newthread(L); + setthvalue(L, L->top, L1); + api_incr_top(L); + lua_unlock(L); + luai_userstatethread(L, L1); + return L1; +} + + + +/* +** basic stack manipulation +*/ + + +LUA_API int lua_gettop (lua_State *L) { + return cast_int(L->top - L->base); +} + + +LUA_API void lua_settop (lua_State *L, int idx) { + lua_lock(L); + if (idx >= 0) { + api_check(L, idx <= L->stack_last - L->base); + while (L->top < L->base + idx) + setnilvalue(L->top++); + L->top = L->base + idx; + } + else { + api_check(L, -(idx+1) <= (L->top - L->base)); + L->top += idx+1; /* `subtract' index (index is negative) */ + } + lua_unlock(L); +} + + +LUA_API void lua_remove (lua_State *L, int idx) { + StkId p; + lua_lock(L); + p = index2adr(L, idx); + api_checkvalidindex(L, p); + while (++p < L->top) setobjs2s(L, p-1, p); + L->top--; + lua_unlock(L); +} + + +LUA_API void lua_insert (lua_State *L, int idx) { + StkId p; + StkId q; + lua_lock(L); + p = index2adr(L, idx); + api_checkvalidindex(L, p); + for (q = L->top; q>p; q--) setobjs2s(L, q, q-1); + setobjs2s(L, p, L->top); + lua_unlock(L); +} + + +LUA_API void lua_replace (lua_State *L, int idx) { + StkId o; + lua_lock(L); + /* explicit test for incompatible code */ + if (idx == LUA_ENVIRONINDEX && L->ci == L->base_ci) + luaG_runerror(L, "no calling environment"); + api_checknelems(L, 1); + o = index2adr(L, idx); + api_checkvalidindex(L, o); + if (idx == LUA_ENVIRONINDEX) { + Closure *func = curr_func(L); + api_check(L, ttistable(L->top - 1)); + func->c.env = hvalue(L->top - 1); + luaC_barrier(L, func, L->top - 1); + } + else { + setobj(L, o, L->top - 1); + if (idx < LUA_GLOBALSINDEX) /* function upvalue? */ + luaC_barrier(L, curr_func(L), L->top - 1); + } + L->top--; + lua_unlock(L); +} + + +LUA_API void lua_pushvalue (lua_State *L, int idx) { + lua_lock(L); + setobj2s(L, L->top, index2adr(L, idx)); + api_incr_top(L); + lua_unlock(L); +} + + + +/* +** access functions (stack -> C) +*/ + + +LUA_API int lua_type (lua_State *L, int idx) { + StkId o = index2adr(L, idx); + return (o == luaO_nilobject) ? LUA_TNONE : ttype(o); +} + + +LUA_API const char *lua_typename (lua_State *L, int t) { + UNUSED(L); + return (t == LUA_TNONE) ? "no value" : luaT_typenames[t]; +} + + +LUA_API int lua_iscfunction (lua_State *L, int idx) { + StkId o = index2adr(L, idx); + return iscfunction(o); +} + + +LUA_API int lua_isnumber (lua_State *L, int idx) { + TValue n; + const TValue *o = index2adr(L, idx); + return tonumber(o, &n); +} + + +LUA_API int lua_isstring (lua_State *L, int idx) { + int t = lua_type(L, idx); + return (t == LUA_TSTRING || t == LUA_TNUMBER); +} + + +LUA_API int lua_isuserdata (lua_State *L, int idx) { + const TValue *o = index2adr(L, idx); + return (ttisuserdata(o) || ttislightuserdata(o)); +} + + +LUA_API int lua_rawequal (lua_State *L, int index1, int index2) { + StkId o1 = index2adr(L, index1); + StkId o2 = index2adr(L, index2); + return (o1 == luaO_nilobject || o2 == luaO_nilobject) ? 0 + : luaO_rawequalObj(o1, o2); +} + + +LUA_API int lua_equal (lua_State *L, int index1, int index2) { + StkId o1, o2; + int i; + lua_lock(L); /* may call tag method */ + o1 = index2adr(L, index1); + o2 = index2adr(L, index2); + i = (o1 == luaO_nilobject || o2 == luaO_nilobject) ? 0 : equalobj(L, o1, o2); + lua_unlock(L); + return i; +} + + +LUA_API int lua_lessthan (lua_State *L, int index1, int index2) { + StkId o1, o2; + int i; + lua_lock(L); /* may call tag method */ + o1 = index2adr(L, index1); + o2 = index2adr(L, index2); + i = (o1 == luaO_nilobject || o2 == luaO_nilobject) ? 0 + : luaV_lessthan(L, o1, o2); + lua_unlock(L); + return i; +} + + + +LUA_API lua_Number lua_tonumber (lua_State *L, int idx) { + TValue n; + const TValue *o = index2adr(L, idx); + if (tonumber(o, &n)) + return nvalue(o); + else + return 0; +} + + +LUA_API lua_Integer lua_tointeger (lua_State *L, int idx) { + TValue n; + const TValue *o = index2adr(L, idx); + if (tonumber(o, &n)) { + lua_Integer res; + lua_Number num = nvalue(o); + lua_number2integer(res, num); + return res; + } + else + return 0; +} + + +LUA_API int lua_toboolean (lua_State *L, int idx) { + const TValue *o = index2adr(L, idx); + return !l_isfalse(o); +} + + +LUA_API const char *lua_tolstring (lua_State *L, int idx, size_t *len) { + StkId o = index2adr(L, idx); + if (!ttisstring(o)) { + lua_lock(L); /* `luaV_tostring' may create a new string */ + if (!luaV_tostring(L, o)) { /* conversion failed? */ + if (len != NULL) *len = 0; + lua_unlock(L); + return NULL; + } + luaC_checkGC(L); + o = index2adr(L, idx); /* previous call may reallocate the stack */ + lua_unlock(L); + } + if (len != NULL) *len = tsvalue(o)->len; + return svalue(o); +} + + +LUA_API size_t lua_objlen (lua_State *L, int idx) { + StkId o = index2adr(L, idx); + switch (ttype(o)) { + case LUA_TSTRING: return tsvalue(o)->len; + case LUA_TUSERDATA: return uvalue(o)->len; + case LUA_TTABLE: return luaH_getn(hvalue(o)); + case LUA_TNUMBER: { + size_t l; + lua_lock(L); /* `luaV_tostring' may create a new string */ + l = (luaV_tostring(L, o) ? tsvalue(o)->len : 0); + lua_unlock(L); + return l; + } + default: return 0; + } +} + + +LUA_API lua_CFunction lua_tocfunction (lua_State *L, int idx) { + StkId o = index2adr(L, idx); + return (!iscfunction(o)) ? NULL : clvalue(o)->c.f; +} + + +LUA_API void *lua_touserdata (lua_State *L, int idx) { + StkId o = index2adr(L, idx); + switch (ttype(o)) { + case LUA_TUSERDATA: return (rawuvalue(o) + 1); + case LUA_TLIGHTUSERDATA: return pvalue(o); + default: return NULL; + } +} + + +LUA_API lua_State *lua_tothread (lua_State *L, int idx) { + StkId o = index2adr(L, idx); + return (!ttisthread(o)) ? NULL : thvalue(o); +} + + +LUA_API const void *lua_topointer (lua_State *L, int idx) { + StkId o = index2adr(L, idx); + switch (ttype(o)) { + case LUA_TTABLE: return hvalue(o); + case LUA_TFUNCTION: return clvalue(o); + case LUA_TTHREAD: return thvalue(o); + case LUA_TUSERDATA: + case LUA_TLIGHTUSERDATA: + return lua_touserdata(L, idx); + default: return NULL; + } +} + + + +/* +** push functions (C -> stack) +*/ + + +LUA_API void lua_pushnil (lua_State *L) { + lua_lock(L); + setnilvalue(L->top); + api_incr_top(L); + lua_unlock(L); +} + + +LUA_API void lua_pushnumber (lua_State *L, lua_Number n) { + lua_lock(L); + setnvalue(L->top, n); + api_incr_top(L); + lua_unlock(L); +} + + +LUA_API void lua_pushinteger (lua_State *L, lua_Integer n) { + lua_lock(L); + setnvalue(L->top, cast_num(n)); + api_incr_top(L); + lua_unlock(L); +} + + +LUA_API void lua_pushlstring (lua_State *L, const char *s, size_t len) { + lua_lock(L); + luaC_checkGC(L); + setsvalue2s(L, L->top, luaS_newlstr(L, s, len)); + api_incr_top(L); + lua_unlock(L); +} + + +LUA_API void lua_pushstring (lua_State *L, const char *s) { + if (s == NULL) + lua_pushnil(L); + else + lua_pushlstring(L, s, strlen(s)); +} + + +LUA_API const char *lua_pushvfstring (lua_State *L, const char *fmt, + va_list argp) { + const char *ret; + lua_lock(L); + luaC_checkGC(L); + ret = luaO_pushvfstring(L, fmt, argp); + lua_unlock(L); + return ret; +} + + +LUA_API const char *lua_pushfstring (lua_State *L, const char *fmt, ...) { + const char *ret; + va_list argp; + lua_lock(L); + luaC_checkGC(L); + va_start(argp, fmt); + ret = luaO_pushvfstring(L, fmt, argp); + va_end(argp); + lua_unlock(L); + return ret; +} + + +LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) { + Closure *cl; + lua_lock(L); + luaC_checkGC(L); + api_checknelems(L, n); + cl = luaF_newCclosure(L, n, getcurrenv(L)); + cl->c.f = fn; + L->top -= n; + while (n--) + setobj2n(L, &cl->c.upvalue[n], L->top+n); + setclvalue(L, L->top, cl); + lua_assert(iswhite(obj2gco(cl))); + api_incr_top(L); + lua_unlock(L); +} + + +LUA_API void lua_pushboolean (lua_State *L, int b) { + lua_lock(L); + setbvalue(L->top, (b != 0)); /* ensure that true is 1 */ + api_incr_top(L); + lua_unlock(L); +} + + +LUA_API void lua_pushlightuserdata (lua_State *L, void *p) { + lua_lock(L); + setpvalue(L->top, p); + api_incr_top(L); + lua_unlock(L); +} + + +LUA_API int lua_pushthread (lua_State *L) { + lua_lock(L); + setthvalue(L, L->top, L); + api_incr_top(L); + lua_unlock(L); + return (G(L)->mainthread == L); +} + + + +/* +** get functions (Lua -> stack) +*/ + + +LUA_API void lua_gettable (lua_State *L, int idx) { + StkId t; + lua_lock(L); + t = index2adr(L, idx); + api_checkvalidindex(L, t); + luaV_gettable(L, t, L->top - 1, L->top - 1); + lua_unlock(L); +} + + +LUA_API void lua_getfield (lua_State *L, int idx, const char *k) { + StkId t; + TValue key; + lua_lock(L); + t = index2adr(L, idx); + api_checkvalidindex(L, t); + setsvalue(L, &key, luaS_new(L, k)); + luaV_gettable(L, t, &key, L->top); + api_incr_top(L); + lua_unlock(L); +} + + +LUA_API void lua_rawget (lua_State *L, int idx) { + StkId t; + lua_lock(L); + t = index2adr(L, idx); + api_check(L, ttistable(t)); + setobj2s(L, L->top - 1, luaH_get(hvalue(t), L->top - 1)); + lua_unlock(L); +} + + +LUA_API void lua_rawgeti (lua_State *L, int idx, int n) { + StkId o; + lua_lock(L); + o = index2adr(L, idx); + api_check(L, ttistable(o)); + setobj2s(L, L->top, luaH_getnum(hvalue(o), n)); + api_incr_top(L); + lua_unlock(L); +} + + +LUA_API void lua_createtable (lua_State *L, int narray, int nrec) { + lua_lock(L); + luaC_checkGC(L); + sethvalue(L, L->top, luaH_new(L, narray, nrec)); + api_incr_top(L); + lua_unlock(L); +} + + +LUA_API int lua_getmetatable (lua_State *L, int objindex) { + const TValue *obj; + Table *mt = NULL; + int res; + lua_lock(L); + obj = index2adr(L, objindex); + switch (ttype(obj)) { + case LUA_TTABLE: + mt = hvalue(obj)->metatable; + break; + case LUA_TUSERDATA: + mt = uvalue(obj)->metatable; + break; + default: + mt = G(L)->mt[ttype(obj)]; + break; + } + if (mt == NULL) + res = 0; + else { + sethvalue(L, L->top, mt); + api_incr_top(L); + res = 1; + } + lua_unlock(L); + return res; +} + + +LUA_API void lua_getfenv (lua_State *L, int idx) { + StkId o; + lua_lock(L); + o = index2adr(L, idx); + api_checkvalidindex(L, o); + switch (ttype(o)) { + case LUA_TFUNCTION: + sethvalue(L, L->top, clvalue(o)->c.env); + break; + case LUA_TUSERDATA: + sethvalue(L, L->top, uvalue(o)->env); + break; + case LUA_TTHREAD: + setobj2s(L, L->top, gt(thvalue(o))); + break; + default: + setnilvalue(L->top); + break; + } + api_incr_top(L); + lua_unlock(L); +} + + +/* +** set functions (stack -> Lua) +*/ + + +LUA_API void lua_settable (lua_State *L, int idx) { + StkId t; + lua_lock(L); + api_checknelems(L, 2); + t = index2adr(L, idx); + api_checkvalidindex(L, t); + luaV_settable(L, t, L->top - 2, L->top - 1); + L->top -= 2; /* pop index and value */ + lua_unlock(L); +} + + +LUA_API void lua_setfield (lua_State *L, int idx, const char *k) { + StkId t; + TValue key; + lua_lock(L); + api_checknelems(L, 1); + t = index2adr(L, idx); + api_checkvalidindex(L, t); + setsvalue(L, &key, luaS_new(L, k)); + luaV_settable(L, t, &key, L->top - 1); + L->top--; /* pop value */ + lua_unlock(L); +} + + +LUA_API void lua_rawset (lua_State *L, int idx) { + StkId t; + lua_lock(L); + api_checknelems(L, 2); + t = index2adr(L, idx); + api_check(L, ttistable(t)); + setobj2t(L, luaH_set(L, hvalue(t), L->top-2), L->top-1); + luaC_barriert(L, hvalue(t), L->top-1); + L->top -= 2; + lua_unlock(L); +} + + +LUA_API void lua_rawseti (lua_State *L, int idx, int n) { + StkId o; + lua_lock(L); + api_checknelems(L, 1); + o = index2adr(L, idx); + api_check(L, ttistable(o)); + setobj2t(L, luaH_setnum(L, hvalue(o), n), L->top-1); + luaC_barriert(L, hvalue(o), L->top-1); + L->top--; + lua_unlock(L); +} + + +LUA_API int lua_setmetatable (lua_State *L, int objindex) { + TValue *obj; + Table *mt; + lua_lock(L); + api_checknelems(L, 1); + obj = index2adr(L, objindex); + api_checkvalidindex(L, obj); + if (ttisnil(L->top - 1)) + mt = NULL; + else { + api_check(L, ttistable(L->top - 1)); + mt = hvalue(L->top - 1); + } + switch (ttype(obj)) { + case LUA_TTABLE: { + hvalue(obj)->metatable = mt; + if (mt) + luaC_objbarriert(L, hvalue(obj), mt); + break; + } + case LUA_TUSERDATA: { + uvalue(obj)->metatable = mt; + if (mt) + luaC_objbarrier(L, rawuvalue(obj), mt); + break; + } + default: { + G(L)->mt[ttype(obj)] = mt; + break; + } + } + L->top--; + lua_unlock(L); + return 1; +} + + +LUA_API int lua_setfenv (lua_State *L, int idx) { + StkId o; + int res = 1; + lua_lock(L); + api_checknelems(L, 1); + o = index2adr(L, idx); + api_checkvalidindex(L, o); + api_check(L, ttistable(L->top - 1)); + switch (ttype(o)) { + case LUA_TFUNCTION: + clvalue(o)->c.env = hvalue(L->top - 1); + break; + case LUA_TUSERDATA: + uvalue(o)->env = hvalue(L->top - 1); + break; + case LUA_TTHREAD: + sethvalue(L, gt(thvalue(o)), hvalue(L->top - 1)); + break; + default: + res = 0; + break; + } + if (res) luaC_objbarrier(L, gcvalue(o), hvalue(L->top - 1)); + L->top--; + lua_unlock(L); + return res; +} + + +/* +** `load' and `call' functions (run Lua code) +*/ + + +#define adjustresults(L,nres) \ + { if (nres == LUA_MULTRET && L->top >= L->ci->top) L->ci->top = L->top; } + + +#define checkresults(L,na,nr) \ + api_check(L, (nr) == LUA_MULTRET || (L->ci->top - L->top >= (nr) - (na))) + + +LUA_API void lua_call (lua_State *L, int nargs, int nresults) { + StkId func; + lua_lock(L); + api_checknelems(L, nargs+1); + checkresults(L, nargs, nresults); + func = L->top - (nargs+1); + luaD_call(L, func, nresults); + adjustresults(L, nresults); + lua_unlock(L); +} + + + +/* +** Execute a protected call. +*/ +struct CallS { /* data to `f_call' */ + StkId func; + int nresults; +}; + + +static void f_call (lua_State *L, void *ud) { + struct CallS *c = cast(struct CallS *, ud); + luaD_call(L, c->func, c->nresults); +} + + + +LUA_API int lua_pcall (lua_State *L, int nargs, int nresults, int errfunc) { + struct CallS c; + int status; + ptrdiff_t func; + lua_lock(L); + api_checknelems(L, nargs+1); + checkresults(L, nargs, nresults); + if (errfunc == 0) + func = 0; + else { + StkId o = index2adr(L, errfunc); + api_checkvalidindex(L, o); + func = savestack(L, o); + } + c.func = L->top - (nargs+1); /* function to be called */ + c.nresults = nresults; + status = luaD_pcall(L, f_call, &c, savestack(L, c.func), func); + adjustresults(L, nresults); + lua_unlock(L); + return status; +} + + +/* +** Execute a protected C call. +*/ +struct CCallS { /* data to `f_Ccall' */ + lua_CFunction func; + void *ud; +}; + + +static void f_Ccall (lua_State *L, void *ud) { + struct CCallS *c = cast(struct CCallS *, ud); + Closure *cl; + cl = luaF_newCclosure(L, 0, getcurrenv(L)); + cl->c.f = c->func; + setclvalue(L, L->top, cl); /* push function */ + api_incr_top(L); + setpvalue(L->top, c->ud); /* push only argument */ + api_incr_top(L); + luaD_call(L, L->top - 2, 0); +} + + +LUA_API int lua_cpcall (lua_State *L, lua_CFunction func, void *ud) { + struct CCallS c; + int status; + lua_lock(L); + c.func = func; + c.ud = ud; + status = luaD_pcall(L, f_Ccall, &c, savestack(L, L->top), 0); + lua_unlock(L); + return status; +} + + +LUA_API int lua_load (lua_State *L, lua_Reader reader, void *data, + const char *chunkname) { + ZIO z; + int status; + lua_lock(L); + if (!chunkname) chunkname = "?"; + luaZ_init(L, &z, reader, data); + status = luaD_protectedparser(L, &z, chunkname); + lua_unlock(L); + return status; +} + + +LUA_API int lua_dump (lua_State *L, lua_Writer writer, void *data) { + int status; + TValue *o; + lua_lock(L); + api_checknelems(L, 1); + o = L->top - 1; + if (isLfunction(o)) + status = luaU_dump(L, clvalue(o)->l.p, writer, data, 0); + else + status = 1; + lua_unlock(L); + return status; +} + + +LUA_API int lua_status (lua_State *L) { + return L->status; +} + + +/* +** Garbage-collection function +*/ + +LUA_API int lua_gc (lua_State *L, int what, int data) { + int res = 0; + global_State *g; + lua_lock(L); + g = G(L); + switch (what) { + case LUA_GCSTOP: { + g->GCthreshold = MAX_LUMEM; + break; + } + case LUA_GCRESTART: { + g->GCthreshold = g->totalbytes; + break; + } + case LUA_GCCOLLECT: { + luaC_fullgc(L); + break; + } + case LUA_GCCOUNT: { + /* GC values are expressed in Kbytes: #bytes/2^10 */ + res = cast_int(g->totalbytes >> 10); + break; + } + case LUA_GCCOUNTB: { + res = cast_int(g->totalbytes & 0x3ff); + break; + } + case LUA_GCSTEP: { + lu_mem a = (cast(lu_mem, data) << 10); + if (a <= g->totalbytes) + g->GCthreshold = g->totalbytes - a; + else + g->GCthreshold = 0; + while (g->GCthreshold <= g->totalbytes) { + luaC_step(L); + if (g->gcstate == GCSpause) { /* end of cycle? */ + res = 1; /* signal it */ + break; + } + } + break; + } + case LUA_GCSETPAUSE: { + res = g->gcpause; + g->gcpause = data; + break; + } + case LUA_GCSETSTEPMUL: { + res = g->gcstepmul; + g->gcstepmul = data; + break; + } + default: res = -1; /* invalid option */ + } + lua_unlock(L); + return res; +} + + + +/* +** miscellaneous functions +*/ + + +LUA_API int lua_error (lua_State *L) { + lua_lock(L); + api_checknelems(L, 1); + luaG_errormsg(L); + lua_unlock(L); + return 0; /* to avoid warnings */ +} + + +LUA_API int lua_next (lua_State *L, int idx) { + StkId t; + int more; + lua_lock(L); + t = index2adr(L, idx); + api_check(L, ttistable(t)); + more = luaH_next(L, hvalue(t), L->top - 1); + if (more) { + api_incr_top(L); + } + else /* no more elements */ + L->top -= 1; /* remove key */ + lua_unlock(L); + return more; +} + + +LUA_API void lua_concat (lua_State *L, int n) { + lua_lock(L); + api_checknelems(L, n); + if (n >= 2) { + luaC_checkGC(L); + luaV_concat(L, n, cast_int(L->top - L->base) - 1); + L->top -= (n-1); + } + else if (n == 0) { /* push empty string */ + setsvalue2s(L, L->top, luaS_newlstr(L, "", 0)); + api_incr_top(L); + } + /* else n == 1; nothing to do */ + lua_unlock(L); +} + + +LUA_API lua_Alloc lua_getallocf (lua_State *L, void **ud) { + lua_Alloc f; + lua_lock(L); + if (ud) *ud = G(L)->ud; + f = G(L)->frealloc; + lua_unlock(L); + return f; +} + + +LUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud) { + lua_lock(L); + G(L)->ud = ud; + G(L)->frealloc = f; + lua_unlock(L); +} + + +LUA_API void *lua_newuserdata (lua_State *L, size_t size) { + Udata *u; + lua_lock(L); + luaC_checkGC(L); + u = luaS_newudata(L, size, getcurrenv(L)); + setuvalue(L, L->top, u); + api_incr_top(L); + lua_unlock(L); + return u + 1; +} + + + + +static const char *aux_upvalue (StkId fi, int n, TValue **val) { + Closure *f; + if (!ttisfunction(fi)) return NULL; + f = clvalue(fi); + if (f->c.isC) { + if (!(1 <= n && n <= f->c.nupvalues)) return NULL; + *val = &f->c.upvalue[n-1]; + return ""; + } + else { + Proto *p = f->l.p; + if (!(1 <= n && n <= p->sizeupvalues)) return NULL; + *val = f->l.upvals[n-1]->v; + return getstr(p->upvalues[n-1]); + } +} + + +LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n) { + const char *name; + TValue *val; + lua_lock(L); + name = aux_upvalue(index2adr(L, funcindex), n, &val); + if (name) { + setobj2s(L, L->top, val); + api_incr_top(L); + } + lua_unlock(L); + return name; +} + + +LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n) { + const char *name; + TValue *val; + StkId fi; + lua_lock(L); + fi = index2adr(L, funcindex); + api_checknelems(L, 1); + name = aux_upvalue(fi, n, &val); + if (name) { + L->top--; + setobj(L, val, L->top); + luaC_barrier(L, clvalue(fi), L->top); + } + lua_unlock(L); + return name; +} + diff --git a/IOS/lua/lua/lapi.h b/IOS/lua/lua/lapi.h new file mode 100644 index 00000000..2c3fab24 --- /dev/null +++ b/IOS/lua/lua/lapi.h @@ -0,0 +1,16 @@ +/* +** $Id: lapi.h,v 2.2.1.1 2007/12/27 13:02:25 roberto Exp $ +** Auxiliary functions from Lua API +** See Copyright Notice in lua.h +*/ + +#ifndef lapi_h +#define lapi_h + + +#include "lobject.h" + + +LUAI_FUNC void luaA_pushobject (lua_State *L, const TValue *o); + +#endif diff --git a/IOS/lua/lua/lauxlib.c b/IOS/lua/lua/lauxlib.c new file mode 100644 index 00000000..10f14e2c --- /dev/null +++ b/IOS/lua/lua/lauxlib.c @@ -0,0 +1,652 @@ +/* +** $Id: lauxlib.c,v 1.159.1.3 2008/01/21 13:20:51 roberto Exp $ +** Auxiliary functions for building Lua libraries +** See Copyright Notice in lua.h +*/ + + +#include +#include +#include +#include +#include +#include + + +/* This file uses only the official API of Lua. +** Any function declared here could be written as an application function. +*/ + +#define lauxlib_c +#define LUA_LIB + +#include "lua.h" + +#include "lauxlib.h" + + +#define FREELIST_REF 0 /* free list of references */ + + +/* convert a stack index to positive */ +#define abs_index(L, i) ((i) > 0 || (i) <= LUA_REGISTRYINDEX ? (i) : \ + lua_gettop(L) + (i) + 1) + + +/* +** {====================================================== +** Error-report functions +** ======================================================= +*/ + + +LUALIB_API int luaL_argerror (lua_State *L, int narg, const char *extramsg) { + lua_Debug ar; + if (!lua_getstack(L, 0, &ar)) /* no stack frame? */ + return luaL_error(L, "bad argument #%d (%s)", narg, extramsg); + lua_getinfo(L, "n", &ar); + if (strcmp(ar.namewhat, "method") == 0) { + narg--; /* do not count `self' */ + if (narg == 0) /* error is in the self argument itself? */ + return luaL_error(L, "calling " LUA_QS " on bad self (%s)", + ar.name, extramsg); + } + if (ar.name == NULL) + ar.name = "?"; + return luaL_error(L, "bad argument #%d to " LUA_QS " (%s)", + narg, ar.name, extramsg); +} + + +LUALIB_API int luaL_typerror (lua_State *L, int narg, const char *tname) { + const char *msg = lua_pushfstring(L, "%s expected, got %s", + tname, luaL_typename(L, narg)); + return luaL_argerror(L, narg, msg); +} + + +static void tag_error (lua_State *L, int narg, int tag) { + luaL_typerror(L, narg, lua_typename(L, tag)); +} + + +LUALIB_API void luaL_where (lua_State *L, int level) { + lua_Debug ar; + if (lua_getstack(L, level, &ar)) { /* check function at level */ + lua_getinfo(L, "Sl", &ar); /* get info about it */ + if (ar.currentline > 0) { /* is there info? */ + lua_pushfstring(L, "%s:%d: ", ar.short_src, ar.currentline); + return; + } + } + lua_pushliteral(L, ""); /* else, no information available... */ +} + + +LUALIB_API int luaL_error (lua_State *L, const char *fmt, ...) { + va_list argp; + va_start(argp, fmt); + luaL_where(L, 1); + lua_pushvfstring(L, fmt, argp); + va_end(argp); + lua_concat(L, 2); + return lua_error(L); +} + +/* }====================================================== */ + + +LUALIB_API int luaL_checkoption (lua_State *L, int narg, const char *def, + const char *const lst[]) { + const char *name = (def) ? luaL_optstring(L, narg, def) : + luaL_checkstring(L, narg); + int i; + for (i=0; lst[i]; i++) + if (strcmp(lst[i], name) == 0) + return i; + return luaL_argerror(L, narg, + lua_pushfstring(L, "invalid option " LUA_QS, name)); +} + + +LUALIB_API int luaL_newmetatable (lua_State *L, const char *tname) { + lua_getfield(L, LUA_REGISTRYINDEX, tname); /* get registry.name */ + if (!lua_isnil(L, -1)) /* name already in use? */ + return 0; /* leave previous value on top, but return 0 */ + lua_pop(L, 1); + lua_newtable(L); /* create metatable */ + lua_pushvalue(L, -1); + lua_setfield(L, LUA_REGISTRYINDEX, tname); /* registry.name = metatable */ + return 1; +} + + +LUALIB_API void *luaL_checkudata (lua_State *L, int ud, const char *tname) { + void *p = lua_touserdata(L, ud); + if (p != NULL) { /* value is a userdata? */ + if (lua_getmetatable(L, ud)) { /* does it have a metatable? */ + lua_getfield(L, LUA_REGISTRYINDEX, tname); /* get correct metatable */ + if (lua_rawequal(L, -1, -2)) { /* does it have the correct mt? */ + lua_pop(L, 2); /* remove both metatables */ + return p; + } + } + } + luaL_typerror(L, ud, tname); /* else error */ + return NULL; /* to avoid warnings */ +} + + +LUALIB_API void luaL_checkstack (lua_State *L, int space, const char *mes) { + if (!lua_checkstack(L, space)) + luaL_error(L, "stack overflow (%s)", mes); +} + + +LUALIB_API void luaL_checktype (lua_State *L, int narg, int t) { + if (lua_type(L, narg) != t) + tag_error(L, narg, t); +} + + +LUALIB_API void luaL_checkany (lua_State *L, int narg) { + if (lua_type(L, narg) == LUA_TNONE) + luaL_argerror(L, narg, "value expected"); +} + + +LUALIB_API const char *luaL_checklstring (lua_State *L, int narg, size_t *len) { + const char *s = lua_tolstring(L, narg, len); + if (!s) tag_error(L, narg, LUA_TSTRING); + return s; +} + + +LUALIB_API const char *luaL_optlstring (lua_State *L, int narg, + const char *def, size_t *len) { + if (lua_isnoneornil(L, narg)) { + if (len) + *len = (def ? strlen(def) : 0); + return def; + } + else return luaL_checklstring(L, narg, len); +} + + +LUALIB_API lua_Number luaL_checknumber (lua_State *L, int narg) { + lua_Number d = lua_tonumber(L, narg); + if (d == 0 && !lua_isnumber(L, narg)) /* avoid extra test when d is not 0 */ + tag_error(L, narg, LUA_TNUMBER); + return d; +} + + +LUALIB_API lua_Number luaL_optnumber (lua_State *L, int narg, lua_Number def) { + return luaL_opt(L, luaL_checknumber, narg, def); +} + + +LUALIB_API lua_Integer luaL_checkinteger (lua_State *L, int narg) { + lua_Integer d = lua_tointeger(L, narg); + if (d == 0 && !lua_isnumber(L, narg)) /* avoid extra test when d is not 0 */ + tag_error(L, narg, LUA_TNUMBER); + return d; +} + + +LUALIB_API lua_Integer luaL_optinteger (lua_State *L, int narg, + lua_Integer def) { + return luaL_opt(L, luaL_checkinteger, narg, def); +} + + +LUALIB_API int luaL_getmetafield (lua_State *L, int obj, const char *event) { + if (!lua_getmetatable(L, obj)) /* no metatable? */ + return 0; + lua_pushstring(L, event); + lua_rawget(L, -2); + if (lua_isnil(L, -1)) { + lua_pop(L, 2); /* remove metatable and metafield */ + return 0; + } + else { + lua_remove(L, -2); /* remove only metatable */ + return 1; + } +} + + +LUALIB_API int luaL_callmeta (lua_State *L, int obj, const char *event) { + obj = abs_index(L, obj); + if (!luaL_getmetafield(L, obj, event)) /* no metafield? */ + return 0; + lua_pushvalue(L, obj); + lua_call(L, 1, 1); + return 1; +} + + +LUALIB_API void (luaL_register) (lua_State *L, const char *libname, + const luaL_Reg *l) { + luaI_openlib(L, libname, l, 0); +} + + +static int libsize (const luaL_Reg *l) { + int size = 0; + for (; l->name; l++) size++; + return size; +} + + +LUALIB_API void luaI_openlib (lua_State *L, const char *libname, + const luaL_Reg *l, int nup) { + if (libname) { + int size = libsize(l); + /* check whether lib already exists */ + luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 1); + lua_getfield(L, -1, libname); /* get _LOADED[libname] */ + if (!lua_istable(L, -1)) { /* not found? */ + lua_pop(L, 1); /* remove previous result */ + /* try global variable (and create one if it does not exist) */ + if (luaL_findtable(L, LUA_GLOBALSINDEX, libname, size) != NULL) + luaL_error(L, "name conflict for module " LUA_QS, libname); + lua_pushvalue(L, -1); + lua_setfield(L, -3, libname); /* _LOADED[libname] = new table */ + } + lua_remove(L, -2); /* remove _LOADED table */ + lua_insert(L, -(nup+1)); /* move library table to below upvalues */ + } + for (; l->name; l++) { + int i; + for (i=0; ifunc, nup); + lua_setfield(L, -(nup+2), l->name); + } + lua_pop(L, nup); /* remove upvalues */ +} + + + +/* +** {====================================================== +** getn-setn: size for arrays +** ======================================================= +*/ + +#if defined(LUA_COMPAT_GETN) + +static int checkint (lua_State *L, int topop) { + int n = (lua_type(L, -1) == LUA_TNUMBER) ? lua_tointeger(L, -1) : -1; + lua_pop(L, topop); + return n; +} + + +static void getsizes (lua_State *L) { + lua_getfield(L, LUA_REGISTRYINDEX, "LUA_SIZES"); + if (lua_isnil(L, -1)) { /* no `size' table? */ + lua_pop(L, 1); /* remove nil */ + lua_newtable(L); /* create it */ + lua_pushvalue(L, -1); /* `size' will be its own metatable */ + lua_setmetatable(L, -2); + lua_pushliteral(L, "kv"); + lua_setfield(L, -2, "__mode"); /* metatable(N).__mode = "kv" */ + lua_pushvalue(L, -1); + lua_setfield(L, LUA_REGISTRYINDEX, "LUA_SIZES"); /* store in register */ + } +} + + +LUALIB_API void luaL_setn (lua_State *L, int t, int n) { + t = abs_index(L, t); + lua_pushliteral(L, "n"); + lua_rawget(L, t); + if (checkint(L, 1) >= 0) { /* is there a numeric field `n'? */ + lua_pushliteral(L, "n"); /* use it */ + lua_pushinteger(L, n); + lua_rawset(L, t); + } + else { /* use `sizes' */ + getsizes(L); + lua_pushvalue(L, t); + lua_pushinteger(L, n); + lua_rawset(L, -3); /* sizes[t] = n */ + lua_pop(L, 1); /* remove `sizes' */ + } +} + + +LUALIB_API int luaL_getn (lua_State *L, int t) { + int n; + t = abs_index(L, t); + lua_pushliteral(L, "n"); /* try t.n */ + lua_rawget(L, t); + if ((n = checkint(L, 1)) >= 0) return n; + getsizes(L); /* else try sizes[t] */ + lua_pushvalue(L, t); + lua_rawget(L, -2); + if ((n = checkint(L, 2)) >= 0) return n; + return (int)lua_objlen(L, t); +} + +#endif + +/* }====================================================== */ + + + +LUALIB_API const char *luaL_gsub (lua_State *L, const char *s, const char *p, + const char *r) { + const char *wild; + size_t l = strlen(p); + luaL_Buffer b; + luaL_buffinit(L, &b); + while ((wild = strstr(s, p)) != NULL) { + luaL_addlstring(&b, s, wild - s); /* push prefix */ + luaL_addstring(&b, r); /* push replacement in place of pattern */ + s = wild + l; /* continue after `p' */ + } + luaL_addstring(&b, s); /* push last suffix */ + luaL_pushresult(&b); + return lua_tostring(L, -1); +} + + +LUALIB_API const char *luaL_findtable (lua_State *L, int idx, + const char *fname, int szhint) { + const char *e; + lua_pushvalue(L, idx); + do { + e = strchr(fname, '.'); + if (e == NULL) e = fname + strlen(fname); + lua_pushlstring(L, fname, e - fname); + lua_rawget(L, -2); + if (lua_isnil(L, -1)) { /* no such field? */ + lua_pop(L, 1); /* remove this nil */ + lua_createtable(L, 0, (*e == '.' ? 1 : szhint)); /* new table for field */ + lua_pushlstring(L, fname, e - fname); + lua_pushvalue(L, -2); + lua_settable(L, -4); /* set new table into field */ + } + else if (!lua_istable(L, -1)) { /* field has a non-table value? */ + lua_pop(L, 2); /* remove table and value */ + return fname; /* return problematic part of the name */ + } + lua_remove(L, -2); /* remove previous table */ + fname = e + 1; + } while (*e == '.'); + return NULL; +} + + + +/* +** {====================================================== +** Generic Buffer manipulation +** ======================================================= +*/ + + +#define bufflen(B) ((B)->p - (B)->buffer) +#define bufffree(B) ((size_t)(LUAL_BUFFERSIZE - bufflen(B))) + +#define LIMIT (LUA_MINSTACK/2) + + +static int emptybuffer (luaL_Buffer *B) { + size_t l = bufflen(B); + if (l == 0) return 0; /* put nothing on stack */ + else { + lua_pushlstring(B->L, B->buffer, l); + B->p = B->buffer; + B->lvl++; + return 1; + } +} + + +static void adjuststack (luaL_Buffer *B) { + if (B->lvl > 1) { + lua_State *L = B->L; + int toget = 1; /* number of levels to concat */ + size_t toplen = lua_strlen(L, -1); + do { + size_t l = lua_strlen(L, -(toget+1)); + if (B->lvl - toget + 1 >= LIMIT || toplen > l) { + toplen += l; + toget++; + } + else break; + } while (toget < B->lvl); + lua_concat(L, toget); + B->lvl = B->lvl - toget + 1; + } +} + + +LUALIB_API char *luaL_prepbuffer (luaL_Buffer *B) { + if (emptybuffer(B)) + adjuststack(B); + return B->buffer; +} + + +LUALIB_API void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l) { + while (l--) + luaL_addchar(B, *s++); +} + + +LUALIB_API void luaL_addstring (luaL_Buffer *B, const char *s) { + luaL_addlstring(B, s, strlen(s)); +} + + +LUALIB_API void luaL_pushresult (luaL_Buffer *B) { + emptybuffer(B); + lua_concat(B->L, B->lvl); + B->lvl = 1; +} + + +LUALIB_API void luaL_addvalue (luaL_Buffer *B) { + lua_State *L = B->L; + size_t vl; + const char *s = lua_tolstring(L, -1, &vl); + if (vl <= bufffree(B)) { /* fit into buffer? */ + memcpy(B->p, s, vl); /* put it there */ + B->p += vl; + lua_pop(L, 1); /* remove from stack */ + } + else { + if (emptybuffer(B)) + lua_insert(L, -2); /* put buffer before new value */ + B->lvl++; /* add new value into B stack */ + adjuststack(B); + } +} + + +LUALIB_API void luaL_buffinit (lua_State *L, luaL_Buffer *B) { + B->L = L; + B->p = B->buffer; + B->lvl = 0; +} + +/* }====================================================== */ + + +LUALIB_API int luaL_ref (lua_State *L, int t) { + int ref; + t = abs_index(L, t); + if (lua_isnil(L, -1)) { + lua_pop(L, 1); /* remove from stack */ + return LUA_REFNIL; /* `nil' has a unique fixed reference */ + } + lua_rawgeti(L, t, FREELIST_REF); /* get first free element */ + ref = (int)lua_tointeger(L, -1); /* ref = t[FREELIST_REF] */ + lua_pop(L, 1); /* remove it from stack */ + if (ref != 0) { /* any free element? */ + lua_rawgeti(L, t, ref); /* remove it from list */ + lua_rawseti(L, t, FREELIST_REF); /* (t[FREELIST_REF] = t[ref]) */ + } + else { /* no free elements */ + ref = (int)lua_objlen(L, t); + ref++; /* create new reference */ + } + lua_rawseti(L, t, ref); + return ref; +} + + +LUALIB_API void luaL_unref (lua_State *L, int t, int ref) { + if (ref >= 0) { + t = abs_index(L, t); + lua_rawgeti(L, t, FREELIST_REF); + lua_rawseti(L, t, ref); /* t[ref] = t[FREELIST_REF] */ + lua_pushinteger(L, ref); + lua_rawseti(L, t, FREELIST_REF); /* t[FREELIST_REF] = ref */ + } +} + + + +/* +** {====================================================== +** Load functions +** ======================================================= +*/ + +typedef struct LoadF { + int extraline; + FILE *f; + char buff[LUAL_BUFFERSIZE]; +} LoadF; + + +static const char *getF (lua_State *L, void *ud, size_t *size) { + LoadF *lf = (LoadF *)ud; + (void)L; + if (lf->extraline) { + lf->extraline = 0; + *size = 1; + return "\n"; + } + if (feof(lf->f)) return NULL; + *size = fread(lf->buff, 1, sizeof(lf->buff), lf->f); + return (*size > 0) ? lf->buff : NULL; +} + + +static int errfile (lua_State *L, const char *what, int fnameindex) { + const char *serr = strerror(errno); + const char *filename = lua_tostring(L, fnameindex) + 1; + lua_pushfstring(L, "cannot %s %s: %s", what, filename, serr); + lua_remove(L, fnameindex); + return LUA_ERRFILE; +} + + +LUALIB_API int luaL_loadfile (lua_State *L, const char *filename) { + LoadF lf; + int status, readstatus; + int c; + int fnameindex = lua_gettop(L) + 1; /* index of filename on the stack */ + lf.extraline = 0; + if (filename == NULL) { + lua_pushliteral(L, "=stdin"); + lf.f = stdin; + } + else { + lua_pushfstring(L, "@%s", filename); + lf.f = fopen(filename, "r"); + if (lf.f == NULL) return errfile(L, "open", fnameindex); + } + c = getc(lf.f); + if (c == '#') { /* Unix exec. file? */ + lf.extraline = 1; + while ((c = getc(lf.f)) != EOF && c != '\n') ; /* skip first line */ + if (c == '\n') c = getc(lf.f); + } + if (c == LUA_SIGNATURE[0] && filename) { /* binary file? */ + lf.f = freopen(filename, "rb", lf.f); /* reopen in binary mode */ + if (lf.f == NULL) return errfile(L, "reopen", fnameindex); + /* skip eventual `#!...' */ + while ((c = getc(lf.f)) != EOF && c != LUA_SIGNATURE[0]) ; + lf.extraline = 0; + } + ungetc(c, lf.f); + status = lua_load(L, getF, &lf, lua_tostring(L, -1)); + readstatus = ferror(lf.f); + if (filename) fclose(lf.f); /* close file (even in case of errors) */ + if (readstatus) { + lua_settop(L, fnameindex); /* ignore results from `lua_load' */ + return errfile(L, "read", fnameindex); + } + lua_remove(L, fnameindex); + return status; +} + + +typedef struct LoadS { + const char *s; + size_t size; +} LoadS; + + +static const char *getS (lua_State *L, void *ud, size_t *size) { + LoadS *ls = (LoadS *)ud; + (void)L; + if (ls->size == 0) return NULL; + *size = ls->size; + ls->size = 0; + return ls->s; +} + + +LUALIB_API int luaL_loadbuffer (lua_State *L, const char *buff, size_t size, + const char *name) { + LoadS ls; + ls.s = buff; + ls.size = size; + return lua_load(L, getS, &ls, name); +} + + +LUALIB_API int (luaL_loadstring) (lua_State *L, const char *s) { + return luaL_loadbuffer(L, s, strlen(s), s); +} + + + +/* }====================================================== */ + + +static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) { + (void)ud; + (void)osize; + if (nsize == 0) { + free(ptr); + return NULL; + } + else + return realloc(ptr, nsize); +} + + +static int panic (lua_State *L) { + (void)L; /* to avoid warnings */ + fprintf(stderr, "PANIC: unprotected error in call to Lua API (%s)\n", + lua_tostring(L, -1)); + return 0; +} + + +LUALIB_API lua_State *luaL_newstate (void) { + lua_State *L = lua_newstate(l_alloc, NULL); + if (L) lua_atpanic(L, &panic); + return L; +} + diff --git a/IOS/lua/lua/lauxlib.h b/IOS/lua/lua/lauxlib.h new file mode 100644 index 00000000..34258235 --- /dev/null +++ b/IOS/lua/lua/lauxlib.h @@ -0,0 +1,174 @@ +/* +** $Id: lauxlib.h,v 1.88.1.1 2007/12/27 13:02:25 roberto Exp $ +** Auxiliary functions for building Lua libraries +** See Copyright Notice in lua.h +*/ + + +#ifndef lauxlib_h +#define lauxlib_h + + +#include +#include + +#include "lua.h" + + +#if defined(LUA_COMPAT_GETN) +LUALIB_API int (luaL_getn) (lua_State *L, int t); +LUALIB_API void (luaL_setn) (lua_State *L, int t, int n); +#else +#define luaL_getn(L,i) ((int)lua_objlen(L, i)) +#define luaL_setn(L,i,j) ((void)0) /* no op! */ +#endif + +#if defined(LUA_COMPAT_OPENLIB) +#define luaI_openlib luaL_openlib +#endif + + +/* extra error code for `luaL_load' */ +#define LUA_ERRFILE (LUA_ERRERR+1) + + +typedef struct luaL_Reg { + const char *name; + lua_CFunction func; +} luaL_Reg; + + + +LUALIB_API void (luaI_openlib) (lua_State *L, const char *libname, + const luaL_Reg *l, int nup); +LUALIB_API void (luaL_register) (lua_State *L, const char *libname, + const luaL_Reg *l); +LUALIB_API int (luaL_getmetafield) (lua_State *L, int obj, const char *e); +LUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e); +LUALIB_API int (luaL_typerror) (lua_State *L, int narg, const char *tname); +LUALIB_API int (luaL_argerror) (lua_State *L, int numarg, const char *extramsg); +LUALIB_API const char *(luaL_checklstring) (lua_State *L, int numArg, + size_t *l); +LUALIB_API const char *(luaL_optlstring) (lua_State *L, int numArg, + const char *def, size_t *l); +LUALIB_API lua_Number (luaL_checknumber) (lua_State *L, int numArg); +LUALIB_API lua_Number (luaL_optnumber) (lua_State *L, int nArg, lua_Number def); + +LUALIB_API lua_Integer (luaL_checkinteger) (lua_State *L, int numArg); +LUALIB_API lua_Integer (luaL_optinteger) (lua_State *L, int nArg, + lua_Integer def); + +LUALIB_API void (luaL_checkstack) (lua_State *L, int sz, const char *msg); +LUALIB_API void (luaL_checktype) (lua_State *L, int narg, int t); +LUALIB_API void (luaL_checkany) (lua_State *L, int narg); + +LUALIB_API int (luaL_newmetatable) (lua_State *L, const char *tname); +LUALIB_API void *(luaL_checkudata) (lua_State *L, int ud, const char *tname); + +LUALIB_API void (luaL_where) (lua_State *L, int lvl); +LUALIB_API int (luaL_error) (lua_State *L, const char *fmt, ...); + +LUALIB_API int (luaL_checkoption) (lua_State *L, int narg, const char *def, + const char *const lst[]); + +LUALIB_API int (luaL_ref) (lua_State *L, int t); +LUALIB_API void (luaL_unref) (lua_State *L, int t, int ref); + +LUALIB_API int (luaL_loadfile) (lua_State *L, const char *filename); +LUALIB_API int (luaL_loadbuffer) (lua_State *L, const char *buff, size_t sz, + const char *name); +LUALIB_API int (luaL_loadstring) (lua_State *L, const char *s); + +LUALIB_API lua_State *(luaL_newstate) (void); + + +LUALIB_API const char *(luaL_gsub) (lua_State *L, const char *s, const char *p, + const char *r); + +LUALIB_API const char *(luaL_findtable) (lua_State *L, int idx, + const char *fname, int szhint); + + + + +/* +** =============================================================== +** some useful macros +** =============================================================== +*/ + +#define luaL_argcheck(L, cond,numarg,extramsg) \ + ((void)((cond) || luaL_argerror(L, (numarg), (extramsg)))) +#define luaL_checkstring(L,n) (luaL_checklstring(L, (n), NULL)) +#define luaL_optstring(L,n,d) (luaL_optlstring(L, (n), (d), NULL)) +#define luaL_checkint(L,n) ((int)luaL_checkinteger(L, (n))) +#define luaL_optint(L,n,d) ((int)luaL_optinteger(L, (n), (d))) +#define luaL_checklong(L,n) ((long)luaL_checkinteger(L, (n))) +#define luaL_optlong(L,n,d) ((long)luaL_optinteger(L, (n), (d))) + +#define luaL_typename(L,i) lua_typename(L, lua_type(L,(i))) + +#define luaL_dofile(L, fn) \ + (luaL_loadfile(L, fn) || lua_pcall(L, 0, LUA_MULTRET, 0)) + +#define luaL_dostring(L, s) \ + (luaL_loadstring(L, s) || lua_pcall(L, 0, LUA_MULTRET, 0)) + +#define luaL_getmetatable(L,n) (lua_getfield(L, LUA_REGISTRYINDEX, (n))) + +#define luaL_opt(L,f,n,d) (lua_isnoneornil(L,(n)) ? (d) : f(L,(n))) + +/* +** {====================================================== +** Generic Buffer manipulation +** ======================================================= +*/ + + + +typedef struct luaL_Buffer { + char *p; /* current position in buffer */ + int lvl; /* number of strings in the stack (level) */ + lua_State *L; + char buffer[LUAL_BUFFERSIZE]; +} luaL_Buffer; + +#define luaL_addchar(B,c) \ + ((void)((B)->p < ((B)->buffer+LUAL_BUFFERSIZE) || luaL_prepbuffer(B)), \ + (*(B)->p++ = (char)(c))) + +/* compatibility only */ +#define luaL_putchar(B,c) luaL_addchar(B,c) + +#define luaL_addsize(B,n) ((B)->p += (n)) + +LUALIB_API void (luaL_buffinit) (lua_State *L, luaL_Buffer *B); +LUALIB_API char *(luaL_prepbuffer) (luaL_Buffer *B); +LUALIB_API void (luaL_addlstring) (luaL_Buffer *B, const char *s, size_t l); +LUALIB_API void (luaL_addstring) (luaL_Buffer *B, const char *s); +LUALIB_API void (luaL_addvalue) (luaL_Buffer *B); +LUALIB_API void (luaL_pushresult) (luaL_Buffer *B); + + +/* }====================================================== */ + + +/* compatibility with ref system */ + +/* pre-defined references */ +#define LUA_NOREF (-2) +#define LUA_REFNIL (-1) + +#define lua_ref(L,lock) ((lock) ? luaL_ref(L, LUA_REGISTRYINDEX) : \ + (lua_pushstring(L, "unlocked references are obsolete"), lua_error(L), 0)) + +#define lua_unref(L,ref) luaL_unref(L, LUA_REGISTRYINDEX, (ref)) + +#define lua_getref(L,ref) lua_rawgeti(L, LUA_REGISTRYINDEX, (ref)) + + +#define luaL_reg luaL_Reg + +#endif + + diff --git a/IOS/lua/lua/lbaselib.c b/IOS/lua/lua/lbaselib.c new file mode 100644 index 00000000..2a4c079d --- /dev/null +++ b/IOS/lua/lua/lbaselib.c @@ -0,0 +1,653 @@ +/* +** $Id: lbaselib.c,v 1.191.1.6 2008/02/14 16:46:22 roberto Exp $ +** Basic library +** See Copyright Notice in lua.h +*/ + + + +#include +#include +#include +#include + +#define lbaselib_c +#define LUA_LIB + +#include "lua.h" + +#include "lauxlib.h" +#include "lualib.h" + + + + +/* +** If your system does not support `stdout', you can just remove this function. +** If you need, you can define your own `print' function, following this +** model but changing `fputs' to put the strings at a proper place +** (a console window or a log file, for instance). +*/ +static int luaB_print (lua_State *L) { + int n = lua_gettop(L); /* number of arguments */ + int i; + lua_getglobal(L, "tostring"); + for (i=1; i<=n; i++) { + const char *s; + lua_pushvalue(L, -1); /* function to be called */ + lua_pushvalue(L, i); /* value to print */ + lua_call(L, 1, 1); + s = lua_tostring(L, -1); /* get result */ + if (s == NULL) + return luaL_error(L, LUA_QL("tostring") " must return a string to " + LUA_QL("print")); + if (i>1) fputs("\t", stdout); + fputs(s, stdout); + lua_pop(L, 1); /* pop result */ + } + fputs("\n", stdout); + return 0; +} + + +static int luaB_tonumber (lua_State *L) { + int base = luaL_optint(L, 2, 10); + if (base == 10) { /* standard conversion */ + luaL_checkany(L, 1); + if (lua_isnumber(L, 1)) { + lua_pushnumber(L, lua_tonumber(L, 1)); + return 1; + } + } + else { + const char *s1 = luaL_checkstring(L, 1); + char *s2; + unsigned long n; + luaL_argcheck(L, 2 <= base && base <= 36, 2, "base out of range"); + n = strtoul(s1, &s2, base); + if (s1 != s2) { /* at least one valid digit? */ + while (isspace((unsigned char)(*s2))) s2++; /* skip trailing spaces */ + if (*s2 == '\0') { /* no invalid trailing characters? */ + lua_pushnumber(L, (lua_Number)n); + return 1; + } + } + } + lua_pushnil(L); /* else not a number */ + return 1; +} + + +static int luaB_error (lua_State *L) { + int level = luaL_optint(L, 2, 1); + lua_settop(L, 1); + if (lua_isstring(L, 1) && level > 0) { /* add extra information? */ + luaL_where(L, level); + lua_pushvalue(L, 1); + lua_concat(L, 2); + } + return lua_error(L); +} + + +static int luaB_getmetatable (lua_State *L) { + luaL_checkany(L, 1); + if (!lua_getmetatable(L, 1)) { + lua_pushnil(L); + return 1; /* no metatable */ + } + luaL_getmetafield(L, 1, "__metatable"); + return 1; /* returns either __metatable field (if present) or metatable */ +} + + +static int luaB_setmetatable (lua_State *L) { + int t = lua_type(L, 2); + luaL_checktype(L, 1, LUA_TTABLE); + luaL_argcheck(L, t == LUA_TNIL || t == LUA_TTABLE, 2, + "nil or table expected"); + if (luaL_getmetafield(L, 1, "__metatable")) + luaL_error(L, "cannot change a protected metatable"); + lua_settop(L, 2); + lua_setmetatable(L, 1); + return 1; +} + + +static void getfunc (lua_State *L, int opt) { + if (lua_isfunction(L, 1)) lua_pushvalue(L, 1); + else { + lua_Debug ar; + int level = opt ? luaL_optint(L, 1, 1) : luaL_checkint(L, 1); + luaL_argcheck(L, level >= 0, 1, "level must be non-negative"); + if (lua_getstack(L, level, &ar) == 0) + luaL_argerror(L, 1, "invalid level"); + lua_getinfo(L, "f", &ar); + if (lua_isnil(L, -1)) + luaL_error(L, "no function environment for tail call at level %d", + level); + } +} + + +static int luaB_getfenv (lua_State *L) { + getfunc(L, 1); + if (lua_iscfunction(L, -1)) /* is a C function? */ + lua_pushvalue(L, LUA_GLOBALSINDEX); /* return the thread's global env. */ + else + lua_getfenv(L, -1); + return 1; +} + + +static int luaB_setfenv (lua_State *L) { + luaL_checktype(L, 2, LUA_TTABLE); + getfunc(L, 0); + lua_pushvalue(L, 2); + if (lua_isnumber(L, 1) && lua_tonumber(L, 1) == 0) { + /* change environment of current thread */ + lua_pushthread(L); + lua_insert(L, -2); + lua_setfenv(L, -2); + return 0; + } + else if (lua_iscfunction(L, -2) || lua_setfenv(L, -2) == 0) + luaL_error(L, + LUA_QL("setfenv") " cannot change environment of given object"); + return 1; +} + + +static int luaB_rawequal (lua_State *L) { + luaL_checkany(L, 1); + luaL_checkany(L, 2); + lua_pushboolean(L, lua_rawequal(L, 1, 2)); + return 1; +} + + +static int luaB_rawget (lua_State *L) { + luaL_checktype(L, 1, LUA_TTABLE); + luaL_checkany(L, 2); + lua_settop(L, 2); + lua_rawget(L, 1); + return 1; +} + +static int luaB_rawset (lua_State *L) { + luaL_checktype(L, 1, LUA_TTABLE); + luaL_checkany(L, 2); + luaL_checkany(L, 3); + lua_settop(L, 3); + lua_rawset(L, 1); + return 1; +} + + +static int luaB_gcinfo (lua_State *L) { + lua_pushinteger(L, lua_getgccount(L)); + return 1; +} + + +static int luaB_collectgarbage (lua_State *L) { + static const char *const opts[] = {"stop", "restart", "collect", + "count", "step", "setpause", "setstepmul", NULL}; + static const int optsnum[] = {LUA_GCSTOP, LUA_GCRESTART, LUA_GCCOLLECT, + LUA_GCCOUNT, LUA_GCSTEP, LUA_GCSETPAUSE, LUA_GCSETSTEPMUL}; + int o = luaL_checkoption(L, 1, "collect", opts); + int ex = luaL_optint(L, 2, 0); + int res = lua_gc(L, optsnum[o], ex); + switch (optsnum[o]) { + case LUA_GCCOUNT: { + int b = lua_gc(L, LUA_GCCOUNTB, 0); + lua_pushnumber(L, res + ((lua_Number)b/1024)); + return 1; + } + case LUA_GCSTEP: { + lua_pushboolean(L, res); + return 1; + } + default: { + lua_pushnumber(L, res); + return 1; + } + } +} + + +static int luaB_type (lua_State *L) { + luaL_checkany(L, 1); + lua_pushstring(L, luaL_typename(L, 1)); + return 1; +} + + +static int luaB_next (lua_State *L) { + luaL_checktype(L, 1, LUA_TTABLE); + lua_settop(L, 2); /* create a 2nd argument if there isn't one */ + if (lua_next(L, 1)) + return 2; + else { + lua_pushnil(L); + return 1; + } +} + + +static int luaB_pairs (lua_State *L) { + luaL_checktype(L, 1, LUA_TTABLE); + lua_pushvalue(L, lua_upvalueindex(1)); /* return generator, */ + lua_pushvalue(L, 1); /* state, */ + lua_pushnil(L); /* and initial value */ + return 3; +} + + +static int ipairsaux (lua_State *L) { + int i = luaL_checkint(L, 2); + luaL_checktype(L, 1, LUA_TTABLE); + i++; /* next value */ + lua_pushinteger(L, i); + lua_rawgeti(L, 1, i); + return (lua_isnil(L, -1)) ? 0 : 2; +} + + +static int luaB_ipairs (lua_State *L) { + luaL_checktype(L, 1, LUA_TTABLE); + lua_pushvalue(L, lua_upvalueindex(1)); /* return generator, */ + lua_pushvalue(L, 1); /* state, */ + lua_pushinteger(L, 0); /* and initial value */ + return 3; +} + + +static int load_aux (lua_State *L, int status) { + if (status == 0) /* OK? */ + return 1; + else { + lua_pushnil(L); + lua_insert(L, -2); /* put before error message */ + return 2; /* return nil plus error message */ + } +} + + +static int luaB_loadstring (lua_State *L) { + size_t l; + const char *s = luaL_checklstring(L, 1, &l); + const char *chunkname = luaL_optstring(L, 2, s); + return load_aux(L, luaL_loadbuffer(L, s, l, chunkname)); +} + + +static int luaB_loadfile (lua_State *L) { + const char *fname = luaL_optstring(L, 1, NULL); + return load_aux(L, luaL_loadfile(L, fname)); +} + + +/* +** Reader for generic `load' function: `lua_load' uses the +** stack for internal stuff, so the reader cannot change the +** stack top. Instead, it keeps its resulting string in a +** reserved slot inside the stack. +*/ +static const char *generic_reader (lua_State *L, void *ud, size_t *size) { + (void)ud; /* to avoid warnings */ + luaL_checkstack(L, 2, "too many nested functions"); + lua_pushvalue(L, 1); /* get function */ + lua_call(L, 0, 1); /* call it */ + if (lua_isnil(L, -1)) { + *size = 0; + return NULL; + } + else if (lua_isstring(L, -1)) { + lua_replace(L, 3); /* save string in a reserved stack slot */ + return lua_tolstring(L, 3, size); + } + else luaL_error(L, "reader function must return a string"); + return NULL; /* to avoid warnings */ +} + + +static int luaB_load (lua_State *L) { + int status; + const char *cname = luaL_optstring(L, 2, "=(load)"); + luaL_checktype(L, 1, LUA_TFUNCTION); + lua_settop(L, 3); /* function, eventual name, plus one reserved slot */ + status = lua_load(L, generic_reader, NULL, cname); + return load_aux(L, status); +} + + +static int luaB_dofile (lua_State *L) { + const char *fname = luaL_optstring(L, 1, NULL); + int n = lua_gettop(L); + if (luaL_loadfile(L, fname) != 0) lua_error(L); + lua_call(L, 0, LUA_MULTRET); + return lua_gettop(L) - n; +} + + +static int luaB_assert (lua_State *L) { + luaL_checkany(L, 1); + if (!lua_toboolean(L, 1)) + return luaL_error(L, "%s", luaL_optstring(L, 2, "assertion failed!")); + return lua_gettop(L); +} + + +static int luaB_unpack (lua_State *L) { + int i, e, n; + luaL_checktype(L, 1, LUA_TTABLE); + i = luaL_optint(L, 2, 1); + e = luaL_opt(L, luaL_checkint, 3, luaL_getn(L, 1)); + if (i > e) return 0; /* empty range */ + n = e - i + 1; /* number of elements */ + if (n <= 0 || !lua_checkstack(L, n)) /* n <= 0 means arith. overflow */ + return luaL_error(L, "too many results to unpack"); + lua_rawgeti(L, 1, i); /* push arg[i] (avoiding overflow problems) */ + while (i++ < e) /* push arg[i + 1...e] */ + lua_rawgeti(L, 1, i); + return n; +} + + +static int luaB_select (lua_State *L) { + int n = lua_gettop(L); + if (lua_type(L, 1) == LUA_TSTRING && *lua_tostring(L, 1) == '#') { + lua_pushinteger(L, n-1); + return 1; + } + else { + int i = luaL_checkint(L, 1); + if (i < 0) i = n + i; + else if (i > n) i = n; + luaL_argcheck(L, 1 <= i, 1, "index out of range"); + return n - i; + } +} + + +static int luaB_pcall (lua_State *L) { + int status; + luaL_checkany(L, 1); + status = lua_pcall(L, lua_gettop(L) - 1, LUA_MULTRET, 0); + lua_pushboolean(L, (status == 0)); + lua_insert(L, 1); + return lua_gettop(L); /* return status + all results */ +} + + +static int luaB_xpcall (lua_State *L) { + int status; + luaL_checkany(L, 2); + lua_settop(L, 2); + lua_insert(L, 1); /* put error function under function to be called */ + status = lua_pcall(L, 0, LUA_MULTRET, 1); + lua_pushboolean(L, (status == 0)); + lua_replace(L, 1); + return lua_gettop(L); /* return status + all results */ +} + + +static int luaB_tostring (lua_State *L) { + luaL_checkany(L, 1); + if (luaL_callmeta(L, 1, "__tostring")) /* is there a metafield? */ + return 1; /* use its value */ + switch (lua_type(L, 1)) { + case LUA_TNUMBER: + lua_pushstring(L, lua_tostring(L, 1)); + break; + case LUA_TSTRING: + lua_pushvalue(L, 1); + break; + case LUA_TBOOLEAN: + lua_pushstring(L, (lua_toboolean(L, 1) ? "true" : "false")); + break; + case LUA_TNIL: + lua_pushliteral(L, "nil"); + break; + default: + lua_pushfstring(L, "%s: %p", luaL_typename(L, 1), lua_topointer(L, 1)); + break; + } + return 1; +} + + +static int luaB_newproxy (lua_State *L) { + lua_settop(L, 1); + lua_newuserdata(L, 0); /* create proxy */ + if (lua_toboolean(L, 1) == 0) + return 1; /* no metatable */ + else if (lua_isboolean(L, 1)) { + lua_newtable(L); /* create a new metatable `m' ... */ + lua_pushvalue(L, -1); /* ... and mark `m' as a valid metatable */ + lua_pushboolean(L, 1); + lua_rawset(L, lua_upvalueindex(1)); /* weaktable[m] = true */ + } + else { + int validproxy = 0; /* to check if weaktable[metatable(u)] == true */ + if (lua_getmetatable(L, 1)) { + lua_rawget(L, lua_upvalueindex(1)); + validproxy = lua_toboolean(L, -1); + lua_pop(L, 1); /* remove value */ + } + luaL_argcheck(L, validproxy, 1, "boolean or proxy expected"); + lua_getmetatable(L, 1); /* metatable is valid; get it */ + } + lua_setmetatable(L, 2); + return 1; +} + + +static const luaL_Reg base_funcs[] = { + {"assert", luaB_assert}, + {"collectgarbage", luaB_collectgarbage}, + {"dofile", luaB_dofile}, + {"error", luaB_error}, + {"gcinfo", luaB_gcinfo}, + {"getfenv", luaB_getfenv}, + {"getmetatable", luaB_getmetatable}, + {"loadfile", luaB_loadfile}, + {"load", luaB_load}, + {"loadstring", luaB_loadstring}, + {"next", luaB_next}, + {"pcall", luaB_pcall}, + {"print", luaB_print}, + {"rawequal", luaB_rawequal}, + {"rawget", luaB_rawget}, + {"rawset", luaB_rawset}, + {"select", luaB_select}, + {"setfenv", luaB_setfenv}, + {"setmetatable", luaB_setmetatable}, + {"tonumber", luaB_tonumber}, + {"tostring", luaB_tostring}, + {"type", luaB_type}, + {"unpack", luaB_unpack}, + {"xpcall", luaB_xpcall}, + {NULL, NULL} +}; + + +/* +** {====================================================== +** Coroutine library +** ======================================================= +*/ + +#define CO_RUN 0 /* running */ +#define CO_SUS 1 /* suspended */ +#define CO_NOR 2 /* 'normal' (it resumed another coroutine) */ +#define CO_DEAD 3 + +static const char *const statnames[] = + {"running", "suspended", "normal", "dead"}; + +static int costatus (lua_State *L, lua_State *co) { + if (L == co) return CO_RUN; + switch (lua_status(co)) { + case LUA_YIELD: + return CO_SUS; + case 0: { + lua_Debug ar; + if (lua_getstack(co, 0, &ar) > 0) /* does it have frames? */ + return CO_NOR; /* it is running */ + else if (lua_gettop(co) == 0) + return CO_DEAD; + else + return CO_SUS; /* initial state */ + } + default: /* some error occured */ + return CO_DEAD; + } +} + + +static int luaB_costatus (lua_State *L) { + lua_State *co = lua_tothread(L, 1); + luaL_argcheck(L, co, 1, "coroutine expected"); + lua_pushstring(L, statnames[costatus(L, co)]); + return 1; +} + + +static int auxresume (lua_State *L, lua_State *co, int narg) { + int status = costatus(L, co); + if (!lua_checkstack(co, narg)) + luaL_error(L, "too many arguments to resume"); + if (status != CO_SUS) { + lua_pushfstring(L, "cannot resume %s coroutine", statnames[status]); + return -1; /* error flag */ + } + lua_xmove(L, co, narg); + lua_setlevel(L, co); + status = lua_resume(co, narg); + if (status == 0 || status == LUA_YIELD) { + int nres = lua_gettop(co); + if (!lua_checkstack(L, nres + 1)) + luaL_error(L, "too many results to resume"); + lua_xmove(co, L, nres); /* move yielded values */ + return nres; + } + else { + lua_xmove(co, L, 1); /* move error message */ + return -1; /* error flag */ + } +} + + +static int luaB_coresume (lua_State *L) { + lua_State *co = lua_tothread(L, 1); + int r; + luaL_argcheck(L, co, 1, "coroutine expected"); + r = auxresume(L, co, lua_gettop(L) - 1); + if (r < 0) { + lua_pushboolean(L, 0); + lua_insert(L, -2); + return 2; /* return false + error message */ + } + else { + lua_pushboolean(L, 1); + lua_insert(L, -(r + 1)); + return r + 1; /* return true + `resume' returns */ + } +} + + +static int luaB_auxwrap (lua_State *L) { + lua_State *co = lua_tothread(L, lua_upvalueindex(1)); + int r = auxresume(L, co, lua_gettop(L)); + if (r < 0) { + if (lua_isstring(L, -1)) { /* error object is a string? */ + luaL_where(L, 1); /* add extra info */ + lua_insert(L, -2); + lua_concat(L, 2); + } + lua_error(L); /* propagate error */ + } + return r; +} + + +static int luaB_cocreate (lua_State *L) { + lua_State *NL = lua_newthread(L); + luaL_argcheck(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), 1, + "Lua function expected"); + lua_pushvalue(L, 1); /* move function to top */ + lua_xmove(L, NL, 1); /* move function from L to NL */ + return 1; +} + + +static int luaB_cowrap (lua_State *L) { + luaB_cocreate(L); + lua_pushcclosure(L, luaB_auxwrap, 1); + return 1; +} + + +static int luaB_yield (lua_State *L) { + return lua_yield(L, lua_gettop(L)); +} + + +static int luaB_corunning (lua_State *L) { + if (lua_pushthread(L)) + lua_pushnil(L); /* main thread is not a coroutine */ + return 1; +} + + +static const luaL_Reg co_funcs[] = { + {"create", luaB_cocreate}, + {"resume", luaB_coresume}, + {"running", luaB_corunning}, + {"status", luaB_costatus}, + {"wrap", luaB_cowrap}, + {"yield", luaB_yield}, + {NULL, NULL} +}; + +/* }====================================================== */ + + +static void auxopen (lua_State *L, const char *name, + lua_CFunction f, lua_CFunction u) { + lua_pushcfunction(L, u); + lua_pushcclosure(L, f, 1); + lua_setfield(L, -2, name); +} + + +static void base_open (lua_State *L) { + /* set global _G */ + lua_pushvalue(L, LUA_GLOBALSINDEX); + lua_setglobal(L, "_G"); + /* open lib into global table */ + luaL_register(L, "_G", base_funcs); + lua_pushliteral(L, LUA_VERSION); + lua_setglobal(L, "_VERSION"); /* set global _VERSION */ + /* `ipairs' and `pairs' need auxliliary functions as upvalues */ + auxopen(L, "ipairs", luaB_ipairs, ipairsaux); + auxopen(L, "pairs", luaB_pairs, luaB_next); + /* `newproxy' needs a weaktable as upvalue */ + lua_createtable(L, 0, 1); /* new table `w' */ + lua_pushvalue(L, -1); /* `w' will be its own metatable */ + lua_setmetatable(L, -2); + lua_pushliteral(L, "kv"); + lua_setfield(L, -2, "__mode"); /* metatable(w).__mode = "kv" */ + lua_pushcclosure(L, luaB_newproxy, 1); + lua_setglobal(L, "newproxy"); /* set global `newproxy' */ +} + + +LUALIB_API int luaopen_base (lua_State *L) { + base_open(L); + luaL_register(L, LUA_COLIBNAME, co_funcs); + return 2; +} + diff --git a/IOS/lua/lua/lcode.c b/IOS/lua/lua/lcode.c new file mode 100644 index 00000000..cff626b7 --- /dev/null +++ b/IOS/lua/lua/lcode.c @@ -0,0 +1,839 @@ +/* +** $Id: lcode.c,v 2.25.1.3 2007/12/28 15:32:23 roberto Exp $ +** Code generator for Lua +** See Copyright Notice in lua.h +*/ + + +#include + +#define lcode_c +#define LUA_CORE + +#include "lua.h" + +#include "lcode.h" +#include "ldebug.h" +#include "ldo.h" +#include "lgc.h" +#include "llex.h" +#include "lmem.h" +#include "lobject.h" +#include "lopcodes.h" +#include "lparser.h" +#include "ltable.h" + + +#define hasjumps(e) ((e)->t != (e)->f) + + +static int isnumeral(expdesc *e) { + return (e->k == VKNUM && e->t == NO_JUMP && e->f == NO_JUMP); +} + + +void luaK_nil (FuncState *fs, int from, int n) { + Instruction *previous; + if (fs->pc > fs->lasttarget) { /* no jumps to current position? */ + if (fs->pc == 0) { /* function start? */ + if (from >= fs->nactvar) + return; /* positions are already clean */ + } + else { + previous = &fs->f->code[fs->pc-1]; + if (GET_OPCODE(*previous) == OP_LOADNIL) { + int pfrom = GETARG_A(*previous); + int pto = GETARG_B(*previous); + if (pfrom <= from && from <= pto+1) { /* can connect both? */ + if (from+n-1 > pto) + SETARG_B(*previous, from+n-1); + return; + } + } + } + } + luaK_codeABC(fs, OP_LOADNIL, from, from+n-1, 0); /* else no optimization */ +} + + +int luaK_jump (FuncState *fs) { + int jpc = fs->jpc; /* save list of jumps to here */ + int j; + fs->jpc = NO_JUMP; + j = luaK_codeAsBx(fs, OP_JMP, 0, NO_JUMP); + luaK_concat(fs, &j, jpc); /* keep them on hold */ + return j; +} + + +void luaK_ret (FuncState *fs, int first, int nret) { + luaK_codeABC(fs, OP_RETURN, first, nret+1, 0); +} + + +static int condjump (FuncState *fs, OpCode op, int A, int B, int C) { + luaK_codeABC(fs, op, A, B, C); + return luaK_jump(fs); +} + + +static void fixjump (FuncState *fs, int pc, int dest) { + Instruction *jmp = &fs->f->code[pc]; + int offset = dest-(pc+1); + lua_assert(dest != NO_JUMP); + if (abs(offset) > MAXARG_sBx) + luaX_syntaxerror(fs->ls, "control structure too long"); + SETARG_sBx(*jmp, offset); +} + + +/* +** returns current `pc' and marks it as a jump target (to avoid wrong +** optimizations with consecutive instructions not in the same basic block). +*/ +int luaK_getlabel (FuncState *fs) { + fs->lasttarget = fs->pc; + return fs->pc; +} + + +static int getjump (FuncState *fs, int pc) { + int offset = GETARG_sBx(fs->f->code[pc]); + if (offset == NO_JUMP) /* point to itself represents end of list */ + return NO_JUMP; /* end of list */ + else + return (pc+1)+offset; /* turn offset into absolute position */ +} + + +static Instruction *getjumpcontrol (FuncState *fs, int pc) { + Instruction *pi = &fs->f->code[pc]; + if (pc >= 1 && testTMode(GET_OPCODE(*(pi-1)))) + return pi-1; + else + return pi; +} + + +/* +** check whether list has any jump that do not produce a value +** (or produce an inverted value) +*/ +static int need_value (FuncState *fs, int list) { + for (; list != NO_JUMP; list = getjump(fs, list)) { + Instruction i = *getjumpcontrol(fs, list); + if (GET_OPCODE(i) != OP_TESTSET) return 1; + } + return 0; /* not found */ +} + + +static int patchtestreg (FuncState *fs, int node, int reg) { + Instruction *i = getjumpcontrol(fs, node); + if (GET_OPCODE(*i) != OP_TESTSET) + return 0; /* cannot patch other instructions */ + if (reg != NO_REG && reg != GETARG_B(*i)) + SETARG_A(*i, reg); + else /* no register to put value or register already has the value */ + *i = CREATE_ABC(OP_TEST, GETARG_B(*i), 0, GETARG_C(*i)); + + return 1; +} + + +static void removevalues (FuncState *fs, int list) { + for (; list != NO_JUMP; list = getjump(fs, list)) + patchtestreg(fs, list, NO_REG); +} + + +static void patchlistaux (FuncState *fs, int list, int vtarget, int reg, + int dtarget) { + while (list != NO_JUMP) { + int next = getjump(fs, list); + if (patchtestreg(fs, list, reg)) + fixjump(fs, list, vtarget); + else + fixjump(fs, list, dtarget); /* jump to default target */ + list = next; + } +} + + +static void dischargejpc (FuncState *fs) { + patchlistaux(fs, fs->jpc, fs->pc, NO_REG, fs->pc); + fs->jpc = NO_JUMP; +} + + +void luaK_patchlist (FuncState *fs, int list, int target) { + if (target == fs->pc) + luaK_patchtohere(fs, list); + else { + lua_assert(target < fs->pc); + patchlistaux(fs, list, target, NO_REG, target); + } +} + + +void luaK_patchtohere (FuncState *fs, int list) { + luaK_getlabel(fs); + luaK_concat(fs, &fs->jpc, list); +} + + +void luaK_concat (FuncState *fs, int *l1, int l2) { + if (l2 == NO_JUMP) return; + else if (*l1 == NO_JUMP) + *l1 = l2; + else { + int list = *l1; + int next; + while ((next = getjump(fs, list)) != NO_JUMP) /* find last element */ + list = next; + fixjump(fs, list, l2); + } +} + + +void luaK_checkstack (FuncState *fs, int n) { + int newstack = fs->freereg + n; + if (newstack > fs->f->maxstacksize) { + if (newstack >= MAXSTACK) + luaX_syntaxerror(fs->ls, "function or expression too complex"); + fs->f->maxstacksize = cast_byte(newstack); + } +} + + +void luaK_reserveregs (FuncState *fs, int n) { + luaK_checkstack(fs, n); + fs->freereg += n; +} + + +static void freereg (FuncState *fs, int reg) { + if (!ISK(reg) && reg >= fs->nactvar) { + fs->freereg--; + lua_assert(reg == fs->freereg); + } +} + + +static void freeexp (FuncState *fs, expdesc *e) { + if (e->k == VNONRELOC) + freereg(fs, e->u.s.info); +} + + +static int addk (FuncState *fs, TValue *k, TValue *v) { + lua_State *L = fs->L; + TValue *idx = luaH_set(L, fs->h, k); + Proto *f = fs->f; + int oldsize = f->sizek; + if (ttisnumber(idx)) { + lua_assert(luaO_rawequalObj(&fs->f->k[cast_int(nvalue(idx))], v)); + return cast_int(nvalue(idx)); + } + else { /* constant not found; create a new entry */ + setnvalue(idx, cast_num(fs->nk)); + luaM_growvector(L, f->k, fs->nk, f->sizek, TValue, + MAXARG_Bx, "constant table overflow"); + while (oldsize < f->sizek) setnilvalue(&f->k[oldsize++]); + setobj(L, &f->k[fs->nk], v); + luaC_barrier(L, f, v); + return fs->nk++; + } +} + + +int luaK_stringK (FuncState *fs, TString *s) { + TValue o; + setsvalue(fs->L, &o, s); + return addk(fs, &o, &o); +} + + +int luaK_numberK (FuncState *fs, lua_Number r) { + TValue o; + setnvalue(&o, r); + return addk(fs, &o, &o); +} + + +static int boolK (FuncState *fs, int b) { + TValue o; + setbvalue(&o, b); + return addk(fs, &o, &o); +} + + +static int nilK (FuncState *fs) { + TValue k, v; + setnilvalue(&v); + /* cannot use nil as key; instead use table itself to represent nil */ + sethvalue(fs->L, &k, fs->h); + return addk(fs, &k, &v); +} + + +void luaK_setreturns (FuncState *fs, expdesc *e, int nresults) { + if (e->k == VCALL) { /* expression is an open function call? */ + SETARG_C(getcode(fs, e), nresults+1); + } + else if (e->k == VVARARG) { + SETARG_B(getcode(fs, e), nresults+1); + SETARG_A(getcode(fs, e), fs->freereg); + luaK_reserveregs(fs, 1); + } +} + + +void luaK_setoneret (FuncState *fs, expdesc *e) { + if (e->k == VCALL) { /* expression is an open function call? */ + e->k = VNONRELOC; + e->u.s.info = GETARG_A(getcode(fs, e)); + } + else if (e->k == VVARARG) { + SETARG_B(getcode(fs, e), 2); + e->k = VRELOCABLE; /* can relocate its simple result */ + } +} + + +void luaK_dischargevars (FuncState *fs, expdesc *e) { + switch (e->k) { + case VLOCAL: { + e->k = VNONRELOC; + break; + } + case VUPVAL: { + e->u.s.info = luaK_codeABC(fs, OP_GETUPVAL, 0, e->u.s.info, 0); + e->k = VRELOCABLE; + break; + } + case VGLOBAL: { + e->u.s.info = luaK_codeABx(fs, OP_GETGLOBAL, 0, e->u.s.info); + e->k = VRELOCABLE; + break; + } + case VINDEXED: { + freereg(fs, e->u.s.aux); + freereg(fs, e->u.s.info); + e->u.s.info = luaK_codeABC(fs, OP_GETTABLE, 0, e->u.s.info, e->u.s.aux); + e->k = VRELOCABLE; + break; + } + case VVARARG: + case VCALL: { + luaK_setoneret(fs, e); + break; + } + default: break; /* there is one value available (somewhere) */ + } +} + + +static int code_label (FuncState *fs, int A, int b, int jump) { + luaK_getlabel(fs); /* those instructions may be jump targets */ + return luaK_codeABC(fs, OP_LOADBOOL, A, b, jump); +} + + +static void discharge2reg (FuncState *fs, expdesc *e, int reg) { + luaK_dischargevars(fs, e); + switch (e->k) { + case VNIL: { + luaK_nil(fs, reg, 1); + break; + } + case VFALSE: case VTRUE: { + luaK_codeABC(fs, OP_LOADBOOL, reg, e->k == VTRUE, 0); + break; + } + case VK: { + luaK_codeABx(fs, OP_LOADK, reg, e->u.s.info); + break; + } + case VKNUM: { + luaK_codeABx(fs, OP_LOADK, reg, luaK_numberK(fs, e->u.nval)); + break; + } + case VRELOCABLE: { + Instruction *pc = &getcode(fs, e); + SETARG_A(*pc, reg); + break; + } + case VNONRELOC: { + if (reg != e->u.s.info) + luaK_codeABC(fs, OP_MOVE, reg, e->u.s.info, 0); + break; + } + default: { + lua_assert(e->k == VVOID || e->k == VJMP); + return; /* nothing to do... */ + } + } + e->u.s.info = reg; + e->k = VNONRELOC; +} + + +static void discharge2anyreg (FuncState *fs, expdesc *e) { + if (e->k != VNONRELOC) { + luaK_reserveregs(fs, 1); + discharge2reg(fs, e, fs->freereg-1); + } +} + + +static void exp2reg (FuncState *fs, expdesc *e, int reg) { + discharge2reg(fs, e, reg); + if (e->k == VJMP) + luaK_concat(fs, &e->t, e->u.s.info); /* put this jump in `t' list */ + if (hasjumps(e)) { + int final; /* position after whole expression */ + int p_f = NO_JUMP; /* position of an eventual LOAD false */ + int p_t = NO_JUMP; /* position of an eventual LOAD true */ + if (need_value(fs, e->t) || need_value(fs, e->f)) { + int fj = (e->k == VJMP) ? NO_JUMP : luaK_jump(fs); + p_f = code_label(fs, reg, 0, 1); + p_t = code_label(fs, reg, 1, 0); + luaK_patchtohere(fs, fj); + } + final = luaK_getlabel(fs); + patchlistaux(fs, e->f, final, reg, p_f); + patchlistaux(fs, e->t, final, reg, p_t); + } + e->f = e->t = NO_JUMP; + e->u.s.info = reg; + e->k = VNONRELOC; +} + + +void luaK_exp2nextreg (FuncState *fs, expdesc *e) { + luaK_dischargevars(fs, e); + freeexp(fs, e); + luaK_reserveregs(fs, 1); + exp2reg(fs, e, fs->freereg - 1); +} + + +int luaK_exp2anyreg (FuncState *fs, expdesc *e) { + luaK_dischargevars(fs, e); + if (e->k == VNONRELOC) { + if (!hasjumps(e)) return e->u.s.info; /* exp is already in a register */ + if (e->u.s.info >= fs->nactvar) { /* reg. is not a local? */ + exp2reg(fs, e, e->u.s.info); /* put value on it */ + return e->u.s.info; + } + } + luaK_exp2nextreg(fs, e); /* default */ + return e->u.s.info; +} + + +void luaK_exp2val (FuncState *fs, expdesc *e) { + if (hasjumps(e)) + luaK_exp2anyreg(fs, e); + else + luaK_dischargevars(fs, e); +} + + +int luaK_exp2RK (FuncState *fs, expdesc *e) { + luaK_exp2val(fs, e); + switch (e->k) { + case VKNUM: + case VTRUE: + case VFALSE: + case VNIL: { + if (fs->nk <= MAXINDEXRK) { /* constant fit in RK operand? */ + e->u.s.info = (e->k == VNIL) ? nilK(fs) : + (e->k == VKNUM) ? luaK_numberK(fs, e->u.nval) : + boolK(fs, (e->k == VTRUE)); + e->k = VK; + return RKASK(e->u.s.info); + } + else break; + } + case VK: { + if (e->u.s.info <= MAXINDEXRK) /* constant fit in argC? */ + return RKASK(e->u.s.info); + else break; + } + default: break; + } + /* not a constant in the right range: put it in a register */ + return luaK_exp2anyreg(fs, e); +} + + +void luaK_storevar (FuncState *fs, expdesc *var, expdesc *ex) { + switch (var->k) { + case VLOCAL: { + freeexp(fs, ex); + exp2reg(fs, ex, var->u.s.info); + return; + } + case VUPVAL: { + int e = luaK_exp2anyreg(fs, ex); + luaK_codeABC(fs, OP_SETUPVAL, e, var->u.s.info, 0); + break; + } + case VGLOBAL: { + int e = luaK_exp2anyreg(fs, ex); + luaK_codeABx(fs, OP_SETGLOBAL, e, var->u.s.info); + break; + } + case VINDEXED: { + int e = luaK_exp2RK(fs, ex); + luaK_codeABC(fs, OP_SETTABLE, var->u.s.info, var->u.s.aux, e); + break; + } + default: { + lua_assert(0); /* invalid var kind to store */ + break; + } + } + freeexp(fs, ex); +} + + +void luaK_self (FuncState *fs, expdesc *e, expdesc *key) { + int func; + luaK_exp2anyreg(fs, e); + freeexp(fs, e); + func = fs->freereg; + luaK_reserveregs(fs, 2); + luaK_codeABC(fs, OP_SELF, func, e->u.s.info, luaK_exp2RK(fs, key)); + freeexp(fs, key); + e->u.s.info = func; + e->k = VNONRELOC; +} + + +static void invertjump (FuncState *fs, expdesc *e) { + Instruction *pc = getjumpcontrol(fs, e->u.s.info); + lua_assert(testTMode(GET_OPCODE(*pc)) && GET_OPCODE(*pc) != OP_TESTSET && + GET_OPCODE(*pc) != OP_TEST); + SETARG_A(*pc, !(GETARG_A(*pc))); +} + + +static int jumponcond (FuncState *fs, expdesc *e, int cond) { + if (e->k == VRELOCABLE) { + Instruction ie = getcode(fs, e); + if (GET_OPCODE(ie) == OP_NOT) { + fs->pc--; /* remove previous OP_NOT */ + return condjump(fs, OP_TEST, GETARG_B(ie), 0, !cond); + } + /* else go through */ + } + discharge2anyreg(fs, e); + freeexp(fs, e); + return condjump(fs, OP_TESTSET, NO_REG, e->u.s.info, cond); +} + + +void luaK_goiftrue (FuncState *fs, expdesc *e) { + int pc; /* pc of last jump */ + luaK_dischargevars(fs, e); + switch (e->k) { + case VK: case VKNUM: case VTRUE: { + pc = NO_JUMP; /* always true; do nothing */ + break; + } + case VFALSE: { + pc = luaK_jump(fs); /* always jump */ + break; + } + case VJMP: { + invertjump(fs, e); + pc = e->u.s.info; + break; + } + default: { + pc = jumponcond(fs, e, 0); + break; + } + } + luaK_concat(fs, &e->f, pc); /* insert last jump in `f' list */ + luaK_patchtohere(fs, e->t); + e->t = NO_JUMP; +} + + +static void luaK_goiffalse (FuncState *fs, expdesc *e) { + int pc; /* pc of last jump */ + luaK_dischargevars(fs, e); + switch (e->k) { + case VNIL: case VFALSE: { + pc = NO_JUMP; /* always false; do nothing */ + break; + } + case VTRUE: { + pc = luaK_jump(fs); /* always jump */ + break; + } + case VJMP: { + pc = e->u.s.info; + break; + } + default: { + pc = jumponcond(fs, e, 1); + break; + } + } + luaK_concat(fs, &e->t, pc); /* insert last jump in `t' list */ + luaK_patchtohere(fs, e->f); + e->f = NO_JUMP; +} + + +static void codenot (FuncState *fs, expdesc *e) { + luaK_dischargevars(fs, e); + switch (e->k) { + case VNIL: case VFALSE: { + e->k = VTRUE; + break; + } + case VK: case VKNUM: case VTRUE: { + e->k = VFALSE; + break; + } + case VJMP: { + invertjump(fs, e); + break; + } + case VRELOCABLE: + case VNONRELOC: { + discharge2anyreg(fs, e); + freeexp(fs, e); + e->u.s.info = luaK_codeABC(fs, OP_NOT, 0, e->u.s.info, 0); + e->k = VRELOCABLE; + break; + } + default: { + lua_assert(0); /* cannot happen */ + break; + } + } + /* interchange true and false lists */ + { int temp = e->f; e->f = e->t; e->t = temp; } + removevalues(fs, e->f); + removevalues(fs, e->t); +} + + +void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) { + t->u.s.aux = luaK_exp2RK(fs, k); + t->k = VINDEXED; +} + + +static int constfolding (OpCode op, expdesc *e1, expdesc *e2) { + lua_Number v1, v2, r; + if (!isnumeral(e1) || !isnumeral(e2)) return 0; + v1 = e1->u.nval; + v2 = e2->u.nval; + switch (op) { + case OP_ADD: r = luai_numadd(v1, v2); break; + case OP_SUB: r = luai_numsub(v1, v2); break; + case OP_MUL: r = luai_nummul(v1, v2); break; + case OP_DIV: + if (v2 == 0) return 0; /* do not attempt to divide by 0 */ + r = luai_numdiv(v1, v2); break; + case OP_MOD: + if (v2 == 0) return 0; /* do not attempt to divide by 0 */ + r = luai_nummod(v1, v2); break; + case OP_POW: r = luai_numpow(v1, v2); break; + case OP_UNM: r = luai_numunm(v1); break; + case OP_LEN: return 0; /* no constant folding for 'len' */ + default: lua_assert(0); r = 0; break; + } + if (luai_numisnan(r)) return 0; /* do not attempt to produce NaN */ + e1->u.nval = r; + return 1; +} + + +static void codearith (FuncState *fs, OpCode op, expdesc *e1, expdesc *e2) { + if (constfolding(op, e1, e2)) + return; + else { + int o2 = (op != OP_UNM && op != OP_LEN) ? luaK_exp2RK(fs, e2) : 0; + int o1 = luaK_exp2RK(fs, e1); + if (o1 > o2) { + freeexp(fs, e1); + freeexp(fs, e2); + } + else { + freeexp(fs, e2); + freeexp(fs, e1); + } + e1->u.s.info = luaK_codeABC(fs, op, 0, o1, o2); + e1->k = VRELOCABLE; + } +} + + +static void codecomp (FuncState *fs, OpCode op, int cond, expdesc *e1, + expdesc *e2) { + int o1 = luaK_exp2RK(fs, e1); + int o2 = luaK_exp2RK(fs, e2); + freeexp(fs, e2); + freeexp(fs, e1); + if (cond == 0 && op != OP_EQ) { + int temp; /* exchange args to replace by `<' or `<=' */ + temp = o1; o1 = o2; o2 = temp; /* o1 <==> o2 */ + cond = 1; + } + e1->u.s.info = condjump(fs, op, cond, o1, o2); + e1->k = VJMP; +} + + +void luaK_prefix (FuncState *fs, UnOpr op, expdesc *e) { + expdesc e2; + e2.t = e2.f = NO_JUMP; e2.k = VKNUM; e2.u.nval = 0; + switch (op) { + case OPR_MINUS: { + if (!isnumeral(e)) + luaK_exp2anyreg(fs, e); /* cannot operate on non-numeric constants */ + codearith(fs, OP_UNM, e, &e2); + break; + } + case OPR_NOT: codenot(fs, e); break; + case OPR_LEN: { + luaK_exp2anyreg(fs, e); /* cannot operate on constants */ + codearith(fs, OP_LEN, e, &e2); + break; + } + default: lua_assert(0); + } +} + + +void luaK_infix (FuncState *fs, BinOpr op, expdesc *v) { + switch (op) { + case OPR_AND: { + luaK_goiftrue(fs, v); + break; + } + case OPR_OR: { + luaK_goiffalse(fs, v); + break; + } + case OPR_CONCAT: { + luaK_exp2nextreg(fs, v); /* operand must be on the `stack' */ + break; + } + case OPR_ADD: case OPR_SUB: case OPR_MUL: case OPR_DIV: + case OPR_MOD: case OPR_POW: { + if (!isnumeral(v)) luaK_exp2RK(fs, v); + break; + } + default: { + luaK_exp2RK(fs, v); + break; + } + } +} + + +void luaK_posfix (FuncState *fs, BinOpr op, expdesc *e1, expdesc *e2) { + switch (op) { + case OPR_AND: { + lua_assert(e1->t == NO_JUMP); /* list must be closed */ + luaK_dischargevars(fs, e2); + luaK_concat(fs, &e2->f, e1->f); + *e1 = *e2; + break; + } + case OPR_OR: { + lua_assert(e1->f == NO_JUMP); /* list must be closed */ + luaK_dischargevars(fs, e2); + luaK_concat(fs, &e2->t, e1->t); + *e1 = *e2; + break; + } + case OPR_CONCAT: { + luaK_exp2val(fs, e2); + if (e2->k == VRELOCABLE && GET_OPCODE(getcode(fs, e2)) == OP_CONCAT) { + lua_assert(e1->u.s.info == GETARG_B(getcode(fs, e2))-1); + freeexp(fs, e1); + SETARG_B(getcode(fs, e2), e1->u.s.info); + e1->k = VRELOCABLE; e1->u.s.info = e2->u.s.info; + } + else { + luaK_exp2nextreg(fs, e2); /* operand must be on the 'stack' */ + codearith(fs, OP_CONCAT, e1, e2); + } + break; + } + case OPR_ADD: codearith(fs, OP_ADD, e1, e2); break; + case OPR_SUB: codearith(fs, OP_SUB, e1, e2); break; + case OPR_MUL: codearith(fs, OP_MUL, e1, e2); break; + case OPR_DIV: codearith(fs, OP_DIV, e1, e2); break; + case OPR_MOD: codearith(fs, OP_MOD, e1, e2); break; + case OPR_POW: codearith(fs, OP_POW, e1, e2); break; + case OPR_EQ: codecomp(fs, OP_EQ, 1, e1, e2); break; + case OPR_NE: codecomp(fs, OP_EQ, 0, e1, e2); break; + case OPR_LT: codecomp(fs, OP_LT, 1, e1, e2); break; + case OPR_LE: codecomp(fs, OP_LE, 1, e1, e2); break; + case OPR_GT: codecomp(fs, OP_LT, 0, e1, e2); break; + case OPR_GE: codecomp(fs, OP_LE, 0, e1, e2); break; + default: lua_assert(0); + } +} + + +void luaK_fixline (FuncState *fs, int line) { + fs->f->lineinfo[fs->pc - 1] = line; +} + + +static int luaK_code (FuncState *fs, Instruction i, int line) { + Proto *f = fs->f; + dischargejpc(fs); /* `pc' will change */ + /* put new instruction in code array */ + luaM_growvector(fs->L, f->code, fs->pc, f->sizecode, Instruction, + MAX_INT, "code size overflow"); + f->code[fs->pc] = i; + /* save corresponding line information */ + luaM_growvector(fs->L, f->lineinfo, fs->pc, f->sizelineinfo, int, + MAX_INT, "code size overflow"); + f->lineinfo[fs->pc] = line; + return fs->pc++; +} + + +int luaK_codeABC (FuncState *fs, OpCode o, int a, int b, int c) { + lua_assert(getOpMode(o) == iABC); + lua_assert(getBMode(o) != OpArgN || b == 0); + lua_assert(getCMode(o) != OpArgN || c == 0); + return luaK_code(fs, CREATE_ABC(o, a, b, c), fs->ls->lastline); +} + + +int luaK_codeABx (FuncState *fs, OpCode o, int a, unsigned int bc) { + lua_assert(getOpMode(o) == iABx || getOpMode(o) == iAsBx); + lua_assert(getCMode(o) == OpArgN); + return luaK_code(fs, CREATE_ABx(o, a, bc), fs->ls->lastline); +} + + +void luaK_setlist (FuncState *fs, int base, int nelems, int tostore) { + int c = (nelems - 1)/LFIELDS_PER_FLUSH + 1; + int b = (tostore == LUA_MULTRET) ? 0 : tostore; + lua_assert(tostore != 0); + if (c <= MAXARG_C) + luaK_codeABC(fs, OP_SETLIST, base, b, c); + else { + luaK_codeABC(fs, OP_SETLIST, base, b, 0); + luaK_code(fs, cast(Instruction, c), fs->ls->lastline); + } + fs->freereg = base + 1; /* free registers with list values */ +} + diff --git a/IOS/lua/lua/lcode.h b/IOS/lua/lua/lcode.h new file mode 100644 index 00000000..b941c607 --- /dev/null +++ b/IOS/lua/lua/lcode.h @@ -0,0 +1,76 @@ +/* +** $Id: lcode.h,v 1.48.1.1 2007/12/27 13:02:25 roberto Exp $ +** Code generator for Lua +** See Copyright Notice in lua.h +*/ + +#ifndef lcode_h +#define lcode_h + +#include "llex.h" +#include "lobject.h" +#include "lopcodes.h" +#include "lparser.h" + + +/* +** Marks the end of a patch list. It is an invalid value both as an absolute +** address, and as a list link (would link an element to itself). +*/ +#define NO_JUMP (-1) + + +/* +** grep "ORDER OPR" if you change these enums +*/ +typedef enum BinOpr { + OPR_ADD, OPR_SUB, OPR_MUL, OPR_DIV, OPR_MOD, OPR_POW, + OPR_CONCAT, + OPR_NE, OPR_EQ, + OPR_LT, OPR_LE, OPR_GT, OPR_GE, + OPR_AND, OPR_OR, + OPR_NOBINOPR +} BinOpr; + + +typedef enum UnOpr { OPR_MINUS, OPR_NOT, OPR_LEN, OPR_NOUNOPR } UnOpr; + + +#define getcode(fs,e) ((fs)->f->code[(e)->u.s.info]) + +#define luaK_codeAsBx(fs,o,A,sBx) luaK_codeABx(fs,o,A,(sBx)+MAXARG_sBx) + +#define luaK_setmultret(fs,e) luaK_setreturns(fs, e, LUA_MULTRET) + +LUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx); +LUAI_FUNC int luaK_codeABC (FuncState *fs, OpCode o, int A, int B, int C); +LUAI_FUNC void luaK_fixline (FuncState *fs, int line); +LUAI_FUNC void luaK_nil (FuncState *fs, int from, int n); +LUAI_FUNC void luaK_reserveregs (FuncState *fs, int n); +LUAI_FUNC void luaK_checkstack (FuncState *fs, int n); +LUAI_FUNC int luaK_stringK (FuncState *fs, TString *s); +LUAI_FUNC int luaK_numberK (FuncState *fs, lua_Number r); +LUAI_FUNC void luaK_dischargevars (FuncState *fs, expdesc *e); +LUAI_FUNC int luaK_exp2anyreg (FuncState *fs, expdesc *e); +LUAI_FUNC void luaK_exp2nextreg (FuncState *fs, expdesc *e); +LUAI_FUNC void luaK_exp2val (FuncState *fs, expdesc *e); +LUAI_FUNC int luaK_exp2RK (FuncState *fs, expdesc *e); +LUAI_FUNC void luaK_self (FuncState *fs, expdesc *e, expdesc *key); +LUAI_FUNC void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k); +LUAI_FUNC void luaK_goiftrue (FuncState *fs, expdesc *e); +LUAI_FUNC void luaK_storevar (FuncState *fs, expdesc *var, expdesc *e); +LUAI_FUNC void luaK_setreturns (FuncState *fs, expdesc *e, int nresults); +LUAI_FUNC void luaK_setoneret (FuncState *fs, expdesc *e); +LUAI_FUNC int luaK_jump (FuncState *fs); +LUAI_FUNC void luaK_ret (FuncState *fs, int first, int nret); +LUAI_FUNC void luaK_patchlist (FuncState *fs, int list, int target); +LUAI_FUNC void luaK_patchtohere (FuncState *fs, int list); +LUAI_FUNC void luaK_concat (FuncState *fs, int *l1, int l2); +LUAI_FUNC int luaK_getlabel (FuncState *fs); +LUAI_FUNC void luaK_prefix (FuncState *fs, UnOpr op, expdesc *v); +LUAI_FUNC void luaK_infix (FuncState *fs, BinOpr op, expdesc *v); +LUAI_FUNC void luaK_posfix (FuncState *fs, BinOpr op, expdesc *v1, expdesc *v2); +LUAI_FUNC void luaK_setlist (FuncState *fs, int base, int nelems, int tostore); + + +#endif diff --git a/IOS/lua/lua/ldblib.c b/IOS/lua/lua/ldblib.c new file mode 100644 index 00000000..67de1222 --- /dev/null +++ b/IOS/lua/lua/ldblib.c @@ -0,0 +1,397 @@ +/* +** $Id: ldblib.c,v 1.104.1.3 2008/01/21 13:11:21 roberto Exp $ +** Interface from Lua to its debug API +** See Copyright Notice in lua.h +*/ + + +#include +#include +#include + +#define ldblib_c +#define LUA_LIB + +#include "lua.h" + +#include "lauxlib.h" +#include "lualib.h" + + + +static int db_getregistry (lua_State *L) { + lua_pushvalue(L, LUA_REGISTRYINDEX); + return 1; +} + + +static int db_getmetatable (lua_State *L) { + luaL_checkany(L, 1); + if (!lua_getmetatable(L, 1)) { + lua_pushnil(L); /* no metatable */ + } + return 1; +} + + +static int db_setmetatable (lua_State *L) { + int t = lua_type(L, 2); + luaL_argcheck(L, t == LUA_TNIL || t == LUA_TTABLE, 2, + "nil or table expected"); + lua_settop(L, 2); + lua_pushboolean(L, lua_setmetatable(L, 1)); + return 1; +} + + +static int db_getfenv (lua_State *L) { + lua_getfenv(L, 1); + return 1; +} + + +static int db_setfenv (lua_State *L) { + luaL_checktype(L, 2, LUA_TTABLE); + lua_settop(L, 2); + if (lua_setfenv(L, 1) == 0) + luaL_error(L, LUA_QL("setfenv") + " cannot change environment of given object"); + return 1; +} + + +static void settabss (lua_State *L, const char *i, const char *v) { + lua_pushstring(L, v); + lua_setfield(L, -2, i); +} + + +static void settabsi (lua_State *L, const char *i, int v) { + lua_pushinteger(L, v); + lua_setfield(L, -2, i); +} + + +static lua_State *getthread (lua_State *L, int *arg) { + if (lua_isthread(L, 1)) { + *arg = 1; + return lua_tothread(L, 1); + } + else { + *arg = 0; + return L; + } +} + + +static void treatstackoption (lua_State *L, lua_State *L1, const char *fname) { + if (L == L1) { + lua_pushvalue(L, -2); + lua_remove(L, -3); + } + else + lua_xmove(L1, L, 1); + lua_setfield(L, -2, fname); +} + + +static int db_getinfo (lua_State *L) { + lua_Debug ar; + int arg; + lua_State *L1 = getthread(L, &arg); + const char *options = luaL_optstring(L, arg+2, "flnSu"); + if (lua_isnumber(L, arg+1)) { + if (!lua_getstack(L1, (int)lua_tointeger(L, arg+1), &ar)) { + lua_pushnil(L); /* level out of range */ + return 1; + } + } + else if (lua_isfunction(L, arg+1)) { + lua_pushfstring(L, ">%s", options); + options = lua_tostring(L, -1); + lua_pushvalue(L, arg+1); + lua_xmove(L, L1, 1); + } + else + return luaL_argerror(L, arg+1, "function or level expected"); + if (!lua_getinfo(L1, options, &ar)) + return luaL_argerror(L, arg+2, "invalid option"); + lua_createtable(L, 0, 2); + if (strchr(options, 'S')) { + settabss(L, "source", ar.source); + settabss(L, "short_src", ar.short_src); + settabsi(L, "linedefined", ar.linedefined); + settabsi(L, "lastlinedefined", ar.lastlinedefined); + settabss(L, "what", ar.what); + } + if (strchr(options, 'l')) + settabsi(L, "currentline", ar.currentline); + if (strchr(options, 'u')) + settabsi(L, "nups", ar.nups); + if (strchr(options, 'n')) { + settabss(L, "name", ar.name); + settabss(L, "namewhat", ar.namewhat); + } + if (strchr(options, 'L')) + treatstackoption(L, L1, "activelines"); + if (strchr(options, 'f')) + treatstackoption(L, L1, "func"); + return 1; /* return table */ +} + + +static int db_getlocal (lua_State *L) { + int arg; + lua_State *L1 = getthread(L, &arg); + lua_Debug ar; + const char *name; + if (!lua_getstack(L1, luaL_checkint(L, arg+1), &ar)) /* out of range? */ + return luaL_argerror(L, arg+1, "level out of range"); + name = lua_getlocal(L1, &ar, luaL_checkint(L, arg+2)); + if (name) { + lua_xmove(L1, L, 1); + lua_pushstring(L, name); + lua_pushvalue(L, -2); + return 2; + } + else { + lua_pushnil(L); + return 1; + } +} + + +static int db_setlocal (lua_State *L) { + int arg; + lua_State *L1 = getthread(L, &arg); + lua_Debug ar; + if (!lua_getstack(L1, luaL_checkint(L, arg+1), &ar)) /* out of range? */ + return luaL_argerror(L, arg+1, "level out of range"); + luaL_checkany(L, arg+3); + lua_settop(L, arg+3); + lua_xmove(L, L1, 1); + lua_pushstring(L, lua_setlocal(L1, &ar, luaL_checkint(L, arg+2))); + return 1; +} + + +static int auxupvalue (lua_State *L, int get) { + const char *name; + int n = luaL_checkint(L, 2); + luaL_checktype(L, 1, LUA_TFUNCTION); + if (lua_iscfunction(L, 1)) return 0; /* cannot touch C upvalues from Lua */ + name = get ? lua_getupvalue(L, 1, n) : lua_setupvalue(L, 1, n); + if (name == NULL) return 0; + lua_pushstring(L, name); + lua_insert(L, -(get+1)); + return get + 1; +} + + +static int db_getupvalue (lua_State *L) { + return auxupvalue(L, 1); +} + + +static int db_setupvalue (lua_State *L) { + luaL_checkany(L, 3); + return auxupvalue(L, 0); +} + + + +static const char KEY_HOOK = 'h'; + + +static void hookf (lua_State *L, lua_Debug *ar) { + static const char *const hooknames[] = + {"call", "return", "line", "count", "tail return"}; + lua_pushlightuserdata(L, (void *)&KEY_HOOK); + lua_rawget(L, LUA_REGISTRYINDEX); + lua_pushlightuserdata(L, L); + lua_rawget(L, -2); + if (lua_isfunction(L, -1)) { + lua_pushstring(L, hooknames[(int)ar->event]); + if (ar->currentline >= 0) + lua_pushinteger(L, ar->currentline); + else lua_pushnil(L); + lua_assert(lua_getinfo(L, "lS", ar)); + lua_call(L, 2, 0); + } +} + + +static int makemask (const char *smask, int count) { + int mask = 0; + if (strchr(smask, 'c')) mask |= LUA_MASKCALL; + if (strchr(smask, 'r')) mask |= LUA_MASKRET; + if (strchr(smask, 'l')) mask |= LUA_MASKLINE; + if (count > 0) mask |= LUA_MASKCOUNT; + return mask; +} + + +static char *unmakemask (int mask, char *smask) { + int i = 0; + if (mask & LUA_MASKCALL) smask[i++] = 'c'; + if (mask & LUA_MASKRET) smask[i++] = 'r'; + if (mask & LUA_MASKLINE) smask[i++] = 'l'; + smask[i] = '\0'; + return smask; +} + + +static void gethooktable (lua_State *L) { + lua_pushlightuserdata(L, (void *)&KEY_HOOK); + lua_rawget(L, LUA_REGISTRYINDEX); + if (!lua_istable(L, -1)) { + lua_pop(L, 1); + lua_createtable(L, 0, 1); + lua_pushlightuserdata(L, (void *)&KEY_HOOK); + lua_pushvalue(L, -2); + lua_rawset(L, LUA_REGISTRYINDEX); + } +} + + +static int db_sethook (lua_State *L) { + int arg, mask, count; + lua_Hook func; + lua_State *L1 = getthread(L, &arg); + if (lua_isnoneornil(L, arg+1)) { + lua_settop(L, arg+1); + func = NULL; mask = 0; count = 0; /* turn off hooks */ + } + else { + const char *smask = luaL_checkstring(L, arg+2); + luaL_checktype(L, arg+1, LUA_TFUNCTION); + count = luaL_optint(L, arg+3, 0); + func = hookf; mask = makemask(smask, count); + } + gethooktable(L); + lua_pushlightuserdata(L, L1); + lua_pushvalue(L, arg+1); + lua_rawset(L, -3); /* set new hook */ + lua_pop(L, 1); /* remove hook table */ + lua_sethook(L1, func, mask, count); /* set hooks */ + return 0; +} + + +static int db_gethook (lua_State *L) { + int arg; + lua_State *L1 = getthread(L, &arg); + char buff[5]; + int mask = lua_gethookmask(L1); + lua_Hook hook = lua_gethook(L1); + if (hook != NULL && hook != hookf) /* external hook? */ + lua_pushliteral(L, "external hook"); + else { + gethooktable(L); + lua_pushlightuserdata(L, L1); + lua_rawget(L, -2); /* get hook */ + lua_remove(L, -2); /* remove hook table */ + } + lua_pushstring(L, unmakemask(mask, buff)); + lua_pushinteger(L, lua_gethookcount(L1)); + return 3; +} + + +static int db_debug (lua_State *L) { + for (;;) { + char buffer[250]; + fputs("lua_debug> ", stderr); + if (fgets(buffer, sizeof(buffer), stdin) == 0 || + strcmp(buffer, "cont\n") == 0) + return 0; + if (luaL_loadbuffer(L, buffer, strlen(buffer), "=(debug command)") || + lua_pcall(L, 0, 0, 0)) { + fputs(lua_tostring(L, -1), stderr); + fputs("\n", stderr); + } + lua_settop(L, 0); /* remove eventual returns */ + } +} + + +#define LEVELS1 12 /* size of the first part of the stack */ +#define LEVELS2 10 /* size of the second part of the stack */ + +static int db_errorfb (lua_State *L) { + int level; + int firstpart = 1; /* still before eventual `...' */ + int arg; + lua_State *L1 = getthread(L, &arg); + lua_Debug ar; + if (lua_isnumber(L, arg+2)) { + level = (int)lua_tointeger(L, arg+2); + lua_pop(L, 1); + } + else + level = (L == L1) ? 1 : 0; /* level 0 may be this own function */ + if (lua_gettop(L) == arg) + lua_pushliteral(L, ""); + else if (!lua_isstring(L, arg+1)) return 1; /* message is not a string */ + else lua_pushliteral(L, "\n"); + lua_pushliteral(L, "stack traceback:"); + while (lua_getstack(L1, level++, &ar)) { + if (level > LEVELS1 && firstpart) { + /* no more than `LEVELS2' more levels? */ + if (!lua_getstack(L1, level+LEVELS2, &ar)) + level--; /* keep going */ + else { + lua_pushliteral(L, "\n\t..."); /* too many levels */ + while (lua_getstack(L1, level+LEVELS2, &ar)) /* find last levels */ + level++; + } + firstpart = 0; + continue; + } + lua_pushliteral(L, "\n\t"); + lua_getinfo(L1, "Snl", &ar); + lua_pushfstring(L, "%s:", ar.short_src); + if (ar.currentline > 0) + lua_pushfstring(L, "%d:", ar.currentline); + if (*ar.namewhat != '\0') /* is there a name? */ + lua_pushfstring(L, " in function " LUA_QS, ar.name); + else { + if (*ar.what == 'm') /* main? */ + lua_pushfstring(L, " in main chunk"); + else if (*ar.what == 'C' || *ar.what == 't') + lua_pushliteral(L, " ?"); /* C function or tail call */ + else + lua_pushfstring(L, " in function <%s:%d>", + ar.short_src, ar.linedefined); + } + lua_concat(L, lua_gettop(L) - arg); + } + lua_concat(L, lua_gettop(L) - arg); + return 1; +} + + +static const luaL_Reg dblib[] = { + {"debug", db_debug}, + {"getfenv", db_getfenv}, + {"gethook", db_gethook}, + {"getinfo", db_getinfo}, + {"getlocal", db_getlocal}, + {"getregistry", db_getregistry}, + {"getmetatable", db_getmetatable}, + {"getupvalue", db_getupvalue}, + {"setfenv", db_setfenv}, + {"sethook", db_sethook}, + {"setlocal", db_setlocal}, + {"setmetatable", db_setmetatable}, + {"setupvalue", db_setupvalue}, + {"traceback", db_errorfb}, + {NULL, NULL} +}; + + +LUALIB_API int luaopen_debug (lua_State *L) { + luaL_register(L, LUA_DBLIBNAME, dblib); + return 1; +} + diff --git a/IOS/lua/lua/ldebug.c b/IOS/lua/lua/ldebug.c new file mode 100644 index 00000000..50ad3d38 --- /dev/null +++ b/IOS/lua/lua/ldebug.c @@ -0,0 +1,638 @@ +/* +** $Id: ldebug.c,v 2.29.1.6 2008/05/08 16:56:26 roberto Exp $ +** Debug Interface +** See Copyright Notice in lua.h +*/ + + +#include +#include +#include + + +#define ldebug_c +#define LUA_CORE + +#include "lua.h" + +#include "lapi.h" +#include "lcode.h" +#include "ldebug.h" +#include "ldo.h" +#include "lfunc.h" +#include "lobject.h" +#include "lopcodes.h" +#include "lstate.h" +#include "lstring.h" +#include "ltable.h" +#include "ltm.h" +#include "lvm.h" + + + +static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name); + + +static int currentpc (lua_State *L, CallInfo *ci) { + if (!isLua(ci)) return -1; /* function is not a Lua function? */ + if (ci == L->ci) + ci->savedpc = L->savedpc; + return pcRel(ci->savedpc, ci_func(ci)->l.p); +} + + +static int currentline (lua_State *L, CallInfo *ci) { + int pc = currentpc(L, ci); + if (pc < 0) + return -1; /* only active lua functions have current-line information */ + else + return getline(ci_func(ci)->l.p, pc); +} + + +/* +** this function can be called asynchronous (e.g. during a signal) +*/ +LUA_API int lua_sethook (lua_State *L, lua_Hook func, int mask, int count) { + if (func == NULL || mask == 0) { /* turn off hooks? */ + mask = 0; + func = NULL; + } + L->hook = func; + L->basehookcount = count; + resethookcount(L); + L->hookmask = cast_byte(mask); + return 1; +} + + +LUA_API lua_Hook lua_gethook (lua_State *L) { + return L->hook; +} + + +LUA_API int lua_gethookmask (lua_State *L) { + return L->hookmask; +} + + +LUA_API int lua_gethookcount (lua_State *L) { + return L->basehookcount; +} + + +LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar) { + int status; + CallInfo *ci; + lua_lock(L); + for (ci = L->ci; level > 0 && ci > L->base_ci; ci--) { + level--; + if (f_isLua(ci)) /* Lua function? */ + level -= ci->tailcalls; /* skip lost tail calls */ + } + if (level == 0 && ci > L->base_ci) { /* level found? */ + status = 1; + ar->i_ci = cast_int(ci - L->base_ci); + } + else if (level < 0) { /* level is of a lost tail call? */ + status = 1; + ar->i_ci = 0; + } + else status = 0; /* no such level */ + lua_unlock(L); + return status; +} + + +static Proto *getluaproto (CallInfo *ci) { + return (isLua(ci) ? ci_func(ci)->l.p : NULL); +} + + +static const char *findlocal (lua_State *L, CallInfo *ci, int n) { + const char *name; + Proto *fp = getluaproto(ci); + if (fp && (name = luaF_getlocalname(fp, n, currentpc(L, ci))) != NULL) + return name; /* is a local variable in a Lua function */ + else { + StkId limit = (ci == L->ci) ? L->top : (ci+1)->func; + if (limit - ci->base >= n && n > 0) /* is 'n' inside 'ci' stack? */ + return "(*temporary)"; + else + return NULL; + } +} + + +LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) { + CallInfo *ci = L->base_ci + ar->i_ci; + const char *name = findlocal(L, ci, n); + lua_lock(L); + if (name) + luaA_pushobject(L, ci->base + (n - 1)); + lua_unlock(L); + return name; +} + + +LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) { + CallInfo *ci = L->base_ci + ar->i_ci; + const char *name = findlocal(L, ci, n); + lua_lock(L); + if (name) + setobjs2s(L, ci->base + (n - 1), L->top - 1); + L->top--; /* pop value */ + lua_unlock(L); + return name; +} + + +static void funcinfo (lua_Debug *ar, Closure *cl) { + if (cl->c.isC) { + ar->source = "=[C]"; + ar->linedefined = -1; + ar->lastlinedefined = -1; + ar->what = "C"; + } + else { + ar->source = getstr(cl->l.p->source); + ar->linedefined = cl->l.p->linedefined; + ar->lastlinedefined = cl->l.p->lastlinedefined; + ar->what = (ar->linedefined == 0) ? "main" : "Lua"; + } + luaO_chunkid(ar->short_src, ar->source, LUA_IDSIZE); +} + + +static void info_tailcall (lua_Debug *ar) { + ar->name = ar->namewhat = ""; + ar->what = "tail"; + ar->lastlinedefined = ar->linedefined = ar->currentline = -1; + ar->source = "=(tail call)"; + luaO_chunkid(ar->short_src, ar->source, LUA_IDSIZE); + ar->nups = 0; +} + + +static void collectvalidlines (lua_State *L, Closure *f) { + if (f == NULL || f->c.isC) { + setnilvalue(L->top); + } + else { + Table *t = luaH_new(L, 0, 0); + int *lineinfo = f->l.p->lineinfo; + int i; + for (i=0; il.p->sizelineinfo; i++) + setbvalue(luaH_setnum(L, t, lineinfo[i]), 1); + sethvalue(L, L->top, t); + } + incr_top(L); +} + + +static int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar, + Closure *f, CallInfo *ci) { + int status = 1; + if (f == NULL) { + info_tailcall(ar); + return status; + } + for (; *what; what++) { + switch (*what) { + case 'S': { + funcinfo(ar, f); + break; + } + case 'l': { + ar->currentline = (ci) ? currentline(L, ci) : -1; + break; + } + case 'u': { + ar->nups = f->c.nupvalues; + break; + } + case 'n': { + ar->namewhat = (ci) ? getfuncname(L, ci, &ar->name) : NULL; + if (ar->namewhat == NULL) { + ar->namewhat = ""; /* not found */ + ar->name = NULL; + } + break; + } + case 'L': + case 'f': /* handled by lua_getinfo */ + break; + default: status = 0; /* invalid option */ + } + } + return status; +} + + +LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) { + int status; + Closure *f = NULL; + CallInfo *ci = NULL; + lua_lock(L); + if (*what == '>') { + StkId func = L->top - 1; + luai_apicheck(L, ttisfunction(func)); + what++; /* skip the '>' */ + f = clvalue(func); + L->top--; /* pop function */ + } + else if (ar->i_ci != 0) { /* no tail call? */ + ci = L->base_ci + ar->i_ci; + lua_assert(ttisfunction(ci->func)); + f = clvalue(ci->func); + } + status = auxgetinfo(L, what, ar, f, ci); + if (strchr(what, 'f')) { + if (f == NULL) setnilvalue(L->top); + else setclvalue(L, L->top, f); + incr_top(L); + } + if (strchr(what, 'L')) + collectvalidlines(L, f); + lua_unlock(L); + return status; +} + + +/* +** {====================================================== +** Symbolic Execution and code checker +** ======================================================= +*/ + +#define check(x) if (!(x)) return 0; + +#define checkjump(pt,pc) check(0 <= pc && pc < pt->sizecode) + +#define checkreg(pt,reg) check((reg) < (pt)->maxstacksize) + + + +static int precheck (const Proto *pt) { + check(pt->maxstacksize <= MAXSTACK); + check(pt->numparams+(pt->is_vararg & VARARG_HASARG) <= pt->maxstacksize); + check(!(pt->is_vararg & VARARG_NEEDSARG) || + (pt->is_vararg & VARARG_HASARG)); + check(pt->sizeupvalues <= pt->nups); + check(pt->sizelineinfo == pt->sizecode || pt->sizelineinfo == 0); + check(pt->sizecode > 0 && GET_OPCODE(pt->code[pt->sizecode-1]) == OP_RETURN); + return 1; +} + + +#define checkopenop(pt,pc) luaG_checkopenop((pt)->code[(pc)+1]) + +int luaG_checkopenop (Instruction i) { + switch (GET_OPCODE(i)) { + case OP_CALL: + case OP_TAILCALL: + case OP_RETURN: + case OP_SETLIST: { + check(GETARG_B(i) == 0); + return 1; + } + default: return 0; /* invalid instruction after an open call */ + } +} + + +static int checkArgMode (const Proto *pt, int r, enum OpArgMask mode) { + switch (mode) { + case OpArgN: check(r == 0); break; + case OpArgU: break; + case OpArgR: checkreg(pt, r); break; + case OpArgK: + check(ISK(r) ? INDEXK(r) < pt->sizek : r < pt->maxstacksize); + break; + } + return 1; +} + + +static Instruction symbexec (const Proto *pt, int lastpc, int reg) { + int pc; + int last; /* stores position of last instruction that changed `reg' */ + last = pt->sizecode-1; /* points to final return (a `neutral' instruction) */ + check(precheck(pt)); + for (pc = 0; pc < lastpc; pc++) { + Instruction i = pt->code[pc]; + OpCode op = GET_OPCODE(i); + int a = GETARG_A(i); + int b = 0; + int c = 0; + check(op < NUM_OPCODES); + checkreg(pt, a); + switch (getOpMode(op)) { + case iABC: { + b = GETARG_B(i); + c = GETARG_C(i); + check(checkArgMode(pt, b, getBMode(op))); + check(checkArgMode(pt, c, getCMode(op))); + break; + } + case iABx: { + b = GETARG_Bx(i); + if (getBMode(op) == OpArgK) check(b < pt->sizek); + break; + } + case iAsBx: { + b = GETARG_sBx(i); + if (getBMode(op) == OpArgR) { + int dest = pc+1+b; + check(0 <= dest && dest < pt->sizecode); + if (dest > 0) { + int j; + /* check that it does not jump to a setlist count; this + is tricky, because the count from a previous setlist may + have the same value of an invalid setlist; so, we must + go all the way back to the first of them (if any) */ + for (j = 0; j < dest; j++) { + Instruction d = pt->code[dest-1-j]; + if (!(GET_OPCODE(d) == OP_SETLIST && GETARG_C(d) == 0)) break; + } + /* if 'j' is even, previous value is not a setlist (even if + it looks like one) */ + check((j&1) == 0); + } + } + break; + } + } + if (testAMode(op)) { + if (a == reg) last = pc; /* change register `a' */ + } + if (testTMode(op)) { + check(pc+2 < pt->sizecode); /* check skip */ + check(GET_OPCODE(pt->code[pc+1]) == OP_JMP); + } + switch (op) { + case OP_LOADBOOL: { + if (c == 1) { /* does it jump? */ + check(pc+2 < pt->sizecode); /* check its jump */ + check(GET_OPCODE(pt->code[pc+1]) != OP_SETLIST || + GETARG_C(pt->code[pc+1]) != 0); + } + break; + } + case OP_LOADNIL: { + if (a <= reg && reg <= b) + last = pc; /* set registers from `a' to `b' */ + break; + } + case OP_GETUPVAL: + case OP_SETUPVAL: { + check(b < pt->nups); + break; + } + case OP_GETGLOBAL: + case OP_SETGLOBAL: { + check(ttisstring(&pt->k[b])); + break; + } + case OP_SELF: { + checkreg(pt, a+1); + if (reg == a+1) last = pc; + break; + } + case OP_CONCAT: { + check(b < c); /* at least two operands */ + break; + } + case OP_TFORLOOP: { + check(c >= 1); /* at least one result (control variable) */ + checkreg(pt, a+2+c); /* space for results */ + if (reg >= a+2) last = pc; /* affect all regs above its base */ + break; + } + case OP_FORLOOP: + case OP_FORPREP: + checkreg(pt, a+3); + /* go through */ + case OP_JMP: { + int dest = pc+1+b; + /* not full check and jump is forward and do not skip `lastpc'? */ + if (reg != NO_REG && pc < dest && dest <= lastpc) + pc += b; /* do the jump */ + break; + } + case OP_CALL: + case OP_TAILCALL: { + if (b != 0) { + checkreg(pt, a+b-1); + } + c--; /* c = num. returns */ + if (c == LUA_MULTRET) { + check(checkopenop(pt, pc)); + } + else if (c != 0) + checkreg(pt, a+c-1); + if (reg >= a) last = pc; /* affect all registers above base */ + break; + } + case OP_RETURN: { + b--; /* b = num. returns */ + if (b > 0) checkreg(pt, a+b-1); + break; + } + case OP_SETLIST: { + if (b > 0) checkreg(pt, a + b); + if (c == 0) { + pc++; + check(pc < pt->sizecode - 1); + } + break; + } + case OP_CLOSURE: { + int nup, j; + check(b < pt->sizep); + nup = pt->p[b]->nups; + check(pc + nup < pt->sizecode); + for (j = 1; j <= nup; j++) { + OpCode op1 = GET_OPCODE(pt->code[pc + j]); + check(op1 == OP_GETUPVAL || op1 == OP_MOVE); + } + if (reg != NO_REG) /* tracing? */ + pc += nup; /* do not 'execute' these pseudo-instructions */ + break; + } + case OP_VARARG: { + check((pt->is_vararg & VARARG_ISVARARG) && + !(pt->is_vararg & VARARG_NEEDSARG)); + b--; + if (b == LUA_MULTRET) check(checkopenop(pt, pc)); + checkreg(pt, a+b-1); + break; + } + default: break; + } + } + return pt->code[last]; +} + +#undef check +#undef checkjump +#undef checkreg + +/* }====================================================== */ + + +int luaG_checkcode (const Proto *pt) { + return (symbexec(pt, pt->sizecode, NO_REG) != 0); +} + + +static const char *kname (Proto *p, int c) { + if (ISK(c) && ttisstring(&p->k[INDEXK(c)])) + return svalue(&p->k[INDEXK(c)]); + else + return "?"; +} + + +static const char *getobjname (lua_State *L, CallInfo *ci, int stackpos, + const char **name) { + if (isLua(ci)) { /* a Lua function? */ + Proto *p = ci_func(ci)->l.p; + int pc = currentpc(L, ci); + Instruction i; + *name = luaF_getlocalname(p, stackpos+1, pc); + if (*name) /* is a local? */ + return "local"; + i = symbexec(p, pc, stackpos); /* try symbolic execution */ + lua_assert(pc != -1); + switch (GET_OPCODE(i)) { + case OP_GETGLOBAL: { + int g = GETARG_Bx(i); /* global index */ + lua_assert(ttisstring(&p->k[g])); + *name = svalue(&p->k[g]); + return "global"; + } + case OP_MOVE: { + int a = GETARG_A(i); + int b = GETARG_B(i); /* move from `b' to `a' */ + if (b < a) + return getobjname(L, ci, b, name); /* get name for `b' */ + break; + } + case OP_GETTABLE: { + int k = GETARG_C(i); /* key index */ + *name = kname(p, k); + return "field"; + } + case OP_GETUPVAL: { + int u = GETARG_B(i); /* upvalue index */ + *name = p->upvalues ? getstr(p->upvalues[u]) : "?"; + return "upvalue"; + } + case OP_SELF: { + int k = GETARG_C(i); /* key index */ + *name = kname(p, k); + return "method"; + } + default: break; + } + } + return NULL; /* no useful name found */ +} + + +static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name) { + Instruction i; + if ((isLua(ci) && ci->tailcalls > 0) || !isLua(ci - 1)) + return NULL; /* calling function is not Lua (or is unknown) */ + ci--; /* calling function */ + i = ci_func(ci)->l.p->code[currentpc(L, ci)]; + if (GET_OPCODE(i) == OP_CALL || GET_OPCODE(i) == OP_TAILCALL || + GET_OPCODE(i) == OP_TFORLOOP) + return getobjname(L, ci, GETARG_A(i), name); + else + return NULL; /* no useful name can be found */ +} + + +/* only ANSI way to check whether a pointer points to an array */ +static int isinstack (CallInfo *ci, const TValue *o) { + StkId p; + for (p = ci->base; p < ci->top; p++) + if (o == p) return 1; + return 0; +} + + +void luaG_typeerror (lua_State *L, const TValue *o, const char *op) { + const char *name = NULL; + const char *t = luaT_typenames[ttype(o)]; + const char *kind = (isinstack(L->ci, o)) ? + getobjname(L, L->ci, cast_int(o - L->base), &name) : + NULL; + if (kind) + luaG_runerror(L, "attempt to %s %s " LUA_QS " (a %s value)", + op, kind, name, t); + else + luaG_runerror(L, "attempt to %s a %s value", op, t); +} + + +void luaG_concaterror (lua_State *L, StkId p1, StkId p2) { + if (ttisstring(p1) || ttisnumber(p1)) p1 = p2; + lua_assert(!ttisstring(p1) && !ttisnumber(p1)); + luaG_typeerror(L, p1, "concatenate"); +} + + +void luaG_aritherror (lua_State *L, const TValue *p1, const TValue *p2) { + TValue temp; + if (luaV_tonumber(p1, &temp) == NULL) + p2 = p1; /* first operand is wrong */ + luaG_typeerror(L, p2, "perform arithmetic on"); +} + + +int luaG_ordererror (lua_State *L, const TValue *p1, const TValue *p2) { + const char *t1 = luaT_typenames[ttype(p1)]; + const char *t2 = luaT_typenames[ttype(p2)]; + if (t1[2] == t2[2]) + luaG_runerror(L, "attempt to compare two %s values", t1); + else + luaG_runerror(L, "attempt to compare %s with %s", t1, t2); + return 0; +} + + +static void addinfo (lua_State *L, const char *msg) { + CallInfo *ci = L->ci; + if (isLua(ci)) { /* is Lua code? */ + char buff[LUA_IDSIZE]; /* add file:line information */ + int line = currentline(L, ci); + luaO_chunkid(buff, getstr(getluaproto(ci)->source), LUA_IDSIZE); + luaO_pushfstring(L, "%s:%d: %s", buff, line, msg); + } +} + + +void luaG_errormsg (lua_State *L) { + if (L->errfunc != 0) { /* is there an error handling function? */ + StkId errfunc = restorestack(L, L->errfunc); + if (!ttisfunction(errfunc)) luaD_throw(L, LUA_ERRERR); + setobjs2s(L, L->top, L->top - 1); /* move argument */ + setobjs2s(L, L->top - 1, errfunc); /* push function */ + incr_top(L); + luaD_call(L, L->top - 2, 1); /* call it */ + } + luaD_throw(L, LUA_ERRRUN); +} + + +void luaG_runerror (lua_State *L, const char *fmt, ...) { + va_list argp; + va_start(argp, fmt); + addinfo(L, luaO_pushvfstring(L, fmt, argp)); + va_end(argp); + luaG_errormsg(L); +} + diff --git a/IOS/lua/lua/ldebug.h b/IOS/lua/lua/ldebug.h new file mode 100644 index 00000000..ba28a972 --- /dev/null +++ b/IOS/lua/lua/ldebug.h @@ -0,0 +1,33 @@ +/* +** $Id: ldebug.h,v 2.3.1.1 2007/12/27 13:02:25 roberto Exp $ +** Auxiliary functions from Debug Interface module +** See Copyright Notice in lua.h +*/ + +#ifndef ldebug_h +#define ldebug_h + + +#include "lstate.h" + + +#define pcRel(pc, p) (cast(int, (pc) - (p)->code) - 1) + +#define getline(f,pc) (((f)->lineinfo) ? (f)->lineinfo[pc] : 0) + +#define resethookcount(L) (L->hookcount = L->basehookcount) + + +LUAI_FUNC void luaG_typeerror (lua_State *L, const TValue *o, + const char *opname); +LUAI_FUNC void luaG_concaterror (lua_State *L, StkId p1, StkId p2); +LUAI_FUNC void luaG_aritherror (lua_State *L, const TValue *p1, + const TValue *p2); +LUAI_FUNC int luaG_ordererror (lua_State *L, const TValue *p1, + const TValue *p2); +LUAI_FUNC void luaG_runerror (lua_State *L, const char *fmt, ...); +LUAI_FUNC void luaG_errormsg (lua_State *L); +LUAI_FUNC int luaG_checkcode (const Proto *pt); +LUAI_FUNC int luaG_checkopenop (Instruction i); + +#endif diff --git a/IOS/lua/lua/ldo.c b/IOS/lua/lua/ldo.c new file mode 100644 index 00000000..8de05f72 --- /dev/null +++ b/IOS/lua/lua/ldo.c @@ -0,0 +1,518 @@ +/* +** $Id: ldo.c,v 2.38.1.3 2008/01/18 22:31:22 roberto Exp $ +** Stack and Call structure of Lua +** See Copyright Notice in lua.h +*/ + + +#include +#include +#include + +#define ldo_c +#define LUA_CORE + +#include "lua.h" + +#include "ldebug.h" +#include "ldo.h" +#include "lfunc.h" +#include "lgc.h" +#include "lmem.h" +#include "lobject.h" +#include "lopcodes.h" +#include "lparser.h" +#include "lstate.h" +#include "lstring.h" +#include "ltable.h" +#include "ltm.h" +#include "lundump.h" +#include "lvm.h" +#include "lzio.h" + + + + +/* +** {====================================================== +** Error-recovery functions +** ======================================================= +*/ + + +/* chain list of long jump buffers */ +struct lua_longjmp { + struct lua_longjmp *previous; + luai_jmpbuf b; + volatile int status; /* error code */ +}; + + +void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop) { + switch (errcode) { + case LUA_ERRMEM: { + setsvalue2s(L, oldtop, luaS_newliteral(L, MEMERRMSG)); + break; + } + case LUA_ERRERR: { + setsvalue2s(L, oldtop, luaS_newliteral(L, "error in error handling")); + break; + } + case LUA_ERRSYNTAX: + case LUA_ERRRUN: { + setobjs2s(L, oldtop, L->top - 1); /* error message on current top */ + break; + } + } + L->top = oldtop + 1; +} + + +static void restore_stack_limit (lua_State *L) { + lua_assert(L->stack_last - L->stack == L->stacksize - EXTRA_STACK - 1); + if (L->size_ci > LUAI_MAXCALLS) { /* there was an overflow? */ + int inuse = cast_int(L->ci - L->base_ci); + if (inuse + 1 < LUAI_MAXCALLS) /* can `undo' overflow? */ + luaD_reallocCI(L, LUAI_MAXCALLS); + } +} + + +static void resetstack (lua_State *L, int status) { + L->ci = L->base_ci; + L->base = L->ci->base; + luaF_close(L, L->base); /* close eventual pending closures */ + luaD_seterrorobj(L, status, L->base); + L->nCcalls = L->baseCcalls; + L->allowhook = 1; + restore_stack_limit(L); + L->errfunc = 0; + L->errorJmp = NULL; +} + + +void luaD_throw (lua_State *L, int errcode) { + if (L->errorJmp) { + L->errorJmp->status = errcode; + LUAI_THROW(L, L->errorJmp); + } + else { + L->status = cast_byte(errcode); + if (G(L)->panic) { + resetstack(L, errcode); + lua_unlock(L); + G(L)->panic(L); + } + exit(EXIT_FAILURE); + } +} + + +int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud) { + struct lua_longjmp lj; + lj.status = 0; + lj.previous = L->errorJmp; /* chain new error handler */ + L->errorJmp = &lj; + LUAI_TRY(L, &lj, + (*f)(L, ud); + ); + L->errorJmp = lj.previous; /* restore old error handler */ + return lj.status; +} + +/* }====================================================== */ + + +static void correctstack (lua_State *L, TValue *oldstack) { + CallInfo *ci; + GCObject *up; + L->top = (L->top - oldstack) + L->stack; + for (up = L->openupval; up != NULL; up = up->gch.next) + gco2uv(up)->v = (gco2uv(up)->v - oldstack) + L->stack; + for (ci = L->base_ci; ci <= L->ci; ci++) { + ci->top = (ci->top - oldstack) + L->stack; + ci->base = (ci->base - oldstack) + L->stack; + ci->func = (ci->func - oldstack) + L->stack; + } + L->base = (L->base - oldstack) + L->stack; +} + + +void luaD_reallocstack (lua_State *L, int newsize) { + TValue *oldstack = L->stack; + int realsize = newsize + 1 + EXTRA_STACK; + lua_assert(L->stack_last - L->stack == L->stacksize - EXTRA_STACK - 1); + luaM_reallocvector(L, L->stack, L->stacksize, realsize, TValue); + L->stacksize = realsize; + L->stack_last = L->stack+newsize; + correctstack(L, oldstack); +} + + +void luaD_reallocCI (lua_State *L, int newsize) { + CallInfo *oldci = L->base_ci; + luaM_reallocvector(L, L->base_ci, L->size_ci, newsize, CallInfo); + L->size_ci = newsize; + L->ci = (L->ci - oldci) + L->base_ci; + L->end_ci = L->base_ci + L->size_ci - 1; +} + + +void luaD_growstack (lua_State *L, int n) { + if (n <= L->stacksize) /* double size is enough? */ + luaD_reallocstack(L, 2*L->stacksize); + else + luaD_reallocstack(L, L->stacksize + n); +} + + +static CallInfo *growCI (lua_State *L) { + if (L->size_ci > LUAI_MAXCALLS) /* overflow while handling overflow? */ + luaD_throw(L, LUA_ERRERR); + else { + luaD_reallocCI(L, 2*L->size_ci); + if (L->size_ci > LUAI_MAXCALLS) + luaG_runerror(L, "stack overflow"); + } + return ++L->ci; +} + + +void luaD_callhook (lua_State *L, int event, int line) { + lua_Hook hook = L->hook; + if (hook && L->allowhook) { + ptrdiff_t top = savestack(L, L->top); + ptrdiff_t ci_top = savestack(L, L->ci->top); + lua_Debug ar; + ar.event = event; + ar.currentline = line; + if (event == LUA_HOOKTAILRET) + ar.i_ci = 0; /* tail call; no debug information about it */ + else + ar.i_ci = cast_int(L->ci - L->base_ci); + luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */ + L->ci->top = L->top + LUA_MINSTACK; + lua_assert(L->ci->top <= L->stack_last); + L->allowhook = 0; /* cannot call hooks inside a hook */ + lua_unlock(L); + (*hook)(L, &ar); + lua_lock(L); + lua_assert(!L->allowhook); + L->allowhook = 1; + L->ci->top = restorestack(L, ci_top); + L->top = restorestack(L, top); + } +} + + +static StkId adjust_varargs (lua_State *L, Proto *p, int actual) { + int i; + int nfixargs = p->numparams; + Table *htab = NULL; + StkId base, fixed; + for (; actual < nfixargs; ++actual) + setnilvalue(L->top++); +#if defined(LUA_COMPAT_VARARG) + if (p->is_vararg & VARARG_NEEDSARG) { /* compat. with old-style vararg? */ + int nvar = actual - nfixargs; /* number of extra arguments */ + lua_assert(p->is_vararg & VARARG_HASARG); + luaC_checkGC(L); + htab = luaH_new(L, nvar, 1); /* create `arg' table */ + for (i=0; itop - nvar + i); + /* store counter in field `n' */ + setnvalue(luaH_setstr(L, htab, luaS_newliteral(L, "n")), cast_num(nvar)); + } +#endif + /* move fixed parameters to final position */ + fixed = L->top - actual; /* first fixed argument */ + base = L->top; /* final position of first argument */ + for (i=0; itop++, fixed+i); + setnilvalue(fixed+i); + } + /* add `arg' parameter */ + if (htab) { + sethvalue(L, L->top++, htab); + lua_assert(iswhite(obj2gco(htab))); + } + return base; +} + + +static StkId tryfuncTM (lua_State *L, StkId func) { + const TValue *tm = luaT_gettmbyobj(L, func, TM_CALL); + StkId p; + ptrdiff_t funcr = savestack(L, func); + if (!ttisfunction(tm)) + luaG_typeerror(L, func, "call"); + /* Open a hole inside the stack at `func' */ + for (p = L->top; p > func; p--) setobjs2s(L, p, p-1); + incr_top(L); + func = restorestack(L, funcr); /* previous call may change stack */ + setobj2s(L, func, tm); /* tag method is the new function to be called */ + return func; +} + + + +#define inc_ci(L) \ + ((L->ci == L->end_ci) ? growCI(L) : \ + (condhardstacktests(luaD_reallocCI(L, L->size_ci)), ++L->ci)) + + +int luaD_precall (lua_State *L, StkId func, int nresults) { + LClosure *cl; + ptrdiff_t funcr; + if (!ttisfunction(func)) /* `func' is not a function? */ + func = tryfuncTM(L, func); /* check the `function' tag method */ + funcr = savestack(L, func); + cl = &clvalue(func)->l; + L->ci->savedpc = L->savedpc; + if (!cl->isC) { /* Lua function? prepare its call */ + CallInfo *ci; + StkId st, base; + Proto *p = cl->p; + luaD_checkstack(L, p->maxstacksize); + func = restorestack(L, funcr); + if (!p->is_vararg) { /* no varargs? */ + base = func + 1; + if (L->top > base + p->numparams) + L->top = base + p->numparams; + } + else { /* vararg function */ + int nargs = cast_int(L->top - func) - 1; + base = adjust_varargs(L, p, nargs); + func = restorestack(L, funcr); /* previous call may change the stack */ + } + ci = inc_ci(L); /* now `enter' new function */ + ci->func = func; + L->base = ci->base = base; + ci->top = L->base + p->maxstacksize; + lua_assert(ci->top <= L->stack_last); + L->savedpc = p->code; /* starting point */ + ci->tailcalls = 0; + ci->nresults = nresults; + for (st = L->top; st < ci->top; st++) + setnilvalue(st); + L->top = ci->top; + if (L->hookmask & LUA_MASKCALL) { + L->savedpc++; /* hooks assume 'pc' is already incremented */ + luaD_callhook(L, LUA_HOOKCALL, -1); + L->savedpc--; /* correct 'pc' */ + } + return PCRLUA; + } + else { /* if is a C function, call it */ + CallInfo *ci; + int n; + luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */ + ci = inc_ci(L); /* now `enter' new function */ + ci->func = restorestack(L, funcr); + L->base = ci->base = ci->func + 1; + ci->top = L->top + LUA_MINSTACK; + lua_assert(ci->top <= L->stack_last); + ci->nresults = nresults; + if (L->hookmask & LUA_MASKCALL) + luaD_callhook(L, LUA_HOOKCALL, -1); + lua_unlock(L); + n = (*curr_func(L)->c.f)(L); /* do the actual call */ + lua_lock(L); + if (n < 0) /* yielding? */ + return PCRYIELD; + else { + luaD_poscall(L, L->top - n); + return PCRC; + } + } +} + + +static StkId callrethooks (lua_State *L, StkId firstResult) { + ptrdiff_t fr = savestack(L, firstResult); /* next call may change stack */ + luaD_callhook(L, LUA_HOOKRET, -1); + if (f_isLua(L->ci)) { /* Lua function? */ + while ((L->hookmask & LUA_MASKRET) && L->ci->tailcalls--) /* tail calls */ + luaD_callhook(L, LUA_HOOKTAILRET, -1); + } + return restorestack(L, fr); +} + + +int luaD_poscall (lua_State *L, StkId firstResult) { + StkId res; + int wanted, i; + CallInfo *ci; + if (L->hookmask & LUA_MASKRET) + firstResult = callrethooks(L, firstResult); + ci = L->ci--; + res = ci->func; /* res == final position of 1st result */ + wanted = ci->nresults; + L->base = (ci - 1)->base; /* restore base */ + L->savedpc = (ci - 1)->savedpc; /* restore savedpc */ + /* move results to correct place */ + for (i = wanted; i != 0 && firstResult < L->top; i--) + setobjs2s(L, res++, firstResult++); + while (i-- > 0) + setnilvalue(res++); + L->top = res; + return (wanted - LUA_MULTRET); /* 0 iff wanted == LUA_MULTRET */ +} + + +/* +** Call a function (C or Lua). The function to be called is at *func. +** The arguments are on the stack, right after the function. +** When returns, all the results are on the stack, starting at the original +** function position. +*/ +void luaD_call (lua_State *L, StkId func, int nResults) { + if (++L->nCcalls >= LUAI_MAXCCALLS) { + if (L->nCcalls == LUAI_MAXCCALLS) + luaG_runerror(L, "C stack overflow"); + else if (L->nCcalls >= (LUAI_MAXCCALLS + (LUAI_MAXCCALLS>>3))) + luaD_throw(L, LUA_ERRERR); /* error while handing stack error */ + } + if (luaD_precall(L, func, nResults) == PCRLUA) /* is a Lua function? */ + luaV_execute(L, 1); /* call it */ + L->nCcalls--; + luaC_checkGC(L); +} + + +static void resume (lua_State *L, void *ud) { + StkId firstArg = cast(StkId, ud); + CallInfo *ci = L->ci; + if (L->status == 0) { /* start coroutine? */ + lua_assert(ci == L->base_ci && firstArg > L->base); + if (luaD_precall(L, firstArg - 1, LUA_MULTRET) != PCRLUA) + return; + } + else { /* resuming from previous yield */ + lua_assert(L->status == LUA_YIELD); + L->status = 0; + if (!f_isLua(ci)) { /* `common' yield? */ + /* finish interrupted execution of `OP_CALL' */ + lua_assert(GET_OPCODE(*((ci-1)->savedpc - 1)) == OP_CALL || + GET_OPCODE(*((ci-1)->savedpc - 1)) == OP_TAILCALL); + if (luaD_poscall(L, firstArg)) /* complete it... */ + L->top = L->ci->top; /* and correct top if not multiple results */ + } + else /* yielded inside a hook: just continue its execution */ + L->base = L->ci->base; + } + luaV_execute(L, cast_int(L->ci - L->base_ci)); +} + + +static int resume_error (lua_State *L, const char *msg) { + L->top = L->ci->base; + setsvalue2s(L, L->top, luaS_new(L, msg)); + incr_top(L); + lua_unlock(L); + return LUA_ERRRUN; +} + + +LUA_API int lua_resume (lua_State *L, int nargs) { + int status; + lua_lock(L); + if (L->status != LUA_YIELD && (L->status != 0 || L->ci != L->base_ci)) + return resume_error(L, "cannot resume non-suspended coroutine"); + if (L->nCcalls >= LUAI_MAXCCALLS) + return resume_error(L, "C stack overflow"); + luai_userstateresume(L, nargs); + lua_assert(L->errfunc == 0); + L->baseCcalls = ++L->nCcalls; + status = luaD_rawrunprotected(L, resume, L->top - nargs); + if (status != 0) { /* error? */ + L->status = cast_byte(status); /* mark thread as `dead' */ + luaD_seterrorobj(L, status, L->top); + L->ci->top = L->top; + } + else { + lua_assert(L->nCcalls == L->baseCcalls); + status = L->status; + } + --L->nCcalls; + lua_unlock(L); + return status; +} + + +LUA_API int lua_yield (lua_State *L, int nresults) { + luai_userstateyield(L, nresults); + lua_lock(L); + if (L->nCcalls > L->baseCcalls) + luaG_runerror(L, "attempt to yield across metamethod/C-call boundary"); + L->base = L->top - nresults; /* protect stack slots below */ + L->status = LUA_YIELD; + lua_unlock(L); + return -1; +} + + +int luaD_pcall (lua_State *L, Pfunc func, void *u, + ptrdiff_t old_top, ptrdiff_t ef) { + int status; + unsigned short oldnCcalls = L->nCcalls; + ptrdiff_t old_ci = saveci(L, L->ci); + lu_byte old_allowhooks = L->allowhook; + ptrdiff_t old_errfunc = L->errfunc; + L->errfunc = ef; + status = luaD_rawrunprotected(L, func, u); + if (status != 0) { /* an error occurred? */ + StkId oldtop = restorestack(L, old_top); + luaF_close(L, oldtop); /* close eventual pending closures */ + luaD_seterrorobj(L, status, oldtop); + L->nCcalls = oldnCcalls; + L->ci = restoreci(L, old_ci); + L->base = L->ci->base; + L->savedpc = L->ci->savedpc; + L->allowhook = old_allowhooks; + restore_stack_limit(L); + } + L->errfunc = old_errfunc; + return status; +} + + + +/* +** Execute a protected parser. +*/ +struct SParser { /* data to `f_parser' */ + ZIO *z; + Mbuffer buff; /* buffer to be used by the scanner */ + const char *name; +}; + +static void f_parser (lua_State *L, void *ud) { + int i; + Proto *tf; + Closure *cl; + struct SParser *p = cast(struct SParser *, ud); + int c = luaZ_lookahead(p->z); + luaC_checkGC(L); + tf = ((c == LUA_SIGNATURE[0]) ? luaU_undump : luaY_parser)(L, p->z, + &p->buff, p->name); + cl = luaF_newLclosure(L, tf->nups, hvalue(gt(L))); + cl->l.p = tf; + for (i = 0; i < tf->nups; i++) /* initialize eventual upvalues */ + cl->l.upvals[i] = luaF_newupval(L); + setclvalue(L, L->top, cl); + incr_top(L); +} + + +int luaD_protectedparser (lua_State *L, ZIO *z, const char *name) { + struct SParser p; + int status; + p.z = z; p.name = name; + luaZ_initbuffer(L, &p.buff); + status = luaD_pcall(L, f_parser, &p, savestack(L, L->top), L->errfunc); + luaZ_freebuffer(L, &p.buff); + return status; +} + + diff --git a/IOS/lua/lua/ldo.h b/IOS/lua/lua/ldo.h new file mode 100644 index 00000000..98fddac5 --- /dev/null +++ b/IOS/lua/lua/ldo.h @@ -0,0 +1,57 @@ +/* +** $Id: ldo.h,v 2.7.1.1 2007/12/27 13:02:25 roberto Exp $ +** Stack and Call structure of Lua +** See Copyright Notice in lua.h +*/ + +#ifndef ldo_h +#define ldo_h + + +#include "lobject.h" +#include "lstate.h" +#include "lzio.h" + + +#define luaD_checkstack(L,n) \ + if ((char *)L->stack_last - (char *)L->top <= (n)*(int)sizeof(TValue)) \ + luaD_growstack(L, n); \ + else condhardstacktests(luaD_reallocstack(L, L->stacksize - EXTRA_STACK - 1)); + + +#define incr_top(L) {luaD_checkstack(L,1); L->top++;} + +#define savestack(L,p) ((char *)(p) - (char *)L->stack) +#define restorestack(L,n) ((TValue *)((char *)L->stack + (n))) + +#define saveci(L,p) ((char *)(p) - (char *)L->base_ci) +#define restoreci(L,n) ((CallInfo *)((char *)L->base_ci + (n))) + + +/* results from luaD_precall */ +#define PCRLUA 0 /* initiated a call to a Lua function */ +#define PCRC 1 /* did a call to a C function */ +#define PCRYIELD 2 /* C funtion yielded */ + + +/* type of protected functions, to be ran by `runprotected' */ +typedef void (*Pfunc) (lua_State *L, void *ud); + +LUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name); +LUAI_FUNC void luaD_callhook (lua_State *L, int event, int line); +LUAI_FUNC int luaD_precall (lua_State *L, StkId func, int nresults); +LUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults); +LUAI_FUNC int luaD_pcall (lua_State *L, Pfunc func, void *u, + ptrdiff_t oldtop, ptrdiff_t ef); +LUAI_FUNC int luaD_poscall (lua_State *L, StkId firstResult); +LUAI_FUNC void luaD_reallocCI (lua_State *L, int newsize); +LUAI_FUNC void luaD_reallocstack (lua_State *L, int newsize); +LUAI_FUNC void luaD_growstack (lua_State *L, int n); + +LUAI_FUNC void luaD_throw (lua_State *L, int errcode); +LUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud); + +LUAI_FUNC void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop); + +#endif + diff --git a/IOS/lua/lua/ldump.c b/IOS/lua/lua/ldump.c new file mode 100644 index 00000000..c9d3d487 --- /dev/null +++ b/IOS/lua/lua/ldump.c @@ -0,0 +1,164 @@ +/* +** $Id: ldump.c,v 2.8.1.1 2007/12/27 13:02:25 roberto Exp $ +** save precompiled Lua chunks +** See Copyright Notice in lua.h +*/ + +#include + +#define ldump_c +#define LUA_CORE + +#include "lua.h" + +#include "lobject.h" +#include "lstate.h" +#include "lundump.h" + +typedef struct { + lua_State* L; + lua_Writer writer; + void* data; + int strip; + int status; +} DumpState; + +#define DumpMem(b,n,size,D) DumpBlock(b,(n)*(size),D) +#define DumpVar(x,D) DumpMem(&x,1,sizeof(x),D) + +static void DumpBlock(const void* b, size_t size, DumpState* D) +{ + if (D->status==0) + { + lua_unlock(D->L); + D->status=(*D->writer)(D->L,b,size,D->data); + lua_lock(D->L); + } +} + +static void DumpChar(int y, DumpState* D) +{ + char x=(char)y; + DumpVar(x,D); +} + +static void DumpInt(int x, DumpState* D) +{ + DumpVar(x,D); +} + +static void DumpNumber(lua_Number x, DumpState* D) +{ + DumpVar(x,D); +} + +static void DumpVector(const void* b, int n, size_t size, DumpState* D) +{ + DumpInt(n,D); + DumpMem(b,n,size,D); +} + +static void DumpString(const TString* s, DumpState* D) +{ + if (s==NULL || getstr(s)==NULL) + { + size_t size=0; + DumpVar(size,D); + } + else + { + size_t size=s->tsv.len+1; /* include trailing '\0' */ + DumpVar(size,D); + DumpBlock(getstr(s),size,D); + } +} + +#define DumpCode(f,D) DumpVector(f->code,f->sizecode,sizeof(Instruction),D) + +static void DumpFunction(const Proto* f, const TString* p, DumpState* D); + +static void DumpConstants(const Proto* f, DumpState* D) +{ + int i,n=f->sizek; + DumpInt(n,D); + for (i=0; ik[i]; + DumpChar(ttype(o),D); + switch (ttype(o)) + { + case LUA_TNIL: + break; + case LUA_TBOOLEAN: + DumpChar(bvalue(o),D); + break; + case LUA_TNUMBER: + DumpNumber(nvalue(o),D); + break; + case LUA_TSTRING: + DumpString(rawtsvalue(o),D); + break; + default: + lua_assert(0); /* cannot happen */ + break; + } + } + n=f->sizep; + DumpInt(n,D); + for (i=0; ip[i],f->source,D); +} + +static void DumpDebug(const Proto* f, DumpState* D) +{ + int i,n; + n= (D->strip) ? 0 : f->sizelineinfo; + DumpVector(f->lineinfo,n,sizeof(int),D); + n= (D->strip) ? 0 : f->sizelocvars; + DumpInt(n,D); + for (i=0; ilocvars[i].varname,D); + DumpInt(f->locvars[i].startpc,D); + DumpInt(f->locvars[i].endpc,D); + } + n= (D->strip) ? 0 : f->sizeupvalues; + DumpInt(n,D); + for (i=0; iupvalues[i],D); +} + +static void DumpFunction(const Proto* f, const TString* p, DumpState* D) +{ + DumpString((f->source==p || D->strip) ? NULL : f->source,D); + DumpInt(f->linedefined,D); + DumpInt(f->lastlinedefined,D); + DumpChar(f->nups,D); + DumpChar(f->numparams,D); + DumpChar(f->is_vararg,D); + DumpChar(f->maxstacksize,D); + DumpCode(f,D); + DumpConstants(f,D); + DumpDebug(f,D); +} + +static void DumpHeader(DumpState* D) +{ + char h[LUAC_HEADERSIZE]; + luaU_header(h); + DumpBlock(h,LUAC_HEADERSIZE,D); +} + +/* +** dump Lua function as precompiled chunk +*/ +int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip) +{ + DumpState D; + D.L=L; + D.writer=w; + D.data=data; + D.strip=strip; + D.status=0; + DumpHeader(&D); + DumpFunction(f,NULL,&D); + return D.status; +} diff --git a/IOS/lua/lua/lfunc.c b/IOS/lua/lua/lfunc.c new file mode 100644 index 00000000..813e88f5 --- /dev/null +++ b/IOS/lua/lua/lfunc.c @@ -0,0 +1,174 @@ +/* +** $Id: lfunc.c,v 2.12.1.2 2007/12/28 14:58:43 roberto Exp $ +** Auxiliary functions to manipulate prototypes and closures +** See Copyright Notice in lua.h +*/ + + +#include + +#define lfunc_c +#define LUA_CORE + +#include "lua.h" + +#include "lfunc.h" +#include "lgc.h" +#include "lmem.h" +#include "lobject.h" +#include "lstate.h" + + + +Closure *luaF_newCclosure (lua_State *L, int nelems, Table *e) { + Closure *c = cast(Closure *, luaM_malloc(L, sizeCclosure(nelems))); + luaC_link(L, obj2gco(c), LUA_TFUNCTION); + c->c.isC = 1; + c->c.env = e; + c->c.nupvalues = cast_byte(nelems); + return c; +} + + +Closure *luaF_newLclosure (lua_State *L, int nelems, Table *e) { + Closure *c = cast(Closure *, luaM_malloc(L, sizeLclosure(nelems))); + luaC_link(L, obj2gco(c), LUA_TFUNCTION); + c->l.isC = 0; + c->l.env = e; + c->l.nupvalues = cast_byte(nelems); + while (nelems--) c->l.upvals[nelems] = NULL; + return c; +} + + +UpVal *luaF_newupval (lua_State *L) { + UpVal *uv = luaM_new(L, UpVal); + luaC_link(L, obj2gco(uv), LUA_TUPVAL); + uv->v = &uv->u.value; + setnilvalue(uv->v); + return uv; +} + + +UpVal *luaF_findupval (lua_State *L, StkId level) { + global_State *g = G(L); + GCObject **pp = &L->openupval; + UpVal *p; + UpVal *uv; + while (*pp != NULL && (p = ngcotouv(*pp))->v >= level) { + lua_assert(p->v != &p->u.value); + if (p->v == level) { /* found a corresponding upvalue? */ + if (isdead(g, obj2gco(p))) /* is it dead? */ + changewhite(obj2gco(p)); /* ressurect it */ + return p; + } + pp = &p->next; + } + uv = luaM_new(L, UpVal); /* not found: create a new one */ + uv->tt = LUA_TUPVAL; + uv->marked = luaC_white(g); + uv->v = level; /* current value lives in the stack */ + uv->next = *pp; /* chain it in the proper position */ + *pp = obj2gco(uv); + uv->u.l.prev = &g->uvhead; /* double link it in `uvhead' list */ + uv->u.l.next = g->uvhead.u.l.next; + uv->u.l.next->u.l.prev = uv; + g->uvhead.u.l.next = uv; + lua_assert(uv->u.l.next->u.l.prev == uv && uv->u.l.prev->u.l.next == uv); + return uv; +} + + +static void unlinkupval (UpVal *uv) { + lua_assert(uv->u.l.next->u.l.prev == uv && uv->u.l.prev->u.l.next == uv); + uv->u.l.next->u.l.prev = uv->u.l.prev; /* remove from `uvhead' list */ + uv->u.l.prev->u.l.next = uv->u.l.next; +} + + +void luaF_freeupval (lua_State *L, UpVal *uv) { + if (uv->v != &uv->u.value) /* is it open? */ + unlinkupval(uv); /* remove from open list */ + luaM_free(L, uv); /* free upvalue */ +} + + +void luaF_close (lua_State *L, StkId level) { + UpVal *uv; + global_State *g = G(L); + while (L->openupval != NULL && (uv = ngcotouv(L->openupval))->v >= level) { + GCObject *o = obj2gco(uv); + lua_assert(!isblack(o) && uv->v != &uv->u.value); + L->openupval = uv->next; /* remove from `open' list */ + if (isdead(g, o)) + luaF_freeupval(L, uv); /* free upvalue */ + else { + unlinkupval(uv); + setobj(L, &uv->u.value, uv->v); + uv->v = &uv->u.value; /* now current value lives here */ + luaC_linkupval(L, uv); /* link upvalue into `gcroot' list */ + } + } +} + + +Proto *luaF_newproto (lua_State *L) { + Proto *f = luaM_new(L, Proto); + luaC_link(L, obj2gco(f), LUA_TPROTO); + f->k = NULL; + f->sizek = 0; + f->p = NULL; + f->sizep = 0; + f->code = NULL; + f->sizecode = 0; + f->sizelineinfo = 0; + f->sizeupvalues = 0; + f->nups = 0; + f->upvalues = NULL; + f->numparams = 0; + f->is_vararg = 0; + f->maxstacksize = 0; + f->lineinfo = NULL; + f->sizelocvars = 0; + f->locvars = NULL; + f->linedefined = 0; + f->lastlinedefined = 0; + f->source = NULL; + return f; +} + + +void luaF_freeproto (lua_State *L, Proto *f) { + luaM_freearray(L, f->code, f->sizecode, Instruction); + luaM_freearray(L, f->p, f->sizep, Proto *); + luaM_freearray(L, f->k, f->sizek, TValue); + luaM_freearray(L, f->lineinfo, f->sizelineinfo, int); + luaM_freearray(L, f->locvars, f->sizelocvars, struct LocVar); + luaM_freearray(L, f->upvalues, f->sizeupvalues, TString *); + luaM_free(L, f); +} + + +void luaF_freeclosure (lua_State *L, Closure *c) { + int size = (c->c.isC) ? sizeCclosure(c->c.nupvalues) : + sizeLclosure(c->l.nupvalues); + luaM_freemem(L, c, size); +} + + +/* +** Look for n-th local variable at line `line' in function `func'. +** Returns NULL if not found. +*/ +const char *luaF_getlocalname (const Proto *f, int local_number, int pc) { + int i; + for (i = 0; isizelocvars && f->locvars[i].startpc <= pc; i++) { + if (pc < f->locvars[i].endpc) { /* is variable active? */ + local_number--; + if (local_number == 0) + return getstr(f->locvars[i].varname); + } + } + return NULL; /* not found */ +} + diff --git a/IOS/lua/lua/lfunc.h b/IOS/lua/lua/lfunc.h new file mode 100644 index 00000000..a68cf515 --- /dev/null +++ b/IOS/lua/lua/lfunc.h @@ -0,0 +1,34 @@ +/* +** $Id: lfunc.h,v 2.4.1.1 2007/12/27 13:02:25 roberto Exp $ +** Auxiliary functions to manipulate prototypes and closures +** See Copyright Notice in lua.h +*/ + +#ifndef lfunc_h +#define lfunc_h + + +#include "lobject.h" + + +#define sizeCclosure(n) (cast(int, sizeof(CClosure)) + \ + cast(int, sizeof(TValue)*((n)-1))) + +#define sizeLclosure(n) (cast(int, sizeof(LClosure)) + \ + cast(int, sizeof(TValue *)*((n)-1))) + + +LUAI_FUNC Proto *luaF_newproto (lua_State *L); +LUAI_FUNC Closure *luaF_newCclosure (lua_State *L, int nelems, Table *e); +LUAI_FUNC Closure *luaF_newLclosure (lua_State *L, int nelems, Table *e); +LUAI_FUNC UpVal *luaF_newupval (lua_State *L); +LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level); +LUAI_FUNC void luaF_close (lua_State *L, StkId level); +LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f); +LUAI_FUNC void luaF_freeclosure (lua_State *L, Closure *c); +LUAI_FUNC void luaF_freeupval (lua_State *L, UpVal *uv); +LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number, + int pc); + + +#endif diff --git a/IOS/lua/lua/lgc.c b/IOS/lua/lua/lgc.c new file mode 100644 index 00000000..d9e0b782 --- /dev/null +++ b/IOS/lua/lua/lgc.c @@ -0,0 +1,711 @@ +/* +** $Id: lgc.c,v 2.38.1.1 2007/12/27 13:02:25 roberto Exp $ +** Garbage Collector +** See Copyright Notice in lua.h +*/ + +#include + +#define lgc_c +#define LUA_CORE + +#include "lua.h" + +#include "ldebug.h" +#include "ldo.h" +#include "lfunc.h" +#include "lgc.h" +#include "lmem.h" +#include "lobject.h" +#include "lstate.h" +#include "lstring.h" +#include "ltable.h" +#include "ltm.h" + + +#define GCSTEPSIZE 1024u +#define GCSWEEPMAX 40 +#define GCSWEEPCOST 10 +#define GCFINALIZECOST 100 + + +#define maskmarks cast_byte(~(bitmask(BLACKBIT)|WHITEBITS)) + +#define makewhite(g,x) \ + ((x)->gch.marked = cast_byte(((x)->gch.marked & maskmarks) | luaC_white(g))) + +#define white2gray(x) reset2bits((x)->gch.marked, WHITE0BIT, WHITE1BIT) +#define black2gray(x) resetbit((x)->gch.marked, BLACKBIT) + +#define stringmark(s) reset2bits((s)->tsv.marked, WHITE0BIT, WHITE1BIT) + + +#define isfinalized(u) testbit((u)->marked, FINALIZEDBIT) +#define markfinalized(u) l_setbit((u)->marked, FINALIZEDBIT) + + +#define KEYWEAK bitmask(KEYWEAKBIT) +#define VALUEWEAK bitmask(VALUEWEAKBIT) + + + +#define markvalue(g,o) { checkconsistency(o); \ + if (iscollectable(o) && iswhite(gcvalue(o))) reallymarkobject(g,gcvalue(o)); } + +#define markobject(g,t) { if (iswhite(obj2gco(t))) \ + reallymarkobject(g, obj2gco(t)); } + + +#define setthreshold(g) (g->GCthreshold = (g->estimate/100) * g->gcpause) + + +static void removeentry (Node *n) { + lua_assert(ttisnil(gval(n))); + if (iscollectable(gkey(n))) + setttype(gkey(n), LUA_TDEADKEY); /* dead key; remove it */ +} + + +static void reallymarkobject (global_State *g, GCObject *o) { + lua_assert(iswhite(o) && !isdead(g, o)); + white2gray(o); + switch (o->gch.tt) { + case LUA_TSTRING: { + return; + } + case LUA_TUSERDATA: { + Table *mt = gco2u(o)->metatable; + gray2black(o); /* udata are never gray */ + if (mt) markobject(g, mt); + markobject(g, gco2u(o)->env); + return; + } + case LUA_TUPVAL: { + UpVal *uv = gco2uv(o); + markvalue(g, uv->v); + if (uv->v == &uv->u.value) /* closed? */ + gray2black(o); /* open upvalues are never black */ + return; + } + case LUA_TFUNCTION: { + gco2cl(o)->c.gclist = g->gray; + g->gray = o; + break; + } + case LUA_TTABLE: { + gco2h(o)->gclist = g->gray; + g->gray = o; + break; + } + case LUA_TTHREAD: { + gco2th(o)->gclist = g->gray; + g->gray = o; + break; + } + case LUA_TPROTO: { + gco2p(o)->gclist = g->gray; + g->gray = o; + break; + } + default: lua_assert(0); + } +} + + +static void marktmu (global_State *g) { + GCObject *u = g->tmudata; + if (u) { + do { + u = u->gch.next; + makewhite(g, u); /* may be marked, if left from previous GC */ + reallymarkobject(g, u); + } while (u != g->tmudata); + } +} + + +/* move `dead' udata that need finalization to list `tmudata' */ +size_t luaC_separateudata (lua_State *L, int all) { + global_State *g = G(L); + size_t deadmem = 0; + GCObject **p = &g->mainthread->next; + GCObject *curr; + while ((curr = *p) != NULL) { + if (!(iswhite(curr) || all) || isfinalized(gco2u(curr))) + p = &curr->gch.next; /* don't bother with them */ + else if (fasttm(L, gco2u(curr)->metatable, TM_GC) == NULL) { + markfinalized(gco2u(curr)); /* don't need finalization */ + p = &curr->gch.next; + } + else { /* must call its gc method */ + deadmem += sizeudata(gco2u(curr)); + markfinalized(gco2u(curr)); + *p = curr->gch.next; + /* link `curr' at the end of `tmudata' list */ + if (g->tmudata == NULL) /* list is empty? */ + g->tmudata = curr->gch.next = curr; /* creates a circular list */ + else { + curr->gch.next = g->tmudata->gch.next; + g->tmudata->gch.next = curr; + g->tmudata = curr; + } + } + } + return deadmem; +} + + +static int traversetable (global_State *g, Table *h) { + int i; + int weakkey = 0; + int weakvalue = 0; + const TValue *mode; + if (h->metatable) + markobject(g, h->metatable); + mode = gfasttm(g, h->metatable, TM_MODE); + if (mode && ttisstring(mode)) { /* is there a weak mode? */ + weakkey = (strchr(svalue(mode), 'k') != NULL); + weakvalue = (strchr(svalue(mode), 'v') != NULL); + if (weakkey || weakvalue) { /* is really weak? */ + h->marked &= ~(KEYWEAK | VALUEWEAK); /* clear bits */ + h->marked |= cast_byte((weakkey << KEYWEAKBIT) | + (weakvalue << VALUEWEAKBIT)); + h->gclist = g->weak; /* must be cleared after GC, ... */ + g->weak = obj2gco(h); /* ... so put in the appropriate list */ + } + } + if (weakkey && weakvalue) return 1; + if (!weakvalue) { + i = h->sizearray; + while (i--) + markvalue(g, &h->array[i]); + } + i = sizenode(h); + while (i--) { + Node *n = gnode(h, i); + lua_assert(ttype(gkey(n)) != LUA_TDEADKEY || ttisnil(gval(n))); + if (ttisnil(gval(n))) + removeentry(n); /* remove empty entries */ + else { + lua_assert(!ttisnil(gkey(n))); + if (!weakkey) markvalue(g, gkey(n)); + if (!weakvalue) markvalue(g, gval(n)); + } + } + return weakkey || weakvalue; +} + + +/* +** All marks are conditional because a GC may happen while the +** prototype is still being created +*/ +static void traverseproto (global_State *g, Proto *f) { + int i; + if (f->source) stringmark(f->source); + for (i=0; isizek; i++) /* mark literals */ + markvalue(g, &f->k[i]); + for (i=0; isizeupvalues; i++) { /* mark upvalue names */ + if (f->upvalues[i]) + stringmark(f->upvalues[i]); + } + for (i=0; isizep; i++) { /* mark nested protos */ + if (f->p[i]) + markobject(g, f->p[i]); + } + for (i=0; isizelocvars; i++) { /* mark local-variable names */ + if (f->locvars[i].varname) + stringmark(f->locvars[i].varname); + } +} + + + +static void traverseclosure (global_State *g, Closure *cl) { + markobject(g, cl->c.env); + if (cl->c.isC) { + int i; + for (i=0; ic.nupvalues; i++) /* mark its upvalues */ + markvalue(g, &cl->c.upvalue[i]); + } + else { + int i; + lua_assert(cl->l.nupvalues == cl->l.p->nups); + markobject(g, cl->l.p); + for (i=0; il.nupvalues; i++) /* mark its upvalues */ + markobject(g, cl->l.upvals[i]); + } +} + + +static void checkstacksizes (lua_State *L, StkId max) { + int ci_used = cast_int(L->ci - L->base_ci); /* number of `ci' in use */ + int s_used = cast_int(max - L->stack); /* part of stack in use */ + if (L->size_ci > LUAI_MAXCALLS) /* handling overflow? */ + return; /* do not touch the stacks */ + if (4*ci_used < L->size_ci && 2*BASIC_CI_SIZE < L->size_ci) + luaD_reallocCI(L, L->size_ci/2); /* still big enough... */ + condhardstacktests(luaD_reallocCI(L, ci_used + 1)); + if (4*s_used < L->stacksize && + 2*(BASIC_STACK_SIZE+EXTRA_STACK) < L->stacksize) + luaD_reallocstack(L, L->stacksize/2); /* still big enough... */ + condhardstacktests(luaD_reallocstack(L, s_used)); +} + + +static void traversestack (global_State *g, lua_State *l) { + StkId o, lim; + CallInfo *ci; + markvalue(g, gt(l)); + lim = l->top; + for (ci = l->base_ci; ci <= l->ci; ci++) { + lua_assert(ci->top <= l->stack_last); + if (lim < ci->top) lim = ci->top; + } + for (o = l->stack; o < l->top; o++) + markvalue(g, o); + for (; o <= lim; o++) + setnilvalue(o); + checkstacksizes(l, lim); +} + + +/* +** traverse one gray object, turning it to black. +** Returns `quantity' traversed. +*/ +static l_mem propagatemark (global_State *g) { + GCObject *o = g->gray; + lua_assert(isgray(o)); + gray2black(o); + switch (o->gch.tt) { + case LUA_TTABLE: { + Table *h = gco2h(o); + g->gray = h->gclist; + if (traversetable(g, h)) /* table is weak? */ + black2gray(o); /* keep it gray */ + return sizeof(Table) + sizeof(TValue) * h->sizearray + + sizeof(Node) * sizenode(h); + } + case LUA_TFUNCTION: { + Closure *cl = gco2cl(o); + g->gray = cl->c.gclist; + traverseclosure(g, cl); + return (cl->c.isC) ? sizeCclosure(cl->c.nupvalues) : + sizeLclosure(cl->l.nupvalues); + } + case LUA_TTHREAD: { + lua_State *th = gco2th(o); + g->gray = th->gclist; + th->gclist = g->grayagain; + g->grayagain = o; + black2gray(o); + traversestack(g, th); + return sizeof(lua_State) + sizeof(TValue) * th->stacksize + + sizeof(CallInfo) * th->size_ci; + } + case LUA_TPROTO: { + Proto *p = gco2p(o); + g->gray = p->gclist; + traverseproto(g, p); + return sizeof(Proto) + sizeof(Instruction) * p->sizecode + + sizeof(Proto *) * p->sizep + + sizeof(TValue) * p->sizek + + sizeof(int) * p->sizelineinfo + + sizeof(LocVar) * p->sizelocvars + + sizeof(TString *) * p->sizeupvalues; + } + default: lua_assert(0); return 0; + } +} + + +static size_t propagateall (global_State *g) { + size_t m = 0; + while (g->gray) m += propagatemark(g); + return m; +} + + +/* +** The next function tells whether a key or value can be cleared from +** a weak table. Non-collectable objects are never removed from weak +** tables. Strings behave as `values', so are never removed too. for +** other objects: if really collected, cannot keep them; for userdata +** being finalized, keep them in keys, but not in values +*/ +static int iscleared (const TValue *o, int iskey) { + if (!iscollectable(o)) return 0; + if (ttisstring(o)) { + stringmark(rawtsvalue(o)); /* strings are `values', so are never weak */ + return 0; + } + return iswhite(gcvalue(o)) || + (ttisuserdata(o) && (!iskey && isfinalized(uvalue(o)))); +} + + +/* +** clear collected entries from weaktables +*/ +static void cleartable (GCObject *l) { + while (l) { + Table *h = gco2h(l); + int i = h->sizearray; + lua_assert(testbit(h->marked, VALUEWEAKBIT) || + testbit(h->marked, KEYWEAKBIT)); + if (testbit(h->marked, VALUEWEAKBIT)) { + while (i--) { + TValue *o = &h->array[i]; + if (iscleared(o, 0)) /* value was collected? */ + setnilvalue(o); /* remove value */ + } + } + i = sizenode(h); + while (i--) { + Node *n = gnode(h, i); + if (!ttisnil(gval(n)) && /* non-empty entry? */ + (iscleared(key2tval(n), 1) || iscleared(gval(n), 0))) { + setnilvalue(gval(n)); /* remove value ... */ + removeentry(n); /* remove entry from table */ + } + } + l = h->gclist; + } +} + + +static void freeobj (lua_State *L, GCObject *o) { + switch (o->gch.tt) { + case LUA_TPROTO: luaF_freeproto(L, gco2p(o)); break; + case LUA_TFUNCTION: luaF_freeclosure(L, gco2cl(o)); break; + case LUA_TUPVAL: luaF_freeupval(L, gco2uv(o)); break; + case LUA_TTABLE: luaH_free(L, gco2h(o)); break; + case LUA_TTHREAD: { + lua_assert(gco2th(o) != L && gco2th(o) != G(L)->mainthread); + luaE_freethread(L, gco2th(o)); + break; + } + case LUA_TSTRING: { + G(L)->strt.nuse--; + luaM_freemem(L, o, sizestring(gco2ts(o))); + break; + } + case LUA_TUSERDATA: { + luaM_freemem(L, o, sizeudata(gco2u(o))); + break; + } + default: lua_assert(0); + } +} + + + +#define sweepwholelist(L,p) sweeplist(L,p,MAX_LUMEM) + + +static GCObject **sweeplist (lua_State *L, GCObject **p, lu_mem count) { + GCObject *curr; + global_State *g = G(L); + int deadmask = otherwhite(g); + while ((curr = *p) != NULL && count-- > 0) { + if (curr->gch.tt == LUA_TTHREAD) /* sweep open upvalues of each thread */ + sweepwholelist(L, &gco2th(curr)->openupval); + if ((curr->gch.marked ^ WHITEBITS) & deadmask) { /* not dead? */ + lua_assert(!isdead(g, curr) || testbit(curr->gch.marked, FIXEDBIT)); + makewhite(g, curr); /* make it white (for next cycle) */ + p = &curr->gch.next; + } + else { /* must erase `curr' */ + lua_assert(isdead(g, curr) || deadmask == bitmask(SFIXEDBIT)); + *p = curr->gch.next; + if (curr == g->rootgc) /* is the first element of the list? */ + g->rootgc = curr->gch.next; /* adjust first */ + freeobj(L, curr); + } + } + return p; +} + + +static void checkSizes (lua_State *L) { + global_State *g = G(L); + /* check size of string hash */ + if (g->strt.nuse < cast(lu_int32, g->strt.size/4) && + g->strt.size > MINSTRTABSIZE*2) + luaS_resize(L, g->strt.size/2); /* table is too big */ + /* check size of buffer */ + if (luaZ_sizebuffer(&g->buff) > LUA_MINBUFFER*2) { /* buffer too big? */ + size_t newsize = luaZ_sizebuffer(&g->buff) / 2; + luaZ_resizebuffer(L, &g->buff, newsize); + } +} + + +static void GCTM (lua_State *L) { + global_State *g = G(L); + GCObject *o = g->tmudata->gch.next; /* get first element */ + Udata *udata = rawgco2u(o); + const TValue *tm; + /* remove udata from `tmudata' */ + if (o == g->tmudata) /* last element? */ + g->tmudata = NULL; + else + g->tmudata->gch.next = udata->uv.next; + udata->uv.next = g->mainthread->next; /* return it to `root' list */ + g->mainthread->next = o; + makewhite(g, o); + tm = fasttm(L, udata->uv.metatable, TM_GC); + if (tm != NULL) { + lu_byte oldah = L->allowhook; + lu_mem oldt = g->GCthreshold; + L->allowhook = 0; /* stop debug hooks during GC tag method */ + g->GCthreshold = 2*g->totalbytes; /* avoid GC steps */ + setobj2s(L, L->top, tm); + setuvalue(L, L->top+1, udata); + L->top += 2; + luaD_call(L, L->top - 2, 0); + L->allowhook = oldah; /* restore hooks */ + g->GCthreshold = oldt; /* restore threshold */ + } +} + + +/* +** Call all GC tag methods +*/ +void luaC_callGCTM (lua_State *L) { + while (G(L)->tmudata) + GCTM(L); +} + + +void luaC_freeall (lua_State *L) { + global_State *g = G(L); + int i; + g->currentwhite = WHITEBITS | bitmask(SFIXEDBIT); /* mask to collect all elements */ + sweepwholelist(L, &g->rootgc); + for (i = 0; i < g->strt.size; i++) /* free all string lists */ + sweepwholelist(L, &g->strt.hash[i]); +} + + +static void markmt (global_State *g) { + int i; + for (i=0; imt[i]) markobject(g, g->mt[i]); +} + + +/* mark root set */ +static void markroot (lua_State *L) { + global_State *g = G(L); + g->gray = NULL; + g->grayagain = NULL; + g->weak = NULL; + markobject(g, g->mainthread); + /* make global table be traversed before main stack */ + markvalue(g, gt(g->mainthread)); + markvalue(g, registry(L)); + markmt(g); + g->gcstate = GCSpropagate; +} + + +static void remarkupvals (global_State *g) { + UpVal *uv; + for (uv = g->uvhead.u.l.next; uv != &g->uvhead; uv = uv->u.l.next) { + lua_assert(uv->u.l.next->u.l.prev == uv && uv->u.l.prev->u.l.next == uv); + if (isgray(obj2gco(uv))) + markvalue(g, uv->v); + } +} + + +static void atomic (lua_State *L) { + global_State *g = G(L); + size_t udsize; /* total size of userdata to be finalized */ + /* remark occasional upvalues of (maybe) dead threads */ + remarkupvals(g); + /* traverse objects cautch by write barrier and by 'remarkupvals' */ + propagateall(g); + /* remark weak tables */ + g->gray = g->weak; + g->weak = NULL; + lua_assert(!iswhite(obj2gco(g->mainthread))); + markobject(g, L); /* mark running thread */ + markmt(g); /* mark basic metatables (again) */ + propagateall(g); + /* remark gray again */ + g->gray = g->grayagain; + g->grayagain = NULL; + propagateall(g); + udsize = luaC_separateudata(L, 0); /* separate userdata to be finalized */ + marktmu(g); /* mark `preserved' userdata */ + udsize += propagateall(g); /* remark, to propagate `preserveness' */ + cleartable(g->weak); /* remove collected objects from weak tables */ + /* flip current white */ + g->currentwhite = cast_byte(otherwhite(g)); + g->sweepstrgc = 0; + g->sweepgc = &g->rootgc; + g->gcstate = GCSsweepstring; + g->estimate = g->totalbytes - udsize; /* first estimate */ +} + + +static l_mem singlestep (lua_State *L) { + global_State *g = G(L); + /*lua_checkmemory(L);*/ + switch (g->gcstate) { + case GCSpause: { + markroot(L); /* start a new collection */ + return 0; + } + case GCSpropagate: { + if (g->gray) + return propagatemark(g); + else { /* no more `gray' objects */ + atomic(L); /* finish mark phase */ + return 0; + } + } + case GCSsweepstring: { + lu_mem old = g->totalbytes; + sweepwholelist(L, &g->strt.hash[g->sweepstrgc++]); + if (g->sweepstrgc >= g->strt.size) /* nothing more to sweep? */ + g->gcstate = GCSsweep; /* end sweep-string phase */ + lua_assert(old >= g->totalbytes); + g->estimate -= old - g->totalbytes; + return GCSWEEPCOST; + } + case GCSsweep: { + lu_mem old = g->totalbytes; + g->sweepgc = sweeplist(L, g->sweepgc, GCSWEEPMAX); + if (*g->sweepgc == NULL) { /* nothing more to sweep? */ + checkSizes(L); + g->gcstate = GCSfinalize; /* end sweep phase */ + } + lua_assert(old >= g->totalbytes); + g->estimate -= old - g->totalbytes; + return GCSWEEPMAX*GCSWEEPCOST; + } + case GCSfinalize: { + if (g->tmudata) { + GCTM(L); + if (g->estimate > GCFINALIZECOST) + g->estimate -= GCFINALIZECOST; + return GCFINALIZECOST; + } + else { + g->gcstate = GCSpause; /* end collection */ + g->gcdept = 0; + return 0; + } + } + default: lua_assert(0); return 0; + } +} + + +void luaC_step (lua_State *L) { + global_State *g = G(L); + l_mem lim = (GCSTEPSIZE/100) * g->gcstepmul; + if (lim == 0) + lim = (MAX_LUMEM-1)/2; /* no limit */ + g->gcdept += g->totalbytes - g->GCthreshold; + do { + lim -= singlestep(L); + if (g->gcstate == GCSpause) + break; + } while (lim > 0); + if (g->gcstate != GCSpause) { + if (g->gcdept < GCSTEPSIZE) + g->GCthreshold = g->totalbytes + GCSTEPSIZE; /* - lim/g->gcstepmul;*/ + else { + g->gcdept -= GCSTEPSIZE; + g->GCthreshold = g->totalbytes; + } + } + else { + lua_assert(g->totalbytes >= g->estimate); + setthreshold(g); + } +} + + +void luaC_fullgc (lua_State *L) { + global_State *g = G(L); + if (g->gcstate <= GCSpropagate) { + /* reset sweep marks to sweep all elements (returning them to white) */ + g->sweepstrgc = 0; + g->sweepgc = &g->rootgc; + /* reset other collector lists */ + g->gray = NULL; + g->grayagain = NULL; + g->weak = NULL; + g->gcstate = GCSsweepstring; + } + lua_assert(g->gcstate != GCSpause && g->gcstate != GCSpropagate); + /* finish any pending sweep phase */ + while (g->gcstate != GCSfinalize) { + lua_assert(g->gcstate == GCSsweepstring || g->gcstate == GCSsweep); + singlestep(L); + } + markroot(L); + while (g->gcstate != GCSpause) { + singlestep(L); + } + setthreshold(g); +} + + +void luaC_barrierf (lua_State *L, GCObject *o, GCObject *v) { + global_State *g = G(L); + lua_assert(isblack(o) && iswhite(v) && !isdead(g, v) && !isdead(g, o)); + lua_assert(g->gcstate != GCSfinalize && g->gcstate != GCSpause); + lua_assert(ttype(&o->gch) != LUA_TTABLE); + /* must keep invariant? */ + if (g->gcstate == GCSpropagate) + reallymarkobject(g, v); /* restore invariant */ + else /* don't mind */ + makewhite(g, o); /* mark as white just to avoid other barriers */ +} + + +void luaC_barrierback (lua_State *L, Table *t) { + global_State *g = G(L); + GCObject *o = obj2gco(t); + lua_assert(isblack(o) && !isdead(g, o)); + lua_assert(g->gcstate != GCSfinalize && g->gcstate != GCSpause); + black2gray(o); /* make table gray (again) */ + t->gclist = g->grayagain; + g->grayagain = o; +} + + +void luaC_link (lua_State *L, GCObject *o, lu_byte tt) { + global_State *g = G(L); + o->gch.next = g->rootgc; + g->rootgc = o; + o->gch.marked = luaC_white(g); + o->gch.tt = tt; +} + + +void luaC_linkupval (lua_State *L, UpVal *uv) { + global_State *g = G(L); + GCObject *o = obj2gco(uv); + o->gch.next = g->rootgc; /* link upvalue into `rootgc' list */ + g->rootgc = o; + if (isgray(o)) { + if (g->gcstate == GCSpropagate) { + gray2black(o); /* closed upvalues need barrier */ + luaC_barrier(L, uv, uv->v); + } + else { /* sweep phase: sweep it (turning it into white) */ + makewhite(g, o); + lua_assert(g->gcstate != GCSfinalize && g->gcstate != GCSpause); + } + } +} + diff --git a/IOS/lua/lua/lgc.h b/IOS/lua/lua/lgc.h new file mode 100644 index 00000000..5a8dc605 --- /dev/null +++ b/IOS/lua/lua/lgc.h @@ -0,0 +1,110 @@ +/* +** $Id: lgc.h,v 2.15.1.1 2007/12/27 13:02:25 roberto Exp $ +** Garbage Collector +** See Copyright Notice in lua.h +*/ + +#ifndef lgc_h +#define lgc_h + + +#include "lobject.h" + + +/* +** Possible states of the Garbage Collector +*/ +#define GCSpause 0 +#define GCSpropagate 1 +#define GCSsweepstring 2 +#define GCSsweep 3 +#define GCSfinalize 4 + + +/* +** some userful bit tricks +*/ +#define resetbits(x,m) ((x) &= cast(lu_byte, ~(m))) +#define setbits(x,m) ((x) |= (m)) +#define testbits(x,m) ((x) & (m)) +#define bitmask(b) (1<<(b)) +#define bit2mask(b1,b2) (bitmask(b1) | bitmask(b2)) +#define l_setbit(x,b) setbits(x, bitmask(b)) +#define resetbit(x,b) resetbits(x, bitmask(b)) +#define testbit(x,b) testbits(x, bitmask(b)) +#define set2bits(x,b1,b2) setbits(x, (bit2mask(b1, b2))) +#define reset2bits(x,b1,b2) resetbits(x, (bit2mask(b1, b2))) +#define test2bits(x,b1,b2) testbits(x, (bit2mask(b1, b2))) + + + +/* +** Layout for bit use in `marked' field: +** bit 0 - object is white (type 0) +** bit 1 - object is white (type 1) +** bit 2 - object is black +** bit 3 - for userdata: has been finalized +** bit 3 - for tables: has weak keys +** bit 4 - for tables: has weak values +** bit 5 - object is fixed (should not be collected) +** bit 6 - object is "super" fixed (only the main thread) +*/ + + +#define WHITE0BIT 0 +#define WHITE1BIT 1 +#define BLACKBIT 2 +#define FINALIZEDBIT 3 +#define KEYWEAKBIT 3 +#define VALUEWEAKBIT 4 +#define FIXEDBIT 5 +#define SFIXEDBIT 6 +#define WHITEBITS bit2mask(WHITE0BIT, WHITE1BIT) + + +#define iswhite(x) test2bits((x)->gch.marked, WHITE0BIT, WHITE1BIT) +#define isblack(x) testbit((x)->gch.marked, BLACKBIT) +#define isgray(x) (!isblack(x) && !iswhite(x)) + +#define otherwhite(g) (g->currentwhite ^ WHITEBITS) +#define isdead(g,v) ((v)->gch.marked & otherwhite(g) & WHITEBITS) + +#define changewhite(x) ((x)->gch.marked ^= WHITEBITS) +#define gray2black(x) l_setbit((x)->gch.marked, BLACKBIT) + +#define valiswhite(x) (iscollectable(x) && iswhite(gcvalue(x))) + +#define luaC_white(g) cast(lu_byte, (g)->currentwhite & WHITEBITS) + + +#define luaC_checkGC(L) { \ + condhardstacktests(luaD_reallocstack(L, L->stacksize - EXTRA_STACK - 1)); \ + if (G(L)->totalbytes >= G(L)->GCthreshold) \ + luaC_step(L); } + + +#define luaC_barrier(L,p,v) { if (valiswhite(v) && isblack(obj2gco(p))) \ + luaC_barrierf(L,obj2gco(p),gcvalue(v)); } + +#define luaC_barriert(L,t,v) { if (valiswhite(v) && isblack(obj2gco(t))) \ + luaC_barrierback(L,t); } + +#define luaC_objbarrier(L,p,o) \ + { if (iswhite(obj2gco(o)) && isblack(obj2gco(p))) \ + luaC_barrierf(L,obj2gco(p),obj2gco(o)); } + +#define luaC_objbarriert(L,t,o) \ + { if (iswhite(obj2gco(o)) && isblack(obj2gco(t))) luaC_barrierback(L,t); } + +LUAI_FUNC size_t luaC_separateudata (lua_State *L, int all); +LUAI_FUNC void luaC_callGCTM (lua_State *L); +LUAI_FUNC void luaC_freeall (lua_State *L); +LUAI_FUNC void luaC_step (lua_State *L); +LUAI_FUNC void luaC_fullgc (lua_State *L); +LUAI_FUNC void luaC_link (lua_State *L, GCObject *o, lu_byte tt); +LUAI_FUNC void luaC_linkupval (lua_State *L, UpVal *uv); +LUAI_FUNC void luaC_barrierf (lua_State *L, GCObject *o, GCObject *v); +LUAI_FUNC void luaC_barrierback (lua_State *L, Table *t); + + +#endif diff --git a/IOS/lua/lua/linit.c b/IOS/lua/lua/linit.c new file mode 100644 index 00000000..c1f90dfa --- /dev/null +++ b/IOS/lua/lua/linit.c @@ -0,0 +1,38 @@ +/* +** $Id: linit.c,v 1.14.1.1 2007/12/27 13:02:25 roberto Exp $ +** Initialization of libraries for lua.c +** See Copyright Notice in lua.h +*/ + + +#define linit_c +#define LUA_LIB + +#include "lua.h" + +#include "lualib.h" +#include "lauxlib.h" + + +static const luaL_Reg lualibs[] = { + {"", luaopen_base}, + {LUA_LOADLIBNAME, luaopen_package}, + {LUA_TABLIBNAME, luaopen_table}, + {LUA_IOLIBNAME, luaopen_io}, + {LUA_OSLIBNAME, luaopen_os}, + {LUA_STRLIBNAME, luaopen_string}, + {LUA_MATHLIBNAME, luaopen_math}, + {LUA_DBLIBNAME, luaopen_debug}, + {NULL, NULL} +}; + + +LUALIB_API void luaL_openlibs (lua_State *L) { + const luaL_Reg *lib = lualibs; + for (; lib->func; lib++) { + lua_pushcfunction(L, lib->func); + lua_pushstring(L, lib->name); + lua_call(L, 1, 0); + } +} + diff --git a/IOS/lua/lua/liolib.c b/IOS/lua/lua/liolib.c new file mode 100644 index 00000000..e79ed1cb --- /dev/null +++ b/IOS/lua/lua/liolib.c @@ -0,0 +1,553 @@ +/* +** $Id: liolib.c,v 2.73.1.3 2008/01/18 17:47:43 roberto Exp $ +** Standard I/O (and system) library +** See Copyright Notice in lua.h +*/ + + +#include +#include +#include +#include + +#define liolib_c +#define LUA_LIB + +#include "lua.h" + +#include "lauxlib.h" +#include "lualib.h" + + + +#define IO_INPUT 1 +#define IO_OUTPUT 2 + + +static const char *const fnames[] = {"input", "output"}; + + +static int pushresult (lua_State *L, int i, const char *filename) { + int en = errno; /* calls to Lua API may change this value */ + if (i) { + lua_pushboolean(L, 1); + return 1; + } + else { + lua_pushnil(L); + if (filename) + lua_pushfstring(L, "%s: %s", filename, strerror(en)); + else + lua_pushfstring(L, "%s", strerror(en)); + lua_pushinteger(L, en); + return 3; + } +} + + +static void fileerror (lua_State *L, int arg, const char *filename) { + lua_pushfstring(L, "%s: %s", filename, strerror(errno)); + luaL_argerror(L, arg, lua_tostring(L, -1)); +} + + +#define tofilep(L) ((FILE **)luaL_checkudata(L, 1, LUA_FILEHANDLE)) + + +static int io_type (lua_State *L) { + void *ud; + luaL_checkany(L, 1); + ud = lua_touserdata(L, 1); + lua_getfield(L, LUA_REGISTRYINDEX, LUA_FILEHANDLE); + if (ud == NULL || !lua_getmetatable(L, 1) || !lua_rawequal(L, -2, -1)) + lua_pushnil(L); /* not a file */ + else if (*((FILE **)ud) == NULL) + lua_pushliteral(L, "closed file"); + else + lua_pushliteral(L, "file"); + return 1; +} + + +static FILE *tofile (lua_State *L) { + FILE **f = tofilep(L); + if (*f == NULL) + luaL_error(L, "attempt to use a closed file"); + return *f; +} + + + +/* +** When creating file handles, always creates a `closed' file handle +** before opening the actual file; so, if there is a memory error, the +** file is not left opened. +*/ +static FILE **newfile (lua_State *L) { + FILE **pf = (FILE **)lua_newuserdata(L, sizeof(FILE *)); + *pf = NULL; /* file handle is currently `closed' */ + luaL_getmetatable(L, LUA_FILEHANDLE); + lua_setmetatable(L, -2); + return pf; +} + + +/* +** function to (not) close the standard files stdin, stdout, and stderr +*/ +static int io_noclose (lua_State *L) { + lua_pushnil(L); + lua_pushliteral(L, "cannot close standard file"); + return 2; +} + + +/* +** function to close 'popen' files +*/ +static int io_pclose (lua_State *L) { + FILE **p = tofilep(L); + int ok = lua_pclose(L, *p); + *p = NULL; + return pushresult(L, ok, NULL); +} + + +/* +** function to close regular files +*/ +static int io_fclose (lua_State *L) { + FILE **p = tofilep(L); + int ok = (fclose(*p) == 0); + *p = NULL; + return pushresult(L, ok, NULL); +} + + +static int aux_close (lua_State *L) { + lua_getfenv(L, 1); + lua_getfield(L, -1, "__close"); + return (lua_tocfunction(L, -1))(L); +} + + +static int io_close (lua_State *L) { + if (lua_isnone(L, 1)) + lua_rawgeti(L, LUA_ENVIRONINDEX, IO_OUTPUT); + tofile(L); /* make sure argument is a file */ + return aux_close(L); +} + + +static int io_gc (lua_State *L) { + FILE *f = *tofilep(L); + /* ignore closed files */ + if (f != NULL) + aux_close(L); + return 0; +} + + +static int io_tostring (lua_State *L) { + FILE *f = *tofilep(L); + if (f == NULL) + lua_pushliteral(L, "file (closed)"); + else + lua_pushfstring(L, "file (%p)", f); + return 1; +} + + +static int io_open (lua_State *L) { + const char *filename = luaL_checkstring(L, 1); + const char *mode = luaL_optstring(L, 2, "r"); + FILE **pf = newfile(L); + *pf = fopen(filename, mode); + return (*pf == NULL) ? pushresult(L, 0, filename) : 1; +} + + +/* +** this function has a separated environment, which defines the +** correct __close for 'popen' files +*/ +static int io_popen (lua_State *L) { + const char *filename = luaL_checkstring(L, 1); + const char *mode = luaL_optstring(L, 2, "r"); + FILE **pf = newfile(L); + *pf = lua_popen(L, filename, mode); + return (*pf == NULL) ? pushresult(L, 0, filename) : 1; +} + + +static int io_tmpfile (lua_State *L) { + FILE **pf = newfile(L); + *pf = tmpfile(); + return (*pf == NULL) ? pushresult(L, 0, NULL) : 1; +} + + +static FILE *getiofile (lua_State *L, int findex) { + FILE *f; + lua_rawgeti(L, LUA_ENVIRONINDEX, findex); + f = *(FILE **)lua_touserdata(L, -1); + if (f == NULL) + luaL_error(L, "standard %s file is closed", fnames[findex - 1]); + return f; +} + + +static int g_iofile (lua_State *L, int f, const char *mode) { + if (!lua_isnoneornil(L, 1)) { + const char *filename = lua_tostring(L, 1); + if (filename) { + FILE **pf = newfile(L); + *pf = fopen(filename, mode); + if (*pf == NULL) + fileerror(L, 1, filename); + } + else { + tofile(L); /* check that it's a valid file handle */ + lua_pushvalue(L, 1); + } + lua_rawseti(L, LUA_ENVIRONINDEX, f); + } + /* return current value */ + lua_rawgeti(L, LUA_ENVIRONINDEX, f); + return 1; +} + + +static int io_input (lua_State *L) { + return g_iofile(L, IO_INPUT, "r"); +} + + +static int io_output (lua_State *L) { + return g_iofile(L, IO_OUTPUT, "w"); +} + + +static int io_readline (lua_State *L); + + +static void aux_lines (lua_State *L, int idx, int toclose) { + lua_pushvalue(L, idx); + lua_pushboolean(L, toclose); /* close/not close file when finished */ + lua_pushcclosure(L, io_readline, 2); +} + + +static int f_lines (lua_State *L) { + tofile(L); /* check that it's a valid file handle */ + aux_lines(L, 1, 0); + return 1; +} + + +static int io_lines (lua_State *L) { + if (lua_isnoneornil(L, 1)) { /* no arguments? */ + /* will iterate over default input */ + lua_rawgeti(L, LUA_ENVIRONINDEX, IO_INPUT); + return f_lines(L); + } + else { + const char *filename = luaL_checkstring(L, 1); + FILE **pf = newfile(L); + *pf = fopen(filename, "r"); + if (*pf == NULL) + fileerror(L, 1, filename); + aux_lines(L, lua_gettop(L), 1); + return 1; + } +} + + +/* +** {====================================================== +** READ +** ======================================================= +*/ + + +static int read_number (lua_State *L, FILE *f) { + lua_Number d; + if (fscanf(f, LUA_NUMBER_SCAN, &d) == 1) { + lua_pushnumber(L, d); + return 1; + } + else return 0; /* read fails */ +} + + +static int test_eof (lua_State *L, FILE *f) { + int c = getc(f); + ungetc(c, f); + lua_pushlstring(L, NULL, 0); + return (c != EOF); +} + + +static int read_line (lua_State *L, FILE *f) { + luaL_Buffer b; + luaL_buffinit(L, &b); + for (;;) { + size_t l; + char *p = luaL_prepbuffer(&b); + if (fgets(p, LUAL_BUFFERSIZE, f) == NULL) { /* eof? */ + luaL_pushresult(&b); /* close buffer */ + return (lua_objlen(L, -1) > 0); /* check whether read something */ + } + l = strlen(p); + if (l == 0 || p[l-1] != '\n') + luaL_addsize(&b, l); + else { + luaL_addsize(&b, l - 1); /* do not include `eol' */ + luaL_pushresult(&b); /* close buffer */ + return 1; /* read at least an `eol' */ + } + } +} + + +static int read_chars (lua_State *L, FILE *f, size_t n) { + size_t rlen; /* how much to read */ + size_t nr; /* number of chars actually read */ + luaL_Buffer b; + luaL_buffinit(L, &b); + rlen = LUAL_BUFFERSIZE; /* try to read that much each time */ + do { + char *p = luaL_prepbuffer(&b); + if (rlen > n) rlen = n; /* cannot read more than asked */ + nr = fread(p, sizeof(char), rlen, f); + luaL_addsize(&b, nr); + n -= nr; /* still have to read `n' chars */ + } while (n > 0 && nr == rlen); /* until end of count or eof */ + luaL_pushresult(&b); /* close buffer */ + return (n == 0 || lua_objlen(L, -1) > 0); +} + + +static int g_read (lua_State *L, FILE *f, int first) { + int nargs = lua_gettop(L) - 1; + int success; + int n; + clearerr(f); + if (nargs == 0) { /* no arguments? */ + success = read_line(L, f); + n = first+1; /* to return 1 result */ + } + else { /* ensure stack space for all results and for auxlib's buffer */ + luaL_checkstack(L, nargs+LUA_MINSTACK, "too many arguments"); + success = 1; + for (n = first; nargs-- && success; n++) { + if (lua_type(L, n) == LUA_TNUMBER) { + size_t l = (size_t)lua_tointeger(L, n); + success = (l == 0) ? test_eof(L, f) : read_chars(L, f, l); + } + else { + const char *p = lua_tostring(L, n); + luaL_argcheck(L, p && p[0] == '*', n, "invalid option"); + switch (p[1]) { + case 'n': /* number */ + success = read_number(L, f); + break; + case 'l': /* line */ + success = read_line(L, f); + break; + case 'a': /* file */ + read_chars(L, f, ~((size_t)0)); /* read MAX_SIZE_T chars */ + success = 1; /* always success */ + break; + default: + return luaL_argerror(L, n, "invalid format"); + } + } + } + } + if (ferror(f)) + return pushresult(L, 0, NULL); + if (!success) { + lua_pop(L, 1); /* remove last result */ + lua_pushnil(L); /* push nil instead */ + } + return n - first; +} + + +static int io_read (lua_State *L) { + return g_read(L, getiofile(L, IO_INPUT), 1); +} + + +static int f_read (lua_State *L) { + return g_read(L, tofile(L), 2); +} + + +static int io_readline (lua_State *L) { + FILE *f = *(FILE **)lua_touserdata(L, lua_upvalueindex(1)); + int sucess; + if (f == NULL) /* file is already closed? */ + luaL_error(L, "file is already closed"); + sucess = read_line(L, f); + if (ferror(f)) + return luaL_error(L, "%s", strerror(errno)); + if (sucess) return 1; + else { /* EOF */ + if (lua_toboolean(L, lua_upvalueindex(2))) { /* generator created file? */ + lua_settop(L, 0); + lua_pushvalue(L, lua_upvalueindex(1)); + aux_close(L); /* close it */ + } + return 0; + } +} + +/* }====================================================== */ + + +static int g_write (lua_State *L, FILE *f, int arg) { + int nargs = lua_gettop(L) - 1; + int status = 1; + for (; nargs--; arg++) { + if (lua_type(L, arg) == LUA_TNUMBER) { + /* optimization: could be done exactly as for strings */ + status = status && + fprintf(f, LUA_NUMBER_FMT, lua_tonumber(L, arg)) > 0; + } + else { + size_t l; + const char *s = luaL_checklstring(L, arg, &l); + status = status && (fwrite(s, sizeof(char), l, f) == l); + } + } + return pushresult(L, status, NULL); +} + + +static int io_write (lua_State *L) { + return g_write(L, getiofile(L, IO_OUTPUT), 1); +} + + +static int f_write (lua_State *L) { + return g_write(L, tofile(L), 2); +} + + +static int f_seek (lua_State *L) { + static const int mode[] = {SEEK_SET, SEEK_CUR, SEEK_END}; + static const char *const modenames[] = {"set", "cur", "end", NULL}; + FILE *f = tofile(L); + int op = luaL_checkoption(L, 2, "cur", modenames); + long offset = luaL_optlong(L, 3, 0); + op = fseek(f, offset, mode[op]); + if (op) + return pushresult(L, 0, NULL); /* error */ + else { + lua_pushinteger(L, ftell(f)); + return 1; + } +} + + +static int f_setvbuf (lua_State *L) { + static const int mode[] = {_IONBF, _IOFBF, _IOLBF}; + static const char *const modenames[] = {"no", "full", "line", NULL}; + FILE *f = tofile(L); + int op = luaL_checkoption(L, 2, NULL, modenames); + lua_Integer sz = luaL_optinteger(L, 3, LUAL_BUFFERSIZE); + int res = setvbuf(f, NULL, mode[op], sz); + return pushresult(L, res == 0, NULL); +} + + + +static int io_flush (lua_State *L) { + return pushresult(L, fflush(getiofile(L, IO_OUTPUT)) == 0, NULL); +} + + +static int f_flush (lua_State *L) { + return pushresult(L, fflush(tofile(L)) == 0, NULL); +} + + +static const luaL_Reg iolib[] = { + {"close", io_close}, + {"flush", io_flush}, + {"input", io_input}, + {"lines", io_lines}, + {"open", io_open}, + {"output", io_output}, + {"popen", io_popen}, + {"read", io_read}, + {"tmpfile", io_tmpfile}, + {"type", io_type}, + {"write", io_write}, + {NULL, NULL} +}; + + +static const luaL_Reg flib[] = { + {"close", io_close}, + {"flush", f_flush}, + {"lines", f_lines}, + {"read", f_read}, + {"seek", f_seek}, + {"setvbuf", f_setvbuf}, + {"write", f_write}, + {"__gc", io_gc}, + {"__tostring", io_tostring}, + {NULL, NULL} +}; + + +static void createmeta (lua_State *L) { + luaL_newmetatable(L, LUA_FILEHANDLE); /* create metatable for file handles */ + lua_pushvalue(L, -1); /* push metatable */ + lua_setfield(L, -2, "__index"); /* metatable.__index = metatable */ + luaL_register(L, NULL, flib); /* file methods */ +} + + +static void createstdfile (lua_State *L, FILE *f, int k, const char *fname) { + *newfile(L) = f; + if (k > 0) { + lua_pushvalue(L, -1); + lua_rawseti(L, LUA_ENVIRONINDEX, k); + } + lua_pushvalue(L, -2); /* copy environment */ + lua_setfenv(L, -2); /* set it */ + lua_setfield(L, -3, fname); +} + + +static void newfenv (lua_State *L, lua_CFunction cls) { + lua_createtable(L, 0, 1); + lua_pushcfunction(L, cls); + lua_setfield(L, -2, "__close"); +} + + +LUALIB_API int luaopen_io (lua_State *L) { + createmeta(L); + /* create (private) environment (with fields IO_INPUT, IO_OUTPUT, __close) */ + newfenv(L, io_fclose); + lua_replace(L, LUA_ENVIRONINDEX); + /* open library */ + luaL_register(L, LUA_IOLIBNAME, iolib); + /* create (and set) default files */ + newfenv(L, io_noclose); /* close function for default files */ + createstdfile(L, stdin, IO_INPUT, "stdin"); + createstdfile(L, stdout, IO_OUTPUT, "stdout"); + createstdfile(L, stderr, 0, "stderr"); + lua_pop(L, 1); /* pop environment for default files */ + lua_getfield(L, -1, "popen"); + newfenv(L, io_pclose); /* create environment for 'popen' */ + lua_setfenv(L, -2); /* set fenv for 'popen' */ + lua_pop(L, 1); /* pop 'popen' */ + return 1; +} + diff --git a/IOS/lua/lua/llex.c b/IOS/lua/lua/llex.c new file mode 100644 index 00000000..6dc31935 --- /dev/null +++ b/IOS/lua/lua/llex.c @@ -0,0 +1,461 @@ +/* +** $Id: llex.c,v 2.20.1.1 2007/12/27 13:02:25 roberto Exp $ +** Lexical Analyzer +** See Copyright Notice in lua.h +*/ + + +#include +#include +#include + +#define llex_c +#define LUA_CORE + +#include "lua.h" + +#include "ldo.h" +#include "llex.h" +#include "lobject.h" +#include "lparser.h" +#include "lstate.h" +#include "lstring.h" +#include "ltable.h" +#include "lzio.h" + + + +#define next(ls) (ls->current = zgetc(ls->z)) + + + + +#define currIsNewline(ls) (ls->current == '\n' || ls->current == '\r') + + +/* ORDER RESERVED */ +const char *const luaX_tokens [] = { + "and", "break", "do", "else", "elseif", + "end", "false", "for", "function", "if", + "in", "local", "nil", "not", "or", "repeat", + "return", "then", "true", "until", "while", + "..", "...", "==", ">=", "<=", "~=", + "", "", "", "", + NULL +}; + + +#define save_and_next(ls) (save(ls, ls->current), next(ls)) + + +static void save (LexState *ls, int c) { + Mbuffer *b = ls->buff; + if (b->n + 1 > b->buffsize) { + size_t newsize; + if (b->buffsize >= MAX_SIZET/2) + luaX_lexerror(ls, "lexical element too long", 0); + newsize = b->buffsize * 2; + luaZ_resizebuffer(ls->L, b, newsize); + } + b->buffer[b->n++] = cast(char, c); +} + + +void luaX_init (lua_State *L) { + int i; + for (i=0; itsv.reserved = cast_byte(i+1); /* reserved word */ + } +} + + +#define MAXSRC 80 + + +const char *luaX_token2str (LexState *ls, int token) { + if (token < FIRST_RESERVED) { + lua_assert(token == cast(unsigned char, token)); + return (iscntrl(token)) ? luaO_pushfstring(ls->L, "char(%d)", token) : + luaO_pushfstring(ls->L, "%c", token); + } + else + return luaX_tokens[token-FIRST_RESERVED]; +} + + +static const char *txtToken (LexState *ls, int token) { + switch (token) { + case TK_NAME: + case TK_STRING: + case TK_NUMBER: + save(ls, '\0'); + return luaZ_buffer(ls->buff); + default: + return luaX_token2str(ls, token); + } +} + + +void luaX_lexerror (LexState *ls, const char *msg, int token) { + char buff[MAXSRC]; + luaO_chunkid(buff, getstr(ls->source), MAXSRC); + msg = luaO_pushfstring(ls->L, "%s:%d: %s", buff, ls->linenumber, msg); + if (token) + luaO_pushfstring(ls->L, "%s near " LUA_QS, msg, txtToken(ls, token)); + luaD_throw(ls->L, LUA_ERRSYNTAX); +} + + +void luaX_syntaxerror (LexState *ls, const char *msg) { + luaX_lexerror(ls, msg, ls->t.token); +} + + +TString *luaX_newstring (LexState *ls, const char *str, size_t l) { + lua_State *L = ls->L; + TString *ts = luaS_newlstr(L, str, l); + TValue *o = luaH_setstr(L, ls->fs->h, ts); /* entry for `str' */ + if (ttisnil(o)) + setbvalue(o, 1); /* make sure `str' will not be collected */ + return ts; +} + + +static void inclinenumber (LexState *ls) { + int old = ls->current; + lua_assert(currIsNewline(ls)); + next(ls); /* skip `\n' or `\r' */ + if (currIsNewline(ls) && ls->current != old) + next(ls); /* skip `\n\r' or `\r\n' */ + if (++ls->linenumber >= MAX_INT) + luaX_syntaxerror(ls, "chunk has too many lines"); +} + + +void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source) { + ls->decpoint = '.'; + ls->L = L; + ls->lookahead.token = TK_EOS; /* no look-ahead token */ + ls->z = z; + ls->fs = NULL; + ls->linenumber = 1; + ls->lastline = 1; + ls->source = source; + luaZ_resizebuffer(ls->L, ls->buff, LUA_MINBUFFER); /* initialize buffer */ + next(ls); /* read first char */ +} + + + +/* +** ======================================================= +** LEXICAL ANALYZER +** ======================================================= +*/ + + + +static int check_next (LexState *ls, const char *set) { + if (!strchr(set, ls->current)) + return 0; + save_and_next(ls); + return 1; +} + + +static void buffreplace (LexState *ls, char from, char to) { + size_t n = luaZ_bufflen(ls->buff); + char *p = luaZ_buffer(ls->buff); + while (n--) + if (p[n] == from) p[n] = to; +} + + +static void trydecpoint (LexState *ls, SemInfo *seminfo) { + /* format error: try to update decimal point separator */ + struct lconv *cv = localeconv(); + char old = ls->decpoint; + ls->decpoint = (cv ? cv->decimal_point[0] : '.'); + buffreplace(ls, old, ls->decpoint); /* try updated decimal separator */ + if (!luaO_str2d(luaZ_buffer(ls->buff), &seminfo->r)) { + /* format error with correct decimal point: no more options */ + buffreplace(ls, ls->decpoint, '.'); /* undo change (for error message) */ + luaX_lexerror(ls, "malformed number", TK_NUMBER); + } +} + + +/* LUA_NUMBER */ +static void read_numeral (LexState *ls, SemInfo *seminfo) { + lua_assert(isdigit(ls->current)); + do { + save_and_next(ls); + } while (isdigit(ls->current) || ls->current == '.'); + if (check_next(ls, "Ee")) /* `E'? */ + check_next(ls, "+-"); /* optional exponent sign */ + while (isalnum(ls->current) || ls->current == '_') + save_and_next(ls); + save(ls, '\0'); + buffreplace(ls, '.', ls->decpoint); /* follow locale for decimal point */ + if (!luaO_str2d(luaZ_buffer(ls->buff), &seminfo->r)) /* format error? */ + trydecpoint(ls, seminfo); /* try to update decimal point separator */ +} + + +static int skip_sep (LexState *ls) { + int count = 0; + int s = ls->current; + lua_assert(s == '[' || s == ']'); + save_and_next(ls); + while (ls->current == '=') { + save_and_next(ls); + count++; + } + return (ls->current == s) ? count : (-count) - 1; +} + + +static void read_long_string (LexState *ls, SemInfo *seminfo, int sep) { + int cont = 0; + (void)(cont); /* avoid warnings when `cont' is not used */ + save_and_next(ls); /* skip 2nd `[' */ + if (currIsNewline(ls)) /* string starts with a newline? */ + inclinenumber(ls); /* skip it */ + for (;;) { + switch (ls->current) { + case EOZ: + luaX_lexerror(ls, (seminfo) ? "unfinished long string" : + "unfinished long comment", TK_EOS); + break; /* to avoid warnings */ +#if defined(LUA_COMPAT_LSTR) + case '[': { + if (skip_sep(ls) == sep) { + save_and_next(ls); /* skip 2nd `[' */ + cont++; +#if LUA_COMPAT_LSTR == 1 + if (sep == 0) + luaX_lexerror(ls, "nesting of [[...]] is deprecated", '['); +#endif + } + break; + } +#endif + case ']': { + if (skip_sep(ls) == sep) { + save_and_next(ls); /* skip 2nd `]' */ +#if defined(LUA_COMPAT_LSTR) && LUA_COMPAT_LSTR == 2 + cont--; + if (sep == 0 && cont >= 0) break; +#endif + goto endloop; + } + break; + } + case '\n': + case '\r': { + save(ls, '\n'); + inclinenumber(ls); + if (!seminfo) luaZ_resetbuffer(ls->buff); /* avoid wasting space */ + break; + } + default: { + if (seminfo) save_and_next(ls); + else next(ls); + } + } + } endloop: + if (seminfo) + seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + (2 + sep), + luaZ_bufflen(ls->buff) - 2*(2 + sep)); +} + + +static void read_string (LexState *ls, int del, SemInfo *seminfo) { + save_and_next(ls); + while (ls->current != del) { + switch (ls->current) { + case EOZ: + luaX_lexerror(ls, "unfinished string", TK_EOS); + continue; /* to avoid warnings */ + case '\n': + case '\r': + luaX_lexerror(ls, "unfinished string", TK_STRING); + continue; /* to avoid warnings */ + case '\\': { + int c; + next(ls); /* do not save the `\' */ + switch (ls->current) { + case 'a': c = '\a'; break; + case 'b': c = '\b'; break; + case 'f': c = '\f'; break; + case 'n': c = '\n'; break; + case 'r': c = '\r'; break; + case 't': c = '\t'; break; + case 'v': c = '\v'; break; + case '\n': /* go through */ + case '\r': save(ls, '\n'); inclinenumber(ls); continue; + case EOZ: continue; /* will raise an error next loop */ + default: { + if (!isdigit(ls->current)) + save_and_next(ls); /* handles \\, \", \', and \? */ + else { /* \xxx */ + int i = 0; + c = 0; + do { + c = 10*c + (ls->current-'0'); + next(ls); + } while (++i<3 && isdigit(ls->current)); + if (c > UCHAR_MAX) + luaX_lexerror(ls, "escape sequence too large", TK_STRING); + save(ls, c); + } + continue; + } + } + save(ls, c); + next(ls); + continue; + } + default: + save_and_next(ls); + } + } + save_and_next(ls); /* skip delimiter */ + seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + 1, + luaZ_bufflen(ls->buff) - 2); +} + + +static int llex (LexState *ls, SemInfo *seminfo) { + luaZ_resetbuffer(ls->buff); + for (;;) { + switch (ls->current) { + case '\n': + case '\r': { + inclinenumber(ls); + continue; + } + case '-': { + next(ls); + if (ls->current != '-') return '-'; + /* else is a comment */ + next(ls); + if (ls->current == '[') { + int sep = skip_sep(ls); + luaZ_resetbuffer(ls->buff); /* `skip_sep' may dirty the buffer */ + if (sep >= 0) { + read_long_string(ls, NULL, sep); /* long comment */ + luaZ_resetbuffer(ls->buff); + continue; + } + } + /* else short comment */ + while (!currIsNewline(ls) && ls->current != EOZ) + next(ls); + continue; + } + case '[': { + int sep = skip_sep(ls); + if (sep >= 0) { + read_long_string(ls, seminfo, sep); + return TK_STRING; + } + else if (sep == -1) return '['; + else luaX_lexerror(ls, "invalid long string delimiter", TK_STRING); + } + case '=': { + next(ls); + if (ls->current != '=') return '='; + else { next(ls); return TK_EQ; } + } + case '<': { + next(ls); + if (ls->current != '=') return '<'; + else { next(ls); return TK_LE; } + } + case '>': { + next(ls); + if (ls->current != '=') return '>'; + else { next(ls); return TK_GE; } + } + case '~': { + next(ls); + if (ls->current != '=') return '~'; + else { next(ls); return TK_NE; } + } + case '"': + case '\'': { + read_string(ls, ls->current, seminfo); + return TK_STRING; + } + case '.': { + save_and_next(ls); + if (check_next(ls, ".")) { + if (check_next(ls, ".")) + return TK_DOTS; /* ... */ + else return TK_CONCAT; /* .. */ + } + else if (!isdigit(ls->current)) return '.'; + else { + read_numeral(ls, seminfo); + return TK_NUMBER; + } + } + case EOZ: { + return TK_EOS; + } + default: { + if (isspace(ls->current)) { + lua_assert(!currIsNewline(ls)); + next(ls); + continue; + } + else if (isdigit(ls->current)) { + read_numeral(ls, seminfo); + return TK_NUMBER; + } + else if (isalpha(ls->current) || ls->current == '_') { + /* identifier or reserved word */ + TString *ts; + do { + save_and_next(ls); + } while (isalnum(ls->current) || ls->current == '_'); + ts = luaX_newstring(ls, luaZ_buffer(ls->buff), + luaZ_bufflen(ls->buff)); + if (ts->tsv.reserved > 0) /* reserved word? */ + return ts->tsv.reserved - 1 + FIRST_RESERVED; + else { + seminfo->ts = ts; + return TK_NAME; + } + } + else { + int c = ls->current; + next(ls); + return c; /* single-char tokens (+ - / ...) */ + } + } + } + } +} + + +void luaX_next (LexState *ls) { + ls->lastline = ls->linenumber; + if (ls->lookahead.token != TK_EOS) { /* is there a look-ahead token? */ + ls->t = ls->lookahead; /* use this one */ + ls->lookahead.token = TK_EOS; /* and discharge it */ + } + else + ls->t.token = llex(ls, &ls->t.seminfo); /* read next token */ +} + + +void luaX_lookahead (LexState *ls) { + lua_assert(ls->lookahead.token == TK_EOS); + ls->lookahead.token = llex(ls, &ls->lookahead.seminfo); +} + diff --git a/IOS/lua/lua/llex.h b/IOS/lua/lua/llex.h new file mode 100644 index 00000000..a9201cee --- /dev/null +++ b/IOS/lua/lua/llex.h @@ -0,0 +1,81 @@ +/* +** $Id: llex.h,v 1.58.1.1 2007/12/27 13:02:25 roberto Exp $ +** Lexical Analyzer +** See Copyright Notice in lua.h +*/ + +#ifndef llex_h +#define llex_h + +#include "lobject.h" +#include "lzio.h" + + +#define FIRST_RESERVED 257 + +/* maximum length of a reserved word */ +#define TOKEN_LEN (sizeof("function")/sizeof(char)) + + +/* +* WARNING: if you change the order of this enumeration, +* grep "ORDER RESERVED" +*/ +enum RESERVED { + /* terminal symbols denoted by reserved words */ + TK_AND = FIRST_RESERVED, TK_BREAK, + TK_DO, TK_ELSE, TK_ELSEIF, TK_END, TK_FALSE, TK_FOR, TK_FUNCTION, + TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT, + TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE, + /* other terminal symbols */ + TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, TK_NUMBER, + TK_NAME, TK_STRING, TK_EOS +}; + +/* number of reserved words */ +#define NUM_RESERVED (cast(int, TK_WHILE-FIRST_RESERVED+1)) + + +/* array with token `names' */ +LUAI_DATA const char *const luaX_tokens []; + + +typedef union { + lua_Number r; + TString *ts; +} SemInfo; /* semantics information */ + + +typedef struct Token { + int token; + SemInfo seminfo; +} Token; + + +typedef struct LexState { + int current; /* current character (charint) */ + int linenumber; /* input line counter */ + int lastline; /* line of last token `consumed' */ + Token t; /* current token */ + Token lookahead; /* look ahead token */ + struct FuncState *fs; /* `FuncState' is private to the parser */ + struct lua_State *L; + ZIO *z; /* input stream */ + Mbuffer *buff; /* buffer for tokens */ + TString *source; /* current source name */ + char decpoint; /* locale decimal point */ +} LexState; + + +LUAI_FUNC void luaX_init (lua_State *L); +LUAI_FUNC void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, + TString *source); +LUAI_FUNC TString *luaX_newstring (LexState *ls, const char *str, size_t l); +LUAI_FUNC void luaX_next (LexState *ls); +LUAI_FUNC void luaX_lookahead (LexState *ls); +LUAI_FUNC void luaX_lexerror (LexState *ls, const char *msg, int token); +LUAI_FUNC void luaX_syntaxerror (LexState *ls, const char *s); +LUAI_FUNC const char *luaX_token2str (LexState *ls, int token); + + +#endif diff --git a/IOS/lua/lua/llimits.h b/IOS/lua/lua/llimits.h new file mode 100644 index 00000000..ca8dcb72 --- /dev/null +++ b/IOS/lua/lua/llimits.h @@ -0,0 +1,128 @@ +/* +** $Id: llimits.h,v 1.69.1.1 2007/12/27 13:02:25 roberto Exp $ +** Limits, basic types, and some other `installation-dependent' definitions +** See Copyright Notice in lua.h +*/ + +#ifndef llimits_h +#define llimits_h + + +#include +#include + + +#include "lua.h" + + +typedef LUAI_UINT32 lu_int32; + +typedef LUAI_UMEM lu_mem; + +typedef LUAI_MEM l_mem; + + + +/* chars used as small naturals (so that `char' is reserved for characters) */ +typedef unsigned char lu_byte; + + +#define MAX_SIZET ((size_t)(~(size_t)0)-2) + +#define MAX_LUMEM ((lu_mem)(~(lu_mem)0)-2) + + +#define MAX_INT (INT_MAX-2) /* maximum value of an int (-2 for safety) */ + +/* +** conversion of pointer to integer +** this is for hashing only; there is no problem if the integer +** cannot hold the whole pointer value +*/ +#define IntPoint(p) ((unsigned int)(lu_mem)(p)) + + + +/* type to ensure maximum alignment */ +typedef LUAI_USER_ALIGNMENT_T L_Umaxalign; + + +/* result of a `usual argument conversion' over lua_Number */ +typedef LUAI_UACNUMBER l_uacNumber; + + +/* internal assertions for in-house debugging */ +#ifdef lua_assert + +#define check_exp(c,e) (lua_assert(c), (e)) +#define api_check(l,e) lua_assert(e) + +#else + +#define lua_assert(c) ((void)0) +#define check_exp(c,e) (e) +#define api_check luai_apicheck + +#endif + + +#ifndef UNUSED +#define UNUSED(x) ((void)(x)) /* to avoid warnings */ +#endif + + +#ifndef cast +#define cast(t, exp) ((t)(exp)) +#endif + +#define cast_byte(i) cast(lu_byte, (i)) +#define cast_num(i) cast(lua_Number, (i)) +#define cast_int(i) cast(int, (i)) + + + +/* +** type for virtual-machine instructions +** must be an unsigned with (at least) 4 bytes (see details in lopcodes.h) +*/ +typedef lu_int32 Instruction; + + + +/* maximum stack for a Lua function */ +#define MAXSTACK 250 + + + +/* minimum size for the string table (must be power of 2) */ +#ifndef MINSTRTABSIZE +#define MINSTRTABSIZE 32 +#endif + + +/* minimum size for string buffer */ +#ifndef LUA_MINBUFFER +#define LUA_MINBUFFER 32 +#endif + + +#ifndef lua_lock +#define lua_lock(L) ((void) 0) +#define lua_unlock(L) ((void) 0) +#endif + +#ifndef luai_threadyield +#define luai_threadyield(L) {lua_unlock(L); lua_lock(L);} +#endif + + +/* +** macro to control inclusion of some hard tests on stack reallocation +*/ +#ifndef HARDSTACKTESTS +#define condhardstacktests(x) ((void)0) +#else +#define condhardstacktests(x) x +#endif + +#endif diff --git a/IOS/lua/lua/lmathlib.c b/IOS/lua/lua/lmathlib.c new file mode 100644 index 00000000..441fbf73 --- /dev/null +++ b/IOS/lua/lua/lmathlib.c @@ -0,0 +1,263 @@ +/* +** $Id: lmathlib.c,v 1.67.1.1 2007/12/27 13:02:25 roberto Exp $ +** Standard mathematical library +** See Copyright Notice in lua.h +*/ + + +#include +#include + +#define lmathlib_c +#define LUA_LIB + +#include "lua.h" + +#include "lauxlib.h" +#include "lualib.h" + + +#undef PI +#define PI (3.14159265358979323846) +#define RADIANS_PER_DEGREE (PI/180.0) + + + +static int math_abs (lua_State *L) { + lua_pushnumber(L, fabs(luaL_checknumber(L, 1))); + return 1; +} + +static int math_sin (lua_State *L) { + lua_pushnumber(L, sin(luaL_checknumber(L, 1))); + return 1; +} + +static int math_sinh (lua_State *L) { + lua_pushnumber(L, sinh(luaL_checknumber(L, 1))); + return 1; +} + +static int math_cos (lua_State *L) { + lua_pushnumber(L, cos(luaL_checknumber(L, 1))); + return 1; +} + +static int math_cosh (lua_State *L) { + lua_pushnumber(L, cosh(luaL_checknumber(L, 1))); + return 1; +} + +static int math_tan (lua_State *L) { + lua_pushnumber(L, tan(luaL_checknumber(L, 1))); + return 1; +} + +static int math_tanh (lua_State *L) { + lua_pushnumber(L, tanh(luaL_checknumber(L, 1))); + return 1; +} + +static int math_asin (lua_State *L) { + lua_pushnumber(L, asin(luaL_checknumber(L, 1))); + return 1; +} + +static int math_acos (lua_State *L) { + lua_pushnumber(L, acos(luaL_checknumber(L, 1))); + return 1; +} + +static int math_atan (lua_State *L) { + lua_pushnumber(L, atan(luaL_checknumber(L, 1))); + return 1; +} + +static int math_atan2 (lua_State *L) { + lua_pushnumber(L, atan2(luaL_checknumber(L, 1), luaL_checknumber(L, 2))); + return 1; +} + +static int math_ceil (lua_State *L) { + lua_pushnumber(L, ceil(luaL_checknumber(L, 1))); + return 1; +} + +static int math_floor (lua_State *L) { + lua_pushnumber(L, floor(luaL_checknumber(L, 1))); + return 1; +} + +static int math_fmod (lua_State *L) { + lua_pushnumber(L, fmod(luaL_checknumber(L, 1), luaL_checknumber(L, 2))); + return 1; +} + +static int math_modf (lua_State *L) { + double ip; + double fp = modf(luaL_checknumber(L, 1), &ip); + lua_pushnumber(L, ip); + lua_pushnumber(L, fp); + return 2; +} + +static int math_sqrt (lua_State *L) { + lua_pushnumber(L, sqrt(luaL_checknumber(L, 1))); + return 1; +} + +static int math_pow (lua_State *L) { + lua_pushnumber(L, pow(luaL_checknumber(L, 1), luaL_checknumber(L, 2))); + return 1; +} + +static int math_log (lua_State *L) { + lua_pushnumber(L, log(luaL_checknumber(L, 1))); + return 1; +} + +static int math_log10 (lua_State *L) { + lua_pushnumber(L, log10(luaL_checknumber(L, 1))); + return 1; +} + +static int math_exp (lua_State *L) { + lua_pushnumber(L, exp(luaL_checknumber(L, 1))); + return 1; +} + +static int math_deg (lua_State *L) { + lua_pushnumber(L, luaL_checknumber(L, 1)/RADIANS_PER_DEGREE); + return 1; +} + +static int math_rad (lua_State *L) { + lua_pushnumber(L, luaL_checknumber(L, 1)*RADIANS_PER_DEGREE); + return 1; +} + +static int math_frexp (lua_State *L) { + int e; + lua_pushnumber(L, frexp(luaL_checknumber(L, 1), &e)); + lua_pushinteger(L, e); + return 2; +} + +static int math_ldexp (lua_State *L) { + lua_pushnumber(L, ldexp(luaL_checknumber(L, 1), luaL_checkint(L, 2))); + return 1; +} + + + +static int math_min (lua_State *L) { + int n = lua_gettop(L); /* number of arguments */ + lua_Number dmin = luaL_checknumber(L, 1); + int i; + for (i=2; i<=n; i++) { + lua_Number d = luaL_checknumber(L, i); + if (d < dmin) + dmin = d; + } + lua_pushnumber(L, dmin); + return 1; +} + + +static int math_max (lua_State *L) { + int n = lua_gettop(L); /* number of arguments */ + lua_Number dmax = luaL_checknumber(L, 1); + int i; + for (i=2; i<=n; i++) { + lua_Number d = luaL_checknumber(L, i); + if (d > dmax) + dmax = d; + } + lua_pushnumber(L, dmax); + return 1; +} + + +static int math_random (lua_State *L) { + /* the `%' avoids the (rare) case of r==1, and is needed also because on + some systems (SunOS!) `rand()' may return a value larger than RAND_MAX */ + lua_Number r = (lua_Number)(rand()%RAND_MAX) / (lua_Number)RAND_MAX; + switch (lua_gettop(L)) { /* check number of arguments */ + case 0: { /* no arguments */ + lua_pushnumber(L, r); /* Number between 0 and 1 */ + break; + } + case 1: { /* only upper limit */ + int u = luaL_checkint(L, 1); + luaL_argcheck(L, 1<=u, 1, "interval is empty"); + lua_pushnumber(L, floor(r*u)+1); /* int between 1 and `u' */ + break; + } + case 2: { /* lower and upper limits */ + int l = luaL_checkint(L, 1); + int u = luaL_checkint(L, 2); + luaL_argcheck(L, l<=u, 2, "interval is empty"); + lua_pushnumber(L, floor(r*(u-l+1))+l); /* int between `l' and `u' */ + break; + } + default: return luaL_error(L, "wrong number of arguments"); + } + return 1; +} + + +static int math_randomseed (lua_State *L) { + srand(luaL_checkint(L, 1)); + return 0; +} + + +static const luaL_Reg mathlib[] = { + {"abs", math_abs}, + {"acos", math_acos}, + {"asin", math_asin}, + {"atan2", math_atan2}, + {"atan", math_atan}, + {"ceil", math_ceil}, + {"cosh", math_cosh}, + {"cos", math_cos}, + {"deg", math_deg}, + {"exp", math_exp}, + {"floor", math_floor}, + {"fmod", math_fmod}, + {"frexp", math_frexp}, + {"ldexp", math_ldexp}, + {"log10", math_log10}, + {"log", math_log}, + {"max", math_max}, + {"min", math_min}, + {"modf", math_modf}, + {"pow", math_pow}, + {"rad", math_rad}, + {"random", math_random}, + {"randomseed", math_randomseed}, + {"sinh", math_sinh}, + {"sin", math_sin}, + {"sqrt", math_sqrt}, + {"tanh", math_tanh}, + {"tan", math_tan}, + {NULL, NULL} +}; + + +/* +** Open math library +*/ +LUALIB_API int luaopen_math (lua_State *L) { + luaL_register(L, LUA_MATHLIBNAME, mathlib); + lua_pushnumber(L, PI); + lua_setfield(L, -2, "pi"); + lua_pushnumber(L, HUGE_VAL); + lua_setfield(L, -2, "huge"); +#if defined(LUA_COMPAT_MOD) + lua_getfield(L, -1, "fmod"); + lua_setfield(L, -2, "mod"); +#endif + return 1; +} + diff --git a/IOS/lua/lua/lmem.c b/IOS/lua/lua/lmem.c new file mode 100644 index 00000000..ae7d8c96 --- /dev/null +++ b/IOS/lua/lua/lmem.c @@ -0,0 +1,86 @@ +/* +** $Id: lmem.c,v 1.70.1.1 2007/12/27 13:02:25 roberto Exp $ +** Interface to Memory Manager +** See Copyright Notice in lua.h +*/ + + +#include + +#define lmem_c +#define LUA_CORE + +#include "lua.h" + +#include "ldebug.h" +#include "ldo.h" +#include "lmem.h" +#include "lobject.h" +#include "lstate.h" + + + +/* +** About the realloc function: +** void * frealloc (void *ud, void *ptr, size_t osize, size_t nsize); +** (`osize' is the old size, `nsize' is the new size) +** +** Lua ensures that (ptr == NULL) iff (osize == 0). +** +** * frealloc(ud, NULL, 0, x) creates a new block of size `x' +** +** * frealloc(ud, p, x, 0) frees the block `p' +** (in this specific case, frealloc must return NULL). +** particularly, frealloc(ud, NULL, 0, 0) does nothing +** (which is equivalent to free(NULL) in ANSI C) +** +** frealloc returns NULL if it cannot create or reallocate the area +** (any reallocation to an equal or smaller size cannot fail!) +*/ + + + +#define MINSIZEARRAY 4 + + +void *luaM_growaux_ (lua_State *L, void *block, int *size, size_t size_elems, + int limit, const char *errormsg) { + void *newblock; + int newsize; + if (*size >= limit/2) { /* cannot double it? */ + if (*size >= limit) /* cannot grow even a little? */ + luaG_runerror(L, errormsg); + newsize = limit; /* still have at least one free place */ + } + else { + newsize = (*size)*2; + if (newsize < MINSIZEARRAY) + newsize = MINSIZEARRAY; /* minimum size */ + } + newblock = luaM_reallocv(L, block, *size, newsize, size_elems); + *size = newsize; /* update only when everything else is OK */ + return newblock; +} + + +void *luaM_toobig (lua_State *L) { + luaG_runerror(L, "memory allocation error: block too big"); + return NULL; /* to avoid warnings */ +} + + + +/* +** generic allocation routine. +*/ +void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) { + global_State *g = G(L); + lua_assert((osize == 0) == (block == NULL)); + block = (*g->frealloc)(g->ud, block, osize, nsize); + if (block == NULL && nsize > 0) + luaD_throw(L, LUA_ERRMEM); + lua_assert((nsize == 0) == (block == NULL)); + g->totalbytes = (g->totalbytes - osize) + nsize; + return block; +} + diff --git a/IOS/lua/lua/lmem.h b/IOS/lua/lua/lmem.h new file mode 100644 index 00000000..7c2dcb32 --- /dev/null +++ b/IOS/lua/lua/lmem.h @@ -0,0 +1,49 @@ +/* +** $Id: lmem.h,v 1.31.1.1 2007/12/27 13:02:25 roberto Exp $ +** Interface to Memory Manager +** See Copyright Notice in lua.h +*/ + +#ifndef lmem_h +#define lmem_h + + +#include + +#include "llimits.h" +#include "lua.h" + +#define MEMERRMSG "not enough memory" + + +#define luaM_reallocv(L,b,on,n,e) \ + ((cast(size_t, (n)+1) <= MAX_SIZET/(e)) ? /* +1 to avoid warnings */ \ + luaM_realloc_(L, (b), (on)*(e), (n)*(e)) : \ + luaM_toobig(L)) + +#define luaM_freemem(L, b, s) luaM_realloc_(L, (b), (s), 0) +#define luaM_free(L, b) luaM_realloc_(L, (b), sizeof(*(b)), 0) +#define luaM_freearray(L, b, n, t) luaM_reallocv(L, (b), n, 0, sizeof(t)) + +#define luaM_malloc(L,t) luaM_realloc_(L, NULL, 0, (t)) +#define luaM_new(L,t) cast(t *, luaM_malloc(L, sizeof(t))) +#define luaM_newvector(L,n,t) \ + cast(t *, luaM_reallocv(L, NULL, 0, n, sizeof(t))) + +#define luaM_growvector(L,v,nelems,size,t,limit,e) \ + if ((nelems)+1 > (size)) \ + ((v)=cast(t *, luaM_growaux_(L,v,&(size),sizeof(t),limit,e))) + +#define luaM_reallocvector(L, v,oldn,n,t) \ + ((v)=cast(t *, luaM_reallocv(L, v, oldn, n, sizeof(t)))) + + +LUAI_FUNC void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize, + size_t size); +LUAI_FUNC void *luaM_toobig (lua_State *L); +LUAI_FUNC void *luaM_growaux_ (lua_State *L, void *block, int *size, + size_t size_elem, int limit, + const char *errormsg); + +#endif + diff --git a/IOS/lua/lua/loadlib.c b/IOS/lua/lua/loadlib.c new file mode 100644 index 00000000..0d401eba --- /dev/null +++ b/IOS/lua/lua/loadlib.c @@ -0,0 +1,666 @@ +/* +** $Id: loadlib.c,v 1.52.1.3 2008/08/06 13:29:28 roberto Exp $ +** Dynamic library loader for Lua +** See Copyright Notice in lua.h +** +** This module contains an implementation of loadlib for Unix systems +** that have dlfcn, an implementation for Darwin (Mac OS X), an +** implementation for Windows, and a stub for other systems. +*/ + + +#include +#include + + +#define loadlib_c +#define LUA_LIB + +#include "lua.h" + +#include "lauxlib.h" +#include "lualib.h" + + +/* prefix for open functions in C libraries */ +#define LUA_POF "luaopen_" + +/* separator for open functions in C libraries */ +#define LUA_OFSEP "_" + + +#define LIBPREFIX "LOADLIB: " + +#define POF LUA_POF +#define LIB_FAIL "open" + + +/* error codes for ll_loadfunc */ +#define ERRLIB 1 +#define ERRFUNC 2 + +#define setprogdir(L) ((void)0) + + +static void ll_unloadlib (void *lib); +static void *ll_load (lua_State *L, const char *path); +static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym); + + + +#if defined(LUA_DL_DLOPEN) +/* +** {======================================================================== +** This is an implementation of loadlib based on the dlfcn interface. +** The dlfcn interface is available in Linux, SunOS, Solaris, IRIX, FreeBSD, +** NetBSD, AIX 4.2, HPUX 11, and probably most other Unix flavors, at least +** as an emulation layer on top of native functions. +** ========================================================================= +*/ + +#include + +static void ll_unloadlib (void *lib) { + dlclose(lib); +} + + +static void *ll_load (lua_State *L, const char *path) { + void *lib = dlopen(path, RTLD_NOW); + if (lib == NULL) lua_pushstring(L, dlerror()); + return lib; +} + + +static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) { + lua_CFunction f = (lua_CFunction)dlsym(lib, sym); + if (f == NULL) lua_pushstring(L, dlerror()); + return f; +} + +/* }====================================================== */ + + + +#elif defined(LUA_DL_DLL) +/* +** {====================================================================== +** This is an implementation of loadlib for Windows using native functions. +** ======================================================================= +*/ + +#include + + +#undef setprogdir + +static void setprogdir (lua_State *L) { + char buff[MAX_PATH + 1]; + char *lb; + DWORD nsize = sizeof(buff)/sizeof(char); + DWORD n = GetModuleFileNameA(NULL, buff, nsize); + if (n == 0 || n == nsize || (lb = strrchr(buff, '\\')) == NULL) + luaL_error(L, "unable to get ModuleFileName"); + else { + *lb = '\0'; + luaL_gsub(L, lua_tostring(L, -1), LUA_EXECDIR, buff); + lua_remove(L, -2); /* remove original string */ + } +} + + +static void pusherror (lua_State *L) { + int error = GetLastError(); + char buffer[128]; + if (FormatMessageA(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM, + NULL, error, 0, buffer, sizeof(buffer), NULL)) + lua_pushstring(L, buffer); + else + lua_pushfstring(L, "system error %d\n", error); +} + +static void ll_unloadlib (void *lib) { + FreeLibrary((HINSTANCE)lib); +} + + +static void *ll_load (lua_State *L, const char *path) { + HINSTANCE lib = LoadLibraryA(path); + if (lib == NULL) pusherror(L); + return lib; +} + + +static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) { + lua_CFunction f = (lua_CFunction)GetProcAddress((HINSTANCE)lib, sym); + if (f == NULL) pusherror(L); + return f; +} + +/* }====================================================== */ + + + +#elif defined(LUA_DL_DYLD) +/* +** {====================================================================== +** Native Mac OS X / Darwin Implementation +** ======================================================================= +*/ + +#include + + +/* Mac appends a `_' before C function names */ +#undef POF +#define POF "_" LUA_POF + + +static void pusherror (lua_State *L) { + const char *err_str; + const char *err_file; + NSLinkEditErrors err; + int err_num; + NSLinkEditError(&err, &err_num, &err_file, &err_str); + lua_pushstring(L, err_str); +} + + +static const char *errorfromcode (NSObjectFileImageReturnCode ret) { + switch (ret) { + case NSObjectFileImageInappropriateFile: + return "file is not a bundle"; + case NSObjectFileImageArch: + return "library is for wrong CPU type"; + case NSObjectFileImageFormat: + return "bad format"; + case NSObjectFileImageAccess: + return "cannot access file"; + case NSObjectFileImageFailure: + default: + return "unable to load library"; + } +} + + +static void ll_unloadlib (void *lib) { + NSUnLinkModule((NSModule)lib, NSUNLINKMODULE_OPTION_RESET_LAZY_REFERENCES); +} + + +static void *ll_load (lua_State *L, const char *path) { + NSObjectFileImage img; + NSObjectFileImageReturnCode ret; + /* this would be a rare case, but prevents crashing if it happens */ + if(!_dyld_present()) { + lua_pushliteral(L, "dyld not present"); + return NULL; + } + ret = NSCreateObjectFileImageFromFile(path, &img); + if (ret == NSObjectFileImageSuccess) { + NSModule mod = NSLinkModule(img, path, NSLINKMODULE_OPTION_PRIVATE | + NSLINKMODULE_OPTION_RETURN_ON_ERROR); + NSDestroyObjectFileImage(img); + if (mod == NULL) pusherror(L); + return mod; + } + lua_pushstring(L, errorfromcode(ret)); + return NULL; +} + + +static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) { + NSSymbol nss = NSLookupSymbolInModule((NSModule)lib, sym); + if (nss == NULL) { + lua_pushfstring(L, "symbol " LUA_QS " not found", sym); + return NULL; + } + return (lua_CFunction)NSAddressOfSymbol(nss); +} + +/* }====================================================== */ + + + +#else +/* +** {====================================================== +** Fallback for other systems +** ======================================================= +*/ + +#undef LIB_FAIL +#define LIB_FAIL "absent" + + +#define DLMSG "dynamic libraries not enabled; check your Lua installation" + + +static void ll_unloadlib (void *lib) { + (void)lib; /* to avoid warnings */ +} + + +static void *ll_load (lua_State *L, const char *path) { + (void)path; /* to avoid warnings */ + lua_pushliteral(L, DLMSG); + return NULL; +} + + +static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) { + (void)lib; (void)sym; /* to avoid warnings */ + lua_pushliteral(L, DLMSG); + return NULL; +} + +/* }====================================================== */ +#endif + + + +static void **ll_register (lua_State *L, const char *path) { + void **plib; + lua_pushfstring(L, "%s%s", LIBPREFIX, path); + lua_gettable(L, LUA_REGISTRYINDEX); /* check library in registry? */ + if (!lua_isnil(L, -1)) /* is there an entry? */ + plib = (void **)lua_touserdata(L, -1); + else { /* no entry yet; create one */ + lua_pop(L, 1); + plib = (void **)lua_newuserdata(L, sizeof(const void *)); + *plib = NULL; + luaL_getmetatable(L, "_LOADLIB"); + lua_setmetatable(L, -2); + lua_pushfstring(L, "%s%s", LIBPREFIX, path); + lua_pushvalue(L, -2); + lua_settable(L, LUA_REGISTRYINDEX); + } + return plib; +} + + +/* +** __gc tag method: calls library's `ll_unloadlib' function with the lib +** handle +*/ +static int gctm (lua_State *L) { + void **lib = (void **)luaL_checkudata(L, 1, "_LOADLIB"); + if (*lib) ll_unloadlib(*lib); + *lib = NULL; /* mark library as closed */ + return 0; +} + + +static int ll_loadfunc (lua_State *L, const char *path, const char *sym) { + void **reg = ll_register(L, path); + if (*reg == NULL) *reg = ll_load(L, path); + if (*reg == NULL) + return ERRLIB; /* unable to load library */ + else { + lua_CFunction f = ll_sym(L, *reg, sym); + if (f == NULL) + return ERRFUNC; /* unable to find function */ + lua_pushcfunction(L, f); + return 0; /* return function */ + } +} + + +static int ll_loadlib (lua_State *L) { + const char *path = luaL_checkstring(L, 1); + const char *init = luaL_checkstring(L, 2); + int stat = ll_loadfunc(L, path, init); + if (stat == 0) /* no errors? */ + return 1; /* return the loaded function */ + else { /* error; error message is on stack top */ + lua_pushnil(L); + lua_insert(L, -2); + lua_pushstring(L, (stat == ERRLIB) ? LIB_FAIL : "init"); + return 3; /* return nil, error message, and where */ + } +} + + + +/* +** {====================================================== +** 'require' function +** ======================================================= +*/ + + +static int readable (const char *filename) { + FILE *f = fopen(filename, "r"); /* try to open file */ + if (f == NULL) return 0; /* open failed */ + fclose(f); + return 1; +} + + +static const char *pushnexttemplate (lua_State *L, const char *path) { + const char *l; + while (*path == *LUA_PATHSEP) path++; /* skip separators */ + if (*path == '\0') return NULL; /* no more templates */ + l = strchr(path, *LUA_PATHSEP); /* find next separator */ + if (l == NULL) l = path + strlen(path); + lua_pushlstring(L, path, l - path); /* template */ + return l; +} + + +static const char *findfile (lua_State *L, const char *name, + const char *pname) { + const char *path; + name = luaL_gsub(L, name, ".", LUA_DIRSEP); + lua_getfield(L, LUA_ENVIRONINDEX, pname); + path = lua_tostring(L, -1); + if (path == NULL) + luaL_error(L, LUA_QL("package.%s") " must be a string", pname); + lua_pushliteral(L, ""); /* error accumulator */ + while ((path = pushnexttemplate(L, path)) != NULL) { + const char *filename; + filename = luaL_gsub(L, lua_tostring(L, -1), LUA_PATH_MARK, name); + lua_remove(L, -2); /* remove path template */ + if (readable(filename)) /* does file exist and is readable? */ + return filename; /* return that file name */ + lua_pushfstring(L, "\n\tno file " LUA_QS, filename); + lua_remove(L, -2); /* remove file name */ + lua_concat(L, 2); /* add entry to possible error message */ + } + return NULL; /* not found */ +} + + +static void loaderror (lua_State *L, const char *filename) { + luaL_error(L, "error loading module " LUA_QS " from file " LUA_QS ":\n\t%s", + lua_tostring(L, 1), filename, lua_tostring(L, -1)); +} + + +static int loader_Lua (lua_State *L) { + const char *filename; + const char *name = luaL_checkstring(L, 1); + filename = findfile(L, name, "path"); + if (filename == NULL) return 1; /* library not found in this path */ + if (luaL_loadfile(L, filename) != 0) + loaderror(L, filename); + return 1; /* library loaded successfully */ +} + + +static const char *mkfuncname (lua_State *L, const char *modname) { + const char *funcname; + const char *mark = strchr(modname, *LUA_IGMARK); + if (mark) modname = mark + 1; + funcname = luaL_gsub(L, modname, ".", LUA_OFSEP); + funcname = lua_pushfstring(L, POF"%s", funcname); + lua_remove(L, -2); /* remove 'gsub' result */ + return funcname; +} + + +static int loader_C (lua_State *L) { + const char *funcname; + const char *name = luaL_checkstring(L, 1); + const char *filename = findfile(L, name, "cpath"); + if (filename == NULL) return 1; /* library not found in this path */ + funcname = mkfuncname(L, name); + if (ll_loadfunc(L, filename, funcname) != 0) + loaderror(L, filename); + return 1; /* library loaded successfully */ +} + + +static int loader_Croot (lua_State *L) { + const char *funcname; + const char *filename; + const char *name = luaL_checkstring(L, 1); + const char *p = strchr(name, '.'); + int stat; + if (p == NULL) return 0; /* is root */ + lua_pushlstring(L, name, p - name); + filename = findfile(L, lua_tostring(L, -1), "cpath"); + if (filename == NULL) return 1; /* root not found */ + funcname = mkfuncname(L, name); + if ((stat = ll_loadfunc(L, filename, funcname)) != 0) { + if (stat != ERRFUNC) loaderror(L, filename); /* real error */ + lua_pushfstring(L, "\n\tno module " LUA_QS " in file " LUA_QS, + name, filename); + return 1; /* function not found */ + } + return 1; +} + + +static int loader_preload (lua_State *L) { + const char *name = luaL_checkstring(L, 1); + lua_getfield(L, LUA_ENVIRONINDEX, "preload"); + if (!lua_istable(L, -1)) + luaL_error(L, LUA_QL("package.preload") " must be a table"); + lua_getfield(L, -1, name); + if (lua_isnil(L, -1)) /* not found? */ + lua_pushfstring(L, "\n\tno field package.preload['%s']", name); + return 1; +} + + +static const int sentinel_ = 0; +#define sentinel ((void *)&sentinel_) + + +static int ll_require (lua_State *L) { + const char *name = luaL_checkstring(L, 1); + int i; + lua_settop(L, 1); /* _LOADED table will be at index 2 */ + lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED"); + lua_getfield(L, 2, name); + if (lua_toboolean(L, -1)) { /* is it there? */ + if (lua_touserdata(L, -1) == sentinel) /* check loops */ + luaL_error(L, "loop or previous error loading module " LUA_QS, name); + return 1; /* package is already loaded */ + } + /* else must load it; iterate over available loaders */ + lua_getfield(L, LUA_ENVIRONINDEX, "loaders"); + if (!lua_istable(L, -1)) + luaL_error(L, LUA_QL("package.loaders") " must be a table"); + lua_pushliteral(L, ""); /* error message accumulator */ + for (i=1; ; i++) { + lua_rawgeti(L, -2, i); /* get a loader */ + if (lua_isnil(L, -1)) + luaL_error(L, "module " LUA_QS " not found:%s", + name, lua_tostring(L, -2)); + lua_pushstring(L, name); + lua_call(L, 1, 1); /* call it */ + if (lua_isfunction(L, -1)) /* did it find module? */ + break; /* module loaded successfully */ + else if (lua_isstring(L, -1)) /* loader returned error message? */ + lua_concat(L, 2); /* accumulate it */ + else + lua_pop(L, 1); + } + lua_pushlightuserdata(L, sentinel); + lua_setfield(L, 2, name); /* _LOADED[name] = sentinel */ + lua_pushstring(L, name); /* pass name as argument to module */ + lua_call(L, 1, 1); /* run loaded module */ + if (!lua_isnil(L, -1)) /* non-nil return? */ + lua_setfield(L, 2, name); /* _LOADED[name] = returned value */ + lua_getfield(L, 2, name); + if (lua_touserdata(L, -1) == sentinel) { /* module did not set a value? */ + lua_pushboolean(L, 1); /* use true as result */ + lua_pushvalue(L, -1); /* extra copy to be returned */ + lua_setfield(L, 2, name); /* _LOADED[name] = true */ + } + return 1; +} + +/* }====================================================== */ + + + +/* +** {====================================================== +** 'module' function +** ======================================================= +*/ + + +static void setfenv (lua_State *L) { + lua_Debug ar; + if (lua_getstack(L, 1, &ar) == 0 || + lua_getinfo(L, "f", &ar) == 0 || /* get calling function */ + lua_iscfunction(L, -1)) + luaL_error(L, LUA_QL("module") " not called from a Lua function"); + lua_pushvalue(L, -2); + lua_setfenv(L, -2); + lua_pop(L, 1); +} + + +static void dooptions (lua_State *L, int n) { + int i; + for (i = 2; i <= n; i++) { + lua_pushvalue(L, i); /* get option (a function) */ + lua_pushvalue(L, -2); /* module */ + lua_call(L, 1, 0); + } +} + + +static void modinit (lua_State *L, const char *modname) { + const char *dot; + lua_pushvalue(L, -1); + lua_setfield(L, -2, "_M"); /* module._M = module */ + lua_pushstring(L, modname); + lua_setfield(L, -2, "_NAME"); + dot = strrchr(modname, '.'); /* look for last dot in module name */ + if (dot == NULL) dot = modname; + else dot++; + /* set _PACKAGE as package name (full module name minus last part) */ + lua_pushlstring(L, modname, dot - modname); + lua_setfield(L, -2, "_PACKAGE"); +} + + +static int ll_module (lua_State *L) { + const char *modname = luaL_checkstring(L, 1); + int loaded = lua_gettop(L) + 1; /* index of _LOADED table */ + lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED"); + lua_getfield(L, loaded, modname); /* get _LOADED[modname] */ + if (!lua_istable(L, -1)) { /* not found? */ + lua_pop(L, 1); /* remove previous result */ + /* try global variable (and create one if it does not exist) */ + if (luaL_findtable(L, LUA_GLOBALSINDEX, modname, 1) != NULL) + return luaL_error(L, "name conflict for module " LUA_QS, modname); + lua_pushvalue(L, -1); + lua_setfield(L, loaded, modname); /* _LOADED[modname] = new table */ + } + /* check whether table already has a _NAME field */ + lua_getfield(L, -1, "_NAME"); + if (!lua_isnil(L, -1)) /* is table an initialized module? */ + lua_pop(L, 1); + else { /* no; initialize it */ + lua_pop(L, 1); + modinit(L, modname); + } + lua_pushvalue(L, -1); + setfenv(L); + dooptions(L, loaded - 1); + return 0; +} + + +static int ll_seeall (lua_State *L) { + luaL_checktype(L, 1, LUA_TTABLE); + if (!lua_getmetatable(L, 1)) { + lua_createtable(L, 0, 1); /* create new metatable */ + lua_pushvalue(L, -1); + lua_setmetatable(L, 1); + } + lua_pushvalue(L, LUA_GLOBALSINDEX); + lua_setfield(L, -2, "__index"); /* mt.__index = _G */ + return 0; +} + + +/* }====================================================== */ + + + +/* auxiliary mark (for internal use) */ +#define AUXMARK "\1" + +static void setpath (lua_State *L, const char *fieldname, const char *envname, + const char *def) { + const char *path = getenv(envname); + if (path == NULL) /* no environment variable? */ + lua_pushstring(L, def); /* use default */ + else { + /* replace ";;" by ";AUXMARK;" and then AUXMARK by default path */ + path = luaL_gsub(L, path, LUA_PATHSEP LUA_PATHSEP, + LUA_PATHSEP AUXMARK LUA_PATHSEP); + luaL_gsub(L, path, AUXMARK, def); + lua_remove(L, -2); + } + setprogdir(L); + lua_setfield(L, -2, fieldname); +} + + +static const luaL_Reg pk_funcs[] = { + {"loadlib", ll_loadlib}, + {"seeall", ll_seeall}, + {NULL, NULL} +}; + + +static const luaL_Reg ll_funcs[] = { + {"module", ll_module}, + {"require", ll_require}, + {NULL, NULL} +}; + + +static const lua_CFunction loaders[] = + {loader_preload, loader_Lua, loader_C, loader_Croot, NULL}; + + +LUALIB_API int luaopen_package (lua_State *L) { + int i; + /* create new type _LOADLIB */ + luaL_newmetatable(L, "_LOADLIB"); + lua_pushcfunction(L, gctm); + lua_setfield(L, -2, "__gc"); + /* create `package' table */ + luaL_register(L, LUA_LOADLIBNAME, pk_funcs); +#if defined(LUA_COMPAT_LOADLIB) + lua_getfield(L, -1, "loadlib"); + lua_setfield(L, LUA_GLOBALSINDEX, "loadlib"); +#endif + lua_pushvalue(L, -1); + lua_replace(L, LUA_ENVIRONINDEX); + /* create `loaders' table */ + lua_createtable(L, 0, sizeof(loaders)/sizeof(loaders[0]) - 1); + /* fill it with pre-defined loaders */ + for (i=0; loaders[i] != NULL; i++) { + lua_pushcfunction(L, loaders[i]); + lua_rawseti(L, -2, i+1); + } + lua_setfield(L, -2, "loaders"); /* put it in field `loaders' */ + setpath(L, "path", LUA_PATH, LUA_PATH_DEFAULT); /* set field `path' */ + setpath(L, "cpath", LUA_CPATH, LUA_CPATH_DEFAULT); /* set field `cpath' */ + /* store config information */ + lua_pushliteral(L, LUA_DIRSEP "\n" LUA_PATHSEP "\n" LUA_PATH_MARK "\n" + LUA_EXECDIR "\n" LUA_IGMARK); + lua_setfield(L, -2, "config"); + /* set field `loaded' */ + luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 2); + lua_setfield(L, -2, "loaded"); + /* set field `preload' */ + lua_newtable(L); + lua_setfield(L, -2, "preload"); + lua_pushvalue(L, LUA_GLOBALSINDEX); + luaL_register(L, NULL, ll_funcs); /* open lib into global table */ + lua_pop(L, 1); + return 1; /* return 'package' table */ +} + diff --git a/IOS/lua/lua/lobject.c b/IOS/lua/lua/lobject.c new file mode 100644 index 00000000..4ff50732 --- /dev/null +++ b/IOS/lua/lua/lobject.c @@ -0,0 +1,214 @@ +/* +** $Id: lobject.c,v 2.22.1.1 2007/12/27 13:02:25 roberto Exp $ +** Some generic functions over Lua objects +** See Copyright Notice in lua.h +*/ + +#include +#include +#include +#include +#include + +#define lobject_c +#define LUA_CORE + +#include "lua.h" + +#include "ldo.h" +#include "lmem.h" +#include "lobject.h" +#include "lstate.h" +#include "lstring.h" +#include "lvm.h" + + + +const TValue luaO_nilobject_ = {{NULL}, LUA_TNIL}; + + +/* +** converts an integer to a "floating point byte", represented as +** (eeeeexxx), where the real value is (1xxx) * 2^(eeeee - 1) if +** eeeee != 0 and (xxx) otherwise. +*/ +int luaO_int2fb (unsigned int x) { + int e = 0; /* expoent */ + while (x >= 16) { + x = (x+1) >> 1; + e++; + } + if (x < 8) return x; + else return ((e+1) << 3) | (cast_int(x) - 8); +} + + +/* converts back */ +int luaO_fb2int (int x) { + int e = (x >> 3) & 31; + if (e == 0) return x; + else return ((x & 7)+8) << (e - 1); +} + + +int luaO_log2 (unsigned int x) { + static const lu_byte log_2[256] = { + 0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5, + 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, + 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, + 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, + 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, + 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, + 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, + 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8 + }; + int l = -1; + while (x >= 256) { l += 8; x >>= 8; } + return l + log_2[x]; + +} + + +int luaO_rawequalObj (const TValue *t1, const TValue *t2) { + if (ttype(t1) != ttype(t2)) return 0; + else switch (ttype(t1)) { + case LUA_TNIL: + return 1; + case LUA_TNUMBER: + return luai_numeq(nvalue(t1), nvalue(t2)); + case LUA_TBOOLEAN: + return bvalue(t1) == bvalue(t2); /* boolean true must be 1 !! */ + case LUA_TLIGHTUSERDATA: + return pvalue(t1) == pvalue(t2); + default: + lua_assert(iscollectable(t1)); + return gcvalue(t1) == gcvalue(t2); + } +} + + +int luaO_str2d (const char *s, lua_Number *result) { + char *endptr; + *result = lua_str2number(s, &endptr); + if (endptr == s) return 0; /* conversion failed */ + if (*endptr == 'x' || *endptr == 'X') /* maybe an hexadecimal constant? */ + *result = cast_num(strtoul(s, &endptr, 16)); + if (*endptr == '\0') return 1; /* most common case */ + while (isspace(cast(unsigned char, *endptr))) endptr++; + if (*endptr != '\0') return 0; /* invalid trailing characters? */ + return 1; +} + + + +static void pushstr (lua_State *L, const char *str) { + setsvalue2s(L, L->top, luaS_new(L, str)); + incr_top(L); +} + + +/* this function handles only `%d', `%c', %f, %p, and `%s' formats */ +const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) { + int n = 1; + pushstr(L, ""); + for (;;) { + const char *e = strchr(fmt, '%'); + if (e == NULL) break; + setsvalue2s(L, L->top, luaS_newlstr(L, fmt, e-fmt)); + incr_top(L); + switch (*(e+1)) { + case 's': { + const char *s = va_arg(argp, char *); + if (s == NULL) s = "(null)"; + pushstr(L, s); + break; + } + case 'c': { + char buff[2]; + buff[0] = cast(char, va_arg(argp, int)); + buff[1] = '\0'; + pushstr(L, buff); + break; + } + case 'd': { + setnvalue(L->top, cast_num(va_arg(argp, int))); + incr_top(L); + break; + } + case 'f': { + setnvalue(L->top, cast_num(va_arg(argp, l_uacNumber))); + incr_top(L); + break; + } + case 'p': { + char buff[4*sizeof(void *) + 8]; /* should be enough space for a `%p' */ + sprintf(buff, "%p", va_arg(argp, void *)); + pushstr(L, buff); + break; + } + case '%': { + pushstr(L, "%"); + break; + } + default: { + char buff[3]; + buff[0] = '%'; + buff[1] = *(e+1); + buff[2] = '\0'; + pushstr(L, buff); + break; + } + } + n += 2; + fmt = e+2; + } + pushstr(L, fmt); + luaV_concat(L, n+1, cast_int(L->top - L->base) - 1); + L->top -= n; + return svalue(L->top - 1); +} + + +const char *luaO_pushfstring (lua_State *L, const char *fmt, ...) { + const char *msg; + va_list argp; + va_start(argp, fmt); + msg = luaO_pushvfstring(L, fmt, argp); + va_end(argp); + return msg; +} + + +void luaO_chunkid (char *out, const char *source, size_t bufflen) { + if (*source == '=') { + strncpy(out, source+1, bufflen); /* remove first char */ + out[bufflen-1] = '\0'; /* ensures null termination */ + } + else { /* out = "source", or "...source" */ + if (*source == '@') { + size_t l; + source++; /* skip the `@' */ + bufflen -= sizeof(" '...' "); + l = strlen(source); + strcpy(out, ""); + if (l > bufflen) { + source += (l-bufflen); /* get last part of file name */ + strcat(out, "..."); + } + strcat(out, source); + } + else { /* out = [string "string"] */ + size_t len = strcspn(source, "\n\r"); /* stop at first newline */ + bufflen -= sizeof(" [string \"...\"] "); + if (len > bufflen) len = bufflen; + strcpy(out, "[string \""); + if (source[len] != '\0') { /* must truncate? */ + strncat(out, source, len); + strcat(out, "..."); + } + else + strcat(out, source); + strcat(out, "\"]"); + } + } +} diff --git a/IOS/lua/lua/lobject.h b/IOS/lua/lua/lobject.h new file mode 100644 index 00000000..f1e447ef --- /dev/null +++ b/IOS/lua/lua/lobject.h @@ -0,0 +1,381 @@ +/* +** $Id: lobject.h,v 2.20.1.2 2008/08/06 13:29:48 roberto Exp $ +** Type definitions for Lua objects +** See Copyright Notice in lua.h +*/ + + +#ifndef lobject_h +#define lobject_h + + +#include + + +#include "llimits.h" +#include "lua.h" + + +/* tags for values visible from Lua */ +#define LAST_TAG LUA_TTHREAD + +#define NUM_TAGS (LAST_TAG+1) + + +/* +** Extra tags for non-values +*/ +#define LUA_TPROTO (LAST_TAG+1) +#define LUA_TUPVAL (LAST_TAG+2) +#define LUA_TDEADKEY (LAST_TAG+3) + + +/* +** Union of all collectable objects +*/ +typedef union GCObject GCObject; + + +/* +** Common Header for all collectable objects (in macro form, to be +** included in other objects) +*/ +#define CommonHeader GCObject *next; lu_byte tt; lu_byte marked + + +/* +** Common header in struct form +*/ +typedef struct GCheader { + CommonHeader; +} GCheader; + + + + +/* +** Union of all Lua values +*/ +typedef union { + GCObject *gc; + void *p; + lua_Number n; + int b; +} Value; + + +/* +** Tagged Values +*/ + +#define TValuefields Value value; int tt + +typedef struct lua_TValue { + TValuefields; +} TValue; + + +/* Macros to test type */ +#define ttisnil(o) (ttype(o) == LUA_TNIL) +#define ttisnumber(o) (ttype(o) == LUA_TNUMBER) +#define ttisstring(o) (ttype(o) == LUA_TSTRING) +#define ttistable(o) (ttype(o) == LUA_TTABLE) +#define ttisfunction(o) (ttype(o) == LUA_TFUNCTION) +#define ttisboolean(o) (ttype(o) == LUA_TBOOLEAN) +#define ttisuserdata(o) (ttype(o) == LUA_TUSERDATA) +#define ttisthread(o) (ttype(o) == LUA_TTHREAD) +#define ttislightuserdata(o) (ttype(o) == LUA_TLIGHTUSERDATA) + +/* Macros to access values */ +#define ttype(o) ((o)->tt) +#define gcvalue(o) check_exp(iscollectable(o), (o)->value.gc) +#define pvalue(o) check_exp(ttislightuserdata(o), (o)->value.p) +#define nvalue(o) check_exp(ttisnumber(o), (o)->value.n) +#define rawtsvalue(o) check_exp(ttisstring(o), &(o)->value.gc->ts) +#define tsvalue(o) (&rawtsvalue(o)->tsv) +#define rawuvalue(o) check_exp(ttisuserdata(o), &(o)->value.gc->u) +#define uvalue(o) (&rawuvalue(o)->uv) +#define clvalue(o) check_exp(ttisfunction(o), &(o)->value.gc->cl) +#define hvalue(o) check_exp(ttistable(o), &(o)->value.gc->h) +#define bvalue(o) check_exp(ttisboolean(o), (o)->value.b) +#define thvalue(o) check_exp(ttisthread(o), &(o)->value.gc->th) + +#define l_isfalse(o) (ttisnil(o) || (ttisboolean(o) && bvalue(o) == 0)) + +/* +** for internal debug only +*/ +#define checkconsistency(obj) \ + lua_assert(!iscollectable(obj) || (ttype(obj) == (obj)->value.gc->gch.tt)) + +#define checkliveness(g,obj) \ + lua_assert(!iscollectable(obj) || \ + ((ttype(obj) == (obj)->value.gc->gch.tt) && !isdead(g, (obj)->value.gc))) + + +/* Macros to set values */ +#define setnilvalue(obj) ((obj)->tt=LUA_TNIL) + +#define setnvalue(obj,x) \ + { TValue *i_o=(obj); i_o->value.n=(x); i_o->tt=LUA_TNUMBER; } + +#define setpvalue(obj,x) \ + { TValue *i_o=(obj); i_o->value.p=(x); i_o->tt=LUA_TLIGHTUSERDATA; } + +#define setbvalue(obj,x) \ + { TValue *i_o=(obj); i_o->value.b=(x); i_o->tt=LUA_TBOOLEAN; } + +#define setsvalue(L,obj,x) \ + { TValue *i_o=(obj); \ + i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TSTRING; \ + checkliveness(G(L),i_o); } + +#define setuvalue(L,obj,x) \ + { TValue *i_o=(obj); \ + i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TUSERDATA; \ + checkliveness(G(L),i_o); } + +#define setthvalue(L,obj,x) \ + { TValue *i_o=(obj); \ + i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TTHREAD; \ + checkliveness(G(L),i_o); } + +#define setclvalue(L,obj,x) \ + { TValue *i_o=(obj); \ + i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TFUNCTION; \ + checkliveness(G(L),i_o); } + +#define sethvalue(L,obj,x) \ + { TValue *i_o=(obj); \ + i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TTABLE; \ + checkliveness(G(L),i_o); } + +#define setptvalue(L,obj,x) \ + { TValue *i_o=(obj); \ + i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TPROTO; \ + checkliveness(G(L),i_o); } + + + + +#define setobj(L,obj1,obj2) \ + { const TValue *o2=(obj2); TValue *o1=(obj1); \ + o1->value = o2->value; o1->tt=o2->tt; \ + checkliveness(G(L),o1); } + + +/* +** different types of sets, according to destination +*/ + +/* from stack to (same) stack */ +#define setobjs2s setobj +/* to stack (not from same stack) */ +#define setobj2s setobj +#define setsvalue2s setsvalue +#define sethvalue2s sethvalue +#define setptvalue2s setptvalue +/* from table to same table */ +#define setobjt2t setobj +/* to table */ +#define setobj2t setobj +/* to new object */ +#define setobj2n setobj +#define setsvalue2n setsvalue + +#define setttype(obj, tt) (ttype(obj) = (tt)) + + +#define iscollectable(o) (ttype(o) >= LUA_TSTRING) + + + +typedef TValue *StkId; /* index to stack elements */ + + +/* +** String headers for string table +*/ +typedef union TString { + L_Umaxalign dummy; /* ensures maximum alignment for strings */ + struct { + CommonHeader; + lu_byte reserved; + unsigned int hash; + size_t len; + } tsv; +} TString; + + +#define getstr(ts) cast(const char *, (ts) + 1) +#define svalue(o) getstr(rawtsvalue(o)) + + + +typedef union Udata { + L_Umaxalign dummy; /* ensures maximum alignment for `local' udata */ + struct { + CommonHeader; + struct Table *metatable; + struct Table *env; + size_t len; + } uv; +} Udata; + + + + +/* +** Function Prototypes +*/ +typedef struct Proto { + CommonHeader; + TValue *k; /* constants used by the function */ + Instruction *code; + struct Proto **p; /* functions defined inside the function */ + int *lineinfo; /* map from opcodes to source lines */ + struct LocVar *locvars; /* information about local variables */ + TString **upvalues; /* upvalue names */ + TString *source; + int sizeupvalues; + int sizek; /* size of `k' */ + int sizecode; + int sizelineinfo; + int sizep; /* size of `p' */ + int sizelocvars; + int linedefined; + int lastlinedefined; + GCObject *gclist; + lu_byte nups; /* number of upvalues */ + lu_byte numparams; + lu_byte is_vararg; + lu_byte maxstacksize; +} Proto; + + +/* masks for new-style vararg */ +#define VARARG_HASARG 1 +#define VARARG_ISVARARG 2 +#define VARARG_NEEDSARG 4 + + +typedef struct LocVar { + TString *varname; + int startpc; /* first point where variable is active */ + int endpc; /* first point where variable is dead */ +} LocVar; + + + +/* +** Upvalues +*/ + +typedef struct UpVal { + CommonHeader; + TValue *v; /* points to stack or to its own value */ + union { + TValue value; /* the value (when closed) */ + struct { /* double linked list (when open) */ + struct UpVal *prev; + struct UpVal *next; + } l; + } u; +} UpVal; + + +/* +** Closures +*/ + +#define ClosureHeader \ + CommonHeader; lu_byte isC; lu_byte nupvalues; GCObject *gclist; \ + struct Table *env + +typedef struct CClosure { + ClosureHeader; + lua_CFunction f; + TValue upvalue[1]; +} CClosure; + + +typedef struct LClosure { + ClosureHeader; + struct Proto *p; + UpVal *upvals[1]; +} LClosure; + + +typedef union Closure { + CClosure c; + LClosure l; +} Closure; + + +#define iscfunction(o) (ttype(o) == LUA_TFUNCTION && clvalue(o)->c.isC) +#define isLfunction(o) (ttype(o) == LUA_TFUNCTION && !clvalue(o)->c.isC) + + +/* +** Tables +*/ + +typedef union TKey { + struct { + TValuefields; + struct Node *next; /* for chaining */ + } nk; + TValue tvk; +} TKey; + + +typedef struct Node { + TValue i_val; + TKey i_key; +} Node; + + +typedef struct Table { + CommonHeader; + lu_byte flags; /* 1<

lsizenode)) + + +#define luaO_nilobject (&luaO_nilobject_) + +LUAI_DATA const TValue luaO_nilobject_; + +#define ceillog2(x) (luaO_log2((x)-1) + 1) + +LUAI_FUNC int luaO_log2 (unsigned int x); +LUAI_FUNC int luaO_int2fb (unsigned int x); +LUAI_FUNC int luaO_fb2int (int x); +LUAI_FUNC int luaO_rawequalObj (const TValue *t1, const TValue *t2); +LUAI_FUNC int luaO_str2d (const char *s, lua_Number *result); +LUAI_FUNC const char *luaO_pushvfstring (lua_State *L, const char *fmt, + va_list argp); +LUAI_FUNC const char *luaO_pushfstring (lua_State *L, const char *fmt, ...); +LUAI_FUNC void luaO_chunkid (char *out, const char *source, size_t len); + + +#endif + diff --git a/IOS/lua/lua/lopcodes.c b/IOS/lua/lua/lopcodes.c new file mode 100644 index 00000000..4cc74523 --- /dev/null +++ b/IOS/lua/lua/lopcodes.c @@ -0,0 +1,102 @@ +/* +** $Id: lopcodes.c,v 1.37.1.1 2007/12/27 13:02:25 roberto Exp $ +** See Copyright Notice in lua.h +*/ + + +#define lopcodes_c +#define LUA_CORE + + +#include "lopcodes.h" + + +/* ORDER OP */ + +const char *const luaP_opnames[NUM_OPCODES+1] = { + "MOVE", + "LOADK", + "LOADBOOL", + "LOADNIL", + "GETUPVAL", + "GETGLOBAL", + "GETTABLE", + "SETGLOBAL", + "SETUPVAL", + "SETTABLE", + "NEWTABLE", + "SELF", + "ADD", + "SUB", + "MUL", + "DIV", + "MOD", + "POW", + "UNM", + "NOT", + "LEN", + "CONCAT", + "JMP", + "EQ", + "LT", + "LE", + "TEST", + "TESTSET", + "CALL", + "TAILCALL", + "RETURN", + "FORLOOP", + "FORPREP", + "TFORLOOP", + "SETLIST", + "CLOSE", + "CLOSURE", + "VARARG", + NULL +}; + + +#define opmode(t,a,b,c,m) (((t)<<7) | ((a)<<6) | ((b)<<4) | ((c)<<2) | (m)) + +const lu_byte luaP_opmodes[NUM_OPCODES] = { +/* T A B C mode opcode */ + opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_MOVE */ + ,opmode(0, 1, OpArgK, OpArgN, iABx) /* OP_LOADK */ + ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_LOADBOOL */ + ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_LOADNIL */ + ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_GETUPVAL */ + ,opmode(0, 1, OpArgK, OpArgN, iABx) /* OP_GETGLOBAL */ + ,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_GETTABLE */ + ,opmode(0, 0, OpArgK, OpArgN, iABx) /* OP_SETGLOBAL */ + ,opmode(0, 0, OpArgU, OpArgN, iABC) /* OP_SETUPVAL */ + ,opmode(0, 0, OpArgK, OpArgK, iABC) /* OP_SETTABLE */ + ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_NEWTABLE */ + ,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_SELF */ + ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_ADD */ + ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_SUB */ + ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_MUL */ + ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_DIV */ + ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_MOD */ + ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_POW */ + ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_UNM */ + ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_NOT */ + ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_LEN */ + ,opmode(0, 1, OpArgR, OpArgR, iABC) /* OP_CONCAT */ + ,opmode(0, 0, OpArgR, OpArgN, iAsBx) /* OP_JMP */ + ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_EQ */ + ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_LT */ + ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_LE */ + ,opmode(1, 1, OpArgR, OpArgU, iABC) /* OP_TEST */ + ,opmode(1, 1, OpArgR, OpArgU, iABC) /* OP_TESTSET */ + ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_CALL */ + ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_TAILCALL */ + ,opmode(0, 0, OpArgU, OpArgN, iABC) /* OP_RETURN */ + ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_FORLOOP */ + ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_FORPREP */ + ,opmode(1, 0, OpArgN, OpArgU, iABC) /* OP_TFORLOOP */ + ,opmode(0, 0, OpArgU, OpArgU, iABC) /* OP_SETLIST */ + ,opmode(0, 0, OpArgN, OpArgN, iABC) /* OP_CLOSE */ + ,opmode(0, 1, OpArgU, OpArgN, iABx) /* OP_CLOSURE */ + ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_VARARG */ +}; + diff --git a/IOS/lua/lua/lopcodes.h b/IOS/lua/lua/lopcodes.h new file mode 100644 index 00000000..41224d6e --- /dev/null +++ b/IOS/lua/lua/lopcodes.h @@ -0,0 +1,268 @@ +/* +** $Id: lopcodes.h,v 1.125.1.1 2007/12/27 13:02:25 roberto Exp $ +** Opcodes for Lua virtual machine +** See Copyright Notice in lua.h +*/ + +#ifndef lopcodes_h +#define lopcodes_h + +#include "llimits.h" + + +/*=========================================================================== + We assume that instructions are unsigned numbers. + All instructions have an opcode in the first 6 bits. + Instructions can have the following fields: + `A' : 8 bits + `B' : 9 bits + `C' : 9 bits + `Bx' : 18 bits (`B' and `C' together) + `sBx' : signed Bx + + A signed argument is represented in excess K; that is, the number + value is the unsigned value minus K. K is exactly the maximum value + for that argument (so that -max is represented by 0, and +max is + represented by 2*max), which is half the maximum for the corresponding + unsigned argument. +===========================================================================*/ + + +enum OpMode {iABC, iABx, iAsBx}; /* basic instruction format */ + + +/* +** size and position of opcode arguments. +*/ +#define SIZE_C 9 +#define SIZE_B 9 +#define SIZE_Bx (SIZE_C + SIZE_B) +#define SIZE_A 8 + +#define SIZE_OP 6 + +#define POS_OP 0 +#define POS_A (POS_OP + SIZE_OP) +#define POS_C (POS_A + SIZE_A) +#define POS_B (POS_C + SIZE_C) +#define POS_Bx POS_C + + +/* +** limits for opcode arguments. +** we use (signed) int to manipulate most arguments, +** so they must fit in LUAI_BITSINT-1 bits (-1 for sign) +*/ +#if SIZE_Bx < LUAI_BITSINT-1 +#define MAXARG_Bx ((1<>1) /* `sBx' is signed */ +#else +#define MAXARG_Bx MAX_INT +#define MAXARG_sBx MAX_INT +#endif + + +#define MAXARG_A ((1<>POS_OP) & MASK1(SIZE_OP,0))) +#define SET_OPCODE(i,o) ((i) = (((i)&MASK0(SIZE_OP,POS_OP)) | \ + ((cast(Instruction, o)<>POS_A) & MASK1(SIZE_A,0))) +#define SETARG_A(i,u) ((i) = (((i)&MASK0(SIZE_A,POS_A)) | \ + ((cast(Instruction, u)<>POS_B) & MASK1(SIZE_B,0))) +#define SETARG_B(i,b) ((i) = (((i)&MASK0(SIZE_B,POS_B)) | \ + ((cast(Instruction, b)<>POS_C) & MASK1(SIZE_C,0))) +#define SETARG_C(i,b) ((i) = (((i)&MASK0(SIZE_C,POS_C)) | \ + ((cast(Instruction, b)<>POS_Bx) & MASK1(SIZE_Bx,0))) +#define SETARG_Bx(i,b) ((i) = (((i)&MASK0(SIZE_Bx,POS_Bx)) | \ + ((cast(Instruction, b)< C) then pc++ */ +OP_TESTSET,/* A B C if (R(B) <=> C) then R(A) := R(B) else pc++ */ + +OP_CALL,/* A B C R(A), ... ,R(A+C-2) := R(A)(R(A+1), ... ,R(A+B-1)) */ +OP_TAILCALL,/* A B C return R(A)(R(A+1), ... ,R(A+B-1)) */ +OP_RETURN,/* A B return R(A), ... ,R(A+B-2) (see note) */ + +OP_FORLOOP,/* A sBx R(A)+=R(A+2); + if R(A) =) R(A)*/ +OP_CLOSURE,/* A Bx R(A) := closure(KPROTO[Bx], R(A), ... ,R(A+n)) */ + +OP_VARARG/* A B R(A), R(A+1), ..., R(A+B-1) = vararg */ +} OpCode; + + +#define NUM_OPCODES (cast(int, OP_VARARG) + 1) + + + +/*=========================================================================== + Notes: + (*) In OP_CALL, if (B == 0) then B = top. C is the number of returns - 1, + and can be 0: OP_CALL then sets `top' to last_result+1, so + next open instruction (OP_CALL, OP_RETURN, OP_SETLIST) may use `top'. + + (*) In OP_VARARG, if (B == 0) then use actual number of varargs and + set top (like in OP_CALL with C == 0). + + (*) In OP_RETURN, if (B == 0) then return up to `top' + + (*) In OP_SETLIST, if (B == 0) then B = `top'; + if (C == 0) then next `instruction' is real C + + (*) For comparisons, A specifies what condition the test should accept + (true or false). + + (*) All `skips' (pc++) assume that next instruction is a jump +===========================================================================*/ + + +/* +** masks for instruction properties. The format is: +** bits 0-1: op mode +** bits 2-3: C arg mode +** bits 4-5: B arg mode +** bit 6: instruction set register A +** bit 7: operator is a test +*/ + +enum OpArgMask { + OpArgN, /* argument is not used */ + OpArgU, /* argument is used */ + OpArgR, /* argument is a register or a jump offset */ + OpArgK /* argument is a constant or register/constant */ +}; + +LUAI_DATA const lu_byte luaP_opmodes[NUM_OPCODES]; + +#define getOpMode(m) (cast(enum OpMode, luaP_opmodes[m] & 3)) +#define getBMode(m) (cast(enum OpArgMask, (luaP_opmodes[m] >> 4) & 3)) +#define getCMode(m) (cast(enum OpArgMask, (luaP_opmodes[m] >> 2) & 3)) +#define testAMode(m) (luaP_opmodes[m] & (1 << 6)) +#define testTMode(m) (luaP_opmodes[m] & (1 << 7)) + + +LUAI_DATA const char *const luaP_opnames[NUM_OPCODES+1]; /* opcode names */ + + +/* number of list items to accumulate before a SETLIST instruction */ +#define LFIELDS_PER_FLUSH 50 + + +#endif diff --git a/IOS/lua/lua/loslib.c b/IOS/lua/lua/loslib.c new file mode 100644 index 00000000..da06a572 --- /dev/null +++ b/IOS/lua/lua/loslib.c @@ -0,0 +1,243 @@ +/* +** $Id: loslib.c,v 1.19.1.3 2008/01/18 16:38:18 roberto Exp $ +** Standard Operating System library +** See Copyright Notice in lua.h +*/ + + +#include +#include +#include +#include +#include + +#define loslib_c +#define LUA_LIB + +#include "lua.h" + +#include "lauxlib.h" +#include "lualib.h" + + +static int os_pushresult (lua_State *L, int i, const char *filename) { + int en = errno; /* calls to Lua API may change this value */ + if (i) { + lua_pushboolean(L, 1); + return 1; + } + else { + lua_pushnil(L); + lua_pushfstring(L, "%s: %s", filename, strerror(en)); + lua_pushinteger(L, en); + return 3; + } +} + + +static int os_execute (lua_State *L) { + lua_pushinteger(L, system(luaL_optstring(L, 1, NULL))); + return 1; +} + + +static int os_remove (lua_State *L) { + const char *filename = luaL_checkstring(L, 1); + return os_pushresult(L, remove(filename) == 0, filename); +} + + +static int os_rename (lua_State *L) { + const char *fromname = luaL_checkstring(L, 1); + const char *toname = luaL_checkstring(L, 2); + return os_pushresult(L, rename(fromname, toname) == 0, fromname); +} + + +static int os_tmpname (lua_State *L) { + char buff[LUA_TMPNAMBUFSIZE]; + int err; + lua_tmpnam(buff, err); + if (err) + return luaL_error(L, "unable to generate a unique filename"); + lua_pushstring(L, buff); + return 1; +} + + +static int os_getenv (lua_State *L) { + lua_pushstring(L, getenv(luaL_checkstring(L, 1))); /* if NULL push nil */ + return 1; +} + + +static int os_clock (lua_State *L) { + lua_pushnumber(L, ((lua_Number)clock())/(lua_Number)CLOCKS_PER_SEC); + return 1; +} + + +/* +** {====================================================== +** Time/Date operations +** { year=%Y, month=%m, day=%d, hour=%H, min=%M, sec=%S, +** wday=%w+1, yday=%j, isdst=? } +** ======================================================= +*/ + +static void setfield (lua_State *L, const char *key, int value) { + lua_pushinteger(L, value); + lua_setfield(L, -2, key); +} + +static void setboolfield (lua_State *L, const char *key, int value) { + if (value < 0) /* undefined? */ + return; /* does not set field */ + lua_pushboolean(L, value); + lua_setfield(L, -2, key); +} + +static int getboolfield (lua_State *L, const char *key) { + int res; + lua_getfield(L, -1, key); + res = lua_isnil(L, -1) ? -1 : lua_toboolean(L, -1); + lua_pop(L, 1); + return res; +} + + +static int getfield (lua_State *L, const char *key, int d) { + int res; + lua_getfield(L, -1, key); + if (lua_isnumber(L, -1)) + res = (int)lua_tointeger(L, -1); + else { + if (d < 0) + return luaL_error(L, "field " LUA_QS " missing in date table", key); + res = d; + } + lua_pop(L, 1); + return res; +} + + +static int os_date (lua_State *L) { + const char *s = luaL_optstring(L, 1, "%c"); + time_t t = luaL_opt(L, (time_t)luaL_checknumber, 2, time(NULL)); + struct tm *stm; + if (*s == '!') { /* UTC? */ + stm = gmtime(&t); + s++; /* skip `!' */ + } + else + stm = localtime(&t); + if (stm == NULL) /* invalid date? */ + lua_pushnil(L); + else if (strcmp(s, "*t") == 0) { + lua_createtable(L, 0, 9); /* 9 = number of fields */ + setfield(L, "sec", stm->tm_sec); + setfield(L, "min", stm->tm_min); + setfield(L, "hour", stm->tm_hour); + setfield(L, "day", stm->tm_mday); + setfield(L, "month", stm->tm_mon+1); + setfield(L, "year", stm->tm_year+1900); + setfield(L, "wday", stm->tm_wday+1); + setfield(L, "yday", stm->tm_yday+1); + setboolfield(L, "isdst", stm->tm_isdst); + } + else { + char cc[3]; + luaL_Buffer b; + cc[0] = '%'; cc[2] = '\0'; + luaL_buffinit(L, &b); + for (; *s; s++) { + if (*s != '%' || *(s + 1) == '\0') /* no conversion specifier? */ + luaL_addchar(&b, *s); + else { + size_t reslen; + char buff[200]; /* should be big enough for any conversion result */ + cc[1] = *(++s); + reslen = strftime(buff, sizeof(buff), cc, stm); + luaL_addlstring(&b, buff, reslen); + } + } + luaL_pushresult(&b); + } + return 1; +} + + +static int os_time (lua_State *L) { + time_t t; + if (lua_isnoneornil(L, 1)) /* called without args? */ + t = time(NULL); /* get current time */ + else { + struct tm ts; + luaL_checktype(L, 1, LUA_TTABLE); + lua_settop(L, 1); /* make sure table is at the top */ + ts.tm_sec = getfield(L, "sec", 0); + ts.tm_min = getfield(L, "min", 0); + ts.tm_hour = getfield(L, "hour", 12); + ts.tm_mday = getfield(L, "day", -1); + ts.tm_mon = getfield(L, "month", -1) - 1; + ts.tm_year = getfield(L, "year", -1) - 1900; + ts.tm_isdst = getboolfield(L, "isdst"); + t = mktime(&ts); + } + if (t == (time_t)(-1)) + lua_pushnil(L); + else + lua_pushnumber(L, (lua_Number)t); + return 1; +} + + +static int os_difftime (lua_State *L) { + lua_pushnumber(L, difftime((time_t)(luaL_checknumber(L, 1)), + (time_t)(luaL_optnumber(L, 2, 0)))); + return 1; +} + +/* }====================================================== */ + + +static int os_setlocale (lua_State *L) { + static const int cat[] = {LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, + LC_NUMERIC, LC_TIME}; + static const char *const catnames[] = {"all", "collate", "ctype", "monetary", + "numeric", "time", NULL}; + const char *l = luaL_optstring(L, 1, NULL); + int op = luaL_checkoption(L, 2, "all", catnames); + lua_pushstring(L, setlocale(cat[op], l)); + return 1; +} + + +static int os_exit (lua_State *L) { + exit(luaL_optint(L, 1, EXIT_SUCCESS)); +} + +static const luaL_Reg syslib[] = { + {"clock", os_clock}, + {"date", os_date}, + {"difftime", os_difftime}, + {"execute", os_execute}, + {"exit", os_exit}, + {"getenv", os_getenv}, + {"remove", os_remove}, + {"rename", os_rename}, + {"setlocale", os_setlocale}, + {"time", os_time}, + {"tmpname", os_tmpname}, + {NULL, NULL} +}; + +/* }====================================================== */ + + + +LUALIB_API int luaopen_os (lua_State *L) { + luaL_register(L, LUA_OSLIBNAME, syslib); + return 1; +} + diff --git a/IOS/lua/lua/lparser.c b/IOS/lua/lua/lparser.c new file mode 100644 index 00000000..1e2a9a88 --- /dev/null +++ b/IOS/lua/lua/lparser.c @@ -0,0 +1,1339 @@ +/* +** $Id: lparser.c,v 2.42.1.3 2007/12/28 15:32:23 roberto Exp $ +** Lua Parser +** See Copyright Notice in lua.h +*/ + + +#include + +#define lparser_c +#define LUA_CORE + +#include "lua.h" + +#include "lcode.h" +#include "ldebug.h" +#include "ldo.h" +#include "lfunc.h" +#include "llex.h" +#include "lmem.h" +#include "lobject.h" +#include "lopcodes.h" +#include "lparser.h" +#include "lstate.h" +#include "lstring.h" +#include "ltable.h" + + + +#define hasmultret(k) ((k) == VCALL || (k) == VVARARG) + +#define getlocvar(fs, i) ((fs)->f->locvars[(fs)->actvar[i]]) + +#define luaY_checklimit(fs,v,l,m) if ((v)>(l)) errorlimit(fs,l,m) + + +/* +** nodes for block list (list of active blocks) +*/ +typedef struct BlockCnt { + struct BlockCnt *previous; /* chain */ + int breaklist; /* list of jumps out of this loop */ + lu_byte nactvar; /* # active locals outside the breakable structure */ + lu_byte upval; /* true if some variable in the block is an upvalue */ + lu_byte isbreakable; /* true if `block' is a loop */ +} BlockCnt; + + + +/* +** prototypes for recursive non-terminal functions +*/ +static void chunk (LexState *ls); +static void expr (LexState *ls, expdesc *v); + + +static void anchor_token (LexState *ls) { + if (ls->t.token == TK_NAME || ls->t.token == TK_STRING) { + TString *ts = ls->t.seminfo.ts; + luaX_newstring(ls, getstr(ts), ts->tsv.len); + } +} + + +static void error_expected (LexState *ls, int token) { + luaX_syntaxerror(ls, + luaO_pushfstring(ls->L, LUA_QS " expected", luaX_token2str(ls, token))); +} + + +static void errorlimit (FuncState *fs, int limit, const char *what) { + const char *msg = (fs->f->linedefined == 0) ? + luaO_pushfstring(fs->L, "main function has more than %d %s", limit, what) : + luaO_pushfstring(fs->L, "function at line %d has more than %d %s", + fs->f->linedefined, limit, what); + luaX_lexerror(fs->ls, msg, 0); +} + + +static int testnext (LexState *ls, int c) { + if (ls->t.token == c) { + luaX_next(ls); + return 1; + } + else return 0; +} + + +static void check (LexState *ls, int c) { + if (ls->t.token != c) + error_expected(ls, c); +} + +static void checknext (LexState *ls, int c) { + check(ls, c); + luaX_next(ls); +} + + +#define check_condition(ls,c,msg) { if (!(c)) luaX_syntaxerror(ls, msg); } + + + +static void check_match (LexState *ls, int what, int who, int where) { + if (!testnext(ls, what)) { + if (where == ls->linenumber) + error_expected(ls, what); + else { + luaX_syntaxerror(ls, luaO_pushfstring(ls->L, + LUA_QS " expected (to close " LUA_QS " at line %d)", + luaX_token2str(ls, what), luaX_token2str(ls, who), where)); + } + } +} + + +static TString *str_checkname (LexState *ls) { + TString *ts; + check(ls, TK_NAME); + ts = ls->t.seminfo.ts; + luaX_next(ls); + return ts; +} + + +static void init_exp (expdesc *e, expkind k, int i) { + e->f = e->t = NO_JUMP; + e->k = k; + e->u.s.info = i; +} + + +static void codestring (LexState *ls, expdesc *e, TString *s) { + init_exp(e, VK, luaK_stringK(ls->fs, s)); +} + + +static void checkname(LexState *ls, expdesc *e) { + codestring(ls, e, str_checkname(ls)); +} + + +static int registerlocalvar (LexState *ls, TString *varname) { + FuncState *fs = ls->fs; + Proto *f = fs->f; + int oldsize = f->sizelocvars; + luaM_growvector(ls->L, f->locvars, fs->nlocvars, f->sizelocvars, + LocVar, SHRT_MAX, "too many local variables"); + while (oldsize < f->sizelocvars) f->locvars[oldsize++].varname = NULL; + f->locvars[fs->nlocvars].varname = varname; + luaC_objbarrier(ls->L, f, varname); + return fs->nlocvars++; +} + + +#define new_localvarliteral(ls,v,n) \ + new_localvar(ls, luaX_newstring(ls, "" v, (sizeof(v)/sizeof(char))-1), n) + + +static void new_localvar (LexState *ls, TString *name, int n) { + FuncState *fs = ls->fs; + luaY_checklimit(fs, fs->nactvar+n+1, LUAI_MAXVARS, "local variables"); + fs->actvar[fs->nactvar+n] = cast(unsigned short, registerlocalvar(ls, name)); +} + + +static void adjustlocalvars (LexState *ls, int nvars) { + FuncState *fs = ls->fs; + fs->nactvar = cast_byte(fs->nactvar + nvars); + for (; nvars; nvars--) { + getlocvar(fs, fs->nactvar - nvars).startpc = fs->pc; + } +} + + +static void removevars (LexState *ls, int tolevel) { + FuncState *fs = ls->fs; + while (fs->nactvar > tolevel) + getlocvar(fs, --fs->nactvar).endpc = fs->pc; +} + + +static int indexupvalue (FuncState *fs, TString *name, expdesc *v) { + int i; + Proto *f = fs->f; + int oldsize = f->sizeupvalues; + for (i=0; inups; i++) { + if (fs->upvalues[i].k == v->k && fs->upvalues[i].info == v->u.s.info) { + lua_assert(f->upvalues[i] == name); + return i; + } + } + /* new one */ + luaY_checklimit(fs, f->nups + 1, LUAI_MAXUPVALUES, "upvalues"); + luaM_growvector(fs->L, f->upvalues, f->nups, f->sizeupvalues, + TString *, MAX_INT, ""); + while (oldsize < f->sizeupvalues) f->upvalues[oldsize++] = NULL; + f->upvalues[f->nups] = name; + luaC_objbarrier(fs->L, f, name); + lua_assert(v->k == VLOCAL || v->k == VUPVAL); + fs->upvalues[f->nups].k = cast_byte(v->k); + fs->upvalues[f->nups].info = cast_byte(v->u.s.info); + return f->nups++; +} + + +static int searchvar (FuncState *fs, TString *n) { + int i; + for (i=fs->nactvar-1; i >= 0; i--) { + if (n == getlocvar(fs, i).varname) + return i; + } + return -1; /* not found */ +} + + +static void markupval (FuncState *fs, int level) { + BlockCnt *bl = fs->bl; + while (bl && bl->nactvar > level) bl = bl->previous; + if (bl) bl->upval = 1; +} + + +static int singlevaraux (FuncState *fs, TString *n, expdesc *var, int base) { + if (fs == NULL) { /* no more levels? */ + init_exp(var, VGLOBAL, NO_REG); /* default is global variable */ + return VGLOBAL; + } + else { + int v = searchvar(fs, n); /* look up at current level */ + if (v >= 0) { + init_exp(var, VLOCAL, v); + if (!base) + markupval(fs, v); /* local will be used as an upval */ + return VLOCAL; + } + else { /* not found at current level; try upper one */ + if (singlevaraux(fs->prev, n, var, 0) == VGLOBAL) + return VGLOBAL; + var->u.s.info = indexupvalue(fs, n, var); /* else was LOCAL or UPVAL */ + var->k = VUPVAL; /* upvalue in this level */ + return VUPVAL; + } + } +} + + +static void singlevar (LexState *ls, expdesc *var) { + TString *varname = str_checkname(ls); + FuncState *fs = ls->fs; + if (singlevaraux(fs, varname, var, 1) == VGLOBAL) + var->u.s.info = luaK_stringK(fs, varname); /* info points to global name */ +} + + +static void adjust_assign (LexState *ls, int nvars, int nexps, expdesc *e) { + FuncState *fs = ls->fs; + int extra = nvars - nexps; + if (hasmultret(e->k)) { + extra++; /* includes call itself */ + if (extra < 0) extra = 0; + luaK_setreturns(fs, e, extra); /* last exp. provides the difference */ + if (extra > 1) luaK_reserveregs(fs, extra-1); + } + else { + if (e->k != VVOID) luaK_exp2nextreg(fs, e); /* close last expression */ + if (extra > 0) { + int reg = fs->freereg; + luaK_reserveregs(fs, extra); + luaK_nil(fs, reg, extra); + } + } +} + + +static void enterlevel (LexState *ls) { + if (++ls->L->nCcalls > LUAI_MAXCCALLS) + luaX_lexerror(ls, "chunk has too many syntax levels", 0); +} + + +#define leavelevel(ls) ((ls)->L->nCcalls--) + + +static void enterblock (FuncState *fs, BlockCnt *bl, lu_byte isbreakable) { + bl->breaklist = NO_JUMP; + bl->isbreakable = isbreakable; + bl->nactvar = fs->nactvar; + bl->upval = 0; + bl->previous = fs->bl; + fs->bl = bl; + lua_assert(fs->freereg == fs->nactvar); +} + + +static void leaveblock (FuncState *fs) { + BlockCnt *bl = fs->bl; + fs->bl = bl->previous; + removevars(fs->ls, bl->nactvar); + if (bl->upval) + luaK_codeABC(fs, OP_CLOSE, bl->nactvar, 0, 0); + /* a block either controls scope or breaks (never both) */ + lua_assert(!bl->isbreakable || !bl->upval); + lua_assert(bl->nactvar == fs->nactvar); + fs->freereg = fs->nactvar; /* free registers */ + luaK_patchtohere(fs, bl->breaklist); +} + + +static void pushclosure (LexState *ls, FuncState *func, expdesc *v) { + FuncState *fs = ls->fs; + Proto *f = fs->f; + int oldsize = f->sizep; + int i; + luaM_growvector(ls->L, f->p, fs->np, f->sizep, Proto *, + MAXARG_Bx, "constant table overflow"); + while (oldsize < f->sizep) f->p[oldsize++] = NULL; + f->p[fs->np++] = func->f; + luaC_objbarrier(ls->L, f, func->f); + init_exp(v, VRELOCABLE, luaK_codeABx(fs, OP_CLOSURE, 0, fs->np-1)); + for (i=0; if->nups; i++) { + OpCode o = (func->upvalues[i].k == VLOCAL) ? OP_MOVE : OP_GETUPVAL; + luaK_codeABC(fs, o, 0, func->upvalues[i].info, 0); + } +} + + +static void open_func (LexState *ls, FuncState *fs) { + lua_State *L = ls->L; + Proto *f = luaF_newproto(L); + fs->f = f; + fs->prev = ls->fs; /* linked list of funcstates */ + fs->ls = ls; + fs->L = L; + ls->fs = fs; + fs->pc = 0; + fs->lasttarget = -1; + fs->jpc = NO_JUMP; + fs->freereg = 0; + fs->nk = 0; + fs->np = 0; + fs->nlocvars = 0; + fs->nactvar = 0; + fs->bl = NULL; + f->source = ls->source; + f->maxstacksize = 2; /* registers 0/1 are always valid */ + fs->h = luaH_new(L, 0, 0); + /* anchor table of constants and prototype (to avoid being collected) */ + sethvalue2s(L, L->top, fs->h); + incr_top(L); + setptvalue2s(L, L->top, f); + incr_top(L); +} + + +static void close_func (LexState *ls) { + lua_State *L = ls->L; + FuncState *fs = ls->fs; + Proto *f = fs->f; + removevars(ls, 0); + luaK_ret(fs, 0, 0); /* final return */ + luaM_reallocvector(L, f->code, f->sizecode, fs->pc, Instruction); + f->sizecode = fs->pc; + luaM_reallocvector(L, f->lineinfo, f->sizelineinfo, fs->pc, int); + f->sizelineinfo = fs->pc; + luaM_reallocvector(L, f->k, f->sizek, fs->nk, TValue); + f->sizek = fs->nk; + luaM_reallocvector(L, f->p, f->sizep, fs->np, Proto *); + f->sizep = fs->np; + luaM_reallocvector(L, f->locvars, f->sizelocvars, fs->nlocvars, LocVar); + f->sizelocvars = fs->nlocvars; + luaM_reallocvector(L, f->upvalues, f->sizeupvalues, f->nups, TString *); + f->sizeupvalues = f->nups; + lua_assert(luaG_checkcode(f)); + lua_assert(fs->bl == NULL); + ls->fs = fs->prev; + L->top -= 2; /* remove table and prototype from the stack */ + /* last token read was anchored in defunct function; must reanchor it */ + if (fs) anchor_token(ls); +} + + +Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, const char *name) { + struct LexState lexstate; + struct FuncState funcstate; + lexstate.buff = buff; + luaX_setinput(L, &lexstate, z, luaS_new(L, name)); + open_func(&lexstate, &funcstate); + funcstate.f->is_vararg = VARARG_ISVARARG; /* main func. is always vararg */ + luaX_next(&lexstate); /* read first token */ + chunk(&lexstate); + check(&lexstate, TK_EOS); + close_func(&lexstate); + lua_assert(funcstate.prev == NULL); + lua_assert(funcstate.f->nups == 0); + lua_assert(lexstate.fs == NULL); + return funcstate.f; +} + + + +/*============================================================*/ +/* GRAMMAR RULES */ +/*============================================================*/ + + +static void field (LexState *ls, expdesc *v) { + /* field -> ['.' | ':'] NAME */ + FuncState *fs = ls->fs; + expdesc key; + luaK_exp2anyreg(fs, v); + luaX_next(ls); /* skip the dot or colon */ + checkname(ls, &key); + luaK_indexed(fs, v, &key); +} + + +static void yindex (LexState *ls, expdesc *v) { + /* index -> '[' expr ']' */ + luaX_next(ls); /* skip the '[' */ + expr(ls, v); + luaK_exp2val(ls->fs, v); + checknext(ls, ']'); +} + + +/* +** {====================================================================== +** Rules for Constructors +** ======================================================================= +*/ + + +struct ConsControl { + expdesc v; /* last list item read */ + expdesc *t; /* table descriptor */ + int nh; /* total number of `record' elements */ + int na; /* total number of array elements */ + int tostore; /* number of array elements pending to be stored */ +}; + + +static void recfield (LexState *ls, struct ConsControl *cc) { + /* recfield -> (NAME | `['exp1`]') = exp1 */ + FuncState *fs = ls->fs; + int reg = ls->fs->freereg; + expdesc key, val; + int rkkey; + if (ls->t.token == TK_NAME) { + luaY_checklimit(fs, cc->nh, MAX_INT, "items in a constructor"); + checkname(ls, &key); + } + else /* ls->t.token == '[' */ + yindex(ls, &key); + cc->nh++; + checknext(ls, '='); + rkkey = luaK_exp2RK(fs, &key); + expr(ls, &val); + luaK_codeABC(fs, OP_SETTABLE, cc->t->u.s.info, rkkey, luaK_exp2RK(fs, &val)); + fs->freereg = reg; /* free registers */ +} + + +static void closelistfield (FuncState *fs, struct ConsControl *cc) { + if (cc->v.k == VVOID) return; /* there is no list item */ + luaK_exp2nextreg(fs, &cc->v); + cc->v.k = VVOID; + if (cc->tostore == LFIELDS_PER_FLUSH) { + luaK_setlist(fs, cc->t->u.s.info, cc->na, cc->tostore); /* flush */ + cc->tostore = 0; /* no more items pending */ + } +} + + +static void lastlistfield (FuncState *fs, struct ConsControl *cc) { + if (cc->tostore == 0) return; + if (hasmultret(cc->v.k)) { + luaK_setmultret(fs, &cc->v); + luaK_setlist(fs, cc->t->u.s.info, cc->na, LUA_MULTRET); + cc->na--; /* do not count last expression (unknown number of elements) */ + } + else { + if (cc->v.k != VVOID) + luaK_exp2nextreg(fs, &cc->v); + luaK_setlist(fs, cc->t->u.s.info, cc->na, cc->tostore); + } +} + + +static void listfield (LexState *ls, struct ConsControl *cc) { + expr(ls, &cc->v); + luaY_checklimit(ls->fs, cc->na, MAX_INT, "items in a constructor"); + cc->na++; + cc->tostore++; +} + + +static void constructor (LexState *ls, expdesc *t) { + /* constructor -> ?? */ + FuncState *fs = ls->fs; + int line = ls->linenumber; + int pc = luaK_codeABC(fs, OP_NEWTABLE, 0, 0, 0); + struct ConsControl cc; + cc.na = cc.nh = cc.tostore = 0; + cc.t = t; + init_exp(t, VRELOCABLE, pc); + init_exp(&cc.v, VVOID, 0); /* no value (yet) */ + luaK_exp2nextreg(ls->fs, t); /* fix it at stack top (for gc) */ + checknext(ls, '{'); + do { + lua_assert(cc.v.k == VVOID || cc.tostore > 0); + if (ls->t.token == '}') break; + closelistfield(fs, &cc); + switch(ls->t.token) { + case TK_NAME: { /* may be listfields or recfields */ + luaX_lookahead(ls); + if (ls->lookahead.token != '=') /* expression? */ + listfield(ls, &cc); + else + recfield(ls, &cc); + break; + } + case '[': { /* constructor_item -> recfield */ + recfield(ls, &cc); + break; + } + default: { /* constructor_part -> listfield */ + listfield(ls, &cc); + break; + } + } + } while (testnext(ls, ',') || testnext(ls, ';')); + check_match(ls, '}', '{', line); + lastlistfield(fs, &cc); + SETARG_B(fs->f->code[pc], luaO_int2fb(cc.na)); /* set initial array size */ + SETARG_C(fs->f->code[pc], luaO_int2fb(cc.nh)); /* set initial table size */ +} + +/* }====================================================================== */ + + + +static void parlist (LexState *ls) { + /* parlist -> [ param { `,' param } ] */ + FuncState *fs = ls->fs; + Proto *f = fs->f; + int nparams = 0; + f->is_vararg = 0; + if (ls->t.token != ')') { /* is `parlist' not empty? */ + do { + switch (ls->t.token) { + case TK_NAME: { /* param -> NAME */ + new_localvar(ls, str_checkname(ls), nparams++); + break; + } + case TK_DOTS: { /* param -> `...' */ + luaX_next(ls); +#if defined(LUA_COMPAT_VARARG) + /* use `arg' as default name */ + new_localvarliteral(ls, "arg", nparams++); + f->is_vararg = VARARG_HASARG | VARARG_NEEDSARG; +#endif + f->is_vararg |= VARARG_ISVARARG; + break; + } + default: luaX_syntaxerror(ls, " or " LUA_QL("...") " expected"); + } + } while (!f->is_vararg && testnext(ls, ',')); + } + adjustlocalvars(ls, nparams); + f->numparams = cast_byte(fs->nactvar - (f->is_vararg & VARARG_HASARG)); + luaK_reserveregs(fs, fs->nactvar); /* reserve register for parameters */ +} + + +static void body (LexState *ls, expdesc *e, int needself, int line) { + /* body -> `(' parlist `)' chunk END */ + FuncState new_fs; + open_func(ls, &new_fs); + new_fs.f->linedefined = line; + checknext(ls, '('); + if (needself) { + new_localvarliteral(ls, "self", 0); + adjustlocalvars(ls, 1); + } + parlist(ls); + checknext(ls, ')'); + chunk(ls); + new_fs.f->lastlinedefined = ls->linenumber; + check_match(ls, TK_END, TK_FUNCTION, line); + close_func(ls); + pushclosure(ls, &new_fs, e); +} + + +static int explist1 (LexState *ls, expdesc *v) { + /* explist1 -> expr { `,' expr } */ + int n = 1; /* at least one expression */ + expr(ls, v); + while (testnext(ls, ',')) { + luaK_exp2nextreg(ls->fs, v); + expr(ls, v); + n++; + } + return n; +} + + +static void funcargs (LexState *ls, expdesc *f) { + FuncState *fs = ls->fs; + expdesc args; + int base, nparams; + int line = ls->linenumber; + switch (ls->t.token) { + case '(': { /* funcargs -> `(' [ explist1 ] `)' */ + if (line != ls->lastline) + luaX_syntaxerror(ls,"ambiguous syntax (function call x new statement)"); + luaX_next(ls); + if (ls->t.token == ')') /* arg list is empty? */ + args.k = VVOID; + else { + explist1(ls, &args); + luaK_setmultret(fs, &args); + } + check_match(ls, ')', '(', line); + break; + } + case '{': { /* funcargs -> constructor */ + constructor(ls, &args); + break; + } + case TK_STRING: { /* funcargs -> STRING */ + codestring(ls, &args, ls->t.seminfo.ts); + luaX_next(ls); /* must use `seminfo' before `next' */ + break; + } + default: { + luaX_syntaxerror(ls, "function arguments expected"); + return; + } + } + lua_assert(f->k == VNONRELOC); + base = f->u.s.info; /* base register for call */ + if (hasmultret(args.k)) + nparams = LUA_MULTRET; /* open call */ + else { + if (args.k != VVOID) + luaK_exp2nextreg(fs, &args); /* close last argument */ + nparams = fs->freereg - (base+1); + } + init_exp(f, VCALL, luaK_codeABC(fs, OP_CALL, base, nparams+1, 2)); + luaK_fixline(fs, line); + fs->freereg = base+1; /* call remove function and arguments and leaves + (unless changed) one result */ +} + + + + +/* +** {====================================================================== +** Expression parsing +** ======================================================================= +*/ + + +static void prefixexp (LexState *ls, expdesc *v) { + /* prefixexp -> NAME | '(' expr ')' */ + switch (ls->t.token) { + case '(': { + int line = ls->linenumber; + luaX_next(ls); + expr(ls, v); + check_match(ls, ')', '(', line); + luaK_dischargevars(ls->fs, v); + return; + } + case TK_NAME: { + singlevar(ls, v); + return; + } + default: { + luaX_syntaxerror(ls, "unexpected symbol"); + return; + } + } +} + + +static void primaryexp (LexState *ls, expdesc *v) { + /* primaryexp -> + prefixexp { `.' NAME | `[' exp `]' | `:' NAME funcargs | funcargs } */ + FuncState *fs = ls->fs; + prefixexp(ls, v); + for (;;) { + switch (ls->t.token) { + case '.': { /* field */ + field(ls, v); + break; + } + case '[': { /* `[' exp1 `]' */ + expdesc key; + luaK_exp2anyreg(fs, v); + yindex(ls, &key); + luaK_indexed(fs, v, &key); + break; + } + case ':': { /* `:' NAME funcargs */ + expdesc key; + luaX_next(ls); + checkname(ls, &key); + luaK_self(fs, v, &key); + funcargs(ls, v); + break; + } + case '(': case TK_STRING: case '{': { /* funcargs */ + luaK_exp2nextreg(fs, v); + funcargs(ls, v); + break; + } + default: return; + } + } +} + + +static void simpleexp (LexState *ls, expdesc *v) { + /* simpleexp -> NUMBER | STRING | NIL | true | false | ... | + constructor | FUNCTION body | primaryexp */ + switch (ls->t.token) { + case TK_NUMBER: { + init_exp(v, VKNUM, 0); + v->u.nval = ls->t.seminfo.r; + break; + } + case TK_STRING: { + codestring(ls, v, ls->t.seminfo.ts); + break; + } + case TK_NIL: { + init_exp(v, VNIL, 0); + break; + } + case TK_TRUE: { + init_exp(v, VTRUE, 0); + break; + } + case TK_FALSE: { + init_exp(v, VFALSE, 0); + break; + } + case TK_DOTS: { /* vararg */ + FuncState *fs = ls->fs; + check_condition(ls, fs->f->is_vararg, + "cannot use " LUA_QL("...") " outside a vararg function"); + fs->f->is_vararg &= ~VARARG_NEEDSARG; /* don't need 'arg' */ + init_exp(v, VVARARG, luaK_codeABC(fs, OP_VARARG, 0, 1, 0)); + break; + } + case '{': { /* constructor */ + constructor(ls, v); + return; + } + case TK_FUNCTION: { + luaX_next(ls); + body(ls, v, 0, ls->linenumber); + return; + } + default: { + primaryexp(ls, v); + return; + } + } + luaX_next(ls); +} + + +static UnOpr getunopr (int op) { + switch (op) { + case TK_NOT: return OPR_NOT; + case '-': return OPR_MINUS; + case '#': return OPR_LEN; + default: return OPR_NOUNOPR; + } +} + + +static BinOpr getbinopr (int op) { + switch (op) { + case '+': return OPR_ADD; + case '-': return OPR_SUB; + case '*': return OPR_MUL; + case '/': return OPR_DIV; + case '%': return OPR_MOD; + case '^': return OPR_POW; + case TK_CONCAT: return OPR_CONCAT; + case TK_NE: return OPR_NE; + case TK_EQ: return OPR_EQ; + case '<': return OPR_LT; + case TK_LE: return OPR_LE; + case '>': return OPR_GT; + case TK_GE: return OPR_GE; + case TK_AND: return OPR_AND; + case TK_OR: return OPR_OR; + default: return OPR_NOBINOPR; + } +} + + +static const struct { + lu_byte left; /* left priority for each binary operator */ + lu_byte right; /* right priority */ +} priority[] = { /* ORDER OPR */ + {6, 6}, {6, 6}, {7, 7}, {7, 7}, {7, 7}, /* `+' `-' `/' `%' */ + {10, 9}, {5, 4}, /* power and concat (right associative) */ + {3, 3}, {3, 3}, /* equality and inequality */ + {3, 3}, {3, 3}, {3, 3}, {3, 3}, /* order */ + {2, 2}, {1, 1} /* logical (and/or) */ +}; + +#define UNARY_PRIORITY 8 /* priority for unary operators */ + + +/* +** subexpr -> (simpleexp | unop subexpr) { binop subexpr } +** where `binop' is any binary operator with a priority higher than `limit' +*/ +static BinOpr subexpr (LexState *ls, expdesc *v, unsigned int limit) { + BinOpr op; + UnOpr uop; + enterlevel(ls); + uop = getunopr(ls->t.token); + if (uop != OPR_NOUNOPR) { + luaX_next(ls); + subexpr(ls, v, UNARY_PRIORITY); + luaK_prefix(ls->fs, uop, v); + } + else simpleexp(ls, v); + /* expand while operators have priorities higher than `limit' */ + op = getbinopr(ls->t.token); + while (op != OPR_NOBINOPR && priority[op].left > limit) { + expdesc v2; + BinOpr nextop; + luaX_next(ls); + luaK_infix(ls->fs, op, v); + /* read sub-expression with higher priority */ + nextop = subexpr(ls, &v2, priority[op].right); + luaK_posfix(ls->fs, op, v, &v2); + op = nextop; + } + leavelevel(ls); + return op; /* return first untreated operator */ +} + + +static void expr (LexState *ls, expdesc *v) { + subexpr(ls, v, 0); +} + +/* }==================================================================== */ + + + +/* +** {====================================================================== +** Rules for Statements +** ======================================================================= +*/ + + +static int block_follow (int token) { + switch (token) { + case TK_ELSE: case TK_ELSEIF: case TK_END: + case TK_UNTIL: case TK_EOS: + return 1; + default: return 0; + } +} + + +static void block (LexState *ls) { + /* block -> chunk */ + FuncState *fs = ls->fs; + BlockCnt bl; + enterblock(fs, &bl, 0); + chunk(ls); + lua_assert(bl.breaklist == NO_JUMP); + leaveblock(fs); +} + + +/* +** structure to chain all variables in the left-hand side of an +** assignment +*/ +struct LHS_assign { + struct LHS_assign *prev; + expdesc v; /* variable (global, local, upvalue, or indexed) */ +}; + + +/* +** check whether, in an assignment to a local variable, the local variable +** is needed in a previous assignment (to a table). If so, save original +** local value in a safe place and use this safe copy in the previous +** assignment. +*/ +static void check_conflict (LexState *ls, struct LHS_assign *lh, expdesc *v) { + FuncState *fs = ls->fs; + int extra = fs->freereg; /* eventual position to save local variable */ + int conflict = 0; + for (; lh; lh = lh->prev) { + if (lh->v.k == VINDEXED) { + if (lh->v.u.s.info == v->u.s.info) { /* conflict? */ + conflict = 1; + lh->v.u.s.info = extra; /* previous assignment will use safe copy */ + } + if (lh->v.u.s.aux == v->u.s.info) { /* conflict? */ + conflict = 1; + lh->v.u.s.aux = extra; /* previous assignment will use safe copy */ + } + } + } + if (conflict) { + luaK_codeABC(fs, OP_MOVE, fs->freereg, v->u.s.info, 0); /* make copy */ + luaK_reserveregs(fs, 1); + } +} + + +static void assignment (LexState *ls, struct LHS_assign *lh, int nvars) { + expdesc e; + check_condition(ls, VLOCAL <= lh->v.k && lh->v.k <= VINDEXED, + "syntax error"); + if (testnext(ls, ',')) { /* assignment -> `,' primaryexp assignment */ + struct LHS_assign nv; + nv.prev = lh; + primaryexp(ls, &nv.v); + if (nv.v.k == VLOCAL) + check_conflict(ls, lh, &nv.v); + luaY_checklimit(ls->fs, nvars, LUAI_MAXCCALLS - ls->L->nCcalls, + "variables in assignment"); + assignment(ls, &nv, nvars+1); + } + else { /* assignment -> `=' explist1 */ + int nexps; + checknext(ls, '='); + nexps = explist1(ls, &e); + if (nexps != nvars) { + adjust_assign(ls, nvars, nexps, &e); + if (nexps > nvars) + ls->fs->freereg -= nexps - nvars; /* remove extra values */ + } + else { + luaK_setoneret(ls->fs, &e); /* close last expression */ + luaK_storevar(ls->fs, &lh->v, &e); + return; /* avoid default */ + } + } + init_exp(&e, VNONRELOC, ls->fs->freereg-1); /* default assignment */ + luaK_storevar(ls->fs, &lh->v, &e); +} + + +static int cond (LexState *ls) { + /* cond -> exp */ + expdesc v; + expr(ls, &v); /* read condition */ + if (v.k == VNIL) v.k = VFALSE; /* `falses' are all equal here */ + luaK_goiftrue(ls->fs, &v); + return v.f; +} + + +static void breakstat (LexState *ls) { + FuncState *fs = ls->fs; + BlockCnt *bl = fs->bl; + int upval = 0; + while (bl && !bl->isbreakable) { + upval |= bl->upval; + bl = bl->previous; + } + if (!bl) + luaX_syntaxerror(ls, "no loop to break"); + if (upval) + luaK_codeABC(fs, OP_CLOSE, bl->nactvar, 0, 0); + luaK_concat(fs, &bl->breaklist, luaK_jump(fs)); +} + + +static void whilestat (LexState *ls, int line) { + /* whilestat -> WHILE cond DO block END */ + FuncState *fs = ls->fs; + int whileinit; + int condexit; + BlockCnt bl; + luaX_next(ls); /* skip WHILE */ + whileinit = luaK_getlabel(fs); + condexit = cond(ls); + enterblock(fs, &bl, 1); + checknext(ls, TK_DO); + block(ls); + luaK_patchlist(fs, luaK_jump(fs), whileinit); + check_match(ls, TK_END, TK_WHILE, line); + leaveblock(fs); + luaK_patchtohere(fs, condexit); /* false conditions finish the loop */ +} + + +static void repeatstat (LexState *ls, int line) { + /* repeatstat -> REPEAT block UNTIL cond */ + int condexit; + FuncState *fs = ls->fs; + int repeat_init = luaK_getlabel(fs); + BlockCnt bl1, bl2; + enterblock(fs, &bl1, 1); /* loop block */ + enterblock(fs, &bl2, 0); /* scope block */ + luaX_next(ls); /* skip REPEAT */ + chunk(ls); + check_match(ls, TK_UNTIL, TK_REPEAT, line); + condexit = cond(ls); /* read condition (inside scope block) */ + if (!bl2.upval) { /* no upvalues? */ + leaveblock(fs); /* finish scope */ + luaK_patchlist(ls->fs, condexit, repeat_init); /* close the loop */ + } + else { /* complete semantics when there are upvalues */ + breakstat(ls); /* if condition then break */ + luaK_patchtohere(ls->fs, condexit); /* else... */ + leaveblock(fs); /* finish scope... */ + luaK_patchlist(ls->fs, luaK_jump(fs), repeat_init); /* and repeat */ + } + leaveblock(fs); /* finish loop */ +} + + +static int exp1 (LexState *ls) { + expdesc e; + int k; + expr(ls, &e); + k = e.k; + luaK_exp2nextreg(ls->fs, &e); + return k; +} + + +static void forbody (LexState *ls, int base, int line, int nvars, int isnum) { + /* forbody -> DO block */ + BlockCnt bl; + FuncState *fs = ls->fs; + int prep, endfor; + adjustlocalvars(ls, 3); /* control variables */ + checknext(ls, TK_DO); + prep = isnum ? luaK_codeAsBx(fs, OP_FORPREP, base, NO_JUMP) : luaK_jump(fs); + enterblock(fs, &bl, 0); /* scope for declared variables */ + adjustlocalvars(ls, nvars); + luaK_reserveregs(fs, nvars); + block(ls); + leaveblock(fs); /* end of scope for declared variables */ + luaK_patchtohere(fs, prep); + endfor = (isnum) ? luaK_codeAsBx(fs, OP_FORLOOP, base, NO_JUMP) : + luaK_codeABC(fs, OP_TFORLOOP, base, 0, nvars); + luaK_fixline(fs, line); /* pretend that `OP_FOR' starts the loop */ + luaK_patchlist(fs, (isnum ? endfor : luaK_jump(fs)), prep + 1); +} + + +static void fornum (LexState *ls, TString *varname, int line) { + /* fornum -> NAME = exp1,exp1[,exp1] forbody */ + FuncState *fs = ls->fs; + int base = fs->freereg; + new_localvarliteral(ls, "(for index)", 0); + new_localvarliteral(ls, "(for limit)", 1); + new_localvarliteral(ls, "(for step)", 2); + new_localvar(ls, varname, 3); + checknext(ls, '='); + exp1(ls); /* initial value */ + checknext(ls, ','); + exp1(ls); /* limit */ + if (testnext(ls, ',')) + exp1(ls); /* optional step */ + else { /* default step = 1 */ + luaK_codeABx(fs, OP_LOADK, fs->freereg, luaK_numberK(fs, 1)); + luaK_reserveregs(fs, 1); + } + forbody(ls, base, line, 1, 1); +} + + +static void forlist (LexState *ls, TString *indexname) { + /* forlist -> NAME {,NAME} IN explist1 forbody */ + FuncState *fs = ls->fs; + expdesc e; + int nvars = 0; + int line; + int base = fs->freereg; + /* create control variables */ + new_localvarliteral(ls, "(for generator)", nvars++); + new_localvarliteral(ls, "(for state)", nvars++); + new_localvarliteral(ls, "(for control)", nvars++); + /* create declared variables */ + new_localvar(ls, indexname, nvars++); + while (testnext(ls, ',')) + new_localvar(ls, str_checkname(ls), nvars++); + checknext(ls, TK_IN); + line = ls->linenumber; + adjust_assign(ls, 3, explist1(ls, &e), &e); + luaK_checkstack(fs, 3); /* extra space to call generator */ + forbody(ls, base, line, nvars - 3, 0); +} + + +static void forstat (LexState *ls, int line) { + /* forstat -> FOR (fornum | forlist) END */ + FuncState *fs = ls->fs; + TString *varname; + BlockCnt bl; + enterblock(fs, &bl, 1); /* scope for loop and control variables */ + luaX_next(ls); /* skip `for' */ + varname = str_checkname(ls); /* first variable name */ + switch (ls->t.token) { + case '=': fornum(ls, varname, line); break; + case ',': case TK_IN: forlist(ls, varname); break; + default: luaX_syntaxerror(ls, LUA_QL("=") " or " LUA_QL("in") " expected"); + } + check_match(ls, TK_END, TK_FOR, line); + leaveblock(fs); /* loop scope (`break' jumps to this point) */ +} + + +static int test_then_block (LexState *ls) { + /* test_then_block -> [IF | ELSEIF] cond THEN block */ + int condexit; + luaX_next(ls); /* skip IF or ELSEIF */ + condexit = cond(ls); + checknext(ls, TK_THEN); + block(ls); /* `then' part */ + return condexit; +} + + +static void ifstat (LexState *ls, int line) { + /* ifstat -> IF cond THEN block {ELSEIF cond THEN block} [ELSE block] END */ + FuncState *fs = ls->fs; + int flist; + int escapelist = NO_JUMP; + flist = test_then_block(ls); /* IF cond THEN block */ + while (ls->t.token == TK_ELSEIF) { + luaK_concat(fs, &escapelist, luaK_jump(fs)); + luaK_patchtohere(fs, flist); + flist = test_then_block(ls); /* ELSEIF cond THEN block */ + } + if (ls->t.token == TK_ELSE) { + luaK_concat(fs, &escapelist, luaK_jump(fs)); + luaK_patchtohere(fs, flist); + luaX_next(ls); /* skip ELSE (after patch, for correct line info) */ + block(ls); /* `else' part */ + } + else + luaK_concat(fs, &escapelist, flist); + luaK_patchtohere(fs, escapelist); + check_match(ls, TK_END, TK_IF, line); +} + + +static void localfunc (LexState *ls) { + expdesc v, b; + FuncState *fs = ls->fs; + new_localvar(ls, str_checkname(ls), 0); + init_exp(&v, VLOCAL, fs->freereg); + luaK_reserveregs(fs, 1); + adjustlocalvars(ls, 1); + body(ls, &b, 0, ls->linenumber); + luaK_storevar(fs, &v, &b); + /* debug information will only see the variable after this point! */ + getlocvar(fs, fs->nactvar - 1).startpc = fs->pc; +} + + +static void localstat (LexState *ls) { + /* stat -> LOCAL NAME {`,' NAME} [`=' explist1] */ + int nvars = 0; + int nexps; + expdesc e; + do { + new_localvar(ls, str_checkname(ls), nvars++); + } while (testnext(ls, ',')); + if (testnext(ls, '=')) + nexps = explist1(ls, &e); + else { + e.k = VVOID; + nexps = 0; + } + adjust_assign(ls, nvars, nexps, &e); + adjustlocalvars(ls, nvars); +} + + +static int funcname (LexState *ls, expdesc *v) { + /* funcname -> NAME {field} [`:' NAME] */ + int needself = 0; + singlevar(ls, v); + while (ls->t.token == '.') + field(ls, v); + if (ls->t.token == ':') { + needself = 1; + field(ls, v); + } + return needself; +} + + +static void funcstat (LexState *ls, int line) { + /* funcstat -> FUNCTION funcname body */ + int needself; + expdesc v, b; + luaX_next(ls); /* skip FUNCTION */ + needself = funcname(ls, &v); + body(ls, &b, needself, line); + luaK_storevar(ls->fs, &v, &b); + luaK_fixline(ls->fs, line); /* definition `happens' in the first line */ +} + + +static void exprstat (LexState *ls) { + /* stat -> func | assignment */ + FuncState *fs = ls->fs; + struct LHS_assign v; + primaryexp(ls, &v.v); + if (v.v.k == VCALL) /* stat -> func */ + SETARG_C(getcode(fs, &v.v), 1); /* call statement uses no results */ + else { /* stat -> assignment */ + v.prev = NULL; + assignment(ls, &v, 1); + } +} + + +static void retstat (LexState *ls) { + /* stat -> RETURN explist */ + FuncState *fs = ls->fs; + expdesc e; + int first, nret; /* registers with returned values */ + luaX_next(ls); /* skip RETURN */ + if (block_follow(ls->t.token) || ls->t.token == ';') + first = nret = 0; /* return no values */ + else { + nret = explist1(ls, &e); /* optional return values */ + if (hasmultret(e.k)) { + luaK_setmultret(fs, &e); + if (e.k == VCALL && nret == 1) { /* tail call? */ + SET_OPCODE(getcode(fs,&e), OP_TAILCALL); + lua_assert(GETARG_A(getcode(fs,&e)) == fs->nactvar); + } + first = fs->nactvar; + nret = LUA_MULTRET; /* return all values */ + } + else { + if (nret == 1) /* only one single value? */ + first = luaK_exp2anyreg(fs, &e); + else { + luaK_exp2nextreg(fs, &e); /* values must go to the `stack' */ + first = fs->nactvar; /* return all `active' values */ + lua_assert(nret == fs->freereg - first); + } + } + } + luaK_ret(fs, first, nret); +} + + +static int statement (LexState *ls) { + int line = ls->linenumber; /* may be needed for error messages */ + switch (ls->t.token) { + case TK_IF: { /* stat -> ifstat */ + ifstat(ls, line); + return 0; + } + case TK_WHILE: { /* stat -> whilestat */ + whilestat(ls, line); + return 0; + } + case TK_DO: { /* stat -> DO block END */ + luaX_next(ls); /* skip DO */ + block(ls); + check_match(ls, TK_END, TK_DO, line); + return 0; + } + case TK_FOR: { /* stat -> forstat */ + forstat(ls, line); + return 0; + } + case TK_REPEAT: { /* stat -> repeatstat */ + repeatstat(ls, line); + return 0; + } + case TK_FUNCTION: { + funcstat(ls, line); /* stat -> funcstat */ + return 0; + } + case TK_LOCAL: { /* stat -> localstat */ + luaX_next(ls); /* skip LOCAL */ + if (testnext(ls, TK_FUNCTION)) /* local function? */ + localfunc(ls); + else + localstat(ls); + return 0; + } + case TK_RETURN: { /* stat -> retstat */ + retstat(ls); + return 1; /* must be last statement */ + } + case TK_BREAK: { /* stat -> breakstat */ + luaX_next(ls); /* skip BREAK */ + breakstat(ls); + return 1; /* must be last statement */ + } + default: { + exprstat(ls); + return 0; /* to avoid warnings */ + } + } +} + + +static void chunk (LexState *ls) { + /* chunk -> { stat [`;'] } */ + int islast = 0; + enterlevel(ls); + while (!islast && !block_follow(ls->t.token)) { + islast = statement(ls); + testnext(ls, ';'); + lua_assert(ls->fs->f->maxstacksize >= ls->fs->freereg && + ls->fs->freereg >= ls->fs->nactvar); + ls->fs->freereg = ls->fs->nactvar; /* free registers */ + } + leavelevel(ls); +} + +/* }====================================================================== */ diff --git a/IOS/lua/lua/lparser.h b/IOS/lua/lua/lparser.h new file mode 100644 index 00000000..18836afd --- /dev/null +++ b/IOS/lua/lua/lparser.h @@ -0,0 +1,82 @@ +/* +** $Id: lparser.h,v 1.57.1.1 2007/12/27 13:02:25 roberto Exp $ +** Lua Parser +** See Copyright Notice in lua.h +*/ + +#ifndef lparser_h +#define lparser_h + +#include "llimits.h" +#include "lobject.h" +#include "lzio.h" + + +/* +** Expression descriptor +*/ + +typedef enum { + VVOID, /* no value */ + VNIL, + VTRUE, + VFALSE, + VK, /* info = index of constant in `k' */ + VKNUM, /* nval = numerical value */ + VLOCAL, /* info = local register */ + VUPVAL, /* info = index of upvalue in `upvalues' */ + VGLOBAL, /* info = index of table; aux = index of global name in `k' */ + VINDEXED, /* info = table register; aux = index register (or `k') */ + VJMP, /* info = instruction pc */ + VRELOCABLE, /* info = instruction pc */ + VNONRELOC, /* info = result register */ + VCALL, /* info = instruction pc */ + VVARARG /* info = instruction pc */ +} expkind; + +typedef struct expdesc { + expkind k; + union { + struct { int info, aux; } s; + lua_Number nval; + } u; + int t; /* patch list of `exit when true' */ + int f; /* patch list of `exit when false' */ +} expdesc; + + +typedef struct upvaldesc { + lu_byte k; + lu_byte info; +} upvaldesc; + + +struct BlockCnt; /* defined in lparser.c */ + + +/* state needed to generate code for a given function */ +typedef struct FuncState { + Proto *f; /* current function header */ + Table *h; /* table to find (and reuse) elements in `k' */ + struct FuncState *prev; /* enclosing function */ + struct LexState *ls; /* lexical state */ + struct lua_State *L; /* copy of the Lua state */ + struct BlockCnt *bl; /* chain of current blocks */ + int pc; /* next position to code (equivalent to `ncode') */ + int lasttarget; /* `pc' of last `jump target' */ + int jpc; /* list of pending jumps to `pc' */ + int freereg; /* first free register */ + int nk; /* number of elements in `k' */ + int np; /* number of elements in `p' */ + short nlocvars; /* number of elements in `locvars' */ + lu_byte nactvar; /* number of active local variables */ + upvaldesc upvalues[LUAI_MAXUPVALUES]; /* upvalues */ + unsigned short actvar[LUAI_MAXVARS]; /* declared-variable stack */ +} FuncState; + + +LUAI_FUNC Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, + const char *name); + + +#endif diff --git a/IOS/lua/lua/lstate.c b/IOS/lua/lua/lstate.c new file mode 100644 index 00000000..4313b83a --- /dev/null +++ b/IOS/lua/lua/lstate.c @@ -0,0 +1,214 @@ +/* +** $Id: lstate.c,v 2.36.1.2 2008/01/03 15:20:39 roberto Exp $ +** Global State +** See Copyright Notice in lua.h +*/ + + +#include + +#define lstate_c +#define LUA_CORE + +#include "lua.h" + +#include "ldebug.h" +#include "ldo.h" +#include "lfunc.h" +#include "lgc.h" +#include "llex.h" +#include "lmem.h" +#include "lstate.h" +#include "lstring.h" +#include "ltable.h" +#include "ltm.h" + + +#define state_size(x) (sizeof(x) + LUAI_EXTRASPACE) +#define fromstate(l) (cast(lu_byte *, (l)) - LUAI_EXTRASPACE) +#define tostate(l) (cast(lua_State *, cast(lu_byte *, l) + LUAI_EXTRASPACE)) + + +/* +** Main thread combines a thread state and the global state +*/ +typedef struct LG { + lua_State l; + global_State g; +} LG; + + + +static void stack_init (lua_State *L1, lua_State *L) { + /* initialize CallInfo array */ + L1->base_ci = luaM_newvector(L, BASIC_CI_SIZE, CallInfo); + L1->ci = L1->base_ci; + L1->size_ci = BASIC_CI_SIZE; + L1->end_ci = L1->base_ci + L1->size_ci - 1; + /* initialize stack array */ + L1->stack = luaM_newvector(L, BASIC_STACK_SIZE + EXTRA_STACK, TValue); + L1->stacksize = BASIC_STACK_SIZE + EXTRA_STACK; + L1->top = L1->stack; + L1->stack_last = L1->stack+(L1->stacksize - EXTRA_STACK)-1; + /* initialize first ci */ + L1->ci->func = L1->top; + setnilvalue(L1->top++); /* `function' entry for this `ci' */ + L1->base = L1->ci->base = L1->top; + L1->ci->top = L1->top + LUA_MINSTACK; +} + + +static void freestack (lua_State *L, lua_State *L1) { + luaM_freearray(L, L1->base_ci, L1->size_ci, CallInfo); + luaM_freearray(L, L1->stack, L1->stacksize, TValue); +} + + +/* +** open parts that may cause memory-allocation errors +*/ +static void f_luaopen (lua_State *L, void *ud) { + global_State *g = G(L); + UNUSED(ud); + stack_init(L, L); /* init stack */ + sethvalue(L, gt(L), luaH_new(L, 0, 2)); /* table of globals */ + sethvalue(L, registry(L), luaH_new(L, 0, 2)); /* registry */ + luaS_resize(L, MINSTRTABSIZE); /* initial size of string table */ + luaT_init(L); + luaX_init(L); + luaS_fix(luaS_newliteral(L, MEMERRMSG)); + g->GCthreshold = 4*g->totalbytes; +} + + +static void preinit_state (lua_State *L, global_State *g) { + G(L) = g; + L->stack = NULL; + L->stacksize = 0; + L->errorJmp = NULL; + L->hook = NULL; + L->hookmask = 0; + L->basehookcount = 0; + L->allowhook = 1; + resethookcount(L); + L->openupval = NULL; + L->size_ci = 0; + L->nCcalls = L->baseCcalls = 0; + L->status = 0; + L->base_ci = L->ci = NULL; + L->savedpc = NULL; + L->errfunc = 0; + setnilvalue(gt(L)); +} + + +static void close_state (lua_State *L) { + global_State *g = G(L); + luaF_close(L, L->stack); /* close all upvalues for this thread */ + luaC_freeall(L); /* collect all objects */ + lua_assert(g->rootgc == obj2gco(L)); + lua_assert(g->strt.nuse == 0); + luaM_freearray(L, G(L)->strt.hash, G(L)->strt.size, TString *); + luaZ_freebuffer(L, &g->buff); + freestack(L, L); + lua_assert(g->totalbytes == sizeof(LG)); + (*g->frealloc)(g->ud, fromstate(L), state_size(LG), 0); +} + + +lua_State *luaE_newthread (lua_State *L) { + lua_State *L1 = tostate(luaM_malloc(L, state_size(lua_State))); + luaC_link(L, obj2gco(L1), LUA_TTHREAD); + preinit_state(L1, G(L)); + stack_init(L1, L); /* init stack */ + setobj2n(L, gt(L1), gt(L)); /* share table of globals */ + L1->hookmask = L->hookmask; + L1->basehookcount = L->basehookcount; + L1->hook = L->hook; + resethookcount(L1); + lua_assert(iswhite(obj2gco(L1))); + return L1; +} + + +void luaE_freethread (lua_State *L, lua_State *L1) { + luaF_close(L1, L1->stack); /* close all upvalues for this thread */ + lua_assert(L1->openupval == NULL); + luai_userstatefree(L1); + freestack(L, L1); + luaM_freemem(L, fromstate(L1), state_size(lua_State)); +} + + +LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) { + int i; + lua_State *L; + global_State *g; + void *l = (*f)(ud, NULL, 0, state_size(LG)); + if (l == NULL) return NULL; + L = tostate(l); + g = &((LG *)L)->g; + L->next = NULL; + L->tt = LUA_TTHREAD; + g->currentwhite = bit2mask(WHITE0BIT, FIXEDBIT); + L->marked = luaC_white(g); + set2bits(L->marked, FIXEDBIT, SFIXEDBIT); + preinit_state(L, g); + g->frealloc = f; + g->ud = ud; + g->mainthread = L; + g->uvhead.u.l.prev = &g->uvhead; + g->uvhead.u.l.next = &g->uvhead; + g->GCthreshold = 0; /* mark it as unfinished state */ + g->strt.size = 0; + g->strt.nuse = 0; + g->strt.hash = NULL; + setnilvalue(registry(L)); + luaZ_initbuffer(L, &g->buff); + g->panic = NULL; + g->gcstate = GCSpause; + g->rootgc = obj2gco(L); + g->sweepstrgc = 0; + g->sweepgc = &g->rootgc; + g->gray = NULL; + g->grayagain = NULL; + g->weak = NULL; + g->tmudata = NULL; + g->totalbytes = sizeof(LG); + g->gcpause = LUAI_GCPAUSE; + g->gcstepmul = LUAI_GCMUL; + g->gcdept = 0; + for (i=0; imt[i] = NULL; + if (luaD_rawrunprotected(L, f_luaopen, NULL) != 0) { + /* memory allocation error: free partial state */ + close_state(L); + L = NULL; + } + else + luai_userstateopen(L); + return L; +} + + +static void callallgcTM (lua_State *L, void *ud) { + UNUSED(ud); + luaC_callGCTM(L); /* call GC metamethods for all udata */ +} + + +LUA_API void lua_close (lua_State *L) { + L = G(L)->mainthread; /* only the main thread can be closed */ + lua_lock(L); + luaF_close(L, L->stack); /* close all upvalues for this thread */ + luaC_separateudata(L, 1); /* separate udata that have GC metamethods */ + L->errfunc = 0; /* no error function during GC metamethods */ + do { /* repeat until no more errors */ + L->ci = L->base_ci; + L->base = L->top = L->ci->base; + L->nCcalls = L->baseCcalls = 0; + } while (luaD_rawrunprotected(L, callallgcTM, NULL) != 0); + lua_assert(G(L)->tmudata == NULL); + luai_userstateclose(L); + close_state(L); +} + diff --git a/IOS/lua/lua/lstate.h b/IOS/lua/lua/lstate.h new file mode 100644 index 00000000..3bc575b6 --- /dev/null +++ b/IOS/lua/lua/lstate.h @@ -0,0 +1,169 @@ +/* +** $Id: lstate.h,v 2.24.1.2 2008/01/03 15:20:39 roberto Exp $ +** Global State +** See Copyright Notice in lua.h +*/ + +#ifndef lstate_h +#define lstate_h + +#include "lua.h" + +#include "lobject.h" +#include "ltm.h" +#include "lzio.h" + + + +struct lua_longjmp; /* defined in ldo.c */ + + +/* table of globals */ +#define gt(L) (&L->l_gt) + +/* registry */ +#define registry(L) (&G(L)->l_registry) + + +/* extra stack space to handle TM calls and some other extras */ +#define EXTRA_STACK 5 + + +#define BASIC_CI_SIZE 8 + +#define BASIC_STACK_SIZE (2*LUA_MINSTACK) + + + +typedef struct stringtable { + GCObject **hash; + lu_int32 nuse; /* number of elements */ + int size; +} stringtable; + + +/* +** informations about a call +*/ +typedef struct CallInfo { + StkId base; /* base for this function */ + StkId func; /* function index in the stack */ + StkId top; /* top for this function */ + const Instruction *savedpc; + int nresults; /* expected number of results from this function */ + int tailcalls; /* number of tail calls lost under this entry */ +} CallInfo; + + + +#define curr_func(L) (clvalue(L->ci->func)) +#define ci_func(ci) (clvalue((ci)->func)) +#define f_isLua(ci) (!ci_func(ci)->c.isC) +#define isLua(ci) (ttisfunction((ci)->func) && f_isLua(ci)) + + +/* +** `global state', shared by all threads of this state +*/ +typedef struct global_State { + stringtable strt; /* hash table for strings */ + lua_Alloc frealloc; /* function to reallocate memory */ + void *ud; /* auxiliary data to `frealloc' */ + lu_byte currentwhite; + lu_byte gcstate; /* state of garbage collector */ + int sweepstrgc; /* position of sweep in `strt' */ + GCObject *rootgc; /* list of all collectable objects */ + GCObject **sweepgc; /* position of sweep in `rootgc' */ + GCObject *gray; /* list of gray objects */ + GCObject *grayagain; /* list of objects to be traversed atomically */ + GCObject *weak; /* list of weak tables (to be cleared) */ + GCObject *tmudata; /* last element of list of userdata to be GC */ + Mbuffer buff; /* temporary buffer for string concatentation */ + lu_mem GCthreshold; + lu_mem totalbytes; /* number of bytes currently allocated */ + lu_mem estimate; /* an estimate of number of bytes actually in use */ + lu_mem gcdept; /* how much GC is `behind schedule' */ + int gcpause; /* size of pause between successive GCs */ + int gcstepmul; /* GC `granularity' */ + lua_CFunction panic; /* to be called in unprotected errors */ + TValue l_registry; + struct lua_State *mainthread; + UpVal uvhead; /* head of double-linked list of all open upvalues */ + struct Table *mt[NUM_TAGS]; /* metatables for basic types */ + TString *tmname[TM_N]; /* array with tag-method names */ +} global_State; + + +/* +** `per thread' state +*/ +struct lua_State { + CommonHeader; + lu_byte status; + StkId top; /* first free slot in the stack */ + StkId base; /* base of current function */ + global_State *l_G; + CallInfo *ci; /* call info for current function */ + const Instruction *savedpc; /* `savedpc' of current function */ + StkId stack_last; /* last free slot in the stack */ + StkId stack; /* stack base */ + CallInfo *end_ci; /* points after end of ci array*/ + CallInfo *base_ci; /* array of CallInfo's */ + int stacksize; + int size_ci; /* size of array `base_ci' */ + unsigned short nCcalls; /* number of nested C calls */ + unsigned short baseCcalls; /* nested C calls when resuming coroutine */ + lu_byte hookmask; + lu_byte allowhook; + int basehookcount; + int hookcount; + lua_Hook hook; + TValue l_gt; /* table of globals */ + TValue env; /* temporary place for environments */ + GCObject *openupval; /* list of open upvalues in this stack */ + GCObject *gclist; + struct lua_longjmp *errorJmp; /* current error recover point */ + ptrdiff_t errfunc; /* current error handling function (stack index) */ +}; + + +#define G(L) (L->l_G) + + +/* +** Union of all collectable objects +*/ +union GCObject { + GCheader gch; + union TString ts; + union Udata u; + union Closure cl; + struct Table h; + struct Proto p; + struct UpVal uv; + struct lua_State th; /* thread */ +}; + + +/* macros to convert a GCObject into a specific value */ +#define rawgco2ts(o) check_exp((o)->gch.tt == LUA_TSTRING, &((o)->ts)) +#define gco2ts(o) (&rawgco2ts(o)->tsv) +#define rawgco2u(o) check_exp((o)->gch.tt == LUA_TUSERDATA, &((o)->u)) +#define gco2u(o) (&rawgco2u(o)->uv) +#define gco2cl(o) check_exp((o)->gch.tt == LUA_TFUNCTION, &((o)->cl)) +#define gco2h(o) check_exp((o)->gch.tt == LUA_TTABLE, &((o)->h)) +#define gco2p(o) check_exp((o)->gch.tt == LUA_TPROTO, &((o)->p)) +#define gco2uv(o) check_exp((o)->gch.tt == LUA_TUPVAL, &((o)->uv)) +#define ngcotouv(o) \ + check_exp((o) == NULL || (o)->gch.tt == LUA_TUPVAL, &((o)->uv)) +#define gco2th(o) check_exp((o)->gch.tt == LUA_TTHREAD, &((o)->th)) + +/* macro to convert any Lua object into a GCObject */ +#define obj2gco(v) (cast(GCObject *, (v))) + + +LUAI_FUNC lua_State *luaE_newthread (lua_State *L); +LUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1); + +#endif + diff --git a/IOS/lua/lua/lstring.c b/IOS/lua/lua/lstring.c new file mode 100644 index 00000000..49113151 --- /dev/null +++ b/IOS/lua/lua/lstring.c @@ -0,0 +1,111 @@ +/* +** $Id: lstring.c,v 2.8.1.1 2007/12/27 13:02:25 roberto Exp $ +** String table (keeps all strings handled by Lua) +** See Copyright Notice in lua.h +*/ + + +#include + +#define lstring_c +#define LUA_CORE + +#include "lua.h" + +#include "lmem.h" +#include "lobject.h" +#include "lstate.h" +#include "lstring.h" + + + +void luaS_resize (lua_State *L, int newsize) { + GCObject **newhash; + stringtable *tb; + int i; + if (G(L)->gcstate == GCSsweepstring) + return; /* cannot resize during GC traverse */ + newhash = luaM_newvector(L, newsize, GCObject *); + tb = &G(L)->strt; + for (i=0; isize; i++) { + GCObject *p = tb->hash[i]; + while (p) { /* for each node in the list */ + GCObject *next = p->gch.next; /* save next */ + unsigned int h = gco2ts(p)->hash; + int h1 = lmod(h, newsize); /* new position */ + lua_assert(cast_int(h%newsize) == lmod(h, newsize)); + p->gch.next = newhash[h1]; /* chain it */ + newhash[h1] = p; + p = next; + } + } + luaM_freearray(L, tb->hash, tb->size, TString *); + tb->size = newsize; + tb->hash = newhash; +} + + +static TString *newlstr (lua_State *L, const char *str, size_t l, + unsigned int h) { + TString *ts; + stringtable *tb; + if (l+1 > (MAX_SIZET - sizeof(TString))/sizeof(char)) + luaM_toobig(L); + ts = cast(TString *, luaM_malloc(L, (l+1)*sizeof(char)+sizeof(TString))); + ts->tsv.len = l; + ts->tsv.hash = h; + ts->tsv.marked = luaC_white(G(L)); + ts->tsv.tt = LUA_TSTRING; + ts->tsv.reserved = 0; + memcpy(ts+1, str, l*sizeof(char)); + ((char *)(ts+1))[l] = '\0'; /* ending 0 */ + tb = &G(L)->strt; + h = lmod(h, tb->size); + ts->tsv.next = tb->hash[h]; /* chain new entry */ + tb->hash[h] = obj2gco(ts); + tb->nuse++; + if (tb->nuse > cast(lu_int32, tb->size) && tb->size <= MAX_INT/2) + luaS_resize(L, tb->size*2); /* too crowded */ + return ts; +} + + +TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { + GCObject *o; + unsigned int h = cast(unsigned int, l); /* seed */ + size_t step = (l>>5)+1; /* if string is too long, don't hash all its chars */ + size_t l1; + for (l1=l; l1>=step; l1-=step) /* compute hash */ + h = h ^ ((h<<5)+(h>>2)+cast(unsigned char, str[l1-1])); + for (o = G(L)->strt.hash[lmod(h, G(L)->strt.size)]; + o != NULL; + o = o->gch.next) { + TString *ts = rawgco2ts(o); + if (ts->tsv.len == l && (memcmp(str, getstr(ts), l) == 0)) { + /* string may be dead */ + if (isdead(G(L), o)) changewhite(o); + return ts; + } + } + return newlstr(L, str, l, h); /* not found */ +} + + +Udata *luaS_newudata (lua_State *L, size_t s, Table *e) { + Udata *u; + if (s > MAX_SIZET - sizeof(Udata)) + luaM_toobig(L); + u = cast(Udata *, luaM_malloc(L, s + sizeof(Udata))); + u->uv.marked = luaC_white(G(L)); /* is not finalized */ + u->uv.tt = LUA_TUSERDATA; + u->uv.len = s; + u->uv.metatable = NULL; + u->uv.env = e; + /* chain it on udata list (after main thread) */ + u->uv.next = G(L)->mainthread->next; + G(L)->mainthread->next = obj2gco(u); + return u; +} + diff --git a/IOS/lua/lua/lstring.h b/IOS/lua/lua/lstring.h new file mode 100644 index 00000000..73a2ff8b --- /dev/null +++ b/IOS/lua/lua/lstring.h @@ -0,0 +1,31 @@ +/* +** $Id: lstring.h,v 1.43.1.1 2007/12/27 13:02:25 roberto Exp $ +** String table (keep all strings handled by Lua) +** See Copyright Notice in lua.h +*/ + +#ifndef lstring_h +#define lstring_h + + +#include "lgc.h" +#include "lobject.h" +#include "lstate.h" + + +#define sizestring(s) (sizeof(union TString)+((s)->len+1)*sizeof(char)) + +#define sizeudata(u) (sizeof(union Udata)+(u)->len) + +#define luaS_new(L, s) (luaS_newlstr(L, s, strlen(s))) +#define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \ + (sizeof(s)/sizeof(char))-1)) + +#define luaS_fix(s) l_setbit((s)->tsv.marked, FIXEDBIT) + +LUAI_FUNC void luaS_resize (lua_State *L, int newsize); +LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s, Table *e); +LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l); + + +#endif diff --git a/IOS/lua/lua/lstrlib.c b/IOS/lua/lua/lstrlib.c new file mode 100644 index 00000000..1b4763d4 --- /dev/null +++ b/IOS/lua/lua/lstrlib.c @@ -0,0 +1,869 @@ +/* +** $Id: lstrlib.c,v 1.132.1.4 2008/07/11 17:27:21 roberto Exp $ +** Standard library for string operations and pattern-matching +** See Copyright Notice in lua.h +*/ + + +#include +#include +#include +#include +#include + +#define lstrlib_c +#define LUA_LIB + +#include "lua.h" + +#include "lauxlib.h" +#include "lualib.h" + + +/* macro to `unsign' a character */ +#define uchar(c) ((unsigned char)(c)) + + + +static int str_len (lua_State *L) { + size_t l; + luaL_checklstring(L, 1, &l); + lua_pushinteger(L, l); + return 1; +} + + +static ptrdiff_t posrelat (ptrdiff_t pos, size_t len) { + /* relative string position: negative means back from end */ + if (pos < 0) pos += (ptrdiff_t)len + 1; + return (pos >= 0) ? pos : 0; +} + + +static int str_sub (lua_State *L) { + size_t l; + const char *s = luaL_checklstring(L, 1, &l); + ptrdiff_t start = posrelat(luaL_checkinteger(L, 2), l); + ptrdiff_t end = posrelat(luaL_optinteger(L, 3, -1), l); + if (start < 1) start = 1; + if (end > (ptrdiff_t)l) end = (ptrdiff_t)l; + if (start <= end) + lua_pushlstring(L, s+start-1, end-start+1); + else lua_pushliteral(L, ""); + return 1; +} + + +static int str_reverse (lua_State *L) { + size_t l; + luaL_Buffer b; + const char *s = luaL_checklstring(L, 1, &l); + luaL_buffinit(L, &b); + while (l--) luaL_addchar(&b, s[l]); + luaL_pushresult(&b); + return 1; +} + + +static int str_lower (lua_State *L) { + size_t l; + size_t i; + luaL_Buffer b; + const char *s = luaL_checklstring(L, 1, &l); + luaL_buffinit(L, &b); + for (i=0; i 0) + luaL_addlstring(&b, s, l); + luaL_pushresult(&b); + return 1; +} + + +static int str_byte (lua_State *L) { + size_t l; + const char *s = luaL_checklstring(L, 1, &l); + ptrdiff_t posi = posrelat(luaL_optinteger(L, 2, 1), l); + ptrdiff_t pose = posrelat(luaL_optinteger(L, 3, posi), l); + int n, i; + if (posi <= 0) posi = 1; + if ((size_t)pose > l) pose = l; + if (posi > pose) return 0; /* empty interval; return no values */ + n = (int)(pose - posi + 1); + if (posi + n <= pose) /* overflow? */ + luaL_error(L, "string slice too long"); + luaL_checkstack(L, n, "string slice too long"); + for (i=0; i= ms->level || ms->capture[l].len == CAP_UNFINISHED) + return luaL_error(ms->L, "invalid capture index"); + return l; +} + + +static int capture_to_close (MatchState *ms) { + int level = ms->level; + for (level--; level>=0; level--) + if (ms->capture[level].len == CAP_UNFINISHED) return level; + return luaL_error(ms->L, "invalid pattern capture"); +} + + +static const char *classend (MatchState *ms, const char *p) { + switch (*p++) { + case L_ESC: { + if (*p == '\0') + luaL_error(ms->L, "malformed pattern (ends with " LUA_QL("%%") ")"); + return p+1; + } + case '[': { + if (*p == '^') p++; + do { /* look for a `]' */ + if (*p == '\0') + luaL_error(ms->L, "malformed pattern (missing " LUA_QL("]") ")"); + if (*(p++) == L_ESC && *p != '\0') + p++; /* skip escapes (e.g. `%]') */ + } while (*p != ']'); + return p+1; + } + default: { + return p; + } + } +} + + +static int match_class (int c, int cl) { + int res; + switch (tolower(cl)) { + case 'a' : res = isalpha(c); break; + case 'c' : res = iscntrl(c); break; + case 'd' : res = isdigit(c); break; + case 'l' : res = islower(c); break; + case 'p' : res = ispunct(c); break; + case 's' : res = isspace(c); break; + case 'u' : res = isupper(c); break; + case 'w' : res = isalnum(c); break; + case 'x' : res = isxdigit(c); break; + case 'z' : res = (c == 0); break; + default: return (cl == c); + } + return (islower(cl) ? res : !res); +} + + +static int matchbracketclass (int c, const char *p, const char *ec) { + int sig = 1; + if (*(p+1) == '^') { + sig = 0; + p++; /* skip the `^' */ + } + while (++p < ec) { + if (*p == L_ESC) { + p++; + if (match_class(c, uchar(*p))) + return sig; + } + else if ((*(p+1) == '-') && (p+2 < ec)) { + p+=2; + if (uchar(*(p-2)) <= c && c <= uchar(*p)) + return sig; + } + else if (uchar(*p) == c) return sig; + } + return !sig; +} + + +static int singlematch (int c, const char *p, const char *ep) { + switch (*p) { + case '.': return 1; /* matches any char */ + case L_ESC: return match_class(c, uchar(*(p+1))); + case '[': return matchbracketclass(c, p, ep-1); + default: return (uchar(*p) == c); + } +} + + +static const char *match (MatchState *ms, const char *s, const char *p); + + +static const char *matchbalance (MatchState *ms, const char *s, + const char *p) { + if (*p == 0 || *(p+1) == 0) + luaL_error(ms->L, "unbalanced pattern"); + if (*s != *p) return NULL; + else { + int b = *p; + int e = *(p+1); + int cont = 1; + while (++s < ms->src_end) { + if (*s == e) { + if (--cont == 0) return s+1; + } + else if (*s == b) cont++; + } + } + return NULL; /* string ends out of balance */ +} + + +static const char *max_expand (MatchState *ms, const char *s, + const char *p, const char *ep) { + ptrdiff_t i = 0; /* counts maximum expand for item */ + while ((s+i)src_end && singlematch(uchar(*(s+i)), p, ep)) + i++; + /* keeps trying to match with the maximum repetitions */ + while (i>=0) { + const char *res = match(ms, (s+i), ep+1); + if (res) return res; + i--; /* else didn't match; reduce 1 repetition to try again */ + } + return NULL; +} + + +static const char *min_expand (MatchState *ms, const char *s, + const char *p, const char *ep) { + for (;;) { + const char *res = match(ms, s, ep+1); + if (res != NULL) + return res; + else if (ssrc_end && singlematch(uchar(*s), p, ep)) + s++; /* try with one more repetition */ + else return NULL; + } +} + + +static const char *start_capture (MatchState *ms, const char *s, + const char *p, int what) { + const char *res; + int level = ms->level; + if (level >= LUA_MAXCAPTURES) luaL_error(ms->L, "too many captures"); + ms->capture[level].init = s; + ms->capture[level].len = what; + ms->level = level+1; + if ((res=match(ms, s, p)) == NULL) /* match failed? */ + ms->level--; /* undo capture */ + return res; +} + + +static const char *end_capture (MatchState *ms, const char *s, + const char *p) { + int l = capture_to_close(ms); + const char *res; + ms->capture[l].len = s - ms->capture[l].init; /* close capture */ + if ((res = match(ms, s, p)) == NULL) /* match failed? */ + ms->capture[l].len = CAP_UNFINISHED; /* undo capture */ + return res; +} + + +static const char *match_capture (MatchState *ms, const char *s, int l) { + size_t len; + l = check_capture(ms, l); + len = ms->capture[l].len; + if ((size_t)(ms->src_end-s) >= len && + memcmp(ms->capture[l].init, s, len) == 0) + return s+len; + else return NULL; +} + + +static const char *match (MatchState *ms, const char *s, const char *p) { + init: /* using goto's to optimize tail recursion */ + switch (*p) { + case '(': { /* start capture */ + if (*(p+1) == ')') /* position capture? */ + return start_capture(ms, s, p+2, CAP_POSITION); + else + return start_capture(ms, s, p+1, CAP_UNFINISHED); + } + case ')': { /* end capture */ + return end_capture(ms, s, p+1); + } + case L_ESC: { + switch (*(p+1)) { + case 'b': { /* balanced string? */ + s = matchbalance(ms, s, p+2); + if (s == NULL) return NULL; + p+=4; goto init; /* else return match(ms, s, p+4); */ + } + case 'f': { /* frontier? */ + const char *ep; char previous; + p += 2; + if (*p != '[') + luaL_error(ms->L, "missing " LUA_QL("[") " after " + LUA_QL("%%f") " in pattern"); + ep = classend(ms, p); /* points to what is next */ + previous = (s == ms->src_init) ? '\0' : *(s-1); + if (matchbracketclass(uchar(previous), p, ep-1) || + !matchbracketclass(uchar(*s), p, ep-1)) return NULL; + p=ep; goto init; /* else return match(ms, s, ep); */ + } + default: { + if (isdigit(uchar(*(p+1)))) { /* capture results (%0-%9)? */ + s = match_capture(ms, s, uchar(*(p+1))); + if (s == NULL) return NULL; + p+=2; goto init; /* else return match(ms, s, p+2) */ + } + goto dflt; /* case default */ + } + } + } + case '\0': { /* end of pattern */ + return s; /* match succeeded */ + } + case '$': { + if (*(p+1) == '\0') /* is the `$' the last char in pattern? */ + return (s == ms->src_end) ? s : NULL; /* check end of string */ + else goto dflt; + } + default: dflt: { /* it is a pattern item */ + const char *ep = classend(ms, p); /* points to what is next */ + int m = ssrc_end && singlematch(uchar(*s), p, ep); + switch (*ep) { + case '?': { /* optional */ + const char *res; + if (m && ((res=match(ms, s+1, ep+1)) != NULL)) + return res; + p=ep+1; goto init; /* else return match(ms, s, ep+1); */ + } + case '*': { /* 0 or more repetitions */ + return max_expand(ms, s, p, ep); + } + case '+': { /* 1 or more repetitions */ + return (m ? max_expand(ms, s+1, p, ep) : NULL); + } + case '-': { /* 0 or more repetitions (minimum) */ + return min_expand(ms, s, p, ep); + } + default: { + if (!m) return NULL; + s++; p=ep; goto init; /* else return match(ms, s+1, ep); */ + } + } + } + } +} + + + +static const char *lmemfind (const char *s1, size_t l1, + const char *s2, size_t l2) { + if (l2 == 0) return s1; /* empty strings are everywhere */ + else if (l2 > l1) return NULL; /* avoids a negative `l1' */ + else { + const char *init; /* to search for a `*s2' inside `s1' */ + l2--; /* 1st char will be checked by `memchr' */ + l1 = l1-l2; /* `s2' cannot be found after that */ + while (l1 > 0 && (init = (const char *)memchr(s1, *s2, l1)) != NULL) { + init++; /* 1st char is already checked */ + if (memcmp(init, s2+1, l2) == 0) + return init-1; + else { /* correct `l1' and `s1' to try again */ + l1 -= init-s1; + s1 = init; + } + } + return NULL; /* not found */ + } +} + + +static void push_onecapture (MatchState *ms, int i, const char *s, + const char *e) { + if (i >= ms->level) { + if (i == 0) /* ms->level == 0, too */ + lua_pushlstring(ms->L, s, e - s); /* add whole match */ + else + luaL_error(ms->L, "invalid capture index"); + } + else { + ptrdiff_t l = ms->capture[i].len; + if (l == CAP_UNFINISHED) luaL_error(ms->L, "unfinished capture"); + if (l == CAP_POSITION) + lua_pushinteger(ms->L, ms->capture[i].init - ms->src_init + 1); + else + lua_pushlstring(ms->L, ms->capture[i].init, l); + } +} + + +static int push_captures (MatchState *ms, const char *s, const char *e) { + int i; + int nlevels = (ms->level == 0 && s) ? 1 : ms->level; + luaL_checkstack(ms->L, nlevels, "too many captures"); + for (i = 0; i < nlevels; i++) + push_onecapture(ms, i, s, e); + return nlevels; /* number of strings pushed */ +} + + +static int str_find_aux (lua_State *L, int find) { + size_t l1, l2; + const char *s = luaL_checklstring(L, 1, &l1); + const char *p = luaL_checklstring(L, 2, &l2); + ptrdiff_t init = posrelat(luaL_optinteger(L, 3, 1), l1) - 1; + if (init < 0) init = 0; + else if ((size_t)(init) > l1) init = (ptrdiff_t)l1; + if (find && (lua_toboolean(L, 4) || /* explicit request? */ + strpbrk(p, SPECIALS) == NULL)) { /* or no special characters? */ + /* do a plain search */ + const char *s2 = lmemfind(s+init, l1-init, p, l2); + if (s2) { + lua_pushinteger(L, s2-s+1); + lua_pushinteger(L, s2-s+l2); + return 2; + } + } + else { + MatchState ms; + int anchor = (*p == '^') ? (p++, 1) : 0; + const char *s1=s+init; + ms.L = L; + ms.src_init = s; + ms.src_end = s+l1; + do { + const char *res; + ms.level = 0; + if ((res=match(&ms, s1, p)) != NULL) { + if (find) { + lua_pushinteger(L, s1-s+1); /* start */ + lua_pushinteger(L, res-s); /* end */ + return push_captures(&ms, NULL, 0) + 2; + } + else + return push_captures(&ms, s1, res); + } + } while (s1++ < ms.src_end && !anchor); + } + lua_pushnil(L); /* not found */ + return 1; +} + + +static int str_find (lua_State *L) { + return str_find_aux(L, 1); +} + + +static int str_match (lua_State *L) { + return str_find_aux(L, 0); +} + + +static int gmatch_aux (lua_State *L) { + MatchState ms; + size_t ls; + const char *s = lua_tolstring(L, lua_upvalueindex(1), &ls); + const char *p = lua_tostring(L, lua_upvalueindex(2)); + const char *src; + ms.L = L; + ms.src_init = s; + ms.src_end = s+ls; + for (src = s + (size_t)lua_tointeger(L, lua_upvalueindex(3)); + src <= ms.src_end; + src++) { + const char *e; + ms.level = 0; + if ((e = match(&ms, src, p)) != NULL) { + lua_Integer newstart = e-s; + if (e == src) newstart++; /* empty match? go at least one position */ + lua_pushinteger(L, newstart); + lua_replace(L, lua_upvalueindex(3)); + return push_captures(&ms, src, e); + } + } + return 0; /* not found */ +} + + +static int gmatch (lua_State *L) { + luaL_checkstring(L, 1); + luaL_checkstring(L, 2); + lua_settop(L, 2); + lua_pushinteger(L, 0); + lua_pushcclosure(L, gmatch_aux, 3); + return 1; +} + + +static int gfind_nodef (lua_State *L) { + return luaL_error(L, LUA_QL("string.gfind") " was renamed to " + LUA_QL("string.gmatch")); +} + + +static void add_s (MatchState *ms, luaL_Buffer *b, const char *s, + const char *e) { + size_t l, i; + const char *news = lua_tolstring(ms->L, 3, &l); + for (i = 0; i < l; i++) { + if (news[i] != L_ESC) + luaL_addchar(b, news[i]); + else { + i++; /* skip ESC */ + if (!isdigit(uchar(news[i]))) + luaL_addchar(b, news[i]); + else if (news[i] == '0') + luaL_addlstring(b, s, e - s); + else { + push_onecapture(ms, news[i] - '1', s, e); + luaL_addvalue(b); /* add capture to accumulated result */ + } + } + } +} + + +static void add_value (MatchState *ms, luaL_Buffer *b, const char *s, + const char *e) { + lua_State *L = ms->L; + switch (lua_type(L, 3)) { + case LUA_TNUMBER: + case LUA_TSTRING: { + add_s(ms, b, s, e); + return; + } + case LUA_TFUNCTION: { + int n; + lua_pushvalue(L, 3); + n = push_captures(ms, s, e); + lua_call(L, n, 1); + break; + } + case LUA_TTABLE: { + push_onecapture(ms, 0, s, e); + lua_gettable(L, 3); + break; + } + } + if (!lua_toboolean(L, -1)) { /* nil or false? */ + lua_pop(L, 1); + lua_pushlstring(L, s, e - s); /* keep original text */ + } + else if (!lua_isstring(L, -1)) + luaL_error(L, "invalid replacement value (a %s)", luaL_typename(L, -1)); + luaL_addvalue(b); /* add result to accumulator */ +} + + +static int str_gsub (lua_State *L) { + size_t srcl; + const char *src = luaL_checklstring(L, 1, &srcl); + const char *p = luaL_checkstring(L, 2); + int tr = lua_type(L, 3); + int max_s = luaL_optint(L, 4, srcl+1); + int anchor = (*p == '^') ? (p++, 1) : 0; + int n = 0; + MatchState ms; + luaL_Buffer b; + luaL_argcheck(L, tr == LUA_TNUMBER || tr == LUA_TSTRING || + tr == LUA_TFUNCTION || tr == LUA_TTABLE, 3, + "string/function/table expected"); + luaL_buffinit(L, &b); + ms.L = L; + ms.src_init = src; + ms.src_end = src+srcl; + while (n < max_s) { + const char *e; + ms.level = 0; + e = match(&ms, src, p); + if (e) { + n++; + add_value(&ms, &b, src, e); + } + if (e && e>src) /* non empty match? */ + src = e; /* skip it */ + else if (src < ms.src_end) + luaL_addchar(&b, *src++); + else break; + if (anchor) break; + } + luaL_addlstring(&b, src, ms.src_end-src); + luaL_pushresult(&b); + lua_pushinteger(L, n); /* number of substitutions */ + return 2; +} + +/* }====================================================== */ + + +/* maximum size of each formatted item (> len(format('%99.99f', -1e308))) */ +#define MAX_ITEM 512 +/* valid flags in a format specification */ +#define FLAGS "-+ #0" +/* +** maximum size of each format specification (such as '%-099.99d') +** (+10 accounts for %99.99x plus margin of error) +*/ +#define MAX_FORMAT (sizeof(FLAGS) + sizeof(LUA_INTFRMLEN) + 10) + + +static void addquoted (lua_State *L, luaL_Buffer *b, int arg) { + size_t l; + const char *s = luaL_checklstring(L, arg, &l); + luaL_addchar(b, '"'); + while (l--) { + switch (*s) { + case '"': case '\\': case '\n': { + luaL_addchar(b, '\\'); + luaL_addchar(b, *s); + break; + } + case '\r': { + luaL_addlstring(b, "\\r", 2); + break; + } + case '\0': { + luaL_addlstring(b, "\\000", 4); + break; + } + default: { + luaL_addchar(b, *s); + break; + } + } + s++; + } + luaL_addchar(b, '"'); +} + +static const char *scanformat (lua_State *L, const char *strfrmt, char *form) { + const char *p = strfrmt; + while (*p != '\0' && strchr(FLAGS, *p) != NULL) p++; /* skip flags */ + if ((size_t)(p - strfrmt) >= sizeof(FLAGS)) + luaL_error(L, "invalid format (repeated flags)"); + if (isdigit(uchar(*p))) p++; /* skip width */ + if (isdigit(uchar(*p))) p++; /* (2 digits at most) */ + if (*p == '.') { + p++; + if (isdigit(uchar(*p))) p++; /* skip precision */ + if (isdigit(uchar(*p))) p++; /* (2 digits at most) */ + } + if (isdigit(uchar(*p))) + luaL_error(L, "invalid format (width or precision too long)"); + *(form++) = '%'; + strncpy(form, strfrmt, p - strfrmt + 1); + form += p - strfrmt + 1; + *form = '\0'; + return p; +} + + +static void addintlen (char *form) { + size_t l = strlen(form); + char spec = form[l - 1]; + strcpy(form + l - 1, LUA_INTFRMLEN); + form[l + sizeof(LUA_INTFRMLEN) - 2] = spec; + form[l + sizeof(LUA_INTFRMLEN) - 1] = '\0'; +} + + +static int str_format (lua_State *L) { + int arg = 1; + size_t sfl; + const char *strfrmt = luaL_checklstring(L, arg, &sfl); + const char *strfrmt_end = strfrmt+sfl; + luaL_Buffer b; + luaL_buffinit(L, &b); + while (strfrmt < strfrmt_end) { + if (*strfrmt != L_ESC) + luaL_addchar(&b, *strfrmt++); + else if (*++strfrmt == L_ESC) + luaL_addchar(&b, *strfrmt++); /* %% */ + else { /* format item */ + char form[MAX_FORMAT]; /* to store the format (`%...') */ + char buff[MAX_ITEM]; /* to store the formatted item */ + arg++; + strfrmt = scanformat(L, strfrmt, form); + switch (*strfrmt++) { + case 'c': { + sprintf(buff, form, (int)luaL_checknumber(L, arg)); + break; + } + case 'd': case 'i': { + addintlen(form); + sprintf(buff, form, (LUA_INTFRM_T)luaL_checknumber(L, arg)); + break; + } + case 'o': case 'u': case 'x': case 'X': { + addintlen(form); + sprintf(buff, form, (unsigned LUA_INTFRM_T)luaL_checknumber(L, arg)); + break; + } + case 'e': case 'E': case 'f': + case 'g': case 'G': { + sprintf(buff, form, (double)luaL_checknumber(L, arg)); + break; + } + case 'q': { + addquoted(L, &b, arg); + continue; /* skip the 'addsize' at the end */ + } + case 's': { + size_t l; + const char *s = luaL_checklstring(L, arg, &l); + if (!strchr(form, '.') && l >= 100) { + /* no precision and string is too long to be formatted; + keep original string */ + lua_pushvalue(L, arg); + luaL_addvalue(&b); + continue; /* skip the `addsize' at the end */ + } + else { + sprintf(buff, form, s); + break; + } + } + default: { /* also treat cases `pnLlh' */ + return luaL_error(L, "invalid option " LUA_QL("%%%c") " to " + LUA_QL("format"), *(strfrmt - 1)); + } + } + luaL_addlstring(&b, buff, strlen(buff)); + } + } + luaL_pushresult(&b); + return 1; +} + + +static const luaL_Reg strlib[] = { + {"byte", str_byte}, + {"char", str_char}, + {"dump", str_dump}, + {"find", str_find}, + {"format", str_format}, + {"gfind", gfind_nodef}, + {"gmatch", gmatch}, + {"gsub", str_gsub}, + {"len", str_len}, + {"lower", str_lower}, + {"match", str_match}, + {"rep", str_rep}, + {"reverse", str_reverse}, + {"sub", str_sub}, + {"upper", str_upper}, + {NULL, NULL} +}; + + +static void createmetatable (lua_State *L) { + lua_createtable(L, 0, 1); /* create metatable for strings */ + lua_pushliteral(L, ""); /* dummy string */ + lua_pushvalue(L, -2); + lua_setmetatable(L, -2); /* set string metatable */ + lua_pop(L, 1); /* pop dummy string */ + lua_pushvalue(L, -2); /* string library... */ + lua_setfield(L, -2, "__index"); /* ...is the __index metamethod */ + lua_pop(L, 1); /* pop metatable */ +} + + +/* +** Open string library +*/ +LUALIB_API int luaopen_string (lua_State *L) { + luaL_register(L, LUA_STRLIBNAME, strlib); +#if defined(LUA_COMPAT_GFIND) + lua_getfield(L, -1, "gmatch"); + lua_setfield(L, -2, "gfind"); +#endif + createmetatable(L); + return 1; +} + diff --git a/IOS/lua/lua/ltable.c b/IOS/lua/lua/ltable.c new file mode 100644 index 00000000..ec84f4fa --- /dev/null +++ b/IOS/lua/lua/ltable.c @@ -0,0 +1,588 @@ +/* +** $Id: ltable.c,v 2.32.1.2 2007/12/28 15:32:23 roberto Exp $ +** Lua tables (hash) +** See Copyright Notice in lua.h +*/ + + +/* +** Implementation of tables (aka arrays, objects, or hash tables). +** Tables keep its elements in two parts: an array part and a hash part. +** Non-negative integer keys are all candidates to be kept in the array +** part. The actual size of the array is the largest `n' such that at +** least half the slots between 0 and n are in use. +** Hash uses a mix of chained scatter table with Brent's variation. +** A main invariant of these tables is that, if an element is not +** in its main position (i.e. the `original' position that its hash gives +** to it), then the colliding element is in its own main position. +** Hence even when the load factor reaches 100%, performance remains good. +*/ + +#include +#include + +#define ltable_c +#define LUA_CORE + +#include "lua.h" + +#include "ldebug.h" +#include "ldo.h" +#include "lgc.h" +#include "lmem.h" +#include "lobject.h" +#include "lstate.h" +#include "ltable.h" + + +/* +** max size of array part is 2^MAXBITS +*/ +#if LUAI_BITSINT > 26 +#define MAXBITS 26 +#else +#define MAXBITS (LUAI_BITSINT-2) +#endif + +#define MAXASIZE (1 << MAXBITS) + + +#define hashpow2(t,n) (gnode(t, lmod((n), sizenode(t)))) + +#define hashstr(t,str) hashpow2(t, (str)->tsv.hash) +#define hashboolean(t,p) hashpow2(t, p) + + +/* +** for some types, it is better to avoid modulus by power of 2, as +** they tend to have many 2 factors. +*/ +#define hashmod(t,n) (gnode(t, ((n) % ((sizenode(t)-1)|1)))) + + +#define hashpointer(t,p) hashmod(t, IntPoint(p)) + + +/* +** number of ints inside a lua_Number +*/ +#define numints cast_int(sizeof(lua_Number)/sizeof(int)) + + + +#define dummynode (&dummynode_) + +static const Node dummynode_ = { + {{NULL}, LUA_TNIL}, /* value */ + {{{NULL}, LUA_TNIL, NULL}} /* key */ +}; + + +/* +** hash for lua_Numbers +*/ +static Node *hashnum (const Table *t, lua_Number n) { + unsigned int a[numints]; + int i; + if (luai_numeq(n, 0)) /* avoid problems with -0 */ + return gnode(t, 0); + memcpy(a, &n, sizeof(a)); + for (i = 1; i < numints; i++) a[0] += a[i]; + return hashmod(t, a[0]); +} + + + +/* +** returns the `main' position of an element in a table (that is, the index +** of its hash value) +*/ +static Node *mainposition (const Table *t, const TValue *key) { + switch (ttype(key)) { + case LUA_TNUMBER: + return hashnum(t, nvalue(key)); + case LUA_TSTRING: + return hashstr(t, rawtsvalue(key)); + case LUA_TBOOLEAN: + return hashboolean(t, bvalue(key)); + case LUA_TLIGHTUSERDATA: + return hashpointer(t, pvalue(key)); + default: + return hashpointer(t, gcvalue(key)); + } +} + + +/* +** returns the index for `key' if `key' is an appropriate key to live in +** the array part of the table, -1 otherwise. +*/ +static int arrayindex (const TValue *key) { + if (ttisnumber(key)) { + lua_Number n = nvalue(key); + int k; + lua_number2int(k, n); + if (luai_numeq(cast_num(k), n)) + return k; + } + return -1; /* `key' did not match some condition */ +} + + +/* +** returns the index of a `key' for table traversals. First goes all +** elements in the array part, then elements in the hash part. The +** beginning of a traversal is signalled by -1. +*/ +static int findindex (lua_State *L, Table *t, StkId key) { + int i; + if (ttisnil(key)) return -1; /* first iteration */ + i = arrayindex(key); + if (0 < i && i <= t->sizearray) /* is `key' inside array part? */ + return i-1; /* yes; that's the index (corrected to C) */ + else { + Node *n = mainposition(t, key); + do { /* check whether `key' is somewhere in the chain */ + /* key may be dead already, but it is ok to use it in `next' */ + if (luaO_rawequalObj(key2tval(n), key) || + (ttype(gkey(n)) == LUA_TDEADKEY && iscollectable(key) && + gcvalue(gkey(n)) == gcvalue(key))) { + i = cast_int(n - gnode(t, 0)); /* key index in hash table */ + /* hash elements are numbered after array ones */ + return i + t->sizearray; + } + else n = gnext(n); + } while (n); + luaG_runerror(L, "invalid key to " LUA_QL("next")); /* key not found */ + return 0; /* to avoid warnings */ + } +} + + +int luaH_next (lua_State *L, Table *t, StkId key) { + int i = findindex(L, t, key); /* find original element */ + for (i++; i < t->sizearray; i++) { /* try first array part */ + if (!ttisnil(&t->array[i])) { /* a non-nil value? */ + setnvalue(key, cast_num(i+1)); + setobj2s(L, key+1, &t->array[i]); + return 1; + } + } + for (i -= t->sizearray; i < sizenode(t); i++) { /* then hash part */ + if (!ttisnil(gval(gnode(t, i)))) { /* a non-nil value? */ + setobj2s(L, key, key2tval(gnode(t, i))); + setobj2s(L, key+1, gval(gnode(t, i))); + return 1; + } + } + return 0; /* no more elements */ +} + + +/* +** {============================================================= +** Rehash +** ============================================================== +*/ + + +static int computesizes (int nums[], int *narray) { + int i; + int twotoi; /* 2^i */ + int a = 0; /* number of elements smaller than 2^i */ + int na = 0; /* number of elements to go to array part */ + int n = 0; /* optimal size for array part */ + for (i = 0, twotoi = 1; twotoi/2 < *narray; i++, twotoi *= 2) { + if (nums[i] > 0) { + a += nums[i]; + if (a > twotoi/2) { /* more than half elements present? */ + n = twotoi; /* optimal size (till now) */ + na = a; /* all elements smaller than n will go to array part */ + } + } + if (a == *narray) break; /* all elements already counted */ + } + *narray = n; + lua_assert(*narray/2 <= na && na <= *narray); + return na; +} + + +static int countint (const TValue *key, int *nums) { + int k = arrayindex(key); + if (0 < k && k <= MAXASIZE) { /* is `key' an appropriate array index? */ + nums[ceillog2(k)]++; /* count as such */ + return 1; + } + else + return 0; +} + + +static int numusearray (const Table *t, int *nums) { + int lg; + int ttlg; /* 2^lg */ + int ause = 0; /* summation of `nums' */ + int i = 1; /* count to traverse all array keys */ + for (lg=0, ttlg=1; lg<=MAXBITS; lg++, ttlg*=2) { /* for each slice */ + int lc = 0; /* counter */ + int lim = ttlg; + if (lim > t->sizearray) { + lim = t->sizearray; /* adjust upper limit */ + if (i > lim) + break; /* no more elements to count */ + } + /* count elements in range (2^(lg-1), 2^lg] */ + for (; i <= lim; i++) { + if (!ttisnil(&t->array[i-1])) + lc++; + } + nums[lg] += lc; + ause += lc; + } + return ause; +} + + +static int numusehash (const Table *t, int *nums, int *pnasize) { + int totaluse = 0; /* total number of elements */ + int ause = 0; /* summation of `nums' */ + int i = sizenode(t); + while (i--) { + Node *n = &t->node[i]; + if (!ttisnil(gval(n))) { + ause += countint(key2tval(n), nums); + totaluse++; + } + } + *pnasize += ause; + return totaluse; +} + + +static void setarrayvector (lua_State *L, Table *t, int size) { + int i; + luaM_reallocvector(L, t->array, t->sizearray, size, TValue); + for (i=t->sizearray; iarray[i]); + t->sizearray = size; +} + + +static void setnodevector (lua_State *L, Table *t, int size) { + int lsize; + if (size == 0) { /* no elements to hash part? */ + t->node = cast(Node *, dummynode); /* use common `dummynode' */ + lsize = 0; + } + else { + int i; + lsize = ceillog2(size); + if (lsize > MAXBITS) + luaG_runerror(L, "table overflow"); + size = twoto(lsize); + t->node = luaM_newvector(L, size, Node); + for (i=0; ilsizenode = cast_byte(lsize); + t->lastfree = gnode(t, size); /* all positions are free */ +} + + +static void resize (lua_State *L, Table *t, int nasize, int nhsize) { + int i; + int oldasize = t->sizearray; + int oldhsize = t->lsizenode; + Node *nold = t->node; /* save old hash ... */ + if (nasize > oldasize) /* array part must grow? */ + setarrayvector(L, t, nasize); + /* create new hash part with appropriate size */ + setnodevector(L, t, nhsize); + if (nasize < oldasize) { /* array part must shrink? */ + t->sizearray = nasize; + /* re-insert elements from vanishing slice */ + for (i=nasize; iarray[i])) + setobjt2t(L, luaH_setnum(L, t, i+1), &t->array[i]); + } + /* shrink array */ + luaM_reallocvector(L, t->array, oldasize, nasize, TValue); + } + /* re-insert elements from hash part */ + for (i = twoto(oldhsize) - 1; i >= 0; i--) { + Node *old = nold+i; + if (!ttisnil(gval(old))) + setobjt2t(L, luaH_set(L, t, key2tval(old)), gval(old)); + } + if (nold != dummynode) + luaM_freearray(L, nold, twoto(oldhsize), Node); /* free old array */ +} + + +void luaH_resizearray (lua_State *L, Table *t, int nasize) { + int nsize = (t->node == dummynode) ? 0 : sizenode(t); + resize(L, t, nasize, nsize); +} + + +static void rehash (lua_State *L, Table *t, const TValue *ek) { + int nasize, na; + int nums[MAXBITS+1]; /* nums[i] = number of keys between 2^(i-1) and 2^i */ + int i; + int totaluse; + for (i=0; i<=MAXBITS; i++) nums[i] = 0; /* reset counts */ + nasize = numusearray(t, nums); /* count keys in array part */ + totaluse = nasize; /* all those keys are integer keys */ + totaluse += numusehash(t, nums, &nasize); /* count keys in hash part */ + /* count extra key */ + nasize += countint(ek, nums); + totaluse++; + /* compute new size for array part */ + na = computesizes(nums, &nasize); + /* resize the table to new computed sizes */ + resize(L, t, nasize, totaluse - na); +} + + + +/* +** }============================================================= +*/ + + +Table *luaH_new (lua_State *L, int narray, int nhash) { + Table *t = luaM_new(L, Table); + luaC_link(L, obj2gco(t), LUA_TTABLE); + t->metatable = NULL; + t->flags = cast_byte(~0); + /* temporary values (kept only if some malloc fails) */ + t->array = NULL; + t->sizearray = 0; + t->lsizenode = 0; + t->node = cast(Node *, dummynode); + setarrayvector(L, t, narray); + setnodevector(L, t, nhash); + return t; +} + + +void luaH_free (lua_State *L, Table *t) { + if (t->node != dummynode) + luaM_freearray(L, t->node, sizenode(t), Node); + luaM_freearray(L, t->array, t->sizearray, TValue); + luaM_free(L, t); +} + + +static Node *getfreepos (Table *t) { + while (t->lastfree-- > t->node) { + if (ttisnil(gkey(t->lastfree))) + return t->lastfree; + } + return NULL; /* could not find a free place */ +} + + + +/* +** inserts a new key into a hash table; first, check whether key's main +** position is free. If not, check whether colliding node is in its main +** position or not: if it is not, move colliding node to an empty place and +** put new key in its main position; otherwise (colliding node is in its main +** position), new key goes to an empty position. +*/ +static TValue *newkey (lua_State *L, Table *t, const TValue *key) { + Node *mp = mainposition(t, key); + if (!ttisnil(gval(mp)) || mp == dummynode) { + Node *othern; + Node *n = getfreepos(t); /* get a free place */ + if (n == NULL) { /* cannot find a free place? */ + rehash(L, t, key); /* grow table */ + return luaH_set(L, t, key); /* re-insert key into grown table */ + } + lua_assert(n != dummynode); + othern = mainposition(t, key2tval(mp)); + if (othern != mp) { /* is colliding node out of its main position? */ + /* yes; move colliding node into free position */ + while (gnext(othern) != mp) othern = gnext(othern); /* find previous */ + gnext(othern) = n; /* redo the chain with `n' in place of `mp' */ + *n = *mp; /* copy colliding node into free pos. (mp->next also goes) */ + gnext(mp) = NULL; /* now `mp' is free */ + setnilvalue(gval(mp)); + } + else { /* colliding node is in its own main position */ + /* new node will go into free position */ + gnext(n) = gnext(mp); /* chain new position */ + gnext(mp) = n; + mp = n; + } + } + gkey(mp)->value = key->value; gkey(mp)->tt = key->tt; + luaC_barriert(L, t, key); + lua_assert(ttisnil(gval(mp))); + return gval(mp); +} + + +/* +** search function for integers +*/ +const TValue *luaH_getnum (Table *t, int key) { + /* (1 <= key && key <= t->sizearray) */ + if (cast(unsigned int, key-1) < cast(unsigned int, t->sizearray)) + return &t->array[key-1]; + else { + lua_Number nk = cast_num(key); + Node *n = hashnum(t, nk); + do { /* check whether `key' is somewhere in the chain */ + if (ttisnumber(gkey(n)) && luai_numeq(nvalue(gkey(n)), nk)) + return gval(n); /* that's it */ + else n = gnext(n); + } while (n); + return luaO_nilobject; + } +} + + +/* +** search function for strings +*/ +const TValue *luaH_getstr (Table *t, TString *key) { + Node *n = hashstr(t, key); + do { /* check whether `key' is somewhere in the chain */ + if (ttisstring(gkey(n)) && rawtsvalue(gkey(n)) == key) + return gval(n); /* that's it */ + else n = gnext(n); + } while (n); + return luaO_nilobject; +} + + +/* +** main search function +*/ +const TValue *luaH_get (Table *t, const TValue *key) { + switch (ttype(key)) { + case LUA_TNIL: return luaO_nilobject; + case LUA_TSTRING: return luaH_getstr(t, rawtsvalue(key)); + case LUA_TNUMBER: { + int k; + lua_Number n = nvalue(key); + lua_number2int(k, n); + if (luai_numeq(cast_num(k), nvalue(key))) /* index is int? */ + return luaH_getnum(t, k); /* use specialized version */ + /* else go through */ + } + default: { + Node *n = mainposition(t, key); + do { /* check whether `key' is somewhere in the chain */ + if (luaO_rawequalObj(key2tval(n), key)) + return gval(n); /* that's it */ + else n = gnext(n); + } while (n); + return luaO_nilobject; + } + } +} + + +TValue *luaH_set (lua_State *L, Table *t, const TValue *key) { + const TValue *p = luaH_get(t, key); + t->flags = 0; + if (p != luaO_nilobject) + return cast(TValue *, p); + else { + if (ttisnil(key)) luaG_runerror(L, "table index is nil"); + else if (ttisnumber(key) && luai_numisnan(nvalue(key))) + luaG_runerror(L, "table index is NaN"); + return newkey(L, t, key); + } +} + + +TValue *luaH_setnum (lua_State *L, Table *t, int key) { + const TValue *p = luaH_getnum(t, key); + if (p != luaO_nilobject) + return cast(TValue *, p); + else { + TValue k; + setnvalue(&k, cast_num(key)); + return newkey(L, t, &k); + } +} + + +TValue *luaH_setstr (lua_State *L, Table *t, TString *key) { + const TValue *p = luaH_getstr(t, key); + if (p != luaO_nilobject) + return cast(TValue *, p); + else { + TValue k; + setsvalue(L, &k, key); + return newkey(L, t, &k); + } +} + + +static int unbound_search (Table *t, unsigned int j) { + unsigned int i = j; /* i is zero or a present index */ + j++; + /* find `i' and `j' such that i is present and j is not */ + while (!ttisnil(luaH_getnum(t, j))) { + i = j; + j *= 2; + if (j > cast(unsigned int, MAX_INT)) { /* overflow? */ + /* table was built with bad purposes: resort to linear search */ + i = 1; + while (!ttisnil(luaH_getnum(t, i))) i++; + return i - 1; + } + } + /* now do a binary search between them */ + while (j - i > 1) { + unsigned int m = (i+j)/2; + if (ttisnil(luaH_getnum(t, m))) j = m; + else i = m; + } + return i; +} + + +/* +** Try to find a boundary in table `t'. A `boundary' is an integer index +** such that t[i] is non-nil and t[i+1] is nil (and 0 if t[1] is nil). +*/ +int luaH_getn (Table *t) { + unsigned int j = t->sizearray; + if (j > 0 && ttisnil(&t->array[j - 1])) { + /* there is a boundary in the array part: (binary) search for it */ + unsigned int i = 0; + while (j - i > 1) { + unsigned int m = (i+j)/2; + if (ttisnil(&t->array[m - 1])) j = m; + else i = m; + } + return i; + } + /* else must find a boundary in hash part */ + else if (t->node == dummynode) /* hash part is empty? */ + return j; /* that is easy... */ + else return unbound_search(t, j); +} + + + +#if defined(LUA_DEBUG) + +Node *luaH_mainposition (const Table *t, const TValue *key) { + return mainposition(t, key); +} + +int luaH_isdummy (Node *n) { return n == dummynode; } + +#endif diff --git a/IOS/lua/lua/ltable.h b/IOS/lua/lua/ltable.h new file mode 100644 index 00000000..f5b9d5ea --- /dev/null +++ b/IOS/lua/lua/ltable.h @@ -0,0 +1,40 @@ +/* +** $Id: ltable.h,v 2.10.1.1 2007/12/27 13:02:25 roberto Exp $ +** Lua tables (hash) +** See Copyright Notice in lua.h +*/ + +#ifndef ltable_h +#define ltable_h + +#include "lobject.h" + + +#define gnode(t,i) (&(t)->node[i]) +#define gkey(n) (&(n)->i_key.nk) +#define gval(n) (&(n)->i_val) +#define gnext(n) ((n)->i_key.nk.next) + +#define key2tval(n) (&(n)->i_key.tvk) + + +LUAI_FUNC const TValue *luaH_getnum (Table *t, int key); +LUAI_FUNC TValue *luaH_setnum (lua_State *L, Table *t, int key); +LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key); +LUAI_FUNC TValue *luaH_setstr (lua_State *L, Table *t, TString *key); +LUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key); +LUAI_FUNC TValue *luaH_set (lua_State *L, Table *t, const TValue *key); +LUAI_FUNC Table *luaH_new (lua_State *L, int narray, int lnhash); +LUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, int nasize); +LUAI_FUNC void luaH_free (lua_State *L, Table *t); +LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key); +LUAI_FUNC int luaH_getn (Table *t); + + +#if defined(LUA_DEBUG) +LUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key); +LUAI_FUNC int luaH_isdummy (Node *n); +#endif + + +#endif diff --git a/IOS/lua/lua/ltablib.c b/IOS/lua/lua/ltablib.c new file mode 100644 index 00000000..b6d9cb4a --- /dev/null +++ b/IOS/lua/lua/ltablib.c @@ -0,0 +1,287 @@ +/* +** $Id: ltablib.c,v 1.38.1.3 2008/02/14 16:46:58 roberto Exp $ +** Library for Table Manipulation +** See Copyright Notice in lua.h +*/ + + +#include + +#define ltablib_c +#define LUA_LIB + +#include "lua.h" + +#include "lauxlib.h" +#include "lualib.h" + + +#define aux_getn(L,n) (luaL_checktype(L, n, LUA_TTABLE), luaL_getn(L, n)) + + +static int foreachi (lua_State *L) { + int i; + int n = aux_getn(L, 1); + luaL_checktype(L, 2, LUA_TFUNCTION); + for (i=1; i <= n; i++) { + lua_pushvalue(L, 2); /* function */ + lua_pushinteger(L, i); /* 1st argument */ + lua_rawgeti(L, 1, i); /* 2nd argument */ + lua_call(L, 2, 1); + if (!lua_isnil(L, -1)) + return 1; + lua_pop(L, 1); /* remove nil result */ + } + return 0; +} + + +static int foreach (lua_State *L) { + luaL_checktype(L, 1, LUA_TTABLE); + luaL_checktype(L, 2, LUA_TFUNCTION); + lua_pushnil(L); /* first key */ + while (lua_next(L, 1)) { + lua_pushvalue(L, 2); /* function */ + lua_pushvalue(L, -3); /* key */ + lua_pushvalue(L, -3); /* value */ + lua_call(L, 2, 1); + if (!lua_isnil(L, -1)) + return 1; + lua_pop(L, 2); /* remove value and result */ + } + return 0; +} + + +static int maxn (lua_State *L) { + lua_Number max = 0; + luaL_checktype(L, 1, LUA_TTABLE); + lua_pushnil(L); /* first key */ + while (lua_next(L, 1)) { + lua_pop(L, 1); /* remove value */ + if (lua_type(L, -1) == LUA_TNUMBER) { + lua_Number v = lua_tonumber(L, -1); + if (v > max) max = v; + } + } + lua_pushnumber(L, max); + return 1; +} + + +static int getn (lua_State *L) { + lua_pushinteger(L, aux_getn(L, 1)); + return 1; +} + + +static int setn (lua_State *L) { + luaL_checktype(L, 1, LUA_TTABLE); +#ifndef luaL_setn + luaL_setn(L, 1, luaL_checkint(L, 2)); +#else + luaL_error(L, LUA_QL("setn") " is obsolete"); +#endif + lua_pushvalue(L, 1); + return 1; +} + + +static int tinsert (lua_State *L) { + int e = aux_getn(L, 1) + 1; /* first empty element */ + int pos; /* where to insert new element */ + switch (lua_gettop(L)) { + case 2: { /* called with only 2 arguments */ + pos = e; /* insert new element at the end */ + break; + } + case 3: { + int i; + pos = luaL_checkint(L, 2); /* 2nd argument is the position */ + if (pos > e) e = pos; /* `grow' array if necessary */ + for (i = e; i > pos; i--) { /* move up elements */ + lua_rawgeti(L, 1, i-1); + lua_rawseti(L, 1, i); /* t[i] = t[i-1] */ + } + break; + } + default: { + return luaL_error(L, "wrong number of arguments to " LUA_QL("insert")); + } + } + luaL_setn(L, 1, e); /* new size */ + lua_rawseti(L, 1, pos); /* t[pos] = v */ + return 0; +} + + +static int tremove (lua_State *L) { + int e = aux_getn(L, 1); + int pos = luaL_optint(L, 2, e); + if (!(1 <= pos && pos <= e)) /* position is outside bounds? */ + return 0; /* nothing to remove */ + luaL_setn(L, 1, e - 1); /* t.n = n-1 */ + lua_rawgeti(L, 1, pos); /* result = t[pos] */ + for ( ;pos= P */ + while (lua_rawgeti(L, 1, ++i), sort_comp(L, -1, -2)) { + if (i>u) luaL_error(L, "invalid order function for sorting"); + lua_pop(L, 1); /* remove a[i] */ + } + /* repeat --j until a[j] <= P */ + while (lua_rawgeti(L, 1, --j), sort_comp(L, -3, -1)) { + if (j + +#define ltm_c +#define LUA_CORE + +#include "lua.h" + +#include "lobject.h" +#include "lstate.h" +#include "lstring.h" +#include "ltable.h" +#include "ltm.h" + + + +const char *const luaT_typenames[] = { + "nil", "boolean", "userdata", "number", + "string", "table", "function", "userdata", "thread", + "proto", "upval" +}; + + +void luaT_init (lua_State *L) { + static const char *const luaT_eventname[] = { /* ORDER TM */ + "__index", "__newindex", + "__gc", "__mode", "__eq", + "__add", "__sub", "__mul", "__div", "__mod", + "__pow", "__unm", "__len", "__lt", "__le", + "__concat", "__call" + }; + int i; + for (i=0; itmname[i] = luaS_new(L, luaT_eventname[i]); + luaS_fix(G(L)->tmname[i]); /* never collect these names */ + } +} + + +/* +** function to be used with macro "fasttm": optimized for absence of +** tag methods +*/ +const TValue *luaT_gettm (Table *events, TMS event, TString *ename) { + const TValue *tm = luaH_getstr(events, ename); + lua_assert(event <= TM_EQ); + if (ttisnil(tm)) { /* no tag method? */ + events->flags |= cast_byte(1u<metatable; + break; + case LUA_TUSERDATA: + mt = uvalue(o)->metatable; + break; + default: + mt = G(L)->mt[ttype(o)]; + } + return (mt ? luaH_getstr(mt, G(L)->tmname[event]) : luaO_nilobject); +} + diff --git a/IOS/lua/lua/ltm.h b/IOS/lua/lua/ltm.h new file mode 100644 index 00000000..64343b78 --- /dev/null +++ b/IOS/lua/lua/ltm.h @@ -0,0 +1,54 @@ +/* +** $Id: ltm.h,v 2.6.1.1 2007/12/27 13:02:25 roberto Exp $ +** Tag methods +** See Copyright Notice in lua.h +*/ + +#ifndef ltm_h +#define ltm_h + + +#include "lobject.h" + + +/* +* WARNING: if you change the order of this enumeration, +* grep "ORDER TM" +*/ +typedef enum { + TM_INDEX, + TM_NEWINDEX, + TM_GC, + TM_MODE, + TM_EQ, /* last tag method with `fast' access */ + TM_ADD, + TM_SUB, + TM_MUL, + TM_DIV, + TM_MOD, + TM_POW, + TM_UNM, + TM_LEN, + TM_LT, + TM_LE, + TM_CONCAT, + TM_CALL, + TM_N /* number of elements in the enum */ +} TMS; + + + +#define gfasttm(g,et,e) ((et) == NULL ? NULL : \ + ((et)->flags & (1u<<(e))) ? NULL : luaT_gettm(et, e, (g)->tmname[e])) + +#define fasttm(l,et,e) gfasttm(G(l), et, e) + +LUAI_DATA const char *const luaT_typenames[]; + + +LUAI_FUNC const TValue *luaT_gettm (Table *events, TMS event, TString *ename); +LUAI_FUNC const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, + TMS event); +LUAI_FUNC void luaT_init (lua_State *L); + +#endif diff --git a/IOS/lua/lua/lua.c b/IOS/lua/lua/lua.c new file mode 100644 index 00000000..6d4b4423 --- /dev/null +++ b/IOS/lua/lua/lua.c @@ -0,0 +1,392 @@ +/* +** $Id: lua.c,v 1.160.1.2 2007/12/28 15:32:23 roberto Exp $ +** Lua stand-alone interpreter +** See Copyright Notice in lua.h +*/ + + +#include +#include +#include +#include + +#define lua_c + +#include "lua.h" + +#include "lauxlib.h" +#include "lualib.h" + + + +static lua_State *globalL = NULL; + +static const char *progname = LUA_PROGNAME; + + + +static void lstop (lua_State *L, lua_Debug *ar) { + (void)ar; /* unused arg. */ + lua_sethook(L, NULL, 0, 0); + luaL_error(L, "interrupted!"); +} + + +static void laction (int i) { + signal(i, SIG_DFL); /* if another SIGINT happens before lstop, + terminate process (default action) */ + lua_sethook(globalL, lstop, LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 1); +} + + +static void print_usage (void) { + fprintf(stderr, + "usage: %s [options] [script [args]].\n" + "Available options are:\n" + " -e stat execute string " LUA_QL("stat") "\n" + " -l name require library " LUA_QL("name") "\n" + " -i enter interactive mode after executing " LUA_QL("script") "\n" + " -v show version information\n" + " -- stop handling options\n" + " - execute stdin and stop handling options\n" + , + progname); + fflush(stderr); +} + + +static void l_message (const char *pname, const char *msg) { + if (pname) fprintf(stderr, "%s: ", pname); + fprintf(stderr, "%s\n", msg); + fflush(stderr); +} + + +static int report (lua_State *L, int status) { + if (status && !lua_isnil(L, -1)) { + const char *msg = lua_tostring(L, -1); + if (msg == NULL) msg = "(error object is not a string)"; + l_message(progname, msg); + lua_pop(L, 1); + } + return status; +} + + +static int traceback (lua_State *L) { + if (!lua_isstring(L, 1)) /* 'message' not a string? */ + return 1; /* keep it intact */ + lua_getfield(L, LUA_GLOBALSINDEX, "debug"); + if (!lua_istable(L, -1)) { + lua_pop(L, 1); + return 1; + } + lua_getfield(L, -1, "traceback"); + if (!lua_isfunction(L, -1)) { + lua_pop(L, 2); + return 1; + } + lua_pushvalue(L, 1); /* pass error message */ + lua_pushinteger(L, 2); /* skip this function and traceback */ + lua_call(L, 2, 1); /* call debug.traceback */ + return 1; +} + + +static int docall (lua_State *L, int narg, int clear) { + int status; + int base = lua_gettop(L) - narg; /* function index */ + lua_pushcfunction(L, traceback); /* push traceback function */ + lua_insert(L, base); /* put it under chunk and args */ + signal(SIGINT, laction); + status = lua_pcall(L, narg, (clear ? 0 : LUA_MULTRET), base); + signal(SIGINT, SIG_DFL); + lua_remove(L, base); /* remove traceback function */ + /* force a complete garbage collection in case of errors */ + if (status != 0) lua_gc(L, LUA_GCCOLLECT, 0); + return status; +} + + +static void print_version (void) { + l_message(NULL, LUA_RELEASE " " LUA_COPYRIGHT); +} + + +static int getargs (lua_State *L, char **argv, int n) { + int narg; + int i; + int argc = 0; + while (argv[argc]) argc++; /* count total number of arguments */ + narg = argc - (n + 1); /* number of arguments to the script */ + luaL_checkstack(L, narg + 3, "too many arguments to script"); + for (i=n+1; i < argc; i++) + lua_pushstring(L, argv[i]); + lua_createtable(L, narg, n + 1); + for (i=0; i < argc; i++) { + lua_pushstring(L, argv[i]); + lua_rawseti(L, -2, i - n); + } + return narg; +} + + +static int dofile (lua_State *L, const char *name) { + int status = luaL_loadfile(L, name) || docall(L, 0, 1); + return report(L, status); +} + + +static int dostring (lua_State *L, const char *s, const char *name) { + int status = luaL_loadbuffer(L, s, strlen(s), name) || docall(L, 0, 1); + return report(L, status); +} + + +static int dolibrary (lua_State *L, const char *name) { + lua_getglobal(L, "require"); + lua_pushstring(L, name); + return report(L, docall(L, 1, 1)); +} + + +static const char *get_prompt (lua_State *L, int firstline) { + const char *p; + lua_getfield(L, LUA_GLOBALSINDEX, firstline ? "_PROMPT" : "_PROMPT2"); + p = lua_tostring(L, -1); + if (p == NULL) p = (firstline ? LUA_PROMPT : LUA_PROMPT2); + lua_pop(L, 1); /* remove global */ + return p; +} + + +static int incomplete (lua_State *L, int status) { + if (status == LUA_ERRSYNTAX) { + size_t lmsg; + const char *msg = lua_tolstring(L, -1, &lmsg); + const char *tp = msg + lmsg - (sizeof(LUA_QL("")) - 1); + if (strstr(msg, LUA_QL("")) == tp) { + lua_pop(L, 1); + return 1; + } + } + return 0; /* else... */ +} + + +static int pushline (lua_State *L, int firstline) { + char buffer[LUA_MAXINPUT]; + char *b = buffer; + size_t l; + const char *prmt = get_prompt(L, firstline); + if (lua_readline(L, b, prmt) == 0) + return 0; /* no input */ + l = strlen(b); + if (l > 0 && b[l-1] == '\n') /* line ends with newline? */ + b[l-1] = '\0'; /* remove it */ + if (firstline && b[0] == '=') /* first line starts with `=' ? */ + lua_pushfstring(L, "return %s", b+1); /* change it to `return' */ + else + lua_pushstring(L, b); + lua_freeline(L, b); + return 1; +} + + +static int loadline (lua_State *L) { + int status; + lua_settop(L, 0); + if (!pushline(L, 1)) + return -1; /* no input */ + for (;;) { /* repeat until gets a complete line */ + status = luaL_loadbuffer(L, lua_tostring(L, 1), lua_strlen(L, 1), "=stdin"); + if (!incomplete(L, status)) break; /* cannot try to add lines? */ + if (!pushline(L, 0)) /* no more input? */ + return -1; + lua_pushliteral(L, "\n"); /* add a new line... */ + lua_insert(L, -2); /* ...between the two lines */ + lua_concat(L, 3); /* join them */ + } + lua_saveline(L, 1); + lua_remove(L, 1); /* remove line */ + return status; +} + + +static void dotty (lua_State *L) { + int status; + const char *oldprogname = progname; + progname = NULL; + while ((status = loadline(L)) != -1) { + if (status == 0) status = docall(L, 0, 0); + report(L, status); + if (status == 0 && lua_gettop(L) > 0) { /* any result to print? */ + lua_getglobal(L, "print"); + lua_insert(L, 1); + if (lua_pcall(L, lua_gettop(L)-1, 0, 0) != 0) + l_message(progname, lua_pushfstring(L, + "error calling " LUA_QL("print") " (%s)", + lua_tostring(L, -1))); + } + } + lua_settop(L, 0); /* clear stack */ + fputs("\n", stdout); + fflush(stdout); + progname = oldprogname; +} + + +static int handle_script (lua_State *L, char **argv, int n) { + int status; + const char *fname; + int narg = getargs(L, argv, n); /* collect arguments */ + lua_setglobal(L, "arg"); + fname = argv[n]; + if (strcmp(fname, "-") == 0 && strcmp(argv[n-1], "--") != 0) + fname = NULL; /* stdin */ + status = luaL_loadfile(L, fname); + lua_insert(L, -(narg+1)); + if (status == 0) + status = docall(L, narg, 0); + else + lua_pop(L, narg); + return report(L, status); +} + + +/* check that argument has no extra characters at the end */ +#define notail(x) {if ((x)[2] != '\0') return -1;} + + +static int collectargs (char **argv, int *pi, int *pv, int *pe) { + int i; + for (i = 1; argv[i] != NULL; i++) { + if (argv[i][0] != '-') /* not an option? */ + return i; + switch (argv[i][1]) { /* option */ + case '-': + notail(argv[i]); + return (argv[i+1] != NULL ? i+1 : 0); + case '\0': + return i; + case 'i': + notail(argv[i]); + *pi = 1; /* go through */ + case 'v': + notail(argv[i]); + *pv = 1; + break; + case 'e': + *pe = 1; /* go through */ + case 'l': + if (argv[i][2] == '\0') { + i++; + if (argv[i] == NULL) return -1; + } + break; + default: return -1; /* invalid option */ + } + } + return 0; +} + + +static int runargs (lua_State *L, char **argv, int n) { + int i; + for (i = 1; i < n; i++) { + if (argv[i] == NULL) continue; + lua_assert(argv[i][0] == '-'); + switch (argv[i][1]) { /* option */ + case 'e': { + const char *chunk = argv[i] + 2; + if (*chunk == '\0') chunk = argv[++i]; + lua_assert(chunk != NULL); + if (dostring(L, chunk, "=(command line)") != 0) + return 1; + break; + } + case 'l': { + const char *filename = argv[i] + 2; + if (*filename == '\0') filename = argv[++i]; + lua_assert(filename != NULL); + if (dolibrary(L, filename)) + return 1; /* stop if file fails */ + break; + } + default: break; + } + } + return 0; +} + + +static int handle_luainit (lua_State *L) { + const char *init = getenv(LUA_INIT); + if (init == NULL) return 0; /* status OK */ + else if (init[0] == '@') + return dofile(L, init+1); + else + return dostring(L, init, "=" LUA_INIT); +} + + +struct Smain { + int argc; + char **argv; + int status; +}; + + +static int pmain (lua_State *L) { + struct Smain *s = (struct Smain *)lua_touserdata(L, 1); + char **argv = s->argv; + int script; + int has_i = 0, has_v = 0, has_e = 0; + globalL = L; + if (argv[0] && argv[0][0]) progname = argv[0]; + lua_gc(L, LUA_GCSTOP, 0); /* stop collector during initialization */ + luaL_openlibs(L); /* open libraries */ + lua_gc(L, LUA_GCRESTART, 0); + s->status = handle_luainit(L); + if (s->status != 0) return 0; + script = collectargs(argv, &has_i, &has_v, &has_e); + if (script < 0) { /* invalid args? */ + print_usage(); + s->status = 1; + return 0; + } + if (has_v) print_version(); + s->status = runargs(L, argv, (script > 0) ? script : s->argc); + if (s->status != 0) return 0; + if (script) + s->status = handle_script(L, argv, script); + if (s->status != 0) return 0; + if (has_i) + dotty(L); + else if (script == 0 && !has_e && !has_v) { + if (lua_stdin_is_tty()) { + print_version(); + dotty(L); + } + else dofile(L, NULL); /* executes stdin as a file */ + } + return 0; +} + + +//int main (int argc, char **argv) { +// int status; +// struct Smain s; +// lua_State *L = lua_open(); /* create state */ +// if (L == NULL) { +// l_message(argv[0], "cannot create state: not enough memory"); +// return EXIT_FAILURE; +// } +// s.argc = argc; +// s.argv = argv; +// status = lua_cpcall(L, &pmain, &s); +// report(L, status); +// lua_close(L); +// return (status || s.status) ? EXIT_FAILURE : EXIT_SUCCESS; +//} + diff --git a/IOS/lua/lua/lua.h b/IOS/lua/lua/lua.h new file mode 100644 index 00000000..e4bdfd3b --- /dev/null +++ b/IOS/lua/lua/lua.h @@ -0,0 +1,388 @@ +/* +** $Id: lua.h,v 1.218.1.5 2008/08/06 13:30:12 roberto Exp $ +** Lua - An Extensible Extension Language +** Lua.org, PUC-Rio, Brazil (http://www.lua.org) +** See Copyright Notice at the end of this file +*/ + + +#ifndef lua_h +#define lua_h + +#include +#include + + +#include "luaconf.h" + + +#define LUA_VERSION "Lua 5.1" +#define LUA_RELEASE "Lua 5.1.4" +#define LUA_VERSION_NUM 501 +#define LUA_COPYRIGHT "Copyright (C) 1994-2008 Lua.org, PUC-Rio" +#define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo & W. Celes" + + +/* mark for precompiled code (`Lua') */ +#define LUA_SIGNATURE "\033Lua" + +/* option for multiple returns in `lua_pcall' and `lua_call' */ +#define LUA_MULTRET (-1) + + +/* +** pseudo-indices +*/ +#define LUA_REGISTRYINDEX (-10000) +#define LUA_ENVIRONINDEX (-10001) +#define LUA_GLOBALSINDEX (-10002) +#define lua_upvalueindex(i) (LUA_GLOBALSINDEX-(i)) + + +/* thread status; 0 is OK */ +#define LUA_YIELD 1 +#define LUA_ERRRUN 2 +#define LUA_ERRSYNTAX 3 +#define LUA_ERRMEM 4 +#define LUA_ERRERR 5 + + +typedef struct lua_State lua_State; + +typedef int (*lua_CFunction) (lua_State *L); + + +/* +** functions that read/write blocks when loading/dumping Lua chunks +*/ +typedef const char * (*lua_Reader) (lua_State *L, void *ud, size_t *sz); + +typedef int (*lua_Writer) (lua_State *L, const void* p, size_t sz, void* ud); + + +/* +** prototype for memory-allocation functions +*/ +typedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize); + + +/* +** basic types +*/ +#define LUA_TNONE (-1) + +#define LUA_TNIL 0 +#define LUA_TBOOLEAN 1 +#define LUA_TLIGHTUSERDATA 2 +#define LUA_TNUMBER 3 +#define LUA_TSTRING 4 +#define LUA_TTABLE 5 +#define LUA_TFUNCTION 6 +#define LUA_TUSERDATA 7 +#define LUA_TTHREAD 8 + + + +/* minimum Lua stack available to a C function */ +#define LUA_MINSTACK 20 + + +/* +** generic extra include file +*/ +#if defined(LUA_USER_H) +#include LUA_USER_H +#endif + + +/* type of numbers in Lua */ +typedef LUA_NUMBER lua_Number; + + +/* type for integer functions */ +typedef LUA_INTEGER lua_Integer; + + + +/* +** state manipulation +*/ +LUA_API lua_State *(lua_newstate) (lua_Alloc f, void *ud); +LUA_API void (lua_close) (lua_State *L); +LUA_API lua_State *(lua_newthread) (lua_State *L); + +LUA_API lua_CFunction (lua_atpanic) (lua_State *L, lua_CFunction panicf); + + +/* +** basic stack manipulation +*/ +LUA_API int (lua_gettop) (lua_State *L); +LUA_API void (lua_settop) (lua_State *L, int idx); +LUA_API void (lua_pushvalue) (lua_State *L, int idx); +LUA_API void (lua_remove) (lua_State *L, int idx); +LUA_API void (lua_insert) (lua_State *L, int idx); +LUA_API void (lua_replace) (lua_State *L, int idx); +LUA_API int (lua_checkstack) (lua_State *L, int sz); + +LUA_API void (lua_xmove) (lua_State *from, lua_State *to, int n); + + +/* +** access functions (stack -> C) +*/ + +LUA_API int (lua_isnumber) (lua_State *L, int idx); +LUA_API int (lua_isstring) (lua_State *L, int idx); +LUA_API int (lua_iscfunction) (lua_State *L, int idx); +LUA_API int (lua_isuserdata) (lua_State *L, int idx); +LUA_API int (lua_type) (lua_State *L, int idx); +LUA_API const char *(lua_typename) (lua_State *L, int tp); + +LUA_API int (lua_equal) (lua_State *L, int idx1, int idx2); +LUA_API int (lua_rawequal) (lua_State *L, int idx1, int idx2); +LUA_API int (lua_lessthan) (lua_State *L, int idx1, int idx2); + +LUA_API lua_Number (lua_tonumber) (lua_State *L, int idx); +LUA_API lua_Integer (lua_tointeger) (lua_State *L, int idx); +LUA_API int (lua_toboolean) (lua_State *L, int idx); +LUA_API const char *(lua_tolstring) (lua_State *L, int idx, size_t *len); +LUA_API size_t (lua_objlen) (lua_State *L, int idx); +LUA_API lua_CFunction (lua_tocfunction) (lua_State *L, int idx); +LUA_API void *(lua_touserdata) (lua_State *L, int idx); +LUA_API lua_State *(lua_tothread) (lua_State *L, int idx); +LUA_API const void *(lua_topointer) (lua_State *L, int idx); + + +/* +** push functions (C -> stack) +*/ +LUA_API void (lua_pushnil) (lua_State *L); +LUA_API void (lua_pushnumber) (lua_State *L, lua_Number n); +LUA_API void (lua_pushinteger) (lua_State *L, lua_Integer n); +LUA_API void (lua_pushlstring) (lua_State *L, const char *s, size_t l); +LUA_API void (lua_pushstring) (lua_State *L, const char *s); +LUA_API const char *(lua_pushvfstring) (lua_State *L, const char *fmt, + va_list argp); +LUA_API const char *(lua_pushfstring) (lua_State *L, const char *fmt, ...); +LUA_API void (lua_pushcclosure) (lua_State *L, lua_CFunction fn, int n); +LUA_API void (lua_pushboolean) (lua_State *L, int b); +LUA_API void (lua_pushlightuserdata) (lua_State *L, void *p); +LUA_API int (lua_pushthread) (lua_State *L); + + +/* +** get functions (Lua -> stack) +*/ +LUA_API void (lua_gettable) (lua_State *L, int idx); +LUA_API void (lua_getfield) (lua_State *L, int idx, const char *k); +LUA_API void (lua_rawget) (lua_State *L, int idx); +LUA_API void (lua_rawgeti) (lua_State *L, int idx, int n); +LUA_API void (lua_createtable) (lua_State *L, int narr, int nrec); +LUA_API void *(lua_newuserdata) (lua_State *L, size_t sz); +LUA_API int (lua_getmetatable) (lua_State *L, int objindex); +LUA_API void (lua_getfenv) (lua_State *L, int idx); + + +/* +** set functions (stack -> Lua) +*/ +LUA_API void (lua_settable) (lua_State *L, int idx); +LUA_API void (lua_setfield) (lua_State *L, int idx, const char *k); +LUA_API void (lua_rawset) (lua_State *L, int idx); +LUA_API void (lua_rawseti) (lua_State *L, int idx, int n); +LUA_API int (lua_setmetatable) (lua_State *L, int objindex); +LUA_API int (lua_setfenv) (lua_State *L, int idx); + + +/* +** `load' and `call' functions (load and run Lua code) +*/ +LUA_API void (lua_call) (lua_State *L, int nargs, int nresults); +LUA_API int (lua_pcall) (lua_State *L, int nargs, int nresults, int errfunc); +LUA_API int (lua_cpcall) (lua_State *L, lua_CFunction func, void *ud); +LUA_API int (lua_load) (lua_State *L, lua_Reader reader, void *dt, + const char *chunkname); + +LUA_API int (lua_dump) (lua_State *L, lua_Writer writer, void *data); + + +/* +** coroutine functions +*/ +LUA_API int (lua_yield) (lua_State *L, int nresults); +LUA_API int (lua_resume) (lua_State *L, int narg); +LUA_API int (lua_status) (lua_State *L); + +/* +** garbage-collection function and options +*/ + +#define LUA_GCSTOP 0 +#define LUA_GCRESTART 1 +#define LUA_GCCOLLECT 2 +#define LUA_GCCOUNT 3 +#define LUA_GCCOUNTB 4 +#define LUA_GCSTEP 5 +#define LUA_GCSETPAUSE 6 +#define LUA_GCSETSTEPMUL 7 + +LUA_API int (lua_gc) (lua_State *L, int what, int data); + + +/* +** miscellaneous functions +*/ + +LUA_API int (lua_error) (lua_State *L); + +LUA_API int (lua_next) (lua_State *L, int idx); + +LUA_API void (lua_concat) (lua_State *L, int n); + +LUA_API lua_Alloc (lua_getallocf) (lua_State *L, void **ud); +LUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud); + + + +/* +** =============================================================== +** some useful macros +** =============================================================== +*/ + +#define lua_pop(L,n) lua_settop(L, -(n)-1) + +#define lua_newtable(L) lua_createtable(L, 0, 0) + +#define lua_register(L,n,f) (lua_pushcfunction(L, (f)), lua_setglobal(L, (n))) + +#define lua_pushcfunction(L,f) lua_pushcclosure(L, (f), 0) + +#define lua_strlen(L,i) lua_objlen(L, (i)) + +#define lua_isfunction(L,n) (lua_type(L, (n)) == LUA_TFUNCTION) +#define lua_istable(L,n) (lua_type(L, (n)) == LUA_TTABLE) +#define lua_islightuserdata(L,n) (lua_type(L, (n)) == LUA_TLIGHTUSERDATA) +#define lua_isnil(L,n) (lua_type(L, (n)) == LUA_TNIL) +#define lua_isboolean(L,n) (lua_type(L, (n)) == LUA_TBOOLEAN) +#define lua_isthread(L,n) (lua_type(L, (n)) == LUA_TTHREAD) +#define lua_isnone(L,n) (lua_type(L, (n)) == LUA_TNONE) +#define lua_isnoneornil(L, n) (lua_type(L, (n)) <= 0) + +#define lua_pushliteral(L, s) \ + lua_pushlstring(L, "" s, (sizeof(s)/sizeof(char))-1) + +#define lua_setglobal(L,s) lua_setfield(L, LUA_GLOBALSINDEX, (s)) +#define lua_getglobal(L,s) lua_getfield(L, LUA_GLOBALSINDEX, (s)) + +#define lua_tostring(L,i) lua_tolstring(L, (i), NULL) + + + +/* +** compatibility macros and functions +*/ + +#define lua_open() luaL_newstate() + +#define lua_getregistry(L) lua_pushvalue(L, LUA_REGISTRYINDEX) + +#define lua_getgccount(L) lua_gc(L, LUA_GCCOUNT, 0) + +#define lua_Chunkreader lua_Reader +#define lua_Chunkwriter lua_Writer + + +/* hack */ +LUA_API void lua_setlevel (lua_State *from, lua_State *to); + + +/* +** {====================================================================== +** Debug API +** ======================================================================= +*/ + + +/* +** Event codes +*/ +#define LUA_HOOKCALL 0 +#define LUA_HOOKRET 1 +#define LUA_HOOKLINE 2 +#define LUA_HOOKCOUNT 3 +#define LUA_HOOKTAILRET 4 + + +/* +** Event masks +*/ +#define LUA_MASKCALL (1 << LUA_HOOKCALL) +#define LUA_MASKRET (1 << LUA_HOOKRET) +#define LUA_MASKLINE (1 << LUA_HOOKLINE) +#define LUA_MASKCOUNT (1 << LUA_HOOKCOUNT) + +typedef struct lua_Debug lua_Debug; /* activation record */ + + +/* Functions to be called by the debuger in specific events */ +typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar); + + +LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar); +LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar); +LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n); +LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n); +LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n); +LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n); + +LUA_API int lua_sethook (lua_State *L, lua_Hook func, int mask, int count); +LUA_API lua_Hook lua_gethook (lua_State *L); +LUA_API int lua_gethookmask (lua_State *L); +LUA_API int lua_gethookcount (lua_State *L); + + +struct lua_Debug { + int event; + const char *name; /* (n) */ + const char *namewhat; /* (n) `global', `local', `field', `method' */ + const char *what; /* (S) `Lua', `C', `main', `tail' */ + const char *source; /* (S) */ + int currentline; /* (l) */ + int nups; /* (u) number of upvalues */ + int linedefined; /* (S) */ + int lastlinedefined; /* (S) */ + char short_src[LUA_IDSIZE]; /* (S) */ + /* private part */ + int i_ci; /* active function */ +}; + +/* }====================================================================== */ + + +/****************************************************************************** +* Copyright (C) 1994-2008 Lua.org, PUC-Rio. All rights reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining +* a copy of this software and associated documentation files (the +* "Software"), to deal in the Software without restriction, including +* without limitation the rights to use, copy, modify, merge, publish, +* distribute, sublicense, and/or sell copies of the Software, and to +* permit persons to whom the Software is furnished to do so, subject to +* the following conditions: +* +* The above copyright notice and this permission notice shall be +* included in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +******************************************************************************/ + + +#endif diff --git a/IOS/lua/lua/luac.c b/IOS/lua/lua/luac.c new file mode 100644 index 00000000..cbe3a596 --- /dev/null +++ b/IOS/lua/lua/luac.c @@ -0,0 +1,200 @@ +/* +** $Id: luac.c,v 1.54 2006/06/02 17:37:11 lhf Exp $ +** Lua compiler (saves bytecodes to files; also list bytecodes) +** See Copyright Notice in lua.h +*/ + +#include +#include +#include +#include + +#define luac_c +#define LUA_CORE + +#include "lua.h" +#include "lauxlib.h" + +#include "ldo.h" +#include "lfunc.h" +#include "lmem.h" +#include "lobject.h" +#include "lopcodes.h" +#include "lstring.h" +#include "lundump.h" + +#define PROGNAME "luac" /* default program name */ +#define OUTPUT PROGNAME ".out" /* default output file */ + +static int listing=0; /* list bytecodes? */ +static int dumping=1; /* dump bytecodes? */ +static int stripping=0; /* strip debug information? */ +static char Output[]={ OUTPUT }; /* default output file name */ +static const char* output=Output; /* actual output file name */ +static const char* progname=PROGNAME; /* actual program name */ + +static void fatal(const char* message) +{ + fprintf(stderr,"%s: %s\n",progname,message); + exit(EXIT_FAILURE); +} + +static void cannot(const char* what) +{ + fprintf(stderr,"%s: cannot %s %s: %s\n",progname,what,output,strerror(errno)); + exit(EXIT_FAILURE); +} + +static void usage(const char* message) +{ + if (*message=='-') + fprintf(stderr,"%s: unrecognized option " LUA_QS "\n",progname,message); + else + fprintf(stderr,"%s: %s\n",progname,message); + fprintf(stderr, + "usage: %s [options] [filenames].\n" + "Available options are:\n" + " - process stdin\n" + " -l list\n" + " -o name output to file " LUA_QL("name") " (default is \"%s\")\n" + " -p parse only\n" + " -s strip debug information\n" + " -v show version information\n" + " -- stop handling options\n", + progname,Output); + exit(EXIT_FAILURE); +} + +#define IS(s) (strcmp(argv[i],s)==0) + +static int doargs(int argc, char* argv[]) +{ + int i; + int version=0; + if (argv[0]!=NULL && *argv[0]!=0) progname=argv[0]; + for (i=1; itop+(i))->l.p) + +static const Proto* combine(lua_State* L, int n) +{ + if (n==1) + return toproto(L,-1); + else + { + int i,pc; + Proto* f=luaF_newproto(L); + setptvalue2s(L,L->top,f); incr_top(L); + f->source=luaS_newliteral(L,"=(" PROGNAME ")"); + f->maxstacksize=1; + pc=2*n+1; + f->code=luaM_newvector(L,pc,Instruction); + f->sizecode=pc; + f->p=luaM_newvector(L,n,Proto*); + f->sizep=n; + pc=0; + for (i=0; ip[i]=toproto(L,i-n-1); + f->code[pc++]=CREATE_ABx(OP_CLOSURE,0,i); + f->code[pc++]=CREATE_ABC(OP_CALL,0,1,1); + } + f->code[pc++]=CREATE_ABC(OP_RETURN,0,1,0); + return f; + } +} + +static int writer(lua_State* L, const void* p, size_t size, void* u) +{ + UNUSED(L); + return (fwrite(p,size,1,(FILE*)u)!=1) && (size!=0); +} + +struct Smain { + int argc; + char** argv; +}; + +static int pmain(lua_State* L) +{ + struct Smain* s = (struct Smain*)lua_touserdata(L, 1); + int argc=s->argc; + char** argv=s->argv; + const Proto* f; + int i; + if (!lua_checkstack(L,argc)) fatal("too many input files"); + for (i=0; i1); + if (dumping) + { + FILE* D= (output==NULL) ? stdout : fopen(output,"wb"); + if (D==NULL) cannot("open"); + lua_lock(L); + luaU_dump(L,f,writer,D,stripping); + lua_unlock(L); + if (ferror(D)) cannot("write"); + if (fclose(D)) cannot("close"); + } + return 0; +} + +//int main(int argc, char* argv[]) +//{ +// lua_State* L; +// struct Smain s; +// int i=doargs(argc,argv); +// argc-=i; argv+=i; +// if (argc<=0) usage("no input files given"); +// L=lua_open(); +// if (L==NULL) fatal("not enough memory for state"); +// s.argc=argc; +// s.argv=argv; +// if (lua_cpcall(L,pmain,&s)!=0) fatal(lua_tostring(L,-1)); +// lua_close(L); +// return EXIT_SUCCESS; +//} diff --git a/IOS/lua/lua/luaconf.h b/IOS/lua/lua/luaconf.h new file mode 100644 index 00000000..bec30482 --- /dev/null +++ b/IOS/lua/lua/luaconf.h @@ -0,0 +1,763 @@ +/* +** $Id: luaconf.h,v 1.82.1.7 2008/02/11 16:25:08 roberto Exp $ +** Configuration file for Lua +** See Copyright Notice in lua.h +*/ + + +#ifndef lconfig_h +#define lconfig_h + +#include +#include + + +/* +** ================================================================== +** Search for "@@" to find all configurable definitions. +** =================================================================== +*/ + + +/* +@@ LUA_ANSI controls the use of non-ansi features. +** CHANGE it (define it) if you want Lua to avoid the use of any +** non-ansi feature or library. +*/ +#if defined(__STRICT_ANSI__) +#define LUA_ANSI +#endif + + +#if !defined(LUA_ANSI) && defined(_WIN32) +#define LUA_WIN +#endif + +#if defined(LUA_USE_LINUX) +#define LUA_USE_POSIX +#define LUA_USE_DLOPEN /* needs an extra library: -ldl */ +#define LUA_USE_READLINE /* needs some extra libraries */ +#endif + +#if defined(LUA_USE_MACOSX) +#define LUA_USE_POSIX +#define LUA_DL_DYLD /* does not need extra library */ +#endif + + + +/* +@@ LUA_USE_POSIX includes all functionallity listed as X/Open System +@* Interfaces Extension (XSI). +** CHANGE it (define it) if your system is XSI compatible. +*/ +#if defined(LUA_USE_POSIX) +#define LUA_USE_MKSTEMP +#define LUA_USE_ISATTY +#define LUA_USE_POPEN +#define LUA_USE_ULONGJMP +#endif + + +/* +@@ LUA_PATH and LUA_CPATH are the names of the environment variables that +@* Lua check to set its paths. +@@ LUA_INIT is the name of the environment variable that Lua +@* checks for initialization code. +** CHANGE them if you want different names. +*/ +#define LUA_PATH "LUA_PATH" +#define LUA_CPATH "LUA_CPATH" +#define LUA_INIT "LUA_INIT" + + +/* +@@ LUA_PATH_DEFAULT is the default path that Lua uses to look for +@* Lua libraries. +@@ LUA_CPATH_DEFAULT is the default path that Lua uses to look for +@* C libraries. +** CHANGE them if your machine has a non-conventional directory +** hierarchy or if you want to install your libraries in +** non-conventional directories. +*/ +#if defined(_WIN32) +/* +** In Windows, any exclamation mark ('!') in the path is replaced by the +** path of the directory of the executable file of the current process. +*/ +#define LUA_LDIR "!\\lua\\" +#define LUA_CDIR "!\\" +#define LUA_PATH_DEFAULT \ + ".\\?.lua;" LUA_LDIR"?.lua;" LUA_LDIR"?\\init.lua;" \ + LUA_CDIR"?.lua;" LUA_CDIR"?\\init.lua" +#define LUA_CPATH_DEFAULT \ + ".\\?.dll;" LUA_CDIR"?.dll;" LUA_CDIR"loadall.dll" + +#else +#define LUA_ROOT "/usr/local/" +#define LUA_LDIR LUA_ROOT "share/lua/5.1/" +#define LUA_CDIR LUA_ROOT "lib/lua/5.1/" +#define LUA_PATH_DEFAULT \ + "./?.lua;" LUA_LDIR"?.lua;" LUA_LDIR"?/init.lua;" \ + LUA_CDIR"?.lua;" LUA_CDIR"?/init.lua" +#define LUA_CPATH_DEFAULT \ + "./?.so;" LUA_CDIR"?.so;" LUA_CDIR"loadall.so" +#endif + + +/* +@@ LUA_DIRSEP is the directory separator (for submodules). +** CHANGE it if your machine does not use "/" as the directory separator +** and is not Windows. (On Windows Lua automatically uses "\".) +*/ +#if defined(_WIN32) +#define LUA_DIRSEP "\\" +#else +#define LUA_DIRSEP "/" +#endif + + +/* +@@ LUA_PATHSEP is the character that separates templates in a path. +@@ LUA_PATH_MARK is the string that marks the substitution points in a +@* template. +@@ LUA_EXECDIR in a Windows path is replaced by the executable's +@* directory. +@@ LUA_IGMARK is a mark to ignore all before it when bulding the +@* luaopen_ function name. +** CHANGE them if for some reason your system cannot use those +** characters. (E.g., if one of those characters is a common character +** in file/directory names.) Probably you do not need to change them. +*/ +#define LUA_PATHSEP ";" +#define LUA_PATH_MARK "?" +#define LUA_EXECDIR "!" +#define LUA_IGMARK "-" + + +/* +@@ LUA_INTEGER is the integral type used by lua_pushinteger/lua_tointeger. +** CHANGE that if ptrdiff_t is not adequate on your machine. (On most +** machines, ptrdiff_t gives a good choice between int or long.) +*/ +#define LUA_INTEGER ptrdiff_t + + +/* +@@ LUA_API is a mark for all core API functions. +@@ LUALIB_API is a mark for all standard library functions. +** CHANGE them if you need to define those functions in some special way. +** For instance, if you want to create one Windows DLL with the core and +** the libraries, you may want to use the following definition (define +** LUA_BUILD_AS_DLL to get it). +*/ +#if defined(LUA_BUILD_AS_DLL) + +#if defined(LUA_CORE) || defined(LUA_LIB) +#define LUA_API __declspec(dllexport) +#else +#define LUA_API __declspec(dllimport) +#endif + +#else + +#define LUA_API extern + +#endif + +/* more often than not the libs go together with the core */ +#define LUALIB_API LUA_API + + +/* +@@ LUAI_FUNC is a mark for all extern functions that are not to be +@* exported to outside modules. +@@ LUAI_DATA is a mark for all extern (const) variables that are not to +@* be exported to outside modules. +** CHANGE them if you need to mark them in some special way. Elf/gcc +** (versions 3.2 and later) mark them as "hidden" to optimize access +** when Lua is compiled as a shared library. +*/ +#if defined(luaall_c) +#define LUAI_FUNC static +#define LUAI_DATA /* empty */ + +#elif defined(__GNUC__) && ((__GNUC__*100 + __GNUC_MINOR__) >= 302) && \ + defined(__ELF__) +#define LUAI_FUNC __attribute__((visibility("hidden"))) extern +#define LUAI_DATA LUAI_FUNC + +#else +#define LUAI_FUNC extern +#define LUAI_DATA extern +#endif + + + +/* +@@ LUA_QL describes how error messages quote program elements. +** CHANGE it if you want a different appearance. +*/ +#define LUA_QL(x) "'" x "'" +#define LUA_QS LUA_QL("%s") + + +/* +@@ LUA_IDSIZE gives the maximum size for the description of the source +@* of a function in debug information. +** CHANGE it if you want a different size. +*/ +#define LUA_IDSIZE 256 + + +/* +** {================================================================== +** Stand-alone configuration +** =================================================================== +*/ + +#if defined(lua_c) || defined(luaall_c) + +/* +@@ lua_stdin_is_tty detects whether the standard input is a 'tty' (that +@* is, whether we're running lua interactively). +** CHANGE it if you have a better definition for non-POSIX/non-Windows +** systems. +*/ +#if defined(LUA_USE_ISATTY) +#include +#define lua_stdin_is_tty() isatty(0) +#elif defined(LUA_WIN) +#include +#include +#define lua_stdin_is_tty() _isatty(_fileno(stdin)) +#else +#define lua_stdin_is_tty() 1 /* assume stdin is a tty */ +#endif + + +/* +@@ LUA_PROMPT is the default prompt used by stand-alone Lua. +@@ LUA_PROMPT2 is the default continuation prompt used by stand-alone Lua. +** CHANGE them if you want different prompts. (You can also change the +** prompts dynamically, assigning to globals _PROMPT/_PROMPT2.) +*/ +#define LUA_PROMPT "> " +#define LUA_PROMPT2 ">> " + + +/* +@@ LUA_PROGNAME is the default name for the stand-alone Lua program. +** CHANGE it if your stand-alone interpreter has a different name and +** your system is not able to detect that name automatically. +*/ +#define LUA_PROGNAME "lua" + + +/* +@@ LUA_MAXINPUT is the maximum length for an input line in the +@* stand-alone interpreter. +** CHANGE it if you need longer lines. +*/ +#define LUA_MAXINPUT 512 + + +/* +@@ lua_readline defines how to show a prompt and then read a line from +@* the standard input. +@@ lua_saveline defines how to "save" a read line in a "history". +@@ lua_freeline defines how to free a line read by lua_readline. +** CHANGE them if you want to improve this functionality (e.g., by using +** GNU readline and history facilities). +*/ +#if defined(LUA_USE_READLINE) +#include +#include +#include +#define lua_readline(L,b,p) ((void)L, ((b)=readline(p)) != NULL) +#define lua_saveline(L,idx) \ + if (lua_strlen(L,idx) > 0) /* non-empty line? */ \ + add_history(lua_tostring(L, idx)); /* add it to history */ +#define lua_freeline(L,b) ((void)L, free(b)) +#else +#define lua_readline(L,b,p) \ + ((void)L, fputs(p, stdout), fflush(stdout), /* show prompt */ \ + fgets(b, LUA_MAXINPUT, stdin) != NULL) /* get line */ +#define lua_saveline(L,idx) { (void)L; (void)idx; } +#define lua_freeline(L,b) { (void)L; (void)b; } +#endif + +#endif + +/* }================================================================== */ + + +/* +@@ LUAI_GCPAUSE defines the default pause between garbage-collector cycles +@* as a percentage. +** CHANGE it if you want the GC to run faster or slower (higher values +** mean larger pauses which mean slower collection.) You can also change +** this value dynamically. +*/ +#define LUAI_GCPAUSE 200 /* 200% (wait memory to double before next GC) */ + + +/* +@@ LUAI_GCMUL defines the default speed of garbage collection relative to +@* memory allocation as a percentage. +** CHANGE it if you want to change the granularity of the garbage +** collection. (Higher values mean coarser collections. 0 represents +** infinity, where each step performs a full collection.) You can also +** change this value dynamically. +*/ +#define LUAI_GCMUL 200 /* GC runs 'twice the speed' of memory allocation */ + + + +/* +@@ LUA_COMPAT_GETN controls compatibility with old getn behavior. +** CHANGE it (define it) if you want exact compatibility with the +** behavior of setn/getn in Lua 5.0. +*/ +#undef LUA_COMPAT_GETN + +/* +@@ LUA_COMPAT_LOADLIB controls compatibility about global loadlib. +** CHANGE it to undefined as soon as you do not need a global 'loadlib' +** function (the function is still available as 'package.loadlib'). +*/ +#undef LUA_COMPAT_LOADLIB + +/* +@@ LUA_COMPAT_VARARG controls compatibility with old vararg feature. +** CHANGE it to undefined as soon as your programs use only '...' to +** access vararg parameters (instead of the old 'arg' table). +*/ +#define LUA_COMPAT_VARARG + +/* +@@ LUA_COMPAT_MOD controls compatibility with old math.mod function. +** CHANGE it to undefined as soon as your programs use 'math.fmod' or +** the new '%' operator instead of 'math.mod'. +*/ +#define LUA_COMPAT_MOD + +/* +@@ LUA_COMPAT_LSTR controls compatibility with old long string nesting +@* facility. +** CHANGE it to 2 if you want the old behaviour, or undefine it to turn +** off the advisory error when nesting [[...]]. +*/ +#define LUA_COMPAT_LSTR 1 + +/* +@@ LUA_COMPAT_GFIND controls compatibility with old 'string.gfind' name. +** CHANGE it to undefined as soon as you rename 'string.gfind' to +** 'string.gmatch'. +*/ +#define LUA_COMPAT_GFIND + +/* +@@ LUA_COMPAT_OPENLIB controls compatibility with old 'luaL_openlib' +@* behavior. +** CHANGE it to undefined as soon as you replace to 'luaL_register' +** your uses of 'luaL_openlib' +*/ +#define LUA_COMPAT_OPENLIB + + + +/* +@@ luai_apicheck is the assert macro used by the Lua-C API. +** CHANGE luai_apicheck if you want Lua to perform some checks in the +** parameters it gets from API calls. This may slow down the interpreter +** a bit, but may be quite useful when debugging C code that interfaces +** with Lua. A useful redefinition is to use assert.h. +*/ +#if defined(LUA_USE_APICHECK) +#include +#define luai_apicheck(L,o) { (void)L; assert(o); } +#else +#define luai_apicheck(L,o) { (void)L; } +#endif + + +/* +@@ LUAI_BITSINT defines the number of bits in an int. +** CHANGE here if Lua cannot automatically detect the number of bits of +** your machine. Probably you do not need to change this. +*/ +/* avoid overflows in comparison */ +#if INT_MAX-20 < 32760 +#define LUAI_BITSINT 16 +#elif INT_MAX > 2147483640L +/* int has at least 32 bits */ +#define LUAI_BITSINT 32 +#else +#error "you must define LUA_BITSINT with number of bits in an integer" +#endif + + +/* +@@ LUAI_UINT32 is an unsigned integer with at least 32 bits. +@@ LUAI_INT32 is an signed integer with at least 32 bits. +@@ LUAI_UMEM is an unsigned integer big enough to count the total +@* memory used by Lua. +@@ LUAI_MEM is a signed integer big enough to count the total memory +@* used by Lua. +** CHANGE here if for some weird reason the default definitions are not +** good enough for your machine. (The definitions in the 'else' +** part always works, but may waste space on machines with 64-bit +** longs.) Probably you do not need to change this. +*/ +#if LUAI_BITSINT >= 32 +#define LUAI_UINT32 unsigned int +#define LUAI_INT32 int +#define LUAI_MAXINT32 INT_MAX +#define LUAI_UMEM size_t +#define LUAI_MEM ptrdiff_t +#else +/* 16-bit ints */ +#define LUAI_UINT32 unsigned long +#define LUAI_INT32 long +#define LUAI_MAXINT32 LONG_MAX +#define LUAI_UMEM unsigned long +#define LUAI_MEM long +#endif + + +/* +@@ LUAI_MAXCALLS limits the number of nested calls. +** CHANGE it if you need really deep recursive calls. This limit is +** arbitrary; its only purpose is to stop infinite recursion before +** exhausting memory. +*/ +#define LUAI_MAXCALLS 20000 + + +/* +@@ LUAI_MAXCSTACK limits the number of Lua stack slots that a C function +@* can use. +** CHANGE it if you need lots of (Lua) stack space for your C +** functions. This limit is arbitrary; its only purpose is to stop C +** functions to consume unlimited stack space. (must be smaller than +** -LUA_REGISTRYINDEX) +*/ +#define LUAI_MAXCSTACK 8000 + + + +/* +** {================================================================== +** CHANGE (to smaller values) the following definitions if your system +** has a small C stack. (Or you may want to change them to larger +** values if your system has a large C stack and these limits are +** too rigid for you.) Some of these constants control the size of +** stack-allocated arrays used by the compiler or the interpreter, while +** others limit the maximum number of recursive calls that the compiler +** or the interpreter can perform. Values too large may cause a C stack +** overflow for some forms of deep constructs. +** =================================================================== +*/ + + +/* +@@ LUAI_MAXCCALLS is the maximum depth for nested C calls (short) and +@* syntactical nested non-terminals in a program. +*/ +#define LUAI_MAXCCALLS 200 + + +/* +@@ LUAI_MAXVARS is the maximum number of local variables per function +@* (must be smaller than 250). +*/ +#define LUAI_MAXVARS 200 + + +/* +@@ LUAI_MAXUPVALUES is the maximum number of upvalues per function +@* (must be smaller than 250). +*/ +#define LUAI_MAXUPVALUES 60 + + +/* +@@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system. +*/ +#define LUAL_BUFFERSIZE BUFSIZ + +/* }================================================================== */ + + + + +/* +** {================================================================== +@@ LUA_NUMBER is the type of numbers in Lua. +** CHANGE the following definitions only if you want to build Lua +** with a number type different from double. You may also need to +** change lua_number2int & lua_number2integer. +** =================================================================== +*/ + +#define LUA_NUMBER_DOUBLE +#define LUA_NUMBER double + +/* +@@ LUAI_UACNUMBER is the result of an 'usual argument conversion' +@* over a number. +*/ +#define LUAI_UACNUMBER double + + +/* +@@ LUA_NUMBER_SCAN is the format for reading numbers. +@@ LUA_NUMBER_FMT is the format for writing numbers. +@@ lua_number2str converts a number to a string. +@@ LUAI_MAXNUMBER2STR is maximum size of previous conversion. +@@ lua_str2number converts a string to a number. +*/ +#define LUA_NUMBER_SCAN "%lf" +#define LUA_NUMBER_FMT "%.14g" +#define lua_number2str(s,n) sprintf((s), LUA_NUMBER_FMT, (n)) +#define LUAI_MAXNUMBER2STR 32 /* 16 digits, sign, point, and \0 */ +#define lua_str2number(s,p) strtod((s), (p)) + + +/* +@@ The luai_num* macros define the primitive operations over numbers. +*/ +#if defined(LUA_CORE) +#include +#define luai_numadd(a,b) ((a)+(b)) +#define luai_numsub(a,b) ((a)-(b)) +#define luai_nummul(a,b) ((a)*(b)) +#define luai_numdiv(a,b) ((a)/(b)) +#define luai_nummod(a,b) ((a) - floor((a)/(b))*(b)) +#define luai_numpow(a,b) (pow(a,b)) +#define luai_numunm(a) (-(a)) +#define luai_numeq(a,b) ((a)==(b)) +#define luai_numlt(a,b) ((a)<(b)) +#define luai_numle(a,b) ((a)<=(b)) +#define luai_numisnan(a) (!luai_numeq((a), (a))) +#endif + + +/* +@@ lua_number2int is a macro to convert lua_Number to int. +@@ lua_number2integer is a macro to convert lua_Number to lua_Integer. +** CHANGE them if you know a faster way to convert a lua_Number to +** int (with any rounding method and without throwing errors) in your +** system. In Pentium machines, a naive typecast from double to int +** in C is extremely slow, so any alternative is worth trying. +*/ + +/* On a Pentium, resort to a trick */ +#if defined(LUA_NUMBER_DOUBLE) && !defined(LUA_ANSI) && !defined(__SSE2__) && \ + (defined(__i386) || defined (_M_IX86) || defined(__i386__)) + +/* On a Microsoft compiler, use assembler */ +#if defined(_MSC_VER) + +#define lua_number2int(i,d) __asm fld d __asm fistp i +#define lua_number2integer(i,n) lua_number2int(i, n) + +/* the next trick should work on any Pentium, but sometimes clashes + with a DirectX idiosyncrasy */ +#else + +union luai_Cast { double l_d; long l_l; }; +#define lua_number2int(i,d) \ + { volatile union luai_Cast u; u.l_d = (d) + 6755399441055744.0; (i) = u.l_l; } +#define lua_number2integer(i,n) lua_number2int(i, n) + +#endif + + +/* this option always works, but may be slow */ +#else +#define lua_number2int(i,d) ((i)=(int)(d)) +#define lua_number2integer(i,d) ((i)=(lua_Integer)(d)) + +#endif + +/* }================================================================== */ + + +/* +@@ LUAI_USER_ALIGNMENT_T is a type that requires maximum alignment. +** CHANGE it if your system requires alignments larger than double. (For +** instance, if your system supports long doubles and they must be +** aligned in 16-byte boundaries, then you should add long double in the +** union.) Probably you do not need to change this. +*/ +#define LUAI_USER_ALIGNMENT_T union { double u; void *s; long l; } + + +/* +@@ LUAI_THROW/LUAI_TRY define how Lua does exception handling. +** CHANGE them if you prefer to use longjmp/setjmp even with C++ +** or if want/don't to use _longjmp/_setjmp instead of regular +** longjmp/setjmp. By default, Lua handles errors with exceptions when +** compiling as C++ code, with _longjmp/_setjmp when asked to use them, +** and with longjmp/setjmp otherwise. +*/ +#if defined(__cplusplus) +/* C++ exceptions */ +#define LUAI_THROW(L,c) throw(c) +#define LUAI_TRY(L,c,a) try { a } catch(...) \ + { if ((c)->status == 0) (c)->status = -1; } +#define luai_jmpbuf int /* dummy variable */ + +#elif defined(LUA_USE_ULONGJMP) +/* in Unix, try _longjmp/_setjmp (more efficient) */ +#define LUAI_THROW(L,c) _longjmp((c)->b, 1) +#define LUAI_TRY(L,c,a) if (_setjmp((c)->b) == 0) { a } +#define luai_jmpbuf jmp_buf + +#else +/* default handling with long jumps */ +#define LUAI_THROW(L,c) longjmp((c)->b, 1) +#define LUAI_TRY(L,c,a) if (setjmp((c)->b) == 0) { a } +#define luai_jmpbuf jmp_buf + +#endif + + +/* +@@ LUA_MAXCAPTURES is the maximum number of captures that a pattern +@* can do during pattern-matching. +** CHANGE it if you need more captures. This limit is arbitrary. +*/ +#define LUA_MAXCAPTURES 32 + + +/* +@@ lua_tmpnam is the function that the OS library uses to create a +@* temporary name. +@@ LUA_TMPNAMBUFSIZE is the maximum size of a name created by lua_tmpnam. +** CHANGE them if you have an alternative to tmpnam (which is considered +** insecure) or if you want the original tmpnam anyway. By default, Lua +** uses tmpnam except when POSIX is available, where it uses mkstemp. +*/ +#if defined(loslib_c) || defined(luaall_c) + +#if defined(LUA_USE_MKSTEMP) +#include +#define LUA_TMPNAMBUFSIZE 32 +#define lua_tmpnam(b,e) { \ + strcpy(b, "/tmp/lua_XXXXXX"); \ + e = mkstemp(b); \ + if (e != -1) close(e); \ + e = (e == -1); } + +#else +#define LUA_TMPNAMBUFSIZE L_tmpnam +#define lua_tmpnam(b,e) { e = (tmpnam(b) == NULL); } +#endif + +#endif + + +/* +@@ lua_popen spawns a new process connected to the current one through +@* the file streams. +** CHANGE it if you have a way to implement it in your system. +*/ +#if defined(LUA_USE_POPEN) + +#define lua_popen(L,c,m) ((void)L, fflush(NULL), popen(c,m)) +#define lua_pclose(L,file) ((void)L, (pclose(file) != -1)) + +#elif defined(LUA_WIN) + +#define lua_popen(L,c,m) ((void)L, _popen(c,m)) +#define lua_pclose(L,file) ((void)L, (_pclose(file) != -1)) + +#else + +#define lua_popen(L,c,m) ((void)((void)c, m), \ + luaL_error(L, LUA_QL("popen") " not supported"), (FILE*)0) +#define lua_pclose(L,file) ((void)((void)L, file), 0) + +#endif + +/* +@@ LUA_DL_* define which dynamic-library system Lua should use. +** CHANGE here if Lua has problems choosing the appropriate +** dynamic-library system for your platform (either Windows' DLL, Mac's +** dyld, or Unix's dlopen). If your system is some kind of Unix, there +** is a good chance that it has dlopen, so LUA_DL_DLOPEN will work for +** it. To use dlopen you also need to adapt the src/Makefile (probably +** adding -ldl to the linker options), so Lua does not select it +** automatically. (When you change the makefile to add -ldl, you must +** also add -DLUA_USE_DLOPEN.) +** If you do not want any kind of dynamic library, undefine all these +** options. +** By default, _WIN32 gets LUA_DL_DLL and MAC OS X gets LUA_DL_DYLD. +*/ +#if defined(LUA_USE_DLOPEN) +#define LUA_DL_DLOPEN +#endif + +#if defined(LUA_WIN) +#define LUA_DL_DLL +#endif + + +/* +@@ LUAI_EXTRASPACE allows you to add user-specific data in a lua_State +@* (the data goes just *before* the lua_State pointer). +** CHANGE (define) this if you really need that. This value must be +** a multiple of the maximum alignment required for your machine. +*/ +#define LUAI_EXTRASPACE 0 + + +/* +@@ luai_userstate* allow user-specific actions on threads. +** CHANGE them if you defined LUAI_EXTRASPACE and need to do something +** extra when a thread is created/deleted/resumed/yielded. +*/ +#define luai_userstateopen(L) ((void)L) +#define luai_userstateclose(L) ((void)L) +#define luai_userstatethread(L,L1) ((void)L) +#define luai_userstatefree(L) ((void)L) +#define luai_userstateresume(L,n) ((void)L) +#define luai_userstateyield(L,n) ((void)L) + + +/* +@@ LUA_INTFRMLEN is the length modifier for integer conversions +@* in 'string.format'. +@@ LUA_INTFRM_T is the integer type correspoding to the previous length +@* modifier. +** CHANGE them if your system supports long long or does not support long. +*/ + +#if defined(LUA_USELONGLONG) + +#define LUA_INTFRMLEN "ll" +#define LUA_INTFRM_T long long + +#else + +#define LUA_INTFRMLEN "l" +#define LUA_INTFRM_T long + +#endif + + + +/* =================================================================== */ + +/* +** Local configuration. You can use this space to add your redefinitions +** without modifying the main part of the file. +*/ + + + +#endif + diff --git a/IOS/lua/lua/lualib.h b/IOS/lua/lua/lualib.h new file mode 100644 index 00000000..469417f6 --- /dev/null +++ b/IOS/lua/lua/lualib.h @@ -0,0 +1,53 @@ +/* +** $Id: lualib.h,v 1.36.1.1 2007/12/27 13:02:25 roberto Exp $ +** Lua standard libraries +** See Copyright Notice in lua.h +*/ + + +#ifndef lualib_h +#define lualib_h + +#include "lua.h" + + +/* Key to file-handle type */ +#define LUA_FILEHANDLE "FILE*" + + +#define LUA_COLIBNAME "coroutine" +LUALIB_API int (luaopen_base) (lua_State *L); + +#define LUA_TABLIBNAME "table" +LUALIB_API int (luaopen_table) (lua_State *L); + +#define LUA_IOLIBNAME "io" +LUALIB_API int (luaopen_io) (lua_State *L); + +#define LUA_OSLIBNAME "os" +LUALIB_API int (luaopen_os) (lua_State *L); + +#define LUA_STRLIBNAME "string" +LUALIB_API int (luaopen_string) (lua_State *L); + +#define LUA_MATHLIBNAME "math" +LUALIB_API int (luaopen_math) (lua_State *L); + +#define LUA_DBLIBNAME "debug" +LUALIB_API int (luaopen_debug) (lua_State *L); + +#define LUA_LOADLIBNAME "package" +LUALIB_API int (luaopen_package) (lua_State *L); + + +/* open all previous libraries */ +LUALIB_API void (luaL_openlibs) (lua_State *L); + + + +#ifndef lua_assert +#define lua_assert(x) ((void)0) +#endif + + +#endif diff --git a/IOS/lua/lua/lundump.c b/IOS/lua/lua/lundump.c new file mode 100644 index 00000000..8010a457 --- /dev/null +++ b/IOS/lua/lua/lundump.c @@ -0,0 +1,227 @@ +/* +** $Id: lundump.c,v 2.7.1.4 2008/04/04 19:51:41 roberto Exp $ +** load precompiled Lua chunks +** See Copyright Notice in lua.h +*/ + +#include + +#define lundump_c +#define LUA_CORE + +#include "lua.h" + +#include "ldebug.h" +#include "ldo.h" +#include "lfunc.h" +#include "lmem.h" +#include "lobject.h" +#include "lstring.h" +#include "lundump.h" +#include "lzio.h" + +typedef struct { + lua_State* L; + ZIO* Z; + Mbuffer* b; + const char* name; +} LoadState; + +#ifdef LUAC_TRUST_BINARIES +#define IF(c,s) +#define error(S,s) +#else +#define IF(c,s) if (c) error(S,s) + +static void error(LoadState* S, const char* why) +{ + luaO_pushfstring(S->L,"%s: %s in precompiled chunk",S->name,why); + luaD_throw(S->L,LUA_ERRSYNTAX); +} +#endif + +#define LoadMem(S,b,n,size) LoadBlock(S,b,(n)*(size)) +#define LoadByte(S) (lu_byte)LoadChar(S) +#define LoadVar(S,x) LoadMem(S,&x,1,sizeof(x)) +#define LoadVector(S,b,n,size) LoadMem(S,b,n,size) + +static void LoadBlock(LoadState* S, void* b, size_t size) +{ + size_t r=luaZ_read(S->Z,b,size); + IF (r!=0, "unexpected end"); +} + +static int LoadChar(LoadState* S) +{ + char x; + LoadVar(S,x); + return x; +} + +static int LoadInt(LoadState* S) +{ + int x; + LoadVar(S,x); + IF (x<0, "bad integer"); + return x; +} + +static lua_Number LoadNumber(LoadState* S) +{ + lua_Number x; + LoadVar(S,x); + return x; +} + +static TString* LoadString(LoadState* S) +{ + size_t size; + LoadVar(S,size); + if (size==0) + return NULL; + else + { + char* s=luaZ_openspace(S->L,S->b,size); + LoadBlock(S,s,size); + return luaS_newlstr(S->L,s,size-1); /* remove trailing '\0' */ + } +} + +static void LoadCode(LoadState* S, Proto* f) +{ + int n=LoadInt(S); + f->code=luaM_newvector(S->L,n,Instruction); + f->sizecode=n; + LoadVector(S,f->code,n,sizeof(Instruction)); +} + +static Proto* LoadFunction(LoadState* S, TString* p); + +static void LoadConstants(LoadState* S, Proto* f) +{ + int i,n; + n=LoadInt(S); + f->k=luaM_newvector(S->L,n,TValue); + f->sizek=n; + for (i=0; ik[i]); + for (i=0; ik[i]; + int t=LoadChar(S); + switch (t) + { + case LUA_TNIL: + setnilvalue(o); + break; + case LUA_TBOOLEAN: + setbvalue(o,LoadChar(S)!=0); + break; + case LUA_TNUMBER: + setnvalue(o,LoadNumber(S)); + break; + case LUA_TSTRING: + setsvalue2n(S->L,o,LoadString(S)); + break; + default: + error(S,"bad constant"); + break; + } + } + n=LoadInt(S); + f->p=luaM_newvector(S->L,n,Proto*); + f->sizep=n; + for (i=0; ip[i]=NULL; + for (i=0; ip[i]=LoadFunction(S,f->source); +} + +static void LoadDebug(LoadState* S, Proto* f) +{ + int i,n; + n=LoadInt(S); + f->lineinfo=luaM_newvector(S->L,n,int); + f->sizelineinfo=n; + LoadVector(S,f->lineinfo,n,sizeof(int)); + n=LoadInt(S); + f->locvars=luaM_newvector(S->L,n,LocVar); + f->sizelocvars=n; + for (i=0; ilocvars[i].varname=NULL; + for (i=0; ilocvars[i].varname=LoadString(S); + f->locvars[i].startpc=LoadInt(S); + f->locvars[i].endpc=LoadInt(S); + } + n=LoadInt(S); + f->upvalues=luaM_newvector(S->L,n,TString*); + f->sizeupvalues=n; + for (i=0; iupvalues[i]=NULL; + for (i=0; iupvalues[i]=LoadString(S); +} + +static Proto* LoadFunction(LoadState* S, TString* p) +{ + Proto* f; + if (++S->L->nCcalls > LUAI_MAXCCALLS) error(S,"code too deep"); + f=luaF_newproto(S->L); + setptvalue2s(S->L,S->L->top,f); incr_top(S->L); + f->source=LoadString(S); if (f->source==NULL) f->source=p; + f->linedefined=LoadInt(S); + f->lastlinedefined=LoadInt(S); + f->nups=LoadByte(S); + f->numparams=LoadByte(S); + f->is_vararg=LoadByte(S); + f->maxstacksize=LoadByte(S); + LoadCode(S,f); + LoadConstants(S,f); + LoadDebug(S,f); + IF (!luaG_checkcode(f), "bad code"); + S->L->top--; + S->L->nCcalls--; + return f; +} + +static void LoadHeader(LoadState* S) +{ + char h[LUAC_HEADERSIZE]; + char s[LUAC_HEADERSIZE]; + luaU_header(h); + LoadBlock(S,s,LUAC_HEADERSIZE); + IF (memcmp(h,s,LUAC_HEADERSIZE)!=0, "bad header"); +} + +/* +** load precompiled chunk +*/ +Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name) +{ + LoadState S; + if (*name=='@' || *name=='=') + S.name=name+1; + else if (*name==LUA_SIGNATURE[0]) + S.name="binary string"; + else + S.name=name; + S.L=L; + S.Z=Z; + S.b=buff; + LoadHeader(&S); + return LoadFunction(&S,luaS_newliteral(L,"=?")); +} + +/* +* make header +*/ +void luaU_header (char* h) +{ + int x=1; + memcpy(h,LUA_SIGNATURE,sizeof(LUA_SIGNATURE)-1); + h+=sizeof(LUA_SIGNATURE)-1; + *h++=(char)LUAC_VERSION; + *h++=(char)LUAC_FORMAT; + *h++=(char)*(char*)&x; /* endianness */ + *h++=(char)sizeof(int); + *h++=(char)sizeof(size_t); + *h++=(char)sizeof(Instruction); + *h++=(char)sizeof(lua_Number); + *h++=(char)(((lua_Number)0.5)==0); /* is lua_Number integral? */ +} diff --git a/IOS/lua/lua/lundump.h b/IOS/lua/lua/lundump.h new file mode 100644 index 00000000..c80189db --- /dev/null +++ b/IOS/lua/lua/lundump.h @@ -0,0 +1,36 @@ +/* +** $Id: lundump.h,v 1.37.1.1 2007/12/27 13:02:25 roberto Exp $ +** load precompiled Lua chunks +** See Copyright Notice in lua.h +*/ + +#ifndef lundump_h +#define lundump_h + +#include "lobject.h" +#include "lzio.h" + +/* load one chunk; from lundump.c */ +LUAI_FUNC Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name); + +/* make header; from lundump.c */ +LUAI_FUNC void luaU_header (char* h); + +/* dump one chunk; from ldump.c */ +LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip); + +#ifdef luac_c +/* print one chunk; from print.c */ +LUAI_FUNC void luaU_print (const Proto* f, int full); +#endif + +/* for header of binary files -- this is Lua 5.1 */ +#define LUAC_VERSION 0x51 + +/* for header of binary files -- this is the official format */ +#define LUAC_FORMAT 0 + +/* size of header of binary files */ +#define LUAC_HEADERSIZE 12 + +#endif diff --git a/IOS/lua/lua/lvm.c b/IOS/lua/lua/lvm.c new file mode 100644 index 00000000..ee3256ab --- /dev/null +++ b/IOS/lua/lua/lvm.c @@ -0,0 +1,763 @@ +/* +** $Id: lvm.c,v 2.63.1.3 2007/12/28 15:32:23 roberto Exp $ +** Lua virtual machine +** See Copyright Notice in lua.h +*/ + + +#include +#include +#include + +#define lvm_c +#define LUA_CORE + +#include "lua.h" + +#include "ldebug.h" +#include "ldo.h" +#include "lfunc.h" +#include "lgc.h" +#include "lobject.h" +#include "lopcodes.h" +#include "lstate.h" +#include "lstring.h" +#include "ltable.h" +#include "ltm.h" +#include "lvm.h" + + + +/* limit for table tag-method chains (to avoid loops) */ +#define MAXTAGLOOP 100 + + +const TValue *luaV_tonumber (const TValue *obj, TValue *n) { + lua_Number num; + if (ttisnumber(obj)) return obj; + if (ttisstring(obj) && luaO_str2d(svalue(obj), &num)) { + setnvalue(n, num); + return n; + } + else + return NULL; +} + + +int luaV_tostring (lua_State *L, StkId obj) { + if (!ttisnumber(obj)) + return 0; + else { + char s[LUAI_MAXNUMBER2STR]; + lua_Number n = nvalue(obj); + lua_number2str(s, n); + setsvalue2s(L, obj, luaS_new(L, s)); + return 1; + } +} + + +static void traceexec (lua_State *L, const Instruction *pc) { + lu_byte mask = L->hookmask; + const Instruction *oldpc = L->savedpc; + L->savedpc = pc; + if ((mask & LUA_MASKCOUNT) && L->hookcount == 0) { + resethookcount(L); + luaD_callhook(L, LUA_HOOKCOUNT, -1); + } + if (mask & LUA_MASKLINE) { + Proto *p = ci_func(L->ci)->l.p; + int npc = pcRel(pc, p); + int newline = getline(p, npc); + /* call linehook when enter a new function, when jump back (loop), + or when enter a new line */ + if (npc == 0 || pc <= oldpc || newline != getline(p, pcRel(oldpc, p))) + luaD_callhook(L, LUA_HOOKLINE, newline); + } +} + + +static void callTMres (lua_State *L, StkId res, const TValue *f, + const TValue *p1, const TValue *p2) { + ptrdiff_t result = savestack(L, res); + setobj2s(L, L->top, f); /* push function */ + setobj2s(L, L->top+1, p1); /* 1st argument */ + setobj2s(L, L->top+2, p2); /* 2nd argument */ + luaD_checkstack(L, 3); + L->top += 3; + luaD_call(L, L->top - 3, 1); + res = restorestack(L, result); + L->top--; + setobjs2s(L, res, L->top); +} + + + +static void callTM (lua_State *L, const TValue *f, const TValue *p1, + const TValue *p2, const TValue *p3) { + setobj2s(L, L->top, f); /* push function */ + setobj2s(L, L->top+1, p1); /* 1st argument */ + setobj2s(L, L->top+2, p2); /* 2nd argument */ + setobj2s(L, L->top+3, p3); /* 3th argument */ + luaD_checkstack(L, 4); + L->top += 4; + luaD_call(L, L->top - 4, 0); +} + + +void luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val) { + int loop; + for (loop = 0; loop < MAXTAGLOOP; loop++) { + const TValue *tm; + if (ttistable(t)) { /* `t' is a table? */ + Table *h = hvalue(t); + const TValue *res = luaH_get(h, key); /* do a primitive get */ + if (!ttisnil(res) || /* result is no nil? */ + (tm = fasttm(L, h->metatable, TM_INDEX)) == NULL) { /* or no TM? */ + setobj2s(L, val, res); + return; + } + /* else will try the tag method */ + } + else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_INDEX))) + luaG_typeerror(L, t, "index"); + if (ttisfunction(tm)) { + callTMres(L, val, tm, t, key); + return; + } + t = tm; /* else repeat with `tm' */ + } + luaG_runerror(L, "loop in gettable"); +} + + +void luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val) { + int loop; + for (loop = 0; loop < MAXTAGLOOP; loop++) { + const TValue *tm; + if (ttistable(t)) { /* `t' is a table? */ + Table *h = hvalue(t); + TValue *oldval = luaH_set(L, h, key); /* do a primitive set */ + if (!ttisnil(oldval) || /* result is no nil? */ + (tm = fasttm(L, h->metatable, TM_NEWINDEX)) == NULL) { /* or no TM? */ + setobj2t(L, oldval, val); + luaC_barriert(L, h, val); + return; + } + /* else will try the tag method */ + } + else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_NEWINDEX))) + luaG_typeerror(L, t, "index"); + if (ttisfunction(tm)) { + callTM(L, tm, t, key, val); + return; + } + t = tm; /* else repeat with `tm' */ + } + luaG_runerror(L, "loop in settable"); +} + + +static int call_binTM (lua_State *L, const TValue *p1, const TValue *p2, + StkId res, TMS event) { + const TValue *tm = luaT_gettmbyobj(L, p1, event); /* try first operand */ + if (ttisnil(tm)) + tm = luaT_gettmbyobj(L, p2, event); /* try second operand */ + if (ttisnil(tm)) return 0; + callTMres(L, res, tm, p1, p2); + return 1; +} + + +static const TValue *get_compTM (lua_State *L, Table *mt1, Table *mt2, + TMS event) { + const TValue *tm1 = fasttm(L, mt1, event); + const TValue *tm2; + if (tm1 == NULL) return NULL; /* no metamethod */ + if (mt1 == mt2) return tm1; /* same metatables => same metamethods */ + tm2 = fasttm(L, mt2, event); + if (tm2 == NULL) return NULL; /* no metamethod */ + if (luaO_rawequalObj(tm1, tm2)) /* same metamethods? */ + return tm1; + return NULL; +} + + +static int call_orderTM (lua_State *L, const TValue *p1, const TValue *p2, + TMS event) { + const TValue *tm1 = luaT_gettmbyobj(L, p1, event); + const TValue *tm2; + if (ttisnil(tm1)) return -1; /* no metamethod? */ + tm2 = luaT_gettmbyobj(L, p2, event); + if (!luaO_rawequalObj(tm1, tm2)) /* different metamethods? */ + return -1; + callTMres(L, L->top, tm1, p1, p2); + return !l_isfalse(L->top); +} + + +static int l_strcmp (const TString *ls, const TString *rs) { + const char *l = getstr(ls); + size_t ll = ls->tsv.len; + const char *r = getstr(rs); + size_t lr = rs->tsv.len; + for (;;) { + int temp = strcoll(l, r); + if (temp != 0) return temp; + else { /* strings are equal up to a `\0' */ + size_t len = strlen(l); /* index of first `\0' in both strings */ + if (len == lr) /* r is finished? */ + return (len == ll) ? 0 : 1; + else if (len == ll) /* l is finished? */ + return -1; /* l is smaller than r (because r is not finished) */ + /* both strings longer than `len'; go on comparing (after the `\0') */ + len++; + l += len; ll -= len; r += len; lr -= len; + } + } +} + + +int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r) { + int res; + if (ttype(l) != ttype(r)) + return luaG_ordererror(L, l, r); + else if (ttisnumber(l)) + return luai_numlt(nvalue(l), nvalue(r)); + else if (ttisstring(l)) + return l_strcmp(rawtsvalue(l), rawtsvalue(r)) < 0; + else if ((res = call_orderTM(L, l, r, TM_LT)) != -1) + return res; + return luaG_ordererror(L, l, r); +} + + +static int lessequal (lua_State *L, const TValue *l, const TValue *r) { + int res; + if (ttype(l) != ttype(r)) + return luaG_ordererror(L, l, r); + else if (ttisnumber(l)) + return luai_numle(nvalue(l), nvalue(r)); + else if (ttisstring(l)) + return l_strcmp(rawtsvalue(l), rawtsvalue(r)) <= 0; + else if ((res = call_orderTM(L, l, r, TM_LE)) != -1) /* first try `le' */ + return res; + else if ((res = call_orderTM(L, r, l, TM_LT)) != -1) /* else try `lt' */ + return !res; + return luaG_ordererror(L, l, r); +} + + +int luaV_equalval (lua_State *L, const TValue *t1, const TValue *t2) { + const TValue *tm; + lua_assert(ttype(t1) == ttype(t2)); + switch (ttype(t1)) { + case LUA_TNIL: return 1; + case LUA_TNUMBER: return luai_numeq(nvalue(t1), nvalue(t2)); + case LUA_TBOOLEAN: return bvalue(t1) == bvalue(t2); /* true must be 1 !! */ + case LUA_TLIGHTUSERDATA: return pvalue(t1) == pvalue(t2); + case LUA_TUSERDATA: { + if (uvalue(t1) == uvalue(t2)) return 1; + tm = get_compTM(L, uvalue(t1)->metatable, uvalue(t2)->metatable, + TM_EQ); + break; /* will try TM */ + } + case LUA_TTABLE: { + if (hvalue(t1) == hvalue(t2)) return 1; + tm = get_compTM(L, hvalue(t1)->metatable, hvalue(t2)->metatable, TM_EQ); + break; /* will try TM */ + } + default: return gcvalue(t1) == gcvalue(t2); + } + if (tm == NULL) return 0; /* no TM? */ + callTMres(L, L->top, tm, t1, t2); /* call TM */ + return !l_isfalse(L->top); +} + + +void luaV_concat (lua_State *L, int total, int last) { + do { + StkId top = L->base + last + 1; + int n = 2; /* number of elements handled in this pass (at least 2) */ + if (!(ttisstring(top-2) || ttisnumber(top-2)) || !tostring(L, top-1)) { + if (!call_binTM(L, top-2, top-1, top-2, TM_CONCAT)) + luaG_concaterror(L, top-2, top-1); + } else if (tsvalue(top-1)->len == 0) /* second op is empty? */ + (void)tostring(L, top - 2); /* result is first op (as string) */ + else { + /* at least two string values; get as many as possible */ + size_t tl = tsvalue(top-1)->len; + char *buffer; + int i; + /* collect total length */ + for (n = 1; n < total && tostring(L, top-n-1); n++) { + size_t l = tsvalue(top-n-1)->len; + if (l >= MAX_SIZET - tl) luaG_runerror(L, "string length overflow"); + tl += l; + } + buffer = luaZ_openspace(L, &G(L)->buff, tl); + tl = 0; + for (i=n; i>0; i--) { /* concat all strings */ + size_t l = tsvalue(top-i)->len; + memcpy(buffer+tl, svalue(top-i), l); + tl += l; + } + setsvalue2s(L, top-n, luaS_newlstr(L, buffer, tl)); + } + total -= n-1; /* got `n' strings to create 1 new */ + last -= n-1; + } while (total > 1); /* repeat until only 1 result left */ +} + + +static void Arith (lua_State *L, StkId ra, const TValue *rb, + const TValue *rc, TMS op) { + TValue tempb, tempc; + const TValue *b, *c; + if ((b = luaV_tonumber(rb, &tempb)) != NULL && + (c = luaV_tonumber(rc, &tempc)) != NULL) { + lua_Number nb = nvalue(b), nc = nvalue(c); + switch (op) { + case TM_ADD: setnvalue(ra, luai_numadd(nb, nc)); break; + case TM_SUB: setnvalue(ra, luai_numsub(nb, nc)); break; + case TM_MUL: setnvalue(ra, luai_nummul(nb, nc)); break; + case TM_DIV: setnvalue(ra, luai_numdiv(nb, nc)); break; + case TM_MOD: setnvalue(ra, luai_nummod(nb, nc)); break; + case TM_POW: setnvalue(ra, luai_numpow(nb, nc)); break; + case TM_UNM: setnvalue(ra, luai_numunm(nb)); break; + default: lua_assert(0); break; + } + } + else if (!call_binTM(L, rb, rc, ra, op)) + luaG_aritherror(L, rb, rc); +} + + + +/* +** some macros for common tasks in `luaV_execute' +*/ + +#define runtime_check(L, c) { if (!(c)) break; } + +#define RA(i) (base+GETARG_A(i)) +/* to be used after possible stack reallocation */ +#define RB(i) check_exp(getBMode(GET_OPCODE(i)) == OpArgR, base+GETARG_B(i)) +#define RC(i) check_exp(getCMode(GET_OPCODE(i)) == OpArgR, base+GETARG_C(i)) +#define RKB(i) check_exp(getBMode(GET_OPCODE(i)) == OpArgK, \ + ISK(GETARG_B(i)) ? k+INDEXK(GETARG_B(i)) : base+GETARG_B(i)) +#define RKC(i) check_exp(getCMode(GET_OPCODE(i)) == OpArgK, \ + ISK(GETARG_C(i)) ? k+INDEXK(GETARG_C(i)) : base+GETARG_C(i)) +#define KBx(i) check_exp(getBMode(GET_OPCODE(i)) == OpArgK, k+GETARG_Bx(i)) + + +#define dojump(L,pc,i) {(pc) += (i); luai_threadyield(L);} + + +#define Protect(x) { L->savedpc = pc; {x;}; base = L->base; } + + +#define arith_op(op,tm) { \ + TValue *rb = RKB(i); \ + TValue *rc = RKC(i); \ + if (ttisnumber(rb) && ttisnumber(rc)) { \ + lua_Number nb = nvalue(rb), nc = nvalue(rc); \ + setnvalue(ra, op(nb, nc)); \ + } \ + else \ + Protect(Arith(L, ra, rb, rc, tm)); \ + } + + + +void luaV_execute (lua_State *L, int nexeccalls) { + LClosure *cl; + StkId base; + TValue *k; + const Instruction *pc; + reentry: /* entry point */ + lua_assert(isLua(L->ci)); + pc = L->savedpc; + cl = &clvalue(L->ci->func)->l; + base = L->base; + k = cl->p->k; + /* main loop of interpreter */ + for (;;) { + const Instruction i = *pc++; + StkId ra; + if ((L->hookmask & (LUA_MASKLINE | LUA_MASKCOUNT)) && + (--L->hookcount == 0 || L->hookmask & LUA_MASKLINE)) { + traceexec(L, pc); + if (L->status == LUA_YIELD) { /* did hook yield? */ + L->savedpc = pc - 1; + return; + } + base = L->base; + } + /* warning!! several calls may realloc the stack and invalidate `ra' */ + ra = RA(i); + lua_assert(base == L->base && L->base == L->ci->base); + lua_assert(base <= L->top && L->top <= L->stack + L->stacksize); + lua_assert(L->top == L->ci->top || luaG_checkopenop(i)); + switch (GET_OPCODE(i)) { + case OP_MOVE: { + setobjs2s(L, ra, RB(i)); + continue; + } + case OP_LOADK: { + setobj2s(L, ra, KBx(i)); + continue; + } + case OP_LOADBOOL: { + setbvalue(ra, GETARG_B(i)); + if (GETARG_C(i)) pc++; /* skip next instruction (if C) */ + continue; + } + case OP_LOADNIL: { + TValue *rb = RB(i); + do { + setnilvalue(rb--); + } while (rb >= ra); + continue; + } + case OP_GETUPVAL: { + int b = GETARG_B(i); + setobj2s(L, ra, cl->upvals[b]->v); + continue; + } + case OP_GETGLOBAL: { + TValue g; + TValue *rb = KBx(i); + sethvalue(L, &g, cl->env); + lua_assert(ttisstring(rb)); + Protect(luaV_gettable(L, &g, rb, ra)); + continue; + } + case OP_GETTABLE: { + Protect(luaV_gettable(L, RB(i), RKC(i), ra)); + continue; + } + case OP_SETGLOBAL: { + TValue g; + sethvalue(L, &g, cl->env); + lua_assert(ttisstring(KBx(i))); + Protect(luaV_settable(L, &g, KBx(i), ra)); + continue; + } + case OP_SETUPVAL: { + UpVal *uv = cl->upvals[GETARG_B(i)]; + setobj(L, uv->v, ra); + luaC_barrier(L, uv, ra); + continue; + } + case OP_SETTABLE: { + Protect(luaV_settable(L, ra, RKB(i), RKC(i))); + continue; + } + case OP_NEWTABLE: { + int b = GETARG_B(i); + int c = GETARG_C(i); + sethvalue(L, ra, luaH_new(L, luaO_fb2int(b), luaO_fb2int(c))); + Protect(luaC_checkGC(L)); + continue; + } + case OP_SELF: { + StkId rb = RB(i); + setobjs2s(L, ra+1, rb); + Protect(luaV_gettable(L, rb, RKC(i), ra)); + continue; + } + case OP_ADD: { + arith_op(luai_numadd, TM_ADD); + continue; + } + case OP_SUB: { + arith_op(luai_numsub, TM_SUB); + continue; + } + case OP_MUL: { + arith_op(luai_nummul, TM_MUL); + continue; + } + case OP_DIV: { + arith_op(luai_numdiv, TM_DIV); + continue; + } + case OP_MOD: { + arith_op(luai_nummod, TM_MOD); + continue; + } + case OP_POW: { + arith_op(luai_numpow, TM_POW); + continue; + } + case OP_UNM: { + TValue *rb = RB(i); + if (ttisnumber(rb)) { + lua_Number nb = nvalue(rb); + setnvalue(ra, luai_numunm(nb)); + } + else { + Protect(Arith(L, ra, rb, rb, TM_UNM)); + } + continue; + } + case OP_NOT: { + int res = l_isfalse(RB(i)); /* next assignment may change this value */ + setbvalue(ra, res); + continue; + } + case OP_LEN: { + const TValue *rb = RB(i); + switch (ttype(rb)) { + case LUA_TTABLE: { + setnvalue(ra, cast_num(luaH_getn(hvalue(rb)))); + break; + } + case LUA_TSTRING: { + setnvalue(ra, cast_num(tsvalue(rb)->len)); + break; + } + default: { /* try metamethod */ + Protect( + if (!call_binTM(L, rb, luaO_nilobject, ra, TM_LEN)) + luaG_typeerror(L, rb, "get length of"); + ) + } + } + continue; + } + case OP_CONCAT: { + int b = GETARG_B(i); + int c = GETARG_C(i); + Protect(luaV_concat(L, c-b+1, c); luaC_checkGC(L)); + setobjs2s(L, RA(i), base+b); + continue; + } + case OP_JMP: { + dojump(L, pc, GETARG_sBx(i)); + continue; + } + case OP_EQ: { + TValue *rb = RKB(i); + TValue *rc = RKC(i); + Protect( + if (equalobj(L, rb, rc) == GETARG_A(i)) + dojump(L, pc, GETARG_sBx(*pc)); + ) + pc++; + continue; + } + case OP_LT: { + Protect( + if (luaV_lessthan(L, RKB(i), RKC(i)) == GETARG_A(i)) + dojump(L, pc, GETARG_sBx(*pc)); + ) + pc++; + continue; + } + case OP_LE: { + Protect( + if (lessequal(L, RKB(i), RKC(i)) == GETARG_A(i)) + dojump(L, pc, GETARG_sBx(*pc)); + ) + pc++; + continue; + } + case OP_TEST: { + if (l_isfalse(ra) != GETARG_C(i)) + dojump(L, pc, GETARG_sBx(*pc)); + pc++; + continue; + } + case OP_TESTSET: { + TValue *rb = RB(i); + if (l_isfalse(rb) != GETARG_C(i)) { + setobjs2s(L, ra, rb); + dojump(L, pc, GETARG_sBx(*pc)); + } + pc++; + continue; + } + case OP_CALL: { + int b = GETARG_B(i); + int nresults = GETARG_C(i) - 1; + if (b != 0) L->top = ra+b; /* else previous instruction set top */ + L->savedpc = pc; + switch (luaD_precall(L, ra, nresults)) { + case PCRLUA: { + nexeccalls++; + goto reentry; /* restart luaV_execute over new Lua function */ + } + case PCRC: { + /* it was a C function (`precall' called it); adjust results */ + if (nresults >= 0) L->top = L->ci->top; + base = L->base; + continue; + } + default: { + return; /* yield */ + } + } + } + case OP_TAILCALL: { + int b = GETARG_B(i); + if (b != 0) L->top = ra+b; /* else previous instruction set top */ + L->savedpc = pc; + lua_assert(GETARG_C(i) - 1 == LUA_MULTRET); + switch (luaD_precall(L, ra, LUA_MULTRET)) { + case PCRLUA: { + /* tail call: put new frame in place of previous one */ + CallInfo *ci = L->ci - 1; /* previous frame */ + int aux; + StkId func = ci->func; + StkId pfunc = (ci+1)->func; /* previous function index */ + if (L->openupval) luaF_close(L, ci->base); + L->base = ci->base = ci->func + ((ci+1)->base - pfunc); + for (aux = 0; pfunc+aux < L->top; aux++) /* move frame down */ + setobjs2s(L, func+aux, pfunc+aux); + ci->top = L->top = func+aux; /* correct top */ + lua_assert(L->top == L->base + clvalue(func)->l.p->maxstacksize); + ci->savedpc = L->savedpc; + ci->tailcalls++; /* one more call lost */ + L->ci--; /* remove new frame */ + goto reentry; + } + case PCRC: { /* it was a C function (`precall' called it) */ + base = L->base; + continue; + } + default: { + return; /* yield */ + } + } + } + case OP_RETURN: { + int b = GETARG_B(i); + if (b != 0) L->top = ra+b-1; + if (L->openupval) luaF_close(L, base); + L->savedpc = pc; + b = luaD_poscall(L, ra); + if (--nexeccalls == 0) /* was previous function running `here'? */ + return; /* no: return */ + else { /* yes: continue its execution */ + if (b) L->top = L->ci->top; + lua_assert(isLua(L->ci)); + lua_assert(GET_OPCODE(*((L->ci)->savedpc - 1)) == OP_CALL); + goto reentry; + } + } + case OP_FORLOOP: { + lua_Number step = nvalue(ra+2); + lua_Number idx = luai_numadd(nvalue(ra), step); /* increment index */ + lua_Number limit = nvalue(ra+1); + if (luai_numlt(0, step) ? luai_numle(idx, limit) + : luai_numle(limit, idx)) { + dojump(L, pc, GETARG_sBx(i)); /* jump back */ + setnvalue(ra, idx); /* update internal index... */ + setnvalue(ra+3, idx); /* ...and external index */ + } + continue; + } + case OP_FORPREP: { + const TValue *init = ra; + const TValue *plimit = ra+1; + const TValue *pstep = ra+2; + L->savedpc = pc; /* next steps may throw errors */ + if (!tonumber(init, ra)) + luaG_runerror(L, LUA_QL("for") " initial value must be a number"); + else if (!tonumber(plimit, ra+1)) + luaG_runerror(L, LUA_QL("for") " limit must be a number"); + else if (!tonumber(pstep, ra+2)) + luaG_runerror(L, LUA_QL("for") " step must be a number"); + setnvalue(ra, luai_numsub(nvalue(ra), nvalue(pstep))); + dojump(L, pc, GETARG_sBx(i)); + continue; + } + case OP_TFORLOOP: { + StkId cb = ra + 3; /* call base */ + setobjs2s(L, cb+2, ra+2); + setobjs2s(L, cb+1, ra+1); + setobjs2s(L, cb, ra); + L->top = cb+3; /* func. + 2 args (state and index) */ + Protect(luaD_call(L, cb, GETARG_C(i))); + L->top = L->ci->top; + cb = RA(i) + 3; /* previous call may change the stack */ + if (!ttisnil(cb)) { /* continue loop? */ + setobjs2s(L, cb-1, cb); /* save control variable */ + dojump(L, pc, GETARG_sBx(*pc)); /* jump back */ + } + pc++; + continue; + } + case OP_SETLIST: { + int n = GETARG_B(i); + int c = GETARG_C(i); + int last; + Table *h; + if (n == 0) { + n = cast_int(L->top - ra) - 1; + L->top = L->ci->top; + } + if (c == 0) c = cast_int(*pc++); + runtime_check(L, ttistable(ra)); + h = hvalue(ra); + last = ((c-1)*LFIELDS_PER_FLUSH) + n; + if (last > h->sizearray) /* needs more space? */ + luaH_resizearray(L, h, last); /* pre-alloc it at once */ + for (; n > 0; n--) { + TValue *val = ra+n; + setobj2t(L, luaH_setnum(L, h, last--), val); + luaC_barriert(L, h, val); + } + continue; + } + case OP_CLOSE: { + luaF_close(L, ra); + continue; + } + case OP_CLOSURE: { + Proto *p; + Closure *ncl; + int nup, j; + p = cl->p->p[GETARG_Bx(i)]; + nup = p->nups; + ncl = luaF_newLclosure(L, nup, cl->env); + ncl->l.p = p; + for (j=0; jl.upvals[j] = cl->upvals[GETARG_B(*pc)]; + else { + lua_assert(GET_OPCODE(*pc) == OP_MOVE); + ncl->l.upvals[j] = luaF_findupval(L, base + GETARG_B(*pc)); + } + } + setclvalue(L, ra, ncl); + Protect(luaC_checkGC(L)); + continue; + } + case OP_VARARG: { + int b = GETARG_B(i) - 1; + int j; + CallInfo *ci = L->ci; + int n = cast_int(ci->base - ci->func) - cl->p->numparams - 1; + if (b == LUA_MULTRET) { + Protect(luaD_checkstack(L, n)); + ra = RA(i); /* previous call may change the stack */ + b = n; + L->top = ra + n; + } + for (j = 0; j < b; j++) { + if (j < n) { + setobjs2s(L, ra + j, ci->base - n + j); + } + else { + setnilvalue(ra + j); + } + } + continue; + } + } + } +} + diff --git a/IOS/lua/lua/lvm.h b/IOS/lua/lua/lvm.h new file mode 100644 index 00000000..bfe4f567 --- /dev/null +++ b/IOS/lua/lua/lvm.h @@ -0,0 +1,36 @@ +/* +** $Id: lvm.h,v 2.5.1.1 2007/12/27 13:02:25 roberto Exp $ +** Lua virtual machine +** See Copyright Notice in lua.h +*/ + +#ifndef lvm_h +#define lvm_h + + +#include "ldo.h" +#include "lobject.h" +#include "ltm.h" + + +#define tostring(L,o) ((ttype(o) == LUA_TSTRING) || (luaV_tostring(L, o))) + +#define tonumber(o,n) (ttype(o) == LUA_TNUMBER || \ + (((o) = luaV_tonumber(o,n)) != NULL)) + +#define equalobj(L,o1,o2) \ + (ttype(o1) == ttype(o2) && luaV_equalval(L, o1, o2)) + + +LUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r); +LUAI_FUNC int luaV_equalval (lua_State *L, const TValue *t1, const TValue *t2); +LUAI_FUNC const TValue *luaV_tonumber (const TValue *obj, TValue *n); +LUAI_FUNC int luaV_tostring (lua_State *L, StkId obj); +LUAI_FUNC void luaV_gettable (lua_State *L, const TValue *t, TValue *key, + StkId val); +LUAI_FUNC void luaV_settable (lua_State *L, const TValue *t, TValue *key, + StkId val); +LUAI_FUNC void luaV_execute (lua_State *L, int nexeccalls); +LUAI_FUNC void luaV_concat (lua_State *L, int total, int last); + +#endif diff --git a/IOS/lua/lua/lzio.c b/IOS/lua/lua/lzio.c new file mode 100644 index 00000000..293edd59 --- /dev/null +++ b/IOS/lua/lua/lzio.c @@ -0,0 +1,82 @@ +/* +** $Id: lzio.c,v 1.31.1.1 2007/12/27 13:02:25 roberto Exp $ +** a generic input stream interface +** See Copyright Notice in lua.h +*/ + + +#include + +#define lzio_c +#define LUA_CORE + +#include "lua.h" + +#include "llimits.h" +#include "lmem.h" +#include "lstate.h" +#include "lzio.h" + + +int luaZ_fill (ZIO *z) { + size_t size; + lua_State *L = z->L; + const char *buff; + lua_unlock(L); + buff = z->reader(L, z->data, &size); + lua_lock(L); + if (buff == NULL || size == 0) return EOZ; + z->n = size - 1; + z->p = buff; + return char2int(*(z->p++)); +} + + +int luaZ_lookahead (ZIO *z) { + if (z->n == 0) { + if (luaZ_fill(z) == EOZ) + return EOZ; + else { + z->n++; /* luaZ_fill removed first byte; put back it */ + z->p--; + } + } + return char2int(*z->p); +} + + +void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) { + z->L = L; + z->reader = reader; + z->data = data; + z->n = 0; + z->p = NULL; +} + + +/* --------------------------------------------------------------- read --- */ +size_t luaZ_read (ZIO *z, void *b, size_t n) { + while (n) { + size_t m; + if (luaZ_lookahead(z) == EOZ) + return n; /* return number of missing bytes */ + m = (n <= z->n) ? n : z->n; /* min. between n and z->n */ + memcpy(b, z->p, m); + z->n -= m; + z->p += m; + b = (char *)b + m; + n -= m; + } + return 0; +} + +/* ------------------------------------------------------------------------ */ +char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n) { + if (n > buff->buffsize) { + if (n < LUA_MINBUFFER) n = LUA_MINBUFFER; + luaZ_resizebuffer(L, buff, n); + } + return buff->buffer; +} + + diff --git a/IOS/lua/lua/lzio.h b/IOS/lua/lua/lzio.h new file mode 100644 index 00000000..51d695d8 --- /dev/null +++ b/IOS/lua/lua/lzio.h @@ -0,0 +1,67 @@ +/* +** $Id: lzio.h,v 1.21.1.1 2007/12/27 13:02:25 roberto Exp $ +** Buffered streams +** See Copyright Notice in lua.h +*/ + + +#ifndef lzio_h +#define lzio_h + +#include "lua.h" + +#include "lmem.h" + + +#define EOZ (-1) /* end of stream */ + +typedef struct Zio ZIO; + +#define char2int(c) cast(int, cast(unsigned char, (c))) + +#define zgetc(z) (((z)->n--)>0 ? char2int(*(z)->p++) : luaZ_fill(z)) + +typedef struct Mbuffer { + char *buffer; + size_t n; + size_t buffsize; +} Mbuffer; + +#define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0) + +#define luaZ_buffer(buff) ((buff)->buffer) +#define luaZ_sizebuffer(buff) ((buff)->buffsize) +#define luaZ_bufflen(buff) ((buff)->n) + +#define luaZ_resetbuffer(buff) ((buff)->n = 0) + + +#define luaZ_resizebuffer(L, buff, size) \ + (luaM_reallocvector(L, (buff)->buffer, (buff)->buffsize, size, char), \ + (buff)->buffsize = size) + +#define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0) + + +LUAI_FUNC char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n); +LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, + void *data); +LUAI_FUNC size_t luaZ_read (ZIO* z, void* b, size_t n); /* read next n bytes */ +LUAI_FUNC int luaZ_lookahead (ZIO *z); + + + +/* --------- Private Part ------------------ */ + +struct Zio { + size_t n; /* bytes still unread */ + const char *p; /* current position in buffer */ + lua_Reader reader; + void* data; /* additional data */ + lua_State *L; /* Lua state (for reader) */ +}; + + +LUAI_FUNC int luaZ_fill (ZIO *z); + +#endif diff --git a/IOS/lua/lua/print.c b/IOS/lua/lua/print.c new file mode 100644 index 00000000..e240cfc3 --- /dev/null +++ b/IOS/lua/lua/print.c @@ -0,0 +1,227 @@ +/* +** $Id: print.c,v 1.55a 2006/05/31 13:30:05 lhf Exp $ +** print bytecodes +** See Copyright Notice in lua.h +*/ + +#include +#include + +#define luac_c +#define LUA_CORE + +#include "ldebug.h" +#include "lobject.h" +#include "lopcodes.h" +#include "lundump.h" + +#define PrintFunction luaU_print + +#define Sizeof(x) ((int)sizeof(x)) +#define VOID(p) ((const void*)(p)) + +static void PrintString(const TString* ts) +{ + const char* s=getstr(ts); + size_t i,n=ts->tsv.len; + putchar('"'); + for (i=0; ik[i]; + switch (ttype(o)) + { + case LUA_TNIL: + printf("nil"); + break; + case LUA_TBOOLEAN: + printf(bvalue(o) ? "true" : "false"); + break; + case LUA_TNUMBER: + printf(LUA_NUMBER_FMT,nvalue(o)); + break; + case LUA_TSTRING: + PrintString(rawtsvalue(o)); + break; + default: /* cannot happen */ + printf("? type=%d",ttype(o)); + break; + } +} + +static void PrintCode(const Proto* f) +{ + const Instruction* code=f->code; + int pc,n=f->sizecode; + for (pc=0; pc0) printf("[%d]\t",line); else printf("[-]\t"); + printf("%-9s\t",luaP_opnames[o]); + switch (getOpMode(o)) + { + case iABC: + printf("%d",a); + if (getBMode(o)!=OpArgN) printf(" %d",ISK(b) ? (-1-INDEXK(b)) : b); + if (getCMode(o)!=OpArgN) printf(" %d",ISK(c) ? (-1-INDEXK(c)) : c); + break; + case iABx: + if (getBMode(o)==OpArgK) printf("%d %d",a,-1-bx); else printf("%d %d",a,bx); + break; + case iAsBx: + if (o==OP_JMP) printf("%d",sbx); else printf("%d %d",a,sbx); + break; + } + switch (o) + { + case OP_LOADK: + printf("\t; "); PrintConstant(f,bx); + break; + case OP_GETUPVAL: + case OP_SETUPVAL: + printf("\t; %s", (f->sizeupvalues>0) ? getstr(f->upvalues[b]) : "-"); + break; + case OP_GETGLOBAL: + case OP_SETGLOBAL: + printf("\t; %s",svalue(&f->k[bx])); + break; + case OP_GETTABLE: + case OP_SELF: + if (ISK(c)) { printf("\t; "); PrintConstant(f,INDEXK(c)); } + break; + case OP_SETTABLE: + case OP_ADD: + case OP_SUB: + case OP_MUL: + case OP_DIV: + case OP_POW: + case OP_EQ: + case OP_LT: + case OP_LE: + if (ISK(b) || ISK(c)) + { + printf("\t; "); + if (ISK(b)) PrintConstant(f,INDEXK(b)); else printf("-"); + printf(" "); + if (ISK(c)) PrintConstant(f,INDEXK(c)); else printf("-"); + } + break; + case OP_JMP: + case OP_FORLOOP: + case OP_FORPREP: + printf("\t; to %d",sbx+pc+2); + break; + case OP_CLOSURE: + printf("\t; %p",VOID(f->p[bx])); + break; + case OP_SETLIST: + if (c==0) printf("\t; %d",(int)code[++pc]); + else printf("\t; %d",c); + break; + default: + break; + } + printf("\n"); + } +} + +#define SS(x) (x==1)?"":"s" +#define S(x) x,SS(x) + +static void PrintHeader(const Proto* f) +{ + const char* s=getstr(f->source); + if (*s=='@' || *s=='=') + s++; + else if (*s==LUA_SIGNATURE[0]) + s="(bstring)"; + else + s="(string)"; + printf("\n%s <%s:%d,%d> (%d instruction%s, %d bytes at %p)\n", + (f->linedefined==0)?"main":"function",s, + f->linedefined,f->lastlinedefined, + S(f->sizecode),f->sizecode*Sizeof(Instruction),VOID(f)); + printf("%d%s param%s, %d slot%s, %d upvalue%s, ", + f->numparams,f->is_vararg?"+":"",SS(f->numparams), + S(f->maxstacksize),S(f->nups)); + printf("%d local%s, %d constant%s, %d function%s\n", + S(f->sizelocvars),S(f->sizek),S(f->sizep)); +} + +static void PrintConstants(const Proto* f) +{ + int i,n=f->sizek; + printf("constants (%d) for %p:\n",n,VOID(f)); + for (i=0; isizelocvars; + printf("locals (%d) for %p:\n",n,VOID(f)); + for (i=0; ilocvars[i].varname),f->locvars[i].startpc+1,f->locvars[i].endpc+1); + } +} + +static void PrintUpvalues(const Proto* f) +{ + int i,n=f->sizeupvalues; + printf("upvalues (%d) for %p:\n",n,VOID(f)); + if (f->upvalues==NULL) return; + for (i=0; iupvalues[i])); + } +} + +void PrintFunction(const Proto* f, int full) +{ + int i,n=f->sizep; + PrintHeader(f); + PrintCode(f); + if (full) + { + PrintConstants(f); + PrintLocals(f); + PrintUpvalues(f); + } + for (i=0; ip[i],full); +} diff --git a/IOS/luaviewEx/.gitignore b/IOS/luaviewEx/.gitignore new file mode 100644 index 00000000..e7b722df --- /dev/null +++ b/IOS/luaviewEx/.gitignore @@ -0,0 +1,33 @@ +# OS X +.DS_Store + +# Xcode +build/ +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 +xcuserdata/ +*.xccheckout +profile +*.moved-aside +DerivedData +*.hmap +*.ipa + +# Bundler +.bundle + +Carthage +# We recommend against adding the Pods directory to your .gitignore. However +# you should judge for yourself, the pros and cons are mentioned at: +# http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control +# +# Note: if you ignore the Pods directory, make sure to uncomment +# `pod install` in .travis.yml +# +# Pods/ diff --git a/IOS/luaviewEx/.travis.yml b/IOS/luaviewEx/.travis.yml new file mode 100644 index 00000000..6ab2fb5f --- /dev/null +++ b/IOS/luaviewEx/.travis.yml @@ -0,0 +1,14 @@ +# references: +# * http://www.objc.io/issue-6/travis-ci.html +# * https://github.com/supermarin/xcpretty#usage + +osx_image: xcode7.3 +language: objective-c +# cache: cocoapods +# podfile: Example/Podfile +# before_install: +# - gem install cocoapods # Since Travis is not always on latest version +# - pod install --project-directory=Example +script: +- set -o pipefail && xcodebuild test -workspace Example/luaviewEx.xcworkspace -scheme luaviewEx-Example -sdk iphonesimulator9.3 ONLY_ACTIVE_ARCH=NO | xcpretty +- pod lib lint diff --git a/IOS/luaviewEx/Example/Podfile b/IOS/luaviewEx/Example/Podfile new file mode 100644 index 00000000..3b75636f --- /dev/null +++ b/IOS/luaviewEx/Example/Podfile @@ -0,0 +1,6 @@ +target 'luaviewEx_Example' do + pod 'luaviewEx', :path => '../' + pod 'SDWebImage', '3.7.5' + pod 'LuaViewSDK', :git => 'https://github.com/alibaba/LuaViewSDK.git', :branch=>'develop' + pod 'MJRefresh' +end diff --git a/IOS/luaviewEx/Example/Podfile.lock b/IOS/luaviewEx/Example/Podfile.lock new file mode 100644 index 00000000..b45b73d3 --- /dev/null +++ b/IOS/luaviewEx/Example/Podfile.lock @@ -0,0 +1,35 @@ +PODS: + - luaviewEx (0.1.0): + - LuaViewSDK + - SDWebImage (~> 3.7.5) + - LuaViewSDK (2.5.16.5) + - MJRefresh (3.1.12) + - SDWebImage (3.7.5): + - SDWebImage/Core (= 3.7.5) + - SDWebImage/Core (3.7.5) + +DEPENDENCIES: + - luaviewEx (from `../`) + - LuaViewSDK (from `https://github.com/alibaba/LuaViewSDK.git`, branch `develop`) + - MJRefresh + - SDWebImage (= 3.7.5) + +EXTERNAL SOURCES: + luaviewEx: + :path: ../ + LuaViewSDK: + :branch: develop + :git: https://github.com/alibaba/LuaViewSDK.git + +CHECKOUT OPTIONS: + LuaViewSDK: + :commit: fd209f64bebecc12347f772446ac1b8ffc8eef4d + :git: https://github.com/alibaba/LuaViewSDK.git + +SPEC CHECKSUMS: + luaviewEx: 6fd6581868833a6b12a26b77b5eb352c36b70167 + LuaViewSDK: 54bae1ca82369020590e4b4db5b7a9a552f8abbb + MJRefresh: 11e1c9d86f2093ddcdbda7836bc2da477ddf568d + SDWebImage: 033e39d6f389724696c4d790b4daffcb4395a9f6 + +COCOAPODS: 0.39.0 diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/JUFLXCSSParser.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/JUFLXCSSParser.h new file mode 120000 index 00000000..cff9798d --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/JUFLXCSSParser.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXCSSParser.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/JUFLXLayoutDefine.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/JUFLXLayoutDefine.h new file mode 120000 index 00000000..7282993c --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/JUFLXLayoutDefine.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXLayoutDefine.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/JUFLXLayoutKit.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/JUFLXLayoutKit.h new file mode 120000 index 00000000..0ae0f18c --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/JUFLXLayoutKit.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXLayoutKit.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/JUFLXLinearLayoutView.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/JUFLXLinearLayoutView.h new file mode 120000 index 00000000..aa93faa6 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/JUFLXLinearLayoutView.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/LayoutExtensions/JUFLXLinearLayoutView.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/JUFLXNode.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/JUFLXNode.h new file mode 120000 index 00000000..b806862e --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/JUFLXNode.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXNode.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/JUFLXTargeNamespace.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/JUFLXTargeNamespace.h new file mode 120000 index 00000000..0bf294d0 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/JUFLXTargeNamespace.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXTargeNamespace.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVAlert.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVAlert.h new file mode 120000 index 00000000..ee14a8ee --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVAlert.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAlert.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVAnimate.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVAnimate.h new file mode 120000 index 00000000..b2cfe6eb --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVAnimate.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAnimate.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVAnimator.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVAnimator.h new file mode 120000 index 00000000..8a34e39c --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVAnimator.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAnimator.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVAudioPlayer.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVAudioPlayer.h new file mode 120000 index 00000000..503efb6a --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVAudioPlayer.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAudioPlayer.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVBaseView.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVBaseView.h new file mode 120000 index 00000000..aaaa6a3d --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVBaseView.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVBaseView.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVBlock.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVBlock.h new file mode 120000 index 00000000..445418f1 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVBlock.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LVBlock.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVBundle.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVBundle.h new file mode 120000 index 00000000..400159a5 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVBundle.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LVBundle.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVButton.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVButton.h new file mode 120000 index 00000000..69276a67 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVButton.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVButton.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVCanvas.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVCanvas.h new file mode 120000 index 00000000..feff6a0f --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVCanvas.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCanvas.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVClassInfo.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVClassInfo.h new file mode 120000 index 00000000..62d55547 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVClassInfo.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVClassInfo.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVCollectionView.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVCollectionView.h new file mode 120000 index 00000000..e51d8c7e --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVCollectionView.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCollectionView.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVCollectionViewCell.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVCollectionViewCell.h new file mode 120000 index 00000000..20527984 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVCollectionViewCell.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCollectionViewCell.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVCollectionViewDelegate.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVCollectionViewDelegate.h new file mode 120000 index 00000000..7f58de3a --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVCollectionViewDelegate.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCollectionViewDelegate.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVCustomPanel.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVCustomPanel.h new file mode 120000 index 00000000..f2ac515d --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVCustomPanel.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCustomPanel.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVCustomView.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVCustomView.h new file mode 120000 index 00000000..200c1196 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVCustomView.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCustomView.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVDB.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVDB.h new file mode 120000 index 00000000..9d63b485 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVDB.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVDB.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVData.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVData.h new file mode 120000 index 00000000..173d79fd --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVData.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVData.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVDate.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVDate.h new file mode 120000 index 00000000..e2e978b8 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVDate.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVDate.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVDebugConnection.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVDebugConnection.h new file mode 120000 index 00000000..dafef858 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVDebugConnection.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvdebug/LVDebugConnection.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVDebuger.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVDebuger.h new file mode 120000 index 00000000..eaaf17ab --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVDebuger.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvdebug/LVDebuger.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVDownloader.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVDownloader.h new file mode 120000 index 00000000..2f254866 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVDownloader.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVDownloader.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVEmptyRefreshCollectionView.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVEmptyRefreshCollectionView.h new file mode 120000 index 00000000..d360a2c9 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVEmptyRefreshCollectionView.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVEmptyRefreshCollectionView.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVEvent.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVEvent.h new file mode 120000 index 00000000..24e2d944 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVEvent.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVEvent.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVExGlobalFunc.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVExGlobalFunc.h new file mode 120000 index 00000000..1138c3b0 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVExGlobalFunc.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVExGlobalFunc.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVFile.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVFile.h new file mode 120000 index 00000000..a12da91d --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVFile.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVFile.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVFlowLayout.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVFlowLayout.h new file mode 120000 index 00000000..ed0e4355 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVFlowLayout.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVFlowLayout.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVGesture.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVGesture.h new file mode 120000 index 00000000..6992fee1 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVGesture.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVGesture.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVGrammarChanger.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVGrammarChanger.h new file mode 120000 index 00000000..e8ce5a9e --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVGrammarChanger.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVGrammarChanger.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVHeads.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVHeads.h new file mode 120000 index 00000000..a75c22be --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVHeads.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVHeads.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVHttp.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVHttp.h new file mode 120000 index 00000000..7dec5503 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVHttp.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVHttp.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVHttpResponse.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVHttpResponse.h new file mode 120000 index 00000000..d2dd5486 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVHttpResponse.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVHttpResponse.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVImage.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVImage.h new file mode 120000 index 00000000..5c7866b7 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVImage.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVImage.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVLabel.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVLabel.h new file mode 120000 index 00000000..c5d3ceda --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVLabel.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLabel.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVLoadingIndicator.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVLoadingIndicator.h new file mode 120000 index 00000000..3c93cda4 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVLoadingIndicator.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLoadingIndicator.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVLongPressGesture.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVLongPressGesture.h new file mode 120000 index 00000000..835c2a20 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVLongPressGesture.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLongPressGesture.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVLuaObjBox.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVLuaObjBox.h new file mode 120000 index 00000000..f71f554f --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVLuaObjBox.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLuaObjBox.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVMethod.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVMethod.h new file mode 120000 index 00000000..4cc41914 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVMethod.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVMethod.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVNativeObjBox.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVNativeObjBox.h new file mode 120000 index 00000000..eac24686 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVNativeObjBox.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNativeObjBox.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVNavigation.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVNavigation.h new file mode 120000 index 00000000..65e43a85 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVNavigation.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNavigation.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVNetworkStatus.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVNetworkStatus.h new file mode 120000 index 00000000..7cc23b24 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVNetworkStatus.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNetworkStatus.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVNinePatchImage.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVNinePatchImage.h new file mode 120000 index 00000000..bb3ebab4 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVNinePatchImage.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNinePatchImage.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVPagerIndicator.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVPagerIndicator.h new file mode 120000 index 00000000..85997f54 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVPagerIndicator.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPagerIndicator.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVPagerView.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVPagerView.h new file mode 120000 index 00000000..eb0f23b0 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVPagerView.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPagerView.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVPagerViewCell.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVPagerViewCell.h new file mode 120000 index 00000000..b62737e5 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVPagerViewCell.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPagerViewCell.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVPanGesture.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVPanGesture.h new file mode 120000 index 00000000..b447a561 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVPanGesture.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPanGesture.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVPinchGesture.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVPinchGesture.h new file mode 120000 index 00000000..ca445744 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVPinchGesture.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPinchGesture.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVPkgInfo.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVPkgInfo.h new file mode 120000 index 00000000..96abe3f9 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVPkgInfo.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/PKG/LVPkgInfo.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVPkgManager.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVPkgManager.h new file mode 120000 index 00000000..88a12062 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVPkgManager.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/PKG/LVPkgManager.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVPointerValueBox.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVPointerValueBox.h new file mode 120000 index 00000000..80ee8da5 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVPointerValueBox.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPointerValueBox.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVRSA.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVRSA.h new file mode 120000 index 00000000..e98128e9 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVRSA.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/RSA/LVRSA.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVRefreshComponent.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVRefreshComponent.h new file mode 120000 index 00000000..2060488b --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVRefreshComponent.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRefreshComponent.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVRefreshConst.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVRefreshConst.h new file mode 120000 index 00000000..81e92b4a --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVRefreshConst.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRefreshConst.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVRefreshHeader.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVRefreshHeader.h new file mode 120000 index 00000000..2a719e3c --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVRefreshHeader.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRefreshHeader.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVRotationGesture.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVRotationGesture.h new file mode 120000 index 00000000..1200c219 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVRotationGesture.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRotationGesture.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVScrollView.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVScrollView.h new file mode 120000 index 00000000..2571b419 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVScrollView.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVScrollView.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVScrollViewDelegate.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVScrollViewDelegate.h new file mode 120000 index 00000000..0ac2fa2e --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVScrollViewDelegate.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVScrollViewDelegate.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVStruct.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVStruct.h new file mode 120000 index 00000000..53bdc3c6 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVStruct.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVStruct.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVStyledString.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVStyledString.h new file mode 120000 index 00000000..dffe03d1 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVStyledString.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVStyledString.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVSwipeGesture.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVSwipeGesture.h new file mode 120000 index 00000000..b5ced0f4 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVSwipeGesture.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVSwipeGesture.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVSystem.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVSystem.h new file mode 120000 index 00000000..9250b0e3 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVSystem.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVSystem.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVTapGesture.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVTapGesture.h new file mode 120000 index 00000000..4a84deac --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVTapGesture.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTapGesture.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVTextField.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVTextField.h new file mode 120000 index 00000000..b8102b92 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVTextField.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTextField.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVTimer.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVTimer.h new file mode 120000 index 00000000..746de595 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVTimer.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTimer.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVToast.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVToast.h new file mode 120000 index 00000000..fd97c006 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVToast.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVToast.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVTransform3D.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVTransform3D.h new file mode 120000 index 00000000..43bbe7ed --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVTransform3D.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTransform3D.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVTypeConvert.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVTypeConvert.h new file mode 120000 index 00000000..2b2e723f --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVTypeConvert.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTypeConvert.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVUtil.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVUtil.h new file mode 120000 index 00000000..ac6cc9c1 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVUtil.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVUtil.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVWebView.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVWebView.h new file mode 120000 index 00000000..8289c64e --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVWebView.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVWebView.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVZipArchive.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVZipArchive.h new file mode 120000 index 00000000..b9d5b240 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LVZipArchive.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/PKG/LVZipArchive.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LView.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LView.h new file mode 120000 index 00000000..d313296a --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LView.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LView.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LViewController.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LViewController.h new file mode 120000 index 00000000..aad26932 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LViewController.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LViewController.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/Layout.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/Layout.h new file mode 120000 index 00000000..82d40452 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/Layout.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/Layout.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LuaView.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LuaView.h new file mode 120000 index 00000000..0a24b841 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LuaView.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LuaView.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LuaViewCore.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LuaViewCore.h new file mode 120000 index 00000000..4cd590b7 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/LuaViewCore.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LuaViewCore.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/NSObject+LuaView.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/NSObject+LuaView.h new file mode 120000 index 00000000..337d4ee5 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/NSObject+LuaView.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/NSObject+LuaView.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/UIScrollView+LVRefresh.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/UIScrollView+LVRefresh.h new file mode 120000 index 00000000..3715a2fd --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/UIScrollView+LVRefresh.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/UIScrollView+LVRefresh.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/UIScrollView+LuaView.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/UIScrollView+LuaView.h new file mode 120000 index 00000000..61d171a3 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/UIScrollView+LuaView.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/UIScrollView+LuaView.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/UIView+JUFLXNode.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/UIView+JUFLXNode.h new file mode 120000 index 00000000..7450653b --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/UIView+JUFLXNode.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/UIView+JUFLXNode.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/UIView+LuaView.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/UIView+LuaView.h new file mode 120000 index 00000000..b2629eb2 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/UIView+LuaView.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/UIView+LuaView.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/lapi.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/lapi.h new file mode 120000 index 00000000..2cfe4202 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/lapi.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/lua/lua/lapi.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/lauxlib.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/lauxlib.h new file mode 120000 index 00000000..71a1f1d4 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/lauxlib.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/lua/lua/lauxlib.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/lcode.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/lcode.h new file mode 120000 index 00000000..f523f289 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/lcode.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/lua/lua/lcode.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/ldebug.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/ldebug.h new file mode 120000 index 00000000..8ad82de5 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/ldebug.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/lua/lua/ldebug.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/ldo.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/ldo.h new file mode 120000 index 00000000..1f37feb5 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/ldo.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/lua/lua/ldo.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/lfunc.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/lfunc.h new file mode 120000 index 00000000..9fe787ec --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/lfunc.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/lua/lua/lfunc.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/lgc.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/lgc.h new file mode 120000 index 00000000..d1fa8f58 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/lgc.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/lua/lua/lgc.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/llex.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/llex.h new file mode 120000 index 00000000..7f3fd64d --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/llex.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/lua/lua/llex.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/llimits.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/llimits.h new file mode 120000 index 00000000..64e115e5 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/llimits.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/lua/lua/llimits.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/lmem.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/lmem.h new file mode 120000 index 00000000..82f7d9f7 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/lmem.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/lua/lua/lmem.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/lobject.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/lobject.h new file mode 120000 index 00000000..c9ca9bd9 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/lobject.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/lua/lua/lobject.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/lopcodes.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/lopcodes.h new file mode 120000 index 00000000..436a47e4 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/lopcodes.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/lua/lua/lopcodes.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/lparser.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/lparser.h new file mode 120000 index 00000000..5bdcac24 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/lparser.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/lua/lua/lparser.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/lstate.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/lstate.h new file mode 120000 index 00000000..dc3d9bbd --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/lstate.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/lua/lua/lstate.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/lstring.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/lstring.h new file mode 120000 index 00000000..a3996333 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/lstring.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/lua/lua/lstring.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/ltable.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/ltable.h new file mode 120000 index 00000000..f65c272a --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/ltable.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/lua/lua/ltable.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/ltm.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/ltm.h new file mode 120000 index 00000000..d4469f9b --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/ltm.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/lua/lua/ltm.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/lua.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/lua.h new file mode 120000 index 00000000..9358f93d --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/lua.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/lua/lua/lua.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/luaconf.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/luaconf.h new file mode 120000 index 00000000..f67055a9 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/luaconf.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/lua/lua/luaconf.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/lualib.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/lualib.h new file mode 120000 index 00000000..6a5c6e62 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/lualib.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/lua/lua/lualib.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/lundump.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/lundump.h new file mode 120000 index 00000000..67166583 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/lundump.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/lua/lua/lundump.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/lvm.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/lvm.h new file mode 120000 index 00000000..f1d688a5 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/lvm.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/lua/lua/lvm.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/lzio.h b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/lzio.h new file mode 120000 index 00000000..f5cf5afa --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/LuaViewSDK/lzio.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/lua/lua/lzio.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/MJRefresh/MJRefresh.h b/IOS/luaviewEx/Example/Pods/Headers/Private/MJRefresh/MJRefresh.h new file mode 120000 index 00000000..d83fdd64 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/MJRefresh/MJRefresh.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/MJRefresh.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/MJRefresh/MJRefreshAutoFooter.h b/IOS/luaviewEx/Example/Pods/Headers/Private/MJRefresh/MJRefreshAutoFooter.h new file mode 120000 index 00000000..5bb1fbc5 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/MJRefresh/MJRefreshAutoFooter.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/Base/MJRefreshAutoFooter.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/MJRefresh/MJRefreshAutoGifFooter.h b/IOS/luaviewEx/Example/Pods/Headers/Private/MJRefresh/MJRefreshAutoGifFooter.h new file mode 120000 index 00000000..1435437b --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/MJRefresh/MJRefreshAutoGifFooter.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/Custom/Footer/Auto/MJRefreshAutoGifFooter.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/MJRefresh/MJRefreshAutoNormalFooter.h b/IOS/luaviewEx/Example/Pods/Headers/Private/MJRefresh/MJRefreshAutoNormalFooter.h new file mode 120000 index 00000000..6b87abe4 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/MJRefresh/MJRefreshAutoNormalFooter.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/Custom/Footer/Auto/MJRefreshAutoNormalFooter.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/MJRefresh/MJRefreshAutoStateFooter.h b/IOS/luaviewEx/Example/Pods/Headers/Private/MJRefresh/MJRefreshAutoStateFooter.h new file mode 120000 index 00000000..19b2053a --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/MJRefresh/MJRefreshAutoStateFooter.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/Custom/Footer/Auto/MJRefreshAutoStateFooter.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/MJRefresh/MJRefreshBackFooter.h b/IOS/luaviewEx/Example/Pods/Headers/Private/MJRefresh/MJRefreshBackFooter.h new file mode 120000 index 00000000..3df4973f --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/MJRefresh/MJRefreshBackFooter.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/Base/MJRefreshBackFooter.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/MJRefresh/MJRefreshBackGifFooter.h b/IOS/luaviewEx/Example/Pods/Headers/Private/MJRefresh/MJRefreshBackGifFooter.h new file mode 120000 index 00000000..e5d5f96d --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/MJRefresh/MJRefreshBackGifFooter.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/Custom/Footer/Back/MJRefreshBackGifFooter.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/MJRefresh/MJRefreshBackNormalFooter.h b/IOS/luaviewEx/Example/Pods/Headers/Private/MJRefresh/MJRefreshBackNormalFooter.h new file mode 120000 index 00000000..c578c7f5 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/MJRefresh/MJRefreshBackNormalFooter.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/Custom/Footer/Back/MJRefreshBackNormalFooter.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/MJRefresh/MJRefreshBackStateFooter.h b/IOS/luaviewEx/Example/Pods/Headers/Private/MJRefresh/MJRefreshBackStateFooter.h new file mode 120000 index 00000000..3317188d --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/MJRefresh/MJRefreshBackStateFooter.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/Custom/Footer/Back/MJRefreshBackStateFooter.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/MJRefresh/MJRefreshComponent.h b/IOS/luaviewEx/Example/Pods/Headers/Private/MJRefresh/MJRefreshComponent.h new file mode 120000 index 00000000..35cb1b14 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/MJRefresh/MJRefreshComponent.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/Base/MJRefreshComponent.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/MJRefresh/MJRefreshConst.h b/IOS/luaviewEx/Example/Pods/Headers/Private/MJRefresh/MJRefreshConst.h new file mode 120000 index 00000000..035954b9 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/MJRefresh/MJRefreshConst.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/MJRefreshConst.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/MJRefresh/MJRefreshFooter.h b/IOS/luaviewEx/Example/Pods/Headers/Private/MJRefresh/MJRefreshFooter.h new file mode 120000 index 00000000..743dda22 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/MJRefresh/MJRefreshFooter.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/Base/MJRefreshFooter.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/MJRefresh/MJRefreshGifHeader.h b/IOS/luaviewEx/Example/Pods/Headers/Private/MJRefresh/MJRefreshGifHeader.h new file mode 120000 index 00000000..aa6afbd0 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/MJRefresh/MJRefreshGifHeader.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/Custom/Header/MJRefreshGifHeader.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/MJRefresh/MJRefreshHeader.h b/IOS/luaviewEx/Example/Pods/Headers/Private/MJRefresh/MJRefreshHeader.h new file mode 120000 index 00000000..3a38b267 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/MJRefresh/MJRefreshHeader.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/Base/MJRefreshHeader.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/MJRefresh/MJRefreshNormalHeader.h b/IOS/luaviewEx/Example/Pods/Headers/Private/MJRefresh/MJRefreshNormalHeader.h new file mode 120000 index 00000000..b5cc1640 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/MJRefresh/MJRefreshNormalHeader.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/Custom/Header/MJRefreshNormalHeader.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/MJRefresh/MJRefreshStateHeader.h b/IOS/luaviewEx/Example/Pods/Headers/Private/MJRefresh/MJRefreshStateHeader.h new file mode 120000 index 00000000..7bd25cf7 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/MJRefresh/MJRefreshStateHeader.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/Custom/Header/MJRefreshStateHeader.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/MJRefresh/NSBundle+MJRefresh.h b/IOS/luaviewEx/Example/Pods/Headers/Private/MJRefresh/NSBundle+MJRefresh.h new file mode 120000 index 00000000..2a628b44 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/MJRefresh/NSBundle+MJRefresh.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/NSBundle+MJRefresh.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/MJRefresh/UIScrollView+MJExtension.h b/IOS/luaviewEx/Example/Pods/Headers/Private/MJRefresh/UIScrollView+MJExtension.h new file mode 120000 index 00000000..1919784b --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/MJRefresh/UIScrollView+MJExtension.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/UIScrollView+MJExtension.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/MJRefresh/UIScrollView+MJRefresh.h b/IOS/luaviewEx/Example/Pods/Headers/Private/MJRefresh/UIScrollView+MJRefresh.h new file mode 120000 index 00000000..47b703d5 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/MJRefresh/UIScrollView+MJRefresh.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/UIScrollView+MJRefresh.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/MJRefresh/UIView+MJExtension.h b/IOS/luaviewEx/Example/Pods/Headers/Private/MJRefresh/UIView+MJExtension.h new file mode 120000 index 00000000..5f198134 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/MJRefresh/UIView+MJExtension.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/UIView+MJExtension.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/SDWebImage/NSData+ImageContentType.h b/IOS/luaviewEx/Example/Pods/Headers/Private/SDWebImage/NSData+ImageContentType.h new file mode 120000 index 00000000..84574987 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/SDWebImage/NSData+ImageContentType.h @@ -0,0 +1 @@ +../../../SDWebImage/SDWebImage/NSData+ImageContentType.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/SDWebImage/SDImageCache.h b/IOS/luaviewEx/Example/Pods/Headers/Private/SDWebImage/SDImageCache.h new file mode 120000 index 00000000..0040b06a --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/SDWebImage/SDImageCache.h @@ -0,0 +1 @@ +../../../SDWebImage/SDWebImage/SDImageCache.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/SDWebImage/SDWebImageCompat.h b/IOS/luaviewEx/Example/Pods/Headers/Private/SDWebImage/SDWebImageCompat.h new file mode 120000 index 00000000..6ca24784 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/SDWebImage/SDWebImageCompat.h @@ -0,0 +1 @@ +../../../SDWebImage/SDWebImage/SDWebImageCompat.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/SDWebImage/SDWebImageDecoder.h b/IOS/luaviewEx/Example/Pods/Headers/Private/SDWebImage/SDWebImageDecoder.h new file mode 120000 index 00000000..a2f3a683 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/SDWebImage/SDWebImageDecoder.h @@ -0,0 +1 @@ +../../../SDWebImage/SDWebImage/SDWebImageDecoder.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/SDWebImage/SDWebImageDownloader.h b/IOS/luaviewEx/Example/Pods/Headers/Private/SDWebImage/SDWebImageDownloader.h new file mode 120000 index 00000000..303b03b1 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/SDWebImage/SDWebImageDownloader.h @@ -0,0 +1 @@ +../../../SDWebImage/SDWebImage/SDWebImageDownloader.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/SDWebImage/SDWebImageDownloaderOperation.h b/IOS/luaviewEx/Example/Pods/Headers/Private/SDWebImage/SDWebImageDownloaderOperation.h new file mode 120000 index 00000000..99441c48 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/SDWebImage/SDWebImageDownloaderOperation.h @@ -0,0 +1 @@ +../../../SDWebImage/SDWebImage/SDWebImageDownloaderOperation.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/SDWebImage/SDWebImageManager.h b/IOS/luaviewEx/Example/Pods/Headers/Private/SDWebImage/SDWebImageManager.h new file mode 120000 index 00000000..1b818485 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/SDWebImage/SDWebImageManager.h @@ -0,0 +1 @@ +../../../SDWebImage/SDWebImage/SDWebImageManager.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/SDWebImage/SDWebImageOperation.h b/IOS/luaviewEx/Example/Pods/Headers/Private/SDWebImage/SDWebImageOperation.h new file mode 120000 index 00000000..20e5b89e --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/SDWebImage/SDWebImageOperation.h @@ -0,0 +1 @@ +../../../SDWebImage/SDWebImage/SDWebImageOperation.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/SDWebImage/SDWebImagePrefetcher.h b/IOS/luaviewEx/Example/Pods/Headers/Private/SDWebImage/SDWebImagePrefetcher.h new file mode 120000 index 00000000..50585c6d --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/SDWebImage/SDWebImagePrefetcher.h @@ -0,0 +1 @@ +../../../SDWebImage/SDWebImage/SDWebImagePrefetcher.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/SDWebImage/UIButton+WebCache.h b/IOS/luaviewEx/Example/Pods/Headers/Private/SDWebImage/UIButton+WebCache.h new file mode 120000 index 00000000..19d2d8e8 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/SDWebImage/UIButton+WebCache.h @@ -0,0 +1 @@ +../../../SDWebImage/SDWebImage/UIButton+WebCache.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/SDWebImage/UIImage+GIF.h b/IOS/luaviewEx/Example/Pods/Headers/Private/SDWebImage/UIImage+GIF.h new file mode 120000 index 00000000..14d5aadd --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/SDWebImage/UIImage+GIF.h @@ -0,0 +1 @@ +../../../SDWebImage/SDWebImage/UIImage+GIF.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/SDWebImage/UIImage+MultiFormat.h b/IOS/luaviewEx/Example/Pods/Headers/Private/SDWebImage/UIImage+MultiFormat.h new file mode 120000 index 00000000..1fb96501 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/SDWebImage/UIImage+MultiFormat.h @@ -0,0 +1 @@ +../../../SDWebImage/SDWebImage/UIImage+MultiFormat.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/SDWebImage/UIImageView+HighlightedWebCache.h b/IOS/luaviewEx/Example/Pods/Headers/Private/SDWebImage/UIImageView+HighlightedWebCache.h new file mode 120000 index 00000000..fd4dea41 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/SDWebImage/UIImageView+HighlightedWebCache.h @@ -0,0 +1 @@ +../../../SDWebImage/SDWebImage/UIImageView+HighlightedWebCache.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/SDWebImage/UIImageView+WebCache.h b/IOS/luaviewEx/Example/Pods/Headers/Private/SDWebImage/UIImageView+WebCache.h new file mode 120000 index 00000000..0c53a47b --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/SDWebImage/UIImageView+WebCache.h @@ -0,0 +1 @@ +../../../SDWebImage/SDWebImage/UIImageView+WebCache.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/SDWebImage/UIView+WebCacheOperation.h b/IOS/luaviewEx/Example/Pods/Headers/Private/SDWebImage/UIView+WebCacheOperation.h new file mode 120000 index 00000000..f9890c40 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/SDWebImage/UIView+WebCacheOperation.h @@ -0,0 +1 @@ +../../../SDWebImage/SDWebImage/UIView+WebCacheOperation.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/luaviewEx/LVExButton.h b/IOS/luaviewEx/Example/Pods/Headers/Private/luaviewEx/LVExButton.h new file mode 120000 index 00000000..3e421146 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/luaviewEx/LVExButton.h @@ -0,0 +1 @@ +../../../../../luaviewEx/Classes/LVExButton.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/luaviewEx/LVExCollectionView.h b/IOS/luaviewEx/Example/Pods/Headers/Private/luaviewEx/LVExCollectionView.h new file mode 120000 index 00000000..b76503e0 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/luaviewEx/LVExCollectionView.h @@ -0,0 +1 @@ +../../../../../luaviewEx/Classes/LVExCollectionView.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/luaviewEx/LVExImage.h b/IOS/luaviewEx/Example/Pods/Headers/Private/luaviewEx/LVExImage.h new file mode 120000 index 00000000..7c8a9e46 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/luaviewEx/LVExImage.h @@ -0,0 +1 @@ +../../../../../luaviewEx/Classes/LVExImage.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Private/luaviewEx/LVViewController.h b/IOS/luaviewEx/Example/Pods/Headers/Private/luaviewEx/LVViewController.h new file mode 120000 index 00000000..5ca1a4bc --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Private/luaviewEx/LVViewController.h @@ -0,0 +1 @@ +../../../../../luaviewEx/Classes/LVViewController.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/JUFLXCSSParser.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/JUFLXCSSParser.h new file mode 120000 index 00000000..cff9798d --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/JUFLXCSSParser.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXCSSParser.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/JUFLXLayoutDefine.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/JUFLXLayoutDefine.h new file mode 120000 index 00000000..7282993c --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/JUFLXLayoutDefine.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXLayoutDefine.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/JUFLXLayoutKit.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/JUFLXLayoutKit.h new file mode 120000 index 00000000..0ae0f18c --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/JUFLXLayoutKit.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXLayoutKit.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/JUFLXLinearLayoutView.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/JUFLXLinearLayoutView.h new file mode 120000 index 00000000..aa93faa6 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/JUFLXLinearLayoutView.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/LayoutExtensions/JUFLXLinearLayoutView.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/JUFLXNode.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/JUFLXNode.h new file mode 120000 index 00000000..b806862e --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/JUFLXNode.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXNode.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/JUFLXTargeNamespace.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/JUFLXTargeNamespace.h new file mode 120000 index 00000000..0bf294d0 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/JUFLXTargeNamespace.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXTargeNamespace.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVAlert.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVAlert.h new file mode 120000 index 00000000..ee14a8ee --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVAlert.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAlert.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVAnimate.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVAnimate.h new file mode 120000 index 00000000..b2cfe6eb --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVAnimate.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAnimate.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVAnimator.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVAnimator.h new file mode 120000 index 00000000..8a34e39c --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVAnimator.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAnimator.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVAudioPlayer.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVAudioPlayer.h new file mode 120000 index 00000000..503efb6a --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVAudioPlayer.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAudioPlayer.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVBaseView.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVBaseView.h new file mode 120000 index 00000000..aaaa6a3d --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVBaseView.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVBaseView.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVBlock.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVBlock.h new file mode 120000 index 00000000..445418f1 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVBlock.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LVBlock.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVBundle.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVBundle.h new file mode 120000 index 00000000..400159a5 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVBundle.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LVBundle.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVButton.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVButton.h new file mode 120000 index 00000000..69276a67 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVButton.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVButton.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVCanvas.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVCanvas.h new file mode 120000 index 00000000..feff6a0f --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVCanvas.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCanvas.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVClassInfo.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVClassInfo.h new file mode 120000 index 00000000..62d55547 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVClassInfo.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVClassInfo.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVCollectionView.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVCollectionView.h new file mode 120000 index 00000000..e51d8c7e --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVCollectionView.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCollectionView.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVCollectionViewCell.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVCollectionViewCell.h new file mode 120000 index 00000000..20527984 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVCollectionViewCell.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCollectionViewCell.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVCollectionViewDelegate.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVCollectionViewDelegate.h new file mode 120000 index 00000000..7f58de3a --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVCollectionViewDelegate.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCollectionViewDelegate.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVCustomPanel.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVCustomPanel.h new file mode 120000 index 00000000..f2ac515d --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVCustomPanel.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCustomPanel.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVCustomView.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVCustomView.h new file mode 120000 index 00000000..200c1196 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVCustomView.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCustomView.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVDB.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVDB.h new file mode 120000 index 00000000..9d63b485 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVDB.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVDB.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVData.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVData.h new file mode 120000 index 00000000..173d79fd --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVData.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVData.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVDate.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVDate.h new file mode 120000 index 00000000..e2e978b8 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVDate.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVDate.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVDebugConnection.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVDebugConnection.h new file mode 120000 index 00000000..dafef858 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVDebugConnection.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvdebug/LVDebugConnection.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVDebuger.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVDebuger.h new file mode 120000 index 00000000..eaaf17ab --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVDebuger.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvdebug/LVDebuger.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVDownloader.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVDownloader.h new file mode 120000 index 00000000..2f254866 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVDownloader.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVDownloader.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVEmptyRefreshCollectionView.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVEmptyRefreshCollectionView.h new file mode 120000 index 00000000..d360a2c9 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVEmptyRefreshCollectionView.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVEmptyRefreshCollectionView.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVEvent.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVEvent.h new file mode 120000 index 00000000..24e2d944 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVEvent.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVEvent.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVExGlobalFunc.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVExGlobalFunc.h new file mode 120000 index 00000000..1138c3b0 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVExGlobalFunc.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVExGlobalFunc.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVFile.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVFile.h new file mode 120000 index 00000000..a12da91d --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVFile.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVFile.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVFlowLayout.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVFlowLayout.h new file mode 120000 index 00000000..ed0e4355 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVFlowLayout.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVFlowLayout.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVGesture.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVGesture.h new file mode 120000 index 00000000..6992fee1 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVGesture.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVGesture.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVGrammarChanger.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVGrammarChanger.h new file mode 120000 index 00000000..e8ce5a9e --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVGrammarChanger.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVGrammarChanger.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVHeads.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVHeads.h new file mode 120000 index 00000000..a75c22be --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVHeads.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVHeads.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVHttp.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVHttp.h new file mode 120000 index 00000000..7dec5503 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVHttp.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVHttp.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVHttpResponse.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVHttpResponse.h new file mode 120000 index 00000000..d2dd5486 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVHttpResponse.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVHttpResponse.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVImage.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVImage.h new file mode 120000 index 00000000..5c7866b7 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVImage.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVImage.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVLabel.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVLabel.h new file mode 120000 index 00000000..c5d3ceda --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVLabel.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLabel.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVLoadingIndicator.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVLoadingIndicator.h new file mode 120000 index 00000000..3c93cda4 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVLoadingIndicator.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLoadingIndicator.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVLongPressGesture.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVLongPressGesture.h new file mode 120000 index 00000000..835c2a20 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVLongPressGesture.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLongPressGesture.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVLuaObjBox.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVLuaObjBox.h new file mode 120000 index 00000000..f71f554f --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVLuaObjBox.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLuaObjBox.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVMethod.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVMethod.h new file mode 120000 index 00000000..4cc41914 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVMethod.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVMethod.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVNativeObjBox.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVNativeObjBox.h new file mode 120000 index 00000000..eac24686 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVNativeObjBox.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNativeObjBox.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVNavigation.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVNavigation.h new file mode 120000 index 00000000..65e43a85 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVNavigation.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNavigation.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVNetworkStatus.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVNetworkStatus.h new file mode 120000 index 00000000..7cc23b24 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVNetworkStatus.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNetworkStatus.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVNinePatchImage.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVNinePatchImage.h new file mode 120000 index 00000000..bb3ebab4 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVNinePatchImage.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNinePatchImage.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVPagerIndicator.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVPagerIndicator.h new file mode 120000 index 00000000..85997f54 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVPagerIndicator.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPagerIndicator.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVPagerView.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVPagerView.h new file mode 120000 index 00000000..eb0f23b0 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVPagerView.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPagerView.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVPagerViewCell.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVPagerViewCell.h new file mode 120000 index 00000000..b62737e5 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVPagerViewCell.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPagerViewCell.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVPanGesture.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVPanGesture.h new file mode 120000 index 00000000..b447a561 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVPanGesture.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPanGesture.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVPinchGesture.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVPinchGesture.h new file mode 120000 index 00000000..ca445744 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVPinchGesture.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPinchGesture.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVPkgInfo.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVPkgInfo.h new file mode 120000 index 00000000..96abe3f9 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVPkgInfo.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/PKG/LVPkgInfo.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVPkgManager.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVPkgManager.h new file mode 120000 index 00000000..88a12062 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVPkgManager.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/PKG/LVPkgManager.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVPointerValueBox.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVPointerValueBox.h new file mode 120000 index 00000000..80ee8da5 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVPointerValueBox.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPointerValueBox.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVRSA.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVRSA.h new file mode 120000 index 00000000..e98128e9 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVRSA.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/RSA/LVRSA.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVRefreshComponent.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVRefreshComponent.h new file mode 120000 index 00000000..2060488b --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVRefreshComponent.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRefreshComponent.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVRefreshConst.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVRefreshConst.h new file mode 120000 index 00000000..81e92b4a --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVRefreshConst.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRefreshConst.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVRefreshHeader.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVRefreshHeader.h new file mode 120000 index 00000000..2a719e3c --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVRefreshHeader.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRefreshHeader.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVRotationGesture.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVRotationGesture.h new file mode 120000 index 00000000..1200c219 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVRotationGesture.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRotationGesture.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVScrollView.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVScrollView.h new file mode 120000 index 00000000..2571b419 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVScrollView.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVScrollView.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVScrollViewDelegate.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVScrollViewDelegate.h new file mode 120000 index 00000000..0ac2fa2e --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVScrollViewDelegate.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVScrollViewDelegate.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVStruct.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVStruct.h new file mode 120000 index 00000000..53bdc3c6 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVStruct.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVStruct.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVStyledString.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVStyledString.h new file mode 120000 index 00000000..dffe03d1 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVStyledString.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVStyledString.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVSwipeGesture.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVSwipeGesture.h new file mode 120000 index 00000000..b5ced0f4 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVSwipeGesture.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVSwipeGesture.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVSystem.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVSystem.h new file mode 120000 index 00000000..9250b0e3 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVSystem.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVSystem.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVTapGesture.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVTapGesture.h new file mode 120000 index 00000000..4a84deac --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVTapGesture.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTapGesture.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVTextField.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVTextField.h new file mode 120000 index 00000000..b8102b92 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVTextField.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTextField.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVTimer.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVTimer.h new file mode 120000 index 00000000..746de595 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVTimer.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTimer.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVToast.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVToast.h new file mode 120000 index 00000000..fd97c006 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVToast.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVToast.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVTransform3D.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVTransform3D.h new file mode 120000 index 00000000..43bbe7ed --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVTransform3D.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTransform3D.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVTypeConvert.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVTypeConvert.h new file mode 120000 index 00000000..2b2e723f --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVTypeConvert.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTypeConvert.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVUtil.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVUtil.h new file mode 120000 index 00000000..ac6cc9c1 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVUtil.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVUtil.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVWebView.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVWebView.h new file mode 120000 index 00000000..8289c64e --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVWebView.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVWebView.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVZipArchive.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVZipArchive.h new file mode 120000 index 00000000..b9d5b240 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LVZipArchive.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/PKG/LVZipArchive.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LView.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LView.h new file mode 120000 index 00000000..d313296a --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LView.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LView.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LViewController.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LViewController.h new file mode 120000 index 00000000..aad26932 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LViewController.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LViewController.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/Layout.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/Layout.h new file mode 120000 index 00000000..82d40452 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/Layout.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/Layout.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LuaView.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LuaView.h new file mode 120000 index 00000000..0a24b841 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LuaView.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LuaView.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LuaViewCore.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LuaViewCore.h new file mode 120000 index 00000000..4cd590b7 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/LuaViewCore.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LuaViewCore.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/NSObject+LuaView.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/NSObject+LuaView.h new file mode 120000 index 00000000..337d4ee5 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/NSObject+LuaView.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/NSObject+LuaView.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/UIScrollView+LVRefresh.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/UIScrollView+LVRefresh.h new file mode 120000 index 00000000..3715a2fd --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/UIScrollView+LVRefresh.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/UIScrollView+LVRefresh.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/UIScrollView+LuaView.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/UIScrollView+LuaView.h new file mode 120000 index 00000000..61d171a3 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/UIScrollView+LuaView.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/UIScrollView+LuaView.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/UIView+JUFLXNode.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/UIView+JUFLXNode.h new file mode 120000 index 00000000..7450653b --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/UIView+JUFLXNode.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/UIView+JUFLXNode.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/UIView+LuaView.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/UIView+LuaView.h new file mode 120000 index 00000000..b2629eb2 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/UIView+LuaView.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/UIView+LuaView.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/lapi.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/lapi.h new file mode 120000 index 00000000..2cfe4202 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/lapi.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/lua/lua/lapi.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/lauxlib.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/lauxlib.h new file mode 120000 index 00000000..71a1f1d4 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/lauxlib.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/lua/lua/lauxlib.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/lcode.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/lcode.h new file mode 120000 index 00000000..f523f289 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/lcode.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/lua/lua/lcode.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/ldebug.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/ldebug.h new file mode 120000 index 00000000..8ad82de5 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/ldebug.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/lua/lua/ldebug.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/ldo.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/ldo.h new file mode 120000 index 00000000..1f37feb5 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/ldo.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/lua/lua/ldo.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/lfunc.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/lfunc.h new file mode 120000 index 00000000..9fe787ec --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/lfunc.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/lua/lua/lfunc.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/lgc.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/lgc.h new file mode 120000 index 00000000..d1fa8f58 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/lgc.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/lua/lua/lgc.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/llex.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/llex.h new file mode 120000 index 00000000..7f3fd64d --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/llex.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/lua/lua/llex.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/llimits.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/llimits.h new file mode 120000 index 00000000..64e115e5 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/llimits.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/lua/lua/llimits.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/lmem.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/lmem.h new file mode 120000 index 00000000..82f7d9f7 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/lmem.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/lua/lua/lmem.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/lobject.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/lobject.h new file mode 120000 index 00000000..c9ca9bd9 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/lobject.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/lua/lua/lobject.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/lopcodes.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/lopcodes.h new file mode 120000 index 00000000..436a47e4 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/lopcodes.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/lua/lua/lopcodes.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/lparser.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/lparser.h new file mode 120000 index 00000000..5bdcac24 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/lparser.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/lua/lua/lparser.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/lstate.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/lstate.h new file mode 120000 index 00000000..dc3d9bbd --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/lstate.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/lua/lua/lstate.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/lstring.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/lstring.h new file mode 120000 index 00000000..a3996333 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/lstring.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/lua/lua/lstring.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/ltable.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/ltable.h new file mode 120000 index 00000000..f65c272a --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/ltable.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/lua/lua/ltable.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/ltm.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/ltm.h new file mode 120000 index 00000000..d4469f9b --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/ltm.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/lua/lua/ltm.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/lua.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/lua.h new file mode 120000 index 00000000..9358f93d --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/lua.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/lua/lua/lua.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/luaconf.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/luaconf.h new file mode 120000 index 00000000..f67055a9 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/luaconf.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/lua/lua/luaconf.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/lualib.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/lualib.h new file mode 120000 index 00000000..6a5c6e62 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/lualib.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/lua/lua/lualib.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/lundump.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/lundump.h new file mode 120000 index 00000000..67166583 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/lundump.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/lua/lua/lundump.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/lvm.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/lvm.h new file mode 120000 index 00000000..f1d688a5 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/lvm.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/lua/lua/lvm.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/lzio.h b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/lzio.h new file mode 120000 index 00000000..f5cf5afa --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/LuaViewSDK/lzio.h @@ -0,0 +1 @@ +../../../LuaViewSDK/IOS/lua/lua/lzio.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/MJRefresh/MJRefresh.h b/IOS/luaviewEx/Example/Pods/Headers/Public/MJRefresh/MJRefresh.h new file mode 120000 index 00000000..d83fdd64 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/MJRefresh/MJRefresh.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/MJRefresh.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/MJRefresh/MJRefreshAutoFooter.h b/IOS/luaviewEx/Example/Pods/Headers/Public/MJRefresh/MJRefreshAutoFooter.h new file mode 120000 index 00000000..5bb1fbc5 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/MJRefresh/MJRefreshAutoFooter.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/Base/MJRefreshAutoFooter.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/MJRefresh/MJRefreshAutoGifFooter.h b/IOS/luaviewEx/Example/Pods/Headers/Public/MJRefresh/MJRefreshAutoGifFooter.h new file mode 120000 index 00000000..1435437b --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/MJRefresh/MJRefreshAutoGifFooter.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/Custom/Footer/Auto/MJRefreshAutoGifFooter.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/MJRefresh/MJRefreshAutoNormalFooter.h b/IOS/luaviewEx/Example/Pods/Headers/Public/MJRefresh/MJRefreshAutoNormalFooter.h new file mode 120000 index 00000000..6b87abe4 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/MJRefresh/MJRefreshAutoNormalFooter.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/Custom/Footer/Auto/MJRefreshAutoNormalFooter.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/MJRefresh/MJRefreshAutoStateFooter.h b/IOS/luaviewEx/Example/Pods/Headers/Public/MJRefresh/MJRefreshAutoStateFooter.h new file mode 120000 index 00000000..19b2053a --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/MJRefresh/MJRefreshAutoStateFooter.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/Custom/Footer/Auto/MJRefreshAutoStateFooter.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/MJRefresh/MJRefreshBackFooter.h b/IOS/luaviewEx/Example/Pods/Headers/Public/MJRefresh/MJRefreshBackFooter.h new file mode 120000 index 00000000..3df4973f --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/MJRefresh/MJRefreshBackFooter.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/Base/MJRefreshBackFooter.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/MJRefresh/MJRefreshBackGifFooter.h b/IOS/luaviewEx/Example/Pods/Headers/Public/MJRefresh/MJRefreshBackGifFooter.h new file mode 120000 index 00000000..e5d5f96d --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/MJRefresh/MJRefreshBackGifFooter.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/Custom/Footer/Back/MJRefreshBackGifFooter.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/MJRefresh/MJRefreshBackNormalFooter.h b/IOS/luaviewEx/Example/Pods/Headers/Public/MJRefresh/MJRefreshBackNormalFooter.h new file mode 120000 index 00000000..c578c7f5 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/MJRefresh/MJRefreshBackNormalFooter.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/Custom/Footer/Back/MJRefreshBackNormalFooter.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/MJRefresh/MJRefreshBackStateFooter.h b/IOS/luaviewEx/Example/Pods/Headers/Public/MJRefresh/MJRefreshBackStateFooter.h new file mode 120000 index 00000000..3317188d --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/MJRefresh/MJRefreshBackStateFooter.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/Custom/Footer/Back/MJRefreshBackStateFooter.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/MJRefresh/MJRefreshComponent.h b/IOS/luaviewEx/Example/Pods/Headers/Public/MJRefresh/MJRefreshComponent.h new file mode 120000 index 00000000..35cb1b14 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/MJRefresh/MJRefreshComponent.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/Base/MJRefreshComponent.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/MJRefresh/MJRefreshConst.h b/IOS/luaviewEx/Example/Pods/Headers/Public/MJRefresh/MJRefreshConst.h new file mode 120000 index 00000000..035954b9 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/MJRefresh/MJRefreshConst.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/MJRefreshConst.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/MJRefresh/MJRefreshFooter.h b/IOS/luaviewEx/Example/Pods/Headers/Public/MJRefresh/MJRefreshFooter.h new file mode 120000 index 00000000..743dda22 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/MJRefresh/MJRefreshFooter.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/Base/MJRefreshFooter.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/MJRefresh/MJRefreshGifHeader.h b/IOS/luaviewEx/Example/Pods/Headers/Public/MJRefresh/MJRefreshGifHeader.h new file mode 120000 index 00000000..aa6afbd0 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/MJRefresh/MJRefreshGifHeader.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/Custom/Header/MJRefreshGifHeader.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/MJRefresh/MJRefreshHeader.h b/IOS/luaviewEx/Example/Pods/Headers/Public/MJRefresh/MJRefreshHeader.h new file mode 120000 index 00000000..3a38b267 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/MJRefresh/MJRefreshHeader.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/Base/MJRefreshHeader.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/MJRefresh/MJRefreshNormalHeader.h b/IOS/luaviewEx/Example/Pods/Headers/Public/MJRefresh/MJRefreshNormalHeader.h new file mode 120000 index 00000000..b5cc1640 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/MJRefresh/MJRefreshNormalHeader.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/Custom/Header/MJRefreshNormalHeader.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/MJRefresh/MJRefreshStateHeader.h b/IOS/luaviewEx/Example/Pods/Headers/Public/MJRefresh/MJRefreshStateHeader.h new file mode 120000 index 00000000..7bd25cf7 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/MJRefresh/MJRefreshStateHeader.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/Custom/Header/MJRefreshStateHeader.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/MJRefresh/NSBundle+MJRefresh.h b/IOS/luaviewEx/Example/Pods/Headers/Public/MJRefresh/NSBundle+MJRefresh.h new file mode 120000 index 00000000..2a628b44 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/MJRefresh/NSBundle+MJRefresh.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/NSBundle+MJRefresh.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/MJRefresh/UIScrollView+MJExtension.h b/IOS/luaviewEx/Example/Pods/Headers/Public/MJRefresh/UIScrollView+MJExtension.h new file mode 120000 index 00000000..1919784b --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/MJRefresh/UIScrollView+MJExtension.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/UIScrollView+MJExtension.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/MJRefresh/UIScrollView+MJRefresh.h b/IOS/luaviewEx/Example/Pods/Headers/Public/MJRefresh/UIScrollView+MJRefresh.h new file mode 120000 index 00000000..47b703d5 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/MJRefresh/UIScrollView+MJRefresh.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/UIScrollView+MJRefresh.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/MJRefresh/UIView+MJExtension.h b/IOS/luaviewEx/Example/Pods/Headers/Public/MJRefresh/UIView+MJExtension.h new file mode 120000 index 00000000..5f198134 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/MJRefresh/UIView+MJExtension.h @@ -0,0 +1 @@ +../../../MJRefresh/MJRefresh/UIView+MJExtension.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/SDWebImage/NSData+ImageContentType.h b/IOS/luaviewEx/Example/Pods/Headers/Public/SDWebImage/NSData+ImageContentType.h new file mode 120000 index 00000000..84574987 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/SDWebImage/NSData+ImageContentType.h @@ -0,0 +1 @@ +../../../SDWebImage/SDWebImage/NSData+ImageContentType.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/SDWebImage/SDImageCache.h b/IOS/luaviewEx/Example/Pods/Headers/Public/SDWebImage/SDImageCache.h new file mode 120000 index 00000000..0040b06a --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/SDWebImage/SDImageCache.h @@ -0,0 +1 @@ +../../../SDWebImage/SDWebImage/SDImageCache.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/SDWebImage/SDWebImageCompat.h b/IOS/luaviewEx/Example/Pods/Headers/Public/SDWebImage/SDWebImageCompat.h new file mode 120000 index 00000000..6ca24784 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/SDWebImage/SDWebImageCompat.h @@ -0,0 +1 @@ +../../../SDWebImage/SDWebImage/SDWebImageCompat.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/SDWebImage/SDWebImageDecoder.h b/IOS/luaviewEx/Example/Pods/Headers/Public/SDWebImage/SDWebImageDecoder.h new file mode 120000 index 00000000..a2f3a683 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/SDWebImage/SDWebImageDecoder.h @@ -0,0 +1 @@ +../../../SDWebImage/SDWebImage/SDWebImageDecoder.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/SDWebImage/SDWebImageDownloader.h b/IOS/luaviewEx/Example/Pods/Headers/Public/SDWebImage/SDWebImageDownloader.h new file mode 120000 index 00000000..303b03b1 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/SDWebImage/SDWebImageDownloader.h @@ -0,0 +1 @@ +../../../SDWebImage/SDWebImage/SDWebImageDownloader.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/SDWebImage/SDWebImageDownloaderOperation.h b/IOS/luaviewEx/Example/Pods/Headers/Public/SDWebImage/SDWebImageDownloaderOperation.h new file mode 120000 index 00000000..99441c48 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/SDWebImage/SDWebImageDownloaderOperation.h @@ -0,0 +1 @@ +../../../SDWebImage/SDWebImage/SDWebImageDownloaderOperation.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/SDWebImage/SDWebImageManager.h b/IOS/luaviewEx/Example/Pods/Headers/Public/SDWebImage/SDWebImageManager.h new file mode 120000 index 00000000..1b818485 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/SDWebImage/SDWebImageManager.h @@ -0,0 +1 @@ +../../../SDWebImage/SDWebImage/SDWebImageManager.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/SDWebImage/SDWebImageOperation.h b/IOS/luaviewEx/Example/Pods/Headers/Public/SDWebImage/SDWebImageOperation.h new file mode 120000 index 00000000..20e5b89e --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/SDWebImage/SDWebImageOperation.h @@ -0,0 +1 @@ +../../../SDWebImage/SDWebImage/SDWebImageOperation.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/SDWebImage/SDWebImagePrefetcher.h b/IOS/luaviewEx/Example/Pods/Headers/Public/SDWebImage/SDWebImagePrefetcher.h new file mode 120000 index 00000000..50585c6d --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/SDWebImage/SDWebImagePrefetcher.h @@ -0,0 +1 @@ +../../../SDWebImage/SDWebImage/SDWebImagePrefetcher.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/SDWebImage/UIButton+WebCache.h b/IOS/luaviewEx/Example/Pods/Headers/Public/SDWebImage/UIButton+WebCache.h new file mode 120000 index 00000000..19d2d8e8 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/SDWebImage/UIButton+WebCache.h @@ -0,0 +1 @@ +../../../SDWebImage/SDWebImage/UIButton+WebCache.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/SDWebImage/UIImage+GIF.h b/IOS/luaviewEx/Example/Pods/Headers/Public/SDWebImage/UIImage+GIF.h new file mode 120000 index 00000000..14d5aadd --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/SDWebImage/UIImage+GIF.h @@ -0,0 +1 @@ +../../../SDWebImage/SDWebImage/UIImage+GIF.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/SDWebImage/UIImage+MultiFormat.h b/IOS/luaviewEx/Example/Pods/Headers/Public/SDWebImage/UIImage+MultiFormat.h new file mode 120000 index 00000000..1fb96501 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/SDWebImage/UIImage+MultiFormat.h @@ -0,0 +1 @@ +../../../SDWebImage/SDWebImage/UIImage+MultiFormat.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/SDWebImage/UIImageView+HighlightedWebCache.h b/IOS/luaviewEx/Example/Pods/Headers/Public/SDWebImage/UIImageView+HighlightedWebCache.h new file mode 120000 index 00000000..fd4dea41 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/SDWebImage/UIImageView+HighlightedWebCache.h @@ -0,0 +1 @@ +../../../SDWebImage/SDWebImage/UIImageView+HighlightedWebCache.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/SDWebImage/UIImageView+WebCache.h b/IOS/luaviewEx/Example/Pods/Headers/Public/SDWebImage/UIImageView+WebCache.h new file mode 120000 index 00000000..0c53a47b --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/SDWebImage/UIImageView+WebCache.h @@ -0,0 +1 @@ +../../../SDWebImage/SDWebImage/UIImageView+WebCache.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/SDWebImage/UIView+WebCacheOperation.h b/IOS/luaviewEx/Example/Pods/Headers/Public/SDWebImage/UIView+WebCacheOperation.h new file mode 120000 index 00000000..f9890c40 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/SDWebImage/UIView+WebCacheOperation.h @@ -0,0 +1 @@ +../../../SDWebImage/SDWebImage/UIView+WebCacheOperation.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/luaviewEx/LVExButton.h b/IOS/luaviewEx/Example/Pods/Headers/Public/luaviewEx/LVExButton.h new file mode 120000 index 00000000..3e421146 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/luaviewEx/LVExButton.h @@ -0,0 +1 @@ +../../../../../luaviewEx/Classes/LVExButton.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/luaviewEx/LVExCollectionView.h b/IOS/luaviewEx/Example/Pods/Headers/Public/luaviewEx/LVExCollectionView.h new file mode 120000 index 00000000..b76503e0 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/luaviewEx/LVExCollectionView.h @@ -0,0 +1 @@ +../../../../../luaviewEx/Classes/LVExCollectionView.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/luaviewEx/LVExImage.h b/IOS/luaviewEx/Example/Pods/Headers/Public/luaviewEx/LVExImage.h new file mode 120000 index 00000000..7c8a9e46 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/luaviewEx/LVExImage.h @@ -0,0 +1 @@ +../../../../../luaviewEx/Classes/LVExImage.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Headers/Public/luaviewEx/LVViewController.h b/IOS/luaviewEx/Example/Pods/Headers/Public/luaviewEx/LVViewController.h new file mode 120000 index 00000000..5ca1a4bc --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Headers/Public/luaviewEx/LVViewController.h @@ -0,0 +1 @@ +../../../../../luaviewEx/Classes/LVViewController.h \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Local Podspecs/LuaViewSDK.podspec.json b/IOS/luaviewEx/Example/Pods/Local Podspecs/LuaViewSDK.podspec.json new file mode 100644 index 00000000..955f055a --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Local Podspecs/LuaViewSDK.podspec.json @@ -0,0 +1,32 @@ +{ + "name": "LuaViewSDK", + "version": "2.5.16.5", + "summary": "LuaView SDK", + "description": "A longer description of LuaViewSDK.podspec in Markdown format.\n* LuaView", + "homepage": "http://gitlab.alibaba-inc.com/luaview/LuaViewSDK", + "license": { + "type": "GNU General Public Licence (GPL), Version 2.0", + "file": "LICENSE.txt" + }, + "authors": { + "城西": "xicheng.dxc@alibaba-inc.com" + }, + "platforms": { + "ios": "7.0" + }, + "source": { + "git": "git@gitlab.alibaba-inc.com:luaview/LuaViewSDK.git", + "tag": "2.1.1.2" + }, + "source_files": [ + "IOS/SDK/LuaViewSDK/Classes/**/*.{h,m,c}", + "IOS/lua/lua/*.{h,m,c}" + ], + "frameworks": [ + "Foundation", + "UIKit", + "CoreGraphics" + ], + "libraries": "z", + "requires_arc": true +} diff --git a/IOS/luaviewEx/Example/Pods/Local Podspecs/luaviewEx.podspec.json b/IOS/luaviewEx/Example/Pods/Local Podspecs/luaviewEx.podspec.json new file mode 100644 index 00000000..27a397bc --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Local Podspecs/luaviewEx.podspec.json @@ -0,0 +1,39 @@ +{ + "name": "luaviewEx", + "version": "0.1.0", + "summary": "A short description of luaviewEx.", + "description": "TODO: Add long description of the pod here.", + "homepage": "https://github.com/yechunxiao19/luaviewEx", + "license": { + "type": "MIT", + "file": "LICENSE" + }, + "authors": { + "yechunxiao19": "chunxiao.ycx@alibaba-inc.com" + }, + "source": { + "git": "https://github.com/yechunxiao19/luaviewEx.git", + "tag": "0.1.0" + }, + "platforms": { + "ios": "8.0" + }, + "source_files": "luaviewEx/Classes/*", + "resource_bundles": { + "luaviewEx": [ + "luaviewEx/Assets/**/*.{lua}" + ] + }, + "public_header_files": "Pod/Classes/*.h", + "dependencies": { + "LuaViewSDK": [ + + ], + "SDWebImage": [ + "~> 3.7.5" + ] + }, + "xcconfig": { + "INFOPLIST_FILE": "../../luaviewEx/Classes/luaviewEx-info.plist" + } +} diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LVBlock.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LVBlock.h new file mode 100644 index 00000000..28d52554 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LVBlock.h @@ -0,0 +1,35 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + +@interface LVBlock : NSObject + +@property (nonatomic,assign) int returnValueNum;// 返回值的数量 + +- (id) initWith:(lua_State*)L statckID:(int) idx; +- (id) initWith:(lua_State*)L globalName:(NSString*) globalName; + +/* + * 调用Lua function + */ +- (NSString*) callWithArgs:(NSArray*) args; +- (NSString*) callWithArgs:(NSArray*) args returnValueNum:(int) returnValueNum; + +/* + * 获取返回值 + */ +- (id) returnValue:(int)index; +- (id) returnValue; + + +- (void) pushFunctionToStack; + + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LVBlock.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LVBlock.m new file mode 100644 index 00000000..2faef2c6 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LVBlock.m @@ -0,0 +1,137 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVBlock.h" +#import "LuaViewCore.h" +#import "LVHeads.h" + +@interface LVBlock () +@property (nonatomic,weak) LuaViewCore* lview; +@property (nonatomic,strong) id retainKey; +@property (nonatomic,strong) NSArray* returnValues; +@end + +@implementation LVBlock + +- (id) initWith:(lua_State*)L statckID:(int) idx{ + self = [super init]; + if( self ){ + self.retainKey = [[NSMutableString alloc] init]; + self.lview = LV_LUASTATE_VIEW(L); + if( lua_type(L, idx)==LUA_TFUNCTION ) { + [LVUtil registryValue:L key:self.retainKey stack:idx]; + } + } + return self; +} + +- (id) initWith:(lua_State*)L globalName:(NSString*) globalName{ + self = [super init]; + if( self ){ + self.retainKey = [[NSMutableString alloc] init]; + self.lview = LV_LUASTATE_VIEW(L); + + if ( [globalName rangeOfString:@"."].length>0 ){ + [self resetFunctionByNames:globalName]; + } else { + lua_getglobal(L, globalName.UTF8String); + if( lua_type(L, -1)==LUA_TFUNCTION ) { + [LVUtil registryValue:L key:self.retainKey stack:-1]; + } + } + } + return self; +} + +-(void) resetFunctionByNames:(NSString*) globalName{ + NSArray * names = [globalName componentsSeparatedByString:@"."]; + lua_State* L = self.lview.l; + if( names.count>0 ){ + NSString* name0 = names.firstObject; + lua_getglobal(L, name0.UTF8String); + for( int i=1; i0 ) { + self.returnValues = values; + } else { + self.returnValues = nil; + } + //lua_settop(L, oldStackNum); + return ret; + } + return nil; +} + +-(void) pushFunctionToStack{ + lua_State* L = self.lview.l; + if( L ){ + [LVUtil pushRegistryValue:L key:self.retainKey]; + } +} + +-(id) returnValue{ + return [self returnValue:0]; +} + +-(id) returnValue:(int)index{ + if( index>=0 && index +#import +#import "LVHeads.h" + +@class LVRSA; + +@interface LVBundle : NSObject + +@property (nonatomic, readonly) NSArray* scriptPaths; +@property (nonatomic, readonly) NSArray* resourcePaths; + +@property (nonatomic, readonly) NSString *currentPath; + +- (void)changeCurrentPath:(NSString *)path; + +/** + * 可以是绝对路径也可以是相对bundle根目录的相对路径 + */ +- (void)addResourcePath:(NSString *)path; +- (void)removeResourcePath:(NSString *)path; + +- (void)addScriptPath:(NSString *)path; +- (void)removeScriptPath:(NSString *)path; + +- (NSString *)resourcePathWithName:(NSString *)name; + +- (NSData *)resourceWithName:(NSString *)name; +- (UIImage *)imageWithName:(NSString *)name; + +- (NSString *)scriptPathWithName:(NSString *)name; + +- (NSData *)scriptWithName:(NSString *)name; +- (NSData *)signedScriptWithName:(NSString *)name rsa:(LVRSA *)rsa; + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LVBundle.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LVBundle.m new file mode 100644 index 00000000..4d20d04d --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LVBundle.m @@ -0,0 +1,205 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVBundle.h" +#import "LVPkgManager.h" +#import "LVUtil.h" +#import "LVHeads.h" +#import "LView.h" + +@interface LVBundle () { + NSMutableArray *_scriptPaths; + NSMutableArray *_resourcePaths; + NSFileManager *_fileManager; + NSString *_currentPath; +} + +@property(nonatomic,strong) NSMutableDictionary* imageCaches; + +@end + +@implementation LVBundle + +@dynamic resourcePaths, scriptPaths; +@dynamic currentPath; + +- (id)init { + self = [super init]; + if(self) { + _fileManager = [NSFileManager defaultManager]; + _currentPath = [[NSBundle mainBundle] resourcePath]; + + _resourcePaths = [NSMutableArray arrayWithObjects:[LVUtil PathForCachesResource:nil], @".", nil]; + _scriptPaths = [NSMutableArray arrayWithObject:@"."]; + _imageCaches = [[NSMutableDictionary alloc] init]; + } + return self; +} + +- (NSString *)currentPath { + return _currentPath; +} + +- (void)changeCurrentPath:(NSString *)path { + NSAssert(path, @"current path could not be nil"); + BOOL isDir = NO; + if (![_fileManager fileExistsAtPath:path isDirectory:&isDir] || !isDir) { + NSAssert(NO, @"%@ not exists or is not a directory", path); + return; + } + + _currentPath = path; +} + +- (NSArray *)resourcePaths { + return [_resourcePaths copy]; +} + +- (void)addResourcePath:(NSString *)path { + NSAssert(path, @"path could not be nil"); + + [_resourcePaths insertObject:path atIndex:0]; +} + +- (void)removeResourcePath:(NSString *)path { + NSAssert(path, @"path could not be nil"); + + [_resourcePaths removeObject:path]; +} + +- (NSArray *)scriptPaths { + return [_scriptPaths copy]; +} + +- (void)addScriptPath:(NSString *)path { + NSAssert(path, @"path could not be nil"); + + [_scriptPaths insertObject:path atIndex:0]; +} + +- (void)removeScriptPath:(NSString *)path { + NSAssert(path, @"path could not be nil"); + + [_scriptPaths removeObject:path]; +} + +- (NSString *)absolutePath:(NSString *)path { + if (path == nil) { + return nil; + } else if ([path hasPrefix:@"/"]) { + return path; + } else { + return [_currentPath stringByAppendingPathComponent:path]; + } +} + +- (NSString *)resourcePathWithName:(NSString *)name { + if (name == nil) { + return nil; + } + + NSString *fullPath = nil; + for (NSString *dir in _resourcePaths) { + fullPath = [self absolutePath:[dir stringByAppendingPathComponent:name]]; + if ([_fileManager fileExistsAtPath:fullPath]) { + return fullPath; + } + } + + return nil; +} + +- (NSData *)resourceWithName:(NSString *)name { + if (name == nil) { + return nil; + } + + NSString *path = [self resourcePathWithName:name]; + if (path == nil) { + return nil; + } + + return [_fileManager contentsAtPath:path]; +} + +- (UIImage *)imageWithName:(NSString *)name { + if (name == nil) { + return nil; + } + UIImage* image = self.imageCaches[name]; + if( image ) { + return image; + } + NSString *path = [self resourcePathWithName:name]; + if( path ) { + image = [UIImage imageWithContentsOfFile:path]; + } else { + image = [UIImage imageNamed:name]; + } + if( image ){ + self.imageCaches[name] = image; + } + return image; +} + +- (NSString *)scriptPathWithName:(NSString *)name { + if (name == nil) { + return nil; + } + + NSString *ext = [name pathExtension]; + if (ext == nil || + !([LVScriptExts[0] isEqualToString:ext] || [LVScriptExts[1] isEqualToString:ext])) { + + NSAssert(nil, @"LuaView: %@ file is not supported!", ext); + return nil; + } + + NSString *fullPath = nil; + for (NSString *dir in _scriptPaths) { + fullPath = [self absolutePath:[dir stringByAppendingPathComponent:name]]; + if ([_fileManager fileExistsAtPath:fullPath]) { + return fullPath; + } + } + + return name; +} + +- (NSData *)scriptWithName:(NSString *)name { + if (name == nil) { + return nil; + } + NSAssert([[name pathExtension] isEqualToString:LVScriptExts[!LVSignedScriptExtIndex]], + @"%@ is not normal script", name); + + NSString *fullPath = [self scriptPathWithName:name]; + if (fullPath == nil) { + return nil; + } + + return [LVUtil dataReadFromFile:fullPath]; +} + +- (NSData *)signedScriptWithName:(NSString *)name rsa:(LVRSA *)rsa { + if (name == nil) { + return nil; + } + + NSAssert([[name pathExtension] isEqualToString:LVScriptExts[LVSignedScriptExtIndex]], + @"%@ is not signed script", name); + + NSString *fullPath = [self scriptPathWithName:name]; + if (fullPath == nil) { + return nil; + } + + return [LVPkgManager readLuaFile:fullPath rsa:rsa]; +} + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LView.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LView.h new file mode 100644 index 00000000..196dad6c --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LView.h @@ -0,0 +1,29 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import + +#import "LuaView.h" +#pragma mark -LuaView 类加载脚本调用接口 +@interface LView : LuaView + +@property (nonatomic,assign) BOOL changeGrammar;// 是否需要语法转换(原先luaview语法和lua标准语法的区别是‘.’和':'互换了),默认是非标准语法,需要转换 + +@property (nonatomic,assign) BOOL checkDebugerServer; // 是否检查调试器 + +// 设置证书地址 +- (void) setPublicKeyFilePath:(NSString*) filePath; + +-(LVBlock*) getLuaBlock:(NSString*) name; + +-(NSString*) callLua:(NSString*) functionName tag:(id) tag environment:(UIView*)environment args:(NSArray*) args; +-(NSString*) callLua:(NSString*) functionName environment:(UIView*) environment args:(NSArray*) args; +-(NSString*) callLua:(NSString*) functionName args:(NSArray*) args; + +@end + diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LView.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LView.m new file mode 100644 index 00000000..8aa0bb75 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LView.m @@ -0,0 +1,47 @@ + +#import "LView.h" +#import "LVRSA.h" + + +@implementation LView + + +-(BOOL) changeGrammar{ + return self.luaviewCore.changeGrammar; +} + +-(void) setChangeGrammar:(BOOL)changeGrammar{ + self.luaviewCore.changeGrammar = changeGrammar; +} + +-(BOOL) checkDebugerServer{ + return self.luaviewCore.checkDebugerServer; +} + +-(void) setCheckDebugerServer:(BOOL)checkDebugerServer{ + self.luaviewCore.checkDebugerServer = checkDebugerServer; +} + +// 设置证书地址 +- (void) setPublicKeyFilePath:(NSString*) filePath{ + [self.luaviewCore.rsa setPublicKeyFilePath:filePath]; +} + +-(NSString*) callLua:(NSString*) functionName tag:(id) tag environment:(UIView*)environment args:(NSArray*) args{ + return [self.luaviewCore callLua:functionName tag:tag environment:environment args:args]; +} + +-(NSString*) callLua:(NSString*) functionName environment:(UIView*) environment args:(NSArray*) args{ + return [self.luaviewCore callLua:functionName environment:environment args:args]; +} + +-(NSString*) callLua:(NSString*) functionName args:(NSArray*) args{ + return [self.luaviewCore callLua:functionName args:args]; +} + +-(LVBlock*) getLuaBlock:(NSString*) name{ + return [self.luaviewCore getLuaBlock:name]; +} + + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LViewController.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LViewController.h new file mode 100644 index 00000000..b0dd9658 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LViewController.h @@ -0,0 +1,33 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import + + +@class LuaView; + +typedef void(^LuaViewRegister)(LuaView* lv); + +@interface LViewController : UIViewController + +@property(nonatomic, readonly) LuaView *lv; +@property(nonatomic, readonly) NSString *mainScriptName; +@property(nonatomic, readonly) NSString *packagePath; + ++ (void)disableReloadKeyCommand:(BOOL)disable; + +- (instancetype)initWithPackage:(NSString *)path mainScript:(NSString *)scriptName; + +- (void)willCreateLuaView; +- (void)didCreateLuaView:(LuaView *) view; +- (void)willDestroyLuaView:(LuaView *) view; +- (void)didDestroyLuaView; + +@property(nonatomic,copy) LuaViewRegister luaviewRegister; + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LViewController.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LViewController.m new file mode 100644 index 00000000..d6dcf2dd --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LViewController.m @@ -0,0 +1,175 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LViewController.h" +#import "LuaView.h" +#import "LVUtil.h" + +#if DEBUG +#define LV_LOCAL_DEBUG 1 +#endif + +@interface LViewController () + +@property (nonatomic, strong) LuaView *lv; + +@property (nonatomic, strong) NSString *packagePath, *mainScriptName; + +@end + +static BOOL __disableReloadKeyCommand = NO; + +@implementation LViewController + ++ (void)disableReloadKeyCommand:(BOOL)disable { + __disableReloadKeyCommand = disable; +} + +- (instancetype)initWithPackage:(NSString *)path mainScript:(NSString *)scriptName { + if (self = [super init]) { + _packagePath = path; + _mainScriptName = scriptName; + } + + return self; +} + +-(void) dealloc{ + [self.lv releaseLuaView]; + self.lv = nil; +} + +- (void)viewDidLoad { + [super viewDidLoad]; + self.automaticallyAdjustsScrollViewInsets = NO; + self.edgesForExtendedLayout = UIRectEdgeNone; + + [self createLuaView]; +} + +- (BOOL)canBecomeFirstResponder { + return YES; +} + +#pragma mark - rewarding methods + +// TODO: reward memory warning + +- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event { + [self.lv motionBegan:motion withEvent:event]; +} + +- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event { + [self.lv motionCancelled:motion withEvent:event]; +} + +- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event { + [self.lv motionEnded:motion withEvent:event]; +} + +-(void) viewWillAppear:(BOOL)animated{ + [super viewWillAppear:animated]; + [self.navigationController setNavigationBarHidden:NO animated:YES]; + + [self.lv viewWillAppear]; +} + +-(void) viewDidAppear:(BOOL)animated{ + [super viewDidAppear:animated]; + [self becomeFirstResponder]; + + [self.lv viewDidAppear]; +} + +-(void) viewWillDisappear:(BOOL)animated{ + [super viewWillDisappear:animated]; + [self.lv viewWillDisAppear]; +} + +-(void) viewDidDisappear:(BOOL)animated{ + [super viewDidDisappear:animated]; + [self.lv viewDidDisAppear]; +} + +#pragma mark - luaview life cycle + +- (void)rebuildLuaView { + [self destroyLuaView]; + [self createLuaView]; +} + +- (void)createLuaView { + [self willCreateLuaView]; + + CGRect rect = self.view.bounds; + + self.lv = [[LuaView alloc] initWithFrame:rect]; + self.lv.viewController = self; + + if( self.luaviewRegister ) { + self.luaviewRegister(self.lv); + } + + [self didCreateLuaView:self.lv]; + + [self.view addSubview:self.lv]; + + [self runLocalPackage:self.packagePath mainScript:self.mainScriptName]; +} + +- (void)destroyLuaView { + [self willDestroyLuaView:self.lv]; + + [self.lv releaseLuaView]; + self.lv = nil; + + [self didDestroyLuaView]; +} + +- (void)runLocalPackage:(NSString *)packagePath mainScript:(NSString *)scriptName { + if (packagePath) { + [self.lv.bundle addScriptPath:packagePath]; + [self.lv.bundle addResourcePath:packagePath]; + } + [self.lv runFile:scriptName ?: @"main.lua"]; +} + +- (void)willCreateLuaView { } + +- (void)didCreateLuaView:(LView *)view { } + +- (void)willDestroyLuaView:(LView *)view { } + +- (void)didDestroyLuaView { } + +#pragma mark - debug + +#if LV_LOCAL_DEBUG + +/* + * Cmd + r 没有刷新时需要做如下设置: + * simulator -> Hardware -> Keyboard -> Connect Hardware Keyboard + * + * https://github.com/facebook/react-native/issues/306#issuecomment-86834162 + */ +- (NSArray *)keyCommands { + if (__disableReloadKeyCommand) { + return nil; + } + + UIKeyCommand *reloadKeyCommand = [UIKeyCommand + keyCommandWithInput:@"r" + modifierFlags:UIKeyModifierCommand + action:@selector(rebuildLuaView)]; + + return @[reloadKeyCommand]; +} + +#endif // LV_LOCAL_DEBUG + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LuaView.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LuaView.h new file mode 100644 index 00000000..8415b1dc --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LuaView.h @@ -0,0 +1,122 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LuaViewCore.h" + + +@class LuaView; + +#pragma mark - LuaView窗口大小变动回调 +@protocol LVCallback +- (void) luaviewFrameDidChange:(LuaView *)lView; +@end + + +@interface LuaView : UIView + +@property (nonatomic,weak) UIViewController* viewController;// 所在的ViewController +@property (nonatomic,strong) LVBundle* bundle; + +@property(nonatomic,weak) id callback; //用于LuaView回调( luaView大小改变 等回调) +@property (nonatomic,strong) LuaViewCore* luaviewCore; +@property (nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; + +-(void) viewWillAppear; +-(void) viewDidAppear; +-(void) viewWillDisAppear; +-(void) viewDidDisAppear; + +#pragma mark - 摇一摇回调 +// 摇一摇开始摇动 +- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event; +// 摇一摇取消摇动 +- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event; +// 摇一摇摇动结束 +- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event; + +-(void) releaseLuaView; + + +// + +/** + * load and run script + * + * @param fileName 本地文件名 + * + * @return 返回运行结果 + */ +-(NSString*) runFile:(NSString*) fileName; + +/** + * 运行一个包, main.lv是主入口 + * + * @param fileName 本地文件名 + * + * @return 返回运行结果 + */ +-(NSString*) runPackage:(NSString*) packageName; + +/** + * 运行一个包, main.lv是主入口 + * + * @param fileName 本地文件名 + * @args args 参数 + * + * @return 返回运行结果 + */ +-(NSString*) runPackage:(NSString*) packageName args:(NSArray*) args; + +/** + * 运行签名的脚本文件 + * + * @param fileName 本地文件名 + * + * @return 返回运行结果 + */ +-(NSString*) runSignFile:(NSString*) fileName; + +/** + * load and run script + * + * @param chars 脚本字符流 + * @param length 脚本字符流的长度 + * @param fileName 文件名,用于出错提示, 可以为空 + * + * @return 运行结果 + */ +-(NSString*) runData:(NSData*) data fileName:(NSString*) fileName; + +-(NSString*) runData:(NSData*) data fileName:(NSString*) fileName changeGrammar:(BOOL) changeGrammar; + +/** + * 加载签名的脚本文件,读取文件并调用lvL_loadbuffer + * + * @param fileName 本地文件名 + * + * @return 返回错误描述 + */ +-(NSString*) loadSignFile:(NSString *)fileName; + +/** + * 加载脚本文件,读取文件并调用lvL_loadbuffer + * + * @param fileName 本地文件名 + * + * @return 返回错误描述 + */ +-(NSString*) loadFile:(NSString *)fileName; + +- (void) setObject:(id)object forKeyedSubscript:(NSObject *)key; + + +-(lua_State*) l; // 获取 lua 状态机 + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LuaView.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LuaView.m new file mode 100644 index 00000000..bf51073b --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LuaView.m @@ -0,0 +1,346 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LuaView.h" +#import "LuaViewCore.h" + +@interface LuaView () +@property (nonatomic,assign) BOOL isOnShowed; +@end + +@implementation LuaView + + + +-(id) init{ + self = [super init]; + if( self ) { + } + return self; +} + +-(id) initWithFrame:(CGRect)frame{ + self = [super initWithFrame:frame]; + if( self ) { + [self createLuaViewCore]; + } + return self; +} + +/* + * 初始化LuaViewCore + */ +-(void) createLuaViewCore{ + self.luaviewCore = [[LuaViewCore alloc] init]; + [self.luaviewCore pushWindow:self]; + self.backgroundColor = [UIColor clearColor]; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(keyboardWillShow:) + name:UIKeyboardWillShowNotification + object:nil]; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(keyboardDidShow:) + name:UIKeyboardDidShowNotification + object:nil]; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(keyboardWillHide:) + name:UIKeyboardWillHideNotification + object:nil]; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(keyboardDidHide:) + name:UIKeyboardDidHideNotification + object:nil]; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(onForeground) + name:UIApplicationDidBecomeActiveNotification + object:nil]; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(onBackground) + name:UIApplicationDidEnterBackgroundNotification + object:nil]; +} + +-(void) dealloc{ + [[NSNotificationCenter defaultCenter] removeObserver:self]; +} + +-(UIViewController*) viewController{ + return self.luaviewCore.viewController; +} + +-(void) setViewController:(UIViewController *)viewController{ + self.luaviewCore.viewController = viewController; +} + +-(LVBundle*) bundle{ + return self.luaviewCore.bundle; +} + +-(void) setBundle:(LVBundle *)bundle{ + self.luaviewCore.bundle = bundle; +} + +-(void) releaseLuaView{ + [self.luaviewCore releaseLuaView]; +} + + +/** + * load and run script + * + * @param fileName 本地文件名 + * + * @return 返回运行结果 + */ +-(NSString*) runFile:(NSString*) fileName{ + return [self.luaviewCore runFile:fileName]; +} + +/** + * 运行一个包, main.lv是主入口 + * + * @param fileName 本地文件名 + * + * @return 返回运行结果 + */ +-(NSString*) runPackage:(NSString*) packageName{ + return [self.luaviewCore runPackage:packageName]; +} + +/** + * 运行一个包, main.lv是主入口 + * + * @param fileName 本地文件名 + * @args args 参数 + * + * @return 返回运行结果 + */ +-(NSString*) runPackage:(NSString*) packageName args:(NSArray*) args{ + return [self.luaviewCore runPackage:packageName args:args]; +} + +/** + * 运行签名的脚本文件 + * + * @param fileName 本地文件名 + * + * @return 返回运行结果 + */ +-(NSString*) runSignFile:(NSString*) fileName{ + return [self.luaviewCore runSignFile:fileName]; +} + +/** + * load and run script + * + * @param chars 脚本字符流 + * @param length 脚本字符流的长度 + * @param fileName 文件名,用于出错提示, 可以为空 + * + * @return 运行结果 + */ +-(NSString*) runData:(NSData*) data fileName:(NSString*) fileName{ + return [self.luaviewCore runData:data fileName:fileName]; +} + +-(NSString*) runData:(NSData*) data fileName:(NSString*) fileName changeGrammar:(BOOL) changeGrammar{ + return [self.luaviewCore runData:data fileName:fileName changeGrammar:changeGrammar]; +} + +/** + * 加载签名的脚本文件,读取文件并调用lvL_loadbuffer + * + * @param fileName 本地文件名 + * + * @return 返回错误描述 + */ +-(NSString*) loadSignFile:(NSString *)fileName{ + return [self.luaviewCore loadSignFile:fileName]; +} + +/** + * 加载脚本文件,读取文件并调用lvL_loadbuffer + * + * @param fileName 本地文件名 + * + * @return 返回错误描述 + */ +-(NSString*) loadFile:(NSString *)fileName{ + return [self.luaviewCore loadFile:fileName]; +} + +-(void) setFrame:(CGRect)frame{ + [super setFrame:frame]; + [self.callback luaviewFrameDidChange:self]; +} + +- (void)setObject:(id)object forKeyedSubscript:(NSObject *)key{ + [self.luaviewCore setObject:object forKeyedSubscript:key]; +} + + +#pragma mark - view appear + +-(void) viewWillAppear{ + lua_State* L = self.luaviewCore.l; + if( L ) { + lua_checkstack32(L); + [self lv_callLuaByKey1:@"ViewWillAppear"]; + } +} + +-(void) viewDidAppear{ + self.isOnShowed = YES; + lua_State* L = self.luaviewCore.l; + if( L ) { + lua_checkstack32(L); + [self lv_callLuaByKey1:@"onShow"];//@"ViewDidAppear" + } +} + +-(void) viewWillDisAppear{ + lua_State* L = self.luaviewCore.l; + if( L ) { + lua_checkstack32(L); + [self lv_callLuaByKey1:@"ViewWillDisAppear"]; + } +} + +-(void) viewDidDisAppear{ + self.isOnShowed = NO; + lua_State* L = self.luaviewCore.l; + if( L ) { + lua_checkstack32(L); + [self lv_callLuaByKey1:@"onHide"];//@"ViewDidDisAppear" + } +} + +-(void) onForeground { + lua_State* L = self.luaviewCore.l; + if( L && self.isOnShowed ) { + lua_checkstack32(L); + lua_pushboolean(L, YES); + [self lv_callLuaByKey1:@"onShow" key2:nil argN:1]; + } +} + +-(void) onBackground { + lua_State* L = self.luaviewCore.l; + if( L && self.isOnShowed ) { + lua_checkstack32(L); + lua_pushboolean(L, YES); + [self lv_callLuaByKey1:@"onHide" key2:nil argN:1]; + } +} + +- (void)didMoveToSuperview{ + [super didMoveToSuperview]; + + lua_State* L = self.luaviewCore.l; + if( L ) { + lua_checkstack32(L); + [self lv_callLuaByKey1:@"DidMoveToSuperview"]; + } +} + +- (void)didMoveToWindow{ + [super didMoveToWindow]; + + lua_State* L = self.luaviewCore.l; + if( L ) { + lua_checkstack32(L); + [self lv_callLuaByKey1:@"DidMoveToSuperview"]; + } +} + +-(void) layoutSubviews{ + [super layoutSubviews]; + + lua_State* L = self.luaviewCore.l; + if( L ) { + lua_checkstack32(L); + [self lv_callLuaByKey1:@STR_ON_LAYOUT]; + } +} + + +#pragma mark - keyboard + +-(void) keyboardWillShow:(NSNotification *)notification { + lua_State* L = self.luaviewCore.l; + if( L ) { + lua_checkstack32(L); + [self lv_callLuaByKey1:@"KeyboardWillShow"]; + } +} +-(void) keyboardDidShow:(NSNotification *)notification { + lua_State* L = self.luaviewCore.l; + if( L ) { + lua_checkstack32(L); + [self lv_callLuaByKey1:@"KeyboardDidShow"]; + } +} +-(void) keyboardWillHide:(NSNotification *)notification { + lua_State* L = self.luaviewCore.l; + if( L ) { + lua_checkstack32(L); + [self lv_callLuaByKey1:@"KeyboardWillHide"]; + } +} +-(void) keyboardDidHide:(NSNotification *)notification { + lua_State* L = self.luaviewCore.l; + if( L ) { + lua_checkstack32(L); + [self lv_callLuaByKey1:@"KeyboardDidHide"]; + } +} + +#pragma mark - 摇一摇相关方法 +// 摇一摇开始摇动 +- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event { + lua_State* L = self.luaviewCore.l; + if (event.subtype == UIEventSubtypeMotionShake) { + if( L ) { + lua_checkstack32(L); + [self lv_callLuaByKey1:@"ShakeBegin"]; + } + } +} + +// 摇一摇取消摇动 +- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event { + if (event.subtype == UIEventSubtypeMotionShake) { + lua_State* L = self.luaviewCore.l; + if( L ) { + lua_checkstack32(L); + [self lv_callLuaByKey1:@"ShakeCanceled"]; + } + } +} + +// 摇一摇摇动结束 +- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event { + if (event.subtype == UIEventSubtypeMotionShake) { + lua_State* L = self.luaviewCore.l; + if( L ) { + lua_checkstack32(L); + [self lv_callLuaByKey1:@"ShakeEnded"]; + } + } +} + +-(lua_State*) l{ + return self.luaviewCore.l; +} + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LuaViewCore.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LuaViewCore.h new file mode 100644 index 00000000..fc1baeba --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LuaViewCore.h @@ -0,0 +1,242 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" +#import "LVDebugConnection.h" + + +@class LView; +@class LVBlock; +@class LVBundle; +@protocol LVProtocal; + + +#pragma mark -LuaView 类加载脚本调用接口 +@interface LuaViewCore : NSObject + +@property (nonatomic,strong) LVRSA* rsa; + +@property (nonatomic,strong) LVBundle* bundle; + +/** + * 是否需要语法转换(原先luaview语法和lua标准语法的区别是‘.’和':'互换了),默认是标准语法,使用非标准语法需要转换成标准语法才设置成true + */ +@property (nonatomic,assign) BOOL changeGrammar; + +//--------------------------------------------------------------------- +/** +* 调试开关 +* +*/ +@property (nonatomic,assign) BOOL checkDebugerServer; // 是否检查调试器 +// @property (nonatomic,assign) BOOL openDebugger; // 开启调试 + + +//--------------------------------------------------------------------- +/** +* 加载脚本文件,读取文件并调用lvL_loadbuffer +* +* @param fileName 本地文件名 +* +* @return 返回错误描述 +*/ +-(NSString*) loadFile:(NSString *)fileName; + +/** +* 加载签名的脚本文件,读取文件并调用lvL_loadbuffer +* +* @param fileName 本地文件名 +* +* @return 返回错误描述 +*/ +-(NSString*) loadSignFile:(NSString *)fileName; + +/** + * 加载代码String + */ +- (NSString*) loadScript:(NSString*)script fileName:(NSString *)fileNam; + +/** +* 加载代码data +*/ +- (NSString*) loadData:(NSData *)data fileName:(NSString *)fileNam; + +/** +* load and run script +* +* @param fileName 本地文件名 +* +* @return 返回运行结果 +*/ +-(NSString*) runFile:(NSString*) fileName; + +/** +* 运行一个包, main.lv是主入口 +* +* @param fileName 本地文件名 +* +* @return 返回运行结果 +*/ +-(NSString*) runPackage:(NSString*) packageName; + +/** +* 运行一个包, main.lv是主入口 +* +* @param fileName 本地文件名 +* @args args 参数 +* +* @return 返回运行结果 +*/ +-(NSString*) runPackage:(NSString*) packageName args:(NSArray*) args; + +/** + * 加载包 + */ +- (NSString*) loadPackage:(NSString*) packageName; + +/** +* 运行签名的脚本文件 +* +* @param fileName 本地文件名 +* +* @return 返回运行结果 +*/ +-(NSString*) runSignFile:(NSString*) fileName; + +/** +* load and run script +* +* @param chars 脚本字符流 +* @param length 脚本字符流的长度 +* @param fileName 文件名,用于出错提示, 可以为空 +* +* @return 运行结果 +*/ +-(NSString*) runData:(NSData*) data fileName:(NSString*) fileName; + +-(NSString*) runData:(NSData*) data fileName:(NSString*) fileName changeGrammar:(BOOL) changeGrammar; + +/** +* +*调用lua脚本, functionName:lua的function名称, environment:运行窗口, args:传递参数 +* +*/ +-(NSString*) callLua:(NSString*) functionName tag:(id) tag environment:(UIView*)environment args:(NSArray*) args; +-(NSString*) callLua:(NSString*) functionName environment:(UIView*) environment args:(NSArray*) args; +-(NSString*) callLua:(NSString*) functionName args:(NSArray*) args; +-(LVBlock*) getLuaBlock:(NSString*) name; + +/** +* 释放虚拟机回收luaView +*/ +-(void) releaseLuaView; + +/** +* Layer模式优化性能 +*/ +@property (nonatomic,assign) BOOL closeLayerMode; + + +/** +* 图片首次出现是否使用动画 +*/ +@property (nonatomic,assign) BOOL disableAnimate; + +@property(nonatomic,copy) NSArray* registerClasses; + +@property (nonatomic,weak) UIViewController* viewController;// 所在的ViewController + +@end + + +#pragma mark - 设置资源搜索路径 +@interface LuaViewCore () + + +/* + * packageName: 包名 比如:"ppt" + * info格式: { "url" : "http://g.tbcdn.cn/ju/lua/3.2.12/ppt4.4.0.js" , "time":"2015-11-18 09:53"} + */ ++(void) downloadPackage:(NSString*)package withInfo:(NSDictionary*)info; + +@end + +#pragma mark - Register 注册外部api接口 +@interface LuaViewCore () + +- (void) setObject:(id)object forKeyedSubscript:(NSObject *)key; +- (void) registerObject:(id) object forName:(NSString*) name sel:(SEL) sel;// 只注册指定API +- (void) registerObject:(id) object forName:(NSString*) name sel:(SEL) sel weakMode:(BOOL) weakMode;// 只注册指定API +- (void) registerObject:(id) object forName:(NSString*) name;// 注册改对象的所有api +- (void) registerObject:(id) object forName:(NSString*) name weakMode:(BOOL) weakMode;// 注册改对象的所有api +- (void) unregisteObjectForName:(NSString*) name;// 取消注册对象 + + +- (void) registerLibs:(id) lib; +- (void) registerName:(NSString*) name withObject:(id) object; +- (void) registerPanel:(id) panel; +- (void) registerPanel:(id) panel forName:(NSString*) name; +- (void) unregister:(NSString*) name; + +@end + + + +#pragma mark - LViewBlock lua闭包参数获取使用 +@interface LuaViewCore () + +- (BOOL) argumentToBool:(int) index; +- (double) argumentToNumber:(int) index; +- (id) argumentToObject:(int) index; + +@end + + +#pragma mark - debugger 只是调试工具使用 +@interface LuaViewCore () + +-(void) callLuaToExecuteServerCmd; +@property (nonatomic,strong) LVDebugConnection* debugConnection; + +@end + + +#pragma mark - Property 系统使用的, 基本上不用关心细节 +@interface LuaViewCore () +@property (nonatomic,assign) BOOL runInSignModel;// 加密模式,优先加载加密脚本 +@property (nonatomic, weak) LuaViewCore* lv_luaviewCore; +@property (nonatomic, assign) LVUserDataInfo* lv_userData;// 脚本中的window对象 数据绑定 +@property (nonatomic, assign) lua_State* l; // lua 状态机 + +-(void) containerAddSubview:(UIView *)view; + + +@end + + + +//------------ 窗口渲染接口, 必须成对出现! 慎用! ------------------------------ +@interface LuaViewCore () +/** + * 渲染窗口 压栈 + * + */ +-(void) pushWindow:(UIView*) window; +-(void) pushRenderTarget:(UIView*) window; + +/** + * 渲染窗口 出栈 + */ +-(void) popWindow:(UIView*) window; +-(void) popRenderTarget:(UIView*) window; + +-(void) luaviewGC; + +@end + diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LuaViewCore.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LuaViewCore.m new file mode 100644 index 00000000..89835cc2 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/LuaViewCore.m @@ -0,0 +1,653 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LuaViewCore.h" + + +#import "LuaViewCore.h" +#import "LVHeads.h" +#import "LVExGlobalFunc.h" +#import "LVTimer.h" +#import "LVDebuger.h" +#import "LVNativeObjBox.h" +#import "LVBlock.h" +#import "LVPkgManager.h" +#import "UIView+LuaView.h" +#import "LVDebugConnection.h" +#import "LVDebugConnection.h" +#import "LVCustomPanel.h" +#import +#import "LVRSA.h" +#import "LVBundle.h" +#import "LVButton.h" +#import "LVScrollView.h" +#import "LVTimer.h" +#import "LVUtil.h" +#import "LVPagerIndicator.h" +#import "LVLoadingIndicator.h" +#import "LVImage.h" +#import "LVWebView.h" +#import "LVLabel.h" +#import "LVBaseView.h" +#import "LVTransform3D.h" +#import "LVTextField.h" +#import "LVAnimate.h" +#import "LVAnimator.h" +#import "LVDate.h" +#import "LVAlert.h" +#import "LVSystem.h" +#import "LVDB.h" +#import "LVGesture.h" +#import "LVTapGesture.h" +#import "LVPanGesture.h" +#import "LVPinchGesture.h" +#import "LVRotationGesture.h" +#import "LVHttp.h" +#import "LVData.h" +#import "LVSwipeGesture.h" +#import "LVLongPressGesture.h" +#import "LVDebuger.h" +#import "LVDownloader.h" +#import "LVAudioPlayer.h" +#import "LVFile.h" +#import "LVStyledString.h" +#import "LVNativeObjBox.h" +#import "LVCollectionView.h" +#import "LVEmptyRefreshCollectionView.h" +#import "LVStruct.h" +#import "LVNavigation.h" +#import "LVCustomPanel.h" +#import "LVCustomView.h" +#import "LVPagerView.h" +#import "LVCanvas.h" +#import "LVEvent.h" + +@interface LuaViewCore () +@property (nonatomic,strong) id mySelf; +@property (nonatomic,assign) BOOL stateInited; +@property (nonatomic,assign) BOOL loadedDebugScript; +@property (atomic,assign) NSInteger callLuaTimes; +@property(nonatomic,weak) UIView* window; +@property (nonatomic,assign) int windowIdx; +@end + +@implementation LuaViewCore + +-(id) init{ + self = [super init]; + if( self ){ + [self myInit]; + [self registeLibs]; + } + return self; +} + +#pragma mark - init + +-(void) myInit{ + self.checkDebugerServer = YES; + self.disableAnimate = YES; + self.closeLayerMode = YES; + self.mySelf = self; + + + self.lv_luaviewCore = self; + self.rsa = [[LVRSA alloc] init]; + self.bundle = [[LVBundle alloc] init]; +} + +-(void) dealloc{ + [self.debugConnection closeAll]; +} + +#pragma mark - run +-(NSString*) runFile:(NSString*) fileName{ + self.runInSignModel = FALSE; + NSData* code = [self.bundle scriptWithName:fileName]; + + return [self runData:code fileName:fileName]; +} + +-(NSString*) runSignFile:(NSString*) fileName{ + self.runInSignModel = TRUE; + NSData* code = [self.bundle signedScriptWithName:fileName rsa:self.rsa]; + + return [self runData:code fileName:fileName]; +} + +- (NSString*) loadPackage:(NSString*) packageName{ + return [self runPackage:packageName]; +} + +-(NSString*) runPackage:(NSString*) packageName { + return [self runPackage:packageName args:nil]; +} + +-(NSString*) runPackage:(NSString*) packageName args:(NSArray*) args{ + self.runInSignModel = TRUE; + + NSString *packagePath = [LVPkgManager rootDirectoryOfPackage:packageName]; + [self.bundle addScriptPath:packagePath]; + [self.bundle addResourcePath:packagePath]; + + self.changeGrammar = [[LVPkgManager changeGrammarOfPackage:packageName] isEqualToString:@"true"]; + + NSString* fileName = @"main.lv"; + NSString* ret = [self runSignFile:fileName]; + lua_State* L = self.l; + if( ret==nil && L ) { + for( int i=0; i0 ) { + if( self.loadedDebugScript == NO ) { + self.loadedDebugScript = YES; + [self.debugConnection sendCmd:@"log" info:@"[LuaView][调试日志] 开始调试!\n"]; + [self loadDebugModel];// 加载调试模块 + } + } +} +#else +- (void) callLuaToExecuteServerCmd{ +} +#endif + +static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) { + (void)ud; + (void)osize; + if (nsize == 0) { + free(ptr); + return NULL; + } else { + return realloc(ptr, nsize); + } +} + + +-(void) registeLibs{ + if( !self.stateInited ) { + self.stateInited = YES; + self.l = lua_newstate(l_alloc, (__bridge void *)(self)); + luaL_openlibs(self.l); + NSArray* arr = nil; + arr = @[ + [LVSystem class], + [LVData class], + [LVStruct class], + [LVBaseView class], + [LVButton class], + [LVImage class], + [LVWebView class], + [LVLabel class], + [LVScrollView class], + [LVCollectionView class], + [LVEmptyRefreshCollectionView class], + [LVPagerView class], + [LVCustomView class], + [LVCanvas class], + [LVEvent class], + [LVTimer class], + [LVPagerIndicator class], + [LVCustomPanel class], + [LVTransform3D class], + [LVAnimator class], + [LVTextField class], + [LVAnimate class], + [LVDate class], + [LVAlert class], + [LVDB class], + [LVGesture class], + [LVTapGesture class], + [LVPinchGesture class], + [LVRotationGesture class], + [LVSwipeGesture class], + [LVLongPressGesture class], + [LVPanGesture class], + [LVLoadingIndicator class], + [LVHttp class], + [LVDownloader class], + [LVFile class], + [LVAudioPlayer class], + [LVStyledString class], + [LVNavigation class], + [LVExGlobalFunc class], + [LVNativeObjBox class], + [LVDebuger class], + ]; + self.registerClasses = arr; + [self registerAllClass]; + + // 默认支持RefreshCollectionView + self[@"RefreshCollectionView"] = [LVCollectionView class]; + } +} + +-(void) registerAllClass{ + lua_State* L = self.l; + //清理栈 + for( NSInteger i =0; i *)key{ + lua_State* L = self.l; + if ( L ==nil ){ + LVError( @"Lua State is released !!!"); + return; + } + if( [key isKindOfClass:[NSString class]] && class_isMetaClass(object_getClass(object)) ) { + if( [object respondsToSelector:@selector(lvClassDefine:globalName:)] ) { + [object lvClassDefine:L globalName:(NSString*)key]; + return; + } + } + if ( [key isKindOfClass:[NSString class]] ){ + [LVNativeObjBox registeObjectWithL:L nativeObject:object name:(NSString*)key sel:nil weakMode:YES]; + } +} + +-(void) unregisteObjectForName:(NSString*) name{ + lua_State* L = self.l; + if ( L ==nil ){ + LVError( @"Lua State is released !!!"); + return ; + } + [LVNativeObjBox unregisteObjectWithL:L name:name]; +} + +- (void) registerLibs:(id) lib{ + lua_State* L = self.l; + if( [lib respondsToSelector:@selector(lvClassDefine:globalName:)] ) { + [lib lvClassDefine:L globalName:nil]; + return; + } +} + +- (void) registerName:(NSString*) name withObject:(id) object{ + [self registerObject:object forName:name]; +} + +- (void) registerPanel:(id) panel{ + [self registerPanel:panel forName:nil]; +} + +- (void) registerPanel:(id) panel forName:(NSString*) name{ + lua_State* L = self.l; + if( [panel respondsToSelector:@selector(lvClassDefine:globalName:)] ) { + [panel lvClassDefine:L globalName:name]; + return; + } +} + +- (void) unregister:(NSString*) name{ + [self unregisteObjectForName:name]; +} +#pragma mark - package + ++(void) downloadPackage:(NSString*)packageName withInfo:(NSDictionary*)info{ + [LVPkgManager downloadPackage:packageName withInfo:info]; +} + +-(BOOL) argumentToBool:(int) index{ + lua_State* L = self.l; + if ( L ) { + return lua_toboolean(L, index); + } + return NO; +} + +-(double) argumentToNumber:(int) index{ + lua_State* L = self.l; + if ( L ) { + return lua_tonumber(L, index); + } + return 0; +} + +-(id) argumentToObject:(int) index{ + lua_State* L = self.l; + if ( L ) { + return lv_luaValueToNativeObject(L, index); + } + return 0; +} + +-(void) containerAddSubview:(UIView *)view{ + lv_addSubview(self, self.window, view); +} + +-(void) createWindow:(UIView *)window{ + self.window = window; + [LVExGlobalFunc registry:self.l window:self.window]; +} + +-(const char*) windowName{ + const char* name = [NSString stringWithFormat:@"core.window.%d",self.windowIdx].UTF8String; + return name; +} + +-(void) pushRenderTarget:(UIView *)window{ + [self pushWindow:window]; +} + +-(void) pushWindow:(UIView*) window{ + lua_State* L = self.l; + lua_checkstack(L,8); + + // 老的window 压栈 + const char* newWindowName = [self windowName]; + lua_getglobal(L, "window"); + lua_setglobal(L, newWindowName); + self.windowIdx ++; + + // 创建新的window + [self createWindow:window];//创建window +} + +-(void) popRenderTarget:(UIView *)window{ + [self popWindow:window]; +} + +-(void) popWindow:(UIView*) window{ + if( self.window==window ) { + lua_State* L = self.l; + lua_checkstack(L,8); + self.windowIdx --; + const char* oldWindowName = [self windowName]; + + // 出栈 + lua_getglobal(L, oldWindowName); + lua_setglobal(L, "window"); + lua_getglobal(L, "window"); + + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, -1); + if( user ) { + self.window = (__bridge UIView *)(user->object); + } + } else { + LVError(@"pop window!!!!"); + } +} + +-(void) luaviewGC { + // 清理luaview对应的内存 + lua_State *state = self.l; + if (state) { + lua_checkstack(state, 8); + lua_pushnil(state); + [LVUtil registryValue:state key:self stack:-1]; + LVBlock *block = [self getLuaBlock:@"System.gc"]; + [block callWithArgs:nil]; + } +} + + +@end + diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/PKG/LVPkgInfo.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/PKG/LVPkgInfo.h new file mode 100644 index 00000000..2f7eb2df --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/PKG/LVPkgInfo.h @@ -0,0 +1,46 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import + +#define LV_PKGINFO_URL @"url" +#define LV_PKGINFO_URL2 @"luaview_script_url" +#define LV_PKGINFO_SHA @"sha" +#define LV_PKGINFO_SHA256 @"sha256" + +#define LV_PKGINFO_SURL @"surl" +#define LV_PKGINFO_SSHA @"ssha" +#define LV_PKGINFO_SSHA256 @"ssha256" + +#define LV_PKGINFO_PACKAGE @"package" + +@interface LVPkgInfo : NSObject + +@property(nonatomic,copy) NSDictionary* originalDic; // 原始信息 + +@property(nonatomic,copy) NSString* url; // 下载地址 +@property(nonatomic,copy) NSString* sha256; // sha256 +@property(nonatomic,copy) NSString* timestamp; // 版本对比时间戳 +@property(nonatomic,assign) BOOL changeGrammar; // 是否需要语法转换(‘:’和'.'互换) +@property(nonatomic,copy) NSString* package; // sha256 + +/* + * + * 解析字典 -> model + * + */ +-(instancetype) init:(NSDictionary*) dic; + +/* + * + * model -> 字典信息 + * + */ +- (NSDictionary*) dictionaryInfo; + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/PKG/LVPkgInfo.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/PKG/LVPkgInfo.m new file mode 100644 index 00000000..ce81e9d3 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/PKG/LVPkgInfo.m @@ -0,0 +1,98 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVPkgInfo.h" +#import "LVUtil.h" + +@implementation LVPkgInfo + +-(instancetype) init:(NSDictionary*) dic{ + self = [super init]; + if( self ) { + NSString* url = nil; + NSString* sha = nil; + + url = [LVPkgInfo safe_string:dic forKey:LV_PKGINFO_SURL]; + sha = [LVPkgInfo safe_string:dic forKey:LV_PKGINFO_SSHA key2:LV_PKGINFO_SSHA256]; + if( url && sha ) { + self.url = url; + self.sha256 = sha; + self.changeGrammar = NO; + } else { + self.url = [LVPkgInfo safe_string:dic forKey:LV_PKGINFO_URL key2:LV_PKGINFO_URL2]; + self.sha256 = [LVPkgInfo safe_string:dic forKey:LV_PKGINFO_SHA key2:LV_PKGINFO_SHA256]; + self.changeGrammar = YES; + } + self.url = [self stringByDecodingURLFormat:self.url]; // 下载地址可能需要解码 + self.url = [self addHttpPrefix:self.url];// 下载地址可能需要加https前缀 + self.package = [LVPkgInfo safe_string:dic forKey:LV_PKGINFO_PACKAGE]; + if( self.package.length<=0 && self.url) { + self.package = [LVUtil MD5HashFromData:[self.url dataUsingEncoding:NSUTF8StringEncoding]]; + } + self.timestamp = self.url;//时间戳 用下载地址标示 + self.originalDic = dic; + } + return self; +} + +-(NSString*) addHttpPrefix:(NSString*) url{ + if( [url rangeOfString:@"://"].length>0 ){ + return url; + } + if( [url hasPrefix:@"//"] ) { + return [NSString stringWithFormat:@"https:%@",url]; + } + return url; +} + +- (NSString *)stringByDecodingURLFormat:(NSString*) str +{ + NSString *result = [str stringByReplacingOccurrencesOfString:@"+" withString:@" "]; + //result = [result stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; + result = [result stringByRemovingPercentEncoding]; + return result; +} + +- (NSDictionary*) dictionaryInfo{ + if( self.url && self.sha256 && self.package ) { + if( self.changeGrammar ) { + return @{LV_PKGINFO_URL:self.url, + LV_PKGINFO_SHA:self.sha256, + LV_PKGINFO_PACKAGE:self.package}; + } else { + return @{LV_PKGINFO_SURL:self.url , + LV_PKGINFO_SSHA:self.sha256, + LV_PKGINFO_PACKAGE:self.package}; + } + } + return nil; +} + ++(NSString*) safe_string:(NSDictionary*) dic forKey:(NSString*) key { + return [self safe_string:dic forKey:key key2:nil]; +} + ++(NSString*) safe_string:(NSDictionary*) dic forKey:(NSString*) key1 key2:(NSString*) key2{ + if( [dic isKindOfClass:[NSDictionary class]] ) { + if( key1 ) { + NSString* s = dic[key1]; + if( [s isKindOfClass:[NSString class]] ) { + return s; + } + } + if( key2 ) { + NSString* s = dic[key2]; + if( [s isKindOfClass:[NSString class]] ) { + return s; + } + } + } + return nil; +} + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/PKG/LVPkgManager.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/PKG/LVPkgManager.h new file mode 100644 index 00000000..a7e091fe --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/PKG/LVPkgManager.h @@ -0,0 +1,62 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVPkgInfo.h" + +#define LUAVIEW_ROOT_PATH @"LUAVIEW_5_11_0" +#define LUAVIEW_VERSION "5.16.0" +#define LUAVIEW_SDK_VERSION "0.5.0" + + +extern NSString * const LV_FILE_NAME_OF_PACKAGE_DOWNLOAD_URL; +extern NSString * const LV_FILE_NAME_OF_PACKAGE_TIMESTAMP; +extern NSString * const LV_FILE_NAME_OF_CHANGE_GRAMMAR; + +@class LVRSA; + +typedef enum : NSUInteger { + LV_DOWNLOAD_ERROR = -1, + LV_DOWNLOAD_CACHE = 0 , + LV_DOWNLOAD_NET = 1, +} LVDownloadDataType; + +typedef void(^LVDownloadCallback)(NSDictionary* info, NSString* error, LVDownloadDataType dataType); + +@interface LVPkgManager : NSObject + ++ (NSString *)rootDirectoryOfPackage:(NSString *)packageName; ++ (NSString *)pathForFileName:(NSString *)fileName package:(NSString *)packageName; + +// 解压失败是-1, 无需解压本地更加新是0, 解压成功是1 ++(int) unpackageFile:(NSString*) fileName packageName:(NSString*) packageName changeGrammar:(BOOL) changeGrammar; ++(int) unpackageData:(NSData*) data packageName:(NSString*) packageName changeGrammar:(BOOL) changeGrammar; + +// 返回值说明 0:本地和线上版本一样; 1:即将去下载; -1:错误 ++(NSInteger) downloadPackage:(NSString*)packageName withInfo:(NSDictionary*) info; +// 返回值说明 0:本地和线上版本一样; 1:即将去下载; -1:错误 ++(NSInteger) downloadPackage:(NSString*)packageName withInfo:(NSDictionary*) info callback:(LVDownloadCallback) callback; + ++(NSData*) readLuaFile:(NSString*) fileName rsa:(LVRSA*) rsa; +// download url ++(NSString*) downloadUrlOfPackage:(NSString*)packageName; ++(BOOL) setPackage:(NSString*)packageName downloadUrl:(NSString*) downloadUrl; +// timestamp ++(NSString*) timestampOfPackage:(NSString*)packageName; ++(BOOL) setPackage:(NSString*)packageName timestamp:(NSString*) time; +// changeGrammar ++(NSString*) changeGrammarOfPackage:(NSString*)packageName; ++(BOOL) setPackage:(NSString*)packageName changeGrammar:(NSString*) timestamp; + +// 返回值说明 0:本地和线上版本一样; -1:错误或者不相等 ++(int) compareDownloadUrlOfPackage:(NSString*)name withServerInfo:(NSDictionary*) info; + +//清理所有LuaView相关文件 ++(void) clearCachesPath; + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/PKG/LVPkgManager.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/PKG/LVPkgManager.m new file mode 100644 index 00000000..258a4a59 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/PKG/LVPkgManager.m @@ -0,0 +1,301 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVPkgManager.h" +#import "LVUtil.h" +#import "LVRSA.h" +#import "LVZipArchive.h" +#import "zlib.h" + +NSString * const LV_FILE_NAME_OF_PACKAGE_DOWNLOAD_URL = @"___download_url___"; +NSString * const LV_FILE_NAME_OF_PACKAGE_TIMESTAMP = @"___timestamp___"; +NSString * const LV_FILE_NAME_OF_CHANGE_GRAMMAR = @"___change_grammar___"; + +@implementation LVPkgManager + ++ (NSString *)rootDirectoryOfPackage:(NSString *)packageName { + NSString *path = [NSString stringWithFormat:@"%@/%@",LUAVIEW_ROOT_PATH, packageName]; + return [LVUtil PathForCachesResource:path]; +} + ++ (NSString *)pathForFileName:(NSString *)fileName package:(NSString *)packageName { + return [[self rootDirectoryOfPackage:packageName] stringByAppendingPathComponent:fileName]; +} + +//------------------------------ write/read file for package --------------------------------- ++(BOOL) writeFile:(NSData*)data packageName:(NSString*)packageName fileName:(NSString*)fileName { + NSString* path = [self pathForFileName:fileName package:packageName]; + if( [LVUtil saveData:data toFile:path] ){ + LVLog (@"writeFile: %@, %d", fileName, (int)data.length); + return YES; + } else { + LVError(@"writeFile: %@, %d", fileName, (int)data.length); + return NO; + } +} + ++(NSData*) readFileFromPackage:(NSString*)packageName fileName:(NSString*)fileName { + NSString *path = [self pathForFileName:fileName package:packageName]; + NSData* data =[LVUtil dataReadFromFile:path]; + return data; +} + +//----------------------------------- timestamp path ----------------------------------------- ++(NSString*) filePathOfPackageDownloadUrl:(NSString *)packageName { + return [self pathForFileName:LV_FILE_NAME_OF_PACKAGE_DOWNLOAD_URL package:packageName]; +} ++(NSString*) filePathOfPackageTimestamp:(NSString *)packageName { + return [self pathForFileName:LV_FILE_NAME_OF_PACKAGE_TIMESTAMP package:packageName]; +} ++(NSString*) filePathOfChangeGrammar:(NSString *)packageName { + return [self pathForFileName:LV_FILE_NAME_OF_CHANGE_GRAMMAR package:packageName]; +} +//------------------------------------------------------------------------------------------ ++(BOOL) deleteFileOfPackageDownloadUrl:(NSString*) packageName{ + NSString* path = [self filePathOfPackageDownloadUrl:packageName]; + return [LVUtil deleteFile:path]; +} ++(BOOL) deleteFileOfPackageTimestamp:(NSString*) packageName{ + NSString* path = [self filePathOfPackageTimestamp:packageName]; + return [LVUtil deleteFile:path]; +} +//------------------------------------ read/write package download url ----------------------------------- ++(NSString*) downloadUrlOfPackage:(NSString*)packageName{ + NSData* data = [self readFileFromPackage:packageName fileName:LV_FILE_NAME_OF_PACKAGE_DOWNLOAD_URL]; + if( data ) { + return [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; + } else { + return nil; + } +} + ++(BOOL) setPackage:(NSString*)packageName downloadUrl:(NSString*) timestamp{ + NSData* data = [timestamp dataUsingEncoding:NSUTF8StringEncoding]; + return [self writeFile:data packageName:packageName fileName:LV_FILE_NAME_OF_PACKAGE_DOWNLOAD_URL]; +} +//------------------------------------ read/write package timestamp ----------------------------------- ++(NSString*) timestampOfPackage:(NSString*)packageName { + NSData* data = [self readFileFromPackage:packageName fileName:LV_FILE_NAME_OF_PACKAGE_TIMESTAMP]; + if( data ) { + return [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; + } else { + return nil; + } +} + ++(BOOL) setPackage:(NSString*)packageName timestamp:(NSString*) timestamp{ + // time file + NSData* data = [timestamp dataUsingEncoding:NSUTF8StringEncoding]; + return [self writeFile:data packageName:packageName fileName:LV_FILE_NAME_OF_PACKAGE_TIMESTAMP]; +} +//------------------------------------ read/write change grammar ----------------------------------- ++(NSString*) changeGrammarOfPackage:(NSString*)packageName { + NSData* data = [self readFileFromPackage:packageName fileName:LV_FILE_NAME_OF_CHANGE_GRAMMAR]; + if( data ) { + return [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; + } else { + return nil; + } +} + ++(BOOL) setPackage:(NSString*)packageName changeGrammar:(NSString*) timestamp{ + // time file + NSData* data = [timestamp dataUsingEncoding:NSUTF8StringEncoding]; + return [self writeFile:data packageName:packageName fileName:LV_FILE_NAME_OF_CHANGE_GRAMMAR]; +} + +//------------------------------------------------------------------------------------------ ++(int) unpackageFile:(NSString*) fileName packageName:(NSString*) packageName changeGrammar:(BOOL) changeGrammar{ + NSString *path = [LVUtil PathForBundle:nil relativePath:fileName]; + + if( [LVUtil exist:path] ){ + NSData* pkgData = [LVUtil dataReadFromFile:path]; + return [self unpackageData:pkgData packageName:packageName changeGrammar:changeGrammar]; + } + return -1; +} +// 根据时间戳,检查是否需要更新 ++(BOOL) checkUpdateWithNewTS:(NSString*)newTS oldTS:(NSString*) oldTS{ + return newTS.length>0 && oldTS.length>0 && [newTS compare:oldTS]==NSOrderedDescending; +} + ++(int) unpackageData:(NSData*) pkgData packageName:(NSString*) packageName changeGrammar:(BOOL) changeGrammar{ + NSString *path = [self rootDirectoryOfPackage:packageName]; + if( pkgData && [LVUtil createPath:path] ){ + LVZipArchive *archive = [LVZipArchive archiveWithData:pkgData]; + + NSString* newTS = [archive timeIntervalStr]; + + NSString* oldTS = [self timestampOfPackage:packageName]; + // 首次下载 或者有 新的最新包 + if( (newTS && oldTS==nil) || [self checkUpdateWithNewTS:newTS oldTS:oldTS] ){ + BOOL result = [archive unzipToDirectory:path]; + if( result ) { + [self setPackage:packageName changeGrammar:(changeGrammar ? @"true":@"false") ]; + [self setPackage:packageName timestamp:newTS]; + return 1; + } + return -1; + } else { + LVLog(@" Not Need unpackage, %@, %@",packageName,newTS); + return 0; + } + } + return -1; +} + ++(NSString*) signfileNameOfOriginFile:(NSString*) fileName{ + return [NSString stringWithFormat:@"%@.sign",fileName]; +} + + ++(int) compareDownloadUrlOfPackage:(NSString*)packageName withServerInfo:(NSDictionary*) info{ + LVPkgInfo* pkgInfo = [[LVPkgInfo alloc] init:info]; + NSString* url1 = [self downloadUrlOfPackage:packageName]; + NSString* url2 = pkgInfo.url; + if( url1 && url2 && + [url1 isKindOfClass:[NSString class]] && [url2 isKindOfClass:[NSString class]] && + [url1 isEqualToString:url2] ){ + return 0; + } + return -1; +} + ++(NSInteger) downloadPackage:(NSString*)packageName withInfo:(NSDictionary*) info { + return [self downloadPackage:packageName withInfo:info callback:nil]; +} + ++(NSInteger) downloadPackage:(NSString*)packageName withInfo:(NSDictionary*) info callback:(LVDownloadCallback) callback{ + if( info ) { + if( [self compareDownloadUrlOfPackage:packageName withServerInfo:info] ){ + [self doDownloadPackage:packageName withInfo:info callback:callback]; + return LV_DOWNLOAD_NET; + } + return LV_DOWNLOAD_CACHE; + } + return LV_DOWNLOAD_ERROR; +} + ++(BOOL) sha256Check:(NSData*) data ret:(NSString*) string{ + NSData* temp = lv_SHA256HashBytes(data); + const unsigned char* bytes = temp.bytes; + NSMutableString* buffer = [[NSMutableString alloc] init]; + for( int i=0; i0 && pkgInfo.url.length>0 && pkgInfo.timestamp.length>0){ + [LVUtil download:pkgInfo.url callback:^(NSData *data) { + // 解包过程放在主线程执行!!!! + dispatch_async(dispatch_get_main_queue(), ^{ + if( data ){ + BOOL sha256OK = [self sha256Check:data ret:pkgInfo.sha256]; + if( sha256OK ){ + [self deleteFileOfPackageDownloadUrl:pkgName];// 开始解包, 删除时间戳文件 + if ( [self unpackageData:data packageName:pkgName changeGrammar:pkgInfo.changeGrammar]>=0 ) { + // 解包成功 + if( [self setPackage:pkgName downloadUrl:pkgInfo.url] ){// 写标记成功 + callback(pkgInfo.originalDic, nil, LV_DOWNLOAD_NET); + return ; + } + } + } + } else { + LVError(@"[downloadPackage] error: url=%@",pkgInfo.url); + } + callback(pkgInfo.originalDic, @"error", LV_DOWNLOAD_ERROR); + }); + }]; + } +} + ++(NSData*) readLuaFile:(NSString*) fileName rsa:(LVRSA*)rsa{ + NSString* signfileName = [self signfileNameOfOriginFile:fileName]; + NSData* signData = [LVUtil dataReadFromFile:signfileName]; + NSData* encodedfileData = [LVUtil dataReadFromFile:fileName]; + // LVLog(@"%@",[[NSString alloc] initWithData:fileData encoding:NSUTF8StringEncoding]); + if( [rsa verifyData:encodedfileData withSignedData:signData] ){ + NSData* fileData = LV_AES256DecryptDataWithKey(encodedfileData, [rsa aesKeyBytes]); + NSData* unzipedData = [self gzipUnpack:fileData]; + return unzipedData; + } + return nil; +} + ++ (NSData *)gzipUnpack:(NSData*) data +{ + if ([data length] == 0) return data; + + NSInteger full_length = [data length]; + NSInteger half_length = [data length] / 2; + + NSMutableData *decompressed = [NSMutableData dataWithLength: full_length + half_length]; + BOOL done = NO; + int status; + + z_stream strm; + strm.next_in = (Bytef *)[data bytes]; + strm.avail_in = (unsigned int)[data length]; + strm.total_out = 0; + strm.zalloc = Z_NULL; + strm.zfree = Z_NULL; + + if (inflateInit2(&strm, (15+32)) != Z_OK) return nil; + while (!done){ + if (strm.total_out >= [decompressed length]) + [decompressed increaseLengthBy: half_length]; + strm.next_out = [decompressed mutableBytes] + strm.total_out; + strm.avail_out = (unsigned int)( [decompressed length] - strm.total_out ); + + // Inflate another chunk. + status = inflate (&strm, Z_SYNC_FLUSH); + if (status == Z_STREAM_END) done = YES; + else if (status != Z_OK) break; + } + if (inflateEnd (&strm) != Z_OK) return nil; + + // Set real length. + if (done){ + [decompressed setLength: strm.total_out]; + return [NSData dataWithData: decompressed]; + } + return nil; +} + ++(void) clearCachesPath { + NSFileManager *fileManager = [NSFileManager defaultManager]; + NSString* rootPath = [LVUtil PathForCachesResource:LUAVIEW_ROOT_PATH]; + if( rootPath ) { + NSArray *contents = [fileManager contentsOfDirectoryAtPath:rootPath error:NULL]; + NSEnumerator *e = [contents objectEnumerator]; + NSString *filename; + while ((filename = [e nextObject])) { + if( [fileManager removeItemAtPath:[rootPath stringByAppendingPathComponent:filename] error:NULL] ) { + LVLog ( @"delete File: %@", filename ); + } else { + LVError( @"delete File: %@", filename ); + } + } + } +} + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/PKG/LVZipArchive.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/PKG/LVZipArchive.h new file mode 100644 index 00000000..45de2974 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/PKG/LVZipArchive.h @@ -0,0 +1,39 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import + +@interface LVZipEntry : NSObject + +@property(nonatomic, readonly) NSString *fileName; + +@property(nonatomic, readonly, getter=isSymlink) BOOL symlink; +@property(nonatomic, readonly, getter=isDirectory) BOOL directory; +@property(nonatomic, readonly) NSInteger permissions; +@property(nonatomic, readonly) NSDate *lastModDate; + +@property(nonatomic, readonly) NSData *data; +@property(nonatomic, readonly) NSData *inflatedData; + +@end + +@interface LVZipArchive : NSObject + +@property(nonatomic, readonly) NSData *data; +@property(nonatomic, readonly) NSArray *entries; + ++ (LVZipArchive *)archiveWithData:(NSData *)data; ++ (BOOL)unzipData:(NSData *)data toDirectory:(NSString *)path; + +- (BOOL)unzipToDirectory:(NSString *)path; + +- (NSDate *)lastModDate; //修改日期 + +-(NSString*) timeIntervalStr; //时间戳 + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/PKG/LVZipArchive.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/PKG/LVZipArchive.m new file mode 100644 index 00000000..791ceb3a --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/PKG/LVZipArchive.m @@ -0,0 +1,538 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVZipArchive.h" +#import "LVUtil.h" +#import + +static const UInt32 kCDHeaderMagicNumber = 0x02014B50; +static const UInt32 kCDHeaderFixedDataLength = 46; + +static const UInt32 kCDTrailerMagicNumber = 0x06054B50; + +static const UInt32 kLFHeaderMagicNumber = 0x04034B50; +static const UInt32 kLFHeaderFixedDataLength = 30; + +struct LVZipBuffer { + void *bytes; + NSInteger size; + NSInteger offset; +}; + +static bool buffer_initWithData(struct LVZipBuffer *buffer, NSData *data, NSUInteger offset) { + buffer->bytes = (void *)data.bytes; + buffer->size = data.length; + buffer->offset = offset; + + return true; +} + +static UInt16 buffer_readInt16(struct LVZipBuffer *buffer) { + UInt16 result = CFSwapInt16LittleToHost(*(UInt16 *)(buffer->bytes + buffer->offset)); + buffer->offset += 2; + + return result; +} + +static UInt32 buffer_readInt32(struct LVZipBuffer *buffer) { + UInt32 result = CFSwapInt32LittleToHost(*(UInt32 *)(buffer->bytes + buffer->offset)); + buffer->offset += 4; + + return result; +} + +static void *buffer_position(struct LVZipBuffer *buffer) { + return (void *)buffer->bytes + buffer->offset; +} + +static bool buffer_skip(struct LVZipBuffer *buffer, NSInteger length) { + NSInteger offset = buffer->offset + length; + if (offset < 0 || offset >= buffer->size) { + return false; + } + + buffer->offset = offset; + + return true; +} + +static bool buffer_seekInt32(struct LVZipBuffer *buffer, UInt32 value) { + NSInteger offset = buffer->size - 4; + + while (offset > 0) { + UInt32 temp = CFSwapInt32LittleToHost(*(UInt32 *)(buffer->bytes + offset)); + if (temp == value) { + buffer->offset = offset; + return true; + } + offset--; + } + + return false; +} + +struct LVZipTrailer { + UInt32 magicNumber; + UInt16 diskNumber; + UInt16 diskNumberWithStart; + UInt16 numberOfEntries; + UInt16 totalNumberOfEntries; + UInt32 sizeOfEntries; + UInt32 startOfEntries; + UInt16 commentLength; + char *comment; +}; + +static bool trailer_initWithData(struct LVZipTrailer *trailer, NSData *data) { + UInt32 trailerCheck = 0; + struct LVZipBuffer buffer = {0}; + buffer_initWithData(&buffer, data, [data length] - sizeof(trailerCheck)); + if (!buffer_seekInt32(&buffer, kCDTrailerMagicNumber)) { + return false; + } + if (buffer.offset < 1) { + return false; + } + + UInt32 mn = buffer_readInt32(&buffer); + assert(mn == kCDTrailerMagicNumber); + + trailer->magicNumber = mn; + trailer->diskNumber = buffer_readInt16(&buffer); + trailer->diskNumberWithStart = buffer_readInt16(&buffer); + trailer->numberOfEntries = buffer_readInt16(&buffer); + trailer->totalNumberOfEntries = buffer_readInt16(&buffer); + trailer->sizeOfEntries = buffer_readInt32(&buffer); + trailer->startOfEntries = buffer_readInt32(&buffer); + trailer->commentLength = buffer_readInt16(&buffer); + if (trailer->commentLength) { + trailer->comment = (char *)buffer_position(&buffer); + } + + return true; +} + +struct LVZipCDHeader { + UInt32 magicNumber; + UInt16 versionMadeBy; + UInt16 versionNeededToExtract; + UInt16 generalPurposeBitFlag; + UInt16 compressionMethod; + UInt32 lastModDate; + UInt32 crc; + UInt16 filenameLength; + UInt16 extraFieldLength; + UInt16 commentLength; + UInt16 diskNumberStart; + UInt16 internalFileAttributes; + UInt32 externalFileAttributes; + UInt64 localHeaderOffset; + + UInt64 compressedSize; + UInt64 uncompressedSize; + + char *filename; + void *extraField; + char *comment; + void *cachedData; +}; + +static bool cdheader_initWithData(struct LVZipCDHeader *header, void *start) { + struct LVZipBuffer buffer = { start, NSUIntegerMax, 0 }; + + UInt32 mn = buffer_readInt32(&buffer); + assert(mn == kCDHeaderMagicNumber); + + header->magicNumber = mn; + header->versionMadeBy = buffer_readInt16(&buffer); + header->versionNeededToExtract = buffer_readInt16(&buffer); + header->generalPurposeBitFlag = buffer_readInt16(&buffer); + header->compressionMethod = buffer_readInt16(&buffer); + header->lastModDate = buffer_readInt32(&buffer); + header->crc = buffer_readInt32(&buffer); + header->compressedSize = buffer_readInt32(&buffer); + header->uncompressedSize = buffer_readInt32(&buffer); + header->filenameLength = buffer_readInt16(&buffer); + header->extraFieldLength = buffer_readInt16(&buffer); + header->commentLength = buffer_readInt16(&buffer); + header->diskNumberStart = buffer_readInt16(&buffer); + header->internalFileAttributes = buffer_readInt16(&buffer); + header->externalFileAttributes = buffer_readInt32(&buffer); + header->localHeaderOffset = buffer_readInt32(&buffer); + + if (header->filenameLength) { + header->filename = (char *)buffer_position(&buffer); + buffer_skip(&buffer, header->filenameLength); + } + if (header->extraFieldLength) { + header->extraField = buffer_position(&buffer); + buffer_skip(&buffer, header->extraFieldLength); + } + if (header->commentLength) { + header->comment = (char *)buffer_position(&buffer); + } + + return true; +} + +static NSString *cdheader_getFileName(struct LVZipCDHeader *header) { + if (header->filenameLength == 0) { + return nil; + } + + NSData *data = [NSData dataWithBytes:header->filename length:header->filenameLength]; + NSString *name = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; + return name; +} + +static NSUInteger cdheader_getLength(struct LVZipCDHeader *header) { + return kCDHeaderFixedDataLength + + header->filenameLength + + header->commentLength + + header->extraFieldLength; +} + +static NSInteger cdheader_getPermissions(struct LVZipCDHeader *header) { + return (header->externalFileAttributes >> 16 & 0x1FF) ?: 0755U; +} + +static NSDate *cdheader_getLastModDate(struct LVZipCDHeader *header) { + // convert dos time + UInt32 dtime = header->lastModDate; + + NSDateComponents *comps = [NSDateComponents new]; + comps.year = (int)(((dtime >> 25) & 0x7f) + 1980); + comps.month = (int)((dtime >> 21) & 0x0f); + comps.day = (int)((dtime >> 16) & 0x1f); + comps.hour = (int)((dtime >> 11) & 0x1f); + comps.minute = (int)((dtime >> 5) & 0x3f); + comps.second = (int)((dtime << 1) & 0x3e); + + return [[NSCalendar currentCalendar] dateFromComponents:comps]; +} + +static NSInteger cdheader_getFileType(struct LVZipCDHeader *header) { + return header->externalFileAttributes >> 29 & 0x1F; +} + +static bool cdheader_isDirecotry(struct LVZipCDHeader *header) { + return cdheader_getFileType(header) == 0x02; +} + +static bool cdheader_isSymlink(struct LVZipCDHeader *header) { + return cdheader_getFileType(header) == 0x05; +} + +struct LVZipLFHeader { + UInt32 magicNumber; + UInt32 versionNeededToExtract; + UInt32 generalPurposeBitFlag; + UInt32 compressionMethod; + UInt32 lastModDate; + UInt32 crc; + UInt64 compressedSize; + UInt64 uncompressedSize; + UInt32 filenameLength; + UInt32 extraFieldLength; + char *filename; + void *extraField; +}; + +static bool lfheader_initWithData(struct LVZipLFHeader *header, void *start) { + struct LVZipBuffer buffer = { start, NSUIntegerMax, 0 }; + + UInt32 mn = buffer_readInt32(&buffer); + assert(mn == kLFHeaderMagicNumber); + + header->magicNumber = mn; + header->versionNeededToExtract = buffer_readInt16(&buffer); + header->generalPurposeBitFlag = buffer_readInt16(&buffer); + header->compressionMethod = buffer_readInt16(&buffer); + header->lastModDate = buffer_readInt32(&buffer); + header->crc = buffer_readInt32(&buffer); + header->compressedSize = buffer_readInt32(&buffer); + header->uncompressedSize = buffer_readInt32(&buffer); + header->filenameLength = buffer_readInt16(&buffer); + header->extraFieldLength = buffer_readInt16(&buffer); + + if (header->filenameLength > 0) { + header->filename = (char *)buffer_position(&buffer); + buffer_skip(&buffer, header->filenameLength); + } + if (header->extraFieldLength > 0) { + header->extraField = (char *)buffer_position(&buffer); + } + + return true; +} + +static NSUInteger lfheader_getLength(struct LVZipLFHeader *header) { + return kLFHeaderFixedDataLength + + header->filenameLength + + header->extraFieldLength; +} + +@interface LVZipArchive () + +@property(nonatomic, strong) NSData *data; +@property(nonatomic, strong) NSArray *entries; + +@end + +@interface LVZipEntry () + +@property(nonatomic, assign) struct LVZipCDHeader internalHeader; +@property(nonatomic, strong) NSData *data; + +@end + +@implementation LVZipArchive + ++ (LVZipArchive *)archiveWithData:(NSData *)data { + struct LVZipTrailer trailer = {0}; + if (!trailer_initWithData(&trailer, data)) { + return nil; + } + + LVZipArchive *archive = [self new]; + archive.data = data; + + NSMutableArray *entries = [NSMutableArray array]; + struct LVZipCDHeader header = {0}; + LVZipEntry *entry = nil; + unsigned long long offset = trailer.startOfEntries; + for (NSUInteger i = 0; i < trailer.totalNumberOfEntries; i++) { + if (cdheader_initWithData(&header, (void *)(data.bytes + offset))) { + entry = [LVZipEntry new]; + entry.internalHeader = header; + [archive fillContentOfEntry:entry]; + [entries addObject:entry]; + + offset += cdheader_getLength(&header); + } else { + break; + } + } + + archive.entries = entries; + + return archive; +} + +- (NSDate *) lastModDate { + NSDate* date0 = self.entries.firstObject.lastModDate; + for( LVZipEntry * entry in self.entries ){ + NSDate* date2 = entry.lastModDate; + if( [date2 timeIntervalSinceDate:date0]>0 ) { + date0 = date2; + } + } + return date0; +} + +- (NSString*) timeIntervalStr{ + NSDate* date = [self lastModDate]; + long long s = (long long)( [date timeIntervalSince1970] ); + NSString *timeStr = [NSString stringWithFormat:@"%lld", s]; + return timeStr; +} + ++ (BOOL)unzipData:(NSData *)data toDirectory:(NSString *)path { + LVZipArchive *archive = [self archiveWithData:data]; + return [archive unzipToDirectory:path]; +} + +- (BOOL)unzipToDirectory:(NSString *)path { + if (path == nil) { + return NO; + } + + NSFileManager *fm = [NSFileManager defaultManager]; + if (![fm createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:NULL]) { + LVLog(@"create directory(%@) error!", path); + return NO; + } + + NSDictionary *attrs = nil; + NSData *inflatedData = nil; + NSString *fileName = nil, *fullPath = nil; + NSError *error = nil; + for (LVZipEntry *entry in self.entries) { + error = nil; + attrs = [self attributes:entry]; + inflatedData = entry.inflatedData; + fileName = entry.fileName; + fullPath = [path stringByAppendingPathComponent:fileName]; + + if ([entry isDirectory]) { + BOOL r = [fm createDirectoryAtPath:fullPath + withIntermediateDirectories:YES + attributes:attrs + error:&error]; + if (!r) { + LVLog(@"create directory(%@) entry error:", fileName, error); + return NO; + } + } else if ([entry isSymlink]) { + NSString *dest = [[NSString alloc] initWithData:inflatedData + encoding:NSUTF8StringEncoding]; + BOOL r = [fm createSymbolicLinkAtPath:fullPath + withDestinationPath:dest + error:&error]; + if (!r) { + LVLog(@"create symlink(%@) entry error:", fileName, error); + return NO; + } + [fm setAttributes:attrs ofItemAtPath:fullPath error:NULL]; + } else { + NSString *dir = [fileName stringByDeletingLastPathComponent]; + if ([dir length] > 0) { + NSString *fullDirPath = [path stringByAppendingPathComponent:dir]; + BOOL isDir = NO, r = NO; + if (![fm fileExistsAtPath:fullDirPath isDirectory:&isDir]) { + r = [fm createDirectoryAtPath:fullDirPath + withIntermediateDirectories:YES + attributes:nil + error:&error]; + if (!r) { + LVLog(@"create file(%@)'s parent directory error:%@", fileName, error); + return NO; + } + } else if (!isDir) { + r = [fm removeItemAtPath:fullDirPath error:&error]; + if (!r) { + LVLog(@"remove exist file(%@) error:%@", dir, error); + return NO; + } + r = [fm createDirectoryAtPath:fullDirPath + withIntermediateDirectories:YES + attributes:nil + error:NULL]; + if (!r) { + LVLog(@"create file(%@)'s parent directory error:%@", fileName, error); + return NO; + } + } + } + + BOOL r = [fm createFileAtPath:fullPath contents:inflatedData attributes:attrs]; + if (!r) { + LVLog(@"create file(%@) entry error", fileName); + return NO; + } + } + } + + return YES; +} + +- (void)fillContentOfEntry:(LVZipEntry *)entry { + if ([entry isDirectory]) { + return; + } + + struct LVZipLFHeader lfHeader = {0}; + void *start = (void *)(self.data.bytes + entry.internalHeader.localHeaderOffset); + if (!lfheader_initWithData(&lfHeader, start)) { + return; + } + + NSUInteger location = (NSUInteger)entry.internalHeader.localHeaderOffset + lfheader_getLength(&lfHeader); + NSUInteger length = (NSUInteger)entry.internalHeader.compressedSize; + entry.data = [self.data subdataWithRange:NSMakeRange(location, length)]; +} + +- (NSDictionary *)attributes:(LVZipEntry *)entry { + if ([entry isDirectory] || [entry isSymlink]) { + return nil; + } + + return @{ NSFilePosixPermissions: @([entry permissions]), + NSFileCreationDate: [entry lastModDate], + NSFileModificationDate: [entry lastModDate] }; +} + +@end + +@implementation LVZipEntry + +@synthesize inflatedData = _inflatedData; +@dynamic fileName, symlink, directory, permissions, lastModDate; + +- (NSString *)fileName { + return cdheader_getFileName(&_internalHeader); +} + +- (NSInteger)permissions { + return cdheader_getPermissions(&_internalHeader); +} + +- (BOOL)isDirectory { + return cdheader_isDirecotry(&_internalHeader) || [[self fileName] hasSuffix:@"/"]; +} + +- (BOOL)isSymlink { + return cdheader_isSymlink(&_internalHeader); +} + +- (NSDate *)lastModDate { + return cdheader_getLastModDate(&_internalHeader); +} + +- (NSData *)inflatedData { + if (_inflatedData) { + return _inflatedData; + } + + if (!_data) { + return nil; + } + + if (_internalHeader.compressionMethod == Z_NO_COMPRESSION || [self isSymlink]) { + _inflatedData = _data; + } else { + _inflatedData = [self inflateData:_data]; + } + + return _inflatedData; +} + +- (NSData *) inflateData:(NSData *)data { + NSUInteger length = [data length]; + NSUInteger halfLength = length / 2; + + NSMutableData *inflatedData = [NSMutableData dataWithLength:length + halfLength]; + BOOL done = NO; + int status; + + z_stream strm; + + strm.next_in = (Bytef *)data.bytes; + strm.avail_in = (unsigned int)[data length]; + strm.total_out = 0; + strm.zalloc = Z_NULL; + strm.zfree = Z_NULL; + + if (inflateInit2(&strm, -MAX_WBITS) != Z_OK) return nil; + while (!done) { + if (strm.total_out >= [inflatedData length]) + [inflatedData increaseLengthBy:halfLength]; + strm.next_out = [inflatedData mutableBytes] + strm.total_out; + strm.avail_out = (unsigned int)([inflatedData length] - strm.total_out); + status = inflate(&strm, Z_SYNC_FLUSH); + if (status == Z_STREAM_END) done = YES; + else if (status != Z_OK) break; + } + if (inflateEnd(&strm) == Z_OK && done) + [inflatedData setLength:strm.total_out]; + else + inflatedData = nil; + return inflatedData; +} + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/RSA/LVRSA.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/RSA/LVRSA.h new file mode 100644 index 00000000..2806d47c --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/RSA/LVRSA.h @@ -0,0 +1,24 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import + +@interface LVRSA : NSObject + +-(BOOL) verifyData:(NSData*)data withSignedData:(NSData*) sign; + +-(NSData*) aesKeyBytes; + +/* + * 设置证书名 + */ +- (void) setPublicKeyFilePath:(NSString*) filePath; + +NSData* lv_SHA256HashBytes(NSData *fileData); + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/RSA/LVRSA.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/RSA/LVRSA.m new file mode 100644 index 00000000..5852c768 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/RSA/LVRSA.m @@ -0,0 +1,252 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVRSA.h" +#import +#import +#import +#import +#import +#import "LVUtil.h" + +@implementation LVRSA { + NSData* g_keyBytes; + SecKeyRef g_publicKey; + NSString* g_publicKeyFilePath; +} + +-(void) dealloc{ + LVReleaseAndNull(g_publicKey); +} + +NSError* lv_verifySignSHA1WithRSA(NSData *fileData, SecKeyRef pubKeyRef, NSData *signedData); + +-(BOOL) verifyData:(NSData*)data withSignedData:(NSData*) signedData{ + SecKeyRef key = [self getPublicKey]; + NSError* error = lv_verifySignSHA1WithRSA(data, key, signedData); + if( error == nil ){ + return YES; + } + LVLog(@"%@",error); + return NO; +} + +-(NSData*) aesKeyBytes{ + if( g_keyBytes==nil ) { + NSData *certificateData = [self publickKeyData]; + g_keyBytes = [LVUtil MD5HashDataFromData:certificateData]; + } + return g_keyBytes; +} + +//公共秘钥的引用: +- (SecKeyRef)getPublicKey{ + if( g_publicKey == NULL ){ + g_publicKey = [self getPublicKey0]; + } + return g_publicKey; +} + +- (void) setPublicKeyFilePath:(NSString*) filePath{ + g_publicKeyFilePath = filePath; +} + +-(NSData*) publickKeyData{ + if( g_publicKeyFilePath==nil ) + g_publicKeyFilePath = [[NSBundle mainBundle] pathForResource:@"public_key" ofType:@"der"]; + + NSData *certificateData = [NSData dataWithContentsOfFile:g_publicKeyFilePath]; + return certificateData; +} + +- (SecKeyRef)getPublicKey0 +{ + NSData *certificateData = [self publickKeyData]; + if ( certificateData==nil ){ + return NULL; + } + SecCertificateRef myCertificate = NULL; + myCertificate = SecCertificateCreateWithData(kCFAllocatorDefault, (__bridge CFDataRef)certificateData); + SecPolicyRef myPolicy = SecPolicyCreateBasicX509(); + SecTrustRef myTrust = NULL; + OSStatus status = SecTrustCreateWithCertificates(myCertificate,myPolicy,&myTrust); + SecTrustResultType trustResult; + if (status == noErr) { + status = SecTrustEvaluate(myTrust, &trustResult); + if( status == noErr ){ + LVReleaseAndNull(myPolicy); + LVReleaseAndNull(myCertificate); + SecKeyRef ret = SecTrustCopyPublicKey(myTrust); + LVReleaseAndNull(myTrust); + return ret; + } + } + LVReleaseAndNull(myPolicy); + LVReleaseAndNull(myCertificate); + return NULL; +} + +//加密: +- (NSData*)rsaEncryptWithData:(NSData*)data usingKey:(SecKeyRef)key{ + + size_t cipherBufferSize = SecKeyGetBlockSize(key); + uint8_t *cipherBuffer = malloc(cipherBufferSize * sizeof(uint8_t)); + memset((void *)cipherBuffer, 0*0, cipherBufferSize); + + NSData *plainTextBytes = data; + size_t blockSize = cipherBufferSize - 11; + size_t blockCount = (size_t)ceil([plainTextBytes length] / (double)blockSize); + NSMutableData *encryptedData = [NSMutableData dataWithCapacity:0]; + + for (int i=0; i0 && key.length>0 ) { + NSUInteger dataLength = [data length]; + + // See the doc: For block ciphers, the output size will always be less than or + // equal to the input size plus the size of one block. + // That's why we need to add the size of one block here + size_t bufferSize = (dataLength + kCCKeySizeAES256); + void *buffer = malloc(bufferSize); + bzero(buffer, sizeof(bufferSize)); + + size_t numBytesDecrypted = 0; + CCCryptorStatus cryptStatus = CCCrypt(kCCDecrypt, kCCAlgorithmAES128, kCCOptionPKCS7Padding, + key.bytes, key.length, + NULL /* initialization vector (optional) */, + [data bytes], dataLength, /* input */ + buffer, bufferSize, /* output */ + &numBytesDecrypted); + + if ( cryptStatus == kCCSuccess ) { + return [NSData dataWithBytesNoCopy:buffer length:numBytesDecrypted]; + } + + free(buffer); //free the buffer; + return nil; + } + return nil; +} + +#define kChosenDigestLength CC_SHA1_DIGEST_LENGTH // SHA-1消息摘要的数据位数160位 +NSData* lv_SHA1HashBytes(NSData *fileData){ + CC_SHA1_CTX ctx; + uint8_t * hashBytes = NULL; + NSData * hash = nil; + + // Malloc a buffer to hold hash. + hashBytes = malloc( kChosenDigestLength * sizeof(uint8_t) ); + memset((void *)hashBytes, 0x0, kChosenDigestLength); + // Initialize the context. + CC_SHA1_Init(&ctx); + // Perform the hash. + CC_SHA1_Update(&ctx, (void *)[fileData bytes], (CC_LONG)[fileData length]); + // Finalize the output. + CC_SHA1_Final(hashBytes, &ctx); + + // Build up the SHA1 blob. + hash = [NSData dataWithBytes:(const void *)hashBytes length:(NSUInteger)kChosenDigestLength]; + if (hashBytes) free(hashBytes); + + return hash; +} + + +NSData* lv_SHA256HashBytes(NSData *fileData){ + CC_SHA256_CTX ctx; + uint8_t * hashBytes = NULL; + NSData * hash = nil; + + // Malloc a buffer to hold hash. + hashBytes = malloc( CC_SHA256_DIGEST_LENGTH * sizeof(uint8_t) ); + memset((void *)hashBytes, 0x0, CC_SHA256_DIGEST_LENGTH); + // Initialize the context. + CC_SHA256_Init(&ctx); + // Perform the hash. + CC_SHA256_Update(&ctx, (void *)[fileData bytes], (CC_LONG)[fileData length]); + // Finalize the output. + CC_SHA256_Final(hashBytes, &ctx); + + // Build up the SHA256 blob. + hash = [NSData dataWithBytes:(const void *)hashBytes length:(NSUInteger)CC_SHA256_DIGEST_LENGTH]; + if ( hashBytes ) { + free(hashBytes); + } + return hash; +} + +NSError* lv_verifySignSHA1WithRSA(NSData *fileData, SecKeyRef pubKeyRef, NSData *signedData){ + if(!fileData || !pubKeyRef || !signedData){ + return [NSError errorWithDomain:@"" code:-1 userInfo:@{@"desc":[NSString stringWithFormat:@"input error fileData=%p pubKeyRef=%p signedData=%p", fileData, pubKeyRef, signedData]}]; + } + OSStatus sanityCheck = noErr; + + NSData *hash = lv_SHA1HashBytes(fileData); + size_t signedHashBytesSize = SecKeyGetBlockSize(pubKeyRef); + //kSecPaddingPKCS1SHA1 kSecPaddingPKCS1MD5 + sanityCheck = SecKeyRawVerify(pubKeyRef, kSecPaddingPKCS1SHA1, [hash bytes], kChosenDigestLength, [signedData bytes], signedHashBytesSize); + + // NS Log(@"data=%@\n hash=%@\n signed=%@", fileData, hash, signedData); + if (sanityCheck == noErr){ + return nil; + }else{ + return [NSError errorWithDomain:@"" code:sanityCheck userInfo:@{@"desc":[NSString stringWithFormat:@"verifySign failed OSStatus=%d", (int)sanityCheck]}]; + } +} + +@end + + + diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXCSSParser.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXCSSParser.h new file mode 100644 index 00000000..3970828e --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXCSSParser.h @@ -0,0 +1,77 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import + +@class JUFLXNode; +@interface JUFLXCSSParser : NSObject + ++ (void)parseInlineCSS:(NSString *)inlineCSS toNode:(JUFLXNode *)node; + +@end + + +/* + * --------------------------------------------------------------------------- + * The valid css value + * --------------------------------------------------------------------------- + */ +/* +NSString * const kHRCSSPosition = @"position"; +NSString * const kHRCSSPositionAbsolute = @"absolute"; +NSString * const kHRCSSPositionTop = @"top"; +NSString * const kHRCSSPositionLeft = @"left"; +NSString * const kHRCSSPositionBottom = @"bottom"; +NSString * const kHRCSSPositionRight = @"right"; + +NSString * const kHRCSSDirection = @"flex-direction"; +NSString * const kHRCSSDirectionRow = @"row"; +NSString * const kHRCSSDirectionRowReverse = @"row-reverse"; +NSString * const kHRCSSDirectionColumn = @"column"; +NSString * const kHRCSSDirectionColumnReverse = @"column-reverse"; + +NSString * const kHRCSSAlignItems = @"align-items"; +NSString * const kHRCSSAlignContent = @"align-content"; +NSString * const kHRCSSAlignSelf = @"align-self"; +NSString * const kHRCSSAlignAuto = @"auto"; +NSString * const kHRCSSAlignStart = @"flex-start"; +NSString * const kHRCSSAlignCenter = @"center"; +NSString * const kHRCSSAlignEnd = @"flex-end"; +NSString * const kHRCSSAlignStretch = @"stretch"; + +NSString * const kHRCSSJustification = @"justify-content"; +NSString * const kHRCSSJustificationStart = @"flex-start"; +NSString * const kHRCSSJustificationCenter = @"center"; +NSString * const kHRCSSJustificationEnd = @"flex-end"; +NSString * const kHRCSSJustificationBetween = @"space-between"; +NSString * const kHRCSSJustificationAround = @"space-around"; + +NSString * const kHRCSSFlex = @"flex"; +NSString * const kHRCSSFlexWrap = @"flex-wrap"; + +NSString * const kHRCSSDimensionWidth = @"width"; +NSString * const kHRCSSDimensionHeight = @"height"; + +NSString * const kHRCSSMinDimensionWidth = @"min-width"; +NSString * const kHRCSSMinDimensionHeight = @"min-height"; + +NSString * const kHRCSSMaxDimensionWidth = @"max-width"; +NSString * const kHRCSSMaxDimensionHeight = @"max-height"; + +NSString * const kHRCSSMargin = @"margin"; +NSString * const kHRCSSMarginLeft = @"margin-left"; +NSString * const kHRCSSMarginTop = @"margin-top"; +NSString * const kHRCSSMarginBottom = @"margin-bottom"; +NSString * const kHRCSSMarginRight = @"margin-right"; + +NSString * const kHRCSSPadding = @"padding"; +NSString * const kHRCSSPaddingLeft = @"padding-left"; +NSString * const kHRCSSPaddingTop = @"padding-top"; +NSString * const kHRCSSPaddingBottom = @"padding-bottom"; +NSString * const kHRCSSPaddingRight = @"padding-right"; +*/ diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXCSSParser.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXCSSParser.m new file mode 100644 index 00000000..3d0e663d --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXCSSParser.m @@ -0,0 +1,326 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ +#import "JUFLXCSSParser.h" +#import "JUFLXNode.h" + +static inline BOOL isValidFloatString(NSString *floatString) { + BOOL valid = NO; + if (floatString && [floatString isKindOfClass:[NSString class]]) { + CGFloat fv = [floatString floatValue]; + valid = fv != NSNotFound; + } + + return valid; +} + +static inline CGFloat getFloatFromString(NSString *string, CGFloat defaultValue) { + CGFloat result = defaultValue; + if (isValidFloatString(string)) { + result = [string floatValue]; + } + + return result; +} + +NSString * const kHRCSSPosition = @"position"; +NSString * const kHRCSSPositionAbsolute = @"absolute"; +NSString * const kHRCSSPositionTop = @"top"; +NSString * const kHRCSSPositionLeft = @"left"; +NSString * const kHRCSSPositionBottom = @"bottom"; +NSString * const kHRCSSPositionRight = @"right"; + +NSString * const kHRCSSDirection = @"flex-direction"; +NSString * const kHRCSSDirectionRow = @"row"; +NSString * const kHRCSSDirectionRowReverse = @"row-reverse"; +NSString * const kHRCSSDirectionColumn = @"column"; +NSString * const kHRCSSDirectionColumnReverse = @"column-reverse"; + +NSString * const kHRCSSAlignItems = @"align-items"; +NSString * const kHRCSSAlignContent = @"align-content"; +NSString * const kHRCSSAlignSelf = @"align-self"; +NSString * const kHRCSSAlignAuto = @"auto"; +NSString * const kHRCSSAlignStart = @"flex-start"; +NSString * const kHRCSSAlignCenter = @"center"; +NSString * const kHRCSSAlignEnd = @"flex-end"; +NSString * const kHRCSSAlignStretch = @"stretch"; + +NSString * const kHRCSSjustifyContent = @"justify-content"; +NSString * const kHRCSSjustifyContentStart = @"flex-start"; +NSString * const kHRCSSjustifyContentCenter = @"center"; +NSString * const kHRCSSjustifyContentEnd = @"flex-end"; +NSString * const kHRCSSjustifyContentBetween = @"space-between"; +NSString * const kHRCSSjustifyContentAround = @"space-around"; + +NSString * const kHRCSSFlex = @"flex"; +NSString * const kHRCSSFlexWrap = @"flex-wrap"; + +NSString * const kHRCSSDimensionSize = @"size"; +NSString * const kHRCSSDimensionWidth = @"width"; +NSString * const kHRCSSDimensionHeight = @"height"; + +NSString * const kHRCSSMinDimensionWidth = @"min-width"; +NSString * const kHRCSSMinDimensionHeight = @"min-height"; + +NSString * const kHRCSSMaxDimensionWidth = @"max-width"; +NSString * const kHRCSSMaxDimensionHeight = @"max-height"; + +NSString * const kHRCSSMargin = @"margin"; +NSString * const kHRCSSMarginLeft = @"margin-left"; +NSString * const kHRCSSMarginTop = @"margin-top"; +NSString * const kHRCSSMarginBottom = @"margin-bottom"; +NSString * const kHRCSSMarginRight = @"margin-right"; + +NSString * const kHRCSSPadding = @"padding"; +NSString * const kHRCSSPaddingLeft = @"padding-left"; +NSString * const kHRCSSPaddingTop = @"padding-top"; +NSString * const kHRCSSPaddingBottom = @"padding-bottom"; +NSString * const kHRCSSPaddingRight = @"padding-right"; + +NSString * const kHRCSSSizeToFit = @"sizetofit"; + +@implementation JUFLXCSSParser + +/** + * Stand is @"diretion:row;alignitems:auto;justifyContent:start" + */ ++ (NSDictionary *)transferInlineCSS:(NSString *)inlineCSS { + if ([inlineCSS hasPrefix:@"{"]) inlineCSS = [inlineCSS substringFromIndex:1]; + if ([inlineCSS hasSuffix:@"}"]) inlineCSS = [inlineCSS substringToIndex:inlineCSS.length - 1]; + + + NSArray *inlineArray = [inlineCSS componentsSeparatedByString:@","]; + if (inlineArray.count == 0) { + if (inlineCSS.length > 0) { + NSLog(@"===>JUFLXNode inlineCSS string maybe be wrong, check it %@", inlineCSS); + return nil; + } + }; + + NSMutableDictionary *result = [NSMutableDictionary dictionary]; + NSCharacterSet *whiteAndNewLine = [NSCharacterSet whitespaceAndNewlineCharacterSet]; + + for (NSString *kv in inlineArray) { + NSArray *kvArray = [kv componentsSeparatedByString:@":"]; + if (kvArray.count == 2) { + NSString *key = kvArray[0]; + NSString *value = kvArray[1]; + if ([key isKindOfClass:[NSString class]] + && key.length > 0 + && [value isKindOfClass:[NSString class]] + && value.length > 0) { + + key = [[key stringByTrimmingCharactersInSet:whiteAndNewLine] lowercaseString]; + value = [[value stringByTrimmingCharactersInSet:whiteAndNewLine] lowercaseString]; + result[key] = value; + } + } + } + + return result; +} + ++ (NSSet *)validInlineCssKeys { + static dispatch_once_t onceToken; + static NSSet *set; + dispatch_once(&onceToken, ^{ + set = [NSSet setWithObjects: + kHRCSSPosition, + kHRCSSPositionTop, + kHRCSSPositionLeft, + kHRCSSPositionBottom, + kHRCSSPositionRight, + kHRCSSDirection, + kHRCSSAlignItems, + kHRCSSAlignContent, + kHRCSSjustifyContent, + kHRCSSFlexWrap, + kHRCSSAlignSelf, + kHRCSSFlex, + kHRCSSDimensionSize, + kHRCSSDimensionWidth, + kHRCSSDimensionHeight, + kHRCSSMinDimensionWidth, + kHRCSSMinDimensionHeight, + kHRCSSMaxDimensionWidth, + kHRCSSMaxDimensionHeight, + kHRCSSMargin, + kHRCSSMarginTop, + kHRCSSMarginLeft, + kHRCSSMarginBottom, + kHRCSSMarginRight, + kHRCSSPadding, + kHRCSSPaddingTop, + kHRCSSPaddingLeft, + kHRCSSPaddingBottom, + kHRCSSPaddingRight, + kHRCSSSizeToFit, + nil]; + }); + return set; + +} + ++ (NSDictionary *)validDirections { + static dispatch_once_t onceToken; + static NSDictionary *dic; + dispatch_once(&onceToken, ^{ + dic = @{kHRCSSDirectionColumn : @(JUFLXLayoutDirectionColumn), + kHRCSSDirectionRow : @(JUFLXLayoutDirectionRow), + kHRCSSDirectionRowReverse : @(JUFLXLayoutDirectionRowReverse), + kHRCSSDirectionColumnReverse : @(JUFLXLayoutDirectionColumnReverse)}; + }); + return dic; +} + ++ (NSDictionary *)validAlignments { + static dispatch_once_t onceToken; + static NSDictionary *dic; + dispatch_once(&onceToken, ^{ + dic = @{kHRCSSAlignAuto : @(JUFLXLayoutAlignmentAuto), + kHRCSSAlignStart : @(JUFLXLayoutAlignmentStart), + kHRCSSAlignCenter : @(JUFLXLayoutAlignmentCenter), + kHRCSSAlignEnd : @(JUFLXLayoutAlignmentEnd), + kHRCSSAlignStretch : @(JUFLXLayoutAlignmentStretch)}; + }); + return dic; +} + ++ (NSDictionary *)validjustifyContents { + static dispatch_once_t onceToken; + static NSDictionary *dic; + dispatch_once(&onceToken, ^{ + dic = @{kHRCSSjustifyContentStart : @(JUFLXLayoutJustifyContentStart), + kHRCSSjustifyContentCenter : @(JUFLXLayoutJustifyContentCenter), + kHRCSSjustifyContentEnd : @(JUFLXLayoutJustifyContentEnd), + kHRCSSjustifyContentBetween : @(JUFLXLayoutJustifyContentBetween), + kHRCSSjustifyContentAround : @(JUFLXLayoutJustifyContentAround), + }; + }); + return dic; + +} + ++ (NSInteger)mappedEnumValueInDictionary:(NSDictionary *)dic withKey:(NSString *)key { + NSString *value = [dic objectForKey:key]; + if (!value) { + NSLog(@"%@ isn't a valid key in valid Dic %@", key, dic); + NSUInteger initialValue = 0; + if ([key isEqualToString:kHRCSSDirection]) { + initialValue = JUFLXLayoutDirectionRow; + + } else if ([key isEqualToString:kHRCSSAlignItems]) { + initialValue = JUFLXLayoutAlignmentStretch; + + } else if ([key isEqualToString:kHRCSSjustifyContent]) { + initialValue = JUFLXLayoutJustifyContentStart; + + } else if ([key isEqualToString:kHRCSSAlignSelf]) { + initialValue = JUFLXLayoutAlignmentAuto; + + } else if ([key isEqualToString:kHRCSSAlignContent]) { + initialValue = JUFLXLayoutAlignmentStretch; + } + + return initialValue; + } + + return [value integerValue]; +} + ++ (void)parseInlineCSS:(NSString *)inlineCSS toNode:(JUFLXNode *)node { + NSDictionary *inlineDic = [self transferInlineCSS:inlineCSS]; + + //filter the invalid key and log +#if DEBUG + id predicateBlock = ^BOOL(id evaluatedObject, NSDictionary *bindings) { + return ![[self validInlineCssKeys] containsObject:evaluatedObject]; + }; + NSArray *invalidKeys = [inlineDic.allKeys filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:predicateBlock]]; + if (invalidKeys.count) { + NSLog(@"<---JUFLXNode---> valid keys %@ doesn't contain these keys %@ \n Please check -> JUFLXNode.h", [self validInlineCssKeys], invalidKeys); + } +#endif + + NSString *position = inlineDic[kHRCSSPosition]; + node.absolute = [position isKindOfClass:[NSString class]] && [position.lowercaseString isEqualToString:@"absolute"]; + CGFloat positionTop = getFloatFromString(inlineDic[kHRCSSPositionTop], node.absoluteEdges.top); + CGFloat positionLeft = getFloatFromString(inlineDic[kHRCSSPositionLeft], node.absoluteEdges.left); + CGFloat positionBottom = getFloatFromString(inlineDic[kHRCSSPositionBottom], node.absoluteEdges.bottom); + CGFloat positionRight = getFloatFromString(inlineDic[kHRCSSPositionRight], node.absoluteEdges.right); + node.absoluteEdges = UIEdgeInsetsMake(positionTop, positionLeft, positionBottom, positionRight); + + NSString *direction = inlineDic[kHRCSSDirection]; + if (direction) node.direction = [self mappedEnumValueInDictionary:[self validDirections] withKey:direction]; + + NSString *alignItems = inlineDic[kHRCSSAlignItems]; + if (alignItems) node.alignItems = [self mappedEnumValueInDictionary:[self validAlignments] withKey:alignItems]; + + NSString *alignSelf = inlineDic[kHRCSSAlignSelf]; + if (alignSelf) node.alignSelf = [self mappedEnumValueInDictionary:[self validAlignments] withKey:alignSelf]; + + NSString *alignContent = inlineDic[kHRCSSAlignContent]; + if (alignContent) node.alignContent = [self mappedEnumValueInDictionary:[self validAlignments] withKey:alignContent]; + + NSString *justifyContent = inlineDic[kHRCSSjustifyContent]; + if (justifyContent) node.justifyContent = [self mappedEnumValueInDictionary:[self validjustifyContents] withKey:justifyContent]; + + + node.flex = getFloatFromString(inlineDic[kHRCSSFlex], node.flex); + + node.flexWrap = getFloatFromString(inlineDic[kHRCSSFlexWrap], node.flexWrap); + + NSString *size = inlineDic[kHRCSSDimensionSize]; + if (isValidFloatString(size)) { + CGFloat sizef = [size floatValue]; + node.dimensions = CGSizeMake(sizef, sizef); + } + + CGFloat width = getFloatFromString(inlineDic[kHRCSSDimensionWidth], node.dimensions.width); + CGFloat height = getFloatFromString(inlineDic[kHRCSSDimensionHeight], node.dimensions.height); + node.dimensions = CGSizeMake(width, height); + + CGFloat minWidth = getFloatFromString(inlineDic[kHRCSSMinDimensionWidth], node.minDimensions.width); + CGFloat minHeight = getFloatFromString(inlineDic[kHRCSSMinDimensionHeight], node.minDimensions.height); + node.minDimensions = CGSizeMake(minWidth, minHeight); + + CGFloat maxWidth = getFloatFromString(inlineDic[kHRCSSMaxDimensionWidth], node.maxDimensions.width); + CGFloat maxHeight = getFloatFromString(inlineDic[kHRCSSMaxDimensionHeight], node.maxDimensions.height); + node.maxDimensions = CGSizeMake(maxWidth, maxHeight); + + NSString *margin = inlineDic[kHRCSSMargin]; + if (isValidFloatString(margin)) { + CGFloat marginf = [margin floatValue]; + node.margin = UIEdgeInsetsMake(marginf, marginf, marginf, marginf); + } + + CGFloat marginTop = getFloatFromString(inlineDic[kHRCSSMarginTop], node.margin.top); + CGFloat marginLeft = getFloatFromString(inlineDic[kHRCSSMarginLeft], node.margin.left); + CGFloat marginBottom = getFloatFromString(inlineDic[kHRCSSMarginBottom], node.margin.bottom); + CGFloat marginRight = getFloatFromString(inlineDic[kHRCSSMarginRight], node.margin.right); + node.margin = UIEdgeInsetsMake(marginTop, marginLeft, marginBottom, marginRight); + + NSString *padding = inlineDic[kHRCSSPadding]; + if (isValidFloatString(padding)) { + CGFloat paddingf = [padding floatValue]; + node.padding = UIEdgeInsetsMake(paddingf, paddingf, paddingf, paddingf); + } + + CGFloat paddingTop = getFloatFromString(inlineDic[kHRCSSPaddingTop], node.padding.top); + CGFloat paddingLeft = getFloatFromString(inlineDic[kHRCSSPaddingLeft], node.padding.left); + CGFloat paddingBottom = getFloatFromString(inlineDic[kHRCSSPaddingBottom], node.padding.bottom); + CGFloat paddingRight = getFloatFromString(inlineDic[kHRCSSPaddingRight], node.padding.right); + node.padding = UIEdgeInsetsMake(paddingTop, paddingLeft, paddingBottom, paddingRight); + + CGFloat sizeToFit = getFloatFromString(inlineDic[kHRCSSSizeToFit], 0); + if (sizeToFit > 0) { + node.sizeToFit = YES; + } +} + + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXLayoutDefine.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXLayoutDefine.h new file mode 100644 index 00000000..cb54abcf --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXLayoutDefine.h @@ -0,0 +1,19 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + + +#define JUFLX_LAYOUT_NAMESPACE JUFLX + +#ifdef JUFLX_LAYOUT_NAMESPACE +// prefix all GData class names with JUFLX_LAYOUT_NAMESPACE for this target + #import "JUFLXTargeNamespace.h" +#endif + +#import "Layout.h" + + diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXLayoutKit.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXLayoutKit.h new file mode 100644 index 00000000..48b2c36f --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXLayoutKit.h @@ -0,0 +1,23 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "JUFLXNode.h" +#import "JUFLXCSSParser.h" +#import "UIView+JUFLXNode.h" +#import "JUFLXLinearLayoutView.h" + +//! Project version number for JUFLXLayoutKit. +FOUNDATION_EXPORT double JUFLXLayoutKitVersionNumber; + +//! Project version string for JUFLXLayoutKit. +FOUNDATION_EXPORT const unsigned char JUFLXLayoutKitVersionString[]; + +// In this header, you should import all the public headers of your framework using statements like #import + + diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXNode.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXNode.h new file mode 100644 index 00000000..2afd6bd1 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXNode.h @@ -0,0 +1,316 @@ +/* + * --------------------------------------------------------------------------- + * * Build base on Facebook's css_layout https://github.com/facebook/css-layout + * * css-layout based on http://www.w3.org/TR/css3-flexbox/ + * --------------------------------------------------------------------------- + */ + + +#import +#import +#import "JUFLXLayoutDefine.h" + +FOUNDATION_EXTERN CGFloat const JUFLXLayoutFloatUnDefined; + +/** + * Check -> http://www.w3.org/TR/css3-flexbox/#flex-direction-property + */ +typedef NS_ENUM(NSInteger, JUFLXLayoutDirection){ + /** + * inlineCSS -> row, → + */ + JUFLXLayoutDirectionRow = CSS_FLEX_DIRECTION_ROW, + /** + * inlineCSS -> row-reverse, ← + */ + JUFLXLayoutDirectionRowReverse = CSS_FLEX_DIRECTION_ROW_REVERSE, + /** + * inlineCSS -> column, ⬇️ + */ + JUFLXLayoutDirectionColumn = CSS_FLEX_DIRECTION_COLUMN, + /** + * inlineCSS -> column-reverse, ↑ + */ + JUFLXLayoutDirectionColumnReverse = CSS_FLEX_DIRECTION_COLUMN_REVERSE, +}; + +/** + * Check -> http://www.w3.org/TR/css3-flexbox/#propdef-align-items + * Check -> http://www.w3.org/TR/css3-flexbox/#propdef-align-content + * Check -> http://www.w3.org/TR/css3-flexbox/#propdef-align-self + */ +typedef NS_ENUM(NSInteger, JUFLXLayoutAlignment){ + /** + * inlineCSS -> auto + */ + JUFLXLayoutAlignmentAuto = CSS_ALIGN_AUTO, + /** + * inlineCSS -> flex-start + */ + JUFLXLayoutAlignmentStart = CSS_ALIGN_FLEX_START, + /** + * inlineCSS -> center + */ + JUFLXLayoutAlignmentCenter = CSS_ALIGN_CENTER, + /** + * inlineCSS -> flex-end + */ + JUFLXLayoutAlignmentEnd = CSS_ALIGN_FLEX_END, + /** + * inlineCSS -> stretch + */ + JUFLXLayoutAlignmentStretch = CSS_ALIGN_STRETCH +}; + +/** + * Check -> http://www.w3.org/TR/css3-flexbox/#propdef-justify-content + */ +typedef NS_ENUM(NSInteger, JUFLXLayoutJustifyContent){ + /** + * inlineCSS -> flex-start + */ + JUFLXLayoutJustifyContentStart = CSS_JUSTIFY_FLEX_START, + /** + * inlineCSS -> center + */ + JUFLXLayoutJustifyContentCenter = CSS_JUSTIFY_CENTER, + /** + * inlineCSS -> flex-end + */ + JUFLXLayoutJustifyContentEnd = CSS_JUSTIFY_FLEX_END, + /** + * inlineCSS -> space-between + */ + JUFLXLayoutJustifyContentBetween = CSS_JUSTIFY_SPACE_BETWEEN, + /** + * inlineCSS -> space-around + */ + JUFLXLayoutJustifyContentAround = CSS_JUSTIFY_SPACE_AROUND +}; + + + +@interface JUFLXNode : NSObject { +@public + BOOL _dirty; +} + +/** + * layout.c's node, the model of css box. + */ +@property (nonatomic, assign, readonly) css_node_t *node; + +/** + * The view initilized with. + */ +@property (nonatomic, weak, readonly) UIView *view; + +/** + * After node layout, the node's frame of the whole calculation. + */ +@property (nonatomic, assign, readonly) CGRect frame; + +/** + * The node's children node. + */ +@property (nonatomic, strong) NSArray *childNodes; + +/** + * Default is view's frame's origin + */ +@property (nonatomic, assign) CGPoint viewOrigin; + +/* + * --------------------------------------------------------------------------- + * As Container's property + * --------------------------------------------------------------------------- + */ + +/** + * If use flex box relative layout + * Default is NO + */ +@property (nonatomic, assign) BOOL absolute; + +/** + * When the position is absolute, use this adjust the position with father + * Default is {0, 0, 0, 0} + */ +@property (nonatomic, assign) UIEdgeInsets absoluteEdges; + +/** + * Check -> http://www.w3.org/TR/css3-flexbox/#flex-direction-property + * inlineCSS -> flex-direction + * Default is row + */ +@property (nonatomic, assign) JUFLXLayoutDirection direction; + +/** + * Check -> http://www.w3.org/TR/css3-flexbox/#propdef-align-items + * inlineCSS -> align-items + * Default is stretch + */ +@property (nonatomic, assign) JUFLXLayoutAlignment alignItems; + +/** + * Check -> http://www.w3.org/TR/css3-flexbox/#propdef-align-content + * inlineCSS -> align-content + * Default is stretch + * Here we don't support the between and around + */ +@property (nonatomic, assign) JUFLXLayoutAlignment alignContent; + +/** + * Check -> http://www.w3.org/TR/css3-flexbox/#propdef-justify-content + * inlineCSS -> justify-content + * Default is start + */ +@property (nonatomic, assign) JUFLXLayoutJustifyContent justifyContent; + +/** + * Check -> http://www.w3.org/TR/css3-flexbox/#flex-wrap-property + * When the container size doesn't satisfy, if use a new depends on this. + * inlineCSS -> flex-wrap + * Here we don't support wrap-reverse + */ +@property (nonatomic, assign) BOOL flexWrap; + + +/* + * --------------------------------------------------------------------------- + * As Child's property + * --------------------------------------------------------------------------- + */ + +/** + * Check -> http://www.w3.org/TR/css3-flexbox/#propdef-align-self + * inlineCSS -> align-self + * Default is auto, means depend on containers' alignItems; + */ +@property (nonatomic, assign) JUFLXLayoutAlignment alignSelf; + +/** + * Means two thing: 1. If self use the remaining space 2. how much would u share with others + * Flex-grow, eg: A node has three children---a,b,c; a.flex = 1, b.flex = 2, c.flex = 1, then a's size will be 1 / (1 + 2 + 1), + * b is 2 / (1 + 2 + 1), c is 1 / (1 + 2 + 1) + * inlineCSS -> flex + * Here we only support flex-grow as flex, not include shrink. + * Default is 0 + */ +@property (nonatomic, assign) CGFloat flex; + +/* + * --------------------------------------------------------------------------- + * As box's property + * --------------------------------------------------------------------------- + */ + +/** + * The style dimensions, default is the view's size, if you set it to {nan, nan}, + * The result frame depends on children's total size, so the children's size should be measured. + * inlineCSS ->size, width, height + * It won't be affected by JUFLXLayoutAlignment + */ +@property (nonatomic, assign) CGSize dimensions; + +/** + * ensure the min dimension of the view size. + * inlineCSS -> min-width, min-height + * Default is {0,0} + */ +@property (nonatomic, assign) CGSize minDimensions; + +/** + * ensure the max dimension of the view size. + * inlineCSS -> max-width, max-height + * Default is {0,0} + */ +@property (nonatomic, assign) CGSize maxDimensions; + +/** + * The margin of the view. + * inlineCSS -> margin, margin-top, margin-left, margin-bottom, margin-right + */ +@property (nonatomic, assign) UIEdgeInsets margin; + +/** + * The padding of the view. + * inlineCSS -> padding, padding-top, padding-left, padding-bottom, padding-right + */ +@property (nonatomic, assign) UIEdgeInsets padding; + +/** + * When encouter the view size should be calculated like text size, use this block. + * If direction is row, then width is the parent's node's frame's width, otherwise is nan. + * It will be affected by JUFLXLayoutAlignment + */ +@property (nonatomic, copy) CGSize (^measure)(CGFloat width); + +/** + * If isSizeToFit == YES, the measure block CGSize (^measure)(CGFloat width) will returned by view's + * sizeThatFits: size, the property will be override by measure block; + * Default is YES; + * It will be affected by JUFLXLayoutAlignment + * inlineCSS -> sizetofit: 1 + */ +@property (nonatomic, assign, getter=isSizeToFit) BOOL sizeToFit; + ++ (instancetype)nodeWithView:(UIView *)view; + +/** + * Create a node + * + * @param view the root view + * @param childNodes an array of JUFLXNodes + * + * @return node + */ ++ (instancetype)nodeWithView:(UIView *)view children:(NSArray *)childNodes; + +/** + * Copy the node attributes to a new view and children + * + * @param view another view + * + * @return a copy node not include the measure block + */ +- (instancetype)copyNodeWithView:(UIView *)view; +- (instancetype)copyNodeWithView:(UIView *)view + children:(NSArray *)childNodes; + + +- (instancetype)initWithView:(UIView *)view; +- (instancetype)initWithView:(UIView *)view children:(NSArray *)childNodes; + +/** + * Bind the node's property to inline css + * + * @param inlineCSS + * @see JUFLXCSSParser to learn the writing rule; + */ +- (void)bindingInlineCSS:(NSString *)inlineCSS; + +/** + * Manually layout the node + * + * @param aysnc move the node calculation back thread + * @param block completion + */ +- (void)layoutAsync:(BOOL)async completionBlock:(void(^)(CGRect frame))block; + +/** + * Layout the view tree if aysnc + */ +- (void)layoutAsync:(BOOL)async; + +/** + * Layout the view tree async + */ +- (void)layout; + +/** + * If log, use NSLog, default is NO; + */ +@property (nonatomic, assign) BOOL debugLogEnabled; + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXNode.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXNode.m new file mode 100644 index 00000000..bdce16d6 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXNode.m @@ -0,0 +1,418 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "JUFLXNode.h" +#import "UIView+JUFLXNode.h" +#import +#import "JUFLXCSSParser.h" + +@interface UIView (JUFLXNodeSetter) + +- (void)setJu_flxNode:(JUFLXNode *)node; +- (NodeDidFinishLayout)ju_flxNodeDidFinishLayoutBlock; + +@end + +CGFloat const JUFLXLayoutFloatUnDefined = CSS_UNDEFINED; + +static bool alwaysDirty(void *context) { + JUFLXNode *self = (__bridge JUFLXNode *)context; + return self->_dirty; +} + +static css_node_t *getChild(void *context, int i) { + JUFLXNode *self = (__bridge JUFLXNode *)context; + JUFLXNode *child = self.childNodes[i]; + return child.node; +} + +static css_dim_t measureNode(void *context, float width) { + JUFLXNode *self = (__bridge JUFLXNode *)context; + CGSize size = self.measure(width); + return (css_dim_t){ size.width, size.height }; +} + +@implementation JUFLXNode { + css_node_t *_node; + NSArray *_childNodes; + CGPoint _viewOrigin; +} + +@synthesize node = _node, dimensions = _dimensions, view = _view, viewOrigin = _viewOrigin; + +- (void)dealloc { + free_css_node(_node); +} + +- (instancetype)init { + return [self initWithView:[UIView new]]; +} + +- (instancetype)initWithView:(UIView *)view { + return [self initWithView:view children:nil]; +} + +- (instancetype)initWithView:(UIView *)view children:(NSArray *)childNodes { + if (self = [super init]) { + _debugLogEnabled = NO; + _dirty = YES; + _node = new_css_node(); + _node->context = (__bridge void *)self; + _node->is_dirty = alwaysDirty; + _node->get_child = getChild; + + //as container initial + self.absolute = NO; + self.absoluteEdges = UIEdgeInsetsZero; + self.direction = JUFLXLayoutDirectionColumn; + self.alignItems = JUFLXLayoutAlignmentStretch; + self.alignContent = JUFLXLayoutAlignmentStretch; + self.justifyContent = JUFLXLayoutJustifyContentStart; + self.flexWrap = NO; + + //as child initial + self.alignSelf = JUFLXLayoutAlignmentAuto; + self.margin = UIEdgeInsetsZero; + self.padding = UIEdgeInsetsZero; + self.flex = 0; + self.sizeToFit = NO; + + _view = view; + _viewOrigin = view.frame.origin; + [_view setJu_flxNode:self]; + + self.childNodes = childNodes; + } + + return self; +} + ++ (instancetype)nodeWithView:(UIView *)view { + return [self nodeWithView:view children:nil]; +} + ++ (instancetype)nodeWithView:(UIView *)view children:(NSArray *)childNodes { + return [[[self class] alloc] initWithView:view children:(NSArray *)childNodes]; +} + +- (instancetype)copyNodeWithView:(UIView *)view { + return [self copyNodeWithView:view children:nil]; +} + +- (instancetype)copyNodeWithView:(UIView *)view children:(NSArray *)childNodes { + JUFLXNode *node = [[self class] nodeWithView:view children:childNodes]; + node.direction = self.direction; + node.alignItems = self.alignItems; + node.alignContent = self.alignContent; + node.justifyContent = self.justifyContent; + node.flexWrap = self.flexWrap; + node.alignSelf = self.alignSelf; + node.flex = self.flex; + node.dimensions = self.dimensions; + node.minDimensions = self.minDimensions; + node.maxDimensions = self.maxDimensions; + node.margin = self.margin; + node.padding = self.padding; + node.sizeToFit = self.sizeToFit; + + return node; +} + +- (void)setChildNodes:(NSArray *)childNodes { + [self _resetOriginNodeViews]; + _childNodes = childNodes; + _node->children_count = (int)_childNodes.count; + [self generateViewTreeWithView:_view childNodes:_childNodes]; +} + +- (void)generateViewTreeWithView:(UIView *)view childNodes:(NSArray *)childNodes { + for (JUFLXNode *childNode in childNodes) { + [view addSubview:childNode.view]; + // only generate the node has child nodes + if ([childNode isContainer]) { + [self generateViewTreeWithView:childNode.view childNodes:childNode.childNodes]; + } + } +} + +- (BOOL)isContainer { + return _childNodes.count > 0; +} + +- (CGRect)frame { + return (CGRect) { + .origin.x = self.node->layout.position[CSS_LEFT] + _viewOrigin.x, + .origin.y = self.node->layout.position[CSS_TOP] + _viewOrigin.y, + .size.width = self.node->layout.dimensions[CSS_WIDTH], + .size.height = self.node->layout.dimensions[CSS_HEIGHT] + }; +} + +- (void)_resetOriginNodeViews { + for (JUFLXNode *subNode in _childNodes) { + if ([subNode isContainer]) { + [subNode _resetOriginNodeViews]; + } + [subNode.view removeFromSuperview]; + } +} + +- (void)_layoutWithNode { + NSTimeInterval start = CFAbsoluteTimeGetCurrent(); + + [self _resetNode]; + layoutNode(_node, self.dimensions.width, _node->style.direction); + + if (_debugLogEnabled) { + NSLog(@"%@ layout all nodes takes time %f \n on thread %@", NSStringFromClass(self.class), CFAbsoluteTimeGetCurrent() - start, [NSThread currentThread]); + } +} + +- (void)_assignNodeFrame { + self.view.frame = self.frame; + + if (self.view.ju_flxNodeDidFinishLayoutBlock) { + self.view.ju_flxNodeDidFinishLayoutBlock(self); + } + + for (JUFLXNode *subNode in _childNodes) { + if ([subNode isContainer]) { + [subNode _assignNodeFrame]; + } else { + NSLog(@"subNode frame is %@", NSStringFromCGRect(subNode.frame)); + subNode.view.frame = subNode.frame; + + if (subNode.view.ju_flxNodeDidFinishLayoutBlock) { + subNode.view.ju_flxNodeDidFinishLayoutBlock(subNode); + } + } + } +} + +- (void)_resetNode { + for (JUFLXNode *subNode in _childNodes) { + [subNode _resetNode]; + } + + self.node->layout.position[CSS_LEFT] = 0; + self.node->layout.position[CSS_TOP] = 0; + self.node->layout.position[CSS_RIGHT] = 0; + self.node->layout.position[CSS_BOTTOM] = 0; + + self.node->layout.dimensions[CSS_WIDTH] = CSS_UNDEFINED; + self.node->layout.dimensions[CSS_HEIGHT] = CSS_UNDEFINED; +} + +- (void)layoutAsync:(BOOL)aysnc completionBlock:(void(^)(CGRect frame))block { + _dirty = YES; + if (aysnc) { + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{ + [self _layoutWithNode]; + dispatch_async(dispatch_get_main_queue(), ^{ + [self _assignNodeFrame]; + _dirty = NO; + if (block) { + block(self.frame); + } + }); + }); + } else { + [self _layoutWithNode]; + [self _assignNodeFrame]; + _dirty = NO; + if (block) { + block(self.frame); + } + } +} + +- (void)layoutAsync:(BOOL)aysnc { + [self layoutAsync:aysnc completionBlock:NULL]; +} + +- (void)layout { + [self layoutAsync:NO completionBlock:NULL]; +} + +- (void)setNeedsLayout { + if (_dirty) { + [self layout]; + } +} + +- (void)setAbsolute:(BOOL)absolute { + if (_absolute == absolute) return; + _absolute = absolute; + _node->style.position_type = _absolute ? CSS_POSITION_ABSOLUTE : CSS_POSITION_RELATIVE; + _dirty = YES; +} + +- (void)setAbsoluteEdges:(UIEdgeInsets)absoluteEdges { + if (UIEdgeInsetsEqualToEdgeInsets(_absoluteEdges, absoluteEdges)) return; + _absoluteEdges = absoluteEdges; + _node->style.position[CSS_LEFT] = _absoluteEdges.left; + _node->style.position[CSS_TOP] = _absoluteEdges.top; + _node->style.position[CSS_RIGHT] = _absoluteEdges.right; + _node->style.position[CSS_BOTTOM] = _absoluteEdges.bottom; + _dirty = YES; +} + +- (CGSize)dimensions { + if (CGSizeEqualToSize(_dimensions, CGSizeZero)) { + _dimensions = self.view.bounds.size; + _node->style.dimensions[CSS_WIDTH] = _dimensions.width; + _node->style.dimensions[CSS_HEIGHT] = _dimensions.height; + } + return _dimensions; +} + +- (void)setDimensions:(CGSize)size { + if (CGSizeEqualToSize(_dimensions, size)) return; + _dimensions = size; + _node->style.dimensions[CSS_WIDTH] = size.width; + _node->style.dimensions[CSS_HEIGHT] = size.height; + _dirty = YES; +} + +- (void)setMinDimensions:(CGSize)size { + if (CGSizeEqualToSize(_minDimensions, size)) return; + _minDimensions = size; + _node->style.minDimensions[CSS_WIDTH] = size.width; + _node->style.minDimensions[CSS_HEIGHT] = size.height; + _dirty = YES; +} + +- (void)setMaxDimensions:(CGSize)size { + if (CGSizeEqualToSize(_maxDimensions, size)) return; + _maxDimensions = size; + _node->style.maxDimensions[CSS_WIDTH] = size.width; + _node->style.maxDimensions[CSS_HEIGHT] = size.height; + _dirty = YES; +} + +- (void)setMargin:(UIEdgeInsets)margin { + if (UIEdgeInsetsEqualToEdgeInsets(_margin, margin)) return; + _margin = margin; + _node->style.margin[CSS_LEFT] = margin.left; + _node->style.margin[CSS_TOP] = margin.top; + _node->style.margin[CSS_RIGHT] = margin.right; + _node->style.margin[CSS_BOTTOM] = margin.bottom; + _dirty = YES; +} + +- (void)setPadding:(UIEdgeInsets)padding { + if (UIEdgeInsetsEqualToEdgeInsets(_padding, padding)) return; + _padding = padding; + _node->style.padding[CSS_LEFT] = padding.left; + _node->style.padding[CSS_TOP] = padding.top; + _node->style.padding[CSS_RIGHT] = padding.right; + _node->style.padding[CSS_BOTTOM] = padding.bottom; + _dirty = YES; +} + +- (void)setDirection:(JUFLXLayoutDirection)direction { + if (_direction == direction) return; + _direction = direction; + _node->style.flex_direction = (int)_direction; + _dirty = YES; +} + +- (void)setAlignContent:(JUFLXLayoutAlignment)alignContent { + if (_alignContent == alignContent) return; + _alignContent = alignContent; + _node->style.align_content = (int)alignContent; + _dirty = YES; +} + +- (void)setAlignItems:(JUFLXLayoutAlignment)alignItems { + if (_alignItems == alignItems) return; + _alignItems = alignItems; + _node->style.align_items = (int)_alignItems; + _dirty = YES; +} + +- (void)setJustifyContent:(JUFLXLayoutJustifyContent)justifyContent { + if (_justifyContent == justifyContent) return; + _justifyContent = justifyContent; + _node->style.justify_content = (int)_justifyContent; + _dirty = YES; +} + +- (void)setFlexWrap:(BOOL)flexWrap { + if (_flexWrap == flexWrap) return; + _flexWrap = flexWrap; + _node->style.flex_wrap = _flexWrap; + _dirty = YES; +} + +- (void)setAlignSelf:(JUFLXLayoutAlignment)alignSelf { + if (_alignSelf == alignSelf) return; + _alignSelf = alignSelf; + _node->style.align_self = (int)_alignSelf; + _dirty = YES; +} + +- (void)setFlex:(CGFloat)flex { + if (_flex == flex) return; + _flex = flex; + _node->style.flex = _flex; + _dirty = YES; +} + +- (void)setMeasure:(CGSize (^)(CGFloat))measure { + if (measure) { + _measure = [measure copy]; + _node->measure = (_measure != nil ? measureNode : NULL); + } +} + +- (void)setSizeToFit:(BOOL)sizeToFit { + if (_sizeToFit == sizeToFit) return; + _sizeToFit = sizeToFit; + if (_sizeToFit) { + __weak typeof(self) wself = self; + self.measure = ^CGSize(CGFloat width) { + return [wself.view sizeThatFits:CGSizeMake(width, CGFLOAT_MAX)]; + }; + } + _dirty = YES; +} + +- (void)bindingInlineCSS:(NSString *)inlineCSS { + [JUFLXCSSParser parseInlineCSS:inlineCSS toNode:self]; +} + +- (NSString *)description { + NSString *selfDescription = [super description]; + if (_debugLogEnabled) { + selfDescription = [NSString stringWithFormat:@"{node's view is %@ and child nodes is \n %@", self.view, self.childNodes]; + print_css_node(_node, CSS_PRINT_STYLE | CSS_PRINT_CHILDREN | CSS_PRINT_LAYOUT); + + } + return selfDescription; +} + +@end + +@implementation UIView (JUFLXNodeSetter) + +- (void)setJu_flxNode:(JUFLXNode *)node { + JUFLXNode *currentNode = objc_getAssociatedObject(self, &JUFLXNodeUIViewNodeKey); + + if (currentNode && node != currentNode) { + NSLog(@"<---JUFLXNode Warning!--->, You are trying set a view %@ with another node %@, pay attention to this view's subViews", self, node); + } + + objc_setAssociatedObject(self, &JUFLXNodeUIViewNodeKey, node, OBJC_ASSOCIATION_RETAIN_NONATOMIC); +} + +- (NodeDidFinishLayout)ju_flxNodeDidFinishLayoutBlock { + return objc_getAssociatedObject(self, &JUFLXNodeUIViewDidFinishBlockKey); +} + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXTargeNamespace.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXTargeNamespace.h new file mode 100644 index 00000000..5359a4db --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/JUFLXTargeNamespace.h @@ -0,0 +1,39 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#if defined(JUFLX_LAYOUT_NAMESPACE) + + #define _JUFLX_NS_SYMBOL_INNER(namespace, symbol) namespace ## _ ## symbol + #define _JUFLX_NS_SYMBOL_MIDDLE(namespace, symbol) _JUFLX_NS_SYMBOL_INNER(namespace, symbol) + #define _JUFLX_NS_SYMBOL(symbol) _JUFLX_NS_SYMBOL_MIDDLE(JUFLX_LAYOUT_NAMESPACE, symbol) + + #define _JUFLX_NS_STRING_INNER(namespace) #namespace + #define _JUFLX_NS_STRING_MIDDLE(namespace) _JUFLX_NS_STRING_INNER(namespace) + #define JUFLX_LAYOUT_NAMESPACE_STRING _JUFLX_NS_STRING_MIDDLE(JUFLX_LAYOUT_NAMESPACE) + + #define css_direction_t _JUFLX_NS_SYMBOL(css_direction_t) + #define css_flex_direction_t _JUFLX_NS_SYMBOL(css_flex_direction_t) + #define css_justify_t _JUFLX_NS_SYMBOL(css_justify_t) + #define css_align_t _JUFLX_NS_SYMBOL(css_align_t) + #define css_position_type_t _JUFLX_NS_SYMBOL(css_position_type_t) + #define css_wrap_type_t _JUFLX_NS_SYMBOL(css_wrap_type_t) + #define css_position_t _JUFLX_NS_SYMBOL(css_position_t) + #define css_dimension_t _JUFLX_NS_SYMBOL(css_dimension_t) + #define css_layout_t _JUFLX_NS_SYMBOL(css_layout_t) + #define css_dim_t _JUFLX_NS_SYMBOL(css_dim_t) + #define css_style_t _JUFLX_NS_SYMBOL(css_style_t) + #define css_node_t _JUFLX_NS_SYMBOL(css_node_t) + #define new_css_node _JUFLX_NS_SYMBOL(new_css_node) + #define init_css_node _JUFLX_NS_SYMBOL(init_css_node) + #define free_css_node _JUFLX_NS_SYMBOL(free_css_node) + #define css_print_options_t _JUFLX_NS_SYMBOL(css_print_options_t) + #define print_css_node _JUFLX_NS_SYMBOL(print_css_node) + #define layoutNode _JUFLX_NS_SYMBOL(layoutNode) + #define isUndefined _JUFLX_NS_SYMBOL(isUndefined) + +#endif diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/Layout.c b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/Layout.c new file mode 100644 index 00000000..cccf3685 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/Layout.c @@ -0,0 +1,1141 @@ +/** + * Copyright (c) 2014, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +#include +#include +#include +#include + +#include "JUFLXLayoutDefine.h" + +#ifdef _MSC_VER +#include +#define isnan _isnan + +/* define fmaxf if < VC12 */ +#if _MSC_VER < 1800 +__forceinline const float fmaxf(const float a, const float b) { + return (a > b) ? a : b; +} +#endif +#endif + +bool isUndefined(float value) { + return isnan(value); +} + +static bool eq(float a, float b) { + if (isUndefined(a)) { + return isUndefined(b); + } + return fabs(a - b) < 0.0001; +} + +void init_css_node(css_node_t *node) { + node->style.align_items = CSS_ALIGN_STRETCH; + node->style.align_content = CSS_ALIGN_FLEX_START; + + node->style.direction = CSS_DIRECTION_INHERIT; + node->style.flex_direction = CSS_FLEX_DIRECTION_COLUMN; + + // Some of the fields default to undefined and not 0 + node->style.dimensions[CSS_WIDTH] = CSS_UNDEFINED; + node->style.dimensions[CSS_HEIGHT] = CSS_UNDEFINED; + + node->style.minDimensions[CSS_WIDTH] = CSS_UNDEFINED; + node->style.minDimensions[CSS_HEIGHT] = CSS_UNDEFINED; + + node->style.maxDimensions[CSS_WIDTH] = CSS_UNDEFINED; + node->style.maxDimensions[CSS_HEIGHT] = CSS_UNDEFINED; + + node->style.position[CSS_LEFT] = CSS_UNDEFINED; + node->style.position[CSS_TOP] = CSS_UNDEFINED; + node->style.position[CSS_RIGHT] = CSS_UNDEFINED; + node->style.position[CSS_BOTTOM] = CSS_UNDEFINED; + + node->style.margin[CSS_START] = CSS_UNDEFINED; + node->style.margin[CSS_END] = CSS_UNDEFINED; + node->style.padding[CSS_START] = CSS_UNDEFINED; + node->style.padding[CSS_END] = CSS_UNDEFINED; + node->style.border[CSS_START] = CSS_UNDEFINED; + node->style.border[CSS_END] = CSS_UNDEFINED; + + node->layout.dimensions[CSS_WIDTH] = CSS_UNDEFINED; + node->layout.dimensions[CSS_HEIGHT] = CSS_UNDEFINED; + + // Such that the comparison is always going to be false + node->layout.last_requested_dimensions[CSS_WIDTH] = -1; + node->layout.last_requested_dimensions[CSS_HEIGHT] = -1; + node->layout.last_parent_max_width = -1; + node->layout.last_direction = (css_direction_t)-1; + node->layout.should_update = true; +} + +css_node_t *new_css_node() { + css_node_t *node = (css_node_t *)calloc(1, sizeof(*node)); + init_css_node(node); + return node; +} + +void free_css_node(css_node_t *node) { + free(node); +} + +static void indent(int n) { + for (int i = 0; i < n; ++i) { + printf(" "); + } +} + +static void print_number_0(const char *str, float number) { + if (!eq(number, 0)) { + printf("%s: %g, ", str, number); + } +} + +static void print_number_nan(const char *str, float number) { + if (!isnan(number)) { + printf("%s: %g, ", str, number); + } +} + +static bool four_equal(float four[4]) { + return + eq(four[0], four[1]) && + eq(four[0], four[2]) && + eq(four[0], four[3]); +} + + +static void print_css_node_rec( + css_node_t *node, + css_print_options_t options, + int level +) { + indent(level); + printf("{"); + + if (node->print) { + node->print(node->context); + } + + if (options & CSS_PRINT_LAYOUT) { + printf("layout: {"); + printf("width: %g, ", node->layout.dimensions[CSS_WIDTH]); + printf("height: %g, ", node->layout.dimensions[CSS_HEIGHT]); + printf("top: %g, ", node->layout.position[CSS_TOP]); + printf("left: %g", node->layout.position[CSS_LEFT]); + printf("}, "); + } + + if (options & CSS_PRINT_STYLE) { + if (node->style.flex_direction == CSS_FLEX_DIRECTION_COLUMN) { + printf("flexDirection: 'column', "); + } else if (node->style.flex_direction == CSS_FLEX_DIRECTION_COLUMN_REVERSE) { + printf("flexDirection: 'columnReverse', "); + } else if (node->style.flex_direction == CSS_FLEX_DIRECTION_ROW) { + printf("flexDirection: 'row', "); + } else if (node->style.flex_direction == CSS_FLEX_DIRECTION_ROW_REVERSE) { + printf("flexDirection: 'rowReverse', "); + } + + if (node->style.justify_content == CSS_JUSTIFY_CENTER) { + printf("justifyContent: 'center', "); + } else if (node->style.justify_content == CSS_JUSTIFY_FLEX_END) { + printf("justifyContent: 'flex-end', "); + } else if (node->style.justify_content == CSS_JUSTIFY_SPACE_AROUND) { + printf("justifyContent: 'space-around', "); + } else if (node->style.justify_content == CSS_JUSTIFY_SPACE_BETWEEN) { + printf("justifyContent: 'space-between', "); + } + + if (node->style.align_items == CSS_ALIGN_CENTER) { + printf("alignItems: 'center', "); + } else if (node->style.align_items == CSS_ALIGN_FLEX_END) { + printf("alignItems: 'flex-end', "); + } else if (node->style.align_items == CSS_ALIGN_STRETCH) { + printf("alignItems: 'stretch', "); + } + + if (node->style.align_content == CSS_ALIGN_CENTER) { + printf("alignContent: 'center', "); + } else if (node->style.align_content == CSS_ALIGN_FLEX_END) { + printf("alignContent: 'flex-end', "); + } else if (node->style.align_content == CSS_ALIGN_STRETCH) { + printf("alignContent: 'stretch', "); + } + + if (node->style.align_self == CSS_ALIGN_FLEX_START) { + printf("alignSelf: 'flex-start', "); + } else if (node->style.align_self == CSS_ALIGN_CENTER) { + printf("alignSelf: 'center', "); + } else if (node->style.align_self == CSS_ALIGN_FLEX_END) { + printf("alignSelf: 'flex-end', "); + } else if (node->style.align_self == CSS_ALIGN_STRETCH) { + printf("alignSelf: 'stretch', "); + } + + print_number_nan("flex", node->style.flex); + + if (four_equal(node->style.margin)) { + print_number_0("margin", node->style.margin[CSS_LEFT]); + } else { + print_number_0("marginLeft", node->style.margin[CSS_LEFT]); + print_number_0("marginRight", node->style.margin[CSS_RIGHT]); + print_number_0("marginTop", node->style.margin[CSS_TOP]); + print_number_0("marginBottom", node->style.margin[CSS_BOTTOM]); + print_number_0("marginStart", node->style.margin[CSS_START]); + print_number_0("marginEnd", node->style.margin[CSS_END]); + } + + if (four_equal(node->style.padding)) { + print_number_0("padding", node->style.margin[CSS_LEFT]); + } else { + print_number_0("paddingLeft", node->style.padding[CSS_LEFT]); + print_number_0("paddingRight", node->style.padding[CSS_RIGHT]); + print_number_0("paddingTop", node->style.padding[CSS_TOP]); + print_number_0("paddingBottom", node->style.padding[CSS_BOTTOM]); + print_number_0("paddingStart", node->style.padding[CSS_START]); + print_number_0("paddingEnd", node->style.padding[CSS_END]); + } + + if (four_equal(node->style.border)) { + print_number_0("borderWidth", node->style.border[CSS_LEFT]); + } else { + print_number_0("borderLeftWidth", node->style.border[CSS_LEFT]); + print_number_0("borderRightWidth", node->style.border[CSS_RIGHT]); + print_number_0("borderTopWidth", node->style.border[CSS_TOP]); + print_number_0("borderBottomWidth", node->style.border[CSS_BOTTOM]); + print_number_0("borderStartWidth", node->style.border[CSS_START]); + print_number_0("borderEndWidth", node->style.border[CSS_END]); + } + + print_number_nan("width", node->style.dimensions[CSS_WIDTH]); + print_number_nan("height", node->style.dimensions[CSS_HEIGHT]); + + if (node->style.position_type == CSS_POSITION_ABSOLUTE) { + printf("position: 'absolute', "); + } + + print_number_nan("left", node->style.position[CSS_LEFT]); + print_number_nan("right", node->style.position[CSS_RIGHT]); + print_number_nan("top", node->style.position[CSS_TOP]); + print_number_nan("bottom", node->style.position[CSS_BOTTOM]); + } + + if (options & CSS_PRINT_CHILDREN && node->children_count > 0) { + printf("children: [\n"); + for (int i = 0; i < node->children_count; ++i) { + print_css_node_rec(node->get_child(node->context, i), options, level + 1); + } + indent(level); + printf("]},\n"); + } else { + printf("},\n"); + } +} + +void print_css_node(css_node_t *node, css_print_options_t options) { + print_css_node_rec(node, options, 0); +} + + +static css_position_t leading[4] = { + /* CSS_FLEX_DIRECTION_COLUMN = */ CSS_TOP, + /* CSS_FLEX_DIRECTION_COLUMN_REVERSE = */ CSS_BOTTOM, + /* CSS_FLEX_DIRECTION_ROW = */ CSS_LEFT, + /* CSS_FLEX_DIRECTION_ROW_REVERSE = */ CSS_RIGHT +}; +static css_position_t trailing[4] = { + /* CSS_FLEX_DIRECTION_COLUMN = */ CSS_BOTTOM, + /* CSS_FLEX_DIRECTION_COLUMN_REVERSE = */ CSS_TOP, + /* CSS_FLEX_DIRECTION_ROW = */ CSS_RIGHT, + /* CSS_FLEX_DIRECTION_ROW_REVERSE = */ CSS_LEFT +}; +static css_position_t pos[4] = { + /* CSS_FLEX_DIRECTION_COLUMN = */ CSS_TOP, + /* CSS_FLEX_DIRECTION_COLUMN_REVERSE = */ CSS_BOTTOM, + /* CSS_FLEX_DIRECTION_ROW = */ CSS_LEFT, + /* CSS_FLEX_DIRECTION_ROW_REVERSE = */ CSS_RIGHT +}; +static css_dimension_t dim[4] = { + /* CSS_FLEX_DIRECTION_COLUMN = */ CSS_HEIGHT, + /* CSS_FLEX_DIRECTION_COLUMN_REVERSE = */ CSS_HEIGHT, + /* CSS_FLEX_DIRECTION_ROW = */ CSS_WIDTH, + /* CSS_FLEX_DIRECTION_ROW_REVERSE = */ CSS_WIDTH +}; + +static bool isRowDirection(css_flex_direction_t flex_direction) { + return flex_direction == CSS_FLEX_DIRECTION_ROW || + flex_direction == CSS_FLEX_DIRECTION_ROW_REVERSE; +} + +static bool isColumnDirection(css_flex_direction_t flex_direction) { + return flex_direction == CSS_FLEX_DIRECTION_COLUMN || + flex_direction == CSS_FLEX_DIRECTION_COLUMN_REVERSE; +} + +static float getLeadingMargin(css_node_t *node, css_flex_direction_t axis) { + if (isRowDirection(axis) && !isUndefined(node->style.margin[CSS_START])) { + return node->style.margin[CSS_START]; + } + + return node->style.margin[leading[axis]]; +} + +static float getTrailingMargin(css_node_t *node, css_flex_direction_t axis) { + if (isRowDirection(axis) && !isUndefined(node->style.margin[CSS_END])) { + return node->style.margin[CSS_END]; + } + + return node->style.margin[trailing[axis]]; +} + +static float getLeadingPadding(css_node_t *node, css_flex_direction_t axis) { + if (isRowDirection(axis) && + !isUndefined(node->style.padding[CSS_START]) && + node->style.padding[CSS_START] >= 0) { + return node->style.padding[CSS_START]; + } + + if (node->style.padding[leading[axis]] >= 0) { + return node->style.padding[leading[axis]]; + } + + return 0; +} + +static float getTrailingPadding(css_node_t *node, css_flex_direction_t axis) { + if (isRowDirection(axis) && + !isUndefined(node->style.padding[CSS_END]) && + node->style.padding[CSS_END] >= 0) { + return node->style.padding[CSS_END]; + } + + if (node->style.padding[trailing[axis]] >= 0) { + return node->style.padding[trailing[axis]]; + } + + return 0; +} + +static float getLeadingBorder(css_node_t *node, css_flex_direction_t axis) { + if (isRowDirection(axis) && + !isUndefined(node->style.border[CSS_START]) && + node->style.border[CSS_START] >= 0) { + return node->style.border[CSS_START]; + } + + if (node->style.border[leading[axis]] >= 0) { + return node->style.border[leading[axis]]; + } + + return 0; +} + +static float getTrailingBorder(css_node_t *node, css_flex_direction_t axis) { + if (isRowDirection(axis) && + !isUndefined(node->style.border[CSS_END]) && + node->style.border[CSS_END] >= 0) { + return node->style.border[CSS_END]; + } + + if (node->style.border[trailing[axis]] >= 0) { + return node->style.border[trailing[axis]]; + } + + return 0; +} + +static float getLeadingPaddingAndBorder(css_node_t *node, css_flex_direction_t axis) { + return getLeadingPadding(node, axis) + getLeadingBorder(node, axis); +} + +static float getTrailingPaddingAndBorder(css_node_t *node, css_flex_direction_t axis) { + return getTrailingPadding(node, axis) + getTrailingBorder(node, axis); +} + +static float getBorderAxis(css_node_t *node, css_flex_direction_t axis) { + return getLeadingBorder(node, axis) + getTrailingBorder(node, axis); +} + +static float getMarginAxis(css_node_t *node, css_flex_direction_t axis) { + return getLeadingMargin(node, axis) + getTrailingMargin(node, axis); +} + +static float getPaddingAndBorderAxis(css_node_t *node, css_flex_direction_t axis) { + return getLeadingPaddingAndBorder(node, axis) + getTrailingPaddingAndBorder(node, axis); +} + +static css_position_type_t getPositionType(css_node_t *node) { + return node->style.position_type; +} + +static css_justify_t getJustifyContent(css_node_t *node) { + return node->style.justify_content; +} + +static css_align_t getAlignContent(css_node_t *node) { + return node->style.align_content; +} + +static css_align_t getAlignItem(css_node_t *node, css_node_t *child) { + if (child->style.align_self != CSS_ALIGN_AUTO) { + return child->style.align_self; + } + return node->style.align_items; +} + +static css_direction_t resolveDirection(css_node_t *node, css_direction_t parentDirection) { + css_direction_t direction = node->style.direction; + + if (direction == CSS_DIRECTION_INHERIT) { + direction = parentDirection > CSS_DIRECTION_INHERIT ? parentDirection : CSS_DIRECTION_LTR; + } + + return direction; +} + +static css_flex_direction_t getFlexDirection(css_node_t *node) { + return node->style.flex_direction; +} + +static css_flex_direction_t resolveAxis(css_flex_direction_t flex_direction, css_direction_t direction) { + if (direction == CSS_DIRECTION_RTL) { + if (flex_direction == CSS_FLEX_DIRECTION_ROW) { + return CSS_FLEX_DIRECTION_ROW_REVERSE; + } else if (flex_direction == CSS_FLEX_DIRECTION_ROW_REVERSE) { + return CSS_FLEX_DIRECTION_ROW; + } + } + + return flex_direction; +} + +static css_flex_direction_t getCrossFlexDirection(css_flex_direction_t flex_direction, css_direction_t direction) { + if (isColumnDirection(flex_direction)) { + return resolveAxis(CSS_FLEX_DIRECTION_ROW, direction); + } else { + return CSS_FLEX_DIRECTION_COLUMN; + } +} + +static float getFlex(css_node_t *node) { + return node->style.flex; +} + +static bool isFlex(css_node_t *node) { + return ( + getPositionType(node) == CSS_POSITION_RELATIVE && + getFlex(node) > 0 + ); +} + +static bool isFlexWrap(css_node_t *node) { + return node->style.flex_wrap == CSS_WRAP; +} + +static float getDimWithMargin(css_node_t *node, css_flex_direction_t axis) { + return node->layout.dimensions[dim[axis]] + + getLeadingMargin(node, axis) + + getTrailingMargin(node, axis); +} + +static bool isDimDefined(css_node_t *node, css_flex_direction_t axis) { + float value = node->style.dimensions[dim[axis]]; + return !isUndefined(value) && value > 0.0; +} + +static bool isPosDefined(css_node_t *node, css_position_t position) { + return !isUndefined(node->style.position[position]); +} + +static bool isMeasureDefined(css_node_t *node) { + return node->measure; +} + +static float getPosition(css_node_t *node, css_position_t position) { + float result = node->style.position[position]; + if (!isUndefined(result)) { + return result; + } + return 0; +} + +static float boundAxis(css_node_t *node, css_flex_direction_t axis, float value) { + float min = CSS_UNDEFINED; + float max = CSS_UNDEFINED; + + if (isColumnDirection(axis)) { + min = node->style.minDimensions[CSS_HEIGHT]; + max = node->style.maxDimensions[CSS_HEIGHT]; + } else if (isRowDirection(axis)) { + min = node->style.minDimensions[CSS_WIDTH]; + max = node->style.maxDimensions[CSS_WIDTH]; + } + + float boundValue = value; + + if (!isUndefined(max) && max >= 0.0 && boundValue > max) { + boundValue = max; + } + if (!isUndefined(min) && min >= 0.0 && boundValue < min) { + boundValue = min; + } + + return boundValue; +} + +// When the user specifically sets a value for width or height +static void setDimensionFromStyle(css_node_t *node, css_flex_direction_t axis) { + // The parent already computed us a width or height. We just skip it + if (!isUndefined(node->layout.dimensions[dim[axis]])) { + return; + } + // We only run if there's a width or height defined + if (!isDimDefined(node, axis)) { + return; + } + + // The dimensions can never be smaller than the padding and border + node->layout.dimensions[dim[axis]] = fmaxf( + boundAxis(node, axis, node->style.dimensions[dim[axis]]), + getPaddingAndBorderAxis(node, axis) + ); +} + +static void setTrailingPosition(css_node_t *node, css_node_t *child, css_flex_direction_t axis) { + child->layout.position[trailing[axis]] = node->layout.dimensions[dim[axis]] - + child->layout.dimensions[dim[axis]] - child->layout.position[pos[axis]]; + } + +// If both left and right are defined, then use left. Otherwise return +// +left or -right depending on which is defined. +static float getRelativePosition(css_node_t *node, css_flex_direction_t axis) { + float lead = node->style.position[leading[axis]]; + if (!isUndefined(lead)) { + return lead; + } + return -getPosition(node, trailing[axis]); +} + +static void layoutNodeImpl(css_node_t *node, float parentMaxWidth, css_direction_t parentDirection) { + /** START_GENERATED **/ + css_direction_t direction = resolveDirection(node, parentDirection); + css_flex_direction_t mainAxis = resolveAxis(getFlexDirection(node), direction); + css_flex_direction_t crossAxis = getCrossFlexDirection(mainAxis, direction); + css_flex_direction_t resolvedRowAxis = resolveAxis(CSS_FLEX_DIRECTION_ROW, direction); + + // Handle width and height style attributes + setDimensionFromStyle(node, mainAxis); + setDimensionFromStyle(node, crossAxis); + + // Set the resolved resolution in the node's layout + node->layout.direction = direction; + + // The position is set by the parent, but we need to complete it with a + // delta composed of the margin and left/top/right/bottom + node->layout.position[leading[mainAxis]] += getLeadingMargin(node, mainAxis) + + getRelativePosition(node, mainAxis); + node->layout.position[trailing[mainAxis]] += getTrailingMargin(node, mainAxis) + + getRelativePosition(node, mainAxis); + node->layout.position[leading[crossAxis]] += getLeadingMargin(node, crossAxis) + + getRelativePosition(node, crossAxis); + node->layout.position[trailing[crossAxis]] += getTrailingMargin(node, crossAxis) + + getRelativePosition(node, crossAxis); + + if (isMeasureDefined(node)) { + float width = CSS_UNDEFINED; + if (isDimDefined(node, resolvedRowAxis)) { + width = node->style.dimensions[CSS_WIDTH]; + } else if (!isUndefined(node->layout.dimensions[dim[resolvedRowAxis]])) { + width = node->layout.dimensions[dim[resolvedRowAxis]]; + } else { + width = parentMaxWidth - + getMarginAxis(node, resolvedRowAxis); + } + width -= getPaddingAndBorderAxis(node, resolvedRowAxis); + + // We only need to give a dimension for the text if we haven't got any + // for it computed yet. It can either be from the style attribute or because + // the element is flexible. + bool isRowUndefined = !isDimDefined(node, resolvedRowAxis) && + isUndefined(node->layout.dimensions[dim[resolvedRowAxis]]); + bool isColumnUndefined = !isDimDefined(node, CSS_FLEX_DIRECTION_COLUMN) && + isUndefined(node->layout.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]]); + + // Let's not measure the text if we already know both dimensions + if (isRowUndefined || isColumnUndefined) { + css_dim_t measureDim = node->measure( + node->context, + + width + ); + if (isRowUndefined) { + node->layout.dimensions[CSS_WIDTH] = measureDim.dimensions[CSS_WIDTH] + + getPaddingAndBorderAxis(node, resolvedRowAxis); + } + if (isColumnUndefined) { + node->layout.dimensions[CSS_HEIGHT] = measureDim.dimensions[CSS_HEIGHT] + + getPaddingAndBorderAxis(node, CSS_FLEX_DIRECTION_COLUMN); + } + } + if (node->children_count == 0) { + return; + } + } + + int i; + int ii; + css_node_t* child; + css_flex_direction_t axis; + + // Pre-fill some dimensions straight from the parent + for (i = 0; i < node->children_count; ++i) { + child = node->get_child(node->context, i); + // Pre-fill cross axis dimensions when the child is using stretch before + // we call the recursive layout pass + if (getAlignItem(node, child) == CSS_ALIGN_STRETCH && + getPositionType(child) == CSS_POSITION_RELATIVE && + !isUndefined(node->layout.dimensions[dim[crossAxis]]) && + !isDimDefined(child, crossAxis)) { + child->layout.dimensions[dim[crossAxis]] = fmaxf( + boundAxis(child, crossAxis, node->layout.dimensions[dim[crossAxis]] - + getPaddingAndBorderAxis(node, crossAxis) - + getMarginAxis(child, crossAxis)), + // You never want to go smaller than padding + getPaddingAndBorderAxis(child, crossAxis) + ); + } else if (getPositionType(child) == CSS_POSITION_ABSOLUTE) { + // Pre-fill dimensions when using absolute position and both offsets for the axis are defined (either both + // left and right or top and bottom). + for (ii = 0; ii < 2; ii++) { + axis = (ii != 0) ? CSS_FLEX_DIRECTION_ROW : CSS_FLEX_DIRECTION_COLUMN; + if (!isUndefined(node->layout.dimensions[dim[axis]]) && + !isDimDefined(child, axis) && + isPosDefined(child, leading[axis]) && + isPosDefined(child, trailing[axis])) { + child->layout.dimensions[dim[axis]] = fmaxf( + boundAxis(child, axis, node->layout.dimensions[dim[axis]] - + getPaddingAndBorderAxis(node, axis) - + getMarginAxis(child, axis) - + getPosition(child, leading[axis]) - + getPosition(child, trailing[axis])), + // You never want to go smaller than padding + getPaddingAndBorderAxis(child, axis) + ); + } + } + } + } + + float definedMainDim = CSS_UNDEFINED; + if (!isUndefined(node->layout.dimensions[dim[mainAxis]])) { + definedMainDim = node->layout.dimensions[dim[mainAxis]] - + getPaddingAndBorderAxis(node, mainAxis); + } + + // We want to execute the next two loops one per line with flex-wrap + int startLine = 0; + int endLine = 0; + // int nextOffset = 0; + int alreadyComputedNextLayout = 0; + // We aggregate the total dimensions of the container in those two variables + float linesCrossDim = 0; + float linesMainDim = 0; + int linesCount = 0; + while (endLine < node->children_count) { + // Layout non flexible children and count children by type + + // mainContentDim is accumulation of the dimensions and margin of all the + // non flexible children. This will be used in order to either set the + // dimensions of the node if none already exist, or to compute the + // remaining space left for the flexible children. + float mainContentDim = 0; + + // There are three kind of children, non flexible, flexible and absolute. + // We need to know how many there are in order to distribute the space. + int flexibleChildrenCount = 0; + float totalFlexible = 0; + int nonFlexibleChildrenCount = 0; + + float maxWidth; + for (i = startLine; i < node->children_count; ++i) { + child = node->get_child(node->context, i); + float nextContentDim = 0; + + // It only makes sense to consider a child flexible if we have a computed + // dimension for the node-> + if (!isUndefined(node->layout.dimensions[dim[mainAxis]]) && isFlex(child)) { + flexibleChildrenCount++; + totalFlexible += getFlex(child); + + // Even if we don't know its exact size yet, we already know the padding, + // border and margin. We'll use this partial information, which represents + // the smallest possible size for the child, to compute the remaining + // available space. + nextContentDim = getPaddingAndBorderAxis(child, mainAxis) + + getMarginAxis(child, mainAxis); + + } else { + maxWidth = CSS_UNDEFINED; + if (!isRowDirection(mainAxis)) { + maxWidth = parentMaxWidth - + getMarginAxis(node, resolvedRowAxis) - + getPaddingAndBorderAxis(node, resolvedRowAxis); + + if (isDimDefined(node, resolvedRowAxis)) { + maxWidth = node->layout.dimensions[dim[resolvedRowAxis]] - + getPaddingAndBorderAxis(node, resolvedRowAxis); + } + } + + // This is the main recursive call. We layout non flexible children. + if (alreadyComputedNextLayout == 0) { + layoutNode(child, maxWidth, direction); + } + + // Absolute positioned elements do not take part of the layout, so we + // don't use them to compute mainContentDim + if (getPositionType(child) == CSS_POSITION_RELATIVE) { + nonFlexibleChildrenCount++; + // At this point we know the final size and margin of the element. + nextContentDim = getDimWithMargin(child, mainAxis); + } + } + + // The element we are about to add would make us go to the next line + if (isFlexWrap(node) && + !isUndefined(node->layout.dimensions[dim[mainAxis]]) && + mainContentDim + nextContentDim > definedMainDim && + // If there's only one element, then it's bigger than the content + // and needs its own line + i != startLine) { + nonFlexibleChildrenCount--; + alreadyComputedNextLayout = 1; + break; + } + alreadyComputedNextLayout = 0; + mainContentDim += nextContentDim; + endLine = i + 1; + } + + // Layout flexible children and allocate empty space + + // In order to position the elements in the main axis, we have two + // controls. The space between the beginning and the first element + // and the space between each two elements. + float leadingMainDim = 0; + float betweenMainDim = 0; + + // The remaining available space that needs to be allocated + float remainingMainDim = 0; + if (!isUndefined(node->layout.dimensions[dim[mainAxis]])) { + remainingMainDim = definedMainDim - mainContentDim; + } else { + remainingMainDim = fmaxf(mainContentDim, 0) - mainContentDim; + } + + // If there are flexible children in the mix, they are going to fill the + // remaining space + if (flexibleChildrenCount != 0) { + float flexibleMainDim = remainingMainDim / totalFlexible; + float baseMainDim; + float boundMainDim; + + // Iterate over every child in the axis. If the flex share of remaining + // space doesn't meet min/max bounds, remove this child from flex + // calculations. + for (i = startLine; i < endLine; ++i) { + child = node->get_child(node->context, i); + if (isFlex(child)) { + baseMainDim = flexibleMainDim * getFlex(child) + + getPaddingAndBorderAxis(child, mainAxis); + boundMainDim = boundAxis(child, mainAxis, baseMainDim); + + if (baseMainDim != boundMainDim) { + remainingMainDim -= boundMainDim; + totalFlexible -= getFlex(child); + } + } + } + flexibleMainDim = remainingMainDim / totalFlexible; + + // The non flexible children can overflow the container, in this case + // we should just assume that there is no space available. + if (flexibleMainDim < 0) { + flexibleMainDim = 0; + } + // We iterate over the full array and only apply the action on flexible + // children. This is faster than actually allocating a new array that + // contains only flexible children. + for (i = startLine; i < endLine; ++i) { + child = node->get_child(node->context, i); + if (isFlex(child)) { + // At this point we know the final size of the element in the main + // dimension + child->layout.dimensions[dim[mainAxis]] = boundAxis(child, mainAxis, + flexibleMainDim * getFlex(child) + getPaddingAndBorderAxis(child, mainAxis) + ); + + maxWidth = CSS_UNDEFINED; + if (isDimDefined(node, resolvedRowAxis)) { + maxWidth = node->layout.dimensions[dim[resolvedRowAxis]] - + getPaddingAndBorderAxis(node, resolvedRowAxis); + } else if (!isRowDirection(mainAxis)) { + maxWidth = parentMaxWidth - + getMarginAxis(node, resolvedRowAxis) - + getPaddingAndBorderAxis(node, resolvedRowAxis); + } + + // And we recursively call the layout algorithm for this child + layoutNode(child, maxWidth, direction); + } + } + + // We use justifyContent to figure out how to allocate the remaining + // space available + } else { + css_justify_t justifyContent = getJustifyContent(node); + if (justifyContent == CSS_JUSTIFY_CENTER) { + leadingMainDim = remainingMainDim / 2; + } else if (justifyContent == CSS_JUSTIFY_FLEX_END) { + leadingMainDim = remainingMainDim; + } else if (justifyContent == CSS_JUSTIFY_SPACE_BETWEEN) { + remainingMainDim = fmaxf(remainingMainDim, 0); + if (flexibleChildrenCount + nonFlexibleChildrenCount - 1 != 0) { + betweenMainDim = remainingMainDim / + (flexibleChildrenCount + nonFlexibleChildrenCount - 1); + } else { + betweenMainDim = 0; + } + } else if (justifyContent == CSS_JUSTIFY_SPACE_AROUND) { + // Space on the edges is half of the space between elements + betweenMainDim = remainingMainDim / + (flexibleChildrenCount + nonFlexibleChildrenCount); + leadingMainDim = betweenMainDim / 2; + } + } + + // Position elements in the main axis and compute dimensions + + // At this point, all the children have their dimensions set. We need to + // find their position. In order to do that, we accumulate data in + // variables that are also useful to compute the total dimensions of the + // container! + float crossDim = 0; + float mainDim = leadingMainDim + + getLeadingPaddingAndBorder(node, mainAxis); + + for (i = startLine; i < endLine; ++i) { + child = node->get_child(node->context, i); + child->line_index = linesCount; + + if (getPositionType(child) == CSS_POSITION_ABSOLUTE && + isPosDefined(child, leading[mainAxis])) { + // In case the child is position absolute and has left/top being + // defined, we override the position to whatever the user said + // (and margin/border). + child->layout.position[pos[mainAxis]] = getPosition(child, leading[mainAxis]) + + getLeadingBorder(node, mainAxis) + + getLeadingMargin(child, mainAxis); + } else { + // If the child is position absolute (without top/left) or relative, + // we put it at the current accumulated offset. + child->layout.position[pos[mainAxis]] += mainDim; + + // Define the trailing position accordingly. + if (!isUndefined(node->layout.dimensions[dim[mainAxis]])) { + setTrailingPosition(node, child, mainAxis); + } + } + + // Now that we placed the element, we need to update the variables + // We only need to do that for relative elements. Absolute elements + // do not take part in that phase. + if (getPositionType(child) == CSS_POSITION_RELATIVE) { + // The main dimension is the sum of all the elements dimension plus + // the spacing. + mainDim += betweenMainDim + getDimWithMargin(child, mainAxis); + // The cross dimension is the max of the elements dimension since there + // can only be one element in that cross dimension. + crossDim = fmaxf(crossDim, boundAxis(child, crossAxis, getDimWithMargin(child, crossAxis))); + } + } + + float containerCrossAxis = node->layout.dimensions[dim[crossAxis]]; + if (isUndefined(node->layout.dimensions[dim[crossAxis]])) { + containerCrossAxis = fmaxf( + // For the cross dim, we add both sides at the end because the value + // is aggregate via a max function. Intermediate negative values + // can mess this computation otherwise + boundAxis(node, crossAxis, crossDim + getPaddingAndBorderAxis(node, crossAxis)), + getPaddingAndBorderAxis(node, crossAxis) + ); + } + + // Position elements in the cross axis + for (i = startLine; i < endLine; ++i) { + child = node->get_child(node->context, i); + + if (getPositionType(child) == CSS_POSITION_ABSOLUTE && + isPosDefined(child, leading[crossAxis])) { + // In case the child is absolutely positionned and has a + // top/left/bottom/right being set, we override all the previously + // computed positions to set it correctly. + child->layout.position[pos[crossAxis]] = getPosition(child, leading[crossAxis]) + + getLeadingBorder(node, crossAxis) + + getLeadingMargin(child, crossAxis); + + } else { + float leadingCrossDim = getLeadingPaddingAndBorder(node, crossAxis); + + // For a relative children, we're either using alignItems (parent) or + // alignSelf (child) in order to determine the position in the cross axis + if (getPositionType(child) == CSS_POSITION_RELATIVE) { + css_align_t alignItem = getAlignItem(node, child); + if (alignItem == CSS_ALIGN_STRETCH) { + // You can only stretch if the dimension has not already been set + // previously. + if (!isDimDefined(child, crossAxis)) { + child->layout.dimensions[dim[crossAxis]] = fmaxf( + boundAxis(child, crossAxis, containerCrossAxis - + getPaddingAndBorderAxis(node, crossAxis) - + getMarginAxis(child, crossAxis)), + // You never want to go smaller than padding + getPaddingAndBorderAxis(child, crossAxis) + ); + } + } else if (alignItem != CSS_ALIGN_FLEX_START) { + // The remaining space between the parent dimensions+padding and child + // dimensions+margin. + float remainingCrossDim = containerCrossAxis - + getPaddingAndBorderAxis(node, crossAxis) - + getDimWithMargin(child, crossAxis); + + if (alignItem == CSS_ALIGN_CENTER) { + leadingCrossDim += remainingCrossDim / 2; + } else { // CSS_ALIGN_FLEX_END + leadingCrossDim += remainingCrossDim; + } + } + } + + // And we apply the position + child->layout.position[pos[crossAxis]] += linesCrossDim + leadingCrossDim; + + // Define the trailing position accordingly. + if (!isUndefined(node->layout.dimensions[dim[crossAxis]])) { + setTrailingPosition(node, child, crossAxis); + } + } + } + + linesCrossDim += crossDim; + linesMainDim = fmaxf(linesMainDim, mainDim); + linesCount += 1; + startLine = endLine; + } + + // + // + // Note(prenaux): More than one line, we need to layout the crossAxis + // according to alignContent. + // + // Note that we could probably remove and handle the one line case + // here too, but for the moment this is safer since it won't interfere with + // previously working code. + // + // See specs: + // http://www.w3.org/TR/2012/CR-css3-flexbox-20120918/#layout-algorithm + // section 9.4 + // + if (linesCount > 1 && + !isUndefined(node->layout.dimensions[dim[crossAxis]])) { + float nodeCrossAxisInnerSize = node->layout.dimensions[dim[crossAxis]] - + getPaddingAndBorderAxis(node, crossAxis); + float remainingAlignContentDim = nodeCrossAxisInnerSize - linesCrossDim; + + float crossDimLead = 0; + float currentLead = getLeadingPaddingAndBorder(node, crossAxis); + + css_align_t alignContent = getAlignContent(node); + if (alignContent == CSS_ALIGN_FLEX_END) { + currentLead += remainingAlignContentDim; + } else if (alignContent == CSS_ALIGN_CENTER) { + currentLead += remainingAlignContentDim / 2; + } else if (alignContent == CSS_ALIGN_STRETCH) { + if (nodeCrossAxisInnerSize > linesCrossDim) { + crossDimLead = (remainingAlignContentDim / linesCount); + } + } + + int endIndex = 0; + for (i = 0; i < linesCount; ++i) { + int startIndex = endIndex; + + // compute the line's height and find the endIndex + float lineHeight = 0; + for (ii = startIndex; ii < node->children_count; ++ii) { + child = node->get_child(node->context, ii); + if (getPositionType(child) != CSS_POSITION_RELATIVE) { + continue; + } + if (child->line_index != i) { + break; + } + if (!isUndefined(child->layout.dimensions[dim[crossAxis]])) { + lineHeight = fmaxf( + lineHeight, + child->layout.dimensions[dim[crossAxis]] + getMarginAxis(child, crossAxis) + ); + } + } + endIndex = ii; + lineHeight += crossDimLead; + + for (ii = startIndex; ii < endIndex; ++ii) { + child = node->get_child(node->context, ii); + if (getPositionType(child) != CSS_POSITION_RELATIVE) { + continue; + } + + css_align_t alignContentAlignItem = getAlignItem(node, child); + if (alignContentAlignItem == CSS_ALIGN_FLEX_START) { + child->layout.position[pos[crossAxis]] = currentLead + getLeadingMargin(child, crossAxis); + } else if (alignContentAlignItem == CSS_ALIGN_FLEX_END) { + child->layout.position[pos[crossAxis]] = currentLead + lineHeight - getTrailingMargin(child, crossAxis) - child->layout.dimensions[dim[crossAxis]]; + } else if (alignContentAlignItem == CSS_ALIGN_CENTER) { + float childHeight = child->layout.dimensions[dim[crossAxis]]; + child->layout.position[pos[crossAxis]] = currentLead + (lineHeight - childHeight) / 2; + } else if (alignContentAlignItem == CSS_ALIGN_STRETCH) { + child->layout.position[pos[crossAxis]] = currentLead + getLeadingMargin(child, crossAxis); + // TODO(prenaux): Correctly set the height of items with undefined + // (auto) crossAxis dimension. + } + } + + currentLead += lineHeight; + } + } + + bool needsMainTrailingPos = false; + bool needsCrossTrailingPos = false; + + // If the user didn't specify a width or height, and it has not been set + // by the container, then we set it via the children. + if (isUndefined(node->layout.dimensions[dim[mainAxis]])) { + node->layout.dimensions[dim[mainAxis]] = fmaxf( + // We're missing the last padding at this point to get the final + // dimension + boundAxis(node, mainAxis, linesMainDim + getTrailingPaddingAndBorder(node, mainAxis)), + // We can never assign a width smaller than the padding and borders + getPaddingAndBorderAxis(node, mainAxis) + ); + + needsMainTrailingPos = true; + } + + if (isUndefined(node->layout.dimensions[dim[crossAxis]])) { + node->layout.dimensions[dim[crossAxis]] = fmaxf( + // For the cross dim, we add both sides at the end because the value + // is aggregate via a max function. Intermediate negative values + // can mess this computation otherwise + boundAxis(node, crossAxis, linesCrossDim + getPaddingAndBorderAxis(node, crossAxis)), + getPaddingAndBorderAxis(node, crossAxis) + ); + + needsCrossTrailingPos = true; + } + + // Set trailing position if necessary + if (needsMainTrailingPos || needsCrossTrailingPos) { + for (i = 0; i < node->children_count; ++i) { + child = node->get_child(node->context, i); + + if (needsMainTrailingPos) { + setTrailingPosition(node, child, mainAxis); + } + + if (needsCrossTrailingPos) { + setTrailingPosition(node, child, crossAxis); + } + } + } + + // Calculate dimensions for absolutely positioned elements + for (i = 0; i < node->children_count; ++i) { + child = node->get_child(node->context, i); + if (getPositionType(child) == CSS_POSITION_ABSOLUTE) { + // Pre-fill dimensions when using absolute position and both offsets for the axis are defined (either both + // left and right or top and bottom). + for (ii = 0; ii < 2; ii++) { + axis = (ii != 0) ? CSS_FLEX_DIRECTION_ROW : CSS_FLEX_DIRECTION_COLUMN; + if (!isUndefined(node->layout.dimensions[dim[axis]]) && + !isDimDefined(child, axis) && + isPosDefined(child, leading[axis]) && + isPosDefined(child, trailing[axis])) { + child->layout.dimensions[dim[axis]] = fmaxf( + boundAxis(child, axis, node->layout.dimensions[dim[axis]] - + getBorderAxis(node, axis) - + getMarginAxis(child, axis) - + getPosition(child, leading[axis]) - + getPosition(child, trailing[axis]) + ), + // You never want to go smaller than padding + getPaddingAndBorderAxis(child, axis) + ); + } + } + for (ii = 0; ii < 2; ii++) { + axis = (ii != 0) ? CSS_FLEX_DIRECTION_ROW : CSS_FLEX_DIRECTION_COLUMN; + if (isPosDefined(child, trailing[axis]) && + !isPosDefined(child, leading[axis])) { + child->layout.position[leading[axis]] = + node->layout.dimensions[dim[axis]] - + child->layout.dimensions[dim[axis]] - + getPosition(child, trailing[axis]); + } + } + } + } + /** END_GENERATED **/ +} + +void layoutNode(css_node_t *node, float parentMaxWidth, css_direction_t parentDirection) { + css_layout_t *layout = &node->layout; + css_direction_t direction = node->style.direction; + layout->should_update = true; + + bool skipLayout = + !node->is_dirty(node->context) && + eq(layout->last_requested_dimensions[CSS_WIDTH], layout->dimensions[CSS_WIDTH]) && + eq(layout->last_requested_dimensions[CSS_HEIGHT], layout->dimensions[CSS_HEIGHT]) && + eq(layout->last_parent_max_width, parentMaxWidth); + eq(layout->last_direction, direction); + + if (skipLayout) { + layout->dimensions[CSS_WIDTH] = layout->last_dimensions[CSS_WIDTH]; + layout->dimensions[CSS_HEIGHT] = layout->last_dimensions[CSS_HEIGHT]; + layout->position[CSS_TOP] = layout->last_position[CSS_TOP]; + layout->position[CSS_LEFT] = layout->last_position[CSS_LEFT]; + } else { + layout->last_requested_dimensions[CSS_WIDTH] = layout->dimensions[CSS_WIDTH]; + layout->last_requested_dimensions[CSS_HEIGHT] = layout->dimensions[CSS_HEIGHT]; + layout->last_parent_max_width = parentMaxWidth; + layout->last_direction = direction; + + layoutNodeImpl(node, parentMaxWidth, parentDirection); + + layout->last_dimensions[CSS_WIDTH] = layout->dimensions[CSS_WIDTH]; + layout->last_dimensions[CSS_HEIGHT] = layout->dimensions[CSS_HEIGHT]; + layout->last_position[CSS_TOP] = layout->position[CSS_TOP]; + layout->last_position[CSS_LEFT] = layout->position[CSS_LEFT]; + } +} diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/Layout.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/Layout.h new file mode 100644 index 00000000..54d31589 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/Layout.h @@ -0,0 +1,163 @@ +/** + * Copyright (c) 2014, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +#ifndef __LAYOUT_H +#define __LAYOUT_H + +#include +#ifndef __cplusplus +#include +#endif + +// Not defined in MSVC++ +#ifndef NAN +static const unsigned long __nan[2] = {0xffffffff, 0x7fffffff}; +#define NAN (*(const float *)__nan) +#endif + +#define CSS_UNDEFINED NAN + +typedef enum { + CSS_DIRECTION_INHERIT = 0, + CSS_DIRECTION_LTR, + CSS_DIRECTION_RTL +} css_direction_t; + +typedef enum { + CSS_FLEX_DIRECTION_COLUMN = 0, + CSS_FLEX_DIRECTION_COLUMN_REVERSE, + CSS_FLEX_DIRECTION_ROW, + CSS_FLEX_DIRECTION_ROW_REVERSE +} css_flex_direction_t; + +typedef enum { + CSS_JUSTIFY_FLEX_START = 0, + CSS_JUSTIFY_CENTER, + CSS_JUSTIFY_FLEX_END, + CSS_JUSTIFY_SPACE_BETWEEN, + CSS_JUSTIFY_SPACE_AROUND +} css_justify_t; + +// Note: auto is only a valid value for alignSelf. It is NOT a valid value for +// alignItems. +typedef enum { + CSS_ALIGN_AUTO = 0, + CSS_ALIGN_FLEX_START, + CSS_ALIGN_CENTER, + CSS_ALIGN_FLEX_END, + CSS_ALIGN_STRETCH +} css_align_t; + +typedef enum { + CSS_POSITION_RELATIVE = 0, + CSS_POSITION_ABSOLUTE +} css_position_type_t; + +typedef enum { + CSS_NOWRAP = 0, + CSS_WRAP +} css_wrap_type_t; + +// Note: left and top are shared between position[2] and position[4], so +// they have to be before right and bottom. +typedef enum { + CSS_LEFT = 0, + CSS_TOP, + CSS_RIGHT, + CSS_BOTTOM, + CSS_START, + CSS_END, + CSS_POSITION_COUNT +} css_position_t; + +typedef enum { + CSS_WIDTH = 0, + CSS_HEIGHT +} css_dimension_t; + +typedef struct { + float position[4]; + float dimensions[2]; + css_direction_t direction; + + // Instead of recomputing the entire layout every single time, we + // cache some information to break early when nothing changed + bool should_update; + float last_requested_dimensions[2]; + float last_parent_max_width; + float last_dimensions[2]; + float last_position[2]; + css_direction_t last_direction; +} css_layout_t; + +typedef struct { + float dimensions[2]; +} css_dim_t; + +typedef struct { + css_direction_t direction; + css_flex_direction_t flex_direction; + css_justify_t justify_content; + css_align_t align_content; + css_align_t align_items; + css_align_t align_self; + css_position_type_t position_type; + css_wrap_type_t flex_wrap; + float flex; + float margin[6]; + float position[4]; + /** + * You should skip all the rules that contain negative values for the + * following attributes. For example: + * {padding: 10, paddingLeft: -5} + * should output: + * {left: 10 ...} + * the following two are incorrect: + * {left: -5 ...} + * {left: 0 ...} + */ + float padding[6]; + float border[6]; + float dimensions[2]; + float minDimensions[2]; + float maxDimensions[2]; +} css_style_t; + +typedef struct css_node { + css_style_t style; + css_layout_t layout; + int children_count; + int line_index; + + css_dim_t (*measure)(void *context, float width); + void (*print)(void *context); + struct css_node* (*get_child)(void *context, int i); + bool (*is_dirty)(void *context); + void *context; +} css_node_t; + + +// Lifecycle of nodes and children +css_node_t *new_css_node(void); +void init_css_node(css_node_t *node); +void free_css_node(css_node_t *node); + +// Print utilities +typedef enum { + CSS_PRINT_LAYOUT = 1, + CSS_PRINT_STYLE = 2, + CSS_PRINT_CHILDREN = 4, +} css_print_options_t; +void print_css_node(css_node_t *node, css_print_options_t options); + +// Function that computes the layout! +void layoutNode(css_node_t *node, float maxWidth, css_direction_t parentDirection); +bool isUndefined(float value); + +#endif diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/LayoutExtensions/JUFLXLinearLayoutView.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/LayoutExtensions/JUFLXLinearLayoutView.h new file mode 100644 index 00000000..abbec9c9 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/LayoutExtensions/JUFLXLinearLayoutView.h @@ -0,0 +1,39 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "JUFLXNode.h" + +/** + * Try to solve two kinds of problems. + * 1. Know all the child views' size and layout them, bonus this container can be autoAdjustFrame + * according to child views' size and contentInset and lineSpacing; + * 2. Know some child view's size(not all), auto flex the remain views in this container. + * + * If you want more customization, sugguest JUFLXNode, also this class is build on this, and it support it. + */ +@interface JUFLXLinearLayoutView : UIView + +@property (nonatomic, strong) NSArray *childViews; + +@property (nonatomic, assign) UIEdgeInsets contentInset; + +@property (nonatomic, assign) JUFLXLayoutDirection layoutDirection; + +/** + * If it is yes, the scrollView frame size will be changed depend on childViews' total size. + * If some views' size is not be setted, set it to be YES won't flex those pending views' size + * default is NO. + */ +@property (nonatomic, assign) BOOL autoAdjustFrameSize; + +@property (nonatomic, assign) CGFloat lineSpacing; + +- (void)layout; + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/LayoutExtensions/JUFLXLinearLayoutView.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/LayoutExtensions/JUFLXLinearLayoutView.m new file mode 100644 index 00000000..734d2f30 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/LayoutExtensions/JUFLXLinearLayoutView.m @@ -0,0 +1,180 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "JUFLXLinearLayoutView.h" +#import "UIView+JUFLXNode.h" + +@implementation JUFLXLinearLayoutView { + BOOL _dirty; +} + +@synthesize contentInset = _contentInset, layoutDirection = _layoutDirection, autoAdjustFrameSize = _autoAdjustFrameSize, lineSpacing = _lineSpacing; + +- (instancetype)init { + self = [super init]; + if (self) { + [self commonInit]; + } + + return self; +} + +- (instancetype)initWithFrame:(CGRect)frame { + self = [super initWithFrame:frame]; + if (self) { + [self commonInit]; + } + + return self; +} + +- (instancetype)initWithCoder:(NSCoder *)coder { + self = [super initWithCoder:coder]; + if (self) { + [self commonInit]; + } + + return self; +} + +- (void)commonInit { + _contentInset = UIEdgeInsetsZero; + _layoutDirection = JUFLXLayoutDirectionColumn; + self.ju_flxNode.direction = _layoutDirection; + _autoAdjustFrameSize = NO; + _lineSpacing = 0; +} + +- (void)setAutoAdjustFrameSize:(BOOL)autoAdjustFrameSize { + if (_autoAdjustFrameSize == autoAdjustFrameSize) return; + + _autoAdjustFrameSize = autoAdjustFrameSize; + + CGFloat dimWidth = CGRectGetWidth(self.frame); + CGFloat dimHeight = CGRectGetHeight(self.frame); + + switch (self.layoutDirection) { + case JUFLXLayoutDirectionRow: + case JUFLXLayoutDirectionRowReverse: { + dimWidth = JUFLXLayoutFloatUnDefined; + break; + } + case JUFLXLayoutDirectionColumn: + case JUFLXLayoutDirectionColumnReverse: { + dimHeight = JUFLXLayoutFloatUnDefined; + break; + } + default: { + break; + } + } + + if (_autoAdjustFrameSize) { + self.ju_flxNode.dimensions = CGSizeMake(dimWidth, dimHeight); + } +} + +- (void)setChildViews:(NSArray *)childViews { + if ([_childViews isEqual:childViews]) return; + + _childViews = childViews; + _childViews = [_childViews filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings) { + BOOL isViewClass = [evaluatedObject isKindOfClass:[UIView class]]; + NSAssert(isViewClass, @"views should be class of UIViews"); + + return isViewClass; + }]]; + + for (UIView *view in self.childViews) { + // if the view is not support self sizing, the we flex it + if (!view.ju_flxNode.measure && view.ju_flxNode.flex == 0 && CGSizeEqualToSize(view.ju_flxNode.dimensions, CGSizeZero)) { + view.ju_flxNode.flex = 1; + } + } + + [self setNeedsUpdateChildViews]; + + self.ju_flxNode.childNodes = [self.childViews valueForKey:@"ju_flxNode"]; + + _dirty = YES; +} + +- (void)setContentInset:(UIEdgeInsets)contentInset { + if (UIEdgeInsetsEqualToEdgeInsets(_contentInset, contentInset)) return; + + _contentInset = contentInset; + [self setNeedsUpdateChildViews]; + + _dirty = YES; +} + +- (void)setLayoutDirection:(JUFLXLayoutDirection)layoutDirection { + if (_layoutDirection == layoutDirection) return; + + _layoutDirection = layoutDirection; + self.ju_flxNode.direction = _layoutDirection; + [self setNeedsUpdateChildViews]; + + _dirty = YES; +} + +- (void)setLineSpacing:(CGFloat)lineSpacing { + if (_lineSpacing == lineSpacing) return; + + _lineSpacing = lineSpacing; + [self setNeedsUpdateChildViews]; + + _dirty = YES; +} + +- (void)setNeedsUpdateChildViews { + BOOL isVerticalLayout = (self.ju_flxNode.direction == JUFLXLayoutDirectionColumn || self.ju_flxNode.direction == JUFLXLayoutDirectionColumnReverse); + [self.childViews enumerateObjectsUsingBlock:^(UIView *view, NSUInteger idx, BOOL *stop) { + UIEdgeInsets edge = UIEdgeInsetsZero; + + if (idx == 0) { + if (isVerticalLayout) { + edge = UIEdgeInsetsMake(_contentInset.top, _contentInset.left, 0, _contentInset.right); + } + else { + edge = UIEdgeInsetsMake(_contentInset.top, _contentInset.left, _contentInset.bottom, 0); + } + } + else if (idx == self.childViews.count - 1) { + if (isVerticalLayout) { + edge = UIEdgeInsetsMake(_lineSpacing, _contentInset.left, _contentInset.bottom, _contentInset.right); + } + else { + edge = UIEdgeInsetsMake(_contentInset.top, _lineSpacing, _contentInset.bottom, _contentInset.right); + } + } + else { + if (isVerticalLayout) { + edge = UIEdgeInsetsMake(_lineSpacing, _contentInset.left, 0, _contentInset.right); + } + else { + edge = UIEdgeInsetsMake(_contentInset.top, _lineSpacing, _contentInset.bottom, 0); + } + } + + view.ju_flxNode.margin = edge; + }]; +} + +- (void)setNeedsReload { + if (_dirty) { + [self layout]; + } +} + +- (void)layout { + [self.ju_flxNode layout]; + _dirty = NO; +} + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/UIView+JUFLXNode.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/UIView+JUFLXNode.h new file mode 100644 index 00000000..3e53f298 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/UIView+JUFLXNode.h @@ -0,0 +1,168 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "JUFLXNode.h" + +typedef void (^NodeDidFinishLayout)(JUFLXNode *node); + +@interface UIView (JUFLXNodeGetter) + +- (JUFLXNode *)ju_flxNode; +- (BOOL)ju_hasFlxNode; +- (void)setJu_flxNodeDidFinishLayoutBlock:(NodeDidFinishLayout)block; + +@end + +@interface UIView (JUFLXNodes) + +@property (nonatomic, strong) NSArray *flx_childViews; +/** + * Default is view's frame's origin + */ +//@property (nonatomic, assign) CGPoint flx_viewOrigin; + +/* + * --------------------------------------------------------------------------- + * As Container's property + * --------------------------------------------------------------------------- + */ + +@property (nonatomic, assign) BOOL flx_absolute; + +@property (nonatomic, assign) UIEdgeInsets flx_absoluteEdgeInsets; + +/** + * Check -> http://www.w3.org/TR/css3-flexbox/#flex-direction-property + * inlineCSS -> flex-direction + * Default is row + */ +@property (nonatomic, assign) JUFLXLayoutDirection flx_direction; + +/** + * Check -> http://www.w3.org/TR/css3-flexbox/#propdef-align-items + * inlineCSS -> align-items + * Default is stretch + */ +@property (nonatomic, assign) JUFLXLayoutAlignment flx_alignItems; + +/** + * Check -> http://www.w3.org/TR/css3-flexbox/#propdef-align-content + * inlineCSS -> align-content + * Default is stretch + * Here we don't support the between and around + */ +@property (nonatomic, assign) JUFLXLayoutAlignment flx_alignContent; + +/** + * Check -> http://www.w3.org/TR/css3-flexbox/#propdef-justify-content + * inlineCSS -> justify-content + * Default is start + */ +@property (nonatomic, assign) JUFLXLayoutJustifyContent flx_justifyContent; + +/** + * Check -> http://www.w3.org/TR/css3-flexbox/#flex-wrap-property + * When the container size doesn't satisfy, if use a new depends on this. + * inlineCSS -> flex-wrap + * Here we don't support wrap-reverse + */ +@property (nonatomic, assign) BOOL flx_flexWrap; + + +/* + * --------------------------------------------------------------------------- + * As Child's property + * --------------------------------------------------------------------------- + */ + +/** + * Check -> http://www.w3.org/TR/css3-flexbox/#propdef-align-self + * inlineCSS -> align-self + * Default is auto, means depend on containers' alignItems; + */ +@property (nonatomic, assign) JUFLXLayoutAlignment flx_alignSelf; + +/** + * Means two thing: 1. If self use the remaining space 2. how much would u share with others + * Flex-grow, eg: A node has three children---a,b,c; a.flex = 1, b.flex = 2, c.flex = 1, then a's size will be 1 / (1 + 2 + 1), + * b is 2 / (1 + 2 + 1), c is 1 / (1 + 2 + 1) + * inlineCSS -> flex + * Here we only support flex-grow as flex, not include shrink. + * Default is 0 + */ +@property (nonatomic, assign) CGFloat flx_flex; + +/* + * --------------------------------------------------------------------------- + * As box's property + * --------------------------------------------------------------------------- + */ + +/** + * The style dimensions, default is the view's size, if you set it to {nan, nan}, + * The result frame depends on children's total size, so the children's size should be measured. + * inlineCSS ->size, width, height + * It won't be affected by JUFLXLayoutAlignment + */ +@property (nonatomic, assign) CGSize flx_dimensions; + +/** + * ensure the min dimension of the view size. + * inlineCSS -> min-width, min-height + * Default is {0,0} + */ +@property (nonatomic, assign) CGSize flx_minDimensions; + +/** + * ensure the max dimension of the view size. + * inlineCSS -> max-width, max-height + * Default is {0,0} + */ +@property (nonatomic, assign) CGSize flx_maxDimensions; + +/** + * The margin of the view. + * inlineCSS -> margin, margin-top, margin-left, margin-bottom, margin-right + */ +@property (nonatomic, assign) UIEdgeInsets flx_margin; + +/** + * The padding of the view. + * inlineCSS -> padding, padding-top, padding-left, padding-bottom, padding-right + */ +@property (nonatomic, assign) UIEdgeInsets flx_padding; + +/** + * When encouter the view size should be calculated like text size, use this block. + * If direction is row, then width is the parent's node's frame's width, otherwise is nan. + * It will be affected by JUFLXLayoutAlignment + */ +@property (nonatomic, copy) CGSize (^flx_measure)(CGFloat width); + +/** + * If isSizeToFit == YES, the measure block CGSize (^measure)(CGFloat width) will returned by view's + * sizeThatFits: size, the property will be override by measure block; + * Default is YES; + * It will be affected by JUFLXLayoutAlignment + * inlineCSS -> sizetofit: 1 + */ +@property (nonatomic, assign) BOOL flx_sizeToFit; + +- (void)flx_bindingInlineCSS:(NSString *)inlineCSS; + +- (void)flx_layout; + +- (void)flx_layoutAsync:(BOOL)async; + +- (void)flx_layoutAsync:(BOOL)async completion:(void(^)(CGRect frame))block; + +@end + +FOUNDATION_EXTERN NSString * const JUFLXNodeUIViewNodeKey; +FOUNDATION_EXTERN NSString * const JUFLXNodeUIViewDidFinishBlockKey; diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/UIView+JUFLXNode.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/UIView+JUFLXNode.m new file mode 100644 index 00000000..0a6533a1 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/layout/UIView+JUFLXNode.m @@ -0,0 +1,191 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "UIView+JUFLXNode.h" +#import +#import "JUFLXNode.h" + +NSString * const JUFLXNodeUIViewNodeKey = @"hrnode.JUFLXNodeUIViewNodeKey"; +NSString * const JUFLXNodeUIViewDidFinishBlockKey = @"hrnode.JUFLXNodeUIViewDidFinishBlockKey"; + +@implementation UIView (JUFLXNodeGetter) + +- (JUFLXNode *)ju_flxNode { + JUFLXNode *node = objc_getAssociatedObject(self, &JUFLXNodeUIViewNodeKey); + if (!node) { + node = [JUFLXNode nodeWithView:self]; + } + return node; +} + +- (BOOL)ju_hasFlxNode { + JUFLXNode *node = objc_getAssociatedObject(self, &JUFLXNodeUIViewNodeKey); + return node != nil; +} + +- (void)setJu_flxNodeDidFinishLayoutBlock:(NodeDidFinishLayout)block { + objc_setAssociatedObject(self, &JUFLXNodeUIViewDidFinishBlockKey, block, OBJC_ASSOCIATION_COPY_NONATOMIC); +} + +@end + +@implementation UIView (JUFLXNodes) + +- (NSArray *)flx_childViews { + return [self.ju_flxNode.childNodes valueForKey:@"view"]; +} + +- (void)setFlx_childViews:(NSArray *)flx_childViews { + self.ju_flxNode.childNodes = [flx_childViews valueForKey:@"ju_flxNode"]; +} + +- (UIEdgeInsets)flx_absoluteEdgeInsets { + return self.ju_flxNode.absoluteEdges; +} + +- (void)setFlx_absoluteEdgeInsets:(UIEdgeInsets)flx_absoluteEdgeInsets { + self.ju_flxNode.absoluteEdges = flx_absoluteEdgeInsets; +} + +- (BOOL)flx_absolute { + return self.ju_flxNode.absolute; +} + +- (void)setFlx_absolute:(BOOL)flx_absolute { + self.ju_flxNode.absolute = flx_absolute; +} + +- (JUFLXLayoutDirection)flx_direction { + return self.ju_flxNode.direction; +} + +- (void)setFlx_direction:(JUFLXLayoutDirection)flx_direction { + self.ju_flxNode.direction = flx_direction; +} + +- (JUFLXLayoutAlignment)flx_alignItems { + return self.ju_flxNode.alignItems; +} + +- (void)setFlx_alignItems:(JUFLXLayoutAlignment)flx_alignItems { + self.ju_flxNode.alignItems = flx_alignItems; +} + +- (JUFLXLayoutAlignment)flx_alignContent { + return self.ju_flxNode.alignContent; +} + +- (void)setFlx_alignContent:(JUFLXLayoutAlignment)flx_alignContent { + self.ju_flxNode.alignContent = flx_alignContent; +} + +- (JUFLXLayoutJustifyContent)flx_justifyContent { + return self.ju_flxNode.justifyContent; +} + +- (void)setFlx_justifyContent:(JUFLXLayoutJustifyContent)flx_justifyContent { + self.ju_flxNode.justifyContent = flx_justifyContent; +} + +- (BOOL)flx_flexWrap { + return self.ju_flxNode.flexWrap; +} + +- (void)setFlx_flexWrap:(BOOL)flx_flexWrap { + self.ju_flxNode.flexWrap = flx_flexWrap; +} + +- (JUFLXLayoutAlignment)flx_alignSelf { + return self.ju_flxNode.alignSelf; +} + +- (void)setFlx_alignSelf:(JUFLXLayoutAlignment)flx_alignSelf { + self.ju_flxNode.alignSelf = flx_alignSelf; +} + +- (CGFloat)flx_flex { + return self.ju_flxNode.flex; +} + +- (void)setFlx_flex:(CGFloat)flx_flex { + self.ju_flxNode.flex = flx_flex; +} + +- (CGSize)flx_dimensions { + return self.ju_flxNode.dimensions; +} + +-(void)setFlx_dimensions:(CGSize)flx_dimensions { + self.ju_flxNode.dimensions = flx_dimensions; +} + +- (CGSize)flx_minDimensions { + return self.ju_flxNode.minDimensions; +} + +- (void)setFlx_minDimensions:(CGSize)flx_minDimensions { + self.ju_flxNode.minDimensions = flx_minDimensions; +} + +- (CGSize)flx_maxDimensions { + return self.ju_flxNode.maxDimensions; +} + +- (void)setFlx_maxDimensions:(CGSize)flx_maxDimensions { + self.ju_flxNode.maxDimensions = flx_maxDimensions; +} + +- (UIEdgeInsets)flx_margin { + return self.ju_flxNode.margin; +} + +- (void)setFlx_margin:(UIEdgeInsets)flx_margin { + self.ju_flxNode.margin = flx_margin; +} + +- (UIEdgeInsets)flx_padding { + return self.ju_flxNode.padding; +} + +- (void)setFlx_padding:(UIEdgeInsets)flx_padding { + self.ju_flxNode.padding = flx_padding; +} + +- (void)setFlx_measure:(CGSize (^)(CGFloat))flx_measure { + self.ju_flxNode.measure = flx_measure; +} + +- (CGSize (^)(CGFloat))flx_measure { + return self.ju_flxNode.measure; +} + +- (BOOL)flx_sizeToFit { + return self.ju_flxNode.isSizeToFit; +} + +- (void)setFlx_sizeToFit:(BOOL)flx_sizeToFit { + self.ju_flxNode.sizeToFit = flx_sizeToFit; +} + +- (void)flx_bindingInlineCSS:(NSString *)inlineCSS { + [self.ju_flxNode bindingInlineCSS:inlineCSS]; +} + +- (void)flx_layout { + [self.ju_flxNode layout]; +} + +- (void)flx_layoutAsync:(BOOL)async { + [self.ju_flxNode layoutAsync:async]; +} + +- (void)flx_layoutAsync:(BOOL)async completion:(void(^)(CGRect frame))block { + [self.ju_flxNode layoutAsync:async completionBlock:block]; +} + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvdebug/LVDebugConnection.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvdebug/LVDebugConnection.h new file mode 100644 index 00000000..7550d329 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvdebug/LVDebugConnection.h @@ -0,0 +1,37 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + +@interface LVDebugConnection : NSObject + +@property (nonatomic,assign) BOOL printToServer; +@property (nonatomic,weak) LuaViewCore* lview; +@property (atomic,strong) NSMutableArray* receivedArray; + +- (BOOL) isOk; + +- (NSString*) getCmd; + +- (NSInteger) waitUntilConnectionEnd; + +- (void) sendCmd:(NSString*) cmdName info:(NSString*) info; +- (void) sendCmd:(NSString*) cmdName info:(NSString*) info args:(NSDictionary*) args; +- (void) sendCmd:(NSString*) cmdName fileName:(NSString*)fileName info:(NSString*) info; +- (void) sendCmd:(NSString*) cmdName fileName:(NSString*)fileName info:(NSString*) info args:(NSDictionary*) args; + +-(void) closeAll; + +// 设置调试器的IP和端口, 用于远程调试 ++(void) setDebugerIP:(NSString*) ip port:(int) port; + +#ifdef DEBUG ++(void) openUrlServer:( void(^)(NSDictionary* args) ) callback; +#endif +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvdebug/LVDebugConnection.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvdebug/LVDebugConnection.m new file mode 100644 index 00000000..3ac8f40c --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvdebug/LVDebugConnection.m @@ -0,0 +1,348 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVDebugConnection.h" +#import +#import +#import +#import +#import +#import +#import +#import +#import "LVUtil.h" +#import "LView.h" + + +#define SOCKET_ERROR (-1) +#define SOCKET_CONNECTINTG (0) +#define SOCKET_SUCCESS (1) + +// 调试器的默认IP和端口 +static NSString* SERVER_IP = @"127.0.0.1"; +static int SERVER_PORT = 9876; + +@interface LVDebugConnection () +@property(nonatomic,strong) NSThread* myThread; +@property(nonatomic,assign) BOOL canWrite; +@property(nonatomic,assign) NSInteger state; +@property(atomic,strong) NSMutableArray* sendArray; +@end + +@implementation LVDebugConnection{ + CFSocketRef _socket; +} + +-(id) init{ + self = [super init]; + if( self ) { + static int index = 0; + self.myThread = [[NSThread alloc] initWithTarget:self selector:@selector(run:) object:nil]; + self.myThread.name = [NSString stringWithFormat:@"LuaView.Debuger.%d",index]; + self.sendArray = [[NSMutableArray alloc] init]; + self.receivedArray = [[NSMutableArray alloc] init]; + [self startThread]; + } + return self; +} + +- (void) dealloc{ + [self closeAll]; +} + +-(BOOL) isOk{ + return self.state>0; +} +- (NSInteger) waitUntilConnectionEnd{ + for(;self.state==SOCKET_CONNECTINTG;) { + [NSThread sleepForTimeInterval:0.01]; + } + return self.state; +} + +-(void) startThread{ + [self.myThread start]; //启动线程 +} + ++(void) setDebugerIP:(NSString*) ip port:(int) port{ + SERVER_IP = ip; + SERVER_PORT = port; +} + +-(void) run:(id) obj{ + @autoreleasepool { + [self Connect:SERVER_IP port:SERVER_PORT]; + + NSRunLoop *runLoop = [NSRunLoop currentRunLoop]; + [runLoop addPort:[NSMachPort port] forMode:NSDefaultRunLoopMode]; + [runLoop run]; + } +} + +- (NSString*) getCmd{ + NSString* cmd = self.receivedArray.lastObject; + if( cmd ) { + [self.receivedArray removeLastObject]; + } + return cmd; +} + +- (void) sendCmd:(NSString*) cmdName info:(NSString*) info{ + [self sendCmd:cmdName fileName:nil info:info]; +} + +- (void) sendCmd:(NSString*) cmdName info:(NSString*) info args:(NSDictionary*) args{ + [self sendCmd:cmdName fileName:nil info:info args:args]; +} + +- (void) sendCmd:(NSString*) cmdName fileName:(NSString*)fileName info:(NSString*) info{ + [self sendCmd:cmdName fileName:fileName info:info args:nil]; +} + +- (void) sendCmd:(NSString*) cmdName fileName:(NSString*)fileName info:(NSString*) info args:(NSDictionary*) args{ + NSMutableString* buffer = [[NSMutableString alloc] init]; + if ( cmdName ) { + [buffer appendFormat:@"Cmd-Name:%@\n",cmdName]; + } + if ( fileName ){ + [buffer appendFormat:@"File-Name:%@\n",fileName]; + } + NSArray* keys = args.allKeys; + for( int i=0; i0) { + LVLog(@"[调试日志][收到指令] %@ ", cmd); + [debuger.receivedArray insertObject:cmd atIndex:0]; + } + // 关闭掉socket + if ( cmd.length<=0 ){ + [debuger closeAll]; + [debuger.receivedArray insertObject:@"close" atIndex:0]; + [debuger.receivedArray insertObject:@"close" atIndex:0]; + } else { + [debuger.lview callLuaToExecuteServerCmd]; + } + break; + } + case kCFSocketWriteCallBack: { + debuger.canWrite = YES; + [debuger sendOneData]; + break; + } + case kCFSocketConnectCallBack: + if( data ) { + // LVLog(@"Debuger Socket Connect failed" ); + debuger.state = SOCKET_ERROR; + } else { + LVLog(@"Debuger Socket connect Success"); + debuger.state = SOCKET_SUCCESS; + } + break; + default: { + LVLog(@"connect type %d", (int)type ); + break; + } + } +} +#endif + +-(void) sendOneData{ + NSData* data = self.sendArray.lastObject; + if( self.canWrite && data) { + [self.sendArray removeLastObject]; + if( data ) { + NSInteger sendLength = send(CFSocketGetNative(_socket), data.bytes, data.length, 0); + if( sendLength!=data.length ) { + LVError(@"Debuger socket Send length Error : %d != %d", (int)sendLength, (int)data.length); + } + } + } +} + +///////////////////监听来自服务器的信息/////////////////// + +#ifdef DEBUG +static NSString* readString(CFSocketRef socket) +{ + unsigned char head[4] = {0}; + NSUInteger readLength0 = 0; + if( recv( CFSocketGetNative(socket), head, sizeof(head), 0 )==sizeof(head) ) { + NSUInteger d0 = head[0]; + NSUInteger d1 = head[1]; + NSUInteger d2 = head[2]; + NSUInteger d3 = head[3]; + readLength0 = (d0<<24) + (d1<<16) + (d2<<8) + d3; + } + + unsigned char buffer[512] = {0}; + NSUInteger readLen = readLength0; + NSMutableData* data = [[NSMutableData alloc] init]; + for(;readLen>0;){ + NSUInteger bufferLen = readLen>=sizeof(buffer)?sizeof(buffer):readLen; + NSUInteger recvLen = recv( CFSocketGetNative(socket), buffer, bufferLen, 0 ); + if ( recvLen>0 ) { + [data appendBytes:buffer length:recvLen]; + readLen -= recvLen; + } else { + break; + } + } + NSString* ret = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; + return ret; +} +#endif +/////////////////////////发送信息给服务器//////////////////////// +- (void) sendString:(NSString *)string +{ + if( self.canWrite ) { + NSData* data = [string dataUsingEncoding:NSUTF8StringEncoding]; + NSUInteger len = data.length; + NSMutableData* buffer = [[NSMutableData alloc] init]; + unsigned char head[4] = {0}; + head[0] = (len>>24); + head[1] = (len>>16); + head[2] = (len>>8); + head[3] = (len); + [buffer appendBytes:head length:4]; + [buffer appendData:data]; + + [self.sendArray insertObject:buffer atIndex:0]; + + [self sendOneData]; + } +} + + +#ifdef DEBUG ++ (id)jsonObject:(NSString *)s{ + NSData* data = [s dataUsingEncoding:NSUTF8StringEncoding]; + @try { + NSError *error = nil; + NSJSONReadingOptions options = 0; + id obj = [NSJSONSerialization JSONObjectWithData:data options:options error:&error]; + if (error) { + return nil; + } + return obj; + } @catch (NSException *exception) { + return nil; + } +} + ++(void) openUrlServer:( void(^)(NSDictionary* args) ) callback{ + dispatch_async(dispatch_get_global_queue(0, 0), ^{ + // 处理耗时操作的代码块... + + LVDebugConnection* debugConnection = [[LVDebugConnection alloc] init]; + if( [debugConnection waitUntilConnectionEnd]>0 ) { + [debugConnection sendCmd:@"debugger" info:@"true"]; + for(;;) { + NSString* cmd = [debugConnection getCmd]; + if( cmd ) { + NSDictionary* dic = [LVDebugConnection jsonObject:cmd]; + if( dic && [dic isKindOfClass:[NSDictionary class]] ) { + //通知主线程刷新 + dispatch_async(dispatch_get_main_queue(), ^{ + //回调或者说是通知主线程刷新, + if( callback ) { + callback( dic ); + } + }); + } + break; + } else { + [NSThread sleepForTimeInterval:0.1]; + } + } + [debugConnection closeAll]; + } else { + [debugConnection closeAll]; + } + + }); +} +#endif + + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvdebug/LVDebugLua.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvdebug/LVDebugLua.m new file mode 100644 index 00000000..af59ae89 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvdebug/LVDebugLua.m @@ -0,0 +1,759 @@ + +// debug.lua +char g_debug_lua[10674] = { + '_','D','E','B','U','G','_','F','I','L','E',' ','=',' ','"','d','e','b','u','g','.','l','u','a','"',0xa, + // _DEBUG_FILE = "debug.lua" + 0xa, + 'd','e','b','u','g','.','b','p','s',' ','=',' ','{',0xa, + // debug.bps = { + ' ',' ',' ',' ','m','a','x',' ','=',' ','0',',',0xa, + // max = 0, + ' ',' ',' ',' ','t','r','a','c','e',' ','=',' ','f','a','l','s','e',',',0xa, + // trace = false, + ' ',' ',' ',' ','l','a','s','t','_','c','m','d',' ','=',' ','"','"',',',0xa, + // last_cmd = "", + ' ',' ',' ',' ','n','e','x','t',' ','=',' ','f','a','l','s','e',',',0xa, + // next = false, + ' ',' ',' ',' ','c','u','r','_','f','u','n','c',' ','=',' ','n','i','l',',',0xa, + // cur_func = nil, + ' ',' ',' ',' ','t','r','a','c','e','_','c','o','u','n','t',' ','=',' ','0',',',0xa, + // trace_count = 0, + ' ',' ',' ',' ','v','a','r','_','t','b','l',' ','=',' ','n','i','l',',',0xa, + // var_tbl = nil, + '}',0xa, + // } + 0xa, + 'f','u','n','c','t','i','o','n',' ','d','e','b','u','g','_','l','o','g','(',' ','l','o','g','_','s','t','r',' ',')',0xa, + // function debug_log( log_str ) + ' ',' ',' ',' ','p','r','i','n','t','(',' ','"','[','L','u','a','V','i','e','w',']','[',0xe8,0xb0,0x83,0xe8,0xaf,0x95,0xe6,0x97,0xa5,0xe5,0xbf,0x97,']',' ','"',' ','.','.',' ','l','o','g','_','s','t','r',' ',')',';',0xa, + // print( "[LuaView][调试日志] " .. log_str ); + 'e','n','d',0xa, + // end + 0xa, + 'f','u','n','c','t','i','o','n',' ','d','e','b','u','g','_','p','r','i','n','t','_','v','a','r','_','0','(',' ','n','a','m','e',',',' ','v','a','l','u','e',',',' ','l','e','v','e','l',' ',')',0xa, + // function debug_print_var_0( name, value, level ) + ' ',' ',' ',' ','l','o','c','a','l',' ','r','e','t',' ','=',' ','"','"',';',0xa, + // local ret = ""; + ' ',' ',' ',' ','l','o','c','a','l',' ','p','r','e','f','i','x',' ','=',' ','s','t','r','i','n','g','.','r','e','p','(',' ','"',' ',' ',' ',' ','"',',',' ','l','e','v','e','l',' ',')',0xa, + // local prefix = string.rep( " ", level ) + ' ',' ',' ',' ','l','o','c','a','l',' ','s','t','r',' ','=',' ','s','t','r','i','n','g','.','f','o','r','m','a','t','(',' ','"','%','s','%','s',' ','=',' ','%','s','"',',',' ','p','r','e','f','i','x',',',' ','n','a','m','e',',',' ','t','o','s','t','r','i','n','g','(','v','a','l','u','e',')',' ',')',0xa, + // local str = string.format( "%s%s = %s", prefix, name, tostring(value) ) + 0xa, + ' ',' ',' ',' ','i','f',' ','t','y','p','e','(',' ','v','a','l','u','e',' ',')',' ','=','=',' ','"','t','a','b','l','e','"',' ','t','h','e','n',0xa, + // if type( value ) == "table" then + ' ',' ',' ',' ',' ',' ',' ',' ','i','f',' ','d','e','b','u','g','.','v','a','r','_','t','b','l','[','v','a','l','u','e',']',' ','t','h','e','n',0xa, + // if debug.var_tbl[value] then + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','-','-',0xe5,0xb7,0xb2,0xe5,0x9c,0xa8,0xe4,0xb8,0xb4,0xe6,0x97,0xb6,0xe8,0xa1,0xa8,0xe4,0xb8,0xad,0xe7,0x9a,0x84,',',0xe5,0x8f,0xaa,0xe6,0x89,0x93,0xe5,0x8d,0xb0,0xe8,0xa1,0xa8,0xe5,0x9c,0xb0,0xe5,0x9d,0x80,0xa, + // --已在临时表中的,只打印表地址 + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','r','e','t',' ','=',' ','r','e','t',' ','.','.',' ','t','o','s','t','r','i','n','g','(','s','t','r',')',' ','.','.',' ',0x27,0x5c,'n',0x27,';',0xa, + // ret = ret .. tostring(str) .. '\n'; + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','r','e','t','u','r','n',' ','r','e','t',';',0xa, + // return ret; + ' ',' ',' ',' ',' ',' ',' ',' ','e','n','d',0xa, + // end + 0xa, + ' ',' ',' ',' ',' ',' ',' ',' ','-','-',0xe5,0x8a,0xa0,0xe5,0x88,0xb0,0xe4,0xb8,0xb4,0xe6,0x97,0xb6,0xe8,0xa1,0xa8,0xe4,0xb8,0xad,',',0xe4,0xbb,0xa5,0xe5,0x85,0x8d,0xe8,0xa1,0xa8,0xe5,0x87,0xba,0xe7,0x8e,0xb0,0xe5,0xbe,0xaa,0xe7,0x8e,0xaf,0xe5,0xbc,0x95,0xe7,0x94,0xa8,0xe6,0x97,0xb6,',',0xe6,0x89,0x93,0xe5,0x8d,0xb0,0xe4,0xb9,0x9f,0xe4,0xba,0xa7,0xe7,0x94,0x9f,0xe6,0xad,0xbb,0xe5,0xbe,0xaa,0xe7,0x8e,0xaf,0xa, + // --加到临时表中,以免表出现循环引用时,打印也产生死循环 + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','.','v','a','r','_','t','b','l','[','v','a','l','u','e',']',' ','=',' ','t','r','u','e',0xa, + // debug.var_tbl[value] = true + ' ',' ',' ',' ',' ',' ',' ',' ','-','-',0xe6,0x89,0x93,0xe5,0x8d,0xb0,0xe8,0xa1,0xa8,0xe4,0xb8,0xad,0xe6,0x89,0x80,0xe6,0x9c,0x89,0xe6,0x95,0xb0,0xe6,0x8d,0xae,0xa, + // --打印表中所有数据 + ' ',' ',' ',' ',' ',' ',' ',' ','r','e','t',' ','=',' ','r','e','t',' ','.','.',' ','s','t','r','i','n','g','.','f','o','r','m','a','t','(',' ','"','%','s','%','s',' ','=',' ','{','"',',',' ','p','r','e','f','i','x',',',' ','n','a','m','e',' ',')',' ','.','.',' ',0x27,0x5c,'n',0x27,';',0xa, + // ret = ret .. string.format( "%s%s = {", prefix, name ) .. '\n'; + ' ',' ',' ',' ',' ',' ',' ',' ','f','o','r',' ','k',',',' ','v',' ','i','n',' ','p','a','i','r','s','(',' ','v','a','l','u','e',' ',')',' ','d','o',0xa, + // for k, v in pairs( value ) do + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','i','f',' ','t','y','p','e','(',' ','k',' ',')',' ','=','=',' ','"','s','t','r','i','n','g','"',' ','t','h','e','n',0xa, + // if type( k ) == "string" then + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','e','l','s','e',0xa, + // else + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','k',' ','=',' ','t','o','s','t','r','i','n','g','(','k',')',';',0xa, + // k = tostring(k); + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','-','-',0xe4,0xb8,0x8d,0xe6,0x89,0x93,0xe5,0x8d,0xb0,' ','"','_','"',0xe5,0xbc,0x80,0xe5,0xa4,0xb4,0xe7,0x9a,0x84,0xe5,0x86,0x85,0xe9,0x83,0xa8,0xe5,0x8f,0x98,0xe9,0x87,0x8f,0xa, + // --不打印 "_"开头的内部变量 + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','-','-','i','f',' ','s','t','r','i','n','g','.','s','u','b','(',' ','k',',',' ','1',',',' ','1',' ',')',' ','~','=',' ','"','_','"',' ','t','h','e','n',0xa, + // --if string.sub( k, 1, 1 ) ~= "_" then + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','r','e','t',' ','=',' ','r','e','t',' ','.','.',' ','d','e','b','u','g','_','p','r','i','n','t','_','v','a','r','_','0','(',' ','k',',',' ','v',',',' ','l','e','v','e','l',' ','+',' ','1',' ',')',0xa, + // ret = ret .. debug_print_var_0( k, v, level + 1 ) + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','-','-','e','n','d',0xa, + // --end + ' ',' ',' ',' ',' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ',' ',' ',' ',' ','r','e','t',' ','=',' ','r','e','t',' ','.','.',' ','p','r','e','f','i','x',' ','.','.',' ','"','}','"',' ','.','.',' ',0x27,0x5c,'n',0x27,';',0xa, + // ret = ret .. prefix .. "}" .. '\n'; + ' ',' ',' ',' ','e','l','s','e','i','f',' ','t','y','p','e','(',' ','v','a','l','u','e',' ',')',' ','=','=',' ','"','s','t','r','i','n','g','"',' ','t','h','e','n',0xa, + // elseif type( value ) == "string" then + ' ',' ',' ',' ',' ',' ',' ',' ','r','e','t',' ','=',' ','r','e','t',' ','.','.',' ','t','o','s','t','r','i','n','g','(','s','t','r',')',' ','.','.',' ',0x27,0x5c,'n',0x27,';',0xa, + // ret = ret .. tostring(str) .. '\n'; + ' ',' ',' ',' ','e','l','s','e',0xa, + // else + ' ',' ',' ',' ',' ',' ',' ',' ','r','e','t',' ','=',' ','r','e','t',' ','.','.',' ','t','o','s','t','r','i','n','g','(','s','t','r',')',' ','.','.',' ',0x27,0x5c,'n',0x27,';',0xa, + // ret = ret .. tostring(str) .. '\n'; + ' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ','r','e','t','u','r','n',' ','r','e','t',';',0xa, + // return ret; + 'e','n','d',0xa, + // end + 0xa, + 'f','u','n','c','t','i','o','n',' ','d','e','b','u','g','_','p','r','i','n','t','_','v','a','r','(',' ','n','a','m','e',',',' ','v','a','l','u','e',',',' ','l','e','v','e','l',' ',')',0xa, + // function debug_print_var( name, value, level ) + ' ',' ',' ',' ','l','o','c','a','l',' ','s',' ','=',' ','d','e','b','u','g','_','p','r','i','n','t','_','v','a','r','_','0','(',' ','n','a','m','e',',',' ','v','a','l','u','e',',',' ','l','e','v','e','l',' ',')',';',0xa, + // local s = debug_print_var_0( name, value, level ); + ' ',' ',' ',' ','i','f','(',' ','s',' ',')',' ','t','h','e','n',0xa, + // if( s ) then + ' ',' ',' ',' ',' ',' ',' ',' ','s',' ','=',' ','s',':','s','u','b','(','1',',',' ','s',':','l','e','n','(',')','-','1',' ',')',';',0xa, + // s = s:sub(1, s:len()-1 ); + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','l','o','g','(',' ','s',' ',')',';',0xa, + // debug_log( s ); + ' ',' ',' ',' ','e','l','s','e',0xa, + // else + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','l','o','g','(',' ','s',' ',')',';',0xa, + // debug_log( s ); + ' ',' ',' ',' ','e','n','d',0xa, + // end + 'e','n','d',0xa, + // end + 0xa, + 'f','u','n','c','t','i','o','n',' ','d','e','b','u','g','_','p','r','i','n','t','_','e','x','p','r','(',' ','v','a','r',' ',')',0xa, + // function debug_print_expr( var ) + ' ',' ',' ',' ','i','f',' ','(',' ','v','a','r','=','=','n','i','l',' ',')',' ','t','h','e','n',0xa, + // if ( var==nil ) then + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','l','o','g','(','"','d','e','b','u','g','_','p','r','i','n','t','_','e','x','p','r',' ','v','a','r','=','=','n','i','l','"',')',';',0xa, + // debug_log("debug_print_expr var==nil"); + ' ',' ',' ',' ',' ',' ',' ',' ','r','e','t','u','r','n',';',0xa, + // return; + ' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ','-','-',0xe6,0xb8,0x85,0xe7,0xa9,0xba,0xe4,0xb8,0xb4,0xe6,0x97,0xb6,0xe5,0x8f,0x98,0xe9,0x87,0x8f,0xe8,0xa1,0xa8,0xa, + // --清空临时变量表 + ' ',' ',' ',' ','d','e','b','u','g','.','v','a','r','_','t','b','l',' ','=',' ','{','}',0xa, + // debug.var_tbl = {} + 0xa, + ' ',' ',' ',' ','l','o','c','a','l',' ','i','n','d','e','x',' ','=',' ','1',0xa, + // local index = 1 + ' ',' ',' ',' ','-','-',0xe6,0x89,0xbe,0xe5,0xb1,0x80,0xe9,0x83,0xa8,0xe5,0x8f,0x98,0xe9,0x87,0x8f,0xa, + // --找局部变量 + ' ',' ',' ',' ','w','h','i','l','e',' ','t','r','u','e',' ','d','o',0xa, + // while true do + ' ',' ',' ',' ',' ',' ',' ',' ','l','o','c','a','l',' ','n','a','m','e',',',' ','v','a','l','u','e',' ','=',' ','d','e','b','u','g','.','g','e','t','l','o','c','a','l','(',' ','4',',',' ','i','n','d','e','x',' ',')',0xa, + // local name, value = debug.getlocal( 4, index ) + ' ',' ',' ',' ',' ',' ',' ',' ','i','f',' ','n','o','t',' ','n','a','m','e',' ','t','h','e','n',' ',0xa, + // if not name then + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','b','r','e','a','k',' ',0xa, + // break + ' ',' ',' ',' ',' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ',' ',' ',' ',' ','i','n','d','e','x',' ','=',' ','i','n','d','e','x',' ','+',' ','1',0xa, + // index = index + 1 + 0xa, + ' ',' ',' ',' ',' ',' ',' ',' ','i','f',' ','n','a','m','e',' ','=','=',' ','v','a','r',' ','t','h','e','n',0xa, + // if name == var then + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','p','r','i','n','t','_','v','a','r','(',' ','v','a','r',',',' ','v','a','l','u','e',',',' ','0',' ',')',0xa, + // debug_print_var( var, value, 0 ) + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','r','e','t','u','r','n',0xa, + // return + ' ',' ',' ',' ',' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ','e','n','d',0xa, + // end + 0xa, + ' ',' ',' ',' ','-','-',' ','t','r','y',' ','u','p','v','a','l','u','e','s',0xa, + // -- try upvalues + ' ',' ',' ',' ','l','o','c','a','l',' ','f','u','n','c',' ','=',' ','d','e','b','u','g','.','g','e','t','i','n','f','o','(','4',',','"','f','"',')','.','f','u','n','c',0xa, + // local func = debug.getinfo(4,"f").func + ' ',' ',' ',' ','l','o','c','a','l',' ','i','n','d','e','x',' ','=',' ','1',0xa, + // local index = 1 + ' ',' ',' ',' ','w','h','i','l','e',' ','t','r','u','e',' ','d','o',0xa, + // while true do + ' ',' ',' ',' ',' ',' ',' ',' ','l','o','c','a','l',' ','n','a','m','e',',',' ','v','a','l','u','e',' ','=',' ','d','e','b','u','g','.','g','e','t','u','p','v','a','l','u','e','(','f','u','n','c',',',' ','i','n','d','e','x',')',0xa, + // local name, value = debug.getupvalue(func, index) + ' ',' ',' ',' ',' ',' ',' ',' ','i','f',' ','n','o','t',' ','n','a','m','e',' ','t','h','e','n',' ',0xa, + // if not name then + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','b','r','e','a','k',' ',0xa, + // break + ' ',' ',' ',' ',' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ',' ',' ',' ',' ','i','f',' ','n','a','m','e',' ','=','=',' ','v','a','r',' ','t','h','e','n',' ',0xa, + // if name == var then + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','p','r','i','n','t','_','v','a','r','(',' ','v','a','r',',',' ','v','a','l','u','e',',',' ','0',' ',')',0xa, + // debug_print_var( var, value, 0 ) + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','r','e','t','u','r','n',0xa, + // return + ' ',' ',' ',' ',' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ',' ',' ',' ','i','n','d','e','x',' ','=',' ','i','n','d','e','x',' ','+',' ','1',0xa, + // index = index + 1 + ' ',' ',' ',' ','e','n','d',0xa, + // end + 0xa, + ' ',' ',' ',' ','-','-',0xe6,0x89,0xbe,0xe5,0x85,0xa8,0xe5,0xb1,0x80,0xe5,0x8f,0x98,0xe9,0x87,0x8f,0xa, + // --找全局变量 + ' ',' ',' ',' ','i','f',' ','_','G','[','v','a','r',']',' ','~','=',' ','n','i','l',' ','t','h','e','n',0xa, + // if _G[var] ~= nil then + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','p','r','i','n','t','_','v','a','r','(',' ','v','a','r',',',' ','_','G','[','v','a','r',']',',',' ','0',' ',')',0xa, + // debug_print_var( var, _G[var], 0 ) + ' ',' ',' ',' ',' ',' ',' ',' ','r','e','t','u','r','n',0xa, + // return + ' ',' ',' ',' ','e','n','d',0xa, + // end + 0xa, + ' ',' ',' ',' ','d','e','b','u','g','_','l','o','g','(',' ','v','a','r',' ','.','.',' ','"',' ','i','s',' ','i','n','v','a','l','i','d','"',' ',')',0xa, + // debug_log( var .. " is invalid" ) + 'e','n','d',0xa, + // end + 0xa, + 0xa, + 'f','u','n','c','t','i','o','n',' ','d','e','b','u','g','_','r','u','n','_','e','x','p','r','(',' ','s',' ',')',0xa, + // function debug_run_expr( s ) + ' ',' ',' ',' ','l','o','a','d','J','s','o','n','(','s',')',0xa, + // loadJson(s) + 'e','n','d',0xa, + // end + 0xa, + 'f','u','n','c','t','i','o','n',' ','a','d','d','_','b','r','e','a','k','p','o','i','n','t','(',' ','e','x','p','r',' ',')',0xa, + // function add_breakpoint( expr ) + ' ',' ',' ',' ','l','o','c','a','l',' ','s','i',' ','=',' ','s','t','r','i','n','g','.','f','i','n','d','(',' ','e','x','p','r',',',' ','"',':','"',' ',')',0xa, + // local si = string.find( expr, ":" ) + ' ',' ',' ',' ','i','f',' ','n','i','l',' ','=','=',' ','s','i',' ','t','h','e','n',0xa, + // if nil == si then + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','l','o','g','(',' ','"','a','d','d',' ','b','r','e','a','k','p','o','i','n','t',' ','e','r','r','o','r',',',' ','e','x','p','r',' ','(','"',' ','.','.',' ','e','x','p','r',' ','.','.',' ','"',')',' ','i','n','v','a','l','i','d','"',' ',')',0xa, + // debug_log( "add breakpoint error, expr (" .. expr .. ") invalid" ) + ' ',' ',' ',' ',' ',' ',' ',' ','r','e','t','u','r','n',0xa, + // return + ' ',' ',' ',' ','e','n','d',0xa, + // end + 0xa, + ' ',' ',' ',' ','l','o','c','a','l',' ','l','i','n','e',' ','=',' ','s','t','r','i','n','g','.','s','u','b','(',' ','e','x','p','r',',',' ','s','i',' ','+',' ','1',' ',')',0xa, + // local line = string.sub( expr, si + 1 ) + ' ',' ',' ',' ','l','o','c','a','l',' ','l','i','n','e',' ','=',' ','t','o','n','u','m','b','e','r','(',' ','l','i','n','e',' ',')',0xa, + // local line = tonumber( line ) + ' ',' ',' ',' ','l','o','c','a','l',' ','s','o','u','r','c','e',' ','=',' ','s','t','r','i','n','g','.','s','u','b','(',' ','e','x','p','r',',',' ','1',',',' ','s','i',' ','-',' ','1',' ',')',0xa, + // local source = string.sub( expr, 1, si - 1 ) + 0xa, + ' ',' ',' ',' ','-','-',0xe5,0x85,0x88,0xe6,0x9f,0xa5,0xe6,0x89,0xbe,0xe6,0x9c,0x89,0xe4,0xb8,0x8d,0xe6,0x9c,0x89,0xe7,0x9b,0xb8,0xe5,0x90,0x8c,0xe6,0x96,0xad,0xe7,0x82,0xb9,0xa, + // --先查找有不有相同断点 + ' ',' ',' ',' ','i','f',' ','(',' ','(',' ','d','e','b','u','g','.','b','p','s','[','l','i','n','e',']',' ','~','=',' ','n','i','l',' ',')',' ','a','n','d',' ','(',' ','d','e','b','u','g','.','b','p','s','[','l','i','n','e',']','[','s','o','u','r','c','e',']',' ','~','=',' ','n','i','l',' ',')',' ',')',' ','t','h','e','n',0xa, + // if ( ( debug.bps[line] ~= nil ) and ( debug.bps[line][source] ~= nil ) ) then + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','l','o','g','(',' ','s','t','r','i','n','g','.','f','o','r','m','a','t','(',' ','"','b','r','e','a','k','p','o','i','n','t',' ','%','s',':','%','d',' ','e','x','i','s','t','e','d','"',',',' ','s','o','u','r','c','e',',',' ','l','i','n','e',' ',')',' ',')',0xa, + // debug_log( string.format( "breakpoint %s:%d existed", source, line ) ) + ' ',' ',' ',' ',' ',' ',' ',' ','r','e','t','u','r','n',0xa, + // return + ' ',' ',' ',' ','e','n','d',0xa, + // end + 0xa, + ' ',' ',' ',' ','l','o','c','a','l',' ','t','b','l',' ','=',' ','{','}',0xa, + // local tbl = {} + ' ',' ',' ',' ','t','b','l','.','s','o','u','r','c','e',' ','=',' ','s','o','u','r','c','e',0xa, + // tbl.source = source + ' ',' ',' ',' ','t','b','l','.','l','i','n','e',' ','=',' ','l','i','n','e',0xa, + // tbl.line = line + ' ',' ',' ',' ','t','b','l','.','a','c','t','i','v','e',' ','=',' ','t','r','u','e',0xa, + // tbl.active = true + ' ',' ',' ',' ','t','b','l','.','n','u','m','b','e','r',' ','=',' ','d','e','b','u','g','.','b','p','s','.','m','a','x',' ','+',' ','1',0xa, + // tbl.number = debug.bps.max + 1 + 0xa, + ' ',' ',' ',' ','i','f',' ','d','e','b','u','g','.','b','p','s','[','l','i','n','e',']',' ','=','=',' ','n','i','l',' ','t','h','e','n',0xa, + // if debug.bps[line] == nil then + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','.','b','p','s','[','l','i','n','e',']',' ','=',' ','{','}',0xa, + // debug.bps[line] = {} + ' ',' ',' ',' ','e','n','d',0xa, + // end + 0xa, + ' ',' ',' ',' ','d','e','b','u','g','.','b','p','s','[','l','i','n','e',']','[','s','o','u','r','c','e',']',' ','=',' ','t','b','l',0xa, + // debug.bps[line][source] = tbl + ' ',' ',' ',' ','d','e','b','u','g','.','b','p','s','.','m','a','x',' ','=',' ','d','e','b','u','g','.','b','p','s','.','m','a','x',' ','+',' ','1',0xa, + // debug.bps.max = debug.bps.max + 1 + ' ',' ',' ',' ','d','e','b','u','g','_','l','o','g','(',' ','s','t','r','i','n','g','.','f','o','r','m','a','t','(',' ','"',0xe5,0x8a,0xa0,0xe6,0x96,0xad,0xe7,0x82,0xb9,'(','%','s',':','%','d',')','"',',',' ','s','o','u','r','c','e',',',' ','l','i','n','e',' ',')',' ',')',0xa, + // debug_log( string.format( "加断点(%s:%d)", source, line ) ) + 'e','n','d',0xa, + // end + 0xa, + 'f','u','n','c','t','i','o','n',' ','r','e','m','o','v','e','_','b','r','e','a','k','p','o','i','n','t','(',' ','e','x','p','r',' ',')',0xa, + // function remove_breakpoint( expr ) + ' ',' ',' ',' ','l','o','c','a','l',' ','s','i',' ','=',' ','s','t','r','i','n','g','.','f','i','n','d','(',' ','e','x','p','r',',',' ','"',':','"',' ',')',0xa, + // local si = string.find( expr, ":" ) + ' ',' ',' ',' ','i','f',' ','n','i','l',' ','=','=',' ','s','i',' ','t','h','e','n',0xa, + // if nil == si then + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','l','o','g','(',' ','"','r','e','m','o','v','e',' ','b','r','e','a','k','p','o','i','n','t',' ','e','r','r','o','r',',',' ','e','x','p','r',' ','(','"',' ','.','.',' ','e','x','p','r',' ','.','.',' ','"',')',' ','i','n','v','a','l','i','d','"',' ',')',0xa, + // debug_log( "remove breakpoint error, expr (" .. expr .. ") invalid" ) + ' ',' ',' ',' ',' ',' ',' ',' ','r','e','t','u','r','n',0xa, + // return + ' ',' ',' ',' ','e','n','d',0xa, + // end + 0xa, + ' ',' ',' ',' ','l','o','c','a','l',' ','l','i','n','e',' ','=',' ','s','t','r','i','n','g','.','s','u','b','(',' ','e','x','p','r',',',' ','s','i',' ','+',' ','1',' ',')',0xa, + // local line = string.sub( expr, si + 1 ) + ' ',' ',' ',' ','l','o','c','a','l',' ','l','i','n','e',' ','=',' ','t','o','n','u','m','b','e','r','(',' ','l','i','n','e',' ',')',0xa, + // local line = tonumber( line ) + ' ',' ',' ',' ','l','o','c','a','l',' ','s','o','u','r','c','e',' ','=',' ','s','t','r','i','n','g','.','s','u','b','(',' ','e','x','p','r',',',' ','1',',',' ','s','i',' ','-',' ','1',' ',')',0xa, + // local source = string.sub( expr, 1, si - 1 ) + 0xa, + ' ',' ',' ',' ','-','-',0xe5,0x85,0x88,0xe6,0x9f,0xa5,0xe6,0x89,0xbe,0xe6,0x9c,0x89,0xe4,0xb8,0x8d,0xe6,0x9c,0x89,0xe7,0x9b,0xb8,0xe5,0x90,0x8c,0xe6,0x96,0xad,0xe7,0x82,0xb9,0xa, + // --先查找有不有相同断点 + ' ',' ',' ',' ','i','f','(',' ','(',' ','d','e','b','u','g','.','b','p','s','[','l','i','n','e',']',' ','~','=',' ','n','i','l',' ',')',' ','a','n','d',' ','(',' ','d','e','b','u','g','.','b','p','s','[','l','i','n','e',']','[','s','o','u','r','c','e',']',' ','~','=',' ','n','i','l',' ',')',' ',')','t','h','e','n',0xa, + // if( ( debug.bps[line] ~= nil ) and ( debug.bps[line][source] ~= nil ) )then + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','.','b','p','s','[','l','i','n','e',']','[','s','o','u','r','c','e',']',' ','=',' ','n','i','l',';',0xa, + // debug.bps[line][source] = nil; + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','l','o','g','(',' ','s','t','r','i','n','g','.','f','o','r','m','a','t','(',' ','"',0xe5,0x88,0xa0,0xe7,0x82,0xb9,0xe6,0x96,0xad,'(','%','s',':','%','d',')','"',',',' ','s','o','u','r','c','e',',',' ','l','i','n','e',' ',')',' ',')',0xa, + // debug_log( string.format( "删点断(%s:%d)", source, line ) ) + ' ',' ',' ',' ',' ',' ',' ',' ','r','e','t','u','r','n',0xa, + // return + ' ',' ',' ',' ','e','l','s','e',0xa, + // else + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','l','o','g','(',' ','s','t','r','i','n','g','.','f','o','r','m','a','t','(',' ','"','n','o','t',' ','f','o','u','n','d',' ','b','r','e','a','k','p','o','i','n','t',' ','%','s',':','%','d',' ','e','x','i','s','t','e','d','"',',',' ','s','o','u','r','c','e',',',' ','l','i','n','e',' ',')',' ',')',0xa, + // debug_log( string.format( "not found breakpoint %s:%d existed", source, line ) ) + ' ',' ',' ',' ',' ',' ',' ',' ','r','e','t','u','r','n',0xa, + // return + ' ',' ',' ',' ','e','n','d',0xa, + // end + 'e','n','d',0xa, + // end + 0xa, + 'f','u','n','c','t','i','o','n',' ','d','e','b','u','g','_','s','h','o','w','_','b','p','(',')',0xa, + // function debug_show_bp() + ' ',' ',' ',' ','f','o','r',' ','k',',',' ','v',' ','i','n',' ','p','a','i','r','s','(',' ','d','e','b','u','g','.','b','p','s',' ',')',' ','d','o',0xa, + // for k, v in pairs( debug.bps ) do + ' ',' ',' ',' ',' ',' ',' ',' ','i','f',' ','t','y','p','e','(',' ','v',' ',')',' ','=','=',' ','"','t','a','b','l','e','"',' ','t','h','e','n',0xa, + // if type( v ) == "table" then + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','f','o','r',' ','k','1',',',' ','v','1',' ','i','n',' ','p','a','i','r','s','(',' ','v',' ',')',' ','d','o',0xa, + // for k1, v1 in pairs( v ) do + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','l','o','c','a','l',' ','s','t','r',' ','=',' ','s','t','r','i','n','g','.','f','o','r','m','a','t','(',' ','"','b','p',' ','n','u','m',':','%','d',' ',' ','%','s',':','%','d',' ',' ','a','c','t','i','v','e',':','"',',',0xa, + // local str = string.format( "bp num:%d %s:%d active:", + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','v','1','.','n','u','m','b','e','r',',',0xa, + // v1.number, + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','v','1','.','s','o','u','r','c','e',',',0xa, + // v1.source, + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','v','1','.','l','i','n','e',' ',')',0xa, + // v1.line ) + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','i','f',' ','v','1','.','a','c','t','i','v','e',' ','t','h','e','n',0xa, + // if v1.active then + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','s','t','r',' ','=',' ','s','t','r',' ','.','.',' ','"','e','n','a','b','l','e','"',0xa, + // str = str .. "enable" + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','e','l','s','e',0xa, + // else + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','s','t','r',' ','=',' ','s','t','r',' ','.','.',' ','"','d','i','s','a','b','l','e','"',0xa, + // str = str .. "disable" + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','l','o','g','(',' ','s','t','r',' ',')',0xa, + // debug_log( str ) + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ',' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ','e','n','d',0xa, + // end + 'e','n','d',0xa, + // end + 0xa, + 'f','u','n','c','t','i','o','n',' ','d','e','b','u','g','_','d','e','l','_','b','p','(',' ','e','x','p','r',' ',')',0xa, + // function debug_del_bp( expr ) + ' ',' ',' ',' ','l','o','c','a','l',' ','n','u','m','b','e','r',' ','=',' ','t','o','n','u','m','b','e','r','(',' ','e','x','p','r',' ',')',0xa, + // local number = tonumber( expr ) + ' ',' ',' ',' ','f','o','r',' ','k',',',' ','v',' ','i','n',' ','p','a','i','r','s','(',' ','d','e','b','u','g','.','b','p','s',' ',')',' ','d','o',0xa, + // for k, v in pairs( debug.bps ) do + ' ',' ',' ',' ',' ',' ',' ',' ','i','f',' ','t','y','p','e','(',' ','v',' ',')',' ','=','=',' ','"','t','a','b','l','e','"',' ','t','h','e','n',0xa, + // if type( v ) == "table" then + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','f','o','r',' ','k','1',',',' ','v','1',' ','i','n',' ','p','a','i','r','s','(',' ','v',' ',')',' ','d','o',0xa, + // for k1, v1 in pairs( v ) do + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','i','f',' ','v','1','.','n','u','m','b','e','r',' ','=','=',' ','n','u','m','b','e','r',' ','t','h','e','n',0xa, + // if v1.number == number then + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','.','b','p','s','[','k',']','[','k','1',']',' ','=',' ','n','i','l',0xa, + // debug.bps[k][k1] = nil + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','l','o','g','(',' ','"','r','e','m','o','v','e',' ','b','p',':','"',' ','.','.',' ','n','u','m','b','e','r',' ','.','.',' ','"',' ','o','k','"',' ',')',0xa, + // debug_log( "remove bp:" .. number .. " ok" ) + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ',' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ','e','n','d',0xa, + // end + 'e','n','d',0xa, + // end + 0xa, + 'f','u','n','c','t','i','o','n',' ','d','e','b','u','g','_','e','n','a','b','l','e','_','b','p','(',' ','e','x','p','r',' ',')',0xa, + // function debug_enable_bp( expr ) + ' ',' ',' ',' ','l','o','c','a','l',' ','n','u','m','b','e','r',' ','=',' ','t','o','n','u','m','b','e','r','(',' ','e','x','p','r',' ',')',0xa, + // local number = tonumber( expr ) + ' ',' ',' ',' ','f','o','r',' ','k',',',' ','v',' ','i','n',' ','p','a','i','r','s','(',' ','d','e','b','u','g','.','b','p','s',' ',')',' ','d','o',0xa, + // for k, v in pairs( debug.bps ) do + ' ',' ',' ',' ',' ',' ',' ',' ','i','f',' ','t','y','p','e','(',' ','v',' ',')',' ','=','=',' ','"','t','a','b','l','e','"',' ','t','h','e','n',0xa, + // if type( v ) == "table" then + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','f','o','r',' ','k','1',',',' ','v','1',' ','i','n',' ','p','a','i','r','s','(',' ','v',' ',')',' ','d','o',0xa, + // for k1, v1 in pairs( v ) do + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','i','f',' ','v','1','.','n','u','m','b','e','r',' ','=','=',' ','n','u','m','b','e','r',' ','t','h','e','n',0xa, + // if v1.number == number then + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','v','1','.','a','c','t','i','v','e',' ','=',' ','t','r','u','e',0xa, + // v1.active = true + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','l','o','g','(',' ','"','e','n','a','b','l','e',' ','b','p',':','"',' ','.','.',' ','n','u','m','b','e','r',' ',')',0xa, + // debug_log( "enable bp:" .. number ) + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ',' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ','e','n','d',0xa, + // end + 'e','n','d',0xa, + // end + 0xa, + 'f','u','n','c','t','i','o','n',' ','d','e','b','u','g','_','d','i','s','a','b','l','e','_','b','p','(',' ','e','x','p','r',' ',')',0xa, + // function debug_disable_bp( expr ) + ' ',' ',' ',' ','l','o','c','a','l',' ','n','u','m','b','e','r',' ','=',' ','t','o','n','u','m','b','e','r','(',' ','e','x','p','r',' ',')',0xa, + // local number = tonumber( expr ) + ' ',' ',' ',' ','f','o','r',' ','k',',',' ','v',' ','i','n',' ','p','a','i','r','s','(',' ','d','e','b','u','g','.','b','p','s',' ',')',' ','d','o',0xa, + // for k, v in pairs( debug.bps ) do + ' ',' ',' ',' ',' ',' ',' ',' ','i','f',' ','t','y','p','e','(',' ','v',' ',')',' ','=','=',' ','"','t','a','b','l','e','"',' ','t','h','e','n',0xa, + // if type( v ) == "table" then + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','f','o','r',' ','k','1',',',' ','v','1',' ','i','n',' ','p','a','i','r','s','(',' ','v',' ',')',' ','d','o',0xa, + // for k1, v1 in pairs( v ) do + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','i','f',' ','v','1','.','n','u','m','b','e','r',' ','=','=',' ','n','u','m','b','e','r',' ','t','h','e','n',0xa, + // if v1.number == number then + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','v','1','.','a','c','t','i','v','e',' ','=',' ','f','a','l','s','e',0xa, + // v1.active = false + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','l','o','g','(',' ','"','d','i','s','a','b','l','e',' ','b','p',':','"',' ','.','.',' ','n','u','m','b','e','r',' ',')',0xa, + // debug_log( "disable bp:" .. number ) + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ',' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ','e','n','d',0xa, + // end + 'e','n','d',0xa, + // end + 0xa, + 'f','u','n','c','t','i','o','n',' ','d','e','b','u','g','_','h','e','l','p','(',')',0xa, + // function debug_help() + ' ',' ',' ',' ','p','r','i','n','t','(',' ','"','h',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','h','e','l','p',' ','i','n','f','o','"',' ',')',0xa, + // print( "h help info" ) + ' ',' ',' ',' ','p','r','i','n','t','(',' ','"','c',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','c','o','n','t','i','n','u','e','"',' ',')',0xa, + // print( "c continue" ) + ' ',' ',' ',' ','p','r','i','n','t','(',' ','"','s',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','t','r','a','c','e','"',' ',')',0xa, + // print( "s trace" ) + ' ',' ',' ',' ','p','r','i','n','t','(',' ','"','n',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','n','e','x','t','"',' ',')',0xa, + // print( "n next" ) + ' ',' ',' ',' ','p','r','i','n','t','(',' ','"','p',' ','v','a','r',' ',' ',' ',' ',' ',' ',' ',' ',' ','p','r','i','n','t',' ','v','a','r','i','a','b','l','e','"',' ',')',0xa, + // print( "p var print variable" ) + ' ',' ',' ',' ','p','r','i','n','t','(',' ','"','r','u','n',' ','e','x','p','r','e','s','s','i','o','n',' ',' ',' ',' ',' ',' ','r','u','n',' ','e','x','p','r','e','s','s','i','o','n',' ','c','o','d','e','"',' ',')',0xa, + // print( "run expression run expression code" ) + ' ',' ',' ',' ','p','r','i','n','t','(',' ','"','b',' ',' ','s','r','c',':','l','i','n','e',' ',' ',' ','a','d','d',' ','b','r','e','a','k','p','o','i','n','t','"',' ',')',0xa, + // print( "b src:line add breakpoint" ) + ' ',' ',' ',' ','p','r','i','n','t','(',' ','"','r','b',' ','s','r','c',':','l','i','n','e',' ',' ',' ','r','e','m','o','v','e',' ','b','r','e','a','k','p','o','i','n','t','"',' ',')',0xa, + // print( "rb src:line remove breakpoint" ) + ' ',' ',' ',' ','p','r','i','n','t','(',' ','"','b','l',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','l','i','s','t',' ','b','r','e','a','k','p','o','i','n','t','"',' ',')',0xa, + // print( "bl list breakpoint" ) + ' ',' ',' ',' ','p','r','i','n','t','(',' ','"','b','t',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','p','r','i','n','t',' ','t','r','a','c','e','b','a','c','k','"',' ',')',0xa, + // print( "bt print traceback" ) + 'e','n','d',0xa, + // end + 0xa, + 'f','u','n','c','t','i','o','n',' ','d','e','b','u','g','_','r','u','n','i','n','g','_','e','x','e','c','u','t','e','(',' ','c','m','d',' ',')',0xa, + // function debug_runing_execute( cmd ) + ' ',' ',' ',' ','i','f','(',' ','c','m','d','=','=','n','i','l',' ',')',' ','t','h','e','n',' ',0xa, + // if( cmd==nil ) then + ' ',' ',' ',' ',0x9,'r','e','t','u','r','n',';',0xa, + // return; + ' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ','l','o','c','a','l',' ','c',' ','=',' ','c','m','d',0xa, + // local c = cmd + ' ',' ',' ',' ','l','o','c','a','l',' ','e','x','p','r',' ','=',' ','"','"',0xa, + // local expr = "" + ' ',' ',' ',' ','l','o','c','a','l',' ','s','i',' ','=',' ','s','t','r','i','n','g','.','f','i','n','d','(',' ','c','m','d',',',' ','"',' ','"',' ',')',0xa, + // local si = string.find( cmd, " " ) + ' ',' ',' ',' ','i','f',' ','s','i',' ','~','=',' ','n','i','l',' ','t','h','e','n',0xa, + // if si ~= nil then + ' ',' ',' ',' ',' ',' ',' ',' ','c',' ','=',' ','s','t','r','i','n','g','.','s','u','b','(',' ','c','m','d',',',' ','1',',',' ','s','i',' ','-',' ','1',' ',')',0xa, + // c = string.sub( cmd, 1, si - 1 ) + ' ',' ',' ',' ',' ',' ',' ',' ','e','x','p','r',' ','=',' ','s','t','r','i','n','g','.','s','u','b','(',' ','c','m','d',',',' ','s','t','r','i','n','g','.','f','i','n','d','(',' ','c','m','d',',',' ','"',' ','%','w','"',' ',')',' ','+',' ','1',' ',')',0xa, + // expr = string.sub( cmd, string.find( cmd, " %w" ) + 1 ) + ' ',' ',' ',' ','e','n','d',0xa, + // end + 0xa, + ' ',' ',' ',' ','i','f',' ','c',' ','=','=',' ','"','b','"',' ','t','h','e','n',0xa, + // if c == "b" then + ' ',' ',' ',' ',' ',' ',' ',' ','a','d','d','_','b','r','e','a','k','p','o','i','n','t','(',' ','e','x','p','r',' ',')',0xa, + // add_breakpoint( expr ) + ' ',' ',' ',' ','e','l','s','e','i','f',' ','c',' ','=','=',' ','"','r','b','"',' ','t','h','e','n',0xa, + // elseif c == "rb" then + ' ',' ',' ',' ',' ',' ',' ',' ','r','e','m','o','v','e','_','b','r','e','a','k','p','o','i','n','t','(',' ','e','x','p','r',' ',')',0xa, + // remove_breakpoint( expr ) + ' ',' ',' ',' ','e','l','s','e','i','f',' ','c',' ','=','=',' ','"','p','"',' ','t','h','e','n',0xa, + // elseif c == "p" then + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','p','r','i','n','t','_','e','x','p','r','(',' ','e','x','p','r',' ',')',0xa, + // debug_print_expr( expr ) + ' ',' ',' ',' ','e','n','d',0xa, + // end + 'e','n','d',0xa, + // end + 0xa, + 'f','u','n','c','t','i','o','n',' ','d','e','b','u','g','_','e','x','e','c','u','t','e','_','c','m','d','(',' ','e','n','v',' ',')',0xa, + // function debug_execute_cmd( env ) + ' ',' ',' ',' ','-','-','p','r','i','n','t','(',' ','"','(','l','d','b',')',' ','"',' ',')',0xa, + // --print( "(ldb) " ) + ' ',' ',' ',' ','l','o','c','a','l',' ','c','m','d',' ','=',' ','d','e','b','u','g','.','r','e','a','d','C','m','d','(',')',0xa, + // local cmd = debug.readCmd() + ' ',' ',' ',' ','i','f',' ','(',' ','c','m','d',' ','=','=','n','i','l',' ',')',' ','t','h','e','n',0xa, + // if ( cmd ==nil ) then + ' ',' ',' ',' ',0x9,'d','e','b','u','g','.','s','l','e','e','p','(','0','.','0','1',')',';',0xa, + // debug.sleep(0.01); + ' ',' ',' ',' ',0x9,'r','e','t','u','r','n',' ','f','a','l','s','e',';',0xa, + // return false; + ' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ','-','-',0xe5,0x8f,0x96,0xe4,0xb8,0x8a,0xe4,0xb8,0x80,0xe6,0xac,0xa1,0xe7,0x9a,0x84,0xe5,0x91,0xbd,0xe4,0xbb,0xa4,',',0xe6,0x96,0xb9,0xe4,0xbe,0xbf,0xe8,0xb0,0x83,0xe8,0xaf,0x95,0xa, + // --取上一次的命令,方便调试 + ' ',' ',' ',' ','-','-',' ','i','f',' ','c','m','d',' ','~','=',' ','"','"',' ','t','h','e','n',0xa, + // -- if cmd ~= "" then + ' ',' ',' ',' ','-','-',' ',' ',' ',' ',' ','d','e','b','u','g','.','b','p','s','.','l','a','s','t','_','c','m','d',' ','=',' ','c','m','d',0xa, + // -- debug.bps.last_cmd = cmd + ' ',' ',' ',' ','-','-',' ','e','l','s','e',0xa, + // -- else + ' ',' ',' ',' ','-','-',' ',' ',' ',' ',' ','c','m','d',' ','=',' ','d','e','b','u','g','.','b','p','s','.','l','a','s','t','_','c','m','d',0xa, + // -- cmd = debug.bps.last_cmd + ' ',' ',' ',' ','-','-',' ','e','n','d',0xa, + // -- end + 0xa, + ' ',' ',' ',' ','l','o','c','a','l',' ','c',' ','=',' ','c','m','d',0xa, + // local c = cmd + ' ',' ',' ',' ','l','o','c','a','l',' ','e','x','p','r',' ','=',' ','"','"',0xa, + // local expr = "" + ' ',' ',' ',' ','l','o','c','a','l',' ','s','i',' ','=',' ','s','t','r','i','n','g','.','f','i','n','d','(',' ','c','m','d',',',' ','"',' ','"',' ',')',0xa, + // local si = string.find( cmd, " " ) + ' ',' ',' ',' ','i','f',' ','s','i',' ','~','=',' ','n','i','l',' ','t','h','e','n',0xa, + // if si ~= nil then + ' ',' ',' ',' ',' ',' ',' ',' ','c',' ','=',' ','s','t','r','i','n','g','.','s','u','b','(',' ','c','m','d',',',' ','1',',',' ','s','i',' ','-',' ','1',' ',')',0xa, + // c = string.sub( cmd, 1, si - 1 ) + ' ',' ',' ',' ',' ',' ',' ',' ','-','-',' ','l','o','c','a','l',' ','i','n','d','e','x',' ','=',' ','s','t','r','i','n','g','.','f','i','n','d','(',' ','c','m','d',',',' ','"',' ','%','w','"',' ',')',';',0xa, + // -- local index = string.find( cmd, " %w" ); + ' ',' ',' ',' ',' ',' ',' ',' ','-','-',' ','i','f',' ','(',' ','i','n','d','e','x',' ',')',' ','t','h','e','n',0xa, + // -- if ( index ) then + ' ',' ',' ',' ',' ',' ',' ',' ','-','-',' ',' ',' ',' ',' ','e','x','p','r',' ','=',' ','s','t','r','i','n','g','.','s','u','b','(',' ','c','m','d',',',' ','i','n','d','e','x',' ','+',' ','1',' ',')',';',0xa, + // -- expr = string.sub( cmd, index + 1 ); + ' ',' ',' ',' ',' ',' ',' ',' ','-','-',' ','e','n','d',0xa, + // -- end + ' ',' ',' ',' ',' ',' ',' ',' ','e','x','p','r',' ','=',' ','s','t','r','i','n','g','.','s','u','b','(','c','m','d',',',' ','s','i',' ','+',' ','1',' ',')',';',0xa, + // expr = string.sub(cmd, si + 1 ); + ' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ','i','f',' ','c','=','=','"','c','l','o','s','e','"',' ','t','h','e','n',0xa, + // if c=="close" then + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','c','l','o','s','e','(',')',';',0xa, + // debug_close(); + ' ',' ',' ',' ',' ',' ',' ',' ','r','e','t','u','r','n',' ','t','r','u','e',';',0xa, + // return true; + ' ',' ',' ',' ','e','l','s','e','i','f',' ','c','=','=','"','n','o','n','e','"',' ','t','h','e','n',0xa, + // elseif c=="none" then + ' ',' ',' ',' ',' ',' ',' ',' ','r','e','t','u','r','n',' ','f','a','l','s','e',';',0xa, + // return false; + ' ',' ',' ',' ','e','l','s','e','i','f',' ','c',' ','=','=',' ','"','c','"',' ','t','h','e','n',0xa, + // elseif c == "c" then + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','.','b','p','s','.','t','r','a','c','e',' ','=',' ','f','a','l','s','e',0xa, + // debug.bps.trace = false + ' ',' ',' ',' ',' ',' ',' ',' ','r','e','t','u','r','n',' ','t','r','u','e',0xa, + // return true + ' ',' ',' ',' ','e','l','s','e','i','f',' ','c',' ','=','=',' ','"','s','"',' ','t','h','e','n',0xa, + // elseif c == "s" then + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','.','b','p','s','.','t','r','a','c','e',' ','=',' ','t','r','u','e',0xa, + // debug.bps.trace = true + ' ',' ',' ',' ',' ',' ',' ',' ','r','e','t','u','r','n',' ','t','r','u','e',0xa, + // return true + ' ',' ',' ',' ','e','l','s','e','i','f',' ','c',' ','=','=',' ','"','n','"',' ','t','h','e','n',0xa, + // elseif c == "n" then + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','.','b','p','s','.','t','r','a','c','e',' ','=',' ','f','a','l','s','e',0xa, + // debug.bps.trace = false + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','.','b','p','s','.','n','e','x','t',' ','=',' ','t','r','u','e',0xa, + // debug.bps.next = true + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','.','b','p','s','.','c','u','r','_','f','u','n','c',' ','=',' ','e','n','v','.','f','u','n','c',0xa, + // debug.bps.cur_func = env.func + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','.','b','p','s','.','t','r','a','c','e','_','c','o','u','n','t',' ','=',' ','d','e','b','u','g','.','t','r','a','c','e','b','a','c','k','_','c','o','u','n','t','(',')',' ','-',' ','1',0xa, + // debug.bps.trace_count = debug.traceback_count() - 1 + ' ',' ',' ',' ',' ',' ',' ',' ','r','e','t','u','r','n',' ','t','r','u','e',0xa, + // return true + ' ',' ',' ',' ','e','l','s','e','i','f',' ','c',' ','=','=',' ','"','p','"',' ','t','h','e','n',0xa, + // elseif c == "p" then + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','p','r','i','n','t','_','e','x','p','r','(',' ','e','x','p','r',' ',')',0xa, + // debug_print_expr( expr ) + ' ',' ',' ',' ','e','l','s','e','i','f',' ','c',' ','=','=',' ','"','r','u','n','"',' ','t','h','e','n',0xa, + // elseif c == "run" then + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','r','u','n','_','e','x','p','r','(',' ','e','x','p','r',' ',')',0xa, + // debug_run_expr( expr ) + ' ',' ',' ',' ','e','l','s','e','i','f',' ','c',' ','=','=',' ','"','b','"',' ','t','h','e','n',0xa, + // elseif c == "b" then + ' ',' ',' ',' ',' ',' ',' ',' ','a','d','d','_','b','r','e','a','k','p','o','i','n','t','(',' ','e','x','p','r',' ',')',0xa, + // add_breakpoint( expr ) + ' ',' ',' ',' ','e','l','s','e','i','f',' ','c',' ','=','=',' ','"','r','b','"',' ','t','h','e','n',0xa, + // elseif c == "rb" then + ' ',' ',' ',' ',' ',' ',' ',' ','r','e','m','o','v','e','_','b','r','e','a','k','p','o','i','n','t','(',' ','e','x','p','r',' ',')',0xa, + // remove_breakpoint( expr ) + ' ',' ',' ',' ','e','l','s','e','i','f',' ','c',' ','=','=',' ','"','b','l','"',' ','t','h','e','n',0xa, + // elseif c == "bl" then + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','s','h','o','w','_','b','p','(',')',0xa, + // debug_show_bp() + ' ',' ',' ',' ','e','l','s','e','i','f',' ','c',' ','=','=',' ','"','d','"',' ','t','h','e','n',0xa, + // elseif c == "d" then + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','d','e','l','_','b','p','(',' ','e','x','p','r',' ',')',0xa, + // debug_del_bp( expr ) + ' ',' ',' ',' ','e','l','s','e','i','f',' ','c',' ','=','=',' ','"','b','e','"',' ','t','h','e','n',0xa, + // elseif c == "be" then + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','e','n','a','b','l','e','_','b','p','(',' ','e','x','p','r',' ',')',0xa, + // debug_enable_bp( expr ) + ' ',' ',' ',' ','e','l','s','e','i','f',' ','c',' ','=','=',' ','"','b','d','"',' ','t','h','e','n',0xa, + // elseif c == "bd" then + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','d','i','s','a','b','l','e','_','b','p','(',' ','e','x','p','r',' ',')',0xa, + // debug_disable_bp( expr ) + ' ',' ',' ',' ','e','l','s','e','i','f',' ','c',' ','=','=',' ','"','b','t','"',' ','t','h','e','n',0xa, + // elseif c == "bt" then + ' ',' ',' ',' ',' ',' ',' ',' ','l','o','c','a','l',' ','t','r','a','c','e',' ','=',' ','d','e','b','u','g','.','t','r','a','c','e','b','a','c','k','(','"','"',',',' ','3',')',';',0xa, + // local trace = debug.traceback("", 3); + ' ',' ',' ',' ',' ',' ',' ',' ','p','r','i','n','t','(',' ','t','r','a','c','e',' ',')',';',0xa, + // print( trace ); + ' ',' ',' ',' ','e','l','s','e','i','f',' ','c',' ','=','=',' ','"','s','t','a','c','k','"',' ','t','h','e','n',0xa, + // elseif c == "stack" then + ' ',' ',' ',' ',' ',' ',' ',' ','l','o','c','a','l',' ','t','r','a','c','e',' ','=',' ','d','e','b','u','g','.','t','r','a','c','e','b','a','c','k','(','"','"',',',' ','3',')',';',0xa, + // local trace = debug.traceback("", 3); + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','.','w','r','i','t','e','C','m','d','(','"','s','t','a','c','k','"',',',' ','t','r','a','c','e',',',' ','n','i','l',')',';',0xa, + // debug.writeCmd("stack", trace, nil); + ' ',' ',' ',' ','e','l','s','e','i','f',' ','c',' ','=','=',' ','"','h','"',' ','t','h','e','n',0xa, + // elseif c == "h" then + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','h','e','l','p','(',')',0xa, + // debug_help() + ' ',' ',' ',' ','e','l','s','e',0xa, + // else + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','_','l','o','g','(',' ','"','i','n','v','a','l','i','d',' ','c','m','d',':','"',' ','.','.',' ','c','m','d',' ',')',0xa, + // debug_log( "invalid cmd:" .. cmd ) + ' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ','r','e','t','u','r','n',' ','f','a','l','s','e',0xa, + // return false + 'e','n','d',0xa, + // end + 0xa, + 'f','u','n','c','t','i','o','n',' ','d','e','b','u','g','_','t','r','a','c','e','(',' ','e','v','e','n','t',',',' ','l','i','n','e',' ',')',0xa, + // function debug_trace( event, line ) + ' ',' ',' ',' ','l','o','c','a','l',' ','e','n','v',' ','=',' ','d','e','b','u','g','.','g','e','t','i','n','f','o','(',' ','2',' ',')',0xa, + // local env = debug.getinfo( 2 ) + 0xa, + ' ',' ',' ',' ','i','f',' ','e','n','v','.','s','o','u','r','c','e',' ','=','=',' ','_','D','E','B','U','G','_','F','I','L','E',' ','t','h','e','n',0xa, + // if env.source == _DEBUG_FILE then + ' ',' ',' ',' ',' ',' ',' ',' ','r','e','t','u','r','n',0xa, + // return + ' ',' ',' ',' ','e','n','d',0xa, + // end + 0xa, + ' ',' ',' ',' ','-','-',0xe5,0x88,0xa4,0xe6,0x96,0xad,0xe6,0x98,0xaf,0xe5,0x90,0xa6,0xe5,0x9c,0xa8,'n','e','x','t',0xe8,0xb0,0x83,0xe8,0xaf,0x95,0xa, + // --判断是否在next调试 + ' ',' ',' ',' ','i','f',' ','d','e','b','u','g','.','b','p','s','.','n','e','x','t',' ',' ','t','h','e','n',0xa, + // if debug.bps.next then + ' ',' ',' ',' ',' ',' ',' ',' ','l','o','c','a','l',' ','t','r','a','c','e','_','c','o','u','n','t',' ','=',' ','d','e','b','u','g','.','t','r','a','c','e','b','a','c','k','_','c','o','u','n','t','(',')',0xa, + // local trace_count = debug.traceback_count() + ' ',' ',' ',' ',' ',' ',' ',' ','-','-',0xe5,0x87,0xbd,0xe6,0x95,0xb0,0xe8,0xbf,0x94,0xe5,0x9b,0x9e,0xe4,0xba,0x86,',',0xe8,0xb0,0x83,0xe7,0x94,0xa8,0xe6,0xa0,0x88,0xe6,0x95,0xb0,0xe9,0x87,0x8f,0xe5,0xb0,0xb1,0xe4,0xbc,0x9a,0xe6,0xaf,0x94,0xe7,0x8e,0xb0,0xe5,0x9c,0xa8,0xe5,0xb0,0x8f,0xa, + // --函数返回了,调用栈数量就会比现在小 + ' ',' ',' ',' ',' ',' ',' ',' ','i','f',' ','t','r','a','c','e','_','c','o','u','n','t',' ','<',' ','d','e','b','u','g','.','b','p','s','.','t','r','a','c','e','_','c','o','u','n','t',' ','t','h','e','n',0xa, + // if trace_count < debug.bps.trace_count then + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','.','b','p','s','.','n','e','x','t',' ','=',' ','f','a','l','s','e',0xa, + // debug.bps.next = false + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','.','b','p','s','.','t','r','a','c','e',' ','=',' ','t','r','u','e',0xa, + // debug.bps.trace = true + ' ',' ',' ',' ',' ',' ',' ',' ','e','l','s','e','i','f',' ','t','r','a','c','e','_','c','o','u','n','t',' ','=','=',' ','d','e','b','u','g','.','b','p','s','.','t','r','a','c','e','_','c','o','u','n','t',' ','t','h','e','n',0xa, + // elseif trace_count == debug.bps.trace_count then + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','i','f',' ','d','e','b','u','g','.','b','p','s','.','c','u','r','_','f','u','n','c',' ','=','=',' ','e','n','v','.','f','u','n','c',' ','t','h','e','n',0xa, + // if debug.bps.cur_func == env.func then + 0x9,' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','.','b','p','s','.','n','e','x','t',' ','=',' ','f','a','l','s','e',0xa, + // debug.bps.next = false + 0x9,' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','.','b','p','s','.','t','r','a','c','e',' ','=',' ','t','r','u','e',0xa, + // debug.bps.trace = true + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ',' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ',' ','e','n','d',0xa, + // end + 0xa, + ' ',' ',' ',' ','-','-',0xe5,0x88,0xa4,0xe6,0x96,0xad,0xe6,0x98,0xaf,0xe5,0x90,0xa6,0xe6,0x9c,0x89,0xe6,0x96,0xad,0xe7,0x82,0xb9,0xa, + // --判断是否有断点 + ' ',' ',' ',' ','i','f','(',' ','(',' ','n','o','t',' ','d','e','b','u','g','.','b','p','s','.','t','r','a','c','e',' ',')',' ','a','n','d',' ','(',' ','d','e','b','u','g','.','b','p','s','[','l','i','n','e',']',' ','~','=',' ','n','i','l',' ',')',' ',')',' ','t','h','e','n',0xa, + // if( ( not debug.bps.trace ) and ( debug.bps[line] ~= nil ) ) then + ' ',' ',' ',' ',' ',' ',' ',' ','l','o','c','a','l',' ','t','b','l',' ','=',' ','d','e','b','u','g','.','b','p','s','[','l','i','n','e',']','[','e','n','v','.','s','o','u','r','c','e',']',0xa, + // local tbl = debug.bps[line][env.source] + ' ',' ',' ',' ',' ',' ',' ',' ','i','f','(',' ',' ','(',' ','t','b','l',' ','~','=',' ','n','i','l',' ',')',' ','a','n','d',' ','t','b','l','.','a','c','t','i','v','e',' ',' ',')','t','h','e','n',0xa, + // if( ( tbl ~= nil ) and tbl.active )then + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','-','-',0xe5,0xa6,0x82,0xe6,0x9e,0x9c,0xe5,0x9c,0xa8,'n','e','x','t',0xe6,0x97,0xb6,',',0xe7,0xa2,0xb0,0xe5,0x88,0xb0,0xe6,0x96,0xad,0xe7,0x82,0xb9,0xe4,0xba,0x86,',',0xe5,0xb0,0xb1,0xe6,0xb8,0x85,0xe9,0x99,0xa4,0xe5,0x8d,0x95,0xe6,0xad,0xa5,0xe8,0xbf,0x90,0xe8,0xa1,0x8c,0xe7,0x8a,0xb6,0xe6,0x80,0x81,0xa, + // --如果在next时,碰到断点了,就清除单步运行状态 + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','.','b','p','s','.','n','e','x','t',' ','=',' ','f','a','l','s','e',0xa, + // debug.bps.next = false + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','.','b','p','s','.','t','r','a','c','e',' ','=',' ','t','r','u','e',0xa, + // debug.bps.trace = true + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','-','-',' ','d','e','b','u','g','_','l','o','g','(',' ','"',0xe7,0xa2,0xb0,0xe5,0x88,0xb0,0xe6,0x96,0xad,0xe7,0x82,0xb9,' ','"',' ','.','.',' ','e','n','v','.','s','o','u','r','c','e',' ','.','.',' ','"',' ','-',' ','"',' ','.','.',' ','l','i','n','e',' ',')',0xa, + // -- debug_log( "碰到断点 " .. env.source .. " - " .. line ) + ' ',' ',' ',' ',' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ','e','n','d',0xa, + // end + 0xa, + ' ',' ',' ',' ','i','f',' ','d','e','b','u','g','.','b','p','s','.','t','r','a','c','e',' ','t','h','e','n',0xa, + // if debug.bps.trace then + ' ',' ',' ',' ',' ',' ',' ',' ','l','o','c','a','l',' ','s','r','c',' ','=',' ','d','e','b','u','g','.','g','e','t','_','f','i','l','e','_','l','i','n','e','(',' ','e','n','v','.','s','o','u','r','c','e',',',' ','l','i','n','e',' ',')',0xa, + // local src = debug.get_file_line( env.source, line ) + ' ',' ',' ',' ',' ',' ',' ',' ','l','o','c','a','l',' ','f','u','n','n','a','m','e',' ','=',' ','e','n','v','.','n','a','m','e',' ','o','r',' ','"','u','n','k','n','o','w','"',0xa, + // local funname = env.name or "unknow" + ' ',' ',' ',' ',' ',' ',' ',' ','-','-','d','e','b','u','g','_','l','o','g','(',' ','s','t','r','i','n','g','.','f','o','r','m','a','t','(',' ','"','%','s',':','%','d','(','%','s',')',' ',' ','%','s','"',',',' ','e','n','v','.','s','o','u','r','c','e',',',' ','l','i','n','e',',',' ','f','u','n','n','a','m','e',',',' ','s','r','c',' ',')',' ',')',0xa, + // --debug_log( string.format( "%s:%d(%s) %s", env.source, line, funname, src ) ) + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','.','r','u','n','n','i','n','g','L','i','n','e','(',' ','e','n','v','.','s','o','u','r','c','e',',',' ','l','i','n','e',' ',')',';',0xa, + // debug.runningLine( env.source, line ); + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','.','b','p','s','.','c','u','r','_','f','i','l','e',' ','=',' ','e','n','v','.','s','o','u','r','c','e',';',0xa, + // debug.bps.cur_file = env.source; + ' ',' ',' ',' ',' ',' ',' ',' ','d','e','b','u','g','.','b','p','s','.','c','u','r','_','l','i','n','e',' ','=',' ','l','i','n','e',0xa, + // debug.bps.cur_line = line + ' ',' ',' ',' ',' ',' ',' ',' ','w','h','i','l','e',' ','n','o','t',' ','d','e','b','u','g','_','e','x','e','c','u','t','e','_','c','m','d','(',' ','e','n','v',' ',')',' ','d','o',0xa, + // while not debug_execute_cmd( env ) do + ' ',' ',' ',' ',' ',' ',' ',' ','e','n','d',0xa, + // end + ' ',' ',' ',' ',' ',' ',' ',' ','r','e','t','u','r','n',';',0xa, + // return; + ' ',' ',' ',' ','e','n','d',0xa, + // end + 'e','n','d',0xa, + // end + 0xa, + 'f','u','n','c','t','i','o','n',' ','b','e','g','i','n','_','d','e','b','u','g','(',')',0xa, + // function begin_debug() + ' ',' ',' ',' ','d','e','b','u','g','.','b','p','s','.','t','r','a','c','e',' ','=',' ','t','r','u','e',0xa, + // debug.bps.trace = true + ' ',' ',' ',' ','d','e','b','u','g','.','s','e','t','h','o','o','k','(',' ','d','e','b','u','g','_','t','r','a','c','e',',',' ','"','l','"',' ',')',0xa, + // debug.sethook( debug_trace, "l" ) + 'e','n','d',0xa, + // end + 0xa, + '-','-',0xe5,0x85,0xb3,0xe9,0x97,0xad,'d','e','b','u','g','g','e','r',0xa, + // --关闭debugger + 'f','u','n','c','t','i','o','n',' ','d','e','b','u','g','_','c','l','o','s','e','(',')',0xa, + // function debug_close() + ' ',' ',' ',' ','d','e','b','u','g','.','b','p','s','.','t','r','a','c','e',' ','=',' ','f','a','l','s','e',0xa, + // debug.bps.trace = false + ' ',' ',' ',' ','d','e','b','u','g','.','b','p','s','.','n','e','x','t',' ','=',' ','f','a','l','s','e',0xa, + // debug.bps.next = false + ' ',' ',' ',' ','d','e','b','u','g','.','s','e','t','h','o','o','k','(',')',0xa, + // debug.sethook() + 'e','n','d',0xa, + // end + 0xa, + 'd','e','b','u','g','_','l','o','g','(','"','l','o','a','d',' ','d','e','b','u','g',' ','m','o','d','e','l','"',')',';',0xa, + // debug_log("load debug model"); + 'd','e','b','u','g','.','p','r','i','n','t','T','o','S','e','r','v','e','r','(','t','r','u','e',')',';',0xa, + // debug.printToServer(true); + 0xa, + 0xa, + 'b','e','g','i','n','_','d','e','b','u','g','(',')',';',' ','-','-',' ','l','a','s','t',' ','l','i','n','e',0xa, + // begin_debug(); -- last line + 0xa, + 0 +}; + diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvdebug/LVDebuger.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvdebug/LVDebuger.h new file mode 100644 index 00000000..782a9375 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvdebug/LVDebuger.h @@ -0,0 +1,19 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + +extern void lv_printToServer(lua_State* L, const char* cs, int withTabChar); + +@interface LVDebuger : NSObject + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvdebug/LVDebuger.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvdebug/LVDebuger.m new file mode 100644 index 00000000..011f339f --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvdebug/LVDebuger.m @@ -0,0 +1,128 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVDebuger.h" +#import "LVHeads.h" +#import "LVDebugConnection.h" +#import "LView.h" +#import "LVHeads.h" + +@implementation LVDebuger + + +static int DebugReadCmd (lua_State *L) { + LuaViewCore* luaView = LV_LUASTATE_VIEW(L); + + NSString* cmd = [luaView.debugConnection getCmd]; + if( cmd ){ + lua_pushstring(L, cmd.UTF8String); + } else { + lua_pushnil(L); + } + return 1; +} + +static int DebugWriteCmd (lua_State *L) { + LuaViewCore* luaView = LV_LUASTATE_VIEW(L); + NSString* cmd = lv_paramString(L, 1); + NSString* info = lv_paramString(L, 2); + NSDictionary* args = lv_luaTableToDictionary(L, 3); + + [luaView.debugConnection sendCmd:cmd info:info args:args]; + return 0; +} + +static int DebugSleep (lua_State *L) { + float time = lua_tonumber(L, 1); + if( time>0 ) { + [NSThread sleepForTimeInterval:time]; + } + return 0; +} + +static int DebugPrintToServer (lua_State *L) { + LuaViewCore* luaView = LV_LUASTATE_VIEW(L); + BOOL open = lua_toboolean(L, 1); + luaView.debugConnection.printToServer = !!open; + return 0; +} + +static int runningLine (lua_State *L) { + NSString* fileName = lv_paramString(L, 1); + if( fileName == nil ){ + fileName = @"unkown"; + } + int lineNumber = lua_tonumber(L, 2); + + NSString* lineInfo = [NSString stringWithFormat:@"%d",lineNumber]; + LuaViewCore* luaView = LV_LUASTATE_VIEW(L); + [luaView.debugConnection sendCmd:@"running" fileName:fileName info:lineInfo args:@{@"Line-Number":lineInfo}]; + return 0; +} + +static int get_file_line( lua_State *L ) +{ + lua_pushstring(L, "one line code"); + return 1; +} + +static int db_traceback_count (lua_State *L) { + lua_Debug ar; + int index = 1; + while (lua_getstack(L, index, &ar)) + index++; + lua_pushnumber( L, index - 1 ); + return 1; +} + +static const luaL_Reg dblib[] = { + {"readCmd", DebugReadCmd}, + {"writeCmd", DebugWriteCmd}, + {"sleep", DebugSleep}, + {"printToServer", DebugPrintToServer}, + {"runningLine", runningLine}, + {"get_file_line", get_file_line}, + {"traceback_count", db_traceback_count}, + {NULL, NULL} +}; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + luaL_register(L, LUA_DBLIBNAME, dblib); + return 0; +} + +// 把日志传送到服务器 +void lv_printToServer(lua_State* L, const char* cs, int withTabChar){ + LuaViewCore* lview = LV_LUASTATE_VIEW(L); + if( lview.debugConnection.printToServer ){ + NSMutableData* data = [[NSMutableData alloc] init]; + if( withTabChar ){ + [data appendBytes:" " length:4]; + } + [data appendBytes:cs length:strlen(cs)]; + + [lview.debugConnection sendCmd:@"log" info:[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]]; + } +} + +// 可变参数实例 +//void lv_print(NSString*format, ...) { +// va_list argumentList; +// va_start(argumentList, format); +// NSMutableString * message = [[NSMutableString alloc] initWithFormat:format +// arguments:argumentList]; +// [message appendString:@"\n"]; +// lv_printToServer(message.UTF8String,0); +// va_end(argumentList); +//} + + + +@end + + diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAlert.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAlert.h new file mode 100644 index 00000000..999e8b15 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAlert.h @@ -0,0 +1,22 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + +@interface LVAlert : UIAlertView + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; + +-(id) init:(lua_State*) l argNum:(int)num; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAlert.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAlert.m new file mode 100644 index 00000000..33b3fc86 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAlert.m @@ -0,0 +1,134 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVAlert.h" +#import "LVBaseView.h" +#import "LView.h" +#import "LVToast.h" +#import "LVHeads.h" + +@interface LVAlert () +@property(nonatomic,strong) NSArray* cmdArray; +@property(nonatomic,assign) int argNum; +@property(nonatomic,assign) int functionNum; +@end + +@implementation LVAlert{ +} + +-(void) dealloc{ + lua_State* L = self.lv_luaviewCore.l; + for ( int i=0; i=1 && index<=max ){ + return lv_paramString(L, index); + } + return nil; +} + +static int lvNewAlertView (lua_State *L) { + int num = lua_gettop(L); + LVAlert* alertView = [[LVAlert alloc] init:L argNum:num]; + if( num>0 ){ + int argID= 0; + for ( int i=1; i<=num; i++ ) { + if( lua_type(L, i) == LUA_TFUNCTION ) { + NSString* tag = alertView.cmdArray[argID++]; + [LVUtil registryValue:L key:tag stack:i]; + alertView.argNum = argID; + } + } + [alertView show]; + } + return 0; +} + + +static int toast (lua_State *L) { + int num = lua_gettop(L); + if( num>0 ){ + NSString* s = lv_paramString(L, 1); + if( s ==nil ) { + s = @" "; + } + // CGSize size = [UIScreen mainScreen].bounds.size; + [LVToast showWithText:s duration:2]; + } + return 0; +} + + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + + // 自动消失的提示框 + lv_defineGlobalFunc("Toast", toast, L); + + // 系统Alert提示框 + [LVUtil reg:L clas:self cfunc:lvNewAlertView globalName:globalName defaultName:@"Alert"]; + const struct luaL_Reg memberFunctions [] = { + {NULL, NULL} + }; + + lv_createClassMetaTable(L, META_TABLE_UIAlertView); + + //luaL_openlib(L, NULL, [LVBaseView lvMemberFunctions], 0); + luaL_openlib(L, NULL, memberFunctions, 0); + return 1; +} + + + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAnimate.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAnimate.h new file mode 100644 index 00000000..52845eae --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAnimate.h @@ -0,0 +1,21 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + +@interface LVAnimate : UIView + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; + +-(id) init:(lua_State*) l; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAnimate.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAnimate.m new file mode 100644 index 00000000..1c306132 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAnimate.m @@ -0,0 +1,137 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + + +#import "LVAnimate.h" +#import "LVUtil.h" +#import "LView.h" +#import "LVHeads.h" + + +@interface LVAnimate () +@property(nonatomic,strong) id mySelf; +@property(nonatomic,assign) float time; +@end + + +@implementation LVAnimate + +-(id) init:(lua_State*) L{ + self = [super init]; + if( self ){ + self.mySelf = self; + self.lv_luaviewCore = LV_LUASTATE_VIEW(L); + } + return self; +} + +-(void) dealloc{ + self.lv_luaviewCore = nil; + self.lv_userData = nil; +} + + +static int lvNewAnimate (lua_State *L) { + int argNum = lua_gettop(L); + if( argNum>=1 ){ + LVAnimate* animate = [[LVAnimate alloc] init:L]; + + int stackID = 1; + + float delay = 0; + float duration = 0.3; + UIViewAnimationOptions option = 0; + CGFloat dampingRatio = 0;//0~1 + CGFloat velocity = 0;//0~1 + + if( lua_type(L, stackID)==LUA_TNUMBER ){ + duration = lua_tonumber(L,stackID++); + } + if( lua_type(L, stackID)==LUA_TNUMBER ){ + delay = lua_tonumber(L,stackID++); + } + + if( lua_type(L, stackID)==LUA_TNUMBER ){ + dampingRatio = lua_tonumber(L,stackID++); + } + + if( lua_type(L, stackID)==LUA_TNUMBER ){ + velocity = lua_tonumber(L,stackID++); + } + + if( lua_type(L, stackID)==LUA_TNUMBER ){ + option = lua_tonumber(L,stackID++); + } + + lua_createtable(L, 0, 8);// table + if( argNum>=stackID && lua_type(L,stackID)==LUA_TFUNCTION ){ + lua_pushstring(L, "animations");// key + lua_pushvalue(L, stackID);//value + lua_settable(L, -3); + stackID++; + } + if( argNum>=stackID && lua_type(L,stackID)==LUA_TFUNCTION ){ + lua_pushstring(L, "completion");// key + lua_pushvalue(L, stackID );//value + lua_settable(L, -3); + } + + [LVUtil registryValue:L key:animate stack:-1]; + + + if( dampingRatio>0 ) { + [UIView animateWithDuration:duration + delay:delay + usingSpringWithDamping:dampingRatio + initialSpringVelocity:velocity + options:option animations:^{ + if( animate.lv_luaviewCore && animate.lv_luaviewCore.l ) { + lua_checkstack32( animate.lv_luaviewCore.l); + [LVUtil call:animate.lv_luaviewCore.l lightUserData:animate key1:"animations" key2:NULL nargs:0]; + } + } completion:^(BOOL finished) { + lua_State* l = animate.lv_luaviewCore.l; + if( l ) { + lua_settop(l, 0); + lua_checkstack32(l); + [LVUtil call:l lightUserData:animate key1:"completion" key2:NULL nargs:0]; + + [LVUtil unregistry:l key:animate]; + } + animate.mySelf = nil; + }]; + } else { + [UIView animateWithDuration:duration + delay:delay + options:option animations:^{ + if( animate.lv_luaviewCore && animate.lv_luaviewCore.l ) { + lua_checkstack32( animate.lv_luaviewCore.l); + [LVUtil call:animate.lv_luaviewCore.l lightUserData:animate key1:"animations" key2:NULL nargs:0]; + } + } completion:^(BOOL finished) { + lua_State* l = animate.lv_luaviewCore.l; + if( l ) { + lua_settop(l, 0); + lua_checkstack32(l); + [LVUtil call:l lightUserData:animate key1:"completion" key2:NULL nargs:0]; + + [LVUtil unregistry:l key:animate]; + } + animate.mySelf = nil; + }]; + } + } + return 0; /* new userdatum is already on the stack */ +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewAnimate globalName:globalName defaultName:@"Animate"]; + return 1; +} + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAnimator.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAnimator.h new file mode 100644 index 00000000..726c1fc1 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAnimator.h @@ -0,0 +1,51 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import +#import "LVHeads.h" +#import "ltable.h" + +typedef NS_ENUM(int, LVAniamtorInterpolator) { + LVLinearInterpolator = 0, + LVAccelerateInterpolator, + LVDecelerateInterpolator, + LVAccelerateDecelerateInterpolator, + LVAnticipateInterpolator, + LVAnticipateOvershootInterpolator, + LVOvershootInterpolator, +}; + +@interface LVAnimator : NSObject + +@property(nonatomic, copy) NSString *keyPath; +@property(nonatomic, copy) NSValue *toValue; + +@property(nonatomic, assign) float duration; +@property(nonatomic, assign) float delay; +@property(nonatomic, assign) int repeatCount; +@property(nonatomic, assign) BOOL autoreverses; +@property(nonatomic, assign) LVAniamtorInterpolator interpolator; // default is linear + +@property(nonatomic, weak) UIView *target; + +@property(nonatomic, weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic, assign) LVUserDataInfo* lv_userData; + +@property(nonatomic, readonly, getter=isRunning) BOOL running; +@property(nonatomic, readonly, getter=isPaused) BOOL paused; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +- (void)start; +- (void)cancel; + +- (void)pause; +- (void)resume; + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAnimator.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAnimator.m new file mode 100644 index 00000000..5840fe15 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAnimator.m @@ -0,0 +1,766 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVAnimator.h" +#import "LVHeads.h" +#import "LVUtil.h" +#import "LuaViewCore.h" +#import "LVTransform3D.h" +#import + +typedef NS_ENUM(int, LVAnimatorCallback) { + kLVAnimatorCallbackOnStart = 1, + kLVAnimatorCallbackOnEnd, + kLVAnimatorCallbackOnCancel, + kLVAnimatorCallbackOnPause, + kLVAnimatorCallbackOnResume, +}; + +static char *callbackKeys[] = { "", "onStart", "onEnd", "onCancel", "onPause", "onResume" }; + +@implementation LVAnimator { + NSString *_animationKey; + CABasicAnimation *_pausedAnimation; + NSTimeInterval _timeOffset; +} + +@dynamic running, paused; + +-(id) lv_nativeObject{ + return self; +} + +static int lvNewAnimator(lua_State *L) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVAnimator class]]; + + LVAnimator *animator = [c new]; + + NEW_USERDATA(userData, Animator); + userData->object = CFBridgingRetain(animator); + + animator.lv_userData = userData; + animator.lv_luaviewCore = LV_LUASTATE_VIEW(L); + + luaL_getmetatable(L, META_TABLE_Animator); + lua_setmetatable(L, -2); + + return 1; +} + +static int __gc(lua_State *L) { + LVUserDataInfo *data = (LVUserDataInfo *)lua_touserdata(L, 1); + if (LVIsType(data, Animator) && data->object) { + LVAnimator *animator = (__bridge LVAnimator *)data->object; + + CFBridgingRelease((__bridge CFTypeRef)(animator)); + data->object = nil; + + animator.lv_luaviewCore = nil; + animator.lv_userData = NULL; + } + + return 0; +} + +static int __tostring(lua_State *L) { + LVUserDataInfo *data = (LVUserDataInfo *)lua_touserdata(L, 1); + if (LVIsType(data, Animator)) { + LVAnimator *animator = (__bridge LVAnimator *)data->object; + NSString *s = [NSString stringWithFormat:@"Animator<%@>: %@", animator.keyPath, animator.toValue]; + lua_pushstring(L, s.UTF8String); + + return 1; + } + + return 0; +} + +static int __eq(lua_State *L) { + LVUserDataInfo *data1 = (LVUserDataInfo *)lua_touserdata(L, 1); + LVUserDataInfo *data2 = (LVUserDataInfo *)lua_touserdata(L, 2); + + if (LVIsType(data1, Animator) && LVIsType(data2, Animator)) { + LVAnimator *a1 = (__bridge LVAnimator *)data1->object; + LVAnimator *a2 = (__bridge LVAnimator *)data2->object; + + BOOL eq = [a1 isEqual:a2]; + lua_pushboolean(L, eq); + + return 1; + } + + return 0; +} + +static int clone(lua_State *L) { + LVUserDataInfo *data = (LVUserDataInfo *)lua_touserdata(L, 1); + if (LVIsType(data, Animator)) { + LVAnimator *animator = [(__bridge LVAnimator *)data->object copy]; + + NEW_USERDATA(userData, Animator); + userData->object = CFBridgingRetain(animator); + + animator.lv_userData = userData; + animator.lv_luaviewCore = LV_LUASTATE_VIEW(L); + + luaL_getmetatable(L, META_TABLE_Animator); + lua_setmetatable(L, -2); + + return 1; + } + + return 0; +} + +static int with(lua_State *L) { + LVUserDataInfo *adata = (LVUserDataInfo *)lua_touserdata(L, 1); + LVUserDataInfo *vdata = (LVUserDataInfo *)lua_touserdata(L, 2); + + if (LVIsType(adata, Animator) && LVIsType(vdata, View)) { + LVAnimator *animator = (__bridge LVAnimator *)adata->object; + animator.target = (__bridge UIView *)vdata->object; + } + + lv_pushUserdata(L, adata); + + return 1; +} + +static int start(lua_State *L) { + LVUserDataInfo *data = (LVUserDataInfo *)lua_touserdata(L, 1); + + if (LVIsType(data, Animator)) { + LVAnimator *animator = (__bridge LVAnimator *)data->object; + if (animator.running) { + LVLog(@"Animation of key:%@ is running!", animator.keyPath); + } else { + [animator start]; + } + } + + lv_pushUserdata(L, data); + + return 1; +} + +static int cancel(lua_State *L) { + LVUserDataInfo *data = (LVUserDataInfo *)lua_touserdata(L, 1); + + if (LVIsType(data, Animator)) { + LVAnimator *animator = (__bridge LVAnimator *)data->object; + [animator cancel]; + } + + lv_pushUserdata(L, data); + + return 1; +} + +static int isRunning(lua_State *L) { + LVUserDataInfo *data = (LVUserDataInfo *)lua_touserdata(L, 1); + + if (LVIsType(data, Animator)) { + LVAnimator *animator = (__bridge LVAnimator *)data->object; + lua_pushboolean(L, animator.running); + } else { + lua_pushboolean(L, 0); + } + + return 1; +} + +static int pauseAnimator(lua_State *L) { + LVUserDataInfo *data = (LVUserDataInfo *)lua_touserdata(L, 1); + + if (LVIsType(data, Animator)) { + LVAnimator *animator = (__bridge LVAnimator *)data->object; + [animator pause]; + } + + lv_pushUserdata(L, data); + + return 1; +} + +static int resumeAnimator(lua_State *L) { + LVUserDataInfo *data = (LVUserDataInfo *)lua_touserdata(L, 1); + + if (LVIsType(data, Animator)) { + LVAnimator *animator = (__bridge LVAnimator *)data->object; + [animator resume]; + } + + lv_pushUserdata(L, data); + + return 1; +} + +static int isPaused(lua_State *L) { + LVUserDataInfo *data = (LVUserDataInfo *)lua_touserdata(L, 1); + + if (LVIsType(data, Animator)) { + LVAnimator *animator = (__bridge LVAnimator *)data->object; + lua_pushboolean(L, animator.paused); + } else { + lua_pushboolean(L, 0); + } + + return 1; +} + +static int duration(lua_State *L) { + LVUserDataInfo *data = (LVUserDataInfo *)lua_touserdata(L, 1); + float value = lua_tonumber(L, 2); + + if (LVIsType(data, Animator)) { + LVAnimator *animator = (__bridge LVAnimator *)data->object; + + animator.duration = value; + } + + lv_pushUserdata(L, data); + + return 1; +} + +static int delay(lua_State *L) { + LVUserDataInfo *data = (LVUserDataInfo *)lua_touserdata(L, 1); + float value = lua_tonumber(L, 2); + + if (LVIsType(data, Animator)) { + LVAnimator *animator = (__bridge LVAnimator *)data->object; + + animator.delay = value; + } + + lv_pushUserdata(L, data); + + return 1; +} + +static int repeatCount(lua_State *L) { + LVUserDataInfo *data = (LVUserDataInfo *)lua_touserdata(L, 1); + int value = (int)lua_tointeger(L, 2); + + if (LVIsType(data, Animator)) { + LVAnimator *animator = (__bridge LVAnimator *)data->object; + + animator.repeatCount = value; + } + + lv_pushUserdata(L, data); + + return 1; +} + +static int autoreverses(lua_State *L) { + LVUserDataInfo *data = (LVUserDataInfo *)lua_touserdata(L, 1); + BOOL autoreverses = !!lua_toboolean(L, 2); + + if (LVIsType(data, Animator)) { + LVAnimator *animator = (__bridge LVAnimator *)data->object; + + animator.autoreverses = autoreverses; + } + + lv_pushUserdata(L, data); + + return 1; +} + +static int interpolator(lua_State *L) { + LVUserDataInfo *data = (LVUserDataInfo *)lua_touserdata(L, 1); + LVAniamtorInterpolator interpolator = lua_tonumber(L, 2); + + if (LVIsType(data, Animator)) { + LVAnimator *animator = (__bridge LVAnimator *)data->object; + + animator.interpolator = interpolator; + } + + lv_pushUserdata(L, data); + + return 1; +} + +static int setCallback(lua_State *L, int idx) { + LVUserDataInfo *data = (LVUserDataInfo *)lua_touserdata(L, 1); + + if (LVIsType(data, Animator)) { + lua_pushvalue(L, 1); + if (lua_type(L, 2) == LUA_TFUNCTION) { + lua_pushvalue(L, 2); + } else { + lua_pushnil(L); + } + + lv_udataRef(L, idx); + } + + lv_pushUserdata(L, data); + + return 1; +} + +static int onStart(lua_State *L) { + return setCallback(L, kLVAnimatorCallbackOnStart); +} + +static int onEnd(lua_State *L) { + return setCallback(L, kLVAnimatorCallbackOnEnd); +} + +static int onCancel(lua_State *L) { + return setCallback(L, kLVAnimatorCallbackOnCancel); +} + +static int onPause(lua_State *L) { + return setCallback(L, kLVAnimatorCallbackOnPause); +} + +static int onResume(lua_State *L) { + return setCallback(L, kLVAnimatorCallbackOnResume); +} + +static int callback(lua_State *L) { + LVUserDataInfo *data = (LVUserDataInfo *)lua_touserdata(L, 1); + if (LVIsType(data, Animator) && lua_type(L, 2) == LUA_TTABLE) { + lua_pushvalue(L, 2); + lua_pushnil(L); + + while (lua_next(L, -2)) { + if (lua_type(L, -2) != LUA_TSTRING) { + continue; + } + const char* key = lua_tostring(L, -2); + int idx = 0; + for (int i = 0; i < sizeof(callbackKeys) / sizeof(callbackKeys[0]); ++i) { + if (strcmp(key, callbackKeys[i]) == 0) { + idx = i; + break; + } + } + + if (idx != 0) { + lua_pushvalue(L, 1); + if (lua_type(L, -2) == LUA_TFUNCTION) { + lua_pushvalue(L, -2); + } else { + lua_pushnil(L); + } + lv_udataRef(L, idx); + lua_pop(L, 2); + } else { + lua_pop(L, 1); + } + } + lua_pop(L, 1); + } + + lv_pushUserdata(L, data); + + return 1; +} + +static int updateValue(lua_State *L, NSString *keyPath, id value) { + LVUserDataInfo *data = (LVUserDataInfo *)lua_touserdata(L, 1); + if (LVIsType(data, Animator)) { + LVAnimator *animator = (__bridge LVAnimator *)data->object; + if (keyPath) { + animator.keyPath = keyPath; + } + + animator.toValue = value; + } + + lua_settop(L, 1); + + return 1; +} + +static int updateFloat(lua_State *L, NSString *keyPath) { + float value = lua_tonumber(L, 2); + + return updateValue(L, keyPath, @(value)); +} + +static int updatePoint(lua_State *L, NSString *keyPath) { + float x = lua_tonumber(L, 2), y = lua_tonumber(L, 3); + NSValue *point = [NSValue valueWithCGPoint:CGPointMake(x, y)]; + + return updateValue(L, keyPath, point); +} + +static int alpha(lua_State *L) { + return updateFloat(L, @"opacity"); +} + +static int rotation(lua_State *L) { + return updateFloat(L, @"transform.rotation"); +} + +static int scale(lua_State *L) { + // default y = x + if (lua_gettop(L) == 2) { + lua_pushnumber(L, lua_tonumber(L, 2)); + } + return updatePoint(L, @"transform.scale"); +} + +static int scaleX(lua_State *L) { + return updateFloat(L, @"transform.scale.x"); +} + +static int scaleY(lua_State *L) { + return updateFloat(L, @"transform.scale.y"); +} + +static int translation(lua_State *L) { + return updatePoint(L, @"transform.translation"); +} + +static int translationX(lua_State *L) { + return updateFloat(L, @"transform.translation.x"); +} + +static int translationY(lua_State *L) { + return updateFloat(L, @"transform.translation.y"); +} + +static int value(lua_State *L) { + return updateFloat(L, nil); +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewAnimator globalName:globalName defaultName:@"Animation"]; + + const struct luaL_Reg memberFunctions[] = { + { "__gc", __gc }, + { "__tostring", __tostring }, + { "__eq", __eq }, + + { "clone", clone }, + + { "with", with }, + { "duration", duration }, + { "delay", delay }, + { "repeatCount", repeatCount }, + { "reverses", autoreverses }, // 和安卓特性不一样 + { "interpolator", interpolator }, + + { "cancel", cancel }, + { "start", start }, + { "isRunning", isRunning }, + + { "pause", pauseAnimator }, + { "resume", resumeAnimator }, + { "isPaused", isPaused }, + + { "callback", callback }, + { callbackKeys[kLVAnimatorCallbackOnStart], onStart }, + { callbackKeys[kLVAnimatorCallbackOnEnd], onEnd }, + { callbackKeys[kLVAnimatorCallbackOnCancel], onCancel }, + { callbackKeys[kLVAnimatorCallbackOnPause], onPause }, + { callbackKeys[kLVAnimatorCallbackOnResume], onResume }, + + { "alpha", alpha }, + { "rotation", rotation }, + { "scale", scale }, + { "scaleX", scaleX }, + { "scaleY", scaleY }, + { "translation", translation }, + { "translationX", translationX }, + { "translationY", translationY }, + { "value", value }, // IOS支持一个, 安卓支持多个值 + //{ "values", value }, + + { NULL, NULL} + }; + + lv_createClassMetaTable(L, META_TABLE_Animator); + luaL_openlib(L, NULL, memberFunctions, 0); + + return 1; +} + +- (instancetype)init { + if (self = [super init]) { + _autoreverses = YES; + } + + return self; +} + +- (instancetype)copyWithZone:(NSZone *)zone { + LVAnimator *animator = [[[self class] allocWithZone:zone] init]; + animator.keyPath = [self.keyPath copy]; + animator.toValue = [self.toValue copy]; + + animator.duration = self.duration; + animator.delay = self.delay; + animator.repeatCount = self.repeatCount; + animator.autoreverses = self.autoreverses; + + animator.target = self.target; + + return animator; +} + +- (instancetype)mutableCopyWithZone:(NSZone *)zone { + return [self copyWithZone:zone]; +} + +- (NSUInteger)hash { + return self.keyPath.hash; +} + +- (BOOL)isEqual:(id)object { + if (object == nil) { + return NO; + } + if (![object isKindOfClass:[self class]]) { + return NO; + } + + LVAnimator *a1 = (LVAnimator *)object; + return lv_objcEqual(self.keyPath, a1.keyPath) && + lv_objcEqual(self.toValue, a1.toValue) && + self.duration == a1.duration && + self.delay == a1.delay && + self.repeatCount == a1.repeatCount && + self.autoreverses == a1.autoreverses; +} + +- (CAMediaTimingFunction *)buildTimingFunction:(LVAniamtorInterpolator)interpolator { + switch (interpolator) { + case LVAnticipateInterpolator: + return [CAMediaTimingFunction functionWithControlPoints:0.5 :-0.6 :0.75 :0.5]; + case LVAnticipateOvershootInterpolator: + return [CAMediaTimingFunction functionWithControlPoints:0.5 :-0.55 :0.5 :1.55]; + case LVOvershootInterpolator: + return [CAMediaTimingFunction functionWithControlPoints:0.3 :0.9 :0.75 :1.3]; + case LVAccelerateDecelerateInterpolator: + return [CAMediaTimingFunction functionWithName:@"easeInEaseOut"]; + case LVAccelerateInterpolator: + return [CAMediaTimingFunction functionWithName:@"easeIn"]; + case LVDecelerateInterpolator: + return [CAMediaTimingFunction functionWithName:@"easeOut"]; + case LVLinearInterpolator: + default: + return [CAMediaTimingFunction functionWithName:@"linear"]; + } +} + +- (CAAnimation *)buildAnimation { + CAAnimation *animation = nil; + CALayer *layer = self.target.layer.presentationLayer ?: self.target.layer; + + if ([self.keyPath isEqualToString:@"transform.scale"]) { + CGPoint point = [self.toValue CGPointValue]; + + NSString *kx = @"transform.scale.x"; + CABasicAnimation *ax = [CABasicAnimation animationWithKeyPath:kx]; + ax.fromValue = [layer valueForKeyPath:kx]; + ax.toValue = @(point.x); + + NSString *ky = @"transform.scale.y"; + CABasicAnimation *ay = [CABasicAnimation animationWithKeyPath:ky]; + ay.fromValue = [layer valueForKeyPath:ky]; + ay.toValue = @(point.y); + + CAAnimationGroup *group = [CAAnimationGroup animation]; + group.animations = @[ax, ay]; + + animation = group; + } else if ([self.keyPath isEqualToString:@"transform.rotation"]) { + CABasicAnimation *a = [CABasicAnimation animationWithKeyPath:@"transform.rotation"]; + a.fromValue = [layer valueForKeyPath:@"transform.rotation"]; + a.toValue = @(((NSNumber *)self.toValue).floatValue * M_PI / 180.0); + + animation = a; + } else { + CABasicAnimation *a = [CABasicAnimation animationWithKeyPath:self.keyPath]; + a.fromValue = [layer valueForKeyPath:self.keyPath]; + a.toValue = self.toValue; + + animation = a; + } + + animation.delegate = (id)self; + animation.duration = self.duration; + animation.fillMode = @"both"; + + if (self.repeatCount > 0) { + animation.repeatCount = self.repeatCount; + if (animation.autoreverses) { + animation.repeatCount += 0.5; + } + animation.autoreverses = self.autoreverses; + } else if (self.repeatCount < 0) { + animation.repeatCount = HUGE_VALF; + animation.autoreverses = self.autoreverses; + } + + animation.timingFunction = [self buildTimingFunction:self.interpolator]; + animation.beginTime = CACurrentMediaTime() + self.delay; + + return animation; +} + +static void syncValue(CAAnimation *animation, CALayer *layer) { + if (!animation || !layer) { + return; + } + + if ([animation isKindOfClass:[CAAnimationGroup class]]) { + for (CAAnimation *a in ((CAAnimationGroup *)animation).animations) { + syncValue(a, layer); + } + } else if ([animation isKindOfClass:[CABasicAnimation class]]) { + CABasicAnimation *a = (CABasicAnimation *)animation; + [layer setValue:a.toValue forKeyPath:a.keyPath]; + } +} + +- (void)syncAnimatingValue:(CALayer *)layer { + if (!layer.presentationLayer) { + return; + } + + NSString *keyPath = nil; + if ([self.keyPath isEqualToString:@"opacity"]) { + keyPath = @"opacity"; + } else { + keyPath = @"transform"; + } + NSValue *current = [layer.presentationLayer valueForKeyPath:keyPath]; + [layer setValue:current forKeyPath:keyPath]; +} + +- (void)start { + if (self.running) { + LVLog(@"Animator(%p keyPath:%@) is running!", self.lv_userData, self.keyPath); + return; + } + if (self.keyPath.length == 0 || self.toValue == nil) { + LVLog(@"Animator keyPath and value cannot be nil!"); + return; + } + + CAAnimation *animation = nil; + if (self.target != nil && (animation = [self buildAnimation])) { + _animationKey = [NSString stringWithFormat:@"LVAnimator:%@", self.keyPath]; + + CALayer *layer = self.target.layer; + if ([layer animationForKey:_animationKey]) { + LVLog(@"warning: Animation of keyPath:%@ is running", self.keyPath); + } + + syncValue(animation, layer); + [layer addAnimation:animation forKey:_animationKey]; + [self callback:kLVAnimatorCallbackOnStart]; + } +} + +- (void)cancel { + if (!self.running) { + LVLog(@"warning: Animation of keyPath:%@ is not running", self.keyPath); + return; + } + + if (self.paused) { + _animationKey = nil; + _pausedAnimation = nil; + _timeOffset = 0.0; + [self callback:kLVAnimatorCallbackOnCancel]; + + // call onEnd, same as Android SDK + [self callback:kLVAnimatorCallbackOnEnd]; + } else { + CALayer *layer = self.target.layer; + [self syncAnimatingValue:layer]; + [layer removeAnimationForKey:_animationKey]; + } +} + +- (BOOL)isRunning { + return _animationKey != nil; +} + +- (void)pause { + if (!self.running) { + LVLog(@"Animator(%p) is not running!", self.lv_userData); + return; + } + if (self.paused) { + LVLog(@"Animator(%p) is already paused!", self.lv_userData); + return; + } + + CALayer *layer = self.target.layer; + [self syncAnimatingValue:layer]; + + _pausedAnimation = [[layer animationForKey:_animationKey] copy]; + _timeOffset = CACurrentMediaTime() - _pausedAnimation.beginTime; + + [layer removeAnimationForKey:_animationKey]; +} + +- (void)resume { + CALayer *layer = self.target.layer; + + _pausedAnimation.beginTime = CACurrentMediaTime() - _timeOffset; + + syncValue(_pausedAnimation, layer); + [layer addAnimation:_pausedAnimation forKey:_animationKey]; + + _timeOffset = 0.0; + _pausedAnimation = nil; + + [self callback:kLVAnimatorCallbackOnResume]; +} + +- (BOOL)isPaused { + return _pausedAnimation != nil; +} + +#pragma mark - animation delegate + +- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag { + if (self.paused) { + [self callback:kLVAnimatorCallbackOnPause]; + } else { + _animationKey = nil; + _pausedAnimation = nil; + _timeOffset = 0.0; + + if (!flag) { + [self callback:kLVAnimatorCallbackOnCancel]; + } + + // call onEnd, same as Android SDK + [self callback:kLVAnimatorCallbackOnEnd]; + } +} + +- (void)callback:(LVAnimatorCallback)idx { + lua_State* l = self.lv_luaviewCore.l; + if (l && self.lv_userData) { + int stackIndex = lua_gettop(l); + + lv_pushUserdata(l, self.lv_userData); + lv_pushUDataRef(l, idx); + lv_runFunction(l); + + if (lua_gettop(l) > stackIndex) { + lua_settop(l, stackIndex); + } + } +} + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAudioPlayer.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAudioPlayer.h new file mode 100644 index 00000000..dd866691 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAudioPlayer.h @@ -0,0 +1,26 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + + +@interface LVAudioPlayer : NSObject + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; + +-(id) init:(lua_State*) l; + +-(void) play; +-(void) stop; + + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAudioPlayer.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAudioPlayer.m new file mode 100644 index 00000000..f946507a --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAudioPlayer.m @@ -0,0 +1,187 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVAudioPlayer.h" +#import +#import "LView.h" +#import "LVHeads.h" + +@interface LVAudioPlayer () +@property(nonatomic,assign) BOOL playing; +@end + +@implementation LVAudioPlayer{ + AVAudioPlayer* audioPlayer; +} + +static void releaseUserDataAudioPlayer(LVUserDataInfo* user){ + if( user && user->object ){ + LVAudioPlayer* palyer = CFBridgingRelease(user->object); + user->object = NULL; + if( palyer ){ + [palyer stop]; + palyer.lv_userData = NULL; + palyer.lv_luaviewCore = nil; + } + } +} + +-(void) dealloc{ + releaseUserDataAudioPlayer(_lv_userData); +} + +-(id) init:(lua_State*) L{ + self = [super init]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(L); + } + return self; +} + +-(void) setPlayFileName0:(NSString*) fileName bundle:(LVBundle*) bundle{ + NSString* path = [bundle resourcePathWithName:fileName]; + if( path ) { + NSURL* url = [[NSURL alloc] initWithString:path]; + NSError* error = nil; + audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];//使用本地URL创建 + if( error ) { + NSLog(@"[LuaView][error]%@",error); + } + } + if( self.playing ) { + [self play]; + } +} + +-(void) setPlayFileName:(NSString*) fileName bundle:(LVBundle*) bundle{ + if( fileName ==nil ) + return; + if( [LVUtil isExternalUrl:fileName] ){ + [LVUtil download:fileName callback:^(NSData *fileData) { + NSString* suffix = [fileName componentsSeparatedByString:@"."].lastObject; + NSData* theFileNameData = [fileName dataUsingEncoding:NSUTF8StringEncoding]; + NSString* md5Path = [LVUtil MD5HashFromData:theFileNameData]; + md5Path = [NSString stringWithFormat:@"%@.%@",md5Path,suffix];//Mp3文件一定要加后缀,否则无法播放 + if( [LVUtil saveData:fileData toFile:[LVUtil PathForCachesResource:md5Path]] ) { + [self setPlayFileName0:md5Path bundle:bundle]; + } + }]; + } else { + [self setPlayFileName0:fileName bundle:bundle]; + } +} + +-(void) play { + [audioPlayer play]; + self.playing = YES; +} + +-(void) stop { + [audioPlayer stop]; + self.playing = NO; +} + +- (id) lv_nativeObject{ + return audioPlayer; +} + + +#pragma -mark AudioPlayer + +static int lvNewAudioPlayer (lua_State *L) { + if( lua_gettop(L)>=1 ) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVAudioPlayer class]]; + + LVAudioPlayer* player = [[c alloc] init:L]; + LuaViewCore* lview = LV_LUASTATE_VIEW(L); + NSString* fileName = lv_paramString(L, 1); + [player setPlayFileName:fileName bundle:lview.bundle]; + + { + NEW_USERDATA(userData, AudioPlayer); + userData->object = CFBridgingRetain(player); + player.lv_userData = userData; + + luaL_getmetatable(L, META_TABLE_AudioPlayer ); + lua_setmetatable(L, -2); + } + return 1; + } + return 0; +} + +static int play (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + + if( user && LVIsType(user, AudioPlayer) ){ + LVAudioPlayer* player = (__bridge LVAudioPlayer *)(user->object); + if( player ){ + [player play]; + lua_pushvalue(L,1); + return 1; + } + } + return 0; +} + +static int stop (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVAudioPlayer* player = (__bridge LVAudioPlayer *)(user->object); + if( player ){ + [player stop]; + } + } + return 0; +} + +static int __gc (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + releaseUserDataAudioPlayer(user); + return 0; +} + +static int __tostring (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVAudioPlayer* player = (__bridge LVAudioPlayer *)(user->object); + NSString* s = [NSString stringWithFormat:@"LVUserDataAudioPlayer: %@", player ]; + lua_pushstring(L, s.UTF8String); + return 1; + } + return 0; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewAudioPlayer globalName:globalName defaultName:@"AudioPlayer"]; + + const struct luaL_Reg memberFunctions [] = { + {"play", play }, + {"stop", stop }, + // pause + // resume + // callback { onComplete onError } + + // playing + // looping + // pausing + + {"__gc", __gc }, + {"__tostring", __tostring }, + {NULL, NULL} + }; + lv_createClassMetaTable(L, META_TABLE_AudioPlayer); + + luaL_openlib(L, NULL, memberFunctions, 0); + return 1; +} + +@end + + + diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVBaseView.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVBaseView.h new file mode 100644 index 00000000..c34e144d --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVBaseView.h @@ -0,0 +1,34 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + +@interface LVBaseView : UIView + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; +@property(nonatomic,assign) NSUInteger lv_align; + +@property(nonatomic,strong) CAShapeLayer* lv_shapeLayer; +@property(nonatomic,assign) BOOL lv_canvas; +@property(nonatomic,strong) NSString * lv_identifier; + +-(id) init:(lua_State*) l; + ++(const luaL_Reg*) baseMemberFunctions; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +@end + + +/** + * callback回调统一处理API + */ +extern int lv_setCallbackByKey(lua_State *L, const char* key, BOOL addGesture); diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVBaseView.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVBaseView.m new file mode 100644 index 00000000..fa1003e1 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVBaseView.m @@ -0,0 +1,1726 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVBaseView.h" +#import "LView.h" +#import "LVTransform3D.h" +#import "LVAnimator.h" +#import +#import "LVStruct.h" +#import "JUFLXLayoutKit.h" +#import "UIView+JUFLXNode.h" +#import "LVGesture.h" +#import "LVHeads.h" + +@interface LVBaseView () +@property(nonatomic,assign) BOOL lv_isCallbackAddClickGesture;// 支持Callback 点击事件 +@end + +@implementation LVBaseView + + +-(id) init:(lua_State*) L{ + self = [super init]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(L); + self.clipsToBounds = YES; + self.lv_isCallbackAddClickGesture = YES; + } + return self; +} + +static void releaseUserDataView(LVUserDataInfo* userdata){ + if( userdata && userdata->object ){ + UIView* view = CFBridgingRelease(userdata->object); + userdata->object = NULL; + if( view ){ + view.lv_userData = NULL; + view.lv_luaviewCore = nil; + if( !userdata->isWindow ) { + [view removeFromSuperview]; + [view.layer removeFromSuperlayer]; + } + } + } +} + +-(void) dealloc { +} + +#pragma -mark center +static int center (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + CGPoint center = view.center; + if ( lua_gettop(L)>=2 ) { + if ( lua_isuserdata(L, 2) ) { + LVUserDataInfo* user = lua_touserdata(L, 2); + if ( LVIsType(user, Struct) ) { + LVStruct* stru = (__bridge LVStruct *)(user->object); + if( [stru dataPointer] ) { + memcpy(¢er, [stru dataPointer], sizeof(CGPoint)); + } + } else { + LVError(@"LVBaseView.setCenter1"); + } + } else { + if( lua_isnumber(L, 2) ){ + center.x = lua_tonumber(L, 2);// 2 + } + if( lua_isnumber(L, 3) ){ + center.y = lua_tonumber(L, 3);// 3 + } + } + if( isnan(center.x) || isnan(center.y) ){ + LVError(@"LVBaseView.setCenter2"); + } else { + view.center = center; + } + view.lv_align = 0; + return 0; + } else { + lua_pushnumber(L, center.x ); + lua_pushnumber(L, center.y ); + return 2; + } + } + } + return 0; +} + +static int centerX(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + CGPoint center = view.center; + if ( lua_gettop(L)>=2 ) { + if( lua_isnumber(L, 2) ){ + center.x = lua_tonumber(L, 2);// 2 + } + if( isnan(center.x) || isnan(center.y) ){ + LVError(@"LVBaseView.setCenterX2"); + } else { + view.center = center; + } + return 0; + } else { + lua_pushnumber(L, center.x ); + return 1; + } + } + } + return 0; +} + +static int centerY(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + CGPoint center = view.center; + if ( lua_gettop(L)>=2 ) { + if( lua_isnumber(L, 2) ){ + center.y = lua_tonumber(L, 2);// 2 + } + if( isnan(center.x) || isnan(center.y) ){ + LVError(@"LVBaseView.setCenterX2"); + } else { + view.center = center; + } + return 0; + } else { + lua_pushnumber(L, center.y ); + return 1; + } + } + } + return 0; +} + +#pragma -mark frame +static int frame (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + CGRect r = view.frame; + if( lua_gettop(L)>=2 ) { + if ( lua_isuserdata(L, 2) ) { + LVUserDataInfo* user = lua_touserdata(L, 2); + if ( LVIsType(user, Struct) ) { + LVStruct* stru = (__bridge LVStruct *)(user->object); + if( [stru dataPointer] ) { + memcpy(&r, [stru dataPointer], sizeof(CGRect)); + } + } else { + LVError(@"LVBaseView.setFrame1"); + } + } else { + if( lua_isnumber(L, 2) ){ + r.origin.x = lua_tonumber(L, 2);// 2 + } + if( lua_isnumber(L, 3) ){ + r.origin.y = lua_tonumber(L, 3);// 3 + } + if( lua_isnumber(L, 4) ){ + r.size.width = lua_tonumber(L, 4);// 4 + } + if( lua_isnumber(L, 5) ){ + r.size.height = lua_tonumber(L, 5);// 5 + } + } + if( isnan(r.origin.x) || isnan(r.origin.y) || isnan(r.size.width) || isnan(r.size.height) ){ + LVError(@"LVBaseView.setFrame2: %s", NSStringFromCGRect(r) ); + } else { + view.frame = r; + } + view.lv_align = 0; + return 0; + } else { + lua_pushnumber(L, r.origin.x ); + lua_pushnumber(L, r.origin.y ); + lua_pushnumber(L, r.size.width ); + lua_pushnumber(L, r.size.height ); + return 4; + } + } + } + return 0; +} + +#pragma -mark frame +static int size (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + CGRect r = view.frame; + if ( lua_gettop(L)>=2 ) { + if ( lua_isuserdata(L, 2) ) { + LVUserDataInfo* user = lua_touserdata(L, 2); + if ( LVIsType(user, Struct) ) { + LVStruct* stru = (__bridge LVStruct *)(user->object); + if( [stru dataPointer] ) { + memcpy(&r.size, [stru dataPointer], sizeof(CGSize)); + } + } else { + LVError(@"LVBaseView.setSize1"); + } + } else { + if( lua_isnumber(L, 2) ){ + r.size.width = lua_tonumber(L, 2);// 4 + } + if( lua_isnumber(L, 3) ){ + r.size.height = lua_tonumber(L, 3);// 5 + } + } + if( isnan(r.origin.x) || isnan(r.origin.y) || isnan(r.size.width) || isnan(r.size.height) ){ + LVError(@"LVBaseView.setSize2: %s", NSStringFromCGRect(r) ); + } else { + view.frame = r; + } + return 0; + } else { + lua_pushnumber(L, r.size.width ); + lua_pushnumber(L, r.size.height ); + return 2; + } + } + } + return 0; +} + +static int origin (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + CGRect r = view.frame; + if ( lua_gettop(L)>=2 ) { + if ( lua_isuserdata(L, 2) ) { + LVUserDataInfo* user = lua_touserdata(L, 2); + if ( LVIsType(user, Struct) ) { + LVStruct* stru = (__bridge LVStruct *)(user->object); + if( [stru dataPointer] ) { + memcpy(&r.origin, [stru dataPointer], sizeof(CGPoint)); + } + } else { + LVError(@"LVBaseView.setOrigin1"); + } + } else { + if( lua_isnumber(L, 2) ){ + r.origin.x = lua_tonumber(L, 2);// 2 + } + if( lua_isnumber(L, 3) ){ + r.origin.y = lua_tonumber(L, 3);// 3 + } + } + if( isnan(r.origin.x) || isnan(r.origin.y) || isnan(r.size.width) || isnan(r.size.height) ){ + LVError(@"LVBaseView.setOrigin2: %s", NSStringFromCGRect(r) ); + } else { + view.frame = r; + } + view.lv_align = 0; + return 0; + } else { + lua_pushnumber(L, r.origin.x ); + lua_pushnumber(L, r.origin.y ); + return 2; + } + } + } + return 0; +} + +static int x (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + CGRect r = view.frame; + if ( lua_gettop(L)>=2 ) { + r.origin.x = lua_tonumber(L, 2);// 2 + if( isnan(r.origin.x) || isnan(r.origin.y) || isnan(r.size.width) || isnan(r.size.height) ){ + LVError(@"LVBaseView.y2: %s", NSStringFromCGRect(r) ); + } else { + view.frame = r; + } + view.lv_align = 0; + return 0; + } else { + lua_pushnumber(L, r.origin.x ); + return 1; + } + } + } + return 0; +} + +#pragma - mark flxNode +static int flxChildViews(lua_State *L) +{ + LVUserDataInfo *user = (LVUserDataInfo *)lua_touserdata(L, 1); + if (user) { + UIView *view = (__bridge UIView *)(user->object); + int childNum = lua_gettop(L); + if (view && childNum>=2 ) { + NSArray *arr = (NSArray*)lv_luaValueToNativeObject(L, 2); + if ([arr isKindOfClass:[NSArray class]] && arr.count > 0) { + NSMutableArray* childs = [[NSMutableArray alloc] init]; + for( int i=0; iobject); + if( temp ) { + [childs addObject:temp.ju_flxNode]; + } + } + view.ju_flxNode.childNodes = childs; + return 0; + } + } + return 0; +} + +static int flxBindingInlineCSS(lua_State *L) +{ + LVUserDataInfo *user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ) { + UIView *view = (__bridge UIView *)(user->object); + + int childNum = lua_gettop(L); + if (view && childNum==2) { + if (lua_type(L, 2) == LUA_TSTRING) { + [view.ju_flxNode bindingInlineCSS:[NSString stringWithUTF8String:lua_tostring(L, 2)]]; + return 0; + } + } + } + return 0; +} + +//static int flxMeasure(lua_State *L) +//{ +// LVUserDataView *user = (LVUserDataView *)lua_touserdata(L, 1); +// UIView *view = (__bridge UIView *)(user->view); +// int childNum = lua_gettop(L); +// if (view && childNum == 2) { +// if (lua_type(L, 2) == LUA_TFUNCTION) { +// lua_pushvalue(L, 1); +// lua_pushvalue(L, 2); +// lv_udataRef(L, USERDATA_FLEX_DELEGATE); +// } +// view.ju_flxNode.measure = ^CGSize(CGFloat width) { +// lv_pushUserdata(L, user ); +// lv_pushUDataRef(L, USERDATA_FLEX_DELEGATE ); +// lua_pushnumber(L, width); +// lv_runFunctionWithArgs(L, 1, 2); +// CGSize size = CGSizeZero; +// size.width = lua_tonumber(L, -2); +// size.height = lua_tonumber(L, -1); +// return size; +// }; +// +// } +// return 0; +//} + +static int flxLayout(lua_State *L) +{ + LVUserDataInfo *user = (LVUserDataInfo *)lua_touserdata(L, 1); + if (user) { + BOOL async = FALSE; + int argNum = lua_gettop(L); + for ( int i=1; i<=argNum; i++ ) { + if ( lua_type(L, i)==LUA_TBOOLEAN ){ + async = lua_toboolean(L, i); + } + if( lua_type(L, i) == LUA_TFUNCTION ) { + lua_pushvalue(L, 1); + lua_pushvalue(L, i); + lv_udataRef(L, USERDATA_FLEX_DELEGATE); + } + } + UIView *view = (__bridge UIView *)(user->object); + [view.ju_flxNode layoutAsync:async completionBlock:^(CGRect frame) { + lv_pushUserdata(L, user ); + lv_pushUDataRef(L, USERDATA_FLEX_DELEGATE ); + lv_runFunction(L); + }]; + } + return 0; +} + + +static int y (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + CGRect r = view.frame; + if ( lua_gettop(L)>=2 ) { + r.origin.y = lua_tonumber(L, 2);// 2 + if( isnan(r.origin.x) || isnan(r.origin.y) || isnan(r.size.width) || isnan(r.size.height) ){ + LVError(@"LVBaseView.y2: %s", NSStringFromCGRect(r) ); + } else { + view.frame = r; + } + view.lv_align = 0; + return 0; + } else { + lua_pushnumber(L, r.origin.y ); + return 1; + } + } + } + return 0; +} + +static int bottom (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + CGRect r = view.frame; + if ( lua_gettop(L)>=2 ) { + r.origin.y = lua_tonumber(L, 2)-r.size.height;// 2 + if( isnan(r.origin.x) || isnan(r.origin.y) || isnan(r.size.width) || isnan(r.size.height) ){ + LVError(@"LVBaseView.y2: %s", NSStringFromCGRect(r) ); + } else { + view.frame = r; + } + view.lv_align = 0; + return 0; + } else { + lua_pushnumber(L, r.origin.y + r.size.height ); + return 1; + } + } + } + return 0; +} + +static int right (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + CGRect r = view.frame; + if ( lua_gettop(L)>=2 ) { + r.origin.x = lua_tonumber(L, 2)-r.size.width;// 2 + if( isnan(r.origin.x) || isnan(r.origin.y) || isnan(r.size.width) || isnan(r.size.height) ){ + LVError(@"LVBaseView.y2: %s", NSStringFromCGRect(r) ); + } else { + view.frame = r; + } + view.lv_align = 0; + return 0; + } else { + lua_pushnumber(L, r.origin.x + r.size.width ); + return 1; + } + } + } + return 0; +} + +static int width (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + CGRect r = view.frame; + if ( lua_gettop(L)>=2 ) { + r.size.width = lua_tonumber(L, 2);// 2 + if( isnan(r.origin.x) || isnan(r.origin.y) || isnan(r.size.width) || isnan(r.size.height) ){ + LVError(@"LVBaseView.y2: %s", NSStringFromCGRect(r) ); + } else { + view.frame = r; + } + return 0; + } else { + lua_pushnumber(L, r.size.width ); + return 1; + } + } + } + return 0; +} + +static int height (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + CGRect r = view.frame; + if ( lua_gettop(L)>=2 ) { + r.size.height = lua_tonumber(L, 2);// 2 + if( isnan(r.origin.x) || isnan(r.origin.y) || isnan(r.size.width) || isnan(r.size.height) ){ + LVError(@"LVBaseView.y2: %s", NSStringFromCGRect(r) ); + } else { + view.frame = r; + } + return 0; + } else { + lua_pushnumber(L, r.size.height ); + return 1; + } + } + } + return 0; +} + +static int addGestureRecognizer (lua_State *L) { + LVUserDataInfo * userDataView = (LVUserDataInfo *)lua_touserdata(L, 1); + LVUserDataInfo * userDataGesture = (LVUserDataInfo *)lua_touserdata(L, 2); + if( userDataView && LVIsType(userDataGesture, Gesture) ){ + UIView* view = (__bridge UIView *)(userDataView->object); + UIGestureRecognizer* gesture = (__bridge UIGestureRecognizer *)(userDataGesture->object); + if( view && gesture ){ + [view addGestureRecognizer:gesture]; + lua_pushvalue(L,1); + return 1; + } + } + return 0; +} + +static int removeGestureRecognizer (lua_State *L) { + LVUserDataInfo * userDataView = (LVUserDataInfo *)lua_touserdata(L, 1); + LVUserDataInfo * userDataGesture = (LVUserDataInfo *)lua_touserdata(L, 2); + if( userDataView && LVIsType(userDataGesture, Gesture) ){ + UIView* view = (__bridge UIView *)(userDataView->object); + UIGestureRecognizer* gesture = (__bridge UIGestureRecognizer *)(userDataGesture->object); + if( view && gesture ){ + [view removeGestureRecognizer:gesture]; + lua_pushvalue(L,1); + return 1; + } + } + return 0; +} + +static int addSubview (lua_State *L) { + LVUserDataInfo * father = (LVUserDataInfo *)lua_touserdata(L, 1); + LVUserDataInfo * son = (LVUserDataInfo *)lua_touserdata(L, 2); + LuaViewCore* luaview = LV_LUASTATE_VIEW(L); + if( father && LVIsType(son, View) ){ + UIView* superview = (__bridge UIView *)(father->object); + UIView* subview = (__bridge UIView *)(son->object); + if( superview && subview ){ + lv_addSubview(luaview, superview, subview); + [subview lv_alignSelfWithSuperRect:superview.frame]; + lua_pushvalue(L,1); + return 1; + } + } + return 0; +} + + +static int getNativeView (lua_State *L) { + LVUserDataInfo * userData = (LVUserDataInfo *)lua_touserdata(L, 1); + if( userData ){ + UIView* view = (__bridge UIView *)(userData->object); + if( view ){ + id object = [view lv_getNativeView]; + lv_pushNativeObjectWithBox(L, object); + return 1; + } + } + return 0; +} + +#pragma -mark 运行环境 +static int children (lua_State *L) { + LuaViewCore* lview = LV_LUASTATE_VIEW(L); + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + + UIView* newWindow = (__bridge UIView *)(user->object); + if ( lview && newWindow && lua_type(L, 2)==LUA_TFUNCTION ) { + lua_settop(L, 2); + [lview pushWindow:newWindow]; + lv_runFunctionWithArgs(L, 1, 0); + [lview popWindow:newWindow]; + } + return 0; +} + + +static int removeFromSuperview (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + [view removeFromSuperview]; + [view.layer removeFromSuperlayer]; + lua_pushvalue(L,1); + return 1; + } + } + return 0; +} + +static int removeAllSubviews (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + NSArray* subviews = view.subviews; + for( UIView* child in subviews ) { + [child removeFromSuperview]; + } + NSArray* sublayers = view.layer.sublayers; + for(CALayer * sublayer in sublayers ) { + [sublayer removeFromSuperlayer]; + } + lua_pushvalue(L,1); + return 1; + } + } + return 0; +} + +static int layerMode(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + if ( lua_gettop(L)>=2 ) { + UIView* superview = view.superview; + BOOL yes = lua_toboolean(L, 2); + if( yes ) { + [view removeFromSuperview]; + [superview.layer addSublayer:view.layer]; + } else { + [view.layer removeFromSuperlayer]; + [superview addSubview:view]; + } + return 0; + } else { + //lua_pushboolean(L, view.hidden ); + //return 1; + } + } + } + return 0; +} + +#pragma -mark hidden +//__deprecated_msg("Use hide") +static int hidden(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + if ( lua_gettop(L)>=2 ) { + BOOL yes = lua_toboolean(L, 2); + view.hidden = yes; + return 0; + } else { + lua_pushboolean(L, view.hidden ); + return 1; + } + } + } + return 0; +} + +static int hide(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + view.hidden = YES; + return 0; + } + } + return 0; +} + +static int show(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + view.hidden = NO; + return 0; + } + } + return 0; +} + +static int isShow(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + lua_pushboolean(L, !view.hidden ); + return 1; + } + } + return 0; +} + +static int isHide(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + lua_pushboolean(L, view.hidden ); + return 1; + } + } + return 0; +} + +static int becomeFirstResponder(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + if( view.canBecomeFirstResponder ) + [view becomeFirstResponder]; + + lua_pushvalue(L,1); + return 1; + } + } + return 0; +} + +static int resignFirstResponder(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + if( view.canResignFirstResponder) + [view resignFirstResponder]; + + lua_pushvalue(L,1); + return 1; + } + } + return 0; +} + +static int isFirstResponder(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + lua_pushboolean(L, view.isFirstResponder?1:0 ); + return 1; + } + } + return 0; +} + +#pragma -mark userInteractionEnabled +static int userInteractionEnabled(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + if ( lua_gettop(L)>=2 ) { + BOOL yes = lua_toboolean(L, 2); + view.userInteractionEnabled = yes; + return 0; + } else { + lua_pushboolean(L, view.userInteractionEnabled ); + return 1; + } + } + } + return 0; +} + +#pragma -mark backgroundColor +static int backgroundColor (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( [view isKindOfClass:[UIView class]] ){ + if( lua_gettop(L)>=2 ) { + UIColor* color = lv_getColorFromStack(L, 2); + view.backgroundColor = color; + return 0; + } else { + UIColor* color = view.backgroundColor; + NSUInteger c = 0; + CGFloat a = 0; + if( lv_uicolor2int(color, &c,&a) ){ + lua_pushnumber(L, c ); + lua_pushnumber(L, a); + return 2; + } + } + } + } + return 0; +} + +#pragma -mark alpha +static int alpha (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if ( lua_gettop(L)>=2 ) { + CALayer* layer = view.layer; + + double alpha = lua_tonumber(L, 2);// 2 + layer.opacity = alpha; + + lua_pop(L, 1); + return 1; + } else { + CALayer* layer = view.layer.presentationLayer ?: view.layer; + + float alpha = layer.opacity; + lua_pushnumber(L, alpha ); + return 1; + } + } + return 0; +} + +#pragma -mark cornerRadius +static int cornerRadius (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( lua_gettop(L)>=2 ) { + double r = lua_tonumber(L, 2);// 2 + view.layer.cornerRadius = r; + return 0; + } else { + float r = view.layer.cornerRadius; + lua_pushnumber(L, r ); + return 1; + } + } + return 0; +} + +#pragma -mark borderWidth +static int borderWidth (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( lua_gettop(L)>=2 ) { + double width = lua_tonumber(L, 2);// 2 + view.layer.borderWidth = width; + return 0; + } else { + float w = view.layer.borderWidth; + lua_pushnumber(L, w ); + return 1; + } + } + return 0; +} + +#pragma -mark shadow +static int setShadowPath (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + [view layer].shadowPath =[UIBezierPath bezierPathWithRect:view.bounds].CGPath; + lua_pushvalue(L,1); + return 1; + } + return 0; +} +static int setMasksToBounds (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + BOOL masksToBounds = lua_toboolean(L, 2);// 2 + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + view.layer.masksToBounds = masksToBounds; + lua_pushvalue(L,1); + return 1; + } + return 0; +} + +static int setShadowOffset (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + float x = lua_tonumber(L, 2);// 2 + float y = lua_tonumber(L, 3);// 2 + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + [view.layer setShadowOffset:CGSizeMake(x, y)]; + lua_pushvalue(L,1); + return 1; + } + return 0; +} + +static int setShadowRadius (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + float radius = lua_tonumber(L, 2);// 2 + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + [view.layer setShadowRadius:radius]; + lua_pushvalue(L,1); + return 1; + } + return 0; +} + +static int setShadowOpacity (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + float opacity = lua_tonumber(L, 2);// 2 + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + [view.layer setShadowOpacity:opacity]; + lua_pushvalue(L,1); + return 1; + } + return 0; +} + +static int setShadowColor (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user && lua_gettop(L)>=2 ){ + UIView* view = (__bridge UIView *)(user->object); + UIColor* color = lv_getColorFromStack(L, 2); + [view.layer setShadowColor:color.CGColor]; + lua_pushvalue(L,1); + return 1; + } + return 0; +} + + +#pragma -mark borderColor + +UIColor* lv_UIColorFromRGBA(NSInteger rgbValue, float alphaValue){ + return [UIColor + colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 + green: ((float)((rgbValue & 0x00FF00) >> 8 ))/255.0 + blue: ((float)((rgbValue & 0x0000FF) ))/255.0 + alpha:alphaValue]; + +} + +static int borderColor (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if ( lua_gettop(L)>=2 ) { + UIColor* color = lv_getColorFromStack(L, 2); + view.layer.borderColor = color.CGColor; + lua_pushvalue(L,1); + return 1; + } else { + UIColor* color = [UIColor colorWithCGColor:view.layer.borderColor]; + NSUInteger c = 0; + CGFloat a = 0; + if( lv_uicolor2int(color, &c, &a) ){ + lua_pushnumber(L, c ); + lua_pushnumber(L, a); + return 2; + } + } + } + return 0; +} + +static int borderDash (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + int argN = lua_gettop(L); + if ( argN>=2 ) { + NSMutableArray* arr = [[NSMutableArray alloc] initWithCapacity:argN]; + for( int i=2; i<=argN; i++) { + if( lua_type(L, i)==LUA_TNUMBER ) { + int v = lua_tonumber(L, i); + [arr addObject:[NSNumber numberWithInt:v]]; + } + } + //虚线边框 + if( arr.count>0 ) { + [view lv_createShapelayer:arr]; + } else { + view.lv_shapeLayer.lineDashPattern = nil; + [view.lv_shapeLayer removeFromSuperlayer]; + view.lv_shapeLayer = nil; + } + return 0; + } else { + NSArray* numbers = view.lv_shapeLayer.lineDashPattern; + for( int i=0; iobject); + if( view ){ + if( lua_gettop(L)>=2 ) { + BOOL yes = lua_toboolean(L, 2); + view.clipsToBounds = yes; + return 0; + } else { + lua_pushnumber(L, view.clipsToBounds ); + return 1; + } + } + } + return 0; +} + +static int adjustSize(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + [view sizeToFit]; + } + } + return 0; +} + +#pragma -mark transformRoteAndScale + +typedef void (TransformSetter)(CATransform3D *, CGFloat); +typedef double (TransformGetter)(CATransform3D *); + +static int transformFuncOneArg(lua_State *L, TransformSetter setter, TransformGetter getter) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + UIView *view = (__bridge UIView *)(user->object); + + if( user ){ + if ( lua_gettop(L) > 1 ) { + CALayer* layer = view.layer; + + double x = lua_tonumber(L, 2); + CATransform3D t = layer.transform; + setter(&t, x); + + layer.transform = t; + + lua_pop(L, 1); + return 1; + } else { + CALayer* layer = view.layer.presentationLayer ?: view.layer; + + CATransform3D t = layer.transform; + double x = getter(&t); + + lua_pushnumber(L, x); + return 1; + } + } + return 0; +} + +static int transformFuncTwoArg(lua_State *L, + TransformSetter xsetter, TransformSetter ysetter, + TransformGetter xgetter, TransformGetter ygetter) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + UIView *view = (__bridge UIView *)(user->object); + + if( user ){ + int argNum = lua_gettop(L); + if ( argNum > 1 ) { + CALayer* layer = view.layer; + + double x = lua_tonumber(L, 2), y = lua_tonumber(L, 3); + CATransform3D t = layer.transform; + xsetter(&t, x); + ysetter(&t, y); + + layer.transform = t; + + lua_pop(L, 1); + return 1; + } else { + CALayer* layer = view.layer.presentationLayer ?: view.layer; + + CATransform3D t = layer.transform; + double x = xgetter(&t), y = ygetter(&t); + + lua_pushnumber(L, x); + lua_pushnumber(L, y); + return 2; + } + } + return 0; +} + +inline static double degreeToRadian(double d) { + return d * M_PI / 180; +} + +inline static double radianToDegree(double r) { + return r / M_PI * 180; +} + +static void transform3DSetDegreeRotation(CATransform3D *t, CGFloat v) { + double r = degreeToRadian(v); + CATransform3DSetRotation(t, r); +} + +static double transform3DGetDegreeRotation(CATransform3D *t) { + double r = CATransform3DGetRotation(t); + return radianToDegree(r); +} + +static int rotationZ (lua_State *L) { + return transformFuncOneArg(L, transform3DSetDegreeRotation, + transform3DGetDegreeRotation); +} + +static int rotationX (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( lua_gettop(L)>=2 ) { + CALayer *layer = view.layer; + + double angle = degreeToRadian(lua_tonumber(L, 2)); + layer.transform = CATransform3DMakeRotation(angle, 1, 0, 0); + + lua_pop(L, 1); + return 1; + } else { + CALayer *layer = view.layer.presentationLayer ?: view.layer; + + double angle = [[layer valueForKeyPath:@"transform.rotation.x"] doubleValue]; + lua_pushnumber(L, angle); + return 1; + } + } + return 0; +} + +static int rotationY (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( lua_gettop(L)>=2 ) { + CALayer *layer = view.layer; + + double angle = degreeToRadian(lua_tonumber(L, 2)); + layer.transform = CATransform3DMakeRotation(angle, 0, 1, 0); + + lua_pop(L, 1); + return 1; + } else { + CALayer *layer = view.layer.presentationLayer ?: view.layer; + + double angle = [[layer valueForKeyPath:@"transform.rotation.y"] doubleValue]; + lua_pushnumber(L, angle); + return 1; + } + } + return 0; +} + +static int scale (lua_State *L) { + if (lua_gettop(L) == 2) { + lua_pushnumber(L, lua_tonumber(L, 2)); + } + return transformFuncTwoArg(L, CATransform3DSetScaleX, CATransform3DSetScaleY, + CATransform3DGetScaleX, CATransform3DGetScaleY); +} + +static int scaleX (lua_State *L) { + return transformFuncOneArg(L, CATransform3DSetScaleX, CATransform3DGetScaleX); +} + +static int scaleY (lua_State *L) { + return transformFuncOneArg(L, CATransform3DSetScaleY, CATransform3DGetScaleY); +} + +static int translation (lua_State *L) { + return transformFuncTwoArg(L, CATransform3DSetTranslationX, CATransform3DSetTranslationY, + CATransform3DGetTranslationX, CATransform3DGetTranslationY); +} + +static int translationX (lua_State *L) { + return transformFuncOneArg(L, CATransform3DSetTranslationX, CATransform3DGetTranslationX); +} + +static int translationY (lua_State *L) { + return transformFuncOneArg(L, CATransform3DSetTranslationY, CATransform3DGetTranslationY); +} + +static int transform3D (lua_State *L) { + LVUserDataInfo* user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if ( lua_gettop(L)>=2 ) { + LVUserDataInfo* userdata = (LVUserDataInfo *)lua_touserdata(L, 2); + if ( LVIsType(userdata, Transform3D)) { + CALayer *layer = view.layer; + + LVTransform3D* tran = (__bridge LVTransform3D *)(userdata->object); + layer.transform = tran.transform; + + lua_pop(L, 1); + return 1; + } + } else { + CALayer *layer = view.layer.presentationLayer ?: view.layer; + + CATransform3D t = layer.transform; + [LVTransform3D pushTransform3D:L transform3d:t]; + return 1; + } + } + return 0; +} + +static int startAnimation(lua_State *L) { + LVUserDataInfo* vdata = (LVUserDataInfo *)lua_touserdata(L, 1); + if( vdata ){ + LVUserDataInfo *adata = NULL; + LVAnimator *animator = nil; + int top = lua_gettop(L); + for (int i = 2; i <= top; ++i) { + adata = lua_touserdata(L, i); + if (!LVIsType(adata, Animator)) { + continue; + } + + animator = (__bridge LVAnimator *)(adata->object); + if (animator == nil) { + continue; + } + + animator.target = (__bridge UIView *)(vdata->object); + [animator start]; + } + } + + return 0; +} + +static int stopAnimation(lua_State *L) { + LVUserDataInfo* user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + [view.layer removeAllAnimations]; + } + + return 0; +} + +#pragma -mark anchorPoint +static int anchorPoint (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( lua_gettop(L)>=2 ) { + double x = lua_tonumber(L, 2);// 2 + double y = lua_tonumber(L, 3);// 3 + view.layer.anchorPoint = CGPointMake(x, y); + return 0; + } else { + CGPoint p = view.layer.anchorPoint; + lua_pushnumber(L, p.x ); + lua_pushnumber(L, p.y ); + return 2; + } + } + return 0; +} + +int lv_setCallbackByKey(lua_State *L, const char* key, BOOL addGesture) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + if ( lua_gettop(L)>=2 ) { + UIView* view = (__bridge UIView *)(user->object); + if( addGesture ) { + [view lv_callbackAddClickGesture];// 检测是否添加手势 + } + lua_checkstack(L, 8); + lua_pushvalue(L, 1); + lv_pushUDataRef(L, USERDATA_KEY_DELEGATE); + if( lua_type(L, -1)==LUA_TNIL ) { + lua_settop(L, 2); + lua_pushvalue(L, 1); + lua_createtable(L, 0, 0); + lv_udataRef(L, USERDATA_KEY_DELEGATE ); + + lua_settop(L, 2); + lua_pushvalue(L, 1); + lv_pushUDataRef(L, USERDATA_KEY_DELEGATE); + } + lua_pushvalue(L, 2); + if( key==NULL && lua_type(L, -1) == LUA_TTABLE ) { + // 如果是表格 设置每个Key + lua_pushnil(L); + while (lua_next(L, -2)) + { + NSString* key = lv_paramString(L, -2); + lua_setfield(L, -4, key.UTF8String); + } + } else { + // 如果是方法设置默认key + lua_setfield(L, -2, (key ? key:STR_ON_CLICK) ); + } + return 0; + } else { + lv_pushUDataRef(L, USERDATA_KEY_DELEGATE); + if ( key ) { + if ( lua_type(L, -1)==LUA_TTABLE ) { + lua_getfield(L, -1, key); + } else { + lua_pushnil(L); + } + } + return 1; + } + } + return 0; +} + +static int callback (lua_State *L) { + return lv_setCallbackByKey(L, NULL, YES); +} + +static int onLayout (lua_State *L) { + return lv_setCallbackByKey(L, STR_ON_LAYOUT, NO); +} + +static int onClick (lua_State *L) { + return lv_setCallbackByKey(L, STR_ON_CLICK, YES); +} + +static void removeOnTouchEventGesture(UIView* view){ + NSArray< UIGestureRecognizer *> * gestures = view.gestureRecognizers; + for( LVGesture* g in gestures ) { + if( [g isKindOfClass:[LVGesture class]] ) { + if( g.onTouchEventCallback ) { + [view removeGestureRecognizer:g]; + break; + } + } + } +} + +static int onTouch (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + int ret = lv_setCallbackByKey(L, STR_ON_TOUCH, NO); + if( user ){ + __weak UIView* view = (__bridge UIView *)(user->object); + removeOnTouchEventGesture(view); + + LVGesture* gesture = [[LVGesture alloc] init:L]; + gesture.onTouchEventCallback = ^(LVGesture* gesture, int argN){ + [view lv_callLuaByKey1:@STR_ON_TOUCH key2:nil argN:1]; + }; + [view addGestureRecognizer:gesture]; + } + return ret; +} + +#pragma -mark __gc +static int __gc (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + releaseUserDataView(user); + return 0; +} + +static int __tostring (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + NSString* s = [NSString stringWithFormat:@"%@",view]; + lua_pushstring(L, s.UTF8String); + return 1; + } + } + return 0; +} + +- (void) layoutSubviews{ + [super layoutSubviews]; + [self lv_alignSubviews]; + [self lv_callLuaByKey1:@STR_ON_LAYOUT]; +} + +static int releaseObject(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + //[LVUtil unregistry:L key:(__bridge id)user->view]; + UIView* view = (__bridge UIView *)(user->object); + [view removeFromSuperview]; + [view.layer removeFromSuperlayer]; + if( [view isKindOfClass:[LuaViewCore class]] ){ + LuaViewCore* lView = (LuaViewCore*)view; + lView.l = NULL; + G(L)->ud = NULL; + [lView releaseLuaView]; + } + } + return 0; +} +//--------------------------- +//static int __newindex (lua_State *L) { +// NSString* key = lv_paramString(L, 2); +// if( key ){ +// lv_getmetatable( L, 1 ); +// lua_getfield(L, -1, key.UTF8String); +// if( lua_type(L, -1)==LUA_TFUNCTION ) { +// lua_CFunction function = lua_tocfunction(L,-1); +// if( function ) { +// lua_remove(L, 2); +// lua_settop(L, 2); +// return function(L); +// } +// } +// } +// LVError(@"not found property: %@", key); +// return 0; +//} + + +static int align (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + int argNum = lua_gettop(L); + if ( argNum>=2 ) { + NSUInteger align = 0; + for (int i=2; i<=argNum; i++ ) { + align |= (NSUInteger)lua_tointeger(L, i); + } + view.lv_align = align; + [view lv_alignSelfWithSuperRect:view.superview.frame]; + return 0; + } else { + lua_pushnumber(L, view.lv_align ); + return 1; + } + } + } + return 0; +} + +static int alignInfo (lua_State *L, int align) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if( view ){ + view.lv_align = align; + [view lv_alignSelfWithSuperRect:view.superview.frame]; + } + } + return 0; +} + +static int alignLeft(lua_State *L ) { + return alignInfo(L, LV_ALIGN_LEFT); +} + +static int alignRight(lua_State *L ) { + return alignInfo(L, LV_ALIGN_RIGHT); +} + +static int alignTop(lua_State *L ) { + return alignInfo(L, LV_ALIGN_TOP); +} + +static int alignBottom(lua_State *L ) { + return alignInfo(L, LV_ALIGN_BOTTOM); +} + +static int alignCenter(lua_State *L ) { + return alignInfo(L, LV_ALIGN_H_CENTER|LV_ALIGN_V_CENTER); +} + +static int effects (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if ( [view isKindOfClass:[UIView class]] ) { + int effectType = lua_tonumber(L, 2); + switch (effectType) { + case EFFECT_NONE: + break; + case EFFECT_CLICK:{ + NSInteger color = lua_tonumber(L, 3); + CGFloat alpha = lua_tonumber(L, 4); + [view lv_effectClick:color alpha:alpha]; + break; + } + case EFFECT_PARALLAX:{ + CGFloat dx = lua_tonumber(L, 3); + CGFloat dy = lua_tonumber(L, 4); + [view lv_effectParallax:dx dy:dy]; + break; + } + default: + break; + } + } + } + return 0; +} + +static int invalidate (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIView* view = (__bridge UIView *)(user->object); + if ( [view isKindOfClass:[UIView class]] ) { + [view setNeedsDisplay]; + } + } + return 0; +} + +static const struct luaL_Reg baseMemberFunctions [] = { + {"hidden", hidden }, + // visible + + {"hide", hide },//__deprecated_msg("Use hidden") + {"isHide", isHide },//__deprecated_msg("Use hidden") + + {"show", show },//__deprecated_msg("Use visible") + {"isShow", isShow },//__deprecated_msg("Use visible") + + {"enabled", userInteractionEnabled }, + {"clipsToBounds", clipsToBounds },// for IOS + + {"backgroundColor", backgroundColor }, + + {"alpha", alpha }, + + {"cornerRadius", cornerRadius }, + + {"borderWidth", borderWidth }, + + {"borderColor", borderColor }, + {"borderDash", borderDash }, + + {"shadowPath", setShadowPath }, // for IOS + {"masksToBounds", setMasksToBounds },// for IOS + {"shadowOffset", setShadowOffset },// for IOS + {"shadowRadius", setShadowRadius },// for IOS + {"shadowOpacity", setShadowOpacity },// for IOS + {"shadowColor", setShadowColor },// for IOS + + {"frame", frame }, + + {"size", size }, + + {"origin", origin },//__deprecated_msg("Use xy") + {"xy", origin }, + + {"center", center}, + {"centerX", centerX}, + {"centerY", centerY}, + + {"x", x}, + {"y", y}, + + {"left", x}, + {"top", y}, + {"bottom", bottom}, + {"right", right}, + + {"width", width}, + {"height", height}, + + {"adjustSize", adjustSize},// 带讨论 + + {"addGesture", addGestureRecognizer }, //__deprecated_msg("Use onTouch") + {"removeGesture", removeGestureRecognizer }, //__deprecated_msg("Use onTouch") + + {"addView", addSubview }, + {"children", children }, + {"removeFromSuper", removeFromSuperview }, + {"removeFromParent", removeFromSuperview }, //__deprecated_msg("Use removeFromSuper") + {"removeAllViews", removeAllSubviews }, + //{"bringToFront", bringToFront}, + + {"rotation", rotationZ }, + {"rotationX", rotationX }, + {"rotationY", rotationY }, + {"rotationZ", rotationZ },//__deprecated_msg("Use rotation") + + {"scale", scale }, + {"scaleX", scaleX }, + {"scaleY", scaleY }, + + {"translation", translation }, + {"translationX", translationX }, + {"translationY", translationY }, + + {"anchorPoint", anchorPoint }, + + {"callback", callback }, + {"onLayout", onLayout }, + {"onClick", onClick }, + {"onTouch", onTouch }, + // onShow + // onHide + // onLongClick + + {"hasFocus", isFirstResponder }, + {"requestFocus", becomeFirstResponder }, + {"cancelFocus", resignFirstResponder }, //__deprecated_msg("Use hidden") + {"clearFocus", resignFirstResponder }, + + {"transform3D", transform3D }, //__deprecated_msg("Use") + + {"startAnimation", startAnimation }, + {"stopAnimation", stopAnimation }, + + + {"__gc", __gc }, + + {"__tostring", __tostring}, + + // {"__newindex", __newindex }, + + {"flexChildren", flxChildViews }, + {"flxLayout", flxLayout },// 安卓无 + {"flexCss", flxBindingInlineCSS}, + + // align + {"align", align}, + {"alignLeft", alignLeft}, + {"alignRight", alignRight}, + {"alignTop", alignTop}, + {"alignBottom", alignBottom}, + {"alignCenter", alignCenter}, + // padding + // margin + + // getNativeView + {"getNativeView", getNativeView}, //__deprecated_msg("Use nativeView") + {"nativeView", getNativeView}, + + {"effects",effects}, // IOS 视差效果 + {"layerMode",layerMode}, // for IOS + + {"invalidate",invalidate}, + {NULL, NULL} +}; + +static const struct luaL_Reg luaViewMemberFunctions [] = { + {"release", releaseObject}, + {NULL, NULL }, +}; + ++(const luaL_Reg*) baseMemberFunctions{ + return baseMemberFunctions; +} + +#pragma -mark UIView +static int lvNewView (lua_State *L) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVBaseView class]]; + + LVBaseView* view = [[c alloc] init:L]; + { + NEW_USERDATA(userData, View); + userData->object = CFBridgingRetain(view); + view.lv_userData = userData; + + luaL_getmetatable(L, META_TABLE_UIView ); + lua_setmetatable(L, -2); + + LuaViewCore* luaviewCore = LV_LUASTATE_VIEW(L); + if( luaviewCore ){ + [luaviewCore containerAddSubview:view]; + } + } + return 1; /* new userdatum is already on the stack */ +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewView globalName:globalName defaultName:@"View"]; + + lv_createClassMetaTable(L, META_TABLE_UIView); + + luaL_openlib(L, NULL, [LVBaseView baseMemberFunctions], 0); + + + lv_createClassMetaTable(L, META_TABLE_LuaView); + luaL_openlib(L, NULL, [LVBaseView baseMemberFunctions], 0); + luaL_openlib(L, NULL, luaViewMemberFunctions, 0); + return 1; +} + +//---------------------------------------------------------------------------------------- + +-(NSString*) description{ + return [NSString stringWithFormat:@"", (int)[self hash], NSStringFromCGRect(self.frame) ]; +} + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVButton.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVButton.h new file mode 100644 index 00000000..c26d5a99 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVButton.h @@ -0,0 +1,28 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" +#import "LView.h" + + +@interface LVButton : UIButton + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; +@property(nonatomic,assign) NSUInteger lv_align; +@property(nonatomic,strong) CAShapeLayer* lv_shapeLayer; + +-(id) init:(lua_State*) l; +-(void) setWebImageUrl:(NSString*)url forState:(UIControlState) state finished:(LVLoadFinished) finished; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +-(void) lvButtonCallBack; + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVButton.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVButton.m new file mode 100644 index 00000000..ada32ee8 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVButton.m @@ -0,0 +1,313 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVButton.h" +#import "LVBaseView.h" +#import "LVImage.h" +#import "LVUtil.h" +#import "LView.h" +#import "LVStyledString.h" +#import "UIView+LuaView.h" +#import "NSObject+LuaView.h" +#import "LVHeads.h" + +@interface LVButton() +@end + +@implementation LVButton + +-(id) init:(lua_State*) l{ + self = [super init]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + [self addTarget:self action:@selector(lvButtonCallBack) forControlEvents:UIControlEventTouchUpInside]; + + // 默认黑色字 + [self setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; + self.clipsToBounds = YES; + self.titleLabel.font = [UIFont systemFontOfSize:14];// 默认字体大小 + } + return self; +} + +-(void) dealloc{ +} + +-(NSString*) description{ + return [NSString stringWithFormat:@"", (int)[self hash], NSStringFromCGRect(self.frame) ]; +} + +-(void) lvButtonCallBack{ + [self lv_buttonCallBack]; +} + +-(void) setWebImageUrl:(NSString*)url forState:(UIControlState) state finished:(LVLoadFinished) finished{ +} + +-(void) setImageUrl:(NSString*) url placeholder:(UIImage *)placeholder state:(UIControlState) state { + if( [LVUtil isExternalUrl:url] ){ + [self setWebImageUrl:url forState:state finished:nil]; + } else { + if( url ) { + LVBundle* bundle = self.lv_luaviewCore.bundle; + [self setImage:[bundle imageWithName:url] forState:state]; + } + } +} + +#pragma -mark Button +static int lvNewButton (lua_State *L) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVButton class]]; + + { + LVButton* button = [[c alloc] init:L]; + { + NEW_USERDATA(userData, View); + userData->object = CFBridgingRetain(button); + button.lv_userData = userData; + + luaL_getmetatable(L, META_TABLE_UIButton ); + lua_setmetatable(L, -2); + } + LuaViewCore* father = LV_LUASTATE_VIEW(L); + if( father ){ + [father containerAddSubview:button]; + } + } + return 1; /* new userdatum is already on the stack */ +} + +static int selected (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVButton* button = (__bridge LVButton *)(user->object); + if( button ){ + if ( lua_gettop(L)>=2 ) { + BOOL yes = lua_toboolean(L, 2); + button.selected = yes; + return 0; + } else { + lua_pushboolean(L, button.selected ); + return 1; + } + } + } + return 0; +} + +static int enabled (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVButton* button = (__bridge LVButton *)(user->object); + if ( lua_gettop(L)>=2 ){ + BOOL yes = lua_toboolean(L, 2); + button.enabled = yes; + return 0; + } else { + lua_pushboolean(L, button.enabled); + return 1; + } + } + return 0; +} + +static int image (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + NSString* normalImage = lv_paramString(L, 2);// 2 + NSString* hightLightImage = lv_paramString(L, 3);// 2 + //NSString* disableImage = lv_paramString(L, 4);// 2 + //NSString* selectedImage = lv_paramString(L, 5);// 2 + LVButton* button = (__bridge LVButton *)(user->object); + if( [button isKindOfClass:[LVButton class]] ){ + [button setImageUrl:normalImage placeholder:nil state:UIControlStateNormal]; + [button setImageUrl:hightLightImage placeholder:nil state:UIControlStateHighlighted]; + //[button setImageUrl:disableImage placeholder:nil state:UIControlStateDisabled]; + //[button setImageUrl:selectedImage placeholder:nil state:UIControlStateSelected]; + + lua_pushvalue(L, 1); + return 1; + } + } + return 0; +} + +static const UIControlState g_states[] = {UIControlStateNormal,UIControlStateHighlighted,UIControlStateDisabled,UIControlStateSelected}; +static int title (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVButton* button = (__bridge LVButton *)(user->object); + if( [button isKindOfClass:[LVButton class]] ){ + int num = lua_gettop(L); + if ( num>=2 ) {// setValue + for (int i=2,j=0; i<=num && j<4; i++ ){ + if ( lua_type(L, i) == LUA_TSTRING ) { + NSString* text1 = lv_paramString(L, i); + if( text1 ) { + [button setTitle:text1 forState:g_states[j++]]; + } + } else if( lua_type(L, 2)==LUA_TUSERDATA ){ + LVUserDataInfo * user2 = lua_touserdata(L, 2); + if( user2 && LVIsType(user2, StyledString) ) { + LVStyledString* attString = (__bridge LVStyledString *)(user2->object); + [button setAttributedTitle:attString.mutableStyledString forState:g_states[j++] ]; + [button.titleLabel sizeToFit]; + } + }else if ( lua_type(L, i) == LUA_TNUMBER ) { + float f = lua_tonumber(L, i); + [button setTitle:[NSString stringWithFormat:@"%f",f] forState:g_states[j++]]; + } + } + return 0; + } else { // getValue + for (int j=0; j<4; j++ ){ + NSString* text1 = [button titleForState:g_states[j++] ]; + lua_pushstring(L, text1.UTF8String); + } + return 4; + } + } + } + return 0; +} + +static int titleColor (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVButton* button = (__bridge LVButton *)(user->object); + if( [button isKindOfClass:[LVButton class]] ){ + int num = lua_gettop(L); + if ( num>=2 ) { + for (int i=2,j=0; i<=num && j<4; i++ ){ + if( lua_type(L, i)==LUA_TNUMBER ) { + UIColor* c = lv_getColorFromStack(L, i); + [button setTitleColor:c forState:g_states[j++]]; + } + } + return 0; + } else { + int retvalueNum = 0; + for (int j=0; j<4; j++ ){ + UIColor* c = [button titleColorForState:g_states[j++] ]; + NSUInteger color=0 ; + CGFloat a = 0; + if( lv_uicolor2int(c, &color, &a) ){ + lua_pushnumber(L, color); + lua_pushnumber(L, a); + retvalueNum += 2; + } + } + return retvalueNum; + } + } + } + return 0; +} + +static int font (lua_State *L) { + LuaViewCore* luaView = LV_LUASTATE_VIEW(L); + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVButton* view = (__bridge LVButton *)(user->object); + if( [view isKindOfClass:[LVButton class]] ){ + int num = lua_gettop(L); + if( num>=2 ) { + if( num>=3 && lua_type(L, 2)==LUA_TSTRING ) { + NSString* fontName = lv_paramString(L, 2); + float fontSize = lua_tonumber(L, 3); + view.titleLabel.font = [LVUtil fontWithName:fontName size:fontSize bundle:luaView.bundle]; + } else { + float fontSize = lua_tonumber(L, 2); + view.titleLabel.font = [UIFont systemFontOfSize:fontSize]; + } + return 0; + } else { + UIFont* font = view.titleLabel.font; + lua_pushstring(L, font.fontName.UTF8String); + lua_pushnumber(L, font.pointSize); + return 2; + } + } + } + return 0; +} + +static int fontSize (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVButton* view = (__bridge LVButton *)(user->object); + if( [view isKindOfClass:[LVButton class]] ){ + int num = lua_gettop(L); + if( num>=2 ) { + float fontSize = lua_tonumber(L, 2); + view.titleLabel.font = [UIFont systemFontOfSize:fontSize]; + return 0; + } else { + UIFont* font = view.titleLabel.font; + lua_pushnumber(L, font.pointSize); + return 1; + } + } + } + return 0; +} + +//static int showsTouchWhenHighlighted(lua_State *L) { +// LVUserDataView * user = (LVUserDataView *)lua_touserdata(L, 1); +// if( user ){ +// LVButton* button = (__bridge LVButton *)(user->view); +// if( lua_gettop(L)<=1 ) { +// lua_pushboolean(L, button.showsTouchWhenHighlighted ); +// return 1; +// } else { +// BOOL yes = lua_toboolean(L, 2); +// button.showsTouchWhenHighlighted = yes; +// return 0; +// } +// } +// return 0; +//} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewButton globalName:globalName defaultName:@"Button"]; + + const struct luaL_Reg memberFunctions [] = { + {"image", image}, + + {"font", font}, + {"fontSize", fontSize}, + {"textSize", fontSize}, // __deprecated_msg("Use lines") + + + {"titleColor", titleColor}, // __deprecated_msg("Use lines") + {"title", title}, // __deprecated_msg("Use lines") + {"textColor", titleColor}, + {"text", title}, + + {"selected", selected}, // __deprecated_msg("Use lines") + {"enabled", enabled}, // __deprecated_msg("Use lines") + + //{"showsTouchWhenHighlighted", showsTouchWhenHighlighted}, + {NULL, NULL} + }; + + lv_createClassMetaTable(L,META_TABLE_UIButton); + + luaL_openlib(L, NULL, [LVBaseView baseMemberFunctions], 0); + luaL_openlib(L, NULL, memberFunctions, 0); + + const char* keys[] = { "addView", NULL};// 移除多余API + lv_luaTableRemoveKeys(L, keys ); + + return 1; +} + + +//---------------------------------------------------------------------------------------- + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCanvas.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCanvas.h new file mode 100644 index 00000000..7a324e3d --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCanvas.h @@ -0,0 +1,28 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import +#import "LVHeads.h" + +@interface LVCanvas : NSObject + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; + +@property(nonatomic,assign) CGContextRef contentRef; + +@property(nonatomic,assign) CGPathDrawingMode drawingMode; + +-(id) init:(lua_State*) l; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + ++(LVCanvas*) createLuaCanvas:(lua_State *)L contentRef:(CGContextRef) contentRef; + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCanvas.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCanvas.m new file mode 100644 index 00000000..c2140faf --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCanvas.m @@ -0,0 +1,733 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVCanvas.h" +#import "LView.h" +#import "LVBundle.h" +#import "LVData.h" +#import "LVImage.h" + +#define LV_ANGLE_RADIANS(angle) (M_PI*angle/180) + +@interface LVCanvas () +@property(nonatomic,strong) UIColor* color; +@property(nonatomic,assign) CGFloat strokeWidth; +@property(nonatomic,assign) CGFloat alpha; +@property(nonatomic,assign) UIFont* font; +@property(nonatomic,assign) CGAffineTransform concatCTM; +@property(nonatomic,assign) CGFloat scaleX; +@property(nonatomic,assign) CGFloat scaleY; +@property(nonatomic,assign) CGFloat skewX; +@property(nonatomic,assign) CGFloat skewY; +@property(nonatomic,assign) CGPoint translate; +@end + +@implementation LVCanvas + + +-(id) init:(lua_State *)l{ + self = [super init]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + } + return self; +} + +-(void) setContentRef:(CGContextRef)contentRef{ + _contentRef = contentRef; + [self resetPaint]; +} + +-(id) lv_nativeObject{ + return self; +} + +-(void) setColor:(UIColor *)color{ + _color = color; + if( _contentRef ) { + CGContextSetStrokeColorWithColor(_contentRef,self.color.CGColor); + CGContextSetFillColorWithColor(_contentRef,self.color.CGColor); + } +} + +-(void) setAlpha:(CGFloat)alpha{ + _alpha = alpha; + if (_contentRef) { +// CGFloat r = 0; +// CGFloat g = 0; +// CGFloat b = 0; +// CGFloat a = 0; +// if( [_color getRed:&r green:&g blue:&b alpha:&a] ){ +// CGContextSetRGBStrokeColor(_contentRef, r, g, b, _alpha); +// CGContextSetRGBFillColor(_contentRef, r, g, b, _alpha); +// } + // 控制左右的绘图alpha + CGContextSetAlpha(_contentRef,alpha); + } +} + +static int nativeObj (lua_State *L) { + LVUserDataInfo * userData = (LVUserDataInfo *)lua_touserdata(L, 1); + if( userData ){ + LVCanvas* view = (__bridge LVCanvas *)(userData->object); + if( view ){ + id object = [view lv_nativeObject]; + lv_pushNativeObjectWithBox(L, object); + return 1; + } + } + return 0; +} + +static int canvas_drawPoint (lua_State *L) { + LVUserDataInfo * user1 = (LVUserDataInfo *)lua_touserdata(L, 1); + LVCanvas* canvas = (__bridge LVCanvas *)(user1->object); + if( LVIsType(user1, Canvas) ){ + CGFloat x1 = lua_tonumber(L, 2); + CGFloat y1 = lua_tonumber(L, 3); + [canvas drawLine:x1-0.5 :y1-0.5 :x1+0.5 :y1+0.5]; + return 1; + } + return 0; +} + +-(void) drawLine:(CGFloat) x1 :(CGFloat)y1 :(CGFloat) x2 :(CGFloat) y2{ + if( _contentRef ) { + CGPoint aPoints[2]; + aPoints[0] = CGPointMake(x1, y1); + aPoints[1] = CGPointMake(x2, y2); + CGContextAddLines(_contentRef, aPoints, 2); + CGContextDrawPath(_contentRef, kCGPathStroke); //根据坐标绘制路径 + } +} + +static int canvas_drawLine (lua_State *L) { + LVUserDataInfo * user1 = (LVUserDataInfo *)lua_touserdata(L, 1); + LVCanvas* canvas = (__bridge LVCanvas *)(user1->object); + if( LVIsType(user1, Canvas) ){ + CGFloat x1 = lua_tonumber(L, 2); + CGFloat y1 = lua_tonumber(L, 3); + CGFloat x2 = lua_tonumber(L, 4); + CGFloat y2 = lua_tonumber(L, 5); + [canvas drawLine:x1 :y1 :x2 :y2]; + return 1; + } + return 0; +} + +-(void) drawRect:(CGFloat)x :(CGFloat)y :(CGFloat)w :(CGFloat)h{ + if( _contentRef ) { + CGContextAddRect(_contentRef, CGRectMake(x, y, w, h)); + CGContextDrawPath(_contentRef, self.drawingMode); + } +} + +static int canvas_drawRect (lua_State *L) { + LVUserDataInfo * user1 = (LVUserDataInfo *)lua_touserdata(L, 1); + LVCanvas* canvas = (__bridge LVCanvas *)(user1->object); + if( LVIsType(user1, Canvas) ){ + CGFloat x1 = lua_tonumber(L, 2); + CGFloat y1 = lua_tonumber(L, 3); + CGFloat x2 = lua_tonumber(L, 4); + CGFloat y2 = lua_tonumber(L, 5); + [canvas drawRect:x1 :y1 :x2 :y2]; + return 1; + } + return 0; +} + +-(void) drawRoundRect:(CGFloat) x :(CGFloat)y :(CGFloat)w :(CGFloat)h :(CGFloat)rx :(CGFloat)ry{ + CGContextRef context = _contentRef; + if( context ) { + // 简便起见,这里把圆角半径设置为长和宽平均值的1/10 + CGFloat radius = rx; + + // 获取CGContext,注意UIKit里用的是一个专门的函数 + CGContextRef context = UIGraphicsGetCurrentContext(); + // 移动到初始点 + CGContextMoveToPoint(context,x+ radius,y+ 0); + + // 绘制第1条线和第1个1/4圆弧 + CGContextAddLineToPoint(context, x+ w - radius, y+0); + CGContextAddArc(context, x+w - radius, y+ radius, radius, -0.5 * M_PI, 0.0, 0); + + // 绘制第2条线和第2个1/4圆弧 + CGContextAddLineToPoint(context, x+ w, y+ h - radius); + CGContextAddArc(context, x+ w - radius, y+ h - radius, radius, 0.0, 0.5 * M_PI, 0); + + // 绘制第3条线和第3个1/4圆弧 + CGContextAddLineToPoint(context, x+radius, y+ h); + CGContextAddArc(context, x+ radius, y+ h-radius, radius, 0.5 * M_PI, M_PI, 0); + + // 绘制第4条线和第4个1/4圆弧 + CGContextAddLineToPoint(context, x+ 0, y+ radius); + CGContextAddArc(context, x+ radius, y+ radius, radius, M_PI, 1.5 * M_PI, 0); + + // 闭合路径 + CGContextClosePath(context); + CGContextDrawPath(context, self.drawingMode); + } +} + +static int canvas_drawRoundRect (lua_State *L) { + LVUserDataInfo * user1 = (LVUserDataInfo *)lua_touserdata(L, 1); + LVCanvas* canvas = (__bridge LVCanvas *)(user1->object); + if( LVIsType(user1, Canvas) ){ + CGFloat x = lua_tonumber(L, 2); + CGFloat y = lua_tonumber(L, 3); + CGFloat w = lua_tonumber(L, 4); + CGFloat h = lua_tonumber(L, 5); + CGFloat rx = lua_tonumber(L, 6); + CGFloat ry = lua_tonumber(L, 7); + [canvas drawRoundRect:x :y :w :h :rx :ry]; + return 1; + } + return 0; +} + +-(void) drawEllipse:(CGFloat) x :(CGFloat)y :(CGFloat)w :(CGFloat)h { + CGContextRef context = _contentRef; + if( context && w>=0 && h>= 0 ) { + //画椭圆 + CGContextAddEllipseInRect(context, CGRectMake(x, y, w, h)); //椭圆 + CGContextDrawPath(context, self.drawingMode); + } +} + +-(void) drawText:(NSString *)text :(UIFont *)font :(CGRect)rect{ + CGContextRef context = _contentRef; + if (context && text) { + //写文字 + NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:font,NSFontAttributeName,self.color,NSForegroundColorAttributeName,nil]; + [text drawInRect:rect withAttributes:attributes]; + } +} + +-(void) drawText:(NSString *)text :(UIFont *)font :(CGFloat)x :(CGFloat) y{ + CGContextRef context = _contentRef; + if (context && text) { + //画文字 + NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:font,NSFontAttributeName,self.color,NSForegroundColorAttributeName,nil]; + [text drawAtPoint:CGPointMake(x, y) withAttributes:attributes]; + } +} + +static int canvas_drawEllipse (lua_State *L) { + LVUserDataInfo * user1 = (LVUserDataInfo *)lua_touserdata(L, 1); + LVCanvas* canvas = (__bridge LVCanvas *)(user1->object); + if( LVIsType(user1, Canvas) ){ + CGFloat x = lua_tonumber(L, 2); + CGFloat y = lua_tonumber(L, 3); + CGFloat w = lua_tonumber(L, 4); + CGFloat h = w; + if( lua_type(L, 5)==LUA_TNUMBER ) { + h = lua_tonumber(L, 5); + } + [canvas drawEllipse:x :y :w :h]; + return 1; + } + return 0; +} + +static int canvas_drawCircle (lua_State *L) { + LVUserDataInfo * user1 = (LVUserDataInfo *)lua_touserdata(L, 1); + LVCanvas* canvas = (__bridge LVCanvas *)(user1->object); + if( LVIsType(user1, Canvas) ){ + CGFloat x = lua_tonumber(L, 2); + CGFloat y = lua_tonumber(L, 3); + CGFloat r = lua_tonumber(L, 4); + [canvas drawEllipse:x-r :y-r :r*2 :r*2]; + return 1; + } + return 0; +} + +static int canvas_color (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVCanvas* canvas = (__bridge LVCanvas *)(user->object); + if( lua_gettop(L)>=2 ) { + UIColor* color = lv_getColorFromStack(L, 2); + canvas.color = color; + return 0; + } else { + UIColor* color = canvas.color; + NSUInteger c = 0; + CGFloat a = 0; + if( lv_uicolor2int(color, &c,&a) ){ + lua_pushnumber(L, c ); + lua_pushnumber(L, a); + return 2; + } + } + } + return 0; +} + +-(void) setStrokeWidth:(CGFloat)strokeWidth{ + _strokeWidth = strokeWidth; + if( _contentRef ) { + CGContextSetLineWidth(_contentRef, strokeWidth); + } +} + +static int canvas_strokeWidth (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVCanvas* canvas = (__bridge LVCanvas *)(user->object); + if( lua_gettop(L)>=2 ) { + canvas.strokeWidth = lua_tonumber(L, 2); + return 0; + } else { + lua_pushnumber(L, canvas.strokeWidth ); + return 1; + } + } + return 0; +} + +static int canvas_style (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVCanvas* canvas = (__bridge LVCanvas *)(user->object); + if( lua_gettop(L)>=2 ) { + canvas.drawingMode = lua_tonumber(L, 2); + return 0; + } else { + lua_pushnumber(L, canvas.drawingMode ); + return 1; + } + } + return 0; +} + +-(void) resetPaint{ + [self clipRect:0 :0 :10240 :10240]; + self.color = [UIColor blackColor]; + self.strokeWidth = 0.5; + self.alpha = 1; + self.drawingMode = kCGPathFill; + self.font = [UIFont systemFontOfSize:12]; + [self scale:1 :1]; + [self rotate:0 :0 :0]; + [self translate:0 :0]; + [self skew:0 :0]; +} + +static int canvas_resetPaint (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVCanvas* canvas = (__bridge LVCanvas *)(user->object); + [canvas resetPaint]; + } + return 0; +} + +static int canvas_alpha (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVCanvas* canvas = (__bridge LVCanvas *)(user->object); + if( lua_gettop(L)>=2 ) { + CGFloat alpha = lua_tonumber(L, 2); + canvas.alpha = alpha; + return 0; + } + } + return 0; +} + +static int canvas_textSize (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVCanvas* canvas = (__bridge LVCanvas *)(user->object); + if( lua_gettop(L)>=2 ) { + CGFloat font = lua_tonumber(L, 2); + canvas.font = [UIFont systemFontOfSize:font]; + return 0; + } else { + return 0; + } + } + return 0; +} + +static int canvas_bold (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVCanvas* canvas = (__bridge LVCanvas *)(user->object); + if( lua_gettop(L)>=2 ) { + CGFloat bold = lua_toboolean(L, 2); + if (bold) { + canvas.font = [UIFont boldSystemFontOfSize:canvas.font.pointSize]; + }else{ + canvas.font = [UIFont systemFontOfSize:canvas.font.pointSize]; + } + return 0; + } else { + return 0; + } + } + return 0; +} + +-(void) clipRect:(CGFloat)x :(CGFloat)y :(CGFloat)w :(CGFloat)h{ + if( _contentRef ) { + CGContextClipToRect(_contentRef,CGRectMake(x, y, w, h)); + } +} + +static int canvas_clipRect (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user && lua_gettop(L)>=5 ){ + LVCanvas* canvas = (__bridge LVCanvas *)(user->object); + CGFloat x = lua_tonumber(L, 2); + CGFloat y = lua_tonumber(L, 3); + CGFloat w = lua_tonumber(L, 4); + CGFloat h = lua_tonumber(L, 5); + [canvas clipRect:x :y :w :h]; + } + return 0; +} + +static int drawText (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVCanvas* canvas = (__bridge LVCanvas *)(user->object); + if( lua_gettop(L)>=2 ) { + const char* text = lua_tolstring(L, 2, NULL); + NSString *str = [NSString stringWithCString:text encoding:NSUTF8StringEncoding]; + CGFloat x = lua_tonumber(L, 3); + CGFloat y = lua_tonumber(L, 4); + CGFloat h = canvas.font.lineHeight; + CGFloat leading = canvas.font.leading ; + CGFloat descender = canvas.font.descender; + CGRect rect = CGRectMake(x, y - (h+leading+descender), h * str.length, h ); + [canvas drawText:str :canvas.font :rect]; + return 0; + } else { + return 0; + } + } + return 0; +} + +static int canvas_drawOval (lua_State *L) { + return canvas_drawEllipse(L); +} + +-(void) drawArc:(CGFloat)x :(CGFloat)y :(CGFloat)w :(CGFloat)h :(CGFloat)startAngle :(CGFloat)endAngle :(BOOL) includeCenter{ + if( _contentRef ) { + x += w/2; + y += h/2; + if( includeCenter ) { + CGContextMoveToPoint(_contentRef, x, y); + } + CGContextAddArc(_contentRef, x, y, w/2, LV_ANGLE_RADIANS(startAngle), LV_ANGLE_RADIANS(endAngle), NO); + CGContextClosePath(_contentRef); + CGContextDrawPath(_contentRef, self.drawingMode); + } +} + +static int canvas_drawArc (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + CGFloat x = lua_tonumber(L, 2); + CGFloat y = lua_tonumber(L, 3); + CGFloat w = lua_tonumber(L, 4); + CGFloat h = lua_tonumber(L, 5); + CGFloat startAngle = lua_tonumber(L, 6); + CGFloat endAngle = lua_tonumber(L, 7); + BOOL includeCenter = lua_toboolean(L, 8); + LVCanvas* canvas = (__bridge LVCanvas *)(user->object); + [canvas drawArc:x :y :w :h :startAngle :endAngle :includeCenter]; + } + return 0; +} + +-(void) drawImage:(UIImage*)image :(CGFloat)x :(CGFloat)y :(CGFloat)w :(CGFloat)h { + if( _contentRef && image) { + CGContextSaveGState(_contentRef); + //CGAffineTransform t1 = CGAffineTransformMake(1, self.skewY, self.skewX, 1, 0, 0); + CGAffineTransform t2 = CGAffineTransformMake(1, 0, 0, -1, 0, 0); + //CGAffineTransform t3 = CGAffineTransformConcat(t1, t2); + CGContextConcatCTM(_contentRef, t2 ); + CGContextDrawImage(_contentRef, CGRectMake(x, -y-h , w, h), image.CGImage); + CGContextRestoreGState(_contentRef); + } +} + +static int canvas_drawImage (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVCanvas* canvas = (__bridge LVCanvas *)(user->object); + UIImage* image = nil; + if ( lua_type(L, 2)==LUA_TSTRING ) { + NSString* imageName = lv_paramString(L, 2);// 2 + image = [canvas.lv_luaviewCore.bundle imageWithName:imageName]; + } else if ( lua_type(L, 2)==LUA_TUSERDATA ) { + LVUserDataInfo * userdata = (LVUserDataInfo *)lua_touserdata(L, 2); + if( LVIsType(userdata, View) ){ + LVImage* lvImage = (__bridge LVImage *)(userdata->object); + if( [lvImage isKindOfClass:[LVImage class]] ) { + image = lvImage.image; + } + } else if( LVIsType(userdata, Data) ) { + LVData* lvdata = (__bridge LVData *)(userdata->object); + image = [[UIImage alloc] initWithData:lvdata.data]; + } + } + if( image ) { + CGFloat x = lua_tonumber(L, 3); + CGFloat y = lua_tonumber(L, 4); + CGFloat w = lua_tonumber(L, 5); + CGFloat h = lua_tonumber(L, 6); + [canvas drawImage:image :x :y :w :h]; + } + } + return 0; +} + +-(void) saveGState { + if( _contentRef ) { + CGContextSaveGState(_contentRef); + } +} + +static int canvas_save (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVCanvas* canvas = (__bridge LVCanvas *)(user->object); + [canvas saveGState]; + } + return 0; +} + +-(void) restoreGState { + if( _contentRef ) { + CGContextRestoreGState(_contentRef); + } +} + +static int canvas_restore (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVCanvas* canvas = (__bridge LVCanvas *)(user->object); + [canvas restoreGState]; + } + return 0; +} + +-(void) rotate:(CGFloat) angle :(CGFloat)x :(CGFloat) y{ + if( _contentRef ) { + CGContextTranslateCTM(_contentRef, x, y); + CGContextRotateCTM(_contentRef,LV_ANGLE_RADIANS(angle) ); + CGContextTranslateCTM(_contentRef, -x, -y); + } +} + +static int canvas_rotate (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVCanvas* canvas = (__bridge LVCanvas *)(user->object); + CGFloat angle = lua_tonumber(L, 2); + CGFloat x = 0; + if( lua_type(L, 3) ) { + x = lua_tonumber(L, 3); + } + CGFloat y = 0; + if( lua_type(L, 4) ) { + y = lua_tonumber(L, 4); + } + [canvas rotate:angle :x :y];; + } + return 0; +} + +-(void) skew:(CGFloat)sx :(CGFloat)sy { + if( _contentRef ) { + self.skewX = sx; + self.skewY = sy; + CGAffineTransform transform = CGAffineTransformMake(1, sy, sx, 1, 0, 0); + CGContextConcatCTM(_contentRef,transform); + } +} + +-(void) setConcatCTM:(CGAffineTransform) transform{ + CGContextConcatCTM(_contentRef,transform); +} + +-(CGAffineTransform) concatCTM{ + return CGContextGetCTM(_contentRef); +} + +static int canvas_skew (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVCanvas* canvas = (__bridge LVCanvas *)(user->object); + CGFloat sx = lua_tonumber(L, 2); + CGFloat sy = 0; + if (lua_type(L, 3)==LUA_TNUMBER ) { + sy = lua_tonumber(L, 3); + } + [canvas skew:sx :sy]; + } + return 0; +} + +-(void) scale:(CGFloat)scaleX :(CGFloat)scaleY { + if( _contentRef ) { + self.scaleX = scaleX; + self.scaleY = scaleY; + CGContextScaleCTM(_contentRef, scaleX, scaleY); + } +} + +static int canvas_scale (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVCanvas* canvas = (__bridge LVCanvas *)(user->object); + CGFloat scaleX = lua_tonumber(L, 2); + CGFloat scaleY = scaleX; + if( lua_type(L, 3)==LUA_TNUMBER ) { + scaleY = lua_tonumber(L, 3); + } + [canvas scale:scaleX :scaleY]; + } + return 0; +} + +-(void) translate:(CGFloat)x :(CGFloat)y { + self.translate = CGPointMake(x, y); + if( _contentRef ) { + CGContextTranslateCTM(_contentRef, x, y); + } +} + +static int canvas_translate (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVCanvas* canvas = (__bridge LVCanvas *)(user->object); + CGFloat x = lua_tonumber(L, 2); + CGFloat y = lua_tonumber(L, 3); + [canvas translate:x :y]; + } + return 0; +} + +static void releaseCanvasUserData(LVUserDataInfo* user){ + if( user && user->object ){ + LVCanvas* canvas = CFBridgingRelease(user->object); + user->object = NULL; + if( canvas ){ + canvas.lv_userData = NULL; + canvas.lv_luaviewCore = nil; + canvas.contentRef = nil; + } + } +} + +static int lvCanvasGC (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + releaseCanvasUserData(user); + return 0; +} + +static int lvNewCanvas (lua_State *L) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVCanvas class]]; + + LVCanvas* canvas = [[c alloc] init:L]; + + { + NEW_USERDATA(userData, Canvas); + userData->object = CFBridgingRetain(canvas); + canvas.lv_userData = userData; + + luaL_getmetatable(L, META_TABLE_Canvas ); + lua_setmetatable(L, -2); + } + return 1; +} + ++(LVCanvas*) createLuaCanvas:(lua_State *)L contentRef:(CGContextRef) contentRef{ + LVCanvas* lvCanvas = [[LVCanvas alloc] init:L]; + lvCanvas.contentRef = contentRef; + { + NEW_USERDATA(userData, Canvas); + userData->object = CFBridgingRetain(lvCanvas); + lvCanvas.lv_userData = userData; + + luaL_getmetatable(L, META_TABLE_Canvas ); + lua_setmetatable(L, -2); + } + return lvCanvas; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewCanvas globalName:globalName defaultName:@"Canvas"]; + + const struct luaL_Reg memberFunctions [] = { + {"__gc", lvCanvasGC }, + {"nativeObj", nativeObj}, + + // size + // font + + {"drawPoint",canvas_drawPoint}, + {"drawLine",canvas_drawLine}, + {"drawRect",canvas_drawRect}, + {"drawRoundRect",canvas_drawRoundRect}, + {"drawCircle",canvas_drawCircle}, + {"drawEllipse",canvas_drawEllipse}, //__deprecated_msg("Use rotation") + {"drawText",drawText}, + {"drawOval",canvas_drawOval}, + {"drawArc",canvas_drawArc}, + {"drawImage",canvas_drawImage}, + + {"color",canvas_color}, + {"alpha",canvas_alpha}, + {"strokeWidth",canvas_strokeWidth}, + {"style",canvas_style}, + {"textSize",canvas_textSize}, + + {"resetPaint",canvas_resetPaint}, + {"save",canvas_save}, + {"restore",canvas_restore}, + + {"rotate",canvas_rotate}, + {"skew",canvas_skew}, + {"scale",canvas_scale}, + {"translate",canvas_translate}, + {"bold",canvas_bold}, + + + {"clipRect",canvas_clipRect}, + + {NULL, NULL} + }; + + lv_createClassMetaTable(L, META_TABLE_Canvas); + luaL_openlib(L, NULL, memberFunctions, 0); + + + { + // PaintStyle 常量 + lua_settop(L, 0); + NSDictionary* v = nil; + v = @{ + @"FILL": @(kCGPathFill), + @"EOFILL": @(kCGPathEOFill),//__deprecated_msg("") + @"STROKE": @(kCGPathStroke), + @"FILLSTROKE": @(kCGPathFillStroke), + @"EOFILLSTROKE": @(kCGPathEOFillStroke),//__deprecated_msg("") + }; + [LVUtil defineGlobal:@"PaintStyle" value:v L:L]; + } + return 0; +} + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVClassInfo.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVClassInfo.h new file mode 100644 index 00000000..e35c8791 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVClassInfo.h @@ -0,0 +1,24 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import + +@class LVMethod; + +@interface LVClassInfo : NSObject + + +- (void) addMethod:(LVMethod*) method key:(NSString*) key; +- (LVMethod*) getMethod:(NSString*) methodName; + +- (BOOL) existMethod:(NSString*) methodName; +- (void) setMethod:(NSString*) methodName exist:(BOOL) exist; + ++ (LVClassInfo*) classInfo:(NSString*) className; + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVClassInfo.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVClassInfo.m new file mode 100644 index 00000000..efc29e77 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVClassInfo.m @@ -0,0 +1,64 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVClassInfo.h" +#import "LVMethod.h" + +@interface LVClassInfo () +@property (nonatomic,strong) NSMutableDictionary* methods; +@property (nonatomic,strong) NSMutableDictionary* apiHash; +@end + +static NSMutableDictionary* g_allClassInfo = nil; + +@implementation LVClassInfo + +-(instancetype) init{ + self = [super init]; + if( self ) { + self.methods = [[NSMutableDictionary alloc] init]; + self.apiHash = [[NSMutableDictionary alloc] init]; + } + return self; +} + ++(LVClassInfo*) classInfo:(NSString*) className { + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + g_allClassInfo = [[NSMutableDictionary alloc] init]; + }); + + if( className==nil ) { + return nil; + } + LVClassInfo* classInfo = g_allClassInfo[className]; + if( classInfo==nil ) { + classInfo = [[LVClassInfo alloc] init]; + g_allClassInfo[className] = classInfo; + } + return classInfo; +} + +-(void) addMethod:(LVMethod*) method key:(NSString*) key{ + self.methods[key] = method; +} + +-(LVMethod*) getMethod:(NSString*) methodName{ + return self.methods[methodName]; +} + +-(BOOL) existMethod:(NSString*) methodName{ + return self.apiHash[methodName] != nil; +} + +-(void) setMethod:(NSString*) methodName exist:(BOOL) exist{ + if( exist ) { + self.apiHash[methodName] = @(exist); + } +} +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCollectionView.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCollectionView.h new file mode 100644 index 00000000..49d40688 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCollectionView.h @@ -0,0 +1,29 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" +#import "UIScrollView+LuaView.h" +#import "LVFlowLayout.h" + +@interface LVCollectionView : UICollectionView + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; +@property(nonatomic,assign) NSUInteger lv_align; +@property(nonatomic,strong) CAShapeLayer* lv_shapeLayer; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +- (id) init:(lua_State*) l; + +@property(nonatomic,weak) id lvScrollViewDelegate; + +@property(nonatomic,strong) LVFlowLayout* lvflowLayout; + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCollectionView.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCollectionView.m new file mode 100644 index 00000000..7df944d6 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCollectionView.m @@ -0,0 +1,275 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVCollectionView.h" +#import "LVCollectionViewCell.h" +#import "LView.h" +#import "LVBaseView.h" +#import "LVScrollView.h" +#import "UIScrollView+LuaView.h" +#import "LVCollectionViewDelegate.h" +#import "LVFlowLayout.h" +#import "LVHeads.h" + +@interface LVCollectionView () +@property (nonatomic,strong) LVCollectionViewDelegate* collectionViewDelegate; +@end + + +@implementation LVCollectionView + +-(id) init:(lua_State*) l { + LVFlowLayout* flowLayout = [[LVFlowLayout alloc] init]; + self = [super initWithFrame:CGRectMake(0, 0, 0, 0) collectionViewLayout:flowLayout]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + self.collectionViewDelegate = [[LVCollectionViewDelegate alloc] init:self]; + self.delegate = self.collectionViewDelegate; + self.dataSource = self.collectionViewDelegate; + self.backgroundColor = [UIColor clearColor]; + + self.lvflowLayout = flowLayout; + self.collectionViewDelegate.lvCollectionView = self; + self.collectionViewDelegate.lvflowLayout = flowLayout; + + self.alwaysBounceVertical = YES; // 垂直总是有弹性动画 + self.scrollsToTop = NO; + } + return self; +} + +-(void) setLvScrollViewDelegate:(id)lvScrollViewDelegate{ + _lvScrollViewDelegate = lvScrollViewDelegate; + self.collectionViewDelegate.delegate = lvScrollViewDelegate; +} + +-(void) dealloc{ +} + +-(void) reloadData{ + [super reloadData]; +} + +-(void) reloadDataASync{ + dispatch_async(dispatch_get_main_queue(), ^{ + [self performSelector:@selector(reloadData) withObject:nil afterDelay:0.001 inModes:@[NSRunLoopCommonModes]]; + }); +} + +-(void) layoutSubviews{ + [super layoutSubviews]; + if ( self.lv_luaviewCore.l ) { + lua_settop(self.lv_luaviewCore.l, 0); + } + [self lv_callLuaByKey1:@STR_ON_LAYOUT]; +} + +// 重载以实现可能的定制需求, contentOffset +- (void) luaviewSetContentOffset:(CGPoint)contentOffset animated:(BOOL)animated{ + [self setContentOffset:contentOffset animated:animated]; +} + +// 重载以实现可能的定制需求, RectToVisible +- (void) luaviewScrollRectToVisible:(CGRect)rect animated:(BOOL)animated{ + [self scrollRectToVisible:rect animated:animated]; +} + +// 重载以实现可能的定制需求, scrollToTop +- (void) luaviewScrollToTopWithAnimated:(BOOL)animated{ + [self scrollRectToVisible:CGRectMake(0, 0, 320, 10) animated:animated]; +} + + + +#pragma -mark lvNewCollectionView +static int lvNewCollectionView(lua_State *L) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVCollectionView class]]; + + LVCollectionView* collectionView = [[c alloc] init:L]; + [collectionView lv_initRefreshHeader]; + + NEW_USERDATA(userData, View); + userData->object = CFBridgingRetain(collectionView); + collectionView.lv_userData = userData; + luaL_getmetatable(L, META_TABLE_UICollectionView ); + lua_setmetatable(L, -2); + + if ( lua_gettop(L)>=1 && lua_type(L, 1)==LUA_TTABLE ) { + lua_pushvalue(L, 1); + lv_udataRef(L, USERDATA_KEY_DELEGATE ); + } + + LuaViewCore* lview = LV_LUASTATE_VIEW(L); + if( lview ){ + [lview containerAddSubview:collectionView]; + } + return 1; +} + +static int reload (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVCollectionView* tableView = (__bridge LVCollectionView *)(user->object); + //reload接口异步拉起,确保layout中也能调用reload + [tableView reloadDataASync]; + lua_pushvalue(L, 1); + return 1; + } + return 0; +} + +static int miniSpacing (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVCollectionView* tableView = (__bridge LVCollectionView *)(user->object); + if( lua_gettop(L)>=3 ) { + CGFloat value1 = lua_tonumber(L, 2); + CGFloat value2 = lua_tonumber(L, 3); + tableView.lvflowLayout.minimumLineSpacing = value1; + tableView.lvflowLayout.minimumInteritemSpacing = value2; + return 0; + } else if( lua_gettop(L)>=2 ) { + CGFloat value1 = lua_tonumber(L, 2); + tableView.lvflowLayout.minimumLineSpacing = value1; + tableView.lvflowLayout.minimumInteritemSpacing = value1; + return 0; + } else { + CGFloat value1 = tableView.lvflowLayout.minimumLineSpacing; + CGFloat value2 = tableView.lvflowLayout.minimumInteritemSpacing; + lua_pushnumber(L, value1); + lua_pushnumber(L, value2); + return 2; + } + } + return 0; +} + +static int scrollDirection (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVCollectionView* tableView = (__bridge LVCollectionView *)(user->object); + if( lua_gettop(L)>=2 ) { + int value1 = lua_tonumber(L, 2); + tableView.lvflowLayout.scrollDirection = value1; + return 0; + } else { + CGFloat value1 = tableView.lvflowLayout.scrollDirection; + lua_pushnumber(L, value1); + return 1; + } + } + return 0; +} + +static int scrollToCell (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( LVIsType(user, View) ){ + LVCollectionView* collectionView = (__bridge LVCollectionView *)(user->object); + if( [collectionView isKindOfClass:[LVCollectionView class]] ) { + int nargs = lua_gettop(L); + if( nargs>=3 ){ + int section = lua_tonumber(L, 2); + int row = lua_tonumber(L, 3); + CGFloat offsetY = 0; + BOOL animation = YES; + for( int i=4; i<=nargs; i++ ) { + if( nargs>=i && lua_type(L, i)==LUA_TNUMBER ) { + offsetY = lua_tonumber(L, i); + } + if( nargs>=i && lua_type(L, i)==LUA_TBOOLEAN ) { + animation = lua_toboolean(L, i); + } + } + + int nativeSection = section-1; + int nativeRow = row-1 ; + if( 0<=nativeSection && nativeSection0 ) { + CGFloat y = r.origin.y + offsetY; + CGSize contentSize = collectionView.contentSize; + CGRect bounds = collectionView.bounds; + // 越界检查 + if( y + bounds.size.height > contentSize.height ) { + y = contentSize.height - bounds.size.height; + } + if( y < 0 ) { + y = 0; + } + [collectionView luaviewSetContentOffset:CGPointMake(0, y) animated:animation]; + } + } + return 0; + } + } + } + return 0; +} + +static int scrollToTop(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( LVIsType(user, View) ){ + LVCollectionView* tableView = (__bridge LVCollectionView *)(user->object); + if( [tableView isKindOfClass:[LVCollectionView class]] ) { + BOOL animation = YES; + if( lua_gettop(L)>=2 ) { + animation = lua_tonumber(L, 2); + } + [tableView luaviewScrollToTopWithAnimated:animation]; + return 0; + } + } + return 0; +} + ++(NSString*) globalName{ + return @"CollectionView"; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + + [LVUtil reg:L clas:self cfunc:lvNewCollectionView globalName:globalName defaultName:[self globalName]]; + + const struct luaL_Reg memberFunctions [] = { + // refreshEnable // IOS 为实现 + {"reload", reload},// 安卓支持section row + + {"miniSpacing", miniSpacing}, + + {"scrollDirection", scrollDirection},// for IOS + + + {"scrollToCell", scrollToCell}, + {"scrollToTop", scrollToTop}, + {NULL, NULL} + }; + + lv_createClassMetaTable(L ,META_TABLE_UICollectionView); + + luaL_openlib(L, NULL, [LVBaseView baseMemberFunctions], 0); + luaL_openlib(L, NULL, [LVScrollView memberFunctions], 0); + luaL_openlib(L, NULL, memberFunctions, 0); + + const char* keys[] = { "addView", NULL};// 移除多余API + lv_luaTableRemoveKeys(L, keys ); + return 1; +} + + + +-(NSString*) description{ + return [NSString stringWithFormat:@"", + (int)[self hash], NSStringFromCGRect(self.frame) , NSStringFromCGSize(self.contentSize)]; +} + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCollectionViewCell.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCollectionViewCell.h new file mode 100644 index 00000000..65ee9217 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCollectionViewCell.h @@ -0,0 +1,21 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + +@interface LVCollectionViewCell : UICollectionViewCell + +@property (nonatomic, assign) BOOL isInited; + +-(void) pushTableToStack; + +-(void) doInitWithLView:(LuaViewCore*) lview; + + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCollectionViewCell.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCollectionViewCell.m new file mode 100644 index 00000000..e16e0861 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCollectionViewCell.m @@ -0,0 +1,65 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVCollectionViewCell.h" +#import "LVHeads.h" +#import "LView.h" +#import "lapi.h" + +@interface LVCollectionViewCell () +@property (nonatomic,weak) LuaViewCore* lv_luaviewCore; +@end + + + +@implementation LVCollectionViewCell + + +-(void) dealloc{ + lua_State* L = self.lv_luaviewCore.l; + if( L ) { + [LVUtil unregistry:L key:self]; + } +} + +-(void) doInitWithLView:(LuaViewCore*) lview{ + self.lv_luaviewCore = lview; + lua_State* L = lview.l; + if( L ) { + lua_createtable(L, 0, 0); + [LVUtil registryValue:L key:self stack:-1]; + lv_luaTableSetWeakWindow(L, self.contentView); + } +} + +-(void) pushTableToStack{ + lua_State* L = self.lv_luaviewCore.l; + if( L ) { + [LVUtil pushRegistryValue:L key:self]; + } +} + +-(NSString*) description{ + return [NSString stringWithFormat:@"", (int)[self hash], NSStringFromCGRect(self.frame)]; +} + +- (void) layoutSubviews{ + [super layoutSubviews]; + + CGRect rect = self.frame; + NSArray* subviews = [self.contentView subviews]; + for( UIView* view in subviews){ + [view lv_alignSelfWithSuperRect:rect]; + } +} + +// 修复gif图片滚动会消失问题 +-(void) prepareForReuse{ +} + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCollectionViewDelegate.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCollectionViewDelegate.h new file mode 100644 index 00000000..be2fc4bd --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCollectionViewDelegate.h @@ -0,0 +1,22 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVScrollViewDelegate.h" + +#define IDENTIFIER "Id" +#define DEFAULT_CELL_IDENTIFIER @"LVCollectionCell.default.identifier" + +@class LVCollectionView; +@class LVFlowLayout; + +@interface LVCollectionViewDelegate : LVScrollViewDelegate + +@property(nonatomic,weak) LVCollectionView* lvCollectionView; +@property(nonatomic,weak) LVFlowLayout* lvflowLayout; + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCollectionViewDelegate.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCollectionViewDelegate.m new file mode 100644 index 00000000..88c0b036 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCollectionViewDelegate.m @@ -0,0 +1,362 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVCollectionViewDelegate.h" +#import "LVCollectionView.h" +#import "LVCollectionViewCell.h" +#import "LView.h" +#import "UIView+LuaView.h" +#import "LVHeads.h" + + +static inline NSInteger mapRow(NSInteger row){ + return row + 1; +} + +static inline NSInteger mapSection(NSInteger section){ + return section + 1; +} + +@interface LVCollectionViewDelegate () + +@property(nonatomic, strong) NSMutableSet *registeredIds; + + +@end + + +@implementation LVCollectionViewDelegate + +- (void)tryRegisterId:(NSString *)identifier inCollectionView:(UICollectionView *)view { + if (self.registeredIds == nil) { + self.registeredIds = [NSMutableSet set]; + } + if (![self.registeredIds containsObject:identifier]) { + [view registerClass:[LVCollectionViewCell class] forCellWithReuseIdentifier:identifier]; + [self.registeredIds addObject:identifier]; + } +} + +- (UICollectionViewCell*) collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { + NSInteger section = indexPath.section; + NSInteger row = indexPath.row; + BOOL pinned = NO; + NSString* identifier = [self retStringCallKey1:"Cell" key2:IDENTIFIER mapedSection:mapSection(section) mapedRow:mapRow(row) pinned:&pinned]; + if( identifier == nil ){ + identifier = DEFAULT_CELL_IDENTIFIER; + } + // 制定的cell 是否悬浮 + if( pinned ) { + [self.lvflowLayout addPinnedIndexPath:indexPath]; + } else { + [self.lvflowLayout delPinnedIndexPath:indexPath]; + } + [self tryRegisterId:identifier inCollectionView:collectionView]; + LVCollectionViewCell* cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath]; + cell.contentView.frame = cell.bounds;//脚本的window是ContentView大小可能和Cell不同步 + LuaViewCore* lview = self.owner.lv_luaviewCore; + lua_State* L = lview.l; + UIView* newWindow = cell.contentView; + [lview pushWindow:newWindow]; + if ( L ) { + if( !cell.isInited ){ + cell.isInited = YES; + [cell doInitWithLView:lview]; + + // 创建cell初始化 + lua_settop(L, 0); + lua_checkstack(L, 12); + [cell pushTableToStack];//arg1: cell + lua_pushnumber(L, mapSection(section) );//arg2: section + lua_pushnumber(L, mapRow(row) );//arg3: row + + lv_pushUserdata(L, self.owner.lv_userData); + lv_pushUDataRef(L, USERDATA_KEY_DELEGATE); + [LVUtil call:L key1:"Cell" key2:identifier.UTF8String key3:"Init" nargs:3 nrets:0 retType:LUA_TNONE]; + } + { // 通知布局调整 + // 参数 cell,section,row + lua_settop(L, 0); + lua_checkstack(L, 12); + [cell pushTableToStack];//arg1: cell + lua_pushnumber(L, mapSection(section) );//arg2: section + lua_pushnumber(L, mapRow(row) );//arg3: row + + lv_pushUserdata(L, self.owner.lv_userData); + lv_pushUDataRef(L, USERDATA_KEY_DELEGATE); + [LVUtil call:L key1:"Cell" key2:identifier.UTF8String key3:"Layout" nargs:3 nrets:0 retType:LUA_TNONE]; + } + } + [lview popWindow:newWindow]; + return cell; +} + +// section数量 +- (NSInteger) numberOfSectionsInCollectionView:(UICollectionView *)collectionView{ + lua_State* l = self.owner.lv_luaviewCore.l; + if( l && self.owner.lv_userData ){ + lv_pushUserdata(l, self.owner.lv_userData); + lv_pushUDataRef(l, USERDATA_KEY_DELEGATE); + if( [LVUtil call:l key1:"Section" key2:"SectionCount" key3:NULL nargs:0 nrets:1 retType:LUA_TNUMBER] ==0 ) { + if( lua_type(l, -1)==LUA_TNUMBER ) { + NSInteger num = lua_tonumber(l, -1); + num = (num>0 ? num : 0); + return num; + } + } + return 1; + } + return 0; +} +// 每个区域的行数 +- (NSInteger) collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{ + lua_State* l = self.owner.lv_luaviewCore.l; + if( l ){ + // args + lua_pushnumber(l, mapSection(section) ); + + // table + lv_pushUserdata(l, self.owner.lv_userData); + lv_pushUDataRef(l, USERDATA_KEY_DELEGATE); + if( [LVUtil call:l key1:"Section" key2:"RowCount" key3:NULL nargs:1 nrets:1 retType:LUA_TNUMBER] ==0 ) { + if( lua_type(l, -1)==LUA_TNUMBER ) { + NSInteger num = lua_tonumber(l, -1); + num = (num>0 ? num : 0); + return num; + } + } + } + return 0; +} +//------- +#pragma mark --UICollectionViewDelegateFlowLayout +//定义每个UICollectionView 的大小 +- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath +{ + NSInteger section = indexPath.section; + NSInteger row = indexPath.row; + NSString* identifier = [self retStringCallKey1:"Cell" key2:IDENTIFIER mapedSection:mapSection(section) mapedRow:mapRow(row) pinned:NULL]; + if( identifier ) { + CGSize size = [self retSizeCallKey1:"Cell" key2:identifier.UTF8String key3:"Size" mapedSection:mapSection(section) mapedRow:mapRow(row) ]; + if( size.width<0 || isnan(size.width) ) { + size.width = 0; + } + if( size.height<0 || isnan(size.height) ) { + size.height = 0; + } + return size; + } else { + return CGSizeMake(self.owner.frame.size.width, 1); + } +} +//定义每个UICollectionView 的间距 +-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section +{ + UIEdgeInsets insets = [self retInsetCallKey1:"Section" key2:"EdgeInsets" mapedSection:mapSection(section) mapedRow:mapRow(0)]; + //insets.top = self.flowLayout.minimumLineSpacing; + return insets; +} +//定义每个UICollectionView 纵向的间距 +- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section { + // return self.flowLayout.minimumLineSpacing; + CGFloat spacing = [self retFloatCallKey1:"Section" key2:"Spacing" mapedSection:mapSection(section) ]; + return spacing; +} + +- (CGFloat) retFloatCallKey1:(const char*) funcName key2:(const char*) key2 mapedSection:(NSInteger) mapedSection { + lua_State* l = self.owner.lv_luaviewCore.l; + if( l ){ + lua_checkstack(l, 12); + lua_pushnumber(l, mapedSection); + + lv_pushUserdata(l, self.owner.lv_userData); + lv_pushUDataRef(l, USERDATA_KEY_DELEGATE); + if( [LVUtil call:l key1:funcName key2:key2 key3:NULL nargs:1 nrets:1 retType:LUA_TNUMBER] ==0 ) { + if( lua_type(l, -1)==LUA_TNUMBER ) { + CGFloat heigth = lua_tonumber(l, -1); + return heigth; + } + } + } + return 0; +} + +- (NSString*) retStringCallKey1:(const char*) key1 key2:(const char*)key2 + mapedSection:(NSInteger) mapedSection mapedRow:(NSInteger) mapedRow pinned:(BOOL*) pinned{ + lua_State* l = self.owner.lv_luaviewCore.l; + if( l ){ + // args + lua_checkstack(l, 12); + lua_pushnumber(l, mapedSection); + lua_pushnumber(l, mapedRow); + + // table + lv_pushUserdata(l, self.owner.lv_userData); + lv_pushUDataRef(l, USERDATA_KEY_DELEGATE); + + if( [LVUtil call:l key1:key1 key2:key2 key3:NULL nargs:2 nrets:2 retType:LUA_TSTRING] ==0 ) { + if( lua_type(l, -2)==LUA_TSTRING ){ + NSString* value = lv_paramString(l, -2); + BOOL yes = lua_toboolean(l, -1); + if( pinned ) { + *pinned = yes; + } + return value; + } + } + } + return nil; +} + +- (CGSize) retSizeCallKey1:(const char*) key1 key2:(const char*)key2 key3:(const char*)key3 + mapedSection:(NSInteger) mapedSection mapedRow:(NSInteger) mapedRow { + lua_State* l = self.owner.lv_luaviewCore.l; + if( l ){ + // args + lua_checkstack(l, 12); + lua_pushnumber(l, mapedSection); + lua_pushnumber(l, mapedRow); + + // table + lv_pushUserdata(l, self.owner.lv_userData); + lv_pushUDataRef(l, USERDATA_KEY_DELEGATE); + + if( [LVUtil call:l key1:key1 key2:key2 key3:key3 nargs:2 nrets:2 retType:LUA_TNONE] ==0 ) { + CGSize size = {0}; + if( lua_type(l, -1) ==LUA_TNIL ) { + size.width = self.owner.frame.size.width; + size.height = lua_tonumber(l, -2); + } else{ + size.width = lua_tonumber(l, -2); + size.height = lua_tonumber(l, -1); + } + return size; + } + } + return CGSizeMake(self.owner.frame.size.width, 1); +} +- (UIEdgeInsets) retInsetCallKey1:(const char*) key1 key2:(const char*)key2 + mapedSection:(NSInteger) mapSection mapedRow:(NSInteger)mapedRow { + lua_State* l = self.owner.lv_luaviewCore.l; + if( l ){ + // args + lua_checkstack(l, 12); + lua_pushnumber(l, mapSection); + lua_pushnumber(l, mapedRow); + + // table + lv_pushUserdata(l, self.owner.lv_userData); + lv_pushUDataRef(l, USERDATA_KEY_DELEGATE); + + if( [LVUtil call:l key1:key1 key2:key2 key3:NULL nargs:2 nrets:4 retType:LUA_TNONE] ==0 ) { + UIEdgeInsets egeInsets = {0}; + egeInsets.top = lua_tonumber(l, -4); + egeInsets.left = lua_tonumber(l, -3); + egeInsets.bottom = lua_tonumber(l, -2); + egeInsets.right = lua_tonumber(l, -1); + return egeInsets; + } + } + return UIEdgeInsetsMake(0, 0, 0, 0); +} + +- (void) collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { + NSInteger section = indexPath.section; + NSInteger row = indexPath.row; + lua_State* l = self.owner.lv_luaviewCore.l; + if( l ){ + NSString* identifier = [self retStringCallKey1:"Cell" key2:IDENTIFIER mapedSection:mapSection(section) mapedRow:mapRow(row) pinned:NULL]; + if ( identifier ) { + // 参数 cell,section,row + lua_settop(l, 0); + lua_checkstack(l, 12); + lua_pushnil(l);// cell + lua_pushnumber(l, mapSection(section) ); + lua_pushnumber(l, mapRow(row) ); + + // table + lv_pushUserdata(l, self.owner.lv_userData); + lv_pushUDataRef(l, USERDATA_KEY_DELEGATE); + + if( [LVUtil call:l key1:"Cell" key2:identifier.UTF8String key3:STR_CALLBACK key4:STR_ON_CLICK nargs:3 nrets:0 retType:LUA_TNONE]==0 ) { + } + } + } +} + +-(void) callWithScrollArgsForKey:(NSString*) functionName{ + UICollectionView* tableView = (UICollectionView*)self.owner; + NSArray* indexPaths = [tableView indexPathsForVisibleItems]; + int visibleCount = 0; + NSIndexPath* indexPath0 = nil; + + for( NSIndexPath* indexPath in indexPaths ) { + visibleCount ++; + if( indexPath0== nil ) { + indexPath0 = indexPath; + } + } + lua_State* L = self.owner.lv_luaviewCore.l; + if( L && indexPath0 ) { + NSInteger section = indexPath0.section; + NSInteger row = indexPath0.row; + + lua_settop(L, 0); + lua_pushnumber(L, mapSection(section) ); + lua_pushnumber(L, mapRow(row) ); + lua_pushnumber(L, visibleCount ); + [self.owner lv_callLuaByKey1:functionName key2:nil argN:3]; + } +} + +- (void)scrollViewDidScroll:(UIScrollView *)scrollView{ + [self callWithScrollArgsForKey:@"Scrolling"]; + if( [self.delegate respondsToSelector:@selector(scrollViewDidScroll:)] ) { + [self.delegate scrollViewDidScroll:scrollView]; + } +} + +- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{ + [self callWithScrollArgsForKey:@"ScrollBegin"]; + if( [self.delegate respondsToSelector:@selector(scrollViewWillBeginDragging:)] ) { + [self.delegate scrollViewWillBeginDragging:scrollView]; + } +} + +- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{ + [self callWithScrollArgsForKey:@"ScrollEnd"]; + if( [self.delegate respondsToSelector:@selector(scrollViewDidEndDecelerating:)] ) { + [self.delegate scrollViewDidEndDecelerating:scrollView]; + } +} + +- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView{ + [self callWithScrollArgsForKey:@"ScrollEnd"]; + if( [self.delegate respondsToSelector:@selector(scrollViewDidEndScrollingAnimation:)] ) { + [self.delegate scrollViewDidEndScrollingAnimation:scrollView]; + } +} + +- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{ + if( !decelerate ) { + [self callWithScrollArgsForKey:@"ScrollEnd"]; + } + if( [self.delegate respondsToSelector:@selector(scrollViewDidEndDragging:willDecelerate:)] ) { + [self.delegate scrollViewDidEndDragging:scrollView willDecelerate:decelerate]; + } +} + +// IOS 特有事件, 状态栏回顶 +- (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView{ + [self callWithScrollArgsForKey:@"ScrollToTop"]; + if( [self.delegate respondsToSelector:@selector(scrollViewDidScrollToTop:)] ) { + [self.delegate scrollViewDidScrollToTop:scrollView]; + } +} + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCustomPanel.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCustomPanel.h new file mode 100644 index 00000000..241ada7d --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCustomPanel.h @@ -0,0 +1,26 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + +@interface LVCustomPanel : UIView + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; +@property(nonatomic,assign) NSUInteger lv_align; +@property(nonatomic,strong) CAShapeLayer* lv_shapeLayer; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +- (void) callLuaWithArgument:(NSString*) info; +- (void) callLuaWithArguments:(NSArray*) args; +// callLuaFunction() +// callLuaCallback + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCustomPanel.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCustomPanel.m new file mode 100644 index 00000000..fa0b094a --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCustomPanel.m @@ -0,0 +1,100 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVCustomPanel.h" +#import "LVBaseView.h" +#import "LView.h" +#import "LVHeads.h" + +@implementation LVCustomPanel + +- (void) callLuaWithArgument:(NSString*) info { + [self callLuaWithArguments:@[ (info?info:@"") ]]; +} + +- (void) callLuaWithArguments:(NSArray*) args{ + // 外部回调脚本一定要在主线程调用 + dispatch_block_t f = ^(){ + lua_State* L = self.lv_luaviewCore.l; + if( L && self.lv_userData ){ + lua_checkstack(L,32); + int num = lua_gettop(L); + for( int i=0; i=4 ) { + r = CGRectMake(lua_tonumber(L, 1), lua_tonumber(L, 2), lua_tonumber(L, 3), lua_tonumber(L, 4)); + } + LVCustomPanel* errorNotice = [[c alloc] initWithFrame:r]; + { + NEW_USERDATA(userData, View); + userData->object = CFBridgingRetain(errorNotice); + errorNotice.lv_userData = userData; + errorNotice.lv_luaviewCore = LV_LUASTATE_VIEW(L); + + luaL_getmetatable(L, META_TABLE_CustomPanel ); + lua_setmetatable(L, -2); + } + LuaViewCore* view = LV_LUASTATE_VIEW(L); + if( view ){ + [view containerAddSubview:errorNotice]; + } + return 1; /* new userdatum is already on the stack */ +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewCustomPanelView globalName:globalName defaultName:@"CustomPanel"]; + + const struct luaL_Reg memberFunctions [] = { + {NULL, NULL} + }; + + lv_createClassMetaTable(L, META_TABLE_CustomPanel); + + luaL_openlib(L, NULL, [LVBaseView baseMemberFunctions], 0); + luaL_openlib(L, NULL, memberFunctions, 0); + return 1; +} + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCustomView.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCustomView.h new file mode 100644 index 00000000..4865143d --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCustomView.h @@ -0,0 +1,24 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + +@interface LVCustomView : UIView + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; +@property(nonatomic,assign) NSUInteger lv_align; +@property(nonatomic,strong) CAShapeLayer* lv_shapeLayer; +@property(nonatomic,assign) BOOL lv_canvas; + +-(id) init:(lua_State*) l; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCustomView.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCustomView.m new file mode 100644 index 00000000..1c28125d --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCustomView.m @@ -0,0 +1,85 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVCustomView.h" +#import "LVBaseView.h" +#import "LView.h" +#import "LVCanvas.h" + +@interface LVCustomView () +@property(nonatomic,assign) BOOL lv_isCallbackAddClickGesture;// 支持Callback 点击事件 +@end + +@implementation LVCustomView + +-(id) init:(lua_State*) l{ + self = [super init]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + self.backgroundColor = [UIColor clearColor]; + self.clipsToBounds = YES; + } + return self; +} + +-(void) drawRect:(CGRect)rect{ + [super drawRect:rect]; + + lua_State* L = self.lv_luaviewCore.l; + if( L ) { + lua_settop(L, 0); + CGContextRef contextRef = UIGraphicsGetCurrentContext(); + LVCanvas* canvas = [LVCanvas createLuaCanvas:L contentRef:contextRef]; + [self lv_callLuaByKey1:@STR_ON_DRAW key2:nil argN:1]; + canvas.contentRef = NULL; + } +} + +#pragma -mark CustomView +static int lvNewCustomView (lua_State *L) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVCustomView class]]; + + { + LVCustomView* customView = [[c alloc] init:L]; + { + NEW_USERDATA(userData, View); + userData->object = CFBridgingRetain(customView); + customView.lv_userData = userData; + + luaL_getmetatable(L, META_TABLE_CustomView ); + lua_setmetatable(L, -2); + } + LuaViewCore* father = LV_LUASTATE_VIEW(L); + if( father ){ + [father containerAddSubview:customView]; + } + } + return 1; /* new userdatum is already on the stack */ +} + +static int onDraw (lua_State *L) { + return lv_setCallbackByKey(L, STR_ON_DRAW, NO); +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewCustomView globalName:globalName defaultName:@"CustomView"]; + + const struct luaL_Reg memberFunctions [] = { + {"onDraw" , onDraw}, + {NULL, NULL} + }; + + lv_createClassMetaTable(L,META_TABLE_CustomView); + + luaL_openlib(L, NULL, [LVBaseView baseMemberFunctions], 0); + luaL_openlib(L, NULL, memberFunctions, 0); + + return 1; +} + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVDB.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVDB.h new file mode 100644 index 00000000..c1c8f6b4 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVDB.h @@ -0,0 +1,16 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + +@interface LVDB : NSObject + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVDB.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVDB.m new file mode 100644 index 00000000..db677ea5 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVDB.m @@ -0,0 +1,92 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVDB.h" +#import "LVHeads.h" + +@implementation LVDB + + + +static int db_get (lua_State *L) { + lv_clearFirstTableValue(L); + NSString* key = lv_paramString(L, 1); + NSString* defaultValue = nil; + if( lua_gettop(L)>=2 && lua_type(L, 2)==LUA_TNUMBER ) { + double v = lua_tonumber(L, 2); + defaultValue = [NSString stringWithFormat:@"%lf",v]; + } else { + defaultValue = lv_paramString(L, 2); + } + if( key.length>0 ) { + NSString* value = [[NSUserDefaults standardUserDefaults] objectForKey:key]; + if( value == nil ) + value = defaultValue; + lua_pushstring(L, value.UTF8String); + return 1; /* number of results */ + } else { + return 0; + } +} + +static BOOL needSub(NSString* s){ + if( [s rangeOfString:@"."].length>0 ){ + if( [s hasSuffix:@"0"] || [s hasSuffix:@"."] ){ + return YES; + } + } + return NO; +} + +static NSString* clearString(NSString* s){ + if( needSub(s) ){ + NSMutableString* buf = [[NSMutableString alloc] initWithString:s]; + for( ;buf.length>0; ){ + if( needSub(buf) ){ + NSRange range = {0}; + range.length = 1; + range.location = buf.length-1; + [buf deleteCharactersInRange:range]; + } else { + break; + } + } + return buf; + } + return s; +} + +static int db_set (lua_State *L) { + lv_clearFirstTableValue(L); + if( lua_gettop(L)>=2 ) { + NSString* key = lv_paramString(L, 1); + NSString* value = lv_paramString(L, 2); + if( value==nil && (lua_type(L, 2)==LUA_TNUMBER) ){ + value = [NSString stringWithFormat:@"%f",lua_tonumber(L, 2)]; + value = clearString(value); + } + if( key.length>0 && value.length>0 ){ + [[NSUserDefaults standardUserDefaults] setObject:value forKey:key]; + [[NSUserDefaults standardUserDefaults] synchronize]; + } + } + return 0; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + const struct luaL_Reg functions [] = { + {"get", db_get}, + {"set", db_set}, + {LUAVIEW_SYS_TABLE_KEY, db_set}, + {NULL, NULL} + }; + luaL_openlib(L, "DB", functions, 0); + return 0; +} + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVData.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVData.h new file mode 100644 index 00000000..d152a4de --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVData.h @@ -0,0 +1,26 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + + +//LVData +@interface LVData : NSObject + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; + +@property(nonatomic,strong) NSMutableData* data;//真实的数据 + +-(id) init:(lua_State*) l; ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + ++(int) createDataObject:(lua_State *)L data:(NSData*) data; + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVData.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVData.m new file mode 100644 index 00000000..ec037483 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVData.m @@ -0,0 +1,219 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVData.h" +#import "LVHeads.h" + +@interface LVData () +@end + +@implementation LVData + +-(id) init:(lua_State *)l{ + self = [super init]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + self.data = [[NSMutableData alloc] init]; + } + return self; +} + +-(id) lv_nativeObject{ + return self.data; +} + +static void releaseUserDataData(LVUserDataInfo* user){ + if( user && user->object ){ + LVData* data = CFBridgingRelease(user->object); + user->object = NULL; + if( data ){ + data.lv_userData = NULL; + data.lv_luaviewCore = nil; + data.data = nil; + } + } +} + +static int lvDataGC (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + releaseUserDataData(user); + return 0; +} + +static int lvNewData (lua_State *L) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVData class]]; + + LVData* data = [[c alloc] init:L]; + int argN = lua_gettop(L); + if( argN>0 ) { + if ( lua_type(L, 1)==LUA_TSTRING ) {// 支持字符串转 NSData + NSString* s = lv_paramString(L, 1); + const char* chars = s.UTF8String; + [data.data appendBytes:chars length:strlen(chars) ]; + } else { + int num = lua_tonumber(L, 1); + if( num>0 ){ + [data.data setLength:num]; + } + } + } + + { + NEW_USERDATA(userData, Data); + userData->object = CFBridgingRetain(data); + data.lv_userData = userData; + + luaL_getmetatable(L, META_TABLE_Data ); + lua_setmetatable(L, -2); + } + return 1; +} + ++(int) createDataObject:(lua_State *)L data:(NSData*) data{ + return [self createDataObject:L data1:data data2:nil]; +} + ++(int) createDataObject:(lua_State *)L data1:(NSData*) data1 data2:(NSData*) data2{ + LVData* lvdata = [[LVData alloc] init:L]; + if( data1 ) { + [lvdata.data setData:data1]; + } + if( data2 ) { + [lvdata.data appendData:data2]; + } + { + NEW_USERDATA(userData, Data); + userData->object = CFBridgingRetain(lvdata); + lvdata.lv_userData = userData; + + luaL_getmetatable(L, META_TABLE_Data ); + lua_setmetatable(L, -2); + } + return 1; +} + +static int __tostring (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVData* data = (__bridge LVData *)(user->object); + NSStringEncoding encode = NSUTF8StringEncoding; + if( lua_gettop(L)>=2 && lua_type(L, 2)==LUA_TNUMBER ) { + encode = lua_tonumber(L, 2); + } + NSString* s = [[NSString alloc] initWithData:data.data encoding:encode]; + if( s==nil ){ + NSStringEncoding gbkEncoding = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000); + s = [[NSString alloc] initWithData:data.data encoding:gbkEncoding]; + if ( s==nil ) { + s = [[NSString alloc] initWithFormat:@"{ UserDataType=data, length=%ld }",(long)data.data.length]; + } + } + lua_pushstring(L, s.UTF8String); + return 1; + } + return 0; +} + +static int __index (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + LVData* lvData = (__bridge LVData *)(user->object); + NSMutableData* data = lvData.data; + if( lvData && lvData.data){ + if( lua_type(L, 2)==LUA_TNUMBER ){ + int index = lua_tonumber(L, 2)-1; + if( index>=0 && indexobject); + NSMutableData* data = lvData.data; + if( lvData && lvData.data){ + if( lua_type(L, 2)==LUA_TNUMBER ){ + int index = lua_tonumber(L, 2)-1; + int value = lua_tonumber(L, 3); + if( index>=0 && indexobject); + LVData* lvData2 = (__bridge LVData *)(user2->object); + if( LVIsType(user1, Data) && LVIsType(user2, Data) && lvData1.data && lvData2.data ){ + [LVData createDataObject:L data1:lvData1.data data2:lvData2.data]; + return 1; + } + return 0; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewData globalName:globalName defaultName:@"Data"]; + + const struct luaL_Reg memberFunctions [] = { + // toJson 判断是否json + // toString 判断是否字符串 + // toTable + // append + + {"__index", __index }, + {"__newindex", __newindex }, + + {"__add", __add }, + + {"__gc", lvDataGC }, + + {"__tostring", __tostring }, + {NULL, NULL} + }; + + lv_createClassMetaTable(L, META_TABLE_Data); + + luaL_openlib(L, NULL, memberFunctions, 0); + return 0; +} + + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVDate.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVDate.h new file mode 100644 index 00000000..e9b31766 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVDate.h @@ -0,0 +1,24 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import + + +@interface LVDate : NSObject + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; + +@property(nonatomic,strong) NSDate* date; + +- (id) lv_nativeObject; // 返回native对象 + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVDate.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVDate.m new file mode 100644 index 00000000..0e9ebe55 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVDate.m @@ -0,0 +1,184 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVHeads.h" +#import "LVDate.h" +#import "LVHeads.h" + + + +@implementation LVDate + +-(id) init:(NSDate*) d{ + self = [super init]; + if( self ) { + self.date = d; + } + return self; +} + +-(id) lv_nativeObject{ + return self.date; +} + +static NSString* string09(NSString* s, NSUInteger len){ + NSMutableString* buf = [[NSMutableString alloc] init]; + for( int i=0; iobject = CFBridgingRetain(d); + + luaL_getmetatable(L, META_TABLE_Date ); + lua_setmetatable(L, -2); + } + } + return 1; /* new userdatum is already on the stack */ +} + + +static int __GC (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( LVIsType(user, Date) && user->object ){ + CFBridgingRelease(user->object); + user->object = NULL; + } + return 0; +} + +static int __tostring (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( LVIsType(user, Date) ){ + LVDate* date = (__bridge LVDate *)(user->object); + NSString* s = [NSString stringWithFormat:@"%@", date.date ]; + lua_pushstring(L, s.UTF8String); + return 1; + } + return 0; +} + +static int format (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + NSString* formatString = lv_paramString(L, 2); + if( LVIsType(user, Date) ){ + LVDate* date = (__bridge LVDate *)(user->object); + if( date ) { + NSString* ret = nil; + if( formatString ){ + NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; + [formatter setDateFormat:formatString]; + ret = [formatter stringFromDate:date.date]; + } else { + ret = [NSString stringWithFormat:@"%@", date.date ]; + } + lua_pushstring(L, ret.UTF8String); + return 1; + } + } + return 0; +} + +static int __sub (lua_State *L) { + LVUserDataInfo * user1 = (LVUserDataInfo *)lua_touserdata(L, 1); + LVUserDataInfo * user2 = (LVUserDataInfo *)lua_touserdata(L, 2); + if( LVIsType(user1, Date) && LVIsType(user2, Date) ){ + LVDate* date1 = (__bridge LVDate *)(user1->object); + LVDate* date2 = (__bridge LVDate *)(user2->object); + double time = [date1.date timeIntervalSinceDate:date2.date]; + lua_pushnumber(L, time); + return 1; + } + return 0; +} + +static int __eq (lua_State *L) { + LVUserDataInfo * user1 = (LVUserDataInfo *)lua_touserdata(L, 1); + LVUserDataInfo * user2 = (LVUserDataInfo *)lua_touserdata(L, 2); + if( LVIsType(user1, Date) && LVIsType(user2, Date) ){ + LVDate* date1 = (__bridge LVDate *)(user1->object); + LVDate* date2 = (__bridge LVDate *)(user2->object); + BOOL yes = [date1.date isEqualToDate:date2.date]; + lua_pushboolean(L, (yes?1:0) ); + return 1; + } + return 0; +} + +static int timeInterval (lua_State *L) { + LVUserDataInfo * user1 = (LVUserDataInfo *)lua_touserdata(L, 1); + if( LVIsType(user1, Date) ){ + LVDate* date1 = (__bridge LVDate *)(user1->object); + double time = [date1.date timeIntervalSince1970]; + lua_pushnumber(L, time); + return 1; + } + return 0; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewDate globalName:globalName defaultName:@"Date"]; + + const struct luaL_Reg memberFunctions [] = { + {"__gc", __GC }, + {"__sub", __sub}, + {"__eq", __eq}, + {"timeInterval", timeInterval }, + + {"__tostring", __tostring }, + {"format", format }, + {NULL, NULL} + }; + + lv_createClassMetaTable(L, META_TABLE_Date); + + luaL_openlib(L, NULL, memberFunctions, 0); + return 1; +} + + +@end + + + diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVDownloader.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVDownloader.h new file mode 100644 index 00000000..b696dd49 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVDownloader.h @@ -0,0 +1,25 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + + +@interface LVDownloader : NSObject + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; + +@property(nonatomic,copy) id luaObjRetainKey; + +-(id) init:(lua_State*) l; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +@end + diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVDownloader.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVDownloader.m new file mode 100644 index 00000000..dd7b2329 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVDownloader.m @@ -0,0 +1,146 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVDownloader.h" +#import "LVUtil.h" +#import "LVData.h" +#import "LView.h" +#import "LVHeads.h" + +@interface LVDownloader () +@property(nonatomic,strong) NSData* data; +@property(nonatomic,strong) id strongSelf; +@end + + +@implementation LVDownloader + + +static void releaseUserDataDownloader(LVUserDataInfo* user){ + if( user && user->object ){ + LVDownloader* downloader = CFBridgingRelease(user->object); + user->object = NULL; + if( downloader ){ + downloader.lv_userData = nil; + downloader.lv_luaviewCore = nil; + } + } +} + +-(void) dealloc{ + releaseUserDataDownloader(_lv_userData); +} + +-(id) lv_nativeObject{ + return nil; +} + +-(id) init:(lua_State*) l{ + self = [super init]; + if( self ){ + self.luaObjRetainKey = [[NSMutableString alloc] init]; + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + self.strongSelf = self; + } + return self; +} + + +#pragma -mark downloader +static int lvNewDownloader (lua_State *L) { + if( lua_gettop(L)>=2 ) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVDownloader class]]; + + LVDownloader* downloader = [[c alloc] init:L]; + NSString* url = lv_paramString(L, 1); // 1: url + //NSString* fileName = lvL_paramString(L, 2);// 2: fileName + // 3: callback + if( lua_type(L, -1) == LUA_TFUNCTION ) { + [LVUtil registryValue:L key:downloader stack:-1]; + } + + { + NEW_USERDATA(userData, Downloader); + userData->object = CFBridgingRetain(downloader); + downloader.lv_userData = userData; + + luaL_getmetatable(L, META_TABLE_Downloader ); + lua_setmetatable(L, -2); + + [LVUtil registryValue:L key:downloader.luaObjRetainKey stack:-1]; + } + [LVUtil download:url callback:^(NSData *data) { + downloader.data = data; + [downloader performSelectorOnMainThread:@selector(didFileLoaded) withObject:nil waitUntilDone:NO]; + }]; + return 1; + } else { + LVError(@"downloader( Callback==nil )!!!"); + } + return 0; +} + +-(void) didFileLoaded{ + lua_State* L = self.lv_luaviewCore.l; + if( L ){ + if( self.data ) { + [LVData createDataObject:L data:self.data]; + } else { + lua_pushnil(L); + } + [LVUtil call:L lightUserData:self key1:nil key2:nil nargs:1]; + + [LVUtil unregistry:L key:self.luaObjRetainKey]; + [LVUtil unregistry:L key:self]; + } + self.strongSelf = nil; +} + + static int __gc (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + releaseUserDataDownloader(user); + return 0; +} + +static int __tostring (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVDownloader* downloader = (__bridge LVDownloader *)(user->object); + NSString* s = [NSString stringWithFormat:@"LVUserDataDownloader: %@", downloader ]; + lua_pushstring(L, s.UTF8String); + return 1; + } + return 0; +} + +static int PathOfResource (lua_State *L) { + NSString* fileName = lv_paramString(L, 1); + LuaViewCore* lview = LV_LUASTATE_VIEW(L); + NSString* path = [lview.bundle resourcePathWithName:fileName]; + lua_pushstring(L, path.UTF8String); + return 1; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + lv_defineGlobalFunc("PathOfResource", PathOfResource, L); + + [LVUtil reg:L clas:self cfunc:lvNewDownloader globalName:globalName defaultName:@"Download"]; // __deprecated_msg("") + const struct luaL_Reg memberFunctions [] = { + {"__gc", __gc }, + + {"__tostring", __tostring }, + {NULL, NULL} + }; + + lv_createClassMetaTable(L, META_TABLE_Downloader); + + luaL_openlib(L, NULL, memberFunctions, 0); + return 1; +} + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVEmptyRefreshCollectionView.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVEmptyRefreshCollectionView.h new file mode 100644 index 00000000..c80eda03 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVEmptyRefreshCollectionView.h @@ -0,0 +1,17 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" +#import "UIScrollView+LuaView.h" +#import "LVCollectionView.h" + +// for IOS +@interface LVEmptyRefreshCollectionView : LVCollectionView + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVEmptyRefreshCollectionView.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVEmptyRefreshCollectionView.m new file mode 100644 index 00000000..8c28b925 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVEmptyRefreshCollectionView.m @@ -0,0 +1,45 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVEmptyRefreshCollectionView.h" +#import "LVRefreshHeader.h" + +@implementation LVEmptyRefreshCollectionView + +// 下拉刷新 +-(void) lv_initRefreshHeader{// 初始化下拉刷新功能 + LVRefreshHeader* refreshHeader = [[LVRefreshHeader alloc] init]; + self.lv_refresh_header = refreshHeader; + + __weak typeof(self) weakSelf = self; + refreshHeader.refreshingBlock = ^(){ + [weakSelf lv_refreshHeaderToRefresh]; + }; +} + +- (void) lv_hiddenRefreshHeader:(BOOL) hidden{ + self.lv_refresh_header.hidden = hidden; +} + +- (void) lv_beginRefreshing{// 进入刷新状态 + [self.lv_refresh_header beginRefreshing]; +} + +- (void) lv_endRefreshing{// 结束刷新状态 + [self.lv_refresh_header endRefreshing]; +} + +- (BOOL) lv_isRefreshing{// 是否正在刷新 + return self.lv_refresh_header.isRefreshing; +} + ++(NSString*) globalName{ + return @"EmptyRefreshCollectionView"; +} + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVEvent.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVEvent.h new file mode 100644 index 00000000..e4944422 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVEvent.h @@ -0,0 +1,35 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import +#import "LVHeads.h" + +#define LVTouchEventType_DOWN 1010 +#define LVTouchEventType_MOVE 1020 +#define LVTouchEventType_CANCEL 1030 +#define LVTouchEventType_UP 1040 + +@interface LVEvent : NSObject + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; + +@property(nonatomic,weak) UIEvent* event; + +@property(nonatomic,assign) NSInteger eventType; + +@property(nonatomic,weak) UIGestureRecognizer* gesture; + +-(id) init:(lua_State *)l gesture:(UIGestureRecognizer*) gesture; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + ++(LVEvent*) createLuaEvent:(lua_State *)L event:(UIEvent*) event gesture:(UIGestureRecognizer*) gesture; + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVEvent.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVEvent.m new file mode 100644 index 00000000..1e665a9c --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVEvent.m @@ -0,0 +1,229 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVEvent.h" + +@interface LVEvent () +@property(nonatomic,strong) NSArray * touches; +@property(nonatomic,assign) CGPoint point; +@property(nonatomic,strong) UITouch* touch; +@end + +@implementation LVEvent + +-(id) init:(lua_State *)l gesture:(UIGestureRecognizer*) gesture{ + self = [super init]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + self.gesture = gesture; + } + return self; +} + +-(void) setEvent:(UIEvent *)event{ + _event = event; + self.touches = event.allTouches.allObjects; + self.touch = self.touches.firstObject; + self.point = [self.touch locationInView:self.gesture.view]; +} + +-(id) lv_nativeObject{ + return self; +} + +static void releaseEventUserData(LVUserDataInfo* user){ + if( user && user->object ){ + LVEvent* lvEvent = CFBridgingRelease(user->object); + user->object = NULL; + if( lvEvent ){ + lvEvent.lv_userData = NULL; + lvEvent.lv_luaviewCore = nil; + lvEvent.event = nil; + lvEvent.touches = nil; + } + } +} + +static int lvEventGC (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + releaseEventUserData(user); + return 0; +} + +static int lvNewEvent (lua_State *L) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVEvent class]]; + + LVEvent* lvEvent = [[c alloc] init:L gesture:nil]; + + { + NEW_USERDATA(userData, Event); + userData->object = CFBridgingRetain(lvEvent); + lvEvent.lv_userData = userData; + + luaL_getmetatable(L, META_TABLE_Event ); + lua_setmetatable(L, -2); + } + return 1; +} + ++(LVEvent*) createLuaEvent:(lua_State *)L event:(UIEvent*) event gesture:(UIGestureRecognizer*) gesture{ + LVEvent* lvEvent = [[LVEvent alloc] init:L gesture:gesture]; + lvEvent.event = event; + { + NEW_USERDATA(userData, Event); + userData->object = CFBridgingRetain(lvEvent); + lvEvent.lv_userData = userData; + + luaL_getmetatable(L, META_TABLE_Event ); + lua_setmetatable(L, -2); + } + return lvEvent; +} + +static int nativeObj (lua_State *L) { + LVUserDataInfo * userData = (LVUserDataInfo *)lua_touserdata(L, 1); + if( userData ){ + LVEvent* lvEvent = (__bridge LVEvent *)(userData->object); + if( lvEvent ){ + id object = lvEvent.event; + lv_pushNativeObjectWithBox(L, object); + return 1; + } + } + return 0; +} + +static int action (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVEvent* lvEvent = (__bridge LVEvent *)(user->object); + if( lvEvent.eventType ) { + lua_pushnumber(L, lvEvent.eventType ); + } else { + UIEventType type = lvEvent.event.type; + lua_pushnumber(L, type ); + } + return 1; + } + return 0; +} + +static int pointer (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVEvent* lvEvent = (__bridge LVEvent *)(user->object); + CGPoint point = lvEvent.point; + NSDictionary* dic = @{ + @"x":@(point.x), + @"y":@(point.y) + }; + lv_pushNativeObject(L, dic ); + return 1; + } + return 0; +} + +static int x (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVEvent* lvEvent = (__bridge LVEvent *)(user->object); + CGPoint point = lvEvent.point; + lua_pushnumber(L, point.x ); + return 1; + } + return 0; +} + +static int y (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVEvent* lvEvent = (__bridge LVEvent *)(user->object); + CGPoint point = lvEvent.point; + lua_pushnumber(L, point.y ); + return 1; + } + return 0; +} + +static int event_id (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVEvent* lvEvent = (__bridge LVEvent *)(user->object); + lua_pushnumber(L, lvEvent.touch.timestamp ); + return 1; + } + return 0; +} + +static int __index (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + if ( lua_type(L, 2)==LUA_TSTRING ){ + lua_checkstack(L, 4); + lua_settop(L, 2); + luaL_getmetatable(L, META_TABLE_EventFunc ); + lua_pushvalue(L, 2); + lua_gettable(L, -2); + lua_remove(L, -2); + lua_remove(L, -2); + lua_CFunction cfunc = lua_tocfunction(L, -1); + if( cfunc ) { + lua_settop(L, 1); + return cfunc(L); + } + } + } + return 0; /* new userdatum is already on the stack */ +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewEvent globalName:globalName defaultName:@"Event"]; + + { + const struct luaL_Reg memberFunctions [] = { + {"__gc", lvEventGC }, + {"nativeObj", nativeObj}, + {"__index", __index }, + + {NULL, NULL} + }; + + lv_createClassMetaTable(L, META_TABLE_Event); + luaL_openlib(L, NULL, memberFunctions, 0); + } + { + + const struct luaL_Reg memberFunctions [] = { + {"id", event_id}, + {"action", action}, + {"pointer", pointer}, + {"x", x}, + {"y", y}, + {NULL, NULL} + }; + + lv_createClassMetaTable(L, META_TABLE_EventFunc); + luaL_openlib(L, NULL, memberFunctions, 0); + } + { + + NSDictionary* v = nil; + v = @{ + @"DOWN":@(LVTouchEventType_DOWN), + @"MOVE":@(LVTouchEventType_MOVE), + @"OUTSIDE":@(UIEventTypeRemoteControl), + @"PRESSES":@(UIEventTypePresses),// for IOS + @"UP":@(LVTouchEventType_UP), + @"CANCEL":@(LVTouchEventType_CANCEL), + }; + [LVUtil defineGlobal:@"TouchEvent" value:v L:L]; + } + return 0; +} + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVExGlobalFunc.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVExGlobalFunc.h new file mode 100644 index 00000000..b1e5feb6 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVExGlobalFunc.h @@ -0,0 +1,20 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import +#import "LVHeads.h" +#import "LView.h" + +@interface LVExGlobalFunc : NSObject + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + ++(void) registry:(lua_State*)L window:(UIView*)window; + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVExGlobalFunc.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVExGlobalFunc.m new file mode 100644 index 00000000..94018036 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVExGlobalFunc.m @@ -0,0 +1,187 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVExGlobalFunc.h" +#import "LVUtil.h" +#import "LVHeads.h" +#import "LVNativeObjBox.h" +#import "LVDebuger.h" + + +//------------------------------------------------------------------------ +@implementation LVExGlobalFunc + +static int lv_print (lua_State *L) { +#ifdef DEBUG + int n = lua_gettop(L); /* number of arguments */ + int i; + NSMutableString* buf = [[NSMutableString alloc] init]; + lua_getglobal(L, "tostring"); + for (i=1; i<=n; i++) { + const char *s = NULL; + lua_pushvalue(L, -1); /* function to be called */ + lua_pushvalue(L, i); /* value to print */ + lua_call(L, 1, 1); + s = lua_tostring(L, -1); /* get result */ + if (s == NULL) + return luaL_error(L, LUA_QL("tostring") " must return a string to " LUA_QL("print")); + if ( i>1 ) { + [buf appendString:@"\t"]; + } + NSString* str = [NSString stringWithUTF8String:s]; + [buf appendFormat:@"%@",str]; + lua_pop(L, 1); /* pop result */ + } + NSLog(@"%@",buf); + [buf appendString:@"\n"]; + lv_printToServer(L, buf.UTF8String, 0); +#endif + return 0; +} + +#pragma -mark registryApi +// 全局静态常量 和 静态方法 ++(void) registryStaticMethod:(lua_State *)L lView:(LuaViewCore *)lView{ + lv_defineGlobalFunc("print", lv_print, L); + + lv_defineGlobalFunc("loadJson", loadJson, L); + + lv_defineGlobalFunc("Unicode", unicode, L); + + // 替换pakcage.loaders中的loader_lv + lua_getglobal(L, LUA_LOADLIBNAME); + lua_getfield(L, 1, "loaders"); + if (!lua_istable(L, -1)) { + return; + } + + lua_pushnumber(L, 2); + lua_pushcfunction(L, loaderForLuaView); + lua_settable(L, -3); +} + +// 注册函数 ++(void) registryApi:(lua_State*)L lView:(LuaViewCore*)lView{ + + + return; +} + +// 注册系统对象 window ++(void) registry:(lua_State*)L window:(UIView*)window{ + NEW_USERDATA(userData, View); + userData->object = CFBridgingRetain(window); + window.lv_userData = userData; + window.lv_luaviewCore = LV_LUASTATE_VIEW(L); + userData->isWindow = 1; + + luaL_getmetatable(L, META_TABLE_LuaView ); + lua_setmetatable(L, -2); + + lua_setglobal(L, "window"); +} +//------------------------------------------------------------------------------------ + +static int loadJson (lua_State *L) { + NSString* json = lv_paramString(L, 1); + if( json ){ + json = [NSString stringWithFormat:@"return %@",json]; + luaL_loadstring(L, json.UTF8String); + if( lua_type(L, -1) == LUA_TFUNCTION ) { + int errorCode = lua_pcall( L, 0, 1, 0); + if( errorCode == 0 ){ + return 1; + } else { + LVError( @"loadJson : %s", lua_tostring(L, -1) ); + } + } else { + LVError( @"loadJson : %s", lua_tostring(L, -1) ); + } + } + return 0; /* number of results */ +} + +static int unicode(lua_State *L) { + int num = lua_gettop(L); + NSMutableString* buf = [[NSMutableString alloc] init]; + for( int i=1; i<=num; i++ ) { + if( lua_type(L, i) == LUA_TNUMBER ) { + unichar c = lua_tonumber(L, i); + [buf appendFormat:@"%C",c]; + } else { + break; + } + } + if( buf.length>0 ) { + lua_pushstring(L, buf.UTF8String); + return 1; + } + return 0; /* number of results */ +} + +static int loaderForLuaView (lua_State *L) { + static NSString *pathFormats[] = { @"%@.%@", @"%@/init.%@" }; + + NSString* moduleName = lv_paramString(L, 1); + if( moduleName ){ + // submodule + moduleName = [moduleName stringByReplacingOccurrencesOfString:@"." withString:@"/"]; + + LuaViewCore* lview = LV_LUASTATE_VIEW(L); + if( lview ) { + __block NSString *fullName = nil, *format = nil, *ext = nil; + BOOL(^findFile)() = ^BOOL() { // set fullName and return YES if found + NSString *name = [NSString stringWithFormat:format, moduleName, ext]; + + if( [lview.bundle scriptPathWithName:name] ) { + fullName = name; + return YES; + } else { + return NO; + } + }; + + for( int i = 0; i < sizeof(pathFormats) / sizeof(pathFormats[0]); ++i ) { + format = pathFormats[i]; + + if( lview.runInSignModel ) { + ext = LVScriptExts[LVSignedScriptExtIndex]; + if (findFile()) { + return [lview loadSignFile:fullName] == nil ? 1 : 0; + } + } + + ext = LVScriptExts[!LVSignedScriptExtIndex]; + if (findFile()) { + return [lview loadFile:fullName] == nil ? 1 : 0; + } + } + } + } + + // not found + return 0; +} + + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + LuaViewCore* lView = LV_LUASTATE_VIEW(L); + // 注册静态全局方法和常量 + [LVExGlobalFunc registryStaticMethod:L lView:lView]; + + //外链注册器 + [LVNativeObjBox lvClassDefine:L globalName:nil]; + // 调试 + [LVDebuger lvClassDefine:L globalName:nil]; + //清理栈 + lua_settop(L, 0); + return 0; +} + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVFile.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVFile.h new file mode 100644 index 00000000..3f1cc393 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVFile.h @@ -0,0 +1,15 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ +#import +#import "LVHeads.h" + +@interface LVFile : NSObject + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVFile.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVFile.m new file mode 100644 index 00000000..ac9414fe --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVFile.m @@ -0,0 +1,134 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVFile.h" +#import "LVHeads.h" +#import "LVData.h" +#import "LView.h" +#import "LVHeads.h" + +@implementation LVFile + +static void saveCallback(lua_State *L, int callbackIndex, NSString* fileName, int errorInfo ) { + if( callbackIndex ) { + lua_checkstack32(L); + lua_pushboolean(L, errorInfo); + lua_pushvalue(L,callbackIndex); + lv_runFunctionWithArgs(L, 1, 0); + } +} + +static BOOL readCallback(lua_State *L, int callbackIndex, NSString* fileName, NSData* data) { + if( callbackIndex ) { + lua_checkstack32(L); + [LVData createDataObject:L data:data]; + lua_pushvalue(L,callbackIndex); + lv_runFunctionWithArgs(L, 1, 0); + return YES; + } + return NO; +} + +static int file_save (lua_State *L) { + int num = lua_gettop(L); + if( num>=2 ) { + LVUserDataInfo * userData = NULL; + NSString* fileName = nil; + int callbackIndex = 0; + for( int i=1; i<=num; i++ ) { + if( lua_type(L, i)==LUA_TUSERDATA && userData==nil ) { + userData = (LVUserDataInfo *)lua_touserdata(L, i); + } + if( lua_type(L, i)==LUA_TSTRING && fileName==nil ) { + fileName = lv_paramString(L, i); + } + if( lua_type(L,i)==LUA_TFUNCTION ) { + callbackIndex = i; + } + } + if ( fileName && userData ) { + LVData* lvData1 = (__bridge LVData *)(userData->object); + if( LVIsType(userData, Data) && lvData1.data){ + if( [LVUtil saveData:lvData1.data toFile:[LVUtil PathForCachesResource:fileName]] ){ + saveCallback(L, callbackIndex, fileName, YES); + lua_pushboolean(L, 1); + return 1; + } else { + saveCallback(L, callbackIndex, fileName, NO); + } + } + } + } + lua_pushboolean(L, 0); + return 1; +} + +static int file_read(lua_State *L){ + int num = lua_gettop(L); + if( L && num>=1 ){ + NSString* fileName = nil; + int callbackIndex = 0; + for( int i=1; i<=num; i++ ) { + if( lua_type(L, i)==LUA_TSTRING && fileName==nil ) { + fileName = lv_paramString(L, i); + } + if( lua_type(L,i)==LUA_TFUNCTION ) { + callbackIndex = i; + } + } + if ( fileName ) { + LuaViewCore* lview = LV_LUASTATE_VIEW(L); + NSData* data = [lview.bundle resourceWithName:fileName]; + if( data ){ + if( readCallback(L, callbackIndex, fileName, data) ){ + } else { + [LVData createDataObject:L data:data]; + } + return 1; + } else { + readCallback(L, callbackIndex, fileName, nil); + } + } + } + return 0; +} + +static int file_exist(lua_State *L){ + if( L && lua_gettop(L)>=1 ){ + NSString* fileName = lv_paramString(L, -1); + LuaViewCore* lview = LV_LUASTATE_VIEW(L); + if( [lview.bundle resourcePathWithName:fileName] ){ + lua_pushboolean(L, 1); + return 1; + } + } + lua_pushboolean(L, 0); + return 1; +} + +static int file_path (lua_State *L) { + NSString* fileName = lv_paramString(L, -1); + LuaViewCore* lview = LV_LUASTATE_VIEW(L); + NSString* path = [lview.bundle resourcePathWithName:fileName]; + lua_pushstring(L, path.UTF8String); + return 1; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + const struct luaL_Reg function [] = { + {"save", file_save}, + {"read", file_read}, + {"exist", file_exist}, + {"path", file_path}, + {NULL, NULL} + }; + luaL_openlib(L, "File", function, 0); + return 0; +} + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVFlowLayout.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVFlowLayout.h new file mode 100644 index 00000000..90f06ef5 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVFlowLayout.h @@ -0,0 +1,19 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import + +@interface LVFlowLayout : UICollectionViewFlowLayout + +-(void) resetPinnedDic; +-(void) addPinnedIndexPath:(NSIndexPath*)indexPath; +-(void) delPinnedIndexPath:(NSIndexPath*)indexPath; +-(BOOL) isPinned:(NSIndexPath*)indexPath; +-(BOOL) pinnedDicIsNil; + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVFlowLayout.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVFlowLayout.m new file mode 100644 index 00000000..43fb603e --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVFlowLayout.m @@ -0,0 +1,111 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVFlowLayout.h" + +@interface LVFlowLayout () +@property(nonatomic, strong) NSMutableDictionary* pinnedDic; +@end + +@implementation LVFlowLayout + +-(id)init +{ + self = [super init]; + if ( self ){ + } + return self; +} + +- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect +{ + NSMutableArray *superLayoutAttArray = [[super layoutAttributesForElementsInRect:rect] mutableCopy]; + NSArray* keys = self.pinnedDic.allKeys; + // 排序 + keys = [keys sortedArrayUsingComparator:^NSComparisonResult(NSIndexPath* obj1, NSIndexPath* obj2) { + return [obj1 compare:obj2]; + }]; + + UICollectionViewLayoutAttributes* prevAtt = nil; + NSInteger pinnedTimes = 0; + for( NSInteger i=((NSInteger)keys.count)-1; i>=0; i-- ) { + NSIndexPath* indexPath = keys[i]; + UICollectionViewLayoutAttributes* a = [self layoutAttributesForItemAtIndexPath:indexPath]; + if( a ) { + CGRect frame = a.frame; + CGFloat minY = self.collectionView.contentOffset.y; + // 浮层:不能小于屏幕offset + if( frame.origin.y < minY ) { + frame.origin.y = minY; + a.frame = frame; + a.zIndex = 10 + i; + pinnedTimes ++; + + if( prevAtt ) { + // 但是浮层不能盖住上一个浮层 + CGFloat maxY = prevAtt.frame.origin.y - frame.size.height; + if( frame.origin.y>maxY ) { + frame.origin.y = maxY; + a.frame = frame; + a.zIndex = 10 + i; + } + } + } + [superLayoutAttArray addObject:a]; + prevAtt = a; + if( pinnedTimes > 1 ) { + // 这两行一定要有!!!!原因还有待确认@城西 + a.alpha = 0; + a.zIndex = -1; + break; + } else { + a.alpha = 1; + } + } + } + return superLayoutAttArray; +} + +-(BOOL) shouldInvalidateLayoutForBoundsChange:(CGRect)newBound +{ + return self.pinnedDic!=nil; +} + +-(void) resetPinnedDic{ + self.pinnedDic = [[NSMutableDictionary alloc] initWithCapacity:8]; +} + +-(void) addPinnedIndexPath:(NSIndexPath*)indexPath { + if( indexPath ) { + if( self.pinnedDic==nil ) { + [self resetPinnedDic]; + } + self.pinnedDic[indexPath] = @(YES); + } +} + +-(void) delPinnedIndexPath:(NSIndexPath*)indexPath{ + if( indexPath ) { + [self.pinnedDic removeObjectForKey:indexPath]; + } +} + +-(BOOL) isPinned:(NSIndexPath*)indexPath{ + if( indexPath ) { + return (self.pinnedDic[indexPath]!=nil); + } + return NO; +} + +-(BOOL) pinnedDicIsNil{ + return self.pinnedDic==nil; +} + +@end + + diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVGesture.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVGesture.h new file mode 100644 index 00000000..020aa3cf --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVGesture.h @@ -0,0 +1,33 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" +#import "NSObject+LuaView.h" + +@class LVGesture; + +typedef void(^LVGestureOnTouchEventCallback)(LVGesture* gesture, int argN); + +@interface LVGesture : UIGestureRecognizer + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; + +@property(nonatomic,copy) LVGestureOnTouchEventCallback onTouchEventCallback; + +-(id) init:(lua_State*) l; + ++(const luaL_Reg*) baseMemberFunctions; + ++(void) releaseUD:(LVUserDataInfo *) user; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVGesture.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVGesture.m new file mode 100644 index 00000000..76f1eee1 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVGesture.m @@ -0,0 +1,228 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVGesture.h" +#import "LView.h" +#import +#import "LVEvent.h" +#import "LVHeads.h" + +@implementation LVGesture + +-(id) init:(lua_State*) l{ + self = [super initWithTarget:self action:@selector(handleGesture:)]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + self.delegate = self; + } + return self; +} + +-(void) handleGesture:(LVGesture*)sender { + [self handleGesture:sender event:nil eventType:0]; +} + +-(void) handleGesture:(LVGesture*)sender event:(UIEvent*) event eventType:(NSInteger) eventType{ + lua_State* l = self.lv_luaviewCore.l; + if ( l ){ + lua_settop(l, 0); + lua_checkstack32(l); + + if( self.onTouchEventCallback ) { + LVEvent* lvEvent = nil; + lvEvent = [LVEvent createLuaEvent:l event:event gesture:self]; + lvEvent.eventType = eventType; + self.onTouchEventCallback(self,1); + lvEvent.event = nil; + } else { + lv_pushUserdata(l,self.lv_userData); + } + [LVUtil call:l lightUserData:self key1:"callback" key2:NULL nargs:1]; + } +} + +- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ + [super touchesBegan:touches withEvent:event]; + [self handleGesture:self event:event eventType:LVTouchEventType_DOWN]; +} + +- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{ + [super touchesMoved:touches withEvent:event]; + [self handleGesture:self event:event eventType:LVTouchEventType_MOVE]; +} + +- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{ + [super touchesEnded:touches withEvent:event]; + [self handleGesture:self event:event eventType:LVTouchEventType_MOVE]; + [self handleGesture:self event:event eventType:LVTouchEventType_UP]; + +} + +- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{ + [super touchesCancelled:touches withEvent:event]; + [self handleGesture:self event:event eventType:LVTouchEventType_CANCEL]; +} + + +static void releaseUserData(LVUserDataInfo * user){ + if( user && user->object ){ + UIGestureRecognizer* gesture = CFBridgingRelease(user->object); + user->object = NULL; + if( gesture ){ + gesture.lv_luaviewCore = nil; + gesture.lv_userData = NULL; + } + } +} + +static int __GC (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + releaseUserData(user); + return 0; +} + + +static int __tostring (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIGestureRecognizer* gesture = (__bridge UIGestureRecognizer *)(user->object); + NSString* s = [NSString stringWithFormat:@"LVUserDataGesture: %@", gesture ]; + lua_pushstring(L, s.UTF8String); + return 1; + } + return 0; +} + +static int location (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIGestureRecognizer* gesture = (__bridge UIGestureRecognizer *)(user->object); + CGPoint p = [gesture locationInView:gesture.view]; + lua_pushnumber(L, p.x); + lua_pushnumber(L, p.y); + return 2; + } + return 0; +} + +static int state (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIGestureRecognizer* gesture = (__bridge UIGestureRecognizer *)(user->object); + NSInteger state = gesture.state; + lua_pushnumber(L, state); + return 1; + } + return 0; +} + +static int nativeGesture (lua_State *L) { + LVUserDataInfo * userData = (LVUserDataInfo *)lua_touserdata(L, 1); + if( userData ){ + UIGestureRecognizer* gesture = (__bridge UIGestureRecognizer *)(userData->object); + if( gesture && [gesture isKindOfClass:[UIGestureRecognizer class]] ){ + lv_pushNativeObjectWithBox(L, gesture); + return 1; + } + } + return 0; +} + +static const struct luaL_Reg baseMemberFunctions [] = { + {"nativeGesture", nativeGesture }, + + {"location", location }, + {"state", state }, + {"__gc", __GC }, + {"__tostring", __tostring }, + {NULL, NULL} +}; + ++(const luaL_Reg*) baseMemberFunctions{ + return baseMemberFunctions; +} + ++(void) releaseUD:(LVUserDataInfo *) user{ + releaseUserData(user); +} + +static int lvNewGesture (lua_State *L) { + { + Class c = [LVUtil upvalueClass:L defaultClass:[LVGesture class]]; + + LVGesture* gesture = [[c alloc] init:L]; + + if( lua_type(L, 1) != LUA_TNIL ) { + [LVUtil registryValue:L key:gesture stack:1]; + } + + { + NEW_USERDATA(userData, Gesture); + gesture.lv_userData = userData; + userData->object = CFBridgingRetain(gesture); + + luaL_getmetatable(L, META_TABLE_Gesture ); + lua_setmetatable(L, -2); + } + } + return 1; /* new userdatum is already on the stack */ +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + + [LVUtil reg:L clas:self cfunc:lvNewGesture globalName:globalName defaultName:@"Gesture"]; + + lv_createClassMetaTable(L, META_TABLE_Gesture); + + luaL_openlib(L, NULL, [LVGesture baseMemberFunctions], 0); + lua_settop(L, 0); + { + NSDictionary* v = nil; + v = @{ + @"POSSIBLE":@(UIGestureRecognizerStatePossible), + @"BEGIN":@(UIGestureRecognizerStateBegan), + @"CHANGED":@(UIGestureRecognizerStateChanged), + @"END":@(UIGestureRecognizerStateEnded), + @"CANCEL":@(UIGestureRecognizerStateCancelled), + @"FAILED":@(UIGestureRecognizerStateFailed), + }; + [LVUtil defineGlobal:@"GestureState" value:v L:L]; + } + + return 0; +} + +// delegate + +- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{ + if( gestureRecognizer ==self ) { + return YES; + } + return NO; +} + +- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{ + return YES; +} + +- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{ + if( gestureRecognizer ==self ) { + return YES; + } + return NO; +} + +- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceivePress:(UIPress *)press{ + if( gestureRecognizer ==self ) { + return YES; + } + return NO; +} + + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVGrammarChanger.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVGrammarChanger.h new file mode 100644 index 00000000..de45ed03 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVGrammarChanger.h @@ -0,0 +1,17 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import + + + +extern NSData* lv_toStandLuaGrammar(NSData* data); + + +@interface LVGrammarChanger : NSObject +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVGrammarChanger.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVGrammarChanger.m new file mode 100644 index 00000000..b046d1bc --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVGrammarChanger.m @@ -0,0 +1,209 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVGrammarChanger.h" + +@implementation LVGrammarChanger + +@end + + + +// ‘.’ 和‘:’ 相互转化代码 +#define LV_TYPE_WORD_FIRST (1) +#define LV_TYPE_WORD_SECOND (2) +#define LV_TYPE_NUMBER (4) +#define LV_TYPE_CHAR_SPACE (8) +#define LV_TYPE_CHAR_NOTES (16) +#define LV_TYPE_CHAR_POINT (32) + +static int g_charTypes[256] = {0}; +static void charTypesInited(){ + g_charTypes['_'] = LV_TYPE_WORD_FIRST|LV_TYPE_WORD_SECOND; + for( char c = 'a'; c<='z'; c++ ) { + g_charTypes[c] = LV_TYPE_WORD_FIRST|LV_TYPE_WORD_SECOND; + } + for( char c = 'A'; c<='Z'; c++ ) { + g_charTypes[c] = LV_TYPE_WORD_FIRST|LV_TYPE_WORD_SECOND; + } + for( char c = '0'; c<='9'; c++ ) { + g_charTypes[c] = LV_TYPE_NUMBER | LV_TYPE_WORD_SECOND; + } + g_charTypes[' '] = LV_TYPE_CHAR_SPACE; + g_charTypes['\n'] = LV_TYPE_CHAR_SPACE; + g_charTypes['.'] = LV_TYPE_CHAR_POINT; + g_charTypes[':'] = LV_TYPE_CHAR_POINT; + g_charTypes['-'] = LV_TYPE_CHAR_NOTES; +} + +inline static NSInteger skipNotes(const unsigned char* cs, NSInteger i, NSInteger length){ + for( int m=0 ; m<2 && i0 ) { + NSInteger length = data.length; + unsigned char* cs = malloc(length+64); + memset(cs, 0, length+64); + [data getBytes:cs length:length]; + for ( NSInteger i=0; ii ) { + i = i2; + i = skipSpace(cs, i, length); + if( checkNextChar(cs, i, length, '(') || checkNextChar(cs, i, length, '{') ) { + unsigned char tempChar = cs[i0]; + if( (char)tempChar=='.' ) { + cs[i0] = ':'; + } else { + cs[i0] = '.'; + } + break; + } + } + } + break; + } + + default: + i = skipOther(cs, i, length); + break; + } + + } + NSData* newData = [[NSData alloc] initWithBytes:cs length:length]; + free(cs); + return newData; + } + return nil; +} diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVHeads.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVHeads.h new file mode 100644 index 00000000..8215e6e9 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVHeads.h @@ -0,0 +1,226 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#ifndef JU_LVHeads_h +#define JU_LVHeads_h +//-------------------------------------------------------------------------------- + +#import + +#import "lua.h" +#import "lauxlib.h" +#import "lualib.h" +#import "lstate.h" +#import "lgc.h" +#import "lapi.h" + +/** + * the index of signed scripts' extionsion(@"lv") in LVScriptExts[] + */ +extern const int LVSignedScriptExtIndex; + +/** + * supported script extensions: { @"lv", @"lua" } + */ +extern NSString * const LVScriptExts[2]; + +#import "LVUtil.h" +#import "LVGrammarChanger.h" +//-------------------------------------------------------------------------------- +#define LV_ALIGN_LEFT (1) +#define LV_ALIGN_H_CENTER (2) +#define LV_ALIGN_RIGHT (4) + +#define LV_ALIGN_TOP (8) +#define LV_ALIGN_V_CENTER (16) +#define LV_ALIGN_BOTTOM (32) + +//------------------------------ +#define LVReleaseAndNull( a ) if(a) { CFRelease(a); a = NULL; } +//------------------------------ + + +#define USERDATA_KEY_DELEGATE 1 +#define USERDATA_KEY_CALLBACK 2 +#define USERDATA_FLEX_DELEGATE 8 + +//---------------创建用户数据------------------------------------------------------- +#define NEW_USERDATA(var, typeName) \ + LVUserDataInfo* var = ( (LVUserDataInfo*)lua_newuserdata( L, sizeof(LVUserDataInfo)) ); \ + lv_createUDataLuatable(L,-1);\ + var->type = LVType_##typeName; \ + var->isWindow = 0; \ +// + + +//----------------用户数据的类型检查-----i-------------------------------------------- +#define LVIsType( user,T) (user && user->type==LVType_##T) + +//----------------用户数据类型 ID--------------------------------------------------- + +extern const char* LVType_View; +extern const char* LVType_Data; +extern const char* LVType_Date; +extern const char* LVType_Http; +extern const char* LVType_Timer; +extern const char* LVType_Transform3D; +extern const char* LVType_Animator; +extern const char* LVType_Gesture; +extern const char* LVType_Downloader; +extern const char* LVType_AudioPlayer; +extern const char* LVType_StyledString; +extern const char* LVType_NativeObject; +extern const char* LVType_Struct; +extern const char* LVType_Canvas; +extern const char* LVType_Event; + + +//----------------View的用户数据结构------------------------------------------------ +typedef struct _LVUserDataInfo { + const char* type;// 用户类型 + const void* object;// 真实的用户对象 + int isWindow; +} LVUserDataInfo; + +//-------------------------------------------------------------------------------- +@class LuaViewCore; +@protocol LVProtocal +@required +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; +- (id) lv_nativeObject; // 返回native对象 +@end + +@protocol LVClassProtocal +@required ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +@end + + +//-----------------------metatable------------------------------------------------ +#define META_TABLE_UIButton "UI.Button" +#define META_TABLE_UIScrollView "UI.ScrollView" +#define META_TABLE_UIView "UI.View" +#define META_TABLE_LuaView "UI.LuaView" +#define META_TABLE_CustomPanel "UI.CustomPanel" +#define META_TABLE_CustomView "UI.CustomView" +#define META_TABLE_Canvas "UI.Canvas" +#define META_TABLE_Event "UI.Event" +#define META_TABLE_EventFunc "UI.EventFunc" +#define META_TABLE_UIViewNewIndex "UI.View.NewIndex" +#define META_TABLE_PagerIndicator "UI.PagerIndicator" +#define META_TABLE_LoadingIndicator "UI.LoadingIndicator" +#define META_TABLE_UIImageView "UI.ImageView" +#define META_TABLE_UIWebView "UI.WebView" +#define META_TABLE_UILabel "UI.Label" +#define META_TABLE_UITextField "UI.TextField" +#define META_TABLE_UITableView "UI.TableView" +#define META_TABLE_UITableViewCell "UI.TableView.Cell" +#define META_TABLE_UICollectionView "UI.CollectionView" +#define META_TABLE_UICollectionViewCell "UI.CollectionView.Cell" +#define META_TABLE_UIPageView "UI.PagerView" +#define META_TABLE_UIAlertView "UI.AlertView" +#define META_TABLE_Transform3D "UI.Transfrom3D" +#define META_TABLE_Animator "UI.Animator" + +#define META_TABLE_Timer "LV.Timer" +#define META_TABLE_Http "LV.Http" +#define META_TABLE_Gesture "LV.Gesture" +#define META_TABLE_PanGesture "LV.Pan.Gesturer" +#define META_TABLE_TapGesture "LV.Tap.Gesture" +#define META_TABLE_PinchGesture "LV.Pinch.Gesture" +#define META_TABLE_RotaionGesture "LV.Rotaion.Gesture" +#define META_TABLE_SwipeGesture "LV.Swipe.Gesture" +#define META_TABLE_LongPressGesture "LV.LongPress.Gesture" +#define META_TABLE_Date "LV.Date" +#define META_TABLE_Data "LV.Data" +#define META_TABLE_Struct "LV.Struct" +#define META_TABLE_Downloader "LV.Downloader" +#define META_TABLE_AudioPlayer "LV.AudioPlayer" +#define META_TABLE_AttributedString "LV.AttributedString" +#define META_TABLE_NativeObject "LV.nativeObjBox" +#define META_TABLE_System "LV.System" + +#define STR_CALLBACK "Callback" +#define STR_ON_LAYOUT "onLayout" +#define STR_ON_CLICK "onClick" +#define STR_ON_DRAW "onDraw" +#define STR_ON_TOUCH "onTouch" +#define STR_onPageStarted "onPageStarted" +#define STR_onPageFinished "onPageFinished" +#define STR_onReceivedError "onReceivedError" + +// lua对象 -> NSString +NSString* lv_paramString(lua_State* L, int idx ); + +// run +NSString* lv_runFunction(lua_State* l); +NSString* lv_runFunctionWithArgs(lua_State* l, int nargs, int nret); + + + +//-------------------------------------------------------------------------------- +@interface LVHeads : NSObject +@end + + +typedef enum:int{ + LVTypeID_NONE = 0, + LVTypeID_void, + LVTypeID_BOOL, + LVTypeID_bool, + LVTypeID_char, + LVTypeID_unsignedchar, + LVTypeID_short, + LVTypeID_unsignedshort, + LVTypeID_int, + LVTypeID_unsignedint, + LVTypeID_NSInteger, + LVTypeID_NSUInteger, + LVTypeID_longlong, + LVTypeID_unsigedlonglong, + LVTypeID_float, + LVTypeID_CGFloat, + LVTypeID_double, + LVTypeID_charP, + LVTypeID_voidP, + LVTypeID_id, + LVTypeID_Class, + LVTypeID_idP, + LVTypeID_struct, +}LVTypeIDEnum; + + +LVTypeIDEnum lua_typeID(const char* type); + +#define isNormalRect(r) ( !( isnan(r.origin.x) || isnan(r.origin.y) || isnan(r.size.width) || isnan(r.size.height) ) ) +#define isNormalSize(s) ( !( isnan(s.width) || isnan(s.height) ) ) +#define isNormalPoint(p) ( !( isnan(p.x) || isnan(p.y) ) ) +#define isNormalEdgeInsets(e) ( !( isnan(e.top) || isnan(e.left) || isnan(e.bottom) || isnan(e.right) ) ) + + +typedef void(^LVLoadFinished)(id errorInfo); + +#import "UIView+LuaView.h" +#import "NSObject+LuaView.h" +#import "UIScrollView+LuaView.h" +#import "LVBundle.h" + +#define EFFECT_NONE 0 +#define EFFECT_CLICK 1 +#define EFFECT_PARALLAX 2 + +#define LV_LUASTATE_VIEW(L) ( (__bridge LuaViewCore *)( G(L)->ud ) ) +#define LUAVIEW_SYS_TABLE_KEY "..::luaview::.." + +#ifndef MakeSureNotNil +#define MakeSureNotNil(__obj) ((__obj) ? (__obj) : @"") +#endif + +#endif diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVHeads.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVHeads.m new file mode 100644 index 00000000..acd9739c --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVHeads.m @@ -0,0 +1,33 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVHeads.h" + + +@implementation LVHeads + +NSString * const LVScriptExts[] = {@"lv", @"lua"}; +const int LVSignedScriptExtIndex = 0; + +const char* LVType_View = "LVType_UserDataView"; +const char* LVType_Data = "LVType_UserDataData"; +const char* LVType_Date = "LVType_UserDataDate"; +const char* LVType_Http = "LVType_UserDataHttp"; +const char* LVType_Timer = "LVType_UserDataTimer"; +const char* LVType_Transform3D = "LVType_UserDataTransform3D"; +const char* LVType_Animator = "LVType_UserDataAnimator"; +const char* LVType_Gesture = "LVType_UserDataGesture"; +const char* LVType_Downloader = "LVType_UserDataDownloader"; +const char* LVType_AudioPlayer = "LVType_UserDataAudioPlayer"; +const char* LVType_StyledString = "LVType_UserDataStyledString"; +const char* LVType_NativeObject = "LVType_UserDataNativeObject"; +const char* LVType_Struct = "LVType_UserDataStruct"; +const char* LVType_Canvas = "LVType_UserDataCanvas"; +const char* LVType_Event = "LVType_UserDataEvent"; + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVHttp.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVHttp.h new file mode 100644 index 00000000..8abfe042 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVHttp.h @@ -0,0 +1,27 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + + +@interface LVHttp : NSObject + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; + +-(id) init:(lua_State*) l; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +/* + * https检查是否是信任的域名, 改方法 可以被覆盖 + */ ++(BOOL) isTrustedHost:(NSString*) host; + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVHttp.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVHttp.m new file mode 100644 index 00000000..40f79e8a --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVHttp.m @@ -0,0 +1,323 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVHttp.h" +#import "LVHttpResponse.h" +#import "LVData.h" +#import "LView.h" +#import "LVHeads.h" + +@interface LVHttp () +@property(nonatomic,strong) id mySelf; +@property(nonatomic,strong) LVHttpResponse* response; +@property(nonatomic,strong) id function; +@property(nonatomic,assign) CGFloat timeout; +@property(nonatomic,strong) NSURLConnection* connection; +@end + +@implementation LVHttp + +static void releaseUserDataHttp(LVUserDataInfo* user){ + if( user && user->object ){ + LVHttp* http = CFBridgingRelease(user->object); + user->object = NULL; + if( http ){ + http.lv_userData = NULL; + http.lv_luaviewCore = nil; + http.mySelf = nil; + } + } +} + +-(void) dealloc{ +} + +-(id) init:(lua_State*) l{ + self = [super init]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + self.mySelf = self; + self.function = [[NSMutableString alloc] init]; + self.response = [[LVHttpResponse alloc] init]; + self.timeout = 30.0; + } + return self; +} + +-(void) requesetEndToDo{ + lua_State* l = self.lv_luaviewCore.l; + if( l ){ + lua_checkstack32(l); + [LVUtil pushRegistryValue:l key:self]; + [LVUtil call:l lightUserData:self.function key1:"callback" key2:NULL nargs:1]; + [LVUtil unregistry:l key:self]; + } + self.response = nil; + self.mySelf = nil; +} + +- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace { + return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]; +} + + ++(BOOL) isTrustedHost:(NSString*) host{ + NSArray* trustedHosts = @[@".alicdn.com",@".tbcdn.com",@".taobao.com",@".tmall.com",@".juhuasuan.com"]; + for( NSString* host in trustedHosts ) { + if( [host hasSuffix:host] ) { + return YES; + } + } + return NO; +} + +- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge { + if ( [challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust] ){ + if ( [LVHttp isTrustedHost:challenge.protectionSpace.host] ) { + [challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge]; + } + } + [challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge]; +} + +-(void) connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{ + self.response.error = error; + [self performSelectorOnMainThread:@selector(requesetEndToDo) withObject:nil waitUntilDone:NO]; +} + +-(void) connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{ + if( self.response.data == nil ) { + self.response.data = [[NSMutableData alloc] init]; + } + [self.response.data appendData:data]; +} + +-(void) connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{ + self.response.response = response; + if( [response isKindOfClass:[NSHTTPURLResponse class]] ){ + self.response.httpResponse = (NSHTTPURLResponse*)response; + } +} +-(void) connectionDidFinishLoading:(NSURLConnection *)connection{ + [self performSelectorOnMainThread:@selector(requesetEndToDo) withObject:nil waitUntilDone:NO]; +} + +-(void) connectionDidReceiveData:(NSData *)data{ + if( self.response.data == nil ) { + self.response.data = [[NSMutableData alloc] init]; + } + [self.response.data appendData:data]; +} + +-(void) connectionDidReceiveResponse:(NSURLResponse *)response{ + self.response.response = response; + if( [response isKindOfClass:[NSHTTPURLResponse class]] ){ + self.response.httpResponse = (NSHTTPURLResponse*)response; + } +} +-(void) connectionDidFinishLoading{ + [self performSelectorOnMainThread:@selector(requesetEndToDo) withObject:nil waitUntilDone:NO]; +} + +-(id) lv_nativeObject{ + return self; +} + +static int lvNewHttpObject (lua_State *L ) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVHttp class]]; + + LVHttp* http = [[c alloc] init:L]; + { + NEW_USERDATA(userData, Http); + userData->object = CFBridgingRetain(http); + http.lv_userData = userData; + + luaL_getmetatable(L, META_TABLE_Http ); + lua_setmetatable(L, -2); + } + [LVUtil registryValue:L key:http stack:-1]; + return 1; +} + +static int get (lua_State *L) { + int argN = lua_gettop(L); + if( argN>=2 ){ + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( LVIsType(user, Http) ) { + LVHttp* http = (__bridge LVHttp *)(user->object); + NSString* urlStr = lv_paramString(L, 2); + + if( lua_type(L, 3) != LUA_TNIL ) { + [LVUtil registryValue:L key:http.function stack:3]; + } + NSURL *url = [NSURL URLWithString:urlStr]; + NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; + [request setHTTPMethod:@"GET"]; + [request setTimeoutInterval:http.timeout]; + + NSOperationQueue *queue = [[NSOperationQueue alloc]init]; + __weak LVHttp* weakHttp = http; + [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) { + [weakHttp connectionDidReceiveResponse:response]; + [weakHttp connectionDidReceiveData:data]; + [weakHttp connectionDidFinishLoading]; + }]; + } + } + return 0; /* new userdatum is already on the stack */ +} + +static int post (lua_State *L) { + int argN = lua_gettop(L); + if( argN>=3 ){ + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( LVIsType(user, Http) ) { + // 1:url 2:heads 3:data 4:callback + NSString* urlStr = lv_paramString(L, 2); + LVHttp* http = (__bridge LVHttp *)(user->object); + NSDictionary* dic = nil; + NSData* data = nil; + for( int i=3 ; i<=argN ; i++ ) { + int type = lua_type(L, i); + if( type==LUA_TSTRING ) {// 数据 + NSString* s = lv_paramString(L, i); + data = [s dataUsingEncoding:NSUTF8StringEncoding]; + } + if( type==LUA_TTABLE ) {// 数据 + id tempDic = lv_luaTableToDictionary(L, i); + NSString* s = [LVUtil objectToString:tempDic]; + data = [s dataUsingEncoding:NSUTF8StringEncoding]; + } + + if( type==LUA_TFUNCTION ) { + [LVUtil registryValue:L key:http.function stack:4]; + } + } + NSURL *url = [NSURL URLWithString:urlStr]; + NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; + [request setHTTPMethod:@"POST"]; + [request setTimeoutInterval:http.timeout]; + + // http头信息 + if( dic.count>0 ){ + for (NSString *key in dic) { + NSString* value = dic[key]; + [request setValue:value forHTTPHeaderField:key]; + } + } + + // data + if( data.length>0 ){ + [request setHTTPBody:data]; + } + + NSOperationQueue *queue = [[NSOperationQueue alloc]init]; + __weak LVHttp* weakHttp = http; + [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) { + [weakHttp connectionDidReceiveResponse:response]; + [weakHttp connectionDidReceiveData:data]; + [weakHttp connectionDidFinishLoading]; + }]; + } + } + return 0; /* new userdatum is already on the stack */ +} + +static int __gc (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + releaseUserDataHttp(user); + return 0; +} + +static int __tostring (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user && LVIsType(user, Http) ){ + LVHttp* http = (__bridge LVHttp *)(user->object); + NSString* s = [NSString stringWithFormat:@"LVUserDataHttp: %@\n response.data.length=%ld\n error:%@", + http.response.response, + (long)http.response.data.length, + http.response.error ]; + lua_pushstring(L, s.UTF8String); + return 1; + } + return 0; +} + +static int data (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user && LVIsType(user, Http) ){ + LVHttp* http = (__bridge LVHttp *)(user->object); + // NSString* s = [NSString stringWithFormat:@"LVUserDataHttp: %@\n response.data.length=%ld\n error:%@", + // http.response.response, + // http.response.data.length, + // http.response.error ]; + return [LVData createDataObject:L data:http.response.data]; + } + return 0; +} +static int responseStatusCode (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user && LVIsType(user, Http) ){ + LVHttp* http = (__bridge LVHttp *)(user->object); + NSHTTPURLResponse* httpResponse = http.response.httpResponse; + lua_pushnumber(L, httpResponse.statusCode); + return 1; + } + return 0; +} +static int responseHeaderFields (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user && LVIsType(user, Http) ){ + LVHttp* http = (__bridge LVHttp *)(user->object); + NSHTTPURLResponse* response = http.response.httpResponse; + lv_pushNativeObject(L,response.allHeaderFields); + return 1; + } + return 0; +} +static int cancel (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user && LVIsType(user, Http) ){ + LVHttp* http = (__bridge LVHttp *)(user->object); + [http.connection cancel]; + return 0; + } + return 0; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + { + const struct luaL_Reg memberFunctions [] = { + {"__gc", __gc }, + + {"__tostring", __tostring }, + + {"data", data }, + {"code", responseStatusCode }, + {"header", responseHeaderFields }, + // IOS: meesage 服务端错误信息 + // timeout + // retryTimes + + {"get", get }, + {"post", post }, + + {"cancel", cancel }, + + {NULL, NULL} + }; + + lv_createClassMetaTable(L, META_TABLE_Http); + + luaL_openlib(L, NULL, memberFunctions, 0); + } + [LVUtil reg:L clas:self cfunc:lvNewHttpObject globalName:globalName defaultName:@"Http"]; + return 1; +} + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVHttpResponse.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVHttpResponse.h new file mode 100644 index 00000000..0bc65809 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVHttpResponse.h @@ -0,0 +1,18 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import + +@interface LVHttpResponse : NSObject + +@property(nonatomic,strong) NSURLResponse *response; +@property(nonatomic,strong) NSHTTPURLResponse *httpResponse; +@property(nonatomic,strong) NSMutableData *data; +@property(nonatomic,strong) NSError *error; + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVHttpResponse.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVHttpResponse.m new file mode 100644 index 00000000..8fffcb9e --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVHttpResponse.m @@ -0,0 +1,13 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVHttpResponse.h" + +@implementation LVHttpResponse + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVImage.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVImage.h new file mode 100644 index 00000000..be97771e --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVImage.h @@ -0,0 +1,41 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" +#import "LView.h" + + +@interface LVImage : UIImageView + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; +@property(nonatomic,assign) NSUInteger lv_align; +@property(nonatomic,strong) CAShapeLayer* lv_shapeLayer; + +-(id) init:(lua_State*) l; + +-(void) setImageByName:(NSString*) imageName; +-(void) setImageByData:(NSData*) data; +-(void) setWebImageUrl:(NSURL*) url finished:(LVLoadFinished) finished; +-(void) effectParallax:(CGFloat)dx dy:(CGFloat)dy ; +-(void) effectClick:(NSInteger)color alpha:(CGFloat)alpha; + +/* + * Lua 脚本回调 + */ +-(void) callLuaDelegate:(id) obj; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +/** + * 图片首次出现是否使用动画 + */ +@property (nonatomic,assign) BOOL disableAnimate; + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVImage.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVImage.m new file mode 100644 index 00000000..ca5d6375 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVImage.m @@ -0,0 +1,295 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVImage.h" +#import "LVBaseView.h" +#import "LVUtil.h" +#import "LVData.h" +#import +#import "LVNinePatchImage.h" +#import "LVHeads.h" + +@interface LVImage () +@property (nonatomic,strong) id functionTag; +@property (nonatomic,strong) UIImageView* blurImageView; +@property (nonatomic,strong) UIVisualEffectView *blurEffectView; +@property (nonatomic,assign) BOOL needCallLuaFunc; +@property (nonatomic,strong) UITapGestureRecognizer* tapGesture; +@property (nonatomic,strong) id errorInfo; +@property(nonatomic,assign) BOOL lv_isCallbackAddClickGesture;// 支持Callback 点击事件 +@end + +@implementation LVImage + + +-(id) init:(lua_State*) l{ + self = [super init]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + self.contentMode = UIViewContentModeScaleAspectFill; + self.functionTag = [[NSMutableString alloc] init]; + self.backgroundColor = [UIColor clearColor]; + self.clipsToBounds = YES; + self.lv_isCallbackAddClickGesture = YES; + self.disableAnimate = self.lv_luaviewCore.disableAnimate; + } + return self; +} + +-(void) setWebImageUrl:(NSURL*) url finished:(LVLoadFinished) finished{ +} + +-(void) callLuaDelegate:(id) obj{ + lua_State* L = self.lv_luaviewCore.l; + if( L ) { + lua_checkstack(L, 4); + lua_pushboolean(L, obj?0:1); + [LVUtil pushRegistryValue:L key:self.functionTag]; + lv_runFunctionWithArgs(L, 1, 0); + } + [LVUtil unregistry:L key:self.functionTag]; +} + +-(void) setImageByName:(NSString*) imageName{ + if( imageName==nil ) + return; + + if( [LVUtil isExternalUrl:imageName] ){ + //CDN image + __weak LVImage* weakImageView = self; + [self setWebImageUrl:[NSURL URLWithString:imageName] finished:^(id errorInfo){ + if( weakImageView.needCallLuaFunc ) { + weakImageView.errorInfo = errorInfo; + [weakImageView performSelectorOnMainThread:@selector(callLuaDelegate:) withObject:errorInfo waitUntilDone:NO]; + } + }]; + } else { + // local Image + UIImage* image = [self.lv_luaviewCore.bundle imageWithName:imageName]; + if ( [LVNinePatchImage isNinePathImageName:imageName] ) { + image = [LVNinePatchImage createNinePatchImage:image]; + [self setImage:image]; + } else { + [self setImage:image]; + } + } +} + +-(void) lv_effectParallax:(CGFloat)dx dy:(CGFloat)dy{ + [self effectParallax:dx dy:dy]; +} + +-(void) effectParallax:(CGFloat)dx dy:(CGFloat)dy { +} + +-(void) effectClick:(NSInteger)color alpha:(CGFloat)alpha { +} + +-(void) setImageByData:(NSData*) data{ + if ( data ) { + UIImage* image = [[UIImage alloc] initWithData:data]; + [self setImage:image]; + } +} + +-(void) canelWebImageLoading{ + // [self cancelCurrentImageLoad]; // 取消上一次CDN加载 +} +-(void) cancelImageLoadAndClearCallback:(lua_State*)L{ + [self canelWebImageLoading]; + [NSObject cancelPreviousPerformRequestsWithTarget:self]; // 取消回调脚本 + [LVUtil unregistry:L key:self.functionTag]; // 清除脚本回调 +} + +-(void) dealloc{ + LVUserDataInfo* userData = self.lv_userData; + if( userData ){ + userData->object = NULL; + } +} + +#pragma -mark ImageView +static int lvNewImageView(lua_State *L) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVImage class]]; + + NSString* imageName = lv_paramString(L, 1); + + LVImage* imageView = [[c alloc] init:L]; + [imageView setImageByName:imageName]; + { + NEW_USERDATA(userData, View); + userData->object = CFBridgingRetain(imageView); + imageView.lv_userData = userData; + + luaL_getmetatable(L, META_TABLE_UIImageView ); + lua_setmetatable(L, -2); + } + LuaViewCore* view = LV_LUASTATE_VIEW(L); + if( view ){ + [view containerAddSubview:imageView]; + } + return 1; /* new userdatum is already on the stack */ +} + +static int setImage (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVImage* imageView = (__bridge LVImage *)(user->object); + if ( [imageView isKindOfClass:[LVImage class]] ) { + [imageView cancelImageLoadAndClearCallback:L]; + if( lua_type(L, 3) == LUA_TFUNCTION ) { + [LVUtil registryValue:L key:imageView.functionTag stack:3]; + imageView.needCallLuaFunc = YES; + } else { + imageView.needCallLuaFunc = NO; + } + if ( lua_type(L, 2)==LUA_TSTRING ) { + NSString* imageName = lv_paramString(L, 2);// 2 + if( imageName ){ + [imageView setImageByName:imageName]; + lua_pushvalue(L,1); + return 1; + } + } else if ( lua_type(L, 2)==LUA_TUSERDATA ) { + LVUserDataInfo * userdata = (LVUserDataInfo *)lua_touserdata(L, 2); + LVData* lvdata = (__bridge LVData *)(userdata->object); + if( LVIsType(userdata, Data) ) { + [imageView setImageByData:lvdata.data]; + lua_pushvalue(L,1); + return 1; + } + } else { + // 清理图片 + imageView.image = nil; + } + } + } + return 0; +} + +static int scaleType (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVImage* imageView = (__bridge LVImage *)(user->object); + if ( [imageView isKindOfClass:[LVImage class]] ) { + if( lua_gettop(L)>=2 ) { + int model = lua_tonumber(L, 2);// 2 + [imageView setContentMode:model]; + return 0; + } else { + UIViewContentMode model = imageView.contentMode; + lua_pushnumber(L, model); + return 1; + } + } + } + return 0; +} + +static int startAnimating (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( L && user ){ + LVImage* imageView = (__bridge LVImage *)(user->object); + if ( [imageView isKindOfClass:[LVImage class]] ) { + NSArray* urlArray = lv_luaTableToArray(L,2); + float repeatCount = 1; + float duration = 0.3; + if( lua_gettop(L)>=3 ){ + duration = lua_tonumber(L, 3); + } + if( lua_gettop(L)>=4 ){ + repeatCount = lua_tonumber(L, 4); + } + LuaViewCore* lview = LV_LUASTATE_VIEW(L); + LVBundle* bundle = lview.bundle; + NSMutableArray *arrayM=[NSMutableArray array]; + for (NSString* url in urlArray) { + UIImage* image = [bundle imageWithName:url]; + if( image ) { + [arrayM addObject:image]; + } + } + [imageView setAnimationImages:arrayM];//设置动画数组 + [imageView setAnimationDuration:duration];//设置动画播放时间 + [imageView setAnimationRepeatCount:repeatCount];//设置动画播放次数 + [imageView startAnimating];//开始动画 + } + } + return 0; +} + +static int stopAnimating (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVImage* imageView = (__bridge LVImage *)(user->object); + if ( [imageView isKindOfClass:[LVImage class]] ) { + [imageView stopAnimating]; + return 0; + } + } + return 0; +} + +static int isAnimating (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVImage* imageView = (__bridge LVImage *)(user->object); + if ( [imageView isKindOfClass:[LVImage class]] ) { + lua_pushboolean(L, imageView.isAnimating?1:0); + return 1; + } + } + lua_pushboolean(L, 0); + return 1; +} + +static int disableAnimate (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVImage* imageView = (__bridge LVImage *)(user->object); + if ( [imageView isKindOfClass:[LVImage class]] ) { + BOOL disableAnimate = lua_toboolean(L, 2); + imageView.disableAnimate = disableAnimate; + } + } + return 0; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + + [LVUtil reg:L clas:self cfunc:lvNewImageView globalName:globalName defaultName:@"Image"]; + + const struct luaL_Reg memberFunctions [] = { + {"image", setImage}, + {"scaleType", scaleType}, + + {"startAnimationImages", startAnimating},//__deprecated_msg("") + {"stopAnimationImages", stopAnimating},//__deprecated_msg("") + {"isAnimationImages", isAnimating},//__deprecated_msg("") + + {"disableAnimate", disableAnimate},//__deprecated_msg("") + {NULL, NULL} + }; + + lv_createClassMetaTable(L, META_TABLE_UIImageView); + + luaL_openlib(L, NULL, [LVBaseView baseMemberFunctions], 0); + luaL_openlib(L, NULL, memberFunctions, 0); + + const char* keys[] = { "addView", NULL};// 移除多余API + lv_luaTableRemoveKeys(L, keys ); + return 1; +} + + +//---------------------------------------------------------------------------------------- +-(NSString*) description{ + return [NSString stringWithFormat:@"", (int)[self hash], NSStringFromCGRect(self.frame) ]; +} + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLabel.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLabel.h new file mode 100644 index 00000000..5f7b4664 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLabel.h @@ -0,0 +1,23 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + +@interface LVLabel : UILabel + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; +@property(nonatomic,assign) NSUInteger lv_align; +@property(nonatomic,strong) CAShapeLayer* lv_shapeLayer; + +-(id) init:(NSString*)imageName l:(lua_State*) l; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLabel.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLabel.m new file mode 100644 index 00000000..49a619da --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLabel.m @@ -0,0 +1,281 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ +#import "LVLabel.h" +#import "LVBaseView.h" +#import "LView.h" +#import "LVStyledString.h" +#import "LVHeads.h" + +@interface LVLabel () +@property(nonatomic,assign) BOOL lv_isCallbackAddClickGesture;// 支持Callback 点击事件 +@end + +@implementation LVLabel + + +-(id) init:(NSString*)imageName l:(lua_State*) l{ + self = [super init]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + self.text = imageName; + self.backgroundColor = [UIColor clearColor]; + self.textAlignment = NSTextAlignmentLeft; + self.lv_isCallbackAddClickGesture = YES; + self.clipsToBounds = YES; + self.font = [UIFont systemFontOfSize:14];// 默认字体大小 + } + return self; +} + +-(void) dealloc{ +} + +#pragma -mark UILabel +static int lvNewLabel(lua_State *L) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVLabel class]]; + { + NSString* text = lv_paramString(L, 1);// 5 + LVLabel* label = [[c alloc] init:text l:L]; + + { + NEW_USERDATA(userData, View); + userData->object = CFBridgingRetain(label); + label.lv_userData = userData; + + luaL_getmetatable(L, META_TABLE_UILabel ); + lua_setmetatable(L, -2); + } + LuaViewCore* view = LV_LUASTATE_VIEW(L); + if( view ){ + [view containerAddSubview:label]; + } + } + return 1; /* new userdatum is already on the stack */ +} + +static int text (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ) { + LVLabel* view = (__bridge LVLabel *)(user->object); + if ( [view isKindOfClass:[LVLabel class]] ) { + if( lua_gettop(L)>=2 ) { + if ( lua_isnoneornil(L, 2 ) ) { + view.text = nil; + } else if( lua_type(L, 2)==LUA_TNUMBER ){ + CGFloat text = lua_tonumber(L, 2);// 2 + view.text = [NSString stringWithFormat:@"%f",text]; + return 0; + } else if( lua_type(L, 2)==LUA_TSTRING ){ + NSString* text = lv_paramString(L, 2);// 2 + view.text = text; + return 0; + } else if( lua_type(L, 2)==LUA_TUSERDATA ){ + LVUserDataInfo * user2 = lua_touserdata(L, 2);// 2 + if( user2 && LVIsType(user2, StyledString) ) { + LVLabel* view = (__bridge LVLabel *)(user->object); + LVStyledString* attString = (__bridge LVStyledString *)(user2->object); + [view setAttributedText:attString.mutableStyledString]; + return 0; + } + } + } else { + NSString* text = view.text; + lua_pushstring(L, text.UTF8String); + return 1; + } + } + } + return 0; +} + +static int lineCount(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVLabel* view = (__bridge LVLabel *)(user->object); + if( lua_gettop(L)>=2 ) { + int number = lua_tonumber(L, 2);// 2 + if( [view isKindOfClass:[LVLabel class]] ){ + view.numberOfLines = number; + return 0; + } + } else { + lua_pushnumber(L, view.numberOfLines ); + return 1; + } + } + return 0; +} + +static int adjustFontSize(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + BOOL yes = lua_toboolean(L, 2);// 2 + LVLabel* view = (__bridge LVLabel *)(user->object); + if( [view isKindOfClass:[LVLabel class]] ){ + view.adjustsFontSizeToFitWidth = yes; + + lua_pushvalue(L,1); + return 1; + } + } + return 0; +} + +static int textColor (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVLabel* view = (__bridge LVLabel *)(user->object); + if( lua_gettop(L)>=2 ) { + if( [view isKindOfClass:[LVLabel class]] ){ + UIColor* color = lv_getColorFromStack(L, 2); + view.textColor = color; + return 0; + } + } else { + UIColor* color = view.textColor; + NSUInteger c = 0; + CGFloat a = 0; + if( lv_uicolor2int(color, &c, &a) ){ + lua_pushnumber(L, c ); + lua_pushnumber(L, a); + return 2; + } + } + } + return 0; +} + +static int font (lua_State *L) { + LuaViewCore* luaView = LV_LUASTATE_VIEW(L); + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( luaView && user ){ + LVLabel* view = (__bridge LVLabel *)(user->object); + if( [view isKindOfClass:[LVLabel class]] ){ + if( lua_gettop(L)>=2 ) { + if( lua_gettop(L)>=3 && lua_type(L, 2)==LUA_TSTRING ) { + NSString* fontName = lv_paramString(L, 2); + float fontSize = lua_tonumber(L, 3); + UIFont* font = [LVUtil fontWithName:fontName size:fontSize bundle:luaView.bundle]; + view.font = font; + } else { + float fontSize = lua_tonumber(L, 2); + view.font = [UIFont systemFontOfSize:fontSize]; + } + return 0; + } else { + UIFont* font = view.font; + NSString* fontName = font.fontName; + CGFloat fontSize = font.pointSize; + lua_pushstring(L, fontName.UTF8String); + lua_pushnumber(L, fontSize); + return 2; + } + } + } + return 0; +} + + +static int fontSize (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVLabel* view = (__bridge LVLabel *)(user->object); + if( [view isKindOfClass:[LVLabel class]] ){ + if( lua_gettop(L)>=2 ) { + float fontSize = lua_tonumber(L, 2); + view.font = [UIFont systemFontOfSize:fontSize]; + return 0; + } else { + UIFont* font = view.font; + CGFloat fontSize = font.pointSize; + lua_pushnumber(L, fontSize); + return 1; + } + } + } + return 0; +} + +static int textAlignment (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVLabel* view = (__bridge LVLabel *)(user->object); + if( lua_gettop(L)>=2 ) { + NSInteger align = lua_tonumber(L, 2);// 2 + if( [view isKindOfClass:[LVLabel class]] ){ + view.textAlignment = align; + return 0; + } + } else { + int align = view.textAlignment; + lua_pushnumber(L, align ); + return 1; + } + } + return 0; +} + +static int ellipsize (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVLabel* view = (__bridge LVLabel *)(user->object); + if( lua_gettop(L)>=2 ) { + NSInteger lineBreakMode = lua_tonumber(L, 2);// 2 + if( [view isKindOfClass:[LVLabel class]] ){ + view.lineBreakMode = lineBreakMode; + return 0; + } + } else { + int lineBreakMode = view.lineBreakMode; + lua_pushnumber(L, lineBreakMode ); + return 1; + } + } + return 0; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewLabel globalName:globalName defaultName:@"Label"]; + + const struct luaL_Reg memberFunctions [] = { + {"text", text}, + + {"textColor", textColor}, + + {"font", font}, + {"fontSize", fontSize}, + {"textSize", fontSize}, // __deprecated_msg("Use fontSize") + + {"ellipsize", ellipsize}, + {"textAlign", textAlignment}, + {"gravity", textAlignment},// 上中下 IOS 不支持,需要考虑支持 + + {"lineCount", lineCount}, // __deprecated_msg("Use lines") + // lines + + {"adjustFontSize", adjustFontSize}, + + {NULL, NULL} + }; + + lv_createClassMetaTable(L, META_TABLE_UILabel); + + luaL_openlib(L, NULL, [LVBaseView baseMemberFunctions], 0); + luaL_openlib(L, NULL, memberFunctions, 0); + + const char* keys[] = { "addView", NULL};// 移除多余API + lv_luaTableRemoveKeys(L, keys ); + return 1; +} + + +-(NSString*) description{ + return [NSString stringWithFormat:@"", (int)[self hash], NSStringFromCGRect(self.frame) ]; +} + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLoadingIndicator.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLoadingIndicator.h new file mode 100644 index 00000000..d73af1bc --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLoadingIndicator.h @@ -0,0 +1,24 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + +@interface LVLoadingIndicator : UIActivityIndicatorView + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; +@property(nonatomic,assign) NSUInteger lv_align; +@property(nonatomic,strong) CAShapeLayer* lv_shapeLayer; + +-(id) init:(lua_State*) l; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLoadingIndicator.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLoadingIndicator.m new file mode 100644 index 00000000..d09977cd --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLoadingIndicator.m @@ -0,0 +1,137 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVLoadingIndicator.h" +#import "LVBaseView.h" +#import "LView.h" +#import "LVHeads.h" + + +@implementation LVLoadingIndicator + + + +-(id) init:(lua_State*) l{ + self = [super init]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + self.clipsToBounds = YES; + self.userInteractionEnabled = NO; + } + return self; +} + +-(void) dealloc{ +} + +#pragma -mark lvNewActivityIndicator +static int lvNewLoadingIndicator (lua_State *L) { + { + Class c = [LVUtil upvalueClass:L defaultClass:[LVLoadingIndicator class]]; + + LVLoadingIndicator* pageControl = [[c alloc] init:L]; + + { + NEW_USERDATA(userData, View); + userData->object = CFBridgingRetain(pageControl); + + luaL_getmetatable(L, META_TABLE_LoadingIndicator ); + lua_setmetatable(L, -2); + } + LuaViewCore* view = LV_LUASTATE_VIEW(L); + if( view ){ + [view containerAddSubview:pageControl]; + } + } + return 1; /* new userdatum is already on the stack */ +} + +static int startAnimating(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVLoadingIndicator* view = (__bridge LVLoadingIndicator *)(user->object); + if( view ){ + [view startAnimating]; + } + } + return 0; +} + +static int stopAnimating(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVLoadingIndicator* view = (__bridge LVLoadingIndicator *)(user->object); + if( view ){ + [view stopAnimating]; + } + } + return 0; +} + +static int isAnimating(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVLoadingIndicator* view = (__bridge LVLoadingIndicator *)(user->object); + if( view ){ + lua_pushboolean(L, view.isAnimating); + return 1; + } + } + return 0; +} + +static int color(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVLoadingIndicator* view = (__bridge LVLoadingIndicator *)(user->object); + if( view ){ + if( lua_gettop(L)>=2 ) { + UIColor* color = lv_getColorFromStack(L, 2); + view.color = color; + return 0; + } else { + UIColor* color = view.color; + NSUInteger c = 0; + CGFloat a = 1; + if( lv_uicolor2int(color, &c, &a) ){ + lua_pushnumber(L, c ); + lua_pushnumber(L, a); + return 2; + } + } + } + } + return 0; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewLoadingIndicator globalName:globalName defaultName:@"LoadingIndicator"]; + + const struct luaL_Reg memberFunctions [] = { + {"start", startAnimating }, + {"stop", stopAnimating }, + {"show", startAnimating },//__deprecated_msg("Use start") + {"hide", stopAnimating },//__deprecated_msg("Use stop") + {"isAnimating", isAnimating }, + {"color", color}, + {NULL, NULL} + }; + + lv_createClassMetaTable(L, META_TABLE_LoadingIndicator); + + luaL_openlib(L, NULL, [LVBaseView baseMemberFunctions], 0); + luaL_openlib(L, NULL, memberFunctions, 0); + + const char* keys[] = { "addView", NULL};// 移除多余API + lv_luaTableRemoveKeys(L, keys ); + return 1; +} + + + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLongPressGesture.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLongPressGesture.h new file mode 100644 index 00000000..10fe1e1c --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLongPressGesture.h @@ -0,0 +1,23 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" +#import "NSObject+LuaView.h" + +@interface LVLongPressGesture : UILongPressGestureRecognizer + + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; + +-(id) init:(lua_State*) l; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLongPressGesture.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLongPressGesture.m new file mode 100644 index 00000000..b023ab83 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLongPressGesture.m @@ -0,0 +1,97 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVLongPressGesture.h" +#import "LVGesture.h" +#import "LView.h" +#import "LVHeads.h" + +@implementation LVLongPressGesture + + +-(void) dealloc{ + LVLog(@"LVLongPressGesture.dealloc"); + [LVGesture releaseUD:_lv_userData]; +} + +-(id) init:(lua_State*) l{ + self = [super initWithTarget:self action:@selector(handleGesture:)]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + } + return self; +} + +-(void) handleGesture:(LVLongPressGesture*)sender { + lua_State* l = self.lv_luaviewCore.l; + if ( l ){ + lua_checkstack32(l); + lv_pushUserdata(l,self.lv_userData); + [LVUtil call:l lightUserData:self key1:"callback" key2:NULL nargs:1]; + } +} + + +static int lvNewLongGesture (lua_State *L) { + { + Class c = [LVUtil upvalueClass:L defaultClass:[LVLongPressGesture class]]; + + LVLongPressGesture* gesture = [[c alloc] init:L]; + + if( lua_type(L, 1) != LUA_TNIL ) { + [LVUtil registryValue:L key:gesture stack:1]; + } + + { + NEW_USERDATA(userData, Gesture); + gesture.lv_userData = userData; + userData->object = CFBridgingRetain(gesture); + + luaL_getmetatable(L, META_TABLE_LongPressGesture ); + lua_setmetatable(L, -2); + } + } + return 1; /* new userdatum is already on the stack */ +} + +static int setTouchCount (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( LVIsType(user, Gesture) ){ + LVLongPressGesture* gesture = (__bridge LVLongPressGesture *)(user->object); + if( lua_gettop(L)>=2 ){ + float num = lua_tonumber(L, 2); + gesture.numberOfTouchesRequired = num; + return 0; + } else { + float num = gesture.numberOfTouchesRequired; + lua_pushnumber(L, num); + return 1; + } + } + return 0; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewLongGesture globalName:globalName defaultName:@"LongPressGesture"]; + + lv_createClassMetaTable(L, META_TABLE_LongPressGesture); + + luaL_openlib(L, NULL, [LVGesture baseMemberFunctions], 0); + + { + const struct luaL_Reg memberFunctions [] = { + {"touchCount", setTouchCount}, + {NULL, NULL} + }; + luaL_openlib(L, NULL, memberFunctions, 0); + } + return 1; +} + + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLuaObjBox.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLuaObjBox.h new file mode 100644 index 00000000..d4a23bf4 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLuaObjBox.h @@ -0,0 +1,18 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LView.h" + +@interface LVLuaObjBox : NSObject + +- (id) init:(lua_State*)L stackID:(int) stackID; + +- (void) setProtocols:(NSArray*) protocols; + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLuaObjBox.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLuaObjBox.m new file mode 100644 index 00000000..36f60cd8 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLuaObjBox.m @@ -0,0 +1,211 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVLuaObjBox.h" +#import +#import "LuaViewCore.h" +#import "LVTypeConvert.h" +#import "LVHeads.h" + +@interface LVLuaObjBox () +@property (nonatomic, strong) NSMutableArray* protocolArray; +@property (nonatomic, weak) LuaViewCore* lview; +@property (nonatomic, strong) NSMutableDictionary* methodSigHashtable; +@end + + +@implementation LVLuaObjBox + + +- (id) init:(lua_State*)L stackID:(int) stackID{ + self = [super init]; + if( self ){ + self.methodSigHashtable = [[NSMutableDictionary alloc] init]; + + self.lview = LV_LUASTATE_VIEW(L); + [LVUtil registryValue:L key:self stack:stackID]; + } + return self; +} + +- (void) dealloc{ + LuaViewCore* lview = self.lview; + if( lview) { + lua_State* L = lview.l; + if( L ) { + [LVUtil unregistry:L key:self]; + } + } +} + + +// static +static BOOL lv_object_isProtocol(id obj ) { + static Class ProtocolClass = NULL; + if( ProtocolClass == NULL ) { + ProtocolClass = objc_getClass("Protocol"); + } + return ( [obj class]==ProtocolClass ); +} + +- (void) setProtocols:(NSArray *)protocols{ + if ( self.protocolArray ==nil ) { + self.protocolArray = [[NSMutableArray alloc] init]; + } + for( id obj in protocols ){ + [self addProtocol:obj]; + } +} + +- (void) addProtocol:(id) obj{ + if ( obj==nil ) + return ; + + if ( (class_isMetaClass(object_getClass(obj)) || lv_object_isProtocol(obj)) ) { + [self addProtocolOnce:obj]; + } else if ( [obj isKindOfClass:[NSString class]] ) { + if ( [self addProtocolOnce:NSProtocolFromString(obj)]==FALSE ){ + if ( [self addProtocolOnce:NSClassFromString(obj)]==FALSE ) { + LVError( @"addProtocol: %@", obj); + return ; + } + } + } else { + [self addProtocolOnce:[obj class]]; + } +} + +- (BOOL) addProtocolOnce:(id) class{ + if ( class ) { + if ( class_isMetaClass(object_getClass(class)) || lv_object_isProtocol(class) ) { + if( ![self.protocolArray containsObject:class] ) { + [self.protocolArray addObject:class]; + return YES; + } + } + } + return NO; +} + + +- (BOOL)respondsToSelector:(SEL)aSelector { + return YES; +} + +- (NSMethodSignature *)methodSignatureForSelector:(SEL)selector +{ + NSString* key = NSStringFromSelector(selector); + NSMethodSignature* sig = self.methodSigHashtable[key]; + if( sig ){ + return sig; + } + for (id type in self.protocolArray ){ + struct objc_method_description* desc = NULL; + + if( lv_object_isProtocol(type) ){ // protocol + Protocol* protocol = type; + struct objc_method_description temp = protocol_getMethodDescription( protocol, selector, YES, YES); + if( temp.types==NULL || temp.name==NULL ) { + temp = protocol_getMethodDescription( protocol, selector, NO, YES); + } + desc = &temp; + } else if( class_isMetaClass(object_getClass(type)) ) { // class + Class class = (Class)type; + Method method = class_getInstanceMethod( class, selector ); + if ( method==NULL ){ + method = class_getClassMethod( class, selector ); + } + if ( method ) { + desc = method_getDescription( method ); + } + } + if( desc && desc->types && desc->name ) { + NSMethodSignature* sig = [NSMethodSignature signatureWithObjCTypes:desc->types]; + self.methodSigHashtable[key] = sig; + return sig; + } + } + return nil; +} + +- (NSString*) nativeFuncNameToLuaFuncName:(NSString*) funcName{ + NSMutableString* s = [[NSMutableString alloc] initWithString:funcName]; + if ( [funcName hasSuffix:@":"] ){ + [s deleteCharactersInRange:NSMakeRange(s.length-1,1)]; + } + [s replaceOccurrencesOfString:@":" withString:@"_" options:NSCaseInsensitiveSearch range:NSMakeRange(0,s.length)]; + return s; +} + +-(NSString*) propertyName:(NSString*) key{ + if( key.length>3 ) { + NSString* string = [[NSString alloc] initWithString:[key substringFromIndex:3]]; + NSString* string0 = [string substringToIndex:1]; + NSString* string1 = [string substringFromIndex:1]; + NSString* ret = [NSString stringWithFormat:@"%@%@",string0.lowercaseString, string1]; + return ret; + } + return key; +} + +- (void)forwardInvocation:(NSInvocation *)invocation +{ + NSString *key = NSStringFromSelector([invocation selector]); + LuaViewCore* lview = self.lview; + lua_State* L = lview.l; + if ( lview && L) { + int luaArgNum = 1; + [LVUtil pushRegistryValue:L key:self]; + int argsNum = (int)invocation.methodSignature.numberOfArguments; + + key = [self nativeFuncNameToLuaFuncName:key]; + int haveReturnValue = [self haveReturnValueOfInvocation:invocation]; + const char* keyName = key.UTF8String; + if ( lv_isLuaObjectHaveProperty(L, -1, keyName) ) { + for ( int i=2; i3 &&[key hasPrefix:@"set"] ){ + NSString* property = [self propertyName:key]; + const char* propertyName = property.UTF8String; + if ( lv_isLuaObjectHaveProperty(L, -1, propertyName) ) { + lua_pushstring(L, propertyName); + lv_pushInvocationArgToLuaStack(invocation, 2, L); + lua_settable(L, -3); + return; + } + } + LVError(@"LuaObjBox.forwardInvocation: not found function: %@", key); + } +} + +- (int) haveReturnValueOfInvocation:(NSInvocation*) invocation{ + const char* type = [invocation.methodSignature methodReturnType]; + if ( type ){ + if( strcmp(@encode(void),type)==0 ) { + return 0; + } + return 1; + } + return 0; +} +// class_copyPropertyList +// class_copyMethodList + +@end + + + diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVMethod.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVMethod.h new file mode 100644 index 00000000..9231d119 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVMethod.h @@ -0,0 +1,22 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + +@interface LVMethod : NSObject + +@property (nonatomic,assign) SEL sel; +@property (nonatomic,copy) NSString* selName; +@property (nonatomic,assign) NSInteger nargs; + +-(id) initWithSel:(SEL)sel; + +-(int) callObj:(id) obj args:(lua_State*)L; + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVMethod.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVMethod.m new file mode 100644 index 00000000..646959a5 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVMethod.m @@ -0,0 +1,71 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVMethod.h" +#import "LVHeads.h" +#import "LVTypeConvert.h" + + +@interface LVMethod () +@property(nonatomic,strong) NSMethodSignature * methodSig; +@end + +@implementation LVMethod + +-(id) initWithSel:(SEL)sel{ + self = [super init]; + if( self ){ + self.sel = sel; + self.selName = NSStringFromSelector(sel); + self.nargs = [self checkSelectorArgsNumber:NSStringFromSelector(sel)]; + } + return self; +} + +-(NSInteger) checkSelectorArgsNumber:(NSString*)s{ + NSInteger num = 0; + for( int i=0; i +#import "LVHeads.h" +#import "LVMethod.h" + + +//LVData +@interface LVNativeObjBox : NSObject + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; + +@property(nonatomic,assign) BOOL weakMode; +@property(nonatomic,strong) id realObject; +@property(nonatomic,weak) id realObjectWeak; +@property(nonatomic,assign) BOOL openAllMethod; + +-(id) init:(lua_State*) l nativeObject:(id)nativeObject; +-(void) addMethod:(LVMethod*) method; +-(int) performMethod:(NSString*) methodName L:(lua_State*)L; + +- (NSString *)className; +- (BOOL)isOCClass; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +/* + * 注册native对象到脚本中, sel可以为空(如果为空注册所有api) + */ ++(int) registeObjectWithL:(lua_State *)L nativeObject:(id) nativeObject name:(NSString*) luaName sel:(SEL) sel weakMode:(BOOL) weakMode; + +/* + * 清除脚本中注册的native对象 + */ ++(int) unregisteObjectWithL:(lua_State *)L name:(NSString*) name; + + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNativeObjBox.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNativeObjBox.m new file mode 100644 index 00000000..ee1d468f --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNativeObjBox.m @@ -0,0 +1,302 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVNativeObjBox.h" +#import "LVHeads.h" +#import +#import "LVClassInfo.h" + +static NSArray* ARG_ARR = nil; + +@interface LVNativeObjBox () +@property (nonatomic,strong) LVClassInfo* classInfo; +@end + + +@implementation LVNativeObjBox + +-(id) init:(lua_State*) l nativeObject:(id)nativeObject{ + self = [super init]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + self.realObject = nativeObject; + + NSString* className = NSStringFromClass([nativeObject class]); + self.classInfo = [LVClassInfo classInfo:className]; + } + return self; +} + +- (BOOL) isEqual:(LVNativeObjBox *)another{ + if (![another isMemberOfClass:[self class]]) { + return false; + } + + return self.realObject == another.realObject || [self.realObject isEqual:another.realObject]; +} + +- (NSUInteger)hash { + return [self.realObject hash]; +} + +- (BOOL) isOCClass{ + return self.realObject && class_isMetaClass(object_getClass(self.realObject)); +} + +- (NSString *)className { + return NSStringFromClass([self.realObject class]); +} + +- (void) setWeakMode:(BOOL)weakMode{ + _weakMode = weakMode; + if( weakMode ) { + if( self.realObject ) { + self.realObjectWeak = self.realObject; + } + self.realObject = nil; + } else { + if( self.realObjectWeak ) { + self.realObject = self.realObjectWeak; + } + self.realObjectWeak = nil; + } +} + +- (id) realObject{ + return _realObject ? _realObject : _realObjectWeak; +} + +- (id) lv_nativeObject{ + return [self realObject]; +} + +-(void) addMethod:(LVMethod*) method { + [self.classInfo addMethod:method key:method.selName]; +} + +-(int) performMethod:(NSString*) methodName L:(lua_State*)L{ + if( methodName ) { + LVMethod* method = [self.classInfo getMethod:methodName]; + if ( method ) { + return [method callObj:self.realObject args:L ]; + } else if( self.openAllMethod ) { + //动态创建API + SEL sel = NSSelectorFromString(methodName); + LVMethod* method = [[LVMethod alloc] initWithSel:sel]; + [self.classInfo addMethod:method key:methodName]; + return [method callObj:self.realObject args:L]; + } else { + LVError(@"not found method: %@", methodName); + } + } + return 0; +} + +static int funcNameFromLuaToOC(NSMutableString* funcName){ + if( funcName.length>0 && [funcName characterAtIndex:0]=='#' ) { + NSRange range = NSMakeRange(0, 1); + [funcName deleteCharactersInRange:range]; + return -1; + } else { + return (int)[funcName replaceOccurrencesOfString:@"_" withString:@":" options:NSLiteralSearch range:NSMakeRange(0,funcName.length)]; + } +} + +// 检查API是否纯在 +- (BOOL) isApiExist:(NSString*) methodName{ + BOOL ret = [self.classInfo existMethod:methodName]; + if( ret ) { + return YES; + } else { + NSMutableString* ocMethodName = [[NSMutableString alloc] initWithString:methodName]; + funcNameFromLuaToOC(ocMethodName); + id nativeObj = self.realObject; + for ( int i=0; i<5; i++ ) { + SEL sel = NSSelectorFromString(ocMethodName); + if( [nativeObj respondsToSelector:sel] ){ + [self.classInfo setMethod:methodName exist:YES]; + return YES; + } + [ocMethodName appendString:@":"]; + } + } + //self.apiHashtable[methodName] = @(NO); + return NO; +} + +static void releaseNativeObject(LVUserDataInfo* user){ + if( user && user->object ){ + LVNativeObjBox* data = CFBridgingRelease(user->object); + user->object = NULL; + if( data ){ + data.lv_userData = nil; + data.lv_luaviewCore = nil; + data.realObject = nil; + } + } +} + +static int __gc (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + releaseNativeObject(user); + return 0; +} + ++(int) registeObjectWithL:(lua_State *)L nativeObject:(id) nativeObject name:(NSString*) name sel:(SEL) sel weakMode:(BOOL)weakMode { + if ( L==nil ){ + LVError( @"Lua State is released !!!"); + return 0; + } + if( nativeObject && name ) { + lua_checkstack(L, 64); + lua_getglobal(L, name.UTF8String); + + LVNativeObjBox* nativeObjBox = nil; + if( lua_type(L, -1)==LUA_TUSERDATA ) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, -1); + if( LVIsType(user, NativeObject) ){ + LVNativeObjBox* temp = (__bridge LVNativeObjBox *)(user->object); + if( temp.realObject==nativeObject ){ + nativeObjBox = temp; + } + } + } + if( nativeObjBox == nil ){ + nativeObjBox = [[LVNativeObjBox alloc] init:L nativeObject:nativeObject]; + } + + if ( sel ) { + LVMethod* method = [[LVMethod alloc] initWithSel:sel]; + [nativeObjBox addMethod:method]; + } else { + nativeObjBox.openAllMethod = YES; + } + nativeObjBox.weakMode = weakMode; + + NEW_USERDATA(userData, NativeObject); + userData->object = CFBridgingRetain(nativeObjBox); + nativeObjBox.lv_userData = userData; + luaL_getmetatable(L, META_TABLE_NativeObject ); + lua_setmetatable(L, -2); + + lua_setglobal(L, name.UTF8String); + } else if ( nativeObject==nil ){ + [LVNativeObjBox unregisteObjectWithL:L name:name]; + } + return 1; +} + + ++(int) unregisteObjectWithL:(lua_State *)L name:(NSString*) name{ + if ( L && name ) { + lua_pushnil(L); + lua_setglobal(L, name.UTF8String); + } + return 0; +} + +static int __tostring (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVNativeObjBox* nativeObjBox = (__bridge LVNativeObjBox *)(user->object); + NSString* s = [[NSString alloc] initWithFormat:@"{ UserDataType=NativeObject, %@ }",nativeObjBox.realObject]; + lua_pushstring(L, s.UTF8String); + return 1; + } + return 0; +} + +static void ifNotEnoughArgsTagAppendMore(NSMutableString* funcName, int num, int luaArgsNum){ + int addNum = luaArgsNum-1-num; + if( 0<=addNum && addNumobject); + NSMutableString* funcName = [NSMutableString stringWithFormat:@"%s",lua_tostring(L, lua_upvalueindex(2)) ]; + int luaArgsNum = lua_gettop(L); + + int _num = funcNameFromLuaToOC(funcName); + if( _num>=0 ) { + ifNotEnoughArgsTagAppendMore(funcName, _num, luaArgsNum); + } + return [nativeObjBox performMethod:funcName L:L]; + } + LVError(@"callNativeObjectFunction"); + return 0; +} + + +static int __index (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + NSString* functionName = lv_paramString(L, 2); + + LVNativeObjBox* nativeObjBox = (__bridge LVNativeObjBox *)(user->object); + id object = nativeObjBox.realObject; + if( nativeObjBox && object && [nativeObjBox isApiExist:functionName] ){ + lua_pushcclosure(L, callNativeObjectFunction, 2); + return 1; + } + return 0; /* new userdatum is already on the stack */ +} + +static int __eq (lua_State *L) { + if (lua_gettop(L) < 2) { + return 0; + } + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + LVUserDataInfo * another = (LVUserDataInfo *)lua_touserdata(L, 2); + if (another != NULL) { + LVNativeObjBox * box1 = (__bridge LVNativeObjBox *)(user->object); + LVNativeObjBox * box2 = (__bridge LVNativeObjBox *)(user->object); + lua_pushboolean(L, [box1 isEqual:box2]); + return 1; + } + return 0; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + // OC常量定义 + if( ARG_ARR==nil ) { + ARG_ARR = @[ + @"", + @":", + @"::", + @":::", + @"::::", + @":::::", + @"::::::", + @":::::::",]; + } + + const struct luaL_Reg memberFunctions [] = { + {"__gc", __gc }, + {"__tostring", __tostring }, + {"__eq", __eq }, + {"__index", __index }, + {NULL, NULL} + }; + + lv_createClassMetaTable(L, META_TABLE_NativeObject); + luaL_openlib(L, NULL, memberFunctions, 0); + + + return 0; +} + + + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNavigation.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNavigation.h new file mode 100644 index 00000000..6828e71a --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNavigation.h @@ -0,0 +1,23 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + +@interface LVNavigation : NSObject + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +// 空实现去除编译警告 +-(void) lv_setNavigationItemTitleView:(UIView*) view; +-(void) lv_setNavigationItemTitle:(NSString*) title; +-(void) lv_setNavigationItemLeftBarButtonItems:(NSArray*) items; +-(void) lv_setNavigationItemRightBarButtonItems:(NSArray*) items; +-(void) lv_setNavigationBarBackgroundImage:(UIImage*) image; + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNavigation.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNavigation.m new file mode 100644 index 00000000..e2cae30d --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNavigation.m @@ -0,0 +1,160 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVNavigation.h" +#import "LView.h" +#import "LVStyledString.h" +#import "LVHeads.h" + +@implementation LVNavigation + +// 空实现去除编译警告 +-(void) lv_setNavigationItemTitleView:(UIView*) view{ +} +-(void) lv_setNavigationItemTitle:(NSString*) title{ +} +-(void) lv_setNavigationItemLeftBarButtonItems:(NSArray*) items{ +} +-(void) lv_setNavigationItemRightBarButtonItems:(NSArray*) items{ +} +-(void) lv_setNavigationBarBackgroundImage:(UIImage*) image{ +} + +static void setViewControllerTitleView(UIViewController* vc, UIView* view){ + if([view isKindOfClass:[UIView class]] ) {// 第三种: View + if( [vc respondsToSelector:@selector(lv_setNavigationItemTitleView:)] ) { + [vc performSelector:@selector(lv_setNavigationItemTitleView:) withObject:view]; + } else { + vc.navigationItem.titleView = view; + } + } +} + +static int setTitle (lua_State *L) { + lv_clearFirstTableValue(L); + LuaViewCore* lview = LV_LUASTATE_VIEW(L); + UIViewController* vc = lview.viewController; + if( vc && lua_gettop(L)>=1 ) { + if( lua_type(L, 1)== LUA_TSTRING ) {// 第一种: string + NSString* title = lv_paramString(L, 1); + if( [vc respondsToSelector:@selector(lv_setNavigationItemTitle:)] ) { + [vc performSelector:@selector(lv_setNavigationItemTitle:) withObject:title]; + } else { + vc.navigationItem.title = title; + } + return 0; + } else if( lua_type(L, 1)== LUA_TUSERDATA ) {//第二种: 复合文本 + LVUserDataInfo * user2 = lua_touserdata(L, 1); + if( user2 && LVIsType(user2, StyledString) ) { + UILabel* label = [[UILabel alloc] init]; + LVStyledString* attString = (__bridge LVStyledString *)(user2->object); + [label setAttributedText:attString.mutableStyledString]; + [label sizeToFit]; + setViewControllerTitleView(vc, label); + return 0; + } + } + id object = lv_luaValueToNativeObject(L, 1);// 第三种: View + setViewControllerTitleView(vc, object); + return 0; + } + return 0; +} + ++(NSArray*) getNavigationItems:(lua_State*)L{ + NSMutableArray* array = [[NSMutableArray alloc] init]; + int num = lua_gettop(L); + for ( int i=1; i<=num; i++ ) { + id object = lv_luaValueToNativeObject(L, i); + if ( [object isKindOfClass:[UIView class]] ) { + [array addObject:[[UIBarButtonItem alloc] initWithCustomView:object]]; + } + } + return array; +} + +static int setLeftButton (lua_State *L) { + lv_clearFirstTableValue(L); + LuaViewCore* lview = LV_LUASTATE_VIEW(L); + UIViewController* vc = lview.viewController; + if( vc && lua_gettop(L)>=1 ) { + NSArray* buttonItems = [LVNavigation getNavigationItems:L]; + if( [vc respondsToSelector:@selector(lv_setNavigationItemLeftBarButtonItems:)] ) { + [vc performSelector:@selector(lv_setNavigationItemLeftBarButtonItems:) withObject:buttonItems]; + } else { + vc.navigationItem.leftBarButtonItems = buttonItems; + } + } + return 0; /* number of results */ +} + +static int setRightButton (lua_State *L) { + lv_clearFirstTableValue(L); + LuaViewCore* lview = LV_LUASTATE_VIEW(L); + UIViewController* vc = lview.viewController; + if( vc && lua_gettop(L)>=1 ) { + NSArray* buttonItems = [LVNavigation getNavigationItems:L]; + if( [vc respondsToSelector:@selector(lv_setNavigationItemRightBarButtonItems:)] ){ + [vc performSelector:@selector(lv_setNavigationItemRightBarButtonItems:) withObject:buttonItems]; + } else { + vc.navigationItem.rightBarButtonItems = buttonItems; + } + } + return 0; /* number of results */ +} + +static int setBackground(lua_State*L ) { + lv_clearFirstTableValue(L); + LuaViewCore* lview = LV_LUASTATE_VIEW(L); + UIViewController* vc = lview.viewController; + if( vc && lua_gettop(L)>=1 ) { + id obj = lv_luaValueToNativeObject(L, 1); + if( [obj isKindOfClass:[UIImageView class]] ) { + UIImageView* imgView = obj; + UIImage* image = imgView.image; + float scale = [UIScreen mainScreen].scale; + if( image.scale=1 ) { + NSInteger value = lua_tonumber(L, 2); + [[UIApplication sharedApplication] setStatusBarStyle:value]; + } + return 0; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + const struct luaL_Reg fs [] = { + {"title", setTitle}, + {"left", setLeftButton}, + {"right", setRightButton}, + {"background", setBackground}, + {"statusBarStyle", setStatusBarStyle}, // for IOS + {LUAVIEW_SYS_TABLE_KEY, setBackground}, + {NULL, NULL} + }; + luaL_openlib(L, "Navigation", fs, 0); + return 0; +} + +@end + + + diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNetworkStatus.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNetworkStatus.h new file mode 100644 index 00000000..b27f5162 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNetworkStatus.h @@ -0,0 +1,34 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import + +#define NW_NETWOEK_STATUS_NOTIFY @"TBNetworkStatusChangeNotify" + +typedef enum { + NotReachable = 0, + ReachableViaWiFi, + ReachableVia2G, + ReachableVia3G, + ReachableVia4G +} LVNetworkStatusEnum; + +@interface LVNetworkStatus : NSObject + ++ (LVNetworkStatus *)shareInstance; + +- (LVNetworkStatusEnum)currentNetworkStatus; + +- (LVNetworkStatusEnum)preNetworkStatus; + +- (NSString *)currentNetworkStatusString; + + + + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNetworkStatus.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNetworkStatus.m new file mode 100644 index 00000000..dffb3a6d --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNetworkStatus.m @@ -0,0 +1,259 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVNetworkStatus.h" +#import +#import +#import +#import +#import +#import +#import +#import + +#import +#import + +#import + +static char *const StrKeyReachabilityQueue = "com.luaview.NetworkSDKReachabilityQueue"; +static dispatch_queue_t reachabilityQueue; + +@implementation LVNetworkStatus +{ + LVNetworkStatusEnum _currentNetworkStatus; + LVNetworkStatusEnum _preNetworkStatus; + SCNetworkReachabilityRef _reachabilityRef; + CTTelephonyNetworkInfo *netInfo; +} + ++ (LVNetworkStatus *)shareInstance +{ + static LVNetworkStatus *s_SPDYNetworkStatusManager = nil; + + @synchronized([self class]) + { + if (!s_SPDYNetworkStatusManager) + { + s_SPDYNetworkStatusManager = [[LVNetworkStatus alloc] init]; + } + } + + return s_SPDYNetworkStatusManager; +} + +- (id)init +{ + self = [super init]; + if (self) + { + struct sockaddr_in zeroAddress; + bzero(&zeroAddress, sizeof(zeroAddress)); + zeroAddress.sin_len = sizeof(zeroAddress); + zeroAddress.sin_family = AF_INET; + _reachabilityRef = SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, (const struct sockaddr*)&zeroAddress); + netInfo = [[CTTelephonyNetworkInfo alloc] init]; + + //开始解析当前网络状态 + [self _reachabilityStatus]; + + //开始监控网络变化 + [self _startNotifier]; + } + + return self; +} + +- (BOOL)_startNotifier +{ + if (!_reachabilityRef) + { + struct sockaddr_in zeroAddress; + bzero(&zeroAddress, sizeof(zeroAddress)); + zeroAddress.sin_len = sizeof(zeroAddress); + zeroAddress.sin_family = AF_INET; + _reachabilityRef = SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, (const struct sockaddr*)&zeroAddress); + } + + if (_reachabilityRef) + { + SCNetworkReachabilityContext context = {0, (__bridge void *)(self), NULL, NULL, NULL}; + + if(SCNetworkReachabilitySetCallback(_reachabilityRef, ReachabilityCallback, &context)) + { + reachabilityQueue = dispatch_queue_create(StrKeyReachabilityQueue, DISPATCH_QUEUE_SERIAL); + SCNetworkReachabilitySetDispatchQueue(_reachabilityRef, reachabilityQueue); + + return YES; + } + } + + return NO; +} + +- (LVNetworkStatusEnum)currentNetworkStatus +{ + return _currentNetworkStatus; +} + +- (LVNetworkStatusEnum)preNetworkStatus +{ + return _preNetworkStatus; +} + +- (NSString *)currentNetworkStatusString +{ + switch (_currentNetworkStatus) + { + case NotReachable: + return @"unknown"; + + case ReachableVia2G: + return @"2g"; + + case ReachableVia3G: + return @"3g"; + + case ReachableVia4G: + return @"4g"; + + case ReachableViaWiFi: + return @"wifi"; + } +} + +- (LVNetworkStatusEnum)_reachabilityStatus +{ + if (_reachabilityRef) + { + SCNetworkReachabilityFlags flags = 0; + if (SCNetworkReachabilityGetFlags(_reachabilityRef, &flags)) + { + _preNetworkStatus = _currentNetworkStatus; + _currentNetworkStatus = [self _networkStatusForReachabilityFlags:flags]; + } + } + return _currentNetworkStatus; +} + +- (BOOL)checkInternetConnection +{ + struct sockaddr_in zeroAddress; + + bzero(&zeroAddress, sizeof(zeroAddress)); + zeroAddress.sin_len = sizeof(zeroAddress); + zeroAddress.sin_family = AF_INET; + + SCNetworkReachabilityRef defaultRouteReachability = SCNetworkReachabilityCreateWithAddress(NULL, (struct sockaddr *)&zeroAddress); + SCNetworkReachabilityFlags flags; + + BOOL didRetrieveFlags = SCNetworkReachabilityGetFlags(defaultRouteReachability, &flags); + + CFRelease(defaultRouteReachability); + + if (!didRetrieveFlags) + { + return NO; + } + + BOOL isReachable = flags & kSCNetworkFlagsReachable; + BOOL needsConnection = flags & kSCNetworkFlagsConnectionRequired; + + return (isReachable && !needsConnection) ? YES : NO; +} + +- (LVNetworkStatusEnum) currentNetworkStatusForiOS7:(LVNetworkStatusEnum) status +{ + NSString *nettype = netInfo.currentRadioAccessTechnology; + + if (nettype) + { + if([CTRadioAccessTechnologyGPRS isEqualToString:nettype]) + { + return ReachableVia2G; + } + else if([CTRadioAccessTechnologyLTE isEqualToString: nettype] + || [CTRadioAccessTechnologyeHRPD isEqualToString: nettype]) + { + return ReachableVia4G; + } + + } + + return status; +} + +- (LVNetworkStatusEnum)_networkStatusForReachabilityFlags:(SCNetworkReachabilityFlags)flags +{ + if ((flags & kSCNetworkReachabilityFlagsReachable) == 0 || ![self checkInternetConnection]) + { + // The target host is not reachable. + return NotReachable; + } + + LVNetworkStatusEnum returnValue = NotReachable; + + if ((flags & kSCNetworkReachabilityFlagsConnectionRequired) == 0) + { + returnValue = ReachableViaWiFi; + } + + if ((((flags & kSCNetworkReachabilityFlagsConnectionOnDemand ) != 0) || + (flags & kSCNetworkReachabilityFlagsConnectionOnTraffic) != 0)) + { + if ((flags & kSCNetworkReachabilityFlagsInterventionRequired) == 0) + { + returnValue = ReachableViaWiFi; + } + } + + if ((flags & kSCNetworkReachabilityFlagsIsWWAN) == kSCNetworkReachabilityFlagsIsWWAN) + { + returnValue = ReachableVia4G; + } + + if ((flags & kSCNetworkReachabilityFlagsIsWWAN) == kSCNetworkReachabilityFlagsIsWWAN) + { + if((flags & kSCNetworkReachabilityFlagsReachable) == kSCNetworkReachabilityFlagsReachable) + { + if ((flags & kSCNetworkReachabilityFlagsTransientConnection) == kSCNetworkReachabilityFlagsTransientConnection) + { + returnValue = ReachableVia3G; + + if((flags & kSCNetworkReachabilityFlagsConnectionRequired) == kSCNetworkReachabilityFlagsConnectionRequired) + { + returnValue = ReachableVia2G; + } + } + } + } + + if ( returnValue != ReachableViaWiFi ) + { + returnValue = [self currentNetworkStatusForiOS7: returnValue]; + } + + return returnValue; +} + +//网络变化回调函数 +static void ReachabilityCallback(SCNetworkReachabilityRef target, SCNetworkReachabilityFlags flags, void* info) +{ + + [[LVNetworkStatus shareInstance] _reachabilityStatus]; +} + +- (void)dealloc +{ + if (_reachabilityRef) + { + CFRelease(_reachabilityRef); + } +} + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNinePatchImage.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNinePatchImage.h new file mode 100755 index 00000000..b2831f89 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNinePatchImage.h @@ -0,0 +1,11 @@ + + +#import + +@interface LVNinePatchImage : NSObject + ++ (UIImage*) createNinePatchImageNamed:(NSString*)name; ++ (UIImage*) createNinePatchImage:(UIImage*)image; ++ (BOOL) isNinePathImageName:(NSString*) name; + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNinePatchImage.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNinePatchImage.m new file mode 100755 index 00000000..f4e99ba7 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNinePatchImage.m @@ -0,0 +1,167 @@ + + +#import "LVNinePatchImage.h" +#import "LVUtil.h" + +#define BYTES_PER_PIXEL 4 + +@implementation LVNinePatchImage + ++ (unsigned char*)getRGBAsFromImage:(UIImage*)image count:(NSInteger)count { + CGImageRef imageRef = [image CGImage]; + NSUInteger width = CGImageGetWidth(imageRef); + NSUInteger height = CGImageGetHeight(imageRef); + CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); + + unsigned char* rawData = (unsigned char*)calloc(height * width * 4, sizeof(unsigned char)); + + NSUInteger bytesPerRow = BYTES_PER_PIXEL * width; + NSUInteger bitsPerComponent = 8; + CGContextRef context = CGBitmapContextCreate(rawData, width, height, + bitsPerComponent, bytesPerRow, colorSpace, + kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big); + CGColorSpaceRelease(colorSpace); + + CGContextDrawImage(context, CGRectMake(0, 0, width, height), imageRef); + CGContextRelease(context); + return rawData; +} + +inline static CGFloat getImageAphaAtPoint(const unsigned char* rawData, NSInteger width, NSInteger height , NSInteger pointX, NSInteger pointY){ + NSInteger bytesPerRow = BYTES_PER_PIXEL * width; + NSInteger byteIndex = (bytesPerRow * pointY) + pointX * BYTES_PER_PIXEL ; + CGFloat alpha = (rawData[byteIndex + 3] * 1.0) / 255.0; + return alpha; +} + ++ (BOOL) isNinePathImageName:(NSString*) name{ + if ( [name hasSuffix:@".9"] || [name hasSuffix:@".9.png"] || [name hasSuffix:@".9@2x.png"] ) { + return YES; + } + return NO; +} + ++ (UIImage*)createNinePatchImageNamed:(NSString*)name { + if ( [self isNinePathImageName:name] ) { + UIImage* oriImage = [UIImage imageNamed:name]; + if ( oriImage==nil ) { + LVLog(@"createNinePatchImageNamed: The input image is nil"); + return nil; + } + return [self createResizableImageFromNinePatchImage:oriImage]; + } + LVLog(@"createNinePatchImageNamed: Image name is not ended with .9"); + return nil; +} + ++ (UIImage*)createNinePatchImage:(UIImage*)image +{ + return [self createResizableImageFromNinePatchImage:image]; +} + ++ (UIImage*)crop:(CGRect)r image0:(UIImage*)image0 +{ + r = CGRectMake(r.origin.x * image0.scale, + r.origin.y * image0.scale, + r.size.width * image0.scale, + r.size.height * image0.scale); + + CGImageRef imageRef = CGImageCreateWithImageInRect([image0 CGImage], r); + UIImage* ret = [UIImage imageWithCGImage:imageRef + scale:image0.scale + orientation:image0.imageOrientation]; + CGImageRelease(imageRef); + return ret; +} + ++ (UIImage*)createResizableImageFromNinePatchImage:(UIImage*)ninePatchImage +{ + CGImageRef imageRef = [ninePatchImage CGImage]; + NSInteger width = CGImageGetWidth(imageRef); + NSInteger height = CGImageGetHeight(imageRef); + + + NSMutableArray* topBarRgba = [NSMutableArray arrayWithCapacity:0]; + NSMutableArray* leftBarRgba = [NSMutableArray arrayWithCapacity:0]; + { + const unsigned char* rawData = [self getRGBAsFromImage:ninePatchImage count:width*height ]; + for( int x=1; x= 0; i--) { + NSNumber* alpha = topBarRgba[i]; + if ( alpha.floatValue == 1) { + right = i; + break; + } + } + // LVLog(@"The .9 PNG format error!!!. right==-1"); + for (int i = left + 1; i <= right - 1; i++) { + NSNumber* alpha = topBarRgba[i]; + if ( alpha.floatValue < 1) { + LVLog(@"The 9-patch PNG format is not support. 1"); + break; + } + } + count = (int) leftBarRgba.count; + for (int i = 0; i <= count - 1; i++) { + NSNumber* alpha = leftBarRgba[i]; + if ( alpha.floatValue == 1) { + top = i; + break; + } + } + //LVLog(@"The .9 PNG format error!!!. top==-1"); + for (int i = count - 1; i >= 0; i--) { + NSNumber* alpha = leftBarRgba[i]; + if ( alpha.floatValue == 1) { + bottom = i; + break; + } + } + //LVLog(@"The .9 PNG format error!!!. bottom==-1"); + for (int i = top + 1; i <= bottom - 1; i++) { + NSNumber* alpha = leftBarRgba[i]; + if ( alpha.floatValue == 0) { + LVLog(@"The 9-patch PNG format is not support.2"); + break; + } + } + if ( top>=0 && left>=0 && bottom>=0 && right>=0 ) { + UIImage* cropImg = [self crop:CGRectMake(1, 1, ninePatchImage.size.width - 2, ninePatchImage.size.height - 2) image0:ninePatchImage]; + float scale0 = cropImg.scale; + float scale2 = [UIScreen mainScreen].scale; + if ( scale2>scale0 ) { + cropImg = [[UIImage alloc] initWithCGImage:cropImg.CGImage + scale:scale2 + orientation:UIImageOrientationUp]; + float big = scale0/scale2; + UIImage* retImg = [cropImg resizableImageWithCapInsets:UIEdgeInsetsMake(top*big, left*big, bottom*big, right*big)]; + return retImg; + } else { + UIImage* retImg = [cropImg resizableImageWithCapInsets:UIEdgeInsetsMake(top, left, bottom, right) ]; + return retImg; + } + } + return ninePatchImage; +} + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPagerIndicator.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPagerIndicator.h new file mode 100644 index 00000000..e61773af --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPagerIndicator.h @@ -0,0 +1,31 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + +@class LVPagerView; + +@interface LVPagerIndicator : UIPageControl + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; +@property(nonatomic,assign) NSUInteger lv_align; +@property(nonatomic,strong) CAShapeLayer* lv_shapeLayer; + + +-(id) init:(lua_State*) l; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +/* + 关联PagerIndicator用的 + */ +@property(nonatomic,weak) LVPagerView* pagerView; + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPagerIndicator.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPagerIndicator.m new file mode 100644 index 00000000..2e07b189 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPagerIndicator.m @@ -0,0 +1,163 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVPagerIndicator.h" +#import "LVBaseView.h" +#import "LView.h" +#import "LVPagerView.h" +#import "LVHeads.h" + +@implementation LVPagerIndicator + + +-(id) init:(lua_State*) l{ + self = [super init]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + self.clipsToBounds = YES; + self.userInteractionEnabled = NO; + } + return self; +} + +-(void) dealloc{ +} + +#pragma -mark PageControl +static int lvNewPagerIndicator (lua_State *L) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVPagerIndicator class]]; + + LVPagerIndicator* pageControl = [[c alloc] init:L]; + + { + NEW_USERDATA(userData, View); + userData->object = CFBridgingRetain(pageControl); + + luaL_getmetatable(L, META_TABLE_PagerIndicator ); + lua_setmetatable(L, -2); + } + LuaViewCore* view = LV_LUASTATE_VIEW(L); + if( view ){ + [view containerAddSubview:pageControl]; + } + return 1; /* new userdatum is already on the stack */ +} + +//static int setPageCount(lua_State *L) { +// LVUserDataView * user = (LVUserDataView *)lua_touserdata(L, 1); +// if( user ){ +// LVPagerIndicator* view = (__bridge LVPagerIndicator *)(user->view); +// if( view ){ +// if( lua_gettop(L)>=2 ) { +// int number = lua_tonumber(L, 2); +// view.numberOfPages = number; +// return 0; +// } else { +// lua_pushnumber(L, view.numberOfPages ); +// return 1; +// } +// } +// } +// return 0; +//} + +static int setCurrentPage(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVPagerIndicator* view = (__bridge LVPagerIndicator *)(user->object); + if( view ){ + if( lua_gettop(L)>=2 ) { + int currentPage = lua_tonumber(L, 2); + //view.currentPage = currentPage-1; + [view.pagerView setCurrentPageIdx:currentPage-1 animation:YES]; + return 0; + } else { + lua_pushnumber(L, view.currentPage+1 ); + return 1; + } + } + } + return 0; +} + +static int pageIndicatorTintColor(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVPagerIndicator* view = (__bridge LVPagerIndicator *)(user->object); + if( view ){ + if( lua_gettop(L)>=2 ) { + UIColor* color = lv_getColorFromStack(L, 2); + view.pageIndicatorTintColor = color; + return 0; + } else { + UIColor* color = view.pageIndicatorTintColor; + NSUInteger c = 0; + CGFloat a = 0; + if( lv_uicolor2int(color, &c, &a) ){ + lua_pushnumber(L, c ); + lua_pushnumber(L, a); + return 2; + } + } + } + } + return 0; +} + +static int currentPageIndicatorTintColor(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVPagerIndicator* view = (__bridge LVPagerIndicator *)(user->object); + if( view ){ + if( lua_gettop(L)>=2 ) { + UIColor* color = lv_getColorFromStack(L, 2); + view.currentPageIndicatorTintColor = color; + return 0; + } else { + UIColor* color = view.currentPageIndicatorTintColor; + NSUInteger c = 0; + CGFloat a = 0; + if( lv_uicolor2int(color, &c, &a) ){ + lua_pushnumber(L, c ); + lua_pushnumber(L, a); + return 2; + } + } + } + } + return 0; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewPagerIndicator globalName:globalName defaultName:@"PagerIndicator"]; + + const struct luaL_Reg memberFunctions [] = { + {"currentPage", setCurrentPage }, + + {"pageColor", pageIndicatorTintColor },//__deprecated_msg("Use unselectedColor") + {"currentPageColor", currentPageIndicatorTintColor },//__deprecated_msg("Use selectedColor") + + {"unselectedColor", pageIndicatorTintColor }, + {"selectedColor", currentPageIndicatorTintColor }, + {NULL, NULL} + }; + + lv_createClassMetaTable(L, META_TABLE_PagerIndicator); + + luaL_openlib(L, NULL, [LVBaseView baseMemberFunctions], 0); + luaL_openlib(L, NULL, memberFunctions, 0); + + const char* keys[] = { "addView", NULL};// 移除多余API + lv_luaTableRemoveKeys(L, keys ); + return 1; +} + + +//---------------------------------------------------------------------------------------- + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPagerView.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPagerView.h new file mode 100644 index 00000000..0e11dc78 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPagerView.h @@ -0,0 +1,28 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + +@class LVPagerIndicator; +@interface LVPagerView : UIView + + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; +@property(nonatomic,assign) NSUInteger lv_align; +@property(nonatomic,strong) CAShapeLayer* lv_shapeLayer; + + +-(id) init:(lua_State*) l; ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +-(void) setIndicator:(LVPagerIndicator*) indicator; +-(void) setCurrentPageIdx:(NSInteger) pageIdx animation:(BOOL) animation; + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPagerView.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPagerView.m new file mode 100644 index 00000000..1b129212 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPagerView.m @@ -0,0 +1,738 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVPagerView.h" +#import "LView.h" +#import "LVBaseView.h" +#import "LVScrollView.h" +#import "LVPagerViewCell.h" +#import "LVPagerIndicator.h" +#import "LVHeads.h" +#import "LuaViewCore.h" + +static inline NSInteger mapPageIdx(NSInteger pageIdx){ + return pageIdx + 1; +} + +static inline NSInteger unmapPageIdx(NSInteger pageIdx){ + return pageIdx - 1; +} + +#define IDENTIFIER "Id" + +// lua 对应的数据 key +#define USERDATA_KEY_DELEGATE 1 + +#define DEFAULT_CELL_IDENTIFIER @"LVCollectionCell.default.identifier" + +@interface LVPagerView () +@property (nonatomic,strong) UICollectionViewFlowLayout *flowLayout; +@property (nonatomic,strong) NSMutableDictionary* identifierDic; +@property (nonatomic,strong) NSMutableArray* cellArray; + + +@property (nonatomic,assign) NSInteger pageIdx0; +@property (nonatomic,assign) NSInteger pageIdx; +@property (nonatomic,weak) LVPagerIndicator* pagerIndicator; + +@property (nonatomic,strong) NSTimer *timer; + +@property (nonatomic,assign) CGPoint nextOffset; +@property (nonatomic,assign) BOOL looping; +@property (nonatomic,assign) NSInteger isScrollEndTimes; + +@property (nonatomic,strong) UIScrollView *scrollview; +@property (nonatomic,assign) CGFloat sideLeft; +@property (nonatomic,assign) CGFloat sideRight; + +@property (nonatomic,assign) BOOL doubleMode; + +@property (nonatomic,assign) float autoScrollInterval; +@end + + +@implementation LVPagerView + +-(id) init:(lua_State*) l { + self = [super init]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + self.backgroundColor = [UIColor clearColor]; + self.cellArray = [[NSMutableArray alloc] init]; + self.scrollview = ({ + UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)]; + scroll.pagingEnabled = YES; + scroll.clipsToBounds = NO; + scroll; + }) ; + + [self addSubview:self.scrollview]; + self.clipsToBounds = YES; + + self.scrollview.pagingEnabled = YES; + self.scrollview.showsHorizontalScrollIndicator = NO; + self.scrollview.delegate = self; + self.scrollview.scrollsToTop = NO; + self.pageIdx = 0; + self.isScrollEndTimes = 0; + } + return self; +} + +-(void) createAllCell { + NSInteger num = [self numberOfPagesInPageView]; + if( num==2 && ( self.sideLeft!=0 || self.sideRight!=0 ) ) { + // 开始双倍模式 + num = 4; + self.doubleMode = YES; + } else { + self.doubleMode = NO; + } + if( numself.cellArray.count ) { + for( int i=((int)self.cellArray.count); i0 ) { + i += self.pageIdx0; + i += 1000 * count; + return i%count; + } + return i; +} + +// xindex 映射 index +-(NSInteger) xindex2index:(NSInteger) i{ + NSUInteger count = self.cellArray.count; + if( count>0 ) { + i -= self.pageIdx0; + i += 1000 * count; + return i%count; + } + return i; +} + +-(void) resetCellFrame{ + {// ScrollView的滚动大小 + CGRect rect = self.bounds; + rect.origin.x = self.sideLeft; + rect.size.width -= self.sideLeft + self.sideRight; + self.scrollview.frame = rect; + } + NSUInteger count = self.cellArray.count; + CGSize size = self.scrollview.frame.size; + for( NSUInteger i=0; i0 ) { + CGPoint p = self.scrollview.contentOffset; + if( self.looping ) { + if( self.cellArray.count>2 ) { + if( p.x < width*0.5 ) { + self.pageIdx0 += 1; + self.scrollview.contentOffset = CGPointMake( p.x + width, 0); + [self resetCellFrame]; + } else if( p.x> width*1.5 ){ + self.pageIdx0 -= 1; + self.scrollview.contentOffset = CGPointMake( p.x - width, 0); + [self resetCellFrame]; + } + } else { + if( p.x< 0 ) { + self.pageIdx0 += 1; + self.scrollview.contentOffset = CGPointMake( p.x + width, 0); + [self resetCellFrame]; + } else if( p.x>=width ){ + self.pageIdx0 -= 1; + self.scrollview.contentOffset = CGPointMake( p.x - width, 0); + [self resetCellFrame]; + } + } + } + } +} + +-(void) setFrame:(CGRect)frame{ + [super setFrame:frame]; + [self resetCellFrame]; +} + +-(void) checkCellVisible{ + CGPoint p = self.scrollview.contentOffset; + CGRect r0 = self.scrollview.bounds; + r0.origin = p; + r0.origin.x -= self.sideLeft; + r0.size.width += self.sideLeft + self.sideRight; + for( int i=0; i=0 && index=2 ) { + pageIdx = pageIdx-2; + } + if( !cell.isInited ){ + cell.isInited = YES; + [cell doInitWithLView:lview]; + + // 创建cell初始化 + lua_settop(l, 0); + lua_checkstack(l, 12); + [cell pushTableToStack];//arg1: cell + lua_pushnumber(l, mapPageIdx(pageIdx) );//arg2: section + + lv_pushUserdata(l, self.lv_userData); + lv_pushUDataRef(l, USERDATA_KEY_DELEGATE); + [LVUtil call:l key1:"Pages" key2:"Init" key3:NULL nargs:2 nrets:0 retType:LUA_TNONE]; + } + { // 通知布局调整 + // 参数 cell,section,row + lua_settop(l, 0); + lua_checkstack(l, 12); + [cell pushTableToStack];//arg1: cell + lua_pushnumber(l, mapPageIdx(pageIdx) );//arg2: section + + lv_pushUserdata(l, self.lv_userData); + lv_pushUDataRef(l, USERDATA_KEY_DELEGATE); + [LVUtil call:l key1:"Pages" key2:"Layout" key3:NULL nargs:2 nrets:0 retType:LUA_TNONE]; + } + } + [lview popWindow:newWindow]; + return cell; +} + +// section数量 +- (NSInteger) numberOfPagesInPageView{ + lua_State* l = self.lv_luaviewCore.l; + if( l && self.lv_userData ){ + lv_pushUserdata(l, self.lv_userData); + lv_pushUDataRef(l, USERDATA_KEY_DELEGATE); + if( [LVUtil call:l key1:"PageCount" key2:NULL key3:NULL nargs:0 nrets:1 retType:LUA_TNUMBER] ==0 ) { + if( lua_type(l, -1)==LUA_TNUMBER ) { + NSInteger num = lua_tonumber(l, -1); + return num; + } + } + return 1; + } + return 1; +} + +-(void) setPageIndicatorIdx:(NSInteger)pageIdx{ + if( pageIdx>=0 && pageIdx=2 ) { + self.pagerIndicator.currentPage = pageIdx-2; + } else { + self.pagerIndicator.currentPage = pageIdx; + } + } +} + + +-(void) setIndicator:(LVPagerIndicator*) indicator{ + self.pagerIndicator = indicator; + self.pagerIndicator.pagerView = self; + if( self.doubleMode ) { + self.pagerIndicator.numberOfPages = 2; + } else { + self.pagerIndicator.numberOfPages = self.cellArray.count; + } + [self setPageIndicatorIdx:self.pageIdx]; +} + +-(void) setCurrentPageIdx:(NSInteger) pageIdx animation:(BOOL) animation{ + float offsetX = [self index2xindex:pageIdx] * self.scrollview.frame.size.width ; + if( offsetX<=0 ){ + offsetX = 0; + } + float maxOffset = self.scrollview.contentSize.width - self.scrollview.frame.size.width; + if( offsetX > maxOffset ){ + offsetX = maxOffset; + } + //[self setContentOffset:CGPointMake(offsetX, 0) animated:animation]; + self.nextOffset = CGPointMake(offsetX, 0); + if( animation ) { + [self performSelectorOnMainThread:@selector(changeOffsetWithAnimation:) withObject:nil waitUntilDone:NO]; + } else { + [self performSelectorOnMainThread:@selector(changeOffsetNoAnimation:) withObject:nil waitUntilDone:NO]; + } +} + +// 有动画 +-(void) changeOffsetWithAnimation:(NSNumber*) value{ + if( self.lv_luaviewCore ) { + [self.scrollview setContentOffset:self.nextOffset animated:YES]; + } +} + +// 无动画 +-(void) changeOffsetNoAnimation:(NSNumber*) value{ + if( self.lv_luaviewCore ) { + [self.scrollview setContentOffset:self.nextOffset animated:NO]; + } +} + +#pragma -mark lvNewCollectionView +static int lvNewPagerView (lua_State *L) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVPagerView class]]; + + if( lua_gettop(L)<=0 ) { + lua_createtable(L, 8, 0); + } + + if ( lua_gettop(L)>=1 && lua_type(L, 1)==LUA_TTABLE ) { + LVPagerView* pageView = [[c alloc] init:L]; + + NEW_USERDATA(userData, View); + userData->object = CFBridgingRetain(pageView); + pageView.lv_userData = userData; + luaL_getmetatable(L, META_TABLE_UIPageView ); + lua_setmetatable(L, -2); + + LuaViewCore* lview = LV_LUASTATE_VIEW(L); + if( lview ){ + [lview containerAddSubview:pageView]; + } + + int stackNum = lua_gettop(L); + lua_pushvalue(L, 1); + lv_udataRef(L, USERDATA_KEY_DELEGATE ); + + [pageView createAllCell]; + lua_settop(L, stackNum); + + lv_pushUserdata(L, pageView.lv_userData); + return 1; + } + return 0; +} + +-(void) reloadData{ + for( UIView* view in self.cellArray ) { + [view removeFromSuperview]; + } + [self createAllCell]; + [self moveCenter]; + [self checkCellVisible]; + self.autoScrollInterval = self.autoScrollInterval; +} + +-(void) reloadDataASync{ + dispatch_async(dispatch_get_main_queue(), ^{ + [self performSelector:@selector(reloadData) withObject:nil afterDelay:0.001 inModes:@[NSRunLoopCommonModes]]; + }); +} + +static int reload (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVPagerView* pageView = (__bridge LVPagerView *)(user->object); + [pageView reloadDataASync]; + lua_pushvalue(L, 1); + return 1; + } + return 0; +} + +static int showScrollBar(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIScrollView* view = (__bridge UIScrollView *)(user->object); + if( lua_gettop(L)>=2 ) { + BOOL yes1 = lua_toboolean(L, 2); + view.showsHorizontalScrollIndicator = yes1; + return 0; + } else { + lua_pushboolean(L, view.showsHorizontalScrollIndicator ); + return 1; + } + } + return 0; +} + +static int setCurrentPage(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVPagerView* view = (__bridge LVPagerView *)(user->object); + if( lua_gettop(L)>=2 ) { + int luaPageIdx = lua_tonumber(L, 2); + BOOL animated = YES; + if( lua_gettop(L)>=3 ) { + animated = lua_toboolean(L, 3); + } + [view setCurrentPageIdx:unmapPageIdx(luaPageIdx) animation:animated]; + lua_settop(L, 1); + return 1; + } else { + NSInteger currentPageIdx = view.pageIdx; + lua_pushnumber( L, mapPageIdx(currentPageIdx) ); + return 1; + } + } + return 0; +} + +-(void) setAutoScrollInterval:(float) interval{ + _autoScrollInterval = interval; + NSInteger totalPages = self.cellArray.count; + if ( totalPages < 2 ){//小于两个没有效果 + [self stopTimer]; + return ; + } + if ( interval > 0.02 ) {//start timer + [self startTimer:interval repeat:YES]; + } else {//stop timer + [self stopTimer]; + } +} + +static int autoScroll(lua_State *L){ + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if(user){ + LVPagerView * view = (__bridge LVPagerView *)(user -> object); + + if(lua_gettop(L) >= 2) { + float interval = lua_tonumber(L, 2); + [view setAutoScrollInterval:interval]; + } + } + return 0; +} + +static int looping(lua_State *L){ + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if(user){ + LVPagerView * view = (__bridge LVPagerView *)(user -> object); + if( lua_gettop(L)>=2 ) { + BOOL ret = lua_toboolean(L, 2); + view.looping = ret; + return 0; + } else { + BOOL yes = view.looping; + lua_pushboolean(L, yes); + return 1; + } + } + return 0; +} + +#pragma -mark Timer +-(void) stopTimer{ + if( self.timer ) { + [self.timer invalidate]; + self.timer = nil; + } +} + +- (void) startTimer:(NSTimeInterval) interval repeat:(BOOL) repeat{ + self.looping = YES; + [self stopTimer]; + //create new timer + self.timer = [NSTimer scheduledTimerWithTimeInterval:interval target:self selector:@selector(scrollTimer:) userInfo:nil repeats:repeat]; +} + +- (void) scrollTimer:(NSTimer *) timer { + if( self.isScrollEndTimes>1 ) { + //更改方向 + NSInteger width = self.scrollview.frame.size.width; + CGPoint p = self.scrollview.contentOffset; + p.x += width; + p.x = ((NSInteger)p.x) /width * width; + self.nextOffset = p; + [self performSelectorOnMainThread:@selector(changeOffsetWithAnimation:) withObject:nil waitUntilDone:NO]; + } else { + self.isScrollEndTimes ++; + } +} + +static int indicator(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVPagerView* view = (__bridge LVPagerView *)(user->object); + if( lua_gettop(L)>=2 ) { + if ( lua_type(L, 2)==LUA_TNIL ) { + view.pagerIndicator = nil; + [view setIndicator:nil];// 设置Indicator + lua_pushvalue(L, 1); + lv_pushUDataRef(L, USERDATA_KEY_DELEGATE ); + lua_pushnil(L);// value + lua_setfield(L, -2, "Indicator"); + } else { + LVUserDataInfo * user2 = (LVUserDataInfo *)lua_touserdata(L, 2); + if( LVIsType(user2, View) ) { + LVPagerIndicator* pagerIndicator = (__bridge LVPagerIndicator *)(user2->object); + if( [pagerIndicator isKindOfClass:[LVPagerIndicator class]] ) { + [view setIndicator:pagerIndicator];// 设置Indicator + lua_pushvalue(L, 1); + lv_pushUDataRef(L, USERDATA_KEY_DELEGATE ); + lua_pushvalue(L, 2);// value + lua_setfield(L, -2, "Indicator"); + } + } + } + return 0; + } else { + lv_pushUDataRef(L, USERDATA_KEY_DELEGATE ); + lua_getfield(L, -2, "Indicator"); + return 1; + } + } + return 0; +} + +static int previewSide(lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVPagerView* pagerview = (__bridge LVPagerView *)(user->object); + if( lua_gettop(L)>=3 ) { + CGFloat sideLeft = lua_tonumber(L, 2); + CGFloat sideRight = lua_tonumber(L, 3); + pagerview.sideLeft = sideLeft; + pagerview.sideRight = sideRight; + pagerview.frame = pagerview.frame; + if( pagerview.cellArray.count==2 ) { + [pagerview reloadDataASync]; + } + return 0; + } else { + lua_pushnumber(L, pagerview.sideLeft); + lua_pushnumber(L, pagerview.sideRight); + return 2; + } + } + return 0; +} + +#pragma -mark __gc +static void releaseUserDataView(LVUserDataInfo* userdata){ + if( userdata && userdata->object ){ + LVPagerView* view = CFBridgingRelease(userdata->object); + userdata->object = NULL; + if( view ){ + [view.timer invalidate]; + view.scrollview.delegate = nil; + [view.scrollview removeFromSuperview]; + NSArray* subviews = view.scrollview.subviews; + for( UIView* view in subviews ) { + [view removeFromSuperview]; + } + view.scrollview.scrollEnabled = NO; + view.scrollview = nil; + + view.lv_userData = nil; + view.lv_luaviewCore = nil; + [view removeFromSuperview]; + } + } +} + +static int __gc (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + releaseUserDataView(user); + return 0; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewPagerView globalName:globalName defaultName:@"PagerView"]; + + const struct luaL_Reg memberFunctions [] = { + {"reload", reload}, + {"showScrollBar", showScrollBar }, + {"currentPage", setCurrentPage }, + {"autoScroll", autoScroll}, // IOS: 需要支持正反滚动 + {"looping", looping}, + {"indicator", indicator}, + + {"previewSide", previewSide}, + + {"__gc", __gc }, + {NULL, NULL} + }; + + lv_createClassMetaTable(L ,META_TABLE_UIPageView); + + luaL_openlib(L, NULL, [LVBaseView baseMemberFunctions], 0); + luaL_openlib(L, NULL, [LVScrollView memberFunctions], 0); + luaL_openlib(L, NULL, memberFunctions, 0); + + const char* keys[] = { "addView", NULL};// 移除多余API + lv_luaTableRemoveKeys(L, keys ); + return 1; +} + + +- (void) callLuaWithScrolling{ + CGFloat offsetX = self.scrollview.contentOffset.x; + CGFloat pageWidth = self.scrollview.frame.size.width; + CGFloat pageIndex = offsetX/pageWidth; + + self.pageIdx = [self xindex2index:pageIndex]; + [self setPageIndicatorIdx:[self xindex2index:pageIndex + 0.5]]; + + lua_State* l = self.lv_luaviewCore.l; + if( l && self.lv_userData ){ + lua_settop(l, 0); + lua_checkstack32(l); + double intPart = 0; + double floatPart = modf( pageIndex, &intPart); + NSInteger pageIdx = self.pageIdx; + if( self.doubleMode&& pageIdx>=2 ) { + pageIdx -= 2; + } + lua_pushnumber(l, mapPageIdx( pageIdx ) ); + lua_pushnumber(l, floatPart); + lua_pushnumber(l, offsetX - intPart*pageWidth); + + lv_pushUserdata(l, self.lv_userData); + lv_pushUDataRef(l, USERDATA_KEY_DELEGATE); + + [LVUtil call:l key1:STR_CALLBACK key2:"Scrolling" key3:NULL nargs:3 nrets:0 retType:LUA_TNONE]; + } +} + +- (void) callLuaWithScrollEnded{ + { + CGFloat offsetX = self.scrollview.contentOffset.x; + CGFloat pageWidth = self.scrollview.frame.size.width; + CGFloat pageIndex = offsetX/pageWidth; + + self.pageIdx = [self xindex2index:pageIndex + 0.1]; + [self setPageIndicatorIdx:[self xindex2index:pageIndex + 0.1]]; + } + lua_State* l = self.lv_luaviewCore.l; + if( l && self.lv_userData ){ + lua_checkstack32(l); + NSInteger pageIdx = self.pageIdx; + if( self.doubleMode&& pageIdx>=2 ) { + pageIdx -= 2; + } + lua_pushnumber(l, mapPageIdx(pageIdx) ); + + lv_pushUserdata(l, self.lv_userData); + lv_pushUDataRef(l, USERDATA_KEY_DELEGATE); + + [LVUtil call:l key1:STR_CALLBACK key2:"ScrollEnd" key3:NULL nargs:1 nrets:0 retType:LUA_TNONE]; + } +} + +- (void)scrollViewDidScroll:(UIScrollView *)scrollView{ + [self moveCenter]; + [self checkCellVisible]; + + [self callLuaWithScrolling]; +} + +- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{ + self.isScrollEndTimes = 0; + [self lv_callLuaByKey1:@STR_CALLBACK key2:@"ScrollBegin" argN:0]; +} +- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView{ + //[self lv_callLuaByKey1:@STR_CALLBACK key2:@"BeginDecelerating"]; +} + +- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{ + [self callLuaWithScrolling]; + [self callLuaWithScrollEnded]; + self.isScrollEndTimes = 0; +} + +- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView{ + [self callLuaWithScrolling]; + [self callLuaWithScrollEnded]; +} + +- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event +{ + UIView *view = [super hitTest:point withEvent:event]; + if ([view isEqual:self]) + { + UIScrollView* scrollview = self.scrollview; + for (UIView *subview in scrollview.subviews) + { + CGPoint offset = CGPointMake(point.x - scrollview.frame.origin.x + scrollview.contentOffset.x - subview.frame.origin.x, + point.y - scrollview.frame.origin.y + scrollview.contentOffset.y - subview.frame.origin.y); + + if ((view = [subview hitTest:offset withEvent:event])) + { + return view; + } + } + return scrollview; + } + return view; +} + +-(NSString*) description{ + return [NSString stringWithFormat:@"", (int)[self hash], NSStringFromCGRect(self.frame) ]; +} +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPagerViewCell.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPagerViewCell.h new file mode 100644 index 00000000..8ee66ffc --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPagerViewCell.h @@ -0,0 +1,23 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LuaViewCore.h" + +@interface LVPagerViewCell : UIView + +@property (nonatomic, assign) NSInteger index; +@property (nonatomic, assign) BOOL isInited; + +-(void) pushTableToStack; + +-(void) doInitWithLView:(LuaViewCore*) lview; + +-(UIView*) contentView; + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPagerViewCell.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPagerViewCell.m new file mode 100644 index 00000000..66dc12ae --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPagerViewCell.m @@ -0,0 +1,66 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVPagerViewCell.h" +#import "LuaViewCore.h" +#import "lapi.h" + +@interface LVPagerViewCell () +@property (nonatomic,weak) LuaViewCore* lv_luaviewCore; +@end + +@implementation LVPagerViewCell + + + +-(void) dealloc{ + lua_State* L = self.lv_luaviewCore.l; + if( L ) { + [LVUtil unregistry:L key:self]; + } +} + +-(void) doInitWithLView:(LuaViewCore*) lview{ + self.lv_luaviewCore = lview; + lua_State* L = lview.l; + if( L ) { + lua_createtable(L, 0, 0); + [LVUtil registryValue:L key:self stack:-1]; + lv_luaTableSetWeakWindow(L, self); + } +} + +-(void) pushTableToStack{ + lua_State* L = self.lv_luaviewCore.l; + if( L ) { + [LVUtil pushRegistryValue:L key:self]; + } +} + +-(UIView*) contentView{ + return self; +} + +-(NSString*) description{ + return [NSString stringWithFormat:@"", (int)[self hash], NSStringFromCGRect(self.frame)]; +} + +- (void) layoutSubviews{ + [super layoutSubviews]; + [self lv_alignSubviews]; +} + +-(instancetype) init{ + self = [super init]; + if ( self ) { + self.clipsToBounds = YES; + } + return self; +} + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPanGesture.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPanGesture.h new file mode 100644 index 00000000..222b2889 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPanGesture.h @@ -0,0 +1,23 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" +#import "NSObject+LuaView.h" + +@interface LVPanGesture : UIPanGestureRecognizer + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; + +-(id) init:(lua_State*) l; + + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPanGesture.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPanGesture.m new file mode 100644 index 00000000..0eeada88 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPanGesture.m @@ -0,0 +1,74 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVPanGesture.h" +#import "LVGesture.h" +#import "LView.h" +#import "LVHeads.h" + +@implementation LVPanGesture + + +-(void) dealloc{ + [LVGesture releaseUD:_lv_userData]; +} + +-(id) init:(lua_State*) l{ + self = [super initWithTarget:self action:@selector(handleGesture:)]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + } + return self; +} + +-(void) handleGesture:(LVPanGesture*)sender { + lua_State* l = self.lv_luaviewCore.l; + if ( l ){ + lua_checkstack32(l); + lv_pushUserdata(l,self.lv_userData); + [LVUtil call:l lightUserData:self key1:"callback" key2:NULL nargs:1]; + } +} + +static int lvNewPanGestureRecognizer (lua_State *L) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVPanGesture class]]; + { + LVPanGesture* gesture = [[c alloc] init:L]; + + if( lua_type(L, 1) == LUA_TFUNCTION ) { + [LVUtil registryValue:L key:gesture stack:1]; + } + + { + NEW_USERDATA(userData, Gesture); + gesture.lv_userData = userData; + userData->object = CFBridgingRetain(gesture); + + luaL_getmetatable(L, META_TABLE_PanGesture ); + lua_setmetatable(L, -2); + } + } + return 1; /* new userdatum is already on the stack */ +} + + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewPanGestureRecognizer globalName:globalName defaultName:@"PanGesture"]; + + const struct luaL_Reg memberFunctions [] = { + {NULL, NULL} + }; + + lv_createClassMetaTable(L, META_TABLE_PanGesture); + + luaL_openlib(L, NULL, [LVGesture baseMemberFunctions], 0); + luaL_openlib(L, NULL, memberFunctions, 0); + return 1; +} + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPinchGesture.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPinchGesture.h new file mode 100644 index 00000000..991a608a --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPinchGesture.h @@ -0,0 +1,24 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "NSObject+LuaView.h" +#import "LVHeads.h" + +@interface LVPinchGesture : UIPinchGestureRecognizer + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; + +-(id) init:(lua_State*) l; + + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPinchGesture.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPinchGesture.m new file mode 100644 index 00000000..1acd2e8a --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPinchGesture.m @@ -0,0 +1,87 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVPinchGesture.h" +#import "LVGesture.h" +#import "LView.h" +#import "LVHeads.h" + +@implementation LVPinchGesture + +-(void) dealloc{ + LVLog(@"LVPinchGesture.dealloc"); + [LVGesture releaseUD:_lv_userData]; +} + +-(id) init:(lua_State*) l{ + self = [super initWithTarget:self action:@selector(handleGesture:)]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + } + return self; +} + +-(void) handleGesture:(LVPinchGesture*)sender { + lua_State* l = self.lv_luaviewCore.l; + if ( l ){ + lua_checkstack32(l); + lv_pushUserdata(l,self.lv_userData); + [LVUtil call:l lightUserData:self key1:"callback" key2:NULL nargs:1]; + } +} + +static int lvNewPinchGestureRecognizer (lua_State *L) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVPinchGesture class]]; + { + LVPinchGesture* gesture = [[c alloc] init:L]; + + if( lua_type(L, 1) != LUA_TFUNCTION ) { + [LVUtil registryValue:L key:gesture stack:1]; + } + + { + NEW_USERDATA(userData, Gesture); + gesture.lv_userData = userData; + userData->object = CFBridgingRetain(gesture); + + luaL_getmetatable(L, META_TABLE_PinchGesture ); + lua_setmetatable(L, -2); + } + } + return 1; /* new userdatum is already on the stack */ +} + +static int scale (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( LVIsType(user, Gesture) ){ + LVPinchGesture* gesture = (__bridge LVPinchGesture *)(user->object); + float s = gesture.scale; + lua_pushnumber(L, s); + return 1; + } + return 0; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewPinchGestureRecognizer globalName:globalName defaultName:@"PinchGesture"]; + + lv_createClassMetaTable(L ,META_TABLE_PinchGesture); + + luaL_openlib(L, NULL, [LVGesture baseMemberFunctions], 0); + + { + const struct luaL_Reg memberFunctions [] = { + {"scale", scale}, + {NULL, NULL} + }; + luaL_openlib(L, NULL, memberFunctions, 0); + } + return 1; +} + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPointerValueBox.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPointerValueBox.h new file mode 100644 index 00000000..8286f1d6 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPointerValueBox.h @@ -0,0 +1,17 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import + +@interface LVPointerValueBox : NSObject + +-(id) initWithPointer:(void*) pointer; + +@property (nonatomic, assign) void* pointer; + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPointerValueBox.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPointerValueBox.m new file mode 100644 index 00000000..08c050d0 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPointerValueBox.m @@ -0,0 +1,22 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVPointerValueBox.h" + +@implementation LVPointerValueBox + +-(id) initWithPointer:(void*) pointer{ + self = [super init]; + if ( self ){ + self.pointer = pointer; + } + return self; +} + + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRefreshComponent.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRefreshComponent.h new file mode 100644 index 00000000..003cc6d6 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRefreshComponent.h @@ -0,0 +1,81 @@ + +#import +#import "LVRefreshConst.h" +#import "UIScrollView+LVRefresh.h" + +/** 刷新控件的状态 */ +typedef NS_ENUM(NSInteger, LVRefreshState) { + /** 普通闲置状态 */ + LVRefreshStateIdle = 1, + /** 松开就可以进行刷新的状态 */ + LVRefreshStatePulling, + /** 正在刷新中的状态 */ + LVRefreshStateRefreshing, + /** 即将刷新的状态 */ + LVRefreshStateWillRefresh, + /** 所有数据加载完毕,没有更多的数据了 */ + LVRefreshStateNoMoreData +}; + +/** 进入刷新状态的回调 */ +typedef void (^LVRefreshComponentRefreshingBlock)(); + +/** 刷新控件的基类 */ +@interface LVRefreshComponent : UIView +{ + /** 记录scrollView刚开始的inset */ + UIEdgeInsets _scrollViewOriginalInset; + /** 父控件 */ + __weak UIScrollView *_scrollView; +} +#pragma mark - 刷新回调 +/** 正在刷新的回调 */ +@property (copy, nonatomic) LVRefreshComponentRefreshingBlock refreshingBlock; +/** 设置回调对象和回调方法 */ +- (void)setRefreshingTarget:(id)target refreshingAction:(SEL)action; +/** 回调对象 */ +@property (weak, nonatomic) id refreshingTarget; +/** 回调方法 */ +@property (assign, nonatomic) SEL refreshingAction; +/** 触发回调(交给子类去调用) */ +- (void)executeRefreshingCallback; + +#pragma mark - 刷新状态控制 +/** 进入刷新状态 */ +- (void)beginRefreshing; +/** 结束刷新状态 */ +- (void)endRefreshing; +/** 是否正在刷新 */ +- (BOOL)isRefreshing; +/** 刷新状态 一般交给子类内部实现 */ +@property (assign, nonatomic) LVRefreshState state; + +#pragma mark - 交给子类去访问 +/** 记录scrollView刚开始的inset */ +@property (assign, nonatomic, readonly) UIEdgeInsets scrollViewOriginalInset; +/** 父控件 */ +@property (weak, nonatomic, readonly) UIScrollView *scrollView; + +#pragma mark - 交给子类们去实现 +/** 初始化 */ +- (void)prepare NS_REQUIRES_SUPER; +/** 摆放子控件frame */ +- (void)placeSubviews NS_REQUIRES_SUPER; +/** 当scrollView的contentOffset发生改变的时候调用 */ +- (void)scrollViewContentOffsetDidChange:(NSDictionary *)change NS_REQUIRES_SUPER; +/** 当scrollView的contentSize发生改变的时候调用 */ +- (void)scrollViewContentSizeDidChange:(NSDictionary *)change NS_REQUIRES_SUPER; +/** 当scrollView的拖拽状态发生改变的时候调用 */ +- (void)scrollViewPanStateDidChange:(NSDictionary *)change NS_REQUIRES_SUPER; + + +#pragma mark - 其他 +/** 拉拽的百分比(交给子类重写) */ +@property (assign, nonatomic) CGFloat pullingPercent; +/** 根据拖拽比例自动切换透明度 */ +@property (assign, nonatomic, getter=isAutomaticallyChangeAlpha) BOOL automaticallyChangeAlpha; +@end + +@interface UILabel(LVRefresh) ++ (instancetype)label; +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRefreshComponent.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRefreshComponent.m new file mode 100644 index 00000000..236d6ef0 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRefreshComponent.m @@ -0,0 +1,227 @@ + + +#import "LVRefreshComponent.h" +#import "LVRefreshConst.h" +#import +#import + + + +@interface LVRefreshComponent() +@property (strong, nonatomic) UIPanGestureRecognizer *pan; +@end + +@implementation LVRefreshComponent +#pragma mark - 初始化 +- (instancetype)initWithFrame:(CGRect)frame +{ + if (self = [super initWithFrame:frame]) { + // 准备工作 + [self prepare]; + + // 默认是普通状态 + self.state = LVRefreshStateIdle; + } + return self; +} + +- (void)prepare +{ + // 基本属性 + self.autoresizingMask = UIViewAutoresizingFlexibleWidth; + self.backgroundColor = [UIColor clearColor]; +} + +- (void)layoutSubviews +{ + [super layoutSubviews]; + + [self placeSubviews]; +} + +- (void)placeSubviews{} + +- (void)willMoveToSuperview:(UIView *)newSuperview +{ + [super willMoveToSuperview:newSuperview]; + + // 如果不是UIScrollView,不做任何事情 + if (newSuperview && ![newSuperview isKindOfClass:[UIScrollView class]]) return; + + // 旧的父控件移除监听 + [self removeObservers]; + + if (newSuperview) { // 新的父控件 + // 设置宽度 + { + CGRect f = self.frame; + f.size.width = newSuperview.frame.size.width; + self.frame = f; + } + // 设置位置 + { + CGRect f = self.frame; + f.origin.x = 0; + self.frame = f; + } + + // 记录UIScrollView + _scrollView = (UIScrollView *)newSuperview; + // 设置永远支持垂直弹簧效果 + _scrollView.alwaysBounceVertical = YES; + // 记录UIScrollView最开始的contentInset + _scrollViewOriginalInset = _scrollView.contentInset; + + // 添加监听 + [self addObservers]; + } +} + +- (void)drawRect:(CGRect)rect +{ + [super drawRect:rect]; + + if (self.state == LVRefreshStateWillRefresh) { + // 预防view还没显示出来就调用了beginRefreshing + self.state = LVRefreshStateRefreshing; + } +} + +#pragma mark - KVO监听 +- (void)addObservers +{ + NSKeyValueObservingOptions options = NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld; + [self.scrollView addObserver:self forKeyPath:LVRefreshKeyPathContentOffset options:options context:nil]; + [self.scrollView addObserver:self forKeyPath:LVRefreshKeyPathContentSize options:options context:nil]; + self.pan = self.scrollView.panGestureRecognizer; + [self.pan addObserver:self forKeyPath:LVRefreshKeyPathPanState options:options context:nil]; +} + +- (void)removeObservers +{ + [self.superview removeObserver:self forKeyPath:LVRefreshKeyPathContentOffset]; + [self.superview removeObserver:self forKeyPath:LVRefreshKeyPathContentSize];; + [self.pan removeObserver:self forKeyPath:LVRefreshKeyPathPanState]; + self.pan = nil; +} + +- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context +{ + // 遇到这些情况就直接返回 + if (!self.userInteractionEnabled) return; + + // 这个就算看不见也需要处理 + if ([keyPath isEqualToString:LVRefreshKeyPathContentSize]) { + [self scrollViewContentSizeDidChange:change]; + } + + // 看不见 + if (self.hidden) return; + if ([keyPath isEqualToString:LVRefreshKeyPathContentOffset]) { + [self scrollViewContentOffsetDidChange:change]; + } else if ([keyPath isEqualToString:LVRefreshKeyPathPanState]) { + [self scrollViewPanStateDidChange:change]; + } +} + +- (void)scrollViewContentOffsetDidChange:(NSDictionary *)change{} +- (void)scrollViewContentSizeDidChange:(NSDictionary *)change{} +- (void)scrollViewPanStateDidChange:(NSDictionary *)change{} + +#pragma mark - 公共方法 +#pragma mark 设置回调对象和回调方法 +- (void)setRefreshingTarget:(id)target refreshingAction:(SEL)action +{ + self.refreshingTarget = target; + self.refreshingAction = action; +} + +#pragma mark 进入刷新状态 +- (void)beginRefreshing +{ + [UIView animateWithDuration:LVRefreshFastAnimationDuration animations:^{ + self.alpha = 1.0; + }]; + self.pullingPercent = 1.0; + // 只要正在刷新,就完全显示 + if (self.window) { + self.state = LVRefreshStateRefreshing; + } else { + self.state = LVRefreshStateWillRefresh; + // 刷新(预防从另一个控制器回到这个控制器的情况,回来要重新刷新一下) + [self setNeedsDisplay]; + } +} + +#pragma mark 结束刷新状态 +- (void)endRefreshing +{ + self.state = LVRefreshStateIdle; +} + +#pragma mark 是否正在刷新 +- (BOOL)isRefreshing +{ + return self.state == LVRefreshStateRefreshing || self.state == LVRefreshStateWillRefresh; +} + +#pragma mark 自动切换透明度 +- (void)setAutoChangeAlpha:(BOOL)autoChangeAlpha +{ + self.automaticallyChangeAlpha = autoChangeAlpha; +} + +- (BOOL)isAutoChangeAlpha +{ + return self.isAutomaticallyChangeAlpha; +} + +- (void)setAutomaticallyChangeAlpha:(BOOL)automaticallyChangeAlpha +{ + _automaticallyChangeAlpha = automaticallyChangeAlpha; + + if (self.isRefreshing) return; + + if (automaticallyChangeAlpha) { + self.alpha = self.pullingPercent; + } else { + self.alpha = 1.0; + } +} + +#pragma mark 根据拖拽进度设置透明度 +- (void)setPullingPercent:(CGFloat)pullingPercent +{ + _pullingPercent = pullingPercent; + + if (self.isRefreshing) return; + + if (self.isAutomaticallyChangeAlpha) { + self.alpha = pullingPercent; + } +} + +#pragma mark - 内部方法 +- (void)executeRefreshingCallback +{ + dispatch_async(dispatch_get_main_queue(), ^{ + if (self.refreshingBlock) { + self.refreshingBlock(); + } + if ([self.refreshingTarget respondsToSelector:self.refreshingAction]) { + LVRefreshMsgSend(LVRefreshMsgTarget(self.refreshingTarget), self.refreshingAction, self); + } + }); +} +@end + +@implementation UILabel(LVRefresh) ++ (instancetype)label +{ + UILabel *label = [[self alloc] init]; + label.autoresizingMask = UIViewAutoresizingFlexibleWidth; + label.textAlignment = NSTextAlignmentCenter; + label.backgroundColor = [UIColor clearColor]; + return label; +} +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRefreshConst.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRefreshConst.h new file mode 100644 index 00000000..04e8a95e --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRefreshConst.h @@ -0,0 +1,25 @@ + +#import +#import + + +//// 运行时objc_msgSend +#define LVRefreshMsgSend(...) ((void (*)(void *, SEL, UIView *))objc_msgSend)(__VA_ARGS__) +#define LVRefreshMsgTarget(target) (__bridge void *)(target) + + +//// 常量 +UIKIT_EXTERN const CGFloat LVRefreshHeaderHeight; +UIKIT_EXTERN const CGFloat LVRefreshFastAnimationDuration; +UIKIT_EXTERN const CGFloat LVRefreshSlowAnimationDuration; + +UIKIT_EXTERN NSString *const LVRefreshKeyPathContentOffset; +UIKIT_EXTERN NSString *const LVRefreshKeyPathContentSize; +UIKIT_EXTERN NSString *const LVRefreshKeyPathContentInset; +UIKIT_EXTERN NSString *const LVRefreshKeyPathPanState; + +// 状态检查 +#define LVRefreshCheckState \ +LVRefreshState oldState = self.state; \ +if (state == oldState) return; \ +[super setState:state]; diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRefreshConst.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRefreshConst.m new file mode 100644 index 00000000..8ffa2d45 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRefreshConst.m @@ -0,0 +1,12 @@ + +#import + +const CGFloat LVRefreshHeaderHeight = 54.0; +const CGFloat LVRefreshFooterHeight = 44.0; +const CGFloat LVRefreshFastAnimationDuration = 0.25; +const CGFloat LVRefreshSlowAnimationDuration = 0.4; + +NSString *const LVRefreshKeyPathContentOffset = @"contentOffset"; +NSString *const LVRefreshKeyPathContentInset = @"contentInset"; +NSString *const LVRefreshKeyPathContentSize = @"contentSize"; +NSString *const LVRefreshKeyPathPanState = @"state"; diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRefreshHeader.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRefreshHeader.h new file mode 100644 index 00000000..b0002ccf --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRefreshHeader.h @@ -0,0 +1,18 @@ + +#import "LVRefreshComponent.h" + +@interface LVRefreshHeader : LVRefreshComponent +/** 创建header */ ++ (instancetype)headerWithRefreshingBlock:(LVRefreshComponentRefreshingBlock)refreshingBlock; +/** 创建header */ ++ (instancetype)headerWithRefreshingTarget:(id)target refreshingAction:(SEL)action; + +/** 这个key用来存储上一次下拉刷新成功的时间 */ +@property (copy, nonatomic) NSString *lastUpdatedTimeKey; +/** 上一次下拉刷新成功的时间 */ +@property (strong, nonatomic, readonly) NSDate *lastUpdatedTime; + +/** 忽略多少scrollView的contentInset的top */ +@property (assign, nonatomic) CGFloat ignoredScrollViewContentInsetTop; + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRefreshHeader.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRefreshHeader.m new file mode 100644 index 00000000..7ce1ebae --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRefreshHeader.m @@ -0,0 +1,181 @@ + + +#import "LVRefreshHeader.h" + +@interface LVRefreshHeader() +@property (assign, nonatomic) CGFloat insetTDelta; +@end + +@implementation LVRefreshHeader +#pragma mark - 构造方法 ++ (instancetype)headerWithRefreshingBlock:(LVRefreshComponentRefreshingBlock)refreshingBlock +{ + LVRefreshHeader *cmp = [[self alloc] init]; + cmp.refreshingBlock = refreshingBlock; + return cmp; +} ++ (instancetype)headerWithRefreshingTarget:(id)target refreshingAction:(SEL)action +{ + LVRefreshHeader *cmp = [[self alloc] init]; + [cmp setRefreshingTarget:target refreshingAction:action]; + return cmp; +} +#pragma mark - 覆盖父类的方法 +- (void)prepare +{ + [super prepare]; + + // 设置key + self.lastUpdatedTimeKey = @"LVRefreshHeaderLastUpdatedTimeKey"; + + // 设置高度f + { + CGRect frame = self.frame; + frame.size.height = LVRefreshHeaderHeight; + self.frame = frame; + } +} + +- (void)placeSubviews +{ + [super placeSubviews]; + + // 设置y值(当自己的高度发生改变了,肯定要重新调整Y值,所以放到placeSubviews方法中设置y值) + { + CGRect frame = self.frame; + frame.origin.y = - frame.size.height - self.ignoredScrollViewContentInsetTop; + self.frame = frame; + } +} + +- (void)scrollViewContentOffsetDidChange:(NSDictionary *)change +{ + [super scrollViewContentOffsetDidChange:change]; + + // 在刷新的refreshing状态 + if (self.state == LVRefreshStateRefreshing) { + if (self.window == nil) return; + + // sectionheader停留解决 + CGPoint offset = self.scrollView.contentOffset; + CGFloat insetT = - offset.y > _scrollViewOriginalInset.top ? - offset.y : _scrollViewOriginalInset.top; + { + CGRect f = self.frame; + insetT = insetT > f.size.height + _scrollViewOriginalInset.top ? f.size.height + _scrollViewOriginalInset.top : insetT; + } + { + UIEdgeInsets inset = self.scrollView.contentInset; + inset.top = insetT; + self.scrollView.contentInset = inset; + } + + self.insetTDelta = _scrollViewOriginalInset.top - insetT; + return; + } + + // 跳转到下一个控制器时,contentInset可能会变 + _scrollViewOriginalInset = self.scrollView.contentInset; + + // 当前的contentOffset + CGPoint offset = self.scrollView.contentOffset; + CGFloat offsetY = offset.y; + // 头部控件刚好出现的offsetY + CGFloat happenOffsetY = - self.scrollViewOriginalInset.top; + + // 如果是向上滚动到看不见头部控件,直接返回 + // >= -> > + if (offsetY > happenOffsetY) return; + + // 普通 和 即将刷新 的临界点 + CGRect f = self.frame; + CGFloat normal2pullingOffsetY = happenOffsetY - f.size.height; + CGFloat pullingPercent = (happenOffsetY - offsetY) / f.size.height; + + if (self.scrollView.isDragging) { // 如果正在拖拽 + self.pullingPercent = pullingPercent; + if (self.state == LVRefreshStateIdle && offsetY < normal2pullingOffsetY) { + // 转为即将刷新状态 + self.state = LVRefreshStatePulling; + } else if (self.state == LVRefreshStatePulling && offsetY >= normal2pullingOffsetY) { + // 转为普通状态 + self.state = LVRefreshStateIdle; + } + } else if (self.state == LVRefreshStatePulling) {// 即将刷新 && 手松开 + // 开始刷新 + [self beginRefreshing]; + } else if (pullingPercent < 1) { + self.pullingPercent = pullingPercent; + } +} + +- (void)setState:(LVRefreshState)state +{ + LVRefreshCheckState + + // 根据状态做事情 + if (state == LVRefreshStateIdle) { + if (oldState != LVRefreshStateRefreshing) return; + + // 保存刷新时间 + [[NSUserDefaults standardUserDefaults] setObject:[NSDate date] forKey:self.lastUpdatedTimeKey]; + [[NSUserDefaults standardUserDefaults] synchronize]; + + // 恢复inset和offset + [UIView animateWithDuration:LVRefreshSlowAnimationDuration animations:^{ + { + UIEdgeInsets inset = self.scrollView.contentInset; + inset.top += self.insetTDelta; + self.scrollView.contentInset = inset; + } + // 自动调整透明度 + if (self.isAutomaticallyChangeAlpha) self.alpha = 0.0; + } completion:^(BOOL finished) { + self.pullingPercent = 0.0; + }]; + } else if (state == LVRefreshStateRefreshing) { + [UIView animateWithDuration:LVRefreshFastAnimationDuration animations:^{ + // 增加滚动区域 + CGRect f = self.frame; + CGFloat top = self.scrollViewOriginalInset.top + f.size.height; + { + UIEdgeInsets inset = self.scrollView.contentInset; + inset.top = top; + self.scrollView.contentInset = inset; + } + + // 设置滚动位置 + { + CGPoint offset = self.scrollView.contentOffset; + offset.y = - top; + self.scrollView.contentOffset = offset; + } + } completion:^(BOOL finished) { + [self executeRefreshingCallback]; + }]; + } +} + +- (void)drawRect:(CGRect)rect +{ + [super drawRect:rect]; + + +} + +#pragma mark - 公共方法 +- (void)endRefreshing +{ + if ([self.scrollView isKindOfClass:[UICollectionView class]]) { + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + [super endRefreshing]; + }); + } else { + [super endRefreshing]; + } +} + +- (NSDate *)lastUpdatedTime +{ + return [[NSUserDefaults standardUserDefaults] objectForKey:self.lastUpdatedTimeKey]; +} +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRotationGesture.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRotationGesture.h new file mode 100644 index 00000000..6f1c248f --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRotationGesture.h @@ -0,0 +1,22 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" +#import "NSObject+LuaView.h" + +@interface LVRotationGesture : UIRotationGestureRecognizer + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; + +-(id) init:(lua_State*) l; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRotationGesture.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRotationGesture.m new file mode 100644 index 00000000..5ace6f9a --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRotationGesture.m @@ -0,0 +1,88 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVRotationGesture.h" +#import "LVGesture.h" +#import "LView.h" +#import "LVHeads.h" + +@implementation LVRotationGesture + +-(void) dealloc{ + LVLog(@"LVRotationGesture.dealloc"); + [LVGesture releaseUD:_lv_userData]; +} + +-(id) init:(lua_State*) l{ + self = [super initWithTarget:self action:@selector(handleGesture:)]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + } + return self; +} + +-(void) handleGesture:(LVRotationGesture*)sender { + lua_State* l = self.lv_luaviewCore.l; + if ( l ){ + lua_checkstack32(l); + lv_pushUserdata(l,self.lv_userData); + [LVUtil call:l lightUserData:self key1:"callback" key2:NULL nargs:1]; + } +} + +static int lvNewRotationGestureRecognizer (lua_State *L) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVRotationGesture class]]; + { + LVRotationGesture* gesture = [[c alloc] init:L]; + + if( lua_type(L, 1) == LUA_TFUNCTION ) { + [LVUtil registryValue:L key:gesture stack:1]; + } + + { + NEW_USERDATA(userData, Gesture); + gesture.lv_userData = userData; + userData->object = CFBridgingRetain(gesture); + + luaL_getmetatable(L, META_TABLE_RotaionGesture ); + lua_setmetatable(L, -2); + } + } + return 1; /* new userdatum is already on the stack */ +} + +static int rotation (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( LVIsType(user, Gesture) ){ + LVRotationGesture* gesture = (__bridge LVRotationGesture *)(user->object); + float s = gesture.rotation; + lua_pushnumber(L, s); + return 1; + } + return 0; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewRotationGestureRecognizer globalName:globalName defaultName:@"RotationGesture"]; + + lv_createClassMetaTable(L ,META_TABLE_RotaionGesture); + + luaL_openlib(L, NULL, [LVGesture baseMemberFunctions], 0); + + { + const struct luaL_Reg memberFunctions [] = { + {"rotation", rotation}, + {NULL, NULL} + }; + luaL_openlib(L, NULL, memberFunctions, 0); + } + return 1; +} + + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVScrollView.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVScrollView.h new file mode 100644 index 00000000..2f48ec67 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVScrollView.h @@ -0,0 +1,28 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" +#import "UIScrollView+LuaView.h" + +@interface LVScrollView : UIScrollView + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; +@property(nonatomic,assign) NSUInteger lv_align; +@property(nonatomic,strong) CAShapeLayer* lv_shapeLayer; + +-(id) init:(lua_State*) l; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + ++(const struct luaL_Reg*) memberFunctions; + +@property(nonatomic,weak) id lvScrollViewDelegate; + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVScrollView.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVScrollView.m new file mode 100644 index 00000000..f913f0c6 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVScrollView.m @@ -0,0 +1,395 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVScrollView.h" +#import "LVBaseView.h" +#import "LVUtil.h" +#import "UIScrollView+LuaView.h" +#import "LVScrollViewDelegate.h" +#import "LVHeads.h" +#import "LView.h" + +@interface LVScrollView () +@property (nonatomic,strong) LVScrollViewDelegate* scrollViewDelegate; +@end + +@implementation LVScrollView + + +-(id) init:(lua_State*) l{ + self = [super init]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + self.scrollViewDelegate = [[LVScrollViewDelegate alloc] init:self]; + self.delegate = self.scrollViewDelegate; + self.alwaysBounceHorizontal = YES; + self.alwaysBounceVertical = NO; + self.showsHorizontalScrollIndicator = NO; + self.showsVerticalScrollIndicator = NO; + self.scrollsToTop = NO; + } + return self; +} + +-(void) setLvScrollViewDelegate:(id)lvScrollViewDelegate{ + _lvScrollViewDelegate = lvScrollViewDelegate; + self.scrollViewDelegate.delegate = lvScrollViewDelegate; +} + +-(void) dealloc{ +} + +- (BOOL)touchesShouldCancelInContentView:(UIView *)view { + return YES; +} + +- (void) layoutSubviews{ + [super layoutSubviews]; + [self lv_alignSubviews]; + [self lv_callLuaByKey1:@STR_ON_LAYOUT]; +} + +#pragma -mark ScrollView +static int lvNewScrollView (lua_State *L) { + { + Class c = [LVUtil upvalueClass:L defaultClass:[LVScrollView class]]; + + LVScrollView* scrollView = [[c alloc] init:L]; + + NEW_USERDATA(userData, View); + userData->object = CFBridgingRetain(scrollView); + scrollView.lv_userData = userData; + + //创建delegate用的事件存储器 + lua_createtable(L, 0, 0); + lv_udataRef(L, USERDATA_KEY_DELEGATE ); + + luaL_getmetatable(L, META_TABLE_UIScrollView ); + lua_setmetatable(L, -2); + + LuaViewCore* view = LV_LUASTATE_VIEW(L); + if( view ){ + [view containerAddSubview:scrollView]; + } + } + return 1; /* new userdatum is already on the stack */ +} + +static int contentSize (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIScrollView* view = (__bridge UIScrollView *)(user->object); + if( [view isKindOfClass:[UIScrollView class]] ){ + if( lua_gettop(L)>=2 ) { + double w = lua_tonumber(L, 2);// 2 + double h = lua_tonumber(L, 3);// 3 + CGSize s = CGSizeMake( w, h ); + if ( isNormalSize(s) ) { + view.contentSize = s; + } + return 0; + } else { + CGSize s = view.contentSize; + lua_pushnumber(L, s.width ); + lua_pushnumber(L, s.height ); + return 2; + } + } + } + return 0; +} + +static int contentOffset (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIScrollView* view = (__bridge UIScrollView *)(user->object); + if( lua_gettop(L)>=2 ) { + double x = lua_tonumber(L, 2);// 2 + double y = lua_tonumber(L, 3);// 3 + BOOL yes = NO; + if( lua_gettop(L)>=4 ) + yes = lua_toboolean(L, 4);// 3 + if( [view isKindOfClass:[UIScrollView class]] ){ + CGPoint p = CGPointMake(x, y); + if( isNormalPoint(p) ) { + CGRect r = view.frame; + r.origin.x = x; + r.origin.y = y; + if( x > view.contentSize.width-view.frame.size.width ) { + x = view.contentSize.width-view.frame.size.width; + } + if( x < 0 ) { + x = 0; + } + if( y > view.contentSize.height-view.frame.size.height ) { + y = view.contentSize.height-view.frame.size.height; + } + if( y < 0 ) { + y = 0; + } + [view setContentOffset:CGPointMake(x, y) animated:yes]; + } + return 0; + } + } else { + CGPoint p = view.contentOffset; + lua_pushnumber(L, p.x ); + lua_pushnumber(L, p.y ); + return 2; + } + } + return 0; +} + +static int contentInset (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIScrollView* view = (__bridge UIScrollView *)(user->object); + if( [view isKindOfClass:[UIScrollView class]] ){ + int num = lua_gettop(L); + if( num>=2 ) { + UIEdgeInsets edgeInsets = view.contentInset; + if( num>=2 ) + edgeInsets.top = lua_tonumber(L, 2); + if( num>=3 ) + edgeInsets.left = lua_tonumber(L, 3); + if( num>=4 ) + edgeInsets.bottom = lua_tonumber(L, 4); + if( num>=5 ) + edgeInsets.right = lua_tonumber(L, 5); + if( isNormalEdgeInsets(edgeInsets) ) { + view.contentInset = edgeInsets; + view.scrollIndicatorInsets = edgeInsets; + } + return 0; + } else { + UIEdgeInsets edgeInsets = view.contentInset; + lua_pushnumber(L, edgeInsets.top ); + lua_pushnumber(L, edgeInsets.left ); + lua_pushnumber(L, edgeInsets.bottom ); + lua_pushnumber(L, edgeInsets.right ); + return 4; + } + } + } + return 0; +} + +//static int pageEnable (lua_State *L) { +// LVUserDataView * user = (LVUserDataView *)lua_touserdata(L, 1); +// if( user ){ +// UIScrollView* view = (__bridge UIScrollView *)(user->view); +// if( [view isKindOfClass:[UIScrollView class]] ){ +// if( lua_gettop(L)>=2 ) { +// BOOL yes = lua_toboolean(L, 2);// 2 +// view.pagingEnabled = yes; +// return 0; +// } else { +// lua_pushnumber(L, view.pagingEnabled ); +// return 1; +// } +// } +// } +// return 0; +//} + +static int showScrollIndicator (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + UIScrollView* view = (__bridge UIScrollView *)(user->object); + if( [view isKindOfClass:[UIScrollView class]] ){ + if( lua_gettop(L)>=2 ) { + BOOL yes1 = lua_toboolean(L, 2); + BOOL yes2 = lua_toboolean(L, 3); + view.showsHorizontalScrollIndicator = yes1; + view.showsVerticalScrollIndicator = yes2; + return 0; + } else { + lua_pushboolean(L, view.showsHorizontalScrollIndicator ); + lua_pushboolean(L, view.showsVerticalScrollIndicator ); + return 2; + } + } + } + return 0; +} + +//static int initRefreshHeader (lua_State *L) { +// LVUserDataView * user = (LVUserDataView *)lua_touserdata(L, 1); +// if( user ){ +// UIScrollView* scrollView = (__bridge UIScrollView *)(user->view); +// [scrollView lv_initRefreshHeader]; +// } +// return 0; +//} + +static int startHeaderRefreshing (lua_State *L){ + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVScrollView* scrollView = (__bridge LVScrollView *)(user->object); + [scrollView lv_beginRefreshing]; + } + return 0; +} + +static int stopHeaderRefreshing (lua_State *L){ + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVScrollView* scrollView = (__bridge LVScrollView *)(user->object); + [scrollView lv_endRefreshing]; + } + return 0; +} + +static int isHeaderRefreshing (lua_State *L){ + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVScrollView* scrollView = (__bridge LVScrollView *)(user->object); + BOOL yes = [scrollView lv_isRefreshing]; + lua_pushboolean(L, yes); + return 1; + } + return 0; +} + +//static int footerNoticeNoMoreData (lua_State *L){ +// LVUserDataView * user = (LVUserDataView *)lua_touserdata(L, 1); +// if( user ){ +// LVScrollView* scrollView = (__bridge LVScrollView *)(user->view); +// [scrollView lv_noticeNoMoreData]; +// } +// return 0; +//} +// +//static int footerResetNoMoreData (lua_State *L){ +// LVUserDataView * user = (LVUserDataView *)lua_touserdata(L, 1); +// if( user ){ +// LVScrollView* scrollView = (__bridge LVScrollView *)(user->view); +// [scrollView lv_resetNoMoreData]; +// } +// return 0; +//} +// +//static int hiddenRefreshFooter (lua_State *L){ +// LVUserDataView * user = (LVUserDataView *)lua_touserdata(L, 1); +// if( user ){ +// LVScrollView* scrollView = (__bridge LVScrollView *)(user->view); +// BOOL hidden = lua_toboolean(L, 2); +// [scrollView lv_hiddenRefreshFooter:hidden]; +// } +// return 0; +//} + +//static int alwaysBounce(lua_State *L) { +// LVUserDataView * user = (LVUserDataView *)lua_touserdata(L, 1); +// if( user ){ +// UIScrollView* view = (__bridge UIScrollView *)(user->view); +// if( [view isKindOfClass:[UIScrollView class]] ){ +// if( lua_gettop(L)>=2 ) { +// BOOL yesVertical = lua_toboolean(L, 2); +// BOOL yesHorizontal = lua_toboolean(L, 3); +// view.alwaysBounceVertical = yesVertical; +// view.alwaysBounceHorizontal = yesHorizontal; +// return 0; +// } else { +// lua_pushboolean(L, view.alwaysBounceVertical); +// lua_pushboolean(L, view.alwaysBounceHorizontal); +// return 2; +// } +// } +// } +// return 0; +//} + +static int callback (lua_State *L) { + return lv_setCallbackByKey(L, nil, NO); +} + +static void releaseUserDataView(LVUserDataInfo* userdata){ + if( userdata && userdata->object ){ + UIView* view = CFBridgingRelease(userdata->object); + userdata->object = NULL; + if( view ){ + view.lv_userData = nil; + view.lv_luaviewCore = nil; + [view removeFromSuperview]; + [view.layer removeFromSuperlayer]; + if( [view isKindOfClass:[UICollectionView class]] ) { + UICollectionView* collectionView = (UICollectionView*)view; + collectionView.delegate = nil; + collectionView.dataSource = nil; + collectionView.scrollEnabled = NO; + } else if( [view isKindOfClass:[UIScrollView class]] ) { + UIScrollView* scrollView = (UIScrollView*)view; + scrollView.delegate = nil; + scrollView.scrollEnabled = NO; + } + } + } +} + +#pragma -mark __gc +static int __gc (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + releaseUserDataView(user); + return 0; +} + +static const struct luaL_Reg memberFunctions [] = { + {"callback", callback },// 回调 + {"initParams", callback },// 回调 + + {"contentSize", contentSize },// for IOS + {"offset", contentOffset },// + // offsetBy + + {"contentInset", contentInset },// for IOS + + {"showScrollIndicator", showScrollIndicator },// for IOS + + // 下拉刷新 + // {"initRefreshing", initRefreshHeader}, + {"startRefreshing", startHeaderRefreshing},// for IOS ScrollView + {"stopRefreshing", stopHeaderRefreshing},// for IOS ScrollView + {"isRefreshing", isHeaderRefreshing},// for IOS ScrollView + + // 上拉加载更多 + // {"footerNoticeNoMoreData", footerNoticeNoMoreData}, + // {"footerResetNoMoreData", footerResetNoMoreData}, + // {"hiddenRefreshFooter", hiddenRefreshFooter}, + + {"__gc", __gc }, + {NULL, NULL} +}; + ++(const struct luaL_Reg*) memberFunctions{ + return memberFunctions; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewScrollView globalName:globalName defaultName:@"HScrollView"]; + [LVUtil reg:L clas:self cfunc:lvNewScrollView globalName:globalName defaultName:@"HorizontalScrollView"]; + + lv_createClassMetaTable(L ,META_TABLE_UIScrollView); + + luaL_openlib(L, NULL, [LVBaseView baseMemberFunctions], 0); + luaL_openlib(L, NULL, memberFunctions, 0); + + const char* keys[] = { "startRefreshing", "stopRefreshing", "isRefreshing", NULL};// 移除多余API + lv_luaTableRemoveKeys(L, keys ); + return 1; +} + + +//---------------------------------------------------------------------------------------- + +-(NSString*) description{ + return [NSString stringWithFormat:@"", (int)[self hash], + NSStringFromCGRect(self.frame),NSStringFromCGSize(self.contentSize) ]; +} +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVScrollViewDelegate.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVScrollViewDelegate.h new file mode 100644 index 00000000..94f8592a --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVScrollViewDelegate.h @@ -0,0 +1,18 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ +#import +#import + +@interface LVScrollViewDelegate : NSObject + +@property(nonatomic,weak) UIView* owner; +@property(nonatomic,weak) id delegate; + +-(id) init:(UIView*) view; + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVScrollViewDelegate.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVScrollViewDelegate.m new file mode 100644 index 00000000..30c73d8a --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVScrollViewDelegate.m @@ -0,0 +1,72 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVScrollViewDelegate.h" +#import "UIView+LuaView.h" + + +@implementation LVScrollViewDelegate + +-(id) init:(UIView*) tableView{ + self = [super init]; + if( self ){ + self.owner = tableView; + } + return self; +} + +- (void)scrollViewDidScroll:(UIScrollView *)scrollView{ + [self.owner lv_callLuaByKey1:@"Scrolling"]; + if( [self.delegate respondsToSelector:@selector(scrollViewDidScroll:)] ) { + [self.delegate scrollViewDidScroll:scrollView]; + } +} + +- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView{ + if( [self.delegate respondsToSelector:@selector(scrollViewWillBeginDecelerating:)] ) { + [self.delegate scrollViewWillBeginDecelerating:scrollView]; + } +} + +- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{ + [self.owner lv_callLuaByKey1:@"ScrollEnd"]; + if( [self.delegate respondsToSelector:@selector(scrollViewDidEndDecelerating:)] ) { + [self.delegate scrollViewDidEndDecelerating:scrollView]; + } +} + +- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView{ + [self.owner lv_callLuaByKey1:@"ScrollEnd"]; + if( [self.delegate respondsToSelector:@selector(scrollViewDidEndScrollingAnimation:)] ) { + [self.delegate scrollViewDidEndScrollingAnimation:scrollView]; + } +} + +- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{ + [self.owner lv_callLuaByKey1:@"ScrollBegin"]; + if( [self.delegate respondsToSelector:@selector(scrollViewWillBeginDragging:)] ) { + [self.delegate scrollViewWillBeginDragging:scrollView]; + } +} + +- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset { + [self.owner lv_callLuaByKey1:@"DragEnd"]; +} + +- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{ + [self.owner lv_callLuaByKey1:@"DragEnd"]; + if( !decelerate ) { + [self.owner lv_callLuaByKey1:@"ScrollEnd"]; + } + if( [self.delegate respondsToSelector:@selector(scrollViewDidEndDragging:willDecelerate:)] ) { + [self.delegate scrollViewDidEndDragging:scrollView willDecelerate:decelerate]; + } +} + + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVStruct.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVStruct.h new file mode 100644 index 00000000..65b98c9b --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVStruct.h @@ -0,0 +1,26 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + +#define LV_STRUCT_MAX_LEN 16 + +@interface LVStruct : NSObject +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; +- (id) lv_nativeObject; // 返回native对象 + + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + ++(int) pushStructToLua:(lua_State*)L data:(void*)data; + +-(CGFloat*) dataPointer; + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVStruct.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVStruct.m new file mode 100644 index 00000000..ddefbe58 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVStruct.m @@ -0,0 +1,223 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVStruct.h" +#import "LVTypeConvert.h" +#import "LVHeads.h" + + + +@implementation LVStruct{ + CGFloat data[LV_STRUCT_MAX_LEN]; +} + +-(void) setIndex:(NSInteger)index byValue:(CGFloat) value{ + if( index>=0 && index=0 && indexobject = CFBridgingRetain(lvstruct); + lvstruct.lv_userData = userData; + + int num = lua_gettop(L); + + for (int i=1,index=0; (i<=num) && (indexobject = CFBridgingRetain(lvstruct); + lvstruct.lv_userData = userData; + + memcpy( [lvstruct dataPointer], data, LV_STRUCT_MAX_LEN*sizeof(CGFloat) ); + luaL_getmetatable(L, META_TABLE_Struct ); + lua_setmetatable(L, -2); + return 1; +} + + +static int setValue (lua_State *L) { + int argNum = lua_gettop(L); + if( argNum>=3 ) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + unsigned int index = lua_tonumber(L, 2); + CGFloat value = lua_tonumber(L, 3); + if ( index>=LV_STRUCT_MAX_LEN ) { + LVError(@"LVStruct.set index:%d", index ); + return 0; + } + if( LVIsType(user, Struct) ){ + LVStruct* lvstruct = (__bridge LVStruct *)(user->object); + if ( argNum>=4 ) { + int type = lua_tonumber(L, 4); + if( [lvstruct dataPointer] ) { + lv_setValueWithType( [lvstruct dataPointer], index, value, type); + } + } else { + [lvstruct setIndex:index byValue:value]; + } + return 0; + } + } + return 0; +} + +static int getValue (lua_State *L) { + int argNum = lua_gettop(L); + if( argNum>=2 ) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + unsigned int index = lua_tonumber(L, 2); + if ( index>=LV_STRUCT_MAX_LEN ) { + LVError(@"LVStruct.get index:%d", index ); + return 0; + } + if( LVIsType(user, Struct) ){ + LVStruct* stru = (__bridge LVStruct *)(user->object); + if ( argNum>=3 ) { + int type = lua_tonumber(L, 3); + CGFloat value = lv_getValueWithType( [stru dataPointer], index, type); + lua_pushnumber(L, value); + return 1; + } else { + CGFloat value = [stru getValueByIndex:index]; + lua_pushnumber(L, value); + return 1; + } + } + } + return 0; +} + +static int __eq (lua_State *L) { + if( lua_gettop(L)==2 ) { + LVUserDataInfo * user1 = (LVUserDataInfo *)lua_touserdata(L, 1); + LVUserDataInfo * user2 = (LVUserDataInfo *)lua_touserdata(L, 2); + if( LVIsType(user1, Struct) && LVIsType(user2, Struct) ){ + LVStruct* s1 = (__bridge LVStruct *)(user1->object); + LVStruct* s2 = (__bridge LVStruct *)(user2->object); + int size = LV_STRUCT_MAX_LEN; + BOOL yes = NO; + if( [s1 dataPointer] && [s2 dataPointer] ) { + yes = !memcmp( [s1 dataPointer], [s2 dataPointer], size); + } + lua_pushboolean(L, (yes?1:0) ); + return 1; + } + } + return 0; +} + +static int __tostring (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( LVIsType(user, Struct) ){ + NSString* s = [NSString stringWithFormat:@"LVUserDataStruct: %d", (int)user ]; + lua_pushstring(L, s.UTF8String); + return 1; + } + return 0; +} + +static int __index (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + if ( lua_type(L, 2)==LUA_TNUMBER ) { + return getValue(L); + } else if ( lua_type(L, 2)==LUA_TSTRING ){ + NSString* key = lv_paramString(L, 2); + if ( [key isEqualToString:@"get"] ) { + lua_pushcfunction(L, getValue); + return 1; + } + if ( [key isEqualToString:@"set"] ) { + lua_pushcfunction(L, setValue); + return 1; + } + } + } + return 0; /* new userdatum is already on the stack */ +} + +static int __newindex (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + if( lua_type(L, 2)==LUA_TNUMBER ){ + return setValue(L); + } else if( lua_type(L, 3)==LUA_TSTRING ){ + + } + } + return 0; /* new userdatum is already on the stack */ +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + lv_defineGlobalFunc("Struct", lvNewStruct, L); + lv_defineGlobalFunc("Rect", lvNewStruct, L); + lv_defineGlobalFunc("Size", lvNewStruct, L); + lv_defineGlobalFunc("Point", lvNewStruct, L); + + const struct luaL_Reg memberFunctions [] = { + {"__index", __index }, + {"__newindex", __newindex }, + {"__eq", __eq}, + + {"set", setValue}, + {"get", getValue}, + + {"__tostring", __tostring}, + + {NULL, NULL} + }; + + lv_createClassMetaTable(L ,META_TABLE_Struct); + + luaL_openlib(L, NULL, memberFunctions, 0); + +// { +// const struct luaL_Reg memberFunctions2 [] = { +// {"__index", __index }, +// {"__newindex", __newindex }, +// {NULL, NULL} +// }; +// lv_createClassMetaTable(L ,"META_TABLE_Struct" ); +// luaL_openlib(L, NULL, memberFunctions2, 0); +// +// luaL_getmetatable(L, META_TABLE_Struct ); +// luaL_getmetatable(L, "META_TABLE_Struct" ); +// lua_setmetatable(L, -2); +// } + return 1; +} + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVStyledString.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVStyledString.h new file mode 100644 index 00000000..42a2001d --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVStyledString.h @@ -0,0 +1,24 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + + +//LVData +@interface LVStyledString : NSObject + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; + +@property(nonatomic,strong) NSMutableAttributedString* mutableStyledString;//真实的数据 + +-(id) init:(lua_State*) l; ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVStyledString.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVStyledString.m new file mode 100644 index 00000000..094a76b8 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVStyledString.m @@ -0,0 +1,311 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVStyledString.h" +#import "LVHeads.h" +#import "LView.h" + +@interface LVStyledString () +@end + +@implementation LVStyledString + +-(id) init:(lua_State *)l{ + self = [super init]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + } + return self; +} + +- (id) lv_nativeObject{ + return self.mutableStyledString; +} + +static void releaseUserDataData(LVUserDataInfo* user){ + if( user && user->object ){ + LVStyledString* data = CFBridgingRelease(user->object); + user->object = NULL; + if( data ){ + data.lv_userData = NULL; + data.lv_luaviewCore = nil; + data.mutableStyledString = nil; + } + } +} + +static int __attributedString_gc (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + releaseUserDataData(user); + return 0; +} + +static UIFont* getFont(NSString* fontName, NSNumber* fontSize, NSString* fontWeigth, NSString* fontStyle, LVBundle* bundle){ + fontSize = fontSize ? fontSize : @(14);// bugfix: 不设置字体大小, 只设置粗体斜体无效, 所以给定默认字体大小14 + if( [fontName isKindOfClass:[NSString class]] ){ + return [LVUtil fontWithName:fontName size:fontSize.floatValue bundle:bundle]; + } + if ( [fontStyle isKindOfClass:[NSString class]] && + [fontStyle compare:@"italic" options:NSCaseInsensitiveSearch]==NSOrderedSame ) { + return [UIFont italicSystemFontOfSize:fontSize.floatValue]; + } + if( [fontWeigth isKindOfClass:[NSString class]] && + [fontWeigth compare:@"bold" options:NSCaseInsensitiveSearch]==NSOrderedSame ){ + // TODO: 支持数值? + return [UIFont boldSystemFontOfSize:fontSize.floatValue]; + } + return [UIFont systemFontOfSize:fontSize.floatValue]; +} + +// 设置字体 +static void resetFont(NSMutableAttributedString* attString, NSDictionary* dic, NSRange range, LVBundle* bundle){ + NSString* fontName = dic[@"fontName"]; + NSNumber* fontSize = dic[@"fontSize"]; + NSString* fontWeight = dic[@"fontWeight"]; + NSString* fontStyle = dic[@"fontStyle"]; + UIFont* font = getFont(fontName, fontSize, fontWeight, fontStyle, bundle); + if( font ) { + [attString addAttribute:NSFontAttributeName value:font range:range]; + } +} + +// 设置前景色 +static void resetForegroundColor(NSMutableAttributedString* attString, NSDictionary* dic, NSRange range){ + NSNumber* value = dic[@"fontColor"]; + float alpha = 1; + if( value ) { + alpha = (value.integerValue>>24) & 0xff; + alpha /= 255.0; + if( alpha == 0) { + alpha = 1; + } + UIColor* color = lv_UIColorFromRGBA(value.integerValue , alpha ); + [attString addAttribute:NSForegroundColorAttributeName value:color range:range]; + } +} + +// 设置背景色 +static void resetBackgroundColor(NSMutableAttributedString* attString, NSDictionary* dic, NSRange range){ + NSNumber* value = dic[@"backgroundColor"]; + float alpha = 1; + if( value ) { + alpha = (value.integerValue>>24) & 0xff; + alpha /= 255.0; + if( alpha == 0) { + alpha = 1; + } + UIColor* color = lv_UIColorFromRGBA(value.integerValue , alpha ); + [attString addAttribute:NSBackgroundColorAttributeName value:color range:range]; + } +} + +static BOOL isNotZeroOrFalse( id value ){ + if( [value isKindOfClass:[NSNumber class]] ) { + NSNumber* v = value; + if( v.intValue == 0 ){ + return NO; + } + if( v.boolValue== NO ) { + return NO; + } + } + return YES; +} + +// 设置划线 +static void resetStriketrhroughSytle(NSMutableAttributedString* attString, NSDictionary* dic, NSRange range){ + NSNumber* value = dic[@"strikethrough"]; + if( value && isNotZeroOrFalse(value) ){ + [attString addAttribute:NSStrikethroughStyleAttributeName value:value range:range]; + } else { + // IOS 8 系统bugfix( 有中划线和我无中划线都要设置属性, 否则有中划线不会出现 ) + [attString addAttribute:NSStrikethroughStyleAttributeName value:@(NSUnderlineStyleNone) range:range]; + } +} + +//下划线 +static void resetUnderLineStyle(NSMutableAttributedString* attString, NSDictionary* dic, NSRange range){ + NSNumber* value = dic[@"underline"]; + if( value && isNotZeroOrFalse(value) ){ + [attString addAttribute:NSUnderlineStyleAttributeName value:value range:range]; + } +} + +//设置字间距 +static void resetCharSpace(NSMutableAttributedString* attString, NSDictionary* dic, NSRange range){ + NSNumber* value = dic[@"charSpace"]; + if( value ){ + [attString addAttribute:(id)NSKernAttributeName value:value range:range]; + } +} + +//设置行间距 +static void resetLineSpace(NSMutableAttributedString* attString, NSDictionary* dic, NSRange range){ + NSNumber* value = dic[@"lineSpace"]; + if( value ) { + NSMutableParagraphStyle * paragraphStyle1 = [[NSMutableParagraphStyle alloc] init]; + paragraphStyle1.lineBreakMode = NSLineBreakByTruncatingTail; + [paragraphStyle1 setLineSpacing:value.intValue]; + [attString addAttribute:(id)NSParagraphStyleAttributeName value:paragraphStyle1 range:range]; + } +} + + +static void resetAttributedString(NSMutableAttributedString* attString, NSDictionary* dic, NSRange range ,LVBundle* bundle){ + resetFont(attString, dic, range, bundle); + resetForegroundColor(attString, dic, range); + resetBackgroundColor(attString, dic, range); + resetStriketrhroughSytle(attString, dic, range); + resetUnderLineStyle(attString, dic, range); + resetCharSpace(attString, dic, range); + resetLineSpace(attString, dic, range); +} + +static int lvNewAttributedString (lua_State *L) { + LuaViewCore* luaView = LV_LUASTATE_VIEW(L); + LVStyledString* attString = [[LVStyledString alloc] init:L]; + if( luaView && lua_gettop(L)>=2 ) { + if( ( lua_type(L, 1)==LUA_TSTRING || lua_type(L, 1)==LUA_TNUMBER ) && lua_type(L, 2)==LUA_TTABLE ){ + NSString* s = nil; + size_t n = 0; + const char* chars = lua_tolstring(L, 1, &n ); + s = [NSString stringWithUTF8String:chars]; + + // 字符串格式非法,导致crash + if( s==nil ) { + s = @""; + } + + attString.mutableStyledString = [[NSMutableAttributedString alloc] initWithString:s]; + + NSDictionary* dic = lv_luaTableToDictionary(L,2); + NSRange range = {0}; + range.location = 0; + range.length = s.length; + if( [dic isKindOfClass:[NSDictionary class]] ) { + resetAttributedString(attString.mutableStyledString, dic, range, luaView.bundle); + } + } + } + + { + NEW_USERDATA(userData, StyledString); + userData->object = CFBridgingRetain(attString); + attString.lv_userData = userData; + + luaL_getmetatable(L, META_TABLE_AttributedString ); + lua_setmetatable(L, -2); + } + return 1; +} + +static int __tostring (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVStyledString* attString = (__bridge LVStyledString *)(user->object); + NSString* s = attString.mutableStyledString.string; + if( s==nil ){ + s = [[NSString alloc] initWithFormat:@"{ UserDataType=AttributedString, null }" ]; + } + lua_pushstring(L, s.UTF8String); + return 1; + } + return 0; +} + +static int append (lua_State *L) { + LVUserDataInfo * user1 = (LVUserDataInfo *)lua_touserdata(L, 1); + LVUserDataInfo * user2 = (LVUserDataInfo *)lua_touserdata(L, 2); + LVStyledString* string1 = (__bridge LVStyledString *)(user1->object); + LVStyledString* string2 = (__bridge LVStyledString *)(user2->object); + if( LVIsType(user1, StyledString) && LVIsType(user2, StyledString) + && string1.mutableStyledString && string2.mutableStyledString ){ + [string1.mutableStyledString appendAttributedString: string2.mutableStyledString]; + return 1; + } + return 0; +} + +static int __add (lua_State *L) { + if( lua_type(L, 2)==LUA_TUSERDATA ) { + LVUserDataInfo * user1 = (LVUserDataInfo *)lua_touserdata(L, 1); + LVUserDataInfo * user2 = (LVUserDataInfo *)lua_touserdata(L, 2); + if( LVIsType(user1, StyledString) && LVIsType(user2, StyledString) ){ + LVStyledString* user1AttString = (__bridge LVStyledString *)(user1->object); + LVStyledString* user2AttString = (__bridge LVStyledString *)(user2->object); + + LVStyledString* attString = [[LVStyledString alloc] init:L]; + attString.mutableStyledString = [[NSMutableAttributedString alloc] init]; + if( user1AttString && user1AttString.mutableStyledString) + [attString.mutableStyledString appendAttributedString:user1AttString.mutableStyledString]; + if( user2AttString && user2AttString.mutableStyledString) + [attString.mutableStyledString appendAttributedString:user2AttString.mutableStyledString]; + { + NEW_USERDATA(userData, StyledString); + userData->object = CFBridgingRetain(attString); + attString.lv_userData = userData; + + luaL_getmetatable(L, META_TABLE_AttributedString ); + lua_setmetatable(L, -2); + } + return 1; + } + } else if( lua_type(L, 2)==LUA_TSTRING || lua_type(L, 2)==LUA_TNUMBER ) { + LVUserDataInfo * user1 = (LVUserDataInfo *)lua_touserdata(L, 1); + NSString* stringArg = nil; + if( lua_type(L, 2)==LUA_TSTRING ) { + stringArg = lv_paramString(L, 2); + } else { + size_t n = 0; + const char* chars = lua_tolstring(L, 2, &n ); + stringArg = [NSString stringWithUTF8String:chars]; + } + if( LVIsType(user1, StyledString) ){ + LVStyledString* user1AttString = (__bridge LVStyledString *)(user1->object); + + LVStyledString* attString = [[LVStyledString alloc] init:L]; + attString.mutableStyledString = [[NSMutableAttributedString alloc] init]; + if( user1AttString && user1AttString.mutableStyledString) + [attString.mutableStyledString appendAttributedString:user1AttString.mutableStyledString]; + if( stringArg ) { + [attString.mutableStyledString appendAttributedString:[[NSMutableAttributedString alloc] initWithString:stringArg]]; + } + { + NEW_USERDATA(userData, StyledString); + userData->object = CFBridgingRetain(attString); + attString.lv_userData = userData; + + luaL_getmetatable(L, META_TABLE_AttributedString ); + lua_setmetatable(L, -2); + } + return 1; + } + } + return 0; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewAttributedString globalName:globalName defaultName:@"StyledString"]; + + const struct luaL_Reg memberFunctions [] = { + {"append", append }, + + {"__add", __add }, + {"__gc", __attributedString_gc }, + + {"__tostring", __tostring }, + {NULL, NULL} + }; + lv_createClassMetaTable(L, META_TABLE_AttributedString); + + luaL_openlib(L, NULL, memberFunctions, 0); + return 0; +} + + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVSwipeGesture.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVSwipeGesture.h new file mode 100644 index 00000000..261d1d84 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVSwipeGesture.h @@ -0,0 +1,22 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" +#import "NSObject+LuaView.h" + +@interface LVSwipeGesture : UISwipeGestureRecognizer + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; + +-(id) init:(lua_State*) l; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVSwipeGesture.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVSwipeGesture.m new file mode 100644 index 00000000..3731ac60 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVSwipeGesture.m @@ -0,0 +1,124 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVSwipeGesture.h" +#import "LVGesture.h" +#import "LView.h" +#import "LVHeads.h" + +@implementation LVSwipeGesture + + +-(void) dealloc{ + LVLog(@"LVSwipeGesture.dealloc"); + [LVGesture releaseUD:_lv_userData]; +} + +-(id) init:(lua_State*) l{ + self = [super initWithTarget:self action:@selector(handleGesture:)]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + } + return self; +} + +-(void) handleGesture:(LVSwipeGesture*)sender { + lua_State* l = self.lv_luaviewCore.l; + if ( l ){ + lua_checkstack32(l); + lv_pushUserdata(l,self.lv_userData); + [LVUtil call:l lightUserData:self key1:"callback" key2:NULL nargs:1]; + } +} + +static int lvSwipeGestureRecognizer (lua_State *L) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVSwipeGesture class]]; + { + LVSwipeGesture* gesture = [[c alloc] init:L]; + + if( lua_type(L, 1) == LUA_TFUNCTION ) { + [LVUtil registryValue:L key:gesture stack:1]; + } + + { + NEW_USERDATA(userData, Gesture); + gesture.lv_userData = userData; + userData->object = CFBridgingRetain(gesture); + + luaL_getmetatable(L, META_TABLE_SwipeGesture ); + lua_setmetatable(L, -2); + } + } + return 1; /* new userdatum is already on the stack */ +} + +static int touchCount (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( LVIsType(user, Gesture) ){ + LVSwipeGesture* gesture = (__bridge LVSwipeGesture *)(user->object); + if( lua_gettop(L)>=2 ) { + float num = lua_tonumber(L, 2); + gesture.numberOfTouchesRequired = num; + return 0; + } else { + float num = gesture.numberOfTouchesRequired; + lua_pushnumber(L, num); + return 1; + } + } + return 0; +} + +static int direction (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( LVIsType(user, Gesture) ){ + LVSwipeGesture* gesture = (__bridge LVSwipeGesture *)(user->object); + if ( lua_gettop(L)>=2 ) { + float num = lua_tonumber(L, 2); + gesture.direction = num; + return 0; + } else { + float direction = gesture.direction; + lua_pushnumber(L, direction); + return 1; + } + } + return 0; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + { + lua_settop(L, 0); + NSDictionary* v = nil; + v = @{ + @"LEFT":@(UISwipeGestureRecognizerDirectionLeft), + @"RIGHT":@(UISwipeGestureRecognizerDirectionRight), + @"UP":@(UISwipeGestureRecognizerDirectionUp), + @"DOWN":@(UISwipeGestureRecognizerDirectionDown), + }; + [LVUtil defineGlobal:@"GestureDirection" value:v L:L]; + } + + [LVUtil reg:L clas:self cfunc:lvSwipeGestureRecognizer globalName:globalName defaultName:@"SwipeGesture"]; + + lv_createClassMetaTable(L ,META_TABLE_SwipeGesture); + luaL_openlib(L, NULL, [LVGesture baseMemberFunctions], 0); + { + const struct luaL_Reg memberFunctions [] = { + {"touchCount", touchCount}, + {"direction", direction}, + {NULL, NULL} + }; + luaL_openlib(L, NULL, memberFunctions, 0); + } + return 1; +} + + + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVSystem.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVSystem.h new file mode 100644 index 00000000..fe138d49 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVSystem.h @@ -0,0 +1,21 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + +@interface LVSystem : NSObject + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +/* + * 获取网络状态, 需要重载API获取网络链接信息: 2g 3g 4g wifi 未知类型返回unkown 断网返回"none" + */ ++(NSString*) netWorkType; + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVSystem.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVSystem.m new file mode 100644 index 00000000..cdf379f5 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVSystem.m @@ -0,0 +1,303 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVSystem.h" +#import "LView.h" +#import "LVPkgManager.h" +#import +#import "LVHeads.h" +#import "LVNetworkStatus.h" +#import "LVAnimator.h" + +@implementation LVSystem + + +// lv 扩展API +static int vmVersion (lua_State *L) { + lua_pushstring(L, LUAVIEW_VERSION ) ; + return 1; /* number of results */ +} + +// lv 扩展API +static int sdkVersion (lua_State *L) { + lua_pushstring(L, LUAVIEW_SDK_VERSION ) ; + return 1; /* number of results */ +} + +// lv 扩展API +static int osVersion (lua_State *L) { + NSString* v = [[UIDevice currentDevice] systemVersion]; + lua_pushstring(L, v.UTF8String); + return 1; /* number of results */ +} + +static int ios (lua_State *L) { + lua_pushboolean(L, 1); + return 1; +} + +static int android (lua_State *L) { + lua_pushboolean(L, 0); + return 1; +} + + ++(NSString*) netWorkType{ + return [[LVNetworkStatus shareInstance] currentNetworkStatusString]; +} + +static int netWorkType (lua_State *L) { + NSString* type = [LVSystem netWorkType]; + lua_pushstring(L, type.UTF8String); + return 1; +} + +static int layerMode (lua_State *L) { + if( lua_gettop(L)>0 ){ + BOOL yes = lua_toboolean(L, -1); + LuaViewCore* luaview = LV_LUASTATE_VIEW(L); + luaview.closeLayerMode = !yes; + } + return 0; +} + +// 屏幕常亮 +static int keepScreenOn (lua_State *L) { + if( lua_gettop(L)>0 ){ + BOOL yes = lua_toboolean(L, -1); + [[UIApplication sharedApplication] setIdleTimerDisabled:yes] ; + } + return 0; +} + +static int scale (lua_State *L) { + CGFloat s = [UIScreen mainScreen].scale; + lua_pushnumber( L, s); + return 1; /* number of results */ +} + + +// lv 扩展API +static int platform (lua_State *L) { + NSString* name = [[UIDevice currentDevice] systemName]; + NSString* version = [[UIDevice currentDevice] systemVersion]; + NSString* buf = [NSString stringWithFormat:@"%@;%@",name,version]; + lua_pushstring(L, [buf UTF8String] ) ; + return 1; /* number of results */ +} + +static int device (lua_State *L) { + NSString* name = [[UIDevice currentDevice] localizedModel]; + NSString* version = [[UIDevice currentDevice] model]; + NSString* buf = [NSString stringWithFormat:@"%@;%@",name,version]; + lua_pushstring(L, [buf UTF8String] ) ; + return 1; /* number of results */ +} + +// lv 扩展API +static int screenSize (lua_State *L) { + CGSize s = [UIScreen mainScreen].bounds.size; + lua_pushnumber(L, s.width ); + lua_pushnumber(L, s.height ); + return 2; /* number of results */ +} + +static int static_gc (lua_State *L) { + lua_gc(L, 2, 0); + return 0; +} + +static int vibrate(lua_State*L){ + AudioServicesPlaySystemSound(kSystemSoundID_Vibrate); + return 1; +} + +static int lvClassLoader(lua_State*L){ + NSString* s = lv_paramString(L, -1); + id obj = NSClassFromString(s); + lv_pushNativeObject(L, obj); + return 1; +} + +static int stringToTable(lua_State*L){ + if( lua_type(L, -1) == LUA_TSTRING ) { + NSString* s = lv_paramString(L, -1); + if( s ) { + id obj = [LVUtil stringToObject:s]; + lv_pushNativeObject(L, obj); + return 1; + } + } + return 0; +} + +static int tableToString(lua_State*L){ + if( lua_type(L, -1) == LUA_TTABLE ) { + id obj = lv_luaValueToNativeObject(L,-1); + NSString* s = [LVUtil objectToString:obj]; + lua_pushstring(L, s.UTF8String); + return 1; + } + return 0; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + { + // System API + const struct luaL_Reg staticFunctions [] = { + {"screenSize", screenSize}, + {"gc",static_gc}, + {"osVersion", osVersion}, + {"vmVersion", vmVersion}, + {"sdkVersion", sdkVersion}, + {"scale", scale}, + {"platform",platform}, + {"device",device}, + {"ios", ios}, + {"android", android}, + {"network", netWorkType}, + {"keepScreenOn", keepScreenOn},// 保持屏幕常亮接口 + {"layerMode", layerMode},// (for IOS) 是否开启layer模式 + {NULL, NULL} + }; + luaL_openlib(L, "System", staticFunctions, 0); + } + { + // Json Table相互转换 + const struct luaL_Reg fs [] = { + {"toString", tableToString}, + {"toJson", tableToString}, + {"toTable",stringToTable}, + {NULL, NULL} + }; + luaL_openlib(L, "Json", fs, 0); + } + // ---- 常量注册 ---- + { + // Align 常量 + lua_settop(L, 0); + NSDictionary* v = nil; + v = @{ + @"LEFT": @(LV_ALIGN_LEFT), + @"RIGHT": @(LV_ALIGN_RIGHT), + @"TOP": @(LV_ALIGN_TOP), + @"BOTTOM": @(LV_ALIGN_BOTTOM), + @"H_CENTER":@(LV_ALIGN_H_CENTER),// 水平居中 + @"V_CENTER":@(LV_ALIGN_V_CENTER),// 垂直居中 + @"CENTER": @(LV_ALIGN_H_CENTER|LV_ALIGN_V_CENTER),// 上下左右都居中 + }; + [LVUtil defineGlobal:@"Align" value:v L:L]; + } + { + lua_settop(L, 0); + NSDictionary* v = nil; + v = @{ + @"LEFT":@(NSTextAlignmentLeft), + @"RIGHT":@(NSTextAlignmentRight), + @"CENTER":@(NSTextAlignmentCenter),// 上下左右都居中 + }; + [LVUtil defineGlobal:@"TextAlign" value:v L:L]; + } + { + //文本太多 "..." 出现的问题 + lua_settop(L, 0); + NSDictionary* v = nil; + v = @{ + @"START":@(NSLineBreakByTruncatingHead), + @"MIDDLE":@(NSLineBreakByTruncatingMiddle), + @"END":@(NSLineBreakByTruncatingTail), + @"MARQUEE":@(NSLineBreakByCharWrapping), + }; + [LVUtil defineGlobal:@"Ellipsize" value:v L:L]; + } + { + //字体Style + lua_settop(L, 0); + NSDictionary* v = nil; + v = @{ + @"NORMAL":@"normal",//正常 + @"ITALIC":@"italic",//斜体 + @"OBLIQUE":@"oblique",//倾斜 //__deprecated_msg("") + // BOLD IOS 不支持 + // + }; + [LVUtil defineGlobal:@"FontStyle" value:v L:L]; + } + { + //字体Weight(粗体、正常) + lua_settop(L, 0); + NSDictionary* v = nil; + v = @{ + @"NORMAL":@"normal", + @"BOLD":@"bold", + }; + [LVUtil defineGlobal:@"FontWeight" value:v L:L]; + } + { + //图片缩放常量 + lua_settop(L, 0); + NSDictionary* v = nil; + v = @{ + @"CENTER":@(UIViewContentModeCenter),//按图片的原来size居中显示,当图片长/宽超过View的长/宽,则截取图片的居中部分显示 + @"CENTER_CROP":@(UIViewContentModeScaleAspectFill),//将图片等比居中显示,完全覆盖view,尽可能小; + @"CENTER_INSIDE":@(UIViewContentModeScaleAspectFit),//将图片的内容完整居中显示,尽可能的大 + @"FIT_CENTER":@(UIViewContentModeScaleAspectFit),//将图片的内容完整居中显示,尽可能的大 + @"FIT_END":@(UIViewContentModeScaleAspectFill),//把图片按比例扩大(缩小)到View的宽度,显示在View的下部分位置 + @"FIT_START":@(UIViewContentModeScaleAspectFill),//把图片按比例扩大(缩小)到View的宽度,显示在View的上部分位置 + @"FIT_XY":@(UIViewContentModeScaleToFill),//把图片按照指定的大小在View中显示 + @"MATRIX":@(UIViewContentModeScaleAspectFill),//用matrix来绘制 + }; + [LVUtil defineGlobal:@"ScaleType" value:v L:L]; + } + { + lua_settop(L, 0); + NSDictionary* v = nil; + v = @{ + @"LINEAR" : @(LVLinearInterpolator), + @"ACCELERATE" : @(LVAccelerateInterpolator), + @"DECELERATE" : @(LVDecelerateInterpolator), + @"ACCELERATE_DECELERATE" : @(LVAccelerateDecelerateInterpolator), + @"ANTICIPATE": @(LVAnticipateInterpolator), + @"OVERSHOOT": @(LVOvershootInterpolator), + @"ANTICIPATE_OVERSHOOT": @(LVAnticipateOvershootInterpolator), + }; + [LVUtil defineGlobal:@"Interpolator" value:v L:L]; + } + { + // 坑位浮动Pinned + lua_settop(L, 0); + NSDictionary* v = nil; + v = @{ + @"YES":@(YES), + @"Yes":@(YES),//__deprecated_msg("Use YES") + @"yes":@(YES),//__deprecated_msg("Use YES") + }; + [LVUtil defineGlobal:@"Pinned" value:v L:L]; + } + + { + // ViewEffect define + lua_settop(L, 0); + NSDictionary* v = nil; + v = @{ + @"NONE":@(EFFECT_NONE), + @"CLICK":@(EFFECT_CLICK), + @"PARALLAX":@(EFFECT_PARALLAX), + }; + [LVUtil defineGlobal:@"ViewEffect" value:v L:L]; + } + + // 震动 完全不兼容安卓, 安卓是类, vabrate(数组) cancel() hasVabrate(); + lv_defineGlobalFunc("Vibrate", vibrate, L); + + // create class api + lv_defineGlobalFunc("__class__", lvClassLoader, L); + return 0; +} + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTapGesture.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTapGesture.h new file mode 100644 index 00000000..5872fd83 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTapGesture.h @@ -0,0 +1,25 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import +#import "LVHeads.h" +#import "NSObject+LuaView.h" + +@interface LVTapGesture : UITapGestureRecognizer + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; + +-(id) init:(lua_State*) l; + + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTapGesture.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTapGesture.m new file mode 100644 index 00000000..d77bff3a --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTapGesture.m @@ -0,0 +1,77 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVTapGesture.h" +#import "LVGesture.h" +#import "LView.h" +#import "LVHeads.h" + +@implementation LVTapGesture + + +-(void) dealloc{ + LVLog(@"LVTapGesture.dealloc"); + [LVGesture releaseUD:_lv_userData]; +} + +-(id) init:(lua_State*) l{ + self = [super initWithTarget:self action:@selector(handleGesture:)]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + } + return self; +} + + + +-(void) handleGesture:(LVTapGesture*)sender { + lua_State* l = self.lv_luaviewCore.l; + if ( l ){ + lua_checkstack32(l); + lv_pushUserdata(l, self.lv_userData); + [LVUtil call:l lightUserData:self key1:"callback" key2:NULL nargs:1]; + } +} + +static int lvNewTapGestureRecognizer (lua_State *L) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVTapGesture class]]; + { + LVTapGesture* gesture = [[c alloc] init:L]; + + if( lua_type(L, 1) == LUA_TFUNCTION ) { + [LVUtil registryValue:L key:gesture stack:1]; + } + + { + NEW_USERDATA(userData, Gesture); + gesture.lv_userData = userData; + userData->object = CFBridgingRetain(gesture); + + luaL_getmetatable(L, META_TABLE_TapGesture ); + lua_setmetatable(L, -2); + } + } + return 1; /* new userdatum is already on the stack */ +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewTapGestureRecognizer globalName:globalName defaultName:@"TapGesture"]; + + const struct luaL_Reg memberFunctions [] = { + {NULL, NULL} + }; + + lv_createClassMetaTable(L ,META_TABLE_TapGesture); + + luaL_openlib(L, NULL, [LVGesture baseMemberFunctions], 0); + luaL_openlib(L, NULL, memberFunctions, 0); + return 1; +} + + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTextField.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTextField.h new file mode 100644 index 00000000..d7621512 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTextField.h @@ -0,0 +1,24 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + + +@interface LVTextField : UITextField + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; +@property(nonatomic,assign) NSUInteger lv_align; +@property(nonatomic,strong) CAShapeLayer* lv_shapeLayer; + +-(id) init:(lua_State*) l; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTextField.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTextField.m new file mode 100644 index 00000000..9ee202b2 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTextField.m @@ -0,0 +1,206 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVTextField.h" +#import "LVBaseView.h" +#import "LView.h" +#import "LVStyledString.h" +#import "LVHeads.h" + +@interface LVTextField () + +@end + +@implementation LVTextField + + +-(id) init:(lua_State*) l{ + self = [super initWithFrame:CGRectMake(0, 0, 100, 40)]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + self.delegate = self; + self.backgroundColor = [UIColor clearColor]; + self.clipsToBounds = YES; + self.font = [UIFont systemFontOfSize:14];// 默认字体大小 + } + return self; +} + +-(void) dealloc{ +} + +- (void)textFieldDidBeginEditing:(UITextField *)textField{ + // became first responder + lua_State* l = self.lv_luaviewCore.l; + if( l ) { + lua_checkstack32(l); + [self lv_callLuaByKey1:@"BeginEditing"]; + } +} + +- (void)textFieldDidEndEditing:(UITextField *)textField{ + lua_State* l = self.lv_luaviewCore.l; + if( l ) { + lua_checkstack32(l); + [self lv_callLuaByKey1:@"EndEditing"]; + } +} + +- (BOOL)textFieldShouldClear:(UITextField *)textField{ +// lua_State* l = self.lv_luaviewCore.l; +// if( l ) { +// lua_checkstack32(l); +// if( [LVUtil call:l lightUserData:self key:"清理"] ){ +// if( lv_isboolean(l, -1) ){ +// return lua_toboolean(l, -1); +// } +// } +// } + return YES; +} + +- (BOOL)textFieldShouldReturn:(UITextField *)textField{ +// lua_State* l = self.lv_luaviewCore.l; +// if( l ) { +// lua_checkstack32(l); +// if( [LVUtil call:l lightUserData:self key:"返回"]==0 ){ +// if( lv_isboolean(l, -1) ){ +// return lua_toboolean(l, -1); +// } +// } +// } + return YES; +} + +- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{ + return YES; +} + +#pragma -mark lvNewTextField +static int lvNewTextField (lua_State *L) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVTextField class]]; + + LVTextField* textFiled = [[c alloc] init:L]; + { + NEW_USERDATA(userData, View); + userData->object = CFBridgingRetain(textFiled); + textFiled.lv_userData = userData; + + luaL_getmetatable(L, META_TABLE_UITextField ); + lua_setmetatable(L, -2); + } + LuaViewCore* lview = LV_LUASTATE_VIEW(L); + if( lview ){ + [lview containerAddSubview:textFiled]; + } + return 1; /* new userdatum is already on the stack */ +} + +static int text (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVTextField* view = (__bridge LVTextField *)(user->object); + if( [view isKindOfClass:[LVTextField class]] ){ + if ( lua_gettop(L)>=2 ) { + if( lua_type(L, 2)==LUA_TUSERDATA ) { + LVUserDataInfo * user2 = lua_touserdata(L, 2);// 2 + if( user2 && LVIsType(user2, StyledString) ) { + LVStyledString* attString = (__bridge LVStyledString *)(user2->object); + view.attributedText = attString.mutableStyledString; + } + } else if( lua_type(L, 2)==LUA_TSTRING ) { + NSString* text = lv_paramString(L, 2);// 2 + view.text = text; + } + return 0; + } else { + NSString* s = view.text; + if( s ) { + lua_pushstring(L, s.UTF8String); + return 1; + } + + NSAttributedString* att = view.attributedText; + if( att ) { + LVStyledString* attString = [[LVStyledString alloc] init:L]; + attString.mutableStyledString = [[NSMutableAttributedString alloc] init]; + [attString.mutableStyledString appendAttributedString:att]; + + NEW_USERDATA(userData, StyledString); + userData->object = CFBridgingRetain(attString); + attString.lv_userData = userData; + + luaL_getmetatable(L, META_TABLE_AttributedString ); + lua_setmetatable(L, -2); + return 1; + } else { + lua_pushnil(L); + } + return 1; + } + } + } + return 0; +} + +static int placeholder (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVTextField* view = (__bridge LVTextField *)(user->object); + if( [view isKindOfClass:[LVTextField class]] ){ + if ( lua_gettop(L)>=2 ) { + if( lua_type(L, 2)==LUA_TSTRING ) { + NSString* text = lv_paramString(L, 2);// 2 + view.placeholder = text; + } else if( lua_type(L, 2)==LUA_TUSERDATA ) { + LVUserDataInfo * user2 = lua_touserdata(L, 2);// 2 + if( user2 && LVIsType(user2, StyledString) ) { + LVStyledString* attString = (__bridge LVStyledString *)(user2->object); + view.attributedPlaceholder = attString.mutableStyledString; + } + } + return 0; + } else { + NSString* s = view.placeholder; + if( s ) { + lua_pushstring(L, s.UTF8String); + } else { + lua_pushnil(L); + } + } + return 1; + } + } + return 0; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewTextField globalName:globalName defaultName:@"TextField"]; + + const struct luaL_Reg memberFunctions [] = { + {"text", text}, + {"hint", placeholder}, + {"placeholder", placeholder}, //__deprecated_msg("Use hint") + {NULL, NULL} + }; + + lv_createClassMetaTable(L ,META_TABLE_UITextField); + + luaL_openlib(L, NULL, [LVBaseView baseMemberFunctions], 0); + luaL_openlib(L, NULL, memberFunctions, 0); + + const char* keys[] = { "addView", NULL};// 移除多余API + lv_luaTableRemoveKeys(L, keys ); + return 1; +} + +-(NSString*) description{ + return [NSString stringWithFormat:@"", (int)[self hash], NSStringFromCGRect(self.frame) ]; +} + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTimer.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTimer.h new file mode 100644 index 00000000..1d12e3de --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTimer.h @@ -0,0 +1,27 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + + +@interface LVTimer : NSObject + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; + +-(id) init:(lua_State*) l; + +-(void) startTimer; +-(void) cancel; + + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTimer.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTimer.m new file mode 100644 index 00000000..0615dbb0 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTimer.m @@ -0,0 +1,232 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVTimer.h" +#import "LView.h" +#import "LVHeads.h" +#import "LVHeads.h" + +@interface LVTimer () +@property(nonatomic,assign) BOOL repeat; +@property(nonatomic,assign) NSTimeInterval delay; +@property(nonatomic,assign) NSTimeInterval interval; +@end + +@implementation LVTimer{ + NSTimer* timer; +} + +static void releaseUserDataTimer(LVUserDataInfo* user){ + if( user && user->object ){ + LVTimer* timer = CFBridgingRelease(user->object); + user->object = NULL; + if( timer ){ + [timer cancel]; + timer.lv_userData = nil; + timer.lv_luaviewCore = nil; + } + } +} + +-(void) dealloc{ + releaseUserDataTimer(_lv_userData); +} + +-(id) init:(lua_State*) l{ + self = [super init]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + self.delay = 0; // 默认延时 + self.repeat = NO; // 默认重复次数 + self.interval = 1; // 默认间隔1秒 + } + return self; +} + +-(void) timerCallBack{ + lua_State* l = self.lv_luaviewCore.l; + if( l && self.lv_userData ){ + lv_pushUserdata(l, self.lv_userData); + lv_pushUDataRef(l, USERDATA_KEY_DELEGATE ); + lv_runFunction(l); + } +} + + +-(void) startTimer{ + [self cancel]; + if( self.delay>0 ) { + NSDate* date = [[NSDate alloc] initWithTimeIntervalSinceNow:self.delay]; + timer = [[NSTimer alloc] initWithFireDate:date interval:self.interval target:self selector:@selector(timerCallBack) userInfo:nil repeats:self.repeat]; + [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes]; + } else { + timer = [NSTimer scheduledTimerWithTimeInterval:self.interval target:self selector:@selector(timerCallBack) userInfo:nil repeats:self.repeat]; + [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes]; + } +} + +-(void) cancel { + [timer invalidate]; + timer = nil; +} + +-(id) lv_nativeObject{ + return timer; +} + + +#pragma -mark Timer + +static int lvNewTimer (lua_State *L) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVTimer class]]; + + LVTimer* timer = [[c alloc] init:L]; + { + NEW_USERDATA(userData, Timer); + userData->object = CFBridgingRetain(timer); + timer.lv_userData = userData; + + luaL_getmetatable(L, META_TABLE_Timer ); + lua_setmetatable(L, -2); + } + if( lua_type(L, 1) == LUA_TFUNCTION ) { + lua_pushvalue(L, 1); + lv_udataRef(L, USERDATA_KEY_DELEGATE); + } + return 1; +} + +static int setCallback (lua_State *L) { + if( lua_type(L, 2) == LUA_TFUNCTION ) { + lua_pushvalue(L, 1); + lua_pushvalue(L, 2); + lv_udataRef(L, USERDATA_KEY_DELEGATE); + } + lua_settop(L, 1); + return 1; +} + +static int start (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + LVTimer* timer = (__bridge LVTimer *)(user->object); + if( lua_gettop(L)>=2 ) { + timer.interval = lua_tonumber(L, 2); + } + if( lua_gettop(L)>=3 ) { + timer.repeat = lua_toboolean(L, 3); + } + if( user ){ + if( timer ){ + [timer startTimer]; + lua_pushvalue(L,1); + return 1; + } + } + return 0; +} + +static int cancel (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVTimer* timer = (__bridge LVTimer *)(user->object); + if( timer ){ + [timer cancel]; + } + } + return 0; +} + +static int delay (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + double delay = lua_tonumber(L, 2); + if( user ){ + LVTimer* timer = (__bridge LVTimer *)(user->object); + if( timer ){ + timer.delay = delay; + lua_pushvalue(L,1); + return 1; + } + } + return 0; +} + +static int repeat (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + BOOL repeat = lua_toboolean(L, 2); + if( user ){ + LVTimer* timer = (__bridge LVTimer *)(user->object); + if( timer ){ + timer.repeat = repeat; + lua_pushvalue(L,1); + return 1; + } + } + return 0; +} + +static int interval (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + double interval = lua_tonumber(L, 2); + if( user ){ + LVTimer* timer = (__bridge LVTimer *)(user->object); + if( timer ){ + timer.interval = interval; + lua_pushvalue(L,1); + return 1; + } + } + return 0; +} + +static int __gc (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + releaseUserDataTimer(user); + return 0; +} + +static int __tostring (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVTimer* timer = (__bridge LVTimer *)(user->object); + NSString* s = [NSString stringWithFormat:@"LVUserDataTimer: %@", timer ]; + lua_pushstring(L, s.UTF8String); + return 1; + } + return 0; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewTimer globalName:globalName defaultName:@"Timer"]; + + const struct luaL_Reg memberFunctions [] = { + {"callback",setCallback}, + + {"start", start }, + {"cancel", cancel }, + {"stop", cancel }, //__deprecated_msg("Use hidden") + + + {"delay", delay }, + {"repeat", repeat }, + {"repeatCount", repeat }, //__deprecated_msg("Use hidden") + {"interval", interval }, + + {"__gc", __gc }, + + {"__tostring", __tostring }, + {NULL, NULL} + }; + + lv_createClassMetaTable(L ,META_TABLE_Timer); + + luaL_openlib(L, NULL, memberFunctions, 0); + return 1; +} + + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVToast.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVToast.h new file mode 100644 index 00000000..6434ea06 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVToast.h @@ -0,0 +1,25 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import + +#define DEFAULT_DISPLAY_DURATION 2.0f + +@interface LVToast : NSObject + ++ (void)showWithText:(NSString *) text; ++ (void)showWithText:(NSString *) text duration:(CGFloat)duration; + ++ (void)showWithText:(NSString *) text topOffset:(CGFloat) topOffset; ++ (void)showWithText:(NSString *) text topOffset:(CGFloat) topOffset duration:(CGFloat) duration; + ++ (void)showWithText:(NSString *) text bottomOffset:(CGFloat) bottomOffset; ++ (void)showWithText:(NSString *) text bottomOffset:(CGFloat) bottomOffset duration:(CGFloat) duration; + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVToast.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVToast.m new file mode 100644 index 00000000..34c1b2df --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVToast.m @@ -0,0 +1,185 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVToast.h" + +#import + + +@interface LVToast () + +- (id)initWithText:(NSString *)text_; +- (void)setDuration:(CGFloat) duration_; + +- (void)toastTaped:(UIButton *)sender_; + +- (void)showAnimation; +- (void)hideAnimation; + +- (void)show; +- (void)showFromTopOffset:(CGFloat) topOffset_; +- (void)showFromBottomOffset:(CGFloat) bottomOffset_; + +@end + + +@implementation LVToast{ + NSString *text; + UIButton *contentView; + CGFloat duration; +} + +- (void)dealloc{ + [[NSNotificationCenter defaultCenter] removeObserver:self + name:UIDeviceOrientationDidChangeNotification + object:[UIDevice currentDevice]]; +} + + +- (id)initWithText:(NSString *)text_{ + if (self = [super init]) { + + text = [text_ copy]; + + UIFont *font = [UIFont boldSystemFontOfSize:14]; + + CGSize textSize = [text boundingRectWithSize:CGSizeMake(280, MAXFLOAT) + options:(NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading) + attributes:@{NSFontAttributeName: font } + context:nil].size; + UILabel *textLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, textSize.width + 12, textSize.height + 12)]; + textLabel.backgroundColor = [UIColor clearColor]; + textLabel.textColor = [UIColor whiteColor]; + textLabel.textAlignment = NSTextAlignmentCenter; + textLabel.font = font; + textLabel.text = text; + textLabel.numberOfLines = 0; + + contentView = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, textLabel.frame.size.width, textLabel.frame.size.height)]; + contentView.layer.cornerRadius = 5.0f; + contentView.layer.borderWidth = 1.0f; + contentView.layer.borderColor = [[UIColor grayColor] colorWithAlphaComponent:0.5].CGColor; + contentView.backgroundColor = [UIColor colorWithRed:0.2f + green:0.2f + blue:0.2f + alpha:0.75f]; + [contentView addSubview:textLabel]; + contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth; + [contentView addTarget:self + action:@selector(toastTaped:) + forControlEvents:UIControlEventTouchDown]; + contentView.alpha = 0.0f; + + + duration = DEFAULT_DISPLAY_DURATION; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(deviceOrientationDidChanged:) + name:UIDeviceOrientationDidChangeNotification + object:[UIDevice currentDevice]]; + } + return self; +} + +- (void)deviceOrientationDidChanged:(NSNotification *)notify_{ + [self hideAnimation]; +} + +-(void)dismissToast{ + [contentView removeFromSuperview]; +} + +-(void)toastTaped:(UIButton *)sender_{ + [self hideAnimation]; +} + +- (void)setDuration:(CGFloat) duration_{ + duration = duration_; +} + +-(void)showAnimation{ + [UIView beginAnimations:@"show" context:NULL]; + [UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; + [UIView setAnimationDuration:0.3]; + contentView.alpha = 1.0f; + [UIView commitAnimations]; +} + +-(void)hideAnimation{ + [UIView beginAnimations:@"hide" context:NULL]; + [UIView setAnimationCurve:UIViewAnimationCurveEaseOut]; + [UIView setAnimationDelegate:self]; + [UIView setAnimationDidStopSelector:@selector(dismissToast)]; + [UIView setAnimationDuration:0.3]; + contentView.alpha = 0.0f; + [UIView commitAnimations]; +} + +- (void)show{ + UIWindow *window = [UIApplication sharedApplication].keyWindow; + contentView.center = window.center; + [window addSubview:contentView]; + [self showAnimation]; + [self performSelector:@selector(hideAnimation) withObject:nil afterDelay:duration]; +} + +- (void)showFromTopOffset:(CGFloat) top_{ + UIWindow *window = [UIApplication sharedApplication].keyWindow; + contentView.center = CGPointMake(window.center.x, top_ + contentView.frame.size.height/2); + [window addSubview:contentView]; + [self showAnimation]; + [self performSelector:@selector(hideAnimation) withObject:nil afterDelay:duration]; +} + +- (void)showFromBottomOffset:(CGFloat) bottom_{ + UIWindow *window = [UIApplication sharedApplication].keyWindow; + contentView.center = CGPointMake(window.center.x, window.frame.size.height-(bottom_ + contentView.frame.size.height/2)); + [window addSubview:contentView]; + [self showAnimation]; + [self performSelector:@selector(hideAnimation) withObject:nil afterDelay:duration]; +} + + ++ (void)showWithText:(NSString *)text_{ + [LVToast showWithText:text_ duration:DEFAULT_DISPLAY_DURATION]; +} + ++ (void)showWithText:(NSString *)text_ + duration:(CGFloat)duration_{ + LVToast *toast = [[LVToast alloc] initWithText:text_]; + [toast setDuration:duration_]; + [toast show]; +} + ++ (void)showWithText:(NSString *)text_ + topOffset:(CGFloat)topOffset_{ + [LVToast showWithText:text_ topOffset:topOffset_ duration:DEFAULT_DISPLAY_DURATION]; +} + ++ (void)showWithText:(NSString *)text_ + topOffset:(CGFloat)topOffset_ + duration:(CGFloat)duration_{ + LVToast *toast = [[LVToast alloc] initWithText:text_]; + [toast setDuration:duration_]; + [toast showFromTopOffset:topOffset_]; +} + ++ (void)showWithText:(NSString *)text_ + bottomOffset:(CGFloat)bottomOffset_{ + [LVToast showWithText:text_ bottomOffset:bottomOffset_ duration:DEFAULT_DISPLAY_DURATION]; +} + ++ (void)showWithText:(NSString *)text_ + bottomOffset:(CGFloat)bottomOffset_ + duration:(CGFloat)duration_{ + LVToast *toast = [[LVToast alloc] initWithText:text_]; + [toast setDuration:duration_]; + [toast showFromBottomOffset:bottomOffset_]; +} + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTransform3D.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTransform3D.h new file mode 100644 index 00000000..42ba1a9e --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTransform3D.h @@ -0,0 +1,46 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + +@interface LVTransform3D : NSObject + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; +- (id) lv_nativeObject; // 返回native对象 + +@property(nonatomic,assign) CATransform3D transform; + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + ++(int) pushTransform3D:(lua_State *)L transform3d:(CATransform3D) t; + +@end + +/* rotation和scale函数只适用于没有x、y轴rotation的矩阵 */ + +extern void CATransform3DSetRotation(CATransform3D *t, CGFloat v); /* z-axis */ + +extern double CATransform3DGetRotation(CATransform3D *t); /* returns [-M_PI, M_PI] */ + +extern void CATransform3DSetScaleX(CATransform3D *t, CGFloat v); +extern void CATransform3DSetScaleY(CATransform3D *t, CGFloat v); +extern void CATransform3DSetScaleZ(CATransform3D *t, CGFloat v); + +extern double CATransform3DGetScaleX(CATransform3D *t); +extern double CATransform3DGetScaleY(CATransform3D *t); +extern double CATransform3DGetScaleZ(CATransform3D *t); + +extern void CATransform3DSetTranslationX(CATransform3D *t, CGFloat v); +extern void CATransform3DSetTranslationY(CATransform3D *t, CGFloat v); +extern void CATransform3DSetTranslationZ(CATransform3D *t, CGFloat v); + +extern double CATransform3DGetTranslationX(CATransform3D *t); +extern double CATransform3DGetTranslationY(CATransform3D *t); +extern double CATransform3DGetTranslationZ(CATransform3D *t); diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTransform3D.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTransform3D.m new file mode 100644 index 00000000..78699e4b --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTransform3D.m @@ -0,0 +1,308 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVTransform3D.h" +#import "LVHeads.h" +#import "LVHeads.h" + +@implementation LVTransform3D + +-(id) lv_nativeObject{ + return nil; +} + +static int lvNewTransform3D (lua_State *L) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVTransform3D class]]; + + { + NEW_USERDATA(userData, Transform3D); + LVTransform3D* trans = [[c alloc] init]; + userData->object = CFBridgingRetain(trans); + trans.transform = CATransform3DIdentity; + luaL_getmetatable(L, META_TABLE_Transform3D ); + lua_setmetatable(L, -2); + } + return 1; /* new userdatum is already on the stack */ +} + ++(int) pushTransform3D:(lua_State *)L transform3d:(CATransform3D) t{ + { + NEW_USERDATA(userData, Transform3D); + LVTransform3D* trans = [[LVTransform3D alloc] init]; + userData->object = CFBridgingRetain(trans); + trans.transform = t; + luaL_getmetatable(L, META_TABLE_Transform3D ); + lua_setmetatable(L, -2); + } + return 1; +} + + +static int translation (lua_State *L) { + if( lua_gettop(L)==4 ) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + double x = lua_tonumber(L, 2);// 2 + double y = lua_tonumber(L, 3);// 3 + double z = lua_tonumber(L, 4);// 4 + if( LVIsType(user, Transform3D) ){ + LVTransform3D* tran = (__bridge LVTransform3D *)(user->object); + tran.transform = CATransform3DTranslate(tran.transform, x, y, z); + lua_pushvalue(L,1); + return 1; + } + } + return 0; +} + +static int scale (lua_State *L) { + if( lua_gettop(L)==4 ) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + double x = lua_tonumber(L, 2);// 2 + double y = lua_tonumber(L, 3);// 3 + double z = lua_tonumber(L, 4);// 4 + if( LVIsType(user, Transform3D) ){ + LVTransform3D* tran = (__bridge LVTransform3D *)(user->object); + tran.transform = CATransform3DScale(tran.transform, x, y, z); + lua_pushvalue(L,1); + return 1; + } + } + return 0; +} + +static int rotate (lua_State *L) { + if( lua_gettop(L)==5 ) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + double angle = lua_tonumber(L, 2); + double x = lua_tonumber(L, 3); + double y = lua_tonumber(L, 4); + double z = lua_tonumber(L, 5); + if( LVIsType(user, Transform3D) ){ + LVTransform3D* tran = (__bridge LVTransform3D *)(user->object); + tran.transform = CATransform3DRotate(tran.transform, angle, x, y, z); + lua_pushvalue(L,1); + return 1; + } + } + return 0; +} + +static int isIdentity (lua_State *L) { + if( lua_gettop(L)==1 ) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( LVIsType(user, Transform3D) ){ + LVTransform3D* tran = (__bridge LVTransform3D *)(user->object); + BOOL yes = CATransform3DIsIdentity(tran.transform ); + int ret = (yes ? 1 : 0); + lua_pushboolean(L, ret); + return 1; + } + } + return 0; +} + +static int reset (lua_State *L) { + if( lua_gettop(L)==1 ) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( LVIsType(user, Transform3D) ){ + LVTransform3D* tran = (__bridge LVTransform3D *)(user->object); + tran.transform = CATransform3DIdentity; + lua_pushvalue(L,1); + return 1; + } + } + return 0; +} + +static int transform_set (lua_State *L) { + if( lua_gettop(L)==2 ) { + LVUserDataInfo * user1 = (LVUserDataInfo *)lua_touserdata(L, 1); + LVUserDataInfo * user2 = (LVUserDataInfo *)lua_touserdata(L, 2); + if( LVIsType(user1, Transform3D) && LVIsType(user2, Transform3D) ){ + LVTransform3D* tran1 = (__bridge LVTransform3D *)(user1->object); + LVTransform3D* tran2 = (__bridge LVTransform3D *)(user2->object); + tran1.transform = tran2.transform; + lua_pushvalue(L,1); + return 1; + } + } + return 0; +} + +static int concat (lua_State *L) { + if( lua_gettop(L)==2 ) { + LVUserDataInfo * user1 = (LVUserDataInfo *)lua_touserdata(L, 1); + LVUserDataInfo * user2 = (LVUserDataInfo *)lua_touserdata(L, 2); + if( LVIsType(user1, Transform3D) && LVIsType(user2, Transform3D) ){ + LVTransform3D* tran1 = (__bridge LVTransform3D *)(user1->object); + LVTransform3D* tran2 = (__bridge LVTransform3D *)(user2->object); + tran1.transform = CATransform3DConcat(tran1.transform, tran2.transform); + + lua_pushvalue(L,1); + return 1; + } + } + return 0; +} + +static int __mul (lua_State *L) { + if( lua_gettop(L)==2 ) { + LVUserDataInfo * user1 = (LVUserDataInfo *)lua_touserdata(L, 1); + LVUserDataInfo * user2 = (LVUserDataInfo *)lua_touserdata(L, 2); + if( LVIsType(user1, Transform3D) && LVIsType(user2, Transform3D) ){ + LVTransform3D* tran1 = (__bridge LVTransform3D *)(user1->object); + LVTransform3D* tran2 = (__bridge LVTransform3D *)(user2->object); + NEW_USERDATA(user, Transform3D); + + LVTransform3D* trans = [[LVTransform3D alloc] init]; + user->object = CFBridgingRetain(trans); + + trans.transform = CATransform3DIdentity; + luaL_getmetatable(L, META_TABLE_Transform3D ); + lua_setmetatable(L, -2); + + trans.transform = CATransform3DConcat(tran1.transform, tran2.transform); + return 1; + } + } + return 0; +} + +static int __eq (lua_State *L) { + if( lua_gettop(L)==2 ) { + LVUserDataInfo * user1 = (LVUserDataInfo *)lua_touserdata(L, 1); + LVUserDataInfo * user2 = (LVUserDataInfo *)lua_touserdata(L, 2); + if( LVIsType(user1, Transform3D) && LVIsType(user2, Transform3D) ){ + LVTransform3D* tran1 = (__bridge LVTransform3D *)(user1->object); + LVTransform3D* tran2 = (__bridge LVTransform3D *)(user2->object); + BOOL yes = CATransform3DEqualToTransform( tran1.transform, tran2.transform); + lua_pushboolean(L, (yes?1:0) ); + return 1; + } + } + return 0; +} + +static int __tostring (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( LVIsType(user, Transform3D) ){ + NSString* s = [NSString stringWithFormat:@"LVUserDataTransform3D: %d", (int)user ]; + lua_pushstring(L, s.UTF8String); + return 1; + } + return 0; +} + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewTransform3D globalName:globalName defaultName:@"Transform3D"]; + + const struct luaL_Reg memberFunctions [] = { + {"__eq", __eq}, + {"__mul", __mul}, + {"rotate", rotate}, + {"scale", scale}, + {"translation", translation}, + + {"isIdentity", isIdentity}, + {"reset", reset}, + + {"set", transform_set}, + {"concat", concat}, + + {"__tostring", __tostring}, + + {NULL, NULL} + }; + + lv_createClassMetaTable(L ,META_TABLE_Transform3D); + + luaL_openlib(L, NULL, memberFunctions, 0); + return 1; +} + +@end + +void CATransform3DSetRotation(CATransform3D *t, CGFloat v) { + double scaleX = CATransform3DGetScaleX(t), scaleY = CATransform3DGetScaleY(t); + t->m11 = scaleX * cos(v); + t->m12 = scaleX * sin(v); + t->m21 = -(scaleY * sin(v)); + t->m22 = scaleY * cos(v); +} + +double CATransform3DGetRotation(CATransform3D *t) { + return atan2(t->m12, t->m11); +} + +void CATransform3DSetScaleX(CATransform3D *t, CGFloat v) { + double r = CATransform3DGetRotation(t); + t->m11 = v * cos(r); + t->m12 = v * sin(r); +} + +double CATransform3DGetScaleX(CATransform3D *t) { + double r = CATransform3DGetRotation(t); + + if (t->m11 != 0) { + return t->m11 / cos(r); + } else if (t->m12 != 0) { + return t->m12 / sin(r); + } else { + return 0; + } +} + +void CATransform3DSetScaleY(CATransform3D *t, CGFloat v) { + double r = CATransform3DGetRotation(t); + t->m21 = -(v * sin(r)); + t->m22 = v * cos(r); +} + +double CATransform3DGetScaleY(CATransform3D *t) { + double r = CATransform3DGetRotation(t); + + if (t->m21 != 0) { + return -(t->m21 / sin(r)); + } else if (t->m22 != 0) { + return t->m22 / cos(r); + } else { + return 0; + } +} + +void CATransform3DSetScaleZ(CATransform3D *t, CGFloat v) { + t->m33 = v; +} + +double CATransform3DGetScaleZ(CATransform3D *t) { + return t->m33; +} + +void CATransform3DSetTranslationX(CATransform3D *t, CGFloat v) { + t->m41 = v; +} + +double CATransform3DGetTranslationX(CATransform3D *t) { + return t->m41; +} + +void CATransform3DSetTranslationY(CATransform3D *t, CGFloat v) { + t->m42 = v; +} + +double CATransform3DGetTranslationY(CATransform3D *t) { + return t->m42; +} + +void CATransform3DSetTranslationZ(CATransform3D *t, CGFloat v) { + t->m43 = v; +} + +double CATransform3DGetTranslationZ(CATransform3D *t) { + return t->m43; +} diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTypeConvert.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTypeConvert.h new file mode 100644 index 00000000..0ea3f45a --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTypeConvert.h @@ -0,0 +1,24 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" +#import "LVUtil.h" + +@interface LVTypeConvert : NSObject + +int lv_pushInvocationReturnValueToLuaStack(NSInvocation* invocation, lua_State* L); +id lv_setInvocationReturnValueByLuaStack(NSInvocation* invocation, lua_State* L, int stackID); + +int lv_pushInvocationArgToLuaStack(NSInvocation* invocation, int index, lua_State* L); +int lv_setInvocationArgByLuaStack(NSInvocation* invocation, int index, lua_State* L, int stackID); + +int lv_setValueWithType(void* p, int index, double value, int type ); +double lv_getValueWithType(void* p, int index, int type ); + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTypeConvert.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTypeConvert.m new file mode 100644 index 00000000..c670d378 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTypeConvert.m @@ -0,0 +1,696 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVTypeConvert.h" +#import "LVHeads.h" +#import "LVStruct.h" +#import "LVHeads.h" +#import + +@implementation LVTypeConvert + +static int typeIdx(const char* type){ + if( type ) { + unsigned char c0 = type[0]; + unsigned char c1 = type[1]; + if ( c1==0 ){ + return 256*0 + c0; + } else if ( c0=='r' ) { // const + return 256*1 + c1; + } else if ( c0=='^' ) { // 指针 + return 256*2 + c1; + } else if ( c0=='{' ) { // 结构体 + return 256*3 + 0; + } else { + LVError(@"LVUtil.typeIdx: %s", type); + return 0; + } + } + return 0; +} + +LVTypeIDEnum lua_typeID(const char* type){ + static LVTypeIDEnum typesDic[256*4] = {0}; + static BOOL inited = NO; + if( !inited ) { + inited = YES; + + typesDic[typeIdx(@encode(void))] = LVTypeID_void; + typesDic[typeIdx(@encode(bool))] = LVTypeID_bool; + typesDic[typeIdx(@encode(BOOL))] = LVTypeID_BOOL; + typesDic[typeIdx(@encode(char))] = LVTypeID_char; + typesDic[typeIdx(@encode(unsigned char))] = LVTypeID_unsignedchar; + typesDic[typeIdx(@encode(short))] = LVTypeID_short; + typesDic[typeIdx(@encode(unsigned short))] = LVTypeID_unsignedshort; + typesDic[typeIdx(@encode(int))] = LVTypeID_int; + typesDic[typeIdx(@encode(unsigned int))] = LVTypeID_unsignedint; + typesDic[typeIdx(@encode(NSInteger))] = LVTypeID_NSInteger; + typesDic[typeIdx(@encode(NSUInteger))] = LVTypeID_NSUInteger; + typesDic[typeIdx(@encode(long long))] = LVTypeID_longlong; + typesDic[typeIdx(@encode(unsigned long long))] = LVTypeID_unsigedlonglong; + typesDic[typeIdx(@encode(float))] = LVTypeID_float; + typesDic[typeIdx(@encode(CGFloat))] = LVTypeID_CGFloat; + typesDic[typeIdx(@encode(double))] = LVTypeID_double; + + typesDic[typeIdx(@encode(BOOL*))] = LVTypeID_charP; + typesDic[typeIdx(@encode(char*))] = LVTypeID_charP; + typesDic[typeIdx(@encode(short*))] = LVTypeID_charP; + typesDic[typeIdx(@encode(int*))] = LVTypeID_charP; + typesDic[typeIdx(@encode(NSInteger*))] = LVTypeID_charP; + typesDic[typeIdx(@encode(long*))] = LVTypeID_charP; + typesDic[typeIdx(@encode(float*))] = LVTypeID_charP; + typesDic[typeIdx(@encode(CGFloat*))] = LVTypeID_charP; + typesDic[typeIdx(@encode(double*))] = LVTypeID_charP; + typesDic[typeIdx(@encode(unsigned char*))] = LVTypeID_charP; + typesDic[typeIdx(@encode(unsigned short*))] = LVTypeID_charP; + typesDic[typeIdx(@encode(unsigned int*))] = LVTypeID_charP; + typesDic[typeIdx(@encode(NSUInteger*))] = LVTypeID_charP; + typesDic[typeIdx(@encode(unsigned long*))] = LVTypeID_charP; + typesDic[typeIdx(@encode(void*))] = LVTypeID_voidP; + typesDic[typeIdx(@encode(void**))] = LVTypeID_voidP; + + typesDic[typeIdx(@encode(const BOOL*))] = LVTypeID_charP; + typesDic[typeIdx(@encode(const char*))] = LVTypeID_charP; + typesDic[typeIdx(@encode(const short*))] = LVTypeID_charP; + typesDic[typeIdx(@encode(const int*))] = LVTypeID_charP; + typesDic[typeIdx(@encode(const long*))] = LVTypeID_charP; + typesDic[typeIdx(@encode(const float*))] = LVTypeID_charP; + typesDic[typeIdx(@encode(const double*))] = LVTypeID_charP; + + typesDic[typeIdx(@encode(const void*))] = LVTypeID_voidP; + typesDic[typeIdx("^{")] = LVTypeID_voidP; + typesDic[typeIdx(@encode(id))] = LVTypeID_id; + typesDic[typeIdx(@encode(Class))] = LVTypeID_Class; + + typesDic[typeIdx(@encode(CGRect))] = LVTypeID_struct; + } + return typesDic[ typeIdx(type) ]; +} + +int lv_setValueWithType(void* p, int index, double value, int type ){ + if ( p ) { + switch (type) { + case 'b': + case 'B': { + BOOL* cp = p; + cp[index] = (BOOL)value; + return 1; + } + case 'c': + case 'C': { + char* cp = p; + cp[index] = (char)value; + return 1; + } + case 's': + case 'S': { + short* cp = p; + cp[index] = (short)value; + return 1; + } + case 'i': + case 'I': { + int* cp = p; + cp[index] = (int)value; + return 1; + } + case 'l': + case 'L': { + long* cp = p; + cp[index] = (long)value; + return 1; + } + case 'q': + case 'Q': { + long long* cp = p; + cp[index] = (long long)value; + return 1; + } + case 'f': { + float* cp = p; + cp[index] = (float)value; + return 1; + } + case 'd': { + double* cp = p; + cp[index] = (double)value; + return 1; + } + default: { + LVError(@"lv_setValueWithType: %c", type); + return 0; + } + } + } + return 0; +} + +double lv_getValueWithType(void* p, int index, int type ){ + if ( p ) { + switch (type) { + case 'b': + case 'B': { + BOOL* cp = p; + return cp[index]; + } + case 'c': + case 'C': { + char* cp = p; + return cp[index]; + } + case 's': + case 'S': { + short* cp = p; + return cp[index]; + } + case 'i': + case 'I': { + int* cp = p; + return cp[index]; + } + case 'l': + case 'L': { + long* cp = p; + return cp[index]; + } + case 'q': + case 'Q': { + long long* cp = p; + return cp[index]; + } + case 'f': { + float* cp = p; + return cp[index]; + } + case 'd': { + double* cp = p; + return cp[index]; + } + default: { + LVError(@"lv_getValueWithType: %c", type); + return 0; + } + } + } + return 0; +} + +int lv_pushInvocationReturnValueToLuaStack(NSInvocation* invocation, lua_State* L){ + const char* type = [invocation.methodSignature methodReturnType]; + if ( type ){ + switch ( lua_typeID(type) ) { + case LVTypeID_void: + return 0; + case LVTypeID_BOOL: { + BOOL result = 0; + [invocation getReturnValue: &result]; + lua_pushboolean(L, result); + return 1; + } + case LVTypeID_bool: { + bool result = 0; + [invocation getReturnValue: &result]; + lua_pushboolean(L, result); + return 1; + } + case LVTypeID_Class: + case LVTypeID_id: { + void* result = nil; + [invocation getReturnValue: &result]; + lv_pushNativeObject(L,(__bridge id)result); + return 1; + } + case LVTypeID_char: { + char result = 0; + [invocation getReturnValue: &result]; + lua_pushnumber(L, result); + return 1; + } + case LVTypeID_unsignedchar: { + unsigned char result = 0; + [invocation getReturnValue: &result]; + lua_pushnumber(L, result); + return 1; + } + case LVTypeID_short: { + short result = 0; + [invocation getReturnValue: &result]; + lua_pushnumber(L, result); + return 1; + } + case LVTypeID_unsignedshort: { + unsigned short result = 0; + [invocation getReturnValue: &result]; + lua_pushnumber(L, result); + return 1; + } + case LVTypeID_int: { + int result = 0; + [invocation getReturnValue: &result]; + lua_pushnumber(L, result); + return 1; + } + case LVTypeID_unsignedint: { + unsigned int result = 0; + [invocation getReturnValue: &result]; + lua_pushnumber(L, result); + return 1; + } + case LVTypeID_NSInteger: { + NSInteger result = 0; + [invocation getReturnValue: &result]; + lua_pushnumber(L, result); + return 1; + } + case LVTypeID_NSUInteger: { + NSUInteger result = 0; + [invocation getReturnValue: &result]; + lua_pushnumber(L, result); + return 1; + } + case LVTypeID_longlong: { + long long result = 0; + [invocation getReturnValue: &result]; + lua_pushnumber(L, result); + return 1; + } + case LVTypeID_unsigedlonglong: { + unsigned long long result = 0; + [invocation getReturnValue: &result]; + lua_pushnumber(L, result); + return 1; + } + case LVTypeID_float: { + float result = 0; + [invocation getReturnValue: &result]; + lua_pushnumber(L, result); + return 1; + } + case LVTypeID_CGFloat: { + CGFloat result = 0; + [invocation getReturnValue: &result]; + lua_pushnumber(L, result); + return 1; + } + case LVTypeID_double: { + double result = 0; + [invocation getReturnValue: &result]; + lua_pushnumber(L, result); + return 1; + } + case LVTypeID_charP: { + char* result = 0; + [invocation getReturnValue: &result]; + lua_pushlightuserdata(L, result); + return 1; + } + case LVTypeID_voidP: { + void* result = 0; + [invocation getReturnValue: &result]; + lua_pushlightuserdata(L, result); + return 1; + } + case LVTypeID_struct:{ + CGFloat result[LV_STRUCT_MAX_LEN] = {0}; + [invocation getReturnValue: result]; + [LVStruct pushStructToLua:L data:result]; + return 1; + } + default: + LVError(@"LVMethod.pushReturnToLuaStack"); + break; + } + } + return 0; +} + +int lv_setInvocationArgByLuaStack(NSInvocation* invocation, int index, lua_State* L, int stackID){ + const char* type = [invocation.methodSignature getArgumentTypeAtIndex:index]; + if ( type ){ + switch ( lua_typeID(type) ) { + case LVTypeID_BOOL: { + BOOL value = lua_toboolean(L, stackID); + [invocation setArgument: &value atIndex:index]; + return 1; + } + case LVTypeID_bool: { + bool value = lua_toboolean(L, stackID); + [invocation setArgument: &value atIndex:index]; + return 1; + } + case LVTypeID_Class: + case LVTypeID_id: { + id nativeObject = lv_luaValueToNativeObject(L, stackID); + [invocation setArgument:&nativeObject atIndex:index]; + return 1; + } + case LVTypeID_char: { + char value = lua_tonumber(L, stackID); + [invocation setArgument: &value atIndex:index]; + return 1; + } + case LVTypeID_unsignedchar: { + unsigned char value = lua_tonumber(L, stackID); + [invocation setArgument: &value atIndex:index]; + return 1; + } + case LVTypeID_short: { + short value = lua_tonumber(L, stackID); + [invocation setArgument: &value atIndex:index]; + return 1; + } + case LVTypeID_unsignedshort: { + unsigned short value = lua_tonumber(L, stackID); + [invocation setArgument: &value atIndex:index]; + return 1; + } + case LVTypeID_int: { + int value = lua_tonumber(L, stackID); + [invocation setArgument: &value atIndex:index]; + return 1; + } + case LVTypeID_unsignedint: { + unsigned int value = lua_tonumber(L, stackID); + [invocation setArgument: &value atIndex:index]; + return 1; + } + case LVTypeID_NSInteger: { + NSInteger value = lua_tonumber(L, stackID); + [invocation setArgument: &value atIndex:index]; + return 1; + } + case LVTypeID_NSUInteger: { + NSUInteger value = lua_tonumber(L, stackID); + [invocation setArgument: &value atIndex:index]; + return 1; + } + case LVTypeID_longlong: { + long long value = lua_tonumber(L, stackID); + [invocation setArgument: &value atIndex:index]; + return 1; + } + case LVTypeID_unsigedlonglong: { + unsigned long long value = lua_tonumber(L, stackID); + [invocation setArgument: &value atIndex:index]; + return 1; + } + case LVTypeID_float: { + float value = lua_tonumber(L, stackID); + [invocation setArgument: &value atIndex:index]; + return 1; + } + case LVTypeID_CGFloat: { + CGFloat value = lua_tonumber(L, stackID); + [invocation setArgument: &value atIndex:index]; + return 1; + } + case LVTypeID_double: { + double value = lua_tonumber(L, stackID); + [invocation setArgument: &value atIndex:index]; + return 1; + } + case LVTypeID_charP: { + char* value = lua_touserdata(L, stackID); + [invocation setArgument: &value atIndex:index]; + return 1; + } + case LVTypeID_voidP: { + void* value = lua_touserdata(L, stackID); + [invocation setArgument: &value atIndex:index]; + return 1; + } + case LVTypeID_struct: { + LVUserDataInfo* user = lua_touserdata(L, stackID); + if ( LVIsType(user, Struct) ) { + LVStruct* stru = (__bridge LVStruct *)(user->object); + if( [stru dataPointer] ) { + [invocation setArgument:[stru dataPointer] atIndex:index]; + } + } + return 1; + } + default: { + NSInteger value = 0; + [invocation setArgument: &value atIndex:index]; + LVError(@"setIvocationArgument:index:byLua:"); + break; + } + } + } + //否则将参数设置为空 + NSInteger value = 0; + [invocation setArgument: &value atIndex:index]; + return 0; +} + +id lv_setInvocationReturnValueByLuaStack(NSInvocation* invocation, lua_State* L, int stackID){ + const char* type = [invocation.methodSignature methodReturnType]; + if ( type ) { + switch ( lua_typeID(type) ) { + case LVTypeID_void: + return nil; + case LVTypeID_BOOL: { + BOOL result = lua_toboolean(L, stackID); + [invocation setReturnValue: &result]; + return nil; + } + case LVTypeID_bool: { + bool result = lua_toboolean(L, stackID); + [invocation setReturnValue: &result]; + return nil; + } + case LVTypeID_Class: + case LVTypeID_id: { + id object = lv_luaValueToNativeObject(L, stackID); + [invocation setReturnValue:&object]; + return object; + } + case LVTypeID_char: { + char result = lua_tonumber(L, stackID); + [invocation setReturnValue: &result]; + return nil; + } + case LVTypeID_unsignedchar: { + unsigned char result = lua_tonumber(L, stackID); + [invocation setReturnValue: &result]; + return nil; + } + case LVTypeID_short: { + short result = lua_tonumber(L, stackID); + [invocation setReturnValue: &result]; + return nil; + } + case LVTypeID_unsignedshort: { + unsigned short result = lua_tonumber(L, stackID); + [invocation setReturnValue: &result]; + return nil; + } + case LVTypeID_int: { + int result = lua_tonumber(L, stackID); + [invocation setReturnValue: &result]; + return nil; + } + case LVTypeID_unsignedint: { + unsigned int result = lua_tonumber(L, stackID); + [invocation setReturnValue: &result]; + return nil; + } + case LVTypeID_NSInteger: { + NSInteger result = lua_tonumber(L, stackID); + [invocation setReturnValue: &result]; + return nil; + } + case LVTypeID_NSUInteger: { + NSUInteger result = lua_tonumber(L, stackID); + [invocation setReturnValue: &result]; + return nil; + } + case LVTypeID_longlong: { + long long result = lua_tonumber(L, stackID); + [invocation setReturnValue: &result]; + return nil; + } + case LVTypeID_unsigedlonglong: { + unsigned long long result = lua_tonumber(L, stackID); + [invocation setReturnValue: &result]; + return nil; + } + case LVTypeID_float: { + float result = lua_tonumber(L, stackID); + [invocation setReturnValue: &result]; + return nil; + } + case LVTypeID_CGFloat: { + CGFloat result = lua_tonumber(L, stackID); + [invocation setReturnValue: &result]; + return nil; + } + case LVTypeID_double: { + double result = lua_tonumber(L, stackID); + [invocation setReturnValue: &result]; + return nil; + } + case LVTypeID_charP: { + char* result = lua_touserdata(L,stackID); + [invocation setReturnValue: &result]; + return nil; + } + case LVTypeID_voidP: { + char* result = lua_touserdata(L,stackID); + [invocation setReturnValue: &result]; + return nil; + } + case LVTypeID_struct: { + LVUserDataInfo* user = lua_touserdata(L,stackID); + if ( LVIsType(user, Struct) ) { + LVStruct* stru = (__bridge LVStruct *)(user->object); + if( [stru dataPointer] ) { + [invocation setReturnValue: [stru dataPointer]]; + } + } + return nil; + } + default: + LVError( @"LVLuaObjBox.setInvocationReturnValue:withLuaObject:"); + break; + } + } + return nil ; +} + +int lv_pushInvocationArgToLuaStack(NSInvocation* invocation, int index, lua_State* L ){ + const char* type = [invocation.methodSignature getArgumentTypeAtIndex:index]; + switch ( lua_typeID(type) ) { + case LVTypeID_BOOL: { + BOOL value = 0; + [invocation getArgument: &value atIndex:index]; + lua_pushnumber(L, value); + return 1; + } + case LVTypeID_bool: { + bool value = 0; + [invocation getArgument: &value atIndex:index]; + lua_pushnumber(L, value); + return 1; + } + case LVTypeID_Class: + case LVTypeID_id: { + void* value = nil; + [invocation getArgument:&value atIndex:index]; + lv_pushNativeObject(L, (__bridge id)value); + return 1; + } + case LVTypeID_char: { + char value = 0; + [invocation getArgument: &value atIndex:index]; + lua_pushnumber(L, value); + return 1; + } + case LVTypeID_unsignedchar: { + unsigned char value = 0; + [invocation getArgument: &value atIndex:index]; + lua_pushnumber(L, value); + return 1; + } + case LVTypeID_short: { + short value = 0; + [invocation getArgument: &value atIndex:index]; + lua_pushnumber(L, value); + return 1; + } + case LVTypeID_unsignedshort: { + unsigned short value = 0; + [invocation getArgument: &value atIndex:index]; + lua_pushnumber(L, value); + return 1; + } + case LVTypeID_int: { + int value = 0; + [invocation getArgument: &value atIndex:index]; + lua_pushnumber(L, value); + return 1; + } + case LVTypeID_unsignedint: { + unsigned int value = 0; + [invocation getArgument: &value atIndex:index]; + lua_pushnumber(L, value); + return 1; + } + case LVTypeID_NSInteger: { + NSInteger value = 0; + [invocation getArgument: &value atIndex:index]; + lua_pushnumber(L, value); + return 1; + } + case LVTypeID_NSUInteger: { + NSUInteger value = 0; + [invocation getArgument: &value atIndex:index]; + lua_pushnumber(L, value); + return 1; + } + case LVTypeID_longlong: { + long long value = 0; + [invocation getArgument: &value atIndex:index]; + lua_pushnumber(L, value); + return 1; + } + case LVTypeID_unsigedlonglong: { + unsigned long long value = 0; + [invocation getArgument: &value atIndex:index]; + lua_pushnumber(L, value); + return 1; + } + case LVTypeID_float: { + float value = 0; + [invocation getArgument: &value atIndex:index]; + lua_pushnumber(L, value); + return 1; + } + case LVTypeID_CGFloat: { + CGFloat value = 0; + [invocation getArgument: &value atIndex:index]; + lua_pushnumber(L, value); + return 1; + } + case LVTypeID_double: { + double value = 0; + [invocation getArgument: &value atIndex:index]; + lua_pushnumber(L, value); + return 1; + } + case LVTypeID_charP: { + char* value = 0; + [invocation getArgument: &value atIndex:index]; + lua_pushlightuserdata(L,value); + return 1; + } + case LVTypeID_voidP: { + void* value = 0; + [invocation getArgument: &value atIndex:index]; + lua_pushlightuserdata(L,value); + return 1; + } + case LVTypeID_struct: { + CGFloat result[LV_STRUCT_MAX_LEN] = {0}; + [invocation getArgument:result atIndex:index]; + [LVStruct pushStructToLua:L data:result]; + return 1; + } + default:{ + LVError(@"LVLuaObjBox.pushInvocation:argIndex:toLua:"); + //否则将参数设置为空 + NSInteger value = 0; + [invocation setArgument: &value atIndex:index]; + return 1; + } + } +} + + + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVUtil.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVUtil.h new file mode 100644 index 00000000..23e4b6fd --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVUtil.h @@ -0,0 +1,232 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import +#import "LVHeads.h" + +@class LVBundle; +@class LuaViewCore; + +typedef void(^LVFuncDownloadEndCallback)(NSData* data); + +@interface LVUtil : NSObject + +/** + * 调用lua对应的方法(如果是function直接调用, 如果是table用key去查找后再调用) + * + * @param l luastate + * @param table 用户数据 + * @param key + * + * @return stackNumber + */ ++(NSString*) call:(lua_State*) l lightUserData:(id) lightUserData key1:(const char*)key1 key2:(const char*)key2 nargs:(int)nargs; + ++(NSString*) call:(lua_State*) l key1:(const char*)key1 key2:(const char*)key2 key3:(const char*)key3 + nargs:(int)nargs nrets:(int)nret + retType:(int) retType; + ++(NSString*) call:(lua_State*) l key1:(const char*)key1 key2:(const char*)key2 key3:(const char*)key3 key4:(const char*)key4 + nargs:(int)nargs nrets:(int)nret + retType:(int) retType; + +/* + * download file + */ ++(void) download:(NSString*) url callback:(LVFuncDownloadEndCallback) nextStep; + +/* + * NSData -> 文件 + */ ++(BOOL) saveData:(NSData*) data toFile:(NSString*) fileName; + +/* + * 文件 -> NSData + */ ++(NSData*) dataReadFromFile:(NSString*) fileName; + + +/* + * 删除文件 + */ ++(BOOL) deleteFile:(NSString*)path; + +/* + * NSCachesDirectory: 相对路径 -> 绝对路径 + */ ++ (NSString*) PathForCachesResource:(NSString* )relativePath ; + +/* + * NSDocumentDirectory: 相对路径 -> 绝对路径 + */ ++ (NSString*) PathForDocumentsResource:(NSString*) relativePath; + +/* + * + */ ++ (NSString*) PathForBundle:(NSBundle*) bundle relativePath:(NSString*) relativePath; + +/* + * 创建目录 + */ ++(BOOL) createPath:(NSString*) path; + ++(BOOL) exist:(NSString*) path; + +/* + * json解析 + */ ++(id) stringToObject:(NSString*) s; ++(NSString*) objectToString:(id) obj; + +/* + * MD5 + */ ++ (NSString*) MD5HashFromData:(NSData*) data; ++ (NSData*) MD5HashDataFromData:(NSData*) data; + +NSData *LV_AES256DecryptDataWithKey(NSData *data, NSData* key); + +// 全局注册表添加/删除 ++ (void) registryValue:(lua_State*) L key:(id) key stack:(int) valueIndex; ++ (void) unregistry:(lua_State*) L key:(id) key; ++ (void) pushRegistryValue:(lua_State*) L key:(id) key; + +// UData 关联脚本object +void lv_udataRef(lua_State* L, int key); // -2: userdata -1: value +void lv_udataUnref(lua_State* L, int key); // -1: userdata +void lv_pushUDataRef(lua_State* L, int key); // -1: userdata + +int lv_createUDataLuatable (lua_State *L, int objindex); +//int lv_setUDataLuatable (lua_State *L, int objindex); +int lv_getUDataLuatable (lua_State *L, int objindex); +/* + * Create Class MetaTable + */ +void lv_createClassMetaTable(lua_State* L, const char* name); + +/* + * Push userData to stack + */ +void lv_pushUserdata(lua_State* L, void* p); + +/* + * table -> NSDictionary + */ +id lv_luaTableToDictionary(lua_State* L, int index); + +/* + * table -> NSArray + */ +NSArray* lv_luaTableToArray(lua_State* L, int idx); + +/* + * oc对象(所有类型) 转成 luavalue + */ +void lv_pushNativeObject(lua_State* L , id value ); + +/* + * oc对象(非基本类型) 转成 luavalue + */ +void lv_pushNativeObjectWithBox(lua_State* L,id nativeObject); + +/* + * luavalue 转成 oc对象 + */ +id lv_luaValueToNativeObject(lua_State* L, int idx); + +/* + * 获取LuaTable对象的 keys + */ +NSArray* lv_luaTableKeys(lua_State* L, int index); + +/* + * 移除LuaTable对象的 指定Keys + */ +void lv_luaTableRemoveKeys(lua_State* L, const char** keys); + +/* + * lua table是否包含属性 + */ +BOOL lv_isLuaObjectHaveProperty(lua_State* L, int idx, const char* key); + +/* + * lua table添加window属性 + */ +void lv_luaTableSetWeakWindow(lua_State* L, UIView* cell); + +/** + * 重置lua虚拟机的栈大小位置 + * + * @param l lua state + */ +void lua_checkstack32(lua_State* l); + +/** + * 清理首个无效参数 + * + * @param l lua state + */ +void lv_clearFirstTableValue(lua_State* l); + +/* + * uicolor -> int + */ +BOOL lv_uicolor2int(UIColor* color,NSUInteger* c, CGFloat* alpha); + +UIColor* lv_getColorFromStack(lua_State* L, int stackID); + + +/* + * Is External Url + */ ++(BOOL) isExternalUrl:(NSString*) url; + +UIColor* lv_UIColorFromRGBA(NSInteger aRGB ,float alpha); + ++(BOOL) ios8; + + ++ (int) loadFont:(NSString*) fileName package:(LVBundle*)bundle; ++ (UIFont *)fontWithName:(NSString *)fontName size:(CGFloat)fontSize bundle:(LVBundle*)bundle; + +void LVLog( NSString* format, ... ); +void LVError( NSString* format, ... ); + +//---------------------------------------- +int lv_callbackFunction(lua_State* l, const char* functionName); + +BOOL lv_objcEqual(id obj1, id obj2); + ++(void) reg:(lua_State*)L clas:(id) c cfunc:(lua_CFunction) cfunc globalName:(NSString*)globalName defaultName:(NSString*) defaultName; + ++(Class) upvalueClass:(lua_State*)L defaultClass:(Class) defaultClass; + ++(void) defineGlobal:(NSString*)globalName value:(id) value L:(lua_State*)L; +void lv_defineGlobalFunc(const char* globalName, lua_CFunction func, lua_State* L); + +void lv_addSubview(LuaViewCore* lv, UIView* superview, UIView* subview); + +extern NSString* safe_stringForKey(NSDictionary*dic, id key); +extern NSDictionary * safe_dictionaryForKey(NSDictionary* dic, id key); +NSDate * safe_dateForKey(NSDictionary* dic, id key ); + + + ++ (NSTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval)inTimeInterval + block:(void (^)(NSTimer *timer))block + repeats:(BOOL)inRepeats; +/* + * 显示Lua的调用堆栈 + */ ++ (NSString*) luaTrace:(lua_State*) L; + +@end + + diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVUtil.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVUtil.m new file mode 100644 index 00000000..44c2dd80 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVUtil.m @@ -0,0 +1,969 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVUtil.h" +#import +#import "LVBlock.h" +#import "LVNativeObjBox.h" +#import "LVPkgManager.h" +#import "LVLuaObjBox.h" +#import "LVPointerValueBox.h" +#import "LVDebuger.h" +#import "LVHeads.h" +#import + +@implementation LVUtil + + ++(BOOL) isExternalUrl:(NSString*) url{ + return [url hasPrefix:@"https://"] || [url hasPrefix:@"http://"]; +} + ++(NSString*) call:(lua_State*) l lightUserData:(id) lightUserData key1:(const char*) key1 key2:(const char*)key2 nargs:(int)nargs { + if( l ){ + lua_checkstack32(l); + lua_pushlightuserdata(l, (__bridge void *)lightUserData);// key=view + lua_gettable(l, LUA_REGISTRYINDEX);/* table = registry[&Key] */ + + return [LVUtil call:l key1:key1 key2:key2 nargs:nargs nrets:0]; + } + return nil; +} + ++(NSString*) call:(lua_State*) l key1:(const char*) key1 key2:(const char*)key2 nargs:(int)nargs nrets:(int)nret{ + return [LVUtil call:l key1:key1 key2:key2 key3:NULL nargs:nargs nrets:nret retType:-8]; +} + ++(NSString*) call:(lua_State*) l key1:(const char*) key1 key2:(const char*)key2 key3:(const char*)key3 + nargs:(int)nargs nrets:(int)nret + retType:(int) retType{ + return [self call:l key1:key1 key2:key2 key3:key3 key4:NULL nargs:nargs nrets:nret retType:retType]; +} + ++(NSString*) call:(lua_State*) l key1:(const char*) key1 key2:(const char*)key2 key3:(const char*)key3 key4:(const char*)key4 + nargs:(int)nargs nrets:(int)nret + retType:(int) retType{ + if( l ){ + if( lua_type(l, -1)==LUA_TNIL ){ + return @"LVUtil: call nil function"; + } else if( lua_type(l, -1)==LUA_TTABLE && key1){//table + lua_getfield(l, -1, key1); + lua_remove(l, -2); + + if( lua_type(l, -1)==LUA_TTABLE && key2){//table + lua_getfield(l, -1, key2); + lua_remove(l, -2); + + if( lua_type(l, -1)==LUA_TTABLE && key3){//table + lua_getfield(l, -1, key3); + lua_remove(l, -2); + + if( lua_type(l, -1)==LUA_TTABLE && key4){//table + lua_getfield(l, -1, key4); + lua_remove(l, -2); + } + } + } + } + int type = lua_type(l, -1); + if ( type==retType && nret==1 ) { + return nil; + } + if( type == LUA_TFUNCTION ){//function + return lv_runFunctionWithArgs(l, nargs, nret); + } + } + return @"LVUtil:lua_State is nil"; +} + +NSString* lv_runFunction(lua_State* l){ + return lv_runFunctionWithArgs(l, 0, 0); +} + +NSString* lv_runFunctionWithArgs(lua_State* l, int nargs, int nret){ + if( l && lua_type(l, -1) == LUA_TFUNCTION ) { + if( nargs>0 ){ + lua_insert(l, -nargs-1); + } + int errorCode = lua_pcall( l, nargs, nret, 0); + if ( errorCode != 0 ) { + const char* s = lua_tostring(l, -1); + LVError( @"%s", s ); +#ifdef DEBUG + NSString* string = [NSString stringWithFormat:@"[LuaView][error] %s",s]; + lv_printToServer(l, string.UTF8String, 0); +#endif + return [NSString stringWithFormat:@"%s",s]; + } + return nil; + } + return @"function is nil error"; +} + +#define api_incr_top(L) {api_check(L, L->top < L->ci->top); L->top++;} +void lv_pushUserdata(lua_State* L, void* p){///是否正确 ???????? + if( p ) { + Udata* u = (Udata*)p; + u -= 1; + lua_lock(L); + luaC_checkGC(L); + setuvalue(L, L->top, u); + api_incr_top(L); + lua_unlock(L); + } else { + lua_pushnil(L); + } +} + +id lv_luaTableToDictionary(lua_State* L ,int index){ + if( lua_type(L, index)!=LUA_TTABLE ) { + return nil; + } + lua_checkstack(L, 128); + NSMutableDictionary* dic = nil; + NSMutableArray* array = nil; + //lua_settop(L, 8); + // Push another reference to the table on top of the stack (so we know + // where it is, and this function can work for negative, positive and + // pseudo indices + lua_pushvalue(L, index); + // stack now contains: -1 => table + lua_pushnil(L); + // stack now contains: -1 => nil; -2 => table + while (lua_next(L, -2)) + { + int keyType = lua_type(L, -2); + + id value = nil; + if( lua_type(L, -1)==LUA_TSTRING ){ + value = lv_paramString(L, -1); + } else if( lua_type(L, -1)==LUA_TNUMBER ){ + value = @(lua_tonumber(L, -1) ); + } else if( lua_type(L, -1)==LUA_TTABLE ){ + value = lv_luaTableToDictionary(L,-1); + } else if( lua_type(L, -1)==LUA_TBOOLEAN ){ + value = @( ((BOOL)lua_toboolean(L, -1)) ); + } else if ( lua_type(L, -1)==LUA_TUSERDATA ) { + LVUserDataInfo* user = (LVUserDataInfo*)lua_touserdata(L, -1); + id obj = (__bridge id)(user->object); + if( [obj respondsToSelector:@selector(lv_nativeObject)] ){ + value = [obj lv_nativeObject]; + } else { + LVError(@"lv_luaTableToDictionary.1"); + } + } else { + LVError(@"lv_luaTableToDictionary.2"); + } + // stack now contains: -1 => value; -2 => key; -3 => table + if( value ) { + if( keyType== LUA_TNUMBER ) { + // number key + if( array == nil ) { + array = [[NSMutableArray alloc] init]; + } + [array addObject:value]; + } else { // string + NSString* key = lv_paramString(L, -2); + if( key ) { + if( dic == nil ) { + dic = [[NSMutableDictionary alloc] init]; + } + [dic setObject:value forKey:key]; + } + } + } + lua_pop(L, 1); + // stack now contains: -1 => key; -2 => table + } + lua_pop(L, 1); + + if( [dic count]>0 ) { + return dic; + } + if ( array.count>0 ) { + return array; + } + // Stack is now the same as it was on entry to this function + return @{}; +} + +NSArray* lv_luaTableKeys(lua_State* L, int index){ + lua_checkstack(L, 128); + NSMutableArray* keys = [[NSMutableArray alloc] init]; + //lua_settop(L, 8); + // Push another reference to the table on top of the stack (so we know + // where it is, and this function can work for negative, positive and + // pseudo indices + if ( lua_type(L, index)!= LUA_TTABLE ){ + return nil; + } + lua_pushvalue(L, index); + // stack now contains: -1 => table + lua_pushnil(L); + // stack now contains: -1 => nil; -2 => table + while (lua_next(L, -2)) + { + NSString* key = lv_paramString(L, -2); + // stack now contains: -1 => value; -2 => key; -3 => table + if( key ) { + [keys addObject:key]; + } + lua_pop(L, 1); + // stack now contains: -1 => key; -2 => table + } + lua_pop(L, 1); + // Stack is now the same as it was on entry to this function + if( keys.count>0 ){ + return keys; + } + return nil; +} + +NSArray* lv_luaTableToArray(lua_State* L,int stackID) +{ + if( lua_type(L, stackID)==LUA_TTABLE) { + int count = luaL_getn(L, stackID); + NSMutableArray* array = [[NSMutableArray alloc] init]; + + for (int i = 0; i < count; i++) + { + lua_rawgeti(L, stackID, i+1); + NSString* s = lv_paramString(L, -1); + [array addObject:s]; + lua_pop(L,1); + } + return array; + } + return nil; +} + +#pragma -mark registry + ++ (void) registryValue:(lua_State*)L key:(id) key stack:(int) stackID{ + if( L ) { + lua_checkstack(L, 4); + lua_pushvalue(L, stackID ); // value + lua_pushlightuserdata(L, (__bridge void *)(key) ); // key + lua_insert(L, -2); // key <==> value 互换 + lua_settable(L, LUA_REGISTRYINDEX);// registry[&Key] = fucntion + } +} + ++ (void) unregistry:(lua_State*) L key:(id) key{ + if( L ) { + lua_checkstack(L, 2); + lua_pushlightuserdata(L, (__bridge void *)(key) ); // key + lua_pushnil(L); // nil + lua_settable(L, LUA_REGISTRYINDEX);// registry[&Key] = nil + } +} + ++ (void) pushRegistryValue:(lua_State*) L key:(id) key{ + if( L ){ + lua_pushlightuserdata(L, (__bridge void *)(key));// key=button + lua_gettable(L, LUA_REGISTRYINDEX);/* value = registry[&Key] */ + } +} + +void lv_createClassMetaTable(lua_State* L , const char* name ){ + luaL_newmetatable(L, name ); + lua_pushstring(L, "__index");//必须要的。 + lua_pushvalue(L, -2); /* pushes the metatable */ + lua_settable(L, -3); /* metatable.__index = metatable */ +} + +void lua_checkstack32(lua_State* l){ + if( l ){ + lua_checkstack( l, 32); + } +} + +void lv_clearFirstTableValue(lua_State* L){ + int num = lua_gettop(L); + if( num>1 && lua_type(L, 1)==LUA_TTABLE ) { + lua_checkstack(L, 4); + lua_getfield(L, 1, LUAVIEW_SYS_TABLE_KEY); + if( lua_isnil(L, -1) ) { + lua_settop(L, num); + } else { + lua_settop(L, num); + lua_remove(L, 1); + } + } +} + +BOOL lv_uicolor2int(UIColor* color,NSUInteger* c, CGFloat* alphaP){ + CGFloat r = 0; + CGFloat g = 0; + CGFloat b = 0; + CGFloat a = 0; + if( [color getRed:&r green:&g blue:&b alpha:&a] ){ + NSUInteger red = (r*255); + NSUInteger green = (g*255); + NSUInteger blue = (b*255); + *c = (red<<16) | (green<<8) | blue; + *alphaP = a; + return YES; + } + return NO; +} + +UIColor* lv_getColorFromStack(lua_State* L, int stackID){ + if ( lua_type(L, stackID)==LUA_TSTRING ) { +// NSString* s = lv_paramString(L, stackID); +// if( s.length>0 && [s characterAtIndex:0]=='#' ) { +// s = [s substringFromIndex:1]; +// NSScanner * scanner = [[NSScanner alloc] initWithString:s] ; +// unsigned long long color = 0; +// [scanner scanHexLongLong:&color]; +// float a = 1; +// if( s.length>=8 ) { +// a = ( (color>>24)&0xff )/255.0; +// } +// float r = ( (color>>16)&0xff )/255.0; +// float g = ( (color>>8)&0xff )/255.0; +// float b = ( (color>>0)&0xff )/255.0; +// UIColor* colorObj = [UIColor colorWithRed:r green:g blue:b alpha:a]; +// return colorObj; +// } + } else if( lua_type(L,stackID)==LUA_TNUMBER ) { + NSUInteger color = lua_tonumber(L, stackID); + float a = 1; + float r = ( (color>>16)&0xff )/255.0; + float g = ( (color>>8)&0xff )/255.0; + float b = ( (color>>0)&0xff )/255.0; + int stackID3 = stackID + 1; + if ( lua_gettop(L)>=stackID3 && lua_type(L,stackID3)==LUA_TNUMBER ) { + a = lua_tonumber(L, stackID+1 ); + if( a>1 ) { + a = 1; + } + if( a<0 ) { + a = 0; + } + } + UIColor* colorObj = [UIColor colorWithRed:r green:g blue:b alpha:a]; + return colorObj; + } + return [UIColor blackColor]; +} + ++(void) download:(NSString*) urlStr callback:(LVFuncDownloadEndCallback) nextStep{ + if( [urlStr hasPrefix:@"//"] ) { + urlStr = [NSString stringWithFormat:@"https:%@",urlStr]; + } + if( [urlStr.lowercaseString hasPrefix:@"http://"] ){ + urlStr = [NSString stringWithFormat:@"https://%@",[urlStr substringFromIndex:7]]; + } + NSURL *url = [NSURL URLWithString:urlStr]; + NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; + [request setHTTPMethod:@"GET"]; + [request setTimeoutInterval:30.0]; + + NSOperationQueue *queue = [[NSOperationQueue alloc]init]; + [NSURLConnection sendAsynchronousRequest:request + queue:queue + completionHandler:^(NSURLResponse *response, NSData *data, NSError *error){ + if( error==nil && data ){ + nextStep(data); + } else { + nextStep(nil); + } + }]; +} + +#pragma file data + ++(BOOL) saveData:(NSData*) data toFile:(NSString*) path{ + if( path ){ + BOOL ret = [data writeToFile:path atomically:YES]; + if( !ret ) { + NSLog(@"[LuaView][error] saveFile: %@", path); + } + return ret; + } + return NO; +} + ++(NSData*) dataReadFromFile:(NSString*)path { + if( path ){ + NSFileManager* fm = [NSFileManager defaultManager]; + NSData* data = [fm contentsAtPath:path]; + return data; + } + return nil; +} + ++(BOOL) deleteFile:(NSString*)path { + if( [self exist:path] ){ + NSFileManager* fm = [NSFileManager defaultManager]; + NSError* err; + [fm removeItemAtPath:path error:&err]; + return err==nil; + } + return YES; +} + ++(BOOL) exist:(NSString*) path{ + BOOL directory = NO; + NSFileManager *fileManage = [NSFileManager defaultManager]; + if ( [fileManage fileExistsAtPath:path isDirectory:&directory] && !directory) { + return YES; + } + return NO; +} + ++ (NSString*) PathForBundle:(NSBundle*) bundle relativePath:(NSString*) relativePath { + NSString* resourcePath = [(nil == bundle ? [NSBundle mainBundle] : bundle) resourcePath]; + return [resourcePath stringByAppendingPathComponent:relativePath]; +} + ++ (NSString*) PathForDocumentsResource:(NSString*) relativePath { + static NSString* documentsPath = nil; + if (nil == documentsPath) { + NSArray* dirs = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); + documentsPath = [dirs objectAtIndex:0]; + } + return [documentsPath stringByAppendingPathComponent:relativePath]; +} + ++ (NSString*) PathForCachesResource:(NSString* )relativePath { + static NSString* cachesPath = nil; + if (nil == cachesPath) { + NSArray* dirs = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); + cachesPath = [dirs objectAtIndex:0]; + } + return [cachesPath stringByAppendingPathComponent:relativePath]; +} + ++(BOOL) createPath:(NSString*) path{ + NSFileManager *fileManage = [NSFileManager defaultManager]; + if ( ![fileManage fileExistsAtPath:path] ) { + NSError* error = nil; + [fileManage createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:&error]; + if( error ) + return NO; + else + return YES; + } + return YES; +} + ++(id) stringToObject:(NSString*) s{ + if( s==nil ) + return nil; + NSData* data = [s dataUsingEncoding:NSUTF8StringEncoding]; + NSError* error = nil; + id dic = [NSJSONSerialization JSONObjectWithData:data + options:NSJSONReadingAllowFragments + error:&error]; + return dic; +} + ++(NSString*) objectToString:(id) obj{ + if( obj ==nil ) + return nil; + NSError* error = nil; + NSData* data = [NSJSONSerialization dataWithJSONObject:obj options:0 error:&error]; + if( data && error==nil ) { + return [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding]; + } + return nil; +} + ++ (NSString*) MD5HashFromData:(NSData*) data { + unsigned char bs[CC_MD5_DIGEST_LENGTH]; + bzero(bs, sizeof(bs)); + CC_MD5_CTX context; + CC_MD5_Init(&context); + size_t bytesHashedNum = 0; + while (bytesHashedNum < [data length]) { + CC_LONG updateSize = 1024 * 1024; + if (([data length] - bytesHashedNum) < (size_t)updateSize) { + updateSize = (CC_LONG)([data length] - bytesHashedNum); + } + CC_MD5_Update(&context, (char *)[data bytes] + bytesHashedNum, updateSize); + bytesHashedNum += updateSize; + } + CC_MD5_Final(bs, &context); + + return [NSString stringWithFormat: + @"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", + bs[0], bs[1], bs[2], bs[3], bs[4], bs[5], bs[6], bs[7], + bs[8], bs[9], bs[10], bs[11], bs[12], bs[13], bs[14],bs[15]]; +} + ++ (NSData*) MD5HashDataFromData:(NSData*) data { + unsigned char bs[CC_MD5_DIGEST_LENGTH]; + bzero(bs, sizeof(bs)); + CC_MD5_CTX context; + CC_MD5_Init(&context); + size_t bytesHashedNum = 0; + while (bytesHashedNum < [data length]) { + CC_LONG updateSize = 1024 * 1024; + if (([data length] - bytesHashedNum) < (size_t)updateSize) { + updateSize = (CC_LONG)([data length] - bytesHashedNum); + } + CC_MD5_Update(&context, (char *)[data bytes] + bytesHashedNum, updateSize); + bytesHashedNum += updateSize; + } + CC_MD5_Final(bs, &context); + + return [[NSData alloc] initWithBytes:bs length:16]; +} + +BOOL lv_isLuaObjectHaveProperty(lua_State* L, int idx, const char* key){ + if (lua_type(L, idx) == LUA_TTABLE ) { + lua_checkstack(L, 8); + lua_pushvalue(L, idx); + lua_getfield(L, -1, key); + BOOL ret = lua_type(L, -1)!=LUA_TNIL; + lua_pop(L, 2); + return ret; + } + return NO; +} + +static id luaObjBox(lua_State* L, int idx){ + LVLuaObjBox* box = [[LVLuaObjBox alloc] init:L stackID:idx]; + return box; +} + +id lv_luaValueToNativeObject(lua_State* L, int idx){ + int type = lua_type(L, idx); + switch ( type ) { + case LUA_TNIL: { + return nil; + } + case LUA_TUSERDATA: { + LVUserDataInfo* user = (LVUserDataInfo*)lua_touserdata(L, idx); + id obj = (__bridge id)(user->object); + if( [obj respondsToSelector:@selector(lv_nativeObject)] ){ + return [obj lv_nativeObject]; + } + LVError(@"lv_luaValueToNativeObject.1"); + return obj; + } + case LUA_TLIGHTUSERDATA:{ + LVPointerValueBox* box = [[LVPointerValueBox alloc] init]; + box.pointer = lua_touserdata(L, idx); + return box; + } + case LUA_TBOOLEAN: { + return [[NSNumber alloc] initWithBool:lua_toboolean(L, idx)]; + } + case LUA_TNUMBER: { + return @( lua_tonumber(L, idx) ); + } + case LUA_TSTRING: { + return lv_paramString(L, idx); + } + case LUA_TTABLE: { + if ( lv_isLuaObjectHaveProperty(L, idx, "__obj") ) { + return luaObjBox(L, idx); + } else { + return lv_luaTableToDictionary(L, idx); + } + } + case LUA_TFUNCTION: { + return [[LVBlock alloc] initWith:L statckID:idx]; + } + default: { + LVError(@"lv_luaObjectToNativeObject.2"); + return nil; + } + } +} + + + +void lv_pushNativeObject(lua_State* L, id value){ + lua_checkstack(L, 4); + if( [value isKindOfClass:[NSString class]] ) { + NSString* s = value; + lua_pushstring(L, s.UTF8String); + return; + } else if( [value isKindOfClass:[NSDictionary class]] ) { + NSDictionary* dictionary = value; + lua_newtable(L); + for (NSString *key in dictionary) { + NSString* value = dictionary[key]; + lua_checkstack(L, 4); + lua_pushstring(L, key.UTF8String); + lv_pushNativeObject(L,value); + lua_settable(L, -3); + } + return; + } else if( [value isKindOfClass:[NSArray class]] ) { + NSArray* array = value; + lua_newtable(L); + for (int i=0; iobject = CFBridgingRetain(nativeObjBox); + nativeObjBox.lv_userData = userData; + luaL_getmetatable(L, META_TABLE_NativeObject ); + lua_setmetatable(L, -2); +} + +// 获取参数-》字符串类型 +NSString* lv_paramString(lua_State* L, int idx ){ + if( lua_gettop(L)>=ABS(idx) && lua_type(L, idx) == LUA_TSTRING ) { + size_t n = 0; + const char* chars = luaL_checklstring(L, idx, &n ); + NSString* s = @""; + if( chars && n>0 ){ + s = [NSString stringWithUTF8String:chars]; + } + return s; + } + return nil; +} + ++(BOOL) ios8{ + static BOOL yes = NO; + static BOOL inited = NO; + if( !inited ) { + inited = YES; + yes = ([[[UIDevice currentDevice] systemVersion] compare:@"8.0"] != NSOrderedAscending); + } + return yes; +} + +void lv_pushUDataRef(lua_State* L, int key) { + // -1:userdata + if( lua_gettop(L)>=1 && lua_type(L, -1)==LUA_TUSERDATA ) { + lua_checkstack(L, 2); + + if( lv_getUDataLuatable(L, -1) ) { + lua_remove(L, -2); + } + if( lua_type(L, -1)==LUA_TTABLE ) { + lua_pushnumber(L, key); + lua_gettable(L, -2); + lua_remove(L, -2); + } else { + LVError( @"lv_pushUDataRef.1" ); + } + } else { + LVError( @"lv_pushUDataRef.2" ); + } +} + +void lv_udataRef(lua_State* L, int key ){ + //-2: userdata -1: value + if( lua_gettop(L)>=2 && lua_type(L, -2)==LUA_TUSERDATA ) { + lua_checkstack(L, 8); + + lv_getUDataLuatable(L, -2);//table + if( lua_type(L, -1)==LUA_TTABLE ) { + lua_pushnumber(L, key);// key + lua_pushvalue(L, -3);//value + lua_settable(L, -3); + lua_pop(L, 2); + } else { + LVError( @"lv_udataRef" ); + } + } +} + +void lv_udataUnref(lua_State* L, int key) { + // -1:userdata + if( lua_gettop(L)>=1 && lua_type(L, -1)==LUA_TUSERDATA ) { + lua_checkstack(L, 8); + + lv_getUDataLuatable(L, -1); + if( lua_type(L, -1)==LUA_TTABLE ) { + lua_pushnumber(L, key); + lua_pushnil(L); + lua_settable(L, -3); + lua_pop(L, 1); + } else { + LVError( @"lv_udataUnref" ); + } + } +} + +static int lv_setUDataLuatable (lua_State *L, int index) { + if( lua_type(L, index)==LUA_TUSERDATA ){ + lua_setfenv(L, index); + return 1; + } + return 0; +} + +int lv_getUDataLuatable (lua_State *L, int index) { + if( lua_type(L, index)==LUA_TUSERDATA ){ + lua_getfenv(L, index); + return 1; + } + return 0; +} + +int lv_createUDataLuatable (lua_State *L, int index){ + lua_checkstack(L, 8); + lua_pushvalue(L, index); + lua_createtable(L, 8, 0); + lv_setUDataLuatable(L, -2); + lua_pop(L, 1); + return 1; +} + +void lv_luaTableSetWeakWindow(lua_State* L, UIView* cell){ + lua_pushstring(L, "window"); + + NEW_USERDATA(userData, View); + userData->object = CFBridgingRetain(cell); + + luaL_getmetatable(L, META_TABLE_UIView ); + lua_setmetatable(L, -2); + + lua_settable(L, -3); +} + +void lv_luaTableRemoveKeys(lua_State* L, const char** keys){ + if ( lua_type(L, -1)== LUA_TTABLE ) { + for ( int i=0; ;i++ ){ + const char* key = keys[i]; + if( key ) { + lua_pushnil(L); + lua_setfield(L, -2, key); + } else { + break; + } + } + } +} + + +int lv_callbackFunction(lua_State* L, const char* functionName){ + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + if ( lua_gettop(L)>=2 && lua_type(L, 2)==LUA_TFUNCTION ) { + lua_pushvalue(L, 1); + lv_pushUDataRef(L, USERDATA_KEY_DELEGATE); + if( lua_type(L, -1)==LUA_TNIL ) { + lua_createtable(L, 0, 0); + lv_udataRef(L, USERDATA_KEY_DELEGATE); + } + lua_pushstring(L, functionName); + lua_pushvalue(L, 2); + lua_settable(L, -3); + return 0; + } else { + lv_pushUDataRef(L, USERDATA_KEY_DELEGATE); + lua_pushstring(L, functionName); + lua_gettable(L, -2); + return 1; + } + } + return 0; +} + +BOOL lv_objcEqual(id obj1, id obj2) { + return obj1 == obj2 || [obj1 isEqual:obj2]; +} + ++ (UIFont *)fontWithName:(NSString *)fontName size:(CGFloat)fontSize bundle:(LVBundle*)bundle{ + UIFont* font = [UIFont fontWithName:fontName size:fontSize]; + if( font == nil ) { + [LVUtil loadFont:fontName package:bundle]; + font = [UIFont fontWithName:fontName size:fontSize]; + } + return font; +} + ++(int) loadFont:(NSString*) fileName package:(LVBundle*)bundle{ + int ret = 0; + if( [fileName.lowercaseString hasSuffix:@".ttf"]==NO ) { + fileName = [NSString stringWithFormat:@"%@.ttf",fileName]; + } + NSData *inData = [bundle resourceWithName:fileName];/* your font-file data */; + CFErrorRef error; + CGDataProviderRef provider = CGDataProviderCreateWithCFData((CFDataRef)inData); + CGFontRef font = CGFontCreateWithDataProvider(provider); + if (! CTFontManagerRegisterGraphicsFont(font, &error)) { + CFStringRef errorDescription = CFErrorCopyDescription(error); + NSLog(@"Failed to load font: %@", errorDescription); + LVReleaseAndNull(errorDescription); + ret = -1; + } + LVReleaseAndNull(font); + LVReleaseAndNull(provider); + return ret; +} + + ++(void) reg:(lua_State*)L clas:(id) c cfunc:(lua_CFunction) cfunc globalName:(NSString*)globalName defaultName:(NSString*) defaultName{ + if( defaultName || globalName ) { + lua_checkstack(L, 12); + NSString* className = NSStringFromClass(c); + lua_pushstring(L, className.UTF8String); + lua_pushcclosure(L, cfunc, 1); + + lua_setglobal(L, globalName ? globalName.UTF8String : defaultName.UTF8String ); + } +} + ++(Class) upvalueClass:(lua_State*)L defaultClass:(Class) defaultClass{ + const char* classNameChars = lua_tostring(L, lua_upvalueindex(1)); + NSMutableString* className = [NSMutableString stringWithFormat:@"%s",classNameChars]; + Class c = NSClassFromString(className); + if( c == nil ) { + c = defaultClass; + } + return c; +} + ++(void) defineGlobal:(NSString*)globalName value:(id) value L:(lua_State*)L { + if( globalName && value ) { + lua_checkstack(L, 12); + lv_pushNativeObject(L, value); + lua_setglobal(L, globalName.UTF8String); + } else { + LVError(@"define Global Value"); + } +} + +void lv_defineGlobalFunc(const char* globalName, lua_CFunction func, lua_State* L) { + if( globalName && func ) { + lua_checkstack(L, 12); + lua_pushcfunction(L, func); + lua_setglobal(L, globalName); + } else { + LVError(@"define Global Function"); + } +} + +void lv_addSubview(LuaViewCore* lv, UIView* superview, UIView* subview){ + [subview removeFromSuperview]; + [subview.layer removeFromSuperlayer]; + if( lv.closeLayerMode + || [superview isKindOfClass:[UIScrollView class]] + || [subview isKindOfClass:[UIScrollView class]] ) { + [superview addSubview:subview]; + } else { + [superview.layer addSublayer:subview.layer]; + } +} + + +static id objectForKey(NSDictionary* dic, id key, Class clazz){ + id obj = [dic objectForKey:key]; + if ([obj isKindOfClass:clazz]) { + return obj; + } + return nil; +} + +NSString* safe_stringForKey(NSDictionary*dic, id key) { + NSString *obj = objectForKey(dic, key, [NSString class] ); + return obj; +} + +NSDictionary * safe_dictionaryForKey(NSDictionary* dic, id key) { + NSDictionary *obj = objectForKey( dic, key, [NSDictionary class] ); + return obj; +} + +NSDate * safe_dateForKey(NSDictionary* dic, id key ){ + NSDate *obj = objectForKey(dic, key, [NSDate class] ); + return obj; +} + + + ++ (NSTimer *) scheduledTimerWithTimeInterval:(NSTimeInterval)inTimeInterval + block:(void (^)(NSTimer *timer))block + repeats:(BOOL)inRepeats { + NSParameterAssert(block != nil); + return [NSTimer scheduledTimerWithTimeInterval:inTimeInterval + target:self + selector:@selector(lv_executeBlockFromTimer:) + userInfo:[block copy] + repeats:inRepeats]; +} + ++ (void)lv_executeBlockFromTimer:(NSTimer *)aTimer { + void (^block)(NSTimer *) = [aTimer userInfo]; + if (block) + block(aTimer); +} + ++ (NSString*) luaTrace:(lua_State*) L{ + // 打印lua调用栈开始 + lua_getglobal(L, "debug"); + lua_getfield(L, -1, "traceback"); + int iError = lua_pcall( L,//VMachine + 0,//Argument Count + 1,//Return Value Count + 0); + const char* s = lua_tostring(L, -1); + NSString* stack = [NSString stringWithFormat:@"%s",s]; + NSLog(@"err:%d \n %@", iError, stack); + return stack; +} + + +void LVLog( NSString* format, ... ){ +#ifdef DEBUG + va_list params; //定义一个指向个数可变的参数列表指针; + va_start(params,format);//va_start 得到第一个可变参数地址, + NSString* s = [[NSString alloc] initWithFormat:format arguments:params]; + NSLog(@"[LuaView]%@", s); + va_end(params); +#endif +} + +void LVError( NSString* format, ... ){ +#ifdef DEBUG + va_list params; //定义一个指向个数可变的参数列表指针; + va_start(params,format);//va_start 得到第一个可变参数地址, + NSString* s = [[NSString alloc] initWithFormat:format arguments:params]; + NSLog(@"[LuaView][error]%@", s); + va_end(params); +#endif +} + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVWebView.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVWebView.h new file mode 100644 index 00000000..f4a02780 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVWebView.h @@ -0,0 +1,43 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" +#import "LView.h" + +@interface LVWebView : UIView + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; +@property(nonatomic,assign) NSUInteger lv_align; +@property(nonatomic,strong) CAShapeLayer* lv_shapeLayer; + +-(id) init:(lua_State*) l; + + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName; + +//-------------------------------------- +-(void) createWebView; +-(BOOL) canGoBack; +-(void) goBack; +-(BOOL) canGoForward; +-(void) goForward; +-(void) reload; +-(void) stopLoading; +-(BOOL) isLoading; +-(NSString*) title; +-(void) loadUrl:(NSString*) url; +-(NSString*) url; + +// 开启下拉刷新(是、否) +-(void) setPullRefreshEnable:(BOOL) t; +// 返回下拉刷新是否开启 +-(BOOL) pullRefreshEnable; + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVWebView.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVWebView.m new file mode 100644 index 00000000..fd2660ca --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/LVWebView.m @@ -0,0 +1,346 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "LVWebView.h" +#import "LVBaseView.h" +#import "NSObject+LuaView.h" + +@interface LVWebView () +@property(nonatomic,strong) UIWebView* webView; +@end + +@implementation LVWebView + + +-(id) init:(lua_State*) l{ + self = [super init]; + if( self ){ + self.lv_luaviewCore = LV_LUASTATE_VIEW(l); + self.contentMode = UIViewContentModeScaleAspectFill; + self.backgroundColor = [UIColor clearColor]; + self.clipsToBounds = YES; + [self createWebView]; + } + return self; +} + +- (void)webViewDidStartLoad:(UIWebView *)webView{ + lua_State* L = self.lv_luaviewCore.l; + if( L && self.lv_userData ){ + lua_settop(L, 0); + [self lv_callLuaByKey1:@STR_onPageStarted]; + } +} + +- (void)webViewDidFinishLoad:(UIWebView *)webView{ + lua_State* L = self.lv_luaviewCore.l; + if( L && self.lv_userData ){ + lua_settop(L, 0); + [self lv_callLuaByKey1:@STR_onPageFinished]; + } +} + +- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{ + lua_State* L = self.lv_luaviewCore.l; + if( L && self.lv_userData ){ + lua_settop(L, 0); + NSInteger errorCode = error.code; + NSString* errorInfo = [NSString stringWithFormat:@"%@",error]; + NSString* url = webView.request.URL.absoluteString; + lua_pushnumber(L, errorCode); + lua_pushstring(L, errorInfo.UTF8String); + lua_pushstring(L, url.UTF8String); + [self lv_callLuaByKey1:@STR_onReceivedError key2:nil argN:3]; + } +} + +// 创建webView +-(void) createWebView{ + self.webView = [[UIWebView alloc] init]; + self.webView.delegate = self; + [self addSubview:self.webView]; +} + +-(BOOL) canGoBack{ + return self.webView.canGoBack; +} + +-(void) goBack{ + [self.webView goBack]; +} + +-(BOOL) canGoForward{ + return self.webView.canGoForward; +} + +-(void) goForward{ + [self.webView goForward]; +} + +-(void) reload{ + [self.webView reload]; +} + +-(void) stopLoading{ + [self.webView stopLoading]; +} + +-(BOOL) isLoading{ + return [self.webView isLoading]; +} + +-(NSString*) title{ + NSString *theTitle=[self.webView stringByEvaluatingJavaScriptFromString:@"document.title"]; + return theTitle; +} + +-(void) loadUrl:(NSString*) url{ + if( url ) { + NSURL * nsurl = [[NSURL alloc] initWithString:url]; + [self.webView loadRequest:[NSURLRequest requestWithURL:nsurl]]; + } +} + +-(NSString*) url{ + return self.webView.request.URL.absoluteString; +} + +-(void) setPullRefreshEnable:(BOOL) t{ +} + +-(BOOL) pullRefreshEnable{ + return NO; +} + +-(void) layoutSubviews{ + [super layoutSubviews]; + self.webView.frame = self.bounds; +} + +-(void) dealloc{ + LVUserDataInfo* userData = self.lv_userData; + if( userData ){ + userData->object = NULL; + } +} + +#pragma -mark webView +static int lvNewWebView(lua_State *L) { + Class c = [LVUtil upvalueClass:L defaultClass:[LVWebView class]]; + + NSString* url = lv_paramString(L, 1); + + LVWebView* webView = [[c alloc] init:L]; + [webView loadUrl:url]; + { + NEW_USERDATA(userData, View); + userData->object = CFBridgingRetain(webView); + webView.lv_userData = userData; + + luaL_getmetatable(L, META_TABLE_UIWebView ); + lua_setmetatable(L, -2); + } + LuaViewCore* view = LV_LUASTATE_VIEW(L); + if( view ){ + [view containerAddSubview:webView]; + } + return 1; /* new userdatum is already on the stack */ +} + +static int canGoBack (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVWebView* webView = (__bridge LVWebView *)(user->object); + if ( [webView isKindOfClass:[LVWebView class]] ) { + BOOL ret = [webView canGoBack]; + lua_pushboolean(L, ret); + return 1; + } + } + lua_pushboolean(L, 0); + return 1; +} + +static int goBack (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVWebView* webView = (__bridge LVWebView *)(user->object); + if ( [webView isKindOfClass:[LVWebView class]] ) { + [webView goBack]; + return 0; + } + } + return 0; +} + +static int canGoForward (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVWebView* webView = (__bridge LVWebView *)(user->object); + if ( [webView isKindOfClass:[LVWebView class]] ) { + BOOL ret = [webView canGoForward]; + lua_pushboolean(L, ret); + return 1; + } + } + lua_pushboolean(L, 0); + return 1; +} + +static int goForward (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVWebView* webView = (__bridge LVWebView *)(user->object); + if ( [webView isKindOfClass:[LVWebView class]] ) { + [webView goForward]; + return 0; + } + } + return 0; +} + +static int reload (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVWebView* webView = (__bridge LVWebView *)(user->object); + if ( [webView isKindOfClass:[LVWebView class]] ) { + [webView reload]; + return 0; + } + } + return 0; +} + +static int stopLoading (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVWebView* webView = (__bridge LVWebView *)(user->object); + if ( [webView isKindOfClass:[LVWebView class]] ) { + [webView stopLoading]; + return 0; + } + } + return 0; +} + +static int isLoading (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVWebView* webView = (__bridge LVWebView *)(user->object); + if ( [webView isKindOfClass:[LVWebView class]] ) { + BOOL ret = [webView isLoading]; + lua_pushboolean(L, ret); + return 1; + } + } + lua_pushboolean(L, 0); + return 1; +} + +static int title (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVWebView* webView = (__bridge LVWebView *)(user->object); + if ( [webView isKindOfClass:[LVWebView class]] ) { + NSString* title = [webView title]; + lua_pushstring(L, title.UTF8String); + return 1; + } + } + return 0; +} + +static int loadUrl (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVWebView* webView = (__bridge LVWebView *)(user->object); + if ( [webView isKindOfClass:[LVWebView class]] ) { + if ( lua_type(L, 2)==LUA_TSTRING ) { + NSString* url = lv_paramString(L, 2);// 2 + [webView loadUrl:url]; + } else if ( lua_type(L, 2)==LUA_TUSERDATA ) { + } else { + } + } + } + return 0; +} + +static int url (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ){ + LVWebView* webView = (__bridge LVWebView *)(user->object); + if ( [webView isKindOfClass:[LVWebView class]] ) { + NSString* s = [webView url]; + lua_pushstring(L, s.UTF8String); + return 1; + } + } + return 0; +} + +static int pullRefreshEnable (lua_State *L) { + LVUserDataInfo * user = (LVUserDataInfo *)lua_touserdata(L, 1); + if( user ) { + LVWebView* webView = (__bridge LVWebView *)(user->object); + if ( [webView isKindOfClass:[LVWebView class]] ) { + if( lua_gettop(L)>=2 ){ + BOOL yes = lua_toboolean(L, 2); + [webView setPullRefreshEnable:yes]; + return 0; + } else { + BOOL ret = [webView pullRefreshEnable]; + lua_pushboolean(L, ret); + return 1; + } + } + } + return 0; +} + +static int callback (lua_State *L) { + return lv_setCallbackByKey(L, STR_CALLBACK, NO); +} + + ++(int) lvClassDefine:(lua_State *)L globalName:(NSString*) globalName{ + [LVUtil reg:L clas:self cfunc:lvNewWebView globalName:globalName defaultName:@"WebView"]; + + const struct luaL_Reg memberFunctions [] = { + {"canGoBack", canGoBack}, + {"goBack", goBack}, + + {"canGoForward", canGoForward}, + {"goForward", goForward}, + + {"reload", reload}, + {"stopLoading", stopLoading}, + {"isLoading", isLoading}, + + {"title", title}, + {"loadUrl", loadUrl}, + {"url", url}, + + {"pullRefreshEnable",pullRefreshEnable}, + + {"callback", callback}, + {NULL, NULL} + }; + + lv_createClassMetaTable(L, META_TABLE_UIWebView); + + luaL_openlib(L, NULL, [LVBaseView baseMemberFunctions], 0); + luaL_openlib(L, NULL, memberFunctions, 0); + + const char* keys[] = { "addView", NULL};// 移除多余API + lv_luaTableRemoveKeys(L, keys ); + return 1; +} + + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/NSObject+LuaView.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/NSObject+LuaView.h new file mode 100644 index 00000000..a83ddc29 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/NSObject+LuaView.h @@ -0,0 +1,24 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ +#import +#import "LVHeads.h" + + +@interface NSObject(NSObjectLuaView) + +@property(nonatomic,weak) LuaViewCore* lv_luaviewCore; +@property(nonatomic,assign) LVUserDataInfo* lv_userData; +- (id) lv_nativeObject; + +- (void) lv_callLuaByKey1:(NSString*) key1; +- (void) lv_callLuaByKey1:(NSString*) key1 key2:(NSString*) key2 argN:(int) argN; +-(NSString*) lv_callLua:(NSString*) functionName args:(NSArray*) args; + +- (void) lv_buttonCallBack; + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/NSObject+LuaView.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/NSObject+LuaView.m new file mode 100644 index 00000000..59c01a15 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/NSObject+LuaView.m @@ -0,0 +1,84 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "NSObject+LuaView.h" +#import "LuaViewCore.h" + +@implementation NSObject(NSObjectLuaView) + +- (LuaViewCore*) lv_luaviewCore{ + return nil; +} + +- (void) setLv_luaviewCore:(LuaViewCore *)lv_luaviewCore{ +} + +- (LVUserDataInfo*)lv_userData{ + return nil; +} + +- (void) setLv_userData:(LVUserDataInfo *)userData{ +} + +- (void) lv_callLuaByKey1:(NSString*) key1{ + [self lv_callLuaByKey1:key1 key2:nil argN:0]; +} + +- (void) lv_callLuaByKey1:(NSString*) key1 key2:(NSString*) key2 argN:(int)argN{ + lua_State* l = self.lv_luaviewCore.l; + if( l && self.lv_userData && key1){ + lua_checkstack32(l); + lv_pushUserdata(l, self.lv_userData); + lv_pushUDataRef(l, USERDATA_KEY_DELEGATE); + if( lua_type(l, -1) == LUA_TTABLE ) { + lua_getfield(l, -1, STR_CALLBACK); + if( lua_type(l, -1)==LUA_TNIL ) { + lua_remove(l, -1); + } else { + lua_remove(l, -2); + } + } + [LVUtil call:l key1:key1.UTF8String key2:key2.UTF8String key3:NULL nargs:argN nrets:0 retType:LUA_TNONE]; + } +} + +-(NSString*) lv_callLua:(NSString*) functionName args:(NSArray*) args{ + lua_State* L = self.lv_luaviewCore.l; + if( L ){ + lua_checkstack(L, (int)args.count*2 + 2); + + for( int i=0; i +#import "LVRefreshConst.h" + +@class LVRefreshHeader; + +@interface UIScrollView (LVRefresh) +/** 下拉刷新控件 */ +@property (strong, nonatomic) LVRefreshHeader * lv_refresh_header; + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/UIScrollView+LVRefresh.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/UIScrollView+LVRefresh.m new file mode 100644 index 00000000..ba9169e5 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/UIScrollView+LVRefresh.m @@ -0,0 +1,34 @@ + +#import "UIScrollView+LVRefresh.h" +#import "LVRefreshHeader.h" +#import + + + +@implementation UIScrollView (LVRefresh) + +#pragma mark - header +static const char LVRefreshHeaderKey = '\0'; +- (void)setLv_refresh_header:(LVRefreshHeader *)header +{ + if (header != self.lv_refresh_header) { + // 删除旧的,添加新的 + [self.lv_refresh_header removeFromSuperview]; + [self insertSubview:header atIndex:0]; + + // 存储新的 + [self willChangeValueForKey:@"lv_refresh_header"]; // KVO + objc_setAssociatedObject(self, &LVRefreshHeaderKey, + header, OBJC_ASSOCIATION_ASSIGN); + [self didChangeValueForKey:@"lv_refresh_header"]; // KVO + } +} + +- (LVRefreshHeader *)lv_refresh_header +{ + return objc_getAssociatedObject(self, &LVRefreshHeaderKey); +} + + +@end + diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/UIScrollView+LuaView.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/UIScrollView+LuaView.h new file mode 100644 index 00000000..a5100279 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/UIScrollView+LuaView.h @@ -0,0 +1,41 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" +#import "UIView+LuaView.h" + + +@interface UIScrollView (UIScrollViewLuaView) + + +// 下拉刷新组件 需要重载的API +- (void) lv_initRefreshHeader;// 开启下拉刷新功能 +- (void) lv_hiddenRefreshHeader:(BOOL) hidden; +- (void) lv_beginRefreshing;// 进入刷新状态 +- (void) lv_endRefreshing;// 结束刷新状态 +- (BOOL) lv_isRefreshing;// 是否正在刷新 + +// 加载更多组件 需要重载的API +- (void) lv_initRefreshFooter;// 开启上拉加载更多功能 +- (void) lv_hiddenRefreshFooter:(BOOL) hidden; +- (void) lv_noticeNoMoreData;// 提示没有更多的数据 +- (void) lv_resetNoMoreData;// 重置没有更多的数据(消除没有更多数据的状态) + +/* + * 回调脚本开始下拉刷新 + */ +- (void) lv_refreshHeaderToRefresh; + +/* + * 回调脚本开始加载更多 + */ +- (void) lv_refreshFooterToLoadMore; + + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/UIScrollView+LuaView.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/UIScrollView+LuaView.m new file mode 100644 index 00000000..8c85c9c8 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/UIScrollView+LuaView.m @@ -0,0 +1,57 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "UIScrollView+LuaView.h" +#import "LuaViewCore.h" +#import "NSObject+LuaView.h" + + +@implementation UIScrollView (UIScrollViewLuaView) + + +// 下拉刷新 +-(void) lv_initRefreshHeader{// 初始化下拉刷新功能 +} + +- (void) lv_hiddenRefreshHeader:(BOOL) hidden{ +} + +- (void) lv_beginRefreshing{// 进入刷新状态 +} + +- (void) lv_endRefreshing{// 结束刷新状态 +} + +- (BOOL) lv_isRefreshing{// 是否正在刷新 + return NO; +} + +// 加载更多 +- (void) lv_initRefreshFooter{// 初始化上拉加载更多功能 +} +- (void) lv_hiddenRefreshFooter:(BOOL) hidden{ +} + +- (void) lv_noticeNoMoreData{// 提示没有更多的数据 +} + +- (void) lv_resetNoMoreData{// 重置没有更多的数据(消除没有更多数据的状态) +} + +- (void) lv_refreshHeaderToRefresh{ + // 开始下拉刷新调用 + [self lv_callLuaByKey1:@"PullDown"]; +} + +- (void) lv_refreshFooterToLoadMore{ + // 开始上拉刷新调用 + [self lv_callLuaByKey1:@"PullUpRefresh"]; +} + + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/UIView+LuaView.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/UIView+LuaView.h new file mode 100644 index 00000000..c353cda2 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/UIView+LuaView.h @@ -0,0 +1,37 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import +#import "LVHeads.h" + +@interface UIView(UIViewLuaView) + + + +@property(nonatomic,assign) NSUInteger lv_align; +@property(nonatomic,assign) BOOL lv_isCallbackAddClickGesture;// 设置Callback时需要注册手势回调,才设置成true + +-(void) lv_callbackAddClickGesture;// 回调添加 + +- (void) lv_alignSubviews; + +- (void) lv_alignSelfWithSuperRect:(CGRect) rect; + +-(id) lv_getNativeView; + +// shapelayer +@property(nonatomic,strong) CAShapeLayer* lv_shapeLayer; +-(CALayer*) lv_layer; +-(void) lv_createShapelayer:(NSArray*) arr; + +-(void) lv_effectParallax:(CGFloat)dx dy:(CGFloat)dy; +-(void) lv_effectClick:(NSInteger)color alpha:(CGFloat)alpha; + +@property(nonatomic,assign) BOOL lv_canvas; + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/UIView+LuaView.m b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/UIView+LuaView.m new file mode 100644 index 00000000..6424f266 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvsdk/UIView+LuaView.m @@ -0,0 +1,127 @@ +/** +  * Created by LuaView. +  * Copyright (c) 2017, Alibaba Group. All rights reserved. +  * +  * This source code is licensed under the MIT. +  * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. +  */ + +#import "UIView+LuaView.h" +#import "LuaViewCore.h" +#import "LVHeads.h" +#import "NSObject+LuaView.h" + +@implementation UIView (UIViewLuaView) + +-(BOOL) lv_isCallbackAddClickGesture{ + return NO; +} +-(void) setLv_isCallbackAddClickGesture:(BOOL)lv_isCallbackAddClickGesture{ +} + +-(void) lv_callbackAddClickGesture { + if( self.lv_isCallbackAddClickGesture ){ + self.lv_isCallbackAddClickGesture = NO; + UITapGestureRecognizer* gesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(lv_buttonCallBack)]; + self.userInteractionEnabled = YES; + [self addGestureRecognizer:gesture]; + } +} + +// align + +-(NSUInteger) lv_align{ + return 0; +} + +-(void) setLv_align:(NSUInteger)lv_align{ +} + +- (void) lv_alignSubviews { + CGRect rect = self.frame; + NSArray* subviews = [self subviews]; + for( UIView* view in subviews){ + [view lv_alignSelfWithSuperRect:rect]; + } +} + +- (void) lv_alignSelfWithSuperRect:(CGRect) rect{ + NSUInteger ali = self.lv_align; + if( ali ){ + CGRect r0 = [self frame]; + CGRect r = r0; + if( ali&LV_ALIGN_LEFT ) { + r.origin.x = 0; + } else if( ali&LV_ALIGN_H_CENTER ) { + r.origin.x = (rect.size.width-r.size.width)/2; + } else if( ali&LV_ALIGN_RIGHT ) { + r.origin.x = rect.size.width-r.size.width; + } + if( ali&LV_ALIGN_TOP ) { + r.origin.y = 0; + } else if( ali&LV_ALIGN_V_CENTER ) { + r.origin.y = (rect.size.height-r.size.height)/2; + } else if( ali&LV_ALIGN_BOTTOM ) { + r.origin.y = (rect.size.height-r.size.height); + } + if( !CGRectEqualToRect(r0, r) ) { + self.frame = r; + } + } +} + +-(id) lv_getNativeView{ + return self; +} + +-(CAShapeLayer*) lv_shapeLayer{ + return nil; +} + +-(void) setLv_shapeLayer:(CAShapeLayer *)lv_shapeLayer{ +} + +-(CALayer*) lv_layer{ + if( self.lv_shapeLayer ){ + return self.lv_shapeLayer; + } + return self.layer; +} + +-(void) lv_createShapelayer:(NSArray*)arr{ + [self.lv_shapeLayer removeFromSuperlayer]; + self.lv_shapeLayer = nil; + + CAShapeLayer *borderLayer = [CAShapeLayer layer]; + borderLayer.bounds = self.bounds; + borderLayer.position = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds)); + borderLayer.lineWidth = self.layer.borderWidth; + + borderLayer.fillColor = [UIColor clearColor].CGColor; + borderLayer.strokeColor = self.layer.borderColor; + borderLayer.path = [UIBezierPath bezierPathWithRoundedRect:borderLayer.bounds cornerRadius:self.layer.cornerRadius].CGPath; + borderLayer.lineDashPattern = arr; + self.lv_shapeLayer = borderLayer; + + if( self.lv_shapeLayer ) { + self.layer.borderColor = [UIColor clearColor].CGColor; + [self.layer addSublayer:self.lv_shapeLayer]; + } +} + +-(void) lv_effectParallax:(CGFloat)dx dy:(CGFloat)dy{ + // 视差效果 +} + +-(void) lv_effectClick:(NSInteger)color alpha:(CGFloat)alpha{ + // 点击特效 +} + +-(BOOL) lv_canvas{ + return NO; +} + +-(void) setLv_canvas:(BOOL)lv_canvas{ +} + +@end diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lapi.c b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lapi.c new file mode 100644 index 00000000..5d5145d2 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lapi.c @@ -0,0 +1,1087 @@ +/* +** $Id: lapi.c,v 2.55.1.5 2008/07/04 18:41:18 roberto Exp $ +** Lua API +** See Copyright Notice in lua.h +*/ + + +#include +#include +#include +#include + +#define lapi_c +#define LUA_CORE + +#include "lua.h" + +#include "lapi.h" +#include "ldebug.h" +#include "ldo.h" +#include "lfunc.h" +#include "lgc.h" +#include "lmem.h" +#include "lobject.h" +#include "lstate.h" +#include "lstring.h" +#include "ltable.h" +#include "ltm.h" +#include "lundump.h" +#include "lvm.h" + + + +const char lua_ident[] = + "$Lua: " LUA_RELEASE " " LUA_COPYRIGHT " $\n" + "$Authors: " LUA_AUTHORS " $\n" + "$URL: www.lua.org $\n"; + + + +#define api_checknelems(L, n) api_check(L, (n) <= (L->top - L->base)) + +#define api_checkvalidindex(L, i) api_check(L, (i) != luaO_nilobject) + +#define api_incr_top(L) {api_check(L, L->top < L->ci->top); L->top++;} + + + +static TValue *index2adr (lua_State *L, int idx) { + if (idx > 0) { + TValue *o = L->base + (idx - 1); + api_check(L, idx <= L->ci->top - L->base); + if (o >= L->top) return cast(TValue *, luaO_nilobject); + else return o; + } + else if (idx > LUA_REGISTRYINDEX) { + api_check(L, idx != 0 && -idx <= L->top - L->base); + return L->top + idx; + } + else switch (idx) { /* pseudo-indices */ + case LUA_REGISTRYINDEX: return registry(L); + case LUA_ENVIRONINDEX: { + Closure *func = curr_func(L); + sethvalue(L, &L->env, func->c.env); + return &L->env; + } + case LUA_GLOBALSINDEX: return gt(L); + default: { + Closure *func = curr_func(L); + idx = LUA_GLOBALSINDEX - idx; + return (idx <= func->c.nupvalues) + ? &func->c.upvalue[idx-1] + : cast(TValue *, luaO_nilobject); + } + } +} + + +static Table *getcurrenv (lua_State *L) { + if (L->ci == L->base_ci) /* no enclosing function? */ + return hvalue(gt(L)); /* use global table as environment */ + else { + Closure *func = curr_func(L); + return func->c.env; + } +} + + +void luaA_pushobject (lua_State *L, const TValue *o) { + setobj2s(L, L->top, o); + api_incr_top(L); +} + + +LUA_API int lua_checkstack (lua_State *L, int size) { + int res = 1; + lua_lock(L); + if (size > LUAI_MAXCSTACK || (L->top - L->base + size) > LUAI_MAXCSTACK) + res = 0; /* stack overflow */ + else if (size > 0) { + luaD_checkstack(L, size); + if (L->ci->top < L->top + size) + L->ci->top = L->top + size; + } + lua_unlock(L); + return res; +} + + +LUA_API void lua_xmove (lua_State *from, lua_State *to, int n) { + int i; + if (from == to) return; + lua_lock(to); + api_checknelems(from, n); + api_check(from, G(from) == G(to)); + api_check(from, to->ci->top - to->top >= n); + from->top -= n; + for (i = 0; i < n; i++) { + setobj2s(to, to->top++, from->top + i); + } + lua_unlock(to); +} + + +LUA_API void lua_setlevel (lua_State *from, lua_State *to) { + to->nCcalls = from->nCcalls; +} + + +LUA_API lua_CFunction lua_atpanic (lua_State *L, lua_CFunction panicf) { + lua_CFunction old; + lua_lock(L); + old = G(L)->panic; + G(L)->panic = panicf; + lua_unlock(L); + return old; +} + + +LUA_API lua_State *lua_newthread (lua_State *L) { + lua_State *L1; + lua_lock(L); + luaC_checkGC(L); + L1 = luaE_newthread(L); + setthvalue(L, L->top, L1); + api_incr_top(L); + lua_unlock(L); + luai_userstatethread(L, L1); + return L1; +} + + + +/* +** basic stack manipulation +*/ + + +LUA_API int lua_gettop (lua_State *L) { + return cast_int(L->top - L->base); +} + + +LUA_API void lua_settop (lua_State *L, int idx) { + lua_lock(L); + if (idx >= 0) { + api_check(L, idx <= L->stack_last - L->base); + while (L->top < L->base + idx) + setnilvalue(L->top++); + L->top = L->base + idx; + } + else { + api_check(L, -(idx+1) <= (L->top - L->base)); + L->top += idx+1; /* `subtract' index (index is negative) */ + } + lua_unlock(L); +} + + +LUA_API void lua_remove (lua_State *L, int idx) { + StkId p; + lua_lock(L); + p = index2adr(L, idx); + api_checkvalidindex(L, p); + while (++p < L->top) setobjs2s(L, p-1, p); + L->top--; + lua_unlock(L); +} + + +LUA_API void lua_insert (lua_State *L, int idx) { + StkId p; + StkId q; + lua_lock(L); + p = index2adr(L, idx); + api_checkvalidindex(L, p); + for (q = L->top; q>p; q--) setobjs2s(L, q, q-1); + setobjs2s(L, p, L->top); + lua_unlock(L); +} + + +LUA_API void lua_replace (lua_State *L, int idx) { + StkId o; + lua_lock(L); + /* explicit test for incompatible code */ + if (idx == LUA_ENVIRONINDEX && L->ci == L->base_ci) + luaG_runerror(L, "no calling environment"); + api_checknelems(L, 1); + o = index2adr(L, idx); + api_checkvalidindex(L, o); + if (idx == LUA_ENVIRONINDEX) { + Closure *func = curr_func(L); + api_check(L, ttistable(L->top - 1)); + func->c.env = hvalue(L->top - 1); + luaC_barrier(L, func, L->top - 1); + } + else { + setobj(L, o, L->top - 1); + if (idx < LUA_GLOBALSINDEX) /* function upvalue? */ + luaC_barrier(L, curr_func(L), L->top - 1); + } + L->top--; + lua_unlock(L); +} + + +LUA_API void lua_pushvalue (lua_State *L, int idx) { + lua_lock(L); + setobj2s(L, L->top, index2adr(L, idx)); + api_incr_top(L); + lua_unlock(L); +} + + + +/* +** access functions (stack -> C) +*/ + + +LUA_API int lua_type (lua_State *L, int idx) { + StkId o = index2adr(L, idx); + return (o == luaO_nilobject) ? LUA_TNONE : ttype(o); +} + + +LUA_API const char *lua_typename (lua_State *L, int t) { + UNUSED(L); + return (t == LUA_TNONE) ? "no value" : luaT_typenames[t]; +} + + +LUA_API int lua_iscfunction (lua_State *L, int idx) { + StkId o = index2adr(L, idx); + return iscfunction(o); +} + + +LUA_API int lua_isnumber (lua_State *L, int idx) { + TValue n; + const TValue *o = index2adr(L, idx); + return tonumber(o, &n); +} + + +LUA_API int lua_isstring (lua_State *L, int idx) { + int t = lua_type(L, idx); + return (t == LUA_TSTRING || t == LUA_TNUMBER); +} + + +LUA_API int lua_isuserdata (lua_State *L, int idx) { + const TValue *o = index2adr(L, idx); + return (ttisuserdata(o) || ttislightuserdata(o)); +} + + +LUA_API int lua_rawequal (lua_State *L, int index1, int index2) { + StkId o1 = index2adr(L, index1); + StkId o2 = index2adr(L, index2); + return (o1 == luaO_nilobject || o2 == luaO_nilobject) ? 0 + : luaO_rawequalObj(o1, o2); +} + + +LUA_API int lua_equal (lua_State *L, int index1, int index2) { + StkId o1, o2; + int i; + lua_lock(L); /* may call tag method */ + o1 = index2adr(L, index1); + o2 = index2adr(L, index2); + i = (o1 == luaO_nilobject || o2 == luaO_nilobject) ? 0 : equalobj(L, o1, o2); + lua_unlock(L); + return i; +} + + +LUA_API int lua_lessthan (lua_State *L, int index1, int index2) { + StkId o1, o2; + int i; + lua_lock(L); /* may call tag method */ + o1 = index2adr(L, index1); + o2 = index2adr(L, index2); + i = (o1 == luaO_nilobject || o2 == luaO_nilobject) ? 0 + : luaV_lessthan(L, o1, o2); + lua_unlock(L); + return i; +} + + + +LUA_API lua_Number lua_tonumber (lua_State *L, int idx) { + TValue n; + const TValue *o = index2adr(L, idx); + if (tonumber(o, &n)) + return nvalue(o); + else + return 0; +} + + +LUA_API lua_Integer lua_tointeger (lua_State *L, int idx) { + TValue n; + const TValue *o = index2adr(L, idx); + if (tonumber(o, &n)) { + lua_Integer res; + lua_Number num = nvalue(o); + lua_number2integer(res, num); + return res; + } + else + return 0; +} + + +LUA_API int lua_toboolean (lua_State *L, int idx) { + const TValue *o = index2adr(L, idx); + return !l_isfalse(o); +} + + +LUA_API const char *lua_tolstring (lua_State *L, int idx, size_t *len) { + StkId o = index2adr(L, idx); + if (!ttisstring(o)) { + lua_lock(L); /* `luaV_tostring' may create a new string */ + if (!luaV_tostring(L, o)) { /* conversion failed? */ + if (len != NULL) *len = 0; + lua_unlock(L); + return NULL; + } + luaC_checkGC(L); + o = index2adr(L, idx); /* previous call may reallocate the stack */ + lua_unlock(L); + } + if (len != NULL) *len = tsvalue(o)->len; + return svalue(o); +} + + +LUA_API size_t lua_objlen (lua_State *L, int idx) { + StkId o = index2adr(L, idx); + switch (ttype(o)) { + case LUA_TSTRING: return tsvalue(o)->len; + case LUA_TUSERDATA: return uvalue(o)->len; + case LUA_TTABLE: return luaH_getn(hvalue(o)); + case LUA_TNUMBER: { + size_t l; + lua_lock(L); /* `luaV_tostring' may create a new string */ + l = (luaV_tostring(L, o) ? tsvalue(o)->len : 0); + lua_unlock(L); + return l; + } + default: return 0; + } +} + + +LUA_API lua_CFunction lua_tocfunction (lua_State *L, int idx) { + StkId o = index2adr(L, idx); + return (!iscfunction(o)) ? NULL : clvalue(o)->c.f; +} + + +LUA_API void *lua_touserdata (lua_State *L, int idx) { + StkId o = index2adr(L, idx); + switch (ttype(o)) { + case LUA_TUSERDATA: return (rawuvalue(o) + 1); + case LUA_TLIGHTUSERDATA: return pvalue(o); + default: return NULL; + } +} + + +LUA_API lua_State *lua_tothread (lua_State *L, int idx) { + StkId o = index2adr(L, idx); + return (!ttisthread(o)) ? NULL : thvalue(o); +} + + +LUA_API const void *lua_topointer (lua_State *L, int idx) { + StkId o = index2adr(L, idx); + switch (ttype(o)) { + case LUA_TTABLE: return hvalue(o); + case LUA_TFUNCTION: return clvalue(o); + case LUA_TTHREAD: return thvalue(o); + case LUA_TUSERDATA: + case LUA_TLIGHTUSERDATA: + return lua_touserdata(L, idx); + default: return NULL; + } +} + + + +/* +** push functions (C -> stack) +*/ + + +LUA_API void lua_pushnil (lua_State *L) { + lua_lock(L); + setnilvalue(L->top); + api_incr_top(L); + lua_unlock(L); +} + + +LUA_API void lua_pushnumber (lua_State *L, lua_Number n) { + lua_lock(L); + setnvalue(L->top, n); + api_incr_top(L); + lua_unlock(L); +} + + +LUA_API void lua_pushinteger (lua_State *L, lua_Integer n) { + lua_lock(L); + setnvalue(L->top, cast_num(n)); + api_incr_top(L); + lua_unlock(L); +} + + +LUA_API void lua_pushlstring (lua_State *L, const char *s, size_t len) { + lua_lock(L); + luaC_checkGC(L); + setsvalue2s(L, L->top, luaS_newlstr(L, s, len)); + api_incr_top(L); + lua_unlock(L); +} + + +LUA_API void lua_pushstring (lua_State *L, const char *s) { + if (s == NULL) + lua_pushnil(L); + else + lua_pushlstring(L, s, strlen(s)); +} + + +LUA_API const char *lua_pushvfstring (lua_State *L, const char *fmt, + va_list argp) { + const char *ret; + lua_lock(L); + luaC_checkGC(L); + ret = luaO_pushvfstring(L, fmt, argp); + lua_unlock(L); + return ret; +} + + +LUA_API const char *lua_pushfstring (lua_State *L, const char *fmt, ...) { + const char *ret; + va_list argp; + lua_lock(L); + luaC_checkGC(L); + va_start(argp, fmt); + ret = luaO_pushvfstring(L, fmt, argp); + va_end(argp); + lua_unlock(L); + return ret; +} + + +LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) { + Closure *cl; + lua_lock(L); + luaC_checkGC(L); + api_checknelems(L, n); + cl = luaF_newCclosure(L, n, getcurrenv(L)); + cl->c.f = fn; + L->top -= n; + while (n--) + setobj2n(L, &cl->c.upvalue[n], L->top+n); + setclvalue(L, L->top, cl); + lua_assert(iswhite(obj2gco(cl))); + api_incr_top(L); + lua_unlock(L); +} + + +LUA_API void lua_pushboolean (lua_State *L, int b) { + lua_lock(L); + setbvalue(L->top, (b != 0)); /* ensure that true is 1 */ + api_incr_top(L); + lua_unlock(L); +} + + +LUA_API void lua_pushlightuserdata (lua_State *L, void *p) { + lua_lock(L); + setpvalue(L->top, p); + api_incr_top(L); + lua_unlock(L); +} + + +LUA_API int lua_pushthread (lua_State *L) { + lua_lock(L); + setthvalue(L, L->top, L); + api_incr_top(L); + lua_unlock(L); + return (G(L)->mainthread == L); +} + + + +/* +** get functions (Lua -> stack) +*/ + + +LUA_API void lua_gettable (lua_State *L, int idx) { + StkId t; + lua_lock(L); + t = index2adr(L, idx); + api_checkvalidindex(L, t); + luaV_gettable(L, t, L->top - 1, L->top - 1); + lua_unlock(L); +} + + +LUA_API void lua_getfield (lua_State *L, int idx, const char *k) { + StkId t; + TValue key; + lua_lock(L); + t = index2adr(L, idx); + api_checkvalidindex(L, t); + setsvalue(L, &key, luaS_new(L, k)); + luaV_gettable(L, t, &key, L->top); + api_incr_top(L); + lua_unlock(L); +} + + +LUA_API void lua_rawget (lua_State *L, int idx) { + StkId t; + lua_lock(L); + t = index2adr(L, idx); + api_check(L, ttistable(t)); + setobj2s(L, L->top - 1, luaH_get(hvalue(t), L->top - 1)); + lua_unlock(L); +} + + +LUA_API void lua_rawgeti (lua_State *L, int idx, int n) { + StkId o; + lua_lock(L); + o = index2adr(L, idx); + api_check(L, ttistable(o)); + setobj2s(L, L->top, luaH_getnum(hvalue(o), n)); + api_incr_top(L); + lua_unlock(L); +} + + +LUA_API void lua_createtable (lua_State *L, int narray, int nrec) { + lua_lock(L); + luaC_checkGC(L); + sethvalue(L, L->top, luaH_new(L, narray, nrec)); + api_incr_top(L); + lua_unlock(L); +} + + +LUA_API int lua_getmetatable (lua_State *L, int objindex) { + const TValue *obj; + Table *mt = NULL; + int res; + lua_lock(L); + obj = index2adr(L, objindex); + switch (ttype(obj)) { + case LUA_TTABLE: + mt = hvalue(obj)->metatable; + break; + case LUA_TUSERDATA: + mt = uvalue(obj)->metatable; + break; + default: + mt = G(L)->mt[ttype(obj)]; + break; + } + if (mt == NULL) + res = 0; + else { + sethvalue(L, L->top, mt); + api_incr_top(L); + res = 1; + } + lua_unlock(L); + return res; +} + + +LUA_API void lua_getfenv (lua_State *L, int idx) { + StkId o; + lua_lock(L); + o = index2adr(L, idx); + api_checkvalidindex(L, o); + switch (ttype(o)) { + case LUA_TFUNCTION: + sethvalue(L, L->top, clvalue(o)->c.env); + break; + case LUA_TUSERDATA: + sethvalue(L, L->top, uvalue(o)->env); + break; + case LUA_TTHREAD: + setobj2s(L, L->top, gt(thvalue(o))); + break; + default: + setnilvalue(L->top); + break; + } + api_incr_top(L); + lua_unlock(L); +} + + +/* +** set functions (stack -> Lua) +*/ + + +LUA_API void lua_settable (lua_State *L, int idx) { + StkId t; + lua_lock(L); + api_checknelems(L, 2); + t = index2adr(L, idx); + api_checkvalidindex(L, t); + luaV_settable(L, t, L->top - 2, L->top - 1); + L->top -= 2; /* pop index and value */ + lua_unlock(L); +} + + +LUA_API void lua_setfield (lua_State *L, int idx, const char *k) { + StkId t; + TValue key; + lua_lock(L); + api_checknelems(L, 1); + t = index2adr(L, idx); + api_checkvalidindex(L, t); + setsvalue(L, &key, luaS_new(L, k)); + luaV_settable(L, t, &key, L->top - 1); + L->top--; /* pop value */ + lua_unlock(L); +} + + +LUA_API void lua_rawset (lua_State *L, int idx) { + StkId t; + lua_lock(L); + api_checknelems(L, 2); + t = index2adr(L, idx); + api_check(L, ttistable(t)); + setobj2t(L, luaH_set(L, hvalue(t), L->top-2), L->top-1); + luaC_barriert(L, hvalue(t), L->top-1); + L->top -= 2; + lua_unlock(L); +} + + +LUA_API void lua_rawseti (lua_State *L, int idx, int n) { + StkId o; + lua_lock(L); + api_checknelems(L, 1); + o = index2adr(L, idx); + api_check(L, ttistable(o)); + setobj2t(L, luaH_setnum(L, hvalue(o), n), L->top-1); + luaC_barriert(L, hvalue(o), L->top-1); + L->top--; + lua_unlock(L); +} + + +LUA_API int lua_setmetatable (lua_State *L, int objindex) { + TValue *obj; + Table *mt; + lua_lock(L); + api_checknelems(L, 1); + obj = index2adr(L, objindex); + api_checkvalidindex(L, obj); + if (ttisnil(L->top - 1)) + mt = NULL; + else { + api_check(L, ttistable(L->top - 1)); + mt = hvalue(L->top - 1); + } + switch (ttype(obj)) { + case LUA_TTABLE: { + hvalue(obj)->metatable = mt; + if (mt) + luaC_objbarriert(L, hvalue(obj), mt); + break; + } + case LUA_TUSERDATA: { + uvalue(obj)->metatable = mt; + if (mt) + luaC_objbarrier(L, rawuvalue(obj), mt); + break; + } + default: { + G(L)->mt[ttype(obj)] = mt; + break; + } + } + L->top--; + lua_unlock(L); + return 1; +} + + +LUA_API int lua_setfenv (lua_State *L, int idx) { + StkId o; + int res = 1; + lua_lock(L); + api_checknelems(L, 1); + o = index2adr(L, idx); + api_checkvalidindex(L, o); + api_check(L, ttistable(L->top - 1)); + switch (ttype(o)) { + case LUA_TFUNCTION: + clvalue(o)->c.env = hvalue(L->top - 1); + break; + case LUA_TUSERDATA: + uvalue(o)->env = hvalue(L->top - 1); + break; + case LUA_TTHREAD: + sethvalue(L, gt(thvalue(o)), hvalue(L->top - 1)); + break; + default: + res = 0; + break; + } + if (res) luaC_objbarrier(L, gcvalue(o), hvalue(L->top - 1)); + L->top--; + lua_unlock(L); + return res; +} + + +/* +** `load' and `call' functions (run Lua code) +*/ + + +#define adjustresults(L,nres) \ + { if (nres == LUA_MULTRET && L->top >= L->ci->top) L->ci->top = L->top; } + + +#define checkresults(L,na,nr) \ + api_check(L, (nr) == LUA_MULTRET || (L->ci->top - L->top >= (nr) - (na))) + + +LUA_API void lua_call (lua_State *L, int nargs, int nresults) { + StkId func; + lua_lock(L); + api_checknelems(L, nargs+1); + checkresults(L, nargs, nresults); + func = L->top - (nargs+1); + luaD_call(L, func, nresults); + adjustresults(L, nresults); + lua_unlock(L); +} + + + +/* +** Execute a protected call. +*/ +struct CallS { /* data to `f_call' */ + StkId func; + int nresults; +}; + + +static void f_call (lua_State *L, void *ud) { + struct CallS *c = cast(struct CallS *, ud); + luaD_call(L, c->func, c->nresults); +} + + + +LUA_API int lua_pcall (lua_State *L, int nargs, int nresults, int errfunc) { + struct CallS c; + int status; + ptrdiff_t func; + lua_lock(L); + api_checknelems(L, nargs+1); + checkresults(L, nargs, nresults); + if (errfunc == 0) + func = 0; + else { + StkId o = index2adr(L, errfunc); + api_checkvalidindex(L, o); + func = savestack(L, o); + } + c.func = L->top - (nargs+1); /* function to be called */ + c.nresults = nresults; + status = luaD_pcall(L, f_call, &c, savestack(L, c.func), func); + adjustresults(L, nresults); + lua_unlock(L); + return status; +} + + +/* +** Execute a protected C call. +*/ +struct CCallS { /* data to `f_Ccall' */ + lua_CFunction func; + void *ud; +}; + + +static void f_Ccall (lua_State *L, void *ud) { + struct CCallS *c = cast(struct CCallS *, ud); + Closure *cl; + cl = luaF_newCclosure(L, 0, getcurrenv(L)); + cl->c.f = c->func; + setclvalue(L, L->top, cl); /* push function */ + api_incr_top(L); + setpvalue(L->top, c->ud); /* push only argument */ + api_incr_top(L); + luaD_call(L, L->top - 2, 0); +} + + +LUA_API int lua_cpcall (lua_State *L, lua_CFunction func, void *ud) { + struct CCallS c; + int status; + lua_lock(L); + c.func = func; + c.ud = ud; + status = luaD_pcall(L, f_Ccall, &c, savestack(L, L->top), 0); + lua_unlock(L); + return status; +} + + +LUA_API int lua_load (lua_State *L, lua_Reader reader, void *data, + const char *chunkname) { + ZIO z; + int status; + lua_lock(L); + if (!chunkname) chunkname = "?"; + luaZ_init(L, &z, reader, data); + status = luaD_protectedparser(L, &z, chunkname); + lua_unlock(L); + return status; +} + + +LUA_API int lua_dump (lua_State *L, lua_Writer writer, void *data) { + int status; + TValue *o; + lua_lock(L); + api_checknelems(L, 1); + o = L->top - 1; + if (isLfunction(o)) + status = luaU_dump(L, clvalue(o)->l.p, writer, data, 0); + else + status = 1; + lua_unlock(L); + return status; +} + + +LUA_API int lua_status (lua_State *L) { + return L->status; +} + + +/* +** Garbage-collection function +*/ + +LUA_API int lua_gc (lua_State *L, int what, int data) { + int res = 0; + global_State *g; + lua_lock(L); + g = G(L); + switch (what) { + case LUA_GCSTOP: { + g->GCthreshold = MAX_LUMEM; + break; + } + case LUA_GCRESTART: { + g->GCthreshold = g->totalbytes; + break; + } + case LUA_GCCOLLECT: { + luaC_fullgc(L); + break; + } + case LUA_GCCOUNT: { + /* GC values are expressed in Kbytes: #bytes/2^10 */ + res = cast_int(g->totalbytes >> 10); + break; + } + case LUA_GCCOUNTB: { + res = cast_int(g->totalbytes & 0x3ff); + break; + } + case LUA_GCSTEP: { + lu_mem a = (cast(lu_mem, data) << 10); + if (a <= g->totalbytes) + g->GCthreshold = g->totalbytes - a; + else + g->GCthreshold = 0; + while (g->GCthreshold <= g->totalbytes) { + luaC_step(L); + if (g->gcstate == GCSpause) { /* end of cycle? */ + res = 1; /* signal it */ + break; + } + } + break; + } + case LUA_GCSETPAUSE: { + res = g->gcpause; + g->gcpause = data; + break; + } + case LUA_GCSETSTEPMUL: { + res = g->gcstepmul; + g->gcstepmul = data; + break; + } + default: res = -1; /* invalid option */ + } + lua_unlock(L); + return res; +} + + + +/* +** miscellaneous functions +*/ + + +LUA_API int lua_error (lua_State *L) { + lua_lock(L); + api_checknelems(L, 1); + luaG_errormsg(L); + lua_unlock(L); + return 0; /* to avoid warnings */ +} + + +LUA_API int lua_next (lua_State *L, int idx) { + StkId t; + int more; + lua_lock(L); + t = index2adr(L, idx); + api_check(L, ttistable(t)); + more = luaH_next(L, hvalue(t), L->top - 1); + if (more) { + api_incr_top(L); + } + else /* no more elements */ + L->top -= 1; /* remove key */ + lua_unlock(L); + return more; +} + + +LUA_API void lua_concat (lua_State *L, int n) { + lua_lock(L); + api_checknelems(L, n); + if (n >= 2) { + luaC_checkGC(L); + luaV_concat(L, n, cast_int(L->top - L->base) - 1); + L->top -= (n-1); + } + else if (n == 0) { /* push empty string */ + setsvalue2s(L, L->top, luaS_newlstr(L, "", 0)); + api_incr_top(L); + } + /* else n == 1; nothing to do */ + lua_unlock(L); +} + + +LUA_API lua_Alloc lua_getallocf (lua_State *L, void **ud) { + lua_Alloc f; + lua_lock(L); + if (ud) *ud = G(L)->ud; + f = G(L)->frealloc; + lua_unlock(L); + return f; +} + + +LUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud) { + lua_lock(L); + G(L)->ud = ud; + G(L)->frealloc = f; + lua_unlock(L); +} + + +LUA_API void *lua_newuserdata (lua_State *L, size_t size) { + Udata *u; + lua_lock(L); + luaC_checkGC(L); + u = luaS_newudata(L, size, getcurrenv(L)); + setuvalue(L, L->top, u); + api_incr_top(L); + lua_unlock(L); + return u + 1; +} + + + + +static const char *aux_upvalue (StkId fi, int n, TValue **val) { + Closure *f; + if (!ttisfunction(fi)) return NULL; + f = clvalue(fi); + if (f->c.isC) { + if (!(1 <= n && n <= f->c.nupvalues)) return NULL; + *val = &f->c.upvalue[n-1]; + return ""; + } + else { + Proto *p = f->l.p; + if (!(1 <= n && n <= p->sizeupvalues)) return NULL; + *val = f->l.upvals[n-1]->v; + return getstr(p->upvalues[n-1]); + } +} + + +LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n) { + const char *name; + TValue *val; + lua_lock(L); + name = aux_upvalue(index2adr(L, funcindex), n, &val); + if (name) { + setobj2s(L, L->top, val); + api_incr_top(L); + } + lua_unlock(L); + return name; +} + + +LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n) { + const char *name; + TValue *val; + StkId fi; + lua_lock(L); + fi = index2adr(L, funcindex); + api_checknelems(L, 1); + name = aux_upvalue(fi, n, &val); + if (name) { + L->top--; + setobj(L, val, L->top); + luaC_barrier(L, clvalue(fi), L->top); + } + lua_unlock(L); + return name; +} + diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lapi.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lapi.h new file mode 100644 index 00000000..2c3fab24 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lapi.h @@ -0,0 +1,16 @@ +/* +** $Id: lapi.h,v 2.2.1.1 2007/12/27 13:02:25 roberto Exp $ +** Auxiliary functions from Lua API +** See Copyright Notice in lua.h +*/ + +#ifndef lapi_h +#define lapi_h + + +#include "lobject.h" + + +LUAI_FUNC void luaA_pushobject (lua_State *L, const TValue *o); + +#endif diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lauxlib.c b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lauxlib.c new file mode 100644 index 00000000..10f14e2c --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lauxlib.c @@ -0,0 +1,652 @@ +/* +** $Id: lauxlib.c,v 1.159.1.3 2008/01/21 13:20:51 roberto Exp $ +** Auxiliary functions for building Lua libraries +** See Copyright Notice in lua.h +*/ + + +#include +#include +#include +#include +#include +#include + + +/* This file uses only the official API of Lua. +** Any function declared here could be written as an application function. +*/ + +#define lauxlib_c +#define LUA_LIB + +#include "lua.h" + +#include "lauxlib.h" + + +#define FREELIST_REF 0 /* free list of references */ + + +/* convert a stack index to positive */ +#define abs_index(L, i) ((i) > 0 || (i) <= LUA_REGISTRYINDEX ? (i) : \ + lua_gettop(L) + (i) + 1) + + +/* +** {====================================================== +** Error-report functions +** ======================================================= +*/ + + +LUALIB_API int luaL_argerror (lua_State *L, int narg, const char *extramsg) { + lua_Debug ar; + if (!lua_getstack(L, 0, &ar)) /* no stack frame? */ + return luaL_error(L, "bad argument #%d (%s)", narg, extramsg); + lua_getinfo(L, "n", &ar); + if (strcmp(ar.namewhat, "method") == 0) { + narg--; /* do not count `self' */ + if (narg == 0) /* error is in the self argument itself? */ + return luaL_error(L, "calling " LUA_QS " on bad self (%s)", + ar.name, extramsg); + } + if (ar.name == NULL) + ar.name = "?"; + return luaL_error(L, "bad argument #%d to " LUA_QS " (%s)", + narg, ar.name, extramsg); +} + + +LUALIB_API int luaL_typerror (lua_State *L, int narg, const char *tname) { + const char *msg = lua_pushfstring(L, "%s expected, got %s", + tname, luaL_typename(L, narg)); + return luaL_argerror(L, narg, msg); +} + + +static void tag_error (lua_State *L, int narg, int tag) { + luaL_typerror(L, narg, lua_typename(L, tag)); +} + + +LUALIB_API void luaL_where (lua_State *L, int level) { + lua_Debug ar; + if (lua_getstack(L, level, &ar)) { /* check function at level */ + lua_getinfo(L, "Sl", &ar); /* get info about it */ + if (ar.currentline > 0) { /* is there info? */ + lua_pushfstring(L, "%s:%d: ", ar.short_src, ar.currentline); + return; + } + } + lua_pushliteral(L, ""); /* else, no information available... */ +} + + +LUALIB_API int luaL_error (lua_State *L, const char *fmt, ...) { + va_list argp; + va_start(argp, fmt); + luaL_where(L, 1); + lua_pushvfstring(L, fmt, argp); + va_end(argp); + lua_concat(L, 2); + return lua_error(L); +} + +/* }====================================================== */ + + +LUALIB_API int luaL_checkoption (lua_State *L, int narg, const char *def, + const char *const lst[]) { + const char *name = (def) ? luaL_optstring(L, narg, def) : + luaL_checkstring(L, narg); + int i; + for (i=0; lst[i]; i++) + if (strcmp(lst[i], name) == 0) + return i; + return luaL_argerror(L, narg, + lua_pushfstring(L, "invalid option " LUA_QS, name)); +} + + +LUALIB_API int luaL_newmetatable (lua_State *L, const char *tname) { + lua_getfield(L, LUA_REGISTRYINDEX, tname); /* get registry.name */ + if (!lua_isnil(L, -1)) /* name already in use? */ + return 0; /* leave previous value on top, but return 0 */ + lua_pop(L, 1); + lua_newtable(L); /* create metatable */ + lua_pushvalue(L, -1); + lua_setfield(L, LUA_REGISTRYINDEX, tname); /* registry.name = metatable */ + return 1; +} + + +LUALIB_API void *luaL_checkudata (lua_State *L, int ud, const char *tname) { + void *p = lua_touserdata(L, ud); + if (p != NULL) { /* value is a userdata? */ + if (lua_getmetatable(L, ud)) { /* does it have a metatable? */ + lua_getfield(L, LUA_REGISTRYINDEX, tname); /* get correct metatable */ + if (lua_rawequal(L, -1, -2)) { /* does it have the correct mt? */ + lua_pop(L, 2); /* remove both metatables */ + return p; + } + } + } + luaL_typerror(L, ud, tname); /* else error */ + return NULL; /* to avoid warnings */ +} + + +LUALIB_API void luaL_checkstack (lua_State *L, int space, const char *mes) { + if (!lua_checkstack(L, space)) + luaL_error(L, "stack overflow (%s)", mes); +} + + +LUALIB_API void luaL_checktype (lua_State *L, int narg, int t) { + if (lua_type(L, narg) != t) + tag_error(L, narg, t); +} + + +LUALIB_API void luaL_checkany (lua_State *L, int narg) { + if (lua_type(L, narg) == LUA_TNONE) + luaL_argerror(L, narg, "value expected"); +} + + +LUALIB_API const char *luaL_checklstring (lua_State *L, int narg, size_t *len) { + const char *s = lua_tolstring(L, narg, len); + if (!s) tag_error(L, narg, LUA_TSTRING); + return s; +} + + +LUALIB_API const char *luaL_optlstring (lua_State *L, int narg, + const char *def, size_t *len) { + if (lua_isnoneornil(L, narg)) { + if (len) + *len = (def ? strlen(def) : 0); + return def; + } + else return luaL_checklstring(L, narg, len); +} + + +LUALIB_API lua_Number luaL_checknumber (lua_State *L, int narg) { + lua_Number d = lua_tonumber(L, narg); + if (d == 0 && !lua_isnumber(L, narg)) /* avoid extra test when d is not 0 */ + tag_error(L, narg, LUA_TNUMBER); + return d; +} + + +LUALIB_API lua_Number luaL_optnumber (lua_State *L, int narg, lua_Number def) { + return luaL_opt(L, luaL_checknumber, narg, def); +} + + +LUALIB_API lua_Integer luaL_checkinteger (lua_State *L, int narg) { + lua_Integer d = lua_tointeger(L, narg); + if (d == 0 && !lua_isnumber(L, narg)) /* avoid extra test when d is not 0 */ + tag_error(L, narg, LUA_TNUMBER); + return d; +} + + +LUALIB_API lua_Integer luaL_optinteger (lua_State *L, int narg, + lua_Integer def) { + return luaL_opt(L, luaL_checkinteger, narg, def); +} + + +LUALIB_API int luaL_getmetafield (lua_State *L, int obj, const char *event) { + if (!lua_getmetatable(L, obj)) /* no metatable? */ + return 0; + lua_pushstring(L, event); + lua_rawget(L, -2); + if (lua_isnil(L, -1)) { + lua_pop(L, 2); /* remove metatable and metafield */ + return 0; + } + else { + lua_remove(L, -2); /* remove only metatable */ + return 1; + } +} + + +LUALIB_API int luaL_callmeta (lua_State *L, int obj, const char *event) { + obj = abs_index(L, obj); + if (!luaL_getmetafield(L, obj, event)) /* no metafield? */ + return 0; + lua_pushvalue(L, obj); + lua_call(L, 1, 1); + return 1; +} + + +LUALIB_API void (luaL_register) (lua_State *L, const char *libname, + const luaL_Reg *l) { + luaI_openlib(L, libname, l, 0); +} + + +static int libsize (const luaL_Reg *l) { + int size = 0; + for (; l->name; l++) size++; + return size; +} + + +LUALIB_API void luaI_openlib (lua_State *L, const char *libname, + const luaL_Reg *l, int nup) { + if (libname) { + int size = libsize(l); + /* check whether lib already exists */ + luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 1); + lua_getfield(L, -1, libname); /* get _LOADED[libname] */ + if (!lua_istable(L, -1)) { /* not found? */ + lua_pop(L, 1); /* remove previous result */ + /* try global variable (and create one if it does not exist) */ + if (luaL_findtable(L, LUA_GLOBALSINDEX, libname, size) != NULL) + luaL_error(L, "name conflict for module " LUA_QS, libname); + lua_pushvalue(L, -1); + lua_setfield(L, -3, libname); /* _LOADED[libname] = new table */ + } + lua_remove(L, -2); /* remove _LOADED table */ + lua_insert(L, -(nup+1)); /* move library table to below upvalues */ + } + for (; l->name; l++) { + int i; + for (i=0; ifunc, nup); + lua_setfield(L, -(nup+2), l->name); + } + lua_pop(L, nup); /* remove upvalues */ +} + + + +/* +** {====================================================== +** getn-setn: size for arrays +** ======================================================= +*/ + +#if defined(LUA_COMPAT_GETN) + +static int checkint (lua_State *L, int topop) { + int n = (lua_type(L, -1) == LUA_TNUMBER) ? lua_tointeger(L, -1) : -1; + lua_pop(L, topop); + return n; +} + + +static void getsizes (lua_State *L) { + lua_getfield(L, LUA_REGISTRYINDEX, "LUA_SIZES"); + if (lua_isnil(L, -1)) { /* no `size' table? */ + lua_pop(L, 1); /* remove nil */ + lua_newtable(L); /* create it */ + lua_pushvalue(L, -1); /* `size' will be its own metatable */ + lua_setmetatable(L, -2); + lua_pushliteral(L, "kv"); + lua_setfield(L, -2, "__mode"); /* metatable(N).__mode = "kv" */ + lua_pushvalue(L, -1); + lua_setfield(L, LUA_REGISTRYINDEX, "LUA_SIZES"); /* store in register */ + } +} + + +LUALIB_API void luaL_setn (lua_State *L, int t, int n) { + t = abs_index(L, t); + lua_pushliteral(L, "n"); + lua_rawget(L, t); + if (checkint(L, 1) >= 0) { /* is there a numeric field `n'? */ + lua_pushliteral(L, "n"); /* use it */ + lua_pushinteger(L, n); + lua_rawset(L, t); + } + else { /* use `sizes' */ + getsizes(L); + lua_pushvalue(L, t); + lua_pushinteger(L, n); + lua_rawset(L, -3); /* sizes[t] = n */ + lua_pop(L, 1); /* remove `sizes' */ + } +} + + +LUALIB_API int luaL_getn (lua_State *L, int t) { + int n; + t = abs_index(L, t); + lua_pushliteral(L, "n"); /* try t.n */ + lua_rawget(L, t); + if ((n = checkint(L, 1)) >= 0) return n; + getsizes(L); /* else try sizes[t] */ + lua_pushvalue(L, t); + lua_rawget(L, -2); + if ((n = checkint(L, 2)) >= 0) return n; + return (int)lua_objlen(L, t); +} + +#endif + +/* }====================================================== */ + + + +LUALIB_API const char *luaL_gsub (lua_State *L, const char *s, const char *p, + const char *r) { + const char *wild; + size_t l = strlen(p); + luaL_Buffer b; + luaL_buffinit(L, &b); + while ((wild = strstr(s, p)) != NULL) { + luaL_addlstring(&b, s, wild - s); /* push prefix */ + luaL_addstring(&b, r); /* push replacement in place of pattern */ + s = wild + l; /* continue after `p' */ + } + luaL_addstring(&b, s); /* push last suffix */ + luaL_pushresult(&b); + return lua_tostring(L, -1); +} + + +LUALIB_API const char *luaL_findtable (lua_State *L, int idx, + const char *fname, int szhint) { + const char *e; + lua_pushvalue(L, idx); + do { + e = strchr(fname, '.'); + if (e == NULL) e = fname + strlen(fname); + lua_pushlstring(L, fname, e - fname); + lua_rawget(L, -2); + if (lua_isnil(L, -1)) { /* no such field? */ + lua_pop(L, 1); /* remove this nil */ + lua_createtable(L, 0, (*e == '.' ? 1 : szhint)); /* new table for field */ + lua_pushlstring(L, fname, e - fname); + lua_pushvalue(L, -2); + lua_settable(L, -4); /* set new table into field */ + } + else if (!lua_istable(L, -1)) { /* field has a non-table value? */ + lua_pop(L, 2); /* remove table and value */ + return fname; /* return problematic part of the name */ + } + lua_remove(L, -2); /* remove previous table */ + fname = e + 1; + } while (*e == '.'); + return NULL; +} + + + +/* +** {====================================================== +** Generic Buffer manipulation +** ======================================================= +*/ + + +#define bufflen(B) ((B)->p - (B)->buffer) +#define bufffree(B) ((size_t)(LUAL_BUFFERSIZE - bufflen(B))) + +#define LIMIT (LUA_MINSTACK/2) + + +static int emptybuffer (luaL_Buffer *B) { + size_t l = bufflen(B); + if (l == 0) return 0; /* put nothing on stack */ + else { + lua_pushlstring(B->L, B->buffer, l); + B->p = B->buffer; + B->lvl++; + return 1; + } +} + + +static void adjuststack (luaL_Buffer *B) { + if (B->lvl > 1) { + lua_State *L = B->L; + int toget = 1; /* number of levels to concat */ + size_t toplen = lua_strlen(L, -1); + do { + size_t l = lua_strlen(L, -(toget+1)); + if (B->lvl - toget + 1 >= LIMIT || toplen > l) { + toplen += l; + toget++; + } + else break; + } while (toget < B->lvl); + lua_concat(L, toget); + B->lvl = B->lvl - toget + 1; + } +} + + +LUALIB_API char *luaL_prepbuffer (luaL_Buffer *B) { + if (emptybuffer(B)) + adjuststack(B); + return B->buffer; +} + + +LUALIB_API void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l) { + while (l--) + luaL_addchar(B, *s++); +} + + +LUALIB_API void luaL_addstring (luaL_Buffer *B, const char *s) { + luaL_addlstring(B, s, strlen(s)); +} + + +LUALIB_API void luaL_pushresult (luaL_Buffer *B) { + emptybuffer(B); + lua_concat(B->L, B->lvl); + B->lvl = 1; +} + + +LUALIB_API void luaL_addvalue (luaL_Buffer *B) { + lua_State *L = B->L; + size_t vl; + const char *s = lua_tolstring(L, -1, &vl); + if (vl <= bufffree(B)) { /* fit into buffer? */ + memcpy(B->p, s, vl); /* put it there */ + B->p += vl; + lua_pop(L, 1); /* remove from stack */ + } + else { + if (emptybuffer(B)) + lua_insert(L, -2); /* put buffer before new value */ + B->lvl++; /* add new value into B stack */ + adjuststack(B); + } +} + + +LUALIB_API void luaL_buffinit (lua_State *L, luaL_Buffer *B) { + B->L = L; + B->p = B->buffer; + B->lvl = 0; +} + +/* }====================================================== */ + + +LUALIB_API int luaL_ref (lua_State *L, int t) { + int ref; + t = abs_index(L, t); + if (lua_isnil(L, -1)) { + lua_pop(L, 1); /* remove from stack */ + return LUA_REFNIL; /* `nil' has a unique fixed reference */ + } + lua_rawgeti(L, t, FREELIST_REF); /* get first free element */ + ref = (int)lua_tointeger(L, -1); /* ref = t[FREELIST_REF] */ + lua_pop(L, 1); /* remove it from stack */ + if (ref != 0) { /* any free element? */ + lua_rawgeti(L, t, ref); /* remove it from list */ + lua_rawseti(L, t, FREELIST_REF); /* (t[FREELIST_REF] = t[ref]) */ + } + else { /* no free elements */ + ref = (int)lua_objlen(L, t); + ref++; /* create new reference */ + } + lua_rawseti(L, t, ref); + return ref; +} + + +LUALIB_API void luaL_unref (lua_State *L, int t, int ref) { + if (ref >= 0) { + t = abs_index(L, t); + lua_rawgeti(L, t, FREELIST_REF); + lua_rawseti(L, t, ref); /* t[ref] = t[FREELIST_REF] */ + lua_pushinteger(L, ref); + lua_rawseti(L, t, FREELIST_REF); /* t[FREELIST_REF] = ref */ + } +} + + + +/* +** {====================================================== +** Load functions +** ======================================================= +*/ + +typedef struct LoadF { + int extraline; + FILE *f; + char buff[LUAL_BUFFERSIZE]; +} LoadF; + + +static const char *getF (lua_State *L, void *ud, size_t *size) { + LoadF *lf = (LoadF *)ud; + (void)L; + if (lf->extraline) { + lf->extraline = 0; + *size = 1; + return "\n"; + } + if (feof(lf->f)) return NULL; + *size = fread(lf->buff, 1, sizeof(lf->buff), lf->f); + return (*size > 0) ? lf->buff : NULL; +} + + +static int errfile (lua_State *L, const char *what, int fnameindex) { + const char *serr = strerror(errno); + const char *filename = lua_tostring(L, fnameindex) + 1; + lua_pushfstring(L, "cannot %s %s: %s", what, filename, serr); + lua_remove(L, fnameindex); + return LUA_ERRFILE; +} + + +LUALIB_API int luaL_loadfile (lua_State *L, const char *filename) { + LoadF lf; + int status, readstatus; + int c; + int fnameindex = lua_gettop(L) + 1; /* index of filename on the stack */ + lf.extraline = 0; + if (filename == NULL) { + lua_pushliteral(L, "=stdin"); + lf.f = stdin; + } + else { + lua_pushfstring(L, "@%s", filename); + lf.f = fopen(filename, "r"); + if (lf.f == NULL) return errfile(L, "open", fnameindex); + } + c = getc(lf.f); + if (c == '#') { /* Unix exec. file? */ + lf.extraline = 1; + while ((c = getc(lf.f)) != EOF && c != '\n') ; /* skip first line */ + if (c == '\n') c = getc(lf.f); + } + if (c == LUA_SIGNATURE[0] && filename) { /* binary file? */ + lf.f = freopen(filename, "rb", lf.f); /* reopen in binary mode */ + if (lf.f == NULL) return errfile(L, "reopen", fnameindex); + /* skip eventual `#!...' */ + while ((c = getc(lf.f)) != EOF && c != LUA_SIGNATURE[0]) ; + lf.extraline = 0; + } + ungetc(c, lf.f); + status = lua_load(L, getF, &lf, lua_tostring(L, -1)); + readstatus = ferror(lf.f); + if (filename) fclose(lf.f); /* close file (even in case of errors) */ + if (readstatus) { + lua_settop(L, fnameindex); /* ignore results from `lua_load' */ + return errfile(L, "read", fnameindex); + } + lua_remove(L, fnameindex); + return status; +} + + +typedef struct LoadS { + const char *s; + size_t size; +} LoadS; + + +static const char *getS (lua_State *L, void *ud, size_t *size) { + LoadS *ls = (LoadS *)ud; + (void)L; + if (ls->size == 0) return NULL; + *size = ls->size; + ls->size = 0; + return ls->s; +} + + +LUALIB_API int luaL_loadbuffer (lua_State *L, const char *buff, size_t size, + const char *name) { + LoadS ls; + ls.s = buff; + ls.size = size; + return lua_load(L, getS, &ls, name); +} + + +LUALIB_API int (luaL_loadstring) (lua_State *L, const char *s) { + return luaL_loadbuffer(L, s, strlen(s), s); +} + + + +/* }====================================================== */ + + +static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) { + (void)ud; + (void)osize; + if (nsize == 0) { + free(ptr); + return NULL; + } + else + return realloc(ptr, nsize); +} + + +static int panic (lua_State *L) { + (void)L; /* to avoid warnings */ + fprintf(stderr, "PANIC: unprotected error in call to Lua API (%s)\n", + lua_tostring(L, -1)); + return 0; +} + + +LUALIB_API lua_State *luaL_newstate (void) { + lua_State *L = lua_newstate(l_alloc, NULL); + if (L) lua_atpanic(L, &panic); + return L; +} + diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lauxlib.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lauxlib.h new file mode 100644 index 00000000..34258235 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lauxlib.h @@ -0,0 +1,174 @@ +/* +** $Id: lauxlib.h,v 1.88.1.1 2007/12/27 13:02:25 roberto Exp $ +** Auxiliary functions for building Lua libraries +** See Copyright Notice in lua.h +*/ + + +#ifndef lauxlib_h +#define lauxlib_h + + +#include +#include + +#include "lua.h" + + +#if defined(LUA_COMPAT_GETN) +LUALIB_API int (luaL_getn) (lua_State *L, int t); +LUALIB_API void (luaL_setn) (lua_State *L, int t, int n); +#else +#define luaL_getn(L,i) ((int)lua_objlen(L, i)) +#define luaL_setn(L,i,j) ((void)0) /* no op! */ +#endif + +#if defined(LUA_COMPAT_OPENLIB) +#define luaI_openlib luaL_openlib +#endif + + +/* extra error code for `luaL_load' */ +#define LUA_ERRFILE (LUA_ERRERR+1) + + +typedef struct luaL_Reg { + const char *name; + lua_CFunction func; +} luaL_Reg; + + + +LUALIB_API void (luaI_openlib) (lua_State *L, const char *libname, + const luaL_Reg *l, int nup); +LUALIB_API void (luaL_register) (lua_State *L, const char *libname, + const luaL_Reg *l); +LUALIB_API int (luaL_getmetafield) (lua_State *L, int obj, const char *e); +LUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e); +LUALIB_API int (luaL_typerror) (lua_State *L, int narg, const char *tname); +LUALIB_API int (luaL_argerror) (lua_State *L, int numarg, const char *extramsg); +LUALIB_API const char *(luaL_checklstring) (lua_State *L, int numArg, + size_t *l); +LUALIB_API const char *(luaL_optlstring) (lua_State *L, int numArg, + const char *def, size_t *l); +LUALIB_API lua_Number (luaL_checknumber) (lua_State *L, int numArg); +LUALIB_API lua_Number (luaL_optnumber) (lua_State *L, int nArg, lua_Number def); + +LUALIB_API lua_Integer (luaL_checkinteger) (lua_State *L, int numArg); +LUALIB_API lua_Integer (luaL_optinteger) (lua_State *L, int nArg, + lua_Integer def); + +LUALIB_API void (luaL_checkstack) (lua_State *L, int sz, const char *msg); +LUALIB_API void (luaL_checktype) (lua_State *L, int narg, int t); +LUALIB_API void (luaL_checkany) (lua_State *L, int narg); + +LUALIB_API int (luaL_newmetatable) (lua_State *L, const char *tname); +LUALIB_API void *(luaL_checkudata) (lua_State *L, int ud, const char *tname); + +LUALIB_API void (luaL_where) (lua_State *L, int lvl); +LUALIB_API int (luaL_error) (lua_State *L, const char *fmt, ...); + +LUALIB_API int (luaL_checkoption) (lua_State *L, int narg, const char *def, + const char *const lst[]); + +LUALIB_API int (luaL_ref) (lua_State *L, int t); +LUALIB_API void (luaL_unref) (lua_State *L, int t, int ref); + +LUALIB_API int (luaL_loadfile) (lua_State *L, const char *filename); +LUALIB_API int (luaL_loadbuffer) (lua_State *L, const char *buff, size_t sz, + const char *name); +LUALIB_API int (luaL_loadstring) (lua_State *L, const char *s); + +LUALIB_API lua_State *(luaL_newstate) (void); + + +LUALIB_API const char *(luaL_gsub) (lua_State *L, const char *s, const char *p, + const char *r); + +LUALIB_API const char *(luaL_findtable) (lua_State *L, int idx, + const char *fname, int szhint); + + + + +/* +** =============================================================== +** some useful macros +** =============================================================== +*/ + +#define luaL_argcheck(L, cond,numarg,extramsg) \ + ((void)((cond) || luaL_argerror(L, (numarg), (extramsg)))) +#define luaL_checkstring(L,n) (luaL_checklstring(L, (n), NULL)) +#define luaL_optstring(L,n,d) (luaL_optlstring(L, (n), (d), NULL)) +#define luaL_checkint(L,n) ((int)luaL_checkinteger(L, (n))) +#define luaL_optint(L,n,d) ((int)luaL_optinteger(L, (n), (d))) +#define luaL_checklong(L,n) ((long)luaL_checkinteger(L, (n))) +#define luaL_optlong(L,n,d) ((long)luaL_optinteger(L, (n), (d))) + +#define luaL_typename(L,i) lua_typename(L, lua_type(L,(i))) + +#define luaL_dofile(L, fn) \ + (luaL_loadfile(L, fn) || lua_pcall(L, 0, LUA_MULTRET, 0)) + +#define luaL_dostring(L, s) \ + (luaL_loadstring(L, s) || lua_pcall(L, 0, LUA_MULTRET, 0)) + +#define luaL_getmetatable(L,n) (lua_getfield(L, LUA_REGISTRYINDEX, (n))) + +#define luaL_opt(L,f,n,d) (lua_isnoneornil(L,(n)) ? (d) : f(L,(n))) + +/* +** {====================================================== +** Generic Buffer manipulation +** ======================================================= +*/ + + + +typedef struct luaL_Buffer { + char *p; /* current position in buffer */ + int lvl; /* number of strings in the stack (level) */ + lua_State *L; + char buffer[LUAL_BUFFERSIZE]; +} luaL_Buffer; + +#define luaL_addchar(B,c) \ + ((void)((B)->p < ((B)->buffer+LUAL_BUFFERSIZE) || luaL_prepbuffer(B)), \ + (*(B)->p++ = (char)(c))) + +/* compatibility only */ +#define luaL_putchar(B,c) luaL_addchar(B,c) + +#define luaL_addsize(B,n) ((B)->p += (n)) + +LUALIB_API void (luaL_buffinit) (lua_State *L, luaL_Buffer *B); +LUALIB_API char *(luaL_prepbuffer) (luaL_Buffer *B); +LUALIB_API void (luaL_addlstring) (luaL_Buffer *B, const char *s, size_t l); +LUALIB_API void (luaL_addstring) (luaL_Buffer *B, const char *s); +LUALIB_API void (luaL_addvalue) (luaL_Buffer *B); +LUALIB_API void (luaL_pushresult) (luaL_Buffer *B); + + +/* }====================================================== */ + + +/* compatibility with ref system */ + +/* pre-defined references */ +#define LUA_NOREF (-2) +#define LUA_REFNIL (-1) + +#define lua_ref(L,lock) ((lock) ? luaL_ref(L, LUA_REGISTRYINDEX) : \ + (lua_pushstring(L, "unlocked references are obsolete"), lua_error(L), 0)) + +#define lua_unref(L,ref) luaL_unref(L, LUA_REGISTRYINDEX, (ref)) + +#define lua_getref(L,ref) lua_rawgeti(L, LUA_REGISTRYINDEX, (ref)) + + +#define luaL_reg luaL_Reg + +#endif + + diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lbaselib.c b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lbaselib.c new file mode 100644 index 00000000..2a4c079d --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lbaselib.c @@ -0,0 +1,653 @@ +/* +** $Id: lbaselib.c,v 1.191.1.6 2008/02/14 16:46:22 roberto Exp $ +** Basic library +** See Copyright Notice in lua.h +*/ + + + +#include +#include +#include +#include + +#define lbaselib_c +#define LUA_LIB + +#include "lua.h" + +#include "lauxlib.h" +#include "lualib.h" + + + + +/* +** If your system does not support `stdout', you can just remove this function. +** If you need, you can define your own `print' function, following this +** model but changing `fputs' to put the strings at a proper place +** (a console window or a log file, for instance). +*/ +static int luaB_print (lua_State *L) { + int n = lua_gettop(L); /* number of arguments */ + int i; + lua_getglobal(L, "tostring"); + for (i=1; i<=n; i++) { + const char *s; + lua_pushvalue(L, -1); /* function to be called */ + lua_pushvalue(L, i); /* value to print */ + lua_call(L, 1, 1); + s = lua_tostring(L, -1); /* get result */ + if (s == NULL) + return luaL_error(L, LUA_QL("tostring") " must return a string to " + LUA_QL("print")); + if (i>1) fputs("\t", stdout); + fputs(s, stdout); + lua_pop(L, 1); /* pop result */ + } + fputs("\n", stdout); + return 0; +} + + +static int luaB_tonumber (lua_State *L) { + int base = luaL_optint(L, 2, 10); + if (base == 10) { /* standard conversion */ + luaL_checkany(L, 1); + if (lua_isnumber(L, 1)) { + lua_pushnumber(L, lua_tonumber(L, 1)); + return 1; + } + } + else { + const char *s1 = luaL_checkstring(L, 1); + char *s2; + unsigned long n; + luaL_argcheck(L, 2 <= base && base <= 36, 2, "base out of range"); + n = strtoul(s1, &s2, base); + if (s1 != s2) { /* at least one valid digit? */ + while (isspace((unsigned char)(*s2))) s2++; /* skip trailing spaces */ + if (*s2 == '\0') { /* no invalid trailing characters? */ + lua_pushnumber(L, (lua_Number)n); + return 1; + } + } + } + lua_pushnil(L); /* else not a number */ + return 1; +} + + +static int luaB_error (lua_State *L) { + int level = luaL_optint(L, 2, 1); + lua_settop(L, 1); + if (lua_isstring(L, 1) && level > 0) { /* add extra information? */ + luaL_where(L, level); + lua_pushvalue(L, 1); + lua_concat(L, 2); + } + return lua_error(L); +} + + +static int luaB_getmetatable (lua_State *L) { + luaL_checkany(L, 1); + if (!lua_getmetatable(L, 1)) { + lua_pushnil(L); + return 1; /* no metatable */ + } + luaL_getmetafield(L, 1, "__metatable"); + return 1; /* returns either __metatable field (if present) or metatable */ +} + + +static int luaB_setmetatable (lua_State *L) { + int t = lua_type(L, 2); + luaL_checktype(L, 1, LUA_TTABLE); + luaL_argcheck(L, t == LUA_TNIL || t == LUA_TTABLE, 2, + "nil or table expected"); + if (luaL_getmetafield(L, 1, "__metatable")) + luaL_error(L, "cannot change a protected metatable"); + lua_settop(L, 2); + lua_setmetatable(L, 1); + return 1; +} + + +static void getfunc (lua_State *L, int opt) { + if (lua_isfunction(L, 1)) lua_pushvalue(L, 1); + else { + lua_Debug ar; + int level = opt ? luaL_optint(L, 1, 1) : luaL_checkint(L, 1); + luaL_argcheck(L, level >= 0, 1, "level must be non-negative"); + if (lua_getstack(L, level, &ar) == 0) + luaL_argerror(L, 1, "invalid level"); + lua_getinfo(L, "f", &ar); + if (lua_isnil(L, -1)) + luaL_error(L, "no function environment for tail call at level %d", + level); + } +} + + +static int luaB_getfenv (lua_State *L) { + getfunc(L, 1); + if (lua_iscfunction(L, -1)) /* is a C function? */ + lua_pushvalue(L, LUA_GLOBALSINDEX); /* return the thread's global env. */ + else + lua_getfenv(L, -1); + return 1; +} + + +static int luaB_setfenv (lua_State *L) { + luaL_checktype(L, 2, LUA_TTABLE); + getfunc(L, 0); + lua_pushvalue(L, 2); + if (lua_isnumber(L, 1) && lua_tonumber(L, 1) == 0) { + /* change environment of current thread */ + lua_pushthread(L); + lua_insert(L, -2); + lua_setfenv(L, -2); + return 0; + } + else if (lua_iscfunction(L, -2) || lua_setfenv(L, -2) == 0) + luaL_error(L, + LUA_QL("setfenv") " cannot change environment of given object"); + return 1; +} + + +static int luaB_rawequal (lua_State *L) { + luaL_checkany(L, 1); + luaL_checkany(L, 2); + lua_pushboolean(L, lua_rawequal(L, 1, 2)); + return 1; +} + + +static int luaB_rawget (lua_State *L) { + luaL_checktype(L, 1, LUA_TTABLE); + luaL_checkany(L, 2); + lua_settop(L, 2); + lua_rawget(L, 1); + return 1; +} + +static int luaB_rawset (lua_State *L) { + luaL_checktype(L, 1, LUA_TTABLE); + luaL_checkany(L, 2); + luaL_checkany(L, 3); + lua_settop(L, 3); + lua_rawset(L, 1); + return 1; +} + + +static int luaB_gcinfo (lua_State *L) { + lua_pushinteger(L, lua_getgccount(L)); + return 1; +} + + +static int luaB_collectgarbage (lua_State *L) { + static const char *const opts[] = {"stop", "restart", "collect", + "count", "step", "setpause", "setstepmul", NULL}; + static const int optsnum[] = {LUA_GCSTOP, LUA_GCRESTART, LUA_GCCOLLECT, + LUA_GCCOUNT, LUA_GCSTEP, LUA_GCSETPAUSE, LUA_GCSETSTEPMUL}; + int o = luaL_checkoption(L, 1, "collect", opts); + int ex = luaL_optint(L, 2, 0); + int res = lua_gc(L, optsnum[o], ex); + switch (optsnum[o]) { + case LUA_GCCOUNT: { + int b = lua_gc(L, LUA_GCCOUNTB, 0); + lua_pushnumber(L, res + ((lua_Number)b/1024)); + return 1; + } + case LUA_GCSTEP: { + lua_pushboolean(L, res); + return 1; + } + default: { + lua_pushnumber(L, res); + return 1; + } + } +} + + +static int luaB_type (lua_State *L) { + luaL_checkany(L, 1); + lua_pushstring(L, luaL_typename(L, 1)); + return 1; +} + + +static int luaB_next (lua_State *L) { + luaL_checktype(L, 1, LUA_TTABLE); + lua_settop(L, 2); /* create a 2nd argument if there isn't one */ + if (lua_next(L, 1)) + return 2; + else { + lua_pushnil(L); + return 1; + } +} + + +static int luaB_pairs (lua_State *L) { + luaL_checktype(L, 1, LUA_TTABLE); + lua_pushvalue(L, lua_upvalueindex(1)); /* return generator, */ + lua_pushvalue(L, 1); /* state, */ + lua_pushnil(L); /* and initial value */ + return 3; +} + + +static int ipairsaux (lua_State *L) { + int i = luaL_checkint(L, 2); + luaL_checktype(L, 1, LUA_TTABLE); + i++; /* next value */ + lua_pushinteger(L, i); + lua_rawgeti(L, 1, i); + return (lua_isnil(L, -1)) ? 0 : 2; +} + + +static int luaB_ipairs (lua_State *L) { + luaL_checktype(L, 1, LUA_TTABLE); + lua_pushvalue(L, lua_upvalueindex(1)); /* return generator, */ + lua_pushvalue(L, 1); /* state, */ + lua_pushinteger(L, 0); /* and initial value */ + return 3; +} + + +static int load_aux (lua_State *L, int status) { + if (status == 0) /* OK? */ + return 1; + else { + lua_pushnil(L); + lua_insert(L, -2); /* put before error message */ + return 2; /* return nil plus error message */ + } +} + + +static int luaB_loadstring (lua_State *L) { + size_t l; + const char *s = luaL_checklstring(L, 1, &l); + const char *chunkname = luaL_optstring(L, 2, s); + return load_aux(L, luaL_loadbuffer(L, s, l, chunkname)); +} + + +static int luaB_loadfile (lua_State *L) { + const char *fname = luaL_optstring(L, 1, NULL); + return load_aux(L, luaL_loadfile(L, fname)); +} + + +/* +** Reader for generic `load' function: `lua_load' uses the +** stack for internal stuff, so the reader cannot change the +** stack top. Instead, it keeps its resulting string in a +** reserved slot inside the stack. +*/ +static const char *generic_reader (lua_State *L, void *ud, size_t *size) { + (void)ud; /* to avoid warnings */ + luaL_checkstack(L, 2, "too many nested functions"); + lua_pushvalue(L, 1); /* get function */ + lua_call(L, 0, 1); /* call it */ + if (lua_isnil(L, -1)) { + *size = 0; + return NULL; + } + else if (lua_isstring(L, -1)) { + lua_replace(L, 3); /* save string in a reserved stack slot */ + return lua_tolstring(L, 3, size); + } + else luaL_error(L, "reader function must return a string"); + return NULL; /* to avoid warnings */ +} + + +static int luaB_load (lua_State *L) { + int status; + const char *cname = luaL_optstring(L, 2, "=(load)"); + luaL_checktype(L, 1, LUA_TFUNCTION); + lua_settop(L, 3); /* function, eventual name, plus one reserved slot */ + status = lua_load(L, generic_reader, NULL, cname); + return load_aux(L, status); +} + + +static int luaB_dofile (lua_State *L) { + const char *fname = luaL_optstring(L, 1, NULL); + int n = lua_gettop(L); + if (luaL_loadfile(L, fname) != 0) lua_error(L); + lua_call(L, 0, LUA_MULTRET); + return lua_gettop(L) - n; +} + + +static int luaB_assert (lua_State *L) { + luaL_checkany(L, 1); + if (!lua_toboolean(L, 1)) + return luaL_error(L, "%s", luaL_optstring(L, 2, "assertion failed!")); + return lua_gettop(L); +} + + +static int luaB_unpack (lua_State *L) { + int i, e, n; + luaL_checktype(L, 1, LUA_TTABLE); + i = luaL_optint(L, 2, 1); + e = luaL_opt(L, luaL_checkint, 3, luaL_getn(L, 1)); + if (i > e) return 0; /* empty range */ + n = e - i + 1; /* number of elements */ + if (n <= 0 || !lua_checkstack(L, n)) /* n <= 0 means arith. overflow */ + return luaL_error(L, "too many results to unpack"); + lua_rawgeti(L, 1, i); /* push arg[i] (avoiding overflow problems) */ + while (i++ < e) /* push arg[i + 1...e] */ + lua_rawgeti(L, 1, i); + return n; +} + + +static int luaB_select (lua_State *L) { + int n = lua_gettop(L); + if (lua_type(L, 1) == LUA_TSTRING && *lua_tostring(L, 1) == '#') { + lua_pushinteger(L, n-1); + return 1; + } + else { + int i = luaL_checkint(L, 1); + if (i < 0) i = n + i; + else if (i > n) i = n; + luaL_argcheck(L, 1 <= i, 1, "index out of range"); + return n - i; + } +} + + +static int luaB_pcall (lua_State *L) { + int status; + luaL_checkany(L, 1); + status = lua_pcall(L, lua_gettop(L) - 1, LUA_MULTRET, 0); + lua_pushboolean(L, (status == 0)); + lua_insert(L, 1); + return lua_gettop(L); /* return status + all results */ +} + + +static int luaB_xpcall (lua_State *L) { + int status; + luaL_checkany(L, 2); + lua_settop(L, 2); + lua_insert(L, 1); /* put error function under function to be called */ + status = lua_pcall(L, 0, LUA_MULTRET, 1); + lua_pushboolean(L, (status == 0)); + lua_replace(L, 1); + return lua_gettop(L); /* return status + all results */ +} + + +static int luaB_tostring (lua_State *L) { + luaL_checkany(L, 1); + if (luaL_callmeta(L, 1, "__tostring")) /* is there a metafield? */ + return 1; /* use its value */ + switch (lua_type(L, 1)) { + case LUA_TNUMBER: + lua_pushstring(L, lua_tostring(L, 1)); + break; + case LUA_TSTRING: + lua_pushvalue(L, 1); + break; + case LUA_TBOOLEAN: + lua_pushstring(L, (lua_toboolean(L, 1) ? "true" : "false")); + break; + case LUA_TNIL: + lua_pushliteral(L, "nil"); + break; + default: + lua_pushfstring(L, "%s: %p", luaL_typename(L, 1), lua_topointer(L, 1)); + break; + } + return 1; +} + + +static int luaB_newproxy (lua_State *L) { + lua_settop(L, 1); + lua_newuserdata(L, 0); /* create proxy */ + if (lua_toboolean(L, 1) == 0) + return 1; /* no metatable */ + else if (lua_isboolean(L, 1)) { + lua_newtable(L); /* create a new metatable `m' ... */ + lua_pushvalue(L, -1); /* ... and mark `m' as a valid metatable */ + lua_pushboolean(L, 1); + lua_rawset(L, lua_upvalueindex(1)); /* weaktable[m] = true */ + } + else { + int validproxy = 0; /* to check if weaktable[metatable(u)] == true */ + if (lua_getmetatable(L, 1)) { + lua_rawget(L, lua_upvalueindex(1)); + validproxy = lua_toboolean(L, -1); + lua_pop(L, 1); /* remove value */ + } + luaL_argcheck(L, validproxy, 1, "boolean or proxy expected"); + lua_getmetatable(L, 1); /* metatable is valid; get it */ + } + lua_setmetatable(L, 2); + return 1; +} + + +static const luaL_Reg base_funcs[] = { + {"assert", luaB_assert}, + {"collectgarbage", luaB_collectgarbage}, + {"dofile", luaB_dofile}, + {"error", luaB_error}, + {"gcinfo", luaB_gcinfo}, + {"getfenv", luaB_getfenv}, + {"getmetatable", luaB_getmetatable}, + {"loadfile", luaB_loadfile}, + {"load", luaB_load}, + {"loadstring", luaB_loadstring}, + {"next", luaB_next}, + {"pcall", luaB_pcall}, + {"print", luaB_print}, + {"rawequal", luaB_rawequal}, + {"rawget", luaB_rawget}, + {"rawset", luaB_rawset}, + {"select", luaB_select}, + {"setfenv", luaB_setfenv}, + {"setmetatable", luaB_setmetatable}, + {"tonumber", luaB_tonumber}, + {"tostring", luaB_tostring}, + {"type", luaB_type}, + {"unpack", luaB_unpack}, + {"xpcall", luaB_xpcall}, + {NULL, NULL} +}; + + +/* +** {====================================================== +** Coroutine library +** ======================================================= +*/ + +#define CO_RUN 0 /* running */ +#define CO_SUS 1 /* suspended */ +#define CO_NOR 2 /* 'normal' (it resumed another coroutine) */ +#define CO_DEAD 3 + +static const char *const statnames[] = + {"running", "suspended", "normal", "dead"}; + +static int costatus (lua_State *L, lua_State *co) { + if (L == co) return CO_RUN; + switch (lua_status(co)) { + case LUA_YIELD: + return CO_SUS; + case 0: { + lua_Debug ar; + if (lua_getstack(co, 0, &ar) > 0) /* does it have frames? */ + return CO_NOR; /* it is running */ + else if (lua_gettop(co) == 0) + return CO_DEAD; + else + return CO_SUS; /* initial state */ + } + default: /* some error occured */ + return CO_DEAD; + } +} + + +static int luaB_costatus (lua_State *L) { + lua_State *co = lua_tothread(L, 1); + luaL_argcheck(L, co, 1, "coroutine expected"); + lua_pushstring(L, statnames[costatus(L, co)]); + return 1; +} + + +static int auxresume (lua_State *L, lua_State *co, int narg) { + int status = costatus(L, co); + if (!lua_checkstack(co, narg)) + luaL_error(L, "too many arguments to resume"); + if (status != CO_SUS) { + lua_pushfstring(L, "cannot resume %s coroutine", statnames[status]); + return -1; /* error flag */ + } + lua_xmove(L, co, narg); + lua_setlevel(L, co); + status = lua_resume(co, narg); + if (status == 0 || status == LUA_YIELD) { + int nres = lua_gettop(co); + if (!lua_checkstack(L, nres + 1)) + luaL_error(L, "too many results to resume"); + lua_xmove(co, L, nres); /* move yielded values */ + return nres; + } + else { + lua_xmove(co, L, 1); /* move error message */ + return -1; /* error flag */ + } +} + + +static int luaB_coresume (lua_State *L) { + lua_State *co = lua_tothread(L, 1); + int r; + luaL_argcheck(L, co, 1, "coroutine expected"); + r = auxresume(L, co, lua_gettop(L) - 1); + if (r < 0) { + lua_pushboolean(L, 0); + lua_insert(L, -2); + return 2; /* return false + error message */ + } + else { + lua_pushboolean(L, 1); + lua_insert(L, -(r + 1)); + return r + 1; /* return true + `resume' returns */ + } +} + + +static int luaB_auxwrap (lua_State *L) { + lua_State *co = lua_tothread(L, lua_upvalueindex(1)); + int r = auxresume(L, co, lua_gettop(L)); + if (r < 0) { + if (lua_isstring(L, -1)) { /* error object is a string? */ + luaL_where(L, 1); /* add extra info */ + lua_insert(L, -2); + lua_concat(L, 2); + } + lua_error(L); /* propagate error */ + } + return r; +} + + +static int luaB_cocreate (lua_State *L) { + lua_State *NL = lua_newthread(L); + luaL_argcheck(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), 1, + "Lua function expected"); + lua_pushvalue(L, 1); /* move function to top */ + lua_xmove(L, NL, 1); /* move function from L to NL */ + return 1; +} + + +static int luaB_cowrap (lua_State *L) { + luaB_cocreate(L); + lua_pushcclosure(L, luaB_auxwrap, 1); + return 1; +} + + +static int luaB_yield (lua_State *L) { + return lua_yield(L, lua_gettop(L)); +} + + +static int luaB_corunning (lua_State *L) { + if (lua_pushthread(L)) + lua_pushnil(L); /* main thread is not a coroutine */ + return 1; +} + + +static const luaL_Reg co_funcs[] = { + {"create", luaB_cocreate}, + {"resume", luaB_coresume}, + {"running", luaB_corunning}, + {"status", luaB_costatus}, + {"wrap", luaB_cowrap}, + {"yield", luaB_yield}, + {NULL, NULL} +}; + +/* }====================================================== */ + + +static void auxopen (lua_State *L, const char *name, + lua_CFunction f, lua_CFunction u) { + lua_pushcfunction(L, u); + lua_pushcclosure(L, f, 1); + lua_setfield(L, -2, name); +} + + +static void base_open (lua_State *L) { + /* set global _G */ + lua_pushvalue(L, LUA_GLOBALSINDEX); + lua_setglobal(L, "_G"); + /* open lib into global table */ + luaL_register(L, "_G", base_funcs); + lua_pushliteral(L, LUA_VERSION); + lua_setglobal(L, "_VERSION"); /* set global _VERSION */ + /* `ipairs' and `pairs' need auxliliary functions as upvalues */ + auxopen(L, "ipairs", luaB_ipairs, ipairsaux); + auxopen(L, "pairs", luaB_pairs, luaB_next); + /* `newproxy' needs a weaktable as upvalue */ + lua_createtable(L, 0, 1); /* new table `w' */ + lua_pushvalue(L, -1); /* `w' will be its own metatable */ + lua_setmetatable(L, -2); + lua_pushliteral(L, "kv"); + lua_setfield(L, -2, "__mode"); /* metatable(w).__mode = "kv" */ + lua_pushcclosure(L, luaB_newproxy, 1); + lua_setglobal(L, "newproxy"); /* set global `newproxy' */ +} + + +LUALIB_API int luaopen_base (lua_State *L) { + base_open(L); + luaL_register(L, LUA_COLIBNAME, co_funcs); + return 2; +} + diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lcode.c b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lcode.c new file mode 100644 index 00000000..cff626b7 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lcode.c @@ -0,0 +1,839 @@ +/* +** $Id: lcode.c,v 2.25.1.3 2007/12/28 15:32:23 roberto Exp $ +** Code generator for Lua +** See Copyright Notice in lua.h +*/ + + +#include + +#define lcode_c +#define LUA_CORE + +#include "lua.h" + +#include "lcode.h" +#include "ldebug.h" +#include "ldo.h" +#include "lgc.h" +#include "llex.h" +#include "lmem.h" +#include "lobject.h" +#include "lopcodes.h" +#include "lparser.h" +#include "ltable.h" + + +#define hasjumps(e) ((e)->t != (e)->f) + + +static int isnumeral(expdesc *e) { + return (e->k == VKNUM && e->t == NO_JUMP && e->f == NO_JUMP); +} + + +void luaK_nil (FuncState *fs, int from, int n) { + Instruction *previous; + if (fs->pc > fs->lasttarget) { /* no jumps to current position? */ + if (fs->pc == 0) { /* function start? */ + if (from >= fs->nactvar) + return; /* positions are already clean */ + } + else { + previous = &fs->f->code[fs->pc-1]; + if (GET_OPCODE(*previous) == OP_LOADNIL) { + int pfrom = GETARG_A(*previous); + int pto = GETARG_B(*previous); + if (pfrom <= from && from <= pto+1) { /* can connect both? */ + if (from+n-1 > pto) + SETARG_B(*previous, from+n-1); + return; + } + } + } + } + luaK_codeABC(fs, OP_LOADNIL, from, from+n-1, 0); /* else no optimization */ +} + + +int luaK_jump (FuncState *fs) { + int jpc = fs->jpc; /* save list of jumps to here */ + int j; + fs->jpc = NO_JUMP; + j = luaK_codeAsBx(fs, OP_JMP, 0, NO_JUMP); + luaK_concat(fs, &j, jpc); /* keep them on hold */ + return j; +} + + +void luaK_ret (FuncState *fs, int first, int nret) { + luaK_codeABC(fs, OP_RETURN, first, nret+1, 0); +} + + +static int condjump (FuncState *fs, OpCode op, int A, int B, int C) { + luaK_codeABC(fs, op, A, B, C); + return luaK_jump(fs); +} + + +static void fixjump (FuncState *fs, int pc, int dest) { + Instruction *jmp = &fs->f->code[pc]; + int offset = dest-(pc+1); + lua_assert(dest != NO_JUMP); + if (abs(offset) > MAXARG_sBx) + luaX_syntaxerror(fs->ls, "control structure too long"); + SETARG_sBx(*jmp, offset); +} + + +/* +** returns current `pc' and marks it as a jump target (to avoid wrong +** optimizations with consecutive instructions not in the same basic block). +*/ +int luaK_getlabel (FuncState *fs) { + fs->lasttarget = fs->pc; + return fs->pc; +} + + +static int getjump (FuncState *fs, int pc) { + int offset = GETARG_sBx(fs->f->code[pc]); + if (offset == NO_JUMP) /* point to itself represents end of list */ + return NO_JUMP; /* end of list */ + else + return (pc+1)+offset; /* turn offset into absolute position */ +} + + +static Instruction *getjumpcontrol (FuncState *fs, int pc) { + Instruction *pi = &fs->f->code[pc]; + if (pc >= 1 && testTMode(GET_OPCODE(*(pi-1)))) + return pi-1; + else + return pi; +} + + +/* +** check whether list has any jump that do not produce a value +** (or produce an inverted value) +*/ +static int need_value (FuncState *fs, int list) { + for (; list != NO_JUMP; list = getjump(fs, list)) { + Instruction i = *getjumpcontrol(fs, list); + if (GET_OPCODE(i) != OP_TESTSET) return 1; + } + return 0; /* not found */ +} + + +static int patchtestreg (FuncState *fs, int node, int reg) { + Instruction *i = getjumpcontrol(fs, node); + if (GET_OPCODE(*i) != OP_TESTSET) + return 0; /* cannot patch other instructions */ + if (reg != NO_REG && reg != GETARG_B(*i)) + SETARG_A(*i, reg); + else /* no register to put value or register already has the value */ + *i = CREATE_ABC(OP_TEST, GETARG_B(*i), 0, GETARG_C(*i)); + + return 1; +} + + +static void removevalues (FuncState *fs, int list) { + for (; list != NO_JUMP; list = getjump(fs, list)) + patchtestreg(fs, list, NO_REG); +} + + +static void patchlistaux (FuncState *fs, int list, int vtarget, int reg, + int dtarget) { + while (list != NO_JUMP) { + int next = getjump(fs, list); + if (patchtestreg(fs, list, reg)) + fixjump(fs, list, vtarget); + else + fixjump(fs, list, dtarget); /* jump to default target */ + list = next; + } +} + + +static void dischargejpc (FuncState *fs) { + patchlistaux(fs, fs->jpc, fs->pc, NO_REG, fs->pc); + fs->jpc = NO_JUMP; +} + + +void luaK_patchlist (FuncState *fs, int list, int target) { + if (target == fs->pc) + luaK_patchtohere(fs, list); + else { + lua_assert(target < fs->pc); + patchlistaux(fs, list, target, NO_REG, target); + } +} + + +void luaK_patchtohere (FuncState *fs, int list) { + luaK_getlabel(fs); + luaK_concat(fs, &fs->jpc, list); +} + + +void luaK_concat (FuncState *fs, int *l1, int l2) { + if (l2 == NO_JUMP) return; + else if (*l1 == NO_JUMP) + *l1 = l2; + else { + int list = *l1; + int next; + while ((next = getjump(fs, list)) != NO_JUMP) /* find last element */ + list = next; + fixjump(fs, list, l2); + } +} + + +void luaK_checkstack (FuncState *fs, int n) { + int newstack = fs->freereg + n; + if (newstack > fs->f->maxstacksize) { + if (newstack >= MAXSTACK) + luaX_syntaxerror(fs->ls, "function or expression too complex"); + fs->f->maxstacksize = cast_byte(newstack); + } +} + + +void luaK_reserveregs (FuncState *fs, int n) { + luaK_checkstack(fs, n); + fs->freereg += n; +} + + +static void freereg (FuncState *fs, int reg) { + if (!ISK(reg) && reg >= fs->nactvar) { + fs->freereg--; + lua_assert(reg == fs->freereg); + } +} + + +static void freeexp (FuncState *fs, expdesc *e) { + if (e->k == VNONRELOC) + freereg(fs, e->u.s.info); +} + + +static int addk (FuncState *fs, TValue *k, TValue *v) { + lua_State *L = fs->L; + TValue *idx = luaH_set(L, fs->h, k); + Proto *f = fs->f; + int oldsize = f->sizek; + if (ttisnumber(idx)) { + lua_assert(luaO_rawequalObj(&fs->f->k[cast_int(nvalue(idx))], v)); + return cast_int(nvalue(idx)); + } + else { /* constant not found; create a new entry */ + setnvalue(idx, cast_num(fs->nk)); + luaM_growvector(L, f->k, fs->nk, f->sizek, TValue, + MAXARG_Bx, "constant table overflow"); + while (oldsize < f->sizek) setnilvalue(&f->k[oldsize++]); + setobj(L, &f->k[fs->nk], v); + luaC_barrier(L, f, v); + return fs->nk++; + } +} + + +int luaK_stringK (FuncState *fs, TString *s) { + TValue o; + setsvalue(fs->L, &o, s); + return addk(fs, &o, &o); +} + + +int luaK_numberK (FuncState *fs, lua_Number r) { + TValue o; + setnvalue(&o, r); + return addk(fs, &o, &o); +} + + +static int boolK (FuncState *fs, int b) { + TValue o; + setbvalue(&o, b); + return addk(fs, &o, &o); +} + + +static int nilK (FuncState *fs) { + TValue k, v; + setnilvalue(&v); + /* cannot use nil as key; instead use table itself to represent nil */ + sethvalue(fs->L, &k, fs->h); + return addk(fs, &k, &v); +} + + +void luaK_setreturns (FuncState *fs, expdesc *e, int nresults) { + if (e->k == VCALL) { /* expression is an open function call? */ + SETARG_C(getcode(fs, e), nresults+1); + } + else if (e->k == VVARARG) { + SETARG_B(getcode(fs, e), nresults+1); + SETARG_A(getcode(fs, e), fs->freereg); + luaK_reserveregs(fs, 1); + } +} + + +void luaK_setoneret (FuncState *fs, expdesc *e) { + if (e->k == VCALL) { /* expression is an open function call? */ + e->k = VNONRELOC; + e->u.s.info = GETARG_A(getcode(fs, e)); + } + else if (e->k == VVARARG) { + SETARG_B(getcode(fs, e), 2); + e->k = VRELOCABLE; /* can relocate its simple result */ + } +} + + +void luaK_dischargevars (FuncState *fs, expdesc *e) { + switch (e->k) { + case VLOCAL: { + e->k = VNONRELOC; + break; + } + case VUPVAL: { + e->u.s.info = luaK_codeABC(fs, OP_GETUPVAL, 0, e->u.s.info, 0); + e->k = VRELOCABLE; + break; + } + case VGLOBAL: { + e->u.s.info = luaK_codeABx(fs, OP_GETGLOBAL, 0, e->u.s.info); + e->k = VRELOCABLE; + break; + } + case VINDEXED: { + freereg(fs, e->u.s.aux); + freereg(fs, e->u.s.info); + e->u.s.info = luaK_codeABC(fs, OP_GETTABLE, 0, e->u.s.info, e->u.s.aux); + e->k = VRELOCABLE; + break; + } + case VVARARG: + case VCALL: { + luaK_setoneret(fs, e); + break; + } + default: break; /* there is one value available (somewhere) */ + } +} + + +static int code_label (FuncState *fs, int A, int b, int jump) { + luaK_getlabel(fs); /* those instructions may be jump targets */ + return luaK_codeABC(fs, OP_LOADBOOL, A, b, jump); +} + + +static void discharge2reg (FuncState *fs, expdesc *e, int reg) { + luaK_dischargevars(fs, e); + switch (e->k) { + case VNIL: { + luaK_nil(fs, reg, 1); + break; + } + case VFALSE: case VTRUE: { + luaK_codeABC(fs, OP_LOADBOOL, reg, e->k == VTRUE, 0); + break; + } + case VK: { + luaK_codeABx(fs, OP_LOADK, reg, e->u.s.info); + break; + } + case VKNUM: { + luaK_codeABx(fs, OP_LOADK, reg, luaK_numberK(fs, e->u.nval)); + break; + } + case VRELOCABLE: { + Instruction *pc = &getcode(fs, e); + SETARG_A(*pc, reg); + break; + } + case VNONRELOC: { + if (reg != e->u.s.info) + luaK_codeABC(fs, OP_MOVE, reg, e->u.s.info, 0); + break; + } + default: { + lua_assert(e->k == VVOID || e->k == VJMP); + return; /* nothing to do... */ + } + } + e->u.s.info = reg; + e->k = VNONRELOC; +} + + +static void discharge2anyreg (FuncState *fs, expdesc *e) { + if (e->k != VNONRELOC) { + luaK_reserveregs(fs, 1); + discharge2reg(fs, e, fs->freereg-1); + } +} + + +static void exp2reg (FuncState *fs, expdesc *e, int reg) { + discharge2reg(fs, e, reg); + if (e->k == VJMP) + luaK_concat(fs, &e->t, e->u.s.info); /* put this jump in `t' list */ + if (hasjumps(e)) { + int final; /* position after whole expression */ + int p_f = NO_JUMP; /* position of an eventual LOAD false */ + int p_t = NO_JUMP; /* position of an eventual LOAD true */ + if (need_value(fs, e->t) || need_value(fs, e->f)) { + int fj = (e->k == VJMP) ? NO_JUMP : luaK_jump(fs); + p_f = code_label(fs, reg, 0, 1); + p_t = code_label(fs, reg, 1, 0); + luaK_patchtohere(fs, fj); + } + final = luaK_getlabel(fs); + patchlistaux(fs, e->f, final, reg, p_f); + patchlistaux(fs, e->t, final, reg, p_t); + } + e->f = e->t = NO_JUMP; + e->u.s.info = reg; + e->k = VNONRELOC; +} + + +void luaK_exp2nextreg (FuncState *fs, expdesc *e) { + luaK_dischargevars(fs, e); + freeexp(fs, e); + luaK_reserveregs(fs, 1); + exp2reg(fs, e, fs->freereg - 1); +} + + +int luaK_exp2anyreg (FuncState *fs, expdesc *e) { + luaK_dischargevars(fs, e); + if (e->k == VNONRELOC) { + if (!hasjumps(e)) return e->u.s.info; /* exp is already in a register */ + if (e->u.s.info >= fs->nactvar) { /* reg. is not a local? */ + exp2reg(fs, e, e->u.s.info); /* put value on it */ + return e->u.s.info; + } + } + luaK_exp2nextreg(fs, e); /* default */ + return e->u.s.info; +} + + +void luaK_exp2val (FuncState *fs, expdesc *e) { + if (hasjumps(e)) + luaK_exp2anyreg(fs, e); + else + luaK_dischargevars(fs, e); +} + + +int luaK_exp2RK (FuncState *fs, expdesc *e) { + luaK_exp2val(fs, e); + switch (e->k) { + case VKNUM: + case VTRUE: + case VFALSE: + case VNIL: { + if (fs->nk <= MAXINDEXRK) { /* constant fit in RK operand? */ + e->u.s.info = (e->k == VNIL) ? nilK(fs) : + (e->k == VKNUM) ? luaK_numberK(fs, e->u.nval) : + boolK(fs, (e->k == VTRUE)); + e->k = VK; + return RKASK(e->u.s.info); + } + else break; + } + case VK: { + if (e->u.s.info <= MAXINDEXRK) /* constant fit in argC? */ + return RKASK(e->u.s.info); + else break; + } + default: break; + } + /* not a constant in the right range: put it in a register */ + return luaK_exp2anyreg(fs, e); +} + + +void luaK_storevar (FuncState *fs, expdesc *var, expdesc *ex) { + switch (var->k) { + case VLOCAL: { + freeexp(fs, ex); + exp2reg(fs, ex, var->u.s.info); + return; + } + case VUPVAL: { + int e = luaK_exp2anyreg(fs, ex); + luaK_codeABC(fs, OP_SETUPVAL, e, var->u.s.info, 0); + break; + } + case VGLOBAL: { + int e = luaK_exp2anyreg(fs, ex); + luaK_codeABx(fs, OP_SETGLOBAL, e, var->u.s.info); + break; + } + case VINDEXED: { + int e = luaK_exp2RK(fs, ex); + luaK_codeABC(fs, OP_SETTABLE, var->u.s.info, var->u.s.aux, e); + break; + } + default: { + lua_assert(0); /* invalid var kind to store */ + break; + } + } + freeexp(fs, ex); +} + + +void luaK_self (FuncState *fs, expdesc *e, expdesc *key) { + int func; + luaK_exp2anyreg(fs, e); + freeexp(fs, e); + func = fs->freereg; + luaK_reserveregs(fs, 2); + luaK_codeABC(fs, OP_SELF, func, e->u.s.info, luaK_exp2RK(fs, key)); + freeexp(fs, key); + e->u.s.info = func; + e->k = VNONRELOC; +} + + +static void invertjump (FuncState *fs, expdesc *e) { + Instruction *pc = getjumpcontrol(fs, e->u.s.info); + lua_assert(testTMode(GET_OPCODE(*pc)) && GET_OPCODE(*pc) != OP_TESTSET && + GET_OPCODE(*pc) != OP_TEST); + SETARG_A(*pc, !(GETARG_A(*pc))); +} + + +static int jumponcond (FuncState *fs, expdesc *e, int cond) { + if (e->k == VRELOCABLE) { + Instruction ie = getcode(fs, e); + if (GET_OPCODE(ie) == OP_NOT) { + fs->pc--; /* remove previous OP_NOT */ + return condjump(fs, OP_TEST, GETARG_B(ie), 0, !cond); + } + /* else go through */ + } + discharge2anyreg(fs, e); + freeexp(fs, e); + return condjump(fs, OP_TESTSET, NO_REG, e->u.s.info, cond); +} + + +void luaK_goiftrue (FuncState *fs, expdesc *e) { + int pc; /* pc of last jump */ + luaK_dischargevars(fs, e); + switch (e->k) { + case VK: case VKNUM: case VTRUE: { + pc = NO_JUMP; /* always true; do nothing */ + break; + } + case VFALSE: { + pc = luaK_jump(fs); /* always jump */ + break; + } + case VJMP: { + invertjump(fs, e); + pc = e->u.s.info; + break; + } + default: { + pc = jumponcond(fs, e, 0); + break; + } + } + luaK_concat(fs, &e->f, pc); /* insert last jump in `f' list */ + luaK_patchtohere(fs, e->t); + e->t = NO_JUMP; +} + + +static void luaK_goiffalse (FuncState *fs, expdesc *e) { + int pc; /* pc of last jump */ + luaK_dischargevars(fs, e); + switch (e->k) { + case VNIL: case VFALSE: { + pc = NO_JUMP; /* always false; do nothing */ + break; + } + case VTRUE: { + pc = luaK_jump(fs); /* always jump */ + break; + } + case VJMP: { + pc = e->u.s.info; + break; + } + default: { + pc = jumponcond(fs, e, 1); + break; + } + } + luaK_concat(fs, &e->t, pc); /* insert last jump in `t' list */ + luaK_patchtohere(fs, e->f); + e->f = NO_JUMP; +} + + +static void codenot (FuncState *fs, expdesc *e) { + luaK_dischargevars(fs, e); + switch (e->k) { + case VNIL: case VFALSE: { + e->k = VTRUE; + break; + } + case VK: case VKNUM: case VTRUE: { + e->k = VFALSE; + break; + } + case VJMP: { + invertjump(fs, e); + break; + } + case VRELOCABLE: + case VNONRELOC: { + discharge2anyreg(fs, e); + freeexp(fs, e); + e->u.s.info = luaK_codeABC(fs, OP_NOT, 0, e->u.s.info, 0); + e->k = VRELOCABLE; + break; + } + default: { + lua_assert(0); /* cannot happen */ + break; + } + } + /* interchange true and false lists */ + { int temp = e->f; e->f = e->t; e->t = temp; } + removevalues(fs, e->f); + removevalues(fs, e->t); +} + + +void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) { + t->u.s.aux = luaK_exp2RK(fs, k); + t->k = VINDEXED; +} + + +static int constfolding (OpCode op, expdesc *e1, expdesc *e2) { + lua_Number v1, v2, r; + if (!isnumeral(e1) || !isnumeral(e2)) return 0; + v1 = e1->u.nval; + v2 = e2->u.nval; + switch (op) { + case OP_ADD: r = luai_numadd(v1, v2); break; + case OP_SUB: r = luai_numsub(v1, v2); break; + case OP_MUL: r = luai_nummul(v1, v2); break; + case OP_DIV: + if (v2 == 0) return 0; /* do not attempt to divide by 0 */ + r = luai_numdiv(v1, v2); break; + case OP_MOD: + if (v2 == 0) return 0; /* do not attempt to divide by 0 */ + r = luai_nummod(v1, v2); break; + case OP_POW: r = luai_numpow(v1, v2); break; + case OP_UNM: r = luai_numunm(v1); break; + case OP_LEN: return 0; /* no constant folding for 'len' */ + default: lua_assert(0); r = 0; break; + } + if (luai_numisnan(r)) return 0; /* do not attempt to produce NaN */ + e1->u.nval = r; + return 1; +} + + +static void codearith (FuncState *fs, OpCode op, expdesc *e1, expdesc *e2) { + if (constfolding(op, e1, e2)) + return; + else { + int o2 = (op != OP_UNM && op != OP_LEN) ? luaK_exp2RK(fs, e2) : 0; + int o1 = luaK_exp2RK(fs, e1); + if (o1 > o2) { + freeexp(fs, e1); + freeexp(fs, e2); + } + else { + freeexp(fs, e2); + freeexp(fs, e1); + } + e1->u.s.info = luaK_codeABC(fs, op, 0, o1, o2); + e1->k = VRELOCABLE; + } +} + + +static void codecomp (FuncState *fs, OpCode op, int cond, expdesc *e1, + expdesc *e2) { + int o1 = luaK_exp2RK(fs, e1); + int o2 = luaK_exp2RK(fs, e2); + freeexp(fs, e2); + freeexp(fs, e1); + if (cond == 0 && op != OP_EQ) { + int temp; /* exchange args to replace by `<' or `<=' */ + temp = o1; o1 = o2; o2 = temp; /* o1 <==> o2 */ + cond = 1; + } + e1->u.s.info = condjump(fs, op, cond, o1, o2); + e1->k = VJMP; +} + + +void luaK_prefix (FuncState *fs, UnOpr op, expdesc *e) { + expdesc e2; + e2.t = e2.f = NO_JUMP; e2.k = VKNUM; e2.u.nval = 0; + switch (op) { + case OPR_MINUS: { + if (!isnumeral(e)) + luaK_exp2anyreg(fs, e); /* cannot operate on non-numeric constants */ + codearith(fs, OP_UNM, e, &e2); + break; + } + case OPR_NOT: codenot(fs, e); break; + case OPR_LEN: { + luaK_exp2anyreg(fs, e); /* cannot operate on constants */ + codearith(fs, OP_LEN, e, &e2); + break; + } + default: lua_assert(0); + } +} + + +void luaK_infix (FuncState *fs, BinOpr op, expdesc *v) { + switch (op) { + case OPR_AND: { + luaK_goiftrue(fs, v); + break; + } + case OPR_OR: { + luaK_goiffalse(fs, v); + break; + } + case OPR_CONCAT: { + luaK_exp2nextreg(fs, v); /* operand must be on the `stack' */ + break; + } + case OPR_ADD: case OPR_SUB: case OPR_MUL: case OPR_DIV: + case OPR_MOD: case OPR_POW: { + if (!isnumeral(v)) luaK_exp2RK(fs, v); + break; + } + default: { + luaK_exp2RK(fs, v); + break; + } + } +} + + +void luaK_posfix (FuncState *fs, BinOpr op, expdesc *e1, expdesc *e2) { + switch (op) { + case OPR_AND: { + lua_assert(e1->t == NO_JUMP); /* list must be closed */ + luaK_dischargevars(fs, e2); + luaK_concat(fs, &e2->f, e1->f); + *e1 = *e2; + break; + } + case OPR_OR: { + lua_assert(e1->f == NO_JUMP); /* list must be closed */ + luaK_dischargevars(fs, e2); + luaK_concat(fs, &e2->t, e1->t); + *e1 = *e2; + break; + } + case OPR_CONCAT: { + luaK_exp2val(fs, e2); + if (e2->k == VRELOCABLE && GET_OPCODE(getcode(fs, e2)) == OP_CONCAT) { + lua_assert(e1->u.s.info == GETARG_B(getcode(fs, e2))-1); + freeexp(fs, e1); + SETARG_B(getcode(fs, e2), e1->u.s.info); + e1->k = VRELOCABLE; e1->u.s.info = e2->u.s.info; + } + else { + luaK_exp2nextreg(fs, e2); /* operand must be on the 'stack' */ + codearith(fs, OP_CONCAT, e1, e2); + } + break; + } + case OPR_ADD: codearith(fs, OP_ADD, e1, e2); break; + case OPR_SUB: codearith(fs, OP_SUB, e1, e2); break; + case OPR_MUL: codearith(fs, OP_MUL, e1, e2); break; + case OPR_DIV: codearith(fs, OP_DIV, e1, e2); break; + case OPR_MOD: codearith(fs, OP_MOD, e1, e2); break; + case OPR_POW: codearith(fs, OP_POW, e1, e2); break; + case OPR_EQ: codecomp(fs, OP_EQ, 1, e1, e2); break; + case OPR_NE: codecomp(fs, OP_EQ, 0, e1, e2); break; + case OPR_LT: codecomp(fs, OP_LT, 1, e1, e2); break; + case OPR_LE: codecomp(fs, OP_LE, 1, e1, e2); break; + case OPR_GT: codecomp(fs, OP_LT, 0, e1, e2); break; + case OPR_GE: codecomp(fs, OP_LE, 0, e1, e2); break; + default: lua_assert(0); + } +} + + +void luaK_fixline (FuncState *fs, int line) { + fs->f->lineinfo[fs->pc - 1] = line; +} + + +static int luaK_code (FuncState *fs, Instruction i, int line) { + Proto *f = fs->f; + dischargejpc(fs); /* `pc' will change */ + /* put new instruction in code array */ + luaM_growvector(fs->L, f->code, fs->pc, f->sizecode, Instruction, + MAX_INT, "code size overflow"); + f->code[fs->pc] = i; + /* save corresponding line information */ + luaM_growvector(fs->L, f->lineinfo, fs->pc, f->sizelineinfo, int, + MAX_INT, "code size overflow"); + f->lineinfo[fs->pc] = line; + return fs->pc++; +} + + +int luaK_codeABC (FuncState *fs, OpCode o, int a, int b, int c) { + lua_assert(getOpMode(o) == iABC); + lua_assert(getBMode(o) != OpArgN || b == 0); + lua_assert(getCMode(o) != OpArgN || c == 0); + return luaK_code(fs, CREATE_ABC(o, a, b, c), fs->ls->lastline); +} + + +int luaK_codeABx (FuncState *fs, OpCode o, int a, unsigned int bc) { + lua_assert(getOpMode(o) == iABx || getOpMode(o) == iAsBx); + lua_assert(getCMode(o) == OpArgN); + return luaK_code(fs, CREATE_ABx(o, a, bc), fs->ls->lastline); +} + + +void luaK_setlist (FuncState *fs, int base, int nelems, int tostore) { + int c = (nelems - 1)/LFIELDS_PER_FLUSH + 1; + int b = (tostore == LUA_MULTRET) ? 0 : tostore; + lua_assert(tostore != 0); + if (c <= MAXARG_C) + luaK_codeABC(fs, OP_SETLIST, base, b, c); + else { + luaK_codeABC(fs, OP_SETLIST, base, b, 0); + luaK_code(fs, cast(Instruction, c), fs->ls->lastline); + } + fs->freereg = base + 1; /* free registers with list values */ +} + diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lcode.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lcode.h new file mode 100644 index 00000000..b941c607 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lcode.h @@ -0,0 +1,76 @@ +/* +** $Id: lcode.h,v 1.48.1.1 2007/12/27 13:02:25 roberto Exp $ +** Code generator for Lua +** See Copyright Notice in lua.h +*/ + +#ifndef lcode_h +#define lcode_h + +#include "llex.h" +#include "lobject.h" +#include "lopcodes.h" +#include "lparser.h" + + +/* +** Marks the end of a patch list. It is an invalid value both as an absolute +** address, and as a list link (would link an element to itself). +*/ +#define NO_JUMP (-1) + + +/* +** grep "ORDER OPR" if you change these enums +*/ +typedef enum BinOpr { + OPR_ADD, OPR_SUB, OPR_MUL, OPR_DIV, OPR_MOD, OPR_POW, + OPR_CONCAT, + OPR_NE, OPR_EQ, + OPR_LT, OPR_LE, OPR_GT, OPR_GE, + OPR_AND, OPR_OR, + OPR_NOBINOPR +} BinOpr; + + +typedef enum UnOpr { OPR_MINUS, OPR_NOT, OPR_LEN, OPR_NOUNOPR } UnOpr; + + +#define getcode(fs,e) ((fs)->f->code[(e)->u.s.info]) + +#define luaK_codeAsBx(fs,o,A,sBx) luaK_codeABx(fs,o,A,(sBx)+MAXARG_sBx) + +#define luaK_setmultret(fs,e) luaK_setreturns(fs, e, LUA_MULTRET) + +LUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx); +LUAI_FUNC int luaK_codeABC (FuncState *fs, OpCode o, int A, int B, int C); +LUAI_FUNC void luaK_fixline (FuncState *fs, int line); +LUAI_FUNC void luaK_nil (FuncState *fs, int from, int n); +LUAI_FUNC void luaK_reserveregs (FuncState *fs, int n); +LUAI_FUNC void luaK_checkstack (FuncState *fs, int n); +LUAI_FUNC int luaK_stringK (FuncState *fs, TString *s); +LUAI_FUNC int luaK_numberK (FuncState *fs, lua_Number r); +LUAI_FUNC void luaK_dischargevars (FuncState *fs, expdesc *e); +LUAI_FUNC int luaK_exp2anyreg (FuncState *fs, expdesc *e); +LUAI_FUNC void luaK_exp2nextreg (FuncState *fs, expdesc *e); +LUAI_FUNC void luaK_exp2val (FuncState *fs, expdesc *e); +LUAI_FUNC int luaK_exp2RK (FuncState *fs, expdesc *e); +LUAI_FUNC void luaK_self (FuncState *fs, expdesc *e, expdesc *key); +LUAI_FUNC void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k); +LUAI_FUNC void luaK_goiftrue (FuncState *fs, expdesc *e); +LUAI_FUNC void luaK_storevar (FuncState *fs, expdesc *var, expdesc *e); +LUAI_FUNC void luaK_setreturns (FuncState *fs, expdesc *e, int nresults); +LUAI_FUNC void luaK_setoneret (FuncState *fs, expdesc *e); +LUAI_FUNC int luaK_jump (FuncState *fs); +LUAI_FUNC void luaK_ret (FuncState *fs, int first, int nret); +LUAI_FUNC void luaK_patchlist (FuncState *fs, int list, int target); +LUAI_FUNC void luaK_patchtohere (FuncState *fs, int list); +LUAI_FUNC void luaK_concat (FuncState *fs, int *l1, int l2); +LUAI_FUNC int luaK_getlabel (FuncState *fs); +LUAI_FUNC void luaK_prefix (FuncState *fs, UnOpr op, expdesc *v); +LUAI_FUNC void luaK_infix (FuncState *fs, BinOpr op, expdesc *v); +LUAI_FUNC void luaK_posfix (FuncState *fs, BinOpr op, expdesc *v1, expdesc *v2); +LUAI_FUNC void luaK_setlist (FuncState *fs, int base, int nelems, int tostore); + + +#endif diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/ldblib.c b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/ldblib.c new file mode 100644 index 00000000..67de1222 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/ldblib.c @@ -0,0 +1,397 @@ +/* +** $Id: ldblib.c,v 1.104.1.3 2008/01/21 13:11:21 roberto Exp $ +** Interface from Lua to its debug API +** See Copyright Notice in lua.h +*/ + + +#include +#include +#include + +#define ldblib_c +#define LUA_LIB + +#include "lua.h" + +#include "lauxlib.h" +#include "lualib.h" + + + +static int db_getregistry (lua_State *L) { + lua_pushvalue(L, LUA_REGISTRYINDEX); + return 1; +} + + +static int db_getmetatable (lua_State *L) { + luaL_checkany(L, 1); + if (!lua_getmetatable(L, 1)) { + lua_pushnil(L); /* no metatable */ + } + return 1; +} + + +static int db_setmetatable (lua_State *L) { + int t = lua_type(L, 2); + luaL_argcheck(L, t == LUA_TNIL || t == LUA_TTABLE, 2, + "nil or table expected"); + lua_settop(L, 2); + lua_pushboolean(L, lua_setmetatable(L, 1)); + return 1; +} + + +static int db_getfenv (lua_State *L) { + lua_getfenv(L, 1); + return 1; +} + + +static int db_setfenv (lua_State *L) { + luaL_checktype(L, 2, LUA_TTABLE); + lua_settop(L, 2); + if (lua_setfenv(L, 1) == 0) + luaL_error(L, LUA_QL("setfenv") + " cannot change environment of given object"); + return 1; +} + + +static void settabss (lua_State *L, const char *i, const char *v) { + lua_pushstring(L, v); + lua_setfield(L, -2, i); +} + + +static void settabsi (lua_State *L, const char *i, int v) { + lua_pushinteger(L, v); + lua_setfield(L, -2, i); +} + + +static lua_State *getthread (lua_State *L, int *arg) { + if (lua_isthread(L, 1)) { + *arg = 1; + return lua_tothread(L, 1); + } + else { + *arg = 0; + return L; + } +} + + +static void treatstackoption (lua_State *L, lua_State *L1, const char *fname) { + if (L == L1) { + lua_pushvalue(L, -2); + lua_remove(L, -3); + } + else + lua_xmove(L1, L, 1); + lua_setfield(L, -2, fname); +} + + +static int db_getinfo (lua_State *L) { + lua_Debug ar; + int arg; + lua_State *L1 = getthread(L, &arg); + const char *options = luaL_optstring(L, arg+2, "flnSu"); + if (lua_isnumber(L, arg+1)) { + if (!lua_getstack(L1, (int)lua_tointeger(L, arg+1), &ar)) { + lua_pushnil(L); /* level out of range */ + return 1; + } + } + else if (lua_isfunction(L, arg+1)) { + lua_pushfstring(L, ">%s", options); + options = lua_tostring(L, -1); + lua_pushvalue(L, arg+1); + lua_xmove(L, L1, 1); + } + else + return luaL_argerror(L, arg+1, "function or level expected"); + if (!lua_getinfo(L1, options, &ar)) + return luaL_argerror(L, arg+2, "invalid option"); + lua_createtable(L, 0, 2); + if (strchr(options, 'S')) { + settabss(L, "source", ar.source); + settabss(L, "short_src", ar.short_src); + settabsi(L, "linedefined", ar.linedefined); + settabsi(L, "lastlinedefined", ar.lastlinedefined); + settabss(L, "what", ar.what); + } + if (strchr(options, 'l')) + settabsi(L, "currentline", ar.currentline); + if (strchr(options, 'u')) + settabsi(L, "nups", ar.nups); + if (strchr(options, 'n')) { + settabss(L, "name", ar.name); + settabss(L, "namewhat", ar.namewhat); + } + if (strchr(options, 'L')) + treatstackoption(L, L1, "activelines"); + if (strchr(options, 'f')) + treatstackoption(L, L1, "func"); + return 1; /* return table */ +} + + +static int db_getlocal (lua_State *L) { + int arg; + lua_State *L1 = getthread(L, &arg); + lua_Debug ar; + const char *name; + if (!lua_getstack(L1, luaL_checkint(L, arg+1), &ar)) /* out of range? */ + return luaL_argerror(L, arg+1, "level out of range"); + name = lua_getlocal(L1, &ar, luaL_checkint(L, arg+2)); + if (name) { + lua_xmove(L1, L, 1); + lua_pushstring(L, name); + lua_pushvalue(L, -2); + return 2; + } + else { + lua_pushnil(L); + return 1; + } +} + + +static int db_setlocal (lua_State *L) { + int arg; + lua_State *L1 = getthread(L, &arg); + lua_Debug ar; + if (!lua_getstack(L1, luaL_checkint(L, arg+1), &ar)) /* out of range? */ + return luaL_argerror(L, arg+1, "level out of range"); + luaL_checkany(L, arg+3); + lua_settop(L, arg+3); + lua_xmove(L, L1, 1); + lua_pushstring(L, lua_setlocal(L1, &ar, luaL_checkint(L, arg+2))); + return 1; +} + + +static int auxupvalue (lua_State *L, int get) { + const char *name; + int n = luaL_checkint(L, 2); + luaL_checktype(L, 1, LUA_TFUNCTION); + if (lua_iscfunction(L, 1)) return 0; /* cannot touch C upvalues from Lua */ + name = get ? lua_getupvalue(L, 1, n) : lua_setupvalue(L, 1, n); + if (name == NULL) return 0; + lua_pushstring(L, name); + lua_insert(L, -(get+1)); + return get + 1; +} + + +static int db_getupvalue (lua_State *L) { + return auxupvalue(L, 1); +} + + +static int db_setupvalue (lua_State *L) { + luaL_checkany(L, 3); + return auxupvalue(L, 0); +} + + + +static const char KEY_HOOK = 'h'; + + +static void hookf (lua_State *L, lua_Debug *ar) { + static const char *const hooknames[] = + {"call", "return", "line", "count", "tail return"}; + lua_pushlightuserdata(L, (void *)&KEY_HOOK); + lua_rawget(L, LUA_REGISTRYINDEX); + lua_pushlightuserdata(L, L); + lua_rawget(L, -2); + if (lua_isfunction(L, -1)) { + lua_pushstring(L, hooknames[(int)ar->event]); + if (ar->currentline >= 0) + lua_pushinteger(L, ar->currentline); + else lua_pushnil(L); + lua_assert(lua_getinfo(L, "lS", ar)); + lua_call(L, 2, 0); + } +} + + +static int makemask (const char *smask, int count) { + int mask = 0; + if (strchr(smask, 'c')) mask |= LUA_MASKCALL; + if (strchr(smask, 'r')) mask |= LUA_MASKRET; + if (strchr(smask, 'l')) mask |= LUA_MASKLINE; + if (count > 0) mask |= LUA_MASKCOUNT; + return mask; +} + + +static char *unmakemask (int mask, char *smask) { + int i = 0; + if (mask & LUA_MASKCALL) smask[i++] = 'c'; + if (mask & LUA_MASKRET) smask[i++] = 'r'; + if (mask & LUA_MASKLINE) smask[i++] = 'l'; + smask[i] = '\0'; + return smask; +} + + +static void gethooktable (lua_State *L) { + lua_pushlightuserdata(L, (void *)&KEY_HOOK); + lua_rawget(L, LUA_REGISTRYINDEX); + if (!lua_istable(L, -1)) { + lua_pop(L, 1); + lua_createtable(L, 0, 1); + lua_pushlightuserdata(L, (void *)&KEY_HOOK); + lua_pushvalue(L, -2); + lua_rawset(L, LUA_REGISTRYINDEX); + } +} + + +static int db_sethook (lua_State *L) { + int arg, mask, count; + lua_Hook func; + lua_State *L1 = getthread(L, &arg); + if (lua_isnoneornil(L, arg+1)) { + lua_settop(L, arg+1); + func = NULL; mask = 0; count = 0; /* turn off hooks */ + } + else { + const char *smask = luaL_checkstring(L, arg+2); + luaL_checktype(L, arg+1, LUA_TFUNCTION); + count = luaL_optint(L, arg+3, 0); + func = hookf; mask = makemask(smask, count); + } + gethooktable(L); + lua_pushlightuserdata(L, L1); + lua_pushvalue(L, arg+1); + lua_rawset(L, -3); /* set new hook */ + lua_pop(L, 1); /* remove hook table */ + lua_sethook(L1, func, mask, count); /* set hooks */ + return 0; +} + + +static int db_gethook (lua_State *L) { + int arg; + lua_State *L1 = getthread(L, &arg); + char buff[5]; + int mask = lua_gethookmask(L1); + lua_Hook hook = lua_gethook(L1); + if (hook != NULL && hook != hookf) /* external hook? */ + lua_pushliteral(L, "external hook"); + else { + gethooktable(L); + lua_pushlightuserdata(L, L1); + lua_rawget(L, -2); /* get hook */ + lua_remove(L, -2); /* remove hook table */ + } + lua_pushstring(L, unmakemask(mask, buff)); + lua_pushinteger(L, lua_gethookcount(L1)); + return 3; +} + + +static int db_debug (lua_State *L) { + for (;;) { + char buffer[250]; + fputs("lua_debug> ", stderr); + if (fgets(buffer, sizeof(buffer), stdin) == 0 || + strcmp(buffer, "cont\n") == 0) + return 0; + if (luaL_loadbuffer(L, buffer, strlen(buffer), "=(debug command)") || + lua_pcall(L, 0, 0, 0)) { + fputs(lua_tostring(L, -1), stderr); + fputs("\n", stderr); + } + lua_settop(L, 0); /* remove eventual returns */ + } +} + + +#define LEVELS1 12 /* size of the first part of the stack */ +#define LEVELS2 10 /* size of the second part of the stack */ + +static int db_errorfb (lua_State *L) { + int level; + int firstpart = 1; /* still before eventual `...' */ + int arg; + lua_State *L1 = getthread(L, &arg); + lua_Debug ar; + if (lua_isnumber(L, arg+2)) { + level = (int)lua_tointeger(L, arg+2); + lua_pop(L, 1); + } + else + level = (L == L1) ? 1 : 0; /* level 0 may be this own function */ + if (lua_gettop(L) == arg) + lua_pushliteral(L, ""); + else if (!lua_isstring(L, arg+1)) return 1; /* message is not a string */ + else lua_pushliteral(L, "\n"); + lua_pushliteral(L, "stack traceback:"); + while (lua_getstack(L1, level++, &ar)) { + if (level > LEVELS1 && firstpart) { + /* no more than `LEVELS2' more levels? */ + if (!lua_getstack(L1, level+LEVELS2, &ar)) + level--; /* keep going */ + else { + lua_pushliteral(L, "\n\t..."); /* too many levels */ + while (lua_getstack(L1, level+LEVELS2, &ar)) /* find last levels */ + level++; + } + firstpart = 0; + continue; + } + lua_pushliteral(L, "\n\t"); + lua_getinfo(L1, "Snl", &ar); + lua_pushfstring(L, "%s:", ar.short_src); + if (ar.currentline > 0) + lua_pushfstring(L, "%d:", ar.currentline); + if (*ar.namewhat != '\0') /* is there a name? */ + lua_pushfstring(L, " in function " LUA_QS, ar.name); + else { + if (*ar.what == 'm') /* main? */ + lua_pushfstring(L, " in main chunk"); + else if (*ar.what == 'C' || *ar.what == 't') + lua_pushliteral(L, " ?"); /* C function or tail call */ + else + lua_pushfstring(L, " in function <%s:%d>", + ar.short_src, ar.linedefined); + } + lua_concat(L, lua_gettop(L) - arg); + } + lua_concat(L, lua_gettop(L) - arg); + return 1; +} + + +static const luaL_Reg dblib[] = { + {"debug", db_debug}, + {"getfenv", db_getfenv}, + {"gethook", db_gethook}, + {"getinfo", db_getinfo}, + {"getlocal", db_getlocal}, + {"getregistry", db_getregistry}, + {"getmetatable", db_getmetatable}, + {"getupvalue", db_getupvalue}, + {"setfenv", db_setfenv}, + {"sethook", db_sethook}, + {"setlocal", db_setlocal}, + {"setmetatable", db_setmetatable}, + {"setupvalue", db_setupvalue}, + {"traceback", db_errorfb}, + {NULL, NULL} +}; + + +LUALIB_API int luaopen_debug (lua_State *L) { + luaL_register(L, LUA_DBLIBNAME, dblib); + return 1; +} + diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/ldebug.c b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/ldebug.c new file mode 100644 index 00000000..50ad3d38 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/ldebug.c @@ -0,0 +1,638 @@ +/* +** $Id: ldebug.c,v 2.29.1.6 2008/05/08 16:56:26 roberto Exp $ +** Debug Interface +** See Copyright Notice in lua.h +*/ + + +#include +#include +#include + + +#define ldebug_c +#define LUA_CORE + +#include "lua.h" + +#include "lapi.h" +#include "lcode.h" +#include "ldebug.h" +#include "ldo.h" +#include "lfunc.h" +#include "lobject.h" +#include "lopcodes.h" +#include "lstate.h" +#include "lstring.h" +#include "ltable.h" +#include "ltm.h" +#include "lvm.h" + + + +static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name); + + +static int currentpc (lua_State *L, CallInfo *ci) { + if (!isLua(ci)) return -1; /* function is not a Lua function? */ + if (ci == L->ci) + ci->savedpc = L->savedpc; + return pcRel(ci->savedpc, ci_func(ci)->l.p); +} + + +static int currentline (lua_State *L, CallInfo *ci) { + int pc = currentpc(L, ci); + if (pc < 0) + return -1; /* only active lua functions have current-line information */ + else + return getline(ci_func(ci)->l.p, pc); +} + + +/* +** this function can be called asynchronous (e.g. during a signal) +*/ +LUA_API int lua_sethook (lua_State *L, lua_Hook func, int mask, int count) { + if (func == NULL || mask == 0) { /* turn off hooks? */ + mask = 0; + func = NULL; + } + L->hook = func; + L->basehookcount = count; + resethookcount(L); + L->hookmask = cast_byte(mask); + return 1; +} + + +LUA_API lua_Hook lua_gethook (lua_State *L) { + return L->hook; +} + + +LUA_API int lua_gethookmask (lua_State *L) { + return L->hookmask; +} + + +LUA_API int lua_gethookcount (lua_State *L) { + return L->basehookcount; +} + + +LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar) { + int status; + CallInfo *ci; + lua_lock(L); + for (ci = L->ci; level > 0 && ci > L->base_ci; ci--) { + level--; + if (f_isLua(ci)) /* Lua function? */ + level -= ci->tailcalls; /* skip lost tail calls */ + } + if (level == 0 && ci > L->base_ci) { /* level found? */ + status = 1; + ar->i_ci = cast_int(ci - L->base_ci); + } + else if (level < 0) { /* level is of a lost tail call? */ + status = 1; + ar->i_ci = 0; + } + else status = 0; /* no such level */ + lua_unlock(L); + return status; +} + + +static Proto *getluaproto (CallInfo *ci) { + return (isLua(ci) ? ci_func(ci)->l.p : NULL); +} + + +static const char *findlocal (lua_State *L, CallInfo *ci, int n) { + const char *name; + Proto *fp = getluaproto(ci); + if (fp && (name = luaF_getlocalname(fp, n, currentpc(L, ci))) != NULL) + return name; /* is a local variable in a Lua function */ + else { + StkId limit = (ci == L->ci) ? L->top : (ci+1)->func; + if (limit - ci->base >= n && n > 0) /* is 'n' inside 'ci' stack? */ + return "(*temporary)"; + else + return NULL; + } +} + + +LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) { + CallInfo *ci = L->base_ci + ar->i_ci; + const char *name = findlocal(L, ci, n); + lua_lock(L); + if (name) + luaA_pushobject(L, ci->base + (n - 1)); + lua_unlock(L); + return name; +} + + +LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) { + CallInfo *ci = L->base_ci + ar->i_ci; + const char *name = findlocal(L, ci, n); + lua_lock(L); + if (name) + setobjs2s(L, ci->base + (n - 1), L->top - 1); + L->top--; /* pop value */ + lua_unlock(L); + return name; +} + + +static void funcinfo (lua_Debug *ar, Closure *cl) { + if (cl->c.isC) { + ar->source = "=[C]"; + ar->linedefined = -1; + ar->lastlinedefined = -1; + ar->what = "C"; + } + else { + ar->source = getstr(cl->l.p->source); + ar->linedefined = cl->l.p->linedefined; + ar->lastlinedefined = cl->l.p->lastlinedefined; + ar->what = (ar->linedefined == 0) ? "main" : "Lua"; + } + luaO_chunkid(ar->short_src, ar->source, LUA_IDSIZE); +} + + +static void info_tailcall (lua_Debug *ar) { + ar->name = ar->namewhat = ""; + ar->what = "tail"; + ar->lastlinedefined = ar->linedefined = ar->currentline = -1; + ar->source = "=(tail call)"; + luaO_chunkid(ar->short_src, ar->source, LUA_IDSIZE); + ar->nups = 0; +} + + +static void collectvalidlines (lua_State *L, Closure *f) { + if (f == NULL || f->c.isC) { + setnilvalue(L->top); + } + else { + Table *t = luaH_new(L, 0, 0); + int *lineinfo = f->l.p->lineinfo; + int i; + for (i=0; il.p->sizelineinfo; i++) + setbvalue(luaH_setnum(L, t, lineinfo[i]), 1); + sethvalue(L, L->top, t); + } + incr_top(L); +} + + +static int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar, + Closure *f, CallInfo *ci) { + int status = 1; + if (f == NULL) { + info_tailcall(ar); + return status; + } + for (; *what; what++) { + switch (*what) { + case 'S': { + funcinfo(ar, f); + break; + } + case 'l': { + ar->currentline = (ci) ? currentline(L, ci) : -1; + break; + } + case 'u': { + ar->nups = f->c.nupvalues; + break; + } + case 'n': { + ar->namewhat = (ci) ? getfuncname(L, ci, &ar->name) : NULL; + if (ar->namewhat == NULL) { + ar->namewhat = ""; /* not found */ + ar->name = NULL; + } + break; + } + case 'L': + case 'f': /* handled by lua_getinfo */ + break; + default: status = 0; /* invalid option */ + } + } + return status; +} + + +LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) { + int status; + Closure *f = NULL; + CallInfo *ci = NULL; + lua_lock(L); + if (*what == '>') { + StkId func = L->top - 1; + luai_apicheck(L, ttisfunction(func)); + what++; /* skip the '>' */ + f = clvalue(func); + L->top--; /* pop function */ + } + else if (ar->i_ci != 0) { /* no tail call? */ + ci = L->base_ci + ar->i_ci; + lua_assert(ttisfunction(ci->func)); + f = clvalue(ci->func); + } + status = auxgetinfo(L, what, ar, f, ci); + if (strchr(what, 'f')) { + if (f == NULL) setnilvalue(L->top); + else setclvalue(L, L->top, f); + incr_top(L); + } + if (strchr(what, 'L')) + collectvalidlines(L, f); + lua_unlock(L); + return status; +} + + +/* +** {====================================================== +** Symbolic Execution and code checker +** ======================================================= +*/ + +#define check(x) if (!(x)) return 0; + +#define checkjump(pt,pc) check(0 <= pc && pc < pt->sizecode) + +#define checkreg(pt,reg) check((reg) < (pt)->maxstacksize) + + + +static int precheck (const Proto *pt) { + check(pt->maxstacksize <= MAXSTACK); + check(pt->numparams+(pt->is_vararg & VARARG_HASARG) <= pt->maxstacksize); + check(!(pt->is_vararg & VARARG_NEEDSARG) || + (pt->is_vararg & VARARG_HASARG)); + check(pt->sizeupvalues <= pt->nups); + check(pt->sizelineinfo == pt->sizecode || pt->sizelineinfo == 0); + check(pt->sizecode > 0 && GET_OPCODE(pt->code[pt->sizecode-1]) == OP_RETURN); + return 1; +} + + +#define checkopenop(pt,pc) luaG_checkopenop((pt)->code[(pc)+1]) + +int luaG_checkopenop (Instruction i) { + switch (GET_OPCODE(i)) { + case OP_CALL: + case OP_TAILCALL: + case OP_RETURN: + case OP_SETLIST: { + check(GETARG_B(i) == 0); + return 1; + } + default: return 0; /* invalid instruction after an open call */ + } +} + + +static int checkArgMode (const Proto *pt, int r, enum OpArgMask mode) { + switch (mode) { + case OpArgN: check(r == 0); break; + case OpArgU: break; + case OpArgR: checkreg(pt, r); break; + case OpArgK: + check(ISK(r) ? INDEXK(r) < pt->sizek : r < pt->maxstacksize); + break; + } + return 1; +} + + +static Instruction symbexec (const Proto *pt, int lastpc, int reg) { + int pc; + int last; /* stores position of last instruction that changed `reg' */ + last = pt->sizecode-1; /* points to final return (a `neutral' instruction) */ + check(precheck(pt)); + for (pc = 0; pc < lastpc; pc++) { + Instruction i = pt->code[pc]; + OpCode op = GET_OPCODE(i); + int a = GETARG_A(i); + int b = 0; + int c = 0; + check(op < NUM_OPCODES); + checkreg(pt, a); + switch (getOpMode(op)) { + case iABC: { + b = GETARG_B(i); + c = GETARG_C(i); + check(checkArgMode(pt, b, getBMode(op))); + check(checkArgMode(pt, c, getCMode(op))); + break; + } + case iABx: { + b = GETARG_Bx(i); + if (getBMode(op) == OpArgK) check(b < pt->sizek); + break; + } + case iAsBx: { + b = GETARG_sBx(i); + if (getBMode(op) == OpArgR) { + int dest = pc+1+b; + check(0 <= dest && dest < pt->sizecode); + if (dest > 0) { + int j; + /* check that it does not jump to a setlist count; this + is tricky, because the count from a previous setlist may + have the same value of an invalid setlist; so, we must + go all the way back to the first of them (if any) */ + for (j = 0; j < dest; j++) { + Instruction d = pt->code[dest-1-j]; + if (!(GET_OPCODE(d) == OP_SETLIST && GETARG_C(d) == 0)) break; + } + /* if 'j' is even, previous value is not a setlist (even if + it looks like one) */ + check((j&1) == 0); + } + } + break; + } + } + if (testAMode(op)) { + if (a == reg) last = pc; /* change register `a' */ + } + if (testTMode(op)) { + check(pc+2 < pt->sizecode); /* check skip */ + check(GET_OPCODE(pt->code[pc+1]) == OP_JMP); + } + switch (op) { + case OP_LOADBOOL: { + if (c == 1) { /* does it jump? */ + check(pc+2 < pt->sizecode); /* check its jump */ + check(GET_OPCODE(pt->code[pc+1]) != OP_SETLIST || + GETARG_C(pt->code[pc+1]) != 0); + } + break; + } + case OP_LOADNIL: { + if (a <= reg && reg <= b) + last = pc; /* set registers from `a' to `b' */ + break; + } + case OP_GETUPVAL: + case OP_SETUPVAL: { + check(b < pt->nups); + break; + } + case OP_GETGLOBAL: + case OP_SETGLOBAL: { + check(ttisstring(&pt->k[b])); + break; + } + case OP_SELF: { + checkreg(pt, a+1); + if (reg == a+1) last = pc; + break; + } + case OP_CONCAT: { + check(b < c); /* at least two operands */ + break; + } + case OP_TFORLOOP: { + check(c >= 1); /* at least one result (control variable) */ + checkreg(pt, a+2+c); /* space for results */ + if (reg >= a+2) last = pc; /* affect all regs above its base */ + break; + } + case OP_FORLOOP: + case OP_FORPREP: + checkreg(pt, a+3); + /* go through */ + case OP_JMP: { + int dest = pc+1+b; + /* not full check and jump is forward and do not skip `lastpc'? */ + if (reg != NO_REG && pc < dest && dest <= lastpc) + pc += b; /* do the jump */ + break; + } + case OP_CALL: + case OP_TAILCALL: { + if (b != 0) { + checkreg(pt, a+b-1); + } + c--; /* c = num. returns */ + if (c == LUA_MULTRET) { + check(checkopenop(pt, pc)); + } + else if (c != 0) + checkreg(pt, a+c-1); + if (reg >= a) last = pc; /* affect all registers above base */ + break; + } + case OP_RETURN: { + b--; /* b = num. returns */ + if (b > 0) checkreg(pt, a+b-1); + break; + } + case OP_SETLIST: { + if (b > 0) checkreg(pt, a + b); + if (c == 0) { + pc++; + check(pc < pt->sizecode - 1); + } + break; + } + case OP_CLOSURE: { + int nup, j; + check(b < pt->sizep); + nup = pt->p[b]->nups; + check(pc + nup < pt->sizecode); + for (j = 1; j <= nup; j++) { + OpCode op1 = GET_OPCODE(pt->code[pc + j]); + check(op1 == OP_GETUPVAL || op1 == OP_MOVE); + } + if (reg != NO_REG) /* tracing? */ + pc += nup; /* do not 'execute' these pseudo-instructions */ + break; + } + case OP_VARARG: { + check((pt->is_vararg & VARARG_ISVARARG) && + !(pt->is_vararg & VARARG_NEEDSARG)); + b--; + if (b == LUA_MULTRET) check(checkopenop(pt, pc)); + checkreg(pt, a+b-1); + break; + } + default: break; + } + } + return pt->code[last]; +} + +#undef check +#undef checkjump +#undef checkreg + +/* }====================================================== */ + + +int luaG_checkcode (const Proto *pt) { + return (symbexec(pt, pt->sizecode, NO_REG) != 0); +} + + +static const char *kname (Proto *p, int c) { + if (ISK(c) && ttisstring(&p->k[INDEXK(c)])) + return svalue(&p->k[INDEXK(c)]); + else + return "?"; +} + + +static const char *getobjname (lua_State *L, CallInfo *ci, int stackpos, + const char **name) { + if (isLua(ci)) { /* a Lua function? */ + Proto *p = ci_func(ci)->l.p; + int pc = currentpc(L, ci); + Instruction i; + *name = luaF_getlocalname(p, stackpos+1, pc); + if (*name) /* is a local? */ + return "local"; + i = symbexec(p, pc, stackpos); /* try symbolic execution */ + lua_assert(pc != -1); + switch (GET_OPCODE(i)) { + case OP_GETGLOBAL: { + int g = GETARG_Bx(i); /* global index */ + lua_assert(ttisstring(&p->k[g])); + *name = svalue(&p->k[g]); + return "global"; + } + case OP_MOVE: { + int a = GETARG_A(i); + int b = GETARG_B(i); /* move from `b' to `a' */ + if (b < a) + return getobjname(L, ci, b, name); /* get name for `b' */ + break; + } + case OP_GETTABLE: { + int k = GETARG_C(i); /* key index */ + *name = kname(p, k); + return "field"; + } + case OP_GETUPVAL: { + int u = GETARG_B(i); /* upvalue index */ + *name = p->upvalues ? getstr(p->upvalues[u]) : "?"; + return "upvalue"; + } + case OP_SELF: { + int k = GETARG_C(i); /* key index */ + *name = kname(p, k); + return "method"; + } + default: break; + } + } + return NULL; /* no useful name found */ +} + + +static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name) { + Instruction i; + if ((isLua(ci) && ci->tailcalls > 0) || !isLua(ci - 1)) + return NULL; /* calling function is not Lua (or is unknown) */ + ci--; /* calling function */ + i = ci_func(ci)->l.p->code[currentpc(L, ci)]; + if (GET_OPCODE(i) == OP_CALL || GET_OPCODE(i) == OP_TAILCALL || + GET_OPCODE(i) == OP_TFORLOOP) + return getobjname(L, ci, GETARG_A(i), name); + else + return NULL; /* no useful name can be found */ +} + + +/* only ANSI way to check whether a pointer points to an array */ +static int isinstack (CallInfo *ci, const TValue *o) { + StkId p; + for (p = ci->base; p < ci->top; p++) + if (o == p) return 1; + return 0; +} + + +void luaG_typeerror (lua_State *L, const TValue *o, const char *op) { + const char *name = NULL; + const char *t = luaT_typenames[ttype(o)]; + const char *kind = (isinstack(L->ci, o)) ? + getobjname(L, L->ci, cast_int(o - L->base), &name) : + NULL; + if (kind) + luaG_runerror(L, "attempt to %s %s " LUA_QS " (a %s value)", + op, kind, name, t); + else + luaG_runerror(L, "attempt to %s a %s value", op, t); +} + + +void luaG_concaterror (lua_State *L, StkId p1, StkId p2) { + if (ttisstring(p1) || ttisnumber(p1)) p1 = p2; + lua_assert(!ttisstring(p1) && !ttisnumber(p1)); + luaG_typeerror(L, p1, "concatenate"); +} + + +void luaG_aritherror (lua_State *L, const TValue *p1, const TValue *p2) { + TValue temp; + if (luaV_tonumber(p1, &temp) == NULL) + p2 = p1; /* first operand is wrong */ + luaG_typeerror(L, p2, "perform arithmetic on"); +} + + +int luaG_ordererror (lua_State *L, const TValue *p1, const TValue *p2) { + const char *t1 = luaT_typenames[ttype(p1)]; + const char *t2 = luaT_typenames[ttype(p2)]; + if (t1[2] == t2[2]) + luaG_runerror(L, "attempt to compare two %s values", t1); + else + luaG_runerror(L, "attempt to compare %s with %s", t1, t2); + return 0; +} + + +static void addinfo (lua_State *L, const char *msg) { + CallInfo *ci = L->ci; + if (isLua(ci)) { /* is Lua code? */ + char buff[LUA_IDSIZE]; /* add file:line information */ + int line = currentline(L, ci); + luaO_chunkid(buff, getstr(getluaproto(ci)->source), LUA_IDSIZE); + luaO_pushfstring(L, "%s:%d: %s", buff, line, msg); + } +} + + +void luaG_errormsg (lua_State *L) { + if (L->errfunc != 0) { /* is there an error handling function? */ + StkId errfunc = restorestack(L, L->errfunc); + if (!ttisfunction(errfunc)) luaD_throw(L, LUA_ERRERR); + setobjs2s(L, L->top, L->top - 1); /* move argument */ + setobjs2s(L, L->top - 1, errfunc); /* push function */ + incr_top(L); + luaD_call(L, L->top - 2, 1); /* call it */ + } + luaD_throw(L, LUA_ERRRUN); +} + + +void luaG_runerror (lua_State *L, const char *fmt, ...) { + va_list argp; + va_start(argp, fmt); + addinfo(L, luaO_pushvfstring(L, fmt, argp)); + va_end(argp); + luaG_errormsg(L); +} + diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/ldebug.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/ldebug.h new file mode 100644 index 00000000..ba28a972 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/ldebug.h @@ -0,0 +1,33 @@ +/* +** $Id: ldebug.h,v 2.3.1.1 2007/12/27 13:02:25 roberto Exp $ +** Auxiliary functions from Debug Interface module +** See Copyright Notice in lua.h +*/ + +#ifndef ldebug_h +#define ldebug_h + + +#include "lstate.h" + + +#define pcRel(pc, p) (cast(int, (pc) - (p)->code) - 1) + +#define getline(f,pc) (((f)->lineinfo) ? (f)->lineinfo[pc] : 0) + +#define resethookcount(L) (L->hookcount = L->basehookcount) + + +LUAI_FUNC void luaG_typeerror (lua_State *L, const TValue *o, + const char *opname); +LUAI_FUNC void luaG_concaterror (lua_State *L, StkId p1, StkId p2); +LUAI_FUNC void luaG_aritherror (lua_State *L, const TValue *p1, + const TValue *p2); +LUAI_FUNC int luaG_ordererror (lua_State *L, const TValue *p1, + const TValue *p2); +LUAI_FUNC void luaG_runerror (lua_State *L, const char *fmt, ...); +LUAI_FUNC void luaG_errormsg (lua_State *L); +LUAI_FUNC int luaG_checkcode (const Proto *pt); +LUAI_FUNC int luaG_checkopenop (Instruction i); + +#endif diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/ldo.c b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/ldo.c new file mode 100644 index 00000000..8de05f72 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/ldo.c @@ -0,0 +1,518 @@ +/* +** $Id: ldo.c,v 2.38.1.3 2008/01/18 22:31:22 roberto Exp $ +** Stack and Call structure of Lua +** See Copyright Notice in lua.h +*/ + + +#include +#include +#include + +#define ldo_c +#define LUA_CORE + +#include "lua.h" + +#include "ldebug.h" +#include "ldo.h" +#include "lfunc.h" +#include "lgc.h" +#include "lmem.h" +#include "lobject.h" +#include "lopcodes.h" +#include "lparser.h" +#include "lstate.h" +#include "lstring.h" +#include "ltable.h" +#include "ltm.h" +#include "lundump.h" +#include "lvm.h" +#include "lzio.h" + + + + +/* +** {====================================================== +** Error-recovery functions +** ======================================================= +*/ + + +/* chain list of long jump buffers */ +struct lua_longjmp { + struct lua_longjmp *previous; + luai_jmpbuf b; + volatile int status; /* error code */ +}; + + +void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop) { + switch (errcode) { + case LUA_ERRMEM: { + setsvalue2s(L, oldtop, luaS_newliteral(L, MEMERRMSG)); + break; + } + case LUA_ERRERR: { + setsvalue2s(L, oldtop, luaS_newliteral(L, "error in error handling")); + break; + } + case LUA_ERRSYNTAX: + case LUA_ERRRUN: { + setobjs2s(L, oldtop, L->top - 1); /* error message on current top */ + break; + } + } + L->top = oldtop + 1; +} + + +static void restore_stack_limit (lua_State *L) { + lua_assert(L->stack_last - L->stack == L->stacksize - EXTRA_STACK - 1); + if (L->size_ci > LUAI_MAXCALLS) { /* there was an overflow? */ + int inuse = cast_int(L->ci - L->base_ci); + if (inuse + 1 < LUAI_MAXCALLS) /* can `undo' overflow? */ + luaD_reallocCI(L, LUAI_MAXCALLS); + } +} + + +static void resetstack (lua_State *L, int status) { + L->ci = L->base_ci; + L->base = L->ci->base; + luaF_close(L, L->base); /* close eventual pending closures */ + luaD_seterrorobj(L, status, L->base); + L->nCcalls = L->baseCcalls; + L->allowhook = 1; + restore_stack_limit(L); + L->errfunc = 0; + L->errorJmp = NULL; +} + + +void luaD_throw (lua_State *L, int errcode) { + if (L->errorJmp) { + L->errorJmp->status = errcode; + LUAI_THROW(L, L->errorJmp); + } + else { + L->status = cast_byte(errcode); + if (G(L)->panic) { + resetstack(L, errcode); + lua_unlock(L); + G(L)->panic(L); + } + exit(EXIT_FAILURE); + } +} + + +int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud) { + struct lua_longjmp lj; + lj.status = 0; + lj.previous = L->errorJmp; /* chain new error handler */ + L->errorJmp = &lj; + LUAI_TRY(L, &lj, + (*f)(L, ud); + ); + L->errorJmp = lj.previous; /* restore old error handler */ + return lj.status; +} + +/* }====================================================== */ + + +static void correctstack (lua_State *L, TValue *oldstack) { + CallInfo *ci; + GCObject *up; + L->top = (L->top - oldstack) + L->stack; + for (up = L->openupval; up != NULL; up = up->gch.next) + gco2uv(up)->v = (gco2uv(up)->v - oldstack) + L->stack; + for (ci = L->base_ci; ci <= L->ci; ci++) { + ci->top = (ci->top - oldstack) + L->stack; + ci->base = (ci->base - oldstack) + L->stack; + ci->func = (ci->func - oldstack) + L->stack; + } + L->base = (L->base - oldstack) + L->stack; +} + + +void luaD_reallocstack (lua_State *L, int newsize) { + TValue *oldstack = L->stack; + int realsize = newsize + 1 + EXTRA_STACK; + lua_assert(L->stack_last - L->stack == L->stacksize - EXTRA_STACK - 1); + luaM_reallocvector(L, L->stack, L->stacksize, realsize, TValue); + L->stacksize = realsize; + L->stack_last = L->stack+newsize; + correctstack(L, oldstack); +} + + +void luaD_reallocCI (lua_State *L, int newsize) { + CallInfo *oldci = L->base_ci; + luaM_reallocvector(L, L->base_ci, L->size_ci, newsize, CallInfo); + L->size_ci = newsize; + L->ci = (L->ci - oldci) + L->base_ci; + L->end_ci = L->base_ci + L->size_ci - 1; +} + + +void luaD_growstack (lua_State *L, int n) { + if (n <= L->stacksize) /* double size is enough? */ + luaD_reallocstack(L, 2*L->stacksize); + else + luaD_reallocstack(L, L->stacksize + n); +} + + +static CallInfo *growCI (lua_State *L) { + if (L->size_ci > LUAI_MAXCALLS) /* overflow while handling overflow? */ + luaD_throw(L, LUA_ERRERR); + else { + luaD_reallocCI(L, 2*L->size_ci); + if (L->size_ci > LUAI_MAXCALLS) + luaG_runerror(L, "stack overflow"); + } + return ++L->ci; +} + + +void luaD_callhook (lua_State *L, int event, int line) { + lua_Hook hook = L->hook; + if (hook && L->allowhook) { + ptrdiff_t top = savestack(L, L->top); + ptrdiff_t ci_top = savestack(L, L->ci->top); + lua_Debug ar; + ar.event = event; + ar.currentline = line; + if (event == LUA_HOOKTAILRET) + ar.i_ci = 0; /* tail call; no debug information about it */ + else + ar.i_ci = cast_int(L->ci - L->base_ci); + luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */ + L->ci->top = L->top + LUA_MINSTACK; + lua_assert(L->ci->top <= L->stack_last); + L->allowhook = 0; /* cannot call hooks inside a hook */ + lua_unlock(L); + (*hook)(L, &ar); + lua_lock(L); + lua_assert(!L->allowhook); + L->allowhook = 1; + L->ci->top = restorestack(L, ci_top); + L->top = restorestack(L, top); + } +} + + +static StkId adjust_varargs (lua_State *L, Proto *p, int actual) { + int i; + int nfixargs = p->numparams; + Table *htab = NULL; + StkId base, fixed; + for (; actual < nfixargs; ++actual) + setnilvalue(L->top++); +#if defined(LUA_COMPAT_VARARG) + if (p->is_vararg & VARARG_NEEDSARG) { /* compat. with old-style vararg? */ + int nvar = actual - nfixargs; /* number of extra arguments */ + lua_assert(p->is_vararg & VARARG_HASARG); + luaC_checkGC(L); + htab = luaH_new(L, nvar, 1); /* create `arg' table */ + for (i=0; itop - nvar + i); + /* store counter in field `n' */ + setnvalue(luaH_setstr(L, htab, luaS_newliteral(L, "n")), cast_num(nvar)); + } +#endif + /* move fixed parameters to final position */ + fixed = L->top - actual; /* first fixed argument */ + base = L->top; /* final position of first argument */ + for (i=0; itop++, fixed+i); + setnilvalue(fixed+i); + } + /* add `arg' parameter */ + if (htab) { + sethvalue(L, L->top++, htab); + lua_assert(iswhite(obj2gco(htab))); + } + return base; +} + + +static StkId tryfuncTM (lua_State *L, StkId func) { + const TValue *tm = luaT_gettmbyobj(L, func, TM_CALL); + StkId p; + ptrdiff_t funcr = savestack(L, func); + if (!ttisfunction(tm)) + luaG_typeerror(L, func, "call"); + /* Open a hole inside the stack at `func' */ + for (p = L->top; p > func; p--) setobjs2s(L, p, p-1); + incr_top(L); + func = restorestack(L, funcr); /* previous call may change stack */ + setobj2s(L, func, tm); /* tag method is the new function to be called */ + return func; +} + + + +#define inc_ci(L) \ + ((L->ci == L->end_ci) ? growCI(L) : \ + (condhardstacktests(luaD_reallocCI(L, L->size_ci)), ++L->ci)) + + +int luaD_precall (lua_State *L, StkId func, int nresults) { + LClosure *cl; + ptrdiff_t funcr; + if (!ttisfunction(func)) /* `func' is not a function? */ + func = tryfuncTM(L, func); /* check the `function' tag method */ + funcr = savestack(L, func); + cl = &clvalue(func)->l; + L->ci->savedpc = L->savedpc; + if (!cl->isC) { /* Lua function? prepare its call */ + CallInfo *ci; + StkId st, base; + Proto *p = cl->p; + luaD_checkstack(L, p->maxstacksize); + func = restorestack(L, funcr); + if (!p->is_vararg) { /* no varargs? */ + base = func + 1; + if (L->top > base + p->numparams) + L->top = base + p->numparams; + } + else { /* vararg function */ + int nargs = cast_int(L->top - func) - 1; + base = adjust_varargs(L, p, nargs); + func = restorestack(L, funcr); /* previous call may change the stack */ + } + ci = inc_ci(L); /* now `enter' new function */ + ci->func = func; + L->base = ci->base = base; + ci->top = L->base + p->maxstacksize; + lua_assert(ci->top <= L->stack_last); + L->savedpc = p->code; /* starting point */ + ci->tailcalls = 0; + ci->nresults = nresults; + for (st = L->top; st < ci->top; st++) + setnilvalue(st); + L->top = ci->top; + if (L->hookmask & LUA_MASKCALL) { + L->savedpc++; /* hooks assume 'pc' is already incremented */ + luaD_callhook(L, LUA_HOOKCALL, -1); + L->savedpc--; /* correct 'pc' */ + } + return PCRLUA; + } + else { /* if is a C function, call it */ + CallInfo *ci; + int n; + luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */ + ci = inc_ci(L); /* now `enter' new function */ + ci->func = restorestack(L, funcr); + L->base = ci->base = ci->func + 1; + ci->top = L->top + LUA_MINSTACK; + lua_assert(ci->top <= L->stack_last); + ci->nresults = nresults; + if (L->hookmask & LUA_MASKCALL) + luaD_callhook(L, LUA_HOOKCALL, -1); + lua_unlock(L); + n = (*curr_func(L)->c.f)(L); /* do the actual call */ + lua_lock(L); + if (n < 0) /* yielding? */ + return PCRYIELD; + else { + luaD_poscall(L, L->top - n); + return PCRC; + } + } +} + + +static StkId callrethooks (lua_State *L, StkId firstResult) { + ptrdiff_t fr = savestack(L, firstResult); /* next call may change stack */ + luaD_callhook(L, LUA_HOOKRET, -1); + if (f_isLua(L->ci)) { /* Lua function? */ + while ((L->hookmask & LUA_MASKRET) && L->ci->tailcalls--) /* tail calls */ + luaD_callhook(L, LUA_HOOKTAILRET, -1); + } + return restorestack(L, fr); +} + + +int luaD_poscall (lua_State *L, StkId firstResult) { + StkId res; + int wanted, i; + CallInfo *ci; + if (L->hookmask & LUA_MASKRET) + firstResult = callrethooks(L, firstResult); + ci = L->ci--; + res = ci->func; /* res == final position of 1st result */ + wanted = ci->nresults; + L->base = (ci - 1)->base; /* restore base */ + L->savedpc = (ci - 1)->savedpc; /* restore savedpc */ + /* move results to correct place */ + for (i = wanted; i != 0 && firstResult < L->top; i--) + setobjs2s(L, res++, firstResult++); + while (i-- > 0) + setnilvalue(res++); + L->top = res; + return (wanted - LUA_MULTRET); /* 0 iff wanted == LUA_MULTRET */ +} + + +/* +** Call a function (C or Lua). The function to be called is at *func. +** The arguments are on the stack, right after the function. +** When returns, all the results are on the stack, starting at the original +** function position. +*/ +void luaD_call (lua_State *L, StkId func, int nResults) { + if (++L->nCcalls >= LUAI_MAXCCALLS) { + if (L->nCcalls == LUAI_MAXCCALLS) + luaG_runerror(L, "C stack overflow"); + else if (L->nCcalls >= (LUAI_MAXCCALLS + (LUAI_MAXCCALLS>>3))) + luaD_throw(L, LUA_ERRERR); /* error while handing stack error */ + } + if (luaD_precall(L, func, nResults) == PCRLUA) /* is a Lua function? */ + luaV_execute(L, 1); /* call it */ + L->nCcalls--; + luaC_checkGC(L); +} + + +static void resume (lua_State *L, void *ud) { + StkId firstArg = cast(StkId, ud); + CallInfo *ci = L->ci; + if (L->status == 0) { /* start coroutine? */ + lua_assert(ci == L->base_ci && firstArg > L->base); + if (luaD_precall(L, firstArg - 1, LUA_MULTRET) != PCRLUA) + return; + } + else { /* resuming from previous yield */ + lua_assert(L->status == LUA_YIELD); + L->status = 0; + if (!f_isLua(ci)) { /* `common' yield? */ + /* finish interrupted execution of `OP_CALL' */ + lua_assert(GET_OPCODE(*((ci-1)->savedpc - 1)) == OP_CALL || + GET_OPCODE(*((ci-1)->savedpc - 1)) == OP_TAILCALL); + if (luaD_poscall(L, firstArg)) /* complete it... */ + L->top = L->ci->top; /* and correct top if not multiple results */ + } + else /* yielded inside a hook: just continue its execution */ + L->base = L->ci->base; + } + luaV_execute(L, cast_int(L->ci - L->base_ci)); +} + + +static int resume_error (lua_State *L, const char *msg) { + L->top = L->ci->base; + setsvalue2s(L, L->top, luaS_new(L, msg)); + incr_top(L); + lua_unlock(L); + return LUA_ERRRUN; +} + + +LUA_API int lua_resume (lua_State *L, int nargs) { + int status; + lua_lock(L); + if (L->status != LUA_YIELD && (L->status != 0 || L->ci != L->base_ci)) + return resume_error(L, "cannot resume non-suspended coroutine"); + if (L->nCcalls >= LUAI_MAXCCALLS) + return resume_error(L, "C stack overflow"); + luai_userstateresume(L, nargs); + lua_assert(L->errfunc == 0); + L->baseCcalls = ++L->nCcalls; + status = luaD_rawrunprotected(L, resume, L->top - nargs); + if (status != 0) { /* error? */ + L->status = cast_byte(status); /* mark thread as `dead' */ + luaD_seterrorobj(L, status, L->top); + L->ci->top = L->top; + } + else { + lua_assert(L->nCcalls == L->baseCcalls); + status = L->status; + } + --L->nCcalls; + lua_unlock(L); + return status; +} + + +LUA_API int lua_yield (lua_State *L, int nresults) { + luai_userstateyield(L, nresults); + lua_lock(L); + if (L->nCcalls > L->baseCcalls) + luaG_runerror(L, "attempt to yield across metamethod/C-call boundary"); + L->base = L->top - nresults; /* protect stack slots below */ + L->status = LUA_YIELD; + lua_unlock(L); + return -1; +} + + +int luaD_pcall (lua_State *L, Pfunc func, void *u, + ptrdiff_t old_top, ptrdiff_t ef) { + int status; + unsigned short oldnCcalls = L->nCcalls; + ptrdiff_t old_ci = saveci(L, L->ci); + lu_byte old_allowhooks = L->allowhook; + ptrdiff_t old_errfunc = L->errfunc; + L->errfunc = ef; + status = luaD_rawrunprotected(L, func, u); + if (status != 0) { /* an error occurred? */ + StkId oldtop = restorestack(L, old_top); + luaF_close(L, oldtop); /* close eventual pending closures */ + luaD_seterrorobj(L, status, oldtop); + L->nCcalls = oldnCcalls; + L->ci = restoreci(L, old_ci); + L->base = L->ci->base; + L->savedpc = L->ci->savedpc; + L->allowhook = old_allowhooks; + restore_stack_limit(L); + } + L->errfunc = old_errfunc; + return status; +} + + + +/* +** Execute a protected parser. +*/ +struct SParser { /* data to `f_parser' */ + ZIO *z; + Mbuffer buff; /* buffer to be used by the scanner */ + const char *name; +}; + +static void f_parser (lua_State *L, void *ud) { + int i; + Proto *tf; + Closure *cl; + struct SParser *p = cast(struct SParser *, ud); + int c = luaZ_lookahead(p->z); + luaC_checkGC(L); + tf = ((c == LUA_SIGNATURE[0]) ? luaU_undump : luaY_parser)(L, p->z, + &p->buff, p->name); + cl = luaF_newLclosure(L, tf->nups, hvalue(gt(L))); + cl->l.p = tf; + for (i = 0; i < tf->nups; i++) /* initialize eventual upvalues */ + cl->l.upvals[i] = luaF_newupval(L); + setclvalue(L, L->top, cl); + incr_top(L); +} + + +int luaD_protectedparser (lua_State *L, ZIO *z, const char *name) { + struct SParser p; + int status; + p.z = z; p.name = name; + luaZ_initbuffer(L, &p.buff); + status = luaD_pcall(L, f_parser, &p, savestack(L, L->top), L->errfunc); + luaZ_freebuffer(L, &p.buff); + return status; +} + + diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/ldo.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/ldo.h new file mode 100644 index 00000000..98fddac5 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/ldo.h @@ -0,0 +1,57 @@ +/* +** $Id: ldo.h,v 2.7.1.1 2007/12/27 13:02:25 roberto Exp $ +** Stack and Call structure of Lua +** See Copyright Notice in lua.h +*/ + +#ifndef ldo_h +#define ldo_h + + +#include "lobject.h" +#include "lstate.h" +#include "lzio.h" + + +#define luaD_checkstack(L,n) \ + if ((char *)L->stack_last - (char *)L->top <= (n)*(int)sizeof(TValue)) \ + luaD_growstack(L, n); \ + else condhardstacktests(luaD_reallocstack(L, L->stacksize - EXTRA_STACK - 1)); + + +#define incr_top(L) {luaD_checkstack(L,1); L->top++;} + +#define savestack(L,p) ((char *)(p) - (char *)L->stack) +#define restorestack(L,n) ((TValue *)((char *)L->stack + (n))) + +#define saveci(L,p) ((char *)(p) - (char *)L->base_ci) +#define restoreci(L,n) ((CallInfo *)((char *)L->base_ci + (n))) + + +/* results from luaD_precall */ +#define PCRLUA 0 /* initiated a call to a Lua function */ +#define PCRC 1 /* did a call to a C function */ +#define PCRYIELD 2 /* C funtion yielded */ + + +/* type of protected functions, to be ran by `runprotected' */ +typedef void (*Pfunc) (lua_State *L, void *ud); + +LUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name); +LUAI_FUNC void luaD_callhook (lua_State *L, int event, int line); +LUAI_FUNC int luaD_precall (lua_State *L, StkId func, int nresults); +LUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults); +LUAI_FUNC int luaD_pcall (lua_State *L, Pfunc func, void *u, + ptrdiff_t oldtop, ptrdiff_t ef); +LUAI_FUNC int luaD_poscall (lua_State *L, StkId firstResult); +LUAI_FUNC void luaD_reallocCI (lua_State *L, int newsize); +LUAI_FUNC void luaD_reallocstack (lua_State *L, int newsize); +LUAI_FUNC void luaD_growstack (lua_State *L, int n); + +LUAI_FUNC void luaD_throw (lua_State *L, int errcode); +LUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud); + +LUAI_FUNC void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop); + +#endif + diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/ldump.c b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/ldump.c new file mode 100644 index 00000000..c9d3d487 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/ldump.c @@ -0,0 +1,164 @@ +/* +** $Id: ldump.c,v 2.8.1.1 2007/12/27 13:02:25 roberto Exp $ +** save precompiled Lua chunks +** See Copyright Notice in lua.h +*/ + +#include + +#define ldump_c +#define LUA_CORE + +#include "lua.h" + +#include "lobject.h" +#include "lstate.h" +#include "lundump.h" + +typedef struct { + lua_State* L; + lua_Writer writer; + void* data; + int strip; + int status; +} DumpState; + +#define DumpMem(b,n,size,D) DumpBlock(b,(n)*(size),D) +#define DumpVar(x,D) DumpMem(&x,1,sizeof(x),D) + +static void DumpBlock(const void* b, size_t size, DumpState* D) +{ + if (D->status==0) + { + lua_unlock(D->L); + D->status=(*D->writer)(D->L,b,size,D->data); + lua_lock(D->L); + } +} + +static void DumpChar(int y, DumpState* D) +{ + char x=(char)y; + DumpVar(x,D); +} + +static void DumpInt(int x, DumpState* D) +{ + DumpVar(x,D); +} + +static void DumpNumber(lua_Number x, DumpState* D) +{ + DumpVar(x,D); +} + +static void DumpVector(const void* b, int n, size_t size, DumpState* D) +{ + DumpInt(n,D); + DumpMem(b,n,size,D); +} + +static void DumpString(const TString* s, DumpState* D) +{ + if (s==NULL || getstr(s)==NULL) + { + size_t size=0; + DumpVar(size,D); + } + else + { + size_t size=s->tsv.len+1; /* include trailing '\0' */ + DumpVar(size,D); + DumpBlock(getstr(s),size,D); + } +} + +#define DumpCode(f,D) DumpVector(f->code,f->sizecode,sizeof(Instruction),D) + +static void DumpFunction(const Proto* f, const TString* p, DumpState* D); + +static void DumpConstants(const Proto* f, DumpState* D) +{ + int i,n=f->sizek; + DumpInt(n,D); + for (i=0; ik[i]; + DumpChar(ttype(o),D); + switch (ttype(o)) + { + case LUA_TNIL: + break; + case LUA_TBOOLEAN: + DumpChar(bvalue(o),D); + break; + case LUA_TNUMBER: + DumpNumber(nvalue(o),D); + break; + case LUA_TSTRING: + DumpString(rawtsvalue(o),D); + break; + default: + lua_assert(0); /* cannot happen */ + break; + } + } + n=f->sizep; + DumpInt(n,D); + for (i=0; ip[i],f->source,D); +} + +static void DumpDebug(const Proto* f, DumpState* D) +{ + int i,n; + n= (D->strip) ? 0 : f->sizelineinfo; + DumpVector(f->lineinfo,n,sizeof(int),D); + n= (D->strip) ? 0 : f->sizelocvars; + DumpInt(n,D); + for (i=0; ilocvars[i].varname,D); + DumpInt(f->locvars[i].startpc,D); + DumpInt(f->locvars[i].endpc,D); + } + n= (D->strip) ? 0 : f->sizeupvalues; + DumpInt(n,D); + for (i=0; iupvalues[i],D); +} + +static void DumpFunction(const Proto* f, const TString* p, DumpState* D) +{ + DumpString((f->source==p || D->strip) ? NULL : f->source,D); + DumpInt(f->linedefined,D); + DumpInt(f->lastlinedefined,D); + DumpChar(f->nups,D); + DumpChar(f->numparams,D); + DumpChar(f->is_vararg,D); + DumpChar(f->maxstacksize,D); + DumpCode(f,D); + DumpConstants(f,D); + DumpDebug(f,D); +} + +static void DumpHeader(DumpState* D) +{ + char h[LUAC_HEADERSIZE]; + luaU_header(h); + DumpBlock(h,LUAC_HEADERSIZE,D); +} + +/* +** dump Lua function as precompiled chunk +*/ +int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip) +{ + DumpState D; + D.L=L; + D.writer=w; + D.data=data; + D.strip=strip; + D.status=0; + DumpHeader(&D); + DumpFunction(f,NULL,&D); + return D.status; +} diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lfunc.c b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lfunc.c new file mode 100644 index 00000000..813e88f5 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lfunc.c @@ -0,0 +1,174 @@ +/* +** $Id: lfunc.c,v 2.12.1.2 2007/12/28 14:58:43 roberto Exp $ +** Auxiliary functions to manipulate prototypes and closures +** See Copyright Notice in lua.h +*/ + + +#include + +#define lfunc_c +#define LUA_CORE + +#include "lua.h" + +#include "lfunc.h" +#include "lgc.h" +#include "lmem.h" +#include "lobject.h" +#include "lstate.h" + + + +Closure *luaF_newCclosure (lua_State *L, int nelems, Table *e) { + Closure *c = cast(Closure *, luaM_malloc(L, sizeCclosure(nelems))); + luaC_link(L, obj2gco(c), LUA_TFUNCTION); + c->c.isC = 1; + c->c.env = e; + c->c.nupvalues = cast_byte(nelems); + return c; +} + + +Closure *luaF_newLclosure (lua_State *L, int nelems, Table *e) { + Closure *c = cast(Closure *, luaM_malloc(L, sizeLclosure(nelems))); + luaC_link(L, obj2gco(c), LUA_TFUNCTION); + c->l.isC = 0; + c->l.env = e; + c->l.nupvalues = cast_byte(nelems); + while (nelems--) c->l.upvals[nelems] = NULL; + return c; +} + + +UpVal *luaF_newupval (lua_State *L) { + UpVal *uv = luaM_new(L, UpVal); + luaC_link(L, obj2gco(uv), LUA_TUPVAL); + uv->v = &uv->u.value; + setnilvalue(uv->v); + return uv; +} + + +UpVal *luaF_findupval (lua_State *L, StkId level) { + global_State *g = G(L); + GCObject **pp = &L->openupval; + UpVal *p; + UpVal *uv; + while (*pp != NULL && (p = ngcotouv(*pp))->v >= level) { + lua_assert(p->v != &p->u.value); + if (p->v == level) { /* found a corresponding upvalue? */ + if (isdead(g, obj2gco(p))) /* is it dead? */ + changewhite(obj2gco(p)); /* ressurect it */ + return p; + } + pp = &p->next; + } + uv = luaM_new(L, UpVal); /* not found: create a new one */ + uv->tt = LUA_TUPVAL; + uv->marked = luaC_white(g); + uv->v = level; /* current value lives in the stack */ + uv->next = *pp; /* chain it in the proper position */ + *pp = obj2gco(uv); + uv->u.l.prev = &g->uvhead; /* double link it in `uvhead' list */ + uv->u.l.next = g->uvhead.u.l.next; + uv->u.l.next->u.l.prev = uv; + g->uvhead.u.l.next = uv; + lua_assert(uv->u.l.next->u.l.prev == uv && uv->u.l.prev->u.l.next == uv); + return uv; +} + + +static void unlinkupval (UpVal *uv) { + lua_assert(uv->u.l.next->u.l.prev == uv && uv->u.l.prev->u.l.next == uv); + uv->u.l.next->u.l.prev = uv->u.l.prev; /* remove from `uvhead' list */ + uv->u.l.prev->u.l.next = uv->u.l.next; +} + + +void luaF_freeupval (lua_State *L, UpVal *uv) { + if (uv->v != &uv->u.value) /* is it open? */ + unlinkupval(uv); /* remove from open list */ + luaM_free(L, uv); /* free upvalue */ +} + + +void luaF_close (lua_State *L, StkId level) { + UpVal *uv; + global_State *g = G(L); + while (L->openupval != NULL && (uv = ngcotouv(L->openupval))->v >= level) { + GCObject *o = obj2gco(uv); + lua_assert(!isblack(o) && uv->v != &uv->u.value); + L->openupval = uv->next; /* remove from `open' list */ + if (isdead(g, o)) + luaF_freeupval(L, uv); /* free upvalue */ + else { + unlinkupval(uv); + setobj(L, &uv->u.value, uv->v); + uv->v = &uv->u.value; /* now current value lives here */ + luaC_linkupval(L, uv); /* link upvalue into `gcroot' list */ + } + } +} + + +Proto *luaF_newproto (lua_State *L) { + Proto *f = luaM_new(L, Proto); + luaC_link(L, obj2gco(f), LUA_TPROTO); + f->k = NULL; + f->sizek = 0; + f->p = NULL; + f->sizep = 0; + f->code = NULL; + f->sizecode = 0; + f->sizelineinfo = 0; + f->sizeupvalues = 0; + f->nups = 0; + f->upvalues = NULL; + f->numparams = 0; + f->is_vararg = 0; + f->maxstacksize = 0; + f->lineinfo = NULL; + f->sizelocvars = 0; + f->locvars = NULL; + f->linedefined = 0; + f->lastlinedefined = 0; + f->source = NULL; + return f; +} + + +void luaF_freeproto (lua_State *L, Proto *f) { + luaM_freearray(L, f->code, f->sizecode, Instruction); + luaM_freearray(L, f->p, f->sizep, Proto *); + luaM_freearray(L, f->k, f->sizek, TValue); + luaM_freearray(L, f->lineinfo, f->sizelineinfo, int); + luaM_freearray(L, f->locvars, f->sizelocvars, struct LocVar); + luaM_freearray(L, f->upvalues, f->sizeupvalues, TString *); + luaM_free(L, f); +} + + +void luaF_freeclosure (lua_State *L, Closure *c) { + int size = (c->c.isC) ? sizeCclosure(c->c.nupvalues) : + sizeLclosure(c->l.nupvalues); + luaM_freemem(L, c, size); +} + + +/* +** Look for n-th local variable at line `line' in function `func'. +** Returns NULL if not found. +*/ +const char *luaF_getlocalname (const Proto *f, int local_number, int pc) { + int i; + for (i = 0; isizelocvars && f->locvars[i].startpc <= pc; i++) { + if (pc < f->locvars[i].endpc) { /* is variable active? */ + local_number--; + if (local_number == 0) + return getstr(f->locvars[i].varname); + } + } + return NULL; /* not found */ +} + diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lfunc.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lfunc.h new file mode 100644 index 00000000..a68cf515 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lfunc.h @@ -0,0 +1,34 @@ +/* +** $Id: lfunc.h,v 2.4.1.1 2007/12/27 13:02:25 roberto Exp $ +** Auxiliary functions to manipulate prototypes and closures +** See Copyright Notice in lua.h +*/ + +#ifndef lfunc_h +#define lfunc_h + + +#include "lobject.h" + + +#define sizeCclosure(n) (cast(int, sizeof(CClosure)) + \ + cast(int, sizeof(TValue)*((n)-1))) + +#define sizeLclosure(n) (cast(int, sizeof(LClosure)) + \ + cast(int, sizeof(TValue *)*((n)-1))) + + +LUAI_FUNC Proto *luaF_newproto (lua_State *L); +LUAI_FUNC Closure *luaF_newCclosure (lua_State *L, int nelems, Table *e); +LUAI_FUNC Closure *luaF_newLclosure (lua_State *L, int nelems, Table *e); +LUAI_FUNC UpVal *luaF_newupval (lua_State *L); +LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level); +LUAI_FUNC void luaF_close (lua_State *L, StkId level); +LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f); +LUAI_FUNC void luaF_freeclosure (lua_State *L, Closure *c); +LUAI_FUNC void luaF_freeupval (lua_State *L, UpVal *uv); +LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number, + int pc); + + +#endif diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lgc.c b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lgc.c new file mode 100644 index 00000000..d9e0b782 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lgc.c @@ -0,0 +1,711 @@ +/* +** $Id: lgc.c,v 2.38.1.1 2007/12/27 13:02:25 roberto Exp $ +** Garbage Collector +** See Copyright Notice in lua.h +*/ + +#include + +#define lgc_c +#define LUA_CORE + +#include "lua.h" + +#include "ldebug.h" +#include "ldo.h" +#include "lfunc.h" +#include "lgc.h" +#include "lmem.h" +#include "lobject.h" +#include "lstate.h" +#include "lstring.h" +#include "ltable.h" +#include "ltm.h" + + +#define GCSTEPSIZE 1024u +#define GCSWEEPMAX 40 +#define GCSWEEPCOST 10 +#define GCFINALIZECOST 100 + + +#define maskmarks cast_byte(~(bitmask(BLACKBIT)|WHITEBITS)) + +#define makewhite(g,x) \ + ((x)->gch.marked = cast_byte(((x)->gch.marked & maskmarks) | luaC_white(g))) + +#define white2gray(x) reset2bits((x)->gch.marked, WHITE0BIT, WHITE1BIT) +#define black2gray(x) resetbit((x)->gch.marked, BLACKBIT) + +#define stringmark(s) reset2bits((s)->tsv.marked, WHITE0BIT, WHITE1BIT) + + +#define isfinalized(u) testbit((u)->marked, FINALIZEDBIT) +#define markfinalized(u) l_setbit((u)->marked, FINALIZEDBIT) + + +#define KEYWEAK bitmask(KEYWEAKBIT) +#define VALUEWEAK bitmask(VALUEWEAKBIT) + + + +#define markvalue(g,o) { checkconsistency(o); \ + if (iscollectable(o) && iswhite(gcvalue(o))) reallymarkobject(g,gcvalue(o)); } + +#define markobject(g,t) { if (iswhite(obj2gco(t))) \ + reallymarkobject(g, obj2gco(t)); } + + +#define setthreshold(g) (g->GCthreshold = (g->estimate/100) * g->gcpause) + + +static void removeentry (Node *n) { + lua_assert(ttisnil(gval(n))); + if (iscollectable(gkey(n))) + setttype(gkey(n), LUA_TDEADKEY); /* dead key; remove it */ +} + + +static void reallymarkobject (global_State *g, GCObject *o) { + lua_assert(iswhite(o) && !isdead(g, o)); + white2gray(o); + switch (o->gch.tt) { + case LUA_TSTRING: { + return; + } + case LUA_TUSERDATA: { + Table *mt = gco2u(o)->metatable; + gray2black(o); /* udata are never gray */ + if (mt) markobject(g, mt); + markobject(g, gco2u(o)->env); + return; + } + case LUA_TUPVAL: { + UpVal *uv = gco2uv(o); + markvalue(g, uv->v); + if (uv->v == &uv->u.value) /* closed? */ + gray2black(o); /* open upvalues are never black */ + return; + } + case LUA_TFUNCTION: { + gco2cl(o)->c.gclist = g->gray; + g->gray = o; + break; + } + case LUA_TTABLE: { + gco2h(o)->gclist = g->gray; + g->gray = o; + break; + } + case LUA_TTHREAD: { + gco2th(o)->gclist = g->gray; + g->gray = o; + break; + } + case LUA_TPROTO: { + gco2p(o)->gclist = g->gray; + g->gray = o; + break; + } + default: lua_assert(0); + } +} + + +static void marktmu (global_State *g) { + GCObject *u = g->tmudata; + if (u) { + do { + u = u->gch.next; + makewhite(g, u); /* may be marked, if left from previous GC */ + reallymarkobject(g, u); + } while (u != g->tmudata); + } +} + + +/* move `dead' udata that need finalization to list `tmudata' */ +size_t luaC_separateudata (lua_State *L, int all) { + global_State *g = G(L); + size_t deadmem = 0; + GCObject **p = &g->mainthread->next; + GCObject *curr; + while ((curr = *p) != NULL) { + if (!(iswhite(curr) || all) || isfinalized(gco2u(curr))) + p = &curr->gch.next; /* don't bother with them */ + else if (fasttm(L, gco2u(curr)->metatable, TM_GC) == NULL) { + markfinalized(gco2u(curr)); /* don't need finalization */ + p = &curr->gch.next; + } + else { /* must call its gc method */ + deadmem += sizeudata(gco2u(curr)); + markfinalized(gco2u(curr)); + *p = curr->gch.next; + /* link `curr' at the end of `tmudata' list */ + if (g->tmudata == NULL) /* list is empty? */ + g->tmudata = curr->gch.next = curr; /* creates a circular list */ + else { + curr->gch.next = g->tmudata->gch.next; + g->tmudata->gch.next = curr; + g->tmudata = curr; + } + } + } + return deadmem; +} + + +static int traversetable (global_State *g, Table *h) { + int i; + int weakkey = 0; + int weakvalue = 0; + const TValue *mode; + if (h->metatable) + markobject(g, h->metatable); + mode = gfasttm(g, h->metatable, TM_MODE); + if (mode && ttisstring(mode)) { /* is there a weak mode? */ + weakkey = (strchr(svalue(mode), 'k') != NULL); + weakvalue = (strchr(svalue(mode), 'v') != NULL); + if (weakkey || weakvalue) { /* is really weak? */ + h->marked &= ~(KEYWEAK | VALUEWEAK); /* clear bits */ + h->marked |= cast_byte((weakkey << KEYWEAKBIT) | + (weakvalue << VALUEWEAKBIT)); + h->gclist = g->weak; /* must be cleared after GC, ... */ + g->weak = obj2gco(h); /* ... so put in the appropriate list */ + } + } + if (weakkey && weakvalue) return 1; + if (!weakvalue) { + i = h->sizearray; + while (i--) + markvalue(g, &h->array[i]); + } + i = sizenode(h); + while (i--) { + Node *n = gnode(h, i); + lua_assert(ttype(gkey(n)) != LUA_TDEADKEY || ttisnil(gval(n))); + if (ttisnil(gval(n))) + removeentry(n); /* remove empty entries */ + else { + lua_assert(!ttisnil(gkey(n))); + if (!weakkey) markvalue(g, gkey(n)); + if (!weakvalue) markvalue(g, gval(n)); + } + } + return weakkey || weakvalue; +} + + +/* +** All marks are conditional because a GC may happen while the +** prototype is still being created +*/ +static void traverseproto (global_State *g, Proto *f) { + int i; + if (f->source) stringmark(f->source); + for (i=0; isizek; i++) /* mark literals */ + markvalue(g, &f->k[i]); + for (i=0; isizeupvalues; i++) { /* mark upvalue names */ + if (f->upvalues[i]) + stringmark(f->upvalues[i]); + } + for (i=0; isizep; i++) { /* mark nested protos */ + if (f->p[i]) + markobject(g, f->p[i]); + } + for (i=0; isizelocvars; i++) { /* mark local-variable names */ + if (f->locvars[i].varname) + stringmark(f->locvars[i].varname); + } +} + + + +static void traverseclosure (global_State *g, Closure *cl) { + markobject(g, cl->c.env); + if (cl->c.isC) { + int i; + for (i=0; ic.nupvalues; i++) /* mark its upvalues */ + markvalue(g, &cl->c.upvalue[i]); + } + else { + int i; + lua_assert(cl->l.nupvalues == cl->l.p->nups); + markobject(g, cl->l.p); + for (i=0; il.nupvalues; i++) /* mark its upvalues */ + markobject(g, cl->l.upvals[i]); + } +} + + +static void checkstacksizes (lua_State *L, StkId max) { + int ci_used = cast_int(L->ci - L->base_ci); /* number of `ci' in use */ + int s_used = cast_int(max - L->stack); /* part of stack in use */ + if (L->size_ci > LUAI_MAXCALLS) /* handling overflow? */ + return; /* do not touch the stacks */ + if (4*ci_used < L->size_ci && 2*BASIC_CI_SIZE < L->size_ci) + luaD_reallocCI(L, L->size_ci/2); /* still big enough... */ + condhardstacktests(luaD_reallocCI(L, ci_used + 1)); + if (4*s_used < L->stacksize && + 2*(BASIC_STACK_SIZE+EXTRA_STACK) < L->stacksize) + luaD_reallocstack(L, L->stacksize/2); /* still big enough... */ + condhardstacktests(luaD_reallocstack(L, s_used)); +} + + +static void traversestack (global_State *g, lua_State *l) { + StkId o, lim; + CallInfo *ci; + markvalue(g, gt(l)); + lim = l->top; + for (ci = l->base_ci; ci <= l->ci; ci++) { + lua_assert(ci->top <= l->stack_last); + if (lim < ci->top) lim = ci->top; + } + for (o = l->stack; o < l->top; o++) + markvalue(g, o); + for (; o <= lim; o++) + setnilvalue(o); + checkstacksizes(l, lim); +} + + +/* +** traverse one gray object, turning it to black. +** Returns `quantity' traversed. +*/ +static l_mem propagatemark (global_State *g) { + GCObject *o = g->gray; + lua_assert(isgray(o)); + gray2black(o); + switch (o->gch.tt) { + case LUA_TTABLE: { + Table *h = gco2h(o); + g->gray = h->gclist; + if (traversetable(g, h)) /* table is weak? */ + black2gray(o); /* keep it gray */ + return sizeof(Table) + sizeof(TValue) * h->sizearray + + sizeof(Node) * sizenode(h); + } + case LUA_TFUNCTION: { + Closure *cl = gco2cl(o); + g->gray = cl->c.gclist; + traverseclosure(g, cl); + return (cl->c.isC) ? sizeCclosure(cl->c.nupvalues) : + sizeLclosure(cl->l.nupvalues); + } + case LUA_TTHREAD: { + lua_State *th = gco2th(o); + g->gray = th->gclist; + th->gclist = g->grayagain; + g->grayagain = o; + black2gray(o); + traversestack(g, th); + return sizeof(lua_State) + sizeof(TValue) * th->stacksize + + sizeof(CallInfo) * th->size_ci; + } + case LUA_TPROTO: { + Proto *p = gco2p(o); + g->gray = p->gclist; + traverseproto(g, p); + return sizeof(Proto) + sizeof(Instruction) * p->sizecode + + sizeof(Proto *) * p->sizep + + sizeof(TValue) * p->sizek + + sizeof(int) * p->sizelineinfo + + sizeof(LocVar) * p->sizelocvars + + sizeof(TString *) * p->sizeupvalues; + } + default: lua_assert(0); return 0; + } +} + + +static size_t propagateall (global_State *g) { + size_t m = 0; + while (g->gray) m += propagatemark(g); + return m; +} + + +/* +** The next function tells whether a key or value can be cleared from +** a weak table. Non-collectable objects are never removed from weak +** tables. Strings behave as `values', so are never removed too. for +** other objects: if really collected, cannot keep them; for userdata +** being finalized, keep them in keys, but not in values +*/ +static int iscleared (const TValue *o, int iskey) { + if (!iscollectable(o)) return 0; + if (ttisstring(o)) { + stringmark(rawtsvalue(o)); /* strings are `values', so are never weak */ + return 0; + } + return iswhite(gcvalue(o)) || + (ttisuserdata(o) && (!iskey && isfinalized(uvalue(o)))); +} + + +/* +** clear collected entries from weaktables +*/ +static void cleartable (GCObject *l) { + while (l) { + Table *h = gco2h(l); + int i = h->sizearray; + lua_assert(testbit(h->marked, VALUEWEAKBIT) || + testbit(h->marked, KEYWEAKBIT)); + if (testbit(h->marked, VALUEWEAKBIT)) { + while (i--) { + TValue *o = &h->array[i]; + if (iscleared(o, 0)) /* value was collected? */ + setnilvalue(o); /* remove value */ + } + } + i = sizenode(h); + while (i--) { + Node *n = gnode(h, i); + if (!ttisnil(gval(n)) && /* non-empty entry? */ + (iscleared(key2tval(n), 1) || iscleared(gval(n), 0))) { + setnilvalue(gval(n)); /* remove value ... */ + removeentry(n); /* remove entry from table */ + } + } + l = h->gclist; + } +} + + +static void freeobj (lua_State *L, GCObject *o) { + switch (o->gch.tt) { + case LUA_TPROTO: luaF_freeproto(L, gco2p(o)); break; + case LUA_TFUNCTION: luaF_freeclosure(L, gco2cl(o)); break; + case LUA_TUPVAL: luaF_freeupval(L, gco2uv(o)); break; + case LUA_TTABLE: luaH_free(L, gco2h(o)); break; + case LUA_TTHREAD: { + lua_assert(gco2th(o) != L && gco2th(o) != G(L)->mainthread); + luaE_freethread(L, gco2th(o)); + break; + } + case LUA_TSTRING: { + G(L)->strt.nuse--; + luaM_freemem(L, o, sizestring(gco2ts(o))); + break; + } + case LUA_TUSERDATA: { + luaM_freemem(L, o, sizeudata(gco2u(o))); + break; + } + default: lua_assert(0); + } +} + + + +#define sweepwholelist(L,p) sweeplist(L,p,MAX_LUMEM) + + +static GCObject **sweeplist (lua_State *L, GCObject **p, lu_mem count) { + GCObject *curr; + global_State *g = G(L); + int deadmask = otherwhite(g); + while ((curr = *p) != NULL && count-- > 0) { + if (curr->gch.tt == LUA_TTHREAD) /* sweep open upvalues of each thread */ + sweepwholelist(L, &gco2th(curr)->openupval); + if ((curr->gch.marked ^ WHITEBITS) & deadmask) { /* not dead? */ + lua_assert(!isdead(g, curr) || testbit(curr->gch.marked, FIXEDBIT)); + makewhite(g, curr); /* make it white (for next cycle) */ + p = &curr->gch.next; + } + else { /* must erase `curr' */ + lua_assert(isdead(g, curr) || deadmask == bitmask(SFIXEDBIT)); + *p = curr->gch.next; + if (curr == g->rootgc) /* is the first element of the list? */ + g->rootgc = curr->gch.next; /* adjust first */ + freeobj(L, curr); + } + } + return p; +} + + +static void checkSizes (lua_State *L) { + global_State *g = G(L); + /* check size of string hash */ + if (g->strt.nuse < cast(lu_int32, g->strt.size/4) && + g->strt.size > MINSTRTABSIZE*2) + luaS_resize(L, g->strt.size/2); /* table is too big */ + /* check size of buffer */ + if (luaZ_sizebuffer(&g->buff) > LUA_MINBUFFER*2) { /* buffer too big? */ + size_t newsize = luaZ_sizebuffer(&g->buff) / 2; + luaZ_resizebuffer(L, &g->buff, newsize); + } +} + + +static void GCTM (lua_State *L) { + global_State *g = G(L); + GCObject *o = g->tmudata->gch.next; /* get first element */ + Udata *udata = rawgco2u(o); + const TValue *tm; + /* remove udata from `tmudata' */ + if (o == g->tmudata) /* last element? */ + g->tmudata = NULL; + else + g->tmudata->gch.next = udata->uv.next; + udata->uv.next = g->mainthread->next; /* return it to `root' list */ + g->mainthread->next = o; + makewhite(g, o); + tm = fasttm(L, udata->uv.metatable, TM_GC); + if (tm != NULL) { + lu_byte oldah = L->allowhook; + lu_mem oldt = g->GCthreshold; + L->allowhook = 0; /* stop debug hooks during GC tag method */ + g->GCthreshold = 2*g->totalbytes; /* avoid GC steps */ + setobj2s(L, L->top, tm); + setuvalue(L, L->top+1, udata); + L->top += 2; + luaD_call(L, L->top - 2, 0); + L->allowhook = oldah; /* restore hooks */ + g->GCthreshold = oldt; /* restore threshold */ + } +} + + +/* +** Call all GC tag methods +*/ +void luaC_callGCTM (lua_State *L) { + while (G(L)->tmudata) + GCTM(L); +} + + +void luaC_freeall (lua_State *L) { + global_State *g = G(L); + int i; + g->currentwhite = WHITEBITS | bitmask(SFIXEDBIT); /* mask to collect all elements */ + sweepwholelist(L, &g->rootgc); + for (i = 0; i < g->strt.size; i++) /* free all string lists */ + sweepwholelist(L, &g->strt.hash[i]); +} + + +static void markmt (global_State *g) { + int i; + for (i=0; imt[i]) markobject(g, g->mt[i]); +} + + +/* mark root set */ +static void markroot (lua_State *L) { + global_State *g = G(L); + g->gray = NULL; + g->grayagain = NULL; + g->weak = NULL; + markobject(g, g->mainthread); + /* make global table be traversed before main stack */ + markvalue(g, gt(g->mainthread)); + markvalue(g, registry(L)); + markmt(g); + g->gcstate = GCSpropagate; +} + + +static void remarkupvals (global_State *g) { + UpVal *uv; + for (uv = g->uvhead.u.l.next; uv != &g->uvhead; uv = uv->u.l.next) { + lua_assert(uv->u.l.next->u.l.prev == uv && uv->u.l.prev->u.l.next == uv); + if (isgray(obj2gco(uv))) + markvalue(g, uv->v); + } +} + + +static void atomic (lua_State *L) { + global_State *g = G(L); + size_t udsize; /* total size of userdata to be finalized */ + /* remark occasional upvalues of (maybe) dead threads */ + remarkupvals(g); + /* traverse objects cautch by write barrier and by 'remarkupvals' */ + propagateall(g); + /* remark weak tables */ + g->gray = g->weak; + g->weak = NULL; + lua_assert(!iswhite(obj2gco(g->mainthread))); + markobject(g, L); /* mark running thread */ + markmt(g); /* mark basic metatables (again) */ + propagateall(g); + /* remark gray again */ + g->gray = g->grayagain; + g->grayagain = NULL; + propagateall(g); + udsize = luaC_separateudata(L, 0); /* separate userdata to be finalized */ + marktmu(g); /* mark `preserved' userdata */ + udsize += propagateall(g); /* remark, to propagate `preserveness' */ + cleartable(g->weak); /* remove collected objects from weak tables */ + /* flip current white */ + g->currentwhite = cast_byte(otherwhite(g)); + g->sweepstrgc = 0; + g->sweepgc = &g->rootgc; + g->gcstate = GCSsweepstring; + g->estimate = g->totalbytes - udsize; /* first estimate */ +} + + +static l_mem singlestep (lua_State *L) { + global_State *g = G(L); + /*lua_checkmemory(L);*/ + switch (g->gcstate) { + case GCSpause: { + markroot(L); /* start a new collection */ + return 0; + } + case GCSpropagate: { + if (g->gray) + return propagatemark(g); + else { /* no more `gray' objects */ + atomic(L); /* finish mark phase */ + return 0; + } + } + case GCSsweepstring: { + lu_mem old = g->totalbytes; + sweepwholelist(L, &g->strt.hash[g->sweepstrgc++]); + if (g->sweepstrgc >= g->strt.size) /* nothing more to sweep? */ + g->gcstate = GCSsweep; /* end sweep-string phase */ + lua_assert(old >= g->totalbytes); + g->estimate -= old - g->totalbytes; + return GCSWEEPCOST; + } + case GCSsweep: { + lu_mem old = g->totalbytes; + g->sweepgc = sweeplist(L, g->sweepgc, GCSWEEPMAX); + if (*g->sweepgc == NULL) { /* nothing more to sweep? */ + checkSizes(L); + g->gcstate = GCSfinalize; /* end sweep phase */ + } + lua_assert(old >= g->totalbytes); + g->estimate -= old - g->totalbytes; + return GCSWEEPMAX*GCSWEEPCOST; + } + case GCSfinalize: { + if (g->tmudata) { + GCTM(L); + if (g->estimate > GCFINALIZECOST) + g->estimate -= GCFINALIZECOST; + return GCFINALIZECOST; + } + else { + g->gcstate = GCSpause; /* end collection */ + g->gcdept = 0; + return 0; + } + } + default: lua_assert(0); return 0; + } +} + + +void luaC_step (lua_State *L) { + global_State *g = G(L); + l_mem lim = (GCSTEPSIZE/100) * g->gcstepmul; + if (lim == 0) + lim = (MAX_LUMEM-1)/2; /* no limit */ + g->gcdept += g->totalbytes - g->GCthreshold; + do { + lim -= singlestep(L); + if (g->gcstate == GCSpause) + break; + } while (lim > 0); + if (g->gcstate != GCSpause) { + if (g->gcdept < GCSTEPSIZE) + g->GCthreshold = g->totalbytes + GCSTEPSIZE; /* - lim/g->gcstepmul;*/ + else { + g->gcdept -= GCSTEPSIZE; + g->GCthreshold = g->totalbytes; + } + } + else { + lua_assert(g->totalbytes >= g->estimate); + setthreshold(g); + } +} + + +void luaC_fullgc (lua_State *L) { + global_State *g = G(L); + if (g->gcstate <= GCSpropagate) { + /* reset sweep marks to sweep all elements (returning them to white) */ + g->sweepstrgc = 0; + g->sweepgc = &g->rootgc; + /* reset other collector lists */ + g->gray = NULL; + g->grayagain = NULL; + g->weak = NULL; + g->gcstate = GCSsweepstring; + } + lua_assert(g->gcstate != GCSpause && g->gcstate != GCSpropagate); + /* finish any pending sweep phase */ + while (g->gcstate != GCSfinalize) { + lua_assert(g->gcstate == GCSsweepstring || g->gcstate == GCSsweep); + singlestep(L); + } + markroot(L); + while (g->gcstate != GCSpause) { + singlestep(L); + } + setthreshold(g); +} + + +void luaC_barrierf (lua_State *L, GCObject *o, GCObject *v) { + global_State *g = G(L); + lua_assert(isblack(o) && iswhite(v) && !isdead(g, v) && !isdead(g, o)); + lua_assert(g->gcstate != GCSfinalize && g->gcstate != GCSpause); + lua_assert(ttype(&o->gch) != LUA_TTABLE); + /* must keep invariant? */ + if (g->gcstate == GCSpropagate) + reallymarkobject(g, v); /* restore invariant */ + else /* don't mind */ + makewhite(g, o); /* mark as white just to avoid other barriers */ +} + + +void luaC_barrierback (lua_State *L, Table *t) { + global_State *g = G(L); + GCObject *o = obj2gco(t); + lua_assert(isblack(o) && !isdead(g, o)); + lua_assert(g->gcstate != GCSfinalize && g->gcstate != GCSpause); + black2gray(o); /* make table gray (again) */ + t->gclist = g->grayagain; + g->grayagain = o; +} + + +void luaC_link (lua_State *L, GCObject *o, lu_byte tt) { + global_State *g = G(L); + o->gch.next = g->rootgc; + g->rootgc = o; + o->gch.marked = luaC_white(g); + o->gch.tt = tt; +} + + +void luaC_linkupval (lua_State *L, UpVal *uv) { + global_State *g = G(L); + GCObject *o = obj2gco(uv); + o->gch.next = g->rootgc; /* link upvalue into `rootgc' list */ + g->rootgc = o; + if (isgray(o)) { + if (g->gcstate == GCSpropagate) { + gray2black(o); /* closed upvalues need barrier */ + luaC_barrier(L, uv, uv->v); + } + else { /* sweep phase: sweep it (turning it into white) */ + makewhite(g, o); + lua_assert(g->gcstate != GCSfinalize && g->gcstate != GCSpause); + } + } +} + diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lgc.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lgc.h new file mode 100644 index 00000000..5a8dc605 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lgc.h @@ -0,0 +1,110 @@ +/* +** $Id: lgc.h,v 2.15.1.1 2007/12/27 13:02:25 roberto Exp $ +** Garbage Collector +** See Copyright Notice in lua.h +*/ + +#ifndef lgc_h +#define lgc_h + + +#include "lobject.h" + + +/* +** Possible states of the Garbage Collector +*/ +#define GCSpause 0 +#define GCSpropagate 1 +#define GCSsweepstring 2 +#define GCSsweep 3 +#define GCSfinalize 4 + + +/* +** some userful bit tricks +*/ +#define resetbits(x,m) ((x) &= cast(lu_byte, ~(m))) +#define setbits(x,m) ((x) |= (m)) +#define testbits(x,m) ((x) & (m)) +#define bitmask(b) (1<<(b)) +#define bit2mask(b1,b2) (bitmask(b1) | bitmask(b2)) +#define l_setbit(x,b) setbits(x, bitmask(b)) +#define resetbit(x,b) resetbits(x, bitmask(b)) +#define testbit(x,b) testbits(x, bitmask(b)) +#define set2bits(x,b1,b2) setbits(x, (bit2mask(b1, b2))) +#define reset2bits(x,b1,b2) resetbits(x, (bit2mask(b1, b2))) +#define test2bits(x,b1,b2) testbits(x, (bit2mask(b1, b2))) + + + +/* +** Layout for bit use in `marked' field: +** bit 0 - object is white (type 0) +** bit 1 - object is white (type 1) +** bit 2 - object is black +** bit 3 - for userdata: has been finalized +** bit 3 - for tables: has weak keys +** bit 4 - for tables: has weak values +** bit 5 - object is fixed (should not be collected) +** bit 6 - object is "super" fixed (only the main thread) +*/ + + +#define WHITE0BIT 0 +#define WHITE1BIT 1 +#define BLACKBIT 2 +#define FINALIZEDBIT 3 +#define KEYWEAKBIT 3 +#define VALUEWEAKBIT 4 +#define FIXEDBIT 5 +#define SFIXEDBIT 6 +#define WHITEBITS bit2mask(WHITE0BIT, WHITE1BIT) + + +#define iswhite(x) test2bits((x)->gch.marked, WHITE0BIT, WHITE1BIT) +#define isblack(x) testbit((x)->gch.marked, BLACKBIT) +#define isgray(x) (!isblack(x) && !iswhite(x)) + +#define otherwhite(g) (g->currentwhite ^ WHITEBITS) +#define isdead(g,v) ((v)->gch.marked & otherwhite(g) & WHITEBITS) + +#define changewhite(x) ((x)->gch.marked ^= WHITEBITS) +#define gray2black(x) l_setbit((x)->gch.marked, BLACKBIT) + +#define valiswhite(x) (iscollectable(x) && iswhite(gcvalue(x))) + +#define luaC_white(g) cast(lu_byte, (g)->currentwhite & WHITEBITS) + + +#define luaC_checkGC(L) { \ + condhardstacktests(luaD_reallocstack(L, L->stacksize - EXTRA_STACK - 1)); \ + if (G(L)->totalbytes >= G(L)->GCthreshold) \ + luaC_step(L); } + + +#define luaC_barrier(L,p,v) { if (valiswhite(v) && isblack(obj2gco(p))) \ + luaC_barrierf(L,obj2gco(p),gcvalue(v)); } + +#define luaC_barriert(L,t,v) { if (valiswhite(v) && isblack(obj2gco(t))) \ + luaC_barrierback(L,t); } + +#define luaC_objbarrier(L,p,o) \ + { if (iswhite(obj2gco(o)) && isblack(obj2gco(p))) \ + luaC_barrierf(L,obj2gco(p),obj2gco(o)); } + +#define luaC_objbarriert(L,t,o) \ + { if (iswhite(obj2gco(o)) && isblack(obj2gco(t))) luaC_barrierback(L,t); } + +LUAI_FUNC size_t luaC_separateudata (lua_State *L, int all); +LUAI_FUNC void luaC_callGCTM (lua_State *L); +LUAI_FUNC void luaC_freeall (lua_State *L); +LUAI_FUNC void luaC_step (lua_State *L); +LUAI_FUNC void luaC_fullgc (lua_State *L); +LUAI_FUNC void luaC_link (lua_State *L, GCObject *o, lu_byte tt); +LUAI_FUNC void luaC_linkupval (lua_State *L, UpVal *uv); +LUAI_FUNC void luaC_barrierf (lua_State *L, GCObject *o, GCObject *v); +LUAI_FUNC void luaC_barrierback (lua_State *L, Table *t); + + +#endif diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/linit.c b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/linit.c new file mode 100644 index 00000000..c1f90dfa --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/linit.c @@ -0,0 +1,38 @@ +/* +** $Id: linit.c,v 1.14.1.1 2007/12/27 13:02:25 roberto Exp $ +** Initialization of libraries for lua.c +** See Copyright Notice in lua.h +*/ + + +#define linit_c +#define LUA_LIB + +#include "lua.h" + +#include "lualib.h" +#include "lauxlib.h" + + +static const luaL_Reg lualibs[] = { + {"", luaopen_base}, + {LUA_LOADLIBNAME, luaopen_package}, + {LUA_TABLIBNAME, luaopen_table}, + {LUA_IOLIBNAME, luaopen_io}, + {LUA_OSLIBNAME, luaopen_os}, + {LUA_STRLIBNAME, luaopen_string}, + {LUA_MATHLIBNAME, luaopen_math}, + {LUA_DBLIBNAME, luaopen_debug}, + {NULL, NULL} +}; + + +LUALIB_API void luaL_openlibs (lua_State *L) { + const luaL_Reg *lib = lualibs; + for (; lib->func; lib++) { + lua_pushcfunction(L, lib->func); + lua_pushstring(L, lib->name); + lua_call(L, 1, 0); + } +} + diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/liolib.c b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/liolib.c new file mode 100644 index 00000000..e79ed1cb --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/liolib.c @@ -0,0 +1,553 @@ +/* +** $Id: liolib.c,v 2.73.1.3 2008/01/18 17:47:43 roberto Exp $ +** Standard I/O (and system) library +** See Copyright Notice in lua.h +*/ + + +#include +#include +#include +#include + +#define liolib_c +#define LUA_LIB + +#include "lua.h" + +#include "lauxlib.h" +#include "lualib.h" + + + +#define IO_INPUT 1 +#define IO_OUTPUT 2 + + +static const char *const fnames[] = {"input", "output"}; + + +static int pushresult (lua_State *L, int i, const char *filename) { + int en = errno; /* calls to Lua API may change this value */ + if (i) { + lua_pushboolean(L, 1); + return 1; + } + else { + lua_pushnil(L); + if (filename) + lua_pushfstring(L, "%s: %s", filename, strerror(en)); + else + lua_pushfstring(L, "%s", strerror(en)); + lua_pushinteger(L, en); + return 3; + } +} + + +static void fileerror (lua_State *L, int arg, const char *filename) { + lua_pushfstring(L, "%s: %s", filename, strerror(errno)); + luaL_argerror(L, arg, lua_tostring(L, -1)); +} + + +#define tofilep(L) ((FILE **)luaL_checkudata(L, 1, LUA_FILEHANDLE)) + + +static int io_type (lua_State *L) { + void *ud; + luaL_checkany(L, 1); + ud = lua_touserdata(L, 1); + lua_getfield(L, LUA_REGISTRYINDEX, LUA_FILEHANDLE); + if (ud == NULL || !lua_getmetatable(L, 1) || !lua_rawequal(L, -2, -1)) + lua_pushnil(L); /* not a file */ + else if (*((FILE **)ud) == NULL) + lua_pushliteral(L, "closed file"); + else + lua_pushliteral(L, "file"); + return 1; +} + + +static FILE *tofile (lua_State *L) { + FILE **f = tofilep(L); + if (*f == NULL) + luaL_error(L, "attempt to use a closed file"); + return *f; +} + + + +/* +** When creating file handles, always creates a `closed' file handle +** before opening the actual file; so, if there is a memory error, the +** file is not left opened. +*/ +static FILE **newfile (lua_State *L) { + FILE **pf = (FILE **)lua_newuserdata(L, sizeof(FILE *)); + *pf = NULL; /* file handle is currently `closed' */ + luaL_getmetatable(L, LUA_FILEHANDLE); + lua_setmetatable(L, -2); + return pf; +} + + +/* +** function to (not) close the standard files stdin, stdout, and stderr +*/ +static int io_noclose (lua_State *L) { + lua_pushnil(L); + lua_pushliteral(L, "cannot close standard file"); + return 2; +} + + +/* +** function to close 'popen' files +*/ +static int io_pclose (lua_State *L) { + FILE **p = tofilep(L); + int ok = lua_pclose(L, *p); + *p = NULL; + return pushresult(L, ok, NULL); +} + + +/* +** function to close regular files +*/ +static int io_fclose (lua_State *L) { + FILE **p = tofilep(L); + int ok = (fclose(*p) == 0); + *p = NULL; + return pushresult(L, ok, NULL); +} + + +static int aux_close (lua_State *L) { + lua_getfenv(L, 1); + lua_getfield(L, -1, "__close"); + return (lua_tocfunction(L, -1))(L); +} + + +static int io_close (lua_State *L) { + if (lua_isnone(L, 1)) + lua_rawgeti(L, LUA_ENVIRONINDEX, IO_OUTPUT); + tofile(L); /* make sure argument is a file */ + return aux_close(L); +} + + +static int io_gc (lua_State *L) { + FILE *f = *tofilep(L); + /* ignore closed files */ + if (f != NULL) + aux_close(L); + return 0; +} + + +static int io_tostring (lua_State *L) { + FILE *f = *tofilep(L); + if (f == NULL) + lua_pushliteral(L, "file (closed)"); + else + lua_pushfstring(L, "file (%p)", f); + return 1; +} + + +static int io_open (lua_State *L) { + const char *filename = luaL_checkstring(L, 1); + const char *mode = luaL_optstring(L, 2, "r"); + FILE **pf = newfile(L); + *pf = fopen(filename, mode); + return (*pf == NULL) ? pushresult(L, 0, filename) : 1; +} + + +/* +** this function has a separated environment, which defines the +** correct __close for 'popen' files +*/ +static int io_popen (lua_State *L) { + const char *filename = luaL_checkstring(L, 1); + const char *mode = luaL_optstring(L, 2, "r"); + FILE **pf = newfile(L); + *pf = lua_popen(L, filename, mode); + return (*pf == NULL) ? pushresult(L, 0, filename) : 1; +} + + +static int io_tmpfile (lua_State *L) { + FILE **pf = newfile(L); + *pf = tmpfile(); + return (*pf == NULL) ? pushresult(L, 0, NULL) : 1; +} + + +static FILE *getiofile (lua_State *L, int findex) { + FILE *f; + lua_rawgeti(L, LUA_ENVIRONINDEX, findex); + f = *(FILE **)lua_touserdata(L, -1); + if (f == NULL) + luaL_error(L, "standard %s file is closed", fnames[findex - 1]); + return f; +} + + +static int g_iofile (lua_State *L, int f, const char *mode) { + if (!lua_isnoneornil(L, 1)) { + const char *filename = lua_tostring(L, 1); + if (filename) { + FILE **pf = newfile(L); + *pf = fopen(filename, mode); + if (*pf == NULL) + fileerror(L, 1, filename); + } + else { + tofile(L); /* check that it's a valid file handle */ + lua_pushvalue(L, 1); + } + lua_rawseti(L, LUA_ENVIRONINDEX, f); + } + /* return current value */ + lua_rawgeti(L, LUA_ENVIRONINDEX, f); + return 1; +} + + +static int io_input (lua_State *L) { + return g_iofile(L, IO_INPUT, "r"); +} + + +static int io_output (lua_State *L) { + return g_iofile(L, IO_OUTPUT, "w"); +} + + +static int io_readline (lua_State *L); + + +static void aux_lines (lua_State *L, int idx, int toclose) { + lua_pushvalue(L, idx); + lua_pushboolean(L, toclose); /* close/not close file when finished */ + lua_pushcclosure(L, io_readline, 2); +} + + +static int f_lines (lua_State *L) { + tofile(L); /* check that it's a valid file handle */ + aux_lines(L, 1, 0); + return 1; +} + + +static int io_lines (lua_State *L) { + if (lua_isnoneornil(L, 1)) { /* no arguments? */ + /* will iterate over default input */ + lua_rawgeti(L, LUA_ENVIRONINDEX, IO_INPUT); + return f_lines(L); + } + else { + const char *filename = luaL_checkstring(L, 1); + FILE **pf = newfile(L); + *pf = fopen(filename, "r"); + if (*pf == NULL) + fileerror(L, 1, filename); + aux_lines(L, lua_gettop(L), 1); + return 1; + } +} + + +/* +** {====================================================== +** READ +** ======================================================= +*/ + + +static int read_number (lua_State *L, FILE *f) { + lua_Number d; + if (fscanf(f, LUA_NUMBER_SCAN, &d) == 1) { + lua_pushnumber(L, d); + return 1; + } + else return 0; /* read fails */ +} + + +static int test_eof (lua_State *L, FILE *f) { + int c = getc(f); + ungetc(c, f); + lua_pushlstring(L, NULL, 0); + return (c != EOF); +} + + +static int read_line (lua_State *L, FILE *f) { + luaL_Buffer b; + luaL_buffinit(L, &b); + for (;;) { + size_t l; + char *p = luaL_prepbuffer(&b); + if (fgets(p, LUAL_BUFFERSIZE, f) == NULL) { /* eof? */ + luaL_pushresult(&b); /* close buffer */ + return (lua_objlen(L, -1) > 0); /* check whether read something */ + } + l = strlen(p); + if (l == 0 || p[l-1] != '\n') + luaL_addsize(&b, l); + else { + luaL_addsize(&b, l - 1); /* do not include `eol' */ + luaL_pushresult(&b); /* close buffer */ + return 1; /* read at least an `eol' */ + } + } +} + + +static int read_chars (lua_State *L, FILE *f, size_t n) { + size_t rlen; /* how much to read */ + size_t nr; /* number of chars actually read */ + luaL_Buffer b; + luaL_buffinit(L, &b); + rlen = LUAL_BUFFERSIZE; /* try to read that much each time */ + do { + char *p = luaL_prepbuffer(&b); + if (rlen > n) rlen = n; /* cannot read more than asked */ + nr = fread(p, sizeof(char), rlen, f); + luaL_addsize(&b, nr); + n -= nr; /* still have to read `n' chars */ + } while (n > 0 && nr == rlen); /* until end of count or eof */ + luaL_pushresult(&b); /* close buffer */ + return (n == 0 || lua_objlen(L, -1) > 0); +} + + +static int g_read (lua_State *L, FILE *f, int first) { + int nargs = lua_gettop(L) - 1; + int success; + int n; + clearerr(f); + if (nargs == 0) { /* no arguments? */ + success = read_line(L, f); + n = first+1; /* to return 1 result */ + } + else { /* ensure stack space for all results and for auxlib's buffer */ + luaL_checkstack(L, nargs+LUA_MINSTACK, "too many arguments"); + success = 1; + for (n = first; nargs-- && success; n++) { + if (lua_type(L, n) == LUA_TNUMBER) { + size_t l = (size_t)lua_tointeger(L, n); + success = (l == 0) ? test_eof(L, f) : read_chars(L, f, l); + } + else { + const char *p = lua_tostring(L, n); + luaL_argcheck(L, p && p[0] == '*', n, "invalid option"); + switch (p[1]) { + case 'n': /* number */ + success = read_number(L, f); + break; + case 'l': /* line */ + success = read_line(L, f); + break; + case 'a': /* file */ + read_chars(L, f, ~((size_t)0)); /* read MAX_SIZE_T chars */ + success = 1; /* always success */ + break; + default: + return luaL_argerror(L, n, "invalid format"); + } + } + } + } + if (ferror(f)) + return pushresult(L, 0, NULL); + if (!success) { + lua_pop(L, 1); /* remove last result */ + lua_pushnil(L); /* push nil instead */ + } + return n - first; +} + + +static int io_read (lua_State *L) { + return g_read(L, getiofile(L, IO_INPUT), 1); +} + + +static int f_read (lua_State *L) { + return g_read(L, tofile(L), 2); +} + + +static int io_readline (lua_State *L) { + FILE *f = *(FILE **)lua_touserdata(L, lua_upvalueindex(1)); + int sucess; + if (f == NULL) /* file is already closed? */ + luaL_error(L, "file is already closed"); + sucess = read_line(L, f); + if (ferror(f)) + return luaL_error(L, "%s", strerror(errno)); + if (sucess) return 1; + else { /* EOF */ + if (lua_toboolean(L, lua_upvalueindex(2))) { /* generator created file? */ + lua_settop(L, 0); + lua_pushvalue(L, lua_upvalueindex(1)); + aux_close(L); /* close it */ + } + return 0; + } +} + +/* }====================================================== */ + + +static int g_write (lua_State *L, FILE *f, int arg) { + int nargs = lua_gettop(L) - 1; + int status = 1; + for (; nargs--; arg++) { + if (lua_type(L, arg) == LUA_TNUMBER) { + /* optimization: could be done exactly as for strings */ + status = status && + fprintf(f, LUA_NUMBER_FMT, lua_tonumber(L, arg)) > 0; + } + else { + size_t l; + const char *s = luaL_checklstring(L, arg, &l); + status = status && (fwrite(s, sizeof(char), l, f) == l); + } + } + return pushresult(L, status, NULL); +} + + +static int io_write (lua_State *L) { + return g_write(L, getiofile(L, IO_OUTPUT), 1); +} + + +static int f_write (lua_State *L) { + return g_write(L, tofile(L), 2); +} + + +static int f_seek (lua_State *L) { + static const int mode[] = {SEEK_SET, SEEK_CUR, SEEK_END}; + static const char *const modenames[] = {"set", "cur", "end", NULL}; + FILE *f = tofile(L); + int op = luaL_checkoption(L, 2, "cur", modenames); + long offset = luaL_optlong(L, 3, 0); + op = fseek(f, offset, mode[op]); + if (op) + return pushresult(L, 0, NULL); /* error */ + else { + lua_pushinteger(L, ftell(f)); + return 1; + } +} + + +static int f_setvbuf (lua_State *L) { + static const int mode[] = {_IONBF, _IOFBF, _IOLBF}; + static const char *const modenames[] = {"no", "full", "line", NULL}; + FILE *f = tofile(L); + int op = luaL_checkoption(L, 2, NULL, modenames); + lua_Integer sz = luaL_optinteger(L, 3, LUAL_BUFFERSIZE); + int res = setvbuf(f, NULL, mode[op], sz); + return pushresult(L, res == 0, NULL); +} + + + +static int io_flush (lua_State *L) { + return pushresult(L, fflush(getiofile(L, IO_OUTPUT)) == 0, NULL); +} + + +static int f_flush (lua_State *L) { + return pushresult(L, fflush(tofile(L)) == 0, NULL); +} + + +static const luaL_Reg iolib[] = { + {"close", io_close}, + {"flush", io_flush}, + {"input", io_input}, + {"lines", io_lines}, + {"open", io_open}, + {"output", io_output}, + {"popen", io_popen}, + {"read", io_read}, + {"tmpfile", io_tmpfile}, + {"type", io_type}, + {"write", io_write}, + {NULL, NULL} +}; + + +static const luaL_Reg flib[] = { + {"close", io_close}, + {"flush", f_flush}, + {"lines", f_lines}, + {"read", f_read}, + {"seek", f_seek}, + {"setvbuf", f_setvbuf}, + {"write", f_write}, + {"__gc", io_gc}, + {"__tostring", io_tostring}, + {NULL, NULL} +}; + + +static void createmeta (lua_State *L) { + luaL_newmetatable(L, LUA_FILEHANDLE); /* create metatable for file handles */ + lua_pushvalue(L, -1); /* push metatable */ + lua_setfield(L, -2, "__index"); /* metatable.__index = metatable */ + luaL_register(L, NULL, flib); /* file methods */ +} + + +static void createstdfile (lua_State *L, FILE *f, int k, const char *fname) { + *newfile(L) = f; + if (k > 0) { + lua_pushvalue(L, -1); + lua_rawseti(L, LUA_ENVIRONINDEX, k); + } + lua_pushvalue(L, -2); /* copy environment */ + lua_setfenv(L, -2); /* set it */ + lua_setfield(L, -3, fname); +} + + +static void newfenv (lua_State *L, lua_CFunction cls) { + lua_createtable(L, 0, 1); + lua_pushcfunction(L, cls); + lua_setfield(L, -2, "__close"); +} + + +LUALIB_API int luaopen_io (lua_State *L) { + createmeta(L); + /* create (private) environment (with fields IO_INPUT, IO_OUTPUT, __close) */ + newfenv(L, io_fclose); + lua_replace(L, LUA_ENVIRONINDEX); + /* open library */ + luaL_register(L, LUA_IOLIBNAME, iolib); + /* create (and set) default files */ + newfenv(L, io_noclose); /* close function for default files */ + createstdfile(L, stdin, IO_INPUT, "stdin"); + createstdfile(L, stdout, IO_OUTPUT, "stdout"); + createstdfile(L, stderr, 0, "stderr"); + lua_pop(L, 1); /* pop environment for default files */ + lua_getfield(L, -1, "popen"); + newfenv(L, io_pclose); /* create environment for 'popen' */ + lua_setfenv(L, -2); /* set fenv for 'popen' */ + lua_pop(L, 1); /* pop 'popen' */ + return 1; +} + diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/llex.c b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/llex.c new file mode 100644 index 00000000..6dc31935 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/llex.c @@ -0,0 +1,461 @@ +/* +** $Id: llex.c,v 2.20.1.1 2007/12/27 13:02:25 roberto Exp $ +** Lexical Analyzer +** See Copyright Notice in lua.h +*/ + + +#include +#include +#include + +#define llex_c +#define LUA_CORE + +#include "lua.h" + +#include "ldo.h" +#include "llex.h" +#include "lobject.h" +#include "lparser.h" +#include "lstate.h" +#include "lstring.h" +#include "ltable.h" +#include "lzio.h" + + + +#define next(ls) (ls->current = zgetc(ls->z)) + + + + +#define currIsNewline(ls) (ls->current == '\n' || ls->current == '\r') + + +/* ORDER RESERVED */ +const char *const luaX_tokens [] = { + "and", "break", "do", "else", "elseif", + "end", "false", "for", "function", "if", + "in", "local", "nil", "not", "or", "repeat", + "return", "then", "true", "until", "while", + "..", "...", "==", ">=", "<=", "~=", + "", "", "", "", + NULL +}; + + +#define save_and_next(ls) (save(ls, ls->current), next(ls)) + + +static void save (LexState *ls, int c) { + Mbuffer *b = ls->buff; + if (b->n + 1 > b->buffsize) { + size_t newsize; + if (b->buffsize >= MAX_SIZET/2) + luaX_lexerror(ls, "lexical element too long", 0); + newsize = b->buffsize * 2; + luaZ_resizebuffer(ls->L, b, newsize); + } + b->buffer[b->n++] = cast(char, c); +} + + +void luaX_init (lua_State *L) { + int i; + for (i=0; itsv.reserved = cast_byte(i+1); /* reserved word */ + } +} + + +#define MAXSRC 80 + + +const char *luaX_token2str (LexState *ls, int token) { + if (token < FIRST_RESERVED) { + lua_assert(token == cast(unsigned char, token)); + return (iscntrl(token)) ? luaO_pushfstring(ls->L, "char(%d)", token) : + luaO_pushfstring(ls->L, "%c", token); + } + else + return luaX_tokens[token-FIRST_RESERVED]; +} + + +static const char *txtToken (LexState *ls, int token) { + switch (token) { + case TK_NAME: + case TK_STRING: + case TK_NUMBER: + save(ls, '\0'); + return luaZ_buffer(ls->buff); + default: + return luaX_token2str(ls, token); + } +} + + +void luaX_lexerror (LexState *ls, const char *msg, int token) { + char buff[MAXSRC]; + luaO_chunkid(buff, getstr(ls->source), MAXSRC); + msg = luaO_pushfstring(ls->L, "%s:%d: %s", buff, ls->linenumber, msg); + if (token) + luaO_pushfstring(ls->L, "%s near " LUA_QS, msg, txtToken(ls, token)); + luaD_throw(ls->L, LUA_ERRSYNTAX); +} + + +void luaX_syntaxerror (LexState *ls, const char *msg) { + luaX_lexerror(ls, msg, ls->t.token); +} + + +TString *luaX_newstring (LexState *ls, const char *str, size_t l) { + lua_State *L = ls->L; + TString *ts = luaS_newlstr(L, str, l); + TValue *o = luaH_setstr(L, ls->fs->h, ts); /* entry for `str' */ + if (ttisnil(o)) + setbvalue(o, 1); /* make sure `str' will not be collected */ + return ts; +} + + +static void inclinenumber (LexState *ls) { + int old = ls->current; + lua_assert(currIsNewline(ls)); + next(ls); /* skip `\n' or `\r' */ + if (currIsNewline(ls) && ls->current != old) + next(ls); /* skip `\n\r' or `\r\n' */ + if (++ls->linenumber >= MAX_INT) + luaX_syntaxerror(ls, "chunk has too many lines"); +} + + +void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source) { + ls->decpoint = '.'; + ls->L = L; + ls->lookahead.token = TK_EOS; /* no look-ahead token */ + ls->z = z; + ls->fs = NULL; + ls->linenumber = 1; + ls->lastline = 1; + ls->source = source; + luaZ_resizebuffer(ls->L, ls->buff, LUA_MINBUFFER); /* initialize buffer */ + next(ls); /* read first char */ +} + + + +/* +** ======================================================= +** LEXICAL ANALYZER +** ======================================================= +*/ + + + +static int check_next (LexState *ls, const char *set) { + if (!strchr(set, ls->current)) + return 0; + save_and_next(ls); + return 1; +} + + +static void buffreplace (LexState *ls, char from, char to) { + size_t n = luaZ_bufflen(ls->buff); + char *p = luaZ_buffer(ls->buff); + while (n--) + if (p[n] == from) p[n] = to; +} + + +static void trydecpoint (LexState *ls, SemInfo *seminfo) { + /* format error: try to update decimal point separator */ + struct lconv *cv = localeconv(); + char old = ls->decpoint; + ls->decpoint = (cv ? cv->decimal_point[0] : '.'); + buffreplace(ls, old, ls->decpoint); /* try updated decimal separator */ + if (!luaO_str2d(luaZ_buffer(ls->buff), &seminfo->r)) { + /* format error with correct decimal point: no more options */ + buffreplace(ls, ls->decpoint, '.'); /* undo change (for error message) */ + luaX_lexerror(ls, "malformed number", TK_NUMBER); + } +} + + +/* LUA_NUMBER */ +static void read_numeral (LexState *ls, SemInfo *seminfo) { + lua_assert(isdigit(ls->current)); + do { + save_and_next(ls); + } while (isdigit(ls->current) || ls->current == '.'); + if (check_next(ls, "Ee")) /* `E'? */ + check_next(ls, "+-"); /* optional exponent sign */ + while (isalnum(ls->current) || ls->current == '_') + save_and_next(ls); + save(ls, '\0'); + buffreplace(ls, '.', ls->decpoint); /* follow locale for decimal point */ + if (!luaO_str2d(luaZ_buffer(ls->buff), &seminfo->r)) /* format error? */ + trydecpoint(ls, seminfo); /* try to update decimal point separator */ +} + + +static int skip_sep (LexState *ls) { + int count = 0; + int s = ls->current; + lua_assert(s == '[' || s == ']'); + save_and_next(ls); + while (ls->current == '=') { + save_and_next(ls); + count++; + } + return (ls->current == s) ? count : (-count) - 1; +} + + +static void read_long_string (LexState *ls, SemInfo *seminfo, int sep) { + int cont = 0; + (void)(cont); /* avoid warnings when `cont' is not used */ + save_and_next(ls); /* skip 2nd `[' */ + if (currIsNewline(ls)) /* string starts with a newline? */ + inclinenumber(ls); /* skip it */ + for (;;) { + switch (ls->current) { + case EOZ: + luaX_lexerror(ls, (seminfo) ? "unfinished long string" : + "unfinished long comment", TK_EOS); + break; /* to avoid warnings */ +#if defined(LUA_COMPAT_LSTR) + case '[': { + if (skip_sep(ls) == sep) { + save_and_next(ls); /* skip 2nd `[' */ + cont++; +#if LUA_COMPAT_LSTR == 1 + if (sep == 0) + luaX_lexerror(ls, "nesting of [[...]] is deprecated", '['); +#endif + } + break; + } +#endif + case ']': { + if (skip_sep(ls) == sep) { + save_and_next(ls); /* skip 2nd `]' */ +#if defined(LUA_COMPAT_LSTR) && LUA_COMPAT_LSTR == 2 + cont--; + if (sep == 0 && cont >= 0) break; +#endif + goto endloop; + } + break; + } + case '\n': + case '\r': { + save(ls, '\n'); + inclinenumber(ls); + if (!seminfo) luaZ_resetbuffer(ls->buff); /* avoid wasting space */ + break; + } + default: { + if (seminfo) save_and_next(ls); + else next(ls); + } + } + } endloop: + if (seminfo) + seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + (2 + sep), + luaZ_bufflen(ls->buff) - 2*(2 + sep)); +} + + +static void read_string (LexState *ls, int del, SemInfo *seminfo) { + save_and_next(ls); + while (ls->current != del) { + switch (ls->current) { + case EOZ: + luaX_lexerror(ls, "unfinished string", TK_EOS); + continue; /* to avoid warnings */ + case '\n': + case '\r': + luaX_lexerror(ls, "unfinished string", TK_STRING); + continue; /* to avoid warnings */ + case '\\': { + int c; + next(ls); /* do not save the `\' */ + switch (ls->current) { + case 'a': c = '\a'; break; + case 'b': c = '\b'; break; + case 'f': c = '\f'; break; + case 'n': c = '\n'; break; + case 'r': c = '\r'; break; + case 't': c = '\t'; break; + case 'v': c = '\v'; break; + case '\n': /* go through */ + case '\r': save(ls, '\n'); inclinenumber(ls); continue; + case EOZ: continue; /* will raise an error next loop */ + default: { + if (!isdigit(ls->current)) + save_and_next(ls); /* handles \\, \", \', and \? */ + else { /* \xxx */ + int i = 0; + c = 0; + do { + c = 10*c + (ls->current-'0'); + next(ls); + } while (++i<3 && isdigit(ls->current)); + if (c > UCHAR_MAX) + luaX_lexerror(ls, "escape sequence too large", TK_STRING); + save(ls, c); + } + continue; + } + } + save(ls, c); + next(ls); + continue; + } + default: + save_and_next(ls); + } + } + save_and_next(ls); /* skip delimiter */ + seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + 1, + luaZ_bufflen(ls->buff) - 2); +} + + +static int llex (LexState *ls, SemInfo *seminfo) { + luaZ_resetbuffer(ls->buff); + for (;;) { + switch (ls->current) { + case '\n': + case '\r': { + inclinenumber(ls); + continue; + } + case '-': { + next(ls); + if (ls->current != '-') return '-'; + /* else is a comment */ + next(ls); + if (ls->current == '[') { + int sep = skip_sep(ls); + luaZ_resetbuffer(ls->buff); /* `skip_sep' may dirty the buffer */ + if (sep >= 0) { + read_long_string(ls, NULL, sep); /* long comment */ + luaZ_resetbuffer(ls->buff); + continue; + } + } + /* else short comment */ + while (!currIsNewline(ls) && ls->current != EOZ) + next(ls); + continue; + } + case '[': { + int sep = skip_sep(ls); + if (sep >= 0) { + read_long_string(ls, seminfo, sep); + return TK_STRING; + } + else if (sep == -1) return '['; + else luaX_lexerror(ls, "invalid long string delimiter", TK_STRING); + } + case '=': { + next(ls); + if (ls->current != '=') return '='; + else { next(ls); return TK_EQ; } + } + case '<': { + next(ls); + if (ls->current != '=') return '<'; + else { next(ls); return TK_LE; } + } + case '>': { + next(ls); + if (ls->current != '=') return '>'; + else { next(ls); return TK_GE; } + } + case '~': { + next(ls); + if (ls->current != '=') return '~'; + else { next(ls); return TK_NE; } + } + case '"': + case '\'': { + read_string(ls, ls->current, seminfo); + return TK_STRING; + } + case '.': { + save_and_next(ls); + if (check_next(ls, ".")) { + if (check_next(ls, ".")) + return TK_DOTS; /* ... */ + else return TK_CONCAT; /* .. */ + } + else if (!isdigit(ls->current)) return '.'; + else { + read_numeral(ls, seminfo); + return TK_NUMBER; + } + } + case EOZ: { + return TK_EOS; + } + default: { + if (isspace(ls->current)) { + lua_assert(!currIsNewline(ls)); + next(ls); + continue; + } + else if (isdigit(ls->current)) { + read_numeral(ls, seminfo); + return TK_NUMBER; + } + else if (isalpha(ls->current) || ls->current == '_') { + /* identifier or reserved word */ + TString *ts; + do { + save_and_next(ls); + } while (isalnum(ls->current) || ls->current == '_'); + ts = luaX_newstring(ls, luaZ_buffer(ls->buff), + luaZ_bufflen(ls->buff)); + if (ts->tsv.reserved > 0) /* reserved word? */ + return ts->tsv.reserved - 1 + FIRST_RESERVED; + else { + seminfo->ts = ts; + return TK_NAME; + } + } + else { + int c = ls->current; + next(ls); + return c; /* single-char tokens (+ - / ...) */ + } + } + } + } +} + + +void luaX_next (LexState *ls) { + ls->lastline = ls->linenumber; + if (ls->lookahead.token != TK_EOS) { /* is there a look-ahead token? */ + ls->t = ls->lookahead; /* use this one */ + ls->lookahead.token = TK_EOS; /* and discharge it */ + } + else + ls->t.token = llex(ls, &ls->t.seminfo); /* read next token */ +} + + +void luaX_lookahead (LexState *ls) { + lua_assert(ls->lookahead.token == TK_EOS); + ls->lookahead.token = llex(ls, &ls->lookahead.seminfo); +} + diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/llex.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/llex.h new file mode 100644 index 00000000..a9201cee --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/llex.h @@ -0,0 +1,81 @@ +/* +** $Id: llex.h,v 1.58.1.1 2007/12/27 13:02:25 roberto Exp $ +** Lexical Analyzer +** See Copyright Notice in lua.h +*/ + +#ifndef llex_h +#define llex_h + +#include "lobject.h" +#include "lzio.h" + + +#define FIRST_RESERVED 257 + +/* maximum length of a reserved word */ +#define TOKEN_LEN (sizeof("function")/sizeof(char)) + + +/* +* WARNING: if you change the order of this enumeration, +* grep "ORDER RESERVED" +*/ +enum RESERVED { + /* terminal symbols denoted by reserved words */ + TK_AND = FIRST_RESERVED, TK_BREAK, + TK_DO, TK_ELSE, TK_ELSEIF, TK_END, TK_FALSE, TK_FOR, TK_FUNCTION, + TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT, + TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE, + /* other terminal symbols */ + TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, TK_NUMBER, + TK_NAME, TK_STRING, TK_EOS +}; + +/* number of reserved words */ +#define NUM_RESERVED (cast(int, TK_WHILE-FIRST_RESERVED+1)) + + +/* array with token `names' */ +LUAI_DATA const char *const luaX_tokens []; + + +typedef union { + lua_Number r; + TString *ts; +} SemInfo; /* semantics information */ + + +typedef struct Token { + int token; + SemInfo seminfo; +} Token; + + +typedef struct LexState { + int current; /* current character (charint) */ + int linenumber; /* input line counter */ + int lastline; /* line of last token `consumed' */ + Token t; /* current token */ + Token lookahead; /* look ahead token */ + struct FuncState *fs; /* `FuncState' is private to the parser */ + struct lua_State *L; + ZIO *z; /* input stream */ + Mbuffer *buff; /* buffer for tokens */ + TString *source; /* current source name */ + char decpoint; /* locale decimal point */ +} LexState; + + +LUAI_FUNC void luaX_init (lua_State *L); +LUAI_FUNC void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, + TString *source); +LUAI_FUNC TString *luaX_newstring (LexState *ls, const char *str, size_t l); +LUAI_FUNC void luaX_next (LexState *ls); +LUAI_FUNC void luaX_lookahead (LexState *ls); +LUAI_FUNC void luaX_lexerror (LexState *ls, const char *msg, int token); +LUAI_FUNC void luaX_syntaxerror (LexState *ls, const char *s); +LUAI_FUNC const char *luaX_token2str (LexState *ls, int token); + + +#endif diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/llimits.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/llimits.h new file mode 100644 index 00000000..ca8dcb72 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/llimits.h @@ -0,0 +1,128 @@ +/* +** $Id: llimits.h,v 1.69.1.1 2007/12/27 13:02:25 roberto Exp $ +** Limits, basic types, and some other `installation-dependent' definitions +** See Copyright Notice in lua.h +*/ + +#ifndef llimits_h +#define llimits_h + + +#include +#include + + +#include "lua.h" + + +typedef LUAI_UINT32 lu_int32; + +typedef LUAI_UMEM lu_mem; + +typedef LUAI_MEM l_mem; + + + +/* chars used as small naturals (so that `char' is reserved for characters) */ +typedef unsigned char lu_byte; + + +#define MAX_SIZET ((size_t)(~(size_t)0)-2) + +#define MAX_LUMEM ((lu_mem)(~(lu_mem)0)-2) + + +#define MAX_INT (INT_MAX-2) /* maximum value of an int (-2 for safety) */ + +/* +** conversion of pointer to integer +** this is for hashing only; there is no problem if the integer +** cannot hold the whole pointer value +*/ +#define IntPoint(p) ((unsigned int)(lu_mem)(p)) + + + +/* type to ensure maximum alignment */ +typedef LUAI_USER_ALIGNMENT_T L_Umaxalign; + + +/* result of a `usual argument conversion' over lua_Number */ +typedef LUAI_UACNUMBER l_uacNumber; + + +/* internal assertions for in-house debugging */ +#ifdef lua_assert + +#define check_exp(c,e) (lua_assert(c), (e)) +#define api_check(l,e) lua_assert(e) + +#else + +#define lua_assert(c) ((void)0) +#define check_exp(c,e) (e) +#define api_check luai_apicheck + +#endif + + +#ifndef UNUSED +#define UNUSED(x) ((void)(x)) /* to avoid warnings */ +#endif + + +#ifndef cast +#define cast(t, exp) ((t)(exp)) +#endif + +#define cast_byte(i) cast(lu_byte, (i)) +#define cast_num(i) cast(lua_Number, (i)) +#define cast_int(i) cast(int, (i)) + + + +/* +** type for virtual-machine instructions +** must be an unsigned with (at least) 4 bytes (see details in lopcodes.h) +*/ +typedef lu_int32 Instruction; + + + +/* maximum stack for a Lua function */ +#define MAXSTACK 250 + + + +/* minimum size for the string table (must be power of 2) */ +#ifndef MINSTRTABSIZE +#define MINSTRTABSIZE 32 +#endif + + +/* minimum size for string buffer */ +#ifndef LUA_MINBUFFER +#define LUA_MINBUFFER 32 +#endif + + +#ifndef lua_lock +#define lua_lock(L) ((void) 0) +#define lua_unlock(L) ((void) 0) +#endif + +#ifndef luai_threadyield +#define luai_threadyield(L) {lua_unlock(L); lua_lock(L);} +#endif + + +/* +** macro to control inclusion of some hard tests on stack reallocation +*/ +#ifndef HARDSTACKTESTS +#define condhardstacktests(x) ((void)0) +#else +#define condhardstacktests(x) x +#endif + +#endif diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lmathlib.c b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lmathlib.c new file mode 100644 index 00000000..441fbf73 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lmathlib.c @@ -0,0 +1,263 @@ +/* +** $Id: lmathlib.c,v 1.67.1.1 2007/12/27 13:02:25 roberto Exp $ +** Standard mathematical library +** See Copyright Notice in lua.h +*/ + + +#include +#include + +#define lmathlib_c +#define LUA_LIB + +#include "lua.h" + +#include "lauxlib.h" +#include "lualib.h" + + +#undef PI +#define PI (3.14159265358979323846) +#define RADIANS_PER_DEGREE (PI/180.0) + + + +static int math_abs (lua_State *L) { + lua_pushnumber(L, fabs(luaL_checknumber(L, 1))); + return 1; +} + +static int math_sin (lua_State *L) { + lua_pushnumber(L, sin(luaL_checknumber(L, 1))); + return 1; +} + +static int math_sinh (lua_State *L) { + lua_pushnumber(L, sinh(luaL_checknumber(L, 1))); + return 1; +} + +static int math_cos (lua_State *L) { + lua_pushnumber(L, cos(luaL_checknumber(L, 1))); + return 1; +} + +static int math_cosh (lua_State *L) { + lua_pushnumber(L, cosh(luaL_checknumber(L, 1))); + return 1; +} + +static int math_tan (lua_State *L) { + lua_pushnumber(L, tan(luaL_checknumber(L, 1))); + return 1; +} + +static int math_tanh (lua_State *L) { + lua_pushnumber(L, tanh(luaL_checknumber(L, 1))); + return 1; +} + +static int math_asin (lua_State *L) { + lua_pushnumber(L, asin(luaL_checknumber(L, 1))); + return 1; +} + +static int math_acos (lua_State *L) { + lua_pushnumber(L, acos(luaL_checknumber(L, 1))); + return 1; +} + +static int math_atan (lua_State *L) { + lua_pushnumber(L, atan(luaL_checknumber(L, 1))); + return 1; +} + +static int math_atan2 (lua_State *L) { + lua_pushnumber(L, atan2(luaL_checknumber(L, 1), luaL_checknumber(L, 2))); + return 1; +} + +static int math_ceil (lua_State *L) { + lua_pushnumber(L, ceil(luaL_checknumber(L, 1))); + return 1; +} + +static int math_floor (lua_State *L) { + lua_pushnumber(L, floor(luaL_checknumber(L, 1))); + return 1; +} + +static int math_fmod (lua_State *L) { + lua_pushnumber(L, fmod(luaL_checknumber(L, 1), luaL_checknumber(L, 2))); + return 1; +} + +static int math_modf (lua_State *L) { + double ip; + double fp = modf(luaL_checknumber(L, 1), &ip); + lua_pushnumber(L, ip); + lua_pushnumber(L, fp); + return 2; +} + +static int math_sqrt (lua_State *L) { + lua_pushnumber(L, sqrt(luaL_checknumber(L, 1))); + return 1; +} + +static int math_pow (lua_State *L) { + lua_pushnumber(L, pow(luaL_checknumber(L, 1), luaL_checknumber(L, 2))); + return 1; +} + +static int math_log (lua_State *L) { + lua_pushnumber(L, log(luaL_checknumber(L, 1))); + return 1; +} + +static int math_log10 (lua_State *L) { + lua_pushnumber(L, log10(luaL_checknumber(L, 1))); + return 1; +} + +static int math_exp (lua_State *L) { + lua_pushnumber(L, exp(luaL_checknumber(L, 1))); + return 1; +} + +static int math_deg (lua_State *L) { + lua_pushnumber(L, luaL_checknumber(L, 1)/RADIANS_PER_DEGREE); + return 1; +} + +static int math_rad (lua_State *L) { + lua_pushnumber(L, luaL_checknumber(L, 1)*RADIANS_PER_DEGREE); + return 1; +} + +static int math_frexp (lua_State *L) { + int e; + lua_pushnumber(L, frexp(luaL_checknumber(L, 1), &e)); + lua_pushinteger(L, e); + return 2; +} + +static int math_ldexp (lua_State *L) { + lua_pushnumber(L, ldexp(luaL_checknumber(L, 1), luaL_checkint(L, 2))); + return 1; +} + + + +static int math_min (lua_State *L) { + int n = lua_gettop(L); /* number of arguments */ + lua_Number dmin = luaL_checknumber(L, 1); + int i; + for (i=2; i<=n; i++) { + lua_Number d = luaL_checknumber(L, i); + if (d < dmin) + dmin = d; + } + lua_pushnumber(L, dmin); + return 1; +} + + +static int math_max (lua_State *L) { + int n = lua_gettop(L); /* number of arguments */ + lua_Number dmax = luaL_checknumber(L, 1); + int i; + for (i=2; i<=n; i++) { + lua_Number d = luaL_checknumber(L, i); + if (d > dmax) + dmax = d; + } + lua_pushnumber(L, dmax); + return 1; +} + + +static int math_random (lua_State *L) { + /* the `%' avoids the (rare) case of r==1, and is needed also because on + some systems (SunOS!) `rand()' may return a value larger than RAND_MAX */ + lua_Number r = (lua_Number)(rand()%RAND_MAX) / (lua_Number)RAND_MAX; + switch (lua_gettop(L)) { /* check number of arguments */ + case 0: { /* no arguments */ + lua_pushnumber(L, r); /* Number between 0 and 1 */ + break; + } + case 1: { /* only upper limit */ + int u = luaL_checkint(L, 1); + luaL_argcheck(L, 1<=u, 1, "interval is empty"); + lua_pushnumber(L, floor(r*u)+1); /* int between 1 and `u' */ + break; + } + case 2: { /* lower and upper limits */ + int l = luaL_checkint(L, 1); + int u = luaL_checkint(L, 2); + luaL_argcheck(L, l<=u, 2, "interval is empty"); + lua_pushnumber(L, floor(r*(u-l+1))+l); /* int between `l' and `u' */ + break; + } + default: return luaL_error(L, "wrong number of arguments"); + } + return 1; +} + + +static int math_randomseed (lua_State *L) { + srand(luaL_checkint(L, 1)); + return 0; +} + + +static const luaL_Reg mathlib[] = { + {"abs", math_abs}, + {"acos", math_acos}, + {"asin", math_asin}, + {"atan2", math_atan2}, + {"atan", math_atan}, + {"ceil", math_ceil}, + {"cosh", math_cosh}, + {"cos", math_cos}, + {"deg", math_deg}, + {"exp", math_exp}, + {"floor", math_floor}, + {"fmod", math_fmod}, + {"frexp", math_frexp}, + {"ldexp", math_ldexp}, + {"log10", math_log10}, + {"log", math_log}, + {"max", math_max}, + {"min", math_min}, + {"modf", math_modf}, + {"pow", math_pow}, + {"rad", math_rad}, + {"random", math_random}, + {"randomseed", math_randomseed}, + {"sinh", math_sinh}, + {"sin", math_sin}, + {"sqrt", math_sqrt}, + {"tanh", math_tanh}, + {"tan", math_tan}, + {NULL, NULL} +}; + + +/* +** Open math library +*/ +LUALIB_API int luaopen_math (lua_State *L) { + luaL_register(L, LUA_MATHLIBNAME, mathlib); + lua_pushnumber(L, PI); + lua_setfield(L, -2, "pi"); + lua_pushnumber(L, HUGE_VAL); + lua_setfield(L, -2, "huge"); +#if defined(LUA_COMPAT_MOD) + lua_getfield(L, -1, "fmod"); + lua_setfield(L, -2, "mod"); +#endif + return 1; +} + diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lmem.c b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lmem.c new file mode 100644 index 00000000..ae7d8c96 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lmem.c @@ -0,0 +1,86 @@ +/* +** $Id: lmem.c,v 1.70.1.1 2007/12/27 13:02:25 roberto Exp $ +** Interface to Memory Manager +** See Copyright Notice in lua.h +*/ + + +#include + +#define lmem_c +#define LUA_CORE + +#include "lua.h" + +#include "ldebug.h" +#include "ldo.h" +#include "lmem.h" +#include "lobject.h" +#include "lstate.h" + + + +/* +** About the realloc function: +** void * frealloc (void *ud, void *ptr, size_t osize, size_t nsize); +** (`osize' is the old size, `nsize' is the new size) +** +** Lua ensures that (ptr == NULL) iff (osize == 0). +** +** * frealloc(ud, NULL, 0, x) creates a new block of size `x' +** +** * frealloc(ud, p, x, 0) frees the block `p' +** (in this specific case, frealloc must return NULL). +** particularly, frealloc(ud, NULL, 0, 0) does nothing +** (which is equivalent to free(NULL) in ANSI C) +** +** frealloc returns NULL if it cannot create or reallocate the area +** (any reallocation to an equal or smaller size cannot fail!) +*/ + + + +#define MINSIZEARRAY 4 + + +void *luaM_growaux_ (lua_State *L, void *block, int *size, size_t size_elems, + int limit, const char *errormsg) { + void *newblock; + int newsize; + if (*size >= limit/2) { /* cannot double it? */ + if (*size >= limit) /* cannot grow even a little? */ + luaG_runerror(L, errormsg); + newsize = limit; /* still have at least one free place */ + } + else { + newsize = (*size)*2; + if (newsize < MINSIZEARRAY) + newsize = MINSIZEARRAY; /* minimum size */ + } + newblock = luaM_reallocv(L, block, *size, newsize, size_elems); + *size = newsize; /* update only when everything else is OK */ + return newblock; +} + + +void *luaM_toobig (lua_State *L) { + luaG_runerror(L, "memory allocation error: block too big"); + return NULL; /* to avoid warnings */ +} + + + +/* +** generic allocation routine. +*/ +void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) { + global_State *g = G(L); + lua_assert((osize == 0) == (block == NULL)); + block = (*g->frealloc)(g->ud, block, osize, nsize); + if (block == NULL && nsize > 0) + luaD_throw(L, LUA_ERRMEM); + lua_assert((nsize == 0) == (block == NULL)); + g->totalbytes = (g->totalbytes - osize) + nsize; + return block; +} + diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lmem.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lmem.h new file mode 100644 index 00000000..7c2dcb32 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lmem.h @@ -0,0 +1,49 @@ +/* +** $Id: lmem.h,v 1.31.1.1 2007/12/27 13:02:25 roberto Exp $ +** Interface to Memory Manager +** See Copyright Notice in lua.h +*/ + +#ifndef lmem_h +#define lmem_h + + +#include + +#include "llimits.h" +#include "lua.h" + +#define MEMERRMSG "not enough memory" + + +#define luaM_reallocv(L,b,on,n,e) \ + ((cast(size_t, (n)+1) <= MAX_SIZET/(e)) ? /* +1 to avoid warnings */ \ + luaM_realloc_(L, (b), (on)*(e), (n)*(e)) : \ + luaM_toobig(L)) + +#define luaM_freemem(L, b, s) luaM_realloc_(L, (b), (s), 0) +#define luaM_free(L, b) luaM_realloc_(L, (b), sizeof(*(b)), 0) +#define luaM_freearray(L, b, n, t) luaM_reallocv(L, (b), n, 0, sizeof(t)) + +#define luaM_malloc(L,t) luaM_realloc_(L, NULL, 0, (t)) +#define luaM_new(L,t) cast(t *, luaM_malloc(L, sizeof(t))) +#define luaM_newvector(L,n,t) \ + cast(t *, luaM_reallocv(L, NULL, 0, n, sizeof(t))) + +#define luaM_growvector(L,v,nelems,size,t,limit,e) \ + if ((nelems)+1 > (size)) \ + ((v)=cast(t *, luaM_growaux_(L,v,&(size),sizeof(t),limit,e))) + +#define luaM_reallocvector(L, v,oldn,n,t) \ + ((v)=cast(t *, luaM_reallocv(L, v, oldn, n, sizeof(t)))) + + +LUAI_FUNC void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize, + size_t size); +LUAI_FUNC void *luaM_toobig (lua_State *L); +LUAI_FUNC void *luaM_growaux_ (lua_State *L, void *block, int *size, + size_t size_elem, int limit, + const char *errormsg); + +#endif + diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/loadlib.c b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/loadlib.c new file mode 100644 index 00000000..0d401eba --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/loadlib.c @@ -0,0 +1,666 @@ +/* +** $Id: loadlib.c,v 1.52.1.3 2008/08/06 13:29:28 roberto Exp $ +** Dynamic library loader for Lua +** See Copyright Notice in lua.h +** +** This module contains an implementation of loadlib for Unix systems +** that have dlfcn, an implementation for Darwin (Mac OS X), an +** implementation for Windows, and a stub for other systems. +*/ + + +#include +#include + + +#define loadlib_c +#define LUA_LIB + +#include "lua.h" + +#include "lauxlib.h" +#include "lualib.h" + + +/* prefix for open functions in C libraries */ +#define LUA_POF "luaopen_" + +/* separator for open functions in C libraries */ +#define LUA_OFSEP "_" + + +#define LIBPREFIX "LOADLIB: " + +#define POF LUA_POF +#define LIB_FAIL "open" + + +/* error codes for ll_loadfunc */ +#define ERRLIB 1 +#define ERRFUNC 2 + +#define setprogdir(L) ((void)0) + + +static void ll_unloadlib (void *lib); +static void *ll_load (lua_State *L, const char *path); +static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym); + + + +#if defined(LUA_DL_DLOPEN) +/* +** {======================================================================== +** This is an implementation of loadlib based on the dlfcn interface. +** The dlfcn interface is available in Linux, SunOS, Solaris, IRIX, FreeBSD, +** NetBSD, AIX 4.2, HPUX 11, and probably most other Unix flavors, at least +** as an emulation layer on top of native functions. +** ========================================================================= +*/ + +#include + +static void ll_unloadlib (void *lib) { + dlclose(lib); +} + + +static void *ll_load (lua_State *L, const char *path) { + void *lib = dlopen(path, RTLD_NOW); + if (lib == NULL) lua_pushstring(L, dlerror()); + return lib; +} + + +static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) { + lua_CFunction f = (lua_CFunction)dlsym(lib, sym); + if (f == NULL) lua_pushstring(L, dlerror()); + return f; +} + +/* }====================================================== */ + + + +#elif defined(LUA_DL_DLL) +/* +** {====================================================================== +** This is an implementation of loadlib for Windows using native functions. +** ======================================================================= +*/ + +#include + + +#undef setprogdir + +static void setprogdir (lua_State *L) { + char buff[MAX_PATH + 1]; + char *lb; + DWORD nsize = sizeof(buff)/sizeof(char); + DWORD n = GetModuleFileNameA(NULL, buff, nsize); + if (n == 0 || n == nsize || (lb = strrchr(buff, '\\')) == NULL) + luaL_error(L, "unable to get ModuleFileName"); + else { + *lb = '\0'; + luaL_gsub(L, lua_tostring(L, -1), LUA_EXECDIR, buff); + lua_remove(L, -2); /* remove original string */ + } +} + + +static void pusherror (lua_State *L) { + int error = GetLastError(); + char buffer[128]; + if (FormatMessageA(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM, + NULL, error, 0, buffer, sizeof(buffer), NULL)) + lua_pushstring(L, buffer); + else + lua_pushfstring(L, "system error %d\n", error); +} + +static void ll_unloadlib (void *lib) { + FreeLibrary((HINSTANCE)lib); +} + + +static void *ll_load (lua_State *L, const char *path) { + HINSTANCE lib = LoadLibraryA(path); + if (lib == NULL) pusherror(L); + return lib; +} + + +static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) { + lua_CFunction f = (lua_CFunction)GetProcAddress((HINSTANCE)lib, sym); + if (f == NULL) pusherror(L); + return f; +} + +/* }====================================================== */ + + + +#elif defined(LUA_DL_DYLD) +/* +** {====================================================================== +** Native Mac OS X / Darwin Implementation +** ======================================================================= +*/ + +#include + + +/* Mac appends a `_' before C function names */ +#undef POF +#define POF "_" LUA_POF + + +static void pusherror (lua_State *L) { + const char *err_str; + const char *err_file; + NSLinkEditErrors err; + int err_num; + NSLinkEditError(&err, &err_num, &err_file, &err_str); + lua_pushstring(L, err_str); +} + + +static const char *errorfromcode (NSObjectFileImageReturnCode ret) { + switch (ret) { + case NSObjectFileImageInappropriateFile: + return "file is not a bundle"; + case NSObjectFileImageArch: + return "library is for wrong CPU type"; + case NSObjectFileImageFormat: + return "bad format"; + case NSObjectFileImageAccess: + return "cannot access file"; + case NSObjectFileImageFailure: + default: + return "unable to load library"; + } +} + + +static void ll_unloadlib (void *lib) { + NSUnLinkModule((NSModule)lib, NSUNLINKMODULE_OPTION_RESET_LAZY_REFERENCES); +} + + +static void *ll_load (lua_State *L, const char *path) { + NSObjectFileImage img; + NSObjectFileImageReturnCode ret; + /* this would be a rare case, but prevents crashing if it happens */ + if(!_dyld_present()) { + lua_pushliteral(L, "dyld not present"); + return NULL; + } + ret = NSCreateObjectFileImageFromFile(path, &img); + if (ret == NSObjectFileImageSuccess) { + NSModule mod = NSLinkModule(img, path, NSLINKMODULE_OPTION_PRIVATE | + NSLINKMODULE_OPTION_RETURN_ON_ERROR); + NSDestroyObjectFileImage(img); + if (mod == NULL) pusherror(L); + return mod; + } + lua_pushstring(L, errorfromcode(ret)); + return NULL; +} + + +static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) { + NSSymbol nss = NSLookupSymbolInModule((NSModule)lib, sym); + if (nss == NULL) { + lua_pushfstring(L, "symbol " LUA_QS " not found", sym); + return NULL; + } + return (lua_CFunction)NSAddressOfSymbol(nss); +} + +/* }====================================================== */ + + + +#else +/* +** {====================================================== +** Fallback for other systems +** ======================================================= +*/ + +#undef LIB_FAIL +#define LIB_FAIL "absent" + + +#define DLMSG "dynamic libraries not enabled; check your Lua installation" + + +static void ll_unloadlib (void *lib) { + (void)lib; /* to avoid warnings */ +} + + +static void *ll_load (lua_State *L, const char *path) { + (void)path; /* to avoid warnings */ + lua_pushliteral(L, DLMSG); + return NULL; +} + + +static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) { + (void)lib; (void)sym; /* to avoid warnings */ + lua_pushliteral(L, DLMSG); + return NULL; +} + +/* }====================================================== */ +#endif + + + +static void **ll_register (lua_State *L, const char *path) { + void **plib; + lua_pushfstring(L, "%s%s", LIBPREFIX, path); + lua_gettable(L, LUA_REGISTRYINDEX); /* check library in registry? */ + if (!lua_isnil(L, -1)) /* is there an entry? */ + plib = (void **)lua_touserdata(L, -1); + else { /* no entry yet; create one */ + lua_pop(L, 1); + plib = (void **)lua_newuserdata(L, sizeof(const void *)); + *plib = NULL; + luaL_getmetatable(L, "_LOADLIB"); + lua_setmetatable(L, -2); + lua_pushfstring(L, "%s%s", LIBPREFIX, path); + lua_pushvalue(L, -2); + lua_settable(L, LUA_REGISTRYINDEX); + } + return plib; +} + + +/* +** __gc tag method: calls library's `ll_unloadlib' function with the lib +** handle +*/ +static int gctm (lua_State *L) { + void **lib = (void **)luaL_checkudata(L, 1, "_LOADLIB"); + if (*lib) ll_unloadlib(*lib); + *lib = NULL; /* mark library as closed */ + return 0; +} + + +static int ll_loadfunc (lua_State *L, const char *path, const char *sym) { + void **reg = ll_register(L, path); + if (*reg == NULL) *reg = ll_load(L, path); + if (*reg == NULL) + return ERRLIB; /* unable to load library */ + else { + lua_CFunction f = ll_sym(L, *reg, sym); + if (f == NULL) + return ERRFUNC; /* unable to find function */ + lua_pushcfunction(L, f); + return 0; /* return function */ + } +} + + +static int ll_loadlib (lua_State *L) { + const char *path = luaL_checkstring(L, 1); + const char *init = luaL_checkstring(L, 2); + int stat = ll_loadfunc(L, path, init); + if (stat == 0) /* no errors? */ + return 1; /* return the loaded function */ + else { /* error; error message is on stack top */ + lua_pushnil(L); + lua_insert(L, -2); + lua_pushstring(L, (stat == ERRLIB) ? LIB_FAIL : "init"); + return 3; /* return nil, error message, and where */ + } +} + + + +/* +** {====================================================== +** 'require' function +** ======================================================= +*/ + + +static int readable (const char *filename) { + FILE *f = fopen(filename, "r"); /* try to open file */ + if (f == NULL) return 0; /* open failed */ + fclose(f); + return 1; +} + + +static const char *pushnexttemplate (lua_State *L, const char *path) { + const char *l; + while (*path == *LUA_PATHSEP) path++; /* skip separators */ + if (*path == '\0') return NULL; /* no more templates */ + l = strchr(path, *LUA_PATHSEP); /* find next separator */ + if (l == NULL) l = path + strlen(path); + lua_pushlstring(L, path, l - path); /* template */ + return l; +} + + +static const char *findfile (lua_State *L, const char *name, + const char *pname) { + const char *path; + name = luaL_gsub(L, name, ".", LUA_DIRSEP); + lua_getfield(L, LUA_ENVIRONINDEX, pname); + path = lua_tostring(L, -1); + if (path == NULL) + luaL_error(L, LUA_QL("package.%s") " must be a string", pname); + lua_pushliteral(L, ""); /* error accumulator */ + while ((path = pushnexttemplate(L, path)) != NULL) { + const char *filename; + filename = luaL_gsub(L, lua_tostring(L, -1), LUA_PATH_MARK, name); + lua_remove(L, -2); /* remove path template */ + if (readable(filename)) /* does file exist and is readable? */ + return filename; /* return that file name */ + lua_pushfstring(L, "\n\tno file " LUA_QS, filename); + lua_remove(L, -2); /* remove file name */ + lua_concat(L, 2); /* add entry to possible error message */ + } + return NULL; /* not found */ +} + + +static void loaderror (lua_State *L, const char *filename) { + luaL_error(L, "error loading module " LUA_QS " from file " LUA_QS ":\n\t%s", + lua_tostring(L, 1), filename, lua_tostring(L, -1)); +} + + +static int loader_Lua (lua_State *L) { + const char *filename; + const char *name = luaL_checkstring(L, 1); + filename = findfile(L, name, "path"); + if (filename == NULL) return 1; /* library not found in this path */ + if (luaL_loadfile(L, filename) != 0) + loaderror(L, filename); + return 1; /* library loaded successfully */ +} + + +static const char *mkfuncname (lua_State *L, const char *modname) { + const char *funcname; + const char *mark = strchr(modname, *LUA_IGMARK); + if (mark) modname = mark + 1; + funcname = luaL_gsub(L, modname, ".", LUA_OFSEP); + funcname = lua_pushfstring(L, POF"%s", funcname); + lua_remove(L, -2); /* remove 'gsub' result */ + return funcname; +} + + +static int loader_C (lua_State *L) { + const char *funcname; + const char *name = luaL_checkstring(L, 1); + const char *filename = findfile(L, name, "cpath"); + if (filename == NULL) return 1; /* library not found in this path */ + funcname = mkfuncname(L, name); + if (ll_loadfunc(L, filename, funcname) != 0) + loaderror(L, filename); + return 1; /* library loaded successfully */ +} + + +static int loader_Croot (lua_State *L) { + const char *funcname; + const char *filename; + const char *name = luaL_checkstring(L, 1); + const char *p = strchr(name, '.'); + int stat; + if (p == NULL) return 0; /* is root */ + lua_pushlstring(L, name, p - name); + filename = findfile(L, lua_tostring(L, -1), "cpath"); + if (filename == NULL) return 1; /* root not found */ + funcname = mkfuncname(L, name); + if ((stat = ll_loadfunc(L, filename, funcname)) != 0) { + if (stat != ERRFUNC) loaderror(L, filename); /* real error */ + lua_pushfstring(L, "\n\tno module " LUA_QS " in file " LUA_QS, + name, filename); + return 1; /* function not found */ + } + return 1; +} + + +static int loader_preload (lua_State *L) { + const char *name = luaL_checkstring(L, 1); + lua_getfield(L, LUA_ENVIRONINDEX, "preload"); + if (!lua_istable(L, -1)) + luaL_error(L, LUA_QL("package.preload") " must be a table"); + lua_getfield(L, -1, name); + if (lua_isnil(L, -1)) /* not found? */ + lua_pushfstring(L, "\n\tno field package.preload['%s']", name); + return 1; +} + + +static const int sentinel_ = 0; +#define sentinel ((void *)&sentinel_) + + +static int ll_require (lua_State *L) { + const char *name = luaL_checkstring(L, 1); + int i; + lua_settop(L, 1); /* _LOADED table will be at index 2 */ + lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED"); + lua_getfield(L, 2, name); + if (lua_toboolean(L, -1)) { /* is it there? */ + if (lua_touserdata(L, -1) == sentinel) /* check loops */ + luaL_error(L, "loop or previous error loading module " LUA_QS, name); + return 1; /* package is already loaded */ + } + /* else must load it; iterate over available loaders */ + lua_getfield(L, LUA_ENVIRONINDEX, "loaders"); + if (!lua_istable(L, -1)) + luaL_error(L, LUA_QL("package.loaders") " must be a table"); + lua_pushliteral(L, ""); /* error message accumulator */ + for (i=1; ; i++) { + lua_rawgeti(L, -2, i); /* get a loader */ + if (lua_isnil(L, -1)) + luaL_error(L, "module " LUA_QS " not found:%s", + name, lua_tostring(L, -2)); + lua_pushstring(L, name); + lua_call(L, 1, 1); /* call it */ + if (lua_isfunction(L, -1)) /* did it find module? */ + break; /* module loaded successfully */ + else if (lua_isstring(L, -1)) /* loader returned error message? */ + lua_concat(L, 2); /* accumulate it */ + else + lua_pop(L, 1); + } + lua_pushlightuserdata(L, sentinel); + lua_setfield(L, 2, name); /* _LOADED[name] = sentinel */ + lua_pushstring(L, name); /* pass name as argument to module */ + lua_call(L, 1, 1); /* run loaded module */ + if (!lua_isnil(L, -1)) /* non-nil return? */ + lua_setfield(L, 2, name); /* _LOADED[name] = returned value */ + lua_getfield(L, 2, name); + if (lua_touserdata(L, -1) == sentinel) { /* module did not set a value? */ + lua_pushboolean(L, 1); /* use true as result */ + lua_pushvalue(L, -1); /* extra copy to be returned */ + lua_setfield(L, 2, name); /* _LOADED[name] = true */ + } + return 1; +} + +/* }====================================================== */ + + + +/* +** {====================================================== +** 'module' function +** ======================================================= +*/ + + +static void setfenv (lua_State *L) { + lua_Debug ar; + if (lua_getstack(L, 1, &ar) == 0 || + lua_getinfo(L, "f", &ar) == 0 || /* get calling function */ + lua_iscfunction(L, -1)) + luaL_error(L, LUA_QL("module") " not called from a Lua function"); + lua_pushvalue(L, -2); + lua_setfenv(L, -2); + lua_pop(L, 1); +} + + +static void dooptions (lua_State *L, int n) { + int i; + for (i = 2; i <= n; i++) { + lua_pushvalue(L, i); /* get option (a function) */ + lua_pushvalue(L, -2); /* module */ + lua_call(L, 1, 0); + } +} + + +static void modinit (lua_State *L, const char *modname) { + const char *dot; + lua_pushvalue(L, -1); + lua_setfield(L, -2, "_M"); /* module._M = module */ + lua_pushstring(L, modname); + lua_setfield(L, -2, "_NAME"); + dot = strrchr(modname, '.'); /* look for last dot in module name */ + if (dot == NULL) dot = modname; + else dot++; + /* set _PACKAGE as package name (full module name minus last part) */ + lua_pushlstring(L, modname, dot - modname); + lua_setfield(L, -2, "_PACKAGE"); +} + + +static int ll_module (lua_State *L) { + const char *modname = luaL_checkstring(L, 1); + int loaded = lua_gettop(L) + 1; /* index of _LOADED table */ + lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED"); + lua_getfield(L, loaded, modname); /* get _LOADED[modname] */ + if (!lua_istable(L, -1)) { /* not found? */ + lua_pop(L, 1); /* remove previous result */ + /* try global variable (and create one if it does not exist) */ + if (luaL_findtable(L, LUA_GLOBALSINDEX, modname, 1) != NULL) + return luaL_error(L, "name conflict for module " LUA_QS, modname); + lua_pushvalue(L, -1); + lua_setfield(L, loaded, modname); /* _LOADED[modname] = new table */ + } + /* check whether table already has a _NAME field */ + lua_getfield(L, -1, "_NAME"); + if (!lua_isnil(L, -1)) /* is table an initialized module? */ + lua_pop(L, 1); + else { /* no; initialize it */ + lua_pop(L, 1); + modinit(L, modname); + } + lua_pushvalue(L, -1); + setfenv(L); + dooptions(L, loaded - 1); + return 0; +} + + +static int ll_seeall (lua_State *L) { + luaL_checktype(L, 1, LUA_TTABLE); + if (!lua_getmetatable(L, 1)) { + lua_createtable(L, 0, 1); /* create new metatable */ + lua_pushvalue(L, -1); + lua_setmetatable(L, 1); + } + lua_pushvalue(L, LUA_GLOBALSINDEX); + lua_setfield(L, -2, "__index"); /* mt.__index = _G */ + return 0; +} + + +/* }====================================================== */ + + + +/* auxiliary mark (for internal use) */ +#define AUXMARK "\1" + +static void setpath (lua_State *L, const char *fieldname, const char *envname, + const char *def) { + const char *path = getenv(envname); + if (path == NULL) /* no environment variable? */ + lua_pushstring(L, def); /* use default */ + else { + /* replace ";;" by ";AUXMARK;" and then AUXMARK by default path */ + path = luaL_gsub(L, path, LUA_PATHSEP LUA_PATHSEP, + LUA_PATHSEP AUXMARK LUA_PATHSEP); + luaL_gsub(L, path, AUXMARK, def); + lua_remove(L, -2); + } + setprogdir(L); + lua_setfield(L, -2, fieldname); +} + + +static const luaL_Reg pk_funcs[] = { + {"loadlib", ll_loadlib}, + {"seeall", ll_seeall}, + {NULL, NULL} +}; + + +static const luaL_Reg ll_funcs[] = { + {"module", ll_module}, + {"require", ll_require}, + {NULL, NULL} +}; + + +static const lua_CFunction loaders[] = + {loader_preload, loader_Lua, loader_C, loader_Croot, NULL}; + + +LUALIB_API int luaopen_package (lua_State *L) { + int i; + /* create new type _LOADLIB */ + luaL_newmetatable(L, "_LOADLIB"); + lua_pushcfunction(L, gctm); + lua_setfield(L, -2, "__gc"); + /* create `package' table */ + luaL_register(L, LUA_LOADLIBNAME, pk_funcs); +#if defined(LUA_COMPAT_LOADLIB) + lua_getfield(L, -1, "loadlib"); + lua_setfield(L, LUA_GLOBALSINDEX, "loadlib"); +#endif + lua_pushvalue(L, -1); + lua_replace(L, LUA_ENVIRONINDEX); + /* create `loaders' table */ + lua_createtable(L, 0, sizeof(loaders)/sizeof(loaders[0]) - 1); + /* fill it with pre-defined loaders */ + for (i=0; loaders[i] != NULL; i++) { + lua_pushcfunction(L, loaders[i]); + lua_rawseti(L, -2, i+1); + } + lua_setfield(L, -2, "loaders"); /* put it in field `loaders' */ + setpath(L, "path", LUA_PATH, LUA_PATH_DEFAULT); /* set field `path' */ + setpath(L, "cpath", LUA_CPATH, LUA_CPATH_DEFAULT); /* set field `cpath' */ + /* store config information */ + lua_pushliteral(L, LUA_DIRSEP "\n" LUA_PATHSEP "\n" LUA_PATH_MARK "\n" + LUA_EXECDIR "\n" LUA_IGMARK); + lua_setfield(L, -2, "config"); + /* set field `loaded' */ + luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 2); + lua_setfield(L, -2, "loaded"); + /* set field `preload' */ + lua_newtable(L); + lua_setfield(L, -2, "preload"); + lua_pushvalue(L, LUA_GLOBALSINDEX); + luaL_register(L, NULL, ll_funcs); /* open lib into global table */ + lua_pop(L, 1); + return 1; /* return 'package' table */ +} + diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lobject.c b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lobject.c new file mode 100644 index 00000000..4ff50732 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lobject.c @@ -0,0 +1,214 @@ +/* +** $Id: lobject.c,v 2.22.1.1 2007/12/27 13:02:25 roberto Exp $ +** Some generic functions over Lua objects +** See Copyright Notice in lua.h +*/ + +#include +#include +#include +#include +#include + +#define lobject_c +#define LUA_CORE + +#include "lua.h" + +#include "ldo.h" +#include "lmem.h" +#include "lobject.h" +#include "lstate.h" +#include "lstring.h" +#include "lvm.h" + + + +const TValue luaO_nilobject_ = {{NULL}, LUA_TNIL}; + + +/* +** converts an integer to a "floating point byte", represented as +** (eeeeexxx), where the real value is (1xxx) * 2^(eeeee - 1) if +** eeeee != 0 and (xxx) otherwise. +*/ +int luaO_int2fb (unsigned int x) { + int e = 0; /* expoent */ + while (x >= 16) { + x = (x+1) >> 1; + e++; + } + if (x < 8) return x; + else return ((e+1) << 3) | (cast_int(x) - 8); +} + + +/* converts back */ +int luaO_fb2int (int x) { + int e = (x >> 3) & 31; + if (e == 0) return x; + else return ((x & 7)+8) << (e - 1); +} + + +int luaO_log2 (unsigned int x) { + static const lu_byte log_2[256] = { + 0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5, + 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, + 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, + 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, + 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, + 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, + 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, + 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8 + }; + int l = -1; + while (x >= 256) { l += 8; x >>= 8; } + return l + log_2[x]; + +} + + +int luaO_rawequalObj (const TValue *t1, const TValue *t2) { + if (ttype(t1) != ttype(t2)) return 0; + else switch (ttype(t1)) { + case LUA_TNIL: + return 1; + case LUA_TNUMBER: + return luai_numeq(nvalue(t1), nvalue(t2)); + case LUA_TBOOLEAN: + return bvalue(t1) == bvalue(t2); /* boolean true must be 1 !! */ + case LUA_TLIGHTUSERDATA: + return pvalue(t1) == pvalue(t2); + default: + lua_assert(iscollectable(t1)); + return gcvalue(t1) == gcvalue(t2); + } +} + + +int luaO_str2d (const char *s, lua_Number *result) { + char *endptr; + *result = lua_str2number(s, &endptr); + if (endptr == s) return 0; /* conversion failed */ + if (*endptr == 'x' || *endptr == 'X') /* maybe an hexadecimal constant? */ + *result = cast_num(strtoul(s, &endptr, 16)); + if (*endptr == '\0') return 1; /* most common case */ + while (isspace(cast(unsigned char, *endptr))) endptr++; + if (*endptr != '\0') return 0; /* invalid trailing characters? */ + return 1; +} + + + +static void pushstr (lua_State *L, const char *str) { + setsvalue2s(L, L->top, luaS_new(L, str)); + incr_top(L); +} + + +/* this function handles only `%d', `%c', %f, %p, and `%s' formats */ +const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) { + int n = 1; + pushstr(L, ""); + for (;;) { + const char *e = strchr(fmt, '%'); + if (e == NULL) break; + setsvalue2s(L, L->top, luaS_newlstr(L, fmt, e-fmt)); + incr_top(L); + switch (*(e+1)) { + case 's': { + const char *s = va_arg(argp, char *); + if (s == NULL) s = "(null)"; + pushstr(L, s); + break; + } + case 'c': { + char buff[2]; + buff[0] = cast(char, va_arg(argp, int)); + buff[1] = '\0'; + pushstr(L, buff); + break; + } + case 'd': { + setnvalue(L->top, cast_num(va_arg(argp, int))); + incr_top(L); + break; + } + case 'f': { + setnvalue(L->top, cast_num(va_arg(argp, l_uacNumber))); + incr_top(L); + break; + } + case 'p': { + char buff[4*sizeof(void *) + 8]; /* should be enough space for a `%p' */ + sprintf(buff, "%p", va_arg(argp, void *)); + pushstr(L, buff); + break; + } + case '%': { + pushstr(L, "%"); + break; + } + default: { + char buff[3]; + buff[0] = '%'; + buff[1] = *(e+1); + buff[2] = '\0'; + pushstr(L, buff); + break; + } + } + n += 2; + fmt = e+2; + } + pushstr(L, fmt); + luaV_concat(L, n+1, cast_int(L->top - L->base) - 1); + L->top -= n; + return svalue(L->top - 1); +} + + +const char *luaO_pushfstring (lua_State *L, const char *fmt, ...) { + const char *msg; + va_list argp; + va_start(argp, fmt); + msg = luaO_pushvfstring(L, fmt, argp); + va_end(argp); + return msg; +} + + +void luaO_chunkid (char *out, const char *source, size_t bufflen) { + if (*source == '=') { + strncpy(out, source+1, bufflen); /* remove first char */ + out[bufflen-1] = '\0'; /* ensures null termination */ + } + else { /* out = "source", or "...source" */ + if (*source == '@') { + size_t l; + source++; /* skip the `@' */ + bufflen -= sizeof(" '...' "); + l = strlen(source); + strcpy(out, ""); + if (l > bufflen) { + source += (l-bufflen); /* get last part of file name */ + strcat(out, "..."); + } + strcat(out, source); + } + else { /* out = [string "string"] */ + size_t len = strcspn(source, "\n\r"); /* stop at first newline */ + bufflen -= sizeof(" [string \"...\"] "); + if (len > bufflen) len = bufflen; + strcpy(out, "[string \""); + if (source[len] != '\0') { /* must truncate? */ + strncat(out, source, len); + strcat(out, "..."); + } + else + strcat(out, source); + strcat(out, "\"]"); + } + } +} diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lobject.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lobject.h new file mode 100644 index 00000000..f1e447ef --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lobject.h @@ -0,0 +1,381 @@ +/* +** $Id: lobject.h,v 2.20.1.2 2008/08/06 13:29:48 roberto Exp $ +** Type definitions for Lua objects +** See Copyright Notice in lua.h +*/ + + +#ifndef lobject_h +#define lobject_h + + +#include + + +#include "llimits.h" +#include "lua.h" + + +/* tags for values visible from Lua */ +#define LAST_TAG LUA_TTHREAD + +#define NUM_TAGS (LAST_TAG+1) + + +/* +** Extra tags for non-values +*/ +#define LUA_TPROTO (LAST_TAG+1) +#define LUA_TUPVAL (LAST_TAG+2) +#define LUA_TDEADKEY (LAST_TAG+3) + + +/* +** Union of all collectable objects +*/ +typedef union GCObject GCObject; + + +/* +** Common Header for all collectable objects (in macro form, to be +** included in other objects) +*/ +#define CommonHeader GCObject *next; lu_byte tt; lu_byte marked + + +/* +** Common header in struct form +*/ +typedef struct GCheader { + CommonHeader; +} GCheader; + + + + +/* +** Union of all Lua values +*/ +typedef union { + GCObject *gc; + void *p; + lua_Number n; + int b; +} Value; + + +/* +** Tagged Values +*/ + +#define TValuefields Value value; int tt + +typedef struct lua_TValue { + TValuefields; +} TValue; + + +/* Macros to test type */ +#define ttisnil(o) (ttype(o) == LUA_TNIL) +#define ttisnumber(o) (ttype(o) == LUA_TNUMBER) +#define ttisstring(o) (ttype(o) == LUA_TSTRING) +#define ttistable(o) (ttype(o) == LUA_TTABLE) +#define ttisfunction(o) (ttype(o) == LUA_TFUNCTION) +#define ttisboolean(o) (ttype(o) == LUA_TBOOLEAN) +#define ttisuserdata(o) (ttype(o) == LUA_TUSERDATA) +#define ttisthread(o) (ttype(o) == LUA_TTHREAD) +#define ttislightuserdata(o) (ttype(o) == LUA_TLIGHTUSERDATA) + +/* Macros to access values */ +#define ttype(o) ((o)->tt) +#define gcvalue(o) check_exp(iscollectable(o), (o)->value.gc) +#define pvalue(o) check_exp(ttislightuserdata(o), (o)->value.p) +#define nvalue(o) check_exp(ttisnumber(o), (o)->value.n) +#define rawtsvalue(o) check_exp(ttisstring(o), &(o)->value.gc->ts) +#define tsvalue(o) (&rawtsvalue(o)->tsv) +#define rawuvalue(o) check_exp(ttisuserdata(o), &(o)->value.gc->u) +#define uvalue(o) (&rawuvalue(o)->uv) +#define clvalue(o) check_exp(ttisfunction(o), &(o)->value.gc->cl) +#define hvalue(o) check_exp(ttistable(o), &(o)->value.gc->h) +#define bvalue(o) check_exp(ttisboolean(o), (o)->value.b) +#define thvalue(o) check_exp(ttisthread(o), &(o)->value.gc->th) + +#define l_isfalse(o) (ttisnil(o) || (ttisboolean(o) && bvalue(o) == 0)) + +/* +** for internal debug only +*/ +#define checkconsistency(obj) \ + lua_assert(!iscollectable(obj) || (ttype(obj) == (obj)->value.gc->gch.tt)) + +#define checkliveness(g,obj) \ + lua_assert(!iscollectable(obj) || \ + ((ttype(obj) == (obj)->value.gc->gch.tt) && !isdead(g, (obj)->value.gc))) + + +/* Macros to set values */ +#define setnilvalue(obj) ((obj)->tt=LUA_TNIL) + +#define setnvalue(obj,x) \ + { TValue *i_o=(obj); i_o->value.n=(x); i_o->tt=LUA_TNUMBER; } + +#define setpvalue(obj,x) \ + { TValue *i_o=(obj); i_o->value.p=(x); i_o->tt=LUA_TLIGHTUSERDATA; } + +#define setbvalue(obj,x) \ + { TValue *i_o=(obj); i_o->value.b=(x); i_o->tt=LUA_TBOOLEAN; } + +#define setsvalue(L,obj,x) \ + { TValue *i_o=(obj); \ + i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TSTRING; \ + checkliveness(G(L),i_o); } + +#define setuvalue(L,obj,x) \ + { TValue *i_o=(obj); \ + i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TUSERDATA; \ + checkliveness(G(L),i_o); } + +#define setthvalue(L,obj,x) \ + { TValue *i_o=(obj); \ + i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TTHREAD; \ + checkliveness(G(L),i_o); } + +#define setclvalue(L,obj,x) \ + { TValue *i_o=(obj); \ + i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TFUNCTION; \ + checkliveness(G(L),i_o); } + +#define sethvalue(L,obj,x) \ + { TValue *i_o=(obj); \ + i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TTABLE; \ + checkliveness(G(L),i_o); } + +#define setptvalue(L,obj,x) \ + { TValue *i_o=(obj); \ + i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TPROTO; \ + checkliveness(G(L),i_o); } + + + + +#define setobj(L,obj1,obj2) \ + { const TValue *o2=(obj2); TValue *o1=(obj1); \ + o1->value = o2->value; o1->tt=o2->tt; \ + checkliveness(G(L),o1); } + + +/* +** different types of sets, according to destination +*/ + +/* from stack to (same) stack */ +#define setobjs2s setobj +/* to stack (not from same stack) */ +#define setobj2s setobj +#define setsvalue2s setsvalue +#define sethvalue2s sethvalue +#define setptvalue2s setptvalue +/* from table to same table */ +#define setobjt2t setobj +/* to table */ +#define setobj2t setobj +/* to new object */ +#define setobj2n setobj +#define setsvalue2n setsvalue + +#define setttype(obj, tt) (ttype(obj) = (tt)) + + +#define iscollectable(o) (ttype(o) >= LUA_TSTRING) + + + +typedef TValue *StkId; /* index to stack elements */ + + +/* +** String headers for string table +*/ +typedef union TString { + L_Umaxalign dummy; /* ensures maximum alignment for strings */ + struct { + CommonHeader; + lu_byte reserved; + unsigned int hash; + size_t len; + } tsv; +} TString; + + +#define getstr(ts) cast(const char *, (ts) + 1) +#define svalue(o) getstr(rawtsvalue(o)) + + + +typedef union Udata { + L_Umaxalign dummy; /* ensures maximum alignment for `local' udata */ + struct { + CommonHeader; + struct Table *metatable; + struct Table *env; + size_t len; + } uv; +} Udata; + + + + +/* +** Function Prototypes +*/ +typedef struct Proto { + CommonHeader; + TValue *k; /* constants used by the function */ + Instruction *code; + struct Proto **p; /* functions defined inside the function */ + int *lineinfo; /* map from opcodes to source lines */ + struct LocVar *locvars; /* information about local variables */ + TString **upvalues; /* upvalue names */ + TString *source; + int sizeupvalues; + int sizek; /* size of `k' */ + int sizecode; + int sizelineinfo; + int sizep; /* size of `p' */ + int sizelocvars; + int linedefined; + int lastlinedefined; + GCObject *gclist; + lu_byte nups; /* number of upvalues */ + lu_byte numparams; + lu_byte is_vararg; + lu_byte maxstacksize; +} Proto; + + +/* masks for new-style vararg */ +#define VARARG_HASARG 1 +#define VARARG_ISVARARG 2 +#define VARARG_NEEDSARG 4 + + +typedef struct LocVar { + TString *varname; + int startpc; /* first point where variable is active */ + int endpc; /* first point where variable is dead */ +} LocVar; + + + +/* +** Upvalues +*/ + +typedef struct UpVal { + CommonHeader; + TValue *v; /* points to stack or to its own value */ + union { + TValue value; /* the value (when closed) */ + struct { /* double linked list (when open) */ + struct UpVal *prev; + struct UpVal *next; + } l; + } u; +} UpVal; + + +/* +** Closures +*/ + +#define ClosureHeader \ + CommonHeader; lu_byte isC; lu_byte nupvalues; GCObject *gclist; \ + struct Table *env + +typedef struct CClosure { + ClosureHeader; + lua_CFunction f; + TValue upvalue[1]; +} CClosure; + + +typedef struct LClosure { + ClosureHeader; + struct Proto *p; + UpVal *upvals[1]; +} LClosure; + + +typedef union Closure { + CClosure c; + LClosure l; +} Closure; + + +#define iscfunction(o) (ttype(o) == LUA_TFUNCTION && clvalue(o)->c.isC) +#define isLfunction(o) (ttype(o) == LUA_TFUNCTION && !clvalue(o)->c.isC) + + +/* +** Tables +*/ + +typedef union TKey { + struct { + TValuefields; + struct Node *next; /* for chaining */ + } nk; + TValue tvk; +} TKey; + + +typedef struct Node { + TValue i_val; + TKey i_key; +} Node; + + +typedef struct Table { + CommonHeader; + lu_byte flags; /* 1<

lsizenode)) + + +#define luaO_nilobject (&luaO_nilobject_) + +LUAI_DATA const TValue luaO_nilobject_; + +#define ceillog2(x) (luaO_log2((x)-1) + 1) + +LUAI_FUNC int luaO_log2 (unsigned int x); +LUAI_FUNC int luaO_int2fb (unsigned int x); +LUAI_FUNC int luaO_fb2int (int x); +LUAI_FUNC int luaO_rawequalObj (const TValue *t1, const TValue *t2); +LUAI_FUNC int luaO_str2d (const char *s, lua_Number *result); +LUAI_FUNC const char *luaO_pushvfstring (lua_State *L, const char *fmt, + va_list argp); +LUAI_FUNC const char *luaO_pushfstring (lua_State *L, const char *fmt, ...); +LUAI_FUNC void luaO_chunkid (char *out, const char *source, size_t len); + + +#endif + diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lopcodes.c b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lopcodes.c new file mode 100644 index 00000000..4cc74523 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lopcodes.c @@ -0,0 +1,102 @@ +/* +** $Id: lopcodes.c,v 1.37.1.1 2007/12/27 13:02:25 roberto Exp $ +** See Copyright Notice in lua.h +*/ + + +#define lopcodes_c +#define LUA_CORE + + +#include "lopcodes.h" + + +/* ORDER OP */ + +const char *const luaP_opnames[NUM_OPCODES+1] = { + "MOVE", + "LOADK", + "LOADBOOL", + "LOADNIL", + "GETUPVAL", + "GETGLOBAL", + "GETTABLE", + "SETGLOBAL", + "SETUPVAL", + "SETTABLE", + "NEWTABLE", + "SELF", + "ADD", + "SUB", + "MUL", + "DIV", + "MOD", + "POW", + "UNM", + "NOT", + "LEN", + "CONCAT", + "JMP", + "EQ", + "LT", + "LE", + "TEST", + "TESTSET", + "CALL", + "TAILCALL", + "RETURN", + "FORLOOP", + "FORPREP", + "TFORLOOP", + "SETLIST", + "CLOSE", + "CLOSURE", + "VARARG", + NULL +}; + + +#define opmode(t,a,b,c,m) (((t)<<7) | ((a)<<6) | ((b)<<4) | ((c)<<2) | (m)) + +const lu_byte luaP_opmodes[NUM_OPCODES] = { +/* T A B C mode opcode */ + opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_MOVE */ + ,opmode(0, 1, OpArgK, OpArgN, iABx) /* OP_LOADK */ + ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_LOADBOOL */ + ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_LOADNIL */ + ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_GETUPVAL */ + ,opmode(0, 1, OpArgK, OpArgN, iABx) /* OP_GETGLOBAL */ + ,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_GETTABLE */ + ,opmode(0, 0, OpArgK, OpArgN, iABx) /* OP_SETGLOBAL */ + ,opmode(0, 0, OpArgU, OpArgN, iABC) /* OP_SETUPVAL */ + ,opmode(0, 0, OpArgK, OpArgK, iABC) /* OP_SETTABLE */ + ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_NEWTABLE */ + ,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_SELF */ + ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_ADD */ + ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_SUB */ + ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_MUL */ + ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_DIV */ + ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_MOD */ + ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_POW */ + ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_UNM */ + ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_NOT */ + ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_LEN */ + ,opmode(0, 1, OpArgR, OpArgR, iABC) /* OP_CONCAT */ + ,opmode(0, 0, OpArgR, OpArgN, iAsBx) /* OP_JMP */ + ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_EQ */ + ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_LT */ + ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_LE */ + ,opmode(1, 1, OpArgR, OpArgU, iABC) /* OP_TEST */ + ,opmode(1, 1, OpArgR, OpArgU, iABC) /* OP_TESTSET */ + ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_CALL */ + ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_TAILCALL */ + ,opmode(0, 0, OpArgU, OpArgN, iABC) /* OP_RETURN */ + ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_FORLOOP */ + ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_FORPREP */ + ,opmode(1, 0, OpArgN, OpArgU, iABC) /* OP_TFORLOOP */ + ,opmode(0, 0, OpArgU, OpArgU, iABC) /* OP_SETLIST */ + ,opmode(0, 0, OpArgN, OpArgN, iABC) /* OP_CLOSE */ + ,opmode(0, 1, OpArgU, OpArgN, iABx) /* OP_CLOSURE */ + ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_VARARG */ +}; + diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lopcodes.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lopcodes.h new file mode 100644 index 00000000..41224d6e --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lopcodes.h @@ -0,0 +1,268 @@ +/* +** $Id: lopcodes.h,v 1.125.1.1 2007/12/27 13:02:25 roberto Exp $ +** Opcodes for Lua virtual machine +** See Copyright Notice in lua.h +*/ + +#ifndef lopcodes_h +#define lopcodes_h + +#include "llimits.h" + + +/*=========================================================================== + We assume that instructions are unsigned numbers. + All instructions have an opcode in the first 6 bits. + Instructions can have the following fields: + `A' : 8 bits + `B' : 9 bits + `C' : 9 bits + `Bx' : 18 bits (`B' and `C' together) + `sBx' : signed Bx + + A signed argument is represented in excess K; that is, the number + value is the unsigned value minus K. K is exactly the maximum value + for that argument (so that -max is represented by 0, and +max is + represented by 2*max), which is half the maximum for the corresponding + unsigned argument. +===========================================================================*/ + + +enum OpMode {iABC, iABx, iAsBx}; /* basic instruction format */ + + +/* +** size and position of opcode arguments. +*/ +#define SIZE_C 9 +#define SIZE_B 9 +#define SIZE_Bx (SIZE_C + SIZE_B) +#define SIZE_A 8 + +#define SIZE_OP 6 + +#define POS_OP 0 +#define POS_A (POS_OP + SIZE_OP) +#define POS_C (POS_A + SIZE_A) +#define POS_B (POS_C + SIZE_C) +#define POS_Bx POS_C + + +/* +** limits for opcode arguments. +** we use (signed) int to manipulate most arguments, +** so they must fit in LUAI_BITSINT-1 bits (-1 for sign) +*/ +#if SIZE_Bx < LUAI_BITSINT-1 +#define MAXARG_Bx ((1<>1) /* `sBx' is signed */ +#else +#define MAXARG_Bx MAX_INT +#define MAXARG_sBx MAX_INT +#endif + + +#define MAXARG_A ((1<>POS_OP) & MASK1(SIZE_OP,0))) +#define SET_OPCODE(i,o) ((i) = (((i)&MASK0(SIZE_OP,POS_OP)) | \ + ((cast(Instruction, o)<>POS_A) & MASK1(SIZE_A,0))) +#define SETARG_A(i,u) ((i) = (((i)&MASK0(SIZE_A,POS_A)) | \ + ((cast(Instruction, u)<>POS_B) & MASK1(SIZE_B,0))) +#define SETARG_B(i,b) ((i) = (((i)&MASK0(SIZE_B,POS_B)) | \ + ((cast(Instruction, b)<>POS_C) & MASK1(SIZE_C,0))) +#define SETARG_C(i,b) ((i) = (((i)&MASK0(SIZE_C,POS_C)) | \ + ((cast(Instruction, b)<>POS_Bx) & MASK1(SIZE_Bx,0))) +#define SETARG_Bx(i,b) ((i) = (((i)&MASK0(SIZE_Bx,POS_Bx)) | \ + ((cast(Instruction, b)< C) then pc++ */ +OP_TESTSET,/* A B C if (R(B) <=> C) then R(A) := R(B) else pc++ */ + +OP_CALL,/* A B C R(A), ... ,R(A+C-2) := R(A)(R(A+1), ... ,R(A+B-1)) */ +OP_TAILCALL,/* A B C return R(A)(R(A+1), ... ,R(A+B-1)) */ +OP_RETURN,/* A B return R(A), ... ,R(A+B-2) (see note) */ + +OP_FORLOOP,/* A sBx R(A)+=R(A+2); + if R(A) =) R(A)*/ +OP_CLOSURE,/* A Bx R(A) := closure(KPROTO[Bx], R(A), ... ,R(A+n)) */ + +OP_VARARG/* A B R(A), R(A+1), ..., R(A+B-1) = vararg */ +} OpCode; + + +#define NUM_OPCODES (cast(int, OP_VARARG) + 1) + + + +/*=========================================================================== + Notes: + (*) In OP_CALL, if (B == 0) then B = top. C is the number of returns - 1, + and can be 0: OP_CALL then sets `top' to last_result+1, so + next open instruction (OP_CALL, OP_RETURN, OP_SETLIST) may use `top'. + + (*) In OP_VARARG, if (B == 0) then use actual number of varargs and + set top (like in OP_CALL with C == 0). + + (*) In OP_RETURN, if (B == 0) then return up to `top' + + (*) In OP_SETLIST, if (B == 0) then B = `top'; + if (C == 0) then next `instruction' is real C + + (*) For comparisons, A specifies what condition the test should accept + (true or false). + + (*) All `skips' (pc++) assume that next instruction is a jump +===========================================================================*/ + + +/* +** masks for instruction properties. The format is: +** bits 0-1: op mode +** bits 2-3: C arg mode +** bits 4-5: B arg mode +** bit 6: instruction set register A +** bit 7: operator is a test +*/ + +enum OpArgMask { + OpArgN, /* argument is not used */ + OpArgU, /* argument is used */ + OpArgR, /* argument is a register or a jump offset */ + OpArgK /* argument is a constant or register/constant */ +}; + +LUAI_DATA const lu_byte luaP_opmodes[NUM_OPCODES]; + +#define getOpMode(m) (cast(enum OpMode, luaP_opmodes[m] & 3)) +#define getBMode(m) (cast(enum OpArgMask, (luaP_opmodes[m] >> 4) & 3)) +#define getCMode(m) (cast(enum OpArgMask, (luaP_opmodes[m] >> 2) & 3)) +#define testAMode(m) (luaP_opmodes[m] & (1 << 6)) +#define testTMode(m) (luaP_opmodes[m] & (1 << 7)) + + +LUAI_DATA const char *const luaP_opnames[NUM_OPCODES+1]; /* opcode names */ + + +/* number of list items to accumulate before a SETLIST instruction */ +#define LFIELDS_PER_FLUSH 50 + + +#endif diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/loslib.c b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/loslib.c new file mode 100644 index 00000000..da06a572 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/loslib.c @@ -0,0 +1,243 @@ +/* +** $Id: loslib.c,v 1.19.1.3 2008/01/18 16:38:18 roberto Exp $ +** Standard Operating System library +** See Copyright Notice in lua.h +*/ + + +#include +#include +#include +#include +#include + +#define loslib_c +#define LUA_LIB + +#include "lua.h" + +#include "lauxlib.h" +#include "lualib.h" + + +static int os_pushresult (lua_State *L, int i, const char *filename) { + int en = errno; /* calls to Lua API may change this value */ + if (i) { + lua_pushboolean(L, 1); + return 1; + } + else { + lua_pushnil(L); + lua_pushfstring(L, "%s: %s", filename, strerror(en)); + lua_pushinteger(L, en); + return 3; + } +} + + +static int os_execute (lua_State *L) { + lua_pushinteger(L, system(luaL_optstring(L, 1, NULL))); + return 1; +} + + +static int os_remove (lua_State *L) { + const char *filename = luaL_checkstring(L, 1); + return os_pushresult(L, remove(filename) == 0, filename); +} + + +static int os_rename (lua_State *L) { + const char *fromname = luaL_checkstring(L, 1); + const char *toname = luaL_checkstring(L, 2); + return os_pushresult(L, rename(fromname, toname) == 0, fromname); +} + + +static int os_tmpname (lua_State *L) { + char buff[LUA_TMPNAMBUFSIZE]; + int err; + lua_tmpnam(buff, err); + if (err) + return luaL_error(L, "unable to generate a unique filename"); + lua_pushstring(L, buff); + return 1; +} + + +static int os_getenv (lua_State *L) { + lua_pushstring(L, getenv(luaL_checkstring(L, 1))); /* if NULL push nil */ + return 1; +} + + +static int os_clock (lua_State *L) { + lua_pushnumber(L, ((lua_Number)clock())/(lua_Number)CLOCKS_PER_SEC); + return 1; +} + + +/* +** {====================================================== +** Time/Date operations +** { year=%Y, month=%m, day=%d, hour=%H, min=%M, sec=%S, +** wday=%w+1, yday=%j, isdst=? } +** ======================================================= +*/ + +static void setfield (lua_State *L, const char *key, int value) { + lua_pushinteger(L, value); + lua_setfield(L, -2, key); +} + +static void setboolfield (lua_State *L, const char *key, int value) { + if (value < 0) /* undefined? */ + return; /* does not set field */ + lua_pushboolean(L, value); + lua_setfield(L, -2, key); +} + +static int getboolfield (lua_State *L, const char *key) { + int res; + lua_getfield(L, -1, key); + res = lua_isnil(L, -1) ? -1 : lua_toboolean(L, -1); + lua_pop(L, 1); + return res; +} + + +static int getfield (lua_State *L, const char *key, int d) { + int res; + lua_getfield(L, -1, key); + if (lua_isnumber(L, -1)) + res = (int)lua_tointeger(L, -1); + else { + if (d < 0) + return luaL_error(L, "field " LUA_QS " missing in date table", key); + res = d; + } + lua_pop(L, 1); + return res; +} + + +static int os_date (lua_State *L) { + const char *s = luaL_optstring(L, 1, "%c"); + time_t t = luaL_opt(L, (time_t)luaL_checknumber, 2, time(NULL)); + struct tm *stm; + if (*s == '!') { /* UTC? */ + stm = gmtime(&t); + s++; /* skip `!' */ + } + else + stm = localtime(&t); + if (stm == NULL) /* invalid date? */ + lua_pushnil(L); + else if (strcmp(s, "*t") == 0) { + lua_createtable(L, 0, 9); /* 9 = number of fields */ + setfield(L, "sec", stm->tm_sec); + setfield(L, "min", stm->tm_min); + setfield(L, "hour", stm->tm_hour); + setfield(L, "day", stm->tm_mday); + setfield(L, "month", stm->tm_mon+1); + setfield(L, "year", stm->tm_year+1900); + setfield(L, "wday", stm->tm_wday+1); + setfield(L, "yday", stm->tm_yday+1); + setboolfield(L, "isdst", stm->tm_isdst); + } + else { + char cc[3]; + luaL_Buffer b; + cc[0] = '%'; cc[2] = '\0'; + luaL_buffinit(L, &b); + for (; *s; s++) { + if (*s != '%' || *(s + 1) == '\0') /* no conversion specifier? */ + luaL_addchar(&b, *s); + else { + size_t reslen; + char buff[200]; /* should be big enough for any conversion result */ + cc[1] = *(++s); + reslen = strftime(buff, sizeof(buff), cc, stm); + luaL_addlstring(&b, buff, reslen); + } + } + luaL_pushresult(&b); + } + return 1; +} + + +static int os_time (lua_State *L) { + time_t t; + if (lua_isnoneornil(L, 1)) /* called without args? */ + t = time(NULL); /* get current time */ + else { + struct tm ts; + luaL_checktype(L, 1, LUA_TTABLE); + lua_settop(L, 1); /* make sure table is at the top */ + ts.tm_sec = getfield(L, "sec", 0); + ts.tm_min = getfield(L, "min", 0); + ts.tm_hour = getfield(L, "hour", 12); + ts.tm_mday = getfield(L, "day", -1); + ts.tm_mon = getfield(L, "month", -1) - 1; + ts.tm_year = getfield(L, "year", -1) - 1900; + ts.tm_isdst = getboolfield(L, "isdst"); + t = mktime(&ts); + } + if (t == (time_t)(-1)) + lua_pushnil(L); + else + lua_pushnumber(L, (lua_Number)t); + return 1; +} + + +static int os_difftime (lua_State *L) { + lua_pushnumber(L, difftime((time_t)(luaL_checknumber(L, 1)), + (time_t)(luaL_optnumber(L, 2, 0)))); + return 1; +} + +/* }====================================================== */ + + +static int os_setlocale (lua_State *L) { + static const int cat[] = {LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, + LC_NUMERIC, LC_TIME}; + static const char *const catnames[] = {"all", "collate", "ctype", "monetary", + "numeric", "time", NULL}; + const char *l = luaL_optstring(L, 1, NULL); + int op = luaL_checkoption(L, 2, "all", catnames); + lua_pushstring(L, setlocale(cat[op], l)); + return 1; +} + + +static int os_exit (lua_State *L) { + exit(luaL_optint(L, 1, EXIT_SUCCESS)); +} + +static const luaL_Reg syslib[] = { + {"clock", os_clock}, + {"date", os_date}, + {"difftime", os_difftime}, + {"execute", os_execute}, + {"exit", os_exit}, + {"getenv", os_getenv}, + {"remove", os_remove}, + {"rename", os_rename}, + {"setlocale", os_setlocale}, + {"time", os_time}, + {"tmpname", os_tmpname}, + {NULL, NULL} +}; + +/* }====================================================== */ + + + +LUALIB_API int luaopen_os (lua_State *L) { + luaL_register(L, LUA_OSLIBNAME, syslib); + return 1; +} + diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lparser.c b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lparser.c new file mode 100644 index 00000000..1e2a9a88 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lparser.c @@ -0,0 +1,1339 @@ +/* +** $Id: lparser.c,v 2.42.1.3 2007/12/28 15:32:23 roberto Exp $ +** Lua Parser +** See Copyright Notice in lua.h +*/ + + +#include + +#define lparser_c +#define LUA_CORE + +#include "lua.h" + +#include "lcode.h" +#include "ldebug.h" +#include "ldo.h" +#include "lfunc.h" +#include "llex.h" +#include "lmem.h" +#include "lobject.h" +#include "lopcodes.h" +#include "lparser.h" +#include "lstate.h" +#include "lstring.h" +#include "ltable.h" + + + +#define hasmultret(k) ((k) == VCALL || (k) == VVARARG) + +#define getlocvar(fs, i) ((fs)->f->locvars[(fs)->actvar[i]]) + +#define luaY_checklimit(fs,v,l,m) if ((v)>(l)) errorlimit(fs,l,m) + + +/* +** nodes for block list (list of active blocks) +*/ +typedef struct BlockCnt { + struct BlockCnt *previous; /* chain */ + int breaklist; /* list of jumps out of this loop */ + lu_byte nactvar; /* # active locals outside the breakable structure */ + lu_byte upval; /* true if some variable in the block is an upvalue */ + lu_byte isbreakable; /* true if `block' is a loop */ +} BlockCnt; + + + +/* +** prototypes for recursive non-terminal functions +*/ +static void chunk (LexState *ls); +static void expr (LexState *ls, expdesc *v); + + +static void anchor_token (LexState *ls) { + if (ls->t.token == TK_NAME || ls->t.token == TK_STRING) { + TString *ts = ls->t.seminfo.ts; + luaX_newstring(ls, getstr(ts), ts->tsv.len); + } +} + + +static void error_expected (LexState *ls, int token) { + luaX_syntaxerror(ls, + luaO_pushfstring(ls->L, LUA_QS " expected", luaX_token2str(ls, token))); +} + + +static void errorlimit (FuncState *fs, int limit, const char *what) { + const char *msg = (fs->f->linedefined == 0) ? + luaO_pushfstring(fs->L, "main function has more than %d %s", limit, what) : + luaO_pushfstring(fs->L, "function at line %d has more than %d %s", + fs->f->linedefined, limit, what); + luaX_lexerror(fs->ls, msg, 0); +} + + +static int testnext (LexState *ls, int c) { + if (ls->t.token == c) { + luaX_next(ls); + return 1; + } + else return 0; +} + + +static void check (LexState *ls, int c) { + if (ls->t.token != c) + error_expected(ls, c); +} + +static void checknext (LexState *ls, int c) { + check(ls, c); + luaX_next(ls); +} + + +#define check_condition(ls,c,msg) { if (!(c)) luaX_syntaxerror(ls, msg); } + + + +static void check_match (LexState *ls, int what, int who, int where) { + if (!testnext(ls, what)) { + if (where == ls->linenumber) + error_expected(ls, what); + else { + luaX_syntaxerror(ls, luaO_pushfstring(ls->L, + LUA_QS " expected (to close " LUA_QS " at line %d)", + luaX_token2str(ls, what), luaX_token2str(ls, who), where)); + } + } +} + + +static TString *str_checkname (LexState *ls) { + TString *ts; + check(ls, TK_NAME); + ts = ls->t.seminfo.ts; + luaX_next(ls); + return ts; +} + + +static void init_exp (expdesc *e, expkind k, int i) { + e->f = e->t = NO_JUMP; + e->k = k; + e->u.s.info = i; +} + + +static void codestring (LexState *ls, expdesc *e, TString *s) { + init_exp(e, VK, luaK_stringK(ls->fs, s)); +} + + +static void checkname(LexState *ls, expdesc *e) { + codestring(ls, e, str_checkname(ls)); +} + + +static int registerlocalvar (LexState *ls, TString *varname) { + FuncState *fs = ls->fs; + Proto *f = fs->f; + int oldsize = f->sizelocvars; + luaM_growvector(ls->L, f->locvars, fs->nlocvars, f->sizelocvars, + LocVar, SHRT_MAX, "too many local variables"); + while (oldsize < f->sizelocvars) f->locvars[oldsize++].varname = NULL; + f->locvars[fs->nlocvars].varname = varname; + luaC_objbarrier(ls->L, f, varname); + return fs->nlocvars++; +} + + +#define new_localvarliteral(ls,v,n) \ + new_localvar(ls, luaX_newstring(ls, "" v, (sizeof(v)/sizeof(char))-1), n) + + +static void new_localvar (LexState *ls, TString *name, int n) { + FuncState *fs = ls->fs; + luaY_checklimit(fs, fs->nactvar+n+1, LUAI_MAXVARS, "local variables"); + fs->actvar[fs->nactvar+n] = cast(unsigned short, registerlocalvar(ls, name)); +} + + +static void adjustlocalvars (LexState *ls, int nvars) { + FuncState *fs = ls->fs; + fs->nactvar = cast_byte(fs->nactvar + nvars); + for (; nvars; nvars--) { + getlocvar(fs, fs->nactvar - nvars).startpc = fs->pc; + } +} + + +static void removevars (LexState *ls, int tolevel) { + FuncState *fs = ls->fs; + while (fs->nactvar > tolevel) + getlocvar(fs, --fs->nactvar).endpc = fs->pc; +} + + +static int indexupvalue (FuncState *fs, TString *name, expdesc *v) { + int i; + Proto *f = fs->f; + int oldsize = f->sizeupvalues; + for (i=0; inups; i++) { + if (fs->upvalues[i].k == v->k && fs->upvalues[i].info == v->u.s.info) { + lua_assert(f->upvalues[i] == name); + return i; + } + } + /* new one */ + luaY_checklimit(fs, f->nups + 1, LUAI_MAXUPVALUES, "upvalues"); + luaM_growvector(fs->L, f->upvalues, f->nups, f->sizeupvalues, + TString *, MAX_INT, ""); + while (oldsize < f->sizeupvalues) f->upvalues[oldsize++] = NULL; + f->upvalues[f->nups] = name; + luaC_objbarrier(fs->L, f, name); + lua_assert(v->k == VLOCAL || v->k == VUPVAL); + fs->upvalues[f->nups].k = cast_byte(v->k); + fs->upvalues[f->nups].info = cast_byte(v->u.s.info); + return f->nups++; +} + + +static int searchvar (FuncState *fs, TString *n) { + int i; + for (i=fs->nactvar-1; i >= 0; i--) { + if (n == getlocvar(fs, i).varname) + return i; + } + return -1; /* not found */ +} + + +static void markupval (FuncState *fs, int level) { + BlockCnt *bl = fs->bl; + while (bl && bl->nactvar > level) bl = bl->previous; + if (bl) bl->upval = 1; +} + + +static int singlevaraux (FuncState *fs, TString *n, expdesc *var, int base) { + if (fs == NULL) { /* no more levels? */ + init_exp(var, VGLOBAL, NO_REG); /* default is global variable */ + return VGLOBAL; + } + else { + int v = searchvar(fs, n); /* look up at current level */ + if (v >= 0) { + init_exp(var, VLOCAL, v); + if (!base) + markupval(fs, v); /* local will be used as an upval */ + return VLOCAL; + } + else { /* not found at current level; try upper one */ + if (singlevaraux(fs->prev, n, var, 0) == VGLOBAL) + return VGLOBAL; + var->u.s.info = indexupvalue(fs, n, var); /* else was LOCAL or UPVAL */ + var->k = VUPVAL; /* upvalue in this level */ + return VUPVAL; + } + } +} + + +static void singlevar (LexState *ls, expdesc *var) { + TString *varname = str_checkname(ls); + FuncState *fs = ls->fs; + if (singlevaraux(fs, varname, var, 1) == VGLOBAL) + var->u.s.info = luaK_stringK(fs, varname); /* info points to global name */ +} + + +static void adjust_assign (LexState *ls, int nvars, int nexps, expdesc *e) { + FuncState *fs = ls->fs; + int extra = nvars - nexps; + if (hasmultret(e->k)) { + extra++; /* includes call itself */ + if (extra < 0) extra = 0; + luaK_setreturns(fs, e, extra); /* last exp. provides the difference */ + if (extra > 1) luaK_reserveregs(fs, extra-1); + } + else { + if (e->k != VVOID) luaK_exp2nextreg(fs, e); /* close last expression */ + if (extra > 0) { + int reg = fs->freereg; + luaK_reserveregs(fs, extra); + luaK_nil(fs, reg, extra); + } + } +} + + +static void enterlevel (LexState *ls) { + if (++ls->L->nCcalls > LUAI_MAXCCALLS) + luaX_lexerror(ls, "chunk has too many syntax levels", 0); +} + + +#define leavelevel(ls) ((ls)->L->nCcalls--) + + +static void enterblock (FuncState *fs, BlockCnt *bl, lu_byte isbreakable) { + bl->breaklist = NO_JUMP; + bl->isbreakable = isbreakable; + bl->nactvar = fs->nactvar; + bl->upval = 0; + bl->previous = fs->bl; + fs->bl = bl; + lua_assert(fs->freereg == fs->nactvar); +} + + +static void leaveblock (FuncState *fs) { + BlockCnt *bl = fs->bl; + fs->bl = bl->previous; + removevars(fs->ls, bl->nactvar); + if (bl->upval) + luaK_codeABC(fs, OP_CLOSE, bl->nactvar, 0, 0); + /* a block either controls scope or breaks (never both) */ + lua_assert(!bl->isbreakable || !bl->upval); + lua_assert(bl->nactvar == fs->nactvar); + fs->freereg = fs->nactvar; /* free registers */ + luaK_patchtohere(fs, bl->breaklist); +} + + +static void pushclosure (LexState *ls, FuncState *func, expdesc *v) { + FuncState *fs = ls->fs; + Proto *f = fs->f; + int oldsize = f->sizep; + int i; + luaM_growvector(ls->L, f->p, fs->np, f->sizep, Proto *, + MAXARG_Bx, "constant table overflow"); + while (oldsize < f->sizep) f->p[oldsize++] = NULL; + f->p[fs->np++] = func->f; + luaC_objbarrier(ls->L, f, func->f); + init_exp(v, VRELOCABLE, luaK_codeABx(fs, OP_CLOSURE, 0, fs->np-1)); + for (i=0; if->nups; i++) { + OpCode o = (func->upvalues[i].k == VLOCAL) ? OP_MOVE : OP_GETUPVAL; + luaK_codeABC(fs, o, 0, func->upvalues[i].info, 0); + } +} + + +static void open_func (LexState *ls, FuncState *fs) { + lua_State *L = ls->L; + Proto *f = luaF_newproto(L); + fs->f = f; + fs->prev = ls->fs; /* linked list of funcstates */ + fs->ls = ls; + fs->L = L; + ls->fs = fs; + fs->pc = 0; + fs->lasttarget = -1; + fs->jpc = NO_JUMP; + fs->freereg = 0; + fs->nk = 0; + fs->np = 0; + fs->nlocvars = 0; + fs->nactvar = 0; + fs->bl = NULL; + f->source = ls->source; + f->maxstacksize = 2; /* registers 0/1 are always valid */ + fs->h = luaH_new(L, 0, 0); + /* anchor table of constants and prototype (to avoid being collected) */ + sethvalue2s(L, L->top, fs->h); + incr_top(L); + setptvalue2s(L, L->top, f); + incr_top(L); +} + + +static void close_func (LexState *ls) { + lua_State *L = ls->L; + FuncState *fs = ls->fs; + Proto *f = fs->f; + removevars(ls, 0); + luaK_ret(fs, 0, 0); /* final return */ + luaM_reallocvector(L, f->code, f->sizecode, fs->pc, Instruction); + f->sizecode = fs->pc; + luaM_reallocvector(L, f->lineinfo, f->sizelineinfo, fs->pc, int); + f->sizelineinfo = fs->pc; + luaM_reallocvector(L, f->k, f->sizek, fs->nk, TValue); + f->sizek = fs->nk; + luaM_reallocvector(L, f->p, f->sizep, fs->np, Proto *); + f->sizep = fs->np; + luaM_reallocvector(L, f->locvars, f->sizelocvars, fs->nlocvars, LocVar); + f->sizelocvars = fs->nlocvars; + luaM_reallocvector(L, f->upvalues, f->sizeupvalues, f->nups, TString *); + f->sizeupvalues = f->nups; + lua_assert(luaG_checkcode(f)); + lua_assert(fs->bl == NULL); + ls->fs = fs->prev; + L->top -= 2; /* remove table and prototype from the stack */ + /* last token read was anchored in defunct function; must reanchor it */ + if (fs) anchor_token(ls); +} + + +Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, const char *name) { + struct LexState lexstate; + struct FuncState funcstate; + lexstate.buff = buff; + luaX_setinput(L, &lexstate, z, luaS_new(L, name)); + open_func(&lexstate, &funcstate); + funcstate.f->is_vararg = VARARG_ISVARARG; /* main func. is always vararg */ + luaX_next(&lexstate); /* read first token */ + chunk(&lexstate); + check(&lexstate, TK_EOS); + close_func(&lexstate); + lua_assert(funcstate.prev == NULL); + lua_assert(funcstate.f->nups == 0); + lua_assert(lexstate.fs == NULL); + return funcstate.f; +} + + + +/*============================================================*/ +/* GRAMMAR RULES */ +/*============================================================*/ + + +static void field (LexState *ls, expdesc *v) { + /* field -> ['.' | ':'] NAME */ + FuncState *fs = ls->fs; + expdesc key; + luaK_exp2anyreg(fs, v); + luaX_next(ls); /* skip the dot or colon */ + checkname(ls, &key); + luaK_indexed(fs, v, &key); +} + + +static void yindex (LexState *ls, expdesc *v) { + /* index -> '[' expr ']' */ + luaX_next(ls); /* skip the '[' */ + expr(ls, v); + luaK_exp2val(ls->fs, v); + checknext(ls, ']'); +} + + +/* +** {====================================================================== +** Rules for Constructors +** ======================================================================= +*/ + + +struct ConsControl { + expdesc v; /* last list item read */ + expdesc *t; /* table descriptor */ + int nh; /* total number of `record' elements */ + int na; /* total number of array elements */ + int tostore; /* number of array elements pending to be stored */ +}; + + +static void recfield (LexState *ls, struct ConsControl *cc) { + /* recfield -> (NAME | `['exp1`]') = exp1 */ + FuncState *fs = ls->fs; + int reg = ls->fs->freereg; + expdesc key, val; + int rkkey; + if (ls->t.token == TK_NAME) { + luaY_checklimit(fs, cc->nh, MAX_INT, "items in a constructor"); + checkname(ls, &key); + } + else /* ls->t.token == '[' */ + yindex(ls, &key); + cc->nh++; + checknext(ls, '='); + rkkey = luaK_exp2RK(fs, &key); + expr(ls, &val); + luaK_codeABC(fs, OP_SETTABLE, cc->t->u.s.info, rkkey, luaK_exp2RK(fs, &val)); + fs->freereg = reg; /* free registers */ +} + + +static void closelistfield (FuncState *fs, struct ConsControl *cc) { + if (cc->v.k == VVOID) return; /* there is no list item */ + luaK_exp2nextreg(fs, &cc->v); + cc->v.k = VVOID; + if (cc->tostore == LFIELDS_PER_FLUSH) { + luaK_setlist(fs, cc->t->u.s.info, cc->na, cc->tostore); /* flush */ + cc->tostore = 0; /* no more items pending */ + } +} + + +static void lastlistfield (FuncState *fs, struct ConsControl *cc) { + if (cc->tostore == 0) return; + if (hasmultret(cc->v.k)) { + luaK_setmultret(fs, &cc->v); + luaK_setlist(fs, cc->t->u.s.info, cc->na, LUA_MULTRET); + cc->na--; /* do not count last expression (unknown number of elements) */ + } + else { + if (cc->v.k != VVOID) + luaK_exp2nextreg(fs, &cc->v); + luaK_setlist(fs, cc->t->u.s.info, cc->na, cc->tostore); + } +} + + +static void listfield (LexState *ls, struct ConsControl *cc) { + expr(ls, &cc->v); + luaY_checklimit(ls->fs, cc->na, MAX_INT, "items in a constructor"); + cc->na++; + cc->tostore++; +} + + +static void constructor (LexState *ls, expdesc *t) { + /* constructor -> ?? */ + FuncState *fs = ls->fs; + int line = ls->linenumber; + int pc = luaK_codeABC(fs, OP_NEWTABLE, 0, 0, 0); + struct ConsControl cc; + cc.na = cc.nh = cc.tostore = 0; + cc.t = t; + init_exp(t, VRELOCABLE, pc); + init_exp(&cc.v, VVOID, 0); /* no value (yet) */ + luaK_exp2nextreg(ls->fs, t); /* fix it at stack top (for gc) */ + checknext(ls, '{'); + do { + lua_assert(cc.v.k == VVOID || cc.tostore > 0); + if (ls->t.token == '}') break; + closelistfield(fs, &cc); + switch(ls->t.token) { + case TK_NAME: { /* may be listfields or recfields */ + luaX_lookahead(ls); + if (ls->lookahead.token != '=') /* expression? */ + listfield(ls, &cc); + else + recfield(ls, &cc); + break; + } + case '[': { /* constructor_item -> recfield */ + recfield(ls, &cc); + break; + } + default: { /* constructor_part -> listfield */ + listfield(ls, &cc); + break; + } + } + } while (testnext(ls, ',') || testnext(ls, ';')); + check_match(ls, '}', '{', line); + lastlistfield(fs, &cc); + SETARG_B(fs->f->code[pc], luaO_int2fb(cc.na)); /* set initial array size */ + SETARG_C(fs->f->code[pc], luaO_int2fb(cc.nh)); /* set initial table size */ +} + +/* }====================================================================== */ + + + +static void parlist (LexState *ls) { + /* parlist -> [ param { `,' param } ] */ + FuncState *fs = ls->fs; + Proto *f = fs->f; + int nparams = 0; + f->is_vararg = 0; + if (ls->t.token != ')') { /* is `parlist' not empty? */ + do { + switch (ls->t.token) { + case TK_NAME: { /* param -> NAME */ + new_localvar(ls, str_checkname(ls), nparams++); + break; + } + case TK_DOTS: { /* param -> `...' */ + luaX_next(ls); +#if defined(LUA_COMPAT_VARARG) + /* use `arg' as default name */ + new_localvarliteral(ls, "arg", nparams++); + f->is_vararg = VARARG_HASARG | VARARG_NEEDSARG; +#endif + f->is_vararg |= VARARG_ISVARARG; + break; + } + default: luaX_syntaxerror(ls, " or " LUA_QL("...") " expected"); + } + } while (!f->is_vararg && testnext(ls, ',')); + } + adjustlocalvars(ls, nparams); + f->numparams = cast_byte(fs->nactvar - (f->is_vararg & VARARG_HASARG)); + luaK_reserveregs(fs, fs->nactvar); /* reserve register for parameters */ +} + + +static void body (LexState *ls, expdesc *e, int needself, int line) { + /* body -> `(' parlist `)' chunk END */ + FuncState new_fs; + open_func(ls, &new_fs); + new_fs.f->linedefined = line; + checknext(ls, '('); + if (needself) { + new_localvarliteral(ls, "self", 0); + adjustlocalvars(ls, 1); + } + parlist(ls); + checknext(ls, ')'); + chunk(ls); + new_fs.f->lastlinedefined = ls->linenumber; + check_match(ls, TK_END, TK_FUNCTION, line); + close_func(ls); + pushclosure(ls, &new_fs, e); +} + + +static int explist1 (LexState *ls, expdesc *v) { + /* explist1 -> expr { `,' expr } */ + int n = 1; /* at least one expression */ + expr(ls, v); + while (testnext(ls, ',')) { + luaK_exp2nextreg(ls->fs, v); + expr(ls, v); + n++; + } + return n; +} + + +static void funcargs (LexState *ls, expdesc *f) { + FuncState *fs = ls->fs; + expdesc args; + int base, nparams; + int line = ls->linenumber; + switch (ls->t.token) { + case '(': { /* funcargs -> `(' [ explist1 ] `)' */ + if (line != ls->lastline) + luaX_syntaxerror(ls,"ambiguous syntax (function call x new statement)"); + luaX_next(ls); + if (ls->t.token == ')') /* arg list is empty? */ + args.k = VVOID; + else { + explist1(ls, &args); + luaK_setmultret(fs, &args); + } + check_match(ls, ')', '(', line); + break; + } + case '{': { /* funcargs -> constructor */ + constructor(ls, &args); + break; + } + case TK_STRING: { /* funcargs -> STRING */ + codestring(ls, &args, ls->t.seminfo.ts); + luaX_next(ls); /* must use `seminfo' before `next' */ + break; + } + default: { + luaX_syntaxerror(ls, "function arguments expected"); + return; + } + } + lua_assert(f->k == VNONRELOC); + base = f->u.s.info; /* base register for call */ + if (hasmultret(args.k)) + nparams = LUA_MULTRET; /* open call */ + else { + if (args.k != VVOID) + luaK_exp2nextreg(fs, &args); /* close last argument */ + nparams = fs->freereg - (base+1); + } + init_exp(f, VCALL, luaK_codeABC(fs, OP_CALL, base, nparams+1, 2)); + luaK_fixline(fs, line); + fs->freereg = base+1; /* call remove function and arguments and leaves + (unless changed) one result */ +} + + + + +/* +** {====================================================================== +** Expression parsing +** ======================================================================= +*/ + + +static void prefixexp (LexState *ls, expdesc *v) { + /* prefixexp -> NAME | '(' expr ')' */ + switch (ls->t.token) { + case '(': { + int line = ls->linenumber; + luaX_next(ls); + expr(ls, v); + check_match(ls, ')', '(', line); + luaK_dischargevars(ls->fs, v); + return; + } + case TK_NAME: { + singlevar(ls, v); + return; + } + default: { + luaX_syntaxerror(ls, "unexpected symbol"); + return; + } + } +} + + +static void primaryexp (LexState *ls, expdesc *v) { + /* primaryexp -> + prefixexp { `.' NAME | `[' exp `]' | `:' NAME funcargs | funcargs } */ + FuncState *fs = ls->fs; + prefixexp(ls, v); + for (;;) { + switch (ls->t.token) { + case '.': { /* field */ + field(ls, v); + break; + } + case '[': { /* `[' exp1 `]' */ + expdesc key; + luaK_exp2anyreg(fs, v); + yindex(ls, &key); + luaK_indexed(fs, v, &key); + break; + } + case ':': { /* `:' NAME funcargs */ + expdesc key; + luaX_next(ls); + checkname(ls, &key); + luaK_self(fs, v, &key); + funcargs(ls, v); + break; + } + case '(': case TK_STRING: case '{': { /* funcargs */ + luaK_exp2nextreg(fs, v); + funcargs(ls, v); + break; + } + default: return; + } + } +} + + +static void simpleexp (LexState *ls, expdesc *v) { + /* simpleexp -> NUMBER | STRING | NIL | true | false | ... | + constructor | FUNCTION body | primaryexp */ + switch (ls->t.token) { + case TK_NUMBER: { + init_exp(v, VKNUM, 0); + v->u.nval = ls->t.seminfo.r; + break; + } + case TK_STRING: { + codestring(ls, v, ls->t.seminfo.ts); + break; + } + case TK_NIL: { + init_exp(v, VNIL, 0); + break; + } + case TK_TRUE: { + init_exp(v, VTRUE, 0); + break; + } + case TK_FALSE: { + init_exp(v, VFALSE, 0); + break; + } + case TK_DOTS: { /* vararg */ + FuncState *fs = ls->fs; + check_condition(ls, fs->f->is_vararg, + "cannot use " LUA_QL("...") " outside a vararg function"); + fs->f->is_vararg &= ~VARARG_NEEDSARG; /* don't need 'arg' */ + init_exp(v, VVARARG, luaK_codeABC(fs, OP_VARARG, 0, 1, 0)); + break; + } + case '{': { /* constructor */ + constructor(ls, v); + return; + } + case TK_FUNCTION: { + luaX_next(ls); + body(ls, v, 0, ls->linenumber); + return; + } + default: { + primaryexp(ls, v); + return; + } + } + luaX_next(ls); +} + + +static UnOpr getunopr (int op) { + switch (op) { + case TK_NOT: return OPR_NOT; + case '-': return OPR_MINUS; + case '#': return OPR_LEN; + default: return OPR_NOUNOPR; + } +} + + +static BinOpr getbinopr (int op) { + switch (op) { + case '+': return OPR_ADD; + case '-': return OPR_SUB; + case '*': return OPR_MUL; + case '/': return OPR_DIV; + case '%': return OPR_MOD; + case '^': return OPR_POW; + case TK_CONCAT: return OPR_CONCAT; + case TK_NE: return OPR_NE; + case TK_EQ: return OPR_EQ; + case '<': return OPR_LT; + case TK_LE: return OPR_LE; + case '>': return OPR_GT; + case TK_GE: return OPR_GE; + case TK_AND: return OPR_AND; + case TK_OR: return OPR_OR; + default: return OPR_NOBINOPR; + } +} + + +static const struct { + lu_byte left; /* left priority for each binary operator */ + lu_byte right; /* right priority */ +} priority[] = { /* ORDER OPR */ + {6, 6}, {6, 6}, {7, 7}, {7, 7}, {7, 7}, /* `+' `-' `/' `%' */ + {10, 9}, {5, 4}, /* power and concat (right associative) */ + {3, 3}, {3, 3}, /* equality and inequality */ + {3, 3}, {3, 3}, {3, 3}, {3, 3}, /* order */ + {2, 2}, {1, 1} /* logical (and/or) */ +}; + +#define UNARY_PRIORITY 8 /* priority for unary operators */ + + +/* +** subexpr -> (simpleexp | unop subexpr) { binop subexpr } +** where `binop' is any binary operator with a priority higher than `limit' +*/ +static BinOpr subexpr (LexState *ls, expdesc *v, unsigned int limit) { + BinOpr op; + UnOpr uop; + enterlevel(ls); + uop = getunopr(ls->t.token); + if (uop != OPR_NOUNOPR) { + luaX_next(ls); + subexpr(ls, v, UNARY_PRIORITY); + luaK_prefix(ls->fs, uop, v); + } + else simpleexp(ls, v); + /* expand while operators have priorities higher than `limit' */ + op = getbinopr(ls->t.token); + while (op != OPR_NOBINOPR && priority[op].left > limit) { + expdesc v2; + BinOpr nextop; + luaX_next(ls); + luaK_infix(ls->fs, op, v); + /* read sub-expression with higher priority */ + nextop = subexpr(ls, &v2, priority[op].right); + luaK_posfix(ls->fs, op, v, &v2); + op = nextop; + } + leavelevel(ls); + return op; /* return first untreated operator */ +} + + +static void expr (LexState *ls, expdesc *v) { + subexpr(ls, v, 0); +} + +/* }==================================================================== */ + + + +/* +** {====================================================================== +** Rules for Statements +** ======================================================================= +*/ + + +static int block_follow (int token) { + switch (token) { + case TK_ELSE: case TK_ELSEIF: case TK_END: + case TK_UNTIL: case TK_EOS: + return 1; + default: return 0; + } +} + + +static void block (LexState *ls) { + /* block -> chunk */ + FuncState *fs = ls->fs; + BlockCnt bl; + enterblock(fs, &bl, 0); + chunk(ls); + lua_assert(bl.breaklist == NO_JUMP); + leaveblock(fs); +} + + +/* +** structure to chain all variables in the left-hand side of an +** assignment +*/ +struct LHS_assign { + struct LHS_assign *prev; + expdesc v; /* variable (global, local, upvalue, or indexed) */ +}; + + +/* +** check whether, in an assignment to a local variable, the local variable +** is needed in a previous assignment (to a table). If so, save original +** local value in a safe place and use this safe copy in the previous +** assignment. +*/ +static void check_conflict (LexState *ls, struct LHS_assign *lh, expdesc *v) { + FuncState *fs = ls->fs; + int extra = fs->freereg; /* eventual position to save local variable */ + int conflict = 0; + for (; lh; lh = lh->prev) { + if (lh->v.k == VINDEXED) { + if (lh->v.u.s.info == v->u.s.info) { /* conflict? */ + conflict = 1; + lh->v.u.s.info = extra; /* previous assignment will use safe copy */ + } + if (lh->v.u.s.aux == v->u.s.info) { /* conflict? */ + conflict = 1; + lh->v.u.s.aux = extra; /* previous assignment will use safe copy */ + } + } + } + if (conflict) { + luaK_codeABC(fs, OP_MOVE, fs->freereg, v->u.s.info, 0); /* make copy */ + luaK_reserveregs(fs, 1); + } +} + + +static void assignment (LexState *ls, struct LHS_assign *lh, int nvars) { + expdesc e; + check_condition(ls, VLOCAL <= lh->v.k && lh->v.k <= VINDEXED, + "syntax error"); + if (testnext(ls, ',')) { /* assignment -> `,' primaryexp assignment */ + struct LHS_assign nv; + nv.prev = lh; + primaryexp(ls, &nv.v); + if (nv.v.k == VLOCAL) + check_conflict(ls, lh, &nv.v); + luaY_checklimit(ls->fs, nvars, LUAI_MAXCCALLS - ls->L->nCcalls, + "variables in assignment"); + assignment(ls, &nv, nvars+1); + } + else { /* assignment -> `=' explist1 */ + int nexps; + checknext(ls, '='); + nexps = explist1(ls, &e); + if (nexps != nvars) { + adjust_assign(ls, nvars, nexps, &e); + if (nexps > nvars) + ls->fs->freereg -= nexps - nvars; /* remove extra values */ + } + else { + luaK_setoneret(ls->fs, &e); /* close last expression */ + luaK_storevar(ls->fs, &lh->v, &e); + return; /* avoid default */ + } + } + init_exp(&e, VNONRELOC, ls->fs->freereg-1); /* default assignment */ + luaK_storevar(ls->fs, &lh->v, &e); +} + + +static int cond (LexState *ls) { + /* cond -> exp */ + expdesc v; + expr(ls, &v); /* read condition */ + if (v.k == VNIL) v.k = VFALSE; /* `falses' are all equal here */ + luaK_goiftrue(ls->fs, &v); + return v.f; +} + + +static void breakstat (LexState *ls) { + FuncState *fs = ls->fs; + BlockCnt *bl = fs->bl; + int upval = 0; + while (bl && !bl->isbreakable) { + upval |= bl->upval; + bl = bl->previous; + } + if (!bl) + luaX_syntaxerror(ls, "no loop to break"); + if (upval) + luaK_codeABC(fs, OP_CLOSE, bl->nactvar, 0, 0); + luaK_concat(fs, &bl->breaklist, luaK_jump(fs)); +} + + +static void whilestat (LexState *ls, int line) { + /* whilestat -> WHILE cond DO block END */ + FuncState *fs = ls->fs; + int whileinit; + int condexit; + BlockCnt bl; + luaX_next(ls); /* skip WHILE */ + whileinit = luaK_getlabel(fs); + condexit = cond(ls); + enterblock(fs, &bl, 1); + checknext(ls, TK_DO); + block(ls); + luaK_patchlist(fs, luaK_jump(fs), whileinit); + check_match(ls, TK_END, TK_WHILE, line); + leaveblock(fs); + luaK_patchtohere(fs, condexit); /* false conditions finish the loop */ +} + + +static void repeatstat (LexState *ls, int line) { + /* repeatstat -> REPEAT block UNTIL cond */ + int condexit; + FuncState *fs = ls->fs; + int repeat_init = luaK_getlabel(fs); + BlockCnt bl1, bl2; + enterblock(fs, &bl1, 1); /* loop block */ + enterblock(fs, &bl2, 0); /* scope block */ + luaX_next(ls); /* skip REPEAT */ + chunk(ls); + check_match(ls, TK_UNTIL, TK_REPEAT, line); + condexit = cond(ls); /* read condition (inside scope block) */ + if (!bl2.upval) { /* no upvalues? */ + leaveblock(fs); /* finish scope */ + luaK_patchlist(ls->fs, condexit, repeat_init); /* close the loop */ + } + else { /* complete semantics when there are upvalues */ + breakstat(ls); /* if condition then break */ + luaK_patchtohere(ls->fs, condexit); /* else... */ + leaveblock(fs); /* finish scope... */ + luaK_patchlist(ls->fs, luaK_jump(fs), repeat_init); /* and repeat */ + } + leaveblock(fs); /* finish loop */ +} + + +static int exp1 (LexState *ls) { + expdesc e; + int k; + expr(ls, &e); + k = e.k; + luaK_exp2nextreg(ls->fs, &e); + return k; +} + + +static void forbody (LexState *ls, int base, int line, int nvars, int isnum) { + /* forbody -> DO block */ + BlockCnt bl; + FuncState *fs = ls->fs; + int prep, endfor; + adjustlocalvars(ls, 3); /* control variables */ + checknext(ls, TK_DO); + prep = isnum ? luaK_codeAsBx(fs, OP_FORPREP, base, NO_JUMP) : luaK_jump(fs); + enterblock(fs, &bl, 0); /* scope for declared variables */ + adjustlocalvars(ls, nvars); + luaK_reserveregs(fs, nvars); + block(ls); + leaveblock(fs); /* end of scope for declared variables */ + luaK_patchtohere(fs, prep); + endfor = (isnum) ? luaK_codeAsBx(fs, OP_FORLOOP, base, NO_JUMP) : + luaK_codeABC(fs, OP_TFORLOOP, base, 0, nvars); + luaK_fixline(fs, line); /* pretend that `OP_FOR' starts the loop */ + luaK_patchlist(fs, (isnum ? endfor : luaK_jump(fs)), prep + 1); +} + + +static void fornum (LexState *ls, TString *varname, int line) { + /* fornum -> NAME = exp1,exp1[,exp1] forbody */ + FuncState *fs = ls->fs; + int base = fs->freereg; + new_localvarliteral(ls, "(for index)", 0); + new_localvarliteral(ls, "(for limit)", 1); + new_localvarliteral(ls, "(for step)", 2); + new_localvar(ls, varname, 3); + checknext(ls, '='); + exp1(ls); /* initial value */ + checknext(ls, ','); + exp1(ls); /* limit */ + if (testnext(ls, ',')) + exp1(ls); /* optional step */ + else { /* default step = 1 */ + luaK_codeABx(fs, OP_LOADK, fs->freereg, luaK_numberK(fs, 1)); + luaK_reserveregs(fs, 1); + } + forbody(ls, base, line, 1, 1); +} + + +static void forlist (LexState *ls, TString *indexname) { + /* forlist -> NAME {,NAME} IN explist1 forbody */ + FuncState *fs = ls->fs; + expdesc e; + int nvars = 0; + int line; + int base = fs->freereg; + /* create control variables */ + new_localvarliteral(ls, "(for generator)", nvars++); + new_localvarliteral(ls, "(for state)", nvars++); + new_localvarliteral(ls, "(for control)", nvars++); + /* create declared variables */ + new_localvar(ls, indexname, nvars++); + while (testnext(ls, ',')) + new_localvar(ls, str_checkname(ls), nvars++); + checknext(ls, TK_IN); + line = ls->linenumber; + adjust_assign(ls, 3, explist1(ls, &e), &e); + luaK_checkstack(fs, 3); /* extra space to call generator */ + forbody(ls, base, line, nvars - 3, 0); +} + + +static void forstat (LexState *ls, int line) { + /* forstat -> FOR (fornum | forlist) END */ + FuncState *fs = ls->fs; + TString *varname; + BlockCnt bl; + enterblock(fs, &bl, 1); /* scope for loop and control variables */ + luaX_next(ls); /* skip `for' */ + varname = str_checkname(ls); /* first variable name */ + switch (ls->t.token) { + case '=': fornum(ls, varname, line); break; + case ',': case TK_IN: forlist(ls, varname); break; + default: luaX_syntaxerror(ls, LUA_QL("=") " or " LUA_QL("in") " expected"); + } + check_match(ls, TK_END, TK_FOR, line); + leaveblock(fs); /* loop scope (`break' jumps to this point) */ +} + + +static int test_then_block (LexState *ls) { + /* test_then_block -> [IF | ELSEIF] cond THEN block */ + int condexit; + luaX_next(ls); /* skip IF or ELSEIF */ + condexit = cond(ls); + checknext(ls, TK_THEN); + block(ls); /* `then' part */ + return condexit; +} + + +static void ifstat (LexState *ls, int line) { + /* ifstat -> IF cond THEN block {ELSEIF cond THEN block} [ELSE block] END */ + FuncState *fs = ls->fs; + int flist; + int escapelist = NO_JUMP; + flist = test_then_block(ls); /* IF cond THEN block */ + while (ls->t.token == TK_ELSEIF) { + luaK_concat(fs, &escapelist, luaK_jump(fs)); + luaK_patchtohere(fs, flist); + flist = test_then_block(ls); /* ELSEIF cond THEN block */ + } + if (ls->t.token == TK_ELSE) { + luaK_concat(fs, &escapelist, luaK_jump(fs)); + luaK_patchtohere(fs, flist); + luaX_next(ls); /* skip ELSE (after patch, for correct line info) */ + block(ls); /* `else' part */ + } + else + luaK_concat(fs, &escapelist, flist); + luaK_patchtohere(fs, escapelist); + check_match(ls, TK_END, TK_IF, line); +} + + +static void localfunc (LexState *ls) { + expdesc v, b; + FuncState *fs = ls->fs; + new_localvar(ls, str_checkname(ls), 0); + init_exp(&v, VLOCAL, fs->freereg); + luaK_reserveregs(fs, 1); + adjustlocalvars(ls, 1); + body(ls, &b, 0, ls->linenumber); + luaK_storevar(fs, &v, &b); + /* debug information will only see the variable after this point! */ + getlocvar(fs, fs->nactvar - 1).startpc = fs->pc; +} + + +static void localstat (LexState *ls) { + /* stat -> LOCAL NAME {`,' NAME} [`=' explist1] */ + int nvars = 0; + int nexps; + expdesc e; + do { + new_localvar(ls, str_checkname(ls), nvars++); + } while (testnext(ls, ',')); + if (testnext(ls, '=')) + nexps = explist1(ls, &e); + else { + e.k = VVOID; + nexps = 0; + } + adjust_assign(ls, nvars, nexps, &e); + adjustlocalvars(ls, nvars); +} + + +static int funcname (LexState *ls, expdesc *v) { + /* funcname -> NAME {field} [`:' NAME] */ + int needself = 0; + singlevar(ls, v); + while (ls->t.token == '.') + field(ls, v); + if (ls->t.token == ':') { + needself = 1; + field(ls, v); + } + return needself; +} + + +static void funcstat (LexState *ls, int line) { + /* funcstat -> FUNCTION funcname body */ + int needself; + expdesc v, b; + luaX_next(ls); /* skip FUNCTION */ + needself = funcname(ls, &v); + body(ls, &b, needself, line); + luaK_storevar(ls->fs, &v, &b); + luaK_fixline(ls->fs, line); /* definition `happens' in the first line */ +} + + +static void exprstat (LexState *ls) { + /* stat -> func | assignment */ + FuncState *fs = ls->fs; + struct LHS_assign v; + primaryexp(ls, &v.v); + if (v.v.k == VCALL) /* stat -> func */ + SETARG_C(getcode(fs, &v.v), 1); /* call statement uses no results */ + else { /* stat -> assignment */ + v.prev = NULL; + assignment(ls, &v, 1); + } +} + + +static void retstat (LexState *ls) { + /* stat -> RETURN explist */ + FuncState *fs = ls->fs; + expdesc e; + int first, nret; /* registers with returned values */ + luaX_next(ls); /* skip RETURN */ + if (block_follow(ls->t.token) || ls->t.token == ';') + first = nret = 0; /* return no values */ + else { + nret = explist1(ls, &e); /* optional return values */ + if (hasmultret(e.k)) { + luaK_setmultret(fs, &e); + if (e.k == VCALL && nret == 1) { /* tail call? */ + SET_OPCODE(getcode(fs,&e), OP_TAILCALL); + lua_assert(GETARG_A(getcode(fs,&e)) == fs->nactvar); + } + first = fs->nactvar; + nret = LUA_MULTRET; /* return all values */ + } + else { + if (nret == 1) /* only one single value? */ + first = luaK_exp2anyreg(fs, &e); + else { + luaK_exp2nextreg(fs, &e); /* values must go to the `stack' */ + first = fs->nactvar; /* return all `active' values */ + lua_assert(nret == fs->freereg - first); + } + } + } + luaK_ret(fs, first, nret); +} + + +static int statement (LexState *ls) { + int line = ls->linenumber; /* may be needed for error messages */ + switch (ls->t.token) { + case TK_IF: { /* stat -> ifstat */ + ifstat(ls, line); + return 0; + } + case TK_WHILE: { /* stat -> whilestat */ + whilestat(ls, line); + return 0; + } + case TK_DO: { /* stat -> DO block END */ + luaX_next(ls); /* skip DO */ + block(ls); + check_match(ls, TK_END, TK_DO, line); + return 0; + } + case TK_FOR: { /* stat -> forstat */ + forstat(ls, line); + return 0; + } + case TK_REPEAT: { /* stat -> repeatstat */ + repeatstat(ls, line); + return 0; + } + case TK_FUNCTION: { + funcstat(ls, line); /* stat -> funcstat */ + return 0; + } + case TK_LOCAL: { /* stat -> localstat */ + luaX_next(ls); /* skip LOCAL */ + if (testnext(ls, TK_FUNCTION)) /* local function? */ + localfunc(ls); + else + localstat(ls); + return 0; + } + case TK_RETURN: { /* stat -> retstat */ + retstat(ls); + return 1; /* must be last statement */ + } + case TK_BREAK: { /* stat -> breakstat */ + luaX_next(ls); /* skip BREAK */ + breakstat(ls); + return 1; /* must be last statement */ + } + default: { + exprstat(ls); + return 0; /* to avoid warnings */ + } + } +} + + +static void chunk (LexState *ls) { + /* chunk -> { stat [`;'] } */ + int islast = 0; + enterlevel(ls); + while (!islast && !block_follow(ls->t.token)) { + islast = statement(ls); + testnext(ls, ';'); + lua_assert(ls->fs->f->maxstacksize >= ls->fs->freereg && + ls->fs->freereg >= ls->fs->nactvar); + ls->fs->freereg = ls->fs->nactvar; /* free registers */ + } + leavelevel(ls); +} + +/* }====================================================================== */ diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lparser.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lparser.h new file mode 100644 index 00000000..18836afd --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lparser.h @@ -0,0 +1,82 @@ +/* +** $Id: lparser.h,v 1.57.1.1 2007/12/27 13:02:25 roberto Exp $ +** Lua Parser +** See Copyright Notice in lua.h +*/ + +#ifndef lparser_h +#define lparser_h + +#include "llimits.h" +#include "lobject.h" +#include "lzio.h" + + +/* +** Expression descriptor +*/ + +typedef enum { + VVOID, /* no value */ + VNIL, + VTRUE, + VFALSE, + VK, /* info = index of constant in `k' */ + VKNUM, /* nval = numerical value */ + VLOCAL, /* info = local register */ + VUPVAL, /* info = index of upvalue in `upvalues' */ + VGLOBAL, /* info = index of table; aux = index of global name in `k' */ + VINDEXED, /* info = table register; aux = index register (or `k') */ + VJMP, /* info = instruction pc */ + VRELOCABLE, /* info = instruction pc */ + VNONRELOC, /* info = result register */ + VCALL, /* info = instruction pc */ + VVARARG /* info = instruction pc */ +} expkind; + +typedef struct expdesc { + expkind k; + union { + struct { int info, aux; } s; + lua_Number nval; + } u; + int t; /* patch list of `exit when true' */ + int f; /* patch list of `exit when false' */ +} expdesc; + + +typedef struct upvaldesc { + lu_byte k; + lu_byte info; +} upvaldesc; + + +struct BlockCnt; /* defined in lparser.c */ + + +/* state needed to generate code for a given function */ +typedef struct FuncState { + Proto *f; /* current function header */ + Table *h; /* table to find (and reuse) elements in `k' */ + struct FuncState *prev; /* enclosing function */ + struct LexState *ls; /* lexical state */ + struct lua_State *L; /* copy of the Lua state */ + struct BlockCnt *bl; /* chain of current blocks */ + int pc; /* next position to code (equivalent to `ncode') */ + int lasttarget; /* `pc' of last `jump target' */ + int jpc; /* list of pending jumps to `pc' */ + int freereg; /* first free register */ + int nk; /* number of elements in `k' */ + int np; /* number of elements in `p' */ + short nlocvars; /* number of elements in `locvars' */ + lu_byte nactvar; /* number of active local variables */ + upvaldesc upvalues[LUAI_MAXUPVALUES]; /* upvalues */ + unsigned short actvar[LUAI_MAXVARS]; /* declared-variable stack */ +} FuncState; + + +LUAI_FUNC Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, + const char *name); + + +#endif diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lstate.c b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lstate.c new file mode 100644 index 00000000..4313b83a --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lstate.c @@ -0,0 +1,214 @@ +/* +** $Id: lstate.c,v 2.36.1.2 2008/01/03 15:20:39 roberto Exp $ +** Global State +** See Copyright Notice in lua.h +*/ + + +#include + +#define lstate_c +#define LUA_CORE + +#include "lua.h" + +#include "ldebug.h" +#include "ldo.h" +#include "lfunc.h" +#include "lgc.h" +#include "llex.h" +#include "lmem.h" +#include "lstate.h" +#include "lstring.h" +#include "ltable.h" +#include "ltm.h" + + +#define state_size(x) (sizeof(x) + LUAI_EXTRASPACE) +#define fromstate(l) (cast(lu_byte *, (l)) - LUAI_EXTRASPACE) +#define tostate(l) (cast(lua_State *, cast(lu_byte *, l) + LUAI_EXTRASPACE)) + + +/* +** Main thread combines a thread state and the global state +*/ +typedef struct LG { + lua_State l; + global_State g; +} LG; + + + +static void stack_init (lua_State *L1, lua_State *L) { + /* initialize CallInfo array */ + L1->base_ci = luaM_newvector(L, BASIC_CI_SIZE, CallInfo); + L1->ci = L1->base_ci; + L1->size_ci = BASIC_CI_SIZE; + L1->end_ci = L1->base_ci + L1->size_ci - 1; + /* initialize stack array */ + L1->stack = luaM_newvector(L, BASIC_STACK_SIZE + EXTRA_STACK, TValue); + L1->stacksize = BASIC_STACK_SIZE + EXTRA_STACK; + L1->top = L1->stack; + L1->stack_last = L1->stack+(L1->stacksize - EXTRA_STACK)-1; + /* initialize first ci */ + L1->ci->func = L1->top; + setnilvalue(L1->top++); /* `function' entry for this `ci' */ + L1->base = L1->ci->base = L1->top; + L1->ci->top = L1->top + LUA_MINSTACK; +} + + +static void freestack (lua_State *L, lua_State *L1) { + luaM_freearray(L, L1->base_ci, L1->size_ci, CallInfo); + luaM_freearray(L, L1->stack, L1->stacksize, TValue); +} + + +/* +** open parts that may cause memory-allocation errors +*/ +static void f_luaopen (lua_State *L, void *ud) { + global_State *g = G(L); + UNUSED(ud); + stack_init(L, L); /* init stack */ + sethvalue(L, gt(L), luaH_new(L, 0, 2)); /* table of globals */ + sethvalue(L, registry(L), luaH_new(L, 0, 2)); /* registry */ + luaS_resize(L, MINSTRTABSIZE); /* initial size of string table */ + luaT_init(L); + luaX_init(L); + luaS_fix(luaS_newliteral(L, MEMERRMSG)); + g->GCthreshold = 4*g->totalbytes; +} + + +static void preinit_state (lua_State *L, global_State *g) { + G(L) = g; + L->stack = NULL; + L->stacksize = 0; + L->errorJmp = NULL; + L->hook = NULL; + L->hookmask = 0; + L->basehookcount = 0; + L->allowhook = 1; + resethookcount(L); + L->openupval = NULL; + L->size_ci = 0; + L->nCcalls = L->baseCcalls = 0; + L->status = 0; + L->base_ci = L->ci = NULL; + L->savedpc = NULL; + L->errfunc = 0; + setnilvalue(gt(L)); +} + + +static void close_state (lua_State *L) { + global_State *g = G(L); + luaF_close(L, L->stack); /* close all upvalues for this thread */ + luaC_freeall(L); /* collect all objects */ + lua_assert(g->rootgc == obj2gco(L)); + lua_assert(g->strt.nuse == 0); + luaM_freearray(L, G(L)->strt.hash, G(L)->strt.size, TString *); + luaZ_freebuffer(L, &g->buff); + freestack(L, L); + lua_assert(g->totalbytes == sizeof(LG)); + (*g->frealloc)(g->ud, fromstate(L), state_size(LG), 0); +} + + +lua_State *luaE_newthread (lua_State *L) { + lua_State *L1 = tostate(luaM_malloc(L, state_size(lua_State))); + luaC_link(L, obj2gco(L1), LUA_TTHREAD); + preinit_state(L1, G(L)); + stack_init(L1, L); /* init stack */ + setobj2n(L, gt(L1), gt(L)); /* share table of globals */ + L1->hookmask = L->hookmask; + L1->basehookcount = L->basehookcount; + L1->hook = L->hook; + resethookcount(L1); + lua_assert(iswhite(obj2gco(L1))); + return L1; +} + + +void luaE_freethread (lua_State *L, lua_State *L1) { + luaF_close(L1, L1->stack); /* close all upvalues for this thread */ + lua_assert(L1->openupval == NULL); + luai_userstatefree(L1); + freestack(L, L1); + luaM_freemem(L, fromstate(L1), state_size(lua_State)); +} + + +LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) { + int i; + lua_State *L; + global_State *g; + void *l = (*f)(ud, NULL, 0, state_size(LG)); + if (l == NULL) return NULL; + L = tostate(l); + g = &((LG *)L)->g; + L->next = NULL; + L->tt = LUA_TTHREAD; + g->currentwhite = bit2mask(WHITE0BIT, FIXEDBIT); + L->marked = luaC_white(g); + set2bits(L->marked, FIXEDBIT, SFIXEDBIT); + preinit_state(L, g); + g->frealloc = f; + g->ud = ud; + g->mainthread = L; + g->uvhead.u.l.prev = &g->uvhead; + g->uvhead.u.l.next = &g->uvhead; + g->GCthreshold = 0; /* mark it as unfinished state */ + g->strt.size = 0; + g->strt.nuse = 0; + g->strt.hash = NULL; + setnilvalue(registry(L)); + luaZ_initbuffer(L, &g->buff); + g->panic = NULL; + g->gcstate = GCSpause; + g->rootgc = obj2gco(L); + g->sweepstrgc = 0; + g->sweepgc = &g->rootgc; + g->gray = NULL; + g->grayagain = NULL; + g->weak = NULL; + g->tmudata = NULL; + g->totalbytes = sizeof(LG); + g->gcpause = LUAI_GCPAUSE; + g->gcstepmul = LUAI_GCMUL; + g->gcdept = 0; + for (i=0; imt[i] = NULL; + if (luaD_rawrunprotected(L, f_luaopen, NULL) != 0) { + /* memory allocation error: free partial state */ + close_state(L); + L = NULL; + } + else + luai_userstateopen(L); + return L; +} + + +static void callallgcTM (lua_State *L, void *ud) { + UNUSED(ud); + luaC_callGCTM(L); /* call GC metamethods for all udata */ +} + + +LUA_API void lua_close (lua_State *L) { + L = G(L)->mainthread; /* only the main thread can be closed */ + lua_lock(L); + luaF_close(L, L->stack); /* close all upvalues for this thread */ + luaC_separateudata(L, 1); /* separate udata that have GC metamethods */ + L->errfunc = 0; /* no error function during GC metamethods */ + do { /* repeat until no more errors */ + L->ci = L->base_ci; + L->base = L->top = L->ci->base; + L->nCcalls = L->baseCcalls = 0; + } while (luaD_rawrunprotected(L, callallgcTM, NULL) != 0); + lua_assert(G(L)->tmudata == NULL); + luai_userstateclose(L); + close_state(L); +} + diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lstate.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lstate.h new file mode 100644 index 00000000..3bc575b6 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lstate.h @@ -0,0 +1,169 @@ +/* +** $Id: lstate.h,v 2.24.1.2 2008/01/03 15:20:39 roberto Exp $ +** Global State +** See Copyright Notice in lua.h +*/ + +#ifndef lstate_h +#define lstate_h + +#include "lua.h" + +#include "lobject.h" +#include "ltm.h" +#include "lzio.h" + + + +struct lua_longjmp; /* defined in ldo.c */ + + +/* table of globals */ +#define gt(L) (&L->l_gt) + +/* registry */ +#define registry(L) (&G(L)->l_registry) + + +/* extra stack space to handle TM calls and some other extras */ +#define EXTRA_STACK 5 + + +#define BASIC_CI_SIZE 8 + +#define BASIC_STACK_SIZE (2*LUA_MINSTACK) + + + +typedef struct stringtable { + GCObject **hash; + lu_int32 nuse; /* number of elements */ + int size; +} stringtable; + + +/* +** informations about a call +*/ +typedef struct CallInfo { + StkId base; /* base for this function */ + StkId func; /* function index in the stack */ + StkId top; /* top for this function */ + const Instruction *savedpc; + int nresults; /* expected number of results from this function */ + int tailcalls; /* number of tail calls lost under this entry */ +} CallInfo; + + + +#define curr_func(L) (clvalue(L->ci->func)) +#define ci_func(ci) (clvalue((ci)->func)) +#define f_isLua(ci) (!ci_func(ci)->c.isC) +#define isLua(ci) (ttisfunction((ci)->func) && f_isLua(ci)) + + +/* +** `global state', shared by all threads of this state +*/ +typedef struct global_State { + stringtable strt; /* hash table for strings */ + lua_Alloc frealloc; /* function to reallocate memory */ + void *ud; /* auxiliary data to `frealloc' */ + lu_byte currentwhite; + lu_byte gcstate; /* state of garbage collector */ + int sweepstrgc; /* position of sweep in `strt' */ + GCObject *rootgc; /* list of all collectable objects */ + GCObject **sweepgc; /* position of sweep in `rootgc' */ + GCObject *gray; /* list of gray objects */ + GCObject *grayagain; /* list of objects to be traversed atomically */ + GCObject *weak; /* list of weak tables (to be cleared) */ + GCObject *tmudata; /* last element of list of userdata to be GC */ + Mbuffer buff; /* temporary buffer for string concatentation */ + lu_mem GCthreshold; + lu_mem totalbytes; /* number of bytes currently allocated */ + lu_mem estimate; /* an estimate of number of bytes actually in use */ + lu_mem gcdept; /* how much GC is `behind schedule' */ + int gcpause; /* size of pause between successive GCs */ + int gcstepmul; /* GC `granularity' */ + lua_CFunction panic; /* to be called in unprotected errors */ + TValue l_registry; + struct lua_State *mainthread; + UpVal uvhead; /* head of double-linked list of all open upvalues */ + struct Table *mt[NUM_TAGS]; /* metatables for basic types */ + TString *tmname[TM_N]; /* array with tag-method names */ +} global_State; + + +/* +** `per thread' state +*/ +struct lua_State { + CommonHeader; + lu_byte status; + StkId top; /* first free slot in the stack */ + StkId base; /* base of current function */ + global_State *l_G; + CallInfo *ci; /* call info for current function */ + const Instruction *savedpc; /* `savedpc' of current function */ + StkId stack_last; /* last free slot in the stack */ + StkId stack; /* stack base */ + CallInfo *end_ci; /* points after end of ci array*/ + CallInfo *base_ci; /* array of CallInfo's */ + int stacksize; + int size_ci; /* size of array `base_ci' */ + unsigned short nCcalls; /* number of nested C calls */ + unsigned short baseCcalls; /* nested C calls when resuming coroutine */ + lu_byte hookmask; + lu_byte allowhook; + int basehookcount; + int hookcount; + lua_Hook hook; + TValue l_gt; /* table of globals */ + TValue env; /* temporary place for environments */ + GCObject *openupval; /* list of open upvalues in this stack */ + GCObject *gclist; + struct lua_longjmp *errorJmp; /* current error recover point */ + ptrdiff_t errfunc; /* current error handling function (stack index) */ +}; + + +#define G(L) (L->l_G) + + +/* +** Union of all collectable objects +*/ +union GCObject { + GCheader gch; + union TString ts; + union Udata u; + union Closure cl; + struct Table h; + struct Proto p; + struct UpVal uv; + struct lua_State th; /* thread */ +}; + + +/* macros to convert a GCObject into a specific value */ +#define rawgco2ts(o) check_exp((o)->gch.tt == LUA_TSTRING, &((o)->ts)) +#define gco2ts(o) (&rawgco2ts(o)->tsv) +#define rawgco2u(o) check_exp((o)->gch.tt == LUA_TUSERDATA, &((o)->u)) +#define gco2u(o) (&rawgco2u(o)->uv) +#define gco2cl(o) check_exp((o)->gch.tt == LUA_TFUNCTION, &((o)->cl)) +#define gco2h(o) check_exp((o)->gch.tt == LUA_TTABLE, &((o)->h)) +#define gco2p(o) check_exp((o)->gch.tt == LUA_TPROTO, &((o)->p)) +#define gco2uv(o) check_exp((o)->gch.tt == LUA_TUPVAL, &((o)->uv)) +#define ngcotouv(o) \ + check_exp((o) == NULL || (o)->gch.tt == LUA_TUPVAL, &((o)->uv)) +#define gco2th(o) check_exp((o)->gch.tt == LUA_TTHREAD, &((o)->th)) + +/* macro to convert any Lua object into a GCObject */ +#define obj2gco(v) (cast(GCObject *, (v))) + + +LUAI_FUNC lua_State *luaE_newthread (lua_State *L); +LUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1); + +#endif + diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lstring.c b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lstring.c new file mode 100644 index 00000000..49113151 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lstring.c @@ -0,0 +1,111 @@ +/* +** $Id: lstring.c,v 2.8.1.1 2007/12/27 13:02:25 roberto Exp $ +** String table (keeps all strings handled by Lua) +** See Copyright Notice in lua.h +*/ + + +#include + +#define lstring_c +#define LUA_CORE + +#include "lua.h" + +#include "lmem.h" +#include "lobject.h" +#include "lstate.h" +#include "lstring.h" + + + +void luaS_resize (lua_State *L, int newsize) { + GCObject **newhash; + stringtable *tb; + int i; + if (G(L)->gcstate == GCSsweepstring) + return; /* cannot resize during GC traverse */ + newhash = luaM_newvector(L, newsize, GCObject *); + tb = &G(L)->strt; + for (i=0; isize; i++) { + GCObject *p = tb->hash[i]; + while (p) { /* for each node in the list */ + GCObject *next = p->gch.next; /* save next */ + unsigned int h = gco2ts(p)->hash; + int h1 = lmod(h, newsize); /* new position */ + lua_assert(cast_int(h%newsize) == lmod(h, newsize)); + p->gch.next = newhash[h1]; /* chain it */ + newhash[h1] = p; + p = next; + } + } + luaM_freearray(L, tb->hash, tb->size, TString *); + tb->size = newsize; + tb->hash = newhash; +} + + +static TString *newlstr (lua_State *L, const char *str, size_t l, + unsigned int h) { + TString *ts; + stringtable *tb; + if (l+1 > (MAX_SIZET - sizeof(TString))/sizeof(char)) + luaM_toobig(L); + ts = cast(TString *, luaM_malloc(L, (l+1)*sizeof(char)+sizeof(TString))); + ts->tsv.len = l; + ts->tsv.hash = h; + ts->tsv.marked = luaC_white(G(L)); + ts->tsv.tt = LUA_TSTRING; + ts->tsv.reserved = 0; + memcpy(ts+1, str, l*sizeof(char)); + ((char *)(ts+1))[l] = '\0'; /* ending 0 */ + tb = &G(L)->strt; + h = lmod(h, tb->size); + ts->tsv.next = tb->hash[h]; /* chain new entry */ + tb->hash[h] = obj2gco(ts); + tb->nuse++; + if (tb->nuse > cast(lu_int32, tb->size) && tb->size <= MAX_INT/2) + luaS_resize(L, tb->size*2); /* too crowded */ + return ts; +} + + +TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { + GCObject *o; + unsigned int h = cast(unsigned int, l); /* seed */ + size_t step = (l>>5)+1; /* if string is too long, don't hash all its chars */ + size_t l1; + for (l1=l; l1>=step; l1-=step) /* compute hash */ + h = h ^ ((h<<5)+(h>>2)+cast(unsigned char, str[l1-1])); + for (o = G(L)->strt.hash[lmod(h, G(L)->strt.size)]; + o != NULL; + o = o->gch.next) { + TString *ts = rawgco2ts(o); + if (ts->tsv.len == l && (memcmp(str, getstr(ts), l) == 0)) { + /* string may be dead */ + if (isdead(G(L), o)) changewhite(o); + return ts; + } + } + return newlstr(L, str, l, h); /* not found */ +} + + +Udata *luaS_newudata (lua_State *L, size_t s, Table *e) { + Udata *u; + if (s > MAX_SIZET - sizeof(Udata)) + luaM_toobig(L); + u = cast(Udata *, luaM_malloc(L, s + sizeof(Udata))); + u->uv.marked = luaC_white(G(L)); /* is not finalized */ + u->uv.tt = LUA_TUSERDATA; + u->uv.len = s; + u->uv.metatable = NULL; + u->uv.env = e; + /* chain it on udata list (after main thread) */ + u->uv.next = G(L)->mainthread->next; + G(L)->mainthread->next = obj2gco(u); + return u; +} + diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lstring.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lstring.h new file mode 100644 index 00000000..73a2ff8b --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lstring.h @@ -0,0 +1,31 @@ +/* +** $Id: lstring.h,v 1.43.1.1 2007/12/27 13:02:25 roberto Exp $ +** String table (keep all strings handled by Lua) +** See Copyright Notice in lua.h +*/ + +#ifndef lstring_h +#define lstring_h + + +#include "lgc.h" +#include "lobject.h" +#include "lstate.h" + + +#define sizestring(s) (sizeof(union TString)+((s)->len+1)*sizeof(char)) + +#define sizeudata(u) (sizeof(union Udata)+(u)->len) + +#define luaS_new(L, s) (luaS_newlstr(L, s, strlen(s))) +#define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \ + (sizeof(s)/sizeof(char))-1)) + +#define luaS_fix(s) l_setbit((s)->tsv.marked, FIXEDBIT) + +LUAI_FUNC void luaS_resize (lua_State *L, int newsize); +LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s, Table *e); +LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l); + + +#endif diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lstrlib.c b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lstrlib.c new file mode 100644 index 00000000..1b4763d4 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lstrlib.c @@ -0,0 +1,869 @@ +/* +** $Id: lstrlib.c,v 1.132.1.4 2008/07/11 17:27:21 roberto Exp $ +** Standard library for string operations and pattern-matching +** See Copyright Notice in lua.h +*/ + + +#include +#include +#include +#include +#include + +#define lstrlib_c +#define LUA_LIB + +#include "lua.h" + +#include "lauxlib.h" +#include "lualib.h" + + +/* macro to `unsign' a character */ +#define uchar(c) ((unsigned char)(c)) + + + +static int str_len (lua_State *L) { + size_t l; + luaL_checklstring(L, 1, &l); + lua_pushinteger(L, l); + return 1; +} + + +static ptrdiff_t posrelat (ptrdiff_t pos, size_t len) { + /* relative string position: negative means back from end */ + if (pos < 0) pos += (ptrdiff_t)len + 1; + return (pos >= 0) ? pos : 0; +} + + +static int str_sub (lua_State *L) { + size_t l; + const char *s = luaL_checklstring(L, 1, &l); + ptrdiff_t start = posrelat(luaL_checkinteger(L, 2), l); + ptrdiff_t end = posrelat(luaL_optinteger(L, 3, -1), l); + if (start < 1) start = 1; + if (end > (ptrdiff_t)l) end = (ptrdiff_t)l; + if (start <= end) + lua_pushlstring(L, s+start-1, end-start+1); + else lua_pushliteral(L, ""); + return 1; +} + + +static int str_reverse (lua_State *L) { + size_t l; + luaL_Buffer b; + const char *s = luaL_checklstring(L, 1, &l); + luaL_buffinit(L, &b); + while (l--) luaL_addchar(&b, s[l]); + luaL_pushresult(&b); + return 1; +} + + +static int str_lower (lua_State *L) { + size_t l; + size_t i; + luaL_Buffer b; + const char *s = luaL_checklstring(L, 1, &l); + luaL_buffinit(L, &b); + for (i=0; i 0) + luaL_addlstring(&b, s, l); + luaL_pushresult(&b); + return 1; +} + + +static int str_byte (lua_State *L) { + size_t l; + const char *s = luaL_checklstring(L, 1, &l); + ptrdiff_t posi = posrelat(luaL_optinteger(L, 2, 1), l); + ptrdiff_t pose = posrelat(luaL_optinteger(L, 3, posi), l); + int n, i; + if (posi <= 0) posi = 1; + if ((size_t)pose > l) pose = l; + if (posi > pose) return 0; /* empty interval; return no values */ + n = (int)(pose - posi + 1); + if (posi + n <= pose) /* overflow? */ + luaL_error(L, "string slice too long"); + luaL_checkstack(L, n, "string slice too long"); + for (i=0; i= ms->level || ms->capture[l].len == CAP_UNFINISHED) + return luaL_error(ms->L, "invalid capture index"); + return l; +} + + +static int capture_to_close (MatchState *ms) { + int level = ms->level; + for (level--; level>=0; level--) + if (ms->capture[level].len == CAP_UNFINISHED) return level; + return luaL_error(ms->L, "invalid pattern capture"); +} + + +static const char *classend (MatchState *ms, const char *p) { + switch (*p++) { + case L_ESC: { + if (*p == '\0') + luaL_error(ms->L, "malformed pattern (ends with " LUA_QL("%%") ")"); + return p+1; + } + case '[': { + if (*p == '^') p++; + do { /* look for a `]' */ + if (*p == '\0') + luaL_error(ms->L, "malformed pattern (missing " LUA_QL("]") ")"); + if (*(p++) == L_ESC && *p != '\0') + p++; /* skip escapes (e.g. `%]') */ + } while (*p != ']'); + return p+1; + } + default: { + return p; + } + } +} + + +static int match_class (int c, int cl) { + int res; + switch (tolower(cl)) { + case 'a' : res = isalpha(c); break; + case 'c' : res = iscntrl(c); break; + case 'd' : res = isdigit(c); break; + case 'l' : res = islower(c); break; + case 'p' : res = ispunct(c); break; + case 's' : res = isspace(c); break; + case 'u' : res = isupper(c); break; + case 'w' : res = isalnum(c); break; + case 'x' : res = isxdigit(c); break; + case 'z' : res = (c == 0); break; + default: return (cl == c); + } + return (islower(cl) ? res : !res); +} + + +static int matchbracketclass (int c, const char *p, const char *ec) { + int sig = 1; + if (*(p+1) == '^') { + sig = 0; + p++; /* skip the `^' */ + } + while (++p < ec) { + if (*p == L_ESC) { + p++; + if (match_class(c, uchar(*p))) + return sig; + } + else if ((*(p+1) == '-') && (p+2 < ec)) { + p+=2; + if (uchar(*(p-2)) <= c && c <= uchar(*p)) + return sig; + } + else if (uchar(*p) == c) return sig; + } + return !sig; +} + + +static int singlematch (int c, const char *p, const char *ep) { + switch (*p) { + case '.': return 1; /* matches any char */ + case L_ESC: return match_class(c, uchar(*(p+1))); + case '[': return matchbracketclass(c, p, ep-1); + default: return (uchar(*p) == c); + } +} + + +static const char *match (MatchState *ms, const char *s, const char *p); + + +static const char *matchbalance (MatchState *ms, const char *s, + const char *p) { + if (*p == 0 || *(p+1) == 0) + luaL_error(ms->L, "unbalanced pattern"); + if (*s != *p) return NULL; + else { + int b = *p; + int e = *(p+1); + int cont = 1; + while (++s < ms->src_end) { + if (*s == e) { + if (--cont == 0) return s+1; + } + else if (*s == b) cont++; + } + } + return NULL; /* string ends out of balance */ +} + + +static const char *max_expand (MatchState *ms, const char *s, + const char *p, const char *ep) { + ptrdiff_t i = 0; /* counts maximum expand for item */ + while ((s+i)src_end && singlematch(uchar(*(s+i)), p, ep)) + i++; + /* keeps trying to match with the maximum repetitions */ + while (i>=0) { + const char *res = match(ms, (s+i), ep+1); + if (res) return res; + i--; /* else didn't match; reduce 1 repetition to try again */ + } + return NULL; +} + + +static const char *min_expand (MatchState *ms, const char *s, + const char *p, const char *ep) { + for (;;) { + const char *res = match(ms, s, ep+1); + if (res != NULL) + return res; + else if (ssrc_end && singlematch(uchar(*s), p, ep)) + s++; /* try with one more repetition */ + else return NULL; + } +} + + +static const char *start_capture (MatchState *ms, const char *s, + const char *p, int what) { + const char *res; + int level = ms->level; + if (level >= LUA_MAXCAPTURES) luaL_error(ms->L, "too many captures"); + ms->capture[level].init = s; + ms->capture[level].len = what; + ms->level = level+1; + if ((res=match(ms, s, p)) == NULL) /* match failed? */ + ms->level--; /* undo capture */ + return res; +} + + +static const char *end_capture (MatchState *ms, const char *s, + const char *p) { + int l = capture_to_close(ms); + const char *res; + ms->capture[l].len = s - ms->capture[l].init; /* close capture */ + if ((res = match(ms, s, p)) == NULL) /* match failed? */ + ms->capture[l].len = CAP_UNFINISHED; /* undo capture */ + return res; +} + + +static const char *match_capture (MatchState *ms, const char *s, int l) { + size_t len; + l = check_capture(ms, l); + len = ms->capture[l].len; + if ((size_t)(ms->src_end-s) >= len && + memcmp(ms->capture[l].init, s, len) == 0) + return s+len; + else return NULL; +} + + +static const char *match (MatchState *ms, const char *s, const char *p) { + init: /* using goto's to optimize tail recursion */ + switch (*p) { + case '(': { /* start capture */ + if (*(p+1) == ')') /* position capture? */ + return start_capture(ms, s, p+2, CAP_POSITION); + else + return start_capture(ms, s, p+1, CAP_UNFINISHED); + } + case ')': { /* end capture */ + return end_capture(ms, s, p+1); + } + case L_ESC: { + switch (*(p+1)) { + case 'b': { /* balanced string? */ + s = matchbalance(ms, s, p+2); + if (s == NULL) return NULL; + p+=4; goto init; /* else return match(ms, s, p+4); */ + } + case 'f': { /* frontier? */ + const char *ep; char previous; + p += 2; + if (*p != '[') + luaL_error(ms->L, "missing " LUA_QL("[") " after " + LUA_QL("%%f") " in pattern"); + ep = classend(ms, p); /* points to what is next */ + previous = (s == ms->src_init) ? '\0' : *(s-1); + if (matchbracketclass(uchar(previous), p, ep-1) || + !matchbracketclass(uchar(*s), p, ep-1)) return NULL; + p=ep; goto init; /* else return match(ms, s, ep); */ + } + default: { + if (isdigit(uchar(*(p+1)))) { /* capture results (%0-%9)? */ + s = match_capture(ms, s, uchar(*(p+1))); + if (s == NULL) return NULL; + p+=2; goto init; /* else return match(ms, s, p+2) */ + } + goto dflt; /* case default */ + } + } + } + case '\0': { /* end of pattern */ + return s; /* match succeeded */ + } + case '$': { + if (*(p+1) == '\0') /* is the `$' the last char in pattern? */ + return (s == ms->src_end) ? s : NULL; /* check end of string */ + else goto dflt; + } + default: dflt: { /* it is a pattern item */ + const char *ep = classend(ms, p); /* points to what is next */ + int m = ssrc_end && singlematch(uchar(*s), p, ep); + switch (*ep) { + case '?': { /* optional */ + const char *res; + if (m && ((res=match(ms, s+1, ep+1)) != NULL)) + return res; + p=ep+1; goto init; /* else return match(ms, s, ep+1); */ + } + case '*': { /* 0 or more repetitions */ + return max_expand(ms, s, p, ep); + } + case '+': { /* 1 or more repetitions */ + return (m ? max_expand(ms, s+1, p, ep) : NULL); + } + case '-': { /* 0 or more repetitions (minimum) */ + return min_expand(ms, s, p, ep); + } + default: { + if (!m) return NULL; + s++; p=ep; goto init; /* else return match(ms, s+1, ep); */ + } + } + } + } +} + + + +static const char *lmemfind (const char *s1, size_t l1, + const char *s2, size_t l2) { + if (l2 == 0) return s1; /* empty strings are everywhere */ + else if (l2 > l1) return NULL; /* avoids a negative `l1' */ + else { + const char *init; /* to search for a `*s2' inside `s1' */ + l2--; /* 1st char will be checked by `memchr' */ + l1 = l1-l2; /* `s2' cannot be found after that */ + while (l1 > 0 && (init = (const char *)memchr(s1, *s2, l1)) != NULL) { + init++; /* 1st char is already checked */ + if (memcmp(init, s2+1, l2) == 0) + return init-1; + else { /* correct `l1' and `s1' to try again */ + l1 -= init-s1; + s1 = init; + } + } + return NULL; /* not found */ + } +} + + +static void push_onecapture (MatchState *ms, int i, const char *s, + const char *e) { + if (i >= ms->level) { + if (i == 0) /* ms->level == 0, too */ + lua_pushlstring(ms->L, s, e - s); /* add whole match */ + else + luaL_error(ms->L, "invalid capture index"); + } + else { + ptrdiff_t l = ms->capture[i].len; + if (l == CAP_UNFINISHED) luaL_error(ms->L, "unfinished capture"); + if (l == CAP_POSITION) + lua_pushinteger(ms->L, ms->capture[i].init - ms->src_init + 1); + else + lua_pushlstring(ms->L, ms->capture[i].init, l); + } +} + + +static int push_captures (MatchState *ms, const char *s, const char *e) { + int i; + int nlevels = (ms->level == 0 && s) ? 1 : ms->level; + luaL_checkstack(ms->L, nlevels, "too many captures"); + for (i = 0; i < nlevels; i++) + push_onecapture(ms, i, s, e); + return nlevels; /* number of strings pushed */ +} + + +static int str_find_aux (lua_State *L, int find) { + size_t l1, l2; + const char *s = luaL_checklstring(L, 1, &l1); + const char *p = luaL_checklstring(L, 2, &l2); + ptrdiff_t init = posrelat(luaL_optinteger(L, 3, 1), l1) - 1; + if (init < 0) init = 0; + else if ((size_t)(init) > l1) init = (ptrdiff_t)l1; + if (find && (lua_toboolean(L, 4) || /* explicit request? */ + strpbrk(p, SPECIALS) == NULL)) { /* or no special characters? */ + /* do a plain search */ + const char *s2 = lmemfind(s+init, l1-init, p, l2); + if (s2) { + lua_pushinteger(L, s2-s+1); + lua_pushinteger(L, s2-s+l2); + return 2; + } + } + else { + MatchState ms; + int anchor = (*p == '^') ? (p++, 1) : 0; + const char *s1=s+init; + ms.L = L; + ms.src_init = s; + ms.src_end = s+l1; + do { + const char *res; + ms.level = 0; + if ((res=match(&ms, s1, p)) != NULL) { + if (find) { + lua_pushinteger(L, s1-s+1); /* start */ + lua_pushinteger(L, res-s); /* end */ + return push_captures(&ms, NULL, 0) + 2; + } + else + return push_captures(&ms, s1, res); + } + } while (s1++ < ms.src_end && !anchor); + } + lua_pushnil(L); /* not found */ + return 1; +} + + +static int str_find (lua_State *L) { + return str_find_aux(L, 1); +} + + +static int str_match (lua_State *L) { + return str_find_aux(L, 0); +} + + +static int gmatch_aux (lua_State *L) { + MatchState ms; + size_t ls; + const char *s = lua_tolstring(L, lua_upvalueindex(1), &ls); + const char *p = lua_tostring(L, lua_upvalueindex(2)); + const char *src; + ms.L = L; + ms.src_init = s; + ms.src_end = s+ls; + for (src = s + (size_t)lua_tointeger(L, lua_upvalueindex(3)); + src <= ms.src_end; + src++) { + const char *e; + ms.level = 0; + if ((e = match(&ms, src, p)) != NULL) { + lua_Integer newstart = e-s; + if (e == src) newstart++; /* empty match? go at least one position */ + lua_pushinteger(L, newstart); + lua_replace(L, lua_upvalueindex(3)); + return push_captures(&ms, src, e); + } + } + return 0; /* not found */ +} + + +static int gmatch (lua_State *L) { + luaL_checkstring(L, 1); + luaL_checkstring(L, 2); + lua_settop(L, 2); + lua_pushinteger(L, 0); + lua_pushcclosure(L, gmatch_aux, 3); + return 1; +} + + +static int gfind_nodef (lua_State *L) { + return luaL_error(L, LUA_QL("string.gfind") " was renamed to " + LUA_QL("string.gmatch")); +} + + +static void add_s (MatchState *ms, luaL_Buffer *b, const char *s, + const char *e) { + size_t l, i; + const char *news = lua_tolstring(ms->L, 3, &l); + for (i = 0; i < l; i++) { + if (news[i] != L_ESC) + luaL_addchar(b, news[i]); + else { + i++; /* skip ESC */ + if (!isdigit(uchar(news[i]))) + luaL_addchar(b, news[i]); + else if (news[i] == '0') + luaL_addlstring(b, s, e - s); + else { + push_onecapture(ms, news[i] - '1', s, e); + luaL_addvalue(b); /* add capture to accumulated result */ + } + } + } +} + + +static void add_value (MatchState *ms, luaL_Buffer *b, const char *s, + const char *e) { + lua_State *L = ms->L; + switch (lua_type(L, 3)) { + case LUA_TNUMBER: + case LUA_TSTRING: { + add_s(ms, b, s, e); + return; + } + case LUA_TFUNCTION: { + int n; + lua_pushvalue(L, 3); + n = push_captures(ms, s, e); + lua_call(L, n, 1); + break; + } + case LUA_TTABLE: { + push_onecapture(ms, 0, s, e); + lua_gettable(L, 3); + break; + } + } + if (!lua_toboolean(L, -1)) { /* nil or false? */ + lua_pop(L, 1); + lua_pushlstring(L, s, e - s); /* keep original text */ + } + else if (!lua_isstring(L, -1)) + luaL_error(L, "invalid replacement value (a %s)", luaL_typename(L, -1)); + luaL_addvalue(b); /* add result to accumulator */ +} + + +static int str_gsub (lua_State *L) { + size_t srcl; + const char *src = luaL_checklstring(L, 1, &srcl); + const char *p = luaL_checkstring(L, 2); + int tr = lua_type(L, 3); + int max_s = luaL_optint(L, 4, srcl+1); + int anchor = (*p == '^') ? (p++, 1) : 0; + int n = 0; + MatchState ms; + luaL_Buffer b; + luaL_argcheck(L, tr == LUA_TNUMBER || tr == LUA_TSTRING || + tr == LUA_TFUNCTION || tr == LUA_TTABLE, 3, + "string/function/table expected"); + luaL_buffinit(L, &b); + ms.L = L; + ms.src_init = src; + ms.src_end = src+srcl; + while (n < max_s) { + const char *e; + ms.level = 0; + e = match(&ms, src, p); + if (e) { + n++; + add_value(&ms, &b, src, e); + } + if (e && e>src) /* non empty match? */ + src = e; /* skip it */ + else if (src < ms.src_end) + luaL_addchar(&b, *src++); + else break; + if (anchor) break; + } + luaL_addlstring(&b, src, ms.src_end-src); + luaL_pushresult(&b); + lua_pushinteger(L, n); /* number of substitutions */ + return 2; +} + +/* }====================================================== */ + + +/* maximum size of each formatted item (> len(format('%99.99f', -1e308))) */ +#define MAX_ITEM 512 +/* valid flags in a format specification */ +#define FLAGS "-+ #0" +/* +** maximum size of each format specification (such as '%-099.99d') +** (+10 accounts for %99.99x plus margin of error) +*/ +#define MAX_FORMAT (sizeof(FLAGS) + sizeof(LUA_INTFRMLEN) + 10) + + +static void addquoted (lua_State *L, luaL_Buffer *b, int arg) { + size_t l; + const char *s = luaL_checklstring(L, arg, &l); + luaL_addchar(b, '"'); + while (l--) { + switch (*s) { + case '"': case '\\': case '\n': { + luaL_addchar(b, '\\'); + luaL_addchar(b, *s); + break; + } + case '\r': { + luaL_addlstring(b, "\\r", 2); + break; + } + case '\0': { + luaL_addlstring(b, "\\000", 4); + break; + } + default: { + luaL_addchar(b, *s); + break; + } + } + s++; + } + luaL_addchar(b, '"'); +} + +static const char *scanformat (lua_State *L, const char *strfrmt, char *form) { + const char *p = strfrmt; + while (*p != '\0' && strchr(FLAGS, *p) != NULL) p++; /* skip flags */ + if ((size_t)(p - strfrmt) >= sizeof(FLAGS)) + luaL_error(L, "invalid format (repeated flags)"); + if (isdigit(uchar(*p))) p++; /* skip width */ + if (isdigit(uchar(*p))) p++; /* (2 digits at most) */ + if (*p == '.') { + p++; + if (isdigit(uchar(*p))) p++; /* skip precision */ + if (isdigit(uchar(*p))) p++; /* (2 digits at most) */ + } + if (isdigit(uchar(*p))) + luaL_error(L, "invalid format (width or precision too long)"); + *(form++) = '%'; + strncpy(form, strfrmt, p - strfrmt + 1); + form += p - strfrmt + 1; + *form = '\0'; + return p; +} + + +static void addintlen (char *form) { + size_t l = strlen(form); + char spec = form[l - 1]; + strcpy(form + l - 1, LUA_INTFRMLEN); + form[l + sizeof(LUA_INTFRMLEN) - 2] = spec; + form[l + sizeof(LUA_INTFRMLEN) - 1] = '\0'; +} + + +static int str_format (lua_State *L) { + int arg = 1; + size_t sfl; + const char *strfrmt = luaL_checklstring(L, arg, &sfl); + const char *strfrmt_end = strfrmt+sfl; + luaL_Buffer b; + luaL_buffinit(L, &b); + while (strfrmt < strfrmt_end) { + if (*strfrmt != L_ESC) + luaL_addchar(&b, *strfrmt++); + else if (*++strfrmt == L_ESC) + luaL_addchar(&b, *strfrmt++); /* %% */ + else { /* format item */ + char form[MAX_FORMAT]; /* to store the format (`%...') */ + char buff[MAX_ITEM]; /* to store the formatted item */ + arg++; + strfrmt = scanformat(L, strfrmt, form); + switch (*strfrmt++) { + case 'c': { + sprintf(buff, form, (int)luaL_checknumber(L, arg)); + break; + } + case 'd': case 'i': { + addintlen(form); + sprintf(buff, form, (LUA_INTFRM_T)luaL_checknumber(L, arg)); + break; + } + case 'o': case 'u': case 'x': case 'X': { + addintlen(form); + sprintf(buff, form, (unsigned LUA_INTFRM_T)luaL_checknumber(L, arg)); + break; + } + case 'e': case 'E': case 'f': + case 'g': case 'G': { + sprintf(buff, form, (double)luaL_checknumber(L, arg)); + break; + } + case 'q': { + addquoted(L, &b, arg); + continue; /* skip the 'addsize' at the end */ + } + case 's': { + size_t l; + const char *s = luaL_checklstring(L, arg, &l); + if (!strchr(form, '.') && l >= 100) { + /* no precision and string is too long to be formatted; + keep original string */ + lua_pushvalue(L, arg); + luaL_addvalue(&b); + continue; /* skip the `addsize' at the end */ + } + else { + sprintf(buff, form, s); + break; + } + } + default: { /* also treat cases `pnLlh' */ + return luaL_error(L, "invalid option " LUA_QL("%%%c") " to " + LUA_QL("format"), *(strfrmt - 1)); + } + } + luaL_addlstring(&b, buff, strlen(buff)); + } + } + luaL_pushresult(&b); + return 1; +} + + +static const luaL_Reg strlib[] = { + {"byte", str_byte}, + {"char", str_char}, + {"dump", str_dump}, + {"find", str_find}, + {"format", str_format}, + {"gfind", gfind_nodef}, + {"gmatch", gmatch}, + {"gsub", str_gsub}, + {"len", str_len}, + {"lower", str_lower}, + {"match", str_match}, + {"rep", str_rep}, + {"reverse", str_reverse}, + {"sub", str_sub}, + {"upper", str_upper}, + {NULL, NULL} +}; + + +static void createmetatable (lua_State *L) { + lua_createtable(L, 0, 1); /* create metatable for strings */ + lua_pushliteral(L, ""); /* dummy string */ + lua_pushvalue(L, -2); + lua_setmetatable(L, -2); /* set string metatable */ + lua_pop(L, 1); /* pop dummy string */ + lua_pushvalue(L, -2); /* string library... */ + lua_setfield(L, -2, "__index"); /* ...is the __index metamethod */ + lua_pop(L, 1); /* pop metatable */ +} + + +/* +** Open string library +*/ +LUALIB_API int luaopen_string (lua_State *L) { + luaL_register(L, LUA_STRLIBNAME, strlib); +#if defined(LUA_COMPAT_GFIND) + lua_getfield(L, -1, "gmatch"); + lua_setfield(L, -2, "gfind"); +#endif + createmetatable(L); + return 1; +} + diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/ltable.c b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/ltable.c new file mode 100644 index 00000000..ec84f4fa --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/ltable.c @@ -0,0 +1,588 @@ +/* +** $Id: ltable.c,v 2.32.1.2 2007/12/28 15:32:23 roberto Exp $ +** Lua tables (hash) +** See Copyright Notice in lua.h +*/ + + +/* +** Implementation of tables (aka arrays, objects, or hash tables). +** Tables keep its elements in two parts: an array part and a hash part. +** Non-negative integer keys are all candidates to be kept in the array +** part. The actual size of the array is the largest `n' such that at +** least half the slots between 0 and n are in use. +** Hash uses a mix of chained scatter table with Brent's variation. +** A main invariant of these tables is that, if an element is not +** in its main position (i.e. the `original' position that its hash gives +** to it), then the colliding element is in its own main position. +** Hence even when the load factor reaches 100%, performance remains good. +*/ + +#include +#include + +#define ltable_c +#define LUA_CORE + +#include "lua.h" + +#include "ldebug.h" +#include "ldo.h" +#include "lgc.h" +#include "lmem.h" +#include "lobject.h" +#include "lstate.h" +#include "ltable.h" + + +/* +** max size of array part is 2^MAXBITS +*/ +#if LUAI_BITSINT > 26 +#define MAXBITS 26 +#else +#define MAXBITS (LUAI_BITSINT-2) +#endif + +#define MAXASIZE (1 << MAXBITS) + + +#define hashpow2(t,n) (gnode(t, lmod((n), sizenode(t)))) + +#define hashstr(t,str) hashpow2(t, (str)->tsv.hash) +#define hashboolean(t,p) hashpow2(t, p) + + +/* +** for some types, it is better to avoid modulus by power of 2, as +** they tend to have many 2 factors. +*/ +#define hashmod(t,n) (gnode(t, ((n) % ((sizenode(t)-1)|1)))) + + +#define hashpointer(t,p) hashmod(t, IntPoint(p)) + + +/* +** number of ints inside a lua_Number +*/ +#define numints cast_int(sizeof(lua_Number)/sizeof(int)) + + + +#define dummynode (&dummynode_) + +static const Node dummynode_ = { + {{NULL}, LUA_TNIL}, /* value */ + {{{NULL}, LUA_TNIL, NULL}} /* key */ +}; + + +/* +** hash for lua_Numbers +*/ +static Node *hashnum (const Table *t, lua_Number n) { + unsigned int a[numints]; + int i; + if (luai_numeq(n, 0)) /* avoid problems with -0 */ + return gnode(t, 0); + memcpy(a, &n, sizeof(a)); + for (i = 1; i < numints; i++) a[0] += a[i]; + return hashmod(t, a[0]); +} + + + +/* +** returns the `main' position of an element in a table (that is, the index +** of its hash value) +*/ +static Node *mainposition (const Table *t, const TValue *key) { + switch (ttype(key)) { + case LUA_TNUMBER: + return hashnum(t, nvalue(key)); + case LUA_TSTRING: + return hashstr(t, rawtsvalue(key)); + case LUA_TBOOLEAN: + return hashboolean(t, bvalue(key)); + case LUA_TLIGHTUSERDATA: + return hashpointer(t, pvalue(key)); + default: + return hashpointer(t, gcvalue(key)); + } +} + + +/* +** returns the index for `key' if `key' is an appropriate key to live in +** the array part of the table, -1 otherwise. +*/ +static int arrayindex (const TValue *key) { + if (ttisnumber(key)) { + lua_Number n = nvalue(key); + int k; + lua_number2int(k, n); + if (luai_numeq(cast_num(k), n)) + return k; + } + return -1; /* `key' did not match some condition */ +} + + +/* +** returns the index of a `key' for table traversals. First goes all +** elements in the array part, then elements in the hash part. The +** beginning of a traversal is signalled by -1. +*/ +static int findindex (lua_State *L, Table *t, StkId key) { + int i; + if (ttisnil(key)) return -1; /* first iteration */ + i = arrayindex(key); + if (0 < i && i <= t->sizearray) /* is `key' inside array part? */ + return i-1; /* yes; that's the index (corrected to C) */ + else { + Node *n = mainposition(t, key); + do { /* check whether `key' is somewhere in the chain */ + /* key may be dead already, but it is ok to use it in `next' */ + if (luaO_rawequalObj(key2tval(n), key) || + (ttype(gkey(n)) == LUA_TDEADKEY && iscollectable(key) && + gcvalue(gkey(n)) == gcvalue(key))) { + i = cast_int(n - gnode(t, 0)); /* key index in hash table */ + /* hash elements are numbered after array ones */ + return i + t->sizearray; + } + else n = gnext(n); + } while (n); + luaG_runerror(L, "invalid key to " LUA_QL("next")); /* key not found */ + return 0; /* to avoid warnings */ + } +} + + +int luaH_next (lua_State *L, Table *t, StkId key) { + int i = findindex(L, t, key); /* find original element */ + for (i++; i < t->sizearray; i++) { /* try first array part */ + if (!ttisnil(&t->array[i])) { /* a non-nil value? */ + setnvalue(key, cast_num(i+1)); + setobj2s(L, key+1, &t->array[i]); + return 1; + } + } + for (i -= t->sizearray; i < sizenode(t); i++) { /* then hash part */ + if (!ttisnil(gval(gnode(t, i)))) { /* a non-nil value? */ + setobj2s(L, key, key2tval(gnode(t, i))); + setobj2s(L, key+1, gval(gnode(t, i))); + return 1; + } + } + return 0; /* no more elements */ +} + + +/* +** {============================================================= +** Rehash +** ============================================================== +*/ + + +static int computesizes (int nums[], int *narray) { + int i; + int twotoi; /* 2^i */ + int a = 0; /* number of elements smaller than 2^i */ + int na = 0; /* number of elements to go to array part */ + int n = 0; /* optimal size for array part */ + for (i = 0, twotoi = 1; twotoi/2 < *narray; i++, twotoi *= 2) { + if (nums[i] > 0) { + a += nums[i]; + if (a > twotoi/2) { /* more than half elements present? */ + n = twotoi; /* optimal size (till now) */ + na = a; /* all elements smaller than n will go to array part */ + } + } + if (a == *narray) break; /* all elements already counted */ + } + *narray = n; + lua_assert(*narray/2 <= na && na <= *narray); + return na; +} + + +static int countint (const TValue *key, int *nums) { + int k = arrayindex(key); + if (0 < k && k <= MAXASIZE) { /* is `key' an appropriate array index? */ + nums[ceillog2(k)]++; /* count as such */ + return 1; + } + else + return 0; +} + + +static int numusearray (const Table *t, int *nums) { + int lg; + int ttlg; /* 2^lg */ + int ause = 0; /* summation of `nums' */ + int i = 1; /* count to traverse all array keys */ + for (lg=0, ttlg=1; lg<=MAXBITS; lg++, ttlg*=2) { /* for each slice */ + int lc = 0; /* counter */ + int lim = ttlg; + if (lim > t->sizearray) { + lim = t->sizearray; /* adjust upper limit */ + if (i > lim) + break; /* no more elements to count */ + } + /* count elements in range (2^(lg-1), 2^lg] */ + for (; i <= lim; i++) { + if (!ttisnil(&t->array[i-1])) + lc++; + } + nums[lg] += lc; + ause += lc; + } + return ause; +} + + +static int numusehash (const Table *t, int *nums, int *pnasize) { + int totaluse = 0; /* total number of elements */ + int ause = 0; /* summation of `nums' */ + int i = sizenode(t); + while (i--) { + Node *n = &t->node[i]; + if (!ttisnil(gval(n))) { + ause += countint(key2tval(n), nums); + totaluse++; + } + } + *pnasize += ause; + return totaluse; +} + + +static void setarrayvector (lua_State *L, Table *t, int size) { + int i; + luaM_reallocvector(L, t->array, t->sizearray, size, TValue); + for (i=t->sizearray; iarray[i]); + t->sizearray = size; +} + + +static void setnodevector (lua_State *L, Table *t, int size) { + int lsize; + if (size == 0) { /* no elements to hash part? */ + t->node = cast(Node *, dummynode); /* use common `dummynode' */ + lsize = 0; + } + else { + int i; + lsize = ceillog2(size); + if (lsize > MAXBITS) + luaG_runerror(L, "table overflow"); + size = twoto(lsize); + t->node = luaM_newvector(L, size, Node); + for (i=0; ilsizenode = cast_byte(lsize); + t->lastfree = gnode(t, size); /* all positions are free */ +} + + +static void resize (lua_State *L, Table *t, int nasize, int nhsize) { + int i; + int oldasize = t->sizearray; + int oldhsize = t->lsizenode; + Node *nold = t->node; /* save old hash ... */ + if (nasize > oldasize) /* array part must grow? */ + setarrayvector(L, t, nasize); + /* create new hash part with appropriate size */ + setnodevector(L, t, nhsize); + if (nasize < oldasize) { /* array part must shrink? */ + t->sizearray = nasize; + /* re-insert elements from vanishing slice */ + for (i=nasize; iarray[i])) + setobjt2t(L, luaH_setnum(L, t, i+1), &t->array[i]); + } + /* shrink array */ + luaM_reallocvector(L, t->array, oldasize, nasize, TValue); + } + /* re-insert elements from hash part */ + for (i = twoto(oldhsize) - 1; i >= 0; i--) { + Node *old = nold+i; + if (!ttisnil(gval(old))) + setobjt2t(L, luaH_set(L, t, key2tval(old)), gval(old)); + } + if (nold != dummynode) + luaM_freearray(L, nold, twoto(oldhsize), Node); /* free old array */ +} + + +void luaH_resizearray (lua_State *L, Table *t, int nasize) { + int nsize = (t->node == dummynode) ? 0 : sizenode(t); + resize(L, t, nasize, nsize); +} + + +static void rehash (lua_State *L, Table *t, const TValue *ek) { + int nasize, na; + int nums[MAXBITS+1]; /* nums[i] = number of keys between 2^(i-1) and 2^i */ + int i; + int totaluse; + for (i=0; i<=MAXBITS; i++) nums[i] = 0; /* reset counts */ + nasize = numusearray(t, nums); /* count keys in array part */ + totaluse = nasize; /* all those keys are integer keys */ + totaluse += numusehash(t, nums, &nasize); /* count keys in hash part */ + /* count extra key */ + nasize += countint(ek, nums); + totaluse++; + /* compute new size for array part */ + na = computesizes(nums, &nasize); + /* resize the table to new computed sizes */ + resize(L, t, nasize, totaluse - na); +} + + + +/* +** }============================================================= +*/ + + +Table *luaH_new (lua_State *L, int narray, int nhash) { + Table *t = luaM_new(L, Table); + luaC_link(L, obj2gco(t), LUA_TTABLE); + t->metatable = NULL; + t->flags = cast_byte(~0); + /* temporary values (kept only if some malloc fails) */ + t->array = NULL; + t->sizearray = 0; + t->lsizenode = 0; + t->node = cast(Node *, dummynode); + setarrayvector(L, t, narray); + setnodevector(L, t, nhash); + return t; +} + + +void luaH_free (lua_State *L, Table *t) { + if (t->node != dummynode) + luaM_freearray(L, t->node, sizenode(t), Node); + luaM_freearray(L, t->array, t->sizearray, TValue); + luaM_free(L, t); +} + + +static Node *getfreepos (Table *t) { + while (t->lastfree-- > t->node) { + if (ttisnil(gkey(t->lastfree))) + return t->lastfree; + } + return NULL; /* could not find a free place */ +} + + + +/* +** inserts a new key into a hash table; first, check whether key's main +** position is free. If not, check whether colliding node is in its main +** position or not: if it is not, move colliding node to an empty place and +** put new key in its main position; otherwise (colliding node is in its main +** position), new key goes to an empty position. +*/ +static TValue *newkey (lua_State *L, Table *t, const TValue *key) { + Node *mp = mainposition(t, key); + if (!ttisnil(gval(mp)) || mp == dummynode) { + Node *othern; + Node *n = getfreepos(t); /* get a free place */ + if (n == NULL) { /* cannot find a free place? */ + rehash(L, t, key); /* grow table */ + return luaH_set(L, t, key); /* re-insert key into grown table */ + } + lua_assert(n != dummynode); + othern = mainposition(t, key2tval(mp)); + if (othern != mp) { /* is colliding node out of its main position? */ + /* yes; move colliding node into free position */ + while (gnext(othern) != mp) othern = gnext(othern); /* find previous */ + gnext(othern) = n; /* redo the chain with `n' in place of `mp' */ + *n = *mp; /* copy colliding node into free pos. (mp->next also goes) */ + gnext(mp) = NULL; /* now `mp' is free */ + setnilvalue(gval(mp)); + } + else { /* colliding node is in its own main position */ + /* new node will go into free position */ + gnext(n) = gnext(mp); /* chain new position */ + gnext(mp) = n; + mp = n; + } + } + gkey(mp)->value = key->value; gkey(mp)->tt = key->tt; + luaC_barriert(L, t, key); + lua_assert(ttisnil(gval(mp))); + return gval(mp); +} + + +/* +** search function for integers +*/ +const TValue *luaH_getnum (Table *t, int key) { + /* (1 <= key && key <= t->sizearray) */ + if (cast(unsigned int, key-1) < cast(unsigned int, t->sizearray)) + return &t->array[key-1]; + else { + lua_Number nk = cast_num(key); + Node *n = hashnum(t, nk); + do { /* check whether `key' is somewhere in the chain */ + if (ttisnumber(gkey(n)) && luai_numeq(nvalue(gkey(n)), nk)) + return gval(n); /* that's it */ + else n = gnext(n); + } while (n); + return luaO_nilobject; + } +} + + +/* +** search function for strings +*/ +const TValue *luaH_getstr (Table *t, TString *key) { + Node *n = hashstr(t, key); + do { /* check whether `key' is somewhere in the chain */ + if (ttisstring(gkey(n)) && rawtsvalue(gkey(n)) == key) + return gval(n); /* that's it */ + else n = gnext(n); + } while (n); + return luaO_nilobject; +} + + +/* +** main search function +*/ +const TValue *luaH_get (Table *t, const TValue *key) { + switch (ttype(key)) { + case LUA_TNIL: return luaO_nilobject; + case LUA_TSTRING: return luaH_getstr(t, rawtsvalue(key)); + case LUA_TNUMBER: { + int k; + lua_Number n = nvalue(key); + lua_number2int(k, n); + if (luai_numeq(cast_num(k), nvalue(key))) /* index is int? */ + return luaH_getnum(t, k); /* use specialized version */ + /* else go through */ + } + default: { + Node *n = mainposition(t, key); + do { /* check whether `key' is somewhere in the chain */ + if (luaO_rawequalObj(key2tval(n), key)) + return gval(n); /* that's it */ + else n = gnext(n); + } while (n); + return luaO_nilobject; + } + } +} + + +TValue *luaH_set (lua_State *L, Table *t, const TValue *key) { + const TValue *p = luaH_get(t, key); + t->flags = 0; + if (p != luaO_nilobject) + return cast(TValue *, p); + else { + if (ttisnil(key)) luaG_runerror(L, "table index is nil"); + else if (ttisnumber(key) && luai_numisnan(nvalue(key))) + luaG_runerror(L, "table index is NaN"); + return newkey(L, t, key); + } +} + + +TValue *luaH_setnum (lua_State *L, Table *t, int key) { + const TValue *p = luaH_getnum(t, key); + if (p != luaO_nilobject) + return cast(TValue *, p); + else { + TValue k; + setnvalue(&k, cast_num(key)); + return newkey(L, t, &k); + } +} + + +TValue *luaH_setstr (lua_State *L, Table *t, TString *key) { + const TValue *p = luaH_getstr(t, key); + if (p != luaO_nilobject) + return cast(TValue *, p); + else { + TValue k; + setsvalue(L, &k, key); + return newkey(L, t, &k); + } +} + + +static int unbound_search (Table *t, unsigned int j) { + unsigned int i = j; /* i is zero or a present index */ + j++; + /* find `i' and `j' such that i is present and j is not */ + while (!ttisnil(luaH_getnum(t, j))) { + i = j; + j *= 2; + if (j > cast(unsigned int, MAX_INT)) { /* overflow? */ + /* table was built with bad purposes: resort to linear search */ + i = 1; + while (!ttisnil(luaH_getnum(t, i))) i++; + return i - 1; + } + } + /* now do a binary search between them */ + while (j - i > 1) { + unsigned int m = (i+j)/2; + if (ttisnil(luaH_getnum(t, m))) j = m; + else i = m; + } + return i; +} + + +/* +** Try to find a boundary in table `t'. A `boundary' is an integer index +** such that t[i] is non-nil and t[i+1] is nil (and 0 if t[1] is nil). +*/ +int luaH_getn (Table *t) { + unsigned int j = t->sizearray; + if (j > 0 && ttisnil(&t->array[j - 1])) { + /* there is a boundary in the array part: (binary) search for it */ + unsigned int i = 0; + while (j - i > 1) { + unsigned int m = (i+j)/2; + if (ttisnil(&t->array[m - 1])) j = m; + else i = m; + } + return i; + } + /* else must find a boundary in hash part */ + else if (t->node == dummynode) /* hash part is empty? */ + return j; /* that is easy... */ + else return unbound_search(t, j); +} + + + +#if defined(LUA_DEBUG) + +Node *luaH_mainposition (const Table *t, const TValue *key) { + return mainposition(t, key); +} + +int luaH_isdummy (Node *n) { return n == dummynode; } + +#endif diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/ltable.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/ltable.h new file mode 100644 index 00000000..f5b9d5ea --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/ltable.h @@ -0,0 +1,40 @@ +/* +** $Id: ltable.h,v 2.10.1.1 2007/12/27 13:02:25 roberto Exp $ +** Lua tables (hash) +** See Copyright Notice in lua.h +*/ + +#ifndef ltable_h +#define ltable_h + +#include "lobject.h" + + +#define gnode(t,i) (&(t)->node[i]) +#define gkey(n) (&(n)->i_key.nk) +#define gval(n) (&(n)->i_val) +#define gnext(n) ((n)->i_key.nk.next) + +#define key2tval(n) (&(n)->i_key.tvk) + + +LUAI_FUNC const TValue *luaH_getnum (Table *t, int key); +LUAI_FUNC TValue *luaH_setnum (lua_State *L, Table *t, int key); +LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key); +LUAI_FUNC TValue *luaH_setstr (lua_State *L, Table *t, TString *key); +LUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key); +LUAI_FUNC TValue *luaH_set (lua_State *L, Table *t, const TValue *key); +LUAI_FUNC Table *luaH_new (lua_State *L, int narray, int lnhash); +LUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, int nasize); +LUAI_FUNC void luaH_free (lua_State *L, Table *t); +LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key); +LUAI_FUNC int luaH_getn (Table *t); + + +#if defined(LUA_DEBUG) +LUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key); +LUAI_FUNC int luaH_isdummy (Node *n); +#endif + + +#endif diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/ltablib.c b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/ltablib.c new file mode 100644 index 00000000..b6d9cb4a --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/ltablib.c @@ -0,0 +1,287 @@ +/* +** $Id: ltablib.c,v 1.38.1.3 2008/02/14 16:46:58 roberto Exp $ +** Library for Table Manipulation +** See Copyright Notice in lua.h +*/ + + +#include + +#define ltablib_c +#define LUA_LIB + +#include "lua.h" + +#include "lauxlib.h" +#include "lualib.h" + + +#define aux_getn(L,n) (luaL_checktype(L, n, LUA_TTABLE), luaL_getn(L, n)) + + +static int foreachi (lua_State *L) { + int i; + int n = aux_getn(L, 1); + luaL_checktype(L, 2, LUA_TFUNCTION); + for (i=1; i <= n; i++) { + lua_pushvalue(L, 2); /* function */ + lua_pushinteger(L, i); /* 1st argument */ + lua_rawgeti(L, 1, i); /* 2nd argument */ + lua_call(L, 2, 1); + if (!lua_isnil(L, -1)) + return 1; + lua_pop(L, 1); /* remove nil result */ + } + return 0; +} + + +static int foreach (lua_State *L) { + luaL_checktype(L, 1, LUA_TTABLE); + luaL_checktype(L, 2, LUA_TFUNCTION); + lua_pushnil(L); /* first key */ + while (lua_next(L, 1)) { + lua_pushvalue(L, 2); /* function */ + lua_pushvalue(L, -3); /* key */ + lua_pushvalue(L, -3); /* value */ + lua_call(L, 2, 1); + if (!lua_isnil(L, -1)) + return 1; + lua_pop(L, 2); /* remove value and result */ + } + return 0; +} + + +static int maxn (lua_State *L) { + lua_Number max = 0; + luaL_checktype(L, 1, LUA_TTABLE); + lua_pushnil(L); /* first key */ + while (lua_next(L, 1)) { + lua_pop(L, 1); /* remove value */ + if (lua_type(L, -1) == LUA_TNUMBER) { + lua_Number v = lua_tonumber(L, -1); + if (v > max) max = v; + } + } + lua_pushnumber(L, max); + return 1; +} + + +static int getn (lua_State *L) { + lua_pushinteger(L, aux_getn(L, 1)); + return 1; +} + + +static int setn (lua_State *L) { + luaL_checktype(L, 1, LUA_TTABLE); +#ifndef luaL_setn + luaL_setn(L, 1, luaL_checkint(L, 2)); +#else + luaL_error(L, LUA_QL("setn") " is obsolete"); +#endif + lua_pushvalue(L, 1); + return 1; +} + + +static int tinsert (lua_State *L) { + int e = aux_getn(L, 1) + 1; /* first empty element */ + int pos; /* where to insert new element */ + switch (lua_gettop(L)) { + case 2: { /* called with only 2 arguments */ + pos = e; /* insert new element at the end */ + break; + } + case 3: { + int i; + pos = luaL_checkint(L, 2); /* 2nd argument is the position */ + if (pos > e) e = pos; /* `grow' array if necessary */ + for (i = e; i > pos; i--) { /* move up elements */ + lua_rawgeti(L, 1, i-1); + lua_rawseti(L, 1, i); /* t[i] = t[i-1] */ + } + break; + } + default: { + return luaL_error(L, "wrong number of arguments to " LUA_QL("insert")); + } + } + luaL_setn(L, 1, e); /* new size */ + lua_rawseti(L, 1, pos); /* t[pos] = v */ + return 0; +} + + +static int tremove (lua_State *L) { + int e = aux_getn(L, 1); + int pos = luaL_optint(L, 2, e); + if (!(1 <= pos && pos <= e)) /* position is outside bounds? */ + return 0; /* nothing to remove */ + luaL_setn(L, 1, e - 1); /* t.n = n-1 */ + lua_rawgeti(L, 1, pos); /* result = t[pos] */ + for ( ;pos= P */ + while (lua_rawgeti(L, 1, ++i), sort_comp(L, -1, -2)) { + if (i>u) luaL_error(L, "invalid order function for sorting"); + lua_pop(L, 1); /* remove a[i] */ + } + /* repeat --j until a[j] <= P */ + while (lua_rawgeti(L, 1, --j), sort_comp(L, -3, -1)) { + if (j + +#define ltm_c +#define LUA_CORE + +#include "lua.h" + +#include "lobject.h" +#include "lstate.h" +#include "lstring.h" +#include "ltable.h" +#include "ltm.h" + + + +const char *const luaT_typenames[] = { + "nil", "boolean", "userdata", "number", + "string", "table", "function", "userdata", "thread", + "proto", "upval" +}; + + +void luaT_init (lua_State *L) { + static const char *const luaT_eventname[] = { /* ORDER TM */ + "__index", "__newindex", + "__gc", "__mode", "__eq", + "__add", "__sub", "__mul", "__div", "__mod", + "__pow", "__unm", "__len", "__lt", "__le", + "__concat", "__call" + }; + int i; + for (i=0; itmname[i] = luaS_new(L, luaT_eventname[i]); + luaS_fix(G(L)->tmname[i]); /* never collect these names */ + } +} + + +/* +** function to be used with macro "fasttm": optimized for absence of +** tag methods +*/ +const TValue *luaT_gettm (Table *events, TMS event, TString *ename) { + const TValue *tm = luaH_getstr(events, ename); + lua_assert(event <= TM_EQ); + if (ttisnil(tm)) { /* no tag method? */ + events->flags |= cast_byte(1u<metatable; + break; + case LUA_TUSERDATA: + mt = uvalue(o)->metatable; + break; + default: + mt = G(L)->mt[ttype(o)]; + } + return (mt ? luaH_getstr(mt, G(L)->tmname[event]) : luaO_nilobject); +} + diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/ltm.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/ltm.h new file mode 100644 index 00000000..64343b78 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/ltm.h @@ -0,0 +1,54 @@ +/* +** $Id: ltm.h,v 2.6.1.1 2007/12/27 13:02:25 roberto Exp $ +** Tag methods +** See Copyright Notice in lua.h +*/ + +#ifndef ltm_h +#define ltm_h + + +#include "lobject.h" + + +/* +* WARNING: if you change the order of this enumeration, +* grep "ORDER TM" +*/ +typedef enum { + TM_INDEX, + TM_NEWINDEX, + TM_GC, + TM_MODE, + TM_EQ, /* last tag method with `fast' access */ + TM_ADD, + TM_SUB, + TM_MUL, + TM_DIV, + TM_MOD, + TM_POW, + TM_UNM, + TM_LEN, + TM_LT, + TM_LE, + TM_CONCAT, + TM_CALL, + TM_N /* number of elements in the enum */ +} TMS; + + + +#define gfasttm(g,et,e) ((et) == NULL ? NULL : \ + ((et)->flags & (1u<<(e))) ? NULL : luaT_gettm(et, e, (g)->tmname[e])) + +#define fasttm(l,et,e) gfasttm(G(l), et, e) + +LUAI_DATA const char *const luaT_typenames[]; + + +LUAI_FUNC const TValue *luaT_gettm (Table *events, TMS event, TString *ename); +LUAI_FUNC const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, + TMS event); +LUAI_FUNC void luaT_init (lua_State *L); + +#endif diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lua.c b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lua.c new file mode 100644 index 00000000..3a466093 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lua.c @@ -0,0 +1,392 @@ +/* +** $Id: lua.c,v 1.160.1.2 2007/12/28 15:32:23 roberto Exp $ +** Lua stand-alone interpreter +** See Copyright Notice in lua.h +*/ + + +#include +#include +#include +#include + +#define lua_c + +#include "lua.h" + +#include "lauxlib.h" +#include "lualib.h" + + + +static lua_State *globalL = NULL; + +static const char *progname = LUA_PROGNAME; + + + +static void lstop (lua_State *L, lua_Debug *ar) { + (void)ar; /* unused arg. */ + lua_sethook(L, NULL, 0, 0); + luaL_error(L, "interrupted!"); +} + + +static void laction (int i) { + signal(i, SIG_DFL); /* if another SIGINT happens before lstop, + terminate process (default action) */ + lua_sethook(globalL, lstop, LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 1); +} + + +static void print_usage (void) { + fprintf(stderr, + "usage: %s [options] [script [args]].\n" + "Available options are:\n" + " -e stat execute string " LUA_QL("stat") "\n" + " -l name require library " LUA_QL("name") "\n" + " -i enter interactive mode after executing " LUA_QL("script") "\n" + " -v show version information\n" + " -- stop handling options\n" + " - execute stdin and stop handling options\n" + , + progname); + fflush(stderr); +} + + +static void l_message (const char *pname, const char *msg) { + if (pname) fprintf(stderr, "%s: ", pname); + fprintf(stderr, "%s\n", msg); + fflush(stderr); +} + + +static int report (lua_State *L, int status) { + if (status && !lua_isnil(L, -1)) { + const char *msg = lua_tostring(L, -1); + if (msg == NULL) msg = "(error object is not a string)"; + l_message(progname, msg); + lua_pop(L, 1); + } + return status; +} + + +static int traceback (lua_State *L) { + if (!lua_isstring(L, 1)) /* 'message' not a string? */ + return 1; /* keep it intact */ + lua_getfield(L, LUA_GLOBALSINDEX, "debug"); + if (!lua_istable(L, -1)) { + lua_pop(L, 1); + return 1; + } + lua_getfield(L, -1, "traceback"); + if (!lua_isfunction(L, -1)) { + lua_pop(L, 2); + return 1; + } + lua_pushvalue(L, 1); /* pass error message */ + lua_pushinteger(L, 2); /* skip this function and traceback */ + lua_call(L, 2, 1); /* call debug.traceback */ + return 1; +} + + +static int docall (lua_State *L, int narg, int clear) { + int status; + int base = lua_gettop(L) - narg; /* function index */ + lua_pushcfunction(L, traceback); /* push traceback function */ + lua_insert(L, base); /* put it under chunk and args */ + signal(SIGINT, laction); + status = lua_pcall(L, narg, (clear ? 0 : LUA_MULTRET), base); + signal(SIGINT, SIG_DFL); + lua_remove(L, base); /* remove traceback function */ + /* force a complete garbage collection in case of errors */ + if (status != 0) lua_gc(L, LUA_GCCOLLECT, 0); + return status; +} + + +static void print_version (void) { + l_message(NULL, LUA_RELEASE " " LUA_COPYRIGHT); +} + + +static int getargs (lua_State *L, char **argv, int n) { + int narg; + int i; + int argc = 0; + while (argv[argc]) argc++; /* count total number of arguments */ + narg = argc - (n + 1); /* number of arguments to the script */ + luaL_checkstack(L, narg + 3, "too many arguments to script"); + for (i=n+1; i < argc; i++) + lua_pushstring(L, argv[i]); + lua_createtable(L, narg, n + 1); + for (i=0; i < argc; i++) { + lua_pushstring(L, argv[i]); + lua_rawseti(L, -2, i - n); + } + return narg; +} + + +static int dofile (lua_State *L, const char *name) { + int status = luaL_loadfile(L, name) || docall(L, 0, 1); + return report(L, status); +} + + +static int dostring (lua_State *L, const char *s, const char *name) { + int status = luaL_loadbuffer(L, s, strlen(s), name) || docall(L, 0, 1); + return report(L, status); +} + + +static int dolibrary (lua_State *L, const char *name) { + lua_getglobal(L, "require"); + lua_pushstring(L, name); + return report(L, docall(L, 1, 1)); +} + + +static const char *get_prompt (lua_State *L, int firstline) { + const char *p; + lua_getfield(L, LUA_GLOBALSINDEX, firstline ? "_PROMPT" : "_PROMPT2"); + p = lua_tostring(L, -1); + if (p == NULL) p = (firstline ? LUA_PROMPT : LUA_PROMPT2); + lua_pop(L, 1); /* remove global */ + return p; +} + + +static int incomplete (lua_State *L, int status) { + if (status == LUA_ERRSYNTAX) { + size_t lmsg; + const char *msg = lua_tolstring(L, -1, &lmsg); + const char *tp = msg + lmsg - (sizeof(LUA_QL("")) - 1); + if (strstr(msg, LUA_QL("")) == tp) { + lua_pop(L, 1); + return 1; + } + } + return 0; /* else... */ +} + + +static int pushline (lua_State *L, int firstline) { + char buffer[LUA_MAXINPUT]; + char *b = buffer; + size_t l; + const char *prmt = get_prompt(L, firstline); + if (lua_readline(L, b, prmt) == 0) + return 0; /* no input */ + l = strlen(b); + if (l > 0 && b[l-1] == '\n') /* line ends with newline? */ + b[l-1] = '\0'; /* remove it */ + if (firstline && b[0] == '=') /* first line starts with `=' ? */ + lua_pushfstring(L, "return %s", b+1); /* change it to `return' */ + else + lua_pushstring(L, b); + lua_freeline(L, b); + return 1; +} + + +static int loadline (lua_State *L) { + int status; + lua_settop(L, 0); + if (!pushline(L, 1)) + return -1; /* no input */ + for (;;) { /* repeat until gets a complete line */ + status = luaL_loadbuffer(L, lua_tostring(L, 1), lua_strlen(L, 1), "=stdin"); + if (!incomplete(L, status)) break; /* cannot try to add lines? */ + if (!pushline(L, 0)) /* no more input? */ + return -1; + lua_pushliteral(L, "\n"); /* add a new line... */ + lua_insert(L, -2); /* ...between the two lines */ + lua_concat(L, 3); /* join them */ + } + lua_saveline(L, 1); + lua_remove(L, 1); /* remove line */ + return status; +} + + +static void dotty (lua_State *L) { + int status; + const char *oldprogname = progname; + progname = NULL; + while ((status = loadline(L)) != -1) { + if (status == 0) status = docall(L, 0, 0); + report(L, status); + if (status == 0 && lua_gettop(L) > 0) { /* any result to print? */ + lua_getglobal(L, "print"); + lua_insert(L, 1); + if (lua_pcall(L, lua_gettop(L)-1, 0, 0) != 0) + l_message(progname, lua_pushfstring(L, + "error calling " LUA_QL("print") " (%s)", + lua_tostring(L, -1))); + } + } + lua_settop(L, 0); /* clear stack */ + fputs("\n", stdout); + fflush(stdout); + progname = oldprogname; +} + + +static int handle_script (lua_State *L, char **argv, int n) { + int status; + const char *fname; + int narg = getargs(L, argv, n); /* collect arguments */ + lua_setglobal(L, "arg"); + fname = argv[n]; + if (strcmp(fname, "-") == 0 && strcmp(argv[n-1], "--") != 0) + fname = NULL; /* stdin */ + status = luaL_loadfile(L, fname); + lua_insert(L, -(narg+1)); + if (status == 0) + status = docall(L, narg, 0); + else + lua_pop(L, narg); + return report(L, status); +} + + +/* check that argument has no extra characters at the end */ +#define notail(x) {if ((x)[2] != '\0') return -1;} + + +static int collectargs (char **argv, int *pi, int *pv, int *pe) { + int i; + for (i = 1; argv[i] != NULL; i++) { + if (argv[i][0] != '-') /* not an option? */ + return i; + switch (argv[i][1]) { /* option */ + case '-': + notail(argv[i]); + return (argv[i+1] != NULL ? i+1 : 0); + case '\0': + return i; + case 'i': + notail(argv[i]); + *pi = 1; /* go through */ + case 'v': + notail(argv[i]); + *pv = 1; + break; + case 'e': + *pe = 1; /* go through */ + case 'l': + if (argv[i][2] == '\0') { + i++; + if (argv[i] == NULL) return -1; + } + break; + default: return -1; /* invalid option */ + } + } + return 0; +} + + +static int runargs (lua_State *L, char **argv, int n) { + int i; + for (i = 1; i < n; i++) { + if (argv[i] == NULL) continue; + lua_assert(argv[i][0] == '-'); + switch (argv[i][1]) { /* option */ + case 'e': { + const char *chunk = argv[i] + 2; + if (*chunk == '\0') chunk = argv[++i]; + lua_assert(chunk != NULL); + if (dostring(L, chunk, "=(command line)") != 0) + return 1; + break; + } + case 'l': { + const char *filename = argv[i] + 2; + if (*filename == '\0') filename = argv[++i]; + lua_assert(filename != NULL); + if (dolibrary(L, filename)) + return 1; /* stop if file fails */ + break; + } + default: break; + } + } + return 0; +} + + +static int handle_luainit (lua_State *L) { + const char *init = getenv(LUA_INIT); + if (init == NULL) return 0; /* status OK */ + else if (init[0] == '@') + return dofile(L, init+1); + else + return dostring(L, init, "=" LUA_INIT); +} + + +struct Smain { + int argc; + char **argv; + int status; +}; + + +static int pmain (lua_State *L) { + struct Smain *s = (struct Smain *)lua_touserdata(L, 1); + char **argv = s->argv; + int script; + int has_i = 0, has_v = 0, has_e = 0; + globalL = L; + if (argv[0] && argv[0][0]) progname = argv[0]; + lua_gc(L, LUA_GCSTOP, 0); /* stop collector during initialization */ + luaL_openlibs(L); /* open libraries */ + lua_gc(L, LUA_GCRESTART, 0); + s->status = handle_luainit(L); + if (s->status != 0) return 0; + script = collectargs(argv, &has_i, &has_v, &has_e); + if (script < 0) { /* invalid args? */ + print_usage(); + s->status = 1; + return 0; + } + if (has_v) print_version(); + s->status = runargs(L, argv, (script > 0) ? script : s->argc); + if (s->status != 0) return 0; + if (script) + s->status = handle_script(L, argv, script); + if (s->status != 0) return 0; + if (has_i) + dotty(L); + else if (script == 0 && !has_e && !has_v) { + if (lua_stdin_is_tty()) { + print_version(); + dotty(L); + } + else dofile(L, NULL); /* executes stdin as a file */ + } + return 0; +} + + +int main (int argc, char **argv) { + int status; + struct Smain s; + lua_State *L = lua_open(); /* create state */ + if (L == NULL) { + l_message(argv[0], "cannot create state: not enough memory"); + return EXIT_FAILURE; + } + s.argc = argc; + s.argv = argv; + status = lua_cpcall(L, &pmain, &s); + report(L, status); + lua_close(L); + return (status || s.status) ? EXIT_FAILURE : EXIT_SUCCESS; +} + diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lua.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lua.h new file mode 100644 index 00000000..e4bdfd3b --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lua.h @@ -0,0 +1,388 @@ +/* +** $Id: lua.h,v 1.218.1.5 2008/08/06 13:30:12 roberto Exp $ +** Lua - An Extensible Extension Language +** Lua.org, PUC-Rio, Brazil (http://www.lua.org) +** See Copyright Notice at the end of this file +*/ + + +#ifndef lua_h +#define lua_h + +#include +#include + + +#include "luaconf.h" + + +#define LUA_VERSION "Lua 5.1" +#define LUA_RELEASE "Lua 5.1.4" +#define LUA_VERSION_NUM 501 +#define LUA_COPYRIGHT "Copyright (C) 1994-2008 Lua.org, PUC-Rio" +#define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo & W. Celes" + + +/* mark for precompiled code (`Lua') */ +#define LUA_SIGNATURE "\033Lua" + +/* option for multiple returns in `lua_pcall' and `lua_call' */ +#define LUA_MULTRET (-1) + + +/* +** pseudo-indices +*/ +#define LUA_REGISTRYINDEX (-10000) +#define LUA_ENVIRONINDEX (-10001) +#define LUA_GLOBALSINDEX (-10002) +#define lua_upvalueindex(i) (LUA_GLOBALSINDEX-(i)) + + +/* thread status; 0 is OK */ +#define LUA_YIELD 1 +#define LUA_ERRRUN 2 +#define LUA_ERRSYNTAX 3 +#define LUA_ERRMEM 4 +#define LUA_ERRERR 5 + + +typedef struct lua_State lua_State; + +typedef int (*lua_CFunction) (lua_State *L); + + +/* +** functions that read/write blocks when loading/dumping Lua chunks +*/ +typedef const char * (*lua_Reader) (lua_State *L, void *ud, size_t *sz); + +typedef int (*lua_Writer) (lua_State *L, const void* p, size_t sz, void* ud); + + +/* +** prototype for memory-allocation functions +*/ +typedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize); + + +/* +** basic types +*/ +#define LUA_TNONE (-1) + +#define LUA_TNIL 0 +#define LUA_TBOOLEAN 1 +#define LUA_TLIGHTUSERDATA 2 +#define LUA_TNUMBER 3 +#define LUA_TSTRING 4 +#define LUA_TTABLE 5 +#define LUA_TFUNCTION 6 +#define LUA_TUSERDATA 7 +#define LUA_TTHREAD 8 + + + +/* minimum Lua stack available to a C function */ +#define LUA_MINSTACK 20 + + +/* +** generic extra include file +*/ +#if defined(LUA_USER_H) +#include LUA_USER_H +#endif + + +/* type of numbers in Lua */ +typedef LUA_NUMBER lua_Number; + + +/* type for integer functions */ +typedef LUA_INTEGER lua_Integer; + + + +/* +** state manipulation +*/ +LUA_API lua_State *(lua_newstate) (lua_Alloc f, void *ud); +LUA_API void (lua_close) (lua_State *L); +LUA_API lua_State *(lua_newthread) (lua_State *L); + +LUA_API lua_CFunction (lua_atpanic) (lua_State *L, lua_CFunction panicf); + + +/* +** basic stack manipulation +*/ +LUA_API int (lua_gettop) (lua_State *L); +LUA_API void (lua_settop) (lua_State *L, int idx); +LUA_API void (lua_pushvalue) (lua_State *L, int idx); +LUA_API void (lua_remove) (lua_State *L, int idx); +LUA_API void (lua_insert) (lua_State *L, int idx); +LUA_API void (lua_replace) (lua_State *L, int idx); +LUA_API int (lua_checkstack) (lua_State *L, int sz); + +LUA_API void (lua_xmove) (lua_State *from, lua_State *to, int n); + + +/* +** access functions (stack -> C) +*/ + +LUA_API int (lua_isnumber) (lua_State *L, int idx); +LUA_API int (lua_isstring) (lua_State *L, int idx); +LUA_API int (lua_iscfunction) (lua_State *L, int idx); +LUA_API int (lua_isuserdata) (lua_State *L, int idx); +LUA_API int (lua_type) (lua_State *L, int idx); +LUA_API const char *(lua_typename) (lua_State *L, int tp); + +LUA_API int (lua_equal) (lua_State *L, int idx1, int idx2); +LUA_API int (lua_rawequal) (lua_State *L, int idx1, int idx2); +LUA_API int (lua_lessthan) (lua_State *L, int idx1, int idx2); + +LUA_API lua_Number (lua_tonumber) (lua_State *L, int idx); +LUA_API lua_Integer (lua_tointeger) (lua_State *L, int idx); +LUA_API int (lua_toboolean) (lua_State *L, int idx); +LUA_API const char *(lua_tolstring) (lua_State *L, int idx, size_t *len); +LUA_API size_t (lua_objlen) (lua_State *L, int idx); +LUA_API lua_CFunction (lua_tocfunction) (lua_State *L, int idx); +LUA_API void *(lua_touserdata) (lua_State *L, int idx); +LUA_API lua_State *(lua_tothread) (lua_State *L, int idx); +LUA_API const void *(lua_topointer) (lua_State *L, int idx); + + +/* +** push functions (C -> stack) +*/ +LUA_API void (lua_pushnil) (lua_State *L); +LUA_API void (lua_pushnumber) (lua_State *L, lua_Number n); +LUA_API void (lua_pushinteger) (lua_State *L, lua_Integer n); +LUA_API void (lua_pushlstring) (lua_State *L, const char *s, size_t l); +LUA_API void (lua_pushstring) (lua_State *L, const char *s); +LUA_API const char *(lua_pushvfstring) (lua_State *L, const char *fmt, + va_list argp); +LUA_API const char *(lua_pushfstring) (lua_State *L, const char *fmt, ...); +LUA_API void (lua_pushcclosure) (lua_State *L, lua_CFunction fn, int n); +LUA_API void (lua_pushboolean) (lua_State *L, int b); +LUA_API void (lua_pushlightuserdata) (lua_State *L, void *p); +LUA_API int (lua_pushthread) (lua_State *L); + + +/* +** get functions (Lua -> stack) +*/ +LUA_API void (lua_gettable) (lua_State *L, int idx); +LUA_API void (lua_getfield) (lua_State *L, int idx, const char *k); +LUA_API void (lua_rawget) (lua_State *L, int idx); +LUA_API void (lua_rawgeti) (lua_State *L, int idx, int n); +LUA_API void (lua_createtable) (lua_State *L, int narr, int nrec); +LUA_API void *(lua_newuserdata) (lua_State *L, size_t sz); +LUA_API int (lua_getmetatable) (lua_State *L, int objindex); +LUA_API void (lua_getfenv) (lua_State *L, int idx); + + +/* +** set functions (stack -> Lua) +*/ +LUA_API void (lua_settable) (lua_State *L, int idx); +LUA_API void (lua_setfield) (lua_State *L, int idx, const char *k); +LUA_API void (lua_rawset) (lua_State *L, int idx); +LUA_API void (lua_rawseti) (lua_State *L, int idx, int n); +LUA_API int (lua_setmetatable) (lua_State *L, int objindex); +LUA_API int (lua_setfenv) (lua_State *L, int idx); + + +/* +** `load' and `call' functions (load and run Lua code) +*/ +LUA_API void (lua_call) (lua_State *L, int nargs, int nresults); +LUA_API int (lua_pcall) (lua_State *L, int nargs, int nresults, int errfunc); +LUA_API int (lua_cpcall) (lua_State *L, lua_CFunction func, void *ud); +LUA_API int (lua_load) (lua_State *L, lua_Reader reader, void *dt, + const char *chunkname); + +LUA_API int (lua_dump) (lua_State *L, lua_Writer writer, void *data); + + +/* +** coroutine functions +*/ +LUA_API int (lua_yield) (lua_State *L, int nresults); +LUA_API int (lua_resume) (lua_State *L, int narg); +LUA_API int (lua_status) (lua_State *L); + +/* +** garbage-collection function and options +*/ + +#define LUA_GCSTOP 0 +#define LUA_GCRESTART 1 +#define LUA_GCCOLLECT 2 +#define LUA_GCCOUNT 3 +#define LUA_GCCOUNTB 4 +#define LUA_GCSTEP 5 +#define LUA_GCSETPAUSE 6 +#define LUA_GCSETSTEPMUL 7 + +LUA_API int (lua_gc) (lua_State *L, int what, int data); + + +/* +** miscellaneous functions +*/ + +LUA_API int (lua_error) (lua_State *L); + +LUA_API int (lua_next) (lua_State *L, int idx); + +LUA_API void (lua_concat) (lua_State *L, int n); + +LUA_API lua_Alloc (lua_getallocf) (lua_State *L, void **ud); +LUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud); + + + +/* +** =============================================================== +** some useful macros +** =============================================================== +*/ + +#define lua_pop(L,n) lua_settop(L, -(n)-1) + +#define lua_newtable(L) lua_createtable(L, 0, 0) + +#define lua_register(L,n,f) (lua_pushcfunction(L, (f)), lua_setglobal(L, (n))) + +#define lua_pushcfunction(L,f) lua_pushcclosure(L, (f), 0) + +#define lua_strlen(L,i) lua_objlen(L, (i)) + +#define lua_isfunction(L,n) (lua_type(L, (n)) == LUA_TFUNCTION) +#define lua_istable(L,n) (lua_type(L, (n)) == LUA_TTABLE) +#define lua_islightuserdata(L,n) (lua_type(L, (n)) == LUA_TLIGHTUSERDATA) +#define lua_isnil(L,n) (lua_type(L, (n)) == LUA_TNIL) +#define lua_isboolean(L,n) (lua_type(L, (n)) == LUA_TBOOLEAN) +#define lua_isthread(L,n) (lua_type(L, (n)) == LUA_TTHREAD) +#define lua_isnone(L,n) (lua_type(L, (n)) == LUA_TNONE) +#define lua_isnoneornil(L, n) (lua_type(L, (n)) <= 0) + +#define lua_pushliteral(L, s) \ + lua_pushlstring(L, "" s, (sizeof(s)/sizeof(char))-1) + +#define lua_setglobal(L,s) lua_setfield(L, LUA_GLOBALSINDEX, (s)) +#define lua_getglobal(L,s) lua_getfield(L, LUA_GLOBALSINDEX, (s)) + +#define lua_tostring(L,i) lua_tolstring(L, (i), NULL) + + + +/* +** compatibility macros and functions +*/ + +#define lua_open() luaL_newstate() + +#define lua_getregistry(L) lua_pushvalue(L, LUA_REGISTRYINDEX) + +#define lua_getgccount(L) lua_gc(L, LUA_GCCOUNT, 0) + +#define lua_Chunkreader lua_Reader +#define lua_Chunkwriter lua_Writer + + +/* hack */ +LUA_API void lua_setlevel (lua_State *from, lua_State *to); + + +/* +** {====================================================================== +** Debug API +** ======================================================================= +*/ + + +/* +** Event codes +*/ +#define LUA_HOOKCALL 0 +#define LUA_HOOKRET 1 +#define LUA_HOOKLINE 2 +#define LUA_HOOKCOUNT 3 +#define LUA_HOOKTAILRET 4 + + +/* +** Event masks +*/ +#define LUA_MASKCALL (1 << LUA_HOOKCALL) +#define LUA_MASKRET (1 << LUA_HOOKRET) +#define LUA_MASKLINE (1 << LUA_HOOKLINE) +#define LUA_MASKCOUNT (1 << LUA_HOOKCOUNT) + +typedef struct lua_Debug lua_Debug; /* activation record */ + + +/* Functions to be called by the debuger in specific events */ +typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar); + + +LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar); +LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar); +LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n); +LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n); +LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n); +LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n); + +LUA_API int lua_sethook (lua_State *L, lua_Hook func, int mask, int count); +LUA_API lua_Hook lua_gethook (lua_State *L); +LUA_API int lua_gethookmask (lua_State *L); +LUA_API int lua_gethookcount (lua_State *L); + + +struct lua_Debug { + int event; + const char *name; /* (n) */ + const char *namewhat; /* (n) `global', `local', `field', `method' */ + const char *what; /* (S) `Lua', `C', `main', `tail' */ + const char *source; /* (S) */ + int currentline; /* (l) */ + int nups; /* (u) number of upvalues */ + int linedefined; /* (S) */ + int lastlinedefined; /* (S) */ + char short_src[LUA_IDSIZE]; /* (S) */ + /* private part */ + int i_ci; /* active function */ +}; + +/* }====================================================================== */ + + +/****************************************************************************** +* Copyright (C) 1994-2008 Lua.org, PUC-Rio. All rights reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining +* a copy of this software and associated documentation files (the +* "Software"), to deal in the Software without restriction, including +* without limitation the rights to use, copy, modify, merge, publish, +* distribute, sublicense, and/or sell copies of the Software, and to +* permit persons to whom the Software is furnished to do so, subject to +* the following conditions: +* +* The above copyright notice and this permission notice shall be +* included in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +******************************************************************************/ + + +#endif diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/luac.c b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/luac.c new file mode 100644 index 00000000..d0701739 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/luac.c @@ -0,0 +1,200 @@ +/* +** $Id: luac.c,v 1.54 2006/06/02 17:37:11 lhf Exp $ +** Lua compiler (saves bytecodes to files; also list bytecodes) +** See Copyright Notice in lua.h +*/ + +#include +#include +#include +#include + +#define luac_c +#define LUA_CORE + +#include "lua.h" +#include "lauxlib.h" + +#include "ldo.h" +#include "lfunc.h" +#include "lmem.h" +#include "lobject.h" +#include "lopcodes.h" +#include "lstring.h" +#include "lundump.h" + +#define PROGNAME "luac" /* default program name */ +#define OUTPUT PROGNAME ".out" /* default output file */ + +static int listing=0; /* list bytecodes? */ +static int dumping=1; /* dump bytecodes? */ +static int stripping=0; /* strip debug information? */ +static char Output[]={ OUTPUT }; /* default output file name */ +static const char* output=Output; /* actual output file name */ +static const char* progname=PROGNAME; /* actual program name */ + +static void fatal(const char* message) +{ + fprintf(stderr,"%s: %s\n",progname,message); + exit(EXIT_FAILURE); +} + +static void cannot(const char* what) +{ + fprintf(stderr,"%s: cannot %s %s: %s\n",progname,what,output,strerror(errno)); + exit(EXIT_FAILURE); +} + +static void usage(const char* message) +{ + if (*message=='-') + fprintf(stderr,"%s: unrecognized option " LUA_QS "\n",progname,message); + else + fprintf(stderr,"%s: %s\n",progname,message); + fprintf(stderr, + "usage: %s [options] [filenames].\n" + "Available options are:\n" + " - process stdin\n" + " -l list\n" + " -o name output to file " LUA_QL("name") " (default is \"%s\")\n" + " -p parse only\n" + " -s strip debug information\n" + " -v show version information\n" + " -- stop handling options\n", + progname,Output); + exit(EXIT_FAILURE); +} + +#define IS(s) (strcmp(argv[i],s)==0) + +static int doargs(int argc, char* argv[]) +{ + int i; + int version=0; + if (argv[0]!=NULL && *argv[0]!=0) progname=argv[0]; + for (i=1; itop+(i))->l.p) + +static const Proto* combine(lua_State* L, int n) +{ + if (n==1) + return toproto(L,-1); + else + { + int i,pc; + Proto* f=luaF_newproto(L); + setptvalue2s(L,L->top,f); incr_top(L); + f->source=luaS_newliteral(L,"=(" PROGNAME ")"); + f->maxstacksize=1; + pc=2*n+1; + f->code=luaM_newvector(L,pc,Instruction); + f->sizecode=pc; + f->p=luaM_newvector(L,n,Proto*); + f->sizep=n; + pc=0; + for (i=0; ip[i]=toproto(L,i-n-1); + f->code[pc++]=CREATE_ABx(OP_CLOSURE,0,i); + f->code[pc++]=CREATE_ABC(OP_CALL,0,1,1); + } + f->code[pc++]=CREATE_ABC(OP_RETURN,0,1,0); + return f; + } +} + +static int writer(lua_State* L, const void* p, size_t size, void* u) +{ + UNUSED(L); + return (fwrite(p,size,1,(FILE*)u)!=1) && (size!=0); +} + +struct Smain { + int argc; + char** argv; +}; + +static int pmain(lua_State* L) +{ + struct Smain* s = (struct Smain*)lua_touserdata(L, 1); + int argc=s->argc; + char** argv=s->argv; + const Proto* f; + int i; + if (!lua_checkstack(L,argc)) fatal("too many input files"); + for (i=0; i1); + if (dumping) + { + FILE* D= (output==NULL) ? stdout : fopen(output,"wb"); + if (D==NULL) cannot("open"); + lua_lock(L); + luaU_dump(L,f,writer,D,stripping); + lua_unlock(L); + if (ferror(D)) cannot("write"); + if (fclose(D)) cannot("close"); + } + return 0; +} + +int main(int argc, char* argv[]) +{ + lua_State* L; + struct Smain s; + int i=doargs(argc,argv); + argc-=i; argv+=i; + if (argc<=0) usage("no input files given"); + L=lua_open(); + if (L==NULL) fatal("not enough memory for state"); + s.argc=argc; + s.argv=argv; + if (lua_cpcall(L,pmain,&s)!=0) fatal(lua_tostring(L,-1)); + lua_close(L); + return EXIT_SUCCESS; +} diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/luaconf.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/luaconf.h new file mode 100644 index 00000000..bec30482 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/luaconf.h @@ -0,0 +1,763 @@ +/* +** $Id: luaconf.h,v 1.82.1.7 2008/02/11 16:25:08 roberto Exp $ +** Configuration file for Lua +** See Copyright Notice in lua.h +*/ + + +#ifndef lconfig_h +#define lconfig_h + +#include +#include + + +/* +** ================================================================== +** Search for "@@" to find all configurable definitions. +** =================================================================== +*/ + + +/* +@@ LUA_ANSI controls the use of non-ansi features. +** CHANGE it (define it) if you want Lua to avoid the use of any +** non-ansi feature or library. +*/ +#if defined(__STRICT_ANSI__) +#define LUA_ANSI +#endif + + +#if !defined(LUA_ANSI) && defined(_WIN32) +#define LUA_WIN +#endif + +#if defined(LUA_USE_LINUX) +#define LUA_USE_POSIX +#define LUA_USE_DLOPEN /* needs an extra library: -ldl */ +#define LUA_USE_READLINE /* needs some extra libraries */ +#endif + +#if defined(LUA_USE_MACOSX) +#define LUA_USE_POSIX +#define LUA_DL_DYLD /* does not need extra library */ +#endif + + + +/* +@@ LUA_USE_POSIX includes all functionallity listed as X/Open System +@* Interfaces Extension (XSI). +** CHANGE it (define it) if your system is XSI compatible. +*/ +#if defined(LUA_USE_POSIX) +#define LUA_USE_MKSTEMP +#define LUA_USE_ISATTY +#define LUA_USE_POPEN +#define LUA_USE_ULONGJMP +#endif + + +/* +@@ LUA_PATH and LUA_CPATH are the names of the environment variables that +@* Lua check to set its paths. +@@ LUA_INIT is the name of the environment variable that Lua +@* checks for initialization code. +** CHANGE them if you want different names. +*/ +#define LUA_PATH "LUA_PATH" +#define LUA_CPATH "LUA_CPATH" +#define LUA_INIT "LUA_INIT" + + +/* +@@ LUA_PATH_DEFAULT is the default path that Lua uses to look for +@* Lua libraries. +@@ LUA_CPATH_DEFAULT is the default path that Lua uses to look for +@* C libraries. +** CHANGE them if your machine has a non-conventional directory +** hierarchy or if you want to install your libraries in +** non-conventional directories. +*/ +#if defined(_WIN32) +/* +** In Windows, any exclamation mark ('!') in the path is replaced by the +** path of the directory of the executable file of the current process. +*/ +#define LUA_LDIR "!\\lua\\" +#define LUA_CDIR "!\\" +#define LUA_PATH_DEFAULT \ + ".\\?.lua;" LUA_LDIR"?.lua;" LUA_LDIR"?\\init.lua;" \ + LUA_CDIR"?.lua;" LUA_CDIR"?\\init.lua" +#define LUA_CPATH_DEFAULT \ + ".\\?.dll;" LUA_CDIR"?.dll;" LUA_CDIR"loadall.dll" + +#else +#define LUA_ROOT "/usr/local/" +#define LUA_LDIR LUA_ROOT "share/lua/5.1/" +#define LUA_CDIR LUA_ROOT "lib/lua/5.1/" +#define LUA_PATH_DEFAULT \ + "./?.lua;" LUA_LDIR"?.lua;" LUA_LDIR"?/init.lua;" \ + LUA_CDIR"?.lua;" LUA_CDIR"?/init.lua" +#define LUA_CPATH_DEFAULT \ + "./?.so;" LUA_CDIR"?.so;" LUA_CDIR"loadall.so" +#endif + + +/* +@@ LUA_DIRSEP is the directory separator (for submodules). +** CHANGE it if your machine does not use "/" as the directory separator +** and is not Windows. (On Windows Lua automatically uses "\".) +*/ +#if defined(_WIN32) +#define LUA_DIRSEP "\\" +#else +#define LUA_DIRSEP "/" +#endif + + +/* +@@ LUA_PATHSEP is the character that separates templates in a path. +@@ LUA_PATH_MARK is the string that marks the substitution points in a +@* template. +@@ LUA_EXECDIR in a Windows path is replaced by the executable's +@* directory. +@@ LUA_IGMARK is a mark to ignore all before it when bulding the +@* luaopen_ function name. +** CHANGE them if for some reason your system cannot use those +** characters. (E.g., if one of those characters is a common character +** in file/directory names.) Probably you do not need to change them. +*/ +#define LUA_PATHSEP ";" +#define LUA_PATH_MARK "?" +#define LUA_EXECDIR "!" +#define LUA_IGMARK "-" + + +/* +@@ LUA_INTEGER is the integral type used by lua_pushinteger/lua_tointeger. +** CHANGE that if ptrdiff_t is not adequate on your machine. (On most +** machines, ptrdiff_t gives a good choice between int or long.) +*/ +#define LUA_INTEGER ptrdiff_t + + +/* +@@ LUA_API is a mark for all core API functions. +@@ LUALIB_API is a mark for all standard library functions. +** CHANGE them if you need to define those functions in some special way. +** For instance, if you want to create one Windows DLL with the core and +** the libraries, you may want to use the following definition (define +** LUA_BUILD_AS_DLL to get it). +*/ +#if defined(LUA_BUILD_AS_DLL) + +#if defined(LUA_CORE) || defined(LUA_LIB) +#define LUA_API __declspec(dllexport) +#else +#define LUA_API __declspec(dllimport) +#endif + +#else + +#define LUA_API extern + +#endif + +/* more often than not the libs go together with the core */ +#define LUALIB_API LUA_API + + +/* +@@ LUAI_FUNC is a mark for all extern functions that are not to be +@* exported to outside modules. +@@ LUAI_DATA is a mark for all extern (const) variables that are not to +@* be exported to outside modules. +** CHANGE them if you need to mark them in some special way. Elf/gcc +** (versions 3.2 and later) mark them as "hidden" to optimize access +** when Lua is compiled as a shared library. +*/ +#if defined(luaall_c) +#define LUAI_FUNC static +#define LUAI_DATA /* empty */ + +#elif defined(__GNUC__) && ((__GNUC__*100 + __GNUC_MINOR__) >= 302) && \ + defined(__ELF__) +#define LUAI_FUNC __attribute__((visibility("hidden"))) extern +#define LUAI_DATA LUAI_FUNC + +#else +#define LUAI_FUNC extern +#define LUAI_DATA extern +#endif + + + +/* +@@ LUA_QL describes how error messages quote program elements. +** CHANGE it if you want a different appearance. +*/ +#define LUA_QL(x) "'" x "'" +#define LUA_QS LUA_QL("%s") + + +/* +@@ LUA_IDSIZE gives the maximum size for the description of the source +@* of a function in debug information. +** CHANGE it if you want a different size. +*/ +#define LUA_IDSIZE 256 + + +/* +** {================================================================== +** Stand-alone configuration +** =================================================================== +*/ + +#if defined(lua_c) || defined(luaall_c) + +/* +@@ lua_stdin_is_tty detects whether the standard input is a 'tty' (that +@* is, whether we're running lua interactively). +** CHANGE it if you have a better definition for non-POSIX/non-Windows +** systems. +*/ +#if defined(LUA_USE_ISATTY) +#include +#define lua_stdin_is_tty() isatty(0) +#elif defined(LUA_WIN) +#include +#include +#define lua_stdin_is_tty() _isatty(_fileno(stdin)) +#else +#define lua_stdin_is_tty() 1 /* assume stdin is a tty */ +#endif + + +/* +@@ LUA_PROMPT is the default prompt used by stand-alone Lua. +@@ LUA_PROMPT2 is the default continuation prompt used by stand-alone Lua. +** CHANGE them if you want different prompts. (You can also change the +** prompts dynamically, assigning to globals _PROMPT/_PROMPT2.) +*/ +#define LUA_PROMPT "> " +#define LUA_PROMPT2 ">> " + + +/* +@@ LUA_PROGNAME is the default name for the stand-alone Lua program. +** CHANGE it if your stand-alone interpreter has a different name and +** your system is not able to detect that name automatically. +*/ +#define LUA_PROGNAME "lua" + + +/* +@@ LUA_MAXINPUT is the maximum length for an input line in the +@* stand-alone interpreter. +** CHANGE it if you need longer lines. +*/ +#define LUA_MAXINPUT 512 + + +/* +@@ lua_readline defines how to show a prompt and then read a line from +@* the standard input. +@@ lua_saveline defines how to "save" a read line in a "history". +@@ lua_freeline defines how to free a line read by lua_readline. +** CHANGE them if you want to improve this functionality (e.g., by using +** GNU readline and history facilities). +*/ +#if defined(LUA_USE_READLINE) +#include +#include +#include +#define lua_readline(L,b,p) ((void)L, ((b)=readline(p)) != NULL) +#define lua_saveline(L,idx) \ + if (lua_strlen(L,idx) > 0) /* non-empty line? */ \ + add_history(lua_tostring(L, idx)); /* add it to history */ +#define lua_freeline(L,b) ((void)L, free(b)) +#else +#define lua_readline(L,b,p) \ + ((void)L, fputs(p, stdout), fflush(stdout), /* show prompt */ \ + fgets(b, LUA_MAXINPUT, stdin) != NULL) /* get line */ +#define lua_saveline(L,idx) { (void)L; (void)idx; } +#define lua_freeline(L,b) { (void)L; (void)b; } +#endif + +#endif + +/* }================================================================== */ + + +/* +@@ LUAI_GCPAUSE defines the default pause between garbage-collector cycles +@* as a percentage. +** CHANGE it if you want the GC to run faster or slower (higher values +** mean larger pauses which mean slower collection.) You can also change +** this value dynamically. +*/ +#define LUAI_GCPAUSE 200 /* 200% (wait memory to double before next GC) */ + + +/* +@@ LUAI_GCMUL defines the default speed of garbage collection relative to +@* memory allocation as a percentage. +** CHANGE it if you want to change the granularity of the garbage +** collection. (Higher values mean coarser collections. 0 represents +** infinity, where each step performs a full collection.) You can also +** change this value dynamically. +*/ +#define LUAI_GCMUL 200 /* GC runs 'twice the speed' of memory allocation */ + + + +/* +@@ LUA_COMPAT_GETN controls compatibility with old getn behavior. +** CHANGE it (define it) if you want exact compatibility with the +** behavior of setn/getn in Lua 5.0. +*/ +#undef LUA_COMPAT_GETN + +/* +@@ LUA_COMPAT_LOADLIB controls compatibility about global loadlib. +** CHANGE it to undefined as soon as you do not need a global 'loadlib' +** function (the function is still available as 'package.loadlib'). +*/ +#undef LUA_COMPAT_LOADLIB + +/* +@@ LUA_COMPAT_VARARG controls compatibility with old vararg feature. +** CHANGE it to undefined as soon as your programs use only '...' to +** access vararg parameters (instead of the old 'arg' table). +*/ +#define LUA_COMPAT_VARARG + +/* +@@ LUA_COMPAT_MOD controls compatibility with old math.mod function. +** CHANGE it to undefined as soon as your programs use 'math.fmod' or +** the new '%' operator instead of 'math.mod'. +*/ +#define LUA_COMPAT_MOD + +/* +@@ LUA_COMPAT_LSTR controls compatibility with old long string nesting +@* facility. +** CHANGE it to 2 if you want the old behaviour, or undefine it to turn +** off the advisory error when nesting [[...]]. +*/ +#define LUA_COMPAT_LSTR 1 + +/* +@@ LUA_COMPAT_GFIND controls compatibility with old 'string.gfind' name. +** CHANGE it to undefined as soon as you rename 'string.gfind' to +** 'string.gmatch'. +*/ +#define LUA_COMPAT_GFIND + +/* +@@ LUA_COMPAT_OPENLIB controls compatibility with old 'luaL_openlib' +@* behavior. +** CHANGE it to undefined as soon as you replace to 'luaL_register' +** your uses of 'luaL_openlib' +*/ +#define LUA_COMPAT_OPENLIB + + + +/* +@@ luai_apicheck is the assert macro used by the Lua-C API. +** CHANGE luai_apicheck if you want Lua to perform some checks in the +** parameters it gets from API calls. This may slow down the interpreter +** a bit, but may be quite useful when debugging C code that interfaces +** with Lua. A useful redefinition is to use assert.h. +*/ +#if defined(LUA_USE_APICHECK) +#include +#define luai_apicheck(L,o) { (void)L; assert(o); } +#else +#define luai_apicheck(L,o) { (void)L; } +#endif + + +/* +@@ LUAI_BITSINT defines the number of bits in an int. +** CHANGE here if Lua cannot automatically detect the number of bits of +** your machine. Probably you do not need to change this. +*/ +/* avoid overflows in comparison */ +#if INT_MAX-20 < 32760 +#define LUAI_BITSINT 16 +#elif INT_MAX > 2147483640L +/* int has at least 32 bits */ +#define LUAI_BITSINT 32 +#else +#error "you must define LUA_BITSINT with number of bits in an integer" +#endif + + +/* +@@ LUAI_UINT32 is an unsigned integer with at least 32 bits. +@@ LUAI_INT32 is an signed integer with at least 32 bits. +@@ LUAI_UMEM is an unsigned integer big enough to count the total +@* memory used by Lua. +@@ LUAI_MEM is a signed integer big enough to count the total memory +@* used by Lua. +** CHANGE here if for some weird reason the default definitions are not +** good enough for your machine. (The definitions in the 'else' +** part always works, but may waste space on machines with 64-bit +** longs.) Probably you do not need to change this. +*/ +#if LUAI_BITSINT >= 32 +#define LUAI_UINT32 unsigned int +#define LUAI_INT32 int +#define LUAI_MAXINT32 INT_MAX +#define LUAI_UMEM size_t +#define LUAI_MEM ptrdiff_t +#else +/* 16-bit ints */ +#define LUAI_UINT32 unsigned long +#define LUAI_INT32 long +#define LUAI_MAXINT32 LONG_MAX +#define LUAI_UMEM unsigned long +#define LUAI_MEM long +#endif + + +/* +@@ LUAI_MAXCALLS limits the number of nested calls. +** CHANGE it if you need really deep recursive calls. This limit is +** arbitrary; its only purpose is to stop infinite recursion before +** exhausting memory. +*/ +#define LUAI_MAXCALLS 20000 + + +/* +@@ LUAI_MAXCSTACK limits the number of Lua stack slots that a C function +@* can use. +** CHANGE it if you need lots of (Lua) stack space for your C +** functions. This limit is arbitrary; its only purpose is to stop C +** functions to consume unlimited stack space. (must be smaller than +** -LUA_REGISTRYINDEX) +*/ +#define LUAI_MAXCSTACK 8000 + + + +/* +** {================================================================== +** CHANGE (to smaller values) the following definitions if your system +** has a small C stack. (Or you may want to change them to larger +** values if your system has a large C stack and these limits are +** too rigid for you.) Some of these constants control the size of +** stack-allocated arrays used by the compiler or the interpreter, while +** others limit the maximum number of recursive calls that the compiler +** or the interpreter can perform. Values too large may cause a C stack +** overflow for some forms of deep constructs. +** =================================================================== +*/ + + +/* +@@ LUAI_MAXCCALLS is the maximum depth for nested C calls (short) and +@* syntactical nested non-terminals in a program. +*/ +#define LUAI_MAXCCALLS 200 + + +/* +@@ LUAI_MAXVARS is the maximum number of local variables per function +@* (must be smaller than 250). +*/ +#define LUAI_MAXVARS 200 + + +/* +@@ LUAI_MAXUPVALUES is the maximum number of upvalues per function +@* (must be smaller than 250). +*/ +#define LUAI_MAXUPVALUES 60 + + +/* +@@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system. +*/ +#define LUAL_BUFFERSIZE BUFSIZ + +/* }================================================================== */ + + + + +/* +** {================================================================== +@@ LUA_NUMBER is the type of numbers in Lua. +** CHANGE the following definitions only if you want to build Lua +** with a number type different from double. You may also need to +** change lua_number2int & lua_number2integer. +** =================================================================== +*/ + +#define LUA_NUMBER_DOUBLE +#define LUA_NUMBER double + +/* +@@ LUAI_UACNUMBER is the result of an 'usual argument conversion' +@* over a number. +*/ +#define LUAI_UACNUMBER double + + +/* +@@ LUA_NUMBER_SCAN is the format for reading numbers. +@@ LUA_NUMBER_FMT is the format for writing numbers. +@@ lua_number2str converts a number to a string. +@@ LUAI_MAXNUMBER2STR is maximum size of previous conversion. +@@ lua_str2number converts a string to a number. +*/ +#define LUA_NUMBER_SCAN "%lf" +#define LUA_NUMBER_FMT "%.14g" +#define lua_number2str(s,n) sprintf((s), LUA_NUMBER_FMT, (n)) +#define LUAI_MAXNUMBER2STR 32 /* 16 digits, sign, point, and \0 */ +#define lua_str2number(s,p) strtod((s), (p)) + + +/* +@@ The luai_num* macros define the primitive operations over numbers. +*/ +#if defined(LUA_CORE) +#include +#define luai_numadd(a,b) ((a)+(b)) +#define luai_numsub(a,b) ((a)-(b)) +#define luai_nummul(a,b) ((a)*(b)) +#define luai_numdiv(a,b) ((a)/(b)) +#define luai_nummod(a,b) ((a) - floor((a)/(b))*(b)) +#define luai_numpow(a,b) (pow(a,b)) +#define luai_numunm(a) (-(a)) +#define luai_numeq(a,b) ((a)==(b)) +#define luai_numlt(a,b) ((a)<(b)) +#define luai_numle(a,b) ((a)<=(b)) +#define luai_numisnan(a) (!luai_numeq((a), (a))) +#endif + + +/* +@@ lua_number2int is a macro to convert lua_Number to int. +@@ lua_number2integer is a macro to convert lua_Number to lua_Integer. +** CHANGE them if you know a faster way to convert a lua_Number to +** int (with any rounding method and without throwing errors) in your +** system. In Pentium machines, a naive typecast from double to int +** in C is extremely slow, so any alternative is worth trying. +*/ + +/* On a Pentium, resort to a trick */ +#if defined(LUA_NUMBER_DOUBLE) && !defined(LUA_ANSI) && !defined(__SSE2__) && \ + (defined(__i386) || defined (_M_IX86) || defined(__i386__)) + +/* On a Microsoft compiler, use assembler */ +#if defined(_MSC_VER) + +#define lua_number2int(i,d) __asm fld d __asm fistp i +#define lua_number2integer(i,n) lua_number2int(i, n) + +/* the next trick should work on any Pentium, but sometimes clashes + with a DirectX idiosyncrasy */ +#else + +union luai_Cast { double l_d; long l_l; }; +#define lua_number2int(i,d) \ + { volatile union luai_Cast u; u.l_d = (d) + 6755399441055744.0; (i) = u.l_l; } +#define lua_number2integer(i,n) lua_number2int(i, n) + +#endif + + +/* this option always works, but may be slow */ +#else +#define lua_number2int(i,d) ((i)=(int)(d)) +#define lua_number2integer(i,d) ((i)=(lua_Integer)(d)) + +#endif + +/* }================================================================== */ + + +/* +@@ LUAI_USER_ALIGNMENT_T is a type that requires maximum alignment. +** CHANGE it if your system requires alignments larger than double. (For +** instance, if your system supports long doubles and they must be +** aligned in 16-byte boundaries, then you should add long double in the +** union.) Probably you do not need to change this. +*/ +#define LUAI_USER_ALIGNMENT_T union { double u; void *s; long l; } + + +/* +@@ LUAI_THROW/LUAI_TRY define how Lua does exception handling. +** CHANGE them if you prefer to use longjmp/setjmp even with C++ +** or if want/don't to use _longjmp/_setjmp instead of regular +** longjmp/setjmp. By default, Lua handles errors with exceptions when +** compiling as C++ code, with _longjmp/_setjmp when asked to use them, +** and with longjmp/setjmp otherwise. +*/ +#if defined(__cplusplus) +/* C++ exceptions */ +#define LUAI_THROW(L,c) throw(c) +#define LUAI_TRY(L,c,a) try { a } catch(...) \ + { if ((c)->status == 0) (c)->status = -1; } +#define luai_jmpbuf int /* dummy variable */ + +#elif defined(LUA_USE_ULONGJMP) +/* in Unix, try _longjmp/_setjmp (more efficient) */ +#define LUAI_THROW(L,c) _longjmp((c)->b, 1) +#define LUAI_TRY(L,c,a) if (_setjmp((c)->b) == 0) { a } +#define luai_jmpbuf jmp_buf + +#else +/* default handling with long jumps */ +#define LUAI_THROW(L,c) longjmp((c)->b, 1) +#define LUAI_TRY(L,c,a) if (setjmp((c)->b) == 0) { a } +#define luai_jmpbuf jmp_buf + +#endif + + +/* +@@ LUA_MAXCAPTURES is the maximum number of captures that a pattern +@* can do during pattern-matching. +** CHANGE it if you need more captures. This limit is arbitrary. +*/ +#define LUA_MAXCAPTURES 32 + + +/* +@@ lua_tmpnam is the function that the OS library uses to create a +@* temporary name. +@@ LUA_TMPNAMBUFSIZE is the maximum size of a name created by lua_tmpnam. +** CHANGE them if you have an alternative to tmpnam (which is considered +** insecure) or if you want the original tmpnam anyway. By default, Lua +** uses tmpnam except when POSIX is available, where it uses mkstemp. +*/ +#if defined(loslib_c) || defined(luaall_c) + +#if defined(LUA_USE_MKSTEMP) +#include +#define LUA_TMPNAMBUFSIZE 32 +#define lua_tmpnam(b,e) { \ + strcpy(b, "/tmp/lua_XXXXXX"); \ + e = mkstemp(b); \ + if (e != -1) close(e); \ + e = (e == -1); } + +#else +#define LUA_TMPNAMBUFSIZE L_tmpnam +#define lua_tmpnam(b,e) { e = (tmpnam(b) == NULL); } +#endif + +#endif + + +/* +@@ lua_popen spawns a new process connected to the current one through +@* the file streams. +** CHANGE it if you have a way to implement it in your system. +*/ +#if defined(LUA_USE_POPEN) + +#define lua_popen(L,c,m) ((void)L, fflush(NULL), popen(c,m)) +#define lua_pclose(L,file) ((void)L, (pclose(file) != -1)) + +#elif defined(LUA_WIN) + +#define lua_popen(L,c,m) ((void)L, _popen(c,m)) +#define lua_pclose(L,file) ((void)L, (_pclose(file) != -1)) + +#else + +#define lua_popen(L,c,m) ((void)((void)c, m), \ + luaL_error(L, LUA_QL("popen") " not supported"), (FILE*)0) +#define lua_pclose(L,file) ((void)((void)L, file), 0) + +#endif + +/* +@@ LUA_DL_* define which dynamic-library system Lua should use. +** CHANGE here if Lua has problems choosing the appropriate +** dynamic-library system for your platform (either Windows' DLL, Mac's +** dyld, or Unix's dlopen). If your system is some kind of Unix, there +** is a good chance that it has dlopen, so LUA_DL_DLOPEN will work for +** it. To use dlopen you also need to adapt the src/Makefile (probably +** adding -ldl to the linker options), so Lua does not select it +** automatically. (When you change the makefile to add -ldl, you must +** also add -DLUA_USE_DLOPEN.) +** If you do not want any kind of dynamic library, undefine all these +** options. +** By default, _WIN32 gets LUA_DL_DLL and MAC OS X gets LUA_DL_DYLD. +*/ +#if defined(LUA_USE_DLOPEN) +#define LUA_DL_DLOPEN +#endif + +#if defined(LUA_WIN) +#define LUA_DL_DLL +#endif + + +/* +@@ LUAI_EXTRASPACE allows you to add user-specific data in a lua_State +@* (the data goes just *before* the lua_State pointer). +** CHANGE (define) this if you really need that. This value must be +** a multiple of the maximum alignment required for your machine. +*/ +#define LUAI_EXTRASPACE 0 + + +/* +@@ luai_userstate* allow user-specific actions on threads. +** CHANGE them if you defined LUAI_EXTRASPACE and need to do something +** extra when a thread is created/deleted/resumed/yielded. +*/ +#define luai_userstateopen(L) ((void)L) +#define luai_userstateclose(L) ((void)L) +#define luai_userstatethread(L,L1) ((void)L) +#define luai_userstatefree(L) ((void)L) +#define luai_userstateresume(L,n) ((void)L) +#define luai_userstateyield(L,n) ((void)L) + + +/* +@@ LUA_INTFRMLEN is the length modifier for integer conversions +@* in 'string.format'. +@@ LUA_INTFRM_T is the integer type correspoding to the previous length +@* modifier. +** CHANGE them if your system supports long long or does not support long. +*/ + +#if defined(LUA_USELONGLONG) + +#define LUA_INTFRMLEN "ll" +#define LUA_INTFRM_T long long + +#else + +#define LUA_INTFRMLEN "l" +#define LUA_INTFRM_T long + +#endif + + + +/* =================================================================== */ + +/* +** Local configuration. You can use this space to add your redefinitions +** without modifying the main part of the file. +*/ + + + +#endif + diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lualib.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lualib.h new file mode 100644 index 00000000..469417f6 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lualib.h @@ -0,0 +1,53 @@ +/* +** $Id: lualib.h,v 1.36.1.1 2007/12/27 13:02:25 roberto Exp $ +** Lua standard libraries +** See Copyright Notice in lua.h +*/ + + +#ifndef lualib_h +#define lualib_h + +#include "lua.h" + + +/* Key to file-handle type */ +#define LUA_FILEHANDLE "FILE*" + + +#define LUA_COLIBNAME "coroutine" +LUALIB_API int (luaopen_base) (lua_State *L); + +#define LUA_TABLIBNAME "table" +LUALIB_API int (luaopen_table) (lua_State *L); + +#define LUA_IOLIBNAME "io" +LUALIB_API int (luaopen_io) (lua_State *L); + +#define LUA_OSLIBNAME "os" +LUALIB_API int (luaopen_os) (lua_State *L); + +#define LUA_STRLIBNAME "string" +LUALIB_API int (luaopen_string) (lua_State *L); + +#define LUA_MATHLIBNAME "math" +LUALIB_API int (luaopen_math) (lua_State *L); + +#define LUA_DBLIBNAME "debug" +LUALIB_API int (luaopen_debug) (lua_State *L); + +#define LUA_LOADLIBNAME "package" +LUALIB_API int (luaopen_package) (lua_State *L); + + +/* open all previous libraries */ +LUALIB_API void (luaL_openlibs) (lua_State *L); + + + +#ifndef lua_assert +#define lua_assert(x) ((void)0) +#endif + + +#endif diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lundump.c b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lundump.c new file mode 100644 index 00000000..8010a457 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lundump.c @@ -0,0 +1,227 @@ +/* +** $Id: lundump.c,v 2.7.1.4 2008/04/04 19:51:41 roberto Exp $ +** load precompiled Lua chunks +** See Copyright Notice in lua.h +*/ + +#include + +#define lundump_c +#define LUA_CORE + +#include "lua.h" + +#include "ldebug.h" +#include "ldo.h" +#include "lfunc.h" +#include "lmem.h" +#include "lobject.h" +#include "lstring.h" +#include "lundump.h" +#include "lzio.h" + +typedef struct { + lua_State* L; + ZIO* Z; + Mbuffer* b; + const char* name; +} LoadState; + +#ifdef LUAC_TRUST_BINARIES +#define IF(c,s) +#define error(S,s) +#else +#define IF(c,s) if (c) error(S,s) + +static void error(LoadState* S, const char* why) +{ + luaO_pushfstring(S->L,"%s: %s in precompiled chunk",S->name,why); + luaD_throw(S->L,LUA_ERRSYNTAX); +} +#endif + +#define LoadMem(S,b,n,size) LoadBlock(S,b,(n)*(size)) +#define LoadByte(S) (lu_byte)LoadChar(S) +#define LoadVar(S,x) LoadMem(S,&x,1,sizeof(x)) +#define LoadVector(S,b,n,size) LoadMem(S,b,n,size) + +static void LoadBlock(LoadState* S, void* b, size_t size) +{ + size_t r=luaZ_read(S->Z,b,size); + IF (r!=0, "unexpected end"); +} + +static int LoadChar(LoadState* S) +{ + char x; + LoadVar(S,x); + return x; +} + +static int LoadInt(LoadState* S) +{ + int x; + LoadVar(S,x); + IF (x<0, "bad integer"); + return x; +} + +static lua_Number LoadNumber(LoadState* S) +{ + lua_Number x; + LoadVar(S,x); + return x; +} + +static TString* LoadString(LoadState* S) +{ + size_t size; + LoadVar(S,size); + if (size==0) + return NULL; + else + { + char* s=luaZ_openspace(S->L,S->b,size); + LoadBlock(S,s,size); + return luaS_newlstr(S->L,s,size-1); /* remove trailing '\0' */ + } +} + +static void LoadCode(LoadState* S, Proto* f) +{ + int n=LoadInt(S); + f->code=luaM_newvector(S->L,n,Instruction); + f->sizecode=n; + LoadVector(S,f->code,n,sizeof(Instruction)); +} + +static Proto* LoadFunction(LoadState* S, TString* p); + +static void LoadConstants(LoadState* S, Proto* f) +{ + int i,n; + n=LoadInt(S); + f->k=luaM_newvector(S->L,n,TValue); + f->sizek=n; + for (i=0; ik[i]); + for (i=0; ik[i]; + int t=LoadChar(S); + switch (t) + { + case LUA_TNIL: + setnilvalue(o); + break; + case LUA_TBOOLEAN: + setbvalue(o,LoadChar(S)!=0); + break; + case LUA_TNUMBER: + setnvalue(o,LoadNumber(S)); + break; + case LUA_TSTRING: + setsvalue2n(S->L,o,LoadString(S)); + break; + default: + error(S,"bad constant"); + break; + } + } + n=LoadInt(S); + f->p=luaM_newvector(S->L,n,Proto*); + f->sizep=n; + for (i=0; ip[i]=NULL; + for (i=0; ip[i]=LoadFunction(S,f->source); +} + +static void LoadDebug(LoadState* S, Proto* f) +{ + int i,n; + n=LoadInt(S); + f->lineinfo=luaM_newvector(S->L,n,int); + f->sizelineinfo=n; + LoadVector(S,f->lineinfo,n,sizeof(int)); + n=LoadInt(S); + f->locvars=luaM_newvector(S->L,n,LocVar); + f->sizelocvars=n; + for (i=0; ilocvars[i].varname=NULL; + for (i=0; ilocvars[i].varname=LoadString(S); + f->locvars[i].startpc=LoadInt(S); + f->locvars[i].endpc=LoadInt(S); + } + n=LoadInt(S); + f->upvalues=luaM_newvector(S->L,n,TString*); + f->sizeupvalues=n; + for (i=0; iupvalues[i]=NULL; + for (i=0; iupvalues[i]=LoadString(S); +} + +static Proto* LoadFunction(LoadState* S, TString* p) +{ + Proto* f; + if (++S->L->nCcalls > LUAI_MAXCCALLS) error(S,"code too deep"); + f=luaF_newproto(S->L); + setptvalue2s(S->L,S->L->top,f); incr_top(S->L); + f->source=LoadString(S); if (f->source==NULL) f->source=p; + f->linedefined=LoadInt(S); + f->lastlinedefined=LoadInt(S); + f->nups=LoadByte(S); + f->numparams=LoadByte(S); + f->is_vararg=LoadByte(S); + f->maxstacksize=LoadByte(S); + LoadCode(S,f); + LoadConstants(S,f); + LoadDebug(S,f); + IF (!luaG_checkcode(f), "bad code"); + S->L->top--; + S->L->nCcalls--; + return f; +} + +static void LoadHeader(LoadState* S) +{ + char h[LUAC_HEADERSIZE]; + char s[LUAC_HEADERSIZE]; + luaU_header(h); + LoadBlock(S,s,LUAC_HEADERSIZE); + IF (memcmp(h,s,LUAC_HEADERSIZE)!=0, "bad header"); +} + +/* +** load precompiled chunk +*/ +Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name) +{ + LoadState S; + if (*name=='@' || *name=='=') + S.name=name+1; + else if (*name==LUA_SIGNATURE[0]) + S.name="binary string"; + else + S.name=name; + S.L=L; + S.Z=Z; + S.b=buff; + LoadHeader(&S); + return LoadFunction(&S,luaS_newliteral(L,"=?")); +} + +/* +* make header +*/ +void luaU_header (char* h) +{ + int x=1; + memcpy(h,LUA_SIGNATURE,sizeof(LUA_SIGNATURE)-1); + h+=sizeof(LUA_SIGNATURE)-1; + *h++=(char)LUAC_VERSION; + *h++=(char)LUAC_FORMAT; + *h++=(char)*(char*)&x; /* endianness */ + *h++=(char)sizeof(int); + *h++=(char)sizeof(size_t); + *h++=(char)sizeof(Instruction); + *h++=(char)sizeof(lua_Number); + *h++=(char)(((lua_Number)0.5)==0); /* is lua_Number integral? */ +} diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lundump.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lundump.h new file mode 100644 index 00000000..c80189db --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lundump.h @@ -0,0 +1,36 @@ +/* +** $Id: lundump.h,v 1.37.1.1 2007/12/27 13:02:25 roberto Exp $ +** load precompiled Lua chunks +** See Copyright Notice in lua.h +*/ + +#ifndef lundump_h +#define lundump_h + +#include "lobject.h" +#include "lzio.h" + +/* load one chunk; from lundump.c */ +LUAI_FUNC Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name); + +/* make header; from lundump.c */ +LUAI_FUNC void luaU_header (char* h); + +/* dump one chunk; from ldump.c */ +LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip); + +#ifdef luac_c +/* print one chunk; from print.c */ +LUAI_FUNC void luaU_print (const Proto* f, int full); +#endif + +/* for header of binary files -- this is Lua 5.1 */ +#define LUAC_VERSION 0x51 + +/* for header of binary files -- this is the official format */ +#define LUAC_FORMAT 0 + +/* size of header of binary files */ +#define LUAC_HEADERSIZE 12 + +#endif diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lvm.c b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lvm.c new file mode 100644 index 00000000..ee3256ab --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lvm.c @@ -0,0 +1,763 @@ +/* +** $Id: lvm.c,v 2.63.1.3 2007/12/28 15:32:23 roberto Exp $ +** Lua virtual machine +** See Copyright Notice in lua.h +*/ + + +#include +#include +#include + +#define lvm_c +#define LUA_CORE + +#include "lua.h" + +#include "ldebug.h" +#include "ldo.h" +#include "lfunc.h" +#include "lgc.h" +#include "lobject.h" +#include "lopcodes.h" +#include "lstate.h" +#include "lstring.h" +#include "ltable.h" +#include "ltm.h" +#include "lvm.h" + + + +/* limit for table tag-method chains (to avoid loops) */ +#define MAXTAGLOOP 100 + + +const TValue *luaV_tonumber (const TValue *obj, TValue *n) { + lua_Number num; + if (ttisnumber(obj)) return obj; + if (ttisstring(obj) && luaO_str2d(svalue(obj), &num)) { + setnvalue(n, num); + return n; + } + else + return NULL; +} + + +int luaV_tostring (lua_State *L, StkId obj) { + if (!ttisnumber(obj)) + return 0; + else { + char s[LUAI_MAXNUMBER2STR]; + lua_Number n = nvalue(obj); + lua_number2str(s, n); + setsvalue2s(L, obj, luaS_new(L, s)); + return 1; + } +} + + +static void traceexec (lua_State *L, const Instruction *pc) { + lu_byte mask = L->hookmask; + const Instruction *oldpc = L->savedpc; + L->savedpc = pc; + if ((mask & LUA_MASKCOUNT) && L->hookcount == 0) { + resethookcount(L); + luaD_callhook(L, LUA_HOOKCOUNT, -1); + } + if (mask & LUA_MASKLINE) { + Proto *p = ci_func(L->ci)->l.p; + int npc = pcRel(pc, p); + int newline = getline(p, npc); + /* call linehook when enter a new function, when jump back (loop), + or when enter a new line */ + if (npc == 0 || pc <= oldpc || newline != getline(p, pcRel(oldpc, p))) + luaD_callhook(L, LUA_HOOKLINE, newline); + } +} + + +static void callTMres (lua_State *L, StkId res, const TValue *f, + const TValue *p1, const TValue *p2) { + ptrdiff_t result = savestack(L, res); + setobj2s(L, L->top, f); /* push function */ + setobj2s(L, L->top+1, p1); /* 1st argument */ + setobj2s(L, L->top+2, p2); /* 2nd argument */ + luaD_checkstack(L, 3); + L->top += 3; + luaD_call(L, L->top - 3, 1); + res = restorestack(L, result); + L->top--; + setobjs2s(L, res, L->top); +} + + + +static void callTM (lua_State *L, const TValue *f, const TValue *p1, + const TValue *p2, const TValue *p3) { + setobj2s(L, L->top, f); /* push function */ + setobj2s(L, L->top+1, p1); /* 1st argument */ + setobj2s(L, L->top+2, p2); /* 2nd argument */ + setobj2s(L, L->top+3, p3); /* 3th argument */ + luaD_checkstack(L, 4); + L->top += 4; + luaD_call(L, L->top - 4, 0); +} + + +void luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val) { + int loop; + for (loop = 0; loop < MAXTAGLOOP; loop++) { + const TValue *tm; + if (ttistable(t)) { /* `t' is a table? */ + Table *h = hvalue(t); + const TValue *res = luaH_get(h, key); /* do a primitive get */ + if (!ttisnil(res) || /* result is no nil? */ + (tm = fasttm(L, h->metatable, TM_INDEX)) == NULL) { /* or no TM? */ + setobj2s(L, val, res); + return; + } + /* else will try the tag method */ + } + else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_INDEX))) + luaG_typeerror(L, t, "index"); + if (ttisfunction(tm)) { + callTMres(L, val, tm, t, key); + return; + } + t = tm; /* else repeat with `tm' */ + } + luaG_runerror(L, "loop in gettable"); +} + + +void luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val) { + int loop; + for (loop = 0; loop < MAXTAGLOOP; loop++) { + const TValue *tm; + if (ttistable(t)) { /* `t' is a table? */ + Table *h = hvalue(t); + TValue *oldval = luaH_set(L, h, key); /* do a primitive set */ + if (!ttisnil(oldval) || /* result is no nil? */ + (tm = fasttm(L, h->metatable, TM_NEWINDEX)) == NULL) { /* or no TM? */ + setobj2t(L, oldval, val); + luaC_barriert(L, h, val); + return; + } + /* else will try the tag method */ + } + else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_NEWINDEX))) + luaG_typeerror(L, t, "index"); + if (ttisfunction(tm)) { + callTM(L, tm, t, key, val); + return; + } + t = tm; /* else repeat with `tm' */ + } + luaG_runerror(L, "loop in settable"); +} + + +static int call_binTM (lua_State *L, const TValue *p1, const TValue *p2, + StkId res, TMS event) { + const TValue *tm = luaT_gettmbyobj(L, p1, event); /* try first operand */ + if (ttisnil(tm)) + tm = luaT_gettmbyobj(L, p2, event); /* try second operand */ + if (ttisnil(tm)) return 0; + callTMres(L, res, tm, p1, p2); + return 1; +} + + +static const TValue *get_compTM (lua_State *L, Table *mt1, Table *mt2, + TMS event) { + const TValue *tm1 = fasttm(L, mt1, event); + const TValue *tm2; + if (tm1 == NULL) return NULL; /* no metamethod */ + if (mt1 == mt2) return tm1; /* same metatables => same metamethods */ + tm2 = fasttm(L, mt2, event); + if (tm2 == NULL) return NULL; /* no metamethod */ + if (luaO_rawequalObj(tm1, tm2)) /* same metamethods? */ + return tm1; + return NULL; +} + + +static int call_orderTM (lua_State *L, const TValue *p1, const TValue *p2, + TMS event) { + const TValue *tm1 = luaT_gettmbyobj(L, p1, event); + const TValue *tm2; + if (ttisnil(tm1)) return -1; /* no metamethod? */ + tm2 = luaT_gettmbyobj(L, p2, event); + if (!luaO_rawequalObj(tm1, tm2)) /* different metamethods? */ + return -1; + callTMres(L, L->top, tm1, p1, p2); + return !l_isfalse(L->top); +} + + +static int l_strcmp (const TString *ls, const TString *rs) { + const char *l = getstr(ls); + size_t ll = ls->tsv.len; + const char *r = getstr(rs); + size_t lr = rs->tsv.len; + for (;;) { + int temp = strcoll(l, r); + if (temp != 0) return temp; + else { /* strings are equal up to a `\0' */ + size_t len = strlen(l); /* index of first `\0' in both strings */ + if (len == lr) /* r is finished? */ + return (len == ll) ? 0 : 1; + else if (len == ll) /* l is finished? */ + return -1; /* l is smaller than r (because r is not finished) */ + /* both strings longer than `len'; go on comparing (after the `\0') */ + len++; + l += len; ll -= len; r += len; lr -= len; + } + } +} + + +int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r) { + int res; + if (ttype(l) != ttype(r)) + return luaG_ordererror(L, l, r); + else if (ttisnumber(l)) + return luai_numlt(nvalue(l), nvalue(r)); + else if (ttisstring(l)) + return l_strcmp(rawtsvalue(l), rawtsvalue(r)) < 0; + else if ((res = call_orderTM(L, l, r, TM_LT)) != -1) + return res; + return luaG_ordererror(L, l, r); +} + + +static int lessequal (lua_State *L, const TValue *l, const TValue *r) { + int res; + if (ttype(l) != ttype(r)) + return luaG_ordererror(L, l, r); + else if (ttisnumber(l)) + return luai_numle(nvalue(l), nvalue(r)); + else if (ttisstring(l)) + return l_strcmp(rawtsvalue(l), rawtsvalue(r)) <= 0; + else if ((res = call_orderTM(L, l, r, TM_LE)) != -1) /* first try `le' */ + return res; + else if ((res = call_orderTM(L, r, l, TM_LT)) != -1) /* else try `lt' */ + return !res; + return luaG_ordererror(L, l, r); +} + + +int luaV_equalval (lua_State *L, const TValue *t1, const TValue *t2) { + const TValue *tm; + lua_assert(ttype(t1) == ttype(t2)); + switch (ttype(t1)) { + case LUA_TNIL: return 1; + case LUA_TNUMBER: return luai_numeq(nvalue(t1), nvalue(t2)); + case LUA_TBOOLEAN: return bvalue(t1) == bvalue(t2); /* true must be 1 !! */ + case LUA_TLIGHTUSERDATA: return pvalue(t1) == pvalue(t2); + case LUA_TUSERDATA: { + if (uvalue(t1) == uvalue(t2)) return 1; + tm = get_compTM(L, uvalue(t1)->metatable, uvalue(t2)->metatable, + TM_EQ); + break; /* will try TM */ + } + case LUA_TTABLE: { + if (hvalue(t1) == hvalue(t2)) return 1; + tm = get_compTM(L, hvalue(t1)->metatable, hvalue(t2)->metatable, TM_EQ); + break; /* will try TM */ + } + default: return gcvalue(t1) == gcvalue(t2); + } + if (tm == NULL) return 0; /* no TM? */ + callTMres(L, L->top, tm, t1, t2); /* call TM */ + return !l_isfalse(L->top); +} + + +void luaV_concat (lua_State *L, int total, int last) { + do { + StkId top = L->base + last + 1; + int n = 2; /* number of elements handled in this pass (at least 2) */ + if (!(ttisstring(top-2) || ttisnumber(top-2)) || !tostring(L, top-1)) { + if (!call_binTM(L, top-2, top-1, top-2, TM_CONCAT)) + luaG_concaterror(L, top-2, top-1); + } else if (tsvalue(top-1)->len == 0) /* second op is empty? */ + (void)tostring(L, top - 2); /* result is first op (as string) */ + else { + /* at least two string values; get as many as possible */ + size_t tl = tsvalue(top-1)->len; + char *buffer; + int i; + /* collect total length */ + for (n = 1; n < total && tostring(L, top-n-1); n++) { + size_t l = tsvalue(top-n-1)->len; + if (l >= MAX_SIZET - tl) luaG_runerror(L, "string length overflow"); + tl += l; + } + buffer = luaZ_openspace(L, &G(L)->buff, tl); + tl = 0; + for (i=n; i>0; i--) { /* concat all strings */ + size_t l = tsvalue(top-i)->len; + memcpy(buffer+tl, svalue(top-i), l); + tl += l; + } + setsvalue2s(L, top-n, luaS_newlstr(L, buffer, tl)); + } + total -= n-1; /* got `n' strings to create 1 new */ + last -= n-1; + } while (total > 1); /* repeat until only 1 result left */ +} + + +static void Arith (lua_State *L, StkId ra, const TValue *rb, + const TValue *rc, TMS op) { + TValue tempb, tempc; + const TValue *b, *c; + if ((b = luaV_tonumber(rb, &tempb)) != NULL && + (c = luaV_tonumber(rc, &tempc)) != NULL) { + lua_Number nb = nvalue(b), nc = nvalue(c); + switch (op) { + case TM_ADD: setnvalue(ra, luai_numadd(nb, nc)); break; + case TM_SUB: setnvalue(ra, luai_numsub(nb, nc)); break; + case TM_MUL: setnvalue(ra, luai_nummul(nb, nc)); break; + case TM_DIV: setnvalue(ra, luai_numdiv(nb, nc)); break; + case TM_MOD: setnvalue(ra, luai_nummod(nb, nc)); break; + case TM_POW: setnvalue(ra, luai_numpow(nb, nc)); break; + case TM_UNM: setnvalue(ra, luai_numunm(nb)); break; + default: lua_assert(0); break; + } + } + else if (!call_binTM(L, rb, rc, ra, op)) + luaG_aritherror(L, rb, rc); +} + + + +/* +** some macros for common tasks in `luaV_execute' +*/ + +#define runtime_check(L, c) { if (!(c)) break; } + +#define RA(i) (base+GETARG_A(i)) +/* to be used after possible stack reallocation */ +#define RB(i) check_exp(getBMode(GET_OPCODE(i)) == OpArgR, base+GETARG_B(i)) +#define RC(i) check_exp(getCMode(GET_OPCODE(i)) == OpArgR, base+GETARG_C(i)) +#define RKB(i) check_exp(getBMode(GET_OPCODE(i)) == OpArgK, \ + ISK(GETARG_B(i)) ? k+INDEXK(GETARG_B(i)) : base+GETARG_B(i)) +#define RKC(i) check_exp(getCMode(GET_OPCODE(i)) == OpArgK, \ + ISK(GETARG_C(i)) ? k+INDEXK(GETARG_C(i)) : base+GETARG_C(i)) +#define KBx(i) check_exp(getBMode(GET_OPCODE(i)) == OpArgK, k+GETARG_Bx(i)) + + +#define dojump(L,pc,i) {(pc) += (i); luai_threadyield(L);} + + +#define Protect(x) { L->savedpc = pc; {x;}; base = L->base; } + + +#define arith_op(op,tm) { \ + TValue *rb = RKB(i); \ + TValue *rc = RKC(i); \ + if (ttisnumber(rb) && ttisnumber(rc)) { \ + lua_Number nb = nvalue(rb), nc = nvalue(rc); \ + setnvalue(ra, op(nb, nc)); \ + } \ + else \ + Protect(Arith(L, ra, rb, rc, tm)); \ + } + + + +void luaV_execute (lua_State *L, int nexeccalls) { + LClosure *cl; + StkId base; + TValue *k; + const Instruction *pc; + reentry: /* entry point */ + lua_assert(isLua(L->ci)); + pc = L->savedpc; + cl = &clvalue(L->ci->func)->l; + base = L->base; + k = cl->p->k; + /* main loop of interpreter */ + for (;;) { + const Instruction i = *pc++; + StkId ra; + if ((L->hookmask & (LUA_MASKLINE | LUA_MASKCOUNT)) && + (--L->hookcount == 0 || L->hookmask & LUA_MASKLINE)) { + traceexec(L, pc); + if (L->status == LUA_YIELD) { /* did hook yield? */ + L->savedpc = pc - 1; + return; + } + base = L->base; + } + /* warning!! several calls may realloc the stack and invalidate `ra' */ + ra = RA(i); + lua_assert(base == L->base && L->base == L->ci->base); + lua_assert(base <= L->top && L->top <= L->stack + L->stacksize); + lua_assert(L->top == L->ci->top || luaG_checkopenop(i)); + switch (GET_OPCODE(i)) { + case OP_MOVE: { + setobjs2s(L, ra, RB(i)); + continue; + } + case OP_LOADK: { + setobj2s(L, ra, KBx(i)); + continue; + } + case OP_LOADBOOL: { + setbvalue(ra, GETARG_B(i)); + if (GETARG_C(i)) pc++; /* skip next instruction (if C) */ + continue; + } + case OP_LOADNIL: { + TValue *rb = RB(i); + do { + setnilvalue(rb--); + } while (rb >= ra); + continue; + } + case OP_GETUPVAL: { + int b = GETARG_B(i); + setobj2s(L, ra, cl->upvals[b]->v); + continue; + } + case OP_GETGLOBAL: { + TValue g; + TValue *rb = KBx(i); + sethvalue(L, &g, cl->env); + lua_assert(ttisstring(rb)); + Protect(luaV_gettable(L, &g, rb, ra)); + continue; + } + case OP_GETTABLE: { + Protect(luaV_gettable(L, RB(i), RKC(i), ra)); + continue; + } + case OP_SETGLOBAL: { + TValue g; + sethvalue(L, &g, cl->env); + lua_assert(ttisstring(KBx(i))); + Protect(luaV_settable(L, &g, KBx(i), ra)); + continue; + } + case OP_SETUPVAL: { + UpVal *uv = cl->upvals[GETARG_B(i)]; + setobj(L, uv->v, ra); + luaC_barrier(L, uv, ra); + continue; + } + case OP_SETTABLE: { + Protect(luaV_settable(L, ra, RKB(i), RKC(i))); + continue; + } + case OP_NEWTABLE: { + int b = GETARG_B(i); + int c = GETARG_C(i); + sethvalue(L, ra, luaH_new(L, luaO_fb2int(b), luaO_fb2int(c))); + Protect(luaC_checkGC(L)); + continue; + } + case OP_SELF: { + StkId rb = RB(i); + setobjs2s(L, ra+1, rb); + Protect(luaV_gettable(L, rb, RKC(i), ra)); + continue; + } + case OP_ADD: { + arith_op(luai_numadd, TM_ADD); + continue; + } + case OP_SUB: { + arith_op(luai_numsub, TM_SUB); + continue; + } + case OP_MUL: { + arith_op(luai_nummul, TM_MUL); + continue; + } + case OP_DIV: { + arith_op(luai_numdiv, TM_DIV); + continue; + } + case OP_MOD: { + arith_op(luai_nummod, TM_MOD); + continue; + } + case OP_POW: { + arith_op(luai_numpow, TM_POW); + continue; + } + case OP_UNM: { + TValue *rb = RB(i); + if (ttisnumber(rb)) { + lua_Number nb = nvalue(rb); + setnvalue(ra, luai_numunm(nb)); + } + else { + Protect(Arith(L, ra, rb, rb, TM_UNM)); + } + continue; + } + case OP_NOT: { + int res = l_isfalse(RB(i)); /* next assignment may change this value */ + setbvalue(ra, res); + continue; + } + case OP_LEN: { + const TValue *rb = RB(i); + switch (ttype(rb)) { + case LUA_TTABLE: { + setnvalue(ra, cast_num(luaH_getn(hvalue(rb)))); + break; + } + case LUA_TSTRING: { + setnvalue(ra, cast_num(tsvalue(rb)->len)); + break; + } + default: { /* try metamethod */ + Protect( + if (!call_binTM(L, rb, luaO_nilobject, ra, TM_LEN)) + luaG_typeerror(L, rb, "get length of"); + ) + } + } + continue; + } + case OP_CONCAT: { + int b = GETARG_B(i); + int c = GETARG_C(i); + Protect(luaV_concat(L, c-b+1, c); luaC_checkGC(L)); + setobjs2s(L, RA(i), base+b); + continue; + } + case OP_JMP: { + dojump(L, pc, GETARG_sBx(i)); + continue; + } + case OP_EQ: { + TValue *rb = RKB(i); + TValue *rc = RKC(i); + Protect( + if (equalobj(L, rb, rc) == GETARG_A(i)) + dojump(L, pc, GETARG_sBx(*pc)); + ) + pc++; + continue; + } + case OP_LT: { + Protect( + if (luaV_lessthan(L, RKB(i), RKC(i)) == GETARG_A(i)) + dojump(L, pc, GETARG_sBx(*pc)); + ) + pc++; + continue; + } + case OP_LE: { + Protect( + if (lessequal(L, RKB(i), RKC(i)) == GETARG_A(i)) + dojump(L, pc, GETARG_sBx(*pc)); + ) + pc++; + continue; + } + case OP_TEST: { + if (l_isfalse(ra) != GETARG_C(i)) + dojump(L, pc, GETARG_sBx(*pc)); + pc++; + continue; + } + case OP_TESTSET: { + TValue *rb = RB(i); + if (l_isfalse(rb) != GETARG_C(i)) { + setobjs2s(L, ra, rb); + dojump(L, pc, GETARG_sBx(*pc)); + } + pc++; + continue; + } + case OP_CALL: { + int b = GETARG_B(i); + int nresults = GETARG_C(i) - 1; + if (b != 0) L->top = ra+b; /* else previous instruction set top */ + L->savedpc = pc; + switch (luaD_precall(L, ra, nresults)) { + case PCRLUA: { + nexeccalls++; + goto reentry; /* restart luaV_execute over new Lua function */ + } + case PCRC: { + /* it was a C function (`precall' called it); adjust results */ + if (nresults >= 0) L->top = L->ci->top; + base = L->base; + continue; + } + default: { + return; /* yield */ + } + } + } + case OP_TAILCALL: { + int b = GETARG_B(i); + if (b != 0) L->top = ra+b; /* else previous instruction set top */ + L->savedpc = pc; + lua_assert(GETARG_C(i) - 1 == LUA_MULTRET); + switch (luaD_precall(L, ra, LUA_MULTRET)) { + case PCRLUA: { + /* tail call: put new frame in place of previous one */ + CallInfo *ci = L->ci - 1; /* previous frame */ + int aux; + StkId func = ci->func; + StkId pfunc = (ci+1)->func; /* previous function index */ + if (L->openupval) luaF_close(L, ci->base); + L->base = ci->base = ci->func + ((ci+1)->base - pfunc); + for (aux = 0; pfunc+aux < L->top; aux++) /* move frame down */ + setobjs2s(L, func+aux, pfunc+aux); + ci->top = L->top = func+aux; /* correct top */ + lua_assert(L->top == L->base + clvalue(func)->l.p->maxstacksize); + ci->savedpc = L->savedpc; + ci->tailcalls++; /* one more call lost */ + L->ci--; /* remove new frame */ + goto reentry; + } + case PCRC: { /* it was a C function (`precall' called it) */ + base = L->base; + continue; + } + default: { + return; /* yield */ + } + } + } + case OP_RETURN: { + int b = GETARG_B(i); + if (b != 0) L->top = ra+b-1; + if (L->openupval) luaF_close(L, base); + L->savedpc = pc; + b = luaD_poscall(L, ra); + if (--nexeccalls == 0) /* was previous function running `here'? */ + return; /* no: return */ + else { /* yes: continue its execution */ + if (b) L->top = L->ci->top; + lua_assert(isLua(L->ci)); + lua_assert(GET_OPCODE(*((L->ci)->savedpc - 1)) == OP_CALL); + goto reentry; + } + } + case OP_FORLOOP: { + lua_Number step = nvalue(ra+2); + lua_Number idx = luai_numadd(nvalue(ra), step); /* increment index */ + lua_Number limit = nvalue(ra+1); + if (luai_numlt(0, step) ? luai_numle(idx, limit) + : luai_numle(limit, idx)) { + dojump(L, pc, GETARG_sBx(i)); /* jump back */ + setnvalue(ra, idx); /* update internal index... */ + setnvalue(ra+3, idx); /* ...and external index */ + } + continue; + } + case OP_FORPREP: { + const TValue *init = ra; + const TValue *plimit = ra+1; + const TValue *pstep = ra+2; + L->savedpc = pc; /* next steps may throw errors */ + if (!tonumber(init, ra)) + luaG_runerror(L, LUA_QL("for") " initial value must be a number"); + else if (!tonumber(plimit, ra+1)) + luaG_runerror(L, LUA_QL("for") " limit must be a number"); + else if (!tonumber(pstep, ra+2)) + luaG_runerror(L, LUA_QL("for") " step must be a number"); + setnvalue(ra, luai_numsub(nvalue(ra), nvalue(pstep))); + dojump(L, pc, GETARG_sBx(i)); + continue; + } + case OP_TFORLOOP: { + StkId cb = ra + 3; /* call base */ + setobjs2s(L, cb+2, ra+2); + setobjs2s(L, cb+1, ra+1); + setobjs2s(L, cb, ra); + L->top = cb+3; /* func. + 2 args (state and index) */ + Protect(luaD_call(L, cb, GETARG_C(i))); + L->top = L->ci->top; + cb = RA(i) + 3; /* previous call may change the stack */ + if (!ttisnil(cb)) { /* continue loop? */ + setobjs2s(L, cb-1, cb); /* save control variable */ + dojump(L, pc, GETARG_sBx(*pc)); /* jump back */ + } + pc++; + continue; + } + case OP_SETLIST: { + int n = GETARG_B(i); + int c = GETARG_C(i); + int last; + Table *h; + if (n == 0) { + n = cast_int(L->top - ra) - 1; + L->top = L->ci->top; + } + if (c == 0) c = cast_int(*pc++); + runtime_check(L, ttistable(ra)); + h = hvalue(ra); + last = ((c-1)*LFIELDS_PER_FLUSH) + n; + if (last > h->sizearray) /* needs more space? */ + luaH_resizearray(L, h, last); /* pre-alloc it at once */ + for (; n > 0; n--) { + TValue *val = ra+n; + setobj2t(L, luaH_setnum(L, h, last--), val); + luaC_barriert(L, h, val); + } + continue; + } + case OP_CLOSE: { + luaF_close(L, ra); + continue; + } + case OP_CLOSURE: { + Proto *p; + Closure *ncl; + int nup, j; + p = cl->p->p[GETARG_Bx(i)]; + nup = p->nups; + ncl = luaF_newLclosure(L, nup, cl->env); + ncl->l.p = p; + for (j=0; jl.upvals[j] = cl->upvals[GETARG_B(*pc)]; + else { + lua_assert(GET_OPCODE(*pc) == OP_MOVE); + ncl->l.upvals[j] = luaF_findupval(L, base + GETARG_B(*pc)); + } + } + setclvalue(L, ra, ncl); + Protect(luaC_checkGC(L)); + continue; + } + case OP_VARARG: { + int b = GETARG_B(i) - 1; + int j; + CallInfo *ci = L->ci; + int n = cast_int(ci->base - ci->func) - cl->p->numparams - 1; + if (b == LUA_MULTRET) { + Protect(luaD_checkstack(L, n)); + ra = RA(i); /* previous call may change the stack */ + b = n; + L->top = ra + n; + } + for (j = 0; j < b; j++) { + if (j < n) { + setobjs2s(L, ra + j, ci->base - n + j); + } + else { + setnilvalue(ra + j); + } + } + continue; + } + } + } +} + diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lvm.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lvm.h new file mode 100644 index 00000000..bfe4f567 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lvm.h @@ -0,0 +1,36 @@ +/* +** $Id: lvm.h,v 2.5.1.1 2007/12/27 13:02:25 roberto Exp $ +** Lua virtual machine +** See Copyright Notice in lua.h +*/ + +#ifndef lvm_h +#define lvm_h + + +#include "ldo.h" +#include "lobject.h" +#include "ltm.h" + + +#define tostring(L,o) ((ttype(o) == LUA_TSTRING) || (luaV_tostring(L, o))) + +#define tonumber(o,n) (ttype(o) == LUA_TNUMBER || \ + (((o) = luaV_tonumber(o,n)) != NULL)) + +#define equalobj(L,o1,o2) \ + (ttype(o1) == ttype(o2) && luaV_equalval(L, o1, o2)) + + +LUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r); +LUAI_FUNC int luaV_equalval (lua_State *L, const TValue *t1, const TValue *t2); +LUAI_FUNC const TValue *luaV_tonumber (const TValue *obj, TValue *n); +LUAI_FUNC int luaV_tostring (lua_State *L, StkId obj); +LUAI_FUNC void luaV_gettable (lua_State *L, const TValue *t, TValue *key, + StkId val); +LUAI_FUNC void luaV_settable (lua_State *L, const TValue *t, TValue *key, + StkId val); +LUAI_FUNC void luaV_execute (lua_State *L, int nexeccalls); +LUAI_FUNC void luaV_concat (lua_State *L, int total, int last); + +#endif diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lzio.c b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lzio.c new file mode 100644 index 00000000..293edd59 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lzio.c @@ -0,0 +1,82 @@ +/* +** $Id: lzio.c,v 1.31.1.1 2007/12/27 13:02:25 roberto Exp $ +** a generic input stream interface +** See Copyright Notice in lua.h +*/ + + +#include + +#define lzio_c +#define LUA_CORE + +#include "lua.h" + +#include "llimits.h" +#include "lmem.h" +#include "lstate.h" +#include "lzio.h" + + +int luaZ_fill (ZIO *z) { + size_t size; + lua_State *L = z->L; + const char *buff; + lua_unlock(L); + buff = z->reader(L, z->data, &size); + lua_lock(L); + if (buff == NULL || size == 0) return EOZ; + z->n = size - 1; + z->p = buff; + return char2int(*(z->p++)); +} + + +int luaZ_lookahead (ZIO *z) { + if (z->n == 0) { + if (luaZ_fill(z) == EOZ) + return EOZ; + else { + z->n++; /* luaZ_fill removed first byte; put back it */ + z->p--; + } + } + return char2int(*z->p); +} + + +void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) { + z->L = L; + z->reader = reader; + z->data = data; + z->n = 0; + z->p = NULL; +} + + +/* --------------------------------------------------------------- read --- */ +size_t luaZ_read (ZIO *z, void *b, size_t n) { + while (n) { + size_t m; + if (luaZ_lookahead(z) == EOZ) + return n; /* return number of missing bytes */ + m = (n <= z->n) ? n : z->n; /* min. between n and z->n */ + memcpy(b, z->p, m); + z->n -= m; + z->p += m; + b = (char *)b + m; + n -= m; + } + return 0; +} + +/* ------------------------------------------------------------------------ */ +char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n) { + if (n > buff->buffsize) { + if (n < LUA_MINBUFFER) n = LUA_MINBUFFER; + luaZ_resizebuffer(L, buff, n); + } + return buff->buffer; +} + + diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lzio.h b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lzio.h new file mode 100644 index 00000000..51d695d8 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/lzio.h @@ -0,0 +1,67 @@ +/* +** $Id: lzio.h,v 1.21.1.1 2007/12/27 13:02:25 roberto Exp $ +** Buffered streams +** See Copyright Notice in lua.h +*/ + + +#ifndef lzio_h +#define lzio_h + +#include "lua.h" + +#include "lmem.h" + + +#define EOZ (-1) /* end of stream */ + +typedef struct Zio ZIO; + +#define char2int(c) cast(int, cast(unsigned char, (c))) + +#define zgetc(z) (((z)->n--)>0 ? char2int(*(z)->p++) : luaZ_fill(z)) + +typedef struct Mbuffer { + char *buffer; + size_t n; + size_t buffsize; +} Mbuffer; + +#define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0) + +#define luaZ_buffer(buff) ((buff)->buffer) +#define luaZ_sizebuffer(buff) ((buff)->buffsize) +#define luaZ_bufflen(buff) ((buff)->n) + +#define luaZ_resetbuffer(buff) ((buff)->n = 0) + + +#define luaZ_resizebuffer(L, buff, size) \ + (luaM_reallocvector(L, (buff)->buffer, (buff)->buffsize, size, char), \ + (buff)->buffsize = size) + +#define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0) + + +LUAI_FUNC char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n); +LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, + void *data); +LUAI_FUNC size_t luaZ_read (ZIO* z, void* b, size_t n); /* read next n bytes */ +LUAI_FUNC int luaZ_lookahead (ZIO *z); + + + +/* --------- Private Part ------------------ */ + +struct Zio { + size_t n; /* bytes still unread */ + const char *p; /* current position in buffer */ + lua_Reader reader; + void* data; /* additional data */ + lua_State *L; /* Lua state (for reader) */ +}; + + +LUAI_FUNC int luaZ_fill (ZIO *z); + +#endif diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/print.c b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/print.c new file mode 100644 index 00000000..e240cfc3 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/IOS/lua/lua/print.c @@ -0,0 +1,227 @@ +/* +** $Id: print.c,v 1.55a 2006/05/31 13:30:05 lhf Exp $ +** print bytecodes +** See Copyright Notice in lua.h +*/ + +#include +#include + +#define luac_c +#define LUA_CORE + +#include "ldebug.h" +#include "lobject.h" +#include "lopcodes.h" +#include "lundump.h" + +#define PrintFunction luaU_print + +#define Sizeof(x) ((int)sizeof(x)) +#define VOID(p) ((const void*)(p)) + +static void PrintString(const TString* ts) +{ + const char* s=getstr(ts); + size_t i,n=ts->tsv.len; + putchar('"'); + for (i=0; ik[i]; + switch (ttype(o)) + { + case LUA_TNIL: + printf("nil"); + break; + case LUA_TBOOLEAN: + printf(bvalue(o) ? "true" : "false"); + break; + case LUA_TNUMBER: + printf(LUA_NUMBER_FMT,nvalue(o)); + break; + case LUA_TSTRING: + PrintString(rawtsvalue(o)); + break; + default: /* cannot happen */ + printf("? type=%d",ttype(o)); + break; + } +} + +static void PrintCode(const Proto* f) +{ + const Instruction* code=f->code; + int pc,n=f->sizecode; + for (pc=0; pc0) printf("[%d]\t",line); else printf("[-]\t"); + printf("%-9s\t",luaP_opnames[o]); + switch (getOpMode(o)) + { + case iABC: + printf("%d",a); + if (getBMode(o)!=OpArgN) printf(" %d",ISK(b) ? (-1-INDEXK(b)) : b); + if (getCMode(o)!=OpArgN) printf(" %d",ISK(c) ? (-1-INDEXK(c)) : c); + break; + case iABx: + if (getBMode(o)==OpArgK) printf("%d %d",a,-1-bx); else printf("%d %d",a,bx); + break; + case iAsBx: + if (o==OP_JMP) printf("%d",sbx); else printf("%d %d",a,sbx); + break; + } + switch (o) + { + case OP_LOADK: + printf("\t; "); PrintConstant(f,bx); + break; + case OP_GETUPVAL: + case OP_SETUPVAL: + printf("\t; %s", (f->sizeupvalues>0) ? getstr(f->upvalues[b]) : "-"); + break; + case OP_GETGLOBAL: + case OP_SETGLOBAL: + printf("\t; %s",svalue(&f->k[bx])); + break; + case OP_GETTABLE: + case OP_SELF: + if (ISK(c)) { printf("\t; "); PrintConstant(f,INDEXK(c)); } + break; + case OP_SETTABLE: + case OP_ADD: + case OP_SUB: + case OP_MUL: + case OP_DIV: + case OP_POW: + case OP_EQ: + case OP_LT: + case OP_LE: + if (ISK(b) || ISK(c)) + { + printf("\t; "); + if (ISK(b)) PrintConstant(f,INDEXK(b)); else printf("-"); + printf(" "); + if (ISK(c)) PrintConstant(f,INDEXK(c)); else printf("-"); + } + break; + case OP_JMP: + case OP_FORLOOP: + case OP_FORPREP: + printf("\t; to %d",sbx+pc+2); + break; + case OP_CLOSURE: + printf("\t; %p",VOID(f->p[bx])); + break; + case OP_SETLIST: + if (c==0) printf("\t; %d",(int)code[++pc]); + else printf("\t; %d",c); + break; + default: + break; + } + printf("\n"); + } +} + +#define SS(x) (x==1)?"":"s" +#define S(x) x,SS(x) + +static void PrintHeader(const Proto* f) +{ + const char* s=getstr(f->source); + if (*s=='@' || *s=='=') + s++; + else if (*s==LUA_SIGNATURE[0]) + s="(bstring)"; + else + s="(string)"; + printf("\n%s <%s:%d,%d> (%d instruction%s, %d bytes at %p)\n", + (f->linedefined==0)?"main":"function",s, + f->linedefined,f->lastlinedefined, + S(f->sizecode),f->sizecode*Sizeof(Instruction),VOID(f)); + printf("%d%s param%s, %d slot%s, %d upvalue%s, ", + f->numparams,f->is_vararg?"+":"",SS(f->numparams), + S(f->maxstacksize),S(f->nups)); + printf("%d local%s, %d constant%s, %d function%s\n", + S(f->sizelocvars),S(f->sizek),S(f->sizep)); +} + +static void PrintConstants(const Proto* f) +{ + int i,n=f->sizek; + printf("constants (%d) for %p:\n",n,VOID(f)); + for (i=0; isizelocvars; + printf("locals (%d) for %p:\n",n,VOID(f)); + for (i=0; ilocvars[i].varname),f->locvars[i].startpc+1,f->locvars[i].endpc+1); + } +} + +static void PrintUpvalues(const Proto* f) +{ + int i,n=f->sizeupvalues; + printf("upvalues (%d) for %p:\n",n,VOID(f)); + if (f->upvalues==NULL) return; + for (i=0; iupvalues[i])); + } +} + +void PrintFunction(const Proto* f, int full) +{ + int i,n=f->sizep; + PrintHeader(f); + PrintCode(f); + if (full) + { + PrintConstants(f); + PrintLocals(f); + PrintUpvalues(f); + } + for (i=0; ip[i],full); +} diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/LICENSE.txt b/IOS/luaviewEx/Example/Pods/LuaViewSDK/LICENSE.txt new file mode 100644 index 00000000..5546ac5f --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/LICENSE.txt @@ -0,0 +1,17 @@ +The MIT License (MIT) +Copyright (c) 2017 Alibaba Group +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/IOS/luaviewEx/Example/Pods/LuaViewSDK/README.md b/IOS/luaviewEx/Example/Pods/LuaViewSDK/README.md new file mode 100644 index 00000000..6dde4ed3 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/LuaViewSDK/README.md @@ -0,0 +1,38 @@ +# 欢迎来到LuaViewSDK + +LuaViewSDK是一个跨iOS和Android平台的界面动态化解决方案,使用同一套Lua脚本在iOS和Android平台构建原生页面,同时兼具了H5的灵活性和Native的高性能 + +## 为什么选择Lua + +为了解决类似的问题,市面上有许多类似的方案,比如React Native和Weex,他们使用了JS框架,配合DSL来进行界面布局,使用JS引擎进行脚本动态解析,实现了动态化的Native界面渲染能力。LuaViewSDK使用lua虚拟机进行脚本解析,通过构建lua与native之间的一系列基础bridge功能,从另一个角度实现了动态化的native能力。相比于基于JS虚拟机的解决方案,LuaViewSDK有如下特性: + +- lua虚拟机极为轻量高效。单个lua虚拟机只消耗大约200到300k的内存空间,同屏渲染几十个LuaView没有任何负担 +- Lua天生就是作为一个极其轻量、可嵌入的设计实现,它更适合做API的封装或是数据传输的中间层。在App的开发上,更适合作为胶水语言,来直接操作native对象 +- 使用App开发人员更为熟悉的Native编程模式,直接创建和操作各种界面对象 +- 轻松桥接native组件,只需要一行代码即可实现在LuaView脚本中操作用户自定义的native功能 + +## 试用Playground App + +LuaViewSDK Playground App下载地址 [Download](https://github.com/alibaba/LuaViewSDK/releases) + +## 如何使用LuaViewSDK + +- [使用说明](https://alibaba.github.io/LuaViewSDK/guide.html) +- [接口文档](https://alibaba.github.io/LuaViewSDK/apimenu.html) + +## 开发者 + +- [董希成](xicheng.dxc@alibaba-inc.com) +- [陈松涛](songtao.cst@alibaba-inc.com) + +## 许可证 + +[MIT](https://github.com/alibaba/LuaViewSDK/blob/master/LICENSE.txt) + +## 社区 + +[Github Wiki](https://github.com/alibaba/LuaViewSDK/wiki) + +QQ群:539262083 + +Twitter:[@luaview](https://twitter.com/luaview) \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/MJRefresh/LICENSE b/IOS/luaviewEx/Example/Pods/MJRefresh/LICENSE new file mode 100644 index 00000000..11bf2345 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/MJRefresh/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2013-2015 MJRefresh (https://github.com/CoderMJLee/MJRefresh) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Base/MJRefreshAutoFooter.h b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Base/MJRefreshAutoFooter.h new file mode 100644 index 00000000..82a02497 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Base/MJRefreshAutoFooter.h @@ -0,0 +1,20 @@ +// +// MJRefreshAutoFooter.h +// MJRefreshExample +// +// Created by MJ Lee on 15/4/24. +// Copyright (c) 2015年 小码哥. All rights reserved. +// + +#import "MJRefreshFooter.h" + +@interface MJRefreshAutoFooter : MJRefreshFooter +/** 是否自动刷新(默认为YES) */ +@property (assign, nonatomic, getter=isAutomaticallyRefresh) BOOL automaticallyRefresh; + +/** 当底部控件出现多少时就自动刷新(默认为1.0,也就是底部控件完全出现时,才会自动刷新) */ +@property (assign, nonatomic) CGFloat appearencePercentTriggerAutoRefresh MJRefreshDeprecated("请使用triggerAutomaticallyRefreshPercent属性"); + +/** 当底部控件出现多少时就自动刷新(默认为1.0,也就是底部控件完全出现时,才会自动刷新) */ +@property (assign, nonatomic) CGFloat triggerAutomaticallyRefreshPercent; +@end diff --git a/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Base/MJRefreshAutoFooter.m b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Base/MJRefreshAutoFooter.m new file mode 100644 index 00000000..7327096b --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Base/MJRefreshAutoFooter.m @@ -0,0 +1,139 @@ +// +// MJRefreshAutoFooter.m +// MJRefreshExample +// +// Created by MJ Lee on 15/4/24. +// Copyright (c) 2015年 小码哥. All rights reserved. +// + +#import "MJRefreshAutoFooter.h" + +@interface MJRefreshAutoFooter() +@end + +@implementation MJRefreshAutoFooter + +#pragma mark - 初始化 +- (void)willMoveToSuperview:(UIView *)newSuperview +{ + [super willMoveToSuperview:newSuperview]; + + if (newSuperview) { // 新的父控件 + if (self.hidden == NO) { + self.scrollView.mj_insetB += self.mj_h; + } + + // 设置位置 + self.mj_y = _scrollView.mj_contentH; + } else { // 被移除了 + if (self.hidden == NO) { + self.scrollView.mj_insetB -= self.mj_h; + } + } +} + +#pragma mark - 过期方法 +- (void)setAppearencePercentTriggerAutoRefresh:(CGFloat)appearencePercentTriggerAutoRefresh +{ + self.triggerAutomaticallyRefreshPercent = appearencePercentTriggerAutoRefresh; +} + +- (CGFloat)appearencePercentTriggerAutoRefresh +{ + return self.triggerAutomaticallyRefreshPercent; +} + +#pragma mark - 实现父类的方法 +- (void)prepare +{ + [super prepare]; + + // 默认底部控件100%出现时才会自动刷新 + self.triggerAutomaticallyRefreshPercent = 1.0; + + // 设置为默认状态 + self.automaticallyRefresh = YES; +} + +- (void)scrollViewContentSizeDidChange:(NSDictionary *)change +{ + [super scrollViewContentSizeDidChange:change]; + + // 设置位置 + self.mj_y = self.scrollView.mj_contentH; +} + +- (void)scrollViewContentOffsetDidChange:(NSDictionary *)change +{ + [super scrollViewContentOffsetDidChange:change]; + + if (self.state != MJRefreshStateIdle || !self.automaticallyRefresh || self.mj_y == 0) return; + + if (_scrollView.mj_insetT + _scrollView.mj_contentH > _scrollView.mj_h) { // 内容超过一个屏幕 + // 这里的_scrollView.mj_contentH替换掉self.mj_y更为合理 + if (_scrollView.mj_offsetY >= _scrollView.mj_contentH - _scrollView.mj_h + self.mj_h * self.triggerAutomaticallyRefreshPercent + _scrollView.mj_insetB - self.mj_h) { + // 防止手松开时连续调用 + CGPoint old = [change[@"old"] CGPointValue]; + CGPoint new = [change[@"new"] CGPointValue]; + if (new.y <= old.y) return; + + // 当底部刷新控件完全出现时,才刷新 + [self beginRefreshing]; + } + } +} + +- (void)scrollViewPanStateDidChange:(NSDictionary *)change +{ + [super scrollViewPanStateDidChange:change]; + + if (self.state != MJRefreshStateIdle) return; + + if (_scrollView.panGestureRecognizer.state == UIGestureRecognizerStateEnded) {// 手松开 + if (_scrollView.mj_insetT + _scrollView.mj_contentH <= _scrollView.mj_h) { // 不够一个屏幕 + if (_scrollView.mj_offsetY >= - _scrollView.mj_insetT) { // 向上拽 + [self beginRefreshing]; + } + } else { // 超出一个屏幕 + if (_scrollView.mj_offsetY >= _scrollView.mj_contentH + _scrollView.mj_insetB - _scrollView.mj_h) { + [self beginRefreshing]; + } + } + } +} + +- (void)setState:(MJRefreshState)state +{ + MJRefreshCheckState + + if (state == MJRefreshStateRefreshing) { + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + [self executeRefreshingCallback]; + }); + } else if (state == MJRefreshStateNoMoreData || state == MJRefreshStateIdle) { + if (MJRefreshStateRefreshing == oldState) { + if (self.endRefreshingCompletionBlock) { + self.endRefreshingCompletionBlock(); + } + } + } +} + +- (void)setHidden:(BOOL)hidden +{ + BOOL lastHidden = self.isHidden; + + [super setHidden:hidden]; + + if (!lastHidden && hidden) { + self.state = MJRefreshStateIdle; + + self.scrollView.mj_insetB -= self.mj_h; + } else if (lastHidden && !hidden) { + self.scrollView.mj_insetB += self.mj_h; + + // 设置位置 + self.mj_y = _scrollView.mj_contentH; + } +} +@end diff --git a/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Base/MJRefreshBackFooter.h b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Base/MJRefreshBackFooter.h new file mode 100644 index 00000000..347083cf --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Base/MJRefreshBackFooter.h @@ -0,0 +1,13 @@ +// +// MJRefreshBackFooter.h +// MJRefreshExample +// +// Created by MJ Lee on 15/4/24. +// Copyright (c) 2015年 小码哥. All rights reserved. +// + +#import "MJRefreshFooter.h" + +@interface MJRefreshBackFooter : MJRefreshFooter + +@end diff --git a/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Base/MJRefreshBackFooter.m b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Base/MJRefreshBackFooter.m new file mode 100644 index 00000000..83978adc --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Base/MJRefreshBackFooter.m @@ -0,0 +1,160 @@ +// +// MJRefreshBackFooter.m +// MJRefreshExample +// +// Created by MJ Lee on 15/4/24. +// Copyright (c) 2015年 小码哥. All rights reserved. +// + +#import "MJRefreshBackFooter.h" + +@interface MJRefreshBackFooter() +@property (assign, nonatomic) NSInteger lastRefreshCount; +@property (assign, nonatomic) CGFloat lastBottomDelta; +@end + +@implementation MJRefreshBackFooter + +#pragma mark - 初始化 +- (void)willMoveToSuperview:(UIView *)newSuperview +{ + [super willMoveToSuperview:newSuperview]; + + [self scrollViewContentSizeDidChange:nil]; +} + +#pragma mark - 实现父类的方法 +- (void)scrollViewContentOffsetDidChange:(NSDictionary *)change +{ + [super scrollViewContentOffsetDidChange:change]; + + // 如果正在刷新,直接返回 + if (self.state == MJRefreshStateRefreshing) return; + + _scrollViewOriginalInset = self.scrollView.contentInset; + + // 当前的contentOffset + CGFloat currentOffsetY = self.scrollView.mj_offsetY; + // 尾部控件刚好出现的offsetY + CGFloat happenOffsetY = [self happenOffsetY]; + // 如果是向下滚动到看不见尾部控件,直接返回 + if (currentOffsetY <= happenOffsetY) return; + + CGFloat pullingPercent = (currentOffsetY - happenOffsetY) / self.mj_h; + + // 如果已全部加载,仅设置pullingPercent,然后返回 + if (self.state == MJRefreshStateNoMoreData) { + self.pullingPercent = pullingPercent; + return; + } + + if (self.scrollView.isDragging) { + self.pullingPercent = pullingPercent; + // 普通 和 即将刷新 的临界点 + CGFloat normal2pullingOffsetY = happenOffsetY + self.mj_h; + + if (self.state == MJRefreshStateIdle && currentOffsetY > normal2pullingOffsetY) { + // 转为即将刷新状态 + self.state = MJRefreshStatePulling; + } else if (self.state == MJRefreshStatePulling && currentOffsetY <= normal2pullingOffsetY) { + // 转为普通状态 + self.state = MJRefreshStateIdle; + } + } else if (self.state == MJRefreshStatePulling) {// 即将刷新 && 手松开 + // 开始刷新 + [self beginRefreshing]; + } else if (pullingPercent < 1) { + self.pullingPercent = pullingPercent; + } +} + +- (void)scrollViewContentSizeDidChange:(NSDictionary *)change +{ + [super scrollViewContentSizeDidChange:change]; + + // 内容的高度 + CGFloat contentHeight = self.scrollView.mj_contentH + self.ignoredScrollViewContentInsetBottom; + // 表格的高度 + CGFloat scrollHeight = self.scrollView.mj_h - self.scrollViewOriginalInset.top - self.scrollViewOriginalInset.bottom + self.ignoredScrollViewContentInsetBottom; + // 设置位置和尺寸 + self.mj_y = MAX(contentHeight, scrollHeight); +} + +- (void)setState:(MJRefreshState)state +{ + MJRefreshCheckState + + // 根据状态来设置属性 + if (state == MJRefreshStateNoMoreData || state == MJRefreshStateIdle) { + // 刷新完毕 + if (MJRefreshStateRefreshing == oldState) { + [UIView animateWithDuration:MJRefreshSlowAnimationDuration animations:^{ + self.scrollView.mj_insetB -= self.lastBottomDelta; + + // 自动调整透明度 + if (self.isAutomaticallyChangeAlpha) self.alpha = 0.0; + } completion:^(BOOL finished) { + self.pullingPercent = 0.0; + + if (self.endRefreshingCompletionBlock) { + self.endRefreshingCompletionBlock(); + } + }]; + } + + CGFloat deltaH = [self heightForContentBreakView]; + // 刚刷新完毕 + if (MJRefreshStateRefreshing == oldState && deltaH > 0 && self.scrollView.mj_totalDataCount != self.lastRefreshCount) { + self.scrollView.mj_offsetY = self.scrollView.mj_offsetY; + } + } else if (state == MJRefreshStateRefreshing) { + // 记录刷新前的数量 + self.lastRefreshCount = self.scrollView.mj_totalDataCount; + + [UIView animateWithDuration:MJRefreshFastAnimationDuration animations:^{ + CGFloat bottom = self.mj_h + self.scrollViewOriginalInset.bottom; + CGFloat deltaH = [self heightForContentBreakView]; + if (deltaH < 0) { // 如果内容高度小于view的高度 + bottom -= deltaH; + } + self.lastBottomDelta = bottom - self.scrollView.mj_insetB; + self.scrollView.mj_insetB = bottom; + self.scrollView.mj_offsetY = [self happenOffsetY] + self.mj_h; + } completion:^(BOOL finished) { + [self executeRefreshingCallback]; + }]; + } +} + +- (void)endRefreshing +{ + dispatch_async(dispatch_get_main_queue(), ^{ + self.state = MJRefreshStateIdle; + }); +} + +- (void)endRefreshingWithNoMoreData +{ + dispatch_async(dispatch_get_main_queue(), ^{ + self.state = MJRefreshStateNoMoreData; + }); +} +#pragma mark - 私有方法 +#pragma mark 获得scrollView的内容 超出 view 的高度 +- (CGFloat)heightForContentBreakView +{ + CGFloat h = self.scrollView.frame.size.height - self.scrollViewOriginalInset.bottom - self.scrollViewOriginalInset.top; + return self.scrollView.contentSize.height - h; +} + +#pragma mark 刚好看到上拉刷新控件时的contentOffset.y +- (CGFloat)happenOffsetY +{ + CGFloat deltaH = [self heightForContentBreakView]; + if (deltaH > 0) { + return deltaH - self.scrollViewOriginalInset.top; + } else { + return - self.scrollViewOriginalInset.top; + } +} +@end diff --git a/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Base/MJRefreshComponent.h b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Base/MJRefreshComponent.h new file mode 100644 index 00000000..9e96c898 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Base/MJRefreshComponent.h @@ -0,0 +1,106 @@ +// 代码地址: https://github.com/CoderMJLee/MJRefresh +// 代码地址: http://code4app.com/ios/%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90%E4%B8%8B%E6%8B%89%E4%B8%8A%E6%8B%89%E5%88%B7%E6%96%B0/52326ce26803fabc46000000 +// MJRefreshComponent.h +// MJRefreshExample +// +// Created by MJ Lee on 15/3/4. +// Copyright (c) 2015年 小码哥. All rights reserved. +// 刷新控件的基类 + +#import +#import "MJRefreshConst.h" +#import "UIView+MJExtension.h" +#import "UIScrollView+MJExtension.h" +#import "UIScrollView+MJRefresh.h" +#import "NSBundle+MJRefresh.h" + +/** 刷新控件的状态 */ +typedef NS_ENUM(NSInteger, MJRefreshState) { + /** 普通闲置状态 */ + MJRefreshStateIdle = 1, + /** 松开就可以进行刷新的状态 */ + MJRefreshStatePulling, + /** 正在刷新中的状态 */ + MJRefreshStateRefreshing, + /** 即将刷新的状态 */ + MJRefreshStateWillRefresh, + /** 所有数据加载完毕,没有更多的数据了 */ + MJRefreshStateNoMoreData +}; + +/** 进入刷新状态的回调 */ +typedef void (^MJRefreshComponentRefreshingBlock)(); +/** 开始刷新后的回调(进入刷新状态后的回调) */ +typedef void (^MJRefreshComponentbeginRefreshingCompletionBlock)(); +/** 结束刷新后的回调 */ +typedef void (^MJRefreshComponentEndRefreshingCompletionBlock)(); + +/** 刷新控件的基类 */ +@interface MJRefreshComponent : UIView +{ + /** 记录scrollView刚开始的inset */ + UIEdgeInsets _scrollViewOriginalInset; + /** 父控件 */ + __weak UIScrollView *_scrollView; +} +#pragma mark - 刷新回调 +/** 正在刷新的回调 */ +@property (copy, nonatomic) MJRefreshComponentRefreshingBlock refreshingBlock; +/** 设置回调对象和回调方法 */ +- (void)setRefreshingTarget:(id)target refreshingAction:(SEL)action; + +/** 回调对象 */ +@property (weak, nonatomic) id refreshingTarget; +/** 回调方法 */ +@property (assign, nonatomic) SEL refreshingAction; +/** 触发回调(交给子类去调用) */ +- (void)executeRefreshingCallback; + +#pragma mark - 刷新状态控制 +/** 进入刷新状态 */ +- (void)beginRefreshing; +- (void)beginRefreshingWithCompletionBlock:(void (^)())completionBlock; +/** 开始刷新后的回调(进入刷新状态后的回调) */ +@property (copy, nonatomic) MJRefreshComponentbeginRefreshingCompletionBlock beginRefreshingCompletionBlock; +/** 结束刷新的回调 */ +@property (copy, nonatomic) MJRefreshComponentEndRefreshingCompletionBlock endRefreshingCompletionBlock; +/** 结束刷新状态 */ +- (void)endRefreshing; +- (void)endRefreshingWithCompletionBlock:(void (^)())completionBlock; +/** 是否正在刷新 */ +- (BOOL)isRefreshing; +/** 刷新状态 一般交给子类内部实现 */ +@property (assign, nonatomic) MJRefreshState state; + +#pragma mark - 交给子类去访问 +/** 记录scrollView刚开始的inset */ +@property (assign, nonatomic, readonly) UIEdgeInsets scrollViewOriginalInset; +/** 父控件 */ +@property (weak, nonatomic, readonly) UIScrollView *scrollView; + +#pragma mark - 交给子类们去实现 +/** 初始化 */ +- (void)prepare NS_REQUIRES_SUPER; +/** 摆放子控件frame */ +- (void)placeSubviews NS_REQUIRES_SUPER; +/** 当scrollView的contentOffset发生改变的时候调用 */ +- (void)scrollViewContentOffsetDidChange:(NSDictionary *)change NS_REQUIRES_SUPER; +/** 当scrollView的contentSize发生改变的时候调用 */ +- (void)scrollViewContentSizeDidChange:(NSDictionary *)change NS_REQUIRES_SUPER; +/** 当scrollView的拖拽状态发生改变的时候调用 */ +- (void)scrollViewPanStateDidChange:(NSDictionary *)change NS_REQUIRES_SUPER; + + +#pragma mark - 其他 +/** 拉拽的百分比(交给子类重写) */ +@property (assign, nonatomic) CGFloat pullingPercent; +/** 根据拖拽比例自动切换透明度 */ +@property (assign, nonatomic, getter=isAutoChangeAlpha) BOOL autoChangeAlpha MJRefreshDeprecated("请使用automaticallyChangeAlpha属性"); +/** 根据拖拽比例自动切换透明度 */ +@property (assign, nonatomic, getter=isAutomaticallyChangeAlpha) BOOL automaticallyChangeAlpha; +@end + +@interface UILabel(MJRefresh) ++ (instancetype)mj_label; +- (CGFloat)mj_textWith; +@end diff --git a/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Base/MJRefreshComponent.m b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Base/MJRefreshComponent.m new file mode 100644 index 00000000..fec5ed7f --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Base/MJRefreshComponent.m @@ -0,0 +1,274 @@ +// 代码地址: https://github.com/CoderMJLee/MJRefresh +// 代码地址: http://code4app.com/ios/%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90%E4%B8%8B%E6%8B%89%E4%B8%8A%E6%8B%89%E5%88%B7%E6%96%B0/52326ce26803fabc46000000 +// MJRefreshComponent.m +// MJRefreshExample +// +// Created by MJ Lee on 15/3/4. +// Copyright (c) 2015年 小码哥. All rights reserved. +// + +#import "MJRefreshComponent.h" +#import "MJRefreshConst.h" + +@interface MJRefreshComponent() +@property (strong, nonatomic) UIPanGestureRecognizer *pan; +@end + +@implementation MJRefreshComponent +#pragma mark - 初始化 +- (instancetype)initWithFrame:(CGRect)frame +{ + if (self = [super initWithFrame:frame]) { + // 准备工作 + [self prepare]; + + // 默认是普通状态 + self.state = MJRefreshStateIdle; + } + return self; +} + +- (void)prepare +{ + // 基本属性 + self.autoresizingMask = UIViewAutoresizingFlexibleWidth; + self.backgroundColor = [UIColor clearColor]; +} + +- (void)layoutSubviews +{ + [self placeSubviews]; + + [super layoutSubviews]; +} + +- (void)placeSubviews{} + +- (void)willMoveToSuperview:(UIView *)newSuperview +{ + [super willMoveToSuperview:newSuperview]; + + // 如果不是UIScrollView,不做任何事情 + if (newSuperview && ![newSuperview isKindOfClass:[UIScrollView class]]) return; + + // 旧的父控件移除监听 + [self removeObservers]; + + if (newSuperview) { // 新的父控件 + // 设置宽度 + self.mj_w = newSuperview.mj_w; + // 设置位置 + self.mj_x = 0; + + // 记录UIScrollView + _scrollView = (UIScrollView *)newSuperview; + // 设置永远支持垂直弹簧效果 + _scrollView.alwaysBounceVertical = YES; + // 记录UIScrollView最开始的contentInset + _scrollViewOriginalInset = _scrollView.contentInset; + + // 添加监听 + [self addObservers]; + } +} + +- (void)drawRect:(CGRect)rect +{ + [super drawRect:rect]; + + if (self.state == MJRefreshStateWillRefresh) { + // 预防view还没显示出来就调用了beginRefreshing + self.state = MJRefreshStateRefreshing; + } +} + +#pragma mark - KVO监听 +- (void)addObservers +{ + NSKeyValueObservingOptions options = NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld; + [self.scrollView addObserver:self forKeyPath:MJRefreshKeyPathContentOffset options:options context:nil]; + [self.scrollView addObserver:self forKeyPath:MJRefreshKeyPathContentSize options:options context:nil]; + self.pan = self.scrollView.panGestureRecognizer; + [self.pan addObserver:self forKeyPath:MJRefreshKeyPathPanState options:options context:nil]; +} + +- (void)removeObservers +{ + [self.superview removeObserver:self forKeyPath:MJRefreshKeyPathContentOffset]; + [self.superview removeObserver:self forKeyPath:MJRefreshKeyPathContentSize];; + [self.pan removeObserver:self forKeyPath:MJRefreshKeyPathPanState]; + self.pan = nil; +} + +- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context +{ + // 遇到这些情况就直接返回 + if (!self.userInteractionEnabled) return; + + // 这个就算看不见也需要处理 + if ([keyPath isEqualToString:MJRefreshKeyPathContentSize]) { + [self scrollViewContentSizeDidChange:change]; + } + + // 看不见 + if (self.hidden) return; + if ([keyPath isEqualToString:MJRefreshKeyPathContentOffset]) { + [self scrollViewContentOffsetDidChange:change]; + } else if ([keyPath isEqualToString:MJRefreshKeyPathPanState]) { + [self scrollViewPanStateDidChange:change]; + } +} + +- (void)scrollViewContentOffsetDidChange:(NSDictionary *)change{} +- (void)scrollViewContentSizeDidChange:(NSDictionary *)change{} +- (void)scrollViewPanStateDidChange:(NSDictionary *)change{} + +#pragma mark - 公共方法 +#pragma mark 设置回调对象和回调方法 +- (void)setRefreshingTarget:(id)target refreshingAction:(SEL)action +{ + self.refreshingTarget = target; + self.refreshingAction = action; +} + +- (void)setState:(MJRefreshState)state +{ + _state = state; + + // 加入主队列的目的是等setState:方法调用完毕、设置完文字后再去布局子控件 + dispatch_async(dispatch_get_main_queue(), ^{ + [self setNeedsLayout]; + }); +} + +#pragma mark 进入刷新状态 +- (void)beginRefreshing +{ + [UIView animateWithDuration:MJRefreshFastAnimationDuration animations:^{ + self.alpha = 1.0; + }]; + self.pullingPercent = 1.0; + // 只要正在刷新,就完全显示 + if (self.window) { + self.state = MJRefreshStateRefreshing; + } else { + // 预防正在刷新中时,调用本方法使得header inset回置失败 + if (self.state != MJRefreshStateRefreshing) { + self.state = MJRefreshStateWillRefresh; + // 刷新(预防从另一个控制器回到这个控制器的情况,回来要重新刷新一下) + [self setNeedsDisplay]; + } + } +} + +- (void)beginRefreshingWithCompletionBlock:(void (^)())completionBlock +{ + self.beginRefreshingCompletionBlock = completionBlock; + + [self beginRefreshing]; +} + +#pragma mark 结束刷新状态 +- (void)endRefreshing +{ + self.state = MJRefreshStateIdle; +} + +- (void)endRefreshingWithCompletionBlock:(void (^)())completionBlock +{ + self.endRefreshingCompletionBlock = completionBlock; + + [self endRefreshing]; +} + +#pragma mark 是否正在刷新 +- (BOOL)isRefreshing +{ + return self.state == MJRefreshStateRefreshing || self.state == MJRefreshStateWillRefresh; +} + +#pragma mark 自动切换透明度 +- (void)setAutoChangeAlpha:(BOOL)autoChangeAlpha +{ + self.automaticallyChangeAlpha = autoChangeAlpha; +} + +- (BOOL)isAutoChangeAlpha +{ + return self.isAutomaticallyChangeAlpha; +} + +- (void)setAutomaticallyChangeAlpha:(BOOL)automaticallyChangeAlpha +{ + _automaticallyChangeAlpha = automaticallyChangeAlpha; + + if (self.isRefreshing) return; + + if (automaticallyChangeAlpha) { + self.alpha = self.pullingPercent; + } else { + self.alpha = 1.0; + } +} + +#pragma mark 根据拖拽进度设置透明度 +- (void)setPullingPercent:(CGFloat)pullingPercent +{ + _pullingPercent = pullingPercent; + + if (self.isRefreshing) return; + + if (self.isAutomaticallyChangeAlpha) { + self.alpha = pullingPercent; + } +} + +#pragma mark - 内部方法 +- (void)executeRefreshingCallback +{ + dispatch_async(dispatch_get_main_queue(), ^{ + if (self.refreshingBlock) { + self.refreshingBlock(); + } + if ([self.refreshingTarget respondsToSelector:self.refreshingAction]) { + MJRefreshMsgSend(MJRefreshMsgTarget(self.refreshingTarget), self.refreshingAction, self); + } + if (self.beginRefreshingCompletionBlock) { + self.beginRefreshingCompletionBlock(); + } + }); +} +@end + +@implementation UILabel(MJRefresh) ++ (instancetype)mj_label +{ + UILabel *label = [[self alloc] init]; + label.font = MJRefreshLabelFont; + label.textColor = MJRefreshLabelTextColor; + label.autoresizingMask = UIViewAutoresizingFlexibleWidth; + label.textAlignment = NSTextAlignmentCenter; + label.backgroundColor = [UIColor clearColor]; + return label; +} + +- (CGFloat)mj_textWith { + CGFloat stringWidth = 0; + CGSize size = CGSizeMake(MAXFLOAT, MAXFLOAT); + if (self.text.length > 0) { +#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000 + stringWidth =[self.text + boundingRectWithSize:size + options:NSStringDrawingUsesLineFragmentOrigin + attributes:@{NSFontAttributeName:self.font} + context:nil].size.width; +#else + + stringWidth = [self.text sizeWithFont:self.font + constrainedToSize:size + lineBreakMode:NSLineBreakByCharWrapping].width; +#endif + } + return stringWidth; +} +@end \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Base/MJRefreshFooter.h b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Base/MJRefreshFooter.h new file mode 100644 index 00000000..22d23e52 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Base/MJRefreshFooter.h @@ -0,0 +1,30 @@ +// 代码地址: https://github.com/CoderMJLee/MJRefresh +// 代码地址: http://code4app.com/ios/%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90%E4%B8%8B%E6%8B%89%E4%B8%8A%E6%8B%89%E5%88%B7%E6%96%B0/52326ce26803fabc46000000 +// MJRefreshFooter.h +// MJRefreshExample +// +// Created by MJ Lee on 15/3/5. +// Copyright (c) 2015年 小码哥. All rights reserved. +// 上拉刷新控件 + +#import "MJRefreshComponent.h" + +@interface MJRefreshFooter : MJRefreshComponent +/** 创建footer */ ++ (instancetype)footerWithRefreshingBlock:(MJRefreshComponentRefreshingBlock)refreshingBlock; +/** 创建footer */ ++ (instancetype)footerWithRefreshingTarget:(id)target refreshingAction:(SEL)action; + +/** 提示没有更多的数据 */ +- (void)endRefreshingWithNoMoreData; +- (void)noticeNoMoreData MJRefreshDeprecated("使用endRefreshingWithNoMoreData"); + +/** 重置没有更多的数据(消除没有更多数据的状态) */ +- (void)resetNoMoreData; + +/** 忽略多少scrollView的contentInset的bottom */ +@property (assign, nonatomic) CGFloat ignoredScrollViewContentInsetBottom; + +/** 自动根据有无数据来显示和隐藏(有数据就显示,没有数据隐藏。默认是NO) */ +@property (assign, nonatomic, getter=isAutomaticallyHidden) BOOL automaticallyHidden; +@end diff --git a/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Base/MJRefreshFooter.m b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Base/MJRefreshFooter.m new file mode 100644 index 00000000..69f65e7d --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Base/MJRefreshFooter.m @@ -0,0 +1,74 @@ +// 代码地址: https://github.com/CoderMJLee/MJRefresh +// 代码地址: http://code4app.com/ios/%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90%E4%B8%8B%E6%8B%89%E4%B8%8A%E6%8B%89%E5%88%B7%E6%96%B0/52326ce26803fabc46000000 +// MJRefreshFooter.m +// MJRefreshExample +// +// Created by MJ Lee on 15/3/5. +// Copyright (c) 2015年 小码哥. All rights reserved. +// + +#import "MJRefreshFooter.h" + +@interface MJRefreshFooter() + +@end + +@implementation MJRefreshFooter +#pragma mark - 构造方法 ++ (instancetype)footerWithRefreshingBlock:(MJRefreshComponentRefreshingBlock)refreshingBlock +{ + MJRefreshFooter *cmp = [[self alloc] init]; + cmp.refreshingBlock = refreshingBlock; + return cmp; +} ++ (instancetype)footerWithRefreshingTarget:(id)target refreshingAction:(SEL)action +{ + MJRefreshFooter *cmp = [[self alloc] init]; + [cmp setRefreshingTarget:target refreshingAction:action]; + return cmp; +} + +#pragma mark - 重写父类的方法 +- (void)prepare +{ + [super prepare]; + + // 设置自己的高度 + self.mj_h = MJRefreshFooterHeight; + + // 默认不会自动隐藏 + self.automaticallyHidden = NO; +} + +- (void)willMoveToSuperview:(UIView *)newSuperview +{ + [super willMoveToSuperview:newSuperview]; + + if (newSuperview) { + // 监听scrollView数据的变化 + if ([self.scrollView isKindOfClass:[UITableView class]] || [self.scrollView isKindOfClass:[UICollectionView class]]) { + [self.scrollView setMj_reloadDataBlock:^(NSInteger totalDataCount) { + if (self.isAutomaticallyHidden) { + self.hidden = (totalDataCount == 0); + } + }]; + } + } +} + +#pragma mark - 公共方法 +- (void)endRefreshingWithNoMoreData +{ + self.state = MJRefreshStateNoMoreData; +} + +- (void)noticeNoMoreData +{ + [self endRefreshingWithNoMoreData]; +} + +- (void)resetNoMoreData +{ + self.state = MJRefreshStateIdle; +} +@end diff --git a/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Base/MJRefreshHeader.h b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Base/MJRefreshHeader.h new file mode 100644 index 00000000..08160245 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Base/MJRefreshHeader.h @@ -0,0 +1,25 @@ +// 代码地址: https://github.com/CoderMJLee/MJRefresh +// 代码地址: http://code4app.com/ios/%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90%E4%B8%8B%E6%8B%89%E4%B8%8A%E6%8B%89%E5%88%B7%E6%96%B0/52326ce26803fabc46000000 +// MJRefreshHeader.h +// MJRefreshExample +// +// Created by MJ Lee on 15/3/4. +// Copyright (c) 2015年 小码哥. All rights reserved. +// 下拉刷新控件:负责监控用户下拉的状态 + +#import "MJRefreshComponent.h" + +@interface MJRefreshHeader : MJRefreshComponent +/** 创建header */ ++ (instancetype)headerWithRefreshingBlock:(MJRefreshComponentRefreshingBlock)refreshingBlock; +/** 创建header */ ++ (instancetype)headerWithRefreshingTarget:(id)target refreshingAction:(SEL)action; + +/** 这个key用来存储上一次下拉刷新成功的时间 */ +@property (copy, nonatomic) NSString *lastUpdatedTimeKey; +/** 上一次下拉刷新成功的时间 */ +@property (strong, nonatomic, readonly) NSDate *lastUpdatedTime; + +/** 忽略多少scrollView的contentInset的top */ +@property (assign, nonatomic) CGFloat ignoredScrollViewContentInsetTop; +@end diff --git a/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Base/MJRefreshHeader.m b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Base/MJRefreshHeader.m new file mode 100644 index 00000000..070cea6c --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Base/MJRefreshHeader.m @@ -0,0 +1,153 @@ +// 代码地址: https://github.com/CoderMJLee/MJRefresh +// 代码地址: http://code4app.com/ios/%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90%E4%B8%8B%E6%8B%89%E4%B8%8A%E6%8B%89%E5%88%B7%E6%96%B0/52326ce26803fabc46000000 +// MJRefreshHeader.m +// MJRefreshExample +// +// Created by MJ Lee on 15/3/4. +// Copyright (c) 2015年 小码哥. All rights reserved. +// + +#import "MJRefreshHeader.h" + +@interface MJRefreshHeader() +@property (assign, nonatomic) CGFloat insetTDelta; +@end + +@implementation MJRefreshHeader +#pragma mark - 构造方法 ++ (instancetype)headerWithRefreshingBlock:(MJRefreshComponentRefreshingBlock)refreshingBlock +{ + MJRefreshHeader *cmp = [[self alloc] init]; + cmp.refreshingBlock = refreshingBlock; + return cmp; +} ++ (instancetype)headerWithRefreshingTarget:(id)target refreshingAction:(SEL)action +{ + MJRefreshHeader *cmp = [[self alloc] init]; + [cmp setRefreshingTarget:target refreshingAction:action]; + return cmp; +} + +#pragma mark - 覆盖父类的方法 +- (void)prepare +{ + [super prepare]; + + // 设置key + self.lastUpdatedTimeKey = MJRefreshHeaderLastUpdatedTimeKey; + + // 设置高度 + self.mj_h = MJRefreshHeaderHeight; +} + +- (void)placeSubviews +{ + [super placeSubviews]; + + // 设置y值(当自己的高度发生改变了,肯定要重新调整Y值,所以放到placeSubviews方法中设置y值) + self.mj_y = - self.mj_h - self.ignoredScrollViewContentInsetTop; +} + +- (void)scrollViewContentOffsetDidChange:(NSDictionary *)change +{ + [super scrollViewContentOffsetDidChange:change]; + + // 在刷新的refreshing状态 + if (self.state == MJRefreshStateRefreshing) { + if (self.window == nil) return; + + // sectionheader停留解决 + CGFloat insetT = - self.scrollView.mj_offsetY > _scrollViewOriginalInset.top ? - self.scrollView.mj_offsetY : _scrollViewOriginalInset.top; + insetT = insetT > self.mj_h + _scrollViewOriginalInset.top ? self.mj_h + _scrollViewOriginalInset.top : insetT; + self.scrollView.mj_insetT = insetT; + + self.insetTDelta = _scrollViewOriginalInset.top - insetT; + return; + } + + // 跳转到下一个控制器时,contentInset可能会变 + _scrollViewOriginalInset = self.scrollView.contentInset; + + // 当前的contentOffset + CGFloat offsetY = self.scrollView.mj_offsetY; + // 头部控件刚好出现的offsetY + CGFloat happenOffsetY = - self.scrollViewOriginalInset.top; + + // 如果是向上滚动到看不见头部控件,直接返回 + // >= -> > + if (offsetY > happenOffsetY) return; + + // 普通 和 即将刷新 的临界点 + CGFloat normal2pullingOffsetY = happenOffsetY - self.mj_h; + CGFloat pullingPercent = (happenOffsetY - offsetY) / self.mj_h; + + if (self.scrollView.isDragging) { // 如果正在拖拽 + self.pullingPercent = pullingPercent; + if (self.state == MJRefreshStateIdle && offsetY < normal2pullingOffsetY) { + // 转为即将刷新状态 + self.state = MJRefreshStatePulling; + } else if (self.state == MJRefreshStatePulling && offsetY >= normal2pullingOffsetY) { + // 转为普通状态 + self.state = MJRefreshStateIdle; + } + } else if (self.state == MJRefreshStatePulling) {// 即将刷新 && 手松开 + // 开始刷新 + [self beginRefreshing]; + } else if (pullingPercent < 1) { + self.pullingPercent = pullingPercent; + } +} + +- (void)setState:(MJRefreshState)state +{ + MJRefreshCheckState + + // 根据状态做事情 + if (state == MJRefreshStateIdle) { + if (oldState != MJRefreshStateRefreshing) return; + + // 保存刷新时间 + [[NSUserDefaults standardUserDefaults] setObject:[NSDate date] forKey:self.lastUpdatedTimeKey]; + [[NSUserDefaults standardUserDefaults] synchronize]; + + // 恢复inset和offset + [UIView animateWithDuration:MJRefreshSlowAnimationDuration animations:^{ + self.scrollView.mj_insetT += self.insetTDelta; + + // 自动调整透明度 + if (self.isAutomaticallyChangeAlpha) self.alpha = 0.0; + } completion:^(BOOL finished) { + self.pullingPercent = 0.0; + + if (self.endRefreshingCompletionBlock) { + self.endRefreshingCompletionBlock(); + } + }]; + } else if (state == MJRefreshStateRefreshing) { + dispatch_async(dispatch_get_main_queue(), ^{ + [UIView animateWithDuration:MJRefreshFastAnimationDuration animations:^{ + CGFloat top = self.scrollViewOriginalInset.top + self.mj_h; + // 增加滚动区域top + self.scrollView.mj_insetT = top; + // 设置滚动位置 + [self.scrollView setContentOffset:CGPointMake(0, -top) animated:NO]; + } completion:^(BOOL finished) { + [self executeRefreshingCallback]; + }]; + }); + } +} + +#pragma mark - 公共方法 +- (void)endRefreshing +{ + dispatch_async(dispatch_get_main_queue(), ^{ + self.state = MJRefreshStateIdle; + }); +} + +- (NSDate *)lastUpdatedTime +{ + return [[NSUserDefaults standardUserDefaults] objectForKey:self.lastUpdatedTimeKey]; +} +@end diff --git a/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Custom/Footer/Auto/MJRefreshAutoGifFooter.h b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Custom/Footer/Auto/MJRefreshAutoGifFooter.h new file mode 100644 index 00000000..6a127e6c --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Custom/Footer/Auto/MJRefreshAutoGifFooter.h @@ -0,0 +1,17 @@ +// +// MJRefreshAutoGifFooter.h +// MJRefreshExample +// +// Created by MJ Lee on 15/4/24. +// Copyright (c) 2015年 小码哥. All rights reserved. +// + +#import "MJRefreshAutoStateFooter.h" + +@interface MJRefreshAutoGifFooter : MJRefreshAutoStateFooter +@property (weak, nonatomic, readonly) UIImageView *gifView; + +/** 设置state状态下的动画图片images 动画持续时间duration*/ +- (void)setImages:(NSArray *)images duration:(NSTimeInterval)duration forState:(MJRefreshState)state; +- (void)setImages:(NSArray *)images forState:(MJRefreshState)state; +@end diff --git a/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Custom/Footer/Auto/MJRefreshAutoGifFooter.m b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Custom/Footer/Auto/MJRefreshAutoGifFooter.m new file mode 100644 index 00000000..25071381 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Custom/Footer/Auto/MJRefreshAutoGifFooter.m @@ -0,0 +1,116 @@ +// +// MJRefreshAutoGifFooter.m +// MJRefreshExample +// +// Created by MJ Lee on 15/4/24. +// Copyright (c) 2015年 小码哥. All rights reserved. +// + +#import "MJRefreshAutoGifFooter.h" + +@interface MJRefreshAutoGifFooter() +{ + __unsafe_unretained UIImageView *_gifView; +} +/** 所有状态对应的动画图片 */ +@property (strong, nonatomic) NSMutableDictionary *stateImages; +/** 所有状态对应的动画时间 */ +@property (strong, nonatomic) NSMutableDictionary *stateDurations; +@end + +@implementation MJRefreshAutoGifFooter +#pragma mark - 懒加载 +- (UIImageView *)gifView +{ + if (!_gifView) { + UIImageView *gifView = [[UIImageView alloc] init]; + [self addSubview:_gifView = gifView]; + } + return _gifView; +} + +- (NSMutableDictionary *)stateImages +{ + if (!_stateImages) { + self.stateImages = [NSMutableDictionary dictionary]; + } + return _stateImages; +} + +- (NSMutableDictionary *)stateDurations +{ + if (!_stateDurations) { + self.stateDurations = [NSMutableDictionary dictionary]; + } + return _stateDurations; +} + +#pragma mark - 公共方法 +- (void)setImages:(NSArray *)images duration:(NSTimeInterval)duration forState:(MJRefreshState)state +{ + if (images == nil) return; + + self.stateImages[@(state)] = images; + self.stateDurations[@(state)] = @(duration); + + /* 根据图片设置控件的高度 */ + UIImage *image = [images firstObject]; + if (image.size.height > self.mj_h) { + self.mj_h = image.size.height; + } +} + +- (void)setImages:(NSArray *)images forState:(MJRefreshState)state +{ + [self setImages:images duration:images.count * 0.1 forState:state]; +} + +#pragma mark - 实现父类的方法 +- (void)prepare +{ + [super prepare]; + + // 初始化间距 + self.labelLeftInset = 20; +} + +- (void)placeSubviews +{ + [super placeSubviews]; + + if (self.gifView.constraints.count) return; + + self.gifView.frame = self.bounds; + if (self.isRefreshingTitleHidden) { + self.gifView.contentMode = UIViewContentModeCenter; + } else { + self.gifView.contentMode = UIViewContentModeRight; + self.gifView.mj_w = self.mj_w * 0.5 - self.labelLeftInset - self.stateLabel.mj_textWith * 0.5; + } +} + +- (void)setState:(MJRefreshState)state +{ + MJRefreshCheckState + + // 根据状态做事情 + if (state == MJRefreshStateRefreshing) { + NSArray *images = self.stateImages[@(state)]; + if (images.count == 0) return; + [self.gifView stopAnimating]; + + self.gifView.hidden = NO; + if (images.count == 1) { // 单张图片 + self.gifView.image = [images lastObject]; + } else { // 多张图片 + self.gifView.animationImages = images; + self.gifView.animationDuration = [self.stateDurations[@(state)] doubleValue]; + [self.gifView startAnimating]; + } + } else if (state == MJRefreshStateNoMoreData || state == MJRefreshStateIdle) { + [self.gifView stopAnimating]; + self.gifView.hidden = YES; + } +} +@end + diff --git a/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Custom/Footer/Auto/MJRefreshAutoNormalFooter.h b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Custom/Footer/Auto/MJRefreshAutoNormalFooter.h new file mode 100644 index 00000000..5549cff5 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Custom/Footer/Auto/MJRefreshAutoNormalFooter.h @@ -0,0 +1,14 @@ +// +// MJRefreshAutoNormalFooter.h +// MJRefreshExample +// +// Created by MJ Lee on 15/4/24. +// Copyright (c) 2015年 小码哥. All rights reserved. +// + +#import "MJRefreshAutoStateFooter.h" + +@interface MJRefreshAutoNormalFooter : MJRefreshAutoStateFooter +/** 菊花的样式 */ +@property (assign, nonatomic) UIActivityIndicatorViewStyle activityIndicatorViewStyle; +@end diff --git a/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Custom/Footer/Auto/MJRefreshAutoNormalFooter.m b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Custom/Footer/Auto/MJRefreshAutoNormalFooter.m new file mode 100644 index 00000000..dae90606 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Custom/Footer/Auto/MJRefreshAutoNormalFooter.m @@ -0,0 +1,69 @@ +// +// MJRefreshAutoNormalFooter.m +// MJRefreshExample +// +// Created by MJ Lee on 15/4/24. +// Copyright (c) 2015年 小码哥. All rights reserved. +// + +#import "MJRefreshAutoNormalFooter.h" + +@interface MJRefreshAutoNormalFooter() +@property (weak, nonatomic) UIActivityIndicatorView *loadingView; +@end + +@implementation MJRefreshAutoNormalFooter +#pragma mark - 懒加载子控件 +- (UIActivityIndicatorView *)loadingView +{ + if (!_loadingView) { + UIActivityIndicatorView *loadingView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:self.activityIndicatorViewStyle]; + loadingView.hidesWhenStopped = YES; + [self addSubview:_loadingView = loadingView]; + } + return _loadingView; +} + +- (void)setActivityIndicatorViewStyle:(UIActivityIndicatorViewStyle)activityIndicatorViewStyle +{ + _activityIndicatorViewStyle = activityIndicatorViewStyle; + + self.loadingView = nil; + [self setNeedsLayout]; +} +#pragma mark - 重写父类的方法 +- (void)prepare +{ + [super prepare]; + + self.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray; +} + +- (void)placeSubviews +{ + [super placeSubviews]; + + if (self.loadingView.constraints.count) return; + + // 圈圈 + CGFloat loadingCenterX = self.mj_w * 0.5; + if (!self.isRefreshingTitleHidden) { + loadingCenterX -= self.stateLabel.mj_textWith * 0.5 + self.labelLeftInset; + } + CGFloat loadingCenterY = self.mj_h * 0.5; + self.loadingView.center = CGPointMake(loadingCenterX, loadingCenterY); +} + +- (void)setState:(MJRefreshState)state +{ + MJRefreshCheckState + + // 根据状态做事情 + if (state == MJRefreshStateNoMoreData || state == MJRefreshStateIdle) { + [self.loadingView stopAnimating]; + } else if (state == MJRefreshStateRefreshing) { + [self.loadingView startAnimating]; + } +} + +@end diff --git a/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Custom/Footer/Auto/MJRefreshAutoStateFooter.h b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Custom/Footer/Auto/MJRefreshAutoStateFooter.h new file mode 100644 index 00000000..9fe7915b --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Custom/Footer/Auto/MJRefreshAutoStateFooter.h @@ -0,0 +1,22 @@ +// +// MJRefreshAutoStateFooter.h +// MJRefreshExample +// +// Created by MJ Lee on 15/6/13. +// Copyright © 2015年 小码哥. All rights reserved. +// + +#import "MJRefreshAutoFooter.h" + +@interface MJRefreshAutoStateFooter : MJRefreshAutoFooter +/** 文字距离圈圈、箭头的距离 */ +@property (assign, nonatomic) CGFloat labelLeftInset; +/** 显示刷新状态的label */ +@property (weak, nonatomic, readonly) UILabel *stateLabel; + +/** 设置state状态下的文字 */ +- (void)setTitle:(NSString *)title forState:(MJRefreshState)state; + +/** 隐藏刷新状态的文字 */ +@property (assign, nonatomic, getter=isRefreshingTitleHidden) BOOL refreshingTitleHidden; +@end diff --git a/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Custom/Footer/Auto/MJRefreshAutoStateFooter.m b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Custom/Footer/Auto/MJRefreshAutoStateFooter.m new file mode 100644 index 00000000..d16547de --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Custom/Footer/Auto/MJRefreshAutoStateFooter.m @@ -0,0 +1,92 @@ +// +// MJRefreshAutoStateFooter.m +// MJRefreshExample +// +// Created by MJ Lee on 15/6/13. +// Copyright © 2015年 小码哥. All rights reserved. +// + +#import "MJRefreshAutoStateFooter.h" + +@interface MJRefreshAutoStateFooter() +{ + /** 显示刷新状态的label */ + __unsafe_unretained UILabel *_stateLabel; +} +/** 所有状态对应的文字 */ +@property (strong, nonatomic) NSMutableDictionary *stateTitles; +@end + +@implementation MJRefreshAutoStateFooter +#pragma mark - 懒加载 +- (NSMutableDictionary *)stateTitles +{ + if (!_stateTitles) { + self.stateTitles = [NSMutableDictionary dictionary]; + } + return _stateTitles; +} + +- (UILabel *)stateLabel +{ + if (!_stateLabel) { + [self addSubview:_stateLabel = [UILabel mj_label]]; + } + return _stateLabel; +} + +#pragma mark - 公共方法 +- (void)setTitle:(NSString *)title forState:(MJRefreshState)state +{ + if (title == nil) return; + self.stateTitles[@(state)] = title; + self.stateLabel.text = self.stateTitles[@(self.state)]; +} + +#pragma mark - 私有方法 +- (void)stateLabelClick +{ + if (self.state == MJRefreshStateIdle) { + [self beginRefreshing]; + } +} + +#pragma mark - 重写父类的方法 +- (void)prepare +{ + [super prepare]; + + // 初始化间距 + self.labelLeftInset = MJRefreshLabelLeftInset; + + // 初始化文字 + [self setTitle:[NSBundle mj_localizedStringForKey:MJRefreshAutoFooterIdleText] forState:MJRefreshStateIdle]; + [self setTitle:[NSBundle mj_localizedStringForKey:MJRefreshAutoFooterRefreshingText] forState:MJRefreshStateRefreshing]; + [self setTitle:[NSBundle mj_localizedStringForKey:MJRefreshAutoFooterNoMoreDataText] forState:MJRefreshStateNoMoreData]; + + // 监听label + self.stateLabel.userInteractionEnabled = YES; + [self.stateLabel addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(stateLabelClick)]]; +} + +- (void)placeSubviews +{ + [super placeSubviews]; + + if (self.stateLabel.constraints.count) return; + + // 状态标签 + self.stateLabel.frame = self.bounds; +} + +- (void)setState:(MJRefreshState)state +{ + MJRefreshCheckState + + if (self.isRefreshingTitleHidden && state == MJRefreshStateRefreshing) { + self.stateLabel.text = nil; + } else { + self.stateLabel.text = self.stateTitles[@(state)]; + } +} +@end \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Custom/Footer/Back/MJRefreshBackGifFooter.h b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Custom/Footer/Back/MJRefreshBackGifFooter.h new file mode 100644 index 00000000..b29af869 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Custom/Footer/Back/MJRefreshBackGifFooter.h @@ -0,0 +1,17 @@ +// +// MJRefreshBackGifFooter.h +// MJRefreshExample +// +// Created by MJ Lee on 15/4/24. +// Copyright (c) 2015年 小码哥. All rights reserved. +// + +#import "MJRefreshBackStateFooter.h" + +@interface MJRefreshBackGifFooter : MJRefreshBackStateFooter +@property (weak, nonatomic, readonly) UIImageView *gifView; + +/** 设置state状态下的动画图片images 动画持续时间duration*/ +- (void)setImages:(NSArray *)images duration:(NSTimeInterval)duration forState:(MJRefreshState)state; +- (void)setImages:(NSArray *)images forState:(MJRefreshState)state; +@end diff --git a/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Custom/Footer/Back/MJRefreshBackGifFooter.m b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Custom/Footer/Back/MJRefreshBackGifFooter.m new file mode 100644 index 00000000..fa97c72c --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Custom/Footer/Back/MJRefreshBackGifFooter.m @@ -0,0 +1,127 @@ +// +// MJRefreshBackGifFooter.m +// MJRefreshExample +// +// Created by MJ Lee on 15/4/24. +// Copyright (c) 2015年 小码哥. All rights reserved. +// + +#import "MJRefreshBackGifFooter.h" + +@interface MJRefreshBackGifFooter() +{ + __unsafe_unretained UIImageView *_gifView; +} +/** 所有状态对应的动画图片 */ +@property (strong, nonatomic) NSMutableDictionary *stateImages; +/** 所有状态对应的动画时间 */ +@property (strong, nonatomic) NSMutableDictionary *stateDurations; +@end + +@implementation MJRefreshBackGifFooter +#pragma mark - 懒加载 +- (UIImageView *)gifView +{ + if (!_gifView) { + UIImageView *gifView = [[UIImageView alloc] init]; + [self addSubview:_gifView = gifView]; + } + return _gifView; +} + +- (NSMutableDictionary *)stateImages +{ + if (!_stateImages) { + self.stateImages = [NSMutableDictionary dictionary]; + } + return _stateImages; +} + +- (NSMutableDictionary *)stateDurations +{ + if (!_stateDurations) { + self.stateDurations = [NSMutableDictionary dictionary]; + } + return _stateDurations; +} + +#pragma mark - 公共方法 +- (void)setImages:(NSArray *)images duration:(NSTimeInterval)duration forState:(MJRefreshState)state +{ + if (images == nil) return; + + self.stateImages[@(state)] = images; + self.stateDurations[@(state)] = @(duration); + + /* 根据图片设置控件的高度 */ + UIImage *image = [images firstObject]; + if (image.size.height > self.mj_h) { + self.mj_h = image.size.height; + } +} + +- (void)setImages:(NSArray *)images forState:(MJRefreshState)state +{ + [self setImages:images duration:images.count * 0.1 forState:state]; +} + +#pragma mark - 实现父类的方法 +- (void)prepare +{ + [super prepare]; + + // 初始化间距 + self.labelLeftInset = 20; +} + +- (void)setPullingPercent:(CGFloat)pullingPercent +{ + [super setPullingPercent:pullingPercent]; + NSArray *images = self.stateImages[@(MJRefreshStateIdle)]; + if (self.state != MJRefreshStateIdle || images.count == 0) return; + [self.gifView stopAnimating]; + NSUInteger index = images.count * pullingPercent; + if (index >= images.count) index = images.count - 1; + self.gifView.image = images[index]; +} + +- (void)placeSubviews +{ + [super placeSubviews]; + + if (self.gifView.constraints.count) return; + + self.gifView.frame = self.bounds; + if (self.stateLabel.hidden) { + self.gifView.contentMode = UIViewContentModeCenter; + } else { + self.gifView.contentMode = UIViewContentModeRight; + self.gifView.mj_w = self.mj_w * 0.5 - self.labelLeftInset - self.stateLabel.mj_textWith * 0.5; + } +} + +- (void)setState:(MJRefreshState)state +{ + MJRefreshCheckState + + // 根据状态做事情 + if (state == MJRefreshStatePulling || state == MJRefreshStateRefreshing) { + NSArray *images = self.stateImages[@(state)]; + if (images.count == 0) return; + + self.gifView.hidden = NO; + [self.gifView stopAnimating]; + if (images.count == 1) { // 单张图片 + self.gifView.image = [images lastObject]; + } else { // 多张图片 + self.gifView.animationImages = images; + self.gifView.animationDuration = [self.stateDurations[@(state)] doubleValue]; + [self.gifView startAnimating]; + } + } else if (state == MJRefreshStateIdle) { + self.gifView.hidden = NO; + } else if (state == MJRefreshStateNoMoreData) { + self.gifView.hidden = YES; + } +} +@end diff --git a/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Custom/Footer/Back/MJRefreshBackNormalFooter.h b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Custom/Footer/Back/MJRefreshBackNormalFooter.h new file mode 100644 index 00000000..90e8b776 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Custom/Footer/Back/MJRefreshBackNormalFooter.h @@ -0,0 +1,15 @@ +// +// MJRefreshBackNormalFooter.h +// MJRefreshExample +// +// Created by MJ Lee on 15/4/24. +// Copyright (c) 2015年 小码哥. All rights reserved. +// + +#import "MJRefreshBackStateFooter.h" + +@interface MJRefreshBackNormalFooter : MJRefreshBackStateFooter +@property (weak, nonatomic, readonly) UIImageView *arrowView; +/** 菊花的样式 */ +@property (assign, nonatomic) UIActivityIndicatorViewStyle activityIndicatorViewStyle; +@end diff --git a/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Custom/Footer/Back/MJRefreshBackNormalFooter.m b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Custom/Footer/Back/MJRefreshBackNormalFooter.m new file mode 100644 index 00000000..30e5ecf7 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Custom/Footer/Back/MJRefreshBackNormalFooter.m @@ -0,0 +1,120 @@ +// +// MJRefreshBackNormalFooter.m +// MJRefreshExample +// +// Created by MJ Lee on 15/4/24. +// Copyright (c) 2015年 小码哥. All rights reserved. +// + +#import "MJRefreshBackNormalFooter.h" +#import "NSBundle+MJRefresh.h" + +@interface MJRefreshBackNormalFooter() +{ + __unsafe_unretained UIImageView *_arrowView; +} +@property (weak, nonatomic) UIActivityIndicatorView *loadingView; +@end + +@implementation MJRefreshBackNormalFooter +#pragma mark - 懒加载子控件 +- (UIImageView *)arrowView +{ + if (!_arrowView) { + UIImageView *arrowView = [[UIImageView alloc] initWithImage:[NSBundle mj_arrowImage]]; + [self addSubview:_arrowView = arrowView]; + } + return _arrowView; +} + + +- (UIActivityIndicatorView *)loadingView +{ + if (!_loadingView) { + UIActivityIndicatorView *loadingView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:self.activityIndicatorViewStyle]; + loadingView.hidesWhenStopped = YES; + [self addSubview:_loadingView = loadingView]; + } + return _loadingView; +} + +- (void)setActivityIndicatorViewStyle:(UIActivityIndicatorViewStyle)activityIndicatorViewStyle +{ + _activityIndicatorViewStyle = activityIndicatorViewStyle; + + self.loadingView = nil; + [self setNeedsLayout]; +} +#pragma mark - 重写父类的方法 +- (void)prepare +{ + [super prepare]; + + self.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray; +} + +- (void)placeSubviews +{ + [super placeSubviews]; + + // 箭头的中心点 + CGFloat arrowCenterX = self.mj_w * 0.5; + if (!self.stateLabel.hidden) { + arrowCenterX -= self.labelLeftInset + self.stateLabel.mj_textWith * 0.5; + } + CGFloat arrowCenterY = self.mj_h * 0.5; + CGPoint arrowCenter = CGPointMake(arrowCenterX, arrowCenterY); + + // 箭头 + if (self.arrowView.constraints.count == 0) { + self.arrowView.mj_size = self.arrowView.image.size; + self.arrowView.center = arrowCenter; + } + + // 圈圈 + if (self.loadingView.constraints.count == 0) { + self.loadingView.center = arrowCenter; + } + + self.arrowView.tintColor = self.stateLabel.textColor; +} + +- (void)setState:(MJRefreshState)state +{ + MJRefreshCheckState + + // 根据状态做事情 + if (state == MJRefreshStateIdle) { + if (oldState == MJRefreshStateRefreshing) { + self.arrowView.transform = CGAffineTransformMakeRotation(0.000001 - M_PI); + [UIView animateWithDuration:MJRefreshSlowAnimationDuration animations:^{ + self.loadingView.alpha = 0.0; + } completion:^(BOOL finished) { + self.loadingView.alpha = 1.0; + [self.loadingView stopAnimating]; + + self.arrowView.hidden = NO; + }]; + } else { + self.arrowView.hidden = NO; + [self.loadingView stopAnimating]; + [UIView animateWithDuration:MJRefreshFastAnimationDuration animations:^{ + self.arrowView.transform = CGAffineTransformMakeRotation(0.000001 - M_PI); + }]; + } + } else if (state == MJRefreshStatePulling) { + self.arrowView.hidden = NO; + [self.loadingView stopAnimating]; + [UIView animateWithDuration:MJRefreshFastAnimationDuration animations:^{ + self.arrowView.transform = CGAffineTransformIdentity; + }]; + } else if (state == MJRefreshStateRefreshing) { + self.arrowView.hidden = YES; + [self.loadingView startAnimating]; + } else if (state == MJRefreshStateNoMoreData) { + self.arrowView.hidden = YES; + [self.loadingView stopAnimating]; + } +} + +@end diff --git a/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Custom/Footer/Back/MJRefreshBackStateFooter.h b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Custom/Footer/Back/MJRefreshBackStateFooter.h new file mode 100644 index 00000000..99b1483d --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Custom/Footer/Back/MJRefreshBackStateFooter.h @@ -0,0 +1,21 @@ +// +// MJRefreshBackStateFooter.h +// MJRefreshExample +// +// Created by MJ Lee on 15/6/13. +// Copyright © 2015年 小码哥. All rights reserved. +// + +#import "MJRefreshBackFooter.h" + +@interface MJRefreshBackStateFooter : MJRefreshBackFooter +/** 文字距离圈圈、箭头的距离 */ +@property (assign, nonatomic) CGFloat labelLeftInset; +/** 显示刷新状态的label */ +@property (weak, nonatomic, readonly) UILabel *stateLabel; +/** 设置state状态下的文字 */ +- (void)setTitle:(NSString *)title forState:(MJRefreshState)state; + +/** 获取state状态下的title */ +- (NSString *)titleForState:(MJRefreshState)state; +@end diff --git a/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Custom/Footer/Back/MJRefreshBackStateFooter.m b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Custom/Footer/Back/MJRefreshBackStateFooter.m new file mode 100644 index 00000000..cc784d00 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Custom/Footer/Back/MJRefreshBackStateFooter.m @@ -0,0 +1,82 @@ +// +// MJRefreshBackStateFooter.m +// MJRefreshExample +// +// Created by MJ Lee on 15/6/13. +// Copyright © 2015年 小码哥. All rights reserved. +// + +#import "MJRefreshBackStateFooter.h" + +@interface MJRefreshBackStateFooter() +{ + /** 显示刷新状态的label */ + __unsafe_unretained UILabel *_stateLabel; +} +/** 所有状态对应的文字 */ +@property (strong, nonatomic) NSMutableDictionary *stateTitles; +@end + +@implementation MJRefreshBackStateFooter +#pragma mark - 懒加载 +- (NSMutableDictionary *)stateTitles +{ + if (!_stateTitles) { + self.stateTitles = [NSMutableDictionary dictionary]; + } + return _stateTitles; +} + +- (UILabel *)stateLabel +{ + if (!_stateLabel) { + [self addSubview:_stateLabel = [UILabel mj_label]]; + } + return _stateLabel; +} + +#pragma mark - 公共方法 +- (void)setTitle:(NSString *)title forState:(MJRefreshState)state +{ + if (title == nil) return; + self.stateTitles[@(state)] = title; + self.stateLabel.text = self.stateTitles[@(self.state)]; +} + +- (NSString *)titleForState:(MJRefreshState)state { + return self.stateTitles[@(state)]; +} + +#pragma mark - 重写父类的方法 +- (void)prepare +{ + [super prepare]; + + // 初始化间距 + self.labelLeftInset = MJRefreshLabelLeftInset; + + // 初始化文字 + [self setTitle:[NSBundle mj_localizedStringForKey:MJRefreshBackFooterIdleText] forState:MJRefreshStateIdle]; + [self setTitle:[NSBundle mj_localizedStringForKey:MJRefreshBackFooterPullingText] forState:MJRefreshStatePulling]; + [self setTitle:[NSBundle mj_localizedStringForKey:MJRefreshBackFooterRefreshingText] forState:MJRefreshStateRefreshing]; + [self setTitle:[NSBundle mj_localizedStringForKey:MJRefreshBackFooterNoMoreDataText] forState:MJRefreshStateNoMoreData]; +} + +- (void)placeSubviews +{ + [super placeSubviews]; + + if (self.stateLabel.constraints.count) return; + + // 状态标签 + self.stateLabel.frame = self.bounds; +} + +- (void)setState:(MJRefreshState)state +{ + MJRefreshCheckState + + // 设置状态文字 + self.stateLabel.text = self.stateTitles[@(state)]; +} +@end diff --git a/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Custom/Header/MJRefreshGifHeader.h b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Custom/Header/MJRefreshGifHeader.h new file mode 100644 index 00000000..ce3ed428 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Custom/Header/MJRefreshGifHeader.h @@ -0,0 +1,17 @@ +// +// MJRefreshGifHeader.h +// MJRefreshExample +// +// Created by MJ Lee on 15/4/24. +// Copyright (c) 2015年 小码哥. All rights reserved. +// + +#import "MJRefreshStateHeader.h" + +@interface MJRefreshGifHeader : MJRefreshStateHeader +@property (weak, nonatomic, readonly) UIImageView *gifView; + +/** 设置state状态下的动画图片images 动画持续时间duration*/ +- (void)setImages:(NSArray *)images duration:(NSTimeInterval)duration forState:(MJRefreshState)state; +- (void)setImages:(NSArray *)images forState:(MJRefreshState)state; +@end diff --git a/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Custom/Header/MJRefreshGifHeader.m b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Custom/Header/MJRefreshGifHeader.m new file mode 100644 index 00000000..f8bcc9ba --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Custom/Header/MJRefreshGifHeader.m @@ -0,0 +1,133 @@ +// +// MJRefreshGifHeader.m +// MJRefreshExample +// +// Created by MJ Lee on 15/4/24. +// Copyright (c) 2015年 小码哥. All rights reserved. +// + +#import "MJRefreshGifHeader.h" + +@interface MJRefreshGifHeader() +{ + __unsafe_unretained UIImageView *_gifView; +} +/** 所有状态对应的动画图片 */ +@property (strong, nonatomic) NSMutableDictionary *stateImages; +/** 所有状态对应的动画时间 */ +@property (strong, nonatomic) NSMutableDictionary *stateDurations; +@end + +@implementation MJRefreshGifHeader +#pragma mark - 懒加载 +- (UIImageView *)gifView +{ + if (!_gifView) { + UIImageView *gifView = [[UIImageView alloc] init]; + [self addSubview:_gifView = gifView]; + } + return _gifView; +} + +- (NSMutableDictionary *)stateImages +{ + if (!_stateImages) { + self.stateImages = [NSMutableDictionary dictionary]; + } + return _stateImages; +} + +- (NSMutableDictionary *)stateDurations +{ + if (!_stateDurations) { + self.stateDurations = [NSMutableDictionary dictionary]; + } + return _stateDurations; +} + +#pragma mark - 公共方法 +- (void)setImages:(NSArray *)images duration:(NSTimeInterval)duration forState:(MJRefreshState)state +{ + if (images == nil) return; + + self.stateImages[@(state)] = images; + self.stateDurations[@(state)] = @(duration); + + /* 根据图片设置控件的高度 */ + UIImage *image = [images firstObject]; + if (image.size.height > self.mj_h) { + self.mj_h = image.size.height; + } +} + +- (void)setImages:(NSArray *)images forState:(MJRefreshState)state +{ + [self setImages:images duration:images.count * 0.1 forState:state]; +} + +#pragma mark - 实现父类的方法 +- (void)prepare +{ + [super prepare]; + + // 初始化间距 + self.labelLeftInset = 20; +} + +- (void)setPullingPercent:(CGFloat)pullingPercent +{ + [super setPullingPercent:pullingPercent]; + NSArray *images = self.stateImages[@(MJRefreshStateIdle)]; + if (self.state != MJRefreshStateIdle || images.count == 0) return; + // 停止动画 + [self.gifView stopAnimating]; + // 设置当前需要显示的图片 + NSUInteger index = images.count * pullingPercent; + if (index >= images.count) index = images.count - 1; + self.gifView.image = images[index]; +} + +- (void)placeSubviews +{ + [super placeSubviews]; + + if (self.gifView.constraints.count) return; + + self.gifView.frame = self.bounds; + if (self.stateLabel.hidden && self.lastUpdatedTimeLabel.hidden) { + self.gifView.contentMode = UIViewContentModeCenter; + } else { + self.gifView.contentMode = UIViewContentModeRight; + + CGFloat stateWidth = self.stateLabel.mj_textWith; + CGFloat timeWidth = 0.0; + if (!self.lastUpdatedTimeLabel.hidden) { + timeWidth = self.lastUpdatedTimeLabel.mj_textWith; + } + CGFloat textWidth = MAX(stateWidth, timeWidth); + self.gifView.mj_w = self.mj_w * 0.5 - textWidth * 0.5 - self.labelLeftInset; + } +} + +- (void)setState:(MJRefreshState)state +{ + MJRefreshCheckState + + // 根据状态做事情 + if (state == MJRefreshStatePulling || state == MJRefreshStateRefreshing) { + NSArray *images = self.stateImages[@(state)]; + if (images.count == 0) return; + + [self.gifView stopAnimating]; + if (images.count == 1) { // 单张图片 + self.gifView.image = [images lastObject]; + } else { // 多张图片 + self.gifView.animationImages = images; + self.gifView.animationDuration = [self.stateDurations[@(state)] doubleValue]; + [self.gifView startAnimating]; + } + } else if (state == MJRefreshStateIdle) { + [self.gifView stopAnimating]; + } +} +@end diff --git a/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Custom/Header/MJRefreshNormalHeader.h b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Custom/Header/MJRefreshNormalHeader.h new file mode 100644 index 00000000..547d05e7 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Custom/Header/MJRefreshNormalHeader.h @@ -0,0 +1,15 @@ +// +// MJRefreshNormalHeader.h +// MJRefreshExample +// +// Created by MJ Lee on 15/4/24. +// Copyright (c) 2015年 小码哥. All rights reserved. +// + +#import "MJRefreshStateHeader.h" + +@interface MJRefreshNormalHeader : MJRefreshStateHeader +@property (weak, nonatomic, readonly) UIImageView *arrowView; +/** 菊花的样式 */ +@property (assign, nonatomic) UIActivityIndicatorViewStyle activityIndicatorViewStyle; +@end diff --git a/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Custom/Header/MJRefreshNormalHeader.m b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Custom/Header/MJRefreshNormalHeader.m new file mode 100644 index 00000000..32d8de70 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Custom/Header/MJRefreshNormalHeader.m @@ -0,0 +1,127 @@ +// +// MJRefreshNormalHeader.m +// MJRefreshExample +// +// Created by MJ Lee on 15/4/24. +// Copyright (c) 2015年 小码哥. All rights reserved. +// + +#import "MJRefreshNormalHeader.h" +#import "NSBundle+MJRefresh.h" + +@interface MJRefreshNormalHeader() +{ + __unsafe_unretained UIImageView *_arrowView; +} +@property (weak, nonatomic) UIActivityIndicatorView *loadingView; +@end + +@implementation MJRefreshNormalHeader +#pragma mark - 懒加载子控件 +- (UIImageView *)arrowView +{ + if (!_arrowView) { + UIImageView *arrowView = [[UIImageView alloc] initWithImage:[NSBundle mj_arrowImage]]; + [self addSubview:_arrowView = arrowView]; + } + return _arrowView; +} + +- (UIActivityIndicatorView *)loadingView +{ + if (!_loadingView) { + UIActivityIndicatorView *loadingView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:self.activityIndicatorViewStyle]; + loadingView.hidesWhenStopped = YES; + [self addSubview:_loadingView = loadingView]; + } + return _loadingView; +} + +#pragma mark - 公共方法 +- (void)setActivityIndicatorViewStyle:(UIActivityIndicatorViewStyle)activityIndicatorViewStyle +{ + _activityIndicatorViewStyle = activityIndicatorViewStyle; + + self.loadingView = nil; + [self setNeedsLayout]; +} + +#pragma mark - 重写父类的方法 +- (void)prepare +{ + [super prepare]; + + self.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray; +} + +- (void)placeSubviews +{ + [super placeSubviews]; + + // 箭头的中心点 + CGFloat arrowCenterX = self.mj_w * 0.5; + if (!self.stateLabel.hidden) { + CGFloat stateWidth = self.stateLabel.mj_textWith; + CGFloat timeWidth = 0.0; + if (!self.lastUpdatedTimeLabel.hidden) { + timeWidth = self.lastUpdatedTimeLabel.mj_textWith; + } + CGFloat textWidth = MAX(stateWidth, timeWidth); + arrowCenterX -= textWidth / 2 + self.labelLeftInset; + } + CGFloat arrowCenterY = self.mj_h * 0.5; + CGPoint arrowCenter = CGPointMake(arrowCenterX, arrowCenterY); + + // 箭头 + if (self.arrowView.constraints.count == 0) { + self.arrowView.mj_size = self.arrowView.image.size; + self.arrowView.center = arrowCenter; + } + + // 圈圈 + if (self.loadingView.constraints.count == 0) { + self.loadingView.center = arrowCenter; + } + + self.arrowView.tintColor = self.stateLabel.textColor; +} + +- (void)setState:(MJRefreshState)state +{ + MJRefreshCheckState + + // 根据状态做事情 + if (state == MJRefreshStateIdle) { + if (oldState == MJRefreshStateRefreshing) { + self.arrowView.transform = CGAffineTransformIdentity; + + [UIView animateWithDuration:MJRefreshSlowAnimationDuration animations:^{ + self.loadingView.alpha = 0.0; + } completion:^(BOOL finished) { + // 如果执行完动画发现不是idle状态,就直接返回,进入其他状态 + if (self.state != MJRefreshStateIdle) return; + + self.loadingView.alpha = 1.0; + [self.loadingView stopAnimating]; + self.arrowView.hidden = NO; + }]; + } else { + [self.loadingView stopAnimating]; + self.arrowView.hidden = NO; + [UIView animateWithDuration:MJRefreshFastAnimationDuration animations:^{ + self.arrowView.transform = CGAffineTransformIdentity; + }]; + } + } else if (state == MJRefreshStatePulling) { + [self.loadingView stopAnimating]; + self.arrowView.hidden = NO; + [UIView animateWithDuration:MJRefreshFastAnimationDuration animations:^{ + self.arrowView.transform = CGAffineTransformMakeRotation(0.000001 - M_PI); + }]; + } else if (state == MJRefreshStateRefreshing) { + self.loadingView.alpha = 1.0; // 防止refreshing -> idle的动画完毕动作没有被执行 + [self.loadingView startAnimating]; + self.arrowView.hidden = YES; + } +} +@end diff --git a/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Custom/Header/MJRefreshStateHeader.h b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Custom/Header/MJRefreshStateHeader.h new file mode 100644 index 00000000..1f3dbc40 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Custom/Header/MJRefreshStateHeader.h @@ -0,0 +1,25 @@ +// +// MJRefreshStateHeader.h +// MJRefreshExample +// +// Created by MJ Lee on 15/4/24. +// Copyright (c) 2015年 小码哥. All rights reserved. +// + +#import "MJRefreshHeader.h" + +@interface MJRefreshStateHeader : MJRefreshHeader +#pragma mark - 刷新时间相关 +/** 利用这个block来决定显示的更新时间文字 */ +@property (copy, nonatomic) NSString *(^lastUpdatedTimeText)(NSDate *lastUpdatedTime); +/** 显示上一次刷新时间的label */ +@property (weak, nonatomic, readonly) UILabel *lastUpdatedTimeLabel; + +#pragma mark - 状态相关 +/** 文字距离圈圈、箭头的距离 */ +@property (assign, nonatomic) CGFloat labelLeftInset; +/** 显示刷新状态的label */ +@property (weak, nonatomic, readonly) UILabel *stateLabel; +/** 设置state状态下的文字 */ +- (void)setTitle:(NSString *)title forState:(MJRefreshState)state; +@end diff --git a/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Custom/Header/MJRefreshStateHeader.m b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Custom/Header/MJRefreshStateHeader.m new file mode 100644 index 00000000..ca78b526 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/Custom/Header/MJRefreshStateHeader.m @@ -0,0 +1,167 @@ +// +// MJRefreshStateHeader.m +// MJRefreshExample +// +// Created by MJ Lee on 15/4/24. +// Copyright (c) 2015年 小码哥. All rights reserved. +// + +#import "MJRefreshStateHeader.h" + +@interface MJRefreshStateHeader() +{ + /** 显示上一次刷新时间的label */ + __unsafe_unretained UILabel *_lastUpdatedTimeLabel; + /** 显示刷新状态的label */ + __unsafe_unretained UILabel *_stateLabel; +} +/** 所有状态对应的文字 */ +@property (strong, nonatomic) NSMutableDictionary *stateTitles; +@end + +@implementation MJRefreshStateHeader +#pragma mark - 懒加载 +- (NSMutableDictionary *)stateTitles +{ + if (!_stateTitles) { + self.stateTitles = [NSMutableDictionary dictionary]; + } + return _stateTitles; +} + +- (UILabel *)stateLabel +{ + if (!_stateLabel) { + [self addSubview:_stateLabel = [UILabel mj_label]]; + } + return _stateLabel; +} + +- (UILabel *)lastUpdatedTimeLabel +{ + if (!_lastUpdatedTimeLabel) { + [self addSubview:_lastUpdatedTimeLabel = [UILabel mj_label]]; + } + return _lastUpdatedTimeLabel; +} + +#pragma mark - 公共方法 +- (void)setTitle:(NSString *)title forState:(MJRefreshState)state +{ + if (title == nil) return; + self.stateTitles[@(state)] = title; + self.stateLabel.text = self.stateTitles[@(self.state)]; +} + +#pragma mark - 日历获取在9.x之后的系统使用currentCalendar会出异常。在8.0之后使用系统新API。 +- (NSCalendar *)currentCalendar { + if ([NSCalendar respondsToSelector:@selector(calendarWithIdentifier:)]) { + return [NSCalendar calendarWithIdentifier:NSCalendarIdentifierGregorian]; + } + return [NSCalendar currentCalendar]; +} + +#pragma mark key的处理 +- (void)setLastUpdatedTimeKey:(NSString *)lastUpdatedTimeKey +{ + [super setLastUpdatedTimeKey:lastUpdatedTimeKey]; + + // 如果label隐藏了,就不用再处理 + if (self.lastUpdatedTimeLabel.hidden) return; + + NSDate *lastUpdatedTime = [[NSUserDefaults standardUserDefaults] objectForKey:lastUpdatedTimeKey]; + + // 如果有block + if (self.lastUpdatedTimeText) { + self.lastUpdatedTimeLabel.text = self.lastUpdatedTimeText(lastUpdatedTime); + return; + } + + if (lastUpdatedTime) { + // 1.获得年月日 + NSCalendar *calendar = [self currentCalendar]; + NSUInteger unitFlags = NSCalendarUnitYear| NSCalendarUnitMonth | NSCalendarUnitDay |NSCalendarUnitHour |NSCalendarUnitMinute; + NSDateComponents *cmp1 = [calendar components:unitFlags fromDate:lastUpdatedTime]; + NSDateComponents *cmp2 = [calendar components:unitFlags fromDate:[NSDate date]]; + + // 2.格式化日期 + NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; + BOOL isToday = NO; + if ([cmp1 day] == [cmp2 day]) { // 今天 + formatter.dateFormat = @" HH:mm"; + isToday = YES; + } else if ([cmp1 year] == [cmp2 year]) { // 今年 + formatter.dateFormat = @"MM-dd HH:mm"; + } else { + formatter.dateFormat = @"yyyy-MM-dd HH:mm"; + } + NSString *time = [formatter stringFromDate:lastUpdatedTime]; + + // 3.显示日期 + self.lastUpdatedTimeLabel.text = [NSString stringWithFormat:@"%@%@%@", + [NSBundle mj_localizedStringForKey:MJRefreshHeaderLastTimeText], + isToday ? [NSBundle mj_localizedStringForKey:MJRefreshHeaderDateTodayText] : @"", + time]; + } else { + self.lastUpdatedTimeLabel.text = [NSString stringWithFormat:@"%@%@", + [NSBundle mj_localizedStringForKey:MJRefreshHeaderLastTimeText], + [NSBundle mj_localizedStringForKey:MJRefreshHeaderNoneLastDateText]]; + } +} + +#pragma mark - 覆盖父类的方法 +- (void)prepare +{ + [super prepare]; + + // 初始化间距 + self.labelLeftInset = MJRefreshLabelLeftInset; + + // 初始化文字 + [self setTitle:[NSBundle mj_localizedStringForKey:MJRefreshHeaderIdleText] forState:MJRefreshStateIdle]; + [self setTitle:[NSBundle mj_localizedStringForKey:MJRefreshHeaderPullingText] forState:MJRefreshStatePulling]; + [self setTitle:[NSBundle mj_localizedStringForKey:MJRefreshHeaderRefreshingText] forState:MJRefreshStateRefreshing]; +} + +- (void)placeSubviews +{ + [super placeSubviews]; + + if (self.stateLabel.hidden) return; + + BOOL noConstrainsOnStatusLabel = self.stateLabel.constraints.count == 0; + + if (self.lastUpdatedTimeLabel.hidden) { + // 状态 + if (noConstrainsOnStatusLabel) self.stateLabel.frame = self.bounds; + } else { + CGFloat stateLabelH = self.mj_h * 0.5; + // 状态 + if (noConstrainsOnStatusLabel) { + self.stateLabel.mj_x = 0; + self.stateLabel.mj_y = 0; + self.stateLabel.mj_w = self.mj_w; + self.stateLabel.mj_h = stateLabelH; + } + + // 更新时间 + if (self.lastUpdatedTimeLabel.constraints.count == 0) { + self.lastUpdatedTimeLabel.mj_x = 0; + self.lastUpdatedTimeLabel.mj_y = stateLabelH; + self.lastUpdatedTimeLabel.mj_w = self.mj_w; + self.lastUpdatedTimeLabel.mj_h = self.mj_h - self.lastUpdatedTimeLabel.mj_y; + } + } +} + +- (void)setState:(MJRefreshState)state +{ + MJRefreshCheckState + + // 设置状态文字 + self.stateLabel.text = self.stateTitles[@(state)]; + + // 重新设置key(重新显示时间) + self.lastUpdatedTimeKey = self.lastUpdatedTimeKey; +} +@end diff --git a/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/MJRefresh.bundle/arrow@2x.png b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/MJRefresh.bundle/arrow@2x.png new file mode 100755 index 00000000..b1078de8 Binary files /dev/null and b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/MJRefresh.bundle/arrow@2x.png differ diff --git a/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/MJRefresh.bundle/en.lproj/Localizable.strings b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/MJRefresh.bundle/en.lproj/Localizable.strings new file mode 100644 index 00000000..a75f6b18 Binary files /dev/null and b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/MJRefresh.bundle/en.lproj/Localizable.strings differ diff --git a/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/MJRefresh.bundle/zh-Hans.lproj/Localizable.strings b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/MJRefresh.bundle/zh-Hans.lproj/Localizable.strings new file mode 100644 index 00000000..0a36d7e1 Binary files /dev/null and b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/MJRefresh.bundle/zh-Hans.lproj/Localizable.strings differ diff --git a/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/MJRefresh.bundle/zh-Hant.lproj/Localizable.strings b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/MJRefresh.bundle/zh-Hant.lproj/Localizable.strings new file mode 100644 index 00000000..7924bba7 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/MJRefresh.bundle/zh-Hant.lproj/Localizable.strings @@ -0,0 +1,16 @@ +"MJRefreshHeaderIdleText" = "下拉可以刷新"; +"MJRefreshHeaderPullingText" = "鬆開立即刷新"; +"MJRefreshHeaderRefreshingText" = "正在刷新數據中..."; + +"MJRefreshAutoFooterIdleText" = "點擊或上拉加載更多"; +"MJRefreshAutoFooterRefreshingText" = "正在加載更多的數據..."; +"MJRefreshAutoFooterNoMoreDataText" = "已經全部加載完畢"; + +"MJRefreshBackFooterIdleText" = "上拉可以加載更多"; +"MJRefreshBackFooterPullingText" = "鬆開立即加載更多"; +"MJRefreshBackFooterRefreshingText" = "正在加載更多的數據..."; +"MJRefreshBackFooterNoMoreDataText" = "已經全部加載完畢"; + +"MJRefreshHeaderLastTimeText" = "最後更新:"; +"MJRefreshHeaderDateTodayText" = "今天"; +"MJRefreshHeaderNoneLastDateText" = "無記錄"; diff --git a/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/MJRefresh.h b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/MJRefresh.h new file mode 100644 index 00000000..196e6ecb --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/MJRefresh.h @@ -0,0 +1,14 @@ +// 代码地址: https://github.com/CoderMJLee/MJRefresh +// 代码地址: http://code4app.com/ios/%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90%E4%B8%8B%E6%8B%89%E4%B8%8A%E6%8B%89%E5%88%B7%E6%96%B0/52326ce26803fabc46000000 + +#import "UIScrollView+MJRefresh.h" +#import "UIScrollView+MJExtension.h" +#import "UIView+MJExtension.h" + +#import "MJRefreshNormalHeader.h" +#import "MJRefreshGifHeader.h" + +#import "MJRefreshBackNormalFooter.h" +#import "MJRefreshBackGifFooter.h" +#import "MJRefreshAutoNormalFooter.h" +#import "MJRefreshAutoGifFooter.h" \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/MJRefreshConst.h b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/MJRefreshConst.h new file mode 100644 index 00000000..4a720212 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/MJRefreshConst.h @@ -0,0 +1,67 @@ +// 代码地址: https://github.com/CoderMJLee/MJRefresh +// 代码地址: http://code4app.com/ios/%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90%E4%B8%8B%E6%8B%89%E4%B8%8A%E6%8B%89%E5%88%B7%E6%96%B0/52326ce26803fabc46000000 +#import +#import + +// 弱引用 +#define MJWeakSelf __weak typeof(self) weakSelf = self; + +// 日志输出 +#ifdef DEBUG +#define MJRefreshLog(...) NSLog(__VA_ARGS__) +#else +#define MJRefreshLog(...) +#endif + +// 过期提醒 +#define MJRefreshDeprecated(instead) NS_DEPRECATED(2_0, 2_0, 2_0, 2_0, instead) + +// 运行时objc_msgSend +#define MJRefreshMsgSend(...) ((void (*)(void *, SEL, UIView *))objc_msgSend)(__VA_ARGS__) +#define MJRefreshMsgTarget(target) (__bridge void *)(target) + +// RGB颜色 +#define MJRefreshColor(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0] + +// 文字颜色 +#define MJRefreshLabelTextColor MJRefreshColor(90, 90, 90) + +// 字体大小 +#define MJRefreshLabelFont [UIFont boldSystemFontOfSize:14] + +// 常量 +UIKIT_EXTERN const CGFloat MJRefreshLabelLeftInset; +UIKIT_EXTERN const CGFloat MJRefreshHeaderHeight; +UIKIT_EXTERN const CGFloat MJRefreshFooterHeight; +UIKIT_EXTERN const CGFloat MJRefreshFastAnimationDuration; +UIKIT_EXTERN const CGFloat MJRefreshSlowAnimationDuration; + +UIKIT_EXTERN NSString *const MJRefreshKeyPathContentOffset; +UIKIT_EXTERN NSString *const MJRefreshKeyPathContentSize; +UIKIT_EXTERN NSString *const MJRefreshKeyPathContentInset; +UIKIT_EXTERN NSString *const MJRefreshKeyPathPanState; + +UIKIT_EXTERN NSString *const MJRefreshHeaderLastUpdatedTimeKey; + +UIKIT_EXTERN NSString *const MJRefreshHeaderIdleText; +UIKIT_EXTERN NSString *const MJRefreshHeaderPullingText; +UIKIT_EXTERN NSString *const MJRefreshHeaderRefreshingText; + +UIKIT_EXTERN NSString *const MJRefreshAutoFooterIdleText; +UIKIT_EXTERN NSString *const MJRefreshAutoFooterRefreshingText; +UIKIT_EXTERN NSString *const MJRefreshAutoFooterNoMoreDataText; + +UIKIT_EXTERN NSString *const MJRefreshBackFooterIdleText; +UIKIT_EXTERN NSString *const MJRefreshBackFooterPullingText; +UIKIT_EXTERN NSString *const MJRefreshBackFooterRefreshingText; +UIKIT_EXTERN NSString *const MJRefreshBackFooterNoMoreDataText; + +UIKIT_EXTERN NSString *const MJRefreshHeaderLastTimeText; +UIKIT_EXTERN NSString *const MJRefreshHeaderDateTodayText; +UIKIT_EXTERN NSString *const MJRefreshHeaderNoneLastDateText; + +// 状态检查 +#define MJRefreshCheckState \ +MJRefreshState oldState = self.state; \ +if (state == oldState) return; \ +[super setState:state]; diff --git a/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/MJRefreshConst.m b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/MJRefreshConst.m new file mode 100644 index 00000000..7c0733ee --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/MJRefreshConst.m @@ -0,0 +1,33 @@ +// 代码地址: https://github.com/CoderMJLee/MJRefresh +// 代码地址: http://code4app.com/ios/%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90%E4%B8%8B%E6%8B%89%E4%B8%8A%E6%8B%89%E5%88%B7%E6%96%B0/52326ce26803fabc46000000 +#import + +const CGFloat MJRefreshLabelLeftInset = 25; +const CGFloat MJRefreshHeaderHeight = 54.0; +const CGFloat MJRefreshFooterHeight = 44.0; +const CGFloat MJRefreshFastAnimationDuration = 0.25; +const CGFloat MJRefreshSlowAnimationDuration = 0.4; + +NSString *const MJRefreshKeyPathContentOffset = @"contentOffset"; +NSString *const MJRefreshKeyPathContentInset = @"contentInset"; +NSString *const MJRefreshKeyPathContentSize = @"contentSize"; +NSString *const MJRefreshKeyPathPanState = @"state"; + +NSString *const MJRefreshHeaderLastUpdatedTimeKey = @"MJRefreshHeaderLastUpdatedTimeKey"; + +NSString *const MJRefreshHeaderIdleText = @"MJRefreshHeaderIdleText"; +NSString *const MJRefreshHeaderPullingText = @"MJRefreshHeaderPullingText"; +NSString *const MJRefreshHeaderRefreshingText = @"MJRefreshHeaderRefreshingText"; + +NSString *const MJRefreshAutoFooterIdleText = @"MJRefreshAutoFooterIdleText"; +NSString *const MJRefreshAutoFooterRefreshingText = @"MJRefreshAutoFooterRefreshingText"; +NSString *const MJRefreshAutoFooterNoMoreDataText = @"MJRefreshAutoFooterNoMoreDataText"; + +NSString *const MJRefreshBackFooterIdleText = @"MJRefreshBackFooterIdleText"; +NSString *const MJRefreshBackFooterPullingText = @"MJRefreshBackFooterPullingText"; +NSString *const MJRefreshBackFooterRefreshingText = @"MJRefreshBackFooterRefreshingText"; +NSString *const MJRefreshBackFooterNoMoreDataText = @"MJRefreshBackFooterNoMoreDataText"; + +NSString *const MJRefreshHeaderLastTimeText = @"MJRefreshHeaderLastTimeText"; +NSString *const MJRefreshHeaderDateTodayText = @"MJRefreshHeaderDateTodayText"; +NSString *const MJRefreshHeaderNoneLastDateText = @"MJRefreshHeaderNoneLastDateText"; \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/NSBundle+MJRefresh.h b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/NSBundle+MJRefresh.h new file mode 100644 index 00000000..01df06c6 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/NSBundle+MJRefresh.h @@ -0,0 +1,16 @@ +// +// NSBundle+MJRefresh.h +// MJRefreshExample +// +// Created by MJ Lee on 16/6/13. +// Copyright © 2016年 小码哥. All rights reserved. +// + +#import + +@interface NSBundle (MJRefresh) ++ (instancetype)mj_refreshBundle; ++ (UIImage *)mj_arrowImage; ++ (NSString *)mj_localizedStringForKey:(NSString *)key value:(NSString *)value; ++ (NSString *)mj_localizedStringForKey:(NSString *)key; +@end diff --git a/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/NSBundle+MJRefresh.m b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/NSBundle+MJRefresh.m new file mode 100644 index 00000000..c155ad49 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/NSBundle+MJRefresh.m @@ -0,0 +1,61 @@ +// +// NSBundle+MJRefresh.m +// MJRefreshExample +// +// Created by MJ Lee on 16/6/13. +// Copyright © 2016年 小码哥. All rights reserved. +// + +#import "NSBundle+MJRefresh.h" +#import "MJRefreshComponent.h" + +@implementation NSBundle (MJRefresh) ++ (instancetype)mj_refreshBundle +{ + static NSBundle *refreshBundle = nil; + if (refreshBundle == nil) { + // 这里不使用mainBundle是为了适配pod 1.x和0.x + refreshBundle = [NSBundle bundleWithPath:[[NSBundle bundleForClass:[MJRefreshComponent class]] pathForResource:@"MJRefresh" ofType:@"bundle"]]; + } + return refreshBundle; +} + ++ (UIImage *)mj_arrowImage +{ + static UIImage *arrowImage = nil; + if (arrowImage == nil) { + arrowImage = [[UIImage imageWithContentsOfFile:[[self mj_refreshBundle] pathForResource:@"arrow@2x" ofType:@"png"]] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; + } + return arrowImage; +} + ++ (NSString *)mj_localizedStringForKey:(NSString *)key +{ + return [self mj_localizedStringForKey:key value:nil]; +} + ++ (NSString *)mj_localizedStringForKey:(NSString *)key value:(NSString *)value +{ + static NSBundle *bundle = nil; + if (bundle == nil) { + // (iOS获取的语言字符串比较不稳定)目前框架只处理en、zh-Hans、zh-Hant三种情况,其他按照系统默认处理 + NSString *language = [NSLocale preferredLanguages].firstObject; + if ([language hasPrefix:@"en"]) { + language = @"en"; + } else if ([language hasPrefix:@"zh"]) { + if ([language rangeOfString:@"Hans"].location != NSNotFound) { + language = @"zh-Hans"; // 简体中文 + } else { // zh-Hant\zh-HK\zh-TW + language = @"zh-Hant"; // 繁體中文 + } + } else { + language = @"en"; + } + + // 从MJRefresh.bundle中查找资源 + bundle = [NSBundle bundleWithPath:[[NSBundle mj_refreshBundle] pathForResource:language ofType:@"lproj"]]; + } + value = [bundle localizedStringForKey:key value:value table:nil]; + return [[NSBundle mainBundle] localizedStringForKey:key value:value table:nil]; +} +@end diff --git a/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/UIScrollView+MJExtension.h b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/UIScrollView+MJExtension.h new file mode 100644 index 00000000..734110f3 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/UIScrollView+MJExtension.h @@ -0,0 +1,23 @@ +// 代码地址: https://github.com/CoderMJLee/MJRefresh +// 代码地址: http://code4app.com/ios/%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90%E4%B8%8B%E6%8B%89%E4%B8%8A%E6%8B%89%E5%88%B7%E6%96%B0/52326ce26803fabc46000000 +// UIScrollView+Extension.h +// MJRefreshExample +// +// Created by MJ Lee on 14-5-28. +// Copyright (c) 2014年 小码哥. All rights reserved. +// + +#import + +@interface UIScrollView (MJExtension) +@property (assign, nonatomic) CGFloat mj_insetT; +@property (assign, nonatomic) CGFloat mj_insetB; +@property (assign, nonatomic) CGFloat mj_insetL; +@property (assign, nonatomic) CGFloat mj_insetR; + +@property (assign, nonatomic) CGFloat mj_offsetX; +@property (assign, nonatomic) CGFloat mj_offsetY; + +@property (assign, nonatomic) CGFloat mj_contentW; +@property (assign, nonatomic) CGFloat mj_contentH; +@end diff --git a/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/UIScrollView+MJExtension.m b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/UIScrollView+MJExtension.m new file mode 100644 index 00000000..6a13f5fe --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/UIScrollView+MJExtension.m @@ -0,0 +1,110 @@ +// 代码地址: https://github.com/CoderMJLee/MJRefresh +// 代码地址: http://code4app.com/ios/%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90%E4%B8%8B%E6%8B%89%E4%B8%8A%E6%8B%89%E5%88%B7%E6%96%B0/52326ce26803fabc46000000 +// UIScrollView+Extension.m +// MJRefreshExample +// +// Created by MJ Lee on 14-5-28. +// Copyright (c) 2014年 小码哥. All rights reserved. +// + +#import "UIScrollView+MJExtension.h" +#import + +@implementation UIScrollView (MJExtension) + +- (void)setMj_insetT:(CGFloat)mj_insetT +{ + UIEdgeInsets inset = self.contentInset; + inset.top = mj_insetT; + self.contentInset = inset; +} + +- (CGFloat)mj_insetT +{ + return self.contentInset.top; +} + +- (void)setMj_insetB:(CGFloat)mj_insetB +{ + UIEdgeInsets inset = self.contentInset; + inset.bottom = mj_insetB; + self.contentInset = inset; +} + +- (CGFloat)mj_insetB +{ + return self.contentInset.bottom; +} + +- (void)setMj_insetL:(CGFloat)mj_insetL +{ + UIEdgeInsets inset = self.contentInset; + inset.left = mj_insetL; + self.contentInset = inset; +} + +- (CGFloat)mj_insetL +{ + return self.contentInset.left; +} + +- (void)setMj_insetR:(CGFloat)mj_insetR +{ + UIEdgeInsets inset = self.contentInset; + inset.right = mj_insetR; + self.contentInset = inset; +} + +- (CGFloat)mj_insetR +{ + return self.contentInset.right; +} + +- (void)setMj_offsetX:(CGFloat)mj_offsetX +{ + CGPoint offset = self.contentOffset; + offset.x = mj_offsetX; + self.contentOffset = offset; +} + +- (CGFloat)mj_offsetX +{ + return self.contentOffset.x; +} + +- (void)setMj_offsetY:(CGFloat)mj_offsetY +{ + CGPoint offset = self.contentOffset; + offset.y = mj_offsetY; + self.contentOffset = offset; +} + +- (CGFloat)mj_offsetY +{ + return self.contentOffset.y; +} + +- (void)setMj_contentW:(CGFloat)mj_contentW +{ + CGSize size = self.contentSize; + size.width = mj_contentW; + self.contentSize = size; +} + +- (CGFloat)mj_contentW +{ + return self.contentSize.width; +} + +- (void)setMj_contentH:(CGFloat)mj_contentH +{ + CGSize size = self.contentSize; + size.height = mj_contentH; + self.contentSize = size; +} + +- (CGFloat)mj_contentH +{ + return self.contentSize.height; +} +@end diff --git a/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/UIScrollView+MJRefresh.h b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/UIScrollView+MJRefresh.h new file mode 100644 index 00000000..17d47153 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/UIScrollView+MJRefresh.h @@ -0,0 +1,26 @@ +// 代码地址: https://github.com/CoderMJLee/MJRefresh +// 代码地址: http://code4app.com/ios/%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90%E4%B8%8B%E6%8B%89%E4%B8%8A%E6%8B%89%E5%88%B7%E6%96%B0/52326ce26803fabc46000000 +// UIScrollView+MJRefresh.h +// MJRefreshExample +// +// Created by MJ Lee on 15/3/4. +// Copyright (c) 2015年 小码哥. All rights reserved. +// 给ScrollView增加下拉刷新、上拉刷新的功能 + +#import +#import "MJRefreshConst.h" + +@class MJRefreshHeader, MJRefreshFooter; + +@interface UIScrollView (MJRefresh) +/** 下拉刷新控件 */ +@property (strong, nonatomic) MJRefreshHeader *mj_header; +@property (strong, nonatomic) MJRefreshHeader *header MJRefreshDeprecated("使用mj_header"); +/** 上拉刷新控件 */ +@property (strong, nonatomic) MJRefreshFooter *mj_footer; +@property (strong, nonatomic) MJRefreshFooter *footer MJRefreshDeprecated("使用mj_footer"); + +#pragma mark - other +- (NSInteger)mj_totalDataCount; +@property (copy, nonatomic) void (^mj_reloadDataBlock)(NSInteger totalDataCount); +@end diff --git a/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/UIScrollView+MJRefresh.m b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/UIScrollView+MJRefresh.m new file mode 100644 index 00000000..b1b99426 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/UIScrollView+MJRefresh.m @@ -0,0 +1,163 @@ +// 代码地址: https://github.com/CoderMJLee/MJRefresh +// 代码地址: http://code4app.com/ios/%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90%E4%B8%8B%E6%8B%89%E4%B8%8A%E6%8B%89%E5%88%B7%E6%96%B0/52326ce26803fabc46000000 +// UIScrollView+MJRefresh.m +// MJRefreshExample +// +// Created by MJ Lee on 15/3/4. +// Copyright (c) 2015年 小码哥. All rights reserved. +// + +#import "UIScrollView+MJRefresh.h" +#import "MJRefreshHeader.h" +#import "MJRefreshFooter.h" +#import + +@implementation NSObject (MJRefresh) + ++ (void)exchangeInstanceMethod1:(SEL)method1 method2:(SEL)method2 +{ + method_exchangeImplementations(class_getInstanceMethod(self, method1), class_getInstanceMethod(self, method2)); +} + ++ (void)exchangeClassMethod1:(SEL)method1 method2:(SEL)method2 +{ + method_exchangeImplementations(class_getClassMethod(self, method1), class_getClassMethod(self, method2)); +} + +@end + +@implementation UIScrollView (MJRefresh) + +#pragma mark - header +static const char MJRefreshHeaderKey = '\0'; +- (void)setMj_header:(MJRefreshHeader *)mj_header +{ + if (mj_header != self.mj_header) { + // 删除旧的,添加新的 + [self.mj_header removeFromSuperview]; + [self insertSubview:mj_header atIndex:0]; + + // 存储新的 + [self willChangeValueForKey:@"mj_header"]; // KVO + objc_setAssociatedObject(self, &MJRefreshHeaderKey, + mj_header, OBJC_ASSOCIATION_ASSIGN); + [self didChangeValueForKey:@"mj_header"]; // KVO + } +} + +- (MJRefreshHeader *)mj_header +{ + return objc_getAssociatedObject(self, &MJRefreshHeaderKey); +} + +#pragma mark - footer +static const char MJRefreshFooterKey = '\0'; +- (void)setMj_footer:(MJRefreshFooter *)mj_footer +{ + if (mj_footer != self.mj_footer) { + // 删除旧的,添加新的 + [self.mj_footer removeFromSuperview]; + [self insertSubview:mj_footer atIndex:0]; + + // 存储新的 + [self willChangeValueForKey:@"mj_footer"]; // KVO + objc_setAssociatedObject(self, &MJRefreshFooterKey, + mj_footer, OBJC_ASSOCIATION_ASSIGN); + [self didChangeValueForKey:@"mj_footer"]; // KVO + } +} + +- (MJRefreshFooter *)mj_footer +{ + return objc_getAssociatedObject(self, &MJRefreshFooterKey); +} + +#pragma mark - 过期 +- (void)setFooter:(MJRefreshFooter *)footer +{ + self.mj_footer = footer; +} + +- (MJRefreshFooter *)footer +{ + return self.mj_footer; +} + +- (void)setHeader:(MJRefreshHeader *)header +{ + self.mj_header = header; +} + +- (MJRefreshHeader *)header +{ + return self.mj_header; +} + +#pragma mark - other +- (NSInteger)mj_totalDataCount +{ + NSInteger totalCount = 0; + if ([self isKindOfClass:[UITableView class]]) { + UITableView *tableView = (UITableView *)self; + + for (NSInteger section = 0; section + +@interface UIView (MJExtension) +@property (assign, nonatomic) CGFloat mj_x; +@property (assign, nonatomic) CGFloat mj_y; +@property (assign, nonatomic) CGFloat mj_w; +@property (assign, nonatomic) CGFloat mj_h; +@property (assign, nonatomic) CGSize mj_size; +@property (assign, nonatomic) CGPoint mj_origin; +@end diff --git a/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/UIView+MJExtension.m b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/UIView+MJExtension.m new file mode 100644 index 00000000..7e8eda2d --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/MJRefresh/MJRefresh/UIView+MJExtension.m @@ -0,0 +1,84 @@ +// 代码地址: https://github.com/CoderMJLee/MJRefresh +// 代码地址: http://code4app.com/ios/%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90%E4%B8%8B%E6%8B%89%E4%B8%8A%E6%8B%89%E5%88%B7%E6%96%B0/52326ce26803fabc46000000 +// UIView+Extension.m +// MJRefreshExample +// +// Created by MJ Lee on 14-5-28. +// Copyright (c) 2014年 小码哥. All rights reserved. +// + +#import "UIView+MJExtension.h" + +@implementation UIView (MJExtension) +- (void)setMj_x:(CGFloat)mj_x +{ + CGRect frame = self.frame; + frame.origin.x = mj_x; + self.frame = frame; +} + +- (CGFloat)mj_x +{ + return self.frame.origin.x; +} + +- (void)setMj_y:(CGFloat)mj_y +{ + CGRect frame = self.frame; + frame.origin.y = mj_y; + self.frame = frame; +} + +- (CGFloat)mj_y +{ + return self.frame.origin.y; +} + +- (void)setMj_w:(CGFloat)mj_w +{ + CGRect frame = self.frame; + frame.size.width = mj_w; + self.frame = frame; +} + +- (CGFloat)mj_w +{ + return self.frame.size.width; +} + +- (void)setMj_h:(CGFloat)mj_h +{ + CGRect frame = self.frame; + frame.size.height = mj_h; + self.frame = frame; +} + +- (CGFloat)mj_h +{ + return self.frame.size.height; +} + +- (void)setMj_size:(CGSize)mj_size +{ + CGRect frame = self.frame; + frame.size = mj_size; + self.frame = frame; +} + +- (CGSize)mj_size +{ + return self.frame.size; +} + +- (void)setMj_origin:(CGPoint)mj_origin +{ + CGRect frame = self.frame; + frame.origin = mj_origin; + self.frame = frame; +} + +- (CGPoint)mj_origin +{ + return self.frame.origin; +} +@end diff --git a/IOS/luaviewEx/Example/Pods/MJRefresh/README.md b/IOS/luaviewEx/Example/Pods/MJRefresh/README.md new file mode 100644 index 00000000..aa400578 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/MJRefresh/README.md @@ -0,0 +1,362 @@ +![(logo)](http://images.cnitblog.com/blog2015/497279/201505/051004492043385.png) +## MJRefresh +* An easy way to use pull-to-refresh + +## Contents +* Getting Started + * [Features【Support what kinds of controls to refresh】](#Support what kinds of controls to refresh) + * [Installation【How to use MJRefresh】](#How to use MJRefresh) + * [Who's using【More than hundreds of Apps are using MJRefresh】](#>More than hundreds of Apps are using MJRefresh) + * [Classes【The Class Structure Chart of MJRefresh】](#The Class Structure Chart of MJRefresh) +* Comment API + * [MJRefreshComponent.h](#MJRefreshComponent.h) + * [MJRefreshHeader.h](#MJRefreshHeader.h) + * [MJRefreshFooter.h](#MJRefreshFooter.h) + * [MJRefreshAutoFooter.h](#MJRefreshAutoFooter.h) +* Examples + * [Reference](#Reference) + * [The drop-down refresh 01-Default](#The drop-down refresh 01-Default) + * [The drop-down refresh 02-Animation image](#The drop-down refresh 02-Animation image) + * [The drop-down refresh 03-Hide the time](#The drop-down refresh 03-Hide the time) + * [The drop-down refresh 04-Hide status and time](#The drop-down refresh 04-Hide status and time) + * [The drop-down refresh 05-DIY title](#The drop-down refresh 05-DIY title) + * [The drop-down refresh 06-DIY the control of refresh](#The drop-down refresh 06-DIY the control of refresh) + * [The pull to refresh 01-Default](#The pull to refresh 01-Default) + * [The pull to refresh 02-Animation image](#The pull to refresh 02-Animation image) + * [The pull to refresh 03-Hide the title of refresh status](#The pull to refresh 03-Hide the title of refresh status) + * [The pull to refresh 04-All loaded](#The pull to refresh 04-All loaded) + * [The pull to refresh 05-DIY title](#The pull to refresh 05-DIY title) + * [The pull to refresh 06-Hidden After loaded](#The pull to refresh 06-Hidden After loaded) + * [The pull to refresh 07-Automatic back of the pull01](#上The pull to refresh 07-Automatic back of the pull01) + * [The pull to refresh 08-Automatic back of the pull02](#The pull to refresh 08-Automatic back of the pull02) + * [The pull to refresh 09-DIY the control of refresh(Automatic refresh)](#The pull to refresh 09-DIY the control of refresh(Automatic refresh)) + * [The pull to refresh 10-DIY the control of refresh(Automatic back)](#The pull to refresh 10-DIY the control of refresh(Automatic back)) + * [UICollectionView01-The pull and drop-down refresh](#UICollectionView01-The pull and drop-down refresh) + * [UIWebView01-The drop-down refresh](#UIWebView01-The drop-down refresh) +* [Hope](#Hope) + +## Support what kinds of controls to refresh +* `UIScrollView`、`UITableView`、`UICollectionView`、`UIWebView` + +## How to use MJRefresh +* Installation with CocoaPods:`pod 'MJRefresh'` +* Manual import: + * Drag All files in the `MJRefresh` folder to project + * Import the main file:`#import "MJRefresh.h"` + +```objc +Base Custom +MJRefresh.bundle MJRefresh.h +MJRefreshConst.h MJRefreshConst.m +UIScrollView+MJExtension.h UIScrollView+MJExtension.m +UIScrollView+MJRefresh.h UIScrollView+MJRefresh.m +UIView+MJExtension.h UIView+MJExtension.m +``` + +## More than hundreds of Apps are using MJRefresh + +* More information of App can focus on:[M了个J-博客园](http://www.cnblogs.com/mjios/p/4409853.html) + +## The Class Structure Chart of MJRefresh +![](http://images0.cnblogs.com/blog2015/497279/201506/132232456139177.png) +- `The class of red text` in the chart:You can use them directly + - The drop-down refresh control types + - Normal:`MJRefreshNormalHeader` + - Gif:`MJRefreshGifHeader` + - The pull to refresh control types + - Auto refresh + - Normal:`MJRefreshAutoNormalFooter` + - Gif:`MJRefreshAutoGifFooter` + - Auto Back + - Normal:`MJRefreshBackNormalFooter` + - Gif:`MJRefreshBackGifFooter` +- `The class of non-red text` in the chart:For inheritance,to use DIY the control of refresh +- About how to DIY the control of refresh,You can refer the Class in below Chart
+ + +## MJRefreshComponent.h +```objc +/** The Base Class of refresh control */ +@interface MJRefreshComponent : UIView +#pragma mark - Control the state of Refresh + +/** BeginRefreshing */ +- (void)beginRefreshing; +/** EndRefreshing */ +- (void)endRefreshing; +/** IsRefreshing */ +- (BOOL)isRefreshing; + +#pragma mark - Other +/** According to the drag ratio to change alpha automatically */ +@property (assign, nonatomic, getter=isAutomaticallyChangeAlpha) BOOL automaticallyChangeAlpha; +@end +``` + +## MJRefreshHeader.h +```objc +@interface MJRefreshHeader : MJRefreshComponent +/** Creat header */ ++ (instancetype)headerWithRefreshingBlock:(MJRefreshComponentRefreshingBlock)refreshingBlock; +/** Creat header */ ++ (instancetype)headerWithRefreshingTarget:(id)target refreshingAction:(SEL)action; + +/** This key is used to storage the time that the last time of drown-down successfully */ +@property (copy, nonatomic) NSString *lastUpdatedTimeKey; +/** The last time of drown-down successfully */ +@property (strong, nonatomic, readonly) NSDate *lastUpdatedTime; + +/** Ignored scrollView contentInset top */ +@property (assign, nonatomic) CGFloat ignoredScrollViewContentInsetTop; +@end +``` + +## MJRefreshFooter.h +```objc +@interface MJRefreshFooter : MJRefreshComponent +/** Creat footer */ ++ (instancetype)footerWithRefreshingBlock:(MJRefreshComponentRefreshingBlock)refreshingBlock; +/** Creat footer */ ++ (instancetype)footerWithRefreshingTarget:(id)target refreshingAction:(SEL)action; + +/** NoticeNoMoreData */ +- (void)noticeNoMoreData; +/** ResetNoMoreData(Clear the status of NoMoreData ) */ +- (void)resetNoMoreData; + +/** Ignored scrollView contentInset bottom */ +@property (assign, nonatomic) CGFloat ignoredScrollViewContentInsetBottom; + +/** Automaticlly show or hidden by the count of data(Show-have data,Hidden- no data) */ +@property (assign, nonatomic) BOOL automaticallyHidden; +@end +``` + +## MJRefreshAutoFooter.h +```objc +@interface MJRefreshAutoFooter : MJRefreshFooter +/** Is Automatically Refresh(Default is Yes) */ +@property (assign, nonatomic, getter=isAutomaticallyRefresh) BOOL automaticallyRefresh; + +/** When there is much at the bottom of the control is automatically refresh(Default is 1.0,Is at the bottom of the control appears in full, will refresh automatically) */ +@property (assign, nonatomic) CGFloat triggerAutomaticallyRefreshPercent; +@end +``` + +## Reference +```objc +* Due to there are more functions of this framework,Don't write specific text describe its usage +* You can directly reference examples MJTableViewController、MJCollectionViewController、MJWebViewController,More intuitive and fast. +``` + + +## The drop-down refresh 01-Default + +```objc +self.tableView.header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{ + //Call this Block When enter the refresh status automatically +}]; +或 +// Set the callback(Once you enter the refresh status,then call the action of target,that is call [self loadNewData]) +self.tableView.header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNewData)]; + +// Enter the refresh status immediately +[self.tableView.header beginRefreshing]; +``` +![(下拉刷新01-普通)](http://images0.cnblogs.com/blog2015/497279/201506/141204343486151.gif) + +## The drop-down refresh 02-Animation image +```objc +// Set the callback(一Once you enter the refresh status,then call the action of target,that is call [self loadNewData]) +MJRefreshGifHeader *header = [MJRefreshGifHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNewData)]; +// Set the ordinary state of animated images +[header setImages:idleImages forState:MJRefreshStateIdle]; +// Set the pulling state of animated images(Enter the status of refreshing as soon as loosen) +[header setImages:pullingImages forState:MJRefreshStatePulling]; +// Set the refreshing state of animated images +[header setImages:refreshingImages forState:MJRefreshStateRefreshing]; +// Set header +self.tableView.mj_header = header; +``` +![(下拉刷新02-动画图片)](http://images0.cnblogs.com/blog2015/497279/201506/141204402238389.gif) + +## The drop-down refresh 03-Hide the time +```objc +// Hide the time +header.lastUpdatedTimeLabel.hidden = YES; +``` +![(下拉刷新03-隐藏时间)](http://images0.cnblogs.com/blog2015/497279/201506/141204456132944.gif) + +## The drop-down refresh 04-Hide status and time +```objc +// Hide the time +header.lastUpdatedTimeLabel.hidden = YES; + +// Hide the status +header.stateLabel.hidden = YES; +``` +![(下拉刷新04-隐藏状态和时间0)](http://images0.cnblogs.com/blog2015/497279/201506/141204508639539.gif) + +## The drop-down refresh 05-DIY title +```objc +// Set title +[header setTitle:@"Pull down to refresh" forState:MJRefreshStateIdle]; +[header setTitle:@"Release to refresh" forState:MJRefreshStatePulling]; +[header setTitle:@"Loading ..." forState:MJRefreshStateRefreshing]; + +// Set font +header.stateLabel.font = [UIFont systemFontOfSize:15]; +header.lastUpdatedTimeLabel.font = [UIFont systemFontOfSize:14]; + +// Set textColor +header.stateLabel.textColor = [UIColor redColor]; +header.lastUpdatedTimeLabel.textColor = [UIColor blueColor]; +``` +![(下拉刷新05-自定义文字)](http://images0.cnblogs.com/blog2015/497279/201506/141204563633593.gif) + +## The drop-down refresh 06-DIY the control of refresh +```objc +self.tableView.mj_header = [MJDIYHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNewData)]; +// Implementation reference to MJDIYHeader.h和MJDIYHeader.m +``` +![(下拉刷新06-自定义刷新控件)](http://images0.cnblogs.com/blog2015/497279/201506/141205019261159.gif) + +## The pull to refresh 01-Default +```objc +self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{ + //Call this Block When enter the refresh status automatically +}]; +或 +// Set the callback(Once you enter the refresh status,then call the action of target,that is call [self loadMoreData]) +self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)]; +``` +![(上拉刷新01-默认)](http://images0.cnblogs.com/blog2015/497279/201506/141205090047696.gif) + +## The pull to refresh 02-Animation image +```objc +// Set the callback(Once you enter the refresh status,then call the action of target,that is call [self loadMoreData]) +MJRefreshAutoGifFooter *footer = [MJRefreshAutoGifFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)]; + +// Set the refresh image +[footer setImages:refreshingImages forState:MJRefreshStateRefreshing]; + +// Set footer +self.tableView.mj_footer = footer; +``` +![(上拉刷新02-动画图片)](http://images0.cnblogs.com/blog2015/497279/201506/141205141445793.gif) + +## The pull to refresh 03-Hide the title of refresh status +```objc +// Hide the title of refresh status +footer.refreshingTitleHidden = YES; +// If does have not above method,then use footer.stateLabel.hidden = YES; +``` +![(上拉刷新03-隐藏刷新状态的文字)](http://images0.cnblogs.com/blog2015/497279/201506/141205200985774.gif) + +## The pull to refresh 04-All loaded +```objc +//Become the status of NoMoreData +[footer noticeNoMoreData]; +``` +![(上拉刷新04-全部加载完毕)](http://images0.cnblogs.com/blog2015/497279/201506/141205248634686.gif) + +## The pull to refresh 05-DIY title +```objc +// Set title +[footer setTitle:@"Click or drag up to refresh" forState:MJRefreshStateIdle]; +[footer setTitle:@"Loading more ..." forState:MJRefreshStateRefreshing]; +[footer setTitle:@"No more data" forState:MJRefreshStateNoMoreData]; + +// Set font +footer.stateLabel.font = [UIFont systemFontOfSize:17]; + +// Set textColor +footer.stateLabel.textColor = [UIColor blueColor]; +``` +![(上拉刷新05-自定义文字)](http://images0.cnblogs.com/blog2015/497279/201506/141205295511153.gif) + +## The pull to refresh 06-Hidden After loaded +```objc +//Hidden current control of the pull to refresh +self.tableView.mj_footer.hidden = YES; +``` +![(上拉刷新06-加载后隐藏)](http://images0.cnblogs.com/blog2015/497279/201506/141205343481821.gif) + +## The pull to refresh 07-Automatic back of the pull01 +```objc +self.tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)]; +``` +![(上拉刷新07-自动回弹的上拉01)](http://images0.cnblogs.com/blog2015/497279/201506/141205392239231.gif) + +## The pull to refresh 08-Automatic back of the pull02 +```objc +MJRefreshBackGifFooter *footer = [MJRefreshBackGifFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)]; + +// Set the normal state of the animated image +[footer setImages:idleImages forState:MJRefreshStateIdle]; +// Set the pulling state of animated images(Enter the status of refreshing as soon as loosen) +[footer setImages:pullingImages forState:MJRefreshStatePulling]; +// Set the refreshing state of animated images +[footer setImages:refreshingImages forState:MJRefreshStateRefreshing]; + +// Set footer +self.tableView.mj_footer = footer; +``` +![(上拉刷新07-自动回弹的上拉02)](http://images0.cnblogs.com/blog2015/497279/201506/141205441443628.gif) + +## The pull to refresh 09-DIY the control of refresh(Automatic refresh) +```objc +self.tableView.mj_footer = [MJDIYAutoFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)]; +// Implementation reference to MJDIYAutoFooter.h和MJDIYAutoFooter.m +``` +![(上拉刷新09-自定义刷新控件(自动刷新))](http://images0.cnblogs.com/blog2015/497279/201506/141205500195866.gif) + +## The pull to refresh 10-DIY the control of refresh(Automatic back) +```objc +self.tableView.mj_footer = [MJDIYBackFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)]; +// Implementation reference to MJDIYBackFooter.h和MJDIYBackFooter.m +``` +![(上拉刷新10-自定义刷新控件(自动回弹))](http://images0.cnblogs.com/blog2015/497279/201506/141205560666819.gif) + +## UICollectionView01-The pull and drop-down refresh +```objc +// The drop-down refresh +self.collectionView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{ + //Call this Block When enter the refresh status automatically +}]; + +// The pull to refresh +self.collectionView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{ + //Call this Block When enter the refresh status automatically +}]; +``` +![(UICollectionView01-上下拉刷新)](http://images0.cnblogs.com/blog2015/497279/201506/141206021603758.gif) + +## UIWebView01-The drop-down refresh +```objc +//Add the control of The drop-down refresh +self.webView.scrollView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{ + //Call this Block When enter the refresh status automatically +}]; +``` +![(UICollectionView01-上下拉刷新)](http://images0.cnblogs.com/blog2015/497279/201506/141206080514524.gif) + +## Remind +* ARC +* iOS>=6.0 +* iPhone \ iPad screen anyway + +## Hope +* If you find bug when used,Hope you can Issues me,Thank you or try to download the latest code of this framework to see the BUG has been fixed or not) +* If you find the function is not enough when used,Hope you can Issues me,I very much to add more useful function to this framework ,Thank you ! +* If you want to contribute code for MJRefresh,please Pull Requests me +* If you use MJRefresh in your develop app,Hope you can go to[CocoaControls](https://www.cocoacontrols.com/controls/mjrefresh)to add the iTunes path + of you app,I Will install your app,and according to the usage of many app,to be a better design and improve to MJRefresh,Thank you ! + * StepO1(WeChat is just an Example,Explore“Your app name itunes”) +![(step01)](http://ww4.sinaimg.cn/mw1024/800cdf9ctw1eq0viiv5rsj20sm0ea41t.jpg) + * StepO2 +![(step02)](http://ww2.sinaimg.cn/mw1024/800cdf9ctw1eq0vilejxlj20tu0me7a0.jpg) + * StepO3 +![(step03)](http://ww1.sinaimg.cn/mw1024/800cdf9ctw1eq0viocpo5j20wc0dc0un.jpg) + * StepO4 +![(step04)](http://ww3.sinaimg.cn/mw1024/800cdf9ctw1eq0vir137xj20si0gewgu.jpg) diff --git a/IOS/luaviewEx/Example/Pods/Manifest.lock b/IOS/luaviewEx/Example/Pods/Manifest.lock new file mode 100644 index 00000000..b45b73d3 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Manifest.lock @@ -0,0 +1,35 @@ +PODS: + - luaviewEx (0.1.0): + - LuaViewSDK + - SDWebImage (~> 3.7.5) + - LuaViewSDK (2.5.16.5) + - MJRefresh (3.1.12) + - SDWebImage (3.7.5): + - SDWebImage/Core (= 3.7.5) + - SDWebImage/Core (3.7.5) + +DEPENDENCIES: + - luaviewEx (from `../`) + - LuaViewSDK (from `https://github.com/alibaba/LuaViewSDK.git`, branch `develop`) + - MJRefresh + - SDWebImage (= 3.7.5) + +EXTERNAL SOURCES: + luaviewEx: + :path: ../ + LuaViewSDK: + :branch: develop + :git: https://github.com/alibaba/LuaViewSDK.git + +CHECKOUT OPTIONS: + LuaViewSDK: + :commit: fd209f64bebecc12347f772446ac1b8ffc8eef4d + :git: https://github.com/alibaba/LuaViewSDK.git + +SPEC CHECKSUMS: + luaviewEx: 6fd6581868833a6b12a26b77b5eb352c36b70167 + LuaViewSDK: 54bae1ca82369020590e4b4db5b7a9a552f8abbb + MJRefresh: 11e1c9d86f2093ddcdbda7836bc2da477ddf568d + SDWebImage: 033e39d6f389724696c4d790b4daffcb4395a9f6 + +COCOAPODS: 0.39.0 diff --git a/IOS/luaviewEx/Example/Pods/Pods.xcodeproj/project.pbxproj b/IOS/luaviewEx/Example/Pods/Pods.xcodeproj/project.pbxproj new file mode 100644 index 00000000..b12b7e75 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Pods.xcodeproj/project.pbxproj @@ -0,0 +1,10467 @@ + + + + + archiveVersion + 1 + classes + + objectVersion + 46 + objects + + 0017127DB94CC6F1B9726D2ABF338D97 + + fileRef + D5E21862F3A5E53844655108A7B7E9AF + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 003669CF9C13F30F337B75D1277C9EE5 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LVImage.h + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVImage.h + sourceTree + <group> + + 00366E6D1CE623FE38FC0701EAB25A08 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + MJRefreshFooter.h + path + MJRefresh/Base/MJRefreshFooter.h + sourceTree + <group> + + 007AA33BCC40F1B83EF19655BA2F1199 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LVRotationGesture.h + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRotationGesture.h + sourceTree + <group> + + 00C6711300727CE3A2D7A80B99BD48AF + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVScrollView.m + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVScrollView.m + sourceTree + <group> + + 00E558B8093CD20D8ED2FA16EED9C9C5 + + fileRef + DA43BA0061AF4BF9BF2135E29B1A9076 + isa + PBXBuildFile + + 015874845E892063530B701C4B563886 + + fileRef + 838A78E077C0BD584472E06993CB3839 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 017115128E6833F9CC8D749E5B0A53AC + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LVLuaObjBox.h + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLuaObjBox.h + sourceTree + <group> + + 0188CA054AC3498974F6477FF90D8ECD + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + lundump.h + path + IOS/lua/lua/lundump.h + sourceTree + <group> + + 01B7F7F27F221C2D9F4F10B8A7EC25C9 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + lstring.h + path + IOS/lua/lua/lstring.h + sourceTree + <group> + + 023E7263521C3044AE972C99F20ACCF4 + + includeInIndex + 1 + isa + PBXFileReference + name + loadlib.c + path + IOS/lua/lua/loadlib.c + sourceTree + <group> + + 02C66FB7DB87FC2EB3AF533E0EF74677 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + JUFLXNode.h + path + IOS/SDK/LuaViewSDK/Classes/layout/JUFLXNode.h + sourceTree + <group> + + 02DD81852450DF997CE182D2E8B96094 + + includeInIndex + 1 + isa + PBXFileReference + name + ldump.c + path + IOS/lua/lua/ldump.c + sourceTree + <group> + + 035A2B93F59B66DD593DBFDA4DBE902A + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVExCollectionView.h + sourceTree + <group> + + 035D3067B44ACFD87A44EAEA19EAD13D + + includeInIndex + 1 + isa + PBXFileReference + path + slaxdom.lua + sourceTree + <group> + + 03ADB1EE211113EC9C3B9167F0A4DB0A + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + UIView+LuaView.h + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/UIView+LuaView.h + sourceTree + <group> + + 03EA78459B07E810AB6C86D73371C652 + + fileRef + A43792C99C7568064B453B7EB1E731F2 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 04A2311BCAE1C0E272C6B1C787F36C3C + + fileRef + C5E35B18C85702FF9D410ED1F4E1C927 + isa + PBXBuildFile + + 04C1DB49FA812C21EEEBEE206A0ED54E + + buildConfigurations + + 96C3FCB7C0C4F9CFA4C03B396CA2A069 + 329DCDA56DD96D91BF81795302D64BBB + + defaultConfigurationIsVisible + 0 + defaultConfigurationName + Release + isa + XCConfigurationList + + 04FF9374848B71D08B51B424BD01CC64 + + fileRef + 649039ECE2B1D879861962C561AE479B + isa + PBXBuildFile + + 0500581B0DC1F609E6FF4F6D2442AFFA + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + text.plist.xml + path + Pods-luaviewEx_Example-acknowledgements.plist + sourceTree + <group> + + 0530B9C172A90C4EBEBB5D9A856A0CED + + fileRef + 4789F07E9F42154904330D02D37FB8CE + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 05BE865A8FF612F7CA84B35D9FA0EEBC + + fileRef + 30A1F8989B983EEB0E4F94E9E8E4FEB0 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 05D798E3E6D13DE52512EE4E6E91B1A2 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + luaviewEx-dummy.m + sourceTree + <group> + + 068DDA81A2C94C892D7F5F299A8E5E0C + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVPanGesture.m + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPanGesture.m + sourceTree + <group> + + 081204C328A1EB30463CFEDB4BB4FA6E + + fileRef + CF453FA45EFCDB74BC1A5F5F33BBC71F + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 08541999325B18DF76249F7305CFAF42 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LVStruct.h + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVStruct.h + sourceTree + <group> + + 08563DD6038B20ED6CF2EDA7C0DD0508 + + fileRef + 0ADF4BFF3F3CB2B0076ECC7EEDED7AA0 + isa + PBXBuildFile + + 088CCD3BADDAEDB931433BB0EC67F856 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + MJRefreshAutoFooter.m + path + MJRefresh/Base/MJRefreshAutoFooter.m + sourceTree + <group> + + 09ABAD4C3D76DFD8494DE962D57E110D + + fileRef + 2A813CC1F4A5B53EB94414FE3499E239 + isa + PBXBuildFile + + 09B58A84FA82B323D09A5242FC2B5791 + + fileRef + 14C63F1ED1E755422CAD72947BB6854E + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 0A4F5042D8E5452A3BA410BCA130BACA + + fileRef + BB6CD102046C6DCE7A34320FC72DBA4D + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 0A6A56AAB0CCC271312FC044BE654DD5 + + fileRef + 7415E077E9F712607D4A69B6EF4E3A99 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 0A7BC5CF629164867EF9BFC779DB9905 + + fileRef + 5AC21404A4384C42C5EC654668A27CC2 + isa + PBXBuildFile + + 0ACB826940D91D6F0E3B839BC7EA70A2 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + SDWebImageDownloaderOperation.m + path + SDWebImage/SDWebImageDownloaderOperation.m + sourceTree + <group> + + 0ADF4BFF3F3CB2B0076ECC7EEDED7AA0 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVCustomView.m + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCustomView.m + sourceTree + <group> + + 0BA6BF787BE2139B97022DBF837C477A + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + MJRefreshConst.h + path + MJRefresh/MJRefreshConst.h + sourceTree + <group> + + 0D42DBBCE5B87DF9D609A6E887B9018B + + fileRef + EEF29B31E969DD77D33BCCB6F665FF96 + isa + PBXBuildFile + + 0D8B62C0984BC350ECBE7CC39F0060F7 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVUtil.m + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVUtil.m + sourceTree + <group> + + 0DA2D9EFDDF4C3FC2D398B83D445ACBC + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVAlert.m + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAlert.m + sourceTree + <group> + + 0DACA354A687AC4660BA27C1AA7381C1 + + fileRef + A622A17FCDB47B180FCD298CCF93321F + isa + PBXBuildFile + settings + + COMPILER_FLAGS + -DOS_OBJECT_USE_OBJC=0 + + + 0E7F78556C26EF63F32574BA1D25E267 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LVPkgManager.h + path + IOS/SDK/LuaViewSDK/Classes/PKG/LVPkgManager.h + sourceTree + <group> + + 0F076CFF2E138CFA704722866DCE9782 + + fileRef + 325C3C570A4FDB3EBF50C0A7B13F91BF + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 0F8460769F8CD781A2B6406866DCA320 + + fileRef + CCBA5EC0FEAC0C022D514664CB0A8F9B + isa + PBXBuildFile + settings + + COMPILER_FLAGS + -DOS_OBJECT_USE_OBJC=0 + + + 0FF8ED2CB0D78645C2BB66738DC66614 + + baseConfigurationReference + 4504CC614A2B924DE6865AB69C9ACA8F + buildSettings + + ENABLE_STRICT_OBJC_MSGSEND + YES + IPHONEOS_DEPLOYMENT_TARGET + 8.3 + MACH_O_TYPE + staticlib + MTL_ENABLE_DEBUG_INFO + NO + OTHER_LDFLAGS + + OTHER_LIBTOOLFLAGS + + PODS_ROOT + $(SRCROOT) + PRODUCT_NAME + $(TARGET_NAME) + SDKROOT + iphoneos + SKIP_INSTALL + YES + + isa + XCBuildConfiguration + name + Release + + 1029FE5B1649EC32DB1502473DD8C938 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + MJRefresh-dummy.m + sourceTree + <group> + + 10DE1947DAC0ED28F6C0A9F9BD75D546 + + buildSettings + + ALWAYS_SEARCH_USER_PATHS + NO + CLANG_CXX_LANGUAGE_STANDARD + gnu++0x + CLANG_CXX_LIBRARY + libc++ + CLANG_ENABLE_MODULES + YES + CLANG_ENABLE_OBJC_ARC + YES + CLANG_WARN_BOOL_CONVERSION + YES + CLANG_WARN_CONSTANT_CONVERSION + YES + CLANG_WARN_DIRECT_OBJC_ISA_USAGE + YES + CLANG_WARN_EMPTY_BODY + YES + CLANG_WARN_ENUM_CONVERSION + YES + CLANG_WARN_INT_CONVERSION + YES + CLANG_WARN_OBJC_ROOT_CLASS + YES + CLANG_WARN_UNREACHABLE_CODE + YES + CLANG_WARN__DUPLICATE_METHOD_MATCH + YES + COPY_PHASE_STRIP + YES + ENABLE_NS_ASSERTIONS + NO + GCC_C_LANGUAGE_STANDARD + gnu99 + GCC_PREPROCESSOR_DEFINITIONS + + RELEASE=1 + + GCC_WARN_64_TO_32_BIT_CONVERSION + YES + GCC_WARN_ABOUT_RETURN_TYPE + YES + GCC_WARN_UNDECLARED_SELECTOR + YES + GCC_WARN_UNINITIALIZED_AUTOS + YES + GCC_WARN_UNUSED_FUNCTION + YES + GCC_WARN_UNUSED_VARIABLE + YES + IPHONEOS_DEPLOYMENT_TARGET + 8.3 + STRIP_INSTALLED_PRODUCT + NO + SYMROOT + ${SRCROOT}/../build + VALIDATE_PRODUCT + YES + + isa + XCBuildConfiguration + name + Release + + 11145200D88F9ABAEEDDD26FEAB3641F + + fileRef + DD9AED002BD0179835C99F308950D01E + isa + PBXBuildFile + + 1200BA0573F489F9E987B6963A9881F3 + + includeInIndex + 1 + isa + PBXFileReference + name + lstrlib.c + path + IOS/lua/lua/lstrlib.c + sourceTree + <group> + + 128A64434D403A522E70D656178107E3 + + fileRef + 007AA33BCC40F1B83EF19655BA2F1199 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 12B5D15073B33A3A1CC86A97D66EBFA1 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + MJRefreshComponent.h + path + MJRefresh/Base/MJRefreshComponent.h + sourceTree + <group> + + 12D1D6C08777961A0F9E3FA5C0E64F8D + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVSwipeGesture.m + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVSwipeGesture.m + sourceTree + <group> + + 1303734F66CF41E1C7547B22B2B51AD1 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + NSBundle+MJRefresh.m + path + MJRefresh/NSBundle+MJRefresh.m + sourceTree + <group> + + 140A5FB3CE8CE79A82BF9395EA69294E + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LuaViewCore.h + path + IOS/SDK/LuaViewSDK/Classes/LuaViewCore.h + sourceTree + <group> + + 1453C4742639DC29E77A2A397333AB6A + + buildConfigurationList + 7CEAC01A2F196CDB49C6A2DBC45CE165 + buildPhases + + 4AA507206EE37C421EED5D7726A966E4 + F833457C4CDBB69A21839521C6C2AD5B + A8C4C2E0AD93FEE59249EE59CD760E4C + + buildRules + + dependencies + + C68D95FDE83929CBBE8BADCC16B14E69 + 4A302094BECFD7BA587E9271E568D676 + DA9257B35361B576E0A3D77062933847 + + isa + PBXNativeTarget + name + luaviewEx + productName + luaviewEx + productReference + 42EC6A04605A1C80044D476FBE2538DF + productType + com.apple.product-type.library.static + + 14ADE1102C757429A486CC0EEFF7163F + + fileRef + 3A3CA36EEC437FF1F5F822907899DD0C + isa + PBXBuildFile + + 14B8B9B15ECBE87983FF987239AB2D7B + + children + + 31E4C72577D34E089E65548C02EAF060 + + isa + PBXGroup + name + Frameworks + sourceTree + <group> + + 14C63F1ED1E755422CAD72947BB6854E + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LVLongPressGesture.h + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLongPressGesture.h + sourceTree + <group> + + 14DDA98CD559DD9E76DA63FEF44098AF + + buildConfigurations + + D2318D2B236AD2B42AEFA3409D6462F5 + A548B95FD1ADA614C553F9ED2356FE81 + + defaultConfigurationIsVisible + 0 + defaultConfigurationName + Release + isa + XCConfigurationList + + 14E611D7FB8EBE58F4FE02103F29ADAE + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVLabel.m + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLabel.m + sourceTree + <group> + + 152E41D8C9AFCAE78F5FA1E151BDBD65 + + fileRef + A33D174EBE777C4C8E31B053AC15D45D + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 15381D52480D9DD90D0131DFF8425DCA + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + UIImage+GIF.m + path + SDWebImage/UIImage+GIF.m + sourceTree + <group> + + 15ED53A5A5A5B880F95660EAB6572A7F + + buildActionMask + 2147483647 + files + + EC0A52132E4476FCCA78F5317059C023 + 360078647E2A038629551ADB65160999 + 7FC6D87D4BEABED4013BAFFC3093A89E + 829CA47C496203FEC6159E8DC09E2BDD + 5F21804D426E53A98AAB3032DFC2E82D + 0F8460769F8CD781A2B6406866DCA320 + E2666B34BAA41A7620A5214CEBE2CE98 + 6E25ECB2BD596CE0B10558B8BADA9DC3 + D56ED68ACC53224CD4BC37A6B5BC6EB1 + 0DACA354A687AC4660BA27C1AA7381C1 + AB1C015FB3D658D34C87EF822357A84B + 778804E48E78E0C2D04C5655C38C53B7 + 65A01D6211BE640201D7E62B62202D6F + 4D3EDCA5FF555D595536CC4A60E6B5DF + 2F925A4AD500FFE852B7EAC04625EE91 + + isa + PBXSourcesBuildPhase + runOnlyForDeploymentPostprocessing + 0 + + 1684D43653C66CECE3818AB69199DBA9 + + fileRef + B2ED8EC46C5618309FDADA00EDAAB038 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 16FC40655B7DE4E187C610A87B44A4A5 + + fileRef + 54E7640CB88EF3B2F9E4C730D4C254BB + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 171B1BADE853597D819B610B8E8FD83C + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LVSwipeGesture.h + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVSwipeGesture.h + sourceTree + <group> + + 1750E8156D634B9DCFCBDF366430F326 + + fileRef + 20F76BE16D5CEA070DB21524AC219E16 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 175B696A75D2EC87BF53C6C0D407A678 + + fileRef + 035A2B93F59B66DD593DBFDA4DBE902A + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 17A8628061070C222D27D34F72F83DF3 + + includeInIndex + 1 + isa + PBXFileReference + name + lobject.c + path + IOS/lua/lua/lobject.c + sourceTree + <group> + + 187EF30C8816993691A5B142EBB7CB36 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + UIView+JUFLXNode.m + path + IOS/SDK/LuaViewSDK/Classes/layout/UIView+JUFLXNode.m + sourceTree + <group> + + 193350A2E9DA407F2917FF58833B85DC + + fileRef + 5BEFD624052F9D9B420664CB47C04C2E + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 1936A2F7295154DE613E6EC820526985 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVNinePatchImage.m + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNinePatchImage.m + sourceTree + <group> + + 19BA6CF23E4A6871720A4118364C09EF + + fileRef + DBF475EA219170B3C68BB1446AE8C55A + isa + PBXBuildFile + + 1A2815B7EA1C751193B90C3CBC87E3FF + + fileRef + CA21EF19F2493AB60C8C0561BA72552A + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 1A4C40BEE34C7100C87D3EA0409B2277 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LVNavigation.h + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNavigation.h + sourceTree + <group> + + 1A54CE3B4BB248552036DB35C1EE2A8E + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVPkgInfo.m + path + IOS/SDK/LuaViewSDK/Classes/PKG/LVPkgInfo.m + sourceTree + <group> + + 1A891937EF4FE3E738E08AF8DF1960BE + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVRSA.m + path + IOS/SDK/LuaViewSDK/Classes/RSA/LVRSA.m + sourceTree + <group> + + 1BD1FEB3E27E055C9425C85436DCAC2F + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVFlowLayout.m + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVFlowLayout.m + sourceTree + <group> + + 1C72D47259AD02A2958DE9AC84C7BC4C + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + MJRefreshHeader.h + path + MJRefresh/Base/MJRefreshHeader.h + sourceTree + <group> + + 1D19AA05C372AF3EFD35A2AD28F4D8BD + + includeInIndex + 1 + isa + PBXFileReference + path + pica.lua + sourceTree + <group> + + 1D6054D63442F671F8D09855592CB662 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVExImage.h + sourceTree + <group> + + 1E455130CD554E363685BBC7EDB1AACE + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + text.xcconfig + path + LuaViewSDK.xcconfig + sourceTree + <group> + + 1E63B736F14800F163BEE98F2656AB57 + + includeInIndex + 1 + isa + PBXFileReference + name + lstate.c + path + IOS/lua/lua/lstate.c + sourceTree + <group> + + 1E6B9968B212F59E3B0F27CB3FBFC8BF + + buildActionMask + 2147483647 + files + + isa + PBXSourcesBuildPhase + runOnlyForDeploymentPostprocessing + 0 + + 1E88082E67EECA1458FA24BBF7677908 + + fileRef + 12B5D15073B33A3A1CC86A97D66EBFA1 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 1EE667E76E8DE6FA80C6611D3FD1781E + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LVTypeConvert.h + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTypeConvert.h + sourceTree + <group> + + 1F48696AD698115D898EC7CCD60D075A + + fileRef + 2953440B280C7D7881037E1325598E5D + isa + PBXBuildFile + + 1FB2A9CD333316F15BDBD47C0ECBB3F6 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LVUtil.h + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVUtil.h + sourceTree + <group> + + 2011B45A98326F01DE4AB680BF2395E5 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + SDImageCache.m + path + SDWebImage/SDImageCache.m + sourceTree + <group> + + 203B879A967F66A09F7417445102D54F + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LVPkgInfo.h + path + IOS/SDK/LuaViewSDK/Classes/PKG/LVPkgInfo.h + sourceTree + <group> + + 208EED9D527973A149D9358AA3702EB4 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LVBundle.h + path + IOS/SDK/LuaViewSDK/Classes/LVBundle.h + sourceTree + <group> + + 20A1DA8983367E7543A28C13AC5F823B + + fileRef + F415216825466C77176DE9B6A714414F + isa + PBXBuildFile + + 20A306972C1A8633ECE0E1237822BB61 + + buildConfigurations + + F3BD82EE8CAB6FC8B410C0865280E598 + 70F7476823A575DF873A0835BCD42F85 + + defaultConfigurationIsVisible + 0 + defaultConfigurationName + Release + isa + XCConfigurationList + + 20C72AFB4286BDD05462A4F78B6B03BF + + fileRef + 6891D507788A858BA1297B6942E967F4 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 20F76BE16D5CEA070DB21524AC219E16 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + MJRefreshBackFooter.h + path + MJRefresh/Base/MJRefreshBackFooter.h + sourceTree + <group> + + 2172479607CC3CD63DA704312491E457 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + UIScrollView+LuaView.m + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/UIScrollView+LuaView.m + sourceTree + <group> + + 2265B12C49637BF869C3E36882EA82D2 + + includeInIndex + 1 + isa + PBXFileReference + path + sys.lua + sourceTree + <group> + + 226E0928F49DF341E97BD79ADADEBD8D + + fileRef + 35ADDF72B83994A75288FF85E354EEB7 + isa + PBXBuildFile + + 229042DE27C75966B85403855D4866E9 + + fileRef + A54FD7B60AF2B1A67ABE81FD1A4A9300 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 22C7129862982EDC0F0620281C94434B + + fileRef + E775D30242799951B07F95972F3E44F0 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 22DFFF53B43BF3B0CCD41940725C77DD + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LVEvent.h + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVEvent.h + sourceTree + <group> + + 233AE6BDA52AF2078C6419CF8B097EA4 + + fileRef + 51EE67DEF356B157B9FC9DAC2821122B + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 233DD3C1DDCD00EB6DB13CF90A48DA85 + + fileRef + 1A891937EF4FE3E738E08AF8DF1960BE + isa + PBXBuildFile + + 239AAEA5FF56DB47A6C061BB0277582E + + includeInIndex + 1 + isa + PBXFileReference + path + copy-framework-resources.rb + sourceTree + <group> + + 23AF67BE150039A0C7AB1436EA782A9D + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LVLoadingIndicator.h + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLoadingIndicator.h + sourceTree + <group> + + 23EF01C652B4106BB0265EE3714CE1E7 + + fileRef + A4A212231C1652C2163EA475935BC083 + isa + PBXBuildFile + + 24172D119E9B5A38073722CED950B86E + + fileRef + 17A8628061070C222D27D34F72F83DF3 + isa + PBXBuildFile + + 2427E2F0CA20B2924D366EA986934663 + + fileRef + 537BC05E46F49890B5734D960924FEAF + isa + PBXBuildFile + + 2434DE58B225AAE5BE481F58D245FF45 + + fileRef + 1E63B736F14800F163BEE98F2656AB57 + isa + PBXBuildFile + + 248AB64F8D0EE3AAC0FF476C689744D6 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVMethod.m + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVMethod.m + sourceTree + <group> + + 24ACDAAE48ECC19C32A56CE5DE769C97 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + SDWebImagePrefetcher.m + path + SDWebImage/SDWebImagePrefetcher.m + sourceTree + <group> + + 24DC94EC0212D4697446E8ADFAA14FA6 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + NSData+ImageContentType.h + path + SDWebImage/NSData+ImageContentType.h + sourceTree + <group> + + 25AA72266E278F67F1AF500807F2A82E + + children + + C1B386F18083FEBE0DF0528794C232C7 + BE108B26C574235B74731390BDF3446E + 627B8671EF21E786E5CFDDE0D01EA3C5 + + isa + PBXGroup + name + Pods + sourceTree + <group> + + 25D9F3CA59FDF03A99EC82DDC3FA2199 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + NSObject+LuaView.m + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/NSObject+LuaView.m + sourceTree + <group> + + 25F8ABDD1532A296D8F95098E2E0A972 + + isa + PBXFileReference + lastKnownFileType + wrapper.framework + name + Foundation.framework + path + Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.0.sdk/System/Library/Frameworks/Foundation.framework + sourceTree + DEVELOPER_DIR + + 26639D12A9E924056B894755C310DC6A + + includeInIndex + 1 + isa + PBXFileReference + name + lstring.c + path + IOS/lua/lua/lstring.c + sourceTree + <group> + + 28D2995468C43DFDB5427BAF0E6685FE + + fileRef + BD8D6B4379E00E28A7D857559B9F24EB + isa + PBXBuildFile + + 28EFF26D92109EA51AD70F2E8673D19E + + fileRef + 25D9F3CA59FDF03A99EC82DDC3FA2199 + isa + PBXBuildFile + + 2953440B280C7D7881037E1325598E5D + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + MJRefreshBackStateFooter.m + path + MJRefresh/Custom/Footer/Back/MJRefreshBackStateFooter.m + sourceTree + <group> + + 295C0410F34CCFB29B0BDC50D310CA1E + + fileRef + 93E455E14459988C5B3FC784AC706191 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 298D19C714ABD4E02CCA49264EB174F7 + + fileRef + 9062C31E489D11885922F6D9606B893A + isa + PBXBuildFile + + 29EA1ACE2211DB8593A117A2AEDC029D + + baseConfigurationReference + A70095A630FF08A50442B16D1B37308C + buildSettings + + ENABLE_STRICT_OBJC_MSGSEND + YES + GCC_PREFIX_HEADER + Target Support Files/luaviewEx/luaviewEx-prefix.pch + IPHONEOS_DEPLOYMENT_TARGET + 8.3 + MTL_ENABLE_DEBUG_INFO + YES + OTHER_LDFLAGS + + OTHER_LIBTOOLFLAGS + + PRIVATE_HEADERS_FOLDER_PATH + + PRODUCT_NAME + $(TARGET_NAME) + PUBLIC_HEADERS_FOLDER_PATH + + SDKROOT + iphoneos + SKIP_INSTALL + YES + + isa + XCBuildConfiguration + name + Debug + + 29EC4AF2D4278E4C86F9D0BD8E8F9CFF + + fileRef + E1105AB3312E4B4559361BFB90F71113 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 2A00E5624756359F3C35FD75432F1CDD + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVPagerView.m + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPagerView.m + sourceTree + <group> + + 2A247B0578AFFD9B75A4AA66AF325AD6 + + fileRef + A0D2A3B993113E8AF1A63CA5189A8860 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 2A26C65B20259D5561282FF13EFB71B4 + + fileRef + 78DD0AF22BF0E3660FC4CD8E74211F6B + isa + PBXBuildFile + + 2A813CC1F4A5B53EB94414FE3499E239 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVPagerViewCell.m + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPagerViewCell.m + sourceTree + <group> + + 2AF980C40415822FFD9E3B034D285AFD + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + SDWebImageOperation.h + path + SDWebImage/SDWebImageOperation.h + sourceTree + <group> + + 2BA16F5CCD3F1E210008D8280A170F1B + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + UIScrollView+LVRefresh.h + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/UIScrollView+LVRefresh.h + sourceTree + <group> + + 2BFAE640B346B9070B1B3F22B86B56EE + + fileRef + BDA6A83655BB36F3747E5F7BD91D5F84 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 2C89DDAB3F53D427C477F8F040FF1598 + + fileRef + 140A5FB3CE8CE79A82BF9395EA69294E + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 2CB0D82457327C3E9202EF86FC9FD46E + + fileRef + 4C79E04329C138C91B4F7F5CF3FB92C7 + isa + PBXBuildFile + + 2CEF57B3C0FB4E9BB5127662BC6C2E1D + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + MJRefreshAutoGifFooter.m + path + MJRefresh/Custom/Footer/Auto/MJRefreshAutoGifFooter.m + sourceTree + <group> + + 2D15CD985562C9AF0C1DDA3EEF4F1EA3 + + fileRef + BAA4CCA3BCB98A42C54C87DEFDC3EA86 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 2D7FBA552B3CED667D78641BD3DEF96C + + fileRef + A7A35A14EB2A583EF86EA849BDF36947 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 2D8E8EC45A3A1A1D94AE762CB5028504 + + buildConfigurations + + 552D02D5BA751AC2E8790D2811D496CA + 10DE1947DAC0ED28F6C0A9F9BD75D546 + + defaultConfigurationIsVisible + 0 + defaultConfigurationName + Release + isa + XCConfigurationList + + 2E1E59F6FBDA7901F0AD952037FCF736 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + MJRefreshAutoStateFooter.h + path + MJRefresh/Custom/Footer/Auto/MJRefreshAutoStateFooter.h + sourceTree + <group> + + 2E2BD15CBDAF008E187B120F43D8A160 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + lstate.h + path + IOS/lua/lua/lstate.h + sourceTree + <group> + + 2E3ADBD6F47F2B2D01784DB392D0030F + + isa + PBXTargetDependency + name + LuaViewSDK + target + 4F318E6CB32EF6E77C176A2A5ACC0B17 + targetProxy + 4CED673A1CD51BD6238015DD2A576C5B + + 2F4989EC176405BACD5E4338909B2D7E + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + text.xcconfig + path + Pods-luaviewEx_Example.debug.xcconfig + sourceTree + <group> + + 2F4A25979F4326CF43F387B4CD7A9387 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVZipArchive.m + path + IOS/SDK/LuaViewSDK/Classes/PKG/LVZipArchive.m + sourceTree + <group> + + 2F925A4AD500FFE852B7EAC04625EE91 + + fileRef + F85FB92DB3CBF2A0853930794C17822D + isa + PBXBuildFile + settings + + COMPILER_FLAGS + -DOS_OBJECT_USE_OBJC=0 + + + 2F9A7A47600CDB37C8959464A2DBF204 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + text.script.sh + path + Pods-luaviewEx_Example-resources.sh + sourceTree + <group> + + 2FBD447B4E903BDF71EACEB55B8C68C5 + + fileRef + 31603E2B84E9141B15192CB5F08073EA + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 2FC9D5C93502F8C8120502B2AF56E419 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + UIImageView+HighlightedWebCache.m + path + SDWebImage/UIImageView+HighlightedWebCache.m + sourceTree + <group> + + 3076D7998BCE2564AC10D34F4E35919C + + children + + 239AAEA5FF56DB47A6C061BB0277582E + DCEA9B91A91B8834D6805B841A16C9BF + 0500581B0DC1F609E6FF4F6D2442AFFA + DBF475EA219170B3C68BB1446AE8C55A + C768C62C080C06511C4FAD0DD3C75DC8 + 2F9A7A47600CDB37C8959464A2DBF204 + 2F4989EC176405BACD5E4338909B2D7E + 4504CC614A2B924DE6865AB69C9ACA8F + + isa + PBXGroup + name + Pods-luaviewEx_Example + path + Target Support Files/Pods-luaviewEx_Example + sourceTree + <group> + + 30A1F8989B983EEB0E4F94E9E8E4FEB0 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + SDWebImageManager.h + path + SDWebImage/SDWebImageManager.h + sourceTree + <group> + + 311B7A4524DB24F3FC085B190A2EEE4B + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVRotationGesture.m + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRotationGesture.m + sourceTree + <group> + + 31603E2B84E9141B15192CB5F08073EA + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LVBaseView.h + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVBaseView.h + sourceTree + <group> + + 316EE69DE9BCB456A94DD12DDE19E4B8 + + includeInIndex + 1 + isa + PBXFileReference + name + llex.c + path + IOS/lua/lua/llex.c + sourceTree + <group> + + 31E4C72577D34E089E65548C02EAF060 + + children + + FA9C85076DEB156BACB490133D4BA212 + 25F8ABDD1532A296D8F95098E2E0A972 + E9147195251E0E11AD9BEC4D2227EA9B + 3AC8A9CDF659CBBCA1320C8046434793 + + isa + PBXGroup + name + iOS + sourceTree + <group> + + 3252D1A51DF30A2321DBBDF3E758DFDB + + fileRef + 2A00E5624756359F3C35FD75432F1CDD + isa + PBXBuildFile + + 325C3C570A4FDB3EBF50C0A7B13F91BF + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LVRefreshHeader.h + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRefreshHeader.h + sourceTree + <group> + + 329DCDA56DD96D91BF81795302D64BBB + + baseConfigurationReference + 7A9B772B1DCEE38F37A46280BAF68BCE + buildSettings + + ENABLE_STRICT_OBJC_MSGSEND + YES + GCC_PREFIX_HEADER + Target Support Files/MJRefresh/MJRefresh-prefix.pch + IPHONEOS_DEPLOYMENT_TARGET + 8.3 + MTL_ENABLE_DEBUG_INFO + NO + OTHER_LDFLAGS + + OTHER_LIBTOOLFLAGS + + PRIVATE_HEADERS_FOLDER_PATH + + PRODUCT_NAME + $(TARGET_NAME) + PUBLIC_HEADERS_FOLDER_PATH + + SDKROOT + iphoneos + SKIP_INSTALL + YES + + isa + XCBuildConfiguration + name + Release + + 33543D000D51A7E95941EB27614734DB + + fileRef + F92BF22EEADD8B8F8EE14951B0A60346 + isa + PBXBuildFile + + 338F63C6EC6F5913CA70D9C3D8E6B5E2 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LVStyledString.h + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVStyledString.h + sourceTree + <group> + + 33B017134DB0FDB8EABE416215B5F7FE + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LVAlert.h + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAlert.h + sourceTree + <group> + + 341B6F033789A6C8C57BEDDBB99666DC + + fileRef + 89FB168616EAC47EBAF5F5819F0E966B + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 34509A2745482CFBCF03BAAFEA0DAE4E + + buildActionMask + 2147483647 + files + + C10291D821E77E019EC760D33F1DAB2B + 2D7FBA552B3CED667D78641BD3DEF96C + 6D40913F14E30C5027EDB1E8E5267456 + 820AE72EE18049DB0D39950065ABA727 + 60B872A80D2C7EC0A342F16970BF22BB + 1750E8156D634B9DCFCBDF366430F326 + 729824F7571ED25599AD2A5E1E831189 + 69E1CE5225A654934B2A36CCEECD0F82 + 8355E9060CF4352ED0E21569A6FED32F + 1E88082E67EECA1458FA24BBF7677908 + 6401732D299AF2E66A86932AC8BB931D + 401E263227EC555D61B8BBB94ED09D73 + 6ACE435B71030CD770DECAA65380285F + 881AB1EA374C9358F2A83F1D835D1B35 + 4A55E2CB58A23956EF1822F5A6DF5F2C + 9347B960A275D7EEF8F79F348578B45D + 832385F31AACCFABD48F783C577C8785 + 7BB5FA5A44FBC13830AE9E7731A38D7F + 4C359B72D6BDE27D946D1B4D5A22DE00 + B10A64BAF7708212BEE77303B46759A0 + + isa + PBXHeadersBuildPhase + runOnlyForDeploymentPostprocessing + 0 + + 345FC47EB56AE9EA01291CACE7F0F46A + + includeInIndex + 1 + isa + PBXFileReference + path + slaxml.lua + sourceTree + <group> + + 348D1C42436EEEA79D62B228F083B2B4 + + fileRef + 890C426A9ADC94BA5988DA60295203C8 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 351CD29F1162B1E8D87FFAC75A91F8FE + + fileRef + 7D77C822DD8392B7460B91F3BBA432B6 + isa + PBXBuildFile + + 359168A371C98797E71E054A2DC74CB7 + + buildActionMask + 2147483647 + files + + 295C0410F34CCFB29B0BDC50D310CA1E + 1A2815B7EA1C751193B90C3CBC87E3FF + EFB3DB5A3F155CB5B9F400A038CA233B + C0F13A7CD2A4B649013B620A747F6E88 + 94DAB483F0559E7CC6717169D4E5714E + B6F34069F4991BA877D50749E15E7944 + 015874845E892063530B701C4B563886 + F13912E48FDB68CCF4BDBB76D803FD90 + C70C5EA435C67E3DB6D52610FF9E4303 + F51168584B32F3D4944CDCE21DB312A9 + 7B240040B6338DDE6A57E43060FCED0E + BFFADAE0A0145E7EEEAFCA4AE0F42108 + 6F31A14C474E25B0815AA8B8E7FF6C4B + 03EA78459B07E810AB6C86D73371C652 + EF06428C066EFCEF8F25ED2786BB8002 + 29EC4AF2D4278E4C86F9D0BD8E8F9CFF + B96893B00EA263CC7C54DD966F040824 + C24A651C62A5C7D591E23BD81FF4425D + A7B2DC731E898BAD2A4D2DCDC92FB990 + 1684D43653C66CECE3818AB69199DBA9 + 7A2793B6C564D48999EE22D2185510A8 + BE021AB2821FBE6EC7313AA7C0AD5B14 + 5953FA17A8A8425CF8FE6D84ECDD7D7B + 2BFAE640B346B9070B1B3F22B86B56EE + 56C1C464F89C88E94685D4997253EA39 + 414E544C9A7B6A5AC07E623D48408D1F + D8389FAFCAF9D8FCC1A95A1DCD8D9ECD + 935FB8B94BE7E8B84D5702F14A5F5FE2 + 2C89DDAB3F53D427C477F8F040FF1598 + CFFAA082F61AB74F30C5BF024E7CC8E1 + 38AC37E99CDF7AC8F6C8F657A687C0FC + 678E3FE55AA75A6C09CB56C748B4CF86 + E95261BDED4B03E24FC2E72EC37CB509 + E03A9B9C8AD7448D4001395A3EB78B92 + 2FBD447B4E903BDF71EACEB55B8C68C5 + 5C8FD7E4A237968D24A0FE0FDD5A3200 + A28A4A17E3A5BF55AF00526DF8E9A350 + B28F53E51E7BAE28654B948FDFE0B85D + 76E51C915ED7D6E19D81AEDCF71072BD + 3EEAF272939C9764F934F166418CC833 + 22C7129862982EDC0F0620281C94434B + 8B998140D8485A90A79018D0EB44E359 + B240D2A581351636E37A298B192C4955 + 0017127DB94CC6F1B9726D2ABF338D97 + A23B6B22A081721F956B2AB7860182E6 + BEA6A093F66522924757896C77F68E77 + 2D15CD985562C9AF0C1DDA3EEF4F1EA3 + 081204C328A1EB30463CFEDB4BB4FA6E + A1B6F2900DCD37AC25FD615F7BB579B4 + D9AD27D17166C52B00A9E224E5380547 + B037B7F37852EC8C203CE475066B236D + D3C4123A5BE271923C45984D624F58FF + FB69CD50281750767B6A748377B527C1 + A9E6BBC5E6D94D20C399D7D57E7FDEE1 + D0CF3B992AE9A436F7A617459A0D5F69 + AFE78D019F9991D225A7A269ECD8C0B0 + 5AF913C6B8B54BF4D19C5187B26B5A4E + B876B862054CB4F45B547C3CAE5D54BB + B5A3EEB2278F9AE16DA9812651A81DF8 + 83406647B37ECC9844DD74CFE8D73337 + CED3E9092F7193546D7D0212737C1F20 + 0A6A56AAB0CCC271312FC044BE654DD5 + 39F9819238F46B1B15F47313FE164949 + 9BADCB79A80C743C895FE989ACA2FF61 + B0ACF7E54126A79BD4E4DF79697C42A1 + B537193286E886B2BA49E092EF29398B + 09B58A84FA82B323D09A5242FC2B5791 + B242B68A8FF49BB326673D0FFB0F59D3 + 3FD045F8806DE76936D8B6EC39335A1A + 229042DE27C75966B85403855D4866E9 + 83BB1491F70E8928E72146B1611E12DE + D444A813656B5E13709C7182926AB285 + 88EE5C417BDD3EBAEE47C36F5A287050 + BD19ABCFE68B0D0EBEADEFD602D439FF + 545B40B808AEEDA73BE42BA5AC231657 + 16FC40655B7DE4E187C610A87B44A4A5 + 7A750F2ACE73CF6ED5D79469ADBBF629 + 91D53D69FDCC6E689C09F07673E16D6F + BE838806D0FF138A1301C65ABAF45E6B + 80C82B94E6B86582590BB363BD7C5523 + 46DB4ADB74CDBF1A4D087624C57A9FFF + E53454694FBDE9F46C885AF250A1D462 + FEFEE2D813FE2DF84A2FC00C56943747 + 3E0B50B630953DE2ED45283028E2E409 + 0F076CFF2E138CFA704722866DCE9782 + 128A64434D403A522E70D656178107E3 + 193350A2E9DA407F2917FF58833B85DC + 8F90FC0C3D7DC2DB7DA95759D9EB4048 + 233AE6BDA52AF2078C6419CF8B097EA4 + C7F85E5C5B56884FAC41FE7ACCCB7B96 + BA6A97FC288F57FADD6B38BFDF554A17 + 8703384A72EF4642F8972DD117FFB0C0 + 348D1C42436EEEA79D62B228F083B2B4 + CEF0CB460D46CC901B4002C668509144 + 761C53DCF49A57833A79EAFB16DA55CE + 2A247B0578AFFD9B75A4AA66AF325AD6 + 0A4F5042D8E5452A3BA410BCA130BACA + 55FE67B8201E9EBC7C09DE61EAA98D62 + 473E395ED419610E653B3104D698CEFE + 8D1612DA1397C4D31D4FFE0E3A288A34 + 20C72AFB4286BDD05462A4F78B6B03BF + 7386B2FA267E1889BFA96B528ADE4DE0 + 341B6F033789A6C8C57BEDDBB99666DC + 695B03969558A0D14A76EC7053C52CF6 + DD604C7F2696CB8FC9805837BCF61402 + 5973E98BBCB546DCB81AE6FAC6C089A1 + A67E211669DA170F7509C4E7E7E7138F + 4EC608AC56A1FF1848D4FECC7DE666FD + + isa + PBXHeadersBuildPhase + runOnlyForDeploymentPostprocessing + 0 + + 35ADDF72B83994A75288FF85E354EEB7 + + includeInIndex + 1 + isa + PBXFileReference + name + lundump.c + path + IOS/lua/lua/lundump.c + sourceTree + <group> + + 35CD100C2D0E4CC5D780A8296D404C8F + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LVGesture.h + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVGesture.h + sourceTree + <group> + + 360078647E2A038629551ADB65160999 + + fileRef + 2011B45A98326F01DE4AB680BF2395E5 + isa + PBXBuildFile + settings + + COMPILER_FLAGS + -DOS_OBJECT_USE_OBJC=0 + + + 3630849F338A0FA6FE65110F2A128923 + + fileRef + 8E9444CA756774982595CC9D0C76124D + isa + PBXBuildFile + + 36444253FBF11067C2A948FD3F51354B + + children + + AD10EC82D3BAC8EF1E7167B8C10E4F13 + EC5C35AC2FEC11F77ED822D5979CC349 + 1D19AA05C372AF3EFD35A2AD28F4D8BD + 035D3067B44ACFD87A44EAEA19EAD13D + 345FC47EB56AE9EA01291CACE7F0F46A + 2265B12C49637BF869C3E36882EA82D2 + 8E9444CA756774982595CC9D0C76124D + + isa + PBXGroup + name + kit + path + kit + sourceTree + <group> + + 364BA089FD07E58FA10BDD7B0B1DAE77 + + children + + FDB3D7BFD24479ACA7B4A8AFEFB5554D + 79602D2EB069434287FDBABEC402407F + F73FE9772F32C391B1AAB165B7618F08 + 035A2B93F59B66DD593DBFDA4DBE902A + F5ECACD0C38562F4F2E34802BD0988BC + 1D6054D63442F671F8D09855592CB662 + 514DBCD4730D08D27E7801BEBB135AFD + 764FA85F96E0C2203583A303AB5E2A19 + CAEABFF750CE4ABF01280F717030161C + + isa + PBXGroup + name + Classes + path + Classes + sourceTree + <group> + + 3744D8D317245CAF30FE6EB069FEE83F + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + NSBundle+MJRefresh.h + path + MJRefresh/NSBundle+MJRefresh.h + sourceTree + <group> + + 3791750D2FBD5D56810E53D9A6213EC3 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + UIScrollView+LVRefresh.m + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/UIScrollView+LVRefresh.m + sourceTree + <group> + + 37DE746FCDAA2F22DAEA83475EB7A313 + + fileRef + 5A9081B1B6104EADB443FDF431CB7F72 + isa + PBXBuildFile + + 37F9666F60E7D38796DB4137A6DA7A70 + + fileRef + F61782492D0F440833634360D6581150 + isa + PBXBuildFile + + 37FC6F4C41E317AA28C71485F4297730 + + buildActionMask + 2147483647 + files + + 19BA6CF23E4A6871720A4118364C09EF + + isa + PBXSourcesBuildPhase + runOnlyForDeploymentPostprocessing + 0 + + 380891D31A6A00C43DFDE002247409D6 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + MJRefresh-prefix.pch + sourceTree + <group> + + 38AC37E99CDF7AC8F6C8F657A687C0FC + + fileRef + 33B017134DB0FDB8EABE416215B5F7FE + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 39F9819238F46B1B15F47313FE164949 + + fileRef + F840D91E74C3F85E04F29F7ABEF8F81C + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 3A17B20AEA2D43C15A6E2237C7037F0E + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + lua.h + path + IOS/lua/lua/lua.h + sourceTree + <group> + + 3A3CA36EEC437FF1F5F822907899DD0C + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LuaViewSDK-dummy.m + sourceTree + <group> + + 3A6684853B85972EBB9649F944951257 + + includeInIndex + 1 + isa + PBXFileReference + name + ltm.c + path + IOS/lua/lua/ltm.c + sourceTree + <group> + + 3AC8A9CDF659CBBCA1320C8046434793 + + isa + PBXFileReference + lastKnownFileType + wrapper.framework + name + UIKit.framework + path + Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.0.sdk/System/Library/Frameworks/UIKit.framework + sourceTree + DEVELOPER_DIR + + 3AE6F79F11B5441864516F58FF9E0339 + + fileRef + 57EBAFA2A570961A23BA797D5F3CC7CB + isa + PBXBuildFile + + 3B4F5343D4689901239BD468FF446213 + + fileRef + CEBB1F45E8262C05ED41A2ED289AB3E7 + isa + PBXBuildFile + + 3BD94C9F2E00DE6591F2C354374F5E3C + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVDate.m + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVDate.m + sourceTree + <group> + + 3C7F46EBB6D17715AFCDAF8AFD619F11 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + JUFLXLinearLayoutView.h + path + IOS/SDK/LuaViewSDK/Classes/layout/LayoutExtensions/JUFLXLinearLayoutView.h + sourceTree + <group> + + 3D9F3435454E2D802E876586F239DFD9 + + buildActionMask + 2147483647 + files + + C49AE2D524F5FB037C0B0F1839A186D3 + + isa + PBXFrameworksBuildPhase + runOnlyForDeploymentPostprocessing + 0 + + 3DBC461A378D2BB81DDA093C65F6194F + + fileRef + 5689CDF8BB798D4EA126EFA3F609C7B9 + isa + PBXBuildFile + + 3DD4E0A4B689E9E67CF5F2549D232C51 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + UIImage+MultiFormat.m + path + SDWebImage/UIImage+MultiFormat.m + sourceTree + <group> + + 3DE1AF744EA6D6605090985C8C6F4385 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + JUFLXLayoutKit.h + path + IOS/SDK/LuaViewSDK/Classes/layout/JUFLXLayoutKit.h + sourceTree + <group> + + 3E0B50B630953DE2ED45283028E2E409 + + fileRef + DDA2790797E4F4E4D3BBCC6487F018F9 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 3EE531AEB3226242F2AA7877E8027660 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVFile.m + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVFile.m + sourceTree + <group> + + 3EEAF272939C9764F934F166418CC833 + + fileRef + 67BB47356A5DF21930F4CE9431DAEF9D + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 3F22E2CF3D8CD0030CAB2045008B48A0 + + fileRef + 1BD1FEB3E27E055C9425C85436DCAC2F + isa + PBXBuildFile + + 3FD045F8806DE76936D8B6EC39335A1A + + fileRef + D6F14AF4755A5E9D5F102E6026867275 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 401E263227EC555D61B8BBB94ED09D73 + + fileRef + 00366E6D1CE623FE38FC0701EAB25A08 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 402DAB9CCD76F0381D3246CFB4118AD8 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LVAudioPlayer.h + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAudioPlayer.h + sourceTree + <group> + + 4108737E1E30428F30C1EE86AE7A00DC + + fileRef + B437CB11C9C8EC6B415DB035A6DB10CF + isa + PBXBuildFile + + 414E544C9A7B6A5AC07E623D48408D1F + + fileRef + ED6DB046063868A72062F85D42CE8FE9 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 4284CEFBABF82ACBF5730DAE0087269C + + fileRef + BAE7B10AF626BF4D88E24777559D4F7E + isa + PBXBuildFile + + 42EC6A04605A1C80044D476FBE2538DF + + explicitFileType + archive.ar + includeInIndex + 0 + isa + PBXFileReference + name + libluaviewEx.a + path + libluaviewEx.a + sourceTree + BUILT_PRODUCTS_DIR + + 433D910F7D577FB44FFDD5FFA027ACBF + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + MJRefreshHeader.m + path + MJRefresh/Base/MJRefreshHeader.m + sourceTree + <group> + + 4374515A88E18AAD7FD4A3C7E61D9E35 + + fileRef + 5B6F2D98A83100E60808E70843203413 + isa + PBXBuildFile + + 4397FD63D238E023474037A653FDC151 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + MJRefreshConst.m + path + MJRefresh/MJRefreshConst.m + sourceTree + <group> + + 444F7EEB7C5EA6D046A98A1C05DC9A19 + + fileRef + 6BC1424DC3D5FEEE3721E798D6E24FFD + isa + PBXBuildFile + + 44514CC68F9B72D2BBADED400AB75D1F + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LVDebuger.h + path + IOS/SDK/LuaViewSDK/Classes/lvdebug/LVDebuger.h + sourceTree + <group> + + 44529459406814AB948DF5BFEEA0A227 + + fileRef + E91D368599C328C5143944AE759B8F95 + isa + PBXBuildFile + + 445BAA7F50663F5766B683D0F3734465 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LVNativeObjBox.h + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNativeObjBox.h + sourceTree + <group> + + 44EAE5374CB9172E71ED4BDD5037797C + + fileRef + 14E611D7FB8EBE58F4FE02103F29ADAE + isa + PBXBuildFile + + 4504CC614A2B924DE6865AB69C9ACA8F + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + text.xcconfig + path + Pods-luaviewEx_Example.release.xcconfig + sourceTree + <group> + + 45069D1D3C8BD7617FA498F2E2F4B186 + + buildActionMask + 2147483647 + files + + DDE5689688A6E9EFBF7717D961CF164C + A4E16D9E4E4425C7DE5DC9095FDE2973 + + isa + PBXFrameworksBuildPhase + runOnlyForDeploymentPostprocessing + 0 + + 4548D482088C76C3191E06CDFD55A8E3 + + fileRef + B054695A110D9DFA2F5EE986F47FDE77 + isa + PBXBuildFile + + 45749D20BBFB064A0B4BC0A1497BCC19 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + MJRefreshAutoGifFooter.h + path + MJRefresh/Custom/Footer/Auto/MJRefreshAutoGifFooter.h + sourceTree + <group> + + 467ADC9DF6A1E6193FE860E7DF3E8D07 + + fileRef + 9F08ADE57BC15F9C6D36323887AFB74D + isa + PBXBuildFile + + 46DB4ADB74CDBF1A4D087624C57A9FFF + + fileRef + 0E7F78556C26EF63F32574BA1D25E267 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 46E2FFAE81593D15ECDF37606CF93415 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LVTextField.h + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTextField.h + sourceTree + <group> + + 472A5178F982E81426BEF67B5D65F41D + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LVZipArchive.h + path + IOS/SDK/LuaViewSDK/Classes/PKG/LVZipArchive.h + sourceTree + <group> + + 47338C4FF8A4FE3BB87A1D282B28DB0E + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LVHttpResponse.h + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVHttpResponse.h + sourceTree + <group> + + 473E395ED419610E653B3104D698CEFE + + fileRef + 1EE667E76E8DE6FA80C6611D3FD1781E + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 47670BAD8ACCB2C39FC2B58875B112E4 + + baseConfigurationReference + A70095A630FF08A50442B16D1B37308C + buildSettings + + ENABLE_STRICT_OBJC_MSGSEND + YES + GCC_PREFIX_HEADER + Target Support Files/luaviewEx/luaviewEx-prefix.pch + IPHONEOS_DEPLOYMENT_TARGET + 8.3 + MTL_ENABLE_DEBUG_INFO + NO + OTHER_LDFLAGS + + OTHER_LIBTOOLFLAGS + + PRIVATE_HEADERS_FOLDER_PATH + + PRODUCT_NAME + $(TARGET_NAME) + PUBLIC_HEADERS_FOLDER_PATH + + SDKROOT + iphoneos + SKIP_INSTALL + YES + + isa + XCBuildConfiguration + name + Release + + 4789F07E9F42154904330D02D37FB8CE + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + UIImage+GIF.h + path + SDWebImage/UIImage+GIF.h + sourceTree + <group> + + 479F07FB188004636EDDA03D43002341 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVNavigation.m + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNavigation.m + sourceTree + <group> + + 485AB80AB11777778F7CD00C82E324D3 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + UIView+WebCacheOperation.h + path + SDWebImage/UIView+WebCacheOperation.h + sourceTree + <group> + + 490174683C07FB520DE43D8ED1A6E1BE + + fileRef + 67509110E30D081975378406A2331EE1 + isa + PBXBuildFile + + 493783C631E479F3E934D24AC62FEA52 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LVCanvas.h + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCanvas.h + sourceTree + <group> + + 499211EAF9B4ACA6D9DC215454184F4D + + fileRef + 433D910F7D577FB44FFDD5FFA027ACBF + isa + PBXBuildFile + + 49FA69425B92D350F96AAE29412E401A + + fileRef + 6FF1243FF125B90C027855CDACA10DC6 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 4A302094BECFD7BA587E9271E568D676 + + isa + PBXTargetDependency + name + SDWebImage + target + 74FCE8A3277B50697CE9268AEF352C6D + targetProxy + FFA639715D800CB6135B1825AF1F63A5 + + 4A55E2CB58A23956EF1822F5A6DF5F2C + + fileRef + DA862005A7A8E002C1A0F7423119C939 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 4AA507206EE37C421EED5D7726A966E4 + + buildActionMask + 2147483647 + files + + BAC23526788511468BCE9118BDC89F2B + EBC90D170EC49DBF123E19EDECA99992 + 9A254373E302312D6E2E4A864D504839 + EE6F5B992DE6AEF9FA035830B86988A8 + F23A9B4C97F8BE23F6473F1838E1F72B + 52AB7A2F6722062B983D98279EC0CEAF + + isa + PBXSourcesBuildPhase + runOnlyForDeploymentPostprocessing + 0 + + 4AB1C0F737FEE5C73C39CEC038113FCF + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVCustomPanel.m + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCustomPanel.m + sourceTree + <group> + + 4ADA7C57CE84EFE603F80884027F04EC + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVBaseView.m + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVBaseView.m + sourceTree + <group> + + 4B47C50F2D0887FAB9E3A511BAF68DB9 + + includeInIndex + 1 + isa + PBXFileReference + name + lparser.c + path + IOS/lua/lua/lparser.c + sourceTree + <group> + + 4B8AC868439D6B598FE5F597062E8BB6 + + children + + 42EC6A04605A1C80044D476FBE2538DF + 73A074EE136AF9389D9E27285D536377 + 82B7CC0F4C26A52AB723510CA911448E + 7073693D24B8C984C2EB5C8007F3FF89 + 8655224C3060F5E10C6F107D17199071 + E4EDF2505C6AA1619D1AD0A8DC324AB3 + + isa + PBXGroup + name + Products + sourceTree + <group> + + 4C0AEDA8B1664448BDACC855484B74B4 + + buildConfigurations + + 890C9345A0104BD5638A0ED7169C20F8 + 0FF8ED2CB0D78645C2BB66738DC66614 + + defaultConfigurationIsVisible + 0 + defaultConfigurationName + Release + isa + XCConfigurationList + + 4C359B72D6BDE27D946D1B4D5A22DE00 + + fileRef + 508F587BDFC380AD0F25CD91E6534878 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 4C79E04329C138C91B4F7F5CF3FB92C7 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LuaViewCore.m + path + IOS/SDK/LuaViewSDK/Classes/LuaViewCore.m + sourceTree + <group> + + 4CED673A1CD51BD6238015DD2A576C5B + + containerPortal + D41D8CD98F00B204E9800998ECF8427E + isa + PBXContainerItemProxy + proxyType + 1 + remoteGlobalIDString + 4F318E6CB32EF6E77C176A2A5ACC0B17 + remoteInfo + LuaViewSDK + + 4CEEDEC12FF31E0D8E32E478281AF82F + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVData.m + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVData.m + sourceTree + <group> + + 4D3EDCA5FF555D595536CC4A60E6B5DF + + fileRef + 7F92A9CFABA3480B518868700976CDA5 + isa + PBXBuildFile + settings + + COMPILER_FLAGS + -DOS_OBJECT_USE_OBJC=0 + + + 4DB012FE92F96D3880937C869CEB5911 + + fileRef + 3BD94C9F2E00DE6591F2C354374F5E3C + isa + PBXBuildFile + + 4EC608AC56A1FF1848D4FECC7DE666FD + + fileRef + 03ADB1EE211113EC9C3B9167F0A4DB0A + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 4F318E6CB32EF6E77C176A2A5ACC0B17 + + buildConfigurationList + 14DDA98CD559DD9E76DA63FEF44098AF + buildPhases + + 8FE0CEEBB6A025807E2D479BE063E59B + 65BBB6361A82C74B5C35D058C7DFF4A2 + 359168A371C98797E71E054A2DC74CB7 + + buildRules + + dependencies + + isa + PBXNativeTarget + name + LuaViewSDK + productName + LuaViewSDK + productReference + 73A074EE136AF9389D9E27285D536377 + productType + com.apple.product-type.library.static + + 4F367DCDFE766D2A4DB80B51A41AACA0 + + fileRef + 4397FD63D238E023474037A653FDC151 + isa + PBXBuildFile + + 4F6B16C9B5B938A893591634C7CDC37B + + fileRef + CB727C1002C9DC01B0669B16FE581B57 + isa + PBXBuildFile + + 4F9F49929FE386525813797DE6D40520 + + fileRef + 78730480B8BA4188FCCB69CDA7AC3192 + isa + PBXBuildFile + + 50487FC48724B55B3FAD221340A0D10A + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + UIView+JUFLXNode.h + path + IOS/SDK/LuaViewSDK/Classes/layout/UIView+JUFLXNode.h + sourceTree + <group> + + 508F587BDFC380AD0F25CD91E6534878 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + UIScrollView+MJRefresh.h + path + MJRefresh/UIScrollView+MJRefresh.h + sourceTree + <group> + + 514DBCD4730D08D27E7801BEBB135AFD + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVExImage.m + sourceTree + <group> + + 515E0623D108242C6EF06F4962027BC0 + + children + + EAD4713FA50BEEBAFF24F34A0311F0EA + 77DA67D346FFDE31047C841AE3E57064 + 8E3C6E9DFDAA48A2FEA8BA3B01A6772E + + isa + PBXGroup + name + luaviewEx + path + ../.. + sourceTree + <group> + + 51EE67DEF356B157B9FC9DAC2821122B + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LVScrollViewDelegate.h + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVScrollViewDelegate.h + sourceTree + <group> + + 51FCC0A1C88049285E0BED1A17102E40 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + UIScrollView+LuaView.h + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/UIScrollView+LuaView.h + sourceTree + <group> + + 52AB7A2F6722062B983D98279EC0CEAF + + fileRef + CAEABFF750CE4ABF01280F717030161C + isa + PBXBuildFile + + 536AB72C44562204A9AC1391933D0E9F + + isa + PBXTargetDependency + name + MJRefresh + target + 70BC44266C6FFE30D2C57129458E070B + targetProxy + F624E64DD3338E4E653B1FA6F7F639CC + + 537BC05E46F49890B5734D960924FEAF + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + MJRefreshAutoStateFooter.m + path + MJRefresh/Custom/Footer/Auto/MJRefreshAutoStateFooter.m + sourceTree + <group> + + 53D9930552D81FA0E4F1BE66C8637137 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + JUFLXCSSParser.m + path + IOS/SDK/LuaViewSDK/Classes/layout/JUFLXCSSParser.m + sourceTree + <group> + + 5405AC1C9053E8072CFC0A500628403B + + fileRef + 4AB1C0F737FEE5C73C39CEC038113FCF + isa + PBXBuildFile + + 5432589AF45A4380F9A7801DCAE74D52 + + fileRef + 567683F560B94BB3577E8A53F91CD895 + isa + PBXBuildFile + + 545B40B808AEEDA73BE42BA5AC231657 + + fileRef + F2696A0E5D878881AC368ADB22AD54AE + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 54BBBD6E8306EBC769FB0D15E0ECB8E6 + + fileRef + 24DC94EC0212D4697446E8ADFAA14FA6 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 54E7640CB88EF3B2F9E4C730D4C254BB + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LVPagerView.h + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPagerView.h + sourceTree + <group> + + 552D02D5BA751AC2E8790D2811D496CA + + buildSettings + + ALWAYS_SEARCH_USER_PATHS + NO + CLANG_CXX_LANGUAGE_STANDARD + gnu++0x + CLANG_CXX_LIBRARY + libc++ + CLANG_ENABLE_MODULES + YES + CLANG_ENABLE_OBJC_ARC + YES + CLANG_WARN_BOOL_CONVERSION + YES + CLANG_WARN_CONSTANT_CONVERSION + YES + CLANG_WARN_DIRECT_OBJC_ISA_USAGE + YES + CLANG_WARN_EMPTY_BODY + YES + CLANG_WARN_ENUM_CONVERSION + YES + CLANG_WARN_INT_CONVERSION + YES + CLANG_WARN_OBJC_ROOT_CLASS + YES + CLANG_WARN_UNREACHABLE_CODE + YES + CLANG_WARN__DUPLICATE_METHOD_MATCH + YES + COPY_PHASE_STRIP + NO + GCC_C_LANGUAGE_STANDARD + gnu99 + GCC_DYNAMIC_NO_PIC + NO + GCC_OPTIMIZATION_LEVEL + 0 + GCC_PREPROCESSOR_DEFINITIONS + + DEBUG=1 + $(inherited) + + GCC_SYMBOLS_PRIVATE_EXTERN + NO + GCC_WARN_64_TO_32_BIT_CONVERSION + YES + GCC_WARN_ABOUT_RETURN_TYPE + YES + GCC_WARN_UNDECLARED_SELECTOR + YES + GCC_WARN_UNINITIALIZED_AUTOS + YES + GCC_WARN_UNUSED_FUNCTION + YES + GCC_WARN_UNUSED_VARIABLE + YES + IPHONEOS_DEPLOYMENT_TARGET + 8.3 + ONLY_ACTIVE_ARCH + YES + STRIP_INSTALLED_PRODUCT + NO + SYMROOT + ${SRCROOT}/../build + + isa + XCBuildConfiguration + name + Debug + + 55FE67B8201E9EBC7C09DE61EAA98D62 + + fileRef + EF5FE19F0817E2CCD49CED853AFC3EA6 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 567683F560B94BB3577E8A53F91CD895 + + includeInIndex + 1 + isa + PBXFileReference + name + lcode.c + path + IOS/lua/lua/lcode.c + sourceTree + <group> + + 5689CDF8BB798D4EA126EFA3F609C7B9 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVAnimator.m + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAnimator.m + sourceTree + <group> + + 56C1C464F89C88E94685D4997253EA39 + + fileRef + 3A17B20AEA2D43C15A6E2237C7037F0E + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 57B72E70DD55F7293F6E965A5295CD27 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LVPanGesture.h + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPanGesture.h + sourceTree + <group> + + 57EBAFA2A570961A23BA797D5F3CC7CB + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVRefreshConst.m + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRefreshConst.m + sourceTree + <group> + + 57EC5811EEDCB1B590F2617CF40877F4 + + fileRef + E60754D5C7CDD4617817CA118EF56AEC + isa + PBXBuildFile + + 57EE5EAB7610CA9E21C165FDFCF71197 + + fileRef + 023E7263521C3044AE972C99F20ACCF4 + isa + PBXBuildFile + + 5953FA17A8A8425CF8FE6D84ECDD7D7B + + fileRef + 9C2E5BED34AA1B93F6B3D3BD49B8C1A4 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 5973E98BBCB546DCB81AE6FAC6C089A1 + + fileRef + 2BA16F5CCD3F1E210008D8280A170F1B + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 5A18A32422C5C66F04A1803B4E06737A + + fileRef + 73DFDF42D880C766AAAD6FC80F309B80 + isa + PBXBuildFile + + 5A9081B1B6104EADB443FDF431CB7F72 + + includeInIndex + 1 + isa + PBXFileReference + name + ltable.c + path + IOS/lua/lua/ltable.c + sourceTree + <group> + + 5AC21404A4384C42C5EC654668A27CC2 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVAudioPlayer.m + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAudioPlayer.m + sourceTree + <group> + + 5AD9B265AA9A38DEC7BAD050E1FFB64E + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVRefreshComponent.m + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRefreshComponent.m + sourceTree + <group> + + 5AF913C6B8B54BF4D19C5187B26B5A4E + + fileRef + 35CD100C2D0E4CC5D780A8296D404C8F + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 5B6F2D98A83100E60808E70843203413 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVAnimate.m + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAnimate.m + sourceTree + <group> + + 5BEFD624052F9D9B420664CB47C04C2E + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LVRSA.h + path + IOS/SDK/LuaViewSDK/Classes/RSA/LVRSA.h + sourceTree + <group> + + 5C15D90409A3D72F70B502B6FBBBD972 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVSystem.m + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVSystem.m + sourceTree + <group> + + 5C8FD7E4A237968D24A0FE0FDD5A3200 + + fileRef + CF942522CEE1D4E4BAF884894D457FA5 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 5D9B05966CFC8F7C7BD4F72C404DBE56 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + UIView+MJExtension.h + path + MJRefresh/UIView+MJExtension.h + sourceTree + <group> + + 5F21804D426E53A98AAB3032DFC2E82D + + fileRef + CD67C1EAF9CE00756E1DF489C938A6ED + isa + PBXBuildFile + settings + + COMPILER_FLAGS + -DOS_OBJECT_USE_OBJC=0 + + + 60B872A80D2C7EC0A342F16970BF22BB + + fileRef + 2E1E59F6FBDA7901F0AD952037FCF736 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 6111192518BA46A0F168020A2BAF5FF1 + + fileRef + 02DD81852450DF997CE182D2E8B96094 + isa + PBXBuildFile + + 6158D6FA11648C8C5CA6A804E036D158 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVDB.m + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVDB.m + sourceTree + <group> + + 62418B24F48022ED37FE832B12BF0F6C + + baseConfigurationReference + FB513E6EF7C88EF59301D4EA01043B1C + buildSettings + + ENABLE_STRICT_OBJC_MSGSEND + YES + GCC_PREFIX_HEADER + Target Support Files/SDWebImage/SDWebImage-prefix.pch + IPHONEOS_DEPLOYMENT_TARGET + 8.3 + MTL_ENABLE_DEBUG_INFO + YES + OTHER_LDFLAGS + + OTHER_LIBTOOLFLAGS + + PRIVATE_HEADERS_FOLDER_PATH + + PRODUCT_NAME + $(TARGET_NAME) + PUBLIC_HEADERS_FOLDER_PATH + + SDKROOT + iphoneos + SKIP_INSTALL + YES + + isa + XCBuildConfiguration + name + Debug + + 627B8671EF21E786E5CFDDE0D01EA3C5 + + children + + A7593BDC6F79DA5149512C5C45A3AB9F + 792FE58B6907A4B3B6AFA6AB5D3AC5DE + + isa + PBXGroup + name + SDWebImage + path + SDWebImage + sourceTree + <group> + + 638A8578DC8D49E287BD73C5CF76D6F0 + + fileRef + 8E8C5F8980ECE0F6CB2DD488817F4BB7 + isa + PBXBuildFile + + 63D59307BAFC1BA81B916BEDAB4682E9 + + buildActionMask + 2147483647 + files + + A10334F05778A0E836EF398D4C903DC5 + 6AAB1C3EC3568A71EAED3C8CC33FAC0C + 98602CDE0E10E3BA0F885E8BC00D691F + 7FC7FDCF03BF09B02C4D26E2A88F8EF1 + 8754C3D03D30A7E51CD4375250F59AAF + A3B74AC925EB24C9BFC6EB9642A95452 + 3630849F338A0FA6FE65110F2A128923 + + isa + PBXResourcesBuildPhase + runOnlyForDeploymentPostprocessing + 0 + + 6401732D299AF2E66A86932AC8BB931D + + fileRef + 0BA6BF787BE2139B97022DBF837C477A + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 649039ECE2B1D879861962C561AE479B + + includeInIndex + 1 + isa + PBXFileReference + name + linit.c + path + IOS/lua/lua/linit.c + sourceTree + <group> + + 64E6D761B8F3FB839E16484F3B839967 + + fileRef + A5A1201FDEB20DFB66C314031B9AAB06 + isa + PBXBuildFile + + 65A01D6211BE640201D7E62B62202D6F + + fileRef + 2FC9D5C93502F8C8120502B2AF56E419 + isa + PBXBuildFile + settings + + COMPILER_FLAGS + -DOS_OBJECT_USE_OBJC=0 + + + 65BBB6361A82C74B5C35D058C7DFF4A2 + + buildActionMask + 2147483647 + files + + BD4E504A2AF6C6A4769C02B1624AB7F9 + 9A6FEA1D26F7F5B4B5363A235FF7EE94 + EFFB2D478FDAC062278F1C29DB6628C0 + + isa + PBXFrameworksBuildPhase + runOnlyForDeploymentPostprocessing + 0 + + 670449DAA0F2A3D1DE6228C035F2D433 + + buildConfigurations + + 62418B24F48022ED37FE832B12BF0F6C + B8A21090164872795973E5E8AA0E2B54 + + defaultConfigurationIsVisible + 0 + defaultConfigurationName + Release + isa + XCConfigurationList + + 67509110E30D081975378406A2331EE1 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVImage.m + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVImage.m + sourceTree + <group> + + 678E3FE55AA75A6C09CB56C748B4CF86 + + fileRef + A116F1B2F17A0588D81965CA21B07794 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 67BB47356A5DF21930F4CE9431DAEF9D + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LVClassInfo.h + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVClassInfo.h + sourceTree + <group> + + 67CAC872CD8C6AE9FDBA920A62E3B401 + + includeInIndex + 1 + isa + PBXFileReference + name + lapi.c + path + IOS/lua/lua/lapi.c + sourceTree + <group> + + 687C81566E0A022C8A6FC66814230E29 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + JUFLXTargeNamespace.h + path + IOS/SDK/LuaViewSDK/Classes/layout/JUFLXTargeNamespace.h + sourceTree + <group> + + 6891D507788A858BA1297B6942E967F4 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LVWebView.h + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVWebView.h + sourceTree + <group> + + 695B03969558A0D14A76EC7053C52CF6 + + fileRef + B7F678867F20FD7240D39C5450EB80B1 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 6971CF9521EF1D534EA8C9FB3003B575 + + fileRef + 00C6711300727CE3A2D7A80B99BD48AF + isa + PBXBuildFile + + 69E1CE5225A654934B2A36CCEECD0F82 + + fileRef + 6DC12DF523650C6B0A46F3621ED2154B + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 6AAB1C3EC3568A71EAED3C8CC33FAC0C + + fileRef + EC5C35AC2FEC11F77ED822D5979CC349 + isa + PBXBuildFile + + 6ACE435B71030CD770DECAA65380285F + + fileRef + 6E6C16B857626130B368F3B40990E0AD + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 6B31962F4E83B6F9BBA48A8E5815FDD7 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVButton.m + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVButton.m + sourceTree + <group> + + 6BC1424DC3D5FEEE3721E798D6E24FFD + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVHeads.m + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVHeads.m + sourceTree + <group> + + 6CBE01C881C54307AD1E31E339461794 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + MJRefreshComponent.m + path + MJRefresh/Base/MJRefreshComponent.m + sourceTree + <group> + + 6CE6B695B24CA6D79E9F7DCAD875C704 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LVCollectionViewDelegate.h + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCollectionViewDelegate.h + sourceTree + <group> + + 6CED6FCB3574B0A8569AE6B839058580 + + fileRef + A51172659A32E024907D7EBC0A4DD608 + isa + PBXBuildFile + + 6D0E65DD94F80D25A79BD3356ED01B39 + + fileRef + 86AF9BF25759B6F231FFB4FA43AEA4B2 + isa + PBXBuildFile + + 6D40913F14E30C5027EDB1E8E5267456 + + fileRef + 45749D20BBFB064A0B4BC0A1497BCC19 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 6DC12DF523650C6B0A46F3621ED2154B + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + MJRefreshBackNormalFooter.h + path + MJRefresh/Custom/Footer/Back/MJRefreshBackNormalFooter.h + sourceTree + <group> + + 6E25ECB2BD596CE0B10558B8BADA9DC3 + + fileRef + D793F466F0871DFC7E2E6CAE9DEA8CFD + isa + PBXBuildFile + settings + + COMPILER_FLAGS + -DOS_OBJECT_USE_OBJC=0 + + + 6E6C16B857626130B368F3B40990E0AD + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + MJRefreshGifHeader.h + path + MJRefresh/Custom/Header/MJRefreshGifHeader.h + sourceTree + <group> + + 6E796FC19BDD4BEAF746BBDE91BA8F69 + + fileRef + 485AB80AB11777778F7CD00C82E324D3 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 6E9813A3A92FBA6F262C2C9EA2D60D14 + + fileRef + 9348F06C427F5B963CB0C869D32EB643 + isa + PBXBuildFile + + 6EA471E10DDA607666D946F224095BE0 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LVPagerViewCell.h + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPagerViewCell.h + sourceTree + <group> + + 6EE29D60F391D048B24759D53FA55883 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + lopcodes.h + path + IOS/lua/lua/lopcodes.h + sourceTree + <group> + + 6F31A14C474E25B0815AA8B8E7FF6C4B + + fileRef + 969455D8276353B9FDA6D90FC62FA7D3 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 6F4C2A2EDA8F187C5576068BDB6E3913 + + fileRef + 5C15D90409A3D72F70B502B6FBBBD972 + isa + PBXBuildFile + + 6FF1243FF125B90C027855CDACA10DC6 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + SDWebImageDownloader.h + path + SDWebImage/SDWebImageDownloader.h + sourceTree + <group> + + 705CFDDE1D005A162AF3D2D672C0C89B + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + lauxlib.h + path + IOS/lua/lua/lauxlib.h + sourceTree + <group> + + 7073693D24B8C984C2EB5C8007F3FF89 + + explicitFileType + archive.ar + includeInIndex + 0 + isa + PBXFileReference + name + libPods-luaviewEx_Example.a + path + libPods-luaviewEx_Example.a + sourceTree + BUILT_PRODUCTS_DIR + + 70BC44266C6FFE30D2C57129458E070B + + buildConfigurationList + 04C1DB49FA812C21EEEBEE206A0ED54E + buildPhases + + 94BDFDFA4567D11ADBE332123689D3BD + 91247678E3E2D23B0BF2C3EF48002167 + 34509A2745482CFBCF03BAAFEA0DAE4E + + buildRules + + dependencies + + isa + PBXNativeTarget + name + MJRefresh + productName + MJRefresh + productReference + 82B7CC0F4C26A52AB723510CA911448E + productType + com.apple.product-type.library.static + + 70C9B683D7D967E5EFEB1C6DFF35431B + + fileRef + 79602D2EB069434287FDBABEC402407F + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 70F7476823A575DF873A0835BCD42F85 + + baseConfigurationReference + A70095A630FF08A50442B16D1B37308C + buildSettings + + ENABLE_STRICT_OBJC_MSGSEND + YES + PRODUCT_NAME + luaviewEx + SDKROOT + iphoneos + SKIP_INSTALL + YES + WRAPPER_EXTENSION + bundle + + isa + XCBuildConfiguration + name + Release + + 70FD815DF49786A6ED20480D82DF1798 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVTransform3D.m + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTransform3D.m + sourceTree + <group> + + 71724E3BA243545F18CD67D71910EDB7 + + fileRef + FA21A688EC47146B09AC98BBCEFEFFC8 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 71C6A6658D8B50B82FE4FD5F536B4136 + + fileRef + D46D2419BC2639AC6CF379CB247C09E7 + isa + PBXBuildFile + + 71F22F871C8DB5D841A8B4BFFB5A01B1 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + llex.h + path + IOS/lua/lua/llex.h + sourceTree + <group> + + 727C7485C9B787AADCED8051FBBD24DB + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + SDWebImageDownloaderOperation.h + path + SDWebImage/SDWebImageDownloaderOperation.h + sourceTree + <group> + + 729824F7571ED25599AD2A5E1E831189 + + fileRef + A3972136BB90BBA8BBD5E586E1B6DAC6 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 7386B2FA267E1889BFA96B528ADE4DE0 + + fileRef + 472A5178F982E81426BEF67B5D65F41D + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 73A074EE136AF9389D9E27285D536377 + + explicitFileType + archive.ar + includeInIndex + 0 + isa + PBXFileReference + name + libLuaViewSDK.a + path + libLuaViewSDK.a + sourceTree + BUILT_PRODUCTS_DIR + + 73DFDF42D880C766AAAD6FC80F309B80 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + MJRefreshBackNormalFooter.m + path + MJRefresh/Custom/Footer/Back/MJRefreshBackNormalFooter.m + sourceTree + <group> + + 7415E077E9F712607D4A69B6EF4E3A99 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LView.h + path + IOS/SDK/LuaViewSDK/Classes/LView.h + sourceTree + <group> + + 74F3D6287B71307E8BB3C163630654EE + + children + + 1E455130CD554E363685BBC7EDB1AACE + 3A3CA36EEC437FF1F5F822907899DD0C + EBA4185E7D76AE98B42C70BD4C3B8E55 + + isa + PBXGroup + name + Support Files + path + ../Target Support Files/LuaViewSDK + sourceTree + <group> + + 74FCE8A3277B50697CE9268AEF352C6D + + buildConfigurationList + 670449DAA0F2A3D1DE6228C035F2D433 + buildPhases + + 15ED53A5A5A5B880F95660EAB6572A7F + 45069D1D3C8BD7617FA498F2E2F4B186 + BB3C7B6B3CF4A394F8727BBA9628483B + + buildRules + + dependencies + + isa + PBXNativeTarget + name + SDWebImage + productName + SDWebImage + productReference + 8655224C3060F5E10C6F107D17199071 + productType + com.apple.product-type.library.static + + 7506F75FAF8A4B5FB7CBF67BD84C38EE + + fileRef + A5FFF7A1893C71D6813D36966DBB49F4 + isa + PBXBuildFile + + 761C53DCF49A57833A79EAFB16DA55CE + + fileRef + 46E2FFAE81593D15ECDF37606CF93415 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 764FA85F96E0C2203583A303AB5E2A19 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVViewController.h + sourceTree + <group> + + 76C99EB7EABF291B06BBED0731BE44E5 + + fileRef + A87D0C7B735B456A76F615F8A91E12AC + isa + PBXBuildFile + + 76E51C915ED7D6E19D81AEDCF71072BD + + fileRef + 493783C631E479F3E934D24AC62FEA52 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 770BFA720B343B1138A7A9C3DE47257F + + fileRef + 926A0ACB90D9DAB5515B704DC0910AE1 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 7739E235EDE00D95E38D3BB4A5A3A323 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVClassInfo.m + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVClassInfo.m + sourceTree + <group> + + 777A861D7A0ED7A46ED02C5611EDC9FD + + fileRef + 1303734F66CF41E1C7547B22B2B51AD1 + isa + PBXBuildFile + + 778804E48E78E0C2D04C5655C38C53B7 + + fileRef + 3DD4E0A4B689E9E67CF5F2549D232C51 + isa + PBXBuildFile + settings + + COMPILER_FLAGS + -DOS_OBJECT_USE_OBJC=0 + + + 77DA67D346FFDE31047C841AE3E57064 + + children + + CB8FA076BCABE1AFF3A3325C222DFA1E + + isa + PBXGroup + name + Resources + sourceTree + <group> + + 78111672A9B49DC20741073B425CF56D + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVDownloader.m + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVDownloader.m + sourceTree + <group> + + 7813395B29A1FCDA22BFAF9A32BBF3F8 + + fileRef + B246BF211681D59247ED035C9AEFE3F4 + isa + PBXBuildFile + + 78730480B8BA4188FCCB69CDA7AC3192 + + includeInIndex + 1 + isa + PBXFileReference + name + lbaselib.c + path + IOS/lua/lua/lbaselib.c + sourceTree + <group> + + 78DD0AF22BF0E3660FC4CD8E74211F6B + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVEvent.m + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVEvent.m + sourceTree + <group> + + 792FE58B6907A4B3B6AFA6AB5D3AC5DE + + children + + FB513E6EF7C88EF59301D4EA01043B1C + 7F3DAAAA59B261122F2004E8CD8DC0AD + AA2A4ED034BB434233C1B9BB4DAD914B + + isa + PBXGroup + name + Support Files + path + ../Target Support Files/SDWebImage + sourceTree + <group> + + 79602D2EB069434287FDBABEC402407F + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LVExButton.h + sourceTree + <group> + + 7A2793B6C564D48999EE22D2185510A8 + + fileRef + 2E2BD15CBDAF008E187B120F43D8A160 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 7A750F2ACE73CF6ED5D79469ADBBF629 + + fileRef + 6EA471E10DDA607666D946F224095BE0 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 7A9B772B1DCEE38F37A46280BAF68BCE + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + text.xcconfig + path + MJRefresh.xcconfig + sourceTree + <group> + + 7B240040B6338DDE6A57E43060FCED0E + + fileRef + FA721E2AB3F4F7FC2123D160555D7E6C + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 7B51A48200C44C9D509171257F1A7E66 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LVNinePatchImage.h + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNinePatchImage.h + sourceTree + <group> + + 7BB2278FE818C87DDEB8FFC46F9BE439 + + fileRef + 843BCB6F268E541DB80F0C5957CD3F2C + isa + PBXBuildFile + + 7BB5FA5A44FBC13830AE9E7731A38D7F + + fileRef + ECF1F5927ABD8D6A17557F62782A0F0B + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 7CAB20DA8C1F658CFA03331F506E9B6C + + fileRef + 81DD7ADF36D7EF7F645FB76353D5BE22 + isa + PBXBuildFile + + 7CEAC01A2F196CDB49C6A2DBC45CE165 + + buildConfigurations + + 29EA1ACE2211DB8593A117A2AEDC029D + 47670BAD8ACCB2C39FC2B58875B112E4 + + defaultConfigurationIsVisible + 0 + defaultConfigurationName + Release + isa + XCConfigurationList + + 7D77C822DD8392B7460B91F3BBA432B6 + + includeInIndex + 1 + isa + PBXFileReference + name + lopcodes.c + path + IOS/lua/lua/lopcodes.c + sourceTree + <group> + + 7DB346D0F39D3F0E887471402A8071AB + + children + + BA6428E9F66FD5A23C0A2E06ED26CD2F + C6022F273B52E68EB2F1C85D62ECA70F + 14B8B9B15ECBE87983FF987239AB2D7B + 25AA72266E278F67F1AF500807F2A82E + 4B8AC868439D6B598FE5F597062E8BB6 + F9C85C83BD4D3C17E408FB82242BB884 + + isa + PBXGroup + sourceTree + <group> + + 7F3DAAAA59B261122F2004E8CD8DC0AD + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + SDWebImage-dummy.m + sourceTree + <group> + + 7F92A9CFABA3480B518868700976CDA5 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + UIImageView+WebCache.m + path + SDWebImage/UIImageView+WebCache.m + sourceTree + <group> + + 7FC6D87D4BEABED4013BAFFC3093A89E + + fileRef + 7F3DAAAA59B261122F2004E8CD8DC0AD + isa + PBXBuildFile + + 7FC7FDCF03BF09B02C4D26E2A88F8EF1 + + fileRef + 035D3067B44ACFD87A44EAEA19EAD13D + isa + PBXBuildFile + + 809A25B7F63AD138429CC8DA24777F6F + + fileRef + A1876BE3D22FCABA0929C593CA3BA01B + isa + PBXBuildFile + + 80C82B94E6B86582590BB363BD7C5523 + + fileRef + 203B879A967F66A09F7417445102D54F + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 81DD7ADF36D7EF7F645FB76353D5BE22 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVCanvas.m + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCanvas.m + sourceTree + <group> + + 820AE72EE18049DB0D39950065ABA727 + + fileRef + 978C32E4C97B32A331452E98DE44BEA5 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 829CA47C496203FEC6159E8DC09E2BDD + + fileRef + D155DDB3A2C8DC3AFBBA3915C2DFFF7E + isa + PBXBuildFile + settings + + COMPILER_FLAGS + -DOS_OBJECT_USE_OBJC=0 + + + 82B7CC0F4C26A52AB723510CA911448E + + explicitFileType + archive.ar + includeInIndex + 0 + isa + PBXFileReference + name + libMJRefresh.a + path + libMJRefresh.a + sourceTree + BUILT_PRODUCTS_DIR + + 832385F31AACCFABD48F783C577C8785 + + fileRef + 3744D8D317245CAF30FE6EB069FEE83F + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 83406647B37ECC9844DD74CFE8D73337 + + fileRef + A2378894A63AF77F9CF73CC6BEED9C89 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 8355E9060CF4352ED0E21569A6FED32F + + fileRef + F8122BA13636B99796B9DB282114BFC7 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 838A78E077C0BD584472E06993CB3839 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + lapi.h + path + IOS/lua/lua/lapi.h + sourceTree + <group> + + 83BB1491F70E8928E72146B1611E12DE + + fileRef + 445BAA7F50663F5766B683D0F3734465 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 843BCB6F268E541DB80F0C5957CD3F2C + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LuaView.m + path + IOS/SDK/LuaViewSDK/Classes/LuaView.m + sourceTree + <group> + + 84CA831836E0DB01AF70D0A6DCAEA523 + + fileRef + 2AF980C40415822FFD9E3B034D285AFD + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 8525801AE98FB64CBB07E945349BF8DF + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LVDownloader.h + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVDownloader.h + sourceTree + <group> + + 85647EFA905E7C4E434C149CCB42C664 + + fileRef + 6158D6FA11648C8C5CA6A804E036D158 + isa + PBXBuildFile + + 8655224C3060F5E10C6F107D17199071 + + explicitFileType + archive.ar + includeInIndex + 0 + isa + PBXFileReference + name + libSDWebImage.a + path + libSDWebImage.a + sourceTree + BUILT_PRODUCTS_DIR + + 86AF9BF25759B6F231FFB4FA43AEA4B2 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVToast.m + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVToast.m + sourceTree + <group> + + 8703384A72EF4642F8972DD117FFB0C0 + + fileRef + 171B1BADE853597D819B610B8E8FD83C + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 8754C3D03D30A7E51CD4375250F59AAF + + fileRef + 345FC47EB56AE9EA01291CACE7F0F46A + isa + PBXBuildFile + + 87BD79A6744E4742A74A8F8FF55ED866 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LVLabel.h + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLabel.h + sourceTree + <group> + + 87CF1D921BB259E09EEC1D210DB41686 + + fileRef + 479F07FB188004636EDDA03D43002341 + isa + PBXBuildFile + + 881AB1EA374C9358F2A83F1D835D1B35 + + fileRef + 1C72D47259AD02A2958DE9AC84C7BC4C + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 88EE5C417BDD3EBAEE47C36F5A287050 + + fileRef + A8A36E7B63A353F64AA2ACCF07D317C6 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 890C426A9ADC94BA5988DA60295203C8 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LVSystem.h + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVSystem.h + sourceTree + <group> + + 890C9345A0104BD5638A0ED7169C20F8 + + baseConfigurationReference + 2F4989EC176405BACD5E4338909B2D7E + buildSettings + + ENABLE_STRICT_OBJC_MSGSEND + YES + IPHONEOS_DEPLOYMENT_TARGET + 8.3 + MACH_O_TYPE + staticlib + MTL_ENABLE_DEBUG_INFO + YES + OTHER_LDFLAGS + + OTHER_LIBTOOLFLAGS + + PODS_ROOT + $(SRCROOT) + PRODUCT_NAME + $(TARGET_NAME) + SDKROOT + iphoneos + SKIP_INSTALL + YES + + isa + XCBuildConfiguration + name + Debug + + 891002139B977F8134D7F33D47B84ECC + + fileRef + 187EF30C8816993691A5B142EBB7CB36 + isa + PBXBuildFile + + 89FB168616EAC47EBAF5F5819F0E966B + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + lzio.h + path + IOS/lua/lua/lzio.h + sourceTree + <group> + + 8A9118E83980D38CDCA9C5476CDBEC66 + + fileRef + 92DAC6EBFEC4A9240CD17049F862950F + isa + PBXBuildFile + + 8AB7A3FC486822899B63497C9BCBB38A + + fileRef + DB10E91F1AD28C6A2668776C9698163A + isa + PBXBuildFile + + 8B998140D8485A90A79018D0EB44E359 + + fileRef + FE813EC15653881F550BD15245030107 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 8B9B660134CD023B3484A41900D9EA5C + + fileRef + 8F625C3DF0AE978BB072440845B4E043 + isa + PBXBuildFile + + 8BC7E34CA04704DB0DC1C33D16E96E3D + + fileRef + 2F4A25979F4326CF43F387B4CD7A9387 + isa + PBXBuildFile + + 8C5E0F2C73B42525D511F9714308FC97 + + children + + F569CDB32B52B31011145A315C00ACE0 + + isa + PBXGroup + name + Resources + sourceTree + <group> + + 8D0BAF2C3A77720FA74AC2A5D286B1F4 + + fileRef + E83E7FDFD7EE07DFC9D0B15DB3D53405 + isa + PBXBuildFile + + 8D1612DA1397C4D31D4FFE0E3A288A34 + + fileRef + 1FB2A9CD333316F15BDBD47C0ECBB3F6 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 8D8D6C86C617AC8D9A2D02914B19BAB3 + + fileRef + 53D9930552D81FA0E4F1BE66C8637137 + isa + PBXBuildFile + + 8E05C821622BBE09397D3CC007F1E968 + + containerPortal + D41D8CD98F00B204E9800998ECF8427E + isa + PBXContainerItemProxy + proxyType + 1 + remoteGlobalIDString + 1453C4742639DC29E77A2A397333AB6A + remoteInfo + luaviewEx + + 8E2B5D644FA6140FCD60151561013E88 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVLuaObjBox.m + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLuaObjBox.m + sourceTree + <group> + + 8E3C6E9DFDAA48A2FEA8BA3B01A6772E + + children + + A70095A630FF08A50442B16D1B37308C + 05D798E3E6D13DE52512EE4E6E91B1A2 + C60FF21AED50CA88BA04605746067E62 + + isa + PBXGroup + name + Support Files + path + Example/Pods/Target Support Files/luaviewEx + sourceTree + <group> + + 8E8C5F8980ECE0F6CB2DD488817F4BB7 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVBundle.m + path + IOS/SDK/LuaViewSDK/Classes/LVBundle.m + sourceTree + <group> + + 8E9444CA756774982595CC9D0C76124D + + includeInIndex + 1 + isa + PBXFileReference + path + util.lua + sourceTree + <group> + + 8ED4822A8555B90915C6EDE4F44D60B6 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVPointerValueBox.m + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPointerValueBox.m + sourceTree + <group> + + 8F625C3DF0AE978BB072440845B4E043 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + JUFLXLinearLayoutView.m + path + IOS/SDK/LuaViewSDK/Classes/layout/LayoutExtensions/JUFLXLinearLayoutView.m + sourceTree + <group> + + 8F90FC0C3D7DC2DB7DA95759D9EB4048 + + fileRef + C0B33593D5C25E32A0416C2B0D1D6C19 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 8FE0CEEBB6A025807E2D479BE063E59B + + buildActionMask + 2147483647 + files + + 8D8D6C86C617AC8D9A2D02914B19BAB3 + 8B9B660134CD023B3484A41900D9EA5C + 941D98402E10BB66C5DA96344D6003B5 + BEDA54F495392FD177BAB5D6D4652408 + 00E558B8093CD20D8ED2FA16EED9C9C5 + 3B4F5343D4689901239BD468FF446213 + 4F9F49929FE386525813797DE6D40520 + 5432589AF45A4380F9A7801DCAE74D52 + 76C99EB7EABF291B06BBED0731BE44E5 + B052D0B785F3DA3C09BFD52B66238399 + CA26090B11F23CC29648ACC0341DD7C1 + 6111192518BA46A0F168020A2BAF5FF1 + 04A2311BCAE1C0E272C6B1C787F36C3C + 903F05A318D50519ED7330AE35FBDD1B + 04FF9374848B71D08B51B424BD01CC64 + 71C6A6658D8B50B82FE4FD5F536B4136 + B5F531DD0399DAE73A325919B866B36F + 298D19C714ABD4E02CCA49264EB174F7 + AFD265D0B50B62C2C4F64C3B9BCE5C04 + 57EE5EAB7610CA9E21C165FDFCF71197 + 24172D119E9B5A38073722CED950B86E + 351CD29F1162B1E8D87FFAC75A91F8FE + 11145200D88F9ABAEEDDD26FEAB3641F + E799FF5DF3ABE640807F8CA4B6F7B06A + 2434DE58B225AAE5BE481F58D245FF45 + FC0D40A8DC42764EA1CCB56A30538E3C + D553675D6159FC01CF2C9FF4F416FA26 + 37DE746FCDAA2F22DAEA83475EB7A313 + 6CED6FCB3574B0A8569AE6B839058580 + 9EE98B1140E09A76C8BBFDEF1E85F455 + F130DA2142E93C4AEBA9C770EB26C9CD + 7506F75FAF8A4B5FB7CBF67BD84C38EE + 7BB2278FE818C87DDEB8FFC46F9BE439 + 2CB0D82457327C3E9202EF86FC9FD46E + 14ADE1102C757429A486CC0EEFF7163F + 226E0928F49DF341E97BD79ADADEBD8D + A770550917041508B4F59DD198ECC53D + 4374515A88E18AAD7FD4A3C7E61D9E35 + 3DBC461A378D2BB81DDA093C65F6194F + 0A7BC5CF629164867EF9BFC779DB9905 + B44A71FEED33ADF5978E99AA2B42225E + EA51452B77AACCDD1D12492768151215 + 638A8578DC8D49E287BD73C5CF76D6F0 + 9FBD1776E46099C52D207021D17817C5 + 7CAB20DA8C1F658CFA03331F506E9B6C + 9CBE048F1EC30FFE4EAF7DA35476C40F + 4F6B16C9B5B938A893591634C7CDC37B + F058A2EEE827FAD98DE4935EDB669368 + C659EE25D3B7EB140970740ABABEACD9 + 5405AC1C9053E8072CFC0A500628403B + 08563DD6038B20ED6CF2EDA7C0DD0508 + E0C0C57120BC2EDC95A79E05E8CD9C90 + 4DB012FE92F96D3880937C869CEB5911 + 85647EFA905E7C4E434C149CCB42C664 + 23EF01C652B4106BB0265EE3714CE1E7 + 57EC5811EEDCB1B590F2617CF40877F4 + BF85DD88573D2E0DBF15DDE9E1B579A5 + AF72EFDFCDCF19D4AE3A33627737C1EF + 96087FDD8A89DB82242131F58A791620 + 2A26C65B20259D5561282FF13EFB71B4 + DCDE4C56163FC1F76D6C35A19F1A9CA8 + D20CB9D528CE0F266A506596D0398D85 + 3F22E2CF3D8CD0030CAB2045008B48A0 + FD0D564503787B9458AB51441306C80F + 8AB7A3FC486822899B63497C9BCBB38A + 444F7EEB7C5EA6D046A98A1C05DC9A19 + A445A53495D2399E3388B9083DF94980 + 809A25B7F63AD138429CC8DA24777F6F + AF0E328E6199F0C716484F3C529D8654 + CBAE399F2CEB69306E6A192564A5A597 + 490174683C07FB520DE43D8ED1A6E1BE + 44EAE5374CB9172E71ED4BDD5037797C + 4284CEFBABF82ACBF5730DAE0087269C + 4108737E1E30428F30C1EE86AE7A00DC + EE68F5F89DE2D1D3AA85D0BE46210819 + 963341154B454AB7C56FF47EC6383583 + D2CD868E08C2A85B1543BBBE5BD4C2FC + DC8B2107202170D5C988FA09BC338CF5 + 87CF1D921BB259E09EEC1D210DB41686 + F1951C4E966743798495C533F7C2F5A9 + C6FFE935D19D6EE38B9EE3A92461CF47 + 8D0BAF2C3A77720FA74AC2A5D286B1F4 + 3252D1A51DF30A2321DBBDF3E758DFDB + 09ABAD4C3D76DFD8494DE962D57E110D + AA48FC085237DB822803986F22098618 + CDF1BDF9A1DB1D02653AAE821A4B39C5 + A0E68173EBFB13292F9BF0DD63BFD530 + BA4F2816B209AE73CD6DF71719815C3C + E8F9AB235FA3DB06565888ED1DB21838 + F80959A1904B32F4C03A43821DEA064C + 3AE6F79F11B5441864516F58FF9E0339 + 37F9666F60E7D38796DB4137A6DA7A70 + 9E97CE55D4E86AD265E4DCF5DEBFF45C + 233DD3C1DDCD00EB6DB13CF90A48DA85 + 6971CF9521EF1D534EA8C9FB3003B575 + 97308CF463F3D783E7F1661C31502637 + B8BDF91499C33445E7B061959CBDBEBF + 90C03AC8CD1F75FC93C76F46099DBEB4 + EDC93199A529A328783AE13C758F338E + 6F4C2A2EDA8F187C5576068BDB6E3913 + C6A6CD778AFAA43EA50F4B4AAD69FE3A + 64E6D761B8F3FB839E16484F3B839967 + BF177C4379C6B237B00E3AE72C87BDAE + 6D0E65DD94F80D25A79BD3356ED01B39 + F4F6EC8C90DE4BAA88081B3047E0E9B7 + 7813395B29A1FCDA22BFAF9A32BBF3F8 + 901BE4F235FB4D877401CBD23201417C + 0D42DBBCE5B87DF9D609A6E887B9018B + 8BC7E34CA04704DB0DC1C33D16E96E3D + 20A1DA8983367E7543A28C13AC5F823B + 28EFF26D92109EA51AD70F2E8673D19E + 33543D000D51A7E95941EB27614734DB + E2C7D367AC6691B5858A77A2D3A1CD6A + B27BE6C8B7906262FF5485D87EA8F0A7 + 891002139B977F8134D7F33D47B84ECC + 28D2995468C43DFDB5427BAF0E6685FE + + isa + PBXSourcesBuildPhase + runOnlyForDeploymentPostprocessing + 0 + + 900805BE7DD4976E7F04C52CA8C66CF0 + + includeInIndex + 1 + isa + PBXFileReference + name + lmem.c + path + IOS/lua/lua/lmem.c + sourceTree + <group> + + 901BE4F235FB4D877401CBD23201417C + + fileRef + 0D8B62C0984BC350ECBE7CC39F0060F7 + isa + PBXBuildFile + + 903F05A318D50519ED7330AE35FBDD1B + + fileRef + B3B3F38D1FA309127E9FB8AA32938AE7 + isa + PBXBuildFile + + 9062C31E489D11885922F6D9606B893A + + includeInIndex + 1 + isa + PBXFileReference + name + lmathlib.c + path + IOS/lua/lua/lmathlib.c + sourceTree + <group> + + 90C03AC8CD1F75FC93C76F46099DBEB4 + + fileRef + BA49E2DC11A1F519D35DECDF146BF6BB + isa + PBXBuildFile + + 91247678E3E2D23B0BF2C3EF48002167 + + buildActionMask + 2147483647 + files + + F04FA8541749536AE6A5E96B5BA70D85 + + isa + PBXFrameworksBuildPhase + runOnlyForDeploymentPostprocessing + 0 + + 91D53D69FDCC6E689C09F07673E16D6F + + fileRef + 57B72E70DD55F7293F6E965A5295CD27 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 926A0ACB90D9DAB5515B704DC0910AE1 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + SDImageCache.h + path + SDWebImage/SDImageCache.h + sourceTree + <group> + + 92DAC6EBFEC4A9240CD17049F862950F + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + MJRefreshStateHeader.m + path + MJRefresh/Custom/Header/MJRefreshStateHeader.m + sourceTree + <group> + + 9347B960A275D7EEF8F79F348578B45D + + fileRef + FCBD3E208A4816657C3EBFA78D140957 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 9348F06C427F5B963CB0C869D32EB643 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + UIScrollView+MJExtension.m + path + MJRefresh/UIScrollView+MJExtension.m + sourceTree + <group> + + 935FB8B94BE7E8B84D5702F14A5F5FE2 + + fileRef + 9EA2901B5E44138E8D7C8D083215B941 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 93BA3472B3385E616264C6BCAA7AE0D0 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVExGlobalFunc.m + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVExGlobalFunc.m + sourceTree + <group> + + 93E455E14459988C5B3FC784AC706191 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + JUFLXCSSParser.h + path + IOS/SDK/LuaViewSDK/Classes/layout/JUFLXCSSParser.h + sourceTree + <group> + + 941D98402E10BB66C5DA96344D6003B5 + + fileRef + 95914943A4946223A1A9ED7908C6B6FB + isa + PBXBuildFile + + 94289A039303C4BC79EA35AD39A597FA + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + NSData+ImageContentType.m + path + SDWebImage/NSData+ImageContentType.m + sourceTree + <group> + + 94BDFDFA4567D11ADBE332123689D3BD + + buildActionMask + 2147483647 + files + + CEFDC58C7241F86D92DEF8EDFCE7DF99 + C0266DA702333927677C77CC3FCB8390 + B7B6154D69B450647A1787A95ECAD0F2 + A2F6E9757ACC5A5FFACE3FE77F525BBB + 2427E2F0CA20B2924D366EA986934663 + E7A8DDD289D3BFB8950D29CBF67C7132 + F01687C8E9A3E4F8A528BE97DE7BDB80 + 5A18A32422C5C66F04A1803B4E06737A + 1F48696AD698115D898EC7CCD60D075A + F52763D22F95CF0A6F8491822F37BF5D + 4F367DCDFE766D2A4DB80B51A41AACA0 + E954B9D3A283FB30A945CE8823E102DD + F3AC7C93C770A6F7918EA23972C1762A + 499211EAF9B4ACA6D9DC215454184F4D + 4548D482088C76C3191E06CDFD55A8E3 + 8A9118E83980D38CDCA9C5476CDBEC66 + 777A861D7A0ED7A46ED02C5611EDC9FD + 6E9813A3A92FBA6F262C2C9EA2D60D14 + 467ADC9DF6A1E6193FE860E7DF3E8D07 + 44529459406814AB948DF5BFEEA0A227 + + isa + PBXSourcesBuildPhase + runOnlyForDeploymentPostprocessing + 0 + + 94DAB483F0559E7CC6717169D4E5714E + + fileRef + 02C66FB7DB87FC2EB3AF533E0EF74677 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 950FF5C3185C027C937FBB60FC84DE00 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVPinchGesture.m + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPinchGesture.m + sourceTree + <group> + + 95914943A4946223A1A9ED7908C6B6FB + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + JUFLXNode.m + path + IOS/SDK/LuaViewSDK/Classes/layout/JUFLXNode.m + sourceTree + <group> + + 96087FDD8A89DB82242131F58A791620 + + fileRef + AA19BC5B1910746326571A254FA88B3B + isa + PBXBuildFile + + 963341154B454AB7C56FF47EC6383583 + + fileRef + F0DADEB1B812067E0D78DDBCAB1ABD4B + isa + PBXBuildFile + + 969455D8276353B9FDA6D90FC62FA7D3 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + lfunc.h + path + IOS/lua/lua/lfunc.h + sourceTree + <group> + + 96C3FCB7C0C4F9CFA4C03B396CA2A069 + + baseConfigurationReference + 7A9B772B1DCEE38F37A46280BAF68BCE + buildSettings + + ENABLE_STRICT_OBJC_MSGSEND + YES + GCC_PREFIX_HEADER + Target Support Files/MJRefresh/MJRefresh-prefix.pch + IPHONEOS_DEPLOYMENT_TARGET + 8.3 + MTL_ENABLE_DEBUG_INFO + YES + OTHER_LDFLAGS + + OTHER_LIBTOOLFLAGS + + PRIVATE_HEADERS_FOLDER_PATH + + PRODUCT_NAME + $(TARGET_NAME) + PUBLIC_HEADERS_FOLDER_PATH + + SDKROOT + iphoneos + SKIP_INSTALL + YES + + isa + XCBuildConfiguration + name + Debug + + 97308CF463F3D783E7F1661C31502637 + + fileRef + C0FEAFF56087033560A33AC4EE4F1E8B + isa + PBXBuildFile + + 978C32E4C97B32A331452E98DE44BEA5 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + MJRefreshAutoNormalFooter.h + path + MJRefresh/Custom/Footer/Auto/MJRefreshAutoNormalFooter.h + sourceTree + <group> + + 98602CDE0E10E3BA0F885E8BC00D691F + + fileRef + 1D19AA05C372AF3EFD35A2AD28F4D8BD + isa + PBXBuildFile + + 98945AAA6D519D499411E6C2AB09E81C + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LVFile.h + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVFile.h + sourceTree + <group> + + 9A254373E302312D6E2E4A864D504839 + + fileRef + F73FE9772F32C391B1AAB165B7618F08 + isa + PBXBuildFile + + 9A6FEA1D26F7F5B4B5363A235FF7EE94 + + fileRef + 25F8ABDD1532A296D8F95098E2E0A972 + isa + PBXBuildFile + + 9BADCB79A80C743C895FE989ACA2FF61 + + fileRef + 003669CF9C13F30F337B75D1277C9EE5 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + 9C2E5BED34AA1B93F6B3D3BD49B8C1A4 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + ltable.h + path + IOS/lua/lua/ltable.h + sourceTree + <group> + + 9CBE048F1EC30FFE4EAF7DA35476C40F + + fileRef + 7739E235EDE00D95E38D3BB4A5A3A323 + isa + PBXBuildFile + + 9E97CE55D4E86AD265E4DCF5DEBFF45C + + fileRef + 311B7A4524DB24F3FC085B190A2EEE4B + isa + PBXBuildFile + + 9EA2901B5E44138E8D7C8D083215B941 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LuaView.h + path + IOS/SDK/LuaViewSDK/Classes/LuaView.h + sourceTree + <group> + + 9EE98B1140E09A76C8BBFDEF1E85F455 + + fileRef + 3A6684853B85972EBB9649F944951257 + isa + PBXBuildFile + + 9F08ADE57BC15F9C6D36323887AFB74D + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + UIScrollView+MJRefresh.m + path + MJRefresh/UIScrollView+MJRefresh.m + sourceTree + <group> + + 9F22373CA3B354C4A11258EFD35DE7B3 + + containerPortal + D41D8CD98F00B204E9800998ECF8427E + isa + PBXContainerItemProxy + proxyType + 1 + remoteGlobalIDString + CD2F0B2AD480735DCD585AADA045E315 + remoteInfo + luaviewEx-luaviewEx + + 9FBD1776E46099C52D207021D17817C5 + + fileRef + 6B31962F4E83B6F9BBA48A8E5815FDD7 + isa + PBXBuildFile + + A0D2A3B993113E8AF1A63CA5189A8860 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LVTimer.h + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTimer.h + sourceTree + <group> + + A0E68173EBFB13292F9BF0DD63BFD530 + + fileRef + 1A54CE3B4BB248552036DB35C1EE2A8E + isa + PBXBuildFile + + A10334F05778A0E836EF398D4C903DC5 + + fileRef + AD10EC82D3BAC8EF1E7167B8C10E4F13 + isa + PBXBuildFile + + A116F1B2F17A0588D81965CA21B07794 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LVAnimate.h + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAnimate.h + sourceTree + <group> + + A1876BE3D22FCABA0929C593CA3BA01B + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVHttpResponse.m + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVHttpResponse.m + sourceTree + <group> + + A1B6F2900DCD37AC25FD615F7BB579B4 + + fileRef + EBDDF52AF60ECE632FBC7F81C05742FB + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + A2378894A63AF77F9CF73CC6BEED9C89 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LVHttp.h + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVHttp.h + sourceTree + <group> + + A23B6B22A081721F956B2AB7860182E6 + + fileRef + C9B0E6679F7503D4526E79D72761AD5E + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + A28A4A17E3A5BF55AF00526DF8E9A350 + + fileRef + 208EED9D527973A149D9358AA3702EB4 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + A2F6E9757ACC5A5FFACE3FE77F525BBB + + fileRef + EA1BD290A8DBB924CF6F50D5B33A3333 + isa + PBXBuildFile + + A33D174EBE777C4C8E31B053AC15D45D + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + UIImageView+HighlightedWebCache.h + path + SDWebImage/UIImageView+HighlightedWebCache.h + sourceTree + <group> + + A36F4D2D88A2A4FFACC5C69F07672F4C + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + Layout.h + path + IOS/SDK/LuaViewSDK/Classes/layout/Layout.h + sourceTree + <group> + + A371B686E3E6E6310B394AEE93B61610 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVStruct.m + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVStruct.m + sourceTree + <group> + + A3972136BB90BBA8BBD5E586E1B6DAC6 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + MJRefreshBackGifFooter.h + path + MJRefresh/Custom/Footer/Back/MJRefreshBackGifFooter.h + sourceTree + <group> + + A3B74AC925EB24C9BFC6EB9642A95452 + + fileRef + 2265B12C49637BF869C3E36882EA82D2 + isa + PBXBuildFile + + A43792C99C7568064B453B7EB1E731F2 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + lgc.h + path + IOS/lua/lua/lgc.h + sourceTree + <group> + + A445A53495D2399E3388B9083DF94980 + + fileRef + A91426F56B4F86B643278F20C70E20B4 + isa + PBXBuildFile + + A49570A1935CF988C04B098F2606CE08 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LVData.h + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVData.h + sourceTree + <group> + + A4A212231C1652C2163EA475935BC083 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVDebugConnection.m + path + IOS/SDK/LuaViewSDK/Classes/lvdebug/LVDebugConnection.m + sourceTree + <group> + + A4E16D9E4E4425C7DE5DC9095FDE2973 + + fileRef + E9147195251E0E11AD9BEC4D2227EA9B + isa + PBXBuildFile + + A51172659A32E024907D7EBC0A4DD608 + + includeInIndex + 1 + isa + PBXFileReference + name + ltablib.c + path + IOS/lua/lua/ltablib.c + sourceTree + <group> + + A51C113A8035ADD4365A0C0751BAC77A + + buildActionMask + 2147483647 + files + + isa + PBXFrameworksBuildPhase + runOnlyForDeploymentPostprocessing + 0 + + A548B95FD1ADA614C553F9ED2356FE81 + + baseConfigurationReference + 1E455130CD554E363685BBC7EDB1AACE + buildSettings + + ENABLE_STRICT_OBJC_MSGSEND + YES + GCC_PREFIX_HEADER + Target Support Files/LuaViewSDK/LuaViewSDK-prefix.pch + IPHONEOS_DEPLOYMENT_TARGET + 8.3 + MTL_ENABLE_DEBUG_INFO + NO + OTHER_LDFLAGS + + OTHER_LIBTOOLFLAGS + + PRIVATE_HEADERS_FOLDER_PATH + + PRODUCT_NAME + $(TARGET_NAME) + PUBLIC_HEADERS_FOLDER_PATH + + SDKROOT + iphoneos + SKIP_INSTALL + YES + + isa + XCBuildConfiguration + name + Release + + A54FD7B60AF2B1A67ABE81FD1A4A9300 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LVMethod.h + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVMethod.h + sourceTree + <group> + + A5A1201FDEB20DFB66C314031B9AAB06 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVTextField.m + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTextField.m + sourceTree + <group> + + A5FFF7A1893C71D6813D36966DBB49F4 + + includeInIndex + 1 + isa + PBXFileReference + name + luac.c + path + IOS/lua/lua/luac.c + sourceTree + <group> + + A622A17FCDB47B180FCD298CCF93321F + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + UIButton+WebCache.m + path + SDWebImage/UIButton+WebCache.m + sourceTree + <group> + + A67E211669DA170F7509C4E7E7E7138F + + fileRef + 50487FC48724B55B3FAD221340A0D10A + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + A70095A630FF08A50442B16D1B37308C + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + text.xcconfig + path + luaviewEx.xcconfig + sourceTree + <group> + + A7593BDC6F79DA5149512C5C45A3AB9F + + children + + 24DC94EC0212D4697446E8ADFAA14FA6 + 94289A039303C4BC79EA35AD39A597FA + 926A0ACB90D9DAB5515B704DC0910AE1 + 2011B45A98326F01DE4AB680BF2395E5 + B583012233B3C4511452844069E5CFB3 + D155DDB3A2C8DC3AFBBA3915C2DFFF7E + DC2A62DF22CB330C871C83E5DCC5A659 + CD67C1EAF9CE00756E1DF489C938A6ED + 6FF1243FF125B90C027855CDACA10DC6 + CCBA5EC0FEAC0C022D514664CB0A8F9B + 727C7485C9B787AADCED8051FBBD24DB + 0ACB826940D91D6F0E3B839BC7EA70A2 + 30A1F8989B983EEB0E4F94E9E8E4FEB0 + D793F466F0871DFC7E2E6CAE9DEA8CFD + 2AF980C40415822FFD9E3B034D285AFD + FA21A688EC47146B09AC98BBCEFEFFC8 + 24ACDAAE48ECC19C32A56CE5DE769C97 + DDF8FFFA4075B105F7CC30A697DAECD8 + A622A17FCDB47B180FCD298CCF93321F + 4789F07E9F42154904330D02D37FB8CE + 15381D52480D9DD90D0131DFF8425DCA + CE8411601EBF400FDDB59EB243710BC8 + 3DD4E0A4B689E9E67CF5F2549D232C51 + A33D174EBE777C4C8E31B053AC15D45D + 2FC9D5C93502F8C8120502B2AF56E419 + D28DAD6825DB9029D2DB8A52B4FD53FB + 7F92A9CFABA3480B518868700976CDA5 + 485AB80AB11777778F7CD00C82E324D3 + F85FB92DB3CBF2A0853930794C17822D + + isa + PBXGroup + name + Core + sourceTree + <group> + + A770550917041508B4F59DD198ECC53D + + fileRef + 0DA2D9EFDDF4C3FC2D398B83D445ACBC + isa + PBXBuildFile + + A7A35A14EB2A583EF86EA849BDF36947 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + MJRefreshAutoFooter.h + path + MJRefresh/Base/MJRefreshAutoFooter.h + sourceTree + <group> + + A7B2DC731E898BAD2A4D2DCDC92FB990 + + fileRef + 6EE29D60F391D048B24759D53FA55883 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + A87D0C7B735B456A76F615F8A91E12AC + + includeInIndex + 1 + isa + PBXFileReference + name + ldblib.c + path + IOS/lua/lua/ldblib.c + sourceTree + <group> + + A8A36E7B63A353F64AA2ACCF07D317C6 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LVNetworkStatus.h + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNetworkStatus.h + sourceTree + <group> + + A8C4C2E0AD93FEE59249EE59CD760E4C + + buildActionMask + 2147483647 + files + + 70C9B683D7D967E5EFEB1C6DFF35431B + 175B696A75D2EC87BF53C6C0D407A678 + C1EB25A94C462FE757B4619F120B27EA + EADADD53B7ABD476C83346CFCF2F15DA + + isa + PBXHeadersBuildPhase + runOnlyForDeploymentPostprocessing + 0 + + A91426F56B4F86B643278F20C70E20B4 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVHttp.m + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVHttp.m + sourceTree + <group> + + A9E6BBC5E6D94D20C399D7D57E7FDEE1 + + fileRef + D4C5CC97A518E7C48604861A38212906 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + AA19BC5B1910746326571A254FA88B3B + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVEmptyRefreshCollectionView.m + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVEmptyRefreshCollectionView.m + sourceTree + <group> + + AA2A4ED034BB434233C1B9BB4DAD914B + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + SDWebImage-prefix.pch + sourceTree + <group> + + AA48FC085237DB822803986F22098618 + + fileRef + 068DDA81A2C94C892D7F5F299A8E5E0C + isa + PBXBuildFile + + AB1C015FB3D658D34C87EF822357A84B + + fileRef + 15381D52480D9DD90D0131DFF8425DCA + isa + PBXBuildFile + settings + + COMPILER_FLAGS + -DOS_OBJECT_USE_OBJC=0 + + + ACC2EB2A47656E483FFA63F5BB44449D + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + lobject.h + path + IOS/lua/lua/lobject.h + sourceTree + <group> + + AD10EC82D3BAC8EF1E7167B8C10E4F13 + + includeInIndex + 1 + isa + PBXFileReference + path + main.lua + sourceTree + <group> + + AF0E328E6199F0C716484F3C529D8654 + + fileRef + CC254FDF3B176BE0D1FE2DAF60B9E028 + isa + PBXBuildFile + + AF72EFDFCDCF19D4AE3A33627737C1EF + + fileRef + 78111672A9B49DC20741073B425CF56D + isa + PBXBuildFile + + AFD265D0B50B62C2C4F64C3B9BCE5C04 + + fileRef + 900805BE7DD4976E7F04C52CA8C66CF0 + isa + PBXBuildFile + + AFE78D019F9991D225A7A269ECD8C0B0 + + fileRef + B84E320E279FED0A6F24B9F2BE01DBFE + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + B037B7F37852EC8C203CE475066B236D + + fileRef + 8525801AE98FB64CBB07E945349BF8DF + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + B052D0B785F3DA3C09BFD52B66238399 + + fileRef + DF536325C88CC5C05ADDBE103FCE108A + isa + PBXBuildFile + + B054695A110D9DFA2F5EE986F47FDE77 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + MJRefreshNormalHeader.m + path + MJRefresh/Custom/Header/MJRefreshNormalHeader.m + sourceTree + <group> + + B0ACF7E54126A79BD4E4DF79697C42A1 + + fileRef + 87BD79A6744E4742A74A8F8FF55ED866 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + B10A64BAF7708212BEE77303B46759A0 + + fileRef + 5D9B05966CFC8F7C7BD4F72C404DBE56 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + B240D2A581351636E37A298B192C4955 + + fileRef + 6CE6B695B24CA6D79E9F7DCAD875C704 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + B242B68A8FF49BB326673D0FFB0F59D3 + + fileRef + 017115128E6833F9CC8D749E5B0A53AC + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + B246BF211681D59247ED035C9AEFE3F4 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVTypeConvert.m + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTypeConvert.m + sourceTree + <group> + + B27BE6C8B7906262FF5485D87EA8F0A7 + + fileRef + 3791750D2FBD5D56810E53D9A6213EC3 + isa + PBXBuildFile + + B28F53E51E7BAE28654B948FDFE0B85D + + fileRef + D2C0AC003380A8D1E007CCDC7F7838A2 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + B2ED8EC46C5618309FDADA00EDAAB038 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + lparser.h + path + IOS/lua/lua/lparser.h + sourceTree + <group> + + B3B3F38D1FA309127E9FB8AA32938AE7 + + includeInIndex + 1 + isa + PBXFileReference + name + lgc.c + path + IOS/lua/lua/lgc.c + sourceTree + <group> + + B3BE4498D6854DDC9F6297A6FCB28E40 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LVPinchGesture.h + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPinchGesture.h + sourceTree + <group> + + B3C078D88E41FB3B67B6C324D154545C + + containerPortal + D41D8CD98F00B204E9800998ECF8427E + isa + PBXContainerItemProxy + proxyType + 1 + remoteGlobalIDString + 4F318E6CB32EF6E77C176A2A5ACC0B17 + remoteInfo + LuaViewSDK + + B3E0B1CA0A5CA3939EE4E4EBD02850F0 + + includeInIndex + 1 + isa + PBXFileReference + name + lua.c + path + IOS/lua/lua/lua.c + sourceTree + <group> + + B437CB11C9C8EC6B415DB035A6DB10CF + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVLongPressGesture.m + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLongPressGesture.m + sourceTree + <group> + + B44A71FEED33ADF5978E99AA2B42225E + + fileRef + 4ADA7C57CE84EFE603F80884027F04EC + isa + PBXBuildFile + + B537193286E886B2BA49E092EF29398B + + fileRef + 23AF67BE150039A0C7AB1436EA782A9D + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + B583012233B3C4511452844069E5CFB3 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + SDWebImageCompat.h + path + SDWebImage/SDWebImageCompat.h + sourceTree + <group> + + B5A3EEB2278F9AE16DA9812651A81DF8 + + fileRef + E7EEB3F6ED037B879C6197E9C3434F7B + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + B5F531DD0399DAE73A325919B866B36F + + fileRef + 316EE69DE9BCB456A94DD12DDE19E4B8 + isa + PBXBuildFile + + B6F34069F4991BA877D50749E15E7944 + + fileRef + 687C81566E0A022C8A6FC66814230E29 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + B6FAA136270760CA13167ECBAC04ECB6 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + MJRefreshBackGifFooter.m + path + MJRefresh/Custom/Footer/Back/MJRefreshBackGifFooter.m + sourceTree + <group> + + B7B6154D69B450647A1787A95ECAD0F2 + + fileRef + 2CEF57B3C0FB4E9BB5127662BC6C2E1D + isa + PBXBuildFile + + B7F678867F20FD7240D39C5450EB80B1 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + NSObject+LuaView.h + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/NSObject+LuaView.h + sourceTree + <group> + + B84E320E279FED0A6F24B9F2BE01DBFE + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LVFlowLayout.h + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVFlowLayout.h + sourceTree + <group> + + B876B862054CB4F45B547C3CAE5D54BB + + fileRef + F3F30AD06DD8E12CFC418BDD2FB66A2C + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + B8A21090164872795973E5E8AA0E2B54 + + baseConfigurationReference + FB513E6EF7C88EF59301D4EA01043B1C + buildSettings + + ENABLE_STRICT_OBJC_MSGSEND + YES + GCC_PREFIX_HEADER + Target Support Files/SDWebImage/SDWebImage-prefix.pch + IPHONEOS_DEPLOYMENT_TARGET + 8.3 + MTL_ENABLE_DEBUG_INFO + NO + OTHER_LDFLAGS + + OTHER_LIBTOOLFLAGS + + PRIVATE_HEADERS_FOLDER_PATH + + PRODUCT_NAME + $(TARGET_NAME) + PUBLIC_HEADERS_FOLDER_PATH + + SDKROOT + iphoneos + SKIP_INSTALL + YES + + isa + XCBuildConfiguration + name + Release + + B8BDF91499C33445E7B061959CBDBEBF + + fileRef + A371B686E3E6E6310B394AEE93B61610 + isa + PBXBuildFile + + B91D13CD046CFF26BE47FCEE1167DD4E + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + lcode.h + path + IOS/lua/lua/lcode.h + sourceTree + <group> + + B96893B00EA263CC7C54DD966F040824 + + fileRef + FFC61C0A10406E550F6013C87AFA4DCE + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + B9E4D87AD5503242A1266D07BE1B569D + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LVTapGesture.h + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTapGesture.h + sourceTree + <group> + + BA49E2DC11A1F519D35DECDF146BF6BB + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVStyledString.m + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVStyledString.m + sourceTree + <group> + + BA4F2816B209AE73CD6DF71719815C3C + + fileRef + E3A9CBF61EE936EE325EC5AE883E0066 + isa + PBXBuildFile + + BA57FB285C5D390FCA342D014427BED5 + + isa + PBXTargetDependency + name + SDWebImage + target + 74FCE8A3277B50697CE9268AEF352C6D + targetProxy + D2A0FE1378F6519A82152B75A85672D5 + + BA6428E9F66FD5A23C0A2E06ED26CD2F + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + text + name + Podfile + path + ../Podfile + sourceTree + SOURCE_ROOT + xcLanguageSpecificationIdentifier + xcode.lang.ruby + + BA6A97FC288F57FADD6B38BFDF554A17 + + fileRef + 338F63C6EC6F5913CA70D9C3D8E6B5E2 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + BA93041CC60ED67985672DE90761EE2E + + buildConfigurationList + 4C0AEDA8B1664448BDACC855484B74B4 + buildPhases + + 37FC6F4C41E317AA28C71485F4297730 + 3D9F3435454E2D802E876586F239DFD9 + + buildRules + + dependencies + + 2E3ADBD6F47F2B2D01784DB392D0030F + 536AB72C44562204A9AC1391933D0E9F + BA57FB285C5D390FCA342D014427BED5 + E549C00ED107F14B95BC8419B6026C6B + + isa + PBXNativeTarget + name + Pods-luaviewEx_Example + productName + Pods-luaviewEx_Example + productReference + 7073693D24B8C984C2EB5C8007F3FF89 + productType + com.apple.product-type.library.static + + BAA4CCA3BCB98A42C54C87DEFDC3EA86 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LVDate.h + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVDate.h + sourceTree + <group> + + BAC23526788511468BCE9118BDC89F2B + + fileRef + 05D798E3E6D13DE52512EE4E6E91B1A2 + isa + PBXBuildFile + + BAE7B10AF626BF4D88E24777559D4F7E + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVLoadingIndicator.m + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVLoadingIndicator.m + sourceTree + <group> + + BB3C7B6B3CF4A394F8727BBA9628483B + + buildActionMask + 2147483647 + files + + 54BBBD6E8306EBC769FB0D15E0ECB8E6 + 770BFA720B343B1138A7A9C3DE47257F + E9ECAEBC3CED87D90F3A521D38AFE1BA + CC7557F38E2763B0896D4F72D06959AF + 49FA69425B92D350F96AAE29412E401A + C68DAED368AC2D72F439CD35AE18734E + 05BE865A8FF612F7CA84B35D9FA0EEBC + 84CA831836E0DB01AF70D0A6DCAEA523 + 71724E3BA243545F18CD67D71910EDB7 + D5DFE667412E0F7EF590DB025AAFE3BF + 0530B9C172A90C4EBEBB5D9A856A0CED + CFBFC237D8CB728EE71E0102528130F4 + 152E41D8C9AFCAE78F5FA1E151BDBD65 + FCA6FB57FC50423C23DCAC4372B4007A + 6E796FC19BDD4BEAF746BBDE91BA8F69 + + isa + PBXHeadersBuildPhase + runOnlyForDeploymentPostprocessing + 0 + + BB6CD102046C6DCE7A34320FC72DBA4D + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LVToast.h + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVToast.h + sourceTree + <group> + + BD19ABCFE68B0D0EBEADEFD602D439FF + + fileRef + 7B51A48200C44C9D509171257F1A7E66 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + BD4E504A2AF6C6A4769C02B1624AB7F9 + + fileRef + FA9C85076DEB156BACB490133D4BA212 + isa + PBXBuildFile + + BD8D6B4379E00E28A7D857559B9F24EB + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + UIView+LuaView.m + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/UIView+LuaView.m + sourceTree + <group> + + BDA6A83655BB36F3747E5F7BD91D5F84 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + ltm.h + path + IOS/lua/lua/ltm.h + sourceTree + <group> + + BE021AB2821FBE6EC7313AA7C0AD5B14 + + fileRef + 01B7F7F27F221C2D9F4F10B8A7EC25C9 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + BE108B26C574235B74731390BDF3446E + + children + + E2B47D08895CF12F15001D80641AE7EC + A7A35A14EB2A583EF86EA849BDF36947 + 088CCD3BADDAEDB931433BB0EC67F856 + 45749D20BBFB064A0B4BC0A1497BCC19 + 2CEF57B3C0FB4E9BB5127662BC6C2E1D + 978C32E4C97B32A331452E98DE44BEA5 + EA1BD290A8DBB924CF6F50D5B33A3333 + 2E1E59F6FBDA7901F0AD952037FCF736 + 537BC05E46F49890B5734D960924FEAF + 20F76BE16D5CEA070DB21524AC219E16 + C2859B4AF84A04B35C7DD4FC1752A3E6 + A3972136BB90BBA8BBD5E586E1B6DAC6 + B6FAA136270760CA13167ECBAC04ECB6 + 6DC12DF523650C6B0A46F3621ED2154B + 73DFDF42D880C766AAAD6FC80F309B80 + F8122BA13636B99796B9DB282114BFC7 + 2953440B280C7D7881037E1325598E5D + 12B5D15073B33A3A1CC86A97D66EBFA1 + 6CBE01C881C54307AD1E31E339461794 + 0BA6BF787BE2139B97022DBF837C477A + 4397FD63D238E023474037A653FDC151 + 00366E6D1CE623FE38FC0701EAB25A08 + E8847300301940C048B49C2444DFB3A8 + 6E6C16B857626130B368F3B40990E0AD + CF553BDF15D022A26DBC51003EF891A6 + 1C72D47259AD02A2958DE9AC84C7BC4C + 433D910F7D577FB44FFDD5FFA027ACBF + DA862005A7A8E002C1A0F7423119C939 + B054695A110D9DFA2F5EE986F47FDE77 + FCBD3E208A4816657C3EBFA78D140957 + 92DAC6EBFEC4A9240CD17049F862950F + 3744D8D317245CAF30FE6EB069FEE83F + 1303734F66CF41E1C7547B22B2B51AD1 + ECF1F5927ABD8D6A17557F62782A0F0B + 9348F06C427F5B963CB0C869D32EB643 + 508F587BDFC380AD0F25CD91E6534878 + 9F08ADE57BC15F9C6D36323887AFB74D + 5D9B05966CFC8F7C7BD4F72C404DBE56 + E91D368599C328C5143944AE759B8F95 + 8C5E0F2C73B42525D511F9714308FC97 + E3EAB8421C92490E10720D883D775E83 + + isa + PBXGroup + name + MJRefresh + path + MJRefresh + sourceTree + <group> + + BE838806D0FF138A1301C65ABAF45E6B + + fileRef + B3BE4498D6854DDC9F6297A6FCB28E40 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + BEA6A093F66522924757896C77F68E77 + + fileRef + A49570A1935CF988C04B098F2606CE08 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + BEDA54F495392FD177BAB5D6D4652408 + + fileRef + 67CAC872CD8C6AE9FDBA920A62E3B401 + isa + PBXBuildFile + + BF177C4379C6B237B00E3AE72C87BDAE + + fileRef + FDE0F21EBD582D712DA29995DB1ED48E + isa + PBXBuildFile + + BF85DD88573D2E0DBF15DDE9E1B579A5 + + fileRef + E5FE3D4D88BE8FD9FA166AC0D8D39CD6 + isa + PBXBuildFile + + BFFADAE0A0145E7EEEAFCA4AE0F42108 + + fileRef + E36CDE0F13900F882CB9AC04DF0807B7 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + C0266DA702333927677C77CC3FCB8390 + + fileRef + 088CCD3BADDAEDB931433BB0EC67F856 + isa + PBXBuildFile + + C0941004CD81E60FF109B01AAE00BB20 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVNetworkStatus.m + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNetworkStatus.m + sourceTree + <group> + + C0B33593D5C25E32A0416C2B0D1D6C19 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LVScrollView.h + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVScrollView.h + sourceTree + <group> + + C0F13A7CD2A4B649013B620A747F6E88 + + fileRef + 3C7F46EBB6D17715AFCDAF8AFD619F11 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + C0FEAFF56087033560A33AC4EE4F1E8B + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVScrollViewDelegate.m + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVScrollViewDelegate.m + sourceTree + <group> + + C10291D821E77E019EC760D33F1DAB2B + + fileRef + E2B47D08895CF12F15001D80641AE7EC + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + C1B386F18083FEBE0DF0528794C232C7 + + children + + 93E455E14459988C5B3FC784AC706191 + 53D9930552D81FA0E4F1BE66C8637137 + CA21EF19F2493AB60C8C0561BA72552A + 3DE1AF744EA6D6605090985C8C6F4385 + 3C7F46EBB6D17715AFCDAF8AFD619F11 + 8F625C3DF0AE978BB072440845B4E043 + 02C66FB7DB87FC2EB3AF533E0EF74677 + 95914943A4946223A1A9ED7908C6B6FB + 687C81566E0A022C8A6FC66814230E29 + 67CAC872CD8C6AE9FDBA920A62E3B401 + 838A78E077C0BD584472E06993CB3839 + DA43BA0061AF4BF9BF2135E29B1A9076 + 705CFDDE1D005A162AF3D2D672C0C89B + CEBB1F45E8262C05ED41A2ED289AB3E7 + A36F4D2D88A2A4FFACC5C69F07672F4C + 78730480B8BA4188FCCB69CDA7AC3192 + 567683F560B94BB3577E8A53F91CD895 + B91D13CD046CFF26BE47FCEE1167DD4E + A87D0C7B735B456A76F615F8A91E12AC + DF536325C88CC5C05ADDBE103FCE108A + FA721E2AB3F4F7FC2123D160555D7E6C + E3C0CE5600B627782320BB991C26CF5F + E36CDE0F13900F882CB9AC04DF0807B7 + 02DD81852450DF997CE182D2E8B96094 + C5E35B18C85702FF9D410ED1F4E1C927 + 969455D8276353B9FDA6D90FC62FA7D3 + B3B3F38D1FA309127E9FB8AA32938AE7 + A43792C99C7568064B453B7EB1E731F2 + 649039ECE2B1D879861962C561AE479B + D46D2419BC2639AC6CF379CB247C09E7 + 316EE69DE9BCB456A94DD12DDE19E4B8 + 71F22F871C8DB5D841A8B4BFFB5A01B1 + E1105AB3312E4B4559361BFB90F71113 + 9062C31E489D11885922F6D9606B893A + 900805BE7DD4976E7F04C52CA8C66CF0 + FFC61C0A10406E550F6013C87AFA4DCE + 023E7263521C3044AE972C99F20ACCF4 + 17A8628061070C222D27D34F72F83DF3 + ACC2EB2A47656E483FFA63F5BB44449D + 7D77C822DD8392B7460B91F3BBA432B6 + 6EE29D60F391D048B24759D53FA55883 + DD9AED002BD0179835C99F308950D01E + 4B47C50F2D0887FAB9E3A511BAF68DB9 + B2ED8EC46C5618309FDADA00EDAAB038 + 1E63B736F14800F163BEE98F2656AB57 + 2E2BD15CBDAF008E187B120F43D8A160 + 26639D12A9E924056B894755C310DC6A + 01B7F7F27F221C2D9F4F10B8A7EC25C9 + 1200BA0573F489F9E987B6963A9881F3 + 5A9081B1B6104EADB443FDF431CB7F72 + 9C2E5BED34AA1B93F6B3D3BD49B8C1A4 + A51172659A32E024907D7EBC0A4DD608 + 3A6684853B85972EBB9649F944951257 + BDA6A83655BB36F3747E5F7BD91D5F84 + B3E0B1CA0A5CA3939EE4E4EBD02850F0 + 3A17B20AEA2D43C15A6E2237C7037F0E + A5FFF7A1893C71D6813D36966DBB49F4 + ED6DB046063868A72062F85D42CE8FE9 + C277D3602A235B89D1CC70575720A3B2 + 9EA2901B5E44138E8D7C8D083215B941 + 843BCB6F268E541DB80F0C5957CD3F2C + 140A5FB3CE8CE79A82BF9395EA69294E + 4C79E04329C138C91B4F7F5CF3FB92C7 + 35ADDF72B83994A75288FF85E354EEB7 + 0188CA054AC3498974F6477FF90D8ECD + 33B017134DB0FDB8EABE416215B5F7FE + 0DA2D9EFDDF4C3FC2D398B83D445ACBC + A116F1B2F17A0588D81965CA21B07794 + 5B6F2D98A83100E60808E70843203413 + FAB3A9A70F42C5AD5AA78034A0017289 + 5689CDF8BB798D4EA126EFA3F609C7B9 + 402DAB9CCD76F0381D3246CFB4118AD8 + 5AC21404A4384C42C5EC654668A27CC2 + 31603E2B84E9141B15192CB5F08073EA + 4ADA7C57CE84EFE603F80884027F04EC + CF942522CEE1D4E4BAF884894D457FA5 + FDD0D74CC63C4876FA1BF2D67BBC2764 + 208EED9D527973A149D9358AA3702EB4 + 8E8C5F8980ECE0F6CB2DD488817F4BB7 + D2C0AC003380A8D1E007CCDC7F7838A2 + 6B31962F4E83B6F9BBA48A8E5815FDD7 + 493783C631E479F3E934D24AC62FEA52 + 81DD7ADF36D7EF7F645FB76353D5BE22 + 67BB47356A5DF21930F4CE9431DAEF9D + 7739E235EDE00D95E38D3BB4A5A3A323 + E775D30242799951B07F95972F3E44F0 + CB727C1002C9DC01B0669B16FE581B57 + FE813EC15653881F550BD15245030107 + D0EA885665A5CEA94A17BC94BB71F8CC + 6CE6B695B24CA6D79E9F7DCAD875C704 + D70DE8F803AE346E1B714A5919C6145F + D5E21862F3A5E53844655108A7B7E9AF + 4AB1C0F737FEE5C73C39CEC038113FCF + C9B0E6679F7503D4526E79D72761AD5E + 0ADF4BFF3F3CB2B0076ECC7EEDED7AA0 + A49570A1935CF988C04B098F2606CE08 + 4CEEDEC12FF31E0D8E32E478281AF82F + BAA4CCA3BCB98A42C54C87DEFDC3EA86 + 3BD94C9F2E00DE6591F2C354374F5E3C + CF453FA45EFCDB74BC1A5F5F33BBC71F + 6158D6FA11648C8C5CA6A804E036D158 + EBDDF52AF60ECE632FBC7F81C05742FB + A4A212231C1652C2163EA475935BC083 + 44514CC68F9B72D2BBADED400AB75D1F + E60754D5C7CDD4617817CA118EF56AEC + E5FE3D4D88BE8FD9FA166AC0D8D39CD6 + 8525801AE98FB64CBB07E945349BF8DF + 78111672A9B49DC20741073B425CF56D + DE174052C5D3174508B253F38871F6F9 + AA19BC5B1910746326571A254FA88B3B + 22DFFF53B43BF3B0CCD41940725C77DD + 78DD0AF22BF0E3660FC4CD8E74211F6B + D4C5CC97A518E7C48604861A38212906 + 93BA3472B3385E616264C6BCAA7AE0D0 + 98945AAA6D519D499411E6C2AB09E81C + 3EE531AEB3226242F2AA7877E8027660 + B84E320E279FED0A6F24B9F2BE01DBFE + 1BD1FEB3E27E055C9425C85436DCAC2F + 35CD100C2D0E4CC5D780A8296D404C8F + CC3B13995249C697A763C83DFDECED96 + F3F30AD06DD8E12CFC418BDD2FB66A2C + DB10E91F1AD28C6A2668776C9698163A + E7EEB3F6ED037B879C6197E9C3434F7B + 6BC1424DC3D5FEEE3721E798D6E24FFD + A2378894A63AF77F9CF73CC6BEED9C89 + A91426F56B4F86B643278F20C70E20B4 + 47338C4FF8A4FE3BB87A1D282B28DB0E + A1876BE3D22FCABA0929C593CA3BA01B + 7415E077E9F712607D4A69B6EF4E3A99 + CC254FDF3B176BE0D1FE2DAF60B9E028 + F840D91E74C3F85E04F29F7ABEF8F81C + F0B8BB58218ADF0076B616053D5A6D24 + 003669CF9C13F30F337B75D1277C9EE5 + 67509110E30D081975378406A2331EE1 + 87BD79A6744E4742A74A8F8FF55ED866 + 14E611D7FB8EBE58F4FE02103F29ADAE + 23AF67BE150039A0C7AB1436EA782A9D + BAE7B10AF626BF4D88E24777559D4F7E + 14C63F1ED1E755422CAD72947BB6854E + B437CB11C9C8EC6B415DB035A6DB10CF + 017115128E6833F9CC8D749E5B0A53AC + 8E2B5D644FA6140FCD60151561013E88 + F0DADEB1B812067E0D78DDBCAB1ABD4B + D6F14AF4755A5E9D5F102E6026867275 + A54FD7B60AF2B1A67ABE81FD1A4A9300 + 248AB64F8D0EE3AAC0FF476C689744D6 + 445BAA7F50663F5766B683D0F3734465 + EA8417A471B4E1EA55DD6CF63387B43B + 1A4C40BEE34C7100C87D3EA0409B2277 + 479F07FB188004636EDDA03D43002341 + A8A36E7B63A353F64AA2ACCF07D317C6 + C0941004CD81E60FF109B01AAE00BB20 + 7B51A48200C44C9D509171257F1A7E66 + 1936A2F7295154DE613E6EC820526985 + F2696A0E5D878881AC368ADB22AD54AE + E83E7FDFD7EE07DFC9D0B15DB3D53405 + 54E7640CB88EF3B2F9E4C730D4C254BB + 2A00E5624756359F3C35FD75432F1CDD + 6EA471E10DDA607666D946F224095BE0 + 2A813CC1F4A5B53EB94414FE3499E239 + 57B72E70DD55F7293F6E965A5295CD27 + 068DDA81A2C94C892D7F5F299A8E5E0C + B3BE4498D6854DDC9F6297A6FCB28E40 + 950FF5C3185C027C937FBB60FC84DE00 + 203B879A967F66A09F7417445102D54F + 1A54CE3B4BB248552036DB35C1EE2A8E + 0E7F78556C26EF63F32574BA1D25E267 + E3A9CBF61EE936EE325EC5AE883E0066 + D618AE4E806D645384B741FFD9B7A837 + 8ED4822A8555B90915C6EDE4F44D60B6 + EF061DEB3722BA928F0CEFC351D6013E + 5AD9B265AA9A38DEC7BAD050E1FFB64E + DDA2790797E4F4E4D3BBCC6487F018F9 + 57EBAFA2A570961A23BA797D5F3CC7CB + 325C3C570A4FDB3EBF50C0A7B13F91BF + F61782492D0F440833634360D6581150 + 007AA33BCC40F1B83EF19655BA2F1199 + 311B7A4524DB24F3FC085B190A2EEE4B + 5BEFD624052F9D9B420664CB47C04C2E + 1A891937EF4FE3E738E08AF8DF1960BE + C0B33593D5C25E32A0416C2B0D1D6C19 + 00C6711300727CE3A2D7A80B99BD48AF + 51EE67DEF356B157B9FC9DAC2821122B + C0FEAFF56087033560A33AC4EE4F1E8B + 08541999325B18DF76249F7305CFAF42 + A371B686E3E6E6310B394AEE93B61610 + 338F63C6EC6F5913CA70D9C3D8E6B5E2 + BA49E2DC11A1F519D35DECDF146BF6BB + 171B1BADE853597D819B610B8E8FD83C + 12D1D6C08777961A0F9E3FA5C0E64F8D + 890C426A9ADC94BA5988DA60295203C8 + 5C15D90409A3D72F70B502B6FBBBD972 + B9E4D87AD5503242A1266D07BE1B569D + F36977FE41664527E1C707D3481426FF + 46E2FFAE81593D15ECDF37606CF93415 + A5A1201FDEB20DFB66C314031B9AAB06 + A0D2A3B993113E8AF1A63CA5189A8860 + FDE0F21EBD582D712DA29995DB1ED48E + BB6CD102046C6DCE7A34320FC72DBA4D + 86AF9BF25759B6F231FFB4FA43AEA4B2 + EF5FE19F0817E2CCD49CED853AFC3EA6 + 70FD815DF49786A6ED20480D82DF1798 + 1EE667E76E8DE6FA80C6611D3FD1781E + B246BF211681D59247ED035C9AEFE3F4 + 1FB2A9CD333316F15BDBD47C0ECBB3F6 + 0D8B62C0984BC350ECBE7CC39F0060F7 + 6891D507788A858BA1297B6942E967F4 + EEF29B31E969DD77D33BCCB6F665FF96 + 472A5178F982E81426BEF67B5D65F41D + 2F4A25979F4326CF43F387B4CD7A9387 + F415216825466C77176DE9B6A714414F + 89FB168616EAC47EBAF5F5819F0E966B + B7F678867F20FD7240D39C5450EB80B1 + 25D9F3CA59FDF03A99EC82DDC3FA2199 + F92BF22EEADD8B8F8EE14951B0A60346 + 51FCC0A1C88049285E0BED1A17102E40 + 2172479607CC3CD63DA704312491E457 + 2BA16F5CCD3F1E210008D8280A170F1B + 3791750D2FBD5D56810E53D9A6213EC3 + 50487FC48724B55B3FAD221340A0D10A + 187EF30C8816993691A5B142EBB7CB36 + 03ADB1EE211113EC9C3B9167F0A4DB0A + BD8D6B4379E00E28A7D857559B9F24EB + 74F3D6287B71307E8BB3C163630654EE + + isa + PBXGroup + name + LuaViewSDK + path + LuaViewSDK + sourceTree + <group> + + C1EB25A94C462FE757B4619F120B27EA + + fileRef + 1D6054D63442F671F8D09855592CB662 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + C24A651C62A5C7D591E23BD81FF4425D + + fileRef + ACC2EB2A47656E483FFA63F5BB44449D + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + C277D3602A235B89D1CC70575720A3B2 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + lualib.h + path + IOS/lua/lua/lualib.h + sourceTree + <group> + + C2859B4AF84A04B35C7DD4FC1752A3E6 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + MJRefreshBackFooter.m + path + MJRefresh/Base/MJRefreshBackFooter.m + sourceTree + <group> + + C49AE2D524F5FB037C0B0F1839A186D3 + + fileRef + 25F8ABDD1532A296D8F95098E2E0A972 + isa + PBXBuildFile + + C5E35B18C85702FF9D410ED1F4E1C927 + + includeInIndex + 1 + isa + PBXFileReference + name + lfunc.c + path + IOS/lua/lua/lfunc.c + sourceTree + <group> + + C5E5EAA6F912F30EDACB1AE47C1518B7 + + fileRef + 25F8ABDD1532A296D8F95098E2E0A972 + isa + PBXBuildFile + + C6022F273B52E68EB2F1C85D62ECA70F + + children + + 515E0623D108242C6EF06F4962027BC0 + + isa + PBXGroup + name + Development Pods + sourceTree + <group> + + C60FF21AED50CA88BA04605746067E62 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + luaviewEx-prefix.pch + sourceTree + <group> + + C659EE25D3B7EB140970740ABABEACD9 + + fileRef + D70DE8F803AE346E1B714A5919C6145F + isa + PBXBuildFile + + C68D95FDE83929CBBE8BADCC16B14E69 + + isa + PBXTargetDependency + name + LuaViewSDK + target + 4F318E6CB32EF6E77C176A2A5ACC0B17 + targetProxy + B3C078D88E41FB3B67B6C324D154545C + + C68DAED368AC2D72F439CD35AE18734E + + fileRef + 727C7485C9B787AADCED8051FBBD24DB + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + C6A6CD778AFAA43EA50F4B4AAD69FE3A + + fileRef + F36977FE41664527E1C707D3481426FF + isa + PBXBuildFile + + C6FFE935D19D6EE38B9EE3A92461CF47 + + fileRef + 1936A2F7295154DE613E6EC820526985 + isa + PBXBuildFile + + C70C5EA435C67E3DB6D52610FF9E4303 + + fileRef + A36F4D2D88A2A4FFACC5C69F07672F4C + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + C768C62C080C06511C4FAD0DD3C75DC8 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + text.script.sh + path + Pods-luaviewEx_Example-frameworks.sh + sourceTree + <group> + + C7F85E5C5B56884FAC41FE7ACCCB7B96 + + fileRef + 08541999325B18DF76249F7305CFAF42 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + C9B0E6679F7503D4526E79D72761AD5E + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LVCustomView.h + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCustomView.h + sourceTree + <group> + + CA21EF19F2493AB60C8C0561BA72552A + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + JUFLXLayoutDefine.h + path + IOS/SDK/LuaViewSDK/Classes/layout/JUFLXLayoutDefine.h + sourceTree + <group> + + CA26090B11F23CC29648ACC0341DD7C1 + + fileRef + E3C0CE5600B627782320BB991C26CF5F + isa + PBXBuildFile + + CAEABFF750CE4ABF01280F717030161C + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVViewController.m + sourceTree + <group> + + CB727C1002C9DC01B0669B16FE581B57 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVCollectionView.m + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCollectionView.m + sourceTree + <group> + + CB8FA076BCABE1AFF3A3325C222DFA1E + + children + + F13126CCA6A080653A6EFFDF3338B31B + + isa + PBXGroup + name + luaviewEx + path + luaviewEx + sourceTree + <group> + + CBAE399F2CEB69306E6A192564A5A597 + + fileRef + F0B8BB58218ADF0076B616053D5A6D24 + isa + PBXBuildFile + + CC254FDF3B176BE0D1FE2DAF60B9E028 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LView.m + path + IOS/SDK/LuaViewSDK/Classes/LView.m + sourceTree + <group> + + CC3B13995249C697A763C83DFDECED96 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVGesture.m + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVGesture.m + sourceTree + <group> + + CC7557F38E2763B0896D4F72D06959AF + + fileRef + DC2A62DF22CB330C871C83E5DCC5A659 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + CCBA5EC0FEAC0C022D514664CB0A8F9B + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + SDWebImageDownloader.m + path + SDWebImage/SDWebImageDownloader.m + sourceTree + <group> + + CD2F0B2AD480735DCD585AADA045E315 + + buildConfigurationList + 20A306972C1A8633ECE0E1237822BB61 + buildPhases + + 1E6B9968B212F59E3B0F27CB3FBFC8BF + A51C113A8035ADD4365A0C0751BAC77A + 63D59307BAFC1BA81B916BEDAB4682E9 + + buildRules + + dependencies + + isa + PBXNativeTarget + name + luaviewEx-luaviewEx + productName + luaviewEx-luaviewEx + productReference + E4EDF2505C6AA1619D1AD0A8DC324AB3 + productType + com.apple.product-type.bundle + + CD67C1EAF9CE00756E1DF489C938A6ED + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + SDWebImageDecoder.m + path + SDWebImage/SDWebImageDecoder.m + sourceTree + <group> + + CDF1BDF9A1DB1D02653AAE821A4B39C5 + + fileRef + 950FF5C3185C027C937FBB60FC84DE00 + isa + PBXBuildFile + + CE8411601EBF400FDDB59EB243710BC8 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + UIImage+MultiFormat.h + path + SDWebImage/UIImage+MultiFormat.h + sourceTree + <group> + + CEBB1F45E8262C05ED41A2ED289AB3E7 + + includeInIndex + 1 + isa + PBXFileReference + name + Layout.c + path + IOS/SDK/LuaViewSDK/Classes/layout/Layout.c + sourceTree + <group> + + CED3E9092F7193546D7D0212737C1F20 + + fileRef + 47338C4FF8A4FE3BB87A1D282B28DB0E + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + CEF0CB460D46CC901B4002C668509144 + + fileRef + B9E4D87AD5503242A1266D07BE1B569D + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + CEFDC58C7241F86D92DEF8EDFCE7DF99 + + fileRef + 1029FE5B1649EC32DB1502473DD8C938 + isa + PBXBuildFile + + CF453FA45EFCDB74BC1A5F5F33BBC71F + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LVDB.h + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVDB.h + sourceTree + <group> + + CF553BDF15D022A26DBC51003EF891A6 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + MJRefreshGifHeader.m + path + MJRefresh/Custom/Header/MJRefreshGifHeader.m + sourceTree + <group> + + CF942522CEE1D4E4BAF884894D457FA5 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LVBlock.h + path + IOS/SDK/LuaViewSDK/Classes/LVBlock.h + sourceTree + <group> + + CFBFC237D8CB728EE71E0102528130F4 + + fileRef + CE8411601EBF400FDDB59EB243710BC8 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + CFFAA082F61AB74F30C5BF024E7CC8E1 + + fileRef + 0188CA054AC3498974F6477FF90D8ECD + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + D0CF3B992AE9A436F7A617459A0D5F69 + + fileRef + 98945AAA6D519D499411E6C2AB09E81C + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + D0EA885665A5CEA94A17BC94BB71F8CC + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVCollectionViewCell.m + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCollectionViewCell.m + sourceTree + <group> + + D155DDB3A2C8DC3AFBBA3915C2DFFF7E + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + SDWebImageCompat.m + path + SDWebImage/SDWebImageCompat.m + sourceTree + <group> + + D20CB9D528CE0F266A506596D0398D85 + + fileRef + 3EE531AEB3226242F2AA7877E8027660 + isa + PBXBuildFile + + D2318D2B236AD2B42AEFA3409D6462F5 + + baseConfigurationReference + 1E455130CD554E363685BBC7EDB1AACE + buildSettings + + ENABLE_STRICT_OBJC_MSGSEND + YES + GCC_PREFIX_HEADER + Target Support Files/LuaViewSDK/LuaViewSDK-prefix.pch + IPHONEOS_DEPLOYMENT_TARGET + 8.3 + MTL_ENABLE_DEBUG_INFO + YES + OTHER_LDFLAGS + + OTHER_LIBTOOLFLAGS + + PRIVATE_HEADERS_FOLDER_PATH + + PRODUCT_NAME + $(TARGET_NAME) + PUBLIC_HEADERS_FOLDER_PATH + + SDKROOT + iphoneos + SKIP_INSTALL + YES + + isa + XCBuildConfiguration + name + Debug + + D28DAD6825DB9029D2DB8A52B4FD53FB + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + UIImageView+WebCache.h + path + SDWebImage/UIImageView+WebCache.h + sourceTree + <group> + + D2A0FE1378F6519A82152B75A85672D5 + + containerPortal + D41D8CD98F00B204E9800998ECF8427E + isa + PBXContainerItemProxy + proxyType + 1 + remoteGlobalIDString + 74FCE8A3277B50697CE9268AEF352C6D + remoteInfo + SDWebImage + + D2C0AC003380A8D1E007CCDC7F7838A2 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LVButton.h + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVButton.h + sourceTree + <group> + + D2CD868E08C2A85B1543BBBE5BD4C2FC + + fileRef + 248AB64F8D0EE3AAC0FF476C689744D6 + isa + PBXBuildFile + + D3C4123A5BE271923C45984D624F58FF + + fileRef + DE174052C5D3174508B253F38871F6F9 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + D41D8CD98F00B204E9800998ECF8427E + + attributes + + LastSwiftUpdateCheck + 0700 + LastUpgradeCheck + 0700 + + buildConfigurationList + 2D8E8EC45A3A1A1D94AE762CB5028504 + compatibilityVersion + Xcode 3.2 + developmentRegion + English + hasScannedForEncodings + 0 + isa + PBXProject + knownRegions + + en + + mainGroup + 7DB346D0F39D3F0E887471402A8071AB + productRefGroup + 4B8AC868439D6B598FE5F597062E8BB6 + projectDirPath + + projectReferences + + projectRoot + + targets + + 1453C4742639DC29E77A2A397333AB6A + CD2F0B2AD480735DCD585AADA045E315 + 4F318E6CB32EF6E77C176A2A5ACC0B17 + 70BC44266C6FFE30D2C57129458E070B + BA93041CC60ED67985672DE90761EE2E + 74FCE8A3277B50697CE9268AEF352C6D + + + D444A813656B5E13709C7182926AB285 + + fileRef + 1A4C40BEE34C7100C87D3EA0409B2277 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + D46D2419BC2639AC6CF379CB247C09E7 + + includeInIndex + 1 + isa + PBXFileReference + name + liolib.c + path + IOS/lua/lua/liolib.c + sourceTree + <group> + + D4C5CC97A518E7C48604861A38212906 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LVExGlobalFunc.h + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVExGlobalFunc.h + sourceTree + <group> + + D553675D6159FC01CF2C9FF4F416FA26 + + fileRef + 1200BA0573F489F9E987B6963A9881F3 + isa + PBXBuildFile + + D56ED68ACC53224CD4BC37A6B5BC6EB1 + + fileRef + 24ACDAAE48ECC19C32A56CE5DE769C97 + isa + PBXBuildFile + settings + + COMPILER_FLAGS + -DOS_OBJECT_USE_OBJC=0 + + + D5DFE667412E0F7EF590DB025AAFE3BF + + fileRef + DDF8FFFA4075B105F7CC30A697DAECD8 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + D5E21862F3A5E53844655108A7B7E9AF + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LVCustomPanel.h + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCustomPanel.h + sourceTree + <group> + + D618AE4E806D645384B741FFD9B7A837 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LVPointerValueBox.h + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPointerValueBox.h + sourceTree + <group> + + D6F14AF4755A5E9D5F102E6026867275 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + lvm.h + path + IOS/lua/lua/lvm.h + sourceTree + <group> + + D70DE8F803AE346E1B714A5919C6145F + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVCollectionViewDelegate.m + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCollectionViewDelegate.m + sourceTree + <group> + + D793F466F0871DFC7E2E6CAE9DEA8CFD + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + SDWebImageManager.m + path + SDWebImage/SDWebImageManager.m + sourceTree + <group> + + D8389FAFCAF9D8FCC1A95A1DCD8D9ECD + + fileRef + C277D3602A235B89D1CC70575720A3B2 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + D9AD27D17166C52B00A9E224E5380547 + + fileRef + 44514CC68F9B72D2BBADED400AB75D1F + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + DA43BA0061AF4BF9BF2135E29B1A9076 + + includeInIndex + 1 + isa + PBXFileReference + name + lauxlib.c + path + IOS/lua/lua/lauxlib.c + sourceTree + <group> + + DA862005A7A8E002C1A0F7423119C939 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + MJRefreshNormalHeader.h + path + MJRefresh/Custom/Header/MJRefreshNormalHeader.h + sourceTree + <group> + + DA9257B35361B576E0A3D77062933847 + + isa + PBXTargetDependency + name + luaviewEx-luaviewEx + target + CD2F0B2AD480735DCD585AADA045E315 + targetProxy + 9F22373CA3B354C4A11258EFD35DE7B3 + + DB10E91F1AD28C6A2668776C9698163A + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVGrammarChanger.m + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVGrammarChanger.m + sourceTree + <group> + + DBF475EA219170B3C68BB1446AE8C55A + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + Pods-luaviewEx_Example-dummy.m + sourceTree + <group> + + DC2A62DF22CB330C871C83E5DCC5A659 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + SDWebImageDecoder.h + path + SDWebImage/SDWebImageDecoder.h + sourceTree + <group> + + DC8B2107202170D5C988FA09BC338CF5 + + fileRef + EA8417A471B4E1EA55DD6CF63387B43B + isa + PBXBuildFile + + DCDE4C56163FC1F76D6C35A19F1A9CA8 + + fileRef + 93BA3472B3385E616264C6BCAA7AE0D0 + isa + PBXBuildFile + + DCEA9B91A91B8834D6805B841A16C9BF + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + text + path + Pods-luaviewEx_Example-acknowledgements.markdown + sourceTree + <group> + + DD604C7F2696CB8FC9805837BCF61402 + + fileRef + 51FCC0A1C88049285E0BED1A17102E40 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + DD9AED002BD0179835C99F308950D01E + + includeInIndex + 1 + isa + PBXFileReference + name + loslib.c + path + IOS/lua/lua/loslib.c + sourceTree + <group> + + DDA2790797E4F4E4D3BBCC6487F018F9 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LVRefreshConst.h + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRefreshConst.h + sourceTree + <group> + + DDE5689688A6E9EFBF7717D961CF164C + + fileRef + 25F8ABDD1532A296D8F95098E2E0A972 + isa + PBXBuildFile + + DDF8FFFA4075B105F7CC30A697DAECD8 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + UIButton+WebCache.h + path + SDWebImage/UIButton+WebCache.h + sourceTree + <group> + + DE174052C5D3174508B253F38871F6F9 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LVEmptyRefreshCollectionView.h + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVEmptyRefreshCollectionView.h + sourceTree + <group> + + DF536325C88CC5C05ADDBE103FCE108A + + includeInIndex + 1 + isa + PBXFileReference + name + ldebug.c + path + IOS/lua/lua/ldebug.c + sourceTree + <group> + + E03A9B9C8AD7448D4001395A3EB78B92 + + fileRef + 402DAB9CCD76F0381D3246CFB4118AD8 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + E0C0C57120BC2EDC95A79E05E8CD9C90 + + fileRef + 4CEEDEC12FF31E0D8E32E478281AF82F + isa + PBXBuildFile + + E1105AB3312E4B4559361BFB90F71113 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + llimits.h + path + IOS/lua/lua/llimits.h + sourceTree + <group> + + E2666B34BAA41A7620A5214CEBE2CE98 + + fileRef + 0ACB826940D91D6F0E3B839BC7EA70A2 + isa + PBXBuildFile + settings + + COMPILER_FLAGS + -DOS_OBJECT_USE_OBJC=0 + + + E2B47D08895CF12F15001D80641AE7EC + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + MJRefresh.h + path + MJRefresh/MJRefresh.h + sourceTree + <group> + + E2C7D367AC6691B5858A77A2D3A1CD6A + + fileRef + 2172479607CC3CD63DA704312491E457 + isa + PBXBuildFile + + E36CDE0F13900F882CB9AC04DF0807B7 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + ldo.h + path + IOS/lua/lua/ldo.h + sourceTree + <group> + + E3A9CBF61EE936EE325EC5AE883E0066 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVPkgManager.m + path + IOS/SDK/LuaViewSDK/Classes/PKG/LVPkgManager.m + sourceTree + <group> + + E3C0CE5600B627782320BB991C26CF5F + + includeInIndex + 1 + isa + PBXFileReference + name + ldo.c + path + IOS/lua/lua/ldo.c + sourceTree + <group> + + E3EAB8421C92490E10720D883D775E83 + + children + + 7A9B772B1DCEE38F37A46280BAF68BCE + 1029FE5B1649EC32DB1502473DD8C938 + 380891D31A6A00C43DFDE002247409D6 + + isa + PBXGroup + name + Support Files + path + ../Target Support Files/MJRefresh + sourceTree + <group> + + E4EDF2505C6AA1619D1AD0A8DC324AB3 + + explicitFileType + wrapper.cfbundle + includeInIndex + 0 + isa + PBXFileReference + name + luaviewEx.bundle + path + luaviewEx.bundle + sourceTree + BUILT_PRODUCTS_DIR + + E53454694FBDE9F46C885AF250A1D462 + + fileRef + D618AE4E806D645384B741FFD9B7A837 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + E549C00ED107F14B95BC8419B6026C6B + + isa + PBXTargetDependency + name + luaviewEx + target + 1453C4742639DC29E77A2A397333AB6A + targetProxy + 8E05C821622BBE09397D3CC007F1E968 + + E5FE3D4D88BE8FD9FA166AC0D8D39CD6 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVDebugLua.m + path + IOS/SDK/LuaViewSDK/Classes/lvdebug/LVDebugLua.m + sourceTree + <group> + + E60754D5C7CDD4617817CA118EF56AEC + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVDebuger.m + path + IOS/SDK/LuaViewSDK/Classes/lvdebug/LVDebuger.m + sourceTree + <group> + + E775D30242799951B07F95972F3E44F0 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LVCollectionView.h + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCollectionView.h + sourceTree + <group> + + E799FF5DF3ABE640807F8CA4B6F7B06A + + fileRef + 4B47C50F2D0887FAB9E3A511BAF68DB9 + isa + PBXBuildFile + + E7A8DDD289D3BFB8950D29CBF67C7132 + + fileRef + C2859B4AF84A04B35C7DD4FC1752A3E6 + isa + PBXBuildFile + + E7EEB3F6ED037B879C6197E9C3434F7B + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LVHeads.h + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVHeads.h + sourceTree + <group> + + E83E7FDFD7EE07DFC9D0B15DB3D53405 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVPagerIndicator.m + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPagerIndicator.m + sourceTree + <group> + + E8847300301940C048B49C2444DFB3A8 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + MJRefreshFooter.m + path + MJRefresh/Base/MJRefreshFooter.m + sourceTree + <group> + + E8F9AB235FA3DB06565888ED1DB21838 + + fileRef + 8ED4822A8555B90915C6EDE4F44D60B6 + isa + PBXBuildFile + + E9147195251E0E11AD9BEC4D2227EA9B + + isa + PBXFileReference + lastKnownFileType + wrapper.framework + name + ImageIO.framework + path + Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.0.sdk/System/Library/Frameworks/ImageIO.framework + sourceTree + DEVELOPER_DIR + + E91D368599C328C5143944AE759B8F95 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + UIView+MJExtension.m + path + MJRefresh/UIView+MJExtension.m + sourceTree + <group> + + E95261BDED4B03E24FC2E72EC37CB509 + + fileRef + FAB3A9A70F42C5AD5AA78034A0017289 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + E954B9D3A283FB30A945CE8823E102DD + + fileRef + E8847300301940C048B49C2444DFB3A8 + isa + PBXBuildFile + + E9ECAEBC3CED87D90F3A521D38AFE1BA + + fileRef + B583012233B3C4511452844069E5CFB3 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + EA1BD290A8DBB924CF6F50D5B33A3333 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + MJRefreshAutoNormalFooter.m + path + MJRefresh/Custom/Footer/Auto/MJRefreshAutoNormalFooter.m + sourceTree + <group> + + EA51452B77AACCDD1D12492768151215 + + fileRef + FDD0D74CC63C4876FA1BF2D67BBC2764 + isa + PBXBuildFile + + EA8417A471B4E1EA55DD6CF63387B43B + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVNativeObjBox.m + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVNativeObjBox.m + sourceTree + <group> + + EAD4713FA50BEEBAFF24F34A0311F0EA + + children + + 364BA089FD07E58FA10BDD7B0B1DAE77 + + isa + PBXGroup + name + luaviewEx + path + luaviewEx + sourceTree + <group> + + EADADD53B7ABD476C83346CFCF2F15DA + + fileRef + 764FA85F96E0C2203583A303AB5E2A19 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + EBA4185E7D76AE98B42C70BD4C3B8E55 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + path + LuaViewSDK-prefix.pch + sourceTree + <group> + + EBC90D170EC49DBF123E19EDECA99992 + + fileRef + FDB3D7BFD24479ACA7B4A8AFEFB5554D + isa + PBXBuildFile + + EBDDF52AF60ECE632FBC7F81C05742FB + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LVDebugConnection.h + path + IOS/SDK/LuaViewSDK/Classes/lvdebug/LVDebugConnection.h + sourceTree + <group> + + EC0A52132E4476FCCA78F5317059C023 + + fileRef + 94289A039303C4BC79EA35AD39A597FA + isa + PBXBuildFile + settings + + COMPILER_FLAGS + -DOS_OBJECT_USE_OBJC=0 + + + EC5C35AC2FEC11F77ED822D5979CC349 + + includeInIndex + 1 + isa + PBXFileReference + path + object.lua + sourceTree + <group> + + ECF1F5927ABD8D6A17557F62782A0F0B + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + UIScrollView+MJExtension.h + path + MJRefresh/UIScrollView+MJExtension.h + sourceTree + <group> + + ED6DB046063868A72062F85D42CE8FE9 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + luaconf.h + path + IOS/lua/lua/luaconf.h + sourceTree + <group> + + EDC93199A529A328783AE13C758F338E + + fileRef + 12D1D6C08777961A0F9E3FA5C0E64F8D + isa + PBXBuildFile + + EE68F5F89DE2D1D3AA85D0BE46210819 + + fileRef + 8E2B5D644FA6140FCD60151561013E88 + isa + PBXBuildFile + + EE6F5B992DE6AEF9FA035830B86988A8 + + fileRef + F5ECACD0C38562F4F2E34802BD0988BC + isa + PBXBuildFile + + EEF29B31E969DD77D33BCCB6F665FF96 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVWebView.m + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVWebView.m + sourceTree + <group> + + EF061DEB3722BA928F0CEFC351D6013E + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LVRefreshComponent.h + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRefreshComponent.h + sourceTree + <group> + + EF06428C066EFCEF8F25ED2786BB8002 + + fileRef + 71F22F871C8DB5D841A8B4BFFB5A01B1 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + EF5FE19F0817E2CCD49CED853AFC3EA6 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LVTransform3D.h + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTransform3D.h + sourceTree + <group> + + EFB3DB5A3F155CB5B9F400A038CA233B + + fileRef + 3DE1AF744EA6D6605090985C8C6F4385 + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + EFFB2D478FDAC062278F1C29DB6628C0 + + fileRef + 3AC8A9CDF659CBBCA1320C8046434793 + isa + PBXBuildFile + + F01687C8E9A3E4F8A528BE97DE7BDB80 + + fileRef + B6FAA136270760CA13167ECBAC04ECB6 + isa + PBXBuildFile + + F04FA8541749536AE6A5E96B5BA70D85 + + fileRef + 25F8ABDD1532A296D8F95098E2E0A972 + isa + PBXBuildFile + + F058A2EEE827FAD98DE4935EDB669368 + + fileRef + D0EA885665A5CEA94A17BC94BB71F8CC + isa + PBXBuildFile + + F0B8BB58218ADF0076B616053D5A6D24 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LViewController.m + path + IOS/SDK/LuaViewSDK/Classes/LViewController.m + sourceTree + <group> + + F0DADEB1B812067E0D78DDBCAB1ABD4B + + includeInIndex + 1 + isa + PBXFileReference + name + lvm.c + path + IOS/lua/lua/lvm.c + sourceTree + <group> + + F130DA2142E93C4AEBA9C770EB26C9CD + + fileRef + B3E0B1CA0A5CA3939EE4E4EBD02850F0 + isa + PBXBuildFile + + F13126CCA6A080653A6EFFDF3338B31B + + children + + 36444253FBF11067C2A948FD3F51354B + + isa + PBXGroup + name + Assets + path + Assets + sourceTree + <group> + + F13912E48FDB68CCF4BDBB76D803FD90 + + fileRef + 705CFDDE1D005A162AF3D2D672C0C89B + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + F1951C4E966743798495C533F7C2F5A9 + + fileRef + C0941004CD81E60FF109B01AAE00BB20 + isa + PBXBuildFile + + F23A9B4C97F8BE23F6473F1838E1F72B + + fileRef + 514DBCD4730D08D27E7801BEBB135AFD + isa + PBXBuildFile + + F2696A0E5D878881AC368ADB22AD54AE + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LVPagerIndicator.h + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVPagerIndicator.h + sourceTree + <group> + + F36977FE41664527E1C707D3481426FF + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVTapGesture.m + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTapGesture.m + sourceTree + <group> + + F3AC7C93C770A6F7918EA23972C1762A + + fileRef + CF553BDF15D022A26DBC51003EF891A6 + isa + PBXBuildFile + + F3BD82EE8CAB6FC8B410C0865280E598 + + baseConfigurationReference + A70095A630FF08A50442B16D1B37308C + buildSettings + + ENABLE_STRICT_OBJC_MSGSEND + YES + PRODUCT_NAME + luaviewEx + SDKROOT + iphoneos + SKIP_INSTALL + YES + WRAPPER_EXTENSION + bundle + + isa + XCBuildConfiguration + name + Debug + + F3F30AD06DD8E12CFC418BDD2FB66A2C + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LVGrammarChanger.h + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVGrammarChanger.h + sourceTree + <group> + + F415216825466C77176DE9B6A714414F + + includeInIndex + 1 + isa + PBXFileReference + name + lzio.c + path + IOS/lua/lua/lzio.c + sourceTree + <group> + + F4F6EC8C90DE4BAA88081B3047E0E9B7 + + fileRef + 70FD815DF49786A6ED20480D82DF1798 + isa + PBXBuildFile + + F51168584B32F3D4944CDCE21DB312A9 + + fileRef + B91D13CD046CFF26BE47FCEE1167DD4E + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + F52763D22F95CF0A6F8491822F37BF5D + + fileRef + 6CBE01C881C54307AD1E31E339461794 + isa + PBXBuildFile + + F569CDB32B52B31011145A315C00ACE0 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + wrapper.plug-in + name + MJRefresh.bundle + path + MJRefresh/MJRefresh.bundle + sourceTree + <group> + + F5ECACD0C38562F4F2E34802BD0988BC + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVExCollectionView.m + sourceTree + <group> + + F61782492D0F440833634360D6581150 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVRefreshHeader.m + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVRefreshHeader.m + sourceTree + <group> + + F624E64DD3338E4E653B1FA6F7F639CC + + containerPortal + D41D8CD98F00B204E9800998ECF8427E + isa + PBXContainerItemProxy + proxyType + 1 + remoteGlobalIDString + 70BC44266C6FFE30D2C57129458E070B + remoteInfo + MJRefresh + + F73FE9772F32C391B1AAB165B7618F08 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + path + LVExButton.m + sourceTree + <group> + + F80959A1904B32F4C03A43821DEA064C + + fileRef + 5AD9B265AA9A38DEC7BAD050E1FFB64E + isa + PBXBuildFile + + F8122BA13636B99796B9DB282114BFC7 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + MJRefreshBackStateFooter.h + path + MJRefresh/Custom/Footer/Back/MJRefreshBackStateFooter.h + sourceTree + <group> + + F833457C4CDBB69A21839521C6C2AD5B + + buildActionMask + 2147483647 + files + + C5E5EAA6F912F30EDACB1AE47C1518B7 + + isa + PBXFrameworksBuildPhase + runOnlyForDeploymentPostprocessing + 0 + + F840D91E74C3F85E04F29F7ABEF8F81C + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LViewController.h + path + IOS/SDK/LuaViewSDK/Classes/LViewController.h + sourceTree + <group> + + F85FB92DB3CBF2A0853930794C17822D + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + UIView+WebCacheOperation.m + path + SDWebImage/UIView+WebCacheOperation.m + sourceTree + <group> + + F92BF22EEADD8B8F8EE14951B0A60346 + + includeInIndex + 1 + isa + PBXFileReference + name + print.c + path + IOS/lua/lua/print.c + sourceTree + <group> + + F9C85C83BD4D3C17E408FB82242BB884 + + children + + 3076D7998BCE2564AC10D34F4E35919C + + isa + PBXGroup + name + Targets Support Files + sourceTree + <group> + + FA21A688EC47146B09AC98BBCEFEFFC8 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + SDWebImagePrefetcher.h + path + SDWebImage/SDWebImagePrefetcher.h + sourceTree + <group> + + FA721E2AB3F4F7FC2123D160555D7E6C + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + ldebug.h + path + IOS/lua/lua/ldebug.h + sourceTree + <group> + + FA9C85076DEB156BACB490133D4BA212 + + isa + PBXFileReference + lastKnownFileType + wrapper.framework + name + CoreGraphics.framework + path + Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.0.sdk/System/Library/Frameworks/CoreGraphics.framework + sourceTree + DEVELOPER_DIR + + FAB3A9A70F42C5AD5AA78034A0017289 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LVAnimator.h + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVAnimator.h + sourceTree + <group> + + FB513E6EF7C88EF59301D4EA01043B1C + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + text.xcconfig + path + SDWebImage.xcconfig + sourceTree + <group> + + FB69CD50281750767B6A748377B527C1 + + fileRef + 22DFFF53B43BF3B0CCD41940725C77DD + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + FC0D40A8DC42764EA1CCB56A30538E3C + + fileRef + 26639D12A9E924056B894755C310DC6A + isa + PBXBuildFile + + FCA6FB57FC50423C23DCAC4372B4007A + + fileRef + D28DAD6825DB9029D2DB8A52B4FD53FB + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + FCBD3E208A4816657C3EBFA78D140957 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + MJRefreshStateHeader.h + path + MJRefresh/Custom/Header/MJRefreshStateHeader.h + sourceTree + <group> + + FD0D564503787B9458AB51441306C80F + + fileRef + CC3B13995249C697A763C83DFDECED96 + isa + PBXBuildFile + + FDB3D7BFD24479ACA7B4A8AFEFB5554D + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + text.plist.xml + path + luaviewEx-info.plist + sourceTree + <group> + + FDD0D74CC63C4876FA1BF2D67BBC2764 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVBlock.m + path + IOS/SDK/LuaViewSDK/Classes/LVBlock.m + sourceTree + <group> + + FDE0F21EBD582D712DA29995DB1ED48E + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.objc + name + LVTimer.m + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVTimer.m + sourceTree + <group> + + FE813EC15653881F550BD15245030107 + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + LVCollectionViewCell.h + path + IOS/SDK/LuaViewSDK/Classes/lvsdk/LVCollectionViewCell.h + sourceTree + <group> + + FEFEE2D813FE2DF84A2FC00C56943747 + + fileRef + EF061DEB3722BA928F0CEFC351D6013E + isa + PBXBuildFile + settings + + ATTRIBUTES + + Public + + + + FFA639715D800CB6135B1825AF1F63A5 + + containerPortal + D41D8CD98F00B204E9800998ECF8427E + isa + PBXContainerItemProxy + proxyType + 1 + remoteGlobalIDString + 74FCE8A3277B50697CE9268AEF352C6D + remoteInfo + SDWebImage + + FFC61C0A10406E550F6013C87AFA4DCE + + includeInIndex + 1 + isa + PBXFileReference + lastKnownFileType + sourcecode.c.h + name + lmem.h + path + IOS/lua/lua/lmem.h + sourceTree + <group> + + + rootObject + D41D8CD98F00B204E9800998ECF8427E + + diff --git a/IOS/luaviewEx/Example/Pods/Pods.xcodeproj/xcshareddata/xcschemes/luaviewEx.xcscheme b/IOS/luaviewEx/Example/Pods/Pods.xcodeproj/xcshareddata/xcschemes/luaviewEx.xcscheme new file mode 100644 index 00000000..804e0e8d --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Pods.xcodeproj/xcshareddata/xcschemes/luaviewEx.xcscheme @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/IOS/luaviewEx/Example/Pods/SDWebImage/LICENSE b/IOS/luaviewEx/Example/Pods/SDWebImage/LICENSE new file mode 100644 index 00000000..ae783e17 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/SDWebImage/LICENSE @@ -0,0 +1,20 @@ +Copyright (c) 2009 Olivier Poitrey + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished +to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + diff --git a/IOS/luaviewEx/Example/Pods/SDWebImage/README.md b/IOS/luaviewEx/Example/Pods/SDWebImage/README.md new file mode 100644 index 00000000..62628f99 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/SDWebImage/README.md @@ -0,0 +1,334 @@ +Web Image +========= +[![Build Status](http://img.shields.io/travis/rs/SDWebImage/master.svg?style=flat)](https://travis-ci.org/rs/SDWebImage) +[![Pod Version](http://img.shields.io/cocoapods/v/SDWebImage.svg?style=flat)](http://cocoadocs.org/docsets/SDWebImage/) +[![Pod Platform](http://img.shields.io/cocoapods/p/SDWebImage.svg?style=flat)](http://cocoadocs.org/docsets/SDWebImage/) +[![Pod License](http://img.shields.io/cocoapods/l/SDWebImage.svg?style=flat)](https://www.apache.org/licenses/LICENSE-2.0.html) +[![Dependency Status](https://www.versioneye.com/objective-c/sdwebimage/3.3/badge.svg?style=flat)](https://www.versioneye.com/objective-c/sdwebimage/3.3) +[![Reference Status](https://www.versioneye.com/objective-c/sdwebimage/reference_badge.svg?style=flat)](https://www.versioneye.com/objective-c/sdwebimage/references) +[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/rs/SDWebImage) + +This library provides a category for UIImageView with support for remote images coming from the web. + +It provides: + +- An `UIImageView` category adding web image and cache management to the Cocoa Touch framework +- An asynchronous image downloader +- An asynchronous memory + disk image caching with automatic cache expiration handling +- Animated GIF support +- WebP format support +- A background image decompression +- A guarantee that the same URL won't be downloaded several times +- A guarantee that bogus URLs won't be retried again and again +- A guarantee that main thread will never be blocked +- Performances! +- Use GCD and ARC +- Arm64 support + +NOTE: The version 3.0 of SDWebImage isn't fully backward compatible with 2.0 and requires iOS 5.1.1 +minimum deployment version. If you need iOS < 5.0 support, please use the last [2.0 version](https://github.com/rs/SDWebImage/tree/2.0-compat). + +[How is SDWebImage better than X?](https://github.com/rs/SDWebImage/wiki/How-is-SDWebImage-better-than-X%3F) + +Who Use It +---------- + +Find out [who uses SDWebImage](https://github.com/rs/SDWebImage/wiki/Who-Uses-SDWebImage) and add your app to the list. + +How To Use +---------- + +API documentation is available at [CocoaDocs - SDWebImage](http://cocoadocs.org/docsets/SDWebImage/) + +### Using UIImageView+WebCache category with UITableView + +Just #import the UIImageView+WebCache.h header, and call the sd_setImageWithURL:placeholderImage: +method from the tableView:cellForRowAtIndexPath: UITableViewDataSource method. Everything will be +handled for you, from async downloads to caching management. + +```objective-c +#import + +... + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { + static NSString *MyIdentifier = @"MyIdentifier"; + + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier]; + if (cell == nil) { + cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault + reuseIdentifier:MyIdentifier] autorelease]; + } + + // Here we use the new provided sd_setImageWithURL: method to load the web image + [cell.imageView sd_setImageWithURL:[NSURL URLWithString:@"http://www.domain.com/path/to/image.jpg"] + placeholderImage:[UIImage imageNamed:@"placeholder.png"]]; + + cell.textLabel.text = @"My Text"; + return cell; +} +``` + +### Using blocks + +With blocks, you can be notified about the image download progress and whenever the image retrieval +has completed with success or not: + +```objective-c +// Here we use the new provided sd_setImageWithURL: method to load the web image +[cell.imageView sd_setImageWithURL:[NSURL URLWithString:@"http://www.domain.com/path/to/image.jpg"] + placeholderImage:[UIImage imageNamed:@"placeholder.png"] + completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { + ... completion code here ... + }]; +``` + +Note: neither your success nor failure block will be call if your image request is canceled before completion. + +### Using SDWebImageManager + +The SDWebImageManager is the class behind the UIImageView+WebCache category. It ties the +asynchronous downloader with the image cache store. You can use this class directly to benefit +from web image downloading with caching in another context than a UIView (ie: with Cocoa). + +Here is a simple example of how to use SDWebImageManager: + +```objective-c +SDWebImageManager *manager = [SDWebImageManager sharedManager]; +[manager downloadImageWithURL:imageURL + options:0 + progress:^(NSInteger receivedSize, NSInteger expectedSize) { + // progression tracking code + } + completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { + if (image) { + // do something with image + } + }]; +``` + +### Using Asynchronous Image Downloader Independently + +It's also possible to use the async image downloader independently: + +```objective-c +SDWebImageDownloader *downloader = [SDWebImageDownloader sharedDownloader]; +[downloader downloadImageWithURL:imageURL + options:0 + progress:^(NSInteger receivedSize, NSInteger expectedSize) { + // progression tracking code + } + completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) { + if (image && finished) { + // do something with image + } + }]; +``` + +### Using Asynchronous Image Caching Independently + +It is also possible to use the async based image cache store independently. SDImageCache +maintains a memory cache and an optional disk cache. Disk cache write operations are performed +asynchronous so it doesn't add unnecessary latency to the UI. + +The SDImageCache class provides a singleton instance for convenience but you can create your own +instance if you want to create separated cache namespace. + +To lookup the cache, you use the `queryDiskCacheForKey:done:` method. If the method returns nil, it means the cache +doesn't currently own the image. You are thus responsible for generating and caching it. The cache +key is an application unique identifier for the image to cache. It is generally the absolute URL of +the image. + +```objective-c +SDImageCache *imageCache = [[SDImageCache alloc] initWithNamespace:@"myNamespace"]; +[imageCache queryDiskCacheForKey:myCacheKey done:^(UIImage *image) { + // image is not nil if image was found +}]; +``` + +By default SDImageCache will lookup the disk cache if an image can't be found in the memory cache. +You can prevent this from happening by calling the alternative method `imageFromMemoryCacheForKey:`. + +To store an image into the cache, you use the storeImage:forKey: method: + +```objective-c +[[SDImageCache sharedImageCache] storeImage:myImage forKey:myCacheKey]; +``` + +By default, the image will be stored in memory cache as well as on disk cache (asynchronously). If +you want only the memory cache, use the alternative method storeImage:forKey:toDisk: with a negative +third argument. + +### Using cache key filter + +Sometime, you may not want to use the image URL as cache key because part of the URL is dynamic +(i.e.: for access control purpose). SDWebImageManager provides a way to set a cache key filter that +takes the NSURL as input, and output a cache key NSString. + +The following example sets a filter in the application delegate that will remove any query-string from +the URL before to use it as a cache key: + +```objective-c +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + SDWebImageManager.sharedManager.cacheKeyFilter = ^(NSURL *url) { + url = [[NSURL alloc] initWithScheme:url.scheme host:url.host path:url.path]; + return [url absoluteString]; + }; + + // Your app init code... + return YES; +} +``` + + +Common Problems +--------------- + +### Using dynamic image size with UITableViewCell + +UITableView determines the size of the image by the first image set for a cell. If your remote images +don't have the same size as your placeholder image, you may experience strange anamorphic scaling issue. +The following article gives a way to workaround this issue: + +[http://www.wrichards.com/blog/2011/11/sdwebimage-fixed-width-cell-images/](http://www.wrichards.com/blog/2011/11/sdwebimage-fixed-width-cell-images/) + + +### Handle image refresh + +SDWebImage does very aggressive caching by default. It ignores all kind of caching control header returned by the HTTP server and cache the returned images with no time restriction. It implies your images URLs are static URLs pointing to images that never change. If the pointed image happen to change, some parts of the URL should change accordingly. + +If you don't control the image server you're using, you may not be able to change the URL when its content is updated. This is the case for Facebook avatar URLs for instance. In such case, you may use the `SDWebImageRefreshCached` flag. This will slightly degrade the performance but will respect the HTTP caching control headers: + +``` objective-c +[imageView sd_setImageWithURL:[NSURL URLWithString:@"https://graph.facebook.com/olivier.poitrey/picture"] + placeholderImage:[UIImage imageNamed:@"avatar-placeholder.png"] + options:SDWebImageRefreshCached]; +``` + +### Add a progress indicator + +See this category: https://github.com/JJSaccolo/UIActivityIndicator-for-SDWebImage + +Installation +------------ + +There are three ways to use SDWebImage in your project: +- using Cocoapods +- copying all the files into your project +- importing the project as a static library + +### Installation with CocoaPods + +[CocoaPods](http://cocoapods.org/) is a dependency manager for Objective-C, which automates and simplifies the process of using 3rd-party libraries in your projects. See the [Get Started](http://cocoapods.org/#get_started) section for more details. + +#### Podfile +``` +platform :ios, '6.1' +pod 'SDWebImage', '~>3.7' +``` + +If you are using Swift, be sure to add `use_frameworks!` and set your target to iOS 8+: +``` +platform :ios, '8.0' +use_frameworks! +``` + +#### Subspecs + +There are 3 subspecs available now: `Core`, `MapKit` and `WebP` (this means you can install only some of the SDWebImage modules. By default, you get just `Core`, so if you need `WebP`, you need to specify it). + +Podfile example: +``` +pod 'SDWebImage/WebP' +``` + +### Installation with Carthage (iOS 8+) + +[Carthage](https://github.com/Carthage/Carthage) is a lightweight dependency manager for Swift and Objective-C. It leverages CocoaTouch modules and is less invasive than CocoaPods. + +To install with carthage, follow the instruction on [Carthage](https://github.com/Carthage/Carthage) + +#### Cartfile +``` +github "rs/SDWebImage" +``` + +#### Usage +Swift + +If you installed using CocoaPods: +``` +import SDWebImage +``` + +If you installed manually: +``` +import WebImage +``` + +Objective-C + +``` +@import WebImage; +``` + +### Installation by cloning the repository + +In order to gain access to all the files from the repository, you should clone it. +``` +git clone --recursive https://github.com/rs/SDWebImage.git +``` + +### Add the SDWebImage project to your project + +- Download and unzip the last version of the framework from the [download page](https://github.com/rs/SDWebImage/releases) +- Right-click on the project navigator and select "Add Files to "Your Project": +- In the dialog, select SDWebImage.framework: +- Check the "Copy items into destination group's folder (if needed)" checkbox + +### Add dependencies + +- In you application project app’s target settings, find the "Build Phases" section and open the "Link Binary With Libraries" block: +- Click the "+" button again and select the "ImageIO.framework", this is needed by the progressive download feature: + +### Add Linker Flag + +Open the "Build Settings" tab, in the "Linking" section, locate the "Other Linker Flags" setting and add the "-ObjC" flag: + +![Other Linker Flags](http://dl.dropbox.com/u/123346/SDWebImage/10_other_linker_flags.jpg) + +Alternatively, if this causes compilation problems with frameworks that extend optional libraries, such as Parse, RestKit or opencv2, instead of the -ObjC flag use: +``` +-force_load SDWebImage.framework/Versions/Current/SDWebImage +``` + +If you're using Cocoa Pods and have any frameworks that extend optional libraries, such as Parsen RestKit or opencv2, instead of the -ObjC flag use: +``` +-force_load $(TARGET_BUILD_DIR)/libPods.a +``` +and this: +``` +$(inherited) +``` + +### Import headers in your source files + +In the source files where you need to use the library, import the header file: + +```objective-c +#import +``` + +### Build Project + +At this point your workspace should build without error. If you are having problem, post to the Issue and the +community can help you solve it. + +Future Enhancements +------------------- + +- LRU memory cache cleanup instead of reset on memory warning + +## Licenses + +All source code is licensed under the [MIT License](https://raw.github.com/rs/SDWebImage/master/LICENSE). diff --git a/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/NSData+ImageContentType.h b/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/NSData+ImageContentType.h new file mode 100644 index 00000000..69c76dc7 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/NSData+ImageContentType.h @@ -0,0 +1,26 @@ +// +// Created by Fabrice Aneche on 06/01/14. +// Copyright (c) 2014 Dailymotion. All rights reserved. +// + +#import + +@interface NSData (ImageContentType) + +/** + * Compute the content type for an image data + * + * @param data the input data + * + * @return the content type as string (i.e. image/jpeg, image/gif) + */ ++ (NSString *)sd_contentTypeForImageData:(NSData *)data; + +@end + + +@interface NSData (ImageContentTypeDeprecated) + ++ (NSString *)contentTypeForImageData:(NSData *)data __deprecated_msg("Use `sd_contentTypeForImageData:`"); + +@end diff --git a/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/NSData+ImageContentType.m b/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/NSData+ImageContentType.m new file mode 100644 index 00000000..0941cfaa --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/NSData+ImageContentType.m @@ -0,0 +1,49 @@ +// +// Created by Fabrice Aneche on 06/01/14. +// Copyright (c) 2014 Dailymotion. All rights reserved. +// + +#import "NSData+ImageContentType.h" + + +@implementation NSData (ImageContentType) + ++ (NSString *)sd_contentTypeForImageData:(NSData *)data { + uint8_t c; + [data getBytes:&c length:1]; + switch (c) { + case 0xFF: + return @"image/jpeg"; + case 0x89: + return @"image/png"; + case 0x47: + return @"image/gif"; + case 0x49: + case 0x4D: + return @"image/tiff"; + case 0x52: + // R as RIFF for WEBP + if ([data length] < 12) { + return nil; + } + + NSString *testString = [[NSString alloc] initWithData:[data subdataWithRange:NSMakeRange(0, 12)] encoding:NSASCIIStringEncoding]; + if ([testString hasPrefix:@"RIFF"] && [testString hasSuffix:@"WEBP"]) { + return @"image/webp"; + } + + return nil; + } + return nil; +} + +@end + + +@implementation NSData (ImageContentTypeDeprecated) + ++ (NSString *)contentTypeForImageData:(NSData *)data { + return [self sd_contentTypeForImageData:data]; +} + +@end diff --git a/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/SDImageCache.h b/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/SDImageCache.h new file mode 100644 index 00000000..95777267 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/SDImageCache.h @@ -0,0 +1,272 @@ +/* + * This file is part of the SDWebImage package. + * (c) Olivier Poitrey + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +#import +#import "SDWebImageCompat.h" + +typedef NS_ENUM(NSInteger, SDImageCacheType) { + /** + * The image wasn't available the SDWebImage caches, but was downloaded from the web. + */ + SDImageCacheTypeNone, + /** + * The image was obtained from the disk cache. + */ + SDImageCacheTypeDisk, + /** + * The image was obtained from the memory cache. + */ + SDImageCacheTypeMemory +}; + +typedef void(^SDWebImageQueryCompletedBlock)(UIImage *image, SDImageCacheType cacheType); + +typedef void(^SDWebImageCheckCacheCompletionBlock)(BOOL isInCache); + +typedef void(^SDWebImageCalculateSizeBlock)(NSUInteger fileCount, NSUInteger totalSize); + +/** + * SDImageCache maintains a memory cache and an optional disk cache. Disk cache write operations are performed + * asynchronous so it doesn’t add unnecessary latency to the UI. + */ +@interface SDImageCache : NSObject + +/** + * Decompressing images that are downloaded and cached can improve performance but can consume lot of memory. + * Defaults to YES. Set this to NO if you are experiencing a crash due to excessive memory consumption. + */ +@property (assign, nonatomic) BOOL shouldDecompressImages; + +/** + * disable iCloud backup [defaults to YES] + */ +@property (assign, nonatomic) BOOL shouldDisableiCloud; + +/** + * use memory cache [defaults to YES] + */ +@property (assign, nonatomic) BOOL shouldCacheImagesInMemory; + +/** + * The maximum "total cost" of the in-memory image cache. The cost function is the number of pixels held in memory. + */ +@property (assign, nonatomic) NSUInteger maxMemoryCost; + +/** + * The maximum number of objects the cache should hold. + */ +@property (assign, nonatomic) NSUInteger maxMemoryCountLimit; + +/** + * The maximum length of time to keep an image in the cache, in seconds + */ +@property (assign, nonatomic) NSInteger maxCacheAge; + +/** + * The maximum size of the cache, in bytes. + */ +@property (assign, nonatomic) NSUInteger maxCacheSize; + +/** + * Returns global shared cache instance + * + * @return SDImageCache global instance + */ ++ (SDImageCache *)sharedImageCache; + +/** + * Init a new cache store with a specific namespace + * + * @param ns The namespace to use for this cache store + */ +- (id)initWithNamespace:(NSString *)ns; + +/** + * Init a new cache store with a specific namespace and directory + * + * @param ns The namespace to use for this cache store + * @param directory Directory to cache disk images in + */ +- (id)initWithNamespace:(NSString *)ns diskCacheDirectory:(NSString *)directory; + +-(NSString *)makeDiskCachePath:(NSString*)fullNamespace; + +/** + * Add a read-only cache path to search for images pre-cached by SDImageCache + * Useful if you want to bundle pre-loaded images with your app + * + * @param path The path to use for this read-only cache path + */ +- (void)addReadOnlyCachePath:(NSString *)path; + +/** + * Store an image into memory and disk cache at the given key. + * + * @param image The image to store + * @param key The unique image cache key, usually it's image absolute URL + */ +- (void)storeImage:(UIImage *)image forKey:(NSString *)key; + +/** + * Store an image into memory and optionally disk cache at the given key. + * + * @param image The image to store + * @param key The unique image cache key, usually it's image absolute URL + * @param toDisk Store the image to disk cache if YES + */ +- (void)storeImage:(UIImage *)image forKey:(NSString *)key toDisk:(BOOL)toDisk; + +/** + * Store an image into memory and optionally disk cache at the given key. + * + * @param image The image to store + * @param recalculate BOOL indicates if imageData can be used or a new data should be constructed from the UIImage + * @param imageData The image data as returned by the server, this representation will be used for disk storage + * instead of converting the given image object into a storable/compressed image format in order + * to save quality and CPU + * @param key The unique image cache key, usually it's image absolute URL + * @param toDisk Store the image to disk cache if YES + */ +- (void)storeImage:(UIImage *)image recalculateFromImage:(BOOL)recalculate imageData:(NSData *)imageData forKey:(NSString *)key toDisk:(BOOL)toDisk; + +/** + * Query the disk cache asynchronously. + * + * @param key The unique key used to store the wanted image + */ +- (NSOperation *)queryDiskCacheForKey:(NSString *)key done:(SDWebImageQueryCompletedBlock)doneBlock; + +/** + * Query the memory cache synchronously. + * + * @param key The unique key used to store the wanted image + */ +- (UIImage *)imageFromMemoryCacheForKey:(NSString *)key; + +/** + * Query the disk cache synchronously after checking the memory cache. + * + * @param key The unique key used to store the wanted image + */ +- (UIImage *)imageFromDiskCacheForKey:(NSString *)key; + +/** + * Remove the image from memory and disk cache synchronously + * + * @param key The unique image cache key + */ +- (void)removeImageForKey:(NSString *)key; + + +/** + * Remove the image from memory and disk cache asynchronously + * + * @param key The unique image cache key + * @param completion An block that should be executed after the image has been removed (optional) + */ +- (void)removeImageForKey:(NSString *)key withCompletion:(SDWebImageNoParamsBlock)completion; + +/** + * Remove the image from memory and optionally disk cache asynchronously + * + * @param key The unique image cache key + * @param fromDisk Also remove cache entry from disk if YES + */ +- (void)removeImageForKey:(NSString *)key fromDisk:(BOOL)fromDisk; + +/** + * Remove the image from memory and optionally disk cache asynchronously + * + * @param key The unique image cache key + * @param fromDisk Also remove cache entry from disk if YES + * @param completion An block that should be executed after the image has been removed (optional) + */ +- (void)removeImageForKey:(NSString *)key fromDisk:(BOOL)fromDisk withCompletion:(SDWebImageNoParamsBlock)completion; + +/** + * Clear all memory cached images + */ +- (void)clearMemory; + +/** + * Clear all disk cached images. Non-blocking method - returns immediately. + * @param completion An block that should be executed after cache expiration completes (optional) + */ +- (void)clearDiskOnCompletion:(SDWebImageNoParamsBlock)completion; + +/** + * Clear all disk cached images + * @see clearDiskOnCompletion: + */ +- (void)clearDisk; + +/** + * Remove all expired cached image from disk. Non-blocking method - returns immediately. + * @param completionBlock An block that should be executed after cache expiration completes (optional) + */ +- (void)cleanDiskWithCompletionBlock:(SDWebImageNoParamsBlock)completionBlock; + +/** + * Remove all expired cached image from disk + * @see cleanDiskWithCompletionBlock: + */ +- (void)cleanDisk; + +/** + * Get the size used by the disk cache + */ +- (NSUInteger)getSize; + +/** + * Get the number of images in the disk cache + */ +- (NSUInteger)getDiskCount; + +/** + * Asynchronously calculate the disk cache's size. + */ +- (void)calculateSizeWithCompletionBlock:(SDWebImageCalculateSizeBlock)completionBlock; + +/** + * Async check if image exists in disk cache already (does not load the image) + * + * @param key the key describing the url + * @param completionBlock the block to be executed when the check is done. + * @note the completion block will be always executed on the main queue + */ +- (void)diskImageExistsWithKey:(NSString *)key completion:(SDWebImageCheckCacheCompletionBlock)completionBlock; + +/** + * Check if image exists in disk cache already (does not load the image) + * + * @param key the key describing the url + * + * @return YES if an image exists for the given key + */ +- (BOOL)diskImageExistsWithKey:(NSString *)key; + +/** + * Get the cache path for a certain key (needs the cache path root folder) + * + * @param key the key (can be obtained from url using cacheKeyForURL) + * @param path the cache path root folder + * + * @return the cache path + */ +- (NSString *)cachePathForKey:(NSString *)key inPath:(NSString *)path; + +/** + * Get the default cache path for a certain key + * + * @param key the key (can be obtained from url using cacheKeyForURL) + * + * @return the default cache path + */ +- (NSString *)defaultCachePathForKey:(NSString *)key; + +@end diff --git a/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/SDImageCache.m b/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/SDImageCache.m new file mode 100644 index 00000000..aa0ff6c9 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/SDImageCache.m @@ -0,0 +1,650 @@ +/* + * This file is part of the SDWebImage package. + * (c) Olivier Poitrey + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +#import "SDImageCache.h" +#import "SDWebImageDecoder.h" +#import "UIImage+MultiFormat.h" +#import + +// See https://github.com/rs/SDWebImage/pull/1141 for discussion +@interface AutoPurgeCache : NSCache +@end + +@implementation AutoPurgeCache + +- (id)init +{ + self = [super init]; + if (self) { + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(removeAllObjects) name:UIApplicationDidReceiveMemoryWarningNotification object:nil]; + } + return self; +} + +- (void)dealloc +{ + [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidReceiveMemoryWarningNotification object:nil]; + +} + +@end + +static const NSInteger kDefaultCacheMaxCacheAge = 60 * 60 * 24 * 7; // 1 week +// PNG signature bytes and data (below) +static unsigned char kPNGSignatureBytes[8] = {0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A}; +static NSData *kPNGSignatureData = nil; + +BOOL ImageDataHasPNGPreffix(NSData *data); + +BOOL ImageDataHasPNGPreffix(NSData *data) { + NSUInteger pngSignatureLength = [kPNGSignatureData length]; + if ([data length] >= pngSignatureLength) { + if ([[data subdataWithRange:NSMakeRange(0, pngSignatureLength)] isEqualToData:kPNGSignatureData]) { + return YES; + } + } + + return NO; +} + +FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { + return image.size.height * image.size.width * image.scale * image.scale; +} + +@interface SDImageCache () + +@property (strong, nonatomic) NSCache *memCache; +@property (strong, nonatomic) NSString *diskCachePath; +@property (strong, nonatomic) NSMutableArray *customPaths; +@property (SDDispatchQueueSetterSementics, nonatomic) dispatch_queue_t ioQueue; + +@end + + +@implementation SDImageCache { + NSFileManager *_fileManager; +} + ++ (SDImageCache *)sharedImageCache { + static dispatch_once_t once; + static id instance; + dispatch_once(&once, ^{ + instance = [self new]; + }); + return instance; +} + +- (id)init { + return [self initWithNamespace:@"default"]; +} + +- (id)initWithNamespace:(NSString *)ns { + NSString *path = [self makeDiskCachePath:ns]; + return [self initWithNamespace:ns diskCacheDirectory:path]; +} + +- (id)initWithNamespace:(NSString *)ns diskCacheDirectory:(NSString *)directory { + if ((self = [super init])) { + NSString *fullNamespace = [@"com.hackemist.SDWebImageCache." stringByAppendingString:ns]; + + // initialise PNG signature data + kPNGSignatureData = [NSData dataWithBytes:kPNGSignatureBytes length:8]; + + // Create IO serial queue + _ioQueue = dispatch_queue_create("com.hackemist.SDWebImageCache", DISPATCH_QUEUE_SERIAL); + + // Init default values + _maxCacheAge = kDefaultCacheMaxCacheAge; + + // Init the memory cache + _memCache = [[AutoPurgeCache alloc] init]; + _memCache.name = fullNamespace; + + // Init the disk cache + if (directory != nil) { + _diskCachePath = [directory stringByAppendingPathComponent:fullNamespace]; + } else { + NSString *path = [self makeDiskCachePath:ns]; + _diskCachePath = path; + } + + // Set decompression to YES + _shouldDecompressImages = YES; + + // memory cache enabled + _shouldCacheImagesInMemory = YES; + + // Disable iCloud + _shouldDisableiCloud = YES; + + dispatch_sync(_ioQueue, ^{ + _fileManager = [NSFileManager new]; + }); + +#if TARGET_OS_IPHONE + // Subscribe to app events + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(clearMemory) + name:UIApplicationDidReceiveMemoryWarningNotification + object:nil]; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(cleanDisk) + name:UIApplicationWillTerminateNotification + object:nil]; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(backgroundCleanDisk) + name:UIApplicationDidEnterBackgroundNotification + object:nil]; +#endif + } + + return self; +} + +- (void)dealloc { + [[NSNotificationCenter defaultCenter] removeObserver:self]; + SDDispatchQueueRelease(_ioQueue); +} + +- (void)addReadOnlyCachePath:(NSString *)path { + if (!self.customPaths) { + self.customPaths = [NSMutableArray new]; + } + + if (![self.customPaths containsObject:path]) { + [self.customPaths addObject:path]; + } +} + +- (NSString *)cachePathForKey:(NSString *)key inPath:(NSString *)path { + NSString *filename = [self cachedFileNameForKey:key]; + return [path stringByAppendingPathComponent:filename]; +} + +- (NSString *)defaultCachePathForKey:(NSString *)key { + return [self cachePathForKey:key inPath:self.diskCachePath]; +} + +#pragma mark SDImageCache (private) + +- (NSString *)cachedFileNameForKey:(NSString *)key { + const char *str = [key UTF8String]; + if (str == NULL) { + str = ""; + } + unsigned char r[CC_MD5_DIGEST_LENGTH]; + CC_MD5(str, (CC_LONG)strlen(str), r); + NSString *filename = [NSString stringWithFormat:@"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%@", + r[0], r[1], r[2], r[3], r[4], r[5], r[6], r[7], r[8], r[9], r[10], + r[11], r[12], r[13], r[14], r[15], [[key pathExtension] isEqualToString:@""] ? @"" : [NSString stringWithFormat:@".%@", [key pathExtension]]]; + + return filename; +} + +#pragma mark ImageCache + +// Init the disk cache +-(NSString *)makeDiskCachePath:(NSString*)fullNamespace{ + NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); + return [paths[0] stringByAppendingPathComponent:fullNamespace]; +} + +- (void)storeImage:(UIImage *)image recalculateFromImage:(BOOL)recalculate imageData:(NSData *)imageData forKey:(NSString *)key toDisk:(BOOL)toDisk { + if (!image || !key) { + return; + } + // if memory cache is enabled + if (self.shouldCacheImagesInMemory) { + NSUInteger cost = SDCacheCostForImage(image); + [self.memCache setObject:image forKey:key cost:cost]; + } + + if (toDisk) { + dispatch_async(self.ioQueue, ^{ + NSData *data = imageData; + + if (image && (recalculate || !data)) { +#if TARGET_OS_IPHONE + // We need to determine if the image is a PNG or a JPEG + // PNGs are easier to detect because they have a unique signature (http://www.w3.org/TR/PNG-Structure.html) + // The first eight bytes of a PNG file always contain the following (decimal) values: + // 137 80 78 71 13 10 26 10 + + // If the imageData is nil (i.e. if trying to save a UIImage directly or the image was transformed on download) + // and the image has an alpha channel, we will consider it PNG to avoid losing the transparency + int alphaInfo = CGImageGetAlphaInfo(image.CGImage); + BOOL hasAlpha = !(alphaInfo == kCGImageAlphaNone || + alphaInfo == kCGImageAlphaNoneSkipFirst || + alphaInfo == kCGImageAlphaNoneSkipLast); + BOOL imageIsPng = hasAlpha; + + // But if we have an image data, we will look at the preffix + if ([imageData length] >= [kPNGSignatureData length]) { + imageIsPng = ImageDataHasPNGPreffix(imageData); + } + + if (imageIsPng) { + data = UIImagePNGRepresentation(image); + } + else { + data = UIImageJPEGRepresentation(image, (CGFloat)1.0); + } +#else + data = [NSBitmapImageRep representationOfImageRepsInArray:image.representations usingType: NSJPEGFileType properties:nil]; +#endif + } + + if (data) { + if (![_fileManager fileExistsAtPath:_diskCachePath]) { + [_fileManager createDirectoryAtPath:_diskCachePath withIntermediateDirectories:YES attributes:nil error:NULL]; + } + + // get cache Path for image key + NSString *cachePathForKey = [self defaultCachePathForKey:key]; + // transform to NSUrl + NSURL *fileURL = [NSURL fileURLWithPath:cachePathForKey]; + + [_fileManager createFileAtPath:cachePathForKey contents:data attributes:nil]; + + // disable iCloud backup + if (self.shouldDisableiCloud) { + [fileURL setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:nil]; + } + } + }); + } +} + +- (void)storeImage:(UIImage *)image forKey:(NSString *)key { + [self storeImage:image recalculateFromImage:YES imageData:nil forKey:key toDisk:YES]; +} + +- (void)storeImage:(UIImage *)image forKey:(NSString *)key toDisk:(BOOL)toDisk { + [self storeImage:image recalculateFromImage:YES imageData:nil forKey:key toDisk:toDisk]; +} + +- (BOOL)diskImageExistsWithKey:(NSString *)key { + BOOL exists = NO; + + // this is an exception to access the filemanager on another queue than ioQueue, but we are using the shared instance + // from apple docs on NSFileManager: The methods of the shared NSFileManager object can be called from multiple threads safely. + exists = [[NSFileManager defaultManager] fileExistsAtPath:[self defaultCachePathForKey:key]]; + + // fallback because of https://github.com/rs/SDWebImage/pull/976 that added the extension to the disk file name + // checking the key with and without the extension + if (!exists) { + exists = [[NSFileManager defaultManager] fileExistsAtPath:[[self defaultCachePathForKey:key] stringByDeletingPathExtension]]; + } + + return exists; +} + +- (void)diskImageExistsWithKey:(NSString *)key completion:(SDWebImageCheckCacheCompletionBlock)completionBlock { + dispatch_async(_ioQueue, ^{ + BOOL exists = [_fileManager fileExistsAtPath:[self defaultCachePathForKey:key]]; + + // fallback because of https://github.com/rs/SDWebImage/pull/976 that added the extension to the disk file name + // checking the key with and without the extension + if (!exists) { + exists = [_fileManager fileExistsAtPath:[[self defaultCachePathForKey:key] stringByDeletingPathExtension]]; + } + + if (completionBlock) { + dispatch_async(dispatch_get_main_queue(), ^{ + completionBlock(exists); + }); + } + }); +} + +- (UIImage *)imageFromMemoryCacheForKey:(NSString *)key { + return [self.memCache objectForKey:key]; +} + +- (UIImage *)imageFromDiskCacheForKey:(NSString *)key { + + // First check the in-memory cache... + UIImage *image = [self imageFromMemoryCacheForKey:key]; + if (image) { + return image; + } + + // Second check the disk cache... + UIImage *diskImage = [self diskImageForKey:key]; + if (diskImage && self.shouldCacheImagesInMemory) { + NSUInteger cost = SDCacheCostForImage(diskImage); + [self.memCache setObject:diskImage forKey:key cost:cost]; + } + + return diskImage; +} + +- (NSData *)diskImageDataBySearchingAllPathsForKey:(NSString *)key { + NSString *defaultPath = [self defaultCachePathForKey:key]; + NSData *data = [NSData dataWithContentsOfFile:defaultPath]; + if (data) { + return data; + } + + // fallback because of https://github.com/rs/SDWebImage/pull/976 that added the extension to the disk file name + // checking the key with and without the extension + data = [NSData dataWithContentsOfFile:[defaultPath stringByDeletingPathExtension]]; + if (data) { + return data; + } + + NSArray *customPaths = [self.customPaths copy]; + for (NSString *path in customPaths) { + NSString *filePath = [self cachePathForKey:key inPath:path]; + NSData *imageData = [NSData dataWithContentsOfFile:filePath]; + if (imageData) { + return imageData; + } + + // fallback because of https://github.com/rs/SDWebImage/pull/976 that added the extension to the disk file name + // checking the key with and without the extension + imageData = [NSData dataWithContentsOfFile:[filePath stringByDeletingPathExtension]]; + if (imageData) { + return imageData; + } + } + + return nil; +} + +- (UIImage *)diskImageForKey:(NSString *)key { + NSData *data = [self diskImageDataBySearchingAllPathsForKey:key]; + if (data) { + UIImage *image = [UIImage sd_imageWithData:data]; + image = [self scaledImageForKey:key image:image]; + if (self.shouldDecompressImages) { + image = [UIImage decodedImageWithImage:image]; + } + return image; + } + else { + return nil; + } +} + +- (UIImage *)scaledImageForKey:(NSString *)key image:(UIImage *)image { + return SDScaledImageForKey(key, image); +} + +- (NSOperation *)queryDiskCacheForKey:(NSString *)key done:(SDWebImageQueryCompletedBlock)doneBlock { + if (!doneBlock) { + return nil; + } + + if (!key) { + doneBlock(nil, SDImageCacheTypeNone); + return nil; + } + + // First check the in-memory cache... + UIImage *image = [self imageFromMemoryCacheForKey:key]; + if (image) { + doneBlock(image, SDImageCacheTypeMemory); + return nil; + } + + NSOperation *operation = [NSOperation new]; + dispatch_async(self.ioQueue, ^{ + if (operation.isCancelled) { + return; + } + + @autoreleasepool { + UIImage *diskImage = [self diskImageForKey:key]; + if (diskImage && self.shouldCacheImagesInMemory) { + NSUInteger cost = SDCacheCostForImage(diskImage); + [self.memCache setObject:diskImage forKey:key cost:cost]; + } + + dispatch_async(dispatch_get_main_queue(), ^{ + doneBlock(diskImage, SDImageCacheTypeDisk); + }); + } + }); + + return operation; +} + +- (void)removeImageForKey:(NSString *)key { + [self removeImageForKey:key withCompletion:nil]; +} + +- (void)removeImageForKey:(NSString *)key withCompletion:(SDWebImageNoParamsBlock)completion { + [self removeImageForKey:key fromDisk:YES withCompletion:completion]; +} + +- (void)removeImageForKey:(NSString *)key fromDisk:(BOOL)fromDisk { + [self removeImageForKey:key fromDisk:fromDisk withCompletion:nil]; +} + +- (void)removeImageForKey:(NSString *)key fromDisk:(BOOL)fromDisk withCompletion:(SDWebImageNoParamsBlock)completion { + + if (key == nil) { + return; + } + + if (self.shouldCacheImagesInMemory) { + [self.memCache removeObjectForKey:key]; + } + + if (fromDisk) { + dispatch_async(self.ioQueue, ^{ + [_fileManager removeItemAtPath:[self defaultCachePathForKey:key] error:nil]; + + if (completion) { + dispatch_async(dispatch_get_main_queue(), ^{ + completion(); + }); + } + }); + } else if (completion){ + completion(); + } + +} + +- (void)setMaxMemoryCost:(NSUInteger)maxMemoryCost { + self.memCache.totalCostLimit = maxMemoryCost; +} + +- (NSUInteger)maxMemoryCost { + return self.memCache.totalCostLimit; +} + +- (NSUInteger)maxMemoryCountLimit { + return self.memCache.countLimit; +} + +- (void)setMaxMemoryCountLimit:(NSUInteger)maxCountLimit { + self.memCache.countLimit = maxCountLimit; +} + +- (void)clearMemory { + [self.memCache removeAllObjects]; +} + +- (void)clearDisk { + [self clearDiskOnCompletion:nil]; +} + +- (void)clearDiskOnCompletion:(SDWebImageNoParamsBlock)completion +{ + dispatch_async(self.ioQueue, ^{ + [_fileManager removeItemAtPath:self.diskCachePath error:nil]; + [_fileManager createDirectoryAtPath:self.diskCachePath + withIntermediateDirectories:YES + attributes:nil + error:NULL]; + + if (completion) { + dispatch_async(dispatch_get_main_queue(), ^{ + completion(); + }); + } + }); +} + +- (void)cleanDisk { + [self cleanDiskWithCompletionBlock:nil]; +} + +- (void)cleanDiskWithCompletionBlock:(SDWebImageNoParamsBlock)completionBlock { + dispatch_async(self.ioQueue, ^{ + NSURL *diskCacheURL = [NSURL fileURLWithPath:self.diskCachePath isDirectory:YES]; + NSArray *resourceKeys = @[NSURLIsDirectoryKey, NSURLContentModificationDateKey, NSURLTotalFileAllocatedSizeKey]; + + // This enumerator prefetches useful properties for our cache files. + NSDirectoryEnumerator *fileEnumerator = [_fileManager enumeratorAtURL:diskCacheURL + includingPropertiesForKeys:resourceKeys + options:NSDirectoryEnumerationSkipsHiddenFiles + errorHandler:NULL]; + + NSDate *expirationDate = [NSDate dateWithTimeIntervalSinceNow:-self.maxCacheAge]; + NSMutableDictionary *cacheFiles = [NSMutableDictionary dictionary]; + NSUInteger currentCacheSize = 0; + + // Enumerate all of the files in the cache directory. This loop has two purposes: + // + // 1. Removing files that are older than the expiration date. + // 2. Storing file attributes for the size-based cleanup pass. + NSMutableArray *urlsToDelete = [[NSMutableArray alloc] init]; + for (NSURL *fileURL in fileEnumerator) { + NSDictionary *resourceValues = [fileURL resourceValuesForKeys:resourceKeys error:NULL]; + + // Skip directories. + if ([resourceValues[NSURLIsDirectoryKey] boolValue]) { + continue; + } + + // Remove files that are older than the expiration date; + NSDate *modificationDate = resourceValues[NSURLContentModificationDateKey]; + if ([[modificationDate laterDate:expirationDate] isEqualToDate:expirationDate]) { + [urlsToDelete addObject:fileURL]; + continue; + } + + // Store a reference to this file and account for its total size. + NSNumber *totalAllocatedSize = resourceValues[NSURLTotalFileAllocatedSizeKey]; + currentCacheSize += [totalAllocatedSize unsignedIntegerValue]; + [cacheFiles setObject:resourceValues forKey:fileURL]; + } + + for (NSURL *fileURL in urlsToDelete) { + [_fileManager removeItemAtURL:fileURL error:nil]; + } + + // If our remaining disk cache exceeds a configured maximum size, perform a second + // size-based cleanup pass. We delete the oldest files first. + if (self.maxCacheSize > 0 && currentCacheSize > self.maxCacheSize) { + // Target half of our maximum cache size for this cleanup pass. + const NSUInteger desiredCacheSize = self.maxCacheSize / 2; + + // Sort the remaining cache files by their last modification time (oldest first). + NSArray *sortedFiles = [cacheFiles keysSortedByValueWithOptions:NSSortConcurrent + usingComparator:^NSComparisonResult(id obj1, id obj2) { + return [obj1[NSURLContentModificationDateKey] compare:obj2[NSURLContentModificationDateKey]]; + }]; + + // Delete files until we fall below our desired cache size. + for (NSURL *fileURL in sortedFiles) { + if ([_fileManager removeItemAtURL:fileURL error:nil]) { + NSDictionary *resourceValues = cacheFiles[fileURL]; + NSNumber *totalAllocatedSize = resourceValues[NSURLTotalFileAllocatedSizeKey]; + currentCacheSize -= [totalAllocatedSize unsignedIntegerValue]; + + if (currentCacheSize < desiredCacheSize) { + break; + } + } + } + } + if (completionBlock) { + dispatch_async(dispatch_get_main_queue(), ^{ + completionBlock(); + }); + } + }); +} + +- (void)backgroundCleanDisk { + Class UIApplicationClass = NSClassFromString(@"UIApplication"); + if(!UIApplicationClass || ![UIApplicationClass respondsToSelector:@selector(sharedApplication)]) { + return; + } + UIApplication *application = [UIApplication performSelector:@selector(sharedApplication)]; + __block UIBackgroundTaskIdentifier bgTask = [application beginBackgroundTaskWithExpirationHandler:^{ + // Clean up any unfinished task business by marking where you + // stopped or ending the task outright. + [application endBackgroundTask:bgTask]; + bgTask = UIBackgroundTaskInvalid; + }]; + + // Start the long-running task and return immediately. + [self cleanDiskWithCompletionBlock:^{ + [application endBackgroundTask:bgTask]; + bgTask = UIBackgroundTaskInvalid; + }]; +} + +- (NSUInteger)getSize { + __block NSUInteger size = 0; + dispatch_sync(self.ioQueue, ^{ + NSDirectoryEnumerator *fileEnumerator = [_fileManager enumeratorAtPath:self.diskCachePath]; + for (NSString *fileName in fileEnumerator) { + NSString *filePath = [self.diskCachePath stringByAppendingPathComponent:fileName]; + NSDictionary *attrs = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:nil]; + size += [attrs fileSize]; + } + }); + return size; +} + +- (NSUInteger)getDiskCount { + __block NSUInteger count = 0; + dispatch_sync(self.ioQueue, ^{ + NSDirectoryEnumerator *fileEnumerator = [_fileManager enumeratorAtPath:self.diskCachePath]; + count = [[fileEnumerator allObjects] count]; + }); + return count; +} + +- (void)calculateSizeWithCompletionBlock:(SDWebImageCalculateSizeBlock)completionBlock { + NSURL *diskCacheURL = [NSURL fileURLWithPath:self.diskCachePath isDirectory:YES]; + + dispatch_async(self.ioQueue, ^{ + NSUInteger fileCount = 0; + NSUInteger totalSize = 0; + + NSDirectoryEnumerator *fileEnumerator = [_fileManager enumeratorAtURL:diskCacheURL + includingPropertiesForKeys:@[NSFileSize] + options:NSDirectoryEnumerationSkipsHiddenFiles + errorHandler:NULL]; + + for (NSURL *fileURL in fileEnumerator) { + NSNumber *fileSize; + [fileURL getResourceValue:&fileSize forKey:NSURLFileSizeKey error:NULL]; + totalSize += [fileSize unsignedIntegerValue]; + fileCount += 1; + } + + if (completionBlock) { + dispatch_async(dispatch_get_main_queue(), ^{ + completionBlock(fileCount, totalSize); + }); + } + }); +} + +@end diff --git a/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/SDWebImageCompat.h b/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/SDWebImageCompat.h new file mode 100644 index 00000000..3c21b413 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/SDWebImageCompat.h @@ -0,0 +1,72 @@ +/* + * This file is part of the SDWebImage package. + * (c) Olivier Poitrey + * (c) Jamie Pinkham + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +#import + +#ifdef __OBJC_GC__ +#error SDWebImage does not support Objective-C Garbage Collection +#endif + +#if __IPHONE_OS_VERSION_MIN_REQUIRED != 20000 && __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_5_0 +#error SDWebImage doesn't support Deployment Target version < 5.0 +#endif + +#if !TARGET_OS_IPHONE +#import +#ifndef UIImage +#define UIImage NSImage +#endif +#ifndef UIImageView +#define UIImageView NSImageView +#endif +#else + +#import + +#endif + +#ifndef NS_ENUM +#define NS_ENUM(_type, _name) enum _name : _type _name; enum _name : _type +#endif + +#ifndef NS_OPTIONS +#define NS_OPTIONS(_type, _name) enum _name : _type _name; enum _name : _type +#endif + +#if OS_OBJECT_USE_OBJC + #undef SDDispatchQueueRelease + #undef SDDispatchQueueSetterSementics + #define SDDispatchQueueRelease(q) + #define SDDispatchQueueSetterSementics strong +#else +#undef SDDispatchQueueRelease +#undef SDDispatchQueueSetterSementics +#define SDDispatchQueueRelease(q) (dispatch_release(q)) +#define SDDispatchQueueSetterSementics assign +#endif + +extern UIImage *SDScaledImageForKey(NSString *key, UIImage *image); + +typedef void(^SDWebImageNoParamsBlock)(); + +extern NSString *const SDWebImageErrorDomain; + +#define dispatch_main_sync_safe(block)\ + if ([NSThread isMainThread]) {\ + block();\ + } else {\ + dispatch_sync(dispatch_get_main_queue(), block);\ + } + +#define dispatch_main_async_safe(block)\ + if ([NSThread isMainThread]) {\ + block();\ + } else {\ + dispatch_async(dispatch_get_main_queue(), block);\ + } diff --git a/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/SDWebImageCompat.m b/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/SDWebImageCompat.m new file mode 100644 index 00000000..9a011bc0 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/SDWebImageCompat.m @@ -0,0 +1,51 @@ +// +// SDWebImageCompat.m +// SDWebImage +// +// Created by Olivier Poitrey on 11/12/12. +// Copyright (c) 2012 Dailymotion. All rights reserved. +// + +#import "SDWebImageCompat.h" + +#if !__has_feature(objc_arc) +#error SDWebImage is ARC only. Either turn on ARC for the project or use -fobjc-arc flag +#endif + +inline UIImage *SDScaledImageForKey(NSString *key, UIImage *image) { + if (!image) { + return nil; + } + + if ([image.images count] > 0) { + NSMutableArray *scaledImages = [NSMutableArray array]; + + for (UIImage *tempImage in image.images) { + [scaledImages addObject:SDScaledImageForKey(key, tempImage)]; + } + + return [UIImage animatedImageWithImages:scaledImages duration:image.duration]; + } + else { + if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) { + CGFloat scale = [UIScreen mainScreen].scale; + if (key.length >= 8) { + NSRange range = [key rangeOfString:@"@2x."]; + if (range.location != NSNotFound) { + scale = 2.0; + } + + range = [key rangeOfString:@"@3x."]; + if (range.location != NSNotFound) { + scale = 3.0; + } + } + + UIImage *scaledImage = [[UIImage alloc] initWithCGImage:image.CGImage scale:scale orientation:image.imageOrientation]; + image = scaledImage; + } + return image; + } +} + +NSString *const SDWebImageErrorDomain = @"SDWebImageErrorDomain"; diff --git a/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/SDWebImageDecoder.h b/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/SDWebImageDecoder.h new file mode 100644 index 00000000..0176a7ba --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/SDWebImageDecoder.h @@ -0,0 +1,18 @@ +/* + * This file is part of the SDWebImage package. + * (c) Olivier Poitrey + * + * Created by james on 9/28/11. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +#import +#import "SDWebImageCompat.h" + +@interface UIImage (ForceDecode) + ++ (UIImage *)decodedImageWithImage:(UIImage *)image; + +@end diff --git a/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/SDWebImageDecoder.m b/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/SDWebImageDecoder.m new file mode 100644 index 00000000..a7c02468 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/SDWebImageDecoder.m @@ -0,0 +1,69 @@ +/* + * This file is part of the SDWebImage package. + * (c) Olivier Poitrey + * + * Created by james on 9/28/11. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +#import "SDWebImageDecoder.h" + +@implementation UIImage (ForceDecode) + ++ (UIImage *)decodedImageWithImage:(UIImage *)image { + // while downloading huge amount of images + // autorelease the bitmap context + // and all vars to help system to free memory + // when there are memory warning. + // on iOS7, do not forget to call + // [[SDImageCache sharedImageCache] clearMemory]; + @autoreleasepool{ + // do not decode animated images + if (image.images) { return image; } + + CGImageRef imageRef = image.CGImage; + + CGImageAlphaInfo alpha = CGImageGetAlphaInfo(imageRef); + BOOL anyAlpha = (alpha == kCGImageAlphaFirst || + alpha == kCGImageAlphaLast || + alpha == kCGImageAlphaPremultipliedFirst || + alpha == kCGImageAlphaPremultipliedLast); + + if (anyAlpha) { return image; } + + size_t width = CGImageGetWidth(imageRef); + size_t height = CGImageGetHeight(imageRef); + + // current + CGColorSpaceModel imageColorSpaceModel = CGColorSpaceGetModel(CGImageGetColorSpace(imageRef)); + CGColorSpaceRef colorspaceRef = CGImageGetColorSpace(imageRef); + + bool unsupportedColorSpace = (imageColorSpaceModel == 0 || imageColorSpaceModel == -1 || imageColorSpaceModel == kCGColorSpaceModelCMYK || imageColorSpaceModel == kCGColorSpaceModelIndexed); + if (unsupportedColorSpace) + colorspaceRef = CGColorSpaceCreateDeviceRGB(); + + CGContextRef context = CGBitmapContextCreate(NULL, width, + height, + CGImageGetBitsPerComponent(imageRef), + 0, + colorspaceRef, + kCGBitmapByteOrderDefault | kCGImageAlphaPremultipliedFirst); + + // Draw the image into the context and retrieve the new image, which will now have an alpha layer + CGContextDrawImage(context, CGRectMake(0, 0, width, height), imageRef); + CGImageRef imageRefWithAlpha = CGBitmapContextCreateImage(context); + UIImage *imageWithAlpha = [UIImage imageWithCGImage:imageRefWithAlpha scale:image.scale orientation:image.imageOrientation]; + + if (unsupportedColorSpace) + CGColorSpaceRelease(colorspaceRef); + + CGContextRelease(context); + CGImageRelease(imageRefWithAlpha); + + return imageWithAlpha; + } +} + +@end diff --git a/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/SDWebImageDownloader.h b/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/SDWebImageDownloader.h new file mode 100644 index 00000000..b64fb130 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/SDWebImageDownloader.h @@ -0,0 +1,191 @@ +/* + * This file is part of the SDWebImage package. + * (c) Olivier Poitrey + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +#import +#import "SDWebImageCompat.h" +#import "SDWebImageOperation.h" + +typedef NS_OPTIONS(NSUInteger, SDWebImageDownloaderOptions) { + SDWebImageDownloaderLowPriority = 1 << 0, + SDWebImageDownloaderProgressiveDownload = 1 << 1, + + /** + * By default, request prevent the of NSURLCache. With this flag, NSURLCache + * is used with default policies. + */ + SDWebImageDownloaderUseNSURLCache = 1 << 2, + + /** + * Call completion block with nil image/imageData if the image was read from NSURLCache + * (to be combined with `SDWebImageDownloaderUseNSURLCache`). + */ + + SDWebImageDownloaderIgnoreCachedResponse = 1 << 3, + /** + * In iOS 4+, continue the download of the image if the app goes to background. This is achieved by asking the system for + * extra time in background to let the request finish. If the background task expires the operation will be cancelled. + */ + + SDWebImageDownloaderContinueInBackground = 1 << 4, + + /** + * Handles cookies stored in NSHTTPCookieStore by setting + * NSMutableURLRequest.HTTPShouldHandleCookies = YES; + */ + SDWebImageDownloaderHandleCookies = 1 << 5, + + /** + * Enable to allow untrusted SSL certificates. + * Useful for testing purposes. Use with caution in production. + */ + SDWebImageDownloaderAllowInvalidSSLCertificates = 1 << 6, + + /** + * Put the image in the high priority queue. + */ + SDWebImageDownloaderHighPriority = 1 << 7, +}; + +typedef NS_ENUM(NSInteger, SDWebImageDownloaderExecutionOrder) { + /** + * Default value. All download operations will execute in queue style (first-in-first-out). + */ + SDWebImageDownloaderFIFOExecutionOrder, + + /** + * All download operations will execute in stack style (last-in-first-out). + */ + SDWebImageDownloaderLIFOExecutionOrder +}; + +extern NSString *const SDWebImageDownloadStartNotification; +extern NSString *const SDWebImageDownloadStopNotification; + +typedef void(^SDWebImageDownloaderProgressBlock)(NSInteger receivedSize, NSInteger expectedSize); + +typedef void(^SDWebImageDownloaderCompletedBlock)(UIImage *image, NSData *data, NSError *error, BOOL finished); + +typedef NSDictionary *(^SDWebImageDownloaderHeadersFilterBlock)(NSURL *url, NSDictionary *headers); + +/** + * Asynchronous downloader dedicated and optimized for image loading. + */ +@interface SDWebImageDownloader : NSObject + +/** + * Decompressing images that are downloaded and cached can improve performance but can consume lot of memory. + * Defaults to YES. Set this to NO if you are experiencing a crash due to excessive memory consumption. + */ +@property (assign, nonatomic) BOOL shouldDecompressImages; + +@property (assign, nonatomic) NSInteger maxConcurrentDownloads; + +/** + * Shows the current amount of downloads that still need to be downloaded + */ +@property (readonly, nonatomic) NSUInteger currentDownloadCount; + + +/** + * The timeout value (in seconds) for the download operation. Default: 15.0. + */ +@property (assign, nonatomic) NSTimeInterval downloadTimeout; + + +/** + * Changes download operations execution order. Default value is `SDWebImageDownloaderFIFOExecutionOrder`. + */ +@property (assign, nonatomic) SDWebImageDownloaderExecutionOrder executionOrder; + +/** + * Singleton method, returns the shared instance + * + * @return global shared instance of downloader class + */ ++ (SDWebImageDownloader *)sharedDownloader; + +/** + * Set the default URL credential to be set for request operations. + */ +@property (strong, nonatomic) NSURLCredential *urlCredential; + +/** + * Set username + */ +@property (strong, nonatomic) NSString *username; + +/** + * Set password + */ +@property (strong, nonatomic) NSString *password; + +/** + * Set filter to pick headers for downloading image HTTP request. + * + * This block will be invoked for each downloading image request, returned + * NSDictionary will be used as headers in corresponding HTTP request. + */ +@property (nonatomic, copy) SDWebImageDownloaderHeadersFilterBlock headersFilter; + +/** + * Set a value for a HTTP header to be appended to each download HTTP request. + * + * @param value The value for the header field. Use `nil` value to remove the header. + * @param field The name of the header field to set. + */ +- (void)setValue:(NSString *)value forHTTPHeaderField:(NSString *)field; + +/** + * Returns the value of the specified HTTP header field. + * + * @return The value associated with the header field field, or `nil` if there is no corresponding header field. + */ +- (NSString *)valueForHTTPHeaderField:(NSString *)field; + +/** + * Sets a subclass of `SDWebImageDownloaderOperation` as the default + * `NSOperation` to be used each time SDWebImage constructs a request + * operation to download an image. + * + * @param operationClass The subclass of `SDWebImageDownloaderOperation` to set + * as default. Passing `nil` will revert to `SDWebImageDownloaderOperation`. + */ +- (void)setOperationClass:(Class)operationClass; + +/** + * Creates a SDWebImageDownloader async downloader instance with a given URL + * + * The delegate will be informed when the image is finish downloaded or an error has happen. + * + * @see SDWebImageDownloaderDelegate + * + * @param url The URL to the image to download + * @param options The options to be used for this download + * @param progressBlock A block called repeatedly while the image is downloading + * @param completedBlock A block called once the download is completed. + * If the download succeeded, the image parameter is set, in case of error, + * error parameter is set with the error. The last parameter is always YES + * if SDWebImageDownloaderProgressiveDownload isn't use. With the + * SDWebImageDownloaderProgressiveDownload option, this block is called + * repeatedly with the partial image object and the finished argument set to NO + * before to be called a last time with the full image and finished argument + * set to YES. In case of error, the finished argument is always YES. + * + * @return A cancellable SDWebImageOperation + */ +- (id )downloadImageWithURL:(NSURL *)url + options:(SDWebImageDownloaderOptions)options + progress:(SDWebImageDownloaderProgressBlock)progressBlock + completed:(SDWebImageDownloaderCompletedBlock)completedBlock; + +/** + * Sets the download queue suspension state + */ +- (void)setSuspended:(BOOL)suspended; + +@end diff --git a/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/SDWebImageDownloader.m b/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/SDWebImageDownloader.m new file mode 100644 index 00000000..1fdcfc92 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/SDWebImageDownloader.m @@ -0,0 +1,232 @@ +/* + * This file is part of the SDWebImage package. + * (c) Olivier Poitrey + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +#import "SDWebImageDownloader.h" +#import "SDWebImageDownloaderOperation.h" +#import + +static NSString *const kProgressCallbackKey = @"progress"; +static NSString *const kCompletedCallbackKey = @"completed"; + +@interface SDWebImageDownloader () + +@property (strong, nonatomic) NSOperationQueue *downloadQueue; +@property (weak, nonatomic) NSOperation *lastAddedOperation; +@property (assign, nonatomic) Class operationClass; +@property (strong, nonatomic) NSMutableDictionary *URLCallbacks; +@property (strong, nonatomic) NSMutableDictionary *HTTPHeaders; +// This queue is used to serialize the handling of the network responses of all the download operation in a single queue +@property (SDDispatchQueueSetterSementics, nonatomic) dispatch_queue_t barrierQueue; + +@end + +@implementation SDWebImageDownloader + ++ (void)initialize { + // Bind SDNetworkActivityIndicator if available (download it here: http://github.com/rs/SDNetworkActivityIndicator ) + // To use it, just add #import "SDNetworkActivityIndicator.h" in addition to the SDWebImage import + if (NSClassFromString(@"SDNetworkActivityIndicator")) { + +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Warc-performSelector-leaks" + id activityIndicator = [NSClassFromString(@"SDNetworkActivityIndicator") performSelector:NSSelectorFromString(@"sharedActivityIndicator")]; +#pragma clang diagnostic pop + + // Remove observer in case it was previously added. + [[NSNotificationCenter defaultCenter] removeObserver:activityIndicator name:SDWebImageDownloadStartNotification object:nil]; + [[NSNotificationCenter defaultCenter] removeObserver:activityIndicator name:SDWebImageDownloadStopNotification object:nil]; + + [[NSNotificationCenter defaultCenter] addObserver:activityIndicator + selector:NSSelectorFromString(@"startActivity") + name:SDWebImageDownloadStartNotification object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:activityIndicator + selector:NSSelectorFromString(@"stopActivity") + name:SDWebImageDownloadStopNotification object:nil]; + } +} + ++ (SDWebImageDownloader *)sharedDownloader { + static dispatch_once_t once; + static id instance; + dispatch_once(&once, ^{ + instance = [self new]; + }); + return instance; +} + +- (id)init { + if ((self = [super init])) { + _operationClass = [SDWebImageDownloaderOperation class]; + _shouldDecompressImages = YES; + _executionOrder = SDWebImageDownloaderFIFOExecutionOrder; + _downloadQueue = [NSOperationQueue new]; + _downloadQueue.maxConcurrentOperationCount = 6; + _URLCallbacks = [NSMutableDictionary new]; +#ifdef SD_WEBP + _HTTPHeaders = [@{@"Accept": @"image/webp,image/*;q=0.8"} mutableCopy]; +#else + _HTTPHeaders = [@{@"Accept": @"image/*;q=0.8"} mutableCopy]; +#endif + _barrierQueue = dispatch_queue_create("com.hackemist.SDWebImageDownloaderBarrierQueue", DISPATCH_QUEUE_CONCURRENT); + _downloadTimeout = 15.0; + } + return self; +} + +- (void)dealloc { + [self.downloadQueue cancelAllOperations]; + SDDispatchQueueRelease(_barrierQueue); +} + +- (void)setValue:(NSString *)value forHTTPHeaderField:(NSString *)field { + if (value) { + self.HTTPHeaders[field] = value; + } + else { + [self.HTTPHeaders removeObjectForKey:field]; + } +} + +- (NSString *)valueForHTTPHeaderField:(NSString *)field { + return self.HTTPHeaders[field]; +} + +- (void)setMaxConcurrentDownloads:(NSInteger)maxConcurrentDownloads { + _downloadQueue.maxConcurrentOperationCount = maxConcurrentDownloads; +} + +- (NSUInteger)currentDownloadCount { + return _downloadQueue.operationCount; +} + +- (NSInteger)maxConcurrentDownloads { + return _downloadQueue.maxConcurrentOperationCount; +} + +- (void)setOperationClass:(Class)operationClass { + _operationClass = operationClass ?: [SDWebImageDownloaderOperation class]; +} + +- (id )downloadImageWithURL:(NSURL *)url options:(SDWebImageDownloaderOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageDownloaderCompletedBlock)completedBlock { + __block SDWebImageDownloaderOperation *operation; + __weak __typeof(self)wself = self; + + [self addProgressCallback:progressBlock completedBlock:completedBlock forURL:url createCallback:^{ + NSTimeInterval timeoutInterval = wself.downloadTimeout; + if (timeoutInterval == 0.0) { + timeoutInterval = 15.0; + } + + // In order to prevent from potential duplicate caching (NSURLCache + SDImageCache) we disable the cache for image requests if told otherwise + NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url cachePolicy:(options & SDWebImageDownloaderUseNSURLCache ? NSURLRequestUseProtocolCachePolicy : NSURLRequestReloadIgnoringLocalCacheData) timeoutInterval:timeoutInterval]; + request.HTTPShouldHandleCookies = (options & SDWebImageDownloaderHandleCookies); + request.HTTPShouldUsePipelining = YES; + if (wself.headersFilter) { + request.allHTTPHeaderFields = wself.headersFilter(url, [wself.HTTPHeaders copy]); + } + else { + request.allHTTPHeaderFields = wself.HTTPHeaders; + } + operation = [[wself.operationClass alloc] initWithRequest:request + options:options + progress:^(NSInteger receivedSize, NSInteger expectedSize) { + SDWebImageDownloader *sself = wself; + if (!sself) return; + __block NSArray *callbacksForURL; + dispatch_sync(sself.barrierQueue, ^{ + callbacksForURL = [sself.URLCallbacks[url] copy]; + }); + for (NSDictionary *callbacks in callbacksForURL) { + dispatch_async(dispatch_get_main_queue(), ^{ + SDWebImageDownloaderProgressBlock callback = callbacks[kProgressCallbackKey]; + if (callback) callback(receivedSize, expectedSize); + }); + } + } + completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) { + SDWebImageDownloader *sself = wself; + if (!sself) return; + __block NSArray *callbacksForURL; + dispatch_barrier_sync(sself.barrierQueue, ^{ + callbacksForURL = [sself.URLCallbacks[url] copy]; + if (finished) { + [sself.URLCallbacks removeObjectForKey:url]; + } + }); + for (NSDictionary *callbacks in callbacksForURL) { + SDWebImageDownloaderCompletedBlock callback = callbacks[kCompletedCallbackKey]; + if (callback) callback(image, data, error, finished); + } + } + cancelled:^{ + SDWebImageDownloader *sself = wself; + if (!sself) return; + dispatch_barrier_async(sself.barrierQueue, ^{ + [sself.URLCallbacks removeObjectForKey:url]; + }); + }]; + operation.shouldDecompressImages = wself.shouldDecompressImages; + + if (wself.urlCredential) { + operation.credential = wself.urlCredential; + } else if (wself.username && wself.password) { + operation.credential = [NSURLCredential credentialWithUser:wself.username password:wself.password persistence:NSURLCredentialPersistenceForSession]; + } + + if (options & SDWebImageDownloaderHighPriority) { + operation.queuePriority = NSOperationQueuePriorityHigh; + } else if (options & SDWebImageDownloaderLowPriority) { + operation.queuePriority = NSOperationQueuePriorityLow; + } + + [wself.downloadQueue addOperation:operation]; + if (wself.executionOrder == SDWebImageDownloaderLIFOExecutionOrder) { + // Emulate LIFO execution order by systematically adding new operations as last operation's dependency + [wself.lastAddedOperation addDependency:operation]; + wself.lastAddedOperation = operation; + } + }]; + + return operation; +} + +- (void)addProgressCallback:(SDWebImageDownloaderProgressBlock)progressBlock completedBlock:(SDWebImageDownloaderCompletedBlock)completedBlock forURL:(NSURL *)url createCallback:(SDWebImageNoParamsBlock)createCallback { + // The URL will be used as the key to the callbacks dictionary so it cannot be nil. If it is nil immediately call the completed block with no image or data. + if (url == nil) { + if (completedBlock != nil) { + completedBlock(nil, nil, nil, NO); + } + return; + } + + dispatch_barrier_sync(self.barrierQueue, ^{ + BOOL first = NO; + if (!self.URLCallbacks[url]) { + self.URLCallbacks[url] = [NSMutableArray new]; + first = YES; + } + + // Handle single download of simultaneous download request for the same URL + NSMutableArray *callbacksForURL = self.URLCallbacks[url]; + NSMutableDictionary *callbacks = [NSMutableDictionary new]; + if (progressBlock) callbacks[kProgressCallbackKey] = [progressBlock copy]; + if (completedBlock) callbacks[kCompletedCallbackKey] = [completedBlock copy]; + [callbacksForURL addObject:callbacks]; + self.URLCallbacks[url] = callbacksForURL; + + if (first) { + createCallback(); + } + }); +} + +- (void)setSuspended:(BOOL)suspended { + [self.downloadQueue setSuspended:suspended]; +} + +@end diff --git a/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/SDWebImageDownloaderOperation.h b/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/SDWebImageDownloaderOperation.h new file mode 100644 index 00000000..dd48b228 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/SDWebImageDownloaderOperation.h @@ -0,0 +1,78 @@ +/* + * This file is part of the SDWebImage package. + * (c) Olivier Poitrey + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +#import +#import "SDWebImageDownloader.h" +#import "SDWebImageOperation.h" + +extern NSString *const SDWebImageDownloadStartNotification; +extern NSString *const SDWebImageDownloadReceiveResponseNotification; +extern NSString *const SDWebImageDownloadStopNotification; +extern NSString *const SDWebImageDownloadFinishNotification; + +@interface SDWebImageDownloaderOperation : NSOperation + +/** + * The request used by the operation's connection. + */ +@property (strong, nonatomic, readonly) NSURLRequest *request; + + +@property (assign, nonatomic) BOOL shouldDecompressImages; + +/** + * Whether the URL connection should consult the credential storage for authenticating the connection. `YES` by default. + * + * This is the value that is returned in the `NSURLConnectionDelegate` method `-connectionShouldUseCredentialStorage:`. + */ +@property (nonatomic, assign) BOOL shouldUseCredentialStorage; + +/** + * The credential used for authentication challenges in `-connection:didReceiveAuthenticationChallenge:`. + * + * This will be overridden by any shared credentials that exist for the username or password of the request URL, if present. + */ +@property (nonatomic, strong) NSURLCredential *credential; + +/** + * The SDWebImageDownloaderOptions for the receiver. + */ +@property (assign, nonatomic, readonly) SDWebImageDownloaderOptions options; + +/** + * The expected size of data. + */ +@property (assign, nonatomic) NSInteger expectedSize; + +/** + * The response returned by the operation's connection. + */ +@property (strong, nonatomic) NSURLResponse *response; + +/** + * Initializes a `SDWebImageDownloaderOperation` object + * + * @see SDWebImageDownloaderOperation + * + * @param request the URL request + * @param options downloader options + * @param progressBlock the block executed when a new chunk of data arrives. + * @note the progress block is executed on a background queue + * @param completedBlock the block executed when the download is done. + * @note the completed block is executed on the main queue for success. If errors are found, there is a chance the block will be executed on a background queue + * @param cancelBlock the block executed if the download (operation) is cancelled + * + * @return the initialized instance + */ +- (id)initWithRequest:(NSURLRequest *)request + options:(SDWebImageDownloaderOptions)options + progress:(SDWebImageDownloaderProgressBlock)progressBlock + completed:(SDWebImageDownloaderCompletedBlock)completedBlock + cancelled:(SDWebImageNoParamsBlock)cancelBlock; + +@end diff --git a/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/SDWebImageDownloaderOperation.m b/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/SDWebImageDownloaderOperation.m new file mode 100644 index 00000000..5a8bd11f --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/SDWebImageDownloaderOperation.m @@ -0,0 +1,466 @@ +/* + * This file is part of the SDWebImage package. + * (c) Olivier Poitrey + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +#import "SDWebImageDownloaderOperation.h" +#import "SDWebImageDecoder.h" +#import "UIImage+MultiFormat.h" +#import +#import "SDWebImageManager.h" + +NSString *const SDWebImageDownloadStartNotification = @"SDWebImageDownloadStartNotification"; +NSString *const SDWebImageDownloadReceiveResponseNotification = @"SDWebImageDownloadReceiveResponseNotification"; +NSString *const SDWebImageDownloadStopNotification = @"SDWebImageDownloadStopNotification"; +NSString *const SDWebImageDownloadFinishNotification = @"SDWebImageDownloadFinishNotification"; + +@interface SDWebImageDownloaderOperation () + +@property (copy, nonatomic) SDWebImageDownloaderProgressBlock progressBlock; +@property (copy, nonatomic) SDWebImageDownloaderCompletedBlock completedBlock; +@property (copy, nonatomic) SDWebImageNoParamsBlock cancelBlock; + +@property (assign, nonatomic, getter = isExecuting) BOOL executing; +@property (assign, nonatomic, getter = isFinished) BOOL finished; +@property (strong, nonatomic) NSMutableData *imageData; +@property (strong, nonatomic) NSURLConnection *connection; +@property (strong, atomic) NSThread *thread; + +#if TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_4_0 +@property (assign, nonatomic) UIBackgroundTaskIdentifier backgroundTaskId; +#endif + +@end + +@implementation SDWebImageDownloaderOperation { + size_t width, height; + UIImageOrientation orientation; + BOOL responseFromCached; +} + +@synthesize executing = _executing; +@synthesize finished = _finished; + +- (id)initWithRequest:(NSURLRequest *)request + options:(SDWebImageDownloaderOptions)options + progress:(SDWebImageDownloaderProgressBlock)progressBlock + completed:(SDWebImageDownloaderCompletedBlock)completedBlock + cancelled:(SDWebImageNoParamsBlock)cancelBlock { + if ((self = [super init])) { + _request = request; + _shouldDecompressImages = YES; + _shouldUseCredentialStorage = YES; + _options = options; + _progressBlock = [progressBlock copy]; + _completedBlock = [completedBlock copy]; + _cancelBlock = [cancelBlock copy]; + _executing = NO; + _finished = NO; + _expectedSize = 0; + responseFromCached = YES; // Initially wrong until `connection:willCacheResponse:` is called or not called + } + return self; +} + +- (void)start { + @synchronized (self) { + if (self.isCancelled) { + self.finished = YES; + [self reset]; + return; + } + +#if TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_4_0 + Class UIApplicationClass = NSClassFromString(@"UIApplication"); + BOOL hasApplication = UIApplicationClass && [UIApplicationClass respondsToSelector:@selector(sharedApplication)]; + if (hasApplication && [self shouldContinueWhenAppEntersBackground]) { + __weak __typeof__ (self) wself = self; + UIApplication * app = [UIApplicationClass performSelector:@selector(sharedApplication)]; + self.backgroundTaskId = [app beginBackgroundTaskWithExpirationHandler:^{ + __strong __typeof (wself) sself = wself; + + if (sself) { + [sself cancel]; + + [app endBackgroundTask:sself.backgroundTaskId]; + sself.backgroundTaskId = UIBackgroundTaskInvalid; + } + }]; + } +#endif + + self.executing = YES; + self.connection = [[NSURLConnection alloc] initWithRequest:self.request delegate:self startImmediately:NO]; + self.thread = [NSThread currentThread]; + } + + [self.connection start]; + + if (self.connection) { + if (self.progressBlock) { + self.progressBlock(0, NSURLResponseUnknownLength); + } + dispatch_async(dispatch_get_main_queue(), ^{ + [[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadStartNotification object:self]; + }); + + if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_5_1) { + // Make sure to run the runloop in our background thread so it can process downloaded data + // Note: we use a timeout to work around an issue with NSURLConnection cancel under iOS 5 + // not waking up the runloop, leading to dead threads (see https://github.com/rs/SDWebImage/issues/466) + CFRunLoopRunInMode(kCFRunLoopDefaultMode, 10, false); + } + else { + CFRunLoopRun(); + } + + if (!self.isFinished) { + [self.connection cancel]; + [self connection:self.connection didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorTimedOut userInfo:@{NSURLErrorFailingURLErrorKey : self.request.URL}]]; + } + } + else { + if (self.completedBlock) { + self.completedBlock(nil, nil, [NSError errorWithDomain:NSURLErrorDomain code:0 userInfo:@{NSLocalizedDescriptionKey : @"Connection can't be initialized"}], YES); + } + } + +#if TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_4_0 + Class UIApplicationClass = NSClassFromString(@"UIApplication"); + if(!UIApplicationClass || ![UIApplicationClass respondsToSelector:@selector(sharedApplication)]) { + return; + } + if (self.backgroundTaskId != UIBackgroundTaskInvalid) { + UIApplication * app = [UIApplication performSelector:@selector(sharedApplication)]; + [app endBackgroundTask:self.backgroundTaskId]; + self.backgroundTaskId = UIBackgroundTaskInvalid; + } +#endif +} + +- (void)cancel { + @synchronized (self) { + if (self.thread) { + [self performSelector:@selector(cancelInternalAndStop) onThread:self.thread withObject:nil waitUntilDone:NO]; + } + else { + [self cancelInternal]; + } + } +} + +- (void)cancelInternalAndStop { + if (self.isFinished) return; + [self cancelInternal]; + CFRunLoopStop(CFRunLoopGetCurrent()); +} + +- (void)cancelInternal { + if (self.isFinished) return; + [super cancel]; + if (self.cancelBlock) self.cancelBlock(); + + if (self.connection) { + [self.connection cancel]; + dispatch_async(dispatch_get_main_queue(), ^{ + [[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadStopNotification object:self]; + }); + + // As we cancelled the connection, its callback won't be called and thus won't + // maintain the isFinished and isExecuting flags. + if (self.isExecuting) self.executing = NO; + if (!self.isFinished) self.finished = YES; + } + + [self reset]; +} + +- (void)done { + self.finished = YES; + self.executing = NO; + [self reset]; +} + +- (void)reset { + self.cancelBlock = nil; + self.completedBlock = nil; + self.progressBlock = nil; + self.connection = nil; + self.imageData = nil; + self.thread = nil; +} + +- (void)setFinished:(BOOL)finished { + [self willChangeValueForKey:@"isFinished"]; + _finished = finished; + [self didChangeValueForKey:@"isFinished"]; +} + +- (void)setExecuting:(BOOL)executing { + [self willChangeValueForKey:@"isExecuting"]; + _executing = executing; + [self didChangeValueForKey:@"isExecuting"]; +} + +- (BOOL)isConcurrent { + return YES; +} + +#pragma mark NSURLConnection (delegate) + +- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { + + //'304 Not Modified' is an exceptional one + if (![response respondsToSelector:@selector(statusCode)] || ([((NSHTTPURLResponse *)response) statusCode] < 400 && [((NSHTTPURLResponse *)response) statusCode] != 304)) { + NSInteger expected = response.expectedContentLength > 0 ? (NSInteger)response.expectedContentLength : 0; + self.expectedSize = expected; + if (self.progressBlock) { + self.progressBlock(0, expected); + } + + self.imageData = [[NSMutableData alloc] initWithCapacity:expected]; + self.response = response; + dispatch_async(dispatch_get_main_queue(), ^{ + [[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadReceiveResponseNotification object:self]; + }); + } + else { + NSUInteger code = [((NSHTTPURLResponse *)response) statusCode]; + + //This is the case when server returns '304 Not Modified'. It means that remote image is not changed. + //In case of 304 we need just cancel the operation and return cached image from the cache. + if (code == 304) { + [self cancelInternal]; + } else { + [self.connection cancel]; + } + dispatch_async(dispatch_get_main_queue(), ^{ + [[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadStopNotification object:self]; + }); + + if (self.completedBlock) { + self.completedBlock(nil, nil, [NSError errorWithDomain:NSURLErrorDomain code:[((NSHTTPURLResponse *)response) statusCode] userInfo:nil], YES); + } + CFRunLoopStop(CFRunLoopGetCurrent()); + [self done]; + } +} + +- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { + [self.imageData appendData:data]; + + if ((self.options & SDWebImageDownloaderProgressiveDownload) && self.expectedSize > 0 && self.completedBlock) { + // The following code is from http://www.cocoaintheshell.com/2011/05/progressive-images-download-imageio/ + // Thanks to the author @Nyx0uf + + // Get the total bytes downloaded + const NSInteger totalSize = self.imageData.length; + + // Update the data source, we must pass ALL the data, not just the new bytes + CGImageSourceRef imageSource = CGImageSourceCreateWithData((__bridge CFDataRef)self.imageData, NULL); + + if (width + height == 0) { + CFDictionaryRef properties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, NULL); + if (properties) { + NSInteger orientationValue = -1; + CFTypeRef val = CFDictionaryGetValue(properties, kCGImagePropertyPixelHeight); + if (val) CFNumberGetValue(val, kCFNumberLongType, &height); + val = CFDictionaryGetValue(properties, kCGImagePropertyPixelWidth); + if (val) CFNumberGetValue(val, kCFNumberLongType, &width); + val = CFDictionaryGetValue(properties, kCGImagePropertyOrientation); + if (val) CFNumberGetValue(val, kCFNumberNSIntegerType, &orientationValue); + CFRelease(properties); + + // When we draw to Core Graphics, we lose orientation information, + // which means the image below born of initWithCGIImage will be + // oriented incorrectly sometimes. (Unlike the image born of initWithData + // in connectionDidFinishLoading.) So save it here and pass it on later. + orientation = [[self class] orientationFromPropertyValue:(orientationValue == -1 ? 1 : orientationValue)]; + } + + } + + if (width + height > 0 && totalSize < self.expectedSize) { + // Create the image + CGImageRef partialImageRef = CGImageSourceCreateImageAtIndex(imageSource, 0, NULL); + +#ifdef TARGET_OS_IPHONE + // Workaround for iOS anamorphic image + if (partialImageRef) { + const size_t partialHeight = CGImageGetHeight(partialImageRef); + CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); + CGContextRef bmContext = CGBitmapContextCreate(NULL, width, height, 8, width * 4, colorSpace, kCGBitmapByteOrderDefault | kCGImageAlphaPremultipliedFirst); + CGColorSpaceRelease(colorSpace); + if (bmContext) { + CGContextDrawImage(bmContext, (CGRect){.origin.x = 0.0f, .origin.y = 0.0f, .size.width = width, .size.height = partialHeight}, partialImageRef); + CGImageRelease(partialImageRef); + partialImageRef = CGBitmapContextCreateImage(bmContext); + CGContextRelease(bmContext); + } + else { + CGImageRelease(partialImageRef); + partialImageRef = nil; + } + } +#endif + + if (partialImageRef) { + UIImage *image = [UIImage imageWithCGImage:partialImageRef scale:1 orientation:orientation]; + NSString *key = [[SDWebImageManager sharedManager] cacheKeyForURL:self.request.URL]; + UIImage *scaledImage = [self scaledImageForKey:key image:image]; + if (self.shouldDecompressImages) { + image = [UIImage decodedImageWithImage:scaledImage]; + } + else { + image = scaledImage; + } + CGImageRelease(partialImageRef); + dispatch_main_sync_safe(^{ + if (self.completedBlock) { + self.completedBlock(image, nil, nil, NO); + } + }); + } + } + + CFRelease(imageSource); + } + + if (self.progressBlock) { + self.progressBlock(self.imageData.length, self.expectedSize); + } +} + ++ (UIImageOrientation)orientationFromPropertyValue:(NSInteger)value { + switch (value) { + case 1: + return UIImageOrientationUp; + case 3: + return UIImageOrientationDown; + case 8: + return UIImageOrientationLeft; + case 6: + return UIImageOrientationRight; + case 2: + return UIImageOrientationUpMirrored; + case 4: + return UIImageOrientationDownMirrored; + case 5: + return UIImageOrientationLeftMirrored; + case 7: + return UIImageOrientationRightMirrored; + default: + return UIImageOrientationUp; + } +} + +- (UIImage *)scaledImageForKey:(NSString *)key image:(UIImage *)image { + return SDScaledImageForKey(key, image); +} + +- (void)connectionDidFinishLoading:(NSURLConnection *)aConnection { + SDWebImageDownloaderCompletedBlock completionBlock = self.completedBlock; + @synchronized(self) { + CFRunLoopStop(CFRunLoopGetCurrent()); + self.thread = nil; + self.connection = nil; + dispatch_async(dispatch_get_main_queue(), ^{ + [[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadStopNotification object:self]; + [[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadFinishNotification object:self]; + }); + } + + if (![[NSURLCache sharedURLCache] cachedResponseForRequest:_request]) { + responseFromCached = NO; + } + + if (completionBlock) { + if (self.options & SDWebImageDownloaderIgnoreCachedResponse && responseFromCached) { + completionBlock(nil, nil, nil, YES); + } else if (self.imageData) { + UIImage *image = [UIImage sd_imageWithData:self.imageData]; + NSString *key = [[SDWebImageManager sharedManager] cacheKeyForURL:self.request.URL]; + image = [self scaledImageForKey:key image:image]; + + // Do not force decoding animated GIFs + if (!image.images) { + if (self.shouldDecompressImages) { + image = [UIImage decodedImageWithImage:image]; + } + } + if (CGSizeEqualToSize(image.size, CGSizeZero)) { + completionBlock(nil, nil, [NSError errorWithDomain:SDWebImageErrorDomain code:0 userInfo:@{NSLocalizedDescriptionKey : @"Downloaded image has 0 pixels"}], YES); + } + else { + completionBlock(image, self.imageData, nil, YES); + } + } else { + completionBlock(nil, nil, [NSError errorWithDomain:SDWebImageErrorDomain code:0 userInfo:@{NSLocalizedDescriptionKey : @"Image data is nil"}], YES); + } + } + self.completionBlock = nil; + [self done]; +} + +- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { + @synchronized(self) { + CFRunLoopStop(CFRunLoopGetCurrent()); + self.thread = nil; + self.connection = nil; + dispatch_async(dispatch_get_main_queue(), ^{ + [[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadStopNotification object:self]; + }); + } + + if (self.completedBlock) { + self.completedBlock(nil, nil, error, YES); + } + self.completionBlock = nil; + [self done]; +} + +- (NSCachedURLResponse *)connection:(NSURLConnection *)connection willCacheResponse:(NSCachedURLResponse *)cachedResponse { + responseFromCached = NO; // If this method is called, it means the response wasn't read from cache + if (self.request.cachePolicy == NSURLRequestReloadIgnoringLocalCacheData) { + // Prevents caching of responses + return nil; + } + else { + return cachedResponse; + } +} + +- (BOOL)shouldContinueWhenAppEntersBackground { + return self.options & SDWebImageDownloaderContinueInBackground; +} + +- (BOOL)connectionShouldUseCredentialStorage:(NSURLConnection __unused *)connection { + return self.shouldUseCredentialStorage; +} + +- (void)connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge{ + if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) { + if (!(self.options & SDWebImageDownloaderAllowInvalidSSLCertificates) && + [challenge.sender respondsToSelector:@selector(performDefaultHandlingForAuthenticationChallenge:)]) { + [challenge.sender performDefaultHandlingForAuthenticationChallenge:challenge]; + } else { + NSURLCredential *credential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]; + [[challenge sender] useCredential:credential forAuthenticationChallenge:challenge]; + } + } else { + if ([challenge previousFailureCount] == 0) { + if (self.credential) { + [[challenge sender] useCredential:self.credential forAuthenticationChallenge:challenge]; + } else { + [[challenge sender] continueWithoutCredentialForAuthenticationChallenge:challenge]; + } + } else { + [[challenge sender] continueWithoutCredentialForAuthenticationChallenge:challenge]; + } + } +} + +@end diff --git a/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/SDWebImageManager.h b/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/SDWebImageManager.h new file mode 100644 index 00000000..18e578a3 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/SDWebImageManager.h @@ -0,0 +1,299 @@ +/* + * This file is part of the SDWebImage package. + * (c) Olivier Poitrey + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +#import "SDWebImageCompat.h" +#import "SDWebImageOperation.h" +#import "SDWebImageDownloader.h" +#import "SDImageCache.h" + +typedef NS_OPTIONS(NSUInteger, SDWebImageOptions) { + /** + * By default, when a URL fail to be downloaded, the URL is blacklisted so the library won't keep trying. + * This flag disable this blacklisting. + */ + SDWebImageRetryFailed = 1 << 0, + + /** + * By default, image downloads are started during UI interactions, this flags disable this feature, + * leading to delayed download on UIScrollView deceleration for instance. + */ + SDWebImageLowPriority = 1 << 1, + + /** + * This flag disables on-disk caching + */ + SDWebImageCacheMemoryOnly = 1 << 2, + + /** + * This flag enables progressive download, the image is displayed progressively during download as a browser would do. + * By default, the image is only displayed once completely downloaded. + */ + SDWebImageProgressiveDownload = 1 << 3, + + /** + * Even if the image is cached, respect the HTTP response cache control, and refresh the image from remote location if needed. + * The disk caching will be handled by NSURLCache instead of SDWebImage leading to slight performance degradation. + * This option helps deal with images changing behind the same request URL, e.g. Facebook graph api profile pics. + * If a cached image is refreshed, the completion block is called once with the cached image and again with the final image. + * + * Use this flag only if you can't make your URLs static with embedded cache busting parameter. + */ + SDWebImageRefreshCached = 1 << 4, + + /** + * In iOS 4+, continue the download of the image if the app goes to background. This is achieved by asking the system for + * extra time in background to let the request finish. If the background task expires the operation will be cancelled. + */ + SDWebImageContinueInBackground = 1 << 5, + + /** + * Handles cookies stored in NSHTTPCookieStore by setting + * NSMutableURLRequest.HTTPShouldHandleCookies = YES; + */ + SDWebImageHandleCookies = 1 << 6, + + /** + * Enable to allow untrusted SSL certificates. + * Useful for testing purposes. Use with caution in production. + */ + SDWebImageAllowInvalidSSLCertificates = 1 << 7, + + /** + * By default, image are loaded in the order they were queued. This flag move them to + * the front of the queue and is loaded immediately instead of waiting for the current queue to be loaded (which + * could take a while). + */ + SDWebImageHighPriority = 1 << 8, + + /** + * By default, placeholder images are loaded while the image is loading. This flag will delay the loading + * of the placeholder image until after the image has finished loading. + */ + SDWebImageDelayPlaceholder = 1 << 9, + + /** + * We usually don't call transformDownloadedImage delegate method on animated images, + * as most transformation code would mangle it. + * Use this flag to transform them anyway. + */ + SDWebImageTransformAnimatedImage = 1 << 10, + + /** + * By default, image is added to the imageView after download. But in some cases, we want to + * have the hand before setting the image (apply a filter or add it with cross-fade animation for instance) + * Use this flag if you want to manually set the image in the completion when success + */ + SDWebImageAvoidAutoSetImage = 1 << 11 +}; + +typedef void(^SDWebImageCompletionBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL); + +typedef void(^SDWebImageCompletionWithFinishedBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL); + +typedef NSString *(^SDWebImageCacheKeyFilterBlock)(NSURL *url); + + +@class SDWebImageManager; + +@protocol SDWebImageManagerDelegate + +@optional + +/** + * Controls which image should be downloaded when the image is not found in the cache. + * + * @param imageManager The current `SDWebImageManager` + * @param imageURL The url of the image to be downloaded + * + * @return Return NO to prevent the downloading of the image on cache misses. If not implemented, YES is implied. + */ +- (BOOL)imageManager:(SDWebImageManager *)imageManager shouldDownloadImageForURL:(NSURL *)imageURL; + +/** + * Allows to transform the image immediately after it has been downloaded and just before to cache it on disk and memory. + * NOTE: This method is called from a global queue in order to not to block the main thread. + * + * @param imageManager The current `SDWebImageManager` + * @param image The image to transform + * @param imageURL The url of the image to transform + * + * @return The transformed image object. + */ +- (UIImage *)imageManager:(SDWebImageManager *)imageManager transformDownloadedImage:(UIImage *)image withURL:(NSURL *)imageURL; + +@end + +/** + * The SDWebImageManager is the class behind the UIImageView+WebCache category and likes. + * It ties the asynchronous downloader (SDWebImageDownloader) with the image cache store (SDImageCache). + * You can use this class directly to benefit from web image downloading with caching in another context than + * a UIView. + * + * Here is a simple example of how to use SDWebImageManager: + * + * @code + +SDWebImageManager *manager = [SDWebImageManager sharedManager]; +[manager downloadImageWithURL:imageURL + options:0 + progress:nil + completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { + if (image) { + // do something with image + } + }]; + + * @endcode + */ +@interface SDWebImageManager : NSObject + +@property (weak, nonatomic) id delegate; + +@property (strong, nonatomic, readonly) SDImageCache *imageCache; +@property (strong, nonatomic, readonly) SDWebImageDownloader *imageDownloader; + +/** + * The cache filter is a block used each time SDWebImageManager need to convert an URL into a cache key. This can + * be used to remove dynamic part of an image URL. + * + * The following example sets a filter in the application delegate that will remove any query-string from the + * URL before to use it as a cache key: + * + * @code + +[[SDWebImageManager sharedManager] setCacheKeyFilter:^(NSURL *url) { + url = [[NSURL alloc] initWithScheme:url.scheme host:url.host path:url.path]; + return [url absoluteString]; +}]; + + * @endcode + */ +@property (nonatomic, copy) SDWebImageCacheKeyFilterBlock cacheKeyFilter; + +/** + * Returns global SDWebImageManager instance. + * + * @return SDWebImageManager shared instance + */ ++ (SDWebImageManager *)sharedManager; + +/** + * Downloads the image at the given URL if not present in cache or return the cached version otherwise. + * + * @param url The URL to the image + * @param options A mask to specify options to use for this request + * @param progressBlock A block called while image is downloading + * @param completedBlock A block called when operation has been completed. + * + * This parameter is required. + * + * This block has no return value and takes the requested UIImage as first parameter. + * In case of error the image parameter is nil and the second parameter may contain an NSError. + * + * The third parameter is an `SDImageCacheType` enum indicating if the image was retrieved from the local cache + * or from the memory cache or from the network. + * + * The last parameter is set to NO when the SDWebImageProgressiveDownload option is used and the image is + * downloading. This block is thus called repeatedly with a partial image. When image is fully downloaded, the + * block is called a last time with the full image and the last parameter set to YES. + * + * @return Returns an NSObject conforming to SDWebImageOperation. Should be an instance of SDWebImageDownloaderOperation + */ +- (id )downloadImageWithURL:(NSURL *)url + options:(SDWebImageOptions)options + progress:(SDWebImageDownloaderProgressBlock)progressBlock + completed:(SDWebImageCompletionWithFinishedBlock)completedBlock; + +/** + * Saves image to cache for given URL + * + * @param image The image to cache + * @param url The URL to the image + * + */ + +- (void)saveImageToCache:(UIImage *)image forURL:(NSURL *)url; + +/** + * Cancel all current operations + */ +- (void)cancelAll; + +/** + * Check one or more operations running + */ +- (BOOL)isRunning; + +/** + * Check if image has already been cached + * + * @param url image url + * + * @return if the image was already cached + */ +- (BOOL)cachedImageExistsForURL:(NSURL *)url; + +/** + * Check if image has already been cached on disk only + * + * @param url image url + * + * @return if the image was already cached (disk only) + */ +- (BOOL)diskImageExistsForURL:(NSURL *)url; + +/** + * Async check if image has already been cached + * + * @param url image url + * @param completionBlock the block to be executed when the check is finished + * + * @note the completion block is always executed on the main queue + */ +- (void)cachedImageExistsForURL:(NSURL *)url + completion:(SDWebImageCheckCacheCompletionBlock)completionBlock; + +/** + * Async check if image has already been cached on disk only + * + * @param url image url + * @param completionBlock the block to be executed when the check is finished + * + * @note the completion block is always executed on the main queue + */ +- (void)diskImageExistsForURL:(NSURL *)url + completion:(SDWebImageCheckCacheCompletionBlock)completionBlock; + + +/** + *Return the cache key for a given URL + */ +- (NSString *)cacheKeyForURL:(NSURL *)url; + +@end + + +#pragma mark - Deprecated + +typedef void(^SDWebImageCompletedBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType) __deprecated_msg("Block type deprecated. Use `SDWebImageCompletionBlock`"); +typedef void(^SDWebImageCompletedWithFinishedBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished) __deprecated_msg("Block type deprecated. Use `SDWebImageCompletionWithFinishedBlock`"); + + +@interface SDWebImageManager (Deprecated) + +/** + * Downloads the image at the given URL if not present in cache or return the cached version otherwise. + * + * @deprecated This method has been deprecated. Use `downloadImageWithURL:options:progress:completed:` + */ +- (id )downloadWithURL:(NSURL *)url + options:(SDWebImageOptions)options + progress:(SDWebImageDownloaderProgressBlock)progressBlock + completed:(SDWebImageCompletedWithFinishedBlock)completedBlock __deprecated_msg("Method deprecated. Use `downloadImageWithURL:options:progress:completed:`"); + +@end diff --git a/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/SDWebImageManager.m b/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/SDWebImageManager.m new file mode 100644 index 00000000..c804ee9a --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/SDWebImageManager.m @@ -0,0 +1,370 @@ +/* + * This file is part of the SDWebImage package. + * (c) Olivier Poitrey + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +#import "SDWebImageManager.h" +#import + +@interface SDWebImageCombinedOperation : NSObject + +@property (assign, nonatomic, getter = isCancelled) BOOL cancelled; +@property (copy, nonatomic) SDWebImageNoParamsBlock cancelBlock; +@property (strong, nonatomic) NSOperation *cacheOperation; + +@end + +@interface SDWebImageManager () + +@property (strong, nonatomic, readwrite) SDImageCache *imageCache; +@property (strong, nonatomic, readwrite) SDWebImageDownloader *imageDownloader; +@property (strong, nonatomic) NSMutableSet *failedURLs; +@property (strong, nonatomic) NSMutableArray *runningOperations; + +@end + +@implementation SDWebImageManager + ++ (id)sharedManager { + static dispatch_once_t once; + static id instance; + dispatch_once(&once, ^{ + instance = [self new]; + }); + return instance; +} + +- (id)init { + if ((self = [super init])) { + _imageCache = [self createCache]; + _imageDownloader = [SDWebImageDownloader sharedDownloader]; + _failedURLs = [NSMutableSet new]; + _runningOperations = [NSMutableArray new]; + } + return self; +} + +- (SDImageCache *)createCache { + return [SDImageCache sharedImageCache]; +} + +- (NSString *)cacheKeyForURL:(NSURL *)url { + if (self.cacheKeyFilter) { + return self.cacheKeyFilter(url); + } + else { + return [url absoluteString]; + } +} + +- (BOOL)cachedImageExistsForURL:(NSURL *)url { + NSString *key = [self cacheKeyForURL:url]; + if ([self.imageCache imageFromMemoryCacheForKey:key] != nil) return YES; + return [self.imageCache diskImageExistsWithKey:key]; +} + +- (BOOL)diskImageExistsForURL:(NSURL *)url { + NSString *key = [self cacheKeyForURL:url]; + return [self.imageCache diskImageExistsWithKey:key]; +} + +- (void)cachedImageExistsForURL:(NSURL *)url + completion:(SDWebImageCheckCacheCompletionBlock)completionBlock { + NSString *key = [self cacheKeyForURL:url]; + + BOOL isInMemoryCache = ([self.imageCache imageFromMemoryCacheForKey:key] != nil); + + if (isInMemoryCache) { + // making sure we call the completion block on the main queue + dispatch_async(dispatch_get_main_queue(), ^{ + if (completionBlock) { + completionBlock(YES); + } + }); + return; + } + + [self.imageCache diskImageExistsWithKey:key completion:^(BOOL isInDiskCache) { + // the completion block of checkDiskCacheForImageWithKey:completion: is always called on the main queue, no need to further dispatch + if (completionBlock) { + completionBlock(isInDiskCache); + } + }]; +} + +- (void)diskImageExistsForURL:(NSURL *)url + completion:(SDWebImageCheckCacheCompletionBlock)completionBlock { + NSString *key = [self cacheKeyForURL:url]; + + [self.imageCache diskImageExistsWithKey:key completion:^(BOOL isInDiskCache) { + // the completion block of checkDiskCacheForImageWithKey:completion: is always called on the main queue, no need to further dispatch + if (completionBlock) { + completionBlock(isInDiskCache); + } + }]; +} + +- (id )downloadImageWithURL:(NSURL *)url + options:(SDWebImageOptions)options + progress:(SDWebImageDownloaderProgressBlock)progressBlock + completed:(SDWebImageCompletionWithFinishedBlock)completedBlock { + // Invoking this method without a completedBlock is pointless + NSAssert(completedBlock != nil, @"If you mean to prefetch the image, use -[SDWebImagePrefetcher prefetchURLs] instead"); + + // Very common mistake is to send the URL using NSString object instead of NSURL. For some strange reason, XCode won't + // throw any warning for this type mismatch. Here we failsafe this error by allowing URLs to be passed as NSString. + if ([url isKindOfClass:NSString.class]) { + url = [NSURL URLWithString:(NSString *)url]; + } + + // Prevents app crashing on argument type error like sending NSNull instead of NSURL + if (![url isKindOfClass:NSURL.class]) { + url = nil; + } + + __block SDWebImageCombinedOperation *operation = [SDWebImageCombinedOperation new]; + __weak SDWebImageCombinedOperation *weakOperation = operation; + + BOOL isFailedUrl = NO; + @synchronized (self.failedURLs) { + isFailedUrl = [self.failedURLs containsObject:url]; + } + + if (url.absoluteString.length == 0 || (!(options & SDWebImageRetryFailed) && isFailedUrl)) { + dispatch_main_sync_safe(^{ + NSError *error = [NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorFileDoesNotExist userInfo:nil]; + completedBlock(nil, error, SDImageCacheTypeNone, YES, url); + }); + return operation; + } + + @synchronized (self.runningOperations) { + [self.runningOperations addObject:operation]; + } + NSString *key = [self cacheKeyForURL:url]; + + operation.cacheOperation = [self.imageCache queryDiskCacheForKey:key done:^(UIImage *image, SDImageCacheType cacheType) { + if (operation.isCancelled) { + @synchronized (self.runningOperations) { + [self.runningOperations removeObject:operation]; + } + + return; + } + + if ((!image || options & SDWebImageRefreshCached) && (![self.delegate respondsToSelector:@selector(imageManager:shouldDownloadImageForURL:)] || [self.delegate imageManager:self shouldDownloadImageForURL:url])) { + if (image && options & SDWebImageRefreshCached) { + dispatch_main_sync_safe(^{ + // If image was found in the cache but SDWebImageRefreshCached is provided, notify about the cached image + // AND try to re-download it in order to let a chance to NSURLCache to refresh it from server. + completedBlock(image, nil, cacheType, YES, url); + }); + } + + // download if no image or requested to refresh anyway, and download allowed by delegate + SDWebImageDownloaderOptions downloaderOptions = 0; + if (options & SDWebImageLowPriority) downloaderOptions |= SDWebImageDownloaderLowPriority; + if (options & SDWebImageProgressiveDownload) downloaderOptions |= SDWebImageDownloaderProgressiveDownload; + if (options & SDWebImageRefreshCached) downloaderOptions |= SDWebImageDownloaderUseNSURLCache; + if (options & SDWebImageContinueInBackground) downloaderOptions |= SDWebImageDownloaderContinueInBackground; + if (options & SDWebImageHandleCookies) downloaderOptions |= SDWebImageDownloaderHandleCookies; + if (options & SDWebImageAllowInvalidSSLCertificates) downloaderOptions |= SDWebImageDownloaderAllowInvalidSSLCertificates; + if (options & SDWebImageHighPriority) downloaderOptions |= SDWebImageDownloaderHighPriority; + if (image && options & SDWebImageRefreshCached) { + // force progressive off if image already cached but forced refreshing + downloaderOptions &= ~SDWebImageDownloaderProgressiveDownload; + // ignore image read from NSURLCache if image if cached but force refreshing + downloaderOptions |= SDWebImageDownloaderIgnoreCachedResponse; + } + id subOperation = [self.imageDownloader downloadImageWithURL:url options:downloaderOptions progress:progressBlock completed:^(UIImage *downloadedImage, NSData *data, NSError *error, BOOL finished) { + __strong __typeof(weakOperation) strongOperation = weakOperation; + if (!strongOperation || strongOperation.isCancelled) { + // Do nothing if the operation was cancelled + // See #699 for more details + // if we would call the completedBlock, there could be a race condition between this block and another completedBlock for the same object, so if this one is called second, we will overwrite the new data + } + else if (error) { + dispatch_main_sync_safe(^{ + if (strongOperation && !strongOperation.isCancelled) { + completedBlock(nil, error, SDImageCacheTypeNone, finished, url); + } + }); + + if ( error.code != NSURLErrorNotConnectedToInternet + && error.code != NSURLErrorCancelled + && error.code != NSURLErrorTimedOut + && error.code != NSURLErrorInternationalRoamingOff + && error.code != NSURLErrorDataNotAllowed + && error.code != NSURLErrorCannotFindHost + && error.code != NSURLErrorCannotConnectToHost) { + @synchronized (self.failedURLs) { + [self.failedURLs addObject:url]; + } + } + } + else { + if ((options & SDWebImageRetryFailed)) { + @synchronized (self.failedURLs) { + [self.failedURLs removeObject:url]; + } + } + + BOOL cacheOnDisk = !(options & SDWebImageCacheMemoryOnly); + + if (options & SDWebImageRefreshCached && image && !downloadedImage) { + // Image refresh hit the NSURLCache cache, do not call the completion block + } + else if (downloadedImage && (!downloadedImage.images || (options & SDWebImageTransformAnimatedImage)) && [self.delegate respondsToSelector:@selector(imageManager:transformDownloadedImage:withURL:)]) { + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{ + UIImage *transformedImage = [self.delegate imageManager:self transformDownloadedImage:downloadedImage withURL:url]; + + if (transformedImage && finished) { + BOOL imageWasTransformed = ![transformedImage isEqual:downloadedImage]; + [self.imageCache storeImage:transformedImage recalculateFromImage:imageWasTransformed imageData:(imageWasTransformed ? nil : data) forKey:key toDisk:cacheOnDisk]; + } + + dispatch_main_sync_safe(^{ + if (strongOperation && !strongOperation.isCancelled) { + completedBlock(transformedImage, nil, SDImageCacheTypeNone, finished, url); + } + }); + }); + } + else { + if (downloadedImage && finished) { + [self.imageCache storeImage:downloadedImage recalculateFromImage:NO imageData:data forKey:key toDisk:cacheOnDisk]; + } + + dispatch_main_sync_safe(^{ + if (strongOperation && !strongOperation.isCancelled) { + completedBlock(downloadedImage, nil, SDImageCacheTypeNone, finished, url); + } + }); + } + } + + if (finished) { + @synchronized (self.runningOperations) { + if (strongOperation) { + [self.runningOperations removeObject:strongOperation]; + } + } + } + }]; + operation.cancelBlock = ^{ + [subOperation cancel]; + + @synchronized (self.runningOperations) { + __strong __typeof(weakOperation) strongOperation = weakOperation; + if (strongOperation) { + [self.runningOperations removeObject:strongOperation]; + } + } + }; + } + else if (image) { + dispatch_main_sync_safe(^{ + __strong __typeof(weakOperation) strongOperation = weakOperation; + if (strongOperation && !strongOperation.isCancelled) { + completedBlock(image, nil, cacheType, YES, url); + } + }); + @synchronized (self.runningOperations) { + [self.runningOperations removeObject:operation]; + } + } + else { + // Image not in cache and download disallowed by delegate + dispatch_main_sync_safe(^{ + __strong __typeof(weakOperation) strongOperation = weakOperation; + if (strongOperation && !weakOperation.isCancelled) { + completedBlock(nil, nil, SDImageCacheTypeNone, YES, url); + } + }); + @synchronized (self.runningOperations) { + [self.runningOperations removeObject:operation]; + } + } + }]; + + return operation; +} + +- (void)saveImageToCache:(UIImage *)image forURL:(NSURL *)url { + if (image && url) { + NSString *key = [self cacheKeyForURL:url]; + [self.imageCache storeImage:image forKey:key toDisk:YES]; + } +} + +- (void)cancelAll { + @synchronized (self.runningOperations) { + NSArray *copiedOperations = [self.runningOperations copy]; + [copiedOperations makeObjectsPerformSelector:@selector(cancel)]; + [self.runningOperations removeObjectsInArray:copiedOperations]; + } +} + +- (BOOL)isRunning { + BOOL isRunning = NO; + @synchronized(self.runningOperations) { + isRunning = (self.runningOperations.count > 0); + } + return isRunning; +} + +@end + + +@implementation SDWebImageCombinedOperation + +- (void)setCancelBlock:(SDWebImageNoParamsBlock)cancelBlock { + // check if the operation is already cancelled, then we just call the cancelBlock + if (self.isCancelled) { + if (cancelBlock) { + cancelBlock(); + } + _cancelBlock = nil; // don't forget to nil the cancelBlock, otherwise we will get crashes + } else { + _cancelBlock = [cancelBlock copy]; + } +} + +- (void)cancel { + self.cancelled = YES; + if (self.cacheOperation) { + [self.cacheOperation cancel]; + self.cacheOperation = nil; + } + if (self.cancelBlock) { + self.cancelBlock(); + + // TODO: this is a temporary fix to #809. + // Until we can figure the exact cause of the crash, going with the ivar instead of the setter +// self.cancelBlock = nil; + _cancelBlock = nil; + } +} + +@end + + +@implementation SDWebImageManager (Deprecated) + +// deprecated method, uses the non deprecated method +// adapter for the completion block +- (id )downloadWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedWithFinishedBlock)completedBlock { + return [self downloadImageWithURL:url + options:options + progress:progressBlock + completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { + if (completedBlock) { + completedBlock(image, error, cacheType, finished); + } + }]; +} + +@end diff --git a/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/SDWebImageOperation.h b/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/SDWebImageOperation.h new file mode 100644 index 00000000..71094ee3 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/SDWebImageOperation.h @@ -0,0 +1,15 @@ +/* + * This file is part of the SDWebImage package. + * (c) Olivier Poitrey + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +#import + +@protocol SDWebImageOperation + +- (void)cancel; + +@end diff --git a/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/SDWebImagePrefetcher.h b/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/SDWebImagePrefetcher.h new file mode 100644 index 00000000..6c31b15f --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/SDWebImagePrefetcher.h @@ -0,0 +1,108 @@ +/* + * This file is part of the SDWebImage package. + * (c) Olivier Poitrey + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +#import +#import "SDWebImageManager.h" + +@class SDWebImagePrefetcher; + +@protocol SDWebImagePrefetcherDelegate + +@optional + +/** + * Called when an image was prefetched. + * + * @param imagePrefetcher The current image prefetcher + * @param imageURL The image url that was prefetched + * @param finishedCount The total number of images that were prefetched (successful or not) + * @param totalCount The total number of images that were to be prefetched + */ +- (void)imagePrefetcher:(SDWebImagePrefetcher *)imagePrefetcher didPrefetchURL:(NSURL *)imageURL finishedCount:(NSUInteger)finishedCount totalCount:(NSUInteger)totalCount; + +/** + * Called when all images are prefetched. + * @param imagePrefetcher The current image prefetcher + * @param totalCount The total number of images that were prefetched (whether successful or not) + * @param skippedCount The total number of images that were skipped + */ +- (void)imagePrefetcher:(SDWebImagePrefetcher *)imagePrefetcher didFinishWithTotalCount:(NSUInteger)totalCount skippedCount:(NSUInteger)skippedCount; + +@end + +typedef void(^SDWebImagePrefetcherProgressBlock)(NSUInteger noOfFinishedUrls, NSUInteger noOfTotalUrls); +typedef void(^SDWebImagePrefetcherCompletionBlock)(NSUInteger noOfFinishedUrls, NSUInteger noOfSkippedUrls); + +/** + * Prefetch some URLs in the cache for future use. Images are downloaded in low priority. + */ +@interface SDWebImagePrefetcher : NSObject + +/** + * The web image manager + */ +@property (strong, nonatomic, readonly) SDWebImageManager *manager; + +/** + * Maximum number of URLs to prefetch at the same time. Defaults to 3. + */ +@property (nonatomic, assign) NSUInteger maxConcurrentDownloads; + +/** + * SDWebImageOptions for prefetcher. Defaults to SDWebImageLowPriority. + */ +@property (nonatomic, assign) SDWebImageOptions options; + +/** + * Queue options for Prefetcher. Defaults to Main Queue. + */ +@property (nonatomic, assign) dispatch_queue_t prefetcherQueue; + +@property (weak, nonatomic) id delegate; + +/** + * Return the global image prefetcher instance. + */ ++ (SDWebImagePrefetcher *)sharedImagePrefetcher; + +/** + * Allows you to instantiate a prefetcher with any arbitrary image manager. + */ +- (id)initWithImageManager:(SDWebImageManager *)manager; + +/** + * Assign list of URLs to let SDWebImagePrefetcher to queue the prefetching, + * currently one image is downloaded at a time, + * and skips images for failed downloads and proceed to the next image in the list + * + * @param urls list of URLs to prefetch + */ +- (void)prefetchURLs:(NSArray *)urls; + +/** + * Assign list of URLs to let SDWebImagePrefetcher to queue the prefetching, + * currently one image is downloaded at a time, + * and skips images for failed downloads and proceed to the next image in the list + * + * @param urls list of URLs to prefetch + * @param progressBlock block to be called when progress updates; + * first parameter is the number of completed (successful or not) requests, + * second parameter is the total number of images originally requested to be prefetched + * @param completionBlock block to be called when prefetching is completed + * first param is the number of completed (successful or not) requests, + * second parameter is the number of skipped requests + */ +- (void)prefetchURLs:(NSArray *)urls progress:(SDWebImagePrefetcherProgressBlock)progressBlock completed:(SDWebImagePrefetcherCompletionBlock)completionBlock; + +/** + * Remove and cancel queued list + */ +- (void)cancelPrefetching; + + +@end diff --git a/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/SDWebImagePrefetcher.m b/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/SDWebImagePrefetcher.m new file mode 100644 index 00000000..f518d441 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/SDWebImagePrefetcher.m @@ -0,0 +1,140 @@ +/* + * This file is part of the SDWebImage package. + * (c) Olivier Poitrey + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +#import "SDWebImagePrefetcher.h" + +@interface SDWebImagePrefetcher () + +@property (strong, nonatomic) SDWebImageManager *manager; +@property (strong, nonatomic) NSArray *prefetchURLs; +@property (assign, nonatomic) NSUInteger requestedCount; +@property (assign, nonatomic) NSUInteger skippedCount; +@property (assign, nonatomic) NSUInteger finishedCount; +@property (assign, nonatomic) NSTimeInterval startedTime; +@property (copy, nonatomic) SDWebImagePrefetcherCompletionBlock completionBlock; +@property (copy, nonatomic) SDWebImagePrefetcherProgressBlock progressBlock; + +@end + +@implementation SDWebImagePrefetcher + ++ (SDWebImagePrefetcher *)sharedImagePrefetcher { + static dispatch_once_t once; + static id instance; + dispatch_once(&once, ^{ + instance = [self new]; + }); + return instance; +} + +- (id)init { + return [self initWithImageManager:[SDWebImageManager new]]; +} + +- (id)initWithImageManager:(SDWebImageManager *)manager { + if ((self = [super init])) { + _manager = manager; + _options = SDWebImageLowPriority; + _prefetcherQueue = dispatch_get_main_queue(); + self.maxConcurrentDownloads = 3; + } + return self; +} + +- (void)setMaxConcurrentDownloads:(NSUInteger)maxConcurrentDownloads { + self.manager.imageDownloader.maxConcurrentDownloads = maxConcurrentDownloads; +} + +- (NSUInteger)maxConcurrentDownloads { + return self.manager.imageDownloader.maxConcurrentDownloads; +} + +- (void)startPrefetchingAtIndex:(NSUInteger)index { + if (index >= self.prefetchURLs.count) return; + self.requestedCount++; + [self.manager downloadImageWithURL:self.prefetchURLs[index] options:self.options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { + if (!finished) return; + self.finishedCount++; + + if (image) { + if (self.progressBlock) { + self.progressBlock(self.finishedCount,[self.prefetchURLs count]); + } + } + else { + if (self.progressBlock) { + self.progressBlock(self.finishedCount,[self.prefetchURLs count]); + } + // Add last failed + self.skippedCount++; + } + if ([self.delegate respondsToSelector:@selector(imagePrefetcher:didPrefetchURL:finishedCount:totalCount:)]) { + [self.delegate imagePrefetcher:self + didPrefetchURL:self.prefetchURLs[index] + finishedCount:self.finishedCount + totalCount:self.prefetchURLs.count + ]; + } + if (self.prefetchURLs.count > self.requestedCount) { + dispatch_async(self.prefetcherQueue, ^{ + [self startPrefetchingAtIndex:self.requestedCount]; + }); + } else if (self.finishedCount == self.requestedCount) { + [self reportStatus]; + if (self.completionBlock) { + self.completionBlock(self.finishedCount, self.skippedCount); + self.completionBlock = nil; + } + self.progressBlock = nil; + } + }]; +} + +- (void)reportStatus { + NSUInteger total = [self.prefetchURLs count]; + if ([self.delegate respondsToSelector:@selector(imagePrefetcher:didFinishWithTotalCount:skippedCount:)]) { + [self.delegate imagePrefetcher:self + didFinishWithTotalCount:(total - self.skippedCount) + skippedCount:self.skippedCount + ]; + } +} + +- (void)prefetchURLs:(NSArray *)urls { + [self prefetchURLs:urls progress:nil completed:nil]; +} + +- (void)prefetchURLs:(NSArray *)urls progress:(SDWebImagePrefetcherProgressBlock)progressBlock completed:(SDWebImagePrefetcherCompletionBlock)completionBlock { + [self cancelPrefetching]; // Prevent duplicate prefetch request + self.startedTime = CFAbsoluteTimeGetCurrent(); + self.prefetchURLs = urls; + self.completionBlock = completionBlock; + self.progressBlock = progressBlock; + + if (urls.count == 0) { + if (completionBlock) { + completionBlock(0,0); + } + } else { + // Starts prefetching from the very first image on the list with the max allowed concurrency + NSUInteger listCount = self.prefetchURLs.count; + for (NSUInteger i = 0; i < self.maxConcurrentDownloads && self.requestedCount < listCount; i++) { + [self startPrefetchingAtIndex:i]; + } + } +} + +- (void)cancelPrefetching { + self.prefetchURLs = nil; + self.skippedCount = 0; + self.requestedCount = 0; + self.finishedCount = 0; + [self.manager cancelAll]; +} + +@end diff --git a/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/UIButton+WebCache.h b/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/UIButton+WebCache.h new file mode 100644 index 00000000..ecf5ced3 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/UIButton+WebCache.h @@ -0,0 +1,229 @@ +/* + * This file is part of the SDWebImage package. + * (c) Olivier Poitrey + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +#import "SDWebImageCompat.h" +#import "SDWebImageManager.h" + +/** + * Integrates SDWebImage async downloading and caching of remote images with UIButtonView. + */ +@interface UIButton (WebCache) + +/** + * Get the current image URL. + */ +- (NSURL *)sd_currentImageURL; + +/** + * Get the image URL for a control state. + * + * @param state Which state you want to know the URL for. The values are described in UIControlState. + */ +- (NSURL *)sd_imageURLForState:(UIControlState)state; + +/** + * Set the imageView `image` with an `url`. + * + * The download is asynchronous and cached. + * + * @param url The url for the image. + * @param state The state that uses the specified title. The values are described in UIControlState. + */ +- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state; + +/** + * Set the imageView `image` with an `url` and a placeholder. + * + * The download is asynchronous and cached. + * + * @param url The url for the image. + * @param state The state that uses the specified title. The values are described in UIControlState. + * @param placeholder The image to be set initially, until the image request finishes. + * @see sd_setImageWithURL:placeholderImage:options: + */ +- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder; + +/** + * Set the imageView `image` with an `url`, placeholder and custom options. + * + * The download is asynchronous and cached. + * + * @param url The url for the image. + * @param state The state that uses the specified title. The values are described in UIControlState. + * @param placeholder The image to be set initially, until the image request finishes. + * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. + */ +- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options; + +/** + * Set the imageView `image` with an `url`. + * + * The download is asynchronous and cached. + * + * @param url The url for the image. + * @param state The state that uses the specified title. The values are described in UIControlState. + * @param completedBlock A block called when operation has been completed. This block has no return value + * and takes the requested UIImage as first parameter. In case of error the image parameter + * is nil and the second parameter may contain an NSError. The third parameter is a Boolean + * indicating if the image was retrieved from the local cache or from the network. + * The fourth parameter is the original image url. + */ +- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletionBlock)completedBlock; + +/** + * Set the imageView `image` with an `url`, placeholder. + * + * The download is asynchronous and cached. + * + * @param url The url for the image. + * @param state The state that uses the specified title. The values are described in UIControlState. + * @param placeholder The image to be set initially, until the image request finishes. + * @param completedBlock A block called when operation has been completed. This block has no return value + * and takes the requested UIImage as first parameter. In case of error the image parameter + * is nil and the second parameter may contain an NSError. The third parameter is a Boolean + * indicating if the image was retrieved from the local cache or from the network. + * The fourth parameter is the original image url. + */ +- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock; + +/** + * Set the imageView `image` with an `url`, placeholder and custom options. + * + * The download is asynchronous and cached. + * + * @param url The url for the image. + * @param state The state that uses the specified title. The values are described in UIControlState. + * @param placeholder The image to be set initially, until the image request finishes. + * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. + * @param completedBlock A block called when operation has been completed. This block has no return value + * and takes the requested UIImage as first parameter. In case of error the image parameter + * is nil and the second parameter may contain an NSError. The third parameter is a Boolean + * indicating if the image was retrieved from the local cache or from the network. + * The fourth parameter is the original image url. + */ +- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock; + +/** + * Set the backgroundImageView `image` with an `url`. + * + * The download is asynchronous and cached. + * + * @param url The url for the image. + * @param state The state that uses the specified title. The values are described in UIControlState. + */ +- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state; + +/** + * Set the backgroundImageView `image` with an `url` and a placeholder. + * + * The download is asynchronous and cached. + * + * @param url The url for the image. + * @param state The state that uses the specified title. The values are described in UIControlState. + * @param placeholder The image to be set initially, until the image request finishes. + * @see sd_setImageWithURL:placeholderImage:options: + */ +- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder; + +/** + * Set the backgroundImageView `image` with an `url`, placeholder and custom options. + * + * The download is asynchronous and cached. + * + * @param url The url for the image. + * @param state The state that uses the specified title. The values are described in UIControlState. + * @param placeholder The image to be set initially, until the image request finishes. + * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. + */ +- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options; + +/** + * Set the backgroundImageView `image` with an `url`. + * + * The download is asynchronous and cached. + * + * @param url The url for the image. + * @param state The state that uses the specified title. The values are described in UIControlState. + * @param completedBlock A block called when operation has been completed. This block has no return value + * and takes the requested UIImage as first parameter. In case of error the image parameter + * is nil and the second parameter may contain an NSError. The third parameter is a Boolean + * indicating if the image was retrieved from the local cache or from the network. + * The fourth parameter is the original image url. + */ +- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletionBlock)completedBlock; + +/** + * Set the backgroundImageView `image` with an `url`, placeholder. + * + * The download is asynchronous and cached. + * + * @param url The url for the image. + * @param state The state that uses the specified title. The values are described in UIControlState. + * @param placeholder The image to be set initially, until the image request finishes. + * @param completedBlock A block called when operation has been completed. This block has no return value + * and takes the requested UIImage as first parameter. In case of error the image parameter + * is nil and the second parameter may contain an NSError. The third parameter is a Boolean + * indicating if the image was retrieved from the local cache or from the network. + * The fourth parameter is the original image url. + */ +- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock; + +/** + * Set the backgroundImageView `image` with an `url`, placeholder and custom options. + * + * The download is asynchronous and cached. + * + * @param url The url for the image. + * @param placeholder The image to be set initially, until the image request finishes. + * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. + * @param completedBlock A block called when operation has been completed. This block has no return value + * and takes the requested UIImage as first parameter. In case of error the image parameter + * is nil and the second parameter may contain an NSError. The third parameter is a Boolean + * indicating if the image was retrieved from the local cache or from the network. + * The fourth parameter is the original image url. + */ +- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock; + +/** + * Cancel the current image download + */ +- (void)sd_cancelImageLoadForState:(UIControlState)state; + +/** + * Cancel the current backgroundImage download + */ +- (void)sd_cancelBackgroundImageLoadForState:(UIControlState)state; + +@end + + +@interface UIButton (WebCacheDeprecated) + +- (NSURL *)currentImageURL __deprecated_msg("Use `sd_currentImageURL`"); +- (NSURL *)imageURLForState:(UIControlState)state __deprecated_msg("Use `sd_imageURLForState:`"); + +- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:forState:`"); +- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:forState:placeholderImage:`"); +- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:forState:placeholderImage:options:`"); + +- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:forState:completed:`"); +- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:forState:placeholderImage:completed:`"); +- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:forState:placeholderImage:options:completed:`"); + +- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state __deprecated_msg("Method deprecated. Use `sd_setBackgroundImageWithURL:forState:`"); +- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder __deprecated_msg("Method deprecated. Use `sd_setBackgroundImageWithURL:forState:placeholderImage:`"); +- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options __deprecated_msg("Method deprecated. Use `sd_setBackgroundImageWithURL:forState:placeholderImage:options:`"); + +- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setBackgroundImageWithURL:forState:completed:`"); +- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setBackgroundImageWithURL:forState:placeholderImage:completed:`"); +- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setBackgroundImageWithURL:forState:placeholderImage:options:completed:`"); + +- (void)cancelCurrentImageLoad __deprecated_msg("Use `sd_cancelImageLoadForState:`"); +- (void)cancelBackgroundImageLoadForState:(UIControlState)state __deprecated_msg("Use `sd_cancelBackgroundImageLoadForState:`"); + +@end diff --git a/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/UIButton+WebCache.m b/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/UIButton+WebCache.m new file mode 100644 index 00000000..ce2175d2 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/UIButton+WebCache.m @@ -0,0 +1,270 @@ +/* + * This file is part of the SDWebImage package. + * (c) Olivier Poitrey + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +#import "UIButton+WebCache.h" +#import "objc/runtime.h" +#import "UIView+WebCacheOperation.h" + +static char imageURLStorageKey; + +@implementation UIButton (WebCache) + +- (NSURL *)sd_currentImageURL { + NSURL *url = self.imageURLStorage[@(self.state)]; + + if (!url) { + url = self.imageURLStorage[@(UIControlStateNormal)]; + } + + return url; +} + +- (NSURL *)sd_imageURLForState:(UIControlState)state { + return self.imageURLStorage[@(state)]; +} + +- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state { + [self sd_setImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil]; +} + +- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder { + [self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:nil]; +} + +- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options { + [self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:options completed:nil]; +} + +- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletionBlock)completedBlock { + [self sd_setImageWithURL:url forState:state placeholderImage:nil options:0 completed:completedBlock]; +} + +- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock { + [self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:completedBlock]; +} + +- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock { + + [self setImage:placeholder forState:state]; + [self sd_cancelImageLoadForState:state]; + + if (!url) { + [self.imageURLStorage removeObjectForKey:@(state)]; + + dispatch_main_async_safe(^{ + if (completedBlock) { + NSError *error = [NSError errorWithDomain:SDWebImageErrorDomain code:-1 userInfo:@{NSLocalizedDescriptionKey : @"Trying to load a nil url"}]; + completedBlock(nil, error, SDImageCacheTypeNone, url); + } + }); + + return; + } + + self.imageURLStorage[@(state)] = url; + + __weak __typeof(self)wself = self; + id operation = [SDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { + if (!wself) return; + dispatch_main_sync_safe(^{ + __strong UIButton *sself = wself; + if (!sself) return; + if (image && (options & SDWebImageAvoidAutoSetImage) && completedBlock) + { + completedBlock(image, error, cacheType, url); + return; + } + else if (image) { + [sself setImage:image forState:state]; + } + if (completedBlock && finished) { + completedBlock(image, error, cacheType, url); + } + }); + }]; + [self sd_setImageLoadOperation:operation forState:state]; +} + +- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state { + [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil]; +} + +- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder { + [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:nil]; +} + +- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options { + [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:options completed:nil]; +} + +- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletionBlock)completedBlock { + [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:nil options:0 completed:completedBlock]; +} + +- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock { + [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:completedBlock]; +} + +- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock { + [self sd_cancelBackgroundImageLoadForState:state]; + + [self setBackgroundImage:placeholder forState:state]; + + if (url) { + __weak __typeof(self)wself = self; + id operation = [SDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { + if (!wself) return; + dispatch_main_sync_safe(^{ + __strong UIButton *sself = wself; + if (!sself) return; + if (image && (options & SDWebImageAvoidAutoSetImage) && completedBlock) + { + completedBlock(image, error, cacheType, url); + return; + } + else if (image) { + [sself setBackgroundImage:image forState:state]; + } + if (completedBlock && finished) { + completedBlock(image, error, cacheType, url); + } + }); + }]; + [self sd_setBackgroundImageLoadOperation:operation forState:state]; + } else { + dispatch_main_async_safe(^{ + NSError *error = [NSError errorWithDomain:SDWebImageErrorDomain code:-1 userInfo:@{NSLocalizedDescriptionKey : @"Trying to load a nil url"}]; + if (completedBlock) { + completedBlock(nil, error, SDImageCacheTypeNone, url); + } + }); + } +} + +- (void)sd_setImageLoadOperation:(id)operation forState:(UIControlState)state { + [self sd_setImageLoadOperation:operation forKey:[NSString stringWithFormat:@"UIButtonImageOperation%@", @(state)]]; +} + +- (void)sd_cancelImageLoadForState:(UIControlState)state { + [self sd_cancelImageLoadOperationWithKey:[NSString stringWithFormat:@"UIButtonImageOperation%@", @(state)]]; +} + +- (void)sd_setBackgroundImageLoadOperation:(id)operation forState:(UIControlState)state { + [self sd_setImageLoadOperation:operation forKey:[NSString stringWithFormat:@"UIButtonBackgroundImageOperation%@", @(state)]]; +} + +- (void)sd_cancelBackgroundImageLoadForState:(UIControlState)state { + [self sd_cancelImageLoadOperationWithKey:[NSString stringWithFormat:@"UIButtonBackgroundImageOperation%@", @(state)]]; +} + +- (NSMutableDictionary *)imageURLStorage { + NSMutableDictionary *storage = objc_getAssociatedObject(self, &imageURLStorageKey); + if (!storage) + { + storage = [NSMutableDictionary dictionary]; + objc_setAssociatedObject(self, &imageURLStorageKey, storage, OBJC_ASSOCIATION_RETAIN_NONATOMIC); + } + + return storage; +} + +@end + + +@implementation UIButton (WebCacheDeprecated) + +- (NSURL *)currentImageURL { + return [self sd_currentImageURL]; +} + +- (NSURL *)imageURLForState:(UIControlState)state { + return [self sd_imageURLForState:state]; +} + +- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state { + [self sd_setImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil]; +} + +- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder { + [self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:nil]; +} + +- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options { + [self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:options completed:nil]; +} + +- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletedBlock)completedBlock { + [self sd_setImageWithURL:url forState:state placeholderImage:nil options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { + if (completedBlock) { + completedBlock(image, error, cacheType); + } + }]; +} + +- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock { + [self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { + if (completedBlock) { + completedBlock(image, error, cacheType); + } + }]; +} + +- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock { + [self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:options completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { + if (completedBlock) { + completedBlock(image, error, cacheType); + } + }]; +} + +- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state { + [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil]; +} + +- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder { + [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:nil]; +} + +- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options { + [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:options completed:nil]; +} + +- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletedBlock)completedBlock { + [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:nil options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { + if (completedBlock) { + completedBlock(image, error, cacheType); + } + }]; +} + +- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock { + [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { + if (completedBlock) { + completedBlock(image, error, cacheType); + } + }]; +} + +- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock { + [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:options completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { + if (completedBlock) { + completedBlock(image, error, cacheType); + } + }]; +} + +- (void)cancelCurrentImageLoad { + // in a backwards compatible manner, cancel for current state + [self sd_cancelImageLoadForState:self.state]; +} + +- (void)cancelBackgroundImageLoadForState:(UIControlState)state { + [self sd_cancelBackgroundImageLoadForState:state]; +} + +@end diff --git a/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/UIImage+GIF.h b/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/UIImage+GIF.h new file mode 100755 index 00000000..084f4241 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/UIImage+GIF.h @@ -0,0 +1,19 @@ +// +// UIImage+GIF.h +// LBGIFImage +// +// Created by Laurin Brandner on 06.01.12. +// Copyright (c) 2012 __MyCompanyName__. All rights reserved. +// + +#import + +@interface UIImage (GIF) + ++ (UIImage *)sd_animatedGIFNamed:(NSString *)name; + ++ (UIImage *)sd_animatedGIFWithData:(NSData *)data; + +- (UIImage *)sd_animatedImageByScalingAndCroppingToSize:(CGSize)size; + +@end diff --git a/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/UIImage+GIF.m b/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/UIImage+GIF.m new file mode 100755 index 00000000..e1ded2aa --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/UIImage+GIF.m @@ -0,0 +1,158 @@ +// +// UIImage+GIF.m +// LBGIFImage +// +// Created by Laurin Brandner on 06.01.12. +// Copyright (c) 2012 __MyCompanyName__. All rights reserved. +// + +#import "UIImage+GIF.h" +#import + +@implementation UIImage (GIF) + ++ (UIImage *)sd_animatedGIFWithData:(NSData *)data { + if (!data) { + return nil; + } + + CGImageSourceRef source = CGImageSourceCreateWithData((__bridge CFDataRef)data, NULL); + + size_t count = CGImageSourceGetCount(source); + + UIImage *animatedImage; + + if (count <= 1) { + animatedImage = [[UIImage alloc] initWithData:data]; + } + else { + NSMutableArray *images = [NSMutableArray array]; + + NSTimeInterval duration = 0.0f; + + for (size_t i = 0; i < count; i++) { + CGImageRef image = CGImageSourceCreateImageAtIndex(source, i, NULL); + + duration += [self sd_frameDurationAtIndex:i source:source]; + + [images addObject:[UIImage imageWithCGImage:image scale:[UIScreen mainScreen].scale orientation:UIImageOrientationUp]]; + + CGImageRelease(image); + } + + if (!duration) { + duration = (1.0f / 10.0f) * count; + } + + animatedImage = [UIImage animatedImageWithImages:images duration:duration]; + } + + CFRelease(source); + + return animatedImage; +} + ++ (float)sd_frameDurationAtIndex:(NSUInteger)index source:(CGImageSourceRef)source { + float frameDuration = 0.1f; + CFDictionaryRef cfFrameProperties = CGImageSourceCopyPropertiesAtIndex(source, index, nil); + NSDictionary *frameProperties = (__bridge NSDictionary *)cfFrameProperties; + NSDictionary *gifProperties = frameProperties[(NSString *)kCGImagePropertyGIFDictionary]; + + NSNumber *delayTimeUnclampedProp = gifProperties[(NSString *)kCGImagePropertyGIFUnclampedDelayTime]; + if (delayTimeUnclampedProp) { + frameDuration = [delayTimeUnclampedProp floatValue]; + } + else { + + NSNumber *delayTimeProp = gifProperties[(NSString *)kCGImagePropertyGIFDelayTime]; + if (delayTimeProp) { + frameDuration = [delayTimeProp floatValue]; + } + } + + // Many annoying ads specify a 0 duration to make an image flash as quickly as possible. + // We follow Firefox's behavior and use a duration of 100 ms for any frames that specify + // a duration of <= 10 ms. See and + // for more information. + + if (frameDuration < 0.011f) { + frameDuration = 0.100f; + } + + CFRelease(cfFrameProperties); + return frameDuration; +} + ++ (UIImage *)sd_animatedGIFNamed:(NSString *)name { + CGFloat scale = [UIScreen mainScreen].scale; + + if (scale > 1.0f) { + NSString *retinaPath = [[NSBundle mainBundle] pathForResource:[name stringByAppendingString:@"@2x"] ofType:@"gif"]; + + NSData *data = [NSData dataWithContentsOfFile:retinaPath]; + + if (data) { + return [UIImage sd_animatedGIFWithData:data]; + } + + NSString *path = [[NSBundle mainBundle] pathForResource:name ofType:@"gif"]; + + data = [NSData dataWithContentsOfFile:path]; + + if (data) { + return [UIImage sd_animatedGIFWithData:data]; + } + + return [UIImage imageNamed:name]; + } + else { + NSString *path = [[NSBundle mainBundle] pathForResource:name ofType:@"gif"]; + + NSData *data = [NSData dataWithContentsOfFile:path]; + + if (data) { + return [UIImage sd_animatedGIFWithData:data]; + } + + return [UIImage imageNamed:name]; + } +} + +- (UIImage *)sd_animatedImageByScalingAndCroppingToSize:(CGSize)size { + if (CGSizeEqualToSize(self.size, size) || CGSizeEqualToSize(size, CGSizeZero)) { + return self; + } + + CGSize scaledSize = size; + CGPoint thumbnailPoint = CGPointZero; + + CGFloat widthFactor = size.width / self.size.width; + CGFloat heightFactor = size.height / self.size.height; + CGFloat scaleFactor = (widthFactor > heightFactor) ? widthFactor : heightFactor; + scaledSize.width = self.size.width * scaleFactor; + scaledSize.height = self.size.height * scaleFactor; + + if (widthFactor > heightFactor) { + thumbnailPoint.y = (size.height - scaledSize.height) * 0.5; + } + else if (widthFactor < heightFactor) { + thumbnailPoint.x = (size.width - scaledSize.width) * 0.5; + } + + NSMutableArray *scaledImages = [NSMutableArray array]; + + for (UIImage *image in self.images) { + UIGraphicsBeginImageContextWithOptions(size, NO, 0.0); + + [image drawInRect:CGRectMake(thumbnailPoint.x, thumbnailPoint.y, scaledSize.width, scaledSize.height)]; + UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); + + [scaledImages addObject:newImage]; + + UIGraphicsEndImageContext(); + } + + return [UIImage animatedImageWithImages:scaledImages duration:self.duration]; +} + +@end diff --git a/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/UIImage+MultiFormat.h b/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/UIImage+MultiFormat.h new file mode 100644 index 00000000..186ebc0a --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/UIImage+MultiFormat.h @@ -0,0 +1,15 @@ +// +// UIImage+MultiFormat.h +// SDWebImage +// +// Created by Olivier Poitrey on 07/06/13. +// Copyright (c) 2013 Dailymotion. All rights reserved. +// + +#import + +@interface UIImage (MultiFormat) + ++ (UIImage *)sd_imageWithData:(NSData *)data; + +@end diff --git a/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/UIImage+MultiFormat.m b/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/UIImage+MultiFormat.m new file mode 100644 index 00000000..a8307544 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/UIImage+MultiFormat.m @@ -0,0 +1,118 @@ +// +// UIImage+MultiFormat.m +// SDWebImage +// +// Created by Olivier Poitrey on 07/06/13. +// Copyright (c) 2013 Dailymotion. All rights reserved. +// + +#import "UIImage+MultiFormat.h" +#import "UIImage+GIF.h" +#import "NSData+ImageContentType.h" +#import + +#ifdef SD_WEBP +#import "UIImage+WebP.h" +#endif + +@implementation UIImage (MultiFormat) + ++ (UIImage *)sd_imageWithData:(NSData *)data { + if (!data) { + return nil; + } + + UIImage *image; + NSString *imageContentType = [NSData sd_contentTypeForImageData:data]; + if ([imageContentType isEqualToString:@"image/gif"]) { + image = [UIImage sd_animatedGIFWithData:data]; + } +#ifdef SD_WEBP + else if ([imageContentType isEqualToString:@"image/webp"]) + { + image = [UIImage sd_imageWithWebPData:data]; + } +#endif + else { + image = [[UIImage alloc] initWithData:data]; + UIImageOrientation orientation = [self sd_imageOrientationFromImageData:data]; + if (orientation != UIImageOrientationUp) { + image = [UIImage imageWithCGImage:image.CGImage + scale:image.scale + orientation:orientation]; + } + } + + + return image; +} + + ++(UIImageOrientation)sd_imageOrientationFromImageData:(NSData *)imageData { + UIImageOrientation result = UIImageOrientationUp; + CGImageSourceRef imageSource = CGImageSourceCreateWithData((__bridge CFDataRef)imageData, NULL); + if (imageSource) { + CFDictionaryRef properties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, NULL); + if (properties) { + CFTypeRef val; + int exifOrientation; + val = CFDictionaryGetValue(properties, kCGImagePropertyOrientation); + if (val) { + CFNumberGetValue(val, kCFNumberIntType, &exifOrientation); + result = [self sd_exifOrientationToiOSOrientation:exifOrientation]; + } // else - if it's not set it remains at up + CFRelease((CFTypeRef) properties); + } else { + //NSLog(@"NO PROPERTIES, FAIL"); + } + CFRelease(imageSource); + } + return result; +} + +#pragma mark EXIF orientation tag converter +// Convert an EXIF image orientation to an iOS one. +// reference see here: http://sylvana.net/jpegcrop/exif_orientation.html ++ (UIImageOrientation) sd_exifOrientationToiOSOrientation:(int)exifOrientation { + UIImageOrientation orientation = UIImageOrientationUp; + switch (exifOrientation) { + case 1: + orientation = UIImageOrientationUp; + break; + + case 3: + orientation = UIImageOrientationDown; + break; + + case 8: + orientation = UIImageOrientationLeft; + break; + + case 6: + orientation = UIImageOrientationRight; + break; + + case 2: + orientation = UIImageOrientationUpMirrored; + break; + + case 4: + orientation = UIImageOrientationDownMirrored; + break; + + case 5: + orientation = UIImageOrientationLeftMirrored; + break; + + case 7: + orientation = UIImageOrientationRightMirrored; + break; + default: + break; + } + return orientation; +} + + + +@end diff --git a/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/UIImageView+HighlightedWebCache.h b/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/UIImageView+HighlightedWebCache.h new file mode 100644 index 00000000..c1d8feaf --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/UIImageView+HighlightedWebCache.h @@ -0,0 +1,100 @@ +/* + * This file is part of the SDWebImage package. + * (c) Olivier Poitrey + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +#import +#import "SDWebImageCompat.h" +#import "SDWebImageManager.h" + +/** + * Integrates SDWebImage async downloading and caching of remote images with UIImageView for highlighted state. + */ +@interface UIImageView (HighlightedWebCache) + +/** + * Set the imageView `highlightedImage` with an `url`. + * + * The download is asynchronous and cached. + * + * @param url The url for the image. + */ +- (void)sd_setHighlightedImageWithURL:(NSURL *)url; + +/** + * Set the imageView `highlightedImage` with an `url` and custom options. + * + * The download is asynchronous and cached. + * + * @param url The url for the image. + * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. + */ +- (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options; + +/** + * Set the imageView `highlightedImage` with an `url`. + * + * The download is asynchronous and cached. + * + * @param url The url for the image. + * @param completedBlock A block called when operation has been completed. This block has no return value + * and takes the requested UIImage as first parameter. In case of error the image parameter + * is nil and the second parameter may contain an NSError. The third parameter is a Boolean + * indicating if the image was retrieved from the local cache or from the network. + * The fourth parameter is the original image url. + */ +- (void)sd_setHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock; + +/** + * Set the imageView `highlightedImage` with an `url` and custom options. + * + * The download is asynchronous and cached. + * + * @param url The url for the image. + * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. + * @param completedBlock A block called when operation has been completed. This block has no return value + * and takes the requested UIImage as first parameter. In case of error the image parameter + * is nil and the second parameter may contain an NSError. The third parameter is a Boolean + * indicating if the image was retrieved from the local cache or from the network. + * The fourth parameter is the original image url. + */ +- (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock; + +/** + * Set the imageView `highlightedImage` with an `url` and custom options. + * + * The download is asynchronous and cached. + * + * @param url The url for the image. + * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. + * @param progressBlock A block called while image is downloading + * @param completedBlock A block called when operation has been completed. This block has no return value + * and takes the requested UIImage as first parameter. In case of error the image parameter + * is nil and the second parameter may contain an NSError. The third parameter is a Boolean + * indicating if the image was retrieved from the local cache or from the network. + * The fourth parameter is the original image url. + */ +- (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock; + +/** + * Cancel the current download + */ +- (void)sd_cancelCurrentHighlightedImageLoad; + +@end + + +@interface UIImageView (HighlightedWebCacheDeprecated) + +- (void)setHighlightedImageWithURL:(NSURL *)url __deprecated_msg("Method deprecated. Use `sd_setHighlightedImageWithURL:`"); +- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options __deprecated_msg("Method deprecated. Use `sd_setHighlightedImageWithURL:options:`"); +- (void)setHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setHighlightedImageWithURL:completed:`"); +- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setHighlightedImageWithURL:options:completed:`"); +- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setHighlightedImageWithURL:options:progress:completed:`"); + +- (void)cancelCurrentHighlightedImageLoad __deprecated_msg("Use `sd_cancelCurrentHighlightedImageLoad`"); + +@end diff --git a/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/UIImageView+HighlightedWebCache.m b/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/UIImageView+HighlightedWebCache.m new file mode 100644 index 00000000..921134e5 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/UIImageView+HighlightedWebCache.m @@ -0,0 +1,112 @@ +/* + * This file is part of the SDWebImage package. + * (c) Olivier Poitrey + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +#import "UIImageView+HighlightedWebCache.h" +#import "UIView+WebCacheOperation.h" + +#define UIImageViewHighlightedWebCacheOperationKey @"highlightedImage" + +@implementation UIImageView (HighlightedWebCache) + +- (void)sd_setHighlightedImageWithURL:(NSURL *)url { + [self sd_setHighlightedImageWithURL:url options:0 progress:nil completed:nil]; +} + +- (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options { + [self sd_setHighlightedImageWithURL:url options:options progress:nil completed:nil]; +} + +- (void)sd_setHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock { + [self sd_setHighlightedImageWithURL:url options:0 progress:nil completed:completedBlock]; +} + +- (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock { + [self sd_setHighlightedImageWithURL:url options:options progress:nil completed:completedBlock]; +} + +- (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock { + [self sd_cancelCurrentHighlightedImageLoad]; + + if (url) { + __weak __typeof(self)wself = self; + id operation = [SDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { + if (!wself) return; + dispatch_main_sync_safe (^ + { + if (!wself) return; + if (image && (options & SDWebImageAvoidAutoSetImage) && completedBlock) + { + completedBlock(image, error, cacheType, url); + return; + } + else if (image) { + wself.highlightedImage = image; + [wself setNeedsLayout]; + } + if (completedBlock && finished) { + completedBlock(image, error, cacheType, url); + } + }); + }]; + [self sd_setImageLoadOperation:operation forKey:UIImageViewHighlightedWebCacheOperationKey]; + } else { + dispatch_main_async_safe(^{ + NSError *error = [NSError errorWithDomain:SDWebImageErrorDomain code:-1 userInfo:@{NSLocalizedDescriptionKey : @"Trying to load a nil url"}]; + if (completedBlock) { + completedBlock(nil, error, SDImageCacheTypeNone, url); + } + }); + } +} + +- (void)sd_cancelCurrentHighlightedImageLoad { + [self sd_cancelImageLoadOperationWithKey:UIImageViewHighlightedWebCacheOperationKey]; +} + +@end + + +@implementation UIImageView (HighlightedWebCacheDeprecated) + +- (void)setHighlightedImageWithURL:(NSURL *)url { + [self sd_setHighlightedImageWithURL:url options:0 progress:nil completed:nil]; +} + +- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options { + [self sd_setHighlightedImageWithURL:url options:options progress:nil completed:nil]; +} + +- (void)setHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock { + [self sd_setHighlightedImageWithURL:url options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { + if (completedBlock) { + completedBlock(image, error, cacheType); + } + }]; +} + +- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock { + [self sd_setHighlightedImageWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { + if (completedBlock) { + completedBlock(image, error, cacheType); + } + }]; +} + +- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock { + [self sd_setHighlightedImageWithURL:url options:0 progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { + if (completedBlock) { + completedBlock(image, error, cacheType); + } + }]; +} + +- (void)cancelCurrentHighlightedImageLoad { + [self sd_cancelCurrentHighlightedImageLoad]; +} + +@end diff --git a/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/UIImageView+WebCache.h b/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/UIImageView+WebCache.h new file mode 100644 index 00000000..eeb7460d --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/UIImageView+WebCache.h @@ -0,0 +1,213 @@ +/* + * This file is part of the SDWebImage package. + * (c) Olivier Poitrey + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +#import "SDWebImageCompat.h" +#import "SDWebImageManager.h" + +/** + * Integrates SDWebImage async downloading and caching of remote images with UIImageView. + * + * Usage with a UITableViewCell sub-class: + * + * @code + +#import + +... + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath +{ + static NSString *MyIdentifier = @"MyIdentifier"; + + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier]; + + if (cell == nil) { + cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier] + autorelease]; + } + + // Here we use the provided sd_setImageWithURL: method to load the web image + // Ensure you use a placeholder image otherwise cells will be initialized with no image + [cell.imageView sd_setImageWithURL:[NSURL URLWithString:@"http://example.com/image.jpg"] + placeholderImage:[UIImage imageNamed:@"placeholder"]]; + + cell.textLabel.text = @"My Text"; + return cell; +} + + * @endcode + */ +@interface UIImageView (WebCache) + +/** + * Get the current image URL. + * + * Note that because of the limitations of categories this property can get out of sync + * if you use sd_setImage: directly. + */ +- (NSURL *)sd_imageURL; + +/** + * Set the imageView `image` with an `url`. + * + * The download is asynchronous and cached. + * + * @param url The url for the image. + */ +- (void)sd_setImageWithURL:(NSURL *)url; + +/** + * Set the imageView `image` with an `url` and a placeholder. + * + * The download is asynchronous and cached. + * + * @param url The url for the image. + * @param placeholder The image to be set initially, until the image request finishes. + * @see sd_setImageWithURL:placeholderImage:options: + */ +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder; + +/** + * Set the imageView `image` with an `url`, placeholder and custom options. + * + * The download is asynchronous and cached. + * + * @param url The url for the image. + * @param placeholder The image to be set initially, until the image request finishes. + * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. + */ +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options; + +/** + * Set the imageView `image` with an `url`. + * + * The download is asynchronous and cached. + * + * @param url The url for the image. + * @param completedBlock A block called when operation has been completed. This block has no return value + * and takes the requested UIImage as first parameter. In case of error the image parameter + * is nil and the second parameter may contain an NSError. The third parameter is a Boolean + * indicating if the image was retrieved from the local cache or from the network. + * The fourth parameter is the original image url. + */ +- (void)sd_setImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock; + +/** + * Set the imageView `image` with an `url`, placeholder. + * + * The download is asynchronous and cached. + * + * @param url The url for the image. + * @param placeholder The image to be set initially, until the image request finishes. + * @param completedBlock A block called when operation has been completed. This block has no return value + * and takes the requested UIImage as first parameter. In case of error the image parameter + * is nil and the second parameter may contain an NSError. The third parameter is a Boolean + * indicating if the image was retrieved from the local cache or from the network. + * The fourth parameter is the original image url. + */ +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock; + +/** + * Set the imageView `image` with an `url`, placeholder and custom options. + * + * The download is asynchronous and cached. + * + * @param url The url for the image. + * @param placeholder The image to be set initially, until the image request finishes. + * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. + * @param completedBlock A block called when operation has been completed. This block has no return value + * and takes the requested UIImage as first parameter. In case of error the image parameter + * is nil and the second parameter may contain an NSError. The third parameter is a Boolean + * indicating if the image was retrieved from the local cache or from the network. + * The fourth parameter is the original image url. + */ +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock; + +/** + * Set the imageView `image` with an `url`, placeholder and custom options. + * + * The download is asynchronous and cached. + * + * @param url The url for the image. + * @param placeholder The image to be set initially, until the image request finishes. + * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. + * @param progressBlock A block called while image is downloading + * @param completedBlock A block called when operation has been completed. This block has no return value + * and takes the requested UIImage as first parameter. In case of error the image parameter + * is nil and the second parameter may contain an NSError. The third parameter is a Boolean + * indicating if the image was retrieved from the local cache or from the network. + * The fourth parameter is the original image url. + */ +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock; + +/** + * Set the imageView `image` with an `url` and optionally a placeholder image. + * + * The download is asynchronous and cached. + * + * @param url The url for the image. + * @param placeholder The image to be set initially, until the image request finishes. + * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. + * @param progressBlock A block called while image is downloading + * @param completedBlock A block called when operation has been completed. This block has no return value + * and takes the requested UIImage as first parameter. In case of error the image parameter + * is nil and the second parameter may contain an NSError. The third parameter is a Boolean + * indicating if the image was retrieved from the local cache or from the network. + * The fourth parameter is the original image url. + */ +- (void)sd_setImageWithPreviousCachedImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock; + +/** + * Download an array of images and starts them in an animation loop + * + * @param arrayOfURLs An array of NSURL + */ +- (void)sd_setAnimationImagesWithURLs:(NSArray *)arrayOfURLs; + +/** + * Cancel the current download + */ +- (void)sd_cancelCurrentImageLoad; + +- (void)sd_cancelCurrentAnimationImagesLoad; + +/** + * Show activity UIActivityIndicatorView + */ +- (void)setShowActivityIndicatorView:(BOOL)show; + +/** + * set desired UIActivityIndicatorViewStyle + * + * @param style The style of the UIActivityIndicatorView + */ +- (void)setIndicatorStyle:(UIActivityIndicatorViewStyle)style; + +@end + + +@interface UIImageView (WebCacheDeprecated) + +- (NSURL *)imageURL __deprecated_msg("Use `sd_imageURL`"); + +- (void)setImageWithURL:(NSURL *)url __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:`"); +- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:`"); +- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:options`"); + +- (void)setImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:completed:`"); +- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:completed:`"); +- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:options:completed:`"); +- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:options:progress:completed:`"); + +- (void)setAnimationImagesWithURLs:(NSArray *)arrayOfURLs __deprecated_msg("Use `sd_setAnimationImagesWithURLs:`"); + +- (void)cancelCurrentArrayLoad __deprecated_msg("Use `sd_cancelCurrentAnimationImagesLoad`"); + +- (void)cancelCurrentImageLoad __deprecated_msg("Use `sd_cancelCurrentImageLoad`"); + +@end diff --git a/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/UIImageView+WebCache.m b/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/UIImageView+WebCache.m new file mode 100644 index 00000000..14f425cc --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/UIImageView+WebCache.m @@ -0,0 +1,277 @@ +/* + * This file is part of the SDWebImage package. + * (c) Olivier Poitrey + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +#import "UIImageView+WebCache.h" +#import "objc/runtime.h" +#import "UIView+WebCacheOperation.h" + +static char imageURLKey; +static char TAG_ACTIVITY_INDICATOR; +static char TAG_ACTIVITY_STYLE; +static char TAG_ACTIVITY_SHOW; + +@implementation UIImageView (WebCache) + +- (void)sd_setImageWithURL:(NSURL *)url { + [self sd_setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:nil]; +} + +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder { + [self sd_setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:nil]; +} + +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options { + [self sd_setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:nil]; +} + +- (void)sd_setImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock { + [self sd_setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:completedBlock]; +} + +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock { + [self sd_setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:completedBlock]; +} + +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock { + [self sd_setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:completedBlock]; +} + +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock { + [self sd_cancelCurrentImageLoad]; + objc_setAssociatedObject(self, &imageURLKey, url, OBJC_ASSOCIATION_RETAIN_NONATOMIC); + + if (!(options & SDWebImageDelayPlaceholder)) { + dispatch_main_async_safe(^{ + self.image = placeholder; + }); + } + + if (url) { + + // check if activityView is enabled or not + if ([self showActivityIndicatorView]) { + [self addActivityIndicator]; + } + + __weak __typeof(self)wself = self; + id operation = [SDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { + [wself removeActivityIndicator]; + if (!wself) return; + dispatch_main_sync_safe(^{ + if (!wself) return; + if (image && (options & SDWebImageAvoidAutoSetImage) && completedBlock) + { + completedBlock(image, error, cacheType, url); + return; + } + else if (image) { + wself.image = image; + [wself setNeedsLayout]; + } else { + if ((options & SDWebImageDelayPlaceholder)) { + wself.image = placeholder; + [wself setNeedsLayout]; + } + } + if (completedBlock && finished) { + completedBlock(image, error, cacheType, url); + } + }); + }]; + [self sd_setImageLoadOperation:operation forKey:@"UIImageViewImageLoad"]; + } else { + dispatch_main_async_safe(^{ + [self removeActivityIndicator]; + if (completedBlock) { + NSError *error = [NSError errorWithDomain:SDWebImageErrorDomain code:-1 userInfo:@{NSLocalizedDescriptionKey : @"Trying to load a nil url"}]; + completedBlock(nil, error, SDImageCacheTypeNone, url); + } + }); + } +} + +- (void)sd_setImageWithPreviousCachedImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock { + NSString *key = [[SDWebImageManager sharedManager] cacheKeyForURL:url]; + UIImage *lastPreviousCachedImage = [[SDImageCache sharedImageCache] imageFromDiskCacheForKey:key]; + + [self sd_setImageWithURL:url placeholderImage:lastPreviousCachedImage ?: placeholder options:options progress:progressBlock completed:completedBlock]; +} + +- (NSURL *)sd_imageURL { + return objc_getAssociatedObject(self, &imageURLKey); +} + +- (void)sd_setAnimationImagesWithURLs:(NSArray *)arrayOfURLs { + [self sd_cancelCurrentAnimationImagesLoad]; + __weak __typeof(self)wself = self; + + NSMutableArray *operationsArray = [[NSMutableArray alloc] init]; + + for (NSURL *logoImageURL in arrayOfURLs) { + id operation = [SDWebImageManager.sharedManager downloadImageWithURL:logoImageURL options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { + if (!wself) return; + dispatch_main_sync_safe(^{ + __strong UIImageView *sself = wself; + [sself stopAnimating]; + if (sself && image) { + NSMutableArray *currentImages = [[sself animationImages] mutableCopy]; + if (!currentImages) { + currentImages = [[NSMutableArray alloc] init]; + } + [currentImages addObject:image]; + + sself.animationImages = currentImages; + [sself setNeedsLayout]; + } + [sself startAnimating]; + }); + }]; + [operationsArray addObject:operation]; + } + + [self sd_setImageLoadOperation:[NSArray arrayWithArray:operationsArray] forKey:@"UIImageViewAnimationImages"]; +} + +- (void)sd_cancelCurrentImageLoad { + [self sd_cancelImageLoadOperationWithKey:@"UIImageViewImageLoad"]; +} + +- (void)sd_cancelCurrentAnimationImagesLoad { + [self sd_cancelImageLoadOperationWithKey:@"UIImageViewAnimationImages"]; +} + + +#pragma mark - +- (UIActivityIndicatorView *)activityIndicator { + return (UIActivityIndicatorView *)objc_getAssociatedObject(self, &TAG_ACTIVITY_INDICATOR); +} + +- (void)setActivityIndicator:(UIActivityIndicatorView *)activityIndicator { + objc_setAssociatedObject(self, &TAG_ACTIVITY_INDICATOR, activityIndicator, OBJC_ASSOCIATION_RETAIN); +} + +- (void)setShowActivityIndicatorView:(BOOL)show{ + objc_setAssociatedObject(self, &TAG_ACTIVITY_SHOW, [NSNumber numberWithBool:show], OBJC_ASSOCIATION_RETAIN); +} + +- (BOOL)showActivityIndicatorView{ + return [objc_getAssociatedObject(self, &TAG_ACTIVITY_SHOW) boolValue]; +} + +- (void)setIndicatorStyle:(UIActivityIndicatorViewStyle)style{ + objc_setAssociatedObject(self, &TAG_ACTIVITY_STYLE, [NSNumber numberWithInt:style], OBJC_ASSOCIATION_RETAIN); +} + +- (int)getIndicatorStyle{ + return [objc_getAssociatedObject(self, &TAG_ACTIVITY_STYLE) intValue]; +} + +- (void)addActivityIndicator { + if (!self.activityIndicator) { + self.activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:[self getIndicatorStyle]]; + self.activityIndicator.translatesAutoresizingMaskIntoConstraints = NO; + + dispatch_main_async_safe(^{ + [self addSubview:self.activityIndicator]; + + [self addConstraint:[NSLayoutConstraint constraintWithItem:self.activityIndicator + attribute:NSLayoutAttributeCenterX + relatedBy:NSLayoutRelationEqual + toItem:self + attribute:NSLayoutAttributeCenterX + multiplier:1.0 + constant:0.0]]; + [self addConstraint:[NSLayoutConstraint constraintWithItem:self.activityIndicator + attribute:NSLayoutAttributeCenterY + relatedBy:NSLayoutRelationEqual + toItem:self + attribute:NSLayoutAttributeCenterY + multiplier:1.0 + constant:0.0]]; + }); + } + + dispatch_main_async_safe(^{ + [self.activityIndicator startAnimating]; + }); + +} + +- (void)removeActivityIndicator { + if (self.activityIndicator) { + [self.activityIndicator removeFromSuperview]; + self.activityIndicator = nil; + } +} + +@end + + +@implementation UIImageView (WebCacheDeprecated) + +- (NSURL *)imageURL { + return [self sd_imageURL]; +} + +- (void)setImageWithURL:(NSURL *)url { + [self sd_setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:nil]; +} + +- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder { + [self sd_setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:nil]; +} + +- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options { + [self sd_setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:nil]; +} + +- (void)setImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock { + [self sd_setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { + if (completedBlock) { + completedBlock(image, error, cacheType); + } + }]; +} + +- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock { + [self sd_setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { + if (completedBlock) { + completedBlock(image, error, cacheType); + } + }]; +} + +- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock { + [self sd_setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { + if (completedBlock) { + completedBlock(image, error, cacheType); + } + }]; +} + +- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock { + [self sd_setImageWithURL:url placeholderImage:placeholder options:options progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { + if (completedBlock) { + completedBlock(image, error, cacheType); + } + }]; +} + +- (void)cancelCurrentArrayLoad { + [self sd_cancelCurrentAnimationImagesLoad]; +} + +- (void)cancelCurrentImageLoad { + [self sd_cancelCurrentImageLoad]; +} + +- (void)setAnimationImagesWithURLs:(NSArray *)arrayOfURLs { + [self sd_setAnimationImagesWithURLs:arrayOfURLs]; +} + +@end diff --git a/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/UIView+WebCacheOperation.h b/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/UIView+WebCacheOperation.h new file mode 100644 index 00000000..67190362 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/UIView+WebCacheOperation.h @@ -0,0 +1,36 @@ +/* + * This file is part of the SDWebImage package. + * (c) Olivier Poitrey + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +#import +#import "SDWebImageManager.h" + +@interface UIView (WebCacheOperation) + +/** + * Set the image load operation (storage in a UIView based dictionary) + * + * @param operation the operation + * @param key key for storing the operation + */ +- (void)sd_setImageLoadOperation:(id)operation forKey:(NSString *)key; + +/** + * Cancel all operations for the current UIView and key + * + * @param key key for identifying the operations + */ +- (void)sd_cancelImageLoadOperationWithKey:(NSString *)key; + +/** + * Just remove the operations corresponding to the current UIView and key without cancelling them + * + * @param key key for identifying the operations + */ +- (void)sd_removeImageLoadOperationWithKey:(NSString *)key; + +@end diff --git a/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/UIView+WebCacheOperation.m b/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/UIView+WebCacheOperation.m new file mode 100644 index 00000000..92194780 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/SDWebImage/SDWebImage/UIView+WebCacheOperation.m @@ -0,0 +1,55 @@ +/* + * This file is part of the SDWebImage package. + * (c) Olivier Poitrey + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +#import "UIView+WebCacheOperation.h" +#import "objc/runtime.h" + +static char loadOperationKey; + +@implementation UIView (WebCacheOperation) + +- (NSMutableDictionary *)operationDictionary { + NSMutableDictionary *operations = objc_getAssociatedObject(self, &loadOperationKey); + if (operations) { + return operations; + } + operations = [NSMutableDictionary dictionary]; + objc_setAssociatedObject(self, &loadOperationKey, operations, OBJC_ASSOCIATION_RETAIN_NONATOMIC); + return operations; +} + +- (void)sd_setImageLoadOperation:(id)operation forKey:(NSString *)key { + [self sd_cancelImageLoadOperationWithKey:key]; + NSMutableDictionary *operationDictionary = [self operationDictionary]; + [operationDictionary setObject:operation forKey:key]; +} + +- (void)sd_cancelImageLoadOperationWithKey:(NSString *)key { + // Cancel in progress downloader from queue + NSMutableDictionary *operationDictionary = [self operationDictionary]; + id operations = [operationDictionary objectForKey:key]; + if (operations) { + if ([operations isKindOfClass:[NSArray class]]) { + for (id operation in operations) { + if (operation) { + [operation cancel]; + } + } + } else if ([operations conformsToProtocol:@protocol(SDWebImageOperation)]){ + [(id) operations cancel]; + } + [operationDictionary removeObjectForKey:key]; + } +} + +- (void)sd_removeImageLoadOperationWithKey:(NSString *)key { + NSMutableDictionary *operationDictionary = [self operationDictionary]; + [operationDictionary removeObjectForKey:key]; +} + +@end diff --git a/IOS/luaviewEx/Example/Pods/Target Support Files/LuaViewSDK/LuaViewSDK-dummy.m b/IOS/luaviewEx/Example/Pods/Target Support Files/LuaViewSDK/LuaViewSDK-dummy.m new file mode 100644 index 00000000..962a7e44 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Target Support Files/LuaViewSDK/LuaViewSDK-dummy.m @@ -0,0 +1,5 @@ +#import +@interface PodsDummy_LuaViewSDK : NSObject +@end +@implementation PodsDummy_LuaViewSDK +@end diff --git a/IOS/luaviewEx/Example/Pods/Target Support Files/LuaViewSDK/LuaViewSDK-prefix.pch b/IOS/luaviewEx/Example/Pods/Target Support Files/LuaViewSDK/LuaViewSDK-prefix.pch new file mode 100644 index 00000000..aa992a4a --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Target Support Files/LuaViewSDK/LuaViewSDK-prefix.pch @@ -0,0 +1,4 @@ +#ifdef __OBJC__ +#import +#endif + diff --git a/IOS/luaviewEx/Example/Pods/Target Support Files/LuaViewSDK/LuaViewSDK.xcconfig b/IOS/luaviewEx/Example/Pods/Target Support Files/LuaViewSDK/LuaViewSDK.xcconfig new file mode 100644 index 00000000..910cb48d --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Target Support Files/LuaViewSDK/LuaViewSDK.xcconfig @@ -0,0 +1,5 @@ +GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 +HEADER_SEARCH_PATHS = "${PODS_ROOT}/Headers/Private" "${PODS_ROOT}/Headers/Private/LuaViewSDK" "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/LuaViewSDK" "${PODS_ROOT}/Headers/Public/MJRefresh" "${PODS_ROOT}/Headers/Public/SDWebImage" "${PODS_ROOT}/Headers/Public/luaviewEx" +OTHER_LDFLAGS = -l"z" -framework "CoreGraphics" -framework "Foundation" -framework "UIKit" +PODS_ROOT = ${SRCROOT} +SKIP_INSTALL = YES \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Target Support Files/MJRefresh/MJRefresh-dummy.m b/IOS/luaviewEx/Example/Pods/Target Support Files/MJRefresh/MJRefresh-dummy.m new file mode 100644 index 00000000..d43259d2 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Target Support Files/MJRefresh/MJRefresh-dummy.m @@ -0,0 +1,5 @@ +#import +@interface PodsDummy_MJRefresh : NSObject +@end +@implementation PodsDummy_MJRefresh +@end diff --git a/IOS/luaviewEx/Example/Pods/Target Support Files/MJRefresh/MJRefresh-prefix.pch b/IOS/luaviewEx/Example/Pods/Target Support Files/MJRefresh/MJRefresh-prefix.pch new file mode 100644 index 00000000..aa992a4a --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Target Support Files/MJRefresh/MJRefresh-prefix.pch @@ -0,0 +1,4 @@ +#ifdef __OBJC__ +#import +#endif + diff --git a/IOS/luaviewEx/Example/Pods/Target Support Files/MJRefresh/MJRefresh.xcconfig b/IOS/luaviewEx/Example/Pods/Target Support Files/MJRefresh/MJRefresh.xcconfig new file mode 100644 index 00000000..1b7631df --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Target Support Files/MJRefresh/MJRefresh.xcconfig @@ -0,0 +1,4 @@ +GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 +HEADER_SEARCH_PATHS = "${PODS_ROOT}/Headers/Private" "${PODS_ROOT}/Headers/Private/MJRefresh" "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/LuaViewSDK" "${PODS_ROOT}/Headers/Public/MJRefresh" "${PODS_ROOT}/Headers/Public/SDWebImage" "${PODS_ROOT}/Headers/Public/luaviewEx" +PODS_ROOT = ${SRCROOT} +SKIP_INSTALL = YES \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Target Support Files/Pods-luaviewEx_Example/Pods-luaviewEx_Example-acknowledgements.markdown b/IOS/luaviewEx/Example/Pods/Target Support Files/Pods-luaviewEx_Example/Pods-luaviewEx_Example-acknowledgements.markdown new file mode 100644 index 00000000..a9ed34eb --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Target Support Files/Pods-luaviewEx_Example/Pods-luaviewEx_Example-acknowledgements.markdown @@ -0,0 +1,94 @@ +# Acknowledgements +This application makes use of the following third party libraries: + +## LuaViewSDK + +The MIT License (MIT) +Copyright (c) 2017 Alibaba Group +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + + +## MJRefresh + +Copyright (c) 2013-2015 MJRefresh (https://github.com/CoderMJLee/MJRefresh) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + + +## SDWebImage + +Copyright (c) 2009 Olivier Poitrey + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished +to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + + + +## luaviewEx + +Copyright (c) 2017 yechunxiao19 + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + +Generated by CocoaPods - http://cocoapods.org diff --git a/IOS/luaviewEx/Example/Pods/Target Support Files/Pods-luaviewEx_Example/Pods-luaviewEx_Example-acknowledgements.plist b/IOS/luaviewEx/Example/Pods/Target Support Files/Pods-luaviewEx_Example/Pods-luaviewEx_Example-acknowledgements.plist new file mode 100644 index 00000000..1ddef8ee --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Target Support Files/Pods-luaviewEx_Example/Pods-luaviewEx_Example-acknowledgements.plist @@ -0,0 +1,136 @@ + + + + + PreferenceSpecifiers + + + FooterText + This application makes use of the following third party libraries: + Title + Acknowledgements + Type + PSGroupSpecifier + + + FooterText + The MIT License (MIT) +Copyright (c) 2017 Alibaba Group +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + + Title + LuaViewSDK + Type + PSGroupSpecifier + + + FooterText + Copyright (c) 2013-2015 MJRefresh (https://github.com/CoderMJLee/MJRefresh) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + + Title + MJRefresh + Type + PSGroupSpecifier + + + FooterText + Copyright (c) 2009 Olivier Poitrey <rs@dailymotion.com> + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished +to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + + + Title + SDWebImage + Type + PSGroupSpecifier + + + FooterText + Copyright (c) 2017 yechunxiao19 <chunxiao.ycx@alibaba-inc.com> + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + + Title + luaviewEx + Type + PSGroupSpecifier + + + FooterText + Generated by CocoaPods - http://cocoapods.org + Title + + Type + PSGroupSpecifier + + + StringsTable + Acknowledgements + Title + Acknowledgements + + diff --git a/IOS/luaviewEx/Example/Pods/Target Support Files/Pods-luaviewEx_Example/Pods-luaviewEx_Example-dummy.m b/IOS/luaviewEx/Example/Pods/Target Support Files/Pods-luaviewEx_Example/Pods-luaviewEx_Example-dummy.m new file mode 100644 index 00000000..04a0e605 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Target Support Files/Pods-luaviewEx_Example/Pods-luaviewEx_Example-dummy.m @@ -0,0 +1,5 @@ +#import +@interface PodsDummy_Pods_luaviewEx_Example : NSObject +@end +@implementation PodsDummy_Pods_luaviewEx_Example +@end diff --git a/IOS/luaviewEx/Example/Pods/Target Support Files/Pods-luaviewEx_Example/Pods-luaviewEx_Example-frameworks.sh b/IOS/luaviewEx/Example/Pods/Target Support Files/Pods-luaviewEx_Example/Pods-luaviewEx_Example-frameworks.sh new file mode 100755 index 00000000..6f763443 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Target Support Files/Pods-luaviewEx_Example/Pods-luaviewEx_Example-frameworks.sh @@ -0,0 +1,84 @@ +#!/bin/sh +set -e + +echo "mkdir -p ${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" +mkdir -p "${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" + +SWIFT_STDLIB_PATH="${DT_TOOLCHAIN_DIR}/usr/lib/swift/${PLATFORM_NAME}" + +install_framework() +{ + if [ -r "${BUILT_PRODUCTS_DIR}/$1" ]; then + local source="${BUILT_PRODUCTS_DIR}/$1" + elif [ -r "${BUILT_PRODUCTS_DIR}/$(basename "$1")" ]; then + local source="${BUILT_PRODUCTS_DIR}/$(basename "$1")" + elif [ -r "$1" ]; then + local source="$1" + fi + + local destination="${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" + + if [ -L "${source}" ]; then + echo "Symlinked..." + source="$(readlink "${source}")" + fi + + # use filter instead of exclude so missing patterns dont' throw errors + echo "rsync -av --filter \"- CVS/\" --filter \"- .svn/\" --filter \"- .git/\" --filter \"- .hg/\" --filter \"- Headers\" --filter \"- PrivateHeaders\" --filter \"- Modules\" \"${source}\" \"${destination}\"" + rsync -av --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "${source}" "${destination}" + + local basename + basename="$(basename -s .framework "$1")" + binary="${destination}/${basename}.framework/${basename}" + if ! [ -r "$binary" ]; then + binary="${destination}/${basename}" + fi + + # Strip invalid architectures so "fat" simulator / device frameworks work on device + if [[ "$(file "$binary")" == *"dynamically linked shared library"* ]]; then + strip_invalid_archs "$binary" + fi + + # Resign the code if required by the build settings to avoid unstable apps + code_sign_if_enabled "${destination}/$(basename "$1")" + + # Embed linked Swift runtime libraries. No longer necessary as of Xcode 7. + if [ "${XCODE_VERSION_MAJOR}" -lt 7 ]; then + local swift_runtime_libs + swift_runtime_libs=$(xcrun otool -LX "$binary" | grep --color=never @rpath/libswift | sed -E s/@rpath\\/\(.+dylib\).*/\\1/g | uniq -u && exit ${PIPESTATUS[0]}) + for lib in $swift_runtime_libs; do + echo "rsync -auv \"${SWIFT_STDLIB_PATH}/${lib}\" \"${destination}\"" + rsync -auv "${SWIFT_STDLIB_PATH}/${lib}" "${destination}" + code_sign_if_enabled "${destination}/${lib}" + done + fi +} + +# Signs a framework with the provided identity +code_sign_if_enabled() { + if [ -n "${EXPANDED_CODE_SIGN_IDENTITY}" -a "${CODE_SIGNING_REQUIRED}" != "NO" -a "${CODE_SIGNING_ALLOWED}" != "NO" ]; then + # Use the current code_sign_identitiy + echo "Code Signing $1 with Identity ${EXPANDED_CODE_SIGN_IDENTITY_NAME}" + echo "/usr/bin/codesign --force --sign ${EXPANDED_CODE_SIGN_IDENTITY} --preserve-metadata=identifier,entitlements \"$1\"" + /usr/bin/codesign --force --sign ${EXPANDED_CODE_SIGN_IDENTITY} --preserve-metadata=identifier,entitlements "$1" + fi +} + +# Strip invalid architectures +strip_invalid_archs() { + binary="$1" + # Get architectures for current file + archs="$(lipo -info "$binary" | rev | cut -d ':' -f1 | rev)" + stripped="" + for arch in $archs; do + if ! [[ "${VALID_ARCHS}" == *"$arch"* ]]; then + # Strip non-valid architectures in-place + lipo -remove "$arch" -output "$binary" "$binary" || exit 1 + stripped="$stripped $arch" + fi + done + if [[ "$stripped" ]]; then + echo "Stripped $binary of architectures:$stripped" + fi +} + diff --git a/IOS/luaviewEx/Example/Pods/Target Support Files/Pods-luaviewEx_Example/Pods-luaviewEx_Example-resources.sh b/IOS/luaviewEx/Example/Pods/Target Support Files/Pods-luaviewEx_Example/Pods-luaviewEx_Example-resources.sh new file mode 100755 index 00000000..3cd211f2 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Target Support Files/Pods-luaviewEx_Example/Pods-luaviewEx_Example-resources.sh @@ -0,0 +1,103 @@ +#!/bin/sh +set -e + +mkdir -p "${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" + +RESOURCES_TO_COPY=${PODS_ROOT}/resources-to-copy-${TARGETNAME}.txt +> "$RESOURCES_TO_COPY" + +XCASSET_FILES=() + +realpath() { + DIRECTORY="$(cd "${1%/*}" && pwd)" + FILENAME="${1##*/}" + echo "$DIRECTORY/$FILENAME" +} + +install_resource() +{ + case $1 in + *.storyboard) + echo "ibtool --reference-external-strings-file --errors --warnings --notices --output-format human-readable-text --compile ${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \"$1\" .storyboard`.storyboardc ${PODS_ROOT}/$1 --sdk ${SDKROOT}" + ibtool --reference-external-strings-file --errors --warnings --notices --output-format human-readable-text --compile "${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \"$1\" .storyboard`.storyboardc" "${PODS_ROOT}/$1" --sdk "${SDKROOT}" + ;; + *.xib) + echo "ibtool --reference-external-strings-file --errors --warnings --notices --output-format human-readable-text --compile ${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \"$1\" .xib`.nib ${PODS_ROOT}/$1 --sdk ${SDKROOT}" + ibtool --reference-external-strings-file --errors --warnings --notices --output-format human-readable-text --compile "${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \"$1\" .xib`.nib" "${PODS_ROOT}/$1" --sdk "${SDKROOT}" + ;; + *.framework) + echo "mkdir -p ${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" + mkdir -p "${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" + echo "rsync -av ${PODS_ROOT}/$1 ${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" + rsync -av "${PODS_ROOT}/$1" "${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" + ;; + *.xcdatamodel) + echo "xcrun momc \"${PODS_ROOT}/$1\" \"${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$1"`.mom\"" + xcrun momc "${PODS_ROOT}/$1" "${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$1" .xcdatamodel`.mom" + ;; + *.xcdatamodeld) + echo "xcrun momc \"${PODS_ROOT}/$1\" \"${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$1" .xcdatamodeld`.momd\"" + xcrun momc "${PODS_ROOT}/$1" "${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$1" .xcdatamodeld`.momd" + ;; + *.xcmappingmodel) + echo "xcrun mapc \"${PODS_ROOT}/$1\" \"${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$1" .xcmappingmodel`.cdm\"" + xcrun mapc "${PODS_ROOT}/$1" "${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$1" .xcmappingmodel`.cdm" + ;; + *.xcassets) + ABSOLUTE_XCASSET_FILE=$(realpath "${PODS_ROOT}/$1") + XCASSET_FILES+=("$ABSOLUTE_XCASSET_FILE") + ;; + /*) + echo "$1" + echo "$1" >> "$RESOURCES_TO_COPY" + ;; + *) + echo "${PODS_ROOT}/$1" + echo "${PODS_ROOT}/$1" >> "$RESOURCES_TO_COPY" + ;; + esac +} +if [[ "$CONFIGURATION" == "Debug" ]]; then + install_resource "MJRefresh/MJRefresh/MJRefresh.bundle" + install_resource "${BUILT_PRODUCTS_DIR}/luaviewEx.bundle" +fi +if [[ "$CONFIGURATION" == "Release" ]]; then + install_resource "MJRefresh/MJRefresh/MJRefresh.bundle" + install_resource "${BUILT_PRODUCTS_DIR}/luaviewEx.bundle" +fi + +mkdir -p "${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" +rsync -avr --copy-links --no-relative --exclude '*/.svn/*' --files-from="$RESOURCES_TO_COPY" / "${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" +if [[ "${ACTION}" == "install" ]] && [[ "${SKIP_INSTALL}" == "NO" ]]; then + mkdir -p "${INSTALL_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" + rsync -avr --copy-links --no-relative --exclude '*/.svn/*' --files-from="$RESOURCES_TO_COPY" / "${INSTALL_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" +fi +rm -f "$RESOURCES_TO_COPY" + +if [[ -n "${WRAPPER_EXTENSION}" ]] && [ "`xcrun --find actool`" ] && [ -n "$XCASSET_FILES" ] +then + case "${TARGETED_DEVICE_FAMILY}" in + 1,2) + TARGET_DEVICE_ARGS="--target-device ipad --target-device iphone" + ;; + 1) + TARGET_DEVICE_ARGS="--target-device iphone" + ;; + 2) + TARGET_DEVICE_ARGS="--target-device ipad" + ;; + *) + TARGET_DEVICE_ARGS="--target-device mac" + ;; + esac + + # Find all other xcassets (this unfortunately includes those of path pods and other targets). + OTHER_XCASSETS=$(find "$PWD" -iname "*.xcassets" -type d) + while read line; do + if [[ $line != "`realpath $PODS_ROOT`*" ]]; then + XCASSET_FILES+=("$line") + fi + done <<<"$OTHER_XCASSETS" + + printf "%s\0" "${XCASSET_FILES[@]}" | xargs -0 xcrun actool --output-format human-readable-text --notices --warnings --platform "${PLATFORM_NAME}" --minimum-deployment-target "${IPHONEOS_DEPLOYMENT_TARGET}" ${TARGET_DEVICE_ARGS} --compress-pngs --compile "${BUILT_PRODUCTS_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" +fi diff --git a/IOS/luaviewEx/Example/Pods/Target Support Files/Pods-luaviewEx_Example/Pods-luaviewEx_Example.debug.xcconfig b/IOS/luaviewEx/Example/Pods/Target Support Files/Pods-luaviewEx_Example/Pods-luaviewEx_Example.debug.xcconfig new file mode 100644 index 00000000..3c6a990c --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Target Support Files/Pods-luaviewEx_Example/Pods-luaviewEx_Example.debug.xcconfig @@ -0,0 +1,6 @@ +GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 +HEADER_SEARCH_PATHS = $(inherited) "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/LuaViewSDK" "${PODS_ROOT}/Headers/Public/MJRefresh" "${PODS_ROOT}/Headers/Public/SDWebImage" "${PODS_ROOT}/Headers/Public/luaviewEx" +INFOPLIST_FILE = ../../luaviewEx/Classes/luaviewEx-info.plist +OTHER_CFLAGS = $(inherited) -isystem "${PODS_ROOT}/Headers/Public" -isystem "${PODS_ROOT}/Headers/Public/LuaViewSDK" -isystem "${PODS_ROOT}/Headers/Public/MJRefresh" -isystem "${PODS_ROOT}/Headers/Public/SDWebImage" -isystem "${PODS_ROOT}/Headers/Public/luaviewEx" +OTHER_LDFLAGS = $(inherited) -ObjC -l"LuaViewSDK" -l"MJRefresh" -l"SDWebImage" -l"luaviewEx" -l"z" -framework "CoreGraphics" -framework "Foundation" -framework "ImageIO" -framework "UIKit" +PODS_ROOT = ${SRCROOT}/Pods \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Target Support Files/Pods-luaviewEx_Example/Pods-luaviewEx_Example.release.xcconfig b/IOS/luaviewEx/Example/Pods/Target Support Files/Pods-luaviewEx_Example/Pods-luaviewEx_Example.release.xcconfig new file mode 100644 index 00000000..3c6a990c --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Target Support Files/Pods-luaviewEx_Example/Pods-luaviewEx_Example.release.xcconfig @@ -0,0 +1,6 @@ +GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 +HEADER_SEARCH_PATHS = $(inherited) "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/LuaViewSDK" "${PODS_ROOT}/Headers/Public/MJRefresh" "${PODS_ROOT}/Headers/Public/SDWebImage" "${PODS_ROOT}/Headers/Public/luaviewEx" +INFOPLIST_FILE = ../../luaviewEx/Classes/luaviewEx-info.plist +OTHER_CFLAGS = $(inherited) -isystem "${PODS_ROOT}/Headers/Public" -isystem "${PODS_ROOT}/Headers/Public/LuaViewSDK" -isystem "${PODS_ROOT}/Headers/Public/MJRefresh" -isystem "${PODS_ROOT}/Headers/Public/SDWebImage" -isystem "${PODS_ROOT}/Headers/Public/luaviewEx" +OTHER_LDFLAGS = $(inherited) -ObjC -l"LuaViewSDK" -l"MJRefresh" -l"SDWebImage" -l"luaviewEx" -l"z" -framework "CoreGraphics" -framework "Foundation" -framework "ImageIO" -framework "UIKit" +PODS_ROOT = ${SRCROOT}/Pods \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Target Support Files/Pods-luaviewEx_Example/copy-framework-resources.rb b/IOS/luaviewEx/Example/Pods/Target Support Files/Pods-luaviewEx_Example/copy-framework-resources.rb new file mode 100755 index 00000000..08383e0b --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Target Support Files/Pods-luaviewEx_Example/copy-framework-resources.rb @@ -0,0 +1,62 @@ +#!/usr/bin/env ruby +# encoding: UTF-8 + +require 'Xcodeproj' +require 'fileutils' + +Encoding.default_external = Encoding::UTF_8 +Encoding.default_internal = Encoding::UTF_8 + +current_target_name = ENV["TARGET_NAME"] +project = Xcodeproj::Project.open(ENV["PROJECT_FILE_PATH"]) + +# 分析环境变量参数 +def parse_args(args) + index = 0 + arg_list = [] + while args && args.length > 0 && args.length > index + space_index = args.index(" ", index) + space_index = -1 if space_index.nil? + arg = args[0..space_index] + if arg.count("\"") % 2 == 0 && arg.count("'") % 2 == 0 + arg_list << arg.strip + args = space_index >= 0 ? args[space_index+1..-1] : nil + index = 0 + end + end + arg_list +end + +def find_key(array, key) + for dic in array + if dic.keys[0] == key + return dic[key] + end + end +end + +current_target = project.targets.find { |target| target.name == current_target_name } + +frameworks = current_target.frameworks_build_phases.files.map{|file| file.file_ref.nil? ? "" : File.basename(file.file_ref.path) }.select { |x| File.extname(x) == ".framework"} + +FRAMEWORK_SEARCH_PATHS = [] +parse_args(ENV['FRAMEWORK_SEARCH_PATHS']).each { |arg| FRAMEWORK_SEARCH_PATHS << arg.gsub("\"", "") } + +for framework in frameworks + FRAMEWORK_SEARCH_PATHS.each do |path| + framework_path = File.join(path, framework) + if File.directory?(framework_path) + ignore_list = ["Info.plist", ".DS_Store"] + if File.directory?(File.join(framework_path, "Resources")) + list = Dir.glob(File.join(framework_path, "Resources/*")) + else + ignore_list += [File.basename(framework, '.framework'), "Headers", "PrivateHeaders", "Modules", "Versions", "_CodeSignature"] + list = Dir.glob(File.join(framework_path, "*")) + end + list.reject!{|entry| ignore_list.include?(File.basename(entry)) } + list.each { |file| puts file} + FileUtils.cp_r list, File.join(ENV["TARGET_BUILD_DIR"], ENV["UNLOCALIZED_RESOURCES_FOLDER_PATH"]) + break + end + end +end diff --git a/IOS/luaviewEx/Example/Pods/Target Support Files/SDWebImage/SDWebImage-dummy.m b/IOS/luaviewEx/Example/Pods/Target Support Files/SDWebImage/SDWebImage-dummy.m new file mode 100644 index 00000000..86d2b5f6 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Target Support Files/SDWebImage/SDWebImage-dummy.m @@ -0,0 +1,5 @@ +#import +@interface PodsDummy_SDWebImage : NSObject +@end +@implementation PodsDummy_SDWebImage +@end diff --git a/IOS/luaviewEx/Example/Pods/Target Support Files/SDWebImage/SDWebImage-prefix.pch b/IOS/luaviewEx/Example/Pods/Target Support Files/SDWebImage/SDWebImage-prefix.pch new file mode 100644 index 00000000..aa992a4a --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Target Support Files/SDWebImage/SDWebImage-prefix.pch @@ -0,0 +1,4 @@ +#ifdef __OBJC__ +#import +#endif + diff --git a/IOS/luaviewEx/Example/Pods/Target Support Files/SDWebImage/SDWebImage.xcconfig b/IOS/luaviewEx/Example/Pods/Target Support Files/SDWebImage/SDWebImage.xcconfig new file mode 100644 index 00000000..b829b7d2 --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Target Support Files/SDWebImage/SDWebImage.xcconfig @@ -0,0 +1,5 @@ +GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 +HEADER_SEARCH_PATHS = "${PODS_ROOT}/Headers/Private" "${PODS_ROOT}/Headers/Private/SDWebImage" "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/LuaViewSDK" "${PODS_ROOT}/Headers/Public/MJRefresh" "${PODS_ROOT}/Headers/Public/SDWebImage" "${PODS_ROOT}/Headers/Public/luaviewEx" +OTHER_LDFLAGS = -framework "ImageIO" +PODS_ROOT = ${SRCROOT} +SKIP_INSTALL = YES \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Pods/Target Support Files/luaviewEx/luaviewEx-dummy.m b/IOS/luaviewEx/Example/Pods/Target Support Files/luaviewEx/luaviewEx-dummy.m new file mode 100644 index 00000000..e2548d6b --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Target Support Files/luaviewEx/luaviewEx-dummy.m @@ -0,0 +1,5 @@ +#import +@interface PodsDummy_luaviewEx : NSObject +@end +@implementation PodsDummy_luaviewEx +@end diff --git a/IOS/luaviewEx/Example/Pods/Target Support Files/luaviewEx/luaviewEx-prefix.pch b/IOS/luaviewEx/Example/Pods/Target Support Files/luaviewEx/luaviewEx-prefix.pch new file mode 100644 index 00000000..aa992a4a --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Target Support Files/luaviewEx/luaviewEx-prefix.pch @@ -0,0 +1,4 @@ +#ifdef __OBJC__ +#import +#endif + diff --git a/IOS/luaviewEx/Example/Pods/Target Support Files/luaviewEx/luaviewEx.xcconfig b/IOS/luaviewEx/Example/Pods/Target Support Files/luaviewEx/luaviewEx.xcconfig new file mode 100644 index 00000000..409d103f --- /dev/null +++ b/IOS/luaviewEx/Example/Pods/Target Support Files/luaviewEx/luaviewEx.xcconfig @@ -0,0 +1,5 @@ +GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 +HEADER_SEARCH_PATHS = "${PODS_ROOT}/Headers/Private" "${PODS_ROOT}/Headers/Private/luaviewEx" "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/LuaViewSDK" "${PODS_ROOT}/Headers/Public/MJRefresh" "${PODS_ROOT}/Headers/Public/SDWebImage" "${PODS_ROOT}/Headers/Public/luaviewEx" +INFOPLIST_FILE = ../../luaviewEx/Classes/luaviewEx-info.plist +PODS_ROOT = ${SRCROOT} +SKIP_INSTALL = YES \ No newline at end of file diff --git a/IOS/luaviewEx/Example/Tests/Tests-Info.plist b/IOS/luaviewEx/Example/Tests/Tests-Info.plist new file mode 100644 index 00000000..169b6f71 --- /dev/null +++ b/IOS/luaviewEx/Example/Tests/Tests-Info.plist @@ -0,0 +1,22 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + ${EXECUTABLE_NAME} + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundlePackageType + BNDL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + + diff --git a/IOS/luaviewEx/Example/Tests/Tests-Prefix.pch b/IOS/luaviewEx/Example/Tests/Tests-Prefix.pch new file mode 100644 index 00000000..0bfb741d --- /dev/null +++ b/IOS/luaviewEx/Example/Tests/Tests-Prefix.pch @@ -0,0 +1,7 @@ +// The contents of this file are implicitly included at the beginning of every test case source file. + +#ifdef __OBJC__ + + + +#endif diff --git a/IOS/luaviewEx/Example/Tests/Tests.m b/IOS/luaviewEx/Example/Tests/Tests.m new file mode 100644 index 00000000..f6137238 --- /dev/null +++ b/IOS/luaviewEx/Example/Tests/Tests.m @@ -0,0 +1,35 @@ +// +// luaviewExTests.m +// luaviewExTests +// +// Created by yechunxiao19 on 04/06/2017. +// Copyright (c) 2017 yechunxiao19. All rights reserved. +// + +@import XCTest; + +@interface Tests : XCTestCase + +@end + +@implementation Tests + +- (void)setUp +{ + [super setUp]; + // Put setup code here. This method is called before the invocation of each test method in the class. +} + +- (void)tearDown +{ + // Put teardown code here. This method is called after the invocation of each test method in the class. + [super tearDown]; +} + +- (void)testExample +{ + XCTFail(@"No implementation for \"%s\"", __PRETTY_FUNCTION__); +} + +@end + diff --git a/IOS/luaviewEx/Example/Tests/en.lproj/InfoPlist.strings b/IOS/luaviewEx/Example/Tests/en.lproj/InfoPlist.strings new file mode 100644 index 00000000..477b28ff --- /dev/null +++ b/IOS/luaviewEx/Example/Tests/en.lproj/InfoPlist.strings @@ -0,0 +1,2 @@ +/* Localized versions of Info.plist keys */ + diff --git a/IOS/luaviewEx/Example/luaviewEx.xcodeproj/project.pbxproj b/IOS/luaviewEx/Example/luaviewEx.xcodeproj/project.pbxproj new file mode 100644 index 00000000..2a0b02cc --- /dev/null +++ b/IOS/luaviewEx/Example/luaviewEx.xcodeproj/project.pbxproj @@ -0,0 +1,613 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + 6003F58E195388D20070C39A /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6003F58D195388D20070C39A /* Foundation.framework */; }; + 6003F590195388D20070C39A /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6003F58F195388D20070C39A /* CoreGraphics.framework */; }; + 6003F592195388D20070C39A /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6003F591195388D20070C39A /* UIKit.framework */; }; + 6003F598195388D20070C39A /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 6003F596195388D20070C39A /* InfoPlist.strings */; }; + 6003F59A195388D20070C39A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 6003F599195388D20070C39A /* main.m */; }; + 6003F59E195388D20070C39A /* LVAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 6003F59D195388D20070C39A /* LVAppDelegate.m */; }; + 6003F5A9195388D20070C39A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6003F5A8195388D20070C39A /* Images.xcassets */; }; + 6003F5B0195388D20070C39A /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6003F5AF195388D20070C39A /* XCTest.framework */; }; + 6003F5B1195388D20070C39A /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6003F58D195388D20070C39A /* Foundation.framework */; }; + 6003F5B2195388D20070C39A /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6003F591195388D20070C39A /* UIKit.framework */; }; + 6003F5BA195388D20070C39A /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 6003F5B8195388D20070C39A /* InfoPlist.strings */; }; + 6003F5BC195388D20070C39A /* Tests.m in Sources */ = {isa = PBXBuildFile; fileRef = 6003F5BB195388D20070C39A /* Tests.m */; }; + 71719F9F1E33DC2100824A3D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 71719F9D1E33DC2100824A3D /* LaunchScreen.storyboard */; }; + 7FDFEA88C11F435A5F66A774 /* libPods-luaviewEx_Example.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 9B13F30441A92564B1C09264 /* libPods-luaviewEx_Example.a */; }; + DC8E1D021E962C8D008A8064 /* App.lua in Resources */ = {isa = PBXBuildFile; fileRef = DC8E1CFB1E962C8D008A8064 /* App.lua */; }; + DC8E1D031E962C8D008A8064 /* app.xml in Resources */ = {isa = PBXBuildFile; fileRef = DC8E1CFC1E962C8D008A8064 /* app.xml */; }; + DC8E1D041E962C8D008A8064 /* demo.xml in Resources */ = {isa = PBXBuildFile; fileRef = DC8E1CFD1E962C8D008A8064 /* demo.xml */; }; + DC8E1D061E962C8D008A8064 /* luaview.png in Resources */ = {isa = PBXBuildFile; fileRef = DC8E1CFF1E962C8D008A8064 /* luaview.png */; }; + DC8E1D071E962C8D008A8064 /* sample in Resources */ = {isa = PBXBuildFile; fileRef = DC8E1D001E962C8D008A8064 /* sample */; }; + DC8E1D081E962C8D008A8064 /* widget in Resources */ = {isa = PBXBuildFile; fileRef = DC8E1D011E962C8D008A8064 /* widget */; }; +/* End PBXBuildFile section */ + +/* Begin PBXContainerItemProxy section */ + 6003F5B3195388D20070C39A /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 6003F582195388D10070C39A /* Project object */; + proxyType = 1; + remoteGlobalIDString = 6003F589195388D20070C39A; + remoteInfo = luaviewEx; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXFileReference section */ + 37896E6B4FE8F9834CD9D570 /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = LICENSE; path = ../LICENSE; sourceTree = ""; }; + 3C2B35DFDC5345C279F8AB5C /* luaviewEx.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = luaviewEx.podspec; path = ../luaviewEx.podspec; sourceTree = ""; }; + 6003F58A195388D20070C39A /* luaviewEx_Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = luaviewEx_Example.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 6003F58D195388D20070C39A /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; + 6003F58F195388D20070C39A /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; + 6003F591195388D20070C39A /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; + 6003F595195388D20070C39A /* luaviewEx-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "luaviewEx-Info.plist"; sourceTree = ""; }; + 6003F597195388D20070C39A /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; + 6003F599195388D20070C39A /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; + 6003F59B195388D20070C39A /* luaviewEx-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "luaviewEx-Prefix.pch"; sourceTree = ""; }; + 6003F59C195388D20070C39A /* LVAppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LVAppDelegate.h; sourceTree = ""; }; + 6003F59D195388D20070C39A /* LVAppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LVAppDelegate.m; sourceTree = ""; }; + 6003F5A8195388D20070C39A /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; + 6003F5AE195388D20070C39A /* luaviewEx_Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = luaviewEx_Tests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + 6003F5AF195388D20070C39A /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; }; + 6003F5B7195388D20070C39A /* Tests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Tests-Info.plist"; sourceTree = ""; }; + 6003F5B9195388D20070C39A /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; + 6003F5BB195388D20070C39A /* Tests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = Tests.m; sourceTree = ""; }; + 606FC2411953D9B200FFA9A0 /* Tests-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Tests-Prefix.pch"; sourceTree = ""; }; + 71719F9E1E33DC2100824A3D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; + 7E6F87FB063AB9201AA9EF27 /* Pods-luaviewEx_Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-luaviewEx_Example.debug.xcconfig"; path = "Pods/Target Support Files/Pods-luaviewEx_Example/Pods-luaviewEx_Example.debug.xcconfig"; sourceTree = ""; }; + 831C8212E175492955E9648E /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = ""; }; + 9B13F30441A92564B1C09264 /* libPods-luaviewEx_Example.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-luaviewEx_Example.a"; sourceTree = BUILT_PRODUCTS_DIR; }; + DC8E1CFB1E962C8D008A8064 /* App.lua */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = App.lua; path = playground/App.lua; sourceTree = ""; }; + DC8E1CFC1E962C8D008A8064 /* app.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; name = app.xml; path = playground/app.xml; sourceTree = ""; }; + DC8E1CFD1E962C8D008A8064 /* demo.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; name = demo.xml; path = playground/demo.xml; sourceTree = ""; }; + DC8E1CFF1E962C8D008A8064 /* luaview.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = luaview.png; path = playground/luaview.png; sourceTree = ""; }; + DC8E1D001E962C8D008A8064 /* sample */ = {isa = PBXFileReference; lastKnownFileType = folder; name = sample; path = playground/sample; sourceTree = ""; }; + DC8E1D011E962C8D008A8064 /* widget */ = {isa = PBXFileReference; lastKnownFileType = folder; name = widget; path = playground/widget; sourceTree = ""; }; + E911704A145F862454D3D51D /* Pods-luaviewEx_Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-luaviewEx_Example.release.xcconfig"; path = "Pods/Target Support Files/Pods-luaviewEx_Example/Pods-luaviewEx_Example.release.xcconfig"; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 6003F587195388D20070C39A /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 6003F590195388D20070C39A /* CoreGraphics.framework in Frameworks */, + 6003F592195388D20070C39A /* UIKit.framework in Frameworks */, + 6003F58E195388D20070C39A /* Foundation.framework in Frameworks */, + 7FDFEA88C11F435A5F66A774 /* libPods-luaviewEx_Example.a in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 6003F5AB195388D20070C39A /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 6003F5B0195388D20070C39A /* XCTest.framework in Frameworks */, + 6003F5B2195388D20070C39A /* UIKit.framework in Frameworks */, + 6003F5B1195388D20070C39A /* Foundation.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 6003F581195388D10070C39A = { + isa = PBXGroup; + children = ( + 60FF7A9C1954A5C5007DD14C /* Podspec Metadata */, + 6003F593195388D20070C39A /* Example for luaviewEx */, + 6003F5B5195388D20070C39A /* Tests */, + 6003F58C195388D20070C39A /* Frameworks */, + 6003F58B195388D20070C39A /* Products */, + 680A19B09A3198A018ED965F /* Pods */, + ); + sourceTree = ""; + }; + 6003F58B195388D20070C39A /* Products */ = { + isa = PBXGroup; + children = ( + 6003F58A195388D20070C39A /* luaviewEx_Example.app */, + 6003F5AE195388D20070C39A /* luaviewEx_Tests.xctest */, + ); + name = Products; + sourceTree = ""; + }; + 6003F58C195388D20070C39A /* Frameworks */ = { + isa = PBXGroup; + children = ( + 6003F58D195388D20070C39A /* Foundation.framework */, + 6003F58F195388D20070C39A /* CoreGraphics.framework */, + 6003F591195388D20070C39A /* UIKit.framework */, + 6003F5AF195388D20070C39A /* XCTest.framework */, + 9B13F30441A92564B1C09264 /* libPods-luaviewEx_Example.a */, + ); + name = Frameworks; + sourceTree = ""; + }; + 6003F593195388D20070C39A /* Example for luaviewEx */ = { + isa = PBXGroup; + children = ( + DC8E1C9F1E962C53008A8064 /* playground */, + 6003F59C195388D20070C39A /* LVAppDelegate.h */, + 6003F59D195388D20070C39A /* LVAppDelegate.m */, + 71719F9D1E33DC2100824A3D /* LaunchScreen.storyboard */, + 6003F5A8195388D20070C39A /* Images.xcassets */, + 6003F594195388D20070C39A /* Supporting Files */, + ); + name = "Example for luaviewEx"; + path = luaviewEx; + sourceTree = ""; + }; + 6003F594195388D20070C39A /* Supporting Files */ = { + isa = PBXGroup; + children = ( + 6003F595195388D20070C39A /* luaviewEx-Info.plist */, + 6003F596195388D20070C39A /* InfoPlist.strings */, + 6003F599195388D20070C39A /* main.m */, + 6003F59B195388D20070C39A /* luaviewEx-Prefix.pch */, + ); + name = "Supporting Files"; + sourceTree = ""; + }; + 6003F5B5195388D20070C39A /* Tests */ = { + isa = PBXGroup; + children = ( + 6003F5BB195388D20070C39A /* Tests.m */, + 6003F5B6195388D20070C39A /* Supporting Files */, + ); + path = Tests; + sourceTree = ""; + }; + 6003F5B6195388D20070C39A /* Supporting Files */ = { + isa = PBXGroup; + children = ( + 6003F5B7195388D20070C39A /* Tests-Info.plist */, + 6003F5B8195388D20070C39A /* InfoPlist.strings */, + 606FC2411953D9B200FFA9A0 /* Tests-Prefix.pch */, + ); + name = "Supporting Files"; + sourceTree = ""; + }; + 60FF7A9C1954A5C5007DD14C /* Podspec Metadata */ = { + isa = PBXGroup; + children = ( + 3C2B35DFDC5345C279F8AB5C /* luaviewEx.podspec */, + 831C8212E175492955E9648E /* README.md */, + 37896E6B4FE8F9834CD9D570 /* LICENSE */, + ); + name = "Podspec Metadata"; + sourceTree = ""; + }; + 680A19B09A3198A018ED965F /* Pods */ = { + isa = PBXGroup; + children = ( + 7E6F87FB063AB9201AA9EF27 /* Pods-luaviewEx_Example.debug.xcconfig */, + E911704A145F862454D3D51D /* Pods-luaviewEx_Example.release.xcconfig */, + ); + name = Pods; + sourceTree = ""; + }; + DC8E1C9F1E962C53008A8064 /* playground */ = { + isa = PBXGroup; + children = ( + DC8E1CFB1E962C8D008A8064 /* App.lua */, + DC8E1CFC1E962C8D008A8064 /* app.xml */, + DC8E1CFD1E962C8D008A8064 /* demo.xml */, + DC8E1CFF1E962C8D008A8064 /* luaview.png */, + DC8E1D001E962C8D008A8064 /* sample */, + DC8E1D011E962C8D008A8064 /* widget */, + ); + name = playground; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 6003F589195388D20070C39A /* luaviewEx_Example */ = { + isa = PBXNativeTarget; + buildConfigurationList = 6003F5BF195388D20070C39A /* Build configuration list for PBXNativeTarget "luaviewEx_Example" */; + buildPhases = ( + C43F40ED5386D5347F42792F /* Check Pods Manifest.lock */, + 6003F586195388D20070C39A /* Sources */, + 6003F587195388D20070C39A /* Frameworks */, + 6003F588195388D20070C39A /* Resources */, + 276C6E2B3A2920C865BF3CF8 /* Embed Pods Frameworks */, + 0CC7F41F823D6215AEF8809B /* Copy Pods Resources */, + 3E39CD9BEF5F1A950BCE17CB /* Copy Framework Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = luaviewEx_Example; + productName = luaviewEx; + productReference = 6003F58A195388D20070C39A /* luaviewEx_Example.app */; + productType = "com.apple.product-type.application"; + }; + 6003F5AD195388D20070C39A /* luaviewEx_Tests */ = { + isa = PBXNativeTarget; + buildConfigurationList = 6003F5C2195388D20070C39A /* Build configuration list for PBXNativeTarget "luaviewEx_Tests" */; + buildPhases = ( + 6003F5AA195388D20070C39A /* Sources */, + 6003F5AB195388D20070C39A /* Frameworks */, + 6003F5AC195388D20070C39A /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + 6003F5B4195388D20070C39A /* PBXTargetDependency */, + ); + name = luaviewEx_Tests; + productName = luaviewExTests; + productReference = 6003F5AE195388D20070C39A /* luaviewEx_Tests.xctest */; + productType = "com.apple.product-type.bundle.unit-test"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 6003F582195388D10070C39A /* Project object */ = { + isa = PBXProject; + attributes = { + CLASSPREFIX = LV; + LastUpgradeCheck = 0720; + ORGANIZATIONNAME = yechunxiao19; + TargetAttributes = { + 6003F5AD195388D20070C39A = { + TestTargetID = 6003F589195388D20070C39A; + }; + }; + }; + buildConfigurationList = 6003F585195388D10070C39A /* Build configuration list for PBXProject "luaviewEx" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 6003F581195388D10070C39A; + productRefGroup = 6003F58B195388D20070C39A /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 6003F589195388D20070C39A /* luaviewEx_Example */, + 6003F5AD195388D20070C39A /* luaviewEx_Tests */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 6003F588195388D20070C39A /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + DC8E1D081E962C8D008A8064 /* widget in Resources */, + DC8E1D041E962C8D008A8064 /* demo.xml in Resources */, + DC8E1D021E962C8D008A8064 /* App.lua in Resources */, + 71719F9F1E33DC2100824A3D /* LaunchScreen.storyboard in Resources */, + DC8E1D061E962C8D008A8064 /* luaview.png in Resources */, + DC8E1D031E962C8D008A8064 /* app.xml in Resources */, + 6003F5A9195388D20070C39A /* Images.xcassets in Resources */, + DC8E1D071E962C8D008A8064 /* sample in Resources */, + 6003F598195388D20070C39A /* InfoPlist.strings in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 6003F5AC195388D20070C39A /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 6003F5BA195388D20070C39A /* InfoPlist.strings in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXShellScriptBuildPhase section */ + 0CC7F41F823D6215AEF8809B /* Copy Pods Resources */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "Copy Pods Resources"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-luaviewEx_Example/Pods-luaviewEx_Example-resources.sh\"\n"; + showEnvVarsInLog = 0; + }; + 276C6E2B3A2920C865BF3CF8 /* Embed Pods Frameworks */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "Embed Pods Frameworks"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-luaviewEx_Example/Pods-luaviewEx_Example-frameworks.sh\"\n"; + showEnvVarsInLog = 0; + }; + 3E39CD9BEF5F1A950BCE17CB /* Copy Framework Resources */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "Copy Framework Resources"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "bash -l -c \"ruby \\\"${SRCROOT}/Pods/Target Support Files/Pods-luaviewEx_Example/copy-framework-resources.rb\\\"\""; + showEnvVarsInLog = 0; + }; + C43F40ED5386D5347F42792F /* Check Pods Manifest.lock */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "Check Pods Manifest.lock"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n"; + showEnvVarsInLog = 0; + }; +/* End PBXShellScriptBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 6003F586195388D20070C39A /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 6003F59E195388D20070C39A /* LVAppDelegate.m in Sources */, + 6003F59A195388D20070C39A /* main.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 6003F5AA195388D20070C39A /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 6003F5BC195388D20070C39A /* Tests.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXTargetDependency section */ + 6003F5B4195388D20070C39A /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 6003F589195388D20070C39A /* luaviewEx_Example */; + targetProxy = 6003F5B3195388D20070C39A /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + +/* Begin PBXVariantGroup section */ + 6003F596195388D20070C39A /* InfoPlist.strings */ = { + isa = PBXVariantGroup; + children = ( + 6003F597195388D20070C39A /* en */, + ); + name = InfoPlist.strings; + sourceTree = ""; + }; + 6003F5B8195388D20070C39A /* InfoPlist.strings */ = { + isa = PBXVariantGroup; + children = ( + 6003F5B9195388D20070C39A /* en */, + ); + name = InfoPlist.strings; + sourceTree = ""; + }; + 71719F9D1E33DC2100824A3D /* LaunchScreen.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 71719F9E1E33DC2100824A3D /* Base */, + ); + name = LaunchScreen.storyboard; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 6003F5BD195388D20070C39A /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_SYMBOLS_PRIVATE_EXTERN = NO; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 8.3; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 6003F5BE195388D20070C39A /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = YES; + ENABLE_NS_ASSERTIONS = NO; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 8.3; + SDKROOT = iphoneos; + TARGETED_DEVICE_FAMILY = "1,2"; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 6003F5C0195388D20070C39A /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 7E6F87FB063AB9201AA9EF27 /* Pods-luaviewEx_Example.debug.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + DEVELOPMENT_TEAM = ""; + GCC_PRECOMPILE_PREFIX_HEADER = YES; + GCC_PREFIX_HEADER = "luaviewEx/luaviewEx-Prefix.pch"; + INFOPLIST_FILE = "luaviewEx/luaviewEx-Info.plist"; + MODULE_NAME = ExampleApp; + PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.${PRODUCT_NAME:rfc1034identifier}"; + PRODUCT_NAME = "$(TARGET_NAME)"; + TARGETED_DEVICE_FAMILY = 1; + WRAPPER_EXTENSION = app; + }; + name = Debug; + }; + 6003F5C1195388D20070C39A /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = E911704A145F862454D3D51D /* Pods-luaviewEx_Example.release.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + DEVELOPMENT_TEAM = ""; + GCC_PRECOMPILE_PREFIX_HEADER = YES; + GCC_PREFIX_HEADER = "luaviewEx/luaviewEx-Prefix.pch"; + INFOPLIST_FILE = "luaviewEx/luaviewEx-Info.plist"; + MODULE_NAME = ExampleApp; + PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.${PRODUCT_NAME:rfc1034identifier}"; + PRODUCT_NAME = "$(TARGET_NAME)"; + TARGETED_DEVICE_FAMILY = 1; + WRAPPER_EXTENSION = app; + }; + name = Release; + }; + 6003F5C3195388D20070C39A /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + BUNDLE_LOADER = "$(TEST_HOST)"; + FRAMEWORK_SEARCH_PATHS = ( + "$(SDKROOT)/Developer/Library/Frameworks", + "$(inherited)", + "$(DEVELOPER_FRAMEWORKS_DIR)", + ); + GCC_PRECOMPILE_PREFIX_HEADER = YES; + GCC_PREFIX_HEADER = "Tests/Tests-Prefix.pch"; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + INFOPLIST_FILE = "Tests/Tests-Info.plist"; + PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.${PRODUCT_NAME:rfc1034identifier}"; + PRODUCT_NAME = "$(TARGET_NAME)"; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/luaviewEx_Example.app/luaviewEx_Example"; + WRAPPER_EXTENSION = xctest; + }; + name = Debug; + }; + 6003F5C4195388D20070C39A /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + BUNDLE_LOADER = "$(TEST_HOST)"; + FRAMEWORK_SEARCH_PATHS = ( + "$(SDKROOT)/Developer/Library/Frameworks", + "$(inherited)", + "$(DEVELOPER_FRAMEWORKS_DIR)", + ); + GCC_PRECOMPILE_PREFIX_HEADER = YES; + GCC_PREFIX_HEADER = "Tests/Tests-Prefix.pch"; + INFOPLIST_FILE = "Tests/Tests-Info.plist"; + PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.${PRODUCT_NAME:rfc1034identifier}"; + PRODUCT_NAME = "$(TARGET_NAME)"; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/luaviewEx_Example.app/luaviewEx_Example"; + WRAPPER_EXTENSION = xctest; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 6003F585195388D10070C39A /* Build configuration list for PBXProject "luaviewEx" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 6003F5BD195388D20070C39A /* Debug */, + 6003F5BE195388D20070C39A /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 6003F5BF195388D20070C39A /* Build configuration list for PBXNativeTarget "luaviewEx_Example" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 6003F5C0195388D20070C39A /* Debug */, + 6003F5C1195388D20070C39A /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 6003F5C2195388D20070C39A /* Build configuration list for PBXNativeTarget "luaviewEx_Tests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 6003F5C3195388D20070C39A /* Debug */, + 6003F5C4195388D20070C39A /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 6003F582195388D10070C39A /* Project object */; +} diff --git a/IOS/luaviewEx/Example/luaviewEx.xcodeproj/xcshareddata/xcschemes/luaviewEx-Example.xcscheme b/IOS/luaviewEx/Example/luaviewEx.xcodeproj/xcshareddata/xcschemes/luaviewEx-Example.xcscheme new file mode 100644 index 00000000..86f57cd7 --- /dev/null +++ b/IOS/luaviewEx/Example/luaviewEx.xcodeproj/xcshareddata/xcschemes/luaviewEx-Example.xcscheme @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/IOS/luaviewEx/Example/luaviewEx.xcworkspace/contents.xcworkspacedata b/IOS/luaviewEx/Example/luaviewEx.xcworkspace/contents.xcworkspacedata new file mode 100644 index 00000000..3bd7752a --- /dev/null +++ b/IOS/luaviewEx/Example/luaviewEx.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,10 @@ + + + + + + + diff --git a/IOS/luaviewEx/Example/luaviewEx/Base.lproj/LaunchScreen.storyboard b/IOS/luaviewEx/Example/luaviewEx/Base.lproj/LaunchScreen.storyboard new file mode 100644 index 00000000..66a76819 --- /dev/null +++ b/IOS/luaviewEx/Example/luaviewEx/Base.lproj/LaunchScreen.storyboard @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/IOS/luaviewEx/Example/luaviewEx/Images.xcassets/AppIcon.appiconset/Contents.json b/IOS/luaviewEx/Example/luaviewEx/Images.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 00000000..d7070bc5 --- /dev/null +++ b/IOS/luaviewEx/Example/luaviewEx/Images.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,93 @@ +{ + "images" : [ + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "3x" + }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "29x29", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "40x40", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "76x76", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "76x76", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "83.5x83.5", + "scale" : "2x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} diff --git a/IOS/luaviewEx/Example/luaviewEx/LVAppDelegate.h b/IOS/luaviewEx/Example/luaviewEx/LVAppDelegate.h new file mode 100644 index 00000000..328a5d2e --- /dev/null +++ b/IOS/luaviewEx/Example/luaviewEx/LVAppDelegate.h @@ -0,0 +1,15 @@ +// +// LVAppDelegate.h +// luaviewEx +// +// Created by yechunxiao19 on 04/06/2017. +// Copyright (c) 2017 yechunxiao19. All rights reserved. +// + +#import + +@interface LVAppDelegate : UIResponder + +@property (strong, nonatomic) UIWindow *window; + +@end diff --git a/IOS/luaviewEx/Example/luaviewEx/LVAppDelegate.m b/IOS/luaviewEx/Example/luaviewEx/LVAppDelegate.m new file mode 100644 index 00000000..5b805509 --- /dev/null +++ b/IOS/luaviewEx/Example/luaviewEx/LVAppDelegate.m @@ -0,0 +1,32 @@ +// +// LVAppDelegate.m +// luaviewEx +// +// Created by yechunxiao19 on 04/06/2017. +// Copyright (c) 2017 yechunxiao19. All rights reserved. +// + +#import "LVAppDelegate.h" +#import "LVViewController.h" + +@implementation LVAppDelegate + +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions +{ + // Override point for customization after application launch. + self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; + self.window.backgroundColor = [UIColor whiteColor]; + + LVViewController* controller = [[LVViewController alloc] initWithPackage]; + +// LVViewController* controller = [[LVViewController alloc] initWithPackage:[[NSBundle mainBundle] resourcePath] mainScript:@"kit/main.lua"]; + + self.window.rootViewController = [[UINavigationController alloc] + initWithRootViewController:controller]; + + [self.window makeKeyAndVisible]; + + return YES; +} + +@end diff --git a/IOS/luaviewEx/Example/luaviewEx/en.lproj/InfoPlist.strings b/IOS/luaviewEx/Example/luaviewEx/en.lproj/InfoPlist.strings new file mode 100644 index 00000000..477b28ff --- /dev/null +++ b/IOS/luaviewEx/Example/luaviewEx/en.lproj/InfoPlist.strings @@ -0,0 +1,2 @@ +/* Localized versions of Info.plist keys */ + diff --git a/IOS/luaviewEx/Example/luaviewEx/luaviewEx-Info.plist b/IOS/luaviewEx/Example/luaviewEx/luaviewEx-Info.plist new file mode 100644 index 00000000..5d65aaf3 --- /dev/null +++ b/IOS/luaviewEx/Example/luaviewEx/luaviewEx-Info.plist @@ -0,0 +1,47 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleDisplayName + ${PRODUCT_NAME} + CFBundleExecutable + ${EXECUTABLE_NAME} + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + ${PRODUCT_NAME} + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1.0 + LSRequiresIPhoneOS + + UILaunchStoryboardName + LaunchScreen + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + + diff --git a/IOS/luaviewEx/Example/luaviewEx/luaviewEx-Prefix.pch b/IOS/luaviewEx/Example/luaviewEx/luaviewEx-Prefix.pch new file mode 100644 index 00000000..7825372c --- /dev/null +++ b/IOS/luaviewEx/Example/luaviewEx/luaviewEx-Prefix.pch @@ -0,0 +1,16 @@ +// +// Prefix header +// +// The contents of this file are implicitly included at the beginning of every source file. +// + +#import + +#ifndef __IPHONE_5_0 +#warning "This project uses features only available in iOS SDK 5.0 and later." +#endif + +#ifdef __OBJC__ + @import UIKit; + @import Foundation; +#endif diff --git a/IOS/luaviewEx/Example/luaviewEx/main.m b/IOS/luaviewEx/Example/luaviewEx/main.m new file mode 100644 index 00000000..f66236a2 --- /dev/null +++ b/IOS/luaviewEx/Example/luaviewEx/main.m @@ -0,0 +1,17 @@ +// +// main.m +// luaviewEx +// +// Created by yechunxiao19 on 04/06/2017. +// Copyright (c) 2017 yechunxiao19. All rights reserved. +// + +@import UIKit; +#import "LVAppDelegate.h" + +int main(int argc, char * argv[]) +{ + @autoreleasepool { + return UIApplicationMain(argc, argv, nil, NSStringFromClass([LVAppDelegate class])); + } +} diff --git a/IOS/luaviewEx/Example/luaviewEx/playground/App.lua b/IOS/luaviewEx/Example/luaviewEx/playground/App.lua new file mode 100644 index 00000000..312eb588 --- /dev/null +++ b/IOS/luaviewEx/Example/luaviewEx/playground/App.lua @@ -0,0 +1,129 @@ +-- +-- Copyright 2017 Alibaba Group +-- License: MIT +-- Website: https://alibaba.github.io/LuaViewSDK +-- User: tuoli +-- Date: 17/3/30 +-- + +Navigation:title("Playground") + +local meta = object:new() + +function meta:onCreate(args) + self.views = pica:getInstance():render("app.xml") + self.widgetList = self.views["widgetTableView"] + self.sampleList = self.views["sampleTableView"] + self.aboutView = self.views["aboutView"] + self.widgetTab = self.views["widgetTab"] + self.sampleTab = self.views["sampleTab"] + self.aboutTab = self.views["aboutTab"] + self.aboutInfo = self.views["info"] + if (sys.android) then + self.aboutInfo:nativeView():setLineSpacing(10*sys.scale,1) + end + + self.widgetData = Json:toTable(' ["Label", "Button", "Image", "TextField", "Loading", "List", "PagerView", "HScrollView", "WebView", "Animation"] ') + self.sampleData = Json:toTable(' ["Douban", "GitHub"] ') + self.sampleSpec = Json:toTable(' ["Get movie information from Douban.", "Search repositories from GitHub."] ') + + self:handle() +end + +function meta:handle() + self.widgetList:initParams({ + Section = { + SectionCount = function() + return 1 + end, + RowCount = function(section) + return table.getn(self.widgetData) + end + }, + Cell = { + Id = function(section, row) + return "SampleCell" + end, + SampleCell = { + Size = function(section, row) + return sys.contW, sys.contH/8 + end, + Init = function(cell, section, row) + cell.window:backgroundColor(0xffffff) + cell.label = Label() + cell.label:frame(15*sys.scale, 15*sys.scale, sys.contW-15*2*sys.scale, (sys.contH/8-15*2*sys.scale)) + end, + Layout = function(cell, section, row) + local style = StyledString(self.widgetData[row], { fontSize = 25*sys.scale, fontColor = 0x000000}) + cell.label:text(style) + end, + Callback = function(cell, section, row) + Bridge:require({page="widget/" .. self.widgetData[row]}) + end + } + } + }) + self.widgetList:reload() + + self.sampleList:initParams({ + Section = { + SectionCount = function() + return 1 + end, + RowCount = function(section) + return table.getn(self.sampleData) + end + }, + Cell = { + Id = function(section, row) + return "SampleCell" + end, + SampleCell = { + Size = function(section, row) + return sys.contW, sys.contH/5 + end, + Init = function(cell, section, row) + cell.objs = pica:getInstance():render("demo.xml") + end, + Layout = function(cell, section, row) + cell.objs["item"]:text(self.sampleData[row]) + cell.objs["subitem"]:text(self.sampleSpec[row]) + end, + Callback = function(cell, section, row) + Bridge:require({page="sample/" .. self.sampleData[row]}) + end + } + } + }) + self.sampleList:reload() + + self.widgetTab:callback(function() + self.widgetTab:textColor(0xEB3131) + self.sampleTab:textColor(0x000000) + self.aboutTab:textColor(0x000000) + + self.widgetList:show() + self.sampleList:hide() + self.aboutView:hide() + end) + self.sampleTab:callback(function() + self.widgetTab:textColor(0x000000) + self.sampleTab:textColor(0xEB3131) + self.aboutTab:textColor(0x000000) + + self.sampleList:show() + self.widgetList:hide() + self.aboutView:hide() + end) + self.aboutTab:callback(function() + self.widgetTab:textColor(0x000000) + self.sampleTab:textColor(0x000000) + self.aboutTab:textColor(0xEB3131) + + self.aboutView:show() + self.widgetList:hide() + self.sampleList:hide() + end) +end + +return meta \ No newline at end of file diff --git a/IOS/luaviewEx/Example/luaviewEx/playground/app.xml b/IOS/luaviewEx/Example/luaviewEx/playground/app.xml new file mode 100644 index 00000000..5cdf7724 --- /dev/null +++ b/IOS/luaviewEx/Example/luaviewEx/playground/app.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/IOS/luaviewEx/Example/luaviewEx/playground/demo.xml b/IOS/luaviewEx/Example/luaviewEx/playground/demo.xml new file mode 100644 index 00000000..76587e47 --- /dev/null +++ b/IOS/luaviewEx/Example/luaviewEx/playground/demo.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/IOS/luaviewEx/Example/luaviewEx/playground/luaview.png b/IOS/luaviewEx/Example/luaviewEx/playground/luaview.png new file mode 100644 index 00000000..40cd90b7 Binary files /dev/null and b/IOS/luaviewEx/Example/luaviewEx/playground/luaview.png differ diff --git a/IOS/luaviewEx/Example/luaviewEx/playground/sample/Douban.lua b/IOS/luaviewEx/Example/luaviewEx/playground/sample/Douban.lua new file mode 100644 index 00000000..531c47c2 --- /dev/null +++ b/IOS/luaviewEx/Example/luaviewEx/playground/sample/Douban.lua @@ -0,0 +1,91 @@ +-- +-- Copyright 2017 Alibaba Group +-- License: MIT +-- Website: https://alibaba.github.io/LuaViewSDK +-- User: tuoli +-- Date: 17/3/30 +-- + +Navigation:title("Douban.lua") + +local meta = object:new() + +function meta:onCreate(args) + self.views = pica:getInstance():render("sample/douban.xml") + self.loading = self.views["loading"] + self.list = self.views["tableView"] + + self:handle() +end + +function meta:handle() + self.loading:show() + print("tuoli", "http request start") + Http():get("http://api.douban.com/v2/movie/in_theaters?apikey=0df993c66c0c636e29ecbb5344252a4a", function(response) + print("tuoli", "http request end") + self.loading:hide() + if (tostring(response:code()) == "200") then + local _jsonData = Json:toTable(tostring(response:data())) + self.list:initParams({ + Section = { + SectionCount = function() + return 1 + end, + RowCount = function(section) + return _jsonData["count"] + end + }, + Cell = { + Id = function(section, row) + return "ItemCell" + end, + ItemCell = { + Size = function(section, row) + return sys.contW, sys.contH/3 + end, + Init = function(cell, section, row) + cell.objs = pica:getInstance():render("sample/douban_cell.xml") + end, + Layout = function(cell, section, row) + cell.objs["profile"]:image(_jsonData["subjects"][row]["images"]["large"]) + cell.objs["movieName"]:text(_jsonData["subjects"][row]["title"]) + cell.objs["score"]:text("评分: " .. _jsonData["subjects"][row]["rating"]["average"]) + local director = "导演: " .. _jsonData["subjects"][row]["directors"][1]["name"] + local actors = "主演: " + for _k, _v in pairs(_jsonData["subjects"][row]["casts"]) do + actors = actors .. _v["name"] .. "/" + end + cell.objs["character"]:text(director .. "\n" .. actors) + cell.objs["number"]:text(_jsonData["subjects"][row]["collect_count"] .. "人看过") + + cell.objs["item"]:callback(function() + Bridge:require({page="sample.Douban_detail", url=_jsonData["subjects"][row]["alt"] .. "mobile"}) + end) + end + } + }, + Callback = { + PullDown = function() + Http():get("http://api.douban.com/v2/movie/in_theaters?apikey=0df993c66c0c636e29ecbb5344252a4a", + function(response) + if (tostring(response:code()) == "200") then + _jsonData = Json:toTable(tostring(response:data())) + self.list:reload() + end + + self.list:stopRefreshing() + end + ) + end + } + }) + + self.list:reload() + else + Toast("Request Error") + end + end) +end + +return meta + diff --git a/IOS/luaviewEx/Example/luaviewEx/playground/sample/Douban_detail.lua b/IOS/luaviewEx/Example/luaviewEx/playground/sample/Douban_detail.lua new file mode 100644 index 00000000..e9eeb5d7 --- /dev/null +++ b/IOS/luaviewEx/Example/luaviewEx/playground/sample/Douban_detail.lua @@ -0,0 +1,24 @@ +-- +-- Copyright 2017 Alibaba Group +-- License: MIT +-- Website: https://alibaba.github.io/LuaViewSDK +-- User: tuoli +-- Date: 17/4/5 +-- + +Navigation:title("豆瓣电影详情") + +local meta = object:new() + +function meta:onCreate(args) + self.web = WebView() + self.web:frame(0, 0, sys.contW, sys.contH) + self.web:loadUrl(args.url) +end + +function meta:handle() + +end + +return meta + diff --git a/IOS/luaviewEx/Example/luaviewEx/playground/sample/GitHub.lua b/IOS/luaviewEx/Example/luaviewEx/playground/sample/GitHub.lua new file mode 100644 index 00000000..16680398 --- /dev/null +++ b/IOS/luaviewEx/Example/luaviewEx/playground/sample/GitHub.lua @@ -0,0 +1,107 @@ +-- +-- Copyright 2017 Alibaba Group +-- License: MIT +-- Website: https://alibaba.github.io/LuaViewSDK +-- User: tuoli +-- Date: 17/3/30 +-- + +Navigation:title("GitHub.lua") + +local meta = object:new() + +function meta:onCreate(args) + if (sys.android) then + self.views = pica:getInstance():render("sample/github_android.xml") + else + self.views = pica:getInstance():render("sample/github_ios.xml") + end + + self.search = self.views["go"] + self.input = self.views["input"] + self.list = self.views["tableView"] + self.loading = self.views["loading"] + + self:handle() +end + +function meta:handle() + local isSearching = false + self.search:callback(function() + if (not sys.android) then + self.input:cancelFocus() + end + + if (isSearching == true) then + return + end + + local content = self.input:text() + local baseUrl = "https://api.github.com/search/repositories?sort=stars&q=" + + self.loading:show() + isSearching = true + + print("tuoli", "http request start") + Http():get(baseUrl .. content, function(response) + isSearching = false + print("tuoli", "http request end") + + self.loading:hide() + + if (tostring(response:code()) == "200") then + local jsonData = Json:toTable(tostring(response:data())) + + if (table.getn(jsonData["items"]) == 0) then + Toast("No Result") + else + local tableData = { + Section = { + SectionCount = function() + return 1 + end, + RowCount = function(section) + return table.getn(jsonData["items"]) + end + }, + Cell = { + Id = function(section, row) + return "ItemCell" + end, + ItemCell = { + Size = function(section, row) + return sys.contW, sys.contH/3 + end, + Init = function(cell, section, row) + cell.objs = pica:getInstance():render("sample/github_cell.xml") + end, + Layout = function(cell, section, row) + cell.objs["name"]:text(jsonData["items"][row]["full_name"]) + if (jsonData["items"][row]["description"]) then + cell.objs["description"]:text(jsonData["items"][row]["description"]) + else + cell.objs["description"]:text("no descriptions") + end + cell.objs["profile"]:image(jsonData["items"][row]["owner"]["avatar_url"]) + cell.objs["profile"]:scaleType(ScaleType.FIT_CENTER) + cell.objs["stars"]:text("Stars: " .. jsonData["items"][row]["stargazers_count"]) + + cell.objs["item"]:callback(function() + Bridge:require({page="sample.GitHub_detail", url=jsonData["items"][row]["html_url"]}) + end) + end + } + } + } + + self.list:initParams(tableData) + self.list:reload() + end + else + Toast("Request Error") + end + end) + end) +end + +return meta \ No newline at end of file diff --git a/IOS/luaviewEx/Example/luaviewEx/playground/sample/GitHub_detail.lua b/IOS/luaviewEx/Example/luaviewEx/playground/sample/GitHub_detail.lua new file mode 100644 index 00000000..37f73690 --- /dev/null +++ b/IOS/luaviewEx/Example/luaviewEx/playground/sample/GitHub_detail.lua @@ -0,0 +1,24 @@ +-- +-- Copyright 2017 Alibaba Group +-- License: MIT +-- Website: https://alibaba.github.io/LuaViewSDK +-- User: tuoli +-- Date: 17/4/5 +-- + +Navigation:title("GitHub详情") + +local meta = object:new() + +function meta:onCreate(args) + self.web = WebView() + self.web:frame(0, 0, sys.contW, sys.contH) + self.web:loadUrl(args.url) +end + +function meta:handle() + +end + +return meta + diff --git a/IOS/luaviewEx/Example/luaviewEx/playground/sample/douban.xml b/IOS/luaviewEx/Example/luaviewEx/playground/sample/douban.xml new file mode 100644 index 00000000..089a89b5 --- /dev/null +++ b/IOS/luaviewEx/Example/luaviewEx/playground/sample/douban.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/IOS/luaviewEx/Example/luaviewEx/playground/sample/douban_cell.xml b/IOS/luaviewEx/Example/luaviewEx/playground/sample/douban_cell.xml new file mode 100644 index 00000000..38dfc62f --- /dev/null +++ b/IOS/luaviewEx/Example/luaviewEx/playground/sample/douban_cell.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/IOS/luaviewEx/Example/luaviewEx/playground/sample/douban_detail.xml b/IOS/luaviewEx/Example/luaviewEx/playground/sample/douban_detail.xml new file mode 100644 index 00000000..e69de29b diff --git a/IOS/luaviewEx/Example/luaviewEx/playground/sample/github_android.xml b/IOS/luaviewEx/Example/luaviewEx/playground/sample/github_android.xml new file mode 100644 index 00000000..5329e7df --- /dev/null +++ b/IOS/luaviewEx/Example/luaviewEx/playground/sample/github_android.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/IOS/luaviewEx/Example/luaviewEx/playground/sample/github_cell.xml b/IOS/luaviewEx/Example/luaviewEx/playground/sample/github_cell.xml new file mode 100644 index 00000000..7e18d437 --- /dev/null +++ b/IOS/luaviewEx/Example/luaviewEx/playground/sample/github_cell.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/IOS/luaviewEx/Example/luaviewEx/playground/sample/github_ios.xml b/IOS/luaviewEx/Example/luaviewEx/playground/sample/github_ios.xml new file mode 100644 index 00000000..a0faa7c3 --- /dev/null +++ b/IOS/luaviewEx/Example/luaviewEx/playground/sample/github_ios.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/IOS/luaviewEx/Example/luaviewEx/playground/widget/Animation.lua b/IOS/luaviewEx/Example/luaviewEx/playground/widget/Animation.lua new file mode 100644 index 00000000..7529e4dd --- /dev/null +++ b/IOS/luaviewEx/Example/luaviewEx/playground/widget/Animation.lua @@ -0,0 +1,53 @@ +-- +-- Copyright 2017 Alibaba Group +-- License: MIT +-- Website: https://alibaba.github.io/LuaViewSDK +-- User: tuoli +-- Date: 17/3/30 +-- + +Navigation:title("Animation.lua") + +local meta = object:new() + +function meta:onCreate(args) + self.views = pica:getInstance():render("widget/animation.xml") + self.spirit = self.views["img"] + self.translateBtn = self.views["translateBtn"] + self.scaleBtn = self.views["scaleBtn"] + self.alphaBtn = self.views["alphaBtn"] + self.resetBtn = self.views["resetBtn"] + self.allBtn = self.views["allBtn"] + + self:handle() +end + +function meta:handle() + self.translateBtn:callback(function() + local translate = Animation():translation(sys.contW/2, sys.contW/2):duration(1) + translate:with(self.spirit):start() + end) + self.scaleBtn:callback(function() + local scale = Animation():scale(0.5, 0.5):duration(1) + scale:with(self.spirit):start() + end) + self.alphaBtn:callback(function() + local alpha = Animation():alpha(0.3):duration(1) + alpha:with(self.spirit):start() + end) + self.allBtn:callback(function() + local translate = Animation():translation(sys.contW/2, sys.contW/2):duration(1) + local scale = Animation():scale(0.5, 0.5):duration(1) + local alpha = Animation():alpha(0.3):duration(1) + alpha:with(self.spirit):start() + scale:with(self.spirit):start() + translate:with(self.spirit):start() + end) + self.resetBtn:callback(function() + self.spirit:translation(0, 0) + self.spirit:scale(1, 1) + self.spirit:alpha(1) + end) +end + +return meta diff --git a/IOS/luaviewEx/Example/luaviewEx/playground/widget/Button.lua b/IOS/luaviewEx/Example/luaviewEx/playground/widget/Button.lua new file mode 100644 index 00000000..a8570b46 --- /dev/null +++ b/IOS/luaviewEx/Example/luaviewEx/playground/widget/Button.lua @@ -0,0 +1,46 @@ +-- +-- Copyright 2017 Alibaba Group +-- License: MIT +-- Website: https://alibaba.github.io/LuaViewSDK +-- User: tuoli +-- Date: 17/3/30 +-- + +Navigation:title("Button.lua") + +local meta = object:new() + +function meta:onCreate(args) + self.views = pica:getInstance():render("widget/button.xml") + self.button1 = self.views["button1"] + self.button2 = self.views["button2"] + self.button3 = self.views["button3"] + self.button4 = self.views["button4"] + self.button5 = self.views["button5"] + self.button6 = self.views["button6"] + + self:handle() +end + +function meta:handle() + self.button1:callback(function() + Toast("Clicked") + end) + self.button2:callback(function() + Toast("Clicked") + end) + self.button3:callback(function() + Toast("Clicked") + end) + self.button4:callback(function() + Toast("Clicked") + end) + self.button5:callback(function() + Toast("Clicked") + end) + self.button6:callback(function() + Toast("Clicked") + end) +end + +return meta diff --git a/IOS/luaviewEx/Example/luaviewEx/playground/widget/HScrollView.lua b/IOS/luaviewEx/Example/luaviewEx/playground/widget/HScrollView.lua new file mode 100644 index 00000000..69131849 --- /dev/null +++ b/IOS/luaviewEx/Example/luaviewEx/playground/widget/HScrollView.lua @@ -0,0 +1,40 @@ +-- +-- Copyright 2017 Alibaba Group +-- License: MIT +-- Website: https://alibaba.github.io/LuaViewSDK +-- User: tuoli +-- Date: 17/3/30 +-- + +Navigation:title("HScrollView.lua") + +local meta = object:new() + +function meta:onCreate(args) + self.views = pica:getInstance():render("widget/hscrollview.xml") + self.scroller = self.views["scroller"] + + self:handle() +end + +function meta:handle() + for k, v in pairs(self.views) do + if k ~= "scroller" then + v:callback(function() + v:backgroundColor(0xEB3131) + for _k, _v in pairs(self.views) do + if _k ~= "scroller" then + if (_v ~= v) then + _v:backgroundColor(0x004B97) + end + end + end + local x, y, w, h = v:frame() + local dx = (sys.contW - w)/2 + self.scroller:offset(x-dx, 0, true) + end) + end + end +end + +return meta \ No newline at end of file diff --git a/IOS/luaviewEx/Example/luaviewEx/playground/widget/Image.lua b/IOS/luaviewEx/Example/luaviewEx/playground/widget/Image.lua new file mode 100644 index 00000000..720ace9d --- /dev/null +++ b/IOS/luaviewEx/Example/luaviewEx/playground/widget/Image.lua @@ -0,0 +1,17 @@ +-- +-- Copyright 2017 Alibaba Group +-- License: MIT +-- Website: https://alibaba.github.io/LuaViewSDK +-- User: tuoli +-- Date: 17/3/30 +-- + +Navigation:title("Image.lua") + +local meta = object:new() + +function meta:onCreate(args) + self.views = pica:getInstance():render("widget/image.xml") +end + +return meta diff --git a/IOS/luaviewEx/Example/luaviewEx/playground/widget/Label.lua b/IOS/luaviewEx/Example/luaviewEx/playground/widget/Label.lua new file mode 100644 index 00000000..cabbb2f6 --- /dev/null +++ b/IOS/luaviewEx/Example/luaviewEx/playground/widget/Label.lua @@ -0,0 +1,56 @@ +-- +-- Copyright 2017 Alibaba Group +-- License: MIT +-- Website: https://alibaba.github.io/LuaViewSDK +-- User: tuoli +-- Date: 17/3/30 +-- + +require("kit.pica") + +Navigation:title("Label.lua") + +local meta = object:new() + +function meta:onCreate(args) + self.list = CollectionView() + self.list:frame(0, 0, sys.contW, sys.contH) + self.list:initParams({ + Section = { + SectionCount = function() + return 1 + end, + RowCount = function(section) + return 1 + end + }, + Cell = { + Id = function(section, row) + return "LabelCell" + end, + LabelCell = { + Size = function(section, row) + return sys.contW, sys.contH*2.5 + end, + Init = function(cell, section, row) + cell.objs = pica:getInstance():render("widget/label_item.xml") + + local fs1 = cell.objs["fs1"] + fs1:text(StyledString("normal", {fontStyle = "normal", fontSize=25*sys.scale })) + local fs2 = cell.objs["fs2"] + fs2:text(StyledString("bold", {fontStyle = "bold", fontSize=25*sys.scale})) + local fs3 = cell.objs["fs3"] + fs3:text(StyledString("italic", {fontStyle = "italic", fontSize=25*sys.scale})) + local td1 = cell.objs["td1"] + td1:text(StyledString("strikethrough", {strikethrough = true, fontSize=25*sys.scale})) + local td2 = cell.objs["td2"] + td2:text(StyledString("underline", {underline = true, fontSize=25*sys.scale})) + end + } + } + }) + + self.list:reload() +end + +return meta diff --git a/IOS/luaviewEx/Example/luaviewEx/playground/widget/List.lua b/IOS/luaviewEx/Example/luaviewEx/playground/widget/List.lua new file mode 100644 index 00000000..9f96cc53 --- /dev/null +++ b/IOS/luaviewEx/Example/luaviewEx/playground/widget/List.lua @@ -0,0 +1,81 @@ +-- +-- Copyright 2017 Alibaba Group +-- License: MIT +-- Website: https://alibaba.github.io/LuaViewSDK +-- User: tuoli +-- Date: 17/3/30 +-- + +Navigation:title("List.lua") + +local meta = object:new() + +function meta:onCreate(args) + self.views = pica:getInstance():render("widget/list.xml") + self.list = self.views["tableView"] + self.header = self.views["headerText"] + if (not sys.android) then + -- iOS还有bug,暂时屏蔽 + self.header:hide() + end + + self.timer = Timer() + self:handle() +end + +function meta:handle() + self.timer:callback(function() + self.list:stopRefreshing() + self.timer:cancel() + end) + + self.list:initParams({ + Section = { + SectionCount = function() + return 1 + end, + RowCount = function(section) + return 20 + end + }, + Cell = { + Id = function(section, row) + return "RowCell" + end, + RowCell = { + Size = function(section, row) + return sys.contW, sys.contH/10 + end, + Init = function(cell, section, row) + cell.window:frame(0, 0, sys.contW, sys.contH/10) + cell.window:flexCss("flex-direction: row") + cell.window:backgroundColor(0xffffff) + + local label = Label() + label:flexCss("margin: 15, flex: 1") + + cell.label = label + cell.window:flexChildren(cell.label) + cell.window:flxLayout(true) -- iOS + end, + Layout = function(cell, section, row) + local style = StyledString("row " .. row, { fontSize = 16*sys.scale, fontColor = 0x000000}) + cell.label:text(style) + end + } + }, + Callback = { + Scrolling = function( firstVisibleSection, firstVisibleRow, visibleCellCount ) + self.header:text("Visible Items: " .. firstVisibleRow .. ", " .. firstVisibleRow + visibleCellCount) + end, + PullDown = function() + self.timer:start(3) + end + } + }) + + self.list:reload() +end + +return meta + diff --git a/IOS/luaviewEx/Example/luaviewEx/playground/widget/Loading.lua b/IOS/luaviewEx/Example/luaviewEx/playground/widget/Loading.lua new file mode 100644 index 00000000..697e8c12 --- /dev/null +++ b/IOS/luaviewEx/Example/luaviewEx/playground/widget/Loading.lua @@ -0,0 +1,20 @@ +-- +-- Copyright 2017 Alibaba Group +-- License: MIT +-- Website: https://alibaba.github.io/LuaViewSDK +-- User: tuoli +-- Date: 17/3/30 +-- + +Navigation:title("Loading.lua") + +local meta = object:new() + +function meta:onCreate(args) + self.views = pica:getInstance():render("widget/loading.xml") + self.loading = self.views["loading"] + self.loading:start() +end + +return meta + diff --git a/IOS/luaviewEx/Example/luaviewEx/playground/widget/PagerView.lua b/IOS/luaviewEx/Example/luaviewEx/playground/widget/PagerView.lua new file mode 100644 index 00000000..a0195faa --- /dev/null +++ b/IOS/luaviewEx/Example/luaviewEx/playground/widget/PagerView.lua @@ -0,0 +1,56 @@ +-- +-- Copyright 2017 Alibaba Group +-- License: MIT +-- Website: https://alibaba.github.io/LuaViewSDK +-- User: tuoli +-- Date: 17/3/30 +-- + +Navigation:title("PagerView.lua") + +local meta = object:new() + +function meta:onCreate(args) + self.views = pica:getInstance():render("widget/pagerview.xml") + self.manualSlider = self.views["pagerView1"] + self.indicator1 = self.views["indicator1"] + self.autoSlider = self.views["pagerView2"] + self.indicator2 = self.views["indicator2"] + + self.color = {0xA066D3, 0xFF7F50, 0x228B22} + + self:handle() +end + +function meta:handle() + self.manualSlider:initParams({ + PageCount = 3, + Pages = { + Init = function(page, pos) + page.objs = pica:getInstance():render("widget/pagerview_page1.xml") + end, + Layout = function(page, pos) + page.objs["root"]:backgroundColor(self.color[pos]) + end + } + }) + self.manualSlider:reload() + self.manualSlider:indicator(self.indicator1) + + self.autoSlider:initParams({ + PageCount = 3, + Pages = { + Init = function(page, pos) + page.objs = pica:getInstance():render("widget/pagerview_page.xml") + end, + Layout = function(page, pos) + page.objs["root"]:backgroundColor(self.color[pos]) + end + } + }) + self.autoSlider:reload() + self.autoSlider:indicator(self.indicator2) +end + +return meta + diff --git a/IOS/luaviewEx/Example/luaviewEx/playground/widget/TextField.lua b/IOS/luaviewEx/Example/luaviewEx/playground/widget/TextField.lua new file mode 100644 index 00000000..29b25a10 --- /dev/null +++ b/IOS/luaviewEx/Example/luaviewEx/playground/widget/TextField.lua @@ -0,0 +1,21 @@ +-- +-- Copyright 2017 Alibaba Group +-- License: MIT +-- Website: https://alibaba.github.io/LuaViewSDK +-- User: tuoli +-- Date: 17/3/30 +-- + +Navigation:title("TextField.lua") + +local meta = object:new() + +function meta:onCreate(args) + if (sys.android) then + pica:getInstance():render("widget/textfield_android.xml") + else + pica:getInstance():render("widget/textfield_ios.xml") + end +end + +return meta \ No newline at end of file diff --git a/IOS/luaviewEx/Example/luaviewEx/playground/widget/WebView.lua b/IOS/luaviewEx/Example/luaviewEx/playground/widget/WebView.lua new file mode 100644 index 00000000..e4b3de19 --- /dev/null +++ b/IOS/luaviewEx/Example/luaviewEx/playground/widget/WebView.lua @@ -0,0 +1,35 @@ +-- +-- Copyright 2017 Alibaba Group +-- License: MIT +-- Website: https://alibaba.github.io/LuaViewSDK +-- User: tuoli +-- Date: 17/3/30 +-- + +Navigation:title("WebView.lua") + +local meta = object:new() + +function meta:onCreate(args) + self.views = pica:getInstance():render("widget/webview.xml") + self.web = self.views["web"] + + self:handle() +end + +function meta:handle() + self.web:callback({ + onPageStarted = function() + print("started") + end, + onPageFinished = function() + print("finished") + end, + onReceiveError = function(errorCode, description, failedUrl) + print("error", errorCode, description, failedUrl) + end + }) +end + +return meta + diff --git a/IOS/luaviewEx/Example/luaviewEx/playground/widget/animation.xml b/IOS/luaviewEx/Example/luaviewEx/playground/widget/animation.xml new file mode 100644 index 00000000..8e57087b --- /dev/null +++ b/IOS/luaviewEx/Example/luaviewEx/playground/widget/animation.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/IOS/luaviewEx/Example/luaviewEx/playground/widget/button.xml b/IOS/luaviewEx/Example/luaviewEx/playground/widget/button.xml new file mode 100644 index 00000000..4c35ffa0 --- /dev/null +++ b/IOS/luaviewEx/Example/luaviewEx/playground/widget/button.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/IOS/luaviewEx/Example/luaviewEx/playground/widget/hscrollview.xml b/IOS/luaviewEx/Example/luaviewEx/playground/widget/hscrollview.xml new file mode 100644 index 00000000..53099f09 --- /dev/null +++ b/IOS/luaviewEx/Example/luaviewEx/playground/widget/hscrollview.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/IOS/luaviewEx/Example/luaviewEx/playground/widget/image.xml b/IOS/luaviewEx/Example/luaviewEx/playground/widget/image.xml new file mode 100644 index 00000000..9711fb01 --- /dev/null +++ b/IOS/luaviewEx/Example/luaviewEx/playground/widget/image.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/IOS/luaviewEx/Example/luaviewEx/playground/widget/label_item.xml b/IOS/luaviewEx/Example/luaviewEx/playground/widget/label_item.xml new file mode 100644 index 00000000..a6378bf8 --- /dev/null +++ b/IOS/luaviewEx/Example/luaviewEx/playground/widget/label_item.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/IOS/luaviewEx/Example/luaviewEx/playground/widget/list.xml b/IOS/luaviewEx/Example/luaviewEx/playground/widget/list.xml new file mode 100644 index 00000000..9276e3c0 --- /dev/null +++ b/IOS/luaviewEx/Example/luaviewEx/playground/widget/list.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/IOS/luaviewEx/Example/luaviewEx/playground/widget/loading.xml b/IOS/luaviewEx/Example/luaviewEx/playground/widget/loading.xml new file mode 100644 index 00000000..441766af --- /dev/null +++ b/IOS/luaviewEx/Example/luaviewEx/playground/widget/loading.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/IOS/luaviewEx/Example/luaviewEx/playground/widget/pagerview.xml b/IOS/luaviewEx/Example/luaviewEx/playground/widget/pagerview.xml new file mode 100644 index 00000000..82ec8f28 --- /dev/null +++ b/IOS/luaviewEx/Example/luaviewEx/playground/widget/pagerview.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/IOS/luaviewEx/Example/luaviewEx/playground/widget/pagerview_page.xml b/IOS/luaviewEx/Example/luaviewEx/playground/widget/pagerview_page.xml new file mode 100644 index 00000000..8512eed6 --- /dev/null +++ b/IOS/luaviewEx/Example/luaviewEx/playground/widget/pagerview_page.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/IOS/luaviewEx/Example/luaviewEx/playground/widget/pagerview_page1.xml b/IOS/luaviewEx/Example/luaviewEx/playground/widget/pagerview_page1.xml new file mode 100644 index 00000000..2a716847 --- /dev/null +++ b/IOS/luaviewEx/Example/luaviewEx/playground/widget/pagerview_page1.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/IOS/luaviewEx/Example/luaviewEx/playground/widget/textfield_android.xml b/IOS/luaviewEx/Example/luaviewEx/playground/widget/textfield_android.xml new file mode 100644 index 00000000..7825acd0 --- /dev/null +++ b/IOS/luaviewEx/Example/luaviewEx/playground/widget/textfield_android.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/IOS/luaviewEx/Example/luaviewEx/playground/widget/textfield_ios.xml b/IOS/luaviewEx/Example/luaviewEx/playground/widget/textfield_ios.xml new file mode 100644 index 00000000..068e46d4 --- /dev/null +++ b/IOS/luaviewEx/Example/luaviewEx/playground/widget/textfield_ios.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/IOS/luaviewEx/Example/luaviewEx/playground/widget/webview.xml b/IOS/luaviewEx/Example/luaviewEx/playground/widget/webview.xml new file mode 100644 index 00000000..1b1fdb47 --- /dev/null +++ b/IOS/luaviewEx/Example/luaviewEx/playground/widget/webview.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/IOS/luaviewEx/LICENSE b/IOS/luaviewEx/LICENSE new file mode 100644 index 00000000..8f9d3e59 --- /dev/null +++ b/IOS/luaviewEx/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2017 yechunxiao19 + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/IOS/luaviewEx/README.md b/IOS/luaviewEx/README.md new file mode 100644 index 00000000..a3f21183 --- /dev/null +++ b/IOS/luaviewEx/README.md @@ -0,0 +1,29 @@ +# luaviewEx + +[![CI Status](http://img.shields.io/travis/yechunxiao19/luaviewEx.svg?style=flat)](https://travis-ci.org/yechunxiao19/luaviewEx) +[![Version](https://img.shields.io/cocoapods/v/luaviewEx.svg?style=flat)](http://cocoapods.org/pods/luaviewEx) +[![License](https://img.shields.io/cocoapods/l/luaviewEx.svg?style=flat)](http://cocoapods.org/pods/luaviewEx) +[![Platform](https://img.shields.io/cocoapods/p/luaviewEx.svg?style=flat)](http://cocoapods.org/pods/luaviewEx) + +## Example + +To run the example project, clone the repo, and run `pod install` from the Example directory first. + +## Requirements + +## Installation + +luaviewEx is available through [CocoaPods](http://cocoapods.org). To install +it, simply add the following line to your Podfile: + +```ruby +pod "luaviewEx" +``` + +## Author + +yechunxiao19, chunxiao.ycx@alibaba-inc.com + +## License + +luaviewEx is available under the MIT license. See the LICENSE file for more info. diff --git a/IOS/luaviewEx/_Pods.xcodeproj b/IOS/luaviewEx/_Pods.xcodeproj new file mode 120000 index 00000000..3c5a8e71 --- /dev/null +++ b/IOS/luaviewEx/_Pods.xcodeproj @@ -0,0 +1 @@ +Example/Pods/Pods.xcodeproj \ No newline at end of file diff --git a/IOS/luaviewEx/luaviewEx.podspec b/IOS/luaviewEx/luaviewEx.podspec new file mode 100644 index 00000000..ff8c29ee --- /dev/null +++ b/IOS/luaviewEx/luaviewEx.podspec @@ -0,0 +1,49 @@ +# +# Be sure to run `pod lib lint luaviewEx.podspec' to ensure this is a +# valid spec before submitting. +# +# Any lines starting with a # are optional, but their use is encouraged +# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html +# + +Pod::Spec.new do |s| + s.name = 'luaviewEx' + s.version = '0.1.0' + s.summary = 'A short description of luaviewEx.' + +# This description is used to generate tags and improve search results. +# * Think: What does it do? Why did you write it? What is the focus? +# * Try to keep it short, snappy and to the point. +# * Write the description between the DESC delimiters below. +# * Finally, don't worry about the indent, CocoaPods strips it! + + s.description = <<-DESC +TODO: Add long description of the pod here. + DESC + + s.homepage = 'https://github.com/yechunxiao19/luaviewEx' + # s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2' + s.license = { :type => 'MIT', :file => 'LICENSE' } + s.author = { 'yechunxiao19' => 'chunxiao.ycx@alibaba-inc.com' } + s.source = { :git => 'https://github.com/yechunxiao19/luaviewEx.git', :tag => s.version.to_s } + # s.social_media_url = 'https://twitter.com/' + + s.ios.deployment_target = '8.0' + + s.source_files = 'luaviewEx/Classes/*' + + s.resource_bundles = { + 'luaviewEx' => ['luaviewEx/Assets/**/*.{lua}'] + } + + s.resources = 'luaviewEx/luaview/luaview.bundle' + + s.public_header_files = 'Pod/Classes/*.h' + # s.frameworks = 'UIKit', 'MapKit' + s.dependency 'LuaViewSDK' + s.dependency 'SDWebImage', '~> 3.7.5' + s.dependency 'MJRefresh' + +s.xcconfig = { 'INFOPLIST_FILE' => '../../luaviewEx/luaviewEx/Classes/luaviewEx-info.plist'} + +end diff --git a/IOS/luaviewEx/luaviewEx/Assets/.gitkeep b/IOS/luaviewEx/luaviewEx/Assets/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/IOS/luaviewEx/luaviewEx/Assets/kit/main.lua b/IOS/luaviewEx/luaviewEx/Assets/kit/main.lua new file mode 100644 index 00000000..88fa4829 --- /dev/null +++ b/IOS/luaviewEx/luaviewEx/Assets/kit/main.lua @@ -0,0 +1,27 @@ +-- +-- Copyright 2017 Alibaba Group +-- License: MIT +-- Website: https://alibaba.github.io/LuaViewSDK +-- User: tuoli +-- Date: 17/3/30 +-- + +require("kit.object") +require("kit.util") +require("kit.sys") +require("kit.pica") + +function main(args) + if (args and type(args) == "table") then + g_page = require(args.page):new() + if (g_page.onCreate == nil) then + Toast("请实现" .. pageName .. ".lua页面的meta:onCreate()方法!") + else + g_page:onCreate(args) + end + else + Toast("页面间透传参数错误!") + end +end + +main(Bridge:args()) diff --git a/IOS/luaviewEx/luaviewEx/Assets/kit/object.lua b/IOS/luaviewEx/luaviewEx/Assets/kit/object.lua new file mode 100644 index 00000000..4ad88095 --- /dev/null +++ b/IOS/luaviewEx/luaviewEx/Assets/kit/object.lua @@ -0,0 +1,17 @@ +-- +-- Copyright 2017 Alibaba Group +-- License: MIT +-- Website: https://alibaba.github.io/LuaViewSDK +-- User: tuoli +-- Date: 17/3/30 +-- + +object = {} + +function object:new(o) + o = o or {} + setmetatable(o, self) + self.__index = self + return o +end + diff --git a/IOS/luaviewEx/luaviewEx/Assets/kit/pica.lua b/IOS/luaviewEx/luaviewEx/Assets/kit/pica.lua new file mode 100644 index 00000000..ef5bc303 --- /dev/null +++ b/IOS/luaviewEx/luaviewEx/Assets/kit/pica.lua @@ -0,0 +1,291 @@ +-- +-- Copyright 2017 Alibaba Group +-- License: MIT +-- Website: https://alibaba.github.io/LuaViewSDK +-- User: tuoli +-- Date: 17/3/30 +-- + +pica = {} + +local _gsub = string.gsub +local _find = string.find + +function pica:new(o) + o = o or {} + setmetatable(o, self) + self.__index = self + return o +end + +function pica:getInstance() + if (self.instance == nil) then + self.instance = self:new() + print("tuoli", "确保一个虚拟机只有一个xmlParser") + print("tuoli", "require kit.slaxdom start") + self.xmlParser = require("kit.slaxdom") + print("tuoli", "require kit.slaxdom end") + self.allViewObjects = {} -- 用于存储所有用该xmlParser解析的xml里的UI对象, 否则在iOS会被回收 + end + + return self.instance +end + +function pica:render(xmlFile) + print("tuoli", "render start", xmlFile) + + print("tuoli", "xml read start") + local data = File:read(xmlFile) + print("tuoli", "xml read end") + + if (type(data) ~= "string") then + data = tostring(data) + print("tuoli xml", string.len(data)) + end + + self.objs = {} + self.flxLayoutObjs = {} + + local identifierObjs = {} + + print("tuoli", "xml dom start") + local root = self.xmlParser:dom(data) + print("tuoli", "xml dom end") + print("tuoli", "parse element start") + self:parseElement(root, nil, identifierObjs) + print("tuoli", "parse element end") + print("tuoli", "flex start") + self:flexOrNot() + print("tuoli", "flex end") + print("tuoli", "render end", xmlFile) + return identifierObjs +end + +--[[ +-- 遍历self.objs,找出有子节点的父节点,并决定是否需要对其子节点进行flex布局 + ]] +function pica:flexOrNot() + for _k, _ in pairs(self.objs) do + local isFlex = false + if (_k.attr["css"] ~= nil) then + isFlex = true + end + + -- 如果遍历出来的对象是一个flex根节点,则遍历它的孩子节点,并设置flexChildren + if (isFlex == true and table.getn(_k.kids) > 0) then + local children = {} + for _, __v in pairs(_k.kids) do + if (self.objs[__v]) then + table.insert(children, self.objs[__v]) + end + end + if (table.getn(children) > 0) then + self.objs[_k]:flexChildren(children) + end + end + end + + -- iOS能否在SDK层屏蔽掉flxLayout的调用 + if (not sys.android) then + for _, _view in pairs(self.flxLayoutObjs) do + _view:flxLayout(true) + end + end +end + +function pica:isViewElement(element) + local view + if (element.name == "View") then + view = View() + elseif (element.name == "Text") then + view = Label() + if (sys.android) then + view:ellipsize(Ellipsize.END) -- default setting + end + view:textColor(0x000000) + elseif (element.name == "Button") then + view = Button() + elseif (element.name == "Image") then + view = Image() + elseif (element.name == "HScroll") then + view = HScrollView() + elseif (element.name == "Web") then + view = WebView() + elseif (element.name == "Input") then + view = TextField() + elseif (element.name == "List") then + view = CollectionView() + view:miniSpacing(0) + elseif (element.name == "Pull") then + view = RefreshCollectionView() + view:miniSpacing(0) + elseif (element.name == "Load") then + view = LoadingIndicator() + elseif (element.name == "Slider") then + view = PagerView() + elseif (element.name == "Indicator") then + view = PagerIndicator() + else + view = nil + end + + if (view ~= nil) then + self.objs[element] = view + table.insert(self.allViewObjects, view) + return true + else + return false + end +end + +--[[ +-- 分割字符串,并去除字符串中的空格符 + ]] +function pica:split(str, delimiter) + if str==nil or str=='' or delimiter==nil then + return nil + end + + local result = {} + for match in (str..delimiter):gmatch("(.-)"..delimiter) do + local _match, _ = string.gsub(match, "^%s*(.-)%s*$", "%1") + table.insert(result, _match) + end + return result +end + +function pica:parseElement(element, parent, identifierObjs) + if (element.type == "comment") then + return + end + + local isContains = self:isViewElement(element) + if (isContains == true and element.attr ~= nil) then + for _, _v in ipairs(element.attr) do + if (_v.name == "frame") then + if (parent and (parent.name == "View" or parent.name == "HScroll")) then + self.objs[parent]:addView(self.objs[element]) + end + local paramFun = sys:loadstring("return " .. _v.value) + self.objs[element]:frame(paramFun()) + elseif (_v.name == "bg") then + self.objs[element]:backgroundColor(tonumber(_v.value)) + elseif (_v.name == "color") then + self.objs[element]:color(tonumber(_v.value)) + elseif (_v.name == "id") then + -- 考虑到性能问题,不采用数组的形式来存取开发者所关注的对象,而是使用字典的形式来存取。 + identifierObjs[_v.value] = self.objs[element] + elseif (_v.name == "css") then +-- print("tuoli css start") + _v.value = _gsub(_v.value, "-","_") + local paramFun = sys:loadstring("return " .. _v.value) + local t = paramFun() + local css = "" + for _k, _v in pairs(t) do + _k = _gsub(_k, "_","-") + if (_find(_k, "margin")) then + css = css .. _k .. ":" .. _v*sys.scale .. "," + else + css = css .. _k .. ":" .. _v .. "," + end + end +-- print("tuoli css end") + self.objs[element]:flexCss(css) + if (not sys.android) then + if (element.name == "View" and parent and (parent.name ~= "View" or (parent.name == "View" and parent.attr["css"] == nil))) then + table.insert(self.flxLayoutObjs, self.objs[element]) + end + end + elseif (_v.name == "title") then + self.objs[element]:title(_v.value) + elseif (_v.name == "titleColor") then + self.objs[element]:titleColor(tonumber(_v.value)) + elseif (_v.name == "image") then + if (element.name == "Button") then + local params = self:split(_v.value, ",") + self.objs[element]:image(params[1], params[2]) + elseif (element.name == "Image") then + self.objs[element]:image(_v.value) + end + elseif (_v.name == "corner") then + self.objs[element]:cornerRadius(tonumber(_v.value)*sys.scale) + elseif (_v.name == "borderColor") then + self.objs[element]:borderColor(tonumber(_v.value)) + elseif (_v.name == "borderWidth") then + self.objs[element]:borderWidth(tonumber(_v.value)) + elseif (_v.name == "textColor") then + if (not sys.android and string.len(_v.value) == 10) then + local alphaStr = string.sub(_v.value, 3, 4) + local alpha = tonumber(alphaStr)/tonumber("0xFF") + self.objs[element]:textColor(tonumber(_v.value), alpha) + else + self.objs[element]:textColor(tonumber(_v.value)) + end + elseif (_v.name == "fontSize") then + self.objs[element]:fontSize(tonumber(_v.value)*sys.scale) + elseif (_v.name == "lineCount") then + self.objs[element]:lineCount(tonumber(_v.value)) + elseif (_v.name == "alpha") then + self.objs[element]:alpha(tonumber(_v.value)) + elseif (_v.name == "text") then + self.objs[element]:text(_v.value) + elseif (_v.name == "textAlign") then + local paramFun = sys:loadstring("return " .. _v.value) + self.objs[element]:textAlign(paramFun()) + elseif (_v.name == "scaleType") then + local paramFun = sys:loadstring("return " .. _v.value) + self.objs[element]:scaleType(paramFun()) + elseif (_v.name == "hint") then + self.objs[element]:hint(_v.value) + elseif (_v.name == "space") then + self.objs[element]:miniSpacing(tonumber(_v.value)) + elseif (_v.name == "autoScroll") then + self.objs[element]:autoScroll(tonumber(_v.value)) + elseif (_v.name == "looping") then + if (_v.value == "true") then + self.objs[element]:looping(true) + else + self.objs[element]:looping(false) + end + elseif (_v.name == "selected") then + self.objs[element]:selectedColor(tonumber(_v.value)) + elseif (_v.name == "unselected") then + self.objs[element]:unselectedColor(tonumber(_v.value)) + elseif (_v.name == "showScrollIndicator") then + if (_v.value == "true") then + self.objs[element]:showScrollIndicator(true) + else + self.objs[element]:showScrollIndicator(false) + end + elseif (_v.name == "url") then + self.objs[element]:loadUrl(_v.value) + elseif (_v.name == "hide") then + if (_v.value == "true") then + self.objs[element]:hide(true) + else + self.objs[element]:hide(false) + end + elseif (_v.name == "contentSize") then + if (not sys.android) then + local paramFun = sys:loadstring("return " .. _v.value) + self.objs[element]:contentSize(paramFun()) + end + else + print("LuaError::Layout", "方法名不对: " .. _v.name) + end + end + end + + if (element.kids ~= nil) then + for _, kid in pairs(element.kids) do + self:parseElement(kid, element, identifierObjs); + end + end +end + +return pica + + + + + diff --git a/IOS/luaviewEx/luaviewEx/Assets/kit/slaxdom.lua b/IOS/luaviewEx/luaviewEx/Assets/kit/slaxdom.lua new file mode 100755 index 00000000..6d2d8087 --- /dev/null +++ b/IOS/luaviewEx/luaviewEx/Assets/kit/slaxdom.lua @@ -0,0 +1,55 @@ +-- Optional parser that creates a flat DOM from parsing +local SLAXML = require 'kit.slaxml' +function SLAXML:dom(xml,opts) + if not opts then opts={} end + local rich = not opts.simple + local push, pop = table.insert, table.remove + local stack = {} + local doc = { type="document", name="#doc", kids={} } + local current = doc + local builder = SLAXML:parser{ + startElement = function(name,nsURI) + local el = { type="element", name=name, kids={}, el=rich and {} or nil, attr={}, nsURI=nsURI, parent=rich and current or nil } + if current==doc then + if doc.root then error(("Encountered element '%s' when the document already has a root '%s' element"):format(name,doc.root.name)) end + doc.root = el + end + push(current.kids,el) + if current.el then push(current.el,el) end + current = el + push(stack,el) +-- print("tuoli 999", name) + end, + attribute = function(name,value,nsURI) + if not current or current.type~="element" then error(("Encountered an attribute %s=%s but I wasn't inside an element"):format(name,value)) end + local attr = {type='attribute',name=name,nsURI=nsURI,value=value,parent=rich and current or nil} + if rich then current.attr[name] = value end + push(current.attr,attr) +-- print("tuoli 999", name) + end, + closeElement = function(name) + if current.name~=name or current.type~="element" then error(("Received a close element notification for '%s' but was inside a '%s' %s"):format(name,current.name,current.type)) end + pop(stack) + current = stack[#stack] +-- print("tuoli 999", name) + end, + text = function(value) + if current.type~='document' then + if current.type~="element" then error(("Received a text notification '%s' but was inside a %s"):format(value,current.type)) end + push(current.kids,{type='text',name='#text',value=value,parent=rich and current or nil}) + end +-- print("tuoli 999", value) + end, + comment = function(value) + push(current.kids,{type='comment',name='#comment',value=value,parent=rich and current or nil}) +-- print("tuoli 999", value) + end, + pi = function(name,value) + push(current.kids,{type='pi',name=name,value=value,parent=rich and current or nil}) +-- print("tuoli 999", name) + end + } + builder:parse(xml,opts) + return doc +end +return SLAXML \ No newline at end of file diff --git a/IOS/luaviewEx/luaviewEx/Assets/kit/slaxml.lua b/IOS/luaviewEx/luaviewEx/Assets/kit/slaxml.lua new file mode 100755 index 00000000..b57cb272 --- /dev/null +++ b/IOS/luaviewEx/luaviewEx/Assets/kit/slaxml.lua @@ -0,0 +1,257 @@ +--[=====================================================================[ +v0.7 Copyright © 2013-2014 Gavin Kistner ; MIT Licensed +See http://github.com/Phrogz/SLAXML for details. +--]=====================================================================] +local SLAXML = { + VERSION = "0.7", + _call = { + pi = function(target,content) + print(string.format("",target,content)) + end, + comment = function(content) + print(string.format("",content)) + end, + startElement = function(name,nsURI,nsPrefix) + io.write("<") + if nsPrefix then io.write(nsPrefix,":") end + io.write(name) + if nsURI then io.write(" (ns='",nsURI,"')") end + print(">") + end, + attribute = function(name,value,nsURI,nsPrefix) + io.write(' ') + if nsPrefix then io.write(nsPrefix,":") end + io.write(name,'=',string.format('%q',value)) + if nsURI then io.write(" (ns='",nsURI,"')") end + io.write("\n") + end, + text = function(text) + print(string.format(" text: %q",text)) + end, + closeElement = function(name,nsURI,nsPrefix) + print(string.format("",name)) + end, + } +} + +function SLAXML:parser(callbacks) + return { _call=callbacks or self._call, parse=SLAXML.parse } +end + +function SLAXML:parse(xml,options) + if not options then options = { stripWhitespace=false } end + + -- Cache references for maximum speed + local find, sub, gsub, char, push, pop, concat = string.find, string.sub, string.gsub, string.char, table.insert, table.remove, table.concat + local first, last, match1, match2, match3, pos2, nsURI + local unpack = unpack or table.unpack + local pos = 1 + local state = "text" + local textStart = 1 + local currentElement={} + local currentAttributes={} + local currentAttributeCt -- manually track length since the table is re-used + local nsStack = {} + local anyElement = false + + local utf8markers = { {0x7FF,192}, {0xFFFF,224}, {0x1FFFFF,240} } + local function utf8(decimal) -- convert unicode code point to utf-8 encoded character string + if decimal<128 then return char(decimal) end + local charbytes = {} + for bytes,vals in ipairs(utf8markers) do + if decimal<=vals[1] then + for b=bytes+1,2,-1 do + local mod = decimal%64 + decimal = (decimal-mod)/64 + charbytes[b] = char(128+mod) + end + charbytes[1] = char(vals[2]+decimal) + return concat(charbytes) + end + end + end + local entityMap = { ["lt"]="<", ["gt"]=">", ["amp"]="&", ["quot"]='"', ["apos"]="'" } + local entitySwap = function(orig,n,s) return entityMap[s] or n=="#" and utf8(tonumber('0'..s)) or orig end + local function unescape(str) return gsub( str, '(&(#?)([%d%a]+);)', entitySwap ) end + + local function finishText() + if first>textStart and self._call.text then + local text = sub(xml,textStart,first-1) + if options.stripWhitespace then + text = gsub(text,'^%s+','') + text = gsub(text,'%s+$','') + if #text==0 then text=nil end + end + if text then self._call.text(unescape(text)) end + end + end + + local function findPI() + first, last, match1, match2 = find( xml, '^<%?([:%a_][:%w_.-]*) ?(.-)%?>', pos ) + if first then + finishText() + if self._call.pi then self._call.pi(match1,match2) end + pos = last+1 + textStart = pos + return true + end + end + + local function findComment() + first, last, match1 = find( xml, '^', pos ) + if first then + finishText() + if self._call.comment then self._call.comment(match1) end + pos = last+1 + textStart = pos + return true + end + end + + local function nsForPrefix(prefix) + if prefix=='xml' then return 'http://www.w3.org/XML/1998/namespace' end -- http://www.w3.org/TR/xml-names/#ns-decl + for i=#nsStack,1,-1 do if nsStack[i][prefix] then return nsStack[i][prefix] end end + error(("Cannot find namespace for prefix %s"):format(prefix)) + end + + local function startElement() + anyElement = true + first, last, match1 = find( xml, '^<([%a_][%w_.-]*)', pos ) + if first then + currentElement[2] = nil -- reset the nsURI, since this table is re-used + currentElement[3] = nil -- reset the nsPrefix, since this table is re-used + finishText() + pos = last+1 + first,last,match2 = find(xml, '^:([%a_][%w_.-]*)', pos ) + if first then + currentElement[1] = match2 + currentElement[3] = match1 -- Save the prefix for later resolution + match1 = match2 + pos = last+1 + else + currentElement[1] = match1 + for i=#nsStack,1,-1 do if nsStack[i]['!'] then currentElement[2] = nsStack[i]['!']; break end end + end + currentAttributeCt = 0 + push(nsStack,{}) + return true + end + end + + local function findAttribute() + first, last, match1 = find( xml, '^%s+([:%a_][:%w_.-]*)%s*=%s*', pos ) + if first then + pos2 = last+1 + first, last, match2 = find( xml, '^"([^<"]*)"', pos2 ) -- FIXME: disallow non-entity ampersands + if first then + pos = last+1 + match2 = unescape(match2) + else + first, last, match2 = find( xml, "^'([^<']*)'", pos2 ) -- FIXME: disallow non-entity ampersands + if first then + pos = last+1 + match2 = unescape(match2) + end + end + end + if match1 and match2 then + local currentAttribute = {match1,match2} + local prefix,name = string.match(match1,'^([^:]+):([^:]+)$') + if prefix then + if prefix=='xmlns' then + nsStack[#nsStack][name] = match2 + else + currentAttribute[1] = name + currentAttribute[4] = prefix + end + else + if match1=='xmlns' then + nsStack[#nsStack]['!'] = match2 + currentElement[2] = match2 + end + end + currentAttributeCt = currentAttributeCt + 1 + currentAttributes[currentAttributeCt] = currentAttribute + return true + end + end + + local function findCDATA() + first, last, match1 = find( xml, '^', pos ) + if first then + finishText() + if self._call.text then self._call.text(match1) end + pos = last+1 + textStart = pos + return true + end + end + + local function closeElement() + first, last, match1 = find( xml, '^%s*(/?)>', pos ) + if first then + state = "text" + pos = last+1 + textStart = pos + + -- Resolve namespace prefixes AFTER all new/redefined prefixes have been parsed + if currentElement[3] then currentElement[2] = nsForPrefix(currentElement[3]) end + if self._call.startElement then self._call.startElement(unpack(currentElement)) end + if self._call.attribute then + for i=1,currentAttributeCt do + if currentAttributes[i][4] then currentAttributes[i][3] = nsForPrefix(currentAttributes[i][4]) end + self._call.attribute(unpack(currentAttributes[i])) + end + end + + if match1=="/" then + pop(nsStack) + if self._call.closeElement then self._call.closeElement(unpack(currentElement)) end + end + return true + end + end + + local function findElementClose() + first, last, match1, match2 = find( xml, '^', pos ) + if first then + nsURI = nil + for i=#nsStack,1,-1 do if nsStack[i]['!'] then nsURI = nsStack[i]['!']; break end end + else + first, last, match2, match1 = find( xml, '^', pos ) + if first then nsURI = nsForPrefix(match2) end + end + if first then + finishText() + if self._call.closeElement then self._call.closeElement(match1,nsURI) end + pos = last+1 + textStart = pos + pop(nsStack) + return true + end + end + + while pos<#xml do + if state=="text" then + if not (findPI() or findComment() or findCDATA() or findElementClose()) then + if startElement() then + state = "attributes" + else + first, last = find( xml, '^[^<]+', pos ) + pos = (first and last or pos) + 1 + end + end + elseif state=="attributes" then + if not findAttribute() then + if not closeElement() then + error("Was in an element and couldn't find attributes or the close.") + end + end + end + end + + if not anyElement then error("Parsing did not discover any elements") end + if #nsStack > 0 then error("Parsing ended with unclosed elements") end +end + +return SLAXML diff --git a/IOS/luaviewEx/luaviewEx/Assets/kit/sys.lua b/IOS/luaviewEx/luaviewEx/Assets/kit/sys.lua new file mode 100644 index 00000000..d9600a35 --- /dev/null +++ b/IOS/luaviewEx/luaviewEx/Assets/kit/sys.lua @@ -0,0 +1,37 @@ +-- +-- Copyright 2017 Alibaba Group +-- License: MIT +-- Website: https://alibaba.github.io/LuaViewSDK +-- User: tuoli +-- Date: 17/3/30 +-- + +if (sys == nil) then + sys = {} + + -- + -- Variables + -- + sys.android = System:android() + sys.scrW, sys.scrH = System:screenSize() + sys.contW = sys.scrW + sys.scale = sys.scrW/375 > 1 and 1 or sys.scrW/375 <= 1 and sys.scrW/375 + -- 减掉ActionBar和StatusBar的高度 + if (sys.android) then + local device = System:device() + sys.contH = device.window_height - device.status_bar_height - device.nav_height + else + sys.contH = sys.scrH - 64 -- iOS, 稳定在这个值 + end + + -- + -- Functions + -- + function sys:loadstring(param) + if (sys.android) then + return load(param) + else + return loadstring(param) + end + end +end \ No newline at end of file diff --git a/IOS/luaviewEx/luaviewEx/Assets/kit/util.lua b/IOS/luaviewEx/luaviewEx/Assets/kit/util.lua new file mode 100644 index 00000000..e7cc4c8e --- /dev/null +++ b/IOS/luaviewEx/luaviewEx/Assets/kit/util.lua @@ -0,0 +1,81 @@ +-- +-- Copyright 2017 Alibaba Group +-- License: MIT +-- Website: https://alibaba.github.io/LuaViewSDK +-- User: tuoli +-- Date: 17/3/30 +-- + +if (util == nil) then + util = {} + function util:printTable(t, exclusions) + if (type(t) == "table") then + local nests = 0 + if not exclusions then exclusions = {} end + local recurse = function(t, recurse, exclusions) + indent = function() + local dent = "" + for i = 1, nests do + dent = dent .. " " + end + return dent + end + local excluded = function(key) + for k, v in pairs(exclusions) do + if v == key then + return true + end + end + return false + end + local isFirst = true + for k, v in pairs(t) do + local dent = indent() + if isFirst then + print(dent .. "|") + isFirst = false + end + dent = indent() + if type(v) == "table" and not excluded(k) then + print(dent .. "|- " .. tostring(k) .. ": " .. type(v)) + nests = nests + 1 + recurse(v, recurse, exclusions) + elseif excluded(k) then + print(dent .. "|- " .. tostring(k) .. ": " .. type(v)) + elseif type(v) == "userdata" or type(v) == "function" then + print(dent .. "|- " .. tostring(k) .. ": " .. type(v)) + elseif type(v) == "string" then + print(dent .. "|- " .. tostring(k) .. ": " .. "\"" .. tostring(v) .. "\"") + else + print(dent .. "|- " .. tostring(k) .. ": " .. tostring(v)) + end + end + nests = nests - 1 + end + + nests = 0 + + if t then + print("### START TABLE ###") + for k, v in pairs(t) do + if type(v) == "table" then + print("|- " .. k .. ": " .. type(v)) + nests = nests + 1 + recurse(v, recurse, exclusions) + elseif type(v) == "userdata" or type(v) == "function" then + print("|- " .. tostring(k) .. ": " .. type(v)) + elseif type(v) == "string" then + print("|- " .. tostring(k) .. ": " .. "\"" .. tostring(v) .. "\"") + else + print("|- " .. tostring(k) .. ": " .. tostring(v)) + end + end + print("### END TABLE ###") + else + print("NIL TABLE") + end + else + print(t) + end + end +end \ No newline at end of file diff --git a/IOS/luaviewEx/luaviewEx/Classes/.gitkeep b/IOS/luaviewEx/luaviewEx/Classes/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/IOS/luaviewEx/luaviewEx/Classes/LVExButton.h b/IOS/luaviewEx/luaviewEx/Classes/LVExButton.h new file mode 100644 index 00000000..b2af1f35 --- /dev/null +++ b/IOS/luaviewEx/luaviewEx/Classes/LVExButton.h @@ -0,0 +1,13 @@ +// +// LVExButton.h +// Pods +// +// Created by OolongTea on 17/4/6. +// +// + +#import "LVButton.h" + +@interface LVExButton : LVButton + +@end diff --git a/IOS/luaviewEx/luaviewEx/Classes/LVExButton.m b/IOS/luaviewEx/luaviewEx/Classes/LVExButton.m new file mode 100644 index 00000000..d9df656c --- /dev/null +++ b/IOS/luaviewEx/luaviewEx/Classes/LVExButton.m @@ -0,0 +1,18 @@ +// +// LVExButton.m +// Pods +// +// Created by OolongTea on 17/4/6. +// +// + +#import "LVExButton.h" +#import + +@implementation LVExButton + +-(void) setWebImageUrl:(NSString *)url forState:(UIControlState)state finished:(LVLoadFinished)finished{ + [self sd_setBackgroundImageWithURL:[NSURL URLWithString:url] forState:state completed:nil]; +} + +@end diff --git a/IOS/luaviewEx/luaviewEx/Classes/LVExCollectionView.h b/IOS/luaviewEx/luaviewEx/Classes/LVExCollectionView.h new file mode 100644 index 00000000..c88989b4 --- /dev/null +++ b/IOS/luaviewEx/luaviewEx/Classes/LVExCollectionView.h @@ -0,0 +1,13 @@ +// +// LVExCollectionView.h +// Pods +// +// Created by OolongTea on 17/4/7. +// +// + +#import "LVCollectionView.h" + +@interface LVExCollectionView : LVCollectionView + +@end diff --git a/IOS/luaviewEx/luaviewEx/Classes/LVExCollectionView.m b/IOS/luaviewEx/luaviewEx/Classes/LVExCollectionView.m new file mode 100644 index 00000000..542956bd --- /dev/null +++ b/IOS/luaviewEx/luaviewEx/Classes/LVExCollectionView.m @@ -0,0 +1,45 @@ +// +// LVExCollectionView.m +// Pods +// +// Created by OolongTea on 17/4/7. +// +// + +#import "LVExCollectionView.h" +#import +#import + +@implementation LVExCollectionView + +// 下拉刷新 +-(void) lv_initRefreshHeader{// 初始化下拉刷新功能 + MJRefreshNormalHeader* refreshHeader = [[MJRefreshNormalHeader alloc] init]; + self.mj_header = refreshHeader; + + __weak typeof(self) weakSelf = self; + refreshHeader.refreshingBlock = ^(){ + [weakSelf lv_refreshHeaderToRefresh]; + }; +} + +- (void) lv_hiddenRefreshHeader:(BOOL) hidden{ + self.mj_header.hidden = hidden; +} + +- (void) lv_beginRefreshing{// 进入刷新状态 + [self.mj_header beginRefreshing]; +} + +- (void) lv_endRefreshing{// 结束刷新状态 + [self.mj_header endRefreshing]; +} + +- (BOOL) lv_isRefreshing{// 是否正在刷新 + return self.mj_header.isRefreshing; +} + +-(void) dealloc{ +} + +@end diff --git a/IOS/luaviewEx/luaviewEx/Classes/LVExImage.h b/IOS/luaviewEx/luaviewEx/Classes/LVExImage.h new file mode 100644 index 00000000..b2ffc66c --- /dev/null +++ b/IOS/luaviewEx/luaviewEx/Classes/LVExImage.h @@ -0,0 +1,13 @@ +// +// LVExImage.h +// Pods +// +// Created by OolongTea on 17/4/6. +// +// + +#import "LVImage.h" + +@interface LVExImage : LVImage + +@end diff --git a/IOS/luaviewEx/luaviewEx/Classes/LVExImage.m b/IOS/luaviewEx/luaviewEx/Classes/LVExImage.m new file mode 100644 index 00000000..6ea33582 --- /dev/null +++ b/IOS/luaviewEx/luaviewEx/Classes/LVExImage.m @@ -0,0 +1,33 @@ +// +// LVExImage.m +// Pods +// +// Created by OolongTea on 17/4/6. +// +// + +#import "LVExImage.h" +#import + +@implementation LVExImage + +-(void) setWebImageUrl:(NSURL*) url finished:(LVLoadFinished) finished{ + __weak LVExImage* weakImageView = self; + [self sd_setImageWithURL:url placeholderImage:nil + completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL* url){ + double duration = (cacheType == SDImageCacheTypeNone && !error)?.4f:.0f; + if( duration>0 ) { + weakImageView.alpha = 0; + [UIView animateWithDuration:duration animations:^{ + weakImageView.alpha = 1.0f; + }]; + } else { + weakImageView.alpha = 1.0f; + } + if( finished ) { + finished( error ); + } + }]; +} + +@end diff --git a/IOS/luaviewEx/luaviewEx/Classes/LVViewController.h b/IOS/luaviewEx/luaviewEx/Classes/LVViewController.h new file mode 100644 index 00000000..0e48de44 --- /dev/null +++ b/IOS/luaviewEx/luaviewEx/Classes/LVViewController.h @@ -0,0 +1,17 @@ +// +// LVViewController.h +// Pods +// +// Created by OolongTea on 17/4/6. +// +// + +#import +#import "LViewController.h" + +@interface LVViewController : LViewController + +@property(nonatomic,copy) NSDictionary* args; +- (instancetype)initWithPackage; + +@end diff --git a/IOS/luaviewEx/luaviewEx/Classes/LVViewController.m b/IOS/luaviewEx/luaviewEx/Classes/LVViewController.m new file mode 100644 index 00000000..8ac0faf8 --- /dev/null +++ b/IOS/luaviewEx/luaviewEx/Classes/LVViewController.m @@ -0,0 +1,74 @@ +// +// LVViewController.m +// Pods +// +// Created by OolongTea on 17/4/6. +// +// + +#import "LVViewController.h" +#import "LView.h" +#import "LVExImage.h" +#import "LVExButton.h" +#import "LVExCollectionView.h" + +@interface LVViewController () + +@end + +@implementation LVViewController + +- (instancetype)initWithPackage { + NSURL *bundleUrl = [[NSBundle mainBundle] URLForResource:@"luaview" withExtension:@"bundle"]; + NSBundle *customBundle = [NSBundle bundleWithURL:bundleUrl]; + NSString *bundlePath = [customBundle bundlePath]; + if (self = [super initWithPackage:bundlePath mainScript:@"kit/main.lua"]) { + self.args = @{@"page":@"App"}; + } + + return self; +} + +- (void)viewDidLoad +{ + [super viewDidLoad]; + + self.view.backgroundColor = [UIColor whiteColor]; + +} + +- (void)didReceiveMemoryWarning +{ + [super didReceiveMemoryWarning]; + // Dispose of any resources that can be recreated. +} + +- (void)willCreateLuaView { + [super willCreateLuaView]; + + while (self.view.subviews.count) { + UIView* child = self.view.subviews.lastObject; + [child removeFromSuperview]; + } +} + +- (void)didCreateLuaView:(LView *)view { + [super didCreateLuaView:view]; + + self.lv[@"RefreshCollectionView"] = [LVExCollectionView class]; + self.lv[@"Image"] = [LVExImage class]; + self.lv[@"Button"] = [LVExButton class]; + // 注册 外部对象. + self.lv[@"Bridge"] = self; +} + +-(void)require:(NSDictionary*)args { + NSURL *bundleUrl = [[NSBundle mainBundle] URLForResource:@"luaview" withExtension:@"bundle"]; + NSBundle *customBundle = [NSBundle bundleWithURL:bundleUrl]; + NSString *bundlePath = [customBundle bundlePath]; + LVViewController* c = [[LVViewController alloc] initWithPackage:bundlePath mainScript:@"kit/main.lua"]; + c.args = args; + [self.navigationController pushViewController:c animated:YES]; +} + +@end diff --git a/IOS/luaviewEx/luaviewEx/Classes/luaviewEx-info.plist b/IOS/luaviewEx/luaviewEx/Classes/luaviewEx-info.plist new file mode 100644 index 00000000..9e2ad891 --- /dev/null +++ b/IOS/luaviewEx/luaviewEx/Classes/luaviewEx-info.plist @@ -0,0 +1,24 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleIdentifier + com.taobao.luaviewEx + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + ${PRODUCT_NAME} + CFBundlePackageType + BNDL + CFBundleShortVersionString + 0.1.6 + CFBundleSignature + ???? + CFBundleVersion + ${CURRENT_PROJECT_VERSION} + NSPrincipalClass + + + diff --git a/IOS/luaviewEx/luaviewEx/luaview/luaview.bundle/Info.plist b/IOS/luaviewEx/luaviewEx/luaview/luaview.bundle/Info.plist new file mode 100644 index 00000000..c2c026d5 Binary files /dev/null and b/IOS/luaviewEx/luaviewEx/luaview/luaview.bundle/Info.plist differ diff --git a/IOS/luaviewEx/luaviewEx/luaview/luaview.bundle/kit/main.lua b/IOS/luaviewEx/luaviewEx/luaview/luaview.bundle/kit/main.lua new file mode 100644 index 00000000..88fa4829 --- /dev/null +++ b/IOS/luaviewEx/luaviewEx/luaview/luaview.bundle/kit/main.lua @@ -0,0 +1,27 @@ +-- +-- Copyright 2017 Alibaba Group +-- License: MIT +-- Website: https://alibaba.github.io/LuaViewSDK +-- User: tuoli +-- Date: 17/3/30 +-- + +require("kit.object") +require("kit.util") +require("kit.sys") +require("kit.pica") + +function main(args) + if (args and type(args) == "table") then + g_page = require(args.page):new() + if (g_page.onCreate == nil) then + Toast("请实现" .. pageName .. ".lua页面的meta:onCreate()方法!") + else + g_page:onCreate(args) + end + else + Toast("页面间透传参数错误!") + end +end + +main(Bridge:args()) diff --git a/IOS/luaviewEx/luaviewEx/luaview/luaview.bundle/kit/object.lua b/IOS/luaviewEx/luaviewEx/luaview/luaview.bundle/kit/object.lua new file mode 100644 index 00000000..4ad88095 --- /dev/null +++ b/IOS/luaviewEx/luaviewEx/luaview/luaview.bundle/kit/object.lua @@ -0,0 +1,17 @@ +-- +-- Copyright 2017 Alibaba Group +-- License: MIT +-- Website: https://alibaba.github.io/LuaViewSDK +-- User: tuoli +-- Date: 17/3/30 +-- + +object = {} + +function object:new(o) + o = o or {} + setmetatable(o, self) + self.__index = self + return o +end + diff --git a/IOS/luaviewEx/luaviewEx/luaview/luaview.bundle/kit/pica.lua b/IOS/luaviewEx/luaviewEx/luaview/luaview.bundle/kit/pica.lua new file mode 100644 index 00000000..ef5bc303 --- /dev/null +++ b/IOS/luaviewEx/luaviewEx/luaview/luaview.bundle/kit/pica.lua @@ -0,0 +1,291 @@ +-- +-- Copyright 2017 Alibaba Group +-- License: MIT +-- Website: https://alibaba.github.io/LuaViewSDK +-- User: tuoli +-- Date: 17/3/30 +-- + +pica = {} + +local _gsub = string.gsub +local _find = string.find + +function pica:new(o) + o = o or {} + setmetatable(o, self) + self.__index = self + return o +end + +function pica:getInstance() + if (self.instance == nil) then + self.instance = self:new() + print("tuoli", "确保一个虚拟机只有一个xmlParser") + print("tuoli", "require kit.slaxdom start") + self.xmlParser = require("kit.slaxdom") + print("tuoli", "require kit.slaxdom end") + self.allViewObjects = {} -- 用于存储所有用该xmlParser解析的xml里的UI对象, 否则在iOS会被回收 + end + + return self.instance +end + +function pica:render(xmlFile) + print("tuoli", "render start", xmlFile) + + print("tuoli", "xml read start") + local data = File:read(xmlFile) + print("tuoli", "xml read end") + + if (type(data) ~= "string") then + data = tostring(data) + print("tuoli xml", string.len(data)) + end + + self.objs = {} + self.flxLayoutObjs = {} + + local identifierObjs = {} + + print("tuoli", "xml dom start") + local root = self.xmlParser:dom(data) + print("tuoli", "xml dom end") + print("tuoli", "parse element start") + self:parseElement(root, nil, identifierObjs) + print("tuoli", "parse element end") + print("tuoli", "flex start") + self:flexOrNot() + print("tuoli", "flex end") + print("tuoli", "render end", xmlFile) + return identifierObjs +end + +--[[ +-- 遍历self.objs,找出有子节点的父节点,并决定是否需要对其子节点进行flex布局 + ]] +function pica:flexOrNot() + for _k, _ in pairs(self.objs) do + local isFlex = false + if (_k.attr["css"] ~= nil) then + isFlex = true + end + + -- 如果遍历出来的对象是一个flex根节点,则遍历它的孩子节点,并设置flexChildren + if (isFlex == true and table.getn(_k.kids) > 0) then + local children = {} + for _, __v in pairs(_k.kids) do + if (self.objs[__v]) then + table.insert(children, self.objs[__v]) + end + end + if (table.getn(children) > 0) then + self.objs[_k]:flexChildren(children) + end + end + end + + -- iOS能否在SDK层屏蔽掉flxLayout的调用 + if (not sys.android) then + for _, _view in pairs(self.flxLayoutObjs) do + _view:flxLayout(true) + end + end +end + +function pica:isViewElement(element) + local view + if (element.name == "View") then + view = View() + elseif (element.name == "Text") then + view = Label() + if (sys.android) then + view:ellipsize(Ellipsize.END) -- default setting + end + view:textColor(0x000000) + elseif (element.name == "Button") then + view = Button() + elseif (element.name == "Image") then + view = Image() + elseif (element.name == "HScroll") then + view = HScrollView() + elseif (element.name == "Web") then + view = WebView() + elseif (element.name == "Input") then + view = TextField() + elseif (element.name == "List") then + view = CollectionView() + view:miniSpacing(0) + elseif (element.name == "Pull") then + view = RefreshCollectionView() + view:miniSpacing(0) + elseif (element.name == "Load") then + view = LoadingIndicator() + elseif (element.name == "Slider") then + view = PagerView() + elseif (element.name == "Indicator") then + view = PagerIndicator() + else + view = nil + end + + if (view ~= nil) then + self.objs[element] = view + table.insert(self.allViewObjects, view) + return true + else + return false + end +end + +--[[ +-- 分割字符串,并去除字符串中的空格符 + ]] +function pica:split(str, delimiter) + if str==nil or str=='' or delimiter==nil then + return nil + end + + local result = {} + for match in (str..delimiter):gmatch("(.-)"..delimiter) do + local _match, _ = string.gsub(match, "^%s*(.-)%s*$", "%1") + table.insert(result, _match) + end + return result +end + +function pica:parseElement(element, parent, identifierObjs) + if (element.type == "comment") then + return + end + + local isContains = self:isViewElement(element) + if (isContains == true and element.attr ~= nil) then + for _, _v in ipairs(element.attr) do + if (_v.name == "frame") then + if (parent and (parent.name == "View" or parent.name == "HScroll")) then + self.objs[parent]:addView(self.objs[element]) + end + local paramFun = sys:loadstring("return " .. _v.value) + self.objs[element]:frame(paramFun()) + elseif (_v.name == "bg") then + self.objs[element]:backgroundColor(tonumber(_v.value)) + elseif (_v.name == "color") then + self.objs[element]:color(tonumber(_v.value)) + elseif (_v.name == "id") then + -- 考虑到性能问题,不采用数组的形式来存取开发者所关注的对象,而是使用字典的形式来存取。 + identifierObjs[_v.value] = self.objs[element] + elseif (_v.name == "css") then +-- print("tuoli css start") + _v.value = _gsub(_v.value, "-","_") + local paramFun = sys:loadstring("return " .. _v.value) + local t = paramFun() + local css = "" + for _k, _v in pairs(t) do + _k = _gsub(_k, "_","-") + if (_find(_k, "margin")) then + css = css .. _k .. ":" .. _v*sys.scale .. "," + else + css = css .. _k .. ":" .. _v .. "," + end + end +-- print("tuoli css end") + self.objs[element]:flexCss(css) + if (not sys.android) then + if (element.name == "View" and parent and (parent.name ~= "View" or (parent.name == "View" and parent.attr["css"] == nil))) then + table.insert(self.flxLayoutObjs, self.objs[element]) + end + end + elseif (_v.name == "title") then + self.objs[element]:title(_v.value) + elseif (_v.name == "titleColor") then + self.objs[element]:titleColor(tonumber(_v.value)) + elseif (_v.name == "image") then + if (element.name == "Button") then + local params = self:split(_v.value, ",") + self.objs[element]:image(params[1], params[2]) + elseif (element.name == "Image") then + self.objs[element]:image(_v.value) + end + elseif (_v.name == "corner") then + self.objs[element]:cornerRadius(tonumber(_v.value)*sys.scale) + elseif (_v.name == "borderColor") then + self.objs[element]:borderColor(tonumber(_v.value)) + elseif (_v.name == "borderWidth") then + self.objs[element]:borderWidth(tonumber(_v.value)) + elseif (_v.name == "textColor") then + if (not sys.android and string.len(_v.value) == 10) then + local alphaStr = string.sub(_v.value, 3, 4) + local alpha = tonumber(alphaStr)/tonumber("0xFF") + self.objs[element]:textColor(tonumber(_v.value), alpha) + else + self.objs[element]:textColor(tonumber(_v.value)) + end + elseif (_v.name == "fontSize") then + self.objs[element]:fontSize(tonumber(_v.value)*sys.scale) + elseif (_v.name == "lineCount") then + self.objs[element]:lineCount(tonumber(_v.value)) + elseif (_v.name == "alpha") then + self.objs[element]:alpha(tonumber(_v.value)) + elseif (_v.name == "text") then + self.objs[element]:text(_v.value) + elseif (_v.name == "textAlign") then + local paramFun = sys:loadstring("return " .. _v.value) + self.objs[element]:textAlign(paramFun()) + elseif (_v.name == "scaleType") then + local paramFun = sys:loadstring("return " .. _v.value) + self.objs[element]:scaleType(paramFun()) + elseif (_v.name == "hint") then + self.objs[element]:hint(_v.value) + elseif (_v.name == "space") then + self.objs[element]:miniSpacing(tonumber(_v.value)) + elseif (_v.name == "autoScroll") then + self.objs[element]:autoScroll(tonumber(_v.value)) + elseif (_v.name == "looping") then + if (_v.value == "true") then + self.objs[element]:looping(true) + else + self.objs[element]:looping(false) + end + elseif (_v.name == "selected") then + self.objs[element]:selectedColor(tonumber(_v.value)) + elseif (_v.name == "unselected") then + self.objs[element]:unselectedColor(tonumber(_v.value)) + elseif (_v.name == "showScrollIndicator") then + if (_v.value == "true") then + self.objs[element]:showScrollIndicator(true) + else + self.objs[element]:showScrollIndicator(false) + end + elseif (_v.name == "url") then + self.objs[element]:loadUrl(_v.value) + elseif (_v.name == "hide") then + if (_v.value == "true") then + self.objs[element]:hide(true) + else + self.objs[element]:hide(false) + end + elseif (_v.name == "contentSize") then + if (not sys.android) then + local paramFun = sys:loadstring("return " .. _v.value) + self.objs[element]:contentSize(paramFun()) + end + else + print("LuaError::Layout", "方法名不对: " .. _v.name) + end + end + end + + if (element.kids ~= nil) then + for _, kid in pairs(element.kids) do + self:parseElement(kid, element, identifierObjs); + end + end +end + +return pica + + + + + diff --git a/IOS/luaviewEx/luaviewEx/luaview/luaview.bundle/kit/slaxdom.lua b/IOS/luaviewEx/luaviewEx/luaview/luaview.bundle/kit/slaxdom.lua new file mode 100755 index 00000000..6d2d8087 --- /dev/null +++ b/IOS/luaviewEx/luaviewEx/luaview/luaview.bundle/kit/slaxdom.lua @@ -0,0 +1,55 @@ +-- Optional parser that creates a flat DOM from parsing +local SLAXML = require 'kit.slaxml' +function SLAXML:dom(xml,opts) + if not opts then opts={} end + local rich = not opts.simple + local push, pop = table.insert, table.remove + local stack = {} + local doc = { type="document", name="#doc", kids={} } + local current = doc + local builder = SLAXML:parser{ + startElement = function(name,nsURI) + local el = { type="element", name=name, kids={}, el=rich and {} or nil, attr={}, nsURI=nsURI, parent=rich and current or nil } + if current==doc then + if doc.root then error(("Encountered element '%s' when the document already has a root '%s' element"):format(name,doc.root.name)) end + doc.root = el + end + push(current.kids,el) + if current.el then push(current.el,el) end + current = el + push(stack,el) +-- print("tuoli 999", name) + end, + attribute = function(name,value,nsURI) + if not current or current.type~="element" then error(("Encountered an attribute %s=%s but I wasn't inside an element"):format(name,value)) end + local attr = {type='attribute',name=name,nsURI=nsURI,value=value,parent=rich and current or nil} + if rich then current.attr[name] = value end + push(current.attr,attr) +-- print("tuoli 999", name) + end, + closeElement = function(name) + if current.name~=name or current.type~="element" then error(("Received a close element notification for '%s' but was inside a '%s' %s"):format(name,current.name,current.type)) end + pop(stack) + current = stack[#stack] +-- print("tuoli 999", name) + end, + text = function(value) + if current.type~='document' then + if current.type~="element" then error(("Received a text notification '%s' but was inside a %s"):format(value,current.type)) end + push(current.kids,{type='text',name='#text',value=value,parent=rich and current or nil}) + end +-- print("tuoli 999", value) + end, + comment = function(value) + push(current.kids,{type='comment',name='#comment',value=value,parent=rich and current or nil}) +-- print("tuoli 999", value) + end, + pi = function(name,value) + push(current.kids,{type='pi',name=name,value=value,parent=rich and current or nil}) +-- print("tuoli 999", name) + end + } + builder:parse(xml,opts) + return doc +end +return SLAXML \ No newline at end of file diff --git a/IOS/luaviewEx/luaviewEx/luaview/luaview.bundle/kit/slaxml.lua b/IOS/luaviewEx/luaviewEx/luaview/luaview.bundle/kit/slaxml.lua new file mode 100755 index 00000000..b57cb272 --- /dev/null +++ b/IOS/luaviewEx/luaviewEx/luaview/luaview.bundle/kit/slaxml.lua @@ -0,0 +1,257 @@ +--[=====================================================================[ +v0.7 Copyright © 2013-2014 Gavin Kistner ; MIT Licensed +See http://github.com/Phrogz/SLAXML for details. +--]=====================================================================] +local SLAXML = { + VERSION = "0.7", + _call = { + pi = function(target,content) + print(string.format("",target,content)) + end, + comment = function(content) + print(string.format("",content)) + end, + startElement = function(name,nsURI,nsPrefix) + io.write("<") + if nsPrefix then io.write(nsPrefix,":") end + io.write(name) + if nsURI then io.write(" (ns='",nsURI,"')") end + print(">") + end, + attribute = function(name,value,nsURI,nsPrefix) + io.write(' ') + if nsPrefix then io.write(nsPrefix,":") end + io.write(name,'=',string.format('%q',value)) + if nsURI then io.write(" (ns='",nsURI,"')") end + io.write("\n") + end, + text = function(text) + print(string.format(" text: %q",text)) + end, + closeElement = function(name,nsURI,nsPrefix) + print(string.format("",name)) + end, + } +} + +function SLAXML:parser(callbacks) + return { _call=callbacks or self._call, parse=SLAXML.parse } +end + +function SLAXML:parse(xml,options) + if not options then options = { stripWhitespace=false } end + + -- Cache references for maximum speed + local find, sub, gsub, char, push, pop, concat = string.find, string.sub, string.gsub, string.char, table.insert, table.remove, table.concat + local first, last, match1, match2, match3, pos2, nsURI + local unpack = unpack or table.unpack + local pos = 1 + local state = "text" + local textStart = 1 + local currentElement={} + local currentAttributes={} + local currentAttributeCt -- manually track length since the table is re-used + local nsStack = {} + local anyElement = false + + local utf8markers = { {0x7FF,192}, {0xFFFF,224}, {0x1FFFFF,240} } + local function utf8(decimal) -- convert unicode code point to utf-8 encoded character string + if decimal<128 then return char(decimal) end + local charbytes = {} + for bytes,vals in ipairs(utf8markers) do + if decimal<=vals[1] then + for b=bytes+1,2,-1 do + local mod = decimal%64 + decimal = (decimal-mod)/64 + charbytes[b] = char(128+mod) + end + charbytes[1] = char(vals[2]+decimal) + return concat(charbytes) + end + end + end + local entityMap = { ["lt"]="<", ["gt"]=">", ["amp"]="&", ["quot"]='"', ["apos"]="'" } + local entitySwap = function(orig,n,s) return entityMap[s] or n=="#" and utf8(tonumber('0'..s)) or orig end + local function unescape(str) return gsub( str, '(&(#?)([%d%a]+);)', entitySwap ) end + + local function finishText() + if first>textStart and self._call.text then + local text = sub(xml,textStart,first-1) + if options.stripWhitespace then + text = gsub(text,'^%s+','') + text = gsub(text,'%s+$','') + if #text==0 then text=nil end + end + if text then self._call.text(unescape(text)) end + end + end + + local function findPI() + first, last, match1, match2 = find( xml, '^<%?([:%a_][:%w_.-]*) ?(.-)%?>', pos ) + if first then + finishText() + if self._call.pi then self._call.pi(match1,match2) end + pos = last+1 + textStart = pos + return true + end + end + + local function findComment() + first, last, match1 = find( xml, '^', pos ) + if first then + finishText() + if self._call.comment then self._call.comment(match1) end + pos = last+1 + textStart = pos + return true + end + end + + local function nsForPrefix(prefix) + if prefix=='xml' then return 'http://www.w3.org/XML/1998/namespace' end -- http://www.w3.org/TR/xml-names/#ns-decl + for i=#nsStack,1,-1 do if nsStack[i][prefix] then return nsStack[i][prefix] end end + error(("Cannot find namespace for prefix %s"):format(prefix)) + end + + local function startElement() + anyElement = true + first, last, match1 = find( xml, '^<([%a_][%w_.-]*)', pos ) + if first then + currentElement[2] = nil -- reset the nsURI, since this table is re-used + currentElement[3] = nil -- reset the nsPrefix, since this table is re-used + finishText() + pos = last+1 + first,last,match2 = find(xml, '^:([%a_][%w_.-]*)', pos ) + if first then + currentElement[1] = match2 + currentElement[3] = match1 -- Save the prefix for later resolution + match1 = match2 + pos = last+1 + else + currentElement[1] = match1 + for i=#nsStack,1,-1 do if nsStack[i]['!'] then currentElement[2] = nsStack[i]['!']; break end end + end + currentAttributeCt = 0 + push(nsStack,{}) + return true + end + end + + local function findAttribute() + first, last, match1 = find( xml, '^%s+([:%a_][:%w_.-]*)%s*=%s*', pos ) + if first then + pos2 = last+1 + first, last, match2 = find( xml, '^"([^<"]*)"', pos2 ) -- FIXME: disallow non-entity ampersands + if first then + pos = last+1 + match2 = unescape(match2) + else + first, last, match2 = find( xml, "^'([^<']*)'", pos2 ) -- FIXME: disallow non-entity ampersands + if first then + pos = last+1 + match2 = unescape(match2) + end + end + end + if match1 and match2 then + local currentAttribute = {match1,match2} + local prefix,name = string.match(match1,'^([^:]+):([^:]+)$') + if prefix then + if prefix=='xmlns' then + nsStack[#nsStack][name] = match2 + else + currentAttribute[1] = name + currentAttribute[4] = prefix + end + else + if match1=='xmlns' then + nsStack[#nsStack]['!'] = match2 + currentElement[2] = match2 + end + end + currentAttributeCt = currentAttributeCt + 1 + currentAttributes[currentAttributeCt] = currentAttribute + return true + end + end + + local function findCDATA() + first, last, match1 = find( xml, '^', pos ) + if first then + finishText() + if self._call.text then self._call.text(match1) end + pos = last+1 + textStart = pos + return true + end + end + + local function closeElement() + first, last, match1 = find( xml, '^%s*(/?)>', pos ) + if first then + state = "text" + pos = last+1 + textStart = pos + + -- Resolve namespace prefixes AFTER all new/redefined prefixes have been parsed + if currentElement[3] then currentElement[2] = nsForPrefix(currentElement[3]) end + if self._call.startElement then self._call.startElement(unpack(currentElement)) end + if self._call.attribute then + for i=1,currentAttributeCt do + if currentAttributes[i][4] then currentAttributes[i][3] = nsForPrefix(currentAttributes[i][4]) end + self._call.attribute(unpack(currentAttributes[i])) + end + end + + if match1=="/" then + pop(nsStack) + if self._call.closeElement then self._call.closeElement(unpack(currentElement)) end + end + return true + end + end + + local function findElementClose() + first, last, match1, match2 = find( xml, '^', pos ) + if first then + nsURI = nil + for i=#nsStack,1,-1 do if nsStack[i]['!'] then nsURI = nsStack[i]['!']; break end end + else + first, last, match2, match1 = find( xml, '^', pos ) + if first then nsURI = nsForPrefix(match2) end + end + if first then + finishText() + if self._call.closeElement then self._call.closeElement(match1,nsURI) end + pos = last+1 + textStart = pos + pop(nsStack) + return true + end + end + + while pos<#xml do + if state=="text" then + if not (findPI() or findComment() or findCDATA() or findElementClose()) then + if startElement() then + state = "attributes" + else + first, last = find( xml, '^[^<]+', pos ) + pos = (first and last or pos) + 1 + end + end + elseif state=="attributes" then + if not findAttribute() then + if not closeElement() then + error("Was in an element and couldn't find attributes or the close.") + end + end + end + end + + if not anyElement then error("Parsing did not discover any elements") end + if #nsStack > 0 then error("Parsing ended with unclosed elements") end +end + +return SLAXML diff --git a/IOS/luaviewEx/luaviewEx/luaview/luaview.bundle/kit/sys.lua b/IOS/luaviewEx/luaviewEx/luaview/luaview.bundle/kit/sys.lua new file mode 100644 index 00000000..d9600a35 --- /dev/null +++ b/IOS/luaviewEx/luaviewEx/luaview/luaview.bundle/kit/sys.lua @@ -0,0 +1,37 @@ +-- +-- Copyright 2017 Alibaba Group +-- License: MIT +-- Website: https://alibaba.github.io/LuaViewSDK +-- User: tuoli +-- Date: 17/3/30 +-- + +if (sys == nil) then + sys = {} + + -- + -- Variables + -- + sys.android = System:android() + sys.scrW, sys.scrH = System:screenSize() + sys.contW = sys.scrW + sys.scale = sys.scrW/375 > 1 and 1 or sys.scrW/375 <= 1 and sys.scrW/375 + -- 减掉ActionBar和StatusBar的高度 + if (sys.android) then + local device = System:device() + sys.contH = device.window_height - device.status_bar_height - device.nav_height + else + sys.contH = sys.scrH - 64 -- iOS, 稳定在这个值 + end + + -- + -- Functions + -- + function sys:loadstring(param) + if (sys.android) then + return load(param) + else + return loadstring(param) + end + end +end \ No newline at end of file diff --git a/IOS/luaviewEx/luaviewEx/luaview/luaview.bundle/kit/util.lua b/IOS/luaviewEx/luaviewEx/luaview/luaview.bundle/kit/util.lua new file mode 100644 index 00000000..e7cc4c8e --- /dev/null +++ b/IOS/luaviewEx/luaviewEx/luaview/luaview.bundle/kit/util.lua @@ -0,0 +1,81 @@ +-- +-- Copyright 2017 Alibaba Group +-- License: MIT +-- Website: https://alibaba.github.io/LuaViewSDK +-- User: tuoli +-- Date: 17/3/30 +-- + +if (util == nil) then + util = {} + function util:printTable(t, exclusions) + if (type(t) == "table") then + local nests = 0 + if not exclusions then exclusions = {} end + local recurse = function(t, recurse, exclusions) + indent = function() + local dent = "" + for i = 1, nests do + dent = dent .. " " + end + return dent + end + local excluded = function(key) + for k, v in pairs(exclusions) do + if v == key then + return true + end + end + return false + end + local isFirst = true + for k, v in pairs(t) do + local dent = indent() + if isFirst then + print(dent .. "|") + isFirst = false + end + dent = indent() + if type(v) == "table" and not excluded(k) then + print(dent .. "|- " .. tostring(k) .. ": " .. type(v)) + nests = nests + 1 + recurse(v, recurse, exclusions) + elseif excluded(k) then + print(dent .. "|- " .. tostring(k) .. ": " .. type(v)) + elseif type(v) == "userdata" or type(v) == "function" then + print(dent .. "|- " .. tostring(k) .. ": " .. type(v)) + elseif type(v) == "string" then + print(dent .. "|- " .. tostring(k) .. ": " .. "\"" .. tostring(v) .. "\"") + else + print(dent .. "|- " .. tostring(k) .. ": " .. tostring(v)) + end + end + nests = nests - 1 + end + + nests = 0 + + if t then + print("### START TABLE ###") + for k, v in pairs(t) do + if type(v) == "table" then + print("|- " .. k .. ": " .. type(v)) + nests = nests + 1 + recurse(v, recurse, exclusions) + elseif type(v) == "userdata" or type(v) == "function" then + print("|- " .. tostring(k) .. ": " .. type(v)) + elseif type(v) == "string" then + print("|- " .. tostring(k) .. ": " .. "\"" .. tostring(v) .. "\"") + else + print("|- " .. tostring(k) .. ": " .. tostring(v)) + end + end + print("### END TABLE ###") + else + print("NIL TABLE") + end + else + print(t) + end + end +end \ No newline at end of file diff --git a/IOS/luaviewEx/luaviewEx/luaview/luaview.xcodeproj/project.pbxproj b/IOS/luaviewEx/luaviewEx/luaview/luaview.xcodeproj/project.pbxproj new file mode 100644 index 00000000..8fc09d87 --- /dev/null +++ b/IOS/luaviewEx/luaviewEx/luaview/luaview.xcodeproj/project.pbxproj @@ -0,0 +1,270 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + AC11EED61E97917A00FF9F04 /* kit in Resources */ = {isa = PBXBuildFile; fileRef = AC11EED41E97917300FF9F04 /* kit */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + AC11EEC81E97910F00FF9F04 /* luaview.bundle */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = luaview.bundle; sourceTree = BUILT_PRODUCTS_DIR; }; + AC11EECB1E97910F00FF9F04 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + AC11EED41E97917300FF9F04 /* kit */ = {isa = PBXFileReference; lastKnownFileType = folder; name = kit; path = ../Assets/kit; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + AC11EEC51E97910F00FF9F04 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + AC11EEBF1E97910F00FF9F04 = { + isa = PBXGroup; + children = ( + AC11EED41E97917300FF9F04 /* kit */, + AC11EECA1E97910F00FF9F04 /* luaview */, + AC11EEC91E97910F00FF9F04 /* Products */, + ); + sourceTree = ""; + }; + AC11EEC91E97910F00FF9F04 /* Products */ = { + isa = PBXGroup; + children = ( + AC11EEC81E97910F00FF9F04 /* luaview.bundle */, + ); + name = Products; + sourceTree = ""; + }; + AC11EECA1E97910F00FF9F04 /* luaview */ = { + isa = PBXGroup; + children = ( + AC11EECB1E97910F00FF9F04 /* Info.plist */, + ); + path = luaview; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + AC11EEC71E97910F00FF9F04 /* luaview */ = { + isa = PBXNativeTarget; + buildConfigurationList = AC11EECE1E97910F00FF9F04 /* Build configuration list for PBXNativeTarget "luaview" */; + buildPhases = ( + AC11EEC41E97910F00FF9F04 /* Sources */, + AC11EEC51E97910F00FF9F04 /* Frameworks */, + AC11EEC61E97910F00FF9F04 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = luaview; + productName = luaview; + productReference = AC11EEC81E97910F00FF9F04 /* luaview.bundle */; + productType = "com.apple.product-type.bundle"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + AC11EEC01E97910F00FF9F04 /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 0800; + ORGANIZATIONNAME = tuoli; + TargetAttributes = { + AC11EEC71E97910F00FF9F04 = { + CreatedOnToolsVersion = 8.0; + ProvisioningStyle = Automatic; + }; + }; + }; + buildConfigurationList = AC11EEC31E97910F00FF9F04 /* Build configuration list for PBXProject "luaview" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + ); + mainGroup = AC11EEBF1E97910F00FF9F04; + productRefGroup = AC11EEC91E97910F00FF9F04 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + AC11EEC71E97910F00FF9F04 /* luaview */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + AC11EEC61E97910F00FF9F04 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + AC11EED61E97917A00FF9F04 /* kit in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + AC11EEC41E97910F00FF9F04 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + AC11EECC1E97910F00FF9F04 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVES = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CODE_SIGN_IDENTITY = "-"; + CONFIGURATION_BUILD_DIR = ./; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.11; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = NO; + SDKROOT = iphoneos; + }; + name = Debug; + }; + AC11EECD1E97910F00FF9F04 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVES = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CODE_SIGN_IDENTITY = "-"; + CONFIGURATION_BUILD_DIR = ./; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.11; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = iphoneos; + }; + name = Release; + }; + AC11EECF1E97910F00FF9F04 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + COMBINE_HIDPI_IMAGES = YES; + INFOPLIST_FILE = luaview/Info.plist; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Bundles"; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + PRODUCT_BUNDLE_IDENTIFIER = alibaba.luaview; + PRODUCT_NAME = "$(TARGET_NAME)"; + SKIP_INSTALL = YES; + WRAPPER_EXTENSION = bundle; + }; + name = Debug; + }; + AC11EED01E97910F00FF9F04 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + COMBINE_HIDPI_IMAGES = YES; + INFOPLIST_FILE = luaview/Info.plist; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Bundles"; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + PRODUCT_BUNDLE_IDENTIFIER = alibaba.luaview; + PRODUCT_NAME = "$(TARGET_NAME)"; + SKIP_INSTALL = YES; + WRAPPER_EXTENSION = bundle; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + AC11EEC31E97910F00FF9F04 /* Build configuration list for PBXProject "luaview" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + AC11EECC1E97910F00FF9F04 /* Debug */, + AC11EECD1E97910F00FF9F04 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + AC11EECE1E97910F00FF9F04 /* Build configuration list for PBXNativeTarget "luaview" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + AC11EECF1E97910F00FF9F04 /* Debug */, + AC11EED01E97910F00FF9F04 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = AC11EEC01E97910F00FF9F04 /* Project object */; +} diff --git a/IOS/luaviewEx/luaviewEx/luaview/luaview/Info.plist b/IOS/luaviewEx/luaviewEx/luaview/luaview/Info.plist new file mode 100644 index 00000000..028a03f5 --- /dev/null +++ b/IOS/luaviewEx/luaviewEx/luaview/luaview/Info.plist @@ -0,0 +1,26 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + BNDL + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + NSHumanReadableCopyright + Copyright © 2017年 tuoli. All rights reserved. + NSPrincipalClass + + + diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 00000000..5546ac5f --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,17 @@ +The MIT License (MIT) +Copyright (c) 2017 Alibaba Group +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/LuaViewBytecodeCompiler/README.md b/LuaViewBytecodeCompiler/README.md new file mode 100644 index 00000000..578db377 --- /dev/null +++ b/LuaViewBytecodeCompiler/README.md @@ -0,0 +1,19 @@ +#LuaViewBytecodeCompiler + +> 该工具用于将LuaView的源码预编译成Lua bytecode。用于加速LuaView的执行。 + +### 注意 +* 该工具编译出来的bytecode代码只能用于Android端,暂时不能用于iOS端 + + +### 使用 +1. 创建项目普通Java项目 +2. 引入jar包 +3. 使用jar包提供的函数对lua代码进行打包(LuaViewBytecodeCompiler类) + * A:public static byte[] compile(byte[] source, String filename) throws Exception + * B:public static void compile(String filePath) throws Exception +4. A第一个方法将一个源码的二进制流编译成lua bytecode二进制流 +5. B方法将给定代码地址的代码编译成lua bytecode并保存在同目录下,文件名为*.luap +6. Android项目直接加载二进制代码 + * luaView.loadPrototype(final InputStream inputStream, final String name, final LuaScriptLoader.ScriptExecuteCallback callback) + diff --git a/LuaViewBytecodeCompiler/luaview-bytecode-compiler.1.0.2.jar b/LuaViewBytecodeCompiler/luaview-bytecode-compiler.1.0.2.jar new file mode 100644 index 00000000..b2a9549d Binary files /dev/null and b/LuaViewBytecodeCompiler/luaview-bytecode-compiler.1.0.2.jar differ diff --git a/LuaViewDebugger/.classpath b/LuaViewDebugger/.classpath new file mode 100644 index 00000000..fb565a58 --- /dev/null +++ b/LuaViewDebugger/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/LuaViewDebugger/.project b/LuaViewDebugger/.project new file mode 100644 index 00000000..a8ead312 --- /dev/null +++ b/LuaViewDebugger/.project @@ -0,0 +1,17 @@ + + + LuaViewDebugger + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/LuaViewDebugger/.settings/org.eclipse.jdt.core.prefs b/LuaViewDebugger/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000..7341ab16 --- /dev/null +++ b/LuaViewDebugger/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.7 diff --git a/LuaViewDebugger/LuaViewDebugger.jar b/LuaViewDebugger/LuaViewDebugger.jar new file mode 100644 index 00000000..91e57f8b Binary files /dev/null and b/LuaViewDebugger/LuaViewDebugger.jar differ diff --git a/LuaViewDebugger/pkgjar.jardesc b/LuaViewDebugger/pkgjar.jardesc new file mode 100644 index 00000000..e60292a5 --- /dev/null +++ b/LuaViewDebugger/pkgjar.jardesc @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/LuaViewDebugger/src/com/alibaba/luaview/debugger/Center.java b/LuaViewDebugger/src/com/alibaba/luaview/debugger/Center.java new file mode 100644 index 00000000..2370def4 --- /dev/null +++ b/LuaViewDebugger/src/com/alibaba/luaview/debugger/Center.java @@ -0,0 +1,24 @@ +package com.alibaba.luaview.debugger; + +import com.alibaba.luaview.debugger.ui.DebuggerFrame; +import com.alibaba.luaview.debugger.ui.SrcCodeCenter; +import com.alibaba.luaview.debugger.ui.Updater; + +public class Center { + public DebuggerFrame frame; + public final SrcCodeCenter srcCodeCenter; + public final Updater updater; + public final Log log; + public final ClientCmdBuffer cmdBuffer; + public final Main main; + public Server worker; + + public Center(Main serverMain) { + this.main = serverMain; + this.cmdBuffer = new ClientCmdBuffer(this); + this.srcCodeCenter = new SrcCodeCenter(this); + this.updater = new Updater(this); + this.log = new Log(this); + } + +} diff --git a/LuaViewDebugger/src/com/alibaba/luaview/debugger/ClientCmd.java b/LuaViewDebugger/src/com/alibaba/luaview/debugger/ClientCmd.java new file mode 100644 index 00000000..f7e14afb --- /dev/null +++ b/LuaViewDebugger/src/com/alibaba/luaview/debugger/ClientCmd.java @@ -0,0 +1,19 @@ +package com.alibaba.luaview.debugger; + +public class ClientCmd { + + public final String cmdString; + + public String toString() { + return "Cmd: " + cmdString; + } + + public ClientCmd(String cmd) { + if (cmd != null) { + this.cmdString = cmd; + } else { + this.cmdString = "none"; + } + } + +} diff --git a/LuaViewDebugger/src/com/alibaba/luaview/debugger/ClientCmdBuffer.java b/LuaViewDebugger/src/com/alibaba/luaview/debugger/ClientCmdBuffer.java new file mode 100644 index 00000000..452b0b05 --- /dev/null +++ b/LuaViewDebugger/src/com/alibaba/luaview/debugger/ClientCmdBuffer.java @@ -0,0 +1,42 @@ +package com.alibaba.luaview.debugger; + +//"h help info" +//"c continue" +//"s trace" +//"n next" +//"p var print variable" +//"b src:line add breakpoint" +//"d num del breakpoint" +//"bl list breakpoint" +//"be num enable breakpoint" +//"bd num disable breakpoint" +//"bt print traceback" + +public final class ClientCmdBuffer { + + private final Center center; + + + public ClientCmdBuffer(Center center) { + this.center = center; + } + + private ClientCmd currentCmd; + + + + public synchronized void pushCmd(ClientCmd cmd) { + if (currentCmd != null) { + currentCmd = null; + center.log.print("!!!操作被忽略 (调试已经结束/断开/或者操作太快)\n"); + } + currentCmd = cmd; + } + + public synchronized ClientCmd popCmd() { + ClientCmd cmd = currentCmd; + currentCmd = null; + return cmd; + } + +} diff --git a/LuaViewDebugger/src/com/alibaba/luaview/debugger/Config.java b/LuaViewDebugger/src/com/alibaba/luaview/debugger/Config.java new file mode 100644 index 00000000..329385ee --- /dev/null +++ b/LuaViewDebugger/src/com/alibaba/luaview/debugger/Config.java @@ -0,0 +1,15 @@ +package com.alibaba.luaview.debugger; + +public class Config { + public static final int BTN_W = 60; + public static final int BTN_W2 = 80; + public static final int BTN_H = 22; + + public static final int LINE_H = 15; + + public static boolean closeWhenConnectionEnd; + + public static final String IP = "127.0.0.1"; + + public static final int PORT = 9876; +} diff --git a/LuaViewDebugger/src/com/alibaba/luaview/debugger/ExitHttpRequest.java b/LuaViewDebugger/src/com/alibaba/luaview/debugger/ExitHttpRequest.java new file mode 100644 index 00000000..59eddd68 --- /dev/null +++ b/LuaViewDebugger/src/com/alibaba/luaview/debugger/ExitHttpRequest.java @@ -0,0 +1,27 @@ +package com.alibaba.luaview.debugger; + +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.net.Socket; + +public final class ExitHttpRequest { + + public final String EXIT_APP = "Exit-App".toLowerCase(); + + public String sendExitCmd() { + String result = null; + try { + Socket socket = new Socket(Config.IP, Config.PORT); + + DataInputStream dis = new DataInputStream(socket.getInputStream()); + DataOutputStream dos = new DataOutputStream(socket.getOutputStream()); + Util.writeString("exit", dos); + result = Util.readString(dis); + socket.close(); + Thread.sleep(1000); + } catch (Exception e) { + } finally { + } + return result; + } +} diff --git a/LuaViewDebugger/src/com/alibaba/luaview/debugger/Log.java b/LuaViewDebugger/src/com/alibaba/luaview/debugger/Log.java new file mode 100644 index 00000000..c65f5cca --- /dev/null +++ b/LuaViewDebugger/src/com/alibaba/luaview/debugger/Log.java @@ -0,0 +1,37 @@ +package com.alibaba.luaview.debugger; + +import java.text.SimpleDateFormat; +import java.util.Date; +import javax.swing.JTextArea; + +public final class Log { + private Center center; + + public Log(Center center) { + this.center = center; + } + + public synchronized void print(String s) { + if (s == null) { + s = ""; + } + if (center.frame != null) { + JTextArea textArea = center.frame.getOutputArea(); + { + String text = textArea.getText(); + if (text.length() <= 0 || text.endsWith("\n")) { + s = date() + s; + } + } + textArea.append(s); + textArea.setCaretPosition(textArea.getText().length()); + } + } + + // 设置日期格式 + private SimpleDateFormat dateFormat = new SimpleDateFormat("[HH:mm:ss.SSS] "); + + public String date() { + return dateFormat.format(new Date()); + } +} diff --git a/LuaViewDebugger/src/com/alibaba/luaview/debugger/Main.java b/LuaViewDebugger/src/com/alibaba/luaview/debugger/Main.java new file mode 100644 index 00000000..8f374faa --- /dev/null +++ b/LuaViewDebugger/src/com/alibaba/luaview/debugger/Main.java @@ -0,0 +1,90 @@ +package com.alibaba.luaview.debugger; + +import java.awt.Dimension; +import java.awt.Toolkit; +import java.io.IOException; +import java.net.ServerSocket; +import java.net.Socket; + +import com.alibaba.luaview.debugger.ui.DebuggerFrame; + +public class Main { + + public static void main(String[] args) { + new Main().main(); + } + + private ServerSocket serverSocket; + + public void main() { + // 关闭老的 + String ret = new ExitHttpRequest().sendExitCmd(); + if (ret != null && "ok".equals(ret.trim())) { + System.out.println("关闭..."); + try { + Thread.sleep(1000); + } catch (Exception e) { + e.printStackTrace(); + } + } + System.out.println("启动..."); + + { + DebuggerFrame frame = new DebuggerFrame(null); + frame.dispose(); + } + + // 启动主控制窗口 + MainFrame.main(); + + // 启动socket调试端口监听服务 + try { + openSocketListner(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + private void openSocketListner() throws Exception { + serverSocket = new ServerSocket(Config.PORT); + while (serverSocket.isBound()) { + Socket connection = serverSocket.accept(); + connection.setSoTimeout(60 * 60 * 24 * 1000);// 超时时间 + Center center = new Center(this); + center.frame = debuggerFrameMain(center); + Server worker = new Server(connection, center); + worker.run(); + // 创建一个tab + center.srcCodeCenter.showHelpTab(); + } + } + + private DebuggerFrame debuggerFrameMain(Center center) { + // 获取屏幕大小 + Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); + int w = screenSize.width; + int h = screenSize.height; + + // 创建界面 + DebuggerFrame frame = new DebuggerFrame(center); + + // 设置窗口大小位置 + frame.setLocation(w / 2, 0); + frame.setSize(w / 2, h); + frame.setVisible(true); + + frame.setIsDebugging(true); + frame.setVisible(true); + return frame; + } + + public void close() { + try { + if (serverSocket != null) + serverSocket.close(); + serverSocket = null; + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/LuaViewDebugger/src/com/alibaba/luaview/debugger/MainFrame.java b/LuaViewDebugger/src/com/alibaba/luaview/debugger/MainFrame.java new file mode 100644 index 00000000..19cbd1d0 --- /dev/null +++ b/LuaViewDebugger/src/com/alibaba/luaview/debugger/MainFrame.java @@ -0,0 +1,61 @@ +package com.alibaba.luaview.debugger; + +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.EventQueue; +import java.awt.Toolkit; +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.JCheckBox; +import javax.swing.event.ChangeListener; +import javax.swing.event.ChangeEvent; + +public class MainFrame extends JFrame { + + private static final long serialVersionUID = -7533358961826961149L; + + private JPanel contentPane; + + /** + * Launch the application. + */ + public static void main() { + EventQueue.invokeLater(new Runnable() { + public void run() { + try { + Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); + MainFrame frame = new MainFrame(); + int h = frame.getHeight(); + frame.setLocation(h, screenSize.height - h * 3 / 2); + frame.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } + + /** + * Create the frame. + */ + public MainFrame() { + setResizable(false); + setTitle("调试器: 请再启动模拟器, 调试器会自动开始调试"); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setBounds(100, 100, 354, 120); + contentPane = new JPanel(); + // contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); + contentPane.setLayout(new BorderLayout(0, 0)); + setContentPane(contentPane); + + final JCheckBox checkBox = new JCheckBox("断开关闭调试窗口"); + checkBox.addChangeListener(new ChangeListener() { + public void stateChanged(ChangeEvent e) { + Config.closeWhenConnectionEnd = checkBox.isSelected(); + } + }); + checkBox.setSelected(true); + contentPane.add(checkBox, BorderLayout.CENTER); + } + +} diff --git a/LuaViewDebugger/src/com/alibaba/luaview/debugger/Server.java b/LuaViewDebugger/src/com/alibaba/luaview/debugger/Server.java new file mode 100644 index 00000000..26baa1f9 --- /dev/null +++ b/LuaViewDebugger/src/com/alibaba/luaview/debugger/Server.java @@ -0,0 +1,102 @@ +package com.alibaba.luaview.debugger; + +import java.io.*; +import java.net.*; + +import com.alibaba.luaview.debugger.ClientCmd; + +public final class Server { + private Socket connection; + private DataOutputStream writer = null; + private DataInputStream reader = null; + private Center center; + + public Server(Socket connection, Center center) { + super(); + this.connection = connection; + try { + reader = new DataInputStream(connection.getInputStream()); + writer = new DataOutputStream(connection.getOutputStream()); + } catch (IOException e) { + e.printStackTrace(); + } + this.center = center; + this.center.worker = this; + } + + private void writeString(String s) throws Exception { + Util.writeString(s, writer); + } + + private String readString() throws Exception { + return Util.readString(reader); + } + + private boolean continueRun = true; + + public void run() { + Runnable runReader = new Runnable() { + @Override + public void run() { + try { + for (; continueRun;) { + Thread.sleep(10); + String string = readString(); + if (string == null || string.length() <= 0) { + continue; + } + System.out.println("Received Cmd: " + string); + if ("exit".equalsIgnoreCase(string)) { + center.main.close(); + System.exit(0); + return; + } else { + center.updater.run(string); + } + } + } catch (Exception e) { + // e.printStackTrace(); + } finally { + close(); + } + System.out.println("----------调试结束1-----------"); + } + + }; + Runnable runWriter = new Runnable() { + @Override + public void run() { + try { + for (; continueRun;) { + ClientCmd cmd = center.cmdBuffer.popCmd(); + if (cmd != null) { + System.out.println("Send Client Cmd: " + cmd); + writeString(cmd.cmdString); + } + Thread.sleep(10); + } + } catch (Exception e) { + // e.printStackTrace(); + } finally { + close(); + } + System.out.println("----------调试结束2-----------"); + } + + }; + new Thread(runReader).start(); + new Thread(runWriter).start(); + } + + public void close() { + try { + this.continueRun = false; + connection.close(); + reader.close(); + writer.close(); + if (Config.closeWhenConnectionEnd) + this.center.frame.dispose(); + } catch (Exception e) { + } + } +} \ No newline at end of file diff --git a/LuaViewDebugger/src/com/alibaba/luaview/debugger/Util.java b/LuaViewDebugger/src/com/alibaba/luaview/debugger/Util.java new file mode 100644 index 00000000..ab2f92e1 --- /dev/null +++ b/LuaViewDebugger/src/com/alibaba/luaview/debugger/Util.java @@ -0,0 +1,33 @@ +package com.alibaba.luaview.debugger; + +import java.io.ByteArrayOutputStream; +import java.io.DataInputStream; +import java.io.DataOutputStream; + +public class Util { + + public static void writeString(String s, DataOutputStream writer) throws Exception { + if (s != null) { + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + DataOutputStream dos = new DataOutputStream(bos); + byte[] data = s.getBytes("UTF-8"); + dos.writeInt(data.length); + dos.write(data); + dos.flush(); + byte[] bs = bos.toByteArray(); + writer.write(bs); + writer.flush(); + } + } + + public static String readString(DataInputStream reader) throws Exception { + int len = reader.readInt(); + if (len > 0) { + byte[] bs = new byte[len]; + reader.readFully(bs); + String s = new String(bs, "UTF-8"); + return s; + } + return null; + } +} diff --git a/LuaViewDebugger/src/com/alibaba/luaview/debugger/ui/BottomLineTabbedPane.java b/LuaViewDebugger/src/com/alibaba/luaview/debugger/ui/BottomLineTabbedPane.java new file mode 100644 index 00000000..9bc35788 --- /dev/null +++ b/LuaViewDebugger/src/com/alibaba/luaview/debugger/ui/BottomLineTabbedPane.java @@ -0,0 +1,21 @@ +package com.alibaba.luaview.debugger.ui; + +import java.awt.Graphics; + +import javax.swing.JTabbedPane; + +public class BottomLineTabbedPane extends JTabbedPane { + private static final long serialVersionUID = -4995869134364341154L; + + public BottomLineTabbedPane(int tabPlacement) { + super(tabPlacement); + } + + public void paint(Graphics g) { + super.paint(g); + // int w = this.getWidth(); + // int h = this.getHeight(); + // g.setColor(new Color(171, 171, 171)); + // g.drawLine(0, h, w, h); + } +} diff --git a/LuaViewDebugger/src/com/alibaba/luaview/debugger/ui/CharsToWords.java b/LuaViewDebugger/src/com/alibaba/luaview/debugger/ui/CharsToWords.java new file mode 100644 index 00000000..4f97270b --- /dev/null +++ b/LuaViewDebugger/src/com/alibaba/luaview/debugger/ui/CharsToWords.java @@ -0,0 +1,143 @@ +package com.alibaba.luaview.debugger.ui; + +import java.util.Vector; + +public class CharsToWords { + + int index; + + public Vector split(String s) { + Vector words = new Vector(); + index = 0; + Word prev = null; + for (int i = 0; i < s.length(); i++) { + Word word = getOneWord(s, prev); + if (word != null) { + if (prev != null) { + word.prev = prev; + prev.next = word; + } + words.add(word); + prev = word; + } else { + break; + } + } + return words; + } + + private char charAt(int index, String s) { + if (index < s.length()) { + return s.charAt(index); + } + return 0; + } + + public Word getOneWord(String s, Word preWord) { + StringBuffer buffer = new StringBuffer(); + for (; index < s.length();) { + char c = s.charAt(index); + // ".." 链接运算符 + if (buffer.length() <= 0 && charAt(index, s) == '.' && charAt(index + 1, s) == '.') { + buffer.append(".."); + index += 2; + break; + } + // 字符串 + if (buffer.length() <= 0 && (c == '"' || c == '\'')) { + char c0 = c; + char preC = 0; + buffer.append(c); + index++; + for (; index < s.length();) { + c = s.charAt(index); + buffer.append(c); + index++; + if (preC != '\\' && c == c0) { + break; + } + } + break; + } + // 注释信息 + if (buffer.length() <= 0 && charAt(index, s) == '-' && charAt(index + 1, s) == '-') { + for (; index < s.length();) { + c = s.charAt(index); + buffer.append(c); + index++; + if (c == '\n') { + break; + } + } + break; + } + // 数字 + if (buffer.length() <= 0 && is09(c)) { + for (; index < s.length();) { + c = s.charAt(index); + if (is09(c) || isAF(c) || c == '.' || c == 'X' || c == 'x') { + buffer.append(c); + index++; + } else { + break; + } + } + break; + } + // 表达式 + if (isAZ(c) || is09(c) || c == '_') { + buffer.append(c); + index++; + } else { + // 普通标点符号括号等. + if (buffer.length() <= 0) { + buffer.append(c); + index++; + } + break; + } + } + if (buffer.length() > 0) { + String w = buffer.toString(); + return new Word(w, preWord); + } + return null; + } + + public boolean is09(char c) { + if ('0' <= c && c <= '9') { + return true; + } + return false; + } + + public static boolean isAF(char c) { + if ('A' <= c && c <= 'F') { + return true; + } + if ('a' <= c && c <= 'f') { + return true; + } + return false; + } + + public static boolean wordStart(char c) { + if (isAZ(c)) { + return true; + } + if ('_' == c) { + return true; + } + return false; + } + + public static boolean isAZ(char c) { + if ('A' <= c && c <= 'Z') { + return true; + } + if ('a' <= c && c <= 'z') { + return true; + } + return false; + } +} diff --git a/LuaViewDebugger/src/com/alibaba/luaview/debugger/ui/DebuggerFrame.java b/LuaViewDebugger/src/com/alibaba/luaview/debugger/ui/DebuggerFrame.java new file mode 100644 index 00000000..c0f7c867 --- /dev/null +++ b/LuaViewDebugger/src/com/alibaba/luaview/debugger/ui/DebuggerFrame.java @@ -0,0 +1,233 @@ +package com.alibaba.luaview.debugger.ui; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.awt.Graphics; +import java.awt.Image; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; + +import javax.imageio.ImageIO; +import javax.swing.ImageIcon; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JSplitPane; +import javax.swing.JTabbedPane; +import javax.swing.JTextArea; +import javax.swing.JTextField; +import javax.swing.ScrollPaneConstants; +import javax.swing.border.Border; +import javax.swing.plaf.basic.BasicSplitPaneDivider; +import javax.swing.plaf.basic.BasicSplitPaneUI; + +import com.alibaba.luaview.debugger.Center; +import com.alibaba.luaview.debugger.ClientCmd; +import com.alibaba.luaview.debugger.Config; + +public class DebuggerFrame extends JFrame { + + private static final long serialVersionUID = -4760175577170083855L; + + private JPanel contentPane; + private JTextField textFieldCmdInput; + private final Center center; + + private String addtionTitle; + + public void setTitle(String name) { + if (this.addtionTitle == null || this.addtionTitle.length() <= 0) { + this.addtionTitle = name; + } + super.setTitle("LuaView - " + addtionTitle); + } + + /** + * Create the frame. + */ + public DebuggerFrame(final Center c) { + this.center = c; + setTitle(""); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setBounds(100, 100, 640, 750); + contentPane = new JPanel(); + // contentPane.setBorder(new EmptyBorder(1, 1, 1, 1)); + contentPane.setLayout(new BorderLayout(0, 0)); + setContentPane(contentPane); + + JPanel panel = new JPanel(); + contentPane.add(panel, BorderLayout.CENTER); + panel.setLayout(new BorderLayout(0, 0)); + + JPanel panelHead = new HeadPanel(); + panelHead.setBackground(Color.WHITE); + panelHead.setBorder(null); + FlowLayout flowLayout = (FlowLayout) panelHead.getLayout(); + flowLayout.setAlignment(FlowLayout.LEFT); + panel.add(panelHead, BorderLayout.NORTH); + + textFieldCmdInput = new JTextField(); + textFieldCmdInput.setToolTipText("调试命令"); + textFieldCmdInput.setPreferredSize(new Dimension(100, Config.BTN_H + 1)); + textFieldCmdInput.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + center.cmdBuffer.pushCmd(new ClientCmd(textFieldCmdInput.getText().trim())); + } + }); + panelHead.add(textFieldCmdInput); + textFieldCmdInput.setColumns(15); + + buttonNextLine = new JButton("下一行"); + buttonNextLine.setPreferredSize(new Dimension(Config.BTN_W, Config.BTN_H)); + buttonNextLine.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + center.srcCodeCenter.clearGotoLine(); + setIsDebugging(false); + center.cmdBuffer.pushCmd(new ClientCmd("n")); + } + }); + try { + Image img = ImageIO.read(getClass().getResource("play.png")); + Image img2 = ImageIO.read(getClass().getResource("play2.png")); + buttonNextBreakPoint = new ImageButton(new ImageIcon(img), new ImageIcon(img2)); + buttonNextBreakPoint.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + center.srcCodeCenter.clearGotoLine(); + setIsDebugging(false); + center.cmdBuffer.pushCmd(new ClientCmd("c")); + } + }); + } catch (Exception ex) { + } + panelHead.add(buttonNextBreakPoint); + panelHead.add(buttonNextLine); + + buttonNextCodeLine = new JButton("下一步"); + buttonNextCodeLine.setPreferredSize(new Dimension(Config.BTN_W, Config.BTN_H)); + buttonNextCodeLine.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + center.srcCodeCenter.clearGotoLine(); + setIsDebugging(false); + center.cmdBuffer.pushCmd(new ClientCmd("s")); + } + }); + panelHead.add(buttonNextCodeLine); + + buttonCallStack = new JButton("显示调用栈"); + buttonCallStack.setPreferredSize(new Dimension(Config.BTN_W2, Config.BTN_H)); + buttonCallStack.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + center.cmdBuffer.pushCmd(new ClientCmd("bt")); + } + }); + panelHead.add(buttonCallStack); + + JPanel panelBody = new JPanel(); + panelBody.setBorder(null); + panel.add(panelBody, BorderLayout.CENTER); + panelBody.setLayout(new BorderLayout(0, 0)); + + JSplitPane splitPane = new JSplitPane(); + splitPane.setDividerSize(7); + try { + splitPane.setUI(new BasicSplitPaneUI() { + public BasicSplitPaneDivider createDefaultDivider() { + return new BasicSplitPaneDivider(this) { + private static final long serialVersionUID = -7493346152989839058L; + private Color color = new Color(171, 171, 171); + + public void setBorder(Border b) { + } + + public void paint(Graphics g) { + super.paint(g); + int w = this.getWidth(); + int h = this.getHeight(); + g.setClip(0, 0, w, h); + g.setColor(color); + g.drawLine(0, 0, w, 0); + g.drawLine(0, h, w, h); + } + }; + } + }); + } catch (Exception e) { + + } + + // splitPane.setBorderPainted(false);// 不打印边框 + splitPane.setBorder(null);// 除去边框 + splitPane.setResizeWeight(0.8); + splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT); + panelBody.add(splitPane, BorderLayout.CENTER); + + JScrollPane scrollPane = new JScrollPane(); + scrollPane.setBorder(null); + scrollPane.setViewportBorder(null); + scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); + scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); + splitPane.setRightComponent(scrollPane); + + outputArea = new JTextArea(); + outputArea.setTabSize(4); + outputArea.setLineWrap(true); + outputArea.setBorder(null); + scrollPane.setViewportView(outputArea); + + tabbedPane = new BottomLineTabbedPane(JTabbedPane.TOP); + tabbedPane.setBorder(null); + tabbedPane.setUI(new EclipseTabbedPaneUI()); + splitPane.setLeftComponent(tabbedPane); + + setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); + addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent e) { + center.worker.close(); + } + }); + } + + private JTabbedPane tabbedPane; + private JTextArea outputArea; + private JButton buttonNextLine; + private JButton buttonNextCodeLine; + private JButton buttonNextBreakPoint; + private JButton buttonCallStack; + + public JTabbedPane getTabbedPane() { + return tabbedPane; + } + + public JTextArea getOutputArea() { + return outputArea; + } + + public JTextField getTextFieldCmdInput() { + return textFieldCmdInput; + } + + public JButton getButtonNextLine() { + return buttonNextLine; + } + + public JButton getButtonNextCodeLine() { + return buttonNextCodeLine; + } + + public JButton getButtonNextBreakPoint() { + return buttonNextBreakPoint; + } + + public void setIsDebugging(boolean yes) { + this.getButtonNextLine().setEnabled(yes); + this.getButtonNextCodeLine().setEnabled(yes); + this.getButtonNextBreakPoint().setEnabled(yes); + this.getTextFieldCmdInput().setEnabled(yes); + this.buttonCallStack.setEnabled(yes); + } +} diff --git a/LuaViewDebugger/src/com/alibaba/luaview/debugger/ui/EclipseTabbedPaneUI.java b/LuaViewDebugger/src/com/alibaba/luaview/debugger/ui/EclipseTabbedPaneUI.java new file mode 100644 index 00000000..4844aaa6 --- /dev/null +++ b/LuaViewDebugger/src/com/alibaba/luaview/debugger/ui/EclipseTabbedPaneUI.java @@ -0,0 +1,185 @@ +package com.alibaba.luaview.debugger.ui; + +import java.awt.Color; +import java.awt.Font; +import java.awt.FontMetrics; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Insets; +import java.awt.Rectangle; +import java.awt.RenderingHints; +import java.awt.Shape; + +import javax.swing.Icon; +import javax.swing.plaf.basic.BasicTabbedPaneUI; + +public class EclipseTabbedPaneUI extends BasicTabbedPaneUI { + + public static final Color LINE_COLOR = new Color(182, 188, 203); + + private static final int R = 13; + + @Override + protected void paintTabBorder(Graphics g, int tabPlacement, int tabIndex, int x, int y, int w, int h, boolean isSelected) { + if (tabPlacement == BOTTOM) { + g.setColor(LINE_COLOR); + g.drawLine(x, y + h - 1, x + w, y + h - 1); + } + + if (tabPlacement == TOP && isSelected) { + g.setColor(LINE_COLOR); + Shape shape = g.getClip(); + g.setClip(x, y, w + 2, h); + g.drawRoundRect(x, y, w, h + R + R, R, R); + g.setClip(shape); + } + + } + + protected void paintTab(Graphics g, int tabPlacement, Rectangle[] rects, int tabIndex, Rectangle iconRect, Rectangle textRect) { + super.paintTab(g, tabPlacement, rects, tabIndex, iconRect, textRect); + } + + /** + * Give selected tab blue color with a gradient!!. + * + * FIXME: with Plastic L&F the unselected background is too dark + */ + @Override + protected void paintTabBackground(Graphics g, int tabPlacement, int tabIndex, int x, int y, int w, int h, boolean isSelected) { + // Color color = UIManager.getColor("control"); + if (isSelected) { + if (tabPlacement == TOP) { + g.setColor(Color.white); + g.fillRoundRect(x, y, w, h + R + R, R, R); + } + } else { + } + } + + /** + * Do not paint a focus indicator. + */ + @Override + protected void paintFocusIndicator(Graphics arg0, int arg1, Rectangle[] arg2, int arg3, Rectangle arg4, Rectangle arg5, boolean arg6) { + // Leave it + } + + /** + * We do not want the tab to "lift up" when it is selected. + */ + @Override + protected void installDefaults() { + super.installDefaults(); + tabAreaInsets = new Insets(0, 0, 0, 0); + selectedTabPadInsets = new Insets(0, 0, 0, 0); + contentBorderInsets = new Insets(1, 0, 0, 0); + } + + /** + * Nor do we want the label to move. + */ + @Override + protected int getTabLabelShiftY(int tabPlacement, int tabIndex, boolean isSelected) { + return 0; + } + + /** + * Increase the tab height a bit + */ + @Override + protected int calculateTabHeight(int tabPlacement, int tabIndex, int fontHeight) { + return fontHeight + 4; + } + + @Override + protected void layoutLabel(int arg0, FontMetrics arg1, int arg2, String arg3, Icon arg4, Rectangle arg5, Rectangle arg6, Rectangle arg7, boolean arg8) { + super.layoutLabel(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); + } + + /** + * Selected labels have a white color. + */ + @Override + protected void paintText(Graphics tempG, int tabPlacement, Font font, FontMetrics metrics, int tabIndex, String title, Rectangle textRect, + boolean isSelected) { + + Graphics2D g = (Graphics2D) tempG; + g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + if (isSelected && tabPlacement == TOP) { + g.setColor(Color.BLACK); + } else { + g.setColor(Color.BLACK); + } + g.drawString(title, textRect.x, textRect.y + metrics.getAscent()); + } + + @Override + protected int calculateTabWidth(int tabPlacement, int tabIndex, FontMetrics metrics) { + int taille = 0; + taille = super.calculateTabWidth(tabPlacement, tabIndex, metrics); + return taille; + } + + @Override + protected void paintContentBorderTopEdge(Graphics g, int tabPlacement, int selectedIndex, int x, int y, int w, int h) { + if (selectedIndex != -1 && tabPlacement == TOP) { + g.setColor(LINE_COLOR); + g.drawLine(x, y, x + w, y); + } + if (tabPlacement == BOTTOM) { + // g.setColor(Color.black); + // g.drawLine(x, y + h - 1, x + w, y + h - 1); + } + } + + @Override + protected void paintContentBorderBottomEdge(Graphics g, int tabPlacement, int selectedIndex, int x, int y, int w, int h) { + g.setColor(LINE_COLOR); + g.drawLine(x, y + h, x + w, y + h); + } + + @Override + protected void paintContentBorderLeftEdge(Graphics g, int tabPlacement, int selectedIndex, int x, int y, int w, int h) { + // do nothingx, y, x, y + h); + } + + @Override + protected void paintContentBorderRightEdge(Graphics g, int tabPlacement, int selectedIndex, int x, int y, int w, int h) { + // do nothing + } + + // @Override + // protected MouseListener createMouseListener() { + // return new CloseHandler(); + // } + // + // class CloseHandler extends MouseHandler { + // public CloseHandler() { + // super(); + // } + // + // public void mouseReleased(MouseEvent e) { + // int x = e.getX(); + // int y = e.getY(); + // int tabIndex = -1; + // int tabCount = tabPane.getTabCount(); + // for (int i = 0; i < tabCount; i++) { + // if (rects[i].contains(x, y)) { + // tabIndex = i; + // break; + // } + // } + // + // if (tabIndex >= 0 && !e.isPopupTrigger()) { + // Rectangle tabRect = rects[tabIndex]; + // y = y - tabRect.y; + // if ((x >= tabRect.x + tabRect.width - 18) && (x <= tabRect.x + + // tabRect.width - 8) && (y >= 5) && (y <= 15)) { + // tabPane.remove(tabIndex); + // } + // } + // } + // } + +} \ No newline at end of file diff --git a/LuaViewDebugger/src/com/alibaba/luaview/debugger/ui/HeadPanel.java b/LuaViewDebugger/src/com/alibaba/luaview/debugger/ui/HeadPanel.java new file mode 100644 index 00000000..dc447c27 --- /dev/null +++ b/LuaViewDebugger/src/com/alibaba/luaview/debugger/ui/HeadPanel.java @@ -0,0 +1,33 @@ +package com.alibaba.luaview.debugger.ui; + +import java.awt.Color; +import java.awt.Graphics; +import java.awt.Graphics2D; + +import javax.swing.JPanel; + +public class HeadPanel extends JPanel { + + private static final long serialVersionUID = -4421177374953807366L; + + public void paint(Graphics tempG) { + if (tempG instanceof Graphics2D == false) { + return; + } + Graphics2D g = (Graphics2D) tempG; + // g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, + // RenderingHints.VALUE_ANTIALIAS_ON); + int w = this.getWidth(); + int h = this.getHeight(); + + for (int i = 0; i < h; i++) { + int t = (207 * (h - i) + 171 * i) / h; + Color c = new Color(t, t, t); + g.setColor(c); + g.drawLine(0, i, w, i); + } + g.setColor(new Color(81, 81, 81)); + g.drawLine(0, h - 1, w, h - 1); + this.paintChildren(g); + } +} diff --git a/LuaViewDebugger/src/com/alibaba/luaview/debugger/ui/ImageButton.java b/LuaViewDebugger/src/com/alibaba/luaview/debugger/ui/ImageButton.java new file mode 100644 index 00000000..20f35025 --- /dev/null +++ b/LuaViewDebugger/src/com/alibaba/luaview/debugger/ui/ImageButton.java @@ -0,0 +1,39 @@ +package com.alibaba.luaview.debugger.ui; + +import java.awt.Dimension; +import java.awt.Image; +import java.awt.Insets; + +import javax.swing.ImageIcon; +import javax.swing.JButton; + +import com.alibaba.luaview.debugger.Config; + +public class ImageButton extends JButton { + private static final int BUT_H = Config.BTN_H - 2; + + private static final long serialVersionUID = -8171450113272087720L; + + private int left = 20; + private int right = 2; + + public ImageButton(ImageIcon icon, ImageIcon icon2) { + icon = changeIcon(icon); + icon2 = changeIcon(icon2); + setIcon(icon); + this.setDisabledIcon(icon2); + setMargin(new Insets(0, left, 0, right));// 将边框外的上下左右空间设置为0 + setIconTextGap(0);// 将标签中显示的文本和图标之间的间隔量设置为0 + setBorderPainted(false);// 不打印边框 + setBorder(null);// 除去边框 + setText(null);// 除去按钮的默认名称 + setFocusPainted(false);// 除去焦点的框 + setContentAreaFilled(false);// 除去默认的背景填充 + this.setPreferredSize(new Dimension(BUT_H + left + right, BUT_H)); + } + + public static ImageIcon changeIcon(ImageIcon ico) { + Image temp = ico.getImage().getScaledInstance(BUT_H, BUT_H, Image.SCALE_SMOOTH); + return new ImageIcon(temp); + } +} \ No newline at end of file diff --git a/LuaViewDebugger/src/com/alibaba/luaview/debugger/ui/Line.java b/LuaViewDebugger/src/com/alibaba/luaview/debugger/ui/Line.java new file mode 100644 index 00000000..977ebf96 --- /dev/null +++ b/LuaViewDebugger/src/com/alibaba/luaview/debugger/ui/Line.java @@ -0,0 +1,42 @@ +package com.alibaba.luaview.debugger.ui; + +import java.awt.Graphics2D; +import java.util.Vector; + +public class Line { + int index; + String tag; + int x; + int y; + int width; + int higth; + final String text; + boolean isBreakPoint; + boolean isCurrentLine; + + final Vector words; + + public Line(String s) { + this.text = s; + words = new CharsToWords().split(s); + } + + public int draw(Graphics2D g, int x, int y) { + for (int i = 0; i < words.size(); i++) { + Word word = words.elementAt(i); + x = word.draw(g, x, y); + } + return x; + } + + public String getPressedString(int x, int y) { + for (int i = 0; i < words.size(); i++) { + Word word = words.elementAt(i); + String s = word.getPressedString(x, y); + if (s != null) { + return s; + } + } + return null; + } +} diff --git a/LuaViewDebugger/src/com/alibaba/luaview/debugger/ui/SrcCodeCenter.java b/LuaViewDebugger/src/com/alibaba/luaview/debugger/ui/SrcCodeCenter.java new file mode 100644 index 00000000..75883a85 --- /dev/null +++ b/LuaViewDebugger/src/com/alibaba/luaview/debugger/ui/SrcCodeCenter.java @@ -0,0 +1,109 @@ +package com.alibaba.luaview.debugger.ui; + +import java.util.Hashtable; + +import javax.swing.JTabbedPane; + +import com.alibaba.luaview.debugger.Center; + +public class SrcCodeCenter { + public final Center center; + + public SrcCodeCenter(Center center) { + this.center = center; + } + + final Hashtable table = new Hashtable(); + + public void showHelpTab() { + String s = "h help info" + "\n" + // + "c continue run" + "\n" + // + "s trace" + "\n" + // + "n next" + "\n" + // + "p var print variable" + "\n" + // + "b src:line add breakpoint" + "\n" + // + "rb src:line remove breakpoint" + "\n" + // + "bl list breakpoint" + "\n" + // + "bt print traceback" + "\n"; + loadfile("帮助信息", s).canBreakPoint = false; + } + + public SrcCodeViewer loadfile(String fileName, String content) { + content = content.replace("\t", " "); + JTabbedPane tabbedPane = center.frame.getTabbedPane(); + if (fileName != null) { + SrcCodeViewer temp = table.get(fileName); + tabbedPane.remove(temp); + table.remove(fileName); + } + SrcCodeViewer viewer = new SrcCodeViewer(fileName, content, this.center); + this.addToTabbedPane(tabbedPane, fileName, viewer); + table.put(fileName, viewer); + return viewer; + } + + private void addToTabbedPane(JTabbedPane tabbedPane, String fileName, SrcCodeViewer viewer) { + int num = tabbedPane.getTabCount(); + String newTitle = this.shortName(fileName); + for (int i = 0; i < num; i++) { + String title = tabbedPane.getTitleAt(i); + if (newTitle.compareTo(title) > 0) { + tabbedPane.insertTab(newTitle, null, viewer, null, i); + return; + } + } + tabbedPane.addTab(newTitle, viewer); + } + + private String shortName(String s) { + int index = s.lastIndexOf('/'); + if (index >= 0) { + s = s.substring(index + 1); + } + s = s.trim(); + if (s.endsWith(".lua")) { + s = s.substring(0, s.length() - 4); + } + if (s.endsWith(".lv")) { + s = s.substring(0, s.length() - 3); + } + return s.trim(); + } + + public void running(String fileName, String lineNumber) { + try { + if (fileName != null) { + SrcCodeViewer viewer = table.get(fileName); + if (viewer != null) { + viewer.gotoLine(Integer.parseInt(lineNumber.trim())); + + JTabbedPane tabbedPane = center.frame.getTabbedPane(); + tabbedPane.setSelectedComponent(viewer); + if (center.frame.isAlwaysOnTop()) { + center.frame.setAlwaysOnTop(true); + } + if (center.frame.isVisible()) { + center.frame.setVisible(true); + } + center.frame.setIsDebugging(true); + } + } + } catch (Exception e) { + e.printStackTrace(); + } + // System.out.println(fileName + lineNumber); + } + + public void clearGotoLine() { + try { + JTabbedPane tabbedPane = center.frame.getTabbedPane(); + SrcCodeViewer viewer = (SrcCodeViewer) tabbedPane.getSelectedComponent(); + if (viewer != null) { + viewer.clearGotoLine(); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + +} diff --git a/LuaViewDebugger/src/com/alibaba/luaview/debugger/ui/SrcCodeScrollPanel.java b/LuaViewDebugger/src/com/alibaba/luaview/debugger/ui/SrcCodeScrollPanel.java new file mode 100755 index 00000000..5e212860 --- /dev/null +++ b/LuaViewDebugger/src/com/alibaba/luaview/debugger/ui/SrcCodeScrollPanel.java @@ -0,0 +1,352 @@ +package com.alibaba.luaview.debugger.ui; + +import java.awt.Color; +import java.awt.Font; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Point; +import java.awt.RenderingHints; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.awt.event.MouseMotionListener; +import java.awt.event.MouseWheelEvent; +import java.awt.event.MouseWheelListener; + +import javax.swing.JPanel; + +import com.alibaba.luaview.debugger.Config; + +abstract public class SrcCodeScrollPanel extends JPanel { + + private static final long serialVersionUID = -8495786914354054078L; + + private Font font = new java.awt.Font("宋体", 0, 14); + + public final int LINE_H = Config.LINE_H; + + private int bar_w = 15; + + private int max_w, max_h; + + private Point point, pointPressed, draggedPoint, m_repressedPoint; + private int m_pressedButtonID = -1; + + private final Point zeroPoint = new Point(0, 0); + + public boolean updateUI = true; + + public SrcCodeScrollPanel() { + this.setBorder(null); + this.addMouseWheelListener(new MouseWheelListener() { + + public void mouseWheelMoved(MouseWheelEvent arg0) { + zeroPoint.y += arg0.getWheelRotation() * 50; + if (updateUI) + updateUI(); + } + + }); + this.addMouseMotionListener(new MouseMotionListener() { + + public void mouseDragged(MouseEvent arg0) { + if (pointPressed == null) { + return; + } + if (draggedPoint == null) { + draggedPoint = arg0.getPoint(); + return; + } + if (isOnBarArea(pointPressed.x)) { + Point oldPoint = draggedPoint; + Point newPoint = arg0.getPoint(); + draggedPoint = newPoint; + scrollBar(newPoint.y - oldPoint.y); + } else { + Point oldPoint = draggedPoint; + Point newPoint = arg0.getPoint(); + draggedPoint = newPoint; + zeroPoint.x -= newPoint.x - oldPoint.x; + zeroPoint.y -= newPoint.y - oldPoint.y; + } + if (updateUI) + updateUI(); + } + + public void mouseMoved(MouseEvent arg0) { + } + + }); + /** + * 鼠标点击 + */ + addMouseListener(new MouseListener() { + public void mouseClicked(MouseEvent e) { + m_pressedButtonID = e.getButton(); + if (e.getClickCount() >= 2) { + m_repressedPoint = e.getPoint(); + } + } + + public void mouseEntered(MouseEvent e) { + int t = e.getButton(); + if (0 <= t && t <= 2) { + } else { + draggedPoint = point = pointPressed = null; + } + } + + public void mouseExited(MouseEvent e) { + int t = e.getButton(); + if (0 <= t && t <= 2) { + } else { + draggedPoint = point = pointPressed = null; + } + } + + public void mousePressed(MouseEvent e) { + draggedPoint = point = pointPressed = null; + pointPressed = e.getPoint(); + + Point t = e.getPoint(); + if (!isOnBarArea(t.x)) { + point = t; + } + requestFocus(); + updateUI(); + } + + public void mouseReleased(MouseEvent e) { + draggedPoint = point = pointPressed = null; + } + }); + } + + private boolean isOnBarArea(int x) { + if (screenW - bar_w < x && x < screenW) + return true; + return false; + } + + private void scrollBar(int dy) { + zeroPoint.y += dy * max_h / screenH; + } + + public void update(Graphics g) { + paint(g); + } + + private int screenW = 100, screenH = 100; + + public void paint(Graphics tempG) { + if (tempG instanceof Graphics2D == false) { + return; + } + Graphics2D g = (Graphics2D) tempG; + g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + g.setFont(font); + if (nextY >= 0) { + zeroPoint.y = nextY; + nextY = -1; + } + screenW = getWidth(); + screenH = getHeight(); + max_w = max_w < screenW ? screenW : max_w; + max_h = max_h < screenH ? screenH : max_h; + if (zeroPoint.x < 0) { + zeroPoint.x = 0; + } else if (zeroPoint.x > max_w - screenW) { + zeroPoint.x = max_w - screenW; + } + if (zeroPoint.y < 0) { + zeroPoint.y = 0; + } else if (zeroPoint.y > max_h - screenH) { + zeroPoint.y = max_h - screenH; + } + g.setColor(Color.white); + g.fillRect(0, 0, screenW, screenH); + // 显示位置 + g.setClip(0, 0, screenW - bar_w, screenH); + g.translate(-zeroPoint.x, -zeroPoint.y); + myPaint(g);// ////////////////////// + g.translate(zeroPoint.x, zeroPoint.y); + // bar + int bar_X = screenW - bar_w; + int bar_Y = zeroPoint.y * screenH / max_h; + int bar_W = bar_w; + int bar_H = screenH * screenH / max_h; + if (bar_H > screenH - 1) { + bar_H = screenH - 1; + } + g.setClip(0, 0, screenW, screenH); + g.setColor(new Color(250, 250, 250)); + g.fillRect(screenW - bar_w, -1, bar_w + 1, screenH + 2); + g.setColor(new Color(232, 232, 232)); + g.drawRect(screenW - bar_w, -1, bar_w + 8, screenH + 2); + fillBar(g, bar_X, bar_Y, bar_W, bar_H); + + if (m_repaint) { + m_repaint = false; + if (updateUI) + updateUI(); + } + } + + private void fillBar(Graphics g, int x, int y, int w, int h) { + y += 3; + h -= 6; + h = h < 2 ? 2 : h; + x += 4; + w -= 8; + g.setColor(new Color(194, 194, 194)); + g.fillRoundRect(x, y, w, h, w, w); + // for (int i = 0; i < w / 2; i++) { + // int t = 255 * (i + T) / ((w / 2) + T); + // Color c = new Color((t << 16) + (t << 8) + t); + // g.setColor(c); + // g.drawLine(x + i, y, x + i, y + h); + // } + // for (int i = w / 2; i < w; i++) { + // int t = 255 * ((w - i) + T) / ((w / 2) + T); + // Color c = new Color((t << 16) + (t << 8) + t); + // g.setColor(c); + // g.drawLine(x + i, y, x + i, y + h); + // } + } + + abstract public void myPaint(Graphics2D g); + + public boolean isRectOnView(int topX, int topY, int endX, int endY) { + int viewX0 = zeroPoint.x; + int viewY0 = zeroPoint.y; + int viewX2 = zeroPoint.x + screenW; + int viewY2 = zeroPoint.y + screenH; + + int tempx0 = topX > viewX0 ? topX : viewX0; + int tempy0 = topY > viewY0 ? topY : viewY0; + int tempx2 = endX > viewX2 ? endX : viewX2; + int tempy2 = endY > viewY2 ? endY : viewY2; + if (tempx0 < tempx2 && tempy0 < tempy2) { + return true; + } + return false; + } + + public boolean isYOnView(int y) { + int viewY0 = zeroPoint.y; + int viewY2 = zeroPoint.y + screenH; + if (y >= viewY0 && y < viewY2) { + return true; + } + return false; + } + + private int nextY = -1; + + public void setNextYOnView(int y) { + // System.out.println("y:" + y); + if (isYOnView(y) == false) { + int viewY0 = zeroPoint.y; + int viewY2 = zeroPoint.y + screenH; + if (Math.abs(viewY0 - y) < Math.abs(viewY2 - y)) { + nextY = y - LINE_H; + } else { + nextY = y - screenH + LINE_H; + } + } else { + nextY = -1; + } + } + + public void resetMaxWH() { + max_w = 10; + max_h = 10; + } + + public void setMaxW(int w) { + max_w = w < max_w ? max_w : w; + } + + public int getMaxW() { + return max_w; + } + + public void setMaxH(int h) { + max_h = h < max_h ? max_h : h; + } + + public boolean isPressThePoint(int x, int y, int r) { + if (point != null) { + int tmp = Math.abs(point.x + zeroPoint.x - x) + Math.abs(point.y + zeroPoint.y - y); + if (tmp < r) { + point = null; + return true; + } + } + return false; + } + + public boolean isPressTheLine(int x, int y, int h) { + if (point != null) { + int pY = point.y + zeroPoint.y; + int y0 = y - h; + int y1 = y; + if (y0 < pY && pY < y1) { + return true; + } + } + return false; + } + + public int pressedPointX() { + if (point != null) { + return point.x + zeroPoint.x; + } + return 0; + } + + public int pressedPointY() { + if (point != null) { + return point.y + zeroPoint.y; + } + return 0; + } + + public int pressedButtonID() { + return m_pressedButtonID; + } + + public void clearPoint() { + point = null; + } + + private boolean m_repaint; + + public void shouldRepaint() { + m_repaint = true; + } + + public Point getPressedPoint() { + Point t = point; + if (t != null) { + t.x += zeroPoint.x; + t.y += zeroPoint.y; + } + point = null; + return t; + } + + public Point getRepressedPoint() { + Point t = m_repressedPoint; + if (t != null) { + t.x += zeroPoint.x; + t.y += zeroPoint.y; + } + m_repressedPoint = null; + return t; + } + + public void setBarW(int w) { + bar_w = w; + } + +} diff --git a/LuaViewDebugger/src/com/alibaba/luaview/debugger/ui/SrcCodeViewer.java b/LuaViewDebugger/src/com/alibaba/luaview/debugger/ui/SrcCodeViewer.java new file mode 100755 index 00000000..65eba003 --- /dev/null +++ b/LuaViewDebugger/src/com/alibaba/luaview/debugger/ui/SrcCodeViewer.java @@ -0,0 +1,242 @@ +package com.alibaba.luaview.debugger.ui; + +/** + * AWT Sample application + * + * @author + * @version 1.00 05/09/22 + */ + +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.Font; +import java.awt.FontMetrics; +import java.awt.Graphics2D; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; +import java.util.Vector; + +import com.alibaba.luaview.debugger.Center; +import com.alibaba.luaview.debugger.ClientCmd; + +// 类的作用:树结构的浏览器 +/** + * + * @author dongxicheng + * + */ +public final class SrcCodeViewer extends SrcCodeScrollPanel { + + private static final long serialVersionUID = -196018687886621L; + + private static final Color currentLineColor = new Color(221, 234, 207); + private static final Color breakPointBGColor = null; + // new Color(251, 238, 235); + + public boolean canBreakPoint = true; + + public final String fileName; + + private final Vector lines = new Vector(); + + private FontMetrics fontMetrics; + + private Center center; + + private Font font16 = new Font("黑体", Font.PLAIN, 13); + private Font font12 = new Font("黑体", Font.PLAIN, 10); + + SrcCodeViewer(String fileName, String content, Center center) { + super(); + this.center = center; + this.setFont(font16); + fontMetrics = getFontMetrics(getFont()); + + addKeyListener(new KeyListener() { + public void keyPressed(KeyEvent arg0) { + if (arg0.getKeyCode() == KeyEvent.VK_W) { + } else if (arg0.getKeyCode() == KeyEvent.VK_S) { + } else if (arg0.getKeyCode() == KeyEvent.VK_A) { + } else if (arg0.getKeyCode() == KeyEvent.VK_D) { + } + updateUI(); + } + + public void keyReleased(KeyEvent arg0) { + } + + public void keyTyped(KeyEvent arg0) { + } + }); + this.fileName = fileName; + this.setFileSting(content); + int len = (this.lines.size() + "").length(); + if (len < 2) { + len = 2; + } + this.X0_TAG = (int) (LINE_H * 0.5) * len; + this.X0 = this.X0_TAG + LINE_H; + } + + private void setFileSting(String s) { + this.lines.removeAllElements(); + String[] arr = s.split("\n"); + for (int i = 0; i < arr.length; i++) { + Line line = new Line(arr[i]); + line.index = i + 1;// 设置行号 + this.lines.add(line); + } + } + + private final int X0_TAG;// LINE_H * 5 / 2; + private final int X0;// LINE_H * 5 / 2; + private final int Y0 = LINE_H * 2; + + public void myPaint(Graphics2D g) { + g.setColor(new Color(0xf0f0f0)); + { + int h = (this.lines.size() + 5) * LINE_H; + if (h < this.getHeight()) { + h = this.getHeight(); + } + g.fillRect(0, 0, X0, h); + g.setColor(new Color(217, 217, 217)); + g.drawLine(X0, 0, X0, h); + } + resetMaxWH(); + try { + setNodeX(X0); + setNodeY(Y0); + } catch (Exception e) { + e.printStackTrace(); + } + for (int i = 0; i < this.lines.size(); i++) { + Line line = this.lines.elementAt(i); + line.tag = "" + (i + 1); + drawOneLine(true, line, g, line.x, line.y); + } + this.clearPoint(); + } + + BasicStroke stroke = new BasicStroke(1); + + /** + * 显示root + * + * @param line + * @param g + * @param topX + * @param topY + */ + private void drawOneLine(boolean yes, Line line, Graphics2D g, int topX, int topY) { + if (line == null) + return; + int x = line.x; + int y = line.y; + + if (isYOnView(y - LINE_H) || isYOnView(y + LINE_H)) { + if (line.isBreakPoint && breakPointBGColor != null) { + g.setColor(breakPointBGColor); + g.fillRect(X0 + 1, y - LINE_H, this.getWidth(), LINE_H); + } + + if (line.isCurrentLine) { + g.setColor(currentLineColor); + g.fillRect(X0 + 1, y - LINE_H, this.getWidth(), LINE_H); + } + + g.setColor(Color.BLACK); + + line.draw(g, x + 2, y - 3); + + if (line.isBreakPoint) {// 断点 + int dx = 2; + g.setColor(Color.red); + g.fillArc(this.X0_TAG + 3, y - LINE_H + dx, LINE_H - dx * 2, LINE_H - dx * 2, 0, 360); + } + + g.setColor(Color.GRAY); + g.setFont(font12); + int w = g.getFontMetrics().stringWidth(line.tag); + g.drawString(line.tag, X0_TAG - w, y - 3); + g.setFont(font16); + } + if (this.pressedPointX() < X0 && this.canBreakPoint && isPressTheLine(x, y, LINE_H)) { + line.isBreakPoint = !line.isBreakPoint; + updateUI(); + if (line.isBreakPoint) { + String s = "b " + this.fileName + ":" + line.index; + center.cmdBuffer.pushCmd(new ClientCmd(s)); + } else { + String s = "rb " + this.fileName + ":" + line.index; + center.cmdBuffer.pushCmd(new ClientCmd(s)); + } + } + + if (X0 < this.pressedPointX() && isPressTheLine(x, y, LINE_H)) { + String s = line.getPressedString(this.pressedPointX(), this.pressedPointY()); + if (s != null && s.length() > 0) { + if (s.indexOf('.') < 0) { + center.cmdBuffer.pushCmd(new ClientCmd("p " + s)); + } else { + center.cmdBuffer.pushCmd(new ClientCmd("run print(\"" + s + " =\" , " + s + ")")); + } + } + } + } + + /** + * 设置x坐标 + * + * @param node + * @param x0 + * @param PER_WIDTH + */ + private void setNodeX(int x0) { + for (int i = 0; i < this.lines.size(); i++) { + Line node = this.lines.elementAt(i); + if (node == null) { + return; + } + node.x = x0; + + node.width = fontMetrics.stringWidth(node.text) + 16; + + int tempX = node.x + node.width + 100; + this.setMaxW(tempX); + } + } + + /** + * 设置y坐标 + * + * @param node + * @return + */ + private void setNodeY(int y0) { + for (int i = 0; i < this.lines.size(); i++) { + Line obj = this.lines.elementAt(i); + obj.y = y0 + i * LINE_H; + setMaxH(obj.y + 50); + } + } + + public void gotoLine(int lineNumber) { + lineNumber -= 1; + for (int i = 0; i < this.lines.size(); i++) { + Line line = this.lines.elementAt(i); + if (lineNumber == i) { + line.isCurrentLine = true; + } else { + line.isCurrentLine = false; + } + } + this.setNextYOnView(lineNumber * LINE_H + Y0); + this.updateUI(); + } + + public void clearGotoLine() { + this.gotoLine(-100); + } + +} diff --git a/LuaViewDebugger/src/com/alibaba/luaview/debugger/ui/UICmd.java b/LuaViewDebugger/src/com/alibaba/luaview/debugger/ui/UICmd.java new file mode 100644 index 00000000..176aeee6 --- /dev/null +++ b/LuaViewDebugger/src/com/alibaba/luaview/debugger/ui/UICmd.java @@ -0,0 +1,28 @@ +package com.alibaba.luaview.debugger.ui; + +public class UICmd { + + public final String cmd;// log/load + + public final String fileName; + + public final String content; + + public UICmd(String cmd, String fileName, String info) { + this.cmd = trim(cmd); + this.fileName = trim(fileName); + this.content = info; + } + + private String trim(String s) { + if (s != null) { + s = s.trim(); + if (s.startsWith(":")) { + s = s.substring(1); + } + return s.trim(); + } + return s; + } + +} diff --git a/LuaViewDebugger/src/com/alibaba/luaview/debugger/ui/Updater.java b/LuaViewDebugger/src/com/alibaba/luaview/debugger/ui/Updater.java new file mode 100644 index 00000000..96b95759 --- /dev/null +++ b/LuaViewDebugger/src/com/alibaba/luaview/debugger/ui/Updater.java @@ -0,0 +1,64 @@ +package com.alibaba.luaview.debugger.ui; + +import com.alibaba.luaview.debugger.Center; +import com.alibaba.luaview.debugger.ui.UICmd; + +public final class Updater { + public final String CMD_NAME = "Cmd-Name:".toLowerCase(); + public final String FILE_NAME = "File-Name:".toLowerCase(); + + private final Center center; + + public Updater(Center center) { + this.center = center; + } + + private UICmd readCmd(String string) throws Exception { + String[] heads = null; + String info = null; + {// parse head + int index = string.indexOf("\n\n"); + if (index >= 0) { + String headString = string.substring(0, index); + info = string.substring(index + 2); + heads = headString.split("\n"); + } + } + String cmdName = null; + String fileName = null; + for (int i = 0; i < heads.length; i++) { + String s = heads[i]; + if (s != null && s.length() > 0) { + String str = s.toLowerCase(); + if (str.startsWith(CMD_NAME)) { + cmdName = s.substring(CMD_NAME.length()); + } else if (str.startsWith(FILE_NAME)) { + fileName = s.substring(FILE_NAME.length()); + } + } + } + UICmd cmd = new UICmd(cmdName, fileName, info); + return cmd; + } + + public void run(String string) { + try { + UICmd cmd = this.readCmd(string); + if (cmd.cmd != null) { + if ("log".equals(cmd.cmd)) { + center.log.print(cmd.content); + } else if ("loadfile".equals(cmd.cmd)) { + this.center.srcCodeCenter.loadfile(cmd.fileName, cmd.content); + center.frame.setTitle(cmd.fileName); + } else if ("running".equals(cmd.cmd)) { + this.center.srcCodeCenter.running(cmd.fileName, cmd.content); + } else { + System.err.println("unkonw cmd: " + cmd.cmd); + } + } + } catch (Exception e) { + e.printStackTrace(); + } + } + +} \ No newline at end of file diff --git a/LuaViewDebugger/src/com/alibaba/luaview/debugger/ui/Word.java b/LuaViewDebugger/src/com/alibaba/luaview/debugger/ui/Word.java new file mode 100644 index 00000000..39927354 --- /dev/null +++ b/LuaViewDebugger/src/com/alibaba/luaview/debugger/ui/Word.java @@ -0,0 +1,138 @@ +package com.alibaba.luaview.debugger.ui; + +import java.awt.Color; +import java.awt.Graphics2D; +import java.util.Hashtable; + +import com.alibaba.luaview.debugger.Config; + +public final class Word { + private static final Color KeyWordColor = new Color(184, 51, 161); + private static final Color ClassNameColor = new Color(111, 65, 167); + private static final Color MemberColor = new Color(80, 129, 135); + private static final Color StringWordColor = new Color(207, 49, 37); + + private static final Color NumberWordColor = new Color(41, 52, 212); + private static final Color CommentWordColor = new Color(146, 146, 146); + + private static final Hashtable keyWordsMap = new Hashtable(); + { + String[] keys = { "for", "if", "else", "elseif", "then", "do", "end", "while",// + "print", "return", "function", "local",// + "self", "this", "contine", "break", "null", "nil",// + "true", "false", "^", "~", "!", ":", "repeat", "until",// + "debug", "math", "string", "table", "ipairs", "pairs", "require", }; + for (int i = 0; i < keys.length; i++) { + String key = keys[i]; + keyWordsMap.put(key, key); + } + } + + public static boolean isKeyWord(String key) { + return keyWordsMap.get(key) != null; + } + + private static final Hashtable globalsMap = new Hashtable(); + { + String[] keys = { "window", "debug", "math", "string", "table", "ipairs", "pairs", "require", }; + for (int i = 0; i < keys.length; i++) { + String key = keys[i]; + globalsMap.put(key, key); + } + } + + public static boolean isClassName(String key) { + if (key != null && key.length() > 0) { + char c = key.charAt(0); + if ('A' <= c && c <= 'Z') { + return true; + } + } + return globalsMap.get(key) != null; + } + + public final String text; + public final Color color; + public boolean isWord; + public boolean isKeyWord; + public boolean isNumber; + public boolean isString; + public boolean isComment; + public boolean isClassName; + public boolean isMember; + + public Word prev; + public Word next; + + // 宽高信息 + int x; + int w; + int y; + int h; + + public String getPressedString(int x, int y) { + // && this.y <= y && y <= this.y + this.h + if (this.x <= x && x <= this.x + this.w) { + String s = this.text.trim(); + Word w = this; + for (; w.prev != null && w.prev.prev != null && w.prev.text.equals(".") && w.prev.prev.isWord;) { + s = w.prev.prev.text + w.prev.text + w.text; + w = w.prev.prev; + } + return s; + } + return null; + } + + public Word(String s, Word prev) { + this.text = s; + if (isClassName(s)) { + this.isClassName = true; + this.color = ClassNameColor; + } else if (isKeyWord(s)) { + this.isKeyWord = true; + this.color = KeyWordColor; + } else if (s.startsWith("--")) { + this.isComment = true; + this.color = CommentWordColor; + } else if (s.startsWith("\"") || s.startsWith("\'")) { + this.isString = true; + this.color = StringWordColor; + } else if (s.length() > 0 && Character.isDigit(s.charAt(0))) { + this.isNumber = true; + this.color = NumberWordColor; + } else { + if (isMember(prev)) { + this.color = MemberColor; + } else { + this.color = Color.black; + } + } + if (s != null && s.length() > 0 && CharsToWords.wordStart(s.charAt(0))) { + this.isWord = true; + } + } + + private boolean isMember(Word pre) { + if (pre != null) { + if (".".equals(pre.text) || ":".equals(pre.text)) { + return true; + } + } + return false; + } + + public int draw(Graphics2D g, int x, int y) { + if (text != null) { + g.setColor(this.color); + g.drawString(text, x, y); + int x2 = x + g.getFontMetrics().stringWidth(text); + this.x = x; + this.y = y; + this.w = x2 - x; + this.h = Config.LINE_H; + return x2; + } + return x; + } +} diff --git a/LuaViewDebugger/src/com/alibaba/luaview/debugger/ui/play.png b/LuaViewDebugger/src/com/alibaba/luaview/debugger/ui/play.png new file mode 100644 index 00000000..732abb5b Binary files /dev/null and b/LuaViewDebugger/src/com/alibaba/luaview/debugger/ui/play.png differ diff --git a/LuaViewDebugger/src/com/alibaba/luaview/debugger/ui/play2.png b/LuaViewDebugger/src/com/alibaba/luaview/debugger/ui/play2.png new file mode 100644 index 00000000..4ac81cce Binary files /dev/null and b/LuaViewDebugger/src/com/alibaba/luaview/debugger/ui/play2.png differ diff --git a/LuaViewDebugger/src/com/alibaba/luaview/tools/DebugLuaCreaterMain.java b/LuaViewDebugger/src/com/alibaba/luaview/tools/DebugLuaCreaterMain.java new file mode 100644 index 00000000..e6b36681 --- /dev/null +++ b/LuaViewDebugger/src/com/alibaba/luaview/tools/DebugLuaCreaterMain.java @@ -0,0 +1,81 @@ +package com.alibaba.luaview.tools; + +import java.io.DataInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.PrintStream; +import java.nio.charset.Charset; +import java.util.Vector; + +public class DebugLuaCreaterMain { + + public static void main(String[] args) { + new DebugLuaCreaterMain().run(); + } + + private void run() { + byte[] bs = file_to_bytes("/Users/dongxicheng/Desktop/LuaView-SDK/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvdebug/debug.lua"); + PrintStream ps = getPrintStream("/Users/dongxicheng/Desktop/LuaView-SDK/LuaViewSDK/IOS/SDK/LuaViewSDK/Classes/lvdebug/LVDebugLua.m"); + ps.println(); + ps.println("// debug.lua"); + ps.println("char g_debug_lua[" + (bs.length + 1) + "] = {"); + ps.print(" "); + int index0 = 0; + for (int i = 0; i < bs.length; i++) { + int c = bs[i] & 0xff; + if (' ' <= c && c < 127 && c != '\'' && c != '\\') { + ps.print("'" + (char) c + "',"); + } else { + ps.print("0x" + Integer.toHexString(c) + ","); + } + if (c == '\n') { + ps.println(); + String s = new String(bs, index0, i - index0, Charset.forName("UTF-8")).trim(); + if (s.length() > 0) + ps.println(" // " + s); + index0 = i + 1; + ps.print(" "); + } + } + ps.println("0"); + ps.println("};"); + ps.println(); + ps.close(); + } + + private byte[] file_to_bytes(String fileName) { + try { + DataInputStream fis = new DataInputStream(new FileInputStream(fileName)); + int length = fis.available(); + byte[] bs = new byte[length]; + fis.readFully(bs); + fis.close(); + return bs; + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + void strings_to_file(Vector strings, String fileName) { + try { + PrintStream dos = getPrintStream(fileName); + for (int i = 0; i < strings.size(); i++) { + dos.println(strings.elementAt(i)); + } + dos.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + private PrintStream getPrintStream(String fileName) { + try { + PrintStream f = new PrintStream(new File(fileName), "UTF-8"); + return f; + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } +} diff --git a/LuaViewSDK.podspec b/LuaViewSDK.podspec new file mode 100644 index 00000000..8f39b36d --- /dev/null +++ b/LuaViewSDK.podspec @@ -0,0 +1,68 @@ + +Pod::Spec.new do |s| + + s.name = "LuaViewSDK" + s.version = "0.5.3" + s.summary = "LuaView SDK" + + s.description = <<-DESC + A longer description of LuaViewSDK.podspec in Markdown format. + * LuaView + DESC + + s.homepage = "http://gitlab.alibaba-inc.com/luaview/LuaViewSDK" + + + s.license = { :type => 'The MIT License (MIT)', :file => 'LICENSE.txt' } + + s.author = { "敛心" => "jinjin.jj@alibaba-inc.com" } + + # ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― # + # + # If this Pod runs only on iOS or OS X, then specify the platform and + # the deployment target. You can optionally include the target after the platform. + # + + s.platform = :ios, "7.0" + + s.source = { :git => "https://github.com/alibaba/LuaViewSDK.git", :tag => "v0.5.2" } + + # s.source_files = "IOS/SDK/LuaViewSDK/Classes/**/*.{h,m,c}", "IOS/lua/lua/*.{h,m,c}" + s.source_files = "IOS/SDK/LuaViewSDK/Classes/**/*.{h,m,c}" + # s.exclude_files = "Classes/Exclude" + + #s.public_header_files = "LuaViewSDK/Classes/**/*.h" + + + # ――― Resources ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # + # + # A list of resources included with the Pod. These are copied into the + # target bundle with a build phase script. Anything else will be cleaned. + # You can preserve files from being cleaned, please don't preserve + # non-essential files like tests, examples and documentation. + # + + # s.resource = "icon.png" + # s.resources = "Resources/*.png" + + # s.preserve_paths = "FilesToSave", "MoreFilesToSave" + + + # ――― Project Linking ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # + # + # Link your library with frameworks, or libraries. Libraries do not include + # the lib prefix of their name. + # + + s.frameworks = 'Foundation', 'UIKit', 'CoreGraphics', 'AVFoundation' + s.libraries = 'z' + + # ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # + # + # If your library depends on compiler flags you can set them in the xcconfig hash + # where they will only apply to your library. If you depend on other Podspecs + # you can include multiple dependencies to ensure it works. + + s.requires_arc = true + +end diff --git a/README.md b/README.md new file mode 100644 index 00000000..36a373ce --- /dev/null +++ b/README.md @@ -0,0 +1,114 @@ +# Welcome to LuaViewSDK + +LuaViewSDK is a cross-platform framework which is designed to build native, dynamic and swift user interfaces. It's based on Lua VM and chooses lua as it's script language. + +## Why Lua + +* Lua is a efficient and swift language. A single Lua VM costs 200k to 300k memorys only in iOS +* Lua is widly used and it's easy to bind to third party frameworks +* LuaView API is nature to native mobile developers, you guys don't have to understand what React.js or Vue.js or DOM is. + +## Demos + +* Complex LuaViewSDK-rendered native pages + + + +* Simple games + + ![](https://gw.alicdn.com/tfs/TB1rKx2QpXXXXbVapXXXXXXXXXX-340-603.gif) + +## Try Playground App + +- iOS download + + [View in App Store](https://itunes.apple.com/cn/app/luaviewplayground/id1216114838?mt=8) + + ![](https://gw.alicdn.com/tfs/TB1aFkkQpXXXXcBXFXXXXXXXXXX-280-280.png) + +- Android download + + ![img](https://alibaba.github.io/LuaViewSDK/guide/doc/playground_android.png) + +## How to use LuaViewSDK + +- [User Guide](https://alibaba.github.io/LuaViewSDK/guide.html) +- [API manual](https://alibaba.github.io/LuaViewSDK/apimenu.html) + +## Developers + +- [Xicheng Dong](xicheng.dxc@alibaba-inc.com) +- [Songtao Chen](songtao.cst@alibaba-inc.com) + +## License + +[MIT](https://github.com/alibaba/LuaViewSDK/blob/master/LICENSE.txt) + +## Communities + +[Github Wiki](https://github.com/alibaba/LuaViewSDK/wiki) + +QQ group:539262083 + +Twitter:[@luaview](https://twitter.com/luaview) + +## Who we are + +We are from Tmall tech team. LuaViewSDK has been widely used in Taobao app, Tmall app and Juhuasuan App nearly two years. And DAU of pages that are developed by LuaViewSDK is over 10 million. + +--- + +# 欢迎来到LuaViewSDK + +LuaViewSDK是一个跨iOS和Android平台的界面动态化解决方案,使用同一套Lua脚本在iOS和Android平台构建原生页面,同时兼具了H5的灵活性和Native的高性能 + +## 为什么选择Lua? + +- Lua是一个高效灵活的语言,在iOS上单个Lua虚拟机仅占用200k到300k +- Lua已经被广泛应用于对于性能要求和灵活性要求都非常高的场合,比如游戏 +- Lua可以非常方便的绑定各类底层库 +- Lua的API对于native开发人员来说非常自然,不用再去理解各类前端开发概念 + +## Demo + +* LuaViewSDK渲染的Native的复杂业务页面 + + + +* 小游戏 + + ![](https://gw.alicdn.com/tfs/TB1rKx2QpXXXXbVapXXXXXXXXXX-340-603.gif) + +## 试用Playground App + +- iOS download + + [在App Store中查看](https://itunes.apple.com/cn/app/luaviewplayground/id1216114838?mt=8) + + ![](https://gw.alicdn.com/tfs/TB1aFkkQpXXXXcBXFXXXXXXXXXX-280-280.png) + +- Android download + + ![img](https://alibaba.github.io/LuaViewSDK/guide/doc/playground_android.png) + +## 如何使用LuaViewSDK + +- [使用说明](https://alibaba.github.io/LuaViewSDK/guide.html) +- [接口文档](https://alibaba.github.io/LuaViewSDK/apimenu.html) + +## 开发者 + +- [董希成](xicheng.dxc@alibaba-inc.com) +- [陈松涛](songtao.cst@alibaba-inc.com) + +## 许可证 + +[MIT](https://github.com/alibaba/LuaViewSDK/blob/master/LICENSE.txt) + +## 社区 + +[Github Wiki](https://github.com/alibaba/LuaViewSDK/wiki) + +QQ群:539262083 + +Twitter:[@luaview](https://twitter.com/luaview) \ No newline at end of file diff --git a/demo.txt b/demo.txt deleted file mode 100644 index 69ec23d1..00000000 --- a/demo.txt +++ /dev/null @@ -1 +0,0 @@ -ddd \ No newline at end of file diff --git a/guide/build_luaviewapp.md b/guide/build_luaviewapp.md new file mode 100644 index 00000000..a21c3aa2 --- /dev/null +++ b/guide/build_luaviewapp.md @@ -0,0 +1,278 @@ +# 构建你的第一个LuaView应用 +## 1 从GitHub克隆最新版本的LuaViewSDK到本地。 +- github网址: https://github.com/alibaba/LuaViewSDK +- https方式:git clone https://github.com/alibaba/LuaViewSDK.git +- ssh方式:git clone git@github.com:alibaba/LuaViewSDK.git + +## 2 Android工程搭建 +### 2.1 打开Android Studio新建一个Android工程 +### 2.2 在工程里添加LuaView的依赖 + +(1)通过 File -> New -> Import Module,选择克隆到本地的LuaViewSDK目录下的Android/LuaView子目录。 + +(2)在项目中的build.gradle文件中添加LuaView的依赖 + + dependencies { + ..... + compile project(':LuaView') + } + +### 2.3 继承自LuaViewBasicActivity +把应用的Launch Activity改成继承自LuaViewBasicActivity。默认Lua业务代码的主入口是LuaView包里的assets/kit/main.lua,默认入口主页面是App.lua,开发者可以更改这两个设置。 + + +```java +public class MyActivity extends LuaViewBasicActivity { + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + } + + /** + * 开发者可以在这里更改入口主页面, 默认是App.lua + * @return + */ + @Override + public String getMainPage() { + return "App"; + } + + /** + * 开发者可以在这里更改Lua代码的主入口 + * 默认使用kit包下的main.lua + * 该包提供了一套界面描述和业务逻辑分离的机制 + * @return + */ + @Override + public String getLuaViewEntry() { + return "kit/main.lua"; + } + } +``` + +## 3 iOS工程搭建 +### 3.1 打开Xcode新建一个iOS工程 +### 3.2 在工程里添加相关依赖 +新建podfile文件 +在podfile文件里面添加 + +```objectivec + pod 'LuaViewSDK' +``` +执行 `pod install` +### 3.3 添加相关依赖代码 +新建XXLuaViewController 作为容器 +```objectivec +#import +#import "LViewController.h" + +@interface MyLuaViewController : LViewController + +@end +``` + +在AppDelegate中设MyLuaViewController 为rootViewController,同时载入首页脚本 + +```objectivec +@implementation AppDelegate + +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; + self.window.backgroundColor = [UIColor whiteColor]; + + MyLuaViewController* controller = [[MyLuaViewController alloc] initWithPackage:[[NSBundle mainBundle] resourcePath] mainScript:@"kit/main.lua"]; + NSString* entry = @"Playground"; + controller.args = (NSDictionary*)entry; + + self.window.rootViewController = [[UINavigationController alloc] + initWithRootViewController:controller]; + [self.window makeKeyAndVisible]; + + return YES; +} +``` +添加页面跳转的Bridge接口 +```objectivec +- (void)didCreateLuaView:(LView *)view { + [super didCreateLuaView:view]; + self.lv[@"Bridge"] = self; +} + +-(void)require:(NSDictionary*)args { + JHSLuaViewController* c = [[JHSLuaViewController alloc] initWithPackage:nil mainScript:@"kit/main.lua"]; + c.args = args; + [self.navigationController pushViewController:c animated:YES]; +} +``` +## 4 Lua业务代码 +### 4.1 关于Lua业务代码的主入口kit/main.lua +kit包提供了一种基于XML的布局机制,分离出界面描述和业务逻辑,使得业务代码可以写得更加优雅。其中,pica.lua是一个负责解析XML标签、创建控件对象、设置控件属性,以及最终布局和渲染视图的单例类。每个虚拟机仅需创建一个这个实例。 +### 4.2 如何实现一个页面 +在工程的assets目录下创建App.lua文件,Lua页面的写法如下: +```lua +local meta = object:new() + +function meta:onCreate() + self.views = pica:getInstance():render("app.xml") +end + +return meta +``` +onCreate()方法会在页面初始化的时候被调用。`pica:getInstance():render("app.xml")`,会返回XML文件中所有带有id的UI对象,开发者可以以字典的方式取得自己所关注的对象用于操作视图。 + +### 4.3 实现app.xml布局文件 +同样地在assets目录下,创建app.xml文件,XML文件的写法如下: +```xml + + + +``` +在XML中,支持两种布局方式,一种是frame布局,也就是绝对布局。另一种是flex布局,使用Facebook的csslayout布局。到此为止,运行工程就可以看到LuaView的Hello World了。 + +![Hello World](https://gw.alicdn.com/tfs/TB1_8mWQpXXXXa9aXXXXXXXXXXX-738-1306.png =369x653) + +## 5 列表示例 +完成了LuaView的Hello World示例,我们再来编写一个展示如何在LuaView中使用列表的例子。这个例子会从豆瓣的开放API获取正在热映的20部电影,并在一个列表中显示出来。我们先只展现一部电影的缩略图、片名、演职员信息以及评分和看过的人数。修改app.xml,如下: +```xml + + + + + + + + + + + +``` +这个时候我们需要mock数据来填充视图,在App.lua中修改如下: +```lua +local meta = object:new() + +function meta:onCreate() + self.views = pica:getInstance():render("app.xml") + + self.views["profile"]:backgroundColor(0x666666) + self.views["movieName"]:text("电影名称") + self.views["score"]:text("评分: 8") + local director = "导演: 某某某" + local actors = "主演: 某某A/某某B" + self.views["character"]:text(director .. "\n" .. actors) + self.views["number"]:text("1900人看过") +end + +return meta +``` +在这段代码中,我们根据app.xml中的id可以取出关注的对象进行属性的设置。再次运行程序,可以看到屏幕发生了变化。 + +![Item](https://gw.alicdn.com/tfs/TB1i7fnQpXXXXXkXFXXXXXXXXXX-734-1300.png =369x653) + +接下来我们从豆瓣的开放API抓取真实的数据用来展示: +```lua +local meta = object:new() + +function meta:onCreate() + self.views = pica:getInstance():render("app.xml") + + Http():get("http://api.douban.com/v2/movie/in_theaters?apikey=0df993c66c0c636e29ecbb5344252a4a", function(response) + if (tostring(response:code()) == "200") then + local _jsonData = Json:toTable(tostring(response:data())) + self.views["profile"]:image(_jsonData["subjects"][1]["images"]["large"]) + self.views["movieName"]:text(_jsonData["subjects"][1]["title"]) + self.views["score"]:text("评分: " .. _jsonData["subjects"][1]["rating"]["average"]) + + local director = "导演: " .. _jsonData["subjects"][1]["directors"][1]["name"] + local actors = "主演: " + for _k, _v in pairs(_jsonData["subjects"][1]["casts"]) do + actors = actors .. _v["name"] .. "/" + end + self.views["character"]:text(director .. "\n" .. actors) + + self.views["number"]:text(_jsonData["subjects"][1]["collect_count"] .. "人看过") + else + Toast("Request Error") + end + end) +end + +return meta +``` +目前为止,只是展示一部电影的信息,为了渲染更多的条目,我们需要List组件。另外由于网络请求的不稳定性和耗时性,我们需要Load加载组件。在assets目录下新增一个list.xml文件如下: +```xml + + + + +``` +相应地,App.lua也要做出更改: +```lua +local meta = object:new() + +function meta:onCreate() + self.views = pica:getInstance():render("list.xml") + self.loading = self.views["loading"] + self.list = self.views["tableView"] + + self:handle() +end + +function meta:handle() + self.loading:show() + Http():get("http://api.douban.com/v2/movie/in_theaters?apikey=0df993c66c0c636e29ecbb5344252a4a", function(response) + self.loading:hide() + if (tostring(response:code()) == "200") then + local _jsonData = Json:toTable(tostring(response:data())) + self.list:initParams({ + Section = { + SectionCount = function() + return 1 + end, + RowCount = function(section) + return _jsonData["count"] + end + }, + Cell = { + Id = function(section, row) + return "ItemCell" + end, + ItemCell = { + Size = function(section, row) + return sys.contW, sys.contH/3 + end, + Init = function(cell, section, row) + cell.objs = pica:getInstance():render("app.xml") + end, + Layout = function(cell, section, row) + cell.objs["profile"]:image(_jsonData["subjects"][row]["images"]["large"]) + cell.objs["movieName"]:text(_jsonData["subjects"][row]["title"]) + cell.objs["score"]:text("评分: " .. _jsonData["subjects"][row]["rating"]["average"]) + + local director = "导演: " .. _jsonData["subjects"][row]["directors"][1]["name"] + local actors = "主演: " + for _k, _v in pairs(_jsonData["subjects"][row]["casts"]) do + actors = actors .. _v["name"] .. "/" + end + cell.objs["character"]:text(director .. "\n" .. actors) + + cell.objs["number"]:text(_jsonData["subjects"][row]["collect_count"] .. "人看过") + end + } + } + }) + + self.list:reload() + else + Toast("Request Error") + end + end) +end + +return meta +``` +代码的关键是要往List中设置数据源,并且重新reload列表。关于List的更多用法可以查看API文档,。此时,再次运行程序,可以看到界面生成了一个完整的电影列表。 + +![List](https://gw.alicdn.com/tfs/TB1GL6vQpXXXXa9XpXXXXXXXXXX-728-1296.png =369x653) + + +恭喜你完成了第一个LuaView应用,接下来开启你的LuaView之旅吧。 diff --git a/liblua.podspec b/liblua.podspec new file mode 100644 index 00000000..082247f4 --- /dev/null +++ b/liblua.podspec @@ -0,0 +1,65 @@ + +Pod::Spec.new do |s| + + s.name = "liblua" + s.version = "5.1.4" + s.summary = "liblua" + + s.description = <<-DESC + A longer description of liblua.podspec in Markdown format. + * LuaView + DESC + + s.homepage = "http://gitlab.alibaba-inc.com/luaview/luaviewsdk" + + + s.license = { :type => 'GNU General Public Licence (GPL), Version 2.0', :file => 'LICENSE.txt' } + + s.author = { "城西" => "xicheng.dxc@alibaba-inc.com" } + + # ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― # + # + # If this Pod runs only on iOS or OS X, then specify the platform and + # the deployment target. You can optionally include the target after the platform. + # + + s.platform = :ios, "7.0" + + s.source = { :git => "https://github.com/alibaba/LuaViewSDK.git", :tag => "0.5.0" } + + s.source_files = "IOS/lua/lua/*.{h,m,c}" + # s.exclude_files = "Classes/Exclude" + + + # ――― Resources ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # + # + # A list of resources included with the Pod. These are copied into the + # target bundle with a build phase script. Anything else will be cleaned. + # You can preserve files from being cleaned, please don't preserve + # non-essential files like tests, examples and documentation. + # + + # s.resource = "icon.png" + # s.resources = "Resources/*.png" + + # s.preserve_paths = "FilesToSave", "MoreFilesToSave" + + + # ――― Project Linking ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # + # + # Link your library with frameworks, or libraries. Libraries do not include + # the lib prefix of their name. + # + + s.frameworks = 'Foundation', 'UIKit', 'CoreGraphics' + s.libraries = 'z' + + # ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # + # + # If your library depends on compiler flags you can set them in the xcconfig hash + # where they will only apply to your library. If you depend on other Podspecs + # you can include multiple dependencies to ensure it works. + + s.requires_arc = true + +end