From adf6cafdc6a8dcb2453ca1204912d796db1263d0 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Thu, 5 Apr 2018 19:10:56 +0000 Subject: Fixing some errors and warnings in lua-winreg Unified line endings --- .../lua/src/modules/lua-winreg/src/lua_int64.h | 6 +++++- .../lua/src/modules/lua-winreg/src/lua_mtutil.h | 2 +- 3rdparty/lua/src/modules/lua-winreg/src/winreg.c | 24 ++++++++++++++++++---- .../lua/src/modules/lua-winreg/test/test_5_1_5.lua | 16 +++++++-------- 3rdparty/lua/src/modules/winreg.h | 3 ++- 5 files changed, 36 insertions(+), 15 deletions(-) diff --git a/3rdparty/lua/src/modules/lua-winreg/src/lua_int64.h b/3rdparty/lua/src/modules/lua-winreg/src/lua_int64.h index 0bf2ecb..f2e15e2 100644 --- a/3rdparty/lua/src/modules/lua-winreg/src/lua_int64.h +++ b/3rdparty/lua/src/modules/lua-winreg/src/lua_int64.h @@ -24,7 +24,11 @@ int atoINT64(const char* s, INT64 *pv); #define lua_pushUINT64(L,n) \ if( n > CONST_9007199254740992 ){ \ char buf[24]; \ - lua_pushstring(L, _ui64toa(n, buf, 10)); \ + if(_ui64toa_s(n, buf, _countof(buf), 10)){ \ + lua_pushnil(L);return; \ + }else{ \ + lua_pushstring(L, buf); \ + } \ }else{ \ lua_pushnumber(L, (lua_Number)(__int64)n); \ } diff --git a/3rdparty/lua/src/modules/lua-winreg/src/lua_mtutil.h b/3rdparty/lua/src/modules/lua-winreg/src/lua_mtutil.h index 34e9717..97fae38 100644 --- a/3rdparty/lua/src/modules/lua-winreg/src/lua_mtutil.h +++ b/3rdparty/lua/src/modules/lua-winreg/src/lua_mtutil.h @@ -7,7 +7,7 @@ extern "C" { #include #include -int lua_opentablemt(lua_State *L, const char * libname, const luaL_Reg * reg); +int lua_opentablemt(lua_State *L, const char * libname, const luaL_Reg * reg, int upval); void * lua_newuserdatamt(lua_State *L, size_t cdata, const char * mtname, const luaL_Reg * mtreg); void * lua_newuserdatamtuv(lua_State *L, size_t cdata, const char * mtname, const luaL_Reg * mtreg, int upval); #ifdef __cplusplus diff --git a/3rdparty/lua/src/modules/lua-winreg/src/winreg.c b/3rdparty/lua/src/modules/lua-winreg/src/winreg.c index a787b87..363c1c2 100644 --- a/3rdparty/lua/src/modules/lua-winreg/src/winreg.c +++ b/3rdparty/lua/src/modules/lua-winreg/src/winreg.c @@ -3,7 +3,9 @@ #endif #include +#ifndef lua_assert #define lua_assert assert +#endif #include #include @@ -37,7 +39,7 @@ #define REG_QWORD ( 11 ) // 64-bit number #endif - +#ifndef LUA_REG_NO_DLL BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved){ UNUSED(hModule); UNUSED(lpReserved); @@ -45,7 +47,9 @@ BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReser return TRUE; } -__declspec(dllexport) int luaopen_winreg(lua_State *L){ +__declspec(dllexport) +#endif +int luaopen_winreg(lua_State *L){ luaL_register(L, "winreg", lreg_reglib); return 1; } @@ -151,7 +155,7 @@ HKEY reg_aux_strtohkey(lua_State *L, const char * psz){ WIN_TRACEA("DIGIT ROOTKEY %s", psz); return (HKEY)(size_t)x; }else{ - for(pph = ph; pph->name && stricmp(psz, pph->name); pph++); + for(pph = ph; pph->name && _stricmp(psz, pph->name); pph++); if(!pph->data)luaL_error(L, "invalid prefix key '%s'", psz); return (HKEY)pph->data; } @@ -342,7 +346,13 @@ void reg_aux_pusheregstrdata(lua_State *L, PVOID pdata, size_t cdata, DWORD dwTy }else{ n = (DWORD64)(*((PDWORD32)pdata)); } - lua_pushstring(L, _ui64toa(n, buf, 10)); + if(_ui64toa_s(n, buf, _countof(buf), 10)){ + lua_pushnil(L); + return; + }else{ + lua_pushstring(L, buf); + } + } break; case REG_MULTI_SZ: { @@ -572,6 +582,7 @@ int reg_getvalue(lua_State *L){//regobj.getvalue } return 2; } +#ifndef LUA_REG_NO_HIVEOPS //docok int reg_loadkey(lua_State *L){//regobj.load LONG ret; @@ -580,12 +591,14 @@ int reg_loadkey(lua_State *L){//regobj.load LUA_CHECK_DLL_ERROR(L, ret); LUA_CHECK_RETURN_OBJECT(L, ret == ERROR_SUCCESS); } +#endif // LUA_REG_NO_HIVEOPS //docok int reg_openkey(lua_State *L){//regobj.openkey reg_aux_newkey(L, reg_aux_gethkey(L, 1), lua_checktstring(L, 2), NULL, reg_aux_getaccess(L, 3), FALSE); return 1; } +#ifndef LUA_REG_NO_HIVEOPS //docok int reg_replacekey(lua_State *L){//regobj.replace LONG ret; @@ -616,12 +629,14 @@ int reg_savekey(lua_State *L){//regobj.save LUA_CHECK_DLL_ERROR(L, ret); LUA_CHECK_RETURN_OBJECT(L, ret == ERROR_SUCCESS); } +#endif // LUA_REG_NO_HIVEOPS //docok int reg_setvalue(lua_State *L){//regobj.setvalue LUA_CHECK_RETURN_OBJECT(L, reg_aux_setvalue(L, reg_aux_gethkey(L, 1), lua_opttstring(L, 2, NULL), reg_aux_getdatatype(L, 4), 3) ); } +#ifndef LUA_REG_NO_HIVEOPS //docok int reg_unloadkey(lua_State *L){//regobj.unload LONG ret; @@ -630,6 +645,7 @@ int reg_unloadkey(lua_State *L){//regobj.unload LUA_CHECK_DLL_ERROR(L, ret); LUA_CHECK_RETURN_OBJECT(L, ret == ERROR_SUCCESS); } +#endif // LUA_REG_NO_HIVEOPS int reg_handle(lua_State *L){//regobj.handle HKEY hKey = reg_aux_gethkey(L, 1); diff --git a/3rdparty/lua/src/modules/lua-winreg/test/test_5_1_5.lua b/3rdparty/lua/src/modules/lua-winreg/test/test_5_1_5.lua index 4c23888..877c75b 100644 --- a/3rdparty/lua/src/modules/lua-winreg/test/test_5_1_5.lua +++ b/3rdparty/lua/src/modules/lua-winreg/test/test_5_1_5.lua @@ -1,8 +1,8 @@ -local winreg = require"winreg" --- Enumerate Application paths -rkey = [[HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths]] -hkey = winreg.openkey(rkey, 'r') -for k in hkey:enumkey() do - print(k,(hkey:openkey(k, 'r'):getvalue())) - collectgarbage() -end +local winreg = require"winreg" +-- Enumerate Application paths +rkey = [[HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths]] +hkey = winreg.openkey(rkey, 'r') +for k in hkey:enumkey() do + print(k,(hkey:openkey(k, 'r'):getvalue())) + collectgarbage() +end diff --git a/3rdparty/lua/src/modules/winreg.h b/3rdparty/lua/src/modules/winreg.h index 3f026d9..c332f07 100644 --- a/3rdparty/lua/src/modules/winreg.h +++ b/3rdparty/lua/src/modules/winreg.h @@ -1,5 +1,5 @@ #ifndef __WINREG_H_VER__ -#define __WINREG_H_VER__ 2012102400 +#define __WINREG_H_VER__ 2018040518 #if (defined(_MSC_VER) && (_MSC_VER >= 1020)) || defined(__MCPP) #pragma once #endif // Check for "#pragma once" support @@ -17,5 +17,6 @@ extern "C" { #define LUA_WINREGNAME "winreg" #define LUA_REG_NO_WINTRACE #define LUA_REG_NO_HIVEOPS +#define LUA_REG_NO_DLL #endif // __LWINREG_H_VER__ -- cgit v1.2.3