More work on moving engine into dlmalloc heap
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include "luastack.hpp"
|
||||
#include <iostream>
|
||||
#include <cassert>
|
||||
#include <cstdio>
|
||||
|
||||
LuaSpecial LuaRegistry(LUA_REGISTRYINDEX);
|
||||
LuaNilMarker LuaNil;
|
||||
@@ -11,20 +12,12 @@ LuaFunctionReg::LuaFunctionReg(const char *n, const char *a, const char *d, lua_
|
||||
args_ = a;
|
||||
docs_ = d;
|
||||
func_ = f;
|
||||
next_ = LuaFunctionRegistry;
|
||||
LuaFunctionRegistry = this;
|
||||
}
|
||||
|
||||
LuaFunctionReg::List LuaFunctionReg::all() {
|
||||
LuaFunctionReg::List result;
|
||||
for (LuaFunctionReg *r = LuaFunctionRegistry; r != 0; r = r->next_) {
|
||||
result.push_back(r);
|
||||
}
|
||||
return result;
|
||||
next_ = All;
|
||||
All = this;
|
||||
}
|
||||
|
||||
const LuaFunctionReg *LuaFunctionReg::lookup(lua_CFunction fn) {
|
||||
for (const LuaFunctionReg *r = LuaFunctionRegistry; r != 0; r = r->next_) {
|
||||
for (const LuaFunctionReg *r = All; r != 0; r = r->next_) {
|
||||
if (r->func_ == fn) {
|
||||
return r;
|
||||
}
|
||||
@@ -32,8 +25,21 @@ const LuaFunctionReg *LuaFunctionReg::lookup(lua_CFunction fn) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
LuaFunctionReg *LuaFunctionReg::LuaFunctionRegistry;
|
||||
LuaFunctionReg *LuaFunctionReg::All;
|
||||
|
||||
static int panicf(lua_State *L) {
|
||||
const char *p = lua_tostring(L, -1);
|
||||
fprintf(stderr, "PANIC: unprotected error in call to Lua API (%s)\n", p);
|
||||
fflush(stderr);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
lua_State *LuaStack::newstate (lua_Alloc allocf) {
|
||||
lua_State *L = lua_newstate(allocf, NULL);
|
||||
if (L) lua_atpanic(L, &panicf);
|
||||
return L;
|
||||
}
|
||||
|
||||
bool LuaStack::ckboolean(LuaSlot s) const {
|
||||
luaL_checktype(L_, s, LUA_TBOOLEAN);
|
||||
@@ -154,7 +160,7 @@ lua_State *LuaStack::newthread(LuaSlot target) const {
|
||||
return result;
|
||||
}
|
||||
|
||||
bool LuaStack::validclassname(const eng::string &cname) {
|
||||
bool LuaStack::validclassname(std::string_view cname) {
|
||||
if (cname.empty()) return false;
|
||||
if (cname == "_G") return false;
|
||||
return true;
|
||||
@@ -243,15 +249,7 @@ eng::string LuaStack::getclass(LuaSlot classtab, LuaSlot classname) const {
|
||||
}
|
||||
}
|
||||
|
||||
eng::string LuaStack::getclass(LuaSlot tab, const char *name) const {
|
||||
push_any_value(name);
|
||||
LuaSpecial classname(lua_gettop(L_));
|
||||
eng::string err = getclass(tab, classname);
|
||||
lua_pop(L_, 1);
|
||||
return err;
|
||||
}
|
||||
|
||||
eng::string LuaStack::getclass(LuaSlot tab, const eng::string &name) const {
|
||||
eng::string LuaStack::getclass(LuaSlot tab, std::string_view name) const {
|
||||
push_any_value(name);
|
||||
LuaSpecial classname(lua_gettop(L_));
|
||||
eng::string err = getclass(tab, classname);
|
||||
@@ -288,14 +286,7 @@ void LuaStack::makeclass(LuaSlot classtab, LuaSlot classname) const {
|
||||
LS.result();
|
||||
}
|
||||
|
||||
void LuaStack::makeclass(LuaSlot tab, const char *name) const {
|
||||
push_any_value(name);
|
||||
LuaSpecial classname(lua_gettop(L_));
|
||||
makeclass(tab, classname);
|
||||
lua_pop(L_, 1);
|
||||
}
|
||||
|
||||
void LuaStack::makeclass(LuaSlot tab, const eng::string &name) const {
|
||||
void LuaStack::makeclass(LuaSlot tab, std::string_view name) const {
|
||||
push_any_value(name);
|
||||
LuaSpecial classname(lua_gettop(L_));
|
||||
makeclass(tab, classname);
|
||||
|
||||
Reference in New Issue
Block a user