constrains function in Lua and C