Git Product home page Git Product logo

Comments (13)

starwing avatar starwing commented on May 28, 2024 1

multiple context support are landed :-)

from lua-protobuf.

daurnimator avatar daurnimator commented on May 28, 2024 1

multiple context support are landed :-)

Thanks!

I see this initial version requires some dancing around to set the default context; make changes; then set the old context again.
In future, would you consider changing things to be methods so that this dance isn't required?

from lua-protobuf.

starwing avatar starwing commented on May 28, 2024

It may easy to add this function, but I wonder it's useful...

from lua-protobuf.

daurnimator avatar daurnimator commented on May 28, 2024

It may easy to add this function, but I wonder it's useful...

I have a use case where users of my server can upload .proto files; and then I use them to send messages on behalf of the user.
I'd like each user to have their own context (or even have ability to have multiple)

from lua-protobuf.

starwing avatar starwing commented on May 28, 2024

In this case, maybe users should be separated into different Lua state?

from lua-protobuf.

daurnimator avatar daurnimator commented on May 28, 2024

In this case, maybe users should be separated into different Lua state?

It's running inside of openresty; which has one lua state per worker process; so that's a no go :(

from lua-protobuf.

starwing avatar starwing commented on May 28, 2024

Okay, I will add plan to do this :-)

from lua-protobuf.

starwing avatar starwing commented on May 28, 2024

most usage use the global context, because this module is usually used in game engines. So people don’t like the method way to use it

from lua-protobuf.

daurnimator avatar daurnimator commented on May 28, 2024

most usage use the global context, because this module is usually used in game engines. So people don’t like the method way to use it

Can always have both options: methods available on the context object; or use a default object when called on the module itself.

from lua-protobuf.

starwing avatar starwing commented on May 28, 2024

It means we will prepare two version of functions: State as the first argument, or not. It may change a lot of code to retrieve state from argument, not from default_lstate(L) routine.

from lua-protobuf.

daurnimator avatar daurnimator commented on May 28, 2024

It may change a lot of code to retrieve state from argument, not from default_lstate(L) routine.

Should be easy to swap it to check_lstate(L, 1);

To get the non-method versions, you could add lua-side wrappers? e.g.

function pb.load(...)
   return pb.get_default_context():load(...)
end

from lua-protobuf.

starwing avatar starwing commented on May 28, 2024

I don't really like to adding Lua wrapper, as a single C module may easier to deploy and use. But it's a way to think of.

and, check functions are relately slow. it will getfield from registry, using type name string as key. thus means to calculate the hash value of string. So maybe it's better to passing it from parameter.

I will try to change pb module into a metatable of state type. but it may take times.

from lua-protobuf.

daurnimator avatar daurnimator commented on May 28, 2024

and, check functions are relately slow. it will getfield from registry, using type name string as key. thus means to calculate the hash value of string. So maybe it's better to passing it from parameter.

For times when speed is critical, I've previously kept the metatable in an upvalue so that you can skip the lookup-by-string step:

	void *ud = lua_touserdata(L, index);;
	int eq;
        if (!ud)
		return NULL;
	if (!lua_getmetatable(L, index))
		return NULL;
	int eq = lua_rawequal(L, -1, lua_upvalueindex(upvalue));
	lua_pop(L, 1);
	if (!eq)
		return NULL;
	

from lua-protobuf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.