本文整理汇总了C++中duk_require_string函数的典型用法代码示例。如果您正苦于以下问题:C++ duk_require_string函数的具体用法?C++ duk_require_string怎么用?C++ duk_require_string使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了duk_require_string函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: AssetDatabase_GetAssetsByImporterType
static int AssetDatabase_GetAssetsByImporterType(duk_context* ctx)
{
JSVM* vm = JSVM::GetJSVM(ctx);
ToolSystem* ts = vm->GetSubsystem<ToolSystem>();
AssetDatabase* db = vm->GetSubsystem<AssetDatabase>();
Project* project = ts->GetProject();
StringHash type = duk_require_string(ctx, 0);
String resourceType = duk_require_string(ctx, 1);
duk_push_array(ctx);
if (!project)
return 1;
PODVector<Asset*> assets;
db->GetAssetsByImporterType(type, resourceType, assets);
for(unsigned i = 0; i < assets.Size(); i++)
{
js_push_class_object_instance(ctx, assets[i], 0);
duk_put_prop_index(ctx, -2, i);
}
return 1;
}
示例2: cb_load_module
static duk_ret_t cb_load_module(duk_context *ctx) {
const char *filename;
const char *module_id;
module_id = duk_require_string(ctx, 0);
duk_get_prop_string(ctx, 2, "filename");
filename = duk_require_string(ctx, -1);
printf("load_cb: id:'%s', filename:'%s'\n", module_id, filename);
if (strcmp(module_id, "pig.js") == 0) {
duk_push_sprintf(ctx, "module.exports = 'you\\'re about to get eaten by %s';",
module_id);
} else if (strcmp(module_id, "cow.js") == 0) {
duk_push_string(ctx, "module.exports = require('pig');");
} else if (strcmp(module_id, "ape.js") == 0) {
duk_push_string(ctx, "module.exports = { module: module, __filename: __filename, wasLoaded: module.loaded };");
} else if (strcmp(module_id, "badger.js") == 0) {
duk_push_string(ctx, "exports.foo = 123; exports.bar = 234;");
} else if (strcmp(module_id, "comment.js") == 0) {
duk_push_string(ctx, "exports.foo = 123; exports.bar = 234; // comment");
} else if (strcmp(module_id, "shebang.js") == 0) {
duk_push_string(ctx, "#!ignored\nexports.foo = 123; exports.bar = 234;");
} else {
duk_error(ctx, DUK_ERR_TYPE_ERROR, "cannot find module: %s", module_id);
}
return 1;
}
示例3: test_1
static duk_ret_t test_1(duk_context *ctx) {
duk_set_top(ctx, 0);
duk_push_string(ctx, "foo");
duk_push_string(ctx, "");
dump_string(duk_require_string(ctx, 0));
dump_string(duk_require_string(ctx, 1));
return 0;
}
示例4: test_1
int test_1(duk_context *ctx) {
duk_set_top(ctx, 0);
duk_push_string(ctx, "foo");
duk_push_string(ctx, "");
printf("string: %s\n", duk_require_string(ctx, 0));
printf("string: %s\n", duk_require_string(ctx, 1));
return 0;
}
示例5: Serializer_Write
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;
}
示例6: SignalWrapper_Terrain_ComponentNameChanged_Emit
static duk_ret_t SignalWrapper_Terrain_ComponentNameChanged_Emit(duk_context* ctx)
{
SignalWrapper_Terrain_ComponentNameChanged* wrapper = GetThisValueObject<SignalWrapper_Terrain_ComponentNameChanged>(ctx, SignalWrapper_Terrain_ComponentNameChanged_ID);
if (!wrapper->owner_) return 0;
String param0 = duk_require_string(ctx, 0);
String param1 = duk_require_string(ctx, 1);
wrapper->signal_->Emit(param0, param1);
return 0;
}
示例7: IAsset_SaveToFile_String_String
static duk_ret_t IAsset_SaveToFile_String_String(duk_context* ctx)
{
int numArgs = duk_get_top(ctx);
IAsset* thisObj = GetThisWeakObject<IAsset>(ctx);
String filename = duk_require_string(ctx, 0);
String serializationParameters = numArgs > 1 ? duk_require_string(ctx, 1) : "";
bool ret = thisObj->SaveToFile(filename, serializationParameters);
duk_push_boolean(ctx, ret);
return 1;
}
示例8: SignalWrapper_IAssetStorage_AssetChanged_Emit
static duk_ret_t SignalWrapper_IAssetStorage_AssetChanged_Emit(duk_context* ctx)
{
SignalWrapper_IAssetStorage_AssetChanged* wrapper = GetThisValueObject<SignalWrapper_IAssetStorage_AssetChanged>(ctx, SignalWrapper_IAssetStorage_AssetChanged_ID);
if (!wrapper->owner_) return 0;
IAssetStorage* param0 = GetWeakObject<IAssetStorage>(ctx, 0);
String param1 = duk_require_string(ctx, 1);
String param2 = duk_require_string(ctx, 2);
IAssetStorage::ChangeType param3 = (IAssetStorage::ChangeType)(int)duk_require_number(ctx, 3);
wrapper->signal_->Emit(param0, param1, param2, param3);
return 0;
}
示例9: FindInterfaceForMember
/*
* Looks for an interface that defines a specific member.
*
* TODO - check for ambiguity - same member defined on multiple interfaces
*/
static const char* FindInterfaceForMember(duk_context* ctx, duk_idx_t mbrIdx, const char** member)
{
const char* iface = NULL;
uint8_t found = FALSE;
size_t numInterfaces;
duk_idx_t listIdx;
duk_get_prop_string(ctx, -1, "interfaces");
numInterfaces = duk_get_length(ctx, -1);
listIdx = AJS_GetAllJoynProperty(ctx, "interfaceDefinition");
if (duk_is_object(ctx, mbrIdx)) {
/*
* Expect an object of form { member:"org.foo.interface" }
*/
duk_enum(ctx, mbrIdx, DUK_ENUM_OWN_PROPERTIES_ONLY);
if (!duk_next(ctx, -1, 1)) {
duk_error(ctx, DUK_ERR_TYPE_ERROR, "Require object of form { 'member-name':'interface-name' }");
}
iface = duk_require_string(ctx, -1);
if (!AJ_StringFindFirstOf(iface, ".") == -1) {
duk_error(ctx, DUK_ERR_TYPE_ERROR, "Interface name '%s' is not a dotted name", iface);
}
*member = duk_require_string(ctx, -2);
duk_get_prop_string(ctx, listIdx, iface);
if (duk_is_undefined(ctx, -1)) {
duk_error(ctx, DUK_ERR_REFERENCE_ERROR, "Unknown interface: '%s'", iface);
}
found = duk_has_prop_string(ctx, -1, *member);
duk_pop_n(ctx, 4);
} else {
size_t i;
/*
* Expect a string
*/
*member = duk_require_string(ctx, mbrIdx);
for (i = 0; !found && (i < numInterfaces); ++i) {
duk_get_prop_index(ctx, -2, i);
iface = duk_require_string(ctx, -1);
duk_get_prop_string(ctx, listIdx, iface);
/*
* See if the requested member exists on this interface
*/
found = duk_has_prop_string(ctx, -1, *member);
duk_pop_2(ctx);
}
}
duk_pop_2(ctx);
if (!found) {
duk_error(ctx, DUK_ERR_REFERENCE_ERROR, "Unknown member: '%s'", *member);
}
return iface;
}
示例10: cb_resolve_module
static duk_ret_t cb_resolve_module(duk_context *ctx) {
const char *module_id;
const char *parent_id;
module_id = duk_require_string(ctx, 0);
parent_id = duk_require_string(ctx, 1);
duk_push_sprintf(ctx, "%s.js", module_id);
printf("resolve_cb: id:'%s', parent-id:'%s', resolve-to:'%s'\n",
module_id, parent_id, duk_get_string(ctx, -1));
return 1;
}
示例11: dukzip_zip_newfile
static duk_ret_t dukzip_zip_newfile(duk_context *ctx) {
zip_fileinfo zi = {0};
int res = ZIP_OK;
zipFile archive = dukzip_zip_from_this(ctx);
const char *filename = "";
duk_int_t level = Z_DEFAULT_COMPRESSION;
duk_int_t method = Z_DEFLATED;
const char *comment = "";
if (duk_is_object(ctx, 0)) {
dukzip_zip_checkoptions(ctx, 0, &filename, &level, &method, &comment);
} else {
filename = duk_require_string(ctx, 0);
if (duk_is_number(ctx, 1)) {
level = duk_get_int(ctx, 1);
}
}
res = zipOpenNewFileInZip64(archive, filename, &zi, NULL, 0, NULL, 0, comment, method, level, 1);
if (res == ZIP_OK) {
duk_push_true(ctx);
} else {
duk_push_false(ctx);
}
return 1;
}
示例12: _gum_duk_parse_protection
gboolean
_gum_duk_parse_protection (duk_context * ctx,
duk_idx_t index,
GumPageProtection * prot)
{
const gchar * prot_str, * ch;
if (!duk_is_string (ctx, index))
return FALSE;
prot_str = duk_require_string (ctx, index);
*prot = GUM_PAGE_NO_ACCESS;
for (ch = prot_str; *ch != '\0'; ch++)
{
switch (*ch)
{
case 'r':
*prot |= GUM_PAGE_READ;
break;
case 'w':
*prot |= GUM_PAGE_WRITE;
break;
case 'x':
*prot |= GUM_PAGE_EXECUTE;
break;
case '-':
break;
default:
return FALSE;
}
}
return TRUE;
}
示例13: _gum_duk_parse_uint64
gboolean
_gum_duk_parse_uint64 (duk_context * ctx,
duk_idx_t index,
GumDukCore * core,
guint64 * u)
{
if (duk_is_string (ctx, index))
{
const gchar * value_as_string, * end;
gboolean valid;
value_as_string = duk_require_string (ctx, index);
if (g_str_has_prefix (value_as_string, "0x"))
{
*u = g_ascii_strtoull (value_as_string + 2, (gchar **) &end, 16);
valid = end != value_as_string + 2;
}
else
{
*u = g_ascii_strtoull (value_as_string, (gchar **) &end, 10);
valid = end != value_as_string;
}
return valid;
}
return _gum_duk_get_uint64 (ctx, index, core, u);
}
示例14: duv_loadfile
// Sync readfile using libuv APIs as an API function.
static duk_ret_t duv_loadfile(duk_context *ctx) {
const char* path = duk_require_string(ctx, 0);
uv_fs_t req;
int fd = 0;
uint64_t size;
char* chunk;
uv_buf_t buf;
if (uv_fs_open(&loop, &req, path, O_RDONLY, 0644, NULL) < 0) goto fail;
fd = req.result;
if (uv_fs_fstat(&loop, &req, fd, NULL) < 0) goto fail;
size = req.statbuf.st_size;
chunk = duk_alloc(ctx, size);
buf = uv_buf_init(chunk, size);
if (uv_fs_read(&loop, &req, fd, &buf, 1, 0, NULL) < 0) goto fail;
duk_push_lstring(ctx, chunk, size);
duk_free(ctx, chunk);
uv_fs_close(&loop, &req, fd, NULL);
uv_fs_req_cleanup(&req);
return 1;
fail:
if (fd) uv_fs_close(&loop, &req, fd, NULL);
uv_fs_req_cleanup(&req);
duk_error(ctx, DUK_ERR_ERROR, "%s: %s: %s", uv_err_name(req.result), uv_strerror(req.result), path);
}
示例15: Line_FromString_Static_string
static duk_ret_t Line_FromString_Static_string(duk_context* ctx)
{
string str = duk_require_string(ctx, 0);
Line ret = Line::FromString(str);
PushValueObjectCopy<Line>(ctx, ret, Line_ID, Line_Finalizer);
return 1;
}