blob: 0c1723e4e8d18ae2c3754fbc5aa5a90b6b72f225 [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "include/core/SkData.h"
9#include "include/core/SkGraphics.h"
10#include "include/core/SkStream.h"
11#include "include/utils/SkLua.h"
12#include "src/core/SkOSFile.h"
mike@reedtribe.org73d9f1c2013-06-09 01:54:56 +000013
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
bungeman38d909e2016-08-02 14:40:46 -070022static sk_sp<SkData> read_into_data(const char file[]) {
23 sk_sp<SkData> data(SkData::MakeFromFileName(file));
reed9594da12014-09-12 12:12:27 -070024 if (!data) {
bungeman38d909e2016-08-02 14:40:46 -070025 data = SkData::MakeEmpty();
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
Mike Kleinbe28ee22017-02-06 12:46:20 -050030int main(int argc, char** argv) {
mike@reedtribe.org73d9f1c2013-06-09 01:54:56 +000031 SkAutoGraphics ag;
32 SkLua L;
33
34 for (int i = 1; i < argc; ++i) {
bungeman38d909e2016-08-02 14:40:46 -070035 sk_sp<SkData> data;
mike@reedtribe.org73d9f1c2013-06-09 01:54:56 +000036 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 }
mike@reedtribe.org73d9f1c2013-06-09 01:54:56 +000052 }
53 return 0;
54}