From: Charles McGarvey Date: Tue, 9 Mar 2010 16:56:56 +0000 (-0700) Subject: new convenient script methods X-Git-Url: https://git.dogcows.com/gitweb?a=commitdiff_plain;h=58c1f9a499d3bb80ea2869b29c714f61e656d48d;p=chaz%2Fyoink new convenient script methods --- diff --git a/Makefile.am b/Makefile.am index f3c3773..7f62c7d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -9,10 +9,10 @@ EXTRA_DIST = autogen.sh extra win32 .PHONY: run debug docs portable installer run: all - @$(CD) src && $(MAKE) run + @cd src && $(MAKE) run debug: all - @$(CD) src && $(MAKE) debug + @cd src && $(MAKE) debug docs: $(DOXYGEN) @@ -20,11 +20,11 @@ docs: if WIN32 portable: all - $(SH) win32/makepackage.sh -p $(prefix) -d "$(DATA_FILES)" \ + $(SH) win32/makepackage.sh -p $(prefix) -d "@DATA_FILES@" \ -s $(STRIP) -V $(VERSION) installer: all - $(SH) win32/makepackage.sh -p $(prefix) -d "$(DATA_FILES)" \ + $(SH) win32/makepackage.sh -p $(prefix) -d "@DATA_FILES@" \ -s $(STRIP) -V $(VERSION) -i $(MAKENSIS) endif diff --git a/configure.ac b/configure.ac index 9331964..d3d55ae 100644 --- a/configure.ac +++ b/configure.ac @@ -318,7 +318,7 @@ fi if test x$missing == xyes then - AC_MSG_WARN([It looks like you're missing some dependencies--building may fail!]) + AC_MSG_ERROR([Please resolve the missing dependencies, and try again.]) fi diff --git a/data/scenes/Classic.lua b/data/scenes/Classic.lua index fb4765f..75ea02a 100644 --- a/data/scenes/Classic.lua +++ b/data/scenes/Classic.lua @@ -5,6 +5,11 @@ LogInfo("-----", "Converted to Lua by Charles McGarvey", "-----") +--for key,value in pairs(_G) do print(key, value) end +meh = Blah:new() +meh:sayHello() +print(meh:myStr(3.1415)) + -- Scene API: -- -- Functions: diff --git a/data/yoinkrc b/data/yoinkrc index bf5bc83..f6f362c 100644 --- a/data/yoinkrc +++ b/data/yoinkrc @@ -81,5 +81,5 @@ swapcontrol = true -- 2 include warnings -- 3 print everything, including debug messages -loglevel = 2 +loglevel = 2 diff --git a/src/Moof/Script.hh b/src/Moof/Script.hh index 9af5440..620db5b 100644 --- a/src/Moof/Script.hh +++ b/src/Moof/Script.hh @@ -15,8 +15,9 @@ /** * @file Script.hh * A thin wrapper over Lua. This is not meant as a complicated binding - * package between C++ and Lua. It does not try to make the boundary - * invisible. It does not hide the concept of the Lua stack, but rather + * package between C++ and Lua. It is not meant to obscure the division + * between C++ and Lua but rather to clarify it and make it more + * manageable. It does not hide the concept of the Lua stack, but rather * provides that mechanism with a certain level of abstraction while also * providing a cleaner, more consistent API. */ @@ -32,8 +33,6 @@ #include #include -#include - namespace Mf { @@ -412,6 +411,19 @@ public: return true; } + /** + * Get the value of a field from the table. + */ + + template + bool get(T& value, V field) const + { + pushField(field); + bool ret = Slot(mState, -1).get(value); + lua_pop(mState, 1); + return ret; + } + /** * Copy the value and push the copy to the stack. @@ -447,7 +459,7 @@ public: } - void pushMetatable() const + void pushMetaTable() const { lua_getmetatable(mState, index); } @@ -569,7 +581,6 @@ public: lua_setglobal(mState, name.c_str()); } - Result doString(const std::string& commands) { return (Result)luaL_dostring(mState, commands.c_str()); diff --git a/src/Scene.cc b/src/Scene.cc index afbfa44..918ff52 100644 --- a/src/Scene.cc +++ b/src/Scene.cc @@ -140,7 +140,7 @@ struct Scene::Impl : public Mf::Manager //Mf::Octree::Ptr mOctree; std::list< boost::shared_ptr > mObjects; - std::list< Mf::Line<2> > mLines; + std::list mLines; Mf::Aabb<3> mBounds; @@ -261,24 +261,26 @@ struct Scene::Impl : public Mf::Manager int scale(Mf::Script& script) { - if (script.getSize() == 3) + int size = script.getSize(); + + if (size == 1) { - Mf::Vector3 vec; - script[1].requireNumber().get(vec[0]); - script[2].requireNumber().get(vec[1]); - script[3].requireNumber().get(vec[2]); + Mf::Scalar value = 1.0; + script[1].requireNumber().get(value); Mf::Matrix4 scaling; - cml::matrix_scale(scaling, vec); + cml::matrix_uniform_scale(scaling, value); mTransform = scaling * mTransform; } - else if (script.getSize() == 1) + else if (size == 3) { - Mf::Scalar value = 1.0; - script[1].requireNumber().get(value); + Mf::Vector3 vec; + script[1].requireNumber().get(vec[0]); + script[2].requireNumber().get(vec[1]); + script[3].requireNumber().get(vec[2]); Mf::Matrix4 scaling; - cml::matrix_uniform_scale(scaling, value); + cml::matrix_scale(scaling, vec); mTransform = scaling * mTransform; } else @@ -311,16 +313,13 @@ struct Scene::Impl : public Mf::Manager int drawTilemap(Mf::Script& script) { - Mf::Script::Slot table = script[1].requireTable(); - Mf::Script::Slot top = script[-1]; + Mf::Script::Slot table = script[1].requireTable(); - int width = 1; - int height = 1; - int nTiles = 0; + int width = 1; + int height = 1; + int nTiles = 0; - table.pushField("width"); - top.get(width); - script.pop(); + table.get(width, "width"); nTiles = table.getLength(); if (nTiles % width != 0) @@ -358,12 +357,8 @@ struct Scene::Impl : public Mf::Manager int wPlus1 = w + 1; int hPlus1 = h + 1; - table.pushField(i); - Mf::Texture::TileIndex index; - top.get(index); - - script.pop(); + table.get(index, i); vertices[h][wPlus1] = Mf::demote(mTransform * Mf::Vector4(wPlus1, h, 0.0, 1.0)); @@ -386,10 +381,7 @@ struct Scene::Impl : public Mf::Manager } Quad::Surface surface = Quad::NONE; - - table.pushField("surface"); - top.get(surface); - script.pop(); + table.get(surface, "surface"); if (surface != Quad::NONE) { @@ -402,7 +394,6 @@ struct Scene::Impl : public Mf::Manager Mf::Vector2 tr = Mf::demote(vertices[height][width]); mLines.push_back(Mf::Line<2>(bl, tr)); - Mf::logInfo("new line"); } return 0; @@ -420,18 +411,10 @@ struct Scene::Impl : public Mf::Manager if (param.isTable()) { - script.push(1); - param.pushField(); - top.get(index); - - param.pushField("u_scale"); - top.get(width); - - param.pushField("blend"); - top.get(blending); - - param.pushField("fog"); - top.get(fog); + param.get(index, 1); + param.get(width, "u_scale"); + param.get(blending, "blend"); + param.get(fog, "fog"); } else if (param.isNumber()) { @@ -441,7 +424,7 @@ struct Scene::Impl : public Mf::Manager Mf::Vector3 vertices[2][width+1]; Mf::Scalar xf; - Mf::Scalar increment = 1.0 / Mf::Scalar(width); + Mf::Scalar increment = SCALAR(1.0) / Mf::Scalar(width); for (int h = 0; h <= 1; ++h) { diff --git a/src/yoink.rc b/src/yoink.rc index 8d626fc..18c10e8 100644 --- a/src/yoink.rc +++ b/src/yoink.rc @@ -39,5 +39,5 @@ BEGIN END END -1000 ICON "yoink.ico" +1000 ICON "../win32/yoink.ico" diff --git a/win32/makedeps.sh b/win32/makedeps.sh index 026d911..e004aec 100755 --- a/win32/makedeps.sh +++ b/win32/makedeps.sh @@ -23,10 +23,10 @@ # libvorbis 1.2.3 # lua 5.1.4 # openal-soft 1.11.753 -# zlib 1.2.3 # # This script requires a working mingw32 toolchain and other basic tools. -# Have fun! +# You also need zlib which may not have been included with your mingw32 +# installation; you're on your own for that one. Have fun! # # Example usage: # ./makedeps.sh -H i486-mingw32 -p /usr/i486-mingw32 -m "-j8" @@ -84,8 +84,9 @@ function die() } DESTDIR="`pwd`/deps" -mkdir -p $DESTDIR -rm -f $DESTDIR/README +mkdir -p "$DESTDIR" +rm -f "$DESTDIR/README" +rm -rf "$DESTDIR/$PREFIX" PACKAGE="boost_1_42_0" @@ -181,23 +182,24 @@ EOL ) || die "installing $PACKAGE" -PACKAGE="zlib123-dll" -cd $DESTDIR -test ! -f $PACKAGE.zip && (wget "http://www.zlib.net/$PACKAGE.zip" || die "downloading $PACKAGE") -(md5sum -c <<"EOL" -cc7fa97f9c19386bb701acc79d0abbca zlib123-dll.zip -EOL -) || die "verifying $PACKAGE" -rm -rf $PACKAGE -unzip -d $PACKAGE $PACKAGE.zip || die "unpackaging $PACKAGE" -cd $PACKAGE -($HOST-dlltool -k -d lib/zlib.def -D zlib1.dll -l libzdll.a && \ -mkdir -p $DESTDIR/$PREFIX/{lib,include} && \ -install -p -m 0644 include/* $DESTDIR/$PREFIX/include/ && \ -install -p -m 0755 zlib1.dll $DESTDIR/$PREFIX/bin/ && \ -install -p -m 0755 libzdll.a $DESTDIR/$PREFIX/lib/ && \ -cd $DESTDIR/$PREFIX/lib && \ -ln -fs libzdll.a libz.dll.a) || die "installing $PACKAGE" +#PACKAGE="zlib123-dll" +#cd $DESTDIR +#test ! -f $PACKAGE.zip && (wget "http://www.zlib.net/$PACKAGE.zip" || die "downloading $PACKAGE") +#(md5sum -c <<"EOL" +#cc7fa97f9c19386bb701acc79d0abbca zlib123-dll.zip +#EOL +#) || die "verifying $PACKAGE" +#rm -rf $PACKAGE +#unzip -d $PACKAGE $PACKAGE.zip || die "unpackaging $PACKAGE" +#cd $PACKAGE +#($HOST-dlltool -k -d lib/zlib.def -D zlib1.dll -l libzdll.a && \ +#$HOST-ranlib libzdll.a && \ +#mkdir -p $DESTDIR/$PREFIX/{lib,include} && \ +#install -p -m 0644 include/* $DESTDIR/$PREFIX/include/ && \ +#install -p -m 0755 zlib1.dll $DESTDIR/$PREFIX/bin/ && \ +#install -p -m 0755 libzdll.a $DESTDIR/$PREFIX/lib/ && \ +#cd $DESTDIR/$PREFIX/lib && \ +#ln -fs libzdll.a libz.dll.a) || die "installing $PACKAGE" PACKAGE="libpng-1.4.1" @@ -210,11 +212,11 @@ EOL rm -rf $PACKAGE tar xzf $PACKAGE.tar.gz || die "unpackaging $PACKAGE" cd $PACKAGE -./configure --host=$HOST --prefix=$PREFIX \ -CPPFLAGS="-I$DESTDIR/$PREFIX/include" \ -LDFLAGS="-L$DESTDIR/$PREFIX/lib" || die "configuring $PACKAGE" -make $MAKEOPTS || die "making $PACKAGE" -make DESTDIR=$DESTDIR install || die "installing $PACKAGE" +cp scripts/makefile.mingw Makefile && \ +make $MAKEOPTS prefix="$PREFIX" CC="$HOST-gcc" AR="$HOST-ar" RANLIB="$HOST-ranlib" \ +ZLIBINC="-I$DESTDIR/$PREFIX/include" \ +ZLIBLIB="-L$DESTDIR/$PREFIX/lib" libpng.a libpng14.dll || die "making $PACKAGE" +make DESTDIR=$DESTDIR install prefix="$PREFIX" || die "installing $PACKAGE" PACKAGE="lua-5.1.4" diff --git a/win32/makepackage.sh b/win32/makepackage.sh index 6cb1afa..0cb4885 100755 --- a/win32/makepackage.sh +++ b/win32/makepackage.sh @@ -2,7 +2,7 @@ # # Yoink -# Run this script to create a portable win32 package. +# Run this script to create a win32 package. # function showhelp() @@ -62,15 +62,14 @@ function die() } ROOT="$PWD" -BUILD="$PWD/tmp-$$" -NAME="yoink-$VERSION" -ARCHIVE="$BUILD/$NAME" -INSTALLER_SCRIPT="$ROOT/win32/yoink.nsi" +BUILD="$ROOT/tmp-$$" +DIRECTORY="yoink-$VERSION" +ARCHIVE="$BUILD/$DIRECTORY" MAN2HTML="$ROOT/doc/man2html.sh" UNIX2DOS="$ROOT/win32/unix2dos.sh" -DLLS="libogg-0 libpng14-14 libvorbis-0 libvorbisfile-3 lua51 OpenAL32 SDL zlib1" +DLLS="libogg-0 libpng14 libvorbis-0 libvorbisfile-3 lua51 OpenAL32 SDL zlib1" if test ! -f "src/version.c" @@ -121,21 +120,26 @@ cd "$ROOT" if test "x$MAKENSIS" = x then -# build the portable archive +# build portable archive + echo "No valid makensis executable passed;" + echo "making portable package instead..." + NAME="$DIRECTORY.zip" cd "$BUILD" - zip -r $NAME.zip $NAME || die "zipping portable archive" + zip -r "$NAME" "$DIRECTORY" || die "zipping portable archive" cd "$ROOT" - mv "$BUILD/$NAME.zip" . - echo "Done! Package saved to $NAME.zip." + mv "$BUILD/$NAME" . + echo "Done! Package saved to $NAME." else # build an installer - cd "$BULID" - "$MAKENSIS" "$INSTALLER_SCRIPT" \ - -DINSTALLFILES="$NAME" -DVERSION="$VERSION" \ + NAME="yoinksetup-$VERSION.exe" + cd "$BUILD" + cp "$ROOT/win32/yoink.nsi" . + "$MAKENSIS" -DROOTPATH="$ROOT" -DINSTALLFILES="$ARCHIVE" \ + -DVERSION="$VERSION" -DOUTFILE="$NAME" yoink.nsi \ || die "running '$MAKENSIS'" cd "$ROOT" - mv "$BUILD/$NAME.exe" . - echo "Done! Installer saved to $NAME.exe." + mv "$BUILD/$NAME" . + echo "Done! Installer saved to $NAME." fi diff --git a/src/setup.ico b/win32/setup.ico similarity index 100% rename from src/setup.ico rename to win32/setup.ico diff --git a/src/uninstall.ico b/win32/uninstall.ico similarity index 100% rename from src/uninstall.ico rename to win32/uninstall.ico diff --git a/src/yoink.ico b/win32/yoink.ico similarity index 100% rename from src/yoink.ico rename to win32/yoink.ico diff --git a/win32/yoink.nsi b/win32/yoink.nsi index 7f1b635..2638a65 100644 --- a/win32/yoink.nsi +++ b/win32/yoink.nsi @@ -12,7 +12,7 @@ ;Name and file Name "Yoink" - OutFile "yoinksetup-$VERSION.exe" + OutFile "${OUTFILE}" SetCompressor /SOLID lzma ;Default installation folder @@ -27,8 +27,8 @@ ;-------------------------------- ;Interface Settings - !define MUI_ICON "../src/setup.ico" - !define MUI_UNICON "../src/uninstall.ico" + !define MUI_ICON "${ROOTPATH}/win32/setup.ico" + !define MUI_UNICON "${ROOTPATH}/win32/uninstall.ico" !define MUI_COMPONENTSPAGE_SMALLDESC @@ -64,7 +64,7 @@ Section "Install Yoink!" SecInstallYoink SetOutPath "$INSTDIR" ;ADD YOUR OWN FILES HERE... - File /r "$INSTALLFILES/*" + File /r "${INSTALLFILES}/*" ;Store installation folder WriteRegStr HKCU "Software\Yoink" "" $INSTDIR @@ -78,9 +78,9 @@ Section "Install Yoink!" SecInstallYoink CreateShortCut "$SMPROGRAMS\Yoink\Uninstall.lnk" "$INSTDIR\uninstall.exe" WriteRegStr HKCU "Software\Games\Yoink" "" "$INSTDIR" - WriteRegStr HKCU "Software\Games\Yoink" "Version" "$VERSION" + WriteRegStr HKCU "Software\Games\Yoink" "Version" "${VERSION}" WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\Yoink" "DisplayName" "Yoink" - WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\Yoink" "DisplayVersion" "$VERSION" + WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\Yoink" "DisplayVersion" "${VERSION}" WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\Yoink" "UninstallString" "$INSTDIR\uninstall.exe" SectionEnd