Exemplo n.º 1
0
static duk_ret_t duk_btnp(duk_context* duk)
{
	tic_machine* machine = getDukMachine(duk);
	tic_mem* memory = (tic_mem*)machine;

	if (duk_is_null_or_undefined(duk, 0))
	{
		duk_push_uint(duk, memory->api.btnp(memory, -1, -1, -1));
	}
	else if(duk_is_null_or_undefined(duk, 1) && duk_is_null_or_undefined(duk, 2))
	{
		s32 index = duk_to_int(duk, 0) & 0x1f;

		duk_push_boolean(duk, memory->api.btnp(memory, index, -1, -1));
	}
	else
	{
		s32 index = duk_to_int(duk, 0) & 0x1f;
		u32 hold = duk_to_int(duk, 1);
		u32 period = duk_to_int(duk, 2);

		duk_push_boolean(duk, memory->api.btnp(memory, index, hold, period));
	}

	return 1;
}
Exemplo n.º 2
0
static s32 duk_keyp(duk_context* duk)
{
	tic_machine* machine = getDukMachine(duk);
	tic_mem* tic = &machine->memory;

	if (duk_is_null_or_undefined(duk, 0))
	{
		duk_push_boolean(duk, tic->api.keyp(tic, tic_key_unknown, -1, -1));
	}
	else
	{
		tic_key key = duk_to_int(duk, 0);

		if(key >= tic_key_escape)
		{
			return duk_error(duk, DUK_ERR_ERROR, "unknown keyboard code\n");
		}
		else
		{
			if(duk_is_null_or_undefined(duk, 1) && duk_is_null_or_undefined(duk, 2))
			{
				duk_push_boolean(duk, tic->api.keyp(tic, key, -1, -1));
			}
			else
			{
				u32 hold = duk_to_int(duk, 1);
				u32 period = duk_to_int(duk, 2);

				duk_push_boolean(duk, tic->api.keyp(tic, key, hold, period));
			}
		}
	}

	return 1;
}
Exemplo n.º 3
0
static int Serializer_Write(duk_context* ctx)
{
    duk_int_t magic = duk_get_current_magic(ctx);

    duk_push_this(ctx);

    // safe cast based on type check above
    Serializer* serial = CastToSerializer(ctx, duk_get_top_index(ctx));

    duk_pop(ctx);

    if (!serial)
    {
        duk_push_boolean(ctx, 0);
        return 1;
    }

    const char* str;
    size_t length;

    IO_MAGIC_TYPE v = (IO_MAGIC_TYPE) magic;

    bool success = false;

    switch(v)
    {
        case IO_MAGIC_INT:
            success = serial->WriteInt((int) duk_require_number(ctx, 0));
            break;
        case IO_MAGIC_STRING:
             str = duk_require_string(ctx, 0);
             length = strlen(str);
             success = serial->Write(str, length);
             /*
             if (length)
             {
                buffer.Resize(length);

                for (size_t i = 0; i < length; i++)
                    buffer[i] = str[i];

                serial->WriteBuffer(buffer);
             }
             */
            break;
        case IO_MAGIC_ZEROSTRING:
            success = serial->WriteString(duk_require_string(ctx, 0));
            break;
        default:
            break;
    }

    duk_push_boolean(ctx, success ? 1 : 0);

    return 1;

}
Exemplo n.º 4
0
duk_idx_t AJS_UnmarshalMessage(duk_context* ctx, AJ_Message* msg, uint8_t accessor)
{
    duk_idx_t objIndex = duk_push_object(ctx);

    duk_push_string(ctx, msg->sender);
    duk_put_prop_string(ctx, objIndex, "sender");

    if ((msg->hdr->msgType == AJ_MSG_METHOD_CALL) || (msg->hdr->msgType == AJ_MSG_SIGNAL)) {
        duk_push_string(ctx, msg->member);
        duk_put_prop_string(ctx, objIndex, "member");
        duk_push_string(ctx, msg->iface);
        duk_put_prop_string(ctx, objIndex, "iface");
        duk_push_string(ctx, msg->objPath);
        duk_put_prop_string(ctx, objIndex, "path");
        /* If sender == unique name then true, otherwise false */
        duk_push_boolean(ctx, !abs(strcmp(msg->sender, AJS_GetBusAttachment()->uniqueName)));
        duk_put_prop_string(ctx, objIndex, "fromSelf");

        if (msg->hdr->msgType == AJ_MSG_METHOD_CALL) {
            AJS_ReplyInternal* msgReply;
            /*
             * Private read-only information needed for composing the reply
             */
            duk_push_string(ctx, AJS_HIDDEN_PROP("reply"));
            msgReply = duk_push_fixed_buffer(ctx, sizeof(AJS_ReplyInternal));
            msgReply->msgId = msg->msgId;
            msgReply->flags = msg->hdr->flags;
            msgReply->serialNum = msg->hdr->serialNum;
            msgReply->sessionId = msg->sessionId;
            msgReply->accessor = accessor;
            duk_def_prop(ctx, objIndex, DUK_DEFPROP_HAVE_VALUE | DUK_DEFPROP_HAVE_WRITABLE);
            /*
             * Register the reply functions
             */
            duk_push_c_lightfunc(ctx, AJS_MethodCallReply, DUK_VARARGS, 0, 0);
            duk_put_prop_string(ctx, objIndex, "reply");
            duk_push_c_lightfunc(ctx, AJS_MethodCallError, DUK_VARARGS, 0, 0);
            duk_put_prop_string(ctx, objIndex, "errorReply");
        }
    } else {
        int isError = (msg->hdr->msgType == AJ_MSG_ERROR);

        AJ_InfoPrintf(("Reply serial %d\n", msg->replySerial));
        duk_push_int(ctx, msg->replySerial);
        duk_put_prop_string(ctx, objIndex, "replySerial");
        if (isError) {
            duk_push_string(ctx, msg->error);
            duk_put_prop_string(ctx, objIndex, "error");
        }
        duk_push_boolean(ctx, isError);
        duk_put_prop_string(ctx, objIndex, "isErrorReply");
    }
    return objIndex;
}
Exemplo n.º 5
0
void test(duk_context *ctx) {
	duk_idx_t i, n;

	duk_push_undefined(ctx);
	duk_push_null(ctx);
	duk_push_boolean(ctx, 0);
	duk_push_boolean(ctx, 123);
	duk_push_number(ctx, 234);
	duk_push_string(ctx, "foo");
	duk_push_object(ctx);
	duk_push_array(ctx);
	duk_push_c_function(ctx, my_c_func, DUK_VARARGS);
	duk_push_fixed_buffer(ctx, 1024);
	duk_push_dynamic_buffer(ctx, 1024);
	duk_push_pointer(ctx, (void *) 0xdeadbeefUL);

	n = duk_get_top(ctx);
	for (i = 0; i < n + 1; i++) {  /* end on invalid index on purpose */
		duk_int_t typeval, typemask;

		typeval = duk_get_type(ctx, i);
		typemask = duk_get_type_mask(ctx, i);

		printf("stack[%ld] --> type=%ld mask=0x%08lx ",
		       (long) i, (long) typeval, (long) typemask);

		switch(duk_get_type(ctx, i)) {
		case DUK_TYPE_NONE:       printf("none"); break;
		case DUK_TYPE_UNDEFINED:  printf("undefined"); break;
		case DUK_TYPE_NULL:       printf("null"); break;
		case DUK_TYPE_BOOLEAN:    printf("boolean"); break;
		case DUK_TYPE_NUMBER:     printf("number"); break;
		case DUK_TYPE_STRING:     printf("string"); break;
		case DUK_TYPE_OBJECT:     printf("object"); break;
		case DUK_TYPE_BUFFER:     printf("buffer"); break;
		case DUK_TYPE_POINTER:    printf("pointer"); break;
		default:                  printf("unknown(%d)", (int) duk_get_type(ctx, i)); break;
		}

		printf(" bool=%d num=%lf str=%s buf-is-null=%d ptr=%p",
		       (int) duk_get_boolean(ctx, i),
		       (double) duk_get_number(ctx, i),
		       duk_get_string(ctx, i),
		       (duk_get_buffer(ctx, i, NULL) == NULL ? 1 : 0),
		       duk_get_pointer(ctx, i));

		printf(" isobj=%d isarr=%d isfunc=%d",
		       (int) duk_is_object(ctx, i),
		       (int) duk_is_array(ctx, i),
		       (int) duk_is_function(ctx, i));

		printf("\n");
	}
}
DUK_INTERNAL void duk_regexp_create_instance(duk_hthread *thr) {
    duk_context *ctx = (duk_context *) thr;
    duk_hobject *h;
    duk_hstring *h_bc;
    duk_small_int_t re_flags;

    /* [ ... escape_source bytecode ] */

    h_bc = duk_get_hstring(ctx, -1);
    DUK_ASSERT(h_bc != NULL);
    DUK_ASSERT(DUK_HSTRING_GET_BYTELEN(h_bc) >= 1);          /* always at least the header */
    DUK_ASSERT(DUK_HSTRING_GET_CHARLEN(h_bc) >= 1);
    DUK_ASSERT((duk_small_int_t) DUK_HSTRING_GET_DATA(h_bc)[0] < 0x80);  /* flags always encodes to 1 byte */
    re_flags = (duk_small_int_t) DUK_HSTRING_GET_DATA(h_bc)[0];

    /* [ ... escaped_source bytecode ] */

    duk_push_object(ctx);
    h = duk_get_hobject(ctx, -1);
    DUK_ASSERT(h != NULL);
    duk_insert(ctx, -3);

    /* [ ... regexp_object escaped_source bytecode ] */

    DUK_HOBJECT_SET_CLASS_NUMBER(h, DUK_HOBJECT_CLASS_REGEXP);
    DUK_HOBJECT_SET_PROTOTYPE_UPDREF(thr, h, thr->builtins[DUK_BIDX_REGEXP_PROTOTYPE]);

    duk_xdef_prop_stridx(ctx, -3, DUK_STRIDX_INT_BYTECODE, DUK_PROPDESC_FLAGS_NONE);

    /* [ ... regexp_object escaped_source ] */

    duk_xdef_prop_stridx(ctx, -2, DUK_STRIDX_SOURCE, DUK_PROPDESC_FLAGS_NONE);

    /* [ ... regexp_object ] */

    duk_push_boolean(ctx, (re_flags & DUK_RE_FLAG_GLOBAL));
    duk_xdef_prop_stridx(ctx, -2, DUK_STRIDX_GLOBAL, DUK_PROPDESC_FLAGS_NONE);

    duk_push_boolean(ctx, (re_flags & DUK_RE_FLAG_IGNORE_CASE));
    duk_xdef_prop_stridx(ctx, -2, DUK_STRIDX_IGNORE_CASE, DUK_PROPDESC_FLAGS_NONE);

    duk_push_boolean(ctx, (re_flags & DUK_RE_FLAG_MULTILINE));
    duk_xdef_prop_stridx(ctx, -2, DUK_STRIDX_MULTILINE, DUK_PROPDESC_FLAGS_NONE);

    duk_push_int(ctx, 0);
    duk_xdef_prop_stridx(ctx, -2, DUK_STRIDX_LAST_INDEX, DUK_PROPDESC_FLAGS_W);

    /* [ ... regexp_object ] */
}
static duk_ret_t IAssetStorage_Trusted(duk_context* ctx)
{
    IAssetStorage* thisObj = GetThisWeakObject<IAssetStorage>(ctx);
    bool ret = thisObj->Trusted();
    duk_push_boolean(ctx, ret);
    return 1;
}
Exemplo n.º 8
0
DUK_LOCAL duk_ret_t duk__finalize_helper(duk_context *ctx, void *udata) {
	duk_hthread *thr;

	DUK_ASSERT(ctx != NULL);
	thr = (duk_hthread *) ctx;
	DUK_UNREF(udata);

	DUK_DDD(DUK_DDDPRINT("protected finalization helper running"));

	/* [... obj] */

	/* XXX: Finalizer lookup should traverse the prototype chain (to allow
	 * inherited finalizers) but should not invoke accessors or proxy object
	 * behavior.  At the moment this lookup will invoke proxy behavior, so
	 * caller must ensure that this function is not called if the target is
	 * a Proxy.
	 */

	duk_get_prop_stridx_short(ctx, -1, DUK_STRIDX_INT_FINALIZER);  /* -> [... obj finalizer] */
	if (!duk_is_callable(ctx, -1)) {
		DUK_DDD(DUK_DDDPRINT("-> no finalizer or finalizer not callable"));
		return 0;
	}
	duk_dup_m2(ctx);
	duk_push_boolean(ctx, DUK_HEAP_HAS_FINALIZER_NORESCUE(thr->heap));
	DUK_DDD(DUK_DDDPRINT("-> finalizer found, calling finalizer"));
	duk_call(ctx, 2);  /* [ ... obj finalizer obj heapDestruct ]  -> [ ... obj retval ] */
	DUK_DDD(DUK_DDDPRINT("finalizer finished successfully"));
	return 0;

	/* Note: we rely on duk_safe_call() to fix up the stack for the caller,
	 * so we don't need to pop stuff here.  There is no return value;
	 * caller determines rescued status based on object refcount.
	 */
}
Exemplo n.º 9
0
// Constructor of the JS Object
duk_ret_t js_myPlugin_ctor(duk_context *ctx)
{
    slog(DEBUG,DEBUG, "Creating new object of "PLUGIN_SCOPE);

    myPluginStructure *mps = malloc(sizeof(myPluginStructure));
    mps->name = duk_require_string(ctx, 0);
    
    // Push special this binding to the function being constructed
    duk_push_this(ctx);

    // Store the underlying object
    duk_push_pointer(ctx, mps);
    duk_put_prop_string(ctx, -2, "\xff""\xff""data");

    // TODO : - if not existand create a hash_map
    //        - store structure to a hash_map('name');
    //          so that it can be reached from JS and C
    
    // Store a boolean flag to mark the object as deleted because the destructor may be called several times
    duk_push_boolean(ctx, false);
    duk_put_prop_string(ctx, -2, "\xff""\xff""deleted");

    // Store the function destructor
    duk_push_c_function(ctx, js_myPlugin_dtor, 1);
    duk_set_finalizer(ctx, -2);

    return 0;
}
Exemplo n.º 10
0
static duk_ret_t Avatar_IsTemporary(duk_context* ctx)
{
    Avatar* thisObj = GetThisWeakObject<Avatar>(ctx);
    bool ret = thisObj->IsTemporary();
    duk_push_boolean(ctx, ret);
    return 1;
}
Exemplo n.º 11
0
DUK_INTERNAL duk_ret_t duk_bi_array_constructor_is_array(duk_context *ctx) {
	duk_hobject *h;

	h = duk_get_hobject_with_class(ctx, 0, DUK_HOBJECT_CLASS_ARRAY);
	duk_push_boolean(ctx, (h != NULL));
	return 1;
}
Exemplo n.º 12
0
static duk_ret_t Terrain_AllPatchesLoaded(duk_context* ctx)
{
    Terrain* thisObj = GetThisWeakObject<Terrain>(ctx);
    bool ret = thisObj->AllPatchesLoaded();
    duk_push_boolean(ctx, ret);
    return 1;
}
static duk_ret_t IAssetStorage_HasLiveUpdate(duk_context* ctx)
{
    IAssetStorage* thisObj = GetThisWeakObject<IAssetStorage>(ctx);
    bool ret = thisObj->HasLiveUpdate();
    duk_push_boolean(ctx, ret);
    return 1;
}
Exemplo n.º 14
0
static duk_ret_t dukky_html_table_cell_element_noWrap_getter(duk_context *ctx)
{
	/* Get private data for method */
	html_table_cell_element_private_t *priv = NULL;
	duk_push_this(ctx);
	duk_get_prop_string(ctx, -1, dukky_magic_string_private);
	priv = duk_get_pointer(ctx, -1);
	duk_pop_2(ctx);
	if (priv == NULL) {
		return 0; /* can do? No can do. */
	}

#line 31 "HTMLTableCellElement.bnd"
	dom_exception exc;
	bool b;

	exc = dom_html_table_cell_element_get_no_wrap((struct dom_html_table_cell_element *)((node_private_t*)priv)->node, &b);
	if (exc != DOM_NO_ERR) {
		return 0;
	}

	duk_push_boolean(ctx, b);

	return 1;
}
static duk_ret_t PhysicsWorld_IsDebugGeometryEnabled(duk_context* ctx)
{
    PhysicsWorld* thisObj = GetThisWeakObject<PhysicsWorld>(ctx);
    bool ret = thisObj->IsDebugGeometryEnabled();
    duk_push_boolean(ctx, ret);
    return 1;
}
static duk_ret_t IAssetTransfer_CachingAllowed(duk_context* ctx)
{
    IAssetTransfer* thisObj = GetThisWeakObject<IAssetTransfer>(ctx);
    bool ret = thisObj->CachingAllowed();
    duk_push_boolean(ctx, ret);
    return 1;
}
static duk_ret_t IAssetTransfer_Abort(duk_context* ctx)
{
    IAssetTransfer* thisObj = GetThisWeakObject<IAssetTransfer>(ctx);
    bool ret = thisObj->Abort();
    duk_push_boolean(ctx, ret);
    return 1;
}
Exemplo n.º 18
0
static duk_ret_t Avatar_ViewEnabled(duk_context* ctx)
{
    Avatar* thisObj = GetThisWeakObject<Avatar>(ctx);
    bool ret = thisObj->ViewEnabled();
    duk_push_boolean(ctx, ret);
    return 1;
}
Exemplo n.º 19
0
static duk_ret_t Line_IsFinite(duk_context* ctx)
{
    Line* thisObj = GetThisValueObject<Line>(ctx, Line_ID);
    bool ret = thisObj->IsFinite();
    duk_push_boolean(ctx, ret);
    return 1;
}
Exemplo n.º 20
0
static duk_ret_t Terrain_IsTemporary(duk_context* ctx)
{
    Terrain* thisObj = GetThisWeakObject<Terrain>(ctx);
    bool ret = thisObj->IsTemporary();
    duk_push_boolean(ctx, ret);
    return 1;
}
static duk_ret_t IAssetStorage_AutoDiscoverable(duk_context* ctx)
{
    IAssetStorage* thisObj = GetThisWeakObject<IAssetStorage>(ctx);
    bool ret = thisObj->AutoDiscoverable();
    duk_push_boolean(ctx, ret);
    return 1;
}
Exemplo n.º 22
0
static duk_ret_t IAsset_LoadFromCache(duk_context* ctx)
{
    IAsset* thisObj = GetThisWeakObject<IAsset>(ctx);
    bool ret = thisObj->LoadFromCache();
    duk_push_boolean(ctx, ret);
    return 1;
}
static duk_ret_t PhysicsWorld_IsClient(duk_context* ctx)
{
    PhysicsWorld* thisObj = GetThisWeakObject<PhysicsWorld>(ctx);
    bool ret = thisObj->IsClient();
    duk_push_boolean(ctx, ret);
    return 1;
}
Exemplo n.º 24
0
static duk_ret_t Avatar_SupportsDynamicAttributes(duk_context* ctx)
{
    Avatar* thisObj = GetThisWeakObject<Avatar>(ctx);
    bool ret = thisObj->SupportsDynamicAttributes();
    duk_push_boolean(ctx, ret);
    return 1;
}
Exemplo n.º 25
0
static duk_ret_t Terrain_SupportsDynamicAttributes(duk_context* ctx)
{
    Terrain* thisObj = GetThisWeakObject<Terrain>(ctx);
    bool ret = thisObj->SupportsDynamicAttributes();
    duk_push_boolean(ctx, ret);
    return 1;
}
 void OnSignal(Entity * param0, Entity * param1, const float3 & param2, const float3 & param3, float param4, float param5, bool param6)
 {
     duk_context* ctx = ctx_;
     duk_push_global_object(ctx);
     duk_get_prop_string(ctx, -1, "_OnSignal");
     duk_remove(ctx, -2);
     duk_push_number(ctx, (size_t)key_);
     duk_push_array(ctx);
     PushWeakObject(ctx, param0);
     duk_put_prop_index(ctx, -2, 0);
     PushWeakObject(ctx, param1);
     duk_put_prop_index(ctx, -2, 1);
     PushValueObjectCopy<float3>(ctx, param2, float3_ID, float3_Finalizer);
     duk_put_prop_index(ctx, -2, 2);
     PushValueObjectCopy<float3>(ctx, param3, float3_ID, float3_Finalizer);
     duk_put_prop_index(ctx, -2, 3);
     duk_push_number(ctx, param4);
     duk_put_prop_index(ctx, -2, 4);
     duk_push_number(ctx, param5);
     duk_put_prop_index(ctx, -2, 5);
     duk_push_boolean(ctx, param6);
     duk_put_prop_index(ctx, -2, 6);
     bool success = duk_pcall(ctx, 2) == 0;
     if (!success) LogError("[JavaScript] OnSignal: " + GetErrorString(ctx));
     duk_pop(ctx);
 }
Exemplo n.º 27
0
static duk_ret_t Terrain_ViewEnabled(duk_context* ctx)
{
    Terrain* thisObj = GetThisWeakObject<Terrain>(ctx);
    bool ret = thisObj->ViewEnabled();
    duk_push_boolean(ctx, ret);
    return 1;
}
static duk_ret_t AssetReferenceList_IsEmpty(duk_context* ctx)
{
    AssetReferenceList* thisObj = GetThisValueObject<AssetReferenceList>(ctx, AssetReferenceList_ID);
    bool ret = thisObj->IsEmpty();
    duk_push_boolean(ctx, ret);
    return 1;
}
Exemplo n.º 29
0
static duk_ret_t IAsset_IsModified(duk_context* ctx)
{
    IAsset* thisObj = GetThisWeakObject<IAsset>(ctx);
    bool ret = thisObj->IsModified();
    duk_push_boolean(ctx, ret);
    return 1;
}
static duk_ret_t EntityReference_IsEmpty(duk_context* ctx)
{
    EntityReference* thisObj = GetThisValueObject<EntityReference>(ctx, EntityReference_ID);
    bool ret = thisObj->IsEmpty();
    duk_push_boolean(ctx, ret);
    return 1;
}