first commit
This commit is contained in:
58
include/modules/script_squirrel/cobject/cobject.h
Normal file
58
include/modules/script_squirrel/cobject/cobject.h
Normal file
@ -0,0 +1,58 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __COBJECT__
|
||||
#define __COBJECT__
|
||||
|
||||
|
||||
#include "script/script_engine_types.h"
|
||||
#include "script_squirrel/squirrel_vm.h"
|
||||
#include "thread/mutex.h"
|
||||
|
||||
|
||||
namespace GS {
|
||||
namespace Script {
|
||||
struct EngineVM;
|
||||
|
||||
/*!
|
||||
@short Weak/shared reference to native C/C++ objects for the Squirrel VM.
|
||||
@author Emmanuel Julien (ejulien@gsworks.fr)
|
||||
*/
|
||||
class CObject
|
||||
{
|
||||
EngineVM *vm;
|
||||
|
||||
public:
|
||||
|
||||
/// Pop safe user pointer.
|
||||
static bool Get(HSQUIRRELVM, int stack_index, void **, CObjectType = typetag_Undefined);
|
||||
/// Get safe user pointer type.
|
||||
static bool GetType(HSQUIRRELVM, int idx, CObjectType &);
|
||||
// Get a base object from derived types.
|
||||
static bool GetBase(HSQUIRRELVM, int idx, void **, CObjectType *derived_types);
|
||||
/// Push safe user pointer.
|
||||
static bool Push(HSQUIRRELVM, void *, CObjectType, bool managed = false);
|
||||
|
||||
/// Initialize reference to a native type.
|
||||
void Initialize(CObjectType, void *, bool managed);
|
||||
/// Release reference to a native type.
|
||||
void Release();
|
||||
|
||||
bool managed;
|
||||
List <CObject *> ::Item *list_item; // Needs to be cached for fast deletion.
|
||||
|
||||
CObjectType type;
|
||||
void *native;
|
||||
|
||||
CObject(EngineVM *vm, CObjectType = typetag_Undefined, void *p = 0, bool managed = false);
|
||||
~CObject();
|
||||
};
|
||||
|
||||
} // Script
|
||||
} // GS
|
||||
|
||||
|
||||
#endif // __COBJECT__
|
||||
20
include/modules/script_squirrel/cobject/cobject_decl.h
Normal file
20
include/modules/script_squirrel/cobject/cobject_decl.h
Normal file
@ -0,0 +1,20 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __COBJECT_DECL
|
||||
#define __COBJECT_DECL
|
||||
|
||||
|
||||
#include "script_squirrel/cobject/squirrel_bindings_utils.h"
|
||||
|
||||
|
||||
namespace GS { class CObject; }
|
||||
|
||||
_DECL_CLASS(CObject);
|
||||
_DECL_NATIVE_CONSTRUCTION(CObject, GS::CObject);
|
||||
|
||||
|
||||
#endif // __COBJECT_DECL
|
||||
@ -0,0 +1,20 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __COBJECT_GEOMETRY_TEMPLATE_DECL__
|
||||
#define __COBJECT_GEOMETRY_TEMPLATE_DECL__
|
||||
|
||||
|
||||
#include "script_squirrel/cobject/squirrel_bindings_utils.h"
|
||||
|
||||
|
||||
class nGeometryTemplate;
|
||||
|
||||
_DECL_CLASS(GeometryTemplate)
|
||||
_DECL_NATIVE_CONSTRUCTION(GeometryTemplate, nGeometryTemplate)
|
||||
|
||||
|
||||
#endif // __COBJECT_GEOMETRY_TEMPLATE_DECL__
|
||||
25
include/modules/script_squirrel/cobject/matrix_decl.h
Normal file
25
include/modules/script_squirrel/cobject/matrix_decl.h
Normal file
@ -0,0 +1,25 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __COBJECT_MATRIX_DECL__
|
||||
#define __COBJECT_MATRIX_DECL__
|
||||
|
||||
|
||||
#include "script_squirrel/cobject/squirrel_bindings_utils.h"
|
||||
|
||||
|
||||
namespace GS {
|
||||
class Matrix3;
|
||||
class Matrix4;
|
||||
}
|
||||
|
||||
_DECL_CLASS(Matrix3)
|
||||
_DECL_NATIVE_CONSTRUCTION(Matrix3, GS::Matrix3)
|
||||
_DECL_CLASS(Matrix4)
|
||||
_DECL_NATIVE_CONSTRUCTION(Matrix4, GS::Matrix4)
|
||||
|
||||
|
||||
#endif // __COBJECT_MATRIX_DECL__
|
||||
24
include/modules/script_squirrel/cobject/quaternion_decl.h
Normal file
24
include/modules/script_squirrel/cobject/quaternion_decl.h
Normal file
@ -0,0 +1,24 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
nEngine - GSFramework
|
||||
Copyright 2001-2012 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __COBJECT_QUATERNION_DECL__
|
||||
#define __COBJECT_QUATERNION_DECL__
|
||||
|
||||
|
||||
#include "script_squirrel/cobject/squirrel_bindings_utils.h"
|
||||
|
||||
#ifndef _T
|
||||
#define _T
|
||||
#endif
|
||||
|
||||
struct nQuaternion;
|
||||
|
||||
|
||||
_DECL_CLASS(Quaternion)
|
||||
_DECL_NATIVE_CONSTRUCTION(Quaternion, nQuaternion)
|
||||
|
||||
|
||||
#endif // __COBJECT_QUATERNION_DECL__
|
||||
@ -0,0 +1,239 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __CU_BINDING_UTILS__
|
||||
#define __CU_BINDING_UTILS__
|
||||
|
||||
|
||||
#include "squirrel.h"
|
||||
#include "script_squirrel/cobject/squirrel_object.h"
|
||||
|
||||
|
||||
namespace GS {
|
||||
namespace Script {
|
||||
class CObject;
|
||||
}
|
||||
}
|
||||
|
||||
struct ScriptClassMemberDecl
|
||||
{
|
||||
const SQChar *name;
|
||||
SQFUNCTION func;
|
||||
int params;
|
||||
const SQChar *typemask;
|
||||
};
|
||||
|
||||
struct SquirrelClassDecl
|
||||
{
|
||||
const SQChar *name;
|
||||
const SQChar *base;
|
||||
const ScriptClassMemberDecl *members;
|
||||
};
|
||||
|
||||
struct ScriptConstantDecl
|
||||
{
|
||||
const SQChar *name;
|
||||
SQObjectType type;
|
||||
|
||||
union value
|
||||
{
|
||||
value(int v = 0) { i = v; }
|
||||
value(float v) { f = v; }
|
||||
value(const SQChar *v) { s = v; }
|
||||
|
||||
float f;
|
||||
int i;
|
||||
const SQChar *s;
|
||||
} val;
|
||||
};
|
||||
|
||||
struct ScriptNamespaceDecl
|
||||
{
|
||||
const SQChar *name;
|
||||
const ScriptClassMemberDecl *members;
|
||||
const ScriptConstantDecl *constants;
|
||||
const ScriptClassMemberDecl *delegate;
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
#define case_ItemDerived \
|
||||
case typetag_Camera: \
|
||||
case typetag_Object: \
|
||||
case typetag_Light: \
|
||||
case typetag_Trigger: \
|
||||
case typetag_Item:
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
#define _GetCObject(_CPP_CLASS, _TYPETAG, _VAR, _IDX) \
|
||||
_CPP_CLASS *_VAR = NULL; \
|
||||
{ \
|
||||
_GetParamAt(GS::Script::CObject, CObject, _IDX) \
|
||||
if (self->type != _TYPETAG) \
|
||||
return sa.ThrowError("Invalid type"); \
|
||||
if (!self->native) \
|
||||
return sa.ThrowError("Object is null"); \
|
||||
_VAR = (_CPP_CLASS *)self->native; \
|
||||
}
|
||||
|
||||
#define _GetSelfNonNull \
|
||||
_GetSelf(GS::Script::CObject, CObject); \
|
||||
if (!self->native) \
|
||||
return sa.ThrowError("Object is null");
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
#define _BEGIN_CLASS(classname)\
|
||||
SQInteger __##classname##__SCypeof(HSQUIRRELVM v)\
|
||||
{\
|
||||
sq_pushstring(v,_SC(#classname),-1);\
|
||||
return 1;\
|
||||
}\
|
||||
struct ScriptClassMemberDecl __##classname##_members[] = {\
|
||||
{_SC("_SCypeof"),__##classname##__SCypeof,1,NULL},
|
||||
|
||||
#define _BEGIN_NAMESPACE(xnamespace) struct ScriptClassMemberDecl __##xnamespace##_members[] = {
|
||||
#define _BEGIN_NAMESPACE_CONSTANTS(xnamespace) {NULL,NULL,NULL,NULL}}; \
|
||||
struct ScriptConstantDecl __##xnamespace##_constants[] = {
|
||||
|
||||
#define _BEGIN_DELEGATE(xnamespace) struct ScriptClassMemberDecl __##xnamespace##_delegate[] = {
|
||||
#define _DELEGATE(xnamespace) __##xnamespace##_delegate
|
||||
#define _END_DELEGATE(classname) {NULL,NULL,NULL,NULL}};
|
||||
|
||||
#define _CONSTANT(name,type,val) {_SC(#name),type,val},
|
||||
#define _CONSTANT_IMPL(name,type) {_SC(#name),type,name},
|
||||
|
||||
#define _MEMBER_FUNCTION(classname,name,nparams,typemask) \
|
||||
{_SC(#name),__##classname##_##name,nparams,typemask},
|
||||
|
||||
#define _END_NAMESPACE(classname,delegate) {NULL,OT_NULL,0}}; \
|
||||
struct ScriptNamespaceDecl __##classname##_decl = { \
|
||||
_SC(#classname), __##classname##_members,__##classname##_constants,delegate };
|
||||
|
||||
#define _END_CLASS(classname) {NULL,NULL,NULL,NULL}}; \
|
||||
struct SquirrelClassDecl __##classname##_decl = { \
|
||||
_SC(#classname), NULL, __##classname##_members };
|
||||
|
||||
#define _END_CLASS_INHERITANCE(classname,base) {NULL,NULL,NULL,NULL}}; \
|
||||
struct SquirrelClassDecl __##classname##_decl = { \
|
||||
_SC(#classname), _SC(#base), __##classname##_members };
|
||||
|
||||
#define _MEMBER_FUNCTION_IMPL(classname,name) \
|
||||
SQInteger __##classname##_##name(HSQUIRRELVM v) \
|
||||
{ \
|
||||
StackHandler sa(v);
|
||||
#define _END_IMPL }
|
||||
|
||||
#define _INIT_STATIC_NAMESPACE(vm,classname) CreateStaticNamespace(vm,&__##classname##_decl);
|
||||
#define _INIT_CLASS(vm,classname)CreateClass(vm,&__##classname##_decl);
|
||||
|
||||
#define _DECL_STATIC_NAMESPACE(xnamespace) extern struct ScriptNamespaceDecl __##xnamespace##_decl;
|
||||
#define _DECL_CLASS(classname) extern struct SquirrelClassDecl __##classname##_decl;
|
||||
|
||||
#define _GetSelf(cppclass,scriptclass) \
|
||||
cppclass *self = NULL; \
|
||||
if (SQ_FAILED(sq_getinstanceup(v,1,(SQUserPointer*)&self,(SQUserPointer)&__##scriptclass##_decl))) \
|
||||
return sq_throwerror(v,_SC("Invalid instance type"));\
|
||||
if (!self)\
|
||||
return sa.ThrowError("Internal failure");
|
||||
|
||||
#define _GetParamAt(cppclass,scriptclass,idx) \
|
||||
cppclass *self = NULL; \
|
||||
if (SQ_FAILED(sq_getinstanceup(v,idx,(SQUserPointer*)&self,(SQUserPointer)&__##scriptclass##_decl))) \
|
||||
return sq_throwerror(v,_SC("Invalid instance type")); \
|
||||
if (!self) \
|
||||
return sa.ThrowError("Internal failure");
|
||||
|
||||
#define _CHECK_INST_PARAM_RAW(pname,idx,cppclass,scriptclass) \
|
||||
cppclass *pname = NULL; \
|
||||
if (SQ_FAILED(sq_getinstanceup(v,idx,(SQUserPointer*)&pname,(SQUserPointer)&__##scriptclass##_decl))) pname = NULL;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
#define _GetTypedParam(pname,idx,cppclass,scriptclass) \
|
||||
cppclass *pname = NULL; \
|
||||
if (SQ_FAILED(sq_getinstanceup(v,idx,(SQUserPointer*)&pname,(SQUserPointer)&__##scriptclass##_decl))) \
|
||||
return sq_throwerror(v,_SC("Invalid instance type"));
|
||||
|
||||
#define _CHECK_INST_PARAM_COBJECT(__PARAM__, __IDX__, __CPPCLASS__) \
|
||||
__CPPCLASS__ *__PARAM__ = NULL; \
|
||||
{ \
|
||||
_GetTypedParam(c_object, __IDX__, GS::CObject, CObject) \
|
||||
if (!c_object->c_object) \
|
||||
return sq_throwerror(v, "C Object is null"); \
|
||||
__PARAM__ = (__CPPCLASS__ *)c_object->c_object; \
|
||||
}
|
||||
|
||||
#define _CHECK_INST_PARAM_BREAK(pname,idx,cppclass,scriptclass) \
|
||||
cppclass *pname = NULL; \
|
||||
if (SQ_FAILED(sq_getinstanceup(v,idx,(SQUserPointer*)&pname,(SQUserPointer)&__##scriptclass##_decl))) \
|
||||
break;
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
#define _CLASS_SCAG(classname) ((SQUserPointer)&__##classname##_decl)
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
#define _DECL_NATIVE_CONSTRUCTION(classname,cppclass)\
|
||||
bool push_##classname(HSQUIRRELVM v, const cppclass &quat);\
|
||||
SquirrelObject new_##classname(HSQUIRRELVM v, const cppclass &quat);
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
#define _IMPL_NATIVE_CONSTRUCTION(classname, cppclass)\
|
||||
static SQInteger classname##_release_hook(SQUserPointer p, SQInteger size)\
|
||||
{\
|
||||
if (p)\
|
||||
{\
|
||||
cppclass *pv = (cppclass *)p;\
|
||||
delete pv;\
|
||||
}\
|
||||
return 0;\
|
||||
}\
|
||||
bool push_##classname(HSQUIRRELVM vm, const cppclass &quat)\
|
||||
{\
|
||||
cppclass *newquat = new cppclass;\
|
||||
*newquat = quat;\
|
||||
if (!CreateNativeClassInstance(vm,#classname,newquat,classname##_release_hook))\
|
||||
{\
|
||||
delete newquat;\
|
||||
return false;\
|
||||
}\
|
||||
return true;\
|
||||
}\
|
||||
::SquirrelObject new_##classname(HSQUIRRELVM vm, const cppclass &quat)\
|
||||
{\
|
||||
::SquirrelObject ret(vm);\
|
||||
if (push_##classname(vm, quat))\
|
||||
{\
|
||||
ret.AttachToStackObject(-1);\
|
||||
sq_pop(vm, 1);\
|
||||
}\
|
||||
return ret;\
|
||||
}\
|
||||
int construct_##classname(HSQUIRRELVM vm, cppclass *p)\
|
||||
{\
|
||||
sq_setinstanceup(vm, 1, p);\
|
||||
sq_setreleasehook(vm, 1, classname##_release_hook);\
|
||||
return 1;\
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
bool CreateStaticClass(HSQUIRRELVM v, SquirrelClassDecl *cd);
|
||||
bool CreateStaticNamespace(HSQUIRRELVM v, ScriptNamespaceDecl *sn);
|
||||
bool CreateClass(HSQUIRRELVM v, SquirrelClassDecl *cd);
|
||||
bool InitScriptClasses(HSQUIRRELVM v);
|
||||
bool CreateNativeClassInstance(HSQUIRRELVM v, const SQChar *classname, SQUserPointer ud, SQRELEASEHOOK hook);
|
||||
int refcounted_release_hook(SQUserPointer p, int size);
|
||||
int construct_RefCounted(void *p);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
#define _SA_RETURN_OBJECT(__EXP__) { ::SquirrelObject o = __EXP__; return sa.Return(o); }
|
||||
#define _ReturnCObject(__OBJECT__, __TYPE__) { GS::Script::CObject::Push(v, __OBJECT__, __TYPE__); return 1; }
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
||||
#endif // __CU_BINDING_UTILS__
|
||||
187
include/modules/script_squirrel/cobject/squirrel_object.h
Normal file
187
include/modules/script_squirrel/cobject/squirrel_object.h
Normal file
@ -0,0 +1,187 @@
|
||||
#ifndef _SQUIRREL_OBJECT_H_
|
||||
#define _SQUIRREL_OBJECT_H_
|
||||
|
||||
class SquirrelObject
|
||||
{
|
||||
// friend class SquirrelVM;
|
||||
public:
|
||||
SquirrelObject(HSQUIRRELVM vm);
|
||||
virtual ~SquirrelObject();
|
||||
SquirrelObject(const SquirrelObject &o);
|
||||
SquirrelObject(HSQOBJECT &o);
|
||||
SquirrelObject & operator =(const SquirrelObject &o);
|
||||
SquirrelObject & operator =(int n);
|
||||
void Append(const SquirrelObject &o);
|
||||
void AttachToStackObject(int idx);
|
||||
SquirrelObject Clone();
|
||||
bool SetValue(const SquirrelObject &key,const SquirrelObject &val);
|
||||
|
||||
bool SetValue(SQInteger key,const SquirrelObject &val);
|
||||
bool SetValue(int key,bool b);
|
||||
bool SetValue(int key,int n);
|
||||
bool SetValue(int key,float f);
|
||||
bool SetValue(int key,const SQChar *s);
|
||||
|
||||
bool SetValue(const SQChar *key,const SquirrelObject &val);
|
||||
bool SetValue(const SQChar *key,bool b);
|
||||
bool SetValue(const SQChar *key,int n);
|
||||
bool SetValue(const SQChar *key,float f);
|
||||
bool SetValue(const SQChar *key,const SQChar *s);
|
||||
|
||||
bool SetInstanceUP(SQUserPointer up);
|
||||
bool IsNull() const;
|
||||
bool IsNumeric() const;
|
||||
int Len() const;
|
||||
bool SetDelegate(SquirrelObject &obj);
|
||||
SquirrelObject GetDelegate();
|
||||
const SQChar* ToString();
|
||||
bool ToBool();
|
||||
SQInteger ToInteger();
|
||||
SQFloat ToFloat();
|
||||
SQUserPointer GetInstanceUP(SQUserPointer tag) const;
|
||||
SquirrelObject GetValue(const SQChar *key) const;
|
||||
bool Exists(const SQChar *key) const;
|
||||
float GetFloat(const SQChar *key) const;
|
||||
int GetInt(const SQChar *key) const;
|
||||
const SQChar *GetString(const SQChar *key) const;
|
||||
bool GetBool(const SQChar *key) const;
|
||||
SquirrelObject GetValue(int key) const;
|
||||
float GetFloat(int key) const;
|
||||
int GetInt(int key) const;
|
||||
const SQChar *GetString(int key) const;
|
||||
bool GetBool(int key) const;
|
||||
SquirrelObject GetAttributes(const SQChar *key = 0);
|
||||
SQObjectType GetType();
|
||||
HSQOBJECT &GetObject(){return _o;}
|
||||
bool BeginIteration();
|
||||
bool Next(SquirrelObject &key,SquirrelObject &value);
|
||||
void EndIteration();
|
||||
private:
|
||||
bool GetSlot(const SQChar *name) const;
|
||||
bool GetSlot(int key) const;
|
||||
HSQOBJECT _o;
|
||||
HSQUIRRELVM vm;
|
||||
};
|
||||
|
||||
struct StackHandler {
|
||||
StackHandler(HSQUIRRELVM v) {
|
||||
_top = sq_gettop(v);
|
||||
this->v = v;
|
||||
}
|
||||
SQFloat GetFloat(int idx) {
|
||||
SQFloat x = 0.0f;
|
||||
if(idx > 0 && idx <= _top) {
|
||||
sq_getfloat(v,idx,&x);
|
||||
}
|
||||
return x;
|
||||
}
|
||||
SQInteger GetInt(int idx) {
|
||||
SQInteger x = 0;
|
||||
if(idx > 0 && idx <= _top) {
|
||||
sq_getinteger(v,idx,&x);
|
||||
}
|
||||
return x;
|
||||
}
|
||||
HSQOBJECT GetObject(int idx) {
|
||||
HSQOBJECT x;
|
||||
if(idx > 0 && idx <= _top) {
|
||||
sq_resetobject(&x);
|
||||
sq_getstackobj(v,idx,&x);
|
||||
}
|
||||
return x;
|
||||
}
|
||||
const SQChar *GetString(int idx)
|
||||
{
|
||||
const SQChar *x = 0;
|
||||
if(idx > 0 && idx <= _top) {
|
||||
sq_getstring(v,idx,&x);
|
||||
}
|
||||
return x;
|
||||
}
|
||||
SQUserPointer GetUserPointer(int idx)
|
||||
{
|
||||
SQUserPointer x = 0;
|
||||
if(idx > 0 && idx <= _top) {
|
||||
sq_getuserpointer(v,idx,&x);
|
||||
}
|
||||
return x;
|
||||
}
|
||||
SQUserPointer GetInstanceUp(int idx,SQUserPointer tag)
|
||||
{
|
||||
SQUserPointer self;
|
||||
if(SQ_FAILED(sq_getinstanceup(v,idx,(SQUserPointer*)&self,tag)))
|
||||
return 0;
|
||||
return self;
|
||||
}
|
||||
SQUserPointer GetUserdata(int idx,SQUserPointer tag)
|
||||
{
|
||||
SQUserPointer otag;
|
||||
SQUserPointer up;
|
||||
if(idx > 0 && idx <= _top) {
|
||||
if(SQ_SUCCEEDED(sq_getuserdata(v,idx,&up,&otag))) {
|
||||
if(tag == otag)
|
||||
return up;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
bool GetBool(int idx)
|
||||
{
|
||||
SQBool ret;
|
||||
if(idx > 0 && idx <= _top) {
|
||||
if(SQ_SUCCEEDED(sq_getbool(v,idx,&ret)))
|
||||
return ret ? true : false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
int GetType(int idx)
|
||||
{
|
||||
if(idx > 0 && idx <= _top) {
|
||||
return sq_gettype(v,idx);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
SQInteger GetParamCount() {
|
||||
return _top;
|
||||
}
|
||||
int Return(const SQChar *s)
|
||||
{
|
||||
sq_pushstring(v,s,-1);
|
||||
return 1;
|
||||
}
|
||||
int Return(float f)
|
||||
{
|
||||
sq_pushfloat(v,f);
|
||||
return 1;
|
||||
}
|
||||
int Return(int i)
|
||||
{
|
||||
sq_pushinteger(v,i);
|
||||
return 1;
|
||||
}
|
||||
int Return(unsigned int i)
|
||||
{
|
||||
sq_pushinteger(v,i);
|
||||
return 1;
|
||||
}
|
||||
int Return(bool b)
|
||||
{
|
||||
sq_pushbool(v,b);
|
||||
return 1;
|
||||
}
|
||||
int Return(SquirrelObject &o)
|
||||
{
|
||||
sq_pushobject(v,o.GetObject());
|
||||
return 1;
|
||||
}
|
||||
int Return() { return 0; }
|
||||
SQInteger ThrowError(const SQChar *error) {
|
||||
return sq_throwerror(v,error);
|
||||
}
|
||||
private:
|
||||
SQInteger _top;
|
||||
HSQUIRRELVM v;
|
||||
};
|
||||
|
||||
#endif //_SQUIRREL_OBJECT_H_
|
||||
18
include/modules/script_squirrel/cobject/uc_binding.h
Normal file
18
include/modules/script_squirrel/cobject/uc_binding.h
Normal file
@ -0,0 +1,18 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
#ifndef __UC_BINDING__
|
||||
#define __UC_BINDING__
|
||||
|
||||
|
||||
#include "squirrel.h"
|
||||
|
||||
|
||||
/// Register fast OO Squirrel binding.
|
||||
void RegisterUCBinding(HSQUIRRELVM vm);
|
||||
|
||||
|
||||
#endif // __UC_BINDING__
|
||||
19
include/modules/script_squirrel/cobject/uv_decl.h
Normal file
19
include/modules/script_squirrel/cobject/uv_decl.h
Normal file
@ -0,0 +1,19 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __COBJECT_UV_DECL__
|
||||
#define __COBJECT_UV_DECL__
|
||||
|
||||
|
||||
#include "script_squirrel/cobject/squirrel_bindings_utils.h"
|
||||
#include "math/vector.h"
|
||||
|
||||
|
||||
_DECL_CLASS(UV)
|
||||
_DECL_NATIVE_CONSTRUCTION(UV, GS::Vector2)
|
||||
|
||||
|
||||
#endif // __COBJECT_UV_DECL__
|
||||
20
include/modules/script_squirrel/cobject/vector_decl.h
Normal file
20
include/modules/script_squirrel/cobject/vector_decl.h
Normal file
@ -0,0 +1,20 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __COBJECT_VECTOR_DECL__
|
||||
#define __COBJECT_VECTOR_DECL__
|
||||
|
||||
|
||||
#include "script_squirrel/cobject/squirrel_bindings_utils.h"
|
||||
|
||||
|
||||
namespace GS { struct Vector4; }
|
||||
|
||||
_DECL_CLASS(Vector)
|
||||
_DECL_NATIVE_CONSTRUCTION(Vector, GS::Vector4)
|
||||
|
||||
|
||||
#endif // __COBJECT_VECTOR_DECL__
|
||||
41
include/modules/script_squirrel/engine_vm.h
Normal file
41
include/modules/script_squirrel/engine_vm.h
Normal file
@ -0,0 +1,41 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __NENGINEVM__
|
||||
#define __NENGINEVM__
|
||||
|
||||
|
||||
#include "script_squirrel/squirrel_vm.h"
|
||||
|
||||
|
||||
namespace GS {
|
||||
namespace Script {
|
||||
class CObject;
|
||||
|
||||
/*
|
||||
@short Squirrel based virtual machine.
|
||||
*/
|
||||
struct EngineVM : public SquirrelVM
|
||||
{
|
||||
List <CObject *> cobjects;
|
||||
|
||||
/// Release all native references.
|
||||
void ReleaseAllNativeReferences();
|
||||
|
||||
/// Push a variant onto the Squirrel stack.
|
||||
virtual bool PushVariant(const Variant &);
|
||||
/// Invalidate all references to a user object.
|
||||
virtual int InvalidateNativeReference(void *);
|
||||
|
||||
virtual bool Open();
|
||||
virtual void Close();
|
||||
};
|
||||
|
||||
} // Script
|
||||
} // GS
|
||||
|
||||
|
||||
#endif // __NENGINEVM__
|
||||
31
include/modules/script_squirrel/engine_vm_debugger.h
Normal file
31
include/modules/script_squirrel/engine_vm_debugger.h
Normal file
@ -0,0 +1,31 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __ENGINE_VM_DEBUGGER__
|
||||
#define __ENGINE_VM_DEBUGGER__
|
||||
|
||||
|
||||
#include "script_squirrel/squirrel_debugger.h"
|
||||
|
||||
|
||||
namespace GS {
|
||||
namespace Script {
|
||||
struct EngineVM;
|
||||
|
||||
/*
|
||||
@short Editor Squirrel debugger interface.
|
||||
@author Emmanuel Julien (ejulien@nworks.fr)
|
||||
*/
|
||||
struct EngineDebugger : public SquirrelDebugger
|
||||
{
|
||||
EngineDebugger(EngineVM &);
|
||||
};
|
||||
|
||||
} // Script
|
||||
} // GS
|
||||
|
||||
|
||||
#endif // __ENGINE_VM_DEBUGGER__
|
||||
35
include/modules/script_squirrel/engine_vm_profiler.h
Normal file
35
include/modules/script_squirrel/engine_vm_profiler.h
Normal file
@ -0,0 +1,35 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __MONITOR_SCRIPT_PROFILER__
|
||||
#define __MONITOR_SCRIPT_PROFILER__
|
||||
|
||||
|
||||
#include "script/script_profiler.h"
|
||||
#include "script/script_vm.h"
|
||||
#include "squirrel.h"
|
||||
|
||||
|
||||
namespace GS {
|
||||
namespace Script {
|
||||
|
||||
/*
|
||||
@short Engine VM profiler interface.
|
||||
@author Emmanuel Julien (ejulien@nworks.fr)
|
||||
*/
|
||||
struct EngineProfiler : public Profiler
|
||||
{
|
||||
/// Get function profile.
|
||||
FunctionProfile *GetFunctionProfile(const char *source, const char *function, int line, FunctionProfile *profile) { return 0; }
|
||||
/// Update profiler.
|
||||
void Update(int type, FunctionProfile *profile) {}
|
||||
};
|
||||
|
||||
} // Script
|
||||
} // GS
|
||||
|
||||
|
||||
#endif // __MONITOR_SCRIPT_PROFILER__
|
||||
201
include/modules/script_squirrel/legacy/binding_helpers.h
Normal file
201
include/modules/script_squirrel/legacy/binding_helpers.h
Normal file
@ -0,0 +1,201 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __NBINDING_HELPERS__
|
||||
#define __NBINDING_HELPERS__
|
||||
|
||||
|
||||
#include "script_squirrel/cobject/uc_binding.h"
|
||||
#include "script_squirrel/cobject/cobject.h"
|
||||
#include "script_squirrel/cobject/vector_decl.h"
|
||||
#include "math/vector.h"
|
||||
#include "log/log.h"
|
||||
|
||||
|
||||
namespace GS {
|
||||
class MinMax;
|
||||
struct Color;
|
||||
struct Vector4;
|
||||
|
||||
template <class T> struct Rect;
|
||||
|
||||
namespace Script {
|
||||
|
||||
/// Register a native closure in the vm.
|
||||
void sq_register(HSQUIRRELVM v, SQFUNCTION f, const char *fname, const SQChar *mask);
|
||||
/// Create a new class instance on the vm stack.
|
||||
bool CreateClassInstance(HSQUIRRELVM vm, const char *class_name, bool call = false);
|
||||
|
||||
void PushColor(HSQUIRRELVM vm, const Color &c);
|
||||
void PushVector2(HSQUIRRELVM vm, const Vector2 &v);
|
||||
void GetVector2(HSQUIRRELVM vm, SQInteger idx, Vector2 &v);
|
||||
void PushVector(HSQUIRRELVM vm, const Vector4 &v, bool push_w = false);
|
||||
|
||||
void GetVector(HSQUIRRELVM vm, SQInteger idx, Vector4 &v, bool get_w = false);
|
||||
void GetUV(HSQUIRRELVM vm, SQInteger idx, Vector2 &uv);
|
||||
|
||||
void PushMinMax(HSQUIRRELVM vm, const MinMax &v);
|
||||
void GetMinMax(HSQUIRRELVM vm, SQInteger idx, MinMax &v);
|
||||
|
||||
void PushRect(HSQUIRRELVM vm, const Rect <float> &r);
|
||||
void GetRect(HSQUIRRELVM vm, SQInteger idx, Rect <float> &r);
|
||||
void PushRect(HSQUIRRELVM vm, const Rect <int> &r);
|
||||
void GetRect(HSQUIRRELVM vm, SQInteger idx, Rect <int> &r);
|
||||
|
||||
#define GetTableKey(_KEY_, _TYPE_GET_, _IDX_, _TO_)\
|
||||
{\
|
||||
sq_pushstring(vm, _KEY_, -1);\
|
||||
sq_get(vm, (_IDX_) - 1);\
|
||||
_TYPE_GET_(vm, -1, &_TO_);\
|
||||
sq_pop(vm, 1);\
|
||||
}
|
||||
#define SetTableKey(_KEY_, _TYPE_PUSH_, _IDX_, _V_)\
|
||||
{\
|
||||
sq_pushstring(vm, _KEY_, -1);\
|
||||
_TYPE_PUSH_(vm, _V_);\
|
||||
sq_set(vm, (_IDX_) - 2);\
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
#define __SQ_INVALIDATENATIVEREF(__PTR__) ((SquirrelVM *)sq_getforeignptr(vm))->InvalidateNativeReference(__PTR__);
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
#define __SQ_GETSTART(__ARGCOUNT__) \
|
||||
int __sq_stackpos = -(__ARGCOUNT__), __sq_argcount = __ARGCOUNT__;
|
||||
#define __SQ_GETUPDATESTACK \
|
||||
__sq_stackpos++;
|
||||
#define __SQ_GETEND \
|
||||
sq_pop(vm, __sq_argcount);
|
||||
/*
|
||||
sq_pop(vm, __sq_argcount);\
|
||||
if (sq_gettop(vm) != 1)\
|
||||
return sq_throwerror(vm, "Internal binding error, stack configuration is invalid");
|
||||
*/
|
||||
|
||||
#define __SQ_STACKPOS __sq_stackpos
|
||||
|
||||
#define __SQ_GETSAFEPTR(__VARNAME__, __TYPE__, __TAG__) \
|
||||
__TYPE__ *__VARNAME__; if (!GS::Script::CObject::Get(vm, __sq_stackpos, (void **)&__VARNAME__, __TAG__)) return -1; if (!__VARNAME__) return sq_throwerror(vm, "Object is null"); __SQ_GETUPDATESTACK
|
||||
#define __SQ_GETSAFEPTRALLOWNULL(__VARNAME__, __TYPE__, __TAG__) \
|
||||
__TYPE__ *__VARNAME__; if (!GS::Script::CObject::Get(vm, __sq_stackpos, (void **)&__VARNAME__, __TAG__)) return -1; __SQ_GETUPDATESTACK
|
||||
|
||||
#define __SQ_GETCOBJECTBASE(__VARNAME__, __TYPE__, __TAGS__) \
|
||||
__TYPE__ *__VARNAME__; if (!GS::Script::CObject::GetBase(vm, __sq_stackpos, (void **)&__VARNAME__, __TAGS__)) return -1; if (!__VARNAME__) return sq_throwerror(vm, "Object is null"); __SQ_GETUPDATESTACK
|
||||
#define __SQ_GETCOBJECTBASEALLOWNULL(__VARNAME__, __TYPE__, __TAGS__) \
|
||||
__TYPE__ *__VARNAME__; if (!GS::Script::CObject::GetBase(vm, __sq_stackpos, (void **)&__VARNAME__, __TAGS__)) return -1; __SQ_GETUPDATESTACK
|
||||
|
||||
#define __SQ_GETOBJECT(__VARNAME__) \
|
||||
HSQOBJECT __VARNAME__; sq_getstackobj(vm, __sq_stackpos, &__VARNAME__); __SQ_GETUPDATESTACK
|
||||
|
||||
#define __SQ_GETINT(__VARNAME__) \
|
||||
SQInteger __VARNAME__; sq_getinteger(vm, __sq_stackpos, &__VARNAME__); __SQ_GETUPDATESTACK
|
||||
#define __SQ_GETFLOAT(__VARNAME__) \
|
||||
SQFloat __VARNAME__; sq_getfloat(vm, __sq_stackpos, &__VARNAME__); __SQ_GETUPDATESTACK
|
||||
#define __SQ_GETBOOL(__VARNAME__) \
|
||||
SQBool __VARNAME__; sq_getbool(vm, __sq_stackpos, &__VARNAME__); __SQ_GETUPDATESTACK
|
||||
#define __SQ_GETSTRING(__VARNAME__) \
|
||||
const SQChar *__VARNAME__; sq_getstring(vm, __sq_stackpos, &__VARNAME__); __SQ_GETUPDATESTACK
|
||||
|
||||
#define __SQ_GETCOLOR(__VARNAME__) \
|
||||
GS::Color __VARNAME__; GetVector(vm, __sq_stackpos, __VARNAME__); __SQ_GETUPDATESTACK
|
||||
#define __SQ_GETVECTOR2(__VARNAME__) \
|
||||
GS::Vector2 __VARNAME__; GetVector2(vm, __sq_stackpos, __VARNAME__); __SQ_GETUPDATESTACK
|
||||
#define __SQ_GETVECTORTO(__VECTOR__, __CONDITION__) \
|
||||
if (__CONDITION__) GetVector(vm, __sq_stackpos, __VECTOR__); __SQ_GETUPDATESTACK
|
||||
#define __SQ_GETVECTORTOALWAYS(__VECTOR__) \
|
||||
GetVector(vm, __sq_stackpos, __VECTOR__); __SQ_GETUPDATESTACK
|
||||
#define __SQ_GETUVTO(__UV__) \
|
||||
GetUV(vm, __sq_stackpos, __UV__); __SQ_GETUPDATESTACK
|
||||
|
||||
#define __SQ_GETRECT(__VARNAME__) \
|
||||
GS::Rect <int> __VARNAME__; GetRect(vm, __sq_stackpos, __VARNAME__); __SQ_GETUPDATESTACK
|
||||
#define __SQ_GETFRECT(__VARNAME__) \
|
||||
GS::Rect <float> __VARNAME__; GetRect(vm, __sq_stackpos, __VARNAME__); __SQ_GETUPDATESTACK
|
||||
#define __SQ_GETRECTTO(__RECT__) \
|
||||
GetRect(vm, __sq_stackpos, __RECT__); __SQ_GETUPDATESTACK
|
||||
|
||||
#define __SQ_GETSINGLE(__G) \
|
||||
__SQ_GETSTART(1) __G __SQ_GETEND
|
||||
|
||||
#define __SQ_RETURNSAFEPTR(Val, Tag) { GS::Script::CObject::Push(vm, Val, Tag); return 1; }
|
||||
#define __SQ_RETURNMANAGEDSAFEPTR(Val, Tag) { GS::Script::CObject::Push(vm, Val, Tag, true); return 1; }
|
||||
|
||||
#define __SQ_RETURNMINMAX(Val) { PushMinMax(vm, Val); return 1; }
|
||||
#define __SQ_RETURNRECT(Val) { PushRect(vm, Val); return 1; }
|
||||
|
||||
#define __SQ_RETURNCOLOR(Val) { PushColor(vm, Val); return 1; }
|
||||
#define __SQ_RETURNVECTOR2(Val) { PushVector2(vm, Val); return 1; }
|
||||
#define __SQ_RETURNVECTORW(Val) { PushVector(vm, Val, true); return 1; }
|
||||
|
||||
#define __SQ_RETURNMINMAX(Val) { PushMinMax(vm, Val); return 1; }
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Wrap old accessors to the much faster OO ones.
|
||||
#ifndef _T
|
||||
#define _T
|
||||
#endif
|
||||
|
||||
#define __SQ_GETMATRIX3(__VARNAME__) \
|
||||
GS::Matrix3 __VARNAME__;\
|
||||
{ HSQUIRRELVM v = vm;\
|
||||
_GetTypedParam(__mtx, __sq_stackpos, GS::Matrix3, Matrix3);\
|
||||
__VARNAME__ = *__mtx;\
|
||||
__SQ_GETUPDATESTACK }
|
||||
#define __SQ_GETMATRIX4(__VARNAME__) \
|
||||
GS::Matrix4 __VARNAME__;\
|
||||
{ HSQUIRRELVM v = vm;\
|
||||
_GetTypedParam(__mtx, __sq_stackpos, GS::Matrix4, Matrix4);\
|
||||
__VARNAME__ = *__mtx;\
|
||||
__SQ_GETUPDATESTACK }
|
||||
|
||||
#define __SQ_RETURNMATRIX3(__V__) \
|
||||
{ StackHandler sa(vm);\
|
||||
_SA_RETURN_OBJECT(new_Matrix3(vm, __V__)) }
|
||||
#define __SQ_RETURNMATRIX4(__V__) \
|
||||
{ StackHandler sa(vm);\
|
||||
_SA_RETURN_OBJECT(new_Matrix4(vm, __V__)) }
|
||||
|
||||
#define __SQ_GETVECTORW(__VARNAME__) \
|
||||
GS::Vector4 __VARNAME__;\
|
||||
{ HSQUIRRELVM v = vm;\
|
||||
_GetTypedParam(__vec, __sq_stackpos, GS::Vector4, Vector);\
|
||||
__VARNAME__ = *__vec;\
|
||||
__SQ_GETUPDATESTACK }
|
||||
#define __SQ_GETVECTOR(__VARNAME__) \
|
||||
__SQ_GETVECTORW(__VARNAME__) \
|
||||
__VARNAME__.w = 1;
|
||||
|
||||
#define __SQ_RETURNVECTOR(Val) \
|
||||
{ StackHandler sa(vm);\
|
||||
_SA_RETURN_OBJECT(new_Vector(vm, Val)) }
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#define __SQ_RETURNINT(Val) { sq_pushinteger(vm, Val); return 1; }
|
||||
#define __SQ_RETURNFLOAT(Val) { sq_pushfloat(vm, Val); return 1; }
|
||||
#define __SQ_RETURNBOOL(Val) { sq_pushbool(vm, Val ? SQTrue : SQFalse); return 1; }
|
||||
#define __SQ_RETURNNULL { sq_pushnull(vm); return 1; }
|
||||
#define __SQ_RETURNSTRING(Val) { sq_pushstring(vm, Val, -1); return 1; }
|
||||
#define __SQ_RETURNOBJECT(Val) { sq_pushobject(vm, Val); return 1; }
|
||||
|
||||
#define __SQ_RETURN return 0;
|
||||
|
||||
#define __SQ_GETSINGLESAFEPTR(Name, Type, Tag) \
|
||||
__SQ_GETSTART(1) \
|
||||
__SQ_GETSAFEPTR(Name, Type, Tag) \
|
||||
__SQ_GETEND
|
||||
|
||||
#define __SQ_GETSINGLESAFEPTRALLOWNULL(Name, Type, Tag) \
|
||||
__SQ_GETSTART(1) \
|
||||
__SQ_GETSAFEPTRALLOWNULL(Name, Type, Tag) \
|
||||
__SQ_GETEND
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
} // Script
|
||||
} // GS
|
||||
|
||||
|
||||
#endif // __NBINDING_HELPERS__
|
||||
63
include/modules/script_squirrel/legacy/squirrel_binding.h
Normal file
63
include/modules/script_squirrel/legacy/squirrel_binding.h
Normal file
@ -0,0 +1,63 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __NMANAGER_SCRIPT_BINDING__
|
||||
#define __NMANAGER_SCRIPT_BINDING__
|
||||
|
||||
|
||||
/// Squirrel API compatible version.
|
||||
#define __SQUIRREL_API_VERSION_COMPATIBILITY__ 1
|
||||
/// Current Squirrel API version.
|
||||
#define __SQUIRREL_API_VERSION__ 2
|
||||
|
||||
typedef struct SQVM* HSQUIRRELVM;
|
||||
|
||||
|
||||
void RegisterAIBinding(HSQUIRRELVM);
|
||||
void RegisterAnimationBinding(HSQUIRRELVM);
|
||||
void RegisterCameraBinding(HSQUIRRELVM);
|
||||
void RegisterClockBinding(HSQUIRRELVM);
|
||||
void RegisterCollisionBinding(HSQUIRRELVM);
|
||||
void RegisterEmitterBinding(HSQUIRRELVM);
|
||||
void RegisterGeometryBinding(HSQUIRRELVM);
|
||||
void RegisterFontBinding(HSQUIRRELVM);
|
||||
void RegisterGroupBinding(HSQUIRRELVM);
|
||||
void RegisterHashBinding(HSQUIRRELVM);
|
||||
void RegisterHTTPBinding(HSQUIRRELVM);
|
||||
void RegisterWebSocketBinding(HSQUIRRELVM);
|
||||
void RegisterInstanceBinding(HSQUIRRELVM);
|
||||
void RegisterIOBinding(HSQUIRRELVM);
|
||||
void RegisterItemBinding(HSQUIRRELVM);
|
||||
void RegisterLightBinding(HSQUIRRELVM);
|
||||
void RegisterProfilerBinding(HSQUIRRELVM);
|
||||
void RegisterMaterialBinding(HSQUIRRELVM);
|
||||
void RegisterMatrixBinding(HSQUIRRELVM);
|
||||
void RegisterMixerBinding(HSQUIRRELVM);
|
||||
void RegisterMotionBinding(HSQUIRRELVM);
|
||||
void RegisterNMLBinding(HSQUIRRELVM);
|
||||
void RegisterObjectBinding(HSQUIRRELVM);
|
||||
void RegisterPhysicBinding(HSQUIRRELVM);
|
||||
void RegisterPictureBinding(HSQUIRRELVM);
|
||||
void RegisterProjectBinding(HSQUIRRELVM);
|
||||
void RegisterRaytracerBinding(HSQUIRRELVM);
|
||||
void RegisterRendererBinding(HSQUIRRELVM);
|
||||
void RegisterResourceFactoryBinding(HSQUIRRELVM);
|
||||
void RegisterSceneBinding(HSQUIRRELVM);
|
||||
void RegisterSoundBinding(HSQUIRRELVM);
|
||||
void RegisterSystemBinding(HSQUIRRELVM);
|
||||
void RegisterTextureBinding(HSQUIRRELVM);
|
||||
void RegisterTriggerBinding(HSQUIRRELVM);
|
||||
void RegisterUIBinding(HSQUIRRELVM);
|
||||
void RegisterPlatformBinding(HSQUIRRELVM);
|
||||
void RegisterMaterialShaderBinding(HSQUIRRELVM);
|
||||
|
||||
void RegisterAllSquirrelBinding(HSQUIRRELVM);
|
||||
|
||||
|
||||
#define GetVMObject(__VM__) ((GS::Script::SquirrelVM *)sq_getforeignptr(__VM__))
|
||||
|
||||
|
||||
#endif // __NMANAGER_SCRIPT_BINDING__
|
||||
118
include/modules/script_squirrel/legacy/ws_manager.h
Normal file
118
include/modules/script_squirrel/legacy/ws_manager.h
Normal file
@ -0,0 +1,118 @@
|
||||
#ifndef WS_MANAGER_H
|
||||
#define WS_MANAGER_H
|
||||
|
||||
// Must be defined before including any Windows headers
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <queue>
|
||||
#endif
|
||||
|
||||
#ifndef NOMINMAX
|
||||
#define NOMINMAX
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32_WINNT
|
||||
#define _WIN32_WINNT 0x0601 // Windows 7 or later
|
||||
#endif
|
||||
|
||||
// Winsock and Bluetooth headers
|
||||
#include <winsock2.h>
|
||||
#include <ws2bth.h>
|
||||
#include <bluetoothapis.h>
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include <chrono>
|
||||
#include <vector>
|
||||
#include <atomic>
|
||||
#include <squirrel.h>
|
||||
|
||||
// Link required libraries
|
||||
#pragma comment(lib, "ws2_32.lib")
|
||||
#pragma comment(lib, "Bthprops.lib")
|
||||
|
||||
#ifndef BT_PORT_ANY
|
||||
#define BT_PORT_ANY ((ULONG)-1)
|
||||
#endif
|
||||
|
||||
#ifndef BTH_ADDR_NULL
|
||||
#define BTH_ADDR_NULL ((BTH_ADDR)0)
|
||||
#endif
|
||||
|
||||
class WebSocketManager {
|
||||
public:
|
||||
struct CallbackEvent {
|
||||
enum Type { CONNECT, DISCONNECT, MESSAGE };
|
||||
Type type;
|
||||
std::string data;
|
||||
SOCKET client_socket;
|
||||
};
|
||||
|
||||
struct ClientConnection {
|
||||
SOCKET socket;
|
||||
std::thread receive_thread;
|
||||
std::atomic<bool> active;
|
||||
|
||||
ClientConnection(SOCKET s) : socket(s), active(true) {}
|
||||
};
|
||||
|
||||
private:
|
||||
SOCKET m_listen_socket;
|
||||
std::vector<ClientConnection*> m_connections;
|
||||
mutable std::mutex m_connections_mutex;
|
||||
std::thread m_accept_thread;
|
||||
std::atomic<bool> m_running;
|
||||
bool m_initialized;
|
||||
std::chrono::steady_clock::time_point m_start_time;
|
||||
uint16_t m_port;
|
||||
|
||||
// Squirrel VM and callbacks
|
||||
HSQUIRRELVM m_vm;
|
||||
HSQOBJECT m_on_connect_callback;
|
||||
HSQOBJECT m_on_disconnect_callback;
|
||||
HSQOBJECT m_on_message_callback;
|
||||
bool m_has_on_connect;
|
||||
bool m_has_on_disconnect;
|
||||
bool m_has_on_message;
|
||||
|
||||
// Event queue - car la VM Squirrel n'est pas thread-safe
|
||||
// Les callbacks doivent être appelés depuis le thread principal
|
||||
std::queue<CallbackEvent> m_event_queue;
|
||||
mutable std::mutex m_queue_mutex;
|
||||
|
||||
void InternalOnConnect(SOCKET client_socket);
|
||||
void InternalOnDisconnect(SOCKET client_socket);
|
||||
void InternalOnMessage(SOCKET client_socket, const std::string& message);
|
||||
|
||||
void InitializeServer();
|
||||
void AcceptLoop();
|
||||
void ReceiveLoop(ClientConnection* connection);
|
||||
bool SendToClient(SOCKET client_socket, const std::string& message);
|
||||
|
||||
public:
|
||||
WebSocketManager(HSQUIRRELVM vm);
|
||||
~WebSocketManager();
|
||||
|
||||
// Server control
|
||||
bool Start(uint16_t port);
|
||||
void Stop();
|
||||
bool IsRunning() const { return m_running; }
|
||||
|
||||
// Messaging
|
||||
void Broadcast(const std::string& message);
|
||||
|
||||
// Statistics
|
||||
int GetConnectionCount() const;
|
||||
float GetUptime() const;
|
||||
uint16_t GetPort() const { return m_port; }
|
||||
|
||||
// Squirrel callbacks
|
||||
void SetOnConnectCallback(HSQOBJECT callback);
|
||||
void SetOnDisconnectCallback(HSQOBJECT callback);
|
||||
void SetOnMessageCallback(HSQOBJECT callback);
|
||||
|
||||
// Process events - DOIT être appelé depuis le thread principal !
|
||||
// C'est ici que les callbacks Squirrel sont réellement invoqués
|
||||
void ProcessEvents();
|
||||
};
|
||||
|
||||
#endif // WS_MANAGER_H
|
||||
44
include/modules/script_squirrel/mmf.h
Normal file
44
include/modules/script_squirrel/mmf.h
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
|
||||
Tau [Physic engine]
|
||||
|
||||
Emmanuel Julien 2004~2005.
|
||||
http://xbarr.ninomojo.com
|
||||
mailto:ejulien@nengine.fr
|
||||
------------------------------------------
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __MMF_SYSTEM__
|
||||
#define __MMF_SYSTEM__
|
||||
|
||||
|
||||
|
||||
#include <TCHAR.H>
|
||||
#include <windows.H>
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
class CMMF
|
||||
{
|
||||
public:
|
||||
CMMF(LPCTSTR MMFName, int size, LPCTSTR mutexName);
|
||||
~CMMF();
|
||||
void Read(void* pData, bool read = true);
|
||||
void Write(void* pData);
|
||||
LPVOID GetMMF() { return m_pSharedData; }
|
||||
|
||||
protected:
|
||||
LPVOID m_pSharedData;
|
||||
|
||||
private:
|
||||
CMMF() {}
|
||||
int m_nSize;
|
||||
HANDLE m_hFileMapping;
|
||||
HANDLE m_hMutex;
|
||||
};
|
||||
|
||||
|
||||
#endif // __MMF_SYSTEM__
|
||||
104
include/modules/script_squirrel/squirrel_analyzer.h
Normal file
104
include/modules/script_squirrel/squirrel_analyzer.h
Normal file
@ -0,0 +1,104 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __NSQUIRRELANALYZER__
|
||||
#define __NSQUIRRELANALYZER__
|
||||
|
||||
|
||||
#include "memory/nshared_ptr.h"
|
||||
#include "memory/nweak_ptr.h"
|
||||
#include "container/nlist.h"
|
||||
#include "nstring/nstring.h"
|
||||
|
||||
|
||||
namespace GS {
|
||||
namespace SquirrelAnalyzer {
|
||||
|
||||
struct Offset
|
||||
{
|
||||
int line, column;
|
||||
|
||||
Offset(int l = 0, int c = 0) : line(l), column(c) {}
|
||||
};
|
||||
|
||||
struct Symbol : public SharedObject
|
||||
{
|
||||
enum Type
|
||||
{
|
||||
TypeNone,
|
||||
TypeVariable,
|
||||
TypeFunction,
|
||||
TypeClass
|
||||
};
|
||||
|
||||
String name;
|
||||
Type type;
|
||||
|
||||
Offset offset;
|
||||
|
||||
Symbol() : type(TypeNone) {}
|
||||
};
|
||||
|
||||
struct Variable : public Symbol
|
||||
{
|
||||
enum VarType
|
||||
{
|
||||
VarNone,
|
||||
VarLocal,
|
||||
VarGlobal,
|
||||
VarMember,
|
||||
VarEnum
|
||||
};
|
||||
|
||||
VarType var_type;
|
||||
|
||||
Variable() : var_type(VarNone) { type = TypeVariable; }
|
||||
};
|
||||
|
||||
struct Function : public Symbol
|
||||
{
|
||||
SharedList <Symbol *> symbols;
|
||||
String prototype;
|
||||
|
||||
Function() { type = TypeFunction; }
|
||||
};
|
||||
|
||||
struct Class : public Symbol
|
||||
{
|
||||
String extends;
|
||||
SharedList <Symbol *> symbols;
|
||||
|
||||
Class() { type = TypeClass; }
|
||||
};
|
||||
|
||||
struct Source
|
||||
{
|
||||
String name;
|
||||
SharedList <Symbol *> symbols;
|
||||
};
|
||||
|
||||
struct SourceSymbol
|
||||
{
|
||||
SharedPtr <Source> source;
|
||||
SharedPtr <Symbol> symbol;
|
||||
};
|
||||
|
||||
struct Program
|
||||
{
|
||||
AutoList <Source *> sources;
|
||||
bool FindSymbol(const char *name, AutoList <SourceSymbol *> &symbols);
|
||||
};
|
||||
|
||||
void DumpProgram(const Program &);
|
||||
|
||||
/// Analyze a source, store result in program object.
|
||||
Source *Analyze(const char *nut, Program &, bool replace = true);
|
||||
|
||||
} // SquirrelAnalyser
|
||||
} // GS
|
||||
|
||||
|
||||
#endif // __NSQUIRRELANALYZER__
|
||||
63
include/modules/script_squirrel/squirrel_debugger.h
Normal file
63
include/modules/script_squirrel/squirrel_debugger.h
Normal file
@ -0,0 +1,63 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __SQUIRREL_DEBUGGER__
|
||||
#define __SQUIRREL_DEBUGGER__
|
||||
|
||||
|
||||
#include "script/script_debugger.h"
|
||||
#include "squirrel.h"
|
||||
|
||||
|
||||
namespace GS {
|
||||
namespace Script {
|
||||
class SquirrelVM;
|
||||
|
||||
/*
|
||||
@short Squirrel debugger interface.
|
||||
@author Emmanuel Julien (ejulien@nworks.fr)
|
||||
*/
|
||||
class SquirrelDebugger : public IDebugger
|
||||
{
|
||||
protected:
|
||||
|
||||
HSQUIRRELVM vm;
|
||||
|
||||
/// Insert a variable in the variable tree.
|
||||
DebuggerVariable *InsertVariable(const char *name, AutoList <DebuggerVariable *> &tree, int level);
|
||||
|
||||
public:
|
||||
|
||||
/*!
|
||||
@name Interface.
|
||||
@{
|
||||
*/
|
||||
/// Format variable parameter.
|
||||
virtual String FormatParameter(DebuggerVariable *variable);
|
||||
/// Format safe ptr parameter.
|
||||
virtual String FormatUserObjectParameter(CObjectType type);
|
||||
/// Convert a debugger variable to a meta string.
|
||||
virtual void VariableToMetatagString(DebuggerVariable *, String &);
|
||||
|
||||
/// Get call stack depth.
|
||||
virtual int GetCallstackDepth();
|
||||
/// Get current script execution call frame index.
|
||||
virtual int GetStackFrameIndex();
|
||||
|
||||
/// Refresh stack locals list.
|
||||
virtual void RefreshStackFrameLocalsCache();
|
||||
/// Get source/line info for the current debug stack frame.
|
||||
virtual void GetStackFrameSource(const char *&, int &);
|
||||
/// @}
|
||||
|
||||
SquirrelDebugger(SquirrelVM &);
|
||||
};
|
||||
|
||||
} // Script
|
||||
} // GS
|
||||
|
||||
|
||||
#endif // __SQUIRREL_DEBUGGER__
|
||||
116
include/modules/script_squirrel/squirrel_vm.h
Normal file
116
include/modules/script_squirrel/squirrel_vm.h
Normal file
@ -0,0 +1,116 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __NSQUIRRELVM__
|
||||
#define __NSQUIRRELVM__
|
||||
|
||||
|
||||
#include "squirrel.h"
|
||||
#include "script/script_vm.h"
|
||||
#include "script/script_object.h"
|
||||
|
||||
|
||||
namespace GS {
|
||||
namespace Script {
|
||||
class SquirrelVM;
|
||||
|
||||
//
|
||||
struct SquirrelObject : public Object
|
||||
{
|
||||
HSQOBJECT object;
|
||||
SquirrelObject(SquirrelVM &, HSQOBJECT);
|
||||
~SquirrelObject();
|
||||
};
|
||||
|
||||
/*
|
||||
@short Squirrel based virtual machine.
|
||||
@author Emmanuel Julien (ejulien@nworks.fr)
|
||||
*/
|
||||
class SquirrelVM : public IVM
|
||||
{
|
||||
protected:
|
||||
|
||||
HSQUIRRELVM vm;
|
||||
|
||||
int call_arg_count;
|
||||
|
||||
public:
|
||||
|
||||
/// Get VM name.
|
||||
const char *GetName() const { return "Squirrel"; }
|
||||
|
||||
/// Get VM call stack.
|
||||
void GetCallStack(AutoList <CallStackEntry *> &);
|
||||
|
||||
/*!
|
||||
@name Squirrel specific API.
|
||||
@{
|
||||
*/
|
||||
HSQUIRRELVM VM() const { return vm; }
|
||||
|
||||
/// Set event hook table.
|
||||
virtual void SetDebugInterface(IDebug *, bool enable_step_hook = false);
|
||||
|
||||
/// Dump VM call stack.
|
||||
static void DumpCallStack(HSQUIRRELVM, const char *desc, String *msg = 0);
|
||||
|
||||
/// Push null value onto the stack.
|
||||
virtual bool PushNull();
|
||||
/// Push property onto the stack.
|
||||
virtual bool PushVariant(const Variant &);
|
||||
/// Get Squirrel value from stack.
|
||||
virtual bool GetVariantFromStack(int stack_index, Variant &);
|
||||
/// Get a reference to a stack object.
|
||||
Object *GetObjectFromStack(int stack_index);
|
||||
/// @}
|
||||
|
||||
/// Get a reference to a VM object.
|
||||
virtual Object *GetObjectFromName(const char *name, const Object *context = 0);
|
||||
|
||||
/// Setup a function call in the VM.
|
||||
virtual bool SetupFunctionCall(const char *func, const Object *function_object = 0, const Object *search_context = 0);
|
||||
/// Set function call context.
|
||||
virtual bool SetFunctionCallContext(const Variant &);
|
||||
/// Push function call null argument.
|
||||
virtual bool PushNullArgument();
|
||||
/// Push function call argument.
|
||||
virtual bool PushArgument(const Variant &);
|
||||
/// Execute a function call in the VM.
|
||||
virtual bool DoFunctionCall(Variant *return_value = 0);
|
||||
|
||||
/// Invalidate all references to a user object.
|
||||
virtual int InvalidateNativeReference(void *) { return 0; }
|
||||
|
||||
/// Compile a script.
|
||||
virtual bool Compile(const char *source, uint size, const Object *context = 0, const char *sourcename = 0);
|
||||
|
||||
/// Create a table object.
|
||||
virtual Object *CreateTable();
|
||||
/// Set a VM variable.
|
||||
virtual bool Set(const char *name, const Variant &, const Object *context = 0);
|
||||
/// Get a VM variable.
|
||||
virtual bool Get(const char *name, Variant &, const Object *context = 0);
|
||||
|
||||
/// Create a script array.
|
||||
virtual Object *CreateArray();
|
||||
/// Append a VM variable to an array.
|
||||
virtual bool Append(const Variant &, const Object *context = 0);
|
||||
|
||||
/// Is the VM open.
|
||||
virtual bool IsOpen() const { return asbool(vm); }
|
||||
|
||||
virtual bool Open();
|
||||
virtual void Close();
|
||||
|
||||
SquirrelVM();
|
||||
virtual ~SquirrelVM();
|
||||
};
|
||||
|
||||
} // Script
|
||||
} // GS
|
||||
|
||||
|
||||
#endif // __NSQUIRRELVM__
|
||||
Reference in New Issue
Block a user