blob: 023ddaeaca51489fd0b93e3841a3e47355df992f [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
14extern "C" {
15 #include "lua.h"
16 #include "lualib.h"
17 #include "lauxlib.h"
18}
19
20static SkData* read_into_data(const char file[]) {
reed9594da12014-09-12 12:12:27 -070021 SkData* data = SkData::NewFromFileName(file);
22 if (!data) {
23 data = SkData::NewEmpty();
mike@reedtribe.org73d9f1c2013-06-09 01:54:56 +000024 }
reed9594da12014-09-12 12:12:27 -070025 return data;
mike@reedtribe.org73d9f1c2013-06-09 01:54:56 +000026}
27
28int tool_main(int argc, char** argv);
29int tool_main(int argc, char** argv) {
30 SkAutoGraphics ag;
31 SkLua L;
32
33 for (int i = 1; i < argc; ++i) {
34 SkData* data = NULL;
35 const void* ptr;
36 size_t len;
37
38 if (!strcmp(argv[i], "--lua") && i < argc-1) {
39 ptr = argv[i + 1];
40 len = strlen(argv[i + 1]);
41 i += 1;
42 } else {
43 data = read_into_data(argv[i]);
44 ptr = data->data();
45 len = data->size();
46 }
47 if (!L.runCode(ptr, len)) {
48 SkDebugf("failed to load %s\n", argv[i]);
49 exit(-1);
50 }
51 SkSafeUnref(data);
52 }
53 return 0;
54}
55
56#if !defined SK_BUILD_FOR_IOS
57int main(int argc, char * const argv[]) {
58 return tool_main(argc, (char**) argv);
59}
60#endif