Mercurial > code
changeset 422:f32aaed52c93
Js: sort basic functions
author | David Demelier <markand@malikania.fr> |
---|---|
date | Thu, 08 Oct 2015 15:54:05 +0200 |
parents | d046379137f3 |
children | 70f5cb449a22 |
files | C++/modules/Js/Js.h |
diffstat | 1 files changed, 88 insertions(+), 71 deletions(-) [+] |
line wrap: on
line diff
--- a/C++/modules/Js/Js.h Thu Oct 08 14:15:27 2015 +0200 +++ b/C++/modules/Js/Js.h Thu Oct 08 15:54:05 2015 +0200 @@ -59,6 +59,7 @@ * usually as empty classes to determine the appropriate action to execute. * * For example, `ctx.push(js::Object{})` will push an empty object into the stack. + */ /** * @class Object @@ -350,6 +351,29 @@ */ /** + * Call the object at the top of the stack. + * + * @param ctx the context + * @param nargs the number of arguments + * @note Non-protected + */ + inline void call(unsigned nargs = 0) + { + duk_call(m_handle.get(), nargs); + } + + /** + * Copy a value from from to to, overwriting the previous value. If either index is invalid, throws an error. + * + * @param from the from index + * @param to the destination + */ + inline void copy(int from, int to) + { + duk_copy(m_handle.get(), from, to); + } + + /** * Define a property. * * @param index the object index @@ -400,6 +424,25 @@ } /** + * Push a duplicate of value at from_index to the stack. If from_index is invalid, throws an error. + * + * @param index the value to copy + * @note Wrapper of duk_dup + */ + inline void dup(int index = -1) + { + duk_dup(m_handle.get(), index); + } + + /** + * Evaluate a non-protected chunk that is at the top of the stack. + */ + inline void eval() + { + duk_eval(m_handle.get()); + } + + /** * Check if the object as a property. * * @param index the object index @@ -438,46 +481,13 @@ } /** - * Get the type of the value at the specified index. - * - * @param ctx the context - * @param index the idnex - * @return the type - */ - inline int type(int index) noexcept - { - return duk_get_type(m_handle.get(), index); - } - - /** - * Get the current stack size. - * - * @param ctx the context - * @return the stack size - */ - inline int top() noexcept - { - return duk_get_top(m_handle.get()); - } - - /** - * Pop a certain number of values from the top of the stack. - * - * @param ctx the context - * @param count the number of values to pop - */ - inline void pop(unsigned count = 1) - { - duk_pop_n(m_handle.get(), count); - } - - /** * Check if idx1 is an instance of idx2. * * @param ctx the context * @param idx1 the value to test * @param idx2 the instance requested * @return true if idx1 is instance of idx2 + * @note Wrapper of duk_instanceof */ inline bool instanceof(int idx1, int idx2) { @@ -485,44 +495,12 @@ } /** - * Call the object at the top of the stack. - * - * @param ctx the context - * @param nargs the number of arguments - * @note Non-protected - */ - inline void call(unsigned nargs = 0) - { - duk_call(m_handle.get(), nargs); - } - - /** - * Copy a value from from to to, overwriting the previous value. If either index is invalid, throws an error. - * - * @param from the from index - * @param to the destination - */ - inline void copy(int from, int to) - { - duk_copy(m_handle.get(), from, to); - } - - /** - * Push a duplicate of value at from_index to the stack. If from_index is invalid, throws an error. - * - * @param index the value to copy - */ - inline void dup(int index = -1) - { - duk_dup(m_handle.get(), index); - } - - /** * Insert a value at to with a value popped from the stack top. The previous value at to and any values above * it are moved up the stack by a step. If to is an invalid index, throws an error. * * @note Negative indices are evaluated prior to popping the value at the stack top * @param to the destination + * @note Wrapper of duk_insert */ inline void insert(int to) { @@ -530,10 +508,23 @@ } /** + * Pop a certain number of values from the top of the stack. + * + * @param ctx the context + * @param count the number of values to pop + * @note Wrapper of duk_pop_n + */ + inline void pop(unsigned count = 1) + { + duk_pop_n(m_handle.get(), count); + } + + /** * Remove value at index. Elements above index are shifted down the stack by a step. If to is an invalid index, * throws an error. * * @param index the value to remove + * @note Wrapper of duk_remove */ inline void remove(int index) { @@ -546,6 +537,7 @@ * * @param index the value to replace by the value at the top of the stack * @note Negative indices are evaluated prior to popping the value at the stack top. + * @note Wrapper of duk_replace */ inline void replace(int index) { @@ -558,6 +550,7 @@ * * @param index1 the first index * @param index2 the second index + * @note Wrapper of duk_swap */ inline void swap(int index1, int index2) { @@ -565,13 +558,28 @@ } /** - * Evaluate a non-protected chunk that is at the top of the stack. + * Get the current stack size. * - * @param ctx + * @param ctx the context + * @return the stack size + * @note Wrapper of duk_get_top */ - inline void eval() + inline int top() noexcept { - duk_eval(m_handle.get()); + return duk_get_top(m_handle.get()); + } + + /** + * Get the type of the value at the specified index. + * + * @param ctx the context + * @param index the idnex + * @return the type + * @note Wrapper of duk_get_type + */ + inline int type(int index) noexcept + { + return duk_get_type(m_handle.get(), index); } /* @@ -588,6 +596,7 @@ * @param ctx the context * @param nargs the number of arguments * @throw ErrorInfo on errors + * @note Wrapper of duk_pcall */ void pcall(unsigned nargs = 0); @@ -597,6 +606,7 @@ * @param source the source * @see File * @see Script + * @note Wrapper of duk_eval */ template <typename Source> inline void eval(Source &&source) @@ -608,6 +618,7 @@ * Evaluate a protected chunk that is at the top of the stack. * * @throw ErrorInfo the error + * @note Wrapper of duk_peval */ void peval(); @@ -618,6 +629,7 @@ * @see File * @see Script * @throw ErrorInfo on failure + * @note Wrapper of duk_peval */ template <typename Source> inline void peval(Source &&source) @@ -1752,6 +1764,11 @@ template <> class TypeInfo<This> { public: + /** + * Push this function into the stack. + * + * @param ctx the context + */ static inline void push(Context &ctx, const This &) { duk_push_this(ctx);