Beispiel #1
0
/**
 * @brief Initializes the timer features provided to Lua.
 */
void LuaContext::register_timer_module() {

  // Functions of sol.timer.
  static const luaL_Reg functions[] = {
      { "start", timer_api_start },
      { "stop_all", timer_api_stop_all },
      { NULL, NULL }
  };
  register_functions(timer_module_name, functions);

  // Methods of the timer type.
  static const luaL_Reg methods[] = {
      { "stop", timer_api_stop },
      { "is_with_sound", timer_api_is_with_sound },
      { "set_with_sound", timer_api_set_with_sound },
      { "is_suspended", timer_api_is_suspended },
      { "set_suspended", timer_api_set_suspended },
      { "is_suspended_with_map", timer_api_is_suspended_with_map },
      { "set_suspended_with_map", timer_api_set_suspended_with_map },
      { NULL, NULL }
  };
  static const luaL_Reg metamethods[] = {
      { "__gc", userdata_meta_gc },
      { NULL, NULL }
  };
  register_type(timer_module_name, methods, metamethods);
}
Beispiel #2
0
ae::es::Lua::Lua( ae::EManager* emanager ) :
		ESystem( emanager )
{
	L = luaL_newstate();
	luaL_openlibs(L);

	register_functions();
}
Beispiel #3
0
void fs_emu_video_sdl_software_init(void)
{
    fs_log("fs_emu_video_sdl_software_init\n");
#else
void fs_emu_video_sdl_init(void)
{
    fs_log("fs_emu_video_sdl_init\n");
#endif
    register_functions();
}
Beispiel #4
0
/**
 * @brief Initializes the menu features provided to Lua.
 */
void LuaContext::register_menu_module() {

  // Functions of sol.menu.
  static const luaL_Reg functions[] = {
      { "start", menu_api_start },
      { "stop", menu_api_stop },
      { "stop_all", menu_api_stop_all },
      { NULL, NULL }
  };
  register_functions(menu_module_name, functions);
}
Beispiel #5
0
static mpdm_t kde4_drv_startup(mpdm_t a, mpdm_t ctxt)
/* driver initialization */
{
    register_functions();

    build_font(1);
    build_colors();

    window = new MPWindow();
    window->show();

    return NULL;
}
Beispiel #6
0
/**
 * \brief Initializes the language features provided to Lua.
 */
void LuaContext::register_language_module() {

  static const luaL_Reg functions[] = {
      { "get_language", language_api_get_language },
      { "set_language", language_api_set_language },
      { "get_language_name", language_api_get_language_name },
      { "get_languages", language_api_get_languages },
      { "get_string", language_api_get_string },
      { "get_dialog", language_api_get_dialog },
      { nullptr, nullptr }
  };

  register_functions(language_module_name, functions);
}
Beispiel #7
0
void mod_db_sql_init() {
        char *str;

	mod_db_sql_config.host = XSTRDUP("127.0.0.1", "mod_db_sql_init");
	mod_db_sql_config.db = XSTRDUP("netmush", "mod_db_sql_init");
	mod_db_sql_config.username = XSTRDUP("netmush", "mod_db_sql_init");
	mod_db_sql_config.password = XSTRDUP("netmush", "mod_db_sql_init");
	mod_db_sql_config.reconnect = 1;
	mod_db_sql_config.port = 3306;
	
    str = XMALLOC(MBUF_SIZE, "mod_db_sql_init");

    snprintf(str, MBUF_SIZE, "version %d.%d", mudstate.version.major, mudstate.version.minor);
    switch(mudstate.version.status){
        case 0:
            snprintf(str, MBUF_SIZE, "%s, Alpha %d", str, mudstate.version.revision);
            break;
        case 1: 
            snprintf(str, MBUF_SIZE, "%s, Beta %d", str, mudstate.version.revision);
            break;
        case 2: 
            snprintf(str, MBUF_SIZE, "%s, Release Candidate %d", str, mudstate.version.revision);
            break;
        default:
            if(mudstate.version.revision > 0) {
                snprintf(str, MBUF_SIZE, "%s, Patch Level %d", str, mudstate.version.revision);
            } else {
                snprintf(str, MBUF_SIZE, "%s, Gold Release.", str);
        }
    }

#ifdef SQL_DRIVER
    snprintf(str, MBUF_SIZE, "%s (%s) using %s driver", str , PACKAGE_RELEASE_DATE, SQL_DRIVER);
    mod_db_sql_version.version=XSTRDUP( str , "mod_db_sql_init");
#else
    snprintf(str, MBUF_SIZE, "%s (%s) using placeholder driver", str , PACKAGE_RELEASE_DATE);
    mod_db_sql_version.version=XSTRDUP(str, "mod_db_sql_init");
#endif
    mod_db_sql_version.author=XSTRDUP("TinyMUSH Development Team", "mod_db_sql_init");
    mod_db_sql_version.email=XSTRDUP("*****@*****.**", "mod_db_sql_init");
    mod_db_sql_version.url=XSTRDUP("http://sourceforge.net/projects/tinymush/", "mod_db_sql_init");
    mod_db_sql_version.description=XSTRDUP("SQL Database interface for TinyMUSH", "mod_db_sql_init");
    mod_db_sql_version.copyright=XSTRDUP("Copyright (C) 2012 TinyMUSH development team.", "mod_db_sql_init");
    
    XFREE(str, "mod_db_sql_init");
	
    register_commands(mod_db_sql_cmdtable);
    register_functions(mod_db_sql_functable);
}
Beispiel #8
0
/**
 * @brief Initializes the audio features provided to Lua.
 */
void LuaContext::register_audio_module() {

  static const luaL_Reg functions[] = {
      { "play_sound", audio_api_play_sound },
      { "preload_sounds", audio_api_preload_sounds },
      { "play_music", audio_api_play_music },
      { "stop_music", audio_api_stop_music },
      { "get_sound_volume", audio_api_get_sound_volume },
      { "set_sound_volume", audio_api_set_sound_volume },
      { "get_music_volume", audio_api_get_music_volume },
      { "set_music_volume", audio_api_set_music_volume },
      { NULL, NULL }
  };
  register_functions(audio_module_name, functions);
}
Beispiel #9
0
/**
 * @brief Initializes the video features provided to Lua.
 */
void LuaContext::register_video_module() {

  static const luaL_Reg functions[] = {
      { "get_window_title", video_api_get_window_title },
      { "set_window_title", video_api_set_window_title },
      { "get_mode", video_api_get_mode },
      { "set_mode", video_api_set_mode },
      { "switch_mode", video_api_switch_mode },
      { "is_mode_supported", video_api_is_mode_supported },
      { "get_modes", video_api_get_modes },
      { "is_fullscreen", video_api_is_fullscreen },
      { "set_fullscreen", video_api_set_fullscreen },
      { NULL, NULL }
  };
  register_functions(video_module_name, functions);
}
Beispiel #10
0
/**
 * \brief Initializes the input features provided to Lua.
 */
void LuaContext::register_input_module() {

  static const luaL_Reg functions[] = {
      { "is_joypad_enabled", input_api_is_joypad_enabled },
      { "set_joypad_enabled", input_api_set_joypad_enabled },
      { "is_key_pressed", input_api_is_key_pressed },
      { "get_key_modifiers", input_api_get_key_modifiers },
      { "is_joypad_button_pressed", input_api_is_joypad_button_pressed },
      { "get_joypad_axis_state", input_api_get_joypad_axis_state },
      { "get_joypad_hat_direction", input_api_get_joypad_hat_direction },
      { "is_mouse_button_pressed", input_api_is_mouse_button_pressed },
      { "get_mouse_position", input_api_get_mouse_position },
      { nullptr, nullptr }
  };

  register_functions(input_module_name, functions);
}
Beispiel #11
0
/**
 * \brief Initializes the main features provided to Lua.
 */
void LuaContext::register_main_module() {

  static const luaL_Reg functions[] = {
      { "load_file", main_api_load_file },
      { "do_file", main_api_do_file },
      { "reset", main_api_reset },
      { "exit", main_api_exit },
      { "get_quest_write_dir", main_api_get_quest_write_dir },
      { "set_quest_write_dir", main_api_set_quest_write_dir },
      { "load_settings", main_api_load_settings },
      { "save_settings", main_api_save_settings },
      { "get_distance", main_api_get_distance },
      { "get_angle", main_api_get_angle },
      { NULL, NULL }
  };
  register_functions(main_module_name, functions);
}
Beispiel #12
0
/**
 * \brief Initializes the file features provided to Lua.
 */
void LuaContext::register_file_module() {

  static const luaL_Reg functions[] = {
      { "open", file_api_open },
      { "exists", file_api_exists },
      { "remove", file_api_remove },
      { "mkdir", file_api_mkdir },
      { NULL, NULL }
  };
  register_functions(file_module_name, functions);

  // Store the original io.open function in the registry.
  // We will need to access it from sol.file.open().
  lua_getglobal(l, "io");
  lua_getfield(l, -1, "open");
  Debug::check_assertion(lua_isfunction(l, -1), "Could not find io.open");
  lua_setfield(l, LUA_REGISTRYINDEX, "io.open");
}
Beispiel #13
0
int main (int argc, char **argv)
{
  scm_init_guile();
  register_functions(NULL);

  //init script, loads the entire script
  scm_c_primitive_load("init.scm");

  //main script, please write update function, and draw function
  scm_c_primitive_load("main.scm");

  if(SDL_Init(SDL_INIT_VIDEO) != 0) {
    printf("it didn't work :(");
    return 1;
  }
  printf("it worked\n");
  SDL_Quit();
  
  return 0;
}
Beispiel #14
0
/**
 * \brief Initializes the audio features provided to Lua.
 */
void LuaContext::register_audio_module() {

  static const luaL_Reg functions[] = {
      { "get_sound_volume", audio_api_get_sound_volume },
      { "set_sound_volume", audio_api_set_sound_volume },
      { "play_sound", audio_api_play_sound },
      { "preload_sounds", audio_api_preload_sounds },
      { "get_music_volume", audio_api_get_music_volume },
      { "set_music_volume", audio_api_set_music_volume },
      { "play_music", audio_api_play_music },
      { "stop_music", audio_api_stop_music },
      { "get_music", audio_api_get_music },
      { "get_music_format", audio_api_get_music_format },
      { "get_music_num_channels", audio_api_get_music_num_channels },
      { "get_music_channel_volume", audio_api_get_music_channel_volume },
      { "set_music_channel_volume", audio_api_set_music_channel_volume },
      { "get_music_tempo", audio_api_get_music_tempo },
      { "set_music_tempo", audio_api_set_music_tempo },
      { nullptr, nullptr }
  };
  register_functions(audio_module_name, functions);
}
Beispiel #15
0
void fs_emu_audio_dummy_init(void)
{
    fs_log("fs_emu_audio_dummy_init\n");
    register_functions();
}
Beispiel #16
0
int parser_eval(const expr_t *e, long double *r, hashtbl_t *vars) {
    if (!e || !r) {
        fprintf(stderr, "eval error: null expression or result var\n");
        return 1;
    }

    /* load known functions */
    static hashtbl_t *functions = NULL;
    if (unlikely(functions == NULL)) {
        functions = hashtbl_init(NULL, NULL);
        register_functions(functions);
    }
    /* stash constants into whatever symtab we get */
    if (unlikely(vars && !hashtbl_get(vars, "_stashed"))) {
        register_constants(vars);
    }

    const list_t *l = (const list_t*)e;
    const list_node_t *n = list_last(l);
    list_t *args = list_init(free, NULL);
    const symbol_t *s;

    while (n && (s = (const symbol_t*)list_data(n))) {
        long double *d = NULL, *v = NULL;
        long double (*f)(list_t*, size_t);

        switch (s->type) {
        case stNumber:
            d = (long double*)zmalloc(sizeof(long double));
            *d = s->number;
            list_push(args, d);
            break;

        case stVariable:
            if (!vars) {
                fprintf(stderr, "eval error: no symbol table\n");
                list_destroy(args);
                return 1;
            }
            if (!(v = (long double*)hashtbl_get(vars, s->variable))) {
                fprintf(stderr, "eval error: uninitialized variable [%s]\n", s->variable);
                list_destroy(args);
                return 1;
            }
            d = (long double*)zmalloc(sizeof(long double));
            *d = *v;
            list_push(args, d);
            break;

        case stBinOperator:
            /* rhs operand */
            if (!(v = (long double*)list_pop(args))) {
                fprintf(stderr, "eval error: missing rhs operand\n");
                list_destroy(args);
                return 1;
            }
        case stUniOperator:
            /* lhs operand, don't pop it... use it to store the result too */
            if (!(d = (long double*)list_peek_head(args))) {
                fprintf(stderr, "eval error: missing lhs operand\n");
                list_destroy(args);
                return 1;
            }
            *d = semanter_operator(s->operator, *d, s->type == stBinOperator ? *v : 0.0);
            free(v);
            break;

        case stFunction:
            if (!(f = (long double(*)(list_t*, size_t))hashtbl_get(functions, s->func.name))) {
                fprintf(stderr, "eval error: unknown function [%s]\n", s->func.name);
                list_destroy(args);
                return 1;
            }
            d = (long double*)zmalloc(sizeof(long double));
            *d = f(args, s->func.nargs);
            list_push(args, d);
            break;
        }
        n = list_prev(n);
    }

    if (list_size(args) != 1) {
        fprintf(stderr, "eval error: corrupt args stack\n");
        list_destroy(args);
        return 1;
    }

    long double *d = (long double*)list_peek_head(args);
    *r = *d;
    list_destroy(args);
    return 0;
}
Beispiel #17
0
void fs_emu_audio_openal_init(void)
{
    fs_log("fs_emu_audio_openal_init\n");
    register_functions();

    // select the "preferred device"
    g_device = alcOpenDevice(NULL);
    if (g_device) {
        fs_log("[OPENAL] Opened device: %s\n",
               alcGetString(g_device, ALC_DEVICE_SPECIFIER));
    } else {
        fs_log("[OPENAL] NULL from alcOpenDevice\n");
        ALenum error_code = alGetError();
        fs_log("[OPENAL] Error code %d\n", error_code);
        if (alGetString(error_code)) {
            fs_log("[OPENAL] %s\n", alGetString(error_code));
        }
        fs_emu_warning("OPENAL: Could not open audio device");
    }
    if (!g_device) {
        return;
    }
    log_openal_info();
    log_openal_devices();

    int frequencies[] = { 48000, 44100, 0 };
    if (fs_config_get_int("audio_frequency") != FS_CONFIG_NONE) {
        frequencies[0] = fs_config_get_int("audio_frequency");
    }

    for (int i = 0; frequencies[i]; i++) {
        int frequency = frequencies[i];
        fs_log("OPENAL: trying frequency %d\n", frequency);
        ALCint attributes[] = {
            ALC_MONO_SOURCES, 0,
            ALC_STEREO_SOURCES, 2,
            ALC_FREQUENCY, frequency,
            0
        };

        g_context = alcCreateContext(g_device, attributes);
        if (g_context) {
            g_audio_out_frequency = frequency;
            break;
        }
    }

    if (g_context) {
        fs_log("OPENAL: created context\n");
        alcMakeContextCurrent(g_context);
        check_al_error("alcMakeContextCurrent");
        fs_log("OPENAL: made context current\n");
    } else {
        fs_emu_warning("OpenAL: no context created\n");
        //check_al_error("alcCreateContext");
    }

    int stereo_sources;
    alcGetIntegerv(g_device, ALC_STEREO_SOURCES, 1, &stereo_sources);
    fs_log("openal: number of stereo sources is %d\n", stereo_sources);

    // FIXME: configure elsewhere
    int abt = fs_config_get_int_clamped("audio_buffer_target_size",
                                        1, 100);
    if (abt == FS_CONFIG_NONE) {
        if (fs_config_get_int("audio_buffer_target_bytes") != FS_CONFIG_NONE) {
            fs_emu_warning("Use audio_buffer_target_size instead\n");
        }
        abt = 40;
#if 0
        if (abt == FS_CONFIG_NONE) {
            abt = 40;
        } else {
            abt = (int) (abt / 1000.0 * (options->frequency * 2 * 2));
        }
#endif
    }
    fs_log("AUDIO: Buffer target size (ms) = %d\n", abt);
    //abt = (int) (abt / 1000.0 * (options->frequency * 2 * 2));
    // fs_log("AUDIO: Buffer target size (bytes) = %d\n", abt);
    /* Specifying fill target in microseconds */
    g_default_fill_target = abt * 1000;
}
Beispiel #18
0
static void
drawable_lua_process (GeglOperation       *op,
                      GeglBuffer          *drawable,
                      GeglBuffer          *aux,
                      GeglBuffer          *result,
                      const GeglRectangle *roi,
                      const gchar         *file,
                      const gchar         *buffer,
                      gdouble              user_value)
{
    /*GimpRGB    background;*/

    GeglRectangle *in_rect = gegl_operation_source_get_bounding_box (GEGL_OPERATION (op),
                                                                       "input");

    lua_State *L;
    Priv p;

    L = luaL_newstate ();
    luaL_openlibs (L);

    register_functions (L, gluas_functions);

    p.rgba_float = babl_format ("RGBA float");
    p.L = L;
    p.width = in_rect->width;
    p.height = in_rect->height;

    p.bx1 = roi->x;
    p.by1 = roi->y;
    p.bx2 = roi->x + roi->width;
    p.by2 = roi->y + roi->height;

    lua_pushnumber (L, (double) user_value);
    lua_setglobal (L, "user_value");
    lua_pushnumber (L, (double) p.width);
    lua_setglobal (L, "width");
    lua_pushnumber (L, (double) p.height);
    lua_setglobal (L, "height");

    lua_pushstring (L, "priv");
    lua_pushlightuserdata (L, &p);
    lua_settable (L, LUA_REGISTRYINDEX);

    p.in_drawable  = drawable;
    p.aux_drawable = aux;
    p.out_drawable = result;

    lua_pushnumber (L, (double) p.bx1);
    lua_setglobal (L, "bound_x0");
    lua_pushnumber (L, (double) p.bx2);
    lua_setglobal (L, "bound_x1");
    lua_pushnumber (L, (double) p.by1);
    lua_setglobal (L, "bound_y0");
    lua_pushnumber (L, (double) p.by2);
    lua_setglobal (L, "bound_y1");

        {
      gint status = 0;

      luaL_loadstring (L, "os.setlocale ('C', 'numeric')");


      /* insert default loop start/end filling the selection */
      if (file && file[0]!='\0')
        status = luaL_loadfile (L, file);
      else if (buffer)
      {
        GString *str = g_string_new (buffer);

        if (!strstr (buffer, "for x"))
        {
          g_string_prepend (str, "for y=bound_y0, bound_y1 do\n for x=bound_x0, bound_x1 do\n");
          g_string_append (str, " end \n progress (y/height)\n end\n");
        }
        status = luaL_loadbuffer (L, str->str, str->len, "buffer");

        g_string_free (str, TRUE);
      }

      if (status == 0)
        status = lua_pcall (L, 0, LUA_MULTRET, 0);

      if (status != 0)
        gegl_node_set (op->node, "error", lua_tostring (L, -1), NULL);
    }
}
Beispiel #19
0
static void
drawable_lua_process (GeglOperation       *op,
                      GeglBuffer          *drawable,
                      GeglBuffer          *aux,
                      GeglBuffer          *result,
                      const GeglRectangle *roi,
                      const gchar         *file,
                      const gchar         *buffer,
                      gdouble              user_value)
{
    /*GimpRGB    background;*/

    GeglRectangle *in_rect = gegl_operation_source_get_bounding_box (GEGL_OPERATION (op),
                                                                       "input");

    lua_State *L;
    Priv p;

    L = luaL_newstate ();
    luaL_openlibs (L);

    register_functions (L, gluas_functions);

    p.rgba_float = babl_format ("RGBA float");
    p.L = L;
    p.width = in_rect->width;
    p.height = in_rect->height;

    p.bx1 = roi->x;
    p.by1 = roi->y;
    p.bx2 = roi->x + roi->width;
    p.by2 = roi->y + roi->height;

    lua_pushnumber (L, (double) user_value);
    lua_setglobal (L, "user_value");
    lua_pushnumber (L, (double) p.width);
    lua_setglobal (L, "width");
    lua_pushnumber (L, (double) p.height);
    lua_setglobal (L, "height");

    lua_pushstring (L, "priv");
    lua_pushlightuserdata (L, &p);
    lua_settable (L, LUA_REGISTRYINDEX);

    p.in_drawable = drawable;
    p.aux_drawable = aux;
    p.out_drawable = result;

    lua_pushnumber (L, (double) p.bx1);
    lua_setglobal (L, "bound_x0");
    lua_pushnumber (L, (double) p.bx2);
    lua_setglobal (L, "bound_x1");
    lua_pushnumber (L, (double) p.by1);
    lua_setglobal (L, "bound_y0");
    lua_pushnumber (L, (double) p.by2);
    lua_setglobal (L, "bound_y1");

        {
      gint status = 0;

      luaL_loadstring (L, "os.setlocale ('C', 'numeric')");

      if (file && file[0]!='\0')
        status = luaL_loadfile (L, file);
      else if (buffer)
        status = luaL_loadbuffer (L, buffer, strlen (buffer), "buffer");

      if (status == 0)
        status = lua_pcall (L, 0, LUA_MULTRET, 0);

      if (status != 0)
        g_warning ("lua error: %s", lua_tostring (L, -1));
    }
}