Skip to content

Commit d22bb69

Browse files
committed
Following describes major update...
- No longer cares about directories you store lua in - It #include "lua.h"'s rather than follow a strict path (MSVS is the reason) - Cleared up imports a lot - Fixed PATH_MAX issue - Added posix compliant versions of functions (for MSVS esp)
1 parent f358a87 commit d22bb69

2 files changed

Lines changed: 67 additions & 118 deletions

File tree

src/additions.c

Lines changed: 17 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -21,64 +21,29 @@
2121
* SOFTWARE.
2222
*/
2323

24-
#if defined(linux) || defined(__linux__) || defined(__linux)
25-
# include <unistd.h>
26-
# include <stdio.h>
27-
# include <stdlib.h>
28-
# define CLEAR_CONSOLE "clear"
29-
#elif defined(unix) || defined(__unix__) || defined(__unix)
30-
# include <unistd.h>
24+
#if defined(_WIN32) || defined(_WIN64)
25+
# include <windows.h>
3126
# include <stdio.h>
3227
# include <stdlib.h>
33-
# define CLEAR_CONSOLE "clear"
34-
#elif defined(__APPLE__) || defined(__MACH__)
28+
# include <direct.h>
29+
# define CLEAR_CONSOLE ("cls")
30+
# ifndef PATH_MAX
31+
# define PATH_MAX (260)
32+
# endif
33+
#else
3534
# include <unistd.h>
3635
# include <stdio.h>
3736
# include <stdlib.h>
38-
# define CLEAR_CONSOLE "clear"
39-
#elif defined(_WIN32) || defined(_WIN64)
40-
# include <windows.h>
41-
# include <stdio.h>
42-
# include <stdlib.h>
43-
# define CLEAR_CONSOLE "cls"
44-
#else
45-
# error "Not familiar. Set up headers accordingly, or -D__linux__ of -Dunix or -D__APPLE__ or -D_WIN32"
37+
# include <dirent.h>
38+
# define CLEAR_CONSOLE ("clear")
4639
#endif
4740

48-
4941
#include <string.h>
50-
#include <dirent.h>
5142
#include <time.h>
43+
5244
#include <sys/types.h>
5345
#include <sys/stat.h>
5446

55-
56-
// Please migrate your lua h's to a proper directory so versions don't collide
57-
// luajit make install puts them in /usr/local/include/luajit-X.X/*
58-
// lua51/52/53 puts them directly in /usr/local/include/* with version collision
59-
#if defined(LUA_51)
60-
# include "lua51/lua.h"
61-
# include "lua51/lualib.h"
62-
# include "lua51/lauxlib.h"
63-
#elif defined(LUA_52)
64-
# include "lua52/lua.h"
65-
# include "lua52/lualib.h"
66-
# include "lua52/lauxlib.h"
67-
#elif defined(LUA_53)
68-
# include "lua53/lua.h"
69-
# include "lua53/lualib.h"
70-
# include "lua53/lauxlib.h"
71-
#elif defined(LUA_JIT_51)
72-
# include "luajit-2.0/lua.h"
73-
# include "luajit-2.0/lualib.h"
74-
# include "luajit-2.0/lauxlib.h"
75-
# include "luajit-2.0/luajit.h"
76-
#else
77-
# warning "Lua version not defined."
78-
# error "Define the version to use. '-DLUA_53' '-DLUA_52' '-DLUA_51' '-DLUA_JIT_51'"
79-
#endif
80-
81-
8247
#include "additions.h"
8348

8449

@@ -87,7 +52,7 @@
8752
static int lua_cwd_getcwd(lua_State* L) {
8853
static char buffer[PATH_MAX];
8954
luaL_checkstack(L, 1, NULL);
90-
lua_pushstring(L, getcwd(buffer, PATH_MAX));
55+
lua_pushstring(L, _getcwd(buffer, PATH_MAX));
9156
return 1;
9257
}
9358

@@ -97,7 +62,7 @@ static int lua_cwd_getcwd(lua_State* L) {
9762
static int lua_cwd_setcwd(lua_State* L) {
9863
luaL_checkstack(L, 1, NULL);
9964
const char* path = luaL_checkstring(L, 1);
100-
if(chdir(path) == 0)
65+
if(_chdir(path) == 0)
10166
lua_pushboolean(L, 1);
10267
else lua_pushboolean(L, 0);
10368
return 1;
@@ -108,6 +73,7 @@ static int lua_cwd_setcwd(lua_State* L) {
10873
// boolean [2] : should stat be used
10974
// returns nil or error, or array with strings of all element names
11075
static int lua_cwd_getdir(lua_State* L) {
76+
#ifndef _WIN32
11177
static DIR* dp;
11278
static struct dirent* ep;
11379

@@ -131,6 +97,9 @@ static int lua_cwd_getdir(lua_State* L) {
13197

13298
closedir(dp);
13399
return 1;
100+
#else
101+
return 0;
102+
#endif // !_WIN32
134103
}
135104

136105
// void clear_window()

src/additions.h

Lines changed: 50 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,50 @@
1-
/* MIT License
2-
*
3-
* Copyright (c) 2017-2018 Cody Tilkins
4-
*
5-
* Permission is hereby granted, free of charge, to any person obtaining a copy
6-
* of this software and associated documentation files (the "Software"), to deal
7-
* in the Software without restriction, including without limitation the rights
8-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9-
* copies of the Software, and to permit persons to whom the Software is
10-
* furnished to do so, subject to the following conditions:
11-
*
12-
* The above copyright notice and this permission notice shall be included in all
13-
* copies or substantial portions of the Software.
14-
*
15-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21-
* SOFTWARE.
22-
*/
23-
24-
#pragma once
25-
26-
#if defined(linux) || defined(__linux__) || defined(__linux)
27-
# define LUA_DLL __attribute__((visibility("default")))
28-
#elif defined(unix) || defined(__unix__) || defined(__unix)
29-
# define LUA_DLL __attribute__((visibility("default")))
30-
#elif defined(__APPLE__) || defined(__MACH__)
31-
# define LUA_DLL __attribute__((visibility("default")))
32-
#elif defined(_WIN32) || defined(_WIN64)
33-
# define LUA_DLL __declspec(dllexport)
34-
#else
35-
# error "OS not familiar. Set up headers accordingly, or -D__linux__ of -Dunix or -D__APPLE__ or -D_WIN32"
36-
#endif
37-
38-
39-
// Please migrate your lua h's to a proper directory so versions don't collide
40-
// luajit make install puts them in /usr/local/include/luajit-X.X/*
41-
// lua51/52/53 puts them directly in /usr/local/include/* with version collision
42-
#if defined(LUA_51)
43-
# include "lua51/lua.h"
44-
# include "lua51/lualib.h"
45-
# include "lua51/lauxlib.h"
46-
#elif defined(LUA_52)
47-
# include "lua52/lua.h"
48-
# include "lua52/lualib.h"
49-
# include "lua52/lauxlib.h"
50-
#elif defined(LUA_53)
51-
# include "lua53/lua.h"
52-
# include "lua53/lualib.h"
53-
# include "lua53/lauxlib.h"
54-
#elif defined(LUA_JIT_51)
55-
# include "luajit-2.0/lua.h"
56-
# include "luajit-2.0/lualib.h"
57-
# include "luajit-2.0/lauxlib.h"
58-
# include "luajit-2.0/luajit.h"
59-
#else
60-
# warning "Lua version not defined."
61-
# error "Define the version to use. '-DLUA_53' '-DLUA_52' '-DLUA_51' '-DLUA_JIT_51'"
62-
#endif
63-
64-
65-
66-
#define LUA_DLL_ENTRY LUA_DLL int
67-
68-
69-
LUA_DLL_ENTRY luaopen_luaadd(lua_State* L);
70-
1+
/* MIT License
2+
*
3+
* Copyright (c) 2017-2018 Cody Tilkins
4+
*
5+
* Permission is hereby granted, free of charge, to any person obtaining a copy
6+
* of this software and associated documentation files (the "Software"), to deal
7+
* in the Software without restriction, including without limitation the rights
8+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
* copies of the Software, and to permit persons to whom the Software is
10+
* furnished to do so, subject to the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be included in all
13+
* copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
* SOFTWARE.
22+
*/
23+
24+
#pragma once
25+
26+
27+
#if defined(_WIN32) || defined(_WIN64)
28+
# define LUA_DLL __declspec(dllexport)
29+
#else
30+
# define LUA_DLL __attribute__((visibility("default")))
31+
#endif
32+
33+
34+
// compiler/project includes
35+
// Please migrate your lua h's to a proper local directory so versions don't collide
36+
// luajit `make install` puts them in /usr/local/include/luajit-X.X/*
37+
// lua51/52/53 `make install` puts them in /usr/local/include/* with version collision
38+
#include "lua.h"
39+
#include "lualib.h"
40+
#include "lauxlib.h"
41+
#if defined(LUA_JIT_51)
42+
# include "jitsupport.h"
43+
#endif
44+
45+
46+
#define LUA_DLL_ENTRY LUA_DLL int
47+
48+
49+
LUA_DLL_ENTRY luaopen_luaadd(lua_State* L);
50+

0 commit comments

Comments
 (0)