Lucciefr
Lua code caving, injection and exploration framework
Macros
luahelpers.h File Reference

Lua helpers declared as macros. More...

Go to the source code of this file.

Macros

#define LUA_CFUNC(fname)   int fname(lua_State *L)
 a macro for proper Lua CFunction declarations
 
#define LREG_NAME(L, func, name)
 register a C function for Lua (with a given name string) More...
 
#define LREG(L, func)   LREG_NAME(L, func, #func)
 register a C function for Lua, simply using the name of the function
 
#define LENUM(L, value)   lua_setglobal_int(L, #value, value)
 register an enum value for Lua, using its name
 
#define luaL_error_fname(L, ...)
 raise Lua error, but auto-prefix message with the function name "%s() " (see http://www.lua.org/manual/5.1/manual.html#luaL_error) More...
 
#define LUA_CHECKIDX(L, idx)
 protect against bad Lua stack index, zero is always invalid More...
 
#define LUA_ABSIDX(L, idx)
 relative Lua stack indices sometimes are hard to maintain, so convert it to an absolute one (when applicable) More...
 
#define LUA_CHKABSIDX(L, idx)
 combine the two macros (LUA_ABSIDX and LUA_CHECKIDX) More...
 
#define lua_iscdata(L, index)   (lua_type(L, index) == LUA_TCDATA)
 test for FFI <cdata> type
 
#define lua_setglobal_int(L, name, value)
 shortcut for pushinteger + setglobal More...
 
#define lua_setglobal_str(L, name, value)
 shortcut for pushstring + setglobal More...
 
#define lua_setglobal_ptr(L, name, value)
 shortcut for pushlightuserdata + setglobal More...
 

Detailed Description

Lua helpers declared as macros.

Macro Definition Documentation

#define LREG_NAME (   L,
  func,
  name 
)
Value:
do { \
lua_pushcfunction(L, (lua_CFunction)func); \
lua_setglobal(L, name); \
} while (0)

register a C function for Lua (with a given name string)

#define LUA_ABSIDX (   L,
  idx 
)
Value:
do { \
if (idx < 0) { idx += lua_gettop(L); idx++; } \
} while (0)

relative Lua stack indices sometimes are hard to maintain, so convert it to an absolute one (when applicable)

#define LUA_CHECKIDX (   L,
  idx 
)
Value:
do { \
if (idx == 0) \
luaL_error(L, "%s() Lua state %p, error: " \
"zero is not an acceptable stack index!", __func__, L); \
} while (0)

protect against bad Lua stack index, zero is always invalid

#define LUA_CHKABSIDX (   L,
  idx 
)
Value:
do { \
if (idx == 0) \
luaL_error(L, "%s() Lua state %p, error: " \
"zero is not an acceptable stack index!", __func__, L); \
if (idx < 0) { idx += lua_gettop(L); idx++; } \
} while (0)

combine the two macros (LUA_ABSIDX and LUA_CHECKIDX)

#define lua_setglobal_int (   L,
  name,
  value 
)
Value:
do { \
lua_pushinteger(L, value); \
lua_setglobal(L, name); \
} while (0)

shortcut for pushinteger + setglobal

#define lua_setglobal_ptr (   L,
  name,
  value 
)
Value:
do { \
lua_pushlightuserdata(L, value); \
lua_setglobal(L, name); \
} while (0)

shortcut for pushlightuserdata + setglobal

#define lua_setglobal_str (   L,
  name,
  value 
)
Value:
do { \
lua_pushstring(L, value); \
lua_setglobal(L, name); \
} while (0)

shortcut for pushstring + setglobal

#define luaL_error_fname (   L,
  ... 
)
Value:
do { \
lua_pushstring(L, __func__); \
lua_pushfstring(L, "() " __VA_ARGS__); \
lua_concat(L, 2); \
lua_error(L); \
} while (0)

raise Lua error, but auto-prefix message with the function name "%s() " (see http://www.lua.org/manual/5.1/manual.html#luaL_error)