expand SkLua to handle creation of its own State

add lua sample

BUG=
R=robertphillips@google.com

Review URL: https://codereview.chromium.org/15742009

git-svn-id: http://skia.googlecode.com/svn/trunk@9247 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/include/utils/SkLua.h b/include/utils/SkLua.h
index 232ba9b..8f48bc1 100644
--- a/include/utils/SkLua.h
+++ b/include/utils/SkLua.h
@@ -10,6 +10,7 @@
 
 #include "SkColor.h"
 #include "SkScalar.h"
+#include "SkString.h"
 
 struct lua_State;
 
@@ -19,7 +20,6 @@
 class SkPath;
 struct SkRect;
 class SkRRect;
-class SkString;
 
 #define SkScalarToLua(x)    SkScalarToDouble(x)
 #define SkLuaToScalar(x)    SkDoubleToScalar(x)
@@ -28,11 +28,17 @@
 public:
     static void Load(lua_State*);
 
-    SkLua(lua_State*);
+    SkLua(const char termCode[] = NULL);    // creates a new L, will close it
+    SkLua(lua_State*);                      // uses L, will not close it
     ~SkLua();
 
-    lua_State* getL() const { return fL; }
-
+    lua_State* get() const { return fL; }
+    lua_State* operator*() const { return fL; }
+    lua_State* operator->() const { return fL; }
+    
+    bool runCode(const char code[]);
+    bool runCode(const void* code, size_t size);
+    
     void pushBool(bool, const char tableKey[] = NULL);
     void pushString(const char[], const char tableKey[] = NULL);
     void pushString(const SkString&, const char tableKey[] = NULL);
@@ -46,7 +52,9 @@
     void pushCanvas(SkCanvas*, const char tableKey[] = NULL);
 
 private:
-    lua_State* fL;
+    lua_State*  fL;
+    SkString    fTermCode;
+    bool        fWeOwnL;
 };
 
 #endif