mirror of
https://github.com/EQEmu/Server.git
synced 2026-06-11 15:58:36 +00:00
Revert "Build System Updated"
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2004 Daniel Wallin
|
||||
// Copyright (c) 2004 Daniel Wallin
|
||||
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the "Software"),
|
||||
@@ -22,121 +22,145 @@
|
||||
|
||||
#define LUABIND_BUILDING
|
||||
|
||||
#include <luabind/lua_include.hpp> // for lua_pushstring, lua_rawset, etc
|
||||
#include <luabind/lua_include.hpp>
|
||||
|
||||
#include <luabind/config.hpp> // for LUABIND_API
|
||||
#include <luabind/typeid.hpp> // for type_id
|
||||
#include <luabind/detail/class_registry.hpp> // for class_registry
|
||||
#include <luabind/detail/class_rep.hpp> // for class_rep
|
||||
#include <luabind/detail/garbage_collector.hpp> // for garbage_collector
|
||||
#include <luabind/luabind.hpp>
|
||||
#include <luabind/detail/class_registry.hpp>
|
||||
#include <luabind/detail/class_rep.hpp>
|
||||
#include <luabind/detail/operator_id.hpp>
|
||||
|
||||
namespace luabind { namespace detail {
|
||||
|
||||
#include <cassert> // for assert
|
||||
#include <map> // for map, etc
|
||||
#include <utility> // for pair
|
||||
LUABIND_API void push_instance_metatable(lua_State* L);
|
||||
|
||||
namespace luabind {
|
||||
namespace detail {
|
||||
namespace {
|
||||
|
||||
LUABIND_API void push_instance_metatable(lua_State* L);
|
||||
int create_cpp_class_metatable(lua_State* L)
|
||||
{
|
||||
lua_newtable(L);
|
||||
|
||||
namespace {
|
||||
// mark the table with our (hopefully) unique tag
|
||||
// that says that the user data that has this
|
||||
// metatable is a class_rep
|
||||
lua_pushstring(L, "__luabind_classrep");
|
||||
lua_pushboolean(L, 1);
|
||||
lua_rawset(L, -3);
|
||||
|
||||
/// @todo is this redundant with the following function? All that differs is the __gc closure
|
||||
int create_cpp_class_metatable(lua_State* L)
|
||||
{
|
||||
lua_newtable(L);
|
||||
lua_pushstring(L, "__gc");
|
||||
lua_pushcclosure(
|
||||
L
|
||||
, &garbage_collector_s<
|
||||
detail::class_rep
|
||||
>::apply
|
||||
, 0);
|
||||
|
||||
// mark the table with our (hopefully) unique tag
|
||||
// that says that the user data that has this
|
||||
// metatable is a class_rep
|
||||
lua_pushstring(L, "__luabind_classrep");
|
||||
lua_pushboolean(L, 1);
|
||||
lua_rawset(L, -3);
|
||||
lua_rawset(L, -3);
|
||||
|
||||
lua_pushstring(L, "__gc");
|
||||
lua_pushcclosure(L, &garbage_collector<class_rep>, 0);
|
||||
lua_pushstring(L, "__call");
|
||||
lua_pushcclosure(L, &class_rep::constructor_dispatcher, 0);
|
||||
lua_rawset(L, -3);
|
||||
|
||||
lua_rawset(L, -3);
|
||||
lua_pushstring(L, "__index");
|
||||
lua_pushcclosure(L, &class_rep::static_class_gettable, 0);
|
||||
lua_rawset(L, -3);
|
||||
|
||||
lua_pushstring(L, "__call");
|
||||
lua_pushcclosure(L, &class_rep::constructor_dispatcher, 0);
|
||||
lua_rawset(L, -3);
|
||||
lua_pushstring(L, "__newindex");
|
||||
lua_pushcclosure(L, &class_rep::lua_settable_dispatcher, 0);
|
||||
lua_rawset(L, -3);
|
||||
|
||||
lua_pushstring(L, "__index");
|
||||
lua_pushcclosure(L, &class_rep::static_class_gettable, 0);
|
||||
lua_rawset(L, -3);
|
||||
return luaL_ref(L, LUA_REGISTRYINDEX);
|
||||
}
|
||||
|
||||
lua_pushstring(L, "__newindex");
|
||||
lua_pushcclosure(L, &class_rep::lua_settable_dispatcher, 0);
|
||||
lua_rawset(L, -3);
|
||||
int create_lua_class_metatable(lua_State* L)
|
||||
{
|
||||
lua_newtable(L);
|
||||
|
||||
return luaL_ref(L, LUA_REGISTRYINDEX);
|
||||
}
|
||||
lua_pushstring(L, "__luabind_classrep");
|
||||
lua_pushboolean(L, 1);
|
||||
lua_rawset(L, -3);
|
||||
|
||||
int create_lua_class_metatable(lua_State* L)
|
||||
{
|
||||
return create_cpp_class_metatable(L);
|
||||
}
|
||||
lua_pushstring(L, "__gc");
|
||||
lua_pushcclosure(
|
||||
L
|
||||
, &detail::garbage_collector_s<
|
||||
detail::class_rep
|
||||
>::apply
|
||||
, 0);
|
||||
|
||||
} // namespace unnamed
|
||||
lua_rawset(L, -3);
|
||||
|
||||
class class_rep;
|
||||
lua_pushstring(L, "__newindex");
|
||||
lua_pushcclosure(L, &class_rep::lua_settable_dispatcher, 0);
|
||||
lua_rawset(L, -3);
|
||||
|
||||
class_registry::class_registry(lua_State* L)
|
||||
: m_cpp_class_metatable(create_cpp_class_metatable(L))
|
||||
, m_lua_class_metatable(create_lua_class_metatable(L))
|
||||
{
|
||||
push_instance_metatable(L);
|
||||
m_instance_metatable = luaL_ref(L, LUA_REGISTRYINDEX);
|
||||
}
|
||||
lua_pushstring(L, "__call");
|
||||
lua_pushcclosure(L, &class_rep::constructor_dispatcher, 0);
|
||||
lua_rawset(L, -3);
|
||||
|
||||
class_registry* class_registry::get_registry(lua_State* L)
|
||||
{
|
||||
lua_pushstring(L, "__index");
|
||||
lua_pushcclosure(L, &class_rep::static_class_gettable, 0);
|
||||
lua_rawset(L, -3);
|
||||
|
||||
return luaL_ref(L, LUA_REGISTRYINDEX);
|
||||
}
|
||||
|
||||
} // namespace unnamed
|
||||
|
||||
class class_rep;
|
||||
|
||||
class_registry::class_registry(lua_State* L)
|
||||
: m_cpp_class_metatable(create_cpp_class_metatable(L))
|
||||
, m_lua_class_metatable(create_lua_class_metatable(L))
|
||||
{
|
||||
push_instance_metatable(L);
|
||||
m_instance_metatable = luaL_ref(L, LUA_REGISTRYINDEX);
|
||||
}
|
||||
|
||||
class_registry* class_registry::get_registry(lua_State* L)
|
||||
{
|
||||
|
||||
#ifdef LUABIND_NOT_THREADSAFE
|
||||
|
||||
// if we don't have to be thread safe, we can keep a
|
||||
// chache of the class_registry pointer without the
|
||||
// need of a mutex
|
||||
static lua_State* cache_key = 0;
|
||||
static class_registry* registry_cache = 0;
|
||||
if(cache_key == L) return registry_cache;
|
||||
// if we don't have to be thread safe, we can keep a
|
||||
// chache of the class_registry pointer without the
|
||||
// need of a mutex
|
||||
static lua_State* cache_key = 0;
|
||||
static class_registry* registry_cache = 0;
|
||||
if (cache_key == L) return registry_cache;
|
||||
|
||||
#endif
|
||||
|
||||
lua_pushstring(L, "__luabind_classes");
|
||||
lua_gettable(L, LUA_REGISTRYINDEX);
|
||||
class_registry* p = static_cast<class_registry*>(lua_touserdata(L, -1));
|
||||
lua_pop(L, 1);
|
||||
lua_pushstring(L, "__luabind_classes");
|
||||
lua_gettable(L, LUA_REGISTRYINDEX);
|
||||
class_registry* p = static_cast<class_registry*>(lua_touserdata(L, -1));
|
||||
lua_pop(L, 1);
|
||||
|
||||
#ifdef LUABIND_NOT_THREADSAFE
|
||||
|
||||
cache_key = L;
|
||||
registry_cache = p;
|
||||
cache_key = L;
|
||||
registry_cache = p;
|
||||
|
||||
#endif
|
||||
|
||||
return p;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
void class_registry::add_class(type_id const& info, class_rep* crep)
|
||||
{
|
||||
// class is already registered
|
||||
assert((m_classes.find(info) == m_classes.end())
|
||||
&& "you are trying to register a class twice");
|
||||
m_classes[info] = crep;
|
||||
}
|
||||
void class_registry::add_class(type_id const& info, class_rep* crep)
|
||||
{
|
||||
// class is already registered
|
||||
assert((m_classes.find(info) == m_classes.end())
|
||||
&& "you are trying to register a class twice");
|
||||
m_classes[info] = crep;
|
||||
}
|
||||
|
||||
class_rep* class_registry::find_class(type_id const& info) const
|
||||
{
|
||||
std::map<type_id, class_rep*>::const_iterator i(
|
||||
m_classes.find(info));
|
||||
class_rep* class_registry::find_class(type_id const& info) const
|
||||
{
|
||||
std::map<type_id, class_rep*>::const_iterator i(
|
||||
m_classes.find(info));
|
||||
|
||||
if(i == m_classes.end()) return 0; // the type is not registered
|
||||
return i->second;
|
||||
}
|
||||
if (i == m_classes.end()) return 0; // the type is not registered
|
||||
return i->second;
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
} // namespace luabind
|
||||
}} // namespace luabind::detail
|
||||
|
||||
|
||||
Reference in New Issue
Block a user