[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: #including foo.lua file directly into C++11 code
- From: Sean Conner <sean@...>
- Date: Tue, 24 Mar 2015 13:57:37 -0400
It was thus said that the Great Bulat Ziganshin once stated:
> Hello Lua,
>
> Note: i found solution and described it at the end of message
>
> I have 200-line Lua script included in C++ code. In order to use Lua
> syntax higlightning, I placed this script into file Startup.lua and
> wrote a trivial script that converts it to the C++ code like that:
[ snip ]
> PS: on the second thought, i resolved it into the C++ code:
>
> LuaInstance() {int a=0;
> #include "Startup.lua"
> }
> const char* startup_code;
>
> with corresponding Lua code:
>
> --a; startup_code = R"fsdfw43r4(
> ..............
> -- )fsdfw43r4";
>
> Do you have better ideas? Should i publish this trick on Lua wiki
> and what is the best place?
You gave no indication of the operating system or compiler you are using.
I can describe what I do, but that's under Linux.
I use the GNU compiler chain. In my Makefile, I have an implicit rule to
compile Lua files into object files (warning: uses GNU features):
%.o : %.lua
$(BIN2C) -o $(@D)/$(*F).c -t $(*F) $<
$(CC) $(CFLAGS) -c -o $@ $(@D)/$(*F).c
$(RM) $(@D)/$(*F).c
This generates a .o file directly from a .lua file (and removes the
temporary .c file since it's not needed anymore). It works for me. Your
milage may vary.
-spc