Ignore:
Timestamp:
Mar 7, 2013, 4:24:52 PM (8 years ago)
Author:
sam
Message:

lua: add support for lua/init.lua in a global World object and give
it a try in MrPigeon.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/world.cpp

    r2216 r2565  
    1919#include "core.h"
    2020
     21#include "lua/lua.hpp"
     22
    2123namespace lol
    2224{
     
    3032    friend class World;
    3133
    32 private:
    33     int width, height;
     34    lua_State *m_lua_state;
    3435};
     36
     37static WorldData g_world_data;
     38World g_world;
    3539
    3640/*
     
    3943
    4044World::World()
    41   : data(new WorldData())
    4245{
    43     data->width = 0;
    44     data->height = 0;
    45 
    46     m_drawgroup = DRAWGROUP_BEFORE;
     46    g_world_data.m_lua_state = luaL_newstate();
     47    luaL_openlibs(g_world_data.m_lua_state);
    4748}
    4849
    4950World::~World()
    5051{
    51     delete data;
     52    lua_close(g_world_data.m_lua_state);
    5253}
    5354
    54 char const *World::GetName()
     55bool World::ExecLua(String const &lua)
    5556{
    56     return "<world>";
     57    Array<String> pathlist = System::GetPathList(lua);
     58    for (int i = 0; i < pathlist.Count(); ++i)
     59    {
     60        luaL_dofile(g_world_data.m_lua_state, pathlist[i].C());
     61    }
     62
     63    return true;
    5764}
    5865
    59 void World::TickGame(float seconds)
     66double World::GetLuaNumber(String const &var)
    6067{
    61     Entity::TickGame(seconds);
    62 }
    63 
    64 void World::TickDraw(float seconds)
    65 {
    66     Entity::TickDraw(seconds);
    67 }
    68 
    69 int World::GetWidth()
    70 {
    71     return data->width * 32;
    72 }
    73 
    74 int World::GetHeight()
    75 {
    76     return data->height * 32;
     68    lua_getglobal(g_world_data.m_lua_state, var.C());
     69    return lua_tonumber(g_world_data.m_lua_state, -1);
    7770}
    7871
Note: See TracChangeset for help on using the changeset viewer.