Changed calling conventions again
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
#include "luastack.hpp"
|
||||
|
||||
LuaSlot LuaRegistry(LUA_REGISTRYINDEX);
|
||||
LuaSlot LuaGlobals(LUA_GLOBALSINDEX);
|
||||
LuaSpecial LuaRegistry(LUA_REGISTRYINDEX);
|
||||
LuaSpecial LuaGlobals(LUA_GLOBALSINDEX);
|
||||
LuaNilMarker LuaNil;
|
||||
|
||||
void LuaStack::count_slots_finalize(int narg, int nvar, int nret) {
|
||||
narg_ = narg;
|
||||
@@ -38,44 +39,22 @@ int LuaStack::result() {
|
||||
return nret_;
|
||||
}
|
||||
|
||||
void LuaStack::reg(lua_State *L, const char *classname, const char *funcname, lua_CFunction fn) {
|
||||
int top = lua_gettop(L);
|
||||
lua_pushvalue(L, LUA_GLOBALSINDEX);
|
||||
luaL_Reg reg;
|
||||
reg.name = funcname;
|
||||
reg.func = fn;
|
||||
luaL_register(L, classname, ®);
|
||||
lua_settop(L, top);
|
||||
LuaFunctionReg *LuaFunctionReg::LuaFunctionRegistry;
|
||||
|
||||
LuaFunctionReg::LuaFunctionReg(int m, const char *n, lua_CFunction f) {
|
||||
mode_ = m;
|
||||
name_ = n;
|
||||
func_ = f;
|
||||
next_ = LuaFunctionRegistry;
|
||||
LuaFunctionRegistry = this;
|
||||
}
|
||||
|
||||
void LuaStack::setnil(LuaSlot target) const {
|
||||
lua_pushnil(L_);
|
||||
lua_replace(L_, target);
|
||||
}
|
||||
|
||||
void LuaStack::setboolean(LuaSlot target, bool b) const {
|
||||
lua_pushboolean(L_, b ? 1 : 0);
|
||||
lua_replace(L_, target);
|
||||
}
|
||||
|
||||
void LuaStack::setboolean(LuaSlot target, int b) const {
|
||||
lua_pushboolean(L_, b);
|
||||
lua_replace(L_, target);
|
||||
}
|
||||
|
||||
void LuaStack::setstring(LuaSlot target, const char *str) const {
|
||||
lua_pushstring(L_, str);
|
||||
lua_replace(L_, target);
|
||||
}
|
||||
|
||||
void LuaStack::setstring(LuaSlot target, const std::string &str) const {
|
||||
lua_pushlstring(L_, str.c_str(), str.size());
|
||||
lua_replace(L_, target);
|
||||
}
|
||||
|
||||
void LuaStack::setnumber(LuaSlot target, double value) const {
|
||||
lua_pushnumber(L_, value);
|
||||
lua_replace(L_, target);
|
||||
LuaFunctionReg::List LuaFunctionReg::all() {
|
||||
LuaFunctionReg::List result;
|
||||
for (const LuaFunctionReg *r = LuaFunctionRegistry; r != 0; r = r->next_) {
|
||||
result.push_back(r);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string LuaStack::tostring(LuaSlot s) const {
|
||||
@@ -123,3 +102,11 @@ void LuaStack::newtable(LuaSlot target) const {
|
||||
lua_newtable(L_);
|
||||
lua_replace(L_, target);
|
||||
}
|
||||
|
||||
void LuaStack::check_nret(int xnret, int otop, int nret) const {
|
||||
int ntop = lua_gettop(L_);
|
||||
if ((nret != xnret)||(ntop != otop + xnret)) {
|
||||
luaL_error(L_, "expected %d return values", xnret);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user