LuaYard/LuaVM.cpp

63 lines
1.1 KiB
C++

#include "LuaVM.h"
void pushvalue(lua_State* L, int val)
{
lua_pushinteger(L, val);
}
void pushvalue(lua_State* L, double val)
{
lua_pushnumber(L, val);
}
void pushvalue(lua_State* L, const char* str)
{
lua_pushstring(L, str);
}
void pushvalue(lua_State* L, const char* str, int len)
{
lua_pushlstring(L, str, len);
}
void pushvalue(lua_State* L, const std::string& str)
{
lua_pushlstring(L, str.c_str(), str.size());
}
void pushvalue(lua_State* L, lua_CFunction fn)
{
lua_pushcfunction(L, fn);
}
void pushvalue(lua_State* L, lua_CFunction fn, int nup)
{
lua_pushcclosure(L, fn, nup);
}
template<>
const char* getvalue(lua_State* L, int index) // LUA_TSTRING
{
return luaL_checkstring(L, index);
}
template<>
std::string getvalue(lua_State* L, int index) // LUA_TSTRING
{
size_t sz;
const char* s = luaL_checklstring(L, index, &sz);
return std::string(s, sz);
}
template<>
int getvalue(lua_State* L, int index) // LUA_TNUMBER
{
return (const int)luaL_checkinteger(L, index);
}
template<>
double getvalue(lua_State* L, int index) // LUA_TNUMBER
{
return luaL_checknumber(L, index);
}