mirror of https://github.com/axmolengine/axmol.git
* add callback support for lua-llthreads
This commit is contained in:
parent
a99b2f0675
commit
df8231362c
File diff suppressed because it is too large
Load Diff
|
@ -2,25 +2,23 @@
|
|||
#ifndef __LLTHREADS_H_
|
||||
#define __LLTHREADS_H_
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include "lua.h"
|
||||
#include "lauxlib.h"
|
||||
#include "lualib.h"
|
||||
|
||||
|
||||
|
||||
#define REG_PACKAGE_IS_CONSTRUCTOR 0
|
||||
#define REG_OBJECTS_AS_GLOBALS 0
|
||||
#define OBJ_DATA_HIDDEN_METATABLE 1
|
||||
#define LUAJIT_FFI 0
|
||||
#define USE_FIELD_GET_SET_METHODS 0
|
||||
#define REG_PACKAGE_IS_CONSTRUCTOR 0
|
||||
#define REG_OBJECTS_AS_GLOBALS 0
|
||||
#define OBJ_DATA_HIDDEN_METATABLE 1
|
||||
#define LUAJIT_FFI 0
|
||||
#define USE_FIELD_GET_SET_METHODS 0
|
||||
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define __WINDOWS__
|
||||
#else
|
||||
|
@ -113,77 +111,86 @@ typedef void (*dyn_caster_t)(void **obj, obj_type **type);
|
|||
|
||||
#define OBJ_TYPE_FLAG_WEAK_REF (1<<0)
|
||||
#define OBJ_TYPE_SIMPLE (1<<1)
|
||||
struct obj_type {
|
||||
dyn_caster_t dcaster; /**< caster to support casting to sub-objects. */
|
||||
int32_t id; /**< type's id. */
|
||||
uint32_t flags; /**< type's flags (weak refs) */
|
||||
const char *name; /**< type's object name. */
|
||||
struct obj_type
|
||||
{
|
||||
dyn_caster_t dcaster; /**< caster to support casting to sub-objects. */
|
||||
int32_t id; /**< type's id. */
|
||||
uint32_t flags; /**< type's flags (weak refs) */
|
||||
const char *name; /**< type's object name. */
|
||||
};
|
||||
|
||||
typedef struct obj_base {
|
||||
int32_t id;
|
||||
base_caster_t bcaster;
|
||||
typedef struct obj_base
|
||||
{
|
||||
int32_t id;
|
||||
base_caster_t bcaster;
|
||||
} obj_base;
|
||||
|
||||
typedef enum obj_const_type {
|
||||
CONST_UNKOWN = 0,
|
||||
CONST_BOOLEAN = 1,
|
||||
CONST_NUMBER = 2,
|
||||
CONST_STRING = 3
|
||||
typedef enum obj_const_type
|
||||
{
|
||||
CONST_UNKOWN = 0,
|
||||
CONST_BOOLEAN = 1,
|
||||
CONST_NUMBER = 2,
|
||||
CONST_STRING = 3
|
||||
} obj_const_type;
|
||||
|
||||
typedef struct obj_const {
|
||||
const char *name; /**< constant's name. */
|
||||
const char *str;
|
||||
double num;
|
||||
obj_const_type type;
|
||||
typedef struct obj_const
|
||||
{
|
||||
const char *name; /**< constant's name. */
|
||||
const char *str;
|
||||
double num;
|
||||
obj_const_type type;
|
||||
} obj_const;
|
||||
|
||||
typedef enum obj_field_type {
|
||||
TYPE_UNKOWN = 0,
|
||||
TYPE_UINT8 = 1,
|
||||
TYPE_UINT16 = 2,
|
||||
TYPE_UINT32 = 3,
|
||||
TYPE_UINT64 = 4,
|
||||
TYPE_INT8 = 5,
|
||||
TYPE_INT16 = 6,
|
||||
TYPE_INT32 = 7,
|
||||
TYPE_INT64 = 8,
|
||||
TYPE_DOUBLE = 9,
|
||||
TYPE_FLOAT = 10,
|
||||
TYPE_STRING = 11
|
||||
typedef enum obj_field_type
|
||||
{
|
||||
TYPE_UNKOWN = 0,
|
||||
TYPE_UINT8 = 1,
|
||||
TYPE_UINT16 = 2,
|
||||
TYPE_UINT32 = 3,
|
||||
TYPE_UINT64 = 4,
|
||||
TYPE_INT8 = 5,
|
||||
TYPE_INT16 = 6,
|
||||
TYPE_INT32 = 7,
|
||||
TYPE_INT64 = 8,
|
||||
TYPE_DOUBLE = 9,
|
||||
TYPE_FLOAT = 10,
|
||||
TYPE_STRING = 11
|
||||
} obj_field_type;
|
||||
|
||||
typedef struct obj_field {
|
||||
const char *name; /**< field's name. */
|
||||
uint32_t offset; /**< offset to field's data. */
|
||||
obj_field_type type; /**< field's data type. */
|
||||
uint32_t flags; /**< is_writable:1bit */
|
||||
typedef struct obj_field
|
||||
{
|
||||
const char *name; /**< field's name. */
|
||||
uint32_t offset; /**< offset to field's data. */
|
||||
obj_field_type type; /**< field's data type. */
|
||||
uint32_t flags; /**< is_writable:1bit */
|
||||
} obj_field;
|
||||
|
||||
typedef struct reg_sub_module {
|
||||
obj_type *type;
|
||||
int is_package;
|
||||
const luaL_reg *pub_funcs;
|
||||
const luaL_reg *methods;
|
||||
const luaL_reg *metas;
|
||||
const obj_base *bases;
|
||||
const obj_field *fields;
|
||||
const obj_const *constants;
|
||||
typedef struct reg_sub_module
|
||||
{
|
||||
obj_type *type;
|
||||
int is_package;
|
||||
const luaL_reg *pub_funcs;
|
||||
const luaL_reg *methods;
|
||||
const luaL_reg *metas;
|
||||
const obj_base *bases;
|
||||
const obj_field *fields;
|
||||
const obj_const *constants;
|
||||
} reg_sub_module;
|
||||
|
||||
#define OBJ_UDATA_FLAG_OWN (1<<0)
|
||||
#define OBJ_UDATA_FLAG_LOOKUP (1<<1)
|
||||
#define OBJ_UDATA_LAST_FLAG (OBJ_UDATA_FLAG_LOOKUP)
|
||||
typedef struct obj_udata {
|
||||
void *obj;
|
||||
uint32_t flags; /**< lua_own:1bit */
|
||||
typedef struct obj_udata
|
||||
{
|
||||
void *obj;
|
||||
uint32_t flags; /**< lua_own:1bit */
|
||||
} obj_udata;
|
||||
|
||||
#if LUAJIT_FFI
|
||||
typedef struct ffi_export_symbol {
|
||||
const char *name;
|
||||
void *sym;
|
||||
typedef struct ffi_export_symbol
|
||||
{
|
||||
const char *name;
|
||||
void *sym;
|
||||
} ffi_export_symbol;
|
||||
#endif
|
||||
|
||||
|
@ -199,6 +206,62 @@ typedef struct ffi_export_symbol {
|
|||
#define OBJ_DATA_HIDDEN_METATABLE 1
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __WINDOWS__
|
||||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
#include <process.h>
|
||||
#else
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
typedef enum
|
||||
{
|
||||
TSTATE_NONE = 0,
|
||||
TSTATE_STARTED = 1<<0,
|
||||
TSTATE_DETACHED = 1<<1,
|
||||
TSTATE_JOINED = 1<<2,
|
||||
} Lua_TState;
|
||||
|
||||
typedef struct Lua_LLThread_child
|
||||
{
|
||||
lua_State *L;
|
||||
int status;
|
||||
int is_detached;
|
||||
int callback;
|
||||
} Lua_LLThread_child;
|
||||
|
||||
typedef struct Lua_LLThread
|
||||
{
|
||||
Lua_LLThread_child *child;
|
||||
#ifdef __WINDOWS__
|
||||
HANDLE thread;
|
||||
#else
|
||||
pthread_t thread;
|
||||
#endif
|
||||
Lua_TState state;
|
||||
} Lua_LLThread;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
lua_State *from_L;
|
||||
lua_State *to_L;
|
||||
int has_cache;
|
||||
int cache_idx;
|
||||
int is_arg;
|
||||
} llthread_copy_state;
|
||||
|
||||
#define LLTHREAD_REFID_FUNC_MAPPING "llthread_refid_func_mapping"
|
||||
|
||||
#ifdef __WINDOWS__
|
||||
#define RUN_CHILD_THREAD static void
|
||||
#else
|
||||
#define RUN_CHILD_THREAD static void*
|
||||
#endif
|
||||
|
||||
|
||||
int luaopen_llthreads(lua_State *L);
|
||||
int llthread_push_results(lua_State *L, Lua_LLThread_child *child, int idx, int top);
|
||||
|
||||
#endif // __LLTHREADS_H_
|
||||
|
|
Loading…
Reference in New Issue