lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


hi,
you can use bin2c.lua script file
then convert the lua code into c Code and #include that in your code
the syntax for convert the lua code into c Code is:
lua bin2c.lua script.lua > header.h

۱۳۹۴-۰۱-۰۴ ۲۰:۵۶ GMT+۰۴:۳۰, Bulat Ziganshin <bulat.ziganshin@gmail.com>:
> 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:
>
> const char* startup_code = R"fsdfw43r4(
>   my Lua code...
> )fsdfw43r4";
>
> Now   i'm   trying  to get rid of those extra files (converter.lua and
> converted-startup.cpp)   and  include Startup.lua contents directly to
> C++ code. My first attempt failed:
>
> const char* startup_code = R"fsdfw43r4(
>   #include "Startup.lua"
> )fsdfw43r4";
>
> (preprocessor isn't fired inside string constants)
>
> So  now  i'm  thinking  about  the  ways to hide a bit of C++ code in
> Startup.lua file, sort of:
>
> -- const char* startup_code = R"fsdfw43r4(
> my Lua code...
> -- )fsdfw43r4";
>
> The last line is fine, but i can't find the way to deal with the first
> one (i.e. write some code ignored by the Lua interpreter and equivalent to
>
> const char* startup_code = R"fsdfw43r4(
>
> for C++ compiler). Any ideas?
>
>
> 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?
>
> --
> Best regards,
>  Bulat                          mailto:Bulat.Ziganshin@gmail.com
>
>
>

Attachment: bin2c.lua
Description: Binary data