static void improv_getcwd(caValue* cwd) { char buf[1024]; if (getcwd(buf, sizeof(buf)) != NULL) circa_set_string(cwd, buf); else circa_set_string(cwd, ""); }
void make_server(Stack* stack) { Value* ip = circa_input(stack, 0); Value* port = circa_input(stack, 1); Value* type = circa_input(stack, 2); Server* server = new Server(); if (circa_string_equals(type, ":tcp")) { server->serverType = TCP; } else if (circa_string_equals(type, ":websock")) { server->serverType = WEBSOCK; memset(&server->parser_settings, 0, sizeof(server->parser_settings)); server->parser_settings.on_message_begin = http_on_message_begin; server->parser_settings.on_url = http_on_url; server->parser_settings.on_status = http_on_status; server->parser_settings.on_header_field = http_on_header_field; server->parser_settings.on_header_value = http_on_header_value; server->parser_settings.on_headers_complete = http_on_headers_complete; server->parser_settings.on_body = http_on_body; server->parser_settings.on_message_complete = http_on_message_complete; } else { Value msg; circa_set_string(&msg, "Unrecognized server type: "); circa_string_append_val(&msg, type); circa_output_error_val(stack, &msg); delete server; return; } uv_loop_t* loop = get_uv_loop(stack->world); circa_set_list(&server->connections, 0); uv_tcp_init(stack->world->libuvWorld->uv_loop, &server->uv_tcp); struct sockaddr_in bind_addr = uv_ip4_addr(circa_string(ip), circa_int(port)); uv_tcp_bind(&server->uv_tcp, bind_addr); int err = uv_listen((uv_stream_t*) &server->uv_tcp, 128, server_on_connect); server->uv_tcp.data = server; if (err) { Value msg; circa_set_string(&msg, "Listen error: "); circa_string_append(&msg, uv_err_name(uv_last_error(loop))); circa_output_error_val(stack, &msg); return; } Value* out = circa_set_default_output(stack, 0); circa_set_native_ptr(circa_index(out, 0), server, ServerRelease); }
int run_command_line(caWorld* world, int argc, const char* args[]) { Value args_v; set_list(&args_v, 0); for (int i=1; i < argc; i++) circa_set_string(circa_append(&args_v), args[i]); return run_command_line(world, &args_v); }
static void http_write_upgrade_response(uv_stream_t* stream) { Value* msg = circa_alloc_value(); circa_set_string(msg, "HTTP/1.1 101 Switching Protocols\r\n" "Upgrade: websocket\r\n" "Connection: Upgrade\r\n" "Sec-WebSocket-Accept: "); circa_string_append(msg, "(responseKey)"); circa_string_append(msg, "\r\n\r\n"); circa_uv_write(stream, msg, false); }
void GLWidget::onInputEvent(caValue* event) { scripts_pre_message_send(); caValue* msg = circa_alloc_list(2); circa_set_string(circa_index(msg, 0), "onInputEvent"); circa_move(event, circa_index(msg, 1)); circa_dealloc_value(event); circa_actor_run_message(g_world, "View", msg); circa_dealloc_value(msg); scripts_post_message_send(); }
void GLWidget::paintEvent(QPaintEvent*) { QPainter painter; painter.begin(this); painter.setRenderHint(QPainter::Antialiasing); scripts_pre_message_send(); // call onPaintEvent caValue* msg = circa_alloc_list(2); circa_set_string(circa_index(msg, 0), "onPaintEvent"); circa_set_typed_pointer(circa_index(msg, 1), circa_find_type(NULL, "Painter"), &painter); circa_actor_run_message(g_world, "View", msg); circa_dealloc_value(msg); scripts_post_message_send(); painter.end(); }
extern "C" int main(int argc, char *argv[]) { if (argc <= 1) { printf("Missing script argument\n"); return 1; } caWorld* world = circa_initialize(); improv::fix_current_directory(); circa_use_local_filesystem(world, ""); circa_add_module_search_path(world, "ca"); improv::setup_native_patches(world); improv::setup_sdl_audio(); improv::ImprovWindow window; window.init(world); const char* arg = argv[1]; circa_set_string(circa_env_insert(window._stack, "scriptName"), arg); if (!improv::sdl_init()) return 1; const int width = 1000; const int height = 600; window.setSize(width, height); SDL_PauseAudio(0); window.mainLoop(); return 0; }
bool load_shaders(ResourceManager* resources, const char* baseFilename, Program* programStruct) { Log("Loading shader: %s", baseFilename); check_gl_error(); // Create shader program. GLuint program = glCreateProgram(); programStruct->program = program; // Load vertex shader. circa::Value vertShaderPathname; circa_set_string(&vertShaderPathname, baseFilename); circa_string_append(&vertShaderPathname, ".vsh"); circa::Value vertShader; resources->loadAsText(circa_string(&vertShaderPathname), &vertShader); if (circa_is_error(&vertShader) || !circa_is_string(&vertShader)) { Log("Failed to load vertex shader: %v", &vertShaderPathname); return false; } // Compile vertex shader circa::Value vertShaderIndex; compile_shader(GL_VERTEX_SHADER, &vertShader, &vertShaderIndex); if (circa_is_error(&vertShaderIndex)) { Log("Failed to compile vertex shader:", &vertShaderPathname); return false; } // Load fragment shader circa::Value fragShaderPathname; circa_set_string(&fragShaderPathname, baseFilename); circa_string_append(&fragShaderPathname, ".fsh"); circa::Value fragShader; resources->loadAsText(circa_string(&fragShaderPathname), &fragShader); if (circa_is_error(&fragShader) || !circa_is_string(&fragShader)) { Log("Failed to load fragment shader:", &fragShaderPathname); return false; } // Compile fragment shader circa::Value fragShaderIndex; compile_shader(GL_FRAGMENT_SHADER, &fragShader, &fragShaderIndex); check_gl_error(); if (circa_is_error(&fragShaderIndex)) { Log("Failed to compile frag shader: %v", &fragShaderPathname); return false; } int vertShaderHandle = circa_int(&vertShaderIndex); int fragShaderHandle = circa_int(&fragShaderIndex); // Attach vertex shader to program. glAttachShader(program, vertShaderHandle); check_gl_error(); // Attach fragment shader to program. glAttachShader(program, fragShaderHandle); check_gl_error(); // Link program. if (!link_program(program)) { Log("Failed to link shaders: %s", baseFilename); glDeleteShader(vertShaderHandle); glDeleteShader(fragShaderHandle); if (program) { glDeleteProgram(program); program = 0; } check_gl_error(); return false; } check_gl_error(); // Get attribute locations programStruct->attributes.vertex = glGetAttribLocation(program, "vertex"); programStruct->attributes.tex_coord = glGetAttribLocation(program, "tex_coord"); check_gl_error(); // Get uniform locations. programStruct->uniforms.modelViewProjectionMatrix = glGetUniformLocation(program, "modelViewProjectionMatrix"); programStruct->uniforms.normalMatrix = glGetUniformLocation(program, "normalMatrix"); programStruct->uniforms.sampler = glGetUniformLocation(program, "sampler"); programStruct->uniforms.sampler2 = glGetUniformLocation(program, "sampler2"); programStruct->uniforms.color = glGetUniformLocation(program, "color"); programStruct->uniforms.blend = glGetUniformLocation(program, "blend"); check_gl_error(); return true; }
Connection() { server = NULL; circa_set_string(&incomingStr, ""); circa_set_list(&incomingMsgs, 0); }