Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1388)

Unified Diff: samplecode/SampleLua.cpp

Issue 649013002: allow for lua click handlers (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « resources/test.lua ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: samplecode/SampleLua.cpp
diff --git a/samplecode/SampleLua.cpp b/samplecode/SampleLua.cpp
index 8e0eaf703d600f9b953e85d9938eda092506b900..917930a67873e57476833faf01ebd52c8d75fc51 100644
--- a/samplecode/SampleLua.cpp
+++ b/samplecode/SampleLua.cpp
@@ -18,7 +18,11 @@ extern "C" {
#include "lauxlib.h"
}
+#define LUA_FILENAME "test.lua"
+//#define LUA_FILENAME "slides.lua"
+
static const char gDrawName[] = "onDrawContent";
+static const char gClickName[] = "onClickHandler";
static const char gMissingCode[] = ""
"local paint = Sk.newPaint()"
@@ -54,7 +58,7 @@ public:
if (NULL == fLua) {
fLua = SkNEW(SkLua);
- SkString str = GetResourcePath("test.lua");
+ SkString str = GetResourcePath(LUA_FILENAME);
SkData* data = SkData::NewFromFileName(str.c_str());
if (data) {
fLua->runCode(data->data(), data->size());
@@ -91,17 +95,31 @@ protected:
// does it make sense to try to "cache" the lua version of this
// canvas between draws?
fLua->pushCanvas(canvas);
- if (lua_pcall(L, 1, 0, 0) != LUA_OK) {
+ if (lua_pcall(L, 1, 1, 0) != LUA_OK) {
SkDebugf("lua err: %s\n", lua_tostring(L, -1));
+ } else {
+ if (lua_isboolean(L, -1) && lua_toboolean(L, -1)) {
+ this->inval(NULL);
+ }
}
}
- // need a way for the lua-sample to tell us if they want animations...
- // hard-code it ON for now.
- this->inval(NULL);
}
virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y,
unsigned modi) SK_OVERRIDE {
+ lua_State* L = this->ensureLua();
+ lua_getglobal(L, gClickName);
+ if (lua_isfunction(L, -1)) {
+ fLua->pushScalar(x);
+ fLua->pushScalar(y);
+ if (lua_pcall(L, 2, 1, 0) != LUA_OK) {
+ SkDebugf("lua err: %s\n", lua_tostring(L, -1));
+ } else {
+ if (lua_isboolean(L, -1) && lua_toboolean(L, -1)) {
+ this->inval(NULL);
+ }
+ }
+ }
return this->INHERITED::onFindClickHandler(x, y, modi);
}
« no previous file with comments | « resources/test.lua ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698