[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: A question of style for C module writers
- From: Charles Heywood <vandor2012@...>
- Date: Sun, 7 Apr 2019 07:08:49 +0000
I think I've seen the second option more than the first outside of autogenerated wrappers, I think because instead of a table lookup you just have a constant string. LuaJIT might optimize it out but for Lua in general I believe strings are faster, although
not as friendly to autocompletion and/or linting engines.
From: firstname.lastname@example.org <email@example.com> on behalf of Marc Balmer <firstname.lastname@example.org>
Sent: Sunday, April 7, 2019 2:00:49 AM
Subject: A question of style for C module writers
I have a question of style. It's about using constants in modules.
Let's say we have a fictious C library libfoo that defines a preprocessor symbol INFO with a value of e.g. 42.
Then I write a Lua module foo which exposes libfoo's functionality to Lua. Should INFO be an integer constant in foo or rather a string that is looked up using luaL_checkoption()?
foo.somefunc(foo.INFO, 'test data')
foo.somefunc('info', 'test data')
It's probably only a question of style or taste, but what is your opininion (or remarks) on this?