2013-11-03 20:16:23 +00:00
|
|
|
/*
|
|
|
|
Copyright (c) 2013 Microsoft Corporation. All rights reserved.
|
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
|
|
|
Author: Leonardo de Moura
|
|
|
|
*/
|
2013-11-08 19:59:47 +00:00
|
|
|
#pragma once
|
2013-11-03 20:16:23 +00:00
|
|
|
#include <lua.hpp>
|
2013-11-08 19:59:47 +00:00
|
|
|
|
2013-11-03 20:16:23 +00:00
|
|
|
namespace lean {
|
|
|
|
void setfuncs(lua_State * L, luaL_Reg const * l, int nup);
|
2013-11-05 19:35:09 +00:00
|
|
|
bool testudata(lua_State * L, int idx, char const * mt);
|
2013-11-12 20:54:34 +00:00
|
|
|
int load(lua_State * L, lua_Reader reader, void * data, char const * source);
|
2013-11-08 16:26:04 +00:00
|
|
|
size_t objlen(lua_State * L, int idx);
|
2013-11-08 19:59:47 +00:00
|
|
|
void dofile(lua_State * L, char const * fname);
|
|
|
|
void dostring(lua_State * L, char const * str);
|
2013-11-14 00:30:59 +00:00
|
|
|
void pcall(lua_State * L, int nargs, int nresults, int errorfun);
|
2013-11-14 21:32:33 +00:00
|
|
|
int lessthan(lua_State * L, int idx1, int idx2);
|
|
|
|
int equal(lua_State * L, int idx1, int idx2);
|
2013-11-03 22:42:54 +00:00
|
|
|
/**
|
|
|
|
\brief Wrapper for invoking function f, and catching Lean exceptions.
|
|
|
|
*/
|
|
|
|
int safe_function_wrapper(lua_State * L, lua_CFunction f);
|
2013-11-04 23:05:04 +00:00
|
|
|
template<lua_CFunction F> int safe_function(lua_State * L) {
|
2013-11-03 22:42:54 +00:00
|
|
|
return safe_function_wrapper(L, F);
|
|
|
|
}
|
2013-11-08 04:48:49 +00:00
|
|
|
template<lua_CFunction F> void set_global_function(lua_State * L, char const * name) {
|
|
|
|
lua_pushcfunction(L, safe_function<F>);
|
|
|
|
lua_setglobal(L, name);
|
|
|
|
}
|
2013-11-13 19:46:09 +00:00
|
|
|
|
|
|
|
#define SET_GLOBAL_FUN(F, N) set_global_function<F>(L, N)
|
|
|
|
|
|
|
|
// Auxiliary macro for creating a Lua table that stores enumeration values
|
|
|
|
#define SET_ENUM(N, V) lua_pushstring(L, N); lua_pushinteger(L, static_cast<int>(V)); lua_settable(L, -3)
|
2013-11-03 20:16:23 +00:00
|
|
|
}
|