lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> http://bit.ly/17SLWdH
> 
> I'm a kinda new to C please be patient, all support are good, any good
> advice?

Welcome to the world of C bindings for Lua. Here are a few comments:

- I don't see any need for iwi.h.

- luaL_reg is absent in 5.2 and deprecated in 5.1. Use luaL_Reg.

- move the definition of iwi_methods to just before luaopen_iwi.

- although it's a matter of style, I prefer to define local variables
  together with their declarations. For instance:

static int iwi_encode(lua_State *L) {
  double lat  = (double)luaL_checknumber(L, 1);
  double lon  = (double)luaL_checknumber(L, 2);
  unsigned int len  = luaL_checkunsigned(L, 3);
  char *hash = GEOHASH_encode(lat, lon, len);
  lua_pushlstring(L, hash, sizeof(hash));  <-- you need strlen(hash) here
  free(hash);
  return 1;
}

- you need strlen not sizeof in
	lua_pushlstring(L, hash, sizeof(hash));
	lua_pushlstring(L, adj_hash, sizeof(adj_hash));

- use luaL_error instead of lua_pushstring+lua_error in two places:
	lua_pushstring(L, "invalid adjacent constant value");
	lua_error(L);

	lua_pushstring(L, "invalid measure constant value");
	lua_error(L);

- why add const in adj_hash if the API does not use const?
	const char *adj_hash;

-  use 180.0 instead of 180

- why isn't GEOHASH_verify_hash bound to Lua?