forked from kyx0r/FA-Binary-Patches
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LuaPlus replication: LuaObject (#106)
- Loading branch information
Showing
12 changed files
with
943 additions
and
429 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#include "LuaAPI.h" | ||
|
||
SHARED bool __thiscall IsLuaFunction(LuaObject *obj) | ||
{ | ||
return obj->Type() == LUA_TFUNCTION; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include "IPairs.h" | ||
|
||
IPairsIterator::IPairsIterator(const LuaObject &table) | ||
: table{table}, index{0}, value{table.m_state} {} | ||
|
||
IPairsIterator &IPairsIterator::operator++() | ||
{ | ||
++index; | ||
value = table[index]; | ||
return *this; | ||
} | ||
|
||
const std::pair<int, LuaObject> IPairsIterator::operator*() const | ||
{ | ||
return {index, value}; | ||
} | ||
|
||
std::pair<int, LuaObject> IPairsIterator::operator*() { return {index, value}; } | ||
|
||
bool IPairsIterator::operator!=(const IPairsEndIterator &) const | ||
{ | ||
return !value.IsNil(); | ||
} | ||
|
||
IPairs::IPairs(const LuaObject &table) : table{table} | ||
{ | ||
luaplus_assert(table.IsTable()); | ||
} | ||
|
||
IPairsIterator IPairs::begin() { return ++IPairsIterator(table); } | ||
IPairsEndIterator IPairs::end() { return IPairsEndIterator{}; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#pragma once | ||
#include "LuaAPI.h" | ||
#include <utility> | ||
|
||
class IPairsEndIterator | ||
{ | ||
}; | ||
|
||
class IPairsIterator | ||
{ | ||
public: | ||
IPairsIterator(const LuaObject &table); | ||
|
||
IPairsIterator &operator++(); | ||
|
||
const std::pair<int, LuaObject> operator*() const; | ||
|
||
std::pair<int, LuaObject> operator*(); | ||
|
||
bool operator!=(const IPairsEndIterator &) const; | ||
|
||
private: | ||
const LuaObject &table; | ||
int index; | ||
LuaObject value; | ||
}; | ||
|
||
class IPairs | ||
{ | ||
public: | ||
IPairs(const LuaObject &table); | ||
|
||
IPairsIterator begin(); | ||
IPairsEndIterator end(); | ||
|
||
private: | ||
const LuaObject &table; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include "Pairs.h" | ||
|
||
PairsIterator::PairsIterator(const LuaObject &table) | ||
: table{table}, key{table.m_state}, value{table.m_state}, done{false} {} | ||
|
||
PairsIterator &PairsIterator::operator++() | ||
{ | ||
LuaState *state = table.m_state; | ||
if (!done && !LuaPlusH_next(state, &table, &key, &value)) | ||
{ | ||
done = true; | ||
} | ||
return *this; | ||
} | ||
|
||
const std::pair<LuaObject, LuaObject> PairsIterator::operator*() const | ||
{ | ||
return {key, value}; | ||
} | ||
|
||
std::pair<LuaObject, LuaObject> PairsIterator::operator*() | ||
{ | ||
return {key, value}; | ||
} | ||
|
||
bool PairsIterator::operator!=(const EndIterator &) const { return !done; } | ||
|
||
Pairs::Pairs(const LuaObject &table) : table{table} | ||
{ | ||
luaplus_assert(table.IsTable()); | ||
} | ||
|
||
PairsIterator Pairs::begin() { return ++PairsIterator(table); } | ||
EndIterator Pairs::end() { return EndIterator{}; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#pragma once | ||
#include "LuaAPI.h" | ||
#include <utility> | ||
|
||
class EndIterator | ||
{ | ||
}; | ||
class PairsIterator | ||
{ | ||
public: | ||
PairsIterator(const LuaObject &table); | ||
|
||
PairsIterator &operator++(); | ||
|
||
const std::pair<LuaObject, LuaObject> operator*() const; | ||
|
||
std::pair<LuaObject, LuaObject> operator*(); | ||
|
||
bool operator!=(const EndIterator &) const; | ||
|
||
private: | ||
const LuaObject &table; | ||
LuaObject key; | ||
LuaObject value; | ||
bool done; | ||
}; | ||
|
||
class Pairs | ||
{ | ||
public: | ||
Pairs(const LuaObject &table); | ||
PairsIterator begin(); | ||
EndIterator end(); | ||
|
||
private: | ||
const LuaObject &table; | ||
}; |
Oops, something went wrong.