Bourne-again Blog

Random programming and other rants.

Cross-language constants May 25, 2008

Filed under: Programming — criminy @ 10:40 pm
Tags: , ,

Original post: October 18, 2006

This CPP macro allows me to take a #define’d constant and register it with Lua.


/* leet hax but remember to always pass a null buffer! */
#define RegisterConstant(L,buffer,c) \
{ \
buffer = malloc(strlen(#c “=”)+(sizeof(int)/2*3) + 1); \
sprintf(buffer,#c “=%i”,c); \
luaL_loadstring(L,buffer); \
lua_pcall(L,0,-1,0); \
free(buffer); buffer = NULL; \
}

I’ve used this with allegro by processing keyboard.h through a script and throwing the output file in a..would you call it a singleton header? Probably not.

cat /usr/include/allegro/keyboard.h | grep “\#define KEY_” | awk ‘{print “RegisterConstant(L,buf,” $1 “);”}’ >> constants.h
—-
cat constants.h | tail -n 4
RegisterConstant(L,buf,KEY_SCRLOCK);
RegisterConstant(L,buf,KEY_NUMLOCK);
RegisterConstant(L,buf,KEY_CAPSLOCK);
RegisterConstant(L,buf,KEY_MAX);

Now KEY_MAX, KEY_SCRLOCK, and everything else in constants.h are valid variables in Lua. I just #include “constants.h” in a lua setup function (where L and buf are declared).
My Main main(), which will probably replace the main in breakout tutorial when I rewrite it =\:


int main(int argc,char * argv[]) /*{+{*/ {
do(g_status = g_loops[g_status]());
while(g_status LESS_THAN STATUS_EXIT_LOOP);
return(gshutdown());
}END_OF_MAIN()/*}_}*/

 

Content wipe, Oops

Filed under: Programming — criminy @ 10:40 pm

I decided to do a content wipe for restarting this blog, them immediately realized my past page-views had spiked at some point, meaning my past posts were read by someone. In fact, I had quite large spikes which I think mean something. I have no hard-copy but google cached them. I’ll put up what I can get, which doesn’t look like much.

As I think about certain posts, and what I was doing, there were some themes I noticed:

  • C/C++, mainly C.
  • Allegro
  • XFCE/Thunar
  • perl
  • flock
  • I said things as if they were important
  • I may have been using Arch Linux back then

Times change, it’s weak, but they do. I tried convincing a bunch of people just that, but I was met with silly ideals and pretensions about web design. I won’t name the site, but I’ll say change is good.

Then -> Now
Vi -> Emacs
XFCE -> Gnome
Arch -> Ubuntu
Jobless -> Employed
C/(C with classes)/Perl -> Modern C++/Scheme

It is odd to dwell on the past year and realize what change is.