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
This document describes how style tags can be specified, how they affect your

@ -38,7 +38,7 @@ function Client.init()
addEvent(function()
scheduleEvent(function()
-- 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, { onGameEnd= function() g_sounds.playMusic("startup.ogg", 3) end })
end, 100)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

@ -26,6 +26,7 @@
#include "shader.h"
#include <framework/luascript/luaobject.h>
// @bindclass
class ShaderProgram : public LuaObject
{
enum {
@ -65,7 +66,7 @@ public:
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, 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 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); }
@ -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 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, 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 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, 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 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; }
GLuint getProgramId() { return m_programId; }
uint getProgramId() { return m_programId; }
ShaderList getShaders() { return m_shaders; }
private:
bool m_linked;
GLuint m_programId;
static GLuint m_currentProgram;
uint m_programId;
static uint m_currentProgram;
ShaderList m_shaders;
std::array<GLint, MAX_UNIFORM_LOCATIONS> m_uniformLocations;
std::array<int, MAX_UNIFORM_LOCATIONS> m_uniformLocations;
};
#endif

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

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

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

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

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

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

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

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

@ -25,6 +25,7 @@
#include "declarations.h"
//@bindsingleton g_sounds
class SoundManager
{
enum {
@ -53,7 +54,7 @@ public:
private:
StreamSoundSourcePtr createStreamSoundSource(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::vector<SoundSourcePtr> m_sources;

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

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

@ -63,7 +63,7 @@ void StreamSoundSource::stop()
void StreamSoundSource::queueBuffers()
{
ALint queued;
int queued;
alGetSourcei(m_sourceId, AL_BUFFERS_QUEUED, &queued);
for(int i = 0; i < STREAM_FRAGMENTS - queued; ++i) {
if(!fillBufferAndQueue(m_buffers[i]->getBufferId()))
@ -73,10 +73,10 @@ void StreamSoundSource::queueBuffers()
void StreamSoundSource::unqueueBuffers()
{
ALint queued;
int queued;
alGetSourcei(m_sourceId, AL_BUFFERS_QUEUED, &queued);
for(int i = 0; i < queued; ++i) {
ALuint buffer;
uint buffer;
alSourceUnqueueBuffers(m_sourceId, 1, &buffer);
}
}
@ -85,10 +85,10 @@ void StreamSoundSource::update()
{
SoundSource::update();
ALint processed = 0;
int processed = 0;
alGetSourcei(m_sourceId, AL_BUFFERS_PROCESSED, &processed);
for(ALint i = 0; i < processed; ++i) {
ALuint buffer;
for(int i = 0; i < processed; ++i) {
uint buffer;
alSourceUnqueueBuffers(m_sourceId, 1, &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
static DataBuffer<char> bufferData(2*STREAM_FRAGMENT_SIZE);

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

@ -1,20 +1,26 @@
#!/usr/bin/lua
if not (#arg >= 1 and #arg <= 4) then
print('usage: ' .. arg[0] .. ' <cpp class header> [class name] [cpp class instance] [lua class instance]')
return false
-- parse options
if #arg == 0 then
print('usage: ' .. arg[0] .. ' <headers> [--doc]')
os.exit(1)
end
cppclassheader = arg[1]
cppclassname = arg[2]
cppclassinstance = arg[3]
luaclassname = arg[3] or luaclassname
gendoc = false
for i=1,#arg do
if arg[i] == '--doc' then
table.remove(arg, i)
gendoc = true
break
end
end
if not io.open(cppclassheader, 'r') then
print('could not open ' .. cppclassheader)
return false
if #arg == 0 then
print('Specify a file.')
os.exit(1)
end
-- string utilities
function string:matchcount(pattern)
local count = 0
for w in self:gmatch(pattern) do count = count + 1 end
@ -28,68 +34,234 @@ function string:splitlines()
return t
end
classfound = false
publicmethods = false
for line in io.lines(cppclassheader) do
foundclassname = line:match('^class ([%w_]+)')
if foundclassname then
if not cppclassname then
guessedclassname = cppclassheader:match('([%w_]+)\.h$'):lower()
if foundclassname:lower() == guessedclassname then
cppclassname = foundclassname
end
function table.removevalue(t, value)
for k,v in pairs(t) do
if v == value then
table.remove(t, k)
break
end
if foundclassname == cppclassname then
classfound = true
publicmethods = false
end
end
if cppclassinstance then
print(' g_lua.registerStaticClass("' .. luaclassname .. '");')
else
baseclassname = line:match(': public ([%w_]+)')
bindline = ' g_lua.registerClass<' .. cppclassname
function string.split(s, delim)
local start = 1
local results = {}
while true do
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
bindline = bindline .. ', ' .. baseclassname
end
function string.trim(s)
return string.match(s, '^%s*(.*%S)') or ''
end
bindline = bindline .. '>();'
print(bindline)
function countbrackets(str)
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 .. '); });'
print(bindline)
end
elseif classfound then
return true
function filterType(arg)
arg = arg:gsub('^const[%s]+', '')
arg = arg:gsub('Ptr', '')
arg = arg:gsub('&', '')
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
if classfound then
if line:match('public:') then
publicmethods = true
elseif line:match('private:') or line:match('protected:') then
publicmethods = false
elseif publicmethods then
funcname, args = line:match('^ *[%w <>&\*:_]* ([%w_]+)%(([^%)]*%))[%w ]*[;{=].*$')
if funcname then
if funcname ~= cppclassname and funcname ~= 'create' then
numargs = args:matchcount('[^,)]+[,)]')
if cppclassinstance then
bindline = ' g_lua.bindClassStaticFunction("' .. luaclassname .. '", "' .. funcname .. '", ' ..
'std::bind(&' .. cppclassname .. "::" .. funcname .. ', &' .. cppclassinstance
for i=1,numargs do
bindline = bindline .. ', std::placeholders::_' .. i
return newstr
end
function filterReturn(str)
str = str:gsub('virtual ', '')
str = str:gsub('static ', '')
return filterType(str:trim())
end
function emitSingletonDecl(cppclass, luaclass)
if gendoc then
outline = 'class ' .. luaclass .. ' {\n' ..
'public:'
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
bindline = bindline .. '));'
else
bindline = ' g_lua.bindClassMemberFunction<' .. cppclassname .. '>("' .. funcname .. '", &' ..
cppclassname .. '::' .. funcname .. ');'
end
print(bindline)
end
else
bindnext = true
end
end
brackets = brackets + countbrackets(line)
end
end
end
return true
for i=1,#arg do
parseHeader(arg[i])
end
Loading…
Cancel
Save