コード例 #1
0
ファイル: init.c プロジェクト: AlicVB/darktable
void dt_lua_init_early(lua_State *L)
{
  if(!L)
  {
    L = luaL_newstate();
  }
  darktable.lua_state.state = L;
  darktable.lua_state.ending = false;
  darktable.lua_state.loop = NULL;;
  darktable.lua_state.context = NULL;;
  darktable.lua_state.stacked_job_queue = NULL;;
  dt_lua_init_lock(); // lock is initialized in the locked state
  luaL_openlibs(darktable.lua_state.state);
  luaA_open(L);
  dt_lua_push_darktable_lib(L);
  // set the metatable
  lua_getmetatable(L, -1);
  lua_pushcfunction(L, dt_call_after_load);
  lua_setfield(L, -2, "__call");
  lua_pushcfunction(L, dt_luacleanup);
  lua_setfield(L, -2, "__gc");
  lua_pop(L, 1);

  lua_pop(L, 1);

  lua_CFunction *cur_type = early_init_funcs;
  while(*cur_type)
  {
    (*cur_type)(L);
    cur_type++;
  }
}
コード例 #2
0
int luaopen_arithmatic (lua_State *L) 
{
    luaA_open(L);
    luaA_struct(L, Complex);
    luaA_struct_member(L, Complex, real_part, float);
    luaA_struct_member(L, Complex, virtual_part, float);

    luaA_function(add_int, int);
    luaA_function(add_complex, Complex, void);

    luaL_openlib(L, "arithmatic", my_arithmatic, 0);
    return 1;
}
コード例 #3
0
ファイル: init.c プロジェクト: MarcAntoine-Arnaud/darktable
void dt_lua_init_early(lua_State*L)
{
  if(!L)
    L= luaL_newstate();
  darktable.lua_state= L;
  luaL_openlibs(darktable.lua_state);
  luaA_open();
  dt_lua_push_darktable_lib(L);
  // set the metatable
  lua_newtable(L);
  lua_pushcfunction(L,dt_luacleanup);
  lua_setfield(L,-2,"__gc");
  lua_setmetatable(L,-2);

  lua_pop(L,1);

  /* types need to be initialized early */
  dt_lua_initialize_types(L);
  /* modules need to be initialized before the are used */
  dt_lua_init_modules(L);

}
コード例 #4
0
ファイル: example_mod.c プロジェクト: Acidburn0zzz/darktable
int main(int argc, char **argv) {
	
  lua_State* L = luaL_newstate();
  
  luaA_open(L);
  luaA_function(L, hello_world, void);
  luaA_function(L, hello_repeat, void, int);
  luaA_function(L, hello_person, void, const char*);
  luaA_function(L, hello_subcount, int, const char*);
  
  lua_register(L, "C", C);
  
  luaL_dostring(L,
    "C('hello_world')\n"
    "C('hello_person', 'Daniel')\n"
    "C('hello_repeat', C('hello_subcount', 'hello hello'))\n"
  );
  
  luaA_close(L);
  lua_close(L);
	
  return 0;
}
コード例 #5
0
ファイル: demo_convert.c プロジェクト: EvilBit/darktable
int main(int argc, char **argv) {
	
  lua_State* L = luaL_newstate();
  luaA_open();
	
  luaA_conversion(pair, luaA_push_pair, luaA_to_pair);
	
  luaA_struct(L, person_details);
  luaA_struct_member(L, person_details, id, int);
  luaA_struct_member(L, person_details, male, char);
  luaA_struct_member(L, person_details, coolness, float);

  pair p = {1, 2};
  person_details my_details = {0, 1, 125212.213};
  
  luaA_push(L, pair, &p);
  printf("Pair: (%s, %s)\n", lua_tostring(L, -2), lua_tostring(L, -1));
  lua_pop(L, 2);
  
  luaA_push(L, person_details, &my_details);
  
  lua_getfield(L, -1, "id");
  printf("Id: %i\n", (int)lua_tointeger(L, -1));
  lua_pop(L, 1);
  
  lua_getfield(L, -1, "male");
  printf("Male: %s\n", (bool)lua_toboolean(L, -1) ? "true" : "false");
  lua_pop(L, 1);
  
  lua_pop(L, 1);
  
  luaA_close();
  lua_close(L);
	
  return 0;
}