Fix. EOL in source [ci skip]

This commit is contained in:
Alexey Melnichuk 2015-06-15 10:29:17 +04:00
parent d85529586b
commit 53fd80bd9b
2 changed files with 215 additions and 215 deletions

View File

@ -1,182 +1,182 @@
/****************************************************************************** /******************************************************************************
* Author: Alexey Melnichuk <mimir@newmail.ru> * Author: Alexey Melnichuk <mimir@newmail.ru>
* *
* Copyright (C) 2014 Alexey Melnichuk <mimir@newmail.ru> * Copyright (C) 2014 Alexey Melnichuk <mimir@newmail.ru>
* *
* Licensed according to the included 'LICENSE' document * Licensed according to the included 'LICENSE' document
* *
* This file is part of lua-lcurl library. * This file is part of lua-lcurl library.
******************************************************************************/ ******************************************************************************/
#include "l52util.h" #include "l52util.h"
#include <memory.h> #include <memory.h>
#include <string.h> /* for memset */ #include <string.h> /* for memset */
#include <assert.h> #include <assert.h>
#if LUA_VERSION_NUM >= 502 #if LUA_VERSION_NUM >= 502
int luaL_typerror (lua_State *L, int narg, const char *tname) { int luaL_typerror (lua_State *L, int narg, const char *tname) {
const char *msg = lua_pushfstring(L, "%s expected, got %s", tname, const char *msg = lua_pushfstring(L, "%s expected, got %s", tname,
luaL_typename(L, narg)); luaL_typename(L, narg));
return luaL_argerror(L, narg, msg); return luaL_argerror(L, narg, msg);
} }
#ifndef luaL_register #ifndef luaL_register
void luaL_register (lua_State *L, const char *libname, const luaL_Reg *l){ void luaL_register (lua_State *L, const char *libname, const luaL_Reg *l){
if(libname) lua_newtable(L); if(libname) lua_newtable(L);
luaL_setfuncs(L, l, 0); luaL_setfuncs(L, l, 0);
} }
#endif #endif
#else #else
void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup){ void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup){
luaL_checkstack(L, nup, "too many upvalues"); luaL_checkstack(L, nup, "too many upvalues");
for (; l->name != NULL; l++) { /* fill the table with given functions */ for (; l->name != NULL; l++) { /* fill the table with given functions */
int i; int i;
for (i = 0; i < nup; i++) /* copy upvalues to the top */ for (i = 0; i < nup; i++) /* copy upvalues to the top */
lua_pushvalue(L, -nup); lua_pushvalue(L, -nup);
lua_pushcclosure(L, l->func, nup); /* closure with those upvalues */ lua_pushcclosure(L, l->func, nup); /* closure with those upvalues */
lua_setfield(L, -(nup + 2), l->name); lua_setfield(L, -(nup + 2), l->name);
} }
lua_pop(L, nup); /* remove upvalues */ lua_pop(L, nup); /* remove upvalues */
} }
void lua_rawgetp(lua_State *L, int index, const void *p){ void lua_rawgetp(lua_State *L, int index, const void *p){
index = lua_absindex(L, index); index = lua_absindex(L, index);
lua_pushlightuserdata(L, (void *)p); lua_pushlightuserdata(L, (void *)p);
lua_rawget(L, index); lua_rawget(L, index);
} }
void lua_rawsetp (lua_State *L, int index, const void *p){ void lua_rawsetp (lua_State *L, int index, const void *p){
index = lua_absindex(L, index); index = lua_absindex(L, index);
lua_pushlightuserdata(L, (void *)p); lua_pushlightuserdata(L, (void *)p);
lua_insert(L, -2); lua_insert(L, -2);
lua_rawset(L, index); lua_rawset(L, index);
} }
int luaL_getmetafield (lua_State *L, int obj, const char *event) { int luaL_getmetafield (lua_State *L, int obj, const char *event) {
if (!lua_getmetatable(L, obj)) /* no metatable? */ if (!lua_getmetatable(L, obj)) /* no metatable? */
return 0; return 0;
lua_pushstring(L, event); lua_pushstring(L, event);
lua_rawget(L, -2); lua_rawget(L, -2);
if (lua_isnil(L, -1)) { if (lua_isnil(L, -1)) {
lua_pop(L, 2); /* remove metatable and metafield */ lua_pop(L, 2); /* remove metatable and metafield */
return 0; return 0;
} }
else { else {
lua_remove(L, -2); /* remove only metatable */ lua_remove(L, -2); /* remove only metatable */
return 1; return 1;
} }
} }
int luaL_callmeta (lua_State *L, int obj, const char *event) { int luaL_callmeta (lua_State *L, int obj, const char *event) {
obj = lua_absindex(L, obj); obj = lua_absindex(L, obj);
if (!luaL_getmetafield(L, obj, event)) /* no metafield? */ if (!luaL_getmetafield(L, obj, event)) /* no metafield? */
return 0; return 0;
lua_pushvalue(L, obj); lua_pushvalue(L, obj);
lua_call(L, 1, 1); lua_call(L, 1, 1);
return 1; return 1;
} }
#endif #endif
int lutil_newmetatablep (lua_State *L, const void *p) { int lutil_newmetatablep (lua_State *L, const void *p) {
lua_rawgetp(L, LUA_REGISTRYINDEX, p); lua_rawgetp(L, LUA_REGISTRYINDEX, p);
if (!lua_isnil(L, -1)) /* name already in use? */ if (!lua_isnil(L, -1)) /* name already in use? */
return 0; /* leave previous value on top, but return 0 */ return 0; /* leave previous value on top, but return 0 */
lua_pop(L, 1); lua_pop(L, 1);
lua_newtable(L); /* create metatable */ lua_newtable(L); /* create metatable */
lua_pushvalue(L, -1); /* duplicate metatable to set*/ lua_pushvalue(L, -1); /* duplicate metatable to set*/
lua_rawsetp(L, LUA_REGISTRYINDEX, p); lua_rawsetp(L, LUA_REGISTRYINDEX, p);
return 1; return 1;
} }
void lutil_getmetatablep (lua_State *L, const void *p) { void lutil_getmetatablep (lua_State *L, const void *p) {
lua_rawgetp(L, LUA_REGISTRYINDEX, p); lua_rawgetp(L, LUA_REGISTRYINDEX, p);
} }
void lutil_setmetatablep (lua_State *L, const void *p) { void lutil_setmetatablep (lua_State *L, const void *p) {
lutil_getmetatablep(L, p); lutil_getmetatablep(L, p);
assert(lua_istable(L,-1)); assert(lua_istable(L,-1));
lua_setmetatable (L, -2); lua_setmetatable (L, -2);
} }
int lutil_isudatap (lua_State *L, int ud, const void *p) { int lutil_isudatap (lua_State *L, int ud, const void *p) {
if (lua_isuserdata(L, ud)){ if (lua_isuserdata(L, ud)){
if (lua_getmetatable(L, ud)) { /* does it have a metatable? */ if (lua_getmetatable(L, ud)) { /* does it have a metatable? */
int res; int res;
lutil_getmetatablep(L,p); /* get correct metatable */ lutil_getmetatablep(L,p); /* get correct metatable */
res = lua_rawequal(L, -1, -2); /* does it have the correct mt? */ res = lua_rawequal(L, -1, -2); /* does it have the correct mt? */
lua_pop(L, 2); /* remove both metatables */ lua_pop(L, 2); /* remove both metatables */
return res; return res;
} }
} }
return 0; return 0;
} }
void *lutil_checkudatap (lua_State *L, int ud, const void *p) { void *lutil_checkudatap (lua_State *L, int ud, const void *p) {
void *up = lua_touserdata(L, ud); void *up = lua_touserdata(L, ud);
if (up != NULL) { /* value is a userdata? */ if (up != NULL) { /* value is a userdata? */
if (lua_getmetatable(L, ud)) { /* does it have a metatable? */ if (lua_getmetatable(L, ud)) { /* does it have a metatable? */
lutil_getmetatablep(L,p); /* get correct metatable */ lutil_getmetatablep(L,p); /* get correct metatable */
if (lua_rawequal(L, -1, -2)) { /* does it have the correct mt? */ if (lua_rawequal(L, -1, -2)) { /* does it have the correct mt? */
lua_pop(L, 2); /* remove both metatables */ lua_pop(L, 2); /* remove both metatables */
return up; return up;
} }
} }
} }
luaL_typerror(L, ud, p); /* else error */ luaL_typerror(L, ud, p); /* else error */
return NULL; /* to avoid warnings */ return NULL; /* to avoid warnings */
} }
int lutil_createmetap (lua_State *L, const void *p, const luaL_Reg *methods, int nup) { int lutil_createmetap (lua_State *L, const void *p, const luaL_Reg *methods, int nup) {
if (!lutil_newmetatablep(L, p)){ if (!lutil_newmetatablep(L, p)){
lua_insert(L, -1 - nup); /* move mt prior upvalues */ lua_insert(L, -1 - nup); /* move mt prior upvalues */
return 0; return 0;
} }
lua_insert(L, -1 - nup); /* move mt prior upvalues */ lua_insert(L, -1 - nup); /* move mt prior upvalues */
luaL_setfuncs (L, methods, nup); /* define methods */ luaL_setfuncs (L, methods, nup); /* define methods */
lua_pushliteral (L, "__index"); /* define metamethods */ lua_pushliteral (L, "__index"); /* define metamethods */
lua_pushvalue (L, -2); lua_pushvalue (L, -2);
lua_settable (L, -3); lua_settable (L, -3);
return 1; return 1;
} }
void *lutil_newudatap_impl(lua_State *L, size_t size, const void *p){ void *lutil_newudatap_impl(lua_State *L, size_t size, const void *p){
void *obj = lua_newuserdata (L, size); void *obj = lua_newuserdata (L, size);
memset(obj, 0, size); memset(obj, 0, size);
lutil_setmetatablep(L, p); lutil_setmetatablep(L, p);
return obj; return obj;
} }
void lutil_pushint64(lua_State *L, int64_t v){ void lutil_pushint64(lua_State *L, int64_t v){
if(sizeof(lua_Integer) >= sizeof(int64_t)){ if(sizeof(lua_Integer) >= sizeof(int64_t)){
lua_pushinteger(L, (lua_Integer)v); lua_pushinteger(L, (lua_Integer)v);
return; return;
} }
lua_pushnumber(L, (lua_Number)v); lua_pushnumber(L, (lua_Number)v);
} }
int64_t lutil_checkint64(lua_State *L, int idx){ int64_t lutil_checkint64(lua_State *L, int idx){
if(sizeof(lua_Integer) >= sizeof(int64_t)) if(sizeof(lua_Integer) >= sizeof(int64_t))
return luaL_checkinteger(L, idx); return luaL_checkinteger(L, idx);
return (int64_t)luaL_checknumber(L, idx); return (int64_t)luaL_checknumber(L, idx);
} }
int64_t lutil_optint64(lua_State *L, int idx, int64_t v){ int64_t lutil_optint64(lua_State *L, int idx, int64_t v){
if(sizeof(lua_Integer) >= sizeof(int64_t)) if(sizeof(lua_Integer) >= sizeof(int64_t))
return luaL_optinteger(L, idx, v); return luaL_optinteger(L, idx, v);
return (int64_t)luaL_optnumber(L, idx, v); return (int64_t)luaL_optnumber(L, idx, v);
} }
void lutil_pushnvalues(lua_State *L, int n){ void lutil_pushnvalues(lua_State *L, int n){
for(;n;--n) lua_pushvalue(L, -n); for(;n;--n) lua_pushvalue(L, -n);
} }

View File

@ -1,33 +1,33 @@
/****************************************************************************** /******************************************************************************
* Author: Alexey Melnichuk <mimir@newmail.ru> * Author: Alexey Melnichuk <mimir@newmail.ru>
* *
* Copyright (C) 2014 Alexey Melnichuk <mimir@newmail.ru> * Copyright (C) 2014 Alexey Melnichuk <mimir@newmail.ru>
* *
* Licensed according to the included 'LICENSE' document * Licensed according to the included 'LICENSE' document
* *
* This file is part of lua-lcurl library. * This file is part of lua-lcurl library.
******************************************************************************/ ******************************************************************************/
#ifndef _LCERROR_H_ #ifndef _LCERROR_H_
#define _LCERROR_H_ #define _LCERROR_H_
#include "lcurl.h" #include "lcurl.h"
#define LCURL_ERROR_CURL 1 #define LCURL_ERROR_CURL 1
#define LCURL_ERROR_EASY 1 #define LCURL_ERROR_EASY 1
#define LCURL_ERROR_MULTI 2 #define LCURL_ERROR_MULTI 2
#define LCURL_ERROR_SHARE 3 #define LCURL_ERROR_SHARE 3
#define LCURL_ERROR_FORM 4 #define LCURL_ERROR_FORM 4
#define LCURL_ERROR_RETURN 1 #define LCURL_ERROR_RETURN 1
#define LCURL_ERROR_RAISE 2 #define LCURL_ERROR_RAISE 2
int lcurl_fail(lua_State *L, int error_type, int code); int lcurl_fail(lua_State *L, int error_type, int code);
int lcurl_fail_ex(lua_State *L, int mode, int error_type, int code); int lcurl_fail_ex(lua_State *L, int mode, int error_type, int code);
int lcurl_error_new(lua_State *L); int lcurl_error_new(lua_State *L);
void lcurl_error_initlib(lua_State *L, int nup); void lcurl_error_initlib(lua_State *L, int nup);
#endif #endif