lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I also created a C header library named L8n (loon).

There are things like a family of function-like macros

l8n_pair_KV(lua_State *L, k, v)

where K is the type of key and V the type of the values.

I also abstracted the userdata metatable creation so it register the __name metamethod, as convenience for printing on Lua side among other things, so my code can be compiled for Lua from 5.1 to 5.4.

These are very cool things, as avoid common mistakes dealing with Lua stack and simplifying the further code reading, but...

As Lua philosophy keeps the language small and simple, I think the same extends for the C Api side.

The macro possibilities are enormous but it could come as bloated Lua source and more complex learning curve for the developers that use C Api, while needing more attention on updates and documenting.

So I really like the macro idea, since it be an external framework to the language.



_________________

Thadeu de Paula https://codeberg.org/waxlab https://codeberg.org/arkt8

Enviado via Proton Mail para dispositivos móveis



-------- Mensagem Original --------
Em 5 de fev de 2023 11:25, Tomas Mudrunka < mudrunka@spoje.net> escreveu:

Hello, in all of projects where i am using C API of Lua, i am using following macros for convenience: #define lua_setglobal_integer(L,n,v) (lua_pushinteger(L, v), lua_setglobal(L, n)) #define lua_setglobal_nil(L,n) (lua_pushnil(L), lua_setglobal(L, n)) #define lua_setglobal_boolean(L,n,v) (lua_pushboolean(L, v), lua_setglobal(L, n)) #define lua_setglobal_number(L,n,v) (lua_pushnumber(L, v), lua_setglobal(L, n)) #define lua_setglobal_string(L,n,v) (lua_pushstring(L, v), lua_setglobal(L, n)) #define lua_setglobal_lstring(L,n,v,l) (lua_pushlstring(L, v, l), lua_setglobal(L, n)) I think it would really be worth adding similar stuff to lua.h. Perhaps creating lua_extra.h if there are reasons for not adding such thing to main header file. What do you think? -- S pozdravem Best regards Tomáš Mudruňka