%% @author Sachin Puri
-module(stack).
-behaviour(gen_server).
-compile(export_all).
%% ====================================================================
%% API functions
%% ====================================================================
start()->
gen_server:start({local, stack}, ?MODULE, [], []).
push(Data)->
gen_server:call(?MODULE, {push, Data}).
pop()->
gen_server:call(?MODULE, {pop}).
ls()->
gen_server:call(?MODULE, {ls}).
%% ====================================================================
%% Internal functions
%% ====================================================================
init(_Args)->
{ok, []}.
handle_call({push, Data},_From, State)->
NewState = [Data|State],
{reply, NewState, NewState};
handle_call({pop},_From, [H|T])->
NewState = T,
{reply, H, NewState};
handle_call({pop},_From, [])->
{reply, [], []};
handle_call({ls},_From, State)->
{reply, State, State}.
handle_cast(_Request, State) ->
{noreply, State}.
handle_info(_Info, State) ->
{noreply, State}.
terminate(_Reason, _State) ->
ok.
code_change(_OldVsn, State, _Extra) ->
{ok, State}.