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

Unified Diff: samplecode/SampleLua.cpp

Issue 652473002: add key handlers to lua (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/slides.lua ('k') | src/utils/SkLua.cpp » ('j') | 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 917930a67873e57476833faf01ebd52c8d75fc51..e7af727ab5b7b63e30870eeb347878fee5de286b 100644
--- a/samplecode/SampleLua.cpp
+++ b/samplecode/SampleLua.cpp
@@ -23,6 +23,7 @@ extern "C" {
static const char gDrawName[] = "onDrawContent";
static const char gClickName[] = "onClickHandler";
+static const char gUnicharName[] = "onCharHandler";
static const char gMissingCode[] = ""
"local paint = Sk.newPaint()"
@@ -79,6 +80,21 @@ protected:
}
SkUnichar uni;
if (SampleCode::CharQ(*evt, &uni)) {
+ lua_State* L = this->ensureLua();
+ lua_getglobal(L, gUnicharName);
+ if (lua_isfunction(L, -1)) {
+ SkString str;
+ str.appendUnichar(uni);
+ fLua->pushString(str.c_str());
+ 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);
+ return true;
+ }
+ }
+ }
}
return this->INHERITED::onQuery(evt);
}
« no previous file with comments | « resources/slides.lua ('k') | src/utils/SkLua.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698