mb_malloc_strcpy

Previous  Next

 

void* mb_malloc_strcpy( const char* pString )

 


 

Allocates and copys a string to the newly allocated memory.  Use this function when you need to return a string in a function.

 

Example

 

// Simple function that returns the string "This is My String!"

 

int _my_func( mb_interpreter_t* s, void** l )

  {

  mb_assert( s && l );

 

  mb_check( mb_attempt_open_bracket( s, l ) );

  mb_check( mb_attempt_close_bracket( s, l ) );

 

  const char* pMyString = "This is My String!";

 

  char* pString = (char*)mb_malloc_strcpy( pMyString );

 

  mb_check( mb_push_string( s, l, pString ) );

 

  return MB_FUNC_OK;

}