Ejemplo n.º 1
0
static void pushBuffer(const ut8 *buf, int len) {
	int i;
	duk_push_fixed_buffer (ctx, len);
	for (i=0; i<len; i++) {
		duk_push_number (ctx, buf[i]);
		duk_put_prop_index (ctx, -2, i);
	}
	// buffer is in stack[-1]
}
Ejemplo n.º 2
0
static duk_ret_t Line_Distance_float3_float(duk_context* ctx)
{
    Line* thisObj = GetThisValueObject<Line>(ctx, Line_ID);
    float3& point = *GetCheckedValueObject<float3>(ctx, 0, float3_ID);
    float d = (float)duk_require_number(ctx, 1);
    float ret = thisObj->Distance(point, d);
    duk_push_number(ctx, ret);
    return 1;
}
Ejemplo n.º 3
0
    void Push( duk_context * ctx, const float value, const float * )
    {
        dukbind_assert(
            ( (float)(duk_double_t) value ) == value,
            "Value does not fit into a duk_double_t"
            );

         duk_push_number( ctx, (duk_double_t)value );
    }
Ejemplo n.º 4
0
Archivo: sys1.c Proyecto: jelaas/sysjs
static int sys1_close(duk_context *ctx)
{
	int fd = duk_to_int(ctx, 0);
	
	int rc  = close(fd);
	
	duk_push_number(ctx, rc);
	return 1;
}
Ejemplo n.º 5
0
static duk_ret_t Line_Distance_LineSegment_float(duk_context* ctx)
{
    Line* thisObj = GetThisValueObject<Line>(ctx, Line_ID);
    LineSegment& other = *GetCheckedValueObject<LineSegment>(ctx, 0, LineSegment_ID);
    float d = (float)duk_require_number(ctx, 1);
    float ret = thisObj->Distance(other, d);
    duk_push_number(ctx, ret);
    return 1;
}
Ejemplo n.º 6
0
static duk_ret_t Terrain_GetPoint_uint_uint(duk_context* ctx)
{
    Terrain* thisObj = GetThisWeakObject<Terrain>(ctx);
    uint x = (uint)duk_require_number(ctx, 0);
    uint y = (uint)duk_require_number(ctx, 1);
    float ret = thisObj->GetPoint(x, y);
    duk_push_number(ctx, ret);
    return 1;
}
Ejemplo n.º 7
0
static void
push_htsmsg_field(duk_context *ctx, const htsmsg_field_t *f)
{
  switch(f->hmf_type) {
  case HMF_STR:
    duk_push_string(ctx, f->hmf_str);
    break;
  case HMF_S64:
    duk_push_number(ctx, f->hmf_s64);
    break;
  case HMF_DBL:
    duk_push_number(ctx, f->hmf_dbl);
    break;
  default:
    duk_push_undefined(ctx);
    break;
  }
}
Ejemplo n.º 8
0
static int Deserializer_Read(duk_context* ctx)
{
    duk_int_t magic = duk_get_current_magic(ctx);

    duk_push_this(ctx);

    // safe cast based on type check above
    Deserializer* deserial = CastToDeserializer(ctx, duk_get_top_index(ctx));

    duk_pop(ctx);

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

    char* data;
    String str;
    size_t length;

    IO_MAGIC_TYPE v = (IO_MAGIC_TYPE) magic;

    bool success = false;

    switch(v)
    {
        case IO_MAGIC_INT:
            duk_push_number(ctx, (double) deserial->ReadInt());
            return 1;
        case IO_MAGIC_STRING:
            length = deserial->GetSize() - deserial->GetPosition();
            str.Resize(length + 1);
            deserial->Read(&str[0], length);
            str[length] = '\0';
            duk_push_string(ctx, str.CString());
            return 1;
        case IO_MAGIC_ZEROSTRING:
            success = duk_push_string(ctx, deserial->ReadString().CString());
            return 1;
        case IO_MAGIC_BINARY:
            length = deserial->GetSize() - deserial->GetPosition();
            duk_push_fixed_buffer(ctx, length);
            duk_push_buffer_object(ctx, -1, 0, length, DUK_BUFOBJ_UINT8ARRAY);
            duk_replace(ctx, -2);
            data = (char*) duk_require_buffer_data(ctx, 0, &length);
            success = deserial->Read(data, length);
            return 1;
        default:
            break;
    }

    duk_push_undefined(ctx);

    return 1;

}
Ejemplo n.º 9
0
int duk_builtin_math_object_twoarg_shared(duk_context *ctx) {
	int fun_idx = duk_get_magic(ctx);
	two_arg_func fun;

	DUK_ASSERT(fun_idx >= 0 && fun_idx < sizeof(two_arg_funcs) / sizeof(two_arg_func));
	fun = two_arg_funcs[fun_idx];
	duk_push_number(ctx, fun(duk_to_number(ctx, 0), duk_to_number(ctx, 1)));
	return 1;
}
Ejemplo n.º 10
0
static int
es_sqlite_step(duk_context *ctx)
{
    es_sqlite_t *es = es_resource_get(ctx, 0, &es_resource_sqlite);

    if(es->es_stmt == NULL) {
        duk_push_null(ctx);
        return 1;
    }

    const int cols = sqlite3_data_count(es->es_stmt);

    duk_push_object(ctx);

    for(int i = 0; i < cols; i++) {

        int64_t i64;

        switch(sqlite3_column_type(es->es_stmt, i)) {

        case SQLITE_INTEGER:
            i64 = sqlite3_column_int64(es->es_stmt, i);
            if(i64 >= INT32_MIN && i64 <= INT32_MAX)
                duk_push_int(ctx, i64);
            else if(i64 >= 0 && i64 <= UINT32_MAX)
                duk_push_uint(ctx, i64);
            else
                duk_push_number(ctx, i64);
            break;
        case SQLITE_TEXT:
            duk_push_string(ctx, (const char *)sqlite3_column_text(es->es_stmt, i));
            break;
        case SQLITE_FLOAT:
            duk_push_number(ctx, sqlite3_column_double(es->es_stmt, i));
            break;
        default:
            continue;
        }
        duk_put_prop_string(ctx, -2, sqlite3_column_name(es->es_stmt, i));
    }
    es_sqlite_stmt_step(ctx, es);
    return 1;
}
Ejemplo n.º 11
0
void Expose_IAsset(duk_context* ctx)
{
    duk_push_object(ctx);
    duk_push_number(ctx, 0);
    duk_put_prop_string(ctx, -2, "Original");
    duk_push_number(ctx, 1);
    duk_put_prop_string(ctx, -2, "Cached");
    duk_push_number(ctx, 2);
    duk_put_prop_string(ctx, -2, "Programmatic");
    duk_push_number(ctx, 3);
    duk_put_prop_string(ctx, -2, "Bundle");
    duk_push_object(ctx);
    duk_put_function_list(ctx, -1, IAsset_Functions);
    DefineProperty(ctx, "Unloaded", IAsset_Get_Unloaded, nullptr);
    DefineProperty(ctx, "Loaded", IAsset_Get_Loaded, nullptr);
    DefineProperty(ctx, "PropertyStatusChanged", IAsset_Get_PropertyStatusChanged, nullptr);
    duk_put_prop_string(ctx, -2, "prototype");
    duk_put_global_string(ctx, IAsset_ID);
}
Ejemplo n.º 12
0
static duk_ret_t Line_Distance_Ray_float_float(duk_context* ctx)
{
    Line* thisObj = GetThisValueObject<Line>(ctx, Line_ID);
    Ray& other = *GetCheckedValueObject<Ray>(ctx, 0, Ray_ID);
    float d = (float)duk_require_number(ctx, 1);
    float d2 = (float)duk_require_number(ctx, 2);
    float ret = thisObj->Distance(other, d, d2);
    duk_push_number(ctx, ret);
    return 1;
}
Ejemplo n.º 13
0
int SnssFileAPI::readInt64(duk_context* ctx)
{
    long long value = 0;
    m_SnssFile.read(reinterpret_cast<char*>(&value), 8);
    if( m_SnssFile.eof() )
        return 0;

    duk_push_number(ctx, (duk_double_t)value);
    return 1;
}
Ejemplo n.º 14
0
int duk_builtin_date_prototype_value_of(duk_context *ctx) {
	/* This native function is also used for Date.prototype.getTime()
	 * as their behavior is identical.
	 */

	double d = push_this_and_get_timeval(ctx, 0 /*flags*/);  /* -> [ this ] */
	DUK_ASSERT(DUK_ISFINITE(d) || DUK_ISNAN(d));
	duk_push_number(ctx, d);
	return 1;
}
Ejemplo n.º 15
0
static duk_ret_t test_1(duk_context *ctx, void *udata) {
	duk_idx_t i, n;

	(void) udata;

	duk_set_top(ctx, 0);
	duk_push_undefined(ctx);
	duk_push_null(ctx);
	duk_push_true(ctx);
	duk_push_false(ctx);
	duk_push_int(ctx, 0);
	duk_push_int(ctx, 1);
	duk_push_nan(ctx);
	duk_push_number(ctx, INFINITY);
	duk_push_string(ctx, "");
	duk_push_string(ctx, "foo");
	duk_push_object(ctx);
	duk_push_number(ctx, 123.456);
	duk_to_object(ctx, -1);  /* Number(123.456) */
	duk_push_thread(ctx);
	duk_push_fixed_buffer(ctx, 0);
	duk_push_fixed_buffer(ctx, 1024);
	duk_push_dynamic_buffer(ctx, 0);
	duk_push_dynamic_buffer(ctx, 1024);
	duk_push_pointer(ctx, (void *) NULL);
	duk_push_pointer(ctx, (void *) 0xdeadbeef);

	n = duk_get_top(ctx);
	printf("top: %ld\n", (long) n);
	for (i = 0; i < n; i++) {
		duk_int_t t1, t2;

		t1 = duk_get_type(ctx, i);
		duk_to_primitive(ctx, i, DUK_HINT_NONE);
		t2 = duk_get_type(ctx, i);

		printf("index %ld, ToString(result): '%s', type: %ld -> %ld\n",
		       (long) i, duk_to_string(ctx, i), (long) t1, (long) t2);
	}

	return 0;
}
Ejemplo n.º 16
0
Archivo: sys1.c Proyecto: jelaas/sysjs
static int sys1_sleep(duk_context *ctx)
{
	int rc;

	int seconds = duk_to_int(ctx, 0);

	rc = sleep(seconds);
	
	duk_push_number(ctx, rc);
	return 1;
}
Ejemplo n.º 17
0
/**
 * fd
 */
static int
es_file_fsize(duk_context *ctx)
{
  es_fd_t *efd = es_fd_get(ctx, 0);

  int64_t siz = fa_fsize(efd->efd_fh);
  if(siz < 0)
    duk_error(ctx, DUK_ERR_ERROR, "File not seekable");
  duk_push_number(ctx, siz);
  return 1;
}
Ejemplo n.º 18
0
static duk_ret_t do_callback(duk_context *ctx)
{
  printf("%s %d\n", __PRETTY_FUNCTION__, __LINE__);

  duk_push_this(ctx);
  duk_push_number(ctx, 10);
  duk_put_prop_string(ctx, -2, "hello");
  duk_put_function_list(ctx, -1, test_testobj_callback_funcs);

  return 0;
}
Ejemplo n.º 19
0
int duk_builtin_date_prototype_set_time(duk_context *ctx) {
	double d;

	(void) push_this_and_get_timeval(ctx, 0 /*flags*/); /* -> [ timeval this ] */
	d = timeclip(duk_to_number(ctx, 0));
	duk_push_number(ctx, d);
	duk_dup_top(ctx);
	duk_put_prop_stridx(ctx, -3, DUK_STRIDX_INT_VALUE); /* -> [ timeval this timeval ] */

	return 1;
}
Ejemplo n.º 20
0
static duk_ret_t
js_Sound_getPitch(duk_context* ctx)
{
	sound_t* sound;

	duk_push_this(ctx);
	duk_get_prop_string(ctx, -1, "\xFF" "ptr"); sound = duk_get_pointer(ctx, -1); duk_pop(ctx);
	duk_pop(ctx);
	duk_push_number(ctx, get_sound_pitch(sound));
	return 1;
}
 void OnSignal(IAssetStorage * param0, String param1, String param2, IAssetStorage::ChangeType param3)
 {
     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);
     duk_push_string(ctx, param1.CString());
     duk_put_prop_index(ctx, -2, 1);
     duk_push_string(ctx, param2.CString());
     duk_put_prop_index(ctx, -2, 2);
     duk_push_number(ctx, param3);
     duk_put_prop_index(ctx, -2, 3);
     bool success = duk_pcall(ctx, 2) == 0;
     if (!success) LogError("[JavaScript] OnSignal: " + GetErrorString(ctx));
     duk_pop(ctx);
 }
Ejemplo n.º 22
0
duk_ret_t duk_bi_math_object_twoarg_shared(duk_context *ctx) {
	duk_small_int_t fun_idx = duk_get_magic(ctx);
	duk__two_arg_func fun;

	DUK_ASSERT(fun_idx >= 0);
	DUK_ASSERT(fun_idx < (duk_small_int_t) (sizeof(duk__two_arg_funcs) / sizeof(duk__two_arg_func)));
	fun = duk__two_arg_funcs[fun_idx];
	/* FIXME: double typing here: double or duk_double_t? */
	duk_push_number(ctx, fun((double) duk_to_number(ctx, 0), (double) duk_to_number(ctx, 1)));
	return 1;
}
Ejemplo n.º 23
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");
	}
}
Ejemplo n.º 24
0
DUK_INTERNAL duk_ret_t duk_bi_math_object_onearg_shared(duk_context *ctx) {
	duk_small_int_t fun_idx = duk_get_current_magic(ctx);
	duk__one_arg_func fun;
	duk_double_t arg1;

	DUK_ASSERT(fun_idx >= 0);
	DUK_ASSERT(fun_idx < (duk_small_int_t) (sizeof(duk__one_arg_funcs) / sizeof(duk__one_arg_func)));
	arg1 = duk_to_number(ctx, 0);
	fun = duk__one_arg_funcs[fun_idx];
	duk_push_number(ctx, (duk_double_t) fun((double) arg1));
	return 1;
}
Ejemplo n.º 25
0
static duk_ret_t test_1(duk_context *ctx) {
	double a, b, c;

	a = duk_get_number(ctx, -3);
	b = duk_get_number(ctx, -2);
	c = duk_get_number(ctx, -1);
	c = c;  /* silence warning */
	duk_push_number(ctx, a + b);

	/* just one return value */
	return 1;
}
Ejemplo n.º 26
0
 void OnSignal()
 {
     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);
     bool success = duk_pcall(ctx, 2) == 0;
     if (!success) LogError("[JavaScript] OnSignal: " + GetErrorString(ctx));
     duk_pop(ctx);
 }
Ejemplo n.º 27
0
Archivo: sys1.c Proyecto: jelaas/sysjs
static int sys1_dup2(duk_context *ctx)
{
	int rc;

	int oldfd = duk_to_int(ctx, 0);
	int newfd = duk_to_int(ctx, 1);

	rc = dup2(oldfd, newfd);
	
	duk_push_number(ctx, rc);
	return 1;	
}
Ejemplo n.º 28
0
static duk_ret_t native_adder(duk_context *ctx) {
	duk_idx_t i, n;
	double res = 0.0;

	n = duk_get_top(ctx);  /* number of args */
	for (i = 0; i < n; i++) {
		res += duk_to_number(ctx, i);
	}

	duk_push_number(ctx, res);
	return 1;
}
Ejemplo n.º 29
0
Archivo: sys1.c Proyecto: jelaas/sysjs
static int sys1_listen(duk_context *ctx)
{
	int rc;

	int fd = duk_to_int(ctx, 0);
	int backlog = duk_to_int(ctx, 1);

	rc = listen(fd, backlog);
	
	duk_push_number(ctx, rc);
	return 1;	
}
Ejemplo n.º 30
0
void CallConnectSignal(duk_context* ctx, void* signal)
{
    int numArgs = duk_get_top(ctx);
    duk_push_number(ctx, (size_t)signal);
    duk_insert(ctx, 0);
    duk_push_global_object(ctx);
    duk_get_prop_string(ctx, -1, "_ConnectSignal");
    duk_remove(ctx, -2); // Global object
    duk_insert(ctx, 0);
    duk_pcall(ctx, numArgs + 1);
    duk_pop(ctx);
}