Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
Lite XL
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Andy Nichols
Lite XL
Commits
ba86b58b
Commit
ba86b58b
authored
5 years ago
by
rxi
Browse files
Options
Downloads
Patches
Plain Diff
Added better resolution of exe directory; should fix #1
parent
3c59abba
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main.c
+52
-10
52 additions, 10 deletions
src/main.c
with
52 additions
and
10 deletions
src/main.c
+
52
−
10
View file @
ba86b58b
...
...
@@ -2,13 +2,58 @@
#include
<SDL2/SDL.h>
#include
"api/api.h"
#include
"renderer.h"
#ifdef _WIN32
#include
<windows.h>
#elif __linux__
#include
<unistd.h>
#elif __APPLE__
#include
<mach-o/dyld.h>
#endif
SDL_Window
*
window
;
static
double
get_scale
(
void
)
{
float
dpi
;
SDL_GetDisplayDPI
(
0
,
NULL
,
&
dpi
,
NULL
);
#if _WIN32
return
dpi
/
96
.
0
;
#elif __APPLE__
return
dpi
/
72
.
0
;
#else
return
1
.
0
;
#endif
}
const
void
get_exe_dir
(
char
*
buf
,
int
sz
)
{
#if _WIN32
int
len
=
GetModuleFileName
(
NULL
,
buf
,
sz
-
1
);
buf
[
len
]
=
'\0'
;
#elif __linux__
char
path
[
512
];
sprintf
(
path
,
"/proc/%d/exe"
,
getpid
());
int
len
=
readlink
(
path
,
buf
,
sz
-
1
);
buf
[
len
]
=
'\0'
;
#elif __APPLE__
unsigned
size
=
sz
;
_NSGetExecutablePath
(
buf
,
&
size
);
#else
strcpy
(
buf
,
"."
)
#endif
for
(
int
i
=
strlen
(
buf
)
-
1
;
i
>
0
;
i
--
)
{
if
(
buf
[
i
]
==
'/'
||
buf
[
i
]
==
'\\'
)
{
buf
[
i
]
=
'\0'
;
break
;
}
}
}
int
main
(
int
argc
,
char
**
argv
)
{
#ifdef _WIN32
HINSTANCE
lib
=
LoadLibrary
(
"user32.dll"
);
...
...
@@ -46,24 +91,21 @@ int main(int argc, char **argv) {
lua_setglobal
(
L
,
"_ARGS"
);
float
dpi
;
SDL_GetDisplayDPI
(
0
,
NULL
,
&
dpi
,
NULL
);
#if _WIN32
lua_pushnumber
(
L
,
dpi
/
96
.
0
);
#elif __APPLE__
lua_pushnumber
(
L
,
dpi
/
72
.
0
);
#else
lua_pushnumber
(
L
,
1
.
0
);
#endif
lua_pushnumber
(
L
,
get_scale
());
lua_setglobal
(
L
,
"_SCALE"
);
char
exedir
[
2048
];
get_exe_dir
(
exedir
,
sizeof
(
exedir
));
lua_pushstring
(
L
,
exedir
);
lua_setglobal
(
L
,
"_EXEDIR"
);
(
void
)
luaL_dostring
(
L
,
"local core
\n
"
"xpcall(function()
\n
"
" _SCALE = tonumber(os.getenv(
\"
LITE_SCALE
\"
)) or _SCALE
\n
"
" _PATHSEP = package.config:sub(1, 1)
\n
"
" _EXEDIR = _ARGS[1]:match('(.*)[/
\\\\
].*$')
\n
"
" package.path = _EXEDIR .. '/data/?.lua;' .. package.path
\n
"
" package.path = _EXEDIR .. '/data/?/init.lua;' .. package.path
\n
"
" core = require('core')
\n
"
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment