Skip to content

Commit 8fb2b22

Browse files
committed
Merge branch 'master' into fontin-fonts
2 parents 17943ba + 50bf4f5 commit 8fb2b22

File tree

13 files changed

+866
-13
lines changed

13 files changed

+866
-13
lines changed

ui_api.cpp

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -792,12 +792,16 @@ static int l_SetViewport(lua_State* L)
792792
ui->LAssert(L, ui->renderer != NULL, "Renderer is not initialised");
793793
ui->LAssert(L, ui->renderEnable, "SetViewport() called outside of OnFrame");
794794
int n = lua_gettop(L);
795+
const float dpiScale = ui->renderer->VirtualScreenScaleFactor();
795796
if (n) {
796797
ui->LAssert(L, n >= 4, "Usage: SetViewport([x, y, width, height])");
797798
for (int i = 1; i <= 4; i++) {
798799
ui->LAssert(L, lua_isnumber(L, i), "SetViewport() argument %d: expected number, got %s", i, luaL_typename(L, i));
799800
}
800-
ui->renderer->SetViewport((int)lua_tointeger(L, 1), (int)lua_tointeger(L, 2), (int)lua_tointeger(L, 3), (int)lua_tointeger(L, 4));
801+
ui->renderer->SetViewport((int)(lua_tointeger(L, 1) * dpiScale),
802+
(int)(lua_tointeger(L, 2) * dpiScale),
803+
(int)(lua_tointeger(L, 3) * dpiScale),
804+
(int)(lua_tointeger(L, 4) * dpiScale));
801805
}
802806
else {
803807
ui->renderer->SetViewport();
@@ -893,10 +897,11 @@ static int l_DrawImage(lua_State* L)
893897
}
894898

895899
if (af & AF_XY) {
900+
const float dpiScale = ui->renderer->VirtualScreenScaleFactor();
896901
for (int i = k; i < k + 4; i++) {
897902
ui->LAssert(L, lua_isnumber(L, i), "DrawImage() argument %d: expected number, got %s", i, luaL_typename(L, i));
898903
const int idx = i - k;
899-
xys[idx/2][idx%2] = (float)lua_tonumber(L, i);
904+
xys[idx/2][idx%2] = (float)lua_tonumber(L, i) * dpiScale;
900905
}
901906
k += 4;
902907
}
@@ -991,10 +996,11 @@ static int l_DrawImageQuad(lua_State* L)
991996
}
992997

993998
if (af & AF_XY) {
999+
const float dpiScale = ui->renderer->VirtualScreenScaleFactor();
9941000
for (int i = k; i < k + 8; i++) {
9951001
ui->LAssert(L, lua_isnumber(L, i), "DrawImageQuad() argument %d: expected number, got %s", i, luaL_typename(L, i));
9961002
const int idx = i - k;
997-
xys[idx / 2][idx % 2] = (float)lua_tonumber(L, i);
1003+
xys[idx / 2][idx % 2] = (float)lua_tonumber(L, i) * dpiScale;
9981004
}
9991005
k += 8;
10001006
}
@@ -1061,9 +1067,15 @@ static int l_DrawString(lua_State* L)
10611067
ui->LAssert(L, lua_isstring(L, 6), "DrawString() argument 6: expected string, got %s", luaL_typename(L, 6));
10621068
static const char* alignMap[6] = { "LEFT", "CENTER", "RIGHT", "CENTER_X", "RIGHT_X", NULL };
10631069
static const char* fontMap[7] = { "FIXED", "VAR", "VAR BOLD", "FONTIN SC", "FONTIN SC ITALIC", "FONTIN ITALIC", NULL};
1070+
const float dpiScale = ui->renderer->VirtualScreenScaleFactor();
10641071
ui->renderer->DrawString(
1065-
(float)lua_tonumber(L, 1), (float)lua_tonumber(L, 2), luaL_checkoption(L, 3, "LEFT", alignMap),
1066-
(int)lua_tointeger(L, 4), NULL, luaL_checkoption(L, 5, "FIXED", fontMap), lua_tostring(L, 6)
1072+
(float)lua_tonumber(L, 1) * dpiScale,
1073+
(float)lua_tonumber(L, 2) * dpiScale,
1074+
luaL_checkoption(L, 3, "LEFT", alignMap),
1075+
(int)lua_tointeger(L, 4) * dpiScale,
1076+
NULL,
1077+
luaL_checkoption(L, 5, "FIXED", fontMap),
1078+
lua_tostring(L, 6)
10671079
);
10681080
return 0;
10691081
}
@@ -1078,7 +1090,10 @@ static int l_DrawStringWidth(lua_State* L)
10781090
ui->LAssert(L, lua_isstring(L, 2), "DrawStringWidth() argument 2: expected string, got %s", luaL_typename(L, 2));
10791091
ui->LAssert(L, lua_isstring(L, 3), "DrawStringWidth() argument 3: expected string, got %s", luaL_typename(L, 3));
10801092
static const char* fontMap[7] = { "FIXED", "VAR", "VAR BOLD", "FONTIN SC", "FONTIN SC ITALIC", "FONTIN ITALIC", NULL };
1081-
lua_pushinteger(L, ui->renderer->DrawStringWidth((int)lua_tointeger(L, 1), luaL_checkoption(L, 2, "FIXED", fontMap), lua_tostring(L, 3)));
1093+
const float dpiScale = ui->renderer->VirtualScreenScaleFactor();
1094+
lua_pushinteger(L, ui->renderer->DrawStringWidth((int)lua_tointeger(L, 1) * dpiScale,
1095+
luaL_checkoption(L, 2, "FIXED", fontMap),
1096+
lua_tostring(L, 3)));
10821097
return 1;
10831098
}
10841099

@@ -1087,14 +1102,18 @@ static int l_DrawStringCursorIndex(lua_State* L)
10871102
ui_main_c* ui = GetUIPtr(L);
10881103
ui->LAssert(L, ui->renderer != NULL, "Renderer is not initialised");
10891104
int n = lua_gettop(L);
1105+
const float dpiScale = ui->renderer->VirtualScreenScaleFactor();
10901106
ui->LAssert(L, n >= 5, "Usage: DrawStringCursorIndex(height, font, text, cursorX, cursorY)");
10911107
ui->LAssert(L, lua_isnumber(L, 1), "DrawStringCursorIndex() argument 1: expected number, got %s", luaL_typename(L, 1));
10921108
ui->LAssert(L, lua_isstring(L, 2), "DrawStringCursorIndex() argument 2: expected string, got %s", luaL_typename(L, 2));
10931109
ui->LAssert(L, lua_isstring(L, 3), "DrawStringCursorIndex() argument 3: expected string, got %s", luaL_typename(L, 3));
10941110
ui->LAssert(L, lua_isnumber(L, 4), "DrawStringCursorIndex() argument 4: expected number, got %s", luaL_typename(L, 4));
10951111
ui->LAssert(L, lua_isnumber(L, 5), "DrawStringCursorIndex() argument 5: expected number, got %s", luaL_typename(L, 5));
10961112
static const char* fontMap[7] = { "FIXED", "VAR", "VAR BOLD", "FONTIN SC", "FONTIN SC ITALIC", "FONTIN ITALIC", NULL };
1097-
lua_pushinteger(L, ui->renderer->DrawStringCursorIndex((int)lua_tointeger(L, 1), luaL_checkoption(L, 2, "FIXED", fontMap), lua_tostring(L, 3), (int)lua_tointeger(L, 4), (int)lua_tointeger(L, 5)) + 1);
1113+
lua_pushinteger(L, ui->renderer->DrawStringCursorIndex((int)lua_tointeger(L, 1) * dpiScale,
1114+
luaL_checkoption(L, 2, "FIXED", fontMap),
1115+
lua_tostring(L, 3),
1116+
(int)lua_tointeger(L, 4) * dpiScale, (int)lua_tointeger(L, 5) * dpiScale) + 1);
10981117
return 1;
10991118
}
11001119

@@ -1376,20 +1395,22 @@ static int l_SetWindowTitle(lua_State* L)
13761395
static int l_GetCursorPos(lua_State* L)
13771396
{
13781397
ui_main_c* ui = GetUIPtr(L);
1379-
lua_pushinteger(L, ui->renderer->VirtualMap(ui->cursorX));
1380-
lua_pushinteger(L, ui->renderer->VirtualMap(ui->cursorY));
1398+
const float dpiScale = ui->renderer->VirtualScreenScaleFactor();
1399+
lua_pushinteger(L, ui->renderer->VirtualMap(ui->cursorX) / dpiScale);
1400+
lua_pushinteger(L, ui->renderer->VirtualMap(ui->cursorY) / dpiScale);
13811401
return 2;
13821402
}
13831403

13841404
static int l_SetCursorPos(lua_State* L)
13851405
{
13861406
ui_main_c* ui = GetUIPtr(L);
13871407
int n = lua_gettop(L);
1408+
const float dpiScale = ui->renderer->VirtualScreenScaleFactor();
13881409
ui->LAssert(L, n >= 2, "Usage: SetCursorPos(x, y)");
13891410
ui->LAssert(L, lua_isnumber(L, 1), "SetCursorPos() argument 1: expected number, got %s", luaL_typename(L, 1));
13901411
ui->LAssert(L, lua_isnumber(L, 2), "SetCursorPos() argument 2: expected number, got %s", luaL_typename(L, 2));
1391-
int x = ui->renderer->VirtualUnmap((int)lua_tointeger(L, 1));
1392-
int y = ui->renderer->VirtualUnmap((int)lua_tointeger(L, 2));
1412+
int x = ui->renderer->VirtualUnmap((int)lua_tointeger(L, 1) * dpiScale);
1413+
int y = ui->renderer->VirtualUnmap((int)lua_tointeger(L, 2) * dpiScale);
13931414
ui->sys->video->SetRelativeCursor(x, y);
13941415
return 0;
13951416
}
@@ -2183,3 +2204,4 @@ int ui_main_c::InitAPI(lua_State* L)
21832204
return 0;
21842205
}
21852206

2207+

vcpkg-configuration.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
{
88
"kind": "filesystem",
99
"path": "vcpkg-ports",
10-
"baseline": "2025-01-19",
10+
"baseline": "2025-10-07",
1111
"packages": ["glfw3", "gli", "luajit"]
1212
}
1313
]
14-
}
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
diff --git a/src/Makefile b/src/Makefile
2+
index c4d0b14d..2c9769b9 100644
3+
--- a/src/Makefile
4+
+++ b/src/Makefile
5+
@@ -318,9 +318,6 @@ ifeq (,$(shell $(TARGET_CC) -o /dev/null -c -x c /dev/null -fno-stack-protector
6+
TARGET_XCFLAGS+= -fno-stack-protector
7+
endif
8+
ifeq (Darwin,$(TARGET_SYS))
9+
- ifeq (,$(MACOSX_DEPLOYMENT_TARGET))
10+
- $(error missing: export MACOSX_DEPLOYMENT_TARGET=XX.YY)
11+
- endif
12+
TARGET_STRIP+= -x
13+
TARGET_XCFLAGS+= -DLUAJIT_UNWIND_EXTERNAL
14+
TARGET_XSHLDFLAGS= -dynamiclib -undefined dynamic_lookup -fPIC
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
diff --git a/etc/luajit.pc b/etc/luajit.pc
2+
index 39e1e57..3837d3b 100644
3+
--- a/etc/luajit.pc
4+
+++ b/etc/luajit.pc
5+
@@ -21,5 +21,5 @@ URL: https://luajit.org
6+
Version: ${version}
7+
Requires:
8+
Libs: -L${libdir} -l${libname}
9+
-Libs.private: -Wl,-E -lm -ldl
10+
+Libs.private: -lm -ldl
11+
Cflags: -I${includedir}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
all:
2+
@echo _CL_ = $(_CL_)
3+
@echo _LINK_ = $(_LINK_)
4+
cd src && .\msvcbuild.bat $(MSVCBUILD_OPTIONS)
5+
6+
install: src/luajit.exe
7+
-mkdir "$(INSTALLDIR)"
8+
-mkdir "$(INSTALLDIR)\bin"
9+
copy src\luajit.exe "$(INSTALLDIR)\bin\"
10+
if exist src\lua51.dll copy src\lua51.dll "$(INSTALLDIR)\bin\"
11+
-mkdir "$(INSTALLDIR)\lib"
12+
copy src\lua51.lib "$(INSTALLDIR)\lib\"
13+
-mkdir "$(INSTALLDIR)\include"
14+
-mkdir "$(INSTALLDIR)\include\luajit"
15+
copy src/lua.h "$(INSTALLDIR)\include\luajit\"
16+
copy src/luajit.h "$(INSTALLDIR)\include\luajit\"
17+
copy src/luaconf.h "$(INSTALLDIR)\include\luajit\"
18+
copy src/lualib.h "$(INSTALLDIR)\include\luajit\"
19+
copy src/lauxlib.h "$(INSTALLDIR)\include\luajit\"
20+
copy src/lua.hpp "$(INSTALLDIR)\include\luajit\"
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
LJARCH=
6+
LUAJIT_BUILDMODE=
7+
LUAJIT_BUILDVM_X=
8+
LUAJIT_DASM_ARCHS=
9+
LUAJIT_PREFIX=
10+
for OPTION; do
11+
case "${OPTION}" in
12+
--prefix=*)
13+
LUAJIT_PREFIX="${OPTION#--prefix=}"
14+
;;
15+
BUILDMODE=*)
16+
LUAJIT_BUILDMODE="${OPTION#BUILDMODE=}"
17+
;;
18+
BUILDVM_X=*)
19+
LUAJIT_BUILDVM_X="${OPTION#BUILDVM_X=}"
20+
;;
21+
DASM_ARCHS=*)
22+
LUAJIT_DASM_ARCHS="${OPTION#DASM_ARCHS=}"
23+
;;
24+
LJARCH=*)
25+
LJARCH="${OPTION#LJARCH=}"
26+
;;
27+
esac
28+
done
29+
30+
cat > Makefile.vcpkg <<END_MAKEFILE ;
31+
32+
COMMON_OPTIONS += 'E=@:' 'Q='
33+
COMMON_OPTIONS += 'BUILDMODE=${LUAJIT_BUILDMODE}'
34+
COMMON_OPTIONS += 'PREFIX=${LUAJIT_PREFIX}'
35+
COMMON_OPTIONS += 'INSTALL_TNAME=luajit'
36+
37+
BUILD_OPTIONS += 'CC=${CC}'
38+
BUILD_OPTIONS += 'CCDEBUG='
39+
BUILD_OPTIONS += 'CFLAGS=${CPPFLAGS} ${CFLAGS}'
40+
BUILD_OPTIONS += 'LDFLAGS=${LDFLAGS}'
41+
BUILD_OPTIONS += 'LIBS=${LIBS}'
42+
43+
ifeq (${LJARCH},)
44+
# native
45+
BUILDVM_PREFIX = ${LUAJIT_PREFIX}/manual-tools/luajit
46+
DASM_ARCHS = ${LUAJIT_DASM_ARCHS}
47+
else
48+
# cross
49+
BUILD_OPTIONS += 'HOST_CC=:'
50+
BUILD_OPTIONS += 'BUILDVM_T='
51+
BUILD_OPTIONS += 'BUILDVM_X=${LUAJIT_BUILDVM_X}'
52+
endif
53+
54+
# used by src/Makefile, best effort from manual '<CC> [-m32] -E src/lj_arch.h -dM'
55+
TARGET_TESTARCH_COMMON += 'LJ_LE 1' 'LJ_HASJIT 1' 'LJ_HASFFI 1' 'LJ_ARCH_HASFPU 1' 'LJ_ABI_SOFTFP 0'
56+
TARGET_TESTARCH_COMMON_32 += \$(TARGET_TESTARCH_COMMON) 'LJ_ARCH_BITS 32'
57+
TARGET_TESTARCH_COMMON_64 += \$(TARGET_TESTARCH_COMMON) 'LJ_ARCH_BITS 64' 'LJ_TARGET_GC64 1'
58+
TARGET_TESTARCH_arm = \$(TARGET_TESTARCH_COMMON_32) LJ_TARGET_ARM
59+
TARGET_TESTARCH_arm64 = \$(TARGET_TESTARCH_COMMON_64) LJ_TARGET_ARM64 'LJ_ARCH_VERSION 80'
60+
TARGET_TESTARCH_x86 = \$(TARGET_TESTARCH_COMMON_32) LJ_TARGET_X86
61+
TARGET_TESTARCH_x64 = \$(TARGET_TESTARCH_COMMON_64) LJ_TARGET_X64 'LJ_FR2 1'
62+
63+
all:
64+
\$(MAKE) clean \$(COMMON_OPTIONS) \$(BUILD_OPTIONS)
65+
\$(MAKE) all \$(COMMON_OPTIONS) \$(BUILD_OPTIONS)
66+
for DA in \$(DASM_ARCHS); do \\
67+
rm -f src/host/buildvm_arch.h src/host/*.o; \\
68+
case "\$\$DA" in \\
69+
arm) TARGET_TESTARCH="\$(TARGET_TESTARCH_arm)" ;; \\
70+
arm64) TARGET_TESTARCH="\$(TARGET_TESTARCH_arm64)" ;; \\
71+
x86) TARGET_TESTARCH="\$(TARGET_TESTARCH_x86)" ;; \\
72+
x64) TARGET_TESTARCH="\$(TARGET_TESTARCH_x64)" ;; \\
73+
esac ; \\
74+
\$(MAKE) -C src host/buildvm-\$\$DA\$(EXECUTABLE_SUFFIX) \$(COMMON_OPTIONS) \$(BUILD_OPTIONS) \\
75+
BUILDVM_T=host/buildvm-\$\$DA\$(EXECUTABLE_SUFFIX) "TARGET_TESTARCH=\$\${TARGET_TESTARCH}" \\
76+
|| exit 1; \\
77+
done
78+
79+
install:
80+
\$(MAKE) install \$(COMMON_OPTIONS)
81+
for DA in \$(DASM_ARCHS); do \\
82+
mkdir -p "\$\${DESTDIR}\$(BUILDVM_PREFIX)"; \\
83+
install -m 0755 "src/host/buildvm-\$\$DA\$(EXECUTABLE_SUFFIX)" "\$\${DESTDIR}\$(BUILDVM_PREFIX)/buildvm-\$\$DA\$(EXECUTABLE_SUFFIX)" || exit 1 ; \\
84+
done
85+
86+
END_MAKEFILE
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Package information for LuaJIT to be used by pkg-config.
2+
majver=2
3+
minver=1
4+
relver=0
5+
version=${majver}.${minver}
6+
abiver=51
7+
8+
prefix=@PREFIX@
9+
multilib=lib
10+
exec_prefix=${prefix}
11+
libdir=${exec_prefix}/${multilib}
12+
libname=lua${abiver}
13+
includedir=${prefix}/include/luajit
14+
15+
INSTALL_LMOD=${prefix}/share/lua/${abiver}
16+
INSTALL_CMOD=${prefix}/${multilib}/lua/${abiver}
17+
18+
Name: LuaJIT
19+
Description: Just-in-time compiler for Lua
20+
URL: https://luajit.org
21+
Version: ${version}
22+
Requires:
23+
Libs: -L${libdir} -l${libname}
24+
Cflags: -I${includedir} @LJIT_MSVC_PC_CFLAGS@
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
diff --git a/src/msvcbuild.bat b/src/msvcbuild.bat
2+
index 69c0c61a..a5bcde7b 100644
3+
--- a/src/msvcbuild.bat
4+
+++ b/src/msvcbuild.bat
5+
@@ -15,15 +15,15 @@
6+
7+
@setlocal
8+
@rem Add more debug flags here, e.g. DEBUGCFLAGS=/DLUA_USE_ASSERT
9+
-@set DEBUGCFLAGS=
10+
-@set LJCOMPILE=cl /nologo /c /O2 /W3 /D_CRT_SECURE_NO_DEPRECATE /D_CRT_STDIO_INLINE=__declspec(dllexport)__inline
11+
+@set DEBUGCFLAGS=/Od
12+
+@set LJCOMPILE=cl /nologo /c /O2 /W3 /D_CRT_SECURE_NO_DEPRECATE /D_CRT_STDIO_INLINE=__declspec(dllexport)__inline /Z7 /GL
13+
@set LJDYNBUILD=/DLUA_BUILD_AS_DLL /MD
14+
@set LJDYNBUILD_DEBUG=/DLUA_BUILD_AS_DLL /MDd
15+
@set LJCOMPILETARGET=/Zi
16+
@set LJLINKTYPE=/DEBUG /RELEASE
17+
@set LJLINKTYPE_DEBUG=/DEBUG
18+
@set LJLINKTARGET=/OPT:REF /OPT:ICF /INCREMENTAL:NO
19+
-@set LJLINK=link /nologo
20+
+@set LJLINK=link /nologo /LTCG
21+
@set LJMT=mt /nologo
22+
@set LJLIB=lib /nologo /nodefaultlib
23+
@set DASMDIR=..\dynasm
24+
@@ -105,10 +105,10 @@ buildvm -m folddef -o lj_folddef.h lj_opt_fold.c
25+
@set LJLINK=%LJLINK% %LJLINKTYPE% %LJLINKTARGET%
26+
@if "%1"=="amalg" goto :AMALGDLL
27+
@if "%1"=="static" goto :STATIC
28+
-%LJCOMPILE% %LJDYNBUILD% lj_*.c lib_*.c
29+
+%LJCOMPILE% %LJDYNBUILD% lj_*.c lib_*.c /Fdlua51.pdb
30+
@if errorlevel 1 goto :BAD
31+
@if "%1"=="mixed" goto :STATICLIB
32+
-%LJLINK% /DLL /OUT:%LJDLLNAME% lj_*.obj lib_*.obj
33+
+%LJLINK% /DLL /OUT:%LJDLLNAME% lj_*.obj lib_*.obj /DEBUG /OPT:ICF /OPT:REF
34+
@if errorlevel 1 goto :BAD
35+
@goto :MTDLL
36+
:STATIC
37+
@@ -136,7 +136,7 @@ buildvm -m folddef -o lj_folddef.h lj_opt_fold.c
38+
if exist %LJDLLNAME%.manifest^
39+
%LJMT% -manifest %LJDLLNAME%.manifest -outputresource:%LJDLLNAME%;2
40+
41+
-%LJCOMPILE% luajit.c
42+
+%LJCOMPILE% luajit.c /Fdluajit.pdb
43+
@if errorlevel 1 goto :BAD
44+
%LJLINK% /OUT:luajit.exe luajit.obj %LJLIBNAME%
45+
@if errorlevel 1 goto :BAD
46+
@@ -164,4 +164,5 @@ if exist luajit.exe.manifest^
47+
@goto :END
48+
:FAIL
49+
@echo You must open a "Visual Studio Command Prompt" to run this script
50+
+exit 1
51+
:END

0 commit comments

Comments
 (0)