Fix execute bit on Unix-likes.

This commit is contained in:
TSnake41 2020-04-01 13:16:15 +02:00
parent 85ef3f07f5
commit dfbc283fed
2 changed files with 25 additions and 2 deletions

View File

@ -102,6 +102,19 @@ static int raylua_builder_new(lua_State *L)
return 1; return 1;
} }
static int raylua_builder_set_executable(lua_State *L)
{
const char *path = luaL_checkstring(L, -1);
printf("BUILDER: Sets '%s' executable.\n", path);
#ifndef WIN32
/* On Windows, there is no need to set a executable flag. */
chmod(path, 0777); /* rwx */
#endif
return 0;
}
static int raylua_builder_close(lua_State *L) static int raylua_builder_close(lua_State *L)
{ {
raylua_builder *builder = lua_touserdata(L, -1); raylua_builder *builder = lua_touserdata(L, -1);
@ -193,6 +206,9 @@ int raylua_builder_boot(lua_State *L)
lua_pushcfunction(L, raylua_builder_add); lua_pushcfunction(L, raylua_builder_add);
lua_setglobal(L, "builder_add"); lua_setglobal(L, "builder_add");
lua_pushcfunction(L, raylua_builder_set_executable);
lua_setglobal(L, "set_executable");
if (luaL_dostring(L, raylua_builder_lua)) if (luaL_dostring(L, raylua_builder_lua))
fputs(luaL_checkstring(L, -1), stderr); fputs(luaL_checkstring(L, -1), stderr);

View File

@ -67,6 +67,8 @@ end
print("BUILDER: Self is " .. self_path) print("BUILDER: Self is " .. self_path)
if t == "directory" then if t == "directory" then
print "BUILDER: Building from folder."
local output = arg[2] local output = arg[2]
if not output then if not output then
@ -75,7 +77,7 @@ if t == "directory" then
if ffi.os == "Windows" then if ffi.os == "Windows" then
output = input_path .. ".exe" output = input_path .. ".exe"
else else
output = input_path .. ".elf" output = input_path .. "_out"
end end
end end
@ -125,6 +127,7 @@ if t == "directory" then
end end
builder_close(builder) builder_close(builder)
set_executable(output)
elseif t == "file" then elseif t == "file" then
local ext = input_path:sub(-4) local ext = input_path:sub(-4)
@ -134,7 +137,7 @@ elseif t == "file" then
if ffi.os == "Windows" then if ffi.os == "Windows" then
path = path .. ".exe" path = path .. ".exe"
else else
path = path .. ".elf" path = path .. "_out"
end end
print("BUILDER: Building " .. path) print("BUILDER: Building " .. path)
@ -157,7 +160,11 @@ elseif t == "file" then
local builder = builder_new(self_path, path) local builder = builder_new(self_path, path)
builder_add(builder, input_path, "main.lua") builder_add(builder, input_path, "main.lua")
builder_close(builder) builder_close(builder)
else
error "Unknown file type."
end end
set_executable(path)
end end
print "BUILDER: Done" print "BUILDER: Done"