switch source tree from k&r to c99
This commit is contained in:
227
src/nhlua.c
227
src/nhlua.c
@@ -14,41 +14,39 @@
|
||||
/* */
|
||||
|
||||
/* lua_CFunction prototypes */
|
||||
static int FDECL(nhl_test, (lua_State *));
|
||||
static int FDECL(nhl_getmap, (lua_State *));
|
||||
static void FDECL(nhl_add_table_entry_bool, (lua_State *, const char *, BOOLEAN_P));
|
||||
static char FDECL(splev_typ2chr, (SCHAR_P));
|
||||
static int FDECL(nhl_gettrap, (lua_State *));
|
||||
static int FDECL(nhl_deltrap, (lua_State *));
|
||||
static int nhl_test(lua_State *);
|
||||
static int nhl_getmap(lua_State *);
|
||||
static void nhl_add_table_entry_bool(lua_State *, const char *, boolean);
|
||||
static char splev_typ2chr(schar);
|
||||
static int nhl_gettrap(lua_State *);
|
||||
static int nhl_deltrap(lua_State *);
|
||||
#if 0
|
||||
static int FDECL(nhl_setmap, (lua_State *));
|
||||
static int nhl_setmap(lua_State *);
|
||||
#endif
|
||||
static int FDECL(nhl_pline, (lua_State *));
|
||||
static int FDECL(nhl_verbalize, (lua_State *));
|
||||
static int FDECL(nhl_menu, (lua_State *));
|
||||
static int FDECL(nhl_getlin, (lua_State *));
|
||||
static int FDECL(nhl_makeplural, (lua_State *));
|
||||
static int FDECL(nhl_makesingular, (lua_State *));
|
||||
static int FDECL(nhl_s_suffix, (lua_State *));
|
||||
static int FDECL(nhl_ing_suffix, (lua_State *));
|
||||
static int FDECL(nhl_an, (lua_State *));
|
||||
static int FDECL(nhl_rn2, (lua_State *));
|
||||
static int FDECL(nhl_random, (lua_State *));
|
||||
static int FDECL(nhl_level_difficulty, (lua_State *));
|
||||
static void FDECL(init_nhc_data, (lua_State *));
|
||||
static int FDECL(nhl_push_anything, (lua_State *, int, void *));
|
||||
static int FDECL(nhl_meta_u_index, (lua_State *));
|
||||
static int FDECL(nhl_meta_u_newindex, (lua_State *));
|
||||
static int FDECL(nhl_u_clear_inventory, (lua_State *));
|
||||
static int FDECL(nhl_u_giveobj, (lua_State *));
|
||||
static void FDECL(init_u_data, (lua_State *));
|
||||
static int FDECL(nhl_set_package_path, (lua_State *, const char *));
|
||||
static int FDECL(traceback_handler, (lua_State *));
|
||||
static int nhl_pline(lua_State *);
|
||||
static int nhl_verbalize(lua_State *);
|
||||
static int nhl_menu(lua_State *);
|
||||
static int nhl_getlin(lua_State *);
|
||||
static int nhl_makeplural(lua_State *);
|
||||
static int nhl_makesingular(lua_State *);
|
||||
static int nhl_s_suffix(lua_State *);
|
||||
static int nhl_ing_suffix(lua_State *);
|
||||
static int nhl_an(lua_State *);
|
||||
static int nhl_rn2(lua_State *);
|
||||
static int nhl_random(lua_State *);
|
||||
static int nhl_level_difficulty(lua_State *);
|
||||
static void init_nhc_data(lua_State *);
|
||||
static int nhl_push_anything(lua_State *, int, void *);
|
||||
static int nhl_meta_u_index(lua_State *);
|
||||
static int nhl_meta_u_newindex(lua_State *);
|
||||
static int nhl_u_clear_inventory(lua_State *);
|
||||
static int nhl_u_giveobj(lua_State *);
|
||||
static void init_u_data(lua_State *);
|
||||
static int nhl_set_package_path(lua_State *, const char *);
|
||||
static int traceback_handler(lua_State *);
|
||||
|
||||
void
|
||||
nhl_error(L, msg)
|
||||
lua_State *L;
|
||||
const char *msg;
|
||||
nhl_error(lua_State *L, const char *msg)
|
||||
{
|
||||
lua_Debug ar;
|
||||
char buf[BUFSZ];
|
||||
@@ -72,8 +70,7 @@ const char *msg;
|
||||
/* Check that parameters are nothing but single table,
|
||||
or if no parameters given, put empty table there */
|
||||
void
|
||||
lcheck_param_table(L)
|
||||
lua_State *L;
|
||||
lcheck_param_table(lua_State *L)
|
||||
{
|
||||
int argc = lua_gettop(L);
|
||||
|
||||
@@ -87,9 +84,7 @@ lua_State *L;
|
||||
}
|
||||
|
||||
schar
|
||||
get_table_mapchr(L, name)
|
||||
lua_State *L;
|
||||
const char *name;
|
||||
get_table_mapchr(lua_State *L, const char *name)
|
||||
{
|
||||
char *ter;
|
||||
xchar typ;
|
||||
@@ -104,10 +99,7 @@ const char *name;
|
||||
}
|
||||
|
||||
schar
|
||||
get_table_mapchr_opt(L, name, defval)
|
||||
lua_State *L;
|
||||
const char *name;
|
||||
schar defval;
|
||||
get_table_mapchr_opt(lua_State *L, const char *name, schar defval)
|
||||
{
|
||||
char *ter;
|
||||
xchar typ;
|
||||
@@ -125,10 +117,7 @@ schar defval;
|
||||
}
|
||||
|
||||
void
|
||||
nhl_add_table_entry_int(L, name, value)
|
||||
lua_State *L;
|
||||
const char *name;
|
||||
int value;
|
||||
nhl_add_table_entry_int(lua_State *L, const char *name, int value)
|
||||
{
|
||||
lua_pushstring(L, name);
|
||||
lua_pushinteger(L, value);
|
||||
@@ -136,10 +125,7 @@ int value;
|
||||
}
|
||||
|
||||
void
|
||||
nhl_add_table_entry_char(L, name, value)
|
||||
lua_State *L;
|
||||
const char *name;
|
||||
char value;
|
||||
nhl_add_table_entry_char(lua_State *L, const char *name, char value)
|
||||
{
|
||||
char buf[2];
|
||||
Sprintf(buf, "%c", value);
|
||||
@@ -149,20 +135,14 @@ char value;
|
||||
}
|
||||
|
||||
void
|
||||
nhl_add_table_entry_str(L, name, value)
|
||||
lua_State *L;
|
||||
const char *name;
|
||||
const char *value;
|
||||
nhl_add_table_entry_str(lua_State *L, const char *name, const char *value)
|
||||
{
|
||||
lua_pushstring(L, name);
|
||||
lua_pushstring(L, value);
|
||||
lua_rawset(L, -3);
|
||||
}
|
||||
void
|
||||
nhl_add_table_entry_bool(L, name, value)
|
||||
lua_State *L;
|
||||
const char *name;
|
||||
boolean value;
|
||||
nhl_add_table_entry_bool(lua_State *L, const char *name, boolean value)
|
||||
{
|
||||
lua_pushstring(L, name);
|
||||
lua_pushboolean(L, value);
|
||||
@@ -212,8 +192,7 @@ const struct {
|
||||
};
|
||||
|
||||
schar
|
||||
splev_chr2typ(c)
|
||||
char c;
|
||||
splev_chr2typ(char c)
|
||||
{
|
||||
int i;
|
||||
|
||||
@@ -224,8 +203,7 @@ char c;
|
||||
}
|
||||
|
||||
schar
|
||||
check_mapchr(s)
|
||||
const char *s;
|
||||
check_mapchr(const char *s)
|
||||
{
|
||||
if (s && strlen(s) == 1)
|
||||
return splev_chr2typ(s[0]);
|
||||
@@ -233,8 +211,7 @@ const char *s;
|
||||
}
|
||||
|
||||
static char
|
||||
splev_typ2chr(typ)
|
||||
schar typ;
|
||||
splev_typ2chr(schar typ)
|
||||
{
|
||||
int i;
|
||||
|
||||
@@ -246,8 +223,7 @@ schar typ;
|
||||
|
||||
/* local t = gettrap(x,y); */
|
||||
static int
|
||||
nhl_gettrap(L)
|
||||
lua_State *L;
|
||||
nhl_gettrap(lua_State *L)
|
||||
{
|
||||
int argc = lua_gettop(L);
|
||||
|
||||
@@ -295,8 +271,7 @@ lua_State *L;
|
||||
|
||||
/* deltrap(x,y); */
|
||||
static int
|
||||
nhl_deltrap(L)
|
||||
lua_State *L;
|
||||
nhl_deltrap(lua_State *L)
|
||||
{
|
||||
int argc = lua_gettop(L);
|
||||
|
||||
@@ -316,8 +291,7 @@ lua_State *L;
|
||||
|
||||
/* local loc = getmap(x,y) */
|
||||
static int
|
||||
nhl_getmap(L)
|
||||
lua_State *L;
|
||||
nhl_getmap(lua_State *L)
|
||||
{
|
||||
int argc = lua_gettop(L);
|
||||
|
||||
@@ -408,8 +382,7 @@ lua_State *L;
|
||||
|
||||
/* pline("It hits!") */
|
||||
static int
|
||||
nhl_pline(L)
|
||||
lua_State *L;
|
||||
nhl_pline(lua_State *L)
|
||||
{
|
||||
int argc = lua_gettop(L);
|
||||
|
||||
@@ -423,8 +396,7 @@ lua_State *L;
|
||||
|
||||
/* verbalize("Fool!") */
|
||||
static int
|
||||
nhl_verbalize(L)
|
||||
lua_State *L;
|
||||
nhl_verbalize(lua_State *L)
|
||||
{
|
||||
int argc = lua_gettop(L);
|
||||
|
||||
@@ -440,8 +412,7 @@ lua_State *L;
|
||||
str = getlin("What do you want to call this dungeon level?");
|
||||
*/
|
||||
static int
|
||||
nhl_getlin(L)
|
||||
lua_State *L;
|
||||
nhl_getlin(lua_State *L)
|
||||
{
|
||||
int argc = lua_gettop(L);
|
||||
|
||||
@@ -465,8 +436,7 @@ lua_State *L;
|
||||
selected = menu("prompt", default, pickX,
|
||||
{ {key:"a", text:"option a"}, {key:"b", text:"option b"}, ... } ) */
|
||||
static int
|
||||
nhl_menu(L)
|
||||
lua_State *L;
|
||||
nhl_menu(lua_State *L)
|
||||
{
|
||||
static const char *const pickX[] = {"none", "one", "any"}; /* PICK_x */
|
||||
int argc = lua_gettop(L);
|
||||
@@ -552,8 +522,7 @@ lua_State *L;
|
||||
|
||||
/* makeplural("zorkmid") */
|
||||
static int
|
||||
nhl_makeplural(L)
|
||||
lua_State *L;
|
||||
nhl_makeplural(lua_State *L)
|
||||
{
|
||||
int argc = lua_gettop(L);
|
||||
|
||||
@@ -567,8 +536,7 @@ lua_State *L;
|
||||
|
||||
/* makesingular("zorkmids") */
|
||||
static int
|
||||
nhl_makesingular(L)
|
||||
lua_State *L;
|
||||
nhl_makesingular(lua_State *L)
|
||||
{
|
||||
int argc = lua_gettop(L);
|
||||
|
||||
@@ -582,8 +550,7 @@ lua_State *L;
|
||||
|
||||
/* s_suffix("foo") */
|
||||
static int
|
||||
nhl_s_suffix(L)
|
||||
lua_State *L;
|
||||
nhl_s_suffix(lua_State *L)
|
||||
{
|
||||
int argc = lua_gettop(L);
|
||||
|
||||
@@ -597,8 +564,7 @@ lua_State *L;
|
||||
|
||||
/* ing_suffix("foo") */
|
||||
static int
|
||||
nhl_ing_suffix(L)
|
||||
lua_State *L;
|
||||
nhl_ing_suffix(lua_State *L)
|
||||
{
|
||||
int argc = lua_gettop(L);
|
||||
|
||||
@@ -612,8 +578,7 @@ lua_State *L;
|
||||
|
||||
/* an("foo") */
|
||||
static int
|
||||
nhl_an(L)
|
||||
lua_State *L;
|
||||
nhl_an(lua_State *L)
|
||||
{
|
||||
int argc = lua_gettop(L);
|
||||
|
||||
@@ -627,8 +592,7 @@ lua_State *L;
|
||||
|
||||
/* rn2(10) */
|
||||
static int
|
||||
nhl_rn2(L)
|
||||
lua_State *L;
|
||||
nhl_rn2(lua_State *L)
|
||||
{
|
||||
int argc = lua_gettop(L);
|
||||
|
||||
@@ -643,8 +607,7 @@ lua_State *L;
|
||||
/* random(10); -- is the same as rn2(10); */
|
||||
/* random(5,8); -- same as 5 + rn2(8); */
|
||||
static int
|
||||
nhl_random(L)
|
||||
lua_State *L;
|
||||
nhl_random(lua_State *L)
|
||||
{
|
||||
int argc = lua_gettop(L);
|
||||
|
||||
@@ -660,8 +623,7 @@ lua_State *L;
|
||||
|
||||
/* level_difficulty() */
|
||||
static int
|
||||
nhl_level_difficulty(L)
|
||||
lua_State *L;
|
||||
nhl_level_difficulty(lua_State *L)
|
||||
{
|
||||
int argc = lua_gettop(L);
|
||||
if (argc == 0) {
|
||||
@@ -675,9 +637,7 @@ lua_State *L;
|
||||
|
||||
/* get mandatory integer value from table */
|
||||
int
|
||||
get_table_int(L, name)
|
||||
lua_State *L;
|
||||
const char *name;
|
||||
get_table_int(lua_State *L, const char *name)
|
||||
{
|
||||
int ret;
|
||||
|
||||
@@ -689,10 +649,7 @@ const char *name;
|
||||
|
||||
/* get optional integer value from table */
|
||||
int
|
||||
get_table_int_opt(L, name, defval)
|
||||
lua_State *L;
|
||||
const char *name;
|
||||
int defval;
|
||||
get_table_int_opt(lua_State *L, const char *name, int defval)
|
||||
{
|
||||
int ret = defval;
|
||||
|
||||
@@ -705,9 +662,7 @@ int defval;
|
||||
}
|
||||
|
||||
char *
|
||||
get_table_str(L, name)
|
||||
lua_State *L;
|
||||
const char *name;
|
||||
get_table_str(lua_State *L, const char *name)
|
||||
{
|
||||
char *ret;
|
||||
|
||||
@@ -720,10 +675,7 @@ const char *name;
|
||||
/* get optional string value from table.
|
||||
return value must be freed by caller. */
|
||||
char *
|
||||
get_table_str_opt(L, name, defval)
|
||||
lua_State *L;
|
||||
const char *name;
|
||||
char *defval;
|
||||
get_table_str_opt(lua_State *L, const char *name, char *defval)
|
||||
{
|
||||
const char *ret;
|
||||
|
||||
@@ -738,9 +690,7 @@ char *defval;
|
||||
}
|
||||
|
||||
int
|
||||
get_table_boolean(L, name)
|
||||
lua_State *L;
|
||||
const char *name;
|
||||
get_table_boolean(lua_State *L, const char *name)
|
||||
{
|
||||
static const char *const boolstr[] = {
|
||||
"true", "false", "yes", "no", NULL
|
||||
@@ -768,10 +718,7 @@ const char *name;
|
||||
}
|
||||
|
||||
int
|
||||
get_table_boolean_opt(L, name, defval)
|
||||
lua_State *L;
|
||||
const char *name;
|
||||
int defval;
|
||||
get_table_boolean_opt(lua_State *L, const char *name, int defval)
|
||||
{
|
||||
int ret = defval;
|
||||
|
||||
@@ -784,12 +731,12 @@ int defval;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* opts[] is a null-terminated list */
|
||||
int
|
||||
get_table_option(L, name, defval, opts)
|
||||
lua_State *L;
|
||||
const char *name;
|
||||
const char *defval;
|
||||
const char *const opts[]; /* NULL-terminated list */
|
||||
get_table_option(lua_State *L,
|
||||
const char *name,
|
||||
const char *defval,
|
||||
const char *const opts[])
|
||||
{
|
||||
int ret;
|
||||
|
||||
@@ -803,8 +750,7 @@ const char *const opts[]; /* NULL-terminated list */
|
||||
test( { x = 123, y = 456 } );
|
||||
*/
|
||||
static int
|
||||
nhl_test(L)
|
||||
lua_State *L;
|
||||
nhl_test(lua_State *L)
|
||||
{
|
||||
int x, y;
|
||||
char *name, Player[] = "Player";
|
||||
@@ -862,8 +808,7 @@ static const struct {
|
||||
|
||||
/* register and init the constants table */
|
||||
static void
|
||||
init_nhc_data(L)
|
||||
lua_State *L;
|
||||
init_nhc_data(lua_State *L)
|
||||
{
|
||||
int i;
|
||||
|
||||
@@ -879,10 +824,7 @@ lua_State *L;
|
||||
}
|
||||
|
||||
static int
|
||||
nhl_push_anything(L, anytype, src)
|
||||
lua_State *L;
|
||||
int anytype;
|
||||
void *src;
|
||||
nhl_push_anything(lua_State *L, int anytype, void *src)
|
||||
{
|
||||
anything any = cg.zeroany;
|
||||
|
||||
@@ -901,8 +843,7 @@ void *src;
|
||||
}
|
||||
|
||||
static int
|
||||
nhl_meta_u_index(L)
|
||||
lua_State *L;
|
||||
nhl_meta_u_index(lua_State *L)
|
||||
{
|
||||
static const struct {
|
||||
const char *name;
|
||||
@@ -956,16 +897,14 @@ lua_State *L;
|
||||
}
|
||||
|
||||
static int
|
||||
nhl_meta_u_newindex(L)
|
||||
lua_State *L;
|
||||
nhl_meta_u_newindex(lua_State *L)
|
||||
{
|
||||
nhl_error(L, "Cannot set u table values");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
nhl_u_clear_inventory(L)
|
||||
lua_State *L UNUSED;
|
||||
nhl_u_clear_inventory(lua_State *L UNUSED)
|
||||
{
|
||||
while (g.invent)
|
||||
useupall(g.invent);
|
||||
@@ -975,8 +914,7 @@ lua_State *L UNUSED;
|
||||
/* Put object into player's inventory */
|
||||
/* u.giveobj(obj.new("rock")); */
|
||||
static int
|
||||
nhl_u_giveobj(L)
|
||||
lua_State *L;
|
||||
nhl_u_giveobj(lua_State *L)
|
||||
{
|
||||
return nhl_obj_u_giveobj(L);
|
||||
}
|
||||
@@ -988,8 +926,7 @@ static const struct luaL_Reg nhl_u_functions[] = {
|
||||
};
|
||||
|
||||
static void
|
||||
init_u_data(L)
|
||||
lua_State *L;
|
||||
init_u_data(lua_State *L)
|
||||
{
|
||||
lua_newtable(L);
|
||||
luaL_setfuncs(L, nhl_u_functions, 0);
|
||||
@@ -1003,9 +940,7 @@ lua_State *L;
|
||||
}
|
||||
|
||||
static int
|
||||
nhl_set_package_path(L, path)
|
||||
lua_State *L;
|
||||
const char *path;
|
||||
nhl_set_package_path(lua_State *L, const char *path)
|
||||
{
|
||||
lua_getglobal(L, "package");
|
||||
lua_pushstring(L, path);
|
||||
@@ -1015,8 +950,7 @@ const char *path;
|
||||
}
|
||||
|
||||
static int
|
||||
traceback_handler(L)
|
||||
lua_State *L;
|
||||
traceback_handler(lua_State *L)
|
||||
{
|
||||
luaL_traceback(L, L, lua_tostring(L, 1), 0);
|
||||
/* TODO: call impossible() if fuzzing? */
|
||||
@@ -1026,9 +960,7 @@ lua_State *L;
|
||||
/* read lua code/data from a dlb module or an external file
|
||||
into a string buffer and feed that to lua */
|
||||
boolean
|
||||
nhl_loadlua(L, fname)
|
||||
lua_State *L;
|
||||
const char *fname;
|
||||
nhl_loadlua(lua_State *L, const char *fname)
|
||||
{
|
||||
#define LOADCHUNKSIZE (1L << 13) /* 8K */
|
||||
boolean ret = TRUE;
|
||||
@@ -1138,7 +1070,7 @@ const char *fname;
|
||||
}
|
||||
|
||||
lua_State *
|
||||
nhl_init()
|
||||
nhl_init(void)
|
||||
{
|
||||
lua_State *L = luaL_newstate();
|
||||
|
||||
@@ -1170,8 +1102,7 @@ nhl_init()
|
||||
}
|
||||
|
||||
boolean
|
||||
load_lua(name)
|
||||
const char *name;
|
||||
load_lua(const char *name)
|
||||
{
|
||||
boolean ret = TRUE;
|
||||
lua_State *L = nhl_init();
|
||||
@@ -1193,7 +1124,7 @@ const char *name;
|
||||
}
|
||||
|
||||
const char *
|
||||
get_lua_version()
|
||||
get_lua_version(void)
|
||||
{
|
||||
size_t len = (size_t) 0;
|
||||
const char *vs = (const char *) 0;
|
||||
|
||||
Reference in New Issue
Block a user