I have, what I believe to be, Slash's random equipment code in my source. I've ported the name and effects part out to Lua and call the functions via a modified version of the call_va function found in the PiL book.
After all the effects are added it runs the following lines to add the random names to the items:
The name and buf variables are initialized as
The name variable is passed byref to Lua which generates the name and passes it back to C, which then is formatted into a buffer variable and applied to the object.
What I'm wondering is, could I skip the STRFREE and str_alloc calls and just pass the name, short_descr and description to Lua and set them there, or would there be some kind of a mess from not freeing the strings first?
I'm wanting to avoid using the buf and name variables and any unnecessary calls to STRFREE and str_alloc.
After all the effects are added it runs the following lines to add the random names to the items:
sprintf( buf, obj->short_descr, name );
STRFREE( obj->short_descr );
obj->short_descr = str_alloc( buf );
sprintf( buf, "%s", obj->short_descr );
STRFREE( obj->name );
obj->name = str_alloc( buf );
STRFREE( obj->description );
sprintf( buf, "%s lies here.", capitalize( obj->short_descr ) );
obj->description = str_alloc( buf );
The name and buf variables are initialized as
char *name = "[random]";
char buf[MAX_STRING_LENGTH];The name variable is passed byref to Lua which generates the name and passes it back to C, which then is formatted into a buffer variable and applied to the object.
What I'm wondering is, could I skip the STRFREE and str_alloc calls and just pass the name, short_descr and description to Lua and set them there, or would there be some kind of a mess from not freeing the strings first?
I'm wanting to avoid using the buf and name variables and any unnecessary calls to STRFREE and str_alloc.