Skip to content

Commit

Permalink
Update lua example
Browse files Browse the repository at this point in the history
  • Loading branch information
halx99 committed Nov 23, 2024
1 parent 7ac457c commit 52319e3
Show file tree
Hide file tree
Showing 11 changed files with 144 additions and 144 deletions.
100 changes: 54 additions & 46 deletions 1k/1kiss.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ $1k = [_1kiss]::new()
# x.y.z~x2.y2.z2 : range
$manifest = @{
msvc = '14.39+'; # cl.exe @link.exe 14.39 VS2022 17.9.x
vs = '12.0+';
ndk = 'r23c';
xcode = '13.0.0+'; # range
# _EMIT_STL_ERROR(STL1000, "Unexpected compiler version, expected Clang xx.x.x or newer.");
Expand Down Expand Up @@ -597,7 +598,8 @@ function find_prog($name, $path = $null, $mode = 'ONLY', $cmd = $null, $params =
else {
if (!$preferredVer.Contains('*')) {
$checkVerCond = '$(version_eq $foundVer $preferredVer)'
} else {
}
else {
$wildcardVer = $preferredVer
$preferredVer = $wildcardVer.TrimEnd('.*')
$checkVerCond = '$(version_like $foundVer $wildcardVer)'
Expand Down Expand Up @@ -752,6 +754,46 @@ function fetch_pkg($url, $exrep = $null) {
if ($pfn_rename) { &$pfn_rename }
}


#
# Find latest installed: Visual Studio 12 2013 +
# installationVersion
# installationPath
# instanceId: used for EnterDevShell
# result:
# $Global:VS_INST
#
$Global:VS_INST = $null
function find_vs() {
if (!$Global:VS_INST) {
$VSWHERE_EXE = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
$eap = $ErrorActionPreference
$ErrorActionPreference = 'SilentlyContinue'

$required_vs_ver = $manifest['vs']
if (!$required_vs_ver) { $required_vs_ver = '12.0+' }

$require_comps = @('Microsoft.Component.MSBuild', 'Microsoft.VisualStudio.Component.VC.Tools.x86.x64')
$vs_installs = ConvertFrom-Json "$(&$VSWHERE_EXE -version $required_vs_ver.TrimEnd('+') -format 'json' -requires $require_comps)"
$ErrorActionPreference = $eap

if ($vs_installs) {
$vs_inst_latest = $null
$vs_ver = ''
foreach ($vs_inst in $vs_installs) {
$inst_ver = [VersionEx]$vs_inst.installationVersion
if ($vs_ver -lt $inst_ver) {
$vs_ver = $inst_ver
$vs_inst_latest = $vs_inst
}
}
$Global:VS_INST = $vs_inst_latest
} else {
throw "No suitable visual studio installed, required: $required_vs_ver"
}
}
}

# setup nuget, not add to path
function setup_nuget() {
if (!$manifest['nuget']) { return $null }
Expand Down Expand Up @@ -1231,11 +1273,12 @@ function setup_emsdk() {
function setup_msvc() {
$cl_prog, $cl_ver = find_prog -name 'msvc' -cmd 'cl' -silent $true -usefv $true
if (!$cl_prog) {
if ($VS_INST) {
Import-Module "$VS_PATH\Common7\Tools\Microsoft.VisualStudio.DevShell.dll"
if ($Global:VS_INST) {
$vs_path = $Global:VS_INST.installationPath
Import-Module "$vs_path\Common7\Tools\Microsoft.VisualStudio.DevShell.dll"
$dev_cmd_args = "-arch=$target_cpu -host_arch=x64 -no_logo"
if (!$manifest['msvc'].EndsWith('+')) { $dev_cmd_args += " -vcvars_ver=$cl_ver" }
Enter-VsDevShell -VsInstanceId $VS_INST.instanceId -SkipAutomaticLocation -DevCmdArguments $dev_cmd_args
Enter-VsDevShell -VsInstanceId $Global:VS_INST.instanceId -SkipAutomaticLocation -DevCmdArguments $dev_cmd_args

$cl_prog, $cl_ver = find_prog -name 'msvc' -cmd 'cl' -silent $true -usefv $true
$1k.println("Using msvc: $cl_prog, version: $cl_ver")
Expand Down Expand Up @@ -1297,44 +1340,6 @@ function setup_gclient() {
$env:DEPOT_TOOLS_WIN_TOOLCHAIN = 0
}

#
# Find latest installed: Visual Studio 12 2013 +
# installationVersion
# instanceId EnterDevShell can use it
# result:
# $Global:VS_VERSION
# $Global:VS_INST
# $Global:VS_PATH
#
$Global:VS_VERSION = $null
$Global:VS_PATH = $null
$Global:VS_INST = $null
function find_vs_latest() {
$vs_version = [VersionEx]'12.0'
if (!$Global:VS_INST) {
$VSWHERE_EXE = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
$eap = $ErrorActionPreference
$ErrorActionPreference = 'SilentlyContinue'

$vs_installs = ConvertFrom-Json "$(&$VSWHERE_EXE -version '12.0' -format 'json')"
$ErrorActionPreference = $eap

if ($vs_installs) {
$vs_inst_latest = $null
foreach ($vs_inst in $vs_installs) {
$inst_ver = [VersionEx]$vs_inst.installationVersion
if ($vs_version -lt $inst_ver) {
$vs_version = $inst_ver
$vs_inst_latest = $vs_inst
}
}
$Global:VS_PATH = $vs_inst_latest.installationPath
$Global:VS_INST = $vs_inst_latest
}
}
$Global:VS_VERSION = $vs_version
}

# preprocess methods:
# <param>-inputOptions</param> [CMAKE_OPTIONS]
function preprocess_win([string[]]$inputOptions) {
Expand All @@ -1350,21 +1355,23 @@ function preprocess_win([string[]]$inputOptions) {
$arch = if ($options.a -eq 'x86') { 'Win32' } else { $options.a }

# arch
if ($VS_VERSION -ge [VersionEx]'16.0') {
$vs_ver = [VersionEx]$Global:VS_INST.installationVersion
if ($vs_ver -ge [VersionEx]'16.0') {
$outputOptions += '-A', $arch
if ($TOOLCHAIN_VER) {
$outputOptions += "-Tv$TOOLCHAIN_VER"
}
}
else {
if (!$TOOLCHAIN_VER) { $TOOLCHAIN_VER = "$($vs_ver.Major)0" }
$gens = @{
'120' = 'Visual Studio 12 2013';
'140' = 'Visual Studio 14 2015'
"150" = 'Visual Studio 15 2017';
}
$Script:cmake_generator = $gens[$TOOLCHAIN_VER]
if (!$Script:cmake_generator) {
throw "Unsupported toolchain: $TOOLCHAIN"
throw "Unsupported toolchain: $TOOLCHAIN$TOOLCHAIN_VER"
}
if ($options.a -eq "x64") {
$Script:cmake_generator += ' Win64'
Expand Down Expand Up @@ -1558,7 +1565,7 @@ $null = setup_glslcc
$cmake_prog, $Script:cmake_ver = setup_cmake

if ($Global:is_win_family) {
find_vs_latest
find_vs
$nuget_prog = setup_nuget
}

Expand Down Expand Up @@ -1614,7 +1621,8 @@ if (!$setupOnly) {
if ($is_host_target) {
if (!$is_host_cpu) {
$out_dir = "${prefix}${TARGET_CPU}"
} else {
}
else {
$out_dir = $prefix.TrimEnd("_")
}
}
Expand Down
6 changes: 3 additions & 3 deletions 1k/install-pwsh.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ mkdir -p $cacheDir

pwsh_ver=$1
if [ "$pwsh_ver" = "" ] ; then
pwsh_ver='7.4.4'
pwsh_ver='7.4.6'
fi

pwsh_min_ver=$2
Expand Down Expand Up @@ -64,8 +64,8 @@ elif [ $HOST_OS = 'Linux' ] ; then
curl -L "https://github.com/PowerShell/PowerShell/releases/download/v$pwsh_ver/$pwsh_pkg" -o "$pwsh_pkg_out"
fi
sudo_cmd=$(which sudo)
$sudo_cmd dpkg -i "$pwsh_pkg_out"
$sudo_cmd apt-get install -f
$sudo_cmd dpkg -i --ignore-depends=libicu72 "$pwsh_pkg_out"
$sudo_cmd apt-get install -f powershell
elif command -v pacman > /dev/null; then # Linux distro: Arch
# refer: https://ephos.github.io/posts/2018-9-17-Pwsh-ArchLinux
# available pwsh version, refer to: https://aur.archlinux.org/packages/powershell-bin
Expand Down
23 changes: 3 additions & 20 deletions examples/lua/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

#if defined(_WIN32)
# include <Windows.h>
# pragma comment(lib, "winmm.lib")
# include "yasio/wtimer_hres.hpp"
#endif

int main(int argc, char** argv)
Expand All @@ -22,15 +22,8 @@ int main(int argc, char** argv)
SetConsoleOutputCP(CP_UTF8);
#endif

#if defined(_WIN32) && WINAPI_FAMILY != WINAPI_FAMILY_APP
UINT TARGET_RESOLUTION = 1; // 1 millisecond target resolution
TIMECAPS tc;
UINT wTimerRes = 0;
if (TIMERR_NOERROR == timeGetDevCaps(&tc, sizeof(TIMECAPS)))
{
wTimerRes = (std::min)((std::max)(tc.wPeriodMin, TARGET_RESOLUTION), tc.wPeriodMax);
timeBeginPeriod(wTimerRes);
}
#if defined(_WIN32)
yasio::wtimer_hres whres;
#endif

#if YASIO__HAS_CXX14
Expand Down Expand Up @@ -78,15 +71,5 @@ int main(int argc, char** argv)
std::this_thread::sleep_for(std::chrono::milliseconds(50));
} while (!update(50.0 / 1000));
#endif

#if defined(_WIN32) && WINAPI_FAMILY != WINAPI_FAMILY_APP
///////////////////////////////////////////////////////////////////////////
/////////////// restoring timer resolution
///////////////////////////////////////////////////////////////////////////
if (wTimerRes != 0)
{
timeEndPeriod(wTimerRes);
}
#endif
return 0;
}
12 changes: 10 additions & 2 deletions examples/lua/scripts/example.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
-- yasio 4.0.0 demo
-- yasio 4.3.x demo

local proto = require 'protocol_enc'
local yasio = require 'yasio' -- constants

Expand Down Expand Up @@ -159,4 +160,11 @@ if(yasio.loop) then
end)
end

return yasio_update
local function yasio_stop()
client:stop()
server:stop()
end

print('yasio - example started, version:' .. yasio.version)

return {update = yasio_update, stop = yasio_stop}
3 changes: 2 additions & 1 deletion extensions/yasio_http/HttpCookie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@
#include "yasio_http/HttpCookie.h"
#include "yasio_http/Uri.h"
#include "yasio/utils.hpp"
#include "yasio/fsutils.hpp"

#include "yasio/split.hpp"
#include "yasio/file.hpp"

#include <stdio.h>
#include <stdlib.h>
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"versions": {
"1kdist": "v90"
"1kdist": "v93"
},
"mirrors": {
"github": {
Expand Down
2 changes: 1 addition & 1 deletion tests/ssl/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void yasioTest()

obs.write_bytes("User-Agent: Mozilla/5.0 (Windows NT 10.0; "
"WOW64) AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/108.0.5359.125 Safari/537.36\r\n");
"Chrome/131.0.0.0 Safari/537.36\r\n");
obs.write_bytes("Accept: */*;q=0.8\r\n");
obs.write_bytes("Connection: Close\r\n\r\n");

Expand Down
2 changes: 1 addition & 1 deletion yasio/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ SOFTWARE.
/*
** The yasio version macros
*/
#define YASIO_VERSION_NUM 0x040301
#define YASIO_VERSION_NUM 0x040302

/*
** The macros used by io_service.
Expand Down
Loading

0 comments on commit 52319e3

Please sign in to comment.