mirror of
https://github.com/love2d/love.git
synced 2026-08-21 13:09:56 +02:00
Rewrite auto.lua
Biggest advantages being automatic header+footer generation, minimal code verification and smaller diffs (from now on)
This commit is contained in:
+89
-30
@@ -24,35 +24,94 @@ namespace love
|
||||
// [audio.lua]
|
||||
const unsigned char audio_lua[] =
|
||||
{
|
||||
0x66,0x75,0x6E,0x63,0x74,0x69,0x6F,0x6E,0x20,0x6C,0x6F,0x76,0x65,0x2E,0x61,
|
||||
0x75,0x64,0x69,0x6F,0x2E,0x6E,0x65,0x77,0x53,0x6F,0x75,0x72,0x63,0x65,0x28,
|
||||
0x61,0x2C,0x20,0x62,0x29,0x20,0x69,0x66,0x20,0x74,0x79,0x70,0x65,0x28,0x61,
|
||||
0x29,0x20,0x3D,0x3D,0x20,0x22,0x73,0x74,0x72,0x69,0x6E,0x67,0x22,0x20,0x74,
|
||||
0x68,0x65,0x6E,0x20,0x61,0x20,0x3D,0x20,0x6C,0x6F,0x76,0x65,0x2E,0x66,0x69,
|
||||
0x6C,0x65,0x73,0x79,0x73,0x74,0x65,0x6D,0x2E,0x6E,0x65,0x77,0x46,0x69,0x6C,
|
||||
0x65,0x28,0x61,0x29,0x20,0x65,0x6E,0x64,0x20,0x69,0x66,0x20,0x74,0x79,0x70,
|
||||
0x65,0x28,0x61,0x29,0x20,0x3D,0x3D,0x20,0x22,0x75,0x73,0x65,0x72,0x64,0x61,
|
||||
0x74,0x61,0x22,0x20,0x74,0x68,0x65,0x6E,0x20,0x69,0x66,0x20,0x61,0x3A,0x74,
|
||||
0x79,0x70,0x65,0x4F,0x66,0x28,0x22,0x46,0x69,0x6C,0x65,0x22,0x29,0x20,0x74,
|
||||
0x68,0x65,0x6E,0x20,0x61,0x20,0x3D,0x20,0x6C,0x6F,0x76,0x65,0x2E,0x73,0x6F,
|
||||
0x75,0x6E,0x64,0x2E,0x6E,0x65,0x77,0x44,0x65,0x63,0x6F,0x64,0x65,0x72,0x28,
|
||||
0x61,0x29,0x20,0x65,0x6E,0x64,0x20,0x69,0x66,0x20,0x61,0x3A,0x74,0x79,0x70,
|
||||
0x65,0x4F,0x66,0x28,0x22,0x44,0x65,0x63,0x6F,0x64,0x65,0x72,0x22,0x29,0x20,
|
||||
0x74,0x68,0x65,0x6E,0x20,0x69,0x66,0x20,0x62,0x20,0x3D,0x3D,0x20,0x22,0x73,
|
||||
0x74,0x61,0x74,0x69,0x63,0x22,0x20,0x74,0x68,0x65,0x6E,0x20,0x61,0x20,0x3D,
|
||||
0x20,0x6C,0x6F,0x76,0x65,0x2E,0x73,0x6F,0x75,0x6E,0x64,0x2E,0x6E,0x65,0x77,
|
||||
0x53,0x6F,0x75,0x6E,0x64,0x44,0x61,0x74,0x61,0x28,0x61,0x29,0x20,0x65,0x6E,
|
||||
0x64,0x20,0x72,0x65,0x74,0x75,0x72,0x6E,0x20,0x6C,0x6F,0x76,0x65,0x2E,0x61,
|
||||
0x75,0x64,0x69,0x6F,0x2E,0x6E,0x65,0x77,0x53,0x6F,0x75,0x72,0x63,0x65,0x31,
|
||||
0x28,0x61,0x29,0x20,0x65,0x6E,0x64,0x20,0x69,0x66,0x20,0x61,0x3A,0x74,0x79,
|
||||
0x70,0x65,0x4F,0x66,0x28,0x22,0x53,0x6F,0x75,0x6E,0x64,0x44,0x61,0x74,0x61,
|
||||
0x22,0x29,0x20,0x74,0x68,0x65,0x6E,0x20,0x72,0x65,0x74,0x75,0x72,0x6E,0x20,
|
||||
0x6C,0x6F,0x76,0x65,0x2E,0x61,0x75,0x64,0x69,0x6F,0x2E,0x6E,0x65,0x77,0x53,
|
||||
0x6F,0x75,0x72,0x63,0x65,0x31,0x28,0x61,0x29,0x20,0x65,0x6E,0x64,0x20,0x65,
|
||||
0x6E,0x64,0x20,0x65,0x72,0x72,0x6F,0x72,0x28,0x22,0x4E,0x6F,0x20,0x6D,0x61,
|
||||
0x74,0x63,0x68,0x69,0x6E,0x67,0x20,0x6F,0x76,0x65,0x72,0x6C,0x6F,0x61,0x64,
|
||||
0x22,0x29,0x20,0x65,0x6E,0x64,
|
||||
};
|
||||
// [/audio.lua]
|
||||
|
||||
0x2d, 0x2d, 0x5b, 0x5b, 0x0a,
|
||||
0x43, 0x6f, 0x70, 0x79, 0x72, 0x69, 0x67, 0x68, 0x74, 0x20, 0x28, 0x63, 0x29, 0x20, 0x32, 0x30, 0x30, 0x36,
|
||||
0x2d, 0x32, 0x30, 0x31, 0x31, 0x20, 0x4c, 0x4f, 0x56, 0x45, 0x20, 0x44, 0x65, 0x76, 0x65, 0x6c, 0x6f, 0x70,
|
||||
0x6d, 0x65, 0x6e, 0x74, 0x20, 0x54, 0x65, 0x61, 0x6d, 0x0a,0x0a,
|
||||
0x54, 0x68, 0x69, 0x73, 0x20, 0x73, 0x6f, 0x66, 0x74, 0x77, 0x61, 0x72, 0x65, 0x20, 0x69, 0x73, 0x20, 0x70,
|
||||
0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x64, 0x20, 0x27, 0x61, 0x73, 0x2d, 0x69, 0x73, 0x27, 0x2c, 0x20, 0x77,
|
||||
0x69, 0x74, 0x68, 0x6f, 0x75, 0x74, 0x20, 0x61, 0x6e, 0x79, 0x20, 0x65, 0x78, 0x70, 0x72, 0x65, 0x73, 0x73,
|
||||
0x20, 0x6f, 0x72, 0x20, 0x69, 0x6d, 0x70, 0x6c, 0x69, 0x65, 0x64, 0x0a,
|
||||
0x77, 0x61, 0x72, 0x72, 0x61, 0x6e, 0x74, 0x79, 0x2e, 0x20, 0x20, 0x49, 0x6e, 0x20, 0x6e, 0x6f, 0x20, 0x65,
|
||||
0x76, 0x65, 0x6e, 0x74, 0x20, 0x77, 0x69, 0x6c, 0x6c, 0x20, 0x74, 0x68, 0x65, 0x20, 0x61, 0x75, 0x74, 0x68,
|
||||
0x6f, 0x72, 0x73, 0x20, 0x62, 0x65, 0x20, 0x68, 0x65, 0x6c, 0x64, 0x20, 0x6c, 0x69, 0x61, 0x62, 0x6c, 0x65,
|
||||
0x20, 0x66, 0x6f, 0x72, 0x20, 0x61, 0x6e, 0x79, 0x20, 0x64, 0x61, 0x6d, 0x61, 0x67, 0x65, 0x73, 0x0a,
|
||||
0x61, 0x72, 0x69, 0x73, 0x69, 0x6e, 0x67, 0x20, 0x66, 0x72, 0x6f, 0x6d, 0x20, 0x74, 0x68, 0x65, 0x20, 0x75,
|
||||
0x73, 0x65, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x69, 0x73, 0x20, 0x73, 0x6f, 0x66, 0x74, 0x77, 0x61, 0x72,
|
||||
0x65, 0x2e, 0x0a,0x0a,
|
||||
0x50, 0x65, 0x72, 0x6d, 0x69, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x69, 0x73, 0x20, 0x67, 0x72, 0x61, 0x6e,
|
||||
0x74, 0x65, 0x64, 0x20, 0x74, 0x6f, 0x20, 0x61, 0x6e, 0x79, 0x6f, 0x6e, 0x65, 0x20, 0x74, 0x6f, 0x20, 0x75,
|
||||
0x73, 0x65, 0x20, 0x74, 0x68, 0x69, 0x73, 0x20, 0x73, 0x6f, 0x66, 0x74, 0x77, 0x61, 0x72, 0x65, 0x20, 0x66,
|
||||
0x6f, 0x72, 0x20, 0x61, 0x6e, 0x79, 0x20, 0x70, 0x75, 0x72, 0x70, 0x6f, 0x73, 0x65, 0x2c, 0x0a,
|
||||
0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64, 0x69, 0x6e, 0x67, 0x20, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x72, 0x63, 0x69,
|
||||
0x61, 0x6c, 0x20, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2c, 0x20, 0x61,
|
||||
0x6e, 0x64, 0x20, 0x74, 0x6f, 0x20, 0x61, 0x6c, 0x74, 0x65, 0x72, 0x20, 0x69, 0x74, 0x20, 0x61, 0x6e, 0x64,
|
||||
0x20, 0x72, 0x65, 0x64, 0x69, 0x73, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x20, 0x69, 0x74, 0x0a,
|
||||
0x66, 0x72, 0x65, 0x65, 0x6c, 0x79, 0x2c, 0x20, 0x73, 0x75, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x20, 0x74, 0x6f,
|
||||
0x20, 0x74, 0x68, 0x65, 0x20, 0x66, 0x6f, 0x6c, 0x6c, 0x6f, 0x77, 0x69, 0x6e, 0x67, 0x20, 0x72, 0x65, 0x73,
|
||||
0x74, 0x72, 0x69, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x3a, 0x0a,0x0a,
|
||||
0x31, 0x2e, 0x20, 0x54, 0x68, 0x65, 0x20, 0x6f, 0x72, 0x69, 0x67, 0x69, 0x6e, 0x20, 0x6f, 0x66, 0x20, 0x74,
|
||||
0x68, 0x69, 0x73, 0x20, 0x73, 0x6f, 0x66, 0x74, 0x77, 0x61, 0x72, 0x65, 0x20, 0x6d, 0x75, 0x73, 0x74, 0x20,
|
||||
0x6e, 0x6f, 0x74, 0x20, 0x62, 0x65, 0x20, 0x6d, 0x69, 0x73, 0x72, 0x65, 0x70, 0x72, 0x65, 0x73, 0x65, 0x6e,
|
||||
0x74, 0x65, 0x64, 0x3b, 0x20, 0x79, 0x6f, 0x75, 0x20, 0x6d, 0x75, 0x73, 0x74, 0x20, 0x6e, 0x6f, 0x74, 0x0a,
|
||||
0x20, 0x20, 0x20, 0x63, 0x6c, 0x61, 0x69, 0x6d, 0x20, 0x74, 0x68, 0x61, 0x74, 0x20, 0x79, 0x6f, 0x75, 0x20,
|
||||
0x77, 0x72, 0x6f, 0x74, 0x65, 0x20, 0x74, 0x68, 0x65, 0x20, 0x6f, 0x72, 0x69, 0x67, 0x69, 0x6e, 0x61, 0x6c,
|
||||
0x20, 0x73, 0x6f, 0x66, 0x74, 0x77, 0x61, 0x72, 0x65, 0x2e, 0x20, 0x49, 0x66, 0x20, 0x79, 0x6f, 0x75, 0x20,
|
||||
0x75, 0x73, 0x65, 0x20, 0x74, 0x68, 0x69, 0x73, 0x20, 0x73, 0x6f, 0x66, 0x74, 0x77, 0x61, 0x72, 0x65, 0x0a,
|
||||
0x20, 0x20, 0x20, 0x69, 0x6e, 0x20, 0x61, 0x20, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x2c, 0x20, 0x61,
|
||||
0x6e, 0x20, 0x61, 0x63, 0x6b, 0x6e, 0x6f, 0x77, 0x6c, 0x65, 0x64, 0x67, 0x6d, 0x65, 0x6e, 0x74, 0x20, 0x69,
|
||||
0x6e, 0x20, 0x74, 0x68, 0x65, 0x20, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x20, 0x64, 0x6f, 0x63, 0x75,
|
||||
0x6d, 0x65, 0x6e, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x77, 0x6f, 0x75, 0x6c, 0x64, 0x20, 0x62, 0x65, 0x0a,
|
||||
0x20, 0x20, 0x20, 0x61, 0x70, 0x70, 0x72, 0x65, 0x63, 0x69, 0x61, 0x74, 0x65, 0x64, 0x20, 0x62, 0x75, 0x74,
|
||||
0x20, 0x69, 0x73, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x64, 0x2e, 0x0a,
|
||||
0x32, 0x2e, 0x20, 0x41, 0x6c, 0x74, 0x65, 0x72, 0x65, 0x64, 0x20, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x20,
|
||||
0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x73, 0x20, 0x6d, 0x75, 0x73, 0x74, 0x20, 0x62, 0x65, 0x20, 0x70,
|
||||
0x6c, 0x61, 0x69, 0x6e, 0x6c, 0x79, 0x20, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x64, 0x20, 0x61, 0x73, 0x20, 0x73,
|
||||
0x75, 0x63, 0x68, 0x2c, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x6d, 0x75, 0x73, 0x74, 0x20, 0x6e, 0x6f, 0x74, 0x20,
|
||||
0x62, 0x65, 0x0a,
|
||||
0x20, 0x20, 0x20, 0x6d, 0x69, 0x73, 0x72, 0x65, 0x70, 0x72, 0x65, 0x73, 0x65, 0x6e, 0x74, 0x65, 0x64, 0x20,
|
||||
0x61, 0x73, 0x20, 0x62, 0x65, 0x69, 0x6e, 0x67, 0x20, 0x74, 0x68, 0x65, 0x20, 0x6f, 0x72, 0x69, 0x67, 0x69,
|
||||
0x6e, 0x61, 0x6c, 0x20, 0x73, 0x6f, 0x66, 0x74, 0x77, 0x61, 0x72, 0x65, 0x2e, 0x0a,
|
||||
0x33, 0x2e, 0x20, 0x54, 0x68, 0x69, 0x73, 0x20, 0x6e, 0x6f, 0x74, 0x69, 0x63, 0x65, 0x20, 0x6d, 0x61, 0x79,
|
||||
0x20, 0x6e, 0x6f, 0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x65, 0x6d, 0x6f, 0x76, 0x65, 0x64, 0x20, 0x6f, 0x72,
|
||||
0x20, 0x61, 0x6c, 0x74, 0x65, 0x72, 0x65, 0x64, 0x20, 0x66, 0x72, 0x6f, 0x6d, 0x20, 0x61, 0x6e, 0x79, 0x20,
|
||||
0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x20, 0x64, 0x69, 0x73, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x69, 0x6f,
|
||||
0x6e, 0x2e, 0x0a,
|
||||
0x2d, 0x2d, 0x5d, 0x5d, 0x0a,0x0a,
|
||||
0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x61, 0x75, 0x64, 0x69,
|
||||
0x6f, 0x2e, 0x6e, 0x65, 0x77, 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x28, 0x61, 0x2c, 0x20, 0x62, 0x29, 0x0a,
|
||||
0x09, 0x69, 0x66, 0x20, 0x74, 0x79, 0x70, 0x65, 0x28, 0x61, 0x29, 0x20, 0x3d, 0x3d, 0x20, 0x22, 0x73, 0x74,
|
||||
0x72, 0x69, 0x6e, 0x67, 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a,
|
||||
0x09, 0x09, 0x61, 0x20, 0x3d, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x79, 0x73,
|
||||
0x74, 0x65, 0x6d, 0x2e, 0x6e, 0x65, 0x77, 0x46, 0x69, 0x6c, 0x65, 0x28, 0x61, 0x29, 0x0a,
|
||||
0x09, 0x65, 0x6e, 0x64, 0x0a,
|
||||
0x09, 0x69, 0x66, 0x20, 0x74, 0x79, 0x70, 0x65, 0x28, 0x61, 0x29, 0x20, 0x3d, 0x3d, 0x20, 0x22, 0x75, 0x73,
|
||||
0x65, 0x72, 0x64, 0x61, 0x74, 0x61, 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a,
|
||||
0x09, 0x09, 0x69, 0x66, 0x20, 0x61, 0x3a, 0x74, 0x79, 0x70, 0x65, 0x4f, 0x66, 0x28, 0x22, 0x46, 0x69, 0x6c,
|
||||
0x65, 0x22, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a,
|
||||
0x09, 0x09, 0x09, 0x61, 0x20, 0x3d, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x73, 0x6f, 0x75, 0x6e, 0x64, 0x2e,
|
||||
0x6e, 0x65, 0x77, 0x44, 0x65, 0x63, 0x6f, 0x64, 0x65, 0x72, 0x28, 0x61, 0x29, 0x0a,
|
||||
0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a,
|
||||
0x09, 0x09, 0x0a,
|
||||
0x09, 0x09, 0x69, 0x66, 0x20, 0x61, 0x3a, 0x74, 0x79, 0x70, 0x65, 0x4f, 0x66, 0x28, 0x22, 0x44, 0x65, 0x63,
|
||||
0x6f, 0x64, 0x65, 0x72, 0x22, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a,
|
||||
0x09, 0x09, 0x09, 0x69, 0x66, 0x20, 0x62, 0x20, 0x3d, 0x3d, 0x20, 0x22, 0x73, 0x74, 0x61, 0x74, 0x69, 0x63,
|
||||
0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a,
|
||||
0x09, 0x09, 0x09, 0x09, 0x61, 0x20, 0x3d, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x73, 0x6f, 0x75, 0x6e, 0x64,
|
||||
0x2e, 0x6e, 0x65, 0x77, 0x53, 0x6f, 0x75, 0x6e, 0x64, 0x44, 0x61, 0x74, 0x61, 0x28, 0x61, 0x29, 0x0a,
|
||||
0x09, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a,
|
||||
0x09, 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x61, 0x75, 0x64,
|
||||
0x69, 0x6f, 0x2e, 0x6e, 0x65, 0x77, 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x31, 0x28, 0x61, 0x29, 0x0a,
|
||||
0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a,
|
||||
0x09, 0x09, 0x69, 0x66, 0x20, 0x61, 0x3a, 0x74, 0x79, 0x70, 0x65, 0x4f, 0x66, 0x28, 0x22, 0x53, 0x6f, 0x75,
|
||||
0x6e, 0x64, 0x44, 0x61, 0x74, 0x61, 0x22, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a,
|
||||
0x09, 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x61, 0x75, 0x64,
|
||||
0x69, 0x6f, 0x2e, 0x6e, 0x65, 0x77, 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x31, 0x28, 0x61, 0x29, 0x0a,
|
||||
0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a,
|
||||
0x09, 0x65, 0x6e, 0x64, 0x0a,
|
||||
0x09, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x28, 0x22, 0x4e, 0x6f, 0x20, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x69, 0x6e,
|
||||
0x67, 0x20, 0x6f, 0x76, 0x65, 0x72, 0x6c, 0x6f, 0x61, 0x64, 0x22, 0x29, 0x0a,
|
||||
0x65, 0x6e, 0x64, 0x0a,
|
||||
}; // [audio.lua]
|
||||
} // love
|
||||
+91
-75
@@ -4,97 +4,113 @@
|
||||
-- Example:
|
||||
-- lua auto.lua boot graphics
|
||||
|
||||
max_width = 15
|
||||
local max_width = 18
|
||||
local pattern = [[
|
||||
/**
|
||||
* Copyright (c) 2006-2011 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
namespace love
|
||||
{
|
||||
|
||||
// [%s]
|
||||
const unsigned char %s[] =
|
||||
{
|
||||
%s
|
||||
}; // [%s]
|
||||
} // love]]
|
||||
--formatting parameters:
|
||||
-- - input file name
|
||||
-- - c variable name
|
||||
-- - array contents
|
||||
-- - input file name
|
||||
|
||||
|
||||
function auto(name)
|
||||
|
||||
--the input file name
|
||||
local src = name .. ".lua"
|
||||
--and the output one
|
||||
local dst = name .. ".lua.h"
|
||||
--the name of the variable
|
||||
local cpp_name = name .. "_lua"
|
||||
|
||||
-- Read source Lua file
|
||||
--do a minimal code check
|
||||
--(syntax errors, really)
|
||||
loadfile(src)
|
||||
--no error catching? no
|
||||
--we have the main loop doing that for us
|
||||
|
||||
--what character is this on this line?
|
||||
local counter = 0
|
||||
|
||||
local function tohex(c)
|
||||
counter = counter + 1
|
||||
--if we've reached the maximum width (or 0)
|
||||
--then we'll carry on and add a newline
|
||||
if counter % max_width == 0 then
|
||||
return ("\n\t0x%02x, "):format(c:byte())
|
||||
end
|
||||
--otherwise we just use the hex of the current byte
|
||||
return ("0x%02x, "):format(c:byte())
|
||||
end
|
||||
|
||||
--let's open the input file
|
||||
local src_file = io.open(src, "rb")
|
||||
local src_data = src_file:read("*a")
|
||||
-- remove comments
|
||||
src_data = src_data:gsub("%-%-%[%[.-%-%-%]%]", ""):gsub("%-%-.-\n", "")
|
||||
-- remove unneeded whitespaces
|
||||
src_data = src_data:gsub("^%s+",""):gsub("%s*$",""):gsub("%s%s+", " ")
|
||||
local src_len = #src_data
|
||||
--create an output string
|
||||
local out_data = ""
|
||||
--go through the input file line-by-line
|
||||
for line in src_file:lines() do
|
||||
--if the line is non-empty
|
||||
if #line > 0 then
|
||||
--set the counter to -1
|
||||
--this will start a new line (see tohex)
|
||||
counter = -1
|
||||
--append the output to what we had, plus a newline character (0x0a is newline)
|
||||
out_data = ("%s%s0x0a,"):format(out_data, line:gsub("\r", ""):gsub(".", tohex))
|
||||
end
|
||||
end
|
||||
--close our input
|
||||
src_file:close()
|
||||
|
||||
local lines = {}
|
||||
local line = {}
|
||||
table.insert(lines, line)
|
||||
|
||||
for i=1,src_len do
|
||||
table.insert(line, string.byte(src_data, i))
|
||||
if math.mod(i, max_width) == 0 then
|
||||
line = {}
|
||||
table.insert(lines, line)
|
||||
end
|
||||
end
|
||||
|
||||
local src_output = "const unsigned char "..cpp_name.."[] = \n{\n"
|
||||
|
||||
for i,line in ipairs(lines) do
|
||||
local concat = {}
|
||||
for j,b in ipairs(line) do
|
||||
table.insert(concat, string.format("0x%02X,", b))
|
||||
end
|
||||
src_output = src_output .. "\t" .. table.concat(concat, "").."\n"
|
||||
end
|
||||
|
||||
src_output = src_output .. "};"
|
||||
|
||||
local include = true
|
||||
|
||||
-- Read dst
|
||||
local dst_lines = {}
|
||||
for line in io.lines(dst) do
|
||||
|
||||
if line == "// ["..src.."]" then
|
||||
include = false
|
||||
table.insert(dst_lines, line)
|
||||
table.insert(dst_lines, src_output)
|
||||
end
|
||||
|
||||
if line == "// [/"..src.."]" then
|
||||
include = true
|
||||
end
|
||||
|
||||
if include then
|
||||
table.insert(dst_lines, line)
|
||||
end
|
||||
end
|
||||
|
||||
local tmp_data = table.concat(dst_lines, "\n")
|
||||
|
||||
-- Overwrite the old file only if they are different.
|
||||
local dst_file = io.open(dst, "rb")
|
||||
dst_data = dst_file:read("*a")
|
||||
dst_file:close()
|
||||
|
||||
if tmp_data == dst_data then
|
||||
print(name .. ": no change")
|
||||
else
|
||||
|
||||
local dst_file = io.open(dst, "wb")
|
||||
dst_file:write(tmp_data)
|
||||
dst_file:close()
|
||||
|
||||
print(name .. ": updated")
|
||||
end
|
||||
--open, write and close the output
|
||||
out_file = io.open(dst, "wb")
|
||||
--see pattern above
|
||||
out_file:write(pattern:format(src, cpp_name, out_data, src))
|
||||
out_file:close()
|
||||
|
||||
--tell the world we succeeded!
|
||||
print(name .. ": Success")
|
||||
end
|
||||
|
||||
--usage
|
||||
if #arg == 0 then
|
||||
print("Usage: lua auto.lua <name1> <name2> .. <name3>")
|
||||
else
|
||||
return print("Usage: lua auto.lua <name1> <name2> .. <name3>")
|
||||
end
|
||||
|
||||
--the 'main' procedure
|
||||
for i, v in ipairs(arg) do
|
||||
--run the auto function for every argument
|
||||
--but do it with pcall, to catch errors
|
||||
local ok, err = pcall(auto, v:gsub("%.lua$",""))
|
||||
if not ok then
|
||||
print("cannot update "..v..": " .. err)
|
||||
end
|
||||
--inform people we've failed
|
||||
print(v .. ": " .. err)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
+2128
-2048
File diff suppressed because it is too large
Load Diff
+5008
-6001
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user