mike@reedtribe.org | 73d9f1c | 2013-06-09 01:54:56 +0000 | [diff] [blame] | 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #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.org | 73d9f1c | 2013-06-09 01:54:56 +0000 | [diff] [blame] | 13 | |
bungeman | 60e0fee | 2015-08-26 05:15:46 -0700 | [diff] [blame] | 14 | #include <stdlib.h> |
| 15 | |
mike@reedtribe.org | 73d9f1c | 2013-06-09 01:54:56 +0000 | [diff] [blame] | 16 | extern "C" { |
| 17 | #include "lua.h" |
| 18 | #include "lualib.h" |
| 19 | #include "lauxlib.h" |
| 20 | } |
| 21 | |
bungeman | 38d909e | 2016-08-02 14:40:46 -0700 | [diff] [blame] | 22 | static sk_sp<SkData> read_into_data(const char file[]) { |
| 23 | sk_sp<SkData> data(SkData::MakeFromFileName(file)); |
reed | 9594da1 | 2014-09-12 12:12:27 -0700 | [diff] [blame] | 24 | if (!data) { |
bungeman | 38d909e | 2016-08-02 14:40:46 -0700 | [diff] [blame] | 25 | data = SkData::MakeEmpty(); |
mike@reedtribe.org | 73d9f1c | 2013-06-09 01:54:56 +0000 | [diff] [blame] | 26 | } |
reed | 9594da1 | 2014-09-12 12:12:27 -0700 | [diff] [blame] | 27 | return data; |
mike@reedtribe.org | 73d9f1c | 2013-06-09 01:54:56 +0000 | [diff] [blame] | 28 | } |
| 29 | |
Mike Klein | be28ee2 | 2017-02-06 12:46:20 -0500 | [diff] [blame] | 30 | int main(int argc, char** argv) { |
mike@reedtribe.org | 73d9f1c | 2013-06-09 01:54:56 +0000 | [diff] [blame] | 31 | SkAutoGraphics ag; |
| 32 | SkLua L; |
| 33 | |
| 34 | for (int i = 1; i < argc; ++i) { |
bungeman | 38d909e | 2016-08-02 14:40:46 -0700 | [diff] [blame] | 35 | sk_sp<SkData> data; |
mike@reedtribe.org | 73d9f1c | 2013-06-09 01:54:56 +0000 | [diff] [blame] | 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 | } |
mike@reedtribe.org | 73d9f1c | 2013-06-09 01:54:56 +0000 | [diff] [blame] | 52 | } |
| 53 | return 0; |
| 54 | } |