{"id":836,"date":"2012-12-18T20:00:00","date_gmt":"2012-12-18T19:00:00","guid":{"rendered":"http:\/\/shadowcovenant.com\/blog\/2012\/12\/18\/no-title-really\/"},"modified":"2012-12-18T20:00:00","modified_gmt":"2012-12-18T19:00:00","slug":"no-title-really","status":"publish","type":"post","link":"http:\/\/shadowcovenant.com\/blog\/2012\/12\/18\/no-title-really\/","title":{"rendered":"No title, really&hellip;"},"content":{"rendered":"<p align=\"justify\">This is one of those posts that have a bit of everything, so no decent title for it\u2026 <img decoding=\"async\" style=\"border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none\" class=\"wlEmoticon wlEmoticon-smile\" alt=\"Smile\" src=\"http:\/\/shadowcovenant.com\/blog\/wp-content\/uploads\/2012\/12\/wlEmoticon-smile.png\" \/><\/p>\n<p align=\"justify\">Anyway, as you might have seen in the <a href=\"http:\/\/www.spellcasterstudios.com\/?p=481\">Spellcaster Studios blog<\/a>, me and Rincewind gave up on the Indie Speed Run, mainly because of scope issues\u2026 We went a little wild with it, Rincewind because of lack of 48-hour compo experience, and me because I thought that without needing to do graphics I could do much more\u2026<\/p>\n<p align=\"justify\">Anyway, it was a good exercise, and I\u2019m definitely finishing this one, not because it is brilliant, but it\u2019s great to figure out bugs on SurgeEd and SurgePlayer, which I used for the game. Already figured out some nasty bugs which would have taken a lot of time to fix on the \u201cGrey\u201d scripts, specially one that only seems to manifest in specific conditions\u2026<\/p>\n<p align=\"justify\">If you\u2019ve been following this blog, you know I\u2019m using <a href=\"http:\/\/www.lua.org\/\">Lua<\/a> to drive the game logic, and specifically <a href=\"http:\/\/luajit.org\/\">LuaJIT<\/a>, and I found an odd behavior\u2026<\/p>\n<p align=\"justify\">The offending piece of code was something that tested a condition and acted on that:<\/p>\n<pre><p align=\"justify\">function do_something(param)<br \/>&#160;&#160; if (ffi.C.test(param)) then<br \/>&#160;&#160;&#160;&#160;&#160; change_object()&#160;&#160;&#160; end\nend<\/p><\/pre>\n<p align=\"justify\">test is a function declared on the FFI, that returned a bool:<\/p>\n<pre><p>ffi = require(&quot;ffi&quot;)<br \/>ffi.cdef[[<\/p><p>   bool test(const char* str);<\/p><p>]]<\/p><\/pre>\n<p>Which had a C counterpart like:<\/p>\n<pre>extern &quot;C&quot;<br \/>{&#160;&#160;&#160; bool __declspec(dllexport) test(const char* str)\n   { <\/pre>\n<pre>        bool b=do_some_test();<\/pre>\n<pre><blockquote><p>        return b;<br \/>   }<br \/>}<\/p><p><br \/>&#160;<\/p><\/blockquote><\/pre>\n<p align=\"justify\">Simple enough\u2026<\/p>\n<p align=\"justify\">Problem is, \u201cchange_object\u201d was never reached\u2026 First I thought it was the \u201cdo_some_test\u201d function that was failing, and I added some tracing to it (writing to the logger) with the output, and it turned true eventually\u2026<\/p>\n<p align=\"justify\">Then I added some tracing in the \u201cdo_something\u201d function, and mysteriously, it started working properly\u2026 After a lot of tests, I found that if I used any function that called normally bound functions before the \u201cffi.C.test\u201d call, the system worked properly\u2026 But if I added FFI based functions, it wouldn\u2019t work!<\/p>\n<p align=\"justify\">This was driving me crazy\u2026 then I had a silly idea\u2026 \u201cbool\u201d is a C++ type, not C type, so I changed the declaration of the C function (not the FFI declaration) to \u201c<font face=\"Courier New\">int __declspec(dllexport) test(const char* str)<\/font>\u201d, returning 1 if \u201cdo_some_test\u201d was true, and 0 otherwise\u2026 And now the system worked properly!<\/p>\n<p align=\"justify\">So, I arrived to the conclusion that you can\u2019t output \u201cbool\u201d directly from the C code (although you can declare it that way on the FFI declaration, to get a proper bool and not an int). I imagine the problem was the size of a bool and the stack manipulation of LuaJIT, which caused the system to access corrupted memory (that was probably zeroed before being used, and that\u2019s why the function apparentely always returned \u201cfalse\u201d, although the C output was \u201ctrue\u201d).<\/p>\n<p align=\"justify\">Anyway, 2 hours of my life getting to the bottom of this\u2026 Had to change all the functions that return a bool to return an int instead\u2026<\/p>\n<p align=\"justify\">Anyway, on other news, take a look at this <a href=\"http:\/\/www.hamnasya.net\/\">Hamnasya<\/a> game\u2026 It\u2019s a cross-media kind of game, where you\u2019re reading a book, but you can affect the outcome and fight battles <em>\u00e0 l\u00e1 RPG\u2026 <\/em>Very cool stuff indeed, and has an excellent trailer:<\/p>\n<div style=\"padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px\" id=\"scid:5737277B-5D6D-4f48-ABFC-DD9C333F4C5D:6d7db897-2eae-4bfa-8592-f46a9c085603\" class=\"wlWriterEditableSmartContent\">\n<div><object width=\"560\" height=\"315\"><param name=\"movie\" value=\"http:\/\/www.youtube.com\/v\/54vrIGb8eVA?hl=en&amp;hd=1\"><\/param><embed src=\"http:\/\/www.youtube.com\/v\/54vrIGb8eVA?hl=en&amp;hd=1\" type=\"application\/x-shockwave-flash\" width=\"560\" height=\"315\"><\/embed><\/object><\/div>\n<\/div>\n<p>&#160;<\/p>\n<p>I haven\u2019t picked it up (I had too many pending games at the moment), but it looks pretty good\u2026<\/p>\n<p>If I don\u2019t write anything in the meantime (highly likely), Merry Christmas and a Happy New Year! <img decoding=\"async\" style=\"border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none\" class=\"wlEmoticon wlEmoticon-smile\" alt=\"Smile\" src=\"http:\/\/shadowcovenant.com\/blog\/wp-content\/uploads\/2012\/12\/wlEmoticon-smile.png\" \/><\/p>\n<div id=\"tweetbutton836\" class=\"tw_button\" style=\"\"><a href=\"http:\/\/twitter.com\/share?url=http%3A%2F%2Fshadowcovenant.com%2Fblog%2F2012%2F12%2F18%2Fno-title-really%2F&amp;text=No%20title%2C%20really%26hellip%3B&amp;related=&amp;lang=en&amp;count=horizontal&amp;counturl=http%3A%2F%2Fshadowcovenant.com%2Fblog%2F2012%2F12%2F18%2Fno-title-really%2F\" class=\"twitter-share-button\"  style=\"width:55px;height:22px;background:transparent url('http:\/\/shadowcovenant.com\/blog\/wp-content\/plugins\/wp-tweet-button\/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;\">Tweet<\/a><\/div>","protected":false},"excerpt":{"rendered":"<p>This is one of those posts that have a bit of everything, so no decent title for it\u2026 Anyway, as you might have seen in the Spellcaster Studios blog, me and Rincewind gave up on the Indie Speed Run, mainly because of scope issues\u2026 We went a little wild with it, Rincewind because of lack [&hellip;]<\/p>\n<div id=\"tweetbutton836\" class=\"tw_button\" style=\"\"><a href=\"http:\/\/twitter.com\/share?url=http%3A%2F%2Fshadowcovenant.com%2Fblog%2F2012%2F12%2F18%2Fno-title-really%2F&amp;text=No%20title%2C%20really%26hellip%3B&amp;related=&amp;lang=en&amp;count=horizontal&amp;counturl=http%3A%2F%2Fshadowcovenant.com%2Fblog%2F2012%2F12%2F18%2Fno-title-really%2F\" class=\"twitter-share-button\"  style=\"width:55px;height:22px;background:transparent url('http:\/\/shadowcovenant.com\/blog\/wp-content\/plugins\/wp-tweet-button\/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;\">Tweet<\/a><\/div>","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23,3],"tags":[164,56,166,165],"class_list":["post-836","post","type-post","status-publish","format-standard","hentry","category-development","category-general","tag-indie","tag-lua","tag-run","tag-speed"],"_links":{"self":[{"href":"http:\/\/shadowcovenant.com\/blog\/wp-json\/wp\/v2\/posts\/836","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/shadowcovenant.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/shadowcovenant.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/shadowcovenant.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/shadowcovenant.com\/blog\/wp-json\/wp\/v2\/comments?post=836"}],"version-history":[{"count":0,"href":"http:\/\/shadowcovenant.com\/blog\/wp-json\/wp\/v2\/posts\/836\/revisions"}],"wp:attachment":[{"href":"http:\/\/shadowcovenant.com\/blog\/wp-json\/wp\/v2\/media?parent=836"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/shadowcovenant.com\/blog\/wp-json\/wp\/v2\/categories?post=836"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/shadowcovenant.com\/blog\/wp-json\/wp\/v2\/tags?post=836"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}