Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Topics - piluve

Pages: [1]
General / Tiled to SFML using lua.
« on: November 25, 2015, 11:08:41 pm »
Hey guys!

I found Tiled (http://www.mapeditor.org/) quite a while ago (I was using Unity) and found it really useful.

I want to be able to load "tiled.lua" files into my C++ program.

I am using LuaBridge(https://github.com/vinniefalco/LuaBridge) to do most of the heavy lifting.

But now I am stuck.
Let me show you how a Tiled map looks in lua:

  version = ""
  luaversion = ""
    name = "Rock"
    name = "Grass"

So yeah it is a lot of information in a table.

Using LuaBridge you can use: getGlobal(luaState,"key") to get a handler to that key value and then cast it into the apropiate type.
But,how do I "get" things without using a name(a char*) just using an id for example like:

lua_State* L = luaL_newstate();
luaL_dofile(L, "../data/scripts/untitled.lua");
lua_pcall(L, 0, 0, 0);
LuaRef globalData = getGlobal(L, "globalData");
LuaRef someKey = getGlobal(L,2);//How to do this

I am not sure how it should be done :C

Sorry it the answer is really obvious but I can´t find it :C

General / Using a singleton pattern for a resource manager.
« on: November 23, 2015, 12:16:02 pm »
Before getting to the question let me explain my problem.

I´ve made a simple ResourceManager where I could add/get resources (sf::Textures,sf::Font etc) and I made it static inside a "Types" file (yeah , you start seeing the problem :D )

When I close the app it will crash (ntdll exception), that confused me a lot.I put down a few breakpoint and the exception was outside of my app.
So I searched google for an answer and I found that I can not use static global things with SFML because we dont know when they will be destroyed and that will cause a few problems.

After this small introduction ;) , now the question.

How do I make a static/global class?

Can I use a singleton pattern like this:

#include <string>

class Logger{
   static Logger* Instance();
   bool openLogFile(std::string logFile);
   void writeToLogFile();
   bool closeLogFile();

   Logger(){};  // Private so that it can  not be called
   Logger(Logger const&){};             // copy constructor is private
   Logger& operator=(Logger const&){};  // assignment operator is private
   static Logger* m_pInstance;

That pattern holds the class as a static pointer, will be this a problem?

Thank you guys!

Pages: [1]