Changeset 358 for trunk/src/lua


Ignore:
Timestamp:
04/29/15 14:53:06 (10 years ago)
Author:
epyon
Message:
  • fixed string_ref constructor
  • implementing string_ref usage in lua: lua_nova string usage optimized lua_values string_ref entries
Location:
trunk/src/lua
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lua/lua_nova.cc

    r323 r358  
    8383                lua_pushvalue( L, itype );
    8484                lua_pushvalue( L, iid );
    85                 lua_pushstring( L, "." );
     85                lua_pushliteral( L, "." );
    8686                lua_pushvalue( L, ifield );
    8787                lua_concat( L, 3 );
     
    292292{
    293293        // storage.__counter++
    294         lua_pushstring( L, "__counter" );
     294        lua_pushliteral( L, "__counter" );
    295295        lua_pushvalue( L, -1 );
    296296        lua_rawget( L, 1 );
     
    303303
    304304        // element.nid = __counter
    305         lua_pushstring( L, "nid" );
     305        lua_pushliteral( L, "nid" );
    306306        lua_pushinteger( L, count );
    307307        lua_rawset( L, 2 );
     
    322322
    323323        // element.id = element.id
    324         lua_pushstring( L, "id" );
     324        lua_pushliteral( L, "id" );
    325325        lua_rawget( L, 2 );
    326326        if ( lua_isnil( L, -1 ) )
     
    413413
    414414        lua_pushvalue( L, 1 );
    415         lua_pushstring( L, "." );
     415        lua_pushliteral( L, "." );
    416416        lua_pushvalue( L, 2 );
    417417        lua_concat( L, 3 ); // new ident index 5
     
    449449
    450450        lua_pushvalue( L, 1 );
    451         lua_pushstring( L, "." );
     451        lua_pushliteral( L, "." );
    452452        lua_pushvalue( L, 2 );
    453453        lua_concat( L, 3 ); // new ident index 6
     
    579579        if ( lua_type( L, 1 ) == LUA_TSTRING )
    580580        {
     581                // TODO: Optimzie
    581582                lua_getglobal( L, lua_tostring( L, 1 ) );
    582583                lua_replace( L, 1 );
     
    809810}
    810811
    811 void nv::lua::register_storage( state* a_state, const string& name, const string& constructor_name )
     812void nv::lua::register_storage( state* a_state, string_ref name, string_ref constructor_name )
    812813{
    813814        // TODO: error checking
     
    816817        // TODO: check if nova is loaded
    817818        lua_pushcfunction( L, nova_register_storage );
    818         lua_pushstring( L, name.c_str() );
     819        lua_pushlstring( L, name.data(), name.size() );
    819820        lua_call( L, 1, 1 );
    820         lua_setglobal( L, constructor_name.c_str() );
     821        lua_setglobal( L, constructor_name.data() );
    821822        lua_settop( L, stack );
    822823}
  • trunk/src/lua/lua_values.cc

    r319 r358  
    7575}
    7676
     77void nv::lua::detail::push_string_ref( lua_State *L, string_ref s )
     78{
     79        lua_pushlstring( L, s.data(), s.size() );
     80}
     81
    7782void nv::lua::detail::push_pointer ( lua_State *L, void* p )
    7883{
     
    108113std::string nv::lua::detail::to_string  ( lua_State *L, int index )
    109114{
    110         return lua_tostring( L, index );
     115        size_t length = 0;
     116        const char* result = lua_tolstring( L, index, &length );
     117        return std::string( result, length );
    111118}
    112119
    113120const char* nv::lua::detail::to_cstring ( lua_State *L, int index )
    114121{
    115         return lua_tostring( L, index );
     122        return lua_tolstring( L, index, nullptr );
     123}
     124
     125nv::string_ref nv::lua::detail::to_string_ref( lua_State *L, int index )
     126{
     127        size_t length = 0;
     128        const char* result = lua_tolstring( L, index, &length );
     129        return string_ref( result, length );
    116130}
    117131
Note: See TracChangeset for help on using the changeset viewer.