Changeset 520 for trunk/src/lua/lua_aux.cc
- Timestamp:
- 10/03/16 17:45:46 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lua/lua_aux.cc
r503 r520 9 9 #include "nv/lua/lua_raw.hh" 10 10 #include "nv/core/random.hh" 11 12 static nv::random lua_rng; 11 13 12 14 static int nluaaux_table_copy( lua_State* L ) … … 94 96 if ( dice < 1 ) luaL_argerror( L, 1, "die count lower than 1!" ); 95 97 if ( sides < 1 ) luaL_argerror( L, 2, "side count lower than 1!" ); 96 lua_pushnumber( L, nv::random::get().dice( static_cast< nv::uint32 >( dice ), static_cast< nv::uint32 >( sides ) ) );98 lua_pushnumber( L, lua_rng.dice( static_cast< nv::uint32 >( dice ), static_cast< nv::uint32 >( sides ) ) ); 97 99 return 1; 98 100 } … … 102 104 if ( lua_gettop( L ) == 0 ) 103 105 { 104 lua_pushnumber( L, nv::random::get().frand(1.0f) );106 lua_pushnumber( L, lua_rng.frand(1.0f) ); 105 107 } 106 108 else … … 110 112 lua_Integer arg1 = luaL_checkinteger( L, 1 ); 111 113 if ( arg1 < 1 ) arg1 = 1; 112 nlua_pushunsigned( L, nv::random::get().urange( 1, static_cast<nv::uint32>( arg1 ) ) );114 nlua_pushunsigned( L, lua_rng.urange( 1, static_cast<nv::uint32>( arg1 ) ) ); 113 115 } 114 116 else … … 116 118 int arg1 = static_cast< int >( luaL_checkinteger( L, 1 ) ); 117 119 int arg2 = static_cast< int >( luaL_checkinteger( L, 2 ) ); 118 int result = ( arg2 >= arg1 ? nv::random::get().srange( arg1, arg2 ) : nv::random::get().srange( arg2, arg1 ) );120 int result = ( arg2 >= arg1 ? lua_rng.srange( arg1, arg2 ) : lua_rng.srange( arg2, arg1 ) ); 119 121 lua_pushinteger( L, result ); 120 122 } … … 125 127 static int nluaaux_math_randomseed( lua_State* L ) 126 128 { 127 nv::random::get().set_seed( nlua_tounsigned( L, 1 ) );129 lua_rng.set_seed( nlua_tounsigned( L, 1 ) ); 128 130 return 0; 129 131 } … … 137 139 }; 138 140 141 nv::random & nv::lua::rng() 142 { 143 return lua_rng; 144 } 145 139 146 void nv::lua::register_aux( lua::state* state ) 140 147 {
Note: See TracChangeset
for help on using the changeset viewer.