From 7b9f0cb5c24ee4f0bea1a2d4b8b42b033bd425dc Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Sat, 25 Jun 2016 05:30:53 -0400 Subject: [PATCH] Add automatic conf.lua loading - Fixes #58 --- lutro.c | 16 ++++++++++++++-- test.lutro | Bin 0 -> 10982 bytes test/conf.lua | 4 ++++ test/main.lua | 9 ++------- 4 files changed, 20 insertions(+), 9 deletions(-) create mode 100644 test.lutro create mode 100644 test/conf.lua diff --git a/lutro.c b/lutro.c index b02b069..570cd04 100644 --- a/lutro.c +++ b/lutro.c @@ -388,21 +388,29 @@ int lutro_unzip(const char *path, const char *extraction_directory) int lutro_load(const char *path) { char mainfile[PATH_MAX_LENGTH]; + // conf.lua https://love2d.org/wiki/Config_Files + char conffile[PATH_MAX_LENGTH]; char gamedir[PATH_MAX_LENGTH]; strlcpy(mainfile, path, PATH_MAX_LENGTH); + strlcpy(conffile, path, PATH_MAX_LENGTH); strlcpy(gamedir, path, PATH_MAX_LENGTH); - if (path_is_directory(mainfile)) + if (path_is_directory(mainfile)) { fill_pathname_join(mainfile, gamedir, "main.lua", sizeof(mainfile)); - else + fill_pathname_join(conffile, gamedir, "conf.lua", sizeof(conffile)); + } + else { path_basedir(gamedir); + } if (!strcmp(path_get_extension(mainfile), "lutro")) { fill_pathname(gamedir, mainfile, "/", sizeof(gamedir)); + fill_pathname(gamedir, conffile, "/", sizeof(gamedir)); lutro_unzip(mainfile, gamedir); fill_pathname_join(mainfile, gamedir, "main.lua", sizeof(mainfile)); + fill_pathname_join(conffile, gamedir, "conf.lua", sizeof(conffile)); } fill_pathname_slash(gamedir, sizeof(gamedir)); @@ -411,6 +419,10 @@ int lutro_load(const char *path) snprintf(package_path, PATH_MAX_LENGTH, ";%s?.lua;%s?/init.lua", gamedir, gamedir); lutro_set_package_path(L, package_path); + // Load the configuration file, ignoring any errors. + dofile(L, conffile); + + // Now that configuration is in place, load main.lua. if(dofile(L, mainfile)) { fprintf(stderr, "%s\n", lua_tostring(L, -1)); diff --git a/test.lutro b/test.lutro new file mode 100644 index 0000000000000000000000000000000000000000..448378d114a3a8a522366c43b9533040380b48e6 GIT binary patch literal 10982 zcmaJ{1z1&0x2C&8x}>E=x7dj0hC|L>ji z%(M5|d%ZJj?LD(*t#^++02&4d8UkFRZD%DOkG~2W_{6})*usuQ{(ofAww*uRl0Aw_Tx6dK{_6O&2K(tHq_z)1W*Wr-dgZ?kk8DB~`iyF5; zUOj||y^Y=xu@UlL+MVA;pFH)aW`%-VS*S&=grMo0f%L5;c9y;kJYB&;@KZY<*{hS@ zPksA7*y(G|L$#Mc?_BA1Hw!vKgDd|FMR*G(9FeE%Y4J@}6EGT~pA;jo(IucvM)UBf z$UcQk1XfdNRG(FCm=!fyM`_bo#nelU4*0}o#tfPqS3AtPTswB-Uc>Roe%BmPn5B!r zwQ-c|HhNvQmT#!&AZ$@mKFPf~JX1R5s=|ww)cnp(mMk5#z{qW7gPKt#gIAN-#?dFV z<5Bn>Enx+}n{$V5SPO&HB{@C#K@2B!9{DAH`h?h3`f;S*;GsT#{FXer!(LbQ93n7p zLoVXenB|DZy!Q#!IfPahChN2kD~^a5CPP#QH9Lal1mV1Zck*d1Ghi>>&~Y`EwY0O| zP;{v2-mEw?PW5@-@yOk}E^tR#Si56NJJWfll%eNwL)5SnV(-vqNkNGxyCrO9YX@X34&~pJZ9u6$3(|`!L)WLKuA!AWJyUfiy@57LU)okdS*T_-+!2NNAQ9 zzEL!*kzH{u&OuQV!>mTN)xD`!l!|-(x|7QgnX-IsB`?U`RFHY8f`$O9`MJ}<6oLVEwEWVd7@*^e(Z zB}z==8#N-FpGQsfja7Lidll05msnT~L73uE2g?Ii6p`tO7dx)QEuY)srt|t6lsdR38f(a~iGnI-L1_?d(T4|gw9#t`wQVaiDehBg$&>7Byv>L8s_hsO(*t0AV* z_w+#qiVWK`N948)JaOjzN838+b@`W=;q+7&VPmP%)N>iueJc)O8d$}M*UvZ-=uJtp zWwEgkya!;VvMNByJ|6*F^X#GJ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