reorganize sources

This commit is contained in:
Eduardo Bart
2011-08-15 11:06:15 -03:00
parent 4e03b15b27
commit d8cc37afdb
113 changed files with 621 additions and 3437 deletions

View File

@@ -1,10 +1,11 @@
#ifndef LUADECLARATIONS_H
#define LUADECLARATIONS_H
#ifndef FRAMEWORK_LUA_DECLARATIONS_H
#define FRAMEWORK_LUA_DECLARATIONS_H
#include <global.h>
#include <framework/global.h>
class LuaInterface;
class LuaObject;
typedef std::function<int(LuaInterface*)> LuaCppFunction;
typedef std::unique_ptr<LuaCppFunction> LuaCppFunctionPtr;
typedef std::shared_ptr<LuaObject> LuaObjectPtr;

View File

@@ -11,21 +11,21 @@ void LuaException::generateLuaErrorMessage(const std::string& error, int traceLe
{
// append trace level to error message
if(traceLevel >= 0)
m_what = aux::make_string("LUA ERROR: ", g_lua.traceback(error, traceLevel));
m_what = fw::mkstr("LUA ERROR: ", g_lua.traceback(error, traceLevel));
else
m_what = aux::make_string("LUA ERROR: ", error);
m_what = fw::mkstr("LUA ERROR: ", error);
}
LuaBadNumberOfArgumentsException::LuaBadNumberOfArgumentsException(int expected, int got)
{
std::string error = "attempt to call a function with wrong number of arguments";
if(expected >= 0 && got >= 0)
error = aux::make_string(error, " (expected ", expected, ", but got ", got, ")");
error = fw::mkstr(error, " (expected ", expected, ", but got ", got, ")");
generateLuaErrorMessage(error, 1);
}
LuaBadValueCastException::LuaBadValueCastException(const std::string& luaTypeName, const std::string& cppTypeName)
{
std::string error = aux::make_string("attempt to cast a '", luaTypeName, "' lua value to '", cppTypeName, "'");
std::string error = fw::mkstr("attempt to cast a '", luaTypeName, "' lua value to '", cppTypeName, "'");
generateLuaErrorMessage(error, 0);
}

View File

@@ -1,7 +1,7 @@
#ifndef LUAEXCEPTION_H
#define LUAEXCEPTION_H
#include "luadeclarations.h"
#include "declarations.h"
class LuaException : public std::exception
{

View File

@@ -1,8 +1,8 @@
#include "luainterface.h"
#include <graphics/fontmanager.h>
#include <ui/ui.h>
#include <net/protocol.h>
#include <core/eventdispatcher.h>
#include <framework/graphics/fontmanager.h>
#include <framework/ui/ui.h>
#include <framework/net/protocol.h>
#include <framework/core/eventdispatcher.h>
void LuaInterface::registerFunctions()
{

View File

@@ -1,7 +1,7 @@
#include "luainterface.h"
#include "luaobject.h"
#include <core/resourcemanager.h>
#include <framework/core/resourcemanager.h>
#include <lua.hpp>
LuaInterface g_lua;
@@ -20,7 +20,7 @@ void LuaInterface::init()
createLuaState();
// check if demangle_type is working as expected
assert(aux::demangle_type<LuaObject>() == "LuaObject");
assert(fw::demangle_type<LuaObject>() == "LuaObject");
// register LuaObject, the base of all other objects
registerClass<LuaObject>();
@@ -125,12 +125,12 @@ void LuaInterface::registerClassMemberField(const std::string& className,
if(getFunction) {
pushCppFunction(getFunction);
setField(aux::make_string("get_", field));
setField(fw::mkstr("get_", field));
}
if(setFunction) {
pushCppFunction(setFunction);
setField(aux::make_string("set_", field));
setField(fw::mkstr("set_", field));
}
pop();
@@ -273,7 +273,7 @@ void LuaInterface::loadFunction(const std::string& buffer, const std::string& so
// gets the function contained in that buffer
if(boost::starts_with(buffer, "function")) {
// evaluate the function
std::string buf = aux::make_string("__func = ", buffer);
std::string buf = fw::mkstr("__func = ", buffer);
loadBuffer(buf, source);
safeCall();
@@ -295,7 +295,7 @@ void LuaInterface::evaluateExpression(const std::string& expression, const std::
{
// evaluates the expression
if(!expression.empty()) {
std::string buffer = aux::make_string("__exp = (", expression, ")");
std::string buffer = fw::mkstr("__exp = (", expression, ")");
loadBuffer(buffer, source);
safeCall();
@@ -898,7 +898,7 @@ void LuaInterface::pushObject(const LuaObjectPtr& obj)
new(newUserdata(sizeof(LuaObjectPtr))) LuaObjectPtr(obj);
// set the userdata metatable
getGlobal(aux::make_string(obj->getLuaObjectName(), "_mt"));
getGlobal(fw::mkstr(obj->getLuaObjectName(), "_mt"));
assert(!isNil());
setMetatable();
}

View File

@@ -1,7 +1,7 @@
#ifndef LUAINTERFACE_H
#define LUAINTERFACE_H
#include "luadeclarations.h"
#include "declarations.h"
struct lua_State;
typedef int (*LuaCFunction) (lua_State *L);
@@ -41,24 +41,24 @@ public:
// register shortcuts using templates
template<class C, class B = LuaObject>
void registerClass() {
registerClass(aux::demangle_type<C>(), aux::demangle_type<B>());
registerClass(fw::demangle_type<C>(), fw::demangle_type<B>());
}
template<class C>
void registerClassStaticFunction(const std::string& functionName, const LuaCppFunction& function) {
registerClassStaticFunction(aux::demangle_type<C>(), functionName, function);
registerClassStaticFunction(fw::demangle_type<C>(), functionName, function);
}
template<class C>
void registerClassMemberFunction(const std::string& functionName, const LuaCppFunction& function) {
registerClassMemberFunction(aux::demangle_type<C>(), functionName, function);
registerClassMemberFunction(fw::demangle_type<C>(), functionName, function);
}
template<class C>
void registerClassMemberField(const std::string& field,
const LuaCppFunction& getFunction,
const LuaCppFunction& setFunction) {
registerClassMemberField(aux::demangle_type<C>(), field, getFunction, setFunction);
registerClassMemberField(fw::demangle_type<C>(), field, getFunction, setFunction);
}
// methods for binding functions
@@ -322,7 +322,7 @@ template<class T>
T LuaInterface::castValue(int index) {
T o;
if(!luavalue_cast(index, o))
throw LuaBadValueCastException(typeName(index), aux::demangle_type<T>());
throw LuaBadValueCastException(typeName(index), fw::demangle_type<T>());
return o;
}

View File

@@ -1,14 +1,14 @@
#ifndef LUAOBJECT_H
#define LUAOBJECT_H
#include "luadeclarations.h"
#include "declarations.h"
/// LuaObject, all script-able classes have it as base
class LuaObject : public std::enable_shared_from_this<LuaObject>
{
public:
LuaObject();
virtual ~LuaObject() ;
virtual ~LuaObject();
/// Calls a function or table of functions stored in a lua field, results are pushed onto the stack,
/// if any lua error occurs, it will be reported to stdout and return 0 results
@@ -40,7 +40,7 @@ public:
/// Returns the class name used in Lua
virtual std::string getLuaObjectName() const {
// this could later be cached for more performance
return aux::demangle_name(typeid(*this).name());
return fw::demangle_name(typeid(*this).name());
}
LuaObjectPtr asLuaObject() { return shared_from_this(); }