Last active
September 27, 2023 00:30
-
-
Save ArmoredPony/107876f6a3fb775e3e9e738ecc64031f to your computer and use it in GitHub Desktop.
Simple Lua binding for QueryPerformanceCounter function from WinAPI. Returns a function, not a table.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "lua.h" | |
#include <windows.h> | |
static LARGE_INTEGER pc, pf; | |
static int queryperformancecounter(lua_State* L) { | |
QueryPerformanceCounter(&pc); | |
lua_pushnumber(L, (double)pc.QuadPart / pf.QuadPart); | |
return 1; | |
} | |
int luaopen_queryperformancecounter(lua_State* L) { | |
QueryPerformanceFrequency(&pf); | |
lua_pushcfunction(L, queryperformancecounter); | |
return 1; | |
} | |
// Compile with: | |
// gcc -O2 -shared -fPIC -o queryperformancecounter.dll lqueryperformancecounter.c <path/to/lua>/bin/lua54.dll -I<path/to/lua>/include | |
// Usage: | |
// local qpc = require 'queryperformancecounter' | |
// local t = qpc() | |
// print(qpc() - t) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment