frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Open in hackernews

Creating C closures from Lua closures

https://lowkpro.com/blog/creating-c-closures-from-lua-closures.html
35•publicdebates•4d ago

Comments

widdershins•3h ago
This doesn't seem like something that should require generating assembly to solve. Couldn't `CALLBACK` just return a table, which contains both the userdata pointer to `REAL_CALLBACK` and a value for `findex`, eliminating the global variable? Then `Add` could extract that. You could even make the table returned by `CALLBACK` callable in Lua with a metatable.

Or, if you're worried about performance/memory, you could allocate a struct for `CALLBACK` to return as userdata, containing the function pointer and `findex`. If you made a little allocator for these it would be extremely fast.

I'm sure I'm missing things, but the solution you chose feels like the nuclear option.

comex•3h ago
The code is passing the function pointers into Win32 APIs, so the caller side isn’t controlled; the callbacks have to work as native C function pointers.

This was probably posted in response to this other link from two days ago, which is about about JIT-compiling wndproc callbacks in particular; the comments discuss the “proper” way to do it, which is to use GWLP_USERDATA:

https://news.ycombinator.com/item?id=46259334

At least, that’s the proper way to do it if you control the entire application. But for what’s apparently a thin wrapper that exposes Win32 APIs directly to Lua, I can understand picking an approach that makes life easier for the Lua code author, even if it’s hackier under the hood. It also avoids the need to write custom behavior for each API.

CodesInChaos•49m ago
Well designed C APIs have a context/userdata parameter on their callbacks, which is registered and stored alongside the function pointer. Unfortunately WNDPROC lacks this parameter.

GWLP_USERDATA should be the best option, though the API for setting it and setting the WNDPROC being separate looks error prone.

psychoslave•47m ago
What’s the thing emulating so much activity around closures lately?

https://news.ycombinator.com/item?id=46228597

https://news.ycombinator.com/item?id=46259334

Also talking about the Knuth boy/man test: https://news.ycombinator.com/item?id=46020151

Not a bad thing, but that really question if there is some active micro-

shakna•43m ago
Why VirtualAlloc?

Lua has its own allocator, which will also collect for you. lua_newuserdata. At the expense of having to set executable yourself, but without all the inbuilt inefficiencies the article points out.

ufo•11m ago
I wonder if there would be a way to piggyback on top of GCC's nested function extension. It does something a little bit similar, with the dynamically generated functions.

SHARP, an approach to photorealistic view synthesis from a single image

https://apple.github.io/ml-sharp/
339•dvrp•7h ago•70 comments

A2UI: A Protocol for Agent-Driven Interfaces

https://a2ui.org/
30•makeramen•2h ago•13 comments

Children with cancer scammed out of millions fundraised for their treatment

https://www.bbc.com/news/articles/ckgz318y8elo
265•1659447091•5h ago•205 comments

Quill OS: An open-source OS for Kobo's eReaders

https://quill-os.org/
297•Curiositry•11h ago•94 comments

A linear-time alternative for Dimensionality Reduction and fast visualisation

https://medium.com/@roman.f/a-linear-time-alternative-to-t-sne-for-dimensionality-reduction-and-f...
67•romanfll•4h ago•19 comments

Bonsai: A Voxel Engine, from scratch

https://github.com/scallyw4g/bonsai
77•jesse__•5h ago•7 comments

Erdős Problem #1026

https://terrytao.wordpress.com/2025/12/08/the-story-of-erdos-problem-126/
96•tzury•6h ago•10 comments

Internal RFCs saved us months of wasted work

https://highimpactengineering.substack.com/p/the-illusion-of-shared-understanding
34•romannikolaev•5d ago•12 comments

ArkhamMirror: Airgapped investigation platform with CIA-style hypothesis testing

https://github.com/mantisfury/ArkhamMirror
10•ArkhamMirror•1h ago•1 comments

JetBlue flight averts mid-air collision with US Air Force jet

https://www.reuters.com/world/americas/jetblue-flight-averts-mid-air-collision-with-us-air-force-...
300•divbzero•12h ago•190 comments

Creating C closures from Lua closures

https://lowkpro.com/blog/creating-c-closures-from-lua-closures.html
35•publicdebates•4d ago•6 comments

I'm a Tech Lead, and nobody listens to me. What should I do?

https://world.hey.com/joaoqalves/i-m-a-tech-lead-and-nobody-listens-to-me-what-should-i-do-e16e454d
47•joaoqalves•2h ago•34 comments

“Are you the one?” is free money

https://blog.owenlacey.dev/posts/are-you-the-one-is-free-money/
347•samwho•4d ago•76 comments

8M users' AI conversations sold for profit by "privacy" extensions

https://www.koi.ai/blog/urban-vpn-browser-extension-ai-conversations-data-collection
521•takira•8h ago•180 comments

Native vs. emulation: World of Warcraft game performance on Snapdragon X Elite

https://rkblog.dev/posts/pc-hardware/pc-on-arm/x86_versus_arm_native_game/
81•geekman7473•11h ago•35 comments

7 Years, 2 Rebuilds, 40K+ Stars: Milvus Recap and Roadmap

https://milvus.io/blog/milvus-exceeds-40k-github-stars.md
22•Fendy•5d ago•8 comments

Show HN: I designed my own 3D printer motherboard

https://github.com/KaiPereira/Cheetah-MX4-Mini
75•kaipereira•1w ago•16 comments

High Performance SSH/SCP

https://www.psc.edu/hpn-ssh-home/
9•gslin•5d ago•3 comments

Essential Semiconductor Physics [pdf]

https://nanohub.org/resources/43623/download/Essential_Semiconductor_Physics.pdf
193•akshatjiwan•2d ago•7 comments

Economics of Orbital vs. Terrestrial Data Centers

https://andrewmccalip.com/space-datacenters
122•flinner•13h ago•178 comments

Chafa: Terminal Graphics for the 21st Century

https://hpjansson.org/chafa/
169•birdculture•17h ago•27 comments

Umbrel – Personal Cloud

https://umbrel.com
191•oldfuture•16h ago•105 comments

Rollstack (YC W23) is hiring multiple software engineers (TypeScript) US/Canada

https://www.ycombinator.com/companies/rollstack-2/jobs/QPqpb1n-software-engineer-typescript-us-ca...
1•yjallouli•9h ago

In Defense of Matlab Code

https://runmat.org/blog/in-defense-of-matlab-whiteboard-style-code
130•finbarr1987•3d ago•129 comments

The appropriate amount of effort is zero

https://expandingawareness.org/blog/the-appropriate-amount-of-effort-is-zero/
131•gmays•15h ago•78 comments

Mark V Shaney

https://en.wikipedia.org/wiki/Mark_V._Shaney
18•djoldman•4d ago•2 comments

Secret Documents Show Pepsi and Walmart Colluded to Raise Food Prices

https://www.thebignewsletter.com/p/secret-documents-show-pepsi-and-walmart
441•connor11528•14h ago•111 comments

Light intensity steers molecular assemblies into 1D, 2D or 3D structures

https://phys.org/news/2025-11-intensity-molecular-1d-2d-3d.html
28•PaulHoule•5d ago•3 comments

A kernel bug froze my machine: Debugging an async-profiler deadlock

https://questdb.com/blog/async-profiler-kernel-bug/
101•bluestreak•14h ago•17 comments

Ford kills the All-Electric F-150

https://www.wired.com/story/ford-kills-electric-f-150-lightning-for-hybrid/
372•sacred-rat•13h ago•589 comments