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.


Messages - totoo

Pages: [1]
1
SFML projects / Re:creation - a top down action adventure about undeads
« on: February 26, 2016, 03:18:01 pm »
great!
as you're becoming a Lua pro, I'd like to ask you something. as I said previously I'm currently implementing Lua Scripting, what I made till now is being able to build an entity template with its components from the lua script, that works great. but what I want to do now is calling C++ functions from Lua. I read a lot about registering functions, I've made it work (in both senses) but, there's something I'm thinking about.
in every Lua function found in any script, we must be able to do everything that is possible (get the current animation frame, get the current speed, get the health... everything) so lots of functions have to be registered. But the thing is, everytime we open a new script file, everything about the previous one is deleted, including the registered functions.
Is there any way not to need to register every function (registered with lua_pushcfunction() and lua_setglobal()) each time I open a new script file ? (I'm not using LuaBridge or anything else and I'd like not to for the moment)

thanks.

2
SFML projects / Re:creation - a top down action adventure about undeads
« on: February 24, 2016, 07:43:04 pm »
indeed, but in my case (and in his too I guess) the keys I'll catch like this will always have no space, or if there are, I simply need to add brackets and double quotes. If the name has no spaces then it is automatically converted into a string, for example:

player = {
        AnimationComponent = {
               
                animations = {
                        idle = {
                       
                        },
                       
                        moving = {
                       
                        },
                       
                        attacking = {
                       
                        }
                }
        }
}
 

if I catch the keys of the animations table, like this:

std::vector<std::string> vec = script.getTableKeys("player.AnimationComponent.animations");

for(unsigned int i = 0; i != vec.size(); ++i){
    std::cout << vec[i] << std::endl;;
}

this will output this:
idle
moving
attacking
(the order is variable but it does not matter)

and if you want to use spaces in your key name :

player = {

        AnimationComponent = {
               
                animations = {
                        ["moving right"] = {
                       
                        }
                }      
        }
}
 

this will output the correct name, with the spaces  ;)

3
SFML projects / Re:creation - a top down action adventure about undeads
« on: February 24, 2016, 05:27:29 pm »
hi Elias ! first of all I'd say what you made till now is great, just keep going, can't wait to play your game!

Actually I'm making my own game too (what a surprise!), and reading yours made me want to use Lua too for scripting. So I'm currently reading your articles in order to learn (which are great btw), and I found a better way than yours to get a table keys (https://eliasdaler.wordpress.com/2013/10/20/lua_and_cpp_pt2/), I don't know if you still use the same code but on your article you're making a string which contains lua code to execute it in a C++ program... definitely not the best way   ;)

So there's mine:

std::vector<std::string> LuaScript::getTableKeys(const std::string& tableName)
{
    std::vector<std::string> strings;

    if(!lua_gettostack(tableName)){
        return strings;
    }

    for(lua_pushnil(L); lua_next(L, -2); lua_pop(L, 1)){
        strings.push_back(lua_tostring(L, -2));
    }

    cleanStack();
    return strings;
}

In fact, when using lua_next(), the value is located at the bottom of the stack, whereas the key is located one upper. So getting the value of the key is as easy as that.

Pages: [1]