diff options
author | reed <reed@chromium.org> | 2014-10-11 13:13:11 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-10-11 13:13:11 -0700 |
commit | 09a1d6751c5c7c09d72ff8e195148509d2cb87ce (patch) | |
tree | d7ad0962f3bc243a9f99058fb19cf6d4b8b2d7cf /samplecode/SampleLua.cpp | |
parent | 18ea777638f1494b068ba4ca1a5d6725a0e80cf1 (diff) |
add key handlers to lua
BUG=skia:
TBR=
Review URL: https://codereview.chromium.org/652473002
Diffstat (limited to 'samplecode/SampleLua.cpp')
-rw-r--r-- | samplecode/SampleLua.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/samplecode/SampleLua.cpp b/samplecode/SampleLua.cpp index 917930a678..e7af727ab5 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); } |