blob: 6aea8ee43776a65aad26e7f227ab7b2814dfc86f [file] [log] [blame]
mike@reedtribe.org73d9f1c2013-06-09 01:54:56 +00001/*
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
bungeman60e0fee2015-08-26 05:15:46 -070014#include <stdlib.h>
15
mike@reedtribe.org73d9f1c2013-06-09 01:54:56 +000016extern "C" {
17 #include "lua.h"
18 #include "lualib.h"
19 #include "lauxlib.h"
20}
21
22static SkData* read_into_data(const char file[]) {
reed9594da12014-09-12 12:12:27 -070023 SkData* data = SkData::NewFromFileName(file);
24 if (!data) {
25 data = SkData::NewEmpty();
mike@reedtribe.org73d9f1c2013-06-09 01:54:56 +000026 }
reed9594da12014-09-12 12:12:27 -070027 return data;
mike@reedtribe.org73d9f1c2013-06-09 01:54:56 +000028}
29
30int tool_main(int argc, char** argv);
31int tool_main(int argc, char** argv) {
32 SkAutoGraphics ag;
33 SkLua L;
34
35 for (int i = 1; i < argc; ++i) {
halcanary96fcdcc2015-08-27 07:41:13 -070036 SkData* data = nullptr;
mike@reedtribe.org73d9f1c2013-06-09 01:54:56 +000037 const void* ptr;
38 size_t len;
39
40 if (!strcmp(argv[i], "--lua") && i < argc-1) {
41 ptr = argv[i + 1];
42 len = strlen(argv[i + 1]);
43 i += 1;
44 } else {
45 data = read_into_data(argv[i]);
46 ptr = data->data();
47 len = data->size();
48 }
49 if (!L.runCode(ptr, len)) {
50 SkDebugf("failed to load %s\n", argv[i]);
51 exit(-1);
52 }
53 SkSafeUnref(data);
54 }
55 return 0;
56}
57
58#if !defined SK_BUILD_FOR_IOS
59int main(int argc, char * const argv[]) {
60 return tool_main(argc, (char**) argv);
61}
62#endif