44 |
|
|
45 |
namespace lua |
namespace lua |
46 |
{ |
{ |
|
class LuaState { |
|
|
public: |
|
|
LuaState (size_t stacksize = 0); |
|
|
~LuaState(); |
|
|
|
|
|
lua_State *get_state() const { return m_state; } |
|
|
private: |
|
|
LuaState (const LuaState &); |
|
|
LuaState &operator = (const LuaState &); |
|
|
|
|
|
/* |
|
|
** Variables |
|
|
*/ |
|
|
lua_State *m_state; |
|
|
}; |
|
|
|
|
|
typedef int LuaTag; |
|
|
|
|
|
|
|
|
class NumberType { |
|
|
|
|
|
}; |
|
|
|
|
|
class UserType { |
|
|
public: |
|
|
UserType (LuaState *state); |
|
|
|
|
|
LuaTag get_tag() const { return m_tag; } |
|
|
|
|
|
bool is_type (int idx) { |
|
|
lua_State *L = m_state->get_state(); |
|
|
return lua_isuserdata(L, idx) && lua_tag(L,idx)==m_tag; |
|
|
} |
|
|
|
|
|
private: |
|
|
LuaState *m_state; |
|
|
LuaTag m_tag; |
|
|
}; |
|
|
} |
|
|
|
|
|
LuaState::LuaState (size_t stacksize) |
|
|
{ |
|
|
m_state = lua_open(stacksize); |
|
|
} |
|
|
|
|
|
LuaState::~LuaState() |
|
|
{ |
|
|
lua_close(state); |
|
|
} |
|
|
|
|
|
namespace lua |
|
|
{ |
|
47 |
lua_State *state = 0; // global Lua state |
lua_State *state = 0; // global Lua state |
48 |
int object_tag; // Lua tag for `Object's |
int object_tag; // Lua tag for `Object's |
49 |
} |
} |
371 |
return lua_call(state, 1, 0); |
return lua_call(state, 1, 0); |
372 |
} |
} |
373 |
|
|
374 |
int |
int lua::Dofile(const string &filename) |
|
lua::Dofile(const string &filename) |
|
375 |
{ |
{ |
376 |
string fname = enigma::FindDataFile(filename); |
string fname = enigma::FindDataFile(filename); |
377 |
|
|
381 |
return retval; |
return retval; |
382 |
} |
} |
383 |
|
|
384 |
|
int lua::Dobuffer (const vector<char> &luacode) |
385 |
|
{ |
386 |
|
return lua_dobuffer (state, &luacode[0], luacode.size(), "buffer"); |
387 |
|
} |
388 |
|
|
389 |
|
|
390 |
int |
int |
391 |
lua::DoSubfolderfile(const string &basefolder, const string &filename) |
lua::DoSubfolderfile(const string &basefolder, const string &filename) |
392 |
{ |
{ |