Raydium 3D Game Engine

Official forum for everything about Raydium, ManiaDrive, MeMak, ...
It is currently Fri Aug 23, 2019 9:37 am

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: lua scripting
PostPosted: Wed Jan 23, 2008 4:07 pm 
Offline

Joined: Wed Nov 07, 2007 7:31 pm
Posts: 26
Location: Amsterdam
A couple of weeks ago i tried to get some lua bindings for scripting raydium games in lua instead of php. It turns out that php is kind of a big dependency on raydium for the virtual filesystem that fetches the files from the web repository when they are not available locally and i really don't know if we need lua scripting when we have php scripting...

anyway here goes my code in case someone wants that feature:

lua_wrappers.c : kind of a replacement for php_wrappers.c
Code:
#ifndef LUA_WRAPPERS_H
#define LUA_WRAPPERS_H

// C prototype to LUA function wrappers:
// LUA_ReturnType_Arg1TypeArg2Type...(function to wrap)
// v stands for: void
// i stands for: int
// f stands for: float
// s stands for: char *
// svaria stands for: (char *, ...)
// Don't forget to register your functions, too ! (see register.c or docs)

#include <lauxlib.h>

#define LUA_checkboolean(b)\
   luaL_checkstring(L, b)
#define LUA_checkinteger(i)\
   luaL_checkinteger(L, i)
#define LUA_checknumber(n)\
   luaL_checknumber(L, n)
#define LUA_checkstring(s)\
   (char *) luaL_checkstring(L, s)

#define str(s) #s
#define LUA_check_args(fnc, args)\
   if(lua_gettop(L) != args) {luaL_error(L, str(fnc(...): wrong number of arguments!)); return 0;}

// missing functions
lua_Number luaL_checkboolean(lua_State *L, int narg)
{
   lua_Number d = lua_toboolean(L, narg);
   if(d == 0 && !lua_isboolean(L, narg)) luaL_typerror(L, narg, lua_typename(L, narg));
   return d;
}

static int lua_globalboolean(lua_State * L)
{
   signed char * var = (signed char *) lua_topointer(L, lua_upvalueindex(1));
   if(lua_gettop(L) == 0)
   {
      lua_pushboolean(L, *var);
      return 1;
   }
   else
   {
      *var = luaL_checkboolean(L, 1);
      return 0;
   }
}

static int lua_globalinteger(lua_State * L)
{
   int * var = (int *) lua_topointer(L, lua_upvalueindex(1));
   if(lua_gettop(L) == 0)
   {
      lua_pushinteger(L, *var);
      return 1;
   }
   else
   {
      *var = luaL_checkint(L, 1);
      return 0;
   }
}

static int lua_globalnumber(lua_State * L)
{
   float * var = (float *) lua_topointer(L, lua_upvalueindex(1));
   if(lua_gettop(L) == 0)
   {
      lua_pushnumber(L, *var);
      return 1;
   }
   else
   {
      *var = luaL_checknumber(L, 1);
      return 0;
   }
}

static int lua_globalstring(lua_State * L)
{
   const char * var = (const char *) lua_topointer(L, lua_upvalueindex(1));
   if(lua_gettop(L) == 0)
   {
      lua_pushstring(L, var);
      return 1;
   }
   else
   {
      var = luaL_checkstring(L, 1);
      return 0;
   }
}

static int lua_globalcallback(lua_State * L)
{
   void (*cb)(void);
   cb = lua_topointer(L, lua_upvalueindex(1));
   cb();
   return 0;
}

// void f(void)
#define LUA_v_v(fname)\
   static int lua_##fname(lua_State *L)\
   {\
      fname();\
      return 0;\
   }


// void f(int)
#define LUA_v_i(fname)\
   static int lua_##fname(lua_State *L)\
   {\
      LUA_check_args(fname, 1)\
      fname(LUA_checkinteger(1));\
      return 0;\
   }

// void f(float)
#define LUA_v_f(fname)\
   static int lua_##fname(lua_State *L)\
   {\
      LUA_check_args(fname, 1)\
      fname(LUA_checknumber(1));\
      return 0;\
   }

// int f(void)
#define LUA_i_v(fname)\
   static int lua_##fname(lua_State *L)\
   {\
      lua_pushinteger(L, fname());\
      return 1;\
   }

// int f(int)
#define LUA_i_i(fname)\
   static int lua_##fname(lua_State *L)\
   {\
      LUA_check_args(fname, 1)\
      lua_pushinteger(L, fname(LUA_checkinteger(1)));\
      return 1;\
   }

// int f(int, int)
#define LUA_i_ii(fname)\
   static int lua_##fname(lua_State *L)\
   {\
      LUA_check_args(fname, 2)\
      lua_pushinteger(L, fname(LUA_checkinteger(1), LUA_checkinteger(2)));\
      return 1;\
   }

// void f(int, int)
#define LUA_v_ii(fname)\
   static int lua_##fname(lua_State *L)\
   {\
      LUA_check_args(fname, 2)\
      fname(LUA_checkinteger(1), LUA_checkinteger(2));\
      return 0;\
   }

// void f(int,float)
#define LUA_v_if(fname)\
   static int lua_##fname(lua_State *L)\
   {\
      LUA_check_args(fname, 2)\
      fname(LUA_checkinteger(1), LUA_checknumber(2));\
      return 0;\
   }

// int f(int,float)
#define LUA_i_if(fname)\
   static int lua_##fname(lua_State *L)\
   {\
      LUA_check_args(fname, 2)\
      lua_pushinteger(L, fname(LUA_checkinteger(1), LUA_checknumber(2)));\
      return 1;\
   }

// void f(float, float, float) - double, too
#define LUA_v_fff(fname)\
   static int lua_##fname(lua_State *L)\
   {\
      LUA_check_args(fname, 3)\
      fname(LUA_checknumber(1), LUA_checknumber(2), LUA_checknumber(3));\
      return 0;\
   }

// void f(float, float, float, float)
#define LUA_v_ffff(fname)\
   static int lua_##fname(lua_State *L)\
   {\
      LUA_check_args(fname, 4)\
      fname(LUA_checknumber(1), LUA_checknumber(2), LUA_checknumber(3), LUA_checknumber(4));\
      return 0;\
   }

// int f(char *)
#define LUA_i_s(fname)\
   static int lua_##fname(lua_State *L)\
   {\
      LUA_check_args(fname, 1)\
      lua_pushinteger(L, fname(LUA_checkstring(1)));\
      return 1;\
   }

// int f(char *, char*)
#define LUA_i_ss(fname)\
   static int lua_##fname(lua_State *L)\
   {\
      LUA_check_args(fname, 2)\
      lua_pushinteger(L, fname(LUA_checkstring(1), LUA_checkstring(2)));\
      return 1;\
   }

// float f(char *, int)
#define LUA_f_si(fname)\
   static int lua_##fname(lua_State *L)\
   {\
      LUA_check_args(fname, 2)\
      lua_pushnumber(L, fname(LUA_checkstring(1), LUA_checkinteger(2)));\
      return 1;\
   }

// int f(char *, int)
#define LUA_i_si(fname)\
   static int lua_##fname(lua_State *L)\
   {\
      LUA_check_args(fname, 2)\
      lua_pushinteger(L, fname(LUA_checkstring(1), LUA_checkinteger(2)));\
      return 1;\
   }

// int f(char *, int, int)
#define LUA_i_sii(fname)\
   static int lua_##fname(lua_State *L)\
   {\
      LUA_check_args(fname, 3)\
      lua_pushinteger(L, fname(LUA_checkstring(1), LUA_checkinteger(2), LUA_checkinteger(3)));\
      return 1;\
   }

// void f(char *)
#define LUA_v_s(fname)\
   static int lua_##fname(lua_State *L)\
   {\
      LUA_check_args(fname, 1)\
      fname(LUA_checkstring(1));\
      return 0;\
   }

// int f(char *, char*, char *)
#define LUA_i_sss(fname)\
   static int lua_##fname(lua_State *L)\
   {\
      LUA_check_args(fname, 3)\
      lua_pushinteger(L, fname(LUA_checkstring(1), LUA_checkstring(2), LUA_checkstring(3)));\
      return 1;\
   }

// void f(char *, char*, char *)
#define LUA_v_sss(fname)\
   static int lua_##fname(lua_State *L)\
   {\
      LUA_check_args(fname, 3)\
      fname(LUA_checkstring(1), LUA_checkstring(2), LUA_checkstring(3));\
      return 0;\
   }

// void f(char *, ...) - (printf style)
#define LUA_v_svaria(fname)\
   static int lua_##fname(lua_State *L)\
   {\
      fname("%s", LUA_checkstring(1));\
      return 0;\
   }

// int f(char *, int, float, float, char *)
#define LUA_i_siffs(fname)\
   static int lua_##fname(lua_State *L)\
   {\
      LUA_check_args(fname, 5)\
      lua_pushinteger(L, fname(LUA_checkstring(1), LUA_checkinteger(2), LUA_checknumber(3), LUA_checknumber(4), LUA_checkstring(5)));\
      return 1;\
   }

// int f(char *, int, float, float, char *, int)
#define LUA_i_siffsi(fname)\
   static int lua_##fname(lua_State *L)\
   {\
      LUA_check_args(fname, 6)\
      lua_pushinteger(L, fname(LUA_checkstring(1), LUA_checkinteger(2), LUA_checknumber(3), LUA_checknumber(4), LUA_checkstring(5), LUA_checkinteger(6)));\
      return 1;\
   }

// int f(char *, int, float, float, char *, float, float, float)
#define LUA_i_siffsfff(fname)\
   static int lua_##fname(lua_State *L)\
   {\
      LUA_check_args(fname, 8)\
      lua_pushinteger(L, fname(LUA_checkstring(1), LUA_checkinteger(2), LUA_checknumber(3), LUA_checknumber(4), LUA_checkstring(5), LUA_checknumber(6), LUA_checknumber(7), LUA_checknumber(8)));\
      return 1;\
   }

// int f(char *, int, float, float, int, int, char *)
#define LUA_i_siffiis(fname)\
   static int lua_##fname(lua_State *L)\
   {\
      LUA_check_args(fname, 7)\
      lua_pushinteger(L, fname(LUA_checkstring(1), LUA_checkinteger(2), LUA_checknumber(3), LUA_checknumber(4), LUA_checkinteger(5), LUA_checkinteger(6), LUA_checkstring(7)));\
      return 1;\
   }

#define LUA_i_siffiii(fname)\
   static int lua_##fname(lua_State *L)\
   {\
      LUA_check_args(fname, 7)\
      lua_pushinteger(L, fname(LUA_checkstring(1), LUA_checkinteger(2), LUA_checknumber(3), LUA_checknumber(4), LUA_checkinteger(5), LUA_checkinteger(6), LUA_checkinteger(7)));\
      return 1;\
   }

// int f(char *, int, float, float, float, float, int, int, char *)
#define LUA_i_siffffiis(fname)\
   static int lua_##fname(lua_State *L)\
   {\
      LUA_check_args(fname, 9)\
      lua_pushinteger(L, fname(LUA_checkstring(1), LUA_checkinteger(2), LUA_checknumber(3), LUA_checknumber(4), LUA_checknumber(5), LUA_checknumber(6), LUA_checkinteger(7), LUA_checkinteger(8), LUA_checkstring(9)));\
      return 1;\
   }

// void f(char *, int)
#define LUA_v_si(fname)\
   static int lua_##fname(lua_State *L)\
   {\
      LUA_check_args(fname, 2)\
      fname(LUA_checkstring(1), LUA_checkinteger(2));\
      return 0;\
   }

// int f(char *, float)
#define LUA_i_sf(fname)\
   static int lua_##fname(lua_State *L)\
   {\
      LUA_check_args(fname, 2)\
      lua_pushinteger(L, fname(LUA_checkstring(1), LUA_checknumber(2)));\
      return 1;\
   }

// int f(char *, float, float)
#define LUA_i_sff(fname)\
   static int lua_##fname(lua_State *L)\
   {\
      LUA_check_args(fname, 3)\
      lua_pushinteger(L, fname(LUA_checkstring(1), LUA_checknumber(2), LUA_checknumber(3)));\
      return 1;\
   }

// void f(char *, float, float)
#define LUA_v_sff(fname)\
   static int lua_##fname(lua_State *L)\
   {\
      LUA_check_args(fname, 3)\
      fname(LUA_checkstring(1), LUA_checknumber(2), LUA_checknumber(3));\
      return 0;\
   }

// void f(char *, float, float, float)
#define LUA_v_sfff(fname)\
   static int lua_##fname(lua_State *L)\
   {\
      LUA_check_args(fname, 4)\
      fname(LUA_checkstring(1), LUA_checknumber(2), LUA_checknumber(3), LUA_checknumber(4));\
      return 0;\
   }

// void f(char *, float, float, float, float, float, float)
#define LUA_v_sffffff(fname)\
   static int lua_##fname(lua_State *L)\
   {\
      LUA_check_args(fname, 7)\
      fname(LUA_checkstring(1), LUA_checknumber(2), LUA_checknumber(3), LUA_checknumber(4), LUA_checknumber(5), LUA_checknumber(6), LUA_checknumber(7));\
      return 0;\
   }

// void f(char *, char *, int)
#define LUA_v_ssi(fname)\
   static int lua_##fname(lua_State *L)\
   {\
      LUA_check_args(fname, 3)\
      fname(LUA_checkstring(1), LUA_checkstring(2), LUA_checkinteger(3));\
      return 0;\
   }

// void f(char *, char *, float)
#define LUA_v_ssf(fname)\
   static int lua_##fname(lua_State *L)\
   {\
      LUA_check_args(fname, 3)\
      fname(LUA_checkstring(1), LUA_checkstring(2), LUA_checknumber(3));\
      return 0;\
   }

// void f(char *, char *, float, float)
#define LUA_v_ssff(fname)\
   static int lua_##fname(lua_State *L)\
   {\
      LUA_check_args(fname, 4)\
      fname(LUA_checkstring(1), LUA_checkstring(2), LUA_checknumber(3), LUA_checknumber(4));\
      return 0;\
   }

// void f(char *, char *, float, float, float)
#define LUA_v_ssfff(fname)\
   static int lua_##fname(lua_State *L)\
   {\
      LUA_check_args(fname, 5)\
      fname(LUA_checkstring(1), LUA_checkstring(2), LUA_checknumber(3), LUA_checknumber(4), LUA_checknumber(5));\
      return 0;\
   }

// void f(char *, char *, float, float, float, float)
#define LUA_v_ssffff(fname)\
   static int lua_##fname(lua_State *L)\
   {\
      LUA_check_args(fname, 6)\
      fname(LUA_checkstring(1), LUA_checkstring(2), LUA_checknumber(3), LUA_checknumber(4), LUA_checknumber(5), LUA_checknumber(6));\
      return 0;\
   }

// void f(char *, char *)
#define LUA_v_ss(fname)\
   static int lua_##fname(lua_State *L)\
   {\
      LUA_check_args(fname, 2)\
      fname(LUA_checkstring(1), LUA_checkstring(2));\
      return 0;\
   }

// void f(char *, float)
#define LUA_v_sf(fname)\
   static int lua_##fname(lua_State *L)\
   {\
      LUA_check_args(fname, 2)\
      fname(LUA_checkstring(1), LUA_checknumber(2));\
      return 0;\
   }

// int f(char *, char *, char *, float, float, float, float, float, float)
#define LUA_i_sssffffff(fname)\
   static int lua_##fname(lua_State *L)\
   {\
      LUA_check_args(fname, 9)\
      lua_pushinteger(L, fname(LUA_checkstring(1), LUA_checkstring(2), LUA_checkstring(3), LUA_checknumber(4), LUA_checknumber(5), LUA_checknumber(6), LUA_checknumber(7), LUA_checknumber(8), LUA_checknumber(9)));\
      return 1;\
   }

// int f(char *, float, float, float, float)
#define LUA_i_sffff(fname)\
   static int lua_##fname(lua_State *L)\
   {\
      LUA_check_args(fname, 5)\
      lua_pushinteger(L, fname(LUA_checkstring(1), LUA_checknumber(2), LUA_checknumber(3), LUA_checknumber(4), LUA_checknumber(5)));\
      return 1;\
   }

// int f(char *, char *, float, float, float, float)
#define LUA_i_ssffff(fname)\
   static int lua_##fname(lua_State *L)\
   {\
      LUA_check_args(fname, 6)\
      lua_pushinteger(L, fname(LUA_checkstring(1), LUA_checkstring(2), LUA_checknumber(3), LUA_checknumber(4), LUA_checknumber(5), LUA_checknumber(6)));\
      return 1;\
   }

// int f(char *, char *, float, float, float, float)
#define LUA_i_sssffff(fname)\
   static int lua_##fname(lua_State *L)\
   {\
      LUA_check_args(fname, 7)\
      lua_pushinteger(L, fname(LUA_checkstring(1), LUA_checkstring(2), LUA_checkstring(3), LUA_checknumber(4), LUA_checknumber(5), LUA_checknumber(6), LUA_checknumber(7)));\
      return 1;\
   }

#endif


script.c kind of a replacement for php_script.c
Code:
#ifndef SCRIPT_C
#define SCRIPT_C

#include "raydium.h"
#include "lua_wrappers.h"

#define LUA_REGISTER_FUNCTION(fnc)\
    lua_pushcfunction(SCRIPT_ENGINE, lua_##fnc);\
    lua_setglobal(SCRIPT_ENGINE, #fnc);

#define LUA_REGISTER_BOOLEAN(b)\
    lua_pushlightuserdata(SCRIPT_ENGINE, &b);\
    lua_pushcclosure(SCRIPT_ENGINE, lua_globalboolean, 1);\
    lua_setglobal(SCRIPT_ENGINE, #b);

#define LUA_REGISTER_INTEGER(i)\
    lua_pushlightuserdata(SCRIPT_ENGINE, &i);\
    lua_pushcclosure(SCRIPT_ENGINE, lua_globalinteger, 1);\
    lua_setglobal(SCRIPT_ENGINE, #i);

#define LUA_REGISTER_NUMBER(f)\
    lua_pushlightuserdata(SCRIPT_ENGINE, &f);\
    lua_pushcclosure(SCRIPT_ENGINE, lua_globalnumber, 1);\
    lua_setglobal(SCRIPT_ENGINE, #f);

#define LUA_REGISTER_STRING(s)\
    lua_pushlightuserdata(SCRIPT_ENGINE, s);\
    lua_pushcclosure(SCRIPT_ENGINE, lua_globalstring, 1);\
    lua_setglobal(SCRIPT_ENGINE, #s);

#define LUA_REGISTER_INTEGER_CONST(i)\
    lua_pushinteger(SCRIPT_ENGINE, i);\
    lua_setglobal(SCRIPT_ENGINE, #i);

#define LUA_REGISTER_NUMBER_CONST(f)\
    lua_pushnumber(SCRIPT_ENGINE, f);\
    lua_setglobal(SCRIPT_ENGINE, #f);

static lua_State * SCRIPT_ENGINE;

// Part 1: create LUA wrappers

// file.c
LUA_v_ss(raydium_file_home_path_cpy)

// light.c
LUA_v_v(raydium_light_enable)
LUA_v_v(raydium_light_disable)
LUA_v_i(raydium_light_on)
LUA_v_i(raydium_light_off)
LUA_v_i(raydium_light_switch)

// fog.c
LUA_v_v(raydium_fog_enable)
LUA_v_v(raydium_fog_disable)

// background.c
LUA_v_ffff(raydium_background_color_change)

// sound.c
LUA_i_s(raydium_sound_load_music)
LUA_i_if(raydium_sound_SetSourceGain)

// render.c
LUA_v_v(raydium_rendering_wireframe)
LUA_v_v(raydium_rendering_normal)
LUA_v_v(raydium_rendering_displaylists_enable)
LUA_v_v(raydium_rendering_displaylists_disable)
LUA_v_ffff(raydium_render_lightmap_color_4f)

// window.c
LUA_v_v(raydium_window_view_update)
LUA_v_fff(raydium_window_view_perspective)

// console.c
LUA_v_s(raydium_console_exec_script)
LUA_v_v(raydium_console_event)

// log.c
LUA_v_svaria(raydium_log)

// capture.c
LUA_v_s(raydium_capture_frame)

// key.c
LUA_i_i(raydium_key_pressed)

// mouse.c
LUA_i_i(raydium_mouse_button_pressed)

// clear.c
LUA_v_v(raydium_clear_frame)

// camera.c
LUA_v_v(raydium_camera_replace)

// object.c
LUA_v_s(raydium_object_draw_name)

// network.c
LUA_i_v(raydium_network_internet_test)

// particle2.c
LUA_i_ss(raydium_particle_generator_load)
LUA_v_s(raydium_particle_generator_delete_name)
LUA_v_sfff(raydium_particle_generator_move_name_3f)
LUA_i_s(raydium_particle_state_dump)
LUA_i_s(raydium_particle_state_restore)

// shadow.c
LUA_v_v(raydium_shadow_enable)
LUA_v_v(raydium_shadow_disable)

// hdr.c
LUA_v_v(raydium_hdr_enable)
LUA_v_v(raydium_hdr_disable)

// parser.c
LUA_i_ss(raydium_parser_db_set)
LUA_i_sss(raydium_parser_db_get)

#ifdef ODE_SUPPORT
//ode.c
LUA_v_v(raydium_ode_callback)
LUA_v_i(raydium_ode_draw_all)
LUA_v_sffffff(raydium_ode_element_camera_inboard_name)
LUA_i_s(raydium_ode_element_find)
LUA_i_ii(raydium_ode_element_delete)
LUA_i_si(raydium_ode_element_delete_name)
LUA_v_ii(raydium_ode_element_gravity)
LUA_v_si(raydium_ode_element_gravity_name)
//LUA_i_s(raydium_ode_element_ground_texture_get_name)
LUA_i_sff(raydium_ode_element_material_name)
LUA_v_sfff(raydium_ode_element_move_name_3f)
LUA_v_sfff(raydium_ode_element_rotate_name_3f)
LUA_v_ssi(raydium_ode_element_moveto_name)
LUA_v_ss(raydium_ode_element_particle_name)
LUA_i_sf(raydium_ode_element_player_angle_name)
LUA_i_i(raydium_ode_element_player_get)
LUA_v_si(raydium_ode_element_rotate_direction_name)
//LUA_v_sf(raydium_ode_element_rotateq_name)
LUA_i_sf(raydium_ode_element_rotfriction_name)
//LUA_i_sf(raydium_ode_element_rotq_get_name)
LUA_i_sf(raydium_ode_element_slip_name)
LUA_v_ii(raydium_ode_element_sound_update)
LUA_v_si(raydium_ode_element_sound_update_name)
LUA_i_i(raydium_ode_element_tag_get)
LUA_i_s(raydium_ode_element_touched_get_name)
LUA_v_si(raydium_ode_element_ttl_set_name)
LUA_v_s(raydium_ode_ground_set_name)
LUA_i_sssffffff(raydium_ode_joint_attach_hinge_name)
LUA_i_sssffffff(raydium_ode_joint_attach_hinge2_name)
LUA_v_sf(raydium_ode_joint_break_force_name)
LUA_v_sff(raydium_ode_joint_hinge_limits_name)
LUA_v_si(raydium_ode_joint_hinge2_block_name)
LUA_v_sff(raydium_ode_joint_suspension_name)
LUA_i_ssffff(raydium_ode_launcher_name_3f)
LUA_i_ssffff(raydium_ode_launcher_simple_name_3f)
LUA_v_sf(raydium_ode_motor_angle_name)
LUA_v_ssi(raydium_ode_motor_attach_name)
LUA_i_sii(raydium_ode_motor_create)
LUA_v_si(raydium_ode_motor_gear_change_name)
LUA_v_sf(raydium_ode_motor_power_max_name)
LUA_v_sfff(raydium_ode_motor_rocket_orientation_name)
LUA_v_si(raydium_ode_motor_rocket_playermovement_name)
LUA_v_ssfff(raydium_ode_motor_rocket_set_name)
LUA_v_sf(raydium_ode_motor_speed_name)
LUA_f_si(raydium_ode_motor_speed_get_name)
LUA_v_ss(raydium_ode_name_auto)
LUA_i_siffffiis(raydium_ode_object_box_add)
LUA_i_s(raydium_ode_object_create)
LUA_i_i(raydium_ode_object_delete)
LUA_i_s(raydium_ode_object_delete_name)
LUA_i_s(raydium_ode_object_find)
LUA_v_sfff(raydium_ode_object_move_name_3f)
LUA_v_sfff(raydium_ode_object_rotate_name_3f)
LUA_i_siffiis(raydium_ode_object_sphere_add)
LUA_v_f(raydium_ode_time_change)
LUA_i_s(raydium_ode_capture_3d)
LUA_v_s(raydium_ode_capture_record)
LUA_v_v(raydium_ode_capture_record_stop)
LUA_v_si(raydium_ode_capture_play)
LUA_v_v(raydium_ode_capture_stop)

// ode_net.c
LUA_i_i(raydium_ode_network_element_isdistant)
LUA_v_v(raydium_ode_network_element_send_all)
LUA_v_i(raydium_ode_network_element_send_iterative)
LUA_v_i(raydium_ode_network_element_send_random)
#endif

// gui.c
LUA_i_s(raydium_gui_theme_load)
LUA_v_v(raydium_gui_show)
LUA_v_v(raydium_gui_hide)
LUA_i_v(raydium_gui_isvisible)
LUA_v_s(raydium_gui_window_delete_name)
LUA_v_fff(raydium_gui_widget_sizes)
LUA_i_sffff(raydium_gui_window_create)
LUA_i_siffs(raydium_gui_button_create_simple)
LUA_i_siffsfff(raydium_gui_label_create)
LUA_i_siffiii(raydium_gui_track_create)
LUA_i_siffs(raydium_gui_edit_create)
LUA_i_siffsi(raydium_gui_check_create)
LUA_i_siffsi(raydium_gui_combo_create)
LUA_i_sss(raydium_gui_read_name)
LUA_i_v(raydium_gui_button_clicked)

// shader.c
LUA_v_ssi(raydium_shader_var_i_name)
LUA_v_ssf(raydium_shader_var_f_name)
LUA_v_ssff(raydium_shader_var_2f_name)
LUA_v_ssfff(raydium_shader_var_3f_name)
LUA_v_ssffff(raydium_shader_var_4f_name)


// Part 2: register functions
void raydium_script_register_api(void)
{
   static int done=0;

   if (done)
   {
      raydium_log("RegAPI: PASSED (already done previously)");
      return;
   }

// file.c
   LUA_REGISTER_FUNCTION(raydium_file_home_path_cpy)

// light.c
   LUA_REGISTER_FUNCTION(raydium_light_enable)
   LUA_REGISTER_FUNCTION(raydium_light_disable)
   LUA_REGISTER_FUNCTION(raydium_light_on)
   LUA_REGISTER_FUNCTION(raydium_light_off)
   LUA_REGISTER_FUNCTION(raydium_light_switch)

// fog.c
   LUA_REGISTER_FUNCTION(raydium_fog_enable)
   LUA_REGISTER_FUNCTION(raydium_fog_disable)

// background.c
   LUA_REGISTER_FUNCTION(raydium_background_color_change)

// sound.c
   LUA_REGISTER_FUNCTION(raydium_sound_load_music)
   LUA_REGISTER_FUNCTION(raydium_sound_SetSourceGain)

// render.c
   LUA_REGISTER_FUNCTION(raydium_rendering_wireframe)
   LUA_REGISTER_FUNCTION(raydium_rendering_normal)
   LUA_REGISTER_FUNCTION(raydium_rendering_displaylists_enable)
   LUA_REGISTER_FUNCTION(raydium_rendering_displaylists_disable)
   LUA_REGISTER_FUNCTION(raydium_render_lightmap_color_4f)
   LUA_REGISTER_INTEGER(raydium_render_fps)

// window.c / projection
   LUA_REGISTER_FUNCTION(raydium_window_view_perspective)
   LUA_REGISTER_FUNCTION(raydium_window_view_update)

// sky.c
   LUA_REGISTER_BOOLEAN(raydium_sky_force)

// console.c
   LUA_REGISTER_FUNCTION(raydium_console_exec_script)
   LUA_REGISTER_FUNCTION(raydium_console_event)
   LUA_REGISTER_STRING(raydium_console_config_texture);

// log.c
   LUA_REGISTER_FUNCTION(raydium_log)

// capture.c
   LUA_REGISTER_FUNCTION(raydium_capture_frame)

// key.c
   LUA_REGISTER_INTEGER(raydium_key_last)
   LUA_REGISTER_BOOLEAN(raydium_key_trace)
   LUA_REGISTER_FUNCTION(raydium_key_pressed)

// mouse.c
   LUA_REGISTER_INTEGER(raydium_mouse_x)
   LUA_REGISTER_INTEGER(raydium_mouse_y)
   LUA_REGISTER_INTEGER(raydium_mouse_click)
   LUA_REGISTER_FUNCTION(raydium_mouse_button_pressed)

// clear.c
   LUA_REGISTER_FUNCTION(raydium_clear_frame)

// camera.c
   LUA_REGISTER_FUNCTION(raydium_camera_replace)
   LUA_REGISTER_NUMBER(raydium_camera_freemove_speed)
   LUA_REGISTER_NUMBER(raydium_camera_freemove_sensibility)

// object.c
   LUA_REGISTER_FUNCTION(raydium_object_draw_name)

// network.c
   LUA_REGISTER_FUNCTION(raydium_network_internet_test)

// particle2.c
   LUA_REGISTER_FUNCTION(raydium_particle_state_dump)
   LUA_REGISTER_FUNCTION(raydium_particle_state_restore)
   LUA_REGISTER_FUNCTION(raydium_particle_generator_load)
   LUA_REGISTER_FUNCTION(raydium_particle_generator_delete_name)
   LUA_REGISTER_FUNCTION(raydium_particle_generator_move_name_3f)

// shadow.c
   LUA_REGISTER_FUNCTION(raydium_shadow_enable)
   LUA_REGISTER_FUNCTION(raydium_shadow_disable)

// hdr.c
   LUA_REGISTER_FUNCTION(raydium_hdr_enable)
   LUA_REGISTER_FUNCTION(raydium_hdr_disable)

// gui.c
   LUA_REGISTER_FUNCTION(raydium_gui_theme_load)
   LUA_REGISTER_FUNCTION(raydium_gui_show)
   LUA_REGISTER_FUNCTION(raydium_gui_hide)
   LUA_REGISTER_FUNCTION(raydium_gui_isvisible)
   LUA_REGISTER_FUNCTION(raydium_gui_window_delete_name)
   LUA_REGISTER_FUNCTION(raydium_gui_widget_sizes)
   LUA_REGISTER_FUNCTION(raydium_gui_window_create)
   LUA_REGISTER_FUNCTION(raydium_gui_button_create_simple)
   LUA_REGISTER_FUNCTION(raydium_gui_label_create)
   LUA_REGISTER_FUNCTION(raydium_gui_track_create)
   LUA_REGISTER_FUNCTION(raydium_gui_edit_create)
   LUA_REGISTER_FUNCTION(raydium_gui_check_create)
   LUA_REGISTER_FUNCTION(raydium_gui_combo_create)
   LUA_REGISTER_FUNCTION(raydium_gui_read_name)
   LUA_REGISTER_FUNCTION(raydium_gui_button_clicked)

// parser
   LUA_REGISTER_FUNCTION(raydium_parser_db_set)
   LUA_REGISTER_FUNCTION(raydium_parser_db_get)


#ifdef ODE_SUPPORT
// ode.c
   LUA_REGISTER_FUNCTION(raydium_ode_callback)
   LUA_REGISTER_FUNCTION(raydium_ode_draw_all)
   LUA_REGISTER_FUNCTION(raydium_ode_element_camera_inboard_name)
   LUA_REGISTER_FUNCTION(raydium_ode_element_find)
   LUA_REGISTER_FUNCTION(raydium_ode_element_delete)
   LUA_REGISTER_FUNCTION(raydium_ode_element_delete_name)
   LUA_REGISTER_FUNCTION(raydium_ode_element_gravity)
   LUA_REGISTER_FUNCTION(raydium_ode_element_gravity_name)
//LUA_REGISTER_FUNCTION(raydium_ode_element_ground_texture_get_name)
   LUA_REGISTER_FUNCTION(raydium_ode_element_material_name)
   LUA_REGISTER_FUNCTION(raydium_ode_element_move_name_3f)
   LUA_REGISTER_FUNCTION(raydium_ode_element_rotate_name_3f)
   LUA_REGISTER_FUNCTION(raydium_ode_element_moveto_name)
   LUA_REGISTER_FUNCTION(raydium_ode_element_particle_name)
   LUA_REGISTER_FUNCTION(raydium_ode_element_player_angle_name)
   LUA_REGISTER_FUNCTION(raydium_ode_element_player_get)
   LUA_REGISTER_FUNCTION(raydium_ode_element_rotate_direction_name)
//LUA_REGISTER_FUNCTION(raydium_ode_element_rotateq_name)
   LUA_REGISTER_FUNCTION(raydium_ode_element_rotfriction_name)
//LUA_REGISTER_FUNCTION(raydium_ode_element_rotq_get_name)
   LUA_REGISTER_FUNCTION(raydium_ode_element_slip_name)
   LUA_REGISTER_FUNCTION(raydium_ode_element_sound_update)
   LUA_REGISTER_FUNCTION(raydium_ode_element_sound_update_name)
   LUA_REGISTER_FUNCTION(raydium_ode_element_tag_get)
   LUA_REGISTER_FUNCTION(raydium_ode_element_touched_get_name)
   LUA_REGISTER_FUNCTION(raydium_ode_element_ttl_set_name)
   LUA_REGISTER_FUNCTION(raydium_ode_ground_set_name)
   LUA_REGISTER_FUNCTION(raydium_ode_joint_attach_hinge_name)
   LUA_REGISTER_FUNCTION(raydium_ode_joint_attach_hinge2_name)
   LUA_REGISTER_FUNCTION(raydium_ode_joint_break_force_name)
   LUA_REGISTER_FUNCTION(raydium_ode_joint_hinge_limits_name)
   LUA_REGISTER_FUNCTION(raydium_ode_joint_hinge2_block_name)
   LUA_REGISTER_FUNCTION(raydium_ode_joint_suspension_name)
   LUA_REGISTER_FUNCTION(raydium_ode_launcher_name_3f)
   LUA_REGISTER_FUNCTION(raydium_ode_launcher_simple_name_3f)
   LUA_REGISTER_FUNCTION(raydium_ode_motor_angle_name)
   LUA_REGISTER_FUNCTION(raydium_ode_motor_attach_name)
   LUA_REGISTER_FUNCTION(raydium_ode_motor_create)
   LUA_REGISTER_FUNCTION(raydium_ode_motor_gear_change_name)
   LUA_REGISTER_FUNCTION(raydium_ode_motor_power_max_name)
   LUA_REGISTER_FUNCTION(raydium_ode_motor_rocket_orientation_name)
   LUA_REGISTER_FUNCTION(raydium_ode_motor_rocket_playermovement_name)
   LUA_REGISTER_FUNCTION(raydium_ode_motor_rocket_set_name)
   LUA_REGISTER_FUNCTION(raydium_ode_motor_speed_name)
   LUA_REGISTER_FUNCTION(raydium_ode_motor_speed_get_name)
   LUA_REGISTER_FUNCTION(raydium_ode_name_auto)
   LUA_REGISTER_FUNCTION(raydium_ode_object_box_add)
   LUA_REGISTER_FUNCTION(raydium_ode_object_create)
   LUA_REGISTER_FUNCTION(raydium_ode_object_delete)
   LUA_REGISTER_FUNCTION(raydium_ode_object_delete_name)
   LUA_REGISTER_FUNCTION(raydium_ode_object_find)
   LUA_REGISTER_FUNCTION(raydium_ode_object_move_name_3f)
   LUA_REGISTER_FUNCTION(raydium_ode_object_rotate_name_3f)
   LUA_REGISTER_FUNCTION(raydium_ode_object_sphere_add)
   LUA_REGISTER_FUNCTION(raydium_ode_time_change)
   LUA_REGISTER_FUNCTION(raydium_ode_capture_3d)
   LUA_REGISTER_FUNCTION(raydium_ode_capture_record)
   LUA_REGISTER_FUNCTION(raydium_ode_capture_record_stop)
   LUA_REGISTER_FUNCTION(raydium_ode_capture_play)
   LUA_REGISTER_FUNCTION(raydium_ode_capture_stop)
   LUA_REGISTER_INTEGER_CONST(RAYDIUM_ODE_AUTODETECT)
   LUA_REGISTER_INTEGER_CONST(RAYDIUM_ODE_STANDARD)
   LUA_REGISTER_INTEGER_CONST(RAYDIUM_ODE_STATIC)
   LUA_REGISTER_INTEGER_CONST(RAYDIUM_ODE_FIXING)
   LUA_REGISTER_INTEGER_CONST(RAYDIUM_ODE_MOTOR_ENGINE)
   LUA_REGISTER_INTEGER_CONST(RAYDIUM_ODE_MOTOR_ANGULAR)
   LUA_REGISTER_INTEGER_CONST(RAYDIUM_ODE_MOTOR_ROCKET)
   LUA_REGISTER_NUMBER_CONST(RAYDIUM_ODE_SLIP_ICE)
   LUA_REGISTER_NUMBER_CONST(RAYDIUM_ODE_SLIP_PLAYER)
   LUA_REGISTER_NUMBER_CONST(RAYDIUM_ODE_SLIP_NORMAL)

// ode_net.c
   LUA_REGISTER_FUNCTION(raydium_ode_network_element_isdistant)
   LUA_REGISTER_FUNCTION(raydium_ode_network_element_send_all)
   LUA_REGISTER_FUNCTION(raydium_ode_network_element_send_iterative)
   LUA_REGISTER_FUNCTION(raydium_ode_network_element_send_random)
#endif

// shader.c
   LUA_REGISTER_FUNCTION(raydium_shader_var_i_name)
   LUA_REGISTER_FUNCTION(raydium_shader_var_f_name)
   LUA_REGISTER_FUNCTION(raydium_shader_var_2f_name)
   LUA_REGISTER_FUNCTION(raydium_shader_var_3f_name)
   LUA_REGISTER_FUNCTION(raydium_shader_var_4f_name)


   raydium_log("Script Engine: OK");
   done=1;
}

void raydium_script_init()
{
   SCRIPT_ENGINE = lua_open();
   luaL_openlibs(SCRIPT_ENGINE);
}

void raydium_script_close()
{
   lua_close(SCRIPT_ENGINE);
}

int raydium_script_exec(char *name)
{
   int res = luaL_dofile(SCRIPT_ENGINE, name);
    if(res != 0)
   {
      raydium_log("%s\n", lua_tostring(SCRIPT_ENGINE, -1));
      lua_pop(SCRIPT_ENGINE, 1);
   }
   return res;
}

void raydium_script_register_boolean(signed char * b, const char * name)
{
    lua_pushlightuserdata(SCRIPT_ENGINE, b);
    lua_pushcclosure(SCRIPT_ENGINE, lua_globalboolean, 1);
    lua_setglobal(SCRIPT_ENGINE, name);
}

void raydium_script_register_integer(int * i, const char * name)
{
    lua_pushlightuserdata(SCRIPT_ENGINE, i);
    lua_pushcclosure(SCRIPT_ENGINE, lua_globalinteger, 1);
    lua_setglobal(SCRIPT_ENGINE, name);
}

void raydium_script_register_number(float * f, const char * name)
{
    lua_pushlightuserdata(SCRIPT_ENGINE, f);
    lua_pushcclosure(SCRIPT_ENGINE, lua_globalnumber, 1);
    lua_setglobal(SCRIPT_ENGINE, name);
}

void raydium_script_register_string(char * s, const char * name)
{
    lua_pushlightuserdata(SCRIPT_ENGINE, s);
    lua_pushcclosure(SCRIPT_ENGINE, lua_globalstring, 1);
    lua_setglobal(SCRIPT_ENGINE, name);
}

void raydium_script_register_integer_const(int i, const char * name)
{
    lua_pushinteger(SCRIPT_ENGINE, i);
    lua_setglobal(SCRIPT_ENGINE, name);
}

void raydium_script_register_number_const(float f, const char * name)
{
    lua_pushnumber(SCRIPT_ENGINE, f);
    lua_setglobal(SCRIPT_ENGINE, name);
}

void raydium_script_register_function(void (*func)(void), const char * name)
{
    lua_pushlightuserdata(SCRIPT_ENGINE, func);
    lua_pushcclosure(SCRIPT_ENGINE, lua_globalcallback, 1);
    lua_setglobal(SCRIPT_ENGINE, name);
}

#endif


As usual you have my permission to add it to the contrib if you like ;-) and to compile just link against lua 5.1.2


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 09, 2008 9:32 pm 
Offline
User avatar

Joined: Sun Mar 16, 2003 2:53 am
Posts: 2590
Location: gnniiiii (Scrat)
It may be interesting to release this in the source tree, in the contrib directory. Paulo, do you want a SVN write access for such tasks ?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 14, 2008 7:37 am 
Offline
User avatar

Joined: Thu Aug 24, 2006 4:06 pm
Posts: 73
Location: SLOVAKIA
will by lua wrapper as part of raydium? (in shortly time?) LUA is really good and useful for all and more quickly as PHP

P.S.: I hhave 2 options, wait or write wrapper self, ( i don't like waiting ;) )


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 14, 2008 8:51 am 
Offline
User avatar

Joined: Thu Sep 29, 2005 2:59 pm
Posts: 828
According the Xfennec answer, yes, it will part of raydium, but it will be added in the contrib folder (like a plugin).
However paulo didn't respond the Xfennec question and Xfennex himself is quite busy.
Do you want to try adding that in raydium yourself? You will have to ask directly Xfennec for an SVN account.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 11, 2008 7:22 am 
Offline

Joined: Wed Nov 07, 2007 7:31 pm
Posts: 26
Location: Amsterdam
Please PM me with the details of the SVN access!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group