doc and luabinder changes

master
Eduardo Bart 12 years ago
parent c5674d10ba
commit aed779a2c8

@ -1,4 +1,4 @@
# @title Style Tags Overview # Style Tags Overview
## Style Overview ## Style Overview
This document describes how style tags can be specified, how they affect your This document describes how style tags can be specified, how they affect your

@ -38,7 +38,7 @@ function Client.init()
addEvent(function() addEvent(function()
scheduleEvent(function() scheduleEvent(function()
-- Play startup music (The Silver Tree, by Mattias Westlund) -- Play startup music (The Silver Tree, by Mattias Westlund)
g_sounds.playMusic("startup.ogg", 3) --g_sounds.playMusic("startup.ogg", 3)
connect(g_game, { onGameStart = function() g_sounds.stopMusic(3) end }) connect(g_game, { onGameStart = function() g_sounds.stopMusic(3) end })
connect(g_game, { onGameEnd= function() g_sounds.playMusic("startup.ogg", 3) end }) connect(g_game, { onGameEnd= function() g_sounds.playMusic("startup.ogg", 3) end })
end, 100) end, 100)

@ -27,6 +27,7 @@
#include <framework/core/adaptativeframecounter.h> #include <framework/core/adaptativeframecounter.h>
#include <framework/graphics/declarations.h> #include <framework/graphics/declarations.h>
//@bindsingleton g_app
class Application class Application
{ {
enum { enum {

@ -25,6 +25,7 @@
#include "declarations.h" #include "declarations.h"
// @bindsingleton g_clock
class Clock class Clock
{ {
public: public:

@ -26,10 +26,12 @@
#include "declarations.h" #include "declarations.h"
#include <framework/otml/declarations.h> #include <framework/otml/declarations.h>
// @bindsingleton g_configs
class ConfigManager class ConfigManager
{ {
public: public:
ConfigManager(); ConfigManager();
bool load(const std::string& file); bool load(const std::string& file);
bool save(); bool save();
void clear(); void clear();

@ -26,6 +26,7 @@
#include "clock.h" #include "clock.h"
#include "scheduledevent.h" #include "scheduledevent.h"
// @bindsingleton g_eventDispatcher
class EventDispatcher class EventDispatcher
{ {
public: public:

@ -24,10 +24,12 @@
#define FILESTREAM_H #define FILESTREAM_H
#include "declarations.h" #include "declarations.h"
#include <framework/luascript/luaobject.h>
struct PHYSFS_File; struct PHYSFS_File;
class FileStream // @bindclass
class FileStream : public LuaObject
{ {
public: public:
FileStream(const std::string& name, PHYSFS_File *fileHandle); FileStream(const std::string& name, PHYSFS_File *fileHandle);
@ -44,8 +46,6 @@ public:
int tell(); int tell();
std::string name() { return m_name; } std::string name() { return m_name; }
std::string readAll();
uint8 getU8(); uint8 getU8();
uint16 getU16(); uint16 getU16();
uint32 getU32(); uint32 getU32();

@ -32,6 +32,7 @@ struct LogMessage {
std::size_t when; std::size_t when;
}; };
// @bindsingleton g_logger
class Logger class Logger
{ {
enum { enum {

@ -28,6 +28,7 @@
#include <framework/otml/declarations.h> #include <framework/otml/declarations.h>
#include <framework/luascript/luaobject.h> #include <framework/luascript/luaobject.h>
// @bindclass
class Module : public LuaObject class Module : public LuaObject
{ {
public: public:
@ -52,6 +53,7 @@ public:
bool isAutoLoad() { return m_autoLoad; } bool isAutoLoad() { return m_autoLoad; }
int getAutoLoadPriority() { return m_autoLoadPriority; } int getAutoLoadPriority() { return m_autoLoadPriority; }
// @dontbind
ModulePtr asModule() { return std::static_pointer_cast<Module>(shared_from_this()); } ModulePtr asModule() { return std::static_pointer_cast<Module>(shared_from_this()); }
protected: protected:

@ -25,6 +25,7 @@
#include "module.h" #include "module.h"
// @bindsingleton g_modules
class ModuleManager class ModuleManager
{ {
public: public:

@ -25,10 +25,13 @@
#include "declarations.h" #include "declarations.h"
// @bindsingleton g_resources
class ResourceManager class ResourceManager
{ {
public: public:
// @dontbind
void init(const char *argv0); void init(const char *argv0);
// @dontbind
void terminate(); void terminate();
void discoverWorkDir(const std::string& appName, const std::string& existentFile); void discoverWorkDir(const std::string& appName, const std::string& existentFile);
@ -41,10 +44,13 @@ public:
bool fileExists(const std::string& fileName); bool fileExists(const std::string& fileName);
bool directoryExists(const std::string& directoryName); bool directoryExists(const std::string& directoryName);
// @dontbind
void loadFile(const std::string& fileName, std::iostream& out); void loadFile(const std::string& fileName, std::iostream& out);
std::string loadFile(const std::string& fileName); std::string loadFile(const std::string& fileName);
// @dontbind
bool saveFile(const std::string& fileName, const uchar* data, uint size); bool saveFile(const std::string& fileName, const uchar* data, uint size);
bool saveFile(const std::string& fileName, const std::string& data); bool saveFile(const std::string& fileName, const std::string& data);
// @dontbind
bool saveFile(const std::string& fileName, std::iostream& in); bool saveFile(const std::string& fileName, std::iostream& in);
FileStreamPtr openFile(const std::string& fileName); FileStreamPtr openFile(const std::string& fileName);

@ -25,6 +25,7 @@
#include "bitmapfont.h" #include "bitmapfont.h"
//@bindsingleton g_fonts
class FontManager class FontManager
{ {
public: public:

@ -82,7 +82,7 @@ void Graphics::init()
glEnable(GL_BLEND); glEnable(GL_BLEND);
// determine max texture size // determine max texture size
GLint maxTextureSize = 0; int maxTextureSize = 0;
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize); glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize);
if(m_maxTextureSize == -1 || m_maxTextureSize > maxTextureSize) if(m_maxTextureSize == -1 || m_maxTextureSize > maxTextureSize)
m_maxTextureSize = maxTextureSize; m_maxTextureSize = maxTextureSize;

@ -26,6 +26,7 @@
#include "declarations.h" #include "declarations.h"
#include "painter.h" #include "painter.h"
// @bindsingleton g_graphics
class Graphics class Graphics
{ {
public: public:
@ -37,8 +38,11 @@ public:
Painter_OpenGL2 Painter_OpenGL2
}; };
// @dontbind
void init(); void init();
// @dontbind
void terminate(); void terminate();
bool parseOption(const std::string& option); bool parseOption(const std::string& option);
bool isPainterEngineAvailable(PainterEngine painterEngine); bool isPainterEngineAvailable(PainterEngine painterEngine);
@ -47,8 +51,6 @@ public:
void resize(const Size& size); void resize(const Size& size);
void setViewportSize(const Size& size);
int getMaxTextureSize() { return m_maxTextureSize; } int getMaxTextureSize() { return m_maxTextureSize; }
const Size& getViewportSize() { return m_viewportSize; } const Size& getViewportSize() { return m_viewportSize; }

@ -49,7 +49,7 @@ public:
private: private:
Type m_type; Type m_type;
GLuint m_id; uint m_id;
}; };
#endif #endif

@ -135,7 +135,7 @@ void Painter::setTexture(Texture* texture)
m_texture = texture; m_texture = texture;
GLuint glTextureId; uint glTextureId;
if(texture) { if(texture) {
setTextureMatrix(texture->getTransformMatrix()); setTextureMatrix(texture->getTransformMatrix());
glTextureId = texture->getId(); glTextureId = texture->getId();

@ -137,7 +137,7 @@ protected:
PainterState m_olderStates[10]; PainterState m_olderStates[10];
int m_oldStateIndex; int m_oldStateIndex;
GLuint m_glTextureId; uint m_glTextureId;
}; };
extern Painter *g_painter; extern Painter *g_painter;

@ -89,7 +89,7 @@ bool Shader::compileSourceFile(const std::string& sourceFile)
std::string Shader::log() std::string Shader::log()
{ {
std::string infoLog; std::string infoLog;
GLint infoLogLength = 0; int infoLogLength = 0;
glGetShaderiv(m_shaderId, GL_INFO_LOG_LENGTH, &infoLogLength); glGetShaderiv(m_shaderId, GL_INFO_LOG_LENGTH, &infoLogLength);
if(infoLogLength > 1) { if(infoLogLength > 1) {
std::vector<char> buf(infoLogLength); std::vector<char> buf(infoLogLength);

@ -40,11 +40,11 @@ public:
bool compileSourceFile(const std::string& sourceFile); bool compileSourceFile(const std::string& sourceFile);
std::string log(); std::string log();
GLuint getShaderId() { return m_shaderId; } uint getShaderId() { return m_shaderId; }
ShaderType getShaderType() { return m_shaderType; } ShaderType getShaderType() { return m_shaderType; }
private: private:
GLuint m_shaderId; uint m_shaderId;
ShaderType m_shaderType; ShaderType m_shaderType;
}; };

@ -25,7 +25,7 @@
#include <framework/application.h> #include <framework/application.h>
GLuint ShaderProgram::m_currentProgram = 0; uint ShaderProgram::m_currentProgram = 0;
ShaderProgram::ShaderProgram() ShaderProgram::ShaderProgram()
{ {
@ -92,7 +92,7 @@ bool ShaderProgram::link()
glLinkProgram(m_programId); glLinkProgram(m_programId);
GLint value = GL_FALSE; int value = GL_FALSE;
glGetProgramiv(m_programId, GL_LINK_STATUS, &value); glGetProgramiv(m_programId, GL_LINK_STATUS, &value);
m_linked = (value != GL_FALSE); m_linked = (value != GL_FALSE);
@ -123,7 +123,7 @@ void ShaderProgram::release()
std::string ShaderProgram::log() std::string ShaderProgram::log()
{ {
std::string infoLog; std::string infoLog;
GLint infoLogLength = 0; int infoLogLength = 0;
glGetProgramiv(m_programId, GL_INFO_LOG_LENGTH, &infoLogLength); glGetProgramiv(m_programId, GL_INFO_LOG_LENGTH, &infoLogLength);
if(infoLogLength > 1) { if(infoLogLength > 1) {
std::vector<char> buf(infoLogLength); std::vector<char> buf(infoLogLength);

@ -26,6 +26,7 @@
#include "shader.h" #include "shader.h"
#include <framework/luascript/luaobject.h> #include <framework/luascript/luaobject.h>
// @bindclass
class ShaderProgram : public LuaObject class ShaderProgram : public LuaObject
{ {
enum { enum {
@ -65,7 +66,7 @@ public:
void setAttributeValue(const char *name, float x, float y, float z) { glVertexAttrib3f(getAttributeLocation(name), x, y, z); } void setAttributeValue(const char *name, float x, float y, float z) { glVertexAttrib3f(getAttributeLocation(name), x, y, z); }
void setUniformValue(int location, const Color& color) { glUniform4f(m_uniformLocations[location], color.rF(), color.gF(), color.bF(), color.aF()); } void setUniformValue(int location, const Color& color) { glUniform4f(m_uniformLocations[location], color.rF(), color.gF(), color.bF(), color.aF()); }
void setUniformValue(int location, GLint value) { glUniform1i(m_uniformLocations[location], value); } void setUniformValue(int location, int value) { glUniform1i(m_uniformLocations[location], value); }
void setUniformValue(int location, float value) { glUniform1f(m_uniformLocations[location], value); } void setUniformValue(int location, float value) { glUniform1f(m_uniformLocations[location], value); }
void setUniformValue(int location, float x, float y) { glUniform2f(m_uniformLocations[location], x, y); } void setUniformValue(int location, float x, float y) { glUniform2f(m_uniformLocations[location], x, y); }
void setUniformValue(int location, float x, float y, float z) { glUniform3f(m_uniformLocations[location], x, y, z); } void setUniformValue(int location, float x, float y, float z) { glUniform3f(m_uniformLocations[location], x, y, z); }
@ -73,25 +74,25 @@ public:
void setUniformValue(int location, const Matrix2& mat) { glUniformMatrix2fv(m_uniformLocations[location], 1, GL_FALSE, mat.data()); } void setUniformValue(int location, const Matrix2& mat) { glUniformMatrix2fv(m_uniformLocations[location], 1, GL_FALSE, mat.data()); }
void setUniformValue(int location, const Matrix3& mat) { glUniformMatrix3fv(m_uniformLocations[location], 1, GL_FALSE, mat.data()); } void setUniformValue(int location, const Matrix3& mat) { glUniformMatrix3fv(m_uniformLocations[location], 1, GL_FALSE, mat.data()); }
void setUniformValue(const char *name, const Color& color) { glUniform4f(glGetUniformLocation(m_programId, name), color.rF(), color.gF(), color.bF(), color.aF()); } void setUniformValue(const char *name, const Color& color) { glUniform4f(glGetUniformLocation(m_programId, name), color.rF(), color.gF(), color.bF(), color.aF()); }
void setUniformValue(const char *name, GLint value) { glUniform1i(glGetUniformLocation(m_programId, name), value); } void setUniformValue(const char *name, int value) { glUniform1i(glGetUniformLocation(m_programId, name), value); }
void setUniformValue(const char *name, float value) { glUniform1f(glGetUniformLocation(m_programId, name), value); } void setUniformValue(const char *name, float value) { glUniform1f(glGetUniformLocation(m_programId, name), value); }
void setUniformValue(const char *name, float x, float y) { glUniform2f(glGetUniformLocation(m_programId, name), x, y); } void setUniformValue(const char *name, float x, float y) { glUniform2f(glGetUniformLocation(m_programId, name), x, y); }
void setUniformValue(const char *name, float x, float y, float z) { glUniform3f(glGetUniformLocation(m_programId, name), x, y, z); } void setUniformValue(const char *name, float x, float y, float z) { glUniform3f(glGetUniformLocation(m_programId, name), x, y, z); }
void setUniformValue(const char *name, float x, float y, float z, float w) { glUniform4f(glGetUniformLocation(m_programId, name), x, y, z, w); } void setUniformValue(const char *name, float x, float y, float z, float w) { glUniform4f(glGetUniformLocation(m_programId, name), x, y, z, w); }
void setUniformValue(const char *name, const Matrix2& mat) { glUniformMatrix2fv(glGetUniformLocation(m_programId, name), 1, GL_FALSE, mat.data()); } void setUniformValue(const char *name, const Matrix2& mat) { glUniformMatrix2fv(glGetUniformLocation(m_programId, name), 1, GL_FALSE, mat.data()); }
void setUniformValue(const char *name, const Matrix3& mat) { glUniformMatrix3fv(glGetUniformLocation(m_programId, name), 1, GL_FALSE, mat.data()); } void setUniformValue(const char *name, const Matrix3& mat) { glUniformMatrix3fv(glGetUniformLocation(m_programId, name), 1, GL_FALSE, mat.data()); }
// TODO: Point, PointF, Color, Size, SizeF ?
// Point, PointF, Color, Size, SizeF,
bool isLinked() { return m_linked; } bool isLinked() { return m_linked; }
GLuint getProgramId() { return m_programId; } uint getProgramId() { return m_programId; }
ShaderList getShaders() { return m_shaders; } ShaderList getShaders() { return m_shaders; }
private: private:
bool m_linked; bool m_linked;
GLuint m_programId; uint m_programId;
static GLuint m_currentProgram; static uint m_currentProgram;
ShaderList m_shaders; ShaderList m_shaders;
std::array<GLint, MAX_UNIFORM_LOCATIONS> m_uniformLocations; std::array<int, MAX_UNIFORM_LOCATIONS> m_uniformLocations;
}; };
#endif #endif

@ -176,7 +176,7 @@ bool Texture::setupSize(const Size& size, bool forcePowerOfTwo)
void Texture::setupWrap() void Texture::setupWrap()
{ {
GLint texParam; int texParam;
if(!m_repeat && g_graphics.canUseClampToEdge()) if(!m_repeat && g_graphics.canUseClampToEdge())
texParam = GL_CLAMP_TO_EDGE; texParam = GL_CLAMP_TO_EDGE;
else else
@ -188,8 +188,8 @@ void Texture::setupWrap()
void Texture::setupFilters() void Texture::setupFilters()
{ {
GLint minFilter; int minFilter;
GLint magFilter; int magFilter;
if(m_smooth) { if(m_smooth) {
minFilter = m_hasMipmaps ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR; minFilter = m_hasMipmaps ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR;
magFilter = GL_LINEAR; magFilter = GL_LINEAR;

@ -41,7 +41,7 @@ public:
void setRepeat(bool repeat); void setRepeat(bool repeat);
void setUpsideDown(bool upsideDown); void setUpsideDown(bool upsideDown);
GLuint getId() { return m_id; } uint getId() { return m_id; }
int getWidth() { return m_size.width(); } int getWidth() { return m_size.width(); }
int getHeight() { return m_size.height(); } int getHeight() { return m_size.height(); }
const Size& getSize() { return m_size; } const Size& getSize() { return m_size; }
@ -59,7 +59,7 @@ protected:
void setupTranformMatrix(); void setupTranformMatrix();
void setupPixels(int level, const Size& size, uchar *pixels, int channels = 4); void setupPixels(int level, const Size& size, uchar *pixels, int channels = 4);
GLuint m_id; uint m_id;
Size m_size; Size m_size;
Size m_glSize; Size m_glSize;
Matrix3 m_transformMatrix; Matrix3 m_transformMatrix;

@ -26,6 +26,7 @@
#include "declarations.h" #include "declarations.h"
/// LuaObject, all script-able classes have it as base /// LuaObject, all script-able classes have it as base
// @bindclass
class LuaObject : public std::enable_shared_from_this<LuaObject> class LuaObject : public std::enable_shared_from_this<LuaObject>
{ {
public: public:

@ -26,6 +26,7 @@
#include "declarations.h" #include "declarations.h"
#include <framework/luascript/luaobject.h> #include <framework/luascript/luaobject.h>
// @bindclass
class InputMessage : public LuaObject class InputMessage : public LuaObject
{ {
public: public:

@ -26,6 +26,7 @@
#include "declarations.h" #include "declarations.h"
#include <framework/luascript/luaobject.h> #include <framework/luascript/luaobject.h>
// @bindclass
class OutputMessage : public LuaObject class OutputMessage : public LuaObject
{ {
public: public:

@ -29,6 +29,7 @@
#include <framework/luascript/luaobject.h> #include <framework/luascript/luaobject.h>
// @bindclass
class Protocol : public LuaObject class Protocol : public LuaObject
{ {
public: public:

@ -27,6 +27,7 @@
#include <framework/core/inputevent.h> #include <framework/core/inputevent.h>
#include <framework/core/timer.h> #include <framework/core/timer.h>
//@bindsingleton g_window
class PlatformWindow class PlatformWindow
{ {
enum { enum {

@ -36,10 +36,10 @@ public:
bool fillBuffer(const SoundFilePtr& soundFile); bool fillBuffer(const SoundFilePtr& soundFile);
bool fillBuffer(ALenum sampleFormat, const DataBuffer<char>& data, int size, int rate); bool fillBuffer(ALenum sampleFormat, const DataBuffer<char>& data, int size, int rate);
ALuint getBufferId() { return m_bufferId; } uint getBufferId() { return m_bufferId; }
private: private:
ALuint m_bufferId; uint m_bufferId;
}; };
#endif #endif

@ -25,6 +25,7 @@
#include "declarations.h" #include "declarations.h"
//@bindsingleton g_sounds
class SoundManager class SoundManager
{ {
enum { enum {
@ -53,7 +54,7 @@ public:
private: private:
StreamSoundSourcePtr createStreamSoundSource(const std::string& filename); StreamSoundSourcePtr createStreamSoundSource(const std::string& filename);
SoundSourcePtr createSoundSource(const std::string& filename); SoundSourcePtr createSoundSource(const std::string& filename);
ALuint loadFileIntoBuffer(const SoundFilePtr& soundFile); uint loadFileIntoBuffer(const SoundFilePtr& soundFile);
std::map<std::string, SoundBufferPtr> m_buffers; std::map<std::string, SoundBufferPtr> m_buffers;
std::vector<SoundSourcePtr> m_sources; std::vector<SoundSourcePtr> m_sources;

@ -65,7 +65,7 @@ void SoundSource::stop()
bool SoundSource::isPlaying() bool SoundSource::isPlaying()
{ {
ALint state = AL_PLAYING; int state = AL_PLAYING;
alGetSourcei(m_sourceId, AL_SOURCE_STATE, &state); alGetSourcei(m_sourceId, AL_SOURCE_STATE, &state);
return state != AL_STOPPED; return state != AL_STOPPED;
} }

@ -28,7 +28,7 @@
class SoundSource class SoundSource
{ {
protected: protected:
SoundSource(ALuint sourceId) : m_sourceId(sourceId) { } SoundSource(uint sourceId) : m_sourceId(sourceId) { }
public: public:
enum FadeState { NoFading, FadingOn, FadingOff }; enum FadeState { NoFading, FadingOn, FadingOff };
@ -56,7 +56,7 @@ protected:
friend class SoundManager; friend class SoundManager;
friend class CombinedSoundSource; friend class CombinedSoundSource;
ALuint m_sourceId; uint m_sourceId;
SoundBufferPtr m_buffer; SoundBufferPtr m_buffer;
FadeState m_fadeState; FadeState m_fadeState;
float m_fadeStartTime; float m_fadeStartTime;

@ -63,7 +63,7 @@ void StreamSoundSource::stop()
void StreamSoundSource::queueBuffers() void StreamSoundSource::queueBuffers()
{ {
ALint queued; int queued;
alGetSourcei(m_sourceId, AL_BUFFERS_QUEUED, &queued); alGetSourcei(m_sourceId, AL_BUFFERS_QUEUED, &queued);
for(int i = 0; i < STREAM_FRAGMENTS - queued; ++i) { for(int i = 0; i < STREAM_FRAGMENTS - queued; ++i) {
if(!fillBufferAndQueue(m_buffers[i]->getBufferId())) if(!fillBufferAndQueue(m_buffers[i]->getBufferId()))
@ -73,10 +73,10 @@ void StreamSoundSource::queueBuffers()
void StreamSoundSource::unqueueBuffers() void StreamSoundSource::unqueueBuffers()
{ {
ALint queued; int queued;
alGetSourcei(m_sourceId, AL_BUFFERS_QUEUED, &queued); alGetSourcei(m_sourceId, AL_BUFFERS_QUEUED, &queued);
for(int i = 0; i < queued; ++i) { for(int i = 0; i < queued; ++i) {
ALuint buffer; uint buffer;
alSourceUnqueueBuffers(m_sourceId, 1, &buffer); alSourceUnqueueBuffers(m_sourceId, 1, &buffer);
} }
} }
@ -85,10 +85,10 @@ void StreamSoundSource::update()
{ {
SoundSource::update(); SoundSource::update();
ALint processed = 0; int processed = 0;
alGetSourcei(m_sourceId, AL_BUFFERS_PROCESSED, &processed); alGetSourcei(m_sourceId, AL_BUFFERS_PROCESSED, &processed);
for(ALint i = 0; i < processed; ++i) { for(int i = 0; i < processed; ++i) {
ALuint buffer; uint buffer;
alSourceUnqueueBuffers(m_sourceId, 1, &buffer); alSourceUnqueueBuffers(m_sourceId, 1, &buffer);
//SoundManager::check_al_error("Couldn't unqueue audio buffer: "); //SoundManager::check_al_error("Couldn't unqueue audio buffer: ");
@ -105,7 +105,7 @@ void StreamSoundSource::update()
} }
} }
bool StreamSoundSource::fillBufferAndQueue(ALuint buffer) bool StreamSoundSource::fillBufferAndQueue(uint buffer)
{ {
// fill buffer // fill buffer
static DataBuffer<char> bufferData(2*STREAM_FRAGMENT_SIZE); static DataBuffer<char> bufferData(2*STREAM_FRAGMENT_SIZE);

@ -51,7 +51,7 @@ public:
private: private:
void queueBuffers(); void queueBuffers();
void unqueueBuffers(); void unqueueBuffers();
bool fillBufferAndQueue(ALuint buffer); bool fillBufferAndQueue(uint buffer);
SoundFilePtr m_soundFile; SoundFilePtr m_soundFile;
std::array<SoundBufferPtr,STREAM_FRAGMENTS> m_buffers; std::array<SoundBufferPtr,STREAM_FRAGMENTS> m_buffers;

@ -58,6 +58,7 @@ private:
bool m_updated; bool m_updated;
}; };
// @bindclass
class UIAnchorLayout : public UILayout class UIAnchorLayout : public UILayout
{ {
public: public:

@ -25,6 +25,7 @@
#include "uilayout.h" #include "uilayout.h"
// @bindclass
class UIBoxLayout : public UILayout class UIBoxLayout : public UILayout
{ {
public: public:

@ -25,6 +25,7 @@
#include <framework/ui/uilayout.h> #include <framework/ui/uilayout.h>
// @bindclass
class UIGridLayout : public UILayout class UIGridLayout : public UILayout
{ {
public: public:

@ -27,6 +27,7 @@
#include <framework/luascript/luaobject.h> #include <framework/luascript/luaobject.h>
#include <framework/otml/otml.h> #include <framework/otml/otml.h>
// @bindclass
class UILayout : public LuaObject class UILayout : public LuaObject
{ {
public: public:

@ -27,6 +27,7 @@
#include <framework/core/inputevent.h> #include <framework/core/inputevent.h>
#include <framework/otml/declarations.h> #include <framework/otml/declarations.h>
//@bindsingleton g_ui
class UIManager class UIManager
{ {
public: public:

@ -25,6 +25,7 @@
#include "uiwidget.h" #include "uiwidget.h"
// @bindclass
class UITextEdit : public UIWidget class UITextEdit : public UIWidget
{ {
public: public:

@ -25,6 +25,7 @@
#include "uiboxlayout.h" #include "uiboxlayout.h"
// @bindclass
class UIVerticalLayout : public UIBoxLayout class UIVerticalLayout : public UIBoxLayout
{ {
public: public:

@ -41,9 +41,7 @@ struct EdgeGroup {
T left; T left;
}; };
// generate lua bindings for this class running: // @bindclass
// ./tools/lua-binding-generator/generate_lua_bindings.lua src/framework/ui/uiwidget.h
class UIWidget : public LuaObject class UIWidget : public LuaObject
{ {
// widget core // widget core

@ -28,7 +28,8 @@
#include <framework/core/timer.h> #include <framework/core/timer.h>
#include <framework/graphics/cachedtext.h> #include <framework/graphics/cachedtext.h>
class AnimatedText // @bindclass
class AnimatedText : public Thing
{ {
public: public:
AnimatedText(); AnimatedText();

@ -27,6 +27,7 @@
#include <framework/luascript/luaobject.h> #include <framework/luascript/luaobject.h>
// @bindclass
class Container : public LuaObject class Container : public LuaObject
{ {
protected: protected:

@ -30,6 +30,7 @@
#include <framework/graphics/fontmanager.h> #include <framework/graphics/fontmanager.h>
#include <framework/graphics/cachedtext.h> #include <framework/graphics/cachedtext.h>
// @bindclass
class Creature : public Thing class Creature : public Thing
{ {
public: public:
@ -142,13 +143,17 @@ protected:
Otc::Direction m_walkTurnDirection; Otc::Direction m_walkTurnDirection;
}; };
class Npc : public Creature { // @bindclass
class Npc : public Creature
{
public: public:
NpcPtr asNpc() { return std::static_pointer_cast<Npc>(shared_from_this()); } NpcPtr asNpc() { return std::static_pointer_cast<Npc>(shared_from_this()); }
bool isNpc() { return true; } bool isNpc() { return true; }
}; };
class Monster : public Creature { // @bindclass
class Monster : public Creature
{
public: public:
MonsterPtr asMonster() { return std::static_pointer_cast<Monster>(shared_from_this()); } MonsterPtr asMonster() { return std::static_pointer_cast<Monster>(shared_from_this()); }
bool isMonster() { return true; } bool isMonster() { return true; }

@ -27,6 +27,7 @@
#include <framework/core/timer.h> #include <framework/core/timer.h>
#include "thing.h" #include "thing.h"
// @bindclass
class Effect : public Thing class Effect : public Thing
{ {
public: public:

@ -31,6 +31,7 @@
typedef std::tuple<std::string, bool> Vip; typedef std::tuple<std::string, bool> Vip;
//@bindsingleton g_game
class Game class Game
{ {
public: public:

@ -68,6 +68,7 @@ enum AttrTypes_t {
ATTR_ATTRIBUTE_MAP = 128 ATTR_ATTRIBUTE_MAP = 128
}; };
// @bindclass
class Item : public Thing class Item : public Thing
{ {
public: public:

@ -25,6 +25,7 @@
#include "player.h" #include "player.h"
// @bindclass
class LocalPlayer : public Player class LocalPlayer : public Player
{ {
enum { enum {

@ -75,6 +75,7 @@ enum OTBM_NodeTypes_t
OTBM_WAYPOINT = 16 OTBM_WAYPOINT = 16
}; };
//@bindsingleton g_map
class Map class Map
{ {
public: public:

@ -28,6 +28,7 @@
#include <framework/luascript/luaobject.h> #include <framework/luascript/luaobject.h>
#include <framework/core/declarations.h> #include <framework/core/declarations.h>
// @bindclass
class MapView : public LuaObject class MapView : public LuaObject
{ {
enum { enum {

@ -27,6 +27,7 @@
#include <framework/core/timer.h> #include <framework/core/timer.h>
#include "thing.h" #include "thing.h"
// @bindclass
class Missile : public Thing class Missile : public Thing
{ {
enum { enum {

@ -25,6 +25,7 @@
#include "creature.h" #include "creature.h"
// @bindclass
class Player : public Creature class Player : public Creature
{ {
public: public:

@ -20,12 +20,13 @@
* THE SOFTWARE. * THE SOFTWARE.
*/ */
#ifndef GAMESHADERS_H #ifndef SHADERMANAGER_H
#define GAMESHADERS_H #define SHADERMANAGER_H
#include "declarations.h" #include "declarations.h"
#include <framework/graphics/paintershaderprogram.h> #include <framework/graphics/paintershaderprogram.h>
//@bindsingleton g_shaders
class ShaderManager class ShaderManager
{ {
public: public:

@ -26,6 +26,7 @@
#include <framework/core/declarations.h> #include <framework/core/declarations.h>
#include <framework/graphics/declarations.h> #include <framework/graphics/declarations.h>
//@bindsingleton g_sprites
class SpriteManager class SpriteManager
{ {
public: public:

@ -25,6 +25,7 @@
#include <framework/core/clock.h> #include <framework/core/clock.h>
#include <framework/core/eventdispatcher.h> #include <framework/core/eventdispatcher.h>
#include <framework/graphics/graphics.h> #include <framework/graphics/graphics.h>
#include <framework/graphics/fontmanager.h>
StaticText::StaticText() StaticText::StaticText()
{ {

@ -23,12 +23,12 @@
#ifndef STATICTEXT_H #ifndef STATICTEXT_H
#define STATICTEXT_H #define STATICTEXT_H
#include "thing.h"
#include <framework/graphics/cachedtext.h> #include <framework/graphics/cachedtext.h>
#include <framework/graphics/fontmanager.h>
#include <framework/core/timer.h> #include <framework/core/timer.h>
#include <framework/luascript/luaobject.h>
class StaticText : public LuaObject // @bindclass
class StaticText : public Thing
{ {
public: public:
StaticText(); StaticText();

@ -33,6 +33,7 @@ struct Light
uint8 color; uint8 color;
}; };
// @bindclass
class Thing : public LuaObject class Thing : public LuaObject
{ {
public: public:

@ -27,6 +27,7 @@
#include <framework/core/declarations.h> #include <framework/core/declarations.h>
#include "thingtype.h" #include "thingtype.h"
//@bindsingleton g_thingsType
class ThingsType class ThingsType
{ {
public: public:

@ -1,20 +1,26 @@
#!/usr/bin/lua #!/usr/bin/lua
if not (#arg >= 1 and #arg <= 4) then -- parse options
print('usage: ' .. arg[0] .. ' <cpp class header> [class name] [cpp class instance] [lua class instance]') if #arg == 0 then
return false print('usage: ' .. arg[0] .. ' <headers> [--doc]')
os.exit(1)
end end
cppclassheader = arg[1] gendoc = false
cppclassname = arg[2] for i=1,#arg do
cppclassinstance = arg[3] if arg[i] == '--doc' then
luaclassname = arg[3] or luaclassname table.remove(arg, i)
gendoc = true
break
end
end
if not io.open(cppclassheader, 'r') then if #arg == 0 then
print('could not open ' .. cppclassheader) print('Specify a file.')
return false os.exit(1)
end end
-- string utilities
function string:matchcount(pattern) function string:matchcount(pattern)
local count = 0 local count = 0
for w in self:gmatch(pattern) do count = count + 1 end for w in self:gmatch(pattern) do count = count + 1 end
@ -28,68 +34,234 @@ function string:splitlines()
return t return t
end end
classfound = false
publicmethods = false function table.removevalue(t, value)
for line in io.lines(cppclassheader) do for k,v in pairs(t) do
foundclassname = line:match('^class ([%w_]+)') if v == value then
if foundclassname then table.remove(t, k)
if not cppclassname then break
guessedclassname = cppclassheader:match('([%w_]+)\.h$'):lower()
if foundclassname:lower() == guessedclassname then
cppclassname = foundclassname
end
end end
if foundclassname == cppclassname then end
classfound = true end
publicmethods = false
if cppclassinstance then function string.split(s, delim)
print(' g_lua.registerStaticClass("' .. luaclassname .. '");') local start = 1
else local results = {}
baseclassname = line:match(': public ([%w_]+)') while true do
bindline = ' g_lua.registerClass<' .. cppclassname local pos = string.find(s, delim, start, true)
if not pos then
break
end
table.insert(results, string.sub(s, start, pos-1))
start = pos + string.len(delim)
end
table.insert(results, string.sub(s, start))
table.removevalue(results, '')
return results
end
if baseclassname and baseclassname ~= 'LuaObject' then function string.trim(s)
bindline = bindline .. ', ' .. baseclassname return string.match(s, '^%s*(.*%S)') or ''
end end
bindline = bindline .. '>();' function countbrackets(str)
print(bindline) local ret = 0
for _i in str:gmatch('{') do ret = ret+1 end
for _i in str:gmatch('}') do ret = ret-1 end
return ret
end
bindline = ' g_lua.bindClassStaticFunction<' .. cppclassname .. '>("create", []{ return ' .. cppclassname .. 'Ptr(new ' .. cppclassname .. '); });' function filterType(arg)
print(bindline) arg = arg:gsub('^const[%s]+', '')
end arg = arg:gsub('Ptr', '')
elseif classfound then arg = arg:gsub('&', '')
return true arg = arg:gsub('.*List$', 'table')
arg = arg:gsub('^std::string$', 'string')
arg = arg:gsub('^OTMLNode$', 'table')
arg = arg:gsub('^std::vector<.*>$', 'table')
arg = arg:gsub('^std::map<.*>$', 'table')
arg = arg:gsub('^[u]?int[0-9_t]*$', 'integer')
arg = arg:gsub('^float$', 'number')
arg = arg:gsub('^double$', 'number')
arg = arg:gsub('^bool$', 'boolean')
arg = arg:gsub('^ticks_t$', 'integer')
arg = arg:gsub('.*\*.*', 'buffer')
arg = arg:gsub('.*::.*', 'enum')
return arg
end
function filterArgs(str)
local args = str:split(',') or { str }
newstr = ''
for i,argstr in pairs(args) do
argstr = argstr:gsub('[%s]*=.*','')
local argtype, argvar = argstr:match('^(.*[%s]+[&*]?)([%w_]*)')
newstr = newstr .. filterType(argtype:trim()) .. ' ' .. argvar:trim()
if i ~= #args then
newstr = newstr .. ', '
end end
end end
if classfound then
if line:match('public:') then return newstr
publicmethods = true end
elseif line:match('private:') or line:match('protected:') then
publicmethods = false function filterReturn(str)
elseif publicmethods then str = str:gsub('virtual ', '')
funcname, args = line:match('^ *[%w <>&\*:_]* ([%w_]+)%(([^%)]*%))[%w ]*[;{=].*$') str = str:gsub('static ', '')
if funcname then return filterType(str:trim())
if funcname ~= cppclassname and funcname ~= 'create' then end
numargs = args:matchcount('[^,)]+[,)]')
if cppclassinstance then function emitSingletonDecl(cppclass, luaclass)
bindline = ' g_lua.bindClassStaticFunction("' .. luaclassname .. '", "' .. funcname .. '", ' .. if gendoc then
'std::bind(&' .. cppclassname .. "::" .. funcname .. ', &' .. cppclassinstance outline = 'class ' .. luaclass .. ' {\n' ..
for i=1,numargs do 'public:'
bindline = bindline .. ', std::placeholders::_' .. i else
outline = ' // ' .. luaclass .. '\n' ..
' g_lua.registerStaticClass("' .. luaclass .. '");'
end
print(outline)
return outline
end
function emitClassDecl(cppclass, luaclass, baseclass)
local outline
if gendoc then
outline = 'class ' .. luaclass
if cppclass ~= 'LuaObject' and baseclass then
outline = outline .. ' : public ' .. baseclass
end
outline = outline .. ' {\npublic:'
else
print(' // ' .. luaclass)
outline = ' g_lua.registerClass<' .. cppclass
if cppclass ~= 'LuaObject' and baseclass and baseclass ~= 'LuaObject' then
outline = outline .. ', ' .. baseclass
end
outline = outline .. '>();'
end
print(outline)
return outline
end
function emitClassEnd()
local outline = '\n'
if gendoc then
outline = '};\n'
end
print(outline)
return outline
end
function emitSingletonFunctionDecl(cppclass, luaclass, funcname, funcargs, funcret)
local outline
if gendoc then
outline = ' ' .. filterReturn(funcret) .. ' ' .. funcname .. '(' .. filterArgs(funcargs) .. ');'
else
outline = ' g_lua.bindSingletonFunction("' .. luaclass .. '", "' .. funcname .. '", &' .. cppclass .. '::' .. funcname .. ', &' .. luaclass .. ');'
end
print(outline)
return outline
end
function emitMemberFunctionDecl(cppclass, luaclass, funcname, funcargs, funcret)
local outline
if gendoc then
outline = ' ' .. filterReturn(funcret) .. ' ' .. funcname .. '(' .. filterArgs(funcargs) .. ');'
else
outline = ' g_lua.bindClassMemberFunction("' .. funcname .. '", &' .. cppclass .. '::' .. funcname .. ');'
end
print(outline)
return outline
end
function parseClassHeader(line, param)
cppclass = line:match('^[%s]*class[%s]+([%w_]+)')
if not cppclass then
print('Invalid directive at ' .. header .. ':' .. linenumber)
os.exit(1)
end
luaclass = param or cppclass
insideclass = true
publicmethods = true
brackets = 0
bindnext = true
if singleton then
emitSingletonDecl(cppclass, luaclass)
else
baseclass = line:match(':[%s]+public[%s]+([%w_]+)')
emitClassDecl(cppclass, luaclass, baseclass)
end
end
function parseHeader(file)
header = file
linenumber = 0
brackets = 0
publicmethods = false
insideclass = false
singleton = false
if not io.open(header, 'r') then
print('Unable to open ' .. header)
exit(1)
end
lines = {}
for line in io.lines(header) do table.insert(lines, line) end
for linenumber=1,#lines do
local line = lines[linenumber]
local param = line:match('^[%s]*//[%s]*@[%w]+[%s]+(.*)[%s]*')
if not insideclass then
if line:match('[%s]*//[%s]*@bindsingleton') then
singleton = true
linenumber = linenumber+1
parseClassHeader(lines[linenumber], param)
elseif line:match('[%s]*//[%s]*@bindclass') then
singleton = false
linenumber = linenumber+1
parseClassHeader(lines[linenumber], param)
end
else
if brackets > 1 then
-- ignore
elseif line:match('[%s]*//[%s]*@dontbind') then
bindnext = false
elseif line:match('[%s]*template') then
bindnext = false
elseif line:match('[%s]*public:') then
publicmethods = true
elseif line:match('[%s]*private:') or line:match('[%s]*protected:') then
publicmethods = false
elseif line:match('^};') then
insideclass = false
emitClassEnd()
elseif bindnext then
funcreturn, funcname, funcargs = line:match('^[%s]*([%w <>&\*:_]*) ([%w_]+)%(([^%)]*%))[%w ]*[;{=].*$')
if funcname then
funcargs = funcargs:match('(.*)\%)')
if funcname ~= cppclass then
if singleton then
emitSingletonFunctionDecl(cppclass, luaclass, funcname, funcargs, funcreturn)
else
emitMemberFunctionDecl(cppclass, luaclass, funcname, funcargs, funcreturn)
end end
bindline = bindline .. '));'
else
bindline = ' g_lua.bindClassMemberFunction<' .. cppclassname .. '>("' .. funcname .. '", &' ..
cppclassname .. '::' .. funcname .. ');'
end end
print(bindline)
end end
else
bindnext = true
end end
end brackets = brackets + countbrackets(line)
end
end end
end end
return true for i=1,#arg do
parseHeader(arg[i])
end
Loading…
Cancel
Save