webmcp
diff libraries/mondelefant/mondelefant_native.c @ 398:ac9a4e1885da
Dropped compatibility code for Lua 5.1 (assume LUA_VERSION_NUM >= 502)
author | jbe |
---|---|
date | Thu Dec 10 17:27:53 2015 +0100 (2015-12-10) |
parents | 46ba2168693a |
children | ef3201ed67f5 |
line diff
1.1 --- a/libraries/mondelefant/mondelefant_native.c Thu Dec 10 17:23:51 2015 +0100 1.2 +++ b/libraries/mondelefant/mondelefant_native.c Thu Dec 10 17:27:53 2015 +0100 1.3 @@ -721,11 +721,7 @@ 1.4 } 1.5 luaL_pushresult(&keybuf); 1.6 // check, if any characters matched: 1.7 -#if LUA_VERSION_NUM >= 502 1.8 if (lua_rawlen(L, -1)) { 1.9 -#else 1.10 - if (lua_objlen(L, -1)) { 1.11 -#endif 1.12 // if any alpha numeric chars or underscores were found, 1.13 // push them on stack as a Lua string and use them to lookup 1.14 // value from second argument: 1.15 @@ -776,11 +772,7 @@ 1.16 ); 1.17 } 1.18 // iterate over items of sub-structure: 1.19 -#if LUA_VERSION_NUM >= 502 1.20 count = lua_rawlen(L, 5); 1.21 -#else 1.22 - count = lua_objlen(L, 5); 1.23 -#endif 1.24 for (i = 0; i < count; i++) { 1.25 // add seperator, unless this is the first run: 1.26 if (i) { 1.27 @@ -1249,17 +1241,9 @@ 1.28 lua_rawgeti(L, 3, command_idx+1); // raw result at stack position 6 1.29 if (lua_toboolean(L, 6)) { 1.30 lua_getfield(L, 6, "_column_info"); // column_info list at position 7 1.31 -#if LUA_VERSION_NUM >= 502 1.32 cols = lua_rawlen(L, 7); 1.33 -#else 1.34 - cols = lua_objlen(L, 7); 1.35 -#endif 1.36 if (mode == MONDELEFANT_QUERY_MODE_LIST) { 1.37 -#if LUA_VERSION_NUM >= 502 1.38 rows = lua_rawlen(L, 6); 1.39 -#else 1.40 - rows = lua_objlen(L, 6); 1.41 -#endif 1.42 for (row = 0; row < rows; row++) { 1.43 lua_rawgeti(L, 6, row+1); // row at stack position 8 1.44 lua_getfield(L, 8, "_data"); // _data table at stack position 9 1.45 @@ -1396,20 +1380,12 @@ 1.46 lua_settop(L, 2); 1.47 lua_getmetatable(L, 1); // 3 1.48 lua_getfield(L, LUA_REGISTRYINDEX, MONDELEFANT_RESULT_MT_REGKEY); // 4 1.49 -#if LUA_VERSION_NUM >= 502 1.50 luaL_argcheck(L, lua_compare(L, 3, 4, LUA_OPEQ), 1, "not a database result"); 1.51 -#else 1.52 - luaL_argcheck(L, lua_equal(L, 3, 4), 1, "not a database result"); 1.53 -#endif 1.54 // ensure that second argument is a database class (model): 1.55 lua_settop(L, 2); 1.56 lua_getmetatable(L, 2); // 3 1.57 lua_getfield(L, LUA_REGISTRYINDEX, MONDELEFANT_CLASS_MT_REGKEY); // 4 1.58 -#if LUA_VERSION_NUM >= 502 1.59 luaL_argcheck(L, lua_compare(L, 3, 4, LUA_OPEQ), 2, "not a database class"); 1.60 -#else 1.61 - luaL_argcheck(L, lua_equal(L, 3, 4), 2, "not a database class"); 1.62 -#endif 1.63 // set attribute "_class" of result list/object to given class: 1.64 lua_settop(L, 2); 1.65 lua_pushvalue(L, 2); // 3 1.66 @@ -1420,11 +1396,7 @@ 1.67 if (lua_rawequal(L, 3, 4)) { 1.68 int i; 1.69 // set attribute "_class" of all elements to given class: 1.70 -#if LUA_VERSION_NUM >= 502 1.71 for (i=0; i < lua_rawlen(L, 1); i++) { 1.72 -#else 1.73 - for (i=0; i < lua_objlen(L, 1); i++) { 1.74 -#endif 1.75 lua_settop(L, 2); 1.76 lua_rawgeti(L, 1, i+1); // 3 1.77 lua_pushvalue(L, 2); // 4 1.78 @@ -1923,71 +1895,39 @@ 1.79 int luaopen_mondelefant_native(lua_State *L) { 1.80 lua_settop(L, 0); 1.81 lua_newtable(L); // module at stack position 1 1.82 -#if LUA_VERSION_NUM >= 502 1.83 luaL_setfuncs(L, mondelefant_module_functions, 0); 1.84 -#else 1.85 - luaL_register(L, NULL, mondelefant_module_functions); 1.86 -#endif 1.87 1.88 lua_pushvalue(L, 1); // 2 1.89 lua_setfield(L, LUA_REGISTRYINDEX, MONDELEFANT_MODULE_REGKEY); 1.90 1.91 lua_newtable(L); // 2 1.92 // NOTE: only PostgreSQL is supported yet: 1.93 -#if LUA_VERSION_NUM >= 502 1.94 luaL_setfuncs(L, mondelefant_conn_methods, 0); 1.95 -#else 1.96 - luaL_register(L, NULL, mondelefant_conn_methods); 1.97 -#endif 1.98 lua_setfield(L, 1, "postgresql_connection_prototype"); 1.99 lua_newtable(L); // 2 1.100 lua_setfield(L, 1, "connection_prototype"); 1.101 1.102 luaL_newmetatable(L, MONDELEFANT_CONN_MT_REGKEY); // 2 1.103 -#if LUA_VERSION_NUM >= 502 1.104 luaL_setfuncs(L, mondelefant_conn_mt_functions, 0); 1.105 -#else 1.106 - luaL_register(L, NULL, mondelefant_conn_mt_functions); 1.107 -#endif 1.108 lua_settop(L, 1); 1.109 luaL_newmetatable(L, MONDELEFANT_RESULT_MT_REGKEY); // 2 1.110 -#if LUA_VERSION_NUM >= 502 1.111 luaL_setfuncs(L, mondelefant_result_mt_functions, 0); 1.112 -#else 1.113 - luaL_register(L, NULL, mondelefant_result_mt_functions); 1.114 -#endif 1.115 lua_setfield(L, 1, "result_metatable"); 1.116 luaL_newmetatable(L, MONDELEFANT_CLASS_MT_REGKEY); // 2 1.117 -#if LUA_VERSION_NUM >= 502 1.118 luaL_setfuncs(L, mondelefant_class_mt_functions, 0); 1.119 -#else 1.120 - luaL_register(L, NULL, mondelefant_class_mt_functions); 1.121 -#endif 1.122 lua_setfield(L, 1, "class_metatable"); 1.123 1.124 lua_newtable(L); // 2 1.125 -#if LUA_VERSION_NUM >= 502 1.126 luaL_setfuncs(L, mondelefant_class_methods, 0); 1.127 -#else 1.128 - luaL_register(L, NULL, mondelefant_class_methods); 1.129 -#endif 1.130 lua_newtable(L); // 3 1.131 -#if LUA_VERSION_NUM >= 502 1.132 luaL_setfuncs(L, mondelefant_object_methods, 0); 1.133 -#else 1.134 - luaL_register(L, NULL, mondelefant_object_methods); 1.135 -#endif 1.136 lua_setfield(L, 2, "object"); 1.137 lua_newtable(L); // 3 1.138 lua_setfield(L, 2, "object_get"); 1.139 lua_newtable(L); // 3 1.140 lua_setfield(L, 2, "object_set"); 1.141 lua_newtable(L); // 3 1.142 -#if LUA_VERSION_NUM >= 502 1.143 luaL_setfuncs(L, mondelefant_list_methods, 0); 1.144 -#else 1.145 - luaL_register(L, NULL, mondelefant_list_methods); 1.146 -#endif 1.147 lua_setfield(L, 2, "list"); 1.148 lua_newtable(L); // 3 1.149 lua_setfield(L, 2, "references"); 1.150 @@ -1998,17 +1938,9 @@ 1.151 lua_setfield(L, 1, "class_prototype"); 1.152 1.153 luaL_newmetatable(L, MONDELEFANT_ERROROBJECT_MT_REGKEY); // 2 1.154 -#if LUA_VERSION_NUM >= 502 1.155 luaL_setfuncs(L, mondelefant_errorobject_mt_functions, 0); 1.156 -#else 1.157 - luaL_register(L, NULL, mondelefant_errorobject_mt_functions); 1.158 -#endif 1.159 lua_newtable(L); // 3 1.160 -#if LUA_VERSION_NUM >= 502 1.161 luaL_setfuncs(L, mondelefant_errorobject_methods, 0); 1.162 -#else 1.163 - luaL_register(L, NULL, mondelefant_errorobject_methods); 1.164 -#endif 1.165 lua_setfield(L, 2, "__index"); 1.166 lua_setfield(L, 1, "errorobject_metatable"); 1.167