10 ms·
A first person shooter in 571 lines of GNU Awk (2016)
- jandrese 4y agoWhat a delightfully insane project. AWK is under-appreciated IMHO. Read the short manual and you'll discover a world of functionality in a highly orthogonal interface. Pattern Match->Manipulate. An incredibly useful workflow for many tasks.
- no_wizard 4y agoI wish there was like a "libawk" or something like it for programmatic usage. Its really a neat piece of work that is limited on being only a shell program. At least, as far as I am aware, there is no programmatic interface
- pphysch 4y agoWhat would be a use case for this?
- no_wizard 4y agoText processing & extraction
- PhilipRoman 4y agoThis is a somewhat different idea but I'd like to be able to feed structured data (in memory objects) to an (user defined) awk-like script without the need to serialize/parse everything. This could be used for packet filtering, conditional breakpoints, file searching, syscall filtering and intercepting, etc. Basically wherever you need a user defined filter more powerful than regex. The embedder can decide what variables and functions to provide for each invocation of the script. You could get something like Wireshark filters out of the box: ip && port==1234 {print size, time} Graphviz includes a tool "gvpr" which essentially implements this idea for processing graphs but of course, they end up reimplementing a large part of awk.
- chaboud 4y agoAt this point I’be caved and just coerce through json via python and jam things through jq for most of my data inspection and sleuthing.
- benhoyt 4y agoI don't know of a "libawk" C library, but my GoAWK interpreter can also be used as a library (Go) library. See reference docs: https://pkg.go.dev/github.com/benhoyt/goawk/interp https://pkg.go.dev/github.com/benhoyt/goawk/interp A project that's using it that way is Benthos, a "stream processor" written in Go. Awk is one of the "processors", the components that filter and transform data: https://www.benthos.dev/docs/components/processors/awk https://www.benthos.dev/docs/components/processors/awk
- DiggyJohnson 4y agoI’ve been really impressed by your ability to share your project in entirely relevant threads recently. Hope that doesn’t sound snarky, because I actually mean it. Awesome project. Keep on.
- benhoyt 4y agoHehe, thanks. Yeah, I was on the fence about posting it the last time, thinking "Hmmm, am I promoting my own project too much?" But I've tried to only do it in very relevant contexts or when people ask and it would solve that question.
- nequo 4y agoGoAWK's CSV mode is a great addition to AWK. Have you thought about adding a JSON mode, too, to get an AWK-flavored alternative to jq? Edit: I see that you have: https://github.com/benhoyt/goawk/issues/152 https://github.com/benhoyt/goawk/issues/152
- benhoyt 4y agoYeah, my comment there more or less sums up the thought I've put in so far. AWK doesn't really have nested data structures, but a lot of JSON / JSON lines is fairly flat, so it may work. It shouldn't be too hard ... though as I've noted there, there are a few tricky design issues to work though. Hope to come back to this at some point!
- 4y ago
- wrp 4y agoGawk added facilities for writing extensions, but I don't see how to use it as a library. Funny I never thought of it, considering how much I like awk, but using awk instead of Lua as an embedded extension language sounds appealing.
- distantwarning7 4y agoI love Lua but I can also see AWK working like a charm here.
- yumaikas 4y agoWhere would you use this? Most languages have good enough string processing to imitate a lot of what AWK does
- chlorion 4y agoYou can write awk scripts directly if you start a file with a "awk -f" shebang or similar! I am not totally sure if this is what you mean or not, but it's much nicer than embedding the script into a bash source file.
- deleted 4y ago[deleted]
- PhillipT2014 4y agoPerhaps:https://github.com/neacsum/awklib https://github.com/neacsum/awklib and article on how to use: https://www.codeproject.com/Articles/5264205/Embedding-AWK-in-a-C-program https://www.codeproject.com/Articles/5264205/Embedding-AWK-i...
- avgcorrection 4y agoAn elegant tool for forgetting inbetween all my organic needs for it.
- glomgril 4y agoHell of a side project. As deranged as it is awesome.
- mikenew 4y agoLooking at the code it's not nearly as deranged as I would have expected. It's actually pretty easy to follow.
- harveywi 4y agoThey missed an opportunity to call this "Levenshtein 3D"
- pmarreck 4y agoI, at least, appreciated this joke =)
- amalgamated_inc 4y agoLiterally dead
- srgpqt 4y agoHuh. Did not know Awk could be so similar to Javascript. I certainly haven’t seen it written in this way before, as usually I only see it used for simple one-liners.
- czx4f4bd 4y agoAwk is a fun, surprisingly powerful language. Even plain mawk can do a lot, but gawk has debugger support, profiling, namespaces, and even network support. (I wouldn't necessarily go out of my way to use most of those features, but it's possible!) It's honestly worth giving the mawk and gawk manual a skim just to see what all they can do. I want to read through The AWK Programming Language as well. https://invisible-island.net/mawk/manpage/mawk.html https://invisible-island.net/mawk/manpage/mawk.html https://www.gnu.org/software/gawk/manual/gawk.html https://www.gnu.org/software/gawk/manual/gawk.html
- tannhaeuser 4y agoJavaScript syntax clearly is derived from awk's: the function keyword, regexp literals, for (x in a), optional semicolons, (associative) arrays, ... Brendan Eich said as much: "JS’s function keyword did come from AWK" [1]. [1]: https://brendaneich.com/2010/07/a-brief-history-of-javascript/ https://brendaneich.com/2010/07/a-brief-history-of-javascrip...
- benhoyt 4y agoYeah, they're both languages which are quite unlike C in operation, but both (by design) use C-like syntax to be more familiar to existing developers. I think AWK has survived incredibly well for a language that's 46 years old.
- jhbadger 4y agoThere is so much about Awk that just seems more modern than Perl, which largely replaced Awk in common usage in the mid 1990s. Maybe the similarity to Javascript (which as others have mentioned isn't coincidental) will encourage younger people to take a look at it.
- pmarreck 4y agoAwk is super interesting if you peel away a little. One nice thing about it is that the amount of code it takes to do something seems to scale quite linearly with the complexity of the thing you need to do. Which is exactly why you often see it in one-liners, but it's so much more. Recommend a deeper look at it.
- j0hnyl 4y agoI came across this not too long ago. I recently picked up awk and went looking for unique / unlikely programs written in the language. This is completely mind blowing.
- jandrese 4y agoI don't know if it was the RNG messing with me or something else, but almost all of the monsters ended up congregating in the elevator room when I played. I was basically just standing in the approach hallway blasting them away one after another.
- oweiler 4y agoI am shocked how readable the code is. Was expecting some Perl-like spaghetti.
- userbinator 4y agoYou could say that the code isn't really awkward to read.
- amalgamated_inc 4y agoThat's what she sed
- gchamonlive 4y agoMom! They spilled Reddit all over my hackernews!
- amalgamated_inc 4y agoGo ask your father.
- ufo 4y agoI was hoping for some clever abuse of AWK's patterns & regexes but clean code will also do :)
- mths 4y agoFor that, to start with, you'd need to be able to create a feedback loop of awk's output back to itself as input. For it not to interfere with rendering, it needs to be on a separate file descriptor from stdout. I found this snippet on stackexchange showing how exactly that is possible on Linux. > echo hello | gawk '!length{exit(0)} {print; print substr($0,2) >"/dev/fd/3"; fflush()}' 3>/dev/fd/0 This "renders" on stdout then feeds itself more input on /dev/fd/3.
- 4y ago
- revskill 4y agoCurious to know if there's language that differentiate between procedure (function with side-effect) and pure function at the syntax level.
- efdee 4y agoBASIC has SUB (for procedures) vs FUNCTION (for functions).
- etra0 4y agoNim does this, it has 'proc' and 'func'. They define a `func` as a procedure with no side effects using the macro `{.noSideEffect.}` [1]. [1] https://nim-lang.org/docs/manual.html#procedures-func https://nim-lang.org/docs/manual.html#procedures-func
- doodpants 4y agoI used Borland Turbo Pascal back in the '80s and '90s, and as I recall it had separate keywords and syntax for defining procedures vs. functions.
- tgv 4y agoThat was about returning a result or not. The void type made that redundant (in Algol-68).
- retzkek 4y agoFortran has subroutines and functions. Functions can take multiple arguments and return a single value (however arguments can also be modified). Subroutines can take multiple arguments, which can be inputs, outputs, or both (arguments can be declared inputs or outputs, but it's not required) and don't return a value. And then there's common blocks for sharing variables between subroutines...
- fortran77 4y agoAnd many languages that were influenced by it, from PL/I to CMS-2 (Both of which I used in my first years as a computer programmer)
- helf 4y agoThis is disgusting and I love it
- haolez 4y agoThis dev must be one of the few in the world that doesn't need Google or man pages when awk is needed :)
- klyrs 4y agoThe weird thing about awk is that it can be written to look like an ordinary c-inspired scripting language. But it also supports the terse one-liners that we see so often; and the general perception is that it's a language for wizards. The ordinary scripting language is hiding in plain sight.
- deleted 4y ago[deleted]
- dang 4y agoRelated: Show HN: 3D shooter in your terminal using raycasting in Awk - https://news.ycombinator.com/item?id=10896901 https://news.ycombinator.com/item?id=10896901 - Jan 2016 (55 comments)
- causi 4y agoIf you're interested in feats of low-size games, I offer you kkrieger, a 3D FPS that fits in 96KB. https://www.youtube.com/watch?v=8fZBUsn5RYg https://www.youtube.com/watch?v=8fZBUsn5RYg
- beezlebroxxxxxx 4y agoThis is wild. One wonders what would happen if the (perhaps misguided) ideals that shaped that project returned to being in vogue.
- sitkack 4y agoPrevious discussions for a post about how they achieved that feat. https://fgiesen.wordpress.com/2012/04/08/metaprogramming-for-madmen/ https://fgiesen.wordpress.com/2012/04/08/metaprogramming-for... Nov 12, 2020 https://news.ycombinator.com/item?id=25043199 https://news.ycombinator.com/item?id=25043199 Aug 8, 2019 https://news.ycombinator.com/item?id=20635640 https://news.ycombinator.com/item?id=20635640 May 13, 2014 https://news.ycombinator.com/item?id=7739599 https://news.ycombinator.com/item?id=7739599
- badsectoracula 4y agoProcedural generation for 3D content is something quite common nowadays - see Substance Designer as an example. AFAIK the people behind kkrieger tried to push their tool for commercial use at some point but it didn't seem to catch on - but that was years ago.
- lmm 4y agoHuge but somewhat dull games. No Man's Sky is probably the big name that went that way recently. Or, in its own way, Dwarf Fortress.
- Night_Thastus 4y agoI'm not sure I'd lump DF in there at all. It may be procedural generated, but there is a mountain of depth to it.
- dekhn 4y agoIn my UNIX learning history I skipped straight from sed to perl and didn't use awk. By the time I had switched to python, awk sounded awfully "old" to me. I went back recently and read more on it and now I understand: it was an excellent interpreted programming language that gave semiskilled programmers some things C didn't, like associative arrays, all nicely packaged within the UNIX frame of mind. In an alternative universe, perhaps awk, instead of perl and then python, would become the scripting language of choice.
- bcrl 4y agoPython is only slightly younger than awk at this point.
- deleted 4y ago[deleted]
- dev_tty01 4y agoFor many of us, it is the scripting language of choice...
- anthk 4y agoMost people naturally stepped from awk+sed+sh to Perl. At least for scripts longer than 30-40 lines where sh looks clunky with too much var substitution and clunky sed regexen. Perl is something between sh and C on syntax, but easier and with builting match/replace capabilities.
- carapace 4y agoThis was linked from "The State of the Awk (2020)" on the front page earlier today: https://news.ycombinator.com/item?id=34438560 https://news.ycombinator.com/item?id=34438560 See also "AWK As A Major Systems Programming Language — Revisited" also linked from that article: http://www.skeeve.com/awk-sys-prog.html http://www.skeeve.com/awk-sys-prog.html
- xs83 4y agoTIL that AWK is basically a fully featured programming language ( ⊙⊙)
- distortionfield 4y agoYeah didn’t realize that GitHub labeled it it’s own language either! Neat.
- anthk 4y agoThis is on the same level of crazyness as the Z-Machine interpreter written in PostScropt.
- leeoniya 4y agoyou may also like: https://nicholas.carlini.com/writing/2019/javascript-doom-clone-13k.html https://nicholas.carlini.com/writing/2019/javascript-doom-cl...
- cramjabsyn 4y agoWelcome to Ken’s Labyrinth
- asicsp 4y agoSee also https://github.com/freznicek/awesome-awk https://github.com/freznicek/awesome-awk Lists projects like "CHIP-8 emulator", "A console videoplayer", "Draw 3D objects" etc
- deafpolygon 4y agoImagine how many games would be possible today if we leveraged those techniques more often.
- voytec 4y agoCool stuff! BTW: gawk installation instructions for NetBSD and OpenBSD but not FreeBSD? That's a new one.
- vermaden 4y agoFortunately the gawk(1) package name is the same on FreeBSD :) # pkg install gawk
- kazinator 4y agoAwk is a kind of first-person shooter, for row and column text files.
- startupsfail 4y agoText output, right? Can ChatGPT play it?
- hipjiveguy 4y agoCan this be ported to mac awk ?