1 #ifndef __R_OBJECT_REF_H
2 #define __R_OBJECT_REF_H
3 
4 /*
5 Copyright 2012 Jared Krinke.
6 
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software and associated documentation files (the "Software"), to deal
9 in the Software without restriction, including without limitation the rights
10 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 copies of the Software, and to permit persons to whom the Software is
12 furnished to do so, subject to the following conditions:
13 
14 The above copyright notice and this permission notice shall be included in
15 all copies or substantial portions of the Software.
16 
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 THE SOFTWARE.
24 */
25 
26 #include <lua.h>
27 
28 #include "r_object.h"
29 
30 #define R_OBJECT_REF_INVALID       -1
31 
32 typedef struct
33 {
34     int                 ref;
35 
36     union
37     {
38         void            *pointer;
39         r_object_t      *object;
40         const char      *str;
41         lua_CFunction   function;
42     } value;
43 } r_object_ref_t;
44 
r_object_ref_init(r_object_ref_t * object_ref)45 R_INLINE void r_object_ref_init(r_object_ref_t *object_ref)
46 {
47     object_ref->ref = R_OBJECT_REF_INVALID;
48     object_ref->value.pointer = NULL;
49 }
50 
51 extern r_status_t r_object_ref_clear(r_state_t *rs, r_object_t *object, r_object_ref_t *object_ref);
52 
53 extern r_status_t r_object_ref_push(r_state_t *rs, r_object_t *object, const r_object_ref_t *object_ref);
54 
55 extern r_status_t r_object_ref_write(r_state_t *rs, r_object_t *object, r_object_ref_t *object_ref, r_object_type_t object_type, int value_index);
56 extern r_status_t r_object_string_ref_write(r_state_t *rs, r_object_t *object, r_object_ref_t *object_ref, int value_index);
57 extern r_status_t r_object_function_ref_write(r_state_t *rs, r_object_t *object, r_object_ref_t *object_ref, int value_index);
58 extern r_status_t r_object_table_ref_write(r_state_t *rs, r_object_t *object, r_object_ref_t *object_ref, int value_index);
59 
60 extern r_status_t r_object_field_object_init_new(r_state_t *rs, r_object_t *object, void *value, r_object_type_t field_type, r_object_ref_t *object_new_ref);
61 
62 extern r_status_t r_object_ref_field_read_global(r_state_t *rs, r_object_t *object, const r_object_field_t *field, void *value);
63 
64 #endif
65 
66