#pragma once

#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"

/* Debug stuff. */
#ifdef NODEBUG
#define LLUA_DEBUG(str, args...) \
  (fprintf(stdout, "Lua: "str"\n", ## args))

#define LLUA_INVALID_PARAMETER() { \
  LLUA_DEBUG("[%s] Invalid parameter (%s:%d)", __func__, __FILE__, __LINE__); \
  return 0; \
}

#define LLUA_MIN_ARGS(n) \
  if(lua_gettop(L) < n) { \
    LLUA_DEBUG("[%s] Too few arguments (%s:%d)", __func__, __FILE__, __LINE__); \
    return 0; \
  }
#else /* NODEBUG. */
#define LLUA_DEBUG(str, args...)  do {;} while(0)
#define LLUA_MIN_ARGS(n)          do {;} while(0)
#define LLUA_INVALID_PARAMETER()  do {;} while(0)
#endif /* NODEBUG. */

/* Comfortability macros. */
#define luaL_dobuffer(L, b, n, s) \
  (luaL_loadbuffer(L, b, n, s) || lua_pcall(L, 0, LUA_MULTRET, 0))