2 * Copyright (c) 2012 Igor Khomyakov. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
7 * 1) Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
9 * 2) Redistributions of source code with modification must include a notice
10 * that the code was modified.
11 * 3) Neither the names of the authors nor the names of their contributors may
12 * be used to endorse or promote products derived from this software without
13 * specific prior written permission.
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
34 #define WRITE_BATCH 50
35 #define WRITE_BEG "[=====["
36 #define WRITE_END "]=====]"
38 void convert(FILE* fi
, FILE* fo
) {
41 fprintf(fo
,"io.write(%s",WRITE_BEG
);
46 fprintf(stderr
,"stdin error: %d\n", errno
);
49 } else if (c
== '\n') {
51 if (lineno
% WRITE_BATCH
== 0) {
52 fprintf(fo
,"%s)\nio.write(%s",WRITE_END
,WRITE_BEG
);
59 fprintf(fo
,"%s)\n",WRITE_END
);
63 int main(int argc
, char* argv
[]) {
64 lua_State
*L
= luaL_newstate();
66 if (luaL_dofile(L
,"config.lua")!=0) {
67 fprintf(stderr
,"%s\n",lua_tostring(L
,-1));
71 convert(stdin
,stdout
);