This is from SMAUG 1.4a.
I've been working with the Lua code and expanding it quite a bit to include bits and pieces of the various data structures, tables and functions so that they can be accessed in the Lua scripting environment. I was attempting to get the AFFECT_DATA data into a Lua table but the bitvectors is another struct inside the struct and it's giving me some troubles.
This is what I have in mud.h:
typedef struct extended_bitvector EXT_BV;
#define XBI 4 /* integers in an extended bitvector */
struct extended_bitvector
{
unsigned int bits[XBI];
};
struct affect_data
{
AFFECT_DATA * next;
AFFECT_DATA * prev;
sh_int type;
int duration;
sh_int location;
int modifier;
EXT_BV bitvector;
};
And this is what I have for lua_scripting.c:
#define AFFECT_NUM_ITEM(arg) \
if(paf->arg) \
{ \
lua_pushnumber(L, paf->arg); \
lua_setfield(L, -2, #arg); \
}
static int L_pget_affect(lua_State *L)
{
AFFECT_DATA *paf;
SKILLTYPE *skill;
int count = 0;
/* get target's name */
CHAR_DATA * target = L_find_character(L);
if(!target) return 0;
lua_newtable(L);
for ( paf = target->first_affect; paf; paf = paf->next )
{
if ( (skill=get_skilltype(paf->type)) != NULL )
{
lua_newtable(L);
AFFECT_NUM_ITEM(type);
AFFECT_NUM_ITEM(location);
AFFECT_NUM_ITEM(duration);
AFFECT_NUM_ITEM(modifier);
count++;
char * buf[25];
sprintf(buf, "affect_%d", count);
lua_setfield (L, -2, (const char *)buf);
}
}
return 1;
}
Any time I've tried to access the bitvector I get compile errors "error: used struct type value where scalar is required"
I've tried using something like this:
#define AFFECT_STR_ITEM(arg) \
if(paf->arg) \
{ \
lua_pushstring(L, print_bitvector(*paf->bitvector));\
lua_setfield(L, -2, #arg); \
}
then using
AFFECT_STR_ITEM(bitvector);
inside the function, but the compiler doesn't like that. In fact, it hasn't like anything I've tried to access the bitvector.
Any suggestions? |