OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SampleCode.h" | 8 #include "SampleCode.h" |
9 #include "SkView.h" | 9 #include "SkView.h" |
10 #include "SkLua.h" | 10 #include "SkLua.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 SkDebugf("lua err: %s\n", lua_tostring(L, -1)); | 53 SkDebugf("lua err: %s\n", lua_tostring(L, -1)); |
54 } | 54 } |
55 } | 55 } |
56 } | 56 } |
57 | 57 |
58 lua_State* ensureLua() { | 58 lua_State* ensureLua() { |
59 if (nullptr == fLua) { | 59 if (nullptr == fLua) { |
60 fLua = new SkLua; | 60 fLua = new SkLua; |
61 | 61 |
62 SkString str = GetResourcePath(LUA_FILENAME); | 62 SkString str = GetResourcePath(LUA_FILENAME); |
63 SkData* data = SkData::NewFromFileName(str.c_str()); | 63 sk_sp<SkData> data(SkData::MakeFromFileName(str.c_str())); |
64 if (data) { | 64 if (data) { |
65 fLua->runCode(data->data(), data->size()); | 65 fLua->runCode(data->data(), data->size()); |
66 data->unref(); | |
67 this->setImageFilename(fLua->get()); | 66 this->setImageFilename(fLua->get()); |
68 } else { | 67 } else { |
69 fLua->runCode(gMissingCode); | 68 fLua->runCode(gMissingCode); |
70 } | 69 } |
71 } | 70 } |
72 return fLua->get(); | 71 return fLua->get(); |
73 } | 72 } |
74 | 73 |
75 protected: | 74 protected: |
76 bool onQuery(SkEvent* evt) override { | 75 bool onQuery(SkEvent* evt) override { |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 private: | 176 private: |
178 SkLua* fLua; | 177 SkLua* fLua; |
179 | 178 |
180 typedef SampleView INHERITED; | 179 typedef SampleView INHERITED; |
181 }; | 180 }; |
182 | 181 |
183 ////////////////////////////////////////////////////////////////////////////// | 182 ////////////////////////////////////////////////////////////////////////////// |
184 | 183 |
185 static SkView* MyFactory() { return new LuaView; } | 184 static SkView* MyFactory() { return new LuaView; } |
186 static SkViewRegister reg(MyFactory); | 185 static SkViewRegister reg(MyFactory); |
OLD | NEW |