• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2013 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #include "SkLua.h"
9 #include "SkGraphics.h"
10 #include "SkStream.h"
11 #include "SkData.h"
12 #include "SkOSFile.h"
13 
14 #include <stdlib.h>
15 
16 extern "C" {
17     #include "lua.h"
18     #include "lualib.h"
19     #include "lauxlib.h"
20 }
21 
read_into_data(const char file[])22 static sk_sp<SkData> read_into_data(const char file[]) {
23     sk_sp<SkData> data(SkData::MakeFromFileName(file));
24     if (!data) {
25         data = SkData::MakeEmpty();
26     }
27     return data;
28 }
29 
main(int argc,char ** argv)30 int main(int argc, char** argv) {
31     SkAutoGraphics ag;
32     SkLua L;
33 
34     for (int i = 1; i < argc; ++i) {
35         sk_sp<SkData> data;
36         const void* ptr;
37         size_t len;
38 
39         if (!strcmp(argv[i], "--lua") && i < argc-1) {
40             ptr = argv[i + 1];
41             len = strlen(argv[i + 1]);
42             i += 1;
43         } else {
44             data = read_into_data(argv[i]);
45             ptr = data->data();
46             len = data->size();
47         }
48         if (!L.runCode(ptr, len)) {
49             SkDebugf("failed to load %s\n", argv[i]);
50             exit(-1);
51         }
52     }
53     return 0;
54 }
55