|
@@ -12,27 +12,6 @@
|
|
|
|
|
|
|
|
LUWRA_NS_BEGIN
|
|
LUWRA_NS_BEGIN
|
|
|
|
|
|
|
|
-namespace internal {
|
|
|
|
|
- template <typename K, typename V, typename... R>
|
|
|
|
|
- struct EntryPusher {
|
|
|
|
|
- static inline
|
|
|
|
|
- void push(State* state, int index, K&& key, V&& value, R&&... rest) {
|
|
|
|
|
- EntryPusher<K, V>::push(state, index, std::forward<K>(key), std::forward<V>(value));
|
|
|
|
|
- EntryPusher<R...>::push(state, index, std::forward<R>(rest)...);
|
|
|
|
|
- }
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
- template <typename K, typename V>
|
|
|
|
|
- struct EntryPusher<K, V> {
|
|
|
|
|
- static inline
|
|
|
|
|
- void push(State* state, int index, K&& key, V&& value) {
|
|
|
|
|
- assert(1 == luwra::push(state, key));
|
|
|
|
|
- assert(1 == luwra::push(state, value));
|
|
|
|
|
- lua_rawset(state, index < 0 ? index - 2 : index);
|
|
|
|
|
- }
|
|
|
|
|
- };
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
/**
|
|
/**
|
|
|
* Check if two values are equal.
|
|
* Check if two values are equal.
|
|
|
*/
|
|
*/
|
|
@@ -67,6 +46,27 @@ V getGlobal(State* state, const std::string& name) {
|
|
|
return instance;
|
|
return instance;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+namespace internal {
|
|
|
|
|
+ template <typename K, typename V, typename... R>
|
|
|
|
|
+ struct EntryPusher {
|
|
|
|
|
+ static inline
|
|
|
|
|
+ void push(State* state, int index, K&& key, V&& value, R&&... rest) {
|
|
|
|
|
+ EntryPusher<K, V>::push(state, index, std::forward<K>(key), std::forward<V>(value));
|
|
|
|
|
+ EntryPusher<R...>::push(state, index, std::forward<R>(rest)...);
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ template <typename K, typename V>
|
|
|
|
|
+ struct EntryPusher<K, V> {
|
|
|
|
|
+ static inline
|
|
|
|
|
+ void push(State* state, int index, K&& key, V&& value) {
|
|
|
|
|
+ assert(1 == luwra::push(state, key));
|
|
|
|
|
+ assert(1 == luwra::push(state, value));
|
|
|
|
|
+ lua_rawset(state, index < 0 ? index - 2 : index);
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* Set multiple fields at once. Allows you to provide multiple key-value pairs.
|
|
* Set multiple fields at once. Allows you to provide multiple key-value pairs.
|
|
|
*/
|
|
*/
|
|
@@ -76,6 +76,23 @@ void setFields(State* state, int index, R&&... args) {
|
|
|
internal::EntryPusher<R...>::push(state, index, std::forward<R>(args)...);
|
|
internal::EntryPusher<R...>::push(state, index, std::forward<R>(args)...);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+/**
|
|
|
|
|
+ * Retrieve a field from a table.
|
|
|
|
|
+ */
|
|
|
|
|
+template <typename V, typename K> static inline
|
|
|
|
|
+V getField(State* state, int index, K key) {
|
|
|
|
|
+ if (index < 0)
|
|
|
|
|
+ index = lua_gettop(state) + (index + 1);
|
|
|
|
|
+
|
|
|
|
|
+ assert(push<K>(state, key) == 1);
|
|
|
|
|
+ lua_rawget(state, index);
|
|
|
|
|
+
|
|
|
|
|
+ V value = read<V>(state, -1);
|
|
|
|
|
+ lua_pop(state, 1);
|
|
|
|
|
+
|
|
|
|
|
+ return value;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* Create a new table and set its fields.
|
|
* Create a new table and set its fields.
|
|
|
*/
|
|
*/
|